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" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 16 | #include "ARM.h" |
| 17 | #include "ARMAddressingModes.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" |
| 20 | #include "ARMISelLowering.h" |
| 21 | #include "ARMMachineFunctionInfo.h" |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 22 | #include "ARMPerfectShuffle.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 23 | #include "ARMRegisterInfo.h" |
| 24 | #include "ARMSubtarget.h" |
| 25 | #include "ARMTargetMachine.h" |
Chris Lattner | 80ec279 | 2009-08-02 00:34:36 +0000 | [diff] [blame] | 26 | #include "ARMTargetObjectFile.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 27 | #include "llvm/CallingConv.h" |
| 28 | #include "llvm/Constants.h" |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 29 | #include "llvm/Function.h" |
Benjamin Kramer | 174101e | 2009-10-20 11:44:38 +0000 | [diff] [blame] | 30 | #include "llvm/GlobalValue.h" |
Evan Cheng | 2770747 | 2007-03-16 08:43:56 +0000 | [diff] [blame] | 31 | #include "llvm/Instruction.h" |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 32 | #include "llvm/Instructions.h" |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 33 | #include "llvm/Intrinsics.h" |
Benjamin Kramer | 174101e | 2009-10-20 11:44:38 +0000 | [diff] [blame] | 34 | #include "llvm/Type.h" |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 35 | #include "llvm/CodeGen/CallingConvLower.h" |
Evan Cheng | 55d4200 | 2011-01-08 01:24:27 +0000 | [diff] [blame] | 36 | #include "llvm/CodeGen/IntrinsicLowering.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 37 | #include "llvm/CodeGen/MachineBasicBlock.h" |
| 38 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 39 | #include "llvm/CodeGen/MachineFunction.h" |
| 40 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 41 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 42 | #include "llvm/CodeGen/PseudoSourceValue.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 43 | #include "llvm/CodeGen/SelectionDAG.h" |
Bill Wendling | 94a1c63 | 2010-03-09 02:46:12 +0000 | [diff] [blame] | 44 | #include "llvm/MC/MCSectionMachO.h" |
Evan Cheng | b6ab254 | 2007-01-31 08:40:13 +0000 | [diff] [blame] | 45 | #include "llvm/Target/TargetOptions.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 46 | #include "llvm/ADT/VectorExtras.h" |
Evan Cheng | 55d4200 | 2011-01-08 01:24:27 +0000 | [diff] [blame] | 47 | #include "llvm/ADT/StringExtras.h" |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 48 | #include "llvm/ADT/Statistic.h" |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 49 | #include "llvm/Support/CommandLine.h" |
Torok Edwin | ab7c09b | 2009-07-08 18:01:40 +0000 | [diff] [blame] | 50 | #include "llvm/Support/ErrorHandling.h" |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 51 | #include "llvm/Support/MathExtras.h" |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 52 | #include "llvm/Support/raw_ostream.h" |
Jim Grosbach | 3fb2b1e | 2009-09-01 01:57:56 +0000 | [diff] [blame] | 53 | #include <sstream> |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 54 | using namespace llvm; |
| 55 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 56 | STATISTIC(NumTailCalls, "Number of tail calls"); |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 57 | STATISTIC(NumMovwMovt, "Number of GAs materialized with movw + movt"); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 58 | |
Bob Wilson | 703af3a | 2010-08-13 22:43:33 +0000 | [diff] [blame] | 59 | // This option should go away when tail calls fully work. |
| 60 | static cl::opt<bool> |
| 61 | EnableARMTailCalls("arm-tail-calls", cl::Hidden, |
| 62 | cl::desc("Generate tail calls (TEMPORARY OPTION)."), |
| 63 | cl::init(false)); |
| 64 | |
Eric Christopher | 836c624 | 2010-12-15 23:47:29 +0000 | [diff] [blame] | 65 | cl::opt<bool> |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 66 | EnableARMLongCalls("arm-long-calls", cl::Hidden, |
Evan Cheng | 515fe3a | 2010-07-08 02:08:50 +0000 | [diff] [blame] | 67 | cl::desc("Generate calls via indirect call instructions"), |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 68 | cl::init(false)); |
| 69 | |
Evan Cheng | 46df4eb | 2010-06-16 07:35:02 +0000 | [diff] [blame] | 70 | static cl::opt<bool> |
| 71 | ARMInterworking("arm-interworking", cl::Hidden, |
| 72 | cl::desc("Enable / disable ARM interworking (for debugging only)"), |
| 73 | cl::init(true)); |
| 74 | |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 75 | // The APCS parameter registers. |
| 76 | static const unsigned GPRArgRegs[] = { |
| 77 | ARM::R0, ARM::R1, ARM::R2, ARM::R3 |
| 78 | }; |
| 79 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 80 | void ARMTargetLowering::addTypeForNEON(EVT VT, EVT PromotedLdStVT, |
| 81 | EVT PromotedBitwiseVT) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 82 | if (VT != PromotedLdStVT) { |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 83 | setOperationAction(ISD::LOAD, VT.getSimpleVT(), Promote); |
Owen Anderson | d6662ad | 2009-08-10 20:46:15 +0000 | [diff] [blame] | 84 | AddPromotedToType (ISD::LOAD, VT.getSimpleVT(), |
| 85 | PromotedLdStVT.getSimpleVT()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 86 | |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 87 | setOperationAction(ISD::STORE, VT.getSimpleVT(), Promote); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 88 | AddPromotedToType (ISD::STORE, VT.getSimpleVT(), |
Owen Anderson | d6662ad | 2009-08-10 20:46:15 +0000 | [diff] [blame] | 89 | PromotedLdStVT.getSimpleVT()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 90 | } |
| 91 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 92 | EVT ElemTy = VT.getVectorElementType(); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 93 | if (ElemTy != MVT::i64 && ElemTy != MVT::f64) |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 94 | setOperationAction(ISD::VSETCC, VT.getSimpleVT(), Custom); |
Bob Wilson | 3468c2e | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 95 | setOperationAction(ISD::EXTRACT_VECTOR_ELT, VT.getSimpleVT(), Custom); |
Bob Wilson | 0696fdf | 2009-09-16 20:20:44 +0000 | [diff] [blame] | 96 | if (ElemTy != MVT::i32) { |
| 97 | setOperationAction(ISD::SINT_TO_FP, VT.getSimpleVT(), Expand); |
| 98 | setOperationAction(ISD::UINT_TO_FP, VT.getSimpleVT(), Expand); |
| 99 | setOperationAction(ISD::FP_TO_SINT, VT.getSimpleVT(), Expand); |
| 100 | setOperationAction(ISD::FP_TO_UINT, VT.getSimpleVT(), Expand); |
| 101 | } |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 102 | setOperationAction(ISD::BUILD_VECTOR, VT.getSimpleVT(), Custom); |
| 103 | setOperationAction(ISD::VECTOR_SHUFFLE, VT.getSimpleVT(), Custom); |
Bob Wilson | 07f6e80 | 2010-06-16 21:34:01 +0000 | [diff] [blame] | 104 | setOperationAction(ISD::CONCAT_VECTORS, VT.getSimpleVT(), Legal); |
Bob Wilson | 5e8b833 | 2011-01-07 04:59:04 +0000 | [diff] [blame] | 105 | setOperationAction(ISD::EXTRACT_SUBVECTOR, VT.getSimpleVT(), Legal); |
Bob Wilson | d0910c4 | 2010-04-06 22:02:24 +0000 | [diff] [blame] | 106 | setOperationAction(ISD::SELECT, VT.getSimpleVT(), Expand); |
| 107 | setOperationAction(ISD::SELECT_CC, VT.getSimpleVT(), Expand); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 108 | if (VT.isInteger()) { |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 109 | setOperationAction(ISD::SHL, VT.getSimpleVT(), Custom); |
| 110 | setOperationAction(ISD::SRA, VT.getSimpleVT(), Custom); |
| 111 | setOperationAction(ISD::SRL, VT.getSimpleVT(), Custom); |
Bob Wilson | b31a11b | 2010-08-20 04:54:02 +0000 | [diff] [blame] | 112 | setLoadExtAction(ISD::SEXTLOAD, VT.getSimpleVT(), Expand); |
| 113 | setLoadExtAction(ISD::ZEXTLOAD, VT.getSimpleVT(), Expand); |
Bob Wilson | 24645a1 | 2010-11-01 18:31:39 +0000 | [diff] [blame] | 114 | for (unsigned InnerVT = (unsigned)MVT::FIRST_VECTOR_VALUETYPE; |
| 115 | InnerVT <= (unsigned)MVT::LAST_VECTOR_VALUETYPE; ++InnerVT) |
| 116 | setTruncStoreAction(VT.getSimpleVT(), |
| 117 | (MVT::SimpleValueType)InnerVT, Expand); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 118 | } |
Bob Wilson | b31a11b | 2010-08-20 04:54:02 +0000 | [diff] [blame] | 119 | setLoadExtAction(ISD::EXTLOAD, VT.getSimpleVT(), Expand); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 120 | |
| 121 | // Promote all bit-wise operations. |
| 122 | if (VT.isInteger() && VT != PromotedBitwiseVT) { |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 123 | setOperationAction(ISD::AND, VT.getSimpleVT(), Promote); |
Owen Anderson | d6662ad | 2009-08-10 20:46:15 +0000 | [diff] [blame] | 124 | AddPromotedToType (ISD::AND, VT.getSimpleVT(), |
| 125 | PromotedBitwiseVT.getSimpleVT()); |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 126 | setOperationAction(ISD::OR, VT.getSimpleVT(), Promote); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 127 | AddPromotedToType (ISD::OR, VT.getSimpleVT(), |
Owen Anderson | d6662ad | 2009-08-10 20:46:15 +0000 | [diff] [blame] | 128 | PromotedBitwiseVT.getSimpleVT()); |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 129 | setOperationAction(ISD::XOR, VT.getSimpleVT(), Promote); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 130 | AddPromotedToType (ISD::XOR, VT.getSimpleVT(), |
Owen Anderson | d6662ad | 2009-08-10 20:46:15 +0000 | [diff] [blame] | 131 | PromotedBitwiseVT.getSimpleVT()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 132 | } |
Bob Wilson | 1633076 | 2009-09-16 00:17:28 +0000 | [diff] [blame] | 133 | |
| 134 | // Neon does not support vector divide/remainder operations. |
| 135 | setOperationAction(ISD::SDIV, VT.getSimpleVT(), Expand); |
| 136 | setOperationAction(ISD::UDIV, VT.getSimpleVT(), Expand); |
| 137 | setOperationAction(ISD::FDIV, VT.getSimpleVT(), Expand); |
| 138 | setOperationAction(ISD::SREM, VT.getSimpleVT(), Expand); |
| 139 | setOperationAction(ISD::UREM, VT.getSimpleVT(), Expand); |
| 140 | setOperationAction(ISD::FREM, VT.getSimpleVT(), Expand); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 141 | } |
| 142 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 143 | void ARMTargetLowering::addDRTypeForNEON(EVT VT) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 144 | addRegisterClass(VT, ARM::DPRRegisterClass); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 145 | addTypeForNEON(VT, MVT::f64, MVT::v2i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 146 | } |
| 147 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 148 | void ARMTargetLowering::addQRTypeForNEON(EVT VT) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 149 | addRegisterClass(VT, ARM::QPRRegisterClass); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 150 | addTypeForNEON(VT, MVT::v2f64, MVT::v4i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 151 | } |
| 152 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 153 | static TargetLoweringObjectFile *createTLOF(TargetMachine &TM) { |
| 154 | if (TM.getSubtarget<ARMSubtarget>().isTargetDarwin()) |
Bill Wendling | 505ad8b | 2010-03-15 21:09:38 +0000 | [diff] [blame] | 155 | return new TargetLoweringObjectFileMachO(); |
Bill Wendling | 94a1c63 | 2010-03-09 02:46:12 +0000 | [diff] [blame] | 156 | |
Chris Lattner | 80ec279 | 2009-08-02 00:34:36 +0000 | [diff] [blame] | 157 | return new ARMElfTargetObjectFile(); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 158 | } |
| 159 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 160 | ARMTargetLowering::ARMTargetLowering(TargetMachine &TM) |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 161 | : TargetLowering(TM, createTLOF(TM)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 162 | Subtarget = &TM.getSubtarget<ARMSubtarget>(); |
Evan Cheng | 3144687 | 2010-07-23 22:39:59 +0000 | [diff] [blame] | 163 | RegInfo = TM.getRegisterInfo(); |
Evan Cheng | 3ef1c87 | 2010-09-10 01:29:16 +0000 | [diff] [blame] | 164 | Itins = TM.getInstrItineraryData(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 165 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 166 | if (Subtarget->isTargetDarwin()) { |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 167 | // Uses VFP for Thumb libfuncs if available. |
| 168 | if (Subtarget->isThumb() && Subtarget->hasVFP2()) { |
| 169 | // Single-precision floating-point arithmetic. |
| 170 | setLibcallName(RTLIB::ADD_F32, "__addsf3vfp"); |
| 171 | setLibcallName(RTLIB::SUB_F32, "__subsf3vfp"); |
| 172 | setLibcallName(RTLIB::MUL_F32, "__mulsf3vfp"); |
| 173 | setLibcallName(RTLIB::DIV_F32, "__divsf3vfp"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 174 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 175 | // Double-precision floating-point arithmetic. |
| 176 | setLibcallName(RTLIB::ADD_F64, "__adddf3vfp"); |
| 177 | setLibcallName(RTLIB::SUB_F64, "__subdf3vfp"); |
| 178 | setLibcallName(RTLIB::MUL_F64, "__muldf3vfp"); |
| 179 | setLibcallName(RTLIB::DIV_F64, "__divdf3vfp"); |
Evan Cheng | 193f850 | 2007-01-31 09:30:58 +0000 | [diff] [blame] | 180 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 181 | // Single-precision comparisons. |
| 182 | setLibcallName(RTLIB::OEQ_F32, "__eqsf2vfp"); |
| 183 | setLibcallName(RTLIB::UNE_F32, "__nesf2vfp"); |
| 184 | setLibcallName(RTLIB::OLT_F32, "__ltsf2vfp"); |
| 185 | setLibcallName(RTLIB::OLE_F32, "__lesf2vfp"); |
| 186 | setLibcallName(RTLIB::OGE_F32, "__gesf2vfp"); |
| 187 | setLibcallName(RTLIB::OGT_F32, "__gtsf2vfp"); |
| 188 | setLibcallName(RTLIB::UO_F32, "__unordsf2vfp"); |
| 189 | setLibcallName(RTLIB::O_F32, "__unordsf2vfp"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 190 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 191 | setCmpLibcallCC(RTLIB::OEQ_F32, ISD::SETNE); |
| 192 | setCmpLibcallCC(RTLIB::UNE_F32, ISD::SETNE); |
| 193 | setCmpLibcallCC(RTLIB::OLT_F32, ISD::SETNE); |
| 194 | setCmpLibcallCC(RTLIB::OLE_F32, ISD::SETNE); |
| 195 | setCmpLibcallCC(RTLIB::OGE_F32, ISD::SETNE); |
| 196 | setCmpLibcallCC(RTLIB::OGT_F32, ISD::SETNE); |
| 197 | setCmpLibcallCC(RTLIB::UO_F32, ISD::SETNE); |
| 198 | setCmpLibcallCC(RTLIB::O_F32, ISD::SETEQ); |
Evan Cheng | 193f850 | 2007-01-31 09:30:58 +0000 | [diff] [blame] | 199 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 200 | // Double-precision comparisons. |
| 201 | setLibcallName(RTLIB::OEQ_F64, "__eqdf2vfp"); |
| 202 | setLibcallName(RTLIB::UNE_F64, "__nedf2vfp"); |
| 203 | setLibcallName(RTLIB::OLT_F64, "__ltdf2vfp"); |
| 204 | setLibcallName(RTLIB::OLE_F64, "__ledf2vfp"); |
| 205 | setLibcallName(RTLIB::OGE_F64, "__gedf2vfp"); |
| 206 | setLibcallName(RTLIB::OGT_F64, "__gtdf2vfp"); |
| 207 | setLibcallName(RTLIB::UO_F64, "__unorddf2vfp"); |
| 208 | setLibcallName(RTLIB::O_F64, "__unorddf2vfp"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 209 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 210 | setCmpLibcallCC(RTLIB::OEQ_F64, ISD::SETNE); |
| 211 | setCmpLibcallCC(RTLIB::UNE_F64, ISD::SETNE); |
| 212 | setCmpLibcallCC(RTLIB::OLT_F64, ISD::SETNE); |
| 213 | setCmpLibcallCC(RTLIB::OLE_F64, ISD::SETNE); |
| 214 | setCmpLibcallCC(RTLIB::OGE_F64, ISD::SETNE); |
| 215 | setCmpLibcallCC(RTLIB::OGT_F64, ISD::SETNE); |
| 216 | setCmpLibcallCC(RTLIB::UO_F64, ISD::SETNE); |
| 217 | setCmpLibcallCC(RTLIB::O_F64, ISD::SETEQ); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 218 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 219 | // Floating-point to integer conversions. |
| 220 | // i64 conversions are done via library routines even when generating VFP |
| 221 | // instructions, so use the same ones. |
| 222 | setLibcallName(RTLIB::FPTOSINT_F64_I32, "__fixdfsivfp"); |
| 223 | setLibcallName(RTLIB::FPTOUINT_F64_I32, "__fixunsdfsivfp"); |
| 224 | setLibcallName(RTLIB::FPTOSINT_F32_I32, "__fixsfsivfp"); |
| 225 | setLibcallName(RTLIB::FPTOUINT_F32_I32, "__fixunssfsivfp"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 226 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 227 | // Conversions between floating types. |
| 228 | setLibcallName(RTLIB::FPROUND_F64_F32, "__truncdfsf2vfp"); |
| 229 | setLibcallName(RTLIB::FPEXT_F32_F64, "__extendsfdf2vfp"); |
| 230 | |
| 231 | // Integer to floating-point conversions. |
| 232 | // i64 conversions are done via library routines even when generating VFP |
| 233 | // instructions, so use the same ones. |
Bob Wilson | 2a14c52 | 2009-03-20 23:16:43 +0000 | [diff] [blame] | 234 | // FIXME: There appears to be some naming inconsistency in ARM libgcc: |
| 235 | // e.g., __floatunsidf vs. __floatunssidfvfp. |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 236 | setLibcallName(RTLIB::SINTTOFP_I32_F64, "__floatsidfvfp"); |
| 237 | setLibcallName(RTLIB::UINTTOFP_I32_F64, "__floatunssidfvfp"); |
| 238 | setLibcallName(RTLIB::SINTTOFP_I32_F32, "__floatsisfvfp"); |
| 239 | setLibcallName(RTLIB::UINTTOFP_I32_F32, "__floatunssisfvfp"); |
| 240 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 241 | } |
| 242 | |
Bob Wilson | 2f95461 | 2009-05-22 17:38:41 +0000 | [diff] [blame] | 243 | // These libcalls are not available in 32-bit. |
| 244 | setLibcallName(RTLIB::SHL_I128, 0); |
| 245 | setLibcallName(RTLIB::SRL_I128, 0); |
| 246 | setLibcallName(RTLIB::SRA_I128, 0); |
| 247 | |
Anton Korobeynikov | 72977a4 | 2009-08-14 20:10:52 +0000 | [diff] [blame] | 248 | if (Subtarget->isAAPCS_ABI()) { |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 249 | // Double-precision floating-point arithmetic helper functions |
Anton Korobeynikov | 4f922f2 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 250 | // RTABI chapter 4.1.2, Table 2 |
| 251 | setLibcallName(RTLIB::ADD_F64, "__aeabi_dadd"); |
| 252 | setLibcallName(RTLIB::DIV_F64, "__aeabi_ddiv"); |
| 253 | setLibcallName(RTLIB::MUL_F64, "__aeabi_dmul"); |
| 254 | setLibcallName(RTLIB::SUB_F64, "__aeabi_dsub"); |
| 255 | setLibcallCallingConv(RTLIB::ADD_F64, CallingConv::ARM_AAPCS); |
| 256 | setLibcallCallingConv(RTLIB::DIV_F64, CallingConv::ARM_AAPCS); |
| 257 | setLibcallCallingConv(RTLIB::MUL_F64, CallingConv::ARM_AAPCS); |
| 258 | setLibcallCallingConv(RTLIB::SUB_F64, CallingConv::ARM_AAPCS); |
| 259 | |
| 260 | // Double-precision floating-point comparison helper functions |
| 261 | // RTABI chapter 4.1.2, Table 3 |
| 262 | setLibcallName(RTLIB::OEQ_F64, "__aeabi_dcmpeq"); |
| 263 | setCmpLibcallCC(RTLIB::OEQ_F64, ISD::SETNE); |
| 264 | setLibcallName(RTLIB::UNE_F64, "__aeabi_dcmpeq"); |
| 265 | setCmpLibcallCC(RTLIB::UNE_F64, ISD::SETEQ); |
| 266 | setLibcallName(RTLIB::OLT_F64, "__aeabi_dcmplt"); |
| 267 | setCmpLibcallCC(RTLIB::OLT_F64, ISD::SETNE); |
| 268 | setLibcallName(RTLIB::OLE_F64, "__aeabi_dcmple"); |
| 269 | setCmpLibcallCC(RTLIB::OLE_F64, ISD::SETNE); |
| 270 | setLibcallName(RTLIB::OGE_F64, "__aeabi_dcmpge"); |
| 271 | setCmpLibcallCC(RTLIB::OGE_F64, ISD::SETNE); |
| 272 | setLibcallName(RTLIB::OGT_F64, "__aeabi_dcmpgt"); |
| 273 | setCmpLibcallCC(RTLIB::OGT_F64, ISD::SETNE); |
| 274 | setLibcallName(RTLIB::UO_F64, "__aeabi_dcmpun"); |
| 275 | setCmpLibcallCC(RTLIB::UO_F64, ISD::SETNE); |
| 276 | setLibcallName(RTLIB::O_F64, "__aeabi_dcmpun"); |
| 277 | setCmpLibcallCC(RTLIB::O_F64, ISD::SETEQ); |
| 278 | setLibcallCallingConv(RTLIB::OEQ_F64, CallingConv::ARM_AAPCS); |
| 279 | setLibcallCallingConv(RTLIB::UNE_F64, CallingConv::ARM_AAPCS); |
| 280 | setLibcallCallingConv(RTLIB::OLT_F64, CallingConv::ARM_AAPCS); |
| 281 | setLibcallCallingConv(RTLIB::OLE_F64, CallingConv::ARM_AAPCS); |
| 282 | setLibcallCallingConv(RTLIB::OGE_F64, CallingConv::ARM_AAPCS); |
| 283 | setLibcallCallingConv(RTLIB::OGT_F64, CallingConv::ARM_AAPCS); |
| 284 | setLibcallCallingConv(RTLIB::UO_F64, CallingConv::ARM_AAPCS); |
| 285 | setLibcallCallingConv(RTLIB::O_F64, CallingConv::ARM_AAPCS); |
| 286 | |
| 287 | // Single-precision floating-point arithmetic helper functions |
| 288 | // RTABI chapter 4.1.2, Table 4 |
| 289 | setLibcallName(RTLIB::ADD_F32, "__aeabi_fadd"); |
| 290 | setLibcallName(RTLIB::DIV_F32, "__aeabi_fdiv"); |
| 291 | setLibcallName(RTLIB::MUL_F32, "__aeabi_fmul"); |
| 292 | setLibcallName(RTLIB::SUB_F32, "__aeabi_fsub"); |
| 293 | setLibcallCallingConv(RTLIB::ADD_F32, CallingConv::ARM_AAPCS); |
| 294 | setLibcallCallingConv(RTLIB::DIV_F32, CallingConv::ARM_AAPCS); |
| 295 | setLibcallCallingConv(RTLIB::MUL_F32, CallingConv::ARM_AAPCS); |
| 296 | setLibcallCallingConv(RTLIB::SUB_F32, CallingConv::ARM_AAPCS); |
| 297 | |
| 298 | // Single-precision floating-point comparison helper functions |
| 299 | // RTABI chapter 4.1.2, Table 5 |
| 300 | setLibcallName(RTLIB::OEQ_F32, "__aeabi_fcmpeq"); |
| 301 | setCmpLibcallCC(RTLIB::OEQ_F32, ISD::SETNE); |
| 302 | setLibcallName(RTLIB::UNE_F32, "__aeabi_fcmpeq"); |
| 303 | setCmpLibcallCC(RTLIB::UNE_F32, ISD::SETEQ); |
| 304 | setLibcallName(RTLIB::OLT_F32, "__aeabi_fcmplt"); |
| 305 | setCmpLibcallCC(RTLIB::OLT_F32, ISD::SETNE); |
| 306 | setLibcallName(RTLIB::OLE_F32, "__aeabi_fcmple"); |
| 307 | setCmpLibcallCC(RTLIB::OLE_F32, ISD::SETNE); |
| 308 | setLibcallName(RTLIB::OGE_F32, "__aeabi_fcmpge"); |
| 309 | setCmpLibcallCC(RTLIB::OGE_F32, ISD::SETNE); |
| 310 | setLibcallName(RTLIB::OGT_F32, "__aeabi_fcmpgt"); |
| 311 | setCmpLibcallCC(RTLIB::OGT_F32, ISD::SETNE); |
| 312 | setLibcallName(RTLIB::UO_F32, "__aeabi_fcmpun"); |
| 313 | setCmpLibcallCC(RTLIB::UO_F32, ISD::SETNE); |
| 314 | setLibcallName(RTLIB::O_F32, "__aeabi_fcmpun"); |
| 315 | setCmpLibcallCC(RTLIB::O_F32, ISD::SETEQ); |
| 316 | setLibcallCallingConv(RTLIB::OEQ_F32, CallingConv::ARM_AAPCS); |
| 317 | setLibcallCallingConv(RTLIB::UNE_F32, CallingConv::ARM_AAPCS); |
| 318 | setLibcallCallingConv(RTLIB::OLT_F32, CallingConv::ARM_AAPCS); |
| 319 | setLibcallCallingConv(RTLIB::OLE_F32, CallingConv::ARM_AAPCS); |
| 320 | setLibcallCallingConv(RTLIB::OGE_F32, CallingConv::ARM_AAPCS); |
| 321 | setLibcallCallingConv(RTLIB::OGT_F32, CallingConv::ARM_AAPCS); |
| 322 | setLibcallCallingConv(RTLIB::UO_F32, CallingConv::ARM_AAPCS); |
| 323 | setLibcallCallingConv(RTLIB::O_F32, CallingConv::ARM_AAPCS); |
| 324 | |
| 325 | // Floating-point to integer conversions. |
| 326 | // RTABI chapter 4.1.2, Table 6 |
| 327 | setLibcallName(RTLIB::FPTOSINT_F64_I32, "__aeabi_d2iz"); |
| 328 | setLibcallName(RTLIB::FPTOUINT_F64_I32, "__aeabi_d2uiz"); |
| 329 | setLibcallName(RTLIB::FPTOSINT_F64_I64, "__aeabi_d2lz"); |
| 330 | setLibcallName(RTLIB::FPTOUINT_F64_I64, "__aeabi_d2ulz"); |
| 331 | setLibcallName(RTLIB::FPTOSINT_F32_I32, "__aeabi_f2iz"); |
| 332 | setLibcallName(RTLIB::FPTOUINT_F32_I32, "__aeabi_f2uiz"); |
| 333 | setLibcallName(RTLIB::FPTOSINT_F32_I64, "__aeabi_f2lz"); |
| 334 | setLibcallName(RTLIB::FPTOUINT_F32_I64, "__aeabi_f2ulz"); |
| 335 | setLibcallCallingConv(RTLIB::FPTOSINT_F64_I32, CallingConv::ARM_AAPCS); |
| 336 | setLibcallCallingConv(RTLIB::FPTOUINT_F64_I32, CallingConv::ARM_AAPCS); |
| 337 | setLibcallCallingConv(RTLIB::FPTOSINT_F64_I64, CallingConv::ARM_AAPCS); |
| 338 | setLibcallCallingConv(RTLIB::FPTOUINT_F64_I64, CallingConv::ARM_AAPCS); |
| 339 | setLibcallCallingConv(RTLIB::FPTOSINT_F32_I32, CallingConv::ARM_AAPCS); |
| 340 | setLibcallCallingConv(RTLIB::FPTOUINT_F32_I32, CallingConv::ARM_AAPCS); |
| 341 | setLibcallCallingConv(RTLIB::FPTOSINT_F32_I64, CallingConv::ARM_AAPCS); |
| 342 | setLibcallCallingConv(RTLIB::FPTOUINT_F32_I64, CallingConv::ARM_AAPCS); |
| 343 | |
| 344 | // Conversions between floating types. |
| 345 | // RTABI chapter 4.1.2, Table 7 |
| 346 | setLibcallName(RTLIB::FPROUND_F64_F32, "__aeabi_d2f"); |
| 347 | setLibcallName(RTLIB::FPEXT_F32_F64, "__aeabi_f2d"); |
| 348 | setLibcallCallingConv(RTLIB::FPROUND_F64_F32, CallingConv::ARM_AAPCS); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 349 | setLibcallCallingConv(RTLIB::FPEXT_F32_F64, CallingConv::ARM_AAPCS); |
Anton Korobeynikov | 4f922f2 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 350 | |
| 351 | // Integer to floating-point conversions. |
| 352 | // RTABI chapter 4.1.2, Table 8 |
| 353 | setLibcallName(RTLIB::SINTTOFP_I32_F64, "__aeabi_i2d"); |
| 354 | setLibcallName(RTLIB::UINTTOFP_I32_F64, "__aeabi_ui2d"); |
| 355 | setLibcallName(RTLIB::SINTTOFP_I64_F64, "__aeabi_l2d"); |
| 356 | setLibcallName(RTLIB::UINTTOFP_I64_F64, "__aeabi_ul2d"); |
| 357 | setLibcallName(RTLIB::SINTTOFP_I32_F32, "__aeabi_i2f"); |
| 358 | setLibcallName(RTLIB::UINTTOFP_I32_F32, "__aeabi_ui2f"); |
| 359 | setLibcallName(RTLIB::SINTTOFP_I64_F32, "__aeabi_l2f"); |
| 360 | setLibcallName(RTLIB::UINTTOFP_I64_F32, "__aeabi_ul2f"); |
| 361 | setLibcallCallingConv(RTLIB::SINTTOFP_I32_F64, CallingConv::ARM_AAPCS); |
| 362 | setLibcallCallingConv(RTLIB::UINTTOFP_I32_F64, CallingConv::ARM_AAPCS); |
| 363 | setLibcallCallingConv(RTLIB::SINTTOFP_I64_F64, CallingConv::ARM_AAPCS); |
| 364 | setLibcallCallingConv(RTLIB::UINTTOFP_I64_F64, CallingConv::ARM_AAPCS); |
| 365 | setLibcallCallingConv(RTLIB::SINTTOFP_I32_F32, CallingConv::ARM_AAPCS); |
| 366 | setLibcallCallingConv(RTLIB::UINTTOFP_I32_F32, CallingConv::ARM_AAPCS); |
| 367 | setLibcallCallingConv(RTLIB::SINTTOFP_I64_F32, CallingConv::ARM_AAPCS); |
| 368 | setLibcallCallingConv(RTLIB::UINTTOFP_I64_F32, CallingConv::ARM_AAPCS); |
| 369 | |
| 370 | // Long long helper functions |
| 371 | // RTABI chapter 4.2, Table 9 |
| 372 | setLibcallName(RTLIB::MUL_I64, "__aeabi_lmul"); |
| 373 | setLibcallName(RTLIB::SDIV_I64, "__aeabi_ldivmod"); |
| 374 | setLibcallName(RTLIB::UDIV_I64, "__aeabi_uldivmod"); |
| 375 | setLibcallName(RTLIB::SHL_I64, "__aeabi_llsl"); |
| 376 | setLibcallName(RTLIB::SRL_I64, "__aeabi_llsr"); |
| 377 | setLibcallName(RTLIB::SRA_I64, "__aeabi_lasr"); |
| 378 | setLibcallCallingConv(RTLIB::MUL_I64, CallingConv::ARM_AAPCS); |
| 379 | setLibcallCallingConv(RTLIB::SDIV_I64, CallingConv::ARM_AAPCS); |
| 380 | setLibcallCallingConv(RTLIB::UDIV_I64, CallingConv::ARM_AAPCS); |
| 381 | setLibcallCallingConv(RTLIB::SHL_I64, CallingConv::ARM_AAPCS); |
| 382 | setLibcallCallingConv(RTLIB::SRL_I64, CallingConv::ARM_AAPCS); |
| 383 | setLibcallCallingConv(RTLIB::SRA_I64, CallingConv::ARM_AAPCS); |
| 384 | |
| 385 | // Integer division functions |
| 386 | // RTABI chapter 4.3.1 |
| 387 | setLibcallName(RTLIB::SDIV_I8, "__aeabi_idiv"); |
| 388 | setLibcallName(RTLIB::SDIV_I16, "__aeabi_idiv"); |
| 389 | setLibcallName(RTLIB::SDIV_I32, "__aeabi_idiv"); |
| 390 | setLibcallName(RTLIB::UDIV_I8, "__aeabi_uidiv"); |
| 391 | setLibcallName(RTLIB::UDIV_I16, "__aeabi_uidiv"); |
| 392 | setLibcallName(RTLIB::UDIV_I32, "__aeabi_uidiv"); |
| 393 | setLibcallCallingConv(RTLIB::SDIV_I8, CallingConv::ARM_AAPCS); |
| 394 | setLibcallCallingConv(RTLIB::SDIV_I16, CallingConv::ARM_AAPCS); |
| 395 | setLibcallCallingConv(RTLIB::SDIV_I32, CallingConv::ARM_AAPCS); |
| 396 | setLibcallCallingConv(RTLIB::UDIV_I8, CallingConv::ARM_AAPCS); |
| 397 | setLibcallCallingConv(RTLIB::UDIV_I16, CallingConv::ARM_AAPCS); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 398 | setLibcallCallingConv(RTLIB::UDIV_I32, CallingConv::ARM_AAPCS); |
Renato Golin | 1ec11fb | 2011-05-22 21:41:23 +0000 | [diff] [blame] | 399 | |
| 400 | // Memory operations |
| 401 | // RTABI chapter 4.3.4 |
| 402 | setLibcallName(RTLIB::MEMCPY, "__aeabi_memcpy"); |
| 403 | setLibcallName(RTLIB::MEMMOVE, "__aeabi_memmove"); |
| 404 | setLibcallName(RTLIB::MEMSET, "__aeabi_memset"); |
Anton Korobeynikov | 72977a4 | 2009-08-14 20:10:52 +0000 | [diff] [blame] | 405 | } |
| 406 | |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 407 | if (Subtarget->isThumb1Only()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 408 | addRegisterClass(MVT::i32, ARM::tGPRRegisterClass); |
Jim Grosbach | 30eae3c | 2009-04-07 20:34:09 +0000 | [diff] [blame] | 409 | else |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 410 | addRegisterClass(MVT::i32, ARM::GPRRegisterClass); |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 411 | if (!UseSoftFloat && Subtarget->hasVFP2() && !Subtarget->isThumb1Only()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 412 | addRegisterClass(MVT::f32, ARM::SPRRegisterClass); |
Jim Grosbach | fcba5e6 | 2010-08-11 15:44:15 +0000 | [diff] [blame] | 413 | if (!Subtarget->isFPOnlySP()) |
| 414 | addRegisterClass(MVT::f64, ARM::DPRRegisterClass); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 415 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 416 | setTruncStoreAction(MVT::f64, MVT::f32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 417 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 418 | |
| 419 | if (Subtarget->hasNEON()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 420 | addDRTypeForNEON(MVT::v2f32); |
| 421 | addDRTypeForNEON(MVT::v8i8); |
| 422 | addDRTypeForNEON(MVT::v4i16); |
| 423 | addDRTypeForNEON(MVT::v2i32); |
| 424 | addDRTypeForNEON(MVT::v1i64); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 425 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 426 | addQRTypeForNEON(MVT::v4f32); |
| 427 | addQRTypeForNEON(MVT::v2f64); |
| 428 | addQRTypeForNEON(MVT::v16i8); |
| 429 | addQRTypeForNEON(MVT::v8i16); |
| 430 | addQRTypeForNEON(MVT::v4i32); |
| 431 | addQRTypeForNEON(MVT::v2i64); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 432 | |
Bob Wilson | 74dc72e | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 433 | // v2f64 is legal so that QR subregs can be extracted as f64 elements, but |
| 434 | // neither Neon nor VFP support any arithmetic operations on it. |
| 435 | setOperationAction(ISD::FADD, MVT::v2f64, Expand); |
| 436 | setOperationAction(ISD::FSUB, MVT::v2f64, Expand); |
| 437 | setOperationAction(ISD::FMUL, MVT::v2f64, Expand); |
| 438 | setOperationAction(ISD::FDIV, MVT::v2f64, Expand); |
| 439 | setOperationAction(ISD::FREM, MVT::v2f64, Expand); |
| 440 | setOperationAction(ISD::FCOPYSIGN, MVT::v2f64, Expand); |
| 441 | setOperationAction(ISD::VSETCC, MVT::v2f64, Expand); |
| 442 | setOperationAction(ISD::FNEG, MVT::v2f64, Expand); |
| 443 | setOperationAction(ISD::FABS, MVT::v2f64, Expand); |
| 444 | setOperationAction(ISD::FSQRT, MVT::v2f64, Expand); |
| 445 | setOperationAction(ISD::FSIN, MVT::v2f64, Expand); |
| 446 | setOperationAction(ISD::FCOS, MVT::v2f64, Expand); |
| 447 | setOperationAction(ISD::FPOWI, MVT::v2f64, Expand); |
| 448 | setOperationAction(ISD::FPOW, MVT::v2f64, Expand); |
| 449 | setOperationAction(ISD::FLOG, MVT::v2f64, Expand); |
| 450 | setOperationAction(ISD::FLOG2, MVT::v2f64, Expand); |
| 451 | setOperationAction(ISD::FLOG10, MVT::v2f64, Expand); |
| 452 | setOperationAction(ISD::FEXP, MVT::v2f64, Expand); |
| 453 | setOperationAction(ISD::FEXP2, MVT::v2f64, Expand); |
| 454 | setOperationAction(ISD::FCEIL, MVT::v2f64, Expand); |
| 455 | setOperationAction(ISD::FTRUNC, MVT::v2f64, Expand); |
| 456 | setOperationAction(ISD::FRINT, MVT::v2f64, Expand); |
| 457 | setOperationAction(ISD::FNEARBYINT, MVT::v2f64, Expand); |
| 458 | setOperationAction(ISD::FFLOOR, MVT::v2f64, Expand); |
| 459 | |
Bob Wilson | b31a11b | 2010-08-20 04:54:02 +0000 | [diff] [blame] | 460 | setTruncStoreAction(MVT::v2f64, MVT::v2f32, Expand); |
| 461 | |
Bob Wilson | 642b329 | 2009-09-16 00:32:15 +0000 | [diff] [blame] | 462 | // Neon does not support some operations on v1i64 and v2i64 types. |
| 463 | setOperationAction(ISD::MUL, MVT::v1i64, Expand); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 464 | // Custom handling for some quad-vector types to detect VMULL. |
| 465 | setOperationAction(ISD::MUL, MVT::v8i16, Custom); |
| 466 | setOperationAction(ISD::MUL, MVT::v4i32, Custom); |
| 467 | setOperationAction(ISD::MUL, MVT::v2i64, Custom); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 468 | // Custom handling for some vector types to avoid expensive expansions |
| 469 | setOperationAction(ISD::SDIV, MVT::v4i16, Custom); |
| 470 | setOperationAction(ISD::SDIV, MVT::v8i8, Custom); |
| 471 | setOperationAction(ISD::UDIV, MVT::v4i16, Custom); |
| 472 | setOperationAction(ISD::UDIV, MVT::v8i8, Custom); |
Bob Wilson | 642b329 | 2009-09-16 00:32:15 +0000 | [diff] [blame] | 473 | setOperationAction(ISD::VSETCC, MVT::v1i64, Expand); |
| 474 | setOperationAction(ISD::VSETCC, MVT::v2i64, Expand); |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 475 | // Neon does not have single instruction SINT_TO_FP and UINT_TO_FP with |
| 476 | // a destination type that is wider than the source. |
| 477 | setOperationAction(ISD::SINT_TO_FP, MVT::v4i16, Custom); |
| 478 | setOperationAction(ISD::UINT_TO_FP, MVT::v4i16, Custom); |
Bob Wilson | 642b329 | 2009-09-16 00:32:15 +0000 | [diff] [blame] | 479 | |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 480 | setTargetDAGCombine(ISD::INTRINSIC_VOID); |
| 481 | setTargetDAGCombine(ISD::INTRINSIC_W_CHAIN); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 482 | setTargetDAGCombine(ISD::INTRINSIC_WO_CHAIN); |
| 483 | setTargetDAGCombine(ISD::SHL); |
| 484 | setTargetDAGCombine(ISD::SRL); |
| 485 | setTargetDAGCombine(ISD::SRA); |
| 486 | setTargetDAGCombine(ISD::SIGN_EXTEND); |
| 487 | setTargetDAGCombine(ISD::ZERO_EXTEND); |
| 488 | setTargetDAGCombine(ISD::ANY_EXTEND); |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 489 | setTargetDAGCombine(ISD::SELECT_CC); |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 490 | setTargetDAGCombine(ISD::BUILD_VECTOR); |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 491 | setTargetDAGCombine(ISD::VECTOR_SHUFFLE); |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 492 | setTargetDAGCombine(ISD::INSERT_VECTOR_ELT); |
| 493 | setTargetDAGCombine(ISD::STORE); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 494 | } |
| 495 | |
Evan Cheng | 9f8cbd1 | 2007-05-18 00:19:34 +0000 | [diff] [blame] | 496 | computeRegisterProperties(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 497 | |
| 498 | // ARM does not have f32 extending load. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 499 | setLoadExtAction(ISD::EXTLOAD, MVT::f32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 500 | |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 501 | // ARM does not have i1 sign extending load. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 502 | setLoadExtAction(ISD::SEXTLOAD, MVT::i1, Promote); |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 503 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 504 | // ARM supports all 4 flavors of integer indexed load / store. |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 505 | if (!Subtarget->isThumb1Only()) { |
| 506 | for (unsigned im = (unsigned)ISD::PRE_INC; |
| 507 | im != (unsigned)ISD::LAST_INDEXED_MODE; ++im) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 508 | setIndexedLoadAction(im, MVT::i1, Legal); |
| 509 | setIndexedLoadAction(im, MVT::i8, Legal); |
| 510 | setIndexedLoadAction(im, MVT::i16, Legal); |
| 511 | setIndexedLoadAction(im, MVT::i32, Legal); |
| 512 | setIndexedStoreAction(im, MVT::i1, Legal); |
| 513 | setIndexedStoreAction(im, MVT::i8, Legal); |
| 514 | setIndexedStoreAction(im, MVT::i16, Legal); |
| 515 | setIndexedStoreAction(im, MVT::i32, Legal); |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 516 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | // i64 operation support. |
Eric Christopher | 2cc4013 | 2011-04-19 18:49:19 +0000 | [diff] [blame] | 520 | setOperationAction(ISD::MUL, MVT::i64, Expand); |
| 521 | setOperationAction(ISD::MULHU, MVT::i32, Expand); |
Evan Cheng | 5b9fcd1 | 2009-07-07 01:17:28 +0000 | [diff] [blame] | 522 | if (Subtarget->isThumb1Only()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 523 | setOperationAction(ISD::UMUL_LOHI, MVT::i32, Expand); |
| 524 | setOperationAction(ISD::SMUL_LOHI, MVT::i32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 525 | } |
Eric Christopher | 2cc4013 | 2011-04-19 18:49:19 +0000 | [diff] [blame] | 526 | if (Subtarget->isThumb1Only() || !Subtarget->hasV6Ops()) |
| 527 | setOperationAction(ISD::MULHS, MVT::i32, Expand); |
| 528 | |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 529 | setOperationAction(ISD::SHL_PARTS, MVT::i32, Custom); |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 530 | setOperationAction(ISD::SRA_PARTS, MVT::i32, Custom); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 531 | setOperationAction(ISD::SRL_PARTS, MVT::i32, Custom); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 532 | setOperationAction(ISD::SRL, MVT::i64, Custom); |
| 533 | setOperationAction(ISD::SRA, MVT::i64, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 534 | |
| 535 | // ARM does not have ROTL. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 536 | setOperationAction(ISD::ROTL, MVT::i32, Expand); |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 537 | setOperationAction(ISD::CTTZ, MVT::i32, Custom); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 538 | setOperationAction(ISD::CTPOP, MVT::i32, Expand); |
David Goodwin | 24062ac | 2009-06-26 20:47:43 +0000 | [diff] [blame] | 539 | if (!Subtarget->hasV5TOps() || Subtarget->isThumb1Only()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 540 | setOperationAction(ISD::CTLZ, MVT::i32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 541 | |
Lauro Ramos Venancio | 368f20f | 2007-03-16 22:54:16 +0000 | [diff] [blame] | 542 | // Only ARMv6 has BSWAP. |
| 543 | if (!Subtarget->hasV6Ops()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 544 | setOperationAction(ISD::BSWAP, MVT::i32, Expand); |
Lauro Ramos Venancio | 368f20f | 2007-03-16 22:54:16 +0000 | [diff] [blame] | 545 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 546 | // These are expanded into libcalls. |
Evan Cheng | 1f190c8 | 2010-11-19 06:28:11 +0000 | [diff] [blame] | 547 | if (!Subtarget->hasDivide() || !Subtarget->isThumb2()) { |
Jim Grosbach | b1dc393 | 2010-05-05 20:44:35 +0000 | [diff] [blame] | 548 | // v7M has a hardware divider |
| 549 | setOperationAction(ISD::SDIV, MVT::i32, Expand); |
| 550 | setOperationAction(ISD::UDIV, MVT::i32, Expand); |
| 551 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 552 | setOperationAction(ISD::SREM, MVT::i32, Expand); |
| 553 | setOperationAction(ISD::UREM, MVT::i32, Expand); |
| 554 | setOperationAction(ISD::SDIVREM, MVT::i32, Expand); |
| 555 | setOperationAction(ISD::UDIVREM, MVT::i32, Expand); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 556 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 557 | setOperationAction(ISD::GlobalAddress, MVT::i32, Custom); |
| 558 | setOperationAction(ISD::ConstantPool, MVT::i32, Custom); |
| 559 | setOperationAction(ISD::GLOBAL_OFFSET_TABLE, MVT::i32, Custom); |
| 560 | setOperationAction(ISD::GlobalTLSAddress, MVT::i32, Custom); |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 561 | setOperationAction(ISD::BlockAddress, MVT::i32, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 562 | |
Evan Cheng | 4da0c7c | 2011-04-08 21:37:21 +0000 | [diff] [blame] | 563 | setOperationAction(ISD::TRAP, MVT::Other, Legal); |
Evan Cheng | fb3611d | 2010-05-11 07:26:32 +0000 | [diff] [blame] | 564 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 565 | // Use the default implementation. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 566 | setOperationAction(ISD::VASTART, MVT::Other, Custom); |
| 567 | setOperationAction(ISD::VAARG, MVT::Other, Expand); |
| 568 | setOperationAction(ISD::VACOPY, MVT::Other, Expand); |
| 569 | setOperationAction(ISD::VAEND, MVT::Other, Expand); |
| 570 | setOperationAction(ISD::STACKSAVE, MVT::Other, Expand); |
| 571 | setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand); |
Jim Grosbach | bff3923 | 2009-08-12 17:38:44 +0000 | [diff] [blame] | 572 | setOperationAction(ISD::EHSELECTION, MVT::i32, Expand); |
Anton Korobeynikov | 5899a60 | 2011-01-24 22:38:45 +0000 | [diff] [blame] | 573 | setOperationAction(ISD::EXCEPTIONADDR, MVT::i32, Expand); |
| 574 | setExceptionPointerRegister(ARM::R0); |
| 575 | setExceptionSelectorRegister(ARM::R1); |
| 576 | |
Evan Cheng | 3a1588a | 2010-04-15 22:20:34 +0000 | [diff] [blame] | 577 | setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32, Expand); |
Evan Cheng | 11db068 | 2010-08-11 06:22:01 +0000 | [diff] [blame] | 578 | // ARMv6 Thumb1 (except for CPUs that support dmb / dsb) and earlier use |
| 579 | // the default expansion. |
| 580 | if (Subtarget->hasDataBarrier() || |
Bob Wilson | 54f9256 | 2010-11-09 22:50:44 +0000 | [diff] [blame] | 581 | (Subtarget->hasV6Ops() && !Subtarget->isThumb())) { |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 582 | // membarrier needs custom lowering; the rest are legal and handled |
| 583 | // normally. |
| 584 | setOperationAction(ISD::MEMBARRIER, MVT::Other, Custom); |
| 585 | } else { |
| 586 | // Set them all for expansion, which will force libcalls. |
| 587 | setOperationAction(ISD::MEMBARRIER, MVT::Other, Expand); |
| 588 | setOperationAction(ISD::ATOMIC_CMP_SWAP, MVT::i8, Expand); |
| 589 | setOperationAction(ISD::ATOMIC_CMP_SWAP, MVT::i16, Expand); |
| 590 | setOperationAction(ISD::ATOMIC_CMP_SWAP, MVT::i32, Expand); |
Jim Grosbach | ef6eb9c | 2010-06-18 23:03:10 +0000 | [diff] [blame] | 591 | setOperationAction(ISD::ATOMIC_SWAP, MVT::i8, Expand); |
| 592 | setOperationAction(ISD::ATOMIC_SWAP, MVT::i16, Expand); |
| 593 | setOperationAction(ISD::ATOMIC_SWAP, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 594 | setOperationAction(ISD::ATOMIC_LOAD_ADD, MVT::i8, Expand); |
| 595 | setOperationAction(ISD::ATOMIC_LOAD_ADD, MVT::i16, Expand); |
| 596 | setOperationAction(ISD::ATOMIC_LOAD_ADD, MVT::i32, Expand); |
| 597 | setOperationAction(ISD::ATOMIC_LOAD_SUB, MVT::i8, Expand); |
| 598 | setOperationAction(ISD::ATOMIC_LOAD_SUB, MVT::i16, Expand); |
| 599 | setOperationAction(ISD::ATOMIC_LOAD_SUB, MVT::i32, Expand); |
| 600 | setOperationAction(ISD::ATOMIC_LOAD_AND, MVT::i8, Expand); |
| 601 | setOperationAction(ISD::ATOMIC_LOAD_AND, MVT::i16, Expand); |
| 602 | setOperationAction(ISD::ATOMIC_LOAD_AND, MVT::i32, Expand); |
| 603 | setOperationAction(ISD::ATOMIC_LOAD_OR, MVT::i8, Expand); |
| 604 | setOperationAction(ISD::ATOMIC_LOAD_OR, MVT::i16, Expand); |
| 605 | setOperationAction(ISD::ATOMIC_LOAD_OR, MVT::i32, Expand); |
| 606 | setOperationAction(ISD::ATOMIC_LOAD_XOR, MVT::i8, Expand); |
| 607 | setOperationAction(ISD::ATOMIC_LOAD_XOR, MVT::i16, Expand); |
| 608 | setOperationAction(ISD::ATOMIC_LOAD_XOR, MVT::i32, Expand); |
| 609 | setOperationAction(ISD::ATOMIC_LOAD_NAND, MVT::i8, Expand); |
| 610 | setOperationAction(ISD::ATOMIC_LOAD_NAND, MVT::i16, Expand); |
| 611 | setOperationAction(ISD::ATOMIC_LOAD_NAND, MVT::i32, Expand); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 612 | setOperationAction(ISD::ATOMIC_LOAD_MIN, MVT::i8, Expand); |
| 613 | setOperationAction(ISD::ATOMIC_LOAD_MIN, MVT::i16, Expand); |
| 614 | setOperationAction(ISD::ATOMIC_LOAD_MIN, MVT::i32, Expand); |
| 615 | setOperationAction(ISD::ATOMIC_LOAD_MAX, MVT::i8, Expand); |
| 616 | setOperationAction(ISD::ATOMIC_LOAD_MAX, MVT::i16, Expand); |
| 617 | setOperationAction(ISD::ATOMIC_LOAD_MAX, MVT::i32, Expand); |
| 618 | setOperationAction(ISD::ATOMIC_LOAD_UMIN, MVT::i8, Expand); |
| 619 | setOperationAction(ISD::ATOMIC_LOAD_UMIN, MVT::i16, Expand); |
| 620 | setOperationAction(ISD::ATOMIC_LOAD_UMIN, MVT::i32, Expand); |
| 621 | setOperationAction(ISD::ATOMIC_LOAD_UMAX, MVT::i8, Expand); |
| 622 | setOperationAction(ISD::ATOMIC_LOAD_UMAX, MVT::i16, Expand); |
| 623 | setOperationAction(ISD::ATOMIC_LOAD_UMAX, MVT::i32, Expand); |
Jim Grosbach | 5def57a | 2010-06-23 16:08:49 +0000 | [diff] [blame] | 624 | // Since the libcalls include locking, fold in the fences |
| 625 | setShouldFoldAtomicFences(true); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 626 | } |
| 627 | // 64-bit versions are always libcalls (for now) |
| 628 | setOperationAction(ISD::ATOMIC_CMP_SWAP, MVT::i64, Expand); |
Jim Grosbach | ef6eb9c | 2010-06-18 23:03:10 +0000 | [diff] [blame] | 629 | setOperationAction(ISD::ATOMIC_SWAP, MVT::i64, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 630 | setOperationAction(ISD::ATOMIC_LOAD_ADD, MVT::i64, Expand); |
| 631 | setOperationAction(ISD::ATOMIC_LOAD_SUB, MVT::i64, Expand); |
| 632 | setOperationAction(ISD::ATOMIC_LOAD_AND, MVT::i64, Expand); |
| 633 | setOperationAction(ISD::ATOMIC_LOAD_OR, MVT::i64, Expand); |
| 634 | setOperationAction(ISD::ATOMIC_LOAD_XOR, MVT::i64, Expand); |
| 635 | setOperationAction(ISD::ATOMIC_LOAD_NAND, MVT::i64, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 636 | |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 637 | setOperationAction(ISD::PREFETCH, MVT::Other, Custom); |
Evan Cheng | bc7deb0 | 2010-11-03 05:14:24 +0000 | [diff] [blame] | 638 | |
Eli Friedman | a2c6f45 | 2010-06-26 04:36:50 +0000 | [diff] [blame] | 639 | // Requires SXTB/SXTH, available on v6 and up in both ARM and Thumb modes. |
| 640 | if (!Subtarget->hasV6Ops()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 641 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i16, Expand); |
| 642 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i8, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 643 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 644 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 645 | |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 646 | if (!UseSoftFloat && Subtarget->hasVFP2() && !Subtarget->isThumb1Only()) { |
Bob Wilson | cb9a6aa | 2010-01-19 22:56:26 +0000 | [diff] [blame] | 647 | // Turn f64->i64 into VMOVRRD, i64 -> f64 to VMOVDRR |
| 648 | // iff target supports vfp2. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 649 | setOperationAction(ISD::BITCAST, MVT::i64, Custom); |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 650 | setOperationAction(ISD::FLT_ROUNDS_, MVT::i32, Custom); |
| 651 | } |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 652 | |
| 653 | // We want to custom lower some of our intrinsics. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 654 | setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom); |
Jim Grosbach | e97f968 | 2010-07-07 00:07:57 +0000 | [diff] [blame] | 655 | if (Subtarget->isTargetDarwin()) { |
| 656 | setOperationAction(ISD::EH_SJLJ_SETJMP, MVT::i32, Custom); |
| 657 | setOperationAction(ISD::EH_SJLJ_LONGJMP, MVT::Other, Custom); |
Jim Grosbach | e4ad387 | 2010-10-19 23:27:08 +0000 | [diff] [blame] | 658 | setOperationAction(ISD::EH_SJLJ_DISPATCHSETUP, MVT::Other, Custom); |
John McCall | 5f8fd54 | 2011-05-29 19:50:32 +0000 | [diff] [blame^] | 659 | setLibcallName(RTLIB::UNWIND_RESUME, "_Unwind_SjLj_Resume"); |
Jim Grosbach | e97f968 | 2010-07-07 00:07:57 +0000 | [diff] [blame] | 660 | } |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 661 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 662 | setOperationAction(ISD::SETCC, MVT::i32, Expand); |
| 663 | setOperationAction(ISD::SETCC, MVT::f32, Expand); |
| 664 | setOperationAction(ISD::SETCC, MVT::f64, Expand); |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 665 | setOperationAction(ISD::SELECT, MVT::i32, Custom); |
| 666 | setOperationAction(ISD::SELECT, MVT::f32, Custom); |
| 667 | setOperationAction(ISD::SELECT, MVT::f64, Custom); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 668 | setOperationAction(ISD::SELECT_CC, MVT::i32, Custom); |
| 669 | setOperationAction(ISD::SELECT_CC, MVT::f32, Custom); |
| 670 | setOperationAction(ISD::SELECT_CC, MVT::f64, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 671 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 672 | setOperationAction(ISD::BRCOND, MVT::Other, Expand); |
| 673 | setOperationAction(ISD::BR_CC, MVT::i32, Custom); |
| 674 | setOperationAction(ISD::BR_CC, MVT::f32, Custom); |
| 675 | setOperationAction(ISD::BR_CC, MVT::f64, Custom); |
| 676 | setOperationAction(ISD::BR_JT, MVT::Other, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 677 | |
Dan Gohman | f96e4de | 2007-10-11 23:21:31 +0000 | [diff] [blame] | 678 | // We don't support sin/cos/fmod/copysign/pow |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 679 | setOperationAction(ISD::FSIN, MVT::f64, Expand); |
| 680 | setOperationAction(ISD::FSIN, MVT::f32, Expand); |
| 681 | setOperationAction(ISD::FCOS, MVT::f32, Expand); |
| 682 | setOperationAction(ISD::FCOS, MVT::f64, Expand); |
| 683 | setOperationAction(ISD::FREM, MVT::f64, Expand); |
| 684 | setOperationAction(ISD::FREM, MVT::f32, Expand); |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 685 | if (!UseSoftFloat && Subtarget->hasVFP2() && !Subtarget->isThumb1Only()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 686 | setOperationAction(ISD::FCOPYSIGN, MVT::f64, Custom); |
| 687 | setOperationAction(ISD::FCOPYSIGN, MVT::f32, Custom); |
Evan Cheng | 110cf48 | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 688 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 689 | setOperationAction(ISD::FPOW, MVT::f64, Expand); |
| 690 | setOperationAction(ISD::FPOW, MVT::f32, Expand); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 691 | |
Anton Korobeynikov | bec3dd2 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 692 | // Various VFP goodness |
| 693 | if (!UseSoftFloat && !Subtarget->isThumb1Only()) { |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 694 | // int <-> fp are custom expanded into bit_convert + ARMISD ops. |
| 695 | if (Subtarget->hasVFP2()) { |
| 696 | setOperationAction(ISD::SINT_TO_FP, MVT::i32, Custom); |
| 697 | setOperationAction(ISD::UINT_TO_FP, MVT::i32, Custom); |
| 698 | setOperationAction(ISD::FP_TO_UINT, MVT::i32, Custom); |
| 699 | setOperationAction(ISD::FP_TO_SINT, MVT::i32, Custom); |
| 700 | } |
Anton Korobeynikov | bec3dd2 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 701 | // Special handling for half-precision FP. |
Anton Korobeynikov | f0d5007 | 2010-03-18 22:35:37 +0000 | [diff] [blame] | 702 | if (!Subtarget->hasFP16()) { |
| 703 | setOperationAction(ISD::FP16_TO_FP32, MVT::f32, Expand); |
| 704 | setOperationAction(ISD::FP32_TO_FP16, MVT::i32, Expand); |
Anton Korobeynikov | bec3dd2 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 705 | } |
Evan Cheng | 110cf48 | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 706 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 707 | |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 708 | // We have target-specific dag combine patterns for the following nodes: |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 709 | // ARMISD::VMOVRRD - No need to call setTargetDAGCombine |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 710 | setTargetDAGCombine(ISD::ADD); |
| 711 | setTargetDAGCombine(ISD::SUB); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 712 | setTargetDAGCombine(ISD::MUL); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 713 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 714 | if (Subtarget->hasV6T2Ops() || Subtarget->hasNEON()) |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 715 | setTargetDAGCombine(ISD::OR); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 716 | if (Subtarget->hasNEON()) |
| 717 | setTargetDAGCombine(ISD::AND); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 718 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 719 | setStackPointerRegisterToSaveRestore(ARM::SP); |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 720 | |
Evan Cheng | f7d87ee | 2010-05-21 00:43:17 +0000 | [diff] [blame] | 721 | if (UseSoftFloat || Subtarget->isThumb1Only() || !Subtarget->hasVFP2()) |
| 722 | setSchedulingPreference(Sched::RegPressure); |
| 723 | else |
| 724 | setSchedulingPreference(Sched::Hybrid); |
Dale Johannesen | 8dd86c1 | 2007-05-17 21:31:21 +0000 | [diff] [blame] | 725 | |
Evan Cheng | 0521928 | 2011-01-06 06:52:41 +0000 | [diff] [blame] | 726 | //// temporary - rewrite interface to use type |
| 727 | maxStoresPerMemcpy = maxStoresPerMemcpyOptSize = 1; |
Evan Cheng | f679939 | 2010-06-26 01:52:05 +0000 | [diff] [blame] | 728 | |
Rafael Espindola | cbeeae2 | 2010-07-11 04:01:49 +0000 | [diff] [blame] | 729 | // On ARM arguments smaller than 4 bytes are extended, so all arguments |
| 730 | // are at least 4 bytes aligned. |
| 731 | setMinStackArgumentAlignment(4); |
| 732 | |
Evan Cheng | fff606d | 2010-09-24 19:07:23 +0000 | [diff] [blame] | 733 | benefitFromCodePlacementOpt = true; |
Eli Friedman | fc5d305 | 2011-05-06 20:34:06 +0000 | [diff] [blame] | 734 | |
| 735 | setMinFunctionAlignment(Subtarget->isThumb() ? 1 : 2); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 736 | } |
| 737 | |
Andrew Trick | 32cec0a | 2011-01-19 02:35:27 +0000 | [diff] [blame] | 738 | // FIXME: It might make sense to define the representative register class as the |
| 739 | // nearest super-register that has a non-null superset. For example, DPR_VFP2 is |
| 740 | // a super-register of SPR, and DPR is a superset if DPR_VFP2. Consequently, |
| 741 | // SPR's representative would be DPR_VFP2. This should work well if register |
| 742 | // pressure tracking were modified such that a register use would increment the |
| 743 | // pressure of the register class's representative and all of it's super |
| 744 | // classes' representatives transitively. We have not implemented this because |
| 745 | // of the difficulty prior to coalescing of modeling operand register classes |
Chris Lattner | 7a2bdde | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 746 | // due to the common occurrence of cross class copies and subregister insertions |
Andrew Trick | 32cec0a | 2011-01-19 02:35:27 +0000 | [diff] [blame] | 747 | // and extractions. |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 748 | std::pair<const TargetRegisterClass*, uint8_t> |
| 749 | ARMTargetLowering::findRepresentativeClass(EVT VT) const{ |
| 750 | const TargetRegisterClass *RRC = 0; |
| 751 | uint8_t Cost = 1; |
| 752 | switch (VT.getSimpleVT().SimpleTy) { |
Evan Cheng | d70f57b | 2010-07-19 22:15:08 +0000 | [diff] [blame] | 753 | default: |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 754 | return TargetLowering::findRepresentativeClass(VT); |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 755 | // Use DPR as representative register class for all floating point |
| 756 | // and vector types. Since there are 32 SPR registers and 32 DPR registers so |
| 757 | // the cost is 1 for both f32 and f64. |
| 758 | case MVT::f32: case MVT::f64: case MVT::v8i8: case MVT::v4i16: |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 759 | case MVT::v2i32: case MVT::v1i64: case MVT::v2f32: |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 760 | RRC = ARM::DPRRegisterClass; |
Andrew Trick | 32cec0a | 2011-01-19 02:35:27 +0000 | [diff] [blame] | 761 | // When NEON is used for SP, only half of the register file is available |
| 762 | // because operations that define both SP and DP results will be constrained |
| 763 | // to the VFP2 class (D0-D15). We currently model this constraint prior to |
| 764 | // coalescing by double-counting the SP regs. See the FIXME above. |
| 765 | if (Subtarget->useNEONForSinglePrecisionFP()) |
| 766 | Cost = 2; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 767 | break; |
| 768 | case MVT::v16i8: case MVT::v8i16: case MVT::v4i32: case MVT::v2i64: |
| 769 | case MVT::v4f32: case MVT::v2f64: |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 770 | RRC = ARM::DPRRegisterClass; |
| 771 | Cost = 2; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 772 | break; |
| 773 | case MVT::v4i64: |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 774 | RRC = ARM::DPRRegisterClass; |
| 775 | Cost = 4; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 776 | break; |
| 777 | case MVT::v8i64: |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 778 | RRC = ARM::DPRRegisterClass; |
| 779 | Cost = 8; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 780 | break; |
Evan Cheng | d70f57b | 2010-07-19 22:15:08 +0000 | [diff] [blame] | 781 | } |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 782 | return std::make_pair(RRC, Cost); |
Evan Cheng | d70f57b | 2010-07-19 22:15:08 +0000 | [diff] [blame] | 783 | } |
| 784 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 785 | const char *ARMTargetLowering::getTargetNodeName(unsigned Opcode) const { |
| 786 | switch (Opcode) { |
| 787 | default: return 0; |
| 788 | case ARMISD::Wrapper: return "ARMISD::Wrapper"; |
Evan Cheng | 53519f0 | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 789 | case ARMISD::WrapperDYN: return "ARMISD::WrapperDYN"; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 790 | case ARMISD::WrapperPIC: return "ARMISD::WrapperPIC"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 791 | case ARMISD::WrapperJT: return "ARMISD::WrapperJT"; |
| 792 | case ARMISD::CALL: return "ARMISD::CALL"; |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 793 | case ARMISD::CALL_PRED: return "ARMISD::CALL_PRED"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 794 | case ARMISD::CALL_NOLINK: return "ARMISD::CALL_NOLINK"; |
| 795 | case ARMISD::tCALL: return "ARMISD::tCALL"; |
| 796 | case ARMISD::BRCOND: return "ARMISD::BRCOND"; |
| 797 | case ARMISD::BR_JT: return "ARMISD::BR_JT"; |
Evan Cheng | 5657c01 | 2009-07-29 02:18:14 +0000 | [diff] [blame] | 798 | case ARMISD::BR2_JT: return "ARMISD::BR2_JT"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 799 | case ARMISD::RET_FLAG: return "ARMISD::RET_FLAG"; |
| 800 | case ARMISD::PIC_ADD: return "ARMISD::PIC_ADD"; |
| 801 | case ARMISD::CMP: return "ARMISD::CMP"; |
David Goodwin | c0309b4 | 2009-06-29 15:33:01 +0000 | [diff] [blame] | 802 | case ARMISD::CMPZ: return "ARMISD::CMPZ"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 803 | case ARMISD::CMPFP: return "ARMISD::CMPFP"; |
| 804 | case ARMISD::CMPFPw0: return "ARMISD::CMPFPw0"; |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 805 | case ARMISD::BCC_i64: return "ARMISD::BCC_i64"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 806 | case ARMISD::FMSTAT: return "ARMISD::FMSTAT"; |
| 807 | case ARMISD::CMOV: return "ARMISD::CMOV"; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 808 | |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 809 | case ARMISD::RBIT: return "ARMISD::RBIT"; |
| 810 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 811 | case ARMISD::FTOSI: return "ARMISD::FTOSI"; |
| 812 | case ARMISD::FTOUI: return "ARMISD::FTOUI"; |
| 813 | case ARMISD::SITOF: return "ARMISD::SITOF"; |
| 814 | case ARMISD::UITOF: return "ARMISD::UITOF"; |
| 815 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 816 | case ARMISD::SRL_FLAG: return "ARMISD::SRL_FLAG"; |
| 817 | case ARMISD::SRA_FLAG: return "ARMISD::SRA_FLAG"; |
| 818 | case ARMISD::RRX: return "ARMISD::RRX"; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 819 | |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 820 | case ARMISD::VMOVRRD: return "ARMISD::VMOVRRD"; |
| 821 | case ARMISD::VMOVDRR: return "ARMISD::VMOVDRR"; |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 822 | |
Evan Cheng | c594208 | 2009-10-28 06:55:03 +0000 | [diff] [blame] | 823 | case ARMISD::EH_SJLJ_SETJMP: return "ARMISD::EH_SJLJ_SETJMP"; |
| 824 | case ARMISD::EH_SJLJ_LONGJMP:return "ARMISD::EH_SJLJ_LONGJMP"; |
Jim Grosbach | e4ad387 | 2010-10-19 23:27:08 +0000 | [diff] [blame] | 825 | case ARMISD::EH_SJLJ_DISPATCHSETUP:return "ARMISD::EH_SJLJ_DISPATCHSETUP"; |
Evan Cheng | c594208 | 2009-10-28 06:55:03 +0000 | [diff] [blame] | 826 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 827 | case ARMISD::TC_RETURN: return "ARMISD::TC_RETURN"; |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 828 | |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 829 | case ARMISD::THREAD_POINTER:return "ARMISD::THREAD_POINTER"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 830 | |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 831 | case ARMISD::DYN_ALLOC: return "ARMISD::DYN_ALLOC"; |
| 832 | |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 833 | case ARMISD::MEMBARRIER: return "ARMISD::MEMBARRIER"; |
Bob Wilson | f74a429 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 834 | case ARMISD::MEMBARRIER_MCR: return "ARMISD::MEMBARRIER_MCR"; |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 835 | |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 836 | case ARMISD::PRELOAD: return "ARMISD::PRELOAD"; |
| 837 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 838 | case ARMISD::VCEQ: return "ARMISD::VCEQ"; |
Bob Wilson | 3a75b9b | 2010-12-18 00:04:26 +0000 | [diff] [blame] | 839 | case ARMISD::VCEQZ: return "ARMISD::VCEQZ"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 840 | case ARMISD::VCGE: return "ARMISD::VCGE"; |
Bob Wilson | 3a75b9b | 2010-12-18 00:04:26 +0000 | [diff] [blame] | 841 | case ARMISD::VCGEZ: return "ARMISD::VCGEZ"; |
| 842 | case ARMISD::VCLEZ: return "ARMISD::VCLEZ"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 843 | case ARMISD::VCGEU: return "ARMISD::VCGEU"; |
| 844 | case ARMISD::VCGT: return "ARMISD::VCGT"; |
Bob Wilson | 3a75b9b | 2010-12-18 00:04:26 +0000 | [diff] [blame] | 845 | case ARMISD::VCGTZ: return "ARMISD::VCGTZ"; |
| 846 | case ARMISD::VCLTZ: return "ARMISD::VCLTZ"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 847 | case ARMISD::VCGTU: return "ARMISD::VCGTU"; |
| 848 | case ARMISD::VTST: return "ARMISD::VTST"; |
| 849 | |
| 850 | case ARMISD::VSHL: return "ARMISD::VSHL"; |
| 851 | case ARMISD::VSHRs: return "ARMISD::VSHRs"; |
| 852 | case ARMISD::VSHRu: return "ARMISD::VSHRu"; |
| 853 | case ARMISD::VSHLLs: return "ARMISD::VSHLLs"; |
| 854 | case ARMISD::VSHLLu: return "ARMISD::VSHLLu"; |
| 855 | case ARMISD::VSHLLi: return "ARMISD::VSHLLi"; |
| 856 | case ARMISD::VSHRN: return "ARMISD::VSHRN"; |
| 857 | case ARMISD::VRSHRs: return "ARMISD::VRSHRs"; |
| 858 | case ARMISD::VRSHRu: return "ARMISD::VRSHRu"; |
| 859 | case ARMISD::VRSHRN: return "ARMISD::VRSHRN"; |
| 860 | case ARMISD::VQSHLs: return "ARMISD::VQSHLs"; |
| 861 | case ARMISD::VQSHLu: return "ARMISD::VQSHLu"; |
| 862 | case ARMISD::VQSHLsu: return "ARMISD::VQSHLsu"; |
| 863 | case ARMISD::VQSHRNs: return "ARMISD::VQSHRNs"; |
| 864 | case ARMISD::VQSHRNu: return "ARMISD::VQSHRNu"; |
| 865 | case ARMISD::VQSHRNsu: return "ARMISD::VQSHRNsu"; |
| 866 | case ARMISD::VQRSHRNs: return "ARMISD::VQRSHRNs"; |
| 867 | case ARMISD::VQRSHRNu: return "ARMISD::VQRSHRNu"; |
| 868 | case ARMISD::VQRSHRNsu: return "ARMISD::VQRSHRNsu"; |
| 869 | case ARMISD::VGETLANEu: return "ARMISD::VGETLANEu"; |
| 870 | case ARMISD::VGETLANEs: return "ARMISD::VGETLANEs"; |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 871 | case ARMISD::VMOVIMM: return "ARMISD::VMOVIMM"; |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 872 | case ARMISD::VMVNIMM: return "ARMISD::VMVNIMM"; |
Bob Wilson | c1d287b | 2009-08-14 05:13:08 +0000 | [diff] [blame] | 873 | case ARMISD::VDUP: return "ARMISD::VDUP"; |
Bob Wilson | 0ce3710 | 2009-08-14 05:08:32 +0000 | [diff] [blame] | 874 | case ARMISD::VDUPLANE: return "ARMISD::VDUPLANE"; |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 875 | case ARMISD::VEXT: return "ARMISD::VEXT"; |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 876 | case ARMISD::VREV64: return "ARMISD::VREV64"; |
| 877 | case ARMISD::VREV32: return "ARMISD::VREV32"; |
| 878 | case ARMISD::VREV16: return "ARMISD::VREV16"; |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 879 | case ARMISD::VZIP: return "ARMISD::VZIP"; |
| 880 | case ARMISD::VUZP: return "ARMISD::VUZP"; |
| 881 | case ARMISD::VTRN: return "ARMISD::VTRN"; |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 882 | case ARMISD::VTBL1: return "ARMISD::VTBL1"; |
| 883 | case ARMISD::VTBL2: return "ARMISD::VTBL2"; |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 884 | case ARMISD::VMULLs: return "ARMISD::VMULLs"; |
| 885 | case ARMISD::VMULLu: return "ARMISD::VMULLu"; |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 886 | case ARMISD::BUILD_VECTOR: return "ARMISD::BUILD_VECTOR"; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 887 | case ARMISD::FMAX: return "ARMISD::FMAX"; |
| 888 | case ARMISD::FMIN: return "ARMISD::FMIN"; |
Jim Grosbach | dd7d28a | 2010-07-17 01:50:57 +0000 | [diff] [blame] | 889 | case ARMISD::BFI: return "ARMISD::BFI"; |
Bob Wilson | 364a72a | 2010-11-28 06:51:11 +0000 | [diff] [blame] | 890 | case ARMISD::VORRIMM: return "ARMISD::VORRIMM"; |
| 891 | case ARMISD::VBICIMM: return "ARMISD::VBICIMM"; |
Cameron Zwarich | c0e6d78 | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 892 | case ARMISD::VBSL: return "ARMISD::VBSL"; |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 893 | case ARMISD::VLD2DUP: return "ARMISD::VLD2DUP"; |
| 894 | case ARMISD::VLD3DUP: return "ARMISD::VLD3DUP"; |
| 895 | case ARMISD::VLD4DUP: return "ARMISD::VLD4DUP"; |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 896 | case ARMISD::VLD1_UPD: return "ARMISD::VLD1_UPD"; |
| 897 | case ARMISD::VLD2_UPD: return "ARMISD::VLD2_UPD"; |
| 898 | case ARMISD::VLD3_UPD: return "ARMISD::VLD3_UPD"; |
| 899 | case ARMISD::VLD4_UPD: return "ARMISD::VLD4_UPD"; |
| 900 | case ARMISD::VLD2LN_UPD: return "ARMISD::VLD2LN_UPD"; |
| 901 | case ARMISD::VLD3LN_UPD: return "ARMISD::VLD3LN_UPD"; |
| 902 | case ARMISD::VLD4LN_UPD: return "ARMISD::VLD4LN_UPD"; |
| 903 | case ARMISD::VLD2DUP_UPD: return "ARMISD::VLD2DUP_UPD"; |
| 904 | case ARMISD::VLD3DUP_UPD: return "ARMISD::VLD3DUP_UPD"; |
| 905 | case ARMISD::VLD4DUP_UPD: return "ARMISD::VLD4DUP_UPD"; |
| 906 | case ARMISD::VST1_UPD: return "ARMISD::VST1_UPD"; |
| 907 | case ARMISD::VST2_UPD: return "ARMISD::VST2_UPD"; |
| 908 | case ARMISD::VST3_UPD: return "ARMISD::VST3_UPD"; |
| 909 | case ARMISD::VST4_UPD: return "ARMISD::VST4_UPD"; |
| 910 | case ARMISD::VST2LN_UPD: return "ARMISD::VST2LN_UPD"; |
| 911 | case ARMISD::VST3LN_UPD: return "ARMISD::VST3LN_UPD"; |
| 912 | case ARMISD::VST4LN_UPD: return "ARMISD::VST4LN_UPD"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 913 | } |
| 914 | } |
| 915 | |
Evan Cheng | 06b666c | 2010-05-15 02:18:07 +0000 | [diff] [blame] | 916 | /// getRegClassFor - Return the register class that should be used for the |
| 917 | /// specified value type. |
| 918 | TargetRegisterClass *ARMTargetLowering::getRegClassFor(EVT VT) const { |
| 919 | // Map v4i64 to QQ registers but do not make the type legal. Similarly map |
| 920 | // v8i64 to QQQQ registers. v4i64 and v8i64 are only used for REG_SEQUENCE to |
| 921 | // load / store 4 to 8 consecutive D registers. |
Evan Cheng | 4782b1e | 2010-05-15 02:20:21 +0000 | [diff] [blame] | 922 | if (Subtarget->hasNEON()) { |
| 923 | if (VT == MVT::v4i64) |
| 924 | return ARM::QQPRRegisterClass; |
| 925 | else if (VT == MVT::v8i64) |
| 926 | return ARM::QQQQPRRegisterClass; |
| 927 | } |
Evan Cheng | 06b666c | 2010-05-15 02:18:07 +0000 | [diff] [blame] | 928 | return TargetLowering::getRegClassFor(VT); |
| 929 | } |
| 930 | |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 931 | // Create a fast isel object. |
| 932 | FastISel * |
| 933 | ARMTargetLowering::createFastISel(FunctionLoweringInfo &funcInfo) const { |
| 934 | return ARM::createFastISel(funcInfo); |
| 935 | } |
| 936 | |
Anton Korobeynikov | cec36f4 | 2010-07-24 21:52:08 +0000 | [diff] [blame] | 937 | /// getMaximalGlobalOffset - Returns the maximal possible offset which can |
| 938 | /// be used for loads / stores from the global. |
| 939 | unsigned ARMTargetLowering::getMaximalGlobalOffset() const { |
| 940 | return (Subtarget->isThumb1Only() ? 127 : 4095); |
| 941 | } |
| 942 | |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 943 | Sched::Preference ARMTargetLowering::getSchedulingPreference(SDNode *N) const { |
Evan Cheng | c10f543 | 2010-05-28 23:25:23 +0000 | [diff] [blame] | 944 | unsigned NumVals = N->getNumValues(); |
| 945 | if (!NumVals) |
| 946 | return Sched::RegPressure; |
| 947 | |
| 948 | for (unsigned i = 0; i != NumVals; ++i) { |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 949 | EVT VT = N->getValueType(i); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 950 | if (VT == MVT::Glue || VT == MVT::Other) |
Evan Cheng | d7e473c | 2010-10-29 18:07:31 +0000 | [diff] [blame] | 951 | continue; |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 952 | if (VT.isFloatingPoint() || VT.isVector()) |
| 953 | return Sched::Latency; |
| 954 | } |
Evan Cheng | c10f543 | 2010-05-28 23:25:23 +0000 | [diff] [blame] | 955 | |
| 956 | if (!N->isMachineOpcode()) |
| 957 | return Sched::RegPressure; |
| 958 | |
| 959 | // Load are scheduled for latency even if there instruction itinerary |
| 960 | // is not available. |
| 961 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 962 | const TargetInstrDesc &TID = TII->get(N->getMachineOpcode()); |
Evan Cheng | d7e473c | 2010-10-29 18:07:31 +0000 | [diff] [blame] | 963 | |
| 964 | if (TID.getNumDefs() == 0) |
| 965 | return Sched::RegPressure; |
| 966 | if (!Itins->isEmpty() && |
| 967 | Itins->getOperandCycle(TID.getSchedClass(), 0) > 2) |
Evan Cheng | c10f543 | 2010-05-28 23:25:23 +0000 | [diff] [blame] | 968 | return Sched::Latency; |
| 969 | |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 970 | return Sched::RegPressure; |
| 971 | } |
| 972 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 973 | //===----------------------------------------------------------------------===// |
| 974 | // Lowering Code |
| 975 | //===----------------------------------------------------------------------===// |
| 976 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 977 | /// IntCCToARMCC - Convert a DAG integer condition code to an ARM CC |
| 978 | static ARMCC::CondCodes IntCCToARMCC(ISD::CondCode CC) { |
| 979 | switch (CC) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 980 | default: llvm_unreachable("Unknown condition code!"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 981 | case ISD::SETNE: return ARMCC::NE; |
| 982 | case ISD::SETEQ: return ARMCC::EQ; |
| 983 | case ISD::SETGT: return ARMCC::GT; |
| 984 | case ISD::SETGE: return ARMCC::GE; |
| 985 | case ISD::SETLT: return ARMCC::LT; |
| 986 | case ISD::SETLE: return ARMCC::LE; |
| 987 | case ISD::SETUGT: return ARMCC::HI; |
| 988 | case ISD::SETUGE: return ARMCC::HS; |
| 989 | case ISD::SETULT: return ARMCC::LO; |
| 990 | case ISD::SETULE: return ARMCC::LS; |
| 991 | } |
| 992 | } |
| 993 | |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 994 | /// FPCCToARMCC - Convert a DAG fp condition code to an ARM CC. |
| 995 | static void FPCCToARMCC(ISD::CondCode CC, ARMCC::CondCodes &CondCode, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 996 | ARMCC::CondCodes &CondCode2) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 997 | CondCode2 = ARMCC::AL; |
| 998 | switch (CC) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 999 | default: llvm_unreachable("Unknown FP condition!"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1000 | case ISD::SETEQ: |
| 1001 | case ISD::SETOEQ: CondCode = ARMCC::EQ; break; |
| 1002 | case ISD::SETGT: |
| 1003 | case ISD::SETOGT: CondCode = ARMCC::GT; break; |
| 1004 | case ISD::SETGE: |
| 1005 | case ISD::SETOGE: CondCode = ARMCC::GE; break; |
| 1006 | case ISD::SETOLT: CondCode = ARMCC::MI; break; |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 1007 | case ISD::SETOLE: CondCode = ARMCC::LS; break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1008 | case ISD::SETONE: CondCode = ARMCC::MI; CondCode2 = ARMCC::GT; break; |
| 1009 | case ISD::SETO: CondCode = ARMCC::VC; break; |
| 1010 | case ISD::SETUO: CondCode = ARMCC::VS; break; |
| 1011 | case ISD::SETUEQ: CondCode = ARMCC::EQ; CondCode2 = ARMCC::VS; break; |
| 1012 | case ISD::SETUGT: CondCode = ARMCC::HI; break; |
| 1013 | case ISD::SETUGE: CondCode = ARMCC::PL; break; |
| 1014 | case ISD::SETLT: |
| 1015 | case ISD::SETULT: CondCode = ARMCC::LT; break; |
| 1016 | case ISD::SETLE: |
| 1017 | case ISD::SETULE: CondCode = ARMCC::LE; break; |
| 1018 | case ISD::SETNE: |
| 1019 | case ISD::SETUNE: CondCode = ARMCC::NE; break; |
| 1020 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1021 | } |
| 1022 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1023 | //===----------------------------------------------------------------------===// |
| 1024 | // Calling Convention Implementation |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1025 | //===----------------------------------------------------------------------===// |
| 1026 | |
| 1027 | #include "ARMGenCallingConv.inc" |
| 1028 | |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1029 | /// CCAssignFnForNode - Selects the correct CCAssignFn for a the |
| 1030 | /// given CallingConvention value. |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1031 | CCAssignFn *ARMTargetLowering::CCAssignFnForNode(CallingConv::ID CC, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1032 | bool Return, |
| 1033 | bool isVarArg) const { |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1034 | switch (CC) { |
| 1035 | default: |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1036 | llvm_unreachable("Unsupported calling convention"); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1037 | case CallingConv::Fast: |
Evan Cheng | 5c2d428 | 2010-10-23 02:19:37 +0000 | [diff] [blame] | 1038 | if (Subtarget->hasVFP2() && !isVarArg) { |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1039 | if (!Subtarget->isAAPCS_ABI()) |
| 1040 | return (Return ? RetFastCC_ARM_APCS : FastCC_ARM_APCS); |
| 1041 | // For AAPCS ABI targets, just use VFP variant of the calling convention. |
| 1042 | return (Return ? RetCC_ARM_AAPCS_VFP : CC_ARM_AAPCS_VFP); |
| 1043 | } |
| 1044 | // Fallthrough |
| 1045 | case CallingConv::C: { |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1046 | // Use target triple & subtarget features to do actual dispatch. |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1047 | if (!Subtarget->isAAPCS_ABI()) |
| 1048 | return (Return ? RetCC_ARM_APCS : CC_ARM_APCS); |
| 1049 | else if (Subtarget->hasVFP2() && |
| 1050 | FloatABIType == FloatABI::Hard && !isVarArg) |
| 1051 | return (Return ? RetCC_ARM_AAPCS_VFP : CC_ARM_AAPCS_VFP); |
| 1052 | return (Return ? RetCC_ARM_AAPCS : CC_ARM_AAPCS); |
| 1053 | } |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1054 | case CallingConv::ARM_AAPCS_VFP: |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1055 | return (Return ? RetCC_ARM_AAPCS_VFP : CC_ARM_AAPCS_VFP); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1056 | case CallingConv::ARM_AAPCS: |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1057 | return (Return ? RetCC_ARM_AAPCS : CC_ARM_AAPCS); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1058 | case CallingConv::ARM_APCS: |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1059 | return (Return ? RetCC_ARM_APCS : CC_ARM_APCS); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1060 | } |
| 1061 | } |
| 1062 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1063 | /// LowerCallResult - Lower the result values of a call into the |
| 1064 | /// appropriate copies out of appropriate physical registers. |
| 1065 | SDValue |
| 1066 | ARMTargetLowering::LowerCallResult(SDValue Chain, SDValue InFlag, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1067 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1068 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 1069 | DebugLoc dl, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1070 | SmallVectorImpl<SDValue> &InVals) const { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1071 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1072 | // Assign locations to each value returned by this call. |
| 1073 | SmallVector<CCValAssign, 16> RVLocs; |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1074 | CCState CCInfo(CallConv, isVarArg, getTargetMachine(), |
Owen Anderson | e922c02 | 2009-07-22 00:24:57 +0000 | [diff] [blame] | 1075 | RVLocs, *DAG.getContext()); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1076 | CCInfo.AnalyzeCallResult(Ins, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1077 | CCAssignFnForNode(CallConv, /* Return*/ true, |
| 1078 | isVarArg)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1079 | |
| 1080 | // Copy all of the result registers out of their specified physreg. |
| 1081 | for (unsigned i = 0; i != RVLocs.size(); ++i) { |
| 1082 | CCValAssign VA = RVLocs[i]; |
| 1083 | |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1084 | SDValue Val; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1085 | if (VA.needsCustom()) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1086 | // Handle f64 or half of a v2f64. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1087 | SDValue Lo = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1088 | InFlag); |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1089 | Chain = Lo.getValue(1); |
| 1090 | InFlag = Lo.getValue(2); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1091 | VA = RVLocs[++i]; // skip ahead to next loc |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1092 | SDValue Hi = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1093 | InFlag); |
| 1094 | Chain = Hi.getValue(1); |
| 1095 | InFlag = Hi.getValue(2); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1096 | Val = DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1097 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1098 | if (VA.getLocVT() == MVT::v2f64) { |
| 1099 | SDValue Vec = DAG.getNode(ISD::UNDEF, dl, MVT::v2f64); |
| 1100 | Vec = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Vec, Val, |
| 1101 | DAG.getConstant(0, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1102 | |
| 1103 | VA = RVLocs[++i]; // skip ahead to next loc |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1104 | Lo = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, InFlag); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1105 | Chain = Lo.getValue(1); |
| 1106 | InFlag = Lo.getValue(2); |
| 1107 | VA = RVLocs[++i]; // skip ahead to next loc |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1108 | Hi = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, InFlag); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1109 | Chain = Hi.getValue(1); |
| 1110 | InFlag = Hi.getValue(2); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1111 | Val = DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1112 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Vec, Val, |
| 1113 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1114 | } |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1115 | } else { |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1116 | Val = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), VA.getLocVT(), |
| 1117 | InFlag); |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1118 | Chain = Val.getValue(1); |
| 1119 | InFlag = Val.getValue(2); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1120 | } |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1121 | |
| 1122 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1123 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1124 | case CCValAssign::Full: break; |
| 1125 | case CCValAssign::BCvt: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1126 | Val = DAG.getNode(ISD::BITCAST, dl, VA.getValVT(), Val); |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1127 | break; |
| 1128 | } |
| 1129 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1130 | InVals.push_back(Val); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1131 | } |
| 1132 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1133 | return Chain; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1134 | } |
| 1135 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1136 | /// LowerMemOpCallTo - Store the argument to the stack. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1137 | SDValue |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1138 | ARMTargetLowering::LowerMemOpCallTo(SDValue Chain, |
| 1139 | SDValue StackPtr, SDValue Arg, |
| 1140 | DebugLoc dl, SelectionDAG &DAG, |
| 1141 | const CCValAssign &VA, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1142 | ISD::ArgFlagsTy Flags) const { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1143 | unsigned LocMemOffset = VA.getLocMemOffset(); |
| 1144 | SDValue PtrOff = DAG.getIntPtrConstant(LocMemOffset); |
| 1145 | PtrOff = DAG.getNode(ISD::ADD, dl, getPointerTy(), StackPtr, PtrOff); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1146 | return DAG.getStore(Chain, dl, Arg, PtrOff, |
Chris Lattner | fc448ff | 2010-09-21 18:51:21 +0000 | [diff] [blame] | 1147 | MachinePointerInfo::getStack(LocMemOffset), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1148 | false, false, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1149 | } |
| 1150 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1151 | void ARMTargetLowering::PassF64ArgInRegs(DebugLoc dl, SelectionDAG &DAG, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1152 | SDValue Chain, SDValue &Arg, |
| 1153 | RegsToPassVector &RegsToPass, |
| 1154 | CCValAssign &VA, CCValAssign &NextVA, |
| 1155 | SDValue &StackPtr, |
| 1156 | SmallVector<SDValue, 8> &MemOpChains, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1157 | ISD::ArgFlagsTy Flags) const { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1158 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1159 | SDValue fmrrd = DAG.getNode(ARMISD::VMOVRRD, dl, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1160 | DAG.getVTList(MVT::i32, MVT::i32), Arg); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1161 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), fmrrd)); |
| 1162 | |
| 1163 | if (NextVA.isRegLoc()) |
| 1164 | RegsToPass.push_back(std::make_pair(NextVA.getLocReg(), fmrrd.getValue(1))); |
| 1165 | else { |
| 1166 | assert(NextVA.isMemLoc()); |
| 1167 | if (StackPtr.getNode() == 0) |
| 1168 | StackPtr = DAG.getCopyFromReg(Chain, dl, ARM::SP, getPointerTy()); |
| 1169 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1170 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, fmrrd.getValue(1), |
| 1171 | dl, DAG, NextVA, |
| 1172 | Flags)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1173 | } |
| 1174 | } |
| 1175 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1176 | /// LowerCall - Lowering a call into a callseq_start <- |
Evan Cheng | fc40342 | 2007-02-03 08:53:01 +0000 | [diff] [blame] | 1177 | /// ARMISD:CALL <- callseq_end chain. Also add input and output parameter |
| 1178 | /// nodes. |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1179 | SDValue |
Evan Cheng | 022d9e1 | 2010-02-02 23:55:14 +0000 | [diff] [blame] | 1180 | ARMTargetLowering::LowerCall(SDValue Chain, SDValue Callee, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1181 | CallingConv::ID CallConv, bool isVarArg, |
Evan Cheng | 0c439eb | 2010-01-27 00:07:07 +0000 | [diff] [blame] | 1182 | bool &isTailCall, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1183 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1184 | const SmallVectorImpl<SDValue> &OutVals, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1185 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 1186 | DebugLoc dl, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1187 | SmallVectorImpl<SDValue> &InVals) const { |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1188 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1189 | bool IsStructRet = (Outs.empty()) ? false : Outs[0].Flags.isSRet(); |
| 1190 | bool IsSibCall = false; |
Bob Wilson | 703af3a | 2010-08-13 22:43:33 +0000 | [diff] [blame] | 1191 | // Temporarily disable tail calls so things don't break. |
Evan Cheng | 0b65599 | 2011-05-20 17:38:48 +0000 | [diff] [blame] | 1192 | if (!EnableARMTailCalls) |
Bob Wilson | 703af3a | 2010-08-13 22:43:33 +0000 | [diff] [blame] | 1193 | isTailCall = false; |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1194 | if (isTailCall) { |
| 1195 | // Check if it's really possible to do a tail call. |
| 1196 | isTailCall = IsEligibleForTailCallOptimization(Callee, CallConv, |
| 1197 | isVarArg, IsStructRet, MF.getFunction()->hasStructRetAttr(), |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1198 | Outs, OutVals, Ins, DAG); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1199 | // We don't support GuaranteedTailCallOpt for ARM, only automatically |
| 1200 | // detected sibcalls. |
| 1201 | if (isTailCall) { |
| 1202 | ++NumTailCalls; |
| 1203 | IsSibCall = true; |
| 1204 | } |
| 1205 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1206 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1207 | // Analyze operands of the call, assigning locations to each operand. |
| 1208 | SmallVector<CCValAssign, 16> ArgLocs; |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1209 | CCState CCInfo(CallConv, isVarArg, getTargetMachine(), ArgLocs, |
| 1210 | *DAG.getContext()); |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1211 | CCInfo.setCallOrPrologue(Call); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1212 | CCInfo.AnalyzeCallOperands(Outs, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1213 | CCAssignFnForNode(CallConv, /* Return*/ false, |
| 1214 | isVarArg)); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1215 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1216 | // Get a count of how many bytes are to be pushed on the stack. |
| 1217 | unsigned NumBytes = CCInfo.getNextStackOffset(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1218 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1219 | // For tail calls, memory operands are available in our caller's stack. |
| 1220 | if (IsSibCall) |
| 1221 | NumBytes = 0; |
| 1222 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1223 | // Adjust the stack pointer for the new arguments... |
| 1224 | // These operations are automatically eliminated by the prolog/epilog pass |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1225 | if (!IsSibCall) |
| 1226 | Chain = DAG.getCALLSEQ_START(Chain, DAG.getIntPtrConstant(NumBytes, true)); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1227 | |
Jim Grosbach | f9a4b76 | 2010-02-24 01:43:03 +0000 | [diff] [blame] | 1228 | SDValue StackPtr = DAG.getCopyFromReg(Chain, dl, ARM::SP, getPointerTy()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1229 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1230 | RegsToPassVector RegsToPass; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1231 | SmallVector<SDValue, 8> MemOpChains; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1232 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1233 | // Walk the register/memloc assignments, inserting copies/loads. In the case |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1234 | // of tail call optimization, arguments are handled later. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1235 | for (unsigned i = 0, realArgIdx = 0, e = ArgLocs.size(); |
| 1236 | i != e; |
| 1237 | ++i, ++realArgIdx) { |
| 1238 | CCValAssign &VA = ArgLocs[i]; |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1239 | SDValue Arg = OutVals[realArgIdx]; |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1240 | ISD::ArgFlagsTy Flags = Outs[realArgIdx].Flags; |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1241 | bool isByVal = Flags.isByVal(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1242 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1243 | // Promote the value if needed. |
| 1244 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1245 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1246 | case CCValAssign::Full: break; |
| 1247 | case CCValAssign::SExt: |
| 1248 | Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg); |
| 1249 | break; |
| 1250 | case CCValAssign::ZExt: |
| 1251 | Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg); |
| 1252 | break; |
| 1253 | case CCValAssign::AExt: |
| 1254 | Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg); |
| 1255 | break; |
| 1256 | case CCValAssign::BCvt: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1257 | Arg = DAG.getNode(ISD::BITCAST, dl, VA.getLocVT(), Arg); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1258 | break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1259 | } |
| 1260 | |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1261 | // 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] | 1262 | if (VA.needsCustom()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1263 | if (VA.getLocVT() == MVT::v2f64) { |
| 1264 | SDValue Op0 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1265 | DAG.getConstant(0, MVT::i32)); |
| 1266 | SDValue Op1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1267 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1268 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1269 | PassF64ArgInRegs(dl, DAG, Chain, Op0, RegsToPass, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1270 | VA, ArgLocs[++i], StackPtr, MemOpChains, Flags); |
| 1271 | |
| 1272 | VA = ArgLocs[++i]; // skip ahead to next loc |
| 1273 | if (VA.isRegLoc()) { |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1274 | PassF64ArgInRegs(dl, DAG, Chain, Op1, RegsToPass, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1275 | VA, ArgLocs[++i], StackPtr, MemOpChains, Flags); |
| 1276 | } else { |
| 1277 | assert(VA.isMemLoc()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1278 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1279 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, Op1, |
| 1280 | dl, DAG, VA, Flags)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1281 | } |
| 1282 | } else { |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1283 | PassF64ArgInRegs(dl, DAG, Chain, Arg, RegsToPass, VA, ArgLocs[++i], |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1284 | StackPtr, MemOpChains, Flags); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1285 | } |
| 1286 | } else if (VA.isRegLoc()) { |
| 1287 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg)); |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1288 | } else if (isByVal) { |
| 1289 | assert(VA.isMemLoc()); |
| 1290 | unsigned offset = 0; |
| 1291 | |
| 1292 | // True if this byval aggregate will be split between registers |
| 1293 | // and memory. |
| 1294 | if (CCInfo.isFirstByValRegValid()) { |
| 1295 | EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
| 1296 | unsigned int i, j; |
| 1297 | for (i = 0, j = CCInfo.getFirstByValReg(); j < ARM::R4; i++, j++) { |
| 1298 | SDValue Const = DAG.getConstant(4*i, MVT::i32); |
| 1299 | SDValue AddArg = DAG.getNode(ISD::ADD, dl, PtrVT, Arg, Const); |
| 1300 | SDValue Load = DAG.getLoad(PtrVT, dl, Chain, AddArg, |
| 1301 | MachinePointerInfo(), |
| 1302 | false, false, 0); |
| 1303 | MemOpChains.push_back(Load.getValue(1)); |
| 1304 | RegsToPass.push_back(std::make_pair(j, Load)); |
| 1305 | } |
| 1306 | offset = ARM::R4 - CCInfo.getFirstByValReg(); |
| 1307 | CCInfo.clearFirstByValReg(); |
| 1308 | } |
| 1309 | |
| 1310 | unsigned LocMemOffset = VA.getLocMemOffset(); |
| 1311 | SDValue StkPtrOff = DAG.getIntPtrConstant(LocMemOffset); |
| 1312 | SDValue Dst = DAG.getNode(ISD::ADD, dl, getPointerTy(), StackPtr, |
| 1313 | StkPtrOff); |
| 1314 | SDValue SrcOffset = DAG.getIntPtrConstant(4*offset); |
| 1315 | SDValue Src = DAG.getNode(ISD::ADD, dl, getPointerTy(), Arg, SrcOffset); |
| 1316 | SDValue SizeNode = DAG.getConstant(Flags.getByValSize() - 4*offset, |
| 1317 | MVT::i32); |
| 1318 | MemOpChains.push_back(DAG.getMemcpy(Chain, dl, Dst, Src, SizeNode, |
| 1319 | Flags.getByValAlign(), |
| 1320 | /*isVolatile=*/false, |
| 1321 | /*AlwaysInline=*/false, |
| 1322 | MachinePointerInfo(0), |
| 1323 | MachinePointerInfo(0))); |
| 1324 | |
| 1325 | } else if (!IsSibCall) { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1326 | assert(VA.isMemLoc()); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1327 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1328 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, Arg, |
| 1329 | dl, DAG, VA, Flags)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1330 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1331 | } |
| 1332 | |
| 1333 | if (!MemOpChains.empty()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1334 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1335 | &MemOpChains[0], MemOpChains.size()); |
| 1336 | |
| 1337 | // Build a sequence of copy-to-reg nodes chained together with token chain |
| 1338 | // and flag operands which copy the outgoing args into the appropriate regs. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1339 | SDValue InFlag; |
Dale Johannesen | 6470a11 | 2010-06-15 22:08:33 +0000 | [diff] [blame] | 1340 | // Tail call byval lowering might overwrite argument registers so in case of |
| 1341 | // tail call optimization the copies to registers are lowered later. |
| 1342 | if (!isTailCall) |
| 1343 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 1344 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, |
| 1345 | RegsToPass[i].second, InFlag); |
| 1346 | InFlag = Chain.getValue(1); |
| 1347 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1348 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1349 | // For tail calls lower the arguments to the 'real' stack slot. |
| 1350 | if (isTailCall) { |
| 1351 | // Force all the incoming stack arguments to be loaded from the stack |
| 1352 | // before any new outgoing arguments are stored to the stack, because the |
| 1353 | // outgoing stack slots may alias the incoming argument stack slots, and |
| 1354 | // the alias isn't otherwise explicit. This is slightly more conservative |
| 1355 | // than necessary, because it means that each store effectively depends |
| 1356 | // on every argument instead of just those arguments it would clobber. |
| 1357 | |
Chris Lattner | 7a2bdde | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 1358 | // Do not flag preceding copytoreg stuff together with the following stuff. |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1359 | InFlag = SDValue(); |
| 1360 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 1361 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, |
| 1362 | RegsToPass[i].second, InFlag); |
| 1363 | InFlag = Chain.getValue(1); |
| 1364 | } |
| 1365 | InFlag =SDValue(); |
| 1366 | } |
| 1367 | |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1368 | // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every |
| 1369 | // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol |
| 1370 | // node so that legalize doesn't hack it. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1371 | bool isDirect = false; |
| 1372 | bool isARMFunc = false; |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 1373 | bool isLocalARMFunc = false; |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1374 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1375 | |
| 1376 | if (EnableARMLongCalls) { |
| 1377 | assert (getTargetMachine().getRelocationModel() == Reloc::Static |
| 1378 | && "long-calls with non-static relocation model!"); |
| 1379 | // Handle a global address or an external symbol. If it's not one of |
| 1380 | // those, the target's already in a register, so we don't need to do |
| 1381 | // anything extra. |
| 1382 | if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
Anders Carlsson | 0dbdca5 | 2010-04-15 03:11:28 +0000 | [diff] [blame] | 1383 | const GlobalValue *GV = G->getGlobal(); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1384 | // Create a constant pool entry for the callee address |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1385 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1386 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GV, |
| 1387 | ARMPCLabelIndex, |
| 1388 | ARMCP::CPValue, 0); |
| 1389 | // Get the address of the callee into a register |
| 1390 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
| 1391 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| 1392 | Callee = DAG.getLoad(getPointerTy(), dl, |
| 1393 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1394 | MachinePointerInfo::getConstantPool(), |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1395 | false, false, 0); |
| 1396 | } else if (ExternalSymbolSDNode *S=dyn_cast<ExternalSymbolSDNode>(Callee)) { |
| 1397 | const char *Sym = S->getSymbol(); |
| 1398 | |
| 1399 | // Create a constant pool entry for the callee address |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1400 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1401 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(*DAG.getContext(), |
| 1402 | Sym, ARMPCLabelIndex, 0); |
| 1403 | // Get the address of the callee into a register |
| 1404 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
| 1405 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| 1406 | Callee = DAG.getLoad(getPointerTy(), dl, |
| 1407 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1408 | MachinePointerInfo::getConstantPool(), |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1409 | false, false, 0); |
| 1410 | } |
| 1411 | } else if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 1412 | const GlobalValue *GV = G->getGlobal(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1413 | isDirect = true; |
Chris Lattner | 4fb63d0 | 2009-07-15 04:12:33 +0000 | [diff] [blame] | 1414 | bool isExt = GV->isDeclaration() || GV->isWeakForLinker(); |
Evan Cheng | 970a419 | 2007-01-19 19:28:01 +0000 | [diff] [blame] | 1415 | bool isStub = (isExt && Subtarget->isTargetDarwin()) && |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1416 | getTargetMachine().getRelocationModel() != Reloc::Static; |
| 1417 | isARMFunc = !Subtarget->isThumb() || isStub; |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 1418 | // ARM call to a local ARM function is predicable. |
Evan Cheng | 46df4eb | 2010-06-16 07:35:02 +0000 | [diff] [blame] | 1419 | isLocalARMFunc = !Subtarget->isThumb() && (!isExt || !ARMInterworking); |
Evan Cheng | c60e76d | 2007-01-30 20:37:08 +0000 | [diff] [blame] | 1420 | // tBX takes a register source operand. |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 1421 | if (isARMFunc && Subtarget->isThumb1Only() && !Subtarget->hasV5TOps()) { |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1422 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 1423 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GV, |
Jim Grosbach | 3fb2b1e | 2009-09-01 01:57:56 +0000 | [diff] [blame] | 1424 | ARMPCLabelIndex, |
| 1425 | ARMCP::CPValue, 4); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1426 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1427 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1428 | Callee = DAG.getLoad(getPointerTy(), dl, |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1429 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1430 | MachinePointerInfo::getConstantPool(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1431 | false, false, 0); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1432 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1433 | Callee = DAG.getNode(ARMISD::PIC_ADD, dl, |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1434 | getPointerTy(), Callee, PICLabel); |
Jim Grosbach | 637d89f | 2010-09-22 23:27:36 +0000 | [diff] [blame] | 1435 | } else { |
| 1436 | // On ELF targets for PIC code, direct calls should go through the PLT |
| 1437 | unsigned OpFlags = 0; |
| 1438 | if (Subtarget->isTargetELF() && |
| 1439 | getTargetMachine().getRelocationModel() == Reloc::PIC_) |
| 1440 | OpFlags = ARMII::MO_PLT; |
| 1441 | Callee = DAG.getTargetGlobalAddress(GV, dl, getPointerTy(), 0, OpFlags); |
| 1442 | } |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1443 | } else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1444 | isDirect = true; |
Evan Cheng | 970a419 | 2007-01-19 19:28:01 +0000 | [diff] [blame] | 1445 | bool isStub = Subtarget->isTargetDarwin() && |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1446 | getTargetMachine().getRelocationModel() != Reloc::Static; |
| 1447 | isARMFunc = !Subtarget->isThumb() || isStub; |
Evan Cheng | c60e76d | 2007-01-30 20:37:08 +0000 | [diff] [blame] | 1448 | // tBX takes a register source operand. |
| 1449 | const char *Sym = S->getSymbol(); |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 1450 | if (isARMFunc && Subtarget->isThumb1Only() && !Subtarget->hasV5TOps()) { |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1451 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 1452 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(*DAG.getContext(), |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 1453 | Sym, ARMPCLabelIndex, 4); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1454 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1455 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1456 | Callee = DAG.getLoad(getPointerTy(), dl, |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1457 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1458 | MachinePointerInfo::getConstantPool(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1459 | false, false, 0); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1460 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1461 | Callee = DAG.getNode(ARMISD::PIC_ADD, dl, |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1462 | getPointerTy(), Callee, PICLabel); |
Jim Grosbach | 637d89f | 2010-09-22 23:27:36 +0000 | [diff] [blame] | 1463 | } else { |
| 1464 | unsigned OpFlags = 0; |
| 1465 | // On ELF targets for PIC code, direct calls should go through the PLT |
| 1466 | if (Subtarget->isTargetELF() && |
| 1467 | getTargetMachine().getRelocationModel() == Reloc::PIC_) |
| 1468 | OpFlags = ARMII::MO_PLT; |
| 1469 | Callee = DAG.getTargetExternalSymbol(Sym, getPointerTy(), OpFlags); |
| 1470 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1471 | } |
| 1472 | |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1473 | // FIXME: handle tail calls differently. |
| 1474 | unsigned CallOpc; |
Evan Cheng | b620724 | 2009-08-01 00:16:10 +0000 | [diff] [blame] | 1475 | if (Subtarget->isThumb()) { |
| 1476 | if ((!isDirect || isARMFunc) && !Subtarget->hasV5TOps()) |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1477 | CallOpc = ARMISD::CALL_NOLINK; |
| 1478 | else |
| 1479 | CallOpc = isARMFunc ? ARMISD::CALL : ARMISD::tCALL; |
| 1480 | } else { |
| 1481 | CallOpc = (isDirect || Subtarget->hasV5TOps()) |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 1482 | ? (isLocalARMFunc ? ARMISD::CALL_PRED : ARMISD::CALL) |
| 1483 | : ARMISD::CALL_NOLINK; |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1484 | } |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1485 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1486 | std::vector<SDValue> Ops; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1487 | Ops.push_back(Chain); |
| 1488 | Ops.push_back(Callee); |
| 1489 | |
| 1490 | // Add argument registers to the end of the list so that they are known live |
| 1491 | // into the call. |
| 1492 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) |
| 1493 | Ops.push_back(DAG.getRegister(RegsToPass[i].first, |
| 1494 | RegsToPass[i].second.getValueType())); |
| 1495 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1496 | if (InFlag.getNode()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1497 | Ops.push_back(InFlag); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1498 | |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 1499 | SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue); |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1500 | if (isTailCall) |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1501 | return DAG.getNode(ARMISD::TC_RETURN, dl, NodeTys, &Ops[0], Ops.size()); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1502 | |
Duncan Sands | 4bdcb61 | 2008-07-02 17:40:58 +0000 | [diff] [blame] | 1503 | // Returns a chain and a flag for retval copy to use. |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1504 | Chain = DAG.getNode(CallOpc, dl, NodeTys, &Ops[0], Ops.size()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1505 | InFlag = Chain.getValue(1); |
| 1506 | |
Chris Lattner | e563bbc | 2008-10-11 22:08:30 +0000 | [diff] [blame] | 1507 | Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(NumBytes, true), |
| 1508 | DAG.getIntPtrConstant(0, true), InFlag); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1509 | if (!Ins.empty()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1510 | InFlag = Chain.getValue(1); |
| 1511 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1512 | // Handle result values, copying them out of physregs into vregs that we |
| 1513 | // return. |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1514 | return LowerCallResult(Chain, InFlag, CallConv, isVarArg, Ins, |
| 1515 | dl, DAG, InVals); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1516 | } |
| 1517 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1518 | /// HandleByVal - Every parameter *after* a byval parameter is passed |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1519 | /// on the stack. Remember the next parameter register to allocate, |
| 1520 | /// and then confiscate the rest of the parameter registers to insure |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1521 | /// this. |
| 1522 | void |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1523 | llvm::ARMTargetLowering::HandleByVal(CCState *State, unsigned &size) const { |
| 1524 | unsigned reg = State->AllocateReg(GPRArgRegs, 4); |
| 1525 | assert((State->getCallOrPrologue() == Prologue || |
| 1526 | State->getCallOrPrologue() == Call) && |
| 1527 | "unhandled ParmContext"); |
| 1528 | if ((!State->isFirstByValRegValid()) && |
| 1529 | (ARM::R0 <= reg) && (reg <= ARM::R3)) { |
| 1530 | State->setFirstByValReg(reg); |
| 1531 | // At a call site, a byval parameter that is split between |
| 1532 | // registers and memory needs its size truncated here. In a |
| 1533 | // function prologue, such byval parameters are reassembled in |
| 1534 | // memory, and are not truncated. |
| 1535 | if (State->getCallOrPrologue() == Call) { |
| 1536 | unsigned excess = 4 * (ARM::R4 - reg); |
| 1537 | assert(size >= excess && "expected larger existing stack allocation"); |
| 1538 | size -= excess; |
| 1539 | } |
| 1540 | } |
| 1541 | // Confiscate any remaining parameter registers to preclude their |
| 1542 | // assignment to subsequent parameters. |
| 1543 | while (State->AllocateReg(GPRArgRegs, 4)) |
| 1544 | ; |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1545 | } |
| 1546 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1547 | /// MatchingStackOffset - Return true if the given stack call argument is |
| 1548 | /// already available in the same position (relatively) of the caller's |
| 1549 | /// incoming argument stack. |
| 1550 | static |
| 1551 | bool MatchingStackOffset(SDValue Arg, unsigned Offset, ISD::ArgFlagsTy Flags, |
| 1552 | MachineFrameInfo *MFI, const MachineRegisterInfo *MRI, |
| 1553 | const ARMInstrInfo *TII) { |
| 1554 | unsigned Bytes = Arg.getValueType().getSizeInBits() / 8; |
| 1555 | int FI = INT_MAX; |
| 1556 | if (Arg.getOpcode() == ISD::CopyFromReg) { |
| 1557 | unsigned VR = cast<RegisterSDNode>(Arg.getOperand(1))->getReg(); |
Jakob Stoklund Olesen | c9df025 | 2011-01-10 02:58:51 +0000 | [diff] [blame] | 1558 | if (!TargetRegisterInfo::isVirtualRegister(VR)) |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1559 | return false; |
| 1560 | MachineInstr *Def = MRI->getVRegDef(VR); |
| 1561 | if (!Def) |
| 1562 | return false; |
| 1563 | if (!Flags.isByVal()) { |
| 1564 | if (!TII->isLoadFromStackSlot(Def, FI)) |
| 1565 | return false; |
| 1566 | } else { |
Dale Johannesen | 7835f1f | 2010-07-08 01:18:23 +0000 | [diff] [blame] | 1567 | return false; |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1568 | } |
| 1569 | } else if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Arg)) { |
| 1570 | if (Flags.isByVal()) |
| 1571 | // ByVal argument is passed in as a pointer but it's now being |
| 1572 | // dereferenced. e.g. |
| 1573 | // define @foo(%struct.X* %A) { |
| 1574 | // tail call @bar(%struct.X* byval %A) |
| 1575 | // } |
| 1576 | return false; |
| 1577 | SDValue Ptr = Ld->getBasePtr(); |
| 1578 | FrameIndexSDNode *FINode = dyn_cast<FrameIndexSDNode>(Ptr); |
| 1579 | if (!FINode) |
| 1580 | return false; |
| 1581 | FI = FINode->getIndex(); |
| 1582 | } else |
| 1583 | return false; |
| 1584 | |
| 1585 | assert(FI != INT_MAX); |
| 1586 | if (!MFI->isFixedObjectIndex(FI)) |
| 1587 | return false; |
| 1588 | return Offset == MFI->getObjectOffset(FI) && Bytes == MFI->getObjectSize(FI); |
| 1589 | } |
| 1590 | |
| 1591 | /// IsEligibleForTailCallOptimization - Check whether the call is eligible |
| 1592 | /// for tail call optimization. Targets which want to do tail call |
| 1593 | /// optimization should implement this function. |
| 1594 | bool |
| 1595 | ARMTargetLowering::IsEligibleForTailCallOptimization(SDValue Callee, |
| 1596 | CallingConv::ID CalleeCC, |
| 1597 | bool isVarArg, |
| 1598 | bool isCalleeStructRet, |
| 1599 | bool isCallerStructRet, |
| 1600 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1601 | const SmallVectorImpl<SDValue> &OutVals, |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1602 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 1603 | SelectionDAG& DAG) const { |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1604 | const Function *CallerF = DAG.getMachineFunction().getFunction(); |
| 1605 | CallingConv::ID CallerCC = CallerF->getCallingConv(); |
| 1606 | bool CCMatch = CallerCC == CalleeCC; |
| 1607 | |
| 1608 | // Look for obvious safe cases to perform tail call optimization that do not |
| 1609 | // require ABI changes. This is what gcc calls sibcall. |
| 1610 | |
Jim Grosbach | 7616b64 | 2010-06-16 23:45:49 +0000 | [diff] [blame] | 1611 | // Do not sibcall optimize vararg calls unless the call site is not passing |
| 1612 | // any arguments. |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1613 | if (isVarArg && !Outs.empty()) |
| 1614 | return false; |
| 1615 | |
| 1616 | // Also avoid sibcall optimization if either caller or callee uses struct |
| 1617 | // return semantics. |
| 1618 | if (isCalleeStructRet || isCallerStructRet) |
| 1619 | return false; |
| 1620 | |
Dale Johannesen | e39fdbe | 2010-06-23 18:52:34 +0000 | [diff] [blame] | 1621 | // FIXME: Completely disable sibcall for Thumb1 since Thumb1RegisterInfo:: |
Evan Cheng | 0110ac6 | 2010-06-19 01:01:32 +0000 | [diff] [blame] | 1622 | // emitEpilogue is not ready for them. |
Dale Johannesen | 7835f1f | 2010-07-08 01:18:23 +0000 | [diff] [blame] | 1623 | // Doing this is tricky, since the LDM/POP instruction on Thumb doesn't take |
| 1624 | // LR. This means if we need to reload LR, it takes an extra instructions, |
| 1625 | // which outweighs the value of the tail call; but here we don't know yet |
| 1626 | // 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] | 1627 | // 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] | 1628 | // emitEpilogue if LR is used. |
Dale Johannesen | 7835f1f | 2010-07-08 01:18:23 +0000 | [diff] [blame] | 1629 | |
| 1630 | // Thumb1 PIC calls to external symbols use BX, so they can be tail calls, |
| 1631 | // but we need to make sure there are enough registers; the only valid |
| 1632 | // registers are the 4 used for parameters. We don't currently do this |
| 1633 | // case. |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1634 | if (Subtarget->isThumb1Only()) |
| 1635 | return false; |
Dale Johannesen | df50d7e | 2010-06-18 18:13:11 +0000 | [diff] [blame] | 1636 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1637 | // If the calling conventions do not match, then we'd better make sure the |
| 1638 | // results are returned in the same way as what the caller expects. |
| 1639 | if (!CCMatch) { |
| 1640 | SmallVector<CCValAssign, 16> RVLocs1; |
| 1641 | CCState CCInfo1(CalleeCC, false, getTargetMachine(), |
| 1642 | RVLocs1, *DAG.getContext()); |
| 1643 | CCInfo1.AnalyzeCallResult(Ins, CCAssignFnForNode(CalleeCC, true, isVarArg)); |
| 1644 | |
| 1645 | SmallVector<CCValAssign, 16> RVLocs2; |
| 1646 | CCState CCInfo2(CallerCC, false, getTargetMachine(), |
| 1647 | RVLocs2, *DAG.getContext()); |
| 1648 | CCInfo2.AnalyzeCallResult(Ins, CCAssignFnForNode(CallerCC, true, isVarArg)); |
| 1649 | |
| 1650 | if (RVLocs1.size() != RVLocs2.size()) |
| 1651 | return false; |
| 1652 | for (unsigned i = 0, e = RVLocs1.size(); i != e; ++i) { |
| 1653 | if (RVLocs1[i].isRegLoc() != RVLocs2[i].isRegLoc()) |
| 1654 | return false; |
| 1655 | if (RVLocs1[i].getLocInfo() != RVLocs2[i].getLocInfo()) |
| 1656 | return false; |
| 1657 | if (RVLocs1[i].isRegLoc()) { |
| 1658 | if (RVLocs1[i].getLocReg() != RVLocs2[i].getLocReg()) |
| 1659 | return false; |
| 1660 | } else { |
| 1661 | if (RVLocs1[i].getLocMemOffset() != RVLocs2[i].getLocMemOffset()) |
| 1662 | return false; |
| 1663 | } |
| 1664 | } |
| 1665 | } |
| 1666 | |
| 1667 | // If the callee takes no arguments then go on to check the results of the |
| 1668 | // call. |
| 1669 | if (!Outs.empty()) { |
| 1670 | // Check if stack adjustment is needed. For now, do not do this if any |
| 1671 | // argument is passed on the stack. |
| 1672 | SmallVector<CCValAssign, 16> ArgLocs; |
| 1673 | CCState CCInfo(CalleeCC, isVarArg, getTargetMachine(), |
| 1674 | ArgLocs, *DAG.getContext()); |
| 1675 | CCInfo.AnalyzeCallOperands(Outs, |
| 1676 | CCAssignFnForNode(CalleeCC, false, isVarArg)); |
| 1677 | if (CCInfo.getNextStackOffset()) { |
| 1678 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1679 | |
| 1680 | // Check if the arguments are already laid out in the right way as |
| 1681 | // the caller's fixed stack objects. |
| 1682 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 1683 | const MachineRegisterInfo *MRI = &MF.getRegInfo(); |
| 1684 | const ARMInstrInfo *TII = |
| 1685 | ((ARMTargetMachine&)getTargetMachine()).getInstrInfo(); |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1686 | for (unsigned i = 0, realArgIdx = 0, e = ArgLocs.size(); |
| 1687 | i != e; |
| 1688 | ++i, ++realArgIdx) { |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1689 | CCValAssign &VA = ArgLocs[i]; |
| 1690 | EVT RegVT = VA.getLocVT(); |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1691 | SDValue Arg = OutVals[realArgIdx]; |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1692 | ISD::ArgFlagsTy Flags = Outs[realArgIdx].Flags; |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1693 | if (VA.getLocInfo() == CCValAssign::Indirect) |
| 1694 | return false; |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1695 | if (VA.needsCustom()) { |
| 1696 | // f64 and vector types are split into multiple registers or |
| 1697 | // register/stack-slot combinations. The types will not match |
| 1698 | // the registers; give up on memory f64 refs until we figure |
| 1699 | // out what to do about this. |
| 1700 | if (!VA.isRegLoc()) |
| 1701 | return false; |
| 1702 | if (!ArgLocs[++i].isRegLoc()) |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 1703 | return false; |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1704 | if (RegVT == MVT::v2f64) { |
| 1705 | if (!ArgLocs[++i].isRegLoc()) |
| 1706 | return false; |
| 1707 | if (!ArgLocs[++i].isRegLoc()) |
| 1708 | return false; |
| 1709 | } |
| 1710 | } else if (!VA.isRegLoc()) { |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1711 | if (!MatchingStackOffset(Arg, VA.getLocMemOffset(), Flags, |
| 1712 | MFI, MRI, TII)) |
| 1713 | return false; |
| 1714 | } |
| 1715 | } |
| 1716 | } |
| 1717 | } |
| 1718 | |
| 1719 | return true; |
| 1720 | } |
| 1721 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1722 | SDValue |
| 1723 | ARMTargetLowering::LowerReturn(SDValue Chain, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1724 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1725 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1726 | const SmallVectorImpl<SDValue> &OutVals, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1727 | DebugLoc dl, SelectionDAG &DAG) const { |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1728 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1729 | // CCValAssign - represent the assignment of the return value to a location. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1730 | SmallVector<CCValAssign, 16> RVLocs; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1731 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1732 | // CCState - Info about the registers and stack slots. |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1733 | CCState CCInfo(CallConv, isVarArg, getTargetMachine(), RVLocs, |
| 1734 | *DAG.getContext()); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1735 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1736 | // Analyze outgoing return values. |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1737 | CCInfo.AnalyzeReturn(Outs, CCAssignFnForNode(CallConv, /* Return */ true, |
| 1738 | isVarArg)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1739 | |
| 1740 | // If this is the first return lowered for this function, add |
| 1741 | // the regs to the liveout set for the function. |
| 1742 | if (DAG.getMachineFunction().getRegInfo().liveout_empty()) { |
| 1743 | for (unsigned i = 0; i != RVLocs.size(); ++i) |
| 1744 | if (RVLocs[i].isRegLoc()) |
| 1745 | DAG.getMachineFunction().getRegInfo().addLiveOut(RVLocs[i].getLocReg()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1746 | } |
| 1747 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1748 | SDValue Flag; |
| 1749 | |
| 1750 | // Copy the result values into the output registers. |
| 1751 | for (unsigned i = 0, realRVLocIdx = 0; |
| 1752 | i != RVLocs.size(); |
| 1753 | ++i, ++realRVLocIdx) { |
| 1754 | CCValAssign &VA = RVLocs[i]; |
| 1755 | assert(VA.isRegLoc() && "Can only return in registers!"); |
| 1756 | |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1757 | SDValue Arg = OutVals[realRVLocIdx]; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1758 | |
| 1759 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1760 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1761 | case CCValAssign::Full: break; |
| 1762 | case CCValAssign::BCvt: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1763 | Arg = DAG.getNode(ISD::BITCAST, dl, VA.getLocVT(), Arg); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1764 | break; |
| 1765 | } |
| 1766 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1767 | if (VA.needsCustom()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1768 | if (VA.getLocVT() == MVT::v2f64) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1769 | // Extract the first half and return it in two registers. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1770 | SDValue Half = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1771 | DAG.getConstant(0, MVT::i32)); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1772 | SDValue HalfGPRs = DAG.getNode(ARMISD::VMOVRRD, dl, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1773 | DAG.getVTList(MVT::i32, MVT::i32), Half); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1774 | |
| 1775 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), HalfGPRs, Flag); |
| 1776 | Flag = Chain.getValue(1); |
| 1777 | VA = RVLocs[++i]; // skip ahead to next loc |
| 1778 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), |
| 1779 | HalfGPRs.getValue(1), Flag); |
| 1780 | Flag = Chain.getValue(1); |
| 1781 | VA = RVLocs[++i]; // skip ahead to next loc |
| 1782 | |
| 1783 | // 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] | 1784 | Arg = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1785 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1786 | } |
| 1787 | // Legalize ret f64 -> ret 2 x i32. We always have fmrrd if f64 is |
| 1788 | // available. |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1789 | SDValue fmrrd = DAG.getNode(ARMISD::VMOVRRD, dl, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1790 | DAG.getVTList(MVT::i32, MVT::i32), &Arg, 1); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1791 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), fmrrd, Flag); |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1792 | Flag = Chain.getValue(1); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1793 | VA = RVLocs[++i]; // skip ahead to next loc |
| 1794 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), fmrrd.getValue(1), |
| 1795 | Flag); |
| 1796 | } else |
| 1797 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), Arg, Flag); |
| 1798 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1799 | // Guarantee that all emitted copies are |
| 1800 | // stuck together, avoiding something bad. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1801 | Flag = Chain.getValue(1); |
| 1802 | } |
| 1803 | |
| 1804 | SDValue result; |
| 1805 | if (Flag.getNode()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1806 | result = DAG.getNode(ARMISD::RET_FLAG, dl, MVT::Other, Chain, Flag); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1807 | else // Return Void |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1808 | result = DAG.getNode(ARMISD::RET_FLAG, dl, MVT::Other, Chain); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1809 | |
| 1810 | return result; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1811 | } |
| 1812 | |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1813 | bool ARMTargetLowering::isUsedByReturnOnly(SDNode *N) const { |
| 1814 | if (N->getNumValues() != 1) |
| 1815 | return false; |
| 1816 | if (!N->hasNUsesOfValue(1, 0)) |
| 1817 | return false; |
| 1818 | |
| 1819 | unsigned NumCopies = 0; |
| 1820 | SDNode* Copies[2]; |
| 1821 | SDNode *Use = *N->use_begin(); |
| 1822 | if (Use->getOpcode() == ISD::CopyToReg) { |
| 1823 | Copies[NumCopies++] = Use; |
| 1824 | } else if (Use->getOpcode() == ARMISD::VMOVRRD) { |
| 1825 | // f64 returned in a pair of GPRs. |
| 1826 | for (SDNode::use_iterator UI = Use->use_begin(), UE = Use->use_end(); |
| 1827 | UI != UE; ++UI) { |
| 1828 | if (UI->getOpcode() != ISD::CopyToReg) |
| 1829 | return false; |
| 1830 | Copies[UI.getUse().getResNo()] = *UI; |
| 1831 | ++NumCopies; |
| 1832 | } |
| 1833 | } else if (Use->getOpcode() == ISD::BITCAST) { |
| 1834 | // f32 returned in a single GPR. |
| 1835 | if (!Use->hasNUsesOfValue(1, 0)) |
| 1836 | return false; |
| 1837 | Use = *Use->use_begin(); |
| 1838 | if (Use->getOpcode() != ISD::CopyToReg || !Use->hasNUsesOfValue(1, 0)) |
| 1839 | return false; |
| 1840 | Copies[NumCopies++] = Use; |
| 1841 | } else { |
| 1842 | return false; |
| 1843 | } |
| 1844 | |
| 1845 | if (NumCopies != 1 && NumCopies != 2) |
| 1846 | return false; |
Evan Cheng | 1bf891a | 2010-12-01 22:59:46 +0000 | [diff] [blame] | 1847 | |
| 1848 | bool HasRet = false; |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1849 | for (unsigned i = 0; i < NumCopies; ++i) { |
| 1850 | SDNode *Copy = Copies[i]; |
| 1851 | for (SDNode::use_iterator UI = Copy->use_begin(), UE = Copy->use_end(); |
| 1852 | UI != UE; ++UI) { |
| 1853 | if (UI->getOpcode() == ISD::CopyToReg) { |
| 1854 | SDNode *Use = *UI; |
| 1855 | if (Use == Copies[0] || Use == Copies[1]) |
| 1856 | continue; |
| 1857 | return false; |
| 1858 | } |
| 1859 | if (UI->getOpcode() != ARMISD::RET_FLAG) |
| 1860 | return false; |
Evan Cheng | 1bf891a | 2010-12-01 22:59:46 +0000 | [diff] [blame] | 1861 | HasRet = true; |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1862 | } |
| 1863 | } |
| 1864 | |
Evan Cheng | 1bf891a | 2010-12-01 22:59:46 +0000 | [diff] [blame] | 1865 | return HasRet; |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1866 | } |
| 1867 | |
Evan Cheng | 485fafc | 2011-03-21 01:19:09 +0000 | [diff] [blame] | 1868 | bool ARMTargetLowering::mayBeEmittedAsTailCall(CallInst *CI) const { |
| 1869 | if (!EnableARMTailCalls) |
| 1870 | return false; |
| 1871 | |
| 1872 | if (!CI->isTailCall()) |
| 1873 | return false; |
| 1874 | |
| 1875 | return !Subtarget->isThumb1Only(); |
| 1876 | } |
| 1877 | |
Bob Wilson | b62d257 | 2009-11-03 00:02:05 +0000 | [diff] [blame] | 1878 | // ConstantPool, JumpTable, GlobalAddress, and ExternalSymbol are lowered as |
| 1879 | // their target counterpart wrapped in the ARMISD::Wrapper node. Suppose N is |
| 1880 | // one of the above mentioned nodes. It has to be wrapped because otherwise |
| 1881 | // Select(N) returns N. So the raw TargetGlobalAddress nodes, etc. can only |
| 1882 | // be used to form addressing mode. These wrapped nodes will be selected |
| 1883 | // into MOVi. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1884 | static SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1885 | EVT PtrVT = Op.getValueType(); |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 1886 | // FIXME there is no actual debug info here |
| 1887 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1888 | ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1889 | SDValue Res; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1890 | if (CP->isMachineConstantPoolEntry()) |
| 1891 | Res = DAG.getTargetConstantPool(CP->getMachineCPVal(), PtrVT, |
| 1892 | CP->getAlignment()); |
| 1893 | else |
| 1894 | Res = DAG.getTargetConstantPool(CP->getConstVal(), PtrVT, |
| 1895 | CP->getAlignment()); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1896 | return DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Res); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1897 | } |
| 1898 | |
Jim Grosbach | e1102ca | 2010-07-19 17:20:38 +0000 | [diff] [blame] | 1899 | unsigned ARMTargetLowering::getJumpTableEncoding() const { |
| 1900 | return MachineJumpTableInfo::EK_Inline; |
| 1901 | } |
| 1902 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1903 | SDValue ARMTargetLowering::LowerBlockAddress(SDValue Op, |
| 1904 | SelectionDAG &DAG) const { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1905 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1906 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 1907 | unsigned ARMPCLabelIndex = 0; |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 1908 | DebugLoc DL = Op.getDebugLoc(); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 1909 | EVT PtrVT = getPointerTy(); |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 1910 | const BlockAddress *BA = cast<BlockAddressSDNode>(Op)->getBlockAddress(); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 1911 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| 1912 | SDValue CPAddr; |
| 1913 | if (RelocM == Reloc::Static) { |
| 1914 | CPAddr = DAG.getTargetConstantPool(BA, PtrVT, 4); |
| 1915 | } else { |
| 1916 | unsigned PCAdj = Subtarget->isThumb() ? 4 : 8; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1917 | ARMPCLabelIndex = AFI->createPICLabelUId(); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 1918 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(BA, ARMPCLabelIndex, |
| 1919 | ARMCP::CPBlockAddress, |
| 1920 | PCAdj); |
| 1921 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
| 1922 | } |
| 1923 | CPAddr = DAG.getNode(ARMISD::Wrapper, DL, PtrVT, CPAddr); |
| 1924 | SDValue Result = DAG.getLoad(PtrVT, DL, DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1925 | MachinePointerInfo::getConstantPool(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1926 | false, false, 0); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 1927 | if (RelocM == Reloc::Static) |
| 1928 | return Result; |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1929 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 1930 | return DAG.getNode(ARMISD::PIC_ADD, DL, PtrVT, Result, PICLabel); |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 1931 | } |
| 1932 | |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1933 | // Lower ISD::GlobalTLSAddress using the "general dynamic" model |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1934 | SDValue |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1935 | ARMTargetLowering::LowerToTLSGeneralDynamicModel(GlobalAddressSDNode *GA, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1936 | SelectionDAG &DAG) const { |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1937 | DebugLoc dl = GA->getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1938 | EVT PtrVT = getPointerTy(); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1939 | unsigned char PCAdj = Subtarget->isThumb() ? 4 : 8; |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1940 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1941 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1942 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1943 | ARMConstantPoolValue *CPV = |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 1944 | new ARMConstantPoolValue(GA->getGlobal(), ARMPCLabelIndex, |
Jim Grosbach | 3a2429a | 2010-11-09 21:36:17 +0000 | [diff] [blame] | 1945 | ARMCP::CPValue, PCAdj, ARMCP::TLSGD, true); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1946 | SDValue Argument = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1947 | Argument = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Argument); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1948 | Argument = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Argument, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1949 | MachinePointerInfo::getConstantPool(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1950 | false, false, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1951 | SDValue Chain = Argument.getValue(1); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1952 | |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1953 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1954 | Argument = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Argument, PICLabel); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1955 | |
| 1956 | // call __tls_get_addr. |
| 1957 | ArgListTy Args; |
| 1958 | ArgListEntry Entry; |
| 1959 | Entry.Node = Argument; |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 1960 | Entry.Ty = (const Type *) Type::getInt32Ty(*DAG.getContext()); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1961 | Args.push_back(Entry); |
Dale Johannesen | 7d2ad62 | 2009-01-30 23:10:59 +0000 | [diff] [blame] | 1962 | // FIXME: is there useful debug info available here? |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1963 | std::pair<SDValue, SDValue> CallResult = |
Evan Cheng | 59bc060 | 2009-08-14 19:11:20 +0000 | [diff] [blame] | 1964 | LowerCallTo(Chain, (const Type *) Type::getInt32Ty(*DAG.getContext()), |
| 1965 | false, false, false, false, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1966 | 0, CallingConv::C, false, /*isReturnValueUsed=*/true, |
Bill Wendling | 46ada19 | 2010-03-02 01:55:18 +0000 | [diff] [blame] | 1967 | DAG.getExternalSymbol("__tls_get_addr", PtrVT), Args, DAG, dl); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1968 | return CallResult.first; |
| 1969 | } |
| 1970 | |
| 1971 | // Lower ISD::GlobalTLSAddress using the "initial exec" or |
| 1972 | // "local exec" model. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1973 | SDValue |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1974 | ARMTargetLowering::LowerToTLSExecModels(GlobalAddressSDNode *GA, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1975 | SelectionDAG &DAG) const { |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 1976 | const GlobalValue *GV = GA->getGlobal(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1977 | DebugLoc dl = GA->getDebugLoc(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1978 | SDValue Offset; |
| 1979 | SDValue Chain = DAG.getEntryNode(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1980 | EVT PtrVT = getPointerTy(); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1981 | // Get the Thread Pointer |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1982 | SDValue ThreadPointer = DAG.getNode(ARMISD::THREAD_POINTER, dl, PtrVT); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1983 | |
Chris Lattner | 4fb63d0 | 2009-07-15 04:12:33 +0000 | [diff] [blame] | 1984 | if (GV->isDeclaration()) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1985 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1986 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1987 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1988 | // Initial exec model. |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1989 | unsigned char PCAdj = Subtarget->isThumb() ? 4 : 8; |
| 1990 | ARMConstantPoolValue *CPV = |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 1991 | new ARMConstantPoolValue(GA->getGlobal(), ARMPCLabelIndex, |
Jim Grosbach | 3a2429a | 2010-11-09 21:36:17 +0000 | [diff] [blame] | 1992 | ARMCP::CPValue, PCAdj, ARMCP::GOTTPOFF, true); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1993 | Offset = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1994 | Offset = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Offset); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1995 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1996 | MachinePointerInfo::getConstantPool(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1997 | false, false, 0); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1998 | Chain = Offset.getValue(1); |
| 1999 | |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2000 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2001 | Offset = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Offset, PICLabel); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2002 | |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2003 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2004 | MachinePointerInfo::getConstantPool(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 2005 | false, false, 0); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2006 | } else { |
| 2007 | // local exec model |
Jim Grosbach | 3a2429a | 2010-11-09 21:36:17 +0000 | [diff] [blame] | 2008 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GV, ARMCP::TPOFF); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2009 | Offset = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2010 | Offset = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Offset); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2011 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2012 | MachinePointerInfo::getConstantPool(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 2013 | false, false, 0); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2014 | } |
| 2015 | |
| 2016 | // The address of the thread local variable is the add of the thread |
| 2017 | // pointer with the offset of the variable. |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2018 | return DAG.getNode(ISD::ADD, dl, PtrVT, ThreadPointer, Offset); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2019 | } |
| 2020 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2021 | SDValue |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2022 | ARMTargetLowering::LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const { |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2023 | // TODO: implement the "local dynamic" model |
| 2024 | assert(Subtarget->isTargetELF() && |
| 2025 | "TLS not implemented for non-ELF targets"); |
| 2026 | GlobalAddressSDNode *GA = cast<GlobalAddressSDNode>(Op); |
| 2027 | // If the relocation model is PIC, use the "General Dynamic" TLS Model, |
| 2028 | // otherwise use the "Local Exec" TLS Model |
| 2029 | if (getTargetMachine().getRelocationModel() == Reloc::PIC_) |
| 2030 | return LowerToTLSGeneralDynamicModel(GA, DAG); |
| 2031 | else |
| 2032 | return LowerToTLSExecModels(GA, DAG); |
| 2033 | } |
| 2034 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2035 | SDValue ARMTargetLowering::LowerGlobalAddressELF(SDValue Op, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2036 | SelectionDAG &DAG) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2037 | EVT PtrVT = getPointerTy(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2038 | DebugLoc dl = Op.getDebugLoc(); |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2039 | const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2040 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| 2041 | if (RelocM == Reloc::PIC_) { |
Rafael Espindola | bb46f52 | 2009-01-15 20:18:42 +0000 | [diff] [blame] | 2042 | bool UseGOTOFF = GV->hasLocalLinkage() || GV->hasHiddenVisibility(); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2043 | ARMConstantPoolValue *CPV = |
Jim Grosbach | 3a2429a | 2010-11-09 21:36:17 +0000 | [diff] [blame] | 2044 | new ARMConstantPoolValue(GV, UseGOTOFF ? ARMCP::GOTOFF : ARMCP::GOT); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2045 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2046 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2047 | SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 2048 | CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2049 | MachinePointerInfo::getConstantPool(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 2050 | false, false, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2051 | SDValue Chain = Result.getValue(1); |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 2052 | SDValue GOT = DAG.getGLOBAL_OFFSET_TABLE(PtrVT); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2053 | Result = DAG.getNode(ISD::ADD, dl, PtrVT, Result, GOT); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2054 | if (!UseGOTOFF) |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 2055 | Result = DAG.getLoad(PtrVT, dl, Chain, Result, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2056 | MachinePointerInfo::getGOT(), false, false, 0); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2057 | return Result; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2058 | } |
| 2059 | |
| 2060 | // If we have T2 ops, we can materialize the address directly via movt/movw |
| 2061 | // pair. This is always cheaper. |
| 2062 | if (Subtarget->useMovt()) { |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2063 | ++NumMovwMovt; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2064 | // FIXME: Once remat is capable of dealing with instructions with register |
| 2065 | // operands, expand this into two nodes. |
| 2066 | return DAG.getNode(ARMISD::Wrapper, dl, PtrVT, |
| 2067 | DAG.getTargetGlobalAddress(GV, dl, PtrVT)); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2068 | } else { |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2069 | SDValue CPAddr = DAG.getTargetConstantPool(GV, PtrVT, 4); |
| 2070 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| 2071 | return DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
| 2072 | MachinePointerInfo::getConstantPool(), |
| 2073 | false, false, 0); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2074 | } |
| 2075 | } |
| 2076 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2077 | SDValue ARMTargetLowering::LowerGlobalAddressDarwin(SDValue Op, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2078 | SelectionDAG &DAG) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2079 | EVT PtrVT = getPointerTy(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2080 | DebugLoc dl = Op.getDebugLoc(); |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2081 | const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2082 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2083 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2084 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2085 | |
Evan Cheng | 4abce0c | 2011-05-27 20:11:27 +0000 | [diff] [blame] | 2086 | // FIXME: Enable this for static codegen when tool issues are fixed. |
| 2087 | if (Subtarget->useMovt() && RelocM != Reloc::Static) { |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2088 | ++NumMovwMovt; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2089 | // FIXME: Once remat is capable of dealing with instructions with register |
| 2090 | // operands, expand this into two nodes. |
Evan Cheng | 53519f0 | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 2091 | if (RelocM == Reloc::Static) |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2092 | return DAG.getNode(ARMISD::Wrapper, dl, PtrVT, |
| 2093 | DAG.getTargetGlobalAddress(GV, dl, PtrVT)); |
| 2094 | |
Evan Cheng | 53519f0 | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 2095 | unsigned Wrapper = (RelocM == Reloc::PIC_) |
| 2096 | ? ARMISD::WrapperPIC : ARMISD::WrapperDYN; |
| 2097 | SDValue Result = DAG.getNode(Wrapper, dl, PtrVT, |
Evan Cheng | 9fe2009 | 2011-01-20 08:34:58 +0000 | [diff] [blame] | 2098 | DAG.getTargetGlobalAddress(GV, dl, PtrVT)); |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2099 | if (Subtarget->GVIsIndirectSymbol(GV, RelocM)) |
| 2100 | Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Result, |
| 2101 | MachinePointerInfo::getGOT(), false, false, 0); |
| 2102 | return Result; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2103 | } |
| 2104 | |
| 2105 | unsigned ARMPCLabelIndex = 0; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2106 | SDValue CPAddr; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2107 | if (RelocM == Reloc::Static) { |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2108 | CPAddr = DAG.getTargetConstantPool(GV, PtrVT, 4); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2109 | } else { |
| 2110 | ARMPCLabelIndex = AFI->createPICLabelUId(); |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 2111 | unsigned PCAdj = (RelocM != Reloc::PIC_) ? 0 : (Subtarget->isThumb()?4:8); |
| 2112 | ARMConstantPoolValue *CPV = |
Jim Grosbach | 3fb2b1e | 2009-09-01 01:57:56 +0000 | [diff] [blame] | 2113 | new ARMConstantPoolValue(GV, ARMPCLabelIndex, ARMCP::CPValue, PCAdj); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2114 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2115 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2116 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2117 | |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2118 | SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2119 | MachinePointerInfo::getConstantPool(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 2120 | false, false, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2121 | SDValue Chain = Result.getValue(1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2122 | |
| 2123 | if (RelocM == Reloc::PIC_) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2124 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2125 | Result = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2126 | } |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 2127 | |
Evan Cheng | 63476a8 | 2009-09-03 07:04:02 +0000 | [diff] [blame] | 2128 | if (Subtarget->GVIsIndirectSymbol(GV, RelocM)) |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2129 | Result = DAG.getLoad(PtrVT, dl, Chain, Result, MachinePointerInfo::getGOT(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 2130 | false, false, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2131 | |
| 2132 | return Result; |
| 2133 | } |
| 2134 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2135 | SDValue ARMTargetLowering::LowerGLOBAL_OFFSET_TABLE(SDValue Op, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2136 | SelectionDAG &DAG) const { |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2137 | assert(Subtarget->isTargetELF() && |
| 2138 | "GLOBAL OFFSET TABLE not implemented for non-ELF targets"); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2139 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2140 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2141 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2142 | EVT PtrVT = getPointerTy(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2143 | DebugLoc dl = Op.getDebugLoc(); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2144 | unsigned PCAdj = Subtarget->isThumb() ? 4 : 8; |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 2145 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(*DAG.getContext(), |
| 2146 | "_GLOBAL_OFFSET_TABLE_", |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 2147 | ARMPCLabelIndex, PCAdj); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2148 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2149 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 2150 | SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2151 | MachinePointerInfo::getConstantPool(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 2152 | false, false, 0); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2153 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2154 | return DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2155 | } |
| 2156 | |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 2157 | SDValue |
Jim Grosbach | e4ad387 | 2010-10-19 23:27:08 +0000 | [diff] [blame] | 2158 | ARMTargetLowering::LowerEH_SJLJ_DISPATCHSETUP(SDValue Op, SelectionDAG &DAG) |
| 2159 | const { |
| 2160 | DebugLoc dl = Op.getDebugLoc(); |
| 2161 | return DAG.getNode(ARMISD::EH_SJLJ_DISPATCHSETUP, dl, MVT::Other, |
Bill Wendling | 61512ba | 2011-05-11 01:11:55 +0000 | [diff] [blame] | 2162 | Op.getOperand(0), Op.getOperand(1)); |
Jim Grosbach | e4ad387 | 2010-10-19 23:27:08 +0000 | [diff] [blame] | 2163 | } |
| 2164 | |
| 2165 | SDValue |
Jim Grosbach | 23ff7cf | 2010-05-26 20:22:18 +0000 | [diff] [blame] | 2166 | ARMTargetLowering::LowerEH_SJLJ_SETJMP(SDValue Op, SelectionDAG &DAG) const { |
| 2167 | DebugLoc dl = Op.getDebugLoc(); |
Jim Grosbach | 0798edd | 2010-05-27 23:49:24 +0000 | [diff] [blame] | 2168 | SDValue Val = DAG.getConstant(0, MVT::i32); |
Jim Grosbach | 23ff7cf | 2010-05-26 20:22:18 +0000 | [diff] [blame] | 2169 | return DAG.getNode(ARMISD::EH_SJLJ_SETJMP, dl, MVT::i32, Op.getOperand(0), |
| 2170 | Op.getOperand(1), Val); |
| 2171 | } |
| 2172 | |
| 2173 | SDValue |
Jim Grosbach | 5eb1951 | 2010-05-22 01:06:18 +0000 | [diff] [blame] | 2174 | ARMTargetLowering::LowerEH_SJLJ_LONGJMP(SDValue Op, SelectionDAG &DAG) const { |
| 2175 | DebugLoc dl = Op.getDebugLoc(); |
| 2176 | return DAG.getNode(ARMISD::EH_SJLJ_LONGJMP, dl, MVT::Other, Op.getOperand(0), |
| 2177 | Op.getOperand(1), DAG.getConstant(0, MVT::i32)); |
| 2178 | } |
| 2179 | |
| 2180 | SDValue |
Jim Grosbach | a87ded2 | 2010-02-08 23:22:00 +0000 | [diff] [blame] | 2181 | ARMTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG, |
Jim Grosbach | 7616b64 | 2010-06-16 23:45:49 +0000 | [diff] [blame] | 2182 | const ARMSubtarget *Subtarget) const { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2183 | unsigned IntNo = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 2184 | DebugLoc dl = Op.getDebugLoc(); |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 2185 | switch (IntNo) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2186 | default: return SDValue(); // Don't custom lower most intrinsics. |
Bob Wilson | 916afdb | 2009-08-04 00:25:01 +0000 | [diff] [blame] | 2187 | case Intrinsic::arm_thread_pointer: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2188 | EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
Bob Wilson | 916afdb | 2009-08-04 00:25:01 +0000 | [diff] [blame] | 2189 | return DAG.getNode(ARMISD::THREAD_POINTER, dl, PtrVT); |
| 2190 | } |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2191 | case Intrinsic::eh_sjlj_lsda: { |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2192 | MachineFunction &MF = DAG.getMachineFunction(); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2193 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2194 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2195 | EVT PtrVT = getPointerTy(); |
| 2196 | DebugLoc dl = Op.getDebugLoc(); |
| 2197 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| 2198 | SDValue CPAddr; |
| 2199 | unsigned PCAdj = (RelocM != Reloc::PIC_) |
| 2200 | ? 0 : (Subtarget->isThumb() ? 4 : 8); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2201 | ARMConstantPoolValue *CPV = |
Jim Grosbach | 3fb2b1e | 2009-09-01 01:57:56 +0000 | [diff] [blame] | 2202 | new ARMConstantPoolValue(MF.getFunction(), ARMPCLabelIndex, |
| 2203 | ARMCP::CPLSDA, PCAdj); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2204 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2205 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2206 | SDValue Result = |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2207 | DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2208 | MachinePointerInfo::getConstantPool(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 2209 | false, false, 0); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2210 | |
| 2211 | if (RelocM == Reloc::PIC_) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2212 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2213 | Result = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
| 2214 | } |
| 2215 | return Result; |
| 2216 | } |
Evan Cheng | 92e3916 | 2011-03-29 23:06:19 +0000 | [diff] [blame] | 2217 | case Intrinsic::arm_neon_vmulls: |
| 2218 | case Intrinsic::arm_neon_vmullu: { |
| 2219 | unsigned NewOpc = (IntNo == Intrinsic::arm_neon_vmulls) |
| 2220 | ? ARMISD::VMULLs : ARMISD::VMULLu; |
| 2221 | return DAG.getNode(NewOpc, Op.getDebugLoc(), Op.getValueType(), |
| 2222 | Op.getOperand(1), Op.getOperand(2)); |
| 2223 | } |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 2224 | } |
| 2225 | } |
| 2226 | |
Jim Grosbach | 7c03dbd | 2009-12-14 21:24:16 +0000 | [diff] [blame] | 2227 | static SDValue LowerMEMBARRIER(SDValue Op, SelectionDAG &DAG, |
Jim Grosbach | 7616b64 | 2010-06-16 23:45:49 +0000 | [diff] [blame] | 2228 | const ARMSubtarget *Subtarget) { |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 2229 | DebugLoc dl = Op.getDebugLoc(); |
Bob Wilson | f74a429 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 2230 | if (!Subtarget->hasDataBarrier()) { |
| 2231 | // Some ARMv6 cpus can support data barriers with an mcr instruction. |
| 2232 | // Thumb1 and pre-v6 ARM mode use a libcall instead and should never get |
| 2233 | // here. |
Bob Wilson | 54f9256 | 2010-11-09 22:50:44 +0000 | [diff] [blame] | 2234 | assert(Subtarget->hasV6Ops() && !Subtarget->isThumb() && |
Evan Cheng | 11db068 | 2010-08-11 06:22:01 +0000 | [diff] [blame] | 2235 | "Unexpected ISD::MEMBARRIER encountered. Should be libcall!"); |
Bob Wilson | f74a429 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 2236 | return DAG.getNode(ARMISD::MEMBARRIER_MCR, dl, MVT::Other, Op.getOperand(0), |
Jim Grosbach | c73993b | 2010-06-17 01:37:00 +0000 | [diff] [blame] | 2237 | DAG.getConstant(0, MVT::i32)); |
Evan Cheng | 11db068 | 2010-08-11 06:22:01 +0000 | [diff] [blame] | 2238 | } |
Bob Wilson | f74a429 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 2239 | |
| 2240 | SDValue Op5 = Op.getOperand(5); |
| 2241 | bool isDeviceBarrier = cast<ConstantSDNode>(Op5)->getZExtValue() != 0; |
| 2242 | unsigned isLL = cast<ConstantSDNode>(Op.getOperand(1))->getZExtValue(); |
| 2243 | unsigned isLS = cast<ConstantSDNode>(Op.getOperand(2))->getZExtValue(); |
| 2244 | bool isOnlyStoreBarrier = (isLL == 0 && isLS == 0); |
| 2245 | |
| 2246 | ARM_MB::MemBOpt DMBOpt; |
| 2247 | if (isDeviceBarrier) |
| 2248 | DMBOpt = isOnlyStoreBarrier ? ARM_MB::ST : ARM_MB::SY; |
| 2249 | else |
| 2250 | DMBOpt = isOnlyStoreBarrier ? ARM_MB::ISHST : ARM_MB::ISH; |
| 2251 | return DAG.getNode(ARMISD::MEMBARRIER, dl, MVT::Other, Op.getOperand(0), |
| 2252 | DAG.getConstant(DMBOpt, MVT::i32)); |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 2253 | } |
| 2254 | |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2255 | static SDValue LowerPREFETCH(SDValue Op, SelectionDAG &DAG, |
| 2256 | const ARMSubtarget *Subtarget) { |
| 2257 | // ARM pre v5TE and Thumb1 does not have preload instructions. |
| 2258 | if (!(Subtarget->isThumb2() || |
| 2259 | (!Subtarget->isThumb1Only() && Subtarget->hasV5TEOps()))) |
| 2260 | // Just preserve the chain. |
| 2261 | return Op.getOperand(0); |
| 2262 | |
| 2263 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 2264 | unsigned isRead = ~cast<ConstantSDNode>(Op.getOperand(2))->getZExtValue() & 1; |
| 2265 | if (!isRead && |
| 2266 | (!Subtarget->hasV7Ops() || !Subtarget->hasMPExtension())) |
| 2267 | // ARMv7 with MP extension has PLDW. |
| 2268 | return Op.getOperand(0); |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2269 | |
| 2270 | if (Subtarget->isThumb()) |
| 2271 | // Invert the bits. |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 2272 | isRead = ~isRead & 1; |
| 2273 | unsigned isData = Subtarget->isThumb() ? 0 : 1; |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2274 | |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 2275 | // Currently there is no intrinsic that matches pli. |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2276 | return DAG.getNode(ARMISD::PRELOAD, dl, MVT::Other, Op.getOperand(0), |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 2277 | Op.getOperand(1), DAG.getConstant(isRead, MVT::i32), |
| 2278 | DAG.getConstant(isData, MVT::i32)); |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2279 | } |
| 2280 | |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 2281 | static SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) { |
| 2282 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2283 | ARMFunctionInfo *FuncInfo = MF.getInfo<ARMFunctionInfo>(); |
| 2284 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2285 | // vastart just stores the address of the VarArgsFrameIndex slot into the |
| 2286 | // memory location argument. |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2287 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2288 | EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 2289 | SDValue FR = DAG.getFrameIndex(FuncInfo->getVarArgsFrameIndex(), PtrVT); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 2290 | const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue(); |
Chris Lattner | fc448ff | 2010-09-21 18:51:21 +0000 | [diff] [blame] | 2291 | return DAG.getStore(Op.getOperand(0), dl, FR, Op.getOperand(1), |
| 2292 | MachinePointerInfo(SV), false, false, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2293 | } |
| 2294 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2295 | SDValue |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2296 | ARMTargetLowering::GetF64FormalArgument(CCValAssign &VA, CCValAssign &NextVA, |
| 2297 | SDValue &Root, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2298 | DebugLoc dl) const { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2299 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2300 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2301 | |
| 2302 | TargetRegisterClass *RC; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 2303 | if (AFI->isThumb1OnlyFunction()) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2304 | RC = ARM::tGPRRegisterClass; |
| 2305 | else |
| 2306 | RC = ARM::GPRRegisterClass; |
| 2307 | |
| 2308 | // Transform the arguments stored in physical registers into virtual ones. |
Devang Patel | 68e6bee | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 2309 | unsigned Reg = MF.addLiveIn(VA.getLocReg(), RC); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2310 | SDValue ArgValue = DAG.getCopyFromReg(Root, dl, Reg, MVT::i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2311 | |
| 2312 | SDValue ArgValue2; |
| 2313 | if (NextVA.isMemLoc()) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2314 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
Evan Cheng | ed2ae13 | 2010-07-03 00:40:23 +0000 | [diff] [blame] | 2315 | int FI = MFI->CreateFixedObject(4, NextVA.getLocMemOffset(), true); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2316 | |
| 2317 | // Create load node to retrieve arguments from the stack. |
| 2318 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2319 | ArgValue2 = DAG.getLoad(MVT::i32, dl, Root, FIN, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2320 | MachinePointerInfo::getFixedStack(FI), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 2321 | false, false, 0); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2322 | } else { |
Devang Patel | 68e6bee | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 2323 | Reg = MF.addLiveIn(NextVA.getLocReg(), RC); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2324 | ArgValue2 = DAG.getCopyFromReg(Root, dl, Reg, MVT::i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2325 | } |
| 2326 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 2327 | return DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, ArgValue, ArgValue2); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2328 | } |
| 2329 | |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2330 | void |
| 2331 | ARMTargetLowering::computeRegArea(CCState &CCInfo, MachineFunction &MF, |
| 2332 | unsigned &VARegSize, unsigned &VARegSaveSize) |
| 2333 | const { |
| 2334 | unsigned NumGPRs; |
| 2335 | if (CCInfo.isFirstByValRegValid()) |
| 2336 | NumGPRs = ARM::R4 - CCInfo.getFirstByValReg(); |
| 2337 | else { |
| 2338 | unsigned int firstUnalloced; |
| 2339 | firstUnalloced = CCInfo.getFirstUnallocated(GPRArgRegs, |
| 2340 | sizeof(GPRArgRegs) / |
| 2341 | sizeof(GPRArgRegs[0])); |
| 2342 | NumGPRs = (firstUnalloced <= 3) ? (4 - firstUnalloced) : 0; |
| 2343 | } |
| 2344 | |
| 2345 | unsigned Align = MF.getTarget().getFrameLowering()->getStackAlignment(); |
| 2346 | VARegSize = NumGPRs * 4; |
| 2347 | VARegSaveSize = (VARegSize + Align - 1) & ~(Align - 1); |
| 2348 | } |
| 2349 | |
| 2350 | // The remaining GPRs hold either the beginning of variable-argument |
| 2351 | // data, or the beginning of an aggregate passed by value (usuall |
| 2352 | // byval). Either way, we allocate stack slots adjacent to the data |
| 2353 | // provided by our caller, and store the unallocated registers there. |
| 2354 | // If this is a variadic function, the va_list pointer will begin with |
| 2355 | // these values; otherwise, this reassembles a (byval) structure that |
| 2356 | // was split between registers and memory. |
| 2357 | void |
| 2358 | ARMTargetLowering::VarArgStyleRegisters(CCState &CCInfo, SelectionDAG &DAG, |
| 2359 | DebugLoc dl, SDValue &Chain, |
| 2360 | unsigned ArgOffset) const { |
| 2361 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2362 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 2363 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2364 | unsigned firstRegToSaveIndex; |
| 2365 | if (CCInfo.isFirstByValRegValid()) |
| 2366 | firstRegToSaveIndex = CCInfo.getFirstByValReg() - ARM::R0; |
| 2367 | else { |
| 2368 | firstRegToSaveIndex = CCInfo.getFirstUnallocated |
| 2369 | (GPRArgRegs, sizeof(GPRArgRegs) / sizeof(GPRArgRegs[0])); |
| 2370 | } |
| 2371 | |
| 2372 | unsigned VARegSize, VARegSaveSize; |
| 2373 | computeRegArea(CCInfo, MF, VARegSize, VARegSaveSize); |
| 2374 | if (VARegSaveSize) { |
| 2375 | // If this function is vararg, store any remaining integer argument regs |
| 2376 | // to their spots on the stack so that they may be loaded by deferencing |
| 2377 | // the result of va_next. |
| 2378 | AFI->setVarArgsRegSaveSize(VARegSaveSize); |
Eric Christopher | 5ac179c | 2011-04-29 23:12:01 +0000 | [diff] [blame] | 2379 | AFI->setVarArgsFrameIndex(MFI->CreateFixedObject(VARegSaveSize, |
| 2380 | ArgOffset + VARegSaveSize |
| 2381 | - VARegSize, |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2382 | false)); |
| 2383 | SDValue FIN = DAG.getFrameIndex(AFI->getVarArgsFrameIndex(), |
| 2384 | getPointerTy()); |
| 2385 | |
| 2386 | SmallVector<SDValue, 4> MemOps; |
| 2387 | for (; firstRegToSaveIndex < 4; ++firstRegToSaveIndex) { |
| 2388 | TargetRegisterClass *RC; |
| 2389 | if (AFI->isThumb1OnlyFunction()) |
| 2390 | RC = ARM::tGPRRegisterClass; |
| 2391 | else |
| 2392 | RC = ARM::GPRRegisterClass; |
| 2393 | |
| 2394 | unsigned VReg = MF.addLiveIn(GPRArgRegs[firstRegToSaveIndex], RC); |
| 2395 | SDValue Val = DAG.getCopyFromReg(Chain, dl, VReg, MVT::i32); |
| 2396 | SDValue Store = |
| 2397 | DAG.getStore(Val.getValue(1), dl, Val, FIN, |
Eric Christopher | 5ac179c | 2011-04-29 23:12:01 +0000 | [diff] [blame] | 2398 | MachinePointerInfo::getFixedStack(AFI->getVarArgsFrameIndex()), |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2399 | false, false, 0); |
| 2400 | MemOps.push_back(Store); |
| 2401 | FIN = DAG.getNode(ISD::ADD, dl, getPointerTy(), FIN, |
| 2402 | DAG.getConstant(4, getPointerTy())); |
| 2403 | } |
| 2404 | if (!MemOps.empty()) |
| 2405 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, |
| 2406 | &MemOps[0], MemOps.size()); |
| 2407 | } else |
| 2408 | // This will point to the next argument passed via stack. |
| 2409 | AFI->setVarArgsFrameIndex(MFI->CreateFixedObject(4, ArgOffset, true)); |
| 2410 | } |
| 2411 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2412 | SDValue |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2413 | ARMTargetLowering::LowerFormalArguments(SDValue Chain, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 2414 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2415 | const SmallVectorImpl<ISD::InputArg> |
| 2416 | &Ins, |
| 2417 | DebugLoc dl, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2418 | SmallVectorImpl<SDValue> &InVals) |
| 2419 | const { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2420 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2421 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 2422 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2423 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2424 | |
| 2425 | // Assign locations to all of the incoming arguments. |
| 2426 | SmallVector<CCValAssign, 16> ArgLocs; |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2427 | CCState CCInfo(CallConv, isVarArg, getTargetMachine(), ArgLocs, |
| 2428 | *DAG.getContext()); |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2429 | CCInfo.setCallOrPrologue(Prologue); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2430 | CCInfo.AnalyzeFormalArguments(Ins, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 2431 | CCAssignFnForNode(CallConv, /* Return*/ false, |
| 2432 | isVarArg)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2433 | |
| 2434 | SmallVector<SDValue, 16> ArgValues; |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2435 | int lastInsIndex = -1; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2436 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2437 | SDValue ArgValue; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2438 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| 2439 | CCValAssign &VA = ArgLocs[i]; |
| 2440 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 2441 | // Arguments stored in registers. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2442 | if (VA.isRegLoc()) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2443 | EVT RegVT = VA.getLocVT(); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2444 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2445 | if (VA.needsCustom()) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2446 | // f64 and vector types are split up into multiple registers or |
| 2447 | // combinations of registers and stack slots. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2448 | if (VA.getLocVT() == MVT::v2f64) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2449 | SDValue ArgValue1 = GetF64FormalArgument(VA, ArgLocs[++i], |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2450 | Chain, DAG, dl); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2451 | VA = ArgLocs[++i]; // skip ahead to next loc |
Bob Wilson | 6a234f0 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 2452 | SDValue ArgValue2; |
| 2453 | if (VA.isMemLoc()) { |
Evan Cheng | ed2ae13 | 2010-07-03 00:40:23 +0000 | [diff] [blame] | 2454 | int FI = MFI->CreateFixedObject(8, VA.getLocMemOffset(), true); |
Bob Wilson | 6a234f0 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 2455 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
| 2456 | ArgValue2 = DAG.getLoad(MVT::f64, dl, Chain, FIN, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2457 | MachinePointerInfo::getFixedStack(FI), |
Bob Wilson | 6a234f0 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 2458 | false, false, 0); |
| 2459 | } else { |
| 2460 | ArgValue2 = GetF64FormalArgument(VA, ArgLocs[++i], |
| 2461 | Chain, DAG, dl); |
| 2462 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2463 | ArgValue = DAG.getNode(ISD::UNDEF, dl, MVT::v2f64); |
| 2464 | ArgValue = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2465 | ArgValue, ArgValue1, DAG.getIntPtrConstant(0)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2466 | ArgValue = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2467 | ArgValue, ArgValue2, DAG.getIntPtrConstant(1)); |
| 2468 | } else |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2469 | ArgValue = GetF64FormalArgument(VA, ArgLocs[++i], Chain, DAG, dl); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2470 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2471 | } else { |
| 2472 | TargetRegisterClass *RC; |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 2473 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2474 | if (RegVT == MVT::f32) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2475 | RC = ARM::SPRRegisterClass; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2476 | else if (RegVT == MVT::f64) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2477 | RC = ARM::DPRRegisterClass; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2478 | else if (RegVT == MVT::v2f64) |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 2479 | RC = ARM::QPRRegisterClass; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2480 | else if (RegVT == MVT::i32) |
Anton Korobeynikov | 058c251 | 2009-08-05 20:15:19 +0000 | [diff] [blame] | 2481 | RC = (AFI->isThumb1OnlyFunction() ? |
| 2482 | ARM::tGPRRegisterClass : ARM::GPRRegisterClass); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2483 | else |
Anton Korobeynikov | 058c251 | 2009-08-05 20:15:19 +0000 | [diff] [blame] | 2484 | llvm_unreachable("RegVT not supported by FORMAL_ARGUMENTS Lowering"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2485 | |
| 2486 | // Transform the arguments in physical registers into virtual ones. |
Devang Patel | 68e6bee | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 2487 | unsigned Reg = MF.addLiveIn(VA.getLocReg(), RC); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2488 | ArgValue = DAG.getCopyFromReg(Chain, dl, Reg, RegVT); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2489 | } |
| 2490 | |
| 2491 | // If this is an 8 or 16-bit value, it is really passed promoted |
| 2492 | // to 32 bits. Insert an assert[sz]ext to capture this, then |
| 2493 | // truncate to the right size. |
| 2494 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 2495 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2496 | case CCValAssign::Full: break; |
| 2497 | case CCValAssign::BCvt: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2498 | ArgValue = DAG.getNode(ISD::BITCAST, dl, VA.getValVT(), ArgValue); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2499 | break; |
| 2500 | case CCValAssign::SExt: |
| 2501 | ArgValue = DAG.getNode(ISD::AssertSext, dl, RegVT, ArgValue, |
| 2502 | DAG.getValueType(VA.getValVT())); |
| 2503 | ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue); |
| 2504 | break; |
| 2505 | case CCValAssign::ZExt: |
| 2506 | ArgValue = DAG.getNode(ISD::AssertZext, dl, RegVT, ArgValue, |
| 2507 | DAG.getValueType(VA.getValVT())); |
| 2508 | ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue); |
| 2509 | break; |
| 2510 | } |
| 2511 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2512 | InVals.push_back(ArgValue); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2513 | |
| 2514 | } else { // VA.isRegLoc() |
| 2515 | |
| 2516 | // sanity check |
| 2517 | assert(VA.isMemLoc()); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2518 | assert(VA.getValVT() != MVT::i64 && "i64 should already be lowered"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2519 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2520 | int index = ArgLocs[i].getValNo(); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 2521 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2522 | // Some Ins[] entries become multiple ArgLoc[] entries. |
| 2523 | // Process them only once. |
| 2524 | if (index != lastInsIndex) |
| 2525 | { |
| 2526 | ISD::ArgFlagsTy Flags = Ins[index].Flags; |
Eric Christopher | 5ac179c | 2011-04-29 23:12:01 +0000 | [diff] [blame] | 2527 | // FIXME: For now, all byval parameter objects are marked mutable. |
| 2528 | // This can be changed with more analysis. |
| 2529 | // In case of tail call optimization mark all arguments mutable. |
| 2530 | // Since they could be overwritten by lowering of arguments in case of |
| 2531 | // a tail call. |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2532 | if (Flags.isByVal()) { |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2533 | unsigned VARegSize, VARegSaveSize; |
| 2534 | computeRegArea(CCInfo, MF, VARegSize, VARegSaveSize); |
| 2535 | VarArgStyleRegisters(CCInfo, DAG, dl, Chain, 0); |
| 2536 | unsigned Bytes = Flags.getByValSize() - VARegSize; |
Evan Cheng | ee2e0e3 | 2011-03-30 23:44:13 +0000 | [diff] [blame] | 2537 | if (Bytes == 0) Bytes = 1; // Don't create zero-sized stack objects. |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2538 | int FI = MFI->CreateFixedObject(Bytes, |
| 2539 | VA.getLocMemOffset(), false); |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2540 | InVals.push_back(DAG.getFrameIndex(FI, getPointerTy())); |
| 2541 | } else { |
| 2542 | int FI = MFI->CreateFixedObject(VA.getLocVT().getSizeInBits()/8, |
| 2543 | VA.getLocMemOffset(), true); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2544 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2545 | // Create load nodes to retrieve arguments from the stack. |
| 2546 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
| 2547 | InVals.push_back(DAG.getLoad(VA.getValVT(), dl, Chain, FIN, |
| 2548 | MachinePointerInfo::getFixedStack(FI), |
| 2549 | false, false, 0)); |
| 2550 | } |
| 2551 | lastInsIndex = index; |
| 2552 | } |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2553 | } |
| 2554 | } |
| 2555 | |
| 2556 | // varargs |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2557 | if (isVarArg) |
| 2558 | VarArgStyleRegisters(CCInfo, DAG, dl, Chain, CCInfo.getNextStackOffset()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2559 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2560 | return Chain; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2561 | } |
| 2562 | |
| 2563 | /// isFloatingPointZero - Return true if this is +0.0. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2564 | static bool isFloatingPointZero(SDValue Op) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2565 | if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(Op)) |
Dale Johannesen | eaf0894 | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 2566 | return CFP->getValueAPF().isPosZero(); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2567 | else if (ISD::isEXTLoad(Op.getNode()) || ISD::isNON_EXTLoad(Op.getNode())) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2568 | // Maybe this has already been legalized into the constant pool? |
| 2569 | if (Op.getOperand(1).getOpcode() == ARMISD::Wrapper) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2570 | SDValue WrapperOp = Op.getOperand(1).getOperand(0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2571 | if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(WrapperOp)) |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2572 | if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CP->getConstVal())) |
Dale Johannesen | eaf0894 | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 2573 | return CFP->getValueAPF().isPosZero(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2574 | } |
| 2575 | } |
| 2576 | return false; |
| 2577 | } |
| 2578 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2579 | /// Returns appropriate ARM CMP (cmp) and corresponding condition code for |
| 2580 | /// the given operands. |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 2581 | SDValue |
| 2582 | ARMTargetLowering::getARMCmp(SDValue LHS, SDValue RHS, ISD::CondCode CC, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2583 | SDValue &ARMcc, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2584 | DebugLoc dl) const { |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2585 | if (ConstantSDNode *RHSC = dyn_cast<ConstantSDNode>(RHS.getNode())) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2586 | unsigned C = RHSC->getZExtValue(); |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 2587 | if (!isLegalICmpImmediate(C)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2588 | // Constant does not fit, try adjusting it by one? |
| 2589 | switch (CC) { |
| 2590 | default: break; |
| 2591 | case ISD::SETLT: |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2592 | case ISD::SETGE: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 2593 | if (C != 0x80000000 && isLegalICmpImmediate(C-1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2594 | CC = (CC == ISD::SETLT) ? ISD::SETLE : ISD::SETGT; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2595 | RHS = DAG.getConstant(C-1, MVT::i32); |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2596 | } |
| 2597 | break; |
| 2598 | case ISD::SETULT: |
| 2599 | case ISD::SETUGE: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 2600 | if (C != 0 && isLegalICmpImmediate(C-1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2601 | CC = (CC == ISD::SETULT) ? ISD::SETULE : ISD::SETUGT; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2602 | RHS = DAG.getConstant(C-1, MVT::i32); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2603 | } |
| 2604 | break; |
| 2605 | case ISD::SETLE: |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2606 | case ISD::SETGT: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 2607 | if (C != 0x7fffffff && isLegalICmpImmediate(C+1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2608 | CC = (CC == ISD::SETLE) ? ISD::SETLT : ISD::SETGE; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2609 | RHS = DAG.getConstant(C+1, MVT::i32); |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2610 | } |
| 2611 | break; |
| 2612 | case ISD::SETULE: |
| 2613 | case ISD::SETUGT: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 2614 | if (C != 0xffffffff && isLegalICmpImmediate(C+1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2615 | CC = (CC == ISD::SETULE) ? ISD::SETULT : ISD::SETUGE; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2616 | RHS = DAG.getConstant(C+1, MVT::i32); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2617 | } |
| 2618 | break; |
| 2619 | } |
| 2620 | } |
| 2621 | } |
| 2622 | |
| 2623 | ARMCC::CondCodes CondCode = IntCCToARMCC(CC); |
Lauro Ramos Venancio | 9996663 | 2007-04-02 01:30:03 +0000 | [diff] [blame] | 2624 | ARMISD::NodeType CompareType; |
| 2625 | switch (CondCode) { |
| 2626 | default: |
| 2627 | CompareType = ARMISD::CMP; |
| 2628 | break; |
| 2629 | case ARMCC::EQ: |
| 2630 | case ARMCC::NE: |
David Goodwin | c0309b4 | 2009-06-29 15:33:01 +0000 | [diff] [blame] | 2631 | // Uses only Z Flag |
| 2632 | CompareType = ARMISD::CMPZ; |
Lauro Ramos Venancio | 9996663 | 2007-04-02 01:30:03 +0000 | [diff] [blame] | 2633 | break; |
| 2634 | } |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2635 | ARMcc = DAG.getConstant(CondCode, MVT::i32); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 2636 | return DAG.getNode(CompareType, dl, MVT::Glue, LHS, RHS); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2637 | } |
| 2638 | |
| 2639 | /// 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] | 2640 | SDValue |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2641 | ARMTargetLowering::getVFPCmp(SDValue LHS, SDValue RHS, SelectionDAG &DAG, |
Evan Cheng | 515fe3a | 2010-07-08 02:08:50 +0000 | [diff] [blame] | 2642 | DebugLoc dl) const { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2643 | SDValue Cmp; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2644 | if (!isFloatingPointZero(RHS)) |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 2645 | Cmp = DAG.getNode(ARMISD::CMPFP, dl, MVT::Glue, LHS, RHS); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2646 | else |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 2647 | Cmp = DAG.getNode(ARMISD::CMPFPw0, dl, MVT::Glue, LHS); |
| 2648 | return DAG.getNode(ARMISD::FMSTAT, dl, MVT::Glue, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2649 | } |
| 2650 | |
Bob Wilson | 79f56c9 | 2011-03-08 01:17:20 +0000 | [diff] [blame] | 2651 | /// duplicateCmp - Glue values can have only one use, so this function |
| 2652 | /// duplicates a comparison node. |
| 2653 | SDValue |
| 2654 | ARMTargetLowering::duplicateCmp(SDValue Cmp, SelectionDAG &DAG) const { |
| 2655 | unsigned Opc = Cmp.getOpcode(); |
| 2656 | DebugLoc DL = Cmp.getDebugLoc(); |
| 2657 | if (Opc == ARMISD::CMP || Opc == ARMISD::CMPZ) |
| 2658 | return DAG.getNode(Opc, DL, MVT::Glue, Cmp.getOperand(0),Cmp.getOperand(1)); |
| 2659 | |
| 2660 | assert(Opc == ARMISD::FMSTAT && "unexpected comparison operation"); |
| 2661 | Cmp = Cmp.getOperand(0); |
| 2662 | Opc = Cmp.getOpcode(); |
| 2663 | if (Opc == ARMISD::CMPFP) |
| 2664 | Cmp = DAG.getNode(Opc, DL, MVT::Glue, Cmp.getOperand(0),Cmp.getOperand(1)); |
| 2665 | else { |
| 2666 | assert(Opc == ARMISD::CMPFPw0 && "unexpected operand of FMSTAT"); |
| 2667 | Cmp = DAG.getNode(Opc, DL, MVT::Glue, Cmp.getOperand(0)); |
| 2668 | } |
| 2669 | return DAG.getNode(ARMISD::FMSTAT, DL, MVT::Glue, Cmp); |
| 2670 | } |
| 2671 | |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 2672 | SDValue ARMTargetLowering::LowerSELECT(SDValue Op, SelectionDAG &DAG) const { |
| 2673 | SDValue Cond = Op.getOperand(0); |
| 2674 | SDValue SelectTrue = Op.getOperand(1); |
| 2675 | SDValue SelectFalse = Op.getOperand(2); |
| 2676 | DebugLoc dl = Op.getDebugLoc(); |
| 2677 | |
| 2678 | // Convert: |
| 2679 | // |
| 2680 | // (select (cmov 1, 0, cond), t, f) -> (cmov t, f, cond) |
| 2681 | // (select (cmov 0, 1, cond), t, f) -> (cmov f, t, cond) |
| 2682 | // |
| 2683 | if (Cond.getOpcode() == ARMISD::CMOV && Cond.hasOneUse()) { |
| 2684 | const ConstantSDNode *CMOVTrue = |
| 2685 | dyn_cast<ConstantSDNode>(Cond.getOperand(0)); |
| 2686 | const ConstantSDNode *CMOVFalse = |
| 2687 | dyn_cast<ConstantSDNode>(Cond.getOperand(1)); |
| 2688 | |
| 2689 | if (CMOVTrue && CMOVFalse) { |
| 2690 | unsigned CMOVTrueVal = CMOVTrue->getZExtValue(); |
| 2691 | unsigned CMOVFalseVal = CMOVFalse->getZExtValue(); |
| 2692 | |
| 2693 | SDValue True; |
| 2694 | SDValue False; |
| 2695 | if (CMOVTrueVal == 1 && CMOVFalseVal == 0) { |
| 2696 | True = SelectTrue; |
| 2697 | False = SelectFalse; |
| 2698 | } else if (CMOVTrueVal == 0 && CMOVFalseVal == 1) { |
| 2699 | True = SelectFalse; |
| 2700 | False = SelectTrue; |
| 2701 | } |
| 2702 | |
| 2703 | if (True.getNode() && False.getNode()) { |
Evan Cheng | b936e30 | 2011-05-18 18:59:17 +0000 | [diff] [blame] | 2704 | EVT VT = Op.getValueType(); |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 2705 | SDValue ARMcc = Cond.getOperand(2); |
| 2706 | SDValue CCR = Cond.getOperand(3); |
Bob Wilson | 79f56c9 | 2011-03-08 01:17:20 +0000 | [diff] [blame] | 2707 | SDValue Cmp = duplicateCmp(Cond.getOperand(4), DAG); |
Evan Cheng | b936e30 | 2011-05-18 18:59:17 +0000 | [diff] [blame] | 2708 | assert(True.getValueType() == VT); |
| 2709 | return DAG.getNode(ARMISD::CMOV, dl, VT, True, False, ARMcc, CCR, Cmp); |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 2710 | } |
| 2711 | } |
| 2712 | } |
| 2713 | |
| 2714 | return DAG.getSelectCC(dl, Cond, |
| 2715 | DAG.getConstant(0, Cond.getValueType()), |
| 2716 | SelectTrue, SelectFalse, ISD::SETNE); |
| 2717 | } |
| 2718 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2719 | SDValue ARMTargetLowering::LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2720 | EVT VT = Op.getValueType(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2721 | SDValue LHS = Op.getOperand(0); |
| 2722 | SDValue RHS = Op.getOperand(1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2723 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(4))->get(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2724 | SDValue TrueVal = Op.getOperand(2); |
| 2725 | SDValue FalseVal = Op.getOperand(3); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2726 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2727 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2728 | if (LHS.getValueType() == MVT::i32) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2729 | SDValue ARMcc; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2730 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2731 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMcc, DAG, dl); |
| 2732 | return DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, ARMcc, CCR,Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2733 | } |
| 2734 | |
| 2735 | ARMCC::CondCodes CondCode, CondCode2; |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 2736 | FPCCToARMCC(CC, CondCode, CondCode2); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2737 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2738 | SDValue ARMcc = DAG.getConstant(CondCode, MVT::i32); |
| 2739 | SDValue Cmp = getVFPCmp(LHS, RHS, DAG, dl); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2740 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2741 | SDValue Result = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2742 | ARMcc, CCR, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2743 | if (CondCode2 != ARMCC::AL) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2744 | SDValue ARMcc2 = DAG.getConstant(CondCode2, MVT::i32); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2745 | // FIXME: Needs another CMP because flag can have but one use. |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2746 | SDValue Cmp2 = getVFPCmp(LHS, RHS, DAG, dl); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2747 | Result = DAG.getNode(ARMISD::CMOV, dl, VT, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2748 | Result, TrueVal, ARMcc2, CCR, Cmp2); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2749 | } |
| 2750 | return Result; |
| 2751 | } |
| 2752 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2753 | /// canChangeToInt - Given the fp compare operand, return true if it is suitable |
| 2754 | /// to morph to an integer compare sequence. |
| 2755 | static bool canChangeToInt(SDValue Op, bool &SeenZero, |
| 2756 | const ARMSubtarget *Subtarget) { |
| 2757 | SDNode *N = Op.getNode(); |
| 2758 | if (!N->hasOneUse()) |
| 2759 | // Otherwise it requires moving the value from fp to integer registers. |
| 2760 | return false; |
| 2761 | if (!N->getNumValues()) |
| 2762 | return false; |
| 2763 | EVT VT = Op.getValueType(); |
| 2764 | if (VT != MVT::f32 && !Subtarget->isFPBrccSlow()) |
| 2765 | // f32 case is generally profitable. f64 case only makes sense when vcmpe + |
| 2766 | // vmrs are very slow, e.g. cortex-a8. |
| 2767 | return false; |
| 2768 | |
| 2769 | if (isFloatingPointZero(Op)) { |
| 2770 | SeenZero = true; |
| 2771 | return true; |
| 2772 | } |
| 2773 | return ISD::isNormalLoad(N); |
| 2774 | } |
| 2775 | |
| 2776 | static SDValue bitcastf32Toi32(SDValue Op, SelectionDAG &DAG) { |
| 2777 | if (isFloatingPointZero(Op)) |
| 2778 | return DAG.getConstant(0, MVT::i32); |
| 2779 | |
| 2780 | if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Op)) |
| 2781 | return DAG.getLoad(MVT::i32, Op.getDebugLoc(), |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2782 | Ld->getChain(), Ld->getBasePtr(), Ld->getPointerInfo(), |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2783 | Ld->isVolatile(), Ld->isNonTemporal(), |
| 2784 | Ld->getAlignment()); |
| 2785 | |
| 2786 | llvm_unreachable("Unknown VFP cmp argument!"); |
| 2787 | } |
| 2788 | |
| 2789 | static void expandf64Toi32(SDValue Op, SelectionDAG &DAG, |
| 2790 | SDValue &RetVal1, SDValue &RetVal2) { |
| 2791 | if (isFloatingPointZero(Op)) { |
| 2792 | RetVal1 = DAG.getConstant(0, MVT::i32); |
| 2793 | RetVal2 = DAG.getConstant(0, MVT::i32); |
| 2794 | return; |
| 2795 | } |
| 2796 | |
| 2797 | if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Op)) { |
| 2798 | SDValue Ptr = Ld->getBasePtr(); |
| 2799 | RetVal1 = DAG.getLoad(MVT::i32, Op.getDebugLoc(), |
| 2800 | Ld->getChain(), Ptr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2801 | Ld->getPointerInfo(), |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2802 | Ld->isVolatile(), Ld->isNonTemporal(), |
| 2803 | Ld->getAlignment()); |
| 2804 | |
| 2805 | EVT PtrType = Ptr.getValueType(); |
| 2806 | unsigned NewAlign = MinAlign(Ld->getAlignment(), 4); |
| 2807 | SDValue NewPtr = DAG.getNode(ISD::ADD, Op.getDebugLoc(), |
| 2808 | PtrType, Ptr, DAG.getConstant(4, PtrType)); |
| 2809 | RetVal2 = DAG.getLoad(MVT::i32, Op.getDebugLoc(), |
| 2810 | Ld->getChain(), NewPtr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2811 | Ld->getPointerInfo().getWithOffset(4), |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2812 | Ld->isVolatile(), Ld->isNonTemporal(), |
| 2813 | NewAlign); |
| 2814 | return; |
| 2815 | } |
| 2816 | |
| 2817 | llvm_unreachable("Unknown VFP cmp argument!"); |
| 2818 | } |
| 2819 | |
| 2820 | /// OptimizeVFPBrcond - With -enable-unsafe-fp-math, it's legal to optimize some |
| 2821 | /// f32 and even f64 comparisons to integer ones. |
| 2822 | SDValue |
| 2823 | ARMTargetLowering::OptimizeVFPBrcond(SDValue Op, SelectionDAG &DAG) const { |
| 2824 | SDValue Chain = Op.getOperand(0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2825 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get(); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2826 | SDValue LHS = Op.getOperand(2); |
| 2827 | SDValue RHS = Op.getOperand(3); |
| 2828 | SDValue Dest = Op.getOperand(4); |
| 2829 | DebugLoc dl = Op.getDebugLoc(); |
| 2830 | |
| 2831 | bool SeenZero = false; |
| 2832 | if (canChangeToInt(LHS, SeenZero, Subtarget) && |
| 2833 | canChangeToInt(RHS, SeenZero, Subtarget) && |
Evan Cheng | 60108e9 | 2010-07-15 22:07:12 +0000 | [diff] [blame] | 2834 | // If one of the operand is zero, it's safe to ignore the NaN case since |
| 2835 | // we only care about equality comparisons. |
| 2836 | (SeenZero || (DAG.isKnownNeverNaN(LHS) && DAG.isKnownNeverNaN(RHS)))) { |
Bob Wilson | 1b772f9 | 2011-03-08 01:17:16 +0000 | [diff] [blame] | 2837 | // If unsafe fp math optimization is enabled and there are no other uses of |
| 2838 | // 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] | 2839 | // to an integer comparison. |
| 2840 | if (CC == ISD::SETOEQ) |
| 2841 | CC = ISD::SETEQ; |
| 2842 | else if (CC == ISD::SETUNE) |
| 2843 | CC = ISD::SETNE; |
| 2844 | |
| 2845 | SDValue ARMcc; |
| 2846 | if (LHS.getValueType() == MVT::f32) { |
| 2847 | LHS = bitcastf32Toi32(LHS, DAG); |
| 2848 | RHS = bitcastf32Toi32(RHS, DAG); |
| 2849 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMcc, DAG, dl); |
| 2850 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| 2851 | return DAG.getNode(ARMISD::BRCOND, dl, MVT::Other, |
| 2852 | Chain, Dest, ARMcc, CCR, Cmp); |
| 2853 | } |
| 2854 | |
| 2855 | SDValue LHS1, LHS2; |
| 2856 | SDValue RHS1, RHS2; |
| 2857 | expandf64Toi32(LHS, DAG, LHS1, LHS2); |
| 2858 | expandf64Toi32(RHS, DAG, RHS1, RHS2); |
| 2859 | ARMCC::CondCodes CondCode = IntCCToARMCC(CC); |
| 2860 | ARMcc = DAG.getConstant(CondCode, MVT::i32); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 2861 | SDVTList VTList = DAG.getVTList(MVT::Other, MVT::Glue); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2862 | SDValue Ops[] = { Chain, ARMcc, LHS1, LHS2, RHS1, RHS2, Dest }; |
| 2863 | return DAG.getNode(ARMISD::BCC_i64, dl, VTList, Ops, 7); |
| 2864 | } |
| 2865 | |
| 2866 | return SDValue(); |
| 2867 | } |
| 2868 | |
| 2869 | SDValue ARMTargetLowering::LowerBR_CC(SDValue Op, SelectionDAG &DAG) const { |
| 2870 | SDValue Chain = Op.getOperand(0); |
| 2871 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get(); |
| 2872 | SDValue LHS = Op.getOperand(2); |
| 2873 | SDValue RHS = Op.getOperand(3); |
| 2874 | SDValue Dest = Op.getOperand(4); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2875 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2876 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2877 | if (LHS.getValueType() == MVT::i32) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2878 | SDValue ARMcc; |
| 2879 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMcc, DAG, dl); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2880 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2881 | return DAG.getNode(ARMISD::BRCOND, dl, MVT::Other, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2882 | Chain, Dest, ARMcc, CCR, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2883 | } |
| 2884 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2885 | assert(LHS.getValueType() == MVT::f32 || LHS.getValueType() == MVT::f64); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2886 | |
| 2887 | if (UnsafeFPMath && |
| 2888 | (CC == ISD::SETEQ || CC == ISD::SETOEQ || |
| 2889 | CC == ISD::SETNE || CC == ISD::SETUNE)) { |
| 2890 | SDValue Result = OptimizeVFPBrcond(Op, DAG); |
| 2891 | if (Result.getNode()) |
| 2892 | return Result; |
| 2893 | } |
| 2894 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2895 | ARMCC::CondCodes CondCode, CondCode2; |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 2896 | FPCCToARMCC(CC, CondCode, CondCode2); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2897 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2898 | SDValue ARMcc = DAG.getConstant(CondCode, MVT::i32); |
| 2899 | SDValue Cmp = getVFPCmp(LHS, RHS, DAG, dl); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2900 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 2901 | SDVTList VTList = DAG.getVTList(MVT::Other, MVT::Glue); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2902 | SDValue Ops[] = { Chain, Dest, ARMcc, CCR, Cmp }; |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2903 | SDValue Res = DAG.getNode(ARMISD::BRCOND, dl, VTList, Ops, 5); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2904 | if (CondCode2 != ARMCC::AL) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2905 | ARMcc = DAG.getConstant(CondCode2, MVT::i32); |
| 2906 | SDValue Ops[] = { Res, Dest, ARMcc, CCR, Res.getValue(1) }; |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2907 | Res = DAG.getNode(ARMISD::BRCOND, dl, VTList, Ops, 5); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2908 | } |
| 2909 | return Res; |
| 2910 | } |
| 2911 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2912 | SDValue ARMTargetLowering::LowerBR_JT(SDValue Op, SelectionDAG &DAG) const { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2913 | SDValue Chain = Op.getOperand(0); |
| 2914 | SDValue Table = Op.getOperand(1); |
| 2915 | SDValue Index = Op.getOperand(2); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2916 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2917 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2918 | EVT PTy = getPointerTy(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2919 | JumpTableSDNode *JT = cast<JumpTableSDNode>(Table); |
| 2920 | ARMFunctionInfo *AFI = DAG.getMachineFunction().getInfo<ARMFunctionInfo>(); |
Bob Wilson | 3eadf00 | 2009-07-14 18:44:34 +0000 | [diff] [blame] | 2921 | SDValue UId = DAG.getConstant(AFI->createJumpTableUId(), PTy); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2922 | SDValue JTI = DAG.getTargetJumpTable(JT->getIndex(), PTy); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2923 | Table = DAG.getNode(ARMISD::WrapperJT, dl, MVT::i32, JTI, UId); |
Evan Cheng | e7c329b | 2009-07-28 20:53:24 +0000 | [diff] [blame] | 2924 | Index = DAG.getNode(ISD::MUL, dl, PTy, Index, DAG.getConstant(4, PTy)); |
| 2925 | SDValue Addr = DAG.getNode(ISD::ADD, dl, PTy, Index, Table); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 2926 | if (Subtarget->isThumb2()) { |
| 2927 | // Thumb2 uses a two-level jump. That is, it jumps into the jump table |
| 2928 | // which does another jump to the destination. This also makes it easier |
| 2929 | // to translate it to TBB / TBH later. |
| 2930 | // FIXME: This might not work if the function is extremely large. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2931 | return DAG.getNode(ARMISD::BR2_JT, dl, MVT::Other, Chain, |
Evan Cheng | 5657c01 | 2009-07-29 02:18:14 +0000 | [diff] [blame] | 2932 | Addr, Op.getOperand(2), JTI, UId); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 2933 | } |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 2934 | if (getTargetMachine().getRelocationModel() == Reloc::PIC_) { |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2935 | Addr = DAG.getLoad((EVT)MVT::i32, dl, Chain, Addr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2936 | MachinePointerInfo::getJumpTable(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 2937 | false, false, 0); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 2938 | Chain = Addr.getValue(1); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2939 | Addr = DAG.getNode(ISD::ADD, dl, PTy, Addr, Table); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2940 | 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] | 2941 | } else { |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2942 | Addr = DAG.getLoad(PTy, dl, Chain, Addr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2943 | MachinePointerInfo::getJumpTable(), false, false, 0); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 2944 | Chain = Addr.getValue(1); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2945 | 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] | 2946 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2947 | } |
| 2948 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 2949 | static SDValue LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG) { |
| 2950 | DebugLoc dl = Op.getDebugLoc(); |
| 2951 | unsigned Opc; |
| 2952 | |
| 2953 | switch (Op.getOpcode()) { |
| 2954 | default: |
| 2955 | assert(0 && "Invalid opcode!"); |
| 2956 | case ISD::FP_TO_SINT: |
| 2957 | Opc = ARMISD::FTOSI; |
| 2958 | break; |
| 2959 | case ISD::FP_TO_UINT: |
| 2960 | Opc = ARMISD::FTOUI; |
| 2961 | break; |
| 2962 | } |
| 2963 | Op = DAG.getNode(Opc, dl, MVT::f32, Op.getOperand(0)); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2964 | return DAG.getNode(ISD::BITCAST, dl, MVT::i32, Op); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 2965 | } |
| 2966 | |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 2967 | static SDValue LowerVectorINT_TO_FP(SDValue Op, SelectionDAG &DAG) { |
| 2968 | EVT VT = Op.getValueType(); |
| 2969 | DebugLoc dl = Op.getDebugLoc(); |
| 2970 | |
| 2971 | EVT OperandVT = Op.getOperand(0).getValueType(); |
| 2972 | assert(OperandVT == MVT::v4i16 && "Invalid type for custom lowering!"); |
| 2973 | if (VT != MVT::v4f32) |
| 2974 | return DAG.UnrollVectorOp(Op.getNode()); |
| 2975 | |
| 2976 | unsigned CastOpc; |
| 2977 | unsigned Opc; |
| 2978 | switch (Op.getOpcode()) { |
| 2979 | default: |
| 2980 | assert(0 && "Invalid opcode!"); |
| 2981 | case ISD::SINT_TO_FP: |
| 2982 | CastOpc = ISD::SIGN_EXTEND; |
| 2983 | Opc = ISD::SINT_TO_FP; |
| 2984 | break; |
| 2985 | case ISD::UINT_TO_FP: |
| 2986 | CastOpc = ISD::ZERO_EXTEND; |
| 2987 | Opc = ISD::UINT_TO_FP; |
| 2988 | break; |
| 2989 | } |
| 2990 | |
| 2991 | Op = DAG.getNode(CastOpc, dl, MVT::v4i32, Op.getOperand(0)); |
| 2992 | return DAG.getNode(Opc, dl, VT, Op); |
| 2993 | } |
| 2994 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 2995 | static SDValue LowerINT_TO_FP(SDValue Op, SelectionDAG &DAG) { |
| 2996 | EVT VT = Op.getValueType(); |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 2997 | if (VT.isVector()) |
| 2998 | return LowerVectorINT_TO_FP(Op, DAG); |
| 2999 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3000 | DebugLoc dl = Op.getDebugLoc(); |
| 3001 | unsigned Opc; |
| 3002 | |
| 3003 | switch (Op.getOpcode()) { |
| 3004 | default: |
| 3005 | assert(0 && "Invalid opcode!"); |
| 3006 | case ISD::SINT_TO_FP: |
| 3007 | Opc = ARMISD::SITOF; |
| 3008 | break; |
| 3009 | case ISD::UINT_TO_FP: |
| 3010 | Opc = ARMISD::UITOF; |
| 3011 | break; |
| 3012 | } |
| 3013 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3014 | Op = DAG.getNode(ISD::BITCAST, dl, MVT::f32, Op.getOperand(0)); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3015 | return DAG.getNode(Opc, dl, VT, Op); |
| 3016 | } |
| 3017 | |
Evan Cheng | 515fe3a | 2010-07-08 02:08:50 +0000 | [diff] [blame] | 3018 | SDValue ARMTargetLowering::LowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3019 | // Implement fcopysign with a fabs and a conditional fneg. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3020 | SDValue Tmp0 = Op.getOperand(0); |
| 3021 | SDValue Tmp1 = Op.getOperand(1); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 3022 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3023 | EVT VT = Op.getValueType(); |
| 3024 | EVT SrcVT = Tmp1.getValueType(); |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3025 | bool InGPR = Tmp0.getOpcode() == ISD::BITCAST || |
| 3026 | Tmp0.getOpcode() == ARMISD::VMOVDRR; |
| 3027 | bool UseNEON = !InGPR && Subtarget->hasNEON(); |
| 3028 | |
| 3029 | if (UseNEON) { |
| 3030 | // Use VBSL to copy the sign bit. |
| 3031 | unsigned EncodedVal = ARM_AM::createNEONModImm(0x6, 0x80); |
| 3032 | SDValue Mask = DAG.getNode(ARMISD::VMOVIMM, dl, MVT::v2i32, |
| 3033 | DAG.getTargetConstant(EncodedVal, MVT::i32)); |
| 3034 | EVT OpVT = (VT == MVT::f32) ? MVT::v2i32 : MVT::v1i64; |
| 3035 | if (VT == MVT::f64) |
| 3036 | Mask = DAG.getNode(ARMISD::VSHL, dl, OpVT, |
| 3037 | DAG.getNode(ISD::BITCAST, dl, OpVT, Mask), |
| 3038 | DAG.getConstant(32, MVT::i32)); |
| 3039 | else /*if (VT == MVT::f32)*/ |
| 3040 | Tmp0 = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, MVT::v2f32, Tmp0); |
| 3041 | if (SrcVT == MVT::f32) { |
| 3042 | Tmp1 = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, MVT::v2f32, Tmp1); |
| 3043 | if (VT == MVT::f64) |
| 3044 | Tmp1 = DAG.getNode(ARMISD::VSHL, dl, OpVT, |
| 3045 | DAG.getNode(ISD::BITCAST, dl, OpVT, Tmp1), |
| 3046 | DAG.getConstant(32, MVT::i32)); |
Evan Cheng | 9eec66e | 2011-04-15 01:31:00 +0000 | [diff] [blame] | 3047 | } else if (VT == MVT::f32) |
| 3048 | Tmp1 = DAG.getNode(ARMISD::VSHRu, dl, MVT::v1i64, |
| 3049 | DAG.getNode(ISD::BITCAST, dl, MVT::v1i64, Tmp1), |
| 3050 | DAG.getConstant(32, MVT::i32)); |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3051 | Tmp0 = DAG.getNode(ISD::BITCAST, dl, OpVT, Tmp0); |
| 3052 | Tmp1 = DAG.getNode(ISD::BITCAST, dl, OpVT, Tmp1); |
| 3053 | |
| 3054 | SDValue AllOnes = DAG.getTargetConstant(ARM_AM::createNEONModImm(0xe, 0xff), |
| 3055 | MVT::i32); |
| 3056 | AllOnes = DAG.getNode(ARMISD::VMOVIMM, dl, MVT::v8i8, AllOnes); |
| 3057 | SDValue MaskNot = DAG.getNode(ISD::XOR, dl, OpVT, Mask, |
| 3058 | DAG.getNode(ISD::BITCAST, dl, OpVT, AllOnes)); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 3059 | |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3060 | SDValue Res = DAG.getNode(ISD::OR, dl, OpVT, |
| 3061 | DAG.getNode(ISD::AND, dl, OpVT, Tmp1, Mask), |
| 3062 | DAG.getNode(ISD::AND, dl, OpVT, Tmp0, MaskNot)); |
Evan Cheng | c24ab5c | 2011-02-28 18:45:27 +0000 | [diff] [blame] | 3063 | if (VT == MVT::f32) { |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3064 | Res = DAG.getNode(ISD::BITCAST, dl, MVT::v2f32, Res); |
| 3065 | Res = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f32, Res, |
| 3066 | DAG.getConstant(0, MVT::i32)); |
| 3067 | } else { |
| 3068 | Res = DAG.getNode(ISD::BITCAST, dl, MVT::f64, Res); |
| 3069 | } |
| 3070 | |
| 3071 | return Res; |
| 3072 | } |
Evan Cheng | c143dd4 | 2011-02-11 02:28:55 +0000 | [diff] [blame] | 3073 | |
| 3074 | // Bitcast operand 1 to i32. |
| 3075 | if (SrcVT == MVT::f64) |
| 3076 | Tmp1 = DAG.getNode(ARMISD::VMOVRRD, dl, DAG.getVTList(MVT::i32, MVT::i32), |
| 3077 | &Tmp1, 1).getValue(1); |
| 3078 | Tmp1 = DAG.getNode(ISD::BITCAST, dl, MVT::i32, Tmp1); |
| 3079 | |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3080 | // Or in the signbit with integer operations. |
| 3081 | SDValue Mask1 = DAG.getConstant(0x80000000, MVT::i32); |
| 3082 | SDValue Mask2 = DAG.getConstant(0x7fffffff, MVT::i32); |
| 3083 | Tmp1 = DAG.getNode(ISD::AND, dl, MVT::i32, Tmp1, Mask1); |
| 3084 | if (VT == MVT::f32) { |
| 3085 | Tmp0 = DAG.getNode(ISD::AND, dl, MVT::i32, |
| 3086 | DAG.getNode(ISD::BITCAST, dl, MVT::i32, Tmp0), Mask2); |
| 3087 | return DAG.getNode(ISD::BITCAST, dl, MVT::f32, |
| 3088 | DAG.getNode(ISD::OR, dl, MVT::i32, Tmp0, Tmp1)); |
Evan Cheng | c143dd4 | 2011-02-11 02:28:55 +0000 | [diff] [blame] | 3089 | } |
| 3090 | |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3091 | // f64: Or the high part with signbit and then combine two parts. |
| 3092 | Tmp0 = DAG.getNode(ARMISD::VMOVRRD, dl, DAG.getVTList(MVT::i32, MVT::i32), |
| 3093 | &Tmp0, 1); |
| 3094 | SDValue Lo = Tmp0.getValue(0); |
| 3095 | SDValue Hi = DAG.getNode(ISD::AND, dl, MVT::i32, Tmp0.getValue(1), Mask2); |
| 3096 | Hi = DAG.getNode(ISD::OR, dl, MVT::i32, Hi, Tmp1); |
| 3097 | return DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3098 | } |
| 3099 | |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3100 | SDValue ARMTargetLowering::LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const{ |
| 3101 | MachineFunction &MF = DAG.getMachineFunction(); |
| 3102 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 3103 | MFI->setReturnAddressIsTaken(true); |
| 3104 | |
| 3105 | EVT VT = Op.getValueType(); |
| 3106 | DebugLoc dl = Op.getDebugLoc(); |
| 3107 | unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
| 3108 | if (Depth) { |
| 3109 | SDValue FrameAddr = LowerFRAMEADDR(Op, DAG); |
| 3110 | SDValue Offset = DAG.getConstant(4, MVT::i32); |
| 3111 | return DAG.getLoad(VT, dl, DAG.getEntryNode(), |
| 3112 | DAG.getNode(ISD::ADD, dl, VT, FrameAddr, Offset), |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 3113 | MachinePointerInfo(), false, false, 0); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3114 | } |
| 3115 | |
| 3116 | // 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] | 3117 | unsigned Reg = MF.addLiveIn(ARM::LR, getRegClassFor(MVT::i32)); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3118 | return DAG.getCopyFromReg(DAG.getEntryNode(), dl, Reg, VT); |
| 3119 | } |
| 3120 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 3121 | SDValue ARMTargetLowering::LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const { |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3122 | MachineFrameInfo *MFI = DAG.getMachineFunction().getFrameInfo(); |
| 3123 | MFI->setFrameAddressIsTaken(true); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3124 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3125 | EVT VT = Op.getValueType(); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3126 | DebugLoc dl = Op.getDebugLoc(); // FIXME probably not meaningful |
| 3127 | unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
Evan Cheng | cd82861 | 2009-06-18 23:14:30 +0000 | [diff] [blame] | 3128 | unsigned FrameReg = (Subtarget->isThumb() || Subtarget->isTargetDarwin()) |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3129 | ? ARM::R7 : ARM::R11; |
| 3130 | SDValue FrameAddr = DAG.getCopyFromReg(DAG.getEntryNode(), dl, FrameReg, VT); |
| 3131 | while (Depth--) |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 3132 | FrameAddr = DAG.getLoad(VT, dl, DAG.getEntryNode(), FrameAddr, |
| 3133 | MachinePointerInfo(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 3134 | false, false, 0); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3135 | return FrameAddr; |
| 3136 | } |
| 3137 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3138 | /// ExpandBITCAST - If the target supports VFP, this function is called to |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3139 | /// expand a bit convert where either the source or destination type is i64 to |
| 3140 | /// use a VMOVDRR or VMOVRRD node. This should not be done when the non-i64 |
| 3141 | /// operand type is illegal (e.g., v2f32 for a target that doesn't support |
| 3142 | /// vectors), since the legalizer won't know what to do with that. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3143 | static SDValue ExpandBITCAST(SDNode *N, SelectionDAG &DAG) { |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3144 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 3145 | DebugLoc dl = N->getDebugLoc(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3146 | SDValue Op = N->getOperand(0); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 3147 | |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3148 | // This function is only supposed to be called for i64 types, either as the |
| 3149 | // source or destination of the bit convert. |
| 3150 | EVT SrcVT = Op.getValueType(); |
| 3151 | EVT DstVT = N->getValueType(0); |
| 3152 | assert((SrcVT == MVT::i64 || DstVT == MVT::i64) && |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3153 | "ExpandBITCAST called for non-i64 type"); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 3154 | |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3155 | // Turn i64->f64 into VMOVDRR. |
| 3156 | if (SrcVT == MVT::i64 && TLI.isTypeLegal(DstVT)) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3157 | SDValue Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Op, |
| 3158 | DAG.getConstant(0, MVT::i32)); |
| 3159 | SDValue Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Op, |
| 3160 | DAG.getConstant(1, MVT::i32)); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3161 | return DAG.getNode(ISD::BITCAST, dl, DstVT, |
Bob Wilson | 1114f56 | 2010-06-11 22:45:25 +0000 | [diff] [blame] | 3162 | DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi)); |
Evan Cheng | c7c7729 | 2008-11-04 19:57:48 +0000 | [diff] [blame] | 3163 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3164 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 3165 | // Turn f64->i64 into VMOVRRD. |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3166 | if (DstVT == MVT::i64 && TLI.isTypeLegal(SrcVT)) { |
| 3167 | SDValue Cvt = DAG.getNode(ARMISD::VMOVRRD, dl, |
| 3168 | DAG.getVTList(MVT::i32, MVT::i32), &Op, 1); |
| 3169 | // Merge the pieces into a single i64 value. |
| 3170 | return DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Cvt, Cvt.getValue(1)); |
| 3171 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3172 | |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3173 | return SDValue(); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3174 | } |
| 3175 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3176 | /// getZeroVector - Returns a vector of specified type with all zero elements. |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3177 | /// Zero vectors are used to represent vector negation and in those cases |
| 3178 | /// will be implemented with the NEON VNEG instruction. However, VNEG does |
| 3179 | /// not support i64 elements, so sometimes the zero vectors will need to be |
| 3180 | /// explicitly constructed. Regardless, use a canonical VMOV to create the |
| 3181 | /// zero vector. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3182 | static SDValue getZeroVector(EVT VT, SelectionDAG &DAG, DebugLoc dl) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3183 | assert(VT.isVector() && "Expected a vector type"); |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3184 | // The canonical modified immediate encoding of a zero vector is....0! |
| 3185 | SDValue EncodedVal = DAG.getTargetConstant(0, MVT::i32); |
| 3186 | EVT VmovVT = VT.is128BitVector() ? MVT::v4i32 : MVT::v2i32; |
| 3187 | SDValue Vmov = DAG.getNode(ARMISD::VMOVIMM, dl, VmovVT, EncodedVal); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3188 | return DAG.getNode(ISD::BITCAST, dl, VT, Vmov); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3189 | } |
| 3190 | |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3191 | /// LowerShiftRightParts - Lower SRA_PARTS, which returns two |
| 3192 | /// 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] | 3193 | SDValue ARMTargetLowering::LowerShiftRightParts(SDValue Op, |
| 3194 | SelectionDAG &DAG) const { |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3195 | assert(Op.getNumOperands() == 3 && "Not a double-shift!"); |
| 3196 | EVT VT = Op.getValueType(); |
| 3197 | unsigned VTBits = VT.getSizeInBits(); |
| 3198 | DebugLoc dl = Op.getDebugLoc(); |
| 3199 | SDValue ShOpLo = Op.getOperand(0); |
| 3200 | SDValue ShOpHi = Op.getOperand(1); |
| 3201 | SDValue ShAmt = Op.getOperand(2); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3202 | SDValue ARMcc; |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 3203 | unsigned Opc = (Op.getOpcode() == ISD::SRA_PARTS) ? ISD::SRA : ISD::SRL; |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3204 | |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 3205 | assert(Op.getOpcode() == ISD::SRA_PARTS || Op.getOpcode() == ISD::SRL_PARTS); |
| 3206 | |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3207 | SDValue RevShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, |
| 3208 | DAG.getConstant(VTBits, MVT::i32), ShAmt); |
| 3209 | SDValue Tmp1 = DAG.getNode(ISD::SRL, dl, VT, ShOpLo, ShAmt); |
| 3210 | SDValue ExtraShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, ShAmt, |
| 3211 | DAG.getConstant(VTBits, MVT::i32)); |
| 3212 | SDValue Tmp2 = DAG.getNode(ISD::SHL, dl, VT, ShOpHi, RevShAmt); |
| 3213 | SDValue FalseVal = DAG.getNode(ISD::OR, dl, VT, Tmp1, Tmp2); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 3214 | SDValue TrueVal = DAG.getNode(Opc, dl, VT, ShOpHi, ExtraShAmt); |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3215 | |
| 3216 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| 3217 | SDValue Cmp = getARMCmp(ExtraShAmt, DAG.getConstant(0, MVT::i32), ISD::SETGE, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3218 | ARMcc, DAG, dl); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 3219 | SDValue Hi = DAG.getNode(Opc, dl, VT, ShOpHi, ShAmt); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3220 | SDValue Lo = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, ARMcc, |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3221 | CCR, Cmp); |
| 3222 | |
| 3223 | SDValue Ops[2] = { Lo, Hi }; |
| 3224 | return DAG.getMergeValues(Ops, 2, dl); |
| 3225 | } |
| 3226 | |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3227 | /// LowerShiftLeftParts - Lower SHL_PARTS, which returns two |
| 3228 | /// 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] | 3229 | SDValue ARMTargetLowering::LowerShiftLeftParts(SDValue Op, |
| 3230 | SelectionDAG &DAG) const { |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3231 | assert(Op.getNumOperands() == 3 && "Not a double-shift!"); |
| 3232 | EVT VT = Op.getValueType(); |
| 3233 | unsigned VTBits = VT.getSizeInBits(); |
| 3234 | DebugLoc dl = Op.getDebugLoc(); |
| 3235 | SDValue ShOpLo = Op.getOperand(0); |
| 3236 | SDValue ShOpHi = Op.getOperand(1); |
| 3237 | SDValue ShAmt = Op.getOperand(2); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3238 | SDValue ARMcc; |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3239 | |
| 3240 | assert(Op.getOpcode() == ISD::SHL_PARTS); |
| 3241 | SDValue RevShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, |
| 3242 | DAG.getConstant(VTBits, MVT::i32), ShAmt); |
| 3243 | SDValue Tmp1 = DAG.getNode(ISD::SRL, dl, VT, ShOpLo, RevShAmt); |
| 3244 | SDValue ExtraShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, ShAmt, |
| 3245 | DAG.getConstant(VTBits, MVT::i32)); |
| 3246 | SDValue Tmp2 = DAG.getNode(ISD::SHL, dl, VT, ShOpHi, ShAmt); |
| 3247 | SDValue Tmp3 = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ExtraShAmt); |
| 3248 | |
| 3249 | SDValue FalseVal = DAG.getNode(ISD::OR, dl, VT, Tmp1, Tmp2); |
| 3250 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| 3251 | SDValue Cmp = getARMCmp(ExtraShAmt, DAG.getConstant(0, MVT::i32), ISD::SETGE, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3252 | ARMcc, DAG, dl); |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3253 | SDValue Lo = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ShAmt); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3254 | SDValue Hi = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, Tmp3, ARMcc, |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3255 | CCR, Cmp); |
| 3256 | |
| 3257 | SDValue Ops[2] = { Lo, Hi }; |
| 3258 | return DAG.getMergeValues(Ops, 2, dl); |
| 3259 | } |
| 3260 | |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 3261 | SDValue ARMTargetLowering::LowerFLT_ROUNDS_(SDValue Op, |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 3262 | SelectionDAG &DAG) const { |
| 3263 | // The rounding mode is in bits 23:22 of the FPSCR. |
| 3264 | // The ARM rounding mode value to FLT_ROUNDS mapping is 0->1, 1->2, 2->3, 3->0 |
| 3265 | // The formula we use to implement this is (((FPSCR + 1 << 22) >> 22) & 3) |
| 3266 | // so that the shift + and get folded into a bitfield extract. |
| 3267 | DebugLoc dl = Op.getDebugLoc(); |
| 3268 | SDValue FPSCR = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::i32, |
| 3269 | DAG.getConstant(Intrinsic::arm_get_fpscr, |
| 3270 | MVT::i32)); |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 3271 | SDValue FltRounds = DAG.getNode(ISD::ADD, dl, MVT::i32, FPSCR, |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 3272 | DAG.getConstant(1U << 22, MVT::i32)); |
| 3273 | SDValue RMODE = DAG.getNode(ISD::SRL, dl, MVT::i32, FltRounds, |
| 3274 | DAG.getConstant(22, MVT::i32)); |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 3275 | return DAG.getNode(ISD::AND, dl, MVT::i32, RMODE, |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 3276 | DAG.getConstant(3, MVT::i32)); |
| 3277 | } |
| 3278 | |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 3279 | static SDValue LowerCTTZ(SDNode *N, SelectionDAG &DAG, |
| 3280 | const ARMSubtarget *ST) { |
| 3281 | EVT VT = N->getValueType(0); |
| 3282 | DebugLoc dl = N->getDebugLoc(); |
| 3283 | |
| 3284 | if (!ST->hasV6T2Ops()) |
| 3285 | return SDValue(); |
| 3286 | |
| 3287 | SDValue rbit = DAG.getNode(ARMISD::RBIT, dl, VT, N->getOperand(0)); |
| 3288 | return DAG.getNode(ISD::CTLZ, dl, VT, rbit); |
| 3289 | } |
| 3290 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3291 | static SDValue LowerShift(SDNode *N, SelectionDAG &DAG, |
| 3292 | const ARMSubtarget *ST) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3293 | EVT VT = N->getValueType(0); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3294 | DebugLoc dl = N->getDebugLoc(); |
| 3295 | |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3296 | if (!VT.isVector()) |
| 3297 | return SDValue(); |
| 3298 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3299 | // Lower vector shifts on NEON to use VSHL. |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3300 | assert(ST->hasNEON() && "unexpected vector shift"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3301 | |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3302 | // Left shifts translate directly to the vshiftu intrinsic. |
| 3303 | if (N->getOpcode() == ISD::SHL) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3304 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT, |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3305 | DAG.getConstant(Intrinsic::arm_neon_vshiftu, MVT::i32), |
| 3306 | N->getOperand(0), N->getOperand(1)); |
| 3307 | |
| 3308 | assert((N->getOpcode() == ISD::SRA || |
| 3309 | N->getOpcode() == ISD::SRL) && "unexpected vector shift opcode"); |
| 3310 | |
| 3311 | // NEON uses the same intrinsics for both left and right shifts. For |
| 3312 | // right shifts, the shift amounts are negative, so negate the vector of |
| 3313 | // shift amounts. |
| 3314 | EVT ShiftVT = N->getOperand(1).getValueType(); |
| 3315 | SDValue NegatedCount = DAG.getNode(ISD::SUB, dl, ShiftVT, |
| 3316 | getZeroVector(ShiftVT, DAG, dl), |
| 3317 | N->getOperand(1)); |
| 3318 | Intrinsic::ID vshiftInt = (N->getOpcode() == ISD::SRA ? |
| 3319 | Intrinsic::arm_neon_vshifts : |
| 3320 | Intrinsic::arm_neon_vshiftu); |
| 3321 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT, |
| 3322 | DAG.getConstant(vshiftInt, MVT::i32), |
| 3323 | N->getOperand(0), NegatedCount); |
| 3324 | } |
| 3325 | |
| 3326 | static SDValue Expand64BitShift(SDNode *N, SelectionDAG &DAG, |
| 3327 | const ARMSubtarget *ST) { |
| 3328 | EVT VT = N->getValueType(0); |
| 3329 | DebugLoc dl = N->getDebugLoc(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3330 | |
Eli Friedman | ce392eb | 2009-08-22 03:13:10 +0000 | [diff] [blame] | 3331 | // We can get here for a node like i32 = ISD::SHL i32, i64 |
| 3332 | if (VT != MVT::i64) |
| 3333 | return SDValue(); |
| 3334 | |
| 3335 | assert((N->getOpcode() == ISD::SRL || N->getOpcode() == ISD::SRA) && |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3336 | "Unknown shift to lower!"); |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 3337 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3338 | // We only lower SRA, SRL of 1 here, all others use generic lowering. |
| 3339 | if (!isa<ConstantSDNode>(N->getOperand(1)) || |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 3340 | cast<ConstantSDNode>(N->getOperand(1))->getZExtValue() != 1) |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 3341 | return SDValue(); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3342 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3343 | // If we are in thumb mode, we don't have RRX. |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 3344 | if (ST->isThumb1Only()) return SDValue(); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3345 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3346 | // 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] | 3347 | 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] | 3348 | DAG.getConstant(0, MVT::i32)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3349 | 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] | 3350 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3351 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3352 | // First, build a SRA_FLAG/SRL_FLAG op, which shifts the top part by one and |
| 3353 | // captures the result into a carry flag. |
| 3354 | unsigned Opc = N->getOpcode() == ISD::SRL ? ARMISD::SRL_FLAG:ARMISD::SRA_FLAG; |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 3355 | 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] | 3356 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3357 | // 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] | 3358 | Lo = DAG.getNode(ARMISD::RRX, dl, MVT::i32, Lo, Hi.getValue(1)); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3359 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3360 | // Merge the pieces into a single i64 value. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3361 | return DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Lo, Hi); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3362 | } |
| 3363 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3364 | static SDValue LowerVSETCC(SDValue Op, SelectionDAG &DAG) { |
| 3365 | SDValue TmpOp0, TmpOp1; |
| 3366 | bool Invert = false; |
| 3367 | bool Swap = false; |
| 3368 | unsigned Opc = 0; |
| 3369 | |
| 3370 | SDValue Op0 = Op.getOperand(0); |
| 3371 | SDValue Op1 = Op.getOperand(1); |
| 3372 | SDValue CC = Op.getOperand(2); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3373 | EVT VT = Op.getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3374 | ISD::CondCode SetCCOpcode = cast<CondCodeSDNode>(CC)->get(); |
| 3375 | DebugLoc dl = Op.getDebugLoc(); |
| 3376 | |
| 3377 | if (Op.getOperand(1).getValueType().isFloatingPoint()) { |
| 3378 | switch (SetCCOpcode) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 3379 | default: llvm_unreachable("Illegal FP comparison"); break; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3380 | case ISD::SETUNE: |
| 3381 | case ISD::SETNE: Invert = true; // Fallthrough |
| 3382 | case ISD::SETOEQ: |
| 3383 | case ISD::SETEQ: Opc = ARMISD::VCEQ; break; |
| 3384 | case ISD::SETOLT: |
| 3385 | case ISD::SETLT: Swap = true; // Fallthrough |
| 3386 | case ISD::SETOGT: |
| 3387 | case ISD::SETGT: Opc = ARMISD::VCGT; break; |
| 3388 | case ISD::SETOLE: |
| 3389 | case ISD::SETLE: Swap = true; // Fallthrough |
| 3390 | case ISD::SETOGE: |
| 3391 | case ISD::SETGE: Opc = ARMISD::VCGE; break; |
| 3392 | case ISD::SETUGE: Swap = true; // Fallthrough |
| 3393 | case ISD::SETULE: Invert = true; Opc = ARMISD::VCGT; break; |
| 3394 | case ISD::SETUGT: Swap = true; // Fallthrough |
| 3395 | case ISD::SETULT: Invert = true; Opc = ARMISD::VCGE; break; |
| 3396 | case ISD::SETUEQ: Invert = true; // Fallthrough |
| 3397 | case ISD::SETONE: |
| 3398 | // Expand this to (OLT | OGT). |
| 3399 | TmpOp0 = Op0; |
| 3400 | TmpOp1 = Op1; |
| 3401 | Opc = ISD::OR; |
| 3402 | Op0 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp1, TmpOp0); |
| 3403 | Op1 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp0, TmpOp1); |
| 3404 | break; |
| 3405 | case ISD::SETUO: Invert = true; // Fallthrough |
| 3406 | case ISD::SETO: |
| 3407 | // Expand this to (OLT | OGE). |
| 3408 | TmpOp0 = Op0; |
| 3409 | TmpOp1 = Op1; |
| 3410 | Opc = ISD::OR; |
| 3411 | Op0 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp1, TmpOp0); |
| 3412 | Op1 = DAG.getNode(ARMISD::VCGE, dl, VT, TmpOp0, TmpOp1); |
| 3413 | break; |
| 3414 | } |
| 3415 | } else { |
| 3416 | // Integer comparisons. |
| 3417 | switch (SetCCOpcode) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 3418 | default: llvm_unreachable("Illegal integer comparison"); break; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3419 | case ISD::SETNE: Invert = true; |
| 3420 | case ISD::SETEQ: Opc = ARMISD::VCEQ; break; |
| 3421 | case ISD::SETLT: Swap = true; |
| 3422 | case ISD::SETGT: Opc = ARMISD::VCGT; break; |
| 3423 | case ISD::SETLE: Swap = true; |
| 3424 | case ISD::SETGE: Opc = ARMISD::VCGE; break; |
| 3425 | case ISD::SETULT: Swap = true; |
| 3426 | case ISD::SETUGT: Opc = ARMISD::VCGTU; break; |
| 3427 | case ISD::SETULE: Swap = true; |
| 3428 | case ISD::SETUGE: Opc = ARMISD::VCGEU; break; |
| 3429 | } |
| 3430 | |
Nick Lewycky | 7f6aa2b | 2009-07-08 03:04:38 +0000 | [diff] [blame] | 3431 | // Detect VTST (Vector Test Bits) = icmp ne (and (op0, op1), zero). |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3432 | if (Opc == ARMISD::VCEQ) { |
| 3433 | |
| 3434 | SDValue AndOp; |
| 3435 | if (ISD::isBuildVectorAllZeros(Op1.getNode())) |
| 3436 | AndOp = Op0; |
| 3437 | else if (ISD::isBuildVectorAllZeros(Op0.getNode())) |
| 3438 | AndOp = Op1; |
| 3439 | |
| 3440 | // Ignore bitconvert. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3441 | if (AndOp.getNode() && AndOp.getOpcode() == ISD::BITCAST) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3442 | AndOp = AndOp.getOperand(0); |
| 3443 | |
| 3444 | if (AndOp.getNode() && AndOp.getOpcode() == ISD::AND) { |
| 3445 | Opc = ARMISD::VTST; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3446 | Op0 = DAG.getNode(ISD::BITCAST, dl, VT, AndOp.getOperand(0)); |
| 3447 | Op1 = DAG.getNode(ISD::BITCAST, dl, VT, AndOp.getOperand(1)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3448 | Invert = !Invert; |
| 3449 | } |
| 3450 | } |
| 3451 | } |
| 3452 | |
| 3453 | if (Swap) |
| 3454 | std::swap(Op0, Op1); |
| 3455 | |
Owen Anderson | c24cb35 | 2010-11-08 23:21:22 +0000 | [diff] [blame] | 3456 | // If one of the operands is a constant vector zero, attempt to fold the |
| 3457 | // comparison to a specialized compare-against-zero form. |
| 3458 | SDValue SingleOp; |
| 3459 | if (ISD::isBuildVectorAllZeros(Op1.getNode())) |
| 3460 | SingleOp = Op0; |
| 3461 | else if (ISD::isBuildVectorAllZeros(Op0.getNode())) { |
| 3462 | if (Opc == ARMISD::VCGE) |
| 3463 | Opc = ARMISD::VCLEZ; |
| 3464 | else if (Opc == ARMISD::VCGT) |
| 3465 | Opc = ARMISD::VCLTZ; |
| 3466 | SingleOp = Op1; |
| 3467 | } |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3468 | |
Owen Anderson | c24cb35 | 2010-11-08 23:21:22 +0000 | [diff] [blame] | 3469 | SDValue Result; |
| 3470 | if (SingleOp.getNode()) { |
| 3471 | switch (Opc) { |
| 3472 | case ARMISD::VCEQ: |
| 3473 | Result = DAG.getNode(ARMISD::VCEQZ, dl, VT, SingleOp); break; |
| 3474 | case ARMISD::VCGE: |
| 3475 | Result = DAG.getNode(ARMISD::VCGEZ, dl, VT, SingleOp); break; |
| 3476 | case ARMISD::VCLEZ: |
| 3477 | Result = DAG.getNode(ARMISD::VCLEZ, dl, VT, SingleOp); break; |
| 3478 | case ARMISD::VCGT: |
| 3479 | Result = DAG.getNode(ARMISD::VCGTZ, dl, VT, SingleOp); break; |
| 3480 | case ARMISD::VCLTZ: |
| 3481 | Result = DAG.getNode(ARMISD::VCLTZ, dl, VT, SingleOp); break; |
| 3482 | default: |
| 3483 | Result = DAG.getNode(Opc, dl, VT, Op0, Op1); |
| 3484 | } |
| 3485 | } else { |
| 3486 | Result = DAG.getNode(Opc, dl, VT, Op0, Op1); |
| 3487 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3488 | |
| 3489 | if (Invert) |
| 3490 | Result = DAG.getNOT(dl, Result, VT); |
| 3491 | |
| 3492 | return Result; |
| 3493 | } |
| 3494 | |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 3495 | /// isNEONModifiedImm - Check if the specified splat value corresponds to a |
| 3496 | /// valid vector constant for a NEON instruction with a "modified immediate" |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3497 | /// operand (e.g., VMOV). If so, return the encoded value. |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 3498 | static SDValue isNEONModifiedImm(uint64_t SplatBits, uint64_t SplatUndef, |
| 3499 | unsigned SplatBitSize, SelectionDAG &DAG, |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3500 | EVT &VT, bool is128Bits, NEONModImmType type) { |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3501 | unsigned OpCmode, Imm; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3502 | |
Bob Wilson | 827b210 | 2010-06-15 19:05:35 +0000 | [diff] [blame] | 3503 | // SplatBitSize is set to the smallest size that splats the vector, so a |
| 3504 | // zero vector will always have SplatBitSize == 8. However, NEON modified |
| 3505 | // immediate instructions others than VMOV do not support the 8-bit encoding |
| 3506 | // of a zero vector, and the default encoding of zero is supposed to be the |
| 3507 | // 32-bit version. |
| 3508 | if (SplatBits == 0) |
| 3509 | SplatBitSize = 32; |
| 3510 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3511 | switch (SplatBitSize) { |
| 3512 | case 8: |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3513 | if (type != VMOVModImm) |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 3514 | return SDValue(); |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3515 | // Any 1-byte value is OK. Op=0, Cmode=1110. |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3516 | assert((SplatBits & ~0xff) == 0 && "one byte splat value is too big"); |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3517 | OpCmode = 0xe; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3518 | Imm = SplatBits; |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3519 | VT = is128Bits ? MVT::v16i8 : MVT::v8i8; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3520 | break; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3521 | |
| 3522 | case 16: |
| 3523 | // 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] | 3524 | VT = is128Bits ? MVT::v8i16 : MVT::v4i16; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3525 | if ((SplatBits & ~0xff) == 0) { |
| 3526 | // Value = 0x00nn: Op=x, Cmode=100x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3527 | OpCmode = 0x8; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3528 | Imm = SplatBits; |
| 3529 | break; |
| 3530 | } |
| 3531 | if ((SplatBits & ~0xff00) == 0) { |
| 3532 | // Value = 0xnn00: Op=x, Cmode=101x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3533 | OpCmode = 0xa; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3534 | Imm = SplatBits >> 8; |
| 3535 | break; |
| 3536 | } |
| 3537 | return SDValue(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3538 | |
| 3539 | case 32: |
| 3540 | // NEON's 32-bit VMOV supports splat values where: |
| 3541 | // * only one byte is nonzero, or |
| 3542 | // * the least significant byte is 0xff and the second byte is nonzero, or |
| 3543 | // * the least significant 2 bytes are 0xff and the third is nonzero. |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3544 | VT = is128Bits ? MVT::v4i32 : MVT::v2i32; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3545 | if ((SplatBits & ~0xff) == 0) { |
| 3546 | // Value = 0x000000nn: Op=x, Cmode=000x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3547 | OpCmode = 0; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3548 | Imm = SplatBits; |
| 3549 | break; |
| 3550 | } |
| 3551 | if ((SplatBits & ~0xff00) == 0) { |
| 3552 | // Value = 0x0000nn00: Op=x, Cmode=001x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3553 | OpCmode = 0x2; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3554 | Imm = SplatBits >> 8; |
| 3555 | break; |
| 3556 | } |
| 3557 | if ((SplatBits & ~0xff0000) == 0) { |
| 3558 | // Value = 0x00nn0000: Op=x, Cmode=010x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3559 | OpCmode = 0x4; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3560 | Imm = SplatBits >> 16; |
| 3561 | break; |
| 3562 | } |
| 3563 | if ((SplatBits & ~0xff000000) == 0) { |
| 3564 | // Value = 0xnn000000: Op=x, Cmode=011x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3565 | OpCmode = 0x6; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3566 | Imm = SplatBits >> 24; |
| 3567 | break; |
| 3568 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3569 | |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3570 | // cmode == 0b1100 and cmode == 0b1101 are not supported for VORR or VBIC |
| 3571 | if (type == OtherModImm) return SDValue(); |
| 3572 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3573 | if ((SplatBits & ~0xffff) == 0 && |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3574 | ((SplatBits | SplatUndef) & 0xff) == 0xff) { |
| 3575 | // Value = 0x0000nnff: Op=x, Cmode=1100. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3576 | OpCmode = 0xc; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3577 | Imm = SplatBits >> 8; |
| 3578 | SplatBits |= 0xff; |
| 3579 | break; |
| 3580 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3581 | |
| 3582 | if ((SplatBits & ~0xffffff) == 0 && |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3583 | ((SplatBits | SplatUndef) & 0xffff) == 0xffff) { |
| 3584 | // Value = 0x00nnffff: Op=x, Cmode=1101. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3585 | OpCmode = 0xd; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3586 | Imm = SplatBits >> 16; |
| 3587 | SplatBits |= 0xffff; |
| 3588 | break; |
| 3589 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3590 | |
| 3591 | // Note: there are a few 32-bit splat values (specifically: 00ffff00, |
| 3592 | // ff000000, ff0000ff, and ffff00ff) that are valid for VMOV.I64 but not |
| 3593 | // VMOV.I32. A (very) minor optimization would be to replicate the value |
| 3594 | // and fall through here to test for a valid 64-bit splat. But, then the |
| 3595 | // caller would also need to check and handle the change in size. |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3596 | return SDValue(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3597 | |
| 3598 | case 64: { |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3599 | if (type != VMOVModImm) |
Bob Wilson | 827b210 | 2010-06-15 19:05:35 +0000 | [diff] [blame] | 3600 | return SDValue(); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 3601 | // 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] | 3602 | uint64_t BitMask = 0xff; |
| 3603 | uint64_t Val = 0; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3604 | unsigned ImmMask = 1; |
| 3605 | Imm = 0; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3606 | for (int ByteNum = 0; ByteNum < 8; ++ByteNum) { |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3607 | if (((SplatBits | SplatUndef) & BitMask) == BitMask) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3608 | Val |= BitMask; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3609 | Imm |= ImmMask; |
| 3610 | } else if ((SplatBits & BitMask) != 0) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3611 | return SDValue(); |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3612 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3613 | BitMask <<= 8; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3614 | ImmMask <<= 1; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3615 | } |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3616 | // Op=1, Cmode=1110. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3617 | OpCmode = 0x1e; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3618 | SplatBits = Val; |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3619 | VT = is128Bits ? MVT::v2i64 : MVT::v1i64; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3620 | break; |
| 3621 | } |
| 3622 | |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3623 | default: |
Bob Wilson | dc076da | 2010-06-19 05:32:09 +0000 | [diff] [blame] | 3624 | llvm_unreachable("unexpected size for isNEONModifiedImm"); |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3625 | return SDValue(); |
| 3626 | } |
| 3627 | |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3628 | unsigned EncodedVal = ARM_AM::createNEONModImm(OpCmode, Imm); |
| 3629 | return DAG.getTargetConstant(EncodedVal, MVT::i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3630 | } |
| 3631 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3632 | static bool isVEXTMask(const SmallVectorImpl<int> &M, EVT VT, |
| 3633 | bool &ReverseVEXT, unsigned &Imm) { |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3634 | unsigned NumElts = VT.getVectorNumElements(); |
| 3635 | ReverseVEXT = false; |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3636 | |
| 3637 | // Assume that the first shuffle index is not UNDEF. Fail if it is. |
| 3638 | if (M[0] < 0) |
| 3639 | return false; |
| 3640 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3641 | Imm = M[0]; |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3642 | |
| 3643 | // If this is a VEXT shuffle, the immediate value is the index of the first |
| 3644 | // element. The other shuffle indices must be the successive elements after |
| 3645 | // the first one. |
| 3646 | unsigned ExpectedElt = Imm; |
| 3647 | for (unsigned i = 1; i < NumElts; ++i) { |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3648 | // Increment the expected index. If it wraps around, it may still be |
| 3649 | // a VEXT but the source vectors must be swapped. |
| 3650 | ExpectedElt += 1; |
| 3651 | if (ExpectedElt == NumElts * 2) { |
| 3652 | ExpectedElt = 0; |
| 3653 | ReverseVEXT = true; |
| 3654 | } |
| 3655 | |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3656 | if (M[i] < 0) continue; // ignore UNDEF indices |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3657 | if (ExpectedElt != static_cast<unsigned>(M[i])) |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3658 | return false; |
| 3659 | } |
| 3660 | |
| 3661 | // Adjust the index value if the source operands will be swapped. |
| 3662 | if (ReverseVEXT) |
| 3663 | Imm -= NumElts; |
| 3664 | |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3665 | return true; |
| 3666 | } |
| 3667 | |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 3668 | /// isVREVMask - Check if a vector shuffle corresponds to a VREV |
| 3669 | /// instruction with the specified blocksize. (The order of the elements |
| 3670 | /// within each block of the vector is reversed.) |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3671 | static bool isVREVMask(const SmallVectorImpl<int> &M, EVT VT, |
| 3672 | unsigned BlockSize) { |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 3673 | assert((BlockSize==16 || BlockSize==32 || BlockSize==64) && |
| 3674 | "Only possible block sizes for VREV are: 16, 32, 64"); |
| 3675 | |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 3676 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 3677 | if (EltSz == 64) |
| 3678 | return false; |
| 3679 | |
| 3680 | unsigned NumElts = VT.getVectorNumElements(); |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3681 | unsigned BlockElts = M[0] + 1; |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3682 | // If the first shuffle index is UNDEF, be optimistic. |
| 3683 | if (M[0] < 0) |
| 3684 | BlockElts = BlockSize / EltSz; |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 3685 | |
| 3686 | if (BlockSize <= EltSz || BlockSize != BlockElts * EltSz) |
| 3687 | return false; |
| 3688 | |
| 3689 | for (unsigned i = 0; i < NumElts; ++i) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3690 | if (M[i] < 0) continue; // ignore UNDEF indices |
| 3691 | if ((unsigned) M[i] != (i - i%BlockElts) + (BlockElts - 1 - i%BlockElts)) |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 3692 | return false; |
| 3693 | } |
| 3694 | |
| 3695 | return true; |
| 3696 | } |
| 3697 | |
Bill Wendling | 0d4c9d9 | 2011-03-15 21:15:20 +0000 | [diff] [blame] | 3698 | static bool isVTBLMask(const SmallVectorImpl<int> &M, EVT VT) { |
| 3699 | // We can handle <8 x i8> vector shuffles. If the index in the mask is out of |
| 3700 | // range, then 0 is placed into the resulting vector. So pretty much any mask |
| 3701 | // of 8 elements can work here. |
| 3702 | return VT == MVT::v8i8 && M.size() == 8; |
| 3703 | } |
| 3704 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3705 | static bool isVTRNMask(const SmallVectorImpl<int> &M, EVT VT, |
| 3706 | unsigned &WhichResult) { |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 3707 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3708 | if (EltSz == 64) |
| 3709 | return false; |
| 3710 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3711 | unsigned NumElts = VT.getVectorNumElements(); |
| 3712 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3713 | for (unsigned i = 0; i < NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3714 | if ((M[i] >= 0 && (unsigned) M[i] != i + WhichResult) || |
| 3715 | (M[i+1] >= 0 && (unsigned) M[i+1] != i + NumElts + WhichResult)) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3716 | return false; |
| 3717 | } |
| 3718 | return true; |
| 3719 | } |
| 3720 | |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3721 | /// isVTRN_v_undef_Mask - Special case of isVTRNMask for canonical form of |
| 3722 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 3723 | /// Mask is e.g., <0, 0, 2, 2> instead of <0, 4, 2, 6>. |
| 3724 | static bool isVTRN_v_undef_Mask(const SmallVectorImpl<int> &M, EVT VT, |
| 3725 | unsigned &WhichResult) { |
| 3726 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3727 | if (EltSz == 64) |
| 3728 | return false; |
| 3729 | |
| 3730 | unsigned NumElts = VT.getVectorNumElements(); |
| 3731 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3732 | for (unsigned i = 0; i < NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3733 | if ((M[i] >= 0 && (unsigned) M[i] != i + WhichResult) || |
| 3734 | (M[i+1] >= 0 && (unsigned) M[i+1] != i + WhichResult)) |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3735 | return false; |
| 3736 | } |
| 3737 | return true; |
| 3738 | } |
| 3739 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3740 | static bool isVUZPMask(const SmallVectorImpl<int> &M, EVT VT, |
| 3741 | unsigned &WhichResult) { |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 3742 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3743 | if (EltSz == 64) |
| 3744 | return false; |
| 3745 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3746 | unsigned NumElts = VT.getVectorNumElements(); |
| 3747 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3748 | for (unsigned i = 0; i != NumElts; ++i) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3749 | if (M[i] < 0) continue; // ignore UNDEF indices |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3750 | if ((unsigned) M[i] != 2 * i + WhichResult) |
| 3751 | return false; |
| 3752 | } |
| 3753 | |
| 3754 | // 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] | 3755 | if (VT.is64BitVector() && EltSz == 32) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3756 | return false; |
| 3757 | |
| 3758 | return true; |
| 3759 | } |
| 3760 | |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3761 | /// isVUZP_v_undef_Mask - Special case of isVUZPMask for canonical form of |
| 3762 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 3763 | /// Mask is e.g., <0, 2, 0, 2> instead of <0, 2, 4, 6>, |
| 3764 | static bool isVUZP_v_undef_Mask(const SmallVectorImpl<int> &M, EVT VT, |
| 3765 | unsigned &WhichResult) { |
| 3766 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3767 | if (EltSz == 64) |
| 3768 | return false; |
| 3769 | |
| 3770 | unsigned Half = VT.getVectorNumElements() / 2; |
| 3771 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3772 | for (unsigned j = 0; j != 2; ++j) { |
| 3773 | unsigned Idx = WhichResult; |
| 3774 | for (unsigned i = 0; i != Half; ++i) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3775 | int MIdx = M[i + j * Half]; |
| 3776 | if (MIdx >= 0 && (unsigned) MIdx != Idx) |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3777 | return false; |
| 3778 | Idx += 2; |
| 3779 | } |
| 3780 | } |
| 3781 | |
| 3782 | // VUZP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32. |
| 3783 | if (VT.is64BitVector() && EltSz == 32) |
| 3784 | return false; |
| 3785 | |
| 3786 | return true; |
| 3787 | } |
| 3788 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3789 | static bool isVZIPMask(const SmallVectorImpl<int> &M, EVT VT, |
| 3790 | unsigned &WhichResult) { |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 3791 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3792 | if (EltSz == 64) |
| 3793 | return false; |
| 3794 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3795 | unsigned NumElts = VT.getVectorNumElements(); |
| 3796 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3797 | unsigned Idx = WhichResult * NumElts / 2; |
| 3798 | for (unsigned i = 0; i != NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3799 | if ((M[i] >= 0 && (unsigned) M[i] != Idx) || |
| 3800 | (M[i+1] >= 0 && (unsigned) M[i+1] != Idx + NumElts)) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3801 | return false; |
| 3802 | Idx += 1; |
| 3803 | } |
| 3804 | |
| 3805 | // 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] | 3806 | if (VT.is64BitVector() && EltSz == 32) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3807 | return false; |
| 3808 | |
| 3809 | return true; |
| 3810 | } |
| 3811 | |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3812 | /// isVZIP_v_undef_Mask - Special case of isVZIPMask for canonical form of |
| 3813 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 3814 | /// Mask is e.g., <0, 0, 1, 1> instead of <0, 4, 1, 5>. |
| 3815 | static bool isVZIP_v_undef_Mask(const SmallVectorImpl<int> &M, EVT VT, |
| 3816 | unsigned &WhichResult) { |
| 3817 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3818 | if (EltSz == 64) |
| 3819 | return false; |
| 3820 | |
| 3821 | unsigned NumElts = VT.getVectorNumElements(); |
| 3822 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3823 | unsigned Idx = WhichResult * NumElts / 2; |
| 3824 | for (unsigned i = 0; i != NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3825 | if ((M[i] >= 0 && (unsigned) M[i] != Idx) || |
| 3826 | (M[i+1] >= 0 && (unsigned) M[i+1] != Idx)) |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3827 | return false; |
| 3828 | Idx += 1; |
| 3829 | } |
| 3830 | |
| 3831 | // VZIP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32. |
| 3832 | if (VT.is64BitVector() && EltSz == 32) |
| 3833 | return false; |
| 3834 | |
| 3835 | return true; |
| 3836 | } |
| 3837 | |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 3838 | // If N is an integer constant that can be moved into a register in one |
| 3839 | // instruction, return an SDValue of such a constant (will become a MOV |
| 3840 | // instruction). Otherwise return null. |
| 3841 | static SDValue IsSingleInstrConstant(SDValue N, SelectionDAG &DAG, |
| 3842 | const ARMSubtarget *ST, DebugLoc dl) { |
| 3843 | uint64_t Val; |
| 3844 | if (!isa<ConstantSDNode>(N)) |
| 3845 | return SDValue(); |
| 3846 | Val = cast<ConstantSDNode>(N)->getZExtValue(); |
| 3847 | |
| 3848 | if (ST->isThumb1Only()) { |
| 3849 | if (Val <= 255 || ~Val <= 255) |
| 3850 | return DAG.getConstant(Val, MVT::i32); |
| 3851 | } else { |
| 3852 | if (ARM_AM::getSOImmVal(Val) != -1 || ARM_AM::getSOImmVal(~Val) != -1) |
| 3853 | return DAG.getConstant(Val, MVT::i32); |
| 3854 | } |
| 3855 | return SDValue(); |
| 3856 | } |
| 3857 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3858 | // If this is a case we can't handle, return null and let the default |
| 3859 | // expansion code take care of it. |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3860 | SDValue ARMTargetLowering::LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG, |
| 3861 | const ARMSubtarget *ST) const { |
Bob Wilson | d06791f | 2009-08-13 01:57:47 +0000 | [diff] [blame] | 3862 | BuildVectorSDNode *BVN = cast<BuildVectorSDNode>(Op.getNode()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3863 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3864 | EVT VT = Op.getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3865 | |
| 3866 | APInt SplatBits, SplatUndef; |
| 3867 | unsigned SplatBitSize; |
| 3868 | bool HasAnyUndefs; |
| 3869 | if (BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { |
Anton Korobeynikov | 71624cc | 2009-08-29 00:08:18 +0000 | [diff] [blame] | 3870 | if (SplatBitSize <= 64) { |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 3871 | // Check if an immediate VMOV works. |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3872 | EVT VmovVT; |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 3873 | SDValue Val = isNEONModifiedImm(SplatBits.getZExtValue(), |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3874 | SplatUndef.getZExtValue(), SplatBitSize, |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3875 | DAG, VmovVT, VT.is128BitVector(), |
| 3876 | VMOVModImm); |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3877 | if (Val.getNode()) { |
| 3878 | SDValue Vmov = DAG.getNode(ARMISD::VMOVIMM, dl, VmovVT, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3879 | return DAG.getNode(ISD::BITCAST, dl, VT, Vmov); |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3880 | } |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 3881 | |
| 3882 | // Try an immediate VMVN. |
| 3883 | uint64_t NegatedImm = (SplatBits.getZExtValue() ^ |
| 3884 | ((1LL << SplatBitSize) - 1)); |
| 3885 | Val = isNEONModifiedImm(NegatedImm, |
| 3886 | SplatUndef.getZExtValue(), SplatBitSize, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3887 | DAG, VmovVT, VT.is128BitVector(), |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3888 | VMVNModImm); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 3889 | if (Val.getNode()) { |
| 3890 | SDValue Vmov = DAG.getNode(ARMISD::VMVNIMM, dl, VmovVT, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3891 | return DAG.getNode(ISD::BITCAST, dl, VT, Vmov); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 3892 | } |
Anton Korobeynikov | 71624cc | 2009-08-29 00:08:18 +0000 | [diff] [blame] | 3893 | } |
Bob Wilson | cf661e2 | 2009-07-30 00:31:25 +0000 | [diff] [blame] | 3894 | } |
| 3895 | |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 3896 | // Scan through the operands to see if only one value is used. |
| 3897 | unsigned NumElts = VT.getVectorNumElements(); |
| 3898 | bool isOnlyLowElement = true; |
| 3899 | bool usesOnlyOneValue = true; |
| 3900 | bool isConstant = true; |
| 3901 | SDValue Value; |
| 3902 | for (unsigned i = 0; i < NumElts; ++i) { |
| 3903 | SDValue V = Op.getOperand(i); |
| 3904 | if (V.getOpcode() == ISD::UNDEF) |
| 3905 | continue; |
| 3906 | if (i > 0) |
| 3907 | isOnlyLowElement = false; |
| 3908 | if (!isa<ConstantFPSDNode>(V) && !isa<ConstantSDNode>(V)) |
| 3909 | isConstant = false; |
| 3910 | |
| 3911 | if (!Value.getNode()) |
| 3912 | Value = V; |
| 3913 | else if (V != Value) |
| 3914 | usesOnlyOneValue = false; |
| 3915 | } |
| 3916 | |
| 3917 | if (!Value.getNode()) |
| 3918 | return DAG.getUNDEF(VT); |
| 3919 | |
| 3920 | if (isOnlyLowElement) |
| 3921 | return DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, VT, Value); |
| 3922 | |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 3923 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 3924 | |
Dale Johannesen | 575cd14 | 2010-10-19 20:00:17 +0000 | [diff] [blame] | 3925 | // Use VDUP for non-constant splats. For f32 constant splats, reduce to |
| 3926 | // i32 and try again. |
| 3927 | if (usesOnlyOneValue && EltSize <= 32) { |
| 3928 | if (!isConstant) |
| 3929 | return DAG.getNode(ARMISD::VDUP, dl, VT, Value); |
| 3930 | if (VT.getVectorElementType().isFloatingPoint()) { |
| 3931 | SmallVector<SDValue, 8> Ops; |
| 3932 | for (unsigned i = 0; i < NumElts; ++i) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3933 | Ops.push_back(DAG.getNode(ISD::BITCAST, dl, MVT::i32, |
Dale Johannesen | 575cd14 | 2010-10-19 20:00:17 +0000 | [diff] [blame] | 3934 | Op.getOperand(i))); |
Nate Begeman | bf5be26 | 2010-11-10 21:35:41 +0000 | [diff] [blame] | 3935 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), MVT::i32, NumElts); |
| 3936 | SDValue Val = DAG.getNode(ISD::BUILD_VECTOR, dl, VecVT, &Ops[0], NumElts); |
Dale Johannesen | e4d3159 | 2010-10-20 22:03:37 +0000 | [diff] [blame] | 3937 | Val = LowerBUILD_VECTOR(Val, DAG, ST); |
| 3938 | if (Val.getNode()) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3939 | return DAG.getNode(ISD::BITCAST, dl, VT, Val); |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 3940 | } |
Dale Johannesen | 575cd14 | 2010-10-19 20:00:17 +0000 | [diff] [blame] | 3941 | SDValue Val = IsSingleInstrConstant(Value, DAG, ST, dl); |
| 3942 | if (Val.getNode()) |
| 3943 | return DAG.getNode(ARMISD::VDUP, dl, VT, Val); |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 3944 | } |
| 3945 | |
| 3946 | // If all elements are constants and the case above didn't get hit, fall back |
| 3947 | // to the default expansion, which will generate a load from the constant |
| 3948 | // pool. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 3949 | if (isConstant) |
| 3950 | return SDValue(); |
| 3951 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3952 | // Empirical tests suggest this is rarely worth it for vectors of length <= 2. |
| 3953 | if (NumElts >= 4) { |
| 3954 | SDValue shuffle = ReconstructShuffle(Op, DAG); |
| 3955 | if (shuffle != SDValue()) |
| 3956 | return shuffle; |
| 3957 | } |
| 3958 | |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 3959 | // 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] | 3960 | // the subregisters. Lower it to an ARMISD::BUILD_VECTOR so the operands |
| 3961 | // will be legalized. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 3962 | if (EltSize >= 32) { |
| 3963 | // Do the expansion with floating-point types, since that is what the VFP |
| 3964 | // registers are defined to use, and since i64 is not legal. |
| 3965 | EVT EltVT = EVT::getFloatingPointVT(EltSize); |
| 3966 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), EltVT, NumElts); |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 3967 | SmallVector<SDValue, 8> Ops; |
| 3968 | for (unsigned i = 0; i < NumElts; ++i) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3969 | Ops.push_back(DAG.getNode(ISD::BITCAST, dl, EltVT, Op.getOperand(i))); |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 3970 | SDValue Val = DAG.getNode(ARMISD::BUILD_VECTOR, dl, VecVT, &Ops[0],NumElts); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3971 | return DAG.getNode(ISD::BITCAST, dl, VT, Val); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3972 | } |
| 3973 | |
| 3974 | return SDValue(); |
| 3975 | } |
| 3976 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3977 | // Gather data to see if the operation can be modelled as a |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 3978 | // shuffle in combination with VEXTs. |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 3979 | SDValue ARMTargetLowering::ReconstructShuffle(SDValue Op, |
| 3980 | SelectionDAG &DAG) const { |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3981 | DebugLoc dl = Op.getDebugLoc(); |
| 3982 | EVT VT = Op.getValueType(); |
| 3983 | unsigned NumElts = VT.getVectorNumElements(); |
| 3984 | |
| 3985 | SmallVector<SDValue, 2> SourceVecs; |
| 3986 | SmallVector<unsigned, 2> MinElts; |
| 3987 | SmallVector<unsigned, 2> MaxElts; |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 3988 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3989 | for (unsigned i = 0; i < NumElts; ++i) { |
| 3990 | SDValue V = Op.getOperand(i); |
| 3991 | if (V.getOpcode() == ISD::UNDEF) |
| 3992 | continue; |
| 3993 | else if (V.getOpcode() != ISD::EXTRACT_VECTOR_ELT) { |
| 3994 | // A shuffle can only come from building a vector from various |
| 3995 | // elements of other vectors. |
| 3996 | return SDValue(); |
| 3997 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 3998 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3999 | // Record this extraction against the appropriate vector if possible... |
| 4000 | SDValue SourceVec = V.getOperand(0); |
| 4001 | unsigned EltNo = cast<ConstantSDNode>(V.getOperand(1))->getZExtValue(); |
| 4002 | bool FoundSource = false; |
| 4003 | for (unsigned j = 0; j < SourceVecs.size(); ++j) { |
| 4004 | if (SourceVecs[j] == SourceVec) { |
| 4005 | if (MinElts[j] > EltNo) |
| 4006 | MinElts[j] = EltNo; |
| 4007 | if (MaxElts[j] < EltNo) |
| 4008 | MaxElts[j] = EltNo; |
| 4009 | FoundSource = true; |
| 4010 | break; |
| 4011 | } |
| 4012 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4013 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4014 | // Or record a new source if not... |
| 4015 | if (!FoundSource) { |
| 4016 | SourceVecs.push_back(SourceVec); |
| 4017 | MinElts.push_back(EltNo); |
| 4018 | MaxElts.push_back(EltNo); |
| 4019 | } |
| 4020 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4021 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4022 | // Currently only do something sane when at most two source vectors |
| 4023 | // involved. |
| 4024 | if (SourceVecs.size() > 2) |
| 4025 | return SDValue(); |
| 4026 | |
| 4027 | SDValue ShuffleSrcs[2] = {DAG.getUNDEF(VT), DAG.getUNDEF(VT) }; |
| 4028 | int VEXTOffsets[2] = {0, 0}; |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4029 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4030 | // This loop extracts the usage patterns of the source vectors |
| 4031 | // and prepares appropriate SDValues for a shuffle if possible. |
| 4032 | for (unsigned i = 0; i < SourceVecs.size(); ++i) { |
| 4033 | if (SourceVecs[i].getValueType() == VT) { |
| 4034 | // No VEXT necessary |
| 4035 | ShuffleSrcs[i] = SourceVecs[i]; |
| 4036 | VEXTOffsets[i] = 0; |
| 4037 | continue; |
| 4038 | } else if (SourceVecs[i].getValueType().getVectorNumElements() < NumElts) { |
| 4039 | // It probably isn't worth padding out a smaller vector just to |
| 4040 | // break it down again in a shuffle. |
| 4041 | return SDValue(); |
| 4042 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4043 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4044 | // Since only 64-bit and 128-bit vectors are legal on ARM and |
| 4045 | // we've eliminated the other cases... |
Bob Wilson | 70f8573 | 2011-01-07 23:40:46 +0000 | [diff] [blame] | 4046 | assert(SourceVecs[i].getValueType().getVectorNumElements() == 2*NumElts && |
| 4047 | "unexpected vector sizes in ReconstructShuffle"); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4048 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4049 | if (MaxElts[i] - MinElts[i] >= NumElts) { |
| 4050 | // Span too large for a VEXT to cope |
| 4051 | return SDValue(); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4052 | } |
| 4053 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4054 | if (MinElts[i] >= NumElts) { |
| 4055 | // The extraction can just take the second half |
| 4056 | VEXTOffsets[i] = NumElts; |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4057 | ShuffleSrcs[i] = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 4058 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4059 | DAG.getIntPtrConstant(NumElts)); |
| 4060 | } else if (MaxElts[i] < NumElts) { |
| 4061 | // The extraction can just take the first half |
| 4062 | VEXTOffsets[i] = 0; |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4063 | ShuffleSrcs[i] = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 4064 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4065 | DAG.getIntPtrConstant(0)); |
| 4066 | } else { |
| 4067 | // An actual VEXT is needed |
| 4068 | VEXTOffsets[i] = MinElts[i]; |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4069 | SDValue VEXTSrc1 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 4070 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4071 | DAG.getIntPtrConstant(0)); |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4072 | SDValue VEXTSrc2 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 4073 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4074 | DAG.getIntPtrConstant(NumElts)); |
| 4075 | ShuffleSrcs[i] = DAG.getNode(ARMISD::VEXT, dl, VT, VEXTSrc1, VEXTSrc2, |
| 4076 | DAG.getConstant(VEXTOffsets[i], MVT::i32)); |
| 4077 | } |
| 4078 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4079 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4080 | SmallVector<int, 8> Mask; |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4081 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4082 | for (unsigned i = 0; i < NumElts; ++i) { |
| 4083 | SDValue Entry = Op.getOperand(i); |
| 4084 | if (Entry.getOpcode() == ISD::UNDEF) { |
| 4085 | Mask.push_back(-1); |
| 4086 | continue; |
| 4087 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4088 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4089 | SDValue ExtractVec = Entry.getOperand(0); |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4090 | int ExtractElt = cast<ConstantSDNode>(Op.getOperand(i) |
| 4091 | .getOperand(1))->getSExtValue(); |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4092 | if (ExtractVec == SourceVecs[0]) { |
| 4093 | Mask.push_back(ExtractElt - VEXTOffsets[0]); |
| 4094 | } else { |
| 4095 | Mask.push_back(ExtractElt + NumElts - VEXTOffsets[1]); |
| 4096 | } |
| 4097 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4098 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4099 | // Final check before we try to produce nonsense... |
| 4100 | if (isShuffleMaskLegal(Mask, VT)) |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4101 | return DAG.getVectorShuffle(VT, dl, ShuffleSrcs[0], ShuffleSrcs[1], |
| 4102 | &Mask[0]); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4103 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4104 | return SDValue(); |
| 4105 | } |
| 4106 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4107 | /// isShuffleMaskLegal - Targets can use this to indicate that they only |
| 4108 | /// support *some* VECTOR_SHUFFLE operations, those with specific masks. |
| 4109 | /// By default, if a target supports the VECTOR_SHUFFLE node, all mask values |
| 4110 | /// are assumed to be legal. |
| 4111 | bool |
| 4112 | ARMTargetLowering::isShuffleMaskLegal(const SmallVectorImpl<int> &M, |
| 4113 | EVT VT) const { |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4114 | if (VT.getVectorNumElements() == 4 && |
| 4115 | (VT.is128BitVector() || VT.is64BitVector())) { |
| 4116 | unsigned PFIndexes[4]; |
| 4117 | for (unsigned i = 0; i != 4; ++i) { |
| 4118 | if (M[i] < 0) |
| 4119 | PFIndexes[i] = 8; |
| 4120 | else |
| 4121 | PFIndexes[i] = M[i]; |
| 4122 | } |
| 4123 | |
| 4124 | // Compute the index in the perfect shuffle table. |
| 4125 | unsigned PFTableIndex = |
| 4126 | PFIndexes[0]*9*9*9+PFIndexes[1]*9*9+PFIndexes[2]*9+PFIndexes[3]; |
| 4127 | unsigned PFEntry = PerfectShuffleTable[PFTableIndex]; |
| 4128 | unsigned Cost = (PFEntry >> 30); |
| 4129 | |
| 4130 | if (Cost <= 4) |
| 4131 | return true; |
| 4132 | } |
| 4133 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4134 | bool ReverseVEXT; |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4135 | unsigned Imm, WhichResult; |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4136 | |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4137 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 4138 | return (EltSize >= 32 || |
| 4139 | ShuffleVectorSDNode::isSplatMask(&M[0], VT) || |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4140 | isVREVMask(M, VT, 64) || |
| 4141 | isVREVMask(M, VT, 32) || |
| 4142 | isVREVMask(M, VT, 16) || |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4143 | isVEXTMask(M, VT, ReverseVEXT, Imm) || |
Bill Wendling | 0d4c9d9 | 2011-03-15 21:15:20 +0000 | [diff] [blame] | 4144 | isVTBLMask(M, VT) || |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4145 | isVTRNMask(M, VT, WhichResult) || |
| 4146 | isVUZPMask(M, VT, WhichResult) || |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4147 | isVZIPMask(M, VT, WhichResult) || |
| 4148 | isVTRN_v_undef_Mask(M, VT, WhichResult) || |
| 4149 | isVUZP_v_undef_Mask(M, VT, WhichResult) || |
| 4150 | isVZIP_v_undef_Mask(M, VT, WhichResult)); |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4151 | } |
| 4152 | |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4153 | /// GeneratePerfectShuffle - Given an entry in the perfect-shuffle table, emit |
| 4154 | /// the specified operations to build the shuffle. |
| 4155 | static SDValue GeneratePerfectShuffle(unsigned PFEntry, SDValue LHS, |
| 4156 | SDValue RHS, SelectionDAG &DAG, |
| 4157 | DebugLoc dl) { |
| 4158 | unsigned OpNum = (PFEntry >> 26) & 0x0F; |
| 4159 | unsigned LHSID = (PFEntry >> 13) & ((1 << 13)-1); |
| 4160 | unsigned RHSID = (PFEntry >> 0) & ((1 << 13)-1); |
| 4161 | |
| 4162 | enum { |
| 4163 | OP_COPY = 0, // Copy, used for things like <u,u,u,3> to say it is <0,1,2,3> |
| 4164 | OP_VREV, |
| 4165 | OP_VDUP0, |
| 4166 | OP_VDUP1, |
| 4167 | OP_VDUP2, |
| 4168 | OP_VDUP3, |
| 4169 | OP_VEXT1, |
| 4170 | OP_VEXT2, |
| 4171 | OP_VEXT3, |
| 4172 | OP_VUZPL, // VUZP, left result |
| 4173 | OP_VUZPR, // VUZP, right result |
| 4174 | OP_VZIPL, // VZIP, left result |
| 4175 | OP_VZIPR, // VZIP, right result |
| 4176 | OP_VTRNL, // VTRN, left result |
| 4177 | OP_VTRNR // VTRN, right result |
| 4178 | }; |
| 4179 | |
| 4180 | if (OpNum == OP_COPY) { |
| 4181 | if (LHSID == (1*9+2)*9+3) return LHS; |
| 4182 | assert(LHSID == ((4*9+5)*9+6)*9+7 && "Illegal OP_COPY!"); |
| 4183 | return RHS; |
| 4184 | } |
| 4185 | |
| 4186 | SDValue OpLHS, OpRHS; |
| 4187 | OpLHS = GeneratePerfectShuffle(PerfectShuffleTable[LHSID], LHS, RHS, DAG, dl); |
| 4188 | OpRHS = GeneratePerfectShuffle(PerfectShuffleTable[RHSID], LHS, RHS, DAG, dl); |
| 4189 | EVT VT = OpLHS.getValueType(); |
| 4190 | |
| 4191 | switch (OpNum) { |
| 4192 | default: llvm_unreachable("Unknown shuffle opcode!"); |
| 4193 | case OP_VREV: |
Tanya Lattner | 2a8eb72 | 2011-05-18 06:42:21 +0000 | [diff] [blame] | 4194 | // VREV divides the vector in half and swaps within the half. |
Tanya Lattner | db28247 | 2011-05-18 21:44:54 +0000 | [diff] [blame] | 4195 | if (VT.getVectorElementType() == MVT::i32 || |
| 4196 | VT.getVectorElementType() == MVT::f32) |
Tanya Lattner | 2a8eb72 | 2011-05-18 06:42:21 +0000 | [diff] [blame] | 4197 | return DAG.getNode(ARMISD::VREV64, dl, VT, OpLHS); |
| 4198 | // vrev <4 x i16> -> VREV32 |
| 4199 | if (VT.getVectorElementType() == MVT::i16) |
| 4200 | return DAG.getNode(ARMISD::VREV32, dl, VT, OpLHS); |
| 4201 | // vrev <4 x i8> -> VREV16 |
| 4202 | assert(VT.getVectorElementType() == MVT::i8); |
| 4203 | return DAG.getNode(ARMISD::VREV16, dl, VT, OpLHS); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4204 | case OP_VDUP0: |
| 4205 | case OP_VDUP1: |
| 4206 | case OP_VDUP2: |
| 4207 | case OP_VDUP3: |
| 4208 | return DAG.getNode(ARMISD::VDUPLANE, dl, VT, |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 4209 | OpLHS, DAG.getConstant(OpNum-OP_VDUP0, MVT::i32)); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4210 | case OP_VEXT1: |
| 4211 | case OP_VEXT2: |
| 4212 | case OP_VEXT3: |
| 4213 | return DAG.getNode(ARMISD::VEXT, dl, VT, |
| 4214 | OpLHS, OpRHS, |
| 4215 | DAG.getConstant(OpNum-OP_VEXT1+1, MVT::i32)); |
| 4216 | case OP_VUZPL: |
| 4217 | case OP_VUZPR: |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 4218 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4219 | OpLHS, OpRHS).getValue(OpNum-OP_VUZPL); |
| 4220 | case OP_VZIPL: |
| 4221 | case OP_VZIPR: |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 4222 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4223 | OpLHS, OpRHS).getValue(OpNum-OP_VZIPL); |
| 4224 | case OP_VTRNL: |
| 4225 | case OP_VTRNR: |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 4226 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), |
| 4227 | OpLHS, OpRHS).getValue(OpNum-OP_VTRNL); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4228 | } |
| 4229 | } |
| 4230 | |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4231 | static SDValue LowerVECTOR_SHUFFLEv8i8(SDValue Op, |
| 4232 | SmallVectorImpl<int> &ShuffleMask, |
| 4233 | SelectionDAG &DAG) { |
| 4234 | // Check to see if we can use the VTBL instruction. |
| 4235 | SDValue V1 = Op.getOperand(0); |
| 4236 | SDValue V2 = Op.getOperand(1); |
| 4237 | DebugLoc DL = Op.getDebugLoc(); |
| 4238 | |
| 4239 | SmallVector<SDValue, 8> VTBLMask; |
| 4240 | for (SmallVectorImpl<int>::iterator |
| 4241 | I = ShuffleMask.begin(), E = ShuffleMask.end(); I != E; ++I) |
| 4242 | VTBLMask.push_back(DAG.getConstant(*I, MVT::i32)); |
| 4243 | |
| 4244 | if (V2.getNode()->getOpcode() == ISD::UNDEF) |
| 4245 | return DAG.getNode(ARMISD::VTBL1, DL, MVT::v8i8, V1, |
| 4246 | DAG.getNode(ISD::BUILD_VECTOR, DL, MVT::v8i8, |
| 4247 | &VTBLMask[0], 8)); |
Bill Wendling | a24cb40 | 2011-03-15 20:47:26 +0000 | [diff] [blame] | 4248 | |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4249 | return DAG.getNode(ARMISD::VTBL2, DL, MVT::v8i8, V1, V2, |
Bill Wendling | a24cb40 | 2011-03-15 20:47:26 +0000 | [diff] [blame] | 4250 | DAG.getNode(ISD::BUILD_VECTOR, DL, MVT::v8i8, |
| 4251 | &VTBLMask[0], 8)); |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4252 | } |
| 4253 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4254 | static SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) { |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4255 | SDValue V1 = Op.getOperand(0); |
| 4256 | SDValue V2 = Op.getOperand(1); |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 4257 | DebugLoc dl = Op.getDebugLoc(); |
| 4258 | EVT VT = Op.getValueType(); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4259 | ShuffleVectorSDNode *SVN = cast<ShuffleVectorSDNode>(Op.getNode()); |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4260 | SmallVector<int, 8> ShuffleMask; |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 4261 | |
Bob Wilson | 2886506 | 2009-08-13 02:13:04 +0000 | [diff] [blame] | 4262 | // Convert shuffles that are directly supported on NEON to target-specific |
| 4263 | // DAG nodes, instead of keeping them as shuffles and matching them again |
| 4264 | // during code selection. This is more efficient and avoids the possibility |
| 4265 | // of inconsistencies between legalization and selection. |
Bob Wilson | bfcbb50 | 2009-08-13 06:01:30 +0000 | [diff] [blame] | 4266 | // FIXME: floating-point vectors should be canonicalized to integer vectors |
| 4267 | // of the same time so that they get CSEd properly. |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4268 | SVN->getMask(ShuffleMask); |
| 4269 | |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4270 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 4271 | if (EltSize <= 32) { |
| 4272 | if (ShuffleVectorSDNode::isSplatMask(&ShuffleMask[0], VT)) { |
| 4273 | int Lane = SVN->getSplatIndex(); |
| 4274 | // If this is undef splat, generate it via "just" vdup, if possible. |
| 4275 | if (Lane == -1) Lane = 0; |
Anton Korobeynikov | 2ae0eec | 2009-11-02 00:12:06 +0000 | [diff] [blame] | 4276 | |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4277 | if (Lane == 0 && V1.getOpcode() == ISD::SCALAR_TO_VECTOR) { |
| 4278 | return DAG.getNode(ARMISD::VDUP, dl, VT, V1.getOperand(0)); |
| 4279 | } |
| 4280 | return DAG.getNode(ARMISD::VDUPLANE, dl, VT, V1, |
| 4281 | DAG.getConstant(Lane, MVT::i32)); |
Bob Wilson | c1d287b | 2009-08-14 05:13:08 +0000 | [diff] [blame] | 4282 | } |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4283 | |
| 4284 | bool ReverseVEXT; |
| 4285 | unsigned Imm; |
| 4286 | if (isVEXTMask(ShuffleMask, VT, ReverseVEXT, Imm)) { |
| 4287 | if (ReverseVEXT) |
| 4288 | std::swap(V1, V2); |
| 4289 | return DAG.getNode(ARMISD::VEXT, dl, VT, V1, V2, |
| 4290 | DAG.getConstant(Imm, MVT::i32)); |
| 4291 | } |
| 4292 | |
| 4293 | if (isVREVMask(ShuffleMask, VT, 64)) |
| 4294 | return DAG.getNode(ARMISD::VREV64, dl, VT, V1); |
| 4295 | if (isVREVMask(ShuffleMask, VT, 32)) |
| 4296 | return DAG.getNode(ARMISD::VREV32, dl, VT, V1); |
| 4297 | if (isVREVMask(ShuffleMask, VT, 16)) |
| 4298 | return DAG.getNode(ARMISD::VREV16, dl, VT, V1); |
| 4299 | |
| 4300 | // Check for Neon shuffles that modify both input vectors in place. |
| 4301 | // If both results are used, i.e., if there are two shuffles with the same |
| 4302 | // source operands and with masks corresponding to both results of one of |
| 4303 | // these operations, DAG memoization will ensure that a single node is |
| 4304 | // used for both shuffles. |
| 4305 | unsigned WhichResult; |
| 4306 | if (isVTRNMask(ShuffleMask, VT, WhichResult)) |
| 4307 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), |
| 4308 | V1, V2).getValue(WhichResult); |
| 4309 | if (isVUZPMask(ShuffleMask, VT, WhichResult)) |
| 4310 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), |
| 4311 | V1, V2).getValue(WhichResult); |
| 4312 | if (isVZIPMask(ShuffleMask, VT, WhichResult)) |
| 4313 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), |
| 4314 | V1, V2).getValue(WhichResult); |
| 4315 | |
| 4316 | if (isVTRN_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 4317 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), |
| 4318 | V1, V1).getValue(WhichResult); |
| 4319 | if (isVUZP_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 4320 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), |
| 4321 | V1, V1).getValue(WhichResult); |
| 4322 | if (isVZIP_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 4323 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), |
| 4324 | V1, V1).getValue(WhichResult); |
Bob Wilson | 0ce3710 | 2009-08-14 05:08:32 +0000 | [diff] [blame] | 4325 | } |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 4326 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4327 | // If the shuffle is not directly supported and it has 4 elements, use |
| 4328 | // the PerfectShuffle-generated table to synthesize it from other shuffles. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4329 | unsigned NumElts = VT.getVectorNumElements(); |
| 4330 | if (NumElts == 4) { |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4331 | unsigned PFIndexes[4]; |
| 4332 | for (unsigned i = 0; i != 4; ++i) { |
| 4333 | if (ShuffleMask[i] < 0) |
| 4334 | PFIndexes[i] = 8; |
| 4335 | else |
| 4336 | PFIndexes[i] = ShuffleMask[i]; |
| 4337 | } |
| 4338 | |
| 4339 | // Compute the index in the perfect shuffle table. |
| 4340 | unsigned PFTableIndex = |
| 4341 | 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] | 4342 | unsigned PFEntry = PerfectShuffleTable[PFTableIndex]; |
| 4343 | unsigned Cost = (PFEntry >> 30); |
| 4344 | |
| 4345 | if (Cost <= 4) |
| 4346 | return GeneratePerfectShuffle(PFEntry, V1, V2, DAG, dl); |
| 4347 | } |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 4348 | |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4349 | // Implement shuffles with 32- or 64-bit elements as ARMISD::BUILD_VECTORs. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4350 | if (EltSize >= 32) { |
| 4351 | // Do the expansion with floating-point types, since that is what the VFP |
| 4352 | // registers are defined to use, and since i64 is not legal. |
| 4353 | EVT EltVT = EVT::getFloatingPointVT(EltSize); |
| 4354 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), EltVT, NumElts); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4355 | V1 = DAG.getNode(ISD::BITCAST, dl, VecVT, V1); |
| 4356 | V2 = DAG.getNode(ISD::BITCAST, dl, VecVT, V2); |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4357 | SmallVector<SDValue, 8> Ops; |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4358 | for (unsigned i = 0; i < NumElts; ++i) { |
Bob Wilson | 63b8845 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 4359 | if (ShuffleMask[i] < 0) |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4360 | Ops.push_back(DAG.getUNDEF(EltVT)); |
| 4361 | else |
| 4362 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, EltVT, |
| 4363 | ShuffleMask[i] < (int)NumElts ? V1 : V2, |
| 4364 | DAG.getConstant(ShuffleMask[i] & (NumElts-1), |
| 4365 | MVT::i32))); |
Bob Wilson | 63b8845 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 4366 | } |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4367 | SDValue Val = DAG.getNode(ARMISD::BUILD_VECTOR, dl, VecVT, &Ops[0],NumElts); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4368 | return DAG.getNode(ISD::BITCAST, dl, VT, Val); |
Bob Wilson | 63b8845 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 4369 | } |
| 4370 | |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4371 | if (VT == MVT::v8i8) { |
| 4372 | SDValue NewOp = LowerVECTOR_SHUFFLEv8i8(Op, ShuffleMask, DAG); |
| 4373 | if (NewOp.getNode()) |
| 4374 | return NewOp; |
| 4375 | } |
| 4376 | |
Bob Wilson | 22cac0d | 2009-08-14 05:16:33 +0000 | [diff] [blame] | 4377 | return SDValue(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4378 | } |
| 4379 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4380 | static SDValue LowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) { |
Bob Wilson | 3468c2e | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 4381 | // EXTRACT_VECTOR_ELT is legal only for immediate indexes. |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4382 | SDValue Lane = Op.getOperand(1); |
Bob Wilson | 3468c2e | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 4383 | if (!isa<ConstantSDNode>(Lane)) |
| 4384 | return SDValue(); |
| 4385 | |
| 4386 | SDValue Vec = Op.getOperand(0); |
| 4387 | if (Op.getValueType() == MVT::i32 && |
| 4388 | Vec.getValueType().getVectorElementType().getSizeInBits() < 32) { |
| 4389 | DebugLoc dl = Op.getDebugLoc(); |
| 4390 | return DAG.getNode(ARMISD::VGETLANEu, dl, MVT::i32, Vec, Lane); |
| 4391 | } |
| 4392 | |
| 4393 | return Op; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4394 | } |
| 4395 | |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 4396 | static SDValue LowerCONCAT_VECTORS(SDValue Op, SelectionDAG &DAG) { |
| 4397 | // The only time a CONCAT_VECTORS operation can have legal types is when |
| 4398 | // two 64-bit vectors are concatenated to a 128-bit vector. |
| 4399 | assert(Op.getValueType().is128BitVector() && Op.getNumOperands() == 2 && |
| 4400 | "unexpected CONCAT_VECTORS"); |
| 4401 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4402 | SDValue Val = DAG.getUNDEF(MVT::v2f64); |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 4403 | SDValue Op0 = Op.getOperand(0); |
| 4404 | SDValue Op1 = Op.getOperand(1); |
| 4405 | if (Op0.getOpcode() != ISD::UNDEF) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4406 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Val, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4407 | DAG.getNode(ISD::BITCAST, dl, MVT::f64, Op0), |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 4408 | DAG.getIntPtrConstant(0)); |
| 4409 | if (Op1.getOpcode() != ISD::UNDEF) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4410 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Val, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4411 | DAG.getNode(ISD::BITCAST, dl, MVT::f64, Op1), |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 4412 | DAG.getIntPtrConstant(1)); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4413 | return DAG.getNode(ISD::BITCAST, dl, Op.getValueType(), Val); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4414 | } |
| 4415 | |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 4416 | /// isExtendedBUILD_VECTOR - Check if N is a constant BUILD_VECTOR where each |
| 4417 | /// element has been zero/sign-extended, depending on the isSigned parameter, |
| 4418 | /// from an integer type half its size. |
| 4419 | static bool isExtendedBUILD_VECTOR(SDNode *N, SelectionDAG &DAG, |
| 4420 | bool isSigned) { |
| 4421 | // A v2i64 BUILD_VECTOR will have been legalized to a BITCAST from v4i32. |
| 4422 | EVT VT = N->getValueType(0); |
| 4423 | if (VT == MVT::v2i64 && N->getOpcode() == ISD::BITCAST) { |
| 4424 | SDNode *BVN = N->getOperand(0).getNode(); |
| 4425 | if (BVN->getValueType(0) != MVT::v4i32 || |
| 4426 | BVN->getOpcode() != ISD::BUILD_VECTOR) |
| 4427 | return false; |
| 4428 | unsigned LoElt = DAG.getTargetLoweringInfo().isBigEndian() ? 1 : 0; |
| 4429 | unsigned HiElt = 1 - LoElt; |
| 4430 | ConstantSDNode *Lo0 = dyn_cast<ConstantSDNode>(BVN->getOperand(LoElt)); |
| 4431 | ConstantSDNode *Hi0 = dyn_cast<ConstantSDNode>(BVN->getOperand(HiElt)); |
| 4432 | ConstantSDNode *Lo1 = dyn_cast<ConstantSDNode>(BVN->getOperand(LoElt+2)); |
| 4433 | ConstantSDNode *Hi1 = dyn_cast<ConstantSDNode>(BVN->getOperand(HiElt+2)); |
| 4434 | if (!Lo0 || !Hi0 || !Lo1 || !Hi1) |
| 4435 | return false; |
| 4436 | if (isSigned) { |
| 4437 | if (Hi0->getSExtValue() == Lo0->getSExtValue() >> 32 && |
| 4438 | Hi1->getSExtValue() == Lo1->getSExtValue() >> 32) |
| 4439 | return true; |
| 4440 | } else { |
| 4441 | if (Hi0->isNullValue() && Hi1->isNullValue()) |
| 4442 | return true; |
| 4443 | } |
| 4444 | return false; |
| 4445 | } |
| 4446 | |
| 4447 | if (N->getOpcode() != ISD::BUILD_VECTOR) |
| 4448 | return false; |
| 4449 | |
| 4450 | for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) { |
| 4451 | SDNode *Elt = N->getOperand(i).getNode(); |
| 4452 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Elt)) { |
| 4453 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 4454 | unsigned HalfSize = EltSize / 2; |
| 4455 | if (isSigned) { |
| 4456 | int64_t SExtVal = C->getSExtValue(); |
| 4457 | if ((SExtVal >> HalfSize) != (SExtVal >> EltSize)) |
| 4458 | return false; |
| 4459 | } else { |
| 4460 | if ((C->getZExtValue() >> HalfSize) != 0) |
| 4461 | return false; |
| 4462 | } |
| 4463 | continue; |
| 4464 | } |
| 4465 | return false; |
| 4466 | } |
| 4467 | |
| 4468 | return true; |
| 4469 | } |
| 4470 | |
| 4471 | /// isSignExtended - Check if a node is a vector value that is sign-extended |
| 4472 | /// or a constant BUILD_VECTOR with sign-extended elements. |
| 4473 | static bool isSignExtended(SDNode *N, SelectionDAG &DAG) { |
| 4474 | if (N->getOpcode() == ISD::SIGN_EXTEND || ISD::isSEXTLoad(N)) |
| 4475 | return true; |
| 4476 | if (isExtendedBUILD_VECTOR(N, DAG, true)) |
| 4477 | return true; |
| 4478 | return false; |
| 4479 | } |
| 4480 | |
| 4481 | /// isZeroExtended - Check if a node is a vector value that is zero-extended |
| 4482 | /// or a constant BUILD_VECTOR with zero-extended elements. |
| 4483 | static bool isZeroExtended(SDNode *N, SelectionDAG &DAG) { |
| 4484 | if (N->getOpcode() == ISD::ZERO_EXTEND || ISD::isZEXTLoad(N)) |
| 4485 | return true; |
| 4486 | if (isExtendedBUILD_VECTOR(N, DAG, false)) |
| 4487 | return true; |
| 4488 | return false; |
| 4489 | } |
| 4490 | |
| 4491 | /// SkipExtension - For a node that is a SIGN_EXTEND, ZERO_EXTEND, extending |
| 4492 | /// load, or BUILD_VECTOR with extended elements, return the unextended value. |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4493 | static SDValue SkipExtension(SDNode *N, SelectionDAG &DAG) { |
| 4494 | if (N->getOpcode() == ISD::SIGN_EXTEND || N->getOpcode() == ISD::ZERO_EXTEND) |
| 4495 | return N->getOperand(0); |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 4496 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) |
| 4497 | return DAG.getLoad(LD->getMemoryVT(), N->getDebugLoc(), LD->getChain(), |
| 4498 | LD->getBasePtr(), LD->getPointerInfo(), LD->isVolatile(), |
| 4499 | LD->isNonTemporal(), LD->getAlignment()); |
| 4500 | // Otherwise, the value must be a BUILD_VECTOR. For v2i64, it will |
| 4501 | // have been legalized as a BITCAST from v4i32. |
| 4502 | if (N->getOpcode() == ISD::BITCAST) { |
| 4503 | SDNode *BVN = N->getOperand(0).getNode(); |
| 4504 | assert(BVN->getOpcode() == ISD::BUILD_VECTOR && |
| 4505 | BVN->getValueType(0) == MVT::v4i32 && "expected v4i32 BUILD_VECTOR"); |
| 4506 | unsigned LowElt = DAG.getTargetLoweringInfo().isBigEndian() ? 1 : 0; |
| 4507 | return DAG.getNode(ISD::BUILD_VECTOR, N->getDebugLoc(), MVT::v2i32, |
| 4508 | BVN->getOperand(LowElt), BVN->getOperand(LowElt+2)); |
| 4509 | } |
| 4510 | // Construct a new BUILD_VECTOR with elements truncated to half the size. |
| 4511 | assert(N->getOpcode() == ISD::BUILD_VECTOR && "expected BUILD_VECTOR"); |
| 4512 | EVT VT = N->getValueType(0); |
| 4513 | unsigned EltSize = VT.getVectorElementType().getSizeInBits() / 2; |
| 4514 | unsigned NumElts = VT.getVectorNumElements(); |
| 4515 | MVT TruncVT = MVT::getIntegerVT(EltSize); |
| 4516 | SmallVector<SDValue, 8> Ops; |
| 4517 | for (unsigned i = 0; i != NumElts; ++i) { |
| 4518 | ConstantSDNode *C = cast<ConstantSDNode>(N->getOperand(i)); |
| 4519 | const APInt &CInt = C->getAPIntValue(); |
Jay Foad | 40f8f62 | 2010-12-07 08:25:19 +0000 | [diff] [blame] | 4520 | Ops.push_back(DAG.getConstant(CInt.trunc(EltSize), TruncVT)); |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 4521 | } |
| 4522 | return DAG.getNode(ISD::BUILD_VECTOR, N->getDebugLoc(), |
| 4523 | MVT::getVectorVT(TruncVT, NumElts), Ops.data(), NumElts); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4524 | } |
| 4525 | |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 4526 | static bool isAddSubSExt(SDNode *N, SelectionDAG &DAG) { |
| 4527 | unsigned Opcode = N->getOpcode(); |
| 4528 | if (Opcode == ISD::ADD || Opcode == ISD::SUB) { |
| 4529 | SDNode *N0 = N->getOperand(0).getNode(); |
| 4530 | SDNode *N1 = N->getOperand(1).getNode(); |
| 4531 | return N0->hasOneUse() && N1->hasOneUse() && |
| 4532 | isSignExtended(N0, DAG) && isSignExtended(N1, DAG); |
| 4533 | } |
| 4534 | return false; |
| 4535 | } |
| 4536 | |
| 4537 | static bool isAddSubZExt(SDNode *N, SelectionDAG &DAG) { |
| 4538 | unsigned Opcode = N->getOpcode(); |
| 4539 | if (Opcode == ISD::ADD || Opcode == ISD::SUB) { |
| 4540 | SDNode *N0 = N->getOperand(0).getNode(); |
| 4541 | SDNode *N1 = N->getOperand(1).getNode(); |
| 4542 | return N0->hasOneUse() && N1->hasOneUse() && |
| 4543 | isZeroExtended(N0, DAG) && isZeroExtended(N1, DAG); |
| 4544 | } |
| 4545 | return false; |
| 4546 | } |
| 4547 | |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4548 | static SDValue LowerMUL(SDValue Op, SelectionDAG &DAG) { |
| 4549 | // Multiplications are only custom-lowered for 128-bit vectors so that |
| 4550 | // VMULL can be detected. Otherwise v2i64 multiplications are not legal. |
| 4551 | EVT VT = Op.getValueType(); |
| 4552 | assert(VT.is128BitVector() && "unexpected type for custom-lowering ISD::MUL"); |
| 4553 | SDNode *N0 = Op.getOperand(0).getNode(); |
| 4554 | SDNode *N1 = Op.getOperand(1).getNode(); |
| 4555 | unsigned NewOpc = 0; |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 4556 | bool isMLA = false; |
| 4557 | bool isN0SExt = isSignExtended(N0, DAG); |
| 4558 | bool isN1SExt = isSignExtended(N1, DAG); |
| 4559 | if (isN0SExt && isN1SExt) |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4560 | NewOpc = ARMISD::VMULLs; |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 4561 | else { |
| 4562 | bool isN0ZExt = isZeroExtended(N0, DAG); |
| 4563 | bool isN1ZExt = isZeroExtended(N1, DAG); |
| 4564 | if (isN0ZExt && isN1ZExt) |
| 4565 | NewOpc = ARMISD::VMULLu; |
| 4566 | else if (isN1SExt || isN1ZExt) { |
| 4567 | // Look for (s/zext A + s/zext B) * (s/zext C). We want to turn these |
| 4568 | // into (s/zext A * s/zext C) + (s/zext B * s/zext C) |
| 4569 | if (isN1SExt && isAddSubSExt(N0, DAG)) { |
| 4570 | NewOpc = ARMISD::VMULLs; |
| 4571 | isMLA = true; |
| 4572 | } else if (isN1ZExt && isAddSubZExt(N0, DAG)) { |
| 4573 | NewOpc = ARMISD::VMULLu; |
| 4574 | isMLA = true; |
| 4575 | } else if (isN0ZExt && isAddSubZExt(N1, DAG)) { |
| 4576 | std::swap(N0, N1); |
| 4577 | NewOpc = ARMISD::VMULLu; |
| 4578 | isMLA = true; |
| 4579 | } |
| 4580 | } |
| 4581 | |
| 4582 | if (!NewOpc) { |
| 4583 | if (VT == MVT::v2i64) |
| 4584 | // Fall through to expand this. It is not legal. |
| 4585 | return SDValue(); |
| 4586 | else |
| 4587 | // Other vector multiplications are legal. |
| 4588 | return Op; |
| 4589 | } |
| 4590 | } |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4591 | |
| 4592 | // Legalize to a VMULL instruction. |
| 4593 | DebugLoc DL = Op.getDebugLoc(); |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 4594 | SDValue Op0; |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4595 | SDValue Op1 = SkipExtension(N1, DAG); |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 4596 | if (!isMLA) { |
| 4597 | Op0 = SkipExtension(N0, DAG); |
| 4598 | assert(Op0.getValueType().is64BitVector() && |
| 4599 | Op1.getValueType().is64BitVector() && |
| 4600 | "unexpected types for extended operands to VMULL"); |
| 4601 | return DAG.getNode(NewOpc, DL, VT, Op0, Op1); |
| 4602 | } |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4603 | |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 4604 | // Optimizing (zext A + zext B) * C, to (VMULL A, C) + (VMULL B, C) during |
| 4605 | // isel lowering to take advantage of no-stall back to back vmul + vmla. |
| 4606 | // vmull q0, d4, d6 |
| 4607 | // vmlal q0, d5, d6 |
| 4608 | // is faster than |
| 4609 | // vaddl q0, d4, d5 |
| 4610 | // vmovl q1, d6 |
| 4611 | // vmul q0, q0, q1 |
| 4612 | SDValue N00 = SkipExtension(N0->getOperand(0).getNode(), DAG); |
| 4613 | SDValue N01 = SkipExtension(N0->getOperand(1).getNode(), DAG); |
| 4614 | EVT Op1VT = Op1.getValueType(); |
| 4615 | return DAG.getNode(N0->getOpcode(), DL, VT, |
| 4616 | DAG.getNode(NewOpc, DL, VT, |
| 4617 | DAG.getNode(ISD::BITCAST, DL, Op1VT, N00), Op1), |
| 4618 | DAG.getNode(NewOpc, DL, VT, |
| 4619 | DAG.getNode(ISD::BITCAST, DL, Op1VT, N01), Op1)); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4620 | } |
| 4621 | |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4622 | static SDValue |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4623 | LowerSDIV_v4i8(SDValue X, SDValue Y, DebugLoc dl, SelectionDAG &DAG) { |
| 4624 | // Convert to float |
| 4625 | // float4 xf = vcvt_f32_s32(vmovl_s16(a.lo)); |
| 4626 | // float4 yf = vcvt_f32_s32(vmovl_s16(b.lo)); |
| 4627 | X = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, X); |
| 4628 | Y = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, Y); |
| 4629 | X = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, X); |
| 4630 | Y = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, Y); |
| 4631 | // Get reciprocal estimate. |
| 4632 | // float4 recip = vrecpeq_f32(yf); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4633 | Y = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4634 | DAG.getConstant(Intrinsic::arm_neon_vrecpe, MVT::i32), Y); |
| 4635 | // Because char has a smaller range than uchar, we can actually get away |
| 4636 | // without any newton steps. This requires that we use a weird bias |
| 4637 | // of 0xb000, however (again, this has been exhaustively tested). |
| 4638 | // float4 result = as_float4(as_int4(xf*recip) + 0xb000); |
| 4639 | X = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, X, Y); |
| 4640 | X = DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, X); |
| 4641 | Y = DAG.getConstant(0xb000, MVT::i32); |
| 4642 | Y = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, Y, Y, Y, Y); |
| 4643 | X = DAG.getNode(ISD::ADD, dl, MVT::v4i32, X, Y); |
| 4644 | X = DAG.getNode(ISD::BITCAST, dl, MVT::v4f32, X); |
| 4645 | // Convert back to short. |
| 4646 | X = DAG.getNode(ISD::FP_TO_SINT, dl, MVT::v4i32, X); |
| 4647 | X = DAG.getNode(ISD::TRUNCATE, dl, MVT::v4i16, X); |
| 4648 | return X; |
| 4649 | } |
| 4650 | |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4651 | static SDValue |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4652 | LowerSDIV_v4i16(SDValue N0, SDValue N1, DebugLoc dl, SelectionDAG &DAG) { |
| 4653 | SDValue N2; |
| 4654 | // Convert to float. |
| 4655 | // float4 yf = vcvt_f32_s32(vmovl_s16(y)); |
| 4656 | // float4 xf = vcvt_f32_s32(vmovl_s16(x)); |
| 4657 | N0 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, N0); |
| 4658 | N1 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, N1); |
| 4659 | N0 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N0); |
| 4660 | N1 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4661 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4662 | // Use reciprocal estimate and one refinement step. |
| 4663 | // float4 recip = vrecpeq_f32(yf); |
| 4664 | // recip *= vrecpsq_f32(yf, recip); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4665 | N2 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4666 | DAG.getConstant(Intrinsic::arm_neon_vrecpe, MVT::i32), N1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4667 | N1 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4668 | DAG.getConstant(Intrinsic::arm_neon_vrecps, MVT::i32), |
| 4669 | N1, N2); |
| 4670 | N2 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N1, N2); |
| 4671 | // Because short has a smaller range than ushort, we can actually get away |
| 4672 | // with only a single newton step. This requires that we use a weird bias |
| 4673 | // of 89, however (again, this has been exhaustively tested). |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 4674 | // float4 result = as_float4(as_int4(xf*recip) + 0x89); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4675 | N0 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N0, N2); |
| 4676 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, N0); |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 4677 | N1 = DAG.getConstant(0x89, MVT::i32); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4678 | N1 = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, N1, N1, N1, N1); |
| 4679 | N0 = DAG.getNode(ISD::ADD, dl, MVT::v4i32, N0, N1); |
| 4680 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4f32, N0); |
| 4681 | // Convert back to integer and return. |
| 4682 | // return vmovn_s32(vcvt_s32_f32(result)); |
| 4683 | N0 = DAG.getNode(ISD::FP_TO_SINT, dl, MVT::v4i32, N0); |
| 4684 | N0 = DAG.getNode(ISD::TRUNCATE, dl, MVT::v4i16, N0); |
| 4685 | return N0; |
| 4686 | } |
| 4687 | |
| 4688 | static SDValue LowerSDIV(SDValue Op, SelectionDAG &DAG) { |
| 4689 | EVT VT = Op.getValueType(); |
| 4690 | assert((VT == MVT::v4i16 || VT == MVT::v8i8) && |
| 4691 | "unexpected type for custom-lowering ISD::SDIV"); |
| 4692 | |
| 4693 | DebugLoc dl = Op.getDebugLoc(); |
| 4694 | SDValue N0 = Op.getOperand(0); |
| 4695 | SDValue N1 = Op.getOperand(1); |
| 4696 | SDValue N2, N3; |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4697 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4698 | if (VT == MVT::v8i8) { |
| 4699 | N0 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v8i16, N0); |
| 4700 | N1 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v8i16, N1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4701 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4702 | N2 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| 4703 | DAG.getIntPtrConstant(4)); |
| 4704 | N3 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4705 | DAG.getIntPtrConstant(4)); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4706 | N0 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| 4707 | DAG.getIntPtrConstant(0)); |
| 4708 | N1 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
| 4709 | DAG.getIntPtrConstant(0)); |
| 4710 | |
| 4711 | N0 = LowerSDIV_v4i8(N0, N1, dl, DAG); // v4i16 |
| 4712 | N2 = LowerSDIV_v4i8(N2, N3, dl, DAG); // v4i16 |
| 4713 | |
| 4714 | N0 = DAG.getNode(ISD::CONCAT_VECTORS, dl, MVT::v8i16, N0, N2); |
| 4715 | N0 = LowerCONCAT_VECTORS(N0, DAG); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4716 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4717 | N0 = DAG.getNode(ISD::TRUNCATE, dl, MVT::v8i8, N0); |
| 4718 | return N0; |
| 4719 | } |
| 4720 | return LowerSDIV_v4i16(N0, N1, dl, DAG); |
| 4721 | } |
| 4722 | |
| 4723 | static SDValue LowerUDIV(SDValue Op, SelectionDAG &DAG) { |
| 4724 | EVT VT = Op.getValueType(); |
| 4725 | assert((VT == MVT::v4i16 || VT == MVT::v8i8) && |
| 4726 | "unexpected type for custom-lowering ISD::UDIV"); |
| 4727 | |
| 4728 | DebugLoc dl = Op.getDebugLoc(); |
| 4729 | SDValue N0 = Op.getOperand(0); |
| 4730 | SDValue N1 = Op.getOperand(1); |
| 4731 | SDValue N2, N3; |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4732 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4733 | if (VT == MVT::v8i8) { |
| 4734 | N0 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v8i16, N0); |
| 4735 | N1 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v8i16, N1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4736 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4737 | N2 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| 4738 | DAG.getIntPtrConstant(4)); |
| 4739 | N3 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4740 | DAG.getIntPtrConstant(4)); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4741 | N0 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| 4742 | DAG.getIntPtrConstant(0)); |
| 4743 | N1 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
| 4744 | DAG.getIntPtrConstant(0)); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4745 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4746 | N0 = LowerSDIV_v4i16(N0, N1, dl, DAG); // v4i16 |
| 4747 | N2 = LowerSDIV_v4i16(N2, N3, dl, DAG); // v4i16 |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4748 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4749 | N0 = DAG.getNode(ISD::CONCAT_VECTORS, dl, MVT::v8i16, N0, N2); |
| 4750 | N0 = LowerCONCAT_VECTORS(N0, DAG); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4751 | |
| 4752 | N0 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v8i8, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4753 | DAG.getConstant(Intrinsic::arm_neon_vqmovnsu, MVT::i32), |
| 4754 | N0); |
| 4755 | return N0; |
| 4756 | } |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4757 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4758 | // v4i16 sdiv ... Convert to float. |
| 4759 | // float4 yf = vcvt_f32_s32(vmovl_u16(y)); |
| 4760 | // float4 xf = vcvt_f32_s32(vmovl_u16(x)); |
| 4761 | N0 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v4i32, N0); |
| 4762 | N1 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v4i32, N1); |
| 4763 | N0 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N0); |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 4764 | SDValue BN1 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N1); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4765 | |
| 4766 | // Use reciprocal estimate and two refinement steps. |
| 4767 | // float4 recip = vrecpeq_f32(yf); |
| 4768 | // recip *= vrecpsq_f32(yf, recip); |
| 4769 | // recip *= vrecpsq_f32(yf, recip); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4770 | N2 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 4771 | DAG.getConstant(Intrinsic::arm_neon_vrecpe, MVT::i32), BN1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4772 | N1 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4773 | DAG.getConstant(Intrinsic::arm_neon_vrecps, MVT::i32), |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 4774 | BN1, N2); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4775 | N2 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N1, N2); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4776 | N1 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4777 | DAG.getConstant(Intrinsic::arm_neon_vrecps, MVT::i32), |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 4778 | BN1, N2); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4779 | N2 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N1, N2); |
| 4780 | // Simply multiplying by the reciprocal estimate can leave us a few ulps |
| 4781 | // too low, so we add 2 ulps (exhaustive testing shows that this is enough, |
| 4782 | // 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] | 4783 | // float4 result = as_float4(as_int4(xf*recip) + 2); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4784 | N0 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N0, N2); |
| 4785 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, N0); |
| 4786 | N1 = DAG.getConstant(2, MVT::i32); |
| 4787 | N1 = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, N1, N1, N1, N1); |
| 4788 | N0 = DAG.getNode(ISD::ADD, dl, MVT::v4i32, N0, N1); |
| 4789 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4f32, N0); |
| 4790 | // Convert back to integer and return. |
| 4791 | // return vmovn_u32(vcvt_s32_f32(result)); |
| 4792 | N0 = DAG.getNode(ISD::FP_TO_SINT, dl, MVT::v4i32, N0); |
| 4793 | N0 = DAG.getNode(ISD::TRUNCATE, dl, MVT::v4i16, N0); |
| 4794 | return N0; |
| 4795 | } |
| 4796 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 4797 | SDValue ARMTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4798 | switch (Op.getOpcode()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 4799 | default: llvm_unreachable("Don't know how to custom lower this!"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4800 | case ISD::ConstantPool: return LowerConstantPool(Op, DAG); |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 4801 | case ISD::BlockAddress: return LowerBlockAddress(Op, DAG); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 4802 | case ISD::GlobalAddress: |
| 4803 | return Subtarget->isTargetDarwin() ? LowerGlobalAddressDarwin(Op, DAG) : |
| 4804 | LowerGlobalAddressELF(Op, DAG); |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4805 | case ISD::GlobalTLSAddress: return LowerGlobalTLSAddress(Op, DAG); |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 4806 | case ISD::SELECT: return LowerSELECT(Op, DAG); |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 4807 | case ISD::SELECT_CC: return LowerSELECT_CC(Op, DAG); |
| 4808 | case ISD::BR_CC: return LowerBR_CC(Op, DAG); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4809 | case ISD::BR_JT: return LowerBR_JT(Op, DAG); |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 4810 | case ISD::VASTART: return LowerVASTART(Op, DAG); |
Jim Grosbach | 7c03dbd | 2009-12-14 21:24:16 +0000 | [diff] [blame] | 4811 | case ISD::MEMBARRIER: return LowerMEMBARRIER(Op, DAG, Subtarget); |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 4812 | case ISD::PREFETCH: return LowerPREFETCH(Op, DAG, Subtarget); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 4813 | case ISD::SINT_TO_FP: |
| 4814 | case ISD::UINT_TO_FP: return LowerINT_TO_FP(Op, DAG); |
| 4815 | case ISD::FP_TO_SINT: |
| 4816 | case ISD::FP_TO_UINT: return LowerFP_TO_INT(Op, DAG); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4817 | case ISD::FCOPYSIGN: return LowerFCOPYSIGN(Op, DAG); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 4818 | case ISD::RETURNADDR: return LowerRETURNADDR(Op, DAG); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 4819 | case ISD::FRAMEADDR: return LowerFRAMEADDR(Op, DAG); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 4820 | case ISD::GLOBAL_OFFSET_TABLE: return LowerGLOBAL_OFFSET_TABLE(Op, DAG); |
Jim Grosbach | 23ff7cf | 2010-05-26 20:22:18 +0000 | [diff] [blame] | 4821 | case ISD::EH_SJLJ_SETJMP: return LowerEH_SJLJ_SETJMP(Op, DAG); |
Jim Grosbach | 5eb1951 | 2010-05-22 01:06:18 +0000 | [diff] [blame] | 4822 | case ISD::EH_SJLJ_LONGJMP: return LowerEH_SJLJ_LONGJMP(Op, DAG); |
Jim Grosbach | e4ad387 | 2010-10-19 23:27:08 +0000 | [diff] [blame] | 4823 | case ISD::EH_SJLJ_DISPATCHSETUP: return LowerEH_SJLJ_DISPATCHSETUP(Op, DAG); |
Jim Grosbach | a87ded2 | 2010-02-08 23:22:00 +0000 | [diff] [blame] | 4824 | case ISD::INTRINSIC_WO_CHAIN: return LowerINTRINSIC_WO_CHAIN(Op, DAG, |
| 4825 | Subtarget); |
Evan Cheng | 21a6179 | 2011-03-14 18:02:30 +0000 | [diff] [blame] | 4826 | case ISD::BITCAST: return ExpandBITCAST(Op.getNode(), DAG); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4827 | case ISD::SHL: |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4828 | case ISD::SRL: |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4829 | case ISD::SRA: return LowerShift(Op.getNode(), DAG, Subtarget); |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 4830 | case ISD::SHL_PARTS: return LowerShiftLeftParts(Op, DAG); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 4831 | case ISD::SRL_PARTS: |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 4832 | case ISD::SRA_PARTS: return LowerShiftRightParts(Op, DAG); |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 4833 | case ISD::CTTZ: return LowerCTTZ(Op.getNode(), DAG, Subtarget); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4834 | case ISD::VSETCC: return LowerVSETCC(Op, DAG); |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 4835 | case ISD::BUILD_VECTOR: return LowerBUILD_VECTOR(Op, DAG, Subtarget); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4836 | case ISD::VECTOR_SHUFFLE: return LowerVECTOR_SHUFFLE(Op, DAG); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4837 | case ISD::EXTRACT_VECTOR_ELT: return LowerEXTRACT_VECTOR_ELT(Op, DAG); |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 4838 | case ISD::CONCAT_VECTORS: return LowerCONCAT_VECTORS(Op, DAG); |
Bob Wilson | b31a11b | 2010-08-20 04:54:02 +0000 | [diff] [blame] | 4839 | case ISD::FLT_ROUNDS_: return LowerFLT_ROUNDS_(Op, DAG); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4840 | case ISD::MUL: return LowerMUL(Op, DAG); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4841 | case ISD::SDIV: return LowerSDIV(Op, DAG); |
| 4842 | case ISD::UDIV: return LowerUDIV(Op, DAG); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4843 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4844 | return SDValue(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4845 | } |
| 4846 | |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 4847 | /// ReplaceNodeResults - Replace the results of node with an illegal result |
| 4848 | /// type with new values built out of custom code. |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 4849 | void ARMTargetLowering::ReplaceNodeResults(SDNode *N, |
| 4850 | SmallVectorImpl<SDValue>&Results, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 4851 | SelectionDAG &DAG) const { |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 4852 | SDValue Res; |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4853 | switch (N->getOpcode()) { |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 4854 | default: |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 4855 | llvm_unreachable("Don't know how to custom expand this!"); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 4856 | break; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4857 | case ISD::BITCAST: |
| 4858 | Res = ExpandBITCAST(N, DAG); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 4859 | break; |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4860 | case ISD::SRL: |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 4861 | case ISD::SRA: |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 4862 | Res = Expand64BitShift(N, DAG, Subtarget); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 4863 | break; |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 4864 | } |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 4865 | if (Res.getNode()) |
| 4866 | Results.push_back(Res); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4867 | } |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4868 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4869 | //===----------------------------------------------------------------------===// |
| 4870 | // ARM Scheduler Hooks |
| 4871 | //===----------------------------------------------------------------------===// |
| 4872 | |
| 4873 | MachineBasicBlock * |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 4874 | ARMTargetLowering::EmitAtomicCmpSwap(MachineInstr *MI, |
| 4875 | MachineBasicBlock *BB, |
| 4876 | unsigned Size) const { |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4877 | unsigned dest = MI->getOperand(0).getReg(); |
| 4878 | unsigned ptr = MI->getOperand(1).getReg(); |
| 4879 | unsigned oldval = MI->getOperand(2).getReg(); |
| 4880 | unsigned newval = MI->getOperand(3).getReg(); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4881 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 4882 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4883 | bool isThumb2 = Subtarget->isThumb2(); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4884 | |
Cameron Zwarich | 7d336c0 | 2011-05-18 02:20:07 +0000 | [diff] [blame] | 4885 | MachineRegisterInfo &MRI = BB->getParent()->getRegInfo(); |
| 4886 | unsigned scratch = |
Cameron Zwarich | 141ec63 | 2011-05-18 02:29:50 +0000 | [diff] [blame] | 4887 | MRI.createVirtualRegister(isThumb2 ? ARM::rGPRRegisterClass |
Cameron Zwarich | 7d336c0 | 2011-05-18 02:20:07 +0000 | [diff] [blame] | 4888 | : ARM::GPRRegisterClass); |
| 4889 | |
| 4890 | if (isThumb2) { |
Cameron Zwarich | 141ec63 | 2011-05-18 02:29:50 +0000 | [diff] [blame] | 4891 | MRI.constrainRegClass(dest, ARM::rGPRRegisterClass); |
| 4892 | MRI.constrainRegClass(oldval, ARM::rGPRRegisterClass); |
| 4893 | MRI.constrainRegClass(newval, ARM::rGPRRegisterClass); |
Cameron Zwarich | 7d336c0 | 2011-05-18 02:20:07 +0000 | [diff] [blame] | 4894 | } |
| 4895 | |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4896 | unsigned ldrOpc, strOpc; |
| 4897 | switch (Size) { |
| 4898 | default: llvm_unreachable("unsupported size for AtomicCmpSwap!"); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4899 | case 1: |
| 4900 | ldrOpc = isThumb2 ? ARM::t2LDREXB : ARM::LDREXB; |
Evan Cheng | aa26102 | 2011-02-07 18:50:47 +0000 | [diff] [blame] | 4901 | strOpc = isThumb2 ? ARM::t2STREXB : ARM::STREXB; |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4902 | break; |
| 4903 | case 2: |
| 4904 | ldrOpc = isThumb2 ? ARM::t2LDREXH : ARM::LDREXH; |
| 4905 | strOpc = isThumb2 ? ARM::t2STREXH : ARM::STREXH; |
| 4906 | break; |
| 4907 | case 4: |
| 4908 | ldrOpc = isThumb2 ? ARM::t2LDREX : ARM::LDREX; |
| 4909 | strOpc = isThumb2 ? ARM::t2STREX : ARM::STREX; |
| 4910 | break; |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4911 | } |
| 4912 | |
| 4913 | MachineFunction *MF = BB->getParent(); |
| 4914 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 4915 | MachineFunction::iterator It = BB; |
| 4916 | ++It; // insert the new blocks after the current block |
| 4917 | |
| 4918 | MachineBasicBlock *loop1MBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 4919 | MachineBasicBlock *loop2MBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 4920 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 4921 | MF->insert(It, loop1MBB); |
| 4922 | MF->insert(It, loop2MBB); |
| 4923 | MF->insert(It, exitMBB); |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 4924 | |
| 4925 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 4926 | exitMBB->splice(exitMBB->begin(), BB, |
| 4927 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 4928 | BB->end()); |
| 4929 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4930 | |
| 4931 | // thisMBB: |
| 4932 | // ... |
| 4933 | // fallthrough --> loop1MBB |
| 4934 | BB->addSuccessor(loop1MBB); |
| 4935 | |
| 4936 | // loop1MBB: |
| 4937 | // ldrex dest, [ptr] |
| 4938 | // cmp dest, oldval |
| 4939 | // bne exitMBB |
| 4940 | BB = loop1MBB; |
| 4941 | AddDefaultPred(BuildMI(BB, dl, TII->get(ldrOpc), dest).addReg(ptr)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4942 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4943 | .addReg(dest).addReg(oldval)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4944 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 4945 | .addMBB(exitMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4946 | BB->addSuccessor(loop2MBB); |
| 4947 | BB->addSuccessor(exitMBB); |
| 4948 | |
| 4949 | // loop2MBB: |
| 4950 | // strex scratch, newval, [ptr] |
| 4951 | // cmp scratch, #0 |
| 4952 | // bne loop1MBB |
| 4953 | BB = loop2MBB; |
| 4954 | AddDefaultPred(BuildMI(BB, dl, TII->get(strOpc), scratch).addReg(newval) |
| 4955 | .addReg(ptr)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4956 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4957 | .addReg(scratch).addImm(0)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4958 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 4959 | .addMBB(loop1MBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4960 | BB->addSuccessor(loop1MBB); |
| 4961 | BB->addSuccessor(exitMBB); |
| 4962 | |
| 4963 | // exitMBB: |
| 4964 | // ... |
| 4965 | BB = exitMBB; |
Jim Grosbach | 5efaed3 | 2010-01-15 00:18:34 +0000 | [diff] [blame] | 4966 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 4967 | MI->eraseFromParent(); // The instruction is gone now. |
Jim Grosbach | 5efaed3 | 2010-01-15 00:18:34 +0000 | [diff] [blame] | 4968 | |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4969 | return BB; |
| 4970 | } |
| 4971 | |
| 4972 | MachineBasicBlock * |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 4973 | ARMTargetLowering::EmitAtomicBinary(MachineInstr *MI, MachineBasicBlock *BB, |
| 4974 | unsigned Size, unsigned BinOpcode) const { |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 4975 | // This also handles ATOMIC_SWAP, indicated by BinOpcode==0. |
| 4976 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 4977 | |
| 4978 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
Jim Grosbach | 867bbbf | 2010-01-15 00:22:18 +0000 | [diff] [blame] | 4979 | MachineFunction *MF = BB->getParent(); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 4980 | MachineFunction::iterator It = BB; |
| 4981 | ++It; |
| 4982 | |
| 4983 | unsigned dest = MI->getOperand(0).getReg(); |
| 4984 | unsigned ptr = MI->getOperand(1).getReg(); |
| 4985 | unsigned incr = MI->getOperand(2).getReg(); |
| 4986 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4987 | bool isThumb2 = Subtarget->isThumb2(); |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 4988 | |
| 4989 | MachineRegisterInfo &MRI = BB->getParent()->getRegInfo(); |
| 4990 | if (isThumb2) { |
| 4991 | MRI.constrainRegClass(dest, ARM::rGPRRegisterClass); |
| 4992 | MRI.constrainRegClass(ptr, ARM::rGPRRegisterClass); |
| 4993 | } |
| 4994 | |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 4995 | unsigned ldrOpc, strOpc; |
| 4996 | switch (Size) { |
| 4997 | default: llvm_unreachable("unsupported size for AtomicCmpSwap!"); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4998 | case 1: |
| 4999 | ldrOpc = isThumb2 ? ARM::t2LDREXB : ARM::LDREXB; |
Jakob Stoklund Olesen | 15913c9 | 2010-01-13 19:54:39 +0000 | [diff] [blame] | 5000 | strOpc = isThumb2 ? ARM::t2STREXB : ARM::STREXB; |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5001 | break; |
| 5002 | case 2: |
| 5003 | ldrOpc = isThumb2 ? ARM::t2LDREXH : ARM::LDREXH; |
| 5004 | strOpc = isThumb2 ? ARM::t2STREXH : ARM::STREXH; |
| 5005 | break; |
| 5006 | case 4: |
| 5007 | ldrOpc = isThumb2 ? ARM::t2LDREX : ARM::LDREX; |
| 5008 | strOpc = isThumb2 ? ARM::t2STREX : ARM::STREX; |
| 5009 | break; |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5010 | } |
| 5011 | |
Jim Grosbach | 867bbbf | 2010-01-15 00:22:18 +0000 | [diff] [blame] | 5012 | MachineBasicBlock *loopMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5013 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5014 | MF->insert(It, loopMBB); |
| 5015 | MF->insert(It, exitMBB); |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 5016 | |
| 5017 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 5018 | exitMBB->splice(exitMBB->begin(), BB, |
| 5019 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 5020 | BB->end()); |
| 5021 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5022 | |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 5023 | TargetRegisterClass *TRC = |
| 5024 | isThumb2 ? ARM::tGPRRegisterClass : ARM::GPRRegisterClass; |
| 5025 | unsigned scratch = MRI.createVirtualRegister(TRC); |
| 5026 | unsigned scratch2 = (!BinOpcode) ? incr : MRI.createVirtualRegister(TRC); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5027 | |
| 5028 | // thisMBB: |
| 5029 | // ... |
| 5030 | // fallthrough --> loopMBB |
| 5031 | BB->addSuccessor(loopMBB); |
| 5032 | |
| 5033 | // loopMBB: |
| 5034 | // ldrex dest, ptr |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5035 | // <binop> scratch2, dest, incr |
| 5036 | // strex scratch, scratch2, ptr |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5037 | // cmp scratch, #0 |
| 5038 | // bne- loopMBB |
| 5039 | // fallthrough --> exitMBB |
| 5040 | BB = loopMBB; |
| 5041 | AddDefaultPred(BuildMI(BB, dl, TII->get(ldrOpc), dest).addReg(ptr)); |
Jim Grosbach | c67b556 | 2009-12-15 00:12:35 +0000 | [diff] [blame] | 5042 | if (BinOpcode) { |
| 5043 | // operand order needs to go the other way for NAND |
| 5044 | if (BinOpcode == ARM::BICrr || BinOpcode == ARM::t2BICrr) |
| 5045 | AddDefaultPred(BuildMI(BB, dl, TII->get(BinOpcode), scratch2). |
| 5046 | addReg(incr).addReg(dest)).addReg(0); |
| 5047 | else |
| 5048 | AddDefaultPred(BuildMI(BB, dl, TII->get(BinOpcode), scratch2). |
| 5049 | addReg(dest).addReg(incr)).addReg(0); |
| 5050 | } |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5051 | |
| 5052 | AddDefaultPred(BuildMI(BB, dl, TII->get(strOpc), scratch).addReg(scratch2) |
| 5053 | .addReg(ptr)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5054 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5055 | .addReg(scratch).addImm(0)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5056 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 5057 | .addMBB(loopMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5058 | |
| 5059 | BB->addSuccessor(loopMBB); |
| 5060 | BB->addSuccessor(exitMBB); |
| 5061 | |
| 5062 | // exitMBB: |
| 5063 | // ... |
| 5064 | BB = exitMBB; |
Evan Cheng | 102ebf1 | 2009-12-21 19:53:39 +0000 | [diff] [blame] | 5065 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 5066 | MI->eraseFromParent(); // The instruction is gone now. |
Evan Cheng | 102ebf1 | 2009-12-21 19:53:39 +0000 | [diff] [blame] | 5067 | |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5068 | return BB; |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 5069 | } |
| 5070 | |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5071 | MachineBasicBlock * |
| 5072 | ARMTargetLowering::EmitAtomicBinaryMinMax(MachineInstr *MI, |
| 5073 | MachineBasicBlock *BB, |
| 5074 | unsigned Size, |
| 5075 | bool signExtend, |
| 5076 | ARMCC::CondCodes Cond) const { |
| 5077 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 5078 | |
| 5079 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 5080 | MachineFunction *MF = BB->getParent(); |
| 5081 | MachineFunction::iterator It = BB; |
| 5082 | ++It; |
| 5083 | |
| 5084 | unsigned dest = MI->getOperand(0).getReg(); |
| 5085 | unsigned ptr = MI->getOperand(1).getReg(); |
| 5086 | unsigned incr = MI->getOperand(2).getReg(); |
| 5087 | unsigned oldval = dest; |
| 5088 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5089 | bool isThumb2 = Subtarget->isThumb2(); |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 5090 | |
| 5091 | MachineRegisterInfo &MRI = BB->getParent()->getRegInfo(); |
| 5092 | if (isThumb2) { |
| 5093 | MRI.constrainRegClass(dest, ARM::rGPRRegisterClass); |
| 5094 | MRI.constrainRegClass(ptr, ARM::rGPRRegisterClass); |
| 5095 | } |
| 5096 | |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5097 | unsigned ldrOpc, strOpc, extendOpc; |
| 5098 | switch (Size) { |
| 5099 | default: llvm_unreachable("unsupported size for AtomicCmpSwap!"); |
| 5100 | case 1: |
| 5101 | ldrOpc = isThumb2 ? ARM::t2LDREXB : ARM::LDREXB; |
| 5102 | strOpc = isThumb2 ? ARM::t2STREXB : ARM::STREXB; |
| 5103 | extendOpc = isThumb2 ? ARM::t2SXTBr : ARM::SXTBr; |
| 5104 | break; |
| 5105 | case 2: |
| 5106 | ldrOpc = isThumb2 ? ARM::t2LDREXH : ARM::LDREXH; |
| 5107 | strOpc = isThumb2 ? ARM::t2STREXH : ARM::STREXH; |
| 5108 | extendOpc = isThumb2 ? ARM::t2SXTHr : ARM::SXTHr; |
| 5109 | break; |
| 5110 | case 4: |
| 5111 | ldrOpc = isThumb2 ? ARM::t2LDREX : ARM::LDREX; |
| 5112 | strOpc = isThumb2 ? ARM::t2STREX : ARM::STREX; |
| 5113 | extendOpc = 0; |
| 5114 | break; |
| 5115 | } |
| 5116 | |
| 5117 | MachineBasicBlock *loopMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5118 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5119 | MF->insert(It, loopMBB); |
| 5120 | MF->insert(It, exitMBB); |
| 5121 | |
| 5122 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 5123 | exitMBB->splice(exitMBB->begin(), BB, |
| 5124 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 5125 | BB->end()); |
| 5126 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
| 5127 | |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 5128 | TargetRegisterClass *TRC = |
| 5129 | isThumb2 ? ARM::tGPRRegisterClass : ARM::GPRRegisterClass; |
| 5130 | unsigned scratch = MRI.createVirtualRegister(TRC); |
| 5131 | unsigned scratch2 = MRI.createVirtualRegister(TRC); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5132 | |
| 5133 | // thisMBB: |
| 5134 | // ... |
| 5135 | // fallthrough --> loopMBB |
| 5136 | BB->addSuccessor(loopMBB); |
| 5137 | |
| 5138 | // loopMBB: |
| 5139 | // ldrex dest, ptr |
| 5140 | // (sign extend dest, if required) |
| 5141 | // cmp dest, incr |
| 5142 | // cmov.cond scratch2, dest, incr |
| 5143 | // strex scratch, scratch2, ptr |
| 5144 | // cmp scratch, #0 |
| 5145 | // bne- loopMBB |
| 5146 | // fallthrough --> exitMBB |
| 5147 | BB = loopMBB; |
| 5148 | AddDefaultPred(BuildMI(BB, dl, TII->get(ldrOpc), dest).addReg(ptr)); |
| 5149 | |
| 5150 | // Sign extend the value, if necessary. |
| 5151 | if (signExtend && extendOpc) { |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 5152 | oldval = MRI.createVirtualRegister(ARM::GPRRegisterClass); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5153 | AddDefaultPred(BuildMI(BB, dl, TII->get(extendOpc), oldval).addReg(dest)); |
| 5154 | } |
| 5155 | |
| 5156 | // Build compare and cmov instructions. |
| 5157 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
| 5158 | .addReg(oldval).addReg(incr)); |
| 5159 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2MOVCCr : ARM::MOVCCr), scratch2) |
| 5160 | .addReg(oldval).addReg(incr).addImm(Cond).addReg(ARM::CPSR); |
| 5161 | |
| 5162 | AddDefaultPred(BuildMI(BB, dl, TII->get(strOpc), scratch).addReg(scratch2) |
| 5163 | .addReg(ptr)); |
| 5164 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 5165 | .addReg(scratch).addImm(0)); |
| 5166 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 5167 | .addMBB(loopMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
| 5168 | |
| 5169 | BB->addSuccessor(loopMBB); |
| 5170 | BB->addSuccessor(exitMBB); |
| 5171 | |
| 5172 | // exitMBB: |
| 5173 | // ... |
| 5174 | BB = exitMBB; |
| 5175 | |
| 5176 | MI->eraseFromParent(); // The instruction is gone now. |
| 5177 | |
| 5178 | return BB; |
| 5179 | } |
| 5180 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 5181 | static |
| 5182 | MachineBasicBlock *OtherSucc(MachineBasicBlock *MBB, MachineBasicBlock *Succ) { |
| 5183 | for (MachineBasicBlock::succ_iterator I = MBB->succ_begin(), |
| 5184 | E = MBB->succ_end(); I != E; ++I) |
| 5185 | if (*I != Succ) |
| 5186 | return *I; |
| 5187 | llvm_unreachable("Expecting a BB with two successors!"); |
| 5188 | } |
| 5189 | |
Andrew Trick | 1c3af77 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 5190 | // FIXME: This opcode table should obviously be expressed in the target |
| 5191 | // description. We probably just need a "machine opcode" value in the pseudo |
| 5192 | // instruction. But the ideal solution maybe to simply remove the "S" version |
| 5193 | // of the opcode altogether. |
| 5194 | struct AddSubFlagsOpcodePair { |
| 5195 | unsigned PseudoOpc; |
| 5196 | unsigned MachineOpc; |
| 5197 | }; |
| 5198 | |
| 5199 | static AddSubFlagsOpcodePair AddSubFlagsOpcodeMap[] = { |
| 5200 | {ARM::ADCSri, ARM::ADCri}, |
| 5201 | {ARM::ADCSrr, ARM::ADCrr}, |
| 5202 | {ARM::ADCSrs, ARM::ADCrs}, |
| 5203 | {ARM::SBCSri, ARM::SBCri}, |
| 5204 | {ARM::SBCSrr, ARM::SBCrr}, |
| 5205 | {ARM::SBCSrs, ARM::SBCrs}, |
| 5206 | {ARM::RSBSri, ARM::RSBri}, |
| 5207 | {ARM::RSBSrr, ARM::RSBrr}, |
| 5208 | {ARM::RSBSrs, ARM::RSBrs}, |
| 5209 | {ARM::RSCSri, ARM::RSCri}, |
| 5210 | {ARM::RSCSrs, ARM::RSCrs}, |
| 5211 | {ARM::t2ADCSri, ARM::t2ADCri}, |
| 5212 | {ARM::t2ADCSrr, ARM::t2ADCrr}, |
| 5213 | {ARM::t2ADCSrs, ARM::t2ADCrs}, |
| 5214 | {ARM::t2SBCSri, ARM::t2SBCri}, |
| 5215 | {ARM::t2SBCSrr, ARM::t2SBCrr}, |
| 5216 | {ARM::t2SBCSrs, ARM::t2SBCrs}, |
| 5217 | {ARM::t2RSBSri, ARM::t2RSBri}, |
| 5218 | {ARM::t2RSBSrs, ARM::t2RSBrs}, |
| 5219 | }; |
| 5220 | |
| 5221 | // Convert and Add or Subtract with Carry and Flags to a generic opcode with |
| 5222 | // CPSR<def> operand. e.g. ADCS (...) -> ADC (... CPSR<def>). |
| 5223 | // |
| 5224 | // FIXME: Somewhere we should assert that CPSR<def> is in the correct |
| 5225 | // position to be recognized by the target descrition as the 'S' bit. |
| 5226 | bool ARMTargetLowering::RemapAddSubWithFlags(MachineInstr *MI, |
| 5227 | MachineBasicBlock *BB) const { |
| 5228 | unsigned OldOpc = MI->getOpcode(); |
| 5229 | unsigned NewOpc = 0; |
| 5230 | |
| 5231 | // This is only called for instructions that need remapping, so iterating over |
| 5232 | // the tiny opcode table is not costly. |
| 5233 | static const int NPairs = |
| 5234 | sizeof(AddSubFlagsOpcodeMap) / sizeof(AddSubFlagsOpcodePair); |
| 5235 | for (AddSubFlagsOpcodePair *Pair = &AddSubFlagsOpcodeMap[0], |
| 5236 | *End = &AddSubFlagsOpcodeMap[NPairs]; Pair != End; ++Pair) { |
| 5237 | if (OldOpc == Pair->PseudoOpc) { |
| 5238 | NewOpc = Pair->MachineOpc; |
| 5239 | break; |
| 5240 | } |
| 5241 | } |
| 5242 | if (!NewOpc) |
| 5243 | return false; |
| 5244 | |
| 5245 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 5246 | DebugLoc dl = MI->getDebugLoc(); |
| 5247 | MachineInstrBuilder MIB = BuildMI(*BB, MI, dl, TII->get(NewOpc)); |
| 5248 | for (unsigned i = 0; i < MI->getNumOperands(); ++i) |
| 5249 | MIB.addOperand(MI->getOperand(i)); |
| 5250 | AddDefaultPred(MIB); |
| 5251 | MIB.addReg(ARM::CPSR, RegState::Define); // S bit |
| 5252 | MI->eraseFromParent(); |
| 5253 | return true; |
| 5254 | } |
| 5255 | |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 5256 | MachineBasicBlock * |
Evan Cheng | ff9b373 | 2008-01-30 18:18:23 +0000 | [diff] [blame] | 5257 | ARMTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI, |
Dan Gohman | af1d8ca | 2010-05-01 00:01:06 +0000 | [diff] [blame] | 5258 | MachineBasicBlock *BB) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5259 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
Dale Johannesen | b672840 | 2009-02-13 02:25:56 +0000 | [diff] [blame] | 5260 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5261 | bool isThumb2 = Subtarget->isThumb2(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5262 | switch (MI->getOpcode()) { |
Andrew Trick | 1c3af77 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 5263 | default: { |
| 5264 | if (RemapAddSubWithFlags(MI, BB)) |
| 5265 | return BB; |
| 5266 | |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5267 | MI->dump(); |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 5268 | llvm_unreachable("Unexpected instr type to insert"); |
Andrew Trick | 1c3af77 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 5269 | } |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5270 | case ARM::ATOMIC_LOAD_ADD_I8: |
| 5271 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr); |
| 5272 | case ARM::ATOMIC_LOAD_ADD_I16: |
| 5273 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr); |
| 5274 | case ARM::ATOMIC_LOAD_ADD_I32: |
| 5275 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5276 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5277 | case ARM::ATOMIC_LOAD_AND_I8: |
| 5278 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
| 5279 | case ARM::ATOMIC_LOAD_AND_I16: |
| 5280 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
| 5281 | case ARM::ATOMIC_LOAD_AND_I32: |
| 5282 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5283 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5284 | case ARM::ATOMIC_LOAD_OR_I8: |
| 5285 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
| 5286 | case ARM::ATOMIC_LOAD_OR_I16: |
| 5287 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
| 5288 | case ARM::ATOMIC_LOAD_OR_I32: |
| 5289 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5290 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5291 | case ARM::ATOMIC_LOAD_XOR_I8: |
| 5292 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
| 5293 | case ARM::ATOMIC_LOAD_XOR_I16: |
| 5294 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
| 5295 | case ARM::ATOMIC_LOAD_XOR_I32: |
| 5296 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 5297 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5298 | case ARM::ATOMIC_LOAD_NAND_I8: |
| 5299 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2BICrr : ARM::BICrr); |
| 5300 | case ARM::ATOMIC_LOAD_NAND_I16: |
| 5301 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2BICrr : ARM::BICrr); |
| 5302 | case ARM::ATOMIC_LOAD_NAND_I32: |
| 5303 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2BICrr : ARM::BICrr); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 5304 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5305 | case ARM::ATOMIC_LOAD_SUB_I8: |
| 5306 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr); |
| 5307 | case ARM::ATOMIC_LOAD_SUB_I16: |
| 5308 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr); |
| 5309 | case ARM::ATOMIC_LOAD_SUB_I32: |
| 5310 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 5311 | |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5312 | case ARM::ATOMIC_LOAD_MIN_I8: |
| 5313 | return EmitAtomicBinaryMinMax(MI, BB, 1, true, ARMCC::LT); |
| 5314 | case ARM::ATOMIC_LOAD_MIN_I16: |
| 5315 | return EmitAtomicBinaryMinMax(MI, BB, 2, true, ARMCC::LT); |
| 5316 | case ARM::ATOMIC_LOAD_MIN_I32: |
| 5317 | return EmitAtomicBinaryMinMax(MI, BB, 4, true, ARMCC::LT); |
| 5318 | |
| 5319 | case ARM::ATOMIC_LOAD_MAX_I8: |
| 5320 | return EmitAtomicBinaryMinMax(MI, BB, 1, true, ARMCC::GT); |
| 5321 | case ARM::ATOMIC_LOAD_MAX_I16: |
| 5322 | return EmitAtomicBinaryMinMax(MI, BB, 2, true, ARMCC::GT); |
| 5323 | case ARM::ATOMIC_LOAD_MAX_I32: |
| 5324 | return EmitAtomicBinaryMinMax(MI, BB, 4, true, ARMCC::GT); |
| 5325 | |
| 5326 | case ARM::ATOMIC_LOAD_UMIN_I8: |
| 5327 | return EmitAtomicBinaryMinMax(MI, BB, 1, false, ARMCC::LO); |
| 5328 | case ARM::ATOMIC_LOAD_UMIN_I16: |
| 5329 | return EmitAtomicBinaryMinMax(MI, BB, 2, false, ARMCC::LO); |
| 5330 | case ARM::ATOMIC_LOAD_UMIN_I32: |
| 5331 | return EmitAtomicBinaryMinMax(MI, BB, 4, false, ARMCC::LO); |
| 5332 | |
| 5333 | case ARM::ATOMIC_LOAD_UMAX_I8: |
| 5334 | return EmitAtomicBinaryMinMax(MI, BB, 1, false, ARMCC::HI); |
| 5335 | case ARM::ATOMIC_LOAD_UMAX_I16: |
| 5336 | return EmitAtomicBinaryMinMax(MI, BB, 2, false, ARMCC::HI); |
| 5337 | case ARM::ATOMIC_LOAD_UMAX_I32: |
| 5338 | return EmitAtomicBinaryMinMax(MI, BB, 4, false, ARMCC::HI); |
| 5339 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5340 | case ARM::ATOMIC_SWAP_I8: return EmitAtomicBinary(MI, BB, 1, 0); |
| 5341 | case ARM::ATOMIC_SWAP_I16: return EmitAtomicBinary(MI, BB, 2, 0); |
| 5342 | case ARM::ATOMIC_SWAP_I32: return EmitAtomicBinary(MI, BB, 4, 0); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 5343 | |
| 5344 | case ARM::ATOMIC_CMP_SWAP_I8: return EmitAtomicCmpSwap(MI, BB, 1); |
| 5345 | case ARM::ATOMIC_CMP_SWAP_I16: return EmitAtomicCmpSwap(MI, BB, 2); |
| 5346 | case ARM::ATOMIC_CMP_SWAP_I32: return EmitAtomicCmpSwap(MI, BB, 4); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5347 | |
Evan Cheng | 007ea27 | 2009-08-12 05:17:19 +0000 | [diff] [blame] | 5348 | case ARM::tMOVCCr_pseudo: { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5349 | // To "insert" a SELECT_CC instruction, we actually have to insert the |
| 5350 | // diamond control-flow pattern. The incoming instruction knows the |
| 5351 | // destination vreg to set, the condition code register to branch on, the |
| 5352 | // true/false values to select between, and a branch opcode to use. |
| 5353 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 5354 | MachineFunction::iterator It = BB; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5355 | ++It; |
| 5356 | |
| 5357 | // thisMBB: |
| 5358 | // ... |
| 5359 | // TrueVal = ... |
| 5360 | // cmpTY ccX, r1, r2 |
| 5361 | // bCC copy1MBB |
| 5362 | // fallthrough --> copy0MBB |
| 5363 | MachineBasicBlock *thisMBB = BB; |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 5364 | MachineFunction *F = BB->getParent(); |
| 5365 | MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB); |
| 5366 | MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB); |
Dan Gohman | 258c58c | 2010-07-06 15:49:48 +0000 | [diff] [blame] | 5367 | F->insert(It, copy0MBB); |
| 5368 | F->insert(It, sinkMBB); |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 5369 | |
| 5370 | // Transfer the remainder of BB and its successor edges to sinkMBB. |
| 5371 | sinkMBB->splice(sinkMBB->begin(), BB, |
| 5372 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 5373 | BB->end()); |
| 5374 | sinkMBB->transferSuccessorsAndUpdatePHIs(BB); |
| 5375 | |
Dan Gohman | 258c58c | 2010-07-06 15:49:48 +0000 | [diff] [blame] | 5376 | BB->addSuccessor(copy0MBB); |
| 5377 | BB->addSuccessor(sinkMBB); |
Dan Gohman | b81c771 | 2010-07-06 15:18:19 +0000 | [diff] [blame] | 5378 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 5379 | BuildMI(BB, dl, TII->get(ARM::tBcc)).addMBB(sinkMBB) |
| 5380 | .addImm(MI->getOperand(3).getImm()).addReg(MI->getOperand(4).getReg()); |
| 5381 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5382 | // copy0MBB: |
| 5383 | // %FalseValue = ... |
| 5384 | // # fallthrough to sinkMBB |
| 5385 | BB = copy0MBB; |
| 5386 | |
| 5387 | // Update machine-CFG edges |
| 5388 | BB->addSuccessor(sinkMBB); |
| 5389 | |
| 5390 | // sinkMBB: |
| 5391 | // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ] |
| 5392 | // ... |
| 5393 | BB = sinkMBB; |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 5394 | BuildMI(*BB, BB->begin(), dl, |
| 5395 | TII->get(ARM::PHI), MI->getOperand(0).getReg()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5396 | .addReg(MI->getOperand(1).getReg()).addMBB(copy0MBB) |
| 5397 | .addReg(MI->getOperand(2).getReg()).addMBB(thisMBB); |
| 5398 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 5399 | MI->eraseFromParent(); // The pseudo instruction is gone now. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5400 | return BB; |
| 5401 | } |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 5402 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 5403 | case ARM::BCCi64: |
| 5404 | case ARM::BCCZi64: { |
Bob Wilson | 3c90469 | 2010-12-23 22:45:49 +0000 | [diff] [blame] | 5405 | // If there is an unconditional branch to the other successor, remove it. |
| 5406 | BB->erase(llvm::next(MachineBasicBlock::iterator(MI)), BB->end()); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 5407 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 5408 | // Compare both parts that make up the double comparison separately for |
| 5409 | // equality. |
| 5410 | bool RHSisZero = MI->getOpcode() == ARM::BCCZi64; |
| 5411 | |
| 5412 | unsigned LHS1 = MI->getOperand(1).getReg(); |
| 5413 | unsigned LHS2 = MI->getOperand(2).getReg(); |
| 5414 | if (RHSisZero) { |
| 5415 | AddDefaultPred(BuildMI(BB, dl, |
| 5416 | TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 5417 | .addReg(LHS1).addImm(0)); |
| 5418 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 5419 | .addReg(LHS2).addImm(0) |
| 5420 | .addImm(ARMCC::EQ).addReg(ARM::CPSR); |
| 5421 | } else { |
| 5422 | unsigned RHS1 = MI->getOperand(3).getReg(); |
| 5423 | unsigned RHS2 = MI->getOperand(4).getReg(); |
| 5424 | AddDefaultPred(BuildMI(BB, dl, |
| 5425 | TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
| 5426 | .addReg(LHS1).addReg(RHS1)); |
| 5427 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
| 5428 | .addReg(LHS2).addReg(RHS2) |
| 5429 | .addImm(ARMCC::EQ).addReg(ARM::CPSR); |
| 5430 | } |
| 5431 | |
| 5432 | MachineBasicBlock *destMBB = MI->getOperand(RHSisZero ? 3 : 5).getMBB(); |
| 5433 | MachineBasicBlock *exitMBB = OtherSucc(BB, destMBB); |
| 5434 | if (MI->getOperand(0).getImm() == ARMCC::NE) |
| 5435 | std::swap(destMBB, exitMBB); |
| 5436 | |
| 5437 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 5438 | .addMBB(destMBB).addImm(ARMCC::EQ).addReg(ARM::CPSR); |
| 5439 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2B : ARM::B)) |
| 5440 | .addMBB(exitMBB); |
| 5441 | |
| 5442 | MI->eraseFromParent(); // The pseudo instruction is gone now. |
| 5443 | return BB; |
| 5444 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5445 | } |
| 5446 | } |
| 5447 | |
| 5448 | //===----------------------------------------------------------------------===// |
| 5449 | // ARM Optimization Hooks |
| 5450 | //===----------------------------------------------------------------------===// |
| 5451 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 5452 | static |
| 5453 | SDValue combineSelectAndUse(SDNode *N, SDValue Slct, SDValue OtherOp, |
| 5454 | TargetLowering::DAGCombinerInfo &DCI) { |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 5455 | SelectionDAG &DAG = DCI.DAG; |
| 5456 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 5457 | EVT VT = N->getValueType(0); |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 5458 | unsigned Opc = N->getOpcode(); |
| 5459 | bool isSlctCC = Slct.getOpcode() == ISD::SELECT_CC; |
| 5460 | SDValue LHS = isSlctCC ? Slct.getOperand(2) : Slct.getOperand(1); |
| 5461 | SDValue RHS = isSlctCC ? Slct.getOperand(3) : Slct.getOperand(2); |
| 5462 | ISD::CondCode CC = ISD::SETCC_INVALID; |
| 5463 | |
| 5464 | if (isSlctCC) { |
| 5465 | CC = cast<CondCodeSDNode>(Slct.getOperand(4))->get(); |
| 5466 | } else { |
| 5467 | SDValue CCOp = Slct.getOperand(0); |
| 5468 | if (CCOp.getOpcode() == ISD::SETCC) |
| 5469 | CC = cast<CondCodeSDNode>(CCOp.getOperand(2))->get(); |
| 5470 | } |
| 5471 | |
| 5472 | bool DoXform = false; |
| 5473 | bool InvCC = false; |
| 5474 | assert ((Opc == ISD::ADD || (Opc == ISD::SUB && Slct == N->getOperand(1))) && |
| 5475 | "Bad input!"); |
| 5476 | |
| 5477 | if (LHS.getOpcode() == ISD::Constant && |
| 5478 | cast<ConstantSDNode>(LHS)->isNullValue()) { |
| 5479 | DoXform = true; |
| 5480 | } else if (CC != ISD::SETCC_INVALID && |
| 5481 | RHS.getOpcode() == ISD::Constant && |
| 5482 | cast<ConstantSDNode>(RHS)->isNullValue()) { |
| 5483 | std::swap(LHS, RHS); |
| 5484 | SDValue Op0 = Slct.getOperand(0); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 5485 | EVT OpVT = isSlctCC ? Op0.getValueType() : |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 5486 | Op0.getOperand(0).getValueType(); |
| 5487 | bool isInt = OpVT.isInteger(); |
| 5488 | CC = ISD::getSetCCInverse(CC, isInt); |
| 5489 | |
| 5490 | if (!TLI.isCondCodeLegal(CC, OpVT)) |
| 5491 | return SDValue(); // Inverse operator isn't legal. |
| 5492 | |
| 5493 | DoXform = true; |
| 5494 | InvCC = true; |
| 5495 | } |
| 5496 | |
| 5497 | if (DoXform) { |
| 5498 | SDValue Result = DAG.getNode(Opc, RHS.getDebugLoc(), VT, OtherOp, RHS); |
| 5499 | if (isSlctCC) |
| 5500 | return DAG.getSelectCC(N->getDebugLoc(), OtherOp, Result, |
| 5501 | Slct.getOperand(0), Slct.getOperand(1), CC); |
| 5502 | SDValue CCOp = Slct.getOperand(0); |
| 5503 | if (InvCC) |
| 5504 | CCOp = DAG.getSetCC(Slct.getDebugLoc(), CCOp.getValueType(), |
| 5505 | CCOp.getOperand(0), CCOp.getOperand(1), CC); |
| 5506 | return DAG.getNode(ISD::SELECT, N->getDebugLoc(), VT, |
| 5507 | CCOp, OtherOp, Result); |
| 5508 | } |
| 5509 | return SDValue(); |
| 5510 | } |
| 5511 | |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 5512 | /// PerformADDCombineWithOperands - Try DAG combinations for an ADD with |
| 5513 | /// operands N0 and N1. This is a helper for PerformADDCombine that is |
| 5514 | /// called with the default operands, and if that fails, with commuted |
| 5515 | /// operands. |
| 5516 | static SDValue PerformADDCombineWithOperands(SDNode *N, SDValue N0, SDValue N1, |
| 5517 | TargetLowering::DAGCombinerInfo &DCI) { |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 5518 | // fold (add (select cc, 0, c), x) -> (select cc, x, (add, x, c)) |
| 5519 | if (N0.getOpcode() == ISD::SELECT && N0.getNode()->hasOneUse()) { |
| 5520 | SDValue Result = combineSelectAndUse(N, N0, N1, DCI); |
| 5521 | if (Result.getNode()) return Result; |
| 5522 | } |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 5523 | return SDValue(); |
| 5524 | } |
| 5525 | |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 5526 | /// PerformADDCombine - Target-specific dag combine xforms for ISD::ADD. |
| 5527 | /// |
| 5528 | static SDValue PerformADDCombine(SDNode *N, |
| 5529 | TargetLowering::DAGCombinerInfo &DCI) { |
| 5530 | SDValue N0 = N->getOperand(0); |
| 5531 | SDValue N1 = N->getOperand(1); |
| 5532 | |
| 5533 | // First try with the default operand order. |
| 5534 | SDValue Result = PerformADDCombineWithOperands(N, N0, N1, DCI); |
| 5535 | if (Result.getNode()) |
| 5536 | return Result; |
| 5537 | |
| 5538 | // If that didn't work, try again with the operands commuted. |
| 5539 | return PerformADDCombineWithOperands(N, N1, N0, DCI); |
| 5540 | } |
| 5541 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 5542 | /// PerformSUBCombine - Target-specific dag combine xforms for ISD::SUB. |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 5543 | /// |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 5544 | static SDValue PerformSUBCombine(SDNode *N, |
| 5545 | TargetLowering::DAGCombinerInfo &DCI) { |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 5546 | SDValue N0 = N->getOperand(0); |
| 5547 | SDValue N1 = N->getOperand(1); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 5548 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 5549 | // fold (sub x, (select cc, 0, c)) -> (select cc, x, (sub, x, c)) |
| 5550 | if (N1.getOpcode() == ISD::SELECT && N1.getNode()->hasOneUse()) { |
| 5551 | SDValue Result = combineSelectAndUse(N, N1, N0, DCI); |
| 5552 | if (Result.getNode()) return Result; |
| 5553 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 5554 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 5555 | return SDValue(); |
| 5556 | } |
| 5557 | |
Evan Cheng | 463d358 | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 5558 | /// PerformVMULCombine |
| 5559 | /// Distribute (A + B) * C to (A * C) + (B * C) to take advantage of the |
| 5560 | /// special multiplier accumulator forwarding. |
| 5561 | /// vmul d3, d0, d2 |
| 5562 | /// vmla d3, d1, d2 |
| 5563 | /// is faster than |
| 5564 | /// vadd d3, d0, d1 |
| 5565 | /// vmul d3, d3, d2 |
| 5566 | static SDValue PerformVMULCombine(SDNode *N, |
| 5567 | TargetLowering::DAGCombinerInfo &DCI, |
| 5568 | const ARMSubtarget *Subtarget) { |
| 5569 | if (!Subtarget->hasVMLxForwarding()) |
| 5570 | return SDValue(); |
| 5571 | |
| 5572 | SelectionDAG &DAG = DCI.DAG; |
| 5573 | SDValue N0 = N->getOperand(0); |
| 5574 | SDValue N1 = N->getOperand(1); |
| 5575 | unsigned Opcode = N0.getOpcode(); |
| 5576 | if (Opcode != ISD::ADD && Opcode != ISD::SUB && |
| 5577 | Opcode != ISD::FADD && Opcode != ISD::FSUB) { |
| 5578 | Opcode = N0.getOpcode(); |
| 5579 | if (Opcode != ISD::ADD && Opcode != ISD::SUB && |
| 5580 | Opcode != ISD::FADD && Opcode != ISD::FSUB) |
| 5581 | return SDValue(); |
| 5582 | std::swap(N0, N1); |
| 5583 | } |
| 5584 | |
| 5585 | EVT VT = N->getValueType(0); |
| 5586 | DebugLoc DL = N->getDebugLoc(); |
| 5587 | SDValue N00 = N0->getOperand(0); |
| 5588 | SDValue N01 = N0->getOperand(1); |
| 5589 | return DAG.getNode(Opcode, DL, VT, |
| 5590 | DAG.getNode(ISD::MUL, DL, VT, N00, N1), |
| 5591 | DAG.getNode(ISD::MUL, DL, VT, N01, N1)); |
| 5592 | } |
| 5593 | |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 5594 | static SDValue PerformMULCombine(SDNode *N, |
| 5595 | TargetLowering::DAGCombinerInfo &DCI, |
| 5596 | const ARMSubtarget *Subtarget) { |
| 5597 | SelectionDAG &DAG = DCI.DAG; |
| 5598 | |
| 5599 | if (Subtarget->isThumb1Only()) |
| 5600 | return SDValue(); |
| 5601 | |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 5602 | if (DCI.isBeforeLegalize() || DCI.isCalledByLegalizer()) |
| 5603 | return SDValue(); |
| 5604 | |
| 5605 | EVT VT = N->getValueType(0); |
Evan Cheng | 463d358 | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 5606 | if (VT.is64BitVector() || VT.is128BitVector()) |
| 5607 | return PerformVMULCombine(N, DCI, Subtarget); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 5608 | if (VT != MVT::i32) |
| 5609 | return SDValue(); |
| 5610 | |
| 5611 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1)); |
| 5612 | if (!C) |
| 5613 | return SDValue(); |
| 5614 | |
| 5615 | uint64_t MulAmt = C->getZExtValue(); |
| 5616 | unsigned ShiftAmt = CountTrailingZeros_64(MulAmt); |
| 5617 | ShiftAmt = ShiftAmt & (32 - 1); |
| 5618 | SDValue V = N->getOperand(0); |
| 5619 | DebugLoc DL = N->getDebugLoc(); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 5620 | |
Anton Korobeynikov | 4878b84 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 5621 | SDValue Res; |
| 5622 | MulAmt >>= ShiftAmt; |
| 5623 | if (isPowerOf2_32(MulAmt - 1)) { |
| 5624 | // (mul x, 2^N + 1) => (add (shl x, N), x) |
| 5625 | Res = DAG.getNode(ISD::ADD, DL, VT, |
| 5626 | V, DAG.getNode(ISD::SHL, DL, VT, |
| 5627 | V, DAG.getConstant(Log2_32(MulAmt-1), |
| 5628 | MVT::i32))); |
| 5629 | } else if (isPowerOf2_32(MulAmt + 1)) { |
| 5630 | // (mul x, 2^N - 1) => (sub (shl x, N), x) |
| 5631 | Res = DAG.getNode(ISD::SUB, DL, VT, |
| 5632 | DAG.getNode(ISD::SHL, DL, VT, |
| 5633 | V, DAG.getConstant(Log2_32(MulAmt+1), |
| 5634 | MVT::i32)), |
| 5635 | V); |
| 5636 | } else |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 5637 | return SDValue(); |
Anton Korobeynikov | 4878b84 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 5638 | |
| 5639 | if (ShiftAmt != 0) |
| 5640 | Res = DAG.getNode(ISD::SHL, DL, VT, Res, |
| 5641 | DAG.getConstant(ShiftAmt, MVT::i32)); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 5642 | |
| 5643 | // Do not add new nodes to DAG combiner worklist. |
Anton Korobeynikov | 4878b84 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 5644 | DCI.CombineTo(N, Res, false); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 5645 | return SDValue(); |
| 5646 | } |
| 5647 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 5648 | static SDValue PerformANDCombine(SDNode *N, |
| 5649 | TargetLowering::DAGCombinerInfo &DCI) { |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5650 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 5651 | // Attempt to use immediate-form VBIC |
| 5652 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(N->getOperand(1)); |
| 5653 | DebugLoc dl = N->getDebugLoc(); |
| 5654 | EVT VT = N->getValueType(0); |
| 5655 | SelectionDAG &DAG = DCI.DAG; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5656 | |
Tanya Lattner | 0433b21 | 2011-04-07 15:24:20 +0000 | [diff] [blame] | 5657 | if(!DAG.getTargetLoweringInfo().isTypeLegal(VT)) |
| 5658 | return SDValue(); |
Andrew Trick | 1c3af77 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 5659 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 5660 | APInt SplatBits, SplatUndef; |
| 5661 | unsigned SplatBitSize; |
| 5662 | bool HasAnyUndefs; |
| 5663 | if (BVN && |
| 5664 | BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { |
| 5665 | if (SplatBitSize <= 64) { |
| 5666 | EVT VbicVT; |
| 5667 | SDValue Val = isNEONModifiedImm((~SplatBits).getZExtValue(), |
| 5668 | SplatUndef.getZExtValue(), SplatBitSize, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5669 | DAG, VbicVT, VT.is128BitVector(), |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 5670 | OtherModImm); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 5671 | if (Val.getNode()) { |
| 5672 | SDValue Input = |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5673 | DAG.getNode(ISD::BITCAST, dl, VbicVT, N->getOperand(0)); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 5674 | SDValue Vbic = DAG.getNode(ARMISD::VBICIMM, dl, VbicVT, Input, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5675 | return DAG.getNode(ISD::BITCAST, dl, VT, Vbic); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 5676 | } |
| 5677 | } |
| 5678 | } |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5679 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 5680 | return SDValue(); |
| 5681 | } |
| 5682 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 5683 | /// PerformORCombine - Target-specific dag combine xforms for ISD::OR |
| 5684 | static SDValue PerformORCombine(SDNode *N, |
| 5685 | TargetLowering::DAGCombinerInfo &DCI, |
| 5686 | const ARMSubtarget *Subtarget) { |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 5687 | // Attempt to use immediate-form VORR |
| 5688 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(N->getOperand(1)); |
| 5689 | DebugLoc dl = N->getDebugLoc(); |
| 5690 | EVT VT = N->getValueType(0); |
| 5691 | SelectionDAG &DAG = DCI.DAG; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5692 | |
Tanya Lattner | 0433b21 | 2011-04-07 15:24:20 +0000 | [diff] [blame] | 5693 | if(!DAG.getTargetLoweringInfo().isTypeLegal(VT)) |
| 5694 | return SDValue(); |
Andrew Trick | 1c3af77 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 5695 | |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 5696 | APInt SplatBits, SplatUndef; |
| 5697 | unsigned SplatBitSize; |
| 5698 | bool HasAnyUndefs; |
| 5699 | if (BVN && Subtarget->hasNEON() && |
| 5700 | BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { |
| 5701 | if (SplatBitSize <= 64) { |
| 5702 | EVT VorrVT; |
| 5703 | SDValue Val = isNEONModifiedImm(SplatBits.getZExtValue(), |
| 5704 | SplatUndef.getZExtValue(), SplatBitSize, |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 5705 | DAG, VorrVT, VT.is128BitVector(), |
| 5706 | OtherModImm); |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 5707 | if (Val.getNode()) { |
| 5708 | SDValue Input = |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5709 | DAG.getNode(ISD::BITCAST, dl, VorrVT, N->getOperand(0)); |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 5710 | SDValue Vorr = DAG.getNode(ARMISD::VORRIMM, dl, VorrVT, Input, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5711 | return DAG.getNode(ISD::BITCAST, dl, VT, Vorr); |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 5712 | } |
| 5713 | } |
| 5714 | } |
| 5715 | |
Cameron Zwarich | c0e6d78 | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 5716 | SDValue N0 = N->getOperand(0); |
| 5717 | if (N0.getOpcode() != ISD::AND) |
| 5718 | return SDValue(); |
| 5719 | SDValue N1 = N->getOperand(1); |
| 5720 | |
| 5721 | // (or (and B, A), (and C, ~A)) => (VBSL A, B, C) when A is a constant. |
| 5722 | if (Subtarget->hasNEON() && N1.getOpcode() == ISD::AND && VT.isVector() && |
| 5723 | DAG.getTargetLoweringInfo().isTypeLegal(VT)) { |
| 5724 | APInt SplatUndef; |
| 5725 | unsigned SplatBitSize; |
| 5726 | bool HasAnyUndefs; |
| 5727 | |
| 5728 | BuildVectorSDNode *BVN0 = dyn_cast<BuildVectorSDNode>(N0->getOperand(1)); |
| 5729 | APInt SplatBits0; |
| 5730 | if (BVN0 && BVN0->isConstantSplat(SplatBits0, SplatUndef, SplatBitSize, |
| 5731 | HasAnyUndefs) && !HasAnyUndefs) { |
| 5732 | BuildVectorSDNode *BVN1 = dyn_cast<BuildVectorSDNode>(N1->getOperand(1)); |
| 5733 | APInt SplatBits1; |
| 5734 | if (BVN1 && BVN1->isConstantSplat(SplatBits1, SplatUndef, SplatBitSize, |
| 5735 | HasAnyUndefs) && !HasAnyUndefs && |
| 5736 | SplatBits0 == ~SplatBits1) { |
| 5737 | // Canonicalize the vector type to make instruction selection simpler. |
| 5738 | EVT CanonicalVT = VT.is128BitVector() ? MVT::v4i32 : MVT::v2i32; |
| 5739 | SDValue Result = DAG.getNode(ARMISD::VBSL, dl, CanonicalVT, |
| 5740 | N0->getOperand(1), N0->getOperand(0), |
Cameron Zwarich | 5af60ce | 2011-04-13 21:01:19 +0000 | [diff] [blame] | 5741 | N1->getOperand(0)); |
Cameron Zwarich | c0e6d78 | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 5742 | return DAG.getNode(ISD::BITCAST, dl, VT, Result); |
| 5743 | } |
| 5744 | } |
| 5745 | } |
| 5746 | |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5747 | // Try to use the ARM/Thumb2 BFI (bitfield insert) instruction when |
| 5748 | // reasonable. |
| 5749 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 5750 | // BFI is only available on V6T2+ |
| 5751 | if (Subtarget->isThumb1Only() || !Subtarget->hasV6T2Ops()) |
| 5752 | return SDValue(); |
| 5753 | |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5754 | DebugLoc DL = N->getDebugLoc(); |
| 5755 | // 1) or (and A, mask), val => ARMbfi A, val, mask |
| 5756 | // iff (val & mask) == val |
| 5757 | // |
| 5758 | // 2) or (and A, mask), (and B, mask2) => ARMbfi A, (lsr B, amt), mask |
| 5759 | // 2a) iff isBitFieldInvertedMask(mask) && isBitFieldInvertedMask(~mask2) |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 5760 | // && mask == ~mask2 |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5761 | // 2b) iff isBitFieldInvertedMask(~mask) && isBitFieldInvertedMask(mask2) |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 5762 | // && ~mask == mask2 |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5763 | // (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] | 5764 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 5765 | if (VT != MVT::i32) |
| 5766 | return SDValue(); |
| 5767 | |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 5768 | SDValue N00 = N0.getOperand(0); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5769 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 5770 | // The value and the mask need to be constants so we can verify this is |
| 5771 | // actually a bitfield set. If the mask is 0xffff, we can do better |
| 5772 | // via a movt instruction, so don't use BFI in that case. |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 5773 | SDValue MaskOp = N0.getOperand(1); |
| 5774 | ConstantSDNode *MaskC = dyn_cast<ConstantSDNode>(MaskOp); |
| 5775 | if (!MaskC) |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 5776 | return SDValue(); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 5777 | unsigned Mask = MaskC->getZExtValue(); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 5778 | if (Mask == 0xffff) |
| 5779 | return SDValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5780 | SDValue Res; |
| 5781 | // Case (1): or (and A, mask), val => ARMbfi A, val, mask |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 5782 | ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1); |
| 5783 | if (N1C) { |
| 5784 | unsigned Val = N1C->getZExtValue(); |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 5785 | if ((Val & ~Mask) != Val) |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5786 | return SDValue(); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 5787 | |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 5788 | if (ARM::isBitFieldInvertedMask(Mask)) { |
| 5789 | Val >>= CountTrailingZeros_32(~Mask); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 5790 | |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 5791 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N00, |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 5792 | DAG.getConstant(Val, MVT::i32), |
| 5793 | DAG.getConstant(Mask, MVT::i32)); |
| 5794 | |
| 5795 | // Do not add new nodes to DAG combiner worklist. |
| 5796 | DCI.CombineTo(N, Res, false); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 5797 | return SDValue(); |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 5798 | } |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5799 | } else if (N1.getOpcode() == ISD::AND) { |
| 5800 | // 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] | 5801 | ConstantSDNode *N11C = dyn_cast<ConstantSDNode>(N1.getOperand(1)); |
| 5802 | if (!N11C) |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5803 | return SDValue(); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 5804 | unsigned Mask2 = N11C->getZExtValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5805 | |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 5806 | // Mask and ~Mask2 (or reverse) must be equivalent for the BFI pattern |
| 5807 | // as is to match. |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5808 | if (ARM::isBitFieldInvertedMask(Mask) && |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 5809 | (Mask == ~Mask2)) { |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5810 | // The pack halfword instruction works better for masks that fit it, |
| 5811 | // so use that when it's available. |
| 5812 | if (Subtarget->hasT2ExtractPack() && |
| 5813 | (Mask == 0xffff || Mask == 0xffff0000)) |
| 5814 | return SDValue(); |
| 5815 | // 2a |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 5816 | unsigned amt = CountTrailingZeros_32(Mask2); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5817 | Res = DAG.getNode(ISD::SRL, DL, VT, N1.getOperand(0), |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 5818 | DAG.getConstant(amt, MVT::i32)); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 5819 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N00, Res, |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5820 | DAG.getConstant(Mask, MVT::i32)); |
| 5821 | // Do not add new nodes to DAG combiner worklist. |
| 5822 | DCI.CombineTo(N, Res, false); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 5823 | return SDValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5824 | } else if (ARM::isBitFieldInvertedMask(~Mask) && |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 5825 | (~Mask == Mask2)) { |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5826 | // The pack halfword instruction works better for masks that fit it, |
| 5827 | // so use that when it's available. |
| 5828 | if (Subtarget->hasT2ExtractPack() && |
| 5829 | (Mask2 == 0xffff || Mask2 == 0xffff0000)) |
| 5830 | return SDValue(); |
| 5831 | // 2b |
| 5832 | unsigned lsb = CountTrailingZeros_32(Mask); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 5833 | Res = DAG.getNode(ISD::SRL, DL, VT, N00, |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5834 | DAG.getConstant(lsb, MVT::i32)); |
| 5835 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N1.getOperand(0), Res, |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 5836 | DAG.getConstant(Mask2, MVT::i32)); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5837 | // Do not add new nodes to DAG combiner worklist. |
| 5838 | DCI.CombineTo(N, Res, false); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 5839 | return SDValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5840 | } |
| 5841 | } |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5842 | |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 5843 | if (DAG.MaskedValueIsZero(N1, MaskC->getAPIntValue()) && |
| 5844 | N00.getOpcode() == ISD::SHL && isa<ConstantSDNode>(N00.getOperand(1)) && |
| 5845 | ARM::isBitFieldInvertedMask(~Mask)) { |
| 5846 | // Case (3): or (and (shl A, #shamt), mask), B => ARMbfi B, A, ~mask |
| 5847 | // where lsb(mask) == #shamt and masked bits of B are known zero. |
| 5848 | SDValue ShAmt = N00.getOperand(1); |
| 5849 | unsigned ShAmtC = cast<ConstantSDNode>(ShAmt)->getZExtValue(); |
| 5850 | unsigned LSB = CountTrailingZeros_32(Mask); |
| 5851 | if (ShAmtC != LSB) |
| 5852 | return SDValue(); |
| 5853 | |
| 5854 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N1, N00.getOperand(0), |
| 5855 | DAG.getConstant(~Mask, MVT::i32)); |
| 5856 | |
| 5857 | // Do not add new nodes to DAG combiner worklist. |
| 5858 | DCI.CombineTo(N, Res, false); |
| 5859 | } |
| 5860 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 5861 | return SDValue(); |
| 5862 | } |
| 5863 | |
Evan Cheng | 0c1aec1 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 5864 | /// PerformBFICombine - (bfi A, (and B, C1), C2) -> (bfi A, B, C2) iff |
| 5865 | /// C1 & C2 == C1. |
| 5866 | static SDValue PerformBFICombine(SDNode *N, |
| 5867 | TargetLowering::DAGCombinerInfo &DCI) { |
| 5868 | SDValue N1 = N->getOperand(1); |
| 5869 | if (N1.getOpcode() == ISD::AND) { |
| 5870 | ConstantSDNode *N11C = dyn_cast<ConstantSDNode>(N1.getOperand(1)); |
| 5871 | if (!N11C) |
| 5872 | return SDValue(); |
| 5873 | unsigned Mask = cast<ConstantSDNode>(N->getOperand(2))->getZExtValue(); |
| 5874 | unsigned Mask2 = N11C->getZExtValue(); |
| 5875 | if ((Mask & Mask2) == Mask2) |
| 5876 | return DCI.DAG.getNode(ARMISD::BFI, N->getDebugLoc(), N->getValueType(0), |
| 5877 | N->getOperand(0), N1.getOperand(0), |
| 5878 | N->getOperand(2)); |
| 5879 | } |
| 5880 | return SDValue(); |
| 5881 | } |
| 5882 | |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 5883 | /// PerformVMOVRRDCombine - Target-specific dag combine xforms for |
| 5884 | /// ARMISD::VMOVRRD. |
| 5885 | static SDValue PerformVMOVRRDCombine(SDNode *N, |
| 5886 | TargetLowering::DAGCombinerInfo &DCI) { |
| 5887 | // vmovrrd(vmovdrr x, y) -> x,y |
| 5888 | SDValue InDouble = N->getOperand(0); |
| 5889 | if (InDouble.getOpcode() == ARMISD::VMOVDRR) |
| 5890 | return DCI.CombineTo(N, InDouble.getOperand(0), InDouble.getOperand(1)); |
Cameron Zwarich | 4071a71 | 2011-04-02 02:40:43 +0000 | [diff] [blame] | 5891 | |
| 5892 | // vmovrrd(load f64) -> (load i32), (load i32) |
| 5893 | SDNode *InNode = InDouble.getNode(); |
| 5894 | if (ISD::isNormalLoad(InNode) && InNode->hasOneUse() && |
| 5895 | InNode->getValueType(0) == MVT::f64 && |
| 5896 | InNode->getOperand(1).getOpcode() == ISD::FrameIndex && |
| 5897 | !cast<LoadSDNode>(InNode)->isVolatile()) { |
| 5898 | // TODO: Should this be done for non-FrameIndex operands? |
| 5899 | LoadSDNode *LD = cast<LoadSDNode>(InNode); |
| 5900 | |
| 5901 | SelectionDAG &DAG = DCI.DAG; |
| 5902 | DebugLoc DL = LD->getDebugLoc(); |
| 5903 | SDValue BasePtr = LD->getBasePtr(); |
| 5904 | SDValue NewLD1 = DAG.getLoad(MVT::i32, DL, LD->getChain(), BasePtr, |
| 5905 | LD->getPointerInfo(), LD->isVolatile(), |
| 5906 | LD->isNonTemporal(), LD->getAlignment()); |
| 5907 | |
| 5908 | SDValue OffsetPtr = DAG.getNode(ISD::ADD, DL, MVT::i32, BasePtr, |
| 5909 | DAG.getConstant(4, MVT::i32)); |
| 5910 | SDValue NewLD2 = DAG.getLoad(MVT::i32, DL, NewLD1.getValue(1), OffsetPtr, |
| 5911 | LD->getPointerInfo(), LD->isVolatile(), |
| 5912 | LD->isNonTemporal(), |
| 5913 | std::min(4U, LD->getAlignment() / 2)); |
| 5914 | |
| 5915 | DAG.ReplaceAllUsesOfValueWith(SDValue(LD, 1), NewLD2.getValue(1)); |
| 5916 | SDValue Result = DCI.CombineTo(N, NewLD1, NewLD2); |
| 5917 | DCI.RemoveFromWorklist(LD); |
| 5918 | DAG.DeleteNode(LD); |
| 5919 | return Result; |
| 5920 | } |
| 5921 | |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 5922 | return SDValue(); |
| 5923 | } |
| 5924 | |
| 5925 | /// PerformVMOVDRRCombine - Target-specific dag combine xforms for |
| 5926 | /// ARMISD::VMOVDRR. This is also used for BUILD_VECTORs with 2 operands. |
| 5927 | static SDValue PerformVMOVDRRCombine(SDNode *N, SelectionDAG &DAG) { |
| 5928 | // N=vmovrrd(X); vmovdrr(N:0, N:1) -> bit_convert(X) |
| 5929 | SDValue Op0 = N->getOperand(0); |
| 5930 | SDValue Op1 = N->getOperand(1); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5931 | if (Op0.getOpcode() == ISD::BITCAST) |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 5932 | Op0 = Op0.getOperand(0); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5933 | if (Op1.getOpcode() == ISD::BITCAST) |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 5934 | Op1 = Op1.getOperand(0); |
| 5935 | if (Op0.getOpcode() == ARMISD::VMOVRRD && |
| 5936 | Op0.getNode() == Op1.getNode() && |
| 5937 | Op0.getResNo() == 0 && Op1.getResNo() == 1) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5938 | return DAG.getNode(ISD::BITCAST, N->getDebugLoc(), |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 5939 | N->getValueType(0), Op0.getOperand(0)); |
| 5940 | return SDValue(); |
| 5941 | } |
| 5942 | |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 5943 | /// PerformSTORECombine - Target-specific dag combine xforms for |
| 5944 | /// ISD::STORE. |
| 5945 | static SDValue PerformSTORECombine(SDNode *N, |
| 5946 | TargetLowering::DAGCombinerInfo &DCI) { |
| 5947 | // Bitcast an i64 store extracted from a vector to f64. |
| 5948 | // Otherwise, the i64 value will be legalized to a pair of i32 values. |
| 5949 | StoreSDNode *St = cast<StoreSDNode>(N); |
| 5950 | SDValue StVal = St->getValue(); |
Cameron Zwarich | d0aacbc | 2011-04-12 02:24:17 +0000 | [diff] [blame] | 5951 | if (!ISD::isNormalStore(St) || St->isVolatile()) |
| 5952 | return SDValue(); |
| 5953 | |
| 5954 | if (StVal.getNode()->getOpcode() == ARMISD::VMOVDRR && |
| 5955 | StVal.getNode()->hasOneUse() && !St->isVolatile()) { |
| 5956 | SelectionDAG &DAG = DCI.DAG; |
| 5957 | DebugLoc DL = St->getDebugLoc(); |
| 5958 | SDValue BasePtr = St->getBasePtr(); |
| 5959 | SDValue NewST1 = DAG.getStore(St->getChain(), DL, |
| 5960 | StVal.getNode()->getOperand(0), BasePtr, |
| 5961 | St->getPointerInfo(), St->isVolatile(), |
| 5962 | St->isNonTemporal(), St->getAlignment()); |
| 5963 | |
| 5964 | SDValue OffsetPtr = DAG.getNode(ISD::ADD, DL, MVT::i32, BasePtr, |
| 5965 | DAG.getConstant(4, MVT::i32)); |
| 5966 | return DAG.getStore(NewST1.getValue(0), DL, StVal.getNode()->getOperand(1), |
| 5967 | OffsetPtr, St->getPointerInfo(), St->isVolatile(), |
| 5968 | St->isNonTemporal(), |
| 5969 | std::min(4U, St->getAlignment() / 2)); |
| 5970 | } |
| 5971 | |
| 5972 | if (StVal.getValueType() != MVT::i64 || |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 5973 | StVal.getNode()->getOpcode() != ISD::EXTRACT_VECTOR_ELT) |
| 5974 | return SDValue(); |
| 5975 | |
| 5976 | SelectionDAG &DAG = DCI.DAG; |
| 5977 | DebugLoc dl = StVal.getDebugLoc(); |
| 5978 | SDValue IntVec = StVal.getOperand(0); |
| 5979 | EVT FloatVT = EVT::getVectorVT(*DAG.getContext(), MVT::f64, |
| 5980 | IntVec.getValueType().getVectorNumElements()); |
| 5981 | SDValue Vec = DAG.getNode(ISD::BITCAST, dl, FloatVT, IntVec); |
| 5982 | SDValue ExtElt = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, |
| 5983 | Vec, StVal.getOperand(1)); |
| 5984 | dl = N->getDebugLoc(); |
| 5985 | SDValue V = DAG.getNode(ISD::BITCAST, dl, MVT::i64, ExtElt); |
| 5986 | // Make the DAGCombiner fold the bitcasts. |
| 5987 | DCI.AddToWorklist(Vec.getNode()); |
| 5988 | DCI.AddToWorklist(ExtElt.getNode()); |
| 5989 | DCI.AddToWorklist(V.getNode()); |
| 5990 | return DAG.getStore(St->getChain(), dl, V, St->getBasePtr(), |
| 5991 | St->getPointerInfo(), St->isVolatile(), |
| 5992 | St->isNonTemporal(), St->getAlignment(), |
| 5993 | St->getTBAAInfo()); |
| 5994 | } |
| 5995 | |
| 5996 | /// hasNormalLoadOperand - Check if any of the operands of a BUILD_VECTOR node |
| 5997 | /// are normal, non-volatile loads. If so, it is profitable to bitcast an |
| 5998 | /// i64 vector to have f64 elements, since the value can then be loaded |
| 5999 | /// directly into a VFP register. |
| 6000 | static bool hasNormalLoadOperand(SDNode *N) { |
| 6001 | unsigned NumElts = N->getValueType(0).getVectorNumElements(); |
| 6002 | for (unsigned i = 0; i < NumElts; ++i) { |
| 6003 | SDNode *Elt = N->getOperand(i).getNode(); |
| 6004 | if (ISD::isNormalLoad(Elt) && !cast<LoadSDNode>(Elt)->isVolatile()) |
| 6005 | return true; |
| 6006 | } |
| 6007 | return false; |
| 6008 | } |
| 6009 | |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 6010 | /// PerformBUILD_VECTORCombine - Target-specific dag combine xforms for |
| 6011 | /// ISD::BUILD_VECTOR. |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 6012 | static SDValue PerformBUILD_VECTORCombine(SDNode *N, |
| 6013 | TargetLowering::DAGCombinerInfo &DCI){ |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 6014 | // build_vector(N=ARMISD::VMOVRRD(X), N:1) -> bit_convert(X): |
| 6015 | // VMOVRRD is introduced when legalizing i64 types. It forces the i64 value |
| 6016 | // into a pair of GPRs, which is fine when the value is used as a scalar, |
| 6017 | // 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] | 6018 | SelectionDAG &DAG = DCI.DAG; |
| 6019 | if (N->getNumOperands() == 2) { |
| 6020 | SDValue RV = PerformVMOVDRRCombine(N, DAG); |
| 6021 | if (RV.getNode()) |
| 6022 | return RV; |
| 6023 | } |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 6024 | |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 6025 | // Load i64 elements as f64 values so that type legalization does not split |
| 6026 | // them up into i32 values. |
| 6027 | EVT VT = N->getValueType(0); |
| 6028 | if (VT.getVectorElementType() != MVT::i64 || !hasNormalLoadOperand(N)) |
| 6029 | return SDValue(); |
| 6030 | DebugLoc dl = N->getDebugLoc(); |
| 6031 | SmallVector<SDValue, 8> Ops; |
| 6032 | unsigned NumElts = VT.getVectorNumElements(); |
| 6033 | for (unsigned i = 0; i < NumElts; ++i) { |
| 6034 | SDValue V = DAG.getNode(ISD::BITCAST, dl, MVT::f64, N->getOperand(i)); |
| 6035 | Ops.push_back(V); |
| 6036 | // Make the DAGCombiner fold the bitcast. |
| 6037 | DCI.AddToWorklist(V.getNode()); |
| 6038 | } |
| 6039 | EVT FloatVT = EVT::getVectorVT(*DAG.getContext(), MVT::f64, NumElts); |
| 6040 | SDValue BV = DAG.getNode(ISD::BUILD_VECTOR, dl, FloatVT, Ops.data(), NumElts); |
| 6041 | return DAG.getNode(ISD::BITCAST, dl, VT, BV); |
| 6042 | } |
| 6043 | |
| 6044 | /// PerformInsertEltCombine - Target-specific dag combine xforms for |
| 6045 | /// ISD::INSERT_VECTOR_ELT. |
| 6046 | static SDValue PerformInsertEltCombine(SDNode *N, |
| 6047 | TargetLowering::DAGCombinerInfo &DCI) { |
| 6048 | // Bitcast an i64 load inserted into a vector to f64. |
| 6049 | // Otherwise, the i64 value will be legalized to a pair of i32 values. |
| 6050 | EVT VT = N->getValueType(0); |
| 6051 | SDNode *Elt = N->getOperand(1).getNode(); |
| 6052 | if (VT.getVectorElementType() != MVT::i64 || |
| 6053 | !ISD::isNormalLoad(Elt) || cast<LoadSDNode>(Elt)->isVolatile()) |
| 6054 | return SDValue(); |
| 6055 | |
| 6056 | SelectionDAG &DAG = DCI.DAG; |
| 6057 | DebugLoc dl = N->getDebugLoc(); |
| 6058 | EVT FloatVT = EVT::getVectorVT(*DAG.getContext(), MVT::f64, |
| 6059 | VT.getVectorNumElements()); |
| 6060 | SDValue Vec = DAG.getNode(ISD::BITCAST, dl, FloatVT, N->getOperand(0)); |
| 6061 | SDValue V = DAG.getNode(ISD::BITCAST, dl, MVT::f64, N->getOperand(1)); |
| 6062 | // Make the DAGCombiner fold the bitcasts. |
| 6063 | DCI.AddToWorklist(Vec.getNode()); |
| 6064 | DCI.AddToWorklist(V.getNode()); |
| 6065 | SDValue InsElt = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, FloatVT, |
| 6066 | Vec, V, N->getOperand(2)); |
| 6067 | return DAG.getNode(ISD::BITCAST, dl, VT, InsElt); |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 6068 | } |
| 6069 | |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 6070 | /// PerformVECTOR_SHUFFLECombine - Target-specific dag combine xforms for |
| 6071 | /// ISD::VECTOR_SHUFFLE. |
| 6072 | static SDValue PerformVECTOR_SHUFFLECombine(SDNode *N, SelectionDAG &DAG) { |
| 6073 | // The LLVM shufflevector instruction does not require the shuffle mask |
| 6074 | // length to match the operand vector length, but ISD::VECTOR_SHUFFLE does |
| 6075 | // have that requirement. When translating to ISD::VECTOR_SHUFFLE, if the |
| 6076 | // operands do not match the mask length, they are extended by concatenating |
| 6077 | // them with undef vectors. That is probably the right thing for other |
| 6078 | // targets, but for NEON it is better to concatenate two double-register |
| 6079 | // size vector operands into a single quad-register size vector. Do that |
| 6080 | // transformation here: |
| 6081 | // shuffle(concat(v1, undef), concat(v2, undef)) -> |
| 6082 | // shuffle(concat(v1, v2), undef) |
| 6083 | SDValue Op0 = N->getOperand(0); |
| 6084 | SDValue Op1 = N->getOperand(1); |
| 6085 | if (Op0.getOpcode() != ISD::CONCAT_VECTORS || |
| 6086 | Op1.getOpcode() != ISD::CONCAT_VECTORS || |
| 6087 | Op0.getNumOperands() != 2 || |
| 6088 | Op1.getNumOperands() != 2) |
| 6089 | return SDValue(); |
| 6090 | SDValue Concat0Op1 = Op0.getOperand(1); |
| 6091 | SDValue Concat1Op1 = Op1.getOperand(1); |
| 6092 | if (Concat0Op1.getOpcode() != ISD::UNDEF || |
| 6093 | Concat1Op1.getOpcode() != ISD::UNDEF) |
| 6094 | return SDValue(); |
| 6095 | // Skip the transformation if any of the types are illegal. |
| 6096 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 6097 | EVT VT = N->getValueType(0); |
| 6098 | if (!TLI.isTypeLegal(VT) || |
| 6099 | !TLI.isTypeLegal(Concat0Op1.getValueType()) || |
| 6100 | !TLI.isTypeLegal(Concat1Op1.getValueType())) |
| 6101 | return SDValue(); |
| 6102 | |
| 6103 | SDValue NewConcat = DAG.getNode(ISD::CONCAT_VECTORS, N->getDebugLoc(), VT, |
| 6104 | Op0.getOperand(0), Op1.getOperand(0)); |
| 6105 | // Translate the shuffle mask. |
| 6106 | SmallVector<int, 16> NewMask; |
| 6107 | unsigned NumElts = VT.getVectorNumElements(); |
| 6108 | unsigned HalfElts = NumElts/2; |
| 6109 | ShuffleVectorSDNode *SVN = cast<ShuffleVectorSDNode>(N); |
| 6110 | for (unsigned n = 0; n < NumElts; ++n) { |
| 6111 | int MaskElt = SVN->getMaskElt(n); |
| 6112 | int NewElt = -1; |
Bob Wilson | 1fa9d30 | 2010-10-27 23:49:00 +0000 | [diff] [blame] | 6113 | if (MaskElt < (int)HalfElts) |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 6114 | NewElt = MaskElt; |
Bob Wilson | 1fa9d30 | 2010-10-27 23:49:00 +0000 | [diff] [blame] | 6115 | else if (MaskElt >= (int)NumElts && MaskElt < (int)(NumElts + HalfElts)) |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 6116 | NewElt = HalfElts + MaskElt - NumElts; |
| 6117 | NewMask.push_back(NewElt); |
| 6118 | } |
| 6119 | return DAG.getVectorShuffle(VT, N->getDebugLoc(), NewConcat, |
| 6120 | DAG.getUNDEF(VT), NewMask.data()); |
| 6121 | } |
| 6122 | |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 6123 | /// CombineBaseUpdate - Target-specific DAG combine function for VLDDUP and |
| 6124 | /// NEON load/store intrinsics to merge base address updates. |
| 6125 | static SDValue CombineBaseUpdate(SDNode *N, |
| 6126 | TargetLowering::DAGCombinerInfo &DCI) { |
| 6127 | if (DCI.isBeforeLegalize() || DCI.isCalledByLegalizer()) |
| 6128 | return SDValue(); |
| 6129 | |
| 6130 | SelectionDAG &DAG = DCI.DAG; |
| 6131 | bool isIntrinsic = (N->getOpcode() == ISD::INTRINSIC_VOID || |
| 6132 | N->getOpcode() == ISD::INTRINSIC_W_CHAIN); |
| 6133 | unsigned AddrOpIdx = (isIntrinsic ? 2 : 1); |
| 6134 | SDValue Addr = N->getOperand(AddrOpIdx); |
| 6135 | |
| 6136 | // Search for a use of the address operand that is an increment. |
| 6137 | for (SDNode::use_iterator UI = Addr.getNode()->use_begin(), |
| 6138 | UE = Addr.getNode()->use_end(); UI != UE; ++UI) { |
| 6139 | SDNode *User = *UI; |
| 6140 | if (User->getOpcode() != ISD::ADD || |
| 6141 | UI.getUse().getResNo() != Addr.getResNo()) |
| 6142 | continue; |
| 6143 | |
| 6144 | // Check that the add is independent of the load/store. Otherwise, folding |
| 6145 | // it would create a cycle. |
| 6146 | if (User->isPredecessorOf(N) || N->isPredecessorOf(User)) |
| 6147 | continue; |
| 6148 | |
| 6149 | // Find the new opcode for the updating load/store. |
| 6150 | bool isLoad = true; |
| 6151 | bool isLaneOp = false; |
| 6152 | unsigned NewOpc = 0; |
| 6153 | unsigned NumVecs = 0; |
| 6154 | if (isIntrinsic) { |
| 6155 | unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue(); |
| 6156 | switch (IntNo) { |
| 6157 | default: assert(0 && "unexpected intrinsic for Neon base update"); |
| 6158 | case Intrinsic::arm_neon_vld1: NewOpc = ARMISD::VLD1_UPD; |
| 6159 | NumVecs = 1; break; |
| 6160 | case Intrinsic::arm_neon_vld2: NewOpc = ARMISD::VLD2_UPD; |
| 6161 | NumVecs = 2; break; |
| 6162 | case Intrinsic::arm_neon_vld3: NewOpc = ARMISD::VLD3_UPD; |
| 6163 | NumVecs = 3; break; |
| 6164 | case Intrinsic::arm_neon_vld4: NewOpc = ARMISD::VLD4_UPD; |
| 6165 | NumVecs = 4; break; |
| 6166 | case Intrinsic::arm_neon_vld2lane: NewOpc = ARMISD::VLD2LN_UPD; |
| 6167 | NumVecs = 2; isLaneOp = true; break; |
| 6168 | case Intrinsic::arm_neon_vld3lane: NewOpc = ARMISD::VLD3LN_UPD; |
| 6169 | NumVecs = 3; isLaneOp = true; break; |
| 6170 | case Intrinsic::arm_neon_vld4lane: NewOpc = ARMISD::VLD4LN_UPD; |
| 6171 | NumVecs = 4; isLaneOp = true; break; |
| 6172 | case Intrinsic::arm_neon_vst1: NewOpc = ARMISD::VST1_UPD; |
| 6173 | NumVecs = 1; isLoad = false; break; |
| 6174 | case Intrinsic::arm_neon_vst2: NewOpc = ARMISD::VST2_UPD; |
| 6175 | NumVecs = 2; isLoad = false; break; |
| 6176 | case Intrinsic::arm_neon_vst3: NewOpc = ARMISD::VST3_UPD; |
| 6177 | NumVecs = 3; isLoad = false; break; |
| 6178 | case Intrinsic::arm_neon_vst4: NewOpc = ARMISD::VST4_UPD; |
| 6179 | NumVecs = 4; isLoad = false; break; |
| 6180 | case Intrinsic::arm_neon_vst2lane: NewOpc = ARMISD::VST2LN_UPD; |
| 6181 | NumVecs = 2; isLoad = false; isLaneOp = true; break; |
| 6182 | case Intrinsic::arm_neon_vst3lane: NewOpc = ARMISD::VST3LN_UPD; |
| 6183 | NumVecs = 3; isLoad = false; isLaneOp = true; break; |
| 6184 | case Intrinsic::arm_neon_vst4lane: NewOpc = ARMISD::VST4LN_UPD; |
| 6185 | NumVecs = 4; isLoad = false; isLaneOp = true; break; |
| 6186 | } |
| 6187 | } else { |
| 6188 | isLaneOp = true; |
| 6189 | switch (N->getOpcode()) { |
| 6190 | default: assert(0 && "unexpected opcode for Neon base update"); |
| 6191 | case ARMISD::VLD2DUP: NewOpc = ARMISD::VLD2DUP_UPD; NumVecs = 2; break; |
| 6192 | case ARMISD::VLD3DUP: NewOpc = ARMISD::VLD3DUP_UPD; NumVecs = 3; break; |
| 6193 | case ARMISD::VLD4DUP: NewOpc = ARMISD::VLD4DUP_UPD; NumVecs = 4; break; |
| 6194 | } |
| 6195 | } |
| 6196 | |
| 6197 | // Find the size of memory referenced by the load/store. |
| 6198 | EVT VecTy; |
| 6199 | if (isLoad) |
| 6200 | VecTy = N->getValueType(0); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6201 | else |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 6202 | VecTy = N->getOperand(AddrOpIdx+1).getValueType(); |
| 6203 | unsigned NumBytes = NumVecs * VecTy.getSizeInBits() / 8; |
| 6204 | if (isLaneOp) |
| 6205 | NumBytes /= VecTy.getVectorNumElements(); |
| 6206 | |
| 6207 | // If the increment is a constant, it must match the memory ref size. |
| 6208 | SDValue Inc = User->getOperand(User->getOperand(0) == Addr ? 1 : 0); |
| 6209 | if (ConstantSDNode *CInc = dyn_cast<ConstantSDNode>(Inc.getNode())) { |
| 6210 | uint64_t IncVal = CInc->getZExtValue(); |
| 6211 | if (IncVal != NumBytes) |
| 6212 | continue; |
| 6213 | } else if (NumBytes >= 3 * 16) { |
| 6214 | // VLD3/4 and VST3/4 for 128-bit vectors are implemented with two |
| 6215 | // separate instructions that make it harder to use a non-constant update. |
| 6216 | continue; |
| 6217 | } |
| 6218 | |
| 6219 | // Create the new updating load/store node. |
| 6220 | EVT Tys[6]; |
| 6221 | unsigned NumResultVecs = (isLoad ? NumVecs : 0); |
| 6222 | unsigned n; |
| 6223 | for (n = 0; n < NumResultVecs; ++n) |
| 6224 | Tys[n] = VecTy; |
| 6225 | Tys[n++] = MVT::i32; |
| 6226 | Tys[n] = MVT::Other; |
| 6227 | SDVTList SDTys = DAG.getVTList(Tys, NumResultVecs+2); |
| 6228 | SmallVector<SDValue, 8> Ops; |
| 6229 | Ops.push_back(N->getOperand(0)); // incoming chain |
| 6230 | Ops.push_back(N->getOperand(AddrOpIdx)); |
| 6231 | Ops.push_back(Inc); |
| 6232 | for (unsigned i = AddrOpIdx + 1; i < N->getNumOperands(); ++i) { |
| 6233 | Ops.push_back(N->getOperand(i)); |
| 6234 | } |
| 6235 | MemIntrinsicSDNode *MemInt = cast<MemIntrinsicSDNode>(N); |
| 6236 | SDValue UpdN = DAG.getMemIntrinsicNode(NewOpc, N->getDebugLoc(), SDTys, |
| 6237 | Ops.data(), Ops.size(), |
| 6238 | MemInt->getMemoryVT(), |
| 6239 | MemInt->getMemOperand()); |
| 6240 | |
| 6241 | // Update the uses. |
| 6242 | std::vector<SDValue> NewResults; |
| 6243 | for (unsigned i = 0; i < NumResultVecs; ++i) { |
| 6244 | NewResults.push_back(SDValue(UpdN.getNode(), i)); |
| 6245 | } |
| 6246 | NewResults.push_back(SDValue(UpdN.getNode(), NumResultVecs+1)); // chain |
| 6247 | DCI.CombineTo(N, NewResults); |
| 6248 | DCI.CombineTo(User, SDValue(UpdN.getNode(), NumResultVecs)); |
| 6249 | |
| 6250 | break; |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6251 | } |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 6252 | return SDValue(); |
| 6253 | } |
| 6254 | |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 6255 | /// CombineVLDDUP - For a VDUPLANE node N, check if its source operand is a |
| 6256 | /// vldN-lane (N > 1) intrinsic, and if all the other uses of that intrinsic |
| 6257 | /// are also VDUPLANEs. If so, combine them to a vldN-dup operation and |
| 6258 | /// return true. |
| 6259 | static bool CombineVLDDUP(SDNode *N, TargetLowering::DAGCombinerInfo &DCI) { |
| 6260 | SelectionDAG &DAG = DCI.DAG; |
| 6261 | EVT VT = N->getValueType(0); |
| 6262 | // vldN-dup instructions only support 64-bit vectors for N > 1. |
| 6263 | if (!VT.is64BitVector()) |
| 6264 | return false; |
| 6265 | |
| 6266 | // Check if the VDUPLANE operand is a vldN-dup intrinsic. |
| 6267 | SDNode *VLD = N->getOperand(0).getNode(); |
| 6268 | if (VLD->getOpcode() != ISD::INTRINSIC_W_CHAIN) |
| 6269 | return false; |
| 6270 | unsigned NumVecs = 0; |
| 6271 | unsigned NewOpc = 0; |
| 6272 | unsigned IntNo = cast<ConstantSDNode>(VLD->getOperand(1))->getZExtValue(); |
| 6273 | if (IntNo == Intrinsic::arm_neon_vld2lane) { |
| 6274 | NumVecs = 2; |
| 6275 | NewOpc = ARMISD::VLD2DUP; |
| 6276 | } else if (IntNo == Intrinsic::arm_neon_vld3lane) { |
| 6277 | NumVecs = 3; |
| 6278 | NewOpc = ARMISD::VLD3DUP; |
| 6279 | } else if (IntNo == Intrinsic::arm_neon_vld4lane) { |
| 6280 | NumVecs = 4; |
| 6281 | NewOpc = ARMISD::VLD4DUP; |
| 6282 | } else { |
| 6283 | return false; |
| 6284 | } |
| 6285 | |
| 6286 | // First check that all the vldN-lane uses are VDUPLANEs and that the lane |
| 6287 | // numbers match the load. |
| 6288 | unsigned VLDLaneNo = |
| 6289 | cast<ConstantSDNode>(VLD->getOperand(NumVecs+3))->getZExtValue(); |
| 6290 | for (SDNode::use_iterator UI = VLD->use_begin(), UE = VLD->use_end(); |
| 6291 | UI != UE; ++UI) { |
| 6292 | // Ignore uses of the chain result. |
| 6293 | if (UI.getUse().getResNo() == NumVecs) |
| 6294 | continue; |
| 6295 | SDNode *User = *UI; |
| 6296 | if (User->getOpcode() != ARMISD::VDUPLANE || |
| 6297 | VLDLaneNo != cast<ConstantSDNode>(User->getOperand(1))->getZExtValue()) |
| 6298 | return false; |
| 6299 | } |
| 6300 | |
| 6301 | // Create the vldN-dup node. |
| 6302 | EVT Tys[5]; |
| 6303 | unsigned n; |
| 6304 | for (n = 0; n < NumVecs; ++n) |
| 6305 | Tys[n] = VT; |
| 6306 | Tys[n] = MVT::Other; |
| 6307 | SDVTList SDTys = DAG.getVTList(Tys, NumVecs+1); |
| 6308 | SDValue Ops[] = { VLD->getOperand(0), VLD->getOperand(2) }; |
| 6309 | MemIntrinsicSDNode *VLDMemInt = cast<MemIntrinsicSDNode>(VLD); |
| 6310 | SDValue VLDDup = DAG.getMemIntrinsicNode(NewOpc, VLD->getDebugLoc(), SDTys, |
| 6311 | Ops, 2, VLDMemInt->getMemoryVT(), |
| 6312 | VLDMemInt->getMemOperand()); |
| 6313 | |
| 6314 | // Update the uses. |
| 6315 | for (SDNode::use_iterator UI = VLD->use_begin(), UE = VLD->use_end(); |
| 6316 | UI != UE; ++UI) { |
| 6317 | unsigned ResNo = UI.getUse().getResNo(); |
| 6318 | // Ignore uses of the chain result. |
| 6319 | if (ResNo == NumVecs) |
| 6320 | continue; |
| 6321 | SDNode *User = *UI; |
| 6322 | DCI.CombineTo(User, SDValue(VLDDup.getNode(), ResNo)); |
| 6323 | } |
| 6324 | |
| 6325 | // Now the vldN-lane intrinsic is dead except for its chain result. |
| 6326 | // Update uses of the chain. |
| 6327 | std::vector<SDValue> VLDDupResults; |
| 6328 | for (unsigned n = 0; n < NumVecs; ++n) |
| 6329 | VLDDupResults.push_back(SDValue(VLDDup.getNode(), n)); |
| 6330 | VLDDupResults.push_back(SDValue(VLDDup.getNode(), NumVecs)); |
| 6331 | DCI.CombineTo(VLD, VLDDupResults); |
| 6332 | |
| 6333 | return true; |
| 6334 | } |
| 6335 | |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 6336 | /// PerformVDUPLANECombine - Target-specific dag combine xforms for |
| 6337 | /// ARMISD::VDUPLANE. |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 6338 | static SDValue PerformVDUPLANECombine(SDNode *N, |
| 6339 | TargetLowering::DAGCombinerInfo &DCI) { |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 6340 | SDValue Op = N->getOperand(0); |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 6341 | |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 6342 | // If the source is a vldN-lane (N > 1) intrinsic, and all the other uses |
| 6343 | // of that intrinsic are also VDUPLANEs, combine them to a vldN-dup operation. |
| 6344 | if (CombineVLDDUP(N, DCI)) |
| 6345 | return SDValue(N, 0); |
| 6346 | |
| 6347 | // If the source is already a VMOVIMM or VMVNIMM splat, the VDUPLANE is |
| 6348 | // redundant. Ignore bit_converts for now; element sizes are checked below. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6349 | while (Op.getOpcode() == ISD::BITCAST) |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 6350 | Op = Op.getOperand(0); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 6351 | if (Op.getOpcode() != ARMISD::VMOVIMM && Op.getOpcode() != ARMISD::VMVNIMM) |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 6352 | return SDValue(); |
| 6353 | |
| 6354 | // Make sure the VMOV element size is not bigger than the VDUPLANE elements. |
| 6355 | unsigned EltSize = Op.getValueType().getVectorElementType().getSizeInBits(); |
| 6356 | // The canonical VMOV for a zero vector uses a 32-bit element size. |
| 6357 | unsigned Imm = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
| 6358 | unsigned EltBits; |
| 6359 | if (ARM_AM::decodeNEONModImm(Imm, EltBits) == 0) |
| 6360 | EltSize = 8; |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 6361 | EVT VT = N->getValueType(0); |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 6362 | if (EltSize > VT.getVectorElementType().getSizeInBits()) |
| 6363 | return SDValue(); |
| 6364 | |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 6365 | return DCI.DAG.getNode(ISD::BITCAST, N->getDebugLoc(), VT, Op); |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 6366 | } |
| 6367 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6368 | /// getVShiftImm - Check if this is a valid build_vector for the immediate |
| 6369 | /// operand of a vector shift operation, where all the elements of the |
| 6370 | /// build_vector must have the same constant integer value. |
| 6371 | static bool getVShiftImm(SDValue Op, unsigned ElementBits, int64_t &Cnt) { |
| 6372 | // Ignore bit_converts. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6373 | while (Op.getOpcode() == ISD::BITCAST) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6374 | Op = Op.getOperand(0); |
| 6375 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(Op.getNode()); |
| 6376 | APInt SplatBits, SplatUndef; |
| 6377 | unsigned SplatBitSize; |
| 6378 | bool HasAnyUndefs; |
| 6379 | if (! BVN || ! BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, |
| 6380 | HasAnyUndefs, ElementBits) || |
| 6381 | SplatBitSize > ElementBits) |
| 6382 | return false; |
| 6383 | Cnt = SplatBits.getSExtValue(); |
| 6384 | return true; |
| 6385 | } |
| 6386 | |
| 6387 | /// isVShiftLImm - Check if this is a valid build_vector for the immediate |
| 6388 | /// operand of a vector shift left operation. That value must be in the range: |
| 6389 | /// 0 <= Value < ElementBits for a left shift; or |
| 6390 | /// 0 <= Value <= ElementBits for a long left shift. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6391 | static bool isVShiftLImm(SDValue Op, EVT VT, bool isLong, int64_t &Cnt) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6392 | assert(VT.isVector() && "vector shift count is not a vector type"); |
| 6393 | unsigned ElementBits = VT.getVectorElementType().getSizeInBits(); |
| 6394 | if (! getVShiftImm(Op, ElementBits, Cnt)) |
| 6395 | return false; |
| 6396 | return (Cnt >= 0 && (isLong ? Cnt-1 : Cnt) < ElementBits); |
| 6397 | } |
| 6398 | |
| 6399 | /// isVShiftRImm - Check if this is a valid build_vector for the immediate |
| 6400 | /// operand of a vector shift right operation. For a shift opcode, the value |
| 6401 | /// is positive, but for an intrinsic the value count must be negative. The |
| 6402 | /// absolute value must be in the range: |
| 6403 | /// 1 <= |Value| <= ElementBits for a right shift; or |
| 6404 | /// 1 <= |Value| <= ElementBits/2 for a narrow right shift. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6405 | static bool isVShiftRImm(SDValue Op, EVT VT, bool isNarrow, bool isIntrinsic, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6406 | int64_t &Cnt) { |
| 6407 | assert(VT.isVector() && "vector shift count is not a vector type"); |
| 6408 | unsigned ElementBits = VT.getVectorElementType().getSizeInBits(); |
| 6409 | if (! getVShiftImm(Op, ElementBits, Cnt)) |
| 6410 | return false; |
| 6411 | if (isIntrinsic) |
| 6412 | Cnt = -Cnt; |
| 6413 | return (Cnt >= 1 && Cnt <= (isNarrow ? ElementBits/2 : ElementBits)); |
| 6414 | } |
| 6415 | |
| 6416 | /// PerformIntrinsicCombine - ARM-specific DAG combining for intrinsics. |
| 6417 | static SDValue PerformIntrinsicCombine(SDNode *N, SelectionDAG &DAG) { |
| 6418 | unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue(); |
| 6419 | switch (IntNo) { |
| 6420 | default: |
| 6421 | // Don't do anything for most intrinsics. |
| 6422 | break; |
| 6423 | |
| 6424 | // Vector shifts: check for immediate versions and lower them. |
| 6425 | // Note: This is done during DAG combining instead of DAG legalizing because |
| 6426 | // the build_vectors for 64-bit vector element shift counts are generally |
| 6427 | // not legal, and it is hard to see their values after they get legalized to |
| 6428 | // loads from a constant pool. |
| 6429 | case Intrinsic::arm_neon_vshifts: |
| 6430 | case Intrinsic::arm_neon_vshiftu: |
| 6431 | case Intrinsic::arm_neon_vshiftls: |
| 6432 | case Intrinsic::arm_neon_vshiftlu: |
| 6433 | case Intrinsic::arm_neon_vshiftn: |
| 6434 | case Intrinsic::arm_neon_vrshifts: |
| 6435 | case Intrinsic::arm_neon_vrshiftu: |
| 6436 | case Intrinsic::arm_neon_vrshiftn: |
| 6437 | case Intrinsic::arm_neon_vqshifts: |
| 6438 | case Intrinsic::arm_neon_vqshiftu: |
| 6439 | case Intrinsic::arm_neon_vqshiftsu: |
| 6440 | case Intrinsic::arm_neon_vqshiftns: |
| 6441 | case Intrinsic::arm_neon_vqshiftnu: |
| 6442 | case Intrinsic::arm_neon_vqshiftnsu: |
| 6443 | case Intrinsic::arm_neon_vqrshiftns: |
| 6444 | case Intrinsic::arm_neon_vqrshiftnu: |
| 6445 | case Intrinsic::arm_neon_vqrshiftnsu: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6446 | EVT VT = N->getOperand(1).getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6447 | int64_t Cnt; |
| 6448 | unsigned VShiftOpc = 0; |
| 6449 | |
| 6450 | switch (IntNo) { |
| 6451 | case Intrinsic::arm_neon_vshifts: |
| 6452 | case Intrinsic::arm_neon_vshiftu: |
| 6453 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) { |
| 6454 | VShiftOpc = ARMISD::VSHL; |
| 6455 | break; |
| 6456 | } |
| 6457 | if (isVShiftRImm(N->getOperand(2), VT, false, true, Cnt)) { |
| 6458 | VShiftOpc = (IntNo == Intrinsic::arm_neon_vshifts ? |
| 6459 | ARMISD::VSHRs : ARMISD::VSHRu); |
| 6460 | break; |
| 6461 | } |
| 6462 | return SDValue(); |
| 6463 | |
| 6464 | case Intrinsic::arm_neon_vshiftls: |
| 6465 | case Intrinsic::arm_neon_vshiftlu: |
| 6466 | if (isVShiftLImm(N->getOperand(2), VT, true, Cnt)) |
| 6467 | break; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 6468 | llvm_unreachable("invalid shift count for vshll intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6469 | |
| 6470 | case Intrinsic::arm_neon_vrshifts: |
| 6471 | case Intrinsic::arm_neon_vrshiftu: |
| 6472 | if (isVShiftRImm(N->getOperand(2), VT, false, true, Cnt)) |
| 6473 | break; |
| 6474 | return SDValue(); |
| 6475 | |
| 6476 | case Intrinsic::arm_neon_vqshifts: |
| 6477 | case Intrinsic::arm_neon_vqshiftu: |
| 6478 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) |
| 6479 | break; |
| 6480 | return SDValue(); |
| 6481 | |
| 6482 | case Intrinsic::arm_neon_vqshiftsu: |
| 6483 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) |
| 6484 | break; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 6485 | llvm_unreachable("invalid shift count for vqshlu intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6486 | |
| 6487 | case Intrinsic::arm_neon_vshiftn: |
| 6488 | case Intrinsic::arm_neon_vrshiftn: |
| 6489 | case Intrinsic::arm_neon_vqshiftns: |
| 6490 | case Intrinsic::arm_neon_vqshiftnu: |
| 6491 | case Intrinsic::arm_neon_vqshiftnsu: |
| 6492 | case Intrinsic::arm_neon_vqrshiftns: |
| 6493 | case Intrinsic::arm_neon_vqrshiftnu: |
| 6494 | case Intrinsic::arm_neon_vqrshiftnsu: |
| 6495 | // Narrowing shifts require an immediate right shift. |
| 6496 | if (isVShiftRImm(N->getOperand(2), VT, true, true, Cnt)) |
| 6497 | break; |
Jim Grosbach | 18f30e6 | 2010-06-02 21:53:11 +0000 | [diff] [blame] | 6498 | llvm_unreachable("invalid shift count for narrowing vector shift " |
| 6499 | "intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6500 | |
| 6501 | default: |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 6502 | llvm_unreachable("unhandled vector shift"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6503 | } |
| 6504 | |
| 6505 | switch (IntNo) { |
| 6506 | case Intrinsic::arm_neon_vshifts: |
| 6507 | case Intrinsic::arm_neon_vshiftu: |
| 6508 | // Opcode already set above. |
| 6509 | break; |
| 6510 | case Intrinsic::arm_neon_vshiftls: |
| 6511 | case Intrinsic::arm_neon_vshiftlu: |
| 6512 | if (Cnt == VT.getVectorElementType().getSizeInBits()) |
| 6513 | VShiftOpc = ARMISD::VSHLLi; |
| 6514 | else |
| 6515 | VShiftOpc = (IntNo == Intrinsic::arm_neon_vshiftls ? |
| 6516 | ARMISD::VSHLLs : ARMISD::VSHLLu); |
| 6517 | break; |
| 6518 | case Intrinsic::arm_neon_vshiftn: |
| 6519 | VShiftOpc = ARMISD::VSHRN; break; |
| 6520 | case Intrinsic::arm_neon_vrshifts: |
| 6521 | VShiftOpc = ARMISD::VRSHRs; break; |
| 6522 | case Intrinsic::arm_neon_vrshiftu: |
| 6523 | VShiftOpc = ARMISD::VRSHRu; break; |
| 6524 | case Intrinsic::arm_neon_vrshiftn: |
| 6525 | VShiftOpc = ARMISD::VRSHRN; break; |
| 6526 | case Intrinsic::arm_neon_vqshifts: |
| 6527 | VShiftOpc = ARMISD::VQSHLs; break; |
| 6528 | case Intrinsic::arm_neon_vqshiftu: |
| 6529 | VShiftOpc = ARMISD::VQSHLu; break; |
| 6530 | case Intrinsic::arm_neon_vqshiftsu: |
| 6531 | VShiftOpc = ARMISD::VQSHLsu; break; |
| 6532 | case Intrinsic::arm_neon_vqshiftns: |
| 6533 | VShiftOpc = ARMISD::VQSHRNs; break; |
| 6534 | case Intrinsic::arm_neon_vqshiftnu: |
| 6535 | VShiftOpc = ARMISD::VQSHRNu; break; |
| 6536 | case Intrinsic::arm_neon_vqshiftnsu: |
| 6537 | VShiftOpc = ARMISD::VQSHRNsu; break; |
| 6538 | case Intrinsic::arm_neon_vqrshiftns: |
| 6539 | VShiftOpc = ARMISD::VQRSHRNs; break; |
| 6540 | case Intrinsic::arm_neon_vqrshiftnu: |
| 6541 | VShiftOpc = ARMISD::VQRSHRNu; break; |
| 6542 | case Intrinsic::arm_neon_vqrshiftnsu: |
| 6543 | VShiftOpc = ARMISD::VQRSHRNsu; break; |
| 6544 | } |
| 6545 | |
| 6546 | return DAG.getNode(VShiftOpc, N->getDebugLoc(), N->getValueType(0), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6547 | N->getOperand(1), DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6548 | } |
| 6549 | |
| 6550 | case Intrinsic::arm_neon_vshiftins: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6551 | EVT VT = N->getOperand(1).getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6552 | int64_t Cnt; |
| 6553 | unsigned VShiftOpc = 0; |
| 6554 | |
| 6555 | if (isVShiftLImm(N->getOperand(3), VT, false, Cnt)) |
| 6556 | VShiftOpc = ARMISD::VSLI; |
| 6557 | else if (isVShiftRImm(N->getOperand(3), VT, false, true, Cnt)) |
| 6558 | VShiftOpc = ARMISD::VSRI; |
| 6559 | else { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 6560 | llvm_unreachable("invalid shift count for vsli/vsri intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6561 | } |
| 6562 | |
| 6563 | return DAG.getNode(VShiftOpc, N->getDebugLoc(), N->getValueType(0), |
| 6564 | N->getOperand(1), N->getOperand(2), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6565 | DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6566 | } |
| 6567 | |
| 6568 | case Intrinsic::arm_neon_vqrshifts: |
| 6569 | case Intrinsic::arm_neon_vqrshiftu: |
| 6570 | // No immediate versions of these to check for. |
| 6571 | break; |
| 6572 | } |
| 6573 | |
| 6574 | return SDValue(); |
| 6575 | } |
| 6576 | |
| 6577 | /// PerformShiftCombine - Checks for immediate versions of vector shifts and |
| 6578 | /// lowers them. As with the vector shift intrinsics, this is done during DAG |
| 6579 | /// combining instead of DAG legalizing because the build_vectors for 64-bit |
| 6580 | /// vector element shift counts are generally not legal, and it is hard to see |
| 6581 | /// their values after they get legalized to loads from a constant pool. |
| 6582 | static SDValue PerformShiftCombine(SDNode *N, SelectionDAG &DAG, |
| 6583 | const ARMSubtarget *ST) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6584 | EVT VT = N->getValueType(0); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6585 | |
| 6586 | // Nothing to be done for scalar shifts. |
Tanya Lattner | 9684a7c | 2010-11-18 22:06:46 +0000 | [diff] [blame] | 6587 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 6588 | if (!VT.isVector() || !TLI.isTypeLegal(VT)) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6589 | return SDValue(); |
| 6590 | |
| 6591 | assert(ST->hasNEON() && "unexpected vector shift"); |
| 6592 | int64_t Cnt; |
| 6593 | |
| 6594 | switch (N->getOpcode()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 6595 | default: llvm_unreachable("unexpected shift opcode"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6596 | |
| 6597 | case ISD::SHL: |
| 6598 | if (isVShiftLImm(N->getOperand(1), VT, false, Cnt)) |
| 6599 | return DAG.getNode(ARMISD::VSHL, N->getDebugLoc(), VT, N->getOperand(0), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6600 | DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6601 | break; |
| 6602 | |
| 6603 | case ISD::SRA: |
| 6604 | case ISD::SRL: |
| 6605 | if (isVShiftRImm(N->getOperand(1), VT, false, false, Cnt)) { |
| 6606 | unsigned VShiftOpc = (N->getOpcode() == ISD::SRA ? |
| 6607 | ARMISD::VSHRs : ARMISD::VSHRu); |
| 6608 | return DAG.getNode(VShiftOpc, N->getDebugLoc(), VT, N->getOperand(0), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6609 | DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6610 | } |
| 6611 | } |
| 6612 | return SDValue(); |
| 6613 | } |
| 6614 | |
| 6615 | /// PerformExtendCombine - Target-specific DAG combining for ISD::SIGN_EXTEND, |
| 6616 | /// ISD::ZERO_EXTEND, and ISD::ANY_EXTEND. |
| 6617 | static SDValue PerformExtendCombine(SDNode *N, SelectionDAG &DAG, |
| 6618 | const ARMSubtarget *ST) { |
| 6619 | SDValue N0 = N->getOperand(0); |
| 6620 | |
| 6621 | // Check for sign- and zero-extensions of vector extract operations of 8- |
| 6622 | // and 16-bit vector elements. NEON supports these directly. They are |
| 6623 | // handled during DAG combining because type legalization will promote them |
| 6624 | // to 32-bit types and it is messy to recognize the operations after that. |
| 6625 | if (ST->hasNEON() && N0.getOpcode() == ISD::EXTRACT_VECTOR_ELT) { |
| 6626 | SDValue Vec = N0.getOperand(0); |
| 6627 | SDValue Lane = N0.getOperand(1); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6628 | EVT VT = N->getValueType(0); |
| 6629 | EVT EltVT = N0.getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6630 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 6631 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6632 | if (VT == MVT::i32 && |
| 6633 | (EltVT == MVT::i8 || EltVT == MVT::i16) && |
Bob Wilson | 3468c2e | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 6634 | TLI.isTypeLegal(Vec.getValueType()) && |
| 6635 | isa<ConstantSDNode>(Lane)) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6636 | |
| 6637 | unsigned Opc = 0; |
| 6638 | switch (N->getOpcode()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 6639 | default: llvm_unreachable("unexpected opcode"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6640 | case ISD::SIGN_EXTEND: |
| 6641 | Opc = ARMISD::VGETLANEs; |
| 6642 | break; |
| 6643 | case ISD::ZERO_EXTEND: |
| 6644 | case ISD::ANY_EXTEND: |
| 6645 | Opc = ARMISD::VGETLANEu; |
| 6646 | break; |
| 6647 | } |
| 6648 | return DAG.getNode(Opc, N->getDebugLoc(), VT, Vec, Lane); |
| 6649 | } |
| 6650 | } |
| 6651 | |
| 6652 | return SDValue(); |
| 6653 | } |
| 6654 | |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 6655 | /// PerformSELECT_CCCombine - Target-specific DAG combining for ISD::SELECT_CC |
| 6656 | /// to match f32 max/min patterns to use NEON vmax/vmin instructions. |
| 6657 | static SDValue PerformSELECT_CCCombine(SDNode *N, SelectionDAG &DAG, |
| 6658 | const ARMSubtarget *ST) { |
| 6659 | // 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] | 6660 | // selects like "x < y ? x : y". Unless the NoNaNsFPMath option is set, |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 6661 | // be careful about NaNs: NEON's vmax/vmin return NaN if either operand is |
| 6662 | // a NaN; only do the transformation when it matches that behavior. |
| 6663 | |
| 6664 | // For now only do this when using NEON for FP operations; if using VFP, it |
| 6665 | // is not obvious that the benefit outweighs the cost of switching to the |
| 6666 | // NEON pipeline. |
| 6667 | if (!ST->hasNEON() || !ST->useNEONForSinglePrecisionFP() || |
| 6668 | N->getValueType(0) != MVT::f32) |
| 6669 | return SDValue(); |
| 6670 | |
| 6671 | SDValue CondLHS = N->getOperand(0); |
| 6672 | SDValue CondRHS = N->getOperand(1); |
| 6673 | SDValue LHS = N->getOperand(2); |
| 6674 | SDValue RHS = N->getOperand(3); |
| 6675 | ISD::CondCode CC = cast<CondCodeSDNode>(N->getOperand(4))->get(); |
| 6676 | |
| 6677 | unsigned Opcode = 0; |
| 6678 | bool IsReversed; |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 6679 | if (DAG.isEqualTo(LHS, CondLHS) && DAG.isEqualTo(RHS, CondRHS)) { |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 6680 | IsReversed = false; // x CC y ? x : y |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 6681 | } else if (DAG.isEqualTo(LHS, CondRHS) && DAG.isEqualTo(RHS, CondLHS)) { |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 6682 | IsReversed = true ; // x CC y ? y : x |
| 6683 | } else { |
| 6684 | return SDValue(); |
| 6685 | } |
| 6686 | |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 6687 | bool IsUnordered; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 6688 | switch (CC) { |
| 6689 | default: break; |
| 6690 | case ISD::SETOLT: |
| 6691 | case ISD::SETOLE: |
| 6692 | case ISD::SETLT: |
| 6693 | case ISD::SETLE: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 6694 | case ISD::SETULT: |
| 6695 | case ISD::SETULE: |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 6696 | // If LHS is NaN, an ordered comparison will be false and the result will |
| 6697 | // be the RHS, but vmin(NaN, RHS) = NaN. Avoid this by checking that LHS |
| 6698 | // != NaN. Likewise, for unordered comparisons, check for RHS != NaN. |
| 6699 | IsUnordered = (CC == ISD::SETULT || CC == ISD::SETULE); |
| 6700 | if (!DAG.isKnownNeverNaN(IsUnordered ? RHS : LHS)) |
| 6701 | break; |
| 6702 | // For less-than-or-equal comparisons, "+0 <= -0" will be true but vmin |
| 6703 | // will return -0, so vmin can only be used for unsafe math or if one of |
| 6704 | // the operands is known to be nonzero. |
| 6705 | if ((CC == ISD::SETLE || CC == ISD::SETOLE || CC == ISD::SETULE) && |
| 6706 | !UnsafeFPMath && |
| 6707 | !(DAG.isKnownNeverZero(LHS) || DAG.isKnownNeverZero(RHS))) |
| 6708 | break; |
| 6709 | Opcode = IsReversed ? ARMISD::FMAX : ARMISD::FMIN; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 6710 | break; |
| 6711 | |
| 6712 | case ISD::SETOGT: |
| 6713 | case ISD::SETOGE: |
| 6714 | case ISD::SETGT: |
| 6715 | case ISD::SETGE: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 6716 | case ISD::SETUGT: |
| 6717 | case ISD::SETUGE: |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 6718 | // If LHS is NaN, an ordered comparison will be false and the result will |
| 6719 | // be the RHS, but vmax(NaN, RHS) = NaN. Avoid this by checking that LHS |
| 6720 | // != NaN. Likewise, for unordered comparisons, check for RHS != NaN. |
| 6721 | IsUnordered = (CC == ISD::SETUGT || CC == ISD::SETUGE); |
| 6722 | if (!DAG.isKnownNeverNaN(IsUnordered ? RHS : LHS)) |
| 6723 | break; |
| 6724 | // For greater-than-or-equal comparisons, "-0 >= +0" will be true but vmax |
| 6725 | // will return +0, so vmax can only be used for unsafe math or if one of |
| 6726 | // the operands is known to be nonzero. |
| 6727 | if ((CC == ISD::SETGE || CC == ISD::SETOGE || CC == ISD::SETUGE) && |
| 6728 | !UnsafeFPMath && |
| 6729 | !(DAG.isKnownNeverZero(LHS) || DAG.isKnownNeverZero(RHS))) |
| 6730 | break; |
| 6731 | Opcode = IsReversed ? ARMISD::FMIN : ARMISD::FMAX; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 6732 | break; |
| 6733 | } |
| 6734 | |
| 6735 | if (!Opcode) |
| 6736 | return SDValue(); |
| 6737 | return DAG.getNode(Opcode, N->getDebugLoc(), N->getValueType(0), LHS, RHS); |
| 6738 | } |
| 6739 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6740 | SDValue ARMTargetLowering::PerformDAGCombine(SDNode *N, |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 6741 | DAGCombinerInfo &DCI) const { |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 6742 | switch (N->getOpcode()) { |
| 6743 | default: break; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 6744 | case ISD::ADD: return PerformADDCombine(N, DCI); |
| 6745 | case ISD::SUB: return PerformSUBCombine(N, DCI); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 6746 | case ISD::MUL: return PerformMULCombine(N, DCI, Subtarget); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 6747 | case ISD::OR: return PerformORCombine(N, DCI, Subtarget); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 6748 | case ISD::AND: return PerformANDCombine(N, DCI); |
Evan Cheng | 0c1aec1 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 6749 | case ARMISD::BFI: return PerformBFICombine(N, DCI); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 6750 | case ARMISD::VMOVRRD: return PerformVMOVRRDCombine(N, DCI); |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 6751 | case ARMISD::VMOVDRR: return PerformVMOVDRRCombine(N, DCI.DAG); |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 6752 | case ISD::STORE: return PerformSTORECombine(N, DCI); |
| 6753 | case ISD::BUILD_VECTOR: return PerformBUILD_VECTORCombine(N, DCI); |
| 6754 | case ISD::INSERT_VECTOR_ELT: return PerformInsertEltCombine(N, DCI); |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 6755 | case ISD::VECTOR_SHUFFLE: return PerformVECTOR_SHUFFLECombine(N, DCI.DAG); |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 6756 | case ARMISD::VDUPLANE: return PerformVDUPLANECombine(N, DCI); |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 6757 | case ISD::INTRINSIC_WO_CHAIN: return PerformIntrinsicCombine(N, DCI.DAG); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6758 | case ISD::SHL: |
| 6759 | case ISD::SRA: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 6760 | case ISD::SRL: return PerformShiftCombine(N, DCI.DAG, Subtarget); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6761 | case ISD::SIGN_EXTEND: |
| 6762 | case ISD::ZERO_EXTEND: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 6763 | case ISD::ANY_EXTEND: return PerformExtendCombine(N, DCI.DAG, Subtarget); |
| 6764 | case ISD::SELECT_CC: return PerformSELECT_CCCombine(N, DCI.DAG, Subtarget); |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 6765 | case ARMISD::VLD2DUP: |
| 6766 | case ARMISD::VLD3DUP: |
| 6767 | case ARMISD::VLD4DUP: |
| 6768 | return CombineBaseUpdate(N, DCI); |
| 6769 | case ISD::INTRINSIC_VOID: |
| 6770 | case ISD::INTRINSIC_W_CHAIN: |
| 6771 | switch (cast<ConstantSDNode>(N->getOperand(1))->getZExtValue()) { |
| 6772 | case Intrinsic::arm_neon_vld1: |
| 6773 | case Intrinsic::arm_neon_vld2: |
| 6774 | case Intrinsic::arm_neon_vld3: |
| 6775 | case Intrinsic::arm_neon_vld4: |
| 6776 | case Intrinsic::arm_neon_vld2lane: |
| 6777 | case Intrinsic::arm_neon_vld3lane: |
| 6778 | case Intrinsic::arm_neon_vld4lane: |
| 6779 | case Intrinsic::arm_neon_vst1: |
| 6780 | case Intrinsic::arm_neon_vst2: |
| 6781 | case Intrinsic::arm_neon_vst3: |
| 6782 | case Intrinsic::arm_neon_vst4: |
| 6783 | case Intrinsic::arm_neon_vst2lane: |
| 6784 | case Intrinsic::arm_neon_vst3lane: |
| 6785 | case Intrinsic::arm_neon_vst4lane: |
| 6786 | return CombineBaseUpdate(N, DCI); |
| 6787 | default: break; |
| 6788 | } |
| 6789 | break; |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 6790 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6791 | return SDValue(); |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 6792 | } |
| 6793 | |
Evan Cheng | 31959b1 | 2011-02-02 01:06:55 +0000 | [diff] [blame] | 6794 | bool ARMTargetLowering::isDesirableToTransformToIntegerOp(unsigned Opc, |
| 6795 | EVT VT) const { |
| 6796 | return (VT == MVT::f32) && (Opc == ISD::LOAD || Opc == ISD::STORE); |
| 6797 | } |
| 6798 | |
Bill Wendling | af56634 | 2009-08-15 21:21:19 +0000 | [diff] [blame] | 6799 | bool ARMTargetLowering::allowsUnalignedMemoryAccesses(EVT VT) const { |
Bob Wilson | 02aba73 | 2010-09-28 04:09:35 +0000 | [diff] [blame] | 6800 | if (!Subtarget->allowsUnalignedMem()) |
Bob Wilson | 86fe66d | 2010-06-25 04:12:31 +0000 | [diff] [blame] | 6801 | return false; |
Bill Wendling | af56634 | 2009-08-15 21:21:19 +0000 | [diff] [blame] | 6802 | |
| 6803 | switch (VT.getSimpleVT().SimpleTy) { |
| 6804 | default: |
| 6805 | return false; |
| 6806 | case MVT::i8: |
| 6807 | case MVT::i16: |
| 6808 | case MVT::i32: |
| 6809 | return true; |
| 6810 | // FIXME: VLD1 etc with standard alignment is legal. |
| 6811 | } |
| 6812 | } |
| 6813 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 6814 | static bool isLegalT1AddressImmediate(int64_t V, EVT VT) { |
| 6815 | if (V < 0) |
| 6816 | return false; |
| 6817 | |
| 6818 | unsigned Scale = 1; |
| 6819 | switch (VT.getSimpleVT().SimpleTy) { |
| 6820 | default: return false; |
| 6821 | case MVT::i1: |
| 6822 | case MVT::i8: |
| 6823 | // Scale == 1; |
| 6824 | break; |
| 6825 | case MVT::i16: |
| 6826 | // Scale == 2; |
| 6827 | Scale = 2; |
| 6828 | break; |
| 6829 | case MVT::i32: |
| 6830 | // Scale == 4; |
| 6831 | Scale = 4; |
| 6832 | break; |
| 6833 | } |
| 6834 | |
| 6835 | if ((V & (Scale - 1)) != 0) |
| 6836 | return false; |
| 6837 | V /= Scale; |
| 6838 | return V == (V & ((1LL << 5) - 1)); |
| 6839 | } |
| 6840 | |
| 6841 | static bool isLegalT2AddressImmediate(int64_t V, EVT VT, |
| 6842 | const ARMSubtarget *Subtarget) { |
| 6843 | bool isNeg = false; |
| 6844 | if (V < 0) { |
| 6845 | isNeg = true; |
| 6846 | V = - V; |
| 6847 | } |
| 6848 | |
| 6849 | switch (VT.getSimpleVT().SimpleTy) { |
| 6850 | default: return false; |
| 6851 | case MVT::i1: |
| 6852 | case MVT::i8: |
| 6853 | case MVT::i16: |
| 6854 | case MVT::i32: |
| 6855 | // + imm12 or - imm8 |
| 6856 | if (isNeg) |
| 6857 | return V == (V & ((1LL << 8) - 1)); |
| 6858 | return V == (V & ((1LL << 12) - 1)); |
| 6859 | case MVT::f32: |
| 6860 | case MVT::f64: |
| 6861 | // Same as ARM mode. FIXME: NEON? |
| 6862 | if (!Subtarget->hasVFP2()) |
| 6863 | return false; |
| 6864 | if ((V & 3) != 0) |
| 6865 | return false; |
| 6866 | V >>= 2; |
| 6867 | return V == (V & ((1LL << 8) - 1)); |
| 6868 | } |
| 6869 | } |
| 6870 | |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 6871 | /// isLegalAddressImmediate - Return true if the integer value can be used |
| 6872 | /// as the offset of the target addressing mode for load / store of the |
| 6873 | /// given type. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6874 | static bool isLegalAddressImmediate(int64_t V, EVT VT, |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 6875 | const ARMSubtarget *Subtarget) { |
Evan Cheng | 961f879 | 2007-03-13 20:37:59 +0000 | [diff] [blame] | 6876 | if (V == 0) |
| 6877 | return true; |
| 6878 | |
Evan Cheng | 6501153 | 2009-03-09 19:15:00 +0000 | [diff] [blame] | 6879 | if (!VT.isSimple()) |
| 6880 | return false; |
| 6881 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 6882 | if (Subtarget->isThumb1Only()) |
| 6883 | return isLegalT1AddressImmediate(V, VT); |
| 6884 | else if (Subtarget->isThumb2()) |
| 6885 | return isLegalT2AddressImmediate(V, VT, Subtarget); |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 6886 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 6887 | // ARM mode. |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 6888 | if (V < 0) |
| 6889 | V = - V; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6890 | switch (VT.getSimpleVT().SimpleTy) { |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 6891 | default: return false; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6892 | case MVT::i1: |
| 6893 | case MVT::i8: |
| 6894 | case MVT::i32: |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 6895 | // +- imm12 |
Anton Korobeynikov | 7c1c261 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 6896 | return V == (V & ((1LL << 12) - 1)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6897 | case MVT::i16: |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 6898 | // +- imm8 |
Anton Korobeynikov | 7c1c261 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 6899 | return V == (V & ((1LL << 8) - 1)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6900 | case MVT::f32: |
| 6901 | case MVT::f64: |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 6902 | if (!Subtarget->hasVFP2()) // FIXME: NEON? |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 6903 | return false; |
Evan Cheng | 0b0a9a9 | 2007-05-03 02:00:18 +0000 | [diff] [blame] | 6904 | if ((V & 3) != 0) |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 6905 | return false; |
| 6906 | V >>= 2; |
Anton Korobeynikov | 7c1c261 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 6907 | return V == (V & ((1LL << 8) - 1)); |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 6908 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6909 | } |
| 6910 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 6911 | bool ARMTargetLowering::isLegalT2ScaledAddressingMode(const AddrMode &AM, |
| 6912 | EVT VT) const { |
| 6913 | int Scale = AM.Scale; |
| 6914 | if (Scale < 0) |
| 6915 | return false; |
| 6916 | |
| 6917 | switch (VT.getSimpleVT().SimpleTy) { |
| 6918 | default: return false; |
| 6919 | case MVT::i1: |
| 6920 | case MVT::i8: |
| 6921 | case MVT::i16: |
| 6922 | case MVT::i32: |
| 6923 | if (Scale == 1) |
| 6924 | return true; |
| 6925 | // r + r << imm |
| 6926 | Scale = Scale & ~1; |
| 6927 | return Scale == 2 || Scale == 4 || Scale == 8; |
| 6928 | case MVT::i64: |
| 6929 | // r + r |
| 6930 | if (((unsigned)AM.HasBaseReg + Scale) <= 2) |
| 6931 | return true; |
| 6932 | return false; |
| 6933 | case MVT::isVoid: |
| 6934 | // Note, we allow "void" uses (basically, uses that aren't loads or |
| 6935 | // stores), because arm allows folding a scale into many arithmetic |
| 6936 | // operations. This should be made more precise and revisited later. |
| 6937 | |
| 6938 | // Allow r << imm, but the imm has to be a multiple of two. |
| 6939 | if (Scale & 1) return false; |
| 6940 | return isPowerOf2_32(Scale); |
| 6941 | } |
| 6942 | } |
| 6943 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 6944 | /// isLegalAddressingMode - Return true if the addressing mode represented |
| 6945 | /// 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] | 6946 | bool ARMTargetLowering::isLegalAddressingMode(const AddrMode &AM, |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 6947 | const Type *Ty) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6948 | EVT VT = getValueType(Ty, true); |
Bob Wilson | 2c7dab1 | 2009-04-08 17:55:28 +0000 | [diff] [blame] | 6949 | if (!isLegalAddressImmediate(AM.BaseOffs, VT, Subtarget)) |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 6950 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 6951 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 6952 | // Can never fold addr of global into load/store. |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 6953 | if (AM.BaseGV) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 6954 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 6955 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 6956 | switch (AM.Scale) { |
| 6957 | case 0: // no scale reg, must be "r+i" or "r", or "i". |
| 6958 | break; |
| 6959 | case 1: |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 6960 | if (Subtarget->isThumb1Only()) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 6961 | return false; |
Chris Lattner | 5a3d40d | 2007-04-13 06:50:55 +0000 | [diff] [blame] | 6962 | // FALL THROUGH. |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 6963 | default: |
Chris Lattner | 5a3d40d | 2007-04-13 06:50:55 +0000 | [diff] [blame] | 6964 | // ARM doesn't support any R+R*scale+imm addr modes. |
| 6965 | if (AM.BaseOffs) |
| 6966 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 6967 | |
Bob Wilson | 2c7dab1 | 2009-04-08 17:55:28 +0000 | [diff] [blame] | 6968 | if (!VT.isSimple()) |
| 6969 | return false; |
| 6970 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 6971 | if (Subtarget->isThumb2()) |
| 6972 | return isLegalT2ScaledAddressingMode(AM, VT); |
| 6973 | |
Chris Lattner | eb13d1b | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 6974 | int Scale = AM.Scale; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6975 | switch (VT.getSimpleVT().SimpleTy) { |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 6976 | default: return false; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6977 | case MVT::i1: |
| 6978 | case MVT::i8: |
| 6979 | case MVT::i32: |
Chris Lattner | eb13d1b | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 6980 | if (Scale < 0) Scale = -Scale; |
| 6981 | if (Scale == 1) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 6982 | return true; |
| 6983 | // r + r << imm |
Chris Lattner | e115294 | 2007-04-11 16:17:12 +0000 | [diff] [blame] | 6984 | return isPowerOf2_32(Scale & ~1); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6985 | case MVT::i16: |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 6986 | case MVT::i64: |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 6987 | // r + r |
Chris Lattner | eb13d1b | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 6988 | if (((unsigned)AM.HasBaseReg + Scale) <= 2) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 6989 | return true; |
Chris Lattner | e115294 | 2007-04-11 16:17:12 +0000 | [diff] [blame] | 6990 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 6991 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6992 | case MVT::isVoid: |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 6993 | // Note, we allow "void" uses (basically, uses that aren't loads or |
| 6994 | // stores), because arm allows folding a scale into many arithmetic |
| 6995 | // operations. This should be made more precise and revisited later. |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 6996 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 6997 | // 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] | 6998 | if (Scale & 1) return false; |
| 6999 | return isPowerOf2_32(Scale); |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 7000 | } |
| 7001 | break; |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 7002 | } |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 7003 | return true; |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 7004 | } |
| 7005 | |
Evan Cheng | 77e4751 | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 7006 | /// isLegalICmpImmediate - Return true if the specified immediate is legal |
| 7007 | /// icmp immediate, that is the target has icmp instructions which can compare |
| 7008 | /// a register against the immediate without having to materialize the |
| 7009 | /// immediate into a register. |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 7010 | bool ARMTargetLowering::isLegalICmpImmediate(int64_t Imm) const { |
Evan Cheng | 77e4751 | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 7011 | if (!Subtarget->isThumb()) |
| 7012 | return ARM_AM::getSOImmVal(Imm) != -1; |
| 7013 | if (Subtarget->isThumb2()) |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 7014 | return ARM_AM::getT2SOImmVal(Imm) != -1; |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 7015 | return Imm >= 0 && Imm <= 255; |
Evan Cheng | 77e4751 | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 7016 | } |
| 7017 | |
Dan Gohman | cca8214 | 2011-05-03 00:46:49 +0000 | [diff] [blame] | 7018 | /// isLegalAddImmediate - Return true if the specified immediate is legal |
| 7019 | /// add immediate, that is the target has add instructions which can add |
| 7020 | /// a register with the immediate without having to materialize the |
| 7021 | /// immediate into a register. |
| 7022 | bool ARMTargetLowering::isLegalAddImmediate(int64_t Imm) const { |
| 7023 | return ARM_AM::getSOImmVal(Imm) != -1; |
| 7024 | } |
| 7025 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 7026 | static bool getARMIndexedAddressParts(SDNode *Ptr, EVT VT, |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 7027 | bool isSEXTLoad, SDValue &Base, |
| 7028 | SDValue &Offset, bool &isInc, |
| 7029 | SelectionDAG &DAG) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7030 | if (Ptr->getOpcode() != ISD::ADD && Ptr->getOpcode() != ISD::SUB) |
| 7031 | return false; |
| 7032 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 7033 | if (VT == MVT::i16 || ((VT == MVT::i8 || VT == MVT::i1) && isSEXTLoad)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7034 | // AddressingMode 3 |
| 7035 | Base = Ptr->getOperand(0); |
| 7036 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 7037 | int RHSC = (int)RHS->getZExtValue(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7038 | if (RHSC < 0 && RHSC > -256) { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 7039 | assert(Ptr->getOpcode() == ISD::ADD); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7040 | isInc = false; |
| 7041 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); |
| 7042 | return true; |
| 7043 | } |
| 7044 | } |
| 7045 | isInc = (Ptr->getOpcode() == ISD::ADD); |
| 7046 | Offset = Ptr->getOperand(1); |
| 7047 | return true; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 7048 | } else if (VT == MVT::i32 || VT == MVT::i8 || VT == MVT::i1) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7049 | // AddressingMode 2 |
| 7050 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 7051 | int RHSC = (int)RHS->getZExtValue(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7052 | if (RHSC < 0 && RHSC > -0x1000) { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 7053 | assert(Ptr->getOpcode() == ISD::ADD); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7054 | isInc = false; |
| 7055 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); |
| 7056 | Base = Ptr->getOperand(0); |
| 7057 | return true; |
| 7058 | } |
| 7059 | } |
| 7060 | |
| 7061 | if (Ptr->getOpcode() == ISD::ADD) { |
| 7062 | isInc = true; |
| 7063 | ARM_AM::ShiftOpc ShOpcVal= ARM_AM::getShiftOpcForNode(Ptr->getOperand(0)); |
| 7064 | if (ShOpcVal != ARM_AM::no_shift) { |
| 7065 | Base = Ptr->getOperand(1); |
| 7066 | Offset = Ptr->getOperand(0); |
| 7067 | } else { |
| 7068 | Base = Ptr->getOperand(0); |
| 7069 | Offset = Ptr->getOperand(1); |
| 7070 | } |
| 7071 | return true; |
| 7072 | } |
| 7073 | |
| 7074 | isInc = (Ptr->getOpcode() == ISD::ADD); |
| 7075 | Base = Ptr->getOperand(0); |
| 7076 | Offset = Ptr->getOperand(1); |
| 7077 | return true; |
| 7078 | } |
| 7079 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 7080 | // FIXME: Use VLDM / VSTM to emulate indexed FP load / store. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7081 | return false; |
| 7082 | } |
| 7083 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 7084 | static bool getT2IndexedAddressParts(SDNode *Ptr, EVT VT, |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 7085 | bool isSEXTLoad, SDValue &Base, |
| 7086 | SDValue &Offset, bool &isInc, |
| 7087 | SelectionDAG &DAG) { |
| 7088 | if (Ptr->getOpcode() != ISD::ADD && Ptr->getOpcode() != ISD::SUB) |
| 7089 | return false; |
| 7090 | |
| 7091 | Base = Ptr->getOperand(0); |
| 7092 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
| 7093 | int RHSC = (int)RHS->getZExtValue(); |
| 7094 | if (RHSC < 0 && RHSC > -0x100) { // 8 bits. |
| 7095 | assert(Ptr->getOpcode() == ISD::ADD); |
| 7096 | isInc = false; |
| 7097 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); |
| 7098 | return true; |
| 7099 | } else if (RHSC > 0 && RHSC < 0x100) { // 8 bit, no zero. |
| 7100 | isInc = Ptr->getOpcode() == ISD::ADD; |
| 7101 | Offset = DAG.getConstant(RHSC, RHS->getValueType(0)); |
| 7102 | return true; |
| 7103 | } |
| 7104 | } |
| 7105 | |
| 7106 | return false; |
| 7107 | } |
| 7108 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7109 | /// getPreIndexedAddressParts - returns true by value, base pointer and |
| 7110 | /// offset pointer and addressing mode by reference if the node's address |
| 7111 | /// can be legally represented as pre-indexed load / store address. |
| 7112 | bool |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7113 | ARMTargetLowering::getPreIndexedAddressParts(SDNode *N, SDValue &Base, |
| 7114 | SDValue &Offset, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7115 | ISD::MemIndexedMode &AM, |
Dan Gohman | 73e0914 | 2009-01-15 16:29:45 +0000 | [diff] [blame] | 7116 | SelectionDAG &DAG) const { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 7117 | if (Subtarget->isThumb1Only()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7118 | return false; |
| 7119 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 7120 | EVT VT; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7121 | SDValue Ptr; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7122 | bool isSEXTLoad = false; |
| 7123 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) { |
| 7124 | Ptr = LD->getBasePtr(); |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 7125 | VT = LD->getMemoryVT(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7126 | isSEXTLoad = LD->getExtensionType() == ISD::SEXTLOAD; |
| 7127 | } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) { |
| 7128 | Ptr = ST->getBasePtr(); |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 7129 | VT = ST->getMemoryVT(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7130 | } else |
| 7131 | return false; |
| 7132 | |
| 7133 | bool isInc; |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 7134 | bool isLegal = false; |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 7135 | if (Subtarget->isThumb2()) |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 7136 | isLegal = getT2IndexedAddressParts(Ptr.getNode(), VT, isSEXTLoad, Base, |
| 7137 | Offset, isInc, DAG); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 7138 | else |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 7139 | isLegal = getARMIndexedAddressParts(Ptr.getNode(), VT, isSEXTLoad, Base, |
Evan Cheng | 0412957 | 2009-07-02 06:44:30 +0000 | [diff] [blame] | 7140 | Offset, isInc, DAG); |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 7141 | if (!isLegal) |
| 7142 | return false; |
| 7143 | |
| 7144 | AM = isInc ? ISD::PRE_INC : ISD::PRE_DEC; |
| 7145 | return true; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7146 | } |
| 7147 | |
| 7148 | /// getPostIndexedAddressParts - returns true by value, base pointer and |
| 7149 | /// offset pointer and addressing mode by reference if this node can be |
| 7150 | /// combined with a load / store to form a post-indexed load / store. |
| 7151 | bool ARMTargetLowering::getPostIndexedAddressParts(SDNode *N, SDNode *Op, |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7152 | SDValue &Base, |
| 7153 | SDValue &Offset, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7154 | ISD::MemIndexedMode &AM, |
Dan Gohman | 73e0914 | 2009-01-15 16:29:45 +0000 | [diff] [blame] | 7155 | SelectionDAG &DAG) const { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 7156 | if (Subtarget->isThumb1Only()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7157 | return false; |
| 7158 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 7159 | EVT VT; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7160 | SDValue Ptr; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7161 | bool isSEXTLoad = false; |
| 7162 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) { |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 7163 | VT = LD->getMemoryVT(); |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 7164 | Ptr = LD->getBasePtr(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7165 | isSEXTLoad = LD->getExtensionType() == ISD::SEXTLOAD; |
| 7166 | } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) { |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 7167 | VT = ST->getMemoryVT(); |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 7168 | Ptr = ST->getBasePtr(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7169 | } else |
| 7170 | return false; |
| 7171 | |
| 7172 | bool isInc; |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 7173 | bool isLegal = false; |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 7174 | if (Subtarget->isThumb2()) |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 7175 | isLegal = getT2IndexedAddressParts(Op, VT, isSEXTLoad, Base, Offset, |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 7176 | isInc, DAG); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 7177 | else |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 7178 | isLegal = getARMIndexedAddressParts(Op, VT, isSEXTLoad, Base, Offset, |
| 7179 | isInc, DAG); |
| 7180 | if (!isLegal) |
| 7181 | return false; |
| 7182 | |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 7183 | if (Ptr != Base) { |
| 7184 | // Swap base ptr and offset to catch more post-index load / store when |
| 7185 | // it's legal. In Thumb2 mode, offset must be an immediate. |
| 7186 | if (Ptr == Offset && Op->getOpcode() == ISD::ADD && |
| 7187 | !Subtarget->isThumb2()) |
| 7188 | std::swap(Base, Offset); |
| 7189 | |
| 7190 | // Post-indexed load / store update the base pointer. |
| 7191 | if (Ptr != Base) |
| 7192 | return false; |
| 7193 | } |
| 7194 | |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 7195 | AM = isInc ? ISD::POST_INC : ISD::POST_DEC; |
| 7196 | return true; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7197 | } |
| 7198 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7199 | void ARMTargetLowering::computeMaskedBitsForTargetNode(const SDValue Op, |
Dan Gohman | 977a76f | 2008-02-13 22:28:48 +0000 | [diff] [blame] | 7200 | const APInt &Mask, |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 7201 | APInt &KnownZero, |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 7202 | APInt &KnownOne, |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 7203 | const SelectionDAG &DAG, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7204 | unsigned Depth) const { |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 7205 | KnownZero = KnownOne = APInt(Mask.getBitWidth(), 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7206 | switch (Op.getOpcode()) { |
| 7207 | default: break; |
| 7208 | case ARMISD::CMOV: { |
| 7209 | // Bits are known zero/one if known on the LHS and RHS. |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 7210 | DAG.ComputeMaskedBits(Op.getOperand(0), Mask, KnownZero, KnownOne, Depth+1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7211 | if (KnownZero == 0 && KnownOne == 0) return; |
| 7212 | |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 7213 | APInt KnownZeroRHS, KnownOneRHS; |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 7214 | DAG.ComputeMaskedBits(Op.getOperand(1), Mask, |
| 7215 | KnownZeroRHS, KnownOneRHS, Depth+1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7216 | KnownZero &= KnownZeroRHS; |
| 7217 | KnownOne &= KnownOneRHS; |
| 7218 | return; |
| 7219 | } |
| 7220 | } |
| 7221 | } |
| 7222 | |
| 7223 | //===----------------------------------------------------------------------===// |
| 7224 | // ARM Inline Assembly Support |
| 7225 | //===----------------------------------------------------------------------===// |
| 7226 | |
Evan Cheng | 55d4200 | 2011-01-08 01:24:27 +0000 | [diff] [blame] | 7227 | bool ARMTargetLowering::ExpandInlineAsm(CallInst *CI) const { |
| 7228 | // Looking for "rev" which is V6+. |
| 7229 | if (!Subtarget->hasV6Ops()) |
| 7230 | return false; |
| 7231 | |
| 7232 | InlineAsm *IA = cast<InlineAsm>(CI->getCalledValue()); |
| 7233 | std::string AsmStr = IA->getAsmString(); |
| 7234 | SmallVector<StringRef, 4> AsmPieces; |
| 7235 | SplitString(AsmStr, AsmPieces, ";\n"); |
| 7236 | |
| 7237 | switch (AsmPieces.size()) { |
| 7238 | default: return false; |
| 7239 | case 1: |
| 7240 | AsmStr = AsmPieces[0]; |
| 7241 | AsmPieces.clear(); |
| 7242 | SplitString(AsmStr, AsmPieces, " \t,"); |
| 7243 | |
| 7244 | // rev $0, $1 |
| 7245 | if (AsmPieces.size() == 3 && |
| 7246 | AsmPieces[0] == "rev" && AsmPieces[1] == "$0" && AsmPieces[2] == "$1" && |
| 7247 | IA->getConstraintString().compare(0, 4, "=l,l") == 0) { |
| 7248 | const IntegerType *Ty = dyn_cast<IntegerType>(CI->getType()); |
| 7249 | if (Ty && Ty->getBitWidth() == 32) |
| 7250 | return IntrinsicLowering::LowerToByteSwap(CI); |
| 7251 | } |
| 7252 | break; |
| 7253 | } |
| 7254 | |
| 7255 | return false; |
| 7256 | } |
| 7257 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7258 | /// getConstraintType - Given a constraint letter, return the type of |
| 7259 | /// constraint it is for this target. |
| 7260 | ARMTargetLowering::ConstraintType |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 7261 | ARMTargetLowering::getConstraintType(const std::string &Constraint) const { |
| 7262 | if (Constraint.size() == 1) { |
| 7263 | switch (Constraint[0]) { |
| 7264 | default: break; |
| 7265 | case 'l': return C_RegisterClass; |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 7266 | case 'w': return C_RegisterClass; |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 7267 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7268 | } |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 7269 | return TargetLowering::getConstraintType(Constraint); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7270 | } |
| 7271 | |
John Thompson | 44ab89e | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 7272 | /// Examine constraint type and operand type and determine a weight value. |
| 7273 | /// This object must already have been set up with the operand type |
| 7274 | /// and the current alternative constraint selected. |
| 7275 | TargetLowering::ConstraintWeight |
| 7276 | ARMTargetLowering::getSingleConstraintMatchWeight( |
| 7277 | AsmOperandInfo &info, const char *constraint) const { |
| 7278 | ConstraintWeight weight = CW_Invalid; |
| 7279 | Value *CallOperandVal = info.CallOperandVal; |
| 7280 | // If we don't have a value, we can't do a match, |
| 7281 | // but allow it at the lowest weight. |
| 7282 | if (CallOperandVal == NULL) |
| 7283 | return CW_Default; |
| 7284 | const Type *type = CallOperandVal->getType(); |
| 7285 | // Look at the constraint type. |
| 7286 | switch (*constraint) { |
| 7287 | default: |
| 7288 | weight = TargetLowering::getSingleConstraintMatchWeight(info, constraint); |
| 7289 | break; |
| 7290 | case 'l': |
| 7291 | if (type->isIntegerTy()) { |
| 7292 | if (Subtarget->isThumb()) |
| 7293 | weight = CW_SpecificReg; |
| 7294 | else |
| 7295 | weight = CW_Register; |
| 7296 | } |
| 7297 | break; |
| 7298 | case 'w': |
| 7299 | if (type->isFloatingPointTy()) |
| 7300 | weight = CW_Register; |
| 7301 | break; |
| 7302 | } |
| 7303 | return weight; |
| 7304 | } |
| 7305 | |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 7306 | std::pair<unsigned, const TargetRegisterClass*> |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7307 | ARMTargetLowering::getRegForInlineAsmConstraint(const std::string &Constraint, |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 7308 | EVT VT) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7309 | if (Constraint.size() == 1) { |
Jakob Stoklund Olesen | 09bf003 | 2010-01-14 18:19:56 +0000 | [diff] [blame] | 7310 | // GCC ARM Constraint Letters |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7311 | switch (Constraint[0]) { |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 7312 | case 'l': |
Jakob Stoklund Olesen | 09bf003 | 2010-01-14 18:19:56 +0000 | [diff] [blame] | 7313 | if (Subtarget->isThumb()) |
Jim Grosbach | 30eae3c | 2009-04-07 20:34:09 +0000 | [diff] [blame] | 7314 | return std::make_pair(0U, ARM::tGPRRegisterClass); |
| 7315 | else |
| 7316 | return std::make_pair(0U, ARM::GPRRegisterClass); |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 7317 | case 'r': |
| 7318 | return std::make_pair(0U, ARM::GPRRegisterClass); |
| 7319 | case 'w': |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 7320 | if (VT == MVT::f32) |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 7321 | return std::make_pair(0U, ARM::SPRRegisterClass); |
Bob Wilson | 5afffae | 2009-12-18 01:03:29 +0000 | [diff] [blame] | 7322 | if (VT.getSizeInBits() == 64) |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 7323 | return std::make_pair(0U, ARM::DPRRegisterClass); |
Evan Cheng | d831cda | 2009-12-08 23:06:22 +0000 | [diff] [blame] | 7324 | if (VT.getSizeInBits() == 128) |
| 7325 | return std::make_pair(0U, ARM::QPRRegisterClass); |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 7326 | break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7327 | } |
| 7328 | } |
Bob Wilson | 33cc5cb | 2010-03-15 23:09:18 +0000 | [diff] [blame] | 7329 | if (StringRef("{cc}").equals_lower(Constraint)) |
Jakob Stoklund Olesen | 0d8ba33 | 2010-06-18 16:49:33 +0000 | [diff] [blame] | 7330 | return std::make_pair(unsigned(ARM::CPSR), ARM::CCRRegisterClass); |
Bob Wilson | 33cc5cb | 2010-03-15 23:09:18 +0000 | [diff] [blame] | 7331 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7332 | return TargetLowering::getRegForInlineAsmConstraint(Constraint, VT); |
| 7333 | } |
| 7334 | |
| 7335 | std::vector<unsigned> ARMTargetLowering:: |
| 7336 | getRegClassForInlineAsmConstraint(const std::string &Constraint, |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 7337 | EVT VT) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7338 | if (Constraint.size() != 1) |
| 7339 | return std::vector<unsigned>(); |
| 7340 | |
| 7341 | switch (Constraint[0]) { // GCC ARM Constraint Letters |
| 7342 | default: break; |
| 7343 | case 'l': |
Jim Grosbach | 30eae3c | 2009-04-07 20:34:09 +0000 | [diff] [blame] | 7344 | return make_vector<unsigned>(ARM::R0, ARM::R1, ARM::R2, ARM::R3, |
| 7345 | ARM::R4, ARM::R5, ARM::R6, ARM::R7, |
| 7346 | 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7347 | case 'r': |
| 7348 | return make_vector<unsigned>(ARM::R0, ARM::R1, ARM::R2, ARM::R3, |
| 7349 | ARM::R4, ARM::R5, ARM::R6, ARM::R7, |
| 7350 | ARM::R8, ARM::R9, ARM::R10, ARM::R11, |
| 7351 | ARM::R12, ARM::LR, 0); |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 7352 | case 'w': |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 7353 | if (VT == MVT::f32) |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 7354 | return make_vector<unsigned>(ARM::S0, ARM::S1, ARM::S2, ARM::S3, |
| 7355 | ARM::S4, ARM::S5, ARM::S6, ARM::S7, |
| 7356 | ARM::S8, ARM::S9, ARM::S10, ARM::S11, |
| 7357 | ARM::S12,ARM::S13,ARM::S14,ARM::S15, |
| 7358 | ARM::S16,ARM::S17,ARM::S18,ARM::S19, |
| 7359 | ARM::S20,ARM::S21,ARM::S22,ARM::S23, |
| 7360 | ARM::S24,ARM::S25,ARM::S26,ARM::S27, |
| 7361 | ARM::S28,ARM::S29,ARM::S30,ARM::S31, 0); |
Bob Wilson | 5afffae | 2009-12-18 01:03:29 +0000 | [diff] [blame] | 7362 | if (VT.getSizeInBits() == 64) |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 7363 | return make_vector<unsigned>(ARM::D0, ARM::D1, ARM::D2, ARM::D3, |
| 7364 | ARM::D4, ARM::D5, ARM::D6, ARM::D7, |
| 7365 | ARM::D8, ARM::D9, ARM::D10,ARM::D11, |
| 7366 | ARM::D12,ARM::D13,ARM::D14,ARM::D15, 0); |
Evan Cheng | d831cda | 2009-12-08 23:06:22 +0000 | [diff] [blame] | 7367 | if (VT.getSizeInBits() == 128) |
| 7368 | return make_vector<unsigned>(ARM::Q0, ARM::Q1, ARM::Q2, ARM::Q3, |
| 7369 | ARM::Q4, ARM::Q5, ARM::Q6, ARM::Q7, 0); |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 7370 | break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7371 | } |
| 7372 | |
| 7373 | return std::vector<unsigned>(); |
| 7374 | } |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 7375 | |
| 7376 | /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops |
| 7377 | /// vector. If it is invalid, don't add anything to Ops. |
| 7378 | void ARMTargetLowering::LowerAsmOperandForConstraint(SDValue Op, |
| 7379 | char Constraint, |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 7380 | std::vector<SDValue>&Ops, |
| 7381 | SelectionDAG &DAG) const { |
| 7382 | SDValue Result(0, 0); |
| 7383 | |
| 7384 | switch (Constraint) { |
| 7385 | default: break; |
| 7386 | case 'I': case 'J': case 'K': case 'L': |
| 7387 | case 'M': case 'N': case 'O': |
| 7388 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op); |
| 7389 | if (!C) |
| 7390 | return; |
| 7391 | |
| 7392 | int64_t CVal64 = C->getSExtValue(); |
| 7393 | int CVal = (int) CVal64; |
| 7394 | // None of these constraints allow values larger than 32 bits. Check |
| 7395 | // that the value fits in an int. |
| 7396 | if (CVal != CVal64) |
| 7397 | return; |
| 7398 | |
| 7399 | switch (Constraint) { |
| 7400 | case 'I': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 7401 | if (Subtarget->isThumb1Only()) { |
| 7402 | // This must be a constant between 0 and 255, for ADD |
| 7403 | // immediates. |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 7404 | if (CVal >= 0 && CVal <= 255) |
| 7405 | break; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 7406 | } else if (Subtarget->isThumb2()) { |
| 7407 | // A constant that can be used as an immediate value in a |
| 7408 | // data-processing instruction. |
| 7409 | if (ARM_AM::getT2SOImmVal(CVal) != -1) |
| 7410 | break; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 7411 | } else { |
| 7412 | // A constant that can be used as an immediate value in a |
| 7413 | // data-processing instruction. |
| 7414 | if (ARM_AM::getSOImmVal(CVal) != -1) |
| 7415 | break; |
| 7416 | } |
| 7417 | return; |
| 7418 | |
| 7419 | case 'J': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 7420 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 7421 | // This must be a constant between -255 and -1, for negated ADD |
| 7422 | // immediates. This can be used in GCC with an "n" modifier that |
| 7423 | // prints the negated value, for use with SUB instructions. It is |
| 7424 | // not useful otherwise but is implemented for compatibility. |
| 7425 | if (CVal >= -255 && CVal <= -1) |
| 7426 | break; |
| 7427 | } else { |
| 7428 | // This must be a constant between -4095 and 4095. It is not clear |
| 7429 | // what this constraint is intended for. Implemented for |
| 7430 | // compatibility with GCC. |
| 7431 | if (CVal >= -4095 && CVal <= 4095) |
| 7432 | break; |
| 7433 | } |
| 7434 | return; |
| 7435 | |
| 7436 | case 'K': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 7437 | if (Subtarget->isThumb1Only()) { |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 7438 | // A 32-bit value where only one byte has a nonzero value. Exclude |
| 7439 | // zero to match GCC. This constraint is used by GCC internally for |
| 7440 | // constants that can be loaded with a move/shift combination. |
| 7441 | // It is not useful otherwise but is implemented for compatibility. |
| 7442 | if (CVal != 0 && ARM_AM::isThumbImmShiftedVal(CVal)) |
| 7443 | break; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 7444 | } else if (Subtarget->isThumb2()) { |
| 7445 | // A constant whose bitwise inverse can be used as an immediate |
| 7446 | // value in a data-processing instruction. This can be used in GCC |
| 7447 | // with a "B" modifier that prints the inverted value, for use with |
| 7448 | // BIC and MVN instructions. It is not useful otherwise but is |
| 7449 | // implemented for compatibility. |
| 7450 | if (ARM_AM::getT2SOImmVal(~CVal) != -1) |
| 7451 | break; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 7452 | } else { |
| 7453 | // A constant whose bitwise inverse can be used as an immediate |
| 7454 | // value in a data-processing instruction. This can be used in GCC |
| 7455 | // with a "B" modifier that prints the inverted value, for use with |
| 7456 | // BIC and MVN instructions. It is not useful otherwise but is |
| 7457 | // implemented for compatibility. |
| 7458 | if (ARM_AM::getSOImmVal(~CVal) != -1) |
| 7459 | break; |
| 7460 | } |
| 7461 | return; |
| 7462 | |
| 7463 | case 'L': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 7464 | if (Subtarget->isThumb1Only()) { |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 7465 | // This must be a constant between -7 and 7, |
| 7466 | // for 3-operand ADD/SUB immediate instructions. |
| 7467 | if (CVal >= -7 && CVal < 7) |
| 7468 | break; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 7469 | } else if (Subtarget->isThumb2()) { |
| 7470 | // A constant whose negation can be used as an immediate value in a |
| 7471 | // data-processing instruction. This can be used in GCC with an "n" |
| 7472 | // modifier that prints the negated value, for use with SUB |
| 7473 | // instructions. It is not useful otherwise but is implemented for |
| 7474 | // compatibility. |
| 7475 | if (ARM_AM::getT2SOImmVal(-CVal) != -1) |
| 7476 | break; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 7477 | } else { |
| 7478 | // A constant whose negation can be used as an immediate value in a |
| 7479 | // data-processing instruction. This can be used in GCC with an "n" |
| 7480 | // modifier that prints the negated value, for use with SUB |
| 7481 | // instructions. It is not useful otherwise but is implemented for |
| 7482 | // compatibility. |
| 7483 | if (ARM_AM::getSOImmVal(-CVal) != -1) |
| 7484 | break; |
| 7485 | } |
| 7486 | return; |
| 7487 | |
| 7488 | case 'M': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 7489 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 7490 | // This must be a multiple of 4 between 0 and 1020, for |
| 7491 | // ADD sp + immediate. |
| 7492 | if ((CVal >= 0 && CVal <= 1020) && ((CVal & 3) == 0)) |
| 7493 | break; |
| 7494 | } else { |
| 7495 | // A power of two or a constant between 0 and 32. This is used in |
| 7496 | // GCC for the shift amount on shifted register operands, but it is |
| 7497 | // useful in general for any shift amounts. |
| 7498 | if ((CVal >= 0 && CVal <= 32) || ((CVal & (CVal - 1)) == 0)) |
| 7499 | break; |
| 7500 | } |
| 7501 | return; |
| 7502 | |
| 7503 | case 'N': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 7504 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 7505 | // This must be a constant between 0 and 31, for shift amounts. |
| 7506 | if (CVal >= 0 && CVal <= 31) |
| 7507 | break; |
| 7508 | } |
| 7509 | return; |
| 7510 | |
| 7511 | case 'O': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 7512 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 7513 | // This must be a multiple of 4 between -508 and 508, for |
| 7514 | // ADD/SUB sp = sp + immediate. |
| 7515 | if ((CVal >= -508 && CVal <= 508) && ((CVal & 3) == 0)) |
| 7516 | break; |
| 7517 | } |
| 7518 | return; |
| 7519 | } |
| 7520 | Result = DAG.getTargetConstant(CVal, Op.getValueType()); |
| 7521 | break; |
| 7522 | } |
| 7523 | |
| 7524 | if (Result.getNode()) { |
| 7525 | Ops.push_back(Result); |
| 7526 | return; |
| 7527 | } |
Dale Johannesen | 1784d16 | 2010-06-25 21:55:36 +0000 | [diff] [blame] | 7528 | return TargetLowering::LowerAsmOperandForConstraint(Op, Constraint, Ops, DAG); |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 7529 | } |
Anton Korobeynikov | 48e1935 | 2009-09-23 19:04:09 +0000 | [diff] [blame] | 7530 | |
| 7531 | bool |
| 7532 | ARMTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const { |
| 7533 | // The ARM target isn't yet aware of offsets. |
| 7534 | return false; |
| 7535 | } |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 7536 | |
| 7537 | int ARM::getVFPf32Imm(const APFloat &FPImm) { |
| 7538 | APInt Imm = FPImm.bitcastToAPInt(); |
| 7539 | uint32_t Sign = Imm.lshr(31).getZExtValue() & 1; |
| 7540 | int32_t Exp = (Imm.lshr(23).getSExtValue() & 0xff) - 127; // -126 to 127 |
| 7541 | int64_t Mantissa = Imm.getZExtValue() & 0x7fffff; // 23 bits |
| 7542 | |
| 7543 | // We can handle 4 bits of mantissa. |
| 7544 | // mantissa = (16+UInt(e:f:g:h))/16. |
| 7545 | if (Mantissa & 0x7ffff) |
| 7546 | return -1; |
| 7547 | Mantissa >>= 19; |
| 7548 | if ((Mantissa & 0xf) != Mantissa) |
| 7549 | return -1; |
| 7550 | |
| 7551 | // We can handle 3 bits of exponent: exp == UInt(NOT(b):c:d)-3 |
| 7552 | if (Exp < -3 || Exp > 4) |
| 7553 | return -1; |
| 7554 | Exp = ((Exp+3) & 0x7) ^ 4; |
| 7555 | |
| 7556 | return ((int)Sign << 7) | (Exp << 4) | Mantissa; |
| 7557 | } |
| 7558 | |
| 7559 | int ARM::getVFPf64Imm(const APFloat &FPImm) { |
| 7560 | APInt Imm = FPImm.bitcastToAPInt(); |
| 7561 | uint64_t Sign = Imm.lshr(63).getZExtValue() & 1; |
| 7562 | int64_t Exp = (Imm.lshr(52).getSExtValue() & 0x7ff) - 1023; // -1022 to 1023 |
| 7563 | uint64_t Mantissa = Imm.getZExtValue() & 0xfffffffffffffLL; |
| 7564 | |
| 7565 | // We can handle 4 bits of mantissa. |
| 7566 | // mantissa = (16+UInt(e:f:g:h))/16. |
| 7567 | if (Mantissa & 0xffffffffffffLL) |
| 7568 | return -1; |
| 7569 | Mantissa >>= 48; |
| 7570 | if ((Mantissa & 0xf) != Mantissa) |
| 7571 | return -1; |
| 7572 | |
| 7573 | // We can handle 3 bits of exponent: exp == UInt(NOT(b):c:d)-3 |
| 7574 | if (Exp < -3 || Exp > 4) |
| 7575 | return -1; |
| 7576 | Exp = ((Exp+3) & 0x7) ^ 4; |
| 7577 | |
| 7578 | return ((int)Sign << 7) | (Exp << 4) | Mantissa; |
| 7579 | } |
| 7580 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 7581 | bool ARM::isBitFieldInvertedMask(unsigned v) { |
| 7582 | if (v == 0xffffffff) |
| 7583 | return 0; |
| 7584 | // there can be 1's on either or both "outsides", all the "inside" |
| 7585 | // bits must be 0's |
| 7586 | unsigned int lsb = 0, msb = 31; |
| 7587 | while (v & (1 << msb)) --msb; |
| 7588 | while (v & (1 << lsb)) ++lsb; |
| 7589 | for (unsigned int i = lsb; i <= msb; ++i) { |
| 7590 | if (v & (1 << i)) |
| 7591 | return 0; |
| 7592 | } |
| 7593 | return 1; |
| 7594 | } |
| 7595 | |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 7596 | /// isFPImmLegal - Returns true if the target can instruction select the |
| 7597 | /// specified FP immediate natively. If false, the legalizer will |
| 7598 | /// materialize the FP immediate as a load from a constant pool. |
| 7599 | bool ARMTargetLowering::isFPImmLegal(const APFloat &Imm, EVT VT) const { |
| 7600 | if (!Subtarget->hasVFP3()) |
| 7601 | return false; |
| 7602 | if (VT == MVT::f32) |
| 7603 | return ARM::getVFPf32Imm(Imm) != -1; |
| 7604 | if (VT == MVT::f64) |
| 7605 | return ARM::getVFPf64Imm(Imm) != -1; |
| 7606 | return false; |
| 7607 | } |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 7608 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7609 | /// getTgtMemIntrinsic - Represent NEON load and store intrinsics as |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 7610 | /// MemIntrinsicNodes. The associated MachineMemOperands record the alignment |
| 7611 | /// specified in the intrinsic calls. |
| 7612 | bool ARMTargetLowering::getTgtMemIntrinsic(IntrinsicInfo &Info, |
| 7613 | const CallInst &I, |
| 7614 | unsigned Intrinsic) const { |
| 7615 | switch (Intrinsic) { |
| 7616 | case Intrinsic::arm_neon_vld1: |
| 7617 | case Intrinsic::arm_neon_vld2: |
| 7618 | case Intrinsic::arm_neon_vld3: |
| 7619 | case Intrinsic::arm_neon_vld4: |
| 7620 | case Intrinsic::arm_neon_vld2lane: |
| 7621 | case Intrinsic::arm_neon_vld3lane: |
| 7622 | case Intrinsic::arm_neon_vld4lane: { |
| 7623 | Info.opc = ISD::INTRINSIC_W_CHAIN; |
| 7624 | // Conservatively set memVT to the entire set of vectors loaded. |
| 7625 | uint64_t NumElts = getTargetData()->getTypeAllocSize(I.getType()) / 8; |
| 7626 | Info.memVT = EVT::getVectorVT(I.getType()->getContext(), MVT::i64, NumElts); |
| 7627 | Info.ptrVal = I.getArgOperand(0); |
| 7628 | Info.offset = 0; |
| 7629 | Value *AlignArg = I.getArgOperand(I.getNumArgOperands() - 1); |
| 7630 | Info.align = cast<ConstantInt>(AlignArg)->getZExtValue(); |
| 7631 | Info.vol = false; // volatile loads with NEON intrinsics not supported |
| 7632 | Info.readMem = true; |
| 7633 | Info.writeMem = false; |
| 7634 | return true; |
| 7635 | } |
| 7636 | case Intrinsic::arm_neon_vst1: |
| 7637 | case Intrinsic::arm_neon_vst2: |
| 7638 | case Intrinsic::arm_neon_vst3: |
| 7639 | case Intrinsic::arm_neon_vst4: |
| 7640 | case Intrinsic::arm_neon_vst2lane: |
| 7641 | case Intrinsic::arm_neon_vst3lane: |
| 7642 | case Intrinsic::arm_neon_vst4lane: { |
| 7643 | Info.opc = ISD::INTRINSIC_VOID; |
| 7644 | // Conservatively set memVT to the entire set of vectors stored. |
| 7645 | unsigned NumElts = 0; |
| 7646 | for (unsigned ArgI = 1, ArgE = I.getNumArgOperands(); ArgI < ArgE; ++ArgI) { |
| 7647 | const Type *ArgTy = I.getArgOperand(ArgI)->getType(); |
| 7648 | if (!ArgTy->isVectorTy()) |
| 7649 | break; |
| 7650 | NumElts += getTargetData()->getTypeAllocSize(ArgTy) / 8; |
| 7651 | } |
| 7652 | Info.memVT = EVT::getVectorVT(I.getType()->getContext(), MVT::i64, NumElts); |
| 7653 | Info.ptrVal = I.getArgOperand(0); |
| 7654 | Info.offset = 0; |
| 7655 | Value *AlignArg = I.getArgOperand(I.getNumArgOperands() - 1); |
| 7656 | Info.align = cast<ConstantInt>(AlignArg)->getZExtValue(); |
| 7657 | Info.vol = false; // volatile stores with NEON intrinsics not supported |
| 7658 | Info.readMem = false; |
| 7659 | Info.writeMem = true; |
| 7660 | return true; |
| 7661 | } |
Bruno Cardoso Lopes | a0112d0 | 2011-05-28 04:07:29 +0000 | [diff] [blame] | 7662 | case Intrinsic::arm_strexd: { |
| 7663 | Info.opc = ISD::INTRINSIC_W_CHAIN; |
| 7664 | Info.memVT = MVT::i64; |
| 7665 | Info.ptrVal = I.getArgOperand(2); |
| 7666 | Info.offset = 0; |
| 7667 | Info.align = 8; |
| 7668 | Info.vol = false; |
| 7669 | Info.readMem = false; |
| 7670 | Info.writeMem = true; |
| 7671 | return true; |
| 7672 | } |
| 7673 | case Intrinsic::arm_ldrexd: { |
| 7674 | Info.opc = ISD::INTRINSIC_W_CHAIN; |
| 7675 | Info.memVT = MVT::i64; |
| 7676 | Info.ptrVal = I.getArgOperand(0); |
| 7677 | Info.offset = 0; |
| 7678 | Info.align = 8; |
| 7679 | Info.vol = false; |
| 7680 | Info.readMem = true; |
| 7681 | Info.writeMem = false; |
| 7682 | return true; |
| 7683 | } |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 7684 | default: |
| 7685 | break; |
| 7686 | } |
| 7687 | |
| 7688 | return false; |
| 7689 | } |