Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1 | //===-- ARMISelLowering.cpp - ARM DAG Lowering Implementation -------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines the interfaces that ARM uses to lower LLVM code into a |
| 11 | // selection DAG. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 15 | #define DEBUG_TYPE "arm-isel" |
Craig Topper | c1f6f42 | 2012-03-17 07:33:42 +0000 | [diff] [blame] | 16 | #include "ARMISelLowering.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 17 | #include "ARM.h" |
Eric Christopher | 6f2ccef | 2010-09-10 22:42:06 +0000 | [diff] [blame] | 18 | #include "ARMCallingConv.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 19 | #include "ARMConstantPoolValue.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 20 | #include "ARMMachineFunctionInfo.h" |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 21 | #include "ARMPerfectShuffle.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 22 | #include "ARMSubtarget.h" |
| 23 | #include "ARMTargetMachine.h" |
Chris Lattner | 80ec279 | 2009-08-02 00:34:36 +0000 | [diff] [blame] | 24 | #include "ARMTargetObjectFile.h" |
Evan Cheng | ee04a6d | 2011-07-20 23:34:39 +0000 | [diff] [blame] | 25 | #include "MCTargetDesc/ARMAddressingModes.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/Statistic.h" |
| 27 | #include "llvm/ADT/StringExtras.h" |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 28 | #include "llvm/CodeGen/CallingConvLower.h" |
Evan Cheng | 55d4200 | 2011-01-08 01:24:27 +0000 | [diff] [blame] | 29 | #include "llvm/CodeGen/IntrinsicLowering.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 30 | #include "llvm/CodeGen/MachineBasicBlock.h" |
| 31 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 32 | #include "llvm/CodeGen/MachineFunction.h" |
| 33 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 34 | #include "llvm/CodeGen/MachineModuleInfo.h" |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 35 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 36 | #include "llvm/CodeGen/SelectionDAG.h" |
Chandler Carruth | 0b8c9a8 | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 37 | #include "llvm/IR/CallingConv.h" |
| 38 | #include "llvm/IR/Constants.h" |
| 39 | #include "llvm/IR/Function.h" |
| 40 | #include "llvm/IR/GlobalValue.h" |
| 41 | #include "llvm/IR/Instruction.h" |
| 42 | #include "llvm/IR/Instructions.h" |
| 43 | #include "llvm/IR/Intrinsics.h" |
| 44 | #include "llvm/IR/Type.h" |
Bill Wendling | 94a1c63 | 2010-03-09 02:46:12 +0000 | [diff] [blame] | 45 | #include "llvm/MC/MCSectionMachO.h" |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 46 | #include "llvm/Support/CommandLine.h" |
Torok Edwin | ab7c09b | 2009-07-08 18:01:40 +0000 | [diff] [blame] | 47 | #include "llvm/Support/ErrorHandling.h" |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 48 | #include "llvm/Support/MathExtras.h" |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 49 | #include "llvm/Support/raw_ostream.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 50 | #include "llvm/Target/TargetOptions.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 51 | using namespace llvm; |
| 52 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 53 | STATISTIC(NumTailCalls, "Number of tail calls"); |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 54 | STATISTIC(NumMovwMovt, "Number of GAs materialized with movw + movt"); |
Manman Ren | 763a75d | 2012-06-01 02:44:42 +0000 | [diff] [blame] | 55 | STATISTIC(NumLoopByVals, "Number of loops generated for byval arguments"); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 56 | |
Bob Wilson | 703af3a | 2010-08-13 22:43:33 +0000 | [diff] [blame] | 57 | // This option should go away when tail calls fully work. |
| 58 | static cl::opt<bool> |
| 59 | EnableARMTailCalls("arm-tail-calls", cl::Hidden, |
| 60 | cl::desc("Generate tail calls (TEMPORARY OPTION)."), |
| 61 | cl::init(false)); |
| 62 | |
Eric Christopher | 836c624 | 2010-12-15 23:47:29 +0000 | [diff] [blame] | 63 | cl::opt<bool> |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 64 | EnableARMLongCalls("arm-long-calls", cl::Hidden, |
Evan Cheng | 515fe3a | 2010-07-08 02:08:50 +0000 | [diff] [blame] | 65 | cl::desc("Generate calls via indirect call instructions"), |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 66 | cl::init(false)); |
| 67 | |
Evan Cheng | 46df4eb | 2010-06-16 07:35:02 +0000 | [diff] [blame] | 68 | static cl::opt<bool> |
| 69 | ARMInterworking("arm-interworking", cl::Hidden, |
| 70 | cl::desc("Enable / disable ARM interworking (for debugging only)"), |
| 71 | cl::init(true)); |
| 72 | |
Benjamin Kramer | 0861f57 | 2011-11-26 23:01:57 +0000 | [diff] [blame] | 73 | namespace { |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 74 | class ARMCCState : public CCState { |
| 75 | public: |
| 76 | ARMCCState(CallingConv::ID CC, bool isVarArg, MachineFunction &MF, |
| 77 | const TargetMachine &TM, SmallVector<CCValAssign, 16> &locs, |
| 78 | LLVMContext &C, ParmContext PC) |
| 79 | : CCState(CC, isVarArg, MF, TM, locs, C) { |
| 80 | assert(((PC == Call) || (PC == Prologue)) && |
| 81 | "ARMCCState users must specify whether their context is call" |
| 82 | "or prologue generation."); |
| 83 | CallOrPrologue = PC; |
| 84 | } |
| 85 | }; |
| 86 | } |
| 87 | |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 88 | // The APCS parameter registers. |
Craig Topper | c5eaae4 | 2012-03-11 07:57:25 +0000 | [diff] [blame] | 89 | static const uint16_t GPRArgRegs[] = { |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 90 | ARM::R0, ARM::R1, ARM::R2, ARM::R3 |
| 91 | }; |
| 92 | |
Craig Topper | 0faf46c | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 93 | void ARMTargetLowering::addTypeForNEON(MVT VT, MVT PromotedLdStVT, |
| 94 | MVT PromotedBitwiseVT) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 95 | if (VT != PromotedLdStVT) { |
Craig Topper | 0faf46c | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 96 | setOperationAction(ISD::LOAD, VT, Promote); |
| 97 | AddPromotedToType (ISD::LOAD, VT, PromotedLdStVT); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 98 | |
Craig Topper | 0faf46c | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 99 | setOperationAction(ISD::STORE, VT, Promote); |
| 100 | AddPromotedToType (ISD::STORE, VT, PromotedLdStVT); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 101 | } |
| 102 | |
Craig Topper | 0faf46c | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 103 | MVT ElemTy = VT.getVectorElementType(); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 104 | if (ElemTy != MVT::i64 && ElemTy != MVT::f64) |
Craig Topper | 0faf46c | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 105 | setOperationAction(ISD::SETCC, VT, Custom); |
| 106 | setOperationAction(ISD::INSERT_VECTOR_ELT, VT, Custom); |
| 107 | setOperationAction(ISD::EXTRACT_VECTOR_ELT, VT, Custom); |
Eli Friedman | 14e809c | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 108 | if (ElemTy == MVT::i32) { |
Craig Topper | 0faf46c | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 109 | setOperationAction(ISD::SINT_TO_FP, VT, Custom); |
| 110 | setOperationAction(ISD::UINT_TO_FP, VT, Custom); |
| 111 | setOperationAction(ISD::FP_TO_SINT, VT, Custom); |
| 112 | setOperationAction(ISD::FP_TO_UINT, VT, Custom); |
Eli Friedman | 14e809c | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 113 | } else { |
Craig Topper | 0faf46c | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 114 | setOperationAction(ISD::SINT_TO_FP, VT, Expand); |
| 115 | setOperationAction(ISD::UINT_TO_FP, VT, Expand); |
| 116 | setOperationAction(ISD::FP_TO_SINT, VT, Expand); |
| 117 | setOperationAction(ISD::FP_TO_UINT, VT, Expand); |
Bob Wilson | 0696fdf | 2009-09-16 20:20:44 +0000 | [diff] [blame] | 118 | } |
Craig Topper | 0faf46c | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 119 | setOperationAction(ISD::BUILD_VECTOR, VT, Custom); |
| 120 | setOperationAction(ISD::VECTOR_SHUFFLE, VT, Custom); |
| 121 | setOperationAction(ISD::CONCAT_VECTORS, VT, Legal); |
| 122 | setOperationAction(ISD::EXTRACT_SUBVECTOR, VT, Legal); |
| 123 | setOperationAction(ISD::SELECT, VT, Expand); |
| 124 | setOperationAction(ISD::SELECT_CC, VT, Expand); |
Jim Grosbach | 4346fa9 | 2012-10-12 22:59:21 +0000 | [diff] [blame] | 125 | setOperationAction(ISD::VSELECT, VT, Expand); |
Craig Topper | 0faf46c | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 126 | setOperationAction(ISD::SIGN_EXTEND_INREG, VT, Expand); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 127 | if (VT.isInteger()) { |
Craig Topper | 0faf46c | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 128 | setOperationAction(ISD::SHL, VT, Custom); |
| 129 | setOperationAction(ISD::SRA, VT, Custom); |
| 130 | setOperationAction(ISD::SRL, VT, Custom); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | // Promote all bit-wise operations. |
| 134 | if (VT.isInteger() && VT != PromotedBitwiseVT) { |
Craig Topper | 0faf46c | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 135 | setOperationAction(ISD::AND, VT, Promote); |
| 136 | AddPromotedToType (ISD::AND, VT, PromotedBitwiseVT); |
| 137 | setOperationAction(ISD::OR, VT, Promote); |
| 138 | AddPromotedToType (ISD::OR, VT, PromotedBitwiseVT); |
| 139 | setOperationAction(ISD::XOR, VT, Promote); |
| 140 | AddPromotedToType (ISD::XOR, VT, PromotedBitwiseVT); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 141 | } |
Bob Wilson | 1633076 | 2009-09-16 00:17:28 +0000 | [diff] [blame] | 142 | |
| 143 | // Neon does not support vector divide/remainder operations. |
Craig Topper | 0faf46c | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 144 | setOperationAction(ISD::SDIV, VT, Expand); |
| 145 | setOperationAction(ISD::UDIV, VT, Expand); |
| 146 | setOperationAction(ISD::FDIV, VT, Expand); |
| 147 | setOperationAction(ISD::SREM, VT, Expand); |
| 148 | setOperationAction(ISD::UREM, VT, Expand); |
| 149 | setOperationAction(ISD::FREM, VT, Expand); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 150 | } |
| 151 | |
Craig Topper | 0faf46c | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 152 | void ARMTargetLowering::addDRTypeForNEON(MVT VT) { |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 153 | addRegisterClass(VT, &ARM::DPRRegClass); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 154 | addTypeForNEON(VT, MVT::f64, MVT::v2i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 155 | } |
| 156 | |
Craig Topper | 0faf46c | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 157 | void ARMTargetLowering::addQRTypeForNEON(MVT VT) { |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 158 | addRegisterClass(VT, &ARM::QPRRegClass); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 159 | addTypeForNEON(VT, MVT::v2f64, MVT::v4i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 160 | } |
| 161 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 162 | static TargetLoweringObjectFile *createTLOF(TargetMachine &TM) { |
| 163 | if (TM.getSubtarget<ARMSubtarget>().isTargetDarwin()) |
Bill Wendling | 505ad8b | 2010-03-15 21:09:38 +0000 | [diff] [blame] | 164 | return new TargetLoweringObjectFileMachO(); |
Bill Wendling | 94a1c63 | 2010-03-09 02:46:12 +0000 | [diff] [blame] | 165 | |
Chris Lattner | 80ec279 | 2009-08-02 00:34:36 +0000 | [diff] [blame] | 166 | return new ARMElfTargetObjectFile(); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 167 | } |
| 168 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 169 | ARMTargetLowering::ARMTargetLowering(TargetMachine &TM) |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 170 | : TargetLowering(TM, createTLOF(TM)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 171 | Subtarget = &TM.getSubtarget<ARMSubtarget>(); |
Evan Cheng | 3144687 | 2010-07-23 22:39:59 +0000 | [diff] [blame] | 172 | RegInfo = TM.getRegisterInfo(); |
Evan Cheng | 3ef1c87 | 2010-09-10 01:29:16 +0000 | [diff] [blame] | 173 | Itins = TM.getInstrItineraryData(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 174 | |
Duncan Sands | 28b77e9 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 175 | setBooleanVectorContents(ZeroOrNegativeOneBooleanContent); |
| 176 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 177 | if (Subtarget->isTargetDarwin()) { |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 178 | // Uses VFP for Thumb libfuncs if available. |
| 179 | if (Subtarget->isThumb() && Subtarget->hasVFP2()) { |
| 180 | // Single-precision floating-point arithmetic. |
| 181 | setLibcallName(RTLIB::ADD_F32, "__addsf3vfp"); |
| 182 | setLibcallName(RTLIB::SUB_F32, "__subsf3vfp"); |
| 183 | setLibcallName(RTLIB::MUL_F32, "__mulsf3vfp"); |
| 184 | setLibcallName(RTLIB::DIV_F32, "__divsf3vfp"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 185 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 186 | // Double-precision floating-point arithmetic. |
| 187 | setLibcallName(RTLIB::ADD_F64, "__adddf3vfp"); |
| 188 | setLibcallName(RTLIB::SUB_F64, "__subdf3vfp"); |
| 189 | setLibcallName(RTLIB::MUL_F64, "__muldf3vfp"); |
| 190 | setLibcallName(RTLIB::DIV_F64, "__divdf3vfp"); |
Evan Cheng | 193f850 | 2007-01-31 09:30:58 +0000 | [diff] [blame] | 191 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 192 | // Single-precision comparisons. |
| 193 | setLibcallName(RTLIB::OEQ_F32, "__eqsf2vfp"); |
| 194 | setLibcallName(RTLIB::UNE_F32, "__nesf2vfp"); |
| 195 | setLibcallName(RTLIB::OLT_F32, "__ltsf2vfp"); |
| 196 | setLibcallName(RTLIB::OLE_F32, "__lesf2vfp"); |
| 197 | setLibcallName(RTLIB::OGE_F32, "__gesf2vfp"); |
| 198 | setLibcallName(RTLIB::OGT_F32, "__gtsf2vfp"); |
| 199 | setLibcallName(RTLIB::UO_F32, "__unordsf2vfp"); |
| 200 | setLibcallName(RTLIB::O_F32, "__unordsf2vfp"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 201 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 202 | setCmpLibcallCC(RTLIB::OEQ_F32, ISD::SETNE); |
| 203 | setCmpLibcallCC(RTLIB::UNE_F32, ISD::SETNE); |
| 204 | setCmpLibcallCC(RTLIB::OLT_F32, ISD::SETNE); |
| 205 | setCmpLibcallCC(RTLIB::OLE_F32, ISD::SETNE); |
| 206 | setCmpLibcallCC(RTLIB::OGE_F32, ISD::SETNE); |
| 207 | setCmpLibcallCC(RTLIB::OGT_F32, ISD::SETNE); |
| 208 | setCmpLibcallCC(RTLIB::UO_F32, ISD::SETNE); |
| 209 | setCmpLibcallCC(RTLIB::O_F32, ISD::SETEQ); |
Evan Cheng | 193f850 | 2007-01-31 09:30:58 +0000 | [diff] [blame] | 210 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 211 | // Double-precision comparisons. |
| 212 | setLibcallName(RTLIB::OEQ_F64, "__eqdf2vfp"); |
| 213 | setLibcallName(RTLIB::UNE_F64, "__nedf2vfp"); |
| 214 | setLibcallName(RTLIB::OLT_F64, "__ltdf2vfp"); |
| 215 | setLibcallName(RTLIB::OLE_F64, "__ledf2vfp"); |
| 216 | setLibcallName(RTLIB::OGE_F64, "__gedf2vfp"); |
| 217 | setLibcallName(RTLIB::OGT_F64, "__gtdf2vfp"); |
| 218 | setLibcallName(RTLIB::UO_F64, "__unorddf2vfp"); |
| 219 | setLibcallName(RTLIB::O_F64, "__unorddf2vfp"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 220 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 221 | setCmpLibcallCC(RTLIB::OEQ_F64, ISD::SETNE); |
| 222 | setCmpLibcallCC(RTLIB::UNE_F64, ISD::SETNE); |
| 223 | setCmpLibcallCC(RTLIB::OLT_F64, ISD::SETNE); |
| 224 | setCmpLibcallCC(RTLIB::OLE_F64, ISD::SETNE); |
| 225 | setCmpLibcallCC(RTLIB::OGE_F64, ISD::SETNE); |
| 226 | setCmpLibcallCC(RTLIB::OGT_F64, ISD::SETNE); |
| 227 | setCmpLibcallCC(RTLIB::UO_F64, ISD::SETNE); |
| 228 | setCmpLibcallCC(RTLIB::O_F64, ISD::SETEQ); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 229 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 230 | // Floating-point to integer conversions. |
| 231 | // i64 conversions are done via library routines even when generating VFP |
| 232 | // instructions, so use the same ones. |
| 233 | setLibcallName(RTLIB::FPTOSINT_F64_I32, "__fixdfsivfp"); |
| 234 | setLibcallName(RTLIB::FPTOUINT_F64_I32, "__fixunsdfsivfp"); |
| 235 | setLibcallName(RTLIB::FPTOSINT_F32_I32, "__fixsfsivfp"); |
| 236 | setLibcallName(RTLIB::FPTOUINT_F32_I32, "__fixunssfsivfp"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 237 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 238 | // Conversions between floating types. |
| 239 | setLibcallName(RTLIB::FPROUND_F64_F32, "__truncdfsf2vfp"); |
| 240 | setLibcallName(RTLIB::FPEXT_F32_F64, "__extendsfdf2vfp"); |
| 241 | |
| 242 | // Integer to floating-point conversions. |
| 243 | // i64 conversions are done via library routines even when generating VFP |
| 244 | // instructions, so use the same ones. |
Bob Wilson | 2a14c52 | 2009-03-20 23:16:43 +0000 | [diff] [blame] | 245 | // FIXME: There appears to be some naming inconsistency in ARM libgcc: |
| 246 | // e.g., __floatunsidf vs. __floatunssidfvfp. |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 247 | setLibcallName(RTLIB::SINTTOFP_I32_F64, "__floatsidfvfp"); |
| 248 | setLibcallName(RTLIB::UINTTOFP_I32_F64, "__floatunssidfvfp"); |
| 249 | setLibcallName(RTLIB::SINTTOFP_I32_F32, "__floatsisfvfp"); |
| 250 | setLibcallName(RTLIB::UINTTOFP_I32_F32, "__floatunssisfvfp"); |
| 251 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 252 | } |
| 253 | |
Bob Wilson | 2f95461 | 2009-05-22 17:38:41 +0000 | [diff] [blame] | 254 | // These libcalls are not available in 32-bit. |
| 255 | setLibcallName(RTLIB::SHL_I128, 0); |
| 256 | setLibcallName(RTLIB::SRL_I128, 0); |
| 257 | setLibcallName(RTLIB::SRA_I128, 0); |
| 258 | |
Evan Cheng | 0704327 | 2012-02-21 20:46:00 +0000 | [diff] [blame] | 259 | if (Subtarget->isAAPCS_ABI() && !Subtarget->isTargetDarwin()) { |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 260 | // Double-precision floating-point arithmetic helper functions |
Anton Korobeynikov | 4f922f2 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 261 | // RTABI chapter 4.1.2, Table 2 |
| 262 | setLibcallName(RTLIB::ADD_F64, "__aeabi_dadd"); |
| 263 | setLibcallName(RTLIB::DIV_F64, "__aeabi_ddiv"); |
| 264 | setLibcallName(RTLIB::MUL_F64, "__aeabi_dmul"); |
| 265 | setLibcallName(RTLIB::SUB_F64, "__aeabi_dsub"); |
| 266 | setLibcallCallingConv(RTLIB::ADD_F64, CallingConv::ARM_AAPCS); |
| 267 | setLibcallCallingConv(RTLIB::DIV_F64, CallingConv::ARM_AAPCS); |
| 268 | setLibcallCallingConv(RTLIB::MUL_F64, CallingConv::ARM_AAPCS); |
| 269 | setLibcallCallingConv(RTLIB::SUB_F64, CallingConv::ARM_AAPCS); |
| 270 | |
| 271 | // Double-precision floating-point comparison helper functions |
| 272 | // RTABI chapter 4.1.2, Table 3 |
| 273 | setLibcallName(RTLIB::OEQ_F64, "__aeabi_dcmpeq"); |
| 274 | setCmpLibcallCC(RTLIB::OEQ_F64, ISD::SETNE); |
| 275 | setLibcallName(RTLIB::UNE_F64, "__aeabi_dcmpeq"); |
| 276 | setCmpLibcallCC(RTLIB::UNE_F64, ISD::SETEQ); |
| 277 | setLibcallName(RTLIB::OLT_F64, "__aeabi_dcmplt"); |
| 278 | setCmpLibcallCC(RTLIB::OLT_F64, ISD::SETNE); |
| 279 | setLibcallName(RTLIB::OLE_F64, "__aeabi_dcmple"); |
| 280 | setCmpLibcallCC(RTLIB::OLE_F64, ISD::SETNE); |
| 281 | setLibcallName(RTLIB::OGE_F64, "__aeabi_dcmpge"); |
| 282 | setCmpLibcallCC(RTLIB::OGE_F64, ISD::SETNE); |
| 283 | setLibcallName(RTLIB::OGT_F64, "__aeabi_dcmpgt"); |
| 284 | setCmpLibcallCC(RTLIB::OGT_F64, ISD::SETNE); |
| 285 | setLibcallName(RTLIB::UO_F64, "__aeabi_dcmpun"); |
| 286 | setCmpLibcallCC(RTLIB::UO_F64, ISD::SETNE); |
| 287 | setLibcallName(RTLIB::O_F64, "__aeabi_dcmpun"); |
| 288 | setCmpLibcallCC(RTLIB::O_F64, ISD::SETEQ); |
| 289 | setLibcallCallingConv(RTLIB::OEQ_F64, CallingConv::ARM_AAPCS); |
| 290 | setLibcallCallingConv(RTLIB::UNE_F64, CallingConv::ARM_AAPCS); |
| 291 | setLibcallCallingConv(RTLIB::OLT_F64, CallingConv::ARM_AAPCS); |
| 292 | setLibcallCallingConv(RTLIB::OLE_F64, CallingConv::ARM_AAPCS); |
| 293 | setLibcallCallingConv(RTLIB::OGE_F64, CallingConv::ARM_AAPCS); |
| 294 | setLibcallCallingConv(RTLIB::OGT_F64, CallingConv::ARM_AAPCS); |
| 295 | setLibcallCallingConv(RTLIB::UO_F64, CallingConv::ARM_AAPCS); |
| 296 | setLibcallCallingConv(RTLIB::O_F64, CallingConv::ARM_AAPCS); |
| 297 | |
| 298 | // Single-precision floating-point arithmetic helper functions |
| 299 | // RTABI chapter 4.1.2, Table 4 |
| 300 | setLibcallName(RTLIB::ADD_F32, "__aeabi_fadd"); |
| 301 | setLibcallName(RTLIB::DIV_F32, "__aeabi_fdiv"); |
| 302 | setLibcallName(RTLIB::MUL_F32, "__aeabi_fmul"); |
| 303 | setLibcallName(RTLIB::SUB_F32, "__aeabi_fsub"); |
| 304 | setLibcallCallingConv(RTLIB::ADD_F32, CallingConv::ARM_AAPCS); |
| 305 | setLibcallCallingConv(RTLIB::DIV_F32, CallingConv::ARM_AAPCS); |
| 306 | setLibcallCallingConv(RTLIB::MUL_F32, CallingConv::ARM_AAPCS); |
| 307 | setLibcallCallingConv(RTLIB::SUB_F32, CallingConv::ARM_AAPCS); |
| 308 | |
| 309 | // Single-precision floating-point comparison helper functions |
| 310 | // RTABI chapter 4.1.2, Table 5 |
| 311 | setLibcallName(RTLIB::OEQ_F32, "__aeabi_fcmpeq"); |
| 312 | setCmpLibcallCC(RTLIB::OEQ_F32, ISD::SETNE); |
| 313 | setLibcallName(RTLIB::UNE_F32, "__aeabi_fcmpeq"); |
| 314 | setCmpLibcallCC(RTLIB::UNE_F32, ISD::SETEQ); |
| 315 | setLibcallName(RTLIB::OLT_F32, "__aeabi_fcmplt"); |
| 316 | setCmpLibcallCC(RTLIB::OLT_F32, ISD::SETNE); |
| 317 | setLibcallName(RTLIB::OLE_F32, "__aeabi_fcmple"); |
| 318 | setCmpLibcallCC(RTLIB::OLE_F32, ISD::SETNE); |
| 319 | setLibcallName(RTLIB::OGE_F32, "__aeabi_fcmpge"); |
| 320 | setCmpLibcallCC(RTLIB::OGE_F32, ISD::SETNE); |
| 321 | setLibcallName(RTLIB::OGT_F32, "__aeabi_fcmpgt"); |
| 322 | setCmpLibcallCC(RTLIB::OGT_F32, ISD::SETNE); |
| 323 | setLibcallName(RTLIB::UO_F32, "__aeabi_fcmpun"); |
| 324 | setCmpLibcallCC(RTLIB::UO_F32, ISD::SETNE); |
| 325 | setLibcallName(RTLIB::O_F32, "__aeabi_fcmpun"); |
| 326 | setCmpLibcallCC(RTLIB::O_F32, ISD::SETEQ); |
| 327 | setLibcallCallingConv(RTLIB::OEQ_F32, CallingConv::ARM_AAPCS); |
| 328 | setLibcallCallingConv(RTLIB::UNE_F32, CallingConv::ARM_AAPCS); |
| 329 | setLibcallCallingConv(RTLIB::OLT_F32, CallingConv::ARM_AAPCS); |
| 330 | setLibcallCallingConv(RTLIB::OLE_F32, CallingConv::ARM_AAPCS); |
| 331 | setLibcallCallingConv(RTLIB::OGE_F32, CallingConv::ARM_AAPCS); |
| 332 | setLibcallCallingConv(RTLIB::OGT_F32, CallingConv::ARM_AAPCS); |
| 333 | setLibcallCallingConv(RTLIB::UO_F32, CallingConv::ARM_AAPCS); |
| 334 | setLibcallCallingConv(RTLIB::O_F32, CallingConv::ARM_AAPCS); |
| 335 | |
| 336 | // Floating-point to integer conversions. |
| 337 | // RTABI chapter 4.1.2, Table 6 |
| 338 | setLibcallName(RTLIB::FPTOSINT_F64_I32, "__aeabi_d2iz"); |
| 339 | setLibcallName(RTLIB::FPTOUINT_F64_I32, "__aeabi_d2uiz"); |
| 340 | setLibcallName(RTLIB::FPTOSINT_F64_I64, "__aeabi_d2lz"); |
| 341 | setLibcallName(RTLIB::FPTOUINT_F64_I64, "__aeabi_d2ulz"); |
| 342 | setLibcallName(RTLIB::FPTOSINT_F32_I32, "__aeabi_f2iz"); |
| 343 | setLibcallName(RTLIB::FPTOUINT_F32_I32, "__aeabi_f2uiz"); |
| 344 | setLibcallName(RTLIB::FPTOSINT_F32_I64, "__aeabi_f2lz"); |
| 345 | setLibcallName(RTLIB::FPTOUINT_F32_I64, "__aeabi_f2ulz"); |
| 346 | setLibcallCallingConv(RTLIB::FPTOSINT_F64_I32, CallingConv::ARM_AAPCS); |
| 347 | setLibcallCallingConv(RTLIB::FPTOUINT_F64_I32, CallingConv::ARM_AAPCS); |
| 348 | setLibcallCallingConv(RTLIB::FPTOSINT_F64_I64, CallingConv::ARM_AAPCS); |
| 349 | setLibcallCallingConv(RTLIB::FPTOUINT_F64_I64, CallingConv::ARM_AAPCS); |
| 350 | setLibcallCallingConv(RTLIB::FPTOSINT_F32_I32, CallingConv::ARM_AAPCS); |
| 351 | setLibcallCallingConv(RTLIB::FPTOUINT_F32_I32, CallingConv::ARM_AAPCS); |
| 352 | setLibcallCallingConv(RTLIB::FPTOSINT_F32_I64, CallingConv::ARM_AAPCS); |
| 353 | setLibcallCallingConv(RTLIB::FPTOUINT_F32_I64, CallingConv::ARM_AAPCS); |
| 354 | |
| 355 | // Conversions between floating types. |
| 356 | // RTABI chapter 4.1.2, Table 7 |
| 357 | setLibcallName(RTLIB::FPROUND_F64_F32, "__aeabi_d2f"); |
| 358 | setLibcallName(RTLIB::FPEXT_F32_F64, "__aeabi_f2d"); |
| 359 | setLibcallCallingConv(RTLIB::FPROUND_F64_F32, CallingConv::ARM_AAPCS); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 360 | setLibcallCallingConv(RTLIB::FPEXT_F32_F64, CallingConv::ARM_AAPCS); |
Anton Korobeynikov | 4f922f2 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 361 | |
| 362 | // Integer to floating-point conversions. |
| 363 | // RTABI chapter 4.1.2, Table 8 |
| 364 | setLibcallName(RTLIB::SINTTOFP_I32_F64, "__aeabi_i2d"); |
| 365 | setLibcallName(RTLIB::UINTTOFP_I32_F64, "__aeabi_ui2d"); |
| 366 | setLibcallName(RTLIB::SINTTOFP_I64_F64, "__aeabi_l2d"); |
| 367 | setLibcallName(RTLIB::UINTTOFP_I64_F64, "__aeabi_ul2d"); |
| 368 | setLibcallName(RTLIB::SINTTOFP_I32_F32, "__aeabi_i2f"); |
| 369 | setLibcallName(RTLIB::UINTTOFP_I32_F32, "__aeabi_ui2f"); |
| 370 | setLibcallName(RTLIB::SINTTOFP_I64_F32, "__aeabi_l2f"); |
| 371 | setLibcallName(RTLIB::UINTTOFP_I64_F32, "__aeabi_ul2f"); |
| 372 | setLibcallCallingConv(RTLIB::SINTTOFP_I32_F64, CallingConv::ARM_AAPCS); |
| 373 | setLibcallCallingConv(RTLIB::UINTTOFP_I32_F64, CallingConv::ARM_AAPCS); |
| 374 | setLibcallCallingConv(RTLIB::SINTTOFP_I64_F64, CallingConv::ARM_AAPCS); |
| 375 | setLibcallCallingConv(RTLIB::UINTTOFP_I64_F64, CallingConv::ARM_AAPCS); |
| 376 | setLibcallCallingConv(RTLIB::SINTTOFP_I32_F32, CallingConv::ARM_AAPCS); |
| 377 | setLibcallCallingConv(RTLIB::UINTTOFP_I32_F32, CallingConv::ARM_AAPCS); |
| 378 | setLibcallCallingConv(RTLIB::SINTTOFP_I64_F32, CallingConv::ARM_AAPCS); |
| 379 | setLibcallCallingConv(RTLIB::UINTTOFP_I64_F32, CallingConv::ARM_AAPCS); |
| 380 | |
| 381 | // Long long helper functions |
| 382 | // RTABI chapter 4.2, Table 9 |
| 383 | setLibcallName(RTLIB::MUL_I64, "__aeabi_lmul"); |
Anton Korobeynikov | 4f922f2 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 384 | setLibcallName(RTLIB::SHL_I64, "__aeabi_llsl"); |
| 385 | setLibcallName(RTLIB::SRL_I64, "__aeabi_llsr"); |
| 386 | setLibcallName(RTLIB::SRA_I64, "__aeabi_lasr"); |
| 387 | setLibcallCallingConv(RTLIB::MUL_I64, CallingConv::ARM_AAPCS); |
| 388 | setLibcallCallingConv(RTLIB::SDIV_I64, CallingConv::ARM_AAPCS); |
| 389 | setLibcallCallingConv(RTLIB::UDIV_I64, CallingConv::ARM_AAPCS); |
| 390 | setLibcallCallingConv(RTLIB::SHL_I64, CallingConv::ARM_AAPCS); |
| 391 | setLibcallCallingConv(RTLIB::SRL_I64, CallingConv::ARM_AAPCS); |
| 392 | setLibcallCallingConv(RTLIB::SRA_I64, CallingConv::ARM_AAPCS); |
| 393 | |
| 394 | // Integer division functions |
| 395 | // RTABI chapter 4.3.1 |
| 396 | setLibcallName(RTLIB::SDIV_I8, "__aeabi_idiv"); |
| 397 | setLibcallName(RTLIB::SDIV_I16, "__aeabi_idiv"); |
| 398 | setLibcallName(RTLIB::SDIV_I32, "__aeabi_idiv"); |
Anton Korobeynikov | 6edd588 | 2012-01-29 09:11:50 +0000 | [diff] [blame] | 399 | setLibcallName(RTLIB::SDIV_I64, "__aeabi_ldivmod"); |
Anton Korobeynikov | 4f922f2 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 400 | setLibcallName(RTLIB::UDIV_I8, "__aeabi_uidiv"); |
| 401 | setLibcallName(RTLIB::UDIV_I16, "__aeabi_uidiv"); |
| 402 | setLibcallName(RTLIB::UDIV_I32, "__aeabi_uidiv"); |
Anton Korobeynikov | 6edd588 | 2012-01-29 09:11:50 +0000 | [diff] [blame] | 403 | setLibcallName(RTLIB::UDIV_I64, "__aeabi_uldivmod"); |
Anton Korobeynikov | 4f922f2 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 404 | setLibcallCallingConv(RTLIB::SDIV_I8, CallingConv::ARM_AAPCS); |
| 405 | setLibcallCallingConv(RTLIB::SDIV_I16, CallingConv::ARM_AAPCS); |
| 406 | setLibcallCallingConv(RTLIB::SDIV_I32, CallingConv::ARM_AAPCS); |
Anton Korobeynikov | 6edd588 | 2012-01-29 09:11:50 +0000 | [diff] [blame] | 407 | setLibcallCallingConv(RTLIB::SDIV_I64, CallingConv::ARM_AAPCS); |
Anton Korobeynikov | 4f922f2 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 408 | setLibcallCallingConv(RTLIB::UDIV_I8, CallingConv::ARM_AAPCS); |
| 409 | setLibcallCallingConv(RTLIB::UDIV_I16, CallingConv::ARM_AAPCS); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 410 | setLibcallCallingConv(RTLIB::UDIV_I32, CallingConv::ARM_AAPCS); |
Anton Korobeynikov | 6edd588 | 2012-01-29 09:11:50 +0000 | [diff] [blame] | 411 | setLibcallCallingConv(RTLIB::UDIV_I64, CallingConv::ARM_AAPCS); |
Renato Golin | 1ec11fb | 2011-05-22 21:41:23 +0000 | [diff] [blame] | 412 | |
| 413 | // Memory operations |
| 414 | // RTABI chapter 4.3.4 |
| 415 | setLibcallName(RTLIB::MEMCPY, "__aeabi_memcpy"); |
| 416 | setLibcallName(RTLIB::MEMMOVE, "__aeabi_memmove"); |
| 417 | setLibcallName(RTLIB::MEMSET, "__aeabi_memset"); |
Anton Korobeynikov | 6edd588 | 2012-01-29 09:11:50 +0000 | [diff] [blame] | 418 | setLibcallCallingConv(RTLIB::MEMCPY, CallingConv::ARM_AAPCS); |
| 419 | setLibcallCallingConv(RTLIB::MEMMOVE, CallingConv::ARM_AAPCS); |
| 420 | setLibcallCallingConv(RTLIB::MEMSET, CallingConv::ARM_AAPCS); |
Anton Korobeynikov | 72977a4 | 2009-08-14 20:10:52 +0000 | [diff] [blame] | 421 | } |
| 422 | |
Bob Wilson | 2fef457 | 2011-10-07 16:59:21 +0000 | [diff] [blame] | 423 | // Use divmod compiler-rt calls for iOS 5.0 and later. |
| 424 | if (Subtarget->getTargetTriple().getOS() == Triple::IOS && |
| 425 | !Subtarget->getTargetTriple().isOSVersionLT(5, 0)) { |
| 426 | setLibcallName(RTLIB::SDIVREM_I32, "__divmodsi4"); |
| 427 | setLibcallName(RTLIB::UDIVREM_I32, "__udivmodsi4"); |
| 428 | } |
| 429 | |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 430 | if (Subtarget->isThumb1Only()) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 431 | addRegisterClass(MVT::i32, &ARM::tGPRRegClass); |
Jim Grosbach | 30eae3c | 2009-04-07 20:34:09 +0000 | [diff] [blame] | 432 | else |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 433 | addRegisterClass(MVT::i32, &ARM::GPRRegClass); |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 434 | if (!TM.Options.UseSoftFloat && Subtarget->hasVFP2() && |
| 435 | !Subtarget->isThumb1Only()) { |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 436 | addRegisterClass(MVT::f32, &ARM::SPRRegClass); |
Jim Grosbach | fcba5e6 | 2010-08-11 15:44:15 +0000 | [diff] [blame] | 437 | if (!Subtarget->isFPOnlySP()) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 438 | addRegisterClass(MVT::f64, &ARM::DPRRegClass); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 439 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 440 | setTruncStoreAction(MVT::f64, MVT::f32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 441 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 442 | |
Eli Friedman | 9f1f26a | 2011-11-08 01:43:53 +0000 | [diff] [blame] | 443 | for (unsigned VT = (unsigned)MVT::FIRST_VECTOR_VALUETYPE; |
| 444 | VT <= (unsigned)MVT::LAST_VECTOR_VALUETYPE; ++VT) { |
| 445 | for (unsigned InnerVT = (unsigned)MVT::FIRST_VECTOR_VALUETYPE; |
| 446 | InnerVT <= (unsigned)MVT::LAST_VECTOR_VALUETYPE; ++InnerVT) |
| 447 | setTruncStoreAction((MVT::SimpleValueType)VT, |
| 448 | (MVT::SimpleValueType)InnerVT, Expand); |
| 449 | setLoadExtAction(ISD::SEXTLOAD, (MVT::SimpleValueType)VT, Expand); |
| 450 | setLoadExtAction(ISD::ZEXTLOAD, (MVT::SimpleValueType)VT, Expand); |
| 451 | setLoadExtAction(ISD::EXTLOAD, (MVT::SimpleValueType)VT, Expand); |
| 452 | } |
| 453 | |
Lang Hames | 45b5f88 | 2012-03-15 18:49:02 +0000 | [diff] [blame] | 454 | setOperationAction(ISD::ConstantFP, MVT::f32, Custom); |
| 455 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 456 | if (Subtarget->hasNEON()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 457 | addDRTypeForNEON(MVT::v2f32); |
| 458 | addDRTypeForNEON(MVT::v8i8); |
| 459 | addDRTypeForNEON(MVT::v4i16); |
| 460 | addDRTypeForNEON(MVT::v2i32); |
| 461 | addDRTypeForNEON(MVT::v1i64); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 462 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 463 | addQRTypeForNEON(MVT::v4f32); |
| 464 | addQRTypeForNEON(MVT::v2f64); |
| 465 | addQRTypeForNEON(MVT::v16i8); |
| 466 | addQRTypeForNEON(MVT::v8i16); |
| 467 | addQRTypeForNEON(MVT::v4i32); |
| 468 | addQRTypeForNEON(MVT::v2i64); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 469 | |
Bob Wilson | 74dc72e | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 470 | // v2f64 is legal so that QR subregs can be extracted as f64 elements, but |
| 471 | // neither Neon nor VFP support any arithmetic operations on it. |
Stepan Dyatkovskiy | 3e0dc06 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 472 | // The same with v4f32. But keep in mind that vadd, vsub, vmul are natively |
| 473 | // supported for v4f32. |
Bob Wilson | 74dc72e | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 474 | setOperationAction(ISD::FADD, MVT::v2f64, Expand); |
| 475 | setOperationAction(ISD::FSUB, MVT::v2f64, Expand); |
| 476 | setOperationAction(ISD::FMUL, MVT::v2f64, Expand); |
Stepan Dyatkovskiy | 3e0dc06 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 477 | // FIXME: Code duplication: FDIV and FREM are expanded always, see |
| 478 | // ARMTargetLowering::addTypeForNEON method for details. |
Bob Wilson | 74dc72e | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 479 | setOperationAction(ISD::FDIV, MVT::v2f64, Expand); |
| 480 | setOperationAction(ISD::FREM, MVT::v2f64, Expand); |
Stepan Dyatkovskiy | 3e0dc06 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 481 | // FIXME: Create unittest. |
| 482 | // In another words, find a way when "copysign" appears in DAG with vector |
| 483 | // operands. |
Bob Wilson | 74dc72e | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 484 | setOperationAction(ISD::FCOPYSIGN, MVT::v2f64, Expand); |
Stepan Dyatkovskiy | 3e0dc06 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 485 | // FIXME: Code duplication: SETCC has custom operation action, see |
| 486 | // ARMTargetLowering::addTypeForNEON method for details. |
Duncan Sands | 28b77e9 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 487 | setOperationAction(ISD::SETCC, MVT::v2f64, Expand); |
Stepan Dyatkovskiy | 3e0dc06 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 488 | // FIXME: Create unittest for FNEG and for FABS. |
Bob Wilson | 74dc72e | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 489 | setOperationAction(ISD::FNEG, MVT::v2f64, Expand); |
| 490 | setOperationAction(ISD::FABS, MVT::v2f64, Expand); |
| 491 | setOperationAction(ISD::FSQRT, MVT::v2f64, Expand); |
| 492 | setOperationAction(ISD::FSIN, MVT::v2f64, Expand); |
| 493 | setOperationAction(ISD::FCOS, MVT::v2f64, Expand); |
| 494 | setOperationAction(ISD::FPOWI, MVT::v2f64, Expand); |
| 495 | setOperationAction(ISD::FPOW, MVT::v2f64, Expand); |
| 496 | setOperationAction(ISD::FLOG, MVT::v2f64, Expand); |
| 497 | setOperationAction(ISD::FLOG2, MVT::v2f64, Expand); |
| 498 | setOperationAction(ISD::FLOG10, MVT::v2f64, Expand); |
| 499 | setOperationAction(ISD::FEXP, MVT::v2f64, Expand); |
| 500 | setOperationAction(ISD::FEXP2, MVT::v2f64, Expand); |
Stepan Dyatkovskiy | 3e0dc06 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 501 | // FIXME: Create unittest for FCEIL, FTRUNC, FRINT, FNEARBYINT, FFLOOR. |
Bob Wilson | 74dc72e | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 502 | setOperationAction(ISD::FCEIL, MVT::v2f64, Expand); |
| 503 | setOperationAction(ISD::FTRUNC, MVT::v2f64, Expand); |
| 504 | setOperationAction(ISD::FRINT, MVT::v2f64, Expand); |
| 505 | setOperationAction(ISD::FNEARBYINT, MVT::v2f64, Expand); |
| 506 | setOperationAction(ISD::FFLOOR, MVT::v2f64, Expand); |
Arnold Schwaighofer | 21c0aa7 | 2013-03-02 19:38:33 +0000 | [diff] [blame^] | 507 | setOperationAction(ISD::FMA, MVT::v2f64, Expand); |
Lang Hames | c0a9f82 | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 508 | |
Stepan Dyatkovskiy | 3e0dc06 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 509 | setOperationAction(ISD::FSQRT, MVT::v4f32, Expand); |
| 510 | setOperationAction(ISD::FSIN, MVT::v4f32, Expand); |
| 511 | setOperationAction(ISD::FCOS, MVT::v4f32, Expand); |
| 512 | setOperationAction(ISD::FPOWI, MVT::v4f32, Expand); |
| 513 | setOperationAction(ISD::FPOW, MVT::v4f32, Expand); |
| 514 | setOperationAction(ISD::FLOG, MVT::v4f32, Expand); |
| 515 | setOperationAction(ISD::FLOG2, MVT::v4f32, Expand); |
| 516 | setOperationAction(ISD::FLOG10, MVT::v4f32, Expand); |
| 517 | setOperationAction(ISD::FEXP, MVT::v4f32, Expand); |
| 518 | setOperationAction(ISD::FEXP2, MVT::v4f32, Expand); |
Craig Topper | 4901047 | 2012-11-15 06:51:10 +0000 | [diff] [blame] | 519 | setOperationAction(ISD::FCEIL, MVT::v4f32, Expand); |
| 520 | setOperationAction(ISD::FTRUNC, MVT::v4f32, Expand); |
| 521 | setOperationAction(ISD::FRINT, MVT::v4f32, Expand); |
| 522 | setOperationAction(ISD::FNEARBYINT, MVT::v4f32, Expand); |
Craig Topper | a1fb1d2 | 2012-09-08 04:58:43 +0000 | [diff] [blame] | 523 | setOperationAction(ISD::FFLOOR, MVT::v4f32, Expand); |
Bob Wilson | 74dc72e | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 524 | |
Arnold Schwaighofer | 21c0aa7 | 2013-03-02 19:38:33 +0000 | [diff] [blame^] | 525 | // Mark v2f32 intrinsics. |
| 526 | setOperationAction(ISD::FSQRT, MVT::v2f32, Expand); |
| 527 | setOperationAction(ISD::FSIN, MVT::v2f32, Expand); |
| 528 | setOperationAction(ISD::FCOS, MVT::v2f32, Expand); |
| 529 | setOperationAction(ISD::FPOWI, MVT::v2f32, Expand); |
| 530 | setOperationAction(ISD::FPOW, MVT::v2f32, Expand); |
| 531 | setOperationAction(ISD::FLOG, MVT::v2f32, Expand); |
| 532 | setOperationAction(ISD::FLOG2, MVT::v2f32, Expand); |
| 533 | setOperationAction(ISD::FLOG10, MVT::v2f32, Expand); |
| 534 | setOperationAction(ISD::FEXP, MVT::v2f32, Expand); |
| 535 | setOperationAction(ISD::FEXP2, MVT::v2f32, Expand); |
| 536 | setOperationAction(ISD::FCEIL, MVT::v2f32, Expand); |
| 537 | setOperationAction(ISD::FTRUNC, MVT::v2f32, Expand); |
| 538 | setOperationAction(ISD::FRINT, MVT::v2f32, Expand); |
| 539 | setOperationAction(ISD::FNEARBYINT, MVT::v2f32, Expand); |
| 540 | setOperationAction(ISD::FFLOOR, MVT::v2f32, Expand); |
| 541 | |
Bob Wilson | 642b329 | 2009-09-16 00:32:15 +0000 | [diff] [blame] | 542 | // Neon does not support some operations on v1i64 and v2i64 types. |
| 543 | setOperationAction(ISD::MUL, MVT::v1i64, Expand); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 544 | // Custom handling for some quad-vector types to detect VMULL. |
| 545 | setOperationAction(ISD::MUL, MVT::v8i16, Custom); |
| 546 | setOperationAction(ISD::MUL, MVT::v4i32, Custom); |
| 547 | setOperationAction(ISD::MUL, MVT::v2i64, Custom); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 548 | // Custom handling for some vector types to avoid expensive expansions |
| 549 | setOperationAction(ISD::SDIV, MVT::v4i16, Custom); |
| 550 | setOperationAction(ISD::SDIV, MVT::v8i8, Custom); |
| 551 | setOperationAction(ISD::UDIV, MVT::v4i16, Custom); |
| 552 | setOperationAction(ISD::UDIV, MVT::v8i8, Custom); |
Duncan Sands | 28b77e9 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 553 | setOperationAction(ISD::SETCC, MVT::v1i64, Expand); |
| 554 | setOperationAction(ISD::SETCC, MVT::v2i64, Expand); |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 555 | // Neon does not have single instruction SINT_TO_FP and UINT_TO_FP with |
James Molloy | 873fd5f | 2012-02-20 09:24:05 +0000 | [diff] [blame] | 556 | // a destination type that is wider than the source, and nor does |
| 557 | // it have a FP_TO_[SU]INT instruction with a narrower destination than |
| 558 | // source. |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 559 | setOperationAction(ISD::SINT_TO_FP, MVT::v4i16, Custom); |
| 560 | setOperationAction(ISD::UINT_TO_FP, MVT::v4i16, Custom); |
James Molloy | 873fd5f | 2012-02-20 09:24:05 +0000 | [diff] [blame] | 561 | setOperationAction(ISD::FP_TO_UINT, MVT::v4i16, Custom); |
| 562 | setOperationAction(ISD::FP_TO_SINT, MVT::v4i16, Custom); |
Bob Wilson | 642b329 | 2009-09-16 00:32:15 +0000 | [diff] [blame] | 563 | |
Eli Friedman | 846ce8e | 2012-11-15 22:44:27 +0000 | [diff] [blame] | 564 | setOperationAction(ISD::FP_ROUND, MVT::v2f32, Expand); |
Eli Friedman | 43147af | 2012-11-17 01:52:46 +0000 | [diff] [blame] | 565 | setOperationAction(ISD::FP_EXTEND, MVT::v2f64, Expand); |
Eli Friedman | 846ce8e | 2012-11-15 22:44:27 +0000 | [diff] [blame] | 566 | |
Evan Cheng | c8e7045 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 567 | // NEON does not have single instruction CTPOP for vectors with element |
| 568 | // types wider than 8-bits. However, custom lowering can leverage the |
| 569 | // v8i8/v16i8 vcnt instruction. |
| 570 | setOperationAction(ISD::CTPOP, MVT::v2i32, Custom); |
| 571 | setOperationAction(ISD::CTPOP, MVT::v4i32, Custom); |
| 572 | setOperationAction(ISD::CTPOP, MVT::v4i16, Custom); |
| 573 | setOperationAction(ISD::CTPOP, MVT::v8i16, Custom); |
| 574 | |
Jim Grosbach | b302a4e | 2013-02-27 21:31:12 +0000 | [diff] [blame] | 575 | // NEON only has FMA instructions as of VFP4. |
| 576 | if (!Subtarget->hasVFP4()) { |
| 577 | setOperationAction(ISD::FMA, MVT::v2f32, Expand); |
| 578 | setOperationAction(ISD::FMA, MVT::v4f32, Expand); |
| 579 | } |
| 580 | |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 581 | setTargetDAGCombine(ISD::INTRINSIC_VOID); |
| 582 | setTargetDAGCombine(ISD::INTRINSIC_W_CHAIN); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 583 | setTargetDAGCombine(ISD::INTRINSIC_WO_CHAIN); |
| 584 | setTargetDAGCombine(ISD::SHL); |
| 585 | setTargetDAGCombine(ISD::SRL); |
| 586 | setTargetDAGCombine(ISD::SRA); |
| 587 | setTargetDAGCombine(ISD::SIGN_EXTEND); |
| 588 | setTargetDAGCombine(ISD::ZERO_EXTEND); |
| 589 | setTargetDAGCombine(ISD::ANY_EXTEND); |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 590 | setTargetDAGCombine(ISD::SELECT_CC); |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 591 | setTargetDAGCombine(ISD::BUILD_VECTOR); |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 592 | setTargetDAGCombine(ISD::VECTOR_SHUFFLE); |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 593 | setTargetDAGCombine(ISD::INSERT_VECTOR_ELT); |
| 594 | setTargetDAGCombine(ISD::STORE); |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 595 | setTargetDAGCombine(ISD::FP_TO_SINT); |
| 596 | setTargetDAGCombine(ISD::FP_TO_UINT); |
| 597 | setTargetDAGCombine(ISD::FDIV); |
Nadav Rotem | 004a24b | 2011-10-15 20:03:12 +0000 | [diff] [blame] | 598 | |
James Molloy | 873fd5f | 2012-02-20 09:24:05 +0000 | [diff] [blame] | 599 | // It is legal to extload from v4i8 to v4i16 or v4i32. |
| 600 | MVT Tys[6] = {MVT::v8i8, MVT::v4i8, MVT::v2i8, |
| 601 | MVT::v4i16, MVT::v2i16, |
| 602 | MVT::v2i32}; |
| 603 | for (unsigned i = 0; i < 6; ++i) { |
| 604 | setLoadExtAction(ISD::EXTLOAD, Tys[i], Legal); |
| 605 | setLoadExtAction(ISD::ZEXTLOAD, Tys[i], Legal); |
| 606 | setLoadExtAction(ISD::SEXTLOAD, Tys[i], Legal); |
| 607 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 608 | } |
| 609 | |
Arnold Schwaighofer | 67514e9 | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 610 | // ARM and Thumb2 support UMLAL/SMLAL. |
| 611 | if (!Subtarget->isThumb1Only()) |
| 612 | setTargetDAGCombine(ISD::ADDC); |
| 613 | |
| 614 | |
Evan Cheng | 9f8cbd1 | 2007-05-18 00:19:34 +0000 | [diff] [blame] | 615 | computeRegisterProperties(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 616 | |
| 617 | // ARM does not have f32 extending load. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 618 | setLoadExtAction(ISD::EXTLOAD, MVT::f32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 619 | |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 620 | // ARM does not have i1 sign extending load. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 621 | setLoadExtAction(ISD::SEXTLOAD, MVT::i1, Promote); |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 622 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 623 | // ARM supports all 4 flavors of integer indexed load / store. |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 624 | if (!Subtarget->isThumb1Only()) { |
| 625 | for (unsigned im = (unsigned)ISD::PRE_INC; |
| 626 | im != (unsigned)ISD::LAST_INDEXED_MODE; ++im) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 627 | setIndexedLoadAction(im, MVT::i1, Legal); |
| 628 | setIndexedLoadAction(im, MVT::i8, Legal); |
| 629 | setIndexedLoadAction(im, MVT::i16, Legal); |
| 630 | setIndexedLoadAction(im, MVT::i32, Legal); |
| 631 | setIndexedStoreAction(im, MVT::i1, Legal); |
| 632 | setIndexedStoreAction(im, MVT::i8, Legal); |
| 633 | setIndexedStoreAction(im, MVT::i16, Legal); |
| 634 | setIndexedStoreAction(im, MVT::i32, Legal); |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 635 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | // i64 operation support. |
Eric Christopher | 2cc4013 | 2011-04-19 18:49:19 +0000 | [diff] [blame] | 639 | setOperationAction(ISD::MUL, MVT::i64, Expand); |
| 640 | setOperationAction(ISD::MULHU, MVT::i32, Expand); |
Evan Cheng | 5b9fcd1 | 2009-07-07 01:17:28 +0000 | [diff] [blame] | 641 | if (Subtarget->isThumb1Only()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 642 | setOperationAction(ISD::UMUL_LOHI, MVT::i32, Expand); |
| 643 | setOperationAction(ISD::SMUL_LOHI, MVT::i32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 644 | } |
Jim Grosbach | a760398 | 2011-07-01 21:12:19 +0000 | [diff] [blame] | 645 | if (Subtarget->isThumb1Only() || !Subtarget->hasV6Ops() |
| 646 | || (Subtarget->isThumb2() && !Subtarget->hasThumb2DSP())) |
Eric Christopher | 2cc4013 | 2011-04-19 18:49:19 +0000 | [diff] [blame] | 647 | setOperationAction(ISD::MULHS, MVT::i32, Expand); |
| 648 | |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 649 | setOperationAction(ISD::SHL_PARTS, MVT::i32, Custom); |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 650 | setOperationAction(ISD::SRA_PARTS, MVT::i32, Custom); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 651 | setOperationAction(ISD::SRL_PARTS, MVT::i32, Custom); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 652 | setOperationAction(ISD::SRL, MVT::i64, Custom); |
| 653 | setOperationAction(ISD::SRA, MVT::i64, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 654 | |
Evan Cheng | 342e316 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 655 | if (!Subtarget->isThumb1Only()) { |
| 656 | // FIXME: We should do this for Thumb1 as well. |
| 657 | setOperationAction(ISD::ADDC, MVT::i32, Custom); |
| 658 | setOperationAction(ISD::ADDE, MVT::i32, Custom); |
| 659 | setOperationAction(ISD::SUBC, MVT::i32, Custom); |
| 660 | setOperationAction(ISD::SUBE, MVT::i32, Custom); |
| 661 | } |
| 662 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 663 | // ARM does not have ROTL. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 664 | setOperationAction(ISD::ROTL, MVT::i32, Expand); |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 665 | setOperationAction(ISD::CTTZ, MVT::i32, Custom); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 666 | setOperationAction(ISD::CTPOP, MVT::i32, Expand); |
David Goodwin | 24062ac | 2009-06-26 20:47:43 +0000 | [diff] [blame] | 667 | if (!Subtarget->hasV5TOps() || Subtarget->isThumb1Only()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 668 | setOperationAction(ISD::CTLZ, MVT::i32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 669 | |
Chandler Carruth | 63974b2 | 2011-12-13 01:56:10 +0000 | [diff] [blame] | 670 | // These just redirect to CTTZ and CTLZ on ARM. |
| 671 | setOperationAction(ISD::CTTZ_ZERO_UNDEF , MVT::i32 , Expand); |
| 672 | setOperationAction(ISD::CTLZ_ZERO_UNDEF , MVT::i32 , Expand); |
| 673 | |
Lauro Ramos Venancio | 368f20f | 2007-03-16 22:54:16 +0000 | [diff] [blame] | 674 | // Only ARMv6 has BSWAP. |
| 675 | if (!Subtarget->hasV6Ops()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 676 | setOperationAction(ISD::BSWAP, MVT::i32, Expand); |
Lauro Ramos Venancio | 368f20f | 2007-03-16 22:54:16 +0000 | [diff] [blame] | 677 | |
Bob Wilson | eb1641d | 2012-09-29 21:43:49 +0000 | [diff] [blame] | 678 | if (!(Subtarget->hasDivide() && Subtarget->isThumb2()) && |
| 679 | !(Subtarget->hasDivideInARMMode() && !Subtarget->isThumb())) { |
| 680 | // 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] | 681 | setOperationAction(ISD::SDIV, MVT::i32, Expand); |
| 682 | setOperationAction(ISD::UDIV, MVT::i32, Expand); |
| 683 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 684 | setOperationAction(ISD::SREM, MVT::i32, Expand); |
| 685 | setOperationAction(ISD::UREM, MVT::i32, Expand); |
| 686 | setOperationAction(ISD::SDIVREM, MVT::i32, Expand); |
| 687 | setOperationAction(ISD::UDIVREM, MVT::i32, Expand); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 688 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 689 | setOperationAction(ISD::GlobalAddress, MVT::i32, Custom); |
| 690 | setOperationAction(ISD::ConstantPool, MVT::i32, Custom); |
| 691 | setOperationAction(ISD::GLOBAL_OFFSET_TABLE, MVT::i32, Custom); |
| 692 | setOperationAction(ISD::GlobalTLSAddress, MVT::i32, Custom); |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 693 | setOperationAction(ISD::BlockAddress, MVT::i32, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 694 | |
Evan Cheng | 4da0c7c | 2011-04-08 21:37:21 +0000 | [diff] [blame] | 695 | setOperationAction(ISD::TRAP, MVT::Other, Legal); |
Evan Cheng | fb3611d | 2010-05-11 07:26:32 +0000 | [diff] [blame] | 696 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 697 | // Use the default implementation. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 698 | setOperationAction(ISD::VASTART, MVT::Other, Custom); |
| 699 | setOperationAction(ISD::VAARG, MVT::Other, Expand); |
| 700 | setOperationAction(ISD::VACOPY, MVT::Other, Expand); |
| 701 | setOperationAction(ISD::VAEND, MVT::Other, Expand); |
| 702 | setOperationAction(ISD::STACKSAVE, MVT::Other, Expand); |
| 703 | setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand); |
Bill Wendling | bdf9db6 | 2012-02-13 23:47:16 +0000 | [diff] [blame] | 704 | |
| 705 | if (!Subtarget->isTargetDarwin()) { |
| 706 | // Non-Darwin platforms may return values in these registers via the |
| 707 | // personality function. |
| 708 | setOperationAction(ISD::EHSELECTION, MVT::i32, Expand); |
| 709 | setOperationAction(ISD::EXCEPTIONADDR, MVT::i32, Expand); |
| 710 | setExceptionPointerRegister(ARM::R0); |
| 711 | setExceptionSelectorRegister(ARM::R1); |
| 712 | } |
Anton Korobeynikov | 5899a60 | 2011-01-24 22:38:45 +0000 | [diff] [blame] | 713 | |
Evan Cheng | 3a1588a | 2010-04-15 22:20:34 +0000 | [diff] [blame] | 714 | setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32, Expand); |
Evan Cheng | 11db068 | 2010-08-11 06:22:01 +0000 | [diff] [blame] | 715 | // ARMv6 Thumb1 (except for CPUs that support dmb / dsb) and earlier use |
| 716 | // the default expansion. |
Eli Friedman | 4db5aca | 2011-08-29 18:23:02 +0000 | [diff] [blame] | 717 | // FIXME: This should be checking for v6k, not just v6. |
Evan Cheng | 11db068 | 2010-08-11 06:22:01 +0000 | [diff] [blame] | 718 | if (Subtarget->hasDataBarrier() || |
Bob Wilson | 54f9256 | 2010-11-09 22:50:44 +0000 | [diff] [blame] | 719 | (Subtarget->hasV6Ops() && !Subtarget->isThumb())) { |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 720 | // membarrier needs custom lowering; the rest are legal and handled |
| 721 | // normally. |
| 722 | setOperationAction(ISD::MEMBARRIER, MVT::Other, Custom); |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 723 | setOperationAction(ISD::ATOMIC_FENCE, MVT::Other, Custom); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 724 | // Custom lowering for 64-bit ops |
| 725 | setOperationAction(ISD::ATOMIC_LOAD_ADD, MVT::i64, Custom); |
| 726 | setOperationAction(ISD::ATOMIC_LOAD_SUB, MVT::i64, Custom); |
| 727 | setOperationAction(ISD::ATOMIC_LOAD_AND, MVT::i64, Custom); |
| 728 | setOperationAction(ISD::ATOMIC_LOAD_OR, MVT::i64, Custom); |
| 729 | setOperationAction(ISD::ATOMIC_LOAD_XOR, MVT::i64, Custom); |
Silviu Baranga | 35b3df6 | 2012-11-29 14:41:25 +0000 | [diff] [blame] | 730 | setOperationAction(ISD::ATOMIC_SWAP, MVT::i64, Custom); |
| 731 | setOperationAction(ISD::ATOMIC_LOAD_MIN, MVT::i64, Custom); |
| 732 | setOperationAction(ISD::ATOMIC_LOAD_MAX, MVT::i64, Custom); |
| 733 | setOperationAction(ISD::ATOMIC_LOAD_UMIN, MVT::i64, Custom); |
| 734 | setOperationAction(ISD::ATOMIC_LOAD_UMAX, MVT::i64, Custom); |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 735 | setOperationAction(ISD::ATOMIC_CMP_SWAP, MVT::i64, Custom); |
Eli Friedman | 26689ac | 2011-08-03 21:06:02 +0000 | [diff] [blame] | 736 | // Automatically insert fences (dmb ist) around ATOMIC_SWAP etc. |
| 737 | setInsertFencesForAtomic(true); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 738 | } else { |
| 739 | // Set them all for expansion, which will force libcalls. |
| 740 | setOperationAction(ISD::MEMBARRIER, MVT::Other, Expand); |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 741 | setOperationAction(ISD::ATOMIC_FENCE, MVT::Other, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 742 | setOperationAction(ISD::ATOMIC_CMP_SWAP, MVT::i32, Expand); |
Jim Grosbach | ef6eb9c | 2010-06-18 23:03:10 +0000 | [diff] [blame] | 743 | setOperationAction(ISD::ATOMIC_SWAP, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 744 | setOperationAction(ISD::ATOMIC_LOAD_ADD, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 745 | setOperationAction(ISD::ATOMIC_LOAD_SUB, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 746 | setOperationAction(ISD::ATOMIC_LOAD_AND, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 747 | setOperationAction(ISD::ATOMIC_LOAD_OR, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 748 | setOperationAction(ISD::ATOMIC_LOAD_XOR, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 749 | setOperationAction(ISD::ATOMIC_LOAD_NAND, MVT::i32, Expand); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 750 | setOperationAction(ISD::ATOMIC_LOAD_MIN, MVT::i32, Expand); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 751 | setOperationAction(ISD::ATOMIC_LOAD_MAX, MVT::i32, Expand); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 752 | setOperationAction(ISD::ATOMIC_LOAD_UMIN, MVT::i32, Expand); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 753 | setOperationAction(ISD::ATOMIC_LOAD_UMAX, MVT::i32, Expand); |
Eli Friedman | 7cc1566 | 2011-09-15 22:18:49 +0000 | [diff] [blame] | 754 | // Mark ATOMIC_LOAD and ATOMIC_STORE custom so we can handle the |
| 755 | // Unordered/Monotonic case. |
| 756 | setOperationAction(ISD::ATOMIC_LOAD, MVT::i32, Custom); |
| 757 | setOperationAction(ISD::ATOMIC_STORE, MVT::i32, Custom); |
Jim Grosbach | 5def57a | 2010-06-23 16:08:49 +0000 | [diff] [blame] | 758 | // Since the libcalls include locking, fold in the fences |
| 759 | setShouldFoldAtomicFences(true); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 760 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 761 | |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 762 | setOperationAction(ISD::PREFETCH, MVT::Other, Custom); |
Evan Cheng | bc7deb0 | 2010-11-03 05:14:24 +0000 | [diff] [blame] | 763 | |
Eli Friedman | a2c6f45 | 2010-06-26 04:36:50 +0000 | [diff] [blame] | 764 | // Requires SXTB/SXTH, available on v6 and up in both ARM and Thumb modes. |
| 765 | if (!Subtarget->hasV6Ops()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 766 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i16, Expand); |
| 767 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i8, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 768 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 769 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 770 | |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 771 | if (!TM.Options.UseSoftFloat && Subtarget->hasVFP2() && |
| 772 | !Subtarget->isThumb1Only()) { |
Bob Wilson | cb9a6aa | 2010-01-19 22:56:26 +0000 | [diff] [blame] | 773 | // Turn f64->i64 into VMOVRRD, i64 -> f64 to VMOVDRR |
Sylvestre Ledru | 94c2271 | 2012-09-27 10:14:43 +0000 | [diff] [blame] | 774 | // iff target supports vfp2. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 775 | setOperationAction(ISD::BITCAST, MVT::i64, Custom); |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 776 | setOperationAction(ISD::FLT_ROUNDS_, MVT::i32, Custom); |
| 777 | } |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 778 | |
| 779 | // We want to custom lower some of our intrinsics. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 780 | setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom); |
Jim Grosbach | e97f968 | 2010-07-07 00:07:57 +0000 | [diff] [blame] | 781 | if (Subtarget->isTargetDarwin()) { |
| 782 | setOperationAction(ISD::EH_SJLJ_SETJMP, MVT::i32, Custom); |
| 783 | setOperationAction(ISD::EH_SJLJ_LONGJMP, MVT::Other, Custom); |
John McCall | 5f8fd54 | 2011-05-29 19:50:32 +0000 | [diff] [blame] | 784 | setLibcallName(RTLIB::UNWIND_RESUME, "_Unwind_SjLj_Resume"); |
Jim Grosbach | e97f968 | 2010-07-07 00:07:57 +0000 | [diff] [blame] | 785 | } |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 786 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 787 | setOperationAction(ISD::SETCC, MVT::i32, Expand); |
| 788 | setOperationAction(ISD::SETCC, MVT::f32, Expand); |
| 789 | setOperationAction(ISD::SETCC, MVT::f64, Expand); |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 790 | setOperationAction(ISD::SELECT, MVT::i32, Custom); |
| 791 | setOperationAction(ISD::SELECT, MVT::f32, Custom); |
| 792 | setOperationAction(ISD::SELECT, MVT::f64, Custom); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 793 | setOperationAction(ISD::SELECT_CC, MVT::i32, Custom); |
| 794 | setOperationAction(ISD::SELECT_CC, MVT::f32, Custom); |
| 795 | setOperationAction(ISD::SELECT_CC, MVT::f64, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 796 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 797 | setOperationAction(ISD::BRCOND, MVT::Other, Expand); |
| 798 | setOperationAction(ISD::BR_CC, MVT::i32, Custom); |
| 799 | setOperationAction(ISD::BR_CC, MVT::f32, Custom); |
| 800 | setOperationAction(ISD::BR_CC, MVT::f64, Custom); |
| 801 | setOperationAction(ISD::BR_JT, MVT::Other, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 802 | |
Dan Gohman | f96e4de | 2007-10-11 23:21:31 +0000 | [diff] [blame] | 803 | // We don't support sin/cos/fmod/copysign/pow |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 804 | setOperationAction(ISD::FSIN, MVT::f64, Expand); |
| 805 | setOperationAction(ISD::FSIN, MVT::f32, Expand); |
| 806 | setOperationAction(ISD::FCOS, MVT::f32, Expand); |
| 807 | setOperationAction(ISD::FCOS, MVT::f64, Expand); |
Evan Cheng | 8688a58 | 2013-01-29 02:32:37 +0000 | [diff] [blame] | 808 | setOperationAction(ISD::FSINCOS, MVT::f64, Expand); |
| 809 | setOperationAction(ISD::FSINCOS, MVT::f32, Expand); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 810 | setOperationAction(ISD::FREM, MVT::f64, Expand); |
| 811 | setOperationAction(ISD::FREM, MVT::f32, Expand); |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 812 | if (!TM.Options.UseSoftFloat && Subtarget->hasVFP2() && |
| 813 | !Subtarget->isThumb1Only()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 814 | setOperationAction(ISD::FCOPYSIGN, MVT::f64, Custom); |
| 815 | setOperationAction(ISD::FCOPYSIGN, MVT::f32, Custom); |
Evan Cheng | 110cf48 | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 816 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 817 | setOperationAction(ISD::FPOW, MVT::f64, Expand); |
| 818 | setOperationAction(ISD::FPOW, MVT::f32, Expand); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 819 | |
Evan Cheng | 3aef2ff | 2012-04-10 21:40:28 +0000 | [diff] [blame] | 820 | if (!Subtarget->hasVFP4()) { |
| 821 | setOperationAction(ISD::FMA, MVT::f64, Expand); |
| 822 | setOperationAction(ISD::FMA, MVT::f32, Expand); |
| 823 | } |
Cameron Zwarich | 3339084 | 2011-07-08 21:39:21 +0000 | [diff] [blame] | 824 | |
Anton Korobeynikov | bec3dd2 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 825 | // Various VFP goodness |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 826 | if (!TM.Options.UseSoftFloat && !Subtarget->isThumb1Only()) { |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 827 | // int <-> fp are custom expanded into bit_convert + ARMISD ops. |
| 828 | if (Subtarget->hasVFP2()) { |
| 829 | setOperationAction(ISD::SINT_TO_FP, MVT::i32, Custom); |
| 830 | setOperationAction(ISD::UINT_TO_FP, MVT::i32, Custom); |
| 831 | setOperationAction(ISD::FP_TO_UINT, MVT::i32, Custom); |
| 832 | setOperationAction(ISD::FP_TO_SINT, MVT::i32, Custom); |
| 833 | } |
Anton Korobeynikov | bec3dd2 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 834 | // Special handling for half-precision FP. |
Anton Korobeynikov | f0d5007 | 2010-03-18 22:35:37 +0000 | [diff] [blame] | 835 | if (!Subtarget->hasFP16()) { |
| 836 | setOperationAction(ISD::FP16_TO_FP32, MVT::f32, Expand); |
| 837 | setOperationAction(ISD::FP32_TO_FP16, MVT::i32, Expand); |
Anton Korobeynikov | bec3dd2 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 838 | } |
Evan Cheng | 110cf48 | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 839 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 840 | |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 841 | // We have target-specific dag combine patterns for the following nodes: |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 842 | // ARMISD::VMOVRRD - No need to call setTargetDAGCombine |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 843 | setTargetDAGCombine(ISD::ADD); |
| 844 | setTargetDAGCombine(ISD::SUB); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 845 | setTargetDAGCombine(ISD::MUL); |
Jakob Stoklund Olesen | a7390fa | 2012-09-07 17:34:15 +0000 | [diff] [blame] | 846 | setTargetDAGCombine(ISD::AND); |
| 847 | setTargetDAGCombine(ISD::OR); |
| 848 | setTargetDAGCombine(ISD::XOR); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 849 | |
Evan Cheng | 5fb468a | 2012-02-23 02:58:19 +0000 | [diff] [blame] | 850 | if (Subtarget->hasV6Ops()) |
| 851 | setTargetDAGCombine(ISD::SRL); |
| 852 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 853 | setStackPointerRegisterToSaveRestore(ARM::SP); |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 854 | |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 855 | if (TM.Options.UseSoftFloat || Subtarget->isThumb1Only() || |
| 856 | !Subtarget->hasVFP2()) |
Evan Cheng | f7d87ee | 2010-05-21 00:43:17 +0000 | [diff] [blame] | 857 | setSchedulingPreference(Sched::RegPressure); |
| 858 | else |
| 859 | setSchedulingPreference(Sched::Hybrid); |
Dale Johannesen | 8dd86c1 | 2007-05-17 21:31:21 +0000 | [diff] [blame] | 860 | |
Evan Cheng | 0521928 | 2011-01-06 06:52:41 +0000 | [diff] [blame] | 861 | //// temporary - rewrite interface to use type |
Jim Grosbach | 3450f80 | 2013-02-20 21:13:59 +0000 | [diff] [blame] | 862 | MaxStoresPerMemset = 8; |
| 863 | MaxStoresPerMemsetOptSize = Subtarget->isTargetDarwin() ? 8 : 4; |
| 864 | MaxStoresPerMemcpy = 4; // For @llvm.memcpy -> sequence of stores |
| 865 | MaxStoresPerMemcpyOptSize = Subtarget->isTargetDarwin() ? 4 : 2; |
| 866 | MaxStoresPerMemmove = 4; // For @llvm.memmove -> sequence of stores |
| 867 | MaxStoresPerMemmoveOptSize = Subtarget->isTargetDarwin() ? 4 : 2; |
Evan Cheng | f679939 | 2010-06-26 01:52:05 +0000 | [diff] [blame] | 868 | |
Rafael Espindola | cbeeae2 | 2010-07-11 04:01:49 +0000 | [diff] [blame] | 869 | // On ARM arguments smaller than 4 bytes are extended, so all arguments |
| 870 | // are at least 4 bytes aligned. |
| 871 | setMinStackArgumentAlignment(4); |
| 872 | |
Jim Grosbach | 3450f80 | 2013-02-20 21:13:59 +0000 | [diff] [blame] | 873 | BenefitFromCodePlacementOpt = true; |
Eli Friedman | fc5d305 | 2011-05-06 20:34:06 +0000 | [diff] [blame] | 874 | |
Benjamin Kramer | aaf723d | 2012-05-05 12:49:14 +0000 | [diff] [blame] | 875 | // Prefer likely predicted branches to selects on out-of-order cores. |
Jim Grosbach | 3450f80 | 2013-02-20 21:13:59 +0000 | [diff] [blame] | 876 | PredictableSelectIsExpensive = Subtarget->isLikeA9(); |
Benjamin Kramer | aaf723d | 2012-05-05 12:49:14 +0000 | [diff] [blame] | 877 | |
Eli Friedman | fc5d305 | 2011-05-06 20:34:06 +0000 | [diff] [blame] | 878 | setMinFunctionAlignment(Subtarget->isThumb() ? 1 : 2); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 879 | } |
| 880 | |
Andrew Trick | 32cec0a | 2011-01-19 02:35:27 +0000 | [diff] [blame] | 881 | // FIXME: It might make sense to define the representative register class as the |
| 882 | // nearest super-register that has a non-null superset. For example, DPR_VFP2 is |
| 883 | // a super-register of SPR, and DPR is a superset if DPR_VFP2. Consequently, |
| 884 | // SPR's representative would be DPR_VFP2. This should work well if register |
| 885 | // pressure tracking were modified such that a register use would increment the |
| 886 | // pressure of the register class's representative and all of it's super |
| 887 | // classes' representatives transitively. We have not implemented this because |
| 888 | // of the difficulty prior to coalescing of modeling operand register classes |
Chris Lattner | 7a2bdde | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 889 | // due to the common occurrence of cross class copies and subregister insertions |
Andrew Trick | 32cec0a | 2011-01-19 02:35:27 +0000 | [diff] [blame] | 890 | // and extractions. |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 891 | std::pair<const TargetRegisterClass*, uint8_t> |
Patrik Hagglund | 0340557 | 2012-12-19 11:30:36 +0000 | [diff] [blame] | 892 | ARMTargetLowering::findRepresentativeClass(MVT VT) const{ |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 893 | const TargetRegisterClass *RRC = 0; |
| 894 | uint8_t Cost = 1; |
Patrik Hagglund | 0340557 | 2012-12-19 11:30:36 +0000 | [diff] [blame] | 895 | switch (VT.SimpleTy) { |
Evan Cheng | d70f57b | 2010-07-19 22:15:08 +0000 | [diff] [blame] | 896 | default: |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 897 | return TargetLowering::findRepresentativeClass(VT); |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 898 | // Use DPR as representative register class for all floating point |
| 899 | // and vector types. Since there are 32 SPR registers and 32 DPR registers so |
| 900 | // the cost is 1 for both f32 and f64. |
| 901 | case MVT::f32: case MVT::f64: case MVT::v8i8: case MVT::v4i16: |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 902 | case MVT::v2i32: case MVT::v1i64: case MVT::v2f32: |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 903 | RRC = &ARM::DPRRegClass; |
Andrew Trick | 32cec0a | 2011-01-19 02:35:27 +0000 | [diff] [blame] | 904 | // When NEON is used for SP, only half of the register file is available |
| 905 | // because operations that define both SP and DP results will be constrained |
| 906 | // to the VFP2 class (D0-D15). We currently model this constraint prior to |
| 907 | // coalescing by double-counting the SP regs. See the FIXME above. |
| 908 | if (Subtarget->useNEONForSinglePrecisionFP()) |
| 909 | Cost = 2; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 910 | break; |
| 911 | case MVT::v16i8: case MVT::v8i16: case MVT::v4i32: case MVT::v2i64: |
| 912 | case MVT::v4f32: case MVT::v2f64: |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 913 | RRC = &ARM::DPRRegClass; |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 914 | Cost = 2; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 915 | break; |
| 916 | case MVT::v4i64: |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 917 | RRC = &ARM::DPRRegClass; |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 918 | Cost = 4; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 919 | break; |
| 920 | case MVT::v8i64: |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 921 | RRC = &ARM::DPRRegClass; |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 922 | Cost = 8; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 923 | break; |
Evan Cheng | d70f57b | 2010-07-19 22:15:08 +0000 | [diff] [blame] | 924 | } |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 925 | return std::make_pair(RRC, Cost); |
Evan Cheng | d70f57b | 2010-07-19 22:15:08 +0000 | [diff] [blame] | 926 | } |
| 927 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 928 | const char *ARMTargetLowering::getTargetNodeName(unsigned Opcode) const { |
| 929 | switch (Opcode) { |
| 930 | default: return 0; |
| 931 | case ARMISD::Wrapper: return "ARMISD::Wrapper"; |
Evan Cheng | 53519f0 | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 932 | case ARMISD::WrapperDYN: return "ARMISD::WrapperDYN"; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 933 | case ARMISD::WrapperPIC: return "ARMISD::WrapperPIC"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 934 | case ARMISD::WrapperJT: return "ARMISD::WrapperJT"; |
| 935 | case ARMISD::CALL: return "ARMISD::CALL"; |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 936 | case ARMISD::CALL_PRED: return "ARMISD::CALL_PRED"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 937 | case ARMISD::CALL_NOLINK: return "ARMISD::CALL_NOLINK"; |
| 938 | case ARMISD::tCALL: return "ARMISD::tCALL"; |
| 939 | case ARMISD::BRCOND: return "ARMISD::BRCOND"; |
| 940 | case ARMISD::BR_JT: return "ARMISD::BR_JT"; |
Evan Cheng | 5657c01 | 2009-07-29 02:18:14 +0000 | [diff] [blame] | 941 | case ARMISD::BR2_JT: return "ARMISD::BR2_JT"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 942 | case ARMISD::RET_FLAG: return "ARMISD::RET_FLAG"; |
| 943 | case ARMISD::PIC_ADD: return "ARMISD::PIC_ADD"; |
| 944 | case ARMISD::CMP: return "ARMISD::CMP"; |
Bill Wendling | ad5c880 | 2012-06-11 08:07:26 +0000 | [diff] [blame] | 945 | case ARMISD::CMN: return "ARMISD::CMN"; |
David Goodwin | c0309b4 | 2009-06-29 15:33:01 +0000 | [diff] [blame] | 946 | case ARMISD::CMPZ: return "ARMISD::CMPZ"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 947 | case ARMISD::CMPFP: return "ARMISD::CMPFP"; |
| 948 | case ARMISD::CMPFPw0: return "ARMISD::CMPFPw0"; |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 949 | case ARMISD::BCC_i64: return "ARMISD::BCC_i64"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 950 | case ARMISD::FMSTAT: return "ARMISD::FMSTAT"; |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 951 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 952 | case ARMISD::CMOV: return "ARMISD::CMOV"; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 953 | |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 954 | case ARMISD::RBIT: return "ARMISD::RBIT"; |
| 955 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 956 | case ARMISD::FTOSI: return "ARMISD::FTOSI"; |
| 957 | case ARMISD::FTOUI: return "ARMISD::FTOUI"; |
| 958 | case ARMISD::SITOF: return "ARMISD::SITOF"; |
| 959 | case ARMISD::UITOF: return "ARMISD::UITOF"; |
| 960 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 961 | case ARMISD::SRL_FLAG: return "ARMISD::SRL_FLAG"; |
| 962 | case ARMISD::SRA_FLAG: return "ARMISD::SRA_FLAG"; |
| 963 | case ARMISD::RRX: return "ARMISD::RRX"; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 964 | |
Evan Cheng | 342e316 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 965 | case ARMISD::ADDC: return "ARMISD::ADDC"; |
| 966 | case ARMISD::ADDE: return "ARMISD::ADDE"; |
| 967 | case ARMISD::SUBC: return "ARMISD::SUBC"; |
| 968 | case ARMISD::SUBE: return "ARMISD::SUBE"; |
| 969 | |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 970 | case ARMISD::VMOVRRD: return "ARMISD::VMOVRRD"; |
| 971 | case ARMISD::VMOVDRR: return "ARMISD::VMOVDRR"; |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 972 | |
Evan Cheng | c594208 | 2009-10-28 06:55:03 +0000 | [diff] [blame] | 973 | case ARMISD::EH_SJLJ_SETJMP: return "ARMISD::EH_SJLJ_SETJMP"; |
| 974 | case ARMISD::EH_SJLJ_LONGJMP:return "ARMISD::EH_SJLJ_LONGJMP"; |
| 975 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 976 | case ARMISD::TC_RETURN: return "ARMISD::TC_RETURN"; |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 977 | |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 978 | case ARMISD::THREAD_POINTER:return "ARMISD::THREAD_POINTER"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 979 | |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 980 | case ARMISD::DYN_ALLOC: return "ARMISD::DYN_ALLOC"; |
| 981 | |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 982 | case ARMISD::MEMBARRIER: return "ARMISD::MEMBARRIER"; |
Bob Wilson | f74a429 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 983 | case ARMISD::MEMBARRIER_MCR: return "ARMISD::MEMBARRIER_MCR"; |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 984 | |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 985 | case ARMISD::PRELOAD: return "ARMISD::PRELOAD"; |
| 986 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 987 | case ARMISD::VCEQ: return "ARMISD::VCEQ"; |
Bob Wilson | 3a75b9b | 2010-12-18 00:04:26 +0000 | [diff] [blame] | 988 | case ARMISD::VCEQZ: return "ARMISD::VCEQZ"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 989 | case ARMISD::VCGE: return "ARMISD::VCGE"; |
Bob Wilson | 3a75b9b | 2010-12-18 00:04:26 +0000 | [diff] [blame] | 990 | case ARMISD::VCGEZ: return "ARMISD::VCGEZ"; |
| 991 | case ARMISD::VCLEZ: return "ARMISD::VCLEZ"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 992 | case ARMISD::VCGEU: return "ARMISD::VCGEU"; |
| 993 | case ARMISD::VCGT: return "ARMISD::VCGT"; |
Bob Wilson | 3a75b9b | 2010-12-18 00:04:26 +0000 | [diff] [blame] | 994 | case ARMISD::VCGTZ: return "ARMISD::VCGTZ"; |
| 995 | case ARMISD::VCLTZ: return "ARMISD::VCLTZ"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 996 | case ARMISD::VCGTU: return "ARMISD::VCGTU"; |
| 997 | case ARMISD::VTST: return "ARMISD::VTST"; |
| 998 | |
| 999 | case ARMISD::VSHL: return "ARMISD::VSHL"; |
| 1000 | case ARMISD::VSHRs: return "ARMISD::VSHRs"; |
| 1001 | case ARMISD::VSHRu: return "ARMISD::VSHRu"; |
| 1002 | case ARMISD::VSHLLs: return "ARMISD::VSHLLs"; |
| 1003 | case ARMISD::VSHLLu: return "ARMISD::VSHLLu"; |
| 1004 | case ARMISD::VSHLLi: return "ARMISD::VSHLLi"; |
| 1005 | case ARMISD::VSHRN: return "ARMISD::VSHRN"; |
| 1006 | case ARMISD::VRSHRs: return "ARMISD::VRSHRs"; |
| 1007 | case ARMISD::VRSHRu: return "ARMISD::VRSHRu"; |
| 1008 | case ARMISD::VRSHRN: return "ARMISD::VRSHRN"; |
| 1009 | case ARMISD::VQSHLs: return "ARMISD::VQSHLs"; |
| 1010 | case ARMISD::VQSHLu: return "ARMISD::VQSHLu"; |
| 1011 | case ARMISD::VQSHLsu: return "ARMISD::VQSHLsu"; |
| 1012 | case ARMISD::VQSHRNs: return "ARMISD::VQSHRNs"; |
| 1013 | case ARMISD::VQSHRNu: return "ARMISD::VQSHRNu"; |
| 1014 | case ARMISD::VQSHRNsu: return "ARMISD::VQSHRNsu"; |
| 1015 | case ARMISD::VQRSHRNs: return "ARMISD::VQRSHRNs"; |
| 1016 | case ARMISD::VQRSHRNu: return "ARMISD::VQRSHRNu"; |
| 1017 | case ARMISD::VQRSHRNsu: return "ARMISD::VQRSHRNsu"; |
| 1018 | case ARMISD::VGETLANEu: return "ARMISD::VGETLANEu"; |
| 1019 | case ARMISD::VGETLANEs: return "ARMISD::VGETLANEs"; |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 1020 | case ARMISD::VMOVIMM: return "ARMISD::VMOVIMM"; |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 1021 | case ARMISD::VMVNIMM: return "ARMISD::VMVNIMM"; |
Evan Cheng | eaa192a | 2011-11-15 02:12:34 +0000 | [diff] [blame] | 1022 | case ARMISD::VMOVFPIMM: return "ARMISD::VMOVFPIMM"; |
Bob Wilson | c1d287b | 2009-08-14 05:13:08 +0000 | [diff] [blame] | 1023 | case ARMISD::VDUP: return "ARMISD::VDUP"; |
Bob Wilson | 0ce3710 | 2009-08-14 05:08:32 +0000 | [diff] [blame] | 1024 | case ARMISD::VDUPLANE: return "ARMISD::VDUPLANE"; |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 1025 | case ARMISD::VEXT: return "ARMISD::VEXT"; |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 1026 | case ARMISD::VREV64: return "ARMISD::VREV64"; |
| 1027 | case ARMISD::VREV32: return "ARMISD::VREV32"; |
| 1028 | case ARMISD::VREV16: return "ARMISD::VREV16"; |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 1029 | case ARMISD::VZIP: return "ARMISD::VZIP"; |
| 1030 | case ARMISD::VUZP: return "ARMISD::VUZP"; |
| 1031 | case ARMISD::VTRN: return "ARMISD::VTRN"; |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 1032 | case ARMISD::VTBL1: return "ARMISD::VTBL1"; |
| 1033 | case ARMISD::VTBL2: return "ARMISD::VTBL2"; |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 1034 | case ARMISD::VMULLs: return "ARMISD::VMULLs"; |
| 1035 | case ARMISD::VMULLu: return "ARMISD::VMULLu"; |
Arnold Schwaighofer | 67514e9 | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 1036 | case ARMISD::UMLAL: return "ARMISD::UMLAL"; |
| 1037 | case ARMISD::SMLAL: return "ARMISD::SMLAL"; |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 1038 | case ARMISD::BUILD_VECTOR: return "ARMISD::BUILD_VECTOR"; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 1039 | case ARMISD::FMAX: return "ARMISD::FMAX"; |
| 1040 | case ARMISD::FMIN: return "ARMISD::FMIN"; |
Jim Grosbach | dd7d28a | 2010-07-17 01:50:57 +0000 | [diff] [blame] | 1041 | case ARMISD::BFI: return "ARMISD::BFI"; |
Bob Wilson | 364a72a | 2010-11-28 06:51:11 +0000 | [diff] [blame] | 1042 | case ARMISD::VORRIMM: return "ARMISD::VORRIMM"; |
| 1043 | case ARMISD::VBICIMM: return "ARMISD::VBICIMM"; |
Cameron Zwarich | c0e6d78 | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 1044 | case ARMISD::VBSL: return "ARMISD::VBSL"; |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 1045 | case ARMISD::VLD2DUP: return "ARMISD::VLD2DUP"; |
| 1046 | case ARMISD::VLD3DUP: return "ARMISD::VLD3DUP"; |
| 1047 | case ARMISD::VLD4DUP: return "ARMISD::VLD4DUP"; |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 1048 | case ARMISD::VLD1_UPD: return "ARMISD::VLD1_UPD"; |
| 1049 | case ARMISD::VLD2_UPD: return "ARMISD::VLD2_UPD"; |
| 1050 | case ARMISD::VLD3_UPD: return "ARMISD::VLD3_UPD"; |
| 1051 | case ARMISD::VLD4_UPD: return "ARMISD::VLD4_UPD"; |
| 1052 | case ARMISD::VLD2LN_UPD: return "ARMISD::VLD2LN_UPD"; |
| 1053 | case ARMISD::VLD3LN_UPD: return "ARMISD::VLD3LN_UPD"; |
| 1054 | case ARMISD::VLD4LN_UPD: return "ARMISD::VLD4LN_UPD"; |
| 1055 | case ARMISD::VLD2DUP_UPD: return "ARMISD::VLD2DUP_UPD"; |
| 1056 | case ARMISD::VLD3DUP_UPD: return "ARMISD::VLD3DUP_UPD"; |
| 1057 | case ARMISD::VLD4DUP_UPD: return "ARMISD::VLD4DUP_UPD"; |
| 1058 | case ARMISD::VST1_UPD: return "ARMISD::VST1_UPD"; |
| 1059 | case ARMISD::VST2_UPD: return "ARMISD::VST2_UPD"; |
| 1060 | case ARMISD::VST3_UPD: return "ARMISD::VST3_UPD"; |
| 1061 | case ARMISD::VST4_UPD: return "ARMISD::VST4_UPD"; |
| 1062 | case ARMISD::VST2LN_UPD: return "ARMISD::VST2LN_UPD"; |
| 1063 | case ARMISD::VST3LN_UPD: return "ARMISD::VST3LN_UPD"; |
| 1064 | case ARMISD::VST4LN_UPD: return "ARMISD::VST4LN_UPD"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1065 | } |
| 1066 | } |
| 1067 | |
Duncan Sands | 28b77e9 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 1068 | EVT ARMTargetLowering::getSetCCResultType(EVT VT) const { |
| 1069 | if (!VT.isVector()) return getPointerTy(); |
| 1070 | return VT.changeVectorElementTypeToInteger(); |
| 1071 | } |
| 1072 | |
Evan Cheng | 06b666c | 2010-05-15 02:18:07 +0000 | [diff] [blame] | 1073 | /// getRegClassFor - Return the register class that should be used for the |
| 1074 | /// specified value type. |
Patrik Hagglund | a61b17c | 2012-12-13 06:34:11 +0000 | [diff] [blame] | 1075 | const TargetRegisterClass *ARMTargetLowering::getRegClassFor(MVT VT) const { |
Evan Cheng | 06b666c | 2010-05-15 02:18:07 +0000 | [diff] [blame] | 1076 | // Map v4i64 to QQ registers but do not make the type legal. Similarly map |
| 1077 | // v8i64 to QQQQ registers. v4i64 and v8i64 are only used for REG_SEQUENCE to |
| 1078 | // load / store 4 to 8 consecutive D registers. |
Evan Cheng | 4782b1e | 2010-05-15 02:20:21 +0000 | [diff] [blame] | 1079 | if (Subtarget->hasNEON()) { |
| 1080 | if (VT == MVT::v4i64) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 1081 | return &ARM::QQPRRegClass; |
| 1082 | if (VT == MVT::v8i64) |
| 1083 | return &ARM::QQQQPRRegClass; |
Evan Cheng | 4782b1e | 2010-05-15 02:20:21 +0000 | [diff] [blame] | 1084 | } |
Evan Cheng | 06b666c | 2010-05-15 02:18:07 +0000 | [diff] [blame] | 1085 | return TargetLowering::getRegClassFor(VT); |
| 1086 | } |
| 1087 | |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 1088 | // Create a fast isel object. |
| 1089 | FastISel * |
Bob Wilson | d49edb7 | 2012-08-03 04:06:28 +0000 | [diff] [blame] | 1090 | ARMTargetLowering::createFastISel(FunctionLoweringInfo &funcInfo, |
| 1091 | const TargetLibraryInfo *libInfo) const { |
| 1092 | return ARM::createFastISel(funcInfo, libInfo); |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 1093 | } |
| 1094 | |
Anton Korobeynikov | cec36f4 | 2010-07-24 21:52:08 +0000 | [diff] [blame] | 1095 | /// getMaximalGlobalOffset - Returns the maximal possible offset which can |
| 1096 | /// be used for loads / stores from the global. |
| 1097 | unsigned ARMTargetLowering::getMaximalGlobalOffset() const { |
| 1098 | return (Subtarget->isThumb1Only() ? 127 : 4095); |
| 1099 | } |
| 1100 | |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1101 | Sched::Preference ARMTargetLowering::getSchedulingPreference(SDNode *N) const { |
Evan Cheng | c10f543 | 2010-05-28 23:25:23 +0000 | [diff] [blame] | 1102 | unsigned NumVals = N->getNumValues(); |
| 1103 | if (!NumVals) |
| 1104 | return Sched::RegPressure; |
| 1105 | |
| 1106 | for (unsigned i = 0; i != NumVals; ++i) { |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1107 | EVT VT = N->getValueType(i); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 1108 | if (VT == MVT::Glue || VT == MVT::Other) |
Evan Cheng | d7e473c | 2010-10-29 18:07:31 +0000 | [diff] [blame] | 1109 | continue; |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1110 | if (VT.isFloatingPoint() || VT.isVector()) |
Dan Gohman | 692c1d8 | 2011-10-24 17:55:11 +0000 | [diff] [blame] | 1111 | return Sched::ILP; |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1112 | } |
Evan Cheng | c10f543 | 2010-05-28 23:25:23 +0000 | [diff] [blame] | 1113 | |
| 1114 | if (!N->isMachineOpcode()) |
| 1115 | return Sched::RegPressure; |
| 1116 | |
| 1117 | // Load are scheduled for latency even if there instruction itinerary |
| 1118 | // is not available. |
| 1119 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 1120 | const MCInstrDesc &MCID = TII->get(N->getMachineOpcode()); |
Evan Cheng | d7e473c | 2010-10-29 18:07:31 +0000 | [diff] [blame] | 1121 | |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 1122 | if (MCID.getNumDefs() == 0) |
Evan Cheng | d7e473c | 2010-10-29 18:07:31 +0000 | [diff] [blame] | 1123 | return Sched::RegPressure; |
| 1124 | if (!Itins->isEmpty() && |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 1125 | Itins->getOperandCycle(MCID.getSchedClass(), 0) > 2) |
Dan Gohman | 692c1d8 | 2011-10-24 17:55:11 +0000 | [diff] [blame] | 1126 | return Sched::ILP; |
Evan Cheng | c10f543 | 2010-05-28 23:25:23 +0000 | [diff] [blame] | 1127 | |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1128 | return Sched::RegPressure; |
| 1129 | } |
| 1130 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1131 | //===----------------------------------------------------------------------===// |
| 1132 | // Lowering Code |
| 1133 | //===----------------------------------------------------------------------===// |
| 1134 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1135 | /// IntCCToARMCC - Convert a DAG integer condition code to an ARM CC |
| 1136 | static ARMCC::CondCodes IntCCToARMCC(ISD::CondCode CC) { |
| 1137 | switch (CC) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1138 | default: llvm_unreachable("Unknown condition code!"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1139 | case ISD::SETNE: return ARMCC::NE; |
| 1140 | case ISD::SETEQ: return ARMCC::EQ; |
| 1141 | case ISD::SETGT: return ARMCC::GT; |
| 1142 | case ISD::SETGE: return ARMCC::GE; |
| 1143 | case ISD::SETLT: return ARMCC::LT; |
| 1144 | case ISD::SETLE: return ARMCC::LE; |
| 1145 | case ISD::SETUGT: return ARMCC::HI; |
| 1146 | case ISD::SETUGE: return ARMCC::HS; |
| 1147 | case ISD::SETULT: return ARMCC::LO; |
| 1148 | case ISD::SETULE: return ARMCC::LS; |
| 1149 | } |
| 1150 | } |
| 1151 | |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 1152 | /// FPCCToARMCC - Convert a DAG fp condition code to an ARM CC. |
| 1153 | static void FPCCToARMCC(ISD::CondCode CC, ARMCC::CondCodes &CondCode, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1154 | ARMCC::CondCodes &CondCode2) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1155 | CondCode2 = ARMCC::AL; |
| 1156 | switch (CC) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1157 | default: llvm_unreachable("Unknown FP condition!"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1158 | case ISD::SETEQ: |
| 1159 | case ISD::SETOEQ: CondCode = ARMCC::EQ; break; |
| 1160 | case ISD::SETGT: |
| 1161 | case ISD::SETOGT: CondCode = ARMCC::GT; break; |
| 1162 | case ISD::SETGE: |
| 1163 | case ISD::SETOGE: CondCode = ARMCC::GE; break; |
| 1164 | case ISD::SETOLT: CondCode = ARMCC::MI; break; |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 1165 | case ISD::SETOLE: CondCode = ARMCC::LS; break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1166 | case ISD::SETONE: CondCode = ARMCC::MI; CondCode2 = ARMCC::GT; break; |
| 1167 | case ISD::SETO: CondCode = ARMCC::VC; break; |
| 1168 | case ISD::SETUO: CondCode = ARMCC::VS; break; |
| 1169 | case ISD::SETUEQ: CondCode = ARMCC::EQ; CondCode2 = ARMCC::VS; break; |
| 1170 | case ISD::SETUGT: CondCode = ARMCC::HI; break; |
| 1171 | case ISD::SETUGE: CondCode = ARMCC::PL; break; |
| 1172 | case ISD::SETLT: |
| 1173 | case ISD::SETULT: CondCode = ARMCC::LT; break; |
| 1174 | case ISD::SETLE: |
| 1175 | case ISD::SETULE: CondCode = ARMCC::LE; break; |
| 1176 | case ISD::SETNE: |
| 1177 | case ISD::SETUNE: CondCode = ARMCC::NE; break; |
| 1178 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1179 | } |
| 1180 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1181 | //===----------------------------------------------------------------------===// |
| 1182 | // Calling Convention Implementation |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1183 | //===----------------------------------------------------------------------===// |
| 1184 | |
| 1185 | #include "ARMGenCallingConv.inc" |
| 1186 | |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1187 | /// CCAssignFnForNode - Selects the correct CCAssignFn for a the |
| 1188 | /// given CallingConvention value. |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1189 | CCAssignFn *ARMTargetLowering::CCAssignFnForNode(CallingConv::ID CC, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1190 | bool Return, |
| 1191 | bool isVarArg) const { |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1192 | switch (CC) { |
| 1193 | default: |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1194 | llvm_unreachable("Unsupported calling convention"); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1195 | case CallingConv::Fast: |
Evan Cheng | 5c2d428 | 2010-10-23 02:19:37 +0000 | [diff] [blame] | 1196 | if (Subtarget->hasVFP2() && !isVarArg) { |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1197 | if (!Subtarget->isAAPCS_ABI()) |
| 1198 | return (Return ? RetFastCC_ARM_APCS : FastCC_ARM_APCS); |
| 1199 | // For AAPCS ABI targets, just use VFP variant of the calling convention. |
| 1200 | return (Return ? RetCC_ARM_AAPCS_VFP : CC_ARM_AAPCS_VFP); |
| 1201 | } |
| 1202 | // Fallthrough |
| 1203 | case CallingConv::C: { |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1204 | // Use target triple & subtarget features to do actual dispatch. |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1205 | if (!Subtarget->isAAPCS_ABI()) |
| 1206 | return (Return ? RetCC_ARM_APCS : CC_ARM_APCS); |
| 1207 | else if (Subtarget->hasVFP2() && |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 1208 | getTargetMachine().Options.FloatABIType == FloatABI::Hard && |
| 1209 | !isVarArg) |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1210 | return (Return ? RetCC_ARM_AAPCS_VFP : CC_ARM_AAPCS_VFP); |
| 1211 | return (Return ? RetCC_ARM_AAPCS : CC_ARM_AAPCS); |
| 1212 | } |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1213 | case CallingConv::ARM_AAPCS_VFP: |
Anton Korobeynikov | f349cb8 | 2012-01-29 09:06:09 +0000 | [diff] [blame] | 1214 | if (!isVarArg) |
| 1215 | return (Return ? RetCC_ARM_AAPCS_VFP : CC_ARM_AAPCS_VFP); |
| 1216 | // Fallthrough |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1217 | case CallingConv::ARM_AAPCS: |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1218 | return (Return ? RetCC_ARM_AAPCS : CC_ARM_AAPCS); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1219 | case CallingConv::ARM_APCS: |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1220 | return (Return ? RetCC_ARM_APCS : CC_ARM_APCS); |
Eric Christopher | e94ac88 | 2012-08-03 00:05:53 +0000 | [diff] [blame] | 1221 | case CallingConv::GHC: |
| 1222 | return (Return ? RetCC_ARM_APCS : CC_ARM_APCS_GHC); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1223 | } |
| 1224 | } |
| 1225 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1226 | /// LowerCallResult - Lower the result values of a call into the |
| 1227 | /// appropriate copies out of appropriate physical registers. |
| 1228 | SDValue |
| 1229 | ARMTargetLowering::LowerCallResult(SDValue Chain, SDValue InFlag, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1230 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1231 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 1232 | DebugLoc dl, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1233 | SmallVectorImpl<SDValue> &InVals) const { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1234 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1235 | // Assign locations to each value returned by this call. |
| 1236 | SmallVector<CCValAssign, 16> RVLocs; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1237 | ARMCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), |
| 1238 | getTargetMachine(), RVLocs, *DAG.getContext(), Call); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1239 | CCInfo.AnalyzeCallResult(Ins, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1240 | CCAssignFnForNode(CallConv, /* Return*/ true, |
| 1241 | isVarArg)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1242 | |
| 1243 | // Copy all of the result registers out of their specified physreg. |
| 1244 | for (unsigned i = 0; i != RVLocs.size(); ++i) { |
| 1245 | CCValAssign VA = RVLocs[i]; |
| 1246 | |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1247 | SDValue Val; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1248 | if (VA.needsCustom()) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1249 | // Handle f64 or half of a v2f64. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1250 | SDValue Lo = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1251 | InFlag); |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1252 | Chain = Lo.getValue(1); |
| 1253 | InFlag = Lo.getValue(2); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1254 | VA = RVLocs[++i]; // skip ahead to next loc |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1255 | SDValue Hi = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1256 | InFlag); |
| 1257 | Chain = Hi.getValue(1); |
| 1258 | InFlag = Hi.getValue(2); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1259 | Val = DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1260 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1261 | if (VA.getLocVT() == MVT::v2f64) { |
| 1262 | SDValue Vec = DAG.getNode(ISD::UNDEF, dl, MVT::v2f64); |
| 1263 | Vec = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Vec, Val, |
| 1264 | DAG.getConstant(0, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1265 | |
| 1266 | VA = RVLocs[++i]; // skip ahead to next loc |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1267 | Lo = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, InFlag); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1268 | Chain = Lo.getValue(1); |
| 1269 | InFlag = Lo.getValue(2); |
| 1270 | VA = RVLocs[++i]; // skip ahead to next loc |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1271 | Hi = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, InFlag); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1272 | Chain = Hi.getValue(1); |
| 1273 | InFlag = Hi.getValue(2); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1274 | Val = DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1275 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Vec, Val, |
| 1276 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1277 | } |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1278 | } else { |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1279 | Val = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), VA.getLocVT(), |
| 1280 | InFlag); |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1281 | Chain = Val.getValue(1); |
| 1282 | InFlag = Val.getValue(2); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1283 | } |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1284 | |
| 1285 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1286 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1287 | case CCValAssign::Full: break; |
| 1288 | case CCValAssign::BCvt: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1289 | Val = DAG.getNode(ISD::BITCAST, dl, VA.getValVT(), Val); |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1290 | break; |
| 1291 | } |
| 1292 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1293 | InVals.push_back(Val); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1294 | } |
| 1295 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1296 | return Chain; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1297 | } |
| 1298 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1299 | /// LowerMemOpCallTo - Store the argument to the stack. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1300 | SDValue |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1301 | ARMTargetLowering::LowerMemOpCallTo(SDValue Chain, |
| 1302 | SDValue StackPtr, SDValue Arg, |
| 1303 | DebugLoc dl, SelectionDAG &DAG, |
| 1304 | const CCValAssign &VA, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1305 | ISD::ArgFlagsTy Flags) const { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1306 | unsigned LocMemOffset = VA.getLocMemOffset(); |
| 1307 | SDValue PtrOff = DAG.getIntPtrConstant(LocMemOffset); |
| 1308 | PtrOff = DAG.getNode(ISD::ADD, dl, getPointerTy(), StackPtr, PtrOff); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1309 | return DAG.getStore(Chain, dl, Arg, PtrOff, |
Chris Lattner | fc448ff | 2010-09-21 18:51:21 +0000 | [diff] [blame] | 1310 | MachinePointerInfo::getStack(LocMemOffset), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1311 | false, false, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1312 | } |
| 1313 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1314 | void ARMTargetLowering::PassF64ArgInRegs(DebugLoc dl, SelectionDAG &DAG, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1315 | SDValue Chain, SDValue &Arg, |
| 1316 | RegsToPassVector &RegsToPass, |
| 1317 | CCValAssign &VA, CCValAssign &NextVA, |
| 1318 | SDValue &StackPtr, |
| 1319 | SmallVector<SDValue, 8> &MemOpChains, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1320 | ISD::ArgFlagsTy Flags) const { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1321 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1322 | SDValue fmrrd = DAG.getNode(ARMISD::VMOVRRD, dl, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1323 | DAG.getVTList(MVT::i32, MVT::i32), Arg); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1324 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), fmrrd)); |
| 1325 | |
| 1326 | if (NextVA.isRegLoc()) |
| 1327 | RegsToPass.push_back(std::make_pair(NextVA.getLocReg(), fmrrd.getValue(1))); |
| 1328 | else { |
| 1329 | assert(NextVA.isMemLoc()); |
| 1330 | if (StackPtr.getNode() == 0) |
| 1331 | StackPtr = DAG.getCopyFromReg(Chain, dl, ARM::SP, getPointerTy()); |
| 1332 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1333 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, fmrrd.getValue(1), |
| 1334 | dl, DAG, NextVA, |
| 1335 | Flags)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1336 | } |
| 1337 | } |
| 1338 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1339 | /// LowerCall - Lowering a call into a callseq_start <- |
Evan Cheng | fc40342 | 2007-02-03 08:53:01 +0000 | [diff] [blame] | 1340 | /// ARMISD:CALL <- callseq_end chain. Also add input and output parameter |
| 1341 | /// nodes. |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1342 | SDValue |
Justin Holewinski | d2ea0e1 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 1343 | ARMTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1344 | SmallVectorImpl<SDValue> &InVals) const { |
Justin Holewinski | d2ea0e1 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 1345 | SelectionDAG &DAG = CLI.DAG; |
| 1346 | DebugLoc &dl = CLI.DL; |
| 1347 | SmallVector<ISD::OutputArg, 32> &Outs = CLI.Outs; |
| 1348 | SmallVector<SDValue, 32> &OutVals = CLI.OutVals; |
| 1349 | SmallVector<ISD::InputArg, 32> &Ins = CLI.Ins; |
| 1350 | SDValue Chain = CLI.Chain; |
| 1351 | SDValue Callee = CLI.Callee; |
| 1352 | bool &isTailCall = CLI.IsTailCall; |
| 1353 | CallingConv::ID CallConv = CLI.CallConv; |
| 1354 | bool doesNotRet = CLI.DoesNotReturn; |
| 1355 | bool isVarArg = CLI.IsVarArg; |
| 1356 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1357 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1358 | bool IsStructRet = (Outs.empty()) ? false : Outs[0].Flags.isSRet(); |
| 1359 | bool IsSibCall = false; |
Bob Wilson | 6d2f9ce | 2011-10-07 17:17:49 +0000 | [diff] [blame] | 1360 | // Disable tail calls if they're not supported. |
| 1361 | if (!EnableARMTailCalls && !Subtarget->supportsTailCall()) |
Bob Wilson | 703af3a | 2010-08-13 22:43:33 +0000 | [diff] [blame] | 1362 | isTailCall = false; |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1363 | if (isTailCall) { |
| 1364 | // Check if it's really possible to do a tail call. |
| 1365 | isTailCall = IsEligibleForTailCallOptimization(Callee, CallConv, |
| 1366 | isVarArg, IsStructRet, MF.getFunction()->hasStructRetAttr(), |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1367 | Outs, OutVals, Ins, DAG); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1368 | // We don't support GuaranteedTailCallOpt for ARM, only automatically |
| 1369 | // detected sibcalls. |
| 1370 | if (isTailCall) { |
| 1371 | ++NumTailCalls; |
| 1372 | IsSibCall = true; |
| 1373 | } |
| 1374 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1375 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1376 | // Analyze operands of the call, assigning locations to each operand. |
| 1377 | SmallVector<CCValAssign, 16> ArgLocs; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1378 | ARMCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), |
| 1379 | getTargetMachine(), ArgLocs, *DAG.getContext(), Call); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1380 | CCInfo.AnalyzeCallOperands(Outs, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1381 | CCAssignFnForNode(CallConv, /* Return*/ false, |
| 1382 | isVarArg)); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1383 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1384 | // Get a count of how many bytes are to be pushed on the stack. |
| 1385 | unsigned NumBytes = CCInfo.getNextStackOffset(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1386 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1387 | // For tail calls, memory operands are available in our caller's stack. |
| 1388 | if (IsSibCall) |
| 1389 | NumBytes = 0; |
| 1390 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1391 | // Adjust the stack pointer for the new arguments... |
| 1392 | // These operations are automatically eliminated by the prolog/epilog pass |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1393 | if (!IsSibCall) |
| 1394 | Chain = DAG.getCALLSEQ_START(Chain, DAG.getIntPtrConstant(NumBytes, true)); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1395 | |
Jim Grosbach | f9a4b76 | 2010-02-24 01:43:03 +0000 | [diff] [blame] | 1396 | SDValue StackPtr = DAG.getCopyFromReg(Chain, dl, ARM::SP, getPointerTy()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1397 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1398 | RegsToPassVector RegsToPass; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1399 | SmallVector<SDValue, 8> MemOpChains; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1400 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1401 | // Walk the register/memloc assignments, inserting copies/loads. In the case |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1402 | // of tail call optimization, arguments are handled later. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1403 | for (unsigned i = 0, realArgIdx = 0, e = ArgLocs.size(); |
| 1404 | i != e; |
| 1405 | ++i, ++realArgIdx) { |
| 1406 | CCValAssign &VA = ArgLocs[i]; |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1407 | SDValue Arg = OutVals[realArgIdx]; |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1408 | ISD::ArgFlagsTy Flags = Outs[realArgIdx].Flags; |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1409 | bool isByVal = Flags.isByVal(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1410 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1411 | // Promote the value if needed. |
| 1412 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1413 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1414 | case CCValAssign::Full: break; |
| 1415 | case CCValAssign::SExt: |
| 1416 | Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg); |
| 1417 | break; |
| 1418 | case CCValAssign::ZExt: |
| 1419 | Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg); |
| 1420 | break; |
| 1421 | case CCValAssign::AExt: |
| 1422 | Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg); |
| 1423 | break; |
| 1424 | case CCValAssign::BCvt: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1425 | Arg = DAG.getNode(ISD::BITCAST, dl, VA.getLocVT(), Arg); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1426 | break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1427 | } |
| 1428 | |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1429 | // 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] | 1430 | if (VA.needsCustom()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1431 | if (VA.getLocVT() == MVT::v2f64) { |
| 1432 | SDValue Op0 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1433 | DAG.getConstant(0, MVT::i32)); |
| 1434 | SDValue Op1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1435 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1436 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1437 | PassF64ArgInRegs(dl, DAG, Chain, Op0, RegsToPass, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1438 | VA, ArgLocs[++i], StackPtr, MemOpChains, Flags); |
| 1439 | |
| 1440 | VA = ArgLocs[++i]; // skip ahead to next loc |
| 1441 | if (VA.isRegLoc()) { |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1442 | PassF64ArgInRegs(dl, DAG, Chain, Op1, RegsToPass, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1443 | VA, ArgLocs[++i], StackPtr, MemOpChains, Flags); |
| 1444 | } else { |
| 1445 | assert(VA.isMemLoc()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1446 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1447 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, Op1, |
| 1448 | dl, DAG, VA, Flags)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1449 | } |
| 1450 | } else { |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1451 | PassF64ArgInRegs(dl, DAG, Chain, Arg, RegsToPass, VA, ArgLocs[++i], |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1452 | StackPtr, MemOpChains, Flags); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1453 | } |
| 1454 | } else if (VA.isRegLoc()) { |
| 1455 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg)); |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1456 | } else if (isByVal) { |
| 1457 | assert(VA.isMemLoc()); |
| 1458 | unsigned offset = 0; |
| 1459 | |
| 1460 | // True if this byval aggregate will be split between registers |
| 1461 | // and memory. |
| 1462 | if (CCInfo.isFirstByValRegValid()) { |
| 1463 | EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
| 1464 | unsigned int i, j; |
| 1465 | for (i = 0, j = CCInfo.getFirstByValReg(); j < ARM::R4; i++, j++) { |
| 1466 | SDValue Const = DAG.getConstant(4*i, MVT::i32); |
| 1467 | SDValue AddArg = DAG.getNode(ISD::ADD, dl, PtrVT, Arg, Const); |
| 1468 | SDValue Load = DAG.getLoad(PtrVT, dl, Chain, AddArg, |
| 1469 | MachinePointerInfo(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 1470 | false, false, false, 0); |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1471 | MemOpChains.push_back(Load.getValue(1)); |
| 1472 | RegsToPass.push_back(std::make_pair(j, Load)); |
| 1473 | } |
| 1474 | offset = ARM::R4 - CCInfo.getFirstByValReg(); |
| 1475 | CCInfo.clearFirstByValReg(); |
| 1476 | } |
| 1477 | |
Manman Ren | 763a75d | 2012-06-01 02:44:42 +0000 | [diff] [blame] | 1478 | if (Flags.getByValSize() - 4*offset > 0) { |
| 1479 | unsigned LocMemOffset = VA.getLocMemOffset(); |
| 1480 | SDValue StkPtrOff = DAG.getIntPtrConstant(LocMemOffset); |
| 1481 | SDValue Dst = DAG.getNode(ISD::ADD, dl, getPointerTy(), StackPtr, |
| 1482 | StkPtrOff); |
| 1483 | SDValue SrcOffset = DAG.getIntPtrConstant(4*offset); |
| 1484 | SDValue Src = DAG.getNode(ISD::ADD, dl, getPointerTy(), Arg, SrcOffset); |
| 1485 | SDValue SizeNode = DAG.getConstant(Flags.getByValSize() - 4*offset, |
| 1486 | MVT::i32); |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 1487 | SDValue AlignNode = DAG.getConstant(Flags.getByValAlign(), MVT::i32); |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1488 | |
Manman Ren | 763a75d | 2012-06-01 02:44:42 +0000 | [diff] [blame] | 1489 | SDVTList VTs = DAG.getVTList(MVT::Other, MVT::Glue); |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 1490 | SDValue Ops[] = { Chain, Dst, Src, SizeNode, AlignNode}; |
Manman Ren | 763a75d | 2012-06-01 02:44:42 +0000 | [diff] [blame] | 1491 | MemOpChains.push_back(DAG.getNode(ARMISD::COPY_STRUCT_BYVAL, dl, VTs, |
| 1492 | Ops, array_lengthof(Ops))); |
| 1493 | } |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1494 | } else if (!IsSibCall) { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1495 | assert(VA.isMemLoc()); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1496 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1497 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, Arg, |
| 1498 | dl, DAG, VA, Flags)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1499 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1500 | } |
| 1501 | |
| 1502 | if (!MemOpChains.empty()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1503 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1504 | &MemOpChains[0], MemOpChains.size()); |
| 1505 | |
| 1506 | // Build a sequence of copy-to-reg nodes chained together with token chain |
| 1507 | // and flag operands which copy the outgoing args into the appropriate regs. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1508 | SDValue InFlag; |
Dale Johannesen | 6470a11 | 2010-06-15 22:08:33 +0000 | [diff] [blame] | 1509 | // Tail call byval lowering might overwrite argument registers so in case of |
| 1510 | // tail call optimization the copies to registers are lowered later. |
| 1511 | if (!isTailCall) |
| 1512 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 1513 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, |
| 1514 | RegsToPass[i].second, InFlag); |
| 1515 | InFlag = Chain.getValue(1); |
| 1516 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1517 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1518 | // For tail calls lower the arguments to the 'real' stack slot. |
| 1519 | if (isTailCall) { |
| 1520 | // Force all the incoming stack arguments to be loaded from the stack |
| 1521 | // before any new outgoing arguments are stored to the stack, because the |
| 1522 | // outgoing stack slots may alias the incoming argument stack slots, and |
| 1523 | // the alias isn't otherwise explicit. This is slightly more conservative |
| 1524 | // than necessary, because it means that each store effectively depends |
| 1525 | // on every argument instead of just those arguments it would clobber. |
| 1526 | |
Chris Lattner | 7a2bdde | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 1527 | // Do not flag preceding copytoreg stuff together with the following stuff. |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1528 | InFlag = SDValue(); |
| 1529 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 1530 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, |
| 1531 | RegsToPass[i].second, InFlag); |
| 1532 | InFlag = Chain.getValue(1); |
| 1533 | } |
| 1534 | InFlag =SDValue(); |
| 1535 | } |
| 1536 | |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1537 | // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every |
| 1538 | // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol |
| 1539 | // node so that legalize doesn't hack it. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1540 | bool isDirect = false; |
| 1541 | bool isARMFunc = false; |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 1542 | bool isLocalARMFunc = false; |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1543 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1544 | |
| 1545 | if (EnableARMLongCalls) { |
| 1546 | assert (getTargetMachine().getRelocationModel() == Reloc::Static |
| 1547 | && "long-calls with non-static relocation model!"); |
| 1548 | // Handle a global address or an external symbol. If it's not one of |
| 1549 | // those, the target's already in a register, so we don't need to do |
| 1550 | // anything extra. |
| 1551 | if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
Anders Carlsson | 0dbdca5 | 2010-04-15 03:11:28 +0000 | [diff] [blame] | 1552 | const GlobalValue *GV = G->getGlobal(); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1553 | // Create a constant pool entry for the callee address |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1554 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 1555 | ARMConstantPoolValue *CPV = |
| 1556 | ARMConstantPoolConstant::Create(GV, ARMPCLabelIndex, ARMCP::CPValue, 0); |
| 1557 | |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1558 | // Get the address of the callee into a register |
| 1559 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
| 1560 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| 1561 | Callee = DAG.getLoad(getPointerTy(), dl, |
| 1562 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1563 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 1564 | false, false, false, 0); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1565 | } else if (ExternalSymbolSDNode *S=dyn_cast<ExternalSymbolSDNode>(Callee)) { |
| 1566 | const char *Sym = S->getSymbol(); |
| 1567 | |
| 1568 | // Create a constant pool entry for the callee address |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1569 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Bill Wendling | fe31e67 | 2011-10-01 08:58:29 +0000 | [diff] [blame] | 1570 | ARMConstantPoolValue *CPV = |
| 1571 | ARMConstantPoolSymbol::Create(*DAG.getContext(), Sym, |
| 1572 | ARMPCLabelIndex, 0); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1573 | // Get the address of the callee into a register |
| 1574 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
| 1575 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| 1576 | Callee = DAG.getLoad(getPointerTy(), dl, |
| 1577 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1578 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 1579 | false, false, false, 0); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1580 | } |
| 1581 | } else if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 1582 | const GlobalValue *GV = G->getGlobal(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1583 | isDirect = true; |
Chris Lattner | 4fb63d0 | 2009-07-15 04:12:33 +0000 | [diff] [blame] | 1584 | bool isExt = GV->isDeclaration() || GV->isWeakForLinker(); |
Evan Cheng | 970a419 | 2007-01-19 19:28:01 +0000 | [diff] [blame] | 1585 | bool isStub = (isExt && Subtarget->isTargetDarwin()) && |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1586 | getTargetMachine().getRelocationModel() != Reloc::Static; |
| 1587 | isARMFunc = !Subtarget->isThumb() || isStub; |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 1588 | // ARM call to a local ARM function is predicable. |
Evan Cheng | 46df4eb | 2010-06-16 07:35:02 +0000 | [diff] [blame] | 1589 | isLocalARMFunc = !Subtarget->isThumb() && (!isExt || !ARMInterworking); |
Evan Cheng | c60e76d | 2007-01-30 20:37:08 +0000 | [diff] [blame] | 1590 | // tBX takes a register source operand. |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 1591 | if (isARMFunc && Subtarget->isThumb1Only() && !Subtarget->hasV5TOps()) { |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1592 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 1593 | ARMConstantPoolValue *CPV = |
| 1594 | ARMConstantPoolConstant::Create(GV, ARMPCLabelIndex, ARMCP::CPValue, 4); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1595 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1596 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1597 | Callee = DAG.getLoad(getPointerTy(), dl, |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1598 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1599 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 1600 | false, false, false, 0); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1601 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1602 | Callee = DAG.getNode(ARMISD::PIC_ADD, dl, |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1603 | getPointerTy(), Callee, PICLabel); |
Jim Grosbach | 637d89f | 2010-09-22 23:27:36 +0000 | [diff] [blame] | 1604 | } else { |
| 1605 | // On ELF targets for PIC code, direct calls should go through the PLT |
| 1606 | unsigned OpFlags = 0; |
| 1607 | if (Subtarget->isTargetELF() && |
Chad Rosier | a6ca703 | 2013-02-28 19:16:42 +0000 | [diff] [blame] | 1608 | getTargetMachine().getRelocationModel() == Reloc::PIC_) |
Jim Grosbach | 637d89f | 2010-09-22 23:27:36 +0000 | [diff] [blame] | 1609 | OpFlags = ARMII::MO_PLT; |
| 1610 | Callee = DAG.getTargetGlobalAddress(GV, dl, getPointerTy(), 0, OpFlags); |
| 1611 | } |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1612 | } else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1613 | isDirect = true; |
Evan Cheng | 970a419 | 2007-01-19 19:28:01 +0000 | [diff] [blame] | 1614 | bool isStub = Subtarget->isTargetDarwin() && |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1615 | getTargetMachine().getRelocationModel() != Reloc::Static; |
| 1616 | isARMFunc = !Subtarget->isThumb() || isStub; |
Evan Cheng | c60e76d | 2007-01-30 20:37:08 +0000 | [diff] [blame] | 1617 | // tBX takes a register source operand. |
| 1618 | const char *Sym = S->getSymbol(); |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 1619 | if (isARMFunc && Subtarget->isThumb1Only() && !Subtarget->hasV5TOps()) { |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1620 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Bill Wendling | fe31e67 | 2011-10-01 08:58:29 +0000 | [diff] [blame] | 1621 | ARMConstantPoolValue *CPV = |
| 1622 | ARMConstantPoolSymbol::Create(*DAG.getContext(), Sym, |
| 1623 | ARMPCLabelIndex, 4); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1624 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1625 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1626 | Callee = DAG.getLoad(getPointerTy(), dl, |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1627 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1628 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 1629 | false, false, false, 0); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1630 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1631 | Callee = DAG.getNode(ARMISD::PIC_ADD, dl, |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1632 | getPointerTy(), Callee, PICLabel); |
Jim Grosbach | 637d89f | 2010-09-22 23:27:36 +0000 | [diff] [blame] | 1633 | } else { |
| 1634 | unsigned OpFlags = 0; |
| 1635 | // On ELF targets for PIC code, direct calls should go through the PLT |
| 1636 | if (Subtarget->isTargetELF() && |
| 1637 | getTargetMachine().getRelocationModel() == Reloc::PIC_) |
| 1638 | OpFlags = ARMII::MO_PLT; |
| 1639 | Callee = DAG.getTargetExternalSymbol(Sym, getPointerTy(), OpFlags); |
| 1640 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1641 | } |
| 1642 | |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1643 | // FIXME: handle tail calls differently. |
| 1644 | unsigned CallOpc; |
Bill Wendling | 831737d | 2012-12-30 10:32:01 +0000 | [diff] [blame] | 1645 | bool HasMinSizeAttr = MF.getFunction()->getAttributes(). |
| 1646 | hasAttribute(AttributeSet::FunctionIndex, Attribute::MinSize); |
Evan Cheng | b620724 | 2009-08-01 00:16:10 +0000 | [diff] [blame] | 1647 | if (Subtarget->isThumb()) { |
| 1648 | if ((!isDirect || isARMFunc) && !Subtarget->hasV5TOps()) |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1649 | CallOpc = ARMISD::CALL_NOLINK; |
| 1650 | else |
| 1651 | CallOpc = isARMFunc ? ARMISD::CALL : ARMISD::tCALL; |
| 1652 | } else { |
Evan Cheng | b341fac | 2012-11-10 02:09:05 +0000 | [diff] [blame] | 1653 | if (!isDirect && !Subtarget->hasV5TOps()) |
Evan Cheng | 4bfcd4a | 2012-02-28 18:51:51 +0000 | [diff] [blame] | 1654 | CallOpc = ARMISD::CALL_NOLINK; |
Evan Cheng | b341fac | 2012-11-10 02:09:05 +0000 | [diff] [blame] | 1655 | else if (doesNotRet && isDirect && Subtarget->hasRAS() && |
Quentin Colombet | 43934ae | 2012-11-02 21:32:17 +0000 | [diff] [blame] | 1656 | // Emit regular call when code size is the priority |
| 1657 | !HasMinSizeAttr) |
Evan Cheng | 4bfcd4a | 2012-02-28 18:51:51 +0000 | [diff] [blame] | 1658 | // "mov lr, pc; b _foo" to avoid confusing the RSP |
| 1659 | CallOpc = ARMISD::CALL_NOLINK; |
| 1660 | else |
| 1661 | CallOpc = isLocalARMFunc ? ARMISD::CALL_PRED : ARMISD::CALL; |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1662 | } |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1663 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1664 | std::vector<SDValue> Ops; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1665 | Ops.push_back(Chain); |
| 1666 | Ops.push_back(Callee); |
| 1667 | |
| 1668 | // Add argument registers to the end of the list so that they are known live |
| 1669 | // into the call. |
| 1670 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) |
| 1671 | Ops.push_back(DAG.getRegister(RegsToPass[i].first, |
| 1672 | RegsToPass[i].second.getValueType())); |
| 1673 | |
Jakob Stoklund Olesen | c54f634 | 2012-02-24 01:19:29 +0000 | [diff] [blame] | 1674 | // Add a register mask operand representing the call-preserved registers. |
| 1675 | const TargetRegisterInfo *TRI = getTargetMachine().getRegisterInfo(); |
| 1676 | const uint32_t *Mask = TRI->getCallPreservedMask(CallConv); |
| 1677 | assert(Mask && "Missing call preserved mask for calling convention"); |
| 1678 | Ops.push_back(DAG.getRegisterMask(Mask)); |
| 1679 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1680 | if (InFlag.getNode()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1681 | Ops.push_back(InFlag); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1682 | |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 1683 | SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue); |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1684 | if (isTailCall) |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1685 | return DAG.getNode(ARMISD::TC_RETURN, dl, NodeTys, &Ops[0], Ops.size()); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1686 | |
Duncan Sands | 4bdcb61 | 2008-07-02 17:40:58 +0000 | [diff] [blame] | 1687 | // Returns a chain and a flag for retval copy to use. |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1688 | Chain = DAG.getNode(CallOpc, dl, NodeTys, &Ops[0], Ops.size()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1689 | InFlag = Chain.getValue(1); |
| 1690 | |
Chris Lattner | e563bbc | 2008-10-11 22:08:30 +0000 | [diff] [blame] | 1691 | Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(NumBytes, true), |
| 1692 | DAG.getIntPtrConstant(0, true), InFlag); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1693 | if (!Ins.empty()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1694 | InFlag = Chain.getValue(1); |
| 1695 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1696 | // Handle result values, copying them out of physregs into vregs that we |
| 1697 | // return. |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1698 | return LowerCallResult(Chain, InFlag, CallConv, isVarArg, Ins, |
| 1699 | dl, DAG, InVals); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1700 | } |
| 1701 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1702 | /// HandleByVal - Every parameter *after* a byval parameter is passed |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1703 | /// on the stack. Remember the next parameter register to allocate, |
| 1704 | /// and then confiscate the rest of the parameter registers to insure |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1705 | /// this. |
| 1706 | void |
Stepan Dyatkovskiy | b52ba9f | 2012-10-16 07:16:47 +0000 | [diff] [blame] | 1707 | ARMTargetLowering::HandleByVal( |
| 1708 | CCState *State, unsigned &size, unsigned Align) const { |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1709 | unsigned reg = State->AllocateReg(GPRArgRegs, 4); |
| 1710 | assert((State->getCallOrPrologue() == Prologue || |
| 1711 | State->getCallOrPrologue() == Call) && |
| 1712 | "unhandled ParmContext"); |
| 1713 | if ((!State->isFirstByValRegValid()) && |
| 1714 | (ARM::R0 <= reg) && (reg <= ARM::R3)) { |
Stepan Dyatkovskiy | b52ba9f | 2012-10-16 07:16:47 +0000 | [diff] [blame] | 1715 | if (Subtarget->isAAPCS_ABI() && Align > 4) { |
| 1716 | unsigned AlignInRegs = Align / 4; |
| 1717 | unsigned Waste = (ARM::R4 - reg) % AlignInRegs; |
| 1718 | for (unsigned i = 0; i < Waste; ++i) |
| 1719 | reg = State->AllocateReg(GPRArgRegs, 4); |
| 1720 | } |
| 1721 | if (reg != 0) { |
| 1722 | State->setFirstByValReg(reg); |
| 1723 | // At a call site, a byval parameter that is split between |
| 1724 | // registers and memory needs its size truncated here. In a |
| 1725 | // function prologue, such byval parameters are reassembled in |
| 1726 | // memory, and are not truncated. |
| 1727 | if (State->getCallOrPrologue() == Call) { |
| 1728 | unsigned excess = 4 * (ARM::R4 - reg); |
| 1729 | assert(size >= excess && "expected larger existing stack allocation"); |
| 1730 | size -= excess; |
| 1731 | } |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1732 | } |
| 1733 | } |
| 1734 | // Confiscate any remaining parameter registers to preclude their |
| 1735 | // assignment to subsequent parameters. |
| 1736 | while (State->AllocateReg(GPRArgRegs, 4)) |
| 1737 | ; |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1738 | } |
| 1739 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1740 | /// MatchingStackOffset - Return true if the given stack call argument is |
| 1741 | /// already available in the same position (relatively) of the caller's |
| 1742 | /// incoming argument stack. |
| 1743 | static |
| 1744 | bool MatchingStackOffset(SDValue Arg, unsigned Offset, ISD::ArgFlagsTy Flags, |
| 1745 | MachineFrameInfo *MFI, const MachineRegisterInfo *MRI, |
Craig Topper | acf2077 | 2012-03-25 23:49:58 +0000 | [diff] [blame] | 1746 | const TargetInstrInfo *TII) { |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1747 | unsigned Bytes = Arg.getValueType().getSizeInBits() / 8; |
| 1748 | int FI = INT_MAX; |
| 1749 | if (Arg.getOpcode() == ISD::CopyFromReg) { |
| 1750 | unsigned VR = cast<RegisterSDNode>(Arg.getOperand(1))->getReg(); |
Jakob Stoklund Olesen | c9df025 | 2011-01-10 02:58:51 +0000 | [diff] [blame] | 1751 | if (!TargetRegisterInfo::isVirtualRegister(VR)) |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1752 | return false; |
| 1753 | MachineInstr *Def = MRI->getVRegDef(VR); |
| 1754 | if (!Def) |
| 1755 | return false; |
| 1756 | if (!Flags.isByVal()) { |
| 1757 | if (!TII->isLoadFromStackSlot(Def, FI)) |
| 1758 | return false; |
| 1759 | } else { |
Dale Johannesen | 7835f1f | 2010-07-08 01:18:23 +0000 | [diff] [blame] | 1760 | return false; |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1761 | } |
| 1762 | } else if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Arg)) { |
| 1763 | if (Flags.isByVal()) |
| 1764 | // ByVal argument is passed in as a pointer but it's now being |
| 1765 | // dereferenced. e.g. |
| 1766 | // define @foo(%struct.X* %A) { |
| 1767 | // tail call @bar(%struct.X* byval %A) |
| 1768 | // } |
| 1769 | return false; |
| 1770 | SDValue Ptr = Ld->getBasePtr(); |
| 1771 | FrameIndexSDNode *FINode = dyn_cast<FrameIndexSDNode>(Ptr); |
| 1772 | if (!FINode) |
| 1773 | return false; |
| 1774 | FI = FINode->getIndex(); |
| 1775 | } else |
| 1776 | return false; |
| 1777 | |
| 1778 | assert(FI != INT_MAX); |
| 1779 | if (!MFI->isFixedObjectIndex(FI)) |
| 1780 | return false; |
| 1781 | return Offset == MFI->getObjectOffset(FI) && Bytes == MFI->getObjectSize(FI); |
| 1782 | } |
| 1783 | |
| 1784 | /// IsEligibleForTailCallOptimization - Check whether the call is eligible |
| 1785 | /// for tail call optimization. Targets which want to do tail call |
| 1786 | /// optimization should implement this function. |
| 1787 | bool |
| 1788 | ARMTargetLowering::IsEligibleForTailCallOptimization(SDValue Callee, |
| 1789 | CallingConv::ID CalleeCC, |
| 1790 | bool isVarArg, |
| 1791 | bool isCalleeStructRet, |
| 1792 | bool isCallerStructRet, |
| 1793 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1794 | const SmallVectorImpl<SDValue> &OutVals, |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1795 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 1796 | SelectionDAG& DAG) const { |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1797 | const Function *CallerF = DAG.getMachineFunction().getFunction(); |
| 1798 | CallingConv::ID CallerCC = CallerF->getCallingConv(); |
| 1799 | bool CCMatch = CallerCC == CalleeCC; |
| 1800 | |
| 1801 | // Look for obvious safe cases to perform tail call optimization that do not |
| 1802 | // require ABI changes. This is what gcc calls sibcall. |
| 1803 | |
Jim Grosbach | 7616b64 | 2010-06-16 23:45:49 +0000 | [diff] [blame] | 1804 | // Do not sibcall optimize vararg calls unless the call site is not passing |
| 1805 | // any arguments. |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1806 | if (isVarArg && !Outs.empty()) |
| 1807 | return false; |
| 1808 | |
| 1809 | // Also avoid sibcall optimization if either caller or callee uses struct |
| 1810 | // return semantics. |
| 1811 | if (isCalleeStructRet || isCallerStructRet) |
| 1812 | return false; |
| 1813 | |
Dale Johannesen | e39fdbe | 2010-06-23 18:52:34 +0000 | [diff] [blame] | 1814 | // FIXME: Completely disable sibcall for Thumb1 since Thumb1RegisterInfo:: |
Jim Grosbach | 8dc41f3 | 2011-07-08 20:18:11 +0000 | [diff] [blame] | 1815 | // emitEpilogue is not ready for them. Thumb tail calls also use t2B, as |
| 1816 | // the Thumb1 16-bit unconditional branch doesn't have sufficient relocation |
| 1817 | // support in the assembler and linker to be used. This would need to be |
| 1818 | // fixed to fully support tail calls in Thumb1. |
| 1819 | // |
Dale Johannesen | 7835f1f | 2010-07-08 01:18:23 +0000 | [diff] [blame] | 1820 | // Doing this is tricky, since the LDM/POP instruction on Thumb doesn't take |
| 1821 | // LR. This means if we need to reload LR, it takes an extra instructions, |
| 1822 | // which outweighs the value of the tail call; but here we don't know yet |
| 1823 | // 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] | 1824 | // 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] | 1825 | // emitEpilogue if LR is used. |
Dale Johannesen | 7835f1f | 2010-07-08 01:18:23 +0000 | [diff] [blame] | 1826 | |
| 1827 | // Thumb1 PIC calls to external symbols use BX, so they can be tail calls, |
| 1828 | // but we need to make sure there are enough registers; the only valid |
| 1829 | // registers are the 4 used for parameters. We don't currently do this |
| 1830 | // case. |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1831 | if (Subtarget->isThumb1Only()) |
| 1832 | return false; |
Dale Johannesen | df50d7e | 2010-06-18 18:13:11 +0000 | [diff] [blame] | 1833 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1834 | // If the calling conventions do not match, then we'd better make sure the |
| 1835 | // results are returned in the same way as what the caller expects. |
| 1836 | if (!CCMatch) { |
| 1837 | SmallVector<CCValAssign, 16> RVLocs1; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1838 | ARMCCState CCInfo1(CalleeCC, false, DAG.getMachineFunction(), |
| 1839 | getTargetMachine(), RVLocs1, *DAG.getContext(), Call); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1840 | CCInfo1.AnalyzeCallResult(Ins, CCAssignFnForNode(CalleeCC, true, isVarArg)); |
| 1841 | |
| 1842 | SmallVector<CCValAssign, 16> RVLocs2; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1843 | ARMCCState CCInfo2(CallerCC, false, DAG.getMachineFunction(), |
| 1844 | getTargetMachine(), RVLocs2, *DAG.getContext(), Call); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1845 | CCInfo2.AnalyzeCallResult(Ins, CCAssignFnForNode(CallerCC, true, isVarArg)); |
| 1846 | |
| 1847 | if (RVLocs1.size() != RVLocs2.size()) |
| 1848 | return false; |
| 1849 | for (unsigned i = 0, e = RVLocs1.size(); i != e; ++i) { |
| 1850 | if (RVLocs1[i].isRegLoc() != RVLocs2[i].isRegLoc()) |
| 1851 | return false; |
| 1852 | if (RVLocs1[i].getLocInfo() != RVLocs2[i].getLocInfo()) |
| 1853 | return false; |
| 1854 | if (RVLocs1[i].isRegLoc()) { |
| 1855 | if (RVLocs1[i].getLocReg() != RVLocs2[i].getLocReg()) |
| 1856 | return false; |
| 1857 | } else { |
| 1858 | if (RVLocs1[i].getLocMemOffset() != RVLocs2[i].getLocMemOffset()) |
| 1859 | return false; |
| 1860 | } |
| 1861 | } |
| 1862 | } |
| 1863 | |
Manman Ren | e6c3cc8 | 2012-10-12 23:39:43 +0000 | [diff] [blame] | 1864 | // If Caller's vararg or byval argument has been split between registers and |
| 1865 | // stack, do not perform tail call, since part of the argument is in caller's |
| 1866 | // local frame. |
| 1867 | const ARMFunctionInfo *AFI_Caller = DAG.getMachineFunction(). |
| 1868 | getInfo<ARMFunctionInfo>(); |
| 1869 | if (AFI_Caller->getVarArgsRegSaveSize()) |
| 1870 | return false; |
| 1871 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1872 | // If the callee takes no arguments then go on to check the results of the |
| 1873 | // call. |
| 1874 | if (!Outs.empty()) { |
| 1875 | // Check if stack adjustment is needed. For now, do not do this if any |
| 1876 | // argument is passed on the stack. |
| 1877 | SmallVector<CCValAssign, 16> ArgLocs; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1878 | ARMCCState CCInfo(CalleeCC, isVarArg, DAG.getMachineFunction(), |
| 1879 | getTargetMachine(), ArgLocs, *DAG.getContext(), Call); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1880 | CCInfo.AnalyzeCallOperands(Outs, |
| 1881 | CCAssignFnForNode(CalleeCC, false, isVarArg)); |
| 1882 | if (CCInfo.getNextStackOffset()) { |
| 1883 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1884 | |
| 1885 | // Check if the arguments are already laid out in the right way as |
| 1886 | // the caller's fixed stack objects. |
| 1887 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 1888 | const MachineRegisterInfo *MRI = &MF.getRegInfo(); |
Craig Topper | acf2077 | 2012-03-25 23:49:58 +0000 | [diff] [blame] | 1889 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1890 | for (unsigned i = 0, realArgIdx = 0, e = ArgLocs.size(); |
| 1891 | i != e; |
| 1892 | ++i, ++realArgIdx) { |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1893 | CCValAssign &VA = ArgLocs[i]; |
| 1894 | EVT RegVT = VA.getLocVT(); |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1895 | SDValue Arg = OutVals[realArgIdx]; |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1896 | ISD::ArgFlagsTy Flags = Outs[realArgIdx].Flags; |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1897 | if (VA.getLocInfo() == CCValAssign::Indirect) |
| 1898 | return false; |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1899 | if (VA.needsCustom()) { |
| 1900 | // f64 and vector types are split into multiple registers or |
| 1901 | // register/stack-slot combinations. The types will not match |
| 1902 | // the registers; give up on memory f64 refs until we figure |
| 1903 | // out what to do about this. |
| 1904 | if (!VA.isRegLoc()) |
| 1905 | return false; |
| 1906 | if (!ArgLocs[++i].isRegLoc()) |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 1907 | return false; |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1908 | if (RegVT == MVT::v2f64) { |
| 1909 | if (!ArgLocs[++i].isRegLoc()) |
| 1910 | return false; |
| 1911 | if (!ArgLocs[++i].isRegLoc()) |
| 1912 | return false; |
| 1913 | } |
| 1914 | } else if (!VA.isRegLoc()) { |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1915 | if (!MatchingStackOffset(Arg, VA.getLocMemOffset(), Flags, |
| 1916 | MFI, MRI, TII)) |
| 1917 | return false; |
| 1918 | } |
| 1919 | } |
| 1920 | } |
| 1921 | } |
| 1922 | |
| 1923 | return true; |
| 1924 | } |
| 1925 | |
Benjamin Kramer | 350c008 | 2012-11-28 20:55:10 +0000 | [diff] [blame] | 1926 | bool |
| 1927 | ARMTargetLowering::CanLowerReturn(CallingConv::ID CallConv, |
| 1928 | MachineFunction &MF, bool isVarArg, |
| 1929 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
| 1930 | LLVMContext &Context) const { |
| 1931 | SmallVector<CCValAssign, 16> RVLocs; |
| 1932 | CCState CCInfo(CallConv, isVarArg, MF, getTargetMachine(), RVLocs, Context); |
| 1933 | return CCInfo.CheckReturn(Outs, CCAssignFnForNode(CallConv, /*Return=*/true, |
| 1934 | isVarArg)); |
| 1935 | } |
| 1936 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1937 | SDValue |
| 1938 | ARMTargetLowering::LowerReturn(SDValue Chain, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1939 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1940 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1941 | const SmallVectorImpl<SDValue> &OutVals, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1942 | DebugLoc dl, SelectionDAG &DAG) const { |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1943 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1944 | // CCValAssign - represent the assignment of the return value to a location. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1945 | SmallVector<CCValAssign, 16> RVLocs; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1946 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1947 | // CCState - Info about the registers and stack slots. |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1948 | ARMCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), |
| 1949 | getTargetMachine(), RVLocs, *DAG.getContext(), Call); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1950 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1951 | // Analyze outgoing return values. |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1952 | CCInfo.AnalyzeReturn(Outs, CCAssignFnForNode(CallConv, /* Return */ true, |
| 1953 | isVarArg)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1954 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1955 | SDValue Flag; |
Jakob Stoklund Olesen | fc74327 | 2013-02-05 18:08:40 +0000 | [diff] [blame] | 1956 | SmallVector<SDValue, 4> RetOps; |
| 1957 | RetOps.push_back(Chain); // Operand #0 = Chain (updated below) |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1958 | |
| 1959 | // Copy the result values into the output registers. |
| 1960 | for (unsigned i = 0, realRVLocIdx = 0; |
| 1961 | i != RVLocs.size(); |
| 1962 | ++i, ++realRVLocIdx) { |
| 1963 | CCValAssign &VA = RVLocs[i]; |
| 1964 | assert(VA.isRegLoc() && "Can only return in registers!"); |
| 1965 | |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1966 | SDValue Arg = OutVals[realRVLocIdx]; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1967 | |
| 1968 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1969 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1970 | case CCValAssign::Full: break; |
| 1971 | case CCValAssign::BCvt: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1972 | Arg = DAG.getNode(ISD::BITCAST, dl, VA.getLocVT(), Arg); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1973 | break; |
| 1974 | } |
| 1975 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1976 | if (VA.needsCustom()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1977 | if (VA.getLocVT() == MVT::v2f64) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1978 | // Extract the first half and return it in two registers. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1979 | SDValue Half = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1980 | DAG.getConstant(0, MVT::i32)); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1981 | SDValue HalfGPRs = DAG.getNode(ARMISD::VMOVRRD, dl, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1982 | DAG.getVTList(MVT::i32, MVT::i32), Half); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1983 | |
| 1984 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), HalfGPRs, Flag); |
| 1985 | Flag = Chain.getValue(1); |
Jakob Stoklund Olesen | fc74327 | 2013-02-05 18:08:40 +0000 | [diff] [blame] | 1986 | RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT())); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1987 | VA = RVLocs[++i]; // skip ahead to next loc |
| 1988 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), |
| 1989 | HalfGPRs.getValue(1), Flag); |
| 1990 | Flag = Chain.getValue(1); |
Jakob Stoklund Olesen | fc74327 | 2013-02-05 18:08:40 +0000 | [diff] [blame] | 1991 | RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT())); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1992 | VA = RVLocs[++i]; // skip ahead to next loc |
| 1993 | |
| 1994 | // 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] | 1995 | Arg = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1996 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1997 | } |
| 1998 | // Legalize ret f64 -> ret 2 x i32. We always have fmrrd if f64 is |
| 1999 | // available. |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 2000 | SDValue fmrrd = DAG.getNode(ARMISD::VMOVRRD, dl, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2001 | DAG.getVTList(MVT::i32, MVT::i32), &Arg, 1); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2002 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), fmrrd, Flag); |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 2003 | Flag = Chain.getValue(1); |
Jakob Stoklund Olesen | fc74327 | 2013-02-05 18:08:40 +0000 | [diff] [blame] | 2004 | RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT())); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2005 | VA = RVLocs[++i]; // skip ahead to next loc |
| 2006 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), fmrrd.getValue(1), |
| 2007 | Flag); |
| 2008 | } else |
| 2009 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), Arg, Flag); |
| 2010 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 2011 | // Guarantee that all emitted copies are |
| 2012 | // stuck together, avoiding something bad. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2013 | Flag = Chain.getValue(1); |
Jakob Stoklund Olesen | fc74327 | 2013-02-05 18:08:40 +0000 | [diff] [blame] | 2014 | RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT())); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2015 | } |
| 2016 | |
Jakob Stoklund Olesen | fc74327 | 2013-02-05 18:08:40 +0000 | [diff] [blame] | 2017 | // Update chain and glue. |
| 2018 | RetOps[0] = Chain; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2019 | if (Flag.getNode()) |
Jakob Stoklund Olesen | fc74327 | 2013-02-05 18:08:40 +0000 | [diff] [blame] | 2020 | RetOps.push_back(Flag); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2021 | |
Jakob Stoklund Olesen | fc74327 | 2013-02-05 18:08:40 +0000 | [diff] [blame] | 2022 | return DAG.getNode(ARMISD::RET_FLAG, dl, MVT::Other, |
| 2023 | RetOps.data(), RetOps.size()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2024 | } |
| 2025 | |
Evan Cheng | bf010eb | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2026 | bool ARMTargetLowering::isUsedByReturnOnly(SDNode *N, SDValue &Chain) const { |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2027 | if (N->getNumValues() != 1) |
| 2028 | return false; |
| 2029 | if (!N->hasNUsesOfValue(1, 0)) |
| 2030 | return false; |
| 2031 | |
Evan Cheng | bf010eb | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2032 | SDValue TCChain = Chain; |
| 2033 | SDNode *Copy = *N->use_begin(); |
| 2034 | if (Copy->getOpcode() == ISD::CopyToReg) { |
| 2035 | // If the copy has a glue operand, we conservatively assume it isn't safe to |
| 2036 | // perform a tail call. |
| 2037 | if (Copy->getOperand(Copy->getNumOperands()-1).getValueType() == MVT::Glue) |
| 2038 | return false; |
| 2039 | TCChain = Copy->getOperand(0); |
| 2040 | } else if (Copy->getOpcode() == ARMISD::VMOVRRD) { |
| 2041 | SDNode *VMov = Copy; |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2042 | // f64 returned in a pair of GPRs. |
Evan Cheng | bf010eb | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2043 | SmallPtrSet<SDNode*, 2> Copies; |
| 2044 | for (SDNode::use_iterator UI = VMov->use_begin(), UE = VMov->use_end(); |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2045 | UI != UE; ++UI) { |
| 2046 | if (UI->getOpcode() != ISD::CopyToReg) |
| 2047 | return false; |
Evan Cheng | bf010eb | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2048 | Copies.insert(*UI); |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2049 | } |
Evan Cheng | bf010eb | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2050 | if (Copies.size() > 2) |
| 2051 | return false; |
| 2052 | |
| 2053 | for (SDNode::use_iterator UI = VMov->use_begin(), UE = VMov->use_end(); |
| 2054 | UI != UE; ++UI) { |
| 2055 | SDValue UseChain = UI->getOperand(0); |
| 2056 | if (Copies.count(UseChain.getNode())) |
| 2057 | // Second CopyToReg |
| 2058 | Copy = *UI; |
| 2059 | else |
| 2060 | // First CopyToReg |
| 2061 | TCChain = UseChain; |
| 2062 | } |
| 2063 | } else if (Copy->getOpcode() == ISD::BITCAST) { |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2064 | // f32 returned in a single GPR. |
Evan Cheng | bf010eb | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2065 | if (!Copy->hasOneUse()) |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2066 | return false; |
Evan Cheng | bf010eb | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2067 | Copy = *Copy->use_begin(); |
| 2068 | if (Copy->getOpcode() != ISD::CopyToReg || !Copy->hasNUsesOfValue(1, 0)) |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2069 | return false; |
Evan Cheng | bf010eb | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2070 | Chain = Copy->getOperand(0); |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2071 | } else { |
| 2072 | return false; |
| 2073 | } |
| 2074 | |
Evan Cheng | 1bf891a | 2010-12-01 22:59:46 +0000 | [diff] [blame] | 2075 | bool HasRet = false; |
Evan Cheng | bf010eb | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2076 | for (SDNode::use_iterator UI = Copy->use_begin(), UE = Copy->use_end(); |
| 2077 | UI != UE; ++UI) { |
| 2078 | if (UI->getOpcode() != ARMISD::RET_FLAG) |
| 2079 | return false; |
| 2080 | HasRet = true; |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2081 | } |
| 2082 | |
Evan Cheng | bf010eb | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2083 | if (!HasRet) |
| 2084 | return false; |
| 2085 | |
| 2086 | Chain = TCChain; |
| 2087 | return true; |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2088 | } |
| 2089 | |
Evan Cheng | 485fafc | 2011-03-21 01:19:09 +0000 | [diff] [blame] | 2090 | bool ARMTargetLowering::mayBeEmittedAsTailCall(CallInst *CI) const { |
Evan Cheng | 1c80f56 | 2012-03-30 01:24:39 +0000 | [diff] [blame] | 2091 | if (!EnableARMTailCalls && !Subtarget->supportsTailCall()) |
Evan Cheng | 485fafc | 2011-03-21 01:19:09 +0000 | [diff] [blame] | 2092 | return false; |
| 2093 | |
| 2094 | if (!CI->isTailCall()) |
| 2095 | return false; |
| 2096 | |
| 2097 | return !Subtarget->isThumb1Only(); |
| 2098 | } |
| 2099 | |
Bob Wilson | b62d257 | 2009-11-03 00:02:05 +0000 | [diff] [blame] | 2100 | // ConstantPool, JumpTable, GlobalAddress, and ExternalSymbol are lowered as |
| 2101 | // their target counterpart wrapped in the ARMISD::Wrapper node. Suppose N is |
| 2102 | // one of the above mentioned nodes. It has to be wrapped because otherwise |
| 2103 | // Select(N) returns N. So the raw TargetGlobalAddress nodes, etc. can only |
| 2104 | // be used to form addressing mode. These wrapped nodes will be selected |
| 2105 | // into MOVi. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2106 | static SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2107 | EVT PtrVT = Op.getValueType(); |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 2108 | // FIXME there is no actual debug info here |
| 2109 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2110 | ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2111 | SDValue Res; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2112 | if (CP->isMachineConstantPoolEntry()) |
| 2113 | Res = DAG.getTargetConstantPool(CP->getMachineCPVal(), PtrVT, |
| 2114 | CP->getAlignment()); |
| 2115 | else |
| 2116 | Res = DAG.getTargetConstantPool(CP->getConstVal(), PtrVT, |
| 2117 | CP->getAlignment()); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2118 | return DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Res); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2119 | } |
| 2120 | |
Jim Grosbach | e1102ca | 2010-07-19 17:20:38 +0000 | [diff] [blame] | 2121 | unsigned ARMTargetLowering::getJumpTableEncoding() const { |
| 2122 | return MachineJumpTableInfo::EK_Inline; |
| 2123 | } |
| 2124 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2125 | SDValue ARMTargetLowering::LowerBlockAddress(SDValue Op, |
| 2126 | SelectionDAG &DAG) const { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2127 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2128 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2129 | unsigned ARMPCLabelIndex = 0; |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 2130 | DebugLoc DL = Op.getDebugLoc(); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2131 | EVT PtrVT = getPointerTy(); |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2132 | const BlockAddress *BA = cast<BlockAddressSDNode>(Op)->getBlockAddress(); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2133 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| 2134 | SDValue CPAddr; |
| 2135 | if (RelocM == Reloc::Static) { |
| 2136 | CPAddr = DAG.getTargetConstantPool(BA, PtrVT, 4); |
| 2137 | } else { |
| 2138 | unsigned PCAdj = Subtarget->isThumb() ? 4 : 8; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2139 | ARMPCLabelIndex = AFI->createPICLabelUId(); |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2140 | ARMConstantPoolValue *CPV = |
| 2141 | ARMConstantPoolConstant::Create(BA, ARMPCLabelIndex, |
| 2142 | ARMCP::CPBlockAddress, PCAdj); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2143 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
| 2144 | } |
| 2145 | CPAddr = DAG.getNode(ARMISD::Wrapper, DL, PtrVT, CPAddr); |
| 2146 | SDValue Result = DAG.getLoad(PtrVT, DL, DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2147 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2148 | false, false, false, 0); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2149 | if (RelocM == Reloc::Static) |
| 2150 | return Result; |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2151 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2152 | return DAG.getNode(ARMISD::PIC_ADD, DL, PtrVT, Result, PICLabel); |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 2153 | } |
| 2154 | |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2155 | // Lower ISD::GlobalTLSAddress using the "general dynamic" model |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2156 | SDValue |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2157 | ARMTargetLowering::LowerToTLSGeneralDynamicModel(GlobalAddressSDNode *GA, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2158 | SelectionDAG &DAG) const { |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2159 | DebugLoc dl = GA->getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2160 | EVT PtrVT = getPointerTy(); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2161 | unsigned char PCAdj = Subtarget->isThumb() ? 4 : 8; |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2162 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2163 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2164 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2165 | ARMConstantPoolValue *CPV = |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2166 | ARMConstantPoolConstant::Create(GA->getGlobal(), ARMPCLabelIndex, |
| 2167 | ARMCP::CPValue, PCAdj, ARMCP::TLSGD, true); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2168 | SDValue Argument = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2169 | Argument = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Argument); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2170 | Argument = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Argument, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2171 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2172 | false, false, false, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2173 | SDValue Chain = Argument.getValue(1); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2174 | |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2175 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2176 | Argument = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Argument, PICLabel); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2177 | |
| 2178 | // call __tls_get_addr. |
| 2179 | ArgListTy Args; |
| 2180 | ArgListEntry Entry; |
| 2181 | Entry.Node = Argument; |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 2182 | Entry.Ty = (Type *) Type::getInt32Ty(*DAG.getContext()); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2183 | Args.push_back(Entry); |
Dale Johannesen | 7d2ad62 | 2009-01-30 23:10:59 +0000 | [diff] [blame] | 2184 | // FIXME: is there useful debug info available here? |
Justin Holewinski | d2ea0e1 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 2185 | TargetLowering::CallLoweringInfo CLI(Chain, |
| 2186 | (Type *) Type::getInt32Ty(*DAG.getContext()), |
Evan Cheng | 59bc060 | 2009-08-14 19:11:20 +0000 | [diff] [blame] | 2187 | false, false, false, false, |
Evan Cheng | 4bfcd4a | 2012-02-28 18:51:51 +0000 | [diff] [blame] | 2188 | 0, CallingConv::C, /*isTailCall=*/false, |
| 2189 | /*doesNotRet=*/false, /*isReturnValueUsed=*/true, |
Bill Wendling | 46ada19 | 2010-03-02 01:55:18 +0000 | [diff] [blame] | 2190 | DAG.getExternalSymbol("__tls_get_addr", PtrVT), Args, DAG, dl); |
Justin Holewinski | d2ea0e1 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 2191 | std::pair<SDValue, SDValue> CallResult = LowerCallTo(CLI); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2192 | return CallResult.first; |
| 2193 | } |
| 2194 | |
| 2195 | // Lower ISD::GlobalTLSAddress using the "initial exec" or |
| 2196 | // "local exec" model. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2197 | SDValue |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2198 | ARMTargetLowering::LowerToTLSExecModels(GlobalAddressSDNode *GA, |
Hans Wennborg | fd5abd5 | 2012-05-04 09:40:39 +0000 | [diff] [blame] | 2199 | SelectionDAG &DAG, |
| 2200 | TLSModel::Model model) const { |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2201 | const GlobalValue *GV = GA->getGlobal(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2202 | DebugLoc dl = GA->getDebugLoc(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2203 | SDValue Offset; |
| 2204 | SDValue Chain = DAG.getEntryNode(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2205 | EVT PtrVT = getPointerTy(); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2206 | // Get the Thread Pointer |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2207 | SDValue ThreadPointer = DAG.getNode(ARMISD::THREAD_POINTER, dl, PtrVT); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2208 | |
Hans Wennborg | fd5abd5 | 2012-05-04 09:40:39 +0000 | [diff] [blame] | 2209 | if (model == TLSModel::InitialExec) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2210 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2211 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2212 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2213 | // Initial exec model. |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2214 | unsigned char PCAdj = Subtarget->isThumb() ? 4 : 8; |
| 2215 | ARMConstantPoolValue *CPV = |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2216 | ARMConstantPoolConstant::Create(GA->getGlobal(), ARMPCLabelIndex, |
| 2217 | ARMCP::CPValue, PCAdj, ARMCP::GOTTPOFF, |
| 2218 | true); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2219 | Offset = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2220 | Offset = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Offset); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2221 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2222 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2223 | false, false, false, 0); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2224 | Chain = Offset.getValue(1); |
| 2225 | |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2226 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2227 | Offset = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Offset, PICLabel); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2228 | |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2229 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2230 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2231 | false, false, false, 0); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2232 | } else { |
| 2233 | // local exec model |
Hans Wennborg | fd5abd5 | 2012-05-04 09:40:39 +0000 | [diff] [blame] | 2234 | assert(model == TLSModel::LocalExec); |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2235 | ARMConstantPoolValue *CPV = |
| 2236 | ARMConstantPoolConstant::Create(GV, ARMCP::TPOFF); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2237 | Offset = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2238 | Offset = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Offset); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2239 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2240 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2241 | false, false, false, 0); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2242 | } |
| 2243 | |
| 2244 | // The address of the thread local variable is the add of the thread |
| 2245 | // pointer with the offset of the variable. |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2246 | return DAG.getNode(ISD::ADD, dl, PtrVT, ThreadPointer, Offset); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2247 | } |
| 2248 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2249 | SDValue |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2250 | ARMTargetLowering::LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const { |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2251 | // TODO: implement the "local dynamic" model |
| 2252 | assert(Subtarget->isTargetELF() && |
| 2253 | "TLS not implemented for non-ELF targets"); |
| 2254 | GlobalAddressSDNode *GA = cast<GlobalAddressSDNode>(Op); |
Hans Wennborg | fd5abd5 | 2012-05-04 09:40:39 +0000 | [diff] [blame] | 2255 | |
| 2256 | TLSModel::Model model = getTargetMachine().getTLSModel(GA->getGlobal()); |
| 2257 | |
| 2258 | switch (model) { |
| 2259 | case TLSModel::GeneralDynamic: |
| 2260 | case TLSModel::LocalDynamic: |
| 2261 | return LowerToTLSGeneralDynamicModel(GA, DAG); |
| 2262 | case TLSModel::InitialExec: |
| 2263 | case TLSModel::LocalExec: |
| 2264 | return LowerToTLSExecModels(GA, DAG, model); |
| 2265 | } |
Matt Beaumont-Gay | 39af944 | 2012-05-04 18:34:27 +0000 | [diff] [blame] | 2266 | llvm_unreachable("bogus TLS model"); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2267 | } |
| 2268 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2269 | SDValue ARMTargetLowering::LowerGlobalAddressELF(SDValue Op, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2270 | SelectionDAG &DAG) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2271 | EVT PtrVT = getPointerTy(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2272 | DebugLoc dl = Op.getDebugLoc(); |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2273 | const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
Chad Rosier | a6ca703 | 2013-02-28 19:16:42 +0000 | [diff] [blame] | 2274 | if (getTargetMachine().getRelocationModel() == Reloc::PIC_) { |
Rafael Espindola | bb46f52 | 2009-01-15 20:18:42 +0000 | [diff] [blame] | 2275 | bool UseGOTOFF = GV->hasLocalLinkage() || GV->hasHiddenVisibility(); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2276 | ARMConstantPoolValue *CPV = |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2277 | ARMConstantPoolConstant::Create(GV, |
| 2278 | UseGOTOFF ? ARMCP::GOTOFF : ARMCP::GOT); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2279 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2280 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2281 | SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 2282 | CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2283 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2284 | false, false, false, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2285 | SDValue Chain = Result.getValue(1); |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 2286 | SDValue GOT = DAG.getGLOBAL_OFFSET_TABLE(PtrVT); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2287 | Result = DAG.getNode(ISD::ADD, dl, PtrVT, Result, GOT); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2288 | if (!UseGOTOFF) |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 2289 | Result = DAG.getLoad(PtrVT, dl, Chain, Result, |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2290 | MachinePointerInfo::getGOT(), |
| 2291 | false, false, false, 0); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2292 | return Result; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2293 | } |
| 2294 | |
| 2295 | // 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] | 2296 | // pair. This is always cheaper. |
| 2297 | if (Subtarget->useMovt()) { |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2298 | ++NumMovwMovt; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2299 | // FIXME: Once remat is capable of dealing with instructions with register |
| 2300 | // operands, expand this into two nodes. |
| 2301 | return DAG.getNode(ARMISD::Wrapper, dl, PtrVT, |
| 2302 | DAG.getTargetGlobalAddress(GV, dl, PtrVT)); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2303 | } else { |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2304 | SDValue CPAddr = DAG.getTargetConstantPool(GV, PtrVT, 4); |
| 2305 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| 2306 | return DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
| 2307 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2308 | false, false, false, 0); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2309 | } |
| 2310 | } |
| 2311 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2312 | SDValue ARMTargetLowering::LowerGlobalAddressDarwin(SDValue Op, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2313 | SelectionDAG &DAG) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2314 | EVT PtrVT = getPointerTy(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2315 | DebugLoc dl = Op.getDebugLoc(); |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2316 | const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2317 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2318 | |
Jakob Stoklund Olesen | 8f37a24 | 2012-01-07 20:49:15 +0000 | [diff] [blame] | 2319 | // FIXME: Enable this for static codegen when tool issues are fixed. Also |
| 2320 | // update ARMFastISel::ARMMaterializeGV. |
Evan Cheng | f31151f | 2011-10-26 01:17:44 +0000 | [diff] [blame] | 2321 | if (Subtarget->useMovt() && RelocM != Reloc::Static) { |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2322 | ++NumMovwMovt; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2323 | // FIXME: Once remat is capable of dealing with instructions with register |
| 2324 | // operands, expand this into two nodes. |
Evan Cheng | 53519f0 | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 2325 | if (RelocM == Reloc::Static) |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2326 | return DAG.getNode(ARMISD::Wrapper, dl, PtrVT, |
| 2327 | DAG.getTargetGlobalAddress(GV, dl, PtrVT)); |
| 2328 | |
Evan Cheng | 53519f0 | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 2329 | unsigned Wrapper = (RelocM == Reloc::PIC_) |
| 2330 | ? ARMISD::WrapperPIC : ARMISD::WrapperDYN; |
| 2331 | SDValue Result = DAG.getNode(Wrapper, dl, PtrVT, |
Evan Cheng | 9fe2009 | 2011-01-20 08:34:58 +0000 | [diff] [blame] | 2332 | DAG.getTargetGlobalAddress(GV, dl, PtrVT)); |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2333 | if (Subtarget->GVIsIndirectSymbol(GV, RelocM)) |
| 2334 | Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Result, |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2335 | MachinePointerInfo::getGOT(), |
| 2336 | false, false, false, 0); |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2337 | return Result; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2338 | } |
| 2339 | |
| 2340 | unsigned ARMPCLabelIndex = 0; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2341 | SDValue CPAddr; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2342 | if (RelocM == Reloc::Static) { |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2343 | CPAddr = DAG.getTargetConstantPool(GV, PtrVT, 4); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2344 | } else { |
Chad Rosier | a6ca703 | 2013-02-28 19:16:42 +0000 | [diff] [blame] | 2345 | ARMFunctionInfo *AFI = DAG.getMachineFunction().getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2346 | ARMPCLabelIndex = AFI->createPICLabelUId(); |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 2347 | unsigned PCAdj = (RelocM != Reloc::PIC_) ? 0 : (Subtarget->isThumb()?4:8); |
| 2348 | ARMConstantPoolValue *CPV = |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2349 | ARMConstantPoolConstant::Create(GV, ARMPCLabelIndex, ARMCP::CPValue, |
| 2350 | PCAdj); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2351 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2352 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2353 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2354 | |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2355 | SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2356 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2357 | false, false, false, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2358 | SDValue Chain = Result.getValue(1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2359 | |
| 2360 | if (RelocM == Reloc::PIC_) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2361 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2362 | Result = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2363 | } |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 2364 | |
Evan Cheng | 63476a8 | 2009-09-03 07:04:02 +0000 | [diff] [blame] | 2365 | if (Subtarget->GVIsIndirectSymbol(GV, RelocM)) |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2366 | Result = DAG.getLoad(PtrVT, dl, Chain, Result, MachinePointerInfo::getGOT(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2367 | false, false, false, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2368 | |
| 2369 | return Result; |
| 2370 | } |
| 2371 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2372 | SDValue ARMTargetLowering::LowerGLOBAL_OFFSET_TABLE(SDValue Op, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2373 | SelectionDAG &DAG) const { |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2374 | assert(Subtarget->isTargetELF() && |
| 2375 | "GLOBAL OFFSET TABLE not implemented for non-ELF targets"); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2376 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2377 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2378 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2379 | EVT PtrVT = getPointerTy(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2380 | DebugLoc dl = Op.getDebugLoc(); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2381 | unsigned PCAdj = Subtarget->isThumb() ? 4 : 8; |
Bill Wendling | fe31e67 | 2011-10-01 08:58:29 +0000 | [diff] [blame] | 2382 | ARMConstantPoolValue *CPV = |
| 2383 | ARMConstantPoolSymbol::Create(*DAG.getContext(), "_GLOBAL_OFFSET_TABLE_", |
| 2384 | ARMPCLabelIndex, PCAdj); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2385 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2386 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 2387 | SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2388 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2389 | false, false, false, 0); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2390 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2391 | return DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2392 | } |
| 2393 | |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 2394 | SDValue |
Jim Grosbach | 23ff7cf | 2010-05-26 20:22:18 +0000 | [diff] [blame] | 2395 | ARMTargetLowering::LowerEH_SJLJ_SETJMP(SDValue Op, SelectionDAG &DAG) const { |
| 2396 | DebugLoc dl = Op.getDebugLoc(); |
Jim Grosbach | 0798edd | 2010-05-27 23:49:24 +0000 | [diff] [blame] | 2397 | SDValue Val = DAG.getConstant(0, MVT::i32); |
Bill Wendling | ce370cf | 2011-10-07 21:25:38 +0000 | [diff] [blame] | 2398 | return DAG.getNode(ARMISD::EH_SJLJ_SETJMP, dl, |
| 2399 | DAG.getVTList(MVT::i32, MVT::Other), Op.getOperand(0), |
Jim Grosbach | 23ff7cf | 2010-05-26 20:22:18 +0000 | [diff] [blame] | 2400 | Op.getOperand(1), Val); |
| 2401 | } |
| 2402 | |
| 2403 | SDValue |
Jim Grosbach | 5eb1951 | 2010-05-22 01:06:18 +0000 | [diff] [blame] | 2404 | ARMTargetLowering::LowerEH_SJLJ_LONGJMP(SDValue Op, SelectionDAG &DAG) const { |
| 2405 | DebugLoc dl = Op.getDebugLoc(); |
| 2406 | return DAG.getNode(ARMISD::EH_SJLJ_LONGJMP, dl, MVT::Other, Op.getOperand(0), |
| 2407 | Op.getOperand(1), DAG.getConstant(0, MVT::i32)); |
| 2408 | } |
| 2409 | |
| 2410 | SDValue |
Jim Grosbach | a87ded2 | 2010-02-08 23:22:00 +0000 | [diff] [blame] | 2411 | ARMTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG, |
Jim Grosbach | 7616b64 | 2010-06-16 23:45:49 +0000 | [diff] [blame] | 2412 | const ARMSubtarget *Subtarget) const { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2413 | unsigned IntNo = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 2414 | DebugLoc dl = Op.getDebugLoc(); |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 2415 | switch (IntNo) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2416 | default: return SDValue(); // Don't custom lower most intrinsics. |
Bob Wilson | 916afdb | 2009-08-04 00:25:01 +0000 | [diff] [blame] | 2417 | case Intrinsic::arm_thread_pointer: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2418 | EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
Bob Wilson | 916afdb | 2009-08-04 00:25:01 +0000 | [diff] [blame] | 2419 | return DAG.getNode(ARMISD::THREAD_POINTER, dl, PtrVT); |
| 2420 | } |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2421 | case Intrinsic::eh_sjlj_lsda: { |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2422 | MachineFunction &MF = DAG.getMachineFunction(); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2423 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2424 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2425 | EVT PtrVT = getPointerTy(); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2426 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| 2427 | SDValue CPAddr; |
| 2428 | unsigned PCAdj = (RelocM != Reloc::PIC_) |
| 2429 | ? 0 : (Subtarget->isThumb() ? 4 : 8); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2430 | ARMConstantPoolValue *CPV = |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2431 | ARMConstantPoolConstant::Create(MF.getFunction(), ARMPCLabelIndex, |
| 2432 | ARMCP::CPLSDA, PCAdj); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2433 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2434 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2435 | SDValue Result = |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2436 | DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2437 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2438 | false, false, false, 0); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2439 | |
| 2440 | if (RelocM == Reloc::PIC_) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2441 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2442 | Result = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
| 2443 | } |
| 2444 | return Result; |
| 2445 | } |
Evan Cheng | 92e3916 | 2011-03-29 23:06:19 +0000 | [diff] [blame] | 2446 | case Intrinsic::arm_neon_vmulls: |
| 2447 | case Intrinsic::arm_neon_vmullu: { |
| 2448 | unsigned NewOpc = (IntNo == Intrinsic::arm_neon_vmulls) |
| 2449 | ? ARMISD::VMULLs : ARMISD::VMULLu; |
| 2450 | return DAG.getNode(NewOpc, Op.getDebugLoc(), Op.getValueType(), |
| 2451 | Op.getOperand(1), Op.getOperand(2)); |
| 2452 | } |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 2453 | } |
| 2454 | } |
| 2455 | |
Jim Grosbach | 7c03dbd | 2009-12-14 21:24:16 +0000 | [diff] [blame] | 2456 | static SDValue LowerMEMBARRIER(SDValue Op, SelectionDAG &DAG, |
Jim Grosbach | 7616b64 | 2010-06-16 23:45:49 +0000 | [diff] [blame] | 2457 | const ARMSubtarget *Subtarget) { |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 2458 | DebugLoc dl = Op.getDebugLoc(); |
Bob Wilson | f74a429 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 2459 | if (!Subtarget->hasDataBarrier()) { |
| 2460 | // Some ARMv6 cpus can support data barriers with an mcr instruction. |
| 2461 | // Thumb1 and pre-v6 ARM mode use a libcall instead and should never get |
| 2462 | // here. |
Bob Wilson | 54f9256 | 2010-11-09 22:50:44 +0000 | [diff] [blame] | 2463 | assert(Subtarget->hasV6Ops() && !Subtarget->isThumb() && |
Evan Cheng | 11db068 | 2010-08-11 06:22:01 +0000 | [diff] [blame] | 2464 | "Unexpected ISD::MEMBARRIER encountered. Should be libcall!"); |
Bob Wilson | f74a429 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 2465 | return DAG.getNode(ARMISD::MEMBARRIER_MCR, dl, MVT::Other, Op.getOperand(0), |
Jim Grosbach | c73993b | 2010-06-17 01:37:00 +0000 | [diff] [blame] | 2466 | DAG.getConstant(0, MVT::i32)); |
Evan Cheng | 11db068 | 2010-08-11 06:22:01 +0000 | [diff] [blame] | 2467 | } |
Bob Wilson | f74a429 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 2468 | |
| 2469 | SDValue Op5 = Op.getOperand(5); |
| 2470 | bool isDeviceBarrier = cast<ConstantSDNode>(Op5)->getZExtValue() != 0; |
| 2471 | unsigned isLL = cast<ConstantSDNode>(Op.getOperand(1))->getZExtValue(); |
| 2472 | unsigned isLS = cast<ConstantSDNode>(Op.getOperand(2))->getZExtValue(); |
| 2473 | bool isOnlyStoreBarrier = (isLL == 0 && isLS == 0); |
| 2474 | |
| 2475 | ARM_MB::MemBOpt DMBOpt; |
| 2476 | if (isDeviceBarrier) |
| 2477 | DMBOpt = isOnlyStoreBarrier ? ARM_MB::ST : ARM_MB::SY; |
| 2478 | else |
| 2479 | DMBOpt = isOnlyStoreBarrier ? ARM_MB::ISHST : ARM_MB::ISH; |
| 2480 | return DAG.getNode(ARMISD::MEMBARRIER, dl, MVT::Other, Op.getOperand(0), |
| 2481 | DAG.getConstant(DMBOpt, MVT::i32)); |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 2482 | } |
| 2483 | |
Eli Friedman | 26689ac | 2011-08-03 21:06:02 +0000 | [diff] [blame] | 2484 | |
| 2485 | static SDValue LowerATOMIC_FENCE(SDValue Op, SelectionDAG &DAG, |
| 2486 | const ARMSubtarget *Subtarget) { |
| 2487 | // FIXME: handle "fence singlethread" more efficiently. |
| 2488 | DebugLoc dl = Op.getDebugLoc(); |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 2489 | if (!Subtarget->hasDataBarrier()) { |
| 2490 | // Some ARMv6 cpus can support data barriers with an mcr instruction. |
| 2491 | // Thumb1 and pre-v6 ARM mode use a libcall instead and should never get |
| 2492 | // here. |
| 2493 | assert(Subtarget->hasV6Ops() && !Subtarget->isThumb() && |
| 2494 | "Unexpected ISD::MEMBARRIER encountered. Should be libcall!"); |
Eli Friedman | 26689ac | 2011-08-03 21:06:02 +0000 | [diff] [blame] | 2495 | return DAG.getNode(ARMISD::MEMBARRIER_MCR, dl, MVT::Other, Op.getOperand(0), |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 2496 | DAG.getConstant(0, MVT::i32)); |
| 2497 | } |
| 2498 | |
Eli Friedman | 26689ac | 2011-08-03 21:06:02 +0000 | [diff] [blame] | 2499 | return DAG.getNode(ARMISD::MEMBARRIER, dl, MVT::Other, Op.getOperand(0), |
Eli Friedman | 989f61e | 2011-08-02 22:44:16 +0000 | [diff] [blame] | 2500 | DAG.getConstant(ARM_MB::ISH, MVT::i32)); |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 2501 | } |
| 2502 | |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2503 | static SDValue LowerPREFETCH(SDValue Op, SelectionDAG &DAG, |
| 2504 | const ARMSubtarget *Subtarget) { |
| 2505 | // ARM pre v5TE and Thumb1 does not have preload instructions. |
| 2506 | if (!(Subtarget->isThumb2() || |
| 2507 | (!Subtarget->isThumb1Only() && Subtarget->hasV5TEOps()))) |
| 2508 | // Just preserve the chain. |
| 2509 | return Op.getOperand(0); |
| 2510 | |
| 2511 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 2512 | unsigned isRead = ~cast<ConstantSDNode>(Op.getOperand(2))->getZExtValue() & 1; |
| 2513 | if (!isRead && |
| 2514 | (!Subtarget->hasV7Ops() || !Subtarget->hasMPExtension())) |
| 2515 | // ARMv7 with MP extension has PLDW. |
| 2516 | return Op.getOperand(0); |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2517 | |
Bruno Cardoso Lopes | 9a76733 | 2011-06-14 04:58:37 +0000 | [diff] [blame] | 2518 | unsigned isData = cast<ConstantSDNode>(Op.getOperand(4))->getZExtValue(); |
| 2519 | if (Subtarget->isThumb()) { |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2520 | // Invert the bits. |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 2521 | isRead = ~isRead & 1; |
Bruno Cardoso Lopes | 9a76733 | 2011-06-14 04:58:37 +0000 | [diff] [blame] | 2522 | isData = ~isData & 1; |
| 2523 | } |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2524 | |
| 2525 | return DAG.getNode(ARMISD::PRELOAD, dl, MVT::Other, Op.getOperand(0), |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 2526 | Op.getOperand(1), DAG.getConstant(isRead, MVT::i32), |
| 2527 | DAG.getConstant(isData, MVT::i32)); |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2528 | } |
| 2529 | |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 2530 | static SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) { |
| 2531 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2532 | ARMFunctionInfo *FuncInfo = MF.getInfo<ARMFunctionInfo>(); |
| 2533 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2534 | // vastart just stores the address of the VarArgsFrameIndex slot into the |
| 2535 | // memory location argument. |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2536 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2537 | EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 2538 | SDValue FR = DAG.getFrameIndex(FuncInfo->getVarArgsFrameIndex(), PtrVT); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 2539 | const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue(); |
Chris Lattner | fc448ff | 2010-09-21 18:51:21 +0000 | [diff] [blame] | 2540 | return DAG.getStore(Op.getOperand(0), dl, FR, Op.getOperand(1), |
| 2541 | MachinePointerInfo(SV), false, false, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2542 | } |
| 2543 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2544 | SDValue |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2545 | ARMTargetLowering::GetF64FormalArgument(CCValAssign &VA, CCValAssign &NextVA, |
| 2546 | SDValue &Root, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2547 | DebugLoc dl) const { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2548 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2549 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2550 | |
Craig Topper | 44d2382 | 2012-02-22 05:59:10 +0000 | [diff] [blame] | 2551 | const TargetRegisterClass *RC; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 2552 | if (AFI->isThumb1OnlyFunction()) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 2553 | RC = &ARM::tGPRRegClass; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2554 | else |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 2555 | RC = &ARM::GPRRegClass; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2556 | |
| 2557 | // Transform the arguments stored in physical registers into virtual ones. |
Devang Patel | 68e6bee | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 2558 | unsigned Reg = MF.addLiveIn(VA.getLocReg(), RC); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2559 | SDValue ArgValue = DAG.getCopyFromReg(Root, dl, Reg, MVT::i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2560 | |
| 2561 | SDValue ArgValue2; |
| 2562 | if (NextVA.isMemLoc()) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2563 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
Evan Cheng | ed2ae13 | 2010-07-03 00:40:23 +0000 | [diff] [blame] | 2564 | int FI = MFI->CreateFixedObject(4, NextVA.getLocMemOffset(), true); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2565 | |
| 2566 | // Create load node to retrieve arguments from the stack. |
| 2567 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2568 | ArgValue2 = DAG.getLoad(MVT::i32, dl, Root, FIN, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2569 | MachinePointerInfo::getFixedStack(FI), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2570 | false, false, false, 0); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2571 | } else { |
Devang Patel | 68e6bee | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 2572 | Reg = MF.addLiveIn(NextVA.getLocReg(), RC); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2573 | ArgValue2 = DAG.getCopyFromReg(Root, dl, Reg, MVT::i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2574 | } |
| 2575 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 2576 | return DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, ArgValue, ArgValue2); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2577 | } |
| 2578 | |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2579 | void |
| 2580 | ARMTargetLowering::computeRegArea(CCState &CCInfo, MachineFunction &MF, |
| 2581 | unsigned &VARegSize, unsigned &VARegSaveSize) |
| 2582 | const { |
| 2583 | unsigned NumGPRs; |
| 2584 | if (CCInfo.isFirstByValRegValid()) |
| 2585 | NumGPRs = ARM::R4 - CCInfo.getFirstByValReg(); |
| 2586 | else { |
| 2587 | unsigned int firstUnalloced; |
| 2588 | firstUnalloced = CCInfo.getFirstUnallocated(GPRArgRegs, |
| 2589 | sizeof(GPRArgRegs) / |
| 2590 | sizeof(GPRArgRegs[0])); |
| 2591 | NumGPRs = (firstUnalloced <= 3) ? (4 - firstUnalloced) : 0; |
| 2592 | } |
| 2593 | |
| 2594 | unsigned Align = MF.getTarget().getFrameLowering()->getStackAlignment(); |
| 2595 | VARegSize = NumGPRs * 4; |
| 2596 | VARegSaveSize = (VARegSize + Align - 1) & ~(Align - 1); |
| 2597 | } |
| 2598 | |
| 2599 | // The remaining GPRs hold either the beginning of variable-argument |
David Peixotto | e68542e | 2013-02-13 00:36:35 +0000 | [diff] [blame] | 2600 | // data, or the beginning of an aggregate passed by value (usually |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2601 | // byval). Either way, we allocate stack slots adjacent to the data |
| 2602 | // provided by our caller, and store the unallocated registers there. |
| 2603 | // If this is a variadic function, the va_list pointer will begin with |
| 2604 | // these values; otherwise, this reassembles a (byval) structure that |
| 2605 | // was split between registers and memory. |
| 2606 | void |
| 2607 | ARMTargetLowering::VarArgStyleRegisters(CCState &CCInfo, SelectionDAG &DAG, |
| 2608 | DebugLoc dl, SDValue &Chain, |
Stepan Dyatkovskiy | 661afe7 | 2012-10-10 11:37:36 +0000 | [diff] [blame] | 2609 | const Value *OrigArg, |
| 2610 | unsigned OffsetFromOrigArg, |
Stepan Dyatkovskiy | 0d3c8d5 | 2012-10-19 08:23:06 +0000 | [diff] [blame] | 2611 | unsigned ArgOffset, |
| 2612 | bool ForceMutable) const { |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2613 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2614 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 2615 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2616 | unsigned firstRegToSaveIndex; |
| 2617 | if (CCInfo.isFirstByValRegValid()) |
| 2618 | firstRegToSaveIndex = CCInfo.getFirstByValReg() - ARM::R0; |
| 2619 | else { |
| 2620 | firstRegToSaveIndex = CCInfo.getFirstUnallocated |
| 2621 | (GPRArgRegs, sizeof(GPRArgRegs) / sizeof(GPRArgRegs[0])); |
| 2622 | } |
| 2623 | |
| 2624 | unsigned VARegSize, VARegSaveSize; |
| 2625 | computeRegArea(CCInfo, MF, VARegSize, VARegSaveSize); |
| 2626 | if (VARegSaveSize) { |
| 2627 | // If this function is vararg, store any remaining integer argument regs |
| 2628 | // to their spots on the stack so that they may be loaded by deferencing |
| 2629 | // the result of va_next. |
| 2630 | AFI->setVarArgsRegSaveSize(VARegSaveSize); |
Eric Christopher | 5ac179c | 2011-04-29 23:12:01 +0000 | [diff] [blame] | 2631 | AFI->setVarArgsFrameIndex(MFI->CreateFixedObject(VARegSaveSize, |
| 2632 | ArgOffset + VARegSaveSize |
| 2633 | - VARegSize, |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2634 | false)); |
| 2635 | SDValue FIN = DAG.getFrameIndex(AFI->getVarArgsFrameIndex(), |
| 2636 | getPointerTy()); |
| 2637 | |
| 2638 | SmallVector<SDValue, 4> MemOps; |
Stepan Dyatkovskiy | 661afe7 | 2012-10-10 11:37:36 +0000 | [diff] [blame] | 2639 | for (unsigned i = 0; firstRegToSaveIndex < 4; ++firstRegToSaveIndex, ++i) { |
Craig Topper | 44d2382 | 2012-02-22 05:59:10 +0000 | [diff] [blame] | 2640 | const TargetRegisterClass *RC; |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2641 | if (AFI->isThumb1OnlyFunction()) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 2642 | RC = &ARM::tGPRRegClass; |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2643 | else |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 2644 | RC = &ARM::GPRRegClass; |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2645 | |
| 2646 | unsigned VReg = MF.addLiveIn(GPRArgRegs[firstRegToSaveIndex], RC); |
| 2647 | SDValue Val = DAG.getCopyFromReg(Chain, dl, VReg, MVT::i32); |
| 2648 | SDValue Store = |
| 2649 | DAG.getStore(Val.getValue(1), dl, Val, FIN, |
Stepan Dyatkovskiy | 661afe7 | 2012-10-10 11:37:36 +0000 | [diff] [blame] | 2650 | MachinePointerInfo(OrigArg, OffsetFromOrigArg + 4*i), |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2651 | false, false, 0); |
| 2652 | MemOps.push_back(Store); |
| 2653 | FIN = DAG.getNode(ISD::ADD, dl, getPointerTy(), FIN, |
| 2654 | DAG.getConstant(4, getPointerTy())); |
| 2655 | } |
| 2656 | if (!MemOps.empty()) |
| 2657 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, |
| 2658 | &MemOps[0], MemOps.size()); |
| 2659 | } else |
| 2660 | // This will point to the next argument passed via stack. |
Stepan Dyatkovskiy | 0d3c8d5 | 2012-10-19 08:23:06 +0000 | [diff] [blame] | 2661 | AFI->setVarArgsFrameIndex( |
| 2662 | MFI->CreateFixedObject(4, ArgOffset, !ForceMutable)); |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2663 | } |
| 2664 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2665 | SDValue |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2666 | ARMTargetLowering::LowerFormalArguments(SDValue Chain, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 2667 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2668 | const SmallVectorImpl<ISD::InputArg> |
| 2669 | &Ins, |
| 2670 | DebugLoc dl, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2671 | SmallVectorImpl<SDValue> &InVals) |
| 2672 | const { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2673 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2674 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 2675 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2676 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2677 | |
| 2678 | // Assign locations to all of the incoming arguments. |
| 2679 | SmallVector<CCValAssign, 16> ArgLocs; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 2680 | ARMCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), |
| 2681 | getTargetMachine(), ArgLocs, *DAG.getContext(), Prologue); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2682 | CCInfo.AnalyzeFormalArguments(Ins, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 2683 | CCAssignFnForNode(CallConv, /* Return*/ false, |
| 2684 | isVarArg)); |
Stepan Dyatkovskiy | 661afe7 | 2012-10-10 11:37:36 +0000 | [diff] [blame] | 2685 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2686 | SmallVector<SDValue, 16> ArgValues; |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2687 | int lastInsIndex = -1; |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2688 | SDValue ArgValue; |
Stepan Dyatkovskiy | 661afe7 | 2012-10-10 11:37:36 +0000 | [diff] [blame] | 2689 | Function::const_arg_iterator CurOrigArg = MF.getFunction()->arg_begin(); |
| 2690 | unsigned CurArgIdx = 0; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2691 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| 2692 | CCValAssign &VA = ArgLocs[i]; |
Stepan Dyatkovskiy | 661afe7 | 2012-10-10 11:37:36 +0000 | [diff] [blame] | 2693 | std::advance(CurOrigArg, Ins[VA.getValNo()].OrigArgIndex - CurArgIdx); |
| 2694 | CurArgIdx = Ins[VA.getValNo()].OrigArgIndex; |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 2695 | // Arguments stored in registers. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2696 | if (VA.isRegLoc()) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2697 | EVT RegVT = VA.getLocVT(); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2698 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2699 | if (VA.needsCustom()) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2700 | // f64 and vector types are split up into multiple registers or |
| 2701 | // combinations of registers and stack slots. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2702 | if (VA.getLocVT() == MVT::v2f64) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2703 | SDValue ArgValue1 = GetF64FormalArgument(VA, ArgLocs[++i], |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2704 | Chain, DAG, dl); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2705 | VA = ArgLocs[++i]; // skip ahead to next loc |
Bob Wilson | 6a234f0 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 2706 | SDValue ArgValue2; |
| 2707 | if (VA.isMemLoc()) { |
Evan Cheng | ed2ae13 | 2010-07-03 00:40:23 +0000 | [diff] [blame] | 2708 | int FI = MFI->CreateFixedObject(8, VA.getLocMemOffset(), true); |
Bob Wilson | 6a234f0 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 2709 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
| 2710 | ArgValue2 = DAG.getLoad(MVT::f64, dl, Chain, FIN, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2711 | MachinePointerInfo::getFixedStack(FI), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2712 | false, false, false, 0); |
Bob Wilson | 6a234f0 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 2713 | } else { |
| 2714 | ArgValue2 = GetF64FormalArgument(VA, ArgLocs[++i], |
| 2715 | Chain, DAG, dl); |
| 2716 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2717 | ArgValue = DAG.getNode(ISD::UNDEF, dl, MVT::v2f64); |
| 2718 | ArgValue = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2719 | ArgValue, ArgValue1, DAG.getIntPtrConstant(0)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2720 | ArgValue = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2721 | ArgValue, ArgValue2, DAG.getIntPtrConstant(1)); |
| 2722 | } else |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2723 | ArgValue = GetF64FormalArgument(VA, ArgLocs[++i], Chain, DAG, dl); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2724 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2725 | } else { |
Craig Topper | 44d2382 | 2012-02-22 05:59:10 +0000 | [diff] [blame] | 2726 | const TargetRegisterClass *RC; |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 2727 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2728 | if (RegVT == MVT::f32) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 2729 | RC = &ARM::SPRRegClass; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2730 | else if (RegVT == MVT::f64) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 2731 | RC = &ARM::DPRRegClass; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2732 | else if (RegVT == MVT::v2f64) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 2733 | RC = &ARM::QPRRegClass; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2734 | else if (RegVT == MVT::i32) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 2735 | RC = AFI->isThumb1OnlyFunction() ? |
| 2736 | (const TargetRegisterClass*)&ARM::tGPRRegClass : |
| 2737 | (const TargetRegisterClass*)&ARM::GPRRegClass; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2738 | else |
Anton Korobeynikov | 058c251 | 2009-08-05 20:15:19 +0000 | [diff] [blame] | 2739 | llvm_unreachable("RegVT not supported by FORMAL_ARGUMENTS Lowering"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2740 | |
| 2741 | // Transform the arguments in physical registers into virtual ones. |
Devang Patel | 68e6bee | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 2742 | unsigned Reg = MF.addLiveIn(VA.getLocReg(), RC); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2743 | ArgValue = DAG.getCopyFromReg(Chain, dl, Reg, RegVT); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2744 | } |
| 2745 | |
| 2746 | // If this is an 8 or 16-bit value, it is really passed promoted |
| 2747 | // to 32 bits. Insert an assert[sz]ext to capture this, then |
| 2748 | // truncate to the right size. |
| 2749 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 2750 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2751 | case CCValAssign::Full: break; |
| 2752 | case CCValAssign::BCvt: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2753 | ArgValue = DAG.getNode(ISD::BITCAST, dl, VA.getValVT(), ArgValue); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2754 | break; |
| 2755 | case CCValAssign::SExt: |
| 2756 | ArgValue = DAG.getNode(ISD::AssertSext, dl, RegVT, ArgValue, |
| 2757 | DAG.getValueType(VA.getValVT())); |
| 2758 | ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue); |
| 2759 | break; |
| 2760 | case CCValAssign::ZExt: |
| 2761 | ArgValue = DAG.getNode(ISD::AssertZext, dl, RegVT, ArgValue, |
| 2762 | DAG.getValueType(VA.getValVT())); |
| 2763 | ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue); |
| 2764 | break; |
| 2765 | } |
| 2766 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2767 | InVals.push_back(ArgValue); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2768 | |
| 2769 | } else { // VA.isRegLoc() |
| 2770 | |
| 2771 | // sanity check |
| 2772 | assert(VA.isMemLoc()); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2773 | assert(VA.getValVT() != MVT::i64 && "i64 should already be lowered"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2774 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2775 | int index = ArgLocs[i].getValNo(); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 2776 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2777 | // Some Ins[] entries become multiple ArgLoc[] entries. |
| 2778 | // Process them only once. |
| 2779 | if (index != lastInsIndex) |
| 2780 | { |
| 2781 | ISD::ArgFlagsTy Flags = Ins[index].Flags; |
Eric Christopher | 471e422 | 2011-06-08 23:55:35 +0000 | [diff] [blame] | 2782 | // FIXME: For now, all byval parameter objects are marked mutable. |
Eric Christopher | 5ac179c | 2011-04-29 23:12:01 +0000 | [diff] [blame] | 2783 | // This can be changed with more analysis. |
| 2784 | // In case of tail call optimization mark all arguments mutable. |
| 2785 | // Since they could be overwritten by lowering of arguments in case of |
| 2786 | // a tail call. |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2787 | if (Flags.isByVal()) { |
Stepan Dyatkovskiy | 0d3c8d5 | 2012-10-19 08:23:06 +0000 | [diff] [blame] | 2788 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2789 | if (!AFI->getVarArgsFrameIndex()) { |
| 2790 | VarArgStyleRegisters(CCInfo, DAG, |
| 2791 | dl, Chain, CurOrigArg, |
| 2792 | Ins[VA.getValNo()].PartOffset, |
| 2793 | VA.getLocMemOffset(), |
| 2794 | true /*force mutable frames*/); |
| 2795 | int VAFrameIndex = AFI->getVarArgsFrameIndex(); |
| 2796 | InVals.push_back(DAG.getFrameIndex(VAFrameIndex, getPointerTy())); |
| 2797 | } else { |
| 2798 | int FI = MFI->CreateFixedObject(Flags.getByValSize(), |
| 2799 | VA.getLocMemOffset(), false); |
| 2800 | InVals.push_back(DAG.getFrameIndex(FI, getPointerTy())); |
| 2801 | } |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2802 | } else { |
| 2803 | int FI = MFI->CreateFixedObject(VA.getLocVT().getSizeInBits()/8, |
| 2804 | VA.getLocMemOffset(), true); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2805 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2806 | // Create load nodes to retrieve arguments from the stack. |
| 2807 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
| 2808 | InVals.push_back(DAG.getLoad(VA.getValVT(), dl, Chain, FIN, |
| 2809 | MachinePointerInfo::getFixedStack(FI), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2810 | false, false, false, 0)); |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2811 | } |
| 2812 | lastInsIndex = index; |
| 2813 | } |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2814 | } |
| 2815 | } |
| 2816 | |
| 2817 | // varargs |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2818 | if (isVarArg) |
Stepan Dyatkovskiy | 661afe7 | 2012-10-10 11:37:36 +0000 | [diff] [blame] | 2819 | VarArgStyleRegisters(CCInfo, DAG, dl, Chain, 0, 0, |
| 2820 | CCInfo.getNextStackOffset()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2821 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2822 | return Chain; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2823 | } |
| 2824 | |
| 2825 | /// isFloatingPointZero - Return true if this is +0.0. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2826 | static bool isFloatingPointZero(SDValue Op) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2827 | if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(Op)) |
Dale Johannesen | eaf0894 | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 2828 | return CFP->getValueAPF().isPosZero(); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2829 | else if (ISD::isEXTLoad(Op.getNode()) || ISD::isNON_EXTLoad(Op.getNode())) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2830 | // Maybe this has already been legalized into the constant pool? |
| 2831 | if (Op.getOperand(1).getOpcode() == ARMISD::Wrapper) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2832 | SDValue WrapperOp = Op.getOperand(1).getOperand(0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2833 | if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(WrapperOp)) |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2834 | if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CP->getConstVal())) |
Dale Johannesen | eaf0894 | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 2835 | return CFP->getValueAPF().isPosZero(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2836 | } |
| 2837 | } |
| 2838 | return false; |
| 2839 | } |
| 2840 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2841 | /// Returns appropriate ARM CMP (cmp) and corresponding condition code for |
| 2842 | /// the given operands. |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 2843 | SDValue |
| 2844 | ARMTargetLowering::getARMCmp(SDValue LHS, SDValue RHS, ISD::CondCode CC, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2845 | SDValue &ARMcc, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2846 | DebugLoc dl) const { |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2847 | if (ConstantSDNode *RHSC = dyn_cast<ConstantSDNode>(RHS.getNode())) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2848 | unsigned C = RHSC->getZExtValue(); |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 2849 | if (!isLegalICmpImmediate(C)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2850 | // Constant does not fit, try adjusting it by one? |
| 2851 | switch (CC) { |
| 2852 | default: break; |
| 2853 | case ISD::SETLT: |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2854 | case ISD::SETGE: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 2855 | if (C != 0x80000000 && isLegalICmpImmediate(C-1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2856 | CC = (CC == ISD::SETLT) ? ISD::SETLE : ISD::SETGT; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2857 | RHS = DAG.getConstant(C-1, MVT::i32); |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2858 | } |
| 2859 | break; |
| 2860 | case ISD::SETULT: |
| 2861 | case ISD::SETUGE: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 2862 | if (C != 0 && isLegalICmpImmediate(C-1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2863 | CC = (CC == ISD::SETULT) ? ISD::SETULE : ISD::SETUGT; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2864 | RHS = DAG.getConstant(C-1, MVT::i32); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2865 | } |
| 2866 | break; |
| 2867 | case ISD::SETLE: |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2868 | case ISD::SETGT: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 2869 | if (C != 0x7fffffff && isLegalICmpImmediate(C+1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2870 | CC = (CC == ISD::SETLE) ? ISD::SETLT : ISD::SETGE; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2871 | RHS = DAG.getConstant(C+1, MVT::i32); |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2872 | } |
| 2873 | break; |
| 2874 | case ISD::SETULE: |
| 2875 | case ISD::SETUGT: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 2876 | if (C != 0xffffffff && isLegalICmpImmediate(C+1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2877 | CC = (CC == ISD::SETULE) ? ISD::SETULT : ISD::SETUGE; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2878 | RHS = DAG.getConstant(C+1, MVT::i32); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2879 | } |
| 2880 | break; |
| 2881 | } |
| 2882 | } |
| 2883 | } |
| 2884 | |
| 2885 | ARMCC::CondCodes CondCode = IntCCToARMCC(CC); |
Lauro Ramos Venancio | 9996663 | 2007-04-02 01:30:03 +0000 | [diff] [blame] | 2886 | ARMISD::NodeType CompareType; |
| 2887 | switch (CondCode) { |
| 2888 | default: |
| 2889 | CompareType = ARMISD::CMP; |
| 2890 | break; |
| 2891 | case ARMCC::EQ: |
| 2892 | case ARMCC::NE: |
David Goodwin | c0309b4 | 2009-06-29 15:33:01 +0000 | [diff] [blame] | 2893 | // Uses only Z Flag |
| 2894 | CompareType = ARMISD::CMPZ; |
Lauro Ramos Venancio | 9996663 | 2007-04-02 01:30:03 +0000 | [diff] [blame] | 2895 | break; |
| 2896 | } |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2897 | ARMcc = DAG.getConstant(CondCode, MVT::i32); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 2898 | return DAG.getNode(CompareType, dl, MVT::Glue, LHS, RHS); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2899 | } |
| 2900 | |
| 2901 | /// 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] | 2902 | SDValue |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2903 | ARMTargetLowering::getVFPCmp(SDValue LHS, SDValue RHS, SelectionDAG &DAG, |
Evan Cheng | 515fe3a | 2010-07-08 02:08:50 +0000 | [diff] [blame] | 2904 | DebugLoc dl) const { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2905 | SDValue Cmp; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2906 | if (!isFloatingPointZero(RHS)) |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 2907 | Cmp = DAG.getNode(ARMISD::CMPFP, dl, MVT::Glue, LHS, RHS); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2908 | else |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 2909 | Cmp = DAG.getNode(ARMISD::CMPFPw0, dl, MVT::Glue, LHS); |
| 2910 | return DAG.getNode(ARMISD::FMSTAT, dl, MVT::Glue, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2911 | } |
| 2912 | |
Bob Wilson | 79f56c9 | 2011-03-08 01:17:20 +0000 | [diff] [blame] | 2913 | /// duplicateCmp - Glue values can have only one use, so this function |
| 2914 | /// duplicates a comparison node. |
| 2915 | SDValue |
| 2916 | ARMTargetLowering::duplicateCmp(SDValue Cmp, SelectionDAG &DAG) const { |
| 2917 | unsigned Opc = Cmp.getOpcode(); |
| 2918 | DebugLoc DL = Cmp.getDebugLoc(); |
| 2919 | if (Opc == ARMISD::CMP || Opc == ARMISD::CMPZ) |
| 2920 | return DAG.getNode(Opc, DL, MVT::Glue, Cmp.getOperand(0),Cmp.getOperand(1)); |
| 2921 | |
| 2922 | assert(Opc == ARMISD::FMSTAT && "unexpected comparison operation"); |
| 2923 | Cmp = Cmp.getOperand(0); |
| 2924 | Opc = Cmp.getOpcode(); |
| 2925 | if (Opc == ARMISD::CMPFP) |
| 2926 | Cmp = DAG.getNode(Opc, DL, MVT::Glue, Cmp.getOperand(0),Cmp.getOperand(1)); |
| 2927 | else { |
| 2928 | assert(Opc == ARMISD::CMPFPw0 && "unexpected operand of FMSTAT"); |
| 2929 | Cmp = DAG.getNode(Opc, DL, MVT::Glue, Cmp.getOperand(0)); |
| 2930 | } |
| 2931 | return DAG.getNode(ARMISD::FMSTAT, DL, MVT::Glue, Cmp); |
| 2932 | } |
| 2933 | |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 2934 | SDValue ARMTargetLowering::LowerSELECT(SDValue Op, SelectionDAG &DAG) const { |
| 2935 | SDValue Cond = Op.getOperand(0); |
| 2936 | SDValue SelectTrue = Op.getOperand(1); |
| 2937 | SDValue SelectFalse = Op.getOperand(2); |
| 2938 | DebugLoc dl = Op.getDebugLoc(); |
| 2939 | |
| 2940 | // Convert: |
| 2941 | // |
| 2942 | // (select (cmov 1, 0, cond), t, f) -> (cmov t, f, cond) |
| 2943 | // (select (cmov 0, 1, cond), t, f) -> (cmov f, t, cond) |
| 2944 | // |
| 2945 | if (Cond.getOpcode() == ARMISD::CMOV && Cond.hasOneUse()) { |
| 2946 | const ConstantSDNode *CMOVTrue = |
| 2947 | dyn_cast<ConstantSDNode>(Cond.getOperand(0)); |
| 2948 | const ConstantSDNode *CMOVFalse = |
| 2949 | dyn_cast<ConstantSDNode>(Cond.getOperand(1)); |
| 2950 | |
| 2951 | if (CMOVTrue && CMOVFalse) { |
| 2952 | unsigned CMOVTrueVal = CMOVTrue->getZExtValue(); |
| 2953 | unsigned CMOVFalseVal = CMOVFalse->getZExtValue(); |
| 2954 | |
| 2955 | SDValue True; |
| 2956 | SDValue False; |
| 2957 | if (CMOVTrueVal == 1 && CMOVFalseVal == 0) { |
| 2958 | True = SelectTrue; |
| 2959 | False = SelectFalse; |
| 2960 | } else if (CMOVTrueVal == 0 && CMOVFalseVal == 1) { |
| 2961 | True = SelectFalse; |
| 2962 | False = SelectTrue; |
| 2963 | } |
| 2964 | |
| 2965 | if (True.getNode() && False.getNode()) { |
Evan Cheng | b936e30 | 2011-05-18 18:59:17 +0000 | [diff] [blame] | 2966 | EVT VT = Op.getValueType(); |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 2967 | SDValue ARMcc = Cond.getOperand(2); |
| 2968 | SDValue CCR = Cond.getOperand(3); |
Bob Wilson | 79f56c9 | 2011-03-08 01:17:20 +0000 | [diff] [blame] | 2969 | SDValue Cmp = duplicateCmp(Cond.getOperand(4), DAG); |
Evan Cheng | b936e30 | 2011-05-18 18:59:17 +0000 | [diff] [blame] | 2970 | assert(True.getValueType() == VT); |
| 2971 | return DAG.getNode(ARMISD::CMOV, dl, VT, True, False, ARMcc, CCR, Cmp); |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 2972 | } |
| 2973 | } |
| 2974 | } |
| 2975 | |
Dan Gohman | db95389 | 2012-02-24 00:09:36 +0000 | [diff] [blame] | 2976 | // ARM's BooleanContents value is UndefinedBooleanContent. Mask out the |
| 2977 | // undefined bits before doing a full-word comparison with zero. |
| 2978 | Cond = DAG.getNode(ISD::AND, dl, Cond.getValueType(), Cond, |
| 2979 | DAG.getConstant(1, Cond.getValueType())); |
| 2980 | |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 2981 | return DAG.getSelectCC(dl, Cond, |
| 2982 | DAG.getConstant(0, Cond.getValueType()), |
| 2983 | SelectTrue, SelectFalse, ISD::SETNE); |
| 2984 | } |
| 2985 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2986 | SDValue ARMTargetLowering::LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2987 | EVT VT = Op.getValueType(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2988 | SDValue LHS = Op.getOperand(0); |
| 2989 | SDValue RHS = Op.getOperand(1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2990 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(4))->get(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2991 | SDValue TrueVal = Op.getOperand(2); |
| 2992 | SDValue FalseVal = Op.getOperand(3); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2993 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2994 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2995 | if (LHS.getValueType() == MVT::i32) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2996 | SDValue ARMcc; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2997 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2998 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMcc, DAG, dl); |
Jim Grosbach | b04546f | 2011-09-13 20:30:37 +0000 | [diff] [blame] | 2999 | return DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, ARMcc, CCR,Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3000 | } |
| 3001 | |
| 3002 | ARMCC::CondCodes CondCode, CondCode2; |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 3003 | FPCCToARMCC(CC, CondCode, CondCode2); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3004 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3005 | SDValue ARMcc = DAG.getConstant(CondCode, MVT::i32); |
| 3006 | SDValue Cmp = getVFPCmp(LHS, RHS, DAG, dl); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3007 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 3008 | SDValue Result = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3009 | ARMcc, CCR, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3010 | if (CondCode2 != ARMCC::AL) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3011 | SDValue ARMcc2 = DAG.getConstant(CondCode2, MVT::i32); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3012 | // FIXME: Needs another CMP because flag can have but one use. |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3013 | SDValue Cmp2 = getVFPCmp(LHS, RHS, DAG, dl); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3014 | Result = DAG.getNode(ARMISD::CMOV, dl, VT, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3015 | Result, TrueVal, ARMcc2, CCR, Cmp2); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3016 | } |
| 3017 | return Result; |
| 3018 | } |
| 3019 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3020 | /// canChangeToInt - Given the fp compare operand, return true if it is suitable |
| 3021 | /// to morph to an integer compare sequence. |
| 3022 | static bool canChangeToInt(SDValue Op, bool &SeenZero, |
| 3023 | const ARMSubtarget *Subtarget) { |
| 3024 | SDNode *N = Op.getNode(); |
| 3025 | if (!N->hasOneUse()) |
| 3026 | // Otherwise it requires moving the value from fp to integer registers. |
| 3027 | return false; |
| 3028 | if (!N->getNumValues()) |
| 3029 | return false; |
| 3030 | EVT VT = Op.getValueType(); |
| 3031 | if (VT != MVT::f32 && !Subtarget->isFPBrccSlow()) |
| 3032 | // f32 case is generally profitable. f64 case only makes sense when vcmpe + |
| 3033 | // vmrs are very slow, e.g. cortex-a8. |
| 3034 | return false; |
| 3035 | |
| 3036 | if (isFloatingPointZero(Op)) { |
| 3037 | SeenZero = true; |
| 3038 | return true; |
| 3039 | } |
| 3040 | return ISD::isNormalLoad(N); |
| 3041 | } |
| 3042 | |
| 3043 | static SDValue bitcastf32Toi32(SDValue Op, SelectionDAG &DAG) { |
| 3044 | if (isFloatingPointZero(Op)) |
| 3045 | return DAG.getConstant(0, MVT::i32); |
| 3046 | |
| 3047 | if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Op)) |
| 3048 | return DAG.getLoad(MVT::i32, Op.getDebugLoc(), |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 3049 | Ld->getChain(), Ld->getBasePtr(), Ld->getPointerInfo(), |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3050 | Ld->isVolatile(), Ld->isNonTemporal(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3051 | Ld->isInvariant(), Ld->getAlignment()); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3052 | |
| 3053 | llvm_unreachable("Unknown VFP cmp argument!"); |
| 3054 | } |
| 3055 | |
| 3056 | static void expandf64Toi32(SDValue Op, SelectionDAG &DAG, |
| 3057 | SDValue &RetVal1, SDValue &RetVal2) { |
| 3058 | if (isFloatingPointZero(Op)) { |
| 3059 | RetVal1 = DAG.getConstant(0, MVT::i32); |
| 3060 | RetVal2 = DAG.getConstant(0, MVT::i32); |
| 3061 | return; |
| 3062 | } |
| 3063 | |
| 3064 | if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Op)) { |
| 3065 | SDValue Ptr = Ld->getBasePtr(); |
| 3066 | RetVal1 = DAG.getLoad(MVT::i32, Op.getDebugLoc(), |
| 3067 | Ld->getChain(), Ptr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 3068 | Ld->getPointerInfo(), |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3069 | Ld->isVolatile(), Ld->isNonTemporal(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3070 | Ld->isInvariant(), Ld->getAlignment()); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3071 | |
| 3072 | EVT PtrType = Ptr.getValueType(); |
| 3073 | unsigned NewAlign = MinAlign(Ld->getAlignment(), 4); |
| 3074 | SDValue NewPtr = DAG.getNode(ISD::ADD, Op.getDebugLoc(), |
| 3075 | PtrType, Ptr, DAG.getConstant(4, PtrType)); |
| 3076 | RetVal2 = DAG.getLoad(MVT::i32, Op.getDebugLoc(), |
| 3077 | Ld->getChain(), NewPtr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 3078 | Ld->getPointerInfo().getWithOffset(4), |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3079 | Ld->isVolatile(), Ld->isNonTemporal(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3080 | Ld->isInvariant(), NewAlign); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3081 | return; |
| 3082 | } |
| 3083 | |
| 3084 | llvm_unreachable("Unknown VFP cmp argument!"); |
| 3085 | } |
| 3086 | |
| 3087 | /// OptimizeVFPBrcond - With -enable-unsafe-fp-math, it's legal to optimize some |
| 3088 | /// f32 and even f64 comparisons to integer ones. |
| 3089 | SDValue |
| 3090 | ARMTargetLowering::OptimizeVFPBrcond(SDValue Op, SelectionDAG &DAG) const { |
| 3091 | SDValue Chain = Op.getOperand(0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3092 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get(); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3093 | SDValue LHS = Op.getOperand(2); |
| 3094 | SDValue RHS = Op.getOperand(3); |
| 3095 | SDValue Dest = Op.getOperand(4); |
| 3096 | DebugLoc dl = Op.getDebugLoc(); |
| 3097 | |
Evan Cheng | fc501a3 | 2012-03-01 23:27:13 +0000 | [diff] [blame] | 3098 | bool LHSSeenZero = false; |
| 3099 | bool LHSOk = canChangeToInt(LHS, LHSSeenZero, Subtarget); |
| 3100 | bool RHSSeenZero = false; |
| 3101 | bool RHSOk = canChangeToInt(RHS, RHSSeenZero, Subtarget); |
| 3102 | if (LHSOk && RHSOk && (LHSSeenZero || RHSSeenZero)) { |
Bob Wilson | 1b772f9 | 2011-03-08 01:17:16 +0000 | [diff] [blame] | 3103 | // If unsafe fp math optimization is enabled and there are no other uses of |
| 3104 | // 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] | 3105 | // to an integer comparison. |
| 3106 | if (CC == ISD::SETOEQ) |
| 3107 | CC = ISD::SETEQ; |
| 3108 | else if (CC == ISD::SETUNE) |
| 3109 | CC = ISD::SETNE; |
| 3110 | |
Evan Cheng | fc501a3 | 2012-03-01 23:27:13 +0000 | [diff] [blame] | 3111 | SDValue Mask = DAG.getConstant(0x7fffffff, MVT::i32); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3112 | SDValue ARMcc; |
| 3113 | if (LHS.getValueType() == MVT::f32) { |
Evan Cheng | fc501a3 | 2012-03-01 23:27:13 +0000 | [diff] [blame] | 3114 | LHS = DAG.getNode(ISD::AND, dl, MVT::i32, |
| 3115 | bitcastf32Toi32(LHS, DAG), Mask); |
| 3116 | RHS = DAG.getNode(ISD::AND, dl, MVT::i32, |
| 3117 | bitcastf32Toi32(RHS, DAG), Mask); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3118 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMcc, DAG, dl); |
| 3119 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| 3120 | return DAG.getNode(ARMISD::BRCOND, dl, MVT::Other, |
| 3121 | Chain, Dest, ARMcc, CCR, Cmp); |
| 3122 | } |
| 3123 | |
| 3124 | SDValue LHS1, LHS2; |
| 3125 | SDValue RHS1, RHS2; |
| 3126 | expandf64Toi32(LHS, DAG, LHS1, LHS2); |
| 3127 | expandf64Toi32(RHS, DAG, RHS1, RHS2); |
Evan Cheng | fc501a3 | 2012-03-01 23:27:13 +0000 | [diff] [blame] | 3128 | LHS2 = DAG.getNode(ISD::AND, dl, MVT::i32, LHS2, Mask); |
| 3129 | RHS2 = DAG.getNode(ISD::AND, dl, MVT::i32, RHS2, Mask); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3130 | ARMCC::CondCodes CondCode = IntCCToARMCC(CC); |
| 3131 | ARMcc = DAG.getConstant(CondCode, MVT::i32); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 3132 | SDVTList VTList = DAG.getVTList(MVT::Other, MVT::Glue); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3133 | SDValue Ops[] = { Chain, ARMcc, LHS1, LHS2, RHS1, RHS2, Dest }; |
| 3134 | return DAG.getNode(ARMISD::BCC_i64, dl, VTList, Ops, 7); |
| 3135 | } |
| 3136 | |
| 3137 | return SDValue(); |
| 3138 | } |
| 3139 | |
| 3140 | SDValue ARMTargetLowering::LowerBR_CC(SDValue Op, SelectionDAG &DAG) const { |
| 3141 | SDValue Chain = Op.getOperand(0); |
| 3142 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get(); |
| 3143 | SDValue LHS = Op.getOperand(2); |
| 3144 | SDValue RHS = Op.getOperand(3); |
| 3145 | SDValue Dest = Op.getOperand(4); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 3146 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3147 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3148 | if (LHS.getValueType() == MVT::i32) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3149 | SDValue ARMcc; |
| 3150 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMcc, DAG, dl); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3151 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3152 | return DAG.getNode(ARMISD::BRCOND, dl, MVT::Other, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3153 | Chain, Dest, ARMcc, CCR, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3154 | } |
| 3155 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3156 | assert(LHS.getValueType() == MVT::f32 || LHS.getValueType() == MVT::f64); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3157 | |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 3158 | if (getTargetMachine().Options.UnsafeFPMath && |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3159 | (CC == ISD::SETEQ || CC == ISD::SETOEQ || |
| 3160 | CC == ISD::SETNE || CC == ISD::SETUNE)) { |
| 3161 | SDValue Result = OptimizeVFPBrcond(Op, DAG); |
| 3162 | if (Result.getNode()) |
| 3163 | return Result; |
| 3164 | } |
| 3165 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3166 | ARMCC::CondCodes CondCode, CondCode2; |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 3167 | FPCCToARMCC(CC, CondCode, CondCode2); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3168 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3169 | SDValue ARMcc = DAG.getConstant(CondCode, MVT::i32); |
| 3170 | SDValue Cmp = getVFPCmp(LHS, RHS, DAG, dl); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3171 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 3172 | SDVTList VTList = DAG.getVTList(MVT::Other, MVT::Glue); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3173 | SDValue Ops[] = { Chain, Dest, ARMcc, CCR, Cmp }; |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 3174 | SDValue Res = DAG.getNode(ARMISD::BRCOND, dl, VTList, Ops, 5); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3175 | if (CondCode2 != ARMCC::AL) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3176 | ARMcc = DAG.getConstant(CondCode2, MVT::i32); |
| 3177 | SDValue Ops[] = { Res, Dest, ARMcc, CCR, Res.getValue(1) }; |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 3178 | Res = DAG.getNode(ARMISD::BRCOND, dl, VTList, Ops, 5); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3179 | } |
| 3180 | return Res; |
| 3181 | } |
| 3182 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 3183 | SDValue ARMTargetLowering::LowerBR_JT(SDValue Op, SelectionDAG &DAG) const { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3184 | SDValue Chain = Op.getOperand(0); |
| 3185 | SDValue Table = Op.getOperand(1); |
| 3186 | SDValue Index = Op.getOperand(2); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 3187 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3188 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3189 | EVT PTy = getPointerTy(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3190 | JumpTableSDNode *JT = cast<JumpTableSDNode>(Table); |
| 3191 | ARMFunctionInfo *AFI = DAG.getMachineFunction().getInfo<ARMFunctionInfo>(); |
Bob Wilson | 3eadf00 | 2009-07-14 18:44:34 +0000 | [diff] [blame] | 3192 | SDValue UId = DAG.getConstant(AFI->createJumpTableUId(), PTy); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3193 | SDValue JTI = DAG.getTargetJumpTable(JT->getIndex(), PTy); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3194 | Table = DAG.getNode(ARMISD::WrapperJT, dl, MVT::i32, JTI, UId); |
Evan Cheng | e7c329b | 2009-07-28 20:53:24 +0000 | [diff] [blame] | 3195 | Index = DAG.getNode(ISD::MUL, dl, PTy, Index, DAG.getConstant(4, PTy)); |
| 3196 | SDValue Addr = DAG.getNode(ISD::ADD, dl, PTy, Index, Table); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3197 | if (Subtarget->isThumb2()) { |
| 3198 | // Thumb2 uses a two-level jump. That is, it jumps into the jump table |
| 3199 | // which does another jump to the destination. This also makes it easier |
| 3200 | // to translate it to TBB / TBH later. |
| 3201 | // FIXME: This might not work if the function is extremely large. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3202 | return DAG.getNode(ARMISD::BR2_JT, dl, MVT::Other, Chain, |
Evan Cheng | 5657c01 | 2009-07-29 02:18:14 +0000 | [diff] [blame] | 3203 | Addr, Op.getOperand(2), JTI, UId); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3204 | } |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3205 | if (getTargetMachine().getRelocationModel() == Reloc::PIC_) { |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 3206 | Addr = DAG.getLoad((EVT)MVT::i32, dl, Chain, Addr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 3207 | MachinePointerInfo::getJumpTable(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3208 | false, false, false, 0); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3209 | Chain = Addr.getValue(1); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 3210 | Addr = DAG.getNode(ISD::ADD, dl, PTy, Addr, Table); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3211 | 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] | 3212 | } else { |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 3213 | Addr = DAG.getLoad(PTy, dl, Chain, Addr, |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3214 | MachinePointerInfo::getJumpTable(), |
| 3215 | false, false, false, 0); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3216 | Chain = Addr.getValue(1); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3217 | 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] | 3218 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3219 | } |
| 3220 | |
Eli Friedman | 14e809c | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3221 | static SDValue LowerVectorFP_TO_INT(SDValue Op, SelectionDAG &DAG) { |
James Molloy | 873fd5f | 2012-02-20 09:24:05 +0000 | [diff] [blame] | 3222 | EVT VT = Op.getValueType(); |
| 3223 | DebugLoc dl = Op.getDebugLoc(); |
Eli Friedman | 14e809c | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3224 | |
James Molloy | 873fd5f | 2012-02-20 09:24:05 +0000 | [diff] [blame] | 3225 | if (Op.getValueType().getVectorElementType() == MVT::i32) { |
| 3226 | if (Op.getOperand(0).getValueType().getVectorElementType() == MVT::f32) |
| 3227 | return Op; |
| 3228 | return DAG.UnrollVectorOp(Op.getNode()); |
| 3229 | } |
| 3230 | |
| 3231 | assert(Op.getOperand(0).getValueType() == MVT::v4f32 && |
| 3232 | "Invalid type for custom lowering!"); |
| 3233 | if (VT != MVT::v4i16) |
| 3234 | return DAG.UnrollVectorOp(Op.getNode()); |
| 3235 | |
| 3236 | Op = DAG.getNode(Op.getOpcode(), dl, MVT::v4i32, Op.getOperand(0)); |
| 3237 | return DAG.getNode(ISD::TRUNCATE, dl, VT, Op); |
Eli Friedman | 14e809c | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3238 | } |
| 3239 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3240 | static SDValue LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG) { |
Eli Friedman | 14e809c | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3241 | EVT VT = Op.getValueType(); |
| 3242 | if (VT.isVector()) |
| 3243 | return LowerVectorFP_TO_INT(Op, DAG); |
| 3244 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3245 | DebugLoc dl = Op.getDebugLoc(); |
| 3246 | unsigned Opc; |
| 3247 | |
| 3248 | switch (Op.getOpcode()) { |
Craig Topper | bc21981 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 3249 | default: llvm_unreachable("Invalid opcode!"); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3250 | case ISD::FP_TO_SINT: |
| 3251 | Opc = ARMISD::FTOSI; |
| 3252 | break; |
| 3253 | case ISD::FP_TO_UINT: |
| 3254 | Opc = ARMISD::FTOUI; |
| 3255 | break; |
| 3256 | } |
| 3257 | Op = DAG.getNode(Opc, dl, MVT::f32, Op.getOperand(0)); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3258 | return DAG.getNode(ISD::BITCAST, dl, MVT::i32, Op); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3259 | } |
| 3260 | |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 3261 | static SDValue LowerVectorINT_TO_FP(SDValue Op, SelectionDAG &DAG) { |
| 3262 | EVT VT = Op.getValueType(); |
| 3263 | DebugLoc dl = Op.getDebugLoc(); |
| 3264 | |
Eli Friedman | 14e809c | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3265 | if (Op.getOperand(0).getValueType().getVectorElementType() == MVT::i32) { |
| 3266 | if (VT.getVectorElementType() == MVT::f32) |
| 3267 | return Op; |
| 3268 | return DAG.UnrollVectorOp(Op.getNode()); |
| 3269 | } |
| 3270 | |
Duncan Sands | 1f6a329 | 2011-08-12 14:54:45 +0000 | [diff] [blame] | 3271 | assert(Op.getOperand(0).getValueType() == MVT::v4i16 && |
| 3272 | "Invalid type for custom lowering!"); |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 3273 | if (VT != MVT::v4f32) |
| 3274 | return DAG.UnrollVectorOp(Op.getNode()); |
| 3275 | |
| 3276 | unsigned CastOpc; |
| 3277 | unsigned Opc; |
| 3278 | switch (Op.getOpcode()) { |
Craig Topper | bc21981 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 3279 | default: llvm_unreachable("Invalid opcode!"); |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 3280 | case ISD::SINT_TO_FP: |
| 3281 | CastOpc = ISD::SIGN_EXTEND; |
| 3282 | Opc = ISD::SINT_TO_FP; |
| 3283 | break; |
| 3284 | case ISD::UINT_TO_FP: |
| 3285 | CastOpc = ISD::ZERO_EXTEND; |
| 3286 | Opc = ISD::UINT_TO_FP; |
| 3287 | break; |
| 3288 | } |
| 3289 | |
| 3290 | Op = DAG.getNode(CastOpc, dl, MVT::v4i32, Op.getOperand(0)); |
| 3291 | return DAG.getNode(Opc, dl, VT, Op); |
| 3292 | } |
| 3293 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3294 | static SDValue LowerINT_TO_FP(SDValue Op, SelectionDAG &DAG) { |
| 3295 | EVT VT = Op.getValueType(); |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 3296 | if (VT.isVector()) |
| 3297 | return LowerVectorINT_TO_FP(Op, DAG); |
| 3298 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3299 | DebugLoc dl = Op.getDebugLoc(); |
| 3300 | unsigned Opc; |
| 3301 | |
| 3302 | switch (Op.getOpcode()) { |
Craig Topper | bc21981 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 3303 | default: llvm_unreachable("Invalid opcode!"); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3304 | case ISD::SINT_TO_FP: |
| 3305 | Opc = ARMISD::SITOF; |
| 3306 | break; |
| 3307 | case ISD::UINT_TO_FP: |
| 3308 | Opc = ARMISD::UITOF; |
| 3309 | break; |
| 3310 | } |
| 3311 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3312 | Op = DAG.getNode(ISD::BITCAST, dl, MVT::f32, Op.getOperand(0)); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3313 | return DAG.getNode(Opc, dl, VT, Op); |
| 3314 | } |
| 3315 | |
Evan Cheng | 515fe3a | 2010-07-08 02:08:50 +0000 | [diff] [blame] | 3316 | SDValue ARMTargetLowering::LowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3317 | // Implement fcopysign with a fabs and a conditional fneg. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3318 | SDValue Tmp0 = Op.getOperand(0); |
| 3319 | SDValue Tmp1 = Op.getOperand(1); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 3320 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3321 | EVT VT = Op.getValueType(); |
| 3322 | EVT SrcVT = Tmp1.getValueType(); |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3323 | bool InGPR = Tmp0.getOpcode() == ISD::BITCAST || |
| 3324 | Tmp0.getOpcode() == ARMISD::VMOVDRR; |
| 3325 | bool UseNEON = !InGPR && Subtarget->hasNEON(); |
| 3326 | |
| 3327 | if (UseNEON) { |
| 3328 | // Use VBSL to copy the sign bit. |
| 3329 | unsigned EncodedVal = ARM_AM::createNEONModImm(0x6, 0x80); |
| 3330 | SDValue Mask = DAG.getNode(ARMISD::VMOVIMM, dl, MVT::v2i32, |
| 3331 | DAG.getTargetConstant(EncodedVal, MVT::i32)); |
| 3332 | EVT OpVT = (VT == MVT::f32) ? MVT::v2i32 : MVT::v1i64; |
| 3333 | if (VT == MVT::f64) |
| 3334 | Mask = DAG.getNode(ARMISD::VSHL, dl, OpVT, |
| 3335 | DAG.getNode(ISD::BITCAST, dl, OpVT, Mask), |
| 3336 | DAG.getConstant(32, MVT::i32)); |
| 3337 | else /*if (VT == MVT::f32)*/ |
| 3338 | Tmp0 = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, MVT::v2f32, Tmp0); |
| 3339 | if (SrcVT == MVT::f32) { |
| 3340 | Tmp1 = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, MVT::v2f32, Tmp1); |
| 3341 | if (VT == MVT::f64) |
| 3342 | Tmp1 = DAG.getNode(ARMISD::VSHL, dl, OpVT, |
| 3343 | DAG.getNode(ISD::BITCAST, dl, OpVT, Tmp1), |
| 3344 | DAG.getConstant(32, MVT::i32)); |
Evan Cheng | 9eec66e | 2011-04-15 01:31:00 +0000 | [diff] [blame] | 3345 | } else if (VT == MVT::f32) |
| 3346 | Tmp1 = DAG.getNode(ARMISD::VSHRu, dl, MVT::v1i64, |
| 3347 | DAG.getNode(ISD::BITCAST, dl, MVT::v1i64, Tmp1), |
| 3348 | DAG.getConstant(32, MVT::i32)); |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3349 | Tmp0 = DAG.getNode(ISD::BITCAST, dl, OpVT, Tmp0); |
| 3350 | Tmp1 = DAG.getNode(ISD::BITCAST, dl, OpVT, Tmp1); |
| 3351 | |
| 3352 | SDValue AllOnes = DAG.getTargetConstant(ARM_AM::createNEONModImm(0xe, 0xff), |
| 3353 | MVT::i32); |
| 3354 | AllOnes = DAG.getNode(ARMISD::VMOVIMM, dl, MVT::v8i8, AllOnes); |
| 3355 | SDValue MaskNot = DAG.getNode(ISD::XOR, dl, OpVT, Mask, |
| 3356 | DAG.getNode(ISD::BITCAST, dl, OpVT, AllOnes)); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 3357 | |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3358 | SDValue Res = DAG.getNode(ISD::OR, dl, OpVT, |
| 3359 | DAG.getNode(ISD::AND, dl, OpVT, Tmp1, Mask), |
| 3360 | DAG.getNode(ISD::AND, dl, OpVT, Tmp0, MaskNot)); |
Evan Cheng | c24ab5c | 2011-02-28 18:45:27 +0000 | [diff] [blame] | 3361 | if (VT == MVT::f32) { |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3362 | Res = DAG.getNode(ISD::BITCAST, dl, MVT::v2f32, Res); |
| 3363 | Res = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f32, Res, |
| 3364 | DAG.getConstant(0, MVT::i32)); |
| 3365 | } else { |
| 3366 | Res = DAG.getNode(ISD::BITCAST, dl, MVT::f64, Res); |
| 3367 | } |
| 3368 | |
| 3369 | return Res; |
| 3370 | } |
Evan Cheng | c143dd4 | 2011-02-11 02:28:55 +0000 | [diff] [blame] | 3371 | |
| 3372 | // Bitcast operand 1 to i32. |
| 3373 | if (SrcVT == MVT::f64) |
| 3374 | Tmp1 = DAG.getNode(ARMISD::VMOVRRD, dl, DAG.getVTList(MVT::i32, MVT::i32), |
| 3375 | &Tmp1, 1).getValue(1); |
| 3376 | Tmp1 = DAG.getNode(ISD::BITCAST, dl, MVT::i32, Tmp1); |
| 3377 | |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3378 | // Or in the signbit with integer operations. |
| 3379 | SDValue Mask1 = DAG.getConstant(0x80000000, MVT::i32); |
| 3380 | SDValue Mask2 = DAG.getConstant(0x7fffffff, MVT::i32); |
| 3381 | Tmp1 = DAG.getNode(ISD::AND, dl, MVT::i32, Tmp1, Mask1); |
| 3382 | if (VT == MVT::f32) { |
| 3383 | Tmp0 = DAG.getNode(ISD::AND, dl, MVT::i32, |
| 3384 | DAG.getNode(ISD::BITCAST, dl, MVT::i32, Tmp0), Mask2); |
| 3385 | return DAG.getNode(ISD::BITCAST, dl, MVT::f32, |
| 3386 | DAG.getNode(ISD::OR, dl, MVT::i32, Tmp0, Tmp1)); |
Evan Cheng | c143dd4 | 2011-02-11 02:28:55 +0000 | [diff] [blame] | 3387 | } |
| 3388 | |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3389 | // f64: Or the high part with signbit and then combine two parts. |
| 3390 | Tmp0 = DAG.getNode(ARMISD::VMOVRRD, dl, DAG.getVTList(MVT::i32, MVT::i32), |
| 3391 | &Tmp0, 1); |
| 3392 | SDValue Lo = Tmp0.getValue(0); |
| 3393 | SDValue Hi = DAG.getNode(ISD::AND, dl, MVT::i32, Tmp0.getValue(1), Mask2); |
| 3394 | Hi = DAG.getNode(ISD::OR, dl, MVT::i32, Hi, Tmp1); |
| 3395 | return DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3396 | } |
| 3397 | |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3398 | SDValue ARMTargetLowering::LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const{ |
| 3399 | MachineFunction &MF = DAG.getMachineFunction(); |
| 3400 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 3401 | MFI->setReturnAddressIsTaken(true); |
| 3402 | |
| 3403 | EVT VT = Op.getValueType(); |
| 3404 | DebugLoc dl = Op.getDebugLoc(); |
| 3405 | unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
| 3406 | if (Depth) { |
| 3407 | SDValue FrameAddr = LowerFRAMEADDR(Op, DAG); |
| 3408 | SDValue Offset = DAG.getConstant(4, MVT::i32); |
| 3409 | return DAG.getLoad(VT, dl, DAG.getEntryNode(), |
| 3410 | DAG.getNode(ISD::ADD, dl, VT, FrameAddr, Offset), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3411 | MachinePointerInfo(), false, false, false, 0); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3412 | } |
| 3413 | |
| 3414 | // 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] | 3415 | unsigned Reg = MF.addLiveIn(ARM::LR, getRegClassFor(MVT::i32)); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3416 | return DAG.getCopyFromReg(DAG.getEntryNode(), dl, Reg, VT); |
| 3417 | } |
| 3418 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 3419 | SDValue ARMTargetLowering::LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const { |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3420 | MachineFrameInfo *MFI = DAG.getMachineFunction().getFrameInfo(); |
| 3421 | MFI->setFrameAddressIsTaken(true); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3422 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3423 | EVT VT = Op.getValueType(); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3424 | DebugLoc dl = Op.getDebugLoc(); // FIXME probably not meaningful |
| 3425 | unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
Evan Cheng | cd82861 | 2009-06-18 23:14:30 +0000 | [diff] [blame] | 3426 | unsigned FrameReg = (Subtarget->isThumb() || Subtarget->isTargetDarwin()) |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3427 | ? ARM::R7 : ARM::R11; |
| 3428 | SDValue FrameAddr = DAG.getCopyFromReg(DAG.getEntryNode(), dl, FrameReg, VT); |
| 3429 | while (Depth--) |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 3430 | FrameAddr = DAG.getLoad(VT, dl, DAG.getEntryNode(), FrameAddr, |
| 3431 | MachinePointerInfo(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3432 | false, false, false, 0); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3433 | return FrameAddr; |
| 3434 | } |
| 3435 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3436 | /// ExpandBITCAST - If the target supports VFP, this function is called to |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3437 | /// expand a bit convert where either the source or destination type is i64 to |
| 3438 | /// use a VMOVDRR or VMOVRRD node. This should not be done when the non-i64 |
| 3439 | /// operand type is illegal (e.g., v2f32 for a target that doesn't support |
| 3440 | /// vectors), since the legalizer won't know what to do with that. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3441 | static SDValue ExpandBITCAST(SDNode *N, SelectionDAG &DAG) { |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3442 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 3443 | DebugLoc dl = N->getDebugLoc(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3444 | SDValue Op = N->getOperand(0); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 3445 | |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3446 | // This function is only supposed to be called for i64 types, either as the |
| 3447 | // source or destination of the bit convert. |
| 3448 | EVT SrcVT = Op.getValueType(); |
| 3449 | EVT DstVT = N->getValueType(0); |
| 3450 | assert((SrcVT == MVT::i64 || DstVT == MVT::i64) && |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3451 | "ExpandBITCAST called for non-i64 type"); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 3452 | |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3453 | // Turn i64->f64 into VMOVDRR. |
| 3454 | if (SrcVT == MVT::i64 && TLI.isTypeLegal(DstVT)) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3455 | SDValue Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Op, |
| 3456 | DAG.getConstant(0, MVT::i32)); |
| 3457 | SDValue Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Op, |
| 3458 | DAG.getConstant(1, MVT::i32)); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3459 | return DAG.getNode(ISD::BITCAST, dl, DstVT, |
Bob Wilson | 1114f56 | 2010-06-11 22:45:25 +0000 | [diff] [blame] | 3460 | DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi)); |
Evan Cheng | c7c7729 | 2008-11-04 19:57:48 +0000 | [diff] [blame] | 3461 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3462 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 3463 | // Turn f64->i64 into VMOVRRD. |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3464 | if (DstVT == MVT::i64 && TLI.isTypeLegal(SrcVT)) { |
| 3465 | SDValue Cvt = DAG.getNode(ARMISD::VMOVRRD, dl, |
| 3466 | DAG.getVTList(MVT::i32, MVT::i32), &Op, 1); |
| 3467 | // Merge the pieces into a single i64 value. |
| 3468 | return DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Cvt, Cvt.getValue(1)); |
| 3469 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3470 | |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3471 | return SDValue(); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3472 | } |
| 3473 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3474 | /// getZeroVector - Returns a vector of specified type with all zero elements. |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3475 | /// Zero vectors are used to represent vector negation and in those cases |
| 3476 | /// will be implemented with the NEON VNEG instruction. However, VNEG does |
| 3477 | /// not support i64 elements, so sometimes the zero vectors will need to be |
| 3478 | /// explicitly constructed. Regardless, use a canonical VMOV to create the |
| 3479 | /// zero vector. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3480 | static SDValue getZeroVector(EVT VT, SelectionDAG &DAG, DebugLoc dl) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3481 | assert(VT.isVector() && "Expected a vector type"); |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3482 | // The canonical modified immediate encoding of a zero vector is....0! |
| 3483 | SDValue EncodedVal = DAG.getTargetConstant(0, MVT::i32); |
| 3484 | EVT VmovVT = VT.is128BitVector() ? MVT::v4i32 : MVT::v2i32; |
| 3485 | SDValue Vmov = DAG.getNode(ARMISD::VMOVIMM, dl, VmovVT, EncodedVal); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3486 | return DAG.getNode(ISD::BITCAST, dl, VT, Vmov); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3487 | } |
| 3488 | |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3489 | /// LowerShiftRightParts - Lower SRA_PARTS, which returns two |
| 3490 | /// 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] | 3491 | SDValue ARMTargetLowering::LowerShiftRightParts(SDValue Op, |
| 3492 | SelectionDAG &DAG) const { |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3493 | assert(Op.getNumOperands() == 3 && "Not a double-shift!"); |
| 3494 | EVT VT = Op.getValueType(); |
| 3495 | unsigned VTBits = VT.getSizeInBits(); |
| 3496 | DebugLoc dl = Op.getDebugLoc(); |
| 3497 | SDValue ShOpLo = Op.getOperand(0); |
| 3498 | SDValue ShOpHi = Op.getOperand(1); |
| 3499 | SDValue ShAmt = Op.getOperand(2); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3500 | SDValue ARMcc; |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 3501 | unsigned Opc = (Op.getOpcode() == ISD::SRA_PARTS) ? ISD::SRA : ISD::SRL; |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3502 | |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 3503 | assert(Op.getOpcode() == ISD::SRA_PARTS || Op.getOpcode() == ISD::SRL_PARTS); |
| 3504 | |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3505 | SDValue RevShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, |
| 3506 | DAG.getConstant(VTBits, MVT::i32), ShAmt); |
| 3507 | SDValue Tmp1 = DAG.getNode(ISD::SRL, dl, VT, ShOpLo, ShAmt); |
| 3508 | SDValue ExtraShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, ShAmt, |
| 3509 | DAG.getConstant(VTBits, MVT::i32)); |
| 3510 | SDValue Tmp2 = DAG.getNode(ISD::SHL, dl, VT, ShOpHi, RevShAmt); |
| 3511 | SDValue FalseVal = DAG.getNode(ISD::OR, dl, VT, Tmp1, Tmp2); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 3512 | SDValue TrueVal = DAG.getNode(Opc, dl, VT, ShOpHi, ExtraShAmt); |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3513 | |
| 3514 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| 3515 | SDValue Cmp = getARMCmp(ExtraShAmt, DAG.getConstant(0, MVT::i32), ISD::SETGE, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3516 | ARMcc, DAG, dl); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 3517 | SDValue Hi = DAG.getNode(Opc, dl, VT, ShOpHi, ShAmt); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3518 | SDValue Lo = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, ARMcc, |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3519 | CCR, Cmp); |
| 3520 | |
| 3521 | SDValue Ops[2] = { Lo, Hi }; |
| 3522 | return DAG.getMergeValues(Ops, 2, dl); |
| 3523 | } |
| 3524 | |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3525 | /// LowerShiftLeftParts - Lower SHL_PARTS, which returns two |
| 3526 | /// 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] | 3527 | SDValue ARMTargetLowering::LowerShiftLeftParts(SDValue Op, |
| 3528 | SelectionDAG &DAG) const { |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3529 | assert(Op.getNumOperands() == 3 && "Not a double-shift!"); |
| 3530 | EVT VT = Op.getValueType(); |
| 3531 | unsigned VTBits = VT.getSizeInBits(); |
| 3532 | DebugLoc dl = Op.getDebugLoc(); |
| 3533 | SDValue ShOpLo = Op.getOperand(0); |
| 3534 | SDValue ShOpHi = Op.getOperand(1); |
| 3535 | SDValue ShAmt = Op.getOperand(2); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3536 | SDValue ARMcc; |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3537 | |
| 3538 | assert(Op.getOpcode() == ISD::SHL_PARTS); |
| 3539 | SDValue RevShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, |
| 3540 | DAG.getConstant(VTBits, MVT::i32), ShAmt); |
| 3541 | SDValue Tmp1 = DAG.getNode(ISD::SRL, dl, VT, ShOpLo, RevShAmt); |
| 3542 | SDValue ExtraShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, ShAmt, |
| 3543 | DAG.getConstant(VTBits, MVT::i32)); |
| 3544 | SDValue Tmp2 = DAG.getNode(ISD::SHL, dl, VT, ShOpHi, ShAmt); |
| 3545 | SDValue Tmp3 = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ExtraShAmt); |
| 3546 | |
| 3547 | SDValue FalseVal = DAG.getNode(ISD::OR, dl, VT, Tmp1, Tmp2); |
| 3548 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| 3549 | SDValue Cmp = getARMCmp(ExtraShAmt, DAG.getConstant(0, MVT::i32), ISD::SETGE, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3550 | ARMcc, DAG, dl); |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3551 | SDValue Lo = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ShAmt); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3552 | SDValue Hi = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, Tmp3, ARMcc, |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3553 | CCR, Cmp); |
| 3554 | |
| 3555 | SDValue Ops[2] = { Lo, Hi }; |
| 3556 | return DAG.getMergeValues(Ops, 2, dl); |
| 3557 | } |
| 3558 | |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 3559 | SDValue ARMTargetLowering::LowerFLT_ROUNDS_(SDValue Op, |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 3560 | SelectionDAG &DAG) const { |
| 3561 | // The rounding mode is in bits 23:22 of the FPSCR. |
| 3562 | // The ARM rounding mode value to FLT_ROUNDS mapping is 0->1, 1->2, 2->3, 3->0 |
| 3563 | // The formula we use to implement this is (((FPSCR + 1 << 22) >> 22) & 3) |
| 3564 | // so that the shift + and get folded into a bitfield extract. |
| 3565 | DebugLoc dl = Op.getDebugLoc(); |
| 3566 | SDValue FPSCR = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::i32, |
| 3567 | DAG.getConstant(Intrinsic::arm_get_fpscr, |
| 3568 | MVT::i32)); |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 3569 | SDValue FltRounds = DAG.getNode(ISD::ADD, dl, MVT::i32, FPSCR, |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 3570 | DAG.getConstant(1U << 22, MVT::i32)); |
| 3571 | SDValue RMODE = DAG.getNode(ISD::SRL, dl, MVT::i32, FltRounds, |
| 3572 | DAG.getConstant(22, MVT::i32)); |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 3573 | return DAG.getNode(ISD::AND, dl, MVT::i32, RMODE, |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 3574 | DAG.getConstant(3, MVT::i32)); |
| 3575 | } |
| 3576 | |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 3577 | static SDValue LowerCTTZ(SDNode *N, SelectionDAG &DAG, |
| 3578 | const ARMSubtarget *ST) { |
| 3579 | EVT VT = N->getValueType(0); |
| 3580 | DebugLoc dl = N->getDebugLoc(); |
| 3581 | |
| 3582 | if (!ST->hasV6T2Ops()) |
| 3583 | return SDValue(); |
| 3584 | |
| 3585 | SDValue rbit = DAG.getNode(ARMISD::RBIT, dl, VT, N->getOperand(0)); |
| 3586 | return DAG.getNode(ISD::CTLZ, dl, VT, rbit); |
| 3587 | } |
| 3588 | |
Evan Cheng | c8e7045 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 3589 | /// getCTPOP16BitCounts - Returns a v8i8/v16i8 vector containing the bit-count |
| 3590 | /// for each 16-bit element from operand, repeated. The basic idea is to |
| 3591 | /// leverage vcnt to get the 8-bit counts, gather and add the results. |
| 3592 | /// |
| 3593 | /// Trace for v4i16: |
| 3594 | /// input = [v0 v1 v2 v3 ] (vi 16-bit element) |
| 3595 | /// cast: N0 = [w0 w1 w2 w3 w4 w5 w6 w7] (v0 = [w0 w1], wi 8-bit element) |
| 3596 | /// vcnt: N1 = [b0 b1 b2 b3 b4 b5 b6 b7] (bi = bit-count of 8-bit element wi) |
| 3597 | /// vrev: N2 = [b1 b0 b3 b2 b5 b4 b7 b6] |
| 3598 | /// [b0 b1 b2 b3 b4 b5 b6 b7] |
| 3599 | /// +[b1 b0 b3 b2 b5 b4 b7 b6] |
| 3600 | /// N3=N1+N2 = [k0 k0 k1 k1 k2 k2 k3 k3] (k0 = b0+b1 = bit-count of 16-bit v0, |
| 3601 | /// vuzp: = [k0 k1 k2 k3 k0 k1 k2 k3] each ki is 8-bits) |
| 3602 | static SDValue getCTPOP16BitCounts(SDNode *N, SelectionDAG &DAG) { |
| 3603 | EVT VT = N->getValueType(0); |
| 3604 | DebugLoc DL = N->getDebugLoc(); |
| 3605 | |
| 3606 | EVT VT8Bit = VT.is64BitVector() ? MVT::v8i8 : MVT::v16i8; |
| 3607 | SDValue N0 = DAG.getNode(ISD::BITCAST, DL, VT8Bit, N->getOperand(0)); |
| 3608 | SDValue N1 = DAG.getNode(ISD::CTPOP, DL, VT8Bit, N0); |
| 3609 | SDValue N2 = DAG.getNode(ARMISD::VREV16, DL, VT8Bit, N1); |
| 3610 | SDValue N3 = DAG.getNode(ISD::ADD, DL, VT8Bit, N1, N2); |
| 3611 | return DAG.getNode(ARMISD::VUZP, DL, VT8Bit, N3, N3); |
| 3612 | } |
| 3613 | |
| 3614 | /// lowerCTPOP16BitElements - Returns a v4i16/v8i16 vector containing the |
| 3615 | /// bit-count for each 16-bit element from the operand. We need slightly |
| 3616 | /// different sequencing for v4i16 and v8i16 to stay within NEON's available |
| 3617 | /// 64/128-bit registers. |
| 3618 | /// |
| 3619 | /// Trace for v4i16: |
| 3620 | /// input = [v0 v1 v2 v3 ] (vi 16-bit element) |
| 3621 | /// v8i8: BitCounts = [k0 k1 k2 k3 k0 k1 k2 k3 ] (ki is the bit-count of vi) |
| 3622 | /// v8i16:Extended = [k0 k1 k2 k3 k0 k1 k2 k3 ] |
| 3623 | /// v4i16:Extracted = [k0 k1 k2 k3 ] |
| 3624 | static SDValue lowerCTPOP16BitElements(SDNode *N, SelectionDAG &DAG) { |
| 3625 | EVT VT = N->getValueType(0); |
| 3626 | DebugLoc DL = N->getDebugLoc(); |
| 3627 | |
| 3628 | SDValue BitCounts = getCTPOP16BitCounts(N, DAG); |
| 3629 | if (VT.is64BitVector()) { |
| 3630 | SDValue Extended = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::v8i16, BitCounts); |
| 3631 | return DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, MVT::v4i16, Extended, |
| 3632 | DAG.getIntPtrConstant(0)); |
| 3633 | } else { |
| 3634 | SDValue Extracted = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, MVT::v8i8, |
| 3635 | BitCounts, DAG.getIntPtrConstant(0)); |
| 3636 | return DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::v8i16, Extracted); |
| 3637 | } |
| 3638 | } |
| 3639 | |
| 3640 | /// lowerCTPOP32BitElements - Returns a v2i32/v4i32 vector containing the |
| 3641 | /// bit-count for each 32-bit element from the operand. The idea here is |
| 3642 | /// to split the vector into 16-bit elements, leverage the 16-bit count |
| 3643 | /// routine, and then combine the results. |
| 3644 | /// |
| 3645 | /// Trace for v2i32 (v4i32 similar with Extracted/Extended exchanged): |
| 3646 | /// input = [v0 v1 ] (vi: 32-bit elements) |
| 3647 | /// Bitcast = [w0 w1 w2 w3 ] (wi: 16-bit elements, v0 = [w0 w1]) |
| 3648 | /// Counts16 = [k0 k1 k2 k3 ] (ki: 16-bit elements, bit-count of wi) |
| 3649 | /// vrev: N0 = [k1 k0 k3 k2 ] |
| 3650 | /// [k0 k1 k2 k3 ] |
| 3651 | /// N1 =+[k1 k0 k3 k2 ] |
| 3652 | /// [k0 k2 k1 k3 ] |
| 3653 | /// N2 =+[k1 k3 k0 k2 ] |
| 3654 | /// [k0 k2 k1 k3 ] |
| 3655 | /// Extended =+[k1 k3 k0 k2 ] |
| 3656 | /// [k0 k2 ] |
| 3657 | /// Extracted=+[k1 k3 ] |
| 3658 | /// |
| 3659 | static SDValue lowerCTPOP32BitElements(SDNode *N, SelectionDAG &DAG) { |
| 3660 | EVT VT = N->getValueType(0); |
| 3661 | DebugLoc DL = N->getDebugLoc(); |
| 3662 | |
| 3663 | EVT VT16Bit = VT.is64BitVector() ? MVT::v4i16 : MVT::v8i16; |
| 3664 | |
| 3665 | SDValue Bitcast = DAG.getNode(ISD::BITCAST, DL, VT16Bit, N->getOperand(0)); |
| 3666 | SDValue Counts16 = lowerCTPOP16BitElements(Bitcast.getNode(), DAG); |
| 3667 | SDValue N0 = DAG.getNode(ARMISD::VREV32, DL, VT16Bit, Counts16); |
| 3668 | SDValue N1 = DAG.getNode(ISD::ADD, DL, VT16Bit, Counts16, N0); |
| 3669 | SDValue N2 = DAG.getNode(ARMISD::VUZP, DL, VT16Bit, N1, N1); |
| 3670 | |
| 3671 | if (VT.is64BitVector()) { |
| 3672 | SDValue Extended = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::v4i32, N2); |
| 3673 | return DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, MVT::v2i32, Extended, |
| 3674 | DAG.getIntPtrConstant(0)); |
| 3675 | } else { |
| 3676 | SDValue Extracted = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, MVT::v4i16, N2, |
| 3677 | DAG.getIntPtrConstant(0)); |
| 3678 | return DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::v4i32, Extracted); |
| 3679 | } |
| 3680 | } |
| 3681 | |
| 3682 | static SDValue LowerCTPOP(SDNode *N, SelectionDAG &DAG, |
| 3683 | const ARMSubtarget *ST) { |
| 3684 | EVT VT = N->getValueType(0); |
| 3685 | |
| 3686 | assert(ST->hasNEON() && "Custom ctpop lowering requires NEON."); |
Matt Beaumont-Gay | 105ab4f | 2012-12-04 23:54:02 +0000 | [diff] [blame] | 3687 | assert((VT == MVT::v2i32 || VT == MVT::v4i32 || |
| 3688 | VT == MVT::v4i16 || VT == MVT::v8i16) && |
Evan Cheng | c8e7045 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 3689 | "Unexpected type for custom ctpop lowering"); |
| 3690 | |
| 3691 | if (VT.getVectorElementType() == MVT::i32) |
| 3692 | return lowerCTPOP32BitElements(N, DAG); |
| 3693 | else |
| 3694 | return lowerCTPOP16BitElements(N, DAG); |
| 3695 | } |
| 3696 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3697 | static SDValue LowerShift(SDNode *N, SelectionDAG &DAG, |
| 3698 | const ARMSubtarget *ST) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3699 | EVT VT = N->getValueType(0); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3700 | DebugLoc dl = N->getDebugLoc(); |
| 3701 | |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3702 | if (!VT.isVector()) |
| 3703 | return SDValue(); |
| 3704 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3705 | // Lower vector shifts on NEON to use VSHL. |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3706 | assert(ST->hasNEON() && "unexpected vector shift"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3707 | |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3708 | // Left shifts translate directly to the vshiftu intrinsic. |
| 3709 | if (N->getOpcode() == ISD::SHL) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3710 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT, |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3711 | DAG.getConstant(Intrinsic::arm_neon_vshiftu, MVT::i32), |
| 3712 | N->getOperand(0), N->getOperand(1)); |
| 3713 | |
| 3714 | assert((N->getOpcode() == ISD::SRA || |
| 3715 | N->getOpcode() == ISD::SRL) && "unexpected vector shift opcode"); |
| 3716 | |
| 3717 | // NEON uses the same intrinsics for both left and right shifts. For |
| 3718 | // right shifts, the shift amounts are negative, so negate the vector of |
| 3719 | // shift amounts. |
| 3720 | EVT ShiftVT = N->getOperand(1).getValueType(); |
| 3721 | SDValue NegatedCount = DAG.getNode(ISD::SUB, dl, ShiftVT, |
| 3722 | getZeroVector(ShiftVT, DAG, dl), |
| 3723 | N->getOperand(1)); |
| 3724 | Intrinsic::ID vshiftInt = (N->getOpcode() == ISD::SRA ? |
| 3725 | Intrinsic::arm_neon_vshifts : |
| 3726 | Intrinsic::arm_neon_vshiftu); |
| 3727 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT, |
| 3728 | DAG.getConstant(vshiftInt, MVT::i32), |
| 3729 | N->getOperand(0), NegatedCount); |
| 3730 | } |
| 3731 | |
| 3732 | static SDValue Expand64BitShift(SDNode *N, SelectionDAG &DAG, |
| 3733 | const ARMSubtarget *ST) { |
| 3734 | EVT VT = N->getValueType(0); |
| 3735 | DebugLoc dl = N->getDebugLoc(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3736 | |
Eli Friedman | ce392eb | 2009-08-22 03:13:10 +0000 | [diff] [blame] | 3737 | // We can get here for a node like i32 = ISD::SHL i32, i64 |
| 3738 | if (VT != MVT::i64) |
| 3739 | return SDValue(); |
| 3740 | |
| 3741 | assert((N->getOpcode() == ISD::SRL || N->getOpcode() == ISD::SRA) && |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3742 | "Unknown shift to lower!"); |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 3743 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3744 | // We only lower SRA, SRL of 1 here, all others use generic lowering. |
| 3745 | if (!isa<ConstantSDNode>(N->getOperand(1)) || |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 3746 | cast<ConstantSDNode>(N->getOperand(1))->getZExtValue() != 1) |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 3747 | return SDValue(); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3748 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3749 | // If we are in thumb mode, we don't have RRX. |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 3750 | if (ST->isThumb1Only()) return SDValue(); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3751 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3752 | // 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] | 3753 | 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] | 3754 | DAG.getConstant(0, MVT::i32)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3755 | 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] | 3756 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3757 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3758 | // First, build a SRA_FLAG/SRL_FLAG op, which shifts the top part by one and |
| 3759 | // captures the result into a carry flag. |
| 3760 | unsigned Opc = N->getOpcode() == ISD::SRL ? ARMISD::SRL_FLAG:ARMISD::SRA_FLAG; |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 3761 | 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] | 3762 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3763 | // 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] | 3764 | Lo = DAG.getNode(ARMISD::RRX, dl, MVT::i32, Lo, Hi.getValue(1)); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3765 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3766 | // Merge the pieces into a single i64 value. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3767 | return DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Lo, Hi); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3768 | } |
| 3769 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3770 | static SDValue LowerVSETCC(SDValue Op, SelectionDAG &DAG) { |
| 3771 | SDValue TmpOp0, TmpOp1; |
| 3772 | bool Invert = false; |
| 3773 | bool Swap = false; |
| 3774 | unsigned Opc = 0; |
| 3775 | |
| 3776 | SDValue Op0 = Op.getOperand(0); |
| 3777 | SDValue Op1 = Op.getOperand(1); |
| 3778 | SDValue CC = Op.getOperand(2); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3779 | EVT VT = Op.getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3780 | ISD::CondCode SetCCOpcode = cast<CondCodeSDNode>(CC)->get(); |
| 3781 | DebugLoc dl = Op.getDebugLoc(); |
| 3782 | |
| 3783 | if (Op.getOperand(1).getValueType().isFloatingPoint()) { |
| 3784 | switch (SetCCOpcode) { |
David Blaikie | 4d6ccb5 | 2012-01-20 21:51:11 +0000 | [diff] [blame] | 3785 | default: llvm_unreachable("Illegal FP comparison"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3786 | case ISD::SETUNE: |
| 3787 | case ISD::SETNE: Invert = true; // Fallthrough |
| 3788 | case ISD::SETOEQ: |
| 3789 | case ISD::SETEQ: Opc = ARMISD::VCEQ; break; |
| 3790 | case ISD::SETOLT: |
| 3791 | case ISD::SETLT: Swap = true; // Fallthrough |
| 3792 | case ISD::SETOGT: |
| 3793 | case ISD::SETGT: Opc = ARMISD::VCGT; break; |
| 3794 | case ISD::SETOLE: |
| 3795 | case ISD::SETLE: Swap = true; // Fallthrough |
| 3796 | case ISD::SETOGE: |
| 3797 | case ISD::SETGE: Opc = ARMISD::VCGE; break; |
| 3798 | case ISD::SETUGE: Swap = true; // Fallthrough |
| 3799 | case ISD::SETULE: Invert = true; Opc = ARMISD::VCGT; break; |
| 3800 | case ISD::SETUGT: Swap = true; // Fallthrough |
| 3801 | case ISD::SETULT: Invert = true; Opc = ARMISD::VCGE; break; |
| 3802 | case ISD::SETUEQ: Invert = true; // Fallthrough |
| 3803 | case ISD::SETONE: |
| 3804 | // Expand this to (OLT | OGT). |
| 3805 | TmpOp0 = Op0; |
| 3806 | TmpOp1 = Op1; |
| 3807 | Opc = ISD::OR; |
| 3808 | Op0 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp1, TmpOp0); |
| 3809 | Op1 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp0, TmpOp1); |
| 3810 | break; |
| 3811 | case ISD::SETUO: Invert = true; // Fallthrough |
| 3812 | case ISD::SETO: |
| 3813 | // Expand this to (OLT | OGE). |
| 3814 | TmpOp0 = Op0; |
| 3815 | TmpOp1 = Op1; |
| 3816 | Opc = ISD::OR; |
| 3817 | Op0 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp1, TmpOp0); |
| 3818 | Op1 = DAG.getNode(ARMISD::VCGE, dl, VT, TmpOp0, TmpOp1); |
| 3819 | break; |
| 3820 | } |
| 3821 | } else { |
| 3822 | // Integer comparisons. |
| 3823 | switch (SetCCOpcode) { |
David Blaikie | 4d6ccb5 | 2012-01-20 21:51:11 +0000 | [diff] [blame] | 3824 | default: llvm_unreachable("Illegal integer comparison"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3825 | case ISD::SETNE: Invert = true; |
| 3826 | case ISD::SETEQ: Opc = ARMISD::VCEQ; break; |
| 3827 | case ISD::SETLT: Swap = true; |
| 3828 | case ISD::SETGT: Opc = ARMISD::VCGT; break; |
| 3829 | case ISD::SETLE: Swap = true; |
| 3830 | case ISD::SETGE: Opc = ARMISD::VCGE; break; |
| 3831 | case ISD::SETULT: Swap = true; |
| 3832 | case ISD::SETUGT: Opc = ARMISD::VCGTU; break; |
| 3833 | case ISD::SETULE: Swap = true; |
| 3834 | case ISD::SETUGE: Opc = ARMISD::VCGEU; break; |
| 3835 | } |
| 3836 | |
Nick Lewycky | 7f6aa2b | 2009-07-08 03:04:38 +0000 | [diff] [blame] | 3837 | // Detect VTST (Vector Test Bits) = icmp ne (and (op0, op1), zero). |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3838 | if (Opc == ARMISD::VCEQ) { |
| 3839 | |
| 3840 | SDValue AndOp; |
| 3841 | if (ISD::isBuildVectorAllZeros(Op1.getNode())) |
| 3842 | AndOp = Op0; |
| 3843 | else if (ISD::isBuildVectorAllZeros(Op0.getNode())) |
| 3844 | AndOp = Op1; |
| 3845 | |
| 3846 | // Ignore bitconvert. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3847 | if (AndOp.getNode() && AndOp.getOpcode() == ISD::BITCAST) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3848 | AndOp = AndOp.getOperand(0); |
| 3849 | |
| 3850 | if (AndOp.getNode() && AndOp.getOpcode() == ISD::AND) { |
| 3851 | Opc = ARMISD::VTST; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3852 | Op0 = DAG.getNode(ISD::BITCAST, dl, VT, AndOp.getOperand(0)); |
| 3853 | Op1 = DAG.getNode(ISD::BITCAST, dl, VT, AndOp.getOperand(1)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3854 | Invert = !Invert; |
| 3855 | } |
| 3856 | } |
| 3857 | } |
| 3858 | |
| 3859 | if (Swap) |
| 3860 | std::swap(Op0, Op1); |
| 3861 | |
Owen Anderson | c24cb35 | 2010-11-08 23:21:22 +0000 | [diff] [blame] | 3862 | // If one of the operands is a constant vector zero, attempt to fold the |
| 3863 | // comparison to a specialized compare-against-zero form. |
| 3864 | SDValue SingleOp; |
| 3865 | if (ISD::isBuildVectorAllZeros(Op1.getNode())) |
| 3866 | SingleOp = Op0; |
| 3867 | else if (ISD::isBuildVectorAllZeros(Op0.getNode())) { |
| 3868 | if (Opc == ARMISD::VCGE) |
| 3869 | Opc = ARMISD::VCLEZ; |
| 3870 | else if (Opc == ARMISD::VCGT) |
| 3871 | Opc = ARMISD::VCLTZ; |
| 3872 | SingleOp = Op1; |
| 3873 | } |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3874 | |
Owen Anderson | c24cb35 | 2010-11-08 23:21:22 +0000 | [diff] [blame] | 3875 | SDValue Result; |
| 3876 | if (SingleOp.getNode()) { |
| 3877 | switch (Opc) { |
| 3878 | case ARMISD::VCEQ: |
| 3879 | Result = DAG.getNode(ARMISD::VCEQZ, dl, VT, SingleOp); break; |
| 3880 | case ARMISD::VCGE: |
| 3881 | Result = DAG.getNode(ARMISD::VCGEZ, dl, VT, SingleOp); break; |
| 3882 | case ARMISD::VCLEZ: |
| 3883 | Result = DAG.getNode(ARMISD::VCLEZ, dl, VT, SingleOp); break; |
| 3884 | case ARMISD::VCGT: |
| 3885 | Result = DAG.getNode(ARMISD::VCGTZ, dl, VT, SingleOp); break; |
| 3886 | case ARMISD::VCLTZ: |
| 3887 | Result = DAG.getNode(ARMISD::VCLTZ, dl, VT, SingleOp); break; |
| 3888 | default: |
| 3889 | Result = DAG.getNode(Opc, dl, VT, Op0, Op1); |
| 3890 | } |
| 3891 | } else { |
| 3892 | Result = DAG.getNode(Opc, dl, VT, Op0, Op1); |
| 3893 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3894 | |
| 3895 | if (Invert) |
| 3896 | Result = DAG.getNOT(dl, Result, VT); |
| 3897 | |
| 3898 | return Result; |
| 3899 | } |
| 3900 | |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 3901 | /// isNEONModifiedImm - Check if the specified splat value corresponds to a |
| 3902 | /// valid vector constant for a NEON instruction with a "modified immediate" |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3903 | /// operand (e.g., VMOV). If so, return the encoded value. |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 3904 | static SDValue isNEONModifiedImm(uint64_t SplatBits, uint64_t SplatUndef, |
| 3905 | unsigned SplatBitSize, SelectionDAG &DAG, |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3906 | EVT &VT, bool is128Bits, NEONModImmType type) { |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3907 | unsigned OpCmode, Imm; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3908 | |
Bob Wilson | 827b210 | 2010-06-15 19:05:35 +0000 | [diff] [blame] | 3909 | // SplatBitSize is set to the smallest size that splats the vector, so a |
| 3910 | // zero vector will always have SplatBitSize == 8. However, NEON modified |
| 3911 | // immediate instructions others than VMOV do not support the 8-bit encoding |
| 3912 | // of a zero vector, and the default encoding of zero is supposed to be the |
| 3913 | // 32-bit version. |
| 3914 | if (SplatBits == 0) |
| 3915 | SplatBitSize = 32; |
| 3916 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3917 | switch (SplatBitSize) { |
| 3918 | case 8: |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3919 | if (type != VMOVModImm) |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 3920 | return SDValue(); |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3921 | // Any 1-byte value is OK. Op=0, Cmode=1110. |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3922 | assert((SplatBits & ~0xff) == 0 && "one byte splat value is too big"); |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3923 | OpCmode = 0xe; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3924 | Imm = SplatBits; |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3925 | VT = is128Bits ? MVT::v16i8 : MVT::v8i8; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3926 | break; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3927 | |
| 3928 | case 16: |
| 3929 | // 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] | 3930 | VT = is128Bits ? MVT::v8i16 : MVT::v4i16; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3931 | if ((SplatBits & ~0xff) == 0) { |
| 3932 | // Value = 0x00nn: Op=x, Cmode=100x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3933 | OpCmode = 0x8; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3934 | Imm = SplatBits; |
| 3935 | break; |
| 3936 | } |
| 3937 | if ((SplatBits & ~0xff00) == 0) { |
| 3938 | // Value = 0xnn00: Op=x, Cmode=101x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3939 | OpCmode = 0xa; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3940 | Imm = SplatBits >> 8; |
| 3941 | break; |
| 3942 | } |
| 3943 | return SDValue(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3944 | |
| 3945 | case 32: |
| 3946 | // NEON's 32-bit VMOV supports splat values where: |
| 3947 | // * only one byte is nonzero, or |
| 3948 | // * the least significant byte is 0xff and the second byte is nonzero, or |
| 3949 | // * the least significant 2 bytes are 0xff and the third is nonzero. |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3950 | VT = is128Bits ? MVT::v4i32 : MVT::v2i32; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3951 | if ((SplatBits & ~0xff) == 0) { |
| 3952 | // Value = 0x000000nn: Op=x, Cmode=000x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3953 | OpCmode = 0; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3954 | Imm = SplatBits; |
| 3955 | break; |
| 3956 | } |
| 3957 | if ((SplatBits & ~0xff00) == 0) { |
| 3958 | // Value = 0x0000nn00: Op=x, Cmode=001x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3959 | OpCmode = 0x2; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3960 | Imm = SplatBits >> 8; |
| 3961 | break; |
| 3962 | } |
| 3963 | if ((SplatBits & ~0xff0000) == 0) { |
| 3964 | // Value = 0x00nn0000: Op=x, Cmode=010x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3965 | OpCmode = 0x4; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3966 | Imm = SplatBits >> 16; |
| 3967 | break; |
| 3968 | } |
| 3969 | if ((SplatBits & ~0xff000000) == 0) { |
| 3970 | // Value = 0xnn000000: Op=x, Cmode=011x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3971 | OpCmode = 0x6; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3972 | Imm = SplatBits >> 24; |
| 3973 | break; |
| 3974 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3975 | |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3976 | // cmode == 0b1100 and cmode == 0b1101 are not supported for VORR or VBIC |
| 3977 | if (type == OtherModImm) return SDValue(); |
| 3978 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3979 | if ((SplatBits & ~0xffff) == 0 && |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3980 | ((SplatBits | SplatUndef) & 0xff) == 0xff) { |
| 3981 | // Value = 0x0000nnff: Op=x, Cmode=1100. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3982 | OpCmode = 0xc; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3983 | Imm = SplatBits >> 8; |
| 3984 | SplatBits |= 0xff; |
| 3985 | break; |
| 3986 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3987 | |
| 3988 | if ((SplatBits & ~0xffffff) == 0 && |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3989 | ((SplatBits | SplatUndef) & 0xffff) == 0xffff) { |
| 3990 | // Value = 0x00nnffff: Op=x, Cmode=1101. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3991 | OpCmode = 0xd; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3992 | Imm = SplatBits >> 16; |
| 3993 | SplatBits |= 0xffff; |
| 3994 | break; |
| 3995 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3996 | |
| 3997 | // Note: there are a few 32-bit splat values (specifically: 00ffff00, |
| 3998 | // ff000000, ff0000ff, and ffff00ff) that are valid for VMOV.I64 but not |
| 3999 | // VMOV.I32. A (very) minor optimization would be to replicate the value |
| 4000 | // and fall through here to test for a valid 64-bit splat. But, then the |
| 4001 | // caller would also need to check and handle the change in size. |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4002 | return SDValue(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4003 | |
| 4004 | case 64: { |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 4005 | if (type != VMOVModImm) |
Bob Wilson | 827b210 | 2010-06-15 19:05:35 +0000 | [diff] [blame] | 4006 | return SDValue(); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 4007 | // 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] | 4008 | uint64_t BitMask = 0xff; |
| 4009 | uint64_t Val = 0; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4010 | unsigned ImmMask = 1; |
| 4011 | Imm = 0; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4012 | for (int ByteNum = 0; ByteNum < 8; ++ByteNum) { |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4013 | if (((SplatBits | SplatUndef) & BitMask) == BitMask) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4014 | Val |= BitMask; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4015 | Imm |= ImmMask; |
| 4016 | } else if ((SplatBits & BitMask) != 0) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4017 | return SDValue(); |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4018 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4019 | BitMask <<= 8; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4020 | ImmMask <<= 1; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4021 | } |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4022 | // Op=1, Cmode=1110. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4023 | OpCmode = 0x1e; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4024 | SplatBits = Val; |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4025 | VT = is128Bits ? MVT::v2i64 : MVT::v1i64; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4026 | break; |
| 4027 | } |
| 4028 | |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4029 | default: |
Bob Wilson | dc076da | 2010-06-19 05:32:09 +0000 | [diff] [blame] | 4030 | llvm_unreachable("unexpected size for isNEONModifiedImm"); |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4031 | } |
| 4032 | |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4033 | unsigned EncodedVal = ARM_AM::createNEONModImm(OpCmode, Imm); |
| 4034 | return DAG.getTargetConstant(EncodedVal, MVT::i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4035 | } |
| 4036 | |
Lang Hames | c0a9f82 | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 4037 | SDValue ARMTargetLowering::LowerConstantFP(SDValue Op, SelectionDAG &DAG, |
| 4038 | const ARMSubtarget *ST) const { |
| 4039 | if (!ST->useNEONForSinglePrecisionFP() || !ST->hasVFP3() || ST->hasD16()) |
| 4040 | return SDValue(); |
| 4041 | |
| 4042 | ConstantFPSDNode *CFP = cast<ConstantFPSDNode>(Op); |
| 4043 | assert(Op.getValueType() == MVT::f32 && |
| 4044 | "ConstantFP custom lowering should only occur for f32."); |
| 4045 | |
| 4046 | // Try splatting with a VMOV.f32... |
| 4047 | APFloat FPVal = CFP->getValueAPF(); |
| 4048 | int ImmVal = ARM_AM::getFP32Imm(FPVal); |
| 4049 | if (ImmVal != -1) { |
| 4050 | DebugLoc DL = Op.getDebugLoc(); |
| 4051 | SDValue NewVal = DAG.getTargetConstant(ImmVal, MVT::i32); |
| 4052 | SDValue VecConstant = DAG.getNode(ARMISD::VMOVFPIMM, DL, MVT::v2f32, |
| 4053 | NewVal); |
| 4054 | return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::f32, VecConstant, |
| 4055 | DAG.getConstant(0, MVT::i32)); |
| 4056 | } |
| 4057 | |
| 4058 | // If that fails, try a VMOV.i32 |
| 4059 | EVT VMovVT; |
| 4060 | unsigned iVal = FPVal.bitcastToAPInt().getZExtValue(); |
| 4061 | SDValue NewVal = isNEONModifiedImm(iVal, 0, 32, DAG, VMovVT, false, |
| 4062 | VMOVModImm); |
| 4063 | if (NewVal != SDValue()) { |
| 4064 | DebugLoc DL = Op.getDebugLoc(); |
| 4065 | SDValue VecConstant = DAG.getNode(ARMISD::VMOVIMM, DL, VMovVT, |
| 4066 | NewVal); |
| 4067 | SDValue VecFConstant = DAG.getNode(ISD::BITCAST, DL, MVT::v2f32, |
| 4068 | VecConstant); |
| 4069 | return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::f32, VecFConstant, |
| 4070 | DAG.getConstant(0, MVT::i32)); |
| 4071 | } |
| 4072 | |
| 4073 | // Finally, try a VMVN.i32 |
| 4074 | NewVal = isNEONModifiedImm(~iVal & 0xffffffff, 0, 32, DAG, VMovVT, false, |
| 4075 | VMVNModImm); |
| 4076 | if (NewVal != SDValue()) { |
| 4077 | DebugLoc DL = Op.getDebugLoc(); |
| 4078 | SDValue VecConstant = DAG.getNode(ARMISD::VMVNIMM, DL, VMovVT, NewVal); |
| 4079 | SDValue VecFConstant = DAG.getNode(ISD::BITCAST, DL, MVT::v2f32, |
| 4080 | VecConstant); |
| 4081 | return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::f32, VecFConstant, |
| 4082 | DAG.getConstant(0, MVT::i32)); |
| 4083 | } |
| 4084 | |
| 4085 | return SDValue(); |
| 4086 | } |
| 4087 | |
Quentin Colombet | 43934ae | 2012-11-02 21:32:17 +0000 | [diff] [blame] | 4088 | // check if an VEXT instruction can handle the shuffle mask when the |
| 4089 | // vector sources of the shuffle are the same. |
| 4090 | static bool isSingletonVEXTMask(ArrayRef<int> M, EVT VT, unsigned &Imm) { |
| 4091 | unsigned NumElts = VT.getVectorNumElements(); |
| 4092 | |
| 4093 | // Assume that the first shuffle index is not UNDEF. Fail if it is. |
| 4094 | if (M[0] < 0) |
| 4095 | return false; |
| 4096 | |
| 4097 | Imm = M[0]; |
| 4098 | |
| 4099 | // If this is a VEXT shuffle, the immediate value is the index of the first |
| 4100 | // element. The other shuffle indices must be the successive elements after |
| 4101 | // the first one. |
| 4102 | unsigned ExpectedElt = Imm; |
| 4103 | for (unsigned i = 1; i < NumElts; ++i) { |
| 4104 | // Increment the expected index. If it wraps around, just follow it |
| 4105 | // back to index zero and keep going. |
| 4106 | ++ExpectedElt; |
| 4107 | if (ExpectedElt == NumElts) |
| 4108 | ExpectedElt = 0; |
| 4109 | |
| 4110 | if (M[i] < 0) continue; // ignore UNDEF indices |
| 4111 | if (ExpectedElt != static_cast<unsigned>(M[i])) |
| 4112 | return false; |
| 4113 | } |
| 4114 | |
| 4115 | return true; |
| 4116 | } |
| 4117 | |
Lang Hames | c0a9f82 | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 4118 | |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4119 | static bool isVEXTMask(ArrayRef<int> M, EVT VT, |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4120 | bool &ReverseVEXT, unsigned &Imm) { |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 4121 | unsigned NumElts = VT.getVectorNumElements(); |
| 4122 | ReverseVEXT = false; |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4123 | |
| 4124 | // Assume that the first shuffle index is not UNDEF. Fail if it is. |
| 4125 | if (M[0] < 0) |
| 4126 | return false; |
| 4127 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4128 | Imm = M[0]; |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 4129 | |
| 4130 | // If this is a VEXT shuffle, the immediate value is the index of the first |
| 4131 | // element. The other shuffle indices must be the successive elements after |
| 4132 | // the first one. |
| 4133 | unsigned ExpectedElt = Imm; |
| 4134 | for (unsigned i = 1; i < NumElts; ++i) { |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 4135 | // Increment the expected index. If it wraps around, it may still be |
| 4136 | // a VEXT but the source vectors must be swapped. |
| 4137 | ExpectedElt += 1; |
| 4138 | if (ExpectedElt == NumElts * 2) { |
| 4139 | ExpectedElt = 0; |
| 4140 | ReverseVEXT = true; |
| 4141 | } |
| 4142 | |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4143 | if (M[i] < 0) continue; // ignore UNDEF indices |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4144 | if (ExpectedElt != static_cast<unsigned>(M[i])) |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 4145 | return false; |
| 4146 | } |
| 4147 | |
| 4148 | // Adjust the index value if the source operands will be swapped. |
| 4149 | if (ReverseVEXT) |
| 4150 | Imm -= NumElts; |
| 4151 | |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 4152 | return true; |
| 4153 | } |
| 4154 | |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 4155 | /// isVREVMask - Check if a vector shuffle corresponds to a VREV |
| 4156 | /// instruction with the specified blocksize. (The order of the elements |
| 4157 | /// within each block of the vector is reversed.) |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4158 | static bool isVREVMask(ArrayRef<int> M, EVT VT, unsigned BlockSize) { |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 4159 | assert((BlockSize==16 || BlockSize==32 || BlockSize==64) && |
| 4160 | "Only possible block sizes for VREV are: 16, 32, 64"); |
| 4161 | |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 4162 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 4163 | if (EltSz == 64) |
| 4164 | return false; |
| 4165 | |
| 4166 | unsigned NumElts = VT.getVectorNumElements(); |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4167 | unsigned BlockElts = M[0] + 1; |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4168 | // If the first shuffle index is UNDEF, be optimistic. |
| 4169 | if (M[0] < 0) |
| 4170 | BlockElts = BlockSize / EltSz; |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 4171 | |
| 4172 | if (BlockSize <= EltSz || BlockSize != BlockElts * EltSz) |
| 4173 | return false; |
| 4174 | |
| 4175 | for (unsigned i = 0; i < NumElts; ++i) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4176 | if (M[i] < 0) continue; // ignore UNDEF indices |
| 4177 | if ((unsigned) M[i] != (i - i%BlockElts) + (BlockElts - 1 - i%BlockElts)) |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 4178 | return false; |
| 4179 | } |
| 4180 | |
| 4181 | return true; |
| 4182 | } |
| 4183 | |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4184 | static bool isVTBLMask(ArrayRef<int> M, EVT VT) { |
Bill Wendling | 0d4c9d9 | 2011-03-15 21:15:20 +0000 | [diff] [blame] | 4185 | // We can handle <8 x i8> vector shuffles. If the index in the mask is out of |
| 4186 | // range, then 0 is placed into the resulting vector. So pretty much any mask |
| 4187 | // of 8 elements can work here. |
| 4188 | return VT == MVT::v8i8 && M.size() == 8; |
| 4189 | } |
| 4190 | |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4191 | static bool isVTRNMask(ArrayRef<int> M, EVT VT, unsigned &WhichResult) { |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 4192 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 4193 | if (EltSz == 64) |
| 4194 | return false; |
| 4195 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4196 | unsigned NumElts = VT.getVectorNumElements(); |
| 4197 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 4198 | for (unsigned i = 0; i < NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4199 | if ((M[i] >= 0 && (unsigned) M[i] != i + WhichResult) || |
| 4200 | (M[i+1] >= 0 && (unsigned) M[i+1] != i + NumElts + WhichResult)) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4201 | return false; |
| 4202 | } |
| 4203 | return true; |
| 4204 | } |
| 4205 | |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4206 | /// isVTRN_v_undef_Mask - Special case of isVTRNMask for canonical form of |
| 4207 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 4208 | /// 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] | 4209 | 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] | 4210 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 4211 | if (EltSz == 64) |
| 4212 | return false; |
| 4213 | |
| 4214 | unsigned NumElts = VT.getVectorNumElements(); |
| 4215 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 4216 | for (unsigned i = 0; i < NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4217 | if ((M[i] >= 0 && (unsigned) M[i] != i + WhichResult) || |
| 4218 | (M[i+1] >= 0 && (unsigned) M[i+1] != i + WhichResult)) |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4219 | return false; |
| 4220 | } |
| 4221 | return true; |
| 4222 | } |
| 4223 | |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4224 | static bool isVUZPMask(ArrayRef<int> M, EVT VT, unsigned &WhichResult) { |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 4225 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 4226 | if (EltSz == 64) |
| 4227 | return false; |
| 4228 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4229 | unsigned NumElts = VT.getVectorNumElements(); |
| 4230 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 4231 | for (unsigned i = 0; i != NumElts; ++i) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4232 | if (M[i] < 0) continue; // ignore UNDEF indices |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4233 | if ((unsigned) M[i] != 2 * i + WhichResult) |
| 4234 | return false; |
| 4235 | } |
| 4236 | |
| 4237 | // 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] | 4238 | if (VT.is64BitVector() && EltSz == 32) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4239 | return false; |
| 4240 | |
| 4241 | return true; |
| 4242 | } |
| 4243 | |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4244 | /// isVUZP_v_undef_Mask - Special case of isVUZPMask for canonical form of |
| 4245 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 4246 | /// 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] | 4247 | 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] | 4248 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 4249 | if (EltSz == 64) |
| 4250 | return false; |
| 4251 | |
| 4252 | unsigned Half = VT.getVectorNumElements() / 2; |
| 4253 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 4254 | for (unsigned j = 0; j != 2; ++j) { |
| 4255 | unsigned Idx = WhichResult; |
| 4256 | for (unsigned i = 0; i != Half; ++i) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4257 | int MIdx = M[i + j * Half]; |
| 4258 | if (MIdx >= 0 && (unsigned) MIdx != Idx) |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4259 | return false; |
| 4260 | Idx += 2; |
| 4261 | } |
| 4262 | } |
| 4263 | |
| 4264 | // VUZP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32. |
| 4265 | if (VT.is64BitVector() && EltSz == 32) |
| 4266 | return false; |
| 4267 | |
| 4268 | return true; |
| 4269 | } |
| 4270 | |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4271 | static bool isVZIPMask(ArrayRef<int> M, EVT VT, unsigned &WhichResult) { |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 4272 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 4273 | if (EltSz == 64) |
| 4274 | return false; |
| 4275 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4276 | unsigned NumElts = VT.getVectorNumElements(); |
| 4277 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 4278 | unsigned Idx = WhichResult * NumElts / 2; |
| 4279 | for (unsigned i = 0; i != NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4280 | if ((M[i] >= 0 && (unsigned) M[i] != Idx) || |
| 4281 | (M[i+1] >= 0 && (unsigned) M[i+1] != Idx + NumElts)) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4282 | return false; |
| 4283 | Idx += 1; |
| 4284 | } |
| 4285 | |
| 4286 | // 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] | 4287 | if (VT.is64BitVector() && EltSz == 32) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4288 | return false; |
| 4289 | |
| 4290 | return true; |
| 4291 | } |
| 4292 | |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4293 | /// isVZIP_v_undef_Mask - Special case of isVZIPMask for canonical form of |
| 4294 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 4295 | /// 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] | 4296 | 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] | 4297 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 4298 | if (EltSz == 64) |
| 4299 | return false; |
| 4300 | |
| 4301 | unsigned NumElts = VT.getVectorNumElements(); |
| 4302 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 4303 | unsigned Idx = WhichResult * NumElts / 2; |
| 4304 | for (unsigned i = 0; i != NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4305 | if ((M[i] >= 0 && (unsigned) M[i] != Idx) || |
| 4306 | (M[i+1] >= 0 && (unsigned) M[i+1] != Idx)) |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4307 | return false; |
| 4308 | Idx += 1; |
| 4309 | } |
| 4310 | |
| 4311 | // VZIP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32. |
| 4312 | if (VT.is64BitVector() && EltSz == 32) |
| 4313 | return false; |
| 4314 | |
| 4315 | return true; |
| 4316 | } |
| 4317 | |
Arnold Schwaighofer | d9316da | 2013-02-12 01:58:32 +0000 | [diff] [blame] | 4318 | /// \return true if this is a reverse operation on an vector. |
| 4319 | static bool isReverseMask(ArrayRef<int> M, EVT VT) { |
| 4320 | unsigned NumElts = VT.getVectorNumElements(); |
| 4321 | // Make sure the mask has the right size. |
| 4322 | if (NumElts != M.size()) |
| 4323 | return false; |
| 4324 | |
| 4325 | // Look for <15, ..., 3, -1, 1, 0>. |
| 4326 | for (unsigned i = 0; i != NumElts; ++i) |
| 4327 | if (M[i] >= 0 && M[i] != (int) (NumElts - 1 - i)) |
| 4328 | return false; |
| 4329 | |
| 4330 | return true; |
| 4331 | } |
| 4332 | |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 4333 | // If N is an integer constant that can be moved into a register in one |
| 4334 | // instruction, return an SDValue of such a constant (will become a MOV |
| 4335 | // instruction). Otherwise return null. |
| 4336 | static SDValue IsSingleInstrConstant(SDValue N, SelectionDAG &DAG, |
| 4337 | const ARMSubtarget *ST, DebugLoc dl) { |
| 4338 | uint64_t Val; |
| 4339 | if (!isa<ConstantSDNode>(N)) |
| 4340 | return SDValue(); |
| 4341 | Val = cast<ConstantSDNode>(N)->getZExtValue(); |
| 4342 | |
| 4343 | if (ST->isThumb1Only()) { |
| 4344 | if (Val <= 255 || ~Val <= 255) |
| 4345 | return DAG.getConstant(Val, MVT::i32); |
| 4346 | } else { |
| 4347 | if (ARM_AM::getSOImmVal(Val) != -1 || ARM_AM::getSOImmVal(~Val) != -1) |
| 4348 | return DAG.getConstant(Val, MVT::i32); |
| 4349 | } |
| 4350 | return SDValue(); |
| 4351 | } |
| 4352 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4353 | // If this is a case we can't handle, return null and let the default |
| 4354 | // expansion code take care of it. |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4355 | SDValue ARMTargetLowering::LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG, |
| 4356 | const ARMSubtarget *ST) const { |
Bob Wilson | d06791f | 2009-08-13 01:57:47 +0000 | [diff] [blame] | 4357 | BuildVectorSDNode *BVN = cast<BuildVectorSDNode>(Op.getNode()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4358 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4359 | EVT VT = Op.getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4360 | |
| 4361 | APInt SplatBits, SplatUndef; |
| 4362 | unsigned SplatBitSize; |
| 4363 | bool HasAnyUndefs; |
| 4364 | if (BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { |
Anton Korobeynikov | 71624cc | 2009-08-29 00:08:18 +0000 | [diff] [blame] | 4365 | if (SplatBitSize <= 64) { |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 4366 | // Check if an immediate VMOV works. |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4367 | EVT VmovVT; |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 4368 | SDValue Val = isNEONModifiedImm(SplatBits.getZExtValue(), |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4369 | SplatUndef.getZExtValue(), SplatBitSize, |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 4370 | DAG, VmovVT, VT.is128BitVector(), |
| 4371 | VMOVModImm); |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4372 | if (Val.getNode()) { |
| 4373 | SDValue Vmov = DAG.getNode(ARMISD::VMOVIMM, dl, VmovVT, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4374 | return DAG.getNode(ISD::BITCAST, dl, VT, Vmov); |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4375 | } |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 4376 | |
| 4377 | // Try an immediate VMVN. |
Eli Friedman | 8e4d042 | 2011-10-13 22:40:23 +0000 | [diff] [blame] | 4378 | uint64_t NegatedImm = (~SplatBits).getZExtValue(); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 4379 | Val = isNEONModifiedImm(NegatedImm, |
| 4380 | SplatUndef.getZExtValue(), SplatBitSize, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4381 | DAG, VmovVT, VT.is128BitVector(), |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 4382 | VMVNModImm); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 4383 | if (Val.getNode()) { |
| 4384 | SDValue Vmov = DAG.getNode(ARMISD::VMVNIMM, dl, VmovVT, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4385 | return DAG.getNode(ISD::BITCAST, dl, VT, Vmov); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 4386 | } |
Evan Cheng | eaa192a | 2011-11-15 02:12:34 +0000 | [diff] [blame] | 4387 | |
| 4388 | // Use vmov.f32 to materialize other v2f32 and v4f32 splats. |
Eli Friedman | 2f21e8c | 2011-12-15 22:56:53 +0000 | [diff] [blame] | 4389 | if ((VT == MVT::v2f32 || VT == MVT::v4f32) && SplatBitSize == 32) { |
Eli Friedman | effab8f | 2011-12-09 23:54:42 +0000 | [diff] [blame] | 4390 | int ImmVal = ARM_AM::getFP32Imm(SplatBits); |
Evan Cheng | eaa192a | 2011-11-15 02:12:34 +0000 | [diff] [blame] | 4391 | if (ImmVal != -1) { |
| 4392 | SDValue Val = DAG.getTargetConstant(ImmVal, MVT::i32); |
| 4393 | return DAG.getNode(ARMISD::VMOVFPIMM, dl, VT, Val); |
| 4394 | } |
| 4395 | } |
Anton Korobeynikov | 71624cc | 2009-08-29 00:08:18 +0000 | [diff] [blame] | 4396 | } |
Bob Wilson | cf661e2 | 2009-07-30 00:31:25 +0000 | [diff] [blame] | 4397 | } |
| 4398 | |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4399 | // Scan through the operands to see if only one value is used. |
James Molloy | ba8562a | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4400 | // |
| 4401 | // As an optimisation, even if more than one value is used it may be more |
| 4402 | // profitable to splat with one value then change some lanes. |
| 4403 | // |
| 4404 | // Heuristically we decide to do this if the vector has a "dominant" value, |
| 4405 | // defined as splatted to more than half of the lanes. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4406 | unsigned NumElts = VT.getVectorNumElements(); |
| 4407 | bool isOnlyLowElement = true; |
| 4408 | bool usesOnlyOneValue = true; |
James Molloy | ba8562a | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4409 | bool hasDominantValue = false; |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4410 | bool isConstant = true; |
James Molloy | ba8562a | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4411 | |
| 4412 | // Map of the number of times a particular SDValue appears in the |
| 4413 | // element list. |
James Molloy | 9515434 | 2012-09-06 10:32:08 +0000 | [diff] [blame] | 4414 | DenseMap<SDValue, unsigned> ValueCounts; |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4415 | SDValue Value; |
| 4416 | for (unsigned i = 0; i < NumElts; ++i) { |
| 4417 | SDValue V = Op.getOperand(i); |
| 4418 | if (V.getOpcode() == ISD::UNDEF) |
| 4419 | continue; |
| 4420 | if (i > 0) |
| 4421 | isOnlyLowElement = false; |
| 4422 | if (!isa<ConstantFPSDNode>(V) && !isa<ConstantSDNode>(V)) |
| 4423 | isConstant = false; |
| 4424 | |
James Molloy | ba8562a | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4425 | ValueCounts.insert(std::make_pair(V, 0)); |
James Molloy | 9515434 | 2012-09-06 10:32:08 +0000 | [diff] [blame] | 4426 | unsigned &Count = ValueCounts[V]; |
James Molloy | ba8562a | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4427 | |
| 4428 | // Is this value dominant? (takes up more than half of the lanes) |
| 4429 | if (++Count > (NumElts / 2)) { |
| 4430 | hasDominantValue = true; |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4431 | Value = V; |
James Molloy | ba8562a | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4432 | } |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4433 | } |
James Molloy | ba8562a | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4434 | if (ValueCounts.size() != 1) |
| 4435 | usesOnlyOneValue = false; |
| 4436 | if (!Value.getNode() && ValueCounts.size() > 0) |
| 4437 | Value = ValueCounts.begin()->first; |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4438 | |
James Molloy | ba8562a | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4439 | if (ValueCounts.size() == 0) |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4440 | return DAG.getUNDEF(VT); |
| 4441 | |
| 4442 | if (isOnlyLowElement) |
| 4443 | return DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, VT, Value); |
| 4444 | |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 4445 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 4446 | |
Dale Johannesen | 575cd14 | 2010-10-19 20:00:17 +0000 | [diff] [blame] | 4447 | // Use VDUP for non-constant splats. For f32 constant splats, reduce to |
| 4448 | // i32 and try again. |
James Molloy | ba8562a | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4449 | if (hasDominantValue && EltSize <= 32) { |
| 4450 | if (!isConstant) { |
| 4451 | SDValue N; |
| 4452 | |
| 4453 | // If we are VDUPing a value that comes directly from a vector, that will |
| 4454 | // cause an unnecessary move to and from a GPR, where instead we could |
| 4455 | // just use VDUPLANE. |
Silviu Baranga | bb1078e | 2012-10-15 09:41:32 +0000 | [diff] [blame] | 4456 | if (Value->getOpcode() == ISD::EXTRACT_VECTOR_ELT) { |
| 4457 | // We need to create a new undef vector to use for the VDUPLANE if the |
| 4458 | // size of the vector from which we get the value is different than the |
| 4459 | // size of the vector that we need to create. We will insert the element |
| 4460 | // such that the register coalescer will remove unnecessary copies. |
| 4461 | if (VT != Value->getOperand(0).getValueType()) { |
| 4462 | ConstantSDNode *constIndex; |
| 4463 | constIndex = dyn_cast<ConstantSDNode>(Value->getOperand(1)); |
| 4464 | assert(constIndex && "The index is not a constant!"); |
| 4465 | unsigned index = constIndex->getAPIntValue().getLimitedValue() % |
| 4466 | VT.getVectorNumElements(); |
| 4467 | N = DAG.getNode(ARMISD::VDUPLANE, dl, VT, |
| 4468 | DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, VT, DAG.getUNDEF(VT), |
| 4469 | Value, DAG.getConstant(index, MVT::i32)), |
| 4470 | DAG.getConstant(index, MVT::i32)); |
| 4471 | } else { |
| 4472 | N = DAG.getNode(ARMISD::VDUPLANE, dl, VT, |
James Molloy | ba8562a | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4473 | Value->getOperand(0), Value->getOperand(1)); |
Silviu Baranga | bb1078e | 2012-10-15 09:41:32 +0000 | [diff] [blame] | 4474 | } |
| 4475 | } |
James Molloy | ba8562a | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4476 | else |
| 4477 | N = DAG.getNode(ARMISD::VDUP, dl, VT, Value); |
| 4478 | |
| 4479 | if (!usesOnlyOneValue) { |
| 4480 | // The dominant value was splatted as 'N', but we now have to insert |
| 4481 | // all differing elements. |
| 4482 | for (unsigned I = 0; I < NumElts; ++I) { |
| 4483 | if (Op.getOperand(I) == Value) |
| 4484 | continue; |
| 4485 | SmallVector<SDValue, 3> Ops; |
| 4486 | Ops.push_back(N); |
| 4487 | Ops.push_back(Op.getOperand(I)); |
| 4488 | Ops.push_back(DAG.getConstant(I, MVT::i32)); |
| 4489 | N = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, VT, &Ops[0], 3); |
| 4490 | } |
| 4491 | } |
| 4492 | return N; |
| 4493 | } |
Dale Johannesen | 575cd14 | 2010-10-19 20:00:17 +0000 | [diff] [blame] | 4494 | if (VT.getVectorElementType().isFloatingPoint()) { |
| 4495 | SmallVector<SDValue, 8> Ops; |
| 4496 | for (unsigned i = 0; i < NumElts; ++i) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4497 | Ops.push_back(DAG.getNode(ISD::BITCAST, dl, MVT::i32, |
Dale Johannesen | 575cd14 | 2010-10-19 20:00:17 +0000 | [diff] [blame] | 4498 | Op.getOperand(i))); |
Nate Begeman | bf5be26 | 2010-11-10 21:35:41 +0000 | [diff] [blame] | 4499 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), MVT::i32, NumElts); |
| 4500 | SDValue Val = DAG.getNode(ISD::BUILD_VECTOR, dl, VecVT, &Ops[0], NumElts); |
Dale Johannesen | e4d3159 | 2010-10-20 22:03:37 +0000 | [diff] [blame] | 4501 | Val = LowerBUILD_VECTOR(Val, DAG, ST); |
| 4502 | if (Val.getNode()) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4503 | return DAG.getNode(ISD::BITCAST, dl, VT, Val); |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 4504 | } |
James Molloy | ba8562a | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4505 | if (usesOnlyOneValue) { |
| 4506 | SDValue Val = IsSingleInstrConstant(Value, DAG, ST, dl); |
| 4507 | if (isConstant && Val.getNode()) |
| 4508 | return DAG.getNode(ARMISD::VDUP, dl, VT, Val); |
| 4509 | } |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 4510 | } |
| 4511 | |
| 4512 | // If all elements are constants and the case above didn't get hit, fall back |
| 4513 | // to the default expansion, which will generate a load from the constant |
| 4514 | // pool. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4515 | if (isConstant) |
| 4516 | return SDValue(); |
| 4517 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4518 | // Empirical tests suggest this is rarely worth it for vectors of length <= 2. |
| 4519 | if (NumElts >= 4) { |
| 4520 | SDValue shuffle = ReconstructShuffle(Op, DAG); |
| 4521 | if (shuffle != SDValue()) |
| 4522 | return shuffle; |
| 4523 | } |
| 4524 | |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4525 | // 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] | 4526 | // the subregisters. Lower it to an ARMISD::BUILD_VECTOR so the operands |
| 4527 | // will be legalized. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4528 | if (EltSize >= 32) { |
| 4529 | // Do the expansion with floating-point types, since that is what the VFP |
| 4530 | // registers are defined to use, and since i64 is not legal. |
| 4531 | EVT EltVT = EVT::getFloatingPointVT(EltSize); |
| 4532 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), EltVT, NumElts); |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4533 | SmallVector<SDValue, 8> Ops; |
| 4534 | for (unsigned i = 0; i < NumElts; ++i) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4535 | Ops.push_back(DAG.getNode(ISD::BITCAST, dl, EltVT, Op.getOperand(i))); |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4536 | SDValue Val = DAG.getNode(ARMISD::BUILD_VECTOR, dl, VecVT, &Ops[0],NumElts); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4537 | return DAG.getNode(ISD::BITCAST, dl, VT, Val); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4538 | } |
| 4539 | |
| 4540 | return SDValue(); |
| 4541 | } |
| 4542 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4543 | // Gather data to see if the operation can be modelled as a |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4544 | // shuffle in combination with VEXTs. |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4545 | SDValue ARMTargetLowering::ReconstructShuffle(SDValue Op, |
| 4546 | SelectionDAG &DAG) const { |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4547 | DebugLoc dl = Op.getDebugLoc(); |
| 4548 | EVT VT = Op.getValueType(); |
| 4549 | unsigned NumElts = VT.getVectorNumElements(); |
| 4550 | |
| 4551 | SmallVector<SDValue, 2> SourceVecs; |
| 4552 | SmallVector<unsigned, 2> MinElts; |
| 4553 | SmallVector<unsigned, 2> MaxElts; |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4554 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4555 | for (unsigned i = 0; i < NumElts; ++i) { |
| 4556 | SDValue V = Op.getOperand(i); |
| 4557 | if (V.getOpcode() == ISD::UNDEF) |
| 4558 | continue; |
| 4559 | else if (V.getOpcode() != ISD::EXTRACT_VECTOR_ELT) { |
| 4560 | // A shuffle can only come from building a vector from various |
| 4561 | // elements of other vectors. |
| 4562 | return SDValue(); |
Eli Friedman | 46995fa | 2011-10-14 23:58:49 +0000 | [diff] [blame] | 4563 | } else if (V.getOperand(0).getValueType().getVectorElementType() != |
| 4564 | VT.getVectorElementType()) { |
| 4565 | // This code doesn't know how to handle shuffles where the vector |
| 4566 | // element types do not match (this happens because type legalization |
| 4567 | // promotes the return type of EXTRACT_VECTOR_ELT). |
| 4568 | // FIXME: It might be appropriate to extend this code to handle |
| 4569 | // mismatched types. |
| 4570 | return SDValue(); |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4571 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4572 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4573 | // Record this extraction against the appropriate vector if possible... |
| 4574 | SDValue SourceVec = V.getOperand(0); |
Jim Grosbach | 2422047 | 2012-07-25 17:02:47 +0000 | [diff] [blame] | 4575 | // If the element number isn't a constant, we can't effectively |
| 4576 | // analyze what's going on. |
| 4577 | if (!isa<ConstantSDNode>(V.getOperand(1))) |
| 4578 | return SDValue(); |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4579 | unsigned EltNo = cast<ConstantSDNode>(V.getOperand(1))->getZExtValue(); |
| 4580 | bool FoundSource = false; |
| 4581 | for (unsigned j = 0; j < SourceVecs.size(); ++j) { |
| 4582 | if (SourceVecs[j] == SourceVec) { |
| 4583 | if (MinElts[j] > EltNo) |
| 4584 | MinElts[j] = EltNo; |
| 4585 | if (MaxElts[j] < EltNo) |
| 4586 | MaxElts[j] = EltNo; |
| 4587 | FoundSource = true; |
| 4588 | break; |
| 4589 | } |
| 4590 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4591 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4592 | // Or record a new source if not... |
| 4593 | if (!FoundSource) { |
| 4594 | SourceVecs.push_back(SourceVec); |
| 4595 | MinElts.push_back(EltNo); |
| 4596 | MaxElts.push_back(EltNo); |
| 4597 | } |
| 4598 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4599 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4600 | // Currently only do something sane when at most two source vectors |
| 4601 | // involved. |
| 4602 | if (SourceVecs.size() > 2) |
| 4603 | return SDValue(); |
| 4604 | |
| 4605 | SDValue ShuffleSrcs[2] = {DAG.getUNDEF(VT), DAG.getUNDEF(VT) }; |
| 4606 | int VEXTOffsets[2] = {0, 0}; |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4607 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4608 | // This loop extracts the usage patterns of the source vectors |
| 4609 | // and prepares appropriate SDValues for a shuffle if possible. |
| 4610 | for (unsigned i = 0; i < SourceVecs.size(); ++i) { |
| 4611 | if (SourceVecs[i].getValueType() == VT) { |
| 4612 | // No VEXT necessary |
| 4613 | ShuffleSrcs[i] = SourceVecs[i]; |
| 4614 | VEXTOffsets[i] = 0; |
| 4615 | continue; |
| 4616 | } else if (SourceVecs[i].getValueType().getVectorNumElements() < NumElts) { |
| 4617 | // It probably isn't worth padding out a smaller vector just to |
| 4618 | // break it down again in a shuffle. |
| 4619 | return SDValue(); |
| 4620 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4621 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4622 | // Since only 64-bit and 128-bit vectors are legal on ARM and |
| 4623 | // we've eliminated the other cases... |
Bob Wilson | 70f8573 | 2011-01-07 23:40:46 +0000 | [diff] [blame] | 4624 | assert(SourceVecs[i].getValueType().getVectorNumElements() == 2*NumElts && |
| 4625 | "unexpected vector sizes in ReconstructShuffle"); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4626 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4627 | if (MaxElts[i] - MinElts[i] >= NumElts) { |
| 4628 | // Span too large for a VEXT to cope |
| 4629 | return SDValue(); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4630 | } |
| 4631 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4632 | if (MinElts[i] >= NumElts) { |
| 4633 | // The extraction can just take the second half |
| 4634 | VEXTOffsets[i] = NumElts; |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4635 | ShuffleSrcs[i] = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 4636 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4637 | DAG.getIntPtrConstant(NumElts)); |
| 4638 | } else if (MaxElts[i] < NumElts) { |
| 4639 | // The extraction can just take the first half |
| 4640 | VEXTOffsets[i] = 0; |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4641 | ShuffleSrcs[i] = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 4642 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4643 | DAG.getIntPtrConstant(0)); |
| 4644 | } else { |
| 4645 | // An actual VEXT is needed |
| 4646 | VEXTOffsets[i] = MinElts[i]; |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4647 | SDValue VEXTSrc1 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 4648 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4649 | DAG.getIntPtrConstant(0)); |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4650 | SDValue VEXTSrc2 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 4651 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4652 | DAG.getIntPtrConstant(NumElts)); |
| 4653 | ShuffleSrcs[i] = DAG.getNode(ARMISD::VEXT, dl, VT, VEXTSrc1, VEXTSrc2, |
| 4654 | DAG.getConstant(VEXTOffsets[i], MVT::i32)); |
| 4655 | } |
| 4656 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4657 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4658 | SmallVector<int, 8> Mask; |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4659 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4660 | for (unsigned i = 0; i < NumElts; ++i) { |
| 4661 | SDValue Entry = Op.getOperand(i); |
| 4662 | if (Entry.getOpcode() == ISD::UNDEF) { |
| 4663 | Mask.push_back(-1); |
| 4664 | continue; |
| 4665 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4666 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4667 | SDValue ExtractVec = Entry.getOperand(0); |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4668 | int ExtractElt = cast<ConstantSDNode>(Op.getOperand(i) |
| 4669 | .getOperand(1))->getSExtValue(); |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4670 | if (ExtractVec == SourceVecs[0]) { |
| 4671 | Mask.push_back(ExtractElt - VEXTOffsets[0]); |
| 4672 | } else { |
| 4673 | Mask.push_back(ExtractElt + NumElts - VEXTOffsets[1]); |
| 4674 | } |
| 4675 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4676 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4677 | // Final check before we try to produce nonsense... |
| 4678 | if (isShuffleMaskLegal(Mask, VT)) |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4679 | return DAG.getVectorShuffle(VT, dl, ShuffleSrcs[0], ShuffleSrcs[1], |
| 4680 | &Mask[0]); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4681 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4682 | return SDValue(); |
| 4683 | } |
| 4684 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4685 | /// isShuffleMaskLegal - Targets can use this to indicate that they only |
| 4686 | /// support *some* VECTOR_SHUFFLE operations, those with specific masks. |
| 4687 | /// By default, if a target supports the VECTOR_SHUFFLE node, all mask values |
| 4688 | /// are assumed to be legal. |
| 4689 | bool |
| 4690 | ARMTargetLowering::isShuffleMaskLegal(const SmallVectorImpl<int> &M, |
| 4691 | EVT VT) const { |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4692 | if (VT.getVectorNumElements() == 4 && |
| 4693 | (VT.is128BitVector() || VT.is64BitVector())) { |
| 4694 | unsigned PFIndexes[4]; |
| 4695 | for (unsigned i = 0; i != 4; ++i) { |
| 4696 | if (M[i] < 0) |
| 4697 | PFIndexes[i] = 8; |
| 4698 | else |
| 4699 | PFIndexes[i] = M[i]; |
| 4700 | } |
| 4701 | |
| 4702 | // Compute the index in the perfect shuffle table. |
| 4703 | unsigned PFTableIndex = |
| 4704 | PFIndexes[0]*9*9*9+PFIndexes[1]*9*9+PFIndexes[2]*9+PFIndexes[3]; |
| 4705 | unsigned PFEntry = PerfectShuffleTable[PFTableIndex]; |
| 4706 | unsigned Cost = (PFEntry >> 30); |
| 4707 | |
| 4708 | if (Cost <= 4) |
| 4709 | return true; |
| 4710 | } |
| 4711 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4712 | bool ReverseVEXT; |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4713 | unsigned Imm, WhichResult; |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4714 | |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4715 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 4716 | return (EltSize >= 32 || |
| 4717 | ShuffleVectorSDNode::isSplatMask(&M[0], VT) || |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4718 | isVREVMask(M, VT, 64) || |
| 4719 | isVREVMask(M, VT, 32) || |
| 4720 | isVREVMask(M, VT, 16) || |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4721 | isVEXTMask(M, VT, ReverseVEXT, Imm) || |
Bill Wendling | 0d4c9d9 | 2011-03-15 21:15:20 +0000 | [diff] [blame] | 4722 | isVTBLMask(M, VT) || |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4723 | isVTRNMask(M, VT, WhichResult) || |
| 4724 | isVUZPMask(M, VT, WhichResult) || |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4725 | isVZIPMask(M, VT, WhichResult) || |
| 4726 | isVTRN_v_undef_Mask(M, VT, WhichResult) || |
| 4727 | isVUZP_v_undef_Mask(M, VT, WhichResult) || |
Arnold Schwaighofer | d9316da | 2013-02-12 01:58:32 +0000 | [diff] [blame] | 4728 | isVZIP_v_undef_Mask(M, VT, WhichResult) || |
| 4729 | ((VT == MVT::v8i16 || VT == MVT::v16i8) && isReverseMask(M, VT))); |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4730 | } |
| 4731 | |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4732 | /// GeneratePerfectShuffle - Given an entry in the perfect-shuffle table, emit |
| 4733 | /// the specified operations to build the shuffle. |
| 4734 | static SDValue GeneratePerfectShuffle(unsigned PFEntry, SDValue LHS, |
| 4735 | SDValue RHS, SelectionDAG &DAG, |
| 4736 | DebugLoc dl) { |
| 4737 | unsigned OpNum = (PFEntry >> 26) & 0x0F; |
| 4738 | unsigned LHSID = (PFEntry >> 13) & ((1 << 13)-1); |
| 4739 | unsigned RHSID = (PFEntry >> 0) & ((1 << 13)-1); |
| 4740 | |
| 4741 | enum { |
| 4742 | OP_COPY = 0, // Copy, used for things like <u,u,u,3> to say it is <0,1,2,3> |
| 4743 | OP_VREV, |
| 4744 | OP_VDUP0, |
| 4745 | OP_VDUP1, |
| 4746 | OP_VDUP2, |
| 4747 | OP_VDUP3, |
| 4748 | OP_VEXT1, |
| 4749 | OP_VEXT2, |
| 4750 | OP_VEXT3, |
| 4751 | OP_VUZPL, // VUZP, left result |
| 4752 | OP_VUZPR, // VUZP, right result |
| 4753 | OP_VZIPL, // VZIP, left result |
| 4754 | OP_VZIPR, // VZIP, right result |
| 4755 | OP_VTRNL, // VTRN, left result |
| 4756 | OP_VTRNR // VTRN, right result |
| 4757 | }; |
| 4758 | |
| 4759 | if (OpNum == OP_COPY) { |
| 4760 | if (LHSID == (1*9+2)*9+3) return LHS; |
| 4761 | assert(LHSID == ((4*9+5)*9+6)*9+7 && "Illegal OP_COPY!"); |
| 4762 | return RHS; |
| 4763 | } |
| 4764 | |
| 4765 | SDValue OpLHS, OpRHS; |
| 4766 | OpLHS = GeneratePerfectShuffle(PerfectShuffleTable[LHSID], LHS, RHS, DAG, dl); |
| 4767 | OpRHS = GeneratePerfectShuffle(PerfectShuffleTable[RHSID], LHS, RHS, DAG, dl); |
| 4768 | EVT VT = OpLHS.getValueType(); |
| 4769 | |
| 4770 | switch (OpNum) { |
| 4771 | default: llvm_unreachable("Unknown shuffle opcode!"); |
| 4772 | case OP_VREV: |
Tanya Lattner | 2a8eb72 | 2011-05-18 06:42:21 +0000 | [diff] [blame] | 4773 | // VREV divides the vector in half and swaps within the half. |
Tanya Lattner | db28247 | 2011-05-18 21:44:54 +0000 | [diff] [blame] | 4774 | if (VT.getVectorElementType() == MVT::i32 || |
| 4775 | VT.getVectorElementType() == MVT::f32) |
Tanya Lattner | 2a8eb72 | 2011-05-18 06:42:21 +0000 | [diff] [blame] | 4776 | return DAG.getNode(ARMISD::VREV64, dl, VT, OpLHS); |
| 4777 | // vrev <4 x i16> -> VREV32 |
| 4778 | if (VT.getVectorElementType() == MVT::i16) |
| 4779 | return DAG.getNode(ARMISD::VREV32, dl, VT, OpLHS); |
| 4780 | // vrev <4 x i8> -> VREV16 |
| 4781 | assert(VT.getVectorElementType() == MVT::i8); |
| 4782 | return DAG.getNode(ARMISD::VREV16, dl, VT, OpLHS); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4783 | case OP_VDUP0: |
| 4784 | case OP_VDUP1: |
| 4785 | case OP_VDUP2: |
| 4786 | case OP_VDUP3: |
| 4787 | return DAG.getNode(ARMISD::VDUPLANE, dl, VT, |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 4788 | OpLHS, DAG.getConstant(OpNum-OP_VDUP0, MVT::i32)); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4789 | case OP_VEXT1: |
| 4790 | case OP_VEXT2: |
| 4791 | case OP_VEXT3: |
| 4792 | return DAG.getNode(ARMISD::VEXT, dl, VT, |
| 4793 | OpLHS, OpRHS, |
| 4794 | DAG.getConstant(OpNum-OP_VEXT1+1, MVT::i32)); |
| 4795 | case OP_VUZPL: |
| 4796 | case OP_VUZPR: |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 4797 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4798 | OpLHS, OpRHS).getValue(OpNum-OP_VUZPL); |
| 4799 | case OP_VZIPL: |
| 4800 | case OP_VZIPR: |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 4801 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4802 | OpLHS, OpRHS).getValue(OpNum-OP_VZIPL); |
| 4803 | case OP_VTRNL: |
| 4804 | case OP_VTRNR: |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 4805 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), |
| 4806 | OpLHS, OpRHS).getValue(OpNum-OP_VTRNL); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4807 | } |
| 4808 | } |
| 4809 | |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4810 | static SDValue LowerVECTOR_SHUFFLEv8i8(SDValue Op, |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4811 | ArrayRef<int> ShuffleMask, |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4812 | SelectionDAG &DAG) { |
| 4813 | // Check to see if we can use the VTBL instruction. |
| 4814 | SDValue V1 = Op.getOperand(0); |
| 4815 | SDValue V2 = Op.getOperand(1); |
| 4816 | DebugLoc DL = Op.getDebugLoc(); |
| 4817 | |
| 4818 | SmallVector<SDValue, 8> VTBLMask; |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4819 | for (ArrayRef<int>::iterator |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4820 | I = ShuffleMask.begin(), E = ShuffleMask.end(); I != E; ++I) |
| 4821 | VTBLMask.push_back(DAG.getConstant(*I, MVT::i32)); |
| 4822 | |
| 4823 | if (V2.getNode()->getOpcode() == ISD::UNDEF) |
| 4824 | return DAG.getNode(ARMISD::VTBL1, DL, MVT::v8i8, V1, |
| 4825 | DAG.getNode(ISD::BUILD_VECTOR, DL, MVT::v8i8, |
| 4826 | &VTBLMask[0], 8)); |
Bill Wendling | a24cb40 | 2011-03-15 20:47:26 +0000 | [diff] [blame] | 4827 | |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4828 | return DAG.getNode(ARMISD::VTBL2, DL, MVT::v8i8, V1, V2, |
Bill Wendling | a24cb40 | 2011-03-15 20:47:26 +0000 | [diff] [blame] | 4829 | DAG.getNode(ISD::BUILD_VECTOR, DL, MVT::v8i8, |
| 4830 | &VTBLMask[0], 8)); |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4831 | } |
| 4832 | |
Arnold Schwaighofer | d9316da | 2013-02-12 01:58:32 +0000 | [diff] [blame] | 4833 | static SDValue LowerReverse_VECTOR_SHUFFLEv16i8_v8i16(SDValue Op, |
| 4834 | SelectionDAG &DAG) { |
| 4835 | DebugLoc DL = Op.getDebugLoc(); |
| 4836 | SDValue OpLHS = Op.getOperand(0); |
| 4837 | EVT VT = OpLHS.getValueType(); |
| 4838 | |
| 4839 | assert((VT == MVT::v8i16 || VT == MVT::v16i8) && |
| 4840 | "Expect an v8i16/v16i8 type"); |
| 4841 | OpLHS = DAG.getNode(ARMISD::VREV64, DL, VT, OpLHS); |
| 4842 | // For a v16i8 type: After the VREV, we have got <8, ...15, 8, ..., 0>. Now, |
| 4843 | // extract the first 8 bytes into the top double word and the last 8 bytes |
| 4844 | // into the bottom double word. The v8i16 case is similar. |
| 4845 | unsigned ExtractNum = (VT == MVT::v16i8) ? 8 : 4; |
| 4846 | return DAG.getNode(ARMISD::VEXT, DL, VT, OpLHS, OpLHS, |
| 4847 | DAG.getConstant(ExtractNum, MVT::i32)); |
| 4848 | } |
| 4849 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4850 | static SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) { |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4851 | SDValue V1 = Op.getOperand(0); |
| 4852 | SDValue V2 = Op.getOperand(1); |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 4853 | DebugLoc dl = Op.getDebugLoc(); |
| 4854 | EVT VT = Op.getValueType(); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4855 | ShuffleVectorSDNode *SVN = cast<ShuffleVectorSDNode>(Op.getNode()); |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 4856 | |
Bob Wilson | 2886506 | 2009-08-13 02:13:04 +0000 | [diff] [blame] | 4857 | // Convert shuffles that are directly supported on NEON to target-specific |
| 4858 | // DAG nodes, instead of keeping them as shuffles and matching them again |
| 4859 | // during code selection. This is more efficient and avoids the possibility |
| 4860 | // of inconsistencies between legalization and selection. |
Bob Wilson | bfcbb50 | 2009-08-13 06:01:30 +0000 | [diff] [blame] | 4861 | // FIXME: floating-point vectors should be canonicalized to integer vectors |
| 4862 | // of the same time so that they get CSEd properly. |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4863 | ArrayRef<int> ShuffleMask = SVN->getMask(); |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4864 | |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4865 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 4866 | if (EltSize <= 32) { |
| 4867 | if (ShuffleVectorSDNode::isSplatMask(&ShuffleMask[0], VT)) { |
| 4868 | int Lane = SVN->getSplatIndex(); |
| 4869 | // If this is undef splat, generate it via "just" vdup, if possible. |
| 4870 | if (Lane == -1) Lane = 0; |
Anton Korobeynikov | 2ae0eec | 2009-11-02 00:12:06 +0000 | [diff] [blame] | 4871 | |
Dan Gohman | 65fd656 | 2011-11-03 21:49:52 +0000 | [diff] [blame] | 4872 | // Test if V1 is a SCALAR_TO_VECTOR. |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4873 | if (Lane == 0 && V1.getOpcode() == ISD::SCALAR_TO_VECTOR) { |
| 4874 | return DAG.getNode(ARMISD::VDUP, dl, VT, V1.getOperand(0)); |
| 4875 | } |
Dan Gohman | 65fd656 | 2011-11-03 21:49:52 +0000 | [diff] [blame] | 4876 | // Test if V1 is a BUILD_VECTOR which is equivalent to a SCALAR_TO_VECTOR |
| 4877 | // (and probably will turn into a SCALAR_TO_VECTOR once legalization |
| 4878 | // reaches it). |
| 4879 | if (Lane == 0 && V1.getOpcode() == ISD::BUILD_VECTOR && |
| 4880 | !isa<ConstantSDNode>(V1.getOperand(0))) { |
| 4881 | bool IsScalarToVector = true; |
| 4882 | for (unsigned i = 1, e = V1.getNumOperands(); i != e; ++i) |
| 4883 | if (V1.getOperand(i).getOpcode() != ISD::UNDEF) { |
| 4884 | IsScalarToVector = false; |
| 4885 | break; |
| 4886 | } |
| 4887 | if (IsScalarToVector) |
| 4888 | return DAG.getNode(ARMISD::VDUP, dl, VT, V1.getOperand(0)); |
| 4889 | } |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4890 | return DAG.getNode(ARMISD::VDUPLANE, dl, VT, V1, |
| 4891 | DAG.getConstant(Lane, MVT::i32)); |
Bob Wilson | c1d287b | 2009-08-14 05:13:08 +0000 | [diff] [blame] | 4892 | } |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4893 | |
| 4894 | bool ReverseVEXT; |
| 4895 | unsigned Imm; |
| 4896 | if (isVEXTMask(ShuffleMask, VT, ReverseVEXT, Imm)) { |
| 4897 | if (ReverseVEXT) |
| 4898 | std::swap(V1, V2); |
| 4899 | return DAG.getNode(ARMISD::VEXT, dl, VT, V1, V2, |
| 4900 | DAG.getConstant(Imm, MVT::i32)); |
| 4901 | } |
| 4902 | |
| 4903 | if (isVREVMask(ShuffleMask, VT, 64)) |
| 4904 | return DAG.getNode(ARMISD::VREV64, dl, VT, V1); |
| 4905 | if (isVREVMask(ShuffleMask, VT, 32)) |
| 4906 | return DAG.getNode(ARMISD::VREV32, dl, VT, V1); |
| 4907 | if (isVREVMask(ShuffleMask, VT, 16)) |
| 4908 | return DAG.getNode(ARMISD::VREV16, dl, VT, V1); |
| 4909 | |
Quentin Colombet | 43934ae | 2012-11-02 21:32:17 +0000 | [diff] [blame] | 4910 | if (V2->getOpcode() == ISD::UNDEF && |
| 4911 | isSingletonVEXTMask(ShuffleMask, VT, Imm)) { |
| 4912 | return DAG.getNode(ARMISD::VEXT, dl, VT, V1, V1, |
| 4913 | DAG.getConstant(Imm, MVT::i32)); |
| 4914 | } |
| 4915 | |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4916 | // Check for Neon shuffles that modify both input vectors in place. |
| 4917 | // If both results are used, i.e., if there are two shuffles with the same |
| 4918 | // source operands and with masks corresponding to both results of one of |
| 4919 | // these operations, DAG memoization will ensure that a single node is |
| 4920 | // used for both shuffles. |
| 4921 | unsigned WhichResult; |
| 4922 | if (isVTRNMask(ShuffleMask, VT, WhichResult)) |
| 4923 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), |
| 4924 | V1, V2).getValue(WhichResult); |
| 4925 | if (isVUZPMask(ShuffleMask, VT, WhichResult)) |
| 4926 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), |
| 4927 | V1, V2).getValue(WhichResult); |
| 4928 | if (isVZIPMask(ShuffleMask, VT, WhichResult)) |
| 4929 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), |
| 4930 | V1, V2).getValue(WhichResult); |
| 4931 | |
| 4932 | if (isVTRN_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 4933 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), |
| 4934 | V1, V1).getValue(WhichResult); |
| 4935 | if (isVUZP_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 4936 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), |
| 4937 | V1, V1).getValue(WhichResult); |
| 4938 | if (isVZIP_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 4939 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), |
| 4940 | V1, V1).getValue(WhichResult); |
Bob Wilson | 0ce3710 | 2009-08-14 05:08:32 +0000 | [diff] [blame] | 4941 | } |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 4942 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4943 | // If the shuffle is not directly supported and it has 4 elements, use |
| 4944 | // the PerfectShuffle-generated table to synthesize it from other shuffles. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4945 | unsigned NumElts = VT.getVectorNumElements(); |
| 4946 | if (NumElts == 4) { |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4947 | unsigned PFIndexes[4]; |
| 4948 | for (unsigned i = 0; i != 4; ++i) { |
| 4949 | if (ShuffleMask[i] < 0) |
| 4950 | PFIndexes[i] = 8; |
| 4951 | else |
| 4952 | PFIndexes[i] = ShuffleMask[i]; |
| 4953 | } |
| 4954 | |
| 4955 | // Compute the index in the perfect shuffle table. |
| 4956 | unsigned PFTableIndex = |
| 4957 | 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] | 4958 | unsigned PFEntry = PerfectShuffleTable[PFTableIndex]; |
| 4959 | unsigned Cost = (PFEntry >> 30); |
| 4960 | |
| 4961 | if (Cost <= 4) |
| 4962 | return GeneratePerfectShuffle(PFEntry, V1, V2, DAG, dl); |
| 4963 | } |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 4964 | |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4965 | // Implement shuffles with 32- or 64-bit elements as ARMISD::BUILD_VECTORs. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4966 | if (EltSize >= 32) { |
| 4967 | // Do the expansion with floating-point types, since that is what the VFP |
| 4968 | // registers are defined to use, and since i64 is not legal. |
| 4969 | EVT EltVT = EVT::getFloatingPointVT(EltSize); |
| 4970 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), EltVT, NumElts); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4971 | V1 = DAG.getNode(ISD::BITCAST, dl, VecVT, V1); |
| 4972 | V2 = DAG.getNode(ISD::BITCAST, dl, VecVT, V2); |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4973 | SmallVector<SDValue, 8> Ops; |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4974 | for (unsigned i = 0; i < NumElts; ++i) { |
Bob Wilson | 63b8845 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 4975 | if (ShuffleMask[i] < 0) |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4976 | Ops.push_back(DAG.getUNDEF(EltVT)); |
| 4977 | else |
| 4978 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, EltVT, |
| 4979 | ShuffleMask[i] < (int)NumElts ? V1 : V2, |
| 4980 | DAG.getConstant(ShuffleMask[i] & (NumElts-1), |
| 4981 | MVT::i32))); |
Bob Wilson | 63b8845 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 4982 | } |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4983 | SDValue Val = DAG.getNode(ARMISD::BUILD_VECTOR, dl, VecVT, &Ops[0],NumElts); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4984 | return DAG.getNode(ISD::BITCAST, dl, VT, Val); |
Bob Wilson | 63b8845 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 4985 | } |
| 4986 | |
Arnold Schwaighofer | d9316da | 2013-02-12 01:58:32 +0000 | [diff] [blame] | 4987 | if ((VT == MVT::v8i16 || VT == MVT::v16i8) && isReverseMask(ShuffleMask, VT)) |
| 4988 | return LowerReverse_VECTOR_SHUFFLEv16i8_v8i16(Op, DAG); |
| 4989 | |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4990 | if (VT == MVT::v8i8) { |
| 4991 | SDValue NewOp = LowerVECTOR_SHUFFLEv8i8(Op, ShuffleMask, DAG); |
| 4992 | if (NewOp.getNode()) |
| 4993 | return NewOp; |
| 4994 | } |
| 4995 | |
Bob Wilson | 22cac0d | 2009-08-14 05:16:33 +0000 | [diff] [blame] | 4996 | return SDValue(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4997 | } |
| 4998 | |
Eli Friedman | 5c89cb8 | 2011-10-24 23:08:52 +0000 | [diff] [blame] | 4999 | static SDValue LowerINSERT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) { |
| 5000 | // INSERT_VECTOR_ELT is legal only for immediate indexes. |
| 5001 | SDValue Lane = Op.getOperand(2); |
| 5002 | if (!isa<ConstantSDNode>(Lane)) |
| 5003 | return SDValue(); |
| 5004 | |
| 5005 | return Op; |
| 5006 | } |
| 5007 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5008 | static SDValue LowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) { |
Bob Wilson | 3468c2e | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 5009 | // EXTRACT_VECTOR_ELT is legal only for immediate indexes. |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5010 | SDValue Lane = Op.getOperand(1); |
Bob Wilson | 3468c2e | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 5011 | if (!isa<ConstantSDNode>(Lane)) |
| 5012 | return SDValue(); |
| 5013 | |
| 5014 | SDValue Vec = Op.getOperand(0); |
| 5015 | if (Op.getValueType() == MVT::i32 && |
| 5016 | Vec.getValueType().getVectorElementType().getSizeInBits() < 32) { |
| 5017 | DebugLoc dl = Op.getDebugLoc(); |
| 5018 | return DAG.getNode(ARMISD::VGETLANEu, dl, MVT::i32, Vec, Lane); |
| 5019 | } |
| 5020 | |
| 5021 | return Op; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5022 | } |
| 5023 | |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 5024 | static SDValue LowerCONCAT_VECTORS(SDValue Op, SelectionDAG &DAG) { |
| 5025 | // The only time a CONCAT_VECTORS operation can have legal types is when |
| 5026 | // two 64-bit vectors are concatenated to a 128-bit vector. |
| 5027 | assert(Op.getValueType().is128BitVector() && Op.getNumOperands() == 2 && |
| 5028 | "unexpected CONCAT_VECTORS"); |
| 5029 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 5030 | SDValue Val = DAG.getUNDEF(MVT::v2f64); |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 5031 | SDValue Op0 = Op.getOperand(0); |
| 5032 | SDValue Op1 = Op.getOperand(1); |
| 5033 | if (Op0.getOpcode() != ISD::UNDEF) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 5034 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Val, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5035 | DAG.getNode(ISD::BITCAST, dl, MVT::f64, Op0), |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 5036 | DAG.getIntPtrConstant(0)); |
| 5037 | if (Op1.getOpcode() != ISD::UNDEF) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 5038 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Val, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5039 | DAG.getNode(ISD::BITCAST, dl, MVT::f64, Op1), |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 5040 | DAG.getIntPtrConstant(1)); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5041 | return DAG.getNode(ISD::BITCAST, dl, Op.getValueType(), Val); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5042 | } |
| 5043 | |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 5044 | /// isExtendedBUILD_VECTOR - Check if N is a constant BUILD_VECTOR where each |
| 5045 | /// element has been zero/sign-extended, depending on the isSigned parameter, |
| 5046 | /// from an integer type half its size. |
| 5047 | static bool isExtendedBUILD_VECTOR(SDNode *N, SelectionDAG &DAG, |
| 5048 | bool isSigned) { |
| 5049 | // A v2i64 BUILD_VECTOR will have been legalized to a BITCAST from v4i32. |
| 5050 | EVT VT = N->getValueType(0); |
| 5051 | if (VT == MVT::v2i64 && N->getOpcode() == ISD::BITCAST) { |
| 5052 | SDNode *BVN = N->getOperand(0).getNode(); |
| 5053 | if (BVN->getValueType(0) != MVT::v4i32 || |
| 5054 | BVN->getOpcode() != ISD::BUILD_VECTOR) |
| 5055 | return false; |
| 5056 | unsigned LoElt = DAG.getTargetLoweringInfo().isBigEndian() ? 1 : 0; |
| 5057 | unsigned HiElt = 1 - LoElt; |
| 5058 | ConstantSDNode *Lo0 = dyn_cast<ConstantSDNode>(BVN->getOperand(LoElt)); |
| 5059 | ConstantSDNode *Hi0 = dyn_cast<ConstantSDNode>(BVN->getOperand(HiElt)); |
| 5060 | ConstantSDNode *Lo1 = dyn_cast<ConstantSDNode>(BVN->getOperand(LoElt+2)); |
| 5061 | ConstantSDNode *Hi1 = dyn_cast<ConstantSDNode>(BVN->getOperand(HiElt+2)); |
| 5062 | if (!Lo0 || !Hi0 || !Lo1 || !Hi1) |
| 5063 | return false; |
| 5064 | if (isSigned) { |
| 5065 | if (Hi0->getSExtValue() == Lo0->getSExtValue() >> 32 && |
| 5066 | Hi1->getSExtValue() == Lo1->getSExtValue() >> 32) |
| 5067 | return true; |
| 5068 | } else { |
| 5069 | if (Hi0->isNullValue() && Hi1->isNullValue()) |
| 5070 | return true; |
| 5071 | } |
| 5072 | return false; |
| 5073 | } |
| 5074 | |
| 5075 | if (N->getOpcode() != ISD::BUILD_VECTOR) |
| 5076 | return false; |
| 5077 | |
| 5078 | for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) { |
| 5079 | SDNode *Elt = N->getOperand(i).getNode(); |
| 5080 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Elt)) { |
| 5081 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 5082 | unsigned HalfSize = EltSize / 2; |
| 5083 | if (isSigned) { |
Bob Wilson | 9d45de2 | 2011-10-18 18:46:49 +0000 | [diff] [blame] | 5084 | if (!isIntN(HalfSize, C->getSExtValue())) |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 5085 | return false; |
| 5086 | } else { |
Bob Wilson | 9d45de2 | 2011-10-18 18:46:49 +0000 | [diff] [blame] | 5087 | if (!isUIntN(HalfSize, C->getZExtValue())) |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 5088 | return false; |
| 5089 | } |
| 5090 | continue; |
| 5091 | } |
| 5092 | return false; |
| 5093 | } |
| 5094 | |
| 5095 | return true; |
| 5096 | } |
| 5097 | |
| 5098 | /// isSignExtended - Check if a node is a vector value that is sign-extended |
| 5099 | /// or a constant BUILD_VECTOR with sign-extended elements. |
| 5100 | static bool isSignExtended(SDNode *N, SelectionDAG &DAG) { |
| 5101 | if (N->getOpcode() == ISD::SIGN_EXTEND || ISD::isSEXTLoad(N)) |
| 5102 | return true; |
| 5103 | if (isExtendedBUILD_VECTOR(N, DAG, true)) |
| 5104 | return true; |
| 5105 | return false; |
| 5106 | } |
| 5107 | |
| 5108 | /// isZeroExtended - Check if a node is a vector value that is zero-extended |
| 5109 | /// or a constant BUILD_VECTOR with zero-extended elements. |
| 5110 | static bool isZeroExtended(SDNode *N, SelectionDAG &DAG) { |
| 5111 | if (N->getOpcode() == ISD::ZERO_EXTEND || ISD::isZEXTLoad(N)) |
| 5112 | return true; |
| 5113 | if (isExtendedBUILD_VECTOR(N, DAG, false)) |
| 5114 | return true; |
| 5115 | return false; |
| 5116 | } |
| 5117 | |
Sebastian Pop | cb49530 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 5118 | /// AddRequiredExtensionForVMULL - Add a sign/zero extension to extend the total |
| 5119 | /// value size to 64 bits. We need a 64-bit D register as an operand to VMULL. |
| 5120 | /// We insert the required extension here to get the vector to fill a D register. |
| 5121 | static SDValue AddRequiredExtensionForVMULL(SDValue N, SelectionDAG &DAG, |
| 5122 | const EVT &OrigTy, |
| 5123 | const EVT &ExtTy, |
| 5124 | unsigned ExtOpcode) { |
| 5125 | // The vector originally had a size of OrigTy. It was then extended to ExtTy. |
| 5126 | // We expect the ExtTy to be 128-bits total. If the OrigTy is less than |
| 5127 | // 64-bits we need to insert a new extension so that it will be 64-bits. |
| 5128 | assert(ExtTy.is128BitVector() && "Unexpected extension size"); |
| 5129 | if (OrigTy.getSizeInBits() >= 64) |
| 5130 | return N; |
| 5131 | |
| 5132 | // Must extend size to at least 64 bits to be used as an operand for VMULL. |
| 5133 | MVT::SimpleValueType OrigSimpleTy = OrigTy.getSimpleVT().SimpleTy; |
| 5134 | EVT NewVT; |
| 5135 | switch (OrigSimpleTy) { |
| 5136 | default: llvm_unreachable("Unexpected Orig Vector Type"); |
| 5137 | case MVT::v2i8: |
| 5138 | case MVT::v2i16: |
| 5139 | NewVT = MVT::v2i32; |
| 5140 | break; |
| 5141 | case MVT::v4i8: |
| 5142 | NewVT = MVT::v4i16; |
| 5143 | break; |
| 5144 | } |
| 5145 | return DAG.getNode(ExtOpcode, N->getDebugLoc(), NewVT, N); |
| 5146 | } |
| 5147 | |
| 5148 | /// SkipLoadExtensionForVMULL - return a load of the original vector size that |
| 5149 | /// does not do any sign/zero extension. If the original vector is less |
| 5150 | /// than 64 bits, an appropriate extension will be added after the load to |
| 5151 | /// reach a total size of 64 bits. We have to add the extension separately |
| 5152 | /// because ARM does not have a sign/zero extending load for vectors. |
| 5153 | static SDValue SkipLoadExtensionForVMULL(LoadSDNode *LD, SelectionDAG& DAG) { |
| 5154 | SDValue NonExtendingLoad = |
| 5155 | DAG.getLoad(LD->getMemoryVT(), LD->getDebugLoc(), LD->getChain(), |
| 5156 | LD->getBasePtr(), LD->getPointerInfo(), LD->isVolatile(), |
| 5157 | LD->isNonTemporal(), LD->isInvariant(), |
| 5158 | LD->getAlignment()); |
| 5159 | unsigned ExtOp = 0; |
| 5160 | switch (LD->getExtensionType()) { |
| 5161 | default: llvm_unreachable("Unexpected LoadExtType"); |
| 5162 | case ISD::EXTLOAD: |
| 5163 | case ISD::SEXTLOAD: ExtOp = ISD::SIGN_EXTEND; break; |
| 5164 | case ISD::ZEXTLOAD: ExtOp = ISD::ZERO_EXTEND; break; |
| 5165 | } |
| 5166 | MVT::SimpleValueType MemType = LD->getMemoryVT().getSimpleVT().SimpleTy; |
| 5167 | MVT::SimpleValueType ExtType = LD->getValueType(0).getSimpleVT().SimpleTy; |
| 5168 | return AddRequiredExtensionForVMULL(NonExtendingLoad, DAG, |
| 5169 | MemType, ExtType, ExtOp); |
| 5170 | } |
| 5171 | |
| 5172 | /// SkipExtensionForVMULL - For a node that is a SIGN_EXTEND, ZERO_EXTEND, |
| 5173 | /// extending load, or BUILD_VECTOR with extended elements, return the |
| 5174 | /// unextended value. The unextended vector should be 64 bits so that it can |
| 5175 | /// be used as an operand to a VMULL instruction. If the original vector size |
| 5176 | /// before extension is less than 64 bits we add a an extension to resize |
| 5177 | /// the vector to 64 bits. |
| 5178 | static SDValue SkipExtensionForVMULL(SDNode *N, SelectionDAG &DAG) { |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 5179 | if (N->getOpcode() == ISD::SIGN_EXTEND || N->getOpcode() == ISD::ZERO_EXTEND) |
Sebastian Pop | cb49530 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 5180 | return AddRequiredExtensionForVMULL(N->getOperand(0), DAG, |
| 5181 | N->getOperand(0)->getValueType(0), |
| 5182 | N->getValueType(0), |
| 5183 | N->getOpcode()); |
| 5184 | |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 5185 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) |
Sebastian Pop | cb49530 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 5186 | return SkipLoadExtensionForVMULL(LD, DAG); |
| 5187 | |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 5188 | // Otherwise, the value must be a BUILD_VECTOR. For v2i64, it will |
| 5189 | // have been legalized as a BITCAST from v4i32. |
| 5190 | if (N->getOpcode() == ISD::BITCAST) { |
| 5191 | SDNode *BVN = N->getOperand(0).getNode(); |
| 5192 | assert(BVN->getOpcode() == ISD::BUILD_VECTOR && |
| 5193 | BVN->getValueType(0) == MVT::v4i32 && "expected v4i32 BUILD_VECTOR"); |
| 5194 | unsigned LowElt = DAG.getTargetLoweringInfo().isBigEndian() ? 1 : 0; |
| 5195 | return DAG.getNode(ISD::BUILD_VECTOR, N->getDebugLoc(), MVT::v2i32, |
| 5196 | BVN->getOperand(LowElt), BVN->getOperand(LowElt+2)); |
| 5197 | } |
| 5198 | // Construct a new BUILD_VECTOR with elements truncated to half the size. |
| 5199 | assert(N->getOpcode() == ISD::BUILD_VECTOR && "expected BUILD_VECTOR"); |
| 5200 | EVT VT = N->getValueType(0); |
| 5201 | unsigned EltSize = VT.getVectorElementType().getSizeInBits() / 2; |
| 5202 | unsigned NumElts = VT.getVectorNumElements(); |
| 5203 | MVT TruncVT = MVT::getIntegerVT(EltSize); |
| 5204 | SmallVector<SDValue, 8> Ops; |
| 5205 | for (unsigned i = 0; i != NumElts; ++i) { |
| 5206 | ConstantSDNode *C = cast<ConstantSDNode>(N->getOperand(i)); |
| 5207 | const APInt &CInt = C->getAPIntValue(); |
Bob Wilson | ff73d8f | 2012-04-30 16:53:34 +0000 | [diff] [blame] | 5208 | // Element types smaller than 32 bits are not legal, so use i32 elements. |
| 5209 | // The values are implicitly truncated so sext vs. zext doesn't matter. |
| 5210 | Ops.push_back(DAG.getConstant(CInt.zextOrTrunc(32), MVT::i32)); |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 5211 | } |
| 5212 | return DAG.getNode(ISD::BUILD_VECTOR, N->getDebugLoc(), |
| 5213 | MVT::getVectorVT(TruncVT, NumElts), Ops.data(), NumElts); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 5214 | } |
| 5215 | |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 5216 | static bool isAddSubSExt(SDNode *N, SelectionDAG &DAG) { |
| 5217 | unsigned Opcode = N->getOpcode(); |
| 5218 | if (Opcode == ISD::ADD || Opcode == ISD::SUB) { |
| 5219 | SDNode *N0 = N->getOperand(0).getNode(); |
| 5220 | SDNode *N1 = N->getOperand(1).getNode(); |
| 5221 | return N0->hasOneUse() && N1->hasOneUse() && |
| 5222 | isSignExtended(N0, DAG) && isSignExtended(N1, DAG); |
| 5223 | } |
| 5224 | return false; |
| 5225 | } |
| 5226 | |
| 5227 | static bool isAddSubZExt(SDNode *N, SelectionDAG &DAG) { |
| 5228 | unsigned Opcode = N->getOpcode(); |
| 5229 | if (Opcode == ISD::ADD || Opcode == ISD::SUB) { |
| 5230 | SDNode *N0 = N->getOperand(0).getNode(); |
| 5231 | SDNode *N1 = N->getOperand(1).getNode(); |
| 5232 | return N0->hasOneUse() && N1->hasOneUse() && |
| 5233 | isZeroExtended(N0, DAG) && isZeroExtended(N1, DAG); |
| 5234 | } |
| 5235 | return false; |
| 5236 | } |
| 5237 | |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 5238 | static SDValue LowerMUL(SDValue Op, SelectionDAG &DAG) { |
| 5239 | // Multiplications are only custom-lowered for 128-bit vectors so that |
| 5240 | // VMULL can be detected. Otherwise v2i64 multiplications are not legal. |
| 5241 | EVT VT = Op.getValueType(); |
Sebastian Pop | cb49530 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 5242 | assert(VT.is128BitVector() && VT.isInteger() && |
| 5243 | "unexpected type for custom-lowering ISD::MUL"); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 5244 | SDNode *N0 = Op.getOperand(0).getNode(); |
| 5245 | SDNode *N1 = Op.getOperand(1).getNode(); |
| 5246 | unsigned NewOpc = 0; |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 5247 | bool isMLA = false; |
| 5248 | bool isN0SExt = isSignExtended(N0, DAG); |
| 5249 | bool isN1SExt = isSignExtended(N1, DAG); |
| 5250 | if (isN0SExt && isN1SExt) |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 5251 | NewOpc = ARMISD::VMULLs; |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 5252 | else { |
| 5253 | bool isN0ZExt = isZeroExtended(N0, DAG); |
| 5254 | bool isN1ZExt = isZeroExtended(N1, DAG); |
| 5255 | if (isN0ZExt && isN1ZExt) |
| 5256 | NewOpc = ARMISD::VMULLu; |
| 5257 | else if (isN1SExt || isN1ZExt) { |
| 5258 | // Look for (s/zext A + s/zext B) * (s/zext C). We want to turn these |
| 5259 | // into (s/zext A * s/zext C) + (s/zext B * s/zext C) |
| 5260 | if (isN1SExt && isAddSubSExt(N0, DAG)) { |
| 5261 | NewOpc = ARMISD::VMULLs; |
| 5262 | isMLA = true; |
| 5263 | } else if (isN1ZExt && isAddSubZExt(N0, DAG)) { |
| 5264 | NewOpc = ARMISD::VMULLu; |
| 5265 | isMLA = true; |
| 5266 | } else if (isN0ZExt && isAddSubZExt(N1, DAG)) { |
| 5267 | std::swap(N0, N1); |
| 5268 | NewOpc = ARMISD::VMULLu; |
| 5269 | isMLA = true; |
| 5270 | } |
| 5271 | } |
| 5272 | |
| 5273 | if (!NewOpc) { |
| 5274 | if (VT == MVT::v2i64) |
| 5275 | // Fall through to expand this. It is not legal. |
| 5276 | return SDValue(); |
| 5277 | else |
| 5278 | // Other vector multiplications are legal. |
| 5279 | return Op; |
| 5280 | } |
| 5281 | } |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 5282 | |
| 5283 | // Legalize to a VMULL instruction. |
| 5284 | DebugLoc DL = Op.getDebugLoc(); |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 5285 | SDValue Op0; |
Sebastian Pop | cb49530 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 5286 | SDValue Op1 = SkipExtensionForVMULL(N1, DAG); |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 5287 | if (!isMLA) { |
Sebastian Pop | cb49530 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 5288 | Op0 = SkipExtensionForVMULL(N0, DAG); |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 5289 | assert(Op0.getValueType().is64BitVector() && |
| 5290 | Op1.getValueType().is64BitVector() && |
| 5291 | "unexpected types for extended operands to VMULL"); |
| 5292 | return DAG.getNode(NewOpc, DL, VT, Op0, Op1); |
| 5293 | } |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 5294 | |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 5295 | // Optimizing (zext A + zext B) * C, to (VMULL A, C) + (VMULL B, C) during |
| 5296 | // isel lowering to take advantage of no-stall back to back vmul + vmla. |
| 5297 | // vmull q0, d4, d6 |
| 5298 | // vmlal q0, d5, d6 |
| 5299 | // is faster than |
| 5300 | // vaddl q0, d4, d5 |
| 5301 | // vmovl q1, d6 |
| 5302 | // vmul q0, q0, q1 |
Sebastian Pop | cb49530 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 5303 | SDValue N00 = SkipExtensionForVMULL(N0->getOperand(0).getNode(), DAG); |
| 5304 | SDValue N01 = SkipExtensionForVMULL(N0->getOperand(1).getNode(), DAG); |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 5305 | EVT Op1VT = Op1.getValueType(); |
| 5306 | return DAG.getNode(N0->getOpcode(), DL, VT, |
| 5307 | DAG.getNode(NewOpc, DL, VT, |
| 5308 | DAG.getNode(ISD::BITCAST, DL, Op1VT, N00), Op1), |
| 5309 | DAG.getNode(NewOpc, DL, VT, |
| 5310 | DAG.getNode(ISD::BITCAST, DL, Op1VT, N01), Op1)); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 5311 | } |
| 5312 | |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5313 | static SDValue |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5314 | LowerSDIV_v4i8(SDValue X, SDValue Y, DebugLoc dl, SelectionDAG &DAG) { |
| 5315 | // Convert to float |
| 5316 | // float4 xf = vcvt_f32_s32(vmovl_s16(a.lo)); |
| 5317 | // float4 yf = vcvt_f32_s32(vmovl_s16(b.lo)); |
| 5318 | X = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, X); |
| 5319 | Y = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, Y); |
| 5320 | X = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, X); |
| 5321 | Y = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, Y); |
| 5322 | // Get reciprocal estimate. |
| 5323 | // float4 recip = vrecpeq_f32(yf); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5324 | Y = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5325 | DAG.getConstant(Intrinsic::arm_neon_vrecpe, MVT::i32), Y); |
| 5326 | // Because char has a smaller range than uchar, we can actually get away |
| 5327 | // without any newton steps. This requires that we use a weird bias |
| 5328 | // of 0xb000, however (again, this has been exhaustively tested). |
| 5329 | // float4 result = as_float4(as_int4(xf*recip) + 0xb000); |
| 5330 | X = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, X, Y); |
| 5331 | X = DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, X); |
| 5332 | Y = DAG.getConstant(0xb000, MVT::i32); |
| 5333 | Y = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, Y, Y, Y, Y); |
| 5334 | X = DAG.getNode(ISD::ADD, dl, MVT::v4i32, X, Y); |
| 5335 | X = DAG.getNode(ISD::BITCAST, dl, MVT::v4f32, X); |
| 5336 | // Convert back to short. |
| 5337 | X = DAG.getNode(ISD::FP_TO_SINT, dl, MVT::v4i32, X); |
| 5338 | X = DAG.getNode(ISD::TRUNCATE, dl, MVT::v4i16, X); |
| 5339 | return X; |
| 5340 | } |
| 5341 | |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5342 | static SDValue |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5343 | LowerSDIV_v4i16(SDValue N0, SDValue N1, DebugLoc dl, SelectionDAG &DAG) { |
| 5344 | SDValue N2; |
| 5345 | // Convert to float. |
| 5346 | // float4 yf = vcvt_f32_s32(vmovl_s16(y)); |
| 5347 | // float4 xf = vcvt_f32_s32(vmovl_s16(x)); |
| 5348 | N0 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, N0); |
| 5349 | N1 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, N1); |
| 5350 | N0 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N0); |
| 5351 | N1 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5352 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5353 | // Use reciprocal estimate and one refinement step. |
| 5354 | // float4 recip = vrecpeq_f32(yf); |
| 5355 | // recip *= vrecpsq_f32(yf, recip); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5356 | N2 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5357 | DAG.getConstant(Intrinsic::arm_neon_vrecpe, MVT::i32), N1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5358 | N1 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5359 | DAG.getConstant(Intrinsic::arm_neon_vrecps, MVT::i32), |
| 5360 | N1, N2); |
| 5361 | N2 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N1, N2); |
| 5362 | // Because short has a smaller range than ushort, we can actually get away |
| 5363 | // with only a single newton step. This requires that we use a weird bias |
| 5364 | // of 89, however (again, this has been exhaustively tested). |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 5365 | // float4 result = as_float4(as_int4(xf*recip) + 0x89); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5366 | N0 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N0, N2); |
| 5367 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, N0); |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 5368 | N1 = DAG.getConstant(0x89, MVT::i32); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5369 | N1 = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, N1, N1, N1, N1); |
| 5370 | N0 = DAG.getNode(ISD::ADD, dl, MVT::v4i32, N0, N1); |
| 5371 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4f32, N0); |
| 5372 | // Convert back to integer and return. |
| 5373 | // return vmovn_s32(vcvt_s32_f32(result)); |
| 5374 | N0 = DAG.getNode(ISD::FP_TO_SINT, dl, MVT::v4i32, N0); |
| 5375 | N0 = DAG.getNode(ISD::TRUNCATE, dl, MVT::v4i16, N0); |
| 5376 | return N0; |
| 5377 | } |
| 5378 | |
| 5379 | static SDValue LowerSDIV(SDValue Op, SelectionDAG &DAG) { |
| 5380 | EVT VT = Op.getValueType(); |
| 5381 | assert((VT == MVT::v4i16 || VT == MVT::v8i8) && |
| 5382 | "unexpected type for custom-lowering ISD::SDIV"); |
| 5383 | |
| 5384 | DebugLoc dl = Op.getDebugLoc(); |
| 5385 | SDValue N0 = Op.getOperand(0); |
| 5386 | SDValue N1 = Op.getOperand(1); |
| 5387 | SDValue N2, N3; |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5388 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5389 | if (VT == MVT::v8i8) { |
| 5390 | N0 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v8i16, N0); |
| 5391 | N1 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v8i16, N1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5392 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5393 | N2 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| 5394 | DAG.getIntPtrConstant(4)); |
| 5395 | N3 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5396 | DAG.getIntPtrConstant(4)); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5397 | N0 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| 5398 | DAG.getIntPtrConstant(0)); |
| 5399 | N1 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
| 5400 | DAG.getIntPtrConstant(0)); |
| 5401 | |
| 5402 | N0 = LowerSDIV_v4i8(N0, N1, dl, DAG); // v4i16 |
| 5403 | N2 = LowerSDIV_v4i8(N2, N3, dl, DAG); // v4i16 |
| 5404 | |
| 5405 | N0 = DAG.getNode(ISD::CONCAT_VECTORS, dl, MVT::v8i16, N0, N2); |
| 5406 | N0 = LowerCONCAT_VECTORS(N0, DAG); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5407 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5408 | N0 = DAG.getNode(ISD::TRUNCATE, dl, MVT::v8i8, N0); |
| 5409 | return N0; |
| 5410 | } |
| 5411 | return LowerSDIV_v4i16(N0, N1, dl, DAG); |
| 5412 | } |
| 5413 | |
| 5414 | static SDValue LowerUDIV(SDValue Op, SelectionDAG &DAG) { |
| 5415 | EVT VT = Op.getValueType(); |
| 5416 | assert((VT == MVT::v4i16 || VT == MVT::v8i8) && |
| 5417 | "unexpected type for custom-lowering ISD::UDIV"); |
| 5418 | |
| 5419 | DebugLoc dl = Op.getDebugLoc(); |
| 5420 | SDValue N0 = Op.getOperand(0); |
| 5421 | SDValue N1 = Op.getOperand(1); |
| 5422 | SDValue N2, N3; |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5423 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5424 | if (VT == MVT::v8i8) { |
| 5425 | N0 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v8i16, N0); |
| 5426 | N1 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v8i16, N1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5427 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5428 | N2 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| 5429 | DAG.getIntPtrConstant(4)); |
| 5430 | N3 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5431 | DAG.getIntPtrConstant(4)); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5432 | N0 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| 5433 | DAG.getIntPtrConstant(0)); |
| 5434 | N1 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
| 5435 | DAG.getIntPtrConstant(0)); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5436 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5437 | N0 = LowerSDIV_v4i16(N0, N1, dl, DAG); // v4i16 |
| 5438 | N2 = LowerSDIV_v4i16(N2, N3, dl, DAG); // v4i16 |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5439 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5440 | N0 = DAG.getNode(ISD::CONCAT_VECTORS, dl, MVT::v8i16, N0, N2); |
| 5441 | N0 = LowerCONCAT_VECTORS(N0, DAG); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5442 | |
| 5443 | N0 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v8i8, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5444 | DAG.getConstant(Intrinsic::arm_neon_vqmovnsu, MVT::i32), |
| 5445 | N0); |
| 5446 | return N0; |
| 5447 | } |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5448 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5449 | // v4i16 sdiv ... Convert to float. |
| 5450 | // float4 yf = vcvt_f32_s32(vmovl_u16(y)); |
| 5451 | // float4 xf = vcvt_f32_s32(vmovl_u16(x)); |
| 5452 | N0 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v4i32, N0); |
| 5453 | N1 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v4i32, N1); |
| 5454 | N0 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N0); |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 5455 | SDValue BN1 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N1); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5456 | |
| 5457 | // Use reciprocal estimate and two refinement steps. |
| 5458 | // float4 recip = vrecpeq_f32(yf); |
| 5459 | // recip *= vrecpsq_f32(yf, recip); |
| 5460 | // recip *= vrecpsq_f32(yf, recip); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5461 | N2 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 5462 | DAG.getConstant(Intrinsic::arm_neon_vrecpe, MVT::i32), BN1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5463 | N1 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5464 | DAG.getConstant(Intrinsic::arm_neon_vrecps, MVT::i32), |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 5465 | BN1, N2); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5466 | N2 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N1, N2); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5467 | N1 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5468 | DAG.getConstant(Intrinsic::arm_neon_vrecps, MVT::i32), |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 5469 | BN1, N2); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5470 | N2 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N1, N2); |
| 5471 | // Simply multiplying by the reciprocal estimate can leave us a few ulps |
| 5472 | // too low, so we add 2 ulps (exhaustive testing shows that this is enough, |
| 5473 | // 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] | 5474 | // float4 result = as_float4(as_int4(xf*recip) + 2); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5475 | N0 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N0, N2); |
| 5476 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, N0); |
| 5477 | N1 = DAG.getConstant(2, MVT::i32); |
| 5478 | N1 = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, N1, N1, N1, N1); |
| 5479 | N0 = DAG.getNode(ISD::ADD, dl, MVT::v4i32, N0, N1); |
| 5480 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4f32, N0); |
| 5481 | // Convert back to integer and return. |
| 5482 | // return vmovn_u32(vcvt_s32_f32(result)); |
| 5483 | N0 = DAG.getNode(ISD::FP_TO_SINT, dl, MVT::v4i32, N0); |
| 5484 | N0 = DAG.getNode(ISD::TRUNCATE, dl, MVT::v4i16, N0); |
| 5485 | return N0; |
| 5486 | } |
| 5487 | |
Evan Cheng | 342e316 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 5488 | static SDValue LowerADDC_ADDE_SUBC_SUBE(SDValue Op, SelectionDAG &DAG) { |
| 5489 | EVT VT = Op.getNode()->getValueType(0); |
| 5490 | SDVTList VTs = DAG.getVTList(VT, MVT::i32); |
| 5491 | |
| 5492 | unsigned Opc; |
| 5493 | bool ExtraOp = false; |
| 5494 | switch (Op.getOpcode()) { |
Craig Topper | bc21981 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 5495 | default: llvm_unreachable("Invalid code"); |
Evan Cheng | 342e316 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 5496 | case ISD::ADDC: Opc = ARMISD::ADDC; break; |
| 5497 | case ISD::ADDE: Opc = ARMISD::ADDE; ExtraOp = true; break; |
| 5498 | case ISD::SUBC: Opc = ARMISD::SUBC; break; |
| 5499 | case ISD::SUBE: Opc = ARMISD::SUBE; ExtraOp = true; break; |
| 5500 | } |
| 5501 | |
| 5502 | if (!ExtraOp) |
| 5503 | return DAG.getNode(Opc, Op->getDebugLoc(), VTs, Op.getOperand(0), |
| 5504 | Op.getOperand(1)); |
| 5505 | return DAG.getNode(Opc, Op->getDebugLoc(), VTs, Op.getOperand(0), |
| 5506 | Op.getOperand(1), Op.getOperand(2)); |
| 5507 | } |
| 5508 | |
Eli Friedman | 74bf18c | 2011-09-15 22:26:18 +0000 | [diff] [blame] | 5509 | static SDValue LowerAtomicLoadStore(SDValue Op, SelectionDAG &DAG) { |
Eli Friedman | 7cc1566 | 2011-09-15 22:18:49 +0000 | [diff] [blame] | 5510 | // Monotonic load/store is legal for all targets |
| 5511 | if (cast<AtomicSDNode>(Op)->getOrdering() <= Monotonic) |
| 5512 | return Op; |
| 5513 | |
| 5514 | // Aquire/Release load/store is not legal for targets without a |
| 5515 | // dmb or equivalent available. |
| 5516 | return SDValue(); |
| 5517 | } |
| 5518 | |
| 5519 | |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5520 | static void |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5521 | ReplaceATOMIC_OP_64(SDNode *Node, SmallVectorImpl<SDValue>& Results, |
| 5522 | SelectionDAG &DAG, unsigned NewOp) { |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5523 | DebugLoc dl = Node->getDebugLoc(); |
Duncan Sands | 17001ce | 2011-10-18 12:44:00 +0000 | [diff] [blame] | 5524 | assert (Node->getValueType(0) == MVT::i64 && |
| 5525 | "Only know how to expand i64 atomics"); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5526 | |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5527 | SmallVector<SDValue, 6> Ops; |
| 5528 | Ops.push_back(Node->getOperand(0)); // Chain |
| 5529 | Ops.push_back(Node->getOperand(1)); // Ptr |
| 5530 | // Low part of Val1 |
| 5531 | Ops.push_back(DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, |
| 5532 | Node->getOperand(2), DAG.getIntPtrConstant(0))); |
| 5533 | // High part of Val1 |
| 5534 | Ops.push_back(DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, |
| 5535 | Node->getOperand(2), DAG.getIntPtrConstant(1))); |
Andrew Trick | 3af7a67 | 2011-09-20 03:06:13 +0000 | [diff] [blame] | 5536 | if (NewOp == ARMISD::ATOMCMPXCHG64_DAG) { |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5537 | // High part of Val1 |
| 5538 | Ops.push_back(DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, |
| 5539 | Node->getOperand(3), DAG.getIntPtrConstant(0))); |
| 5540 | // High part of Val2 |
| 5541 | Ops.push_back(DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, |
| 5542 | Node->getOperand(3), DAG.getIntPtrConstant(1))); |
| 5543 | } |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5544 | SDVTList Tys = DAG.getVTList(MVT::i32, MVT::i32, MVT::Other); |
| 5545 | SDValue Result = |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5546 | DAG.getMemIntrinsicNode(NewOp, dl, Tys, Ops.data(), Ops.size(), MVT::i64, |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5547 | cast<MemSDNode>(Node)->getMemOperand()); |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5548 | SDValue OpsF[] = { Result.getValue(0), Result.getValue(1) }; |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5549 | Results.push_back(DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, OpsF, 2)); |
| 5550 | Results.push_back(Result.getValue(2)); |
| 5551 | } |
| 5552 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 5553 | SDValue ARMTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5554 | switch (Op.getOpcode()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 5555 | default: llvm_unreachable("Don't know how to custom lower this!"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5556 | case ISD::ConstantPool: return LowerConstantPool(Op, DAG); |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 5557 | case ISD::BlockAddress: return LowerBlockAddress(Op, DAG); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 5558 | case ISD::GlobalAddress: |
| 5559 | return Subtarget->isTargetDarwin() ? LowerGlobalAddressDarwin(Op, DAG) : |
| 5560 | LowerGlobalAddressELF(Op, DAG); |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 5561 | case ISD::GlobalTLSAddress: return LowerGlobalTLSAddress(Op, DAG); |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 5562 | case ISD::SELECT: return LowerSELECT(Op, DAG); |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 5563 | case ISD::SELECT_CC: return LowerSELECT_CC(Op, DAG); |
| 5564 | case ISD::BR_CC: return LowerBR_CC(Op, DAG); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5565 | case ISD::BR_JT: return LowerBR_JT(Op, DAG); |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 5566 | case ISD::VASTART: return LowerVASTART(Op, DAG); |
Jim Grosbach | 7c03dbd | 2009-12-14 21:24:16 +0000 | [diff] [blame] | 5567 | case ISD::MEMBARRIER: return LowerMEMBARRIER(Op, DAG, Subtarget); |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 5568 | case ISD::ATOMIC_FENCE: return LowerATOMIC_FENCE(Op, DAG, Subtarget); |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 5569 | case ISD::PREFETCH: return LowerPREFETCH(Op, DAG, Subtarget); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 5570 | case ISD::SINT_TO_FP: |
| 5571 | case ISD::UINT_TO_FP: return LowerINT_TO_FP(Op, DAG); |
| 5572 | case ISD::FP_TO_SINT: |
| 5573 | case ISD::FP_TO_UINT: return LowerFP_TO_INT(Op, DAG); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5574 | case ISD::FCOPYSIGN: return LowerFCOPYSIGN(Op, DAG); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 5575 | case ISD::RETURNADDR: return LowerRETURNADDR(Op, DAG); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 5576 | case ISD::FRAMEADDR: return LowerFRAMEADDR(Op, DAG); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 5577 | case ISD::GLOBAL_OFFSET_TABLE: return LowerGLOBAL_OFFSET_TABLE(Op, DAG); |
Jim Grosbach | 23ff7cf | 2010-05-26 20:22:18 +0000 | [diff] [blame] | 5578 | case ISD::EH_SJLJ_SETJMP: return LowerEH_SJLJ_SETJMP(Op, DAG); |
Jim Grosbach | 5eb1951 | 2010-05-22 01:06:18 +0000 | [diff] [blame] | 5579 | case ISD::EH_SJLJ_LONGJMP: return LowerEH_SJLJ_LONGJMP(Op, DAG); |
Jim Grosbach | a87ded2 | 2010-02-08 23:22:00 +0000 | [diff] [blame] | 5580 | case ISD::INTRINSIC_WO_CHAIN: return LowerINTRINSIC_WO_CHAIN(Op, DAG, |
| 5581 | Subtarget); |
Evan Cheng | 21a6179 | 2011-03-14 18:02:30 +0000 | [diff] [blame] | 5582 | case ISD::BITCAST: return ExpandBITCAST(Op.getNode(), DAG); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5583 | case ISD::SHL: |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 5584 | case ISD::SRL: |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5585 | case ISD::SRA: return LowerShift(Op.getNode(), DAG, Subtarget); |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 5586 | case ISD::SHL_PARTS: return LowerShiftLeftParts(Op, DAG); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 5587 | case ISD::SRL_PARTS: |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 5588 | case ISD::SRA_PARTS: return LowerShiftRightParts(Op, DAG); |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 5589 | case ISD::CTTZ: return LowerCTTZ(Op.getNode(), DAG, Subtarget); |
Evan Cheng | c8e7045 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 5590 | case ISD::CTPOP: return LowerCTPOP(Op.getNode(), DAG, Subtarget); |
Duncan Sands | 28b77e9 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 5591 | case ISD::SETCC: return LowerVSETCC(Op, DAG); |
Lang Hames | 45b5f88 | 2012-03-15 18:49:02 +0000 | [diff] [blame] | 5592 | case ISD::ConstantFP: return LowerConstantFP(Op, DAG, Subtarget); |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 5593 | case ISD::BUILD_VECTOR: return LowerBUILD_VECTOR(Op, DAG, Subtarget); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5594 | case ISD::VECTOR_SHUFFLE: return LowerVECTOR_SHUFFLE(Op, DAG); |
Eli Friedman | 5c89cb8 | 2011-10-24 23:08:52 +0000 | [diff] [blame] | 5595 | case ISD::INSERT_VECTOR_ELT: return LowerINSERT_VECTOR_ELT(Op, DAG); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5596 | case ISD::EXTRACT_VECTOR_ELT: return LowerEXTRACT_VECTOR_ELT(Op, DAG); |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 5597 | case ISD::CONCAT_VECTORS: return LowerCONCAT_VECTORS(Op, DAG); |
Bob Wilson | b31a11b | 2010-08-20 04:54:02 +0000 | [diff] [blame] | 5598 | case ISD::FLT_ROUNDS_: return LowerFLT_ROUNDS_(Op, DAG); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 5599 | case ISD::MUL: return LowerMUL(Op, DAG); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5600 | case ISD::SDIV: return LowerSDIV(Op, DAG); |
| 5601 | case ISD::UDIV: return LowerUDIV(Op, DAG); |
Evan Cheng | 342e316 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 5602 | case ISD::ADDC: |
| 5603 | case ISD::ADDE: |
| 5604 | case ISD::SUBC: |
| 5605 | case ISD::SUBE: return LowerADDC_ADDE_SUBC_SUBE(Op, DAG); |
Eli Friedman | 7cc1566 | 2011-09-15 22:18:49 +0000 | [diff] [blame] | 5606 | case ISD::ATOMIC_LOAD: |
Eli Friedman | 74bf18c | 2011-09-15 22:26:18 +0000 | [diff] [blame] | 5607 | case ISD::ATOMIC_STORE: return LowerAtomicLoadStore(Op, DAG); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5608 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5609 | } |
| 5610 | |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 5611 | /// ReplaceNodeResults - Replace the results of node with an illegal result |
| 5612 | /// type with new values built out of custom code. |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 5613 | void ARMTargetLowering::ReplaceNodeResults(SDNode *N, |
| 5614 | SmallVectorImpl<SDValue>&Results, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 5615 | SelectionDAG &DAG) const { |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 5616 | SDValue Res; |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 5617 | switch (N->getOpcode()) { |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 5618 | default: |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 5619 | llvm_unreachable("Don't know how to custom expand this!"); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5620 | case ISD::BITCAST: |
| 5621 | Res = ExpandBITCAST(N, DAG); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 5622 | break; |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 5623 | case ISD::SRL: |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 5624 | case ISD::SRA: |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 5625 | Res = Expand64BitShift(N, DAG, Subtarget); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 5626 | break; |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5627 | case ISD::ATOMIC_LOAD_ADD: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5628 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMADD64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5629 | return; |
| 5630 | case ISD::ATOMIC_LOAD_AND: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5631 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMAND64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5632 | return; |
| 5633 | case ISD::ATOMIC_LOAD_NAND: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5634 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMNAND64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5635 | return; |
| 5636 | case ISD::ATOMIC_LOAD_OR: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5637 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMOR64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5638 | return; |
| 5639 | case ISD::ATOMIC_LOAD_SUB: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5640 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMSUB64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5641 | return; |
| 5642 | case ISD::ATOMIC_LOAD_XOR: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5643 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMXOR64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5644 | return; |
| 5645 | case ISD::ATOMIC_SWAP: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5646 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMSWAP64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5647 | return; |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5648 | case ISD::ATOMIC_CMP_SWAP: |
| 5649 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMCMPXCHG64_DAG); |
| 5650 | return; |
Silviu Baranga | 35b3df6 | 2012-11-29 14:41:25 +0000 | [diff] [blame] | 5651 | case ISD::ATOMIC_LOAD_MIN: |
| 5652 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMMIN64_DAG); |
| 5653 | return; |
| 5654 | case ISD::ATOMIC_LOAD_UMIN: |
| 5655 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMUMIN64_DAG); |
| 5656 | return; |
| 5657 | case ISD::ATOMIC_LOAD_MAX: |
| 5658 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMMAX64_DAG); |
| 5659 | return; |
| 5660 | case ISD::ATOMIC_LOAD_UMAX: |
| 5661 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMUMAX64_DAG); |
| 5662 | return; |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 5663 | } |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 5664 | if (Res.getNode()) |
| 5665 | Results.push_back(Res); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 5666 | } |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 5667 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5668 | //===----------------------------------------------------------------------===// |
| 5669 | // ARM Scheduler Hooks |
| 5670 | //===----------------------------------------------------------------------===// |
| 5671 | |
| 5672 | MachineBasicBlock * |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 5673 | ARMTargetLowering::EmitAtomicCmpSwap(MachineInstr *MI, |
| 5674 | MachineBasicBlock *BB, |
| 5675 | unsigned Size) const { |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5676 | unsigned dest = MI->getOperand(0).getReg(); |
| 5677 | unsigned ptr = MI->getOperand(1).getReg(); |
| 5678 | unsigned oldval = MI->getOperand(2).getReg(); |
| 5679 | unsigned newval = MI->getOperand(3).getReg(); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5680 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 5681 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5682 | bool isThumb2 = Subtarget->isThumb2(); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5683 | |
Cameron Zwarich | 7d336c0 | 2011-05-18 02:20:07 +0000 | [diff] [blame] | 5684 | MachineRegisterInfo &MRI = BB->getParent()->getRegInfo(); |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 5685 | unsigned scratch = MRI.createVirtualRegister(isThumb2 ? |
| 5686 | (const TargetRegisterClass*)&ARM::rGPRRegClass : |
| 5687 | (const TargetRegisterClass*)&ARM::GPRRegClass); |
Cameron Zwarich | 7d336c0 | 2011-05-18 02:20:07 +0000 | [diff] [blame] | 5688 | |
| 5689 | if (isThumb2) { |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 5690 | MRI.constrainRegClass(dest, &ARM::rGPRRegClass); |
| 5691 | MRI.constrainRegClass(oldval, &ARM::rGPRRegClass); |
| 5692 | MRI.constrainRegClass(newval, &ARM::rGPRRegClass); |
Cameron Zwarich | 7d336c0 | 2011-05-18 02:20:07 +0000 | [diff] [blame] | 5693 | } |
| 5694 | |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5695 | unsigned ldrOpc, strOpc; |
| 5696 | switch (Size) { |
| 5697 | default: llvm_unreachable("unsupported size for AtomicCmpSwap!"); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5698 | case 1: |
| 5699 | ldrOpc = isThumb2 ? ARM::t2LDREXB : ARM::LDREXB; |
Evan Cheng | aa26102 | 2011-02-07 18:50:47 +0000 | [diff] [blame] | 5700 | strOpc = isThumb2 ? ARM::t2STREXB : ARM::STREXB; |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5701 | break; |
| 5702 | case 2: |
| 5703 | ldrOpc = isThumb2 ? ARM::t2LDREXH : ARM::LDREXH; |
| 5704 | strOpc = isThumb2 ? ARM::t2STREXH : ARM::STREXH; |
| 5705 | break; |
| 5706 | case 4: |
| 5707 | ldrOpc = isThumb2 ? ARM::t2LDREX : ARM::LDREX; |
| 5708 | strOpc = isThumb2 ? ARM::t2STREX : ARM::STREX; |
| 5709 | break; |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5710 | } |
| 5711 | |
| 5712 | MachineFunction *MF = BB->getParent(); |
| 5713 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 5714 | MachineFunction::iterator It = BB; |
| 5715 | ++It; // insert the new blocks after the current block |
| 5716 | |
| 5717 | MachineBasicBlock *loop1MBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5718 | MachineBasicBlock *loop2MBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5719 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5720 | MF->insert(It, loop1MBB); |
| 5721 | MF->insert(It, loop2MBB); |
| 5722 | MF->insert(It, exitMBB); |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 5723 | |
| 5724 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 5725 | exitMBB->splice(exitMBB->begin(), BB, |
| 5726 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 5727 | BB->end()); |
| 5728 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5729 | |
| 5730 | // thisMBB: |
| 5731 | // ... |
| 5732 | // fallthrough --> loop1MBB |
| 5733 | BB->addSuccessor(loop1MBB); |
| 5734 | |
| 5735 | // loop1MBB: |
| 5736 | // ldrex dest, [ptr] |
| 5737 | // cmp dest, oldval |
| 5738 | // bne exitMBB |
| 5739 | BB = loop1MBB; |
Jim Grosbach | b6aed50 | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 5740 | MachineInstrBuilder MIB = BuildMI(BB, dl, TII->get(ldrOpc), dest).addReg(ptr); |
| 5741 | if (ldrOpc == ARM::t2LDREX) |
| 5742 | MIB.addImm(0); |
| 5743 | AddDefaultPred(MIB); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5744 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5745 | .addReg(dest).addReg(oldval)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5746 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 5747 | .addMBB(exitMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5748 | BB->addSuccessor(loop2MBB); |
| 5749 | BB->addSuccessor(exitMBB); |
| 5750 | |
| 5751 | // loop2MBB: |
| 5752 | // strex scratch, newval, [ptr] |
| 5753 | // cmp scratch, #0 |
| 5754 | // bne loop1MBB |
| 5755 | BB = loop2MBB; |
Jim Grosbach | b6aed50 | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 5756 | MIB = BuildMI(BB, dl, TII->get(strOpc), scratch).addReg(newval).addReg(ptr); |
| 5757 | if (strOpc == ARM::t2STREX) |
| 5758 | MIB.addImm(0); |
| 5759 | AddDefaultPred(MIB); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5760 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5761 | .addReg(scratch).addImm(0)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5762 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 5763 | .addMBB(loop1MBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5764 | BB->addSuccessor(loop1MBB); |
| 5765 | BB->addSuccessor(exitMBB); |
| 5766 | |
| 5767 | // exitMBB: |
| 5768 | // ... |
| 5769 | BB = exitMBB; |
Jim Grosbach | 5efaed3 | 2010-01-15 00:18:34 +0000 | [diff] [blame] | 5770 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 5771 | MI->eraseFromParent(); // The instruction is gone now. |
Jim Grosbach | 5efaed3 | 2010-01-15 00:18:34 +0000 | [diff] [blame] | 5772 | |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5773 | return BB; |
| 5774 | } |
| 5775 | |
| 5776 | MachineBasicBlock * |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 5777 | ARMTargetLowering::EmitAtomicBinary(MachineInstr *MI, MachineBasicBlock *BB, |
| 5778 | unsigned Size, unsigned BinOpcode) const { |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5779 | // This also handles ATOMIC_SWAP, indicated by BinOpcode==0. |
| 5780 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 5781 | |
| 5782 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
Jim Grosbach | 867bbbf | 2010-01-15 00:22:18 +0000 | [diff] [blame] | 5783 | MachineFunction *MF = BB->getParent(); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5784 | MachineFunction::iterator It = BB; |
| 5785 | ++It; |
| 5786 | |
| 5787 | unsigned dest = MI->getOperand(0).getReg(); |
| 5788 | unsigned ptr = MI->getOperand(1).getReg(); |
| 5789 | unsigned incr = MI->getOperand(2).getReg(); |
| 5790 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5791 | bool isThumb2 = Subtarget->isThumb2(); |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 5792 | |
| 5793 | MachineRegisterInfo &MRI = BB->getParent()->getRegInfo(); |
| 5794 | if (isThumb2) { |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 5795 | MRI.constrainRegClass(dest, &ARM::rGPRRegClass); |
| 5796 | MRI.constrainRegClass(ptr, &ARM::rGPRRegClass); |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 5797 | } |
| 5798 | |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5799 | unsigned ldrOpc, strOpc; |
| 5800 | switch (Size) { |
| 5801 | default: llvm_unreachable("unsupported size for AtomicCmpSwap!"); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5802 | case 1: |
| 5803 | ldrOpc = isThumb2 ? ARM::t2LDREXB : ARM::LDREXB; |
Jakob Stoklund Olesen | 15913c9 | 2010-01-13 19:54:39 +0000 | [diff] [blame] | 5804 | strOpc = isThumb2 ? ARM::t2STREXB : ARM::STREXB; |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5805 | break; |
| 5806 | case 2: |
| 5807 | ldrOpc = isThumb2 ? ARM::t2LDREXH : ARM::LDREXH; |
| 5808 | strOpc = isThumb2 ? ARM::t2STREXH : ARM::STREXH; |
| 5809 | break; |
| 5810 | case 4: |
| 5811 | ldrOpc = isThumb2 ? ARM::t2LDREX : ARM::LDREX; |
| 5812 | strOpc = isThumb2 ? ARM::t2STREX : ARM::STREX; |
| 5813 | break; |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5814 | } |
| 5815 | |
Jim Grosbach | 867bbbf | 2010-01-15 00:22:18 +0000 | [diff] [blame] | 5816 | MachineBasicBlock *loopMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5817 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5818 | MF->insert(It, loopMBB); |
| 5819 | MF->insert(It, exitMBB); |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 5820 | |
| 5821 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 5822 | exitMBB->splice(exitMBB->begin(), BB, |
| 5823 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 5824 | BB->end()); |
| 5825 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5826 | |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 5827 | const TargetRegisterClass *TRC = isThumb2 ? |
Jakob Stoklund Olesen | 05e80f2 | 2012-08-31 02:08:34 +0000 | [diff] [blame] | 5828 | (const TargetRegisterClass*)&ARM::rGPRRegClass : |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 5829 | (const TargetRegisterClass*)&ARM::GPRRegClass; |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 5830 | unsigned scratch = MRI.createVirtualRegister(TRC); |
| 5831 | unsigned scratch2 = (!BinOpcode) ? incr : MRI.createVirtualRegister(TRC); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5832 | |
| 5833 | // thisMBB: |
| 5834 | // ... |
| 5835 | // fallthrough --> loopMBB |
| 5836 | BB->addSuccessor(loopMBB); |
| 5837 | |
| 5838 | // loopMBB: |
| 5839 | // ldrex dest, ptr |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5840 | // <binop> scratch2, dest, incr |
| 5841 | // strex scratch, scratch2, ptr |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5842 | // cmp scratch, #0 |
| 5843 | // bne- loopMBB |
| 5844 | // fallthrough --> exitMBB |
| 5845 | BB = loopMBB; |
Jim Grosbach | b6aed50 | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 5846 | MachineInstrBuilder MIB = BuildMI(BB, dl, TII->get(ldrOpc), dest).addReg(ptr); |
| 5847 | if (ldrOpc == ARM::t2LDREX) |
| 5848 | MIB.addImm(0); |
| 5849 | AddDefaultPred(MIB); |
Jim Grosbach | c67b556 | 2009-12-15 00:12:35 +0000 | [diff] [blame] | 5850 | if (BinOpcode) { |
| 5851 | // operand order needs to go the other way for NAND |
| 5852 | if (BinOpcode == ARM::BICrr || BinOpcode == ARM::t2BICrr) |
| 5853 | AddDefaultPred(BuildMI(BB, dl, TII->get(BinOpcode), scratch2). |
| 5854 | addReg(incr).addReg(dest)).addReg(0); |
| 5855 | else |
| 5856 | AddDefaultPred(BuildMI(BB, dl, TII->get(BinOpcode), scratch2). |
| 5857 | addReg(dest).addReg(incr)).addReg(0); |
| 5858 | } |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5859 | |
Jim Grosbach | b6aed50 | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 5860 | MIB = BuildMI(BB, dl, TII->get(strOpc), scratch).addReg(scratch2).addReg(ptr); |
| 5861 | if (strOpc == ARM::t2STREX) |
| 5862 | MIB.addImm(0); |
| 5863 | AddDefaultPred(MIB); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5864 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5865 | .addReg(scratch).addImm(0)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5866 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 5867 | .addMBB(loopMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5868 | |
| 5869 | BB->addSuccessor(loopMBB); |
| 5870 | BB->addSuccessor(exitMBB); |
| 5871 | |
| 5872 | // exitMBB: |
| 5873 | // ... |
| 5874 | BB = exitMBB; |
Evan Cheng | 102ebf1 | 2009-12-21 19:53:39 +0000 | [diff] [blame] | 5875 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 5876 | MI->eraseFromParent(); // The instruction is gone now. |
Evan Cheng | 102ebf1 | 2009-12-21 19:53:39 +0000 | [diff] [blame] | 5877 | |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5878 | return BB; |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 5879 | } |
| 5880 | |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5881 | MachineBasicBlock * |
| 5882 | ARMTargetLowering::EmitAtomicBinaryMinMax(MachineInstr *MI, |
| 5883 | MachineBasicBlock *BB, |
| 5884 | unsigned Size, |
| 5885 | bool signExtend, |
| 5886 | ARMCC::CondCodes Cond) const { |
| 5887 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 5888 | |
| 5889 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 5890 | MachineFunction *MF = BB->getParent(); |
| 5891 | MachineFunction::iterator It = BB; |
| 5892 | ++It; |
| 5893 | |
| 5894 | unsigned dest = MI->getOperand(0).getReg(); |
| 5895 | unsigned ptr = MI->getOperand(1).getReg(); |
| 5896 | unsigned incr = MI->getOperand(2).getReg(); |
| 5897 | unsigned oldval = dest; |
| 5898 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5899 | bool isThumb2 = Subtarget->isThumb2(); |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 5900 | |
| 5901 | MachineRegisterInfo &MRI = BB->getParent()->getRegInfo(); |
| 5902 | if (isThumb2) { |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 5903 | MRI.constrainRegClass(dest, &ARM::rGPRRegClass); |
| 5904 | MRI.constrainRegClass(ptr, &ARM::rGPRRegClass); |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 5905 | } |
| 5906 | |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5907 | unsigned ldrOpc, strOpc, extendOpc; |
| 5908 | switch (Size) { |
| 5909 | default: llvm_unreachable("unsupported size for AtomicCmpSwap!"); |
| 5910 | case 1: |
| 5911 | ldrOpc = isThumb2 ? ARM::t2LDREXB : ARM::LDREXB; |
| 5912 | strOpc = isThumb2 ? ARM::t2STREXB : ARM::STREXB; |
Jim Grosbach | c5a8c86 | 2011-07-27 16:47:19 +0000 | [diff] [blame] | 5913 | extendOpc = isThumb2 ? ARM::t2SXTB : ARM::SXTB; |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5914 | break; |
| 5915 | case 2: |
| 5916 | ldrOpc = isThumb2 ? ARM::t2LDREXH : ARM::LDREXH; |
| 5917 | strOpc = isThumb2 ? ARM::t2STREXH : ARM::STREXH; |
Jim Grosbach | c5a8c86 | 2011-07-27 16:47:19 +0000 | [diff] [blame] | 5918 | extendOpc = isThumb2 ? ARM::t2SXTH : ARM::SXTH; |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5919 | break; |
| 5920 | case 4: |
| 5921 | ldrOpc = isThumb2 ? ARM::t2LDREX : ARM::LDREX; |
| 5922 | strOpc = isThumb2 ? ARM::t2STREX : ARM::STREX; |
| 5923 | extendOpc = 0; |
| 5924 | break; |
| 5925 | } |
| 5926 | |
| 5927 | MachineBasicBlock *loopMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5928 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5929 | MF->insert(It, loopMBB); |
| 5930 | MF->insert(It, exitMBB); |
| 5931 | |
| 5932 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 5933 | exitMBB->splice(exitMBB->begin(), BB, |
| 5934 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 5935 | BB->end()); |
| 5936 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
| 5937 | |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 5938 | const TargetRegisterClass *TRC = isThumb2 ? |
Jakob Stoklund Olesen | 05e80f2 | 2012-08-31 02:08:34 +0000 | [diff] [blame] | 5939 | (const TargetRegisterClass*)&ARM::rGPRRegClass : |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 5940 | (const TargetRegisterClass*)&ARM::GPRRegClass; |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 5941 | unsigned scratch = MRI.createVirtualRegister(TRC); |
| 5942 | unsigned scratch2 = MRI.createVirtualRegister(TRC); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5943 | |
| 5944 | // thisMBB: |
| 5945 | // ... |
| 5946 | // fallthrough --> loopMBB |
| 5947 | BB->addSuccessor(loopMBB); |
| 5948 | |
| 5949 | // loopMBB: |
| 5950 | // ldrex dest, ptr |
| 5951 | // (sign extend dest, if required) |
| 5952 | // cmp dest, incr |
James Molloy | d6d10ae | 2012-09-26 09:48:32 +0000 | [diff] [blame] | 5953 | // cmov.cond scratch2, incr, dest |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5954 | // strex scratch, scratch2, ptr |
| 5955 | // cmp scratch, #0 |
| 5956 | // bne- loopMBB |
| 5957 | // fallthrough --> exitMBB |
| 5958 | BB = loopMBB; |
Jim Grosbach | b6aed50 | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 5959 | MachineInstrBuilder MIB = BuildMI(BB, dl, TII->get(ldrOpc), dest).addReg(ptr); |
| 5960 | if (ldrOpc == ARM::t2LDREX) |
| 5961 | MIB.addImm(0); |
| 5962 | AddDefaultPred(MIB); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5963 | |
| 5964 | // Sign extend the value, if necessary. |
| 5965 | if (signExtend && extendOpc) { |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 5966 | oldval = MRI.createVirtualRegister(&ARM::GPRRegClass); |
Jim Grosbach | c5a8c86 | 2011-07-27 16:47:19 +0000 | [diff] [blame] | 5967 | AddDefaultPred(BuildMI(BB, dl, TII->get(extendOpc), oldval) |
| 5968 | .addReg(dest) |
| 5969 | .addImm(0)); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5970 | } |
| 5971 | |
| 5972 | // Build compare and cmov instructions. |
| 5973 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
| 5974 | .addReg(oldval).addReg(incr)); |
| 5975 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2MOVCCr : ARM::MOVCCr), scratch2) |
James Molloy | d6d10ae | 2012-09-26 09:48:32 +0000 | [diff] [blame] | 5976 | .addReg(incr).addReg(oldval).addImm(Cond).addReg(ARM::CPSR); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5977 | |
Jim Grosbach | b6aed50 | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 5978 | MIB = BuildMI(BB, dl, TII->get(strOpc), scratch).addReg(scratch2).addReg(ptr); |
| 5979 | if (strOpc == ARM::t2STREX) |
| 5980 | MIB.addImm(0); |
| 5981 | AddDefaultPred(MIB); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5982 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 5983 | .addReg(scratch).addImm(0)); |
| 5984 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 5985 | .addMBB(loopMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
| 5986 | |
| 5987 | BB->addSuccessor(loopMBB); |
| 5988 | BB->addSuccessor(exitMBB); |
| 5989 | |
| 5990 | // exitMBB: |
| 5991 | // ... |
| 5992 | BB = exitMBB; |
| 5993 | |
| 5994 | MI->eraseFromParent(); // The instruction is gone now. |
| 5995 | |
| 5996 | return BB; |
| 5997 | } |
| 5998 | |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5999 | MachineBasicBlock * |
| 6000 | ARMTargetLowering::EmitAtomicBinary64(MachineInstr *MI, MachineBasicBlock *BB, |
| 6001 | unsigned Op1, unsigned Op2, |
Silviu Baranga | 35b3df6 | 2012-11-29 14:41:25 +0000 | [diff] [blame] | 6002 | bool NeedsCarry, bool IsCmpxchg, |
| 6003 | bool IsMinMax, ARMCC::CondCodes CC) const { |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6004 | // This also handles ATOMIC_SWAP, indicated by Op1==0. |
| 6005 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 6006 | |
| 6007 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 6008 | MachineFunction *MF = BB->getParent(); |
| 6009 | MachineFunction::iterator It = BB; |
| 6010 | ++It; |
| 6011 | |
| 6012 | unsigned destlo = MI->getOperand(0).getReg(); |
| 6013 | unsigned desthi = MI->getOperand(1).getReg(); |
| 6014 | unsigned ptr = MI->getOperand(2).getReg(); |
| 6015 | unsigned vallo = MI->getOperand(3).getReg(); |
| 6016 | unsigned valhi = MI->getOperand(4).getReg(); |
| 6017 | DebugLoc dl = MI->getDebugLoc(); |
| 6018 | bool isThumb2 = Subtarget->isThumb2(); |
| 6019 | |
| 6020 | MachineRegisterInfo &MRI = BB->getParent()->getRegInfo(); |
| 6021 | if (isThumb2) { |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 6022 | MRI.constrainRegClass(destlo, &ARM::rGPRRegClass); |
| 6023 | MRI.constrainRegClass(desthi, &ARM::rGPRRegClass); |
| 6024 | MRI.constrainRegClass(ptr, &ARM::rGPRRegClass); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6025 | } |
| 6026 | |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6027 | MachineBasicBlock *loopMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
Eli Friedman | 7df496d | 2011-09-01 22:27:41 +0000 | [diff] [blame] | 6028 | MachineBasicBlock *contBB = 0, *cont2BB = 0; |
Silviu Baranga | 35b3df6 | 2012-11-29 14:41:25 +0000 | [diff] [blame] | 6029 | if (IsCmpxchg || IsMinMax) |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 6030 | contBB = MF->CreateMachineBasicBlock(LLVM_BB); |
Silviu Baranga | 35b3df6 | 2012-11-29 14:41:25 +0000 | [diff] [blame] | 6031 | if (IsCmpxchg) |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 6032 | cont2BB = MF->CreateMachineBasicBlock(LLVM_BB); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6033 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
Silviu Baranga | 35b3df6 | 2012-11-29 14:41:25 +0000 | [diff] [blame] | 6034 | |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6035 | MF->insert(It, loopMBB); |
Silviu Baranga | 35b3df6 | 2012-11-29 14:41:25 +0000 | [diff] [blame] | 6036 | if (IsCmpxchg || IsMinMax) MF->insert(It, contBB); |
| 6037 | if (IsCmpxchg) MF->insert(It, cont2BB); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6038 | MF->insert(It, exitMBB); |
| 6039 | |
| 6040 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 6041 | exitMBB->splice(exitMBB->begin(), BB, |
| 6042 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 6043 | BB->end()); |
| 6044 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
| 6045 | |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 6046 | const TargetRegisterClass *TRC = isThumb2 ? |
| 6047 | (const TargetRegisterClass*)&ARM::tGPRRegClass : |
| 6048 | (const TargetRegisterClass*)&ARM::GPRRegClass; |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6049 | unsigned storesuccess = MRI.createVirtualRegister(TRC); |
| 6050 | |
| 6051 | // thisMBB: |
| 6052 | // ... |
| 6053 | // fallthrough --> loopMBB |
| 6054 | BB->addSuccessor(loopMBB); |
| 6055 | |
| 6056 | // loopMBB: |
| 6057 | // ldrexd r2, r3, ptr |
| 6058 | // <binopa> r0, r2, incr |
| 6059 | // <binopb> r1, r3, incr |
| 6060 | // strexd storesuccess, r0, r1, ptr |
| 6061 | // cmp storesuccess, #0 |
| 6062 | // bne- loopMBB |
| 6063 | // fallthrough --> exitMBB |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6064 | BB = loopMBB; |
Tim Northover | 0adfded | 2013-01-29 09:06:13 +0000 | [diff] [blame] | 6065 | |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6066 | // Load |
Tim Northover | 0adfded | 2013-01-29 09:06:13 +0000 | [diff] [blame] | 6067 | if (isThumb2) { |
| 6068 | AddDefaultPred(BuildMI(BB, dl, TII->get(ARM::t2LDREXD)) |
| 6069 | .addReg(destlo, RegState::Define) |
| 6070 | .addReg(desthi, RegState::Define) |
| 6071 | .addReg(ptr)); |
| 6072 | } else { |
| 6073 | unsigned GPRPair0 = MRI.createVirtualRegister(&ARM::GPRPairRegClass); |
| 6074 | AddDefaultPred(BuildMI(BB, dl, TII->get(ARM::LDREXD)) |
| 6075 | .addReg(GPRPair0, RegState::Define).addReg(ptr)); |
| 6076 | // Copy r2/r3 into dest. (This copy will normally be coalesced.) |
| 6077 | BuildMI(BB, dl, TII->get(TargetOpcode::COPY), destlo) |
| 6078 | .addReg(GPRPair0, 0, ARM::gsub_0); |
| 6079 | BuildMI(BB, dl, TII->get(TargetOpcode::COPY), desthi) |
| 6080 | .addReg(GPRPair0, 0, ARM::gsub_1); |
Silviu Baranga | 35b3df6 | 2012-11-29 14:41:25 +0000 | [diff] [blame] | 6081 | } |
Weiming Zhao | e56764b | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 6082 | |
Tim Northover | 0adfded | 2013-01-29 09:06:13 +0000 | [diff] [blame] | 6083 | unsigned StoreLo, StoreHi; |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 6084 | if (IsCmpxchg) { |
| 6085 | // Add early exit |
| 6086 | for (unsigned i = 0; i < 2; i++) { |
| 6087 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPrr : |
| 6088 | ARM::CMPrr)) |
| 6089 | .addReg(i == 0 ? destlo : desthi) |
| 6090 | .addReg(i == 0 ? vallo : valhi)); |
| 6091 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 6092 | .addMBB(exitMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
| 6093 | BB->addSuccessor(exitMBB); |
| 6094 | BB->addSuccessor(i == 0 ? contBB : cont2BB); |
| 6095 | BB = (i == 0 ? contBB : cont2BB); |
| 6096 | } |
| 6097 | |
| 6098 | // Copy to physregs for strexd |
Tim Northover | 0adfded | 2013-01-29 09:06:13 +0000 | [diff] [blame] | 6099 | StoreLo = MI->getOperand(5).getReg(); |
| 6100 | StoreHi = MI->getOperand(6).getReg(); |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 6101 | } else if (Op1) { |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6102 | // Perform binary operation |
Weiming Zhao | e56764b | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 6103 | unsigned tmpRegLo = MRI.createVirtualRegister(TRC); |
| 6104 | AddDefaultPred(BuildMI(BB, dl, TII->get(Op1), tmpRegLo) |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6105 | .addReg(destlo).addReg(vallo)) |
| 6106 | .addReg(NeedsCarry ? ARM::CPSR : 0, getDefRegState(NeedsCarry)); |
Weiming Zhao | e56764b | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 6107 | unsigned tmpRegHi = MRI.createVirtualRegister(TRC); |
| 6108 | AddDefaultPred(BuildMI(BB, dl, TII->get(Op2), tmpRegHi) |
Silviu Baranga | 35b3df6 | 2012-11-29 14:41:25 +0000 | [diff] [blame] | 6109 | .addReg(desthi).addReg(valhi)) |
| 6110 | .addReg(IsMinMax ? ARM::CPSR : 0, getDefRegState(IsMinMax)); |
Weiming Zhao | e56764b | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 6111 | |
Tim Northover | 0adfded | 2013-01-29 09:06:13 +0000 | [diff] [blame] | 6112 | StoreLo = tmpRegLo; |
| 6113 | StoreHi = tmpRegHi; |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6114 | } else { |
| 6115 | // Copy to physregs for strexd |
Tim Northover | 0adfded | 2013-01-29 09:06:13 +0000 | [diff] [blame] | 6116 | StoreLo = vallo; |
| 6117 | StoreHi = valhi; |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6118 | } |
Silviu Baranga | 35b3df6 | 2012-11-29 14:41:25 +0000 | [diff] [blame] | 6119 | if (IsMinMax) { |
| 6120 | // Compare and branch to exit block. |
| 6121 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 6122 | .addMBB(exitMBB).addImm(CC).addReg(ARM::CPSR); |
| 6123 | BB->addSuccessor(exitMBB); |
| 6124 | BB->addSuccessor(contBB); |
| 6125 | BB = contBB; |
Tim Northover | 0adfded | 2013-01-29 09:06:13 +0000 | [diff] [blame] | 6126 | StoreLo = vallo; |
| 6127 | StoreHi = valhi; |
Silviu Baranga | 35b3df6 | 2012-11-29 14:41:25 +0000 | [diff] [blame] | 6128 | } |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6129 | |
| 6130 | // Store |
Tim Northover | 0adfded | 2013-01-29 09:06:13 +0000 | [diff] [blame] | 6131 | if (isThumb2) { |
| 6132 | AddDefaultPred(BuildMI(BB, dl, TII->get(ARM::t2STREXD), storesuccess) |
| 6133 | .addReg(StoreLo).addReg(StoreHi).addReg(ptr)); |
| 6134 | } else { |
| 6135 | // Marshal a pair... |
| 6136 | unsigned StorePair = MRI.createVirtualRegister(&ARM::GPRPairRegClass); |
| 6137 | unsigned UndefPair = MRI.createVirtualRegister(&ARM::GPRPairRegClass); |
| 6138 | unsigned r1 = MRI.createVirtualRegister(&ARM::GPRPairRegClass); |
| 6139 | BuildMI(BB, dl, TII->get(TargetOpcode::IMPLICIT_DEF), UndefPair); |
| 6140 | BuildMI(BB, dl, TII->get(TargetOpcode::INSERT_SUBREG), r1) |
| 6141 | .addReg(UndefPair) |
| 6142 | .addReg(StoreLo) |
| 6143 | .addImm(ARM::gsub_0); |
| 6144 | BuildMI(BB, dl, TII->get(TargetOpcode::INSERT_SUBREG), StorePair) |
| 6145 | .addReg(r1) |
| 6146 | .addReg(StoreHi) |
| 6147 | .addImm(ARM::gsub_1); |
| 6148 | |
| 6149 | // ...and store it |
| 6150 | AddDefaultPred(BuildMI(BB, dl, TII->get(ARM::STREXD), storesuccess) |
| 6151 | .addReg(StorePair).addReg(ptr)); |
| 6152 | } |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6153 | // Cmp+jump |
| 6154 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 6155 | .addReg(storesuccess).addImm(0)); |
| 6156 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 6157 | .addMBB(loopMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
| 6158 | |
| 6159 | BB->addSuccessor(loopMBB); |
| 6160 | BB->addSuccessor(exitMBB); |
| 6161 | |
| 6162 | // exitMBB: |
| 6163 | // ... |
| 6164 | BB = exitMBB; |
| 6165 | |
| 6166 | MI->eraseFromParent(); // The instruction is gone now. |
| 6167 | |
| 6168 | return BB; |
| 6169 | } |
| 6170 | |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 6171 | /// SetupEntryBlockForSjLj - Insert code into the entry block that creates and |
| 6172 | /// registers the function context. |
| 6173 | void ARMTargetLowering:: |
| 6174 | SetupEntryBlockForSjLj(MachineInstr *MI, MachineBasicBlock *MBB, |
| 6175 | MachineBasicBlock *DispatchBB, int FI) const { |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 6176 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 6177 | DebugLoc dl = MI->getDebugLoc(); |
| 6178 | MachineFunction *MF = MBB->getParent(); |
| 6179 | MachineRegisterInfo *MRI = &MF->getRegInfo(); |
| 6180 | MachineConstantPool *MCP = MF->getConstantPool(); |
| 6181 | ARMFunctionInfo *AFI = MF->getInfo<ARMFunctionInfo>(); |
| 6182 | const Function *F = MF->getFunction(); |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 6183 | |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 6184 | bool isThumb = Subtarget->isThumb(); |
Bill Wendling | ff4216a | 2011-10-03 22:44:15 +0000 | [diff] [blame] | 6185 | bool isThumb2 = Subtarget->isThumb2(); |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 6186 | |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 6187 | unsigned PCLabelId = AFI->createPICLabelUId(); |
Bill Wendling | ff4216a | 2011-10-03 22:44:15 +0000 | [diff] [blame] | 6188 | unsigned PCAdj = (isThumb || isThumb2) ? 4 : 8; |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 6189 | ARMConstantPoolValue *CPV = |
| 6190 | ARMConstantPoolMBB::Create(F->getContext(), DispatchBB, PCLabelId, PCAdj); |
| 6191 | unsigned CPI = MCP->getConstantPoolIndex(CPV, 4); |
| 6192 | |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 6193 | const TargetRegisterClass *TRC = isThumb ? |
| 6194 | (const TargetRegisterClass*)&ARM::tGPRRegClass : |
| 6195 | (const TargetRegisterClass*)&ARM::GPRRegClass; |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 6196 | |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 6197 | // Grab constant pool and fixed stack memory operands. |
| 6198 | MachineMemOperand *CPMMO = |
| 6199 | MF->getMachineMemOperand(MachinePointerInfo::getConstantPool(), |
| 6200 | MachineMemOperand::MOLoad, 4, 4); |
| 6201 | |
| 6202 | MachineMemOperand *FIMMOSt = |
| 6203 | MF->getMachineMemOperand(MachinePointerInfo::getFixedStack(FI), |
| 6204 | MachineMemOperand::MOStore, 4, 4); |
| 6205 | |
| 6206 | // Load the address of the dispatch MBB into the jump buffer. |
| 6207 | if (isThumb2) { |
| 6208 | // Incoming value: jbuf |
| 6209 | // ldr.n r5, LCPI1_1 |
| 6210 | // orr r5, r5, #1 |
| 6211 | // add r5, pc |
| 6212 | // str r5, [$jbuf, #+4] ; &jbuf[1] |
| 6213 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 6214 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::t2LDRpci), NewVReg1) |
| 6215 | .addConstantPoolIndex(CPI) |
| 6216 | .addMemOperand(CPMMO)); |
| 6217 | // Set the low bit because of thumb mode. |
| 6218 | unsigned NewVReg2 = MRI->createVirtualRegister(TRC); |
| 6219 | AddDefaultCC( |
| 6220 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::t2ORRri), NewVReg2) |
| 6221 | .addReg(NewVReg1, RegState::Kill) |
| 6222 | .addImm(0x01))); |
| 6223 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
| 6224 | BuildMI(*MBB, MI, dl, TII->get(ARM::tPICADD), NewVReg3) |
| 6225 | .addReg(NewVReg2, RegState::Kill) |
| 6226 | .addImm(PCLabelId); |
| 6227 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::t2STRi12)) |
| 6228 | .addReg(NewVReg3, RegState::Kill) |
| 6229 | .addFrameIndex(FI) |
| 6230 | .addImm(36) // &jbuf[1] :: pc |
| 6231 | .addMemOperand(FIMMOSt)); |
| 6232 | } else if (isThumb) { |
| 6233 | // Incoming value: jbuf |
| 6234 | // ldr.n r1, LCPI1_4 |
| 6235 | // add r1, pc |
| 6236 | // mov r2, #1 |
| 6237 | // orrs r1, r2 |
| 6238 | // add r2, $jbuf, #+4 ; &jbuf[1] |
| 6239 | // str r1, [r2] |
| 6240 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 6241 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tLDRpci), NewVReg1) |
| 6242 | .addConstantPoolIndex(CPI) |
| 6243 | .addMemOperand(CPMMO)); |
| 6244 | unsigned NewVReg2 = MRI->createVirtualRegister(TRC); |
| 6245 | BuildMI(*MBB, MI, dl, TII->get(ARM::tPICADD), NewVReg2) |
| 6246 | .addReg(NewVReg1, RegState::Kill) |
| 6247 | .addImm(PCLabelId); |
| 6248 | // Set the low bit because of thumb mode. |
| 6249 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
| 6250 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tMOVi8), NewVReg3) |
| 6251 | .addReg(ARM::CPSR, RegState::Define) |
| 6252 | .addImm(1)); |
| 6253 | unsigned NewVReg4 = MRI->createVirtualRegister(TRC); |
| 6254 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tORR), NewVReg4) |
| 6255 | .addReg(ARM::CPSR, RegState::Define) |
| 6256 | .addReg(NewVReg2, RegState::Kill) |
| 6257 | .addReg(NewVReg3, RegState::Kill)); |
| 6258 | unsigned NewVReg5 = MRI->createVirtualRegister(TRC); |
| 6259 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tADDrSPi), NewVReg5) |
| 6260 | .addFrameIndex(FI) |
| 6261 | .addImm(36)); // &jbuf[1] :: pc |
| 6262 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tSTRi)) |
| 6263 | .addReg(NewVReg4, RegState::Kill) |
| 6264 | .addReg(NewVReg5, RegState::Kill) |
| 6265 | .addImm(0) |
| 6266 | .addMemOperand(FIMMOSt)); |
| 6267 | } else { |
| 6268 | // Incoming value: jbuf |
| 6269 | // ldr r1, LCPI1_1 |
| 6270 | // add r1, pc, r1 |
| 6271 | // str r1, [$jbuf, #+4] ; &jbuf[1] |
| 6272 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 6273 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::LDRi12), NewVReg1) |
| 6274 | .addConstantPoolIndex(CPI) |
| 6275 | .addImm(0) |
| 6276 | .addMemOperand(CPMMO)); |
| 6277 | unsigned NewVReg2 = MRI->createVirtualRegister(TRC); |
| 6278 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::PICADD), NewVReg2) |
| 6279 | .addReg(NewVReg1, RegState::Kill) |
| 6280 | .addImm(PCLabelId)); |
| 6281 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::STRi12)) |
| 6282 | .addReg(NewVReg2, RegState::Kill) |
| 6283 | .addFrameIndex(FI) |
| 6284 | .addImm(36) // &jbuf[1] :: pc |
| 6285 | .addMemOperand(FIMMOSt)); |
| 6286 | } |
| 6287 | } |
| 6288 | |
| 6289 | MachineBasicBlock *ARMTargetLowering:: |
| 6290 | EmitSjLjDispatchBlock(MachineInstr *MI, MachineBasicBlock *MBB) const { |
| 6291 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 6292 | DebugLoc dl = MI->getDebugLoc(); |
| 6293 | MachineFunction *MF = MBB->getParent(); |
| 6294 | MachineRegisterInfo *MRI = &MF->getRegInfo(); |
| 6295 | ARMFunctionInfo *AFI = MF->getInfo<ARMFunctionInfo>(); |
| 6296 | MachineFrameInfo *MFI = MF->getFrameInfo(); |
| 6297 | int FI = MFI->getFunctionContextIndex(); |
| 6298 | |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 6299 | const TargetRegisterClass *TRC = Subtarget->isThumb() ? |
| 6300 | (const TargetRegisterClass*)&ARM::tGPRRegClass : |
Jakob Stoklund Olesen | 027c32a | 2012-05-20 06:38:47 +0000 | [diff] [blame] | 6301 | (const TargetRegisterClass*)&ARM::GPRnopcRegClass; |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 6302 | |
Bill Wendling | 04f15b4 | 2011-10-06 21:29:56 +0000 | [diff] [blame] | 6303 | // Get a mapping of the call site numbers to all of the landing pads they're |
| 6304 | // associated with. |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6305 | DenseMap<unsigned, SmallVector<MachineBasicBlock*, 2> > CallSiteNumToLPad; |
| 6306 | unsigned MaxCSNum = 0; |
| 6307 | MachineModuleInfo &MMI = MF->getMMI(); |
Jim Grosbach | d4f020a | 2012-04-06 23:43:50 +0000 | [diff] [blame] | 6308 | for (MachineFunction::iterator BB = MF->begin(), E = MF->end(); BB != E; |
| 6309 | ++BB) { |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6310 | if (!BB->isLandingPad()) continue; |
| 6311 | |
| 6312 | // FIXME: We should assert that the EH_LABEL is the first MI in the landing |
| 6313 | // pad. |
| 6314 | for (MachineBasicBlock::iterator |
| 6315 | II = BB->begin(), IE = BB->end(); II != IE; ++II) { |
| 6316 | if (!II->isEHLabel()) continue; |
| 6317 | |
| 6318 | MCSymbol *Sym = II->getOperand(0).getMCSymbol(); |
Bill Wendling | 5cbef19 | 2011-10-05 23:28:57 +0000 | [diff] [blame] | 6319 | if (!MMI.hasCallSiteLandingPad(Sym)) continue; |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6320 | |
Bill Wendling | 5cbef19 | 2011-10-05 23:28:57 +0000 | [diff] [blame] | 6321 | SmallVectorImpl<unsigned> &CallSiteIdxs = MMI.getCallSiteLandingPad(Sym); |
| 6322 | for (SmallVectorImpl<unsigned>::iterator |
| 6323 | CSI = CallSiteIdxs.begin(), CSE = CallSiteIdxs.end(); |
| 6324 | CSI != CSE; ++CSI) { |
| 6325 | CallSiteNumToLPad[*CSI].push_back(BB); |
| 6326 | MaxCSNum = std::max(MaxCSNum, *CSI); |
| 6327 | } |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6328 | break; |
| 6329 | } |
| 6330 | } |
| 6331 | |
| 6332 | // Get an ordered list of the machine basic blocks for the jump table. |
| 6333 | std::vector<MachineBasicBlock*> LPadList; |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6334 | SmallPtrSet<MachineBasicBlock*, 64> InvokeBBs; |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6335 | LPadList.reserve(CallSiteNumToLPad.size()); |
| 6336 | for (unsigned I = 1; I <= MaxCSNum; ++I) { |
| 6337 | SmallVectorImpl<MachineBasicBlock*> &MBBList = CallSiteNumToLPad[I]; |
| 6338 | for (SmallVectorImpl<MachineBasicBlock*>::iterator |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6339 | II = MBBList.begin(), IE = MBBList.end(); II != IE; ++II) { |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6340 | LPadList.push_back(*II); |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6341 | InvokeBBs.insert((*II)->pred_begin(), (*II)->pred_end()); |
| 6342 | } |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6343 | } |
| 6344 | |
Bill Wendling | 5cbef19 | 2011-10-05 23:28:57 +0000 | [diff] [blame] | 6345 | assert(!LPadList.empty() && |
| 6346 | "No landing pad destinations for the dispatch jump table!"); |
| 6347 | |
Bill Wendling | 04f15b4 | 2011-10-06 21:29:56 +0000 | [diff] [blame] | 6348 | // Create the jump table and associated information. |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6349 | MachineJumpTableInfo *JTI = |
| 6350 | MF->getOrCreateJumpTableInfo(MachineJumpTableInfo::EK_Inline); |
| 6351 | unsigned MJTI = JTI->createJumpTableIndex(LPadList); |
| 6352 | unsigned UId = AFI->createJumpTableUId(); |
Chad Rosier | b8f307b | 2013-03-01 18:30:38 +0000 | [diff] [blame] | 6353 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6354 | |
Bill Wendling | 04f15b4 | 2011-10-06 21:29:56 +0000 | [diff] [blame] | 6355 | // Create the MBBs for the dispatch code. |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 6356 | |
| 6357 | // Shove the dispatch's address into the return slot in the function context. |
| 6358 | MachineBasicBlock *DispatchBB = MF->CreateMachineBasicBlock(); |
| 6359 | DispatchBB->setIsLandingPad(); |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 6360 | |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 6361 | MachineBasicBlock *TrapBB = MF->CreateMachineBasicBlock(); |
Eli Bendersky | 0f156af | 2013-01-30 16:30:19 +0000 | [diff] [blame] | 6362 | unsigned trap_opcode; |
Chad Rosier | 279706e | 2013-02-28 18:54:27 +0000 | [diff] [blame] | 6363 | if (Subtarget->isThumb()) |
Eli Bendersky | 0f156af | 2013-01-30 16:30:19 +0000 | [diff] [blame] | 6364 | trap_opcode = ARM::tTRAP; |
Chad Rosier | 279706e | 2013-02-28 18:54:27 +0000 | [diff] [blame] | 6365 | else |
| 6366 | trap_opcode = Subtarget->useNaClTrap() ? ARM::TRAPNaCl : ARM::TRAP; |
| 6367 | |
Eli Bendersky | 0f156af | 2013-01-30 16:30:19 +0000 | [diff] [blame] | 6368 | BuildMI(TrapBB, dl, TII->get(trap_opcode)); |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 6369 | DispatchBB->addSuccessor(TrapBB); |
| 6370 | |
| 6371 | MachineBasicBlock *DispContBB = MF->CreateMachineBasicBlock(); |
| 6372 | DispatchBB->addSuccessor(DispContBB); |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6373 | |
Bill Wendling | a48ed4f | 2011-10-17 21:32:56 +0000 | [diff] [blame] | 6374 | // Insert and MBBs. |
Bill Wendling | 930193c | 2011-10-06 00:53:33 +0000 | [diff] [blame] | 6375 | MF->insert(MF->end(), DispatchBB); |
| 6376 | MF->insert(MF->end(), DispContBB); |
| 6377 | MF->insert(MF->end(), TrapBB); |
Bill Wendling | 930193c | 2011-10-06 00:53:33 +0000 | [diff] [blame] | 6378 | |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 6379 | // Insert code into the entry block that creates and registers the function |
| 6380 | // context. |
| 6381 | SetupEntryBlockForSjLj(MI, MBB, DispatchBB, FI); |
| 6382 | |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 6383 | MachineMemOperand *FIMMOLd = |
Bill Wendling | 04f15b4 | 2011-10-06 21:29:56 +0000 | [diff] [blame] | 6384 | MF->getMachineMemOperand(MachinePointerInfo::getFixedStack(FI), |
Bill Wendling | 083a8eb | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 6385 | MachineMemOperand::MOLoad | |
| 6386 | MachineMemOperand::MOVolatile, 4, 4); |
Bill Wendling | 930193c | 2011-10-06 00:53:33 +0000 | [diff] [blame] | 6387 | |
Chad Rosier | e7bd519 | 2012-11-06 23:05:24 +0000 | [diff] [blame] | 6388 | MachineInstrBuilder MIB; |
| 6389 | MIB = BuildMI(DispatchBB, dl, TII->get(ARM::Int_eh_sjlj_dispatchsetup)); |
| 6390 | |
| 6391 | const ARMBaseInstrInfo *AII = static_cast<const ARMBaseInstrInfo*>(TII); |
| 6392 | const ARMBaseRegisterInfo &RI = AII->getRegisterInfo(); |
| 6393 | |
| 6394 | // Add a register mask with no preserved registers. This results in all |
| 6395 | // registers being marked as clobbered. |
| 6396 | MIB.addRegMask(RI.getNoPreservedMask()); |
Bob Wilson | eaab6ef | 2011-11-16 07:11:57 +0000 | [diff] [blame] | 6397 | |
Bill Wendling | 952cb50 | 2011-10-18 22:49:07 +0000 | [diff] [blame] | 6398 | unsigned NumLPads = LPadList.size(); |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6399 | if (Subtarget->isThumb2()) { |
| 6400 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 6401 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2LDRi12), NewVReg1) |
| 6402 | .addFrameIndex(FI) |
| 6403 | .addImm(4) |
| 6404 | .addMemOperand(FIMMOLd)); |
Bill Wendling | b9fecf4 | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 6405 | |
Bill Wendling | 952cb50 | 2011-10-18 22:49:07 +0000 | [diff] [blame] | 6406 | if (NumLPads < 256) { |
| 6407 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2CMPri)) |
| 6408 | .addReg(NewVReg1) |
| 6409 | .addImm(LPadList.size())); |
| 6410 | } else { |
| 6411 | unsigned VReg1 = MRI->createVirtualRegister(TRC); |
| 6412 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2MOVi16), VReg1) |
Bill Wendling | 15a1a22 | 2011-10-18 23:19:55 +0000 | [diff] [blame] | 6413 | .addImm(NumLPads & 0xFFFF)); |
| 6414 | |
| 6415 | unsigned VReg2 = VReg1; |
| 6416 | if ((NumLPads & 0xFFFF0000) != 0) { |
| 6417 | VReg2 = MRI->createVirtualRegister(TRC); |
| 6418 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2MOVTi16), VReg2) |
| 6419 | .addReg(VReg1) |
| 6420 | .addImm(NumLPads >> 16)); |
| 6421 | } |
| 6422 | |
Bill Wendling | 952cb50 | 2011-10-18 22:49:07 +0000 | [diff] [blame] | 6423 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2CMPrr)) |
| 6424 | .addReg(NewVReg1) |
| 6425 | .addReg(VReg2)); |
| 6426 | } |
Bill Wendling | b9fecf4 | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 6427 | |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6428 | BuildMI(DispatchBB, dl, TII->get(ARM::t2Bcc)) |
| 6429 | .addMBB(TrapBB) |
| 6430 | .addImm(ARMCC::HI) |
| 6431 | .addReg(ARM::CPSR); |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 6432 | |
Bill Wendling | b9fecf4 | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 6433 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
| 6434 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::t2LEApcrelJT),NewVReg3) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6435 | .addJumpTableIndex(MJTI) |
| 6436 | .addImm(UId)); |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6437 | |
Bill Wendling | b9fecf4 | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 6438 | unsigned NewVReg4 = MRI->createVirtualRegister(TRC); |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6439 | AddDefaultCC( |
| 6440 | AddDefaultPred( |
Bill Wendling | b9fecf4 | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 6441 | BuildMI(DispContBB, dl, TII->get(ARM::t2ADDrs), NewVReg4) |
| 6442 | .addReg(NewVReg3, RegState::Kill) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6443 | .addReg(NewVReg1) |
| 6444 | .addImm(ARM_AM::getSORegOpc(ARM_AM::lsl, 2)))); |
| 6445 | |
| 6446 | BuildMI(DispContBB, dl, TII->get(ARM::t2BR_JT)) |
Bill Wendling | b9fecf4 | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 6447 | .addReg(NewVReg4, RegState::Kill) |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6448 | .addReg(NewVReg1) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6449 | .addJumpTableIndex(MJTI) |
| 6450 | .addImm(UId); |
| 6451 | } else if (Subtarget->isThumb()) { |
Bill Wendling | 083a8eb | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 6452 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 6453 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::tLDRspi), NewVReg1) |
| 6454 | .addFrameIndex(FI) |
| 6455 | .addImm(1) |
| 6456 | .addMemOperand(FIMMOLd)); |
Bill Wendling | f1083d4 | 2011-10-07 22:08:37 +0000 | [diff] [blame] | 6457 | |
Bill Wendling | a5871dc | 2011-10-18 23:11:05 +0000 | [diff] [blame] | 6458 | if (NumLPads < 256) { |
| 6459 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::tCMPi8)) |
| 6460 | .addReg(NewVReg1) |
| 6461 | .addImm(NumLPads)); |
| 6462 | } else { |
| 6463 | MachineConstantPool *ConstantPool = MF->getConstantPool(); |
Bill Wendling | 922ad78 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 6464 | Type *Int32Ty = Type::getInt32Ty(MF->getFunction()->getContext()); |
| 6465 | const Constant *C = ConstantInt::get(Int32Ty, NumLPads); |
| 6466 | |
| 6467 | // MachineConstantPool wants an explicit alignment. |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 6468 | unsigned Align = getDataLayout()->getPrefTypeAlignment(Int32Ty); |
Bill Wendling | 922ad78 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 6469 | if (Align == 0) |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 6470 | Align = getDataLayout()->getTypeAllocSize(C->getType()); |
Bill Wendling | 922ad78 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 6471 | unsigned Idx = ConstantPool->getConstantPoolIndex(C, Align); |
Bill Wendling | a5871dc | 2011-10-18 23:11:05 +0000 | [diff] [blame] | 6472 | |
| 6473 | unsigned VReg1 = MRI->createVirtualRegister(TRC); |
| 6474 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::tLDRpci)) |
| 6475 | .addReg(VReg1, RegState::Define) |
| 6476 | .addConstantPoolIndex(Idx)); |
| 6477 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::tCMPr)) |
| 6478 | .addReg(NewVReg1) |
| 6479 | .addReg(VReg1)); |
| 6480 | } |
| 6481 | |
Bill Wendling | 083a8eb | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 6482 | BuildMI(DispatchBB, dl, TII->get(ARM::tBcc)) |
| 6483 | .addMBB(TrapBB) |
| 6484 | .addImm(ARMCC::HI) |
| 6485 | .addReg(ARM::CPSR); |
| 6486 | |
| 6487 | unsigned NewVReg2 = MRI->createVirtualRegister(TRC); |
| 6488 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tLSLri), NewVReg2) |
| 6489 | .addReg(ARM::CPSR, RegState::Define) |
| 6490 | .addReg(NewVReg1) |
| 6491 | .addImm(2)); |
| 6492 | |
| 6493 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
Bill Wendling | 217f0e9 | 2011-10-06 23:41:14 +0000 | [diff] [blame] | 6494 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tLEApcrelJT), NewVReg3) |
Bill Wendling | 083a8eb | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 6495 | .addJumpTableIndex(MJTI) |
| 6496 | .addImm(UId)); |
| 6497 | |
| 6498 | unsigned NewVReg4 = MRI->createVirtualRegister(TRC); |
| 6499 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tADDrr), NewVReg4) |
| 6500 | .addReg(ARM::CPSR, RegState::Define) |
| 6501 | .addReg(NewVReg2, RegState::Kill) |
| 6502 | .addReg(NewVReg3)); |
| 6503 | |
| 6504 | MachineMemOperand *JTMMOLd = |
| 6505 | MF->getMachineMemOperand(MachinePointerInfo::getJumpTable(), |
| 6506 | MachineMemOperand::MOLoad, 4, 4); |
| 6507 | |
| 6508 | unsigned NewVReg5 = MRI->createVirtualRegister(TRC); |
| 6509 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tLDRi), NewVReg5) |
| 6510 | .addReg(NewVReg4, RegState::Kill) |
| 6511 | .addImm(0) |
| 6512 | .addMemOperand(JTMMOLd)); |
| 6513 | |
Chad Rosier | b8f307b | 2013-03-01 18:30:38 +0000 | [diff] [blame] | 6514 | unsigned NewVReg6 = NewVReg5; |
| 6515 | if (RelocM == Reloc::PIC_) { |
| 6516 | NewVReg6 = MRI->createVirtualRegister(TRC); |
| 6517 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tADDrr), NewVReg6) |
| 6518 | .addReg(ARM::CPSR, RegState::Define) |
| 6519 | .addReg(NewVReg5, RegState::Kill) |
| 6520 | .addReg(NewVReg3)); |
| 6521 | } |
Bill Wendling | 083a8eb | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 6522 | |
| 6523 | BuildMI(DispContBB, dl, TII->get(ARM::tBR_JTr)) |
| 6524 | .addReg(NewVReg6, RegState::Kill) |
| 6525 | .addJumpTableIndex(MJTI) |
| 6526 | .addImm(UId); |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6527 | } else { |
| 6528 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 6529 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::LDRi12), NewVReg1) |
| 6530 | .addFrameIndex(FI) |
| 6531 | .addImm(4) |
| 6532 | .addMemOperand(FIMMOLd)); |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6533 | |
Bill Wendling | 85f3a0a | 2011-10-18 22:52:20 +0000 | [diff] [blame] | 6534 | if (NumLPads < 256) { |
| 6535 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::CMPri)) |
| 6536 | .addReg(NewVReg1) |
| 6537 | .addImm(NumLPads)); |
Bill Wendling | 922ad78 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 6538 | } else if (Subtarget->hasV6T2Ops() && isUInt<16>(NumLPads)) { |
Bill Wendling | 85f3a0a | 2011-10-18 22:52:20 +0000 | [diff] [blame] | 6539 | unsigned VReg1 = MRI->createVirtualRegister(TRC); |
| 6540 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::MOVi16), VReg1) |
Bill Wendling | 15a1a22 | 2011-10-18 23:19:55 +0000 | [diff] [blame] | 6541 | .addImm(NumLPads & 0xFFFF)); |
| 6542 | |
| 6543 | unsigned VReg2 = VReg1; |
| 6544 | if ((NumLPads & 0xFFFF0000) != 0) { |
| 6545 | VReg2 = MRI->createVirtualRegister(TRC); |
| 6546 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::MOVTi16), VReg2) |
| 6547 | .addReg(VReg1) |
| 6548 | .addImm(NumLPads >> 16)); |
| 6549 | } |
| 6550 | |
Bill Wendling | 85f3a0a | 2011-10-18 22:52:20 +0000 | [diff] [blame] | 6551 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::CMPrr)) |
| 6552 | .addReg(NewVReg1) |
| 6553 | .addReg(VReg2)); |
Bill Wendling | 922ad78 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 6554 | } else { |
| 6555 | MachineConstantPool *ConstantPool = MF->getConstantPool(); |
| 6556 | Type *Int32Ty = Type::getInt32Ty(MF->getFunction()->getContext()); |
| 6557 | const Constant *C = ConstantInt::get(Int32Ty, NumLPads); |
| 6558 | |
| 6559 | // MachineConstantPool wants an explicit alignment. |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 6560 | unsigned Align = getDataLayout()->getPrefTypeAlignment(Int32Ty); |
Bill Wendling | 922ad78 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 6561 | if (Align == 0) |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 6562 | Align = getDataLayout()->getTypeAllocSize(C->getType()); |
Bill Wendling | 922ad78 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 6563 | unsigned Idx = ConstantPool->getConstantPoolIndex(C, Align); |
| 6564 | |
| 6565 | unsigned VReg1 = MRI->createVirtualRegister(TRC); |
| 6566 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::LDRcp)) |
| 6567 | .addReg(VReg1, RegState::Define) |
Bill Wendling | 767f8be | 2011-10-20 20:37:11 +0000 | [diff] [blame] | 6568 | .addConstantPoolIndex(Idx) |
| 6569 | .addImm(0)); |
Bill Wendling | 922ad78 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 6570 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::CMPrr)) |
| 6571 | .addReg(NewVReg1) |
| 6572 | .addReg(VReg1, RegState::Kill)); |
Bill Wendling | 85f3a0a | 2011-10-18 22:52:20 +0000 | [diff] [blame] | 6573 | } |
| 6574 | |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6575 | BuildMI(DispatchBB, dl, TII->get(ARM::Bcc)) |
| 6576 | .addMBB(TrapBB) |
| 6577 | .addImm(ARMCC::HI) |
| 6578 | .addReg(ARM::CPSR); |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6579 | |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6580 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6581 | AddDefaultCC( |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6582 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::MOVsi), NewVReg3) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6583 | .addReg(NewVReg1) |
| 6584 | .addImm(ARM_AM::getSORegOpc(ARM_AM::lsl, 2)))); |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6585 | unsigned NewVReg4 = MRI->createVirtualRegister(TRC); |
| 6586 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::LEApcrelJT), NewVReg4) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6587 | .addJumpTableIndex(MJTI) |
| 6588 | .addImm(UId)); |
| 6589 | |
| 6590 | MachineMemOperand *JTMMOLd = |
| 6591 | MF->getMachineMemOperand(MachinePointerInfo::getJumpTable(), |
| 6592 | MachineMemOperand::MOLoad, 4, 4); |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6593 | unsigned NewVReg5 = MRI->createVirtualRegister(TRC); |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6594 | AddDefaultPred( |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6595 | BuildMI(DispContBB, dl, TII->get(ARM::LDRrs), NewVReg5) |
| 6596 | .addReg(NewVReg3, RegState::Kill) |
| 6597 | .addReg(NewVReg4) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6598 | .addImm(0) |
| 6599 | .addMemOperand(JTMMOLd)); |
| 6600 | |
Chad Rosier | b8f307b | 2013-03-01 18:30:38 +0000 | [diff] [blame] | 6601 | if (RelocM == Reloc::PIC_) { |
| 6602 | BuildMI(DispContBB, dl, TII->get(ARM::BR_JTadd)) |
| 6603 | .addReg(NewVReg5, RegState::Kill) |
| 6604 | .addReg(NewVReg4) |
| 6605 | .addJumpTableIndex(MJTI) |
| 6606 | .addImm(UId); |
| 6607 | } else { |
| 6608 | BuildMI(DispContBB, dl, TII->get(ARM::BR_JTr)) |
| 6609 | .addReg(NewVReg5, RegState::Kill) |
| 6610 | .addJumpTableIndex(MJTI) |
| 6611 | .addImm(UId); |
| 6612 | } |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6613 | } |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6614 | |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 6615 | // Add the jump table entries as successors to the MBB. |
Jakob Stoklund Olesen | a0708d1 | 2012-08-20 20:52:03 +0000 | [diff] [blame] | 6616 | SmallPtrSet<MachineBasicBlock*, 8> SeenMBBs; |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 6617 | for (std::vector<MachineBasicBlock*>::iterator |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6618 | I = LPadList.begin(), E = LPadList.end(); I != E; ++I) { |
| 6619 | MachineBasicBlock *CurMBB = *I; |
Jakob Stoklund Olesen | a0708d1 | 2012-08-20 20:52:03 +0000 | [diff] [blame] | 6620 | if (SeenMBBs.insert(CurMBB)) |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6621 | DispContBB->addSuccessor(CurMBB); |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6622 | } |
| 6623 | |
Bill Wendling | 24bb925 | 2011-10-17 05:25:09 +0000 | [diff] [blame] | 6624 | // 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] | 6625 | const uint16_t *SavedRegs = RI.getCalleeSavedRegs(MF); |
Bill Wendling | f7b0207 | 2011-10-18 18:30:49 +0000 | [diff] [blame] | 6626 | SmallVector<MachineBasicBlock*, 64> MBBLPads; |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6627 | for (SmallPtrSet<MachineBasicBlock*, 64>::iterator |
| 6628 | I = InvokeBBs.begin(), E = InvokeBBs.end(); I != E; ++I) { |
| 6629 | MachineBasicBlock *BB = *I; |
Bill Wendling | 969c9ef | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 6630 | |
| 6631 | // Remove the landing pad successor from the invoke block and replace it |
| 6632 | // with the new dispatch block. |
Bill Wendling | de39d86 | 2011-10-26 07:16:18 +0000 | [diff] [blame] | 6633 | SmallVector<MachineBasicBlock*, 4> Successors(BB->succ_begin(), |
| 6634 | BB->succ_end()); |
| 6635 | while (!Successors.empty()) { |
| 6636 | MachineBasicBlock *SMBB = Successors.pop_back_val(); |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6637 | if (SMBB->isLandingPad()) { |
| 6638 | BB->removeSuccessor(SMBB); |
Bill Wendling | f7b0207 | 2011-10-18 18:30:49 +0000 | [diff] [blame] | 6639 | MBBLPads.push_back(SMBB); |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6640 | } |
| 6641 | } |
| 6642 | |
| 6643 | BB->addSuccessor(DispatchBB); |
Bill Wendling | 969c9ef | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 6644 | |
| 6645 | // Find the invoke call and mark all of the callee-saved registers as |
| 6646 | // 'implicit defined' so that they're spilled. This prevents code from |
| 6647 | // moving instructions to before the EH block, where they will never be |
| 6648 | // executed. |
| 6649 | for (MachineBasicBlock::reverse_iterator |
| 6650 | II = BB->rbegin(), IE = BB->rend(); II != IE; ++II) { |
Evan Cheng | 5a96b3d | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 6651 | if (!II->isCall()) continue; |
Bill Wendling | 969c9ef | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 6652 | |
| 6653 | DenseMap<unsigned, bool> DefRegs; |
| 6654 | for (MachineInstr::mop_iterator |
| 6655 | OI = II->operands_begin(), OE = II->operands_end(); |
| 6656 | OI != OE; ++OI) { |
| 6657 | if (!OI->isReg()) continue; |
| 6658 | DefRegs[OI->getReg()] = true; |
| 6659 | } |
| 6660 | |
Jakob Stoklund Olesen | 37a942c | 2012-12-19 21:31:56 +0000 | [diff] [blame] | 6661 | MachineInstrBuilder MIB(*MF, &*II); |
Bill Wendling | 969c9ef | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 6662 | |
Bill Wendling | 5d79859 | 2011-10-14 23:55:44 +0000 | [diff] [blame] | 6663 | for (unsigned i = 0; SavedRegs[i] != 0; ++i) { |
Bill Wendling | b8dcb31 | 2011-10-22 00:29:28 +0000 | [diff] [blame] | 6664 | unsigned Reg = SavedRegs[i]; |
| 6665 | if (Subtarget->isThumb2() && |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 6666 | !ARM::tGPRRegClass.contains(Reg) && |
| 6667 | !ARM::hGPRRegClass.contains(Reg)) |
Bill Wendling | b8dcb31 | 2011-10-22 00:29:28 +0000 | [diff] [blame] | 6668 | continue; |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 6669 | if (Subtarget->isThumb1Only() && !ARM::tGPRRegClass.contains(Reg)) |
Bill Wendling | b8dcb31 | 2011-10-22 00:29:28 +0000 | [diff] [blame] | 6670 | continue; |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 6671 | if (!Subtarget->isThumb() && !ARM::GPRRegClass.contains(Reg)) |
Bill Wendling | b8dcb31 | 2011-10-22 00:29:28 +0000 | [diff] [blame] | 6672 | continue; |
| 6673 | if (!DefRegs[Reg]) |
| 6674 | MIB.addReg(Reg, RegState::ImplicitDefine | RegState::Dead); |
Bill Wendling | 5d79859 | 2011-10-14 23:55:44 +0000 | [diff] [blame] | 6675 | } |
Bill Wendling | 969c9ef | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 6676 | |
| 6677 | break; |
| 6678 | } |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6679 | } |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 6680 | |
Bill Wendling | f7b0207 | 2011-10-18 18:30:49 +0000 | [diff] [blame] | 6681 | // Mark all former landing pads as non-landing pads. The dispatch is the only |
| 6682 | // landing pad now. |
| 6683 | for (SmallVectorImpl<MachineBasicBlock*>::iterator |
| 6684 | I = MBBLPads.begin(), E = MBBLPads.end(); I != E; ++I) |
| 6685 | (*I)->setIsLandingPad(false); |
| 6686 | |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 6687 | // The instruction is gone now. |
| 6688 | MI->eraseFromParent(); |
| 6689 | |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 6690 | return MBB; |
| 6691 | } |
| 6692 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 6693 | static |
| 6694 | MachineBasicBlock *OtherSucc(MachineBasicBlock *MBB, MachineBasicBlock *Succ) { |
| 6695 | for (MachineBasicBlock::succ_iterator I = MBB->succ_begin(), |
| 6696 | E = MBB->succ_end(); I != E; ++I) |
| 6697 | if (*I != Succ) |
| 6698 | return *I; |
| 6699 | llvm_unreachable("Expecting a BB with two successors!"); |
| 6700 | } |
| 6701 | |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 6702 | MachineBasicBlock *ARMTargetLowering:: |
| 6703 | EmitStructByval(MachineInstr *MI, MachineBasicBlock *BB) const { |
| 6704 | // This pseudo instruction has 3 operands: dst, src, size |
| 6705 | // We expand it to a loop if size > Subtarget->getMaxInlineSizeThreshold(). |
| 6706 | // Otherwise, we will generate unrolled scalar copies. |
| 6707 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 6708 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 6709 | MachineFunction::iterator It = BB; |
| 6710 | ++It; |
| 6711 | |
| 6712 | unsigned dest = MI->getOperand(0).getReg(); |
| 6713 | unsigned src = MI->getOperand(1).getReg(); |
| 6714 | unsigned SizeVal = MI->getOperand(2).getImm(); |
| 6715 | unsigned Align = MI->getOperand(3).getImm(); |
| 6716 | DebugLoc dl = MI->getDebugLoc(); |
| 6717 | |
| 6718 | bool isThumb2 = Subtarget->isThumb2(); |
| 6719 | MachineFunction *MF = BB->getParent(); |
| 6720 | MachineRegisterInfo &MRI = MF->getRegInfo(); |
Manman Ren | eda9fdf | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 6721 | unsigned ldrOpc, strOpc, UnitSize = 0; |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 6722 | |
| 6723 | const TargetRegisterClass *TRC = isThumb2 ? |
| 6724 | (const TargetRegisterClass*)&ARM::tGPRRegClass : |
| 6725 | (const TargetRegisterClass*)&ARM::GPRRegClass; |
Manman Ren | eda9fdf | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 6726 | const TargetRegisterClass *TRC_Vec = 0; |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 6727 | |
| 6728 | if (Align & 1) { |
| 6729 | ldrOpc = isThumb2 ? ARM::t2LDRB_POST : ARM::LDRB_POST_IMM; |
| 6730 | strOpc = isThumb2 ? ARM::t2STRB_POST : ARM::STRB_POST_IMM; |
| 6731 | UnitSize = 1; |
| 6732 | } else if (Align & 2) { |
| 6733 | ldrOpc = isThumb2 ? ARM::t2LDRH_POST : ARM::LDRH_POST; |
| 6734 | strOpc = isThumb2 ? ARM::t2STRH_POST : ARM::STRH_POST; |
| 6735 | UnitSize = 2; |
| 6736 | } else { |
Manman Ren | eda9fdf | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 6737 | // Check whether we can use NEON instructions. |
Bill Wendling | 831737d | 2012-12-30 10:32:01 +0000 | [diff] [blame] | 6738 | if (!MF->getFunction()->getAttributes(). |
| 6739 | hasAttribute(AttributeSet::FunctionIndex, |
| 6740 | Attribute::NoImplicitFloat) && |
Manman Ren | eda9fdf | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 6741 | Subtarget->hasNEON()) { |
| 6742 | if ((Align % 16 == 0) && SizeVal >= 16) { |
| 6743 | ldrOpc = ARM::VLD1q32wb_fixed; |
| 6744 | strOpc = ARM::VST1q32wb_fixed; |
| 6745 | UnitSize = 16; |
| 6746 | TRC_Vec = (const TargetRegisterClass*)&ARM::DPairRegClass; |
| 6747 | } |
| 6748 | else if ((Align % 8 == 0) && SizeVal >= 8) { |
| 6749 | ldrOpc = ARM::VLD1d32wb_fixed; |
| 6750 | strOpc = ARM::VST1d32wb_fixed; |
| 6751 | UnitSize = 8; |
| 6752 | TRC_Vec = (const TargetRegisterClass*)&ARM::DPRRegClass; |
| 6753 | } |
| 6754 | } |
| 6755 | // Can't use NEON instructions. |
| 6756 | if (UnitSize == 0) { |
| 6757 | ldrOpc = isThumb2 ? ARM::t2LDR_POST : ARM::LDR_POST_IMM; |
| 6758 | strOpc = isThumb2 ? ARM::t2STR_POST : ARM::STR_POST_IMM; |
| 6759 | UnitSize = 4; |
| 6760 | } |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 6761 | } |
Manman Ren | eda9fdf | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 6762 | |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 6763 | unsigned BytesLeft = SizeVal % UnitSize; |
| 6764 | unsigned LoopSize = SizeVal - BytesLeft; |
| 6765 | |
| 6766 | if (SizeVal <= Subtarget->getMaxInlineSizeThreshold()) { |
| 6767 | // Use LDR and STR to copy. |
| 6768 | // [scratch, srcOut] = LDR_POST(srcIn, UnitSize) |
| 6769 | // [destOut] = STR_POST(scratch, destIn, UnitSize) |
| 6770 | unsigned srcIn = src; |
| 6771 | unsigned destIn = dest; |
| 6772 | for (unsigned i = 0; i < LoopSize; i+=UnitSize) { |
Manman Ren | eda9fdf | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 6773 | unsigned scratch = MRI.createVirtualRegister(UnitSize >= 8 ? TRC_Vec:TRC); |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 6774 | unsigned srcOut = MRI.createVirtualRegister(TRC); |
| 6775 | unsigned destOut = MRI.createVirtualRegister(TRC); |
Manman Ren | eda9fdf | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 6776 | if (UnitSize >= 8) { |
| 6777 | AddDefaultPred(BuildMI(*BB, MI, dl, |
| 6778 | TII->get(ldrOpc), scratch) |
| 6779 | .addReg(srcOut, RegState::Define).addReg(srcIn).addImm(0)); |
| 6780 | |
| 6781 | AddDefaultPred(BuildMI(*BB, MI, dl, TII->get(strOpc), destOut) |
| 6782 | .addReg(destIn).addImm(0).addReg(scratch)); |
| 6783 | } else if (isThumb2) { |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 6784 | AddDefaultPred(BuildMI(*BB, MI, dl, |
| 6785 | TII->get(ldrOpc), scratch) |
| 6786 | .addReg(srcOut, RegState::Define).addReg(srcIn).addImm(UnitSize)); |
| 6787 | |
| 6788 | AddDefaultPred(BuildMI(*BB, MI, dl, TII->get(strOpc), destOut) |
| 6789 | .addReg(scratch).addReg(destIn) |
| 6790 | .addImm(UnitSize)); |
| 6791 | } else { |
| 6792 | AddDefaultPred(BuildMI(*BB, MI, dl, |
| 6793 | TII->get(ldrOpc), scratch) |
| 6794 | .addReg(srcOut, RegState::Define).addReg(srcIn).addReg(0) |
| 6795 | .addImm(UnitSize)); |
| 6796 | |
| 6797 | AddDefaultPred(BuildMI(*BB, MI, dl, TII->get(strOpc), destOut) |
| 6798 | .addReg(scratch).addReg(destIn) |
| 6799 | .addReg(0).addImm(UnitSize)); |
| 6800 | } |
| 6801 | srcIn = srcOut; |
| 6802 | destIn = destOut; |
| 6803 | } |
| 6804 | |
| 6805 | // Handle the leftover bytes with LDRB and STRB. |
| 6806 | // [scratch, srcOut] = LDRB_POST(srcIn, 1) |
| 6807 | // [destOut] = STRB_POST(scratch, destIn, 1) |
| 6808 | ldrOpc = isThumb2 ? ARM::t2LDRB_POST : ARM::LDRB_POST_IMM; |
| 6809 | strOpc = isThumb2 ? ARM::t2STRB_POST : ARM::STRB_POST_IMM; |
| 6810 | for (unsigned i = 0; i < BytesLeft; i++) { |
| 6811 | unsigned scratch = MRI.createVirtualRegister(TRC); |
| 6812 | unsigned srcOut = MRI.createVirtualRegister(TRC); |
| 6813 | unsigned destOut = MRI.createVirtualRegister(TRC); |
| 6814 | if (isThumb2) { |
| 6815 | AddDefaultPred(BuildMI(*BB, MI, dl, |
| 6816 | TII->get(ldrOpc),scratch) |
| 6817 | .addReg(srcOut, RegState::Define).addReg(srcIn).addImm(1)); |
| 6818 | |
| 6819 | AddDefaultPred(BuildMI(*BB, MI, dl, TII->get(strOpc), destOut) |
| 6820 | .addReg(scratch).addReg(destIn) |
| 6821 | .addReg(0).addImm(1)); |
| 6822 | } else { |
| 6823 | AddDefaultPred(BuildMI(*BB, MI, dl, |
| 6824 | TII->get(ldrOpc),scratch) |
Stepan Dyatkovskiy | 2c2cb3c | 2012-10-10 11:43:40 +0000 | [diff] [blame] | 6825 | .addReg(srcOut, RegState::Define).addReg(srcIn) |
| 6826 | .addReg(0).addImm(1)); |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 6827 | |
| 6828 | AddDefaultPred(BuildMI(*BB, MI, dl, TII->get(strOpc), destOut) |
| 6829 | .addReg(scratch).addReg(destIn) |
| 6830 | .addReg(0).addImm(1)); |
| 6831 | } |
| 6832 | srcIn = srcOut; |
| 6833 | destIn = destOut; |
| 6834 | } |
| 6835 | MI->eraseFromParent(); // The instruction is gone now. |
| 6836 | return BB; |
| 6837 | } |
| 6838 | |
| 6839 | // Expand the pseudo op to a loop. |
| 6840 | // thisMBB: |
| 6841 | // ... |
| 6842 | // movw varEnd, # --> with thumb2 |
| 6843 | // movt varEnd, # |
| 6844 | // ldrcp varEnd, idx --> without thumb2 |
| 6845 | // fallthrough --> loopMBB |
| 6846 | // loopMBB: |
| 6847 | // PHI varPhi, varEnd, varLoop |
| 6848 | // PHI srcPhi, src, srcLoop |
| 6849 | // PHI destPhi, dst, destLoop |
| 6850 | // [scratch, srcLoop] = LDR_POST(srcPhi, UnitSize) |
| 6851 | // [destLoop] = STR_POST(scratch, destPhi, UnitSize) |
| 6852 | // subs varLoop, varPhi, #UnitSize |
| 6853 | // bne loopMBB |
| 6854 | // fallthrough --> exitMBB |
| 6855 | // exitMBB: |
| 6856 | // epilogue to handle left-over bytes |
| 6857 | // [scratch, srcOut] = LDRB_POST(srcLoop, 1) |
| 6858 | // [destOut] = STRB_POST(scratch, destLoop, 1) |
| 6859 | MachineBasicBlock *loopMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 6860 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 6861 | MF->insert(It, loopMBB); |
| 6862 | MF->insert(It, exitMBB); |
| 6863 | |
| 6864 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 6865 | exitMBB->splice(exitMBB->begin(), BB, |
| 6866 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 6867 | BB->end()); |
| 6868 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
| 6869 | |
| 6870 | // Load an immediate to varEnd. |
| 6871 | unsigned varEnd = MRI.createVirtualRegister(TRC); |
| 6872 | if (isThumb2) { |
| 6873 | unsigned VReg1 = varEnd; |
| 6874 | if ((LoopSize & 0xFFFF0000) != 0) |
| 6875 | VReg1 = MRI.createVirtualRegister(TRC); |
| 6876 | AddDefaultPred(BuildMI(BB, dl, TII->get(ARM::t2MOVi16), VReg1) |
| 6877 | .addImm(LoopSize & 0xFFFF)); |
| 6878 | |
| 6879 | if ((LoopSize & 0xFFFF0000) != 0) |
| 6880 | AddDefaultPred(BuildMI(BB, dl, TII->get(ARM::t2MOVTi16), varEnd) |
| 6881 | .addReg(VReg1) |
| 6882 | .addImm(LoopSize >> 16)); |
| 6883 | } else { |
| 6884 | MachineConstantPool *ConstantPool = MF->getConstantPool(); |
| 6885 | Type *Int32Ty = Type::getInt32Ty(MF->getFunction()->getContext()); |
| 6886 | const Constant *C = ConstantInt::get(Int32Ty, LoopSize); |
| 6887 | |
| 6888 | // MachineConstantPool wants an explicit alignment. |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 6889 | unsigned Align = getDataLayout()->getPrefTypeAlignment(Int32Ty); |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 6890 | if (Align == 0) |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 6891 | Align = getDataLayout()->getTypeAllocSize(C->getType()); |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 6892 | unsigned Idx = ConstantPool->getConstantPoolIndex(C, Align); |
| 6893 | |
| 6894 | AddDefaultPred(BuildMI(BB, dl, TII->get(ARM::LDRcp)) |
| 6895 | .addReg(varEnd, RegState::Define) |
| 6896 | .addConstantPoolIndex(Idx) |
| 6897 | .addImm(0)); |
| 6898 | } |
| 6899 | BB->addSuccessor(loopMBB); |
| 6900 | |
| 6901 | // Generate the loop body: |
| 6902 | // varPhi = PHI(varLoop, varEnd) |
| 6903 | // srcPhi = PHI(srcLoop, src) |
| 6904 | // destPhi = PHI(destLoop, dst) |
| 6905 | MachineBasicBlock *entryBB = BB; |
| 6906 | BB = loopMBB; |
| 6907 | unsigned varLoop = MRI.createVirtualRegister(TRC); |
| 6908 | unsigned varPhi = MRI.createVirtualRegister(TRC); |
| 6909 | unsigned srcLoop = MRI.createVirtualRegister(TRC); |
| 6910 | unsigned srcPhi = MRI.createVirtualRegister(TRC); |
| 6911 | unsigned destLoop = MRI.createVirtualRegister(TRC); |
| 6912 | unsigned destPhi = MRI.createVirtualRegister(TRC); |
| 6913 | |
| 6914 | BuildMI(*BB, BB->begin(), dl, TII->get(ARM::PHI), varPhi) |
| 6915 | .addReg(varLoop).addMBB(loopMBB) |
| 6916 | .addReg(varEnd).addMBB(entryBB); |
| 6917 | BuildMI(BB, dl, TII->get(ARM::PHI), srcPhi) |
| 6918 | .addReg(srcLoop).addMBB(loopMBB) |
| 6919 | .addReg(src).addMBB(entryBB); |
| 6920 | BuildMI(BB, dl, TII->get(ARM::PHI), destPhi) |
| 6921 | .addReg(destLoop).addMBB(loopMBB) |
| 6922 | .addReg(dest).addMBB(entryBB); |
| 6923 | |
| 6924 | // [scratch, srcLoop] = LDR_POST(srcPhi, UnitSize) |
| 6925 | // [destLoop] = STR_POST(scratch, destPhi, UnitSiz) |
Manman Ren | eda9fdf | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 6926 | unsigned scratch = MRI.createVirtualRegister(UnitSize >= 8 ? TRC_Vec:TRC); |
| 6927 | if (UnitSize >= 8) { |
| 6928 | AddDefaultPred(BuildMI(BB, dl, TII->get(ldrOpc), scratch) |
| 6929 | .addReg(srcLoop, RegState::Define).addReg(srcPhi).addImm(0)); |
| 6930 | |
| 6931 | AddDefaultPred(BuildMI(BB, dl, TII->get(strOpc), destLoop) |
| 6932 | .addReg(destPhi).addImm(0).addReg(scratch)); |
| 6933 | } else if (isThumb2) { |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 6934 | AddDefaultPred(BuildMI(BB, dl, TII->get(ldrOpc), scratch) |
| 6935 | .addReg(srcLoop, RegState::Define).addReg(srcPhi).addImm(UnitSize)); |
| 6936 | |
| 6937 | AddDefaultPred(BuildMI(BB, dl, TII->get(strOpc), destLoop) |
| 6938 | .addReg(scratch).addReg(destPhi) |
| 6939 | .addImm(UnitSize)); |
| 6940 | } else { |
| 6941 | AddDefaultPred(BuildMI(BB, dl, TII->get(ldrOpc), scratch) |
| 6942 | .addReg(srcLoop, RegState::Define).addReg(srcPhi).addReg(0) |
| 6943 | .addImm(UnitSize)); |
| 6944 | |
| 6945 | AddDefaultPred(BuildMI(BB, dl, TII->get(strOpc), destLoop) |
| 6946 | .addReg(scratch).addReg(destPhi) |
| 6947 | .addReg(0).addImm(UnitSize)); |
| 6948 | } |
| 6949 | |
| 6950 | // Decrement loop variable by UnitSize. |
| 6951 | MachineInstrBuilder MIB = BuildMI(BB, dl, |
| 6952 | TII->get(isThumb2 ? ARM::t2SUBri : ARM::SUBri), varLoop); |
| 6953 | AddDefaultCC(AddDefaultPred(MIB.addReg(varPhi).addImm(UnitSize))); |
| 6954 | MIB->getOperand(5).setReg(ARM::CPSR); |
| 6955 | MIB->getOperand(5).setIsDef(true); |
| 6956 | |
| 6957 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 6958 | .addMBB(loopMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
| 6959 | |
| 6960 | // loopMBB can loop back to loopMBB or fall through to exitMBB. |
| 6961 | BB->addSuccessor(loopMBB); |
| 6962 | BB->addSuccessor(exitMBB); |
| 6963 | |
| 6964 | // Add epilogue to handle BytesLeft. |
| 6965 | BB = exitMBB; |
| 6966 | MachineInstr *StartOfExit = exitMBB->begin(); |
| 6967 | ldrOpc = isThumb2 ? ARM::t2LDRB_POST : ARM::LDRB_POST_IMM; |
| 6968 | strOpc = isThumb2 ? ARM::t2STRB_POST : ARM::STRB_POST_IMM; |
| 6969 | |
| 6970 | // [scratch, srcOut] = LDRB_POST(srcLoop, 1) |
| 6971 | // [destOut] = STRB_POST(scratch, destLoop, 1) |
| 6972 | unsigned srcIn = srcLoop; |
| 6973 | unsigned destIn = destLoop; |
| 6974 | for (unsigned i = 0; i < BytesLeft; i++) { |
| 6975 | unsigned scratch = MRI.createVirtualRegister(TRC); |
| 6976 | unsigned srcOut = MRI.createVirtualRegister(TRC); |
| 6977 | unsigned destOut = MRI.createVirtualRegister(TRC); |
| 6978 | if (isThumb2) { |
| 6979 | AddDefaultPred(BuildMI(*BB, StartOfExit, dl, |
| 6980 | TII->get(ldrOpc),scratch) |
| 6981 | .addReg(srcOut, RegState::Define).addReg(srcIn).addImm(1)); |
| 6982 | |
| 6983 | AddDefaultPred(BuildMI(*BB, StartOfExit, dl, TII->get(strOpc), destOut) |
| 6984 | .addReg(scratch).addReg(destIn) |
| 6985 | .addImm(1)); |
| 6986 | } else { |
| 6987 | AddDefaultPred(BuildMI(*BB, StartOfExit, dl, |
| 6988 | TII->get(ldrOpc),scratch) |
| 6989 | .addReg(srcOut, RegState::Define).addReg(srcIn).addReg(0).addImm(1)); |
| 6990 | |
| 6991 | AddDefaultPred(BuildMI(*BB, StartOfExit, dl, TII->get(strOpc), destOut) |
| 6992 | .addReg(scratch).addReg(destIn) |
| 6993 | .addReg(0).addImm(1)); |
| 6994 | } |
| 6995 | srcIn = srcOut; |
| 6996 | destIn = destOut; |
| 6997 | } |
| 6998 | |
| 6999 | MI->eraseFromParent(); // The instruction is gone now. |
| 7000 | return BB; |
| 7001 | } |
| 7002 | |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 7003 | MachineBasicBlock * |
Evan Cheng | ff9b373 | 2008-01-30 18:18:23 +0000 | [diff] [blame] | 7004 | ARMTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI, |
Dan Gohman | af1d8ca | 2010-05-01 00:01:06 +0000 | [diff] [blame] | 7005 | MachineBasicBlock *BB) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7006 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
Dale Johannesen | b672840 | 2009-02-13 02:25:56 +0000 | [diff] [blame] | 7007 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 7008 | bool isThumb2 = Subtarget->isThumb2(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7009 | switch (MI->getOpcode()) { |
Andrew Trick | 1c3af77 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 7010 | default: { |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 7011 | MI->dump(); |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 7012 | llvm_unreachable("Unexpected instr type to insert"); |
Andrew Trick | 1c3af77 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 7013 | } |
Jim Grosbach | ee2c2a4 | 2011-09-16 21:55:56 +0000 | [diff] [blame] | 7014 | // The Thumb2 pre-indexed stores have the same MI operands, they just |
| 7015 | // define them differently in the .td files from the isel patterns, so |
| 7016 | // they need pseudos. |
| 7017 | case ARM::t2STR_preidx: |
| 7018 | MI->setDesc(TII->get(ARM::t2STR_PRE)); |
| 7019 | return BB; |
| 7020 | case ARM::t2STRB_preidx: |
| 7021 | MI->setDesc(TII->get(ARM::t2STRB_PRE)); |
| 7022 | return BB; |
| 7023 | case ARM::t2STRH_preidx: |
| 7024 | MI->setDesc(TII->get(ARM::t2STRH_PRE)); |
| 7025 | return BB; |
| 7026 | |
Jim Grosbach | 19dec20 | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 7027 | case ARM::STRi_preidx: |
| 7028 | case ARM::STRBi_preidx: { |
Jim Grosbach | 6cd5716 | 2011-08-09 21:22:41 +0000 | [diff] [blame] | 7029 | unsigned NewOpc = MI->getOpcode() == ARM::STRi_preidx ? |
Jim Grosbach | 19dec20 | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 7030 | ARM::STR_PRE_IMM : ARM::STRB_PRE_IMM; |
| 7031 | // Decode the offset. |
| 7032 | unsigned Offset = MI->getOperand(4).getImm(); |
| 7033 | bool isSub = ARM_AM::getAM2Op(Offset) == ARM_AM::sub; |
| 7034 | Offset = ARM_AM::getAM2Offset(Offset); |
| 7035 | if (isSub) |
| 7036 | Offset = -Offset; |
| 7037 | |
Jim Grosbach | 4dfe220 | 2011-08-12 21:02:34 +0000 | [diff] [blame] | 7038 | MachineMemOperand *MMO = *MI->memoperands_begin(); |
Benjamin Kramer | 2753ae3 | 2011-08-27 17:36:14 +0000 | [diff] [blame] | 7039 | BuildMI(*BB, MI, dl, TII->get(NewOpc)) |
Jim Grosbach | 19dec20 | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 7040 | .addOperand(MI->getOperand(0)) // Rn_wb |
| 7041 | .addOperand(MI->getOperand(1)) // Rt |
| 7042 | .addOperand(MI->getOperand(2)) // Rn |
| 7043 | .addImm(Offset) // offset (skip GPR==zero_reg) |
| 7044 | .addOperand(MI->getOperand(5)) // pred |
Jim Grosbach | 4dfe220 | 2011-08-12 21:02:34 +0000 | [diff] [blame] | 7045 | .addOperand(MI->getOperand(6)) |
| 7046 | .addMemOperand(MMO); |
Jim Grosbach | 19dec20 | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 7047 | MI->eraseFromParent(); |
| 7048 | return BB; |
| 7049 | } |
| 7050 | case ARM::STRr_preidx: |
Jim Grosbach | 7b8f46c | 2011-08-11 21:17:22 +0000 | [diff] [blame] | 7051 | case ARM::STRBr_preidx: |
| 7052 | case ARM::STRH_preidx: { |
| 7053 | unsigned NewOpc; |
| 7054 | switch (MI->getOpcode()) { |
| 7055 | default: llvm_unreachable("unexpected opcode!"); |
| 7056 | case ARM::STRr_preidx: NewOpc = ARM::STR_PRE_REG; break; |
| 7057 | case ARM::STRBr_preidx: NewOpc = ARM::STRB_PRE_REG; break; |
| 7058 | case ARM::STRH_preidx: NewOpc = ARM::STRH_PRE; break; |
| 7059 | } |
Jim Grosbach | 19dec20 | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 7060 | MachineInstrBuilder MIB = BuildMI(*BB, MI, dl, TII->get(NewOpc)); |
| 7061 | for (unsigned i = 0; i < MI->getNumOperands(); ++i) |
| 7062 | MIB.addOperand(MI->getOperand(i)); |
| 7063 | MI->eraseFromParent(); |
| 7064 | return BB; |
| 7065 | } |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 7066 | case ARM::ATOMIC_LOAD_ADD_I8: |
| 7067 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr); |
| 7068 | case ARM::ATOMIC_LOAD_ADD_I16: |
| 7069 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr); |
| 7070 | case ARM::ATOMIC_LOAD_ADD_I32: |
| 7071 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 7072 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 7073 | case ARM::ATOMIC_LOAD_AND_I8: |
| 7074 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
| 7075 | case ARM::ATOMIC_LOAD_AND_I16: |
| 7076 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
| 7077 | case ARM::ATOMIC_LOAD_AND_I32: |
| 7078 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 7079 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 7080 | case ARM::ATOMIC_LOAD_OR_I8: |
| 7081 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
| 7082 | case ARM::ATOMIC_LOAD_OR_I16: |
| 7083 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
| 7084 | case ARM::ATOMIC_LOAD_OR_I32: |
| 7085 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 7086 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 7087 | case ARM::ATOMIC_LOAD_XOR_I8: |
| 7088 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
| 7089 | case ARM::ATOMIC_LOAD_XOR_I16: |
| 7090 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
| 7091 | case ARM::ATOMIC_LOAD_XOR_I32: |
| 7092 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 7093 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 7094 | case ARM::ATOMIC_LOAD_NAND_I8: |
| 7095 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2BICrr : ARM::BICrr); |
| 7096 | case ARM::ATOMIC_LOAD_NAND_I16: |
| 7097 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2BICrr : ARM::BICrr); |
| 7098 | case ARM::ATOMIC_LOAD_NAND_I32: |
| 7099 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2BICrr : ARM::BICrr); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 7100 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 7101 | case ARM::ATOMIC_LOAD_SUB_I8: |
| 7102 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr); |
| 7103 | case ARM::ATOMIC_LOAD_SUB_I16: |
| 7104 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr); |
| 7105 | case ARM::ATOMIC_LOAD_SUB_I32: |
| 7106 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 7107 | |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 7108 | case ARM::ATOMIC_LOAD_MIN_I8: |
| 7109 | return EmitAtomicBinaryMinMax(MI, BB, 1, true, ARMCC::LT); |
| 7110 | case ARM::ATOMIC_LOAD_MIN_I16: |
| 7111 | return EmitAtomicBinaryMinMax(MI, BB, 2, true, ARMCC::LT); |
| 7112 | case ARM::ATOMIC_LOAD_MIN_I32: |
| 7113 | return EmitAtomicBinaryMinMax(MI, BB, 4, true, ARMCC::LT); |
| 7114 | |
| 7115 | case ARM::ATOMIC_LOAD_MAX_I8: |
| 7116 | return EmitAtomicBinaryMinMax(MI, BB, 1, true, ARMCC::GT); |
| 7117 | case ARM::ATOMIC_LOAD_MAX_I16: |
| 7118 | return EmitAtomicBinaryMinMax(MI, BB, 2, true, ARMCC::GT); |
| 7119 | case ARM::ATOMIC_LOAD_MAX_I32: |
| 7120 | return EmitAtomicBinaryMinMax(MI, BB, 4, true, ARMCC::GT); |
| 7121 | |
| 7122 | case ARM::ATOMIC_LOAD_UMIN_I8: |
| 7123 | return EmitAtomicBinaryMinMax(MI, BB, 1, false, ARMCC::LO); |
| 7124 | case ARM::ATOMIC_LOAD_UMIN_I16: |
| 7125 | return EmitAtomicBinaryMinMax(MI, BB, 2, false, ARMCC::LO); |
| 7126 | case ARM::ATOMIC_LOAD_UMIN_I32: |
| 7127 | return EmitAtomicBinaryMinMax(MI, BB, 4, false, ARMCC::LO); |
| 7128 | |
| 7129 | case ARM::ATOMIC_LOAD_UMAX_I8: |
| 7130 | return EmitAtomicBinaryMinMax(MI, BB, 1, false, ARMCC::HI); |
| 7131 | case ARM::ATOMIC_LOAD_UMAX_I16: |
| 7132 | return EmitAtomicBinaryMinMax(MI, BB, 2, false, ARMCC::HI); |
| 7133 | case ARM::ATOMIC_LOAD_UMAX_I32: |
| 7134 | return EmitAtomicBinaryMinMax(MI, BB, 4, false, ARMCC::HI); |
| 7135 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 7136 | case ARM::ATOMIC_SWAP_I8: return EmitAtomicBinary(MI, BB, 1, 0); |
| 7137 | case ARM::ATOMIC_SWAP_I16: return EmitAtomicBinary(MI, BB, 2, 0); |
| 7138 | case ARM::ATOMIC_SWAP_I32: return EmitAtomicBinary(MI, BB, 4, 0); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 7139 | |
| 7140 | case ARM::ATOMIC_CMP_SWAP_I8: return EmitAtomicCmpSwap(MI, BB, 1); |
| 7141 | case ARM::ATOMIC_CMP_SWAP_I16: return EmitAtomicCmpSwap(MI, BB, 2); |
| 7142 | case ARM::ATOMIC_CMP_SWAP_I32: return EmitAtomicCmpSwap(MI, BB, 4); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 7143 | |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 7144 | |
| 7145 | case ARM::ATOMADD6432: |
| 7146 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr, |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 7147 | isThumb2 ? ARM::t2ADCrr : ARM::ADCrr, |
| 7148 | /*NeedsCarry*/ true); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 7149 | case ARM::ATOMSUB6432: |
| 7150 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr, |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 7151 | isThumb2 ? ARM::t2SBCrr : ARM::SBCrr, |
| 7152 | /*NeedsCarry*/ true); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 7153 | case ARM::ATOMOR6432: |
| 7154 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr, |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 7155 | isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 7156 | case ARM::ATOMXOR6432: |
| 7157 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2EORrr : ARM::EORrr, |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 7158 | isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 7159 | case ARM::ATOMAND6432: |
| 7160 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr, |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 7161 | isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 7162 | case ARM::ATOMSWAP6432: |
| 7163 | return EmitAtomicBinary64(MI, BB, 0, 0, false); |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 7164 | case ARM::ATOMCMPXCHG6432: |
| 7165 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr, |
| 7166 | isThumb2 ? ARM::t2SBCrr : ARM::SBCrr, |
| 7167 | /*NeedsCarry*/ false, /*IsCmpxchg*/true); |
Silviu Baranga | 35b3df6 | 2012-11-29 14:41:25 +0000 | [diff] [blame] | 7168 | case ARM::ATOMMIN6432: |
| 7169 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr, |
| 7170 | isThumb2 ? ARM::t2SBCrr : ARM::SBCrr, |
| 7171 | /*NeedsCarry*/ true, /*IsCmpxchg*/false, |
Silviu Baranga | 4a9256f | 2013-01-25 10:39:49 +0000 | [diff] [blame] | 7172 | /*IsMinMax*/ true, ARMCC::LT); |
Silviu Baranga | 35b3df6 | 2012-11-29 14:41:25 +0000 | [diff] [blame] | 7173 | case ARM::ATOMMAX6432: |
| 7174 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr, |
| 7175 | isThumb2 ? ARM::t2SBCrr : ARM::SBCrr, |
| 7176 | /*NeedsCarry*/ true, /*IsCmpxchg*/false, |
| 7177 | /*IsMinMax*/ true, ARMCC::GE); |
| 7178 | case ARM::ATOMUMIN6432: |
| 7179 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr, |
| 7180 | isThumb2 ? ARM::t2SBCrr : ARM::SBCrr, |
| 7181 | /*NeedsCarry*/ true, /*IsCmpxchg*/false, |
Silviu Baranga | 4a9256f | 2013-01-25 10:39:49 +0000 | [diff] [blame] | 7182 | /*IsMinMax*/ true, ARMCC::LO); |
Silviu Baranga | 35b3df6 | 2012-11-29 14:41:25 +0000 | [diff] [blame] | 7183 | case ARM::ATOMUMAX6432: |
| 7184 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr, |
| 7185 | isThumb2 ? ARM::t2SBCrr : ARM::SBCrr, |
| 7186 | /*NeedsCarry*/ true, /*IsCmpxchg*/false, |
| 7187 | /*IsMinMax*/ true, ARMCC::HS); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 7188 | |
Evan Cheng | 007ea27 | 2009-08-12 05:17:19 +0000 | [diff] [blame] | 7189 | case ARM::tMOVCCr_pseudo: { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7190 | // To "insert" a SELECT_CC instruction, we actually have to insert the |
| 7191 | // diamond control-flow pattern. The incoming instruction knows the |
| 7192 | // destination vreg to set, the condition code register to branch on, the |
| 7193 | // true/false values to select between, and a branch opcode to use. |
| 7194 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 7195 | MachineFunction::iterator It = BB; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7196 | ++It; |
| 7197 | |
| 7198 | // thisMBB: |
| 7199 | // ... |
| 7200 | // TrueVal = ... |
| 7201 | // cmpTY ccX, r1, r2 |
| 7202 | // bCC copy1MBB |
| 7203 | // fallthrough --> copy0MBB |
| 7204 | MachineBasicBlock *thisMBB = BB; |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 7205 | MachineFunction *F = BB->getParent(); |
| 7206 | MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB); |
| 7207 | MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB); |
Dan Gohman | 258c58c | 2010-07-06 15:49:48 +0000 | [diff] [blame] | 7208 | F->insert(It, copy0MBB); |
| 7209 | F->insert(It, sinkMBB); |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 7210 | |
| 7211 | // Transfer the remainder of BB and its successor edges to sinkMBB. |
| 7212 | sinkMBB->splice(sinkMBB->begin(), BB, |
| 7213 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 7214 | BB->end()); |
| 7215 | sinkMBB->transferSuccessorsAndUpdatePHIs(BB); |
| 7216 | |
Dan Gohman | 258c58c | 2010-07-06 15:49:48 +0000 | [diff] [blame] | 7217 | BB->addSuccessor(copy0MBB); |
| 7218 | BB->addSuccessor(sinkMBB); |
Dan Gohman | b81c771 | 2010-07-06 15:18:19 +0000 | [diff] [blame] | 7219 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 7220 | BuildMI(BB, dl, TII->get(ARM::tBcc)).addMBB(sinkMBB) |
| 7221 | .addImm(MI->getOperand(3).getImm()).addReg(MI->getOperand(4).getReg()); |
| 7222 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7223 | // copy0MBB: |
| 7224 | // %FalseValue = ... |
| 7225 | // # fallthrough to sinkMBB |
| 7226 | BB = copy0MBB; |
| 7227 | |
| 7228 | // Update machine-CFG edges |
| 7229 | BB->addSuccessor(sinkMBB); |
| 7230 | |
| 7231 | // sinkMBB: |
| 7232 | // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ] |
| 7233 | // ... |
| 7234 | BB = sinkMBB; |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 7235 | BuildMI(*BB, BB->begin(), dl, |
| 7236 | TII->get(ARM::PHI), MI->getOperand(0).getReg()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7237 | .addReg(MI->getOperand(1).getReg()).addMBB(copy0MBB) |
| 7238 | .addReg(MI->getOperand(2).getReg()).addMBB(thisMBB); |
| 7239 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 7240 | MI->eraseFromParent(); // The pseudo instruction is gone now. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7241 | return BB; |
| 7242 | } |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 7243 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 7244 | case ARM::BCCi64: |
| 7245 | case ARM::BCCZi64: { |
Bob Wilson | 3c90469 | 2010-12-23 22:45:49 +0000 | [diff] [blame] | 7246 | // If there is an unconditional branch to the other successor, remove it. |
| 7247 | BB->erase(llvm::next(MachineBasicBlock::iterator(MI)), BB->end()); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 7248 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 7249 | // Compare both parts that make up the double comparison separately for |
| 7250 | // equality. |
| 7251 | bool RHSisZero = MI->getOpcode() == ARM::BCCZi64; |
| 7252 | |
| 7253 | unsigned LHS1 = MI->getOperand(1).getReg(); |
| 7254 | unsigned LHS2 = MI->getOperand(2).getReg(); |
| 7255 | if (RHSisZero) { |
| 7256 | AddDefaultPred(BuildMI(BB, dl, |
| 7257 | TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 7258 | .addReg(LHS1).addImm(0)); |
| 7259 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 7260 | .addReg(LHS2).addImm(0) |
| 7261 | .addImm(ARMCC::EQ).addReg(ARM::CPSR); |
| 7262 | } else { |
| 7263 | unsigned RHS1 = MI->getOperand(3).getReg(); |
| 7264 | unsigned RHS2 = MI->getOperand(4).getReg(); |
| 7265 | AddDefaultPred(BuildMI(BB, dl, |
| 7266 | TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
| 7267 | .addReg(LHS1).addReg(RHS1)); |
| 7268 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
| 7269 | .addReg(LHS2).addReg(RHS2) |
| 7270 | .addImm(ARMCC::EQ).addReg(ARM::CPSR); |
| 7271 | } |
| 7272 | |
| 7273 | MachineBasicBlock *destMBB = MI->getOperand(RHSisZero ? 3 : 5).getMBB(); |
| 7274 | MachineBasicBlock *exitMBB = OtherSucc(BB, destMBB); |
| 7275 | if (MI->getOperand(0).getImm() == ARMCC::NE) |
| 7276 | std::swap(destMBB, exitMBB); |
| 7277 | |
| 7278 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 7279 | .addMBB(destMBB).addImm(ARMCC::EQ).addReg(ARM::CPSR); |
Owen Anderson | 51f6a7a | 2011-09-09 21:48:23 +0000 | [diff] [blame] | 7280 | if (isThumb2) |
| 7281 | AddDefaultPred(BuildMI(BB, dl, TII->get(ARM::t2B)).addMBB(exitMBB)); |
| 7282 | else |
| 7283 | BuildMI(BB, dl, TII->get(ARM::B)) .addMBB(exitMBB); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 7284 | |
| 7285 | MI->eraseFromParent(); // The pseudo instruction is gone now. |
| 7286 | return BB; |
| 7287 | } |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7288 | |
Bill Wendling | 5bc8528 | 2011-10-17 20:37:20 +0000 | [diff] [blame] | 7289 | case ARM::Int_eh_sjlj_setjmp: |
| 7290 | case ARM::Int_eh_sjlj_setjmp_nofp: |
| 7291 | case ARM::tInt_eh_sjlj_setjmp: |
| 7292 | case ARM::t2Int_eh_sjlj_setjmp: |
| 7293 | case ARM::t2Int_eh_sjlj_setjmp_nofp: |
| 7294 | EmitSjLjDispatchBlock(MI, BB); |
| 7295 | return BB; |
| 7296 | |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7297 | case ARM::ABS: |
| 7298 | case ARM::t2ABS: { |
| 7299 | // To insert an ABS instruction, we have to insert the |
| 7300 | // diamond control-flow pattern. The incoming instruction knows the |
| 7301 | // source vreg to test against 0, the destination vreg to set, |
| 7302 | // the condition code register to branch on, the |
Andrew Trick | 7f5f0da | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 7303 | // true/false values to select between, and a branch opcode to use. |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7304 | // It transforms |
| 7305 | // V1 = ABS V0 |
| 7306 | // into |
| 7307 | // V2 = MOVS V0 |
| 7308 | // BCC (branch to SinkBB if V0 >= 0) |
| 7309 | // RSBBB: V3 = RSBri V2, 0 (compute ABS if V2 < 0) |
Andrew Trick | 7f5f0da | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 7310 | // SinkBB: V1 = PHI(V2, V3) |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7311 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 7312 | MachineFunction::iterator BBI = BB; |
| 7313 | ++BBI; |
| 7314 | MachineFunction *Fn = BB->getParent(); |
| 7315 | MachineBasicBlock *RSBBB = Fn->CreateMachineBasicBlock(LLVM_BB); |
| 7316 | MachineBasicBlock *SinkBB = Fn->CreateMachineBasicBlock(LLVM_BB); |
| 7317 | Fn->insert(BBI, RSBBB); |
| 7318 | Fn->insert(BBI, SinkBB); |
| 7319 | |
| 7320 | unsigned int ABSSrcReg = MI->getOperand(1).getReg(); |
| 7321 | unsigned int ABSDstReg = MI->getOperand(0).getReg(); |
| 7322 | bool isThumb2 = Subtarget->isThumb2(); |
| 7323 | MachineRegisterInfo &MRI = Fn->getRegInfo(); |
| 7324 | // In Thumb mode S must not be specified if source register is the SP or |
| 7325 | // PC and if destination register is the SP, so restrict register class |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 7326 | unsigned NewRsbDstReg = MRI.createVirtualRegister(isThumb2 ? |
| 7327 | (const TargetRegisterClass*)&ARM::rGPRRegClass : |
| 7328 | (const TargetRegisterClass*)&ARM::GPRRegClass); |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7329 | |
| 7330 | // Transfer the remainder of BB and its successor edges to sinkMBB. |
| 7331 | SinkBB->splice(SinkBB->begin(), BB, |
| 7332 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 7333 | BB->end()); |
| 7334 | SinkBB->transferSuccessorsAndUpdatePHIs(BB); |
| 7335 | |
| 7336 | BB->addSuccessor(RSBBB); |
| 7337 | BB->addSuccessor(SinkBB); |
| 7338 | |
| 7339 | // fall through to SinkMBB |
| 7340 | RSBBB->addSuccessor(SinkBB); |
| 7341 | |
Manman Ren | 307473d | 2012-06-15 21:32:12 +0000 | [diff] [blame] | 7342 | // insert a cmp at the end of BB |
Andrew Trick | 49b446f | 2012-07-18 18:34:24 +0000 | [diff] [blame] | 7343 | AddDefaultPred(BuildMI(BB, dl, |
Manman Ren | 307473d | 2012-06-15 21:32:12 +0000 | [diff] [blame] | 7344 | TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 7345 | .addReg(ABSSrcReg).addImm(0)); |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7346 | |
| 7347 | // 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] | 7348 | BuildMI(BB, dl, |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7349 | TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)).addMBB(SinkBB) |
| 7350 | .addImm(ARMCC::getOppositeCondition(ARMCC::MI)).addReg(ARM::CPSR); |
| 7351 | |
| 7352 | // insert rsbri in RSBBB |
| 7353 | // Note: BCC and rsbri will be converted into predicated rsbmi |
| 7354 | // by if-conversion pass |
Andrew Trick | 7f5f0da | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 7355 | BuildMI(*RSBBB, RSBBB->begin(), dl, |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7356 | TII->get(isThumb2 ? ARM::t2RSBri : ARM::RSBri), NewRsbDstReg) |
Manman Ren | 307473d | 2012-06-15 21:32:12 +0000 | [diff] [blame] | 7357 | .addReg(ABSSrcReg, RegState::Kill) |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7358 | .addImm(0).addImm((unsigned)ARMCC::AL).addReg(0).addReg(0); |
| 7359 | |
Andrew Trick | 7f5f0da | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 7360 | // insert PHI in SinkBB, |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7361 | // reuse ABSDstReg to not change uses of ABS instruction |
| 7362 | BuildMI(*SinkBB, SinkBB->begin(), dl, |
| 7363 | TII->get(ARM::PHI), ABSDstReg) |
| 7364 | .addReg(NewRsbDstReg).addMBB(RSBBB) |
Manman Ren | 307473d | 2012-06-15 21:32:12 +0000 | [diff] [blame] | 7365 | .addReg(ABSSrcReg).addMBB(BB); |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7366 | |
| 7367 | // remove ABS instruction |
Andrew Trick | 7f5f0da | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 7368 | MI->eraseFromParent(); |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7369 | |
| 7370 | // return last added BB |
| 7371 | return SinkBB; |
| 7372 | } |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7373 | case ARM::COPY_STRUCT_BYVAL_I32: |
Manman Ren | 763a75d | 2012-06-01 02:44:42 +0000 | [diff] [blame] | 7374 | ++NumLoopByVals; |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7375 | return EmitStructByval(MI, BB); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7376 | } |
| 7377 | } |
| 7378 | |
Evan Cheng | 37fefc2 | 2011-08-30 19:09:48 +0000 | [diff] [blame] | 7379 | void ARMTargetLowering::AdjustInstrPostInstrSelection(MachineInstr *MI, |
| 7380 | SDNode *Node) const { |
Evan Cheng | 5a96b3d | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 7381 | if (!MI->hasPostISelHook()) { |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 7382 | assert(!convertAddSubFlagsOpcode(MI->getOpcode()) && |
| 7383 | "Pseudo flag-setting opcodes must be marked with 'hasPostISelHook'"); |
| 7384 | return; |
| 7385 | } |
| 7386 | |
Evan Cheng | 5a96b3d | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 7387 | const MCInstrDesc *MCID = &MI->getDesc(); |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7388 | // Adjust potentially 's' setting instructions after isel, i.e. ADC, SBC, RSB, |
| 7389 | // RSC. Coming out of isel, they have an implicit CPSR def, but the optional |
| 7390 | // operand is still set to noreg. If needed, set the optional operand's |
| 7391 | // register to CPSR, and remove the redundant implicit def. |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 7392 | // |
Andrew Trick | 90b7b12 | 2011-10-18 19:18:52 +0000 | [diff] [blame] | 7393 | // e.g. ADCS (..., CPSR<imp-def>) -> ADC (... opt:CPSR<def>). |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7394 | |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 7395 | // Rename pseudo opcodes. |
| 7396 | unsigned NewOpc = convertAddSubFlagsOpcode(MI->getOpcode()); |
| 7397 | if (NewOpc) { |
| 7398 | const ARMBaseInstrInfo *TII = |
| 7399 | static_cast<const ARMBaseInstrInfo*>(getTargetMachine().getInstrInfo()); |
Andrew Trick | 90b7b12 | 2011-10-18 19:18:52 +0000 | [diff] [blame] | 7400 | MCID = &TII->get(NewOpc); |
| 7401 | |
| 7402 | assert(MCID->getNumOperands() == MI->getDesc().getNumOperands() + 1 && |
| 7403 | "converted opcode should be the same except for cc_out"); |
| 7404 | |
| 7405 | MI->setDesc(*MCID); |
| 7406 | |
| 7407 | // Add the optional cc_out operand |
| 7408 | MI->addOperand(MachineOperand::CreateReg(0, /*isDef=*/true)); |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 7409 | } |
Andrew Trick | 90b7b12 | 2011-10-18 19:18:52 +0000 | [diff] [blame] | 7410 | unsigned ccOutIdx = MCID->getNumOperands() - 1; |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7411 | |
| 7412 | // Any ARM instruction that sets the 's' bit should specify an optional |
| 7413 | // "cc_out" operand in the last operand position. |
Evan Cheng | 5a96b3d | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 7414 | if (!MI->hasOptionalDef() || !MCID->OpInfo[ccOutIdx].isOptionalDef()) { |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 7415 | assert(!NewOpc && "Optional cc_out operand required"); |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7416 | return; |
| 7417 | } |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 7418 | // Look for an implicit def of CPSR added by MachineInstr ctor. Remove it |
| 7419 | // since we already have an optional CPSR def. |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7420 | bool definesCPSR = false; |
| 7421 | bool deadCPSR = false; |
Andrew Trick | 90b7b12 | 2011-10-18 19:18:52 +0000 | [diff] [blame] | 7422 | for (unsigned i = MCID->getNumOperands(), e = MI->getNumOperands(); |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7423 | i != e; ++i) { |
| 7424 | const MachineOperand &MO = MI->getOperand(i); |
| 7425 | if (MO.isReg() && MO.isDef() && MO.getReg() == ARM::CPSR) { |
| 7426 | definesCPSR = true; |
| 7427 | if (MO.isDead()) |
| 7428 | deadCPSR = true; |
| 7429 | MI->RemoveOperand(i); |
| 7430 | break; |
Evan Cheng | 37fefc2 | 2011-08-30 19:09:48 +0000 | [diff] [blame] | 7431 | } |
| 7432 | } |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7433 | if (!definesCPSR) { |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 7434 | assert(!NewOpc && "Optional cc_out operand required"); |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7435 | return; |
| 7436 | } |
| 7437 | assert(deadCPSR == !Node->hasAnyUseOfValue(1) && "inconsistent dead flag"); |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 7438 | if (deadCPSR) { |
| 7439 | assert(!MI->getOperand(ccOutIdx).getReg() && |
| 7440 | "expect uninitialized optional cc_out operand"); |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7441 | return; |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 7442 | } |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7443 | |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 7444 | // If this instruction was defined with an optional CPSR def and its dag node |
| 7445 | // had a live implicit CPSR def, then activate the optional CPSR def. |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7446 | MachineOperand &MO = MI->getOperand(ccOutIdx); |
| 7447 | MO.setReg(ARM::CPSR); |
| 7448 | MO.setIsDef(true); |
Evan Cheng | 37fefc2 | 2011-08-30 19:09:48 +0000 | [diff] [blame] | 7449 | } |
| 7450 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7451 | //===----------------------------------------------------------------------===// |
| 7452 | // ARM Optimization Hooks |
| 7453 | //===----------------------------------------------------------------------===// |
| 7454 | |
Jakob Stoklund Olesen | 1f1ab3e | 2012-08-17 16:59:09 +0000 | [diff] [blame] | 7455 | // Helper function that checks if N is a null or all ones constant. |
| 7456 | static inline bool isZeroOrAllOnes(SDValue N, bool AllOnes) { |
| 7457 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(N); |
| 7458 | if (!C) |
| 7459 | return false; |
| 7460 | return AllOnes ? C->isAllOnesValue() : C->isNullValue(); |
| 7461 | } |
| 7462 | |
Jakob Stoklund Olesen | 864c870 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 7463 | // Return true if N is conditionally 0 or all ones. |
| 7464 | // Detects these expressions where cc is an i1 value: |
| 7465 | // |
| 7466 | // (select cc 0, y) [AllOnes=0] |
| 7467 | // (select cc y, 0) [AllOnes=0] |
| 7468 | // (zext cc) [AllOnes=0] |
| 7469 | // (sext cc) [AllOnes=0/1] |
| 7470 | // (select cc -1, y) [AllOnes=1] |
| 7471 | // (select cc y, -1) [AllOnes=1] |
| 7472 | // |
| 7473 | // Invert is set when N is the null/all ones constant when CC is false. |
| 7474 | // OtherOp is set to the alternative value of N. |
| 7475 | static bool isConditionalZeroOrAllOnes(SDNode *N, bool AllOnes, |
| 7476 | SDValue &CC, bool &Invert, |
| 7477 | SDValue &OtherOp, |
| 7478 | SelectionDAG &DAG) { |
| 7479 | switch (N->getOpcode()) { |
| 7480 | default: return false; |
| 7481 | case ISD::SELECT: { |
| 7482 | CC = N->getOperand(0); |
| 7483 | SDValue N1 = N->getOperand(1); |
| 7484 | SDValue N2 = N->getOperand(2); |
| 7485 | if (isZeroOrAllOnes(N1, AllOnes)) { |
| 7486 | Invert = false; |
| 7487 | OtherOp = N2; |
| 7488 | return true; |
| 7489 | } |
| 7490 | if (isZeroOrAllOnes(N2, AllOnes)) { |
| 7491 | Invert = true; |
| 7492 | OtherOp = N1; |
| 7493 | return true; |
| 7494 | } |
| 7495 | return false; |
| 7496 | } |
| 7497 | case ISD::ZERO_EXTEND: |
| 7498 | // (zext cc) can never be the all ones value. |
| 7499 | if (AllOnes) |
| 7500 | return false; |
| 7501 | // Fall through. |
| 7502 | case ISD::SIGN_EXTEND: { |
| 7503 | EVT VT = N->getValueType(0); |
| 7504 | CC = N->getOperand(0); |
| 7505 | if (CC.getValueType() != MVT::i1) |
| 7506 | return false; |
| 7507 | Invert = !AllOnes; |
| 7508 | if (AllOnes) |
| 7509 | // When looking for an AllOnes constant, N is an sext, and the 'other' |
| 7510 | // value is 0. |
| 7511 | OtherOp = DAG.getConstant(0, VT); |
| 7512 | else if (N->getOpcode() == ISD::ZERO_EXTEND) |
| 7513 | // When looking for a 0 constant, N can be zext or sext. |
| 7514 | OtherOp = DAG.getConstant(1, VT); |
| 7515 | else |
| 7516 | OtherOp = DAG.getConstant(APInt::getAllOnesValue(VT.getSizeInBits()), VT); |
| 7517 | return true; |
| 7518 | } |
| 7519 | } |
| 7520 | } |
| 7521 | |
Jakob Stoklund Olesen | 1f1ab3e | 2012-08-17 16:59:09 +0000 | [diff] [blame] | 7522 | // Combine a constant select operand into its use: |
| 7523 | // |
Jakob Stoklund Olesen | dcd2342 | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 7524 | // (add (select cc, 0, c), x) -> (select cc, x, (add, x, c)) |
| 7525 | // (sub x, (select cc, 0, c)) -> (select cc, x, (sub, x, c)) |
| 7526 | // (and (select cc, -1, c), x) -> (select cc, x, (and, x, c)) [AllOnes=1] |
| 7527 | // (or (select cc, 0, c), x) -> (select cc, x, (or, x, c)) |
| 7528 | // (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] | 7529 | // |
| 7530 | // 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] | 7531 | // is null, or all ones when AllOnes is set. |
Jakob Stoklund Olesen | 1f1ab3e | 2012-08-17 16:59:09 +0000 | [diff] [blame] | 7532 | // |
Jakob Stoklund Olesen | 864c870 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 7533 | // Also recognize sext/zext from i1: |
| 7534 | // |
| 7535 | // (add (zext cc), x) -> (select cc (add x, 1), x) |
| 7536 | // (add (sext cc), x) -> (select cc (add x, -1), x) |
| 7537 | // |
| 7538 | // These transformations eventually create predicated instructions. |
| 7539 | // |
Jakob Stoklund Olesen | 1f1ab3e | 2012-08-17 16:59:09 +0000 | [diff] [blame] | 7540 | // @param N The node to transform. |
| 7541 | // @param Slct The N operand that is a select. |
| 7542 | // @param OtherOp The other N operand (x above). |
| 7543 | // @param DCI Context. |
Jakob Stoklund Olesen | dcd2342 | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 7544 | // @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] | 7545 | // @returns The new node, or SDValue() on failure. |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 7546 | static |
| 7547 | SDValue combineSelectAndUse(SDNode *N, SDValue Slct, SDValue OtherOp, |
Jakob Stoklund Olesen | dcd2342 | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 7548 | TargetLowering::DAGCombinerInfo &DCI, |
| 7549 | bool AllOnes = false) { |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 7550 | SelectionDAG &DAG = DCI.DAG; |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 7551 | EVT VT = N->getValueType(0); |
Jakob Stoklund Olesen | 864c870 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 7552 | SDValue NonConstantVal; |
| 7553 | SDValue CCOp; |
| 7554 | bool SwapSelectOps; |
| 7555 | if (!isConditionalZeroOrAllOnes(Slct.getNode(), AllOnes, CCOp, SwapSelectOps, |
| 7556 | NonConstantVal, DAG)) |
Jakob Stoklund Olesen | 1f1ab3e | 2012-08-17 16:59:09 +0000 | [diff] [blame] | 7557 | return SDValue(); |
| 7558 | |
Jakob Stoklund Olesen | 864c870 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 7559 | // Slct is now know to be the desired identity constant when CC is true. |
| 7560 | SDValue TrueVal = OtherOp; |
| 7561 | SDValue FalseVal = DAG.getNode(N->getOpcode(), N->getDebugLoc(), VT, |
| 7562 | OtherOp, NonConstantVal); |
| 7563 | // Unless SwapSelectOps says CC should be false. |
| 7564 | if (SwapSelectOps) |
| 7565 | std::swap(TrueVal, FalseVal); |
| 7566 | |
Jakob Stoklund Olesen | 1f1ab3e | 2012-08-17 16:59:09 +0000 | [diff] [blame] | 7567 | return DAG.getNode(ISD::SELECT, N->getDebugLoc(), VT, |
Jakob Stoklund Olesen | 864c870 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 7568 | CCOp, TrueVal, FalseVal); |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 7569 | } |
| 7570 | |
Jakob Stoklund Olesen | dcd2342 | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 7571 | // Attempt combineSelectAndUse on each operand of a commutative operator N. |
| 7572 | static |
| 7573 | SDValue combineSelectAndUseCommutative(SDNode *N, bool AllOnes, |
| 7574 | TargetLowering::DAGCombinerInfo &DCI) { |
| 7575 | SDValue N0 = N->getOperand(0); |
| 7576 | SDValue N1 = N->getOperand(1); |
Jakob Stoklund Olesen | 864c870 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 7577 | if (N0.getNode()->hasOneUse()) { |
Jakob Stoklund Olesen | dcd2342 | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 7578 | SDValue Result = combineSelectAndUse(N, N0, N1, DCI, AllOnes); |
| 7579 | if (Result.getNode()) |
| 7580 | return Result; |
| 7581 | } |
Jakob Stoklund Olesen | 864c870 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 7582 | if (N1.getNode()->hasOneUse()) { |
Jakob Stoklund Olesen | dcd2342 | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 7583 | SDValue Result = combineSelectAndUse(N, N1, N0, DCI, AllOnes); |
| 7584 | if (Result.getNode()) |
| 7585 | return Result; |
| 7586 | } |
| 7587 | return SDValue(); |
| 7588 | } |
| 7589 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7590 | // AddCombineToVPADDL- For pair-wise add on neon, use the vpaddl instruction |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7591 | // (only after legalization). |
| 7592 | static SDValue AddCombineToVPADDL(SDNode *N, SDValue N0, SDValue N1, |
| 7593 | TargetLowering::DAGCombinerInfo &DCI, |
| 7594 | const ARMSubtarget *Subtarget) { |
| 7595 | |
| 7596 | // Only perform optimization if after legalize, and if NEON is available. We |
| 7597 | // also expected both operands to be BUILD_VECTORs. |
| 7598 | if (DCI.isBeforeLegalize() || !Subtarget->hasNEON() |
| 7599 | || N0.getOpcode() != ISD::BUILD_VECTOR |
| 7600 | || N1.getOpcode() != ISD::BUILD_VECTOR) |
| 7601 | return SDValue(); |
| 7602 | |
| 7603 | // Check output type since VPADDL operand elements can only be 8, 16, or 32. |
| 7604 | EVT VT = N->getValueType(0); |
| 7605 | if (!VT.isInteger() || VT.getVectorElementType() == MVT::i64) |
| 7606 | return SDValue(); |
| 7607 | |
| 7608 | // Check that the vector operands are of the right form. |
| 7609 | // N0 and N1 are BUILD_VECTOR nodes with N number of EXTRACT_VECTOR |
| 7610 | // operands, where N is the size of the formed vector. |
| 7611 | // Each EXTRACT_VECTOR should have the same input vector and odd or even |
| 7612 | // index such that we have a pair wise add pattern. |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7613 | |
| 7614 | // Grab the vector that all EXTRACT_VECTOR nodes should be referencing. |
Bob Wilson | 7a10ab7 | 2011-06-15 06:04:34 +0000 | [diff] [blame] | 7615 | if (N0->getOperand(0)->getOpcode() != ISD::EXTRACT_VECTOR_ELT) |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7616 | return SDValue(); |
Bob Wilson | 7a10ab7 | 2011-06-15 06:04:34 +0000 | [diff] [blame] | 7617 | SDValue Vec = N0->getOperand(0)->getOperand(0); |
| 7618 | SDNode *V = Vec.getNode(); |
| 7619 | unsigned nextIndex = 0; |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7620 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7621 | // For each operands to the ADD which are BUILD_VECTORs, |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7622 | // check to see if each of their operands are an EXTRACT_VECTOR with |
| 7623 | // the same vector and appropriate index. |
| 7624 | for (unsigned i = 0, e = N0->getNumOperands(); i != e; ++i) { |
| 7625 | if (N0->getOperand(i)->getOpcode() == ISD::EXTRACT_VECTOR_ELT |
| 7626 | && N1->getOperand(i)->getOpcode() == ISD::EXTRACT_VECTOR_ELT) { |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7627 | |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7628 | SDValue ExtVec0 = N0->getOperand(i); |
| 7629 | SDValue ExtVec1 = N1->getOperand(i); |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7630 | |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7631 | // First operand is the vector, verify its the same. |
| 7632 | if (V != ExtVec0->getOperand(0).getNode() || |
| 7633 | V != ExtVec1->getOperand(0).getNode()) |
| 7634 | return SDValue(); |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7635 | |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7636 | // Second is the constant, verify its correct. |
| 7637 | ConstantSDNode *C0 = dyn_cast<ConstantSDNode>(ExtVec0->getOperand(1)); |
| 7638 | ConstantSDNode *C1 = dyn_cast<ConstantSDNode>(ExtVec1->getOperand(1)); |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7639 | |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7640 | // For the constant, we want to see all the even or all the odd. |
| 7641 | if (!C0 || !C1 || C0->getZExtValue() != nextIndex |
| 7642 | || C1->getZExtValue() != nextIndex+1) |
| 7643 | return SDValue(); |
| 7644 | |
| 7645 | // Increment index. |
| 7646 | nextIndex+=2; |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7647 | } else |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7648 | return SDValue(); |
| 7649 | } |
| 7650 | |
| 7651 | // Create VPADDL node. |
| 7652 | SelectionDAG &DAG = DCI.DAG; |
| 7653 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7654 | |
| 7655 | // Build operand list. |
| 7656 | SmallVector<SDValue, 8> Ops; |
| 7657 | Ops.push_back(DAG.getConstant(Intrinsic::arm_neon_vpaddls, |
| 7658 | TLI.getPointerTy())); |
| 7659 | |
| 7660 | // Input is the vector. |
| 7661 | Ops.push_back(Vec); |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7662 | |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7663 | // Get widened type and narrowed type. |
| 7664 | MVT widenType; |
| 7665 | unsigned numElem = VT.getVectorNumElements(); |
| 7666 | switch (VT.getVectorElementType().getSimpleVT().SimpleTy) { |
| 7667 | case MVT::i8: widenType = MVT::getVectorVT(MVT::i16, numElem); break; |
| 7668 | case MVT::i16: widenType = MVT::getVectorVT(MVT::i32, numElem); break; |
| 7669 | case MVT::i32: widenType = MVT::getVectorVT(MVT::i64, numElem); break; |
| 7670 | default: |
Craig Topper | bc21981 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 7671 | llvm_unreachable("Invalid vector element type for padd optimization."); |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7672 | } |
| 7673 | |
| 7674 | SDValue tmp = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, N->getDebugLoc(), |
| 7675 | widenType, &Ops[0], Ops.size()); |
| 7676 | return DAG.getNode(ISD::TRUNCATE, N->getDebugLoc(), VT, tmp); |
| 7677 | } |
| 7678 | |
Arnold Schwaighofer | 67514e9 | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 7679 | static SDValue findMUL_LOHI(SDValue V) { |
| 7680 | if (V->getOpcode() == ISD::UMUL_LOHI || |
| 7681 | V->getOpcode() == ISD::SMUL_LOHI) |
| 7682 | return V; |
| 7683 | return SDValue(); |
| 7684 | } |
| 7685 | |
| 7686 | static SDValue AddCombineTo64bitMLAL(SDNode *AddcNode, |
| 7687 | TargetLowering::DAGCombinerInfo &DCI, |
| 7688 | const ARMSubtarget *Subtarget) { |
| 7689 | |
| 7690 | if (Subtarget->isThumb1Only()) return SDValue(); |
| 7691 | |
| 7692 | // Only perform the checks after legalize when the pattern is available. |
| 7693 | if (DCI.isBeforeLegalize()) return SDValue(); |
| 7694 | |
| 7695 | // Look for multiply add opportunities. |
| 7696 | // The pattern is a ISD::UMUL_LOHI followed by two add nodes, where |
| 7697 | // each add nodes consumes a value from ISD::UMUL_LOHI and there is |
| 7698 | // a glue link from the first add to the second add. |
| 7699 | // If we find this pattern, we can replace the U/SMUL_LOHI, ADDC, and ADDE by |
| 7700 | // a S/UMLAL instruction. |
| 7701 | // loAdd UMUL_LOHI |
| 7702 | // \ / :lo \ :hi |
| 7703 | // \ / \ [no multiline comment] |
| 7704 | // ADDC | hiAdd |
| 7705 | // \ :glue / / |
| 7706 | // \ / / |
| 7707 | // ADDE |
| 7708 | // |
| 7709 | assert(AddcNode->getOpcode() == ISD::ADDC && "Expect an ADDC"); |
| 7710 | SDValue AddcOp0 = AddcNode->getOperand(0); |
| 7711 | SDValue AddcOp1 = AddcNode->getOperand(1); |
| 7712 | |
| 7713 | // Check if the two operands are from the same mul_lohi node. |
| 7714 | if (AddcOp0.getNode() == AddcOp1.getNode()) |
| 7715 | return SDValue(); |
| 7716 | |
| 7717 | assert(AddcNode->getNumValues() == 2 && |
| 7718 | AddcNode->getValueType(0) == MVT::i32 && |
| 7719 | AddcNode->getValueType(1) == MVT::Glue && |
| 7720 | "Expect ADDC with two result values: i32, glue"); |
| 7721 | |
| 7722 | // Check that the ADDC adds the low result of the S/UMUL_LOHI. |
| 7723 | if (AddcOp0->getOpcode() != ISD::UMUL_LOHI && |
| 7724 | AddcOp0->getOpcode() != ISD::SMUL_LOHI && |
| 7725 | AddcOp1->getOpcode() != ISD::UMUL_LOHI && |
| 7726 | AddcOp1->getOpcode() != ISD::SMUL_LOHI) |
| 7727 | return SDValue(); |
| 7728 | |
| 7729 | // Look for the glued ADDE. |
| 7730 | SDNode* AddeNode = AddcNode->getGluedUser(); |
| 7731 | if (AddeNode == NULL) |
| 7732 | return SDValue(); |
| 7733 | |
| 7734 | // Make sure it is really an ADDE. |
| 7735 | if (AddeNode->getOpcode() != ISD::ADDE) |
| 7736 | return SDValue(); |
| 7737 | |
| 7738 | assert(AddeNode->getNumOperands() == 3 && |
| 7739 | AddeNode->getOperand(2).getValueType() == MVT::Glue && |
| 7740 | "ADDE node has the wrong inputs"); |
| 7741 | |
| 7742 | // Check for the triangle shape. |
| 7743 | SDValue AddeOp0 = AddeNode->getOperand(0); |
| 7744 | SDValue AddeOp1 = AddeNode->getOperand(1); |
| 7745 | |
| 7746 | // Make sure that the ADDE operands are not coming from the same node. |
| 7747 | if (AddeOp0.getNode() == AddeOp1.getNode()) |
| 7748 | return SDValue(); |
| 7749 | |
| 7750 | // Find the MUL_LOHI node walking up ADDE's operands. |
| 7751 | bool IsLeftOperandMUL = false; |
| 7752 | SDValue MULOp = findMUL_LOHI(AddeOp0); |
| 7753 | if (MULOp == SDValue()) |
| 7754 | MULOp = findMUL_LOHI(AddeOp1); |
| 7755 | else |
| 7756 | IsLeftOperandMUL = true; |
| 7757 | if (MULOp == SDValue()) |
| 7758 | return SDValue(); |
| 7759 | |
| 7760 | // Figure out the right opcode. |
| 7761 | unsigned Opc = MULOp->getOpcode(); |
| 7762 | unsigned FinalOpc = (Opc == ISD::SMUL_LOHI) ? ARMISD::SMLAL : ARMISD::UMLAL; |
| 7763 | |
| 7764 | // Figure out the high and low input values to the MLAL node. |
| 7765 | SDValue* HiMul = &MULOp; |
| 7766 | SDValue* HiAdd = NULL; |
| 7767 | SDValue* LoMul = NULL; |
| 7768 | SDValue* LowAdd = NULL; |
| 7769 | |
| 7770 | if (IsLeftOperandMUL) |
| 7771 | HiAdd = &AddeOp1; |
| 7772 | else |
| 7773 | HiAdd = &AddeOp0; |
| 7774 | |
| 7775 | |
| 7776 | if (AddcOp0->getOpcode() == Opc) { |
| 7777 | LoMul = &AddcOp0; |
| 7778 | LowAdd = &AddcOp1; |
| 7779 | } |
| 7780 | if (AddcOp1->getOpcode() == Opc) { |
| 7781 | LoMul = &AddcOp1; |
| 7782 | LowAdd = &AddcOp0; |
| 7783 | } |
| 7784 | |
| 7785 | if (LoMul == NULL) |
| 7786 | return SDValue(); |
| 7787 | |
| 7788 | if (LoMul->getNode() != HiMul->getNode()) |
| 7789 | return SDValue(); |
| 7790 | |
| 7791 | // Create the merged node. |
| 7792 | SelectionDAG &DAG = DCI.DAG; |
| 7793 | |
| 7794 | // Build operand list. |
| 7795 | SmallVector<SDValue, 8> Ops; |
| 7796 | Ops.push_back(LoMul->getOperand(0)); |
| 7797 | Ops.push_back(LoMul->getOperand(1)); |
| 7798 | Ops.push_back(*LowAdd); |
| 7799 | Ops.push_back(*HiAdd); |
| 7800 | |
| 7801 | SDValue MLALNode = DAG.getNode(FinalOpc, AddcNode->getDebugLoc(), |
| 7802 | DAG.getVTList(MVT::i32, MVT::i32), |
| 7803 | &Ops[0], Ops.size()); |
| 7804 | |
| 7805 | // Replace the ADDs' nodes uses by the MLA node's values. |
| 7806 | SDValue HiMLALResult(MLALNode.getNode(), 1); |
| 7807 | DAG.ReplaceAllUsesOfValueWith(SDValue(AddeNode, 0), HiMLALResult); |
| 7808 | |
| 7809 | SDValue LoMLALResult(MLALNode.getNode(), 0); |
| 7810 | DAG.ReplaceAllUsesOfValueWith(SDValue(AddcNode, 0), LoMLALResult); |
| 7811 | |
| 7812 | // Return original node to notify the driver to stop replacing. |
| 7813 | SDValue resNode(AddcNode, 0); |
| 7814 | return resNode; |
| 7815 | } |
| 7816 | |
| 7817 | /// PerformADDCCombine - Target-specific dag combine transform from |
| 7818 | /// ISD::ADDC, ISD::ADDE, and ISD::MUL_LOHI to MLAL. |
| 7819 | static SDValue PerformADDCCombine(SDNode *N, |
| 7820 | TargetLowering::DAGCombinerInfo &DCI, |
| 7821 | const ARMSubtarget *Subtarget) { |
| 7822 | |
| 7823 | return AddCombineTo64bitMLAL(N, DCI, Subtarget); |
| 7824 | |
| 7825 | } |
| 7826 | |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 7827 | /// PerformADDCombineWithOperands - Try DAG combinations for an ADD with |
| 7828 | /// operands N0 and N1. This is a helper for PerformADDCombine that is |
| 7829 | /// called with the default operands, and if that fails, with commuted |
| 7830 | /// operands. |
| 7831 | static SDValue PerformADDCombineWithOperands(SDNode *N, SDValue N0, SDValue N1, |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7832 | TargetLowering::DAGCombinerInfo &DCI, |
| 7833 | const ARMSubtarget *Subtarget){ |
| 7834 | |
| 7835 | // Attempt to create vpaddl for this add. |
| 7836 | SDValue Result = AddCombineToVPADDL(N, N0, N1, DCI, Subtarget); |
| 7837 | if (Result.getNode()) |
| 7838 | return Result; |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7839 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 7840 | // 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] | 7841 | if (N0.getNode()->hasOneUse()) { |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 7842 | SDValue Result = combineSelectAndUse(N, N0, N1, DCI); |
| 7843 | if (Result.getNode()) return Result; |
| 7844 | } |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 7845 | return SDValue(); |
| 7846 | } |
| 7847 | |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 7848 | /// PerformADDCombine - Target-specific dag combine xforms for ISD::ADD. |
| 7849 | /// |
| 7850 | static SDValue PerformADDCombine(SDNode *N, |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7851 | TargetLowering::DAGCombinerInfo &DCI, |
| 7852 | const ARMSubtarget *Subtarget) { |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 7853 | SDValue N0 = N->getOperand(0); |
| 7854 | SDValue N1 = N->getOperand(1); |
| 7855 | |
| 7856 | // First try with the default operand order. |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7857 | SDValue Result = PerformADDCombineWithOperands(N, N0, N1, DCI, Subtarget); |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 7858 | if (Result.getNode()) |
| 7859 | return Result; |
| 7860 | |
| 7861 | // If that didn't work, try again with the operands commuted. |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7862 | return PerformADDCombineWithOperands(N, N1, N0, DCI, Subtarget); |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 7863 | } |
| 7864 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 7865 | /// PerformSUBCombine - Target-specific dag combine xforms for ISD::SUB. |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 7866 | /// |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 7867 | static SDValue PerformSUBCombine(SDNode *N, |
| 7868 | TargetLowering::DAGCombinerInfo &DCI) { |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 7869 | SDValue N0 = N->getOperand(0); |
| 7870 | SDValue N1 = N->getOperand(1); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 7871 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 7872 | // 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] | 7873 | if (N1.getNode()->hasOneUse()) { |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 7874 | SDValue Result = combineSelectAndUse(N, N1, N0, DCI); |
| 7875 | if (Result.getNode()) return Result; |
| 7876 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 7877 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 7878 | return SDValue(); |
| 7879 | } |
| 7880 | |
Evan Cheng | 463d358 | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 7881 | /// PerformVMULCombine |
| 7882 | /// Distribute (A + B) * C to (A * C) + (B * C) to take advantage of the |
| 7883 | /// special multiplier accumulator forwarding. |
| 7884 | /// vmul d3, d0, d2 |
| 7885 | /// vmla d3, d1, d2 |
| 7886 | /// is faster than |
| 7887 | /// vadd d3, d0, d1 |
| 7888 | /// vmul d3, d3, d2 |
| 7889 | static SDValue PerformVMULCombine(SDNode *N, |
| 7890 | TargetLowering::DAGCombinerInfo &DCI, |
| 7891 | const ARMSubtarget *Subtarget) { |
| 7892 | if (!Subtarget->hasVMLxForwarding()) |
| 7893 | return SDValue(); |
| 7894 | |
| 7895 | SelectionDAG &DAG = DCI.DAG; |
| 7896 | SDValue N0 = N->getOperand(0); |
| 7897 | SDValue N1 = N->getOperand(1); |
| 7898 | unsigned Opcode = N0.getOpcode(); |
| 7899 | if (Opcode != ISD::ADD && Opcode != ISD::SUB && |
| 7900 | Opcode != ISD::FADD && Opcode != ISD::FSUB) { |
Chad Rosier | 689edc8 | 2011-06-16 01:21:54 +0000 | [diff] [blame] | 7901 | Opcode = N1.getOpcode(); |
Evan Cheng | 463d358 | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 7902 | if (Opcode != ISD::ADD && Opcode != ISD::SUB && |
| 7903 | Opcode != ISD::FADD && Opcode != ISD::FSUB) |
| 7904 | return SDValue(); |
| 7905 | std::swap(N0, N1); |
| 7906 | } |
| 7907 | |
| 7908 | EVT VT = N->getValueType(0); |
| 7909 | DebugLoc DL = N->getDebugLoc(); |
| 7910 | SDValue N00 = N0->getOperand(0); |
| 7911 | SDValue N01 = N0->getOperand(1); |
| 7912 | return DAG.getNode(Opcode, DL, VT, |
| 7913 | DAG.getNode(ISD::MUL, DL, VT, N00, N1), |
| 7914 | DAG.getNode(ISD::MUL, DL, VT, N01, N1)); |
| 7915 | } |
| 7916 | |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 7917 | static SDValue PerformMULCombine(SDNode *N, |
| 7918 | TargetLowering::DAGCombinerInfo &DCI, |
| 7919 | const ARMSubtarget *Subtarget) { |
| 7920 | SelectionDAG &DAG = DCI.DAG; |
| 7921 | |
| 7922 | if (Subtarget->isThumb1Only()) |
| 7923 | return SDValue(); |
| 7924 | |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 7925 | if (DCI.isBeforeLegalize() || DCI.isCalledByLegalizer()) |
| 7926 | return SDValue(); |
| 7927 | |
| 7928 | EVT VT = N->getValueType(0); |
Evan Cheng | 463d358 | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 7929 | if (VT.is64BitVector() || VT.is128BitVector()) |
| 7930 | return PerformVMULCombine(N, DCI, Subtarget); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 7931 | if (VT != MVT::i32) |
| 7932 | return SDValue(); |
| 7933 | |
| 7934 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1)); |
| 7935 | if (!C) |
| 7936 | return SDValue(); |
| 7937 | |
Anton Korobeynikov | 2d7ea04 | 2012-03-19 19:19:50 +0000 | [diff] [blame] | 7938 | int64_t MulAmt = C->getSExtValue(); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 7939 | unsigned ShiftAmt = CountTrailingZeros_64(MulAmt); |
Anton Korobeynikov | 2d7ea04 | 2012-03-19 19:19:50 +0000 | [diff] [blame] | 7940 | |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 7941 | ShiftAmt = ShiftAmt & (32 - 1); |
| 7942 | SDValue V = N->getOperand(0); |
| 7943 | DebugLoc DL = N->getDebugLoc(); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 7944 | |
Anton Korobeynikov | 4878b84 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 7945 | SDValue Res; |
| 7946 | MulAmt >>= ShiftAmt; |
Anton Korobeynikov | 2d7ea04 | 2012-03-19 19:19:50 +0000 | [diff] [blame] | 7947 | |
| 7948 | if (MulAmt >= 0) { |
| 7949 | if (isPowerOf2_32(MulAmt - 1)) { |
| 7950 | // (mul x, 2^N + 1) => (add (shl x, N), x) |
| 7951 | Res = DAG.getNode(ISD::ADD, DL, VT, |
| 7952 | V, |
| 7953 | DAG.getNode(ISD::SHL, DL, VT, |
| 7954 | V, |
| 7955 | DAG.getConstant(Log2_32(MulAmt - 1), |
| 7956 | MVT::i32))); |
| 7957 | } else if (isPowerOf2_32(MulAmt + 1)) { |
| 7958 | // (mul x, 2^N - 1) => (sub (shl x, N), x) |
| 7959 | Res = DAG.getNode(ISD::SUB, DL, VT, |
| 7960 | DAG.getNode(ISD::SHL, DL, VT, |
| 7961 | V, |
| 7962 | DAG.getConstant(Log2_32(MulAmt + 1), |
| 7963 | MVT::i32)), |
| 7964 | V); |
| 7965 | } else |
| 7966 | return SDValue(); |
| 7967 | } else { |
| 7968 | uint64_t MulAmtAbs = -MulAmt; |
| 7969 | if (isPowerOf2_32(MulAmtAbs + 1)) { |
| 7970 | // (mul x, -(2^N - 1)) => (sub x, (shl x, N)) |
| 7971 | Res = DAG.getNode(ISD::SUB, DL, VT, |
| 7972 | V, |
| 7973 | DAG.getNode(ISD::SHL, DL, VT, |
| 7974 | V, |
| 7975 | DAG.getConstant(Log2_32(MulAmtAbs + 1), |
| 7976 | MVT::i32))); |
| 7977 | } else if (isPowerOf2_32(MulAmtAbs - 1)) { |
| 7978 | // (mul x, -(2^N + 1)) => - (add (shl x, N), x) |
| 7979 | Res = DAG.getNode(ISD::ADD, DL, VT, |
| 7980 | V, |
| 7981 | DAG.getNode(ISD::SHL, DL, VT, |
| 7982 | V, |
| 7983 | DAG.getConstant(Log2_32(MulAmtAbs-1), |
| 7984 | MVT::i32))); |
| 7985 | Res = DAG.getNode(ISD::SUB, DL, VT, |
| 7986 | DAG.getConstant(0, MVT::i32),Res); |
| 7987 | |
| 7988 | } else |
| 7989 | return SDValue(); |
| 7990 | } |
Anton Korobeynikov | 4878b84 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 7991 | |
| 7992 | if (ShiftAmt != 0) |
Anton Korobeynikov | 2d7ea04 | 2012-03-19 19:19:50 +0000 | [diff] [blame] | 7993 | Res = DAG.getNode(ISD::SHL, DL, VT, |
| 7994 | Res, DAG.getConstant(ShiftAmt, MVT::i32)); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 7995 | |
| 7996 | // Do not add new nodes to DAG combiner worklist. |
Anton Korobeynikov | 4878b84 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 7997 | DCI.CombineTo(N, Res, false); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 7998 | return SDValue(); |
| 7999 | } |
| 8000 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 8001 | static SDValue PerformANDCombine(SDNode *N, |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 8002 | TargetLowering::DAGCombinerInfo &DCI, |
| 8003 | const ARMSubtarget *Subtarget) { |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 8004 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 8005 | // Attempt to use immediate-form VBIC |
| 8006 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(N->getOperand(1)); |
| 8007 | DebugLoc dl = N->getDebugLoc(); |
| 8008 | EVT VT = N->getValueType(0); |
| 8009 | SelectionDAG &DAG = DCI.DAG; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8010 | |
Tanya Lattner | 0433b21 | 2011-04-07 15:24:20 +0000 | [diff] [blame] | 8011 | if(!DAG.getTargetLoweringInfo().isTypeLegal(VT)) |
| 8012 | return SDValue(); |
Andrew Trick | 1c3af77 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 8013 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 8014 | APInt SplatBits, SplatUndef; |
| 8015 | unsigned SplatBitSize; |
| 8016 | bool HasAnyUndefs; |
| 8017 | if (BVN && |
| 8018 | BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { |
| 8019 | if (SplatBitSize <= 64) { |
| 8020 | EVT VbicVT; |
| 8021 | SDValue Val = isNEONModifiedImm((~SplatBits).getZExtValue(), |
| 8022 | SplatUndef.getZExtValue(), SplatBitSize, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8023 | DAG, VbicVT, VT.is128BitVector(), |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 8024 | OtherModImm); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 8025 | if (Val.getNode()) { |
| 8026 | SDValue Input = |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8027 | DAG.getNode(ISD::BITCAST, dl, VbicVT, N->getOperand(0)); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 8028 | SDValue Vbic = DAG.getNode(ARMISD::VBICIMM, dl, VbicVT, Input, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8029 | return DAG.getNode(ISD::BITCAST, dl, VT, Vbic); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 8030 | } |
| 8031 | } |
| 8032 | } |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8033 | |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 8034 | if (!Subtarget->isThumb1Only()) { |
Jakob Stoklund Olesen | dcd2342 | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 8035 | // fold (and (select cc, -1, c), x) -> (select cc, x, (and, x, c)) |
| 8036 | SDValue Result = combineSelectAndUseCommutative(N, true, DCI); |
| 8037 | if (Result.getNode()) |
| 8038 | return Result; |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 8039 | } |
| 8040 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 8041 | return SDValue(); |
| 8042 | } |
| 8043 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8044 | /// PerformORCombine - Target-specific dag combine xforms for ISD::OR |
| 8045 | static SDValue PerformORCombine(SDNode *N, |
| 8046 | TargetLowering::DAGCombinerInfo &DCI, |
| 8047 | const ARMSubtarget *Subtarget) { |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 8048 | // Attempt to use immediate-form VORR |
| 8049 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(N->getOperand(1)); |
| 8050 | DebugLoc dl = N->getDebugLoc(); |
| 8051 | EVT VT = N->getValueType(0); |
| 8052 | SelectionDAG &DAG = DCI.DAG; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8053 | |
Tanya Lattner | 0433b21 | 2011-04-07 15:24:20 +0000 | [diff] [blame] | 8054 | if(!DAG.getTargetLoweringInfo().isTypeLegal(VT)) |
| 8055 | return SDValue(); |
Andrew Trick | 1c3af77 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 8056 | |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 8057 | APInt SplatBits, SplatUndef; |
| 8058 | unsigned SplatBitSize; |
| 8059 | bool HasAnyUndefs; |
| 8060 | if (BVN && Subtarget->hasNEON() && |
| 8061 | BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { |
| 8062 | if (SplatBitSize <= 64) { |
| 8063 | EVT VorrVT; |
| 8064 | SDValue Val = isNEONModifiedImm(SplatBits.getZExtValue(), |
| 8065 | SplatUndef.getZExtValue(), SplatBitSize, |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 8066 | DAG, VorrVT, VT.is128BitVector(), |
| 8067 | OtherModImm); |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 8068 | if (Val.getNode()) { |
| 8069 | SDValue Input = |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8070 | DAG.getNode(ISD::BITCAST, dl, VorrVT, N->getOperand(0)); |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 8071 | SDValue Vorr = DAG.getNode(ARMISD::VORRIMM, dl, VorrVT, Input, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8072 | return DAG.getNode(ISD::BITCAST, dl, VT, Vorr); |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 8073 | } |
| 8074 | } |
| 8075 | } |
| 8076 | |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 8077 | if (!Subtarget->isThumb1Only()) { |
Jakob Stoklund Olesen | dcd2342 | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 8078 | // fold (or (select cc, 0, c), x) -> (select cc, x, (or, 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 | |
Nadav Rotem | df83203 | 2012-08-13 18:52:44 +0000 | [diff] [blame] | 8084 | // The code below optimizes (or (and X, Y), Z). |
| 8085 | // The AND operand needs to have a single user to make these optimizations |
| 8086 | // profitable. |
Cameron Zwarich | c0e6d78 | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 8087 | SDValue N0 = N->getOperand(0); |
Nadav Rotem | df83203 | 2012-08-13 18:52:44 +0000 | [diff] [blame] | 8088 | if (N0.getOpcode() != ISD::AND || !N0.hasOneUse()) |
Cameron Zwarich | c0e6d78 | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 8089 | return SDValue(); |
| 8090 | SDValue N1 = N->getOperand(1); |
| 8091 | |
| 8092 | // (or (and B, A), (and C, ~A)) => (VBSL A, B, C) when A is a constant. |
| 8093 | if (Subtarget->hasNEON() && N1.getOpcode() == ISD::AND && VT.isVector() && |
| 8094 | DAG.getTargetLoweringInfo().isTypeLegal(VT)) { |
| 8095 | APInt SplatUndef; |
| 8096 | unsigned SplatBitSize; |
| 8097 | bool HasAnyUndefs; |
| 8098 | |
| 8099 | BuildVectorSDNode *BVN0 = dyn_cast<BuildVectorSDNode>(N0->getOperand(1)); |
| 8100 | APInt SplatBits0; |
| 8101 | if (BVN0 && BVN0->isConstantSplat(SplatBits0, SplatUndef, SplatBitSize, |
| 8102 | HasAnyUndefs) && !HasAnyUndefs) { |
| 8103 | BuildVectorSDNode *BVN1 = dyn_cast<BuildVectorSDNode>(N1->getOperand(1)); |
| 8104 | APInt SplatBits1; |
| 8105 | if (BVN1 && BVN1->isConstantSplat(SplatBits1, SplatUndef, SplatBitSize, |
| 8106 | HasAnyUndefs) && !HasAnyUndefs && |
| 8107 | SplatBits0 == ~SplatBits1) { |
| 8108 | // Canonicalize the vector type to make instruction selection simpler. |
| 8109 | EVT CanonicalVT = VT.is128BitVector() ? MVT::v4i32 : MVT::v2i32; |
| 8110 | SDValue Result = DAG.getNode(ARMISD::VBSL, dl, CanonicalVT, |
| 8111 | N0->getOperand(1), N0->getOperand(0), |
Cameron Zwarich | 5af60ce | 2011-04-13 21:01:19 +0000 | [diff] [blame] | 8112 | N1->getOperand(0)); |
Cameron Zwarich | c0e6d78 | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 8113 | return DAG.getNode(ISD::BITCAST, dl, VT, Result); |
| 8114 | } |
| 8115 | } |
| 8116 | } |
| 8117 | |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8118 | // Try to use the ARM/Thumb2 BFI (bitfield insert) instruction when |
| 8119 | // reasonable. |
| 8120 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8121 | // BFI is only available on V6T2+ |
| 8122 | if (Subtarget->isThumb1Only() || !Subtarget->hasV6T2Ops()) |
| 8123 | return SDValue(); |
| 8124 | |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8125 | DebugLoc DL = N->getDebugLoc(); |
| 8126 | // 1) or (and A, mask), val => ARMbfi A, val, mask |
Sylvestre Ledru | 94c2271 | 2012-09-27 10:14:43 +0000 | [diff] [blame] | 8127 | // iff (val & mask) == val |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8128 | // |
| 8129 | // 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] | 8130 | // 2a) iff isBitFieldInvertedMask(mask) && isBitFieldInvertedMask(~mask2) |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 8131 | // && mask == ~mask2 |
Sylvestre Ledru | 94c2271 | 2012-09-27 10:14:43 +0000 | [diff] [blame] | 8132 | // 2b) iff isBitFieldInvertedMask(~mask) && isBitFieldInvertedMask(mask2) |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 8133 | // && ~mask == mask2 |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8134 | // (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] | 8135 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8136 | if (VT != MVT::i32) |
| 8137 | return SDValue(); |
| 8138 | |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8139 | SDValue N00 = N0.getOperand(0); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8140 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8141 | // The value and the mask need to be constants so we can verify this is |
| 8142 | // actually a bitfield set. If the mask is 0xffff, we can do better |
| 8143 | // via a movt instruction, so don't use BFI in that case. |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8144 | SDValue MaskOp = N0.getOperand(1); |
| 8145 | ConstantSDNode *MaskC = dyn_cast<ConstantSDNode>(MaskOp); |
| 8146 | if (!MaskC) |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8147 | return SDValue(); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8148 | unsigned Mask = MaskC->getZExtValue(); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8149 | if (Mask == 0xffff) |
| 8150 | return SDValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8151 | SDValue Res; |
| 8152 | // Case (1): or (and A, mask), val => ARMbfi A, val, mask |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8153 | ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1); |
| 8154 | if (N1C) { |
| 8155 | unsigned Val = N1C->getZExtValue(); |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 8156 | if ((Val & ~Mask) != Val) |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8157 | return SDValue(); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8158 | |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 8159 | if (ARM::isBitFieldInvertedMask(Mask)) { |
| 8160 | Val >>= CountTrailingZeros_32(~Mask); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8161 | |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8162 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N00, |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 8163 | DAG.getConstant(Val, MVT::i32), |
| 8164 | DAG.getConstant(Mask, MVT::i32)); |
| 8165 | |
| 8166 | // Do not add new nodes to DAG combiner worklist. |
| 8167 | DCI.CombineTo(N, Res, false); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8168 | return SDValue(); |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 8169 | } |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8170 | } else if (N1.getOpcode() == ISD::AND) { |
| 8171 | // 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] | 8172 | ConstantSDNode *N11C = dyn_cast<ConstantSDNode>(N1.getOperand(1)); |
| 8173 | if (!N11C) |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8174 | return SDValue(); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8175 | unsigned Mask2 = N11C->getZExtValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8176 | |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 8177 | // Mask and ~Mask2 (or reverse) must be equivalent for the BFI pattern |
| 8178 | // as is to match. |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8179 | if (ARM::isBitFieldInvertedMask(Mask) && |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 8180 | (Mask == ~Mask2)) { |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8181 | // The pack halfword instruction works better for masks that fit it, |
| 8182 | // so use that when it's available. |
| 8183 | if (Subtarget->hasT2ExtractPack() && |
| 8184 | (Mask == 0xffff || Mask == 0xffff0000)) |
| 8185 | return SDValue(); |
| 8186 | // 2a |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 8187 | unsigned amt = CountTrailingZeros_32(Mask2); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8188 | Res = DAG.getNode(ISD::SRL, DL, VT, N1.getOperand(0), |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 8189 | DAG.getConstant(amt, MVT::i32)); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8190 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N00, Res, |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8191 | DAG.getConstant(Mask, MVT::i32)); |
| 8192 | // Do not add new nodes to DAG combiner worklist. |
| 8193 | DCI.CombineTo(N, Res, false); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8194 | return SDValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8195 | } else if (ARM::isBitFieldInvertedMask(~Mask) && |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 8196 | (~Mask == Mask2)) { |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8197 | // The pack halfword instruction works better for masks that fit it, |
| 8198 | // so use that when it's available. |
| 8199 | if (Subtarget->hasT2ExtractPack() && |
| 8200 | (Mask2 == 0xffff || Mask2 == 0xffff0000)) |
| 8201 | return SDValue(); |
| 8202 | // 2b |
| 8203 | unsigned lsb = CountTrailingZeros_32(Mask); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8204 | Res = DAG.getNode(ISD::SRL, DL, VT, N00, |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8205 | DAG.getConstant(lsb, MVT::i32)); |
| 8206 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N1.getOperand(0), Res, |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 8207 | DAG.getConstant(Mask2, MVT::i32)); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8208 | // Do not add new nodes to DAG combiner worklist. |
| 8209 | DCI.CombineTo(N, Res, false); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8210 | return SDValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8211 | } |
| 8212 | } |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8213 | |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8214 | if (DAG.MaskedValueIsZero(N1, MaskC->getAPIntValue()) && |
| 8215 | N00.getOpcode() == ISD::SHL && isa<ConstantSDNode>(N00.getOperand(1)) && |
| 8216 | ARM::isBitFieldInvertedMask(~Mask)) { |
| 8217 | // Case (3): or (and (shl A, #shamt), mask), B => ARMbfi B, A, ~mask |
| 8218 | // where lsb(mask) == #shamt and masked bits of B are known zero. |
| 8219 | SDValue ShAmt = N00.getOperand(1); |
| 8220 | unsigned ShAmtC = cast<ConstantSDNode>(ShAmt)->getZExtValue(); |
| 8221 | unsigned LSB = CountTrailingZeros_32(Mask); |
| 8222 | if (ShAmtC != LSB) |
| 8223 | return SDValue(); |
| 8224 | |
| 8225 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N1, N00.getOperand(0), |
| 8226 | DAG.getConstant(~Mask, MVT::i32)); |
| 8227 | |
| 8228 | // Do not add new nodes to DAG combiner worklist. |
| 8229 | DCI.CombineTo(N, Res, false); |
| 8230 | } |
| 8231 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8232 | return SDValue(); |
| 8233 | } |
| 8234 | |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 8235 | static SDValue PerformXORCombine(SDNode *N, |
| 8236 | TargetLowering::DAGCombinerInfo &DCI, |
| 8237 | const ARMSubtarget *Subtarget) { |
| 8238 | EVT VT = N->getValueType(0); |
| 8239 | SelectionDAG &DAG = DCI.DAG; |
| 8240 | |
| 8241 | if(!DAG.getTargetLoweringInfo().isTypeLegal(VT)) |
| 8242 | return SDValue(); |
| 8243 | |
| 8244 | if (!Subtarget->isThumb1Only()) { |
Jakob Stoklund Olesen | dcd2342 | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 8245 | // fold (xor (select cc, 0, c), x) -> (select cc, x, (xor, x, c)) |
| 8246 | SDValue Result = combineSelectAndUseCommutative(N, false, DCI); |
| 8247 | if (Result.getNode()) |
| 8248 | return Result; |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 8249 | } |
| 8250 | |
| 8251 | return SDValue(); |
| 8252 | } |
| 8253 | |
Evan Cheng | bf188ae | 2011-06-15 01:12:31 +0000 | [diff] [blame] | 8254 | /// PerformBFICombine - (bfi A, (and B, Mask1), Mask2) -> (bfi A, B, Mask2) iff |
| 8255 | /// 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] | 8256 | static SDValue PerformBFICombine(SDNode *N, |
| 8257 | TargetLowering::DAGCombinerInfo &DCI) { |
| 8258 | SDValue N1 = N->getOperand(1); |
| 8259 | if (N1.getOpcode() == ISD::AND) { |
| 8260 | ConstantSDNode *N11C = dyn_cast<ConstantSDNode>(N1.getOperand(1)); |
| 8261 | if (!N11C) |
| 8262 | return SDValue(); |
Evan Cheng | bf188ae | 2011-06-15 01:12:31 +0000 | [diff] [blame] | 8263 | unsigned InvMask = cast<ConstantSDNode>(N->getOperand(2))->getZExtValue(); |
| 8264 | unsigned LSB = CountTrailingZeros_32(~InvMask); |
| 8265 | unsigned Width = (32 - CountLeadingZeros_32(~InvMask)) - LSB; |
| 8266 | unsigned Mask = (1 << Width)-1; |
Evan Cheng | 0c1aec1 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 8267 | unsigned Mask2 = N11C->getZExtValue(); |
Evan Cheng | bf188ae | 2011-06-15 01:12:31 +0000 | [diff] [blame] | 8268 | if ((Mask & (~Mask2)) == 0) |
Evan Cheng | 0c1aec1 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 8269 | return DCI.DAG.getNode(ARMISD::BFI, N->getDebugLoc(), N->getValueType(0), |
| 8270 | N->getOperand(0), N1.getOperand(0), |
| 8271 | N->getOperand(2)); |
| 8272 | } |
| 8273 | return SDValue(); |
| 8274 | } |
| 8275 | |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 8276 | /// PerformVMOVRRDCombine - Target-specific dag combine xforms for |
| 8277 | /// ARMISD::VMOVRRD. |
| 8278 | static SDValue PerformVMOVRRDCombine(SDNode *N, |
| 8279 | TargetLowering::DAGCombinerInfo &DCI) { |
| 8280 | // vmovrrd(vmovdrr x, y) -> x,y |
| 8281 | SDValue InDouble = N->getOperand(0); |
| 8282 | if (InDouble.getOpcode() == ARMISD::VMOVDRR) |
| 8283 | return DCI.CombineTo(N, InDouble.getOperand(0), InDouble.getOperand(1)); |
Cameron Zwarich | 4071a71 | 2011-04-02 02:40:43 +0000 | [diff] [blame] | 8284 | |
| 8285 | // vmovrrd(load f64) -> (load i32), (load i32) |
| 8286 | SDNode *InNode = InDouble.getNode(); |
| 8287 | if (ISD::isNormalLoad(InNode) && InNode->hasOneUse() && |
| 8288 | InNode->getValueType(0) == MVT::f64 && |
| 8289 | InNode->getOperand(1).getOpcode() == ISD::FrameIndex && |
| 8290 | !cast<LoadSDNode>(InNode)->isVolatile()) { |
| 8291 | // TODO: Should this be done for non-FrameIndex operands? |
| 8292 | LoadSDNode *LD = cast<LoadSDNode>(InNode); |
| 8293 | |
| 8294 | SelectionDAG &DAG = DCI.DAG; |
| 8295 | DebugLoc DL = LD->getDebugLoc(); |
| 8296 | SDValue BasePtr = LD->getBasePtr(); |
| 8297 | SDValue NewLD1 = DAG.getLoad(MVT::i32, DL, LD->getChain(), BasePtr, |
| 8298 | LD->getPointerInfo(), LD->isVolatile(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 8299 | LD->isNonTemporal(), LD->isInvariant(), |
| 8300 | LD->getAlignment()); |
Cameron Zwarich | 4071a71 | 2011-04-02 02:40:43 +0000 | [diff] [blame] | 8301 | |
| 8302 | SDValue OffsetPtr = DAG.getNode(ISD::ADD, DL, MVT::i32, BasePtr, |
| 8303 | DAG.getConstant(4, MVT::i32)); |
| 8304 | SDValue NewLD2 = DAG.getLoad(MVT::i32, DL, NewLD1.getValue(1), OffsetPtr, |
| 8305 | LD->getPointerInfo(), LD->isVolatile(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 8306 | LD->isNonTemporal(), LD->isInvariant(), |
Cameron Zwarich | 4071a71 | 2011-04-02 02:40:43 +0000 | [diff] [blame] | 8307 | std::min(4U, LD->getAlignment() / 2)); |
| 8308 | |
| 8309 | DAG.ReplaceAllUsesOfValueWith(SDValue(LD, 1), NewLD2.getValue(1)); |
| 8310 | SDValue Result = DCI.CombineTo(N, NewLD1, NewLD2); |
| 8311 | DCI.RemoveFromWorklist(LD); |
| 8312 | DAG.DeleteNode(LD); |
| 8313 | return Result; |
| 8314 | } |
| 8315 | |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 8316 | return SDValue(); |
| 8317 | } |
| 8318 | |
| 8319 | /// PerformVMOVDRRCombine - Target-specific dag combine xforms for |
| 8320 | /// ARMISD::VMOVDRR. This is also used for BUILD_VECTORs with 2 operands. |
| 8321 | static SDValue PerformVMOVDRRCombine(SDNode *N, SelectionDAG &DAG) { |
| 8322 | // N=vmovrrd(X); vmovdrr(N:0, N:1) -> bit_convert(X) |
| 8323 | SDValue Op0 = N->getOperand(0); |
| 8324 | SDValue Op1 = N->getOperand(1); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8325 | if (Op0.getOpcode() == ISD::BITCAST) |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 8326 | Op0 = Op0.getOperand(0); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8327 | if (Op1.getOpcode() == ISD::BITCAST) |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 8328 | Op1 = Op1.getOperand(0); |
| 8329 | if (Op0.getOpcode() == ARMISD::VMOVRRD && |
| 8330 | Op0.getNode() == Op1.getNode() && |
| 8331 | Op0.getResNo() == 0 && Op1.getResNo() == 1) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8332 | return DAG.getNode(ISD::BITCAST, N->getDebugLoc(), |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 8333 | N->getValueType(0), Op0.getOperand(0)); |
| 8334 | return SDValue(); |
| 8335 | } |
| 8336 | |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 8337 | /// PerformSTORECombine - Target-specific dag combine xforms for |
| 8338 | /// ISD::STORE. |
| 8339 | static SDValue PerformSTORECombine(SDNode *N, |
| 8340 | TargetLowering::DAGCombinerInfo &DCI) { |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 8341 | StoreSDNode *St = cast<StoreSDNode>(N); |
Chad Rosier | 7f35455 | 2012-04-09 20:32:02 +0000 | [diff] [blame] | 8342 | if (St->isVolatile()) |
| 8343 | return SDValue(); |
| 8344 | |
Andrew Trick | 49b446f | 2012-07-18 18:34:24 +0000 | [diff] [blame] | 8345 | // Optimize trunc store (of multiple scalars) to shuffle and store. First, |
Chad Rosier | 7f35455 | 2012-04-09 20:32:02 +0000 | [diff] [blame] | 8346 | // pack all of the elements in one place. Next, store to memory in fewer |
| 8347 | // chunks. |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 8348 | SDValue StVal = St->getValue(); |
Chad Rosier | 7f35455 | 2012-04-09 20:32:02 +0000 | [diff] [blame] | 8349 | EVT VT = StVal.getValueType(); |
| 8350 | if (St->isTruncatingStore() && VT.isVector()) { |
| 8351 | SelectionDAG &DAG = DCI.DAG; |
| 8352 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 8353 | EVT StVT = St->getMemoryVT(); |
| 8354 | unsigned NumElems = VT.getVectorNumElements(); |
| 8355 | assert(StVT != VT && "Cannot truncate to the same type"); |
| 8356 | unsigned FromEltSz = VT.getVectorElementType().getSizeInBits(); |
| 8357 | unsigned ToEltSz = StVT.getVectorElementType().getSizeInBits(); |
| 8358 | |
| 8359 | // From, To sizes and ElemCount must be pow of two |
| 8360 | if (!isPowerOf2_32(NumElems * FromEltSz * ToEltSz)) return SDValue(); |
| 8361 | |
| 8362 | // We are going to use the original vector elt for storing. |
| 8363 | // Accumulated smaller vector elements must be a multiple of the store size. |
| 8364 | if (0 != (NumElems * FromEltSz) % ToEltSz) return SDValue(); |
| 8365 | |
| 8366 | unsigned SizeRatio = FromEltSz / ToEltSz; |
| 8367 | assert(SizeRatio * NumElems * ToEltSz == VT.getSizeInBits()); |
| 8368 | |
| 8369 | // Create a type on which we perform the shuffle. |
| 8370 | EVT WideVecVT = EVT::getVectorVT(*DAG.getContext(), StVT.getScalarType(), |
| 8371 | NumElems*SizeRatio); |
| 8372 | assert(WideVecVT.getSizeInBits() == VT.getSizeInBits()); |
| 8373 | |
| 8374 | DebugLoc DL = St->getDebugLoc(); |
| 8375 | SDValue WideVec = DAG.getNode(ISD::BITCAST, DL, WideVecVT, StVal); |
| 8376 | SmallVector<int, 8> ShuffleVec(NumElems * SizeRatio, -1); |
| 8377 | for (unsigned i = 0; i < NumElems; ++i) ShuffleVec[i] = i * SizeRatio; |
| 8378 | |
| 8379 | // Can't shuffle using an illegal type. |
| 8380 | if (!TLI.isTypeLegal(WideVecVT)) return SDValue(); |
| 8381 | |
| 8382 | SDValue Shuff = DAG.getVectorShuffle(WideVecVT, DL, WideVec, |
| 8383 | DAG.getUNDEF(WideVec.getValueType()), |
| 8384 | ShuffleVec.data()); |
| 8385 | // At this point all of the data is stored at the bottom of the |
| 8386 | // register. We now need to save it to mem. |
| 8387 | |
| 8388 | // Find the largest store unit |
| 8389 | MVT StoreType = MVT::i8; |
| 8390 | for (unsigned tp = MVT::FIRST_INTEGER_VALUETYPE; |
| 8391 | tp < MVT::LAST_INTEGER_VALUETYPE; ++tp) { |
| 8392 | MVT Tp = (MVT::SimpleValueType)tp; |
| 8393 | if (TLI.isTypeLegal(Tp) && Tp.getSizeInBits() <= NumElems * ToEltSz) |
| 8394 | StoreType = Tp; |
| 8395 | } |
| 8396 | // Didn't find a legal store type. |
| 8397 | if (!TLI.isTypeLegal(StoreType)) |
| 8398 | return SDValue(); |
| 8399 | |
| 8400 | // Bitcast the original vector into a vector of store-size units |
| 8401 | EVT StoreVecVT = EVT::getVectorVT(*DAG.getContext(), |
| 8402 | StoreType, VT.getSizeInBits()/EVT(StoreType).getSizeInBits()); |
| 8403 | assert(StoreVecVT.getSizeInBits() == VT.getSizeInBits()); |
| 8404 | SDValue ShuffWide = DAG.getNode(ISD::BITCAST, DL, StoreVecVT, Shuff); |
| 8405 | SmallVector<SDValue, 8> Chains; |
| 8406 | SDValue Increment = DAG.getConstant(StoreType.getSizeInBits()/8, |
| 8407 | TLI.getPointerTy()); |
| 8408 | SDValue BasePtr = St->getBasePtr(); |
| 8409 | |
| 8410 | // Perform one or more big stores into memory. |
| 8411 | unsigned E = (ToEltSz*NumElems)/StoreType.getSizeInBits(); |
| 8412 | for (unsigned I = 0; I < E; I++) { |
| 8413 | SDValue SubVec = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, |
| 8414 | StoreType, ShuffWide, |
| 8415 | DAG.getIntPtrConstant(I)); |
| 8416 | SDValue Ch = DAG.getStore(St->getChain(), DL, SubVec, BasePtr, |
| 8417 | St->getPointerInfo(), St->isVolatile(), |
| 8418 | St->isNonTemporal(), St->getAlignment()); |
| 8419 | BasePtr = DAG.getNode(ISD::ADD, DL, BasePtr.getValueType(), BasePtr, |
| 8420 | Increment); |
| 8421 | Chains.push_back(Ch); |
| 8422 | } |
| 8423 | return DAG.getNode(ISD::TokenFactor, DL, MVT::Other, &Chains[0], |
| 8424 | Chains.size()); |
| 8425 | } |
| 8426 | |
| 8427 | if (!ISD::isNormalStore(St)) |
Cameron Zwarich | d0aacbc | 2011-04-12 02:24:17 +0000 | [diff] [blame] | 8428 | return SDValue(); |
| 8429 | |
Chad Rosier | 96b66d6 | 2012-04-09 19:38:15 +0000 | [diff] [blame] | 8430 | // Split a store of a VMOVDRR into two integer stores to avoid mixing NEON and |
| 8431 | // ARM stores of arguments in the same cache line. |
Cameron Zwarich | d0aacbc | 2011-04-12 02:24:17 +0000 | [diff] [blame] | 8432 | if (StVal.getNode()->getOpcode() == ARMISD::VMOVDRR && |
Chad Rosier | 96b66d6 | 2012-04-09 19:38:15 +0000 | [diff] [blame] | 8433 | StVal.getNode()->hasOneUse()) { |
Cameron Zwarich | d0aacbc | 2011-04-12 02:24:17 +0000 | [diff] [blame] | 8434 | SelectionDAG &DAG = DCI.DAG; |
| 8435 | DebugLoc DL = St->getDebugLoc(); |
| 8436 | SDValue BasePtr = St->getBasePtr(); |
| 8437 | SDValue NewST1 = DAG.getStore(St->getChain(), DL, |
| 8438 | StVal.getNode()->getOperand(0), BasePtr, |
| 8439 | St->getPointerInfo(), St->isVolatile(), |
| 8440 | St->isNonTemporal(), St->getAlignment()); |
| 8441 | |
| 8442 | SDValue OffsetPtr = DAG.getNode(ISD::ADD, DL, MVT::i32, BasePtr, |
| 8443 | DAG.getConstant(4, MVT::i32)); |
| 8444 | return DAG.getStore(NewST1.getValue(0), DL, StVal.getNode()->getOperand(1), |
| 8445 | OffsetPtr, St->getPointerInfo(), St->isVolatile(), |
| 8446 | St->isNonTemporal(), |
| 8447 | std::min(4U, St->getAlignment() / 2)); |
| 8448 | } |
| 8449 | |
| 8450 | if (StVal.getValueType() != MVT::i64 || |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 8451 | StVal.getNode()->getOpcode() != ISD::EXTRACT_VECTOR_ELT) |
| 8452 | return SDValue(); |
| 8453 | |
Chad Rosier | 96b66d6 | 2012-04-09 19:38:15 +0000 | [diff] [blame] | 8454 | // Bitcast an i64 store extracted from a vector to f64. |
| 8455 | // 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] | 8456 | SelectionDAG &DAG = DCI.DAG; |
| 8457 | DebugLoc dl = StVal.getDebugLoc(); |
| 8458 | SDValue IntVec = StVal.getOperand(0); |
| 8459 | EVT FloatVT = EVT::getVectorVT(*DAG.getContext(), MVT::f64, |
| 8460 | IntVec.getValueType().getVectorNumElements()); |
| 8461 | SDValue Vec = DAG.getNode(ISD::BITCAST, dl, FloatVT, IntVec); |
| 8462 | SDValue ExtElt = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, |
| 8463 | Vec, StVal.getOperand(1)); |
| 8464 | dl = N->getDebugLoc(); |
| 8465 | SDValue V = DAG.getNode(ISD::BITCAST, dl, MVT::i64, ExtElt); |
| 8466 | // Make the DAGCombiner fold the bitcasts. |
| 8467 | DCI.AddToWorklist(Vec.getNode()); |
| 8468 | DCI.AddToWorklist(ExtElt.getNode()); |
| 8469 | DCI.AddToWorklist(V.getNode()); |
| 8470 | return DAG.getStore(St->getChain(), dl, V, St->getBasePtr(), |
| 8471 | St->getPointerInfo(), St->isVolatile(), |
| 8472 | St->isNonTemporal(), St->getAlignment(), |
| 8473 | St->getTBAAInfo()); |
| 8474 | } |
| 8475 | |
| 8476 | /// hasNormalLoadOperand - Check if any of the operands of a BUILD_VECTOR node |
| 8477 | /// are normal, non-volatile loads. If so, it is profitable to bitcast an |
| 8478 | /// i64 vector to have f64 elements, since the value can then be loaded |
| 8479 | /// directly into a VFP register. |
| 8480 | static bool hasNormalLoadOperand(SDNode *N) { |
| 8481 | unsigned NumElts = N->getValueType(0).getVectorNumElements(); |
| 8482 | for (unsigned i = 0; i < NumElts; ++i) { |
| 8483 | SDNode *Elt = N->getOperand(i).getNode(); |
| 8484 | if (ISD::isNormalLoad(Elt) && !cast<LoadSDNode>(Elt)->isVolatile()) |
| 8485 | return true; |
| 8486 | } |
| 8487 | return false; |
| 8488 | } |
| 8489 | |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 8490 | /// PerformBUILD_VECTORCombine - Target-specific dag combine xforms for |
| 8491 | /// ISD::BUILD_VECTOR. |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 8492 | static SDValue PerformBUILD_VECTORCombine(SDNode *N, |
| 8493 | TargetLowering::DAGCombinerInfo &DCI){ |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 8494 | // build_vector(N=ARMISD::VMOVRRD(X), N:1) -> bit_convert(X): |
| 8495 | // VMOVRRD is introduced when legalizing i64 types. It forces the i64 value |
| 8496 | // into a pair of GPRs, which is fine when the value is used as a scalar, |
| 8497 | // 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] | 8498 | SelectionDAG &DAG = DCI.DAG; |
| 8499 | if (N->getNumOperands() == 2) { |
| 8500 | SDValue RV = PerformVMOVDRRCombine(N, DAG); |
| 8501 | if (RV.getNode()) |
| 8502 | return RV; |
| 8503 | } |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 8504 | |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 8505 | // Load i64 elements as f64 values so that type legalization does not split |
| 8506 | // them up into i32 values. |
| 8507 | EVT VT = N->getValueType(0); |
| 8508 | if (VT.getVectorElementType() != MVT::i64 || !hasNormalLoadOperand(N)) |
| 8509 | return SDValue(); |
| 8510 | DebugLoc dl = N->getDebugLoc(); |
| 8511 | SmallVector<SDValue, 8> Ops; |
| 8512 | unsigned NumElts = VT.getVectorNumElements(); |
| 8513 | for (unsigned i = 0; i < NumElts; ++i) { |
| 8514 | SDValue V = DAG.getNode(ISD::BITCAST, dl, MVT::f64, N->getOperand(i)); |
| 8515 | Ops.push_back(V); |
| 8516 | // Make the DAGCombiner fold the bitcast. |
| 8517 | DCI.AddToWorklist(V.getNode()); |
| 8518 | } |
| 8519 | EVT FloatVT = EVT::getVectorVT(*DAG.getContext(), MVT::f64, NumElts); |
| 8520 | SDValue BV = DAG.getNode(ISD::BUILD_VECTOR, dl, FloatVT, Ops.data(), NumElts); |
| 8521 | return DAG.getNode(ISD::BITCAST, dl, VT, BV); |
| 8522 | } |
| 8523 | |
| 8524 | /// PerformInsertEltCombine - Target-specific dag combine xforms for |
| 8525 | /// ISD::INSERT_VECTOR_ELT. |
| 8526 | static SDValue PerformInsertEltCombine(SDNode *N, |
| 8527 | TargetLowering::DAGCombinerInfo &DCI) { |
| 8528 | // Bitcast an i64 load inserted into a vector to f64. |
| 8529 | // Otherwise, the i64 value will be legalized to a pair of i32 values. |
| 8530 | EVT VT = N->getValueType(0); |
| 8531 | SDNode *Elt = N->getOperand(1).getNode(); |
| 8532 | if (VT.getVectorElementType() != MVT::i64 || |
| 8533 | !ISD::isNormalLoad(Elt) || cast<LoadSDNode>(Elt)->isVolatile()) |
| 8534 | return SDValue(); |
| 8535 | |
| 8536 | SelectionDAG &DAG = DCI.DAG; |
| 8537 | DebugLoc dl = N->getDebugLoc(); |
| 8538 | EVT FloatVT = EVT::getVectorVT(*DAG.getContext(), MVT::f64, |
| 8539 | VT.getVectorNumElements()); |
| 8540 | SDValue Vec = DAG.getNode(ISD::BITCAST, dl, FloatVT, N->getOperand(0)); |
| 8541 | SDValue V = DAG.getNode(ISD::BITCAST, dl, MVT::f64, N->getOperand(1)); |
| 8542 | // Make the DAGCombiner fold the bitcasts. |
| 8543 | DCI.AddToWorklist(Vec.getNode()); |
| 8544 | DCI.AddToWorklist(V.getNode()); |
| 8545 | SDValue InsElt = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, FloatVT, |
| 8546 | Vec, V, N->getOperand(2)); |
| 8547 | return DAG.getNode(ISD::BITCAST, dl, VT, InsElt); |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 8548 | } |
| 8549 | |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 8550 | /// PerformVECTOR_SHUFFLECombine - Target-specific dag combine xforms for |
| 8551 | /// ISD::VECTOR_SHUFFLE. |
| 8552 | static SDValue PerformVECTOR_SHUFFLECombine(SDNode *N, SelectionDAG &DAG) { |
| 8553 | // The LLVM shufflevector instruction does not require the shuffle mask |
| 8554 | // length to match the operand vector length, but ISD::VECTOR_SHUFFLE does |
| 8555 | // have that requirement. When translating to ISD::VECTOR_SHUFFLE, if the |
| 8556 | // operands do not match the mask length, they are extended by concatenating |
| 8557 | // them with undef vectors. That is probably the right thing for other |
| 8558 | // targets, but for NEON it is better to concatenate two double-register |
| 8559 | // size vector operands into a single quad-register size vector. Do that |
| 8560 | // transformation here: |
| 8561 | // shuffle(concat(v1, undef), concat(v2, undef)) -> |
| 8562 | // shuffle(concat(v1, v2), undef) |
| 8563 | SDValue Op0 = N->getOperand(0); |
| 8564 | SDValue Op1 = N->getOperand(1); |
| 8565 | if (Op0.getOpcode() != ISD::CONCAT_VECTORS || |
| 8566 | Op1.getOpcode() != ISD::CONCAT_VECTORS || |
| 8567 | Op0.getNumOperands() != 2 || |
| 8568 | Op1.getNumOperands() != 2) |
| 8569 | return SDValue(); |
| 8570 | SDValue Concat0Op1 = Op0.getOperand(1); |
| 8571 | SDValue Concat1Op1 = Op1.getOperand(1); |
| 8572 | if (Concat0Op1.getOpcode() != ISD::UNDEF || |
| 8573 | Concat1Op1.getOpcode() != ISD::UNDEF) |
| 8574 | return SDValue(); |
| 8575 | // Skip the transformation if any of the types are illegal. |
| 8576 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 8577 | EVT VT = N->getValueType(0); |
| 8578 | if (!TLI.isTypeLegal(VT) || |
| 8579 | !TLI.isTypeLegal(Concat0Op1.getValueType()) || |
| 8580 | !TLI.isTypeLegal(Concat1Op1.getValueType())) |
| 8581 | return SDValue(); |
| 8582 | |
| 8583 | SDValue NewConcat = DAG.getNode(ISD::CONCAT_VECTORS, N->getDebugLoc(), VT, |
| 8584 | Op0.getOperand(0), Op1.getOperand(0)); |
| 8585 | // Translate the shuffle mask. |
| 8586 | SmallVector<int, 16> NewMask; |
| 8587 | unsigned NumElts = VT.getVectorNumElements(); |
| 8588 | unsigned HalfElts = NumElts/2; |
| 8589 | ShuffleVectorSDNode *SVN = cast<ShuffleVectorSDNode>(N); |
| 8590 | for (unsigned n = 0; n < NumElts; ++n) { |
| 8591 | int MaskElt = SVN->getMaskElt(n); |
| 8592 | int NewElt = -1; |
Bob Wilson | 1fa9d30 | 2010-10-27 23:49:00 +0000 | [diff] [blame] | 8593 | if (MaskElt < (int)HalfElts) |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 8594 | NewElt = MaskElt; |
Bob Wilson | 1fa9d30 | 2010-10-27 23:49:00 +0000 | [diff] [blame] | 8595 | else if (MaskElt >= (int)NumElts && MaskElt < (int)(NumElts + HalfElts)) |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 8596 | NewElt = HalfElts + MaskElt - NumElts; |
| 8597 | NewMask.push_back(NewElt); |
| 8598 | } |
| 8599 | return DAG.getVectorShuffle(VT, N->getDebugLoc(), NewConcat, |
| 8600 | DAG.getUNDEF(VT), NewMask.data()); |
| 8601 | } |
| 8602 | |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 8603 | /// CombineBaseUpdate - Target-specific DAG combine function for VLDDUP and |
| 8604 | /// NEON load/store intrinsics to merge base address updates. |
| 8605 | static SDValue CombineBaseUpdate(SDNode *N, |
| 8606 | TargetLowering::DAGCombinerInfo &DCI) { |
| 8607 | if (DCI.isBeforeLegalize() || DCI.isCalledByLegalizer()) |
| 8608 | return SDValue(); |
| 8609 | |
| 8610 | SelectionDAG &DAG = DCI.DAG; |
| 8611 | bool isIntrinsic = (N->getOpcode() == ISD::INTRINSIC_VOID || |
| 8612 | N->getOpcode() == ISD::INTRINSIC_W_CHAIN); |
| 8613 | unsigned AddrOpIdx = (isIntrinsic ? 2 : 1); |
| 8614 | SDValue Addr = N->getOperand(AddrOpIdx); |
| 8615 | |
| 8616 | // Search for a use of the address operand that is an increment. |
| 8617 | for (SDNode::use_iterator UI = Addr.getNode()->use_begin(), |
| 8618 | UE = Addr.getNode()->use_end(); UI != UE; ++UI) { |
| 8619 | SDNode *User = *UI; |
| 8620 | if (User->getOpcode() != ISD::ADD || |
| 8621 | UI.getUse().getResNo() != Addr.getResNo()) |
| 8622 | continue; |
| 8623 | |
| 8624 | // Check that the add is independent of the load/store. Otherwise, folding |
| 8625 | // it would create a cycle. |
| 8626 | if (User->isPredecessorOf(N) || N->isPredecessorOf(User)) |
| 8627 | continue; |
| 8628 | |
| 8629 | // Find the new opcode for the updating load/store. |
| 8630 | bool isLoad = true; |
| 8631 | bool isLaneOp = false; |
| 8632 | unsigned NewOpc = 0; |
| 8633 | unsigned NumVecs = 0; |
| 8634 | if (isIntrinsic) { |
| 8635 | unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue(); |
| 8636 | switch (IntNo) { |
Craig Topper | bc21981 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 8637 | default: llvm_unreachable("unexpected intrinsic for Neon base update"); |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 8638 | case Intrinsic::arm_neon_vld1: NewOpc = ARMISD::VLD1_UPD; |
| 8639 | NumVecs = 1; break; |
| 8640 | case Intrinsic::arm_neon_vld2: NewOpc = ARMISD::VLD2_UPD; |
| 8641 | NumVecs = 2; break; |
| 8642 | case Intrinsic::arm_neon_vld3: NewOpc = ARMISD::VLD3_UPD; |
| 8643 | NumVecs = 3; break; |
| 8644 | case Intrinsic::arm_neon_vld4: NewOpc = ARMISD::VLD4_UPD; |
| 8645 | NumVecs = 4; break; |
| 8646 | case Intrinsic::arm_neon_vld2lane: NewOpc = ARMISD::VLD2LN_UPD; |
| 8647 | NumVecs = 2; isLaneOp = true; break; |
| 8648 | case Intrinsic::arm_neon_vld3lane: NewOpc = ARMISD::VLD3LN_UPD; |
| 8649 | NumVecs = 3; isLaneOp = true; break; |
| 8650 | case Intrinsic::arm_neon_vld4lane: NewOpc = ARMISD::VLD4LN_UPD; |
| 8651 | NumVecs = 4; isLaneOp = true; break; |
| 8652 | case Intrinsic::arm_neon_vst1: NewOpc = ARMISD::VST1_UPD; |
| 8653 | NumVecs = 1; isLoad = false; break; |
| 8654 | case Intrinsic::arm_neon_vst2: NewOpc = ARMISD::VST2_UPD; |
| 8655 | NumVecs = 2; isLoad = false; break; |
| 8656 | case Intrinsic::arm_neon_vst3: NewOpc = ARMISD::VST3_UPD; |
| 8657 | NumVecs = 3; isLoad = false; break; |
| 8658 | case Intrinsic::arm_neon_vst4: NewOpc = ARMISD::VST4_UPD; |
| 8659 | NumVecs = 4; isLoad = false; break; |
| 8660 | case Intrinsic::arm_neon_vst2lane: NewOpc = ARMISD::VST2LN_UPD; |
| 8661 | NumVecs = 2; isLoad = false; isLaneOp = true; break; |
| 8662 | case Intrinsic::arm_neon_vst3lane: NewOpc = ARMISD::VST3LN_UPD; |
| 8663 | NumVecs = 3; isLoad = false; isLaneOp = true; break; |
| 8664 | case Intrinsic::arm_neon_vst4lane: NewOpc = ARMISD::VST4LN_UPD; |
| 8665 | NumVecs = 4; isLoad = false; isLaneOp = true; break; |
| 8666 | } |
| 8667 | } else { |
| 8668 | isLaneOp = true; |
| 8669 | switch (N->getOpcode()) { |
Craig Topper | bc21981 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 8670 | default: llvm_unreachable("unexpected opcode for Neon base update"); |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 8671 | case ARMISD::VLD2DUP: NewOpc = ARMISD::VLD2DUP_UPD; NumVecs = 2; break; |
| 8672 | case ARMISD::VLD3DUP: NewOpc = ARMISD::VLD3DUP_UPD; NumVecs = 3; break; |
| 8673 | case ARMISD::VLD4DUP: NewOpc = ARMISD::VLD4DUP_UPD; NumVecs = 4; break; |
| 8674 | } |
| 8675 | } |
| 8676 | |
| 8677 | // Find the size of memory referenced by the load/store. |
| 8678 | EVT VecTy; |
| 8679 | if (isLoad) |
| 8680 | VecTy = N->getValueType(0); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 8681 | else |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 8682 | VecTy = N->getOperand(AddrOpIdx+1).getValueType(); |
| 8683 | unsigned NumBytes = NumVecs * VecTy.getSizeInBits() / 8; |
| 8684 | if (isLaneOp) |
| 8685 | NumBytes /= VecTy.getVectorNumElements(); |
| 8686 | |
| 8687 | // If the increment is a constant, it must match the memory ref size. |
| 8688 | SDValue Inc = User->getOperand(User->getOperand(0) == Addr ? 1 : 0); |
| 8689 | if (ConstantSDNode *CInc = dyn_cast<ConstantSDNode>(Inc.getNode())) { |
| 8690 | uint64_t IncVal = CInc->getZExtValue(); |
| 8691 | if (IncVal != NumBytes) |
| 8692 | continue; |
| 8693 | } else if (NumBytes >= 3 * 16) { |
| 8694 | // VLD3/4 and VST3/4 for 128-bit vectors are implemented with two |
| 8695 | // separate instructions that make it harder to use a non-constant update. |
| 8696 | continue; |
| 8697 | } |
| 8698 | |
| 8699 | // Create the new updating load/store node. |
| 8700 | EVT Tys[6]; |
| 8701 | unsigned NumResultVecs = (isLoad ? NumVecs : 0); |
| 8702 | unsigned n; |
| 8703 | for (n = 0; n < NumResultVecs; ++n) |
| 8704 | Tys[n] = VecTy; |
| 8705 | Tys[n++] = MVT::i32; |
| 8706 | Tys[n] = MVT::Other; |
| 8707 | SDVTList SDTys = DAG.getVTList(Tys, NumResultVecs+2); |
| 8708 | SmallVector<SDValue, 8> Ops; |
| 8709 | Ops.push_back(N->getOperand(0)); // incoming chain |
| 8710 | Ops.push_back(N->getOperand(AddrOpIdx)); |
| 8711 | Ops.push_back(Inc); |
| 8712 | for (unsigned i = AddrOpIdx + 1; i < N->getNumOperands(); ++i) { |
| 8713 | Ops.push_back(N->getOperand(i)); |
| 8714 | } |
| 8715 | MemIntrinsicSDNode *MemInt = cast<MemIntrinsicSDNode>(N); |
| 8716 | SDValue UpdN = DAG.getMemIntrinsicNode(NewOpc, N->getDebugLoc(), SDTys, |
| 8717 | Ops.data(), Ops.size(), |
| 8718 | MemInt->getMemoryVT(), |
| 8719 | MemInt->getMemOperand()); |
| 8720 | |
| 8721 | // Update the uses. |
| 8722 | std::vector<SDValue> NewResults; |
| 8723 | for (unsigned i = 0; i < NumResultVecs; ++i) { |
| 8724 | NewResults.push_back(SDValue(UpdN.getNode(), i)); |
| 8725 | } |
| 8726 | NewResults.push_back(SDValue(UpdN.getNode(), NumResultVecs+1)); // chain |
| 8727 | DCI.CombineTo(N, NewResults); |
| 8728 | DCI.CombineTo(User, SDValue(UpdN.getNode(), NumResultVecs)); |
| 8729 | |
| 8730 | break; |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 8731 | } |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 8732 | return SDValue(); |
| 8733 | } |
| 8734 | |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 8735 | /// CombineVLDDUP - For a VDUPLANE node N, check if its source operand is a |
| 8736 | /// vldN-lane (N > 1) intrinsic, and if all the other uses of that intrinsic |
| 8737 | /// are also VDUPLANEs. If so, combine them to a vldN-dup operation and |
| 8738 | /// return true. |
| 8739 | static bool CombineVLDDUP(SDNode *N, TargetLowering::DAGCombinerInfo &DCI) { |
| 8740 | SelectionDAG &DAG = DCI.DAG; |
| 8741 | EVT VT = N->getValueType(0); |
| 8742 | // vldN-dup instructions only support 64-bit vectors for N > 1. |
| 8743 | if (!VT.is64BitVector()) |
| 8744 | return false; |
| 8745 | |
| 8746 | // Check if the VDUPLANE operand is a vldN-dup intrinsic. |
| 8747 | SDNode *VLD = N->getOperand(0).getNode(); |
| 8748 | if (VLD->getOpcode() != ISD::INTRINSIC_W_CHAIN) |
| 8749 | return false; |
| 8750 | unsigned NumVecs = 0; |
| 8751 | unsigned NewOpc = 0; |
| 8752 | unsigned IntNo = cast<ConstantSDNode>(VLD->getOperand(1))->getZExtValue(); |
| 8753 | if (IntNo == Intrinsic::arm_neon_vld2lane) { |
| 8754 | NumVecs = 2; |
| 8755 | NewOpc = ARMISD::VLD2DUP; |
| 8756 | } else if (IntNo == Intrinsic::arm_neon_vld3lane) { |
| 8757 | NumVecs = 3; |
| 8758 | NewOpc = ARMISD::VLD3DUP; |
| 8759 | } else if (IntNo == Intrinsic::arm_neon_vld4lane) { |
| 8760 | NumVecs = 4; |
| 8761 | NewOpc = ARMISD::VLD4DUP; |
| 8762 | } else { |
| 8763 | return false; |
| 8764 | } |
| 8765 | |
| 8766 | // First check that all the vldN-lane uses are VDUPLANEs and that the lane |
| 8767 | // numbers match the load. |
| 8768 | unsigned VLDLaneNo = |
| 8769 | cast<ConstantSDNode>(VLD->getOperand(NumVecs+3))->getZExtValue(); |
| 8770 | for (SDNode::use_iterator UI = VLD->use_begin(), UE = VLD->use_end(); |
| 8771 | UI != UE; ++UI) { |
| 8772 | // Ignore uses of the chain result. |
| 8773 | if (UI.getUse().getResNo() == NumVecs) |
| 8774 | continue; |
| 8775 | SDNode *User = *UI; |
| 8776 | if (User->getOpcode() != ARMISD::VDUPLANE || |
| 8777 | VLDLaneNo != cast<ConstantSDNode>(User->getOperand(1))->getZExtValue()) |
| 8778 | return false; |
| 8779 | } |
| 8780 | |
| 8781 | // Create the vldN-dup node. |
| 8782 | EVT Tys[5]; |
| 8783 | unsigned n; |
| 8784 | for (n = 0; n < NumVecs; ++n) |
| 8785 | Tys[n] = VT; |
| 8786 | Tys[n] = MVT::Other; |
| 8787 | SDVTList SDTys = DAG.getVTList(Tys, NumVecs+1); |
| 8788 | SDValue Ops[] = { VLD->getOperand(0), VLD->getOperand(2) }; |
| 8789 | MemIntrinsicSDNode *VLDMemInt = cast<MemIntrinsicSDNode>(VLD); |
| 8790 | SDValue VLDDup = DAG.getMemIntrinsicNode(NewOpc, VLD->getDebugLoc(), SDTys, |
| 8791 | Ops, 2, VLDMemInt->getMemoryVT(), |
| 8792 | VLDMemInt->getMemOperand()); |
| 8793 | |
| 8794 | // Update the uses. |
| 8795 | for (SDNode::use_iterator UI = VLD->use_begin(), UE = VLD->use_end(); |
| 8796 | UI != UE; ++UI) { |
| 8797 | unsigned ResNo = UI.getUse().getResNo(); |
| 8798 | // Ignore uses of the chain result. |
| 8799 | if (ResNo == NumVecs) |
| 8800 | continue; |
| 8801 | SDNode *User = *UI; |
| 8802 | DCI.CombineTo(User, SDValue(VLDDup.getNode(), ResNo)); |
| 8803 | } |
| 8804 | |
| 8805 | // Now the vldN-lane intrinsic is dead except for its chain result. |
| 8806 | // Update uses of the chain. |
| 8807 | std::vector<SDValue> VLDDupResults; |
| 8808 | for (unsigned n = 0; n < NumVecs; ++n) |
| 8809 | VLDDupResults.push_back(SDValue(VLDDup.getNode(), n)); |
| 8810 | VLDDupResults.push_back(SDValue(VLDDup.getNode(), NumVecs)); |
| 8811 | DCI.CombineTo(VLD, VLDDupResults); |
| 8812 | |
| 8813 | return true; |
| 8814 | } |
| 8815 | |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 8816 | /// PerformVDUPLANECombine - Target-specific dag combine xforms for |
| 8817 | /// ARMISD::VDUPLANE. |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 8818 | static SDValue PerformVDUPLANECombine(SDNode *N, |
| 8819 | TargetLowering::DAGCombinerInfo &DCI) { |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 8820 | SDValue Op = N->getOperand(0); |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 8821 | |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 8822 | // If the source is a vldN-lane (N > 1) intrinsic, and all the other uses |
| 8823 | // of that intrinsic are also VDUPLANEs, combine them to a vldN-dup operation. |
| 8824 | if (CombineVLDDUP(N, DCI)) |
| 8825 | return SDValue(N, 0); |
| 8826 | |
| 8827 | // If the source is already a VMOVIMM or VMVNIMM splat, the VDUPLANE is |
| 8828 | // redundant. Ignore bit_converts for now; element sizes are checked below. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8829 | while (Op.getOpcode() == ISD::BITCAST) |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 8830 | Op = Op.getOperand(0); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 8831 | if (Op.getOpcode() != ARMISD::VMOVIMM && Op.getOpcode() != ARMISD::VMVNIMM) |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 8832 | return SDValue(); |
| 8833 | |
| 8834 | // Make sure the VMOV element size is not bigger than the VDUPLANE elements. |
| 8835 | unsigned EltSize = Op.getValueType().getVectorElementType().getSizeInBits(); |
| 8836 | // The canonical VMOV for a zero vector uses a 32-bit element size. |
| 8837 | unsigned Imm = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
| 8838 | unsigned EltBits; |
| 8839 | if (ARM_AM::decodeNEONModImm(Imm, EltBits) == 0) |
| 8840 | EltSize = 8; |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 8841 | EVT VT = N->getValueType(0); |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 8842 | if (EltSize > VT.getVectorElementType().getSizeInBits()) |
| 8843 | return SDValue(); |
| 8844 | |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 8845 | return DCI.DAG.getNode(ISD::BITCAST, N->getDebugLoc(), VT, Op); |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 8846 | } |
| 8847 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 8848 | // 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] | 8849 | // elements are the same constant, C, and Log2(C) ranges from 1 to 32. |
| 8850 | static bool isConstVecPow2(SDValue ConstVec, bool isSigned, uint64_t &C) |
| 8851 | { |
Chad Rosier | 118c9a0 | 2011-06-28 17:26:57 +0000 | [diff] [blame] | 8852 | integerPart cN; |
| 8853 | integerPart c0 = 0; |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 8854 | for (unsigned I = 0, E = ConstVec.getValueType().getVectorNumElements(); |
| 8855 | I != E; I++) { |
| 8856 | ConstantFPSDNode *C = dyn_cast<ConstantFPSDNode>(ConstVec.getOperand(I)); |
| 8857 | if (!C) |
| 8858 | return false; |
| 8859 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 8860 | bool isExact; |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 8861 | APFloat APF = C->getValueAPF(); |
| 8862 | if (APF.convertToInteger(&cN, 64, isSigned, APFloat::rmTowardZero, &isExact) |
| 8863 | != APFloat::opOK || !isExact) |
| 8864 | return false; |
| 8865 | |
| 8866 | c0 = (I == 0) ? cN : c0; |
| 8867 | if (!isPowerOf2_64(cN) || c0 != cN || Log2_64(c0) < 1 || Log2_64(c0) > 32) |
| 8868 | return false; |
| 8869 | } |
| 8870 | C = c0; |
| 8871 | return true; |
| 8872 | } |
| 8873 | |
| 8874 | /// PerformVCVTCombine - VCVT (floating-point to fixed-point, Advanced SIMD) |
| 8875 | /// can replace combinations of VMUL and VCVT (floating-point to integer) |
| 8876 | /// when the VMUL has a constant operand that is a power of 2. |
| 8877 | /// |
| 8878 | /// Example (assume d17 = <float 8.000000e+00, float 8.000000e+00>): |
| 8879 | /// vmul.f32 d16, d17, d16 |
| 8880 | /// vcvt.s32.f32 d16, d16 |
| 8881 | /// becomes: |
| 8882 | /// vcvt.s32.f32 d16, d16, #3 |
| 8883 | static SDValue PerformVCVTCombine(SDNode *N, |
| 8884 | TargetLowering::DAGCombinerInfo &DCI, |
| 8885 | const ARMSubtarget *Subtarget) { |
| 8886 | SelectionDAG &DAG = DCI.DAG; |
| 8887 | SDValue Op = N->getOperand(0); |
| 8888 | |
| 8889 | if (!Subtarget->hasNEON() || !Op.getValueType().isVector() || |
| 8890 | Op.getOpcode() != ISD::FMUL) |
| 8891 | return SDValue(); |
| 8892 | |
| 8893 | uint64_t C; |
| 8894 | SDValue N0 = Op->getOperand(0); |
| 8895 | SDValue ConstVec = Op->getOperand(1); |
| 8896 | bool isSigned = N->getOpcode() == ISD::FP_TO_SINT; |
| 8897 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 8898 | if (ConstVec.getOpcode() != ISD::BUILD_VECTOR || |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 8899 | !isConstVecPow2(ConstVec, isSigned, C)) |
| 8900 | return SDValue(); |
| 8901 | |
| 8902 | unsigned IntrinsicOpcode = isSigned ? Intrinsic::arm_neon_vcvtfp2fxs : |
| 8903 | Intrinsic::arm_neon_vcvtfp2fxu; |
| 8904 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, N->getDebugLoc(), |
| 8905 | N->getValueType(0), |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 8906 | DAG.getConstant(IntrinsicOpcode, MVT::i32), N0, |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 8907 | DAG.getConstant(Log2_64(C), MVT::i32)); |
| 8908 | } |
| 8909 | |
| 8910 | /// PerformVDIVCombine - VCVT (fixed-point to floating-point, Advanced SIMD) |
| 8911 | /// can replace combinations of VCVT (integer to floating-point) and VDIV |
| 8912 | /// when the VDIV has a constant operand that is a power of 2. |
| 8913 | /// |
| 8914 | /// Example (assume d17 = <float 8.000000e+00, float 8.000000e+00>): |
| 8915 | /// vcvt.f32.s32 d16, d16 |
| 8916 | /// vdiv.f32 d16, d17, d16 |
| 8917 | /// becomes: |
| 8918 | /// vcvt.f32.s32 d16, d16, #3 |
| 8919 | static SDValue PerformVDIVCombine(SDNode *N, |
| 8920 | TargetLowering::DAGCombinerInfo &DCI, |
| 8921 | const ARMSubtarget *Subtarget) { |
| 8922 | SelectionDAG &DAG = DCI.DAG; |
| 8923 | SDValue Op = N->getOperand(0); |
| 8924 | unsigned OpOpcode = Op.getNode()->getOpcode(); |
| 8925 | |
| 8926 | if (!Subtarget->hasNEON() || !N->getValueType(0).isVector() || |
| 8927 | (OpOpcode != ISD::SINT_TO_FP && OpOpcode != ISD::UINT_TO_FP)) |
| 8928 | return SDValue(); |
| 8929 | |
| 8930 | uint64_t C; |
| 8931 | SDValue ConstVec = N->getOperand(1); |
| 8932 | bool isSigned = OpOpcode == ISD::SINT_TO_FP; |
| 8933 | |
| 8934 | if (ConstVec.getOpcode() != ISD::BUILD_VECTOR || |
| 8935 | !isConstVecPow2(ConstVec, isSigned, C)) |
| 8936 | return SDValue(); |
| 8937 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 8938 | unsigned IntrinsicOpcode = isSigned ? Intrinsic::arm_neon_vcvtfxs2fp : |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 8939 | Intrinsic::arm_neon_vcvtfxu2fp; |
| 8940 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, N->getDebugLoc(), |
| 8941 | Op.getValueType(), |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 8942 | DAG.getConstant(IntrinsicOpcode, MVT::i32), |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 8943 | Op.getOperand(0), DAG.getConstant(Log2_64(C), MVT::i32)); |
| 8944 | } |
| 8945 | |
| 8946 | /// Getvshiftimm - Check if this is a valid build_vector for the immediate |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8947 | /// operand of a vector shift operation, where all the elements of the |
| 8948 | /// build_vector must have the same constant integer value. |
| 8949 | static bool getVShiftImm(SDValue Op, unsigned ElementBits, int64_t &Cnt) { |
| 8950 | // Ignore bit_converts. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8951 | while (Op.getOpcode() == ISD::BITCAST) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8952 | Op = Op.getOperand(0); |
| 8953 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(Op.getNode()); |
| 8954 | APInt SplatBits, SplatUndef; |
| 8955 | unsigned SplatBitSize; |
| 8956 | bool HasAnyUndefs; |
| 8957 | if (! BVN || ! BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, |
| 8958 | HasAnyUndefs, ElementBits) || |
| 8959 | SplatBitSize > ElementBits) |
| 8960 | return false; |
| 8961 | Cnt = SplatBits.getSExtValue(); |
| 8962 | return true; |
| 8963 | } |
| 8964 | |
| 8965 | /// isVShiftLImm - Check if this is a valid build_vector for the immediate |
| 8966 | /// operand of a vector shift left operation. That value must be in the range: |
| 8967 | /// 0 <= Value < ElementBits for a left shift; or |
| 8968 | /// 0 <= Value <= ElementBits for a long left shift. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8969 | static bool isVShiftLImm(SDValue Op, EVT VT, bool isLong, int64_t &Cnt) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8970 | assert(VT.isVector() && "vector shift count is not a vector type"); |
| 8971 | unsigned ElementBits = VT.getVectorElementType().getSizeInBits(); |
| 8972 | if (! getVShiftImm(Op, ElementBits, Cnt)) |
| 8973 | return false; |
| 8974 | return (Cnt >= 0 && (isLong ? Cnt-1 : Cnt) < ElementBits); |
| 8975 | } |
| 8976 | |
| 8977 | /// isVShiftRImm - Check if this is a valid build_vector for the immediate |
| 8978 | /// operand of a vector shift right operation. For a shift opcode, the value |
| 8979 | /// is positive, but for an intrinsic the value count must be negative. The |
| 8980 | /// absolute value must be in the range: |
| 8981 | /// 1 <= |Value| <= ElementBits for a right shift; or |
| 8982 | /// 1 <= |Value| <= ElementBits/2 for a narrow right shift. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8983 | static bool isVShiftRImm(SDValue Op, EVT VT, bool isNarrow, bool isIntrinsic, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8984 | int64_t &Cnt) { |
| 8985 | assert(VT.isVector() && "vector shift count is not a vector type"); |
| 8986 | unsigned ElementBits = VT.getVectorElementType().getSizeInBits(); |
| 8987 | if (! getVShiftImm(Op, ElementBits, Cnt)) |
| 8988 | return false; |
| 8989 | if (isIntrinsic) |
| 8990 | Cnt = -Cnt; |
| 8991 | return (Cnt >= 1 && Cnt <= (isNarrow ? ElementBits/2 : ElementBits)); |
| 8992 | } |
| 8993 | |
| 8994 | /// PerformIntrinsicCombine - ARM-specific DAG combining for intrinsics. |
| 8995 | static SDValue PerformIntrinsicCombine(SDNode *N, SelectionDAG &DAG) { |
| 8996 | unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue(); |
| 8997 | switch (IntNo) { |
| 8998 | default: |
| 8999 | // Don't do anything for most intrinsics. |
| 9000 | break; |
| 9001 | |
| 9002 | // Vector shifts: check for immediate versions and lower them. |
| 9003 | // Note: This is done during DAG combining instead of DAG legalizing because |
| 9004 | // the build_vectors for 64-bit vector element shift counts are generally |
| 9005 | // not legal, and it is hard to see their values after they get legalized to |
| 9006 | // loads from a constant pool. |
| 9007 | case Intrinsic::arm_neon_vshifts: |
| 9008 | case Intrinsic::arm_neon_vshiftu: |
| 9009 | case Intrinsic::arm_neon_vshiftls: |
| 9010 | case Intrinsic::arm_neon_vshiftlu: |
| 9011 | case Intrinsic::arm_neon_vshiftn: |
| 9012 | case Intrinsic::arm_neon_vrshifts: |
| 9013 | case Intrinsic::arm_neon_vrshiftu: |
| 9014 | case Intrinsic::arm_neon_vrshiftn: |
| 9015 | case Intrinsic::arm_neon_vqshifts: |
| 9016 | case Intrinsic::arm_neon_vqshiftu: |
| 9017 | case Intrinsic::arm_neon_vqshiftsu: |
| 9018 | case Intrinsic::arm_neon_vqshiftns: |
| 9019 | case Intrinsic::arm_neon_vqshiftnu: |
| 9020 | case Intrinsic::arm_neon_vqshiftnsu: |
| 9021 | case Intrinsic::arm_neon_vqrshiftns: |
| 9022 | case Intrinsic::arm_neon_vqrshiftnu: |
| 9023 | case Intrinsic::arm_neon_vqrshiftnsu: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 9024 | EVT VT = N->getOperand(1).getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9025 | int64_t Cnt; |
| 9026 | unsigned VShiftOpc = 0; |
| 9027 | |
| 9028 | switch (IntNo) { |
| 9029 | case Intrinsic::arm_neon_vshifts: |
| 9030 | case Intrinsic::arm_neon_vshiftu: |
| 9031 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) { |
| 9032 | VShiftOpc = ARMISD::VSHL; |
| 9033 | break; |
| 9034 | } |
| 9035 | if (isVShiftRImm(N->getOperand(2), VT, false, true, Cnt)) { |
| 9036 | VShiftOpc = (IntNo == Intrinsic::arm_neon_vshifts ? |
| 9037 | ARMISD::VSHRs : ARMISD::VSHRu); |
| 9038 | break; |
| 9039 | } |
| 9040 | return SDValue(); |
| 9041 | |
| 9042 | case Intrinsic::arm_neon_vshiftls: |
| 9043 | case Intrinsic::arm_neon_vshiftlu: |
| 9044 | if (isVShiftLImm(N->getOperand(2), VT, true, Cnt)) |
| 9045 | break; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 9046 | llvm_unreachable("invalid shift count for vshll intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9047 | |
| 9048 | case Intrinsic::arm_neon_vrshifts: |
| 9049 | case Intrinsic::arm_neon_vrshiftu: |
| 9050 | if (isVShiftRImm(N->getOperand(2), VT, false, true, Cnt)) |
| 9051 | break; |
| 9052 | return SDValue(); |
| 9053 | |
| 9054 | case Intrinsic::arm_neon_vqshifts: |
| 9055 | case Intrinsic::arm_neon_vqshiftu: |
| 9056 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) |
| 9057 | break; |
| 9058 | return SDValue(); |
| 9059 | |
| 9060 | case Intrinsic::arm_neon_vqshiftsu: |
| 9061 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) |
| 9062 | break; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 9063 | llvm_unreachable("invalid shift count for vqshlu intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9064 | |
| 9065 | case Intrinsic::arm_neon_vshiftn: |
| 9066 | case Intrinsic::arm_neon_vrshiftn: |
| 9067 | case Intrinsic::arm_neon_vqshiftns: |
| 9068 | case Intrinsic::arm_neon_vqshiftnu: |
| 9069 | case Intrinsic::arm_neon_vqshiftnsu: |
| 9070 | case Intrinsic::arm_neon_vqrshiftns: |
| 9071 | case Intrinsic::arm_neon_vqrshiftnu: |
| 9072 | case Intrinsic::arm_neon_vqrshiftnsu: |
| 9073 | // Narrowing shifts require an immediate right shift. |
| 9074 | if (isVShiftRImm(N->getOperand(2), VT, true, true, Cnt)) |
| 9075 | break; |
Jim Grosbach | 18f30e6 | 2010-06-02 21:53:11 +0000 | [diff] [blame] | 9076 | llvm_unreachable("invalid shift count for narrowing vector shift " |
| 9077 | "intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9078 | |
| 9079 | default: |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 9080 | llvm_unreachable("unhandled vector shift"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9081 | } |
| 9082 | |
| 9083 | switch (IntNo) { |
| 9084 | case Intrinsic::arm_neon_vshifts: |
| 9085 | case Intrinsic::arm_neon_vshiftu: |
| 9086 | // Opcode already set above. |
| 9087 | break; |
| 9088 | case Intrinsic::arm_neon_vshiftls: |
| 9089 | case Intrinsic::arm_neon_vshiftlu: |
| 9090 | if (Cnt == VT.getVectorElementType().getSizeInBits()) |
| 9091 | VShiftOpc = ARMISD::VSHLLi; |
| 9092 | else |
| 9093 | VShiftOpc = (IntNo == Intrinsic::arm_neon_vshiftls ? |
| 9094 | ARMISD::VSHLLs : ARMISD::VSHLLu); |
| 9095 | break; |
| 9096 | case Intrinsic::arm_neon_vshiftn: |
| 9097 | VShiftOpc = ARMISD::VSHRN; break; |
| 9098 | case Intrinsic::arm_neon_vrshifts: |
| 9099 | VShiftOpc = ARMISD::VRSHRs; break; |
| 9100 | case Intrinsic::arm_neon_vrshiftu: |
| 9101 | VShiftOpc = ARMISD::VRSHRu; break; |
| 9102 | case Intrinsic::arm_neon_vrshiftn: |
| 9103 | VShiftOpc = ARMISD::VRSHRN; break; |
| 9104 | case Intrinsic::arm_neon_vqshifts: |
| 9105 | VShiftOpc = ARMISD::VQSHLs; break; |
| 9106 | case Intrinsic::arm_neon_vqshiftu: |
| 9107 | VShiftOpc = ARMISD::VQSHLu; break; |
| 9108 | case Intrinsic::arm_neon_vqshiftsu: |
| 9109 | VShiftOpc = ARMISD::VQSHLsu; break; |
| 9110 | case Intrinsic::arm_neon_vqshiftns: |
| 9111 | VShiftOpc = ARMISD::VQSHRNs; break; |
| 9112 | case Intrinsic::arm_neon_vqshiftnu: |
| 9113 | VShiftOpc = ARMISD::VQSHRNu; break; |
| 9114 | case Intrinsic::arm_neon_vqshiftnsu: |
| 9115 | VShiftOpc = ARMISD::VQSHRNsu; break; |
| 9116 | case Intrinsic::arm_neon_vqrshiftns: |
| 9117 | VShiftOpc = ARMISD::VQRSHRNs; break; |
| 9118 | case Intrinsic::arm_neon_vqrshiftnu: |
| 9119 | VShiftOpc = ARMISD::VQRSHRNu; break; |
| 9120 | case Intrinsic::arm_neon_vqrshiftnsu: |
| 9121 | VShiftOpc = ARMISD::VQRSHRNsu; break; |
| 9122 | } |
| 9123 | |
| 9124 | return DAG.getNode(VShiftOpc, N->getDebugLoc(), N->getValueType(0), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9125 | N->getOperand(1), DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9126 | } |
| 9127 | |
| 9128 | case Intrinsic::arm_neon_vshiftins: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 9129 | EVT VT = N->getOperand(1).getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9130 | int64_t Cnt; |
| 9131 | unsigned VShiftOpc = 0; |
| 9132 | |
| 9133 | if (isVShiftLImm(N->getOperand(3), VT, false, Cnt)) |
| 9134 | VShiftOpc = ARMISD::VSLI; |
| 9135 | else if (isVShiftRImm(N->getOperand(3), VT, false, true, Cnt)) |
| 9136 | VShiftOpc = ARMISD::VSRI; |
| 9137 | else { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 9138 | llvm_unreachable("invalid shift count for vsli/vsri intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9139 | } |
| 9140 | |
| 9141 | return DAG.getNode(VShiftOpc, N->getDebugLoc(), N->getValueType(0), |
| 9142 | N->getOperand(1), N->getOperand(2), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9143 | DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9144 | } |
| 9145 | |
| 9146 | case Intrinsic::arm_neon_vqrshifts: |
| 9147 | case Intrinsic::arm_neon_vqrshiftu: |
| 9148 | // No immediate versions of these to check for. |
| 9149 | break; |
| 9150 | } |
| 9151 | |
| 9152 | return SDValue(); |
| 9153 | } |
| 9154 | |
| 9155 | /// PerformShiftCombine - Checks for immediate versions of vector shifts and |
| 9156 | /// lowers them. As with the vector shift intrinsics, this is done during DAG |
| 9157 | /// combining instead of DAG legalizing because the build_vectors for 64-bit |
| 9158 | /// vector element shift counts are generally not legal, and it is hard to see |
| 9159 | /// their values after they get legalized to loads from a constant pool. |
| 9160 | static SDValue PerformShiftCombine(SDNode *N, SelectionDAG &DAG, |
| 9161 | const ARMSubtarget *ST) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 9162 | EVT VT = N->getValueType(0); |
Evan Cheng | 5fb468a | 2012-02-23 02:58:19 +0000 | [diff] [blame] | 9163 | if (N->getOpcode() == ISD::SRL && VT == MVT::i32 && ST->hasV6Ops()) { |
| 9164 | // Canonicalize (srl (bswap x), 16) to (rotr (bswap x), 16) if the high |
| 9165 | // 16-bits of x is zero. This optimizes rev + lsr 16 to rev16. |
| 9166 | SDValue N1 = N->getOperand(1); |
| 9167 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N1)) { |
| 9168 | SDValue N0 = N->getOperand(0); |
| 9169 | if (C->getZExtValue() == 16 && N0.getOpcode() == ISD::BSWAP && |
| 9170 | DAG.MaskedValueIsZero(N0.getOperand(0), |
| 9171 | APInt::getHighBitsSet(32, 16))) |
| 9172 | return DAG.getNode(ISD::ROTR, N->getDebugLoc(), VT, N0, N1); |
| 9173 | } |
| 9174 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9175 | |
| 9176 | // Nothing to be done for scalar shifts. |
Tanya Lattner | 9684a7c | 2010-11-18 22:06:46 +0000 | [diff] [blame] | 9177 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 9178 | if (!VT.isVector() || !TLI.isTypeLegal(VT)) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9179 | return SDValue(); |
| 9180 | |
| 9181 | assert(ST->hasNEON() && "unexpected vector shift"); |
| 9182 | int64_t Cnt; |
| 9183 | |
| 9184 | switch (N->getOpcode()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 9185 | default: llvm_unreachable("unexpected shift opcode"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9186 | |
| 9187 | case ISD::SHL: |
| 9188 | if (isVShiftLImm(N->getOperand(1), VT, false, Cnt)) |
| 9189 | return DAG.getNode(ARMISD::VSHL, N->getDebugLoc(), VT, N->getOperand(0), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9190 | DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9191 | break; |
| 9192 | |
| 9193 | case ISD::SRA: |
| 9194 | case ISD::SRL: |
| 9195 | if (isVShiftRImm(N->getOperand(1), VT, false, false, Cnt)) { |
| 9196 | unsigned VShiftOpc = (N->getOpcode() == ISD::SRA ? |
| 9197 | ARMISD::VSHRs : ARMISD::VSHRu); |
| 9198 | return DAG.getNode(VShiftOpc, N->getDebugLoc(), VT, N->getOperand(0), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9199 | DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9200 | } |
| 9201 | } |
| 9202 | return SDValue(); |
| 9203 | } |
| 9204 | |
| 9205 | /// PerformExtendCombine - Target-specific DAG combining for ISD::SIGN_EXTEND, |
| 9206 | /// ISD::ZERO_EXTEND, and ISD::ANY_EXTEND. |
| 9207 | static SDValue PerformExtendCombine(SDNode *N, SelectionDAG &DAG, |
| 9208 | const ARMSubtarget *ST) { |
| 9209 | SDValue N0 = N->getOperand(0); |
| 9210 | |
| 9211 | // Check for sign- and zero-extensions of vector extract operations of 8- |
| 9212 | // and 16-bit vector elements. NEON supports these directly. They are |
| 9213 | // handled during DAG combining because type legalization will promote them |
| 9214 | // to 32-bit types and it is messy to recognize the operations after that. |
| 9215 | if (ST->hasNEON() && N0.getOpcode() == ISD::EXTRACT_VECTOR_ELT) { |
| 9216 | SDValue Vec = N0.getOperand(0); |
| 9217 | SDValue Lane = N0.getOperand(1); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 9218 | EVT VT = N->getValueType(0); |
| 9219 | EVT EltVT = N0.getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9220 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 9221 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9222 | if (VT == MVT::i32 && |
| 9223 | (EltVT == MVT::i8 || EltVT == MVT::i16) && |
Bob Wilson | 3468c2e | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 9224 | TLI.isTypeLegal(Vec.getValueType()) && |
| 9225 | isa<ConstantSDNode>(Lane)) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9226 | |
| 9227 | unsigned Opc = 0; |
| 9228 | switch (N->getOpcode()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 9229 | default: llvm_unreachable("unexpected opcode"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9230 | case ISD::SIGN_EXTEND: |
| 9231 | Opc = ARMISD::VGETLANEs; |
| 9232 | break; |
| 9233 | case ISD::ZERO_EXTEND: |
| 9234 | case ISD::ANY_EXTEND: |
| 9235 | Opc = ARMISD::VGETLANEu; |
| 9236 | break; |
| 9237 | } |
| 9238 | return DAG.getNode(Opc, N->getDebugLoc(), VT, Vec, Lane); |
| 9239 | } |
| 9240 | } |
| 9241 | |
| 9242 | return SDValue(); |
| 9243 | } |
| 9244 | |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9245 | /// PerformSELECT_CCCombine - Target-specific DAG combining for ISD::SELECT_CC |
| 9246 | /// to match f32 max/min patterns to use NEON vmax/vmin instructions. |
| 9247 | static SDValue PerformSELECT_CCCombine(SDNode *N, SelectionDAG &DAG, |
| 9248 | const ARMSubtarget *ST) { |
| 9249 | // 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] | 9250 | // selects like "x < y ? x : y". Unless the NoNaNsFPMath option is set, |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9251 | // be careful about NaNs: NEON's vmax/vmin return NaN if either operand is |
| 9252 | // a NaN; only do the transformation when it matches that behavior. |
| 9253 | |
| 9254 | // For now only do this when using NEON for FP operations; if using VFP, it |
| 9255 | // is not obvious that the benefit outweighs the cost of switching to the |
| 9256 | // NEON pipeline. |
| 9257 | if (!ST->hasNEON() || !ST->useNEONForSinglePrecisionFP() || |
| 9258 | N->getValueType(0) != MVT::f32) |
| 9259 | return SDValue(); |
| 9260 | |
| 9261 | SDValue CondLHS = N->getOperand(0); |
| 9262 | SDValue CondRHS = N->getOperand(1); |
| 9263 | SDValue LHS = N->getOperand(2); |
| 9264 | SDValue RHS = N->getOperand(3); |
| 9265 | ISD::CondCode CC = cast<CondCodeSDNode>(N->getOperand(4))->get(); |
| 9266 | |
| 9267 | unsigned Opcode = 0; |
| 9268 | bool IsReversed; |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 9269 | if (DAG.isEqualTo(LHS, CondLHS) && DAG.isEqualTo(RHS, CondRHS)) { |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9270 | IsReversed = false; // x CC y ? x : y |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 9271 | } else if (DAG.isEqualTo(LHS, CondRHS) && DAG.isEqualTo(RHS, CondLHS)) { |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9272 | IsReversed = true ; // x CC y ? y : x |
| 9273 | } else { |
| 9274 | return SDValue(); |
| 9275 | } |
| 9276 | |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 9277 | bool IsUnordered; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9278 | switch (CC) { |
| 9279 | default: break; |
| 9280 | case ISD::SETOLT: |
| 9281 | case ISD::SETOLE: |
| 9282 | case ISD::SETLT: |
| 9283 | case ISD::SETLE: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9284 | case ISD::SETULT: |
| 9285 | case ISD::SETULE: |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 9286 | // If LHS is NaN, an ordered comparison will be false and the result will |
| 9287 | // be the RHS, but vmin(NaN, RHS) = NaN. Avoid this by checking that LHS |
| 9288 | // != NaN. Likewise, for unordered comparisons, check for RHS != NaN. |
| 9289 | IsUnordered = (CC == ISD::SETULT || CC == ISD::SETULE); |
| 9290 | if (!DAG.isKnownNeverNaN(IsUnordered ? RHS : LHS)) |
| 9291 | break; |
| 9292 | // For less-than-or-equal comparisons, "+0 <= -0" will be true but vmin |
| 9293 | // will return -0, so vmin can only be used for unsafe math or if one of |
| 9294 | // the operands is known to be nonzero. |
| 9295 | if ((CC == ISD::SETLE || CC == ISD::SETOLE || CC == ISD::SETULE) && |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 9296 | !DAG.getTarget().Options.UnsafeFPMath && |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 9297 | !(DAG.isKnownNeverZero(LHS) || DAG.isKnownNeverZero(RHS))) |
| 9298 | break; |
| 9299 | Opcode = IsReversed ? ARMISD::FMAX : ARMISD::FMIN; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9300 | break; |
| 9301 | |
| 9302 | case ISD::SETOGT: |
| 9303 | case ISD::SETOGE: |
| 9304 | case ISD::SETGT: |
| 9305 | case ISD::SETGE: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9306 | case ISD::SETUGT: |
| 9307 | case ISD::SETUGE: |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 9308 | // If LHS is NaN, an ordered comparison will be false and the result will |
| 9309 | // be the RHS, but vmax(NaN, RHS) = NaN. Avoid this by checking that LHS |
| 9310 | // != NaN. Likewise, for unordered comparisons, check for RHS != NaN. |
| 9311 | IsUnordered = (CC == ISD::SETUGT || CC == ISD::SETUGE); |
| 9312 | if (!DAG.isKnownNeverNaN(IsUnordered ? RHS : LHS)) |
| 9313 | break; |
| 9314 | // For greater-than-or-equal comparisons, "-0 >= +0" will be true but vmax |
| 9315 | // will return +0, so vmax can only be used for unsafe math or if one of |
| 9316 | // the operands is known to be nonzero. |
| 9317 | if ((CC == ISD::SETGE || CC == ISD::SETOGE || CC == ISD::SETUGE) && |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 9318 | !DAG.getTarget().Options.UnsafeFPMath && |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 9319 | !(DAG.isKnownNeverZero(LHS) || DAG.isKnownNeverZero(RHS))) |
| 9320 | break; |
| 9321 | Opcode = IsReversed ? ARMISD::FMIN : ARMISD::FMAX; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9322 | break; |
| 9323 | } |
| 9324 | |
| 9325 | if (!Opcode) |
| 9326 | return SDValue(); |
| 9327 | return DAG.getNode(Opcode, N->getDebugLoc(), N->getValueType(0), LHS, RHS); |
| 9328 | } |
| 9329 | |
Evan Cheng | e721f5c | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 9330 | /// PerformCMOVCombine - Target-specific DAG combining for ARMISD::CMOV. |
| 9331 | SDValue |
| 9332 | ARMTargetLowering::PerformCMOVCombine(SDNode *N, SelectionDAG &DAG) const { |
| 9333 | SDValue Cmp = N->getOperand(4); |
| 9334 | if (Cmp.getOpcode() != ARMISD::CMPZ) |
| 9335 | // Only looking at EQ and NE cases. |
| 9336 | return SDValue(); |
| 9337 | |
| 9338 | EVT VT = N->getValueType(0); |
| 9339 | DebugLoc dl = N->getDebugLoc(); |
| 9340 | SDValue LHS = Cmp.getOperand(0); |
| 9341 | SDValue RHS = Cmp.getOperand(1); |
| 9342 | SDValue FalseVal = N->getOperand(0); |
| 9343 | SDValue TrueVal = N->getOperand(1); |
| 9344 | SDValue ARMcc = N->getOperand(2); |
Jim Grosbach | b04546f | 2011-09-13 20:30:37 +0000 | [diff] [blame] | 9345 | ARMCC::CondCodes CC = |
| 9346 | (ARMCC::CondCodes)cast<ConstantSDNode>(ARMcc)->getZExtValue(); |
Evan Cheng | e721f5c | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 9347 | |
| 9348 | // Simplify |
| 9349 | // mov r1, r0 |
| 9350 | // cmp r1, x |
| 9351 | // mov r0, y |
| 9352 | // moveq r0, x |
| 9353 | // to |
| 9354 | // cmp r0, x |
| 9355 | // movne r0, y |
| 9356 | // |
| 9357 | // mov r1, r0 |
| 9358 | // cmp r1, x |
| 9359 | // mov r0, x |
| 9360 | // movne r0, y |
| 9361 | // to |
| 9362 | // cmp r0, x |
| 9363 | // movne r0, y |
| 9364 | /// FIXME: Turn this into a target neutral optimization? |
| 9365 | SDValue Res; |
Evan Cheng | 9b88d2d | 2011-09-28 23:16:31 +0000 | [diff] [blame] | 9366 | if (CC == ARMCC::NE && FalseVal == RHS && FalseVal != LHS) { |
Evan Cheng | e721f5c | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 9367 | Res = DAG.getNode(ARMISD::CMOV, dl, VT, LHS, TrueVal, ARMcc, |
| 9368 | N->getOperand(3), Cmp); |
| 9369 | } else if (CC == ARMCC::EQ && TrueVal == RHS) { |
| 9370 | SDValue ARMcc; |
| 9371 | SDValue NewCmp = getARMCmp(LHS, RHS, ISD::SETNE, ARMcc, DAG, dl); |
| 9372 | Res = DAG.getNode(ARMISD::CMOV, dl, VT, LHS, FalseVal, ARMcc, |
| 9373 | N->getOperand(3), NewCmp); |
| 9374 | } |
| 9375 | |
| 9376 | if (Res.getNode()) { |
| 9377 | APInt KnownZero, KnownOne; |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 9378 | DAG.ComputeMaskedBits(SDValue(N,0), KnownZero, KnownOne); |
Evan Cheng | e721f5c | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 9379 | // Capture demanded bits information that would be otherwise lost. |
| 9380 | if (KnownZero == 0xfffffffe) |
| 9381 | Res = DAG.getNode(ISD::AssertZext, dl, MVT::i32, Res, |
| 9382 | DAG.getValueType(MVT::i1)); |
| 9383 | else if (KnownZero == 0xffffff00) |
| 9384 | Res = DAG.getNode(ISD::AssertZext, dl, MVT::i32, Res, |
| 9385 | DAG.getValueType(MVT::i8)); |
| 9386 | else if (KnownZero == 0xffff0000) |
| 9387 | Res = DAG.getNode(ISD::AssertZext, dl, MVT::i32, Res, |
| 9388 | DAG.getValueType(MVT::i16)); |
| 9389 | } |
| 9390 | |
| 9391 | return Res; |
| 9392 | } |
| 9393 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 9394 | SDValue ARMTargetLowering::PerformDAGCombine(SDNode *N, |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 9395 | DAGCombinerInfo &DCI) const { |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 9396 | switch (N->getOpcode()) { |
| 9397 | default: break; |
Arnold Schwaighofer | 67514e9 | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 9398 | case ISD::ADDC: return PerformADDCCombine(N, DCI, Subtarget); |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 9399 | case ISD::ADD: return PerformADDCombine(N, DCI, Subtarget); |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9400 | case ISD::SUB: return PerformSUBCombine(N, DCI); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 9401 | case ISD::MUL: return PerformMULCombine(N, DCI, Subtarget); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 9402 | case ISD::OR: return PerformORCombine(N, DCI, Subtarget); |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 9403 | case ISD::XOR: return PerformXORCombine(N, DCI, Subtarget); |
| 9404 | case ISD::AND: return PerformANDCombine(N, DCI, Subtarget); |
Evan Cheng | 0c1aec1 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 9405 | case ARMISD::BFI: return PerformBFICombine(N, DCI); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 9406 | case ARMISD::VMOVRRD: return PerformVMOVRRDCombine(N, DCI); |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 9407 | case ARMISD::VMOVDRR: return PerformVMOVDRRCombine(N, DCI.DAG); |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 9408 | case ISD::STORE: return PerformSTORECombine(N, DCI); |
| 9409 | case ISD::BUILD_VECTOR: return PerformBUILD_VECTORCombine(N, DCI); |
| 9410 | case ISD::INSERT_VECTOR_ELT: return PerformInsertEltCombine(N, DCI); |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 9411 | case ISD::VECTOR_SHUFFLE: return PerformVECTOR_SHUFFLECombine(N, DCI.DAG); |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 9412 | case ARMISD::VDUPLANE: return PerformVDUPLANECombine(N, DCI); |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 9413 | case ISD::FP_TO_SINT: |
| 9414 | case ISD::FP_TO_UINT: return PerformVCVTCombine(N, DCI, Subtarget); |
| 9415 | case ISD::FDIV: return PerformVDIVCombine(N, DCI, Subtarget); |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9416 | case ISD::INTRINSIC_WO_CHAIN: return PerformIntrinsicCombine(N, DCI.DAG); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9417 | case ISD::SHL: |
| 9418 | case ISD::SRA: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9419 | case ISD::SRL: return PerformShiftCombine(N, DCI.DAG, Subtarget); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9420 | case ISD::SIGN_EXTEND: |
| 9421 | case ISD::ZERO_EXTEND: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9422 | case ISD::ANY_EXTEND: return PerformExtendCombine(N, DCI.DAG, Subtarget); |
| 9423 | case ISD::SELECT_CC: return PerformSELECT_CCCombine(N, DCI.DAG, Subtarget); |
Evan Cheng | e721f5c | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 9424 | case ARMISD::CMOV: return PerformCMOVCombine(N, DCI.DAG); |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9425 | case ARMISD::VLD2DUP: |
| 9426 | case ARMISD::VLD3DUP: |
| 9427 | case ARMISD::VLD4DUP: |
| 9428 | return CombineBaseUpdate(N, DCI); |
| 9429 | case ISD::INTRINSIC_VOID: |
| 9430 | case ISD::INTRINSIC_W_CHAIN: |
| 9431 | switch (cast<ConstantSDNode>(N->getOperand(1))->getZExtValue()) { |
| 9432 | case Intrinsic::arm_neon_vld1: |
| 9433 | case Intrinsic::arm_neon_vld2: |
| 9434 | case Intrinsic::arm_neon_vld3: |
| 9435 | case Intrinsic::arm_neon_vld4: |
| 9436 | case Intrinsic::arm_neon_vld2lane: |
| 9437 | case Intrinsic::arm_neon_vld3lane: |
| 9438 | case Intrinsic::arm_neon_vld4lane: |
| 9439 | case Intrinsic::arm_neon_vst1: |
| 9440 | case Intrinsic::arm_neon_vst2: |
| 9441 | case Intrinsic::arm_neon_vst3: |
| 9442 | case Intrinsic::arm_neon_vst4: |
| 9443 | case Intrinsic::arm_neon_vst2lane: |
| 9444 | case Intrinsic::arm_neon_vst3lane: |
| 9445 | case Intrinsic::arm_neon_vst4lane: |
| 9446 | return CombineBaseUpdate(N, DCI); |
| 9447 | default: break; |
| 9448 | } |
| 9449 | break; |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 9450 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 9451 | return SDValue(); |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 9452 | } |
| 9453 | |
Evan Cheng | 31959b1 | 2011-02-02 01:06:55 +0000 | [diff] [blame] | 9454 | bool ARMTargetLowering::isDesirableToTransformToIntegerOp(unsigned Opc, |
| 9455 | EVT VT) const { |
| 9456 | return (VT == MVT::f32) && (Opc == ISD::LOAD || Opc == ISD::STORE); |
| 9457 | } |
| 9458 | |
Evan Cheng | 376642e | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 9459 | bool ARMTargetLowering::allowsUnalignedMemoryAccesses(EVT VT, bool *Fast) const { |
Evan Cheng | d10eab0 | 2012-09-18 01:42:45 +0000 | [diff] [blame] | 9460 | // The AllowsUnaliged flag models the SCTLR.A setting in ARM cpus |
Chad Rosier | b3235b1 | 2012-11-09 18:25:27 +0000 | [diff] [blame] | 9461 | bool AllowsUnaligned = Subtarget->allowsUnalignedMem(); |
Bill Wendling | af56634 | 2009-08-15 21:21:19 +0000 | [diff] [blame] | 9462 | |
| 9463 | switch (VT.getSimpleVT().SimpleTy) { |
| 9464 | default: |
| 9465 | return false; |
| 9466 | case MVT::i8: |
| 9467 | case MVT::i16: |
Evan Cheng | 376642e | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 9468 | case MVT::i32: { |
Evan Cheng | d10eab0 | 2012-09-18 01:42:45 +0000 | [diff] [blame] | 9469 | // Unaligned access can use (for example) LRDB, LRDH, LDR |
Evan Cheng | 376642e | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 9470 | if (AllowsUnaligned) { |
| 9471 | if (Fast) |
| 9472 | *Fast = Subtarget->hasV7Ops(); |
| 9473 | return true; |
| 9474 | } |
| 9475 | return false; |
| 9476 | } |
Evan Cheng | a99c508 | 2012-08-15 17:44:53 +0000 | [diff] [blame] | 9477 | case MVT::f64: |
Evan Cheng | 376642e | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 9478 | case MVT::v2f64: { |
Evan Cheng | d10eab0 | 2012-09-18 01:42:45 +0000 | [diff] [blame] | 9479 | // For any little-endian targets with neon, we can support unaligned ld/st |
| 9480 | // of D and Q (e.g. {D0,D1}) registers by using vld1.i8/vst1.i8. |
| 9481 | // A big-endian target may also explictly support unaligned accesses |
Evan Cheng | 376642e | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 9482 | if (Subtarget->hasNEON() && (AllowsUnaligned || isLittleEndian())) { |
| 9483 | if (Fast) |
| 9484 | *Fast = true; |
| 9485 | return true; |
| 9486 | } |
| 9487 | return false; |
| 9488 | } |
Bill Wendling | af56634 | 2009-08-15 21:21:19 +0000 | [diff] [blame] | 9489 | } |
| 9490 | } |
| 9491 | |
Lang Hames | 1a1d1fc | 2011-11-02 22:52:45 +0000 | [diff] [blame] | 9492 | static bool memOpAlign(unsigned DstAlign, unsigned SrcAlign, |
| 9493 | unsigned AlignCheck) { |
| 9494 | return ((SrcAlign == 0 || SrcAlign % AlignCheck == 0) && |
| 9495 | (DstAlign == 0 || DstAlign % AlignCheck == 0)); |
| 9496 | } |
| 9497 | |
| 9498 | EVT ARMTargetLowering::getOptimalMemOpType(uint64_t Size, |
| 9499 | unsigned DstAlign, unsigned SrcAlign, |
Evan Cheng | 946a3a9 | 2012-12-12 02:34:41 +0000 | [diff] [blame] | 9500 | bool IsMemset, bool ZeroMemset, |
Lang Hames | 1a1d1fc | 2011-11-02 22:52:45 +0000 | [diff] [blame] | 9501 | bool MemcpyStrSrc, |
| 9502 | MachineFunction &MF) const { |
| 9503 | const Function *F = MF.getFunction(); |
| 9504 | |
| 9505 | // See if we can use NEON instructions for this... |
Evan Cheng | 946a3a9 | 2012-12-12 02:34:41 +0000 | [diff] [blame] | 9506 | if ((!IsMemset || ZeroMemset) && |
Evan Cheng | 376642e | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 9507 | Subtarget->hasNEON() && |
Bill Wendling | 831737d | 2012-12-30 10:32:01 +0000 | [diff] [blame] | 9508 | !F->getAttributes().hasAttribute(AttributeSet::FunctionIndex, |
| 9509 | Attribute::NoImplicitFloat)) { |
Evan Cheng | 376642e | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 9510 | bool Fast; |
Evan Cheng | 6a1b5cc | 2012-12-11 02:31:57 +0000 | [diff] [blame] | 9511 | if (Size >= 16 && |
| 9512 | (memOpAlign(SrcAlign, DstAlign, 16) || |
| 9513 | (allowsUnalignedMemoryAccesses(MVT::v2f64, &Fast) && Fast))) { |
Evan Cheng | 376642e | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 9514 | return MVT::v2f64; |
Evan Cheng | 6a1b5cc | 2012-12-11 02:31:57 +0000 | [diff] [blame] | 9515 | } else if (Size >= 8 && |
| 9516 | (memOpAlign(SrcAlign, DstAlign, 8) || |
| 9517 | (allowsUnalignedMemoryAccesses(MVT::f64, &Fast) && Fast))) { |
Evan Cheng | 376642e | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 9518 | return MVT::f64; |
Lang Hames | 1a1d1fc | 2011-11-02 22:52:45 +0000 | [diff] [blame] | 9519 | } |
| 9520 | } |
| 9521 | |
Lang Hames | 5207bf2 | 2011-11-08 18:56:23 +0000 | [diff] [blame] | 9522 | // Lowering to i32/i16 if the size permits. |
Evan Cheng | 6a1b5cc | 2012-12-11 02:31:57 +0000 | [diff] [blame] | 9523 | if (Size >= 4) |
Lang Hames | 5207bf2 | 2011-11-08 18:56:23 +0000 | [diff] [blame] | 9524 | return MVT::i32; |
Evan Cheng | 6a1b5cc | 2012-12-11 02:31:57 +0000 | [diff] [blame] | 9525 | else if (Size >= 2) |
Lang Hames | 5207bf2 | 2011-11-08 18:56:23 +0000 | [diff] [blame] | 9526 | return MVT::i16; |
Lang Hames | 5207bf2 | 2011-11-08 18:56:23 +0000 | [diff] [blame] | 9527 | |
Lang Hames | 1a1d1fc | 2011-11-02 22:52:45 +0000 | [diff] [blame] | 9528 | // Let the target-independent logic figure it out. |
| 9529 | return MVT::Other; |
| 9530 | } |
| 9531 | |
Evan Cheng | 2766a47 | 2012-12-06 19:13:27 +0000 | [diff] [blame] | 9532 | bool ARMTargetLowering::isZExtFree(SDValue Val, EVT VT2) const { |
| 9533 | if (Val.getOpcode() != ISD::LOAD) |
| 9534 | return false; |
| 9535 | |
| 9536 | EVT VT1 = Val.getValueType(); |
| 9537 | if (!VT1.isSimple() || !VT1.isInteger() || |
| 9538 | !VT2.isSimple() || !VT2.isInteger()) |
| 9539 | return false; |
| 9540 | |
| 9541 | switch (VT1.getSimpleVT().SimpleTy) { |
| 9542 | default: break; |
| 9543 | case MVT::i1: |
| 9544 | case MVT::i8: |
| 9545 | case MVT::i16: |
| 9546 | // 8-bit and 16-bit loads implicitly zero-extend to 32-bits. |
| 9547 | return true; |
| 9548 | } |
| 9549 | |
| 9550 | return false; |
| 9551 | } |
| 9552 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 9553 | static bool isLegalT1AddressImmediate(int64_t V, EVT VT) { |
| 9554 | if (V < 0) |
| 9555 | return false; |
| 9556 | |
| 9557 | unsigned Scale = 1; |
| 9558 | switch (VT.getSimpleVT().SimpleTy) { |
| 9559 | default: return false; |
| 9560 | case MVT::i1: |
| 9561 | case MVT::i8: |
| 9562 | // Scale == 1; |
| 9563 | break; |
| 9564 | case MVT::i16: |
| 9565 | // Scale == 2; |
| 9566 | Scale = 2; |
| 9567 | break; |
| 9568 | case MVT::i32: |
| 9569 | // Scale == 4; |
| 9570 | Scale = 4; |
| 9571 | break; |
| 9572 | } |
| 9573 | |
| 9574 | if ((V & (Scale - 1)) != 0) |
| 9575 | return false; |
| 9576 | V /= Scale; |
| 9577 | return V == (V & ((1LL << 5) - 1)); |
| 9578 | } |
| 9579 | |
| 9580 | static bool isLegalT2AddressImmediate(int64_t V, EVT VT, |
| 9581 | const ARMSubtarget *Subtarget) { |
| 9582 | bool isNeg = false; |
| 9583 | if (V < 0) { |
| 9584 | isNeg = true; |
| 9585 | V = - V; |
| 9586 | } |
| 9587 | |
| 9588 | switch (VT.getSimpleVT().SimpleTy) { |
| 9589 | default: return false; |
| 9590 | case MVT::i1: |
| 9591 | case MVT::i8: |
| 9592 | case MVT::i16: |
| 9593 | case MVT::i32: |
| 9594 | // + imm12 or - imm8 |
| 9595 | if (isNeg) |
| 9596 | return V == (V & ((1LL << 8) - 1)); |
| 9597 | return V == (V & ((1LL << 12) - 1)); |
| 9598 | case MVT::f32: |
| 9599 | case MVT::f64: |
| 9600 | // Same as ARM mode. FIXME: NEON? |
| 9601 | if (!Subtarget->hasVFP2()) |
| 9602 | return false; |
| 9603 | if ((V & 3) != 0) |
| 9604 | return false; |
| 9605 | V >>= 2; |
| 9606 | return V == (V & ((1LL << 8) - 1)); |
| 9607 | } |
| 9608 | } |
| 9609 | |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9610 | /// isLegalAddressImmediate - Return true if the integer value can be used |
| 9611 | /// as the offset of the target addressing mode for load / store of the |
| 9612 | /// given type. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 9613 | static bool isLegalAddressImmediate(int64_t V, EVT VT, |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9614 | const ARMSubtarget *Subtarget) { |
Evan Cheng | 961f879 | 2007-03-13 20:37:59 +0000 | [diff] [blame] | 9615 | if (V == 0) |
| 9616 | return true; |
| 9617 | |
Evan Cheng | 6501153 | 2009-03-09 19:15:00 +0000 | [diff] [blame] | 9618 | if (!VT.isSimple()) |
| 9619 | return false; |
| 9620 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 9621 | if (Subtarget->isThumb1Only()) |
| 9622 | return isLegalT1AddressImmediate(V, VT); |
| 9623 | else if (Subtarget->isThumb2()) |
| 9624 | return isLegalT2AddressImmediate(V, VT, Subtarget); |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9625 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 9626 | // ARM mode. |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9627 | if (V < 0) |
| 9628 | V = - V; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9629 | switch (VT.getSimpleVT().SimpleTy) { |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9630 | default: return false; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9631 | case MVT::i1: |
| 9632 | case MVT::i8: |
| 9633 | case MVT::i32: |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9634 | // +- imm12 |
Anton Korobeynikov | 7c1c261 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 9635 | return V == (V & ((1LL << 12) - 1)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9636 | case MVT::i16: |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9637 | // +- imm8 |
Anton Korobeynikov | 7c1c261 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 9638 | return V == (V & ((1LL << 8) - 1)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9639 | case MVT::f32: |
| 9640 | case MVT::f64: |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 9641 | if (!Subtarget->hasVFP2()) // FIXME: NEON? |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9642 | return false; |
Evan Cheng | 0b0a9a9 | 2007-05-03 02:00:18 +0000 | [diff] [blame] | 9643 | if ((V & 3) != 0) |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9644 | return false; |
| 9645 | V >>= 2; |
Anton Korobeynikov | 7c1c261 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 9646 | return V == (V & ((1LL << 8) - 1)); |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9647 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9648 | } |
| 9649 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 9650 | bool ARMTargetLowering::isLegalT2ScaledAddressingMode(const AddrMode &AM, |
| 9651 | EVT VT) const { |
| 9652 | int Scale = AM.Scale; |
| 9653 | if (Scale < 0) |
| 9654 | return false; |
| 9655 | |
| 9656 | switch (VT.getSimpleVT().SimpleTy) { |
| 9657 | default: return false; |
| 9658 | case MVT::i1: |
| 9659 | case MVT::i8: |
| 9660 | case MVT::i16: |
| 9661 | case MVT::i32: |
| 9662 | if (Scale == 1) |
| 9663 | return true; |
| 9664 | // r + r << imm |
| 9665 | Scale = Scale & ~1; |
| 9666 | return Scale == 2 || Scale == 4 || Scale == 8; |
| 9667 | case MVT::i64: |
| 9668 | // r + r |
| 9669 | if (((unsigned)AM.HasBaseReg + Scale) <= 2) |
| 9670 | return true; |
| 9671 | return false; |
| 9672 | case MVT::isVoid: |
| 9673 | // Note, we allow "void" uses (basically, uses that aren't loads or |
| 9674 | // stores), because arm allows folding a scale into many arithmetic |
| 9675 | // operations. This should be made more precise and revisited later. |
| 9676 | |
| 9677 | // Allow r << imm, but the imm has to be a multiple of two. |
| 9678 | if (Scale & 1) return false; |
| 9679 | return isPowerOf2_32(Scale); |
| 9680 | } |
| 9681 | } |
| 9682 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9683 | /// isLegalAddressingMode - Return true if the addressing mode represented |
| 9684 | /// 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] | 9685 | bool ARMTargetLowering::isLegalAddressingMode(const AddrMode &AM, |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 9686 | Type *Ty) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 9687 | EVT VT = getValueType(Ty, true); |
Bob Wilson | 2c7dab1 | 2009-04-08 17:55:28 +0000 | [diff] [blame] | 9688 | if (!isLegalAddressImmediate(AM.BaseOffs, VT, Subtarget)) |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9689 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 9690 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9691 | // Can never fold addr of global into load/store. |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 9692 | if (AM.BaseGV) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9693 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 9694 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9695 | switch (AM.Scale) { |
| 9696 | case 0: // no scale reg, must be "r+i" or "r", or "i". |
| 9697 | break; |
| 9698 | case 1: |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 9699 | if (Subtarget->isThumb1Only()) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9700 | return false; |
Chris Lattner | 5a3d40d | 2007-04-13 06:50:55 +0000 | [diff] [blame] | 9701 | // FALL THROUGH. |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9702 | default: |
Chris Lattner | 5a3d40d | 2007-04-13 06:50:55 +0000 | [diff] [blame] | 9703 | // ARM doesn't support any R+R*scale+imm addr modes. |
| 9704 | if (AM.BaseOffs) |
| 9705 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 9706 | |
Bob Wilson | 2c7dab1 | 2009-04-08 17:55:28 +0000 | [diff] [blame] | 9707 | if (!VT.isSimple()) |
| 9708 | return false; |
| 9709 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 9710 | if (Subtarget->isThumb2()) |
| 9711 | return isLegalT2ScaledAddressingMode(AM, VT); |
| 9712 | |
Chris Lattner | eb13d1b | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 9713 | int Scale = AM.Scale; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9714 | switch (VT.getSimpleVT().SimpleTy) { |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9715 | default: return false; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9716 | case MVT::i1: |
| 9717 | case MVT::i8: |
| 9718 | case MVT::i32: |
Chris Lattner | eb13d1b | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 9719 | if (Scale < 0) Scale = -Scale; |
| 9720 | if (Scale == 1) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9721 | return true; |
| 9722 | // r + r << imm |
Chris Lattner | e115294 | 2007-04-11 16:17:12 +0000 | [diff] [blame] | 9723 | return isPowerOf2_32(Scale & ~1); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9724 | case MVT::i16: |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 9725 | case MVT::i64: |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9726 | // r + r |
Chris Lattner | eb13d1b | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 9727 | if (((unsigned)AM.HasBaseReg + Scale) <= 2) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9728 | return true; |
Chris Lattner | e115294 | 2007-04-11 16:17:12 +0000 | [diff] [blame] | 9729 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 9730 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9731 | case MVT::isVoid: |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9732 | // Note, we allow "void" uses (basically, uses that aren't loads or |
| 9733 | // stores), because arm allows folding a scale into many arithmetic |
| 9734 | // operations. This should be made more precise and revisited later. |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 9735 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9736 | // 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] | 9737 | if (Scale & 1) return false; |
| 9738 | return isPowerOf2_32(Scale); |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9739 | } |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9740 | } |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9741 | return true; |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9742 | } |
| 9743 | |
Evan Cheng | 77e4751 | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 9744 | /// isLegalICmpImmediate - Return true if the specified immediate is legal |
| 9745 | /// icmp immediate, that is the target has icmp instructions which can compare |
| 9746 | /// a register against the immediate without having to materialize the |
| 9747 | /// immediate into a register. |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 9748 | bool ARMTargetLowering::isLegalICmpImmediate(int64_t Imm) const { |
Jakob Stoklund Olesen | 70fbea7 | 2012-04-06 17:45:04 +0000 | [diff] [blame] | 9749 | // Thumb2 and ARM modes can use cmn for negative immediates. |
Evan Cheng | 77e4751 | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 9750 | if (!Subtarget->isThumb()) |
Chandler Carruth | ba4d457 | 2012-04-06 20:10:52 +0000 | [diff] [blame] | 9751 | return ARM_AM::getSOImmVal(llvm::abs64(Imm)) != -1; |
Evan Cheng | 77e4751 | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 9752 | if (Subtarget->isThumb2()) |
Chandler Carruth | ba4d457 | 2012-04-06 20:10:52 +0000 | [diff] [blame] | 9753 | return ARM_AM::getT2SOImmVal(llvm::abs64(Imm)) != -1; |
Jakob Stoklund Olesen | 70fbea7 | 2012-04-06 17:45:04 +0000 | [diff] [blame] | 9754 | // Thumb1 doesn't have cmn, and only 8-bit immediates. |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 9755 | return Imm >= 0 && Imm <= 255; |
Evan Cheng | 77e4751 | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 9756 | } |
| 9757 | |
Andrew Trick | 8d8d961 | 2012-07-18 18:34:27 +0000 | [diff] [blame] | 9758 | /// isLegalAddImmediate - Return true if the specified immediate is a legal add |
| 9759 | /// *or sub* immediate, that is the target has add or sub instructions which can |
| 9760 | /// add a register with the immediate without having to materialize the |
Dan Gohman | cca8214 | 2011-05-03 00:46:49 +0000 | [diff] [blame] | 9761 | /// immediate into a register. |
| 9762 | bool ARMTargetLowering::isLegalAddImmediate(int64_t Imm) const { |
Andrew Trick | 8d8d961 | 2012-07-18 18:34:27 +0000 | [diff] [blame] | 9763 | // Same encoding for add/sub, just flip the sign. |
| 9764 | int64_t AbsImm = llvm::abs64(Imm); |
| 9765 | if (!Subtarget->isThumb()) |
| 9766 | return ARM_AM::getSOImmVal(AbsImm) != -1; |
| 9767 | if (Subtarget->isThumb2()) |
| 9768 | return ARM_AM::getT2SOImmVal(AbsImm) != -1; |
| 9769 | // Thumb1 only has 8-bit unsigned immediate. |
| 9770 | return AbsImm >= 0 && AbsImm <= 255; |
Dan Gohman | cca8214 | 2011-05-03 00:46:49 +0000 | [diff] [blame] | 9771 | } |
| 9772 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 9773 | static bool getARMIndexedAddressParts(SDNode *Ptr, EVT VT, |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 9774 | bool isSEXTLoad, SDValue &Base, |
| 9775 | SDValue &Offset, bool &isInc, |
| 9776 | SelectionDAG &DAG) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9777 | if (Ptr->getOpcode() != ISD::ADD && Ptr->getOpcode() != ISD::SUB) |
| 9778 | return false; |
| 9779 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9780 | if (VT == MVT::i16 || ((VT == MVT::i8 || VT == MVT::i1) && isSEXTLoad)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9781 | // AddressingMode 3 |
| 9782 | Base = Ptr->getOperand(0); |
| 9783 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 9784 | int RHSC = (int)RHS->getZExtValue(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9785 | if (RHSC < 0 && RHSC > -256) { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 9786 | assert(Ptr->getOpcode() == ISD::ADD); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9787 | isInc = false; |
| 9788 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); |
| 9789 | return true; |
| 9790 | } |
| 9791 | } |
| 9792 | isInc = (Ptr->getOpcode() == ISD::ADD); |
| 9793 | Offset = Ptr->getOperand(1); |
| 9794 | return true; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9795 | } else if (VT == MVT::i32 || VT == MVT::i8 || VT == MVT::i1) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9796 | // AddressingMode 2 |
| 9797 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 9798 | int RHSC = (int)RHS->getZExtValue(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9799 | if (RHSC < 0 && RHSC > -0x1000) { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 9800 | assert(Ptr->getOpcode() == ISD::ADD); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9801 | isInc = false; |
| 9802 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); |
| 9803 | Base = Ptr->getOperand(0); |
| 9804 | return true; |
| 9805 | } |
| 9806 | } |
| 9807 | |
| 9808 | if (Ptr->getOpcode() == ISD::ADD) { |
| 9809 | isInc = true; |
Evan Cheng | ee04a6d | 2011-07-20 23:34:39 +0000 | [diff] [blame] | 9810 | ARM_AM::ShiftOpc ShOpcVal= |
| 9811 | ARM_AM::getShiftOpcForNode(Ptr->getOperand(0).getOpcode()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9812 | if (ShOpcVal != ARM_AM::no_shift) { |
| 9813 | Base = Ptr->getOperand(1); |
| 9814 | Offset = Ptr->getOperand(0); |
| 9815 | } else { |
| 9816 | Base = Ptr->getOperand(0); |
| 9817 | Offset = Ptr->getOperand(1); |
| 9818 | } |
| 9819 | return true; |
| 9820 | } |
| 9821 | |
| 9822 | isInc = (Ptr->getOpcode() == ISD::ADD); |
| 9823 | Base = Ptr->getOperand(0); |
| 9824 | Offset = Ptr->getOperand(1); |
| 9825 | return true; |
| 9826 | } |
| 9827 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 9828 | // FIXME: Use VLDM / VSTM to emulate indexed FP load / store. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9829 | return false; |
| 9830 | } |
| 9831 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 9832 | static bool getT2IndexedAddressParts(SDNode *Ptr, EVT VT, |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 9833 | bool isSEXTLoad, SDValue &Base, |
| 9834 | SDValue &Offset, bool &isInc, |
| 9835 | SelectionDAG &DAG) { |
| 9836 | if (Ptr->getOpcode() != ISD::ADD && Ptr->getOpcode() != ISD::SUB) |
| 9837 | return false; |
| 9838 | |
| 9839 | Base = Ptr->getOperand(0); |
| 9840 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
| 9841 | int RHSC = (int)RHS->getZExtValue(); |
| 9842 | if (RHSC < 0 && RHSC > -0x100) { // 8 bits. |
| 9843 | assert(Ptr->getOpcode() == ISD::ADD); |
| 9844 | isInc = false; |
| 9845 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); |
| 9846 | return true; |
| 9847 | } else if (RHSC > 0 && RHSC < 0x100) { // 8 bit, no zero. |
| 9848 | isInc = Ptr->getOpcode() == ISD::ADD; |
| 9849 | Offset = DAG.getConstant(RHSC, RHS->getValueType(0)); |
| 9850 | return true; |
| 9851 | } |
| 9852 | } |
| 9853 | |
| 9854 | return false; |
| 9855 | } |
| 9856 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9857 | /// getPreIndexedAddressParts - returns true by value, base pointer and |
| 9858 | /// offset pointer and addressing mode by reference if the node's address |
| 9859 | /// can be legally represented as pre-indexed load / store address. |
| 9860 | bool |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 9861 | ARMTargetLowering::getPreIndexedAddressParts(SDNode *N, SDValue &Base, |
| 9862 | SDValue &Offset, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9863 | ISD::MemIndexedMode &AM, |
Dan Gohman | 73e0914 | 2009-01-15 16:29:45 +0000 | [diff] [blame] | 9864 | SelectionDAG &DAG) const { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 9865 | if (Subtarget->isThumb1Only()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9866 | return false; |
| 9867 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 9868 | EVT VT; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 9869 | SDValue Ptr; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9870 | bool isSEXTLoad = false; |
| 9871 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) { |
| 9872 | Ptr = LD->getBasePtr(); |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 9873 | VT = LD->getMemoryVT(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9874 | isSEXTLoad = LD->getExtensionType() == ISD::SEXTLOAD; |
| 9875 | } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) { |
| 9876 | Ptr = ST->getBasePtr(); |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 9877 | VT = ST->getMemoryVT(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9878 | } else |
| 9879 | return false; |
| 9880 | |
| 9881 | bool isInc; |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 9882 | bool isLegal = false; |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 9883 | if (Subtarget->isThumb2()) |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 9884 | isLegal = getT2IndexedAddressParts(Ptr.getNode(), VT, isSEXTLoad, Base, |
| 9885 | Offset, isInc, DAG); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 9886 | else |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 9887 | isLegal = getARMIndexedAddressParts(Ptr.getNode(), VT, isSEXTLoad, Base, |
Evan Cheng | 0412957 | 2009-07-02 06:44:30 +0000 | [diff] [blame] | 9888 | Offset, isInc, DAG); |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 9889 | if (!isLegal) |
| 9890 | return false; |
| 9891 | |
| 9892 | AM = isInc ? ISD::PRE_INC : ISD::PRE_DEC; |
| 9893 | return true; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9894 | } |
| 9895 | |
| 9896 | /// getPostIndexedAddressParts - returns true by value, base pointer and |
| 9897 | /// offset pointer and addressing mode by reference if this node can be |
| 9898 | /// combined with a load / store to form a post-indexed load / store. |
| 9899 | bool ARMTargetLowering::getPostIndexedAddressParts(SDNode *N, SDNode *Op, |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 9900 | SDValue &Base, |
| 9901 | SDValue &Offset, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9902 | ISD::MemIndexedMode &AM, |
Dan Gohman | 73e0914 | 2009-01-15 16:29:45 +0000 | [diff] [blame] | 9903 | SelectionDAG &DAG) const { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 9904 | if (Subtarget->isThumb1Only()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9905 | return false; |
| 9906 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 9907 | EVT VT; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 9908 | SDValue Ptr; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9909 | bool isSEXTLoad = false; |
| 9910 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) { |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 9911 | VT = LD->getMemoryVT(); |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 9912 | Ptr = LD->getBasePtr(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9913 | isSEXTLoad = LD->getExtensionType() == ISD::SEXTLOAD; |
| 9914 | } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) { |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 9915 | VT = ST->getMemoryVT(); |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 9916 | Ptr = ST->getBasePtr(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9917 | } else |
| 9918 | return false; |
| 9919 | |
| 9920 | bool isInc; |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 9921 | bool isLegal = false; |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 9922 | if (Subtarget->isThumb2()) |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 9923 | isLegal = getT2IndexedAddressParts(Op, VT, isSEXTLoad, Base, Offset, |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 9924 | isInc, DAG); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 9925 | else |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 9926 | isLegal = getARMIndexedAddressParts(Op, VT, isSEXTLoad, Base, Offset, |
| 9927 | isInc, DAG); |
| 9928 | if (!isLegal) |
| 9929 | return false; |
| 9930 | |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 9931 | if (Ptr != Base) { |
| 9932 | // Swap base ptr and offset to catch more post-index load / store when |
| 9933 | // it's legal. In Thumb2 mode, offset must be an immediate. |
| 9934 | if (Ptr == Offset && Op->getOpcode() == ISD::ADD && |
| 9935 | !Subtarget->isThumb2()) |
| 9936 | std::swap(Base, Offset); |
| 9937 | |
| 9938 | // Post-indexed load / store update the base pointer. |
| 9939 | if (Ptr != Base) |
| 9940 | return false; |
| 9941 | } |
| 9942 | |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 9943 | AM = isInc ? ISD::POST_INC : ISD::POST_DEC; |
| 9944 | return true; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9945 | } |
| 9946 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 9947 | void ARMTargetLowering::computeMaskedBitsForTargetNode(const SDValue Op, |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 9948 | APInt &KnownZero, |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 9949 | APInt &KnownOne, |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 9950 | const SelectionDAG &DAG, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9951 | unsigned Depth) const { |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 9952 | KnownZero = KnownOne = APInt(KnownOne.getBitWidth(), 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9953 | switch (Op.getOpcode()) { |
| 9954 | default: break; |
| 9955 | case ARMISD::CMOV: { |
| 9956 | // Bits are known zero/one if known on the LHS and RHS. |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 9957 | DAG.ComputeMaskedBits(Op.getOperand(0), KnownZero, KnownOne, Depth+1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9958 | if (KnownZero == 0 && KnownOne == 0) return; |
| 9959 | |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 9960 | APInt KnownZeroRHS, KnownOneRHS; |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 9961 | DAG.ComputeMaskedBits(Op.getOperand(1), KnownZeroRHS, KnownOneRHS, Depth+1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9962 | KnownZero &= KnownZeroRHS; |
| 9963 | KnownOne &= KnownOneRHS; |
| 9964 | return; |
| 9965 | } |
| 9966 | } |
| 9967 | } |
| 9968 | |
| 9969 | //===----------------------------------------------------------------------===// |
| 9970 | // ARM Inline Assembly Support |
| 9971 | //===----------------------------------------------------------------------===// |
| 9972 | |
Evan Cheng | 55d4200 | 2011-01-08 01:24:27 +0000 | [diff] [blame] | 9973 | bool ARMTargetLowering::ExpandInlineAsm(CallInst *CI) const { |
| 9974 | // Looking for "rev" which is V6+. |
| 9975 | if (!Subtarget->hasV6Ops()) |
| 9976 | return false; |
| 9977 | |
| 9978 | InlineAsm *IA = cast<InlineAsm>(CI->getCalledValue()); |
| 9979 | std::string AsmStr = IA->getAsmString(); |
| 9980 | SmallVector<StringRef, 4> AsmPieces; |
| 9981 | SplitString(AsmStr, AsmPieces, ";\n"); |
| 9982 | |
| 9983 | switch (AsmPieces.size()) { |
| 9984 | default: return false; |
| 9985 | case 1: |
| 9986 | AsmStr = AsmPieces[0]; |
| 9987 | AsmPieces.clear(); |
| 9988 | SplitString(AsmStr, AsmPieces, " \t,"); |
| 9989 | |
| 9990 | // rev $0, $1 |
| 9991 | if (AsmPieces.size() == 3 && |
| 9992 | AsmPieces[0] == "rev" && AsmPieces[1] == "$0" && AsmPieces[2] == "$1" && |
| 9993 | IA->getConstraintString().compare(0, 4, "=l,l") == 0) { |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 9994 | IntegerType *Ty = dyn_cast<IntegerType>(CI->getType()); |
Evan Cheng | 55d4200 | 2011-01-08 01:24:27 +0000 | [diff] [blame] | 9995 | if (Ty && Ty->getBitWidth() == 32) |
| 9996 | return IntrinsicLowering::LowerToByteSwap(CI); |
| 9997 | } |
| 9998 | break; |
| 9999 | } |
| 10000 | |
| 10001 | return false; |
| 10002 | } |
| 10003 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10004 | /// getConstraintType - Given a constraint letter, return the type of |
| 10005 | /// constraint it is for this target. |
| 10006 | ARMTargetLowering::ConstraintType |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 10007 | ARMTargetLowering::getConstraintType(const std::string &Constraint) const { |
| 10008 | if (Constraint.size() == 1) { |
| 10009 | switch (Constraint[0]) { |
| 10010 | default: break; |
| 10011 | case 'l': return C_RegisterClass; |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 10012 | case 'w': return C_RegisterClass; |
Eric Christopher | 73744df | 2011-06-30 23:23:01 +0000 | [diff] [blame] | 10013 | case 'h': return C_RegisterClass; |
Eric Christopher | 89bd71f | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 10014 | case 'x': return C_RegisterClass; |
Eric Christopher | d5dc9ec | 2011-07-01 00:30:46 +0000 | [diff] [blame] | 10015 | case 't': return C_RegisterClass; |
Eric Christopher | 5e653c9 | 2011-07-01 01:00:07 +0000 | [diff] [blame] | 10016 | case 'j': return C_Other; // Constant for movw. |
Eric Christopher | ef7f1e7 | 2011-07-29 21:18:58 +0000 | [diff] [blame] | 10017 | // An address with a single base register. Due to the way we |
| 10018 | // currently handle addresses it is the same as an 'r' memory constraint. |
| 10019 | case 'Q': return C_Memory; |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 10020 | } |
Eric Christopher | 1312ca8 | 2011-06-21 22:10:57 +0000 | [diff] [blame] | 10021 | } else if (Constraint.size() == 2) { |
| 10022 | switch (Constraint[0]) { |
| 10023 | default: break; |
| 10024 | // All 'U+' constraints are addresses. |
| 10025 | case 'U': return C_Memory; |
| 10026 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10027 | } |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 10028 | return TargetLowering::getConstraintType(Constraint); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10029 | } |
| 10030 | |
John Thompson | 44ab89e | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 10031 | /// Examine constraint type and operand type and determine a weight value. |
| 10032 | /// This object must already have been set up with the operand type |
| 10033 | /// and the current alternative constraint selected. |
| 10034 | TargetLowering::ConstraintWeight |
| 10035 | ARMTargetLowering::getSingleConstraintMatchWeight( |
| 10036 | AsmOperandInfo &info, const char *constraint) const { |
| 10037 | ConstraintWeight weight = CW_Invalid; |
| 10038 | Value *CallOperandVal = info.CallOperandVal; |
| 10039 | // If we don't have a value, we can't do a match, |
| 10040 | // but allow it at the lowest weight. |
| 10041 | if (CallOperandVal == NULL) |
| 10042 | return CW_Default; |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 10043 | Type *type = CallOperandVal->getType(); |
John Thompson | 44ab89e | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 10044 | // Look at the constraint type. |
| 10045 | switch (*constraint) { |
| 10046 | default: |
| 10047 | weight = TargetLowering::getSingleConstraintMatchWeight(info, constraint); |
| 10048 | break; |
| 10049 | case 'l': |
| 10050 | if (type->isIntegerTy()) { |
| 10051 | if (Subtarget->isThumb()) |
| 10052 | weight = CW_SpecificReg; |
| 10053 | else |
| 10054 | weight = CW_Register; |
| 10055 | } |
| 10056 | break; |
| 10057 | case 'w': |
| 10058 | if (type->isFloatingPointTy()) |
| 10059 | weight = CW_Register; |
| 10060 | break; |
| 10061 | } |
| 10062 | return weight; |
| 10063 | } |
| 10064 | |
Eric Christopher | 35e6d4d | 2011-06-30 23:50:52 +0000 | [diff] [blame] | 10065 | typedef std::pair<unsigned, const TargetRegisterClass*> RCPair; |
| 10066 | RCPair |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10067 | ARMTargetLowering::getRegForInlineAsmConstraint(const std::string &Constraint, |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 10068 | EVT VT) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10069 | if (Constraint.size() == 1) { |
Jakob Stoklund Olesen | 09bf003 | 2010-01-14 18:19:56 +0000 | [diff] [blame] | 10070 | // GCC ARM Constraint Letters |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10071 | switch (Constraint[0]) { |
Eric Christopher | 73744df | 2011-06-30 23:23:01 +0000 | [diff] [blame] | 10072 | case 'l': // Low regs or general regs. |
Jakob Stoklund Olesen | 09bf003 | 2010-01-14 18:19:56 +0000 | [diff] [blame] | 10073 | if (Subtarget->isThumb()) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 10074 | return RCPair(0U, &ARM::tGPRRegClass); |
| 10075 | return RCPair(0U, &ARM::GPRRegClass); |
Eric Christopher | 73744df | 2011-06-30 23:23:01 +0000 | [diff] [blame] | 10076 | case 'h': // High regs or no regs. |
| 10077 | if (Subtarget->isThumb()) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 10078 | return RCPair(0U, &ARM::hGPRRegClass); |
Eric Christopher | 1070f82 | 2011-07-01 00:19:27 +0000 | [diff] [blame] | 10079 | break; |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 10080 | case 'r': |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 10081 | return RCPair(0U, &ARM::GPRRegClass); |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 10082 | case 'w': |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 10083 | if (VT == MVT::f32) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 10084 | return RCPair(0U, &ARM::SPRRegClass); |
Bob Wilson | 5afffae | 2009-12-18 01:03:29 +0000 | [diff] [blame] | 10085 | if (VT.getSizeInBits() == 64) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 10086 | return RCPair(0U, &ARM::DPRRegClass); |
Evan Cheng | d831cda | 2009-12-08 23:06:22 +0000 | [diff] [blame] | 10087 | if (VT.getSizeInBits() == 128) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 10088 | return RCPair(0U, &ARM::QPRRegClass); |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 10089 | break; |
Eric Christopher | 89bd71f | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 10090 | case 'x': |
| 10091 | if (VT == MVT::f32) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 10092 | return RCPair(0U, &ARM::SPR_8RegClass); |
Eric Christopher | 89bd71f | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 10093 | if (VT.getSizeInBits() == 64) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 10094 | return RCPair(0U, &ARM::DPR_8RegClass); |
Eric Christopher | 89bd71f | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 10095 | if (VT.getSizeInBits() == 128) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 10096 | return RCPair(0U, &ARM::QPR_8RegClass); |
Eric Christopher | 89bd71f | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 10097 | break; |
Eric Christopher | d5dc9ec | 2011-07-01 00:30:46 +0000 | [diff] [blame] | 10098 | case 't': |
| 10099 | if (VT == MVT::f32) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 10100 | return RCPair(0U, &ARM::SPRRegClass); |
Eric Christopher | d5dc9ec | 2011-07-01 00:30:46 +0000 | [diff] [blame] | 10101 | break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10102 | } |
| 10103 | } |
Bob Wilson | 33cc5cb | 2010-03-15 23:09:18 +0000 | [diff] [blame] | 10104 | if (StringRef("{cc}").equals_lower(Constraint)) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 10105 | return std::make_pair(unsigned(ARM::CPSR), &ARM::CCRRegClass); |
Bob Wilson | 33cc5cb | 2010-03-15 23:09:18 +0000 | [diff] [blame] | 10106 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10107 | return TargetLowering::getRegForInlineAsmConstraint(Constraint, VT); |
| 10108 | } |
| 10109 | |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10110 | /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops |
| 10111 | /// vector. If it is invalid, don't add anything to Ops. |
| 10112 | void ARMTargetLowering::LowerAsmOperandForConstraint(SDValue Op, |
Eric Christopher | 100c833 | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 10113 | std::string &Constraint, |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10114 | std::vector<SDValue>&Ops, |
| 10115 | SelectionDAG &DAG) const { |
| 10116 | SDValue Result(0, 0); |
| 10117 | |
Eric Christopher | 100c833 | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 10118 | // Currently only support length 1 constraints. |
| 10119 | if (Constraint.length() != 1) return; |
Eric Christopher | 471e422 | 2011-06-08 23:55:35 +0000 | [diff] [blame] | 10120 | |
Eric Christopher | 100c833 | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 10121 | char ConstraintLetter = Constraint[0]; |
| 10122 | switch (ConstraintLetter) { |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10123 | default: break; |
Eric Christopher | 5e653c9 | 2011-07-01 01:00:07 +0000 | [diff] [blame] | 10124 | case 'j': |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10125 | case 'I': case 'J': case 'K': case 'L': |
| 10126 | case 'M': case 'N': case 'O': |
| 10127 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op); |
| 10128 | if (!C) |
| 10129 | return; |
| 10130 | |
| 10131 | int64_t CVal64 = C->getSExtValue(); |
| 10132 | int CVal = (int) CVal64; |
| 10133 | // None of these constraints allow values larger than 32 bits. Check |
| 10134 | // that the value fits in an int. |
| 10135 | if (CVal != CVal64) |
| 10136 | return; |
| 10137 | |
Eric Christopher | 100c833 | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 10138 | switch (ConstraintLetter) { |
Eric Christopher | 5e653c9 | 2011-07-01 01:00:07 +0000 | [diff] [blame] | 10139 | case 'j': |
Andrew Trick | 3af7a67 | 2011-09-20 03:06:13 +0000 | [diff] [blame] | 10140 | // Constant suitable for movw, must be between 0 and |
| 10141 | // 65535. |
| 10142 | if (Subtarget->hasV6T2Ops()) |
| 10143 | if (CVal >= 0 && CVal <= 65535) |
| 10144 | break; |
| 10145 | return; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10146 | case 'I': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 10147 | if (Subtarget->isThumb1Only()) { |
| 10148 | // This must be a constant between 0 and 255, for ADD |
| 10149 | // immediates. |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10150 | if (CVal >= 0 && CVal <= 255) |
| 10151 | break; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 10152 | } else if (Subtarget->isThumb2()) { |
| 10153 | // A constant that can be used as an immediate value in a |
| 10154 | // data-processing instruction. |
| 10155 | if (ARM_AM::getT2SOImmVal(CVal) != -1) |
| 10156 | break; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10157 | } else { |
| 10158 | // A constant that can be used as an immediate value in a |
| 10159 | // data-processing instruction. |
| 10160 | if (ARM_AM::getSOImmVal(CVal) != -1) |
| 10161 | break; |
| 10162 | } |
| 10163 | return; |
| 10164 | |
| 10165 | case 'J': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 10166 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10167 | // This must be a constant between -255 and -1, for negated ADD |
| 10168 | // immediates. This can be used in GCC with an "n" modifier that |
| 10169 | // prints the negated value, for use with SUB instructions. It is |
| 10170 | // not useful otherwise but is implemented for compatibility. |
| 10171 | if (CVal >= -255 && CVal <= -1) |
| 10172 | break; |
| 10173 | } else { |
| 10174 | // This must be a constant between -4095 and 4095. It is not clear |
| 10175 | // what this constraint is intended for. Implemented for |
| 10176 | // compatibility with GCC. |
| 10177 | if (CVal >= -4095 && CVal <= 4095) |
| 10178 | break; |
| 10179 | } |
| 10180 | return; |
| 10181 | |
| 10182 | case 'K': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 10183 | if (Subtarget->isThumb1Only()) { |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10184 | // A 32-bit value where only one byte has a nonzero value. Exclude |
| 10185 | // zero to match GCC. This constraint is used by GCC internally for |
| 10186 | // constants that can be loaded with a move/shift combination. |
| 10187 | // It is not useful otherwise but is implemented for compatibility. |
| 10188 | if (CVal != 0 && ARM_AM::isThumbImmShiftedVal(CVal)) |
| 10189 | break; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 10190 | } else if (Subtarget->isThumb2()) { |
| 10191 | // A constant whose bitwise inverse can be used as an immediate |
| 10192 | // value in a data-processing instruction. This can be used in GCC |
| 10193 | // with a "B" modifier that prints the inverted value, for use with |
| 10194 | // BIC and MVN instructions. It is not useful otherwise but is |
| 10195 | // implemented for compatibility. |
| 10196 | if (ARM_AM::getT2SOImmVal(~CVal) != -1) |
| 10197 | break; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10198 | } else { |
| 10199 | // A constant whose bitwise inverse can be used as an immediate |
| 10200 | // value in a data-processing instruction. This can be used in GCC |
| 10201 | // with a "B" modifier that prints the inverted value, for use with |
| 10202 | // BIC and MVN instructions. It is not useful otherwise but is |
| 10203 | // implemented for compatibility. |
| 10204 | if (ARM_AM::getSOImmVal(~CVal) != -1) |
| 10205 | break; |
| 10206 | } |
| 10207 | return; |
| 10208 | |
| 10209 | case 'L': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 10210 | if (Subtarget->isThumb1Only()) { |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10211 | // This must be a constant between -7 and 7, |
| 10212 | // for 3-operand ADD/SUB immediate instructions. |
| 10213 | if (CVal >= -7 && CVal < 7) |
| 10214 | break; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 10215 | } else if (Subtarget->isThumb2()) { |
| 10216 | // A constant whose negation can be used as an immediate value in a |
| 10217 | // data-processing instruction. This can be used in GCC with an "n" |
| 10218 | // modifier that prints the negated value, for use with SUB |
| 10219 | // instructions. It is not useful otherwise but is implemented for |
| 10220 | // compatibility. |
| 10221 | if (ARM_AM::getT2SOImmVal(-CVal) != -1) |
| 10222 | break; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10223 | } else { |
| 10224 | // A constant whose negation can be used as an immediate value in a |
| 10225 | // data-processing instruction. This can be used in GCC with an "n" |
| 10226 | // modifier that prints the negated value, for use with SUB |
| 10227 | // instructions. It is not useful otherwise but is implemented for |
| 10228 | // compatibility. |
| 10229 | if (ARM_AM::getSOImmVal(-CVal) != -1) |
| 10230 | break; |
| 10231 | } |
| 10232 | return; |
| 10233 | |
| 10234 | case 'M': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 10235 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10236 | // This must be a multiple of 4 between 0 and 1020, for |
| 10237 | // ADD sp + immediate. |
| 10238 | if ((CVal >= 0 && CVal <= 1020) && ((CVal & 3) == 0)) |
| 10239 | break; |
| 10240 | } else { |
| 10241 | // A power of two or a constant between 0 and 32. This is used in |
| 10242 | // GCC for the shift amount on shifted register operands, but it is |
| 10243 | // useful in general for any shift amounts. |
| 10244 | if ((CVal >= 0 && CVal <= 32) || ((CVal & (CVal - 1)) == 0)) |
| 10245 | break; |
| 10246 | } |
| 10247 | return; |
| 10248 | |
| 10249 | case 'N': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 10250 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10251 | // This must be a constant between 0 and 31, for shift amounts. |
| 10252 | if (CVal >= 0 && CVal <= 31) |
| 10253 | break; |
| 10254 | } |
| 10255 | return; |
| 10256 | |
| 10257 | case 'O': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 10258 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10259 | // This must be a multiple of 4 between -508 and 508, for |
| 10260 | // ADD/SUB sp = sp + immediate. |
| 10261 | if ((CVal >= -508 && CVal <= 508) && ((CVal & 3) == 0)) |
| 10262 | break; |
| 10263 | } |
| 10264 | return; |
| 10265 | } |
| 10266 | Result = DAG.getTargetConstant(CVal, Op.getValueType()); |
| 10267 | break; |
| 10268 | } |
| 10269 | |
| 10270 | if (Result.getNode()) { |
| 10271 | Ops.push_back(Result); |
| 10272 | return; |
| 10273 | } |
Dale Johannesen | 1784d16 | 2010-06-25 21:55:36 +0000 | [diff] [blame] | 10274 | return TargetLowering::LowerAsmOperandForConstraint(Op, Constraint, Ops, DAG); |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10275 | } |
Anton Korobeynikov | 48e1935 | 2009-09-23 19:04:09 +0000 | [diff] [blame] | 10276 | |
| 10277 | bool |
| 10278 | ARMTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const { |
| 10279 | // The ARM target isn't yet aware of offsets. |
| 10280 | return false; |
| 10281 | } |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 10282 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 10283 | bool ARM::isBitFieldInvertedMask(unsigned v) { |
| 10284 | if (v == 0xffffffff) |
| 10285 | return 0; |
| 10286 | // there can be 1's on either or both "outsides", all the "inside" |
| 10287 | // bits must be 0's |
| 10288 | unsigned int lsb = 0, msb = 31; |
| 10289 | while (v & (1 << msb)) --msb; |
| 10290 | while (v & (1 << lsb)) ++lsb; |
| 10291 | for (unsigned int i = lsb; i <= msb; ++i) { |
| 10292 | if (v & (1 << i)) |
| 10293 | return 0; |
| 10294 | } |
| 10295 | return 1; |
| 10296 | } |
| 10297 | |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 10298 | /// isFPImmLegal - Returns true if the target can instruction select the |
| 10299 | /// specified FP immediate natively. If false, the legalizer will |
| 10300 | /// materialize the FP immediate as a load from a constant pool. |
| 10301 | bool ARMTargetLowering::isFPImmLegal(const APFloat &Imm, EVT VT) const { |
| 10302 | if (!Subtarget->hasVFP3()) |
| 10303 | return false; |
| 10304 | if (VT == MVT::f32) |
Jim Grosbach | 4ebbf7b | 2011-09-30 00:50:06 +0000 | [diff] [blame] | 10305 | return ARM_AM::getFP32Imm(Imm) != -1; |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 10306 | if (VT == MVT::f64) |
Jim Grosbach | 4ebbf7b | 2011-09-30 00:50:06 +0000 | [diff] [blame] | 10307 | return ARM_AM::getFP64Imm(Imm) != -1; |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 10308 | return false; |
| 10309 | } |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 10310 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 10311 | /// getTgtMemIntrinsic - Represent NEON load and store intrinsics as |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 10312 | /// MemIntrinsicNodes. The associated MachineMemOperands record the alignment |
| 10313 | /// specified in the intrinsic calls. |
| 10314 | bool ARMTargetLowering::getTgtMemIntrinsic(IntrinsicInfo &Info, |
| 10315 | const CallInst &I, |
| 10316 | unsigned Intrinsic) const { |
| 10317 | switch (Intrinsic) { |
| 10318 | case Intrinsic::arm_neon_vld1: |
| 10319 | case Intrinsic::arm_neon_vld2: |
| 10320 | case Intrinsic::arm_neon_vld3: |
| 10321 | case Intrinsic::arm_neon_vld4: |
| 10322 | case Intrinsic::arm_neon_vld2lane: |
| 10323 | case Intrinsic::arm_neon_vld3lane: |
| 10324 | case Intrinsic::arm_neon_vld4lane: { |
| 10325 | Info.opc = ISD::INTRINSIC_W_CHAIN; |
| 10326 | // Conservatively set memVT to the entire set of vectors loaded. |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 10327 | uint64_t NumElts = getDataLayout()->getTypeAllocSize(I.getType()) / 8; |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 10328 | Info.memVT = EVT::getVectorVT(I.getType()->getContext(), MVT::i64, NumElts); |
| 10329 | Info.ptrVal = I.getArgOperand(0); |
| 10330 | Info.offset = 0; |
| 10331 | Value *AlignArg = I.getArgOperand(I.getNumArgOperands() - 1); |
| 10332 | Info.align = cast<ConstantInt>(AlignArg)->getZExtValue(); |
| 10333 | Info.vol = false; // volatile loads with NEON intrinsics not supported |
| 10334 | Info.readMem = true; |
| 10335 | Info.writeMem = false; |
| 10336 | return true; |
| 10337 | } |
| 10338 | case Intrinsic::arm_neon_vst1: |
| 10339 | case Intrinsic::arm_neon_vst2: |
| 10340 | case Intrinsic::arm_neon_vst3: |
| 10341 | case Intrinsic::arm_neon_vst4: |
| 10342 | case Intrinsic::arm_neon_vst2lane: |
| 10343 | case Intrinsic::arm_neon_vst3lane: |
| 10344 | case Intrinsic::arm_neon_vst4lane: { |
| 10345 | Info.opc = ISD::INTRINSIC_VOID; |
| 10346 | // Conservatively set memVT to the entire set of vectors stored. |
| 10347 | unsigned NumElts = 0; |
| 10348 | for (unsigned ArgI = 1, ArgE = I.getNumArgOperands(); ArgI < ArgE; ++ArgI) { |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 10349 | Type *ArgTy = I.getArgOperand(ArgI)->getType(); |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 10350 | if (!ArgTy->isVectorTy()) |
| 10351 | break; |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 10352 | NumElts += getDataLayout()->getTypeAllocSize(ArgTy) / 8; |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 10353 | } |
| 10354 | Info.memVT = EVT::getVectorVT(I.getType()->getContext(), MVT::i64, NumElts); |
| 10355 | Info.ptrVal = I.getArgOperand(0); |
| 10356 | Info.offset = 0; |
| 10357 | Value *AlignArg = I.getArgOperand(I.getNumArgOperands() - 1); |
| 10358 | Info.align = cast<ConstantInt>(AlignArg)->getZExtValue(); |
| 10359 | Info.vol = false; // volatile stores with NEON intrinsics not supported |
| 10360 | Info.readMem = false; |
| 10361 | Info.writeMem = true; |
| 10362 | return true; |
| 10363 | } |
Bruno Cardoso Lopes | a0112d0 | 2011-05-28 04:07:29 +0000 | [diff] [blame] | 10364 | case Intrinsic::arm_strexd: { |
| 10365 | Info.opc = ISD::INTRINSIC_W_CHAIN; |
| 10366 | Info.memVT = MVT::i64; |
| 10367 | Info.ptrVal = I.getArgOperand(2); |
| 10368 | Info.offset = 0; |
| 10369 | Info.align = 8; |
Bruno Cardoso Lopes | c75448c | 2011-06-16 18:11:32 +0000 | [diff] [blame] | 10370 | Info.vol = true; |
Bruno Cardoso Lopes | a0112d0 | 2011-05-28 04:07:29 +0000 | [diff] [blame] | 10371 | Info.readMem = false; |
| 10372 | Info.writeMem = true; |
| 10373 | return true; |
| 10374 | } |
| 10375 | case Intrinsic::arm_ldrexd: { |
| 10376 | Info.opc = ISD::INTRINSIC_W_CHAIN; |
| 10377 | Info.memVT = MVT::i64; |
| 10378 | Info.ptrVal = I.getArgOperand(0); |
| 10379 | Info.offset = 0; |
| 10380 | Info.align = 8; |
Bruno Cardoso Lopes | c75448c | 2011-06-16 18:11:32 +0000 | [diff] [blame] | 10381 | Info.vol = true; |
Bruno Cardoso Lopes | a0112d0 | 2011-05-28 04:07:29 +0000 | [diff] [blame] | 10382 | Info.readMem = true; |
| 10383 | Info.writeMem = false; |
| 10384 | return true; |
| 10385 | } |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 10386 | default: |
| 10387 | break; |
| 10388 | } |
| 10389 | |
| 10390 | return false; |
| 10391 | } |