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 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 75 | void ARMTargetLowering::addTypeForNEON(EVT VT, EVT PromotedLdStVT, |
| 76 | EVT PromotedBitwiseVT) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 77 | if (VT != PromotedLdStVT) { |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 78 | setOperationAction(ISD::LOAD, VT.getSimpleVT(), Promote); |
Owen Anderson | d6662ad | 2009-08-10 20:46:15 +0000 | [diff] [blame] | 79 | AddPromotedToType (ISD::LOAD, VT.getSimpleVT(), |
| 80 | PromotedLdStVT.getSimpleVT()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 81 | |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 82 | setOperationAction(ISD::STORE, VT.getSimpleVT(), Promote); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 83 | AddPromotedToType (ISD::STORE, VT.getSimpleVT(), |
Owen Anderson | d6662ad | 2009-08-10 20:46:15 +0000 | [diff] [blame] | 84 | PromotedLdStVT.getSimpleVT()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 85 | } |
| 86 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 87 | EVT ElemTy = VT.getVectorElementType(); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 88 | if (ElemTy != MVT::i64 && ElemTy != MVT::f64) |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 89 | setOperationAction(ISD::VSETCC, VT.getSimpleVT(), Custom); |
Bob Wilson | 3468c2e | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 90 | setOperationAction(ISD::EXTRACT_VECTOR_ELT, VT.getSimpleVT(), Custom); |
Bob Wilson | 0696fdf | 2009-09-16 20:20:44 +0000 | [diff] [blame] | 91 | if (ElemTy != MVT::i32) { |
| 92 | setOperationAction(ISD::SINT_TO_FP, VT.getSimpleVT(), Expand); |
| 93 | setOperationAction(ISD::UINT_TO_FP, VT.getSimpleVT(), Expand); |
| 94 | setOperationAction(ISD::FP_TO_SINT, VT.getSimpleVT(), Expand); |
| 95 | setOperationAction(ISD::FP_TO_UINT, VT.getSimpleVT(), Expand); |
| 96 | } |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 97 | setOperationAction(ISD::BUILD_VECTOR, VT.getSimpleVT(), Custom); |
| 98 | setOperationAction(ISD::VECTOR_SHUFFLE, VT.getSimpleVT(), Custom); |
Bob Wilson | 07f6e80 | 2010-06-16 21:34:01 +0000 | [diff] [blame] | 99 | setOperationAction(ISD::CONCAT_VECTORS, VT.getSimpleVT(), Legal); |
Bob Wilson | 5e8b833 | 2011-01-07 04:59:04 +0000 | [diff] [blame] | 100 | setOperationAction(ISD::EXTRACT_SUBVECTOR, VT.getSimpleVT(), Legal); |
Bob Wilson | d0910c4 | 2010-04-06 22:02:24 +0000 | [diff] [blame] | 101 | setOperationAction(ISD::SELECT, VT.getSimpleVT(), Expand); |
| 102 | setOperationAction(ISD::SELECT_CC, VT.getSimpleVT(), Expand); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 103 | if (VT.isInteger()) { |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 104 | setOperationAction(ISD::SHL, VT.getSimpleVT(), Custom); |
| 105 | setOperationAction(ISD::SRA, VT.getSimpleVT(), Custom); |
| 106 | setOperationAction(ISD::SRL, VT.getSimpleVT(), Custom); |
Bob Wilson | b31a11b | 2010-08-20 04:54:02 +0000 | [diff] [blame] | 107 | setLoadExtAction(ISD::SEXTLOAD, VT.getSimpleVT(), Expand); |
| 108 | setLoadExtAction(ISD::ZEXTLOAD, VT.getSimpleVT(), Expand); |
Bob Wilson | 24645a1 | 2010-11-01 18:31:39 +0000 | [diff] [blame] | 109 | for (unsigned InnerVT = (unsigned)MVT::FIRST_VECTOR_VALUETYPE; |
| 110 | InnerVT <= (unsigned)MVT::LAST_VECTOR_VALUETYPE; ++InnerVT) |
| 111 | setTruncStoreAction(VT.getSimpleVT(), |
| 112 | (MVT::SimpleValueType)InnerVT, Expand); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 113 | } |
Bob Wilson | b31a11b | 2010-08-20 04:54:02 +0000 | [diff] [blame] | 114 | setLoadExtAction(ISD::EXTLOAD, VT.getSimpleVT(), Expand); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 115 | |
| 116 | // Promote all bit-wise operations. |
| 117 | if (VT.isInteger() && VT != PromotedBitwiseVT) { |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 118 | setOperationAction(ISD::AND, VT.getSimpleVT(), Promote); |
Owen Anderson | d6662ad | 2009-08-10 20:46:15 +0000 | [diff] [blame] | 119 | AddPromotedToType (ISD::AND, VT.getSimpleVT(), |
| 120 | PromotedBitwiseVT.getSimpleVT()); |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 121 | setOperationAction(ISD::OR, VT.getSimpleVT(), Promote); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 122 | AddPromotedToType (ISD::OR, VT.getSimpleVT(), |
Owen Anderson | d6662ad | 2009-08-10 20:46:15 +0000 | [diff] [blame] | 123 | PromotedBitwiseVT.getSimpleVT()); |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 124 | setOperationAction(ISD::XOR, VT.getSimpleVT(), Promote); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 125 | AddPromotedToType (ISD::XOR, VT.getSimpleVT(), |
Owen Anderson | d6662ad | 2009-08-10 20:46:15 +0000 | [diff] [blame] | 126 | PromotedBitwiseVT.getSimpleVT()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 127 | } |
Bob Wilson | 1633076 | 2009-09-16 00:17:28 +0000 | [diff] [blame] | 128 | |
| 129 | // Neon does not support vector divide/remainder operations. |
| 130 | setOperationAction(ISD::SDIV, VT.getSimpleVT(), Expand); |
| 131 | setOperationAction(ISD::UDIV, VT.getSimpleVT(), Expand); |
| 132 | setOperationAction(ISD::FDIV, VT.getSimpleVT(), Expand); |
| 133 | setOperationAction(ISD::SREM, VT.getSimpleVT(), Expand); |
| 134 | setOperationAction(ISD::UREM, VT.getSimpleVT(), Expand); |
| 135 | setOperationAction(ISD::FREM, VT.getSimpleVT(), Expand); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 136 | } |
| 137 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 138 | void ARMTargetLowering::addDRTypeForNEON(EVT VT) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 139 | addRegisterClass(VT, ARM::DPRRegisterClass); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 140 | addTypeForNEON(VT, MVT::f64, MVT::v2i32); |
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::addQRTypeForNEON(EVT VT) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 144 | addRegisterClass(VT, ARM::QPRRegisterClass); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 145 | addTypeForNEON(VT, MVT::v2f64, MVT::v4i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 146 | } |
| 147 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 148 | static TargetLoweringObjectFile *createTLOF(TargetMachine &TM) { |
| 149 | if (TM.getSubtarget<ARMSubtarget>().isTargetDarwin()) |
Bill Wendling | 505ad8b | 2010-03-15 21:09:38 +0000 | [diff] [blame] | 150 | return new TargetLoweringObjectFileMachO(); |
Bill Wendling | 94a1c63 | 2010-03-09 02:46:12 +0000 | [diff] [blame] | 151 | |
Chris Lattner | 80ec279 | 2009-08-02 00:34:36 +0000 | [diff] [blame] | 152 | return new ARMElfTargetObjectFile(); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 153 | } |
| 154 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 155 | ARMTargetLowering::ARMTargetLowering(TargetMachine &TM) |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 156 | : TargetLowering(TM, createTLOF(TM)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 157 | Subtarget = &TM.getSubtarget<ARMSubtarget>(); |
Evan Cheng | 3144687 | 2010-07-23 22:39:59 +0000 | [diff] [blame] | 158 | RegInfo = TM.getRegisterInfo(); |
Evan Cheng | 3ef1c87 | 2010-09-10 01:29:16 +0000 | [diff] [blame] | 159 | Itins = TM.getInstrItineraryData(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 160 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 161 | if (Subtarget->isTargetDarwin()) { |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 162 | // Uses VFP for Thumb libfuncs if available. |
| 163 | if (Subtarget->isThumb() && Subtarget->hasVFP2()) { |
| 164 | // Single-precision floating-point arithmetic. |
| 165 | setLibcallName(RTLIB::ADD_F32, "__addsf3vfp"); |
| 166 | setLibcallName(RTLIB::SUB_F32, "__subsf3vfp"); |
| 167 | setLibcallName(RTLIB::MUL_F32, "__mulsf3vfp"); |
| 168 | setLibcallName(RTLIB::DIV_F32, "__divsf3vfp"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 169 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 170 | // Double-precision floating-point arithmetic. |
| 171 | setLibcallName(RTLIB::ADD_F64, "__adddf3vfp"); |
| 172 | setLibcallName(RTLIB::SUB_F64, "__subdf3vfp"); |
| 173 | setLibcallName(RTLIB::MUL_F64, "__muldf3vfp"); |
| 174 | setLibcallName(RTLIB::DIV_F64, "__divdf3vfp"); |
Evan Cheng | 193f850 | 2007-01-31 09:30:58 +0000 | [diff] [blame] | 175 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 176 | // Single-precision comparisons. |
| 177 | setLibcallName(RTLIB::OEQ_F32, "__eqsf2vfp"); |
| 178 | setLibcallName(RTLIB::UNE_F32, "__nesf2vfp"); |
| 179 | setLibcallName(RTLIB::OLT_F32, "__ltsf2vfp"); |
| 180 | setLibcallName(RTLIB::OLE_F32, "__lesf2vfp"); |
| 181 | setLibcallName(RTLIB::OGE_F32, "__gesf2vfp"); |
| 182 | setLibcallName(RTLIB::OGT_F32, "__gtsf2vfp"); |
| 183 | setLibcallName(RTLIB::UO_F32, "__unordsf2vfp"); |
| 184 | setLibcallName(RTLIB::O_F32, "__unordsf2vfp"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 185 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 186 | setCmpLibcallCC(RTLIB::OEQ_F32, ISD::SETNE); |
| 187 | setCmpLibcallCC(RTLIB::UNE_F32, ISD::SETNE); |
| 188 | setCmpLibcallCC(RTLIB::OLT_F32, ISD::SETNE); |
| 189 | setCmpLibcallCC(RTLIB::OLE_F32, ISD::SETNE); |
| 190 | setCmpLibcallCC(RTLIB::OGE_F32, ISD::SETNE); |
| 191 | setCmpLibcallCC(RTLIB::OGT_F32, ISD::SETNE); |
| 192 | setCmpLibcallCC(RTLIB::UO_F32, ISD::SETNE); |
| 193 | setCmpLibcallCC(RTLIB::O_F32, ISD::SETEQ); |
Evan Cheng | 193f850 | 2007-01-31 09:30:58 +0000 | [diff] [blame] | 194 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 195 | // Double-precision comparisons. |
| 196 | setLibcallName(RTLIB::OEQ_F64, "__eqdf2vfp"); |
| 197 | setLibcallName(RTLIB::UNE_F64, "__nedf2vfp"); |
| 198 | setLibcallName(RTLIB::OLT_F64, "__ltdf2vfp"); |
| 199 | setLibcallName(RTLIB::OLE_F64, "__ledf2vfp"); |
| 200 | setLibcallName(RTLIB::OGE_F64, "__gedf2vfp"); |
| 201 | setLibcallName(RTLIB::OGT_F64, "__gtdf2vfp"); |
| 202 | setLibcallName(RTLIB::UO_F64, "__unorddf2vfp"); |
| 203 | setLibcallName(RTLIB::O_F64, "__unorddf2vfp"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 204 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 205 | setCmpLibcallCC(RTLIB::OEQ_F64, ISD::SETNE); |
| 206 | setCmpLibcallCC(RTLIB::UNE_F64, ISD::SETNE); |
| 207 | setCmpLibcallCC(RTLIB::OLT_F64, ISD::SETNE); |
| 208 | setCmpLibcallCC(RTLIB::OLE_F64, ISD::SETNE); |
| 209 | setCmpLibcallCC(RTLIB::OGE_F64, ISD::SETNE); |
| 210 | setCmpLibcallCC(RTLIB::OGT_F64, ISD::SETNE); |
| 211 | setCmpLibcallCC(RTLIB::UO_F64, ISD::SETNE); |
| 212 | setCmpLibcallCC(RTLIB::O_F64, ISD::SETEQ); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 213 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 214 | // Floating-point to integer conversions. |
| 215 | // i64 conversions are done via library routines even when generating VFP |
| 216 | // instructions, so use the same ones. |
| 217 | setLibcallName(RTLIB::FPTOSINT_F64_I32, "__fixdfsivfp"); |
| 218 | setLibcallName(RTLIB::FPTOUINT_F64_I32, "__fixunsdfsivfp"); |
| 219 | setLibcallName(RTLIB::FPTOSINT_F32_I32, "__fixsfsivfp"); |
| 220 | setLibcallName(RTLIB::FPTOUINT_F32_I32, "__fixunssfsivfp"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 221 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 222 | // Conversions between floating types. |
| 223 | setLibcallName(RTLIB::FPROUND_F64_F32, "__truncdfsf2vfp"); |
| 224 | setLibcallName(RTLIB::FPEXT_F32_F64, "__extendsfdf2vfp"); |
| 225 | |
| 226 | // Integer to floating-point conversions. |
| 227 | // i64 conversions are done via library routines even when generating VFP |
| 228 | // instructions, so use the same ones. |
Bob Wilson | 2a14c52 | 2009-03-20 23:16:43 +0000 | [diff] [blame] | 229 | // FIXME: There appears to be some naming inconsistency in ARM libgcc: |
| 230 | // e.g., __floatunsidf vs. __floatunssidfvfp. |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 231 | setLibcallName(RTLIB::SINTTOFP_I32_F64, "__floatsidfvfp"); |
| 232 | setLibcallName(RTLIB::UINTTOFP_I32_F64, "__floatunssidfvfp"); |
| 233 | setLibcallName(RTLIB::SINTTOFP_I32_F32, "__floatsisfvfp"); |
| 234 | setLibcallName(RTLIB::UINTTOFP_I32_F32, "__floatunssisfvfp"); |
| 235 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 236 | } |
| 237 | |
Bob Wilson | 2f95461 | 2009-05-22 17:38:41 +0000 | [diff] [blame] | 238 | // These libcalls are not available in 32-bit. |
| 239 | setLibcallName(RTLIB::SHL_I128, 0); |
| 240 | setLibcallName(RTLIB::SRL_I128, 0); |
| 241 | setLibcallName(RTLIB::SRA_I128, 0); |
| 242 | |
Anton Korobeynikov | 72977a4 | 2009-08-14 20:10:52 +0000 | [diff] [blame] | 243 | if (Subtarget->isAAPCS_ABI()) { |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 244 | // Double-precision floating-point arithmetic helper functions |
Anton Korobeynikov | 4f922f2 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 245 | // RTABI chapter 4.1.2, Table 2 |
| 246 | setLibcallName(RTLIB::ADD_F64, "__aeabi_dadd"); |
| 247 | setLibcallName(RTLIB::DIV_F64, "__aeabi_ddiv"); |
| 248 | setLibcallName(RTLIB::MUL_F64, "__aeabi_dmul"); |
| 249 | setLibcallName(RTLIB::SUB_F64, "__aeabi_dsub"); |
| 250 | setLibcallCallingConv(RTLIB::ADD_F64, CallingConv::ARM_AAPCS); |
| 251 | setLibcallCallingConv(RTLIB::DIV_F64, CallingConv::ARM_AAPCS); |
| 252 | setLibcallCallingConv(RTLIB::MUL_F64, CallingConv::ARM_AAPCS); |
| 253 | setLibcallCallingConv(RTLIB::SUB_F64, CallingConv::ARM_AAPCS); |
| 254 | |
| 255 | // Double-precision floating-point comparison helper functions |
| 256 | // RTABI chapter 4.1.2, Table 3 |
| 257 | setLibcallName(RTLIB::OEQ_F64, "__aeabi_dcmpeq"); |
| 258 | setCmpLibcallCC(RTLIB::OEQ_F64, ISD::SETNE); |
| 259 | setLibcallName(RTLIB::UNE_F64, "__aeabi_dcmpeq"); |
| 260 | setCmpLibcallCC(RTLIB::UNE_F64, ISD::SETEQ); |
| 261 | setLibcallName(RTLIB::OLT_F64, "__aeabi_dcmplt"); |
| 262 | setCmpLibcallCC(RTLIB::OLT_F64, ISD::SETNE); |
| 263 | setLibcallName(RTLIB::OLE_F64, "__aeabi_dcmple"); |
| 264 | setCmpLibcallCC(RTLIB::OLE_F64, ISD::SETNE); |
| 265 | setLibcallName(RTLIB::OGE_F64, "__aeabi_dcmpge"); |
| 266 | setCmpLibcallCC(RTLIB::OGE_F64, ISD::SETNE); |
| 267 | setLibcallName(RTLIB::OGT_F64, "__aeabi_dcmpgt"); |
| 268 | setCmpLibcallCC(RTLIB::OGT_F64, ISD::SETNE); |
| 269 | setLibcallName(RTLIB::UO_F64, "__aeabi_dcmpun"); |
| 270 | setCmpLibcallCC(RTLIB::UO_F64, ISD::SETNE); |
| 271 | setLibcallName(RTLIB::O_F64, "__aeabi_dcmpun"); |
| 272 | setCmpLibcallCC(RTLIB::O_F64, ISD::SETEQ); |
| 273 | setLibcallCallingConv(RTLIB::OEQ_F64, CallingConv::ARM_AAPCS); |
| 274 | setLibcallCallingConv(RTLIB::UNE_F64, CallingConv::ARM_AAPCS); |
| 275 | setLibcallCallingConv(RTLIB::OLT_F64, CallingConv::ARM_AAPCS); |
| 276 | setLibcallCallingConv(RTLIB::OLE_F64, CallingConv::ARM_AAPCS); |
| 277 | setLibcallCallingConv(RTLIB::OGE_F64, CallingConv::ARM_AAPCS); |
| 278 | setLibcallCallingConv(RTLIB::OGT_F64, CallingConv::ARM_AAPCS); |
| 279 | setLibcallCallingConv(RTLIB::UO_F64, CallingConv::ARM_AAPCS); |
| 280 | setLibcallCallingConv(RTLIB::O_F64, CallingConv::ARM_AAPCS); |
| 281 | |
| 282 | // Single-precision floating-point arithmetic helper functions |
| 283 | // RTABI chapter 4.1.2, Table 4 |
| 284 | setLibcallName(RTLIB::ADD_F32, "__aeabi_fadd"); |
| 285 | setLibcallName(RTLIB::DIV_F32, "__aeabi_fdiv"); |
| 286 | setLibcallName(RTLIB::MUL_F32, "__aeabi_fmul"); |
| 287 | setLibcallName(RTLIB::SUB_F32, "__aeabi_fsub"); |
| 288 | setLibcallCallingConv(RTLIB::ADD_F32, CallingConv::ARM_AAPCS); |
| 289 | setLibcallCallingConv(RTLIB::DIV_F32, CallingConv::ARM_AAPCS); |
| 290 | setLibcallCallingConv(RTLIB::MUL_F32, CallingConv::ARM_AAPCS); |
| 291 | setLibcallCallingConv(RTLIB::SUB_F32, CallingConv::ARM_AAPCS); |
| 292 | |
| 293 | // Single-precision floating-point comparison helper functions |
| 294 | // RTABI chapter 4.1.2, Table 5 |
| 295 | setLibcallName(RTLIB::OEQ_F32, "__aeabi_fcmpeq"); |
| 296 | setCmpLibcallCC(RTLIB::OEQ_F32, ISD::SETNE); |
| 297 | setLibcallName(RTLIB::UNE_F32, "__aeabi_fcmpeq"); |
| 298 | setCmpLibcallCC(RTLIB::UNE_F32, ISD::SETEQ); |
| 299 | setLibcallName(RTLIB::OLT_F32, "__aeabi_fcmplt"); |
| 300 | setCmpLibcallCC(RTLIB::OLT_F32, ISD::SETNE); |
| 301 | setLibcallName(RTLIB::OLE_F32, "__aeabi_fcmple"); |
| 302 | setCmpLibcallCC(RTLIB::OLE_F32, ISD::SETNE); |
| 303 | setLibcallName(RTLIB::OGE_F32, "__aeabi_fcmpge"); |
| 304 | setCmpLibcallCC(RTLIB::OGE_F32, ISD::SETNE); |
| 305 | setLibcallName(RTLIB::OGT_F32, "__aeabi_fcmpgt"); |
| 306 | setCmpLibcallCC(RTLIB::OGT_F32, ISD::SETNE); |
| 307 | setLibcallName(RTLIB::UO_F32, "__aeabi_fcmpun"); |
| 308 | setCmpLibcallCC(RTLIB::UO_F32, ISD::SETNE); |
| 309 | setLibcallName(RTLIB::O_F32, "__aeabi_fcmpun"); |
| 310 | setCmpLibcallCC(RTLIB::O_F32, ISD::SETEQ); |
| 311 | setLibcallCallingConv(RTLIB::OEQ_F32, CallingConv::ARM_AAPCS); |
| 312 | setLibcallCallingConv(RTLIB::UNE_F32, CallingConv::ARM_AAPCS); |
| 313 | setLibcallCallingConv(RTLIB::OLT_F32, CallingConv::ARM_AAPCS); |
| 314 | setLibcallCallingConv(RTLIB::OLE_F32, CallingConv::ARM_AAPCS); |
| 315 | setLibcallCallingConv(RTLIB::OGE_F32, CallingConv::ARM_AAPCS); |
| 316 | setLibcallCallingConv(RTLIB::OGT_F32, CallingConv::ARM_AAPCS); |
| 317 | setLibcallCallingConv(RTLIB::UO_F32, CallingConv::ARM_AAPCS); |
| 318 | setLibcallCallingConv(RTLIB::O_F32, CallingConv::ARM_AAPCS); |
| 319 | |
| 320 | // Floating-point to integer conversions. |
| 321 | // RTABI chapter 4.1.2, Table 6 |
| 322 | setLibcallName(RTLIB::FPTOSINT_F64_I32, "__aeabi_d2iz"); |
| 323 | setLibcallName(RTLIB::FPTOUINT_F64_I32, "__aeabi_d2uiz"); |
| 324 | setLibcallName(RTLIB::FPTOSINT_F64_I64, "__aeabi_d2lz"); |
| 325 | setLibcallName(RTLIB::FPTOUINT_F64_I64, "__aeabi_d2ulz"); |
| 326 | setLibcallName(RTLIB::FPTOSINT_F32_I32, "__aeabi_f2iz"); |
| 327 | setLibcallName(RTLIB::FPTOUINT_F32_I32, "__aeabi_f2uiz"); |
| 328 | setLibcallName(RTLIB::FPTOSINT_F32_I64, "__aeabi_f2lz"); |
| 329 | setLibcallName(RTLIB::FPTOUINT_F32_I64, "__aeabi_f2ulz"); |
| 330 | setLibcallCallingConv(RTLIB::FPTOSINT_F64_I32, CallingConv::ARM_AAPCS); |
| 331 | setLibcallCallingConv(RTLIB::FPTOUINT_F64_I32, CallingConv::ARM_AAPCS); |
| 332 | setLibcallCallingConv(RTLIB::FPTOSINT_F64_I64, CallingConv::ARM_AAPCS); |
| 333 | setLibcallCallingConv(RTLIB::FPTOUINT_F64_I64, CallingConv::ARM_AAPCS); |
| 334 | setLibcallCallingConv(RTLIB::FPTOSINT_F32_I32, CallingConv::ARM_AAPCS); |
| 335 | setLibcallCallingConv(RTLIB::FPTOUINT_F32_I32, CallingConv::ARM_AAPCS); |
| 336 | setLibcallCallingConv(RTLIB::FPTOSINT_F32_I64, CallingConv::ARM_AAPCS); |
| 337 | setLibcallCallingConv(RTLIB::FPTOUINT_F32_I64, CallingConv::ARM_AAPCS); |
| 338 | |
| 339 | // Conversions between floating types. |
| 340 | // RTABI chapter 4.1.2, Table 7 |
| 341 | setLibcallName(RTLIB::FPROUND_F64_F32, "__aeabi_d2f"); |
| 342 | setLibcallName(RTLIB::FPEXT_F32_F64, "__aeabi_f2d"); |
| 343 | setLibcallCallingConv(RTLIB::FPROUND_F64_F32, CallingConv::ARM_AAPCS); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 344 | setLibcallCallingConv(RTLIB::FPEXT_F32_F64, CallingConv::ARM_AAPCS); |
Anton Korobeynikov | 4f922f2 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 345 | |
| 346 | // Integer to floating-point conversions. |
| 347 | // RTABI chapter 4.1.2, Table 8 |
| 348 | setLibcallName(RTLIB::SINTTOFP_I32_F64, "__aeabi_i2d"); |
| 349 | setLibcallName(RTLIB::UINTTOFP_I32_F64, "__aeabi_ui2d"); |
| 350 | setLibcallName(RTLIB::SINTTOFP_I64_F64, "__aeabi_l2d"); |
| 351 | setLibcallName(RTLIB::UINTTOFP_I64_F64, "__aeabi_ul2d"); |
| 352 | setLibcallName(RTLIB::SINTTOFP_I32_F32, "__aeabi_i2f"); |
| 353 | setLibcallName(RTLIB::UINTTOFP_I32_F32, "__aeabi_ui2f"); |
| 354 | setLibcallName(RTLIB::SINTTOFP_I64_F32, "__aeabi_l2f"); |
| 355 | setLibcallName(RTLIB::UINTTOFP_I64_F32, "__aeabi_ul2f"); |
| 356 | setLibcallCallingConv(RTLIB::SINTTOFP_I32_F64, CallingConv::ARM_AAPCS); |
| 357 | setLibcallCallingConv(RTLIB::UINTTOFP_I32_F64, CallingConv::ARM_AAPCS); |
| 358 | setLibcallCallingConv(RTLIB::SINTTOFP_I64_F64, CallingConv::ARM_AAPCS); |
| 359 | setLibcallCallingConv(RTLIB::UINTTOFP_I64_F64, CallingConv::ARM_AAPCS); |
| 360 | setLibcallCallingConv(RTLIB::SINTTOFP_I32_F32, CallingConv::ARM_AAPCS); |
| 361 | setLibcallCallingConv(RTLIB::UINTTOFP_I32_F32, CallingConv::ARM_AAPCS); |
| 362 | setLibcallCallingConv(RTLIB::SINTTOFP_I64_F32, CallingConv::ARM_AAPCS); |
| 363 | setLibcallCallingConv(RTLIB::UINTTOFP_I64_F32, CallingConv::ARM_AAPCS); |
| 364 | |
| 365 | // Long long helper functions |
| 366 | // RTABI chapter 4.2, Table 9 |
| 367 | setLibcallName(RTLIB::MUL_I64, "__aeabi_lmul"); |
| 368 | setLibcallName(RTLIB::SDIV_I64, "__aeabi_ldivmod"); |
| 369 | setLibcallName(RTLIB::UDIV_I64, "__aeabi_uldivmod"); |
| 370 | setLibcallName(RTLIB::SHL_I64, "__aeabi_llsl"); |
| 371 | setLibcallName(RTLIB::SRL_I64, "__aeabi_llsr"); |
| 372 | setLibcallName(RTLIB::SRA_I64, "__aeabi_lasr"); |
| 373 | setLibcallCallingConv(RTLIB::MUL_I64, CallingConv::ARM_AAPCS); |
| 374 | setLibcallCallingConv(RTLIB::SDIV_I64, CallingConv::ARM_AAPCS); |
| 375 | setLibcallCallingConv(RTLIB::UDIV_I64, CallingConv::ARM_AAPCS); |
| 376 | setLibcallCallingConv(RTLIB::SHL_I64, CallingConv::ARM_AAPCS); |
| 377 | setLibcallCallingConv(RTLIB::SRL_I64, CallingConv::ARM_AAPCS); |
| 378 | setLibcallCallingConv(RTLIB::SRA_I64, CallingConv::ARM_AAPCS); |
| 379 | |
| 380 | // Integer division functions |
| 381 | // RTABI chapter 4.3.1 |
| 382 | setLibcallName(RTLIB::SDIV_I8, "__aeabi_idiv"); |
| 383 | setLibcallName(RTLIB::SDIV_I16, "__aeabi_idiv"); |
| 384 | setLibcallName(RTLIB::SDIV_I32, "__aeabi_idiv"); |
| 385 | setLibcallName(RTLIB::UDIV_I8, "__aeabi_uidiv"); |
| 386 | setLibcallName(RTLIB::UDIV_I16, "__aeabi_uidiv"); |
| 387 | setLibcallName(RTLIB::UDIV_I32, "__aeabi_uidiv"); |
| 388 | setLibcallCallingConv(RTLIB::SDIV_I8, CallingConv::ARM_AAPCS); |
| 389 | setLibcallCallingConv(RTLIB::SDIV_I16, CallingConv::ARM_AAPCS); |
| 390 | setLibcallCallingConv(RTLIB::SDIV_I32, CallingConv::ARM_AAPCS); |
| 391 | setLibcallCallingConv(RTLIB::UDIV_I8, CallingConv::ARM_AAPCS); |
| 392 | setLibcallCallingConv(RTLIB::UDIV_I16, CallingConv::ARM_AAPCS); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 393 | setLibcallCallingConv(RTLIB::UDIV_I32, CallingConv::ARM_AAPCS); |
Anton Korobeynikov | 72977a4 | 2009-08-14 20:10:52 +0000 | [diff] [blame] | 394 | } |
| 395 | |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 396 | if (Subtarget->isThumb1Only()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 397 | addRegisterClass(MVT::i32, ARM::tGPRRegisterClass); |
Jim Grosbach | 30eae3c | 2009-04-07 20:34:09 +0000 | [diff] [blame] | 398 | else |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 399 | addRegisterClass(MVT::i32, ARM::GPRRegisterClass); |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 400 | if (!UseSoftFloat && Subtarget->hasVFP2() && !Subtarget->isThumb1Only()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 401 | addRegisterClass(MVT::f32, ARM::SPRRegisterClass); |
Jim Grosbach | fcba5e6 | 2010-08-11 15:44:15 +0000 | [diff] [blame] | 402 | if (!Subtarget->isFPOnlySP()) |
| 403 | addRegisterClass(MVT::f64, ARM::DPRRegisterClass); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 404 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 405 | setTruncStoreAction(MVT::f64, MVT::f32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 406 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 407 | |
| 408 | if (Subtarget->hasNEON()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 409 | addDRTypeForNEON(MVT::v2f32); |
| 410 | addDRTypeForNEON(MVT::v8i8); |
| 411 | addDRTypeForNEON(MVT::v4i16); |
| 412 | addDRTypeForNEON(MVT::v2i32); |
| 413 | addDRTypeForNEON(MVT::v1i64); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 414 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 415 | addQRTypeForNEON(MVT::v4f32); |
| 416 | addQRTypeForNEON(MVT::v2f64); |
| 417 | addQRTypeForNEON(MVT::v16i8); |
| 418 | addQRTypeForNEON(MVT::v8i16); |
| 419 | addQRTypeForNEON(MVT::v4i32); |
| 420 | addQRTypeForNEON(MVT::v2i64); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 421 | |
Bob Wilson | 74dc72e | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 422 | // v2f64 is legal so that QR subregs can be extracted as f64 elements, but |
| 423 | // neither Neon nor VFP support any arithmetic operations on it. |
| 424 | setOperationAction(ISD::FADD, MVT::v2f64, Expand); |
| 425 | setOperationAction(ISD::FSUB, MVT::v2f64, Expand); |
| 426 | setOperationAction(ISD::FMUL, MVT::v2f64, Expand); |
| 427 | setOperationAction(ISD::FDIV, MVT::v2f64, Expand); |
| 428 | setOperationAction(ISD::FREM, MVT::v2f64, Expand); |
| 429 | setOperationAction(ISD::FCOPYSIGN, MVT::v2f64, Expand); |
| 430 | setOperationAction(ISD::VSETCC, MVT::v2f64, Expand); |
| 431 | setOperationAction(ISD::FNEG, MVT::v2f64, Expand); |
| 432 | setOperationAction(ISD::FABS, MVT::v2f64, Expand); |
| 433 | setOperationAction(ISD::FSQRT, MVT::v2f64, Expand); |
| 434 | setOperationAction(ISD::FSIN, MVT::v2f64, Expand); |
| 435 | setOperationAction(ISD::FCOS, MVT::v2f64, Expand); |
| 436 | setOperationAction(ISD::FPOWI, MVT::v2f64, Expand); |
| 437 | setOperationAction(ISD::FPOW, MVT::v2f64, Expand); |
| 438 | setOperationAction(ISD::FLOG, MVT::v2f64, Expand); |
| 439 | setOperationAction(ISD::FLOG2, MVT::v2f64, Expand); |
| 440 | setOperationAction(ISD::FLOG10, MVT::v2f64, Expand); |
| 441 | setOperationAction(ISD::FEXP, MVT::v2f64, Expand); |
| 442 | setOperationAction(ISD::FEXP2, MVT::v2f64, Expand); |
| 443 | setOperationAction(ISD::FCEIL, MVT::v2f64, Expand); |
| 444 | setOperationAction(ISD::FTRUNC, MVT::v2f64, Expand); |
| 445 | setOperationAction(ISD::FRINT, MVT::v2f64, Expand); |
| 446 | setOperationAction(ISD::FNEARBYINT, MVT::v2f64, Expand); |
| 447 | setOperationAction(ISD::FFLOOR, MVT::v2f64, Expand); |
| 448 | |
Bob Wilson | b31a11b | 2010-08-20 04:54:02 +0000 | [diff] [blame] | 449 | setTruncStoreAction(MVT::v2f64, MVT::v2f32, Expand); |
| 450 | |
Bob Wilson | 642b329 | 2009-09-16 00:32:15 +0000 | [diff] [blame] | 451 | // Neon does not support some operations on v1i64 and v2i64 types. |
| 452 | setOperationAction(ISD::MUL, MVT::v1i64, Expand); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 453 | // Custom handling for some quad-vector types to detect VMULL. |
| 454 | setOperationAction(ISD::MUL, MVT::v8i16, Custom); |
| 455 | setOperationAction(ISD::MUL, MVT::v4i32, Custom); |
| 456 | setOperationAction(ISD::MUL, MVT::v2i64, Custom); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 457 | // Custom handling for some vector types to avoid expensive expansions |
| 458 | setOperationAction(ISD::SDIV, MVT::v4i16, Custom); |
| 459 | setOperationAction(ISD::SDIV, MVT::v8i8, Custom); |
| 460 | setOperationAction(ISD::UDIV, MVT::v4i16, Custom); |
| 461 | setOperationAction(ISD::UDIV, MVT::v8i8, Custom); |
Bob Wilson | 642b329 | 2009-09-16 00:32:15 +0000 | [diff] [blame] | 462 | setOperationAction(ISD::VSETCC, MVT::v1i64, Expand); |
| 463 | setOperationAction(ISD::VSETCC, MVT::v2i64, Expand); |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 464 | // Neon does not have single instruction SINT_TO_FP and UINT_TO_FP with |
| 465 | // a destination type that is wider than the source. |
| 466 | setOperationAction(ISD::SINT_TO_FP, MVT::v4i16, Custom); |
| 467 | setOperationAction(ISD::UINT_TO_FP, MVT::v4i16, Custom); |
Bob Wilson | 642b329 | 2009-09-16 00:32:15 +0000 | [diff] [blame] | 468 | |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 469 | setTargetDAGCombine(ISD::INTRINSIC_VOID); |
| 470 | setTargetDAGCombine(ISD::INTRINSIC_W_CHAIN); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 471 | setTargetDAGCombine(ISD::INTRINSIC_WO_CHAIN); |
| 472 | setTargetDAGCombine(ISD::SHL); |
| 473 | setTargetDAGCombine(ISD::SRL); |
| 474 | setTargetDAGCombine(ISD::SRA); |
| 475 | setTargetDAGCombine(ISD::SIGN_EXTEND); |
| 476 | setTargetDAGCombine(ISD::ZERO_EXTEND); |
| 477 | setTargetDAGCombine(ISD::ANY_EXTEND); |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 478 | setTargetDAGCombine(ISD::SELECT_CC); |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 479 | setTargetDAGCombine(ISD::BUILD_VECTOR); |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 480 | setTargetDAGCombine(ISD::VECTOR_SHUFFLE); |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 481 | setTargetDAGCombine(ISD::INSERT_VECTOR_ELT); |
| 482 | setTargetDAGCombine(ISD::STORE); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 483 | } |
| 484 | |
Evan Cheng | 9f8cbd1 | 2007-05-18 00:19:34 +0000 | [diff] [blame] | 485 | computeRegisterProperties(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 486 | |
| 487 | // ARM does not have f32 extending load. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 488 | setLoadExtAction(ISD::EXTLOAD, MVT::f32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 489 | |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 490 | // ARM does not have i1 sign extending load. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 491 | setLoadExtAction(ISD::SEXTLOAD, MVT::i1, Promote); |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 492 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 493 | // ARM supports all 4 flavors of integer indexed load / store. |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 494 | if (!Subtarget->isThumb1Only()) { |
| 495 | for (unsigned im = (unsigned)ISD::PRE_INC; |
| 496 | im != (unsigned)ISD::LAST_INDEXED_MODE; ++im) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 497 | setIndexedLoadAction(im, MVT::i1, Legal); |
| 498 | setIndexedLoadAction(im, MVT::i8, Legal); |
| 499 | setIndexedLoadAction(im, MVT::i16, Legal); |
| 500 | setIndexedLoadAction(im, MVT::i32, Legal); |
| 501 | setIndexedStoreAction(im, MVT::i1, Legal); |
| 502 | setIndexedStoreAction(im, MVT::i8, Legal); |
| 503 | setIndexedStoreAction(im, MVT::i16, Legal); |
| 504 | setIndexedStoreAction(im, MVT::i32, Legal); |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 505 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | // i64 operation support. |
Evan Cheng | 5b9fcd1 | 2009-07-07 01:17:28 +0000 | [diff] [blame] | 509 | if (Subtarget->isThumb1Only()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 510 | setOperationAction(ISD::MUL, MVT::i64, Expand); |
| 511 | setOperationAction(ISD::MULHU, MVT::i32, Expand); |
| 512 | setOperationAction(ISD::MULHS, MVT::i32, Expand); |
| 513 | setOperationAction(ISD::UMUL_LOHI, MVT::i32, Expand); |
| 514 | setOperationAction(ISD::SMUL_LOHI, MVT::i32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 515 | } else { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 516 | setOperationAction(ISD::MUL, MVT::i64, Expand); |
| 517 | setOperationAction(ISD::MULHU, MVT::i32, Expand); |
Evan Cheng | b620724 | 2009-08-01 00:16:10 +0000 | [diff] [blame] | 518 | if (!Subtarget->hasV6Ops()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 519 | setOperationAction(ISD::MULHS, MVT::i32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 520 | } |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 521 | setOperationAction(ISD::SHL_PARTS, MVT::i32, Custom); |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 522 | setOperationAction(ISD::SRA_PARTS, MVT::i32, Custom); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 523 | setOperationAction(ISD::SRL_PARTS, MVT::i32, Custom); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 524 | setOperationAction(ISD::SRL, MVT::i64, Custom); |
| 525 | setOperationAction(ISD::SRA, MVT::i64, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 526 | |
| 527 | // ARM does not have ROTL. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 528 | setOperationAction(ISD::ROTL, MVT::i32, Expand); |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 529 | setOperationAction(ISD::CTTZ, MVT::i32, Custom); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 530 | setOperationAction(ISD::CTPOP, MVT::i32, Expand); |
David Goodwin | 24062ac | 2009-06-26 20:47:43 +0000 | [diff] [blame] | 531 | if (!Subtarget->hasV5TOps() || Subtarget->isThumb1Only()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 532 | setOperationAction(ISD::CTLZ, MVT::i32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 533 | |
Lauro Ramos Venancio | 368f20f | 2007-03-16 22:54:16 +0000 | [diff] [blame] | 534 | // Only ARMv6 has BSWAP. |
| 535 | if (!Subtarget->hasV6Ops()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 536 | setOperationAction(ISD::BSWAP, MVT::i32, Expand); |
Lauro Ramos Venancio | 368f20f | 2007-03-16 22:54:16 +0000 | [diff] [blame] | 537 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 538 | // These are expanded into libcalls. |
Evan Cheng | 1f190c8 | 2010-11-19 06:28:11 +0000 | [diff] [blame] | 539 | if (!Subtarget->hasDivide() || !Subtarget->isThumb2()) { |
Jim Grosbach | b1dc393 | 2010-05-05 20:44:35 +0000 | [diff] [blame] | 540 | // v7M has a hardware divider |
| 541 | setOperationAction(ISD::SDIV, MVT::i32, Expand); |
| 542 | setOperationAction(ISD::UDIV, MVT::i32, Expand); |
| 543 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 544 | setOperationAction(ISD::SREM, MVT::i32, Expand); |
| 545 | setOperationAction(ISD::UREM, MVT::i32, Expand); |
| 546 | setOperationAction(ISD::SDIVREM, MVT::i32, Expand); |
| 547 | setOperationAction(ISD::UDIVREM, MVT::i32, Expand); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 548 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 549 | setOperationAction(ISD::GlobalAddress, MVT::i32, Custom); |
| 550 | setOperationAction(ISD::ConstantPool, MVT::i32, Custom); |
| 551 | setOperationAction(ISD::GLOBAL_OFFSET_TABLE, MVT::i32, Custom); |
| 552 | setOperationAction(ISD::GlobalTLSAddress, MVT::i32, Custom); |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 553 | setOperationAction(ISD::BlockAddress, MVT::i32, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 554 | |
Evan Cheng | fb3611d | 2010-05-11 07:26:32 +0000 | [diff] [blame] | 555 | setOperationAction(ISD::TRAP, MVT::Other, Legal); |
| 556 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 557 | // Use the default implementation. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 558 | setOperationAction(ISD::VASTART, MVT::Other, Custom); |
| 559 | setOperationAction(ISD::VAARG, MVT::Other, Expand); |
| 560 | setOperationAction(ISD::VACOPY, MVT::Other, Expand); |
| 561 | setOperationAction(ISD::VAEND, MVT::Other, Expand); |
| 562 | setOperationAction(ISD::STACKSAVE, MVT::Other, Expand); |
| 563 | setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand); |
Jim Grosbach | bff3923 | 2009-08-12 17:38:44 +0000 | [diff] [blame] | 564 | setOperationAction(ISD::EHSELECTION, MVT::i32, Expand); |
Anton Korobeynikov | 5899a60 | 2011-01-24 22:38:45 +0000 | [diff] [blame] | 565 | setOperationAction(ISD::EXCEPTIONADDR, MVT::i32, Expand); |
| 566 | setExceptionPointerRegister(ARM::R0); |
| 567 | setExceptionSelectorRegister(ARM::R1); |
| 568 | |
Evan Cheng | 3a1588a | 2010-04-15 22:20:34 +0000 | [diff] [blame] | 569 | setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32, Expand); |
Evan Cheng | 11db068 | 2010-08-11 06:22:01 +0000 | [diff] [blame] | 570 | // ARMv6 Thumb1 (except for CPUs that support dmb / dsb) and earlier use |
| 571 | // the default expansion. |
| 572 | if (Subtarget->hasDataBarrier() || |
Bob Wilson | 54f9256 | 2010-11-09 22:50:44 +0000 | [diff] [blame] | 573 | (Subtarget->hasV6Ops() && !Subtarget->isThumb())) { |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 574 | // membarrier needs custom lowering; the rest are legal and handled |
| 575 | // normally. |
| 576 | setOperationAction(ISD::MEMBARRIER, MVT::Other, Custom); |
| 577 | } else { |
| 578 | // Set them all for expansion, which will force libcalls. |
| 579 | setOperationAction(ISD::MEMBARRIER, MVT::Other, Expand); |
| 580 | setOperationAction(ISD::ATOMIC_CMP_SWAP, MVT::i8, Expand); |
| 581 | setOperationAction(ISD::ATOMIC_CMP_SWAP, MVT::i16, Expand); |
| 582 | setOperationAction(ISD::ATOMIC_CMP_SWAP, MVT::i32, Expand); |
Jim Grosbach | ef6eb9c | 2010-06-18 23:03:10 +0000 | [diff] [blame] | 583 | setOperationAction(ISD::ATOMIC_SWAP, MVT::i8, Expand); |
| 584 | setOperationAction(ISD::ATOMIC_SWAP, MVT::i16, Expand); |
| 585 | setOperationAction(ISD::ATOMIC_SWAP, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 586 | setOperationAction(ISD::ATOMIC_LOAD_ADD, MVT::i8, Expand); |
| 587 | setOperationAction(ISD::ATOMIC_LOAD_ADD, MVT::i16, Expand); |
| 588 | setOperationAction(ISD::ATOMIC_LOAD_ADD, MVT::i32, Expand); |
| 589 | setOperationAction(ISD::ATOMIC_LOAD_SUB, MVT::i8, Expand); |
| 590 | setOperationAction(ISD::ATOMIC_LOAD_SUB, MVT::i16, Expand); |
| 591 | setOperationAction(ISD::ATOMIC_LOAD_SUB, MVT::i32, Expand); |
| 592 | setOperationAction(ISD::ATOMIC_LOAD_AND, MVT::i8, Expand); |
| 593 | setOperationAction(ISD::ATOMIC_LOAD_AND, MVT::i16, Expand); |
| 594 | setOperationAction(ISD::ATOMIC_LOAD_AND, MVT::i32, Expand); |
| 595 | setOperationAction(ISD::ATOMIC_LOAD_OR, MVT::i8, Expand); |
| 596 | setOperationAction(ISD::ATOMIC_LOAD_OR, MVT::i16, Expand); |
| 597 | setOperationAction(ISD::ATOMIC_LOAD_OR, MVT::i32, Expand); |
| 598 | setOperationAction(ISD::ATOMIC_LOAD_XOR, MVT::i8, Expand); |
| 599 | setOperationAction(ISD::ATOMIC_LOAD_XOR, MVT::i16, Expand); |
| 600 | setOperationAction(ISD::ATOMIC_LOAD_XOR, MVT::i32, Expand); |
| 601 | setOperationAction(ISD::ATOMIC_LOAD_NAND, MVT::i8, Expand); |
| 602 | setOperationAction(ISD::ATOMIC_LOAD_NAND, MVT::i16, Expand); |
| 603 | setOperationAction(ISD::ATOMIC_LOAD_NAND, MVT::i32, Expand); |
Jim Grosbach | 5def57a | 2010-06-23 16:08:49 +0000 | [diff] [blame] | 604 | // Since the libcalls include locking, fold in the fences |
| 605 | setShouldFoldAtomicFences(true); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 606 | } |
| 607 | // 64-bit versions are always libcalls (for now) |
| 608 | setOperationAction(ISD::ATOMIC_CMP_SWAP, MVT::i64, Expand); |
Jim Grosbach | ef6eb9c | 2010-06-18 23:03:10 +0000 | [diff] [blame] | 609 | setOperationAction(ISD::ATOMIC_SWAP, MVT::i64, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 610 | setOperationAction(ISD::ATOMIC_LOAD_ADD, MVT::i64, Expand); |
| 611 | setOperationAction(ISD::ATOMIC_LOAD_SUB, MVT::i64, Expand); |
| 612 | setOperationAction(ISD::ATOMIC_LOAD_AND, MVT::i64, Expand); |
| 613 | setOperationAction(ISD::ATOMIC_LOAD_OR, MVT::i64, Expand); |
| 614 | setOperationAction(ISD::ATOMIC_LOAD_XOR, MVT::i64, Expand); |
| 615 | setOperationAction(ISD::ATOMIC_LOAD_NAND, MVT::i64, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 616 | |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 617 | setOperationAction(ISD::PREFETCH, MVT::Other, Custom); |
Evan Cheng | bc7deb0 | 2010-11-03 05:14:24 +0000 | [diff] [blame] | 618 | |
Eli Friedman | a2c6f45 | 2010-06-26 04:36:50 +0000 | [diff] [blame] | 619 | // Requires SXTB/SXTH, available on v6 and up in both ARM and Thumb modes. |
| 620 | if (!Subtarget->hasV6Ops()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 621 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i16, Expand); |
| 622 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i8, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 623 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 624 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 625 | |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 626 | if (!UseSoftFloat && Subtarget->hasVFP2() && !Subtarget->isThumb1Only()) { |
Bob Wilson | cb9a6aa | 2010-01-19 22:56:26 +0000 | [diff] [blame] | 627 | // Turn f64->i64 into VMOVRRD, i64 -> f64 to VMOVDRR |
| 628 | // iff target supports vfp2. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 629 | setOperationAction(ISD::BITCAST, MVT::i64, Custom); |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 630 | setOperationAction(ISD::FLT_ROUNDS_, MVT::i32, Custom); |
| 631 | } |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 632 | |
| 633 | // We want to custom lower some of our intrinsics. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 634 | setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom); |
Jim Grosbach | e97f968 | 2010-07-07 00:07:57 +0000 | [diff] [blame] | 635 | if (Subtarget->isTargetDarwin()) { |
| 636 | setOperationAction(ISD::EH_SJLJ_SETJMP, MVT::i32, Custom); |
| 637 | setOperationAction(ISD::EH_SJLJ_LONGJMP, MVT::Other, Custom); |
Jim Grosbach | e4ad387 | 2010-10-19 23:27:08 +0000 | [diff] [blame] | 638 | setOperationAction(ISD::EH_SJLJ_DISPATCHSETUP, MVT::Other, Custom); |
Jim Grosbach | e97f968 | 2010-07-07 00:07:57 +0000 | [diff] [blame] | 639 | } |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 640 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 641 | setOperationAction(ISD::SETCC, MVT::i32, Expand); |
| 642 | setOperationAction(ISD::SETCC, MVT::f32, Expand); |
| 643 | setOperationAction(ISD::SETCC, MVT::f64, Expand); |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 644 | setOperationAction(ISD::SELECT, MVT::i32, Custom); |
| 645 | setOperationAction(ISD::SELECT, MVT::f32, Custom); |
| 646 | setOperationAction(ISD::SELECT, MVT::f64, Custom); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 647 | setOperationAction(ISD::SELECT_CC, MVT::i32, Custom); |
| 648 | setOperationAction(ISD::SELECT_CC, MVT::f32, Custom); |
| 649 | setOperationAction(ISD::SELECT_CC, MVT::f64, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 650 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 651 | setOperationAction(ISD::BRCOND, MVT::Other, Expand); |
| 652 | setOperationAction(ISD::BR_CC, MVT::i32, Custom); |
| 653 | setOperationAction(ISD::BR_CC, MVT::f32, Custom); |
| 654 | setOperationAction(ISD::BR_CC, MVT::f64, Custom); |
| 655 | setOperationAction(ISD::BR_JT, MVT::Other, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 656 | |
Dan Gohman | f96e4de | 2007-10-11 23:21:31 +0000 | [diff] [blame] | 657 | // We don't support sin/cos/fmod/copysign/pow |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 658 | setOperationAction(ISD::FSIN, MVT::f64, Expand); |
| 659 | setOperationAction(ISD::FSIN, MVT::f32, Expand); |
| 660 | setOperationAction(ISD::FCOS, MVT::f32, Expand); |
| 661 | setOperationAction(ISD::FCOS, MVT::f64, Expand); |
| 662 | setOperationAction(ISD::FREM, MVT::f64, Expand); |
| 663 | setOperationAction(ISD::FREM, MVT::f32, Expand); |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 664 | if (!UseSoftFloat && Subtarget->hasVFP2() && !Subtarget->isThumb1Only()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 665 | setOperationAction(ISD::FCOPYSIGN, MVT::f64, Custom); |
| 666 | setOperationAction(ISD::FCOPYSIGN, MVT::f32, Custom); |
Evan Cheng | 110cf48 | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 667 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 668 | setOperationAction(ISD::FPOW, MVT::f64, Expand); |
| 669 | setOperationAction(ISD::FPOW, MVT::f32, Expand); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 670 | |
Anton Korobeynikov | bec3dd2 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 671 | // Various VFP goodness |
| 672 | if (!UseSoftFloat && !Subtarget->isThumb1Only()) { |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 673 | // int <-> fp are custom expanded into bit_convert + ARMISD ops. |
| 674 | if (Subtarget->hasVFP2()) { |
| 675 | setOperationAction(ISD::SINT_TO_FP, MVT::i32, Custom); |
| 676 | setOperationAction(ISD::UINT_TO_FP, MVT::i32, Custom); |
| 677 | setOperationAction(ISD::FP_TO_UINT, MVT::i32, Custom); |
| 678 | setOperationAction(ISD::FP_TO_SINT, MVT::i32, Custom); |
| 679 | } |
Anton Korobeynikov | bec3dd2 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 680 | // Special handling for half-precision FP. |
Anton Korobeynikov | f0d5007 | 2010-03-18 22:35:37 +0000 | [diff] [blame] | 681 | if (!Subtarget->hasFP16()) { |
| 682 | setOperationAction(ISD::FP16_TO_FP32, MVT::f32, Expand); |
| 683 | setOperationAction(ISD::FP32_TO_FP16, MVT::i32, Expand); |
Anton Korobeynikov | bec3dd2 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 684 | } |
Evan Cheng | 110cf48 | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 685 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 686 | |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 687 | // We have target-specific dag combine patterns for the following nodes: |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 688 | // ARMISD::VMOVRRD - No need to call setTargetDAGCombine |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 689 | setTargetDAGCombine(ISD::ADD); |
| 690 | setTargetDAGCombine(ISD::SUB); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 691 | setTargetDAGCombine(ISD::MUL); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 692 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 693 | if (Subtarget->hasV6T2Ops() || Subtarget->hasNEON()) |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 694 | setTargetDAGCombine(ISD::OR); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 695 | if (Subtarget->hasNEON()) |
| 696 | setTargetDAGCombine(ISD::AND); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 697 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 698 | setStackPointerRegisterToSaveRestore(ARM::SP); |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 699 | |
Evan Cheng | f7d87ee | 2010-05-21 00:43:17 +0000 | [diff] [blame] | 700 | if (UseSoftFloat || Subtarget->isThumb1Only() || !Subtarget->hasVFP2()) |
| 701 | setSchedulingPreference(Sched::RegPressure); |
| 702 | else |
| 703 | setSchedulingPreference(Sched::Hybrid); |
Dale Johannesen | 8dd86c1 | 2007-05-17 21:31:21 +0000 | [diff] [blame] | 704 | |
Evan Cheng | 0521928 | 2011-01-06 06:52:41 +0000 | [diff] [blame] | 705 | //// temporary - rewrite interface to use type |
| 706 | maxStoresPerMemcpy = maxStoresPerMemcpyOptSize = 1; |
Evan Cheng | f679939 | 2010-06-26 01:52:05 +0000 | [diff] [blame] | 707 | |
Rafael Espindola | cbeeae2 | 2010-07-11 04:01:49 +0000 | [diff] [blame] | 708 | // On ARM arguments smaller than 4 bytes are extended, so all arguments |
| 709 | // are at least 4 bytes aligned. |
| 710 | setMinStackArgumentAlignment(4); |
| 711 | |
Evan Cheng | fff606d | 2010-09-24 19:07:23 +0000 | [diff] [blame] | 712 | benefitFromCodePlacementOpt = true; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 713 | } |
| 714 | |
Andrew Trick | 32cec0a | 2011-01-19 02:35:27 +0000 | [diff] [blame] | 715 | // FIXME: It might make sense to define the representative register class as the |
| 716 | // nearest super-register that has a non-null superset. For example, DPR_VFP2 is |
| 717 | // a super-register of SPR, and DPR is a superset if DPR_VFP2. Consequently, |
| 718 | // SPR's representative would be DPR_VFP2. This should work well if register |
| 719 | // pressure tracking were modified such that a register use would increment the |
| 720 | // pressure of the register class's representative and all of it's super |
| 721 | // classes' representatives transitively. We have not implemented this because |
| 722 | // of the difficulty prior to coalescing of modeling operand register classes |
| 723 | // due to the common occurence of cross class copies and subregister insertions |
| 724 | // and extractions. |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 725 | std::pair<const TargetRegisterClass*, uint8_t> |
| 726 | ARMTargetLowering::findRepresentativeClass(EVT VT) const{ |
| 727 | const TargetRegisterClass *RRC = 0; |
| 728 | uint8_t Cost = 1; |
| 729 | switch (VT.getSimpleVT().SimpleTy) { |
Evan Cheng | d70f57b | 2010-07-19 22:15:08 +0000 | [diff] [blame] | 730 | default: |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 731 | return TargetLowering::findRepresentativeClass(VT); |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 732 | // Use DPR as representative register class for all floating point |
| 733 | // and vector types. Since there are 32 SPR registers and 32 DPR registers so |
| 734 | // the cost is 1 for both f32 and f64. |
| 735 | case MVT::f32: case MVT::f64: case MVT::v8i8: case MVT::v4i16: |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 736 | case MVT::v2i32: case MVT::v1i64: case MVT::v2f32: |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 737 | RRC = ARM::DPRRegisterClass; |
Andrew Trick | 32cec0a | 2011-01-19 02:35:27 +0000 | [diff] [blame] | 738 | // When NEON is used for SP, only half of the register file is available |
| 739 | // because operations that define both SP and DP results will be constrained |
| 740 | // to the VFP2 class (D0-D15). We currently model this constraint prior to |
| 741 | // coalescing by double-counting the SP regs. See the FIXME above. |
| 742 | if (Subtarget->useNEONForSinglePrecisionFP()) |
| 743 | Cost = 2; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 744 | break; |
| 745 | case MVT::v16i8: case MVT::v8i16: case MVT::v4i32: case MVT::v2i64: |
| 746 | case MVT::v4f32: case MVT::v2f64: |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 747 | RRC = ARM::DPRRegisterClass; |
| 748 | Cost = 2; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 749 | break; |
| 750 | case MVT::v4i64: |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 751 | RRC = ARM::DPRRegisterClass; |
| 752 | Cost = 4; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 753 | break; |
| 754 | case MVT::v8i64: |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 755 | RRC = ARM::DPRRegisterClass; |
| 756 | Cost = 8; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 757 | break; |
Evan Cheng | d70f57b | 2010-07-19 22:15:08 +0000 | [diff] [blame] | 758 | } |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 759 | return std::make_pair(RRC, Cost); |
Evan Cheng | d70f57b | 2010-07-19 22:15:08 +0000 | [diff] [blame] | 760 | } |
| 761 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 762 | const char *ARMTargetLowering::getTargetNodeName(unsigned Opcode) const { |
| 763 | switch (Opcode) { |
| 764 | default: return 0; |
| 765 | case ARMISD::Wrapper: return "ARMISD::Wrapper"; |
Evan Cheng | 53519f0 | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 766 | case ARMISD::WrapperDYN: return "ARMISD::WrapperDYN"; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 767 | case ARMISD::WrapperPIC: return "ARMISD::WrapperPIC"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 768 | case ARMISD::WrapperJT: return "ARMISD::WrapperJT"; |
| 769 | case ARMISD::CALL: return "ARMISD::CALL"; |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 770 | case ARMISD::CALL_PRED: return "ARMISD::CALL_PRED"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 771 | case ARMISD::CALL_NOLINK: return "ARMISD::CALL_NOLINK"; |
| 772 | case ARMISD::tCALL: return "ARMISD::tCALL"; |
| 773 | case ARMISD::BRCOND: return "ARMISD::BRCOND"; |
| 774 | case ARMISD::BR_JT: return "ARMISD::BR_JT"; |
Evan Cheng | 5657c01 | 2009-07-29 02:18:14 +0000 | [diff] [blame] | 775 | case ARMISD::BR2_JT: return "ARMISD::BR2_JT"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 776 | case ARMISD::RET_FLAG: return "ARMISD::RET_FLAG"; |
| 777 | case ARMISD::PIC_ADD: return "ARMISD::PIC_ADD"; |
| 778 | case ARMISD::CMP: return "ARMISD::CMP"; |
David Goodwin | c0309b4 | 2009-06-29 15:33:01 +0000 | [diff] [blame] | 779 | case ARMISD::CMPZ: return "ARMISD::CMPZ"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 780 | case ARMISD::CMPFP: return "ARMISD::CMPFP"; |
| 781 | case ARMISD::CMPFPw0: return "ARMISD::CMPFPw0"; |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 782 | case ARMISD::BCC_i64: return "ARMISD::BCC_i64"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 783 | case ARMISD::FMSTAT: return "ARMISD::FMSTAT"; |
| 784 | case ARMISD::CMOV: return "ARMISD::CMOV"; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 785 | |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 786 | case ARMISD::RBIT: return "ARMISD::RBIT"; |
| 787 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 788 | case ARMISD::FTOSI: return "ARMISD::FTOSI"; |
| 789 | case ARMISD::FTOUI: return "ARMISD::FTOUI"; |
| 790 | case ARMISD::SITOF: return "ARMISD::SITOF"; |
| 791 | case ARMISD::UITOF: return "ARMISD::UITOF"; |
| 792 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 793 | case ARMISD::SRL_FLAG: return "ARMISD::SRL_FLAG"; |
| 794 | case ARMISD::SRA_FLAG: return "ARMISD::SRA_FLAG"; |
| 795 | case ARMISD::RRX: return "ARMISD::RRX"; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 796 | |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 797 | case ARMISD::VMOVRRD: return "ARMISD::VMOVRRD"; |
| 798 | case ARMISD::VMOVDRR: return "ARMISD::VMOVDRR"; |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 799 | |
Evan Cheng | c594208 | 2009-10-28 06:55:03 +0000 | [diff] [blame] | 800 | case ARMISD::EH_SJLJ_SETJMP: return "ARMISD::EH_SJLJ_SETJMP"; |
| 801 | case ARMISD::EH_SJLJ_LONGJMP:return "ARMISD::EH_SJLJ_LONGJMP"; |
Jim Grosbach | e4ad387 | 2010-10-19 23:27:08 +0000 | [diff] [blame] | 802 | case ARMISD::EH_SJLJ_DISPATCHSETUP:return "ARMISD::EH_SJLJ_DISPATCHSETUP"; |
Evan Cheng | c594208 | 2009-10-28 06:55:03 +0000 | [diff] [blame] | 803 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 804 | case ARMISD::TC_RETURN: return "ARMISD::TC_RETURN"; |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 805 | |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 806 | case ARMISD::THREAD_POINTER:return "ARMISD::THREAD_POINTER"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 807 | |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 808 | case ARMISD::DYN_ALLOC: return "ARMISD::DYN_ALLOC"; |
| 809 | |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 810 | case ARMISD::MEMBARRIER: return "ARMISD::MEMBARRIER"; |
Bob Wilson | f74a429 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 811 | case ARMISD::MEMBARRIER_MCR: return "ARMISD::MEMBARRIER_MCR"; |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 812 | |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 813 | case ARMISD::PRELOAD: return "ARMISD::PRELOAD"; |
| 814 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 815 | case ARMISD::VCEQ: return "ARMISD::VCEQ"; |
Bob Wilson | 3a75b9b | 2010-12-18 00:04:26 +0000 | [diff] [blame] | 816 | case ARMISD::VCEQZ: return "ARMISD::VCEQZ"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 817 | case ARMISD::VCGE: return "ARMISD::VCGE"; |
Bob Wilson | 3a75b9b | 2010-12-18 00:04:26 +0000 | [diff] [blame] | 818 | case ARMISD::VCGEZ: return "ARMISD::VCGEZ"; |
| 819 | case ARMISD::VCLEZ: return "ARMISD::VCLEZ"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 820 | case ARMISD::VCGEU: return "ARMISD::VCGEU"; |
| 821 | case ARMISD::VCGT: return "ARMISD::VCGT"; |
Bob Wilson | 3a75b9b | 2010-12-18 00:04:26 +0000 | [diff] [blame] | 822 | case ARMISD::VCGTZ: return "ARMISD::VCGTZ"; |
| 823 | case ARMISD::VCLTZ: return "ARMISD::VCLTZ"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 824 | case ARMISD::VCGTU: return "ARMISD::VCGTU"; |
| 825 | case ARMISD::VTST: return "ARMISD::VTST"; |
| 826 | |
| 827 | case ARMISD::VSHL: return "ARMISD::VSHL"; |
| 828 | case ARMISD::VSHRs: return "ARMISD::VSHRs"; |
| 829 | case ARMISD::VSHRu: return "ARMISD::VSHRu"; |
| 830 | case ARMISD::VSHLLs: return "ARMISD::VSHLLs"; |
| 831 | case ARMISD::VSHLLu: return "ARMISD::VSHLLu"; |
| 832 | case ARMISD::VSHLLi: return "ARMISD::VSHLLi"; |
| 833 | case ARMISD::VSHRN: return "ARMISD::VSHRN"; |
| 834 | case ARMISD::VRSHRs: return "ARMISD::VRSHRs"; |
| 835 | case ARMISD::VRSHRu: return "ARMISD::VRSHRu"; |
| 836 | case ARMISD::VRSHRN: return "ARMISD::VRSHRN"; |
| 837 | case ARMISD::VQSHLs: return "ARMISD::VQSHLs"; |
| 838 | case ARMISD::VQSHLu: return "ARMISD::VQSHLu"; |
| 839 | case ARMISD::VQSHLsu: return "ARMISD::VQSHLsu"; |
| 840 | case ARMISD::VQSHRNs: return "ARMISD::VQSHRNs"; |
| 841 | case ARMISD::VQSHRNu: return "ARMISD::VQSHRNu"; |
| 842 | case ARMISD::VQSHRNsu: return "ARMISD::VQSHRNsu"; |
| 843 | case ARMISD::VQRSHRNs: return "ARMISD::VQRSHRNs"; |
| 844 | case ARMISD::VQRSHRNu: return "ARMISD::VQRSHRNu"; |
| 845 | case ARMISD::VQRSHRNsu: return "ARMISD::VQRSHRNsu"; |
| 846 | case ARMISD::VGETLANEu: return "ARMISD::VGETLANEu"; |
| 847 | case ARMISD::VGETLANEs: return "ARMISD::VGETLANEs"; |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 848 | case ARMISD::VMOVIMM: return "ARMISD::VMOVIMM"; |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 849 | case ARMISD::VMVNIMM: return "ARMISD::VMVNIMM"; |
Bob Wilson | c1d287b | 2009-08-14 05:13:08 +0000 | [diff] [blame] | 850 | case ARMISD::VDUP: return "ARMISD::VDUP"; |
Bob Wilson | 0ce3710 | 2009-08-14 05:08:32 +0000 | [diff] [blame] | 851 | case ARMISD::VDUPLANE: return "ARMISD::VDUPLANE"; |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 852 | case ARMISD::VEXT: return "ARMISD::VEXT"; |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 853 | case ARMISD::VREV64: return "ARMISD::VREV64"; |
| 854 | case ARMISD::VREV32: return "ARMISD::VREV32"; |
| 855 | case ARMISD::VREV16: return "ARMISD::VREV16"; |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 856 | case ARMISD::VZIP: return "ARMISD::VZIP"; |
| 857 | case ARMISD::VUZP: return "ARMISD::VUZP"; |
| 858 | case ARMISD::VTRN: return "ARMISD::VTRN"; |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 859 | case ARMISD::VTBL1: return "ARMISD::VTBL1"; |
| 860 | case ARMISD::VTBL2: return "ARMISD::VTBL2"; |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 861 | case ARMISD::VMULLs: return "ARMISD::VMULLs"; |
| 862 | case ARMISD::VMULLu: return "ARMISD::VMULLu"; |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 863 | case ARMISD::BUILD_VECTOR: return "ARMISD::BUILD_VECTOR"; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 864 | case ARMISD::FMAX: return "ARMISD::FMAX"; |
| 865 | case ARMISD::FMIN: return "ARMISD::FMIN"; |
Jim Grosbach | dd7d28a | 2010-07-17 01:50:57 +0000 | [diff] [blame] | 866 | case ARMISD::BFI: return "ARMISD::BFI"; |
Bob Wilson | 364a72a | 2010-11-28 06:51:11 +0000 | [diff] [blame] | 867 | case ARMISD::VORRIMM: return "ARMISD::VORRIMM"; |
| 868 | case ARMISD::VBICIMM: return "ARMISD::VBICIMM"; |
Cameron Zwarich | c0e6d78 | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 869 | case ARMISD::VBSL: return "ARMISD::VBSL"; |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 870 | case ARMISD::VLD2DUP: return "ARMISD::VLD2DUP"; |
| 871 | case ARMISD::VLD3DUP: return "ARMISD::VLD3DUP"; |
| 872 | case ARMISD::VLD4DUP: return "ARMISD::VLD4DUP"; |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 873 | case ARMISD::VLD1_UPD: return "ARMISD::VLD1_UPD"; |
| 874 | case ARMISD::VLD2_UPD: return "ARMISD::VLD2_UPD"; |
| 875 | case ARMISD::VLD3_UPD: return "ARMISD::VLD3_UPD"; |
| 876 | case ARMISD::VLD4_UPD: return "ARMISD::VLD4_UPD"; |
| 877 | case ARMISD::VLD2LN_UPD: return "ARMISD::VLD2LN_UPD"; |
| 878 | case ARMISD::VLD3LN_UPD: return "ARMISD::VLD3LN_UPD"; |
| 879 | case ARMISD::VLD4LN_UPD: return "ARMISD::VLD4LN_UPD"; |
| 880 | case ARMISD::VLD2DUP_UPD: return "ARMISD::VLD2DUP_UPD"; |
| 881 | case ARMISD::VLD3DUP_UPD: return "ARMISD::VLD3DUP_UPD"; |
| 882 | case ARMISD::VLD4DUP_UPD: return "ARMISD::VLD4DUP_UPD"; |
| 883 | case ARMISD::VST1_UPD: return "ARMISD::VST1_UPD"; |
| 884 | case ARMISD::VST2_UPD: return "ARMISD::VST2_UPD"; |
| 885 | case ARMISD::VST3_UPD: return "ARMISD::VST3_UPD"; |
| 886 | case ARMISD::VST4_UPD: return "ARMISD::VST4_UPD"; |
| 887 | case ARMISD::VST2LN_UPD: return "ARMISD::VST2LN_UPD"; |
| 888 | case ARMISD::VST3LN_UPD: return "ARMISD::VST3LN_UPD"; |
| 889 | case ARMISD::VST4LN_UPD: return "ARMISD::VST4LN_UPD"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 890 | } |
| 891 | } |
| 892 | |
Evan Cheng | 06b666c | 2010-05-15 02:18:07 +0000 | [diff] [blame] | 893 | /// getRegClassFor - Return the register class that should be used for the |
| 894 | /// specified value type. |
| 895 | TargetRegisterClass *ARMTargetLowering::getRegClassFor(EVT VT) const { |
| 896 | // Map v4i64 to QQ registers but do not make the type legal. Similarly map |
| 897 | // v8i64 to QQQQ registers. v4i64 and v8i64 are only used for REG_SEQUENCE to |
| 898 | // load / store 4 to 8 consecutive D registers. |
Evan Cheng | 4782b1e | 2010-05-15 02:20:21 +0000 | [diff] [blame] | 899 | if (Subtarget->hasNEON()) { |
| 900 | if (VT == MVT::v4i64) |
| 901 | return ARM::QQPRRegisterClass; |
| 902 | else if (VT == MVT::v8i64) |
| 903 | return ARM::QQQQPRRegisterClass; |
| 904 | } |
Evan Cheng | 06b666c | 2010-05-15 02:18:07 +0000 | [diff] [blame] | 905 | return TargetLowering::getRegClassFor(VT); |
| 906 | } |
| 907 | |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 908 | // Create a fast isel object. |
| 909 | FastISel * |
| 910 | ARMTargetLowering::createFastISel(FunctionLoweringInfo &funcInfo) const { |
| 911 | return ARM::createFastISel(funcInfo); |
| 912 | } |
| 913 | |
Bill Wendling | b4202b8 | 2009-07-01 18:50:55 +0000 | [diff] [blame] | 914 | /// getFunctionAlignment - Return the Log2 alignment of this function. |
Bill Wendling | 20c568f | 2009-06-30 22:38:32 +0000 | [diff] [blame] | 915 | unsigned ARMTargetLowering::getFunctionAlignment(const Function *F) const { |
Bob Wilson | b5b5057 | 2010-07-01 22:26:26 +0000 | [diff] [blame] | 916 | return getTargetMachine().getSubtarget<ARMSubtarget>().isThumb() ? 1 : 2; |
Bill Wendling | 20c568f | 2009-06-30 22:38:32 +0000 | [diff] [blame] | 917 | } |
| 918 | |
Anton Korobeynikov | cec36f4 | 2010-07-24 21:52:08 +0000 | [diff] [blame] | 919 | /// getMaximalGlobalOffset - Returns the maximal possible offset which can |
| 920 | /// be used for loads / stores from the global. |
| 921 | unsigned ARMTargetLowering::getMaximalGlobalOffset() const { |
| 922 | return (Subtarget->isThumb1Only() ? 127 : 4095); |
| 923 | } |
| 924 | |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 925 | Sched::Preference ARMTargetLowering::getSchedulingPreference(SDNode *N) const { |
Evan Cheng | c10f543 | 2010-05-28 23:25:23 +0000 | [diff] [blame] | 926 | unsigned NumVals = N->getNumValues(); |
| 927 | if (!NumVals) |
| 928 | return Sched::RegPressure; |
| 929 | |
| 930 | for (unsigned i = 0; i != NumVals; ++i) { |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 931 | EVT VT = N->getValueType(i); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 932 | if (VT == MVT::Glue || VT == MVT::Other) |
Evan Cheng | d7e473c | 2010-10-29 18:07:31 +0000 | [diff] [blame] | 933 | continue; |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 934 | if (VT.isFloatingPoint() || VT.isVector()) |
| 935 | return Sched::Latency; |
| 936 | } |
Evan Cheng | c10f543 | 2010-05-28 23:25:23 +0000 | [diff] [blame] | 937 | |
| 938 | if (!N->isMachineOpcode()) |
| 939 | return Sched::RegPressure; |
| 940 | |
| 941 | // Load are scheduled for latency even if there instruction itinerary |
| 942 | // is not available. |
| 943 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 944 | const TargetInstrDesc &TID = TII->get(N->getMachineOpcode()); |
Evan Cheng | d7e473c | 2010-10-29 18:07:31 +0000 | [diff] [blame] | 945 | |
| 946 | if (TID.getNumDefs() == 0) |
| 947 | return Sched::RegPressure; |
| 948 | if (!Itins->isEmpty() && |
| 949 | Itins->getOperandCycle(TID.getSchedClass(), 0) > 2) |
Evan Cheng | c10f543 | 2010-05-28 23:25:23 +0000 | [diff] [blame] | 950 | return Sched::Latency; |
| 951 | |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 952 | return Sched::RegPressure; |
| 953 | } |
| 954 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 955 | //===----------------------------------------------------------------------===// |
| 956 | // Lowering Code |
| 957 | //===----------------------------------------------------------------------===// |
| 958 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 959 | /// IntCCToARMCC - Convert a DAG integer condition code to an ARM CC |
| 960 | static ARMCC::CondCodes IntCCToARMCC(ISD::CondCode CC) { |
| 961 | switch (CC) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 962 | default: llvm_unreachable("Unknown condition code!"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 963 | case ISD::SETNE: return ARMCC::NE; |
| 964 | case ISD::SETEQ: return ARMCC::EQ; |
| 965 | case ISD::SETGT: return ARMCC::GT; |
| 966 | case ISD::SETGE: return ARMCC::GE; |
| 967 | case ISD::SETLT: return ARMCC::LT; |
| 968 | case ISD::SETLE: return ARMCC::LE; |
| 969 | case ISD::SETUGT: return ARMCC::HI; |
| 970 | case ISD::SETUGE: return ARMCC::HS; |
| 971 | case ISD::SETULT: return ARMCC::LO; |
| 972 | case ISD::SETULE: return ARMCC::LS; |
| 973 | } |
| 974 | } |
| 975 | |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 976 | /// FPCCToARMCC - Convert a DAG fp condition code to an ARM CC. |
| 977 | static void FPCCToARMCC(ISD::CondCode CC, ARMCC::CondCodes &CondCode, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 978 | ARMCC::CondCodes &CondCode2) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 979 | CondCode2 = ARMCC::AL; |
| 980 | switch (CC) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 981 | default: llvm_unreachable("Unknown FP condition!"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 982 | case ISD::SETEQ: |
| 983 | case ISD::SETOEQ: CondCode = ARMCC::EQ; break; |
| 984 | case ISD::SETGT: |
| 985 | case ISD::SETOGT: CondCode = ARMCC::GT; break; |
| 986 | case ISD::SETGE: |
| 987 | case ISD::SETOGE: CondCode = ARMCC::GE; break; |
| 988 | case ISD::SETOLT: CondCode = ARMCC::MI; break; |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 989 | case ISD::SETOLE: CondCode = ARMCC::LS; break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 990 | case ISD::SETONE: CondCode = ARMCC::MI; CondCode2 = ARMCC::GT; break; |
| 991 | case ISD::SETO: CondCode = ARMCC::VC; break; |
| 992 | case ISD::SETUO: CondCode = ARMCC::VS; break; |
| 993 | case ISD::SETUEQ: CondCode = ARMCC::EQ; CondCode2 = ARMCC::VS; break; |
| 994 | case ISD::SETUGT: CondCode = ARMCC::HI; break; |
| 995 | case ISD::SETUGE: CondCode = ARMCC::PL; break; |
| 996 | case ISD::SETLT: |
| 997 | case ISD::SETULT: CondCode = ARMCC::LT; break; |
| 998 | case ISD::SETLE: |
| 999 | case ISD::SETULE: CondCode = ARMCC::LE; break; |
| 1000 | case ISD::SETNE: |
| 1001 | case ISD::SETUNE: CondCode = ARMCC::NE; break; |
| 1002 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1003 | } |
| 1004 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1005 | //===----------------------------------------------------------------------===// |
| 1006 | // Calling Convention Implementation |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1007 | //===----------------------------------------------------------------------===// |
| 1008 | |
| 1009 | #include "ARMGenCallingConv.inc" |
| 1010 | |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1011 | /// CCAssignFnForNode - Selects the correct CCAssignFn for a the |
| 1012 | /// given CallingConvention value. |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1013 | CCAssignFn *ARMTargetLowering::CCAssignFnForNode(CallingConv::ID CC, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1014 | bool Return, |
| 1015 | bool isVarArg) const { |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1016 | switch (CC) { |
| 1017 | default: |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1018 | llvm_unreachable("Unsupported calling convention"); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1019 | case CallingConv::Fast: |
Evan Cheng | 5c2d428 | 2010-10-23 02:19:37 +0000 | [diff] [blame] | 1020 | if (Subtarget->hasVFP2() && !isVarArg) { |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1021 | if (!Subtarget->isAAPCS_ABI()) |
| 1022 | return (Return ? RetFastCC_ARM_APCS : FastCC_ARM_APCS); |
| 1023 | // For AAPCS ABI targets, just use VFP variant of the calling convention. |
| 1024 | return (Return ? RetCC_ARM_AAPCS_VFP : CC_ARM_AAPCS_VFP); |
| 1025 | } |
| 1026 | // Fallthrough |
| 1027 | case CallingConv::C: { |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1028 | // Use target triple & subtarget features to do actual dispatch. |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1029 | if (!Subtarget->isAAPCS_ABI()) |
| 1030 | return (Return ? RetCC_ARM_APCS : CC_ARM_APCS); |
| 1031 | else if (Subtarget->hasVFP2() && |
| 1032 | FloatABIType == FloatABI::Hard && !isVarArg) |
| 1033 | return (Return ? RetCC_ARM_AAPCS_VFP : CC_ARM_AAPCS_VFP); |
| 1034 | return (Return ? RetCC_ARM_AAPCS : CC_ARM_AAPCS); |
| 1035 | } |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1036 | case CallingConv::ARM_AAPCS_VFP: |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1037 | return (Return ? RetCC_ARM_AAPCS_VFP : CC_ARM_AAPCS_VFP); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1038 | case CallingConv::ARM_AAPCS: |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1039 | return (Return ? RetCC_ARM_AAPCS : CC_ARM_AAPCS); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1040 | case CallingConv::ARM_APCS: |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1041 | return (Return ? RetCC_ARM_APCS : CC_ARM_APCS); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1042 | } |
| 1043 | } |
| 1044 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1045 | /// LowerCallResult - Lower the result values of a call into the |
| 1046 | /// appropriate copies out of appropriate physical registers. |
| 1047 | SDValue |
| 1048 | ARMTargetLowering::LowerCallResult(SDValue Chain, SDValue InFlag, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1049 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1050 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 1051 | DebugLoc dl, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1052 | SmallVectorImpl<SDValue> &InVals) const { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1053 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1054 | // Assign locations to each value returned by this call. |
| 1055 | SmallVector<CCValAssign, 16> RVLocs; |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1056 | CCState CCInfo(CallConv, isVarArg, getTargetMachine(), |
Owen Anderson | e922c02 | 2009-07-22 00:24:57 +0000 | [diff] [blame] | 1057 | RVLocs, *DAG.getContext()); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1058 | CCInfo.AnalyzeCallResult(Ins, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1059 | CCAssignFnForNode(CallConv, /* Return*/ true, |
| 1060 | isVarArg)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1061 | |
| 1062 | // Copy all of the result registers out of their specified physreg. |
| 1063 | for (unsigned i = 0; i != RVLocs.size(); ++i) { |
| 1064 | CCValAssign VA = RVLocs[i]; |
| 1065 | |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1066 | SDValue Val; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1067 | if (VA.needsCustom()) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1068 | // Handle f64 or half of a v2f64. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1069 | SDValue Lo = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1070 | InFlag); |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1071 | Chain = Lo.getValue(1); |
| 1072 | InFlag = Lo.getValue(2); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1073 | VA = RVLocs[++i]; // skip ahead to next loc |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1074 | SDValue Hi = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1075 | InFlag); |
| 1076 | Chain = Hi.getValue(1); |
| 1077 | InFlag = Hi.getValue(2); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1078 | Val = DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1079 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1080 | if (VA.getLocVT() == MVT::v2f64) { |
| 1081 | SDValue Vec = DAG.getNode(ISD::UNDEF, dl, MVT::v2f64); |
| 1082 | Vec = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Vec, Val, |
| 1083 | DAG.getConstant(0, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1084 | |
| 1085 | VA = RVLocs[++i]; // skip ahead to next loc |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1086 | Lo = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, InFlag); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1087 | Chain = Lo.getValue(1); |
| 1088 | InFlag = Lo.getValue(2); |
| 1089 | VA = RVLocs[++i]; // skip ahead to next loc |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1090 | Hi = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, InFlag); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1091 | Chain = Hi.getValue(1); |
| 1092 | InFlag = Hi.getValue(2); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1093 | Val = DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1094 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Vec, Val, |
| 1095 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1096 | } |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1097 | } else { |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1098 | Val = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), VA.getLocVT(), |
| 1099 | InFlag); |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1100 | Chain = Val.getValue(1); |
| 1101 | InFlag = Val.getValue(2); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1102 | } |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1103 | |
| 1104 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1105 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1106 | case CCValAssign::Full: break; |
| 1107 | case CCValAssign::BCvt: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1108 | Val = DAG.getNode(ISD::BITCAST, dl, VA.getValVT(), Val); |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1109 | break; |
| 1110 | } |
| 1111 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1112 | InVals.push_back(Val); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1113 | } |
| 1114 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1115 | return Chain; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | /// CreateCopyOfByValArgument - Make a copy of an aggregate at address specified |
| 1119 | /// by "Src" to address "Dst" of size "Size". Alignment information is |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1120 | /// specified by the specific parameter attribute. The copy will be passed as |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1121 | /// a byval function parameter. |
| 1122 | /// Sometimes what we are copying is the end of a larger object, the part that |
| 1123 | /// does not fit in registers. |
| 1124 | static SDValue |
| 1125 | CreateCopyOfByValArgument(SDValue Src, SDValue Dst, SDValue Chain, |
| 1126 | ISD::ArgFlagsTy Flags, SelectionDAG &DAG, |
| 1127 | DebugLoc dl) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1128 | SDValue SizeNode = DAG.getConstant(Flags.getByValSize(), MVT::i32); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1129 | return DAG.getMemcpy(Chain, dl, Dst, Src, SizeNode, Flags.getByValAlign(), |
Mon P Wang | 20adc9d | 2010-04-04 03:10:48 +0000 | [diff] [blame] | 1130 | /*isVolatile=*/false, /*AlwaysInline=*/false, |
Chris Lattner | e72f202 | 2010-09-21 05:40:29 +0000 | [diff] [blame] | 1131 | MachinePointerInfo(0), MachinePointerInfo(0)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1132 | } |
| 1133 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1134 | /// LowerMemOpCallTo - Store the argument to the stack. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1135 | SDValue |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1136 | ARMTargetLowering::LowerMemOpCallTo(SDValue Chain, |
| 1137 | SDValue StackPtr, SDValue Arg, |
| 1138 | DebugLoc dl, SelectionDAG &DAG, |
| 1139 | const CCValAssign &VA, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1140 | ISD::ArgFlagsTy Flags) const { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1141 | unsigned LocMemOffset = VA.getLocMemOffset(); |
| 1142 | SDValue PtrOff = DAG.getIntPtrConstant(LocMemOffset); |
| 1143 | PtrOff = DAG.getNode(ISD::ADD, dl, getPointerTy(), StackPtr, PtrOff); |
Chris Lattner | fc448ff | 2010-09-21 18:51:21 +0000 | [diff] [blame] | 1144 | if (Flags.isByVal()) |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1145 | return CreateCopyOfByValArgument(Arg, PtrOff, Chain, Flags, DAG, dl); |
Chris Lattner | fc448ff | 2010-09-21 18:51:21 +0000 | [diff] [blame] | 1146 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1147 | return DAG.getStore(Chain, dl, Arg, PtrOff, |
Chris Lattner | fc448ff | 2010-09-21 18:51:21 +0000 | [diff] [blame] | 1148 | MachinePointerInfo::getStack(LocMemOffset), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1149 | false, false, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1150 | } |
| 1151 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1152 | void ARMTargetLowering::PassF64ArgInRegs(DebugLoc dl, SelectionDAG &DAG, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1153 | SDValue Chain, SDValue &Arg, |
| 1154 | RegsToPassVector &RegsToPass, |
| 1155 | CCValAssign &VA, CCValAssign &NextVA, |
| 1156 | SDValue &StackPtr, |
| 1157 | SmallVector<SDValue, 8> &MemOpChains, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1158 | ISD::ArgFlagsTy Flags) const { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1159 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1160 | SDValue fmrrd = DAG.getNode(ARMISD::VMOVRRD, dl, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1161 | DAG.getVTList(MVT::i32, MVT::i32), Arg); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1162 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), fmrrd)); |
| 1163 | |
| 1164 | if (NextVA.isRegLoc()) |
| 1165 | RegsToPass.push_back(std::make_pair(NextVA.getLocReg(), fmrrd.getValue(1))); |
| 1166 | else { |
| 1167 | assert(NextVA.isMemLoc()); |
| 1168 | if (StackPtr.getNode() == 0) |
| 1169 | StackPtr = DAG.getCopyFromReg(Chain, dl, ARM::SP, getPointerTy()); |
| 1170 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1171 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, fmrrd.getValue(1), |
| 1172 | dl, DAG, NextVA, |
| 1173 | Flags)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1174 | } |
| 1175 | } |
| 1176 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1177 | /// LowerCall - Lowering a call into a callseq_start <- |
Evan Cheng | fc40342 | 2007-02-03 08:53:01 +0000 | [diff] [blame] | 1178 | /// ARMISD:CALL <- callseq_end chain. Also add input and output parameter |
| 1179 | /// nodes. |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1180 | SDValue |
Evan Cheng | 022d9e1 | 2010-02-02 23:55:14 +0000 | [diff] [blame] | 1181 | ARMTargetLowering::LowerCall(SDValue Chain, SDValue Callee, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1182 | CallingConv::ID CallConv, bool isVarArg, |
Evan Cheng | 0c439eb | 2010-01-27 00:07:07 +0000 | [diff] [blame] | 1183 | bool &isTailCall, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1184 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1185 | const SmallVectorImpl<SDValue> &OutVals, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1186 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 1187 | DebugLoc dl, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1188 | SmallVectorImpl<SDValue> &InVals) const { |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1189 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1190 | bool IsStructRet = (Outs.empty()) ? false : Outs[0].Flags.isSRet(); |
| 1191 | bool IsSibCall = false; |
Bob Wilson | 703af3a | 2010-08-13 22:43:33 +0000 | [diff] [blame] | 1192 | // Temporarily disable tail calls so things don't break. |
| 1193 | if (!EnableARMTailCalls) |
| 1194 | isTailCall = false; |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1195 | if (isTailCall) { |
| 1196 | // Check if it's really possible to do a tail call. |
| 1197 | isTailCall = IsEligibleForTailCallOptimization(Callee, CallConv, |
| 1198 | isVarArg, IsStructRet, MF.getFunction()->hasStructRetAttr(), |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1199 | Outs, OutVals, Ins, DAG); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1200 | // We don't support GuaranteedTailCallOpt for ARM, only automatically |
| 1201 | // detected sibcalls. |
| 1202 | if (isTailCall) { |
| 1203 | ++NumTailCalls; |
| 1204 | IsSibCall = true; |
| 1205 | } |
| 1206 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1207 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1208 | // Analyze operands of the call, assigning locations to each operand. |
| 1209 | SmallVector<CCValAssign, 16> ArgLocs; |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1210 | CCState CCInfo(CallConv, isVarArg, getTargetMachine(), ArgLocs, |
| 1211 | *DAG.getContext()); |
| 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 | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1288 | } else if (!IsSibCall || isByVal) { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1289 | assert(VA.isMemLoc()); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1290 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1291 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, Arg, |
| 1292 | dl, DAG, VA, Flags)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1293 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1294 | } |
| 1295 | |
| 1296 | if (!MemOpChains.empty()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1297 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1298 | &MemOpChains[0], MemOpChains.size()); |
| 1299 | |
| 1300 | // Build a sequence of copy-to-reg nodes chained together with token chain |
| 1301 | // and flag operands which copy the outgoing args into the appropriate regs. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1302 | SDValue InFlag; |
Dale Johannesen | 6470a11 | 2010-06-15 22:08:33 +0000 | [diff] [blame] | 1303 | // Tail call byval lowering might overwrite argument registers so in case of |
| 1304 | // tail call optimization the copies to registers are lowered later. |
| 1305 | if (!isTailCall) |
| 1306 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 1307 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, |
| 1308 | RegsToPass[i].second, InFlag); |
| 1309 | InFlag = Chain.getValue(1); |
| 1310 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1311 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1312 | // For tail calls lower the arguments to the 'real' stack slot. |
| 1313 | if (isTailCall) { |
| 1314 | // Force all the incoming stack arguments to be loaded from the stack |
| 1315 | // before any new outgoing arguments are stored to the stack, because the |
| 1316 | // outgoing stack slots may alias the incoming argument stack slots, and |
| 1317 | // the alias isn't otherwise explicit. This is slightly more conservative |
| 1318 | // than necessary, because it means that each store effectively depends |
| 1319 | // on every argument instead of just those arguments it would clobber. |
| 1320 | |
| 1321 | // Do not flag preceeding copytoreg stuff together with the following stuff. |
| 1322 | InFlag = SDValue(); |
| 1323 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 1324 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, |
| 1325 | RegsToPass[i].second, InFlag); |
| 1326 | InFlag = Chain.getValue(1); |
| 1327 | } |
| 1328 | InFlag =SDValue(); |
| 1329 | } |
| 1330 | |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1331 | // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every |
| 1332 | // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol |
| 1333 | // node so that legalize doesn't hack it. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1334 | bool isDirect = false; |
| 1335 | bool isARMFunc = false; |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 1336 | bool isLocalARMFunc = false; |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1337 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1338 | |
| 1339 | if (EnableARMLongCalls) { |
| 1340 | assert (getTargetMachine().getRelocationModel() == Reloc::Static |
| 1341 | && "long-calls with non-static relocation model!"); |
| 1342 | // Handle a global address or an external symbol. If it's not one of |
| 1343 | // those, the target's already in a register, so we don't need to do |
| 1344 | // anything extra. |
| 1345 | if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
Anders Carlsson | 0dbdca5 | 2010-04-15 03:11:28 +0000 | [diff] [blame] | 1346 | const GlobalValue *GV = G->getGlobal(); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1347 | // Create a constant pool entry for the callee address |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1348 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1349 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GV, |
| 1350 | ARMPCLabelIndex, |
| 1351 | ARMCP::CPValue, 0); |
| 1352 | // Get the address of the callee into a register |
| 1353 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
| 1354 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| 1355 | Callee = DAG.getLoad(getPointerTy(), dl, |
| 1356 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1357 | MachinePointerInfo::getConstantPool(), |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1358 | false, false, 0); |
| 1359 | } else if (ExternalSymbolSDNode *S=dyn_cast<ExternalSymbolSDNode>(Callee)) { |
| 1360 | const char *Sym = S->getSymbol(); |
| 1361 | |
| 1362 | // Create a constant pool entry for the callee address |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1363 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1364 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(*DAG.getContext(), |
| 1365 | Sym, ARMPCLabelIndex, 0); |
| 1366 | // Get the address of the callee into a register |
| 1367 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
| 1368 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| 1369 | Callee = DAG.getLoad(getPointerTy(), dl, |
| 1370 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1371 | MachinePointerInfo::getConstantPool(), |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1372 | false, false, 0); |
| 1373 | } |
| 1374 | } else if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 1375 | const GlobalValue *GV = G->getGlobal(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1376 | isDirect = true; |
Chris Lattner | 4fb63d0 | 2009-07-15 04:12:33 +0000 | [diff] [blame] | 1377 | bool isExt = GV->isDeclaration() || GV->isWeakForLinker(); |
Evan Cheng | 970a419 | 2007-01-19 19:28:01 +0000 | [diff] [blame] | 1378 | bool isStub = (isExt && Subtarget->isTargetDarwin()) && |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1379 | getTargetMachine().getRelocationModel() != Reloc::Static; |
| 1380 | isARMFunc = !Subtarget->isThumb() || isStub; |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 1381 | // ARM call to a local ARM function is predicable. |
Evan Cheng | 46df4eb | 2010-06-16 07:35:02 +0000 | [diff] [blame] | 1382 | isLocalARMFunc = !Subtarget->isThumb() && (!isExt || !ARMInterworking); |
Evan Cheng | c60e76d | 2007-01-30 20:37:08 +0000 | [diff] [blame] | 1383 | // tBX takes a register source operand. |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 1384 | if (isARMFunc && Subtarget->isThumb1Only() && !Subtarget->hasV5TOps()) { |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1385 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 1386 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GV, |
Jim Grosbach | 3fb2b1e | 2009-09-01 01:57:56 +0000 | [diff] [blame] | 1387 | ARMPCLabelIndex, |
| 1388 | ARMCP::CPValue, 4); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1389 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1390 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1391 | Callee = DAG.getLoad(getPointerTy(), dl, |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1392 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1393 | MachinePointerInfo::getConstantPool(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1394 | false, false, 0); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1395 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1396 | Callee = DAG.getNode(ARMISD::PIC_ADD, dl, |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1397 | getPointerTy(), Callee, PICLabel); |
Jim Grosbach | 637d89f | 2010-09-22 23:27:36 +0000 | [diff] [blame] | 1398 | } else { |
| 1399 | // On ELF targets for PIC code, direct calls should go through the PLT |
| 1400 | unsigned OpFlags = 0; |
| 1401 | if (Subtarget->isTargetELF() && |
| 1402 | getTargetMachine().getRelocationModel() == Reloc::PIC_) |
| 1403 | OpFlags = ARMII::MO_PLT; |
| 1404 | Callee = DAG.getTargetGlobalAddress(GV, dl, getPointerTy(), 0, OpFlags); |
| 1405 | } |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1406 | } else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1407 | isDirect = true; |
Evan Cheng | 970a419 | 2007-01-19 19:28:01 +0000 | [diff] [blame] | 1408 | bool isStub = Subtarget->isTargetDarwin() && |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1409 | getTargetMachine().getRelocationModel() != Reloc::Static; |
| 1410 | isARMFunc = !Subtarget->isThumb() || isStub; |
Evan Cheng | c60e76d | 2007-01-30 20:37:08 +0000 | [diff] [blame] | 1411 | // tBX takes a register source operand. |
| 1412 | const char *Sym = S->getSymbol(); |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 1413 | if (isARMFunc && Subtarget->isThumb1Only() && !Subtarget->hasV5TOps()) { |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1414 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 1415 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(*DAG.getContext(), |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 1416 | Sym, ARMPCLabelIndex, 4); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1417 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1418 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1419 | Callee = DAG.getLoad(getPointerTy(), dl, |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1420 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1421 | MachinePointerInfo::getConstantPool(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1422 | false, false, 0); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1423 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1424 | Callee = DAG.getNode(ARMISD::PIC_ADD, dl, |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1425 | getPointerTy(), Callee, PICLabel); |
Jim Grosbach | 637d89f | 2010-09-22 23:27:36 +0000 | [diff] [blame] | 1426 | } else { |
| 1427 | unsigned OpFlags = 0; |
| 1428 | // On ELF targets for PIC code, direct calls should go through the PLT |
| 1429 | if (Subtarget->isTargetELF() && |
| 1430 | getTargetMachine().getRelocationModel() == Reloc::PIC_) |
| 1431 | OpFlags = ARMII::MO_PLT; |
| 1432 | Callee = DAG.getTargetExternalSymbol(Sym, getPointerTy(), OpFlags); |
| 1433 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1434 | } |
| 1435 | |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1436 | // FIXME: handle tail calls differently. |
| 1437 | unsigned CallOpc; |
Evan Cheng | b620724 | 2009-08-01 00:16:10 +0000 | [diff] [blame] | 1438 | if (Subtarget->isThumb()) { |
| 1439 | if ((!isDirect || isARMFunc) && !Subtarget->hasV5TOps()) |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1440 | CallOpc = ARMISD::CALL_NOLINK; |
| 1441 | else |
| 1442 | CallOpc = isARMFunc ? ARMISD::CALL : ARMISD::tCALL; |
| 1443 | } else { |
| 1444 | CallOpc = (isDirect || Subtarget->hasV5TOps()) |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 1445 | ? (isLocalARMFunc ? ARMISD::CALL_PRED : ARMISD::CALL) |
| 1446 | : ARMISD::CALL_NOLINK; |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1447 | } |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1448 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1449 | std::vector<SDValue> Ops; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1450 | Ops.push_back(Chain); |
| 1451 | Ops.push_back(Callee); |
| 1452 | |
| 1453 | // Add argument registers to the end of the list so that they are known live |
| 1454 | // into the call. |
| 1455 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) |
| 1456 | Ops.push_back(DAG.getRegister(RegsToPass[i].first, |
| 1457 | RegsToPass[i].second.getValueType())); |
| 1458 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1459 | if (InFlag.getNode()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1460 | Ops.push_back(InFlag); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1461 | |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 1462 | SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue); |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1463 | if (isTailCall) |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1464 | return DAG.getNode(ARMISD::TC_RETURN, dl, NodeTys, &Ops[0], Ops.size()); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1465 | |
Duncan Sands | 4bdcb61 | 2008-07-02 17:40:58 +0000 | [diff] [blame] | 1466 | // Returns a chain and a flag for retval copy to use. |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1467 | Chain = DAG.getNode(CallOpc, dl, NodeTys, &Ops[0], Ops.size()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1468 | InFlag = Chain.getValue(1); |
| 1469 | |
Chris Lattner | e563bbc | 2008-10-11 22:08:30 +0000 | [diff] [blame] | 1470 | Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(NumBytes, true), |
| 1471 | DAG.getIntPtrConstant(0, true), InFlag); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1472 | if (!Ins.empty()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1473 | InFlag = Chain.getValue(1); |
| 1474 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1475 | // Handle result values, copying them out of physregs into vregs that we |
| 1476 | // return. |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1477 | return LowerCallResult(Chain, InFlag, CallConv, isVarArg, Ins, |
| 1478 | dl, DAG, InVals); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1479 | } |
| 1480 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1481 | /// HandleByVal - Every parameter *after* a byval parameter is passed |
| 1482 | /// on the stack. Confiscate all the parameter registers to insure |
| 1483 | /// this. |
| 1484 | void |
| 1485 | llvm::ARMTargetLowering::HandleByVal(CCState *State) const { |
| 1486 | static const unsigned RegList1[] = { |
| 1487 | ARM::R0, ARM::R1, ARM::R2, ARM::R3 |
| 1488 | }; |
| 1489 | do {} while (State->AllocateReg(RegList1, 4)); |
| 1490 | } |
| 1491 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1492 | /// MatchingStackOffset - Return true if the given stack call argument is |
| 1493 | /// already available in the same position (relatively) of the caller's |
| 1494 | /// incoming argument stack. |
| 1495 | static |
| 1496 | bool MatchingStackOffset(SDValue Arg, unsigned Offset, ISD::ArgFlagsTy Flags, |
| 1497 | MachineFrameInfo *MFI, const MachineRegisterInfo *MRI, |
| 1498 | const ARMInstrInfo *TII) { |
| 1499 | unsigned Bytes = Arg.getValueType().getSizeInBits() / 8; |
| 1500 | int FI = INT_MAX; |
| 1501 | if (Arg.getOpcode() == ISD::CopyFromReg) { |
| 1502 | unsigned VR = cast<RegisterSDNode>(Arg.getOperand(1))->getReg(); |
Jakob Stoklund Olesen | c9df025 | 2011-01-10 02:58:51 +0000 | [diff] [blame] | 1503 | if (!TargetRegisterInfo::isVirtualRegister(VR)) |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1504 | return false; |
| 1505 | MachineInstr *Def = MRI->getVRegDef(VR); |
| 1506 | if (!Def) |
| 1507 | return false; |
| 1508 | if (!Flags.isByVal()) { |
| 1509 | if (!TII->isLoadFromStackSlot(Def, FI)) |
| 1510 | return false; |
| 1511 | } else { |
Dale Johannesen | 7835f1f | 2010-07-08 01:18:23 +0000 | [diff] [blame] | 1512 | return false; |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1513 | } |
| 1514 | } else if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Arg)) { |
| 1515 | if (Flags.isByVal()) |
| 1516 | // ByVal argument is passed in as a pointer but it's now being |
| 1517 | // dereferenced. e.g. |
| 1518 | // define @foo(%struct.X* %A) { |
| 1519 | // tail call @bar(%struct.X* byval %A) |
| 1520 | // } |
| 1521 | return false; |
| 1522 | SDValue Ptr = Ld->getBasePtr(); |
| 1523 | FrameIndexSDNode *FINode = dyn_cast<FrameIndexSDNode>(Ptr); |
| 1524 | if (!FINode) |
| 1525 | return false; |
| 1526 | FI = FINode->getIndex(); |
| 1527 | } else |
| 1528 | return false; |
| 1529 | |
| 1530 | assert(FI != INT_MAX); |
| 1531 | if (!MFI->isFixedObjectIndex(FI)) |
| 1532 | return false; |
| 1533 | return Offset == MFI->getObjectOffset(FI) && Bytes == MFI->getObjectSize(FI); |
| 1534 | } |
| 1535 | |
| 1536 | /// IsEligibleForTailCallOptimization - Check whether the call is eligible |
| 1537 | /// for tail call optimization. Targets which want to do tail call |
| 1538 | /// optimization should implement this function. |
| 1539 | bool |
| 1540 | ARMTargetLowering::IsEligibleForTailCallOptimization(SDValue Callee, |
| 1541 | CallingConv::ID CalleeCC, |
| 1542 | bool isVarArg, |
| 1543 | bool isCalleeStructRet, |
| 1544 | bool isCallerStructRet, |
| 1545 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1546 | const SmallVectorImpl<SDValue> &OutVals, |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1547 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 1548 | SelectionDAG& DAG) const { |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1549 | const Function *CallerF = DAG.getMachineFunction().getFunction(); |
| 1550 | CallingConv::ID CallerCC = CallerF->getCallingConv(); |
| 1551 | bool CCMatch = CallerCC == CalleeCC; |
| 1552 | |
| 1553 | // Look for obvious safe cases to perform tail call optimization that do not |
| 1554 | // require ABI changes. This is what gcc calls sibcall. |
| 1555 | |
Jim Grosbach | 7616b64 | 2010-06-16 23:45:49 +0000 | [diff] [blame] | 1556 | // Do not sibcall optimize vararg calls unless the call site is not passing |
| 1557 | // any arguments. |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1558 | if (isVarArg && !Outs.empty()) |
| 1559 | return false; |
| 1560 | |
| 1561 | // Also avoid sibcall optimization if either caller or callee uses struct |
| 1562 | // return semantics. |
| 1563 | if (isCalleeStructRet || isCallerStructRet) |
| 1564 | return false; |
| 1565 | |
Dale Johannesen | e39fdbe | 2010-06-23 18:52:34 +0000 | [diff] [blame] | 1566 | // FIXME: Completely disable sibcall for Thumb1 since Thumb1RegisterInfo:: |
Evan Cheng | 0110ac6 | 2010-06-19 01:01:32 +0000 | [diff] [blame] | 1567 | // emitEpilogue is not ready for them. |
Dale Johannesen | 7835f1f | 2010-07-08 01:18:23 +0000 | [diff] [blame] | 1568 | // Doing this is tricky, since the LDM/POP instruction on Thumb doesn't take |
| 1569 | // LR. This means if we need to reload LR, it takes an extra instructions, |
| 1570 | // which outweighs the value of the tail call; but here we don't know yet |
| 1571 | // 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] | 1572 | // 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] | 1573 | // emitEpilogue if LR is used. |
Dale Johannesen | 7835f1f | 2010-07-08 01:18:23 +0000 | [diff] [blame] | 1574 | |
| 1575 | // Thumb1 PIC calls to external symbols use BX, so they can be tail calls, |
| 1576 | // but we need to make sure there are enough registers; the only valid |
| 1577 | // registers are the 4 used for parameters. We don't currently do this |
| 1578 | // case. |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1579 | if (Subtarget->isThumb1Only()) |
| 1580 | return false; |
Dale Johannesen | df50d7e | 2010-06-18 18:13:11 +0000 | [diff] [blame] | 1581 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1582 | // If the calling conventions do not match, then we'd better make sure the |
| 1583 | // results are returned in the same way as what the caller expects. |
| 1584 | if (!CCMatch) { |
| 1585 | SmallVector<CCValAssign, 16> RVLocs1; |
| 1586 | CCState CCInfo1(CalleeCC, false, getTargetMachine(), |
| 1587 | RVLocs1, *DAG.getContext()); |
| 1588 | CCInfo1.AnalyzeCallResult(Ins, CCAssignFnForNode(CalleeCC, true, isVarArg)); |
| 1589 | |
| 1590 | SmallVector<CCValAssign, 16> RVLocs2; |
| 1591 | CCState CCInfo2(CallerCC, false, getTargetMachine(), |
| 1592 | RVLocs2, *DAG.getContext()); |
| 1593 | CCInfo2.AnalyzeCallResult(Ins, CCAssignFnForNode(CallerCC, true, isVarArg)); |
| 1594 | |
| 1595 | if (RVLocs1.size() != RVLocs2.size()) |
| 1596 | return false; |
| 1597 | for (unsigned i = 0, e = RVLocs1.size(); i != e; ++i) { |
| 1598 | if (RVLocs1[i].isRegLoc() != RVLocs2[i].isRegLoc()) |
| 1599 | return false; |
| 1600 | if (RVLocs1[i].getLocInfo() != RVLocs2[i].getLocInfo()) |
| 1601 | return false; |
| 1602 | if (RVLocs1[i].isRegLoc()) { |
| 1603 | if (RVLocs1[i].getLocReg() != RVLocs2[i].getLocReg()) |
| 1604 | return false; |
| 1605 | } else { |
| 1606 | if (RVLocs1[i].getLocMemOffset() != RVLocs2[i].getLocMemOffset()) |
| 1607 | return false; |
| 1608 | } |
| 1609 | } |
| 1610 | } |
| 1611 | |
| 1612 | // If the callee takes no arguments then go on to check the results of the |
| 1613 | // call. |
| 1614 | if (!Outs.empty()) { |
| 1615 | // Check if stack adjustment is needed. For now, do not do this if any |
| 1616 | // argument is passed on the stack. |
| 1617 | SmallVector<CCValAssign, 16> ArgLocs; |
| 1618 | CCState CCInfo(CalleeCC, isVarArg, getTargetMachine(), |
| 1619 | ArgLocs, *DAG.getContext()); |
| 1620 | CCInfo.AnalyzeCallOperands(Outs, |
| 1621 | CCAssignFnForNode(CalleeCC, false, isVarArg)); |
| 1622 | if (CCInfo.getNextStackOffset()) { |
| 1623 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1624 | |
| 1625 | // Check if the arguments are already laid out in the right way as |
| 1626 | // the caller's fixed stack objects. |
| 1627 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 1628 | const MachineRegisterInfo *MRI = &MF.getRegInfo(); |
| 1629 | const ARMInstrInfo *TII = |
| 1630 | ((ARMTargetMachine&)getTargetMachine()).getInstrInfo(); |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1631 | for (unsigned i = 0, realArgIdx = 0, e = ArgLocs.size(); |
| 1632 | i != e; |
| 1633 | ++i, ++realArgIdx) { |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1634 | CCValAssign &VA = ArgLocs[i]; |
| 1635 | EVT RegVT = VA.getLocVT(); |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1636 | SDValue Arg = OutVals[realArgIdx]; |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1637 | ISD::ArgFlagsTy Flags = Outs[realArgIdx].Flags; |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1638 | if (VA.getLocInfo() == CCValAssign::Indirect) |
| 1639 | return false; |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1640 | if (VA.needsCustom()) { |
| 1641 | // f64 and vector types are split into multiple registers or |
| 1642 | // register/stack-slot combinations. The types will not match |
| 1643 | // the registers; give up on memory f64 refs until we figure |
| 1644 | // out what to do about this. |
| 1645 | if (!VA.isRegLoc()) |
| 1646 | return false; |
| 1647 | if (!ArgLocs[++i].isRegLoc()) |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 1648 | return false; |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1649 | if (RegVT == MVT::v2f64) { |
| 1650 | if (!ArgLocs[++i].isRegLoc()) |
| 1651 | return false; |
| 1652 | if (!ArgLocs[++i].isRegLoc()) |
| 1653 | return false; |
| 1654 | } |
| 1655 | } else if (!VA.isRegLoc()) { |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1656 | if (!MatchingStackOffset(Arg, VA.getLocMemOffset(), Flags, |
| 1657 | MFI, MRI, TII)) |
| 1658 | return false; |
| 1659 | } |
| 1660 | } |
| 1661 | } |
| 1662 | } |
| 1663 | |
| 1664 | return true; |
| 1665 | } |
| 1666 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1667 | SDValue |
| 1668 | ARMTargetLowering::LowerReturn(SDValue Chain, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1669 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1670 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1671 | const SmallVectorImpl<SDValue> &OutVals, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1672 | DebugLoc dl, SelectionDAG &DAG) const { |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1673 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1674 | // CCValAssign - represent the assignment of the return value to a location. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1675 | SmallVector<CCValAssign, 16> RVLocs; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1676 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1677 | // CCState - Info about the registers and stack slots. |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1678 | CCState CCInfo(CallConv, isVarArg, getTargetMachine(), RVLocs, |
| 1679 | *DAG.getContext()); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1680 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1681 | // Analyze outgoing return values. |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1682 | CCInfo.AnalyzeReturn(Outs, CCAssignFnForNode(CallConv, /* Return */ true, |
| 1683 | isVarArg)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1684 | |
| 1685 | // If this is the first return lowered for this function, add |
| 1686 | // the regs to the liveout set for the function. |
| 1687 | if (DAG.getMachineFunction().getRegInfo().liveout_empty()) { |
| 1688 | for (unsigned i = 0; i != RVLocs.size(); ++i) |
| 1689 | if (RVLocs[i].isRegLoc()) |
| 1690 | DAG.getMachineFunction().getRegInfo().addLiveOut(RVLocs[i].getLocReg()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1691 | } |
| 1692 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1693 | SDValue Flag; |
| 1694 | |
| 1695 | // Copy the result values into the output registers. |
| 1696 | for (unsigned i = 0, realRVLocIdx = 0; |
| 1697 | i != RVLocs.size(); |
| 1698 | ++i, ++realRVLocIdx) { |
| 1699 | CCValAssign &VA = RVLocs[i]; |
| 1700 | assert(VA.isRegLoc() && "Can only return in registers!"); |
| 1701 | |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1702 | SDValue Arg = OutVals[realRVLocIdx]; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1703 | |
| 1704 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1705 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1706 | case CCValAssign::Full: break; |
| 1707 | case CCValAssign::BCvt: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1708 | Arg = DAG.getNode(ISD::BITCAST, dl, VA.getLocVT(), Arg); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1709 | break; |
| 1710 | } |
| 1711 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1712 | if (VA.needsCustom()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1713 | if (VA.getLocVT() == MVT::v2f64) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1714 | // Extract the first half and return it in two registers. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1715 | SDValue Half = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1716 | DAG.getConstant(0, MVT::i32)); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1717 | SDValue HalfGPRs = DAG.getNode(ARMISD::VMOVRRD, dl, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1718 | DAG.getVTList(MVT::i32, MVT::i32), Half); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1719 | |
| 1720 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), HalfGPRs, Flag); |
| 1721 | Flag = Chain.getValue(1); |
| 1722 | VA = RVLocs[++i]; // skip ahead to next loc |
| 1723 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), |
| 1724 | HalfGPRs.getValue(1), Flag); |
| 1725 | Flag = Chain.getValue(1); |
| 1726 | VA = RVLocs[++i]; // skip ahead to next loc |
| 1727 | |
| 1728 | // 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] | 1729 | Arg = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1730 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1731 | } |
| 1732 | // Legalize ret f64 -> ret 2 x i32. We always have fmrrd if f64 is |
| 1733 | // available. |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1734 | SDValue fmrrd = DAG.getNode(ARMISD::VMOVRRD, dl, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1735 | DAG.getVTList(MVT::i32, MVT::i32), &Arg, 1); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1736 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), fmrrd, Flag); |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1737 | Flag = Chain.getValue(1); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1738 | VA = RVLocs[++i]; // skip ahead to next loc |
| 1739 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), fmrrd.getValue(1), |
| 1740 | Flag); |
| 1741 | } else |
| 1742 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), Arg, Flag); |
| 1743 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1744 | // Guarantee that all emitted copies are |
| 1745 | // stuck together, avoiding something bad. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1746 | Flag = Chain.getValue(1); |
| 1747 | } |
| 1748 | |
| 1749 | SDValue result; |
| 1750 | if (Flag.getNode()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1751 | result = DAG.getNode(ARMISD::RET_FLAG, dl, MVT::Other, Chain, Flag); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1752 | else // Return Void |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1753 | result = DAG.getNode(ARMISD::RET_FLAG, dl, MVT::Other, Chain); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1754 | |
| 1755 | return result; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1756 | } |
| 1757 | |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1758 | bool ARMTargetLowering::isUsedByReturnOnly(SDNode *N) const { |
| 1759 | if (N->getNumValues() != 1) |
| 1760 | return false; |
| 1761 | if (!N->hasNUsesOfValue(1, 0)) |
| 1762 | return false; |
| 1763 | |
| 1764 | unsigned NumCopies = 0; |
| 1765 | SDNode* Copies[2]; |
| 1766 | SDNode *Use = *N->use_begin(); |
| 1767 | if (Use->getOpcode() == ISD::CopyToReg) { |
| 1768 | Copies[NumCopies++] = Use; |
| 1769 | } else if (Use->getOpcode() == ARMISD::VMOVRRD) { |
| 1770 | // f64 returned in a pair of GPRs. |
| 1771 | for (SDNode::use_iterator UI = Use->use_begin(), UE = Use->use_end(); |
| 1772 | UI != UE; ++UI) { |
| 1773 | if (UI->getOpcode() != ISD::CopyToReg) |
| 1774 | return false; |
| 1775 | Copies[UI.getUse().getResNo()] = *UI; |
| 1776 | ++NumCopies; |
| 1777 | } |
| 1778 | } else if (Use->getOpcode() == ISD::BITCAST) { |
| 1779 | // f32 returned in a single GPR. |
| 1780 | if (!Use->hasNUsesOfValue(1, 0)) |
| 1781 | return false; |
| 1782 | Use = *Use->use_begin(); |
| 1783 | if (Use->getOpcode() != ISD::CopyToReg || !Use->hasNUsesOfValue(1, 0)) |
| 1784 | return false; |
| 1785 | Copies[NumCopies++] = Use; |
| 1786 | } else { |
| 1787 | return false; |
| 1788 | } |
| 1789 | |
| 1790 | if (NumCopies != 1 && NumCopies != 2) |
| 1791 | return false; |
Evan Cheng | 1bf891a | 2010-12-01 22:59:46 +0000 | [diff] [blame] | 1792 | |
| 1793 | bool HasRet = false; |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1794 | for (unsigned i = 0; i < NumCopies; ++i) { |
| 1795 | SDNode *Copy = Copies[i]; |
| 1796 | for (SDNode::use_iterator UI = Copy->use_begin(), UE = Copy->use_end(); |
| 1797 | UI != UE; ++UI) { |
| 1798 | if (UI->getOpcode() == ISD::CopyToReg) { |
| 1799 | SDNode *Use = *UI; |
| 1800 | if (Use == Copies[0] || Use == Copies[1]) |
| 1801 | continue; |
| 1802 | return false; |
| 1803 | } |
| 1804 | if (UI->getOpcode() != ARMISD::RET_FLAG) |
| 1805 | return false; |
Evan Cheng | 1bf891a | 2010-12-01 22:59:46 +0000 | [diff] [blame] | 1806 | HasRet = true; |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1807 | } |
| 1808 | } |
| 1809 | |
Evan Cheng | 1bf891a | 2010-12-01 22:59:46 +0000 | [diff] [blame] | 1810 | return HasRet; |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1811 | } |
| 1812 | |
Evan Cheng | 485fafc | 2011-03-21 01:19:09 +0000 | [diff] [blame] | 1813 | bool ARMTargetLowering::mayBeEmittedAsTailCall(CallInst *CI) const { |
| 1814 | if (!EnableARMTailCalls) |
| 1815 | return false; |
| 1816 | |
| 1817 | if (!CI->isTailCall()) |
| 1818 | return false; |
| 1819 | |
| 1820 | return !Subtarget->isThumb1Only(); |
| 1821 | } |
| 1822 | |
Bob Wilson | b62d257 | 2009-11-03 00:02:05 +0000 | [diff] [blame] | 1823 | // ConstantPool, JumpTable, GlobalAddress, and ExternalSymbol are lowered as |
| 1824 | // their target counterpart wrapped in the ARMISD::Wrapper node. Suppose N is |
| 1825 | // one of the above mentioned nodes. It has to be wrapped because otherwise |
| 1826 | // Select(N) returns N. So the raw TargetGlobalAddress nodes, etc. can only |
| 1827 | // be used to form addressing mode. These wrapped nodes will be selected |
| 1828 | // into MOVi. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1829 | static SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1830 | EVT PtrVT = Op.getValueType(); |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 1831 | // FIXME there is no actual debug info here |
| 1832 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1833 | ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1834 | SDValue Res; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1835 | if (CP->isMachineConstantPoolEntry()) |
| 1836 | Res = DAG.getTargetConstantPool(CP->getMachineCPVal(), PtrVT, |
| 1837 | CP->getAlignment()); |
| 1838 | else |
| 1839 | Res = DAG.getTargetConstantPool(CP->getConstVal(), PtrVT, |
| 1840 | CP->getAlignment()); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1841 | return DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Res); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1842 | } |
| 1843 | |
Jim Grosbach | e1102ca | 2010-07-19 17:20:38 +0000 | [diff] [blame] | 1844 | unsigned ARMTargetLowering::getJumpTableEncoding() const { |
| 1845 | return MachineJumpTableInfo::EK_Inline; |
| 1846 | } |
| 1847 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1848 | SDValue ARMTargetLowering::LowerBlockAddress(SDValue Op, |
| 1849 | SelectionDAG &DAG) const { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1850 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1851 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 1852 | unsigned ARMPCLabelIndex = 0; |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 1853 | DebugLoc DL = Op.getDebugLoc(); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 1854 | EVT PtrVT = getPointerTy(); |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 1855 | const BlockAddress *BA = cast<BlockAddressSDNode>(Op)->getBlockAddress(); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 1856 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| 1857 | SDValue CPAddr; |
| 1858 | if (RelocM == Reloc::Static) { |
| 1859 | CPAddr = DAG.getTargetConstantPool(BA, PtrVT, 4); |
| 1860 | } else { |
| 1861 | unsigned PCAdj = Subtarget->isThumb() ? 4 : 8; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1862 | ARMPCLabelIndex = AFI->createPICLabelUId(); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 1863 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(BA, ARMPCLabelIndex, |
| 1864 | ARMCP::CPBlockAddress, |
| 1865 | PCAdj); |
| 1866 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
| 1867 | } |
| 1868 | CPAddr = DAG.getNode(ARMISD::Wrapper, DL, PtrVT, CPAddr); |
| 1869 | SDValue Result = DAG.getLoad(PtrVT, DL, DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1870 | MachinePointerInfo::getConstantPool(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1871 | false, false, 0); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 1872 | if (RelocM == Reloc::Static) |
| 1873 | return Result; |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1874 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 1875 | return DAG.getNode(ARMISD::PIC_ADD, DL, PtrVT, Result, PICLabel); |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 1876 | } |
| 1877 | |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1878 | // Lower ISD::GlobalTLSAddress using the "general dynamic" model |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1879 | SDValue |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1880 | ARMTargetLowering::LowerToTLSGeneralDynamicModel(GlobalAddressSDNode *GA, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1881 | SelectionDAG &DAG) const { |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1882 | DebugLoc dl = GA->getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1883 | EVT PtrVT = getPointerTy(); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1884 | unsigned char PCAdj = Subtarget->isThumb() ? 4 : 8; |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1885 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1886 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1887 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1888 | ARMConstantPoolValue *CPV = |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 1889 | new ARMConstantPoolValue(GA->getGlobal(), ARMPCLabelIndex, |
Jim Grosbach | 3a2429a | 2010-11-09 21:36:17 +0000 | [diff] [blame] | 1890 | ARMCP::CPValue, PCAdj, ARMCP::TLSGD, true); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1891 | SDValue Argument = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1892 | Argument = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Argument); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1893 | Argument = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Argument, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1894 | MachinePointerInfo::getConstantPool(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1895 | false, false, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1896 | SDValue Chain = Argument.getValue(1); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1897 | |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1898 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1899 | Argument = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Argument, PICLabel); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1900 | |
| 1901 | // call __tls_get_addr. |
| 1902 | ArgListTy Args; |
| 1903 | ArgListEntry Entry; |
| 1904 | Entry.Node = Argument; |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 1905 | Entry.Ty = (const Type *) Type::getInt32Ty(*DAG.getContext()); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1906 | Args.push_back(Entry); |
Dale Johannesen | 7d2ad62 | 2009-01-30 23:10:59 +0000 | [diff] [blame] | 1907 | // FIXME: is there useful debug info available here? |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1908 | std::pair<SDValue, SDValue> CallResult = |
Evan Cheng | 59bc060 | 2009-08-14 19:11:20 +0000 | [diff] [blame] | 1909 | LowerCallTo(Chain, (const Type *) Type::getInt32Ty(*DAG.getContext()), |
| 1910 | false, false, false, false, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1911 | 0, CallingConv::C, false, /*isReturnValueUsed=*/true, |
Bill Wendling | 46ada19 | 2010-03-02 01:55:18 +0000 | [diff] [blame] | 1912 | DAG.getExternalSymbol("__tls_get_addr", PtrVT), Args, DAG, dl); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1913 | return CallResult.first; |
| 1914 | } |
| 1915 | |
| 1916 | // Lower ISD::GlobalTLSAddress using the "initial exec" or |
| 1917 | // "local exec" model. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1918 | SDValue |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1919 | ARMTargetLowering::LowerToTLSExecModels(GlobalAddressSDNode *GA, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1920 | SelectionDAG &DAG) const { |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 1921 | const GlobalValue *GV = GA->getGlobal(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1922 | DebugLoc dl = GA->getDebugLoc(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1923 | SDValue Offset; |
| 1924 | SDValue Chain = DAG.getEntryNode(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1925 | EVT PtrVT = getPointerTy(); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1926 | // Get the Thread Pointer |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1927 | SDValue ThreadPointer = DAG.getNode(ARMISD::THREAD_POINTER, dl, PtrVT); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1928 | |
Chris Lattner | 4fb63d0 | 2009-07-15 04:12:33 +0000 | [diff] [blame] | 1929 | if (GV->isDeclaration()) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1930 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1931 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1932 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1933 | // Initial exec model. |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1934 | unsigned char PCAdj = Subtarget->isThumb() ? 4 : 8; |
| 1935 | ARMConstantPoolValue *CPV = |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 1936 | new ARMConstantPoolValue(GA->getGlobal(), ARMPCLabelIndex, |
Jim Grosbach | 3a2429a | 2010-11-09 21:36:17 +0000 | [diff] [blame] | 1937 | ARMCP::CPValue, PCAdj, ARMCP::GOTTPOFF, true); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1938 | Offset = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1939 | Offset = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Offset); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1940 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1941 | MachinePointerInfo::getConstantPool(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1942 | false, false, 0); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1943 | Chain = Offset.getValue(1); |
| 1944 | |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1945 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1946 | Offset = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Offset, PICLabel); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1947 | |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1948 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, |
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); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1951 | } else { |
| 1952 | // local exec model |
Jim Grosbach | 3a2429a | 2010-11-09 21:36:17 +0000 | [diff] [blame] | 1953 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GV, ARMCP::TPOFF); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1954 | Offset = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1955 | Offset = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Offset); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1956 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1957 | MachinePointerInfo::getConstantPool(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1958 | false, false, 0); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1959 | } |
| 1960 | |
| 1961 | // The address of the thread local variable is the add of the thread |
| 1962 | // pointer with the offset of the variable. |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1963 | return DAG.getNode(ISD::ADD, dl, PtrVT, ThreadPointer, Offset); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1964 | } |
| 1965 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1966 | SDValue |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1967 | ARMTargetLowering::LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const { |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1968 | // TODO: implement the "local dynamic" model |
| 1969 | assert(Subtarget->isTargetELF() && |
| 1970 | "TLS not implemented for non-ELF targets"); |
| 1971 | GlobalAddressSDNode *GA = cast<GlobalAddressSDNode>(Op); |
| 1972 | // If the relocation model is PIC, use the "General Dynamic" TLS Model, |
| 1973 | // otherwise use the "Local Exec" TLS Model |
| 1974 | if (getTargetMachine().getRelocationModel() == Reloc::PIC_) |
| 1975 | return LowerToTLSGeneralDynamicModel(GA, DAG); |
| 1976 | else |
| 1977 | return LowerToTLSExecModels(GA, DAG); |
| 1978 | } |
| 1979 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1980 | SDValue ARMTargetLowering::LowerGlobalAddressELF(SDValue Op, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1981 | SelectionDAG &DAG) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1982 | EVT PtrVT = getPointerTy(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1983 | DebugLoc dl = Op.getDebugLoc(); |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 1984 | const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 1985 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| 1986 | if (RelocM == Reloc::PIC_) { |
Rafael Espindola | bb46f52 | 2009-01-15 20:18:42 +0000 | [diff] [blame] | 1987 | bool UseGOTOFF = GV->hasLocalLinkage() || GV->hasHiddenVisibility(); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 1988 | ARMConstantPoolValue *CPV = |
Jim Grosbach | 3a2429a | 2010-11-09 21:36:17 +0000 | [diff] [blame] | 1989 | new ARMConstantPoolValue(GV, UseGOTOFF ? ARMCP::GOTOFF : ARMCP::GOT); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1990 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1991 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1992 | SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 1993 | CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1994 | MachinePointerInfo::getConstantPool(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1995 | false, false, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1996 | SDValue Chain = Result.getValue(1); |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 1997 | SDValue GOT = DAG.getGLOBAL_OFFSET_TABLE(PtrVT); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1998 | Result = DAG.getNode(ISD::ADD, dl, PtrVT, Result, GOT); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 1999 | if (!UseGOTOFF) |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 2000 | Result = DAG.getLoad(PtrVT, dl, Chain, Result, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2001 | MachinePointerInfo::getGOT(), false, false, 0); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2002 | return Result; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2003 | } |
| 2004 | |
| 2005 | // If we have T2 ops, we can materialize the address directly via movt/movw |
| 2006 | // pair. This is always cheaper. |
| 2007 | if (Subtarget->useMovt()) { |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2008 | ++NumMovwMovt; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2009 | // FIXME: Once remat is capable of dealing with instructions with register |
| 2010 | // operands, expand this into two nodes. |
| 2011 | return DAG.getNode(ARMISD::Wrapper, dl, PtrVT, |
| 2012 | DAG.getTargetGlobalAddress(GV, dl, PtrVT)); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2013 | } else { |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2014 | SDValue CPAddr = DAG.getTargetConstantPool(GV, PtrVT, 4); |
| 2015 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| 2016 | return DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
| 2017 | MachinePointerInfo::getConstantPool(), |
| 2018 | false, false, 0); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2019 | } |
| 2020 | } |
| 2021 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2022 | SDValue ARMTargetLowering::LowerGlobalAddressDarwin(SDValue Op, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2023 | SelectionDAG &DAG) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2024 | EVT PtrVT = getPointerTy(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2025 | DebugLoc dl = Op.getDebugLoc(); |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2026 | const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2027 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2028 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2029 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2030 | |
| 2031 | if (Subtarget->useMovt()) { |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2032 | ++NumMovwMovt; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2033 | // FIXME: Once remat is capable of dealing with instructions with register |
| 2034 | // operands, expand this into two nodes. |
Evan Cheng | 53519f0 | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 2035 | if (RelocM == Reloc::Static) |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2036 | return DAG.getNode(ARMISD::Wrapper, dl, PtrVT, |
| 2037 | DAG.getTargetGlobalAddress(GV, dl, PtrVT)); |
| 2038 | |
Evan Cheng | 53519f0 | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 2039 | unsigned Wrapper = (RelocM == Reloc::PIC_) |
| 2040 | ? ARMISD::WrapperPIC : ARMISD::WrapperDYN; |
| 2041 | SDValue Result = DAG.getNode(Wrapper, dl, PtrVT, |
Evan Cheng | 9fe2009 | 2011-01-20 08:34:58 +0000 | [diff] [blame] | 2042 | DAG.getTargetGlobalAddress(GV, dl, PtrVT)); |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2043 | if (Subtarget->GVIsIndirectSymbol(GV, RelocM)) |
| 2044 | Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Result, |
| 2045 | MachinePointerInfo::getGOT(), false, false, 0); |
| 2046 | return Result; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2047 | } |
| 2048 | |
| 2049 | unsigned ARMPCLabelIndex = 0; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2050 | SDValue CPAddr; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2051 | if (RelocM == Reloc::Static) { |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2052 | CPAddr = DAG.getTargetConstantPool(GV, PtrVT, 4); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2053 | } else { |
| 2054 | ARMPCLabelIndex = AFI->createPICLabelUId(); |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 2055 | unsigned PCAdj = (RelocM != Reloc::PIC_) ? 0 : (Subtarget->isThumb()?4:8); |
| 2056 | ARMConstantPoolValue *CPV = |
Jim Grosbach | 3fb2b1e | 2009-09-01 01:57:56 +0000 | [diff] [blame] | 2057 | new ARMConstantPoolValue(GV, ARMPCLabelIndex, ARMCP::CPValue, PCAdj); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2058 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2059 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2060 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2061 | |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2062 | SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2063 | MachinePointerInfo::getConstantPool(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 2064 | false, false, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2065 | SDValue Chain = Result.getValue(1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2066 | |
| 2067 | if (RelocM == Reloc::PIC_) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2068 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2069 | Result = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2070 | } |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 2071 | |
Evan Cheng | 63476a8 | 2009-09-03 07:04:02 +0000 | [diff] [blame] | 2072 | if (Subtarget->GVIsIndirectSymbol(GV, RelocM)) |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2073 | Result = DAG.getLoad(PtrVT, dl, Chain, Result, MachinePointerInfo::getGOT(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 2074 | false, false, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2075 | |
| 2076 | return Result; |
| 2077 | } |
| 2078 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2079 | SDValue ARMTargetLowering::LowerGLOBAL_OFFSET_TABLE(SDValue Op, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2080 | SelectionDAG &DAG) const { |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2081 | assert(Subtarget->isTargetELF() && |
| 2082 | "GLOBAL OFFSET TABLE not implemented for non-ELF targets"); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2083 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2084 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2085 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2086 | EVT PtrVT = getPointerTy(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2087 | DebugLoc dl = Op.getDebugLoc(); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2088 | unsigned PCAdj = Subtarget->isThumb() ? 4 : 8; |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 2089 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(*DAG.getContext(), |
| 2090 | "_GLOBAL_OFFSET_TABLE_", |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 2091 | ARMPCLabelIndex, PCAdj); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2092 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2093 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 2094 | SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2095 | MachinePointerInfo::getConstantPool(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 2096 | false, false, 0); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2097 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2098 | return DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2099 | } |
| 2100 | |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 2101 | SDValue |
Jim Grosbach | e4ad387 | 2010-10-19 23:27:08 +0000 | [diff] [blame] | 2102 | ARMTargetLowering::LowerEH_SJLJ_DISPATCHSETUP(SDValue Op, SelectionDAG &DAG) |
| 2103 | const { |
| 2104 | DebugLoc dl = Op.getDebugLoc(); |
| 2105 | return DAG.getNode(ARMISD::EH_SJLJ_DISPATCHSETUP, dl, MVT::Other, |
| 2106 | Op.getOperand(0), Op.getOperand(1)); |
| 2107 | } |
| 2108 | |
| 2109 | SDValue |
Jim Grosbach | 23ff7cf | 2010-05-26 20:22:18 +0000 | [diff] [blame] | 2110 | ARMTargetLowering::LowerEH_SJLJ_SETJMP(SDValue Op, SelectionDAG &DAG) const { |
| 2111 | DebugLoc dl = Op.getDebugLoc(); |
Jim Grosbach | 0798edd | 2010-05-27 23:49:24 +0000 | [diff] [blame] | 2112 | SDValue Val = DAG.getConstant(0, MVT::i32); |
Jim Grosbach | 23ff7cf | 2010-05-26 20:22:18 +0000 | [diff] [blame] | 2113 | return DAG.getNode(ARMISD::EH_SJLJ_SETJMP, dl, MVT::i32, Op.getOperand(0), |
| 2114 | Op.getOperand(1), Val); |
| 2115 | } |
| 2116 | |
| 2117 | SDValue |
Jim Grosbach | 5eb1951 | 2010-05-22 01:06:18 +0000 | [diff] [blame] | 2118 | ARMTargetLowering::LowerEH_SJLJ_LONGJMP(SDValue Op, SelectionDAG &DAG) const { |
| 2119 | DebugLoc dl = Op.getDebugLoc(); |
| 2120 | return DAG.getNode(ARMISD::EH_SJLJ_LONGJMP, dl, MVT::Other, Op.getOperand(0), |
| 2121 | Op.getOperand(1), DAG.getConstant(0, MVT::i32)); |
| 2122 | } |
| 2123 | |
| 2124 | SDValue |
Jim Grosbach | a87ded2 | 2010-02-08 23:22:00 +0000 | [diff] [blame] | 2125 | ARMTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG, |
Jim Grosbach | 7616b64 | 2010-06-16 23:45:49 +0000 | [diff] [blame] | 2126 | const ARMSubtarget *Subtarget) const { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2127 | unsigned IntNo = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 2128 | DebugLoc dl = Op.getDebugLoc(); |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 2129 | switch (IntNo) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2130 | default: return SDValue(); // Don't custom lower most intrinsics. |
Bob Wilson | 916afdb | 2009-08-04 00:25:01 +0000 | [diff] [blame] | 2131 | case Intrinsic::arm_thread_pointer: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2132 | EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
Bob Wilson | 916afdb | 2009-08-04 00:25:01 +0000 | [diff] [blame] | 2133 | return DAG.getNode(ARMISD::THREAD_POINTER, dl, PtrVT); |
| 2134 | } |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2135 | case Intrinsic::eh_sjlj_lsda: { |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2136 | MachineFunction &MF = DAG.getMachineFunction(); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2137 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2138 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2139 | EVT PtrVT = getPointerTy(); |
| 2140 | DebugLoc dl = Op.getDebugLoc(); |
| 2141 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| 2142 | SDValue CPAddr; |
| 2143 | unsigned PCAdj = (RelocM != Reloc::PIC_) |
| 2144 | ? 0 : (Subtarget->isThumb() ? 4 : 8); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2145 | ARMConstantPoolValue *CPV = |
Jim Grosbach | 3fb2b1e | 2009-09-01 01:57:56 +0000 | [diff] [blame] | 2146 | new ARMConstantPoolValue(MF.getFunction(), ARMPCLabelIndex, |
| 2147 | ARMCP::CPLSDA, PCAdj); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2148 | 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); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2150 | SDValue Result = |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2151 | DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2152 | MachinePointerInfo::getConstantPool(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 2153 | false, false, 0); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2154 | |
| 2155 | if (RelocM == Reloc::PIC_) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2156 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2157 | Result = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
| 2158 | } |
| 2159 | return Result; |
| 2160 | } |
Evan Cheng | 92e3916 | 2011-03-29 23:06:19 +0000 | [diff] [blame] | 2161 | case Intrinsic::arm_neon_vmulls: |
| 2162 | case Intrinsic::arm_neon_vmullu: { |
| 2163 | unsigned NewOpc = (IntNo == Intrinsic::arm_neon_vmulls) |
| 2164 | ? ARMISD::VMULLs : ARMISD::VMULLu; |
| 2165 | return DAG.getNode(NewOpc, Op.getDebugLoc(), Op.getValueType(), |
| 2166 | Op.getOperand(1), Op.getOperand(2)); |
| 2167 | } |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 2168 | } |
| 2169 | } |
| 2170 | |
Jim Grosbach | 7c03dbd | 2009-12-14 21:24:16 +0000 | [diff] [blame] | 2171 | static SDValue LowerMEMBARRIER(SDValue Op, SelectionDAG &DAG, |
Jim Grosbach | 7616b64 | 2010-06-16 23:45:49 +0000 | [diff] [blame] | 2172 | const ARMSubtarget *Subtarget) { |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 2173 | DebugLoc dl = Op.getDebugLoc(); |
Bob Wilson | f74a429 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 2174 | if (!Subtarget->hasDataBarrier()) { |
| 2175 | // Some ARMv6 cpus can support data barriers with an mcr instruction. |
| 2176 | // Thumb1 and pre-v6 ARM mode use a libcall instead and should never get |
| 2177 | // here. |
Bob Wilson | 54f9256 | 2010-11-09 22:50:44 +0000 | [diff] [blame] | 2178 | assert(Subtarget->hasV6Ops() && !Subtarget->isThumb() && |
Evan Cheng | 11db068 | 2010-08-11 06:22:01 +0000 | [diff] [blame] | 2179 | "Unexpected ISD::MEMBARRIER encountered. Should be libcall!"); |
Bob Wilson | f74a429 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 2180 | return DAG.getNode(ARMISD::MEMBARRIER_MCR, dl, MVT::Other, Op.getOperand(0), |
Jim Grosbach | c73993b | 2010-06-17 01:37:00 +0000 | [diff] [blame] | 2181 | DAG.getConstant(0, MVT::i32)); |
Evan Cheng | 11db068 | 2010-08-11 06:22:01 +0000 | [diff] [blame] | 2182 | } |
Bob Wilson | f74a429 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 2183 | |
| 2184 | SDValue Op5 = Op.getOperand(5); |
| 2185 | bool isDeviceBarrier = cast<ConstantSDNode>(Op5)->getZExtValue() != 0; |
| 2186 | unsigned isLL = cast<ConstantSDNode>(Op.getOperand(1))->getZExtValue(); |
| 2187 | unsigned isLS = cast<ConstantSDNode>(Op.getOperand(2))->getZExtValue(); |
| 2188 | bool isOnlyStoreBarrier = (isLL == 0 && isLS == 0); |
| 2189 | |
| 2190 | ARM_MB::MemBOpt DMBOpt; |
| 2191 | if (isDeviceBarrier) |
| 2192 | DMBOpt = isOnlyStoreBarrier ? ARM_MB::ST : ARM_MB::SY; |
| 2193 | else |
| 2194 | DMBOpt = isOnlyStoreBarrier ? ARM_MB::ISHST : ARM_MB::ISH; |
| 2195 | return DAG.getNode(ARMISD::MEMBARRIER, dl, MVT::Other, Op.getOperand(0), |
| 2196 | DAG.getConstant(DMBOpt, MVT::i32)); |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 2197 | } |
| 2198 | |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2199 | static SDValue LowerPREFETCH(SDValue Op, SelectionDAG &DAG, |
| 2200 | const ARMSubtarget *Subtarget) { |
| 2201 | // ARM pre v5TE and Thumb1 does not have preload instructions. |
| 2202 | if (!(Subtarget->isThumb2() || |
| 2203 | (!Subtarget->isThumb1Only() && Subtarget->hasV5TEOps()))) |
| 2204 | // Just preserve the chain. |
| 2205 | return Op.getOperand(0); |
| 2206 | |
| 2207 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 2208 | unsigned isRead = ~cast<ConstantSDNode>(Op.getOperand(2))->getZExtValue() & 1; |
| 2209 | if (!isRead && |
| 2210 | (!Subtarget->hasV7Ops() || !Subtarget->hasMPExtension())) |
| 2211 | // ARMv7 with MP extension has PLDW. |
| 2212 | return Op.getOperand(0); |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2213 | |
| 2214 | if (Subtarget->isThumb()) |
| 2215 | // Invert the bits. |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 2216 | isRead = ~isRead & 1; |
| 2217 | unsigned isData = Subtarget->isThumb() ? 0 : 1; |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2218 | |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 2219 | // Currently there is no intrinsic that matches pli. |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2220 | return DAG.getNode(ARMISD::PRELOAD, dl, MVT::Other, Op.getOperand(0), |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 2221 | Op.getOperand(1), DAG.getConstant(isRead, MVT::i32), |
| 2222 | DAG.getConstant(isData, MVT::i32)); |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2223 | } |
| 2224 | |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 2225 | static SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) { |
| 2226 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2227 | ARMFunctionInfo *FuncInfo = MF.getInfo<ARMFunctionInfo>(); |
| 2228 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2229 | // vastart just stores the address of the VarArgsFrameIndex slot into the |
| 2230 | // memory location argument. |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2231 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2232 | EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 2233 | SDValue FR = DAG.getFrameIndex(FuncInfo->getVarArgsFrameIndex(), PtrVT); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 2234 | const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue(); |
Chris Lattner | fc448ff | 2010-09-21 18:51:21 +0000 | [diff] [blame] | 2235 | return DAG.getStore(Op.getOperand(0), dl, FR, Op.getOperand(1), |
| 2236 | MachinePointerInfo(SV), false, false, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2237 | } |
| 2238 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2239 | SDValue |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2240 | ARMTargetLowering::GetF64FormalArgument(CCValAssign &VA, CCValAssign &NextVA, |
| 2241 | SDValue &Root, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2242 | DebugLoc dl) const { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2243 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2244 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2245 | |
| 2246 | TargetRegisterClass *RC; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 2247 | if (AFI->isThumb1OnlyFunction()) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2248 | RC = ARM::tGPRRegisterClass; |
| 2249 | else |
| 2250 | RC = ARM::GPRRegisterClass; |
| 2251 | |
| 2252 | // Transform the arguments stored in physical registers into virtual ones. |
Devang Patel | 68e6bee | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 2253 | unsigned Reg = MF.addLiveIn(VA.getLocReg(), RC); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2254 | SDValue ArgValue = DAG.getCopyFromReg(Root, dl, Reg, MVT::i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2255 | |
| 2256 | SDValue ArgValue2; |
| 2257 | if (NextVA.isMemLoc()) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2258 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
Evan Cheng | ed2ae13 | 2010-07-03 00:40:23 +0000 | [diff] [blame] | 2259 | int FI = MFI->CreateFixedObject(4, NextVA.getLocMemOffset(), true); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2260 | |
| 2261 | // Create load node to retrieve arguments from the stack. |
| 2262 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2263 | ArgValue2 = DAG.getLoad(MVT::i32, dl, Root, FIN, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2264 | MachinePointerInfo::getFixedStack(FI), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 2265 | false, false, 0); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2266 | } else { |
Devang Patel | 68e6bee | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 2267 | Reg = MF.addLiveIn(NextVA.getLocReg(), RC); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2268 | ArgValue2 = DAG.getCopyFromReg(Root, dl, Reg, MVT::i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2269 | } |
| 2270 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 2271 | return DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, ArgValue, ArgValue2); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2272 | } |
| 2273 | |
| 2274 | SDValue |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2275 | ARMTargetLowering::LowerFormalArguments(SDValue Chain, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 2276 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2277 | const SmallVectorImpl<ISD::InputArg> |
| 2278 | &Ins, |
| 2279 | DebugLoc dl, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2280 | SmallVectorImpl<SDValue> &InVals) |
| 2281 | const { |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2282 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2283 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2284 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 2285 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2286 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2287 | |
| 2288 | // Assign locations to all of the incoming arguments. |
| 2289 | SmallVector<CCValAssign, 16> ArgLocs; |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2290 | CCState CCInfo(CallConv, isVarArg, getTargetMachine(), ArgLocs, |
| 2291 | *DAG.getContext()); |
| 2292 | CCInfo.AnalyzeFormalArguments(Ins, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 2293 | CCAssignFnForNode(CallConv, /* Return*/ false, |
| 2294 | isVarArg)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2295 | |
| 2296 | SmallVector<SDValue, 16> ArgValues; |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2297 | int lastInsIndex = -1; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2298 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2299 | SDValue ArgValue; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2300 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| 2301 | CCValAssign &VA = ArgLocs[i]; |
| 2302 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 2303 | // Arguments stored in registers. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2304 | if (VA.isRegLoc()) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2305 | EVT RegVT = VA.getLocVT(); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2306 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2307 | if (VA.needsCustom()) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2308 | // f64 and vector types are split up into multiple registers or |
| 2309 | // combinations of registers and stack slots. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2310 | if (VA.getLocVT() == MVT::v2f64) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2311 | SDValue ArgValue1 = GetF64FormalArgument(VA, ArgLocs[++i], |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2312 | Chain, DAG, dl); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2313 | VA = ArgLocs[++i]; // skip ahead to next loc |
Bob Wilson | 6a234f0 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 2314 | SDValue ArgValue2; |
| 2315 | if (VA.isMemLoc()) { |
Evan Cheng | ed2ae13 | 2010-07-03 00:40:23 +0000 | [diff] [blame] | 2316 | int FI = MFI->CreateFixedObject(8, VA.getLocMemOffset(), true); |
Bob Wilson | 6a234f0 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 2317 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
| 2318 | ArgValue2 = DAG.getLoad(MVT::f64, dl, Chain, FIN, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2319 | MachinePointerInfo::getFixedStack(FI), |
Bob Wilson | 6a234f0 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 2320 | false, false, 0); |
| 2321 | } else { |
| 2322 | ArgValue2 = GetF64FormalArgument(VA, ArgLocs[++i], |
| 2323 | Chain, DAG, dl); |
| 2324 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2325 | ArgValue = DAG.getNode(ISD::UNDEF, dl, MVT::v2f64); |
| 2326 | ArgValue = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2327 | ArgValue, ArgValue1, DAG.getIntPtrConstant(0)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2328 | ArgValue = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2329 | ArgValue, ArgValue2, DAG.getIntPtrConstant(1)); |
| 2330 | } else |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2331 | ArgValue = GetF64FormalArgument(VA, ArgLocs[++i], Chain, DAG, dl); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2332 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2333 | } else { |
| 2334 | TargetRegisterClass *RC; |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 2335 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2336 | if (RegVT == MVT::f32) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2337 | RC = ARM::SPRRegisterClass; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2338 | else if (RegVT == MVT::f64) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2339 | RC = ARM::DPRRegisterClass; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2340 | else if (RegVT == MVT::v2f64) |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 2341 | RC = ARM::QPRRegisterClass; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2342 | else if (RegVT == MVT::i32) |
Anton Korobeynikov | 058c251 | 2009-08-05 20:15:19 +0000 | [diff] [blame] | 2343 | RC = (AFI->isThumb1OnlyFunction() ? |
| 2344 | ARM::tGPRRegisterClass : ARM::GPRRegisterClass); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2345 | else |
Anton Korobeynikov | 058c251 | 2009-08-05 20:15:19 +0000 | [diff] [blame] | 2346 | llvm_unreachable("RegVT not supported by FORMAL_ARGUMENTS Lowering"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2347 | |
| 2348 | // Transform the arguments in physical registers into virtual ones. |
Devang Patel | 68e6bee | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 2349 | unsigned Reg = MF.addLiveIn(VA.getLocReg(), RC); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2350 | ArgValue = DAG.getCopyFromReg(Chain, dl, Reg, RegVT); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2351 | } |
| 2352 | |
| 2353 | // If this is an 8 or 16-bit value, it is really passed promoted |
| 2354 | // to 32 bits. Insert an assert[sz]ext to capture this, then |
| 2355 | // truncate to the right size. |
| 2356 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 2357 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2358 | case CCValAssign::Full: break; |
| 2359 | case CCValAssign::BCvt: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2360 | ArgValue = DAG.getNode(ISD::BITCAST, dl, VA.getValVT(), ArgValue); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2361 | break; |
| 2362 | case CCValAssign::SExt: |
| 2363 | ArgValue = DAG.getNode(ISD::AssertSext, dl, RegVT, ArgValue, |
| 2364 | DAG.getValueType(VA.getValVT())); |
| 2365 | ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue); |
| 2366 | break; |
| 2367 | case CCValAssign::ZExt: |
| 2368 | ArgValue = DAG.getNode(ISD::AssertZext, dl, RegVT, ArgValue, |
| 2369 | DAG.getValueType(VA.getValVT())); |
| 2370 | ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue); |
| 2371 | break; |
| 2372 | } |
| 2373 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2374 | InVals.push_back(ArgValue); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2375 | |
| 2376 | } else { // VA.isRegLoc() |
| 2377 | |
| 2378 | // sanity check |
| 2379 | assert(VA.isMemLoc()); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2380 | assert(VA.getValVT() != MVT::i64 && "i64 should already be lowered"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2381 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2382 | int index = ArgLocs[i].getValNo(); |
| 2383 | |
| 2384 | // Some Ins[] entries become multiple ArgLoc[] entries. |
| 2385 | // Process them only once. |
| 2386 | if (index != lastInsIndex) |
| 2387 | { |
| 2388 | ISD::ArgFlagsTy Flags = Ins[index].Flags; |
| 2389 | // FIXME: For now, all byval parameter objects are marked mutable. This can be |
| 2390 | // changed with more analysis. |
| 2391 | // In case of tail call optimization mark all arguments mutable. Since they |
| 2392 | // could be overwritten by lowering of arguments in case of a tail call. |
| 2393 | if (Flags.isByVal()) { |
Evan Cheng | ee2e0e3 | 2011-03-30 23:44:13 +0000 | [diff] [blame] | 2394 | unsigned Bytes = Flags.getByValSize(); |
| 2395 | if (Bytes == 0) Bytes = 1; // Don't create zero-sized stack objects. |
| 2396 | int FI = MFI->CreateFixedObject(Bytes, VA.getLocMemOffset(), false); |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2397 | InVals.push_back(DAG.getFrameIndex(FI, getPointerTy())); |
| 2398 | } else { |
| 2399 | int FI = MFI->CreateFixedObject(VA.getLocVT().getSizeInBits()/8, |
| 2400 | VA.getLocMemOffset(), true); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2401 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2402 | // Create load nodes to retrieve arguments from the stack. |
| 2403 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
| 2404 | InVals.push_back(DAG.getLoad(VA.getValVT(), dl, Chain, FIN, |
| 2405 | MachinePointerInfo::getFixedStack(FI), |
| 2406 | false, false, 0)); |
| 2407 | } |
| 2408 | lastInsIndex = index; |
| 2409 | } |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2410 | } |
| 2411 | } |
| 2412 | |
| 2413 | // varargs |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2414 | if (isVarArg) { |
| 2415 | static const unsigned GPRArgRegs[] = { |
| 2416 | ARM::R0, ARM::R1, ARM::R2, ARM::R3 |
| 2417 | }; |
| 2418 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 2419 | unsigned NumGPRs = CCInfo.getFirstUnallocated |
| 2420 | (GPRArgRegs, sizeof(GPRArgRegs) / sizeof(GPRArgRegs[0])); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2421 | |
Anton Korobeynikov | 16c29b5 | 2011-01-10 12:39:04 +0000 | [diff] [blame] | 2422 | unsigned Align = MF.getTarget().getFrameLowering()->getStackAlignment(); |
Lauro Ramos Venancio | 600c383 | 2007-02-23 20:32:57 +0000 | [diff] [blame] | 2423 | unsigned VARegSize = (4 - NumGPRs) * 4; |
| 2424 | unsigned VARegSaveSize = (VARegSize + Align - 1) & ~(Align - 1); |
Rafael Espindola | c1382b7 | 2009-10-30 14:33:14 +0000 | [diff] [blame] | 2425 | unsigned ArgOffset = CCInfo.getNextStackOffset(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2426 | if (VARegSaveSize) { |
| 2427 | // If this function is vararg, store any remaining integer argument regs |
| 2428 | // to their spots on the stack so that they may be loaded by deferencing |
| 2429 | // the result of va_next. |
| 2430 | AFI->setVarArgsRegSaveSize(VARegSaveSize); |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 2431 | AFI->setVarArgsFrameIndex( |
| 2432 | MFI->CreateFixedObject(VARegSaveSize, |
| 2433 | ArgOffset + VARegSaveSize - VARegSize, |
Jim Grosbach | fd52906 | 2010-10-15 18:34:47 +0000 | [diff] [blame] | 2434 | false)); |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 2435 | SDValue FIN = DAG.getFrameIndex(AFI->getVarArgsFrameIndex(), |
| 2436 | getPointerTy()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2437 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2438 | SmallVector<SDValue, 4> MemOps; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2439 | for (; NumGPRs < 4; ++NumGPRs) { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2440 | TargetRegisterClass *RC; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 2441 | if (AFI->isThumb1OnlyFunction()) |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2442 | RC = ARM::tGPRRegisterClass; |
Jim Grosbach | 30eae3c | 2009-04-07 20:34:09 +0000 | [diff] [blame] | 2443 | else |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2444 | RC = ARM::GPRRegisterClass; |
| 2445 | |
Devang Patel | 68e6bee | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 2446 | unsigned VReg = MF.addLiveIn(GPRArgRegs[NumGPRs], RC); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2447 | SDValue Val = DAG.getCopyFromReg(Chain, dl, VReg, MVT::i32); |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 2448 | SDValue Store = |
| 2449 | DAG.getStore(Val.getValue(1), dl, Val, FIN, |
Chris Lattner | fc448ff | 2010-09-21 18:51:21 +0000 | [diff] [blame] | 2450 | MachinePointerInfo::getFixedStack(AFI->getVarArgsFrameIndex()), |
| 2451 | false, false, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2452 | MemOps.push_back(Store); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2453 | FIN = DAG.getNode(ISD::ADD, dl, getPointerTy(), FIN, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2454 | DAG.getConstant(4, getPointerTy())); |
| 2455 | } |
| 2456 | if (!MemOps.empty()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2457 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2458 | &MemOps[0], MemOps.size()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2459 | } else |
| 2460 | // This will point to the next argument passed via stack. |
Evan Cheng | ed2ae13 | 2010-07-03 00:40:23 +0000 | [diff] [blame] | 2461 | AFI->setVarArgsFrameIndex(MFI->CreateFixedObject(4, ArgOffset, true)); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2462 | } |
| 2463 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2464 | return Chain; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2465 | } |
| 2466 | |
| 2467 | /// isFloatingPointZero - Return true if this is +0.0. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2468 | static bool isFloatingPointZero(SDValue Op) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2469 | if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(Op)) |
Dale Johannesen | eaf0894 | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 2470 | return CFP->getValueAPF().isPosZero(); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2471 | else if (ISD::isEXTLoad(Op.getNode()) || ISD::isNON_EXTLoad(Op.getNode())) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2472 | // Maybe this has already been legalized into the constant pool? |
| 2473 | if (Op.getOperand(1).getOpcode() == ARMISD::Wrapper) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2474 | SDValue WrapperOp = Op.getOperand(1).getOperand(0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2475 | if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(WrapperOp)) |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2476 | if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CP->getConstVal())) |
Dale Johannesen | eaf0894 | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 2477 | return CFP->getValueAPF().isPosZero(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2478 | } |
| 2479 | } |
| 2480 | return false; |
| 2481 | } |
| 2482 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2483 | /// Returns appropriate ARM CMP (cmp) and corresponding condition code for |
| 2484 | /// the given operands. |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 2485 | SDValue |
| 2486 | ARMTargetLowering::getARMCmp(SDValue LHS, SDValue RHS, ISD::CondCode CC, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2487 | SDValue &ARMcc, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2488 | DebugLoc dl) const { |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2489 | if (ConstantSDNode *RHSC = dyn_cast<ConstantSDNode>(RHS.getNode())) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2490 | unsigned C = RHSC->getZExtValue(); |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 2491 | if (!isLegalICmpImmediate(C)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2492 | // Constant does not fit, try adjusting it by one? |
| 2493 | switch (CC) { |
| 2494 | default: break; |
| 2495 | case ISD::SETLT: |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2496 | case ISD::SETGE: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 2497 | if (C != 0x80000000 && isLegalICmpImmediate(C-1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2498 | CC = (CC == ISD::SETLT) ? ISD::SETLE : ISD::SETGT; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2499 | RHS = DAG.getConstant(C-1, MVT::i32); |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2500 | } |
| 2501 | break; |
| 2502 | case ISD::SETULT: |
| 2503 | case ISD::SETUGE: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 2504 | if (C != 0 && isLegalICmpImmediate(C-1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2505 | CC = (CC == ISD::SETULT) ? ISD::SETULE : ISD::SETUGT; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2506 | RHS = DAG.getConstant(C-1, MVT::i32); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2507 | } |
| 2508 | break; |
| 2509 | case ISD::SETLE: |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2510 | case ISD::SETGT: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 2511 | if (C != 0x7fffffff && isLegalICmpImmediate(C+1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2512 | CC = (CC == ISD::SETLE) ? ISD::SETLT : ISD::SETGE; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2513 | RHS = DAG.getConstant(C+1, MVT::i32); |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2514 | } |
| 2515 | break; |
| 2516 | case ISD::SETULE: |
| 2517 | case ISD::SETUGT: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 2518 | if (C != 0xffffffff && isLegalICmpImmediate(C+1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2519 | CC = (CC == ISD::SETULE) ? ISD::SETULT : ISD::SETUGE; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2520 | RHS = DAG.getConstant(C+1, MVT::i32); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2521 | } |
| 2522 | break; |
| 2523 | } |
| 2524 | } |
| 2525 | } |
| 2526 | |
| 2527 | ARMCC::CondCodes CondCode = IntCCToARMCC(CC); |
Lauro Ramos Venancio | 9996663 | 2007-04-02 01:30:03 +0000 | [diff] [blame] | 2528 | ARMISD::NodeType CompareType; |
| 2529 | switch (CondCode) { |
| 2530 | default: |
| 2531 | CompareType = ARMISD::CMP; |
| 2532 | break; |
| 2533 | case ARMCC::EQ: |
| 2534 | case ARMCC::NE: |
David Goodwin | c0309b4 | 2009-06-29 15:33:01 +0000 | [diff] [blame] | 2535 | // Uses only Z Flag |
| 2536 | CompareType = ARMISD::CMPZ; |
Lauro Ramos Venancio | 9996663 | 2007-04-02 01:30:03 +0000 | [diff] [blame] | 2537 | break; |
| 2538 | } |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2539 | ARMcc = DAG.getConstant(CondCode, MVT::i32); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 2540 | return DAG.getNode(CompareType, dl, MVT::Glue, LHS, RHS); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2541 | } |
| 2542 | |
| 2543 | /// 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] | 2544 | SDValue |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2545 | ARMTargetLowering::getVFPCmp(SDValue LHS, SDValue RHS, SelectionDAG &DAG, |
Evan Cheng | 515fe3a | 2010-07-08 02:08:50 +0000 | [diff] [blame] | 2546 | DebugLoc dl) const { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2547 | SDValue Cmp; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2548 | if (!isFloatingPointZero(RHS)) |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 2549 | Cmp = DAG.getNode(ARMISD::CMPFP, dl, MVT::Glue, LHS, RHS); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2550 | else |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 2551 | Cmp = DAG.getNode(ARMISD::CMPFPw0, dl, MVT::Glue, LHS); |
| 2552 | return DAG.getNode(ARMISD::FMSTAT, dl, MVT::Glue, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2553 | } |
| 2554 | |
Bob Wilson | 79f56c9 | 2011-03-08 01:17:20 +0000 | [diff] [blame] | 2555 | /// duplicateCmp - Glue values can have only one use, so this function |
| 2556 | /// duplicates a comparison node. |
| 2557 | SDValue |
| 2558 | ARMTargetLowering::duplicateCmp(SDValue Cmp, SelectionDAG &DAG) const { |
| 2559 | unsigned Opc = Cmp.getOpcode(); |
| 2560 | DebugLoc DL = Cmp.getDebugLoc(); |
| 2561 | if (Opc == ARMISD::CMP || Opc == ARMISD::CMPZ) |
| 2562 | return DAG.getNode(Opc, DL, MVT::Glue, Cmp.getOperand(0),Cmp.getOperand(1)); |
| 2563 | |
| 2564 | assert(Opc == ARMISD::FMSTAT && "unexpected comparison operation"); |
| 2565 | Cmp = Cmp.getOperand(0); |
| 2566 | Opc = Cmp.getOpcode(); |
| 2567 | if (Opc == ARMISD::CMPFP) |
| 2568 | Cmp = DAG.getNode(Opc, DL, MVT::Glue, Cmp.getOperand(0),Cmp.getOperand(1)); |
| 2569 | else { |
| 2570 | assert(Opc == ARMISD::CMPFPw0 && "unexpected operand of FMSTAT"); |
| 2571 | Cmp = DAG.getNode(Opc, DL, MVT::Glue, Cmp.getOperand(0)); |
| 2572 | } |
| 2573 | return DAG.getNode(ARMISD::FMSTAT, DL, MVT::Glue, Cmp); |
| 2574 | } |
| 2575 | |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 2576 | SDValue ARMTargetLowering::LowerSELECT(SDValue Op, SelectionDAG &DAG) const { |
| 2577 | SDValue Cond = Op.getOperand(0); |
| 2578 | SDValue SelectTrue = Op.getOperand(1); |
| 2579 | SDValue SelectFalse = Op.getOperand(2); |
| 2580 | DebugLoc dl = Op.getDebugLoc(); |
| 2581 | |
| 2582 | // Convert: |
| 2583 | // |
| 2584 | // (select (cmov 1, 0, cond), t, f) -> (cmov t, f, cond) |
| 2585 | // (select (cmov 0, 1, cond), t, f) -> (cmov f, t, cond) |
| 2586 | // |
| 2587 | if (Cond.getOpcode() == ARMISD::CMOV && Cond.hasOneUse()) { |
| 2588 | const ConstantSDNode *CMOVTrue = |
| 2589 | dyn_cast<ConstantSDNode>(Cond.getOperand(0)); |
| 2590 | const ConstantSDNode *CMOVFalse = |
| 2591 | dyn_cast<ConstantSDNode>(Cond.getOperand(1)); |
| 2592 | |
| 2593 | if (CMOVTrue && CMOVFalse) { |
| 2594 | unsigned CMOVTrueVal = CMOVTrue->getZExtValue(); |
| 2595 | unsigned CMOVFalseVal = CMOVFalse->getZExtValue(); |
| 2596 | |
| 2597 | SDValue True; |
| 2598 | SDValue False; |
| 2599 | if (CMOVTrueVal == 1 && CMOVFalseVal == 0) { |
| 2600 | True = SelectTrue; |
| 2601 | False = SelectFalse; |
| 2602 | } else if (CMOVTrueVal == 0 && CMOVFalseVal == 1) { |
| 2603 | True = SelectFalse; |
| 2604 | False = SelectTrue; |
| 2605 | } |
| 2606 | |
| 2607 | if (True.getNode() && False.getNode()) { |
| 2608 | EVT VT = Cond.getValueType(); |
| 2609 | SDValue ARMcc = Cond.getOperand(2); |
| 2610 | SDValue CCR = Cond.getOperand(3); |
Bob Wilson | 79f56c9 | 2011-03-08 01:17:20 +0000 | [diff] [blame] | 2611 | SDValue Cmp = duplicateCmp(Cond.getOperand(4), DAG); |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 2612 | return DAG.getNode(ARMISD::CMOV, dl, VT, True, False, ARMcc, CCR, Cmp); |
| 2613 | } |
| 2614 | } |
| 2615 | } |
| 2616 | |
| 2617 | return DAG.getSelectCC(dl, Cond, |
| 2618 | DAG.getConstant(0, Cond.getValueType()), |
| 2619 | SelectTrue, SelectFalse, ISD::SETNE); |
| 2620 | } |
| 2621 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2622 | SDValue ARMTargetLowering::LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2623 | EVT VT = Op.getValueType(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2624 | SDValue LHS = Op.getOperand(0); |
| 2625 | SDValue RHS = Op.getOperand(1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2626 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(4))->get(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2627 | SDValue TrueVal = Op.getOperand(2); |
| 2628 | SDValue FalseVal = Op.getOperand(3); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2629 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2630 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2631 | if (LHS.getValueType() == MVT::i32) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2632 | SDValue ARMcc; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2633 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2634 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMcc, DAG, dl); |
| 2635 | return DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, ARMcc, CCR,Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2636 | } |
| 2637 | |
| 2638 | ARMCC::CondCodes CondCode, CondCode2; |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 2639 | FPCCToARMCC(CC, CondCode, CondCode2); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2640 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2641 | SDValue ARMcc = DAG.getConstant(CondCode, MVT::i32); |
| 2642 | SDValue Cmp = getVFPCmp(LHS, RHS, DAG, dl); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2643 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2644 | SDValue Result = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2645 | ARMcc, CCR, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2646 | if (CondCode2 != ARMCC::AL) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2647 | SDValue ARMcc2 = DAG.getConstant(CondCode2, MVT::i32); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2648 | // FIXME: Needs another CMP because flag can have but one use. |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2649 | SDValue Cmp2 = getVFPCmp(LHS, RHS, DAG, dl); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2650 | Result = DAG.getNode(ARMISD::CMOV, dl, VT, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2651 | Result, TrueVal, ARMcc2, CCR, Cmp2); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2652 | } |
| 2653 | return Result; |
| 2654 | } |
| 2655 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2656 | /// canChangeToInt - Given the fp compare operand, return true if it is suitable |
| 2657 | /// to morph to an integer compare sequence. |
| 2658 | static bool canChangeToInt(SDValue Op, bool &SeenZero, |
| 2659 | const ARMSubtarget *Subtarget) { |
| 2660 | SDNode *N = Op.getNode(); |
| 2661 | if (!N->hasOneUse()) |
| 2662 | // Otherwise it requires moving the value from fp to integer registers. |
| 2663 | return false; |
| 2664 | if (!N->getNumValues()) |
| 2665 | return false; |
| 2666 | EVT VT = Op.getValueType(); |
| 2667 | if (VT != MVT::f32 && !Subtarget->isFPBrccSlow()) |
| 2668 | // f32 case is generally profitable. f64 case only makes sense when vcmpe + |
| 2669 | // vmrs are very slow, e.g. cortex-a8. |
| 2670 | return false; |
| 2671 | |
| 2672 | if (isFloatingPointZero(Op)) { |
| 2673 | SeenZero = true; |
| 2674 | return true; |
| 2675 | } |
| 2676 | return ISD::isNormalLoad(N); |
| 2677 | } |
| 2678 | |
| 2679 | static SDValue bitcastf32Toi32(SDValue Op, SelectionDAG &DAG) { |
| 2680 | if (isFloatingPointZero(Op)) |
| 2681 | return DAG.getConstant(0, MVT::i32); |
| 2682 | |
| 2683 | if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Op)) |
| 2684 | return DAG.getLoad(MVT::i32, Op.getDebugLoc(), |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2685 | Ld->getChain(), Ld->getBasePtr(), Ld->getPointerInfo(), |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2686 | Ld->isVolatile(), Ld->isNonTemporal(), |
| 2687 | Ld->getAlignment()); |
| 2688 | |
| 2689 | llvm_unreachable("Unknown VFP cmp argument!"); |
| 2690 | } |
| 2691 | |
| 2692 | static void expandf64Toi32(SDValue Op, SelectionDAG &DAG, |
| 2693 | SDValue &RetVal1, SDValue &RetVal2) { |
| 2694 | if (isFloatingPointZero(Op)) { |
| 2695 | RetVal1 = DAG.getConstant(0, MVT::i32); |
| 2696 | RetVal2 = DAG.getConstant(0, MVT::i32); |
| 2697 | return; |
| 2698 | } |
| 2699 | |
| 2700 | if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Op)) { |
| 2701 | SDValue Ptr = Ld->getBasePtr(); |
| 2702 | RetVal1 = DAG.getLoad(MVT::i32, Op.getDebugLoc(), |
| 2703 | Ld->getChain(), Ptr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2704 | Ld->getPointerInfo(), |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2705 | Ld->isVolatile(), Ld->isNonTemporal(), |
| 2706 | Ld->getAlignment()); |
| 2707 | |
| 2708 | EVT PtrType = Ptr.getValueType(); |
| 2709 | unsigned NewAlign = MinAlign(Ld->getAlignment(), 4); |
| 2710 | SDValue NewPtr = DAG.getNode(ISD::ADD, Op.getDebugLoc(), |
| 2711 | PtrType, Ptr, DAG.getConstant(4, PtrType)); |
| 2712 | RetVal2 = DAG.getLoad(MVT::i32, Op.getDebugLoc(), |
| 2713 | Ld->getChain(), NewPtr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2714 | Ld->getPointerInfo().getWithOffset(4), |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2715 | Ld->isVolatile(), Ld->isNonTemporal(), |
| 2716 | NewAlign); |
| 2717 | return; |
| 2718 | } |
| 2719 | |
| 2720 | llvm_unreachable("Unknown VFP cmp argument!"); |
| 2721 | } |
| 2722 | |
| 2723 | /// OptimizeVFPBrcond - With -enable-unsafe-fp-math, it's legal to optimize some |
| 2724 | /// f32 and even f64 comparisons to integer ones. |
| 2725 | SDValue |
| 2726 | ARMTargetLowering::OptimizeVFPBrcond(SDValue Op, SelectionDAG &DAG) const { |
| 2727 | SDValue Chain = Op.getOperand(0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2728 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get(); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2729 | SDValue LHS = Op.getOperand(2); |
| 2730 | SDValue RHS = Op.getOperand(3); |
| 2731 | SDValue Dest = Op.getOperand(4); |
| 2732 | DebugLoc dl = Op.getDebugLoc(); |
| 2733 | |
| 2734 | bool SeenZero = false; |
| 2735 | if (canChangeToInt(LHS, SeenZero, Subtarget) && |
| 2736 | canChangeToInt(RHS, SeenZero, Subtarget) && |
Evan Cheng | 60108e9 | 2010-07-15 22:07:12 +0000 | [diff] [blame] | 2737 | // If one of the operand is zero, it's safe to ignore the NaN case since |
| 2738 | // we only care about equality comparisons. |
| 2739 | (SeenZero || (DAG.isKnownNeverNaN(LHS) && DAG.isKnownNeverNaN(RHS)))) { |
Bob Wilson | 1b772f9 | 2011-03-08 01:17:16 +0000 | [diff] [blame] | 2740 | // If unsafe fp math optimization is enabled and there are no other uses of |
| 2741 | // 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] | 2742 | // to an integer comparison. |
| 2743 | if (CC == ISD::SETOEQ) |
| 2744 | CC = ISD::SETEQ; |
| 2745 | else if (CC == ISD::SETUNE) |
| 2746 | CC = ISD::SETNE; |
| 2747 | |
| 2748 | SDValue ARMcc; |
| 2749 | if (LHS.getValueType() == MVT::f32) { |
| 2750 | LHS = bitcastf32Toi32(LHS, DAG); |
| 2751 | RHS = bitcastf32Toi32(RHS, DAG); |
| 2752 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMcc, DAG, dl); |
| 2753 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| 2754 | return DAG.getNode(ARMISD::BRCOND, dl, MVT::Other, |
| 2755 | Chain, Dest, ARMcc, CCR, Cmp); |
| 2756 | } |
| 2757 | |
| 2758 | SDValue LHS1, LHS2; |
| 2759 | SDValue RHS1, RHS2; |
| 2760 | expandf64Toi32(LHS, DAG, LHS1, LHS2); |
| 2761 | expandf64Toi32(RHS, DAG, RHS1, RHS2); |
| 2762 | ARMCC::CondCodes CondCode = IntCCToARMCC(CC); |
| 2763 | ARMcc = DAG.getConstant(CondCode, MVT::i32); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 2764 | SDVTList VTList = DAG.getVTList(MVT::Other, MVT::Glue); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2765 | SDValue Ops[] = { Chain, ARMcc, LHS1, LHS2, RHS1, RHS2, Dest }; |
| 2766 | return DAG.getNode(ARMISD::BCC_i64, dl, VTList, Ops, 7); |
| 2767 | } |
| 2768 | |
| 2769 | return SDValue(); |
| 2770 | } |
| 2771 | |
| 2772 | SDValue ARMTargetLowering::LowerBR_CC(SDValue Op, SelectionDAG &DAG) const { |
| 2773 | SDValue Chain = Op.getOperand(0); |
| 2774 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get(); |
| 2775 | SDValue LHS = Op.getOperand(2); |
| 2776 | SDValue RHS = Op.getOperand(3); |
| 2777 | SDValue Dest = Op.getOperand(4); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2778 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2779 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2780 | if (LHS.getValueType() == MVT::i32) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2781 | SDValue ARMcc; |
| 2782 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMcc, DAG, dl); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2783 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2784 | return DAG.getNode(ARMISD::BRCOND, dl, MVT::Other, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2785 | Chain, Dest, ARMcc, CCR, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2786 | } |
| 2787 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2788 | assert(LHS.getValueType() == MVT::f32 || LHS.getValueType() == MVT::f64); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2789 | |
| 2790 | if (UnsafeFPMath && |
| 2791 | (CC == ISD::SETEQ || CC == ISD::SETOEQ || |
| 2792 | CC == ISD::SETNE || CC == ISD::SETUNE)) { |
| 2793 | SDValue Result = OptimizeVFPBrcond(Op, DAG); |
| 2794 | if (Result.getNode()) |
| 2795 | return Result; |
| 2796 | } |
| 2797 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2798 | ARMCC::CondCodes CondCode, CondCode2; |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 2799 | FPCCToARMCC(CC, CondCode, CondCode2); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2800 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2801 | SDValue ARMcc = DAG.getConstant(CondCode, MVT::i32); |
| 2802 | SDValue Cmp = getVFPCmp(LHS, RHS, DAG, dl); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2803 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 2804 | SDVTList VTList = DAG.getVTList(MVT::Other, MVT::Glue); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2805 | SDValue Ops[] = { Chain, Dest, ARMcc, CCR, Cmp }; |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2806 | SDValue Res = DAG.getNode(ARMISD::BRCOND, dl, VTList, Ops, 5); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2807 | if (CondCode2 != ARMCC::AL) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2808 | ARMcc = DAG.getConstant(CondCode2, MVT::i32); |
| 2809 | SDValue Ops[] = { Res, Dest, ARMcc, CCR, Res.getValue(1) }; |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2810 | Res = DAG.getNode(ARMISD::BRCOND, dl, VTList, Ops, 5); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2811 | } |
| 2812 | return Res; |
| 2813 | } |
| 2814 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2815 | SDValue ARMTargetLowering::LowerBR_JT(SDValue Op, SelectionDAG &DAG) const { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2816 | SDValue Chain = Op.getOperand(0); |
| 2817 | SDValue Table = Op.getOperand(1); |
| 2818 | SDValue Index = Op.getOperand(2); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2819 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2820 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2821 | EVT PTy = getPointerTy(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2822 | JumpTableSDNode *JT = cast<JumpTableSDNode>(Table); |
| 2823 | ARMFunctionInfo *AFI = DAG.getMachineFunction().getInfo<ARMFunctionInfo>(); |
Bob Wilson | 3eadf00 | 2009-07-14 18:44:34 +0000 | [diff] [blame] | 2824 | SDValue UId = DAG.getConstant(AFI->createJumpTableUId(), PTy); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2825 | SDValue JTI = DAG.getTargetJumpTable(JT->getIndex(), PTy); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2826 | Table = DAG.getNode(ARMISD::WrapperJT, dl, MVT::i32, JTI, UId); |
Evan Cheng | e7c329b | 2009-07-28 20:53:24 +0000 | [diff] [blame] | 2827 | Index = DAG.getNode(ISD::MUL, dl, PTy, Index, DAG.getConstant(4, PTy)); |
| 2828 | SDValue Addr = DAG.getNode(ISD::ADD, dl, PTy, Index, Table); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 2829 | if (Subtarget->isThumb2()) { |
| 2830 | // Thumb2 uses a two-level jump. That is, it jumps into the jump table |
| 2831 | // which does another jump to the destination. This also makes it easier |
| 2832 | // to translate it to TBB / TBH later. |
| 2833 | // FIXME: This might not work if the function is extremely large. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2834 | return DAG.getNode(ARMISD::BR2_JT, dl, MVT::Other, Chain, |
Evan Cheng | 5657c01 | 2009-07-29 02:18:14 +0000 | [diff] [blame] | 2835 | Addr, Op.getOperand(2), JTI, UId); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 2836 | } |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 2837 | if (getTargetMachine().getRelocationModel() == Reloc::PIC_) { |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2838 | Addr = DAG.getLoad((EVT)MVT::i32, dl, Chain, Addr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2839 | MachinePointerInfo::getJumpTable(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 2840 | false, false, 0); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 2841 | Chain = Addr.getValue(1); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2842 | Addr = DAG.getNode(ISD::ADD, dl, PTy, Addr, Table); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2843 | 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] | 2844 | } else { |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2845 | Addr = DAG.getLoad(PTy, dl, Chain, Addr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2846 | MachinePointerInfo::getJumpTable(), false, false, 0); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 2847 | Chain = Addr.getValue(1); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2848 | 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] | 2849 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2850 | } |
| 2851 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 2852 | static SDValue LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG) { |
| 2853 | DebugLoc dl = Op.getDebugLoc(); |
| 2854 | unsigned Opc; |
| 2855 | |
| 2856 | switch (Op.getOpcode()) { |
| 2857 | default: |
| 2858 | assert(0 && "Invalid opcode!"); |
| 2859 | case ISD::FP_TO_SINT: |
| 2860 | Opc = ARMISD::FTOSI; |
| 2861 | break; |
| 2862 | case ISD::FP_TO_UINT: |
| 2863 | Opc = ARMISD::FTOUI; |
| 2864 | break; |
| 2865 | } |
| 2866 | Op = DAG.getNode(Opc, dl, MVT::f32, Op.getOperand(0)); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2867 | return DAG.getNode(ISD::BITCAST, dl, MVT::i32, Op); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 2868 | } |
| 2869 | |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 2870 | static SDValue LowerVectorINT_TO_FP(SDValue Op, SelectionDAG &DAG) { |
| 2871 | EVT VT = Op.getValueType(); |
| 2872 | DebugLoc dl = Op.getDebugLoc(); |
| 2873 | |
| 2874 | EVT OperandVT = Op.getOperand(0).getValueType(); |
| 2875 | assert(OperandVT == MVT::v4i16 && "Invalid type for custom lowering!"); |
| 2876 | if (VT != MVT::v4f32) |
| 2877 | return DAG.UnrollVectorOp(Op.getNode()); |
| 2878 | |
| 2879 | unsigned CastOpc; |
| 2880 | unsigned Opc; |
| 2881 | switch (Op.getOpcode()) { |
| 2882 | default: |
| 2883 | assert(0 && "Invalid opcode!"); |
| 2884 | case ISD::SINT_TO_FP: |
| 2885 | CastOpc = ISD::SIGN_EXTEND; |
| 2886 | Opc = ISD::SINT_TO_FP; |
| 2887 | break; |
| 2888 | case ISD::UINT_TO_FP: |
| 2889 | CastOpc = ISD::ZERO_EXTEND; |
| 2890 | Opc = ISD::UINT_TO_FP; |
| 2891 | break; |
| 2892 | } |
| 2893 | |
| 2894 | Op = DAG.getNode(CastOpc, dl, MVT::v4i32, Op.getOperand(0)); |
| 2895 | return DAG.getNode(Opc, dl, VT, Op); |
| 2896 | } |
| 2897 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 2898 | static SDValue LowerINT_TO_FP(SDValue Op, SelectionDAG &DAG) { |
| 2899 | EVT VT = Op.getValueType(); |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 2900 | if (VT.isVector()) |
| 2901 | return LowerVectorINT_TO_FP(Op, DAG); |
| 2902 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 2903 | DebugLoc dl = Op.getDebugLoc(); |
| 2904 | unsigned Opc; |
| 2905 | |
| 2906 | switch (Op.getOpcode()) { |
| 2907 | default: |
| 2908 | assert(0 && "Invalid opcode!"); |
| 2909 | case ISD::SINT_TO_FP: |
| 2910 | Opc = ARMISD::SITOF; |
| 2911 | break; |
| 2912 | case ISD::UINT_TO_FP: |
| 2913 | Opc = ARMISD::UITOF; |
| 2914 | break; |
| 2915 | } |
| 2916 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2917 | Op = DAG.getNode(ISD::BITCAST, dl, MVT::f32, Op.getOperand(0)); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 2918 | return DAG.getNode(Opc, dl, VT, Op); |
| 2919 | } |
| 2920 | |
Evan Cheng | 515fe3a | 2010-07-08 02:08:50 +0000 | [diff] [blame] | 2921 | SDValue ARMTargetLowering::LowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2922 | // Implement fcopysign with a fabs and a conditional fneg. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2923 | SDValue Tmp0 = Op.getOperand(0); |
| 2924 | SDValue Tmp1 = Op.getOperand(1); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2925 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2926 | EVT VT = Op.getValueType(); |
| 2927 | EVT SrcVT = Tmp1.getValueType(); |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 2928 | bool InGPR = Tmp0.getOpcode() == ISD::BITCAST || |
| 2929 | Tmp0.getOpcode() == ARMISD::VMOVDRR; |
| 2930 | bool UseNEON = !InGPR && Subtarget->hasNEON(); |
| 2931 | |
| 2932 | if (UseNEON) { |
| 2933 | // Use VBSL to copy the sign bit. |
| 2934 | unsigned EncodedVal = ARM_AM::createNEONModImm(0x6, 0x80); |
| 2935 | SDValue Mask = DAG.getNode(ARMISD::VMOVIMM, dl, MVT::v2i32, |
| 2936 | DAG.getTargetConstant(EncodedVal, MVT::i32)); |
| 2937 | EVT OpVT = (VT == MVT::f32) ? MVT::v2i32 : MVT::v1i64; |
| 2938 | if (VT == MVT::f64) |
| 2939 | Mask = DAG.getNode(ARMISD::VSHL, dl, OpVT, |
| 2940 | DAG.getNode(ISD::BITCAST, dl, OpVT, Mask), |
| 2941 | DAG.getConstant(32, MVT::i32)); |
| 2942 | else /*if (VT == MVT::f32)*/ |
| 2943 | Tmp0 = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, MVT::v2f32, Tmp0); |
| 2944 | if (SrcVT == MVT::f32) { |
| 2945 | Tmp1 = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, MVT::v2f32, Tmp1); |
| 2946 | if (VT == MVT::f64) |
| 2947 | Tmp1 = DAG.getNode(ARMISD::VSHL, dl, OpVT, |
| 2948 | DAG.getNode(ISD::BITCAST, dl, OpVT, Tmp1), |
| 2949 | DAG.getConstant(32, MVT::i32)); |
| 2950 | } |
| 2951 | Tmp0 = DAG.getNode(ISD::BITCAST, dl, OpVT, Tmp0); |
| 2952 | Tmp1 = DAG.getNode(ISD::BITCAST, dl, OpVT, Tmp1); |
| 2953 | |
| 2954 | SDValue AllOnes = DAG.getTargetConstant(ARM_AM::createNEONModImm(0xe, 0xff), |
| 2955 | MVT::i32); |
| 2956 | AllOnes = DAG.getNode(ARMISD::VMOVIMM, dl, MVT::v8i8, AllOnes); |
| 2957 | SDValue MaskNot = DAG.getNode(ISD::XOR, dl, OpVT, Mask, |
| 2958 | DAG.getNode(ISD::BITCAST, dl, OpVT, AllOnes)); |
| 2959 | |
| 2960 | SDValue Res = DAG.getNode(ISD::OR, dl, OpVT, |
| 2961 | DAG.getNode(ISD::AND, dl, OpVT, Tmp1, Mask), |
| 2962 | DAG.getNode(ISD::AND, dl, OpVT, Tmp0, MaskNot)); |
Evan Cheng | c24ab5c | 2011-02-28 18:45:27 +0000 | [diff] [blame] | 2963 | if (VT == MVT::f32) { |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 2964 | Res = DAG.getNode(ISD::BITCAST, dl, MVT::v2f32, Res); |
| 2965 | Res = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f32, Res, |
| 2966 | DAG.getConstant(0, MVT::i32)); |
| 2967 | } else { |
| 2968 | Res = DAG.getNode(ISD::BITCAST, dl, MVT::f64, Res); |
| 2969 | } |
| 2970 | |
| 2971 | return Res; |
| 2972 | } |
Evan Cheng | c143dd4 | 2011-02-11 02:28:55 +0000 | [diff] [blame] | 2973 | |
| 2974 | // Bitcast operand 1 to i32. |
| 2975 | if (SrcVT == MVT::f64) |
| 2976 | Tmp1 = DAG.getNode(ARMISD::VMOVRRD, dl, DAG.getVTList(MVT::i32, MVT::i32), |
| 2977 | &Tmp1, 1).getValue(1); |
| 2978 | Tmp1 = DAG.getNode(ISD::BITCAST, dl, MVT::i32, Tmp1); |
| 2979 | |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 2980 | // Or in the signbit with integer operations. |
| 2981 | SDValue Mask1 = DAG.getConstant(0x80000000, MVT::i32); |
| 2982 | SDValue Mask2 = DAG.getConstant(0x7fffffff, MVT::i32); |
| 2983 | Tmp1 = DAG.getNode(ISD::AND, dl, MVT::i32, Tmp1, Mask1); |
| 2984 | if (VT == MVT::f32) { |
| 2985 | Tmp0 = DAG.getNode(ISD::AND, dl, MVT::i32, |
| 2986 | DAG.getNode(ISD::BITCAST, dl, MVT::i32, Tmp0), Mask2); |
| 2987 | return DAG.getNode(ISD::BITCAST, dl, MVT::f32, |
| 2988 | DAG.getNode(ISD::OR, dl, MVT::i32, Tmp0, Tmp1)); |
Evan Cheng | c143dd4 | 2011-02-11 02:28:55 +0000 | [diff] [blame] | 2989 | } |
| 2990 | |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 2991 | // f64: Or the high part with signbit and then combine two parts. |
| 2992 | Tmp0 = DAG.getNode(ARMISD::VMOVRRD, dl, DAG.getVTList(MVT::i32, MVT::i32), |
| 2993 | &Tmp0, 1); |
| 2994 | SDValue Lo = Tmp0.getValue(0); |
| 2995 | SDValue Hi = DAG.getNode(ISD::AND, dl, MVT::i32, Tmp0.getValue(1), Mask2); |
| 2996 | Hi = DAG.getNode(ISD::OR, dl, MVT::i32, Hi, Tmp1); |
| 2997 | return DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2998 | } |
| 2999 | |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3000 | SDValue ARMTargetLowering::LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const{ |
| 3001 | MachineFunction &MF = DAG.getMachineFunction(); |
| 3002 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 3003 | MFI->setReturnAddressIsTaken(true); |
| 3004 | |
| 3005 | EVT VT = Op.getValueType(); |
| 3006 | DebugLoc dl = Op.getDebugLoc(); |
| 3007 | unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
| 3008 | if (Depth) { |
| 3009 | SDValue FrameAddr = LowerFRAMEADDR(Op, DAG); |
| 3010 | SDValue Offset = DAG.getConstant(4, MVT::i32); |
| 3011 | return DAG.getLoad(VT, dl, DAG.getEntryNode(), |
| 3012 | DAG.getNode(ISD::ADD, dl, VT, FrameAddr, Offset), |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 3013 | MachinePointerInfo(), false, false, 0); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3014 | } |
| 3015 | |
| 3016 | // 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] | 3017 | unsigned Reg = MF.addLiveIn(ARM::LR, getRegClassFor(MVT::i32)); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3018 | return DAG.getCopyFromReg(DAG.getEntryNode(), dl, Reg, VT); |
| 3019 | } |
| 3020 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 3021 | SDValue ARMTargetLowering::LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const { |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3022 | MachineFrameInfo *MFI = DAG.getMachineFunction().getFrameInfo(); |
| 3023 | MFI->setFrameAddressIsTaken(true); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3024 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3025 | EVT VT = Op.getValueType(); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3026 | DebugLoc dl = Op.getDebugLoc(); // FIXME probably not meaningful |
| 3027 | unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
Evan Cheng | cd82861 | 2009-06-18 23:14:30 +0000 | [diff] [blame] | 3028 | unsigned FrameReg = (Subtarget->isThumb() || Subtarget->isTargetDarwin()) |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3029 | ? ARM::R7 : ARM::R11; |
| 3030 | SDValue FrameAddr = DAG.getCopyFromReg(DAG.getEntryNode(), dl, FrameReg, VT); |
| 3031 | while (Depth--) |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 3032 | FrameAddr = DAG.getLoad(VT, dl, DAG.getEntryNode(), FrameAddr, |
| 3033 | MachinePointerInfo(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 3034 | false, false, 0); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3035 | return FrameAddr; |
| 3036 | } |
| 3037 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3038 | /// ExpandBITCAST - If the target supports VFP, this function is called to |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3039 | /// expand a bit convert where either the source or destination type is i64 to |
| 3040 | /// use a VMOVDRR or VMOVRRD node. This should not be done when the non-i64 |
| 3041 | /// operand type is illegal (e.g., v2f32 for a target that doesn't support |
| 3042 | /// vectors), since the legalizer won't know what to do with that. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3043 | static SDValue ExpandBITCAST(SDNode *N, SelectionDAG &DAG) { |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3044 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 3045 | DebugLoc dl = N->getDebugLoc(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3046 | SDValue Op = N->getOperand(0); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 3047 | |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3048 | // This function is only supposed to be called for i64 types, either as the |
| 3049 | // source or destination of the bit convert. |
| 3050 | EVT SrcVT = Op.getValueType(); |
| 3051 | EVT DstVT = N->getValueType(0); |
| 3052 | assert((SrcVT == MVT::i64 || DstVT == MVT::i64) && |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3053 | "ExpandBITCAST called for non-i64 type"); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 3054 | |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3055 | // Turn i64->f64 into VMOVDRR. |
| 3056 | if (SrcVT == MVT::i64 && TLI.isTypeLegal(DstVT)) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3057 | SDValue Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Op, |
| 3058 | DAG.getConstant(0, MVT::i32)); |
| 3059 | SDValue Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Op, |
| 3060 | DAG.getConstant(1, MVT::i32)); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3061 | return DAG.getNode(ISD::BITCAST, dl, DstVT, |
Bob Wilson | 1114f56 | 2010-06-11 22:45:25 +0000 | [diff] [blame] | 3062 | DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi)); |
Evan Cheng | c7c7729 | 2008-11-04 19:57:48 +0000 | [diff] [blame] | 3063 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3064 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 3065 | // Turn f64->i64 into VMOVRRD. |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3066 | if (DstVT == MVT::i64 && TLI.isTypeLegal(SrcVT)) { |
| 3067 | SDValue Cvt = DAG.getNode(ARMISD::VMOVRRD, dl, |
| 3068 | DAG.getVTList(MVT::i32, MVT::i32), &Op, 1); |
| 3069 | // Merge the pieces into a single i64 value. |
| 3070 | return DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Cvt, Cvt.getValue(1)); |
| 3071 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3072 | |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3073 | return SDValue(); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3074 | } |
| 3075 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3076 | /// getZeroVector - Returns a vector of specified type with all zero elements. |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3077 | /// Zero vectors are used to represent vector negation and in those cases |
| 3078 | /// will be implemented with the NEON VNEG instruction. However, VNEG does |
| 3079 | /// not support i64 elements, so sometimes the zero vectors will need to be |
| 3080 | /// explicitly constructed. Regardless, use a canonical VMOV to create the |
| 3081 | /// zero vector. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3082 | static SDValue getZeroVector(EVT VT, SelectionDAG &DAG, DebugLoc dl) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3083 | assert(VT.isVector() && "Expected a vector type"); |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3084 | // The canonical modified immediate encoding of a zero vector is....0! |
| 3085 | SDValue EncodedVal = DAG.getTargetConstant(0, MVT::i32); |
| 3086 | EVT VmovVT = VT.is128BitVector() ? MVT::v4i32 : MVT::v2i32; |
| 3087 | SDValue Vmov = DAG.getNode(ARMISD::VMOVIMM, dl, VmovVT, EncodedVal); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3088 | return DAG.getNode(ISD::BITCAST, dl, VT, Vmov); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3089 | } |
| 3090 | |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3091 | /// LowerShiftRightParts - Lower SRA_PARTS, which returns two |
| 3092 | /// 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] | 3093 | SDValue ARMTargetLowering::LowerShiftRightParts(SDValue Op, |
| 3094 | SelectionDAG &DAG) const { |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3095 | assert(Op.getNumOperands() == 3 && "Not a double-shift!"); |
| 3096 | EVT VT = Op.getValueType(); |
| 3097 | unsigned VTBits = VT.getSizeInBits(); |
| 3098 | DebugLoc dl = Op.getDebugLoc(); |
| 3099 | SDValue ShOpLo = Op.getOperand(0); |
| 3100 | SDValue ShOpHi = Op.getOperand(1); |
| 3101 | SDValue ShAmt = Op.getOperand(2); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3102 | SDValue ARMcc; |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 3103 | unsigned Opc = (Op.getOpcode() == ISD::SRA_PARTS) ? ISD::SRA : ISD::SRL; |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3104 | |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 3105 | assert(Op.getOpcode() == ISD::SRA_PARTS || Op.getOpcode() == ISD::SRL_PARTS); |
| 3106 | |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3107 | SDValue RevShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, |
| 3108 | DAG.getConstant(VTBits, MVT::i32), ShAmt); |
| 3109 | SDValue Tmp1 = DAG.getNode(ISD::SRL, dl, VT, ShOpLo, ShAmt); |
| 3110 | SDValue ExtraShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, ShAmt, |
| 3111 | DAG.getConstant(VTBits, MVT::i32)); |
| 3112 | SDValue Tmp2 = DAG.getNode(ISD::SHL, dl, VT, ShOpHi, RevShAmt); |
| 3113 | SDValue FalseVal = DAG.getNode(ISD::OR, dl, VT, Tmp1, Tmp2); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 3114 | SDValue TrueVal = DAG.getNode(Opc, dl, VT, ShOpHi, ExtraShAmt); |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3115 | |
| 3116 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| 3117 | SDValue Cmp = getARMCmp(ExtraShAmt, DAG.getConstant(0, MVT::i32), ISD::SETGE, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3118 | ARMcc, DAG, dl); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 3119 | SDValue Hi = DAG.getNode(Opc, dl, VT, ShOpHi, ShAmt); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3120 | SDValue Lo = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, ARMcc, |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3121 | CCR, Cmp); |
| 3122 | |
| 3123 | SDValue Ops[2] = { Lo, Hi }; |
| 3124 | return DAG.getMergeValues(Ops, 2, dl); |
| 3125 | } |
| 3126 | |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3127 | /// LowerShiftLeftParts - Lower SHL_PARTS, which returns two |
| 3128 | /// 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] | 3129 | SDValue ARMTargetLowering::LowerShiftLeftParts(SDValue Op, |
| 3130 | SelectionDAG &DAG) const { |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3131 | assert(Op.getNumOperands() == 3 && "Not a double-shift!"); |
| 3132 | EVT VT = Op.getValueType(); |
| 3133 | unsigned VTBits = VT.getSizeInBits(); |
| 3134 | DebugLoc dl = Op.getDebugLoc(); |
| 3135 | SDValue ShOpLo = Op.getOperand(0); |
| 3136 | SDValue ShOpHi = Op.getOperand(1); |
| 3137 | SDValue ShAmt = Op.getOperand(2); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3138 | SDValue ARMcc; |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3139 | |
| 3140 | assert(Op.getOpcode() == ISD::SHL_PARTS); |
| 3141 | SDValue RevShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, |
| 3142 | DAG.getConstant(VTBits, MVT::i32), ShAmt); |
| 3143 | SDValue Tmp1 = DAG.getNode(ISD::SRL, dl, VT, ShOpLo, RevShAmt); |
| 3144 | SDValue ExtraShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, ShAmt, |
| 3145 | DAG.getConstant(VTBits, MVT::i32)); |
| 3146 | SDValue Tmp2 = DAG.getNode(ISD::SHL, dl, VT, ShOpHi, ShAmt); |
| 3147 | SDValue Tmp3 = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ExtraShAmt); |
| 3148 | |
| 3149 | SDValue FalseVal = DAG.getNode(ISD::OR, dl, VT, Tmp1, Tmp2); |
| 3150 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| 3151 | SDValue Cmp = getARMCmp(ExtraShAmt, DAG.getConstant(0, MVT::i32), ISD::SETGE, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3152 | ARMcc, DAG, dl); |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3153 | SDValue Lo = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ShAmt); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3154 | SDValue Hi = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, Tmp3, ARMcc, |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3155 | CCR, Cmp); |
| 3156 | |
| 3157 | SDValue Ops[2] = { Lo, Hi }; |
| 3158 | return DAG.getMergeValues(Ops, 2, dl); |
| 3159 | } |
| 3160 | |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 3161 | SDValue ARMTargetLowering::LowerFLT_ROUNDS_(SDValue Op, |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 3162 | SelectionDAG &DAG) const { |
| 3163 | // The rounding mode is in bits 23:22 of the FPSCR. |
| 3164 | // The ARM rounding mode value to FLT_ROUNDS mapping is 0->1, 1->2, 2->3, 3->0 |
| 3165 | // The formula we use to implement this is (((FPSCR + 1 << 22) >> 22) & 3) |
| 3166 | // so that the shift + and get folded into a bitfield extract. |
| 3167 | DebugLoc dl = Op.getDebugLoc(); |
| 3168 | SDValue FPSCR = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::i32, |
| 3169 | DAG.getConstant(Intrinsic::arm_get_fpscr, |
| 3170 | MVT::i32)); |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 3171 | SDValue FltRounds = DAG.getNode(ISD::ADD, dl, MVT::i32, FPSCR, |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 3172 | DAG.getConstant(1U << 22, MVT::i32)); |
| 3173 | SDValue RMODE = DAG.getNode(ISD::SRL, dl, MVT::i32, FltRounds, |
| 3174 | DAG.getConstant(22, MVT::i32)); |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 3175 | return DAG.getNode(ISD::AND, dl, MVT::i32, RMODE, |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 3176 | DAG.getConstant(3, MVT::i32)); |
| 3177 | } |
| 3178 | |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 3179 | static SDValue LowerCTTZ(SDNode *N, SelectionDAG &DAG, |
| 3180 | const ARMSubtarget *ST) { |
| 3181 | EVT VT = N->getValueType(0); |
| 3182 | DebugLoc dl = N->getDebugLoc(); |
| 3183 | |
| 3184 | if (!ST->hasV6T2Ops()) |
| 3185 | return SDValue(); |
| 3186 | |
| 3187 | SDValue rbit = DAG.getNode(ARMISD::RBIT, dl, VT, N->getOperand(0)); |
| 3188 | return DAG.getNode(ISD::CTLZ, dl, VT, rbit); |
| 3189 | } |
| 3190 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3191 | static SDValue LowerShift(SDNode *N, SelectionDAG &DAG, |
| 3192 | const ARMSubtarget *ST) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3193 | EVT VT = N->getValueType(0); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3194 | DebugLoc dl = N->getDebugLoc(); |
| 3195 | |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3196 | if (!VT.isVector()) |
| 3197 | return SDValue(); |
| 3198 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3199 | // Lower vector shifts on NEON to use VSHL. |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3200 | assert(ST->hasNEON() && "unexpected vector shift"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3201 | |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3202 | // Left shifts translate directly to the vshiftu intrinsic. |
| 3203 | if (N->getOpcode() == ISD::SHL) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3204 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT, |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3205 | DAG.getConstant(Intrinsic::arm_neon_vshiftu, MVT::i32), |
| 3206 | N->getOperand(0), N->getOperand(1)); |
| 3207 | |
| 3208 | assert((N->getOpcode() == ISD::SRA || |
| 3209 | N->getOpcode() == ISD::SRL) && "unexpected vector shift opcode"); |
| 3210 | |
| 3211 | // NEON uses the same intrinsics for both left and right shifts. For |
| 3212 | // right shifts, the shift amounts are negative, so negate the vector of |
| 3213 | // shift amounts. |
| 3214 | EVT ShiftVT = N->getOperand(1).getValueType(); |
| 3215 | SDValue NegatedCount = DAG.getNode(ISD::SUB, dl, ShiftVT, |
| 3216 | getZeroVector(ShiftVT, DAG, dl), |
| 3217 | N->getOperand(1)); |
| 3218 | Intrinsic::ID vshiftInt = (N->getOpcode() == ISD::SRA ? |
| 3219 | Intrinsic::arm_neon_vshifts : |
| 3220 | Intrinsic::arm_neon_vshiftu); |
| 3221 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT, |
| 3222 | DAG.getConstant(vshiftInt, MVT::i32), |
| 3223 | N->getOperand(0), NegatedCount); |
| 3224 | } |
| 3225 | |
| 3226 | static SDValue Expand64BitShift(SDNode *N, SelectionDAG &DAG, |
| 3227 | const ARMSubtarget *ST) { |
| 3228 | EVT VT = N->getValueType(0); |
| 3229 | DebugLoc dl = N->getDebugLoc(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3230 | |
Eli Friedman | ce392eb | 2009-08-22 03:13:10 +0000 | [diff] [blame] | 3231 | // We can get here for a node like i32 = ISD::SHL i32, i64 |
| 3232 | if (VT != MVT::i64) |
| 3233 | return SDValue(); |
| 3234 | |
| 3235 | assert((N->getOpcode() == ISD::SRL || N->getOpcode() == ISD::SRA) && |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3236 | "Unknown shift to lower!"); |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 3237 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3238 | // We only lower SRA, SRL of 1 here, all others use generic lowering. |
| 3239 | if (!isa<ConstantSDNode>(N->getOperand(1)) || |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 3240 | cast<ConstantSDNode>(N->getOperand(1))->getZExtValue() != 1) |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 3241 | return SDValue(); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3242 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3243 | // If we are in thumb mode, we don't have RRX. |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 3244 | if (ST->isThumb1Only()) return SDValue(); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3245 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3246 | // 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] | 3247 | 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] | 3248 | DAG.getConstant(0, MVT::i32)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3249 | 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] | 3250 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3251 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3252 | // First, build a SRA_FLAG/SRL_FLAG op, which shifts the top part by one and |
| 3253 | // captures the result into a carry flag. |
| 3254 | unsigned Opc = N->getOpcode() == ISD::SRL ? ARMISD::SRL_FLAG:ARMISD::SRA_FLAG; |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 3255 | 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] | 3256 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3257 | // 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] | 3258 | Lo = DAG.getNode(ARMISD::RRX, dl, MVT::i32, Lo, Hi.getValue(1)); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3259 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3260 | // Merge the pieces into a single i64 value. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3261 | return DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Lo, Hi); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3262 | } |
| 3263 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3264 | static SDValue LowerVSETCC(SDValue Op, SelectionDAG &DAG) { |
| 3265 | SDValue TmpOp0, TmpOp1; |
| 3266 | bool Invert = false; |
| 3267 | bool Swap = false; |
| 3268 | unsigned Opc = 0; |
| 3269 | |
| 3270 | SDValue Op0 = Op.getOperand(0); |
| 3271 | SDValue Op1 = Op.getOperand(1); |
| 3272 | SDValue CC = Op.getOperand(2); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3273 | EVT VT = Op.getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3274 | ISD::CondCode SetCCOpcode = cast<CondCodeSDNode>(CC)->get(); |
| 3275 | DebugLoc dl = Op.getDebugLoc(); |
| 3276 | |
| 3277 | if (Op.getOperand(1).getValueType().isFloatingPoint()) { |
| 3278 | switch (SetCCOpcode) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 3279 | default: llvm_unreachable("Illegal FP comparison"); break; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3280 | case ISD::SETUNE: |
| 3281 | case ISD::SETNE: Invert = true; // Fallthrough |
| 3282 | case ISD::SETOEQ: |
| 3283 | case ISD::SETEQ: Opc = ARMISD::VCEQ; break; |
| 3284 | case ISD::SETOLT: |
| 3285 | case ISD::SETLT: Swap = true; // Fallthrough |
| 3286 | case ISD::SETOGT: |
| 3287 | case ISD::SETGT: Opc = ARMISD::VCGT; break; |
| 3288 | case ISD::SETOLE: |
| 3289 | case ISD::SETLE: Swap = true; // Fallthrough |
| 3290 | case ISD::SETOGE: |
| 3291 | case ISD::SETGE: Opc = ARMISD::VCGE; break; |
| 3292 | case ISD::SETUGE: Swap = true; // Fallthrough |
| 3293 | case ISD::SETULE: Invert = true; Opc = ARMISD::VCGT; break; |
| 3294 | case ISD::SETUGT: Swap = true; // Fallthrough |
| 3295 | case ISD::SETULT: Invert = true; Opc = ARMISD::VCGE; break; |
| 3296 | case ISD::SETUEQ: Invert = true; // Fallthrough |
| 3297 | case ISD::SETONE: |
| 3298 | // Expand this to (OLT | OGT). |
| 3299 | TmpOp0 = Op0; |
| 3300 | TmpOp1 = Op1; |
| 3301 | Opc = ISD::OR; |
| 3302 | Op0 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp1, TmpOp0); |
| 3303 | Op1 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp0, TmpOp1); |
| 3304 | break; |
| 3305 | case ISD::SETUO: Invert = true; // Fallthrough |
| 3306 | case ISD::SETO: |
| 3307 | // Expand this to (OLT | OGE). |
| 3308 | TmpOp0 = Op0; |
| 3309 | TmpOp1 = Op1; |
| 3310 | Opc = ISD::OR; |
| 3311 | Op0 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp1, TmpOp0); |
| 3312 | Op1 = DAG.getNode(ARMISD::VCGE, dl, VT, TmpOp0, TmpOp1); |
| 3313 | break; |
| 3314 | } |
| 3315 | } else { |
| 3316 | // Integer comparisons. |
| 3317 | switch (SetCCOpcode) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 3318 | default: llvm_unreachable("Illegal integer comparison"); break; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3319 | case ISD::SETNE: Invert = true; |
| 3320 | case ISD::SETEQ: Opc = ARMISD::VCEQ; break; |
| 3321 | case ISD::SETLT: Swap = true; |
| 3322 | case ISD::SETGT: Opc = ARMISD::VCGT; break; |
| 3323 | case ISD::SETLE: Swap = true; |
| 3324 | case ISD::SETGE: Opc = ARMISD::VCGE; break; |
| 3325 | case ISD::SETULT: Swap = true; |
| 3326 | case ISD::SETUGT: Opc = ARMISD::VCGTU; break; |
| 3327 | case ISD::SETULE: Swap = true; |
| 3328 | case ISD::SETUGE: Opc = ARMISD::VCGEU; break; |
| 3329 | } |
| 3330 | |
Nick Lewycky | 7f6aa2b | 2009-07-08 03:04:38 +0000 | [diff] [blame] | 3331 | // Detect VTST (Vector Test Bits) = icmp ne (and (op0, op1), zero). |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3332 | if (Opc == ARMISD::VCEQ) { |
| 3333 | |
| 3334 | SDValue AndOp; |
| 3335 | if (ISD::isBuildVectorAllZeros(Op1.getNode())) |
| 3336 | AndOp = Op0; |
| 3337 | else if (ISD::isBuildVectorAllZeros(Op0.getNode())) |
| 3338 | AndOp = Op1; |
| 3339 | |
| 3340 | // Ignore bitconvert. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3341 | if (AndOp.getNode() && AndOp.getOpcode() == ISD::BITCAST) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3342 | AndOp = AndOp.getOperand(0); |
| 3343 | |
| 3344 | if (AndOp.getNode() && AndOp.getOpcode() == ISD::AND) { |
| 3345 | Opc = ARMISD::VTST; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3346 | Op0 = DAG.getNode(ISD::BITCAST, dl, VT, AndOp.getOperand(0)); |
| 3347 | Op1 = DAG.getNode(ISD::BITCAST, dl, VT, AndOp.getOperand(1)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3348 | Invert = !Invert; |
| 3349 | } |
| 3350 | } |
| 3351 | } |
| 3352 | |
| 3353 | if (Swap) |
| 3354 | std::swap(Op0, Op1); |
| 3355 | |
Owen Anderson | c24cb35 | 2010-11-08 23:21:22 +0000 | [diff] [blame] | 3356 | // If one of the operands is a constant vector zero, attempt to fold the |
| 3357 | // comparison to a specialized compare-against-zero form. |
| 3358 | SDValue SingleOp; |
| 3359 | if (ISD::isBuildVectorAllZeros(Op1.getNode())) |
| 3360 | SingleOp = Op0; |
| 3361 | else if (ISD::isBuildVectorAllZeros(Op0.getNode())) { |
| 3362 | if (Opc == ARMISD::VCGE) |
| 3363 | Opc = ARMISD::VCLEZ; |
| 3364 | else if (Opc == ARMISD::VCGT) |
| 3365 | Opc = ARMISD::VCLTZ; |
| 3366 | SingleOp = Op1; |
| 3367 | } |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3368 | |
Owen Anderson | c24cb35 | 2010-11-08 23:21:22 +0000 | [diff] [blame] | 3369 | SDValue Result; |
| 3370 | if (SingleOp.getNode()) { |
| 3371 | switch (Opc) { |
| 3372 | case ARMISD::VCEQ: |
| 3373 | Result = DAG.getNode(ARMISD::VCEQZ, dl, VT, SingleOp); break; |
| 3374 | case ARMISD::VCGE: |
| 3375 | Result = DAG.getNode(ARMISD::VCGEZ, dl, VT, SingleOp); break; |
| 3376 | case ARMISD::VCLEZ: |
| 3377 | Result = DAG.getNode(ARMISD::VCLEZ, dl, VT, SingleOp); break; |
| 3378 | case ARMISD::VCGT: |
| 3379 | Result = DAG.getNode(ARMISD::VCGTZ, dl, VT, SingleOp); break; |
| 3380 | case ARMISD::VCLTZ: |
| 3381 | Result = DAG.getNode(ARMISD::VCLTZ, dl, VT, SingleOp); break; |
| 3382 | default: |
| 3383 | Result = DAG.getNode(Opc, dl, VT, Op0, Op1); |
| 3384 | } |
| 3385 | } else { |
| 3386 | Result = DAG.getNode(Opc, dl, VT, Op0, Op1); |
| 3387 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3388 | |
| 3389 | if (Invert) |
| 3390 | Result = DAG.getNOT(dl, Result, VT); |
| 3391 | |
| 3392 | return Result; |
| 3393 | } |
| 3394 | |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 3395 | /// isNEONModifiedImm - Check if the specified splat value corresponds to a |
| 3396 | /// valid vector constant for a NEON instruction with a "modified immediate" |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3397 | /// operand (e.g., VMOV). If so, return the encoded value. |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 3398 | static SDValue isNEONModifiedImm(uint64_t SplatBits, uint64_t SplatUndef, |
| 3399 | unsigned SplatBitSize, SelectionDAG &DAG, |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3400 | EVT &VT, bool is128Bits, NEONModImmType type) { |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3401 | unsigned OpCmode, Imm; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3402 | |
Bob Wilson | 827b210 | 2010-06-15 19:05:35 +0000 | [diff] [blame] | 3403 | // SplatBitSize is set to the smallest size that splats the vector, so a |
| 3404 | // zero vector will always have SplatBitSize == 8. However, NEON modified |
| 3405 | // immediate instructions others than VMOV do not support the 8-bit encoding |
| 3406 | // of a zero vector, and the default encoding of zero is supposed to be the |
| 3407 | // 32-bit version. |
| 3408 | if (SplatBits == 0) |
| 3409 | SplatBitSize = 32; |
| 3410 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3411 | switch (SplatBitSize) { |
| 3412 | case 8: |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3413 | if (type != VMOVModImm) |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 3414 | return SDValue(); |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3415 | // Any 1-byte value is OK. Op=0, Cmode=1110. |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3416 | assert((SplatBits & ~0xff) == 0 && "one byte splat value is too big"); |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3417 | OpCmode = 0xe; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3418 | Imm = SplatBits; |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3419 | VT = is128Bits ? MVT::v16i8 : MVT::v8i8; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3420 | break; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3421 | |
| 3422 | case 16: |
| 3423 | // 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] | 3424 | VT = is128Bits ? MVT::v8i16 : MVT::v4i16; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3425 | if ((SplatBits & ~0xff) == 0) { |
| 3426 | // Value = 0x00nn: Op=x, Cmode=100x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3427 | OpCmode = 0x8; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3428 | Imm = SplatBits; |
| 3429 | break; |
| 3430 | } |
| 3431 | if ((SplatBits & ~0xff00) == 0) { |
| 3432 | // Value = 0xnn00: Op=x, Cmode=101x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3433 | OpCmode = 0xa; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3434 | Imm = SplatBits >> 8; |
| 3435 | break; |
| 3436 | } |
| 3437 | return SDValue(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3438 | |
| 3439 | case 32: |
| 3440 | // NEON's 32-bit VMOV supports splat values where: |
| 3441 | // * only one byte is nonzero, or |
| 3442 | // * the least significant byte is 0xff and the second byte is nonzero, or |
| 3443 | // * the least significant 2 bytes are 0xff and the third is nonzero. |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3444 | VT = is128Bits ? MVT::v4i32 : MVT::v2i32; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3445 | if ((SplatBits & ~0xff) == 0) { |
| 3446 | // Value = 0x000000nn: Op=x, Cmode=000x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3447 | OpCmode = 0; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3448 | Imm = SplatBits; |
| 3449 | break; |
| 3450 | } |
| 3451 | if ((SplatBits & ~0xff00) == 0) { |
| 3452 | // Value = 0x0000nn00: Op=x, Cmode=001x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3453 | OpCmode = 0x2; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3454 | Imm = SplatBits >> 8; |
| 3455 | break; |
| 3456 | } |
| 3457 | if ((SplatBits & ~0xff0000) == 0) { |
| 3458 | // Value = 0x00nn0000: Op=x, Cmode=010x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3459 | OpCmode = 0x4; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3460 | Imm = SplatBits >> 16; |
| 3461 | break; |
| 3462 | } |
| 3463 | if ((SplatBits & ~0xff000000) == 0) { |
| 3464 | // Value = 0xnn000000: Op=x, Cmode=011x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3465 | OpCmode = 0x6; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3466 | Imm = SplatBits >> 24; |
| 3467 | break; |
| 3468 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3469 | |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3470 | // cmode == 0b1100 and cmode == 0b1101 are not supported for VORR or VBIC |
| 3471 | if (type == OtherModImm) return SDValue(); |
| 3472 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3473 | if ((SplatBits & ~0xffff) == 0 && |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3474 | ((SplatBits | SplatUndef) & 0xff) == 0xff) { |
| 3475 | // Value = 0x0000nnff: Op=x, Cmode=1100. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3476 | OpCmode = 0xc; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3477 | Imm = SplatBits >> 8; |
| 3478 | SplatBits |= 0xff; |
| 3479 | break; |
| 3480 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3481 | |
| 3482 | if ((SplatBits & ~0xffffff) == 0 && |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3483 | ((SplatBits | SplatUndef) & 0xffff) == 0xffff) { |
| 3484 | // Value = 0x00nnffff: Op=x, Cmode=1101. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3485 | OpCmode = 0xd; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3486 | Imm = SplatBits >> 16; |
| 3487 | SplatBits |= 0xffff; |
| 3488 | break; |
| 3489 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3490 | |
| 3491 | // Note: there are a few 32-bit splat values (specifically: 00ffff00, |
| 3492 | // ff000000, ff0000ff, and ffff00ff) that are valid for VMOV.I64 but not |
| 3493 | // VMOV.I32. A (very) minor optimization would be to replicate the value |
| 3494 | // and fall through here to test for a valid 64-bit splat. But, then the |
| 3495 | // caller would also need to check and handle the change in size. |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3496 | return SDValue(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3497 | |
| 3498 | case 64: { |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3499 | if (type != VMOVModImm) |
Bob Wilson | 827b210 | 2010-06-15 19:05:35 +0000 | [diff] [blame] | 3500 | return SDValue(); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 3501 | // 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] | 3502 | uint64_t BitMask = 0xff; |
| 3503 | uint64_t Val = 0; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3504 | unsigned ImmMask = 1; |
| 3505 | Imm = 0; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3506 | for (int ByteNum = 0; ByteNum < 8; ++ByteNum) { |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3507 | if (((SplatBits | SplatUndef) & BitMask) == BitMask) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3508 | Val |= BitMask; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3509 | Imm |= ImmMask; |
| 3510 | } else if ((SplatBits & BitMask) != 0) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3511 | return SDValue(); |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3512 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3513 | BitMask <<= 8; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3514 | ImmMask <<= 1; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3515 | } |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3516 | // Op=1, Cmode=1110. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3517 | OpCmode = 0x1e; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3518 | SplatBits = Val; |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3519 | VT = is128Bits ? MVT::v2i64 : MVT::v1i64; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3520 | break; |
| 3521 | } |
| 3522 | |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3523 | default: |
Bob Wilson | dc076da | 2010-06-19 05:32:09 +0000 | [diff] [blame] | 3524 | llvm_unreachable("unexpected size for isNEONModifiedImm"); |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3525 | return SDValue(); |
| 3526 | } |
| 3527 | |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3528 | unsigned EncodedVal = ARM_AM::createNEONModImm(OpCmode, Imm); |
| 3529 | return DAG.getTargetConstant(EncodedVal, MVT::i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3530 | } |
| 3531 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3532 | static bool isVEXTMask(const SmallVectorImpl<int> &M, EVT VT, |
| 3533 | bool &ReverseVEXT, unsigned &Imm) { |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3534 | unsigned NumElts = VT.getVectorNumElements(); |
| 3535 | ReverseVEXT = false; |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3536 | |
| 3537 | // Assume that the first shuffle index is not UNDEF. Fail if it is. |
| 3538 | if (M[0] < 0) |
| 3539 | return false; |
| 3540 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3541 | Imm = M[0]; |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3542 | |
| 3543 | // If this is a VEXT shuffle, the immediate value is the index of the first |
| 3544 | // element. The other shuffle indices must be the successive elements after |
| 3545 | // the first one. |
| 3546 | unsigned ExpectedElt = Imm; |
| 3547 | for (unsigned i = 1; i < NumElts; ++i) { |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3548 | // Increment the expected index. If it wraps around, it may still be |
| 3549 | // a VEXT but the source vectors must be swapped. |
| 3550 | ExpectedElt += 1; |
| 3551 | if (ExpectedElt == NumElts * 2) { |
| 3552 | ExpectedElt = 0; |
| 3553 | ReverseVEXT = true; |
| 3554 | } |
| 3555 | |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3556 | if (M[i] < 0) continue; // ignore UNDEF indices |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3557 | if (ExpectedElt != static_cast<unsigned>(M[i])) |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3558 | return false; |
| 3559 | } |
| 3560 | |
| 3561 | // Adjust the index value if the source operands will be swapped. |
| 3562 | if (ReverseVEXT) |
| 3563 | Imm -= NumElts; |
| 3564 | |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3565 | return true; |
| 3566 | } |
| 3567 | |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 3568 | /// isVREVMask - Check if a vector shuffle corresponds to a VREV |
| 3569 | /// instruction with the specified blocksize. (The order of the elements |
| 3570 | /// within each block of the vector is reversed.) |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3571 | static bool isVREVMask(const SmallVectorImpl<int> &M, EVT VT, |
| 3572 | unsigned BlockSize) { |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 3573 | assert((BlockSize==16 || BlockSize==32 || BlockSize==64) && |
| 3574 | "Only possible block sizes for VREV are: 16, 32, 64"); |
| 3575 | |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 3576 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 3577 | if (EltSz == 64) |
| 3578 | return false; |
| 3579 | |
| 3580 | unsigned NumElts = VT.getVectorNumElements(); |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3581 | unsigned BlockElts = M[0] + 1; |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3582 | // If the first shuffle index is UNDEF, be optimistic. |
| 3583 | if (M[0] < 0) |
| 3584 | BlockElts = BlockSize / EltSz; |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 3585 | |
| 3586 | if (BlockSize <= EltSz || BlockSize != BlockElts * EltSz) |
| 3587 | return false; |
| 3588 | |
| 3589 | for (unsigned i = 0; i < NumElts; ++i) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3590 | if (M[i] < 0) continue; // ignore UNDEF indices |
| 3591 | if ((unsigned) M[i] != (i - i%BlockElts) + (BlockElts - 1 - i%BlockElts)) |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 3592 | return false; |
| 3593 | } |
| 3594 | |
| 3595 | return true; |
| 3596 | } |
| 3597 | |
Bill Wendling | 0d4c9d9 | 2011-03-15 21:15:20 +0000 | [diff] [blame] | 3598 | static bool isVTBLMask(const SmallVectorImpl<int> &M, EVT VT) { |
| 3599 | // We can handle <8 x i8> vector shuffles. If the index in the mask is out of |
| 3600 | // range, then 0 is placed into the resulting vector. So pretty much any mask |
| 3601 | // of 8 elements can work here. |
| 3602 | return VT == MVT::v8i8 && M.size() == 8; |
| 3603 | } |
| 3604 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3605 | static bool isVTRNMask(const SmallVectorImpl<int> &M, EVT VT, |
| 3606 | unsigned &WhichResult) { |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 3607 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3608 | if (EltSz == 64) |
| 3609 | return false; |
| 3610 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3611 | unsigned NumElts = VT.getVectorNumElements(); |
| 3612 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3613 | for (unsigned i = 0; i < NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3614 | if ((M[i] >= 0 && (unsigned) M[i] != i + WhichResult) || |
| 3615 | (M[i+1] >= 0 && (unsigned) M[i+1] != i + NumElts + WhichResult)) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3616 | return false; |
| 3617 | } |
| 3618 | return true; |
| 3619 | } |
| 3620 | |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3621 | /// isVTRN_v_undef_Mask - Special case of isVTRNMask for canonical form of |
| 3622 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 3623 | /// Mask is e.g., <0, 0, 2, 2> instead of <0, 4, 2, 6>. |
| 3624 | static bool isVTRN_v_undef_Mask(const SmallVectorImpl<int> &M, EVT VT, |
| 3625 | unsigned &WhichResult) { |
| 3626 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3627 | if (EltSz == 64) |
| 3628 | return false; |
| 3629 | |
| 3630 | unsigned NumElts = VT.getVectorNumElements(); |
| 3631 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3632 | for (unsigned i = 0; i < NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3633 | if ((M[i] >= 0 && (unsigned) M[i] != i + WhichResult) || |
| 3634 | (M[i+1] >= 0 && (unsigned) M[i+1] != i + WhichResult)) |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3635 | return false; |
| 3636 | } |
| 3637 | return true; |
| 3638 | } |
| 3639 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3640 | static bool isVUZPMask(const SmallVectorImpl<int> &M, EVT VT, |
| 3641 | unsigned &WhichResult) { |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 3642 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3643 | if (EltSz == 64) |
| 3644 | return false; |
| 3645 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3646 | unsigned NumElts = VT.getVectorNumElements(); |
| 3647 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3648 | for (unsigned i = 0; i != NumElts; ++i) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3649 | if (M[i] < 0) continue; // ignore UNDEF indices |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3650 | if ((unsigned) M[i] != 2 * i + WhichResult) |
| 3651 | return false; |
| 3652 | } |
| 3653 | |
| 3654 | // 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] | 3655 | if (VT.is64BitVector() && EltSz == 32) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3656 | return false; |
| 3657 | |
| 3658 | return true; |
| 3659 | } |
| 3660 | |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3661 | /// isVUZP_v_undef_Mask - Special case of isVUZPMask for canonical form of |
| 3662 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 3663 | /// Mask is e.g., <0, 2, 0, 2> instead of <0, 2, 4, 6>, |
| 3664 | static bool isVUZP_v_undef_Mask(const SmallVectorImpl<int> &M, EVT VT, |
| 3665 | unsigned &WhichResult) { |
| 3666 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3667 | if (EltSz == 64) |
| 3668 | return false; |
| 3669 | |
| 3670 | unsigned Half = VT.getVectorNumElements() / 2; |
| 3671 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3672 | for (unsigned j = 0; j != 2; ++j) { |
| 3673 | unsigned Idx = WhichResult; |
| 3674 | for (unsigned i = 0; i != Half; ++i) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3675 | int MIdx = M[i + j * Half]; |
| 3676 | if (MIdx >= 0 && (unsigned) MIdx != Idx) |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3677 | return false; |
| 3678 | Idx += 2; |
| 3679 | } |
| 3680 | } |
| 3681 | |
| 3682 | // VUZP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32. |
| 3683 | if (VT.is64BitVector() && EltSz == 32) |
| 3684 | return false; |
| 3685 | |
| 3686 | return true; |
| 3687 | } |
| 3688 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3689 | static bool isVZIPMask(const SmallVectorImpl<int> &M, EVT VT, |
| 3690 | unsigned &WhichResult) { |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 3691 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3692 | if (EltSz == 64) |
| 3693 | return false; |
| 3694 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3695 | unsigned NumElts = VT.getVectorNumElements(); |
| 3696 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3697 | unsigned Idx = WhichResult * NumElts / 2; |
| 3698 | for (unsigned i = 0; i != NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3699 | if ((M[i] >= 0 && (unsigned) M[i] != Idx) || |
| 3700 | (M[i+1] >= 0 && (unsigned) M[i+1] != Idx + NumElts)) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3701 | return false; |
| 3702 | Idx += 1; |
| 3703 | } |
| 3704 | |
| 3705 | // 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] | 3706 | if (VT.is64BitVector() && EltSz == 32) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3707 | return false; |
| 3708 | |
| 3709 | return true; |
| 3710 | } |
| 3711 | |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3712 | /// isVZIP_v_undef_Mask - Special case of isVZIPMask for canonical form of |
| 3713 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 3714 | /// Mask is e.g., <0, 0, 1, 1> instead of <0, 4, 1, 5>. |
| 3715 | static bool isVZIP_v_undef_Mask(const SmallVectorImpl<int> &M, EVT VT, |
| 3716 | unsigned &WhichResult) { |
| 3717 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3718 | if (EltSz == 64) |
| 3719 | return false; |
| 3720 | |
| 3721 | unsigned NumElts = VT.getVectorNumElements(); |
| 3722 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3723 | unsigned Idx = WhichResult * NumElts / 2; |
| 3724 | for (unsigned i = 0; i != NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3725 | if ((M[i] >= 0 && (unsigned) M[i] != Idx) || |
| 3726 | (M[i+1] >= 0 && (unsigned) M[i+1] != Idx)) |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3727 | return false; |
| 3728 | Idx += 1; |
| 3729 | } |
| 3730 | |
| 3731 | // VZIP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32. |
| 3732 | if (VT.is64BitVector() && EltSz == 32) |
| 3733 | return false; |
| 3734 | |
| 3735 | return true; |
| 3736 | } |
| 3737 | |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 3738 | // If N is an integer constant that can be moved into a register in one |
| 3739 | // instruction, return an SDValue of such a constant (will become a MOV |
| 3740 | // instruction). Otherwise return null. |
| 3741 | static SDValue IsSingleInstrConstant(SDValue N, SelectionDAG &DAG, |
| 3742 | const ARMSubtarget *ST, DebugLoc dl) { |
| 3743 | uint64_t Val; |
| 3744 | if (!isa<ConstantSDNode>(N)) |
| 3745 | return SDValue(); |
| 3746 | Val = cast<ConstantSDNode>(N)->getZExtValue(); |
| 3747 | |
| 3748 | if (ST->isThumb1Only()) { |
| 3749 | if (Val <= 255 || ~Val <= 255) |
| 3750 | return DAG.getConstant(Val, MVT::i32); |
| 3751 | } else { |
| 3752 | if (ARM_AM::getSOImmVal(Val) != -1 || ARM_AM::getSOImmVal(~Val) != -1) |
| 3753 | return DAG.getConstant(Val, MVT::i32); |
| 3754 | } |
| 3755 | return SDValue(); |
| 3756 | } |
| 3757 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3758 | // If this is a case we can't handle, return null and let the default |
| 3759 | // expansion code take care of it. |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3760 | SDValue ARMTargetLowering::LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG, |
| 3761 | const ARMSubtarget *ST) const { |
Bob Wilson | d06791f | 2009-08-13 01:57:47 +0000 | [diff] [blame] | 3762 | BuildVectorSDNode *BVN = cast<BuildVectorSDNode>(Op.getNode()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3763 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3764 | EVT VT = Op.getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3765 | |
| 3766 | APInt SplatBits, SplatUndef; |
| 3767 | unsigned SplatBitSize; |
| 3768 | bool HasAnyUndefs; |
| 3769 | if (BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { |
Anton Korobeynikov | 71624cc | 2009-08-29 00:08:18 +0000 | [diff] [blame] | 3770 | if (SplatBitSize <= 64) { |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 3771 | // Check if an immediate VMOV works. |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3772 | EVT VmovVT; |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 3773 | SDValue Val = isNEONModifiedImm(SplatBits.getZExtValue(), |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3774 | SplatUndef.getZExtValue(), SplatBitSize, |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3775 | DAG, VmovVT, VT.is128BitVector(), |
| 3776 | VMOVModImm); |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3777 | if (Val.getNode()) { |
| 3778 | SDValue Vmov = DAG.getNode(ARMISD::VMOVIMM, dl, VmovVT, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3779 | return DAG.getNode(ISD::BITCAST, dl, VT, Vmov); |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3780 | } |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 3781 | |
| 3782 | // Try an immediate VMVN. |
| 3783 | uint64_t NegatedImm = (SplatBits.getZExtValue() ^ |
| 3784 | ((1LL << SplatBitSize) - 1)); |
| 3785 | Val = isNEONModifiedImm(NegatedImm, |
| 3786 | SplatUndef.getZExtValue(), SplatBitSize, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3787 | DAG, VmovVT, VT.is128BitVector(), |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3788 | VMVNModImm); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 3789 | if (Val.getNode()) { |
| 3790 | SDValue Vmov = DAG.getNode(ARMISD::VMVNIMM, dl, VmovVT, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3791 | return DAG.getNode(ISD::BITCAST, dl, VT, Vmov); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 3792 | } |
Anton Korobeynikov | 71624cc | 2009-08-29 00:08:18 +0000 | [diff] [blame] | 3793 | } |
Bob Wilson | cf661e2 | 2009-07-30 00:31:25 +0000 | [diff] [blame] | 3794 | } |
| 3795 | |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 3796 | // Scan through the operands to see if only one value is used. |
| 3797 | unsigned NumElts = VT.getVectorNumElements(); |
| 3798 | bool isOnlyLowElement = true; |
| 3799 | bool usesOnlyOneValue = true; |
| 3800 | bool isConstant = true; |
| 3801 | SDValue Value; |
| 3802 | for (unsigned i = 0; i < NumElts; ++i) { |
| 3803 | SDValue V = Op.getOperand(i); |
| 3804 | if (V.getOpcode() == ISD::UNDEF) |
| 3805 | continue; |
| 3806 | if (i > 0) |
| 3807 | isOnlyLowElement = false; |
| 3808 | if (!isa<ConstantFPSDNode>(V) && !isa<ConstantSDNode>(V)) |
| 3809 | isConstant = false; |
| 3810 | |
| 3811 | if (!Value.getNode()) |
| 3812 | Value = V; |
| 3813 | else if (V != Value) |
| 3814 | usesOnlyOneValue = false; |
| 3815 | } |
| 3816 | |
| 3817 | if (!Value.getNode()) |
| 3818 | return DAG.getUNDEF(VT); |
| 3819 | |
| 3820 | if (isOnlyLowElement) |
| 3821 | return DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, VT, Value); |
| 3822 | |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 3823 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 3824 | |
Dale Johannesen | 575cd14 | 2010-10-19 20:00:17 +0000 | [diff] [blame] | 3825 | // Use VDUP for non-constant splats. For f32 constant splats, reduce to |
| 3826 | // i32 and try again. |
| 3827 | if (usesOnlyOneValue && EltSize <= 32) { |
| 3828 | if (!isConstant) |
| 3829 | return DAG.getNode(ARMISD::VDUP, dl, VT, Value); |
| 3830 | if (VT.getVectorElementType().isFloatingPoint()) { |
| 3831 | SmallVector<SDValue, 8> Ops; |
| 3832 | for (unsigned i = 0; i < NumElts; ++i) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3833 | Ops.push_back(DAG.getNode(ISD::BITCAST, dl, MVT::i32, |
Dale Johannesen | 575cd14 | 2010-10-19 20:00:17 +0000 | [diff] [blame] | 3834 | Op.getOperand(i))); |
Nate Begeman | bf5be26 | 2010-11-10 21:35:41 +0000 | [diff] [blame] | 3835 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), MVT::i32, NumElts); |
| 3836 | SDValue Val = DAG.getNode(ISD::BUILD_VECTOR, dl, VecVT, &Ops[0], NumElts); |
Dale Johannesen | e4d3159 | 2010-10-20 22:03:37 +0000 | [diff] [blame] | 3837 | Val = LowerBUILD_VECTOR(Val, DAG, ST); |
| 3838 | if (Val.getNode()) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3839 | return DAG.getNode(ISD::BITCAST, dl, VT, Val); |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 3840 | } |
Dale Johannesen | 575cd14 | 2010-10-19 20:00:17 +0000 | [diff] [blame] | 3841 | SDValue Val = IsSingleInstrConstant(Value, DAG, ST, dl); |
| 3842 | if (Val.getNode()) |
| 3843 | return DAG.getNode(ARMISD::VDUP, dl, VT, Val); |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 3844 | } |
| 3845 | |
| 3846 | // If all elements are constants and the case above didn't get hit, fall back |
| 3847 | // to the default expansion, which will generate a load from the constant |
| 3848 | // pool. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 3849 | if (isConstant) |
| 3850 | return SDValue(); |
| 3851 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3852 | // Empirical tests suggest this is rarely worth it for vectors of length <= 2. |
| 3853 | if (NumElts >= 4) { |
| 3854 | SDValue shuffle = ReconstructShuffle(Op, DAG); |
| 3855 | if (shuffle != SDValue()) |
| 3856 | return shuffle; |
| 3857 | } |
| 3858 | |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 3859 | // 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] | 3860 | // the subregisters. Lower it to an ARMISD::BUILD_VECTOR so the operands |
| 3861 | // will be legalized. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 3862 | if (EltSize >= 32) { |
| 3863 | // Do the expansion with floating-point types, since that is what the VFP |
| 3864 | // registers are defined to use, and since i64 is not legal. |
| 3865 | EVT EltVT = EVT::getFloatingPointVT(EltSize); |
| 3866 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), EltVT, NumElts); |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 3867 | SmallVector<SDValue, 8> Ops; |
| 3868 | for (unsigned i = 0; i < NumElts; ++i) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3869 | Ops.push_back(DAG.getNode(ISD::BITCAST, dl, EltVT, Op.getOperand(i))); |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 3870 | SDValue Val = DAG.getNode(ARMISD::BUILD_VECTOR, dl, VecVT, &Ops[0],NumElts); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3871 | return DAG.getNode(ISD::BITCAST, dl, VT, Val); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3872 | } |
| 3873 | |
| 3874 | return SDValue(); |
| 3875 | } |
| 3876 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3877 | // Gather data to see if the operation can be modelled as a |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 3878 | // shuffle in combination with VEXTs. |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 3879 | SDValue ARMTargetLowering::ReconstructShuffle(SDValue Op, |
| 3880 | SelectionDAG &DAG) const { |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3881 | DebugLoc dl = Op.getDebugLoc(); |
| 3882 | EVT VT = Op.getValueType(); |
| 3883 | unsigned NumElts = VT.getVectorNumElements(); |
| 3884 | |
| 3885 | SmallVector<SDValue, 2> SourceVecs; |
| 3886 | SmallVector<unsigned, 2> MinElts; |
| 3887 | SmallVector<unsigned, 2> MaxElts; |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 3888 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3889 | for (unsigned i = 0; i < NumElts; ++i) { |
| 3890 | SDValue V = Op.getOperand(i); |
| 3891 | if (V.getOpcode() == ISD::UNDEF) |
| 3892 | continue; |
| 3893 | else if (V.getOpcode() != ISD::EXTRACT_VECTOR_ELT) { |
| 3894 | // A shuffle can only come from building a vector from various |
| 3895 | // elements of other vectors. |
| 3896 | return SDValue(); |
| 3897 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 3898 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3899 | // Record this extraction against the appropriate vector if possible... |
| 3900 | SDValue SourceVec = V.getOperand(0); |
| 3901 | unsigned EltNo = cast<ConstantSDNode>(V.getOperand(1))->getZExtValue(); |
| 3902 | bool FoundSource = false; |
| 3903 | for (unsigned j = 0; j < SourceVecs.size(); ++j) { |
| 3904 | if (SourceVecs[j] == SourceVec) { |
| 3905 | if (MinElts[j] > EltNo) |
| 3906 | MinElts[j] = EltNo; |
| 3907 | if (MaxElts[j] < EltNo) |
| 3908 | MaxElts[j] = EltNo; |
| 3909 | FoundSource = true; |
| 3910 | break; |
| 3911 | } |
| 3912 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 3913 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3914 | // Or record a new source if not... |
| 3915 | if (!FoundSource) { |
| 3916 | SourceVecs.push_back(SourceVec); |
| 3917 | MinElts.push_back(EltNo); |
| 3918 | MaxElts.push_back(EltNo); |
| 3919 | } |
| 3920 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 3921 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3922 | // Currently only do something sane when at most two source vectors |
| 3923 | // involved. |
| 3924 | if (SourceVecs.size() > 2) |
| 3925 | return SDValue(); |
| 3926 | |
| 3927 | SDValue ShuffleSrcs[2] = {DAG.getUNDEF(VT), DAG.getUNDEF(VT) }; |
| 3928 | int VEXTOffsets[2] = {0, 0}; |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 3929 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3930 | // This loop extracts the usage patterns of the source vectors |
| 3931 | // and prepares appropriate SDValues for a shuffle if possible. |
| 3932 | for (unsigned i = 0; i < SourceVecs.size(); ++i) { |
| 3933 | if (SourceVecs[i].getValueType() == VT) { |
| 3934 | // No VEXT necessary |
| 3935 | ShuffleSrcs[i] = SourceVecs[i]; |
| 3936 | VEXTOffsets[i] = 0; |
| 3937 | continue; |
| 3938 | } else if (SourceVecs[i].getValueType().getVectorNumElements() < NumElts) { |
| 3939 | // It probably isn't worth padding out a smaller vector just to |
| 3940 | // break it down again in a shuffle. |
| 3941 | return SDValue(); |
| 3942 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 3943 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3944 | // Since only 64-bit and 128-bit vectors are legal on ARM and |
| 3945 | // we've eliminated the other cases... |
Bob Wilson | 70f8573 | 2011-01-07 23:40:46 +0000 | [diff] [blame] | 3946 | assert(SourceVecs[i].getValueType().getVectorNumElements() == 2*NumElts && |
| 3947 | "unexpected vector sizes in ReconstructShuffle"); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 3948 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3949 | if (MaxElts[i] - MinElts[i] >= NumElts) { |
| 3950 | // Span too large for a VEXT to cope |
| 3951 | return SDValue(); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 3952 | } |
| 3953 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3954 | if (MinElts[i] >= NumElts) { |
| 3955 | // The extraction can just take the second half |
| 3956 | VEXTOffsets[i] = NumElts; |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 3957 | ShuffleSrcs[i] = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 3958 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3959 | DAG.getIntPtrConstant(NumElts)); |
| 3960 | } else if (MaxElts[i] < NumElts) { |
| 3961 | // The extraction can just take the first half |
| 3962 | VEXTOffsets[i] = 0; |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 3963 | ShuffleSrcs[i] = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 3964 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3965 | DAG.getIntPtrConstant(0)); |
| 3966 | } else { |
| 3967 | // An actual VEXT is needed |
| 3968 | VEXTOffsets[i] = MinElts[i]; |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 3969 | SDValue VEXTSrc1 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 3970 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3971 | DAG.getIntPtrConstant(0)); |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 3972 | SDValue VEXTSrc2 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 3973 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3974 | DAG.getIntPtrConstant(NumElts)); |
| 3975 | ShuffleSrcs[i] = DAG.getNode(ARMISD::VEXT, dl, VT, VEXTSrc1, VEXTSrc2, |
| 3976 | DAG.getConstant(VEXTOffsets[i], MVT::i32)); |
| 3977 | } |
| 3978 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 3979 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3980 | SmallVector<int, 8> Mask; |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 3981 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3982 | for (unsigned i = 0; i < NumElts; ++i) { |
| 3983 | SDValue Entry = Op.getOperand(i); |
| 3984 | if (Entry.getOpcode() == ISD::UNDEF) { |
| 3985 | Mask.push_back(-1); |
| 3986 | continue; |
| 3987 | } |
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 | SDValue ExtractVec = Entry.getOperand(0); |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 3990 | int ExtractElt = cast<ConstantSDNode>(Op.getOperand(i) |
| 3991 | .getOperand(1))->getSExtValue(); |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3992 | if (ExtractVec == SourceVecs[0]) { |
| 3993 | Mask.push_back(ExtractElt - VEXTOffsets[0]); |
| 3994 | } else { |
| 3995 | Mask.push_back(ExtractElt + NumElts - VEXTOffsets[1]); |
| 3996 | } |
| 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 | // Final check before we try to produce nonsense... |
| 4000 | if (isShuffleMaskLegal(Mask, VT)) |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4001 | return DAG.getVectorShuffle(VT, dl, ShuffleSrcs[0], ShuffleSrcs[1], |
| 4002 | &Mask[0]); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4003 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4004 | return SDValue(); |
| 4005 | } |
| 4006 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4007 | /// isShuffleMaskLegal - Targets can use this to indicate that they only |
| 4008 | /// support *some* VECTOR_SHUFFLE operations, those with specific masks. |
| 4009 | /// By default, if a target supports the VECTOR_SHUFFLE node, all mask values |
| 4010 | /// are assumed to be legal. |
| 4011 | bool |
| 4012 | ARMTargetLowering::isShuffleMaskLegal(const SmallVectorImpl<int> &M, |
| 4013 | EVT VT) const { |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4014 | if (VT.getVectorNumElements() == 4 && |
| 4015 | (VT.is128BitVector() || VT.is64BitVector())) { |
| 4016 | unsigned PFIndexes[4]; |
| 4017 | for (unsigned i = 0; i != 4; ++i) { |
| 4018 | if (M[i] < 0) |
| 4019 | PFIndexes[i] = 8; |
| 4020 | else |
| 4021 | PFIndexes[i] = M[i]; |
| 4022 | } |
| 4023 | |
| 4024 | // Compute the index in the perfect shuffle table. |
| 4025 | unsigned PFTableIndex = |
| 4026 | PFIndexes[0]*9*9*9+PFIndexes[1]*9*9+PFIndexes[2]*9+PFIndexes[3]; |
| 4027 | unsigned PFEntry = PerfectShuffleTable[PFTableIndex]; |
| 4028 | unsigned Cost = (PFEntry >> 30); |
| 4029 | |
| 4030 | if (Cost <= 4) |
| 4031 | return true; |
| 4032 | } |
| 4033 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4034 | bool ReverseVEXT; |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4035 | unsigned Imm, WhichResult; |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4036 | |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4037 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 4038 | return (EltSize >= 32 || |
| 4039 | ShuffleVectorSDNode::isSplatMask(&M[0], VT) || |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4040 | isVREVMask(M, VT, 64) || |
| 4041 | isVREVMask(M, VT, 32) || |
| 4042 | isVREVMask(M, VT, 16) || |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4043 | isVEXTMask(M, VT, ReverseVEXT, Imm) || |
Bill Wendling | 0d4c9d9 | 2011-03-15 21:15:20 +0000 | [diff] [blame] | 4044 | isVTBLMask(M, VT) || |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4045 | isVTRNMask(M, VT, WhichResult) || |
| 4046 | isVUZPMask(M, VT, WhichResult) || |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4047 | isVZIPMask(M, VT, WhichResult) || |
| 4048 | isVTRN_v_undef_Mask(M, VT, WhichResult) || |
| 4049 | isVUZP_v_undef_Mask(M, VT, WhichResult) || |
| 4050 | isVZIP_v_undef_Mask(M, VT, WhichResult)); |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4051 | } |
| 4052 | |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4053 | /// GeneratePerfectShuffle - Given an entry in the perfect-shuffle table, emit |
| 4054 | /// the specified operations to build the shuffle. |
| 4055 | static SDValue GeneratePerfectShuffle(unsigned PFEntry, SDValue LHS, |
| 4056 | SDValue RHS, SelectionDAG &DAG, |
| 4057 | DebugLoc dl) { |
| 4058 | unsigned OpNum = (PFEntry >> 26) & 0x0F; |
| 4059 | unsigned LHSID = (PFEntry >> 13) & ((1 << 13)-1); |
| 4060 | unsigned RHSID = (PFEntry >> 0) & ((1 << 13)-1); |
| 4061 | |
| 4062 | enum { |
| 4063 | OP_COPY = 0, // Copy, used for things like <u,u,u,3> to say it is <0,1,2,3> |
| 4064 | OP_VREV, |
| 4065 | OP_VDUP0, |
| 4066 | OP_VDUP1, |
| 4067 | OP_VDUP2, |
| 4068 | OP_VDUP3, |
| 4069 | OP_VEXT1, |
| 4070 | OP_VEXT2, |
| 4071 | OP_VEXT3, |
| 4072 | OP_VUZPL, // VUZP, left result |
| 4073 | OP_VUZPR, // VUZP, right result |
| 4074 | OP_VZIPL, // VZIP, left result |
| 4075 | OP_VZIPR, // VZIP, right result |
| 4076 | OP_VTRNL, // VTRN, left result |
| 4077 | OP_VTRNR // VTRN, right result |
| 4078 | }; |
| 4079 | |
| 4080 | if (OpNum == OP_COPY) { |
| 4081 | if (LHSID == (1*9+2)*9+3) return LHS; |
| 4082 | assert(LHSID == ((4*9+5)*9+6)*9+7 && "Illegal OP_COPY!"); |
| 4083 | return RHS; |
| 4084 | } |
| 4085 | |
| 4086 | SDValue OpLHS, OpRHS; |
| 4087 | OpLHS = GeneratePerfectShuffle(PerfectShuffleTable[LHSID], LHS, RHS, DAG, dl); |
| 4088 | OpRHS = GeneratePerfectShuffle(PerfectShuffleTable[RHSID], LHS, RHS, DAG, dl); |
| 4089 | EVT VT = OpLHS.getValueType(); |
| 4090 | |
| 4091 | switch (OpNum) { |
| 4092 | default: llvm_unreachable("Unknown shuffle opcode!"); |
| 4093 | case OP_VREV: |
| 4094 | return DAG.getNode(ARMISD::VREV64, dl, VT, OpLHS); |
| 4095 | case OP_VDUP0: |
| 4096 | case OP_VDUP1: |
| 4097 | case OP_VDUP2: |
| 4098 | case OP_VDUP3: |
| 4099 | return DAG.getNode(ARMISD::VDUPLANE, dl, VT, |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 4100 | OpLHS, DAG.getConstant(OpNum-OP_VDUP0, MVT::i32)); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4101 | case OP_VEXT1: |
| 4102 | case OP_VEXT2: |
| 4103 | case OP_VEXT3: |
| 4104 | return DAG.getNode(ARMISD::VEXT, dl, VT, |
| 4105 | OpLHS, OpRHS, |
| 4106 | DAG.getConstant(OpNum-OP_VEXT1+1, MVT::i32)); |
| 4107 | case OP_VUZPL: |
| 4108 | case OP_VUZPR: |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 4109 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4110 | OpLHS, OpRHS).getValue(OpNum-OP_VUZPL); |
| 4111 | case OP_VZIPL: |
| 4112 | case OP_VZIPR: |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 4113 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4114 | OpLHS, OpRHS).getValue(OpNum-OP_VZIPL); |
| 4115 | case OP_VTRNL: |
| 4116 | case OP_VTRNR: |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 4117 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), |
| 4118 | OpLHS, OpRHS).getValue(OpNum-OP_VTRNL); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4119 | } |
| 4120 | } |
| 4121 | |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4122 | static SDValue LowerVECTOR_SHUFFLEv8i8(SDValue Op, |
| 4123 | SmallVectorImpl<int> &ShuffleMask, |
| 4124 | SelectionDAG &DAG) { |
| 4125 | // Check to see if we can use the VTBL instruction. |
| 4126 | SDValue V1 = Op.getOperand(0); |
| 4127 | SDValue V2 = Op.getOperand(1); |
| 4128 | DebugLoc DL = Op.getDebugLoc(); |
| 4129 | |
| 4130 | SmallVector<SDValue, 8> VTBLMask; |
| 4131 | for (SmallVectorImpl<int>::iterator |
| 4132 | I = ShuffleMask.begin(), E = ShuffleMask.end(); I != E; ++I) |
| 4133 | VTBLMask.push_back(DAG.getConstant(*I, MVT::i32)); |
| 4134 | |
| 4135 | if (V2.getNode()->getOpcode() == ISD::UNDEF) |
| 4136 | return DAG.getNode(ARMISD::VTBL1, DL, MVT::v8i8, V1, |
| 4137 | DAG.getNode(ISD::BUILD_VECTOR, DL, MVT::v8i8, |
| 4138 | &VTBLMask[0], 8)); |
Bill Wendling | a24cb40 | 2011-03-15 20:47:26 +0000 | [diff] [blame] | 4139 | |
| 4140 | return DAG.getNode(ARMISD::VTBL2, DL, MVT::v8i8, V1, V2, |
| 4141 | DAG.getNode(ISD::BUILD_VECTOR, DL, MVT::v8i8, |
| 4142 | &VTBLMask[0], 8)); |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4143 | } |
| 4144 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4145 | static SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) { |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4146 | SDValue V1 = Op.getOperand(0); |
| 4147 | SDValue V2 = Op.getOperand(1); |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 4148 | DebugLoc dl = Op.getDebugLoc(); |
| 4149 | EVT VT = Op.getValueType(); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4150 | ShuffleVectorSDNode *SVN = cast<ShuffleVectorSDNode>(Op.getNode()); |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4151 | SmallVector<int, 8> ShuffleMask; |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 4152 | |
Bob Wilson | 2886506 | 2009-08-13 02:13:04 +0000 | [diff] [blame] | 4153 | // Convert shuffles that are directly supported on NEON to target-specific |
| 4154 | // DAG nodes, instead of keeping them as shuffles and matching them again |
| 4155 | // during code selection. This is more efficient and avoids the possibility |
| 4156 | // of inconsistencies between legalization and selection. |
Bob Wilson | bfcbb50 | 2009-08-13 06:01:30 +0000 | [diff] [blame] | 4157 | // FIXME: floating-point vectors should be canonicalized to integer vectors |
| 4158 | // of the same time so that they get CSEd properly. |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4159 | SVN->getMask(ShuffleMask); |
| 4160 | |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4161 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 4162 | if (EltSize <= 32) { |
| 4163 | if (ShuffleVectorSDNode::isSplatMask(&ShuffleMask[0], VT)) { |
| 4164 | int Lane = SVN->getSplatIndex(); |
| 4165 | // If this is undef splat, generate it via "just" vdup, if possible. |
| 4166 | if (Lane == -1) Lane = 0; |
Anton Korobeynikov | 2ae0eec | 2009-11-02 00:12:06 +0000 | [diff] [blame] | 4167 | |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4168 | if (Lane == 0 && V1.getOpcode() == ISD::SCALAR_TO_VECTOR) { |
| 4169 | return DAG.getNode(ARMISD::VDUP, dl, VT, V1.getOperand(0)); |
| 4170 | } |
| 4171 | return DAG.getNode(ARMISD::VDUPLANE, dl, VT, V1, |
| 4172 | DAG.getConstant(Lane, MVT::i32)); |
Bob Wilson | c1d287b | 2009-08-14 05:13:08 +0000 | [diff] [blame] | 4173 | } |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4174 | |
| 4175 | bool ReverseVEXT; |
| 4176 | unsigned Imm; |
| 4177 | if (isVEXTMask(ShuffleMask, VT, ReverseVEXT, Imm)) { |
| 4178 | if (ReverseVEXT) |
| 4179 | std::swap(V1, V2); |
| 4180 | return DAG.getNode(ARMISD::VEXT, dl, VT, V1, V2, |
| 4181 | DAG.getConstant(Imm, MVT::i32)); |
| 4182 | } |
| 4183 | |
| 4184 | if (isVREVMask(ShuffleMask, VT, 64)) |
| 4185 | return DAG.getNode(ARMISD::VREV64, dl, VT, V1); |
| 4186 | if (isVREVMask(ShuffleMask, VT, 32)) |
| 4187 | return DAG.getNode(ARMISD::VREV32, dl, VT, V1); |
| 4188 | if (isVREVMask(ShuffleMask, VT, 16)) |
| 4189 | return DAG.getNode(ARMISD::VREV16, dl, VT, V1); |
| 4190 | |
| 4191 | // Check for Neon shuffles that modify both input vectors in place. |
| 4192 | // If both results are used, i.e., if there are two shuffles with the same |
| 4193 | // source operands and with masks corresponding to both results of one of |
| 4194 | // these operations, DAG memoization will ensure that a single node is |
| 4195 | // used for both shuffles. |
| 4196 | unsigned WhichResult; |
| 4197 | if (isVTRNMask(ShuffleMask, VT, WhichResult)) |
| 4198 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), |
| 4199 | V1, V2).getValue(WhichResult); |
| 4200 | if (isVUZPMask(ShuffleMask, VT, WhichResult)) |
| 4201 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), |
| 4202 | V1, V2).getValue(WhichResult); |
| 4203 | if (isVZIPMask(ShuffleMask, VT, WhichResult)) |
| 4204 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), |
| 4205 | V1, V2).getValue(WhichResult); |
| 4206 | |
| 4207 | if (isVTRN_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 4208 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), |
| 4209 | V1, V1).getValue(WhichResult); |
| 4210 | if (isVUZP_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 4211 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), |
| 4212 | V1, V1).getValue(WhichResult); |
| 4213 | if (isVZIP_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 4214 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), |
| 4215 | V1, V1).getValue(WhichResult); |
Bob Wilson | 0ce3710 | 2009-08-14 05:08:32 +0000 | [diff] [blame] | 4216 | } |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 4217 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4218 | // If the shuffle is not directly supported and it has 4 elements, use |
| 4219 | // the PerfectShuffle-generated table to synthesize it from other shuffles. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4220 | unsigned NumElts = VT.getVectorNumElements(); |
| 4221 | if (NumElts == 4) { |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4222 | unsigned PFIndexes[4]; |
| 4223 | for (unsigned i = 0; i != 4; ++i) { |
| 4224 | if (ShuffleMask[i] < 0) |
| 4225 | PFIndexes[i] = 8; |
| 4226 | else |
| 4227 | PFIndexes[i] = ShuffleMask[i]; |
| 4228 | } |
| 4229 | |
| 4230 | // Compute the index in the perfect shuffle table. |
| 4231 | unsigned PFTableIndex = |
| 4232 | 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] | 4233 | unsigned PFEntry = PerfectShuffleTable[PFTableIndex]; |
| 4234 | unsigned Cost = (PFEntry >> 30); |
| 4235 | |
| 4236 | if (Cost <= 4) |
| 4237 | return GeneratePerfectShuffle(PFEntry, V1, V2, DAG, dl); |
| 4238 | } |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 4239 | |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4240 | // Implement shuffles with 32- or 64-bit elements as ARMISD::BUILD_VECTORs. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4241 | if (EltSize >= 32) { |
| 4242 | // Do the expansion with floating-point types, since that is what the VFP |
| 4243 | // registers are defined to use, and since i64 is not legal. |
| 4244 | EVT EltVT = EVT::getFloatingPointVT(EltSize); |
| 4245 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), EltVT, NumElts); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4246 | V1 = DAG.getNode(ISD::BITCAST, dl, VecVT, V1); |
| 4247 | V2 = DAG.getNode(ISD::BITCAST, dl, VecVT, V2); |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4248 | SmallVector<SDValue, 8> Ops; |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4249 | for (unsigned i = 0; i < NumElts; ++i) { |
Bob Wilson | 63b8845 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 4250 | if (ShuffleMask[i] < 0) |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4251 | Ops.push_back(DAG.getUNDEF(EltVT)); |
| 4252 | else |
| 4253 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, EltVT, |
| 4254 | ShuffleMask[i] < (int)NumElts ? V1 : V2, |
| 4255 | DAG.getConstant(ShuffleMask[i] & (NumElts-1), |
| 4256 | MVT::i32))); |
Bob Wilson | 63b8845 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 4257 | } |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4258 | SDValue Val = DAG.getNode(ARMISD::BUILD_VECTOR, dl, VecVT, &Ops[0],NumElts); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4259 | return DAG.getNode(ISD::BITCAST, dl, VT, Val); |
Bob Wilson | 63b8845 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 4260 | } |
| 4261 | |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4262 | if (VT == MVT::v8i8) { |
| 4263 | SDValue NewOp = LowerVECTOR_SHUFFLEv8i8(Op, ShuffleMask, DAG); |
| 4264 | if (NewOp.getNode()) |
| 4265 | return NewOp; |
| 4266 | } |
| 4267 | |
Bob Wilson | 22cac0d | 2009-08-14 05:16:33 +0000 | [diff] [blame] | 4268 | return SDValue(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4269 | } |
| 4270 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4271 | static SDValue LowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) { |
Bob Wilson | 3468c2e | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 4272 | // EXTRACT_VECTOR_ELT is legal only for immediate indexes. |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4273 | SDValue Lane = Op.getOperand(1); |
Bob Wilson | 3468c2e | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 4274 | if (!isa<ConstantSDNode>(Lane)) |
| 4275 | return SDValue(); |
| 4276 | |
| 4277 | SDValue Vec = Op.getOperand(0); |
| 4278 | if (Op.getValueType() == MVT::i32 && |
| 4279 | Vec.getValueType().getVectorElementType().getSizeInBits() < 32) { |
| 4280 | DebugLoc dl = Op.getDebugLoc(); |
| 4281 | return DAG.getNode(ARMISD::VGETLANEu, dl, MVT::i32, Vec, Lane); |
| 4282 | } |
| 4283 | |
| 4284 | return Op; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4285 | } |
| 4286 | |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 4287 | static SDValue LowerCONCAT_VECTORS(SDValue Op, SelectionDAG &DAG) { |
| 4288 | // The only time a CONCAT_VECTORS operation can have legal types is when |
| 4289 | // two 64-bit vectors are concatenated to a 128-bit vector. |
| 4290 | assert(Op.getValueType().is128BitVector() && Op.getNumOperands() == 2 && |
| 4291 | "unexpected CONCAT_VECTORS"); |
| 4292 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4293 | SDValue Val = DAG.getUNDEF(MVT::v2f64); |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 4294 | SDValue Op0 = Op.getOperand(0); |
| 4295 | SDValue Op1 = Op.getOperand(1); |
| 4296 | if (Op0.getOpcode() != ISD::UNDEF) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4297 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Val, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4298 | DAG.getNode(ISD::BITCAST, dl, MVT::f64, Op0), |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 4299 | DAG.getIntPtrConstant(0)); |
| 4300 | if (Op1.getOpcode() != ISD::UNDEF) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4301 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Val, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4302 | DAG.getNode(ISD::BITCAST, dl, MVT::f64, Op1), |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 4303 | DAG.getIntPtrConstant(1)); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4304 | return DAG.getNode(ISD::BITCAST, dl, Op.getValueType(), Val); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4305 | } |
| 4306 | |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 4307 | /// isExtendedBUILD_VECTOR - Check if N is a constant BUILD_VECTOR where each |
| 4308 | /// element has been zero/sign-extended, depending on the isSigned parameter, |
| 4309 | /// from an integer type half its size. |
| 4310 | static bool isExtendedBUILD_VECTOR(SDNode *N, SelectionDAG &DAG, |
| 4311 | bool isSigned) { |
| 4312 | // A v2i64 BUILD_VECTOR will have been legalized to a BITCAST from v4i32. |
| 4313 | EVT VT = N->getValueType(0); |
| 4314 | if (VT == MVT::v2i64 && N->getOpcode() == ISD::BITCAST) { |
| 4315 | SDNode *BVN = N->getOperand(0).getNode(); |
| 4316 | if (BVN->getValueType(0) != MVT::v4i32 || |
| 4317 | BVN->getOpcode() != ISD::BUILD_VECTOR) |
| 4318 | return false; |
| 4319 | unsigned LoElt = DAG.getTargetLoweringInfo().isBigEndian() ? 1 : 0; |
| 4320 | unsigned HiElt = 1 - LoElt; |
| 4321 | ConstantSDNode *Lo0 = dyn_cast<ConstantSDNode>(BVN->getOperand(LoElt)); |
| 4322 | ConstantSDNode *Hi0 = dyn_cast<ConstantSDNode>(BVN->getOperand(HiElt)); |
| 4323 | ConstantSDNode *Lo1 = dyn_cast<ConstantSDNode>(BVN->getOperand(LoElt+2)); |
| 4324 | ConstantSDNode *Hi1 = dyn_cast<ConstantSDNode>(BVN->getOperand(HiElt+2)); |
| 4325 | if (!Lo0 || !Hi0 || !Lo1 || !Hi1) |
| 4326 | return false; |
| 4327 | if (isSigned) { |
| 4328 | if (Hi0->getSExtValue() == Lo0->getSExtValue() >> 32 && |
| 4329 | Hi1->getSExtValue() == Lo1->getSExtValue() >> 32) |
| 4330 | return true; |
| 4331 | } else { |
| 4332 | if (Hi0->isNullValue() && Hi1->isNullValue()) |
| 4333 | return true; |
| 4334 | } |
| 4335 | return false; |
| 4336 | } |
| 4337 | |
| 4338 | if (N->getOpcode() != ISD::BUILD_VECTOR) |
| 4339 | return false; |
| 4340 | |
| 4341 | for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) { |
| 4342 | SDNode *Elt = N->getOperand(i).getNode(); |
| 4343 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Elt)) { |
| 4344 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 4345 | unsigned HalfSize = EltSize / 2; |
| 4346 | if (isSigned) { |
| 4347 | int64_t SExtVal = C->getSExtValue(); |
| 4348 | if ((SExtVal >> HalfSize) != (SExtVal >> EltSize)) |
| 4349 | return false; |
| 4350 | } else { |
| 4351 | if ((C->getZExtValue() >> HalfSize) != 0) |
| 4352 | return false; |
| 4353 | } |
| 4354 | continue; |
| 4355 | } |
| 4356 | return false; |
| 4357 | } |
| 4358 | |
| 4359 | return true; |
| 4360 | } |
| 4361 | |
| 4362 | /// isSignExtended - Check if a node is a vector value that is sign-extended |
| 4363 | /// or a constant BUILD_VECTOR with sign-extended elements. |
| 4364 | static bool isSignExtended(SDNode *N, SelectionDAG &DAG) { |
| 4365 | if (N->getOpcode() == ISD::SIGN_EXTEND || ISD::isSEXTLoad(N)) |
| 4366 | return true; |
| 4367 | if (isExtendedBUILD_VECTOR(N, DAG, true)) |
| 4368 | return true; |
| 4369 | return false; |
| 4370 | } |
| 4371 | |
| 4372 | /// isZeroExtended - Check if a node is a vector value that is zero-extended |
| 4373 | /// or a constant BUILD_VECTOR with zero-extended elements. |
| 4374 | static bool isZeroExtended(SDNode *N, SelectionDAG &DAG) { |
| 4375 | if (N->getOpcode() == ISD::ZERO_EXTEND || ISD::isZEXTLoad(N)) |
| 4376 | return true; |
| 4377 | if (isExtendedBUILD_VECTOR(N, DAG, false)) |
| 4378 | return true; |
| 4379 | return false; |
| 4380 | } |
| 4381 | |
| 4382 | /// SkipExtension - For a node that is a SIGN_EXTEND, ZERO_EXTEND, extending |
| 4383 | /// load, or BUILD_VECTOR with extended elements, return the unextended value. |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4384 | static SDValue SkipExtension(SDNode *N, SelectionDAG &DAG) { |
| 4385 | if (N->getOpcode() == ISD::SIGN_EXTEND || N->getOpcode() == ISD::ZERO_EXTEND) |
| 4386 | return N->getOperand(0); |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 4387 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) |
| 4388 | return DAG.getLoad(LD->getMemoryVT(), N->getDebugLoc(), LD->getChain(), |
| 4389 | LD->getBasePtr(), LD->getPointerInfo(), LD->isVolatile(), |
| 4390 | LD->isNonTemporal(), LD->getAlignment()); |
| 4391 | // Otherwise, the value must be a BUILD_VECTOR. For v2i64, it will |
| 4392 | // have been legalized as a BITCAST from v4i32. |
| 4393 | if (N->getOpcode() == ISD::BITCAST) { |
| 4394 | SDNode *BVN = N->getOperand(0).getNode(); |
| 4395 | assert(BVN->getOpcode() == ISD::BUILD_VECTOR && |
| 4396 | BVN->getValueType(0) == MVT::v4i32 && "expected v4i32 BUILD_VECTOR"); |
| 4397 | unsigned LowElt = DAG.getTargetLoweringInfo().isBigEndian() ? 1 : 0; |
| 4398 | return DAG.getNode(ISD::BUILD_VECTOR, N->getDebugLoc(), MVT::v2i32, |
| 4399 | BVN->getOperand(LowElt), BVN->getOperand(LowElt+2)); |
| 4400 | } |
| 4401 | // Construct a new BUILD_VECTOR with elements truncated to half the size. |
| 4402 | assert(N->getOpcode() == ISD::BUILD_VECTOR && "expected BUILD_VECTOR"); |
| 4403 | EVT VT = N->getValueType(0); |
| 4404 | unsigned EltSize = VT.getVectorElementType().getSizeInBits() / 2; |
| 4405 | unsigned NumElts = VT.getVectorNumElements(); |
| 4406 | MVT TruncVT = MVT::getIntegerVT(EltSize); |
| 4407 | SmallVector<SDValue, 8> Ops; |
| 4408 | for (unsigned i = 0; i != NumElts; ++i) { |
| 4409 | ConstantSDNode *C = cast<ConstantSDNode>(N->getOperand(i)); |
| 4410 | const APInt &CInt = C->getAPIntValue(); |
Jay Foad | 40f8f62 | 2010-12-07 08:25:19 +0000 | [diff] [blame] | 4411 | Ops.push_back(DAG.getConstant(CInt.trunc(EltSize), TruncVT)); |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 4412 | } |
| 4413 | return DAG.getNode(ISD::BUILD_VECTOR, N->getDebugLoc(), |
| 4414 | MVT::getVectorVT(TruncVT, NumElts), Ops.data(), NumElts); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4415 | } |
| 4416 | |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 4417 | static bool isAddSubSExt(SDNode *N, SelectionDAG &DAG) { |
| 4418 | unsigned Opcode = N->getOpcode(); |
| 4419 | if (Opcode == ISD::ADD || Opcode == ISD::SUB) { |
| 4420 | SDNode *N0 = N->getOperand(0).getNode(); |
| 4421 | SDNode *N1 = N->getOperand(1).getNode(); |
| 4422 | return N0->hasOneUse() && N1->hasOneUse() && |
| 4423 | isSignExtended(N0, DAG) && isSignExtended(N1, DAG); |
| 4424 | } |
| 4425 | return false; |
| 4426 | } |
| 4427 | |
| 4428 | static bool isAddSubZExt(SDNode *N, SelectionDAG &DAG) { |
| 4429 | unsigned Opcode = N->getOpcode(); |
| 4430 | if (Opcode == ISD::ADD || Opcode == ISD::SUB) { |
| 4431 | SDNode *N0 = N->getOperand(0).getNode(); |
| 4432 | SDNode *N1 = N->getOperand(1).getNode(); |
| 4433 | return N0->hasOneUse() && N1->hasOneUse() && |
| 4434 | isZeroExtended(N0, DAG) && isZeroExtended(N1, DAG); |
| 4435 | } |
| 4436 | return false; |
| 4437 | } |
| 4438 | |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4439 | static SDValue LowerMUL(SDValue Op, SelectionDAG &DAG) { |
| 4440 | // Multiplications are only custom-lowered for 128-bit vectors so that |
| 4441 | // VMULL can be detected. Otherwise v2i64 multiplications are not legal. |
| 4442 | EVT VT = Op.getValueType(); |
| 4443 | assert(VT.is128BitVector() && "unexpected type for custom-lowering ISD::MUL"); |
| 4444 | SDNode *N0 = Op.getOperand(0).getNode(); |
| 4445 | SDNode *N1 = Op.getOperand(1).getNode(); |
| 4446 | unsigned NewOpc = 0; |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 4447 | bool isMLA = false; |
| 4448 | bool isN0SExt = isSignExtended(N0, DAG); |
| 4449 | bool isN1SExt = isSignExtended(N1, DAG); |
| 4450 | if (isN0SExt && isN1SExt) |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4451 | NewOpc = ARMISD::VMULLs; |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 4452 | else { |
| 4453 | bool isN0ZExt = isZeroExtended(N0, DAG); |
| 4454 | bool isN1ZExt = isZeroExtended(N1, DAG); |
| 4455 | if (isN0ZExt && isN1ZExt) |
| 4456 | NewOpc = ARMISD::VMULLu; |
| 4457 | else if (isN1SExt || isN1ZExt) { |
| 4458 | // Look for (s/zext A + s/zext B) * (s/zext C). We want to turn these |
| 4459 | // into (s/zext A * s/zext C) + (s/zext B * s/zext C) |
| 4460 | if (isN1SExt && isAddSubSExt(N0, DAG)) { |
| 4461 | NewOpc = ARMISD::VMULLs; |
| 4462 | isMLA = true; |
| 4463 | } else if (isN1ZExt && isAddSubZExt(N0, DAG)) { |
| 4464 | NewOpc = ARMISD::VMULLu; |
| 4465 | isMLA = true; |
| 4466 | } else if (isN0ZExt && isAddSubZExt(N1, DAG)) { |
| 4467 | std::swap(N0, N1); |
| 4468 | NewOpc = ARMISD::VMULLu; |
| 4469 | isMLA = true; |
| 4470 | } |
| 4471 | } |
| 4472 | |
| 4473 | if (!NewOpc) { |
| 4474 | if (VT == MVT::v2i64) |
| 4475 | // Fall through to expand this. It is not legal. |
| 4476 | return SDValue(); |
| 4477 | else |
| 4478 | // Other vector multiplications are legal. |
| 4479 | return Op; |
| 4480 | } |
| 4481 | } |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4482 | |
| 4483 | // Legalize to a VMULL instruction. |
| 4484 | DebugLoc DL = Op.getDebugLoc(); |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 4485 | SDValue Op0; |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4486 | SDValue Op1 = SkipExtension(N1, DAG); |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 4487 | if (!isMLA) { |
| 4488 | Op0 = SkipExtension(N0, DAG); |
| 4489 | assert(Op0.getValueType().is64BitVector() && |
| 4490 | Op1.getValueType().is64BitVector() && |
| 4491 | "unexpected types for extended operands to VMULL"); |
| 4492 | return DAG.getNode(NewOpc, DL, VT, Op0, Op1); |
| 4493 | } |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4494 | |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 4495 | // Optimizing (zext A + zext B) * C, to (VMULL A, C) + (VMULL B, C) during |
| 4496 | // isel lowering to take advantage of no-stall back to back vmul + vmla. |
| 4497 | // vmull q0, d4, d6 |
| 4498 | // vmlal q0, d5, d6 |
| 4499 | // is faster than |
| 4500 | // vaddl q0, d4, d5 |
| 4501 | // vmovl q1, d6 |
| 4502 | // vmul q0, q0, q1 |
| 4503 | SDValue N00 = SkipExtension(N0->getOperand(0).getNode(), DAG); |
| 4504 | SDValue N01 = SkipExtension(N0->getOperand(1).getNode(), DAG); |
| 4505 | EVT Op1VT = Op1.getValueType(); |
| 4506 | return DAG.getNode(N0->getOpcode(), DL, VT, |
| 4507 | DAG.getNode(NewOpc, DL, VT, |
| 4508 | DAG.getNode(ISD::BITCAST, DL, Op1VT, N00), Op1), |
| 4509 | DAG.getNode(NewOpc, DL, VT, |
| 4510 | DAG.getNode(ISD::BITCAST, DL, Op1VT, N01), Op1)); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4511 | } |
| 4512 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4513 | static SDValue |
| 4514 | LowerSDIV_v4i8(SDValue X, SDValue Y, DebugLoc dl, SelectionDAG &DAG) { |
| 4515 | // Convert to float |
| 4516 | // float4 xf = vcvt_f32_s32(vmovl_s16(a.lo)); |
| 4517 | // float4 yf = vcvt_f32_s32(vmovl_s16(b.lo)); |
| 4518 | X = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, X); |
| 4519 | Y = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, Y); |
| 4520 | X = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, X); |
| 4521 | Y = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, Y); |
| 4522 | // Get reciprocal estimate. |
| 4523 | // float4 recip = vrecpeq_f32(yf); |
| 4524 | Y = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
| 4525 | DAG.getConstant(Intrinsic::arm_neon_vrecpe, MVT::i32), Y); |
| 4526 | // Because char has a smaller range than uchar, we can actually get away |
| 4527 | // without any newton steps. This requires that we use a weird bias |
| 4528 | // of 0xb000, however (again, this has been exhaustively tested). |
| 4529 | // float4 result = as_float4(as_int4(xf*recip) + 0xb000); |
| 4530 | X = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, X, Y); |
| 4531 | X = DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, X); |
| 4532 | Y = DAG.getConstant(0xb000, MVT::i32); |
| 4533 | Y = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, Y, Y, Y, Y); |
| 4534 | X = DAG.getNode(ISD::ADD, dl, MVT::v4i32, X, Y); |
| 4535 | X = DAG.getNode(ISD::BITCAST, dl, MVT::v4f32, X); |
| 4536 | // Convert back to short. |
| 4537 | X = DAG.getNode(ISD::FP_TO_SINT, dl, MVT::v4i32, X); |
| 4538 | X = DAG.getNode(ISD::TRUNCATE, dl, MVT::v4i16, X); |
| 4539 | return X; |
| 4540 | } |
| 4541 | |
| 4542 | static SDValue |
| 4543 | LowerSDIV_v4i16(SDValue N0, SDValue N1, DebugLoc dl, SelectionDAG &DAG) { |
| 4544 | SDValue N2; |
| 4545 | // Convert to float. |
| 4546 | // float4 yf = vcvt_f32_s32(vmovl_s16(y)); |
| 4547 | // float4 xf = vcvt_f32_s32(vmovl_s16(x)); |
| 4548 | N0 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, N0); |
| 4549 | N1 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, N1); |
| 4550 | N0 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N0); |
| 4551 | N1 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N1); |
| 4552 | |
| 4553 | // Use reciprocal estimate and one refinement step. |
| 4554 | // float4 recip = vrecpeq_f32(yf); |
| 4555 | // recip *= vrecpsq_f32(yf, recip); |
| 4556 | N2 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
| 4557 | DAG.getConstant(Intrinsic::arm_neon_vrecpe, MVT::i32), N1); |
| 4558 | N1 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
| 4559 | DAG.getConstant(Intrinsic::arm_neon_vrecps, MVT::i32), |
| 4560 | N1, N2); |
| 4561 | N2 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N1, N2); |
| 4562 | // Because short has a smaller range than ushort, we can actually get away |
| 4563 | // with only a single newton step. This requires that we use a weird bias |
| 4564 | // of 89, however (again, this has been exhaustively tested). |
| 4565 | // float4 result = as_float4(as_int4(xf*recip) + 89); |
| 4566 | N0 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N0, N2); |
| 4567 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, N0); |
| 4568 | N1 = DAG.getConstant(89, MVT::i32); |
| 4569 | N1 = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, N1, N1, N1, N1); |
| 4570 | N0 = DAG.getNode(ISD::ADD, dl, MVT::v4i32, N0, N1); |
| 4571 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4f32, N0); |
| 4572 | // Convert back to integer and return. |
| 4573 | // return vmovn_s32(vcvt_s32_f32(result)); |
| 4574 | N0 = DAG.getNode(ISD::FP_TO_SINT, dl, MVT::v4i32, N0); |
| 4575 | N0 = DAG.getNode(ISD::TRUNCATE, dl, MVT::v4i16, N0); |
| 4576 | return N0; |
| 4577 | } |
| 4578 | |
| 4579 | static SDValue LowerSDIV(SDValue Op, SelectionDAG &DAG) { |
| 4580 | EVT VT = Op.getValueType(); |
| 4581 | assert((VT == MVT::v4i16 || VT == MVT::v8i8) && |
| 4582 | "unexpected type for custom-lowering ISD::SDIV"); |
| 4583 | |
| 4584 | DebugLoc dl = Op.getDebugLoc(); |
| 4585 | SDValue N0 = Op.getOperand(0); |
| 4586 | SDValue N1 = Op.getOperand(1); |
| 4587 | SDValue N2, N3; |
| 4588 | |
| 4589 | if (VT == MVT::v8i8) { |
| 4590 | N0 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v8i16, N0); |
| 4591 | N1 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v8i16, N1); |
| 4592 | |
| 4593 | N2 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| 4594 | DAG.getIntPtrConstant(4)); |
| 4595 | N3 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
| 4596 | DAG.getIntPtrConstant(4)); |
| 4597 | N0 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| 4598 | DAG.getIntPtrConstant(0)); |
| 4599 | N1 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
| 4600 | DAG.getIntPtrConstant(0)); |
| 4601 | |
| 4602 | N0 = LowerSDIV_v4i8(N0, N1, dl, DAG); // v4i16 |
| 4603 | N2 = LowerSDIV_v4i8(N2, N3, dl, DAG); // v4i16 |
| 4604 | |
| 4605 | N0 = DAG.getNode(ISD::CONCAT_VECTORS, dl, MVT::v8i16, N0, N2); |
| 4606 | N0 = LowerCONCAT_VECTORS(N0, DAG); |
| 4607 | |
| 4608 | N0 = DAG.getNode(ISD::TRUNCATE, dl, MVT::v8i8, N0); |
| 4609 | return N0; |
| 4610 | } |
| 4611 | return LowerSDIV_v4i16(N0, N1, dl, DAG); |
| 4612 | } |
| 4613 | |
| 4614 | static SDValue LowerUDIV(SDValue Op, SelectionDAG &DAG) { |
| 4615 | EVT VT = Op.getValueType(); |
| 4616 | assert((VT == MVT::v4i16 || VT == MVT::v8i8) && |
| 4617 | "unexpected type for custom-lowering ISD::UDIV"); |
| 4618 | |
| 4619 | DebugLoc dl = Op.getDebugLoc(); |
| 4620 | SDValue N0 = Op.getOperand(0); |
| 4621 | SDValue N1 = Op.getOperand(1); |
| 4622 | SDValue N2, N3; |
| 4623 | |
| 4624 | if (VT == MVT::v8i8) { |
| 4625 | N0 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v8i16, N0); |
| 4626 | N1 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v8i16, N1); |
| 4627 | |
| 4628 | N2 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| 4629 | DAG.getIntPtrConstant(4)); |
| 4630 | N3 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
| 4631 | DAG.getIntPtrConstant(4)); |
| 4632 | N0 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| 4633 | DAG.getIntPtrConstant(0)); |
| 4634 | N1 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
| 4635 | DAG.getIntPtrConstant(0)); |
| 4636 | |
| 4637 | N0 = LowerSDIV_v4i16(N0, N1, dl, DAG); // v4i16 |
| 4638 | N2 = LowerSDIV_v4i16(N2, N3, dl, DAG); // v4i16 |
| 4639 | |
| 4640 | N0 = DAG.getNode(ISD::CONCAT_VECTORS, dl, MVT::v8i16, N0, N2); |
| 4641 | N0 = LowerCONCAT_VECTORS(N0, DAG); |
| 4642 | |
| 4643 | N0 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v8i8, |
| 4644 | DAG.getConstant(Intrinsic::arm_neon_vqmovnsu, MVT::i32), |
| 4645 | N0); |
| 4646 | return N0; |
| 4647 | } |
| 4648 | |
| 4649 | // v4i16 sdiv ... Convert to float. |
| 4650 | // float4 yf = vcvt_f32_s32(vmovl_u16(y)); |
| 4651 | // float4 xf = vcvt_f32_s32(vmovl_u16(x)); |
| 4652 | N0 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v4i32, N0); |
| 4653 | N1 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v4i32, N1); |
| 4654 | N0 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N0); |
| 4655 | N1 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N1); |
| 4656 | |
| 4657 | // Use reciprocal estimate and two refinement steps. |
| 4658 | // float4 recip = vrecpeq_f32(yf); |
| 4659 | // recip *= vrecpsq_f32(yf, recip); |
| 4660 | // recip *= vrecpsq_f32(yf, recip); |
| 4661 | N2 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
| 4662 | DAG.getConstant(Intrinsic::arm_neon_vrecpe, MVT::i32), N1); |
| 4663 | N1 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
| 4664 | DAG.getConstant(Intrinsic::arm_neon_vrecps, MVT::i32), |
| 4665 | N1, N2); |
| 4666 | N2 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N1, N2); |
| 4667 | N1 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
| 4668 | DAG.getConstant(Intrinsic::arm_neon_vrecps, MVT::i32), |
| 4669 | N1, N2); |
| 4670 | N2 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N1, N2); |
| 4671 | // Simply multiplying by the reciprocal estimate can leave us a few ulps |
| 4672 | // too low, so we add 2 ulps (exhaustive testing shows that this is enough, |
| 4673 | // and that it will never cause us to return an answer too large). |
| 4674 | // float4 result = as_float4(as_int4(xf*recip) + 89); |
| 4675 | N0 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N0, N2); |
| 4676 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, N0); |
| 4677 | N1 = DAG.getConstant(2, MVT::i32); |
| 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_u32(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 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 4688 | SDValue ARMTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4689 | switch (Op.getOpcode()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 4690 | default: llvm_unreachable("Don't know how to custom lower this!"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4691 | case ISD::ConstantPool: return LowerConstantPool(Op, DAG); |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 4692 | case ISD::BlockAddress: return LowerBlockAddress(Op, DAG); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 4693 | case ISD::GlobalAddress: |
| 4694 | return Subtarget->isTargetDarwin() ? LowerGlobalAddressDarwin(Op, DAG) : |
| 4695 | LowerGlobalAddressELF(Op, DAG); |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4696 | case ISD::GlobalTLSAddress: return LowerGlobalTLSAddress(Op, DAG); |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 4697 | case ISD::SELECT: return LowerSELECT(Op, DAG); |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 4698 | case ISD::SELECT_CC: return LowerSELECT_CC(Op, DAG); |
| 4699 | case ISD::BR_CC: return LowerBR_CC(Op, DAG); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4700 | case ISD::BR_JT: return LowerBR_JT(Op, DAG); |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 4701 | case ISD::VASTART: return LowerVASTART(Op, DAG); |
Jim Grosbach | 7c03dbd | 2009-12-14 21:24:16 +0000 | [diff] [blame] | 4702 | case ISD::MEMBARRIER: return LowerMEMBARRIER(Op, DAG, Subtarget); |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 4703 | case ISD::PREFETCH: return LowerPREFETCH(Op, DAG, Subtarget); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 4704 | case ISD::SINT_TO_FP: |
| 4705 | case ISD::UINT_TO_FP: return LowerINT_TO_FP(Op, DAG); |
| 4706 | case ISD::FP_TO_SINT: |
| 4707 | case ISD::FP_TO_UINT: return LowerFP_TO_INT(Op, DAG); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4708 | case ISD::FCOPYSIGN: return LowerFCOPYSIGN(Op, DAG); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 4709 | case ISD::RETURNADDR: return LowerRETURNADDR(Op, DAG); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 4710 | case ISD::FRAMEADDR: return LowerFRAMEADDR(Op, DAG); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 4711 | case ISD::GLOBAL_OFFSET_TABLE: return LowerGLOBAL_OFFSET_TABLE(Op, DAG); |
Jim Grosbach | 23ff7cf | 2010-05-26 20:22:18 +0000 | [diff] [blame] | 4712 | case ISD::EH_SJLJ_SETJMP: return LowerEH_SJLJ_SETJMP(Op, DAG); |
Jim Grosbach | 5eb1951 | 2010-05-22 01:06:18 +0000 | [diff] [blame] | 4713 | case ISD::EH_SJLJ_LONGJMP: return LowerEH_SJLJ_LONGJMP(Op, DAG); |
Jim Grosbach | e4ad387 | 2010-10-19 23:27:08 +0000 | [diff] [blame] | 4714 | case ISD::EH_SJLJ_DISPATCHSETUP: return LowerEH_SJLJ_DISPATCHSETUP(Op, DAG); |
Jim Grosbach | a87ded2 | 2010-02-08 23:22:00 +0000 | [diff] [blame] | 4715 | case ISD::INTRINSIC_WO_CHAIN: return LowerINTRINSIC_WO_CHAIN(Op, DAG, |
| 4716 | Subtarget); |
Evan Cheng | 21a6179 | 2011-03-14 18:02:30 +0000 | [diff] [blame] | 4717 | case ISD::BITCAST: return ExpandBITCAST(Op.getNode(), DAG); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4718 | case ISD::SHL: |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4719 | case ISD::SRL: |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4720 | case ISD::SRA: return LowerShift(Op.getNode(), DAG, Subtarget); |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 4721 | case ISD::SHL_PARTS: return LowerShiftLeftParts(Op, DAG); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 4722 | case ISD::SRL_PARTS: |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 4723 | case ISD::SRA_PARTS: return LowerShiftRightParts(Op, DAG); |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 4724 | case ISD::CTTZ: return LowerCTTZ(Op.getNode(), DAG, Subtarget); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4725 | case ISD::VSETCC: return LowerVSETCC(Op, DAG); |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 4726 | case ISD::BUILD_VECTOR: return LowerBUILD_VECTOR(Op, DAG, Subtarget); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4727 | case ISD::VECTOR_SHUFFLE: return LowerVECTOR_SHUFFLE(Op, DAG); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4728 | case ISD::EXTRACT_VECTOR_ELT: return LowerEXTRACT_VECTOR_ELT(Op, DAG); |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 4729 | case ISD::CONCAT_VECTORS: return LowerCONCAT_VECTORS(Op, DAG); |
Bob Wilson | b31a11b | 2010-08-20 04:54:02 +0000 | [diff] [blame] | 4730 | case ISD::FLT_ROUNDS_: return LowerFLT_ROUNDS_(Op, DAG); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4731 | case ISD::MUL: return LowerMUL(Op, DAG); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4732 | case ISD::SDIV: return LowerSDIV(Op, DAG); |
| 4733 | case ISD::UDIV: return LowerUDIV(Op, DAG); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4734 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4735 | return SDValue(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4736 | } |
| 4737 | |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 4738 | /// ReplaceNodeResults - Replace the results of node with an illegal result |
| 4739 | /// type with new values built out of custom code. |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 4740 | void ARMTargetLowering::ReplaceNodeResults(SDNode *N, |
| 4741 | SmallVectorImpl<SDValue>&Results, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 4742 | SelectionDAG &DAG) const { |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 4743 | SDValue Res; |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4744 | switch (N->getOpcode()) { |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 4745 | default: |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 4746 | llvm_unreachable("Don't know how to custom expand this!"); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 4747 | break; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4748 | case ISD::BITCAST: |
| 4749 | Res = ExpandBITCAST(N, DAG); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 4750 | break; |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4751 | case ISD::SRL: |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 4752 | case ISD::SRA: |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 4753 | Res = Expand64BitShift(N, DAG, Subtarget); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 4754 | break; |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 4755 | } |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 4756 | if (Res.getNode()) |
| 4757 | Results.push_back(Res); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4758 | } |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4759 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4760 | //===----------------------------------------------------------------------===// |
| 4761 | // ARM Scheduler Hooks |
| 4762 | //===----------------------------------------------------------------------===// |
| 4763 | |
| 4764 | MachineBasicBlock * |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 4765 | ARMTargetLowering::EmitAtomicCmpSwap(MachineInstr *MI, |
| 4766 | MachineBasicBlock *BB, |
| 4767 | unsigned Size) const { |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4768 | unsigned dest = MI->getOperand(0).getReg(); |
| 4769 | unsigned ptr = MI->getOperand(1).getReg(); |
| 4770 | unsigned oldval = MI->getOperand(2).getReg(); |
| 4771 | unsigned newval = MI->getOperand(3).getReg(); |
| 4772 | unsigned scratch = BB->getParent()->getRegInfo() |
| 4773 | .createVirtualRegister(ARM::GPRRegisterClass); |
| 4774 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 4775 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4776 | bool isThumb2 = Subtarget->isThumb2(); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4777 | |
| 4778 | unsigned ldrOpc, strOpc; |
| 4779 | switch (Size) { |
| 4780 | default: llvm_unreachable("unsupported size for AtomicCmpSwap!"); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4781 | case 1: |
| 4782 | ldrOpc = isThumb2 ? ARM::t2LDREXB : ARM::LDREXB; |
Evan Cheng | aa26102 | 2011-02-07 18:50:47 +0000 | [diff] [blame] | 4783 | strOpc = isThumb2 ? ARM::t2STREXB : ARM::STREXB; |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4784 | break; |
| 4785 | case 2: |
| 4786 | ldrOpc = isThumb2 ? ARM::t2LDREXH : ARM::LDREXH; |
| 4787 | strOpc = isThumb2 ? ARM::t2STREXH : ARM::STREXH; |
| 4788 | break; |
| 4789 | case 4: |
| 4790 | ldrOpc = isThumb2 ? ARM::t2LDREX : ARM::LDREX; |
| 4791 | strOpc = isThumb2 ? ARM::t2STREX : ARM::STREX; |
| 4792 | break; |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4793 | } |
| 4794 | |
| 4795 | MachineFunction *MF = BB->getParent(); |
| 4796 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 4797 | MachineFunction::iterator It = BB; |
| 4798 | ++It; // insert the new blocks after the current block |
| 4799 | |
| 4800 | MachineBasicBlock *loop1MBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 4801 | MachineBasicBlock *loop2MBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 4802 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 4803 | MF->insert(It, loop1MBB); |
| 4804 | MF->insert(It, loop2MBB); |
| 4805 | MF->insert(It, exitMBB); |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 4806 | |
| 4807 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 4808 | exitMBB->splice(exitMBB->begin(), BB, |
| 4809 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 4810 | BB->end()); |
| 4811 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4812 | |
| 4813 | // thisMBB: |
| 4814 | // ... |
| 4815 | // fallthrough --> loop1MBB |
| 4816 | BB->addSuccessor(loop1MBB); |
| 4817 | |
| 4818 | // loop1MBB: |
| 4819 | // ldrex dest, [ptr] |
| 4820 | // cmp dest, oldval |
| 4821 | // bne exitMBB |
| 4822 | BB = loop1MBB; |
| 4823 | AddDefaultPred(BuildMI(BB, dl, TII->get(ldrOpc), dest).addReg(ptr)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4824 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4825 | .addReg(dest).addReg(oldval)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4826 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 4827 | .addMBB(exitMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4828 | BB->addSuccessor(loop2MBB); |
| 4829 | BB->addSuccessor(exitMBB); |
| 4830 | |
| 4831 | // loop2MBB: |
| 4832 | // strex scratch, newval, [ptr] |
| 4833 | // cmp scratch, #0 |
| 4834 | // bne loop1MBB |
| 4835 | BB = loop2MBB; |
| 4836 | AddDefaultPred(BuildMI(BB, dl, TII->get(strOpc), scratch).addReg(newval) |
| 4837 | .addReg(ptr)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4838 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4839 | .addReg(scratch).addImm(0)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4840 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 4841 | .addMBB(loop1MBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4842 | BB->addSuccessor(loop1MBB); |
| 4843 | BB->addSuccessor(exitMBB); |
| 4844 | |
| 4845 | // exitMBB: |
| 4846 | // ... |
| 4847 | BB = exitMBB; |
Jim Grosbach | 5efaed3 | 2010-01-15 00:18:34 +0000 | [diff] [blame] | 4848 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 4849 | MI->eraseFromParent(); // The instruction is gone now. |
Jim Grosbach | 5efaed3 | 2010-01-15 00:18:34 +0000 | [diff] [blame] | 4850 | |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4851 | return BB; |
| 4852 | } |
| 4853 | |
| 4854 | MachineBasicBlock * |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 4855 | ARMTargetLowering::EmitAtomicBinary(MachineInstr *MI, MachineBasicBlock *BB, |
| 4856 | unsigned Size, unsigned BinOpcode) const { |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 4857 | // This also handles ATOMIC_SWAP, indicated by BinOpcode==0. |
| 4858 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 4859 | |
| 4860 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
Jim Grosbach | 867bbbf | 2010-01-15 00:22:18 +0000 | [diff] [blame] | 4861 | MachineFunction *MF = BB->getParent(); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 4862 | MachineFunction::iterator It = BB; |
| 4863 | ++It; |
| 4864 | |
| 4865 | unsigned dest = MI->getOperand(0).getReg(); |
| 4866 | unsigned ptr = MI->getOperand(1).getReg(); |
| 4867 | unsigned incr = MI->getOperand(2).getReg(); |
| 4868 | DebugLoc dl = MI->getDebugLoc(); |
Rafael Espindola | fda60d3 | 2009-12-18 16:59:39 +0000 | [diff] [blame] | 4869 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4870 | bool isThumb2 = Subtarget->isThumb2(); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 4871 | unsigned ldrOpc, strOpc; |
| 4872 | switch (Size) { |
| 4873 | default: llvm_unreachable("unsupported size for AtomicCmpSwap!"); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4874 | case 1: |
| 4875 | ldrOpc = isThumb2 ? ARM::t2LDREXB : ARM::LDREXB; |
Jakob Stoklund Olesen | 15913c9 | 2010-01-13 19:54:39 +0000 | [diff] [blame] | 4876 | strOpc = isThumb2 ? ARM::t2STREXB : ARM::STREXB; |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4877 | break; |
| 4878 | case 2: |
| 4879 | ldrOpc = isThumb2 ? ARM::t2LDREXH : ARM::LDREXH; |
| 4880 | strOpc = isThumb2 ? ARM::t2STREXH : ARM::STREXH; |
| 4881 | break; |
| 4882 | case 4: |
| 4883 | ldrOpc = isThumb2 ? ARM::t2LDREX : ARM::LDREX; |
| 4884 | strOpc = isThumb2 ? ARM::t2STREX : ARM::STREX; |
| 4885 | break; |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 4886 | } |
| 4887 | |
Jim Grosbach | 867bbbf | 2010-01-15 00:22:18 +0000 | [diff] [blame] | 4888 | MachineBasicBlock *loopMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 4889 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 4890 | MF->insert(It, loopMBB); |
| 4891 | MF->insert(It, exitMBB); |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 4892 | |
| 4893 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 4894 | exitMBB->splice(exitMBB->begin(), BB, |
| 4895 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 4896 | BB->end()); |
| 4897 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 4898 | |
Jim Grosbach | 867bbbf | 2010-01-15 00:22:18 +0000 | [diff] [blame] | 4899 | MachineRegisterInfo &RegInfo = MF->getRegInfo(); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 4900 | unsigned scratch = RegInfo.createVirtualRegister(ARM::GPRRegisterClass); |
| 4901 | unsigned scratch2 = (!BinOpcode) ? incr : |
| 4902 | RegInfo.createVirtualRegister(ARM::GPRRegisterClass); |
| 4903 | |
| 4904 | // thisMBB: |
| 4905 | // ... |
| 4906 | // fallthrough --> loopMBB |
| 4907 | BB->addSuccessor(loopMBB); |
| 4908 | |
| 4909 | // loopMBB: |
| 4910 | // ldrex dest, ptr |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4911 | // <binop> scratch2, dest, incr |
| 4912 | // strex scratch, scratch2, ptr |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 4913 | // cmp scratch, #0 |
| 4914 | // bne- loopMBB |
| 4915 | // fallthrough --> exitMBB |
| 4916 | BB = loopMBB; |
| 4917 | AddDefaultPred(BuildMI(BB, dl, TII->get(ldrOpc), dest).addReg(ptr)); |
Jim Grosbach | c67b556 | 2009-12-15 00:12:35 +0000 | [diff] [blame] | 4918 | if (BinOpcode) { |
| 4919 | // operand order needs to go the other way for NAND |
| 4920 | if (BinOpcode == ARM::BICrr || BinOpcode == ARM::t2BICrr) |
| 4921 | AddDefaultPred(BuildMI(BB, dl, TII->get(BinOpcode), scratch2). |
| 4922 | addReg(incr).addReg(dest)).addReg(0); |
| 4923 | else |
| 4924 | AddDefaultPred(BuildMI(BB, dl, TII->get(BinOpcode), scratch2). |
| 4925 | addReg(dest).addReg(incr)).addReg(0); |
| 4926 | } |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 4927 | |
| 4928 | AddDefaultPred(BuildMI(BB, dl, TII->get(strOpc), scratch).addReg(scratch2) |
| 4929 | .addReg(ptr)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4930 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 4931 | .addReg(scratch).addImm(0)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4932 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 4933 | .addMBB(loopMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 4934 | |
| 4935 | BB->addSuccessor(loopMBB); |
| 4936 | BB->addSuccessor(exitMBB); |
| 4937 | |
| 4938 | // exitMBB: |
| 4939 | // ... |
| 4940 | BB = exitMBB; |
Evan Cheng | 102ebf1 | 2009-12-21 19:53:39 +0000 | [diff] [blame] | 4941 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 4942 | MI->eraseFromParent(); // The instruction is gone now. |
Evan Cheng | 102ebf1 | 2009-12-21 19:53:39 +0000 | [diff] [blame] | 4943 | |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 4944 | return BB; |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 4945 | } |
| 4946 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 4947 | static |
| 4948 | MachineBasicBlock *OtherSucc(MachineBasicBlock *MBB, MachineBasicBlock *Succ) { |
| 4949 | for (MachineBasicBlock::succ_iterator I = MBB->succ_begin(), |
| 4950 | E = MBB->succ_end(); I != E; ++I) |
| 4951 | if (*I != Succ) |
| 4952 | return *I; |
| 4953 | llvm_unreachable("Expecting a BB with two successors!"); |
| 4954 | } |
| 4955 | |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 4956 | MachineBasicBlock * |
Evan Cheng | ff9b373 | 2008-01-30 18:18:23 +0000 | [diff] [blame] | 4957 | ARMTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI, |
Dan Gohman | af1d8ca | 2010-05-01 00:01:06 +0000 | [diff] [blame] | 4958 | MachineBasicBlock *BB) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4959 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
Dale Johannesen | b672840 | 2009-02-13 02:25:56 +0000 | [diff] [blame] | 4960 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4961 | bool isThumb2 = Subtarget->isThumb2(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4962 | switch (MI->getOpcode()) { |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 4963 | default: |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4964 | MI->dump(); |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 4965 | llvm_unreachable("Unexpected instr type to insert"); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4966 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4967 | case ARM::ATOMIC_LOAD_ADD_I8: |
| 4968 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr); |
| 4969 | case ARM::ATOMIC_LOAD_ADD_I16: |
| 4970 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr); |
| 4971 | case ARM::ATOMIC_LOAD_ADD_I32: |
| 4972 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4973 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4974 | case ARM::ATOMIC_LOAD_AND_I8: |
| 4975 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
| 4976 | case ARM::ATOMIC_LOAD_AND_I16: |
| 4977 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
| 4978 | case ARM::ATOMIC_LOAD_AND_I32: |
| 4979 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4980 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4981 | case ARM::ATOMIC_LOAD_OR_I8: |
| 4982 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
| 4983 | case ARM::ATOMIC_LOAD_OR_I16: |
| 4984 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
| 4985 | case ARM::ATOMIC_LOAD_OR_I32: |
| 4986 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4987 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4988 | case ARM::ATOMIC_LOAD_XOR_I8: |
| 4989 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
| 4990 | case ARM::ATOMIC_LOAD_XOR_I16: |
| 4991 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
| 4992 | case ARM::ATOMIC_LOAD_XOR_I32: |
| 4993 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 4994 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4995 | case ARM::ATOMIC_LOAD_NAND_I8: |
| 4996 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2BICrr : ARM::BICrr); |
| 4997 | case ARM::ATOMIC_LOAD_NAND_I16: |
| 4998 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2BICrr : ARM::BICrr); |
| 4999 | case ARM::ATOMIC_LOAD_NAND_I32: |
| 5000 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2BICrr : ARM::BICrr); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 5001 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5002 | case ARM::ATOMIC_LOAD_SUB_I8: |
| 5003 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr); |
| 5004 | case ARM::ATOMIC_LOAD_SUB_I16: |
| 5005 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr); |
| 5006 | case ARM::ATOMIC_LOAD_SUB_I32: |
| 5007 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 5008 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5009 | case ARM::ATOMIC_SWAP_I8: return EmitAtomicBinary(MI, BB, 1, 0); |
| 5010 | case ARM::ATOMIC_SWAP_I16: return EmitAtomicBinary(MI, BB, 2, 0); |
| 5011 | case ARM::ATOMIC_SWAP_I32: return EmitAtomicBinary(MI, BB, 4, 0); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 5012 | |
| 5013 | case ARM::ATOMIC_CMP_SWAP_I8: return EmitAtomicCmpSwap(MI, BB, 1); |
| 5014 | case ARM::ATOMIC_CMP_SWAP_I16: return EmitAtomicCmpSwap(MI, BB, 2); |
| 5015 | case ARM::ATOMIC_CMP_SWAP_I32: return EmitAtomicCmpSwap(MI, BB, 4); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5016 | |
Evan Cheng | 007ea27 | 2009-08-12 05:17:19 +0000 | [diff] [blame] | 5017 | case ARM::tMOVCCr_pseudo: { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5018 | // To "insert" a SELECT_CC instruction, we actually have to insert the |
| 5019 | // diamond control-flow pattern. The incoming instruction knows the |
| 5020 | // destination vreg to set, the condition code register to branch on, the |
| 5021 | // true/false values to select between, and a branch opcode to use. |
| 5022 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 5023 | MachineFunction::iterator It = BB; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5024 | ++It; |
| 5025 | |
| 5026 | // thisMBB: |
| 5027 | // ... |
| 5028 | // TrueVal = ... |
| 5029 | // cmpTY ccX, r1, r2 |
| 5030 | // bCC copy1MBB |
| 5031 | // fallthrough --> copy0MBB |
| 5032 | MachineBasicBlock *thisMBB = BB; |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 5033 | MachineFunction *F = BB->getParent(); |
| 5034 | MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB); |
| 5035 | MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB); |
Dan Gohman | 258c58c | 2010-07-06 15:49:48 +0000 | [diff] [blame] | 5036 | F->insert(It, copy0MBB); |
| 5037 | F->insert(It, sinkMBB); |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 5038 | |
| 5039 | // Transfer the remainder of BB and its successor edges to sinkMBB. |
| 5040 | sinkMBB->splice(sinkMBB->begin(), BB, |
| 5041 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 5042 | BB->end()); |
| 5043 | sinkMBB->transferSuccessorsAndUpdatePHIs(BB); |
| 5044 | |
Dan Gohman | 258c58c | 2010-07-06 15:49:48 +0000 | [diff] [blame] | 5045 | BB->addSuccessor(copy0MBB); |
| 5046 | BB->addSuccessor(sinkMBB); |
Dan Gohman | b81c771 | 2010-07-06 15:18:19 +0000 | [diff] [blame] | 5047 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 5048 | BuildMI(BB, dl, TII->get(ARM::tBcc)).addMBB(sinkMBB) |
| 5049 | .addImm(MI->getOperand(3).getImm()).addReg(MI->getOperand(4).getReg()); |
| 5050 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5051 | // copy0MBB: |
| 5052 | // %FalseValue = ... |
| 5053 | // # fallthrough to sinkMBB |
| 5054 | BB = copy0MBB; |
| 5055 | |
| 5056 | // Update machine-CFG edges |
| 5057 | BB->addSuccessor(sinkMBB); |
| 5058 | |
| 5059 | // sinkMBB: |
| 5060 | // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ] |
| 5061 | // ... |
| 5062 | BB = sinkMBB; |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 5063 | BuildMI(*BB, BB->begin(), dl, |
| 5064 | TII->get(ARM::PHI), MI->getOperand(0).getReg()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5065 | .addReg(MI->getOperand(1).getReg()).addMBB(copy0MBB) |
| 5066 | .addReg(MI->getOperand(2).getReg()).addMBB(thisMBB); |
| 5067 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 5068 | MI->eraseFromParent(); // The pseudo instruction is gone now. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5069 | return BB; |
| 5070 | } |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 5071 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 5072 | case ARM::BCCi64: |
| 5073 | case ARM::BCCZi64: { |
Bob Wilson | 3c90469 | 2010-12-23 22:45:49 +0000 | [diff] [blame] | 5074 | // If there is an unconditional branch to the other successor, remove it. |
| 5075 | BB->erase(llvm::next(MachineBasicBlock::iterator(MI)), BB->end()); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 5076 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 5077 | // Compare both parts that make up the double comparison separately for |
| 5078 | // equality. |
| 5079 | bool RHSisZero = MI->getOpcode() == ARM::BCCZi64; |
| 5080 | |
| 5081 | unsigned LHS1 = MI->getOperand(1).getReg(); |
| 5082 | unsigned LHS2 = MI->getOperand(2).getReg(); |
| 5083 | if (RHSisZero) { |
| 5084 | AddDefaultPred(BuildMI(BB, dl, |
| 5085 | TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 5086 | .addReg(LHS1).addImm(0)); |
| 5087 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 5088 | .addReg(LHS2).addImm(0) |
| 5089 | .addImm(ARMCC::EQ).addReg(ARM::CPSR); |
| 5090 | } else { |
| 5091 | unsigned RHS1 = MI->getOperand(3).getReg(); |
| 5092 | unsigned RHS2 = MI->getOperand(4).getReg(); |
| 5093 | AddDefaultPred(BuildMI(BB, dl, |
| 5094 | TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
| 5095 | .addReg(LHS1).addReg(RHS1)); |
| 5096 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
| 5097 | .addReg(LHS2).addReg(RHS2) |
| 5098 | .addImm(ARMCC::EQ).addReg(ARM::CPSR); |
| 5099 | } |
| 5100 | |
| 5101 | MachineBasicBlock *destMBB = MI->getOperand(RHSisZero ? 3 : 5).getMBB(); |
| 5102 | MachineBasicBlock *exitMBB = OtherSucc(BB, destMBB); |
| 5103 | if (MI->getOperand(0).getImm() == ARMCC::NE) |
| 5104 | std::swap(destMBB, exitMBB); |
| 5105 | |
| 5106 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 5107 | .addMBB(destMBB).addImm(ARMCC::EQ).addReg(ARM::CPSR); |
| 5108 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2B : ARM::B)) |
| 5109 | .addMBB(exitMBB); |
| 5110 | |
| 5111 | MI->eraseFromParent(); // The pseudo instruction is gone now. |
| 5112 | return BB; |
| 5113 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5114 | } |
| 5115 | } |
| 5116 | |
| 5117 | //===----------------------------------------------------------------------===// |
| 5118 | // ARM Optimization Hooks |
| 5119 | //===----------------------------------------------------------------------===// |
| 5120 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 5121 | static |
| 5122 | SDValue combineSelectAndUse(SDNode *N, SDValue Slct, SDValue OtherOp, |
| 5123 | TargetLowering::DAGCombinerInfo &DCI) { |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 5124 | SelectionDAG &DAG = DCI.DAG; |
| 5125 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 5126 | EVT VT = N->getValueType(0); |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 5127 | unsigned Opc = N->getOpcode(); |
| 5128 | bool isSlctCC = Slct.getOpcode() == ISD::SELECT_CC; |
| 5129 | SDValue LHS = isSlctCC ? Slct.getOperand(2) : Slct.getOperand(1); |
| 5130 | SDValue RHS = isSlctCC ? Slct.getOperand(3) : Slct.getOperand(2); |
| 5131 | ISD::CondCode CC = ISD::SETCC_INVALID; |
| 5132 | |
| 5133 | if (isSlctCC) { |
| 5134 | CC = cast<CondCodeSDNode>(Slct.getOperand(4))->get(); |
| 5135 | } else { |
| 5136 | SDValue CCOp = Slct.getOperand(0); |
| 5137 | if (CCOp.getOpcode() == ISD::SETCC) |
| 5138 | CC = cast<CondCodeSDNode>(CCOp.getOperand(2))->get(); |
| 5139 | } |
| 5140 | |
| 5141 | bool DoXform = false; |
| 5142 | bool InvCC = false; |
| 5143 | assert ((Opc == ISD::ADD || (Opc == ISD::SUB && Slct == N->getOperand(1))) && |
| 5144 | "Bad input!"); |
| 5145 | |
| 5146 | if (LHS.getOpcode() == ISD::Constant && |
| 5147 | cast<ConstantSDNode>(LHS)->isNullValue()) { |
| 5148 | DoXform = true; |
| 5149 | } else if (CC != ISD::SETCC_INVALID && |
| 5150 | RHS.getOpcode() == ISD::Constant && |
| 5151 | cast<ConstantSDNode>(RHS)->isNullValue()) { |
| 5152 | std::swap(LHS, RHS); |
| 5153 | SDValue Op0 = Slct.getOperand(0); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 5154 | EVT OpVT = isSlctCC ? Op0.getValueType() : |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 5155 | Op0.getOperand(0).getValueType(); |
| 5156 | bool isInt = OpVT.isInteger(); |
| 5157 | CC = ISD::getSetCCInverse(CC, isInt); |
| 5158 | |
| 5159 | if (!TLI.isCondCodeLegal(CC, OpVT)) |
| 5160 | return SDValue(); // Inverse operator isn't legal. |
| 5161 | |
| 5162 | DoXform = true; |
| 5163 | InvCC = true; |
| 5164 | } |
| 5165 | |
| 5166 | if (DoXform) { |
| 5167 | SDValue Result = DAG.getNode(Opc, RHS.getDebugLoc(), VT, OtherOp, RHS); |
| 5168 | if (isSlctCC) |
| 5169 | return DAG.getSelectCC(N->getDebugLoc(), OtherOp, Result, |
| 5170 | Slct.getOperand(0), Slct.getOperand(1), CC); |
| 5171 | SDValue CCOp = Slct.getOperand(0); |
| 5172 | if (InvCC) |
| 5173 | CCOp = DAG.getSetCC(Slct.getDebugLoc(), CCOp.getValueType(), |
| 5174 | CCOp.getOperand(0), CCOp.getOperand(1), CC); |
| 5175 | return DAG.getNode(ISD::SELECT, N->getDebugLoc(), VT, |
| 5176 | CCOp, OtherOp, Result); |
| 5177 | } |
| 5178 | return SDValue(); |
| 5179 | } |
| 5180 | |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 5181 | /// PerformADDCombineWithOperands - Try DAG combinations for an ADD with |
| 5182 | /// operands N0 and N1. This is a helper for PerformADDCombine that is |
| 5183 | /// called with the default operands, and if that fails, with commuted |
| 5184 | /// operands. |
| 5185 | static SDValue PerformADDCombineWithOperands(SDNode *N, SDValue N0, SDValue N1, |
| 5186 | TargetLowering::DAGCombinerInfo &DCI) { |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 5187 | // fold (add (select cc, 0, c), x) -> (select cc, x, (add, x, c)) |
| 5188 | if (N0.getOpcode() == ISD::SELECT && N0.getNode()->hasOneUse()) { |
| 5189 | SDValue Result = combineSelectAndUse(N, N0, N1, DCI); |
| 5190 | if (Result.getNode()) return Result; |
| 5191 | } |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 5192 | return SDValue(); |
| 5193 | } |
| 5194 | |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 5195 | /// PerformADDCombine - Target-specific dag combine xforms for ISD::ADD. |
| 5196 | /// |
| 5197 | static SDValue PerformADDCombine(SDNode *N, |
| 5198 | TargetLowering::DAGCombinerInfo &DCI) { |
| 5199 | SDValue N0 = N->getOperand(0); |
| 5200 | SDValue N1 = N->getOperand(1); |
| 5201 | |
| 5202 | // First try with the default operand order. |
| 5203 | SDValue Result = PerformADDCombineWithOperands(N, N0, N1, DCI); |
| 5204 | if (Result.getNode()) |
| 5205 | return Result; |
| 5206 | |
| 5207 | // If that didn't work, try again with the operands commuted. |
| 5208 | return PerformADDCombineWithOperands(N, N1, N0, DCI); |
| 5209 | } |
| 5210 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 5211 | /// PerformSUBCombine - Target-specific dag combine xforms for ISD::SUB. |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 5212 | /// |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 5213 | static SDValue PerformSUBCombine(SDNode *N, |
| 5214 | TargetLowering::DAGCombinerInfo &DCI) { |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 5215 | SDValue N0 = N->getOperand(0); |
| 5216 | SDValue N1 = N->getOperand(1); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 5217 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 5218 | // fold (sub x, (select cc, 0, c)) -> (select cc, x, (sub, x, c)) |
| 5219 | if (N1.getOpcode() == ISD::SELECT && N1.getNode()->hasOneUse()) { |
| 5220 | SDValue Result = combineSelectAndUse(N, N1, N0, DCI); |
| 5221 | if (Result.getNode()) return Result; |
| 5222 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 5223 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 5224 | return SDValue(); |
| 5225 | } |
| 5226 | |
Evan Cheng | 463d358 | 2011-03-31 19:38:48 +0000 | [diff] [blame^] | 5227 | /// PerformVMULCombine |
| 5228 | /// Distribute (A + B) * C to (A * C) + (B * C) to take advantage of the |
| 5229 | /// special multiplier accumulator forwarding. |
| 5230 | /// vmul d3, d0, d2 |
| 5231 | /// vmla d3, d1, d2 |
| 5232 | /// is faster than |
| 5233 | /// vadd d3, d0, d1 |
| 5234 | /// vmul d3, d3, d2 |
| 5235 | static SDValue PerformVMULCombine(SDNode *N, |
| 5236 | TargetLowering::DAGCombinerInfo &DCI, |
| 5237 | const ARMSubtarget *Subtarget) { |
| 5238 | if (!Subtarget->hasVMLxForwarding()) |
| 5239 | return SDValue(); |
| 5240 | |
| 5241 | SelectionDAG &DAG = DCI.DAG; |
| 5242 | SDValue N0 = N->getOperand(0); |
| 5243 | SDValue N1 = N->getOperand(1); |
| 5244 | unsigned Opcode = N0.getOpcode(); |
| 5245 | if (Opcode != ISD::ADD && Opcode != ISD::SUB && |
| 5246 | Opcode != ISD::FADD && Opcode != ISD::FSUB) { |
| 5247 | Opcode = N0.getOpcode(); |
| 5248 | if (Opcode != ISD::ADD && Opcode != ISD::SUB && |
| 5249 | Opcode != ISD::FADD && Opcode != ISD::FSUB) |
| 5250 | return SDValue(); |
| 5251 | std::swap(N0, N1); |
| 5252 | } |
| 5253 | |
| 5254 | EVT VT = N->getValueType(0); |
| 5255 | DebugLoc DL = N->getDebugLoc(); |
| 5256 | SDValue N00 = N0->getOperand(0); |
| 5257 | SDValue N01 = N0->getOperand(1); |
| 5258 | return DAG.getNode(Opcode, DL, VT, |
| 5259 | DAG.getNode(ISD::MUL, DL, VT, N00, N1), |
| 5260 | DAG.getNode(ISD::MUL, DL, VT, N01, N1)); |
| 5261 | } |
| 5262 | |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 5263 | static SDValue PerformMULCombine(SDNode *N, |
| 5264 | TargetLowering::DAGCombinerInfo &DCI, |
| 5265 | const ARMSubtarget *Subtarget) { |
| 5266 | SelectionDAG &DAG = DCI.DAG; |
| 5267 | |
| 5268 | if (Subtarget->isThumb1Only()) |
| 5269 | return SDValue(); |
| 5270 | |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 5271 | if (DCI.isBeforeLegalize() || DCI.isCalledByLegalizer()) |
| 5272 | return SDValue(); |
| 5273 | |
| 5274 | EVT VT = N->getValueType(0); |
Evan Cheng | 463d358 | 2011-03-31 19:38:48 +0000 | [diff] [blame^] | 5275 | if (VT.is64BitVector() || VT.is128BitVector()) |
| 5276 | return PerformVMULCombine(N, DCI, Subtarget); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 5277 | if (VT != MVT::i32) |
| 5278 | return SDValue(); |
| 5279 | |
| 5280 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1)); |
| 5281 | if (!C) |
| 5282 | return SDValue(); |
| 5283 | |
| 5284 | uint64_t MulAmt = C->getZExtValue(); |
| 5285 | unsigned ShiftAmt = CountTrailingZeros_64(MulAmt); |
| 5286 | ShiftAmt = ShiftAmt & (32 - 1); |
| 5287 | SDValue V = N->getOperand(0); |
| 5288 | DebugLoc DL = N->getDebugLoc(); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 5289 | |
Anton Korobeynikov | 4878b84 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 5290 | SDValue Res; |
| 5291 | MulAmt >>= ShiftAmt; |
| 5292 | if (isPowerOf2_32(MulAmt - 1)) { |
| 5293 | // (mul x, 2^N + 1) => (add (shl x, N), x) |
| 5294 | Res = DAG.getNode(ISD::ADD, DL, VT, |
| 5295 | V, DAG.getNode(ISD::SHL, DL, VT, |
| 5296 | V, DAG.getConstant(Log2_32(MulAmt-1), |
| 5297 | MVT::i32))); |
| 5298 | } else if (isPowerOf2_32(MulAmt + 1)) { |
| 5299 | // (mul x, 2^N - 1) => (sub (shl x, N), x) |
| 5300 | Res = DAG.getNode(ISD::SUB, DL, VT, |
| 5301 | DAG.getNode(ISD::SHL, DL, VT, |
| 5302 | V, DAG.getConstant(Log2_32(MulAmt+1), |
| 5303 | MVT::i32)), |
| 5304 | V); |
| 5305 | } else |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 5306 | return SDValue(); |
Anton Korobeynikov | 4878b84 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 5307 | |
| 5308 | if (ShiftAmt != 0) |
| 5309 | Res = DAG.getNode(ISD::SHL, DL, VT, Res, |
| 5310 | DAG.getConstant(ShiftAmt, MVT::i32)); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 5311 | |
| 5312 | // Do not add new nodes to DAG combiner worklist. |
Anton Korobeynikov | 4878b84 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 5313 | DCI.CombineTo(N, Res, false); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 5314 | return SDValue(); |
| 5315 | } |
| 5316 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 5317 | static SDValue PerformANDCombine(SDNode *N, |
| 5318 | TargetLowering::DAGCombinerInfo &DCI) { |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 5319 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 5320 | // Attempt to use immediate-form VBIC |
| 5321 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(N->getOperand(1)); |
| 5322 | DebugLoc dl = N->getDebugLoc(); |
| 5323 | EVT VT = N->getValueType(0); |
| 5324 | SelectionDAG &DAG = DCI.DAG; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5325 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 5326 | APInt SplatBits, SplatUndef; |
| 5327 | unsigned SplatBitSize; |
| 5328 | bool HasAnyUndefs; |
| 5329 | if (BVN && |
| 5330 | BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { |
| 5331 | if (SplatBitSize <= 64) { |
| 5332 | EVT VbicVT; |
| 5333 | SDValue Val = isNEONModifiedImm((~SplatBits).getZExtValue(), |
| 5334 | SplatUndef.getZExtValue(), SplatBitSize, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5335 | DAG, VbicVT, VT.is128BitVector(), |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 5336 | OtherModImm); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 5337 | if (Val.getNode()) { |
| 5338 | SDValue Input = |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5339 | DAG.getNode(ISD::BITCAST, dl, VbicVT, N->getOperand(0)); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 5340 | SDValue Vbic = DAG.getNode(ARMISD::VBICIMM, dl, VbicVT, Input, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5341 | return DAG.getNode(ISD::BITCAST, dl, VT, Vbic); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 5342 | } |
| 5343 | } |
| 5344 | } |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5345 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 5346 | return SDValue(); |
| 5347 | } |
| 5348 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 5349 | /// PerformORCombine - Target-specific dag combine xforms for ISD::OR |
| 5350 | static SDValue PerformORCombine(SDNode *N, |
| 5351 | TargetLowering::DAGCombinerInfo &DCI, |
| 5352 | const ARMSubtarget *Subtarget) { |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 5353 | // Attempt to use immediate-form VORR |
| 5354 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(N->getOperand(1)); |
| 5355 | DebugLoc dl = N->getDebugLoc(); |
| 5356 | EVT VT = N->getValueType(0); |
| 5357 | SelectionDAG &DAG = DCI.DAG; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5358 | |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 5359 | APInt SplatBits, SplatUndef; |
| 5360 | unsigned SplatBitSize; |
| 5361 | bool HasAnyUndefs; |
| 5362 | if (BVN && Subtarget->hasNEON() && |
| 5363 | BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { |
| 5364 | if (SplatBitSize <= 64) { |
| 5365 | EVT VorrVT; |
| 5366 | SDValue Val = isNEONModifiedImm(SplatBits.getZExtValue(), |
| 5367 | SplatUndef.getZExtValue(), SplatBitSize, |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 5368 | DAG, VorrVT, VT.is128BitVector(), |
| 5369 | OtherModImm); |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 5370 | if (Val.getNode()) { |
| 5371 | SDValue Input = |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5372 | DAG.getNode(ISD::BITCAST, dl, VorrVT, N->getOperand(0)); |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 5373 | SDValue Vorr = DAG.getNode(ARMISD::VORRIMM, dl, VorrVT, Input, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5374 | return DAG.getNode(ISD::BITCAST, dl, VT, Vorr); |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 5375 | } |
| 5376 | } |
| 5377 | } |
| 5378 | |
Cameron Zwarich | c0e6d78 | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 5379 | SDValue N0 = N->getOperand(0); |
| 5380 | if (N0.getOpcode() != ISD::AND) |
| 5381 | return SDValue(); |
| 5382 | SDValue N1 = N->getOperand(1); |
| 5383 | |
| 5384 | // (or (and B, A), (and C, ~A)) => (VBSL A, B, C) when A is a constant. |
| 5385 | if (Subtarget->hasNEON() && N1.getOpcode() == ISD::AND && VT.isVector() && |
| 5386 | DAG.getTargetLoweringInfo().isTypeLegal(VT)) { |
| 5387 | APInt SplatUndef; |
| 5388 | unsigned SplatBitSize; |
| 5389 | bool HasAnyUndefs; |
| 5390 | |
| 5391 | BuildVectorSDNode *BVN0 = dyn_cast<BuildVectorSDNode>(N0->getOperand(1)); |
| 5392 | APInt SplatBits0; |
| 5393 | if (BVN0 && BVN0->isConstantSplat(SplatBits0, SplatUndef, SplatBitSize, |
| 5394 | HasAnyUndefs) && !HasAnyUndefs) { |
| 5395 | BuildVectorSDNode *BVN1 = dyn_cast<BuildVectorSDNode>(N1->getOperand(1)); |
| 5396 | APInt SplatBits1; |
| 5397 | if (BVN1 && BVN1->isConstantSplat(SplatBits1, SplatUndef, SplatBitSize, |
| 5398 | HasAnyUndefs) && !HasAnyUndefs && |
| 5399 | SplatBits0 == ~SplatBits1) { |
| 5400 | // Canonicalize the vector type to make instruction selection simpler. |
| 5401 | EVT CanonicalVT = VT.is128BitVector() ? MVT::v4i32 : MVT::v2i32; |
| 5402 | SDValue Result = DAG.getNode(ARMISD::VBSL, dl, CanonicalVT, |
| 5403 | N0->getOperand(1), N0->getOperand(0), |
| 5404 | N1->getOperand(1)); |
| 5405 | return DAG.getNode(ISD::BITCAST, dl, VT, Result); |
| 5406 | } |
| 5407 | } |
| 5408 | } |
| 5409 | |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5410 | // Try to use the ARM/Thumb2 BFI (bitfield insert) instruction when |
| 5411 | // reasonable. |
| 5412 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 5413 | // BFI is only available on V6T2+ |
| 5414 | if (Subtarget->isThumb1Only() || !Subtarget->hasV6T2Ops()) |
| 5415 | return SDValue(); |
| 5416 | |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5417 | DebugLoc DL = N->getDebugLoc(); |
| 5418 | // 1) or (and A, mask), val => ARMbfi A, val, mask |
| 5419 | // iff (val & mask) == val |
| 5420 | // |
| 5421 | // 2) or (and A, mask), (and B, mask2) => ARMbfi A, (lsr B, amt), mask |
| 5422 | // 2a) iff isBitFieldInvertedMask(mask) && isBitFieldInvertedMask(~mask2) |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 5423 | // && mask == ~mask2 |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5424 | // 2b) iff isBitFieldInvertedMask(~mask) && isBitFieldInvertedMask(mask2) |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 5425 | // && ~mask == mask2 |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5426 | // (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] | 5427 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 5428 | if (VT != MVT::i32) |
| 5429 | return SDValue(); |
| 5430 | |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 5431 | SDValue N00 = N0.getOperand(0); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5432 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 5433 | // The value and the mask need to be constants so we can verify this is |
| 5434 | // actually a bitfield set. If the mask is 0xffff, we can do better |
| 5435 | // via a movt instruction, so don't use BFI in that case. |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 5436 | SDValue MaskOp = N0.getOperand(1); |
| 5437 | ConstantSDNode *MaskC = dyn_cast<ConstantSDNode>(MaskOp); |
| 5438 | if (!MaskC) |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 5439 | return SDValue(); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 5440 | unsigned Mask = MaskC->getZExtValue(); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 5441 | if (Mask == 0xffff) |
| 5442 | return SDValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5443 | SDValue Res; |
| 5444 | // Case (1): or (and A, mask), val => ARMbfi A, val, mask |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 5445 | ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1); |
| 5446 | if (N1C) { |
| 5447 | unsigned Val = N1C->getZExtValue(); |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 5448 | if ((Val & ~Mask) != Val) |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5449 | return SDValue(); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 5450 | |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 5451 | if (ARM::isBitFieldInvertedMask(Mask)) { |
| 5452 | Val >>= CountTrailingZeros_32(~Mask); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 5453 | |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 5454 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N00, |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 5455 | DAG.getConstant(Val, MVT::i32), |
| 5456 | DAG.getConstant(Mask, MVT::i32)); |
| 5457 | |
| 5458 | // Do not add new nodes to DAG combiner worklist. |
| 5459 | DCI.CombineTo(N, Res, false); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 5460 | return SDValue(); |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 5461 | } |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5462 | } else if (N1.getOpcode() == ISD::AND) { |
| 5463 | // 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] | 5464 | ConstantSDNode *N11C = dyn_cast<ConstantSDNode>(N1.getOperand(1)); |
| 5465 | if (!N11C) |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5466 | return SDValue(); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 5467 | unsigned Mask2 = N11C->getZExtValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5468 | |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 5469 | // Mask and ~Mask2 (or reverse) must be equivalent for the BFI pattern |
| 5470 | // as is to match. |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5471 | if (ARM::isBitFieldInvertedMask(Mask) && |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 5472 | (Mask == ~Mask2)) { |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5473 | // The pack halfword instruction works better for masks that fit it, |
| 5474 | // so use that when it's available. |
| 5475 | if (Subtarget->hasT2ExtractPack() && |
| 5476 | (Mask == 0xffff || Mask == 0xffff0000)) |
| 5477 | return SDValue(); |
| 5478 | // 2a |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 5479 | unsigned amt = CountTrailingZeros_32(Mask2); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5480 | Res = DAG.getNode(ISD::SRL, DL, VT, N1.getOperand(0), |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 5481 | DAG.getConstant(amt, MVT::i32)); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 5482 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N00, Res, |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5483 | DAG.getConstant(Mask, MVT::i32)); |
| 5484 | // Do not add new nodes to DAG combiner worklist. |
| 5485 | DCI.CombineTo(N, Res, false); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 5486 | return SDValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5487 | } else if (ARM::isBitFieldInvertedMask(~Mask) && |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 5488 | (~Mask == Mask2)) { |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5489 | // The pack halfword instruction works better for masks that fit it, |
| 5490 | // so use that when it's available. |
| 5491 | if (Subtarget->hasT2ExtractPack() && |
| 5492 | (Mask2 == 0xffff || Mask2 == 0xffff0000)) |
| 5493 | return SDValue(); |
| 5494 | // 2b |
| 5495 | unsigned lsb = CountTrailingZeros_32(Mask); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 5496 | Res = DAG.getNode(ISD::SRL, DL, VT, N00, |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5497 | DAG.getConstant(lsb, MVT::i32)); |
| 5498 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N1.getOperand(0), Res, |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 5499 | DAG.getConstant(Mask2, MVT::i32)); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5500 | // Do not add new nodes to DAG combiner worklist. |
| 5501 | DCI.CombineTo(N, Res, false); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 5502 | return SDValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5503 | } |
| 5504 | } |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5505 | |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 5506 | if (DAG.MaskedValueIsZero(N1, MaskC->getAPIntValue()) && |
| 5507 | N00.getOpcode() == ISD::SHL && isa<ConstantSDNode>(N00.getOperand(1)) && |
| 5508 | ARM::isBitFieldInvertedMask(~Mask)) { |
| 5509 | // Case (3): or (and (shl A, #shamt), mask), B => ARMbfi B, A, ~mask |
| 5510 | // where lsb(mask) == #shamt and masked bits of B are known zero. |
| 5511 | SDValue ShAmt = N00.getOperand(1); |
| 5512 | unsigned ShAmtC = cast<ConstantSDNode>(ShAmt)->getZExtValue(); |
| 5513 | unsigned LSB = CountTrailingZeros_32(Mask); |
| 5514 | if (ShAmtC != LSB) |
| 5515 | return SDValue(); |
| 5516 | |
| 5517 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N1, N00.getOperand(0), |
| 5518 | DAG.getConstant(~Mask, MVT::i32)); |
| 5519 | |
| 5520 | // Do not add new nodes to DAG combiner worklist. |
| 5521 | DCI.CombineTo(N, Res, false); |
| 5522 | } |
| 5523 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 5524 | return SDValue(); |
| 5525 | } |
| 5526 | |
Evan Cheng | 0c1aec1 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 5527 | /// PerformBFICombine - (bfi A, (and B, C1), C2) -> (bfi A, B, C2) iff |
| 5528 | /// C1 & C2 == C1. |
| 5529 | static SDValue PerformBFICombine(SDNode *N, |
| 5530 | TargetLowering::DAGCombinerInfo &DCI) { |
| 5531 | SDValue N1 = N->getOperand(1); |
| 5532 | if (N1.getOpcode() == ISD::AND) { |
| 5533 | ConstantSDNode *N11C = dyn_cast<ConstantSDNode>(N1.getOperand(1)); |
| 5534 | if (!N11C) |
| 5535 | return SDValue(); |
| 5536 | unsigned Mask = cast<ConstantSDNode>(N->getOperand(2))->getZExtValue(); |
| 5537 | unsigned Mask2 = N11C->getZExtValue(); |
| 5538 | if ((Mask & Mask2) == Mask2) |
| 5539 | return DCI.DAG.getNode(ARMISD::BFI, N->getDebugLoc(), N->getValueType(0), |
| 5540 | N->getOperand(0), N1.getOperand(0), |
| 5541 | N->getOperand(2)); |
| 5542 | } |
| 5543 | return SDValue(); |
| 5544 | } |
| 5545 | |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 5546 | /// PerformVMOVRRDCombine - Target-specific dag combine xforms for |
| 5547 | /// ARMISD::VMOVRRD. |
| 5548 | static SDValue PerformVMOVRRDCombine(SDNode *N, |
| 5549 | TargetLowering::DAGCombinerInfo &DCI) { |
| 5550 | // vmovrrd(vmovdrr x, y) -> x,y |
| 5551 | SDValue InDouble = N->getOperand(0); |
| 5552 | if (InDouble.getOpcode() == ARMISD::VMOVDRR) |
| 5553 | return DCI.CombineTo(N, InDouble.getOperand(0), InDouble.getOperand(1)); |
| 5554 | return SDValue(); |
| 5555 | } |
| 5556 | |
| 5557 | /// PerformVMOVDRRCombine - Target-specific dag combine xforms for |
| 5558 | /// ARMISD::VMOVDRR. This is also used for BUILD_VECTORs with 2 operands. |
| 5559 | static SDValue PerformVMOVDRRCombine(SDNode *N, SelectionDAG &DAG) { |
| 5560 | // N=vmovrrd(X); vmovdrr(N:0, N:1) -> bit_convert(X) |
| 5561 | SDValue Op0 = N->getOperand(0); |
| 5562 | SDValue Op1 = N->getOperand(1); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5563 | if (Op0.getOpcode() == ISD::BITCAST) |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 5564 | Op0 = Op0.getOperand(0); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5565 | if (Op1.getOpcode() == ISD::BITCAST) |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 5566 | Op1 = Op1.getOperand(0); |
| 5567 | if (Op0.getOpcode() == ARMISD::VMOVRRD && |
| 5568 | Op0.getNode() == Op1.getNode() && |
| 5569 | Op0.getResNo() == 0 && Op1.getResNo() == 1) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5570 | return DAG.getNode(ISD::BITCAST, N->getDebugLoc(), |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 5571 | N->getValueType(0), Op0.getOperand(0)); |
| 5572 | return SDValue(); |
| 5573 | } |
| 5574 | |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 5575 | /// PerformSTORECombine - Target-specific dag combine xforms for |
| 5576 | /// ISD::STORE. |
| 5577 | static SDValue PerformSTORECombine(SDNode *N, |
| 5578 | TargetLowering::DAGCombinerInfo &DCI) { |
| 5579 | // Bitcast an i64 store extracted from a vector to f64. |
| 5580 | // Otherwise, the i64 value will be legalized to a pair of i32 values. |
| 5581 | StoreSDNode *St = cast<StoreSDNode>(N); |
| 5582 | SDValue StVal = St->getValue(); |
| 5583 | if (!ISD::isNormalStore(St) || St->isVolatile() || |
| 5584 | StVal.getValueType() != MVT::i64 || |
| 5585 | StVal.getNode()->getOpcode() != ISD::EXTRACT_VECTOR_ELT) |
| 5586 | return SDValue(); |
| 5587 | |
| 5588 | SelectionDAG &DAG = DCI.DAG; |
| 5589 | DebugLoc dl = StVal.getDebugLoc(); |
| 5590 | SDValue IntVec = StVal.getOperand(0); |
| 5591 | EVT FloatVT = EVT::getVectorVT(*DAG.getContext(), MVT::f64, |
| 5592 | IntVec.getValueType().getVectorNumElements()); |
| 5593 | SDValue Vec = DAG.getNode(ISD::BITCAST, dl, FloatVT, IntVec); |
| 5594 | SDValue ExtElt = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, |
| 5595 | Vec, StVal.getOperand(1)); |
| 5596 | dl = N->getDebugLoc(); |
| 5597 | SDValue V = DAG.getNode(ISD::BITCAST, dl, MVT::i64, ExtElt); |
| 5598 | // Make the DAGCombiner fold the bitcasts. |
| 5599 | DCI.AddToWorklist(Vec.getNode()); |
| 5600 | DCI.AddToWorklist(ExtElt.getNode()); |
| 5601 | DCI.AddToWorklist(V.getNode()); |
| 5602 | return DAG.getStore(St->getChain(), dl, V, St->getBasePtr(), |
| 5603 | St->getPointerInfo(), St->isVolatile(), |
| 5604 | St->isNonTemporal(), St->getAlignment(), |
| 5605 | St->getTBAAInfo()); |
| 5606 | } |
| 5607 | |
| 5608 | /// hasNormalLoadOperand - Check if any of the operands of a BUILD_VECTOR node |
| 5609 | /// are normal, non-volatile loads. If so, it is profitable to bitcast an |
| 5610 | /// i64 vector to have f64 elements, since the value can then be loaded |
| 5611 | /// directly into a VFP register. |
| 5612 | static bool hasNormalLoadOperand(SDNode *N) { |
| 5613 | unsigned NumElts = N->getValueType(0).getVectorNumElements(); |
| 5614 | for (unsigned i = 0; i < NumElts; ++i) { |
| 5615 | SDNode *Elt = N->getOperand(i).getNode(); |
| 5616 | if (ISD::isNormalLoad(Elt) && !cast<LoadSDNode>(Elt)->isVolatile()) |
| 5617 | return true; |
| 5618 | } |
| 5619 | return false; |
| 5620 | } |
| 5621 | |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 5622 | /// PerformBUILD_VECTORCombine - Target-specific dag combine xforms for |
| 5623 | /// ISD::BUILD_VECTOR. |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 5624 | static SDValue PerformBUILD_VECTORCombine(SDNode *N, |
| 5625 | TargetLowering::DAGCombinerInfo &DCI){ |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 5626 | // build_vector(N=ARMISD::VMOVRRD(X), N:1) -> bit_convert(X): |
| 5627 | // VMOVRRD is introduced when legalizing i64 types. It forces the i64 value |
| 5628 | // into a pair of GPRs, which is fine when the value is used as a scalar, |
| 5629 | // 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] | 5630 | SelectionDAG &DAG = DCI.DAG; |
| 5631 | if (N->getNumOperands() == 2) { |
| 5632 | SDValue RV = PerformVMOVDRRCombine(N, DAG); |
| 5633 | if (RV.getNode()) |
| 5634 | return RV; |
| 5635 | } |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 5636 | |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 5637 | // Load i64 elements as f64 values so that type legalization does not split |
| 5638 | // them up into i32 values. |
| 5639 | EVT VT = N->getValueType(0); |
| 5640 | if (VT.getVectorElementType() != MVT::i64 || !hasNormalLoadOperand(N)) |
| 5641 | return SDValue(); |
| 5642 | DebugLoc dl = N->getDebugLoc(); |
| 5643 | SmallVector<SDValue, 8> Ops; |
| 5644 | unsigned NumElts = VT.getVectorNumElements(); |
| 5645 | for (unsigned i = 0; i < NumElts; ++i) { |
| 5646 | SDValue V = DAG.getNode(ISD::BITCAST, dl, MVT::f64, N->getOperand(i)); |
| 5647 | Ops.push_back(V); |
| 5648 | // Make the DAGCombiner fold the bitcast. |
| 5649 | DCI.AddToWorklist(V.getNode()); |
| 5650 | } |
| 5651 | EVT FloatVT = EVT::getVectorVT(*DAG.getContext(), MVT::f64, NumElts); |
| 5652 | SDValue BV = DAG.getNode(ISD::BUILD_VECTOR, dl, FloatVT, Ops.data(), NumElts); |
| 5653 | return DAG.getNode(ISD::BITCAST, dl, VT, BV); |
| 5654 | } |
| 5655 | |
| 5656 | /// PerformInsertEltCombine - Target-specific dag combine xforms for |
| 5657 | /// ISD::INSERT_VECTOR_ELT. |
| 5658 | static SDValue PerformInsertEltCombine(SDNode *N, |
| 5659 | TargetLowering::DAGCombinerInfo &DCI) { |
| 5660 | // Bitcast an i64 load inserted into a vector to f64. |
| 5661 | // Otherwise, the i64 value will be legalized to a pair of i32 values. |
| 5662 | EVT VT = N->getValueType(0); |
| 5663 | SDNode *Elt = N->getOperand(1).getNode(); |
| 5664 | if (VT.getVectorElementType() != MVT::i64 || |
| 5665 | !ISD::isNormalLoad(Elt) || cast<LoadSDNode>(Elt)->isVolatile()) |
| 5666 | return SDValue(); |
| 5667 | |
| 5668 | SelectionDAG &DAG = DCI.DAG; |
| 5669 | DebugLoc dl = N->getDebugLoc(); |
| 5670 | EVT FloatVT = EVT::getVectorVT(*DAG.getContext(), MVT::f64, |
| 5671 | VT.getVectorNumElements()); |
| 5672 | SDValue Vec = DAG.getNode(ISD::BITCAST, dl, FloatVT, N->getOperand(0)); |
| 5673 | SDValue V = DAG.getNode(ISD::BITCAST, dl, MVT::f64, N->getOperand(1)); |
| 5674 | // Make the DAGCombiner fold the bitcasts. |
| 5675 | DCI.AddToWorklist(Vec.getNode()); |
| 5676 | DCI.AddToWorklist(V.getNode()); |
| 5677 | SDValue InsElt = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, FloatVT, |
| 5678 | Vec, V, N->getOperand(2)); |
| 5679 | return DAG.getNode(ISD::BITCAST, dl, VT, InsElt); |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 5680 | } |
| 5681 | |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 5682 | /// PerformVECTOR_SHUFFLECombine - Target-specific dag combine xforms for |
| 5683 | /// ISD::VECTOR_SHUFFLE. |
| 5684 | static SDValue PerformVECTOR_SHUFFLECombine(SDNode *N, SelectionDAG &DAG) { |
| 5685 | // The LLVM shufflevector instruction does not require the shuffle mask |
| 5686 | // length to match the operand vector length, but ISD::VECTOR_SHUFFLE does |
| 5687 | // have that requirement. When translating to ISD::VECTOR_SHUFFLE, if the |
| 5688 | // operands do not match the mask length, they are extended by concatenating |
| 5689 | // them with undef vectors. That is probably the right thing for other |
| 5690 | // targets, but for NEON it is better to concatenate two double-register |
| 5691 | // size vector operands into a single quad-register size vector. Do that |
| 5692 | // transformation here: |
| 5693 | // shuffle(concat(v1, undef), concat(v2, undef)) -> |
| 5694 | // shuffle(concat(v1, v2), undef) |
| 5695 | SDValue Op0 = N->getOperand(0); |
| 5696 | SDValue Op1 = N->getOperand(1); |
| 5697 | if (Op0.getOpcode() != ISD::CONCAT_VECTORS || |
| 5698 | Op1.getOpcode() != ISD::CONCAT_VECTORS || |
| 5699 | Op0.getNumOperands() != 2 || |
| 5700 | Op1.getNumOperands() != 2) |
| 5701 | return SDValue(); |
| 5702 | SDValue Concat0Op1 = Op0.getOperand(1); |
| 5703 | SDValue Concat1Op1 = Op1.getOperand(1); |
| 5704 | if (Concat0Op1.getOpcode() != ISD::UNDEF || |
| 5705 | Concat1Op1.getOpcode() != ISD::UNDEF) |
| 5706 | return SDValue(); |
| 5707 | // Skip the transformation if any of the types are illegal. |
| 5708 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 5709 | EVT VT = N->getValueType(0); |
| 5710 | if (!TLI.isTypeLegal(VT) || |
| 5711 | !TLI.isTypeLegal(Concat0Op1.getValueType()) || |
| 5712 | !TLI.isTypeLegal(Concat1Op1.getValueType())) |
| 5713 | return SDValue(); |
| 5714 | |
| 5715 | SDValue NewConcat = DAG.getNode(ISD::CONCAT_VECTORS, N->getDebugLoc(), VT, |
| 5716 | Op0.getOperand(0), Op1.getOperand(0)); |
| 5717 | // Translate the shuffle mask. |
| 5718 | SmallVector<int, 16> NewMask; |
| 5719 | unsigned NumElts = VT.getVectorNumElements(); |
| 5720 | unsigned HalfElts = NumElts/2; |
| 5721 | ShuffleVectorSDNode *SVN = cast<ShuffleVectorSDNode>(N); |
| 5722 | for (unsigned n = 0; n < NumElts; ++n) { |
| 5723 | int MaskElt = SVN->getMaskElt(n); |
| 5724 | int NewElt = -1; |
Bob Wilson | 1fa9d30 | 2010-10-27 23:49:00 +0000 | [diff] [blame] | 5725 | if (MaskElt < (int)HalfElts) |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 5726 | NewElt = MaskElt; |
Bob Wilson | 1fa9d30 | 2010-10-27 23:49:00 +0000 | [diff] [blame] | 5727 | else if (MaskElt >= (int)NumElts && MaskElt < (int)(NumElts + HalfElts)) |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 5728 | NewElt = HalfElts + MaskElt - NumElts; |
| 5729 | NewMask.push_back(NewElt); |
| 5730 | } |
| 5731 | return DAG.getVectorShuffle(VT, N->getDebugLoc(), NewConcat, |
| 5732 | DAG.getUNDEF(VT), NewMask.data()); |
| 5733 | } |
| 5734 | |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 5735 | /// CombineBaseUpdate - Target-specific DAG combine function for VLDDUP and |
| 5736 | /// NEON load/store intrinsics to merge base address updates. |
| 5737 | static SDValue CombineBaseUpdate(SDNode *N, |
| 5738 | TargetLowering::DAGCombinerInfo &DCI) { |
| 5739 | if (DCI.isBeforeLegalize() || DCI.isCalledByLegalizer()) |
| 5740 | return SDValue(); |
| 5741 | |
| 5742 | SelectionDAG &DAG = DCI.DAG; |
| 5743 | bool isIntrinsic = (N->getOpcode() == ISD::INTRINSIC_VOID || |
| 5744 | N->getOpcode() == ISD::INTRINSIC_W_CHAIN); |
| 5745 | unsigned AddrOpIdx = (isIntrinsic ? 2 : 1); |
| 5746 | SDValue Addr = N->getOperand(AddrOpIdx); |
| 5747 | |
| 5748 | // Search for a use of the address operand that is an increment. |
| 5749 | for (SDNode::use_iterator UI = Addr.getNode()->use_begin(), |
| 5750 | UE = Addr.getNode()->use_end(); UI != UE; ++UI) { |
| 5751 | SDNode *User = *UI; |
| 5752 | if (User->getOpcode() != ISD::ADD || |
| 5753 | UI.getUse().getResNo() != Addr.getResNo()) |
| 5754 | continue; |
| 5755 | |
| 5756 | // Check that the add is independent of the load/store. Otherwise, folding |
| 5757 | // it would create a cycle. |
| 5758 | if (User->isPredecessorOf(N) || N->isPredecessorOf(User)) |
| 5759 | continue; |
| 5760 | |
| 5761 | // Find the new opcode for the updating load/store. |
| 5762 | bool isLoad = true; |
| 5763 | bool isLaneOp = false; |
| 5764 | unsigned NewOpc = 0; |
| 5765 | unsigned NumVecs = 0; |
| 5766 | if (isIntrinsic) { |
| 5767 | unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue(); |
| 5768 | switch (IntNo) { |
| 5769 | default: assert(0 && "unexpected intrinsic for Neon base update"); |
| 5770 | case Intrinsic::arm_neon_vld1: NewOpc = ARMISD::VLD1_UPD; |
| 5771 | NumVecs = 1; break; |
| 5772 | case Intrinsic::arm_neon_vld2: NewOpc = ARMISD::VLD2_UPD; |
| 5773 | NumVecs = 2; break; |
| 5774 | case Intrinsic::arm_neon_vld3: NewOpc = ARMISD::VLD3_UPD; |
| 5775 | NumVecs = 3; break; |
| 5776 | case Intrinsic::arm_neon_vld4: NewOpc = ARMISD::VLD4_UPD; |
| 5777 | NumVecs = 4; break; |
| 5778 | case Intrinsic::arm_neon_vld2lane: NewOpc = ARMISD::VLD2LN_UPD; |
| 5779 | NumVecs = 2; isLaneOp = true; break; |
| 5780 | case Intrinsic::arm_neon_vld3lane: NewOpc = ARMISD::VLD3LN_UPD; |
| 5781 | NumVecs = 3; isLaneOp = true; break; |
| 5782 | case Intrinsic::arm_neon_vld4lane: NewOpc = ARMISD::VLD4LN_UPD; |
| 5783 | NumVecs = 4; isLaneOp = true; break; |
| 5784 | case Intrinsic::arm_neon_vst1: NewOpc = ARMISD::VST1_UPD; |
| 5785 | NumVecs = 1; isLoad = false; break; |
| 5786 | case Intrinsic::arm_neon_vst2: NewOpc = ARMISD::VST2_UPD; |
| 5787 | NumVecs = 2; isLoad = false; break; |
| 5788 | case Intrinsic::arm_neon_vst3: NewOpc = ARMISD::VST3_UPD; |
| 5789 | NumVecs = 3; isLoad = false; break; |
| 5790 | case Intrinsic::arm_neon_vst4: NewOpc = ARMISD::VST4_UPD; |
| 5791 | NumVecs = 4; isLoad = false; break; |
| 5792 | case Intrinsic::arm_neon_vst2lane: NewOpc = ARMISD::VST2LN_UPD; |
| 5793 | NumVecs = 2; isLoad = false; isLaneOp = true; break; |
| 5794 | case Intrinsic::arm_neon_vst3lane: NewOpc = ARMISD::VST3LN_UPD; |
| 5795 | NumVecs = 3; isLoad = false; isLaneOp = true; break; |
| 5796 | case Intrinsic::arm_neon_vst4lane: NewOpc = ARMISD::VST4LN_UPD; |
| 5797 | NumVecs = 4; isLoad = false; isLaneOp = true; break; |
| 5798 | } |
| 5799 | } else { |
| 5800 | isLaneOp = true; |
| 5801 | switch (N->getOpcode()) { |
| 5802 | default: assert(0 && "unexpected opcode for Neon base update"); |
| 5803 | case ARMISD::VLD2DUP: NewOpc = ARMISD::VLD2DUP_UPD; NumVecs = 2; break; |
| 5804 | case ARMISD::VLD3DUP: NewOpc = ARMISD::VLD3DUP_UPD; NumVecs = 3; break; |
| 5805 | case ARMISD::VLD4DUP: NewOpc = ARMISD::VLD4DUP_UPD; NumVecs = 4; break; |
| 5806 | } |
| 5807 | } |
| 5808 | |
| 5809 | // Find the size of memory referenced by the load/store. |
| 5810 | EVT VecTy; |
| 5811 | if (isLoad) |
| 5812 | VecTy = N->getValueType(0); |
| 5813 | else |
| 5814 | VecTy = N->getOperand(AddrOpIdx+1).getValueType(); |
| 5815 | unsigned NumBytes = NumVecs * VecTy.getSizeInBits() / 8; |
| 5816 | if (isLaneOp) |
| 5817 | NumBytes /= VecTy.getVectorNumElements(); |
| 5818 | |
| 5819 | // If the increment is a constant, it must match the memory ref size. |
| 5820 | SDValue Inc = User->getOperand(User->getOperand(0) == Addr ? 1 : 0); |
| 5821 | if (ConstantSDNode *CInc = dyn_cast<ConstantSDNode>(Inc.getNode())) { |
| 5822 | uint64_t IncVal = CInc->getZExtValue(); |
| 5823 | if (IncVal != NumBytes) |
| 5824 | continue; |
| 5825 | } else if (NumBytes >= 3 * 16) { |
| 5826 | // VLD3/4 and VST3/4 for 128-bit vectors are implemented with two |
| 5827 | // separate instructions that make it harder to use a non-constant update. |
| 5828 | continue; |
| 5829 | } |
| 5830 | |
| 5831 | // Create the new updating load/store node. |
| 5832 | EVT Tys[6]; |
| 5833 | unsigned NumResultVecs = (isLoad ? NumVecs : 0); |
| 5834 | unsigned n; |
| 5835 | for (n = 0; n < NumResultVecs; ++n) |
| 5836 | Tys[n] = VecTy; |
| 5837 | Tys[n++] = MVT::i32; |
| 5838 | Tys[n] = MVT::Other; |
| 5839 | SDVTList SDTys = DAG.getVTList(Tys, NumResultVecs+2); |
| 5840 | SmallVector<SDValue, 8> Ops; |
| 5841 | Ops.push_back(N->getOperand(0)); // incoming chain |
| 5842 | Ops.push_back(N->getOperand(AddrOpIdx)); |
| 5843 | Ops.push_back(Inc); |
| 5844 | for (unsigned i = AddrOpIdx + 1; i < N->getNumOperands(); ++i) { |
| 5845 | Ops.push_back(N->getOperand(i)); |
| 5846 | } |
| 5847 | MemIntrinsicSDNode *MemInt = cast<MemIntrinsicSDNode>(N); |
| 5848 | SDValue UpdN = DAG.getMemIntrinsicNode(NewOpc, N->getDebugLoc(), SDTys, |
| 5849 | Ops.data(), Ops.size(), |
| 5850 | MemInt->getMemoryVT(), |
| 5851 | MemInt->getMemOperand()); |
| 5852 | |
| 5853 | // Update the uses. |
| 5854 | std::vector<SDValue> NewResults; |
| 5855 | for (unsigned i = 0; i < NumResultVecs; ++i) { |
| 5856 | NewResults.push_back(SDValue(UpdN.getNode(), i)); |
| 5857 | } |
| 5858 | NewResults.push_back(SDValue(UpdN.getNode(), NumResultVecs+1)); // chain |
| 5859 | DCI.CombineTo(N, NewResults); |
| 5860 | DCI.CombineTo(User, SDValue(UpdN.getNode(), NumResultVecs)); |
| 5861 | |
| 5862 | break; |
| 5863 | } |
| 5864 | return SDValue(); |
| 5865 | } |
| 5866 | |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 5867 | /// CombineVLDDUP - For a VDUPLANE node N, check if its source operand is a |
| 5868 | /// vldN-lane (N > 1) intrinsic, and if all the other uses of that intrinsic |
| 5869 | /// are also VDUPLANEs. If so, combine them to a vldN-dup operation and |
| 5870 | /// return true. |
| 5871 | static bool CombineVLDDUP(SDNode *N, TargetLowering::DAGCombinerInfo &DCI) { |
| 5872 | SelectionDAG &DAG = DCI.DAG; |
| 5873 | EVT VT = N->getValueType(0); |
| 5874 | // vldN-dup instructions only support 64-bit vectors for N > 1. |
| 5875 | if (!VT.is64BitVector()) |
| 5876 | return false; |
| 5877 | |
| 5878 | // Check if the VDUPLANE operand is a vldN-dup intrinsic. |
| 5879 | SDNode *VLD = N->getOperand(0).getNode(); |
| 5880 | if (VLD->getOpcode() != ISD::INTRINSIC_W_CHAIN) |
| 5881 | return false; |
| 5882 | unsigned NumVecs = 0; |
| 5883 | unsigned NewOpc = 0; |
| 5884 | unsigned IntNo = cast<ConstantSDNode>(VLD->getOperand(1))->getZExtValue(); |
| 5885 | if (IntNo == Intrinsic::arm_neon_vld2lane) { |
| 5886 | NumVecs = 2; |
| 5887 | NewOpc = ARMISD::VLD2DUP; |
| 5888 | } else if (IntNo == Intrinsic::arm_neon_vld3lane) { |
| 5889 | NumVecs = 3; |
| 5890 | NewOpc = ARMISD::VLD3DUP; |
| 5891 | } else if (IntNo == Intrinsic::arm_neon_vld4lane) { |
| 5892 | NumVecs = 4; |
| 5893 | NewOpc = ARMISD::VLD4DUP; |
| 5894 | } else { |
| 5895 | return false; |
| 5896 | } |
| 5897 | |
| 5898 | // First check that all the vldN-lane uses are VDUPLANEs and that the lane |
| 5899 | // numbers match the load. |
| 5900 | unsigned VLDLaneNo = |
| 5901 | cast<ConstantSDNode>(VLD->getOperand(NumVecs+3))->getZExtValue(); |
| 5902 | for (SDNode::use_iterator UI = VLD->use_begin(), UE = VLD->use_end(); |
| 5903 | UI != UE; ++UI) { |
| 5904 | // Ignore uses of the chain result. |
| 5905 | if (UI.getUse().getResNo() == NumVecs) |
| 5906 | continue; |
| 5907 | SDNode *User = *UI; |
| 5908 | if (User->getOpcode() != ARMISD::VDUPLANE || |
| 5909 | VLDLaneNo != cast<ConstantSDNode>(User->getOperand(1))->getZExtValue()) |
| 5910 | return false; |
| 5911 | } |
| 5912 | |
| 5913 | // Create the vldN-dup node. |
| 5914 | EVT Tys[5]; |
| 5915 | unsigned n; |
| 5916 | for (n = 0; n < NumVecs; ++n) |
| 5917 | Tys[n] = VT; |
| 5918 | Tys[n] = MVT::Other; |
| 5919 | SDVTList SDTys = DAG.getVTList(Tys, NumVecs+1); |
| 5920 | SDValue Ops[] = { VLD->getOperand(0), VLD->getOperand(2) }; |
| 5921 | MemIntrinsicSDNode *VLDMemInt = cast<MemIntrinsicSDNode>(VLD); |
| 5922 | SDValue VLDDup = DAG.getMemIntrinsicNode(NewOpc, VLD->getDebugLoc(), SDTys, |
| 5923 | Ops, 2, VLDMemInt->getMemoryVT(), |
| 5924 | VLDMemInt->getMemOperand()); |
| 5925 | |
| 5926 | // Update the uses. |
| 5927 | for (SDNode::use_iterator UI = VLD->use_begin(), UE = VLD->use_end(); |
| 5928 | UI != UE; ++UI) { |
| 5929 | unsigned ResNo = UI.getUse().getResNo(); |
| 5930 | // Ignore uses of the chain result. |
| 5931 | if (ResNo == NumVecs) |
| 5932 | continue; |
| 5933 | SDNode *User = *UI; |
| 5934 | DCI.CombineTo(User, SDValue(VLDDup.getNode(), ResNo)); |
| 5935 | } |
| 5936 | |
| 5937 | // Now the vldN-lane intrinsic is dead except for its chain result. |
| 5938 | // Update uses of the chain. |
| 5939 | std::vector<SDValue> VLDDupResults; |
| 5940 | for (unsigned n = 0; n < NumVecs; ++n) |
| 5941 | VLDDupResults.push_back(SDValue(VLDDup.getNode(), n)); |
| 5942 | VLDDupResults.push_back(SDValue(VLDDup.getNode(), NumVecs)); |
| 5943 | DCI.CombineTo(VLD, VLDDupResults); |
| 5944 | |
| 5945 | return true; |
| 5946 | } |
| 5947 | |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 5948 | /// PerformVDUPLANECombine - Target-specific dag combine xforms for |
| 5949 | /// ARMISD::VDUPLANE. |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 5950 | static SDValue PerformVDUPLANECombine(SDNode *N, |
| 5951 | TargetLowering::DAGCombinerInfo &DCI) { |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 5952 | SDValue Op = N->getOperand(0); |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 5953 | |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 5954 | // If the source is a vldN-lane (N > 1) intrinsic, and all the other uses |
| 5955 | // of that intrinsic are also VDUPLANEs, combine them to a vldN-dup operation. |
| 5956 | if (CombineVLDDUP(N, DCI)) |
| 5957 | return SDValue(N, 0); |
| 5958 | |
| 5959 | // If the source is already a VMOVIMM or VMVNIMM splat, the VDUPLANE is |
| 5960 | // redundant. Ignore bit_converts for now; element sizes are checked below. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5961 | while (Op.getOpcode() == ISD::BITCAST) |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 5962 | Op = Op.getOperand(0); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 5963 | if (Op.getOpcode() != ARMISD::VMOVIMM && Op.getOpcode() != ARMISD::VMVNIMM) |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 5964 | return SDValue(); |
| 5965 | |
| 5966 | // Make sure the VMOV element size is not bigger than the VDUPLANE elements. |
| 5967 | unsigned EltSize = Op.getValueType().getVectorElementType().getSizeInBits(); |
| 5968 | // The canonical VMOV for a zero vector uses a 32-bit element size. |
| 5969 | unsigned Imm = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
| 5970 | unsigned EltBits; |
| 5971 | if (ARM_AM::decodeNEONModImm(Imm, EltBits) == 0) |
| 5972 | EltSize = 8; |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 5973 | EVT VT = N->getValueType(0); |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 5974 | if (EltSize > VT.getVectorElementType().getSizeInBits()) |
| 5975 | return SDValue(); |
| 5976 | |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 5977 | return DCI.DAG.getNode(ISD::BITCAST, N->getDebugLoc(), VT, Op); |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 5978 | } |
| 5979 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5980 | /// getVShiftImm - Check if this is a valid build_vector for the immediate |
| 5981 | /// operand of a vector shift operation, where all the elements of the |
| 5982 | /// build_vector must have the same constant integer value. |
| 5983 | static bool getVShiftImm(SDValue Op, unsigned ElementBits, int64_t &Cnt) { |
| 5984 | // Ignore bit_converts. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5985 | while (Op.getOpcode() == ISD::BITCAST) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5986 | Op = Op.getOperand(0); |
| 5987 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(Op.getNode()); |
| 5988 | APInt SplatBits, SplatUndef; |
| 5989 | unsigned SplatBitSize; |
| 5990 | bool HasAnyUndefs; |
| 5991 | if (! BVN || ! BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, |
| 5992 | HasAnyUndefs, ElementBits) || |
| 5993 | SplatBitSize > ElementBits) |
| 5994 | return false; |
| 5995 | Cnt = SplatBits.getSExtValue(); |
| 5996 | return true; |
| 5997 | } |
| 5998 | |
| 5999 | /// isVShiftLImm - Check if this is a valid build_vector for the immediate |
| 6000 | /// operand of a vector shift left operation. That value must be in the range: |
| 6001 | /// 0 <= Value < ElementBits for a left shift; or |
| 6002 | /// 0 <= Value <= ElementBits for a long left shift. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6003 | static bool isVShiftLImm(SDValue Op, EVT VT, bool isLong, int64_t &Cnt) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6004 | assert(VT.isVector() && "vector shift count is not a vector type"); |
| 6005 | unsigned ElementBits = VT.getVectorElementType().getSizeInBits(); |
| 6006 | if (! getVShiftImm(Op, ElementBits, Cnt)) |
| 6007 | return false; |
| 6008 | return (Cnt >= 0 && (isLong ? Cnt-1 : Cnt) < ElementBits); |
| 6009 | } |
| 6010 | |
| 6011 | /// isVShiftRImm - Check if this is a valid build_vector for the immediate |
| 6012 | /// operand of a vector shift right operation. For a shift opcode, the value |
| 6013 | /// is positive, but for an intrinsic the value count must be negative. The |
| 6014 | /// absolute value must be in the range: |
| 6015 | /// 1 <= |Value| <= ElementBits for a right shift; or |
| 6016 | /// 1 <= |Value| <= ElementBits/2 for a narrow right shift. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6017 | static bool isVShiftRImm(SDValue Op, EVT VT, bool isNarrow, bool isIntrinsic, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6018 | int64_t &Cnt) { |
| 6019 | assert(VT.isVector() && "vector shift count is not a vector type"); |
| 6020 | unsigned ElementBits = VT.getVectorElementType().getSizeInBits(); |
| 6021 | if (! getVShiftImm(Op, ElementBits, Cnt)) |
| 6022 | return false; |
| 6023 | if (isIntrinsic) |
| 6024 | Cnt = -Cnt; |
| 6025 | return (Cnt >= 1 && Cnt <= (isNarrow ? ElementBits/2 : ElementBits)); |
| 6026 | } |
| 6027 | |
| 6028 | /// PerformIntrinsicCombine - ARM-specific DAG combining for intrinsics. |
| 6029 | static SDValue PerformIntrinsicCombine(SDNode *N, SelectionDAG &DAG) { |
| 6030 | unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue(); |
| 6031 | switch (IntNo) { |
| 6032 | default: |
| 6033 | // Don't do anything for most intrinsics. |
| 6034 | break; |
| 6035 | |
| 6036 | // Vector shifts: check for immediate versions and lower them. |
| 6037 | // Note: This is done during DAG combining instead of DAG legalizing because |
| 6038 | // the build_vectors for 64-bit vector element shift counts are generally |
| 6039 | // not legal, and it is hard to see their values after they get legalized to |
| 6040 | // loads from a constant pool. |
| 6041 | case Intrinsic::arm_neon_vshifts: |
| 6042 | case Intrinsic::arm_neon_vshiftu: |
| 6043 | case Intrinsic::arm_neon_vshiftls: |
| 6044 | case Intrinsic::arm_neon_vshiftlu: |
| 6045 | case Intrinsic::arm_neon_vshiftn: |
| 6046 | case Intrinsic::arm_neon_vrshifts: |
| 6047 | case Intrinsic::arm_neon_vrshiftu: |
| 6048 | case Intrinsic::arm_neon_vrshiftn: |
| 6049 | case Intrinsic::arm_neon_vqshifts: |
| 6050 | case Intrinsic::arm_neon_vqshiftu: |
| 6051 | case Intrinsic::arm_neon_vqshiftsu: |
| 6052 | case Intrinsic::arm_neon_vqshiftns: |
| 6053 | case Intrinsic::arm_neon_vqshiftnu: |
| 6054 | case Intrinsic::arm_neon_vqshiftnsu: |
| 6055 | case Intrinsic::arm_neon_vqrshiftns: |
| 6056 | case Intrinsic::arm_neon_vqrshiftnu: |
| 6057 | case Intrinsic::arm_neon_vqrshiftnsu: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6058 | EVT VT = N->getOperand(1).getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6059 | int64_t Cnt; |
| 6060 | unsigned VShiftOpc = 0; |
| 6061 | |
| 6062 | switch (IntNo) { |
| 6063 | case Intrinsic::arm_neon_vshifts: |
| 6064 | case Intrinsic::arm_neon_vshiftu: |
| 6065 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) { |
| 6066 | VShiftOpc = ARMISD::VSHL; |
| 6067 | break; |
| 6068 | } |
| 6069 | if (isVShiftRImm(N->getOperand(2), VT, false, true, Cnt)) { |
| 6070 | VShiftOpc = (IntNo == Intrinsic::arm_neon_vshifts ? |
| 6071 | ARMISD::VSHRs : ARMISD::VSHRu); |
| 6072 | break; |
| 6073 | } |
| 6074 | return SDValue(); |
| 6075 | |
| 6076 | case Intrinsic::arm_neon_vshiftls: |
| 6077 | case Intrinsic::arm_neon_vshiftlu: |
| 6078 | if (isVShiftLImm(N->getOperand(2), VT, true, Cnt)) |
| 6079 | break; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 6080 | llvm_unreachable("invalid shift count for vshll intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6081 | |
| 6082 | case Intrinsic::arm_neon_vrshifts: |
| 6083 | case Intrinsic::arm_neon_vrshiftu: |
| 6084 | if (isVShiftRImm(N->getOperand(2), VT, false, true, Cnt)) |
| 6085 | break; |
| 6086 | return SDValue(); |
| 6087 | |
| 6088 | case Intrinsic::arm_neon_vqshifts: |
| 6089 | case Intrinsic::arm_neon_vqshiftu: |
| 6090 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) |
| 6091 | break; |
| 6092 | return SDValue(); |
| 6093 | |
| 6094 | case Intrinsic::arm_neon_vqshiftsu: |
| 6095 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) |
| 6096 | break; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 6097 | llvm_unreachable("invalid shift count for vqshlu intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6098 | |
| 6099 | case Intrinsic::arm_neon_vshiftn: |
| 6100 | case Intrinsic::arm_neon_vrshiftn: |
| 6101 | case Intrinsic::arm_neon_vqshiftns: |
| 6102 | case Intrinsic::arm_neon_vqshiftnu: |
| 6103 | case Intrinsic::arm_neon_vqshiftnsu: |
| 6104 | case Intrinsic::arm_neon_vqrshiftns: |
| 6105 | case Intrinsic::arm_neon_vqrshiftnu: |
| 6106 | case Intrinsic::arm_neon_vqrshiftnsu: |
| 6107 | // Narrowing shifts require an immediate right shift. |
| 6108 | if (isVShiftRImm(N->getOperand(2), VT, true, true, Cnt)) |
| 6109 | break; |
Jim Grosbach | 18f30e6 | 2010-06-02 21:53:11 +0000 | [diff] [blame] | 6110 | llvm_unreachable("invalid shift count for narrowing vector shift " |
| 6111 | "intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6112 | |
| 6113 | default: |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 6114 | llvm_unreachable("unhandled vector shift"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6115 | } |
| 6116 | |
| 6117 | switch (IntNo) { |
| 6118 | case Intrinsic::arm_neon_vshifts: |
| 6119 | case Intrinsic::arm_neon_vshiftu: |
| 6120 | // Opcode already set above. |
| 6121 | break; |
| 6122 | case Intrinsic::arm_neon_vshiftls: |
| 6123 | case Intrinsic::arm_neon_vshiftlu: |
| 6124 | if (Cnt == VT.getVectorElementType().getSizeInBits()) |
| 6125 | VShiftOpc = ARMISD::VSHLLi; |
| 6126 | else |
| 6127 | VShiftOpc = (IntNo == Intrinsic::arm_neon_vshiftls ? |
| 6128 | ARMISD::VSHLLs : ARMISD::VSHLLu); |
| 6129 | break; |
| 6130 | case Intrinsic::arm_neon_vshiftn: |
| 6131 | VShiftOpc = ARMISD::VSHRN; break; |
| 6132 | case Intrinsic::arm_neon_vrshifts: |
| 6133 | VShiftOpc = ARMISD::VRSHRs; break; |
| 6134 | case Intrinsic::arm_neon_vrshiftu: |
| 6135 | VShiftOpc = ARMISD::VRSHRu; break; |
| 6136 | case Intrinsic::arm_neon_vrshiftn: |
| 6137 | VShiftOpc = ARMISD::VRSHRN; break; |
| 6138 | case Intrinsic::arm_neon_vqshifts: |
| 6139 | VShiftOpc = ARMISD::VQSHLs; break; |
| 6140 | case Intrinsic::arm_neon_vqshiftu: |
| 6141 | VShiftOpc = ARMISD::VQSHLu; break; |
| 6142 | case Intrinsic::arm_neon_vqshiftsu: |
| 6143 | VShiftOpc = ARMISD::VQSHLsu; break; |
| 6144 | case Intrinsic::arm_neon_vqshiftns: |
| 6145 | VShiftOpc = ARMISD::VQSHRNs; break; |
| 6146 | case Intrinsic::arm_neon_vqshiftnu: |
| 6147 | VShiftOpc = ARMISD::VQSHRNu; break; |
| 6148 | case Intrinsic::arm_neon_vqshiftnsu: |
| 6149 | VShiftOpc = ARMISD::VQSHRNsu; break; |
| 6150 | case Intrinsic::arm_neon_vqrshiftns: |
| 6151 | VShiftOpc = ARMISD::VQRSHRNs; break; |
| 6152 | case Intrinsic::arm_neon_vqrshiftnu: |
| 6153 | VShiftOpc = ARMISD::VQRSHRNu; break; |
| 6154 | case Intrinsic::arm_neon_vqrshiftnsu: |
| 6155 | VShiftOpc = ARMISD::VQRSHRNsu; break; |
| 6156 | } |
| 6157 | |
| 6158 | return DAG.getNode(VShiftOpc, N->getDebugLoc(), N->getValueType(0), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6159 | N->getOperand(1), DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6160 | } |
| 6161 | |
| 6162 | case Intrinsic::arm_neon_vshiftins: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6163 | EVT VT = N->getOperand(1).getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6164 | int64_t Cnt; |
| 6165 | unsigned VShiftOpc = 0; |
| 6166 | |
| 6167 | if (isVShiftLImm(N->getOperand(3), VT, false, Cnt)) |
| 6168 | VShiftOpc = ARMISD::VSLI; |
| 6169 | else if (isVShiftRImm(N->getOperand(3), VT, false, true, Cnt)) |
| 6170 | VShiftOpc = ARMISD::VSRI; |
| 6171 | else { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 6172 | llvm_unreachable("invalid shift count for vsli/vsri intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6173 | } |
| 6174 | |
| 6175 | return DAG.getNode(VShiftOpc, N->getDebugLoc(), N->getValueType(0), |
| 6176 | N->getOperand(1), N->getOperand(2), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6177 | DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6178 | } |
| 6179 | |
| 6180 | case Intrinsic::arm_neon_vqrshifts: |
| 6181 | case Intrinsic::arm_neon_vqrshiftu: |
| 6182 | // No immediate versions of these to check for. |
| 6183 | break; |
| 6184 | } |
| 6185 | |
| 6186 | return SDValue(); |
| 6187 | } |
| 6188 | |
| 6189 | /// PerformShiftCombine - Checks for immediate versions of vector shifts and |
| 6190 | /// lowers them. As with the vector shift intrinsics, this is done during DAG |
| 6191 | /// combining instead of DAG legalizing because the build_vectors for 64-bit |
| 6192 | /// vector element shift counts are generally not legal, and it is hard to see |
| 6193 | /// their values after they get legalized to loads from a constant pool. |
| 6194 | static SDValue PerformShiftCombine(SDNode *N, SelectionDAG &DAG, |
| 6195 | const ARMSubtarget *ST) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6196 | EVT VT = N->getValueType(0); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6197 | |
| 6198 | // Nothing to be done for scalar shifts. |
Tanya Lattner | 9684a7c | 2010-11-18 22:06:46 +0000 | [diff] [blame] | 6199 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 6200 | if (!VT.isVector() || !TLI.isTypeLegal(VT)) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6201 | return SDValue(); |
| 6202 | |
| 6203 | assert(ST->hasNEON() && "unexpected vector shift"); |
| 6204 | int64_t Cnt; |
| 6205 | |
| 6206 | switch (N->getOpcode()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 6207 | default: llvm_unreachable("unexpected shift opcode"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6208 | |
| 6209 | case ISD::SHL: |
| 6210 | if (isVShiftLImm(N->getOperand(1), VT, false, Cnt)) |
| 6211 | return DAG.getNode(ARMISD::VSHL, N->getDebugLoc(), VT, N->getOperand(0), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6212 | DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6213 | break; |
| 6214 | |
| 6215 | case ISD::SRA: |
| 6216 | case ISD::SRL: |
| 6217 | if (isVShiftRImm(N->getOperand(1), VT, false, false, Cnt)) { |
| 6218 | unsigned VShiftOpc = (N->getOpcode() == ISD::SRA ? |
| 6219 | ARMISD::VSHRs : ARMISD::VSHRu); |
| 6220 | return DAG.getNode(VShiftOpc, N->getDebugLoc(), VT, N->getOperand(0), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6221 | DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6222 | } |
| 6223 | } |
| 6224 | return SDValue(); |
| 6225 | } |
| 6226 | |
| 6227 | /// PerformExtendCombine - Target-specific DAG combining for ISD::SIGN_EXTEND, |
| 6228 | /// ISD::ZERO_EXTEND, and ISD::ANY_EXTEND. |
| 6229 | static SDValue PerformExtendCombine(SDNode *N, SelectionDAG &DAG, |
| 6230 | const ARMSubtarget *ST) { |
| 6231 | SDValue N0 = N->getOperand(0); |
| 6232 | |
| 6233 | // Check for sign- and zero-extensions of vector extract operations of 8- |
| 6234 | // and 16-bit vector elements. NEON supports these directly. They are |
| 6235 | // handled during DAG combining because type legalization will promote them |
| 6236 | // to 32-bit types and it is messy to recognize the operations after that. |
| 6237 | if (ST->hasNEON() && N0.getOpcode() == ISD::EXTRACT_VECTOR_ELT) { |
| 6238 | SDValue Vec = N0.getOperand(0); |
| 6239 | SDValue Lane = N0.getOperand(1); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6240 | EVT VT = N->getValueType(0); |
| 6241 | EVT EltVT = N0.getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6242 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 6243 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6244 | if (VT == MVT::i32 && |
| 6245 | (EltVT == MVT::i8 || EltVT == MVT::i16) && |
Bob Wilson | 3468c2e | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 6246 | TLI.isTypeLegal(Vec.getValueType()) && |
| 6247 | isa<ConstantSDNode>(Lane)) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6248 | |
| 6249 | unsigned Opc = 0; |
| 6250 | switch (N->getOpcode()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 6251 | default: llvm_unreachable("unexpected opcode"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6252 | case ISD::SIGN_EXTEND: |
| 6253 | Opc = ARMISD::VGETLANEs; |
| 6254 | break; |
| 6255 | case ISD::ZERO_EXTEND: |
| 6256 | case ISD::ANY_EXTEND: |
| 6257 | Opc = ARMISD::VGETLANEu; |
| 6258 | break; |
| 6259 | } |
| 6260 | return DAG.getNode(Opc, N->getDebugLoc(), VT, Vec, Lane); |
| 6261 | } |
| 6262 | } |
| 6263 | |
| 6264 | return SDValue(); |
| 6265 | } |
| 6266 | |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 6267 | /// PerformSELECT_CCCombine - Target-specific DAG combining for ISD::SELECT_CC |
| 6268 | /// to match f32 max/min patterns to use NEON vmax/vmin instructions. |
| 6269 | static SDValue PerformSELECT_CCCombine(SDNode *N, SelectionDAG &DAG, |
| 6270 | const ARMSubtarget *ST) { |
| 6271 | // 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] | 6272 | // selects like "x < y ? x : y". Unless the NoNaNsFPMath option is set, |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 6273 | // be careful about NaNs: NEON's vmax/vmin return NaN if either operand is |
| 6274 | // a NaN; only do the transformation when it matches that behavior. |
| 6275 | |
| 6276 | // For now only do this when using NEON for FP operations; if using VFP, it |
| 6277 | // is not obvious that the benefit outweighs the cost of switching to the |
| 6278 | // NEON pipeline. |
| 6279 | if (!ST->hasNEON() || !ST->useNEONForSinglePrecisionFP() || |
| 6280 | N->getValueType(0) != MVT::f32) |
| 6281 | return SDValue(); |
| 6282 | |
| 6283 | SDValue CondLHS = N->getOperand(0); |
| 6284 | SDValue CondRHS = N->getOperand(1); |
| 6285 | SDValue LHS = N->getOperand(2); |
| 6286 | SDValue RHS = N->getOperand(3); |
| 6287 | ISD::CondCode CC = cast<CondCodeSDNode>(N->getOperand(4))->get(); |
| 6288 | |
| 6289 | unsigned Opcode = 0; |
| 6290 | bool IsReversed; |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 6291 | if (DAG.isEqualTo(LHS, CondLHS) && DAG.isEqualTo(RHS, CondRHS)) { |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 6292 | IsReversed = false; // x CC y ? x : y |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 6293 | } else if (DAG.isEqualTo(LHS, CondRHS) && DAG.isEqualTo(RHS, CondLHS)) { |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 6294 | IsReversed = true ; // x CC y ? y : x |
| 6295 | } else { |
| 6296 | return SDValue(); |
| 6297 | } |
| 6298 | |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 6299 | bool IsUnordered; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 6300 | switch (CC) { |
| 6301 | default: break; |
| 6302 | case ISD::SETOLT: |
| 6303 | case ISD::SETOLE: |
| 6304 | case ISD::SETLT: |
| 6305 | case ISD::SETLE: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 6306 | case ISD::SETULT: |
| 6307 | case ISD::SETULE: |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 6308 | // If LHS is NaN, an ordered comparison will be false and the result will |
| 6309 | // be the RHS, but vmin(NaN, RHS) = NaN. Avoid this by checking that LHS |
| 6310 | // != NaN. Likewise, for unordered comparisons, check for RHS != NaN. |
| 6311 | IsUnordered = (CC == ISD::SETULT || CC == ISD::SETULE); |
| 6312 | if (!DAG.isKnownNeverNaN(IsUnordered ? RHS : LHS)) |
| 6313 | break; |
| 6314 | // For less-than-or-equal comparisons, "+0 <= -0" will be true but vmin |
| 6315 | // will return -0, so vmin can only be used for unsafe math or if one of |
| 6316 | // the operands is known to be nonzero. |
| 6317 | if ((CC == ISD::SETLE || CC == ISD::SETOLE || CC == ISD::SETULE) && |
| 6318 | !UnsafeFPMath && |
| 6319 | !(DAG.isKnownNeverZero(LHS) || DAG.isKnownNeverZero(RHS))) |
| 6320 | break; |
| 6321 | Opcode = IsReversed ? ARMISD::FMAX : ARMISD::FMIN; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 6322 | break; |
| 6323 | |
| 6324 | case ISD::SETOGT: |
| 6325 | case ISD::SETOGE: |
| 6326 | case ISD::SETGT: |
| 6327 | case ISD::SETGE: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 6328 | case ISD::SETUGT: |
| 6329 | case ISD::SETUGE: |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 6330 | // If LHS is NaN, an ordered comparison will be false and the result will |
| 6331 | // be the RHS, but vmax(NaN, RHS) = NaN. Avoid this by checking that LHS |
| 6332 | // != NaN. Likewise, for unordered comparisons, check for RHS != NaN. |
| 6333 | IsUnordered = (CC == ISD::SETUGT || CC == ISD::SETUGE); |
| 6334 | if (!DAG.isKnownNeverNaN(IsUnordered ? RHS : LHS)) |
| 6335 | break; |
| 6336 | // For greater-than-or-equal comparisons, "-0 >= +0" will be true but vmax |
| 6337 | // will return +0, so vmax can only be used for unsafe math or if one of |
| 6338 | // the operands is known to be nonzero. |
| 6339 | if ((CC == ISD::SETGE || CC == ISD::SETOGE || CC == ISD::SETUGE) && |
| 6340 | !UnsafeFPMath && |
| 6341 | !(DAG.isKnownNeverZero(LHS) || DAG.isKnownNeverZero(RHS))) |
| 6342 | break; |
| 6343 | Opcode = IsReversed ? ARMISD::FMIN : ARMISD::FMAX; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 6344 | break; |
| 6345 | } |
| 6346 | |
| 6347 | if (!Opcode) |
| 6348 | return SDValue(); |
| 6349 | return DAG.getNode(Opcode, N->getDebugLoc(), N->getValueType(0), LHS, RHS); |
| 6350 | } |
| 6351 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6352 | SDValue ARMTargetLowering::PerformDAGCombine(SDNode *N, |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 6353 | DAGCombinerInfo &DCI) const { |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 6354 | switch (N->getOpcode()) { |
| 6355 | default: break; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 6356 | case ISD::ADD: return PerformADDCombine(N, DCI); |
| 6357 | case ISD::SUB: return PerformSUBCombine(N, DCI); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 6358 | case ISD::MUL: return PerformMULCombine(N, DCI, Subtarget); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 6359 | case ISD::OR: return PerformORCombine(N, DCI, Subtarget); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 6360 | case ISD::AND: return PerformANDCombine(N, DCI); |
Evan Cheng | 0c1aec1 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 6361 | case ARMISD::BFI: return PerformBFICombine(N, DCI); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 6362 | case ARMISD::VMOVRRD: return PerformVMOVRRDCombine(N, DCI); |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 6363 | case ARMISD::VMOVDRR: return PerformVMOVDRRCombine(N, DCI.DAG); |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 6364 | case ISD::STORE: return PerformSTORECombine(N, DCI); |
| 6365 | case ISD::BUILD_VECTOR: return PerformBUILD_VECTORCombine(N, DCI); |
| 6366 | case ISD::INSERT_VECTOR_ELT: return PerformInsertEltCombine(N, DCI); |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 6367 | case ISD::VECTOR_SHUFFLE: return PerformVECTOR_SHUFFLECombine(N, DCI.DAG); |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 6368 | case ARMISD::VDUPLANE: return PerformVDUPLANECombine(N, DCI); |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 6369 | case ISD::INTRINSIC_WO_CHAIN: return PerformIntrinsicCombine(N, DCI.DAG); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6370 | case ISD::SHL: |
| 6371 | case ISD::SRA: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 6372 | case ISD::SRL: return PerformShiftCombine(N, DCI.DAG, Subtarget); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6373 | case ISD::SIGN_EXTEND: |
| 6374 | case ISD::ZERO_EXTEND: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 6375 | case ISD::ANY_EXTEND: return PerformExtendCombine(N, DCI.DAG, Subtarget); |
| 6376 | case ISD::SELECT_CC: return PerformSELECT_CCCombine(N, DCI.DAG, Subtarget); |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 6377 | case ARMISD::VLD2DUP: |
| 6378 | case ARMISD::VLD3DUP: |
| 6379 | case ARMISD::VLD4DUP: |
| 6380 | return CombineBaseUpdate(N, DCI); |
| 6381 | case ISD::INTRINSIC_VOID: |
| 6382 | case ISD::INTRINSIC_W_CHAIN: |
| 6383 | switch (cast<ConstantSDNode>(N->getOperand(1))->getZExtValue()) { |
| 6384 | case Intrinsic::arm_neon_vld1: |
| 6385 | case Intrinsic::arm_neon_vld2: |
| 6386 | case Intrinsic::arm_neon_vld3: |
| 6387 | case Intrinsic::arm_neon_vld4: |
| 6388 | case Intrinsic::arm_neon_vld2lane: |
| 6389 | case Intrinsic::arm_neon_vld3lane: |
| 6390 | case Intrinsic::arm_neon_vld4lane: |
| 6391 | case Intrinsic::arm_neon_vst1: |
| 6392 | case Intrinsic::arm_neon_vst2: |
| 6393 | case Intrinsic::arm_neon_vst3: |
| 6394 | case Intrinsic::arm_neon_vst4: |
| 6395 | case Intrinsic::arm_neon_vst2lane: |
| 6396 | case Intrinsic::arm_neon_vst3lane: |
| 6397 | case Intrinsic::arm_neon_vst4lane: |
| 6398 | return CombineBaseUpdate(N, DCI); |
| 6399 | default: break; |
| 6400 | } |
| 6401 | break; |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 6402 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6403 | return SDValue(); |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 6404 | } |
| 6405 | |
Evan Cheng | 31959b1 | 2011-02-02 01:06:55 +0000 | [diff] [blame] | 6406 | bool ARMTargetLowering::isDesirableToTransformToIntegerOp(unsigned Opc, |
| 6407 | EVT VT) const { |
| 6408 | return (VT == MVT::f32) && (Opc == ISD::LOAD || Opc == ISD::STORE); |
| 6409 | } |
| 6410 | |
Bill Wendling | af56634 | 2009-08-15 21:21:19 +0000 | [diff] [blame] | 6411 | bool ARMTargetLowering::allowsUnalignedMemoryAccesses(EVT VT) const { |
Bob Wilson | 02aba73 | 2010-09-28 04:09:35 +0000 | [diff] [blame] | 6412 | if (!Subtarget->allowsUnalignedMem()) |
Bob Wilson | 86fe66d | 2010-06-25 04:12:31 +0000 | [diff] [blame] | 6413 | return false; |
Bill Wendling | af56634 | 2009-08-15 21:21:19 +0000 | [diff] [blame] | 6414 | |
| 6415 | switch (VT.getSimpleVT().SimpleTy) { |
| 6416 | default: |
| 6417 | return false; |
| 6418 | case MVT::i8: |
| 6419 | case MVT::i16: |
| 6420 | case MVT::i32: |
| 6421 | return true; |
| 6422 | // FIXME: VLD1 etc with standard alignment is legal. |
| 6423 | } |
| 6424 | } |
| 6425 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 6426 | static bool isLegalT1AddressImmediate(int64_t V, EVT VT) { |
| 6427 | if (V < 0) |
| 6428 | return false; |
| 6429 | |
| 6430 | unsigned Scale = 1; |
| 6431 | switch (VT.getSimpleVT().SimpleTy) { |
| 6432 | default: return false; |
| 6433 | case MVT::i1: |
| 6434 | case MVT::i8: |
| 6435 | // Scale == 1; |
| 6436 | break; |
| 6437 | case MVT::i16: |
| 6438 | // Scale == 2; |
| 6439 | Scale = 2; |
| 6440 | break; |
| 6441 | case MVT::i32: |
| 6442 | // Scale == 4; |
| 6443 | Scale = 4; |
| 6444 | break; |
| 6445 | } |
| 6446 | |
| 6447 | if ((V & (Scale - 1)) != 0) |
| 6448 | return false; |
| 6449 | V /= Scale; |
| 6450 | return V == (V & ((1LL << 5) - 1)); |
| 6451 | } |
| 6452 | |
| 6453 | static bool isLegalT2AddressImmediate(int64_t V, EVT VT, |
| 6454 | const ARMSubtarget *Subtarget) { |
| 6455 | bool isNeg = false; |
| 6456 | if (V < 0) { |
| 6457 | isNeg = true; |
| 6458 | V = - V; |
| 6459 | } |
| 6460 | |
| 6461 | switch (VT.getSimpleVT().SimpleTy) { |
| 6462 | default: return false; |
| 6463 | case MVT::i1: |
| 6464 | case MVT::i8: |
| 6465 | case MVT::i16: |
| 6466 | case MVT::i32: |
| 6467 | // + imm12 or - imm8 |
| 6468 | if (isNeg) |
| 6469 | return V == (V & ((1LL << 8) - 1)); |
| 6470 | return V == (V & ((1LL << 12) - 1)); |
| 6471 | case MVT::f32: |
| 6472 | case MVT::f64: |
| 6473 | // Same as ARM mode. FIXME: NEON? |
| 6474 | if (!Subtarget->hasVFP2()) |
| 6475 | return false; |
| 6476 | if ((V & 3) != 0) |
| 6477 | return false; |
| 6478 | V >>= 2; |
| 6479 | return V == (V & ((1LL << 8) - 1)); |
| 6480 | } |
| 6481 | } |
| 6482 | |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 6483 | /// isLegalAddressImmediate - Return true if the integer value can be used |
| 6484 | /// as the offset of the target addressing mode for load / store of the |
| 6485 | /// given type. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6486 | static bool isLegalAddressImmediate(int64_t V, EVT VT, |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 6487 | const ARMSubtarget *Subtarget) { |
Evan Cheng | 961f879 | 2007-03-13 20:37:59 +0000 | [diff] [blame] | 6488 | if (V == 0) |
| 6489 | return true; |
| 6490 | |
Evan Cheng | 6501153 | 2009-03-09 19:15:00 +0000 | [diff] [blame] | 6491 | if (!VT.isSimple()) |
| 6492 | return false; |
| 6493 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 6494 | if (Subtarget->isThumb1Only()) |
| 6495 | return isLegalT1AddressImmediate(V, VT); |
| 6496 | else if (Subtarget->isThumb2()) |
| 6497 | return isLegalT2AddressImmediate(V, VT, Subtarget); |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 6498 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 6499 | // ARM mode. |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 6500 | if (V < 0) |
| 6501 | V = - V; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6502 | switch (VT.getSimpleVT().SimpleTy) { |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 6503 | default: return false; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6504 | case MVT::i1: |
| 6505 | case MVT::i8: |
| 6506 | case MVT::i32: |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 6507 | // +- imm12 |
Anton Korobeynikov | 7c1c261 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 6508 | return V == (V & ((1LL << 12) - 1)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6509 | case MVT::i16: |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 6510 | // +- imm8 |
Anton Korobeynikov | 7c1c261 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 6511 | return V == (V & ((1LL << 8) - 1)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6512 | case MVT::f32: |
| 6513 | case MVT::f64: |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 6514 | if (!Subtarget->hasVFP2()) // FIXME: NEON? |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 6515 | return false; |
Evan Cheng | 0b0a9a9 | 2007-05-03 02:00:18 +0000 | [diff] [blame] | 6516 | if ((V & 3) != 0) |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 6517 | return false; |
| 6518 | V >>= 2; |
Anton Korobeynikov | 7c1c261 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 6519 | return V == (V & ((1LL << 8) - 1)); |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 6520 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6521 | } |
| 6522 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 6523 | bool ARMTargetLowering::isLegalT2ScaledAddressingMode(const AddrMode &AM, |
| 6524 | EVT VT) const { |
| 6525 | int Scale = AM.Scale; |
| 6526 | if (Scale < 0) |
| 6527 | return false; |
| 6528 | |
| 6529 | switch (VT.getSimpleVT().SimpleTy) { |
| 6530 | default: return false; |
| 6531 | case MVT::i1: |
| 6532 | case MVT::i8: |
| 6533 | case MVT::i16: |
| 6534 | case MVT::i32: |
| 6535 | if (Scale == 1) |
| 6536 | return true; |
| 6537 | // r + r << imm |
| 6538 | Scale = Scale & ~1; |
| 6539 | return Scale == 2 || Scale == 4 || Scale == 8; |
| 6540 | case MVT::i64: |
| 6541 | // r + r |
| 6542 | if (((unsigned)AM.HasBaseReg + Scale) <= 2) |
| 6543 | return true; |
| 6544 | return false; |
| 6545 | case MVT::isVoid: |
| 6546 | // Note, we allow "void" uses (basically, uses that aren't loads or |
| 6547 | // stores), because arm allows folding a scale into many arithmetic |
| 6548 | // operations. This should be made more precise and revisited later. |
| 6549 | |
| 6550 | // Allow r << imm, but the imm has to be a multiple of two. |
| 6551 | if (Scale & 1) return false; |
| 6552 | return isPowerOf2_32(Scale); |
| 6553 | } |
| 6554 | } |
| 6555 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 6556 | /// isLegalAddressingMode - Return true if the addressing mode represented |
| 6557 | /// 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] | 6558 | bool ARMTargetLowering::isLegalAddressingMode(const AddrMode &AM, |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 6559 | const Type *Ty) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6560 | EVT VT = getValueType(Ty, true); |
Bob Wilson | 2c7dab1 | 2009-04-08 17:55:28 +0000 | [diff] [blame] | 6561 | if (!isLegalAddressImmediate(AM.BaseOffs, VT, Subtarget)) |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 6562 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 6563 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 6564 | // Can never fold addr of global into load/store. |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 6565 | if (AM.BaseGV) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 6566 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 6567 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 6568 | switch (AM.Scale) { |
| 6569 | case 0: // no scale reg, must be "r+i" or "r", or "i". |
| 6570 | break; |
| 6571 | case 1: |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 6572 | if (Subtarget->isThumb1Only()) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 6573 | return false; |
Chris Lattner | 5a3d40d | 2007-04-13 06:50:55 +0000 | [diff] [blame] | 6574 | // FALL THROUGH. |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 6575 | default: |
Chris Lattner | 5a3d40d | 2007-04-13 06:50:55 +0000 | [diff] [blame] | 6576 | // ARM doesn't support any R+R*scale+imm addr modes. |
| 6577 | if (AM.BaseOffs) |
| 6578 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 6579 | |
Bob Wilson | 2c7dab1 | 2009-04-08 17:55:28 +0000 | [diff] [blame] | 6580 | if (!VT.isSimple()) |
| 6581 | return false; |
| 6582 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 6583 | if (Subtarget->isThumb2()) |
| 6584 | return isLegalT2ScaledAddressingMode(AM, VT); |
| 6585 | |
Chris Lattner | eb13d1b | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 6586 | int Scale = AM.Scale; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6587 | switch (VT.getSimpleVT().SimpleTy) { |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 6588 | default: return false; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6589 | case MVT::i1: |
| 6590 | case MVT::i8: |
| 6591 | case MVT::i32: |
Chris Lattner | eb13d1b | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 6592 | if (Scale < 0) Scale = -Scale; |
| 6593 | if (Scale == 1) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 6594 | return true; |
| 6595 | // r + r << imm |
Chris Lattner | e115294 | 2007-04-11 16:17:12 +0000 | [diff] [blame] | 6596 | return isPowerOf2_32(Scale & ~1); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6597 | case MVT::i16: |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 6598 | case MVT::i64: |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 6599 | // r + r |
Chris Lattner | eb13d1b | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 6600 | if (((unsigned)AM.HasBaseReg + Scale) <= 2) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 6601 | return true; |
Chris Lattner | e115294 | 2007-04-11 16:17:12 +0000 | [diff] [blame] | 6602 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 6603 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6604 | case MVT::isVoid: |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 6605 | // Note, we allow "void" uses (basically, uses that aren't loads or |
| 6606 | // stores), because arm allows folding a scale into many arithmetic |
| 6607 | // operations. This should be made more precise and revisited later. |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 6608 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 6609 | // 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] | 6610 | if (Scale & 1) return false; |
| 6611 | return isPowerOf2_32(Scale); |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 6612 | } |
| 6613 | break; |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 6614 | } |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 6615 | return true; |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 6616 | } |
| 6617 | |
Evan Cheng | 77e4751 | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 6618 | /// isLegalICmpImmediate - Return true if the specified immediate is legal |
| 6619 | /// icmp immediate, that is the target has icmp instructions which can compare |
| 6620 | /// a register against the immediate without having to materialize the |
| 6621 | /// immediate into a register. |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 6622 | bool ARMTargetLowering::isLegalICmpImmediate(int64_t Imm) const { |
Evan Cheng | 77e4751 | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 6623 | if (!Subtarget->isThumb()) |
| 6624 | return ARM_AM::getSOImmVal(Imm) != -1; |
| 6625 | if (Subtarget->isThumb2()) |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 6626 | return ARM_AM::getT2SOImmVal(Imm) != -1; |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 6627 | return Imm >= 0 && Imm <= 255; |
Evan Cheng | 77e4751 | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 6628 | } |
| 6629 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6630 | static bool getARMIndexedAddressParts(SDNode *Ptr, EVT VT, |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 6631 | bool isSEXTLoad, SDValue &Base, |
| 6632 | SDValue &Offset, bool &isInc, |
| 6633 | SelectionDAG &DAG) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6634 | if (Ptr->getOpcode() != ISD::ADD && Ptr->getOpcode() != ISD::SUB) |
| 6635 | return false; |
| 6636 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6637 | if (VT == MVT::i16 || ((VT == MVT::i8 || VT == MVT::i1) && isSEXTLoad)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6638 | // AddressingMode 3 |
| 6639 | Base = Ptr->getOperand(0); |
| 6640 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 6641 | int RHSC = (int)RHS->getZExtValue(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6642 | if (RHSC < 0 && RHSC > -256) { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 6643 | assert(Ptr->getOpcode() == ISD::ADD); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6644 | isInc = false; |
| 6645 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); |
| 6646 | return true; |
| 6647 | } |
| 6648 | } |
| 6649 | isInc = (Ptr->getOpcode() == ISD::ADD); |
| 6650 | Offset = Ptr->getOperand(1); |
| 6651 | return true; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6652 | } else if (VT == MVT::i32 || VT == MVT::i8 || VT == MVT::i1) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6653 | // AddressingMode 2 |
| 6654 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 6655 | int RHSC = (int)RHS->getZExtValue(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6656 | if (RHSC < 0 && RHSC > -0x1000) { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 6657 | assert(Ptr->getOpcode() == ISD::ADD); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6658 | isInc = false; |
| 6659 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); |
| 6660 | Base = Ptr->getOperand(0); |
| 6661 | return true; |
| 6662 | } |
| 6663 | } |
| 6664 | |
| 6665 | if (Ptr->getOpcode() == ISD::ADD) { |
| 6666 | isInc = true; |
| 6667 | ARM_AM::ShiftOpc ShOpcVal= ARM_AM::getShiftOpcForNode(Ptr->getOperand(0)); |
| 6668 | if (ShOpcVal != ARM_AM::no_shift) { |
| 6669 | Base = Ptr->getOperand(1); |
| 6670 | Offset = Ptr->getOperand(0); |
| 6671 | } else { |
| 6672 | Base = Ptr->getOperand(0); |
| 6673 | Offset = Ptr->getOperand(1); |
| 6674 | } |
| 6675 | return true; |
| 6676 | } |
| 6677 | |
| 6678 | isInc = (Ptr->getOpcode() == ISD::ADD); |
| 6679 | Base = Ptr->getOperand(0); |
| 6680 | Offset = Ptr->getOperand(1); |
| 6681 | return true; |
| 6682 | } |
| 6683 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 6684 | // FIXME: Use VLDM / VSTM to emulate indexed FP load / store. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6685 | return false; |
| 6686 | } |
| 6687 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6688 | static bool getT2IndexedAddressParts(SDNode *Ptr, EVT VT, |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 6689 | bool isSEXTLoad, SDValue &Base, |
| 6690 | SDValue &Offset, bool &isInc, |
| 6691 | SelectionDAG &DAG) { |
| 6692 | if (Ptr->getOpcode() != ISD::ADD && Ptr->getOpcode() != ISD::SUB) |
| 6693 | return false; |
| 6694 | |
| 6695 | Base = Ptr->getOperand(0); |
| 6696 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
| 6697 | int RHSC = (int)RHS->getZExtValue(); |
| 6698 | if (RHSC < 0 && RHSC > -0x100) { // 8 bits. |
| 6699 | assert(Ptr->getOpcode() == ISD::ADD); |
| 6700 | isInc = false; |
| 6701 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); |
| 6702 | return true; |
| 6703 | } else if (RHSC > 0 && RHSC < 0x100) { // 8 bit, no zero. |
| 6704 | isInc = Ptr->getOpcode() == ISD::ADD; |
| 6705 | Offset = DAG.getConstant(RHSC, RHS->getValueType(0)); |
| 6706 | return true; |
| 6707 | } |
| 6708 | } |
| 6709 | |
| 6710 | return false; |
| 6711 | } |
| 6712 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6713 | /// getPreIndexedAddressParts - returns true by value, base pointer and |
| 6714 | /// offset pointer and addressing mode by reference if the node's address |
| 6715 | /// can be legally represented as pre-indexed load / store address. |
| 6716 | bool |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6717 | ARMTargetLowering::getPreIndexedAddressParts(SDNode *N, SDValue &Base, |
| 6718 | SDValue &Offset, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6719 | ISD::MemIndexedMode &AM, |
Dan Gohman | 73e0914 | 2009-01-15 16:29:45 +0000 | [diff] [blame] | 6720 | SelectionDAG &DAG) const { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 6721 | if (Subtarget->isThumb1Only()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6722 | return false; |
| 6723 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6724 | EVT VT; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6725 | SDValue Ptr; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6726 | bool isSEXTLoad = false; |
| 6727 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) { |
| 6728 | Ptr = LD->getBasePtr(); |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 6729 | VT = LD->getMemoryVT(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6730 | isSEXTLoad = LD->getExtensionType() == ISD::SEXTLOAD; |
| 6731 | } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) { |
| 6732 | Ptr = ST->getBasePtr(); |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 6733 | VT = ST->getMemoryVT(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6734 | } else |
| 6735 | return false; |
| 6736 | |
| 6737 | bool isInc; |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 6738 | bool isLegal = false; |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 6739 | if (Subtarget->isThumb2()) |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 6740 | isLegal = getT2IndexedAddressParts(Ptr.getNode(), VT, isSEXTLoad, Base, |
| 6741 | Offset, isInc, DAG); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 6742 | else |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 6743 | isLegal = getARMIndexedAddressParts(Ptr.getNode(), VT, isSEXTLoad, Base, |
Evan Cheng | 0412957 | 2009-07-02 06:44:30 +0000 | [diff] [blame] | 6744 | Offset, isInc, DAG); |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 6745 | if (!isLegal) |
| 6746 | return false; |
| 6747 | |
| 6748 | AM = isInc ? ISD::PRE_INC : ISD::PRE_DEC; |
| 6749 | return true; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6750 | } |
| 6751 | |
| 6752 | /// getPostIndexedAddressParts - returns true by value, base pointer and |
| 6753 | /// offset pointer and addressing mode by reference if this node can be |
| 6754 | /// combined with a load / store to form a post-indexed load / store. |
| 6755 | bool ARMTargetLowering::getPostIndexedAddressParts(SDNode *N, SDNode *Op, |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6756 | SDValue &Base, |
| 6757 | SDValue &Offset, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6758 | ISD::MemIndexedMode &AM, |
Dan Gohman | 73e0914 | 2009-01-15 16:29:45 +0000 | [diff] [blame] | 6759 | SelectionDAG &DAG) const { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 6760 | if (Subtarget->isThumb1Only()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6761 | return false; |
| 6762 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6763 | EVT VT; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6764 | SDValue Ptr; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6765 | bool isSEXTLoad = false; |
| 6766 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) { |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 6767 | VT = LD->getMemoryVT(); |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 6768 | Ptr = LD->getBasePtr(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6769 | isSEXTLoad = LD->getExtensionType() == ISD::SEXTLOAD; |
| 6770 | } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) { |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 6771 | VT = ST->getMemoryVT(); |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 6772 | Ptr = ST->getBasePtr(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6773 | } else |
| 6774 | return false; |
| 6775 | |
| 6776 | bool isInc; |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 6777 | bool isLegal = false; |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 6778 | if (Subtarget->isThumb2()) |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 6779 | isLegal = getT2IndexedAddressParts(Op, VT, isSEXTLoad, Base, Offset, |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 6780 | isInc, DAG); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 6781 | else |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 6782 | isLegal = getARMIndexedAddressParts(Op, VT, isSEXTLoad, Base, Offset, |
| 6783 | isInc, DAG); |
| 6784 | if (!isLegal) |
| 6785 | return false; |
| 6786 | |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 6787 | if (Ptr != Base) { |
| 6788 | // Swap base ptr and offset to catch more post-index load / store when |
| 6789 | // it's legal. In Thumb2 mode, offset must be an immediate. |
| 6790 | if (Ptr == Offset && Op->getOpcode() == ISD::ADD && |
| 6791 | !Subtarget->isThumb2()) |
| 6792 | std::swap(Base, Offset); |
| 6793 | |
| 6794 | // Post-indexed load / store update the base pointer. |
| 6795 | if (Ptr != Base) |
| 6796 | return false; |
| 6797 | } |
| 6798 | |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 6799 | AM = isInc ? ISD::POST_INC : ISD::POST_DEC; |
| 6800 | return true; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6801 | } |
| 6802 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6803 | void ARMTargetLowering::computeMaskedBitsForTargetNode(const SDValue Op, |
Dan Gohman | 977a76f | 2008-02-13 22:28:48 +0000 | [diff] [blame] | 6804 | const APInt &Mask, |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 6805 | APInt &KnownZero, |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 6806 | APInt &KnownOne, |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 6807 | const SelectionDAG &DAG, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6808 | unsigned Depth) const { |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 6809 | KnownZero = KnownOne = APInt(Mask.getBitWidth(), 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6810 | switch (Op.getOpcode()) { |
| 6811 | default: break; |
| 6812 | case ARMISD::CMOV: { |
| 6813 | // Bits are known zero/one if known on the LHS and RHS. |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 6814 | DAG.ComputeMaskedBits(Op.getOperand(0), Mask, KnownZero, KnownOne, Depth+1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6815 | if (KnownZero == 0 && KnownOne == 0) return; |
| 6816 | |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 6817 | APInt KnownZeroRHS, KnownOneRHS; |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 6818 | DAG.ComputeMaskedBits(Op.getOperand(1), Mask, |
| 6819 | KnownZeroRHS, KnownOneRHS, Depth+1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6820 | KnownZero &= KnownZeroRHS; |
| 6821 | KnownOne &= KnownOneRHS; |
| 6822 | return; |
| 6823 | } |
| 6824 | } |
| 6825 | } |
| 6826 | |
| 6827 | //===----------------------------------------------------------------------===// |
| 6828 | // ARM Inline Assembly Support |
| 6829 | //===----------------------------------------------------------------------===// |
| 6830 | |
Evan Cheng | 55d4200 | 2011-01-08 01:24:27 +0000 | [diff] [blame] | 6831 | bool ARMTargetLowering::ExpandInlineAsm(CallInst *CI) const { |
| 6832 | // Looking for "rev" which is V6+. |
| 6833 | if (!Subtarget->hasV6Ops()) |
| 6834 | return false; |
| 6835 | |
| 6836 | InlineAsm *IA = cast<InlineAsm>(CI->getCalledValue()); |
| 6837 | std::string AsmStr = IA->getAsmString(); |
| 6838 | SmallVector<StringRef, 4> AsmPieces; |
| 6839 | SplitString(AsmStr, AsmPieces, ";\n"); |
| 6840 | |
| 6841 | switch (AsmPieces.size()) { |
| 6842 | default: return false; |
| 6843 | case 1: |
| 6844 | AsmStr = AsmPieces[0]; |
| 6845 | AsmPieces.clear(); |
| 6846 | SplitString(AsmStr, AsmPieces, " \t,"); |
| 6847 | |
| 6848 | // rev $0, $1 |
| 6849 | if (AsmPieces.size() == 3 && |
| 6850 | AsmPieces[0] == "rev" && AsmPieces[1] == "$0" && AsmPieces[2] == "$1" && |
| 6851 | IA->getConstraintString().compare(0, 4, "=l,l") == 0) { |
| 6852 | const IntegerType *Ty = dyn_cast<IntegerType>(CI->getType()); |
| 6853 | if (Ty && Ty->getBitWidth() == 32) |
| 6854 | return IntrinsicLowering::LowerToByteSwap(CI); |
| 6855 | } |
| 6856 | break; |
| 6857 | } |
| 6858 | |
| 6859 | return false; |
| 6860 | } |
| 6861 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6862 | /// getConstraintType - Given a constraint letter, return the type of |
| 6863 | /// constraint it is for this target. |
| 6864 | ARMTargetLowering::ConstraintType |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 6865 | ARMTargetLowering::getConstraintType(const std::string &Constraint) const { |
| 6866 | if (Constraint.size() == 1) { |
| 6867 | switch (Constraint[0]) { |
| 6868 | default: break; |
| 6869 | case 'l': return C_RegisterClass; |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 6870 | case 'w': return C_RegisterClass; |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 6871 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6872 | } |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 6873 | return TargetLowering::getConstraintType(Constraint); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6874 | } |
| 6875 | |
John Thompson | 44ab89e | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 6876 | /// Examine constraint type and operand type and determine a weight value. |
| 6877 | /// This object must already have been set up with the operand type |
| 6878 | /// and the current alternative constraint selected. |
| 6879 | TargetLowering::ConstraintWeight |
| 6880 | ARMTargetLowering::getSingleConstraintMatchWeight( |
| 6881 | AsmOperandInfo &info, const char *constraint) const { |
| 6882 | ConstraintWeight weight = CW_Invalid; |
| 6883 | Value *CallOperandVal = info.CallOperandVal; |
| 6884 | // If we don't have a value, we can't do a match, |
| 6885 | // but allow it at the lowest weight. |
| 6886 | if (CallOperandVal == NULL) |
| 6887 | return CW_Default; |
| 6888 | const Type *type = CallOperandVal->getType(); |
| 6889 | // Look at the constraint type. |
| 6890 | switch (*constraint) { |
| 6891 | default: |
| 6892 | weight = TargetLowering::getSingleConstraintMatchWeight(info, constraint); |
| 6893 | break; |
| 6894 | case 'l': |
| 6895 | if (type->isIntegerTy()) { |
| 6896 | if (Subtarget->isThumb()) |
| 6897 | weight = CW_SpecificReg; |
| 6898 | else |
| 6899 | weight = CW_Register; |
| 6900 | } |
| 6901 | break; |
| 6902 | case 'w': |
| 6903 | if (type->isFloatingPointTy()) |
| 6904 | weight = CW_Register; |
| 6905 | break; |
| 6906 | } |
| 6907 | return weight; |
| 6908 | } |
| 6909 | |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 6910 | std::pair<unsigned, const TargetRegisterClass*> |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6911 | ARMTargetLowering::getRegForInlineAsmConstraint(const std::string &Constraint, |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6912 | EVT VT) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6913 | if (Constraint.size() == 1) { |
Jakob Stoklund Olesen | 09bf003 | 2010-01-14 18:19:56 +0000 | [diff] [blame] | 6914 | // GCC ARM Constraint Letters |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6915 | switch (Constraint[0]) { |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 6916 | case 'l': |
Jakob Stoklund Olesen | 09bf003 | 2010-01-14 18:19:56 +0000 | [diff] [blame] | 6917 | if (Subtarget->isThumb()) |
Jim Grosbach | 30eae3c | 2009-04-07 20:34:09 +0000 | [diff] [blame] | 6918 | return std::make_pair(0U, ARM::tGPRRegisterClass); |
| 6919 | else |
| 6920 | return std::make_pair(0U, ARM::GPRRegisterClass); |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 6921 | case 'r': |
| 6922 | return std::make_pair(0U, ARM::GPRRegisterClass); |
| 6923 | case 'w': |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6924 | if (VT == MVT::f32) |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 6925 | return std::make_pair(0U, ARM::SPRRegisterClass); |
Bob Wilson | 5afffae | 2009-12-18 01:03:29 +0000 | [diff] [blame] | 6926 | if (VT.getSizeInBits() == 64) |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 6927 | return std::make_pair(0U, ARM::DPRRegisterClass); |
Evan Cheng | d831cda | 2009-12-08 23:06:22 +0000 | [diff] [blame] | 6928 | if (VT.getSizeInBits() == 128) |
| 6929 | return std::make_pair(0U, ARM::QPRRegisterClass); |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 6930 | break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6931 | } |
| 6932 | } |
Bob Wilson | 33cc5cb | 2010-03-15 23:09:18 +0000 | [diff] [blame] | 6933 | if (StringRef("{cc}").equals_lower(Constraint)) |
Jakob Stoklund Olesen | 0d8ba33 | 2010-06-18 16:49:33 +0000 | [diff] [blame] | 6934 | return std::make_pair(unsigned(ARM::CPSR), ARM::CCRRegisterClass); |
Bob Wilson | 33cc5cb | 2010-03-15 23:09:18 +0000 | [diff] [blame] | 6935 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6936 | return TargetLowering::getRegForInlineAsmConstraint(Constraint, VT); |
| 6937 | } |
| 6938 | |
| 6939 | std::vector<unsigned> ARMTargetLowering:: |
| 6940 | getRegClassForInlineAsmConstraint(const std::string &Constraint, |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6941 | EVT VT) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6942 | if (Constraint.size() != 1) |
| 6943 | return std::vector<unsigned>(); |
| 6944 | |
| 6945 | switch (Constraint[0]) { // GCC ARM Constraint Letters |
| 6946 | default: break; |
| 6947 | case 'l': |
Jim Grosbach | 30eae3c | 2009-04-07 20:34:09 +0000 | [diff] [blame] | 6948 | return make_vector<unsigned>(ARM::R0, ARM::R1, ARM::R2, ARM::R3, |
| 6949 | ARM::R4, ARM::R5, ARM::R6, ARM::R7, |
| 6950 | 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6951 | case 'r': |
| 6952 | return make_vector<unsigned>(ARM::R0, ARM::R1, ARM::R2, ARM::R3, |
| 6953 | ARM::R4, ARM::R5, ARM::R6, ARM::R7, |
| 6954 | ARM::R8, ARM::R9, ARM::R10, ARM::R11, |
| 6955 | ARM::R12, ARM::LR, 0); |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 6956 | case 'w': |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6957 | if (VT == MVT::f32) |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 6958 | return make_vector<unsigned>(ARM::S0, ARM::S1, ARM::S2, ARM::S3, |
| 6959 | ARM::S4, ARM::S5, ARM::S6, ARM::S7, |
| 6960 | ARM::S8, ARM::S9, ARM::S10, ARM::S11, |
| 6961 | ARM::S12,ARM::S13,ARM::S14,ARM::S15, |
| 6962 | ARM::S16,ARM::S17,ARM::S18,ARM::S19, |
| 6963 | ARM::S20,ARM::S21,ARM::S22,ARM::S23, |
| 6964 | ARM::S24,ARM::S25,ARM::S26,ARM::S27, |
| 6965 | ARM::S28,ARM::S29,ARM::S30,ARM::S31, 0); |
Bob Wilson | 5afffae | 2009-12-18 01:03:29 +0000 | [diff] [blame] | 6966 | if (VT.getSizeInBits() == 64) |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 6967 | return make_vector<unsigned>(ARM::D0, ARM::D1, ARM::D2, ARM::D3, |
| 6968 | ARM::D4, ARM::D5, ARM::D6, ARM::D7, |
| 6969 | ARM::D8, ARM::D9, ARM::D10,ARM::D11, |
| 6970 | ARM::D12,ARM::D13,ARM::D14,ARM::D15, 0); |
Evan Cheng | d831cda | 2009-12-08 23:06:22 +0000 | [diff] [blame] | 6971 | if (VT.getSizeInBits() == 128) |
| 6972 | return make_vector<unsigned>(ARM::Q0, ARM::Q1, ARM::Q2, ARM::Q3, |
| 6973 | ARM::Q4, ARM::Q5, ARM::Q6, ARM::Q7, 0); |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 6974 | break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6975 | } |
| 6976 | |
| 6977 | return std::vector<unsigned>(); |
| 6978 | } |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 6979 | |
| 6980 | /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops |
| 6981 | /// vector. If it is invalid, don't add anything to Ops. |
| 6982 | void ARMTargetLowering::LowerAsmOperandForConstraint(SDValue Op, |
| 6983 | char Constraint, |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 6984 | std::vector<SDValue>&Ops, |
| 6985 | SelectionDAG &DAG) const { |
| 6986 | SDValue Result(0, 0); |
| 6987 | |
| 6988 | switch (Constraint) { |
| 6989 | default: break; |
| 6990 | case 'I': case 'J': case 'K': case 'L': |
| 6991 | case 'M': case 'N': case 'O': |
| 6992 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op); |
| 6993 | if (!C) |
| 6994 | return; |
| 6995 | |
| 6996 | int64_t CVal64 = C->getSExtValue(); |
| 6997 | int CVal = (int) CVal64; |
| 6998 | // None of these constraints allow values larger than 32 bits. Check |
| 6999 | // that the value fits in an int. |
| 7000 | if (CVal != CVal64) |
| 7001 | return; |
| 7002 | |
| 7003 | switch (Constraint) { |
| 7004 | case 'I': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 7005 | if (Subtarget->isThumb1Only()) { |
| 7006 | // This must be a constant between 0 and 255, for ADD |
| 7007 | // immediates. |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 7008 | if (CVal >= 0 && CVal <= 255) |
| 7009 | break; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 7010 | } else if (Subtarget->isThumb2()) { |
| 7011 | // A constant that can be used as an immediate value in a |
| 7012 | // data-processing instruction. |
| 7013 | if (ARM_AM::getT2SOImmVal(CVal) != -1) |
| 7014 | break; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 7015 | } else { |
| 7016 | // A constant that can be used as an immediate value in a |
| 7017 | // data-processing instruction. |
| 7018 | if (ARM_AM::getSOImmVal(CVal) != -1) |
| 7019 | break; |
| 7020 | } |
| 7021 | return; |
| 7022 | |
| 7023 | case 'J': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 7024 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 7025 | // This must be a constant between -255 and -1, for negated ADD |
| 7026 | // immediates. This can be used in GCC with an "n" modifier that |
| 7027 | // prints the negated value, for use with SUB instructions. It is |
| 7028 | // not useful otherwise but is implemented for compatibility. |
| 7029 | if (CVal >= -255 && CVal <= -1) |
| 7030 | break; |
| 7031 | } else { |
| 7032 | // This must be a constant between -4095 and 4095. It is not clear |
| 7033 | // what this constraint is intended for. Implemented for |
| 7034 | // compatibility with GCC. |
| 7035 | if (CVal >= -4095 && CVal <= 4095) |
| 7036 | break; |
| 7037 | } |
| 7038 | return; |
| 7039 | |
| 7040 | case 'K': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 7041 | if (Subtarget->isThumb1Only()) { |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 7042 | // A 32-bit value where only one byte has a nonzero value. Exclude |
| 7043 | // zero to match GCC. This constraint is used by GCC internally for |
| 7044 | // constants that can be loaded with a move/shift combination. |
| 7045 | // It is not useful otherwise but is implemented for compatibility. |
| 7046 | if (CVal != 0 && ARM_AM::isThumbImmShiftedVal(CVal)) |
| 7047 | break; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 7048 | } else if (Subtarget->isThumb2()) { |
| 7049 | // A constant whose bitwise inverse can be used as an immediate |
| 7050 | // value in a data-processing instruction. This can be used in GCC |
| 7051 | // with a "B" modifier that prints the inverted value, for use with |
| 7052 | // BIC and MVN instructions. It is not useful otherwise but is |
| 7053 | // implemented for compatibility. |
| 7054 | if (ARM_AM::getT2SOImmVal(~CVal) != -1) |
| 7055 | break; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 7056 | } else { |
| 7057 | // A constant whose bitwise inverse can be used as an immediate |
| 7058 | // value in a data-processing instruction. This can be used in GCC |
| 7059 | // with a "B" modifier that prints the inverted value, for use with |
| 7060 | // BIC and MVN instructions. It is not useful otherwise but is |
| 7061 | // implemented for compatibility. |
| 7062 | if (ARM_AM::getSOImmVal(~CVal) != -1) |
| 7063 | break; |
| 7064 | } |
| 7065 | return; |
| 7066 | |
| 7067 | case 'L': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 7068 | if (Subtarget->isThumb1Only()) { |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 7069 | // This must be a constant between -7 and 7, |
| 7070 | // for 3-operand ADD/SUB immediate instructions. |
| 7071 | if (CVal >= -7 && CVal < 7) |
| 7072 | break; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 7073 | } else if (Subtarget->isThumb2()) { |
| 7074 | // A constant whose negation can be used as an immediate value in a |
| 7075 | // data-processing instruction. This can be used in GCC with an "n" |
| 7076 | // modifier that prints the negated value, for use with SUB |
| 7077 | // instructions. It is not useful otherwise but is implemented for |
| 7078 | // compatibility. |
| 7079 | if (ARM_AM::getT2SOImmVal(-CVal) != -1) |
| 7080 | break; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 7081 | } else { |
| 7082 | // A constant whose negation can be used as an immediate value in a |
| 7083 | // data-processing instruction. This can be used in GCC with an "n" |
| 7084 | // modifier that prints the negated value, for use with SUB |
| 7085 | // instructions. It is not useful otherwise but is implemented for |
| 7086 | // compatibility. |
| 7087 | if (ARM_AM::getSOImmVal(-CVal) != -1) |
| 7088 | break; |
| 7089 | } |
| 7090 | return; |
| 7091 | |
| 7092 | case 'M': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 7093 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 7094 | // This must be a multiple of 4 between 0 and 1020, for |
| 7095 | // ADD sp + immediate. |
| 7096 | if ((CVal >= 0 && CVal <= 1020) && ((CVal & 3) == 0)) |
| 7097 | break; |
| 7098 | } else { |
| 7099 | // A power of two or a constant between 0 and 32. This is used in |
| 7100 | // GCC for the shift amount on shifted register operands, but it is |
| 7101 | // useful in general for any shift amounts. |
| 7102 | if ((CVal >= 0 && CVal <= 32) || ((CVal & (CVal - 1)) == 0)) |
| 7103 | break; |
| 7104 | } |
| 7105 | return; |
| 7106 | |
| 7107 | case 'N': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 7108 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 7109 | // This must be a constant between 0 and 31, for shift amounts. |
| 7110 | if (CVal >= 0 && CVal <= 31) |
| 7111 | break; |
| 7112 | } |
| 7113 | return; |
| 7114 | |
| 7115 | case 'O': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 7116 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 7117 | // This must be a multiple of 4 between -508 and 508, for |
| 7118 | // ADD/SUB sp = sp + immediate. |
| 7119 | if ((CVal >= -508 && CVal <= 508) && ((CVal & 3) == 0)) |
| 7120 | break; |
| 7121 | } |
| 7122 | return; |
| 7123 | } |
| 7124 | Result = DAG.getTargetConstant(CVal, Op.getValueType()); |
| 7125 | break; |
| 7126 | } |
| 7127 | |
| 7128 | if (Result.getNode()) { |
| 7129 | Ops.push_back(Result); |
| 7130 | return; |
| 7131 | } |
Dale Johannesen | 1784d16 | 2010-06-25 21:55:36 +0000 | [diff] [blame] | 7132 | return TargetLowering::LowerAsmOperandForConstraint(Op, Constraint, Ops, DAG); |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 7133 | } |
Anton Korobeynikov | 48e1935 | 2009-09-23 19:04:09 +0000 | [diff] [blame] | 7134 | |
| 7135 | bool |
| 7136 | ARMTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const { |
| 7137 | // The ARM target isn't yet aware of offsets. |
| 7138 | return false; |
| 7139 | } |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 7140 | |
| 7141 | int ARM::getVFPf32Imm(const APFloat &FPImm) { |
| 7142 | APInt Imm = FPImm.bitcastToAPInt(); |
| 7143 | uint32_t Sign = Imm.lshr(31).getZExtValue() & 1; |
| 7144 | int32_t Exp = (Imm.lshr(23).getSExtValue() & 0xff) - 127; // -126 to 127 |
| 7145 | int64_t Mantissa = Imm.getZExtValue() & 0x7fffff; // 23 bits |
| 7146 | |
| 7147 | // We can handle 4 bits of mantissa. |
| 7148 | // mantissa = (16+UInt(e:f:g:h))/16. |
| 7149 | if (Mantissa & 0x7ffff) |
| 7150 | return -1; |
| 7151 | Mantissa >>= 19; |
| 7152 | if ((Mantissa & 0xf) != Mantissa) |
| 7153 | return -1; |
| 7154 | |
| 7155 | // We can handle 3 bits of exponent: exp == UInt(NOT(b):c:d)-3 |
| 7156 | if (Exp < -3 || Exp > 4) |
| 7157 | return -1; |
| 7158 | Exp = ((Exp+3) & 0x7) ^ 4; |
| 7159 | |
| 7160 | return ((int)Sign << 7) | (Exp << 4) | Mantissa; |
| 7161 | } |
| 7162 | |
| 7163 | int ARM::getVFPf64Imm(const APFloat &FPImm) { |
| 7164 | APInt Imm = FPImm.bitcastToAPInt(); |
| 7165 | uint64_t Sign = Imm.lshr(63).getZExtValue() & 1; |
| 7166 | int64_t Exp = (Imm.lshr(52).getSExtValue() & 0x7ff) - 1023; // -1022 to 1023 |
| 7167 | uint64_t Mantissa = Imm.getZExtValue() & 0xfffffffffffffLL; |
| 7168 | |
| 7169 | // We can handle 4 bits of mantissa. |
| 7170 | // mantissa = (16+UInt(e:f:g:h))/16. |
| 7171 | if (Mantissa & 0xffffffffffffLL) |
| 7172 | return -1; |
| 7173 | Mantissa >>= 48; |
| 7174 | if ((Mantissa & 0xf) != Mantissa) |
| 7175 | return -1; |
| 7176 | |
| 7177 | // We can handle 3 bits of exponent: exp == UInt(NOT(b):c:d)-3 |
| 7178 | if (Exp < -3 || Exp > 4) |
| 7179 | return -1; |
| 7180 | Exp = ((Exp+3) & 0x7) ^ 4; |
| 7181 | |
| 7182 | return ((int)Sign << 7) | (Exp << 4) | Mantissa; |
| 7183 | } |
| 7184 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 7185 | bool ARM::isBitFieldInvertedMask(unsigned v) { |
| 7186 | if (v == 0xffffffff) |
| 7187 | return 0; |
| 7188 | // there can be 1's on either or both "outsides", all the "inside" |
| 7189 | // bits must be 0's |
| 7190 | unsigned int lsb = 0, msb = 31; |
| 7191 | while (v & (1 << msb)) --msb; |
| 7192 | while (v & (1 << lsb)) ++lsb; |
| 7193 | for (unsigned int i = lsb; i <= msb; ++i) { |
| 7194 | if (v & (1 << i)) |
| 7195 | return 0; |
| 7196 | } |
| 7197 | return 1; |
| 7198 | } |
| 7199 | |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 7200 | /// isFPImmLegal - Returns true if the target can instruction select the |
| 7201 | /// specified FP immediate natively. If false, the legalizer will |
| 7202 | /// materialize the FP immediate as a load from a constant pool. |
| 7203 | bool ARMTargetLowering::isFPImmLegal(const APFloat &Imm, EVT VT) const { |
| 7204 | if (!Subtarget->hasVFP3()) |
| 7205 | return false; |
| 7206 | if (VT == MVT::f32) |
| 7207 | return ARM::getVFPf32Imm(Imm) != -1; |
| 7208 | if (VT == MVT::f64) |
| 7209 | return ARM::getVFPf64Imm(Imm) != -1; |
| 7210 | return false; |
| 7211 | } |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 7212 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7213 | /// getTgtMemIntrinsic - Represent NEON load and store intrinsics as |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 7214 | /// MemIntrinsicNodes. The associated MachineMemOperands record the alignment |
| 7215 | /// specified in the intrinsic calls. |
| 7216 | bool ARMTargetLowering::getTgtMemIntrinsic(IntrinsicInfo &Info, |
| 7217 | const CallInst &I, |
| 7218 | unsigned Intrinsic) const { |
| 7219 | switch (Intrinsic) { |
| 7220 | case Intrinsic::arm_neon_vld1: |
| 7221 | case Intrinsic::arm_neon_vld2: |
| 7222 | case Intrinsic::arm_neon_vld3: |
| 7223 | case Intrinsic::arm_neon_vld4: |
| 7224 | case Intrinsic::arm_neon_vld2lane: |
| 7225 | case Intrinsic::arm_neon_vld3lane: |
| 7226 | case Intrinsic::arm_neon_vld4lane: { |
| 7227 | Info.opc = ISD::INTRINSIC_W_CHAIN; |
| 7228 | // Conservatively set memVT to the entire set of vectors loaded. |
| 7229 | uint64_t NumElts = getTargetData()->getTypeAllocSize(I.getType()) / 8; |
| 7230 | Info.memVT = EVT::getVectorVT(I.getType()->getContext(), MVT::i64, NumElts); |
| 7231 | Info.ptrVal = I.getArgOperand(0); |
| 7232 | Info.offset = 0; |
| 7233 | Value *AlignArg = I.getArgOperand(I.getNumArgOperands() - 1); |
| 7234 | Info.align = cast<ConstantInt>(AlignArg)->getZExtValue(); |
| 7235 | Info.vol = false; // volatile loads with NEON intrinsics not supported |
| 7236 | Info.readMem = true; |
| 7237 | Info.writeMem = false; |
| 7238 | return true; |
| 7239 | } |
| 7240 | case Intrinsic::arm_neon_vst1: |
| 7241 | case Intrinsic::arm_neon_vst2: |
| 7242 | case Intrinsic::arm_neon_vst3: |
| 7243 | case Intrinsic::arm_neon_vst4: |
| 7244 | case Intrinsic::arm_neon_vst2lane: |
| 7245 | case Intrinsic::arm_neon_vst3lane: |
| 7246 | case Intrinsic::arm_neon_vst4lane: { |
| 7247 | Info.opc = ISD::INTRINSIC_VOID; |
| 7248 | // Conservatively set memVT to the entire set of vectors stored. |
| 7249 | unsigned NumElts = 0; |
| 7250 | for (unsigned ArgI = 1, ArgE = I.getNumArgOperands(); ArgI < ArgE; ++ArgI) { |
| 7251 | const Type *ArgTy = I.getArgOperand(ArgI)->getType(); |
| 7252 | if (!ArgTy->isVectorTy()) |
| 7253 | break; |
| 7254 | NumElts += getTargetData()->getTypeAllocSize(ArgTy) / 8; |
| 7255 | } |
| 7256 | Info.memVT = EVT::getVectorVT(I.getType()->getContext(), MVT::i64, NumElts); |
| 7257 | Info.ptrVal = I.getArgOperand(0); |
| 7258 | Info.offset = 0; |
| 7259 | Value *AlignArg = I.getArgOperand(I.getNumArgOperands() - 1); |
| 7260 | Info.align = cast<ConstantInt>(AlignArg)->getZExtValue(); |
| 7261 | Info.vol = false; // volatile stores with NEON intrinsics not supported |
| 7262 | Info.readMem = false; |
| 7263 | Info.writeMem = true; |
| 7264 | return true; |
| 7265 | } |
| 7266 | default: |
| 7267 | break; |
| 7268 | } |
| 7269 | |
| 7270 | return false; |
| 7271 | } |