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); |
Bob Wilson | 642b329 | 2009-09-16 00:32:15 +0000 | [diff] [blame] | 457 | setOperationAction(ISD::VSETCC, MVT::v1i64, Expand); |
| 458 | setOperationAction(ISD::VSETCC, MVT::v2i64, Expand); |
| 459 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 460 | setTargetDAGCombine(ISD::INTRINSIC_WO_CHAIN); |
| 461 | setTargetDAGCombine(ISD::SHL); |
| 462 | setTargetDAGCombine(ISD::SRL); |
| 463 | setTargetDAGCombine(ISD::SRA); |
| 464 | setTargetDAGCombine(ISD::SIGN_EXTEND); |
| 465 | setTargetDAGCombine(ISD::ZERO_EXTEND); |
| 466 | setTargetDAGCombine(ISD::ANY_EXTEND); |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 467 | setTargetDAGCombine(ISD::SELECT_CC); |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 468 | setTargetDAGCombine(ISD::BUILD_VECTOR); |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 469 | setTargetDAGCombine(ISD::VECTOR_SHUFFLE); |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 470 | setTargetDAGCombine(ISD::INSERT_VECTOR_ELT); |
| 471 | setTargetDAGCombine(ISD::STORE); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 472 | } |
| 473 | |
Evan Cheng | 9f8cbd1 | 2007-05-18 00:19:34 +0000 | [diff] [blame] | 474 | computeRegisterProperties(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 475 | |
| 476 | // ARM does not have f32 extending load. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 477 | setLoadExtAction(ISD::EXTLOAD, MVT::f32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 478 | |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 479 | // ARM does not have i1 sign extending load. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 480 | setLoadExtAction(ISD::SEXTLOAD, MVT::i1, Promote); |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 481 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 482 | // ARM supports all 4 flavors of integer indexed load / store. |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 483 | if (!Subtarget->isThumb1Only()) { |
| 484 | for (unsigned im = (unsigned)ISD::PRE_INC; |
| 485 | im != (unsigned)ISD::LAST_INDEXED_MODE; ++im) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 486 | setIndexedLoadAction(im, MVT::i1, Legal); |
| 487 | setIndexedLoadAction(im, MVT::i8, Legal); |
| 488 | setIndexedLoadAction(im, MVT::i16, Legal); |
| 489 | setIndexedLoadAction(im, MVT::i32, Legal); |
| 490 | setIndexedStoreAction(im, MVT::i1, Legal); |
| 491 | setIndexedStoreAction(im, MVT::i8, Legal); |
| 492 | setIndexedStoreAction(im, MVT::i16, Legal); |
| 493 | setIndexedStoreAction(im, MVT::i32, Legal); |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 494 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | // i64 operation support. |
Evan Cheng | 5b9fcd1 | 2009-07-07 01:17:28 +0000 | [diff] [blame] | 498 | if (Subtarget->isThumb1Only()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 499 | setOperationAction(ISD::MUL, MVT::i64, Expand); |
| 500 | setOperationAction(ISD::MULHU, MVT::i32, Expand); |
| 501 | setOperationAction(ISD::MULHS, MVT::i32, Expand); |
| 502 | setOperationAction(ISD::UMUL_LOHI, MVT::i32, Expand); |
| 503 | setOperationAction(ISD::SMUL_LOHI, MVT::i32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 504 | } else { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 505 | setOperationAction(ISD::MUL, MVT::i64, Expand); |
| 506 | setOperationAction(ISD::MULHU, MVT::i32, Expand); |
Evan Cheng | b620724 | 2009-08-01 00:16:10 +0000 | [diff] [blame] | 507 | if (!Subtarget->hasV6Ops()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 508 | setOperationAction(ISD::MULHS, MVT::i32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 509 | } |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 510 | setOperationAction(ISD::SHL_PARTS, MVT::i32, Custom); |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 511 | setOperationAction(ISD::SRA_PARTS, MVT::i32, Custom); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 512 | setOperationAction(ISD::SRL_PARTS, MVT::i32, Custom); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 513 | setOperationAction(ISD::SRL, MVT::i64, Custom); |
| 514 | setOperationAction(ISD::SRA, MVT::i64, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 515 | |
| 516 | // ARM does not have ROTL. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 517 | setOperationAction(ISD::ROTL, MVT::i32, Expand); |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 518 | setOperationAction(ISD::CTTZ, MVT::i32, Custom); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 519 | setOperationAction(ISD::CTPOP, MVT::i32, Expand); |
David Goodwin | 24062ac | 2009-06-26 20:47:43 +0000 | [diff] [blame] | 520 | if (!Subtarget->hasV5TOps() || Subtarget->isThumb1Only()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 521 | setOperationAction(ISD::CTLZ, MVT::i32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 522 | |
Lauro Ramos Venancio | 368f20f | 2007-03-16 22:54:16 +0000 | [diff] [blame] | 523 | // Only ARMv6 has BSWAP. |
| 524 | if (!Subtarget->hasV6Ops()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 525 | setOperationAction(ISD::BSWAP, MVT::i32, Expand); |
Lauro Ramos Venancio | 368f20f | 2007-03-16 22:54:16 +0000 | [diff] [blame] | 526 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 527 | // These are expanded into libcalls. |
Evan Cheng | 1f190c8 | 2010-11-19 06:28:11 +0000 | [diff] [blame] | 528 | if (!Subtarget->hasDivide() || !Subtarget->isThumb2()) { |
Jim Grosbach | b1dc393 | 2010-05-05 20:44:35 +0000 | [diff] [blame] | 529 | // v7M has a hardware divider |
| 530 | setOperationAction(ISD::SDIV, MVT::i32, Expand); |
| 531 | setOperationAction(ISD::UDIV, MVT::i32, Expand); |
| 532 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 533 | setOperationAction(ISD::SREM, MVT::i32, Expand); |
| 534 | setOperationAction(ISD::UREM, MVT::i32, Expand); |
| 535 | setOperationAction(ISD::SDIVREM, MVT::i32, Expand); |
| 536 | setOperationAction(ISD::UDIVREM, MVT::i32, Expand); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 537 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 538 | setOperationAction(ISD::GlobalAddress, MVT::i32, Custom); |
| 539 | setOperationAction(ISD::ConstantPool, MVT::i32, Custom); |
| 540 | setOperationAction(ISD::GLOBAL_OFFSET_TABLE, MVT::i32, Custom); |
| 541 | setOperationAction(ISD::GlobalTLSAddress, MVT::i32, Custom); |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 542 | setOperationAction(ISD::BlockAddress, MVT::i32, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 543 | |
Evan Cheng | fb3611d | 2010-05-11 07:26:32 +0000 | [diff] [blame] | 544 | setOperationAction(ISD::TRAP, MVT::Other, Legal); |
| 545 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 546 | // Use the default implementation. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 547 | setOperationAction(ISD::VASTART, MVT::Other, Custom); |
| 548 | setOperationAction(ISD::VAARG, MVT::Other, Expand); |
| 549 | setOperationAction(ISD::VACOPY, MVT::Other, Expand); |
| 550 | setOperationAction(ISD::VAEND, MVT::Other, Expand); |
| 551 | setOperationAction(ISD::STACKSAVE, MVT::Other, Expand); |
| 552 | setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand); |
Jim Grosbach | bff3923 | 2009-08-12 17:38:44 +0000 | [diff] [blame] | 553 | setOperationAction(ISD::EHSELECTION, MVT::i32, Expand); |
Anton Korobeynikov | 5899a60 | 2011-01-24 22:38:45 +0000 | [diff] [blame] | 554 | setOperationAction(ISD::EXCEPTIONADDR, MVT::i32, Expand); |
| 555 | setExceptionPointerRegister(ARM::R0); |
| 556 | setExceptionSelectorRegister(ARM::R1); |
| 557 | |
Evan Cheng | 3a1588a | 2010-04-15 22:20:34 +0000 | [diff] [blame] | 558 | setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32, Expand); |
Evan Cheng | 11db068 | 2010-08-11 06:22:01 +0000 | [diff] [blame] | 559 | // ARMv6 Thumb1 (except for CPUs that support dmb / dsb) and earlier use |
| 560 | // the default expansion. |
| 561 | if (Subtarget->hasDataBarrier() || |
Bob Wilson | 54f9256 | 2010-11-09 22:50:44 +0000 | [diff] [blame] | 562 | (Subtarget->hasV6Ops() && !Subtarget->isThumb())) { |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 563 | // membarrier needs custom lowering; the rest are legal and handled |
| 564 | // normally. |
| 565 | setOperationAction(ISD::MEMBARRIER, MVT::Other, Custom); |
| 566 | } else { |
| 567 | // Set them all for expansion, which will force libcalls. |
| 568 | setOperationAction(ISD::MEMBARRIER, MVT::Other, Expand); |
| 569 | setOperationAction(ISD::ATOMIC_CMP_SWAP, MVT::i8, Expand); |
| 570 | setOperationAction(ISD::ATOMIC_CMP_SWAP, MVT::i16, Expand); |
| 571 | setOperationAction(ISD::ATOMIC_CMP_SWAP, MVT::i32, Expand); |
Jim Grosbach | ef6eb9c | 2010-06-18 23:03:10 +0000 | [diff] [blame] | 572 | setOperationAction(ISD::ATOMIC_SWAP, MVT::i8, Expand); |
| 573 | setOperationAction(ISD::ATOMIC_SWAP, MVT::i16, Expand); |
| 574 | setOperationAction(ISD::ATOMIC_SWAP, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 575 | setOperationAction(ISD::ATOMIC_LOAD_ADD, MVT::i8, Expand); |
| 576 | setOperationAction(ISD::ATOMIC_LOAD_ADD, MVT::i16, Expand); |
| 577 | setOperationAction(ISD::ATOMIC_LOAD_ADD, MVT::i32, Expand); |
| 578 | setOperationAction(ISD::ATOMIC_LOAD_SUB, MVT::i8, Expand); |
| 579 | setOperationAction(ISD::ATOMIC_LOAD_SUB, MVT::i16, Expand); |
| 580 | setOperationAction(ISD::ATOMIC_LOAD_SUB, MVT::i32, Expand); |
| 581 | setOperationAction(ISD::ATOMIC_LOAD_AND, MVT::i8, Expand); |
| 582 | setOperationAction(ISD::ATOMIC_LOAD_AND, MVT::i16, Expand); |
| 583 | setOperationAction(ISD::ATOMIC_LOAD_AND, MVT::i32, Expand); |
| 584 | setOperationAction(ISD::ATOMIC_LOAD_OR, MVT::i8, Expand); |
| 585 | setOperationAction(ISD::ATOMIC_LOAD_OR, MVT::i16, Expand); |
| 586 | setOperationAction(ISD::ATOMIC_LOAD_OR, MVT::i32, Expand); |
| 587 | setOperationAction(ISD::ATOMIC_LOAD_XOR, MVT::i8, Expand); |
| 588 | setOperationAction(ISD::ATOMIC_LOAD_XOR, MVT::i16, Expand); |
| 589 | setOperationAction(ISD::ATOMIC_LOAD_XOR, MVT::i32, Expand); |
| 590 | setOperationAction(ISD::ATOMIC_LOAD_NAND, MVT::i8, Expand); |
| 591 | setOperationAction(ISD::ATOMIC_LOAD_NAND, MVT::i16, Expand); |
| 592 | setOperationAction(ISD::ATOMIC_LOAD_NAND, MVT::i32, Expand); |
Jim Grosbach | 5def57a | 2010-06-23 16:08:49 +0000 | [diff] [blame] | 593 | // Since the libcalls include locking, fold in the fences |
| 594 | setShouldFoldAtomicFences(true); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 595 | } |
| 596 | // 64-bit versions are always libcalls (for now) |
| 597 | setOperationAction(ISD::ATOMIC_CMP_SWAP, MVT::i64, Expand); |
Jim Grosbach | ef6eb9c | 2010-06-18 23:03:10 +0000 | [diff] [blame] | 598 | setOperationAction(ISD::ATOMIC_SWAP, MVT::i64, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 599 | setOperationAction(ISD::ATOMIC_LOAD_ADD, MVT::i64, Expand); |
| 600 | setOperationAction(ISD::ATOMIC_LOAD_SUB, MVT::i64, Expand); |
| 601 | setOperationAction(ISD::ATOMIC_LOAD_AND, MVT::i64, Expand); |
| 602 | setOperationAction(ISD::ATOMIC_LOAD_OR, MVT::i64, Expand); |
| 603 | setOperationAction(ISD::ATOMIC_LOAD_XOR, MVT::i64, Expand); |
| 604 | setOperationAction(ISD::ATOMIC_LOAD_NAND, MVT::i64, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 605 | |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 606 | setOperationAction(ISD::PREFETCH, MVT::Other, Custom); |
Evan Cheng | bc7deb0 | 2010-11-03 05:14:24 +0000 | [diff] [blame] | 607 | |
Eli Friedman | a2c6f45 | 2010-06-26 04:36:50 +0000 | [diff] [blame] | 608 | // Requires SXTB/SXTH, available on v6 and up in both ARM and Thumb modes. |
| 609 | if (!Subtarget->hasV6Ops()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 610 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i16, Expand); |
| 611 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i8, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 612 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 613 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 614 | |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 615 | if (!UseSoftFloat && Subtarget->hasVFP2() && !Subtarget->isThumb1Only()) { |
Bob Wilson | cb9a6aa | 2010-01-19 22:56:26 +0000 | [diff] [blame] | 616 | // Turn f64->i64 into VMOVRRD, i64 -> f64 to VMOVDRR |
| 617 | // iff target supports vfp2. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 618 | setOperationAction(ISD::BITCAST, MVT::i64, Custom); |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 619 | setOperationAction(ISD::FLT_ROUNDS_, MVT::i32, Custom); |
| 620 | } |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 621 | |
| 622 | // We want to custom lower some of our intrinsics. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 623 | setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom); |
Jim Grosbach | e97f968 | 2010-07-07 00:07:57 +0000 | [diff] [blame] | 624 | if (Subtarget->isTargetDarwin()) { |
| 625 | setOperationAction(ISD::EH_SJLJ_SETJMP, MVT::i32, Custom); |
| 626 | setOperationAction(ISD::EH_SJLJ_LONGJMP, MVT::Other, Custom); |
Jim Grosbach | e4ad387 | 2010-10-19 23:27:08 +0000 | [diff] [blame] | 627 | setOperationAction(ISD::EH_SJLJ_DISPATCHSETUP, MVT::Other, Custom); |
Jim Grosbach | e97f968 | 2010-07-07 00:07:57 +0000 | [diff] [blame] | 628 | } |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 629 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 630 | setOperationAction(ISD::SETCC, MVT::i32, Expand); |
| 631 | setOperationAction(ISD::SETCC, MVT::f32, Expand); |
| 632 | setOperationAction(ISD::SETCC, MVT::f64, Expand); |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 633 | setOperationAction(ISD::SELECT, MVT::i32, Custom); |
| 634 | setOperationAction(ISD::SELECT, MVT::f32, Custom); |
| 635 | setOperationAction(ISD::SELECT, MVT::f64, Custom); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 636 | setOperationAction(ISD::SELECT_CC, MVT::i32, Custom); |
| 637 | setOperationAction(ISD::SELECT_CC, MVT::f32, Custom); |
| 638 | setOperationAction(ISD::SELECT_CC, MVT::f64, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 639 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 640 | setOperationAction(ISD::BRCOND, MVT::Other, Expand); |
| 641 | setOperationAction(ISD::BR_CC, MVT::i32, Custom); |
| 642 | setOperationAction(ISD::BR_CC, MVT::f32, Custom); |
| 643 | setOperationAction(ISD::BR_CC, MVT::f64, Custom); |
| 644 | setOperationAction(ISD::BR_JT, MVT::Other, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 645 | |
Dan Gohman | f96e4de | 2007-10-11 23:21:31 +0000 | [diff] [blame] | 646 | // We don't support sin/cos/fmod/copysign/pow |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 647 | setOperationAction(ISD::FSIN, MVT::f64, Expand); |
| 648 | setOperationAction(ISD::FSIN, MVT::f32, Expand); |
| 649 | setOperationAction(ISD::FCOS, MVT::f32, Expand); |
| 650 | setOperationAction(ISD::FCOS, MVT::f64, Expand); |
| 651 | setOperationAction(ISD::FREM, MVT::f64, Expand); |
| 652 | setOperationAction(ISD::FREM, MVT::f32, Expand); |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 653 | if (!UseSoftFloat && Subtarget->hasVFP2() && !Subtarget->isThumb1Only()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 654 | setOperationAction(ISD::FCOPYSIGN, MVT::f64, Custom); |
| 655 | setOperationAction(ISD::FCOPYSIGN, MVT::f32, Custom); |
Evan Cheng | 110cf48 | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 656 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 657 | setOperationAction(ISD::FPOW, MVT::f64, Expand); |
| 658 | setOperationAction(ISD::FPOW, MVT::f32, Expand); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 659 | |
Anton Korobeynikov | bec3dd2 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 660 | // Various VFP goodness |
| 661 | if (!UseSoftFloat && !Subtarget->isThumb1Only()) { |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 662 | // int <-> fp are custom expanded into bit_convert + ARMISD ops. |
| 663 | if (Subtarget->hasVFP2()) { |
| 664 | setOperationAction(ISD::SINT_TO_FP, MVT::i32, Custom); |
| 665 | setOperationAction(ISD::UINT_TO_FP, MVT::i32, Custom); |
| 666 | setOperationAction(ISD::FP_TO_UINT, MVT::i32, Custom); |
| 667 | setOperationAction(ISD::FP_TO_SINT, MVT::i32, Custom); |
| 668 | } |
Anton Korobeynikov | bec3dd2 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 669 | // Special handling for half-precision FP. |
Anton Korobeynikov | f0d5007 | 2010-03-18 22:35:37 +0000 | [diff] [blame] | 670 | if (!Subtarget->hasFP16()) { |
| 671 | setOperationAction(ISD::FP16_TO_FP32, MVT::f32, Expand); |
| 672 | setOperationAction(ISD::FP32_TO_FP16, MVT::i32, Expand); |
Anton Korobeynikov | bec3dd2 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 673 | } |
Evan Cheng | 110cf48 | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 674 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 675 | |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 676 | // We have target-specific dag combine patterns for the following nodes: |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 677 | // ARMISD::VMOVRRD - No need to call setTargetDAGCombine |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 678 | setTargetDAGCombine(ISD::ADD); |
| 679 | setTargetDAGCombine(ISD::SUB); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 680 | setTargetDAGCombine(ISD::MUL); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 681 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 682 | if (Subtarget->hasV6T2Ops() || Subtarget->hasNEON()) |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 683 | setTargetDAGCombine(ISD::OR); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 684 | if (Subtarget->hasNEON()) |
| 685 | setTargetDAGCombine(ISD::AND); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 686 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 687 | setStackPointerRegisterToSaveRestore(ARM::SP); |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 688 | |
Evan Cheng | f7d87ee | 2010-05-21 00:43:17 +0000 | [diff] [blame] | 689 | if (UseSoftFloat || Subtarget->isThumb1Only() || !Subtarget->hasVFP2()) |
| 690 | setSchedulingPreference(Sched::RegPressure); |
| 691 | else |
| 692 | setSchedulingPreference(Sched::Hybrid); |
Dale Johannesen | 8dd86c1 | 2007-05-17 21:31:21 +0000 | [diff] [blame] | 693 | |
Evan Cheng | 0521928 | 2011-01-06 06:52:41 +0000 | [diff] [blame] | 694 | //// temporary - rewrite interface to use type |
| 695 | maxStoresPerMemcpy = maxStoresPerMemcpyOptSize = 1; |
Evan Cheng | f679939 | 2010-06-26 01:52:05 +0000 | [diff] [blame] | 696 | |
Rafael Espindola | cbeeae2 | 2010-07-11 04:01:49 +0000 | [diff] [blame] | 697 | // On ARM arguments smaller than 4 bytes are extended, so all arguments |
| 698 | // are at least 4 bytes aligned. |
| 699 | setMinStackArgumentAlignment(4); |
| 700 | |
Evan Cheng | fff606d | 2010-09-24 19:07:23 +0000 | [diff] [blame] | 701 | benefitFromCodePlacementOpt = true; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 702 | } |
| 703 | |
Andrew Trick | 32cec0a | 2011-01-19 02:35:27 +0000 | [diff] [blame] | 704 | // FIXME: It might make sense to define the representative register class as the |
| 705 | // nearest super-register that has a non-null superset. For example, DPR_VFP2 is |
| 706 | // a super-register of SPR, and DPR is a superset if DPR_VFP2. Consequently, |
| 707 | // SPR's representative would be DPR_VFP2. This should work well if register |
| 708 | // pressure tracking were modified such that a register use would increment the |
| 709 | // pressure of the register class's representative and all of it's super |
| 710 | // classes' representatives transitively. We have not implemented this because |
| 711 | // of the difficulty prior to coalescing of modeling operand register classes |
| 712 | // due to the common occurence of cross class copies and subregister insertions |
| 713 | // and extractions. |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 714 | std::pair<const TargetRegisterClass*, uint8_t> |
| 715 | ARMTargetLowering::findRepresentativeClass(EVT VT) const{ |
| 716 | const TargetRegisterClass *RRC = 0; |
| 717 | uint8_t Cost = 1; |
| 718 | switch (VT.getSimpleVT().SimpleTy) { |
Evan Cheng | d70f57b | 2010-07-19 22:15:08 +0000 | [diff] [blame] | 719 | default: |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 720 | return TargetLowering::findRepresentativeClass(VT); |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 721 | // Use DPR as representative register class for all floating point |
| 722 | // and vector types. Since there are 32 SPR registers and 32 DPR registers so |
| 723 | // the cost is 1 for both f32 and f64. |
| 724 | case MVT::f32: case MVT::f64: case MVT::v8i8: case MVT::v4i16: |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 725 | case MVT::v2i32: case MVT::v1i64: case MVT::v2f32: |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 726 | RRC = ARM::DPRRegisterClass; |
Andrew Trick | 32cec0a | 2011-01-19 02:35:27 +0000 | [diff] [blame] | 727 | // When NEON is used for SP, only half of the register file is available |
| 728 | // because operations that define both SP and DP results will be constrained |
| 729 | // to the VFP2 class (D0-D15). We currently model this constraint prior to |
| 730 | // coalescing by double-counting the SP regs. See the FIXME above. |
| 731 | if (Subtarget->useNEONForSinglePrecisionFP()) |
| 732 | Cost = 2; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 733 | break; |
| 734 | case MVT::v16i8: case MVT::v8i16: case MVT::v4i32: case MVT::v2i64: |
| 735 | case MVT::v4f32: case MVT::v2f64: |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 736 | RRC = ARM::DPRRegisterClass; |
| 737 | Cost = 2; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 738 | break; |
| 739 | case MVT::v4i64: |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 740 | RRC = ARM::DPRRegisterClass; |
| 741 | Cost = 4; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 742 | break; |
| 743 | case MVT::v8i64: |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 744 | RRC = ARM::DPRRegisterClass; |
| 745 | Cost = 8; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 746 | break; |
Evan Cheng | d70f57b | 2010-07-19 22:15:08 +0000 | [diff] [blame] | 747 | } |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 748 | return std::make_pair(RRC, Cost); |
Evan Cheng | d70f57b | 2010-07-19 22:15:08 +0000 | [diff] [blame] | 749 | } |
| 750 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 751 | const char *ARMTargetLowering::getTargetNodeName(unsigned Opcode) const { |
| 752 | switch (Opcode) { |
| 753 | default: return 0; |
| 754 | case ARMISD::Wrapper: return "ARMISD::Wrapper"; |
Evan Cheng | 53519f0 | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 755 | case ARMISD::WrapperDYN: return "ARMISD::WrapperDYN"; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 756 | case ARMISD::WrapperPIC: return "ARMISD::WrapperPIC"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 757 | case ARMISD::WrapperJT: return "ARMISD::WrapperJT"; |
| 758 | case ARMISD::CALL: return "ARMISD::CALL"; |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 759 | case ARMISD::CALL_PRED: return "ARMISD::CALL_PRED"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 760 | case ARMISD::CALL_NOLINK: return "ARMISD::CALL_NOLINK"; |
| 761 | case ARMISD::tCALL: return "ARMISD::tCALL"; |
| 762 | case ARMISD::BRCOND: return "ARMISD::BRCOND"; |
| 763 | case ARMISD::BR_JT: return "ARMISD::BR_JT"; |
Evan Cheng | 5657c01 | 2009-07-29 02:18:14 +0000 | [diff] [blame] | 764 | case ARMISD::BR2_JT: return "ARMISD::BR2_JT"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 765 | case ARMISD::RET_FLAG: return "ARMISD::RET_FLAG"; |
| 766 | case ARMISD::PIC_ADD: return "ARMISD::PIC_ADD"; |
| 767 | case ARMISD::CMP: return "ARMISD::CMP"; |
David Goodwin | c0309b4 | 2009-06-29 15:33:01 +0000 | [diff] [blame] | 768 | case ARMISD::CMPZ: return "ARMISD::CMPZ"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 769 | case ARMISD::CMPFP: return "ARMISD::CMPFP"; |
| 770 | case ARMISD::CMPFPw0: return "ARMISD::CMPFPw0"; |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 771 | case ARMISD::BCC_i64: return "ARMISD::BCC_i64"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 772 | case ARMISD::FMSTAT: return "ARMISD::FMSTAT"; |
| 773 | case ARMISD::CMOV: return "ARMISD::CMOV"; |
| 774 | case ARMISD::CNEG: return "ARMISD::CNEG"; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 775 | |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 776 | case ARMISD::RBIT: return "ARMISD::RBIT"; |
| 777 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 778 | case ARMISD::FTOSI: return "ARMISD::FTOSI"; |
| 779 | case ARMISD::FTOUI: return "ARMISD::FTOUI"; |
| 780 | case ARMISD::SITOF: return "ARMISD::SITOF"; |
| 781 | case ARMISD::UITOF: return "ARMISD::UITOF"; |
| 782 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 783 | case ARMISD::SRL_FLAG: return "ARMISD::SRL_FLAG"; |
| 784 | case ARMISD::SRA_FLAG: return "ARMISD::SRA_FLAG"; |
| 785 | case ARMISD::RRX: return "ARMISD::RRX"; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 786 | |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 787 | case ARMISD::VMOVRRD: return "ARMISD::VMOVRRD"; |
| 788 | case ARMISD::VMOVDRR: return "ARMISD::VMOVDRR"; |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 789 | |
Evan Cheng | c594208 | 2009-10-28 06:55:03 +0000 | [diff] [blame] | 790 | case ARMISD::EH_SJLJ_SETJMP: return "ARMISD::EH_SJLJ_SETJMP"; |
| 791 | case ARMISD::EH_SJLJ_LONGJMP:return "ARMISD::EH_SJLJ_LONGJMP"; |
Jim Grosbach | e4ad387 | 2010-10-19 23:27:08 +0000 | [diff] [blame] | 792 | case ARMISD::EH_SJLJ_DISPATCHSETUP:return "ARMISD::EH_SJLJ_DISPATCHSETUP"; |
Evan Cheng | c594208 | 2009-10-28 06:55:03 +0000 | [diff] [blame] | 793 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 794 | case ARMISD::TC_RETURN: return "ARMISD::TC_RETURN"; |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 795 | |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 796 | case ARMISD::THREAD_POINTER:return "ARMISD::THREAD_POINTER"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 797 | |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 798 | case ARMISD::DYN_ALLOC: return "ARMISD::DYN_ALLOC"; |
| 799 | |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 800 | case ARMISD::MEMBARRIER: return "ARMISD::MEMBARRIER"; |
Bob Wilson | f74a429 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 801 | case ARMISD::MEMBARRIER_MCR: return "ARMISD::MEMBARRIER_MCR"; |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 802 | |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 803 | case ARMISD::PRELOAD: return "ARMISD::PRELOAD"; |
| 804 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 805 | case ARMISD::VCEQ: return "ARMISD::VCEQ"; |
Bob Wilson | 3a75b9b | 2010-12-18 00:04:26 +0000 | [diff] [blame] | 806 | case ARMISD::VCEQZ: return "ARMISD::VCEQZ"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 807 | case ARMISD::VCGE: return "ARMISD::VCGE"; |
Bob Wilson | 3a75b9b | 2010-12-18 00:04:26 +0000 | [diff] [blame] | 808 | case ARMISD::VCGEZ: return "ARMISD::VCGEZ"; |
| 809 | case ARMISD::VCLEZ: return "ARMISD::VCLEZ"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 810 | case ARMISD::VCGEU: return "ARMISD::VCGEU"; |
| 811 | case ARMISD::VCGT: return "ARMISD::VCGT"; |
Bob Wilson | 3a75b9b | 2010-12-18 00:04:26 +0000 | [diff] [blame] | 812 | case ARMISD::VCGTZ: return "ARMISD::VCGTZ"; |
| 813 | case ARMISD::VCLTZ: return "ARMISD::VCLTZ"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 814 | case ARMISD::VCGTU: return "ARMISD::VCGTU"; |
| 815 | case ARMISD::VTST: return "ARMISD::VTST"; |
| 816 | |
| 817 | case ARMISD::VSHL: return "ARMISD::VSHL"; |
| 818 | case ARMISD::VSHRs: return "ARMISD::VSHRs"; |
| 819 | case ARMISD::VSHRu: return "ARMISD::VSHRu"; |
| 820 | case ARMISD::VSHLLs: return "ARMISD::VSHLLs"; |
| 821 | case ARMISD::VSHLLu: return "ARMISD::VSHLLu"; |
| 822 | case ARMISD::VSHLLi: return "ARMISD::VSHLLi"; |
| 823 | case ARMISD::VSHRN: return "ARMISD::VSHRN"; |
| 824 | case ARMISD::VRSHRs: return "ARMISD::VRSHRs"; |
| 825 | case ARMISD::VRSHRu: return "ARMISD::VRSHRu"; |
| 826 | case ARMISD::VRSHRN: return "ARMISD::VRSHRN"; |
| 827 | case ARMISD::VQSHLs: return "ARMISD::VQSHLs"; |
| 828 | case ARMISD::VQSHLu: return "ARMISD::VQSHLu"; |
| 829 | case ARMISD::VQSHLsu: return "ARMISD::VQSHLsu"; |
| 830 | case ARMISD::VQSHRNs: return "ARMISD::VQSHRNs"; |
| 831 | case ARMISD::VQSHRNu: return "ARMISD::VQSHRNu"; |
| 832 | case ARMISD::VQSHRNsu: return "ARMISD::VQSHRNsu"; |
| 833 | case ARMISD::VQRSHRNs: return "ARMISD::VQRSHRNs"; |
| 834 | case ARMISD::VQRSHRNu: return "ARMISD::VQRSHRNu"; |
| 835 | case ARMISD::VQRSHRNsu: return "ARMISD::VQRSHRNsu"; |
| 836 | case ARMISD::VGETLANEu: return "ARMISD::VGETLANEu"; |
| 837 | case ARMISD::VGETLANEs: return "ARMISD::VGETLANEs"; |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 838 | case ARMISD::VMOVIMM: return "ARMISD::VMOVIMM"; |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 839 | case ARMISD::VMVNIMM: return "ARMISD::VMVNIMM"; |
Bob Wilson | c1d287b | 2009-08-14 05:13:08 +0000 | [diff] [blame] | 840 | case ARMISD::VDUP: return "ARMISD::VDUP"; |
Bob Wilson | 0ce3710 | 2009-08-14 05:08:32 +0000 | [diff] [blame] | 841 | case ARMISD::VDUPLANE: return "ARMISD::VDUPLANE"; |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 842 | case ARMISD::VEXT: return "ARMISD::VEXT"; |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 843 | case ARMISD::VREV64: return "ARMISD::VREV64"; |
| 844 | case ARMISD::VREV32: return "ARMISD::VREV32"; |
| 845 | case ARMISD::VREV16: return "ARMISD::VREV16"; |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 846 | case ARMISD::VZIP: return "ARMISD::VZIP"; |
| 847 | case ARMISD::VUZP: return "ARMISD::VUZP"; |
| 848 | case ARMISD::VTRN: return "ARMISD::VTRN"; |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 849 | case ARMISD::VMULLs: return "ARMISD::VMULLs"; |
| 850 | case ARMISD::VMULLu: return "ARMISD::VMULLu"; |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 851 | case ARMISD::BUILD_VECTOR: return "ARMISD::BUILD_VECTOR"; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 852 | case ARMISD::FMAX: return "ARMISD::FMAX"; |
| 853 | case ARMISD::FMIN: return "ARMISD::FMIN"; |
Jim Grosbach | dd7d28a | 2010-07-17 01:50:57 +0000 | [diff] [blame] | 854 | case ARMISD::BFI: return "ARMISD::BFI"; |
Bob Wilson | 364a72a | 2010-11-28 06:51:11 +0000 | [diff] [blame] | 855 | case ARMISD::VORRIMM: return "ARMISD::VORRIMM"; |
| 856 | case ARMISD::VBICIMM: return "ARMISD::VBICIMM"; |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 857 | case ARMISD::VLD2DUP: return "ARMISD::VLD2DUP"; |
| 858 | case ARMISD::VLD3DUP: return "ARMISD::VLD3DUP"; |
| 859 | case ARMISD::VLD4DUP: return "ARMISD::VLD4DUP"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 860 | } |
| 861 | } |
| 862 | |
Evan Cheng | 06b666c | 2010-05-15 02:18:07 +0000 | [diff] [blame] | 863 | /// getRegClassFor - Return the register class that should be used for the |
| 864 | /// specified value type. |
| 865 | TargetRegisterClass *ARMTargetLowering::getRegClassFor(EVT VT) const { |
| 866 | // Map v4i64 to QQ registers but do not make the type legal. Similarly map |
| 867 | // v8i64 to QQQQ registers. v4i64 and v8i64 are only used for REG_SEQUENCE to |
| 868 | // load / store 4 to 8 consecutive D registers. |
Evan Cheng | 4782b1e | 2010-05-15 02:20:21 +0000 | [diff] [blame] | 869 | if (Subtarget->hasNEON()) { |
| 870 | if (VT == MVT::v4i64) |
| 871 | return ARM::QQPRRegisterClass; |
| 872 | else if (VT == MVT::v8i64) |
| 873 | return ARM::QQQQPRRegisterClass; |
| 874 | } |
Evan Cheng | 06b666c | 2010-05-15 02:18:07 +0000 | [diff] [blame] | 875 | return TargetLowering::getRegClassFor(VT); |
| 876 | } |
| 877 | |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 878 | // Create a fast isel object. |
| 879 | FastISel * |
| 880 | ARMTargetLowering::createFastISel(FunctionLoweringInfo &funcInfo) const { |
| 881 | return ARM::createFastISel(funcInfo); |
| 882 | } |
| 883 | |
Bill Wendling | b4202b8 | 2009-07-01 18:50:55 +0000 | [diff] [blame] | 884 | /// getFunctionAlignment - Return the Log2 alignment of this function. |
Bill Wendling | 20c568f | 2009-06-30 22:38:32 +0000 | [diff] [blame] | 885 | unsigned ARMTargetLowering::getFunctionAlignment(const Function *F) const { |
Bob Wilson | b5b5057 | 2010-07-01 22:26:26 +0000 | [diff] [blame] | 886 | return getTargetMachine().getSubtarget<ARMSubtarget>().isThumb() ? 1 : 2; |
Bill Wendling | 20c568f | 2009-06-30 22:38:32 +0000 | [diff] [blame] | 887 | } |
| 888 | |
Anton Korobeynikov | cec36f4 | 2010-07-24 21:52:08 +0000 | [diff] [blame] | 889 | /// getMaximalGlobalOffset - Returns the maximal possible offset which can |
| 890 | /// be used for loads / stores from the global. |
| 891 | unsigned ARMTargetLowering::getMaximalGlobalOffset() const { |
| 892 | return (Subtarget->isThumb1Only() ? 127 : 4095); |
| 893 | } |
| 894 | |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 895 | Sched::Preference ARMTargetLowering::getSchedulingPreference(SDNode *N) const { |
Evan Cheng | c10f543 | 2010-05-28 23:25:23 +0000 | [diff] [blame] | 896 | unsigned NumVals = N->getNumValues(); |
| 897 | if (!NumVals) |
| 898 | return Sched::RegPressure; |
| 899 | |
| 900 | for (unsigned i = 0; i != NumVals; ++i) { |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 901 | EVT VT = N->getValueType(i); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 902 | if (VT == MVT::Glue || VT == MVT::Other) |
Evan Cheng | d7e473c | 2010-10-29 18:07:31 +0000 | [diff] [blame] | 903 | continue; |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 904 | if (VT.isFloatingPoint() || VT.isVector()) |
| 905 | return Sched::Latency; |
| 906 | } |
Evan Cheng | c10f543 | 2010-05-28 23:25:23 +0000 | [diff] [blame] | 907 | |
| 908 | if (!N->isMachineOpcode()) |
| 909 | return Sched::RegPressure; |
| 910 | |
| 911 | // Load are scheduled for latency even if there instruction itinerary |
| 912 | // is not available. |
| 913 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 914 | const TargetInstrDesc &TID = TII->get(N->getMachineOpcode()); |
Evan Cheng | d7e473c | 2010-10-29 18:07:31 +0000 | [diff] [blame] | 915 | |
| 916 | if (TID.getNumDefs() == 0) |
| 917 | return Sched::RegPressure; |
| 918 | if (!Itins->isEmpty() && |
| 919 | Itins->getOperandCycle(TID.getSchedClass(), 0) > 2) |
Evan Cheng | c10f543 | 2010-05-28 23:25:23 +0000 | [diff] [blame] | 920 | return Sched::Latency; |
| 921 | |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 922 | return Sched::RegPressure; |
| 923 | } |
| 924 | |
Anton Korobeynikov | 16c29b5 | 2011-01-10 12:39:04 +0000 | [diff] [blame] | 925 | // FIXME: Move to RegInfo |
Evan Cheng | 3144687 | 2010-07-23 22:39:59 +0000 | [diff] [blame] | 926 | unsigned |
| 927 | ARMTargetLowering::getRegPressureLimit(const TargetRegisterClass *RC, |
| 928 | MachineFunction &MF) const { |
Anton Korobeynikov | 16c29b5 | 2011-01-10 12:39:04 +0000 | [diff] [blame] | 929 | const TargetFrameLowering *TFI = MF.getTarget().getFrameLowering(); |
Anton Korobeynikov | d0c3817 | 2010-11-18 21:19:35 +0000 | [diff] [blame] | 930 | |
Evan Cheng | 3144687 | 2010-07-23 22:39:59 +0000 | [diff] [blame] | 931 | switch (RC->getID()) { |
| 932 | default: |
| 933 | return 0; |
| 934 | case ARM::tGPRRegClassID: |
Anton Korobeynikov | d0c3817 | 2010-11-18 21:19:35 +0000 | [diff] [blame] | 935 | return TFI->hasFP(MF) ? 4 : 5; |
Evan Cheng | ac09680 | 2010-08-10 19:30:19 +0000 | [diff] [blame] | 936 | case ARM::GPRRegClassID: { |
Anton Korobeynikov | d0c3817 | 2010-11-18 21:19:35 +0000 | [diff] [blame] | 937 | unsigned FP = TFI->hasFP(MF) ? 1 : 0; |
Evan Cheng | ac09680 | 2010-08-10 19:30:19 +0000 | [diff] [blame] | 938 | return 10 - FP - (Subtarget->isR9Reserved() ? 1 : 0); |
| 939 | } |
Evan Cheng | 3144687 | 2010-07-23 22:39:59 +0000 | [diff] [blame] | 940 | case ARM::SPRRegClassID: // Currently not used as 'rep' register class. |
| 941 | case ARM::DPRRegClassID: |
| 942 | return 32 - 10; |
| 943 | } |
| 944 | } |
| 945 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 946 | //===----------------------------------------------------------------------===// |
| 947 | // Lowering Code |
| 948 | //===----------------------------------------------------------------------===// |
| 949 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 950 | /// IntCCToARMCC - Convert a DAG integer condition code to an ARM CC |
| 951 | static ARMCC::CondCodes IntCCToARMCC(ISD::CondCode CC) { |
| 952 | switch (CC) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 953 | default: llvm_unreachable("Unknown condition code!"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 954 | case ISD::SETNE: return ARMCC::NE; |
| 955 | case ISD::SETEQ: return ARMCC::EQ; |
| 956 | case ISD::SETGT: return ARMCC::GT; |
| 957 | case ISD::SETGE: return ARMCC::GE; |
| 958 | case ISD::SETLT: return ARMCC::LT; |
| 959 | case ISD::SETLE: return ARMCC::LE; |
| 960 | case ISD::SETUGT: return ARMCC::HI; |
| 961 | case ISD::SETUGE: return ARMCC::HS; |
| 962 | case ISD::SETULT: return ARMCC::LO; |
| 963 | case ISD::SETULE: return ARMCC::LS; |
| 964 | } |
| 965 | } |
| 966 | |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 967 | /// FPCCToARMCC - Convert a DAG fp condition code to an ARM CC. |
| 968 | static void FPCCToARMCC(ISD::CondCode CC, ARMCC::CondCodes &CondCode, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 969 | ARMCC::CondCodes &CondCode2) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 970 | CondCode2 = ARMCC::AL; |
| 971 | switch (CC) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 972 | default: llvm_unreachable("Unknown FP condition!"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 973 | case ISD::SETEQ: |
| 974 | case ISD::SETOEQ: CondCode = ARMCC::EQ; break; |
| 975 | case ISD::SETGT: |
| 976 | case ISD::SETOGT: CondCode = ARMCC::GT; break; |
| 977 | case ISD::SETGE: |
| 978 | case ISD::SETOGE: CondCode = ARMCC::GE; break; |
| 979 | case ISD::SETOLT: CondCode = ARMCC::MI; break; |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 980 | case ISD::SETOLE: CondCode = ARMCC::LS; break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 981 | case ISD::SETONE: CondCode = ARMCC::MI; CondCode2 = ARMCC::GT; break; |
| 982 | case ISD::SETO: CondCode = ARMCC::VC; break; |
| 983 | case ISD::SETUO: CondCode = ARMCC::VS; break; |
| 984 | case ISD::SETUEQ: CondCode = ARMCC::EQ; CondCode2 = ARMCC::VS; break; |
| 985 | case ISD::SETUGT: CondCode = ARMCC::HI; break; |
| 986 | case ISD::SETUGE: CondCode = ARMCC::PL; break; |
| 987 | case ISD::SETLT: |
| 988 | case ISD::SETULT: CondCode = ARMCC::LT; break; |
| 989 | case ISD::SETLE: |
| 990 | case ISD::SETULE: CondCode = ARMCC::LE; break; |
| 991 | case ISD::SETNE: |
| 992 | case ISD::SETUNE: CondCode = ARMCC::NE; break; |
| 993 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 994 | } |
| 995 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 996 | //===----------------------------------------------------------------------===// |
| 997 | // Calling Convention Implementation |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 998 | //===----------------------------------------------------------------------===// |
| 999 | |
| 1000 | #include "ARMGenCallingConv.inc" |
| 1001 | |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1002 | /// CCAssignFnForNode - Selects the correct CCAssignFn for a the |
| 1003 | /// given CallingConvention value. |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1004 | CCAssignFn *ARMTargetLowering::CCAssignFnForNode(CallingConv::ID CC, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1005 | bool Return, |
| 1006 | bool isVarArg) const { |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1007 | switch (CC) { |
| 1008 | default: |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1009 | llvm_unreachable("Unsupported calling convention"); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1010 | case CallingConv::Fast: |
Evan Cheng | 5c2d428 | 2010-10-23 02:19:37 +0000 | [diff] [blame] | 1011 | if (Subtarget->hasVFP2() && !isVarArg) { |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1012 | if (!Subtarget->isAAPCS_ABI()) |
| 1013 | return (Return ? RetFastCC_ARM_APCS : FastCC_ARM_APCS); |
| 1014 | // For AAPCS ABI targets, just use VFP variant of the calling convention. |
| 1015 | return (Return ? RetCC_ARM_AAPCS_VFP : CC_ARM_AAPCS_VFP); |
| 1016 | } |
| 1017 | // Fallthrough |
| 1018 | case CallingConv::C: { |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1019 | // Use target triple & subtarget features to do actual dispatch. |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1020 | if (!Subtarget->isAAPCS_ABI()) |
| 1021 | return (Return ? RetCC_ARM_APCS : CC_ARM_APCS); |
| 1022 | else if (Subtarget->hasVFP2() && |
| 1023 | FloatABIType == FloatABI::Hard && !isVarArg) |
| 1024 | return (Return ? RetCC_ARM_AAPCS_VFP : CC_ARM_AAPCS_VFP); |
| 1025 | return (Return ? RetCC_ARM_AAPCS : CC_ARM_AAPCS); |
| 1026 | } |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1027 | case CallingConv::ARM_AAPCS_VFP: |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1028 | return (Return ? RetCC_ARM_AAPCS_VFP : CC_ARM_AAPCS_VFP); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1029 | case CallingConv::ARM_AAPCS: |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1030 | return (Return ? RetCC_ARM_AAPCS : CC_ARM_AAPCS); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1031 | case CallingConv::ARM_APCS: |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1032 | return (Return ? RetCC_ARM_APCS : CC_ARM_APCS); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1033 | } |
| 1034 | } |
| 1035 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1036 | /// LowerCallResult - Lower the result values of a call into the |
| 1037 | /// appropriate copies out of appropriate physical registers. |
| 1038 | SDValue |
| 1039 | ARMTargetLowering::LowerCallResult(SDValue Chain, SDValue InFlag, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1040 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1041 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 1042 | DebugLoc dl, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1043 | SmallVectorImpl<SDValue> &InVals) const { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1044 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1045 | // Assign locations to each value returned by this call. |
| 1046 | SmallVector<CCValAssign, 16> RVLocs; |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1047 | CCState CCInfo(CallConv, isVarArg, getTargetMachine(), |
Owen Anderson | e922c02 | 2009-07-22 00:24:57 +0000 | [diff] [blame] | 1048 | RVLocs, *DAG.getContext()); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1049 | CCInfo.AnalyzeCallResult(Ins, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1050 | CCAssignFnForNode(CallConv, /* Return*/ true, |
| 1051 | isVarArg)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1052 | |
| 1053 | // Copy all of the result registers out of their specified physreg. |
| 1054 | for (unsigned i = 0; i != RVLocs.size(); ++i) { |
| 1055 | CCValAssign VA = RVLocs[i]; |
| 1056 | |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1057 | SDValue Val; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1058 | if (VA.needsCustom()) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1059 | // Handle f64 or half of a v2f64. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1060 | SDValue Lo = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1061 | InFlag); |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1062 | Chain = Lo.getValue(1); |
| 1063 | InFlag = Lo.getValue(2); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1064 | VA = RVLocs[++i]; // skip ahead to next loc |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1065 | SDValue Hi = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1066 | InFlag); |
| 1067 | Chain = Hi.getValue(1); |
| 1068 | InFlag = Hi.getValue(2); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1069 | Val = DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1070 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1071 | if (VA.getLocVT() == MVT::v2f64) { |
| 1072 | SDValue Vec = DAG.getNode(ISD::UNDEF, dl, MVT::v2f64); |
| 1073 | Vec = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Vec, Val, |
| 1074 | DAG.getConstant(0, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1075 | |
| 1076 | VA = RVLocs[++i]; // skip ahead to next loc |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1077 | Lo = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, InFlag); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1078 | Chain = Lo.getValue(1); |
| 1079 | InFlag = Lo.getValue(2); |
| 1080 | VA = RVLocs[++i]; // skip ahead to next loc |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1081 | Hi = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, InFlag); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1082 | Chain = Hi.getValue(1); |
| 1083 | InFlag = Hi.getValue(2); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1084 | Val = DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1085 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Vec, Val, |
| 1086 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1087 | } |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1088 | } else { |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1089 | Val = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), VA.getLocVT(), |
| 1090 | InFlag); |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1091 | Chain = Val.getValue(1); |
| 1092 | InFlag = Val.getValue(2); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1093 | } |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1094 | |
| 1095 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1096 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1097 | case CCValAssign::Full: break; |
| 1098 | case CCValAssign::BCvt: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1099 | Val = DAG.getNode(ISD::BITCAST, dl, VA.getValVT(), Val); |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1100 | break; |
| 1101 | } |
| 1102 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1103 | InVals.push_back(Val); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1104 | } |
| 1105 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1106 | return Chain; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1107 | } |
| 1108 | |
| 1109 | /// CreateCopyOfByValArgument - Make a copy of an aggregate at address specified |
| 1110 | /// by "Src" to address "Dst" of size "Size". Alignment information is |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1111 | /// specified by the specific parameter attribute. The copy will be passed as |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1112 | /// a byval function parameter. |
| 1113 | /// Sometimes what we are copying is the end of a larger object, the part that |
| 1114 | /// does not fit in registers. |
| 1115 | static SDValue |
| 1116 | CreateCopyOfByValArgument(SDValue Src, SDValue Dst, SDValue Chain, |
| 1117 | ISD::ArgFlagsTy Flags, SelectionDAG &DAG, |
| 1118 | DebugLoc dl) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1119 | SDValue SizeNode = DAG.getConstant(Flags.getByValSize(), MVT::i32); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1120 | return DAG.getMemcpy(Chain, dl, Dst, Src, SizeNode, Flags.getByValAlign(), |
Mon P Wang | 20adc9d | 2010-04-04 03:10:48 +0000 | [diff] [blame] | 1121 | /*isVolatile=*/false, /*AlwaysInline=*/false, |
Chris Lattner | e72f202 | 2010-09-21 05:40:29 +0000 | [diff] [blame] | 1122 | MachinePointerInfo(0), MachinePointerInfo(0)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1123 | } |
| 1124 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1125 | /// LowerMemOpCallTo - Store the argument to the stack. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1126 | SDValue |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1127 | ARMTargetLowering::LowerMemOpCallTo(SDValue Chain, |
| 1128 | SDValue StackPtr, SDValue Arg, |
| 1129 | DebugLoc dl, SelectionDAG &DAG, |
| 1130 | const CCValAssign &VA, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1131 | ISD::ArgFlagsTy Flags) const { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1132 | unsigned LocMemOffset = VA.getLocMemOffset(); |
| 1133 | SDValue PtrOff = DAG.getIntPtrConstant(LocMemOffset); |
| 1134 | PtrOff = DAG.getNode(ISD::ADD, dl, getPointerTy(), StackPtr, PtrOff); |
Chris Lattner | fc448ff | 2010-09-21 18:51:21 +0000 | [diff] [blame] | 1135 | if (Flags.isByVal()) |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1136 | return CreateCopyOfByValArgument(Arg, PtrOff, Chain, Flags, DAG, dl); |
Chris Lattner | fc448ff | 2010-09-21 18:51:21 +0000 | [diff] [blame] | 1137 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1138 | return DAG.getStore(Chain, dl, Arg, PtrOff, |
Chris Lattner | fc448ff | 2010-09-21 18:51:21 +0000 | [diff] [blame] | 1139 | MachinePointerInfo::getStack(LocMemOffset), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1140 | false, false, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1141 | } |
| 1142 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1143 | void ARMTargetLowering::PassF64ArgInRegs(DebugLoc dl, SelectionDAG &DAG, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1144 | SDValue Chain, SDValue &Arg, |
| 1145 | RegsToPassVector &RegsToPass, |
| 1146 | CCValAssign &VA, CCValAssign &NextVA, |
| 1147 | SDValue &StackPtr, |
| 1148 | SmallVector<SDValue, 8> &MemOpChains, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1149 | ISD::ArgFlagsTy Flags) const { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1150 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1151 | SDValue fmrrd = DAG.getNode(ARMISD::VMOVRRD, dl, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1152 | DAG.getVTList(MVT::i32, MVT::i32), Arg); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1153 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), fmrrd)); |
| 1154 | |
| 1155 | if (NextVA.isRegLoc()) |
| 1156 | RegsToPass.push_back(std::make_pair(NextVA.getLocReg(), fmrrd.getValue(1))); |
| 1157 | else { |
| 1158 | assert(NextVA.isMemLoc()); |
| 1159 | if (StackPtr.getNode() == 0) |
| 1160 | StackPtr = DAG.getCopyFromReg(Chain, dl, ARM::SP, getPointerTy()); |
| 1161 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1162 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, fmrrd.getValue(1), |
| 1163 | dl, DAG, NextVA, |
| 1164 | Flags)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1165 | } |
| 1166 | } |
| 1167 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1168 | /// LowerCall - Lowering a call into a callseq_start <- |
Evan Cheng | fc40342 | 2007-02-03 08:53:01 +0000 | [diff] [blame] | 1169 | /// ARMISD:CALL <- callseq_end chain. Also add input and output parameter |
| 1170 | /// nodes. |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1171 | SDValue |
Evan Cheng | 022d9e1 | 2010-02-02 23:55:14 +0000 | [diff] [blame] | 1172 | ARMTargetLowering::LowerCall(SDValue Chain, SDValue Callee, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1173 | CallingConv::ID CallConv, bool isVarArg, |
Evan Cheng | 0c439eb | 2010-01-27 00:07:07 +0000 | [diff] [blame] | 1174 | bool &isTailCall, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1175 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1176 | const SmallVectorImpl<SDValue> &OutVals, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1177 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 1178 | DebugLoc dl, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1179 | SmallVectorImpl<SDValue> &InVals) const { |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1180 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1181 | bool IsStructRet = (Outs.empty()) ? false : Outs[0].Flags.isSRet(); |
| 1182 | bool IsSibCall = false; |
Bob Wilson | 703af3a | 2010-08-13 22:43:33 +0000 | [diff] [blame] | 1183 | // Temporarily disable tail calls so things don't break. |
| 1184 | if (!EnableARMTailCalls) |
| 1185 | isTailCall = false; |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1186 | if (isTailCall) { |
| 1187 | // Check if it's really possible to do a tail call. |
| 1188 | isTailCall = IsEligibleForTailCallOptimization(Callee, CallConv, |
| 1189 | isVarArg, IsStructRet, MF.getFunction()->hasStructRetAttr(), |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1190 | Outs, OutVals, Ins, DAG); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1191 | // We don't support GuaranteedTailCallOpt for ARM, only automatically |
| 1192 | // detected sibcalls. |
| 1193 | if (isTailCall) { |
| 1194 | ++NumTailCalls; |
| 1195 | IsSibCall = true; |
| 1196 | } |
| 1197 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1198 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1199 | // Analyze operands of the call, assigning locations to each operand. |
| 1200 | SmallVector<CCValAssign, 16> ArgLocs; |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1201 | CCState CCInfo(CallConv, isVarArg, getTargetMachine(), ArgLocs, |
| 1202 | *DAG.getContext()); |
| 1203 | CCInfo.AnalyzeCallOperands(Outs, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1204 | CCAssignFnForNode(CallConv, /* Return*/ false, |
| 1205 | isVarArg)); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1206 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1207 | // Get a count of how many bytes are to be pushed on the stack. |
| 1208 | unsigned NumBytes = CCInfo.getNextStackOffset(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1209 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1210 | // For tail calls, memory operands are available in our caller's stack. |
| 1211 | if (IsSibCall) |
| 1212 | NumBytes = 0; |
| 1213 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1214 | // Adjust the stack pointer for the new arguments... |
| 1215 | // These operations are automatically eliminated by the prolog/epilog pass |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1216 | if (!IsSibCall) |
| 1217 | Chain = DAG.getCALLSEQ_START(Chain, DAG.getIntPtrConstant(NumBytes, true)); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1218 | |
Jim Grosbach | f9a4b76 | 2010-02-24 01:43:03 +0000 | [diff] [blame] | 1219 | SDValue StackPtr = DAG.getCopyFromReg(Chain, dl, ARM::SP, getPointerTy()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1220 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1221 | RegsToPassVector RegsToPass; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1222 | SmallVector<SDValue, 8> MemOpChains; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1223 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1224 | // Walk the register/memloc assignments, inserting copies/loads. In the case |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1225 | // of tail call optimization, arguments are handled later. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1226 | for (unsigned i = 0, realArgIdx = 0, e = ArgLocs.size(); |
| 1227 | i != e; |
| 1228 | ++i, ++realArgIdx) { |
| 1229 | CCValAssign &VA = ArgLocs[i]; |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1230 | SDValue Arg = OutVals[realArgIdx]; |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1231 | ISD::ArgFlagsTy Flags = Outs[realArgIdx].Flags; |
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 | // Promote the value if needed. |
| 1234 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1235 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1236 | case CCValAssign::Full: break; |
| 1237 | case CCValAssign::SExt: |
| 1238 | Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg); |
| 1239 | break; |
| 1240 | case CCValAssign::ZExt: |
| 1241 | Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg); |
| 1242 | break; |
| 1243 | case CCValAssign::AExt: |
| 1244 | Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg); |
| 1245 | break; |
| 1246 | case CCValAssign::BCvt: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1247 | Arg = DAG.getNode(ISD::BITCAST, dl, VA.getLocVT(), Arg); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1248 | break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1249 | } |
| 1250 | |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1251 | // 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] | 1252 | if (VA.needsCustom()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1253 | if (VA.getLocVT() == MVT::v2f64) { |
| 1254 | SDValue Op0 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1255 | DAG.getConstant(0, MVT::i32)); |
| 1256 | SDValue Op1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1257 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1258 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1259 | PassF64ArgInRegs(dl, DAG, Chain, Op0, RegsToPass, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1260 | VA, ArgLocs[++i], StackPtr, MemOpChains, Flags); |
| 1261 | |
| 1262 | VA = ArgLocs[++i]; // skip ahead to next loc |
| 1263 | if (VA.isRegLoc()) { |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1264 | PassF64ArgInRegs(dl, DAG, Chain, Op1, RegsToPass, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1265 | VA, ArgLocs[++i], StackPtr, MemOpChains, Flags); |
| 1266 | } else { |
| 1267 | assert(VA.isMemLoc()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1268 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1269 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, Op1, |
| 1270 | dl, DAG, VA, Flags)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1271 | } |
| 1272 | } else { |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1273 | PassF64ArgInRegs(dl, DAG, Chain, Arg, RegsToPass, VA, ArgLocs[++i], |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1274 | StackPtr, MemOpChains, Flags); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1275 | } |
| 1276 | } else if (VA.isRegLoc()) { |
| 1277 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg)); |
Dale Johannesen | df50d7e | 2010-06-18 18:13:11 +0000 | [diff] [blame] | 1278 | } else if (!IsSibCall) { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1279 | assert(VA.isMemLoc()); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1280 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1281 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, Arg, |
| 1282 | dl, DAG, VA, Flags)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1283 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1284 | } |
| 1285 | |
| 1286 | if (!MemOpChains.empty()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1287 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1288 | &MemOpChains[0], MemOpChains.size()); |
| 1289 | |
| 1290 | // Build a sequence of copy-to-reg nodes chained together with token chain |
| 1291 | // and flag operands which copy the outgoing args into the appropriate regs. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1292 | SDValue InFlag; |
Dale Johannesen | 6470a11 | 2010-06-15 22:08:33 +0000 | [diff] [blame] | 1293 | // Tail call byval lowering might overwrite argument registers so in case of |
| 1294 | // tail call optimization the copies to registers are lowered later. |
| 1295 | if (!isTailCall) |
| 1296 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 1297 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, |
| 1298 | RegsToPass[i].second, InFlag); |
| 1299 | InFlag = Chain.getValue(1); |
| 1300 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1301 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1302 | // For tail calls lower the arguments to the 'real' stack slot. |
| 1303 | if (isTailCall) { |
| 1304 | // Force all the incoming stack arguments to be loaded from the stack |
| 1305 | // before any new outgoing arguments are stored to the stack, because the |
| 1306 | // outgoing stack slots may alias the incoming argument stack slots, and |
| 1307 | // the alias isn't otherwise explicit. This is slightly more conservative |
| 1308 | // than necessary, because it means that each store effectively depends |
| 1309 | // on every argument instead of just those arguments it would clobber. |
| 1310 | |
| 1311 | // Do not flag preceeding copytoreg stuff together with the following stuff. |
| 1312 | InFlag = SDValue(); |
| 1313 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 1314 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, |
| 1315 | RegsToPass[i].second, InFlag); |
| 1316 | InFlag = Chain.getValue(1); |
| 1317 | } |
| 1318 | InFlag =SDValue(); |
| 1319 | } |
| 1320 | |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1321 | // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every |
| 1322 | // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol |
| 1323 | // node so that legalize doesn't hack it. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1324 | bool isDirect = false; |
| 1325 | bool isARMFunc = false; |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 1326 | bool isLocalARMFunc = false; |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1327 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1328 | |
| 1329 | if (EnableARMLongCalls) { |
| 1330 | assert (getTargetMachine().getRelocationModel() == Reloc::Static |
| 1331 | && "long-calls with non-static relocation model!"); |
| 1332 | // Handle a global address or an external symbol. If it's not one of |
| 1333 | // those, the target's already in a register, so we don't need to do |
| 1334 | // anything extra. |
| 1335 | if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
Anders Carlsson | 0dbdca5 | 2010-04-15 03:11:28 +0000 | [diff] [blame] | 1336 | const GlobalValue *GV = G->getGlobal(); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1337 | // Create a constant pool entry for the callee address |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1338 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1339 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GV, |
| 1340 | ARMPCLabelIndex, |
| 1341 | ARMCP::CPValue, 0); |
| 1342 | // Get the address of the callee into a register |
| 1343 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
| 1344 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| 1345 | Callee = DAG.getLoad(getPointerTy(), dl, |
| 1346 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1347 | MachinePointerInfo::getConstantPool(), |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1348 | false, false, 0); |
| 1349 | } else if (ExternalSymbolSDNode *S=dyn_cast<ExternalSymbolSDNode>(Callee)) { |
| 1350 | const char *Sym = S->getSymbol(); |
| 1351 | |
| 1352 | // Create a constant pool entry for the callee address |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1353 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1354 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(*DAG.getContext(), |
| 1355 | Sym, ARMPCLabelIndex, 0); |
| 1356 | // Get the address of the callee into a register |
| 1357 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
| 1358 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| 1359 | Callee = DAG.getLoad(getPointerTy(), dl, |
| 1360 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1361 | MachinePointerInfo::getConstantPool(), |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1362 | false, false, 0); |
| 1363 | } |
| 1364 | } else if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 1365 | const GlobalValue *GV = G->getGlobal(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1366 | isDirect = true; |
Chris Lattner | 4fb63d0 | 2009-07-15 04:12:33 +0000 | [diff] [blame] | 1367 | bool isExt = GV->isDeclaration() || GV->isWeakForLinker(); |
Evan Cheng | 970a419 | 2007-01-19 19:28:01 +0000 | [diff] [blame] | 1368 | bool isStub = (isExt && Subtarget->isTargetDarwin()) && |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1369 | getTargetMachine().getRelocationModel() != Reloc::Static; |
| 1370 | isARMFunc = !Subtarget->isThumb() || isStub; |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 1371 | // ARM call to a local ARM function is predicable. |
Evan Cheng | 46df4eb | 2010-06-16 07:35:02 +0000 | [diff] [blame] | 1372 | isLocalARMFunc = !Subtarget->isThumb() && (!isExt || !ARMInterworking); |
Evan Cheng | c60e76d | 2007-01-30 20:37:08 +0000 | [diff] [blame] | 1373 | // tBX takes a register source operand. |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 1374 | if (isARMFunc && Subtarget->isThumb1Only() && !Subtarget->hasV5TOps()) { |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1375 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 1376 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GV, |
Jim Grosbach | 3fb2b1e | 2009-09-01 01:57:56 +0000 | [diff] [blame] | 1377 | ARMPCLabelIndex, |
| 1378 | ARMCP::CPValue, 4); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1379 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1380 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1381 | Callee = DAG.getLoad(getPointerTy(), dl, |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1382 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1383 | MachinePointerInfo::getConstantPool(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1384 | false, false, 0); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1385 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1386 | Callee = DAG.getNode(ARMISD::PIC_ADD, dl, |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1387 | getPointerTy(), Callee, PICLabel); |
Jim Grosbach | 637d89f | 2010-09-22 23:27:36 +0000 | [diff] [blame] | 1388 | } else { |
| 1389 | // On ELF targets for PIC code, direct calls should go through the PLT |
| 1390 | unsigned OpFlags = 0; |
| 1391 | if (Subtarget->isTargetELF() && |
| 1392 | getTargetMachine().getRelocationModel() == Reloc::PIC_) |
| 1393 | OpFlags = ARMII::MO_PLT; |
| 1394 | Callee = DAG.getTargetGlobalAddress(GV, dl, getPointerTy(), 0, OpFlags); |
| 1395 | } |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1396 | } else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1397 | isDirect = true; |
Evan Cheng | 970a419 | 2007-01-19 19:28:01 +0000 | [diff] [blame] | 1398 | bool isStub = Subtarget->isTargetDarwin() && |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1399 | getTargetMachine().getRelocationModel() != Reloc::Static; |
| 1400 | isARMFunc = !Subtarget->isThumb() || isStub; |
Evan Cheng | c60e76d | 2007-01-30 20:37:08 +0000 | [diff] [blame] | 1401 | // tBX takes a register source operand. |
| 1402 | const char *Sym = S->getSymbol(); |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 1403 | if (isARMFunc && Subtarget->isThumb1Only() && !Subtarget->hasV5TOps()) { |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1404 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 1405 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(*DAG.getContext(), |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 1406 | Sym, ARMPCLabelIndex, 4); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1407 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1408 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1409 | Callee = DAG.getLoad(getPointerTy(), dl, |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1410 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1411 | MachinePointerInfo::getConstantPool(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1412 | false, false, 0); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1413 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1414 | Callee = DAG.getNode(ARMISD::PIC_ADD, dl, |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1415 | getPointerTy(), Callee, PICLabel); |
Jim Grosbach | 637d89f | 2010-09-22 23:27:36 +0000 | [diff] [blame] | 1416 | } else { |
| 1417 | unsigned OpFlags = 0; |
| 1418 | // On ELF targets for PIC code, direct calls should go through the PLT |
| 1419 | if (Subtarget->isTargetELF() && |
| 1420 | getTargetMachine().getRelocationModel() == Reloc::PIC_) |
| 1421 | OpFlags = ARMII::MO_PLT; |
| 1422 | Callee = DAG.getTargetExternalSymbol(Sym, getPointerTy(), OpFlags); |
| 1423 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1424 | } |
| 1425 | |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1426 | // FIXME: handle tail calls differently. |
| 1427 | unsigned CallOpc; |
Evan Cheng | b620724 | 2009-08-01 00:16:10 +0000 | [diff] [blame] | 1428 | if (Subtarget->isThumb()) { |
| 1429 | if ((!isDirect || isARMFunc) && !Subtarget->hasV5TOps()) |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1430 | CallOpc = ARMISD::CALL_NOLINK; |
| 1431 | else |
| 1432 | CallOpc = isARMFunc ? ARMISD::CALL : ARMISD::tCALL; |
| 1433 | } else { |
| 1434 | CallOpc = (isDirect || Subtarget->hasV5TOps()) |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 1435 | ? (isLocalARMFunc ? ARMISD::CALL_PRED : ARMISD::CALL) |
| 1436 | : ARMISD::CALL_NOLINK; |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1437 | } |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1438 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1439 | std::vector<SDValue> Ops; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1440 | Ops.push_back(Chain); |
| 1441 | Ops.push_back(Callee); |
| 1442 | |
| 1443 | // Add argument registers to the end of the list so that they are known live |
| 1444 | // into the call. |
| 1445 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) |
| 1446 | Ops.push_back(DAG.getRegister(RegsToPass[i].first, |
| 1447 | RegsToPass[i].second.getValueType())); |
| 1448 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1449 | if (InFlag.getNode()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1450 | Ops.push_back(InFlag); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1451 | |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 1452 | SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue); |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1453 | if (isTailCall) |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1454 | return DAG.getNode(ARMISD::TC_RETURN, dl, NodeTys, &Ops[0], Ops.size()); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1455 | |
Duncan Sands | 4bdcb61 | 2008-07-02 17:40:58 +0000 | [diff] [blame] | 1456 | // Returns a chain and a flag for retval copy to use. |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1457 | Chain = DAG.getNode(CallOpc, dl, NodeTys, &Ops[0], Ops.size()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1458 | InFlag = Chain.getValue(1); |
| 1459 | |
Chris Lattner | e563bbc | 2008-10-11 22:08:30 +0000 | [diff] [blame] | 1460 | Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(NumBytes, true), |
| 1461 | DAG.getIntPtrConstant(0, true), InFlag); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1462 | if (!Ins.empty()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1463 | InFlag = Chain.getValue(1); |
| 1464 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1465 | // Handle result values, copying them out of physregs into vregs that we |
| 1466 | // return. |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1467 | return LowerCallResult(Chain, InFlag, CallConv, isVarArg, Ins, |
| 1468 | dl, DAG, InVals); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1469 | } |
| 1470 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1471 | /// MatchingStackOffset - Return true if the given stack call argument is |
| 1472 | /// already available in the same position (relatively) of the caller's |
| 1473 | /// incoming argument stack. |
| 1474 | static |
| 1475 | bool MatchingStackOffset(SDValue Arg, unsigned Offset, ISD::ArgFlagsTy Flags, |
| 1476 | MachineFrameInfo *MFI, const MachineRegisterInfo *MRI, |
| 1477 | const ARMInstrInfo *TII) { |
| 1478 | unsigned Bytes = Arg.getValueType().getSizeInBits() / 8; |
| 1479 | int FI = INT_MAX; |
| 1480 | if (Arg.getOpcode() == ISD::CopyFromReg) { |
| 1481 | unsigned VR = cast<RegisterSDNode>(Arg.getOperand(1))->getReg(); |
Jakob Stoklund Olesen | c9df025 | 2011-01-10 02:58:51 +0000 | [diff] [blame] | 1482 | if (!TargetRegisterInfo::isVirtualRegister(VR)) |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1483 | return false; |
| 1484 | MachineInstr *Def = MRI->getVRegDef(VR); |
| 1485 | if (!Def) |
| 1486 | return false; |
| 1487 | if (!Flags.isByVal()) { |
| 1488 | if (!TII->isLoadFromStackSlot(Def, FI)) |
| 1489 | return false; |
| 1490 | } else { |
Dale Johannesen | 7835f1f | 2010-07-08 01:18:23 +0000 | [diff] [blame] | 1491 | return false; |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1492 | } |
| 1493 | } else if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Arg)) { |
| 1494 | if (Flags.isByVal()) |
| 1495 | // ByVal argument is passed in as a pointer but it's now being |
| 1496 | // dereferenced. e.g. |
| 1497 | // define @foo(%struct.X* %A) { |
| 1498 | // tail call @bar(%struct.X* byval %A) |
| 1499 | // } |
| 1500 | return false; |
| 1501 | SDValue Ptr = Ld->getBasePtr(); |
| 1502 | FrameIndexSDNode *FINode = dyn_cast<FrameIndexSDNode>(Ptr); |
| 1503 | if (!FINode) |
| 1504 | return false; |
| 1505 | FI = FINode->getIndex(); |
| 1506 | } else |
| 1507 | return false; |
| 1508 | |
| 1509 | assert(FI != INT_MAX); |
| 1510 | if (!MFI->isFixedObjectIndex(FI)) |
| 1511 | return false; |
| 1512 | return Offset == MFI->getObjectOffset(FI) && Bytes == MFI->getObjectSize(FI); |
| 1513 | } |
| 1514 | |
| 1515 | /// IsEligibleForTailCallOptimization - Check whether the call is eligible |
| 1516 | /// for tail call optimization. Targets which want to do tail call |
| 1517 | /// optimization should implement this function. |
| 1518 | bool |
| 1519 | ARMTargetLowering::IsEligibleForTailCallOptimization(SDValue Callee, |
| 1520 | CallingConv::ID CalleeCC, |
| 1521 | bool isVarArg, |
| 1522 | bool isCalleeStructRet, |
| 1523 | bool isCallerStructRet, |
| 1524 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1525 | const SmallVectorImpl<SDValue> &OutVals, |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1526 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 1527 | SelectionDAG& DAG) const { |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1528 | const Function *CallerF = DAG.getMachineFunction().getFunction(); |
| 1529 | CallingConv::ID CallerCC = CallerF->getCallingConv(); |
| 1530 | bool CCMatch = CallerCC == CalleeCC; |
| 1531 | |
| 1532 | // Look for obvious safe cases to perform tail call optimization that do not |
| 1533 | // require ABI changes. This is what gcc calls sibcall. |
| 1534 | |
Jim Grosbach | 7616b64 | 2010-06-16 23:45:49 +0000 | [diff] [blame] | 1535 | // Do not sibcall optimize vararg calls unless the call site is not passing |
| 1536 | // any arguments. |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1537 | if (isVarArg && !Outs.empty()) |
| 1538 | return false; |
| 1539 | |
| 1540 | // Also avoid sibcall optimization if either caller or callee uses struct |
| 1541 | // return semantics. |
| 1542 | if (isCalleeStructRet || isCallerStructRet) |
| 1543 | return false; |
| 1544 | |
Dale Johannesen | e39fdbe | 2010-06-23 18:52:34 +0000 | [diff] [blame] | 1545 | // FIXME: Completely disable sibcall for Thumb1 since Thumb1RegisterInfo:: |
Evan Cheng | 0110ac6 | 2010-06-19 01:01:32 +0000 | [diff] [blame] | 1546 | // emitEpilogue is not ready for them. |
Dale Johannesen | 7835f1f | 2010-07-08 01:18:23 +0000 | [diff] [blame] | 1547 | // Doing this is tricky, since the LDM/POP instruction on Thumb doesn't take |
| 1548 | // LR. This means if we need to reload LR, it takes an extra instructions, |
| 1549 | // which outweighs the value of the tail call; but here we don't know yet |
| 1550 | // 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] | 1551 | // 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] | 1552 | // emitEpilogue if LR is used. |
Dale Johannesen | 7835f1f | 2010-07-08 01:18:23 +0000 | [diff] [blame] | 1553 | |
| 1554 | // Thumb1 PIC calls to external symbols use BX, so they can be tail calls, |
| 1555 | // but we need to make sure there are enough registers; the only valid |
| 1556 | // registers are the 4 used for parameters. We don't currently do this |
| 1557 | // case. |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1558 | if (Subtarget->isThumb1Only()) |
| 1559 | return false; |
Dale Johannesen | df50d7e | 2010-06-18 18:13:11 +0000 | [diff] [blame] | 1560 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1561 | // If the calling conventions do not match, then we'd better make sure the |
| 1562 | // results are returned in the same way as what the caller expects. |
| 1563 | if (!CCMatch) { |
| 1564 | SmallVector<CCValAssign, 16> RVLocs1; |
| 1565 | CCState CCInfo1(CalleeCC, false, getTargetMachine(), |
| 1566 | RVLocs1, *DAG.getContext()); |
| 1567 | CCInfo1.AnalyzeCallResult(Ins, CCAssignFnForNode(CalleeCC, true, isVarArg)); |
| 1568 | |
| 1569 | SmallVector<CCValAssign, 16> RVLocs2; |
| 1570 | CCState CCInfo2(CallerCC, false, getTargetMachine(), |
| 1571 | RVLocs2, *DAG.getContext()); |
| 1572 | CCInfo2.AnalyzeCallResult(Ins, CCAssignFnForNode(CallerCC, true, isVarArg)); |
| 1573 | |
| 1574 | if (RVLocs1.size() != RVLocs2.size()) |
| 1575 | return false; |
| 1576 | for (unsigned i = 0, e = RVLocs1.size(); i != e; ++i) { |
| 1577 | if (RVLocs1[i].isRegLoc() != RVLocs2[i].isRegLoc()) |
| 1578 | return false; |
| 1579 | if (RVLocs1[i].getLocInfo() != RVLocs2[i].getLocInfo()) |
| 1580 | return false; |
| 1581 | if (RVLocs1[i].isRegLoc()) { |
| 1582 | if (RVLocs1[i].getLocReg() != RVLocs2[i].getLocReg()) |
| 1583 | return false; |
| 1584 | } else { |
| 1585 | if (RVLocs1[i].getLocMemOffset() != RVLocs2[i].getLocMemOffset()) |
| 1586 | return false; |
| 1587 | } |
| 1588 | } |
| 1589 | } |
| 1590 | |
| 1591 | // If the callee takes no arguments then go on to check the results of the |
| 1592 | // call. |
| 1593 | if (!Outs.empty()) { |
| 1594 | // Check if stack adjustment is needed. For now, do not do this if any |
| 1595 | // argument is passed on the stack. |
| 1596 | SmallVector<CCValAssign, 16> ArgLocs; |
| 1597 | CCState CCInfo(CalleeCC, isVarArg, getTargetMachine(), |
| 1598 | ArgLocs, *DAG.getContext()); |
| 1599 | CCInfo.AnalyzeCallOperands(Outs, |
| 1600 | CCAssignFnForNode(CalleeCC, false, isVarArg)); |
| 1601 | if (CCInfo.getNextStackOffset()) { |
| 1602 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1603 | |
| 1604 | // Check if the arguments are already laid out in the right way as |
| 1605 | // the caller's fixed stack objects. |
| 1606 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 1607 | const MachineRegisterInfo *MRI = &MF.getRegInfo(); |
| 1608 | const ARMInstrInfo *TII = |
| 1609 | ((ARMTargetMachine&)getTargetMachine()).getInstrInfo(); |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1610 | for (unsigned i = 0, realArgIdx = 0, e = ArgLocs.size(); |
| 1611 | i != e; |
| 1612 | ++i, ++realArgIdx) { |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1613 | CCValAssign &VA = ArgLocs[i]; |
| 1614 | EVT RegVT = VA.getLocVT(); |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1615 | SDValue Arg = OutVals[realArgIdx]; |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1616 | ISD::ArgFlagsTy Flags = Outs[realArgIdx].Flags; |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1617 | if (VA.getLocInfo() == CCValAssign::Indirect) |
| 1618 | return false; |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1619 | if (VA.needsCustom()) { |
| 1620 | // f64 and vector types are split into multiple registers or |
| 1621 | // register/stack-slot combinations. The types will not match |
| 1622 | // the registers; give up on memory f64 refs until we figure |
| 1623 | // out what to do about this. |
| 1624 | if (!VA.isRegLoc()) |
| 1625 | return false; |
| 1626 | if (!ArgLocs[++i].isRegLoc()) |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 1627 | return false; |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1628 | if (RegVT == MVT::v2f64) { |
| 1629 | if (!ArgLocs[++i].isRegLoc()) |
| 1630 | return false; |
| 1631 | if (!ArgLocs[++i].isRegLoc()) |
| 1632 | return false; |
| 1633 | } |
| 1634 | } else if (!VA.isRegLoc()) { |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1635 | if (!MatchingStackOffset(Arg, VA.getLocMemOffset(), Flags, |
| 1636 | MFI, MRI, TII)) |
| 1637 | return false; |
| 1638 | } |
| 1639 | } |
| 1640 | } |
| 1641 | } |
| 1642 | |
| 1643 | return true; |
| 1644 | } |
| 1645 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1646 | SDValue |
| 1647 | ARMTargetLowering::LowerReturn(SDValue Chain, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1648 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1649 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1650 | const SmallVectorImpl<SDValue> &OutVals, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1651 | DebugLoc dl, SelectionDAG &DAG) const { |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1652 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1653 | // CCValAssign - represent the assignment of the return value to a location. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1654 | SmallVector<CCValAssign, 16> RVLocs; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1655 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1656 | // CCState - Info about the registers and stack slots. |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1657 | CCState CCInfo(CallConv, isVarArg, getTargetMachine(), RVLocs, |
| 1658 | *DAG.getContext()); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1659 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1660 | // Analyze outgoing return values. |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1661 | CCInfo.AnalyzeReturn(Outs, CCAssignFnForNode(CallConv, /* Return */ true, |
| 1662 | isVarArg)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1663 | |
| 1664 | // If this is the first return lowered for this function, add |
| 1665 | // the regs to the liveout set for the function. |
| 1666 | if (DAG.getMachineFunction().getRegInfo().liveout_empty()) { |
| 1667 | for (unsigned i = 0; i != RVLocs.size(); ++i) |
| 1668 | if (RVLocs[i].isRegLoc()) |
| 1669 | DAG.getMachineFunction().getRegInfo().addLiveOut(RVLocs[i].getLocReg()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1670 | } |
| 1671 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1672 | SDValue Flag; |
| 1673 | |
| 1674 | // Copy the result values into the output registers. |
| 1675 | for (unsigned i = 0, realRVLocIdx = 0; |
| 1676 | i != RVLocs.size(); |
| 1677 | ++i, ++realRVLocIdx) { |
| 1678 | CCValAssign &VA = RVLocs[i]; |
| 1679 | assert(VA.isRegLoc() && "Can only return in registers!"); |
| 1680 | |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1681 | SDValue Arg = OutVals[realRVLocIdx]; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1682 | |
| 1683 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1684 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1685 | case CCValAssign::Full: break; |
| 1686 | case CCValAssign::BCvt: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1687 | Arg = DAG.getNode(ISD::BITCAST, dl, VA.getLocVT(), Arg); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1688 | break; |
| 1689 | } |
| 1690 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1691 | if (VA.needsCustom()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1692 | if (VA.getLocVT() == MVT::v2f64) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1693 | // Extract the first half and return it in two registers. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1694 | SDValue Half = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1695 | DAG.getConstant(0, MVT::i32)); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1696 | SDValue HalfGPRs = DAG.getNode(ARMISD::VMOVRRD, dl, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1697 | DAG.getVTList(MVT::i32, MVT::i32), Half); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1698 | |
| 1699 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), HalfGPRs, Flag); |
| 1700 | Flag = Chain.getValue(1); |
| 1701 | VA = RVLocs[++i]; // skip ahead to next loc |
| 1702 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), |
| 1703 | HalfGPRs.getValue(1), Flag); |
| 1704 | Flag = Chain.getValue(1); |
| 1705 | VA = RVLocs[++i]; // skip ahead to next loc |
| 1706 | |
| 1707 | // 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] | 1708 | Arg = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1709 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1710 | } |
| 1711 | // Legalize ret f64 -> ret 2 x i32. We always have fmrrd if f64 is |
| 1712 | // available. |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1713 | SDValue fmrrd = DAG.getNode(ARMISD::VMOVRRD, dl, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1714 | DAG.getVTList(MVT::i32, MVT::i32), &Arg, 1); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1715 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), fmrrd, Flag); |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1716 | Flag = Chain.getValue(1); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1717 | VA = RVLocs[++i]; // skip ahead to next loc |
| 1718 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), fmrrd.getValue(1), |
| 1719 | Flag); |
| 1720 | } else |
| 1721 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), Arg, Flag); |
| 1722 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1723 | // Guarantee that all emitted copies are |
| 1724 | // stuck together, avoiding something bad. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1725 | Flag = Chain.getValue(1); |
| 1726 | } |
| 1727 | |
| 1728 | SDValue result; |
| 1729 | if (Flag.getNode()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1730 | result = DAG.getNode(ARMISD::RET_FLAG, dl, MVT::Other, Chain, Flag); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1731 | else // Return Void |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1732 | result = DAG.getNode(ARMISD::RET_FLAG, dl, MVT::Other, Chain); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1733 | |
| 1734 | return result; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1735 | } |
| 1736 | |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1737 | bool ARMTargetLowering::isUsedByReturnOnly(SDNode *N) const { |
| 1738 | if (N->getNumValues() != 1) |
| 1739 | return false; |
| 1740 | if (!N->hasNUsesOfValue(1, 0)) |
| 1741 | return false; |
| 1742 | |
| 1743 | unsigned NumCopies = 0; |
| 1744 | SDNode* Copies[2]; |
| 1745 | SDNode *Use = *N->use_begin(); |
| 1746 | if (Use->getOpcode() == ISD::CopyToReg) { |
| 1747 | Copies[NumCopies++] = Use; |
| 1748 | } else if (Use->getOpcode() == ARMISD::VMOVRRD) { |
| 1749 | // f64 returned in a pair of GPRs. |
| 1750 | for (SDNode::use_iterator UI = Use->use_begin(), UE = Use->use_end(); |
| 1751 | UI != UE; ++UI) { |
| 1752 | if (UI->getOpcode() != ISD::CopyToReg) |
| 1753 | return false; |
| 1754 | Copies[UI.getUse().getResNo()] = *UI; |
| 1755 | ++NumCopies; |
| 1756 | } |
| 1757 | } else if (Use->getOpcode() == ISD::BITCAST) { |
| 1758 | // f32 returned in a single GPR. |
| 1759 | if (!Use->hasNUsesOfValue(1, 0)) |
| 1760 | return false; |
| 1761 | Use = *Use->use_begin(); |
| 1762 | if (Use->getOpcode() != ISD::CopyToReg || !Use->hasNUsesOfValue(1, 0)) |
| 1763 | return false; |
| 1764 | Copies[NumCopies++] = Use; |
| 1765 | } else { |
| 1766 | return false; |
| 1767 | } |
| 1768 | |
| 1769 | if (NumCopies != 1 && NumCopies != 2) |
| 1770 | return false; |
Evan Cheng | 1bf891a | 2010-12-01 22:59:46 +0000 | [diff] [blame] | 1771 | |
| 1772 | bool HasRet = false; |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1773 | for (unsigned i = 0; i < NumCopies; ++i) { |
| 1774 | SDNode *Copy = Copies[i]; |
| 1775 | for (SDNode::use_iterator UI = Copy->use_begin(), UE = Copy->use_end(); |
| 1776 | UI != UE; ++UI) { |
| 1777 | if (UI->getOpcode() == ISD::CopyToReg) { |
| 1778 | SDNode *Use = *UI; |
| 1779 | if (Use == Copies[0] || Use == Copies[1]) |
| 1780 | continue; |
| 1781 | return false; |
| 1782 | } |
| 1783 | if (UI->getOpcode() != ARMISD::RET_FLAG) |
| 1784 | return false; |
Evan Cheng | 1bf891a | 2010-12-01 22:59:46 +0000 | [diff] [blame] | 1785 | HasRet = true; |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1786 | } |
| 1787 | } |
| 1788 | |
Evan Cheng | 1bf891a | 2010-12-01 22:59:46 +0000 | [diff] [blame] | 1789 | return HasRet; |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1790 | } |
| 1791 | |
Bob Wilson | b62d257 | 2009-11-03 00:02:05 +0000 | [diff] [blame] | 1792 | // ConstantPool, JumpTable, GlobalAddress, and ExternalSymbol are lowered as |
| 1793 | // their target counterpart wrapped in the ARMISD::Wrapper node. Suppose N is |
| 1794 | // one of the above mentioned nodes. It has to be wrapped because otherwise |
| 1795 | // Select(N) returns N. So the raw TargetGlobalAddress nodes, etc. can only |
| 1796 | // be used to form addressing mode. These wrapped nodes will be selected |
| 1797 | // into MOVi. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1798 | static SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1799 | EVT PtrVT = Op.getValueType(); |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 1800 | // FIXME there is no actual debug info here |
| 1801 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1802 | ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1803 | SDValue Res; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1804 | if (CP->isMachineConstantPoolEntry()) |
| 1805 | Res = DAG.getTargetConstantPool(CP->getMachineCPVal(), PtrVT, |
| 1806 | CP->getAlignment()); |
| 1807 | else |
| 1808 | Res = DAG.getTargetConstantPool(CP->getConstVal(), PtrVT, |
| 1809 | CP->getAlignment()); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1810 | return DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Res); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1811 | } |
| 1812 | |
Jim Grosbach | e1102ca | 2010-07-19 17:20:38 +0000 | [diff] [blame] | 1813 | unsigned ARMTargetLowering::getJumpTableEncoding() const { |
| 1814 | return MachineJumpTableInfo::EK_Inline; |
| 1815 | } |
| 1816 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1817 | SDValue ARMTargetLowering::LowerBlockAddress(SDValue Op, |
| 1818 | SelectionDAG &DAG) const { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1819 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1820 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 1821 | unsigned ARMPCLabelIndex = 0; |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 1822 | DebugLoc DL = Op.getDebugLoc(); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 1823 | EVT PtrVT = getPointerTy(); |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 1824 | const BlockAddress *BA = cast<BlockAddressSDNode>(Op)->getBlockAddress(); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 1825 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| 1826 | SDValue CPAddr; |
| 1827 | if (RelocM == Reloc::Static) { |
| 1828 | CPAddr = DAG.getTargetConstantPool(BA, PtrVT, 4); |
| 1829 | } else { |
| 1830 | unsigned PCAdj = Subtarget->isThumb() ? 4 : 8; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1831 | ARMPCLabelIndex = AFI->createPICLabelUId(); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 1832 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(BA, ARMPCLabelIndex, |
| 1833 | ARMCP::CPBlockAddress, |
| 1834 | PCAdj); |
| 1835 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
| 1836 | } |
| 1837 | CPAddr = DAG.getNode(ARMISD::Wrapper, DL, PtrVT, CPAddr); |
| 1838 | SDValue Result = DAG.getLoad(PtrVT, DL, DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1839 | MachinePointerInfo::getConstantPool(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1840 | false, false, 0); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 1841 | if (RelocM == Reloc::Static) |
| 1842 | return Result; |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1843 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 1844 | return DAG.getNode(ARMISD::PIC_ADD, DL, PtrVT, Result, PICLabel); |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 1845 | } |
| 1846 | |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1847 | // Lower ISD::GlobalTLSAddress using the "general dynamic" model |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1848 | SDValue |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1849 | ARMTargetLowering::LowerToTLSGeneralDynamicModel(GlobalAddressSDNode *GA, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1850 | SelectionDAG &DAG) const { |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1851 | DebugLoc dl = GA->getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1852 | EVT PtrVT = getPointerTy(); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1853 | unsigned char PCAdj = Subtarget->isThumb() ? 4 : 8; |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1854 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1855 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1856 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1857 | ARMConstantPoolValue *CPV = |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 1858 | new ARMConstantPoolValue(GA->getGlobal(), ARMPCLabelIndex, |
Jim Grosbach | 3a2429a | 2010-11-09 21:36:17 +0000 | [diff] [blame] | 1859 | ARMCP::CPValue, PCAdj, ARMCP::TLSGD, true); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1860 | SDValue Argument = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1861 | Argument = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Argument); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1862 | Argument = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Argument, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1863 | MachinePointerInfo::getConstantPool(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1864 | false, false, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1865 | SDValue Chain = Argument.getValue(1); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1866 | |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1867 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1868 | Argument = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Argument, PICLabel); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1869 | |
| 1870 | // call __tls_get_addr. |
| 1871 | ArgListTy Args; |
| 1872 | ArgListEntry Entry; |
| 1873 | Entry.Node = Argument; |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 1874 | Entry.Ty = (const Type *) Type::getInt32Ty(*DAG.getContext()); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1875 | Args.push_back(Entry); |
Dale Johannesen | 7d2ad62 | 2009-01-30 23:10:59 +0000 | [diff] [blame] | 1876 | // FIXME: is there useful debug info available here? |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1877 | std::pair<SDValue, SDValue> CallResult = |
Evan Cheng | 59bc060 | 2009-08-14 19:11:20 +0000 | [diff] [blame] | 1878 | LowerCallTo(Chain, (const Type *) Type::getInt32Ty(*DAG.getContext()), |
| 1879 | false, false, false, false, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1880 | 0, CallingConv::C, false, /*isReturnValueUsed=*/true, |
Bill Wendling | 46ada19 | 2010-03-02 01:55:18 +0000 | [diff] [blame] | 1881 | DAG.getExternalSymbol("__tls_get_addr", PtrVT), Args, DAG, dl); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1882 | return CallResult.first; |
| 1883 | } |
| 1884 | |
| 1885 | // Lower ISD::GlobalTLSAddress using the "initial exec" or |
| 1886 | // "local exec" model. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1887 | SDValue |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1888 | ARMTargetLowering::LowerToTLSExecModels(GlobalAddressSDNode *GA, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1889 | SelectionDAG &DAG) const { |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 1890 | const GlobalValue *GV = GA->getGlobal(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1891 | DebugLoc dl = GA->getDebugLoc(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1892 | SDValue Offset; |
| 1893 | SDValue Chain = DAG.getEntryNode(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1894 | EVT PtrVT = getPointerTy(); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1895 | // Get the Thread Pointer |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1896 | SDValue ThreadPointer = DAG.getNode(ARMISD::THREAD_POINTER, dl, PtrVT); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1897 | |
Chris Lattner | 4fb63d0 | 2009-07-15 04:12:33 +0000 | [diff] [blame] | 1898 | if (GV->isDeclaration()) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1899 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1900 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1901 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1902 | // Initial exec model. |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1903 | unsigned char PCAdj = Subtarget->isThumb() ? 4 : 8; |
| 1904 | ARMConstantPoolValue *CPV = |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 1905 | new ARMConstantPoolValue(GA->getGlobal(), ARMPCLabelIndex, |
Jim Grosbach | 3a2429a | 2010-11-09 21:36:17 +0000 | [diff] [blame] | 1906 | ARMCP::CPValue, PCAdj, ARMCP::GOTTPOFF, true); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1907 | Offset = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1908 | Offset = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Offset); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1909 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1910 | MachinePointerInfo::getConstantPool(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1911 | false, false, 0); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1912 | Chain = Offset.getValue(1); |
| 1913 | |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1914 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1915 | Offset = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Offset, PICLabel); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1916 | |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1917 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1918 | MachinePointerInfo::getConstantPool(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1919 | false, false, 0); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1920 | } else { |
| 1921 | // local exec model |
Jim Grosbach | 3a2429a | 2010-11-09 21:36:17 +0000 | [diff] [blame] | 1922 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GV, ARMCP::TPOFF); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1923 | Offset = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1924 | Offset = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Offset); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1925 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1926 | MachinePointerInfo::getConstantPool(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1927 | false, false, 0); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1928 | } |
| 1929 | |
| 1930 | // The address of the thread local variable is the add of the thread |
| 1931 | // pointer with the offset of the variable. |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1932 | return DAG.getNode(ISD::ADD, dl, PtrVT, ThreadPointer, Offset); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1933 | } |
| 1934 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1935 | SDValue |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1936 | ARMTargetLowering::LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const { |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1937 | // TODO: implement the "local dynamic" model |
| 1938 | assert(Subtarget->isTargetELF() && |
| 1939 | "TLS not implemented for non-ELF targets"); |
| 1940 | GlobalAddressSDNode *GA = cast<GlobalAddressSDNode>(Op); |
| 1941 | // If the relocation model is PIC, use the "General Dynamic" TLS Model, |
| 1942 | // otherwise use the "Local Exec" TLS Model |
| 1943 | if (getTargetMachine().getRelocationModel() == Reloc::PIC_) |
| 1944 | return LowerToTLSGeneralDynamicModel(GA, DAG); |
| 1945 | else |
| 1946 | return LowerToTLSExecModels(GA, DAG); |
| 1947 | } |
| 1948 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1949 | SDValue ARMTargetLowering::LowerGlobalAddressELF(SDValue Op, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1950 | SelectionDAG &DAG) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1951 | EVT PtrVT = getPointerTy(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1952 | DebugLoc dl = Op.getDebugLoc(); |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 1953 | const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 1954 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| 1955 | if (RelocM == Reloc::PIC_) { |
Rafael Espindola | bb46f52 | 2009-01-15 20:18:42 +0000 | [diff] [blame] | 1956 | bool UseGOTOFF = GV->hasLocalLinkage() || GV->hasHiddenVisibility(); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 1957 | ARMConstantPoolValue *CPV = |
Jim Grosbach | 3a2429a | 2010-11-09 21:36:17 +0000 | [diff] [blame] | 1958 | new ARMConstantPoolValue(GV, UseGOTOFF ? ARMCP::GOTOFF : ARMCP::GOT); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1959 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1960 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1961 | SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 1962 | CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1963 | MachinePointerInfo::getConstantPool(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1964 | false, false, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1965 | SDValue Chain = Result.getValue(1); |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 1966 | SDValue GOT = DAG.getGLOBAL_OFFSET_TABLE(PtrVT); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1967 | Result = DAG.getNode(ISD::ADD, dl, PtrVT, Result, GOT); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 1968 | if (!UseGOTOFF) |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 1969 | Result = DAG.getLoad(PtrVT, dl, Chain, Result, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1970 | MachinePointerInfo::getGOT(), false, false, 0); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 1971 | return Result; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1972 | } |
| 1973 | |
| 1974 | // If we have T2 ops, we can materialize the address directly via movt/movw |
| 1975 | // pair. This is always cheaper. |
| 1976 | if (Subtarget->useMovt()) { |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 1977 | ++NumMovwMovt; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1978 | // FIXME: Once remat is capable of dealing with instructions with register |
| 1979 | // operands, expand this into two nodes. |
| 1980 | return DAG.getNode(ARMISD::Wrapper, dl, PtrVT, |
| 1981 | DAG.getTargetGlobalAddress(GV, dl, PtrVT)); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 1982 | } else { |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1983 | SDValue CPAddr = DAG.getTargetConstantPool(GV, PtrVT, 4); |
| 1984 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| 1985 | return DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
| 1986 | MachinePointerInfo::getConstantPool(), |
| 1987 | false, false, 0); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 1988 | } |
| 1989 | } |
| 1990 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1991 | SDValue ARMTargetLowering::LowerGlobalAddressDarwin(SDValue Op, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1992 | SelectionDAG &DAG) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1993 | EVT PtrVT = getPointerTy(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1994 | DebugLoc dl = Op.getDebugLoc(); |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 1995 | const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1996 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1997 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1998 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 1999 | |
| 2000 | if (Subtarget->useMovt()) { |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2001 | ++NumMovwMovt; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2002 | // FIXME: Once remat is capable of dealing with instructions with register |
| 2003 | // operands, expand this into two nodes. |
Evan Cheng | 53519f0 | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 2004 | if (RelocM == Reloc::Static) |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2005 | return DAG.getNode(ARMISD::Wrapper, dl, PtrVT, |
| 2006 | DAG.getTargetGlobalAddress(GV, dl, PtrVT)); |
| 2007 | |
Evan Cheng | 53519f0 | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 2008 | unsigned Wrapper = (RelocM == Reloc::PIC_) |
| 2009 | ? ARMISD::WrapperPIC : ARMISD::WrapperDYN; |
| 2010 | SDValue Result = DAG.getNode(Wrapper, dl, PtrVT, |
Evan Cheng | 9fe2009 | 2011-01-20 08:34:58 +0000 | [diff] [blame] | 2011 | DAG.getTargetGlobalAddress(GV, dl, PtrVT)); |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2012 | if (Subtarget->GVIsIndirectSymbol(GV, RelocM)) |
| 2013 | Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Result, |
| 2014 | MachinePointerInfo::getGOT(), false, false, 0); |
| 2015 | return Result; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2016 | } |
| 2017 | |
| 2018 | unsigned ARMPCLabelIndex = 0; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2019 | SDValue CPAddr; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2020 | if (RelocM == Reloc::Static) { |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2021 | CPAddr = DAG.getTargetConstantPool(GV, PtrVT, 4); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2022 | } else { |
| 2023 | ARMPCLabelIndex = AFI->createPICLabelUId(); |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 2024 | unsigned PCAdj = (RelocM != Reloc::PIC_) ? 0 : (Subtarget->isThumb()?4:8); |
| 2025 | ARMConstantPoolValue *CPV = |
Jim Grosbach | 3fb2b1e | 2009-09-01 01:57:56 +0000 | [diff] [blame] | 2026 | new ARMConstantPoolValue(GV, ARMPCLabelIndex, ARMCP::CPValue, PCAdj); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2027 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2028 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2029 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2030 | |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2031 | SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2032 | MachinePointerInfo::getConstantPool(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 2033 | false, false, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2034 | SDValue Chain = Result.getValue(1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2035 | |
| 2036 | if (RelocM == Reloc::PIC_) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2037 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2038 | Result = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2039 | } |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 2040 | |
Evan Cheng | 63476a8 | 2009-09-03 07:04:02 +0000 | [diff] [blame] | 2041 | if (Subtarget->GVIsIndirectSymbol(GV, RelocM)) |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2042 | Result = DAG.getLoad(PtrVT, dl, Chain, Result, MachinePointerInfo::getGOT(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 2043 | false, false, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2044 | |
| 2045 | return Result; |
| 2046 | } |
| 2047 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2048 | SDValue ARMTargetLowering::LowerGLOBAL_OFFSET_TABLE(SDValue Op, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2049 | SelectionDAG &DAG) const { |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2050 | assert(Subtarget->isTargetELF() && |
| 2051 | "GLOBAL OFFSET TABLE not implemented for non-ELF targets"); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2052 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2053 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2054 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2055 | EVT PtrVT = getPointerTy(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2056 | DebugLoc dl = Op.getDebugLoc(); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2057 | unsigned PCAdj = Subtarget->isThumb() ? 4 : 8; |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 2058 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(*DAG.getContext(), |
| 2059 | "_GLOBAL_OFFSET_TABLE_", |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 2060 | ARMPCLabelIndex, PCAdj); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2061 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2062 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 2063 | SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2064 | MachinePointerInfo::getConstantPool(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 2065 | false, false, 0); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2066 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2067 | return DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2068 | } |
| 2069 | |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 2070 | SDValue |
Jim Grosbach | e4ad387 | 2010-10-19 23:27:08 +0000 | [diff] [blame] | 2071 | ARMTargetLowering::LowerEH_SJLJ_DISPATCHSETUP(SDValue Op, SelectionDAG &DAG) |
| 2072 | const { |
| 2073 | DebugLoc dl = Op.getDebugLoc(); |
| 2074 | return DAG.getNode(ARMISD::EH_SJLJ_DISPATCHSETUP, dl, MVT::Other, |
| 2075 | Op.getOperand(0), Op.getOperand(1)); |
| 2076 | } |
| 2077 | |
| 2078 | SDValue |
Jim Grosbach | 23ff7cf | 2010-05-26 20:22:18 +0000 | [diff] [blame] | 2079 | ARMTargetLowering::LowerEH_SJLJ_SETJMP(SDValue Op, SelectionDAG &DAG) const { |
| 2080 | DebugLoc dl = Op.getDebugLoc(); |
Jim Grosbach | 0798edd | 2010-05-27 23:49:24 +0000 | [diff] [blame] | 2081 | SDValue Val = DAG.getConstant(0, MVT::i32); |
Jim Grosbach | 23ff7cf | 2010-05-26 20:22:18 +0000 | [diff] [blame] | 2082 | return DAG.getNode(ARMISD::EH_SJLJ_SETJMP, dl, MVT::i32, Op.getOperand(0), |
| 2083 | Op.getOperand(1), Val); |
| 2084 | } |
| 2085 | |
| 2086 | SDValue |
Jim Grosbach | 5eb1951 | 2010-05-22 01:06:18 +0000 | [diff] [blame] | 2087 | ARMTargetLowering::LowerEH_SJLJ_LONGJMP(SDValue Op, SelectionDAG &DAG) const { |
| 2088 | DebugLoc dl = Op.getDebugLoc(); |
| 2089 | return DAG.getNode(ARMISD::EH_SJLJ_LONGJMP, dl, MVT::Other, Op.getOperand(0), |
| 2090 | Op.getOperand(1), DAG.getConstant(0, MVT::i32)); |
| 2091 | } |
| 2092 | |
| 2093 | SDValue |
Jim Grosbach | a87ded2 | 2010-02-08 23:22:00 +0000 | [diff] [blame] | 2094 | ARMTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG, |
Jim Grosbach | 7616b64 | 2010-06-16 23:45:49 +0000 | [diff] [blame] | 2095 | const ARMSubtarget *Subtarget) const { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2096 | unsigned IntNo = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 2097 | DebugLoc dl = Op.getDebugLoc(); |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 2098 | switch (IntNo) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2099 | default: return SDValue(); // Don't custom lower most intrinsics. |
Bob Wilson | 916afdb | 2009-08-04 00:25:01 +0000 | [diff] [blame] | 2100 | case Intrinsic::arm_thread_pointer: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2101 | EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
Bob Wilson | 916afdb | 2009-08-04 00:25:01 +0000 | [diff] [blame] | 2102 | return DAG.getNode(ARMISD::THREAD_POINTER, dl, PtrVT); |
| 2103 | } |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2104 | case Intrinsic::eh_sjlj_lsda: { |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2105 | MachineFunction &MF = DAG.getMachineFunction(); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2106 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2107 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2108 | EVT PtrVT = getPointerTy(); |
| 2109 | DebugLoc dl = Op.getDebugLoc(); |
| 2110 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| 2111 | SDValue CPAddr; |
| 2112 | unsigned PCAdj = (RelocM != Reloc::PIC_) |
| 2113 | ? 0 : (Subtarget->isThumb() ? 4 : 8); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2114 | ARMConstantPoolValue *CPV = |
Jim Grosbach | 3fb2b1e | 2009-09-01 01:57:56 +0000 | [diff] [blame] | 2115 | new ARMConstantPoolValue(MF.getFunction(), ARMPCLabelIndex, |
| 2116 | ARMCP::CPLSDA, PCAdj); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2117 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2118 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2119 | SDValue Result = |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2120 | DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2121 | MachinePointerInfo::getConstantPool(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 2122 | false, false, 0); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2123 | |
| 2124 | if (RelocM == Reloc::PIC_) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2125 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2126 | Result = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
| 2127 | } |
| 2128 | return Result; |
| 2129 | } |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 2130 | } |
| 2131 | } |
| 2132 | |
Jim Grosbach | 7c03dbd | 2009-12-14 21:24:16 +0000 | [diff] [blame] | 2133 | static SDValue LowerMEMBARRIER(SDValue Op, SelectionDAG &DAG, |
Jim Grosbach | 7616b64 | 2010-06-16 23:45:49 +0000 | [diff] [blame] | 2134 | const ARMSubtarget *Subtarget) { |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 2135 | DebugLoc dl = Op.getDebugLoc(); |
Bob Wilson | f74a429 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 2136 | if (!Subtarget->hasDataBarrier()) { |
| 2137 | // Some ARMv6 cpus can support data barriers with an mcr instruction. |
| 2138 | // Thumb1 and pre-v6 ARM mode use a libcall instead and should never get |
| 2139 | // here. |
Bob Wilson | 54f9256 | 2010-11-09 22:50:44 +0000 | [diff] [blame] | 2140 | assert(Subtarget->hasV6Ops() && !Subtarget->isThumb() && |
Evan Cheng | 11db068 | 2010-08-11 06:22:01 +0000 | [diff] [blame] | 2141 | "Unexpected ISD::MEMBARRIER encountered. Should be libcall!"); |
Bob Wilson | f74a429 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 2142 | return DAG.getNode(ARMISD::MEMBARRIER_MCR, dl, MVT::Other, Op.getOperand(0), |
Jim Grosbach | c73993b | 2010-06-17 01:37:00 +0000 | [diff] [blame] | 2143 | DAG.getConstant(0, MVT::i32)); |
Evan Cheng | 11db068 | 2010-08-11 06:22:01 +0000 | [diff] [blame] | 2144 | } |
Bob Wilson | f74a429 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 2145 | |
| 2146 | SDValue Op5 = Op.getOperand(5); |
| 2147 | bool isDeviceBarrier = cast<ConstantSDNode>(Op5)->getZExtValue() != 0; |
| 2148 | unsigned isLL = cast<ConstantSDNode>(Op.getOperand(1))->getZExtValue(); |
| 2149 | unsigned isLS = cast<ConstantSDNode>(Op.getOperand(2))->getZExtValue(); |
| 2150 | bool isOnlyStoreBarrier = (isLL == 0 && isLS == 0); |
| 2151 | |
| 2152 | ARM_MB::MemBOpt DMBOpt; |
| 2153 | if (isDeviceBarrier) |
| 2154 | DMBOpt = isOnlyStoreBarrier ? ARM_MB::ST : ARM_MB::SY; |
| 2155 | else |
| 2156 | DMBOpt = isOnlyStoreBarrier ? ARM_MB::ISHST : ARM_MB::ISH; |
| 2157 | return DAG.getNode(ARMISD::MEMBARRIER, dl, MVT::Other, Op.getOperand(0), |
| 2158 | DAG.getConstant(DMBOpt, MVT::i32)); |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 2159 | } |
| 2160 | |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2161 | static SDValue LowerPREFETCH(SDValue Op, SelectionDAG &DAG, |
| 2162 | const ARMSubtarget *Subtarget) { |
| 2163 | // ARM pre v5TE and Thumb1 does not have preload instructions. |
| 2164 | if (!(Subtarget->isThumb2() || |
| 2165 | (!Subtarget->isThumb1Only() && Subtarget->hasV5TEOps()))) |
| 2166 | // Just preserve the chain. |
| 2167 | return Op.getOperand(0); |
| 2168 | |
| 2169 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 2170 | unsigned isRead = ~cast<ConstantSDNode>(Op.getOperand(2))->getZExtValue() & 1; |
| 2171 | if (!isRead && |
| 2172 | (!Subtarget->hasV7Ops() || !Subtarget->hasMPExtension())) |
| 2173 | // ARMv7 with MP extension has PLDW. |
| 2174 | return Op.getOperand(0); |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2175 | |
| 2176 | if (Subtarget->isThumb()) |
| 2177 | // Invert the bits. |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 2178 | isRead = ~isRead & 1; |
| 2179 | unsigned isData = Subtarget->isThumb() ? 0 : 1; |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2180 | |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 2181 | // Currently there is no intrinsic that matches pli. |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2182 | return DAG.getNode(ARMISD::PRELOAD, dl, MVT::Other, Op.getOperand(0), |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 2183 | Op.getOperand(1), DAG.getConstant(isRead, MVT::i32), |
| 2184 | DAG.getConstant(isData, MVT::i32)); |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2185 | } |
| 2186 | |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 2187 | static SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) { |
| 2188 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2189 | ARMFunctionInfo *FuncInfo = MF.getInfo<ARMFunctionInfo>(); |
| 2190 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2191 | // vastart just stores the address of the VarArgsFrameIndex slot into the |
| 2192 | // memory location argument. |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2193 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2194 | EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 2195 | SDValue FR = DAG.getFrameIndex(FuncInfo->getVarArgsFrameIndex(), PtrVT); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 2196 | const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue(); |
Chris Lattner | fc448ff | 2010-09-21 18:51:21 +0000 | [diff] [blame] | 2197 | return DAG.getStore(Op.getOperand(0), dl, FR, Op.getOperand(1), |
| 2198 | MachinePointerInfo(SV), false, false, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2199 | } |
| 2200 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2201 | SDValue |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2202 | ARMTargetLowering::GetF64FormalArgument(CCValAssign &VA, CCValAssign &NextVA, |
| 2203 | SDValue &Root, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2204 | DebugLoc dl) const { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2205 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2206 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2207 | |
| 2208 | TargetRegisterClass *RC; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 2209 | if (AFI->isThumb1OnlyFunction()) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2210 | RC = ARM::tGPRRegisterClass; |
| 2211 | else |
| 2212 | RC = ARM::GPRRegisterClass; |
| 2213 | |
| 2214 | // Transform the arguments stored in physical registers into virtual ones. |
Devang Patel | e9a7ea6 | 2011-01-31 21:38:14 +0000 | [diff] [blame] | 2215 | unsigned Reg = MF.addLiveIn(VA.getLocReg(), RC, dl); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2216 | SDValue ArgValue = DAG.getCopyFromReg(Root, dl, Reg, MVT::i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2217 | |
| 2218 | SDValue ArgValue2; |
| 2219 | if (NextVA.isMemLoc()) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2220 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
Evan Cheng | ed2ae13 | 2010-07-03 00:40:23 +0000 | [diff] [blame] | 2221 | int FI = MFI->CreateFixedObject(4, NextVA.getLocMemOffset(), true); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2222 | |
| 2223 | // Create load node to retrieve arguments from the stack. |
| 2224 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2225 | ArgValue2 = DAG.getLoad(MVT::i32, dl, Root, FIN, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2226 | MachinePointerInfo::getFixedStack(FI), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 2227 | false, false, 0); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2228 | } else { |
Devang Patel | e9a7ea6 | 2011-01-31 21:38:14 +0000 | [diff] [blame] | 2229 | Reg = MF.addLiveIn(NextVA.getLocReg(), RC, dl); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2230 | ArgValue2 = DAG.getCopyFromReg(Root, dl, Reg, MVT::i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2231 | } |
| 2232 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 2233 | return DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, ArgValue, ArgValue2); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2234 | } |
| 2235 | |
| 2236 | SDValue |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2237 | ARMTargetLowering::LowerFormalArguments(SDValue Chain, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 2238 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2239 | const SmallVectorImpl<ISD::InputArg> |
| 2240 | &Ins, |
| 2241 | DebugLoc dl, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2242 | SmallVectorImpl<SDValue> &InVals) |
| 2243 | const { |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2244 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2245 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2246 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 2247 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2248 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2249 | |
| 2250 | // Assign locations to all of the incoming arguments. |
| 2251 | SmallVector<CCValAssign, 16> ArgLocs; |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2252 | CCState CCInfo(CallConv, isVarArg, getTargetMachine(), ArgLocs, |
| 2253 | *DAG.getContext()); |
| 2254 | CCInfo.AnalyzeFormalArguments(Ins, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 2255 | CCAssignFnForNode(CallConv, /* Return*/ false, |
| 2256 | isVarArg)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2257 | |
| 2258 | SmallVector<SDValue, 16> ArgValues; |
| 2259 | |
| 2260 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| 2261 | CCValAssign &VA = ArgLocs[i]; |
| 2262 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 2263 | // Arguments stored in registers. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2264 | if (VA.isRegLoc()) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2265 | EVT RegVT = VA.getLocVT(); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2266 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2267 | SDValue ArgValue; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2268 | if (VA.needsCustom()) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2269 | // f64 and vector types are split up into multiple registers or |
| 2270 | // combinations of registers and stack slots. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2271 | if (VA.getLocVT() == MVT::v2f64) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2272 | SDValue ArgValue1 = GetF64FormalArgument(VA, ArgLocs[++i], |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2273 | Chain, DAG, dl); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2274 | VA = ArgLocs[++i]; // skip ahead to next loc |
Bob Wilson | 6a234f0 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 2275 | SDValue ArgValue2; |
| 2276 | if (VA.isMemLoc()) { |
Evan Cheng | ed2ae13 | 2010-07-03 00:40:23 +0000 | [diff] [blame] | 2277 | int FI = MFI->CreateFixedObject(8, VA.getLocMemOffset(), true); |
Bob Wilson | 6a234f0 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 2278 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
| 2279 | ArgValue2 = DAG.getLoad(MVT::f64, dl, Chain, FIN, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2280 | MachinePointerInfo::getFixedStack(FI), |
Bob Wilson | 6a234f0 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 2281 | false, false, 0); |
| 2282 | } else { |
| 2283 | ArgValue2 = GetF64FormalArgument(VA, ArgLocs[++i], |
| 2284 | Chain, DAG, dl); |
| 2285 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2286 | ArgValue = DAG.getNode(ISD::UNDEF, dl, MVT::v2f64); |
| 2287 | ArgValue = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2288 | ArgValue, ArgValue1, DAG.getIntPtrConstant(0)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2289 | ArgValue = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2290 | ArgValue, ArgValue2, DAG.getIntPtrConstant(1)); |
| 2291 | } else |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2292 | ArgValue = GetF64FormalArgument(VA, ArgLocs[++i], Chain, DAG, dl); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2293 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2294 | } else { |
| 2295 | TargetRegisterClass *RC; |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 2296 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2297 | if (RegVT == MVT::f32) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2298 | RC = ARM::SPRRegisterClass; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2299 | else if (RegVT == MVT::f64) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2300 | RC = ARM::DPRRegisterClass; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2301 | else if (RegVT == MVT::v2f64) |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 2302 | RC = ARM::QPRRegisterClass; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2303 | else if (RegVT == MVT::i32) |
Anton Korobeynikov | 058c251 | 2009-08-05 20:15:19 +0000 | [diff] [blame] | 2304 | RC = (AFI->isThumb1OnlyFunction() ? |
| 2305 | ARM::tGPRRegisterClass : ARM::GPRRegisterClass); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2306 | else |
Anton Korobeynikov | 058c251 | 2009-08-05 20:15:19 +0000 | [diff] [blame] | 2307 | llvm_unreachable("RegVT not supported by FORMAL_ARGUMENTS Lowering"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2308 | |
| 2309 | // Transform the arguments in physical registers into virtual ones. |
Devang Patel | e9a7ea6 | 2011-01-31 21:38:14 +0000 | [diff] [blame] | 2310 | unsigned Reg = MF.addLiveIn(VA.getLocReg(), RC, dl); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2311 | ArgValue = DAG.getCopyFromReg(Chain, dl, Reg, RegVT); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2312 | } |
| 2313 | |
| 2314 | // If this is an 8 or 16-bit value, it is really passed promoted |
| 2315 | // to 32 bits. Insert an assert[sz]ext to capture this, then |
| 2316 | // truncate to the right size. |
| 2317 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 2318 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2319 | case CCValAssign::Full: break; |
| 2320 | case CCValAssign::BCvt: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2321 | ArgValue = DAG.getNode(ISD::BITCAST, dl, VA.getValVT(), ArgValue); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2322 | break; |
| 2323 | case CCValAssign::SExt: |
| 2324 | ArgValue = DAG.getNode(ISD::AssertSext, dl, RegVT, ArgValue, |
| 2325 | DAG.getValueType(VA.getValVT())); |
| 2326 | ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue); |
| 2327 | break; |
| 2328 | case CCValAssign::ZExt: |
| 2329 | ArgValue = DAG.getNode(ISD::AssertZext, dl, RegVT, ArgValue, |
| 2330 | DAG.getValueType(VA.getValVT())); |
| 2331 | ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue); |
| 2332 | break; |
| 2333 | } |
| 2334 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2335 | InVals.push_back(ArgValue); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2336 | |
| 2337 | } else { // VA.isRegLoc() |
| 2338 | |
| 2339 | // sanity check |
| 2340 | assert(VA.isMemLoc()); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2341 | assert(VA.getValVT() != MVT::i64 && "i64 should already be lowered"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2342 | |
| 2343 | unsigned ArgSize = VA.getLocVT().getSizeInBits()/8; |
Evan Cheng | ed2ae13 | 2010-07-03 00:40:23 +0000 | [diff] [blame] | 2344 | int FI = MFI->CreateFixedObject(ArgSize, VA.getLocMemOffset(), true); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2345 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 2346 | // Create load nodes to retrieve arguments from the stack. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2347 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2348 | InVals.push_back(DAG.getLoad(VA.getValVT(), dl, Chain, FIN, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2349 | MachinePointerInfo::getFixedStack(FI), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 2350 | false, false, 0)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2351 | } |
| 2352 | } |
| 2353 | |
| 2354 | // varargs |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2355 | if (isVarArg) { |
| 2356 | static const unsigned GPRArgRegs[] = { |
| 2357 | ARM::R0, ARM::R1, ARM::R2, ARM::R3 |
| 2358 | }; |
| 2359 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 2360 | unsigned NumGPRs = CCInfo.getFirstUnallocated |
| 2361 | (GPRArgRegs, sizeof(GPRArgRegs) / sizeof(GPRArgRegs[0])); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2362 | |
Anton Korobeynikov | 16c29b5 | 2011-01-10 12:39:04 +0000 | [diff] [blame] | 2363 | unsigned Align = MF.getTarget().getFrameLowering()->getStackAlignment(); |
Lauro Ramos Venancio | 600c383 | 2007-02-23 20:32:57 +0000 | [diff] [blame] | 2364 | unsigned VARegSize = (4 - NumGPRs) * 4; |
| 2365 | unsigned VARegSaveSize = (VARegSize + Align - 1) & ~(Align - 1); |
Rafael Espindola | c1382b7 | 2009-10-30 14:33:14 +0000 | [diff] [blame] | 2366 | unsigned ArgOffset = CCInfo.getNextStackOffset(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2367 | if (VARegSaveSize) { |
| 2368 | // If this function is vararg, store any remaining integer argument regs |
| 2369 | // to their spots on the stack so that they may be loaded by deferencing |
| 2370 | // the result of va_next. |
| 2371 | AFI->setVarArgsRegSaveSize(VARegSaveSize); |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 2372 | AFI->setVarArgsFrameIndex( |
| 2373 | MFI->CreateFixedObject(VARegSaveSize, |
| 2374 | ArgOffset + VARegSaveSize - VARegSize, |
Jim Grosbach | fd52906 | 2010-10-15 18:34:47 +0000 | [diff] [blame] | 2375 | false)); |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 2376 | SDValue FIN = DAG.getFrameIndex(AFI->getVarArgsFrameIndex(), |
| 2377 | getPointerTy()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2378 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2379 | SmallVector<SDValue, 4> MemOps; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2380 | for (; NumGPRs < 4; ++NumGPRs) { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2381 | TargetRegisterClass *RC; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 2382 | if (AFI->isThumb1OnlyFunction()) |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2383 | RC = ARM::tGPRRegisterClass; |
Jim Grosbach | 30eae3c | 2009-04-07 20:34:09 +0000 | [diff] [blame] | 2384 | else |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2385 | RC = ARM::GPRRegisterClass; |
| 2386 | |
Devang Patel | e9a7ea6 | 2011-01-31 21:38:14 +0000 | [diff] [blame] | 2387 | unsigned VReg = MF.addLiveIn(GPRArgRegs[NumGPRs], RC, dl); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2388 | SDValue Val = DAG.getCopyFromReg(Chain, dl, VReg, MVT::i32); |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 2389 | SDValue Store = |
| 2390 | DAG.getStore(Val.getValue(1), dl, Val, FIN, |
Chris Lattner | fc448ff | 2010-09-21 18:51:21 +0000 | [diff] [blame] | 2391 | MachinePointerInfo::getFixedStack(AFI->getVarArgsFrameIndex()), |
| 2392 | false, false, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2393 | MemOps.push_back(Store); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2394 | FIN = DAG.getNode(ISD::ADD, dl, getPointerTy(), FIN, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2395 | DAG.getConstant(4, getPointerTy())); |
| 2396 | } |
| 2397 | if (!MemOps.empty()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2398 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2399 | &MemOps[0], MemOps.size()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2400 | } else |
| 2401 | // This will point to the next argument passed via stack. |
Evan Cheng | ed2ae13 | 2010-07-03 00:40:23 +0000 | [diff] [blame] | 2402 | AFI->setVarArgsFrameIndex(MFI->CreateFixedObject(4, ArgOffset, true)); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2403 | } |
| 2404 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2405 | return Chain; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2406 | } |
| 2407 | |
| 2408 | /// isFloatingPointZero - Return true if this is +0.0. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2409 | static bool isFloatingPointZero(SDValue Op) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2410 | if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(Op)) |
Dale Johannesen | eaf0894 | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 2411 | return CFP->getValueAPF().isPosZero(); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2412 | else if (ISD::isEXTLoad(Op.getNode()) || ISD::isNON_EXTLoad(Op.getNode())) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2413 | // Maybe this has already been legalized into the constant pool? |
| 2414 | if (Op.getOperand(1).getOpcode() == ARMISD::Wrapper) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2415 | SDValue WrapperOp = Op.getOperand(1).getOperand(0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2416 | if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(WrapperOp)) |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2417 | if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CP->getConstVal())) |
Dale Johannesen | eaf0894 | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 2418 | return CFP->getValueAPF().isPosZero(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2419 | } |
| 2420 | } |
| 2421 | return false; |
| 2422 | } |
| 2423 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2424 | /// Returns appropriate ARM CMP (cmp) and corresponding condition code for |
| 2425 | /// the given operands. |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 2426 | SDValue |
| 2427 | ARMTargetLowering::getARMCmp(SDValue LHS, SDValue RHS, ISD::CondCode CC, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2428 | SDValue &ARMcc, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2429 | DebugLoc dl) const { |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2430 | if (ConstantSDNode *RHSC = dyn_cast<ConstantSDNode>(RHS.getNode())) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2431 | unsigned C = RHSC->getZExtValue(); |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 2432 | if (!isLegalICmpImmediate(C)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2433 | // Constant does not fit, try adjusting it by one? |
| 2434 | switch (CC) { |
| 2435 | default: break; |
| 2436 | case ISD::SETLT: |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2437 | case ISD::SETGE: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 2438 | if (C != 0x80000000 && isLegalICmpImmediate(C-1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2439 | CC = (CC == ISD::SETLT) ? ISD::SETLE : ISD::SETGT; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2440 | RHS = DAG.getConstant(C-1, MVT::i32); |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2441 | } |
| 2442 | break; |
| 2443 | case ISD::SETULT: |
| 2444 | case ISD::SETUGE: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 2445 | if (C != 0 && isLegalICmpImmediate(C-1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2446 | CC = (CC == ISD::SETULT) ? ISD::SETULE : ISD::SETUGT; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2447 | RHS = DAG.getConstant(C-1, MVT::i32); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2448 | } |
| 2449 | break; |
| 2450 | case ISD::SETLE: |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2451 | case ISD::SETGT: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 2452 | if (C != 0x7fffffff && isLegalICmpImmediate(C+1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2453 | CC = (CC == ISD::SETLE) ? ISD::SETLT : ISD::SETGE; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2454 | RHS = DAG.getConstant(C+1, MVT::i32); |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2455 | } |
| 2456 | break; |
| 2457 | case ISD::SETULE: |
| 2458 | case ISD::SETUGT: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 2459 | if (C != 0xffffffff && isLegalICmpImmediate(C+1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2460 | CC = (CC == ISD::SETULE) ? ISD::SETULT : ISD::SETUGE; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2461 | RHS = DAG.getConstant(C+1, MVT::i32); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2462 | } |
| 2463 | break; |
| 2464 | } |
| 2465 | } |
| 2466 | } |
| 2467 | |
| 2468 | ARMCC::CondCodes CondCode = IntCCToARMCC(CC); |
Lauro Ramos Venancio | 9996663 | 2007-04-02 01:30:03 +0000 | [diff] [blame] | 2469 | ARMISD::NodeType CompareType; |
| 2470 | switch (CondCode) { |
| 2471 | default: |
| 2472 | CompareType = ARMISD::CMP; |
| 2473 | break; |
| 2474 | case ARMCC::EQ: |
| 2475 | case ARMCC::NE: |
David Goodwin | c0309b4 | 2009-06-29 15:33:01 +0000 | [diff] [blame] | 2476 | // Uses only Z Flag |
| 2477 | CompareType = ARMISD::CMPZ; |
Lauro Ramos Venancio | 9996663 | 2007-04-02 01:30:03 +0000 | [diff] [blame] | 2478 | break; |
| 2479 | } |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2480 | ARMcc = DAG.getConstant(CondCode, MVT::i32); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 2481 | return DAG.getNode(CompareType, dl, MVT::Glue, LHS, RHS); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2482 | } |
| 2483 | |
| 2484 | /// 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] | 2485 | SDValue |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2486 | ARMTargetLowering::getVFPCmp(SDValue LHS, SDValue RHS, SelectionDAG &DAG, |
Evan Cheng | 515fe3a | 2010-07-08 02:08:50 +0000 | [diff] [blame] | 2487 | DebugLoc dl) const { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2488 | SDValue Cmp; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2489 | if (!isFloatingPointZero(RHS)) |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 2490 | Cmp = DAG.getNode(ARMISD::CMPFP, dl, MVT::Glue, LHS, RHS); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2491 | else |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 2492 | Cmp = DAG.getNode(ARMISD::CMPFPw0, dl, MVT::Glue, LHS); |
| 2493 | return DAG.getNode(ARMISD::FMSTAT, dl, MVT::Glue, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2494 | } |
| 2495 | |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 2496 | SDValue ARMTargetLowering::LowerSELECT(SDValue Op, SelectionDAG &DAG) const { |
| 2497 | SDValue Cond = Op.getOperand(0); |
| 2498 | SDValue SelectTrue = Op.getOperand(1); |
| 2499 | SDValue SelectFalse = Op.getOperand(2); |
| 2500 | DebugLoc dl = Op.getDebugLoc(); |
| 2501 | |
| 2502 | // Convert: |
| 2503 | // |
| 2504 | // (select (cmov 1, 0, cond), t, f) -> (cmov t, f, cond) |
| 2505 | // (select (cmov 0, 1, cond), t, f) -> (cmov f, t, cond) |
| 2506 | // |
| 2507 | if (Cond.getOpcode() == ARMISD::CMOV && Cond.hasOneUse()) { |
| 2508 | const ConstantSDNode *CMOVTrue = |
| 2509 | dyn_cast<ConstantSDNode>(Cond.getOperand(0)); |
| 2510 | const ConstantSDNode *CMOVFalse = |
| 2511 | dyn_cast<ConstantSDNode>(Cond.getOperand(1)); |
| 2512 | |
| 2513 | if (CMOVTrue && CMOVFalse) { |
| 2514 | unsigned CMOVTrueVal = CMOVTrue->getZExtValue(); |
| 2515 | unsigned CMOVFalseVal = CMOVFalse->getZExtValue(); |
| 2516 | |
| 2517 | SDValue True; |
| 2518 | SDValue False; |
| 2519 | if (CMOVTrueVal == 1 && CMOVFalseVal == 0) { |
| 2520 | True = SelectTrue; |
| 2521 | False = SelectFalse; |
| 2522 | } else if (CMOVTrueVal == 0 && CMOVFalseVal == 1) { |
| 2523 | True = SelectFalse; |
| 2524 | False = SelectTrue; |
| 2525 | } |
| 2526 | |
| 2527 | if (True.getNode() && False.getNode()) { |
| 2528 | EVT VT = Cond.getValueType(); |
| 2529 | SDValue ARMcc = Cond.getOperand(2); |
| 2530 | SDValue CCR = Cond.getOperand(3); |
| 2531 | SDValue Cmp = Cond.getOperand(4); |
| 2532 | return DAG.getNode(ARMISD::CMOV, dl, VT, True, False, ARMcc, CCR, Cmp); |
| 2533 | } |
| 2534 | } |
| 2535 | } |
| 2536 | |
| 2537 | return DAG.getSelectCC(dl, Cond, |
| 2538 | DAG.getConstant(0, Cond.getValueType()), |
| 2539 | SelectTrue, SelectFalse, ISD::SETNE); |
| 2540 | } |
| 2541 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2542 | SDValue ARMTargetLowering::LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2543 | EVT VT = Op.getValueType(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2544 | SDValue LHS = Op.getOperand(0); |
| 2545 | SDValue RHS = Op.getOperand(1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2546 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(4))->get(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2547 | SDValue TrueVal = Op.getOperand(2); |
| 2548 | SDValue FalseVal = Op.getOperand(3); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2549 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2550 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2551 | if (LHS.getValueType() == MVT::i32) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2552 | SDValue ARMcc; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2553 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2554 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMcc, DAG, dl); |
| 2555 | return DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, ARMcc, CCR,Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2556 | } |
| 2557 | |
| 2558 | ARMCC::CondCodes CondCode, CondCode2; |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 2559 | FPCCToARMCC(CC, CondCode, CondCode2); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2560 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2561 | SDValue ARMcc = DAG.getConstant(CondCode, MVT::i32); |
| 2562 | SDValue Cmp = getVFPCmp(LHS, RHS, DAG, dl); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2563 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2564 | SDValue Result = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2565 | ARMcc, CCR, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2566 | if (CondCode2 != ARMCC::AL) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2567 | SDValue ARMcc2 = DAG.getConstant(CondCode2, MVT::i32); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2568 | // FIXME: Needs another CMP because flag can have but one use. |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2569 | SDValue Cmp2 = getVFPCmp(LHS, RHS, DAG, dl); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2570 | Result = DAG.getNode(ARMISD::CMOV, dl, VT, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2571 | Result, TrueVal, ARMcc2, CCR, Cmp2); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2572 | } |
| 2573 | return Result; |
| 2574 | } |
| 2575 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2576 | /// canChangeToInt - Given the fp compare operand, return true if it is suitable |
| 2577 | /// to morph to an integer compare sequence. |
| 2578 | static bool canChangeToInt(SDValue Op, bool &SeenZero, |
| 2579 | const ARMSubtarget *Subtarget) { |
| 2580 | SDNode *N = Op.getNode(); |
| 2581 | if (!N->hasOneUse()) |
| 2582 | // Otherwise it requires moving the value from fp to integer registers. |
| 2583 | return false; |
| 2584 | if (!N->getNumValues()) |
| 2585 | return false; |
| 2586 | EVT VT = Op.getValueType(); |
| 2587 | if (VT != MVT::f32 && !Subtarget->isFPBrccSlow()) |
| 2588 | // f32 case is generally profitable. f64 case only makes sense when vcmpe + |
| 2589 | // vmrs are very slow, e.g. cortex-a8. |
| 2590 | return false; |
| 2591 | |
| 2592 | if (isFloatingPointZero(Op)) { |
| 2593 | SeenZero = true; |
| 2594 | return true; |
| 2595 | } |
| 2596 | return ISD::isNormalLoad(N); |
| 2597 | } |
| 2598 | |
| 2599 | static SDValue bitcastf32Toi32(SDValue Op, SelectionDAG &DAG) { |
| 2600 | if (isFloatingPointZero(Op)) |
| 2601 | return DAG.getConstant(0, MVT::i32); |
| 2602 | |
| 2603 | if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Op)) |
| 2604 | return DAG.getLoad(MVT::i32, Op.getDebugLoc(), |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2605 | Ld->getChain(), Ld->getBasePtr(), Ld->getPointerInfo(), |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2606 | Ld->isVolatile(), Ld->isNonTemporal(), |
| 2607 | Ld->getAlignment()); |
| 2608 | |
| 2609 | llvm_unreachable("Unknown VFP cmp argument!"); |
| 2610 | } |
| 2611 | |
| 2612 | static void expandf64Toi32(SDValue Op, SelectionDAG &DAG, |
| 2613 | SDValue &RetVal1, SDValue &RetVal2) { |
| 2614 | if (isFloatingPointZero(Op)) { |
| 2615 | RetVal1 = DAG.getConstant(0, MVT::i32); |
| 2616 | RetVal2 = DAG.getConstant(0, MVT::i32); |
| 2617 | return; |
| 2618 | } |
| 2619 | |
| 2620 | if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Op)) { |
| 2621 | SDValue Ptr = Ld->getBasePtr(); |
| 2622 | RetVal1 = DAG.getLoad(MVT::i32, Op.getDebugLoc(), |
| 2623 | Ld->getChain(), Ptr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2624 | Ld->getPointerInfo(), |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2625 | Ld->isVolatile(), Ld->isNonTemporal(), |
| 2626 | Ld->getAlignment()); |
| 2627 | |
| 2628 | EVT PtrType = Ptr.getValueType(); |
| 2629 | unsigned NewAlign = MinAlign(Ld->getAlignment(), 4); |
| 2630 | SDValue NewPtr = DAG.getNode(ISD::ADD, Op.getDebugLoc(), |
| 2631 | PtrType, Ptr, DAG.getConstant(4, PtrType)); |
| 2632 | RetVal2 = DAG.getLoad(MVT::i32, Op.getDebugLoc(), |
| 2633 | Ld->getChain(), NewPtr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2634 | Ld->getPointerInfo().getWithOffset(4), |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2635 | Ld->isVolatile(), Ld->isNonTemporal(), |
| 2636 | NewAlign); |
| 2637 | return; |
| 2638 | } |
| 2639 | |
| 2640 | llvm_unreachable("Unknown VFP cmp argument!"); |
| 2641 | } |
| 2642 | |
| 2643 | /// OptimizeVFPBrcond - With -enable-unsafe-fp-math, it's legal to optimize some |
| 2644 | /// f32 and even f64 comparisons to integer ones. |
| 2645 | SDValue |
| 2646 | ARMTargetLowering::OptimizeVFPBrcond(SDValue Op, SelectionDAG &DAG) const { |
| 2647 | SDValue Chain = Op.getOperand(0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2648 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get(); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2649 | SDValue LHS = Op.getOperand(2); |
| 2650 | SDValue RHS = Op.getOperand(3); |
| 2651 | SDValue Dest = Op.getOperand(4); |
| 2652 | DebugLoc dl = Op.getDebugLoc(); |
| 2653 | |
| 2654 | bool SeenZero = false; |
| 2655 | if (canChangeToInt(LHS, SeenZero, Subtarget) && |
| 2656 | canChangeToInt(RHS, SeenZero, Subtarget) && |
Evan Cheng | 60108e9 | 2010-07-15 22:07:12 +0000 | [diff] [blame] | 2657 | // If one of the operand is zero, it's safe to ignore the NaN case since |
| 2658 | // we only care about equality comparisons. |
| 2659 | (SeenZero || (DAG.isKnownNeverNaN(LHS) && DAG.isKnownNeverNaN(RHS)))) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2660 | // If unsafe fp math optimization is enabled and there are no othter uses of |
| 2661 | // the CMP operands, and the condition code is EQ oe NE, we can optimize it |
| 2662 | // to an integer comparison. |
| 2663 | if (CC == ISD::SETOEQ) |
| 2664 | CC = ISD::SETEQ; |
| 2665 | else if (CC == ISD::SETUNE) |
| 2666 | CC = ISD::SETNE; |
| 2667 | |
| 2668 | SDValue ARMcc; |
| 2669 | if (LHS.getValueType() == MVT::f32) { |
| 2670 | LHS = bitcastf32Toi32(LHS, DAG); |
| 2671 | RHS = bitcastf32Toi32(RHS, DAG); |
| 2672 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMcc, DAG, dl); |
| 2673 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| 2674 | return DAG.getNode(ARMISD::BRCOND, dl, MVT::Other, |
| 2675 | Chain, Dest, ARMcc, CCR, Cmp); |
| 2676 | } |
| 2677 | |
| 2678 | SDValue LHS1, LHS2; |
| 2679 | SDValue RHS1, RHS2; |
| 2680 | expandf64Toi32(LHS, DAG, LHS1, LHS2); |
| 2681 | expandf64Toi32(RHS, DAG, RHS1, RHS2); |
| 2682 | ARMCC::CondCodes CondCode = IntCCToARMCC(CC); |
| 2683 | ARMcc = DAG.getConstant(CondCode, MVT::i32); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 2684 | SDVTList VTList = DAG.getVTList(MVT::Other, MVT::Glue); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2685 | SDValue Ops[] = { Chain, ARMcc, LHS1, LHS2, RHS1, RHS2, Dest }; |
| 2686 | return DAG.getNode(ARMISD::BCC_i64, dl, VTList, Ops, 7); |
| 2687 | } |
| 2688 | |
| 2689 | return SDValue(); |
| 2690 | } |
| 2691 | |
| 2692 | SDValue ARMTargetLowering::LowerBR_CC(SDValue Op, SelectionDAG &DAG) const { |
| 2693 | SDValue Chain = Op.getOperand(0); |
| 2694 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get(); |
| 2695 | SDValue LHS = Op.getOperand(2); |
| 2696 | SDValue RHS = Op.getOperand(3); |
| 2697 | SDValue Dest = Op.getOperand(4); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2698 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2699 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2700 | if (LHS.getValueType() == MVT::i32) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2701 | SDValue ARMcc; |
| 2702 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMcc, DAG, dl); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2703 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2704 | return DAG.getNode(ARMISD::BRCOND, dl, MVT::Other, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2705 | Chain, Dest, ARMcc, CCR, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2706 | } |
| 2707 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2708 | assert(LHS.getValueType() == MVT::f32 || LHS.getValueType() == MVT::f64); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2709 | |
| 2710 | if (UnsafeFPMath && |
| 2711 | (CC == ISD::SETEQ || CC == ISD::SETOEQ || |
| 2712 | CC == ISD::SETNE || CC == ISD::SETUNE)) { |
| 2713 | SDValue Result = OptimizeVFPBrcond(Op, DAG); |
| 2714 | if (Result.getNode()) |
| 2715 | return Result; |
| 2716 | } |
| 2717 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2718 | ARMCC::CondCodes CondCode, CondCode2; |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 2719 | FPCCToARMCC(CC, CondCode, CondCode2); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2720 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2721 | SDValue ARMcc = DAG.getConstant(CondCode, MVT::i32); |
| 2722 | SDValue Cmp = getVFPCmp(LHS, RHS, DAG, dl); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2723 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 2724 | SDVTList VTList = DAG.getVTList(MVT::Other, MVT::Glue); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2725 | SDValue Ops[] = { Chain, Dest, ARMcc, CCR, Cmp }; |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2726 | SDValue Res = DAG.getNode(ARMISD::BRCOND, dl, VTList, Ops, 5); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2727 | if (CondCode2 != ARMCC::AL) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2728 | ARMcc = DAG.getConstant(CondCode2, MVT::i32); |
| 2729 | SDValue Ops[] = { Res, Dest, ARMcc, CCR, Res.getValue(1) }; |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2730 | Res = DAG.getNode(ARMISD::BRCOND, dl, VTList, Ops, 5); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2731 | } |
| 2732 | return Res; |
| 2733 | } |
| 2734 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2735 | SDValue ARMTargetLowering::LowerBR_JT(SDValue Op, SelectionDAG &DAG) const { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2736 | SDValue Chain = Op.getOperand(0); |
| 2737 | SDValue Table = Op.getOperand(1); |
| 2738 | SDValue Index = Op.getOperand(2); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2739 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2740 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2741 | EVT PTy = getPointerTy(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2742 | JumpTableSDNode *JT = cast<JumpTableSDNode>(Table); |
| 2743 | ARMFunctionInfo *AFI = DAG.getMachineFunction().getInfo<ARMFunctionInfo>(); |
Bob Wilson | 3eadf00 | 2009-07-14 18:44:34 +0000 | [diff] [blame] | 2744 | SDValue UId = DAG.getConstant(AFI->createJumpTableUId(), PTy); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2745 | SDValue JTI = DAG.getTargetJumpTable(JT->getIndex(), PTy); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2746 | Table = DAG.getNode(ARMISD::WrapperJT, dl, MVT::i32, JTI, UId); |
Evan Cheng | e7c329b | 2009-07-28 20:53:24 +0000 | [diff] [blame] | 2747 | Index = DAG.getNode(ISD::MUL, dl, PTy, Index, DAG.getConstant(4, PTy)); |
| 2748 | SDValue Addr = DAG.getNode(ISD::ADD, dl, PTy, Index, Table); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 2749 | if (Subtarget->isThumb2()) { |
| 2750 | // Thumb2 uses a two-level jump. That is, it jumps into the jump table |
| 2751 | // which does another jump to the destination. This also makes it easier |
| 2752 | // to translate it to TBB / TBH later. |
| 2753 | // FIXME: This might not work if the function is extremely large. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2754 | return DAG.getNode(ARMISD::BR2_JT, dl, MVT::Other, Chain, |
Evan Cheng | 5657c01 | 2009-07-29 02:18:14 +0000 | [diff] [blame] | 2755 | Addr, Op.getOperand(2), JTI, UId); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 2756 | } |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 2757 | if (getTargetMachine().getRelocationModel() == Reloc::PIC_) { |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2758 | Addr = DAG.getLoad((EVT)MVT::i32, dl, Chain, Addr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2759 | MachinePointerInfo::getJumpTable(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 2760 | false, false, 0); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 2761 | Chain = Addr.getValue(1); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2762 | Addr = DAG.getNode(ISD::ADD, dl, PTy, Addr, Table); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2763 | 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] | 2764 | } else { |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2765 | Addr = DAG.getLoad(PTy, dl, Chain, Addr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2766 | MachinePointerInfo::getJumpTable(), false, false, 0); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 2767 | Chain = Addr.getValue(1); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2768 | 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] | 2769 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2770 | } |
| 2771 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 2772 | static SDValue LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG) { |
| 2773 | DebugLoc dl = Op.getDebugLoc(); |
| 2774 | unsigned Opc; |
| 2775 | |
| 2776 | switch (Op.getOpcode()) { |
| 2777 | default: |
| 2778 | assert(0 && "Invalid opcode!"); |
| 2779 | case ISD::FP_TO_SINT: |
| 2780 | Opc = ARMISD::FTOSI; |
| 2781 | break; |
| 2782 | case ISD::FP_TO_UINT: |
| 2783 | Opc = ARMISD::FTOUI; |
| 2784 | break; |
| 2785 | } |
| 2786 | Op = DAG.getNode(Opc, dl, MVT::f32, Op.getOperand(0)); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2787 | return DAG.getNode(ISD::BITCAST, dl, MVT::i32, Op); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 2788 | } |
| 2789 | |
| 2790 | static SDValue LowerINT_TO_FP(SDValue Op, SelectionDAG &DAG) { |
| 2791 | EVT VT = Op.getValueType(); |
| 2792 | DebugLoc dl = Op.getDebugLoc(); |
| 2793 | unsigned Opc; |
| 2794 | |
| 2795 | switch (Op.getOpcode()) { |
| 2796 | default: |
| 2797 | assert(0 && "Invalid opcode!"); |
| 2798 | case ISD::SINT_TO_FP: |
| 2799 | Opc = ARMISD::SITOF; |
| 2800 | break; |
| 2801 | case ISD::UINT_TO_FP: |
| 2802 | Opc = ARMISD::UITOF; |
| 2803 | break; |
| 2804 | } |
| 2805 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2806 | Op = DAG.getNode(ISD::BITCAST, dl, MVT::f32, Op.getOperand(0)); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 2807 | return DAG.getNode(Opc, dl, VT, Op); |
| 2808 | } |
| 2809 | |
Evan Cheng | 515fe3a | 2010-07-08 02:08:50 +0000 | [diff] [blame] | 2810 | SDValue ARMTargetLowering::LowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2811 | // Implement fcopysign with a fabs and a conditional fneg. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2812 | SDValue Tmp0 = Op.getOperand(0); |
| 2813 | SDValue Tmp1 = Op.getOperand(1); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2814 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2815 | EVT VT = Op.getValueType(); |
| 2816 | EVT SrcVT = Tmp1.getValueType(); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2817 | SDValue AbsVal = DAG.getNode(ISD::FABS, dl, VT, Tmp0); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2818 | SDValue ARMcc = DAG.getConstant(ARMCC::LT, MVT::i32); |
Evan Cheng | 515fe3a | 2010-07-08 02:08:50 +0000 | [diff] [blame] | 2819 | SDValue FP0 = DAG.getConstantFP(0.0, SrcVT); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2820 | SDValue Cmp = getVFPCmp(Tmp1, FP0, DAG, dl); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2821 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2822 | return DAG.getNode(ARMISD::CNEG, dl, VT, AbsVal, AbsVal, ARMcc, CCR, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2823 | } |
| 2824 | |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 2825 | SDValue ARMTargetLowering::LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const{ |
| 2826 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2827 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 2828 | MFI->setReturnAddressIsTaken(true); |
| 2829 | |
| 2830 | EVT VT = Op.getValueType(); |
| 2831 | DebugLoc dl = Op.getDebugLoc(); |
| 2832 | unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
| 2833 | if (Depth) { |
| 2834 | SDValue FrameAddr = LowerFRAMEADDR(Op, DAG); |
| 2835 | SDValue Offset = DAG.getConstant(4, MVT::i32); |
| 2836 | return DAG.getLoad(VT, dl, DAG.getEntryNode(), |
| 2837 | DAG.getNode(ISD::ADD, dl, VT, FrameAddr, Offset), |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2838 | MachinePointerInfo(), false, false, 0); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 2839 | } |
| 2840 | |
| 2841 | // Return LR, which contains the return address. Mark it an implicit live-in. |
Devang Patel | e9a7ea6 | 2011-01-31 21:38:14 +0000 | [diff] [blame] | 2842 | unsigned Reg = MF.addLiveIn(ARM::LR, getRegClassFor(MVT::i32), dl); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 2843 | return DAG.getCopyFromReg(DAG.getEntryNode(), dl, Reg, VT); |
| 2844 | } |
| 2845 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2846 | SDValue ARMTargetLowering::LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const { |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 2847 | MachineFrameInfo *MFI = DAG.getMachineFunction().getFrameInfo(); |
| 2848 | MFI->setFrameAddressIsTaken(true); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 2849 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2850 | EVT VT = Op.getValueType(); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 2851 | DebugLoc dl = Op.getDebugLoc(); // FIXME probably not meaningful |
| 2852 | unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
Evan Cheng | cd82861 | 2009-06-18 23:14:30 +0000 | [diff] [blame] | 2853 | unsigned FrameReg = (Subtarget->isThumb() || Subtarget->isTargetDarwin()) |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 2854 | ? ARM::R7 : ARM::R11; |
| 2855 | SDValue FrameAddr = DAG.getCopyFromReg(DAG.getEntryNode(), dl, FrameReg, VT); |
| 2856 | while (Depth--) |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2857 | FrameAddr = DAG.getLoad(VT, dl, DAG.getEntryNode(), FrameAddr, |
| 2858 | MachinePointerInfo(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 2859 | false, false, 0); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 2860 | return FrameAddr; |
| 2861 | } |
| 2862 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2863 | /// ExpandBITCAST - If the target supports VFP, this function is called to |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 2864 | /// expand a bit convert where either the source or destination type is i64 to |
| 2865 | /// use a VMOVDRR or VMOVRRD node. This should not be done when the non-i64 |
| 2866 | /// operand type is illegal (e.g., v2f32 for a target that doesn't support |
| 2867 | /// vectors), since the legalizer won't know what to do with that. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2868 | static SDValue ExpandBITCAST(SDNode *N, SelectionDAG &DAG) { |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 2869 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 2870 | DebugLoc dl = N->getDebugLoc(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2871 | SDValue Op = N->getOperand(0); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 2872 | |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 2873 | // This function is only supposed to be called for i64 types, either as the |
| 2874 | // source or destination of the bit convert. |
| 2875 | EVT SrcVT = Op.getValueType(); |
| 2876 | EVT DstVT = N->getValueType(0); |
| 2877 | assert((SrcVT == MVT::i64 || DstVT == MVT::i64) && |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2878 | "ExpandBITCAST called for non-i64 type"); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 2879 | |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 2880 | // Turn i64->f64 into VMOVDRR. |
| 2881 | if (SrcVT == MVT::i64 && TLI.isTypeLegal(DstVT)) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2882 | SDValue Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Op, |
| 2883 | DAG.getConstant(0, MVT::i32)); |
| 2884 | SDValue Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Op, |
| 2885 | DAG.getConstant(1, MVT::i32)); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2886 | return DAG.getNode(ISD::BITCAST, dl, DstVT, |
Bob Wilson | 1114f56 | 2010-06-11 22:45:25 +0000 | [diff] [blame] | 2887 | DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi)); |
Evan Cheng | c7c7729 | 2008-11-04 19:57:48 +0000 | [diff] [blame] | 2888 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2889 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 2890 | // Turn f64->i64 into VMOVRRD. |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 2891 | if (DstVT == MVT::i64 && TLI.isTypeLegal(SrcVT)) { |
| 2892 | SDValue Cvt = DAG.getNode(ARMISD::VMOVRRD, dl, |
| 2893 | DAG.getVTList(MVT::i32, MVT::i32), &Op, 1); |
| 2894 | // Merge the pieces into a single i64 value. |
| 2895 | return DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Cvt, Cvt.getValue(1)); |
| 2896 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2897 | |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 2898 | return SDValue(); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 2899 | } |
| 2900 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2901 | /// getZeroVector - Returns a vector of specified type with all zero elements. |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 2902 | /// Zero vectors are used to represent vector negation and in those cases |
| 2903 | /// will be implemented with the NEON VNEG instruction. However, VNEG does |
| 2904 | /// not support i64 elements, so sometimes the zero vectors will need to be |
| 2905 | /// explicitly constructed. Regardless, use a canonical VMOV to create the |
| 2906 | /// zero vector. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2907 | static SDValue getZeroVector(EVT VT, SelectionDAG &DAG, DebugLoc dl) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2908 | assert(VT.isVector() && "Expected a vector type"); |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 2909 | // The canonical modified immediate encoding of a zero vector is....0! |
| 2910 | SDValue EncodedVal = DAG.getTargetConstant(0, MVT::i32); |
| 2911 | EVT VmovVT = VT.is128BitVector() ? MVT::v4i32 : MVT::v2i32; |
| 2912 | SDValue Vmov = DAG.getNode(ARMISD::VMOVIMM, dl, VmovVT, EncodedVal); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2913 | return DAG.getNode(ISD::BITCAST, dl, VT, Vmov); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2914 | } |
| 2915 | |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 2916 | /// LowerShiftRightParts - Lower SRA_PARTS, which returns two |
| 2917 | /// 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] | 2918 | SDValue ARMTargetLowering::LowerShiftRightParts(SDValue Op, |
| 2919 | SelectionDAG &DAG) const { |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 2920 | assert(Op.getNumOperands() == 3 && "Not a double-shift!"); |
| 2921 | EVT VT = Op.getValueType(); |
| 2922 | unsigned VTBits = VT.getSizeInBits(); |
| 2923 | DebugLoc dl = Op.getDebugLoc(); |
| 2924 | SDValue ShOpLo = Op.getOperand(0); |
| 2925 | SDValue ShOpHi = Op.getOperand(1); |
| 2926 | SDValue ShAmt = Op.getOperand(2); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2927 | SDValue ARMcc; |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 2928 | unsigned Opc = (Op.getOpcode() == ISD::SRA_PARTS) ? ISD::SRA : ISD::SRL; |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 2929 | |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 2930 | assert(Op.getOpcode() == ISD::SRA_PARTS || Op.getOpcode() == ISD::SRL_PARTS); |
| 2931 | |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 2932 | SDValue RevShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, |
| 2933 | DAG.getConstant(VTBits, MVT::i32), ShAmt); |
| 2934 | SDValue Tmp1 = DAG.getNode(ISD::SRL, dl, VT, ShOpLo, ShAmt); |
| 2935 | SDValue ExtraShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, ShAmt, |
| 2936 | DAG.getConstant(VTBits, MVT::i32)); |
| 2937 | SDValue Tmp2 = DAG.getNode(ISD::SHL, dl, VT, ShOpHi, RevShAmt); |
| 2938 | SDValue FalseVal = DAG.getNode(ISD::OR, dl, VT, Tmp1, Tmp2); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 2939 | SDValue TrueVal = DAG.getNode(Opc, dl, VT, ShOpHi, ExtraShAmt); |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 2940 | |
| 2941 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| 2942 | SDValue Cmp = getARMCmp(ExtraShAmt, DAG.getConstant(0, MVT::i32), ISD::SETGE, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2943 | ARMcc, DAG, dl); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 2944 | SDValue Hi = DAG.getNode(Opc, dl, VT, ShOpHi, ShAmt); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2945 | SDValue Lo = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, ARMcc, |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 2946 | CCR, Cmp); |
| 2947 | |
| 2948 | SDValue Ops[2] = { Lo, Hi }; |
| 2949 | return DAG.getMergeValues(Ops, 2, dl); |
| 2950 | } |
| 2951 | |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 2952 | /// LowerShiftLeftParts - Lower SHL_PARTS, which returns two |
| 2953 | /// 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] | 2954 | SDValue ARMTargetLowering::LowerShiftLeftParts(SDValue Op, |
| 2955 | SelectionDAG &DAG) const { |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 2956 | assert(Op.getNumOperands() == 3 && "Not a double-shift!"); |
| 2957 | EVT VT = Op.getValueType(); |
| 2958 | unsigned VTBits = VT.getSizeInBits(); |
| 2959 | DebugLoc dl = Op.getDebugLoc(); |
| 2960 | SDValue ShOpLo = Op.getOperand(0); |
| 2961 | SDValue ShOpHi = Op.getOperand(1); |
| 2962 | SDValue ShAmt = Op.getOperand(2); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2963 | SDValue ARMcc; |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 2964 | |
| 2965 | assert(Op.getOpcode() == ISD::SHL_PARTS); |
| 2966 | SDValue RevShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, |
| 2967 | DAG.getConstant(VTBits, MVT::i32), ShAmt); |
| 2968 | SDValue Tmp1 = DAG.getNode(ISD::SRL, dl, VT, ShOpLo, RevShAmt); |
| 2969 | SDValue ExtraShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, ShAmt, |
| 2970 | DAG.getConstant(VTBits, MVT::i32)); |
| 2971 | SDValue Tmp2 = DAG.getNode(ISD::SHL, dl, VT, ShOpHi, ShAmt); |
| 2972 | SDValue Tmp3 = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ExtraShAmt); |
| 2973 | |
| 2974 | SDValue FalseVal = DAG.getNode(ISD::OR, dl, VT, Tmp1, Tmp2); |
| 2975 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| 2976 | SDValue Cmp = getARMCmp(ExtraShAmt, DAG.getConstant(0, MVT::i32), ISD::SETGE, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2977 | ARMcc, DAG, dl); |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 2978 | SDValue Lo = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ShAmt); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2979 | SDValue Hi = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, Tmp3, ARMcc, |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 2980 | CCR, Cmp); |
| 2981 | |
| 2982 | SDValue Ops[2] = { Lo, Hi }; |
| 2983 | return DAG.getMergeValues(Ops, 2, dl); |
| 2984 | } |
| 2985 | |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 2986 | SDValue ARMTargetLowering::LowerFLT_ROUNDS_(SDValue Op, |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 2987 | SelectionDAG &DAG) const { |
| 2988 | // The rounding mode is in bits 23:22 of the FPSCR. |
| 2989 | // The ARM rounding mode value to FLT_ROUNDS mapping is 0->1, 1->2, 2->3, 3->0 |
| 2990 | // The formula we use to implement this is (((FPSCR + 1 << 22) >> 22) & 3) |
| 2991 | // so that the shift + and get folded into a bitfield extract. |
| 2992 | DebugLoc dl = Op.getDebugLoc(); |
| 2993 | SDValue FPSCR = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::i32, |
| 2994 | DAG.getConstant(Intrinsic::arm_get_fpscr, |
| 2995 | MVT::i32)); |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 2996 | SDValue FltRounds = DAG.getNode(ISD::ADD, dl, MVT::i32, FPSCR, |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 2997 | DAG.getConstant(1U << 22, MVT::i32)); |
| 2998 | SDValue RMODE = DAG.getNode(ISD::SRL, dl, MVT::i32, FltRounds, |
| 2999 | DAG.getConstant(22, MVT::i32)); |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 3000 | return DAG.getNode(ISD::AND, dl, MVT::i32, RMODE, |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 3001 | DAG.getConstant(3, MVT::i32)); |
| 3002 | } |
| 3003 | |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 3004 | static SDValue LowerCTTZ(SDNode *N, SelectionDAG &DAG, |
| 3005 | const ARMSubtarget *ST) { |
| 3006 | EVT VT = N->getValueType(0); |
| 3007 | DebugLoc dl = N->getDebugLoc(); |
| 3008 | |
| 3009 | if (!ST->hasV6T2Ops()) |
| 3010 | return SDValue(); |
| 3011 | |
| 3012 | SDValue rbit = DAG.getNode(ARMISD::RBIT, dl, VT, N->getOperand(0)); |
| 3013 | return DAG.getNode(ISD::CTLZ, dl, VT, rbit); |
| 3014 | } |
| 3015 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3016 | static SDValue LowerShift(SDNode *N, SelectionDAG &DAG, |
| 3017 | const ARMSubtarget *ST) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3018 | EVT VT = N->getValueType(0); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3019 | DebugLoc dl = N->getDebugLoc(); |
| 3020 | |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3021 | if (!VT.isVector()) |
| 3022 | return SDValue(); |
| 3023 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3024 | // Lower vector shifts on NEON to use VSHL. |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3025 | assert(ST->hasNEON() && "unexpected vector shift"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3026 | |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3027 | // Left shifts translate directly to the vshiftu intrinsic. |
| 3028 | if (N->getOpcode() == ISD::SHL) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3029 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT, |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3030 | DAG.getConstant(Intrinsic::arm_neon_vshiftu, MVT::i32), |
| 3031 | N->getOperand(0), N->getOperand(1)); |
| 3032 | |
| 3033 | assert((N->getOpcode() == ISD::SRA || |
| 3034 | N->getOpcode() == ISD::SRL) && "unexpected vector shift opcode"); |
| 3035 | |
| 3036 | // NEON uses the same intrinsics for both left and right shifts. For |
| 3037 | // right shifts, the shift amounts are negative, so negate the vector of |
| 3038 | // shift amounts. |
| 3039 | EVT ShiftVT = N->getOperand(1).getValueType(); |
| 3040 | SDValue NegatedCount = DAG.getNode(ISD::SUB, dl, ShiftVT, |
| 3041 | getZeroVector(ShiftVT, DAG, dl), |
| 3042 | N->getOperand(1)); |
| 3043 | Intrinsic::ID vshiftInt = (N->getOpcode() == ISD::SRA ? |
| 3044 | Intrinsic::arm_neon_vshifts : |
| 3045 | Intrinsic::arm_neon_vshiftu); |
| 3046 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT, |
| 3047 | DAG.getConstant(vshiftInt, MVT::i32), |
| 3048 | N->getOperand(0), NegatedCount); |
| 3049 | } |
| 3050 | |
| 3051 | static SDValue Expand64BitShift(SDNode *N, SelectionDAG &DAG, |
| 3052 | const ARMSubtarget *ST) { |
| 3053 | EVT VT = N->getValueType(0); |
| 3054 | DebugLoc dl = N->getDebugLoc(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3055 | |
Eli Friedman | ce392eb | 2009-08-22 03:13:10 +0000 | [diff] [blame] | 3056 | // We can get here for a node like i32 = ISD::SHL i32, i64 |
| 3057 | if (VT != MVT::i64) |
| 3058 | return SDValue(); |
| 3059 | |
| 3060 | assert((N->getOpcode() == ISD::SRL || N->getOpcode() == ISD::SRA) && |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3061 | "Unknown shift to lower!"); |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 3062 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3063 | // We only lower SRA, SRL of 1 here, all others use generic lowering. |
| 3064 | if (!isa<ConstantSDNode>(N->getOperand(1)) || |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 3065 | cast<ConstantSDNode>(N->getOperand(1))->getZExtValue() != 1) |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 3066 | return SDValue(); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3067 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3068 | // If we are in thumb mode, we don't have RRX. |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 3069 | if (ST->isThumb1Only()) return SDValue(); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3070 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3071 | // 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] | 3072 | 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] | 3073 | DAG.getConstant(0, MVT::i32)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3074 | 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] | 3075 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3076 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3077 | // First, build a SRA_FLAG/SRL_FLAG op, which shifts the top part by one and |
| 3078 | // captures the result into a carry flag. |
| 3079 | unsigned Opc = N->getOpcode() == ISD::SRL ? ARMISD::SRL_FLAG:ARMISD::SRA_FLAG; |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 3080 | 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] | 3081 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3082 | // 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] | 3083 | Lo = DAG.getNode(ARMISD::RRX, dl, MVT::i32, Lo, Hi.getValue(1)); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3084 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3085 | // Merge the pieces into a single i64 value. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3086 | return DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Lo, Hi); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3087 | } |
| 3088 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3089 | static SDValue LowerVSETCC(SDValue Op, SelectionDAG &DAG) { |
| 3090 | SDValue TmpOp0, TmpOp1; |
| 3091 | bool Invert = false; |
| 3092 | bool Swap = false; |
| 3093 | unsigned Opc = 0; |
| 3094 | |
| 3095 | SDValue Op0 = Op.getOperand(0); |
| 3096 | SDValue Op1 = Op.getOperand(1); |
| 3097 | SDValue CC = Op.getOperand(2); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3098 | EVT VT = Op.getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3099 | ISD::CondCode SetCCOpcode = cast<CondCodeSDNode>(CC)->get(); |
| 3100 | DebugLoc dl = Op.getDebugLoc(); |
| 3101 | |
| 3102 | if (Op.getOperand(1).getValueType().isFloatingPoint()) { |
| 3103 | switch (SetCCOpcode) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 3104 | default: llvm_unreachable("Illegal FP comparison"); break; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3105 | case ISD::SETUNE: |
| 3106 | case ISD::SETNE: Invert = true; // Fallthrough |
| 3107 | case ISD::SETOEQ: |
| 3108 | case ISD::SETEQ: Opc = ARMISD::VCEQ; break; |
| 3109 | case ISD::SETOLT: |
| 3110 | case ISD::SETLT: Swap = true; // Fallthrough |
| 3111 | case ISD::SETOGT: |
| 3112 | case ISD::SETGT: Opc = ARMISD::VCGT; break; |
| 3113 | case ISD::SETOLE: |
| 3114 | case ISD::SETLE: Swap = true; // Fallthrough |
| 3115 | case ISD::SETOGE: |
| 3116 | case ISD::SETGE: Opc = ARMISD::VCGE; break; |
| 3117 | case ISD::SETUGE: Swap = true; // Fallthrough |
| 3118 | case ISD::SETULE: Invert = true; Opc = ARMISD::VCGT; break; |
| 3119 | case ISD::SETUGT: Swap = true; // Fallthrough |
| 3120 | case ISD::SETULT: Invert = true; Opc = ARMISD::VCGE; break; |
| 3121 | case ISD::SETUEQ: Invert = true; // Fallthrough |
| 3122 | case ISD::SETONE: |
| 3123 | // Expand this to (OLT | OGT). |
| 3124 | TmpOp0 = Op0; |
| 3125 | TmpOp1 = Op1; |
| 3126 | Opc = ISD::OR; |
| 3127 | Op0 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp1, TmpOp0); |
| 3128 | Op1 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp0, TmpOp1); |
| 3129 | break; |
| 3130 | case ISD::SETUO: Invert = true; // Fallthrough |
| 3131 | case ISD::SETO: |
| 3132 | // Expand this to (OLT | OGE). |
| 3133 | TmpOp0 = Op0; |
| 3134 | TmpOp1 = Op1; |
| 3135 | Opc = ISD::OR; |
| 3136 | Op0 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp1, TmpOp0); |
| 3137 | Op1 = DAG.getNode(ARMISD::VCGE, dl, VT, TmpOp0, TmpOp1); |
| 3138 | break; |
| 3139 | } |
| 3140 | } else { |
| 3141 | // Integer comparisons. |
| 3142 | switch (SetCCOpcode) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 3143 | default: llvm_unreachable("Illegal integer comparison"); break; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3144 | case ISD::SETNE: Invert = true; |
| 3145 | case ISD::SETEQ: Opc = ARMISD::VCEQ; break; |
| 3146 | case ISD::SETLT: Swap = true; |
| 3147 | case ISD::SETGT: Opc = ARMISD::VCGT; break; |
| 3148 | case ISD::SETLE: Swap = true; |
| 3149 | case ISD::SETGE: Opc = ARMISD::VCGE; break; |
| 3150 | case ISD::SETULT: Swap = true; |
| 3151 | case ISD::SETUGT: Opc = ARMISD::VCGTU; break; |
| 3152 | case ISD::SETULE: Swap = true; |
| 3153 | case ISD::SETUGE: Opc = ARMISD::VCGEU; break; |
| 3154 | } |
| 3155 | |
Nick Lewycky | 7f6aa2b | 2009-07-08 03:04:38 +0000 | [diff] [blame] | 3156 | // Detect VTST (Vector Test Bits) = icmp ne (and (op0, op1), zero). |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3157 | if (Opc == ARMISD::VCEQ) { |
| 3158 | |
| 3159 | SDValue AndOp; |
| 3160 | if (ISD::isBuildVectorAllZeros(Op1.getNode())) |
| 3161 | AndOp = Op0; |
| 3162 | else if (ISD::isBuildVectorAllZeros(Op0.getNode())) |
| 3163 | AndOp = Op1; |
| 3164 | |
| 3165 | // Ignore bitconvert. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3166 | if (AndOp.getNode() && AndOp.getOpcode() == ISD::BITCAST) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3167 | AndOp = AndOp.getOperand(0); |
| 3168 | |
| 3169 | if (AndOp.getNode() && AndOp.getOpcode() == ISD::AND) { |
| 3170 | Opc = ARMISD::VTST; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3171 | Op0 = DAG.getNode(ISD::BITCAST, dl, VT, AndOp.getOperand(0)); |
| 3172 | Op1 = DAG.getNode(ISD::BITCAST, dl, VT, AndOp.getOperand(1)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3173 | Invert = !Invert; |
| 3174 | } |
| 3175 | } |
| 3176 | } |
| 3177 | |
| 3178 | if (Swap) |
| 3179 | std::swap(Op0, Op1); |
| 3180 | |
Owen Anderson | c24cb35 | 2010-11-08 23:21:22 +0000 | [diff] [blame] | 3181 | // If one of the operands is a constant vector zero, attempt to fold the |
| 3182 | // comparison to a specialized compare-against-zero form. |
| 3183 | SDValue SingleOp; |
| 3184 | if (ISD::isBuildVectorAllZeros(Op1.getNode())) |
| 3185 | SingleOp = Op0; |
| 3186 | else if (ISD::isBuildVectorAllZeros(Op0.getNode())) { |
| 3187 | if (Opc == ARMISD::VCGE) |
| 3188 | Opc = ARMISD::VCLEZ; |
| 3189 | else if (Opc == ARMISD::VCGT) |
| 3190 | Opc = ARMISD::VCLTZ; |
| 3191 | SingleOp = Op1; |
| 3192 | } |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3193 | |
Owen Anderson | c24cb35 | 2010-11-08 23:21:22 +0000 | [diff] [blame] | 3194 | SDValue Result; |
| 3195 | if (SingleOp.getNode()) { |
| 3196 | switch (Opc) { |
| 3197 | case ARMISD::VCEQ: |
| 3198 | Result = DAG.getNode(ARMISD::VCEQZ, dl, VT, SingleOp); break; |
| 3199 | case ARMISD::VCGE: |
| 3200 | Result = DAG.getNode(ARMISD::VCGEZ, dl, VT, SingleOp); break; |
| 3201 | case ARMISD::VCLEZ: |
| 3202 | Result = DAG.getNode(ARMISD::VCLEZ, dl, VT, SingleOp); break; |
| 3203 | case ARMISD::VCGT: |
| 3204 | Result = DAG.getNode(ARMISD::VCGTZ, dl, VT, SingleOp); break; |
| 3205 | case ARMISD::VCLTZ: |
| 3206 | Result = DAG.getNode(ARMISD::VCLTZ, dl, VT, SingleOp); break; |
| 3207 | default: |
| 3208 | Result = DAG.getNode(Opc, dl, VT, Op0, Op1); |
| 3209 | } |
| 3210 | } else { |
| 3211 | Result = DAG.getNode(Opc, dl, VT, Op0, Op1); |
| 3212 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3213 | |
| 3214 | if (Invert) |
| 3215 | Result = DAG.getNOT(dl, Result, VT); |
| 3216 | |
| 3217 | return Result; |
| 3218 | } |
| 3219 | |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 3220 | /// isNEONModifiedImm - Check if the specified splat value corresponds to a |
| 3221 | /// valid vector constant for a NEON instruction with a "modified immediate" |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3222 | /// operand (e.g., VMOV). If so, return the encoded value. |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 3223 | static SDValue isNEONModifiedImm(uint64_t SplatBits, uint64_t SplatUndef, |
| 3224 | unsigned SplatBitSize, SelectionDAG &DAG, |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3225 | EVT &VT, bool is128Bits, NEONModImmType type) { |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3226 | unsigned OpCmode, Imm; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3227 | |
Bob Wilson | 827b210 | 2010-06-15 19:05:35 +0000 | [diff] [blame] | 3228 | // SplatBitSize is set to the smallest size that splats the vector, so a |
| 3229 | // zero vector will always have SplatBitSize == 8. However, NEON modified |
| 3230 | // immediate instructions others than VMOV do not support the 8-bit encoding |
| 3231 | // of a zero vector, and the default encoding of zero is supposed to be the |
| 3232 | // 32-bit version. |
| 3233 | if (SplatBits == 0) |
| 3234 | SplatBitSize = 32; |
| 3235 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3236 | switch (SplatBitSize) { |
| 3237 | case 8: |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3238 | if (type != VMOVModImm) |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 3239 | return SDValue(); |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3240 | // Any 1-byte value is OK. Op=0, Cmode=1110. |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3241 | assert((SplatBits & ~0xff) == 0 && "one byte splat value is too big"); |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3242 | OpCmode = 0xe; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3243 | Imm = SplatBits; |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3244 | VT = is128Bits ? MVT::v16i8 : MVT::v8i8; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3245 | break; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3246 | |
| 3247 | case 16: |
| 3248 | // 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] | 3249 | VT = is128Bits ? MVT::v8i16 : MVT::v4i16; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3250 | if ((SplatBits & ~0xff) == 0) { |
| 3251 | // Value = 0x00nn: Op=x, Cmode=100x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3252 | OpCmode = 0x8; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3253 | Imm = SplatBits; |
| 3254 | break; |
| 3255 | } |
| 3256 | if ((SplatBits & ~0xff00) == 0) { |
| 3257 | // Value = 0xnn00: Op=x, Cmode=101x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3258 | OpCmode = 0xa; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3259 | Imm = SplatBits >> 8; |
| 3260 | break; |
| 3261 | } |
| 3262 | return SDValue(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3263 | |
| 3264 | case 32: |
| 3265 | // NEON's 32-bit VMOV supports splat values where: |
| 3266 | // * only one byte is nonzero, or |
| 3267 | // * the least significant byte is 0xff and the second byte is nonzero, or |
| 3268 | // * the least significant 2 bytes are 0xff and the third is nonzero. |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3269 | VT = is128Bits ? MVT::v4i32 : MVT::v2i32; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3270 | if ((SplatBits & ~0xff) == 0) { |
| 3271 | // Value = 0x000000nn: Op=x, Cmode=000x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3272 | OpCmode = 0; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3273 | Imm = SplatBits; |
| 3274 | break; |
| 3275 | } |
| 3276 | if ((SplatBits & ~0xff00) == 0) { |
| 3277 | // Value = 0x0000nn00: Op=x, Cmode=001x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3278 | OpCmode = 0x2; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3279 | Imm = SplatBits >> 8; |
| 3280 | break; |
| 3281 | } |
| 3282 | if ((SplatBits & ~0xff0000) == 0) { |
| 3283 | // Value = 0x00nn0000: Op=x, Cmode=010x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3284 | OpCmode = 0x4; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3285 | Imm = SplatBits >> 16; |
| 3286 | break; |
| 3287 | } |
| 3288 | if ((SplatBits & ~0xff000000) == 0) { |
| 3289 | // Value = 0xnn000000: Op=x, Cmode=011x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3290 | OpCmode = 0x6; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3291 | Imm = SplatBits >> 24; |
| 3292 | break; |
| 3293 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3294 | |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3295 | // cmode == 0b1100 and cmode == 0b1101 are not supported for VORR or VBIC |
| 3296 | if (type == OtherModImm) return SDValue(); |
| 3297 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3298 | if ((SplatBits & ~0xffff) == 0 && |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3299 | ((SplatBits | SplatUndef) & 0xff) == 0xff) { |
| 3300 | // Value = 0x0000nnff: Op=x, Cmode=1100. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3301 | OpCmode = 0xc; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3302 | Imm = SplatBits >> 8; |
| 3303 | SplatBits |= 0xff; |
| 3304 | break; |
| 3305 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3306 | |
| 3307 | if ((SplatBits & ~0xffffff) == 0 && |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3308 | ((SplatBits | SplatUndef) & 0xffff) == 0xffff) { |
| 3309 | // Value = 0x00nnffff: Op=x, Cmode=1101. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3310 | OpCmode = 0xd; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3311 | Imm = SplatBits >> 16; |
| 3312 | SplatBits |= 0xffff; |
| 3313 | break; |
| 3314 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3315 | |
| 3316 | // Note: there are a few 32-bit splat values (specifically: 00ffff00, |
| 3317 | // ff000000, ff0000ff, and ffff00ff) that are valid for VMOV.I64 but not |
| 3318 | // VMOV.I32. A (very) minor optimization would be to replicate the value |
| 3319 | // and fall through here to test for a valid 64-bit splat. But, then the |
| 3320 | // caller would also need to check and handle the change in size. |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3321 | return SDValue(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3322 | |
| 3323 | case 64: { |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3324 | if (type != VMOVModImm) |
Bob Wilson | 827b210 | 2010-06-15 19:05:35 +0000 | [diff] [blame] | 3325 | return SDValue(); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 3326 | // 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] | 3327 | uint64_t BitMask = 0xff; |
| 3328 | uint64_t Val = 0; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3329 | unsigned ImmMask = 1; |
| 3330 | Imm = 0; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3331 | for (int ByteNum = 0; ByteNum < 8; ++ByteNum) { |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3332 | if (((SplatBits | SplatUndef) & BitMask) == BitMask) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3333 | Val |= BitMask; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3334 | Imm |= ImmMask; |
| 3335 | } else if ((SplatBits & BitMask) != 0) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3336 | return SDValue(); |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3337 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3338 | BitMask <<= 8; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3339 | ImmMask <<= 1; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3340 | } |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3341 | // Op=1, Cmode=1110. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3342 | OpCmode = 0x1e; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3343 | SplatBits = Val; |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3344 | VT = is128Bits ? MVT::v2i64 : MVT::v1i64; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3345 | break; |
| 3346 | } |
| 3347 | |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3348 | default: |
Bob Wilson | dc076da | 2010-06-19 05:32:09 +0000 | [diff] [blame] | 3349 | llvm_unreachable("unexpected size for isNEONModifiedImm"); |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3350 | return SDValue(); |
| 3351 | } |
| 3352 | |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3353 | unsigned EncodedVal = ARM_AM::createNEONModImm(OpCmode, Imm); |
| 3354 | return DAG.getTargetConstant(EncodedVal, MVT::i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3355 | } |
| 3356 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3357 | static bool isVEXTMask(const SmallVectorImpl<int> &M, EVT VT, |
| 3358 | bool &ReverseVEXT, unsigned &Imm) { |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3359 | unsigned NumElts = VT.getVectorNumElements(); |
| 3360 | ReverseVEXT = false; |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3361 | |
| 3362 | // Assume that the first shuffle index is not UNDEF. Fail if it is. |
| 3363 | if (M[0] < 0) |
| 3364 | return false; |
| 3365 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3366 | Imm = M[0]; |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3367 | |
| 3368 | // If this is a VEXT shuffle, the immediate value is the index of the first |
| 3369 | // element. The other shuffle indices must be the successive elements after |
| 3370 | // the first one. |
| 3371 | unsigned ExpectedElt = Imm; |
| 3372 | for (unsigned i = 1; i < NumElts; ++i) { |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3373 | // Increment the expected index. If it wraps around, it may still be |
| 3374 | // a VEXT but the source vectors must be swapped. |
| 3375 | ExpectedElt += 1; |
| 3376 | if (ExpectedElt == NumElts * 2) { |
| 3377 | ExpectedElt = 0; |
| 3378 | ReverseVEXT = true; |
| 3379 | } |
| 3380 | |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3381 | if (M[i] < 0) continue; // ignore UNDEF indices |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3382 | if (ExpectedElt != static_cast<unsigned>(M[i])) |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3383 | return false; |
| 3384 | } |
| 3385 | |
| 3386 | // Adjust the index value if the source operands will be swapped. |
| 3387 | if (ReverseVEXT) |
| 3388 | Imm -= NumElts; |
| 3389 | |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3390 | return true; |
| 3391 | } |
| 3392 | |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 3393 | /// isVREVMask - Check if a vector shuffle corresponds to a VREV |
| 3394 | /// instruction with the specified blocksize. (The order of the elements |
| 3395 | /// within each block of the vector is reversed.) |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3396 | static bool isVREVMask(const SmallVectorImpl<int> &M, EVT VT, |
| 3397 | unsigned BlockSize) { |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 3398 | assert((BlockSize==16 || BlockSize==32 || BlockSize==64) && |
| 3399 | "Only possible block sizes for VREV are: 16, 32, 64"); |
| 3400 | |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 3401 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 3402 | if (EltSz == 64) |
| 3403 | return false; |
| 3404 | |
| 3405 | unsigned NumElts = VT.getVectorNumElements(); |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3406 | unsigned BlockElts = M[0] + 1; |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3407 | // If the first shuffle index is UNDEF, be optimistic. |
| 3408 | if (M[0] < 0) |
| 3409 | BlockElts = BlockSize / EltSz; |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 3410 | |
| 3411 | if (BlockSize <= EltSz || BlockSize != BlockElts * EltSz) |
| 3412 | return false; |
| 3413 | |
| 3414 | for (unsigned i = 0; i < NumElts; ++i) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3415 | if (M[i] < 0) continue; // ignore UNDEF indices |
| 3416 | if ((unsigned) M[i] != (i - i%BlockElts) + (BlockElts - 1 - i%BlockElts)) |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 3417 | return false; |
| 3418 | } |
| 3419 | |
| 3420 | return true; |
| 3421 | } |
| 3422 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3423 | static bool isVTRNMask(const SmallVectorImpl<int> &M, EVT VT, |
| 3424 | unsigned &WhichResult) { |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 3425 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3426 | if (EltSz == 64) |
| 3427 | return false; |
| 3428 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3429 | unsigned NumElts = VT.getVectorNumElements(); |
| 3430 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3431 | for (unsigned i = 0; i < NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3432 | if ((M[i] >= 0 && (unsigned) M[i] != i + WhichResult) || |
| 3433 | (M[i+1] >= 0 && (unsigned) M[i+1] != i + NumElts + WhichResult)) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3434 | return false; |
| 3435 | } |
| 3436 | return true; |
| 3437 | } |
| 3438 | |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3439 | /// isVTRN_v_undef_Mask - Special case of isVTRNMask for canonical form of |
| 3440 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 3441 | /// Mask is e.g., <0, 0, 2, 2> instead of <0, 4, 2, 6>. |
| 3442 | static bool isVTRN_v_undef_Mask(const SmallVectorImpl<int> &M, EVT VT, |
| 3443 | unsigned &WhichResult) { |
| 3444 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3445 | if (EltSz == 64) |
| 3446 | return false; |
| 3447 | |
| 3448 | unsigned NumElts = VT.getVectorNumElements(); |
| 3449 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3450 | for (unsigned i = 0; i < NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3451 | if ((M[i] >= 0 && (unsigned) M[i] != i + WhichResult) || |
| 3452 | (M[i+1] >= 0 && (unsigned) M[i+1] != i + WhichResult)) |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3453 | return false; |
| 3454 | } |
| 3455 | return true; |
| 3456 | } |
| 3457 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3458 | static bool isVUZPMask(const SmallVectorImpl<int> &M, EVT VT, |
| 3459 | unsigned &WhichResult) { |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 3460 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3461 | if (EltSz == 64) |
| 3462 | return false; |
| 3463 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3464 | unsigned NumElts = VT.getVectorNumElements(); |
| 3465 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3466 | for (unsigned i = 0; i != NumElts; ++i) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3467 | if (M[i] < 0) continue; // ignore UNDEF indices |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3468 | if ((unsigned) M[i] != 2 * i + WhichResult) |
| 3469 | return false; |
| 3470 | } |
| 3471 | |
| 3472 | // 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] | 3473 | if (VT.is64BitVector() && EltSz == 32) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3474 | return false; |
| 3475 | |
| 3476 | return true; |
| 3477 | } |
| 3478 | |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3479 | /// isVUZP_v_undef_Mask - Special case of isVUZPMask for canonical form of |
| 3480 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 3481 | /// Mask is e.g., <0, 2, 0, 2> instead of <0, 2, 4, 6>, |
| 3482 | static bool isVUZP_v_undef_Mask(const SmallVectorImpl<int> &M, EVT VT, |
| 3483 | unsigned &WhichResult) { |
| 3484 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3485 | if (EltSz == 64) |
| 3486 | return false; |
| 3487 | |
| 3488 | unsigned Half = VT.getVectorNumElements() / 2; |
| 3489 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3490 | for (unsigned j = 0; j != 2; ++j) { |
| 3491 | unsigned Idx = WhichResult; |
| 3492 | for (unsigned i = 0; i != Half; ++i) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3493 | int MIdx = M[i + j * Half]; |
| 3494 | if (MIdx >= 0 && (unsigned) MIdx != Idx) |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3495 | return false; |
| 3496 | Idx += 2; |
| 3497 | } |
| 3498 | } |
| 3499 | |
| 3500 | // VUZP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32. |
| 3501 | if (VT.is64BitVector() && EltSz == 32) |
| 3502 | return false; |
| 3503 | |
| 3504 | return true; |
| 3505 | } |
| 3506 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3507 | static bool isVZIPMask(const SmallVectorImpl<int> &M, EVT VT, |
| 3508 | unsigned &WhichResult) { |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 3509 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3510 | if (EltSz == 64) |
| 3511 | return false; |
| 3512 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3513 | unsigned NumElts = VT.getVectorNumElements(); |
| 3514 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3515 | unsigned Idx = WhichResult * NumElts / 2; |
| 3516 | for (unsigned i = 0; i != NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3517 | if ((M[i] >= 0 && (unsigned) M[i] != Idx) || |
| 3518 | (M[i+1] >= 0 && (unsigned) M[i+1] != Idx + NumElts)) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3519 | return false; |
| 3520 | Idx += 1; |
| 3521 | } |
| 3522 | |
| 3523 | // 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] | 3524 | if (VT.is64BitVector() && EltSz == 32) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3525 | return false; |
| 3526 | |
| 3527 | return true; |
| 3528 | } |
| 3529 | |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3530 | /// isVZIP_v_undef_Mask - Special case of isVZIPMask for canonical form of |
| 3531 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 3532 | /// Mask is e.g., <0, 0, 1, 1> instead of <0, 4, 1, 5>. |
| 3533 | static bool isVZIP_v_undef_Mask(const SmallVectorImpl<int> &M, EVT VT, |
| 3534 | unsigned &WhichResult) { |
| 3535 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3536 | if (EltSz == 64) |
| 3537 | return false; |
| 3538 | |
| 3539 | unsigned NumElts = VT.getVectorNumElements(); |
| 3540 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3541 | unsigned Idx = WhichResult * NumElts / 2; |
| 3542 | for (unsigned i = 0; i != NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3543 | if ((M[i] >= 0 && (unsigned) M[i] != Idx) || |
| 3544 | (M[i+1] >= 0 && (unsigned) M[i+1] != Idx)) |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3545 | return false; |
| 3546 | Idx += 1; |
| 3547 | } |
| 3548 | |
| 3549 | // VZIP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32. |
| 3550 | if (VT.is64BitVector() && EltSz == 32) |
| 3551 | return false; |
| 3552 | |
| 3553 | return true; |
| 3554 | } |
| 3555 | |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 3556 | // If N is an integer constant that can be moved into a register in one |
| 3557 | // instruction, return an SDValue of such a constant (will become a MOV |
| 3558 | // instruction). Otherwise return null. |
| 3559 | static SDValue IsSingleInstrConstant(SDValue N, SelectionDAG &DAG, |
| 3560 | const ARMSubtarget *ST, DebugLoc dl) { |
| 3561 | uint64_t Val; |
| 3562 | if (!isa<ConstantSDNode>(N)) |
| 3563 | return SDValue(); |
| 3564 | Val = cast<ConstantSDNode>(N)->getZExtValue(); |
| 3565 | |
| 3566 | if (ST->isThumb1Only()) { |
| 3567 | if (Val <= 255 || ~Val <= 255) |
| 3568 | return DAG.getConstant(Val, MVT::i32); |
| 3569 | } else { |
| 3570 | if (ARM_AM::getSOImmVal(Val) != -1 || ARM_AM::getSOImmVal(~Val) != -1) |
| 3571 | return DAG.getConstant(Val, MVT::i32); |
| 3572 | } |
| 3573 | return SDValue(); |
| 3574 | } |
| 3575 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3576 | // If this is a case we can't handle, return null and let the default |
| 3577 | // expansion code take care of it. |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3578 | SDValue ARMTargetLowering::LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG, |
| 3579 | const ARMSubtarget *ST) const { |
Bob Wilson | d06791f | 2009-08-13 01:57:47 +0000 | [diff] [blame] | 3580 | BuildVectorSDNode *BVN = cast<BuildVectorSDNode>(Op.getNode()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3581 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3582 | EVT VT = Op.getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3583 | |
| 3584 | APInt SplatBits, SplatUndef; |
| 3585 | unsigned SplatBitSize; |
| 3586 | bool HasAnyUndefs; |
| 3587 | if (BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { |
Anton Korobeynikov | 71624cc | 2009-08-29 00:08:18 +0000 | [diff] [blame] | 3588 | if (SplatBitSize <= 64) { |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 3589 | // Check if an immediate VMOV works. |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3590 | EVT VmovVT; |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 3591 | SDValue Val = isNEONModifiedImm(SplatBits.getZExtValue(), |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3592 | SplatUndef.getZExtValue(), SplatBitSize, |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3593 | DAG, VmovVT, VT.is128BitVector(), |
| 3594 | VMOVModImm); |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3595 | if (Val.getNode()) { |
| 3596 | SDValue Vmov = DAG.getNode(ARMISD::VMOVIMM, dl, VmovVT, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3597 | return DAG.getNode(ISD::BITCAST, dl, VT, Vmov); |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3598 | } |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 3599 | |
| 3600 | // Try an immediate VMVN. |
| 3601 | uint64_t NegatedImm = (SplatBits.getZExtValue() ^ |
| 3602 | ((1LL << SplatBitSize) - 1)); |
| 3603 | Val = isNEONModifiedImm(NegatedImm, |
| 3604 | SplatUndef.getZExtValue(), SplatBitSize, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3605 | DAG, VmovVT, VT.is128BitVector(), |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3606 | VMVNModImm); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 3607 | if (Val.getNode()) { |
| 3608 | SDValue Vmov = DAG.getNode(ARMISD::VMVNIMM, dl, VmovVT, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3609 | return DAG.getNode(ISD::BITCAST, dl, VT, Vmov); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 3610 | } |
Anton Korobeynikov | 71624cc | 2009-08-29 00:08:18 +0000 | [diff] [blame] | 3611 | } |
Bob Wilson | cf661e2 | 2009-07-30 00:31:25 +0000 | [diff] [blame] | 3612 | } |
| 3613 | |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 3614 | // Scan through the operands to see if only one value is used. |
| 3615 | unsigned NumElts = VT.getVectorNumElements(); |
| 3616 | bool isOnlyLowElement = true; |
| 3617 | bool usesOnlyOneValue = true; |
| 3618 | bool isConstant = true; |
| 3619 | SDValue Value; |
| 3620 | for (unsigned i = 0; i < NumElts; ++i) { |
| 3621 | SDValue V = Op.getOperand(i); |
| 3622 | if (V.getOpcode() == ISD::UNDEF) |
| 3623 | continue; |
| 3624 | if (i > 0) |
| 3625 | isOnlyLowElement = false; |
| 3626 | if (!isa<ConstantFPSDNode>(V) && !isa<ConstantSDNode>(V)) |
| 3627 | isConstant = false; |
| 3628 | |
| 3629 | if (!Value.getNode()) |
| 3630 | Value = V; |
| 3631 | else if (V != Value) |
| 3632 | usesOnlyOneValue = false; |
| 3633 | } |
| 3634 | |
| 3635 | if (!Value.getNode()) |
| 3636 | return DAG.getUNDEF(VT); |
| 3637 | |
| 3638 | if (isOnlyLowElement) |
| 3639 | return DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, VT, Value); |
| 3640 | |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 3641 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 3642 | |
Dale Johannesen | 575cd14 | 2010-10-19 20:00:17 +0000 | [diff] [blame] | 3643 | // Use VDUP for non-constant splats. For f32 constant splats, reduce to |
| 3644 | // i32 and try again. |
| 3645 | if (usesOnlyOneValue && EltSize <= 32) { |
| 3646 | if (!isConstant) |
| 3647 | return DAG.getNode(ARMISD::VDUP, dl, VT, Value); |
| 3648 | if (VT.getVectorElementType().isFloatingPoint()) { |
| 3649 | SmallVector<SDValue, 8> Ops; |
| 3650 | for (unsigned i = 0; i < NumElts; ++i) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3651 | Ops.push_back(DAG.getNode(ISD::BITCAST, dl, MVT::i32, |
Dale Johannesen | 575cd14 | 2010-10-19 20:00:17 +0000 | [diff] [blame] | 3652 | Op.getOperand(i))); |
Nate Begeman | bf5be26 | 2010-11-10 21:35:41 +0000 | [diff] [blame] | 3653 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), MVT::i32, NumElts); |
| 3654 | SDValue Val = DAG.getNode(ISD::BUILD_VECTOR, dl, VecVT, &Ops[0], NumElts); |
Dale Johannesen | e4d3159 | 2010-10-20 22:03:37 +0000 | [diff] [blame] | 3655 | Val = LowerBUILD_VECTOR(Val, DAG, ST); |
| 3656 | if (Val.getNode()) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3657 | return DAG.getNode(ISD::BITCAST, dl, VT, Val); |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 3658 | } |
Dale Johannesen | 575cd14 | 2010-10-19 20:00:17 +0000 | [diff] [blame] | 3659 | SDValue Val = IsSingleInstrConstant(Value, DAG, ST, dl); |
| 3660 | if (Val.getNode()) |
| 3661 | return DAG.getNode(ARMISD::VDUP, dl, VT, Val); |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 3662 | } |
| 3663 | |
| 3664 | // If all elements are constants and the case above didn't get hit, fall back |
| 3665 | // to the default expansion, which will generate a load from the constant |
| 3666 | // pool. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 3667 | if (isConstant) |
| 3668 | return SDValue(); |
| 3669 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3670 | // Empirical tests suggest this is rarely worth it for vectors of length <= 2. |
| 3671 | if (NumElts >= 4) { |
| 3672 | SDValue shuffle = ReconstructShuffle(Op, DAG); |
| 3673 | if (shuffle != SDValue()) |
| 3674 | return shuffle; |
| 3675 | } |
| 3676 | |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 3677 | // 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] | 3678 | // the subregisters. Lower it to an ARMISD::BUILD_VECTOR so the operands |
| 3679 | // will be legalized. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 3680 | if (EltSize >= 32) { |
| 3681 | // Do the expansion with floating-point types, since that is what the VFP |
| 3682 | // registers are defined to use, and since i64 is not legal. |
| 3683 | EVT EltVT = EVT::getFloatingPointVT(EltSize); |
| 3684 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), EltVT, NumElts); |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 3685 | SmallVector<SDValue, 8> Ops; |
| 3686 | for (unsigned i = 0; i < NumElts; ++i) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3687 | Ops.push_back(DAG.getNode(ISD::BITCAST, dl, EltVT, Op.getOperand(i))); |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 3688 | SDValue Val = DAG.getNode(ARMISD::BUILD_VECTOR, dl, VecVT, &Ops[0],NumElts); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3689 | return DAG.getNode(ISD::BITCAST, dl, VT, Val); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3690 | } |
| 3691 | |
| 3692 | return SDValue(); |
| 3693 | } |
| 3694 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3695 | // Gather data to see if the operation can be modelled as a |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 3696 | // shuffle in combination with VEXTs. |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 3697 | SDValue ARMTargetLowering::ReconstructShuffle(SDValue Op, |
| 3698 | SelectionDAG &DAG) const { |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3699 | DebugLoc dl = Op.getDebugLoc(); |
| 3700 | EVT VT = Op.getValueType(); |
| 3701 | unsigned NumElts = VT.getVectorNumElements(); |
| 3702 | |
| 3703 | SmallVector<SDValue, 2> SourceVecs; |
| 3704 | SmallVector<unsigned, 2> MinElts; |
| 3705 | SmallVector<unsigned, 2> MaxElts; |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 3706 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3707 | for (unsigned i = 0; i < NumElts; ++i) { |
| 3708 | SDValue V = Op.getOperand(i); |
| 3709 | if (V.getOpcode() == ISD::UNDEF) |
| 3710 | continue; |
| 3711 | else if (V.getOpcode() != ISD::EXTRACT_VECTOR_ELT) { |
| 3712 | // A shuffle can only come from building a vector from various |
| 3713 | // elements of other vectors. |
| 3714 | return SDValue(); |
| 3715 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 3716 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3717 | // Record this extraction against the appropriate vector if possible... |
| 3718 | SDValue SourceVec = V.getOperand(0); |
| 3719 | unsigned EltNo = cast<ConstantSDNode>(V.getOperand(1))->getZExtValue(); |
| 3720 | bool FoundSource = false; |
| 3721 | for (unsigned j = 0; j < SourceVecs.size(); ++j) { |
| 3722 | if (SourceVecs[j] == SourceVec) { |
| 3723 | if (MinElts[j] > EltNo) |
| 3724 | MinElts[j] = EltNo; |
| 3725 | if (MaxElts[j] < EltNo) |
| 3726 | MaxElts[j] = EltNo; |
| 3727 | FoundSource = true; |
| 3728 | break; |
| 3729 | } |
| 3730 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 3731 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3732 | // Or record a new source if not... |
| 3733 | if (!FoundSource) { |
| 3734 | SourceVecs.push_back(SourceVec); |
| 3735 | MinElts.push_back(EltNo); |
| 3736 | MaxElts.push_back(EltNo); |
| 3737 | } |
| 3738 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 3739 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3740 | // Currently only do something sane when at most two source vectors |
| 3741 | // involved. |
| 3742 | if (SourceVecs.size() > 2) |
| 3743 | return SDValue(); |
| 3744 | |
| 3745 | SDValue ShuffleSrcs[2] = {DAG.getUNDEF(VT), DAG.getUNDEF(VT) }; |
| 3746 | int VEXTOffsets[2] = {0, 0}; |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 3747 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3748 | // This loop extracts the usage patterns of the source vectors |
| 3749 | // and prepares appropriate SDValues for a shuffle if possible. |
| 3750 | for (unsigned i = 0; i < SourceVecs.size(); ++i) { |
| 3751 | if (SourceVecs[i].getValueType() == VT) { |
| 3752 | // No VEXT necessary |
| 3753 | ShuffleSrcs[i] = SourceVecs[i]; |
| 3754 | VEXTOffsets[i] = 0; |
| 3755 | continue; |
| 3756 | } else if (SourceVecs[i].getValueType().getVectorNumElements() < NumElts) { |
| 3757 | // It probably isn't worth padding out a smaller vector just to |
| 3758 | // break it down again in a shuffle. |
| 3759 | return SDValue(); |
| 3760 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 3761 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3762 | // Since only 64-bit and 128-bit vectors are legal on ARM and |
| 3763 | // we've eliminated the other cases... |
Bob Wilson | 70f8573 | 2011-01-07 23:40:46 +0000 | [diff] [blame] | 3764 | assert(SourceVecs[i].getValueType().getVectorNumElements() == 2*NumElts && |
| 3765 | "unexpected vector sizes in ReconstructShuffle"); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 3766 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3767 | if (MaxElts[i] - MinElts[i] >= NumElts) { |
| 3768 | // Span too large for a VEXT to cope |
| 3769 | return SDValue(); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 3770 | } |
| 3771 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3772 | if (MinElts[i] >= NumElts) { |
| 3773 | // The extraction can just take the second half |
| 3774 | VEXTOffsets[i] = NumElts; |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 3775 | ShuffleSrcs[i] = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 3776 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3777 | DAG.getIntPtrConstant(NumElts)); |
| 3778 | } else if (MaxElts[i] < NumElts) { |
| 3779 | // The extraction can just take the first half |
| 3780 | VEXTOffsets[i] = 0; |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 3781 | ShuffleSrcs[i] = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 3782 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3783 | DAG.getIntPtrConstant(0)); |
| 3784 | } else { |
| 3785 | // An actual VEXT is needed |
| 3786 | VEXTOffsets[i] = MinElts[i]; |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 3787 | SDValue VEXTSrc1 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 3788 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3789 | DAG.getIntPtrConstant(0)); |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 3790 | SDValue VEXTSrc2 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 3791 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3792 | DAG.getIntPtrConstant(NumElts)); |
| 3793 | ShuffleSrcs[i] = DAG.getNode(ARMISD::VEXT, dl, VT, VEXTSrc1, VEXTSrc2, |
| 3794 | DAG.getConstant(VEXTOffsets[i], MVT::i32)); |
| 3795 | } |
| 3796 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 3797 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3798 | SmallVector<int, 8> Mask; |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 3799 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3800 | for (unsigned i = 0; i < NumElts; ++i) { |
| 3801 | SDValue Entry = Op.getOperand(i); |
| 3802 | if (Entry.getOpcode() == ISD::UNDEF) { |
| 3803 | Mask.push_back(-1); |
| 3804 | continue; |
| 3805 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 3806 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3807 | SDValue ExtractVec = Entry.getOperand(0); |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 3808 | int ExtractElt = cast<ConstantSDNode>(Op.getOperand(i) |
| 3809 | .getOperand(1))->getSExtValue(); |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3810 | if (ExtractVec == SourceVecs[0]) { |
| 3811 | Mask.push_back(ExtractElt - VEXTOffsets[0]); |
| 3812 | } else { |
| 3813 | Mask.push_back(ExtractElt + NumElts - VEXTOffsets[1]); |
| 3814 | } |
| 3815 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 3816 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3817 | // Final check before we try to produce nonsense... |
| 3818 | if (isShuffleMaskLegal(Mask, VT)) |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 3819 | return DAG.getVectorShuffle(VT, dl, ShuffleSrcs[0], ShuffleSrcs[1], |
| 3820 | &Mask[0]); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 3821 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3822 | return SDValue(); |
| 3823 | } |
| 3824 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3825 | /// isShuffleMaskLegal - Targets can use this to indicate that they only |
| 3826 | /// support *some* VECTOR_SHUFFLE operations, those with specific masks. |
| 3827 | /// By default, if a target supports the VECTOR_SHUFFLE node, all mask values |
| 3828 | /// are assumed to be legal. |
| 3829 | bool |
| 3830 | ARMTargetLowering::isShuffleMaskLegal(const SmallVectorImpl<int> &M, |
| 3831 | EVT VT) const { |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 3832 | if (VT.getVectorNumElements() == 4 && |
| 3833 | (VT.is128BitVector() || VT.is64BitVector())) { |
| 3834 | unsigned PFIndexes[4]; |
| 3835 | for (unsigned i = 0; i != 4; ++i) { |
| 3836 | if (M[i] < 0) |
| 3837 | PFIndexes[i] = 8; |
| 3838 | else |
| 3839 | PFIndexes[i] = M[i]; |
| 3840 | } |
| 3841 | |
| 3842 | // Compute the index in the perfect shuffle table. |
| 3843 | unsigned PFTableIndex = |
| 3844 | PFIndexes[0]*9*9*9+PFIndexes[1]*9*9+PFIndexes[2]*9+PFIndexes[3]; |
| 3845 | unsigned PFEntry = PerfectShuffleTable[PFTableIndex]; |
| 3846 | unsigned Cost = (PFEntry >> 30); |
| 3847 | |
| 3848 | if (Cost <= 4) |
| 3849 | return true; |
| 3850 | } |
| 3851 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3852 | bool ReverseVEXT; |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3853 | unsigned Imm, WhichResult; |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3854 | |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 3855 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 3856 | return (EltSize >= 32 || |
| 3857 | ShuffleVectorSDNode::isSplatMask(&M[0], VT) || |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3858 | isVREVMask(M, VT, 64) || |
| 3859 | isVREVMask(M, VT, 32) || |
| 3860 | isVREVMask(M, VT, 16) || |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3861 | isVEXTMask(M, VT, ReverseVEXT, Imm) || |
| 3862 | isVTRNMask(M, VT, WhichResult) || |
| 3863 | isVUZPMask(M, VT, WhichResult) || |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3864 | isVZIPMask(M, VT, WhichResult) || |
| 3865 | isVTRN_v_undef_Mask(M, VT, WhichResult) || |
| 3866 | isVUZP_v_undef_Mask(M, VT, WhichResult) || |
| 3867 | isVZIP_v_undef_Mask(M, VT, WhichResult)); |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3868 | } |
| 3869 | |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 3870 | /// GeneratePerfectShuffle - Given an entry in the perfect-shuffle table, emit |
| 3871 | /// the specified operations to build the shuffle. |
| 3872 | static SDValue GeneratePerfectShuffle(unsigned PFEntry, SDValue LHS, |
| 3873 | SDValue RHS, SelectionDAG &DAG, |
| 3874 | DebugLoc dl) { |
| 3875 | unsigned OpNum = (PFEntry >> 26) & 0x0F; |
| 3876 | unsigned LHSID = (PFEntry >> 13) & ((1 << 13)-1); |
| 3877 | unsigned RHSID = (PFEntry >> 0) & ((1 << 13)-1); |
| 3878 | |
| 3879 | enum { |
| 3880 | OP_COPY = 0, // Copy, used for things like <u,u,u,3> to say it is <0,1,2,3> |
| 3881 | OP_VREV, |
| 3882 | OP_VDUP0, |
| 3883 | OP_VDUP1, |
| 3884 | OP_VDUP2, |
| 3885 | OP_VDUP3, |
| 3886 | OP_VEXT1, |
| 3887 | OP_VEXT2, |
| 3888 | OP_VEXT3, |
| 3889 | OP_VUZPL, // VUZP, left result |
| 3890 | OP_VUZPR, // VUZP, right result |
| 3891 | OP_VZIPL, // VZIP, left result |
| 3892 | OP_VZIPR, // VZIP, right result |
| 3893 | OP_VTRNL, // VTRN, left result |
| 3894 | OP_VTRNR // VTRN, right result |
| 3895 | }; |
| 3896 | |
| 3897 | if (OpNum == OP_COPY) { |
| 3898 | if (LHSID == (1*9+2)*9+3) return LHS; |
| 3899 | assert(LHSID == ((4*9+5)*9+6)*9+7 && "Illegal OP_COPY!"); |
| 3900 | return RHS; |
| 3901 | } |
| 3902 | |
| 3903 | SDValue OpLHS, OpRHS; |
| 3904 | OpLHS = GeneratePerfectShuffle(PerfectShuffleTable[LHSID], LHS, RHS, DAG, dl); |
| 3905 | OpRHS = GeneratePerfectShuffle(PerfectShuffleTable[RHSID], LHS, RHS, DAG, dl); |
| 3906 | EVT VT = OpLHS.getValueType(); |
| 3907 | |
| 3908 | switch (OpNum) { |
| 3909 | default: llvm_unreachable("Unknown shuffle opcode!"); |
| 3910 | case OP_VREV: |
| 3911 | return DAG.getNode(ARMISD::VREV64, dl, VT, OpLHS); |
| 3912 | case OP_VDUP0: |
| 3913 | case OP_VDUP1: |
| 3914 | case OP_VDUP2: |
| 3915 | case OP_VDUP3: |
| 3916 | return DAG.getNode(ARMISD::VDUPLANE, dl, VT, |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 3917 | OpLHS, DAG.getConstant(OpNum-OP_VDUP0, MVT::i32)); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 3918 | case OP_VEXT1: |
| 3919 | case OP_VEXT2: |
| 3920 | case OP_VEXT3: |
| 3921 | return DAG.getNode(ARMISD::VEXT, dl, VT, |
| 3922 | OpLHS, OpRHS, |
| 3923 | DAG.getConstant(OpNum-OP_VEXT1+1, MVT::i32)); |
| 3924 | case OP_VUZPL: |
| 3925 | case OP_VUZPR: |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 3926 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 3927 | OpLHS, OpRHS).getValue(OpNum-OP_VUZPL); |
| 3928 | case OP_VZIPL: |
| 3929 | case OP_VZIPR: |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 3930 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 3931 | OpLHS, OpRHS).getValue(OpNum-OP_VZIPL); |
| 3932 | case OP_VTRNL: |
| 3933 | case OP_VTRNR: |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 3934 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), |
| 3935 | OpLHS, OpRHS).getValue(OpNum-OP_VTRNL); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 3936 | } |
| 3937 | } |
| 3938 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3939 | static SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) { |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 3940 | SDValue V1 = Op.getOperand(0); |
| 3941 | SDValue V2 = Op.getOperand(1); |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 3942 | DebugLoc dl = Op.getDebugLoc(); |
| 3943 | EVT VT = Op.getValueType(); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 3944 | ShuffleVectorSDNode *SVN = cast<ShuffleVectorSDNode>(Op.getNode()); |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3945 | SmallVector<int, 8> ShuffleMask; |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 3946 | |
Bob Wilson | 2886506 | 2009-08-13 02:13:04 +0000 | [diff] [blame] | 3947 | // Convert shuffles that are directly supported on NEON to target-specific |
| 3948 | // DAG nodes, instead of keeping them as shuffles and matching them again |
| 3949 | // during code selection. This is more efficient and avoids the possibility |
| 3950 | // of inconsistencies between legalization and selection. |
Bob Wilson | bfcbb50 | 2009-08-13 06:01:30 +0000 | [diff] [blame] | 3951 | // FIXME: floating-point vectors should be canonicalized to integer vectors |
| 3952 | // of the same time so that they get CSEd properly. |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3953 | SVN->getMask(ShuffleMask); |
| 3954 | |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 3955 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 3956 | if (EltSize <= 32) { |
| 3957 | if (ShuffleVectorSDNode::isSplatMask(&ShuffleMask[0], VT)) { |
| 3958 | int Lane = SVN->getSplatIndex(); |
| 3959 | // If this is undef splat, generate it via "just" vdup, if possible. |
| 3960 | if (Lane == -1) Lane = 0; |
Anton Korobeynikov | 2ae0eec | 2009-11-02 00:12:06 +0000 | [diff] [blame] | 3961 | |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 3962 | if (Lane == 0 && V1.getOpcode() == ISD::SCALAR_TO_VECTOR) { |
| 3963 | return DAG.getNode(ARMISD::VDUP, dl, VT, V1.getOperand(0)); |
| 3964 | } |
| 3965 | return DAG.getNode(ARMISD::VDUPLANE, dl, VT, V1, |
| 3966 | DAG.getConstant(Lane, MVT::i32)); |
Bob Wilson | c1d287b | 2009-08-14 05:13:08 +0000 | [diff] [blame] | 3967 | } |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 3968 | |
| 3969 | bool ReverseVEXT; |
| 3970 | unsigned Imm; |
| 3971 | if (isVEXTMask(ShuffleMask, VT, ReverseVEXT, Imm)) { |
| 3972 | if (ReverseVEXT) |
| 3973 | std::swap(V1, V2); |
| 3974 | return DAG.getNode(ARMISD::VEXT, dl, VT, V1, V2, |
| 3975 | DAG.getConstant(Imm, MVT::i32)); |
| 3976 | } |
| 3977 | |
| 3978 | if (isVREVMask(ShuffleMask, VT, 64)) |
| 3979 | return DAG.getNode(ARMISD::VREV64, dl, VT, V1); |
| 3980 | if (isVREVMask(ShuffleMask, VT, 32)) |
| 3981 | return DAG.getNode(ARMISD::VREV32, dl, VT, V1); |
| 3982 | if (isVREVMask(ShuffleMask, VT, 16)) |
| 3983 | return DAG.getNode(ARMISD::VREV16, dl, VT, V1); |
| 3984 | |
| 3985 | // Check for Neon shuffles that modify both input vectors in place. |
| 3986 | // If both results are used, i.e., if there are two shuffles with the same |
| 3987 | // source operands and with masks corresponding to both results of one of |
| 3988 | // these operations, DAG memoization will ensure that a single node is |
| 3989 | // used for both shuffles. |
| 3990 | unsigned WhichResult; |
| 3991 | if (isVTRNMask(ShuffleMask, VT, WhichResult)) |
| 3992 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), |
| 3993 | V1, V2).getValue(WhichResult); |
| 3994 | if (isVUZPMask(ShuffleMask, VT, WhichResult)) |
| 3995 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), |
| 3996 | V1, V2).getValue(WhichResult); |
| 3997 | if (isVZIPMask(ShuffleMask, VT, WhichResult)) |
| 3998 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), |
| 3999 | V1, V2).getValue(WhichResult); |
| 4000 | |
| 4001 | if (isVTRN_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 4002 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), |
| 4003 | V1, V1).getValue(WhichResult); |
| 4004 | if (isVUZP_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 4005 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), |
| 4006 | V1, V1).getValue(WhichResult); |
| 4007 | if (isVZIP_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 4008 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), |
| 4009 | V1, V1).getValue(WhichResult); |
Bob Wilson | 0ce3710 | 2009-08-14 05:08:32 +0000 | [diff] [blame] | 4010 | } |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 4011 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4012 | // If the shuffle is not directly supported and it has 4 elements, use |
| 4013 | // the PerfectShuffle-generated table to synthesize it from other shuffles. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4014 | unsigned NumElts = VT.getVectorNumElements(); |
| 4015 | if (NumElts == 4) { |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4016 | unsigned PFIndexes[4]; |
| 4017 | for (unsigned i = 0; i != 4; ++i) { |
| 4018 | if (ShuffleMask[i] < 0) |
| 4019 | PFIndexes[i] = 8; |
| 4020 | else |
| 4021 | PFIndexes[i] = ShuffleMask[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]; |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4027 | unsigned PFEntry = PerfectShuffleTable[PFTableIndex]; |
| 4028 | unsigned Cost = (PFEntry >> 30); |
| 4029 | |
| 4030 | if (Cost <= 4) |
| 4031 | return GeneratePerfectShuffle(PFEntry, V1, V2, DAG, dl); |
| 4032 | } |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 4033 | |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4034 | // Implement shuffles with 32- or 64-bit elements as ARMISD::BUILD_VECTORs. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4035 | if (EltSize >= 32) { |
| 4036 | // Do the expansion with floating-point types, since that is what the VFP |
| 4037 | // registers are defined to use, and since i64 is not legal. |
| 4038 | EVT EltVT = EVT::getFloatingPointVT(EltSize); |
| 4039 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), EltVT, NumElts); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4040 | V1 = DAG.getNode(ISD::BITCAST, dl, VecVT, V1); |
| 4041 | V2 = DAG.getNode(ISD::BITCAST, dl, VecVT, V2); |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4042 | SmallVector<SDValue, 8> Ops; |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4043 | for (unsigned i = 0; i < NumElts; ++i) { |
Bob Wilson | 63b8845 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 4044 | if (ShuffleMask[i] < 0) |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4045 | Ops.push_back(DAG.getUNDEF(EltVT)); |
| 4046 | else |
| 4047 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, EltVT, |
| 4048 | ShuffleMask[i] < (int)NumElts ? V1 : V2, |
| 4049 | DAG.getConstant(ShuffleMask[i] & (NumElts-1), |
| 4050 | MVT::i32))); |
Bob Wilson | 63b8845 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 4051 | } |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4052 | SDValue Val = DAG.getNode(ARMISD::BUILD_VECTOR, dl, VecVT, &Ops[0],NumElts); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4053 | return DAG.getNode(ISD::BITCAST, dl, VT, Val); |
Bob Wilson | 63b8845 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 4054 | } |
| 4055 | |
Bob Wilson | 22cac0d | 2009-08-14 05:16:33 +0000 | [diff] [blame] | 4056 | return SDValue(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4057 | } |
| 4058 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4059 | static SDValue LowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) { |
Bob Wilson | 3468c2e | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 4060 | // EXTRACT_VECTOR_ELT is legal only for immediate indexes. |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4061 | SDValue Lane = Op.getOperand(1); |
Bob Wilson | 3468c2e | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 4062 | if (!isa<ConstantSDNode>(Lane)) |
| 4063 | return SDValue(); |
| 4064 | |
| 4065 | SDValue Vec = Op.getOperand(0); |
| 4066 | if (Op.getValueType() == MVT::i32 && |
| 4067 | Vec.getValueType().getVectorElementType().getSizeInBits() < 32) { |
| 4068 | DebugLoc dl = Op.getDebugLoc(); |
| 4069 | return DAG.getNode(ARMISD::VGETLANEu, dl, MVT::i32, Vec, Lane); |
| 4070 | } |
| 4071 | |
| 4072 | return Op; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4073 | } |
| 4074 | |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 4075 | static SDValue LowerCONCAT_VECTORS(SDValue Op, SelectionDAG &DAG) { |
| 4076 | // The only time a CONCAT_VECTORS operation can have legal types is when |
| 4077 | // two 64-bit vectors are concatenated to a 128-bit vector. |
| 4078 | assert(Op.getValueType().is128BitVector() && Op.getNumOperands() == 2 && |
| 4079 | "unexpected CONCAT_VECTORS"); |
| 4080 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4081 | SDValue Val = DAG.getUNDEF(MVT::v2f64); |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 4082 | SDValue Op0 = Op.getOperand(0); |
| 4083 | SDValue Op1 = Op.getOperand(1); |
| 4084 | if (Op0.getOpcode() != ISD::UNDEF) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4085 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Val, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4086 | DAG.getNode(ISD::BITCAST, dl, MVT::f64, Op0), |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 4087 | DAG.getIntPtrConstant(0)); |
| 4088 | if (Op1.getOpcode() != ISD::UNDEF) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4089 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Val, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4090 | DAG.getNode(ISD::BITCAST, dl, MVT::f64, Op1), |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 4091 | DAG.getIntPtrConstant(1)); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4092 | return DAG.getNode(ISD::BITCAST, dl, Op.getValueType(), Val); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4093 | } |
| 4094 | |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 4095 | /// isExtendedBUILD_VECTOR - Check if N is a constant BUILD_VECTOR where each |
| 4096 | /// element has been zero/sign-extended, depending on the isSigned parameter, |
| 4097 | /// from an integer type half its size. |
| 4098 | static bool isExtendedBUILD_VECTOR(SDNode *N, SelectionDAG &DAG, |
| 4099 | bool isSigned) { |
| 4100 | // A v2i64 BUILD_VECTOR will have been legalized to a BITCAST from v4i32. |
| 4101 | EVT VT = N->getValueType(0); |
| 4102 | if (VT == MVT::v2i64 && N->getOpcode() == ISD::BITCAST) { |
| 4103 | SDNode *BVN = N->getOperand(0).getNode(); |
| 4104 | if (BVN->getValueType(0) != MVT::v4i32 || |
| 4105 | BVN->getOpcode() != ISD::BUILD_VECTOR) |
| 4106 | return false; |
| 4107 | unsigned LoElt = DAG.getTargetLoweringInfo().isBigEndian() ? 1 : 0; |
| 4108 | unsigned HiElt = 1 - LoElt; |
| 4109 | ConstantSDNode *Lo0 = dyn_cast<ConstantSDNode>(BVN->getOperand(LoElt)); |
| 4110 | ConstantSDNode *Hi0 = dyn_cast<ConstantSDNode>(BVN->getOperand(HiElt)); |
| 4111 | ConstantSDNode *Lo1 = dyn_cast<ConstantSDNode>(BVN->getOperand(LoElt+2)); |
| 4112 | ConstantSDNode *Hi1 = dyn_cast<ConstantSDNode>(BVN->getOperand(HiElt+2)); |
| 4113 | if (!Lo0 || !Hi0 || !Lo1 || !Hi1) |
| 4114 | return false; |
| 4115 | if (isSigned) { |
| 4116 | if (Hi0->getSExtValue() == Lo0->getSExtValue() >> 32 && |
| 4117 | Hi1->getSExtValue() == Lo1->getSExtValue() >> 32) |
| 4118 | return true; |
| 4119 | } else { |
| 4120 | if (Hi0->isNullValue() && Hi1->isNullValue()) |
| 4121 | return true; |
| 4122 | } |
| 4123 | return false; |
| 4124 | } |
| 4125 | |
| 4126 | if (N->getOpcode() != ISD::BUILD_VECTOR) |
| 4127 | return false; |
| 4128 | |
| 4129 | for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) { |
| 4130 | SDNode *Elt = N->getOperand(i).getNode(); |
| 4131 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Elt)) { |
| 4132 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 4133 | unsigned HalfSize = EltSize / 2; |
| 4134 | if (isSigned) { |
| 4135 | int64_t SExtVal = C->getSExtValue(); |
| 4136 | if ((SExtVal >> HalfSize) != (SExtVal >> EltSize)) |
| 4137 | return false; |
| 4138 | } else { |
| 4139 | if ((C->getZExtValue() >> HalfSize) != 0) |
| 4140 | return false; |
| 4141 | } |
| 4142 | continue; |
| 4143 | } |
| 4144 | return false; |
| 4145 | } |
| 4146 | |
| 4147 | return true; |
| 4148 | } |
| 4149 | |
| 4150 | /// isSignExtended - Check if a node is a vector value that is sign-extended |
| 4151 | /// or a constant BUILD_VECTOR with sign-extended elements. |
| 4152 | static bool isSignExtended(SDNode *N, SelectionDAG &DAG) { |
| 4153 | if (N->getOpcode() == ISD::SIGN_EXTEND || ISD::isSEXTLoad(N)) |
| 4154 | return true; |
| 4155 | if (isExtendedBUILD_VECTOR(N, DAG, true)) |
| 4156 | return true; |
| 4157 | return false; |
| 4158 | } |
| 4159 | |
| 4160 | /// isZeroExtended - Check if a node is a vector value that is zero-extended |
| 4161 | /// or a constant BUILD_VECTOR with zero-extended elements. |
| 4162 | static bool isZeroExtended(SDNode *N, SelectionDAG &DAG) { |
| 4163 | if (N->getOpcode() == ISD::ZERO_EXTEND || ISD::isZEXTLoad(N)) |
| 4164 | return true; |
| 4165 | if (isExtendedBUILD_VECTOR(N, DAG, false)) |
| 4166 | return true; |
| 4167 | return false; |
| 4168 | } |
| 4169 | |
| 4170 | /// SkipExtension - For a node that is a SIGN_EXTEND, ZERO_EXTEND, extending |
| 4171 | /// load, or BUILD_VECTOR with extended elements, return the unextended value. |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4172 | static SDValue SkipExtension(SDNode *N, SelectionDAG &DAG) { |
| 4173 | if (N->getOpcode() == ISD::SIGN_EXTEND || N->getOpcode() == ISD::ZERO_EXTEND) |
| 4174 | return N->getOperand(0); |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 4175 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) |
| 4176 | return DAG.getLoad(LD->getMemoryVT(), N->getDebugLoc(), LD->getChain(), |
| 4177 | LD->getBasePtr(), LD->getPointerInfo(), LD->isVolatile(), |
| 4178 | LD->isNonTemporal(), LD->getAlignment()); |
| 4179 | // Otherwise, the value must be a BUILD_VECTOR. For v2i64, it will |
| 4180 | // have been legalized as a BITCAST from v4i32. |
| 4181 | if (N->getOpcode() == ISD::BITCAST) { |
| 4182 | SDNode *BVN = N->getOperand(0).getNode(); |
| 4183 | assert(BVN->getOpcode() == ISD::BUILD_VECTOR && |
| 4184 | BVN->getValueType(0) == MVT::v4i32 && "expected v4i32 BUILD_VECTOR"); |
| 4185 | unsigned LowElt = DAG.getTargetLoweringInfo().isBigEndian() ? 1 : 0; |
| 4186 | return DAG.getNode(ISD::BUILD_VECTOR, N->getDebugLoc(), MVT::v2i32, |
| 4187 | BVN->getOperand(LowElt), BVN->getOperand(LowElt+2)); |
| 4188 | } |
| 4189 | // Construct a new BUILD_VECTOR with elements truncated to half the size. |
| 4190 | assert(N->getOpcode() == ISD::BUILD_VECTOR && "expected BUILD_VECTOR"); |
| 4191 | EVT VT = N->getValueType(0); |
| 4192 | unsigned EltSize = VT.getVectorElementType().getSizeInBits() / 2; |
| 4193 | unsigned NumElts = VT.getVectorNumElements(); |
| 4194 | MVT TruncVT = MVT::getIntegerVT(EltSize); |
| 4195 | SmallVector<SDValue, 8> Ops; |
| 4196 | for (unsigned i = 0; i != NumElts; ++i) { |
| 4197 | ConstantSDNode *C = cast<ConstantSDNode>(N->getOperand(i)); |
| 4198 | const APInt &CInt = C->getAPIntValue(); |
Jay Foad | 40f8f62 | 2010-12-07 08:25:19 +0000 | [diff] [blame] | 4199 | Ops.push_back(DAG.getConstant(CInt.trunc(EltSize), TruncVT)); |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 4200 | } |
| 4201 | return DAG.getNode(ISD::BUILD_VECTOR, N->getDebugLoc(), |
| 4202 | MVT::getVectorVT(TruncVT, NumElts), Ops.data(), NumElts); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4203 | } |
| 4204 | |
| 4205 | static SDValue LowerMUL(SDValue Op, SelectionDAG &DAG) { |
| 4206 | // Multiplications are only custom-lowered for 128-bit vectors so that |
| 4207 | // VMULL can be detected. Otherwise v2i64 multiplications are not legal. |
| 4208 | EVT VT = Op.getValueType(); |
| 4209 | assert(VT.is128BitVector() && "unexpected type for custom-lowering ISD::MUL"); |
| 4210 | SDNode *N0 = Op.getOperand(0).getNode(); |
| 4211 | SDNode *N1 = Op.getOperand(1).getNode(); |
| 4212 | unsigned NewOpc = 0; |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 4213 | if (isSignExtended(N0, DAG) && isSignExtended(N1, DAG)) |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4214 | NewOpc = ARMISD::VMULLs; |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 4215 | else if (isZeroExtended(N0, DAG) && isZeroExtended(N1, DAG)) |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4216 | NewOpc = ARMISD::VMULLu; |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 4217 | else if (VT == MVT::v2i64) |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4218 | // Fall through to expand this. It is not legal. |
| 4219 | return SDValue(); |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 4220 | else |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4221 | // Other vector multiplications are legal. |
| 4222 | return Op; |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4223 | |
| 4224 | // Legalize to a VMULL instruction. |
| 4225 | DebugLoc DL = Op.getDebugLoc(); |
| 4226 | SDValue Op0 = SkipExtension(N0, DAG); |
| 4227 | SDValue Op1 = SkipExtension(N1, DAG); |
| 4228 | |
| 4229 | assert(Op0.getValueType().is64BitVector() && |
| 4230 | Op1.getValueType().is64BitVector() && |
| 4231 | "unexpected types for extended operands to VMULL"); |
| 4232 | return DAG.getNode(NewOpc, DL, VT, Op0, Op1); |
| 4233 | } |
| 4234 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 4235 | SDValue ARMTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4236 | switch (Op.getOpcode()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 4237 | default: llvm_unreachable("Don't know how to custom lower this!"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4238 | case ISD::ConstantPool: return LowerConstantPool(Op, DAG); |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 4239 | case ISD::BlockAddress: return LowerBlockAddress(Op, DAG); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 4240 | case ISD::GlobalAddress: |
| 4241 | return Subtarget->isTargetDarwin() ? LowerGlobalAddressDarwin(Op, DAG) : |
| 4242 | LowerGlobalAddressELF(Op, DAG); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 4243 | case ISD::GlobalTLSAddress: return LowerGlobalTLSAddress(Op, DAG); |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 4244 | case ISD::SELECT: return LowerSELECT(Op, DAG); |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 4245 | case ISD::SELECT_CC: return LowerSELECT_CC(Op, DAG); |
| 4246 | case ISD::BR_CC: return LowerBR_CC(Op, DAG); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4247 | case ISD::BR_JT: return LowerBR_JT(Op, DAG); |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 4248 | case ISD::VASTART: return LowerVASTART(Op, DAG); |
Jim Grosbach | 7c03dbd | 2009-12-14 21:24:16 +0000 | [diff] [blame] | 4249 | case ISD::MEMBARRIER: return LowerMEMBARRIER(Op, DAG, Subtarget); |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 4250 | case ISD::PREFETCH: return LowerPREFETCH(Op, DAG, Subtarget); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 4251 | case ISD::SINT_TO_FP: |
| 4252 | case ISD::UINT_TO_FP: return LowerINT_TO_FP(Op, DAG); |
| 4253 | case ISD::FP_TO_SINT: |
| 4254 | case ISD::FP_TO_UINT: return LowerFP_TO_INT(Op, DAG); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4255 | case ISD::FCOPYSIGN: return LowerFCOPYSIGN(Op, DAG); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 4256 | case ISD::RETURNADDR: return LowerRETURNADDR(Op, DAG); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 4257 | case ISD::FRAMEADDR: return LowerFRAMEADDR(Op, DAG); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 4258 | case ISD::GLOBAL_OFFSET_TABLE: return LowerGLOBAL_OFFSET_TABLE(Op, DAG); |
Jim Grosbach | 23ff7cf | 2010-05-26 20:22:18 +0000 | [diff] [blame] | 4259 | case ISD::EH_SJLJ_SETJMP: return LowerEH_SJLJ_SETJMP(Op, DAG); |
Jim Grosbach | 5eb1951 | 2010-05-22 01:06:18 +0000 | [diff] [blame] | 4260 | case ISD::EH_SJLJ_LONGJMP: return LowerEH_SJLJ_LONGJMP(Op, DAG); |
Jim Grosbach | e4ad387 | 2010-10-19 23:27:08 +0000 | [diff] [blame] | 4261 | case ISD::EH_SJLJ_DISPATCHSETUP: return LowerEH_SJLJ_DISPATCHSETUP(Op, DAG); |
Jim Grosbach | a87ded2 | 2010-02-08 23:22:00 +0000 | [diff] [blame] | 4262 | case ISD::INTRINSIC_WO_CHAIN: return LowerINTRINSIC_WO_CHAIN(Op, DAG, |
| 4263 | Subtarget); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4264 | case ISD::BITCAST: return ExpandBITCAST(Op.getNode(), DAG); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4265 | case ISD::SHL: |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4266 | case ISD::SRL: |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4267 | case ISD::SRA: return LowerShift(Op.getNode(), DAG, Subtarget); |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 4268 | case ISD::SHL_PARTS: return LowerShiftLeftParts(Op, DAG); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 4269 | case ISD::SRL_PARTS: |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 4270 | case ISD::SRA_PARTS: return LowerShiftRightParts(Op, DAG); |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 4271 | case ISD::CTTZ: return LowerCTTZ(Op.getNode(), DAG, Subtarget); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4272 | case ISD::VSETCC: return LowerVSETCC(Op, DAG); |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 4273 | case ISD::BUILD_VECTOR: return LowerBUILD_VECTOR(Op, DAG, Subtarget); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4274 | case ISD::VECTOR_SHUFFLE: return LowerVECTOR_SHUFFLE(Op, DAG); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4275 | case ISD::EXTRACT_VECTOR_ELT: return LowerEXTRACT_VECTOR_ELT(Op, DAG); |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 4276 | case ISD::CONCAT_VECTORS: return LowerCONCAT_VECTORS(Op, DAG); |
Bob Wilson | b31a11b | 2010-08-20 04:54:02 +0000 | [diff] [blame] | 4277 | case ISD::FLT_ROUNDS_: return LowerFLT_ROUNDS_(Op, DAG); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4278 | case ISD::MUL: return LowerMUL(Op, DAG); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4279 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4280 | return SDValue(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4281 | } |
| 4282 | |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 4283 | /// ReplaceNodeResults - Replace the results of node with an illegal result |
| 4284 | /// type with new values built out of custom code. |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 4285 | void ARMTargetLowering::ReplaceNodeResults(SDNode *N, |
| 4286 | SmallVectorImpl<SDValue>&Results, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 4287 | SelectionDAG &DAG) const { |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 4288 | SDValue Res; |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4289 | switch (N->getOpcode()) { |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 4290 | default: |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 4291 | llvm_unreachable("Don't know how to custom expand this!"); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 4292 | break; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4293 | case ISD::BITCAST: |
| 4294 | Res = ExpandBITCAST(N, DAG); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 4295 | break; |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4296 | case ISD::SRL: |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 4297 | case ISD::SRA: |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 4298 | Res = Expand64BitShift(N, DAG, Subtarget); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 4299 | break; |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 4300 | } |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 4301 | if (Res.getNode()) |
| 4302 | Results.push_back(Res); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4303 | } |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4304 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4305 | //===----------------------------------------------------------------------===// |
| 4306 | // ARM Scheduler Hooks |
| 4307 | //===----------------------------------------------------------------------===// |
| 4308 | |
| 4309 | MachineBasicBlock * |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 4310 | ARMTargetLowering::EmitAtomicCmpSwap(MachineInstr *MI, |
| 4311 | MachineBasicBlock *BB, |
| 4312 | unsigned Size) const { |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4313 | unsigned dest = MI->getOperand(0).getReg(); |
| 4314 | unsigned ptr = MI->getOperand(1).getReg(); |
| 4315 | unsigned oldval = MI->getOperand(2).getReg(); |
| 4316 | unsigned newval = MI->getOperand(3).getReg(); |
| 4317 | unsigned scratch = BB->getParent()->getRegInfo() |
| 4318 | .createVirtualRegister(ARM::GPRRegisterClass); |
| 4319 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 4320 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4321 | bool isThumb2 = Subtarget->isThumb2(); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4322 | |
| 4323 | unsigned ldrOpc, strOpc; |
| 4324 | switch (Size) { |
| 4325 | default: llvm_unreachable("unsupported size for AtomicCmpSwap!"); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4326 | case 1: |
| 4327 | ldrOpc = isThumb2 ? ARM::t2LDREXB : ARM::LDREXB; |
| 4328 | strOpc = isThumb2 ? ARM::t2LDREXB : ARM::STREXB; |
| 4329 | break; |
| 4330 | case 2: |
| 4331 | ldrOpc = isThumb2 ? ARM::t2LDREXH : ARM::LDREXH; |
| 4332 | strOpc = isThumb2 ? ARM::t2STREXH : ARM::STREXH; |
| 4333 | break; |
| 4334 | case 4: |
| 4335 | ldrOpc = isThumb2 ? ARM::t2LDREX : ARM::LDREX; |
| 4336 | strOpc = isThumb2 ? ARM::t2STREX : ARM::STREX; |
| 4337 | break; |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4338 | } |
| 4339 | |
| 4340 | MachineFunction *MF = BB->getParent(); |
| 4341 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 4342 | MachineFunction::iterator It = BB; |
| 4343 | ++It; // insert the new blocks after the current block |
| 4344 | |
| 4345 | MachineBasicBlock *loop1MBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 4346 | MachineBasicBlock *loop2MBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 4347 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 4348 | MF->insert(It, loop1MBB); |
| 4349 | MF->insert(It, loop2MBB); |
| 4350 | MF->insert(It, exitMBB); |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 4351 | |
| 4352 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 4353 | exitMBB->splice(exitMBB->begin(), BB, |
| 4354 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 4355 | BB->end()); |
| 4356 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4357 | |
| 4358 | // thisMBB: |
| 4359 | // ... |
| 4360 | // fallthrough --> loop1MBB |
| 4361 | BB->addSuccessor(loop1MBB); |
| 4362 | |
| 4363 | // loop1MBB: |
| 4364 | // ldrex dest, [ptr] |
| 4365 | // cmp dest, oldval |
| 4366 | // bne exitMBB |
| 4367 | BB = loop1MBB; |
| 4368 | AddDefaultPred(BuildMI(BB, dl, TII->get(ldrOpc), dest).addReg(ptr)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4369 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4370 | .addReg(dest).addReg(oldval)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4371 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 4372 | .addMBB(exitMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4373 | BB->addSuccessor(loop2MBB); |
| 4374 | BB->addSuccessor(exitMBB); |
| 4375 | |
| 4376 | // loop2MBB: |
| 4377 | // strex scratch, newval, [ptr] |
| 4378 | // cmp scratch, #0 |
| 4379 | // bne loop1MBB |
| 4380 | BB = loop2MBB; |
| 4381 | AddDefaultPred(BuildMI(BB, dl, TII->get(strOpc), scratch).addReg(newval) |
| 4382 | .addReg(ptr)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4383 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4384 | .addReg(scratch).addImm(0)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4385 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 4386 | .addMBB(loop1MBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4387 | BB->addSuccessor(loop1MBB); |
| 4388 | BB->addSuccessor(exitMBB); |
| 4389 | |
| 4390 | // exitMBB: |
| 4391 | // ... |
| 4392 | BB = exitMBB; |
Jim Grosbach | 5efaed3 | 2010-01-15 00:18:34 +0000 | [diff] [blame] | 4393 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 4394 | MI->eraseFromParent(); // The instruction is gone now. |
Jim Grosbach | 5efaed3 | 2010-01-15 00:18:34 +0000 | [diff] [blame] | 4395 | |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4396 | return BB; |
| 4397 | } |
| 4398 | |
| 4399 | MachineBasicBlock * |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 4400 | ARMTargetLowering::EmitAtomicBinary(MachineInstr *MI, MachineBasicBlock *BB, |
| 4401 | unsigned Size, unsigned BinOpcode) const { |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 4402 | // This also handles ATOMIC_SWAP, indicated by BinOpcode==0. |
| 4403 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 4404 | |
| 4405 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
Jim Grosbach | 867bbbf | 2010-01-15 00:22:18 +0000 | [diff] [blame] | 4406 | MachineFunction *MF = BB->getParent(); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 4407 | MachineFunction::iterator It = BB; |
| 4408 | ++It; |
| 4409 | |
| 4410 | unsigned dest = MI->getOperand(0).getReg(); |
| 4411 | unsigned ptr = MI->getOperand(1).getReg(); |
| 4412 | unsigned incr = MI->getOperand(2).getReg(); |
| 4413 | DebugLoc dl = MI->getDebugLoc(); |
Rafael Espindola | fda60d3 | 2009-12-18 16:59:39 +0000 | [diff] [blame] | 4414 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4415 | bool isThumb2 = Subtarget->isThumb2(); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 4416 | unsigned ldrOpc, strOpc; |
| 4417 | switch (Size) { |
| 4418 | default: llvm_unreachable("unsupported size for AtomicCmpSwap!"); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4419 | case 1: |
| 4420 | ldrOpc = isThumb2 ? ARM::t2LDREXB : ARM::LDREXB; |
Jakob Stoklund Olesen | 15913c9 | 2010-01-13 19:54:39 +0000 | [diff] [blame] | 4421 | strOpc = isThumb2 ? ARM::t2STREXB : ARM::STREXB; |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4422 | break; |
| 4423 | case 2: |
| 4424 | ldrOpc = isThumb2 ? ARM::t2LDREXH : ARM::LDREXH; |
| 4425 | strOpc = isThumb2 ? ARM::t2STREXH : ARM::STREXH; |
| 4426 | break; |
| 4427 | case 4: |
| 4428 | ldrOpc = isThumb2 ? ARM::t2LDREX : ARM::LDREX; |
| 4429 | strOpc = isThumb2 ? ARM::t2STREX : ARM::STREX; |
| 4430 | break; |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 4431 | } |
| 4432 | |
Jim Grosbach | 867bbbf | 2010-01-15 00:22:18 +0000 | [diff] [blame] | 4433 | MachineBasicBlock *loopMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 4434 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 4435 | MF->insert(It, loopMBB); |
| 4436 | MF->insert(It, exitMBB); |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 4437 | |
| 4438 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 4439 | exitMBB->splice(exitMBB->begin(), BB, |
| 4440 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 4441 | BB->end()); |
| 4442 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 4443 | |
Jim Grosbach | 867bbbf | 2010-01-15 00:22:18 +0000 | [diff] [blame] | 4444 | MachineRegisterInfo &RegInfo = MF->getRegInfo(); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 4445 | unsigned scratch = RegInfo.createVirtualRegister(ARM::GPRRegisterClass); |
| 4446 | unsigned scratch2 = (!BinOpcode) ? incr : |
| 4447 | RegInfo.createVirtualRegister(ARM::GPRRegisterClass); |
| 4448 | |
| 4449 | // thisMBB: |
| 4450 | // ... |
| 4451 | // fallthrough --> loopMBB |
| 4452 | BB->addSuccessor(loopMBB); |
| 4453 | |
| 4454 | // loopMBB: |
| 4455 | // ldrex dest, ptr |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4456 | // <binop> scratch2, dest, incr |
| 4457 | // strex scratch, scratch2, ptr |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 4458 | // cmp scratch, #0 |
| 4459 | // bne- loopMBB |
| 4460 | // fallthrough --> exitMBB |
| 4461 | BB = loopMBB; |
| 4462 | AddDefaultPred(BuildMI(BB, dl, TII->get(ldrOpc), dest).addReg(ptr)); |
Jim Grosbach | c67b556 | 2009-12-15 00:12:35 +0000 | [diff] [blame] | 4463 | if (BinOpcode) { |
| 4464 | // operand order needs to go the other way for NAND |
| 4465 | if (BinOpcode == ARM::BICrr || BinOpcode == ARM::t2BICrr) |
| 4466 | AddDefaultPred(BuildMI(BB, dl, TII->get(BinOpcode), scratch2). |
| 4467 | addReg(incr).addReg(dest)).addReg(0); |
| 4468 | else |
| 4469 | AddDefaultPred(BuildMI(BB, dl, TII->get(BinOpcode), scratch2). |
| 4470 | addReg(dest).addReg(incr)).addReg(0); |
| 4471 | } |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 4472 | |
| 4473 | AddDefaultPred(BuildMI(BB, dl, TII->get(strOpc), scratch).addReg(scratch2) |
| 4474 | .addReg(ptr)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4475 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 4476 | .addReg(scratch).addImm(0)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4477 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 4478 | .addMBB(loopMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 4479 | |
| 4480 | BB->addSuccessor(loopMBB); |
| 4481 | BB->addSuccessor(exitMBB); |
| 4482 | |
| 4483 | // exitMBB: |
| 4484 | // ... |
| 4485 | BB = exitMBB; |
Evan Cheng | 102ebf1 | 2009-12-21 19:53:39 +0000 | [diff] [blame] | 4486 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 4487 | MI->eraseFromParent(); // The instruction is gone now. |
Evan Cheng | 102ebf1 | 2009-12-21 19:53:39 +0000 | [diff] [blame] | 4488 | |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 4489 | return BB; |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 4490 | } |
| 4491 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 4492 | static |
| 4493 | MachineBasicBlock *OtherSucc(MachineBasicBlock *MBB, MachineBasicBlock *Succ) { |
| 4494 | for (MachineBasicBlock::succ_iterator I = MBB->succ_begin(), |
| 4495 | E = MBB->succ_end(); I != E; ++I) |
| 4496 | if (*I != Succ) |
| 4497 | return *I; |
| 4498 | llvm_unreachable("Expecting a BB with two successors!"); |
| 4499 | } |
| 4500 | |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 4501 | MachineBasicBlock * |
Evan Cheng | ff9b373 | 2008-01-30 18:18:23 +0000 | [diff] [blame] | 4502 | ARMTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI, |
Dan Gohman | af1d8ca | 2010-05-01 00:01:06 +0000 | [diff] [blame] | 4503 | MachineBasicBlock *BB) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4504 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
Dale Johannesen | b672840 | 2009-02-13 02:25:56 +0000 | [diff] [blame] | 4505 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4506 | bool isThumb2 = Subtarget->isThumb2(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4507 | switch (MI->getOpcode()) { |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 4508 | default: |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4509 | MI->dump(); |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 4510 | llvm_unreachable("Unexpected instr type to insert"); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4511 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4512 | case ARM::ATOMIC_LOAD_ADD_I8: |
| 4513 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr); |
| 4514 | case ARM::ATOMIC_LOAD_ADD_I16: |
| 4515 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr); |
| 4516 | case ARM::ATOMIC_LOAD_ADD_I32: |
| 4517 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4518 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4519 | case ARM::ATOMIC_LOAD_AND_I8: |
| 4520 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
| 4521 | case ARM::ATOMIC_LOAD_AND_I16: |
| 4522 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
| 4523 | case ARM::ATOMIC_LOAD_AND_I32: |
| 4524 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4525 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4526 | case ARM::ATOMIC_LOAD_OR_I8: |
| 4527 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
| 4528 | case ARM::ATOMIC_LOAD_OR_I16: |
| 4529 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
| 4530 | case ARM::ATOMIC_LOAD_OR_I32: |
| 4531 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4532 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4533 | case ARM::ATOMIC_LOAD_XOR_I8: |
| 4534 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
| 4535 | case ARM::ATOMIC_LOAD_XOR_I16: |
| 4536 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
| 4537 | case ARM::ATOMIC_LOAD_XOR_I32: |
| 4538 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 4539 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4540 | case ARM::ATOMIC_LOAD_NAND_I8: |
| 4541 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2BICrr : ARM::BICrr); |
| 4542 | case ARM::ATOMIC_LOAD_NAND_I16: |
| 4543 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2BICrr : ARM::BICrr); |
| 4544 | case ARM::ATOMIC_LOAD_NAND_I32: |
| 4545 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2BICrr : ARM::BICrr); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 4546 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4547 | case ARM::ATOMIC_LOAD_SUB_I8: |
| 4548 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr); |
| 4549 | case ARM::ATOMIC_LOAD_SUB_I16: |
| 4550 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr); |
| 4551 | case ARM::ATOMIC_LOAD_SUB_I32: |
| 4552 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 4553 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4554 | case ARM::ATOMIC_SWAP_I8: return EmitAtomicBinary(MI, BB, 1, 0); |
| 4555 | case ARM::ATOMIC_SWAP_I16: return EmitAtomicBinary(MI, BB, 2, 0); |
| 4556 | case ARM::ATOMIC_SWAP_I32: return EmitAtomicBinary(MI, BB, 4, 0); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 4557 | |
| 4558 | case ARM::ATOMIC_CMP_SWAP_I8: return EmitAtomicCmpSwap(MI, BB, 1); |
| 4559 | case ARM::ATOMIC_CMP_SWAP_I16: return EmitAtomicCmpSwap(MI, BB, 2); |
| 4560 | case ARM::ATOMIC_CMP_SWAP_I32: return EmitAtomicCmpSwap(MI, BB, 4); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4561 | |
Evan Cheng | 007ea27 | 2009-08-12 05:17:19 +0000 | [diff] [blame] | 4562 | case ARM::tMOVCCr_pseudo: { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4563 | // To "insert" a SELECT_CC instruction, we actually have to insert the |
| 4564 | // diamond control-flow pattern. The incoming instruction knows the |
| 4565 | // destination vreg to set, the condition code register to branch on, the |
| 4566 | // true/false values to select between, and a branch opcode to use. |
| 4567 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 4568 | MachineFunction::iterator It = BB; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4569 | ++It; |
| 4570 | |
| 4571 | // thisMBB: |
| 4572 | // ... |
| 4573 | // TrueVal = ... |
| 4574 | // cmpTY ccX, r1, r2 |
| 4575 | // bCC copy1MBB |
| 4576 | // fallthrough --> copy0MBB |
| 4577 | MachineBasicBlock *thisMBB = BB; |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 4578 | MachineFunction *F = BB->getParent(); |
| 4579 | MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB); |
| 4580 | MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB); |
Dan Gohman | 258c58c | 2010-07-06 15:49:48 +0000 | [diff] [blame] | 4581 | F->insert(It, copy0MBB); |
| 4582 | F->insert(It, sinkMBB); |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 4583 | |
| 4584 | // Transfer the remainder of BB and its successor edges to sinkMBB. |
| 4585 | sinkMBB->splice(sinkMBB->begin(), BB, |
| 4586 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 4587 | BB->end()); |
| 4588 | sinkMBB->transferSuccessorsAndUpdatePHIs(BB); |
| 4589 | |
Dan Gohman | 258c58c | 2010-07-06 15:49:48 +0000 | [diff] [blame] | 4590 | BB->addSuccessor(copy0MBB); |
| 4591 | BB->addSuccessor(sinkMBB); |
Dan Gohman | b81c771 | 2010-07-06 15:18:19 +0000 | [diff] [blame] | 4592 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 4593 | BuildMI(BB, dl, TII->get(ARM::tBcc)).addMBB(sinkMBB) |
| 4594 | .addImm(MI->getOperand(3).getImm()).addReg(MI->getOperand(4).getReg()); |
| 4595 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4596 | // copy0MBB: |
| 4597 | // %FalseValue = ... |
| 4598 | // # fallthrough to sinkMBB |
| 4599 | BB = copy0MBB; |
| 4600 | |
| 4601 | // Update machine-CFG edges |
| 4602 | BB->addSuccessor(sinkMBB); |
| 4603 | |
| 4604 | // sinkMBB: |
| 4605 | // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ] |
| 4606 | // ... |
| 4607 | BB = sinkMBB; |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 4608 | BuildMI(*BB, BB->begin(), dl, |
| 4609 | TII->get(ARM::PHI), MI->getOperand(0).getReg()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4610 | .addReg(MI->getOperand(1).getReg()).addMBB(copy0MBB) |
| 4611 | .addReg(MI->getOperand(2).getReg()).addMBB(thisMBB); |
| 4612 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 4613 | MI->eraseFromParent(); // The pseudo instruction is gone now. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4614 | return BB; |
| 4615 | } |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 4616 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 4617 | case ARM::BCCi64: |
| 4618 | case ARM::BCCZi64: { |
Bob Wilson | 3c90469 | 2010-12-23 22:45:49 +0000 | [diff] [blame] | 4619 | // If there is an unconditional branch to the other successor, remove it. |
| 4620 | BB->erase(llvm::next(MachineBasicBlock::iterator(MI)), BB->end()); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4621 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 4622 | // Compare both parts that make up the double comparison separately for |
| 4623 | // equality. |
| 4624 | bool RHSisZero = MI->getOpcode() == ARM::BCCZi64; |
| 4625 | |
| 4626 | unsigned LHS1 = MI->getOperand(1).getReg(); |
| 4627 | unsigned LHS2 = MI->getOperand(2).getReg(); |
| 4628 | if (RHSisZero) { |
| 4629 | AddDefaultPred(BuildMI(BB, dl, |
| 4630 | TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 4631 | .addReg(LHS1).addImm(0)); |
| 4632 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 4633 | .addReg(LHS2).addImm(0) |
| 4634 | .addImm(ARMCC::EQ).addReg(ARM::CPSR); |
| 4635 | } else { |
| 4636 | unsigned RHS1 = MI->getOperand(3).getReg(); |
| 4637 | unsigned RHS2 = MI->getOperand(4).getReg(); |
| 4638 | AddDefaultPred(BuildMI(BB, dl, |
| 4639 | TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
| 4640 | .addReg(LHS1).addReg(RHS1)); |
| 4641 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
| 4642 | .addReg(LHS2).addReg(RHS2) |
| 4643 | .addImm(ARMCC::EQ).addReg(ARM::CPSR); |
| 4644 | } |
| 4645 | |
| 4646 | MachineBasicBlock *destMBB = MI->getOperand(RHSisZero ? 3 : 5).getMBB(); |
| 4647 | MachineBasicBlock *exitMBB = OtherSucc(BB, destMBB); |
| 4648 | if (MI->getOperand(0).getImm() == ARMCC::NE) |
| 4649 | std::swap(destMBB, exitMBB); |
| 4650 | |
| 4651 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 4652 | .addMBB(destMBB).addImm(ARMCC::EQ).addReg(ARM::CPSR); |
| 4653 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2B : ARM::B)) |
| 4654 | .addMBB(exitMBB); |
| 4655 | |
| 4656 | MI->eraseFromParent(); // The pseudo instruction is gone now. |
| 4657 | return BB; |
| 4658 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4659 | } |
| 4660 | } |
| 4661 | |
| 4662 | //===----------------------------------------------------------------------===// |
| 4663 | // ARM Optimization Hooks |
| 4664 | //===----------------------------------------------------------------------===// |
| 4665 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 4666 | static |
| 4667 | SDValue combineSelectAndUse(SDNode *N, SDValue Slct, SDValue OtherOp, |
| 4668 | TargetLowering::DAGCombinerInfo &DCI) { |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 4669 | SelectionDAG &DAG = DCI.DAG; |
| 4670 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4671 | EVT VT = N->getValueType(0); |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 4672 | unsigned Opc = N->getOpcode(); |
| 4673 | bool isSlctCC = Slct.getOpcode() == ISD::SELECT_CC; |
| 4674 | SDValue LHS = isSlctCC ? Slct.getOperand(2) : Slct.getOperand(1); |
| 4675 | SDValue RHS = isSlctCC ? Slct.getOperand(3) : Slct.getOperand(2); |
| 4676 | ISD::CondCode CC = ISD::SETCC_INVALID; |
| 4677 | |
| 4678 | if (isSlctCC) { |
| 4679 | CC = cast<CondCodeSDNode>(Slct.getOperand(4))->get(); |
| 4680 | } else { |
| 4681 | SDValue CCOp = Slct.getOperand(0); |
| 4682 | if (CCOp.getOpcode() == ISD::SETCC) |
| 4683 | CC = cast<CondCodeSDNode>(CCOp.getOperand(2))->get(); |
| 4684 | } |
| 4685 | |
| 4686 | bool DoXform = false; |
| 4687 | bool InvCC = false; |
| 4688 | assert ((Opc == ISD::ADD || (Opc == ISD::SUB && Slct == N->getOperand(1))) && |
| 4689 | "Bad input!"); |
| 4690 | |
| 4691 | if (LHS.getOpcode() == ISD::Constant && |
| 4692 | cast<ConstantSDNode>(LHS)->isNullValue()) { |
| 4693 | DoXform = true; |
| 4694 | } else if (CC != ISD::SETCC_INVALID && |
| 4695 | RHS.getOpcode() == ISD::Constant && |
| 4696 | cast<ConstantSDNode>(RHS)->isNullValue()) { |
| 4697 | std::swap(LHS, RHS); |
| 4698 | SDValue Op0 = Slct.getOperand(0); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4699 | EVT OpVT = isSlctCC ? Op0.getValueType() : |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 4700 | Op0.getOperand(0).getValueType(); |
| 4701 | bool isInt = OpVT.isInteger(); |
| 4702 | CC = ISD::getSetCCInverse(CC, isInt); |
| 4703 | |
| 4704 | if (!TLI.isCondCodeLegal(CC, OpVT)) |
| 4705 | return SDValue(); // Inverse operator isn't legal. |
| 4706 | |
| 4707 | DoXform = true; |
| 4708 | InvCC = true; |
| 4709 | } |
| 4710 | |
| 4711 | if (DoXform) { |
| 4712 | SDValue Result = DAG.getNode(Opc, RHS.getDebugLoc(), VT, OtherOp, RHS); |
| 4713 | if (isSlctCC) |
| 4714 | return DAG.getSelectCC(N->getDebugLoc(), OtherOp, Result, |
| 4715 | Slct.getOperand(0), Slct.getOperand(1), CC); |
| 4716 | SDValue CCOp = Slct.getOperand(0); |
| 4717 | if (InvCC) |
| 4718 | CCOp = DAG.getSetCC(Slct.getDebugLoc(), CCOp.getValueType(), |
| 4719 | CCOp.getOperand(0), CCOp.getOperand(1), CC); |
| 4720 | return DAG.getNode(ISD::SELECT, N->getDebugLoc(), VT, |
| 4721 | CCOp, OtherOp, Result); |
| 4722 | } |
| 4723 | return SDValue(); |
| 4724 | } |
| 4725 | |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 4726 | /// PerformADDCombineWithOperands - Try DAG combinations for an ADD with |
| 4727 | /// operands N0 and N1. This is a helper for PerformADDCombine that is |
| 4728 | /// called with the default operands, and if that fails, with commuted |
| 4729 | /// operands. |
| 4730 | static SDValue PerformADDCombineWithOperands(SDNode *N, SDValue N0, SDValue N1, |
| 4731 | TargetLowering::DAGCombinerInfo &DCI) { |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 4732 | // fold (add (select cc, 0, c), x) -> (select cc, x, (add, x, c)) |
| 4733 | if (N0.getOpcode() == ISD::SELECT && N0.getNode()->hasOneUse()) { |
| 4734 | SDValue Result = combineSelectAndUse(N, N0, N1, DCI); |
| 4735 | if (Result.getNode()) return Result; |
| 4736 | } |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 4737 | return SDValue(); |
| 4738 | } |
| 4739 | |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 4740 | /// PerformADDCombine - Target-specific dag combine xforms for ISD::ADD. |
| 4741 | /// |
| 4742 | static SDValue PerformADDCombine(SDNode *N, |
| 4743 | TargetLowering::DAGCombinerInfo &DCI) { |
| 4744 | SDValue N0 = N->getOperand(0); |
| 4745 | SDValue N1 = N->getOperand(1); |
| 4746 | |
| 4747 | // First try with the default operand order. |
| 4748 | SDValue Result = PerformADDCombineWithOperands(N, N0, N1, DCI); |
| 4749 | if (Result.getNode()) |
| 4750 | return Result; |
| 4751 | |
| 4752 | // If that didn't work, try again with the operands commuted. |
| 4753 | return PerformADDCombineWithOperands(N, N1, N0, DCI); |
| 4754 | } |
| 4755 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 4756 | /// PerformSUBCombine - Target-specific dag combine xforms for ISD::SUB. |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 4757 | /// |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 4758 | static SDValue PerformSUBCombine(SDNode *N, |
| 4759 | TargetLowering::DAGCombinerInfo &DCI) { |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 4760 | SDValue N0 = N->getOperand(0); |
| 4761 | SDValue N1 = N->getOperand(1); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 4762 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 4763 | // fold (sub x, (select cc, 0, c)) -> (select cc, x, (sub, x, c)) |
| 4764 | if (N1.getOpcode() == ISD::SELECT && N1.getNode()->hasOneUse()) { |
| 4765 | SDValue Result = combineSelectAndUse(N, N1, N0, DCI); |
| 4766 | if (Result.getNode()) return Result; |
| 4767 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 4768 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 4769 | return SDValue(); |
| 4770 | } |
| 4771 | |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 4772 | static SDValue PerformMULCombine(SDNode *N, |
| 4773 | TargetLowering::DAGCombinerInfo &DCI, |
| 4774 | const ARMSubtarget *Subtarget) { |
| 4775 | SelectionDAG &DAG = DCI.DAG; |
| 4776 | |
| 4777 | if (Subtarget->isThumb1Only()) |
| 4778 | return SDValue(); |
| 4779 | |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 4780 | if (DCI.isBeforeLegalize() || DCI.isCalledByLegalizer()) |
| 4781 | return SDValue(); |
| 4782 | |
| 4783 | EVT VT = N->getValueType(0); |
| 4784 | if (VT != MVT::i32) |
| 4785 | return SDValue(); |
| 4786 | |
| 4787 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1)); |
| 4788 | if (!C) |
| 4789 | return SDValue(); |
| 4790 | |
| 4791 | uint64_t MulAmt = C->getZExtValue(); |
| 4792 | unsigned ShiftAmt = CountTrailingZeros_64(MulAmt); |
| 4793 | ShiftAmt = ShiftAmt & (32 - 1); |
| 4794 | SDValue V = N->getOperand(0); |
| 4795 | DebugLoc DL = N->getDebugLoc(); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 4796 | |
Anton Korobeynikov | 4878b84 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 4797 | SDValue Res; |
| 4798 | MulAmt >>= ShiftAmt; |
| 4799 | if (isPowerOf2_32(MulAmt - 1)) { |
| 4800 | // (mul x, 2^N + 1) => (add (shl x, N), x) |
| 4801 | Res = DAG.getNode(ISD::ADD, DL, VT, |
| 4802 | V, DAG.getNode(ISD::SHL, DL, VT, |
| 4803 | V, DAG.getConstant(Log2_32(MulAmt-1), |
| 4804 | MVT::i32))); |
| 4805 | } else if (isPowerOf2_32(MulAmt + 1)) { |
| 4806 | // (mul x, 2^N - 1) => (sub (shl x, N), x) |
| 4807 | Res = DAG.getNode(ISD::SUB, DL, VT, |
| 4808 | DAG.getNode(ISD::SHL, DL, VT, |
| 4809 | V, DAG.getConstant(Log2_32(MulAmt+1), |
| 4810 | MVT::i32)), |
| 4811 | V); |
| 4812 | } else |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 4813 | return SDValue(); |
Anton Korobeynikov | 4878b84 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 4814 | |
| 4815 | if (ShiftAmt != 0) |
| 4816 | Res = DAG.getNode(ISD::SHL, DL, VT, Res, |
| 4817 | DAG.getConstant(ShiftAmt, MVT::i32)); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 4818 | |
| 4819 | // Do not add new nodes to DAG combiner worklist. |
Anton Korobeynikov | 4878b84 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 4820 | DCI.CombineTo(N, Res, false); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 4821 | return SDValue(); |
| 4822 | } |
| 4823 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 4824 | static SDValue PerformANDCombine(SDNode *N, |
| 4825 | TargetLowering::DAGCombinerInfo &DCI) { |
| 4826 | // Attempt to use immediate-form VBIC |
| 4827 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(N->getOperand(1)); |
| 4828 | DebugLoc dl = N->getDebugLoc(); |
| 4829 | EVT VT = N->getValueType(0); |
| 4830 | SelectionDAG &DAG = DCI.DAG; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4831 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 4832 | APInt SplatBits, SplatUndef; |
| 4833 | unsigned SplatBitSize; |
| 4834 | bool HasAnyUndefs; |
| 4835 | if (BVN && |
| 4836 | BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { |
| 4837 | if (SplatBitSize <= 64) { |
| 4838 | EVT VbicVT; |
| 4839 | SDValue Val = isNEONModifiedImm((~SplatBits).getZExtValue(), |
| 4840 | SplatUndef.getZExtValue(), SplatBitSize, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4841 | DAG, VbicVT, VT.is128BitVector(), |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 4842 | OtherModImm); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 4843 | if (Val.getNode()) { |
| 4844 | SDValue Input = |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4845 | DAG.getNode(ISD::BITCAST, dl, VbicVT, N->getOperand(0)); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 4846 | SDValue Vbic = DAG.getNode(ARMISD::VBICIMM, dl, VbicVT, Input, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4847 | return DAG.getNode(ISD::BITCAST, dl, VT, Vbic); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 4848 | } |
| 4849 | } |
| 4850 | } |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4851 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 4852 | return SDValue(); |
| 4853 | } |
| 4854 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 4855 | /// PerformORCombine - Target-specific dag combine xforms for ISD::OR |
| 4856 | static SDValue PerformORCombine(SDNode *N, |
| 4857 | TargetLowering::DAGCombinerInfo &DCI, |
| 4858 | const ARMSubtarget *Subtarget) { |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 4859 | // Attempt to use immediate-form VORR |
| 4860 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(N->getOperand(1)); |
| 4861 | DebugLoc dl = N->getDebugLoc(); |
| 4862 | EVT VT = N->getValueType(0); |
| 4863 | SelectionDAG &DAG = DCI.DAG; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4864 | |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 4865 | APInt SplatBits, SplatUndef; |
| 4866 | unsigned SplatBitSize; |
| 4867 | bool HasAnyUndefs; |
| 4868 | if (BVN && Subtarget->hasNEON() && |
| 4869 | BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { |
| 4870 | if (SplatBitSize <= 64) { |
| 4871 | EVT VorrVT; |
| 4872 | SDValue Val = isNEONModifiedImm(SplatBits.getZExtValue(), |
| 4873 | SplatUndef.getZExtValue(), SplatBitSize, |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 4874 | DAG, VorrVT, VT.is128BitVector(), |
| 4875 | OtherModImm); |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 4876 | if (Val.getNode()) { |
| 4877 | SDValue Input = |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4878 | DAG.getNode(ISD::BITCAST, dl, VorrVT, N->getOperand(0)); |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 4879 | SDValue Vorr = DAG.getNode(ARMISD::VORRIMM, dl, VorrVT, Input, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4880 | return DAG.getNode(ISD::BITCAST, dl, VT, Vorr); |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 4881 | } |
| 4882 | } |
| 4883 | } |
| 4884 | |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 4885 | // Try to use the ARM/Thumb2 BFI (bitfield insert) instruction when |
| 4886 | // reasonable. |
| 4887 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 4888 | // BFI is only available on V6T2+ |
| 4889 | if (Subtarget->isThumb1Only() || !Subtarget->hasV6T2Ops()) |
| 4890 | return SDValue(); |
| 4891 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 4892 | SDValue N0 = N->getOperand(0), N1 = N->getOperand(1); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 4893 | DebugLoc DL = N->getDebugLoc(); |
| 4894 | // 1) or (and A, mask), val => ARMbfi A, val, mask |
| 4895 | // iff (val & mask) == val |
| 4896 | // |
| 4897 | // 2) or (and A, mask), (and B, mask2) => ARMbfi A, (lsr B, amt), mask |
| 4898 | // 2a) iff isBitFieldInvertedMask(mask) && isBitFieldInvertedMask(~mask2) |
| 4899 | // && CountPopulation_32(mask) == CountPopulation_32(~mask2) |
| 4900 | // 2b) iff isBitFieldInvertedMask(~mask) && isBitFieldInvertedMask(mask2) |
| 4901 | // && CountPopulation_32(mask) == CountPopulation_32(~mask2) |
| 4902 | // (i.e., copy a bitfield value into another bitfield of the same width) |
| 4903 | if (N0.getOpcode() != ISD::AND) |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 4904 | return SDValue(); |
| 4905 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 4906 | if (VT != MVT::i32) |
| 4907 | return SDValue(); |
| 4908 | |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 4909 | SDValue N00 = N0.getOperand(0); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 4910 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 4911 | // The value and the mask need to be constants so we can verify this is |
| 4912 | // actually a bitfield set. If the mask is 0xffff, we can do better |
| 4913 | // via a movt instruction, so don't use BFI in that case. |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 4914 | SDValue MaskOp = N0.getOperand(1); |
| 4915 | ConstantSDNode *MaskC = dyn_cast<ConstantSDNode>(MaskOp); |
| 4916 | if (!MaskC) |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 4917 | return SDValue(); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 4918 | unsigned Mask = MaskC->getZExtValue(); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 4919 | if (Mask == 0xffff) |
| 4920 | return SDValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 4921 | SDValue Res; |
| 4922 | // Case (1): or (and A, mask), val => ARMbfi A, val, mask |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 4923 | ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1); |
| 4924 | if (N1C) { |
| 4925 | unsigned Val = N1C->getZExtValue(); |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 4926 | if ((Val & ~Mask) != Val) |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 4927 | return SDValue(); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 4928 | |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 4929 | if (ARM::isBitFieldInvertedMask(Mask)) { |
| 4930 | Val >>= CountTrailingZeros_32(~Mask); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 4931 | |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 4932 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N00, |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 4933 | DAG.getConstant(Val, MVT::i32), |
| 4934 | DAG.getConstant(Mask, MVT::i32)); |
| 4935 | |
| 4936 | // Do not add new nodes to DAG combiner worklist. |
| 4937 | DCI.CombineTo(N, Res, false); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 4938 | return SDValue(); |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 4939 | } |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 4940 | } else if (N1.getOpcode() == ISD::AND) { |
| 4941 | // 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] | 4942 | ConstantSDNode *N11C = dyn_cast<ConstantSDNode>(N1.getOperand(1)); |
| 4943 | if (!N11C) |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 4944 | return SDValue(); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 4945 | unsigned Mask2 = N11C->getZExtValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 4946 | |
| 4947 | if (ARM::isBitFieldInvertedMask(Mask) && |
| 4948 | ARM::isBitFieldInvertedMask(~Mask2) && |
| 4949 | (CountPopulation_32(Mask) == CountPopulation_32(~Mask2))) { |
| 4950 | // The pack halfword instruction works better for masks that fit it, |
| 4951 | // so use that when it's available. |
| 4952 | if (Subtarget->hasT2ExtractPack() && |
| 4953 | (Mask == 0xffff || Mask == 0xffff0000)) |
| 4954 | return SDValue(); |
| 4955 | // 2a |
| 4956 | unsigned lsb = CountTrailingZeros_32(Mask2); |
| 4957 | Res = DAG.getNode(ISD::SRL, DL, VT, N1.getOperand(0), |
| 4958 | DAG.getConstant(lsb, MVT::i32)); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 4959 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N00, Res, |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 4960 | DAG.getConstant(Mask, MVT::i32)); |
| 4961 | // Do not add new nodes to DAG combiner worklist. |
| 4962 | DCI.CombineTo(N, Res, false); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 4963 | return SDValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 4964 | } else if (ARM::isBitFieldInvertedMask(~Mask) && |
| 4965 | ARM::isBitFieldInvertedMask(Mask2) && |
| 4966 | (CountPopulation_32(~Mask) == CountPopulation_32(Mask2))) { |
| 4967 | // The pack halfword instruction works better for masks that fit it, |
| 4968 | // so use that when it's available. |
| 4969 | if (Subtarget->hasT2ExtractPack() && |
| 4970 | (Mask2 == 0xffff || Mask2 == 0xffff0000)) |
| 4971 | return SDValue(); |
| 4972 | // 2b |
| 4973 | unsigned lsb = CountTrailingZeros_32(Mask); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 4974 | Res = DAG.getNode(ISD::SRL, DL, VT, N00, |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 4975 | DAG.getConstant(lsb, MVT::i32)); |
| 4976 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N1.getOperand(0), Res, |
| 4977 | DAG.getConstant(Mask2, MVT::i32)); |
| 4978 | // Do not add new nodes to DAG combiner worklist. |
| 4979 | DCI.CombineTo(N, Res, false); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 4980 | return SDValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 4981 | } |
| 4982 | } |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4983 | |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 4984 | if (DAG.MaskedValueIsZero(N1, MaskC->getAPIntValue()) && |
| 4985 | N00.getOpcode() == ISD::SHL && isa<ConstantSDNode>(N00.getOperand(1)) && |
| 4986 | ARM::isBitFieldInvertedMask(~Mask)) { |
| 4987 | // Case (3): or (and (shl A, #shamt), mask), B => ARMbfi B, A, ~mask |
| 4988 | // where lsb(mask) == #shamt and masked bits of B are known zero. |
| 4989 | SDValue ShAmt = N00.getOperand(1); |
| 4990 | unsigned ShAmtC = cast<ConstantSDNode>(ShAmt)->getZExtValue(); |
| 4991 | unsigned LSB = CountTrailingZeros_32(Mask); |
| 4992 | if (ShAmtC != LSB) |
| 4993 | return SDValue(); |
| 4994 | |
| 4995 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N1, N00.getOperand(0), |
| 4996 | DAG.getConstant(~Mask, MVT::i32)); |
| 4997 | |
| 4998 | // Do not add new nodes to DAG combiner worklist. |
| 4999 | DCI.CombineTo(N, Res, false); |
| 5000 | } |
| 5001 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 5002 | return SDValue(); |
| 5003 | } |
| 5004 | |
Evan Cheng | 0c1aec1 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 5005 | /// PerformBFICombine - (bfi A, (and B, C1), C2) -> (bfi A, B, C2) iff |
| 5006 | /// C1 & C2 == C1. |
| 5007 | static SDValue PerformBFICombine(SDNode *N, |
| 5008 | TargetLowering::DAGCombinerInfo &DCI) { |
| 5009 | SDValue N1 = N->getOperand(1); |
| 5010 | if (N1.getOpcode() == ISD::AND) { |
| 5011 | ConstantSDNode *N11C = dyn_cast<ConstantSDNode>(N1.getOperand(1)); |
| 5012 | if (!N11C) |
| 5013 | return SDValue(); |
| 5014 | unsigned Mask = cast<ConstantSDNode>(N->getOperand(2))->getZExtValue(); |
| 5015 | unsigned Mask2 = N11C->getZExtValue(); |
| 5016 | if ((Mask & Mask2) == Mask2) |
| 5017 | return DCI.DAG.getNode(ARMISD::BFI, N->getDebugLoc(), N->getValueType(0), |
| 5018 | N->getOperand(0), N1.getOperand(0), |
| 5019 | N->getOperand(2)); |
| 5020 | } |
| 5021 | return SDValue(); |
| 5022 | } |
| 5023 | |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 5024 | /// PerformVMOVRRDCombine - Target-specific dag combine xforms for |
| 5025 | /// ARMISD::VMOVRRD. |
| 5026 | static SDValue PerformVMOVRRDCombine(SDNode *N, |
| 5027 | TargetLowering::DAGCombinerInfo &DCI) { |
| 5028 | // vmovrrd(vmovdrr x, y) -> x,y |
| 5029 | SDValue InDouble = N->getOperand(0); |
| 5030 | if (InDouble.getOpcode() == ARMISD::VMOVDRR) |
| 5031 | return DCI.CombineTo(N, InDouble.getOperand(0), InDouble.getOperand(1)); |
| 5032 | return SDValue(); |
| 5033 | } |
| 5034 | |
| 5035 | /// PerformVMOVDRRCombine - Target-specific dag combine xforms for |
| 5036 | /// ARMISD::VMOVDRR. This is also used for BUILD_VECTORs with 2 operands. |
| 5037 | static SDValue PerformVMOVDRRCombine(SDNode *N, SelectionDAG &DAG) { |
| 5038 | // N=vmovrrd(X); vmovdrr(N:0, N:1) -> bit_convert(X) |
| 5039 | SDValue Op0 = N->getOperand(0); |
| 5040 | SDValue Op1 = N->getOperand(1); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5041 | if (Op0.getOpcode() == ISD::BITCAST) |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 5042 | Op0 = Op0.getOperand(0); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5043 | if (Op1.getOpcode() == ISD::BITCAST) |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 5044 | Op1 = Op1.getOperand(0); |
| 5045 | if (Op0.getOpcode() == ARMISD::VMOVRRD && |
| 5046 | Op0.getNode() == Op1.getNode() && |
| 5047 | Op0.getResNo() == 0 && Op1.getResNo() == 1) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5048 | return DAG.getNode(ISD::BITCAST, N->getDebugLoc(), |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 5049 | N->getValueType(0), Op0.getOperand(0)); |
| 5050 | return SDValue(); |
| 5051 | } |
| 5052 | |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 5053 | /// PerformSTORECombine - Target-specific dag combine xforms for |
| 5054 | /// ISD::STORE. |
| 5055 | static SDValue PerformSTORECombine(SDNode *N, |
| 5056 | TargetLowering::DAGCombinerInfo &DCI) { |
| 5057 | // Bitcast an i64 store extracted from a vector to f64. |
| 5058 | // Otherwise, the i64 value will be legalized to a pair of i32 values. |
| 5059 | StoreSDNode *St = cast<StoreSDNode>(N); |
| 5060 | SDValue StVal = St->getValue(); |
| 5061 | if (!ISD::isNormalStore(St) || St->isVolatile() || |
| 5062 | StVal.getValueType() != MVT::i64 || |
| 5063 | StVal.getNode()->getOpcode() != ISD::EXTRACT_VECTOR_ELT) |
| 5064 | return SDValue(); |
| 5065 | |
| 5066 | SelectionDAG &DAG = DCI.DAG; |
| 5067 | DebugLoc dl = StVal.getDebugLoc(); |
| 5068 | SDValue IntVec = StVal.getOperand(0); |
| 5069 | EVT FloatVT = EVT::getVectorVT(*DAG.getContext(), MVT::f64, |
| 5070 | IntVec.getValueType().getVectorNumElements()); |
| 5071 | SDValue Vec = DAG.getNode(ISD::BITCAST, dl, FloatVT, IntVec); |
| 5072 | SDValue ExtElt = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, |
| 5073 | Vec, StVal.getOperand(1)); |
| 5074 | dl = N->getDebugLoc(); |
| 5075 | SDValue V = DAG.getNode(ISD::BITCAST, dl, MVT::i64, ExtElt); |
| 5076 | // Make the DAGCombiner fold the bitcasts. |
| 5077 | DCI.AddToWorklist(Vec.getNode()); |
| 5078 | DCI.AddToWorklist(ExtElt.getNode()); |
| 5079 | DCI.AddToWorklist(V.getNode()); |
| 5080 | return DAG.getStore(St->getChain(), dl, V, St->getBasePtr(), |
| 5081 | St->getPointerInfo(), St->isVolatile(), |
| 5082 | St->isNonTemporal(), St->getAlignment(), |
| 5083 | St->getTBAAInfo()); |
| 5084 | } |
| 5085 | |
| 5086 | /// hasNormalLoadOperand - Check if any of the operands of a BUILD_VECTOR node |
| 5087 | /// are normal, non-volatile loads. If so, it is profitable to bitcast an |
| 5088 | /// i64 vector to have f64 elements, since the value can then be loaded |
| 5089 | /// directly into a VFP register. |
| 5090 | static bool hasNormalLoadOperand(SDNode *N) { |
| 5091 | unsigned NumElts = N->getValueType(0).getVectorNumElements(); |
| 5092 | for (unsigned i = 0; i < NumElts; ++i) { |
| 5093 | SDNode *Elt = N->getOperand(i).getNode(); |
| 5094 | if (ISD::isNormalLoad(Elt) && !cast<LoadSDNode>(Elt)->isVolatile()) |
| 5095 | return true; |
| 5096 | } |
| 5097 | return false; |
| 5098 | } |
| 5099 | |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 5100 | /// PerformBUILD_VECTORCombine - Target-specific dag combine xforms for |
| 5101 | /// ISD::BUILD_VECTOR. |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 5102 | static SDValue PerformBUILD_VECTORCombine(SDNode *N, |
| 5103 | TargetLowering::DAGCombinerInfo &DCI){ |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 5104 | // build_vector(N=ARMISD::VMOVRRD(X), N:1) -> bit_convert(X): |
| 5105 | // VMOVRRD is introduced when legalizing i64 types. It forces the i64 value |
| 5106 | // into a pair of GPRs, which is fine when the value is used as a scalar, |
| 5107 | // 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] | 5108 | SelectionDAG &DAG = DCI.DAG; |
| 5109 | if (N->getNumOperands() == 2) { |
| 5110 | SDValue RV = PerformVMOVDRRCombine(N, DAG); |
| 5111 | if (RV.getNode()) |
| 5112 | return RV; |
| 5113 | } |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 5114 | |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 5115 | // Load i64 elements as f64 values so that type legalization does not split |
| 5116 | // them up into i32 values. |
| 5117 | EVT VT = N->getValueType(0); |
| 5118 | if (VT.getVectorElementType() != MVT::i64 || !hasNormalLoadOperand(N)) |
| 5119 | return SDValue(); |
| 5120 | DebugLoc dl = N->getDebugLoc(); |
| 5121 | SmallVector<SDValue, 8> Ops; |
| 5122 | unsigned NumElts = VT.getVectorNumElements(); |
| 5123 | for (unsigned i = 0; i < NumElts; ++i) { |
| 5124 | SDValue V = DAG.getNode(ISD::BITCAST, dl, MVT::f64, N->getOperand(i)); |
| 5125 | Ops.push_back(V); |
| 5126 | // Make the DAGCombiner fold the bitcast. |
| 5127 | DCI.AddToWorklist(V.getNode()); |
| 5128 | } |
| 5129 | EVT FloatVT = EVT::getVectorVT(*DAG.getContext(), MVT::f64, NumElts); |
| 5130 | SDValue BV = DAG.getNode(ISD::BUILD_VECTOR, dl, FloatVT, Ops.data(), NumElts); |
| 5131 | return DAG.getNode(ISD::BITCAST, dl, VT, BV); |
| 5132 | } |
| 5133 | |
| 5134 | /// PerformInsertEltCombine - Target-specific dag combine xforms for |
| 5135 | /// ISD::INSERT_VECTOR_ELT. |
| 5136 | static SDValue PerformInsertEltCombine(SDNode *N, |
| 5137 | TargetLowering::DAGCombinerInfo &DCI) { |
| 5138 | // Bitcast an i64 load inserted into a vector to f64. |
| 5139 | // Otherwise, the i64 value will be legalized to a pair of i32 values. |
| 5140 | EVT VT = N->getValueType(0); |
| 5141 | SDNode *Elt = N->getOperand(1).getNode(); |
| 5142 | if (VT.getVectorElementType() != MVT::i64 || |
| 5143 | !ISD::isNormalLoad(Elt) || cast<LoadSDNode>(Elt)->isVolatile()) |
| 5144 | return SDValue(); |
| 5145 | |
| 5146 | SelectionDAG &DAG = DCI.DAG; |
| 5147 | DebugLoc dl = N->getDebugLoc(); |
| 5148 | EVT FloatVT = EVT::getVectorVT(*DAG.getContext(), MVT::f64, |
| 5149 | VT.getVectorNumElements()); |
| 5150 | SDValue Vec = DAG.getNode(ISD::BITCAST, dl, FloatVT, N->getOperand(0)); |
| 5151 | SDValue V = DAG.getNode(ISD::BITCAST, dl, MVT::f64, N->getOperand(1)); |
| 5152 | // Make the DAGCombiner fold the bitcasts. |
| 5153 | DCI.AddToWorklist(Vec.getNode()); |
| 5154 | DCI.AddToWorklist(V.getNode()); |
| 5155 | SDValue InsElt = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, FloatVT, |
| 5156 | Vec, V, N->getOperand(2)); |
| 5157 | return DAG.getNode(ISD::BITCAST, dl, VT, InsElt); |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 5158 | } |
| 5159 | |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 5160 | /// PerformVECTOR_SHUFFLECombine - Target-specific dag combine xforms for |
| 5161 | /// ISD::VECTOR_SHUFFLE. |
| 5162 | static SDValue PerformVECTOR_SHUFFLECombine(SDNode *N, SelectionDAG &DAG) { |
| 5163 | // The LLVM shufflevector instruction does not require the shuffle mask |
| 5164 | // length to match the operand vector length, but ISD::VECTOR_SHUFFLE does |
| 5165 | // have that requirement. When translating to ISD::VECTOR_SHUFFLE, if the |
| 5166 | // operands do not match the mask length, they are extended by concatenating |
| 5167 | // them with undef vectors. That is probably the right thing for other |
| 5168 | // targets, but for NEON it is better to concatenate two double-register |
| 5169 | // size vector operands into a single quad-register size vector. Do that |
| 5170 | // transformation here: |
| 5171 | // shuffle(concat(v1, undef), concat(v2, undef)) -> |
| 5172 | // shuffle(concat(v1, v2), undef) |
| 5173 | SDValue Op0 = N->getOperand(0); |
| 5174 | SDValue Op1 = N->getOperand(1); |
| 5175 | if (Op0.getOpcode() != ISD::CONCAT_VECTORS || |
| 5176 | Op1.getOpcode() != ISD::CONCAT_VECTORS || |
| 5177 | Op0.getNumOperands() != 2 || |
| 5178 | Op1.getNumOperands() != 2) |
| 5179 | return SDValue(); |
| 5180 | SDValue Concat0Op1 = Op0.getOperand(1); |
| 5181 | SDValue Concat1Op1 = Op1.getOperand(1); |
| 5182 | if (Concat0Op1.getOpcode() != ISD::UNDEF || |
| 5183 | Concat1Op1.getOpcode() != ISD::UNDEF) |
| 5184 | return SDValue(); |
| 5185 | // Skip the transformation if any of the types are illegal. |
| 5186 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 5187 | EVT VT = N->getValueType(0); |
| 5188 | if (!TLI.isTypeLegal(VT) || |
| 5189 | !TLI.isTypeLegal(Concat0Op1.getValueType()) || |
| 5190 | !TLI.isTypeLegal(Concat1Op1.getValueType())) |
| 5191 | return SDValue(); |
| 5192 | |
| 5193 | SDValue NewConcat = DAG.getNode(ISD::CONCAT_VECTORS, N->getDebugLoc(), VT, |
| 5194 | Op0.getOperand(0), Op1.getOperand(0)); |
| 5195 | // Translate the shuffle mask. |
| 5196 | SmallVector<int, 16> NewMask; |
| 5197 | unsigned NumElts = VT.getVectorNumElements(); |
| 5198 | unsigned HalfElts = NumElts/2; |
| 5199 | ShuffleVectorSDNode *SVN = cast<ShuffleVectorSDNode>(N); |
| 5200 | for (unsigned n = 0; n < NumElts; ++n) { |
| 5201 | int MaskElt = SVN->getMaskElt(n); |
| 5202 | int NewElt = -1; |
Bob Wilson | 1fa9d30 | 2010-10-27 23:49:00 +0000 | [diff] [blame] | 5203 | if (MaskElt < (int)HalfElts) |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 5204 | NewElt = MaskElt; |
Bob Wilson | 1fa9d30 | 2010-10-27 23:49:00 +0000 | [diff] [blame] | 5205 | else if (MaskElt >= (int)NumElts && MaskElt < (int)(NumElts + HalfElts)) |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 5206 | NewElt = HalfElts + MaskElt - NumElts; |
| 5207 | NewMask.push_back(NewElt); |
| 5208 | } |
| 5209 | return DAG.getVectorShuffle(VT, N->getDebugLoc(), NewConcat, |
| 5210 | DAG.getUNDEF(VT), NewMask.data()); |
| 5211 | } |
| 5212 | |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 5213 | /// CombineVLDDUP - For a VDUPLANE node N, check if its source operand is a |
| 5214 | /// vldN-lane (N > 1) intrinsic, and if all the other uses of that intrinsic |
| 5215 | /// are also VDUPLANEs. If so, combine them to a vldN-dup operation and |
| 5216 | /// return true. |
| 5217 | static bool CombineVLDDUP(SDNode *N, TargetLowering::DAGCombinerInfo &DCI) { |
| 5218 | SelectionDAG &DAG = DCI.DAG; |
| 5219 | EVT VT = N->getValueType(0); |
| 5220 | // vldN-dup instructions only support 64-bit vectors for N > 1. |
| 5221 | if (!VT.is64BitVector()) |
| 5222 | return false; |
| 5223 | |
| 5224 | // Check if the VDUPLANE operand is a vldN-dup intrinsic. |
| 5225 | SDNode *VLD = N->getOperand(0).getNode(); |
| 5226 | if (VLD->getOpcode() != ISD::INTRINSIC_W_CHAIN) |
| 5227 | return false; |
| 5228 | unsigned NumVecs = 0; |
| 5229 | unsigned NewOpc = 0; |
| 5230 | unsigned IntNo = cast<ConstantSDNode>(VLD->getOperand(1))->getZExtValue(); |
| 5231 | if (IntNo == Intrinsic::arm_neon_vld2lane) { |
| 5232 | NumVecs = 2; |
| 5233 | NewOpc = ARMISD::VLD2DUP; |
| 5234 | } else if (IntNo == Intrinsic::arm_neon_vld3lane) { |
| 5235 | NumVecs = 3; |
| 5236 | NewOpc = ARMISD::VLD3DUP; |
| 5237 | } else if (IntNo == Intrinsic::arm_neon_vld4lane) { |
| 5238 | NumVecs = 4; |
| 5239 | NewOpc = ARMISD::VLD4DUP; |
| 5240 | } else { |
| 5241 | return false; |
| 5242 | } |
| 5243 | |
| 5244 | // First check that all the vldN-lane uses are VDUPLANEs and that the lane |
| 5245 | // numbers match the load. |
| 5246 | unsigned VLDLaneNo = |
| 5247 | cast<ConstantSDNode>(VLD->getOperand(NumVecs+3))->getZExtValue(); |
| 5248 | for (SDNode::use_iterator UI = VLD->use_begin(), UE = VLD->use_end(); |
| 5249 | UI != UE; ++UI) { |
| 5250 | // Ignore uses of the chain result. |
| 5251 | if (UI.getUse().getResNo() == NumVecs) |
| 5252 | continue; |
| 5253 | SDNode *User = *UI; |
| 5254 | if (User->getOpcode() != ARMISD::VDUPLANE || |
| 5255 | VLDLaneNo != cast<ConstantSDNode>(User->getOperand(1))->getZExtValue()) |
| 5256 | return false; |
| 5257 | } |
| 5258 | |
| 5259 | // Create the vldN-dup node. |
| 5260 | EVT Tys[5]; |
| 5261 | unsigned n; |
| 5262 | for (n = 0; n < NumVecs; ++n) |
| 5263 | Tys[n] = VT; |
| 5264 | Tys[n] = MVT::Other; |
| 5265 | SDVTList SDTys = DAG.getVTList(Tys, NumVecs+1); |
| 5266 | SDValue Ops[] = { VLD->getOperand(0), VLD->getOperand(2) }; |
| 5267 | MemIntrinsicSDNode *VLDMemInt = cast<MemIntrinsicSDNode>(VLD); |
| 5268 | SDValue VLDDup = DAG.getMemIntrinsicNode(NewOpc, VLD->getDebugLoc(), SDTys, |
| 5269 | Ops, 2, VLDMemInt->getMemoryVT(), |
| 5270 | VLDMemInt->getMemOperand()); |
| 5271 | |
| 5272 | // Update the uses. |
| 5273 | for (SDNode::use_iterator UI = VLD->use_begin(), UE = VLD->use_end(); |
| 5274 | UI != UE; ++UI) { |
| 5275 | unsigned ResNo = UI.getUse().getResNo(); |
| 5276 | // Ignore uses of the chain result. |
| 5277 | if (ResNo == NumVecs) |
| 5278 | continue; |
| 5279 | SDNode *User = *UI; |
| 5280 | DCI.CombineTo(User, SDValue(VLDDup.getNode(), ResNo)); |
| 5281 | } |
| 5282 | |
| 5283 | // Now the vldN-lane intrinsic is dead except for its chain result. |
| 5284 | // Update uses of the chain. |
| 5285 | std::vector<SDValue> VLDDupResults; |
| 5286 | for (unsigned n = 0; n < NumVecs; ++n) |
| 5287 | VLDDupResults.push_back(SDValue(VLDDup.getNode(), n)); |
| 5288 | VLDDupResults.push_back(SDValue(VLDDup.getNode(), NumVecs)); |
| 5289 | DCI.CombineTo(VLD, VLDDupResults); |
| 5290 | |
| 5291 | return true; |
| 5292 | } |
| 5293 | |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 5294 | /// PerformVDUPLANECombine - Target-specific dag combine xforms for |
| 5295 | /// ARMISD::VDUPLANE. |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 5296 | static SDValue PerformVDUPLANECombine(SDNode *N, |
| 5297 | TargetLowering::DAGCombinerInfo &DCI) { |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 5298 | SDValue Op = N->getOperand(0); |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 5299 | |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 5300 | // If the source is a vldN-lane (N > 1) intrinsic, and all the other uses |
| 5301 | // of that intrinsic are also VDUPLANEs, combine them to a vldN-dup operation. |
| 5302 | if (CombineVLDDUP(N, DCI)) |
| 5303 | return SDValue(N, 0); |
| 5304 | |
| 5305 | // If the source is already a VMOVIMM or VMVNIMM splat, the VDUPLANE is |
| 5306 | // redundant. Ignore bit_converts for now; element sizes are checked below. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5307 | while (Op.getOpcode() == ISD::BITCAST) |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 5308 | Op = Op.getOperand(0); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 5309 | if (Op.getOpcode() != ARMISD::VMOVIMM && Op.getOpcode() != ARMISD::VMVNIMM) |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 5310 | return SDValue(); |
| 5311 | |
| 5312 | // Make sure the VMOV element size is not bigger than the VDUPLANE elements. |
| 5313 | unsigned EltSize = Op.getValueType().getVectorElementType().getSizeInBits(); |
| 5314 | // The canonical VMOV for a zero vector uses a 32-bit element size. |
| 5315 | unsigned Imm = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
| 5316 | unsigned EltBits; |
| 5317 | if (ARM_AM::decodeNEONModImm(Imm, EltBits) == 0) |
| 5318 | EltSize = 8; |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 5319 | EVT VT = N->getValueType(0); |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 5320 | if (EltSize > VT.getVectorElementType().getSizeInBits()) |
| 5321 | return SDValue(); |
| 5322 | |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 5323 | return DCI.DAG.getNode(ISD::BITCAST, N->getDebugLoc(), VT, Op); |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 5324 | } |
| 5325 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5326 | /// getVShiftImm - Check if this is a valid build_vector for the immediate |
| 5327 | /// operand of a vector shift operation, where all the elements of the |
| 5328 | /// build_vector must have the same constant integer value. |
| 5329 | static bool getVShiftImm(SDValue Op, unsigned ElementBits, int64_t &Cnt) { |
| 5330 | // Ignore bit_converts. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5331 | while (Op.getOpcode() == ISD::BITCAST) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5332 | Op = Op.getOperand(0); |
| 5333 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(Op.getNode()); |
| 5334 | APInt SplatBits, SplatUndef; |
| 5335 | unsigned SplatBitSize; |
| 5336 | bool HasAnyUndefs; |
| 5337 | if (! BVN || ! BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, |
| 5338 | HasAnyUndefs, ElementBits) || |
| 5339 | SplatBitSize > ElementBits) |
| 5340 | return false; |
| 5341 | Cnt = SplatBits.getSExtValue(); |
| 5342 | return true; |
| 5343 | } |
| 5344 | |
| 5345 | /// isVShiftLImm - Check if this is a valid build_vector for the immediate |
| 5346 | /// operand of a vector shift left operation. That value must be in the range: |
| 5347 | /// 0 <= Value < ElementBits for a left shift; or |
| 5348 | /// 0 <= Value <= ElementBits for a long left shift. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 5349 | static bool isVShiftLImm(SDValue Op, EVT VT, bool isLong, int64_t &Cnt) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5350 | assert(VT.isVector() && "vector shift count is not a vector type"); |
| 5351 | unsigned ElementBits = VT.getVectorElementType().getSizeInBits(); |
| 5352 | if (! getVShiftImm(Op, ElementBits, Cnt)) |
| 5353 | return false; |
| 5354 | return (Cnt >= 0 && (isLong ? Cnt-1 : Cnt) < ElementBits); |
| 5355 | } |
| 5356 | |
| 5357 | /// isVShiftRImm - Check if this is a valid build_vector for the immediate |
| 5358 | /// operand of a vector shift right operation. For a shift opcode, the value |
| 5359 | /// is positive, but for an intrinsic the value count must be negative. The |
| 5360 | /// absolute value must be in the range: |
| 5361 | /// 1 <= |Value| <= ElementBits for a right shift; or |
| 5362 | /// 1 <= |Value| <= ElementBits/2 for a narrow right shift. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 5363 | static bool isVShiftRImm(SDValue Op, EVT VT, bool isNarrow, bool isIntrinsic, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5364 | int64_t &Cnt) { |
| 5365 | assert(VT.isVector() && "vector shift count is not a vector type"); |
| 5366 | unsigned ElementBits = VT.getVectorElementType().getSizeInBits(); |
| 5367 | if (! getVShiftImm(Op, ElementBits, Cnt)) |
| 5368 | return false; |
| 5369 | if (isIntrinsic) |
| 5370 | Cnt = -Cnt; |
| 5371 | return (Cnt >= 1 && Cnt <= (isNarrow ? ElementBits/2 : ElementBits)); |
| 5372 | } |
| 5373 | |
| 5374 | /// PerformIntrinsicCombine - ARM-specific DAG combining for intrinsics. |
| 5375 | static SDValue PerformIntrinsicCombine(SDNode *N, SelectionDAG &DAG) { |
| 5376 | unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue(); |
| 5377 | switch (IntNo) { |
| 5378 | default: |
| 5379 | // Don't do anything for most intrinsics. |
| 5380 | break; |
| 5381 | |
| 5382 | // Vector shifts: check for immediate versions and lower them. |
| 5383 | // Note: This is done during DAG combining instead of DAG legalizing because |
| 5384 | // the build_vectors for 64-bit vector element shift counts are generally |
| 5385 | // not legal, and it is hard to see their values after they get legalized to |
| 5386 | // loads from a constant pool. |
| 5387 | case Intrinsic::arm_neon_vshifts: |
| 5388 | case Intrinsic::arm_neon_vshiftu: |
| 5389 | case Intrinsic::arm_neon_vshiftls: |
| 5390 | case Intrinsic::arm_neon_vshiftlu: |
| 5391 | case Intrinsic::arm_neon_vshiftn: |
| 5392 | case Intrinsic::arm_neon_vrshifts: |
| 5393 | case Intrinsic::arm_neon_vrshiftu: |
| 5394 | case Intrinsic::arm_neon_vrshiftn: |
| 5395 | case Intrinsic::arm_neon_vqshifts: |
| 5396 | case Intrinsic::arm_neon_vqshiftu: |
| 5397 | case Intrinsic::arm_neon_vqshiftsu: |
| 5398 | case Intrinsic::arm_neon_vqshiftns: |
| 5399 | case Intrinsic::arm_neon_vqshiftnu: |
| 5400 | case Intrinsic::arm_neon_vqshiftnsu: |
| 5401 | case Intrinsic::arm_neon_vqrshiftns: |
| 5402 | case Intrinsic::arm_neon_vqrshiftnu: |
| 5403 | case Intrinsic::arm_neon_vqrshiftnsu: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 5404 | EVT VT = N->getOperand(1).getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5405 | int64_t Cnt; |
| 5406 | unsigned VShiftOpc = 0; |
| 5407 | |
| 5408 | switch (IntNo) { |
| 5409 | case Intrinsic::arm_neon_vshifts: |
| 5410 | case Intrinsic::arm_neon_vshiftu: |
| 5411 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) { |
| 5412 | VShiftOpc = ARMISD::VSHL; |
| 5413 | break; |
| 5414 | } |
| 5415 | if (isVShiftRImm(N->getOperand(2), VT, false, true, Cnt)) { |
| 5416 | VShiftOpc = (IntNo == Intrinsic::arm_neon_vshifts ? |
| 5417 | ARMISD::VSHRs : ARMISD::VSHRu); |
| 5418 | break; |
| 5419 | } |
| 5420 | return SDValue(); |
| 5421 | |
| 5422 | case Intrinsic::arm_neon_vshiftls: |
| 5423 | case Intrinsic::arm_neon_vshiftlu: |
| 5424 | if (isVShiftLImm(N->getOperand(2), VT, true, Cnt)) |
| 5425 | break; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 5426 | llvm_unreachable("invalid shift count for vshll intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5427 | |
| 5428 | case Intrinsic::arm_neon_vrshifts: |
| 5429 | case Intrinsic::arm_neon_vrshiftu: |
| 5430 | if (isVShiftRImm(N->getOperand(2), VT, false, true, Cnt)) |
| 5431 | break; |
| 5432 | return SDValue(); |
| 5433 | |
| 5434 | case Intrinsic::arm_neon_vqshifts: |
| 5435 | case Intrinsic::arm_neon_vqshiftu: |
| 5436 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) |
| 5437 | break; |
| 5438 | return SDValue(); |
| 5439 | |
| 5440 | case Intrinsic::arm_neon_vqshiftsu: |
| 5441 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) |
| 5442 | break; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 5443 | llvm_unreachable("invalid shift count for vqshlu intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5444 | |
| 5445 | case Intrinsic::arm_neon_vshiftn: |
| 5446 | case Intrinsic::arm_neon_vrshiftn: |
| 5447 | case Intrinsic::arm_neon_vqshiftns: |
| 5448 | case Intrinsic::arm_neon_vqshiftnu: |
| 5449 | case Intrinsic::arm_neon_vqshiftnsu: |
| 5450 | case Intrinsic::arm_neon_vqrshiftns: |
| 5451 | case Intrinsic::arm_neon_vqrshiftnu: |
| 5452 | case Intrinsic::arm_neon_vqrshiftnsu: |
| 5453 | // Narrowing shifts require an immediate right shift. |
| 5454 | if (isVShiftRImm(N->getOperand(2), VT, true, true, Cnt)) |
| 5455 | break; |
Jim Grosbach | 18f30e6 | 2010-06-02 21:53:11 +0000 | [diff] [blame] | 5456 | llvm_unreachable("invalid shift count for narrowing vector shift " |
| 5457 | "intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5458 | |
| 5459 | default: |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 5460 | llvm_unreachable("unhandled vector shift"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5461 | } |
| 5462 | |
| 5463 | switch (IntNo) { |
| 5464 | case Intrinsic::arm_neon_vshifts: |
| 5465 | case Intrinsic::arm_neon_vshiftu: |
| 5466 | // Opcode already set above. |
| 5467 | break; |
| 5468 | case Intrinsic::arm_neon_vshiftls: |
| 5469 | case Intrinsic::arm_neon_vshiftlu: |
| 5470 | if (Cnt == VT.getVectorElementType().getSizeInBits()) |
| 5471 | VShiftOpc = ARMISD::VSHLLi; |
| 5472 | else |
| 5473 | VShiftOpc = (IntNo == Intrinsic::arm_neon_vshiftls ? |
| 5474 | ARMISD::VSHLLs : ARMISD::VSHLLu); |
| 5475 | break; |
| 5476 | case Intrinsic::arm_neon_vshiftn: |
| 5477 | VShiftOpc = ARMISD::VSHRN; break; |
| 5478 | case Intrinsic::arm_neon_vrshifts: |
| 5479 | VShiftOpc = ARMISD::VRSHRs; break; |
| 5480 | case Intrinsic::arm_neon_vrshiftu: |
| 5481 | VShiftOpc = ARMISD::VRSHRu; break; |
| 5482 | case Intrinsic::arm_neon_vrshiftn: |
| 5483 | VShiftOpc = ARMISD::VRSHRN; break; |
| 5484 | case Intrinsic::arm_neon_vqshifts: |
| 5485 | VShiftOpc = ARMISD::VQSHLs; break; |
| 5486 | case Intrinsic::arm_neon_vqshiftu: |
| 5487 | VShiftOpc = ARMISD::VQSHLu; break; |
| 5488 | case Intrinsic::arm_neon_vqshiftsu: |
| 5489 | VShiftOpc = ARMISD::VQSHLsu; break; |
| 5490 | case Intrinsic::arm_neon_vqshiftns: |
| 5491 | VShiftOpc = ARMISD::VQSHRNs; break; |
| 5492 | case Intrinsic::arm_neon_vqshiftnu: |
| 5493 | VShiftOpc = ARMISD::VQSHRNu; break; |
| 5494 | case Intrinsic::arm_neon_vqshiftnsu: |
| 5495 | VShiftOpc = ARMISD::VQSHRNsu; break; |
| 5496 | case Intrinsic::arm_neon_vqrshiftns: |
| 5497 | VShiftOpc = ARMISD::VQRSHRNs; break; |
| 5498 | case Intrinsic::arm_neon_vqrshiftnu: |
| 5499 | VShiftOpc = ARMISD::VQRSHRNu; break; |
| 5500 | case Intrinsic::arm_neon_vqrshiftnsu: |
| 5501 | VShiftOpc = ARMISD::VQRSHRNsu; break; |
| 5502 | } |
| 5503 | |
| 5504 | return DAG.getNode(VShiftOpc, N->getDebugLoc(), N->getValueType(0), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 5505 | N->getOperand(1), DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5506 | } |
| 5507 | |
| 5508 | case Intrinsic::arm_neon_vshiftins: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 5509 | EVT VT = N->getOperand(1).getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5510 | int64_t Cnt; |
| 5511 | unsigned VShiftOpc = 0; |
| 5512 | |
| 5513 | if (isVShiftLImm(N->getOperand(3), VT, false, Cnt)) |
| 5514 | VShiftOpc = ARMISD::VSLI; |
| 5515 | else if (isVShiftRImm(N->getOperand(3), VT, false, true, Cnt)) |
| 5516 | VShiftOpc = ARMISD::VSRI; |
| 5517 | else { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 5518 | llvm_unreachable("invalid shift count for vsli/vsri intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5519 | } |
| 5520 | |
| 5521 | return DAG.getNode(VShiftOpc, N->getDebugLoc(), N->getValueType(0), |
| 5522 | N->getOperand(1), N->getOperand(2), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 5523 | DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5524 | } |
| 5525 | |
| 5526 | case Intrinsic::arm_neon_vqrshifts: |
| 5527 | case Intrinsic::arm_neon_vqrshiftu: |
| 5528 | // No immediate versions of these to check for. |
| 5529 | break; |
| 5530 | } |
| 5531 | |
| 5532 | return SDValue(); |
| 5533 | } |
| 5534 | |
| 5535 | /// PerformShiftCombine - Checks for immediate versions of vector shifts and |
| 5536 | /// lowers them. As with the vector shift intrinsics, this is done during DAG |
| 5537 | /// combining instead of DAG legalizing because the build_vectors for 64-bit |
| 5538 | /// vector element shift counts are generally not legal, and it is hard to see |
| 5539 | /// their values after they get legalized to loads from a constant pool. |
| 5540 | static SDValue PerformShiftCombine(SDNode *N, SelectionDAG &DAG, |
| 5541 | const ARMSubtarget *ST) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 5542 | EVT VT = N->getValueType(0); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5543 | |
| 5544 | // Nothing to be done for scalar shifts. |
Tanya Lattner | 9684a7c | 2010-11-18 22:06:46 +0000 | [diff] [blame] | 5545 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 5546 | if (!VT.isVector() || !TLI.isTypeLegal(VT)) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5547 | return SDValue(); |
| 5548 | |
| 5549 | assert(ST->hasNEON() && "unexpected vector shift"); |
| 5550 | int64_t Cnt; |
| 5551 | |
| 5552 | switch (N->getOpcode()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 5553 | default: llvm_unreachable("unexpected shift opcode"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5554 | |
| 5555 | case ISD::SHL: |
| 5556 | if (isVShiftLImm(N->getOperand(1), VT, false, Cnt)) |
| 5557 | return DAG.getNode(ARMISD::VSHL, N->getDebugLoc(), VT, N->getOperand(0), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 5558 | DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5559 | break; |
| 5560 | |
| 5561 | case ISD::SRA: |
| 5562 | case ISD::SRL: |
| 5563 | if (isVShiftRImm(N->getOperand(1), VT, false, false, Cnt)) { |
| 5564 | unsigned VShiftOpc = (N->getOpcode() == ISD::SRA ? |
| 5565 | ARMISD::VSHRs : ARMISD::VSHRu); |
| 5566 | return DAG.getNode(VShiftOpc, N->getDebugLoc(), VT, N->getOperand(0), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 5567 | DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5568 | } |
| 5569 | } |
| 5570 | return SDValue(); |
| 5571 | } |
| 5572 | |
| 5573 | /// PerformExtendCombine - Target-specific DAG combining for ISD::SIGN_EXTEND, |
| 5574 | /// ISD::ZERO_EXTEND, and ISD::ANY_EXTEND. |
| 5575 | static SDValue PerformExtendCombine(SDNode *N, SelectionDAG &DAG, |
| 5576 | const ARMSubtarget *ST) { |
| 5577 | SDValue N0 = N->getOperand(0); |
| 5578 | |
| 5579 | // Check for sign- and zero-extensions of vector extract operations of 8- |
| 5580 | // and 16-bit vector elements. NEON supports these directly. They are |
| 5581 | // handled during DAG combining because type legalization will promote them |
| 5582 | // to 32-bit types and it is messy to recognize the operations after that. |
| 5583 | if (ST->hasNEON() && N0.getOpcode() == ISD::EXTRACT_VECTOR_ELT) { |
| 5584 | SDValue Vec = N0.getOperand(0); |
| 5585 | SDValue Lane = N0.getOperand(1); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 5586 | EVT VT = N->getValueType(0); |
| 5587 | EVT EltVT = N0.getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5588 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 5589 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 5590 | if (VT == MVT::i32 && |
| 5591 | (EltVT == MVT::i8 || EltVT == MVT::i16) && |
Bob Wilson | 3468c2e | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 5592 | TLI.isTypeLegal(Vec.getValueType()) && |
| 5593 | isa<ConstantSDNode>(Lane)) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5594 | |
| 5595 | unsigned Opc = 0; |
| 5596 | switch (N->getOpcode()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 5597 | default: llvm_unreachable("unexpected opcode"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5598 | case ISD::SIGN_EXTEND: |
| 5599 | Opc = ARMISD::VGETLANEs; |
| 5600 | break; |
| 5601 | case ISD::ZERO_EXTEND: |
| 5602 | case ISD::ANY_EXTEND: |
| 5603 | Opc = ARMISD::VGETLANEu; |
| 5604 | break; |
| 5605 | } |
| 5606 | return DAG.getNode(Opc, N->getDebugLoc(), VT, Vec, Lane); |
| 5607 | } |
| 5608 | } |
| 5609 | |
| 5610 | return SDValue(); |
| 5611 | } |
| 5612 | |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 5613 | /// PerformSELECT_CCCombine - Target-specific DAG combining for ISD::SELECT_CC |
| 5614 | /// to match f32 max/min patterns to use NEON vmax/vmin instructions. |
| 5615 | static SDValue PerformSELECT_CCCombine(SDNode *N, SelectionDAG &DAG, |
| 5616 | const ARMSubtarget *ST) { |
| 5617 | // 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] | 5618 | // selects like "x < y ? x : y". Unless the NoNaNsFPMath option is set, |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 5619 | // be careful about NaNs: NEON's vmax/vmin return NaN if either operand is |
| 5620 | // a NaN; only do the transformation when it matches that behavior. |
| 5621 | |
| 5622 | // For now only do this when using NEON for FP operations; if using VFP, it |
| 5623 | // is not obvious that the benefit outweighs the cost of switching to the |
| 5624 | // NEON pipeline. |
| 5625 | if (!ST->hasNEON() || !ST->useNEONForSinglePrecisionFP() || |
| 5626 | N->getValueType(0) != MVT::f32) |
| 5627 | return SDValue(); |
| 5628 | |
| 5629 | SDValue CondLHS = N->getOperand(0); |
| 5630 | SDValue CondRHS = N->getOperand(1); |
| 5631 | SDValue LHS = N->getOperand(2); |
| 5632 | SDValue RHS = N->getOperand(3); |
| 5633 | ISD::CondCode CC = cast<CondCodeSDNode>(N->getOperand(4))->get(); |
| 5634 | |
| 5635 | unsigned Opcode = 0; |
| 5636 | bool IsReversed; |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 5637 | if (DAG.isEqualTo(LHS, CondLHS) && DAG.isEqualTo(RHS, CondRHS)) { |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 5638 | IsReversed = false; // x CC y ? x : y |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 5639 | } else if (DAG.isEqualTo(LHS, CondRHS) && DAG.isEqualTo(RHS, CondLHS)) { |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 5640 | IsReversed = true ; // x CC y ? y : x |
| 5641 | } else { |
| 5642 | return SDValue(); |
| 5643 | } |
| 5644 | |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 5645 | bool IsUnordered; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 5646 | switch (CC) { |
| 5647 | default: break; |
| 5648 | case ISD::SETOLT: |
| 5649 | case ISD::SETOLE: |
| 5650 | case ISD::SETLT: |
| 5651 | case ISD::SETLE: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 5652 | case ISD::SETULT: |
| 5653 | case ISD::SETULE: |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 5654 | // If LHS is NaN, an ordered comparison will be false and the result will |
| 5655 | // be the RHS, but vmin(NaN, RHS) = NaN. Avoid this by checking that LHS |
| 5656 | // != NaN. Likewise, for unordered comparisons, check for RHS != NaN. |
| 5657 | IsUnordered = (CC == ISD::SETULT || CC == ISD::SETULE); |
| 5658 | if (!DAG.isKnownNeverNaN(IsUnordered ? RHS : LHS)) |
| 5659 | break; |
| 5660 | // For less-than-or-equal comparisons, "+0 <= -0" will be true but vmin |
| 5661 | // will return -0, so vmin can only be used for unsafe math or if one of |
| 5662 | // the operands is known to be nonzero. |
| 5663 | if ((CC == ISD::SETLE || CC == ISD::SETOLE || CC == ISD::SETULE) && |
| 5664 | !UnsafeFPMath && |
| 5665 | !(DAG.isKnownNeverZero(LHS) || DAG.isKnownNeverZero(RHS))) |
| 5666 | break; |
| 5667 | Opcode = IsReversed ? ARMISD::FMAX : ARMISD::FMIN; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 5668 | break; |
| 5669 | |
| 5670 | case ISD::SETOGT: |
| 5671 | case ISD::SETOGE: |
| 5672 | case ISD::SETGT: |
| 5673 | case ISD::SETGE: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 5674 | case ISD::SETUGT: |
| 5675 | case ISD::SETUGE: |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 5676 | // If LHS is NaN, an ordered comparison will be false and the result will |
| 5677 | // be the RHS, but vmax(NaN, RHS) = NaN. Avoid this by checking that LHS |
| 5678 | // != NaN. Likewise, for unordered comparisons, check for RHS != NaN. |
| 5679 | IsUnordered = (CC == ISD::SETUGT || CC == ISD::SETUGE); |
| 5680 | if (!DAG.isKnownNeverNaN(IsUnordered ? RHS : LHS)) |
| 5681 | break; |
| 5682 | // For greater-than-or-equal comparisons, "-0 >= +0" will be true but vmax |
| 5683 | // will return +0, so vmax can only be used for unsafe math or if one of |
| 5684 | // the operands is known to be nonzero. |
| 5685 | if ((CC == ISD::SETGE || CC == ISD::SETOGE || CC == ISD::SETUGE) && |
| 5686 | !UnsafeFPMath && |
| 5687 | !(DAG.isKnownNeverZero(LHS) || DAG.isKnownNeverZero(RHS))) |
| 5688 | break; |
| 5689 | Opcode = IsReversed ? ARMISD::FMIN : ARMISD::FMAX; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 5690 | break; |
| 5691 | } |
| 5692 | |
| 5693 | if (!Opcode) |
| 5694 | return SDValue(); |
| 5695 | return DAG.getNode(Opcode, N->getDebugLoc(), N->getValueType(0), LHS, RHS); |
| 5696 | } |
| 5697 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5698 | SDValue ARMTargetLowering::PerformDAGCombine(SDNode *N, |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 5699 | DAGCombinerInfo &DCI) const { |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 5700 | switch (N->getOpcode()) { |
| 5701 | default: break; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 5702 | case ISD::ADD: return PerformADDCombine(N, DCI); |
| 5703 | case ISD::SUB: return PerformSUBCombine(N, DCI); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 5704 | case ISD::MUL: return PerformMULCombine(N, DCI, Subtarget); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 5705 | case ISD::OR: return PerformORCombine(N, DCI, Subtarget); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 5706 | case ISD::AND: return PerformANDCombine(N, DCI); |
Evan Cheng | 0c1aec1 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 5707 | case ARMISD::BFI: return PerformBFICombine(N, DCI); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 5708 | case ARMISD::VMOVRRD: return PerformVMOVRRDCombine(N, DCI); |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 5709 | case ARMISD::VMOVDRR: return PerformVMOVDRRCombine(N, DCI.DAG); |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 5710 | case ISD::STORE: return PerformSTORECombine(N, DCI); |
| 5711 | case ISD::BUILD_VECTOR: return PerformBUILD_VECTORCombine(N, DCI); |
| 5712 | case ISD::INSERT_VECTOR_ELT: return PerformInsertEltCombine(N, DCI); |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 5713 | case ISD::VECTOR_SHUFFLE: return PerformVECTOR_SHUFFLECombine(N, DCI.DAG); |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 5714 | case ARMISD::VDUPLANE: return PerformVDUPLANECombine(N, DCI); |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 5715 | case ISD::INTRINSIC_WO_CHAIN: return PerformIntrinsicCombine(N, DCI.DAG); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5716 | case ISD::SHL: |
| 5717 | case ISD::SRA: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 5718 | case ISD::SRL: return PerformShiftCombine(N, DCI.DAG, Subtarget); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5719 | case ISD::SIGN_EXTEND: |
| 5720 | case ISD::ZERO_EXTEND: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 5721 | case ISD::ANY_EXTEND: return PerformExtendCombine(N, DCI.DAG, Subtarget); |
| 5722 | case ISD::SELECT_CC: return PerformSELECT_CCCombine(N, DCI.DAG, Subtarget); |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 5723 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5724 | return SDValue(); |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 5725 | } |
| 5726 | |
Bill Wendling | af56634 | 2009-08-15 21:21:19 +0000 | [diff] [blame] | 5727 | bool ARMTargetLowering::allowsUnalignedMemoryAccesses(EVT VT) const { |
Bob Wilson | 02aba73 | 2010-09-28 04:09:35 +0000 | [diff] [blame] | 5728 | if (!Subtarget->allowsUnalignedMem()) |
Bob Wilson | 86fe66d | 2010-06-25 04:12:31 +0000 | [diff] [blame] | 5729 | return false; |
Bill Wendling | af56634 | 2009-08-15 21:21:19 +0000 | [diff] [blame] | 5730 | |
| 5731 | switch (VT.getSimpleVT().SimpleTy) { |
| 5732 | default: |
| 5733 | return false; |
| 5734 | case MVT::i8: |
| 5735 | case MVT::i16: |
| 5736 | case MVT::i32: |
| 5737 | return true; |
| 5738 | // FIXME: VLD1 etc with standard alignment is legal. |
| 5739 | } |
| 5740 | } |
| 5741 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 5742 | static bool isLegalT1AddressImmediate(int64_t V, EVT VT) { |
| 5743 | if (V < 0) |
| 5744 | return false; |
| 5745 | |
| 5746 | unsigned Scale = 1; |
| 5747 | switch (VT.getSimpleVT().SimpleTy) { |
| 5748 | default: return false; |
| 5749 | case MVT::i1: |
| 5750 | case MVT::i8: |
| 5751 | // Scale == 1; |
| 5752 | break; |
| 5753 | case MVT::i16: |
| 5754 | // Scale == 2; |
| 5755 | Scale = 2; |
| 5756 | break; |
| 5757 | case MVT::i32: |
| 5758 | // Scale == 4; |
| 5759 | Scale = 4; |
| 5760 | break; |
| 5761 | } |
| 5762 | |
| 5763 | if ((V & (Scale - 1)) != 0) |
| 5764 | return false; |
| 5765 | V /= Scale; |
| 5766 | return V == (V & ((1LL << 5) - 1)); |
| 5767 | } |
| 5768 | |
| 5769 | static bool isLegalT2AddressImmediate(int64_t V, EVT VT, |
| 5770 | const ARMSubtarget *Subtarget) { |
| 5771 | bool isNeg = false; |
| 5772 | if (V < 0) { |
| 5773 | isNeg = true; |
| 5774 | V = - V; |
| 5775 | } |
| 5776 | |
| 5777 | switch (VT.getSimpleVT().SimpleTy) { |
| 5778 | default: return false; |
| 5779 | case MVT::i1: |
| 5780 | case MVT::i8: |
| 5781 | case MVT::i16: |
| 5782 | case MVT::i32: |
| 5783 | // + imm12 or - imm8 |
| 5784 | if (isNeg) |
| 5785 | return V == (V & ((1LL << 8) - 1)); |
| 5786 | return V == (V & ((1LL << 12) - 1)); |
| 5787 | case MVT::f32: |
| 5788 | case MVT::f64: |
| 5789 | // Same as ARM mode. FIXME: NEON? |
| 5790 | if (!Subtarget->hasVFP2()) |
| 5791 | return false; |
| 5792 | if ((V & 3) != 0) |
| 5793 | return false; |
| 5794 | V >>= 2; |
| 5795 | return V == (V & ((1LL << 8) - 1)); |
| 5796 | } |
| 5797 | } |
| 5798 | |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 5799 | /// isLegalAddressImmediate - Return true if the integer value can be used |
| 5800 | /// as the offset of the target addressing mode for load / store of the |
| 5801 | /// given type. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 5802 | static bool isLegalAddressImmediate(int64_t V, EVT VT, |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 5803 | const ARMSubtarget *Subtarget) { |
Evan Cheng | 961f879 | 2007-03-13 20:37:59 +0000 | [diff] [blame] | 5804 | if (V == 0) |
| 5805 | return true; |
| 5806 | |
Evan Cheng | 6501153 | 2009-03-09 19:15:00 +0000 | [diff] [blame] | 5807 | if (!VT.isSimple()) |
| 5808 | return false; |
| 5809 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 5810 | if (Subtarget->isThumb1Only()) |
| 5811 | return isLegalT1AddressImmediate(V, VT); |
| 5812 | else if (Subtarget->isThumb2()) |
| 5813 | return isLegalT2AddressImmediate(V, VT, Subtarget); |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 5814 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 5815 | // ARM mode. |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 5816 | if (V < 0) |
| 5817 | V = - V; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 5818 | switch (VT.getSimpleVT().SimpleTy) { |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 5819 | default: return false; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 5820 | case MVT::i1: |
| 5821 | case MVT::i8: |
| 5822 | case MVT::i32: |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 5823 | // +- imm12 |
Anton Korobeynikov | 7c1c261 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 5824 | return V == (V & ((1LL << 12) - 1)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 5825 | case MVT::i16: |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 5826 | // +- imm8 |
Anton Korobeynikov | 7c1c261 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 5827 | return V == (V & ((1LL << 8) - 1)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 5828 | case MVT::f32: |
| 5829 | case MVT::f64: |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 5830 | if (!Subtarget->hasVFP2()) // FIXME: NEON? |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 5831 | return false; |
Evan Cheng | 0b0a9a9 | 2007-05-03 02:00:18 +0000 | [diff] [blame] | 5832 | if ((V & 3) != 0) |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 5833 | return false; |
| 5834 | V >>= 2; |
Anton Korobeynikov | 7c1c261 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 5835 | return V == (V & ((1LL << 8) - 1)); |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 5836 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5837 | } |
| 5838 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 5839 | bool ARMTargetLowering::isLegalT2ScaledAddressingMode(const AddrMode &AM, |
| 5840 | EVT VT) const { |
| 5841 | int Scale = AM.Scale; |
| 5842 | if (Scale < 0) |
| 5843 | return false; |
| 5844 | |
| 5845 | switch (VT.getSimpleVT().SimpleTy) { |
| 5846 | default: return false; |
| 5847 | case MVT::i1: |
| 5848 | case MVT::i8: |
| 5849 | case MVT::i16: |
| 5850 | case MVT::i32: |
| 5851 | if (Scale == 1) |
| 5852 | return true; |
| 5853 | // r + r << imm |
| 5854 | Scale = Scale & ~1; |
| 5855 | return Scale == 2 || Scale == 4 || Scale == 8; |
| 5856 | case MVT::i64: |
| 5857 | // r + r |
| 5858 | if (((unsigned)AM.HasBaseReg + Scale) <= 2) |
| 5859 | return true; |
| 5860 | return false; |
| 5861 | case MVT::isVoid: |
| 5862 | // Note, we allow "void" uses (basically, uses that aren't loads or |
| 5863 | // stores), because arm allows folding a scale into many arithmetic |
| 5864 | // operations. This should be made more precise and revisited later. |
| 5865 | |
| 5866 | // Allow r << imm, but the imm has to be a multiple of two. |
| 5867 | if (Scale & 1) return false; |
| 5868 | return isPowerOf2_32(Scale); |
| 5869 | } |
| 5870 | } |
| 5871 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 5872 | /// isLegalAddressingMode - Return true if the addressing mode represented |
| 5873 | /// 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] | 5874 | bool ARMTargetLowering::isLegalAddressingMode(const AddrMode &AM, |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 5875 | const Type *Ty) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 5876 | EVT VT = getValueType(Ty, true); |
Bob Wilson | 2c7dab1 | 2009-04-08 17:55:28 +0000 | [diff] [blame] | 5877 | if (!isLegalAddressImmediate(AM.BaseOffs, VT, Subtarget)) |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 5878 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 5879 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 5880 | // Can never fold addr of global into load/store. |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 5881 | if (AM.BaseGV) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 5882 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 5883 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 5884 | switch (AM.Scale) { |
| 5885 | case 0: // no scale reg, must be "r+i" or "r", or "i". |
| 5886 | break; |
| 5887 | case 1: |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 5888 | if (Subtarget->isThumb1Only()) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 5889 | return false; |
Chris Lattner | 5a3d40d | 2007-04-13 06:50:55 +0000 | [diff] [blame] | 5890 | // FALL THROUGH. |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 5891 | default: |
Chris Lattner | 5a3d40d | 2007-04-13 06:50:55 +0000 | [diff] [blame] | 5892 | // ARM doesn't support any R+R*scale+imm addr modes. |
| 5893 | if (AM.BaseOffs) |
| 5894 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 5895 | |
Bob Wilson | 2c7dab1 | 2009-04-08 17:55:28 +0000 | [diff] [blame] | 5896 | if (!VT.isSimple()) |
| 5897 | return false; |
| 5898 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 5899 | if (Subtarget->isThumb2()) |
| 5900 | return isLegalT2ScaledAddressingMode(AM, VT); |
| 5901 | |
Chris Lattner | eb13d1b | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 5902 | int Scale = AM.Scale; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 5903 | switch (VT.getSimpleVT().SimpleTy) { |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 5904 | default: return false; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 5905 | case MVT::i1: |
| 5906 | case MVT::i8: |
| 5907 | case MVT::i32: |
Chris Lattner | eb13d1b | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 5908 | if (Scale < 0) Scale = -Scale; |
| 5909 | if (Scale == 1) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 5910 | return true; |
| 5911 | // r + r << imm |
Chris Lattner | e115294 | 2007-04-11 16:17:12 +0000 | [diff] [blame] | 5912 | return isPowerOf2_32(Scale & ~1); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 5913 | case MVT::i16: |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 5914 | case MVT::i64: |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 5915 | // r + r |
Chris Lattner | eb13d1b | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 5916 | if (((unsigned)AM.HasBaseReg + Scale) <= 2) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 5917 | return true; |
Chris Lattner | e115294 | 2007-04-11 16:17:12 +0000 | [diff] [blame] | 5918 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 5919 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 5920 | case MVT::isVoid: |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 5921 | // Note, we allow "void" uses (basically, uses that aren't loads or |
| 5922 | // stores), because arm allows folding a scale into many arithmetic |
| 5923 | // operations. This should be made more precise and revisited later. |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 5924 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 5925 | // 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] | 5926 | if (Scale & 1) return false; |
| 5927 | return isPowerOf2_32(Scale); |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 5928 | } |
| 5929 | break; |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 5930 | } |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 5931 | return true; |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 5932 | } |
| 5933 | |
Evan Cheng | 77e4751 | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 5934 | /// isLegalICmpImmediate - Return true if the specified immediate is legal |
| 5935 | /// icmp immediate, that is the target has icmp instructions which can compare |
| 5936 | /// a register against the immediate without having to materialize the |
| 5937 | /// immediate into a register. |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 5938 | bool ARMTargetLowering::isLegalICmpImmediate(int64_t Imm) const { |
Evan Cheng | 77e4751 | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 5939 | if (!Subtarget->isThumb()) |
| 5940 | return ARM_AM::getSOImmVal(Imm) != -1; |
| 5941 | if (Subtarget->isThumb2()) |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 5942 | return ARM_AM::getT2SOImmVal(Imm) != -1; |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 5943 | return Imm >= 0 && Imm <= 255; |
Evan Cheng | 77e4751 | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 5944 | } |
| 5945 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 5946 | static bool getARMIndexedAddressParts(SDNode *Ptr, EVT VT, |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 5947 | bool isSEXTLoad, SDValue &Base, |
| 5948 | SDValue &Offset, bool &isInc, |
| 5949 | SelectionDAG &DAG) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5950 | if (Ptr->getOpcode() != ISD::ADD && Ptr->getOpcode() != ISD::SUB) |
| 5951 | return false; |
| 5952 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 5953 | if (VT == MVT::i16 || ((VT == MVT::i8 || VT == MVT::i1) && isSEXTLoad)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5954 | // AddressingMode 3 |
| 5955 | Base = Ptr->getOperand(0); |
| 5956 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 5957 | int RHSC = (int)RHS->getZExtValue(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5958 | if (RHSC < 0 && RHSC > -256) { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 5959 | assert(Ptr->getOpcode() == ISD::ADD); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5960 | isInc = false; |
| 5961 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); |
| 5962 | return true; |
| 5963 | } |
| 5964 | } |
| 5965 | isInc = (Ptr->getOpcode() == ISD::ADD); |
| 5966 | Offset = Ptr->getOperand(1); |
| 5967 | return true; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 5968 | } else if (VT == MVT::i32 || VT == MVT::i8 || VT == MVT::i1) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5969 | // AddressingMode 2 |
| 5970 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 5971 | int RHSC = (int)RHS->getZExtValue(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5972 | if (RHSC < 0 && RHSC > -0x1000) { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 5973 | assert(Ptr->getOpcode() == ISD::ADD); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5974 | isInc = false; |
| 5975 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); |
| 5976 | Base = Ptr->getOperand(0); |
| 5977 | return true; |
| 5978 | } |
| 5979 | } |
| 5980 | |
| 5981 | if (Ptr->getOpcode() == ISD::ADD) { |
| 5982 | isInc = true; |
| 5983 | ARM_AM::ShiftOpc ShOpcVal= ARM_AM::getShiftOpcForNode(Ptr->getOperand(0)); |
| 5984 | if (ShOpcVal != ARM_AM::no_shift) { |
| 5985 | Base = Ptr->getOperand(1); |
| 5986 | Offset = Ptr->getOperand(0); |
| 5987 | } else { |
| 5988 | Base = Ptr->getOperand(0); |
| 5989 | Offset = Ptr->getOperand(1); |
| 5990 | } |
| 5991 | return true; |
| 5992 | } |
| 5993 | |
| 5994 | isInc = (Ptr->getOpcode() == ISD::ADD); |
| 5995 | Base = Ptr->getOperand(0); |
| 5996 | Offset = Ptr->getOperand(1); |
| 5997 | return true; |
| 5998 | } |
| 5999 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 6000 | // FIXME: Use VLDM / VSTM to emulate indexed FP load / store. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6001 | return false; |
| 6002 | } |
| 6003 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6004 | static bool getT2IndexedAddressParts(SDNode *Ptr, EVT VT, |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 6005 | bool isSEXTLoad, SDValue &Base, |
| 6006 | SDValue &Offset, bool &isInc, |
| 6007 | SelectionDAG &DAG) { |
| 6008 | if (Ptr->getOpcode() != ISD::ADD && Ptr->getOpcode() != ISD::SUB) |
| 6009 | return false; |
| 6010 | |
| 6011 | Base = Ptr->getOperand(0); |
| 6012 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
| 6013 | int RHSC = (int)RHS->getZExtValue(); |
| 6014 | if (RHSC < 0 && RHSC > -0x100) { // 8 bits. |
| 6015 | assert(Ptr->getOpcode() == ISD::ADD); |
| 6016 | isInc = false; |
| 6017 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); |
| 6018 | return true; |
| 6019 | } else if (RHSC > 0 && RHSC < 0x100) { // 8 bit, no zero. |
| 6020 | isInc = Ptr->getOpcode() == ISD::ADD; |
| 6021 | Offset = DAG.getConstant(RHSC, RHS->getValueType(0)); |
| 6022 | return true; |
| 6023 | } |
| 6024 | } |
| 6025 | |
| 6026 | return false; |
| 6027 | } |
| 6028 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6029 | /// getPreIndexedAddressParts - returns true by value, base pointer and |
| 6030 | /// offset pointer and addressing mode by reference if the node's address |
| 6031 | /// can be legally represented as pre-indexed load / store address. |
| 6032 | bool |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6033 | ARMTargetLowering::getPreIndexedAddressParts(SDNode *N, SDValue &Base, |
| 6034 | SDValue &Offset, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6035 | ISD::MemIndexedMode &AM, |
Dan Gohman | 73e0914 | 2009-01-15 16:29:45 +0000 | [diff] [blame] | 6036 | SelectionDAG &DAG) const { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 6037 | if (Subtarget->isThumb1Only()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6038 | return false; |
| 6039 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6040 | EVT VT; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6041 | SDValue Ptr; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6042 | bool isSEXTLoad = false; |
| 6043 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) { |
| 6044 | Ptr = LD->getBasePtr(); |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 6045 | VT = LD->getMemoryVT(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6046 | isSEXTLoad = LD->getExtensionType() == ISD::SEXTLOAD; |
| 6047 | } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) { |
| 6048 | Ptr = ST->getBasePtr(); |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 6049 | VT = ST->getMemoryVT(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6050 | } else |
| 6051 | return false; |
| 6052 | |
| 6053 | bool isInc; |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 6054 | bool isLegal = false; |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 6055 | if (Subtarget->isThumb2()) |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 6056 | isLegal = getT2IndexedAddressParts(Ptr.getNode(), VT, isSEXTLoad, Base, |
| 6057 | Offset, isInc, DAG); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 6058 | else |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 6059 | isLegal = getARMIndexedAddressParts(Ptr.getNode(), VT, isSEXTLoad, Base, |
Evan Cheng | 0412957 | 2009-07-02 06:44:30 +0000 | [diff] [blame] | 6060 | Offset, isInc, DAG); |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 6061 | if (!isLegal) |
| 6062 | return false; |
| 6063 | |
| 6064 | AM = isInc ? ISD::PRE_INC : ISD::PRE_DEC; |
| 6065 | return true; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6066 | } |
| 6067 | |
| 6068 | /// getPostIndexedAddressParts - returns true by value, base pointer and |
| 6069 | /// offset pointer and addressing mode by reference if this node can be |
| 6070 | /// combined with a load / store to form a post-indexed load / store. |
| 6071 | bool ARMTargetLowering::getPostIndexedAddressParts(SDNode *N, SDNode *Op, |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6072 | SDValue &Base, |
| 6073 | SDValue &Offset, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6074 | ISD::MemIndexedMode &AM, |
Dan Gohman | 73e0914 | 2009-01-15 16:29:45 +0000 | [diff] [blame] | 6075 | SelectionDAG &DAG) const { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 6076 | if (Subtarget->isThumb1Only()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6077 | return false; |
| 6078 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6079 | EVT VT; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6080 | SDValue Ptr; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6081 | bool isSEXTLoad = false; |
| 6082 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) { |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 6083 | VT = LD->getMemoryVT(); |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 6084 | Ptr = LD->getBasePtr(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6085 | isSEXTLoad = LD->getExtensionType() == ISD::SEXTLOAD; |
| 6086 | } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) { |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 6087 | VT = ST->getMemoryVT(); |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 6088 | Ptr = ST->getBasePtr(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6089 | } else |
| 6090 | return false; |
| 6091 | |
| 6092 | bool isInc; |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 6093 | bool isLegal = false; |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 6094 | if (Subtarget->isThumb2()) |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 6095 | isLegal = getT2IndexedAddressParts(Op, VT, isSEXTLoad, Base, Offset, |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 6096 | isInc, DAG); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 6097 | else |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 6098 | isLegal = getARMIndexedAddressParts(Op, VT, isSEXTLoad, Base, Offset, |
| 6099 | isInc, DAG); |
| 6100 | if (!isLegal) |
| 6101 | return false; |
| 6102 | |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 6103 | if (Ptr != Base) { |
| 6104 | // Swap base ptr and offset to catch more post-index load / store when |
| 6105 | // it's legal. In Thumb2 mode, offset must be an immediate. |
| 6106 | if (Ptr == Offset && Op->getOpcode() == ISD::ADD && |
| 6107 | !Subtarget->isThumb2()) |
| 6108 | std::swap(Base, Offset); |
| 6109 | |
| 6110 | // Post-indexed load / store update the base pointer. |
| 6111 | if (Ptr != Base) |
| 6112 | return false; |
| 6113 | } |
| 6114 | |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 6115 | AM = isInc ? ISD::POST_INC : ISD::POST_DEC; |
| 6116 | return true; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6117 | } |
| 6118 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6119 | void ARMTargetLowering::computeMaskedBitsForTargetNode(const SDValue Op, |
Dan Gohman | 977a76f | 2008-02-13 22:28:48 +0000 | [diff] [blame] | 6120 | const APInt &Mask, |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 6121 | APInt &KnownZero, |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 6122 | APInt &KnownOne, |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 6123 | const SelectionDAG &DAG, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6124 | unsigned Depth) const { |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 6125 | KnownZero = KnownOne = APInt(Mask.getBitWidth(), 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6126 | switch (Op.getOpcode()) { |
| 6127 | default: break; |
| 6128 | case ARMISD::CMOV: { |
| 6129 | // Bits are known zero/one if known on the LHS and RHS. |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 6130 | DAG.ComputeMaskedBits(Op.getOperand(0), Mask, KnownZero, KnownOne, Depth+1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6131 | if (KnownZero == 0 && KnownOne == 0) return; |
| 6132 | |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 6133 | APInt KnownZeroRHS, KnownOneRHS; |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 6134 | DAG.ComputeMaskedBits(Op.getOperand(1), Mask, |
| 6135 | KnownZeroRHS, KnownOneRHS, Depth+1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6136 | KnownZero &= KnownZeroRHS; |
| 6137 | KnownOne &= KnownOneRHS; |
| 6138 | return; |
| 6139 | } |
| 6140 | } |
| 6141 | } |
| 6142 | |
| 6143 | //===----------------------------------------------------------------------===// |
| 6144 | // ARM Inline Assembly Support |
| 6145 | //===----------------------------------------------------------------------===// |
| 6146 | |
Evan Cheng | 55d4200 | 2011-01-08 01:24:27 +0000 | [diff] [blame] | 6147 | bool ARMTargetLowering::ExpandInlineAsm(CallInst *CI) const { |
| 6148 | // Looking for "rev" which is V6+. |
| 6149 | if (!Subtarget->hasV6Ops()) |
| 6150 | return false; |
| 6151 | |
| 6152 | InlineAsm *IA = cast<InlineAsm>(CI->getCalledValue()); |
| 6153 | std::string AsmStr = IA->getAsmString(); |
| 6154 | SmallVector<StringRef, 4> AsmPieces; |
| 6155 | SplitString(AsmStr, AsmPieces, ";\n"); |
| 6156 | |
| 6157 | switch (AsmPieces.size()) { |
| 6158 | default: return false; |
| 6159 | case 1: |
| 6160 | AsmStr = AsmPieces[0]; |
| 6161 | AsmPieces.clear(); |
| 6162 | SplitString(AsmStr, AsmPieces, " \t,"); |
| 6163 | |
| 6164 | // rev $0, $1 |
| 6165 | if (AsmPieces.size() == 3 && |
| 6166 | AsmPieces[0] == "rev" && AsmPieces[1] == "$0" && AsmPieces[2] == "$1" && |
| 6167 | IA->getConstraintString().compare(0, 4, "=l,l") == 0) { |
| 6168 | const IntegerType *Ty = dyn_cast<IntegerType>(CI->getType()); |
| 6169 | if (Ty && Ty->getBitWidth() == 32) |
| 6170 | return IntrinsicLowering::LowerToByteSwap(CI); |
| 6171 | } |
| 6172 | break; |
| 6173 | } |
| 6174 | |
| 6175 | return false; |
| 6176 | } |
| 6177 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6178 | /// getConstraintType - Given a constraint letter, return the type of |
| 6179 | /// constraint it is for this target. |
| 6180 | ARMTargetLowering::ConstraintType |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 6181 | ARMTargetLowering::getConstraintType(const std::string &Constraint) const { |
| 6182 | if (Constraint.size() == 1) { |
| 6183 | switch (Constraint[0]) { |
| 6184 | default: break; |
| 6185 | case 'l': return C_RegisterClass; |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 6186 | case 'w': return C_RegisterClass; |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 6187 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6188 | } |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 6189 | return TargetLowering::getConstraintType(Constraint); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6190 | } |
| 6191 | |
John Thompson | 44ab89e | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 6192 | /// Examine constraint type and operand type and determine a weight value. |
| 6193 | /// This object must already have been set up with the operand type |
| 6194 | /// and the current alternative constraint selected. |
| 6195 | TargetLowering::ConstraintWeight |
| 6196 | ARMTargetLowering::getSingleConstraintMatchWeight( |
| 6197 | AsmOperandInfo &info, const char *constraint) const { |
| 6198 | ConstraintWeight weight = CW_Invalid; |
| 6199 | Value *CallOperandVal = info.CallOperandVal; |
| 6200 | // If we don't have a value, we can't do a match, |
| 6201 | // but allow it at the lowest weight. |
| 6202 | if (CallOperandVal == NULL) |
| 6203 | return CW_Default; |
| 6204 | const Type *type = CallOperandVal->getType(); |
| 6205 | // Look at the constraint type. |
| 6206 | switch (*constraint) { |
| 6207 | default: |
| 6208 | weight = TargetLowering::getSingleConstraintMatchWeight(info, constraint); |
| 6209 | break; |
| 6210 | case 'l': |
| 6211 | if (type->isIntegerTy()) { |
| 6212 | if (Subtarget->isThumb()) |
| 6213 | weight = CW_SpecificReg; |
| 6214 | else |
| 6215 | weight = CW_Register; |
| 6216 | } |
| 6217 | break; |
| 6218 | case 'w': |
| 6219 | if (type->isFloatingPointTy()) |
| 6220 | weight = CW_Register; |
| 6221 | break; |
| 6222 | } |
| 6223 | return weight; |
| 6224 | } |
| 6225 | |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 6226 | std::pair<unsigned, const TargetRegisterClass*> |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6227 | ARMTargetLowering::getRegForInlineAsmConstraint(const std::string &Constraint, |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6228 | EVT VT) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6229 | if (Constraint.size() == 1) { |
Jakob Stoklund Olesen | 09bf003 | 2010-01-14 18:19:56 +0000 | [diff] [blame] | 6230 | // GCC ARM Constraint Letters |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6231 | switch (Constraint[0]) { |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 6232 | case 'l': |
Jakob Stoklund Olesen | 09bf003 | 2010-01-14 18:19:56 +0000 | [diff] [blame] | 6233 | if (Subtarget->isThumb()) |
Jim Grosbach | 30eae3c | 2009-04-07 20:34:09 +0000 | [diff] [blame] | 6234 | return std::make_pair(0U, ARM::tGPRRegisterClass); |
| 6235 | else |
| 6236 | return std::make_pair(0U, ARM::GPRRegisterClass); |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 6237 | case 'r': |
| 6238 | return std::make_pair(0U, ARM::GPRRegisterClass); |
| 6239 | case 'w': |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6240 | if (VT == MVT::f32) |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 6241 | return std::make_pair(0U, ARM::SPRRegisterClass); |
Bob Wilson | 5afffae | 2009-12-18 01:03:29 +0000 | [diff] [blame] | 6242 | if (VT.getSizeInBits() == 64) |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 6243 | return std::make_pair(0U, ARM::DPRRegisterClass); |
Evan Cheng | d831cda | 2009-12-08 23:06:22 +0000 | [diff] [blame] | 6244 | if (VT.getSizeInBits() == 128) |
| 6245 | return std::make_pair(0U, ARM::QPRRegisterClass); |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 6246 | break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6247 | } |
| 6248 | } |
Bob Wilson | 33cc5cb | 2010-03-15 23:09:18 +0000 | [diff] [blame] | 6249 | if (StringRef("{cc}").equals_lower(Constraint)) |
Jakob Stoklund Olesen | 0d8ba33 | 2010-06-18 16:49:33 +0000 | [diff] [blame] | 6250 | return std::make_pair(unsigned(ARM::CPSR), ARM::CCRRegisterClass); |
Bob Wilson | 33cc5cb | 2010-03-15 23:09:18 +0000 | [diff] [blame] | 6251 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6252 | return TargetLowering::getRegForInlineAsmConstraint(Constraint, VT); |
| 6253 | } |
| 6254 | |
| 6255 | std::vector<unsigned> ARMTargetLowering:: |
| 6256 | getRegClassForInlineAsmConstraint(const std::string &Constraint, |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6257 | EVT VT) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6258 | if (Constraint.size() != 1) |
| 6259 | return std::vector<unsigned>(); |
| 6260 | |
| 6261 | switch (Constraint[0]) { // GCC ARM Constraint Letters |
| 6262 | default: break; |
| 6263 | case 'l': |
Jim Grosbach | 30eae3c | 2009-04-07 20:34:09 +0000 | [diff] [blame] | 6264 | return make_vector<unsigned>(ARM::R0, ARM::R1, ARM::R2, ARM::R3, |
| 6265 | ARM::R4, ARM::R5, ARM::R6, ARM::R7, |
| 6266 | 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6267 | case 'r': |
| 6268 | return make_vector<unsigned>(ARM::R0, ARM::R1, ARM::R2, ARM::R3, |
| 6269 | ARM::R4, ARM::R5, ARM::R6, ARM::R7, |
| 6270 | ARM::R8, ARM::R9, ARM::R10, ARM::R11, |
| 6271 | ARM::R12, ARM::LR, 0); |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 6272 | case 'w': |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6273 | if (VT == MVT::f32) |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 6274 | return make_vector<unsigned>(ARM::S0, ARM::S1, ARM::S2, ARM::S3, |
| 6275 | ARM::S4, ARM::S5, ARM::S6, ARM::S7, |
| 6276 | ARM::S8, ARM::S9, ARM::S10, ARM::S11, |
| 6277 | ARM::S12,ARM::S13,ARM::S14,ARM::S15, |
| 6278 | ARM::S16,ARM::S17,ARM::S18,ARM::S19, |
| 6279 | ARM::S20,ARM::S21,ARM::S22,ARM::S23, |
| 6280 | ARM::S24,ARM::S25,ARM::S26,ARM::S27, |
| 6281 | ARM::S28,ARM::S29,ARM::S30,ARM::S31, 0); |
Bob Wilson | 5afffae | 2009-12-18 01:03:29 +0000 | [diff] [blame] | 6282 | if (VT.getSizeInBits() == 64) |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 6283 | return make_vector<unsigned>(ARM::D0, ARM::D1, ARM::D2, ARM::D3, |
| 6284 | ARM::D4, ARM::D5, ARM::D6, ARM::D7, |
| 6285 | ARM::D8, ARM::D9, ARM::D10,ARM::D11, |
| 6286 | ARM::D12,ARM::D13,ARM::D14,ARM::D15, 0); |
Evan Cheng | d831cda | 2009-12-08 23:06:22 +0000 | [diff] [blame] | 6287 | if (VT.getSizeInBits() == 128) |
| 6288 | return make_vector<unsigned>(ARM::Q0, ARM::Q1, ARM::Q2, ARM::Q3, |
| 6289 | ARM::Q4, ARM::Q5, ARM::Q6, ARM::Q7, 0); |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 6290 | break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6291 | } |
| 6292 | |
| 6293 | return std::vector<unsigned>(); |
| 6294 | } |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 6295 | |
| 6296 | /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops |
| 6297 | /// vector. If it is invalid, don't add anything to Ops. |
| 6298 | void ARMTargetLowering::LowerAsmOperandForConstraint(SDValue Op, |
| 6299 | char Constraint, |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 6300 | std::vector<SDValue>&Ops, |
| 6301 | SelectionDAG &DAG) const { |
| 6302 | SDValue Result(0, 0); |
| 6303 | |
| 6304 | switch (Constraint) { |
| 6305 | default: break; |
| 6306 | case 'I': case 'J': case 'K': case 'L': |
| 6307 | case 'M': case 'N': case 'O': |
| 6308 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op); |
| 6309 | if (!C) |
| 6310 | return; |
| 6311 | |
| 6312 | int64_t CVal64 = C->getSExtValue(); |
| 6313 | int CVal = (int) CVal64; |
| 6314 | // None of these constraints allow values larger than 32 bits. Check |
| 6315 | // that the value fits in an int. |
| 6316 | if (CVal != CVal64) |
| 6317 | return; |
| 6318 | |
| 6319 | switch (Constraint) { |
| 6320 | case 'I': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 6321 | if (Subtarget->isThumb1Only()) { |
| 6322 | // This must be a constant between 0 and 255, for ADD |
| 6323 | // immediates. |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 6324 | if (CVal >= 0 && CVal <= 255) |
| 6325 | break; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 6326 | } else if (Subtarget->isThumb2()) { |
| 6327 | // A constant that can be used as an immediate value in a |
| 6328 | // data-processing instruction. |
| 6329 | if (ARM_AM::getT2SOImmVal(CVal) != -1) |
| 6330 | break; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 6331 | } else { |
| 6332 | // A constant that can be used as an immediate value in a |
| 6333 | // data-processing instruction. |
| 6334 | if (ARM_AM::getSOImmVal(CVal) != -1) |
| 6335 | break; |
| 6336 | } |
| 6337 | return; |
| 6338 | |
| 6339 | case 'J': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 6340 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 6341 | // This must be a constant between -255 and -1, for negated ADD |
| 6342 | // immediates. This can be used in GCC with an "n" modifier that |
| 6343 | // prints the negated value, for use with SUB instructions. It is |
| 6344 | // not useful otherwise but is implemented for compatibility. |
| 6345 | if (CVal >= -255 && CVal <= -1) |
| 6346 | break; |
| 6347 | } else { |
| 6348 | // This must be a constant between -4095 and 4095. It is not clear |
| 6349 | // what this constraint is intended for. Implemented for |
| 6350 | // compatibility with GCC. |
| 6351 | if (CVal >= -4095 && CVal <= 4095) |
| 6352 | break; |
| 6353 | } |
| 6354 | return; |
| 6355 | |
| 6356 | case 'K': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 6357 | if (Subtarget->isThumb1Only()) { |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 6358 | // A 32-bit value where only one byte has a nonzero value. Exclude |
| 6359 | // zero to match GCC. This constraint is used by GCC internally for |
| 6360 | // constants that can be loaded with a move/shift combination. |
| 6361 | // It is not useful otherwise but is implemented for compatibility. |
| 6362 | if (CVal != 0 && ARM_AM::isThumbImmShiftedVal(CVal)) |
| 6363 | break; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 6364 | } else if (Subtarget->isThumb2()) { |
| 6365 | // A constant whose bitwise inverse can be used as an immediate |
| 6366 | // value in a data-processing instruction. This can be used in GCC |
| 6367 | // with a "B" modifier that prints the inverted value, for use with |
| 6368 | // BIC and MVN instructions. It is not useful otherwise but is |
| 6369 | // implemented for compatibility. |
| 6370 | if (ARM_AM::getT2SOImmVal(~CVal) != -1) |
| 6371 | break; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 6372 | } else { |
| 6373 | // A constant whose bitwise inverse can be used as an immediate |
| 6374 | // value in a data-processing instruction. This can be used in GCC |
| 6375 | // with a "B" modifier that prints the inverted value, for use with |
| 6376 | // BIC and MVN instructions. It is not useful otherwise but is |
| 6377 | // implemented for compatibility. |
| 6378 | if (ARM_AM::getSOImmVal(~CVal) != -1) |
| 6379 | break; |
| 6380 | } |
| 6381 | return; |
| 6382 | |
| 6383 | case 'L': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 6384 | if (Subtarget->isThumb1Only()) { |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 6385 | // This must be a constant between -7 and 7, |
| 6386 | // for 3-operand ADD/SUB immediate instructions. |
| 6387 | if (CVal >= -7 && CVal < 7) |
| 6388 | break; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 6389 | } else if (Subtarget->isThumb2()) { |
| 6390 | // A constant whose negation can be used as an immediate value in a |
| 6391 | // data-processing instruction. This can be used in GCC with an "n" |
| 6392 | // modifier that prints the negated value, for use with SUB |
| 6393 | // instructions. It is not useful otherwise but is implemented for |
| 6394 | // compatibility. |
| 6395 | if (ARM_AM::getT2SOImmVal(-CVal) != -1) |
| 6396 | break; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 6397 | } else { |
| 6398 | // A constant whose negation can be used as an immediate value in a |
| 6399 | // data-processing instruction. This can be used in GCC with an "n" |
| 6400 | // modifier that prints the negated value, for use with SUB |
| 6401 | // instructions. It is not useful otherwise but is implemented for |
| 6402 | // compatibility. |
| 6403 | if (ARM_AM::getSOImmVal(-CVal) != -1) |
| 6404 | break; |
| 6405 | } |
| 6406 | return; |
| 6407 | |
| 6408 | case 'M': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 6409 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 6410 | // This must be a multiple of 4 between 0 and 1020, for |
| 6411 | // ADD sp + immediate. |
| 6412 | if ((CVal >= 0 && CVal <= 1020) && ((CVal & 3) == 0)) |
| 6413 | break; |
| 6414 | } else { |
| 6415 | // A power of two or a constant between 0 and 32. This is used in |
| 6416 | // GCC for the shift amount on shifted register operands, but it is |
| 6417 | // useful in general for any shift amounts. |
| 6418 | if ((CVal >= 0 && CVal <= 32) || ((CVal & (CVal - 1)) == 0)) |
| 6419 | break; |
| 6420 | } |
| 6421 | return; |
| 6422 | |
| 6423 | case 'N': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 6424 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 6425 | // This must be a constant between 0 and 31, for shift amounts. |
| 6426 | if (CVal >= 0 && CVal <= 31) |
| 6427 | break; |
| 6428 | } |
| 6429 | return; |
| 6430 | |
| 6431 | case 'O': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 6432 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 6433 | // This must be a multiple of 4 between -508 and 508, for |
| 6434 | // ADD/SUB sp = sp + immediate. |
| 6435 | if ((CVal >= -508 && CVal <= 508) && ((CVal & 3) == 0)) |
| 6436 | break; |
| 6437 | } |
| 6438 | return; |
| 6439 | } |
| 6440 | Result = DAG.getTargetConstant(CVal, Op.getValueType()); |
| 6441 | break; |
| 6442 | } |
| 6443 | |
| 6444 | if (Result.getNode()) { |
| 6445 | Ops.push_back(Result); |
| 6446 | return; |
| 6447 | } |
Dale Johannesen | 1784d16 | 2010-06-25 21:55:36 +0000 | [diff] [blame] | 6448 | return TargetLowering::LowerAsmOperandForConstraint(Op, Constraint, Ops, DAG); |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 6449 | } |
Anton Korobeynikov | 48e1935 | 2009-09-23 19:04:09 +0000 | [diff] [blame] | 6450 | |
| 6451 | bool |
| 6452 | ARMTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const { |
| 6453 | // The ARM target isn't yet aware of offsets. |
| 6454 | return false; |
| 6455 | } |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 6456 | |
| 6457 | int ARM::getVFPf32Imm(const APFloat &FPImm) { |
| 6458 | APInt Imm = FPImm.bitcastToAPInt(); |
| 6459 | uint32_t Sign = Imm.lshr(31).getZExtValue() & 1; |
| 6460 | int32_t Exp = (Imm.lshr(23).getSExtValue() & 0xff) - 127; // -126 to 127 |
| 6461 | int64_t Mantissa = Imm.getZExtValue() & 0x7fffff; // 23 bits |
| 6462 | |
| 6463 | // We can handle 4 bits of mantissa. |
| 6464 | // mantissa = (16+UInt(e:f:g:h))/16. |
| 6465 | if (Mantissa & 0x7ffff) |
| 6466 | return -1; |
| 6467 | Mantissa >>= 19; |
| 6468 | if ((Mantissa & 0xf) != Mantissa) |
| 6469 | return -1; |
| 6470 | |
| 6471 | // We can handle 3 bits of exponent: exp == UInt(NOT(b):c:d)-3 |
| 6472 | if (Exp < -3 || Exp > 4) |
| 6473 | return -1; |
| 6474 | Exp = ((Exp+3) & 0x7) ^ 4; |
| 6475 | |
| 6476 | return ((int)Sign << 7) | (Exp << 4) | Mantissa; |
| 6477 | } |
| 6478 | |
| 6479 | int ARM::getVFPf64Imm(const APFloat &FPImm) { |
| 6480 | APInt Imm = FPImm.bitcastToAPInt(); |
| 6481 | uint64_t Sign = Imm.lshr(63).getZExtValue() & 1; |
| 6482 | int64_t Exp = (Imm.lshr(52).getSExtValue() & 0x7ff) - 1023; // -1022 to 1023 |
| 6483 | uint64_t Mantissa = Imm.getZExtValue() & 0xfffffffffffffLL; |
| 6484 | |
| 6485 | // We can handle 4 bits of mantissa. |
| 6486 | // mantissa = (16+UInt(e:f:g:h))/16. |
| 6487 | if (Mantissa & 0xffffffffffffLL) |
| 6488 | return -1; |
| 6489 | Mantissa >>= 48; |
| 6490 | if ((Mantissa & 0xf) != Mantissa) |
| 6491 | return -1; |
| 6492 | |
| 6493 | // We can handle 3 bits of exponent: exp == UInt(NOT(b):c:d)-3 |
| 6494 | if (Exp < -3 || Exp > 4) |
| 6495 | return -1; |
| 6496 | Exp = ((Exp+3) & 0x7) ^ 4; |
| 6497 | |
| 6498 | return ((int)Sign << 7) | (Exp << 4) | Mantissa; |
| 6499 | } |
| 6500 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 6501 | bool ARM::isBitFieldInvertedMask(unsigned v) { |
| 6502 | if (v == 0xffffffff) |
| 6503 | return 0; |
| 6504 | // there can be 1's on either or both "outsides", all the "inside" |
| 6505 | // bits must be 0's |
| 6506 | unsigned int lsb = 0, msb = 31; |
| 6507 | while (v & (1 << msb)) --msb; |
| 6508 | while (v & (1 << lsb)) ++lsb; |
| 6509 | for (unsigned int i = lsb; i <= msb; ++i) { |
| 6510 | if (v & (1 << i)) |
| 6511 | return 0; |
| 6512 | } |
| 6513 | return 1; |
| 6514 | } |
| 6515 | |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 6516 | /// isFPImmLegal - Returns true if the target can instruction select the |
| 6517 | /// specified FP immediate natively. If false, the legalizer will |
| 6518 | /// materialize the FP immediate as a load from a constant pool. |
| 6519 | bool ARMTargetLowering::isFPImmLegal(const APFloat &Imm, EVT VT) const { |
| 6520 | if (!Subtarget->hasVFP3()) |
| 6521 | return false; |
| 6522 | if (VT == MVT::f32) |
| 6523 | return ARM::getVFPf32Imm(Imm) != -1; |
| 6524 | if (VT == MVT::f64) |
| 6525 | return ARM::getVFPf64Imm(Imm) != -1; |
| 6526 | return false; |
| 6527 | } |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 6528 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6529 | /// getTgtMemIntrinsic - Represent NEON load and store intrinsics as |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 6530 | /// MemIntrinsicNodes. The associated MachineMemOperands record the alignment |
| 6531 | /// specified in the intrinsic calls. |
| 6532 | bool ARMTargetLowering::getTgtMemIntrinsic(IntrinsicInfo &Info, |
| 6533 | const CallInst &I, |
| 6534 | unsigned Intrinsic) const { |
| 6535 | switch (Intrinsic) { |
| 6536 | case Intrinsic::arm_neon_vld1: |
| 6537 | case Intrinsic::arm_neon_vld2: |
| 6538 | case Intrinsic::arm_neon_vld3: |
| 6539 | case Intrinsic::arm_neon_vld4: |
| 6540 | case Intrinsic::arm_neon_vld2lane: |
| 6541 | case Intrinsic::arm_neon_vld3lane: |
| 6542 | case Intrinsic::arm_neon_vld4lane: { |
| 6543 | Info.opc = ISD::INTRINSIC_W_CHAIN; |
| 6544 | // Conservatively set memVT to the entire set of vectors loaded. |
| 6545 | uint64_t NumElts = getTargetData()->getTypeAllocSize(I.getType()) / 8; |
| 6546 | Info.memVT = EVT::getVectorVT(I.getType()->getContext(), MVT::i64, NumElts); |
| 6547 | Info.ptrVal = I.getArgOperand(0); |
| 6548 | Info.offset = 0; |
| 6549 | Value *AlignArg = I.getArgOperand(I.getNumArgOperands() - 1); |
| 6550 | Info.align = cast<ConstantInt>(AlignArg)->getZExtValue(); |
| 6551 | Info.vol = false; // volatile loads with NEON intrinsics not supported |
| 6552 | Info.readMem = true; |
| 6553 | Info.writeMem = false; |
| 6554 | return true; |
| 6555 | } |
| 6556 | case Intrinsic::arm_neon_vst1: |
| 6557 | case Intrinsic::arm_neon_vst2: |
| 6558 | case Intrinsic::arm_neon_vst3: |
| 6559 | case Intrinsic::arm_neon_vst4: |
| 6560 | case Intrinsic::arm_neon_vst2lane: |
| 6561 | case Intrinsic::arm_neon_vst3lane: |
| 6562 | case Intrinsic::arm_neon_vst4lane: { |
| 6563 | Info.opc = ISD::INTRINSIC_VOID; |
| 6564 | // Conservatively set memVT to the entire set of vectors stored. |
| 6565 | unsigned NumElts = 0; |
| 6566 | for (unsigned ArgI = 1, ArgE = I.getNumArgOperands(); ArgI < ArgE; ++ArgI) { |
| 6567 | const Type *ArgTy = I.getArgOperand(ArgI)->getType(); |
| 6568 | if (!ArgTy->isVectorTy()) |
| 6569 | break; |
| 6570 | NumElts += getTargetData()->getTypeAllocSize(ArgTy) / 8; |
| 6571 | } |
| 6572 | Info.memVT = EVT::getVectorVT(I.getType()->getContext(), MVT::i64, NumElts); |
| 6573 | Info.ptrVal = I.getArgOperand(0); |
| 6574 | Info.offset = 0; |
| 6575 | Value *AlignArg = I.getArgOperand(I.getNumArgOperands() - 1); |
| 6576 | Info.align = cast<ConstantInt>(AlignArg)->getZExtValue(); |
| 6577 | Info.vol = false; // volatile stores with NEON intrinsics not supported |
| 6578 | Info.readMem = false; |
| 6579 | Info.writeMem = true; |
| 6580 | return true; |
| 6581 | } |
| 6582 | default: |
| 6583 | break; |
| 6584 | } |
| 6585 | |
| 6586 | return false; |
| 6587 | } |