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 | |
| 15 | #include "ARM.h" |
| 16 | #include "ARMAddressingModes.h" |
| 17 | #include "ARMConstantPoolValue.h" |
| 18 | #include "ARMISelLowering.h" |
| 19 | #include "ARMMachineFunctionInfo.h" |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 20 | #include "ARMPerfectShuffle.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 21 | #include "ARMRegisterInfo.h" |
| 22 | #include "ARMSubtarget.h" |
| 23 | #include "ARMTargetMachine.h" |
Chris Lattner | 80ec279 | 2009-08-02 00:34:36 +0000 | [diff] [blame] | 24 | #include "ARMTargetObjectFile.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 25 | #include "llvm/CallingConv.h" |
| 26 | #include "llvm/Constants.h" |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 27 | #include "llvm/Function.h" |
Benjamin Kramer | 174101e | 2009-10-20 11:44:38 +0000 | [diff] [blame] | 28 | #include "llvm/GlobalValue.h" |
Evan Cheng | 2770747 | 2007-03-16 08:43:56 +0000 | [diff] [blame] | 29 | #include "llvm/Instruction.h" |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 30 | #include "llvm/Intrinsics.h" |
Benjamin Kramer | 174101e | 2009-10-20 11:44:38 +0000 | [diff] [blame] | 31 | #include "llvm/Type.h" |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 32 | #include "llvm/CodeGen/CallingConvLower.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 33 | #include "llvm/CodeGen/MachineBasicBlock.h" |
| 34 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 35 | #include "llvm/CodeGen/MachineFunction.h" |
| 36 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 37 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 38 | #include "llvm/CodeGen/PseudoSourceValue.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 39 | #include "llvm/CodeGen/SelectionDAG.h" |
Bill Wendling | 94a1c63 | 2010-03-09 02:46:12 +0000 | [diff] [blame] | 40 | #include "llvm/MC/MCSectionMachO.h" |
Evan Cheng | b6ab254 | 2007-01-31 08:40:13 +0000 | [diff] [blame] | 41 | #include "llvm/Target/TargetOptions.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 42 | #include "llvm/ADT/VectorExtras.h" |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 43 | #include "llvm/Support/CommandLine.h" |
Torok Edwin | ab7c09b | 2009-07-08 18:01:40 +0000 | [diff] [blame] | 44 | #include "llvm/Support/ErrorHandling.h" |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 45 | #include "llvm/Support/MathExtras.h" |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 46 | #include "llvm/Support/raw_ostream.h" |
Jim Grosbach | 3fb2b1e | 2009-09-01 01:57:56 +0000 | [diff] [blame] | 47 | #include <sstream> |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 48 | using namespace llvm; |
| 49 | |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 50 | static cl::opt<bool> |
| 51 | EnableARMLongCalls("arm-long-calls", cl::Hidden, |
| 52 | cl::desc("Generate calls via indirect call instructions."), |
| 53 | cl::init(false)); |
| 54 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 55 | static bool CC_ARM_APCS_Custom_f64(unsigned &ValNo, EVT &ValVT, EVT &LocVT, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 56 | CCValAssign::LocInfo &LocInfo, |
| 57 | ISD::ArgFlagsTy &ArgFlags, |
| 58 | CCState &State); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 59 | static bool CC_ARM_AAPCS_Custom_f64(unsigned &ValNo, EVT &ValVT, EVT &LocVT, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 60 | CCValAssign::LocInfo &LocInfo, |
| 61 | ISD::ArgFlagsTy &ArgFlags, |
| 62 | CCState &State); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 63 | static bool RetCC_ARM_APCS_Custom_f64(unsigned &ValNo, EVT &ValVT, EVT &LocVT, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 64 | CCValAssign::LocInfo &LocInfo, |
| 65 | ISD::ArgFlagsTy &ArgFlags, |
| 66 | CCState &State); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 67 | static bool RetCC_ARM_AAPCS_Custom_f64(unsigned &ValNo, EVT &ValVT, EVT &LocVT, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 68 | CCValAssign::LocInfo &LocInfo, |
| 69 | ISD::ArgFlagsTy &ArgFlags, |
| 70 | CCState &State); |
| 71 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 72 | void ARMTargetLowering::addTypeForNEON(EVT VT, EVT PromotedLdStVT, |
| 73 | EVT PromotedBitwiseVT) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 74 | if (VT != PromotedLdStVT) { |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 75 | setOperationAction(ISD::LOAD, VT.getSimpleVT(), Promote); |
Owen Anderson | d6662ad | 2009-08-10 20:46:15 +0000 | [diff] [blame] | 76 | AddPromotedToType (ISD::LOAD, VT.getSimpleVT(), |
| 77 | PromotedLdStVT.getSimpleVT()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 78 | |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 79 | setOperationAction(ISD::STORE, VT.getSimpleVT(), Promote); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 80 | AddPromotedToType (ISD::STORE, VT.getSimpleVT(), |
Owen Anderson | d6662ad | 2009-08-10 20:46:15 +0000 | [diff] [blame] | 81 | PromotedLdStVT.getSimpleVT()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 82 | } |
| 83 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 84 | EVT ElemTy = VT.getVectorElementType(); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 85 | if (ElemTy != MVT::i64 && ElemTy != MVT::f64) |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 86 | setOperationAction(ISD::VSETCC, VT.getSimpleVT(), Custom); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 87 | if (ElemTy == MVT::i8 || ElemTy == MVT::i16) |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 88 | setOperationAction(ISD::EXTRACT_VECTOR_ELT, VT.getSimpleVT(), Custom); |
Bob Wilson | 0696fdf | 2009-09-16 20:20:44 +0000 | [diff] [blame] | 89 | if (ElemTy != MVT::i32) { |
| 90 | setOperationAction(ISD::SINT_TO_FP, VT.getSimpleVT(), Expand); |
| 91 | setOperationAction(ISD::UINT_TO_FP, VT.getSimpleVT(), Expand); |
| 92 | setOperationAction(ISD::FP_TO_SINT, VT.getSimpleVT(), Expand); |
| 93 | setOperationAction(ISD::FP_TO_UINT, VT.getSimpleVT(), Expand); |
| 94 | } |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 95 | setOperationAction(ISD::BUILD_VECTOR, VT.getSimpleVT(), Custom); |
| 96 | setOperationAction(ISD::VECTOR_SHUFFLE, VT.getSimpleVT(), Custom); |
Evan Cheng | de8aa4e | 2010-05-05 18:28:36 +0000 | [diff] [blame] | 97 | if (llvm::ModelWithRegSequence()) |
| 98 | setOperationAction(ISD::CONCAT_VECTORS, VT.getSimpleVT(), Legal); |
| 99 | else |
| 100 | setOperationAction(ISD::CONCAT_VECTORS, VT.getSimpleVT(), Custom); |
Anton Korobeynikov | 8e6c2b9 | 2009-08-21 12:40:35 +0000 | [diff] [blame] | 101 | setOperationAction(ISD::EXTRACT_SUBVECTOR, VT.getSimpleVT(), Expand); |
Bob Wilson | d0910c4 | 2010-04-06 22:02:24 +0000 | [diff] [blame] | 102 | setOperationAction(ISD::SELECT, VT.getSimpleVT(), Expand); |
| 103 | setOperationAction(ISD::SELECT_CC, VT.getSimpleVT(), Expand); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 104 | if (VT.isInteger()) { |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 105 | setOperationAction(ISD::SHL, VT.getSimpleVT(), Custom); |
| 106 | setOperationAction(ISD::SRA, VT.getSimpleVT(), Custom); |
| 107 | setOperationAction(ISD::SRL, VT.getSimpleVT(), Custom); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | // Promote all bit-wise operations. |
| 111 | if (VT.isInteger() && VT != PromotedBitwiseVT) { |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 112 | setOperationAction(ISD::AND, VT.getSimpleVT(), Promote); |
Owen Anderson | d6662ad | 2009-08-10 20:46:15 +0000 | [diff] [blame] | 113 | AddPromotedToType (ISD::AND, VT.getSimpleVT(), |
| 114 | PromotedBitwiseVT.getSimpleVT()); |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 115 | setOperationAction(ISD::OR, VT.getSimpleVT(), Promote); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 116 | AddPromotedToType (ISD::OR, VT.getSimpleVT(), |
Owen Anderson | d6662ad | 2009-08-10 20:46:15 +0000 | [diff] [blame] | 117 | PromotedBitwiseVT.getSimpleVT()); |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 118 | setOperationAction(ISD::XOR, VT.getSimpleVT(), Promote); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 119 | AddPromotedToType (ISD::XOR, VT.getSimpleVT(), |
Owen Anderson | d6662ad | 2009-08-10 20:46:15 +0000 | [diff] [blame] | 120 | PromotedBitwiseVT.getSimpleVT()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 121 | } |
Bob Wilson | 1633076 | 2009-09-16 00:17:28 +0000 | [diff] [blame] | 122 | |
| 123 | // Neon does not support vector divide/remainder operations. |
| 124 | setOperationAction(ISD::SDIV, VT.getSimpleVT(), Expand); |
| 125 | setOperationAction(ISD::UDIV, VT.getSimpleVT(), Expand); |
| 126 | setOperationAction(ISD::FDIV, VT.getSimpleVT(), Expand); |
| 127 | setOperationAction(ISD::SREM, VT.getSimpleVT(), Expand); |
| 128 | setOperationAction(ISD::UREM, VT.getSimpleVT(), Expand); |
| 129 | setOperationAction(ISD::FREM, VT.getSimpleVT(), Expand); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 130 | } |
| 131 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 132 | void ARMTargetLowering::addDRTypeForNEON(EVT VT) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 133 | addRegisterClass(VT, ARM::DPRRegisterClass); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 134 | addTypeForNEON(VT, MVT::f64, MVT::v2i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 135 | } |
| 136 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 137 | void ARMTargetLowering::addQRTypeForNEON(EVT VT) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 138 | addRegisterClass(VT, ARM::QPRRegisterClass); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 139 | addTypeForNEON(VT, MVT::v2f64, MVT::v4i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 140 | } |
| 141 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 142 | static TargetLoweringObjectFile *createTLOF(TargetMachine &TM) { |
| 143 | if (TM.getSubtarget<ARMSubtarget>().isTargetDarwin()) |
Bill Wendling | 505ad8b | 2010-03-15 21:09:38 +0000 | [diff] [blame] | 144 | return new TargetLoweringObjectFileMachO(); |
Bill Wendling | 94a1c63 | 2010-03-09 02:46:12 +0000 | [diff] [blame] | 145 | |
Chris Lattner | 80ec279 | 2009-08-02 00:34:36 +0000 | [diff] [blame] | 146 | return new ARMElfTargetObjectFile(); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 147 | } |
| 148 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 149 | ARMTargetLowering::ARMTargetLowering(TargetMachine &TM) |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 150 | : TargetLowering(TM, createTLOF(TM)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 151 | Subtarget = &TM.getSubtarget<ARMSubtarget>(); |
| 152 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 153 | if (Subtarget->isTargetDarwin()) { |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 154 | // Uses VFP for Thumb libfuncs if available. |
| 155 | if (Subtarget->isThumb() && Subtarget->hasVFP2()) { |
| 156 | // Single-precision floating-point arithmetic. |
| 157 | setLibcallName(RTLIB::ADD_F32, "__addsf3vfp"); |
| 158 | setLibcallName(RTLIB::SUB_F32, "__subsf3vfp"); |
| 159 | setLibcallName(RTLIB::MUL_F32, "__mulsf3vfp"); |
| 160 | setLibcallName(RTLIB::DIV_F32, "__divsf3vfp"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 161 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 162 | // Double-precision floating-point arithmetic. |
| 163 | setLibcallName(RTLIB::ADD_F64, "__adddf3vfp"); |
| 164 | setLibcallName(RTLIB::SUB_F64, "__subdf3vfp"); |
| 165 | setLibcallName(RTLIB::MUL_F64, "__muldf3vfp"); |
| 166 | setLibcallName(RTLIB::DIV_F64, "__divdf3vfp"); |
Evan Cheng | 193f850 | 2007-01-31 09:30:58 +0000 | [diff] [blame] | 167 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 168 | // Single-precision comparisons. |
| 169 | setLibcallName(RTLIB::OEQ_F32, "__eqsf2vfp"); |
| 170 | setLibcallName(RTLIB::UNE_F32, "__nesf2vfp"); |
| 171 | setLibcallName(RTLIB::OLT_F32, "__ltsf2vfp"); |
| 172 | setLibcallName(RTLIB::OLE_F32, "__lesf2vfp"); |
| 173 | setLibcallName(RTLIB::OGE_F32, "__gesf2vfp"); |
| 174 | setLibcallName(RTLIB::OGT_F32, "__gtsf2vfp"); |
| 175 | setLibcallName(RTLIB::UO_F32, "__unordsf2vfp"); |
| 176 | setLibcallName(RTLIB::O_F32, "__unordsf2vfp"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 177 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 178 | setCmpLibcallCC(RTLIB::OEQ_F32, ISD::SETNE); |
| 179 | setCmpLibcallCC(RTLIB::UNE_F32, ISD::SETNE); |
| 180 | setCmpLibcallCC(RTLIB::OLT_F32, ISD::SETNE); |
| 181 | setCmpLibcallCC(RTLIB::OLE_F32, ISD::SETNE); |
| 182 | setCmpLibcallCC(RTLIB::OGE_F32, ISD::SETNE); |
| 183 | setCmpLibcallCC(RTLIB::OGT_F32, ISD::SETNE); |
| 184 | setCmpLibcallCC(RTLIB::UO_F32, ISD::SETNE); |
| 185 | setCmpLibcallCC(RTLIB::O_F32, ISD::SETEQ); |
Evan Cheng | 193f850 | 2007-01-31 09:30:58 +0000 | [diff] [blame] | 186 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 187 | // Double-precision comparisons. |
| 188 | setLibcallName(RTLIB::OEQ_F64, "__eqdf2vfp"); |
| 189 | setLibcallName(RTLIB::UNE_F64, "__nedf2vfp"); |
| 190 | setLibcallName(RTLIB::OLT_F64, "__ltdf2vfp"); |
| 191 | setLibcallName(RTLIB::OLE_F64, "__ledf2vfp"); |
| 192 | setLibcallName(RTLIB::OGE_F64, "__gedf2vfp"); |
| 193 | setLibcallName(RTLIB::OGT_F64, "__gtdf2vfp"); |
| 194 | setLibcallName(RTLIB::UO_F64, "__unorddf2vfp"); |
| 195 | setLibcallName(RTLIB::O_F64, "__unorddf2vfp"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 196 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 197 | setCmpLibcallCC(RTLIB::OEQ_F64, ISD::SETNE); |
| 198 | setCmpLibcallCC(RTLIB::UNE_F64, ISD::SETNE); |
| 199 | setCmpLibcallCC(RTLIB::OLT_F64, ISD::SETNE); |
| 200 | setCmpLibcallCC(RTLIB::OLE_F64, ISD::SETNE); |
| 201 | setCmpLibcallCC(RTLIB::OGE_F64, ISD::SETNE); |
| 202 | setCmpLibcallCC(RTLIB::OGT_F64, ISD::SETNE); |
| 203 | setCmpLibcallCC(RTLIB::UO_F64, ISD::SETNE); |
| 204 | setCmpLibcallCC(RTLIB::O_F64, ISD::SETEQ); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 205 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 206 | // Floating-point to integer conversions. |
| 207 | // i64 conversions are done via library routines even when generating VFP |
| 208 | // instructions, so use the same ones. |
| 209 | setLibcallName(RTLIB::FPTOSINT_F64_I32, "__fixdfsivfp"); |
| 210 | setLibcallName(RTLIB::FPTOUINT_F64_I32, "__fixunsdfsivfp"); |
| 211 | setLibcallName(RTLIB::FPTOSINT_F32_I32, "__fixsfsivfp"); |
| 212 | setLibcallName(RTLIB::FPTOUINT_F32_I32, "__fixunssfsivfp"); |
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 | // Conversions between floating types. |
| 215 | setLibcallName(RTLIB::FPROUND_F64_F32, "__truncdfsf2vfp"); |
| 216 | setLibcallName(RTLIB::FPEXT_F32_F64, "__extendsfdf2vfp"); |
| 217 | |
| 218 | // Integer to floating-point conversions. |
| 219 | // i64 conversions are done via library routines even when generating VFP |
| 220 | // instructions, so use the same ones. |
Bob Wilson | 2a14c52 | 2009-03-20 23:16:43 +0000 | [diff] [blame] | 221 | // FIXME: There appears to be some naming inconsistency in ARM libgcc: |
| 222 | // e.g., __floatunsidf vs. __floatunssidfvfp. |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 223 | setLibcallName(RTLIB::SINTTOFP_I32_F64, "__floatsidfvfp"); |
| 224 | setLibcallName(RTLIB::UINTTOFP_I32_F64, "__floatunssidfvfp"); |
| 225 | setLibcallName(RTLIB::SINTTOFP_I32_F32, "__floatsisfvfp"); |
| 226 | setLibcallName(RTLIB::UINTTOFP_I32_F32, "__floatunssisfvfp"); |
| 227 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 228 | } |
| 229 | |
Bob Wilson | 2f95461 | 2009-05-22 17:38:41 +0000 | [diff] [blame] | 230 | // These libcalls are not available in 32-bit. |
| 231 | setLibcallName(RTLIB::SHL_I128, 0); |
| 232 | setLibcallName(RTLIB::SRL_I128, 0); |
| 233 | setLibcallName(RTLIB::SRA_I128, 0); |
| 234 | |
Anton Korobeynikov | 72977a4 | 2009-08-14 20:10:52 +0000 | [diff] [blame] | 235 | // Libcalls should use the AAPCS base standard ABI, even if hard float |
| 236 | // is in effect, as per the ARM RTABI specification, section 4.1.2. |
| 237 | if (Subtarget->isAAPCS_ABI()) { |
| 238 | for (int i = 0; i < RTLIB::UNKNOWN_LIBCALL; ++i) { |
| 239 | setLibcallCallingConv(static_cast<RTLIB::Libcall>(i), |
| 240 | CallingConv::ARM_AAPCS); |
| 241 | } |
| 242 | } |
| 243 | |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 244 | if (Subtarget->isThumb1Only()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 245 | addRegisterClass(MVT::i32, ARM::tGPRRegisterClass); |
Jim Grosbach | 30eae3c | 2009-04-07 20:34:09 +0000 | [diff] [blame] | 246 | else |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 247 | addRegisterClass(MVT::i32, ARM::GPRRegisterClass); |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 248 | if (!UseSoftFloat && Subtarget->hasVFP2() && !Subtarget->isThumb1Only()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 249 | addRegisterClass(MVT::f32, ARM::SPRRegisterClass); |
| 250 | addRegisterClass(MVT::f64, ARM::DPRRegisterClass); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 251 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 252 | setTruncStoreAction(MVT::f64, MVT::f32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 253 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 254 | |
| 255 | if (Subtarget->hasNEON()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 256 | addDRTypeForNEON(MVT::v2f32); |
| 257 | addDRTypeForNEON(MVT::v8i8); |
| 258 | addDRTypeForNEON(MVT::v4i16); |
| 259 | addDRTypeForNEON(MVT::v2i32); |
| 260 | addDRTypeForNEON(MVT::v1i64); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 261 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 262 | addQRTypeForNEON(MVT::v4f32); |
| 263 | addQRTypeForNEON(MVT::v2f64); |
| 264 | addQRTypeForNEON(MVT::v16i8); |
| 265 | addQRTypeForNEON(MVT::v8i16); |
| 266 | addQRTypeForNEON(MVT::v4i32); |
| 267 | addQRTypeForNEON(MVT::v2i64); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 268 | |
Bob Wilson | 74dc72e | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 269 | // v2f64 is legal so that QR subregs can be extracted as f64 elements, but |
| 270 | // neither Neon nor VFP support any arithmetic operations on it. |
| 271 | setOperationAction(ISD::FADD, MVT::v2f64, Expand); |
| 272 | setOperationAction(ISD::FSUB, MVT::v2f64, Expand); |
| 273 | setOperationAction(ISD::FMUL, MVT::v2f64, Expand); |
| 274 | setOperationAction(ISD::FDIV, MVT::v2f64, Expand); |
| 275 | setOperationAction(ISD::FREM, MVT::v2f64, Expand); |
| 276 | setOperationAction(ISD::FCOPYSIGN, MVT::v2f64, Expand); |
| 277 | setOperationAction(ISD::VSETCC, MVT::v2f64, Expand); |
| 278 | setOperationAction(ISD::FNEG, MVT::v2f64, Expand); |
| 279 | setOperationAction(ISD::FABS, MVT::v2f64, Expand); |
| 280 | setOperationAction(ISD::FSQRT, MVT::v2f64, Expand); |
| 281 | setOperationAction(ISD::FSIN, MVT::v2f64, Expand); |
| 282 | setOperationAction(ISD::FCOS, MVT::v2f64, Expand); |
| 283 | setOperationAction(ISD::FPOWI, MVT::v2f64, Expand); |
| 284 | setOperationAction(ISD::FPOW, MVT::v2f64, Expand); |
| 285 | setOperationAction(ISD::FLOG, MVT::v2f64, Expand); |
| 286 | setOperationAction(ISD::FLOG2, MVT::v2f64, Expand); |
| 287 | setOperationAction(ISD::FLOG10, MVT::v2f64, Expand); |
| 288 | setOperationAction(ISD::FEXP, MVT::v2f64, Expand); |
| 289 | setOperationAction(ISD::FEXP2, MVT::v2f64, Expand); |
| 290 | setOperationAction(ISD::FCEIL, MVT::v2f64, Expand); |
| 291 | setOperationAction(ISD::FTRUNC, MVT::v2f64, Expand); |
| 292 | setOperationAction(ISD::FRINT, MVT::v2f64, Expand); |
| 293 | setOperationAction(ISD::FNEARBYINT, MVT::v2f64, Expand); |
| 294 | setOperationAction(ISD::FFLOOR, MVT::v2f64, Expand); |
| 295 | |
Bob Wilson | 642b329 | 2009-09-16 00:32:15 +0000 | [diff] [blame] | 296 | // Neon does not support some operations on v1i64 and v2i64 types. |
| 297 | setOperationAction(ISD::MUL, MVT::v1i64, Expand); |
| 298 | setOperationAction(ISD::MUL, MVT::v2i64, Expand); |
| 299 | setOperationAction(ISD::VSETCC, MVT::v1i64, Expand); |
| 300 | setOperationAction(ISD::VSETCC, MVT::v2i64, Expand); |
| 301 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 302 | setTargetDAGCombine(ISD::INTRINSIC_WO_CHAIN); |
| 303 | setTargetDAGCombine(ISD::SHL); |
| 304 | setTargetDAGCombine(ISD::SRL); |
| 305 | setTargetDAGCombine(ISD::SRA); |
| 306 | setTargetDAGCombine(ISD::SIGN_EXTEND); |
| 307 | setTargetDAGCombine(ISD::ZERO_EXTEND); |
| 308 | setTargetDAGCombine(ISD::ANY_EXTEND); |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 309 | setTargetDAGCombine(ISD::SELECT_CC); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 310 | } |
| 311 | |
Evan Cheng | 9f8cbd1 | 2007-05-18 00:19:34 +0000 | [diff] [blame] | 312 | computeRegisterProperties(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 313 | |
| 314 | // ARM does not have f32 extending load. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 315 | setLoadExtAction(ISD::EXTLOAD, MVT::f32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 316 | |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 317 | // ARM does not have i1 sign extending load. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 318 | setLoadExtAction(ISD::SEXTLOAD, MVT::i1, Promote); |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 319 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 320 | // ARM supports all 4 flavors of integer indexed load / store. |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 321 | if (!Subtarget->isThumb1Only()) { |
| 322 | for (unsigned im = (unsigned)ISD::PRE_INC; |
| 323 | im != (unsigned)ISD::LAST_INDEXED_MODE; ++im) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 324 | setIndexedLoadAction(im, MVT::i1, Legal); |
| 325 | setIndexedLoadAction(im, MVT::i8, Legal); |
| 326 | setIndexedLoadAction(im, MVT::i16, Legal); |
| 327 | setIndexedLoadAction(im, MVT::i32, Legal); |
| 328 | setIndexedStoreAction(im, MVT::i1, Legal); |
| 329 | setIndexedStoreAction(im, MVT::i8, Legal); |
| 330 | setIndexedStoreAction(im, MVT::i16, Legal); |
| 331 | setIndexedStoreAction(im, MVT::i32, Legal); |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 332 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | // i64 operation support. |
Evan Cheng | 5b9fcd1 | 2009-07-07 01:17:28 +0000 | [diff] [blame] | 336 | if (Subtarget->isThumb1Only()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 337 | setOperationAction(ISD::MUL, MVT::i64, Expand); |
| 338 | setOperationAction(ISD::MULHU, MVT::i32, Expand); |
| 339 | setOperationAction(ISD::MULHS, MVT::i32, Expand); |
| 340 | setOperationAction(ISD::UMUL_LOHI, MVT::i32, Expand); |
| 341 | setOperationAction(ISD::SMUL_LOHI, MVT::i32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 342 | } else { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 343 | setOperationAction(ISD::MUL, MVT::i64, Expand); |
| 344 | setOperationAction(ISD::MULHU, MVT::i32, Expand); |
Evan Cheng | b620724 | 2009-08-01 00:16:10 +0000 | [diff] [blame] | 345 | if (!Subtarget->hasV6Ops()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 346 | setOperationAction(ISD::MULHS, MVT::i32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 347 | } |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 348 | setOperationAction(ISD::SHL_PARTS, MVT::i32, Custom); |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 349 | setOperationAction(ISD::SRA_PARTS, MVT::i32, Custom); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 350 | setOperationAction(ISD::SRL_PARTS, MVT::i32, Custom); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 351 | setOperationAction(ISD::SRL, MVT::i64, Custom); |
| 352 | setOperationAction(ISD::SRA, MVT::i64, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 353 | |
| 354 | // ARM does not have ROTL. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 355 | setOperationAction(ISD::ROTL, MVT::i32, Expand); |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 356 | setOperationAction(ISD::CTTZ, MVT::i32, Custom); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 357 | setOperationAction(ISD::CTPOP, MVT::i32, Expand); |
David Goodwin | 24062ac | 2009-06-26 20:47:43 +0000 | [diff] [blame] | 358 | if (!Subtarget->hasV5TOps() || Subtarget->isThumb1Only()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 359 | setOperationAction(ISD::CTLZ, MVT::i32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 360 | |
Lauro Ramos Venancio | 368f20f | 2007-03-16 22:54:16 +0000 | [diff] [blame] | 361 | // Only ARMv6 has BSWAP. |
| 362 | if (!Subtarget->hasV6Ops()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 363 | setOperationAction(ISD::BSWAP, MVT::i32, Expand); |
Lauro Ramos Venancio | 368f20f | 2007-03-16 22:54:16 +0000 | [diff] [blame] | 364 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 365 | // These are expanded into libcalls. |
Jim Grosbach | 2940213 | 2010-05-05 23:44:43 +0000 | [diff] [blame] | 366 | if (!Subtarget->hasDivide()) { |
Jim Grosbach | b1dc393 | 2010-05-05 20:44:35 +0000 | [diff] [blame] | 367 | // v7M has a hardware divider |
| 368 | setOperationAction(ISD::SDIV, MVT::i32, Expand); |
| 369 | setOperationAction(ISD::UDIV, MVT::i32, Expand); |
| 370 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 371 | setOperationAction(ISD::SREM, MVT::i32, Expand); |
| 372 | setOperationAction(ISD::UREM, MVT::i32, Expand); |
| 373 | setOperationAction(ISD::SDIVREM, MVT::i32, Expand); |
| 374 | setOperationAction(ISD::UDIVREM, MVT::i32, Expand); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 375 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 376 | setOperationAction(ISD::GlobalAddress, MVT::i32, Custom); |
| 377 | setOperationAction(ISD::ConstantPool, MVT::i32, Custom); |
| 378 | setOperationAction(ISD::GLOBAL_OFFSET_TABLE, MVT::i32, Custom); |
| 379 | setOperationAction(ISD::GlobalTLSAddress, MVT::i32, Custom); |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 380 | setOperationAction(ISD::BlockAddress, MVT::i32, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 381 | |
Evan Cheng | fb3611d | 2010-05-11 07:26:32 +0000 | [diff] [blame] | 382 | setOperationAction(ISD::TRAP, MVT::Other, Legal); |
| 383 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 384 | // Use the default implementation. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 385 | setOperationAction(ISD::VASTART, MVT::Other, Custom); |
| 386 | setOperationAction(ISD::VAARG, MVT::Other, Expand); |
| 387 | setOperationAction(ISD::VACOPY, MVT::Other, Expand); |
| 388 | setOperationAction(ISD::VAEND, MVT::Other, Expand); |
| 389 | setOperationAction(ISD::STACKSAVE, MVT::Other, Expand); |
| 390 | setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand); |
Jim Grosbach | bff3923 | 2009-08-12 17:38:44 +0000 | [diff] [blame] | 391 | setOperationAction(ISD::EHSELECTION, MVT::i32, Expand); |
| 392 | // FIXME: Shouldn't need this, since no register is used, but the legalizer |
| 393 | // doesn't yet know how to not do that for SjLj. |
| 394 | setExceptionSelectorRegister(ARM::R0); |
Evan Cheng | 3a1588a | 2010-04-15 22:20:34 +0000 | [diff] [blame] | 395 | setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32, Expand); |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 396 | setOperationAction(ISD::MEMBARRIER, MVT::Other, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 397 | |
Jim Grosbach | 4b77f6a | 2010-05-07 18:34:55 +0000 | [diff] [blame] | 398 | // If the subtarget does not have extract instructions, sign_extend_inreg |
| 399 | // needs to be expanded. Extract is available in ARM mode on v6 and up, |
| 400 | // and on most Thumb2 implementations. |
| 401 | if ((!Subtarget->isThumb() && !Subtarget->hasV6Ops()) |
| 402 | || (Subtarget->isThumb2() && !Subtarget->hasT2ExtractPack())) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 403 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i16, Expand); |
| 404 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i8, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 405 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 406 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 407 | |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 408 | if (!UseSoftFloat && Subtarget->hasVFP2() && !Subtarget->isThumb1Only()) |
Bob Wilson | cb9a6aa | 2010-01-19 22:56:26 +0000 | [diff] [blame] | 409 | // Turn f64->i64 into VMOVRRD, i64 -> f64 to VMOVDRR |
| 410 | // iff target supports vfp2. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 411 | setOperationAction(ISD::BIT_CONVERT, MVT::i64, Custom); |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 412 | |
| 413 | // We want to custom lower some of our intrinsics. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 414 | setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom); |
Jim Grosbach | 5eb1951 | 2010-05-22 01:06:18 +0000 | [diff] [blame^] | 415 | setOperationAction(ISD::EH_SJLJ_LONGJMP, MVT::Other, Custom); |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 416 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 417 | setOperationAction(ISD::SETCC, MVT::i32, Expand); |
| 418 | setOperationAction(ISD::SETCC, MVT::f32, Expand); |
| 419 | setOperationAction(ISD::SETCC, MVT::f64, Expand); |
| 420 | setOperationAction(ISD::SELECT, MVT::i32, Expand); |
| 421 | setOperationAction(ISD::SELECT, MVT::f32, Expand); |
| 422 | setOperationAction(ISD::SELECT, MVT::f64, Expand); |
| 423 | setOperationAction(ISD::SELECT_CC, MVT::i32, Custom); |
| 424 | setOperationAction(ISD::SELECT_CC, MVT::f32, Custom); |
| 425 | setOperationAction(ISD::SELECT_CC, MVT::f64, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 426 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 427 | setOperationAction(ISD::BRCOND, MVT::Other, Expand); |
| 428 | setOperationAction(ISD::BR_CC, MVT::i32, Custom); |
| 429 | setOperationAction(ISD::BR_CC, MVT::f32, Custom); |
| 430 | setOperationAction(ISD::BR_CC, MVT::f64, Custom); |
| 431 | setOperationAction(ISD::BR_JT, MVT::Other, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 432 | |
Dan Gohman | f96e4de | 2007-10-11 23:21:31 +0000 | [diff] [blame] | 433 | // We don't support sin/cos/fmod/copysign/pow |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 434 | setOperationAction(ISD::FSIN, MVT::f64, Expand); |
| 435 | setOperationAction(ISD::FSIN, MVT::f32, Expand); |
| 436 | setOperationAction(ISD::FCOS, MVT::f32, Expand); |
| 437 | setOperationAction(ISD::FCOS, MVT::f64, Expand); |
| 438 | setOperationAction(ISD::FREM, MVT::f64, Expand); |
| 439 | setOperationAction(ISD::FREM, MVT::f32, Expand); |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 440 | if (!UseSoftFloat && Subtarget->hasVFP2() && !Subtarget->isThumb1Only()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 441 | setOperationAction(ISD::FCOPYSIGN, MVT::f64, Custom); |
| 442 | setOperationAction(ISD::FCOPYSIGN, MVT::f32, Custom); |
Evan Cheng | 110cf48 | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 443 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 444 | setOperationAction(ISD::FPOW, MVT::f64, Expand); |
| 445 | setOperationAction(ISD::FPOW, MVT::f32, Expand); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 446 | |
Anton Korobeynikov | bec3dd2 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 447 | // Various VFP goodness |
| 448 | if (!UseSoftFloat && !Subtarget->isThumb1Only()) { |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 449 | // int <-> fp are custom expanded into bit_convert + ARMISD ops. |
| 450 | if (Subtarget->hasVFP2()) { |
| 451 | setOperationAction(ISD::SINT_TO_FP, MVT::i32, Custom); |
| 452 | setOperationAction(ISD::UINT_TO_FP, MVT::i32, Custom); |
| 453 | setOperationAction(ISD::FP_TO_UINT, MVT::i32, Custom); |
| 454 | setOperationAction(ISD::FP_TO_SINT, MVT::i32, Custom); |
| 455 | } |
Anton Korobeynikov | bec3dd2 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 456 | // Special handling for half-precision FP. |
Anton Korobeynikov | f0d5007 | 2010-03-18 22:35:37 +0000 | [diff] [blame] | 457 | if (!Subtarget->hasFP16()) { |
| 458 | setOperationAction(ISD::FP16_TO_FP32, MVT::f32, Expand); |
| 459 | setOperationAction(ISD::FP32_TO_FP16, MVT::i32, Expand); |
Anton Korobeynikov | bec3dd2 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 460 | } |
Evan Cheng | 110cf48 | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 461 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 462 | |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 463 | // We have target-specific dag combine patterns for the following nodes: |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 464 | // ARMISD::VMOVRRD - No need to call setTargetDAGCombine |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 465 | setTargetDAGCombine(ISD::ADD); |
| 466 | setTargetDAGCombine(ISD::SUB); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 467 | setTargetDAGCombine(ISD::MUL); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 468 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 469 | setStackPointerRegisterToSaveRestore(ARM::SP); |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 470 | |
Evan Cheng | f7d87ee | 2010-05-21 00:43:17 +0000 | [diff] [blame] | 471 | if (UseSoftFloat || Subtarget->isThumb1Only() || !Subtarget->hasVFP2()) |
| 472 | setSchedulingPreference(Sched::RegPressure); |
| 473 | else |
| 474 | setSchedulingPreference(Sched::Hybrid); |
Dale Johannesen | 8dd86c1 | 2007-05-17 21:31:21 +0000 | [diff] [blame] | 475 | |
Evan Cheng | bc9b754 | 2009-08-15 07:59:10 +0000 | [diff] [blame] | 476 | // FIXME: If-converter should use instruction latency to determine |
| 477 | // profitability rather than relying on fixed limits. |
| 478 | if (Subtarget->getCPUString() == "generic") { |
| 479 | // Generic (and overly aggressive) if-conversion limits. |
| 480 | setIfCvtBlockSizeLimit(10); |
| 481 | setIfCvtDupBlockSizeLimit(2); |
Jim Grosbach | 35075a7 | 2010-03-24 16:15:14 +0000 | [diff] [blame] | 482 | } else if (Subtarget->hasV7Ops()) { |
Jim Grosbach | fceabef | 2010-03-24 00:03:13 +0000 | [diff] [blame] | 483 | setIfCvtBlockSizeLimit(3); |
| 484 | setIfCvtDupBlockSizeLimit(1); |
Evan Cheng | bc9b754 | 2009-08-15 07:59:10 +0000 | [diff] [blame] | 485 | } else if (Subtarget->hasV6Ops()) { |
| 486 | setIfCvtBlockSizeLimit(2); |
| 487 | setIfCvtDupBlockSizeLimit(1); |
| 488 | } else { |
| 489 | setIfCvtBlockSizeLimit(3); |
| 490 | setIfCvtDupBlockSizeLimit(2); |
Evan Cheng | 8557c2b | 2009-06-19 01:51:50 +0000 | [diff] [blame] | 491 | } |
| 492 | |
Dale Johannesen | 8dd86c1 | 2007-05-17 21:31:21 +0000 | [diff] [blame] | 493 | maxStoresPerMemcpy = 1; //// temporary - rewrite interface to use type |
Bob Wilson | e6abdff | 2009-05-18 20:55:32 +0000 | [diff] [blame] | 494 | // Do not enable CodePlacementOpt for now: it currently runs after the |
| 495 | // ARMConstantIslandPass and messes up branch relaxation and placement |
| 496 | // of constant islands. |
| 497 | // benefitFromCodePlacementOpt = true; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 498 | } |
| 499 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 500 | const char *ARMTargetLowering::getTargetNodeName(unsigned Opcode) const { |
| 501 | switch (Opcode) { |
| 502 | default: return 0; |
| 503 | case ARMISD::Wrapper: return "ARMISD::Wrapper"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 504 | case ARMISD::WrapperJT: return "ARMISD::WrapperJT"; |
| 505 | case ARMISD::CALL: return "ARMISD::CALL"; |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 506 | case ARMISD::CALL_PRED: return "ARMISD::CALL_PRED"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 507 | case ARMISD::CALL_NOLINK: return "ARMISD::CALL_NOLINK"; |
| 508 | case ARMISD::tCALL: return "ARMISD::tCALL"; |
| 509 | case ARMISD::BRCOND: return "ARMISD::BRCOND"; |
| 510 | case ARMISD::BR_JT: return "ARMISD::BR_JT"; |
Evan Cheng | 5657c01 | 2009-07-29 02:18:14 +0000 | [diff] [blame] | 511 | case ARMISD::BR2_JT: return "ARMISD::BR2_JT"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 512 | case ARMISD::RET_FLAG: return "ARMISD::RET_FLAG"; |
| 513 | case ARMISD::PIC_ADD: return "ARMISD::PIC_ADD"; |
| 514 | case ARMISD::CMP: return "ARMISD::CMP"; |
David Goodwin | c0309b4 | 2009-06-29 15:33:01 +0000 | [diff] [blame] | 515 | case ARMISD::CMPZ: return "ARMISD::CMPZ"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 516 | case ARMISD::CMPFP: return "ARMISD::CMPFP"; |
| 517 | case ARMISD::CMPFPw0: return "ARMISD::CMPFPw0"; |
| 518 | case ARMISD::FMSTAT: return "ARMISD::FMSTAT"; |
| 519 | case ARMISD::CMOV: return "ARMISD::CMOV"; |
| 520 | case ARMISD::CNEG: return "ARMISD::CNEG"; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 521 | |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 522 | case ARMISD::RBIT: return "ARMISD::RBIT"; |
| 523 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 524 | case ARMISD::FTOSI: return "ARMISD::FTOSI"; |
| 525 | case ARMISD::FTOUI: return "ARMISD::FTOUI"; |
| 526 | case ARMISD::SITOF: return "ARMISD::SITOF"; |
| 527 | case ARMISD::UITOF: return "ARMISD::UITOF"; |
| 528 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 529 | case ARMISD::SRL_FLAG: return "ARMISD::SRL_FLAG"; |
| 530 | case ARMISD::SRA_FLAG: return "ARMISD::SRA_FLAG"; |
| 531 | case ARMISD::RRX: return "ARMISD::RRX"; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 532 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 533 | case ARMISD::VMOVRRD: return "ARMISD::VMOVRRD"; |
| 534 | case ARMISD::VMOVDRR: return "ARMISD::VMOVDRR"; |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 535 | |
Evan Cheng | c594208 | 2009-10-28 06:55:03 +0000 | [diff] [blame] | 536 | case ARMISD::EH_SJLJ_SETJMP: return "ARMISD::EH_SJLJ_SETJMP"; |
| 537 | case ARMISD::EH_SJLJ_LONGJMP:return "ARMISD::EH_SJLJ_LONGJMP"; |
| 538 | |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 539 | case ARMISD::THREAD_POINTER:return "ARMISD::THREAD_POINTER"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 540 | |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 541 | case ARMISD::DYN_ALLOC: return "ARMISD::DYN_ALLOC"; |
| 542 | |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 543 | case ARMISD::MEMBARRIER: return "ARMISD::MEMBARRIER"; |
| 544 | case ARMISD::SYNCBARRIER: return "ARMISD::SYNCBARRIER"; |
| 545 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 546 | case ARMISD::VCEQ: return "ARMISD::VCEQ"; |
| 547 | case ARMISD::VCGE: return "ARMISD::VCGE"; |
| 548 | case ARMISD::VCGEU: return "ARMISD::VCGEU"; |
| 549 | case ARMISD::VCGT: return "ARMISD::VCGT"; |
| 550 | case ARMISD::VCGTU: return "ARMISD::VCGTU"; |
| 551 | case ARMISD::VTST: return "ARMISD::VTST"; |
| 552 | |
| 553 | case ARMISD::VSHL: return "ARMISD::VSHL"; |
| 554 | case ARMISD::VSHRs: return "ARMISD::VSHRs"; |
| 555 | case ARMISD::VSHRu: return "ARMISD::VSHRu"; |
| 556 | case ARMISD::VSHLLs: return "ARMISD::VSHLLs"; |
| 557 | case ARMISD::VSHLLu: return "ARMISD::VSHLLu"; |
| 558 | case ARMISD::VSHLLi: return "ARMISD::VSHLLi"; |
| 559 | case ARMISD::VSHRN: return "ARMISD::VSHRN"; |
| 560 | case ARMISD::VRSHRs: return "ARMISD::VRSHRs"; |
| 561 | case ARMISD::VRSHRu: return "ARMISD::VRSHRu"; |
| 562 | case ARMISD::VRSHRN: return "ARMISD::VRSHRN"; |
| 563 | case ARMISD::VQSHLs: return "ARMISD::VQSHLs"; |
| 564 | case ARMISD::VQSHLu: return "ARMISD::VQSHLu"; |
| 565 | case ARMISD::VQSHLsu: return "ARMISD::VQSHLsu"; |
| 566 | case ARMISD::VQSHRNs: return "ARMISD::VQSHRNs"; |
| 567 | case ARMISD::VQSHRNu: return "ARMISD::VQSHRNu"; |
| 568 | case ARMISD::VQSHRNsu: return "ARMISD::VQSHRNsu"; |
| 569 | case ARMISD::VQRSHRNs: return "ARMISD::VQRSHRNs"; |
| 570 | case ARMISD::VQRSHRNu: return "ARMISD::VQRSHRNu"; |
| 571 | case ARMISD::VQRSHRNsu: return "ARMISD::VQRSHRNsu"; |
| 572 | case ARMISD::VGETLANEu: return "ARMISD::VGETLANEu"; |
| 573 | case ARMISD::VGETLANEs: return "ARMISD::VGETLANEs"; |
Bob Wilson | c1d287b | 2009-08-14 05:13:08 +0000 | [diff] [blame] | 574 | case ARMISD::VDUP: return "ARMISD::VDUP"; |
Bob Wilson | 0ce3710 | 2009-08-14 05:08:32 +0000 | [diff] [blame] | 575 | case ARMISD::VDUPLANE: return "ARMISD::VDUPLANE"; |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 576 | case ARMISD::VEXT: return "ARMISD::VEXT"; |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 577 | case ARMISD::VREV64: return "ARMISD::VREV64"; |
| 578 | case ARMISD::VREV32: return "ARMISD::VREV32"; |
| 579 | case ARMISD::VREV16: return "ARMISD::VREV16"; |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 580 | case ARMISD::VZIP: return "ARMISD::VZIP"; |
| 581 | case ARMISD::VUZP: return "ARMISD::VUZP"; |
| 582 | case ARMISD::VTRN: return "ARMISD::VTRN"; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 583 | case ARMISD::FMAX: return "ARMISD::FMAX"; |
| 584 | case ARMISD::FMIN: return "ARMISD::FMIN"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 585 | } |
| 586 | } |
| 587 | |
Evan Cheng | 06b666c | 2010-05-15 02:18:07 +0000 | [diff] [blame] | 588 | /// getRegClassFor - Return the register class that should be used for the |
| 589 | /// specified value type. |
| 590 | TargetRegisterClass *ARMTargetLowering::getRegClassFor(EVT VT) const { |
| 591 | // Map v4i64 to QQ registers but do not make the type legal. Similarly map |
| 592 | // v8i64 to QQQQ registers. v4i64 and v8i64 are only used for REG_SEQUENCE to |
| 593 | // load / store 4 to 8 consecutive D registers. |
Evan Cheng | 4782b1e | 2010-05-15 02:20:21 +0000 | [diff] [blame] | 594 | if (Subtarget->hasNEON()) { |
| 595 | if (VT == MVT::v4i64) |
| 596 | return ARM::QQPRRegisterClass; |
| 597 | else if (VT == MVT::v8i64) |
| 598 | return ARM::QQQQPRRegisterClass; |
| 599 | } |
Evan Cheng | 06b666c | 2010-05-15 02:18:07 +0000 | [diff] [blame] | 600 | return TargetLowering::getRegClassFor(VT); |
| 601 | } |
| 602 | |
Bill Wendling | b4202b8 | 2009-07-01 18:50:55 +0000 | [diff] [blame] | 603 | /// getFunctionAlignment - Return the Log2 alignment of this function. |
Bill Wendling | 20c568f | 2009-06-30 22:38:32 +0000 | [diff] [blame] | 604 | unsigned ARMTargetLowering::getFunctionAlignment(const Function *F) const { |
Evan Cheng | 048e36f | 2009-10-02 06:57:25 +0000 | [diff] [blame] | 605 | return getTargetMachine().getSubtarget<ARMSubtarget>().isThumb() ? 0 : 1; |
Bill Wendling | 20c568f | 2009-06-30 22:38:32 +0000 | [diff] [blame] | 606 | } |
| 607 | |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 608 | Sched::Preference ARMTargetLowering::getSchedulingPreference(SDNode *N) const { |
| 609 | for (unsigned i = 0, e = N->getNumValues(); i != e; ++i) { |
| 610 | EVT VT = N->getValueType(i); |
| 611 | if (VT.isFloatingPoint() || VT.isVector()) |
| 612 | return Sched::Latency; |
| 613 | } |
| 614 | return Sched::RegPressure; |
| 615 | } |
| 616 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 617 | //===----------------------------------------------------------------------===// |
| 618 | // Lowering Code |
| 619 | //===----------------------------------------------------------------------===// |
| 620 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 621 | /// IntCCToARMCC - Convert a DAG integer condition code to an ARM CC |
| 622 | static ARMCC::CondCodes IntCCToARMCC(ISD::CondCode CC) { |
| 623 | switch (CC) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 624 | default: llvm_unreachable("Unknown condition code!"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 625 | case ISD::SETNE: return ARMCC::NE; |
| 626 | case ISD::SETEQ: return ARMCC::EQ; |
| 627 | case ISD::SETGT: return ARMCC::GT; |
| 628 | case ISD::SETGE: return ARMCC::GE; |
| 629 | case ISD::SETLT: return ARMCC::LT; |
| 630 | case ISD::SETLE: return ARMCC::LE; |
| 631 | case ISD::SETUGT: return ARMCC::HI; |
| 632 | case ISD::SETUGE: return ARMCC::HS; |
| 633 | case ISD::SETULT: return ARMCC::LO; |
| 634 | case ISD::SETULE: return ARMCC::LS; |
| 635 | } |
| 636 | } |
| 637 | |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 638 | /// FPCCToARMCC - Convert a DAG fp condition code to an ARM CC. |
| 639 | static void FPCCToARMCC(ISD::CondCode CC, ARMCC::CondCodes &CondCode, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 640 | ARMCC::CondCodes &CondCode2) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 641 | CondCode2 = ARMCC::AL; |
| 642 | switch (CC) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 643 | default: llvm_unreachable("Unknown FP condition!"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 644 | case ISD::SETEQ: |
| 645 | case ISD::SETOEQ: CondCode = ARMCC::EQ; break; |
| 646 | case ISD::SETGT: |
| 647 | case ISD::SETOGT: CondCode = ARMCC::GT; break; |
| 648 | case ISD::SETGE: |
| 649 | case ISD::SETOGE: CondCode = ARMCC::GE; break; |
| 650 | case ISD::SETOLT: CondCode = ARMCC::MI; break; |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 651 | case ISD::SETOLE: CondCode = ARMCC::LS; break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 652 | case ISD::SETONE: CondCode = ARMCC::MI; CondCode2 = ARMCC::GT; break; |
| 653 | case ISD::SETO: CondCode = ARMCC::VC; break; |
| 654 | case ISD::SETUO: CondCode = ARMCC::VS; break; |
| 655 | case ISD::SETUEQ: CondCode = ARMCC::EQ; CondCode2 = ARMCC::VS; break; |
| 656 | case ISD::SETUGT: CondCode = ARMCC::HI; break; |
| 657 | case ISD::SETUGE: CondCode = ARMCC::PL; break; |
| 658 | case ISD::SETLT: |
| 659 | case ISD::SETULT: CondCode = ARMCC::LT; break; |
| 660 | case ISD::SETLE: |
| 661 | case ISD::SETULE: CondCode = ARMCC::LE; break; |
| 662 | case ISD::SETNE: |
| 663 | case ISD::SETUNE: CondCode = ARMCC::NE; break; |
| 664 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 665 | } |
| 666 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 667 | //===----------------------------------------------------------------------===// |
| 668 | // Calling Convention Implementation |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 669 | //===----------------------------------------------------------------------===// |
| 670 | |
| 671 | #include "ARMGenCallingConv.inc" |
| 672 | |
| 673 | // APCS f64 is in register pairs, possibly split to stack |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 674 | static bool f64AssignAPCS(unsigned &ValNo, EVT &ValVT, EVT &LocVT, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 675 | CCValAssign::LocInfo &LocInfo, |
| 676 | CCState &State, bool CanFail) { |
| 677 | static const unsigned RegList[] = { ARM::R0, ARM::R1, ARM::R2, ARM::R3 }; |
| 678 | |
| 679 | // Try to get the first register. |
| 680 | if (unsigned Reg = State.AllocateReg(RegList, 4)) |
| 681 | State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo)); |
| 682 | else { |
| 683 | // For the 2nd half of a v2f64, do not fail. |
| 684 | if (CanFail) |
| 685 | return false; |
| 686 | |
| 687 | // Put the whole thing on the stack. |
| 688 | State.addLoc(CCValAssign::getCustomMem(ValNo, ValVT, |
| 689 | State.AllocateStack(8, 4), |
| 690 | LocVT, LocInfo)); |
| 691 | return true; |
| 692 | } |
| 693 | |
| 694 | // Try to get the second register. |
| 695 | if (unsigned Reg = State.AllocateReg(RegList, 4)) |
| 696 | State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo)); |
| 697 | else |
| 698 | State.addLoc(CCValAssign::getCustomMem(ValNo, ValVT, |
| 699 | State.AllocateStack(4, 4), |
| 700 | LocVT, LocInfo)); |
| 701 | return true; |
| 702 | } |
| 703 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 704 | static bool CC_ARM_APCS_Custom_f64(unsigned &ValNo, EVT &ValVT, EVT &LocVT, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 705 | CCValAssign::LocInfo &LocInfo, |
| 706 | ISD::ArgFlagsTy &ArgFlags, |
| 707 | CCState &State) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 708 | if (!f64AssignAPCS(ValNo, ValVT, LocVT, LocInfo, State, true)) |
| 709 | return false; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 710 | if (LocVT == MVT::v2f64 && |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 711 | !f64AssignAPCS(ValNo, ValVT, LocVT, LocInfo, State, false)) |
| 712 | return false; |
Bob Wilson | e65586b | 2009-04-17 20:40:45 +0000 | [diff] [blame] | 713 | return true; // we handled it |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | // AAPCS f64 is in aligned register pairs |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 717 | static bool f64AssignAAPCS(unsigned &ValNo, EVT &ValVT, EVT &LocVT, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 718 | CCValAssign::LocInfo &LocInfo, |
| 719 | CCState &State, bool CanFail) { |
| 720 | static const unsigned HiRegList[] = { ARM::R0, ARM::R2 }; |
| 721 | static const unsigned LoRegList[] = { ARM::R1, ARM::R3 }; |
| 722 | |
| 723 | unsigned Reg = State.AllocateReg(HiRegList, LoRegList, 2); |
| 724 | if (Reg == 0) { |
| 725 | // For the 2nd half of a v2f64, do not just fail. |
| 726 | if (CanFail) |
| 727 | return false; |
| 728 | |
| 729 | // Put the whole thing on the stack. |
| 730 | State.addLoc(CCValAssign::getCustomMem(ValNo, ValVT, |
| 731 | State.AllocateStack(8, 8), |
| 732 | LocVT, LocInfo)); |
| 733 | return true; |
| 734 | } |
| 735 | |
| 736 | unsigned i; |
| 737 | for (i = 0; i < 2; ++i) |
| 738 | if (HiRegList[i] == Reg) |
| 739 | break; |
| 740 | |
| 741 | State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo)); |
| 742 | State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, LoRegList[i], |
| 743 | LocVT, LocInfo)); |
| 744 | return true; |
| 745 | } |
| 746 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 747 | static bool CC_ARM_AAPCS_Custom_f64(unsigned &ValNo, EVT &ValVT, EVT &LocVT, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 748 | CCValAssign::LocInfo &LocInfo, |
| 749 | ISD::ArgFlagsTy &ArgFlags, |
| 750 | CCState &State) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 751 | if (!f64AssignAAPCS(ValNo, ValVT, LocVT, LocInfo, State, true)) |
| 752 | return false; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 753 | if (LocVT == MVT::v2f64 && |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 754 | !f64AssignAAPCS(ValNo, ValVT, LocVT, LocInfo, State, false)) |
| 755 | return false; |
| 756 | return true; // we handled it |
| 757 | } |
| 758 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 759 | static bool f64RetAssign(unsigned &ValNo, EVT &ValVT, EVT &LocVT, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 760 | CCValAssign::LocInfo &LocInfo, CCState &State) { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 761 | static const unsigned HiRegList[] = { ARM::R0, ARM::R2 }; |
| 762 | static const unsigned LoRegList[] = { ARM::R1, ARM::R3 }; |
| 763 | |
Bob Wilson | e65586b | 2009-04-17 20:40:45 +0000 | [diff] [blame] | 764 | unsigned Reg = State.AllocateReg(HiRegList, LoRegList, 2); |
| 765 | if (Reg == 0) |
| 766 | return false; // we didn't handle it |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 767 | |
Bob Wilson | e65586b | 2009-04-17 20:40:45 +0000 | [diff] [blame] | 768 | unsigned i; |
| 769 | for (i = 0; i < 2; ++i) |
| 770 | if (HiRegList[i] == Reg) |
| 771 | break; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 772 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 773 | State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo)); |
Bob Wilson | e65586b | 2009-04-17 20:40:45 +0000 | [diff] [blame] | 774 | State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, LoRegList[i], |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 775 | LocVT, LocInfo)); |
| 776 | return true; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 777 | } |
| 778 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 779 | static bool RetCC_ARM_APCS_Custom_f64(unsigned &ValNo, EVT &ValVT, EVT &LocVT, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 780 | CCValAssign::LocInfo &LocInfo, |
| 781 | ISD::ArgFlagsTy &ArgFlags, |
| 782 | CCState &State) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 783 | if (!f64RetAssign(ValNo, ValVT, LocVT, LocInfo, State)) |
| 784 | return false; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 785 | if (LocVT == MVT::v2f64 && !f64RetAssign(ValNo, ValVT, LocVT, LocInfo, State)) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 786 | return false; |
Bob Wilson | e65586b | 2009-04-17 20:40:45 +0000 | [diff] [blame] | 787 | return true; // we handled it |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 788 | } |
| 789 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 790 | static bool RetCC_ARM_AAPCS_Custom_f64(unsigned &ValNo, EVT &ValVT, EVT &LocVT, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 791 | CCValAssign::LocInfo &LocInfo, |
| 792 | ISD::ArgFlagsTy &ArgFlags, |
| 793 | CCState &State) { |
| 794 | return RetCC_ARM_APCS_Custom_f64(ValNo, ValVT, LocVT, LocInfo, ArgFlags, |
| 795 | State); |
| 796 | } |
| 797 | |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 798 | /// CCAssignFnForNode - Selects the correct CCAssignFn for a the |
| 799 | /// given CallingConvention value. |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 800 | CCAssignFn *ARMTargetLowering::CCAssignFnForNode(CallingConv::ID CC, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 801 | bool Return, |
| 802 | bool isVarArg) const { |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 803 | switch (CC) { |
| 804 | default: |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 805 | llvm_unreachable("Unsupported calling convention"); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 806 | case CallingConv::C: |
| 807 | case CallingConv::Fast: |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 808 | // Use target triple & subtarget features to do actual dispatch. |
| 809 | if (Subtarget->isAAPCS_ABI()) { |
| 810 | if (Subtarget->hasVFP2() && |
| 811 | FloatABIType == FloatABI::Hard && !isVarArg) |
| 812 | return (Return ? RetCC_ARM_AAPCS_VFP: CC_ARM_AAPCS_VFP); |
| 813 | else |
| 814 | return (Return ? RetCC_ARM_AAPCS: CC_ARM_AAPCS); |
| 815 | } else |
| 816 | return (Return ? RetCC_ARM_APCS: CC_ARM_APCS); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 817 | case CallingConv::ARM_AAPCS_VFP: |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 818 | return (Return ? RetCC_ARM_AAPCS_VFP: CC_ARM_AAPCS_VFP); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 819 | case CallingConv::ARM_AAPCS: |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 820 | return (Return ? RetCC_ARM_AAPCS: CC_ARM_AAPCS); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 821 | case CallingConv::ARM_APCS: |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 822 | return (Return ? RetCC_ARM_APCS: CC_ARM_APCS); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 823 | } |
| 824 | } |
| 825 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 826 | /// LowerCallResult - Lower the result values of a call into the |
| 827 | /// appropriate copies out of appropriate physical registers. |
| 828 | SDValue |
| 829 | ARMTargetLowering::LowerCallResult(SDValue Chain, SDValue InFlag, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 830 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 831 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 832 | DebugLoc dl, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 833 | SmallVectorImpl<SDValue> &InVals) const { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 834 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 835 | // Assign locations to each value returned by this call. |
| 836 | SmallVector<CCValAssign, 16> RVLocs; |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 837 | CCState CCInfo(CallConv, isVarArg, getTargetMachine(), |
Owen Anderson | e922c02 | 2009-07-22 00:24:57 +0000 | [diff] [blame] | 838 | RVLocs, *DAG.getContext()); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 839 | CCInfo.AnalyzeCallResult(Ins, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 840 | CCAssignFnForNode(CallConv, /* Return*/ true, |
| 841 | isVarArg)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 842 | |
| 843 | // Copy all of the result registers out of their specified physreg. |
| 844 | for (unsigned i = 0; i != RVLocs.size(); ++i) { |
| 845 | CCValAssign VA = RVLocs[i]; |
| 846 | |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 847 | SDValue Val; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 848 | if (VA.needsCustom()) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 849 | // Handle f64 or half of a v2f64. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 850 | SDValue Lo = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 851 | InFlag); |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 852 | Chain = Lo.getValue(1); |
| 853 | InFlag = Lo.getValue(2); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 854 | VA = RVLocs[++i]; // skip ahead to next loc |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 855 | SDValue Hi = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 856 | InFlag); |
| 857 | Chain = Hi.getValue(1); |
| 858 | InFlag = Hi.getValue(2); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 859 | Val = DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 860 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 861 | if (VA.getLocVT() == MVT::v2f64) { |
| 862 | SDValue Vec = DAG.getNode(ISD::UNDEF, dl, MVT::v2f64); |
| 863 | Vec = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Vec, Val, |
| 864 | DAG.getConstant(0, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 865 | |
| 866 | VA = RVLocs[++i]; // skip ahead to next loc |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 867 | Lo = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, InFlag); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 868 | Chain = Lo.getValue(1); |
| 869 | InFlag = Lo.getValue(2); |
| 870 | VA = RVLocs[++i]; // skip ahead to next loc |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 871 | Hi = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, InFlag); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 872 | Chain = Hi.getValue(1); |
| 873 | InFlag = Hi.getValue(2); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 874 | Val = DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 875 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Vec, Val, |
| 876 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 877 | } |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 878 | } else { |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 879 | Val = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), VA.getLocVT(), |
| 880 | InFlag); |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 881 | Chain = Val.getValue(1); |
| 882 | InFlag = Val.getValue(2); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 883 | } |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 884 | |
| 885 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 886 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 887 | case CCValAssign::Full: break; |
| 888 | case CCValAssign::BCvt: |
| 889 | Val = DAG.getNode(ISD::BIT_CONVERT, dl, VA.getValVT(), Val); |
| 890 | break; |
| 891 | } |
| 892 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 893 | InVals.push_back(Val); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 894 | } |
| 895 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 896 | return Chain; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 897 | } |
| 898 | |
| 899 | /// CreateCopyOfByValArgument - Make a copy of an aggregate at address specified |
| 900 | /// by "Src" to address "Dst" of size "Size". Alignment information is |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 901 | /// specified by the specific parameter attribute. The copy will be passed as |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 902 | /// a byval function parameter. |
| 903 | /// Sometimes what we are copying is the end of a larger object, the part that |
| 904 | /// does not fit in registers. |
| 905 | static SDValue |
| 906 | CreateCopyOfByValArgument(SDValue Src, SDValue Dst, SDValue Chain, |
| 907 | ISD::ArgFlagsTy Flags, SelectionDAG &DAG, |
| 908 | DebugLoc dl) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 909 | SDValue SizeNode = DAG.getConstant(Flags.getByValSize(), MVT::i32); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 910 | return DAG.getMemcpy(Chain, dl, Dst, Src, SizeNode, Flags.getByValAlign(), |
Mon P Wang | 20adc9d | 2010-04-04 03:10:48 +0000 | [diff] [blame] | 911 | /*isVolatile=*/false, /*AlwaysInline=*/false, |
| 912 | NULL, 0, NULL, 0); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 913 | } |
| 914 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 915 | /// LowerMemOpCallTo - Store the argument to the stack. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 916 | SDValue |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 917 | ARMTargetLowering::LowerMemOpCallTo(SDValue Chain, |
| 918 | SDValue StackPtr, SDValue Arg, |
| 919 | DebugLoc dl, SelectionDAG &DAG, |
| 920 | const CCValAssign &VA, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 921 | ISD::ArgFlagsTy Flags) const { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 922 | unsigned LocMemOffset = VA.getLocMemOffset(); |
| 923 | SDValue PtrOff = DAG.getIntPtrConstant(LocMemOffset); |
| 924 | PtrOff = DAG.getNode(ISD::ADD, dl, getPointerTy(), StackPtr, PtrOff); |
| 925 | if (Flags.isByVal()) { |
| 926 | return CreateCopyOfByValArgument(Arg, PtrOff, Chain, Flags, DAG, dl); |
| 927 | } |
| 928 | return DAG.getStore(Chain, dl, Arg, PtrOff, |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 929 | PseudoSourceValue::getStack(), LocMemOffset, |
| 930 | false, false, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 931 | } |
| 932 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 933 | void ARMTargetLowering::PassF64ArgInRegs(DebugLoc dl, SelectionDAG &DAG, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 934 | SDValue Chain, SDValue &Arg, |
| 935 | RegsToPassVector &RegsToPass, |
| 936 | CCValAssign &VA, CCValAssign &NextVA, |
| 937 | SDValue &StackPtr, |
| 938 | SmallVector<SDValue, 8> &MemOpChains, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 939 | ISD::ArgFlagsTy Flags) const { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 940 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 941 | SDValue fmrrd = DAG.getNode(ARMISD::VMOVRRD, dl, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 942 | DAG.getVTList(MVT::i32, MVT::i32), Arg); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 943 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), fmrrd)); |
| 944 | |
| 945 | if (NextVA.isRegLoc()) |
| 946 | RegsToPass.push_back(std::make_pair(NextVA.getLocReg(), fmrrd.getValue(1))); |
| 947 | else { |
| 948 | assert(NextVA.isMemLoc()); |
| 949 | if (StackPtr.getNode() == 0) |
| 950 | StackPtr = DAG.getCopyFromReg(Chain, dl, ARM::SP, getPointerTy()); |
| 951 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 952 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, fmrrd.getValue(1), |
| 953 | dl, DAG, NextVA, |
| 954 | Flags)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 955 | } |
| 956 | } |
| 957 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 958 | /// LowerCall - Lowering a call into a callseq_start <- |
Evan Cheng | fc40342 | 2007-02-03 08:53:01 +0000 | [diff] [blame] | 959 | /// ARMISD:CALL <- callseq_end chain. Also add input and output parameter |
| 960 | /// nodes. |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 961 | SDValue |
Evan Cheng | 022d9e1 | 2010-02-02 23:55:14 +0000 | [diff] [blame] | 962 | ARMTargetLowering::LowerCall(SDValue Chain, SDValue Callee, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 963 | CallingConv::ID CallConv, bool isVarArg, |
Evan Cheng | 0c439eb | 2010-01-27 00:07:07 +0000 | [diff] [blame] | 964 | bool &isTailCall, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 965 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
| 966 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 967 | DebugLoc dl, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 968 | SmallVectorImpl<SDValue> &InVals) const { |
Evan Cheng | 0c439eb | 2010-01-27 00:07:07 +0000 | [diff] [blame] | 969 | // ARM target does not yet support tail call optimization. |
| 970 | isTailCall = false; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 971 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 972 | // Analyze operands of the call, assigning locations to each operand. |
| 973 | SmallVector<CCValAssign, 16> ArgLocs; |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 974 | CCState CCInfo(CallConv, isVarArg, getTargetMachine(), ArgLocs, |
| 975 | *DAG.getContext()); |
| 976 | CCInfo.AnalyzeCallOperands(Outs, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 977 | CCAssignFnForNode(CallConv, /* Return*/ false, |
| 978 | isVarArg)); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 979 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 980 | // Get a count of how many bytes are to be pushed on the stack. |
| 981 | unsigned NumBytes = CCInfo.getNextStackOffset(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 982 | |
| 983 | // Adjust the stack pointer for the new arguments... |
| 984 | // These operations are automatically eliminated by the prolog/epilog pass |
Chris Lattner | e563bbc | 2008-10-11 22:08:30 +0000 | [diff] [blame] | 985 | Chain = DAG.getCALLSEQ_START(Chain, DAG.getIntPtrConstant(NumBytes, true)); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 986 | |
Jim Grosbach | f9a4b76 | 2010-02-24 01:43:03 +0000 | [diff] [blame] | 987 | SDValue StackPtr = DAG.getCopyFromReg(Chain, dl, ARM::SP, getPointerTy()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 988 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 989 | RegsToPassVector RegsToPass; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 990 | SmallVector<SDValue, 8> MemOpChains; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 991 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 992 | // Walk the register/memloc assignments, inserting copies/loads. In the case |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 993 | // of tail call optimization, arguments are handled later. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 994 | for (unsigned i = 0, realArgIdx = 0, e = ArgLocs.size(); |
| 995 | i != e; |
| 996 | ++i, ++realArgIdx) { |
| 997 | CCValAssign &VA = ArgLocs[i]; |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 998 | SDValue Arg = Outs[realArgIdx].Val; |
| 999 | ISD::ArgFlagsTy Flags = Outs[realArgIdx].Flags; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1000 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1001 | // Promote the value if needed. |
| 1002 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1003 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1004 | case CCValAssign::Full: break; |
| 1005 | case CCValAssign::SExt: |
| 1006 | Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg); |
| 1007 | break; |
| 1008 | case CCValAssign::ZExt: |
| 1009 | Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg); |
| 1010 | break; |
| 1011 | case CCValAssign::AExt: |
| 1012 | Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg); |
| 1013 | break; |
| 1014 | case CCValAssign::BCvt: |
| 1015 | Arg = DAG.getNode(ISD::BIT_CONVERT, dl, VA.getLocVT(), Arg); |
| 1016 | break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1017 | } |
| 1018 | |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1019 | // 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] | 1020 | if (VA.needsCustom()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1021 | if (VA.getLocVT() == MVT::v2f64) { |
| 1022 | SDValue Op0 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1023 | DAG.getConstant(0, MVT::i32)); |
| 1024 | SDValue Op1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1025 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1026 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1027 | PassF64ArgInRegs(dl, DAG, Chain, Op0, RegsToPass, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1028 | VA, ArgLocs[++i], StackPtr, MemOpChains, Flags); |
| 1029 | |
| 1030 | VA = ArgLocs[++i]; // skip ahead to next loc |
| 1031 | if (VA.isRegLoc()) { |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1032 | PassF64ArgInRegs(dl, DAG, Chain, Op1, RegsToPass, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1033 | VA, ArgLocs[++i], StackPtr, MemOpChains, Flags); |
| 1034 | } else { |
| 1035 | assert(VA.isMemLoc()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1036 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1037 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, Op1, |
| 1038 | dl, DAG, VA, Flags)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1039 | } |
| 1040 | } else { |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1041 | PassF64ArgInRegs(dl, DAG, Chain, Arg, RegsToPass, VA, ArgLocs[++i], |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1042 | StackPtr, MemOpChains, Flags); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1043 | } |
| 1044 | } else if (VA.isRegLoc()) { |
| 1045 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg)); |
| 1046 | } else { |
| 1047 | assert(VA.isMemLoc()); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1048 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1049 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, Arg, |
| 1050 | dl, DAG, VA, Flags)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1051 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1052 | } |
| 1053 | |
| 1054 | if (!MemOpChains.empty()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1055 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1056 | &MemOpChains[0], MemOpChains.size()); |
| 1057 | |
| 1058 | // Build a sequence of copy-to-reg nodes chained together with token chain |
| 1059 | // and flag operands which copy the outgoing args into the appropriate regs. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1060 | SDValue InFlag; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1061 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1062 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1063 | RegsToPass[i].second, InFlag); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1064 | InFlag = Chain.getValue(1); |
| 1065 | } |
| 1066 | |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1067 | // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every |
| 1068 | // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol |
| 1069 | // node so that legalize doesn't hack it. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1070 | bool isDirect = false; |
| 1071 | bool isARMFunc = false; |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 1072 | bool isLocalARMFunc = false; |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1073 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1074 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1075 | |
| 1076 | if (EnableARMLongCalls) { |
| 1077 | assert (getTargetMachine().getRelocationModel() == Reloc::Static |
| 1078 | && "long-calls with non-static relocation model!"); |
| 1079 | // Handle a global address or an external symbol. If it's not one of |
| 1080 | // those, the target's already in a register, so we don't need to do |
| 1081 | // anything extra. |
| 1082 | if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
Anders Carlsson | 0dbdca5 | 2010-04-15 03:11:28 +0000 | [diff] [blame] | 1083 | const GlobalValue *GV = G->getGlobal(); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1084 | // Create a constant pool entry for the callee address |
| 1085 | unsigned ARMPCLabelIndex = AFI->createConstPoolEntryUId(); |
| 1086 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GV, |
| 1087 | ARMPCLabelIndex, |
| 1088 | ARMCP::CPValue, 0); |
| 1089 | // Get the address of the callee into a register |
| 1090 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
| 1091 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| 1092 | Callee = DAG.getLoad(getPointerTy(), dl, |
| 1093 | DAG.getEntryNode(), CPAddr, |
| 1094 | PseudoSourceValue::getConstantPool(), 0, |
| 1095 | false, false, 0); |
| 1096 | } else if (ExternalSymbolSDNode *S=dyn_cast<ExternalSymbolSDNode>(Callee)) { |
| 1097 | const char *Sym = S->getSymbol(); |
| 1098 | |
| 1099 | // Create a constant pool entry for the callee address |
| 1100 | unsigned ARMPCLabelIndex = AFI->createConstPoolEntryUId(); |
| 1101 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(*DAG.getContext(), |
| 1102 | Sym, ARMPCLabelIndex, 0); |
| 1103 | // Get the address of the callee into a register |
| 1104 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
| 1105 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| 1106 | Callee = DAG.getLoad(getPointerTy(), dl, |
| 1107 | DAG.getEntryNode(), CPAddr, |
| 1108 | PseudoSourceValue::getConstantPool(), 0, |
| 1109 | false, false, 0); |
| 1110 | } |
| 1111 | } else if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 1112 | const GlobalValue *GV = G->getGlobal(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1113 | isDirect = true; |
Chris Lattner | 4fb63d0 | 2009-07-15 04:12:33 +0000 | [diff] [blame] | 1114 | bool isExt = GV->isDeclaration() || GV->isWeakForLinker(); |
Evan Cheng | 970a419 | 2007-01-19 19:28:01 +0000 | [diff] [blame] | 1115 | bool isStub = (isExt && Subtarget->isTargetDarwin()) && |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1116 | getTargetMachine().getRelocationModel() != Reloc::Static; |
| 1117 | isARMFunc = !Subtarget->isThumb() || isStub; |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 1118 | // ARM call to a local ARM function is predicable. |
| 1119 | isLocalARMFunc = !Subtarget->isThumb() && !isExt; |
Evan Cheng | c60e76d | 2007-01-30 20:37:08 +0000 | [diff] [blame] | 1120 | // tBX takes a register source operand. |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 1121 | if (isARMFunc && Subtarget->isThumb1Only() && !Subtarget->hasV5TOps()) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1122 | unsigned ARMPCLabelIndex = AFI->createConstPoolEntryUId(); |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 1123 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GV, |
Jim Grosbach | 3fb2b1e | 2009-09-01 01:57:56 +0000 | [diff] [blame] | 1124 | ARMPCLabelIndex, |
| 1125 | ARMCP::CPValue, 4); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1126 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1127 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1128 | Callee = DAG.getLoad(getPointerTy(), dl, |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1129 | DAG.getEntryNode(), CPAddr, |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1130 | PseudoSourceValue::getConstantPool(), 0, |
| 1131 | false, false, 0); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1132 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1133 | Callee = DAG.getNode(ARMISD::PIC_ADD, dl, |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1134 | getPointerTy(), Callee, PICLabel); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1135 | } else |
Evan Cheng | c60e76d | 2007-01-30 20:37:08 +0000 | [diff] [blame] | 1136 | Callee = DAG.getTargetGlobalAddress(GV, getPointerTy()); |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1137 | } else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1138 | isDirect = true; |
Evan Cheng | 970a419 | 2007-01-19 19:28:01 +0000 | [diff] [blame] | 1139 | bool isStub = Subtarget->isTargetDarwin() && |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1140 | getTargetMachine().getRelocationModel() != Reloc::Static; |
| 1141 | isARMFunc = !Subtarget->isThumb() || isStub; |
Evan Cheng | c60e76d | 2007-01-30 20:37:08 +0000 | [diff] [blame] | 1142 | // tBX takes a register source operand. |
| 1143 | const char *Sym = S->getSymbol(); |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 1144 | if (isARMFunc && Subtarget->isThumb1Only() && !Subtarget->hasV5TOps()) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1145 | unsigned ARMPCLabelIndex = AFI->createConstPoolEntryUId(); |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 1146 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(*DAG.getContext(), |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 1147 | Sym, ARMPCLabelIndex, 4); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1148 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1149 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1150 | Callee = DAG.getLoad(getPointerTy(), dl, |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1151 | DAG.getEntryNode(), CPAddr, |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1152 | PseudoSourceValue::getConstantPool(), 0, |
| 1153 | false, false, 0); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1154 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1155 | Callee = DAG.getNode(ARMISD::PIC_ADD, dl, |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1156 | getPointerTy(), Callee, PICLabel); |
Evan Cheng | c60e76d | 2007-01-30 20:37:08 +0000 | [diff] [blame] | 1157 | } else |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1158 | Callee = DAG.getTargetExternalSymbol(Sym, getPointerTy()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1159 | } |
| 1160 | |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1161 | // FIXME: handle tail calls differently. |
| 1162 | unsigned CallOpc; |
Evan Cheng | b620724 | 2009-08-01 00:16:10 +0000 | [diff] [blame] | 1163 | if (Subtarget->isThumb()) { |
| 1164 | if ((!isDirect || isARMFunc) && !Subtarget->hasV5TOps()) |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1165 | CallOpc = ARMISD::CALL_NOLINK; |
| 1166 | else |
| 1167 | CallOpc = isARMFunc ? ARMISD::CALL : ARMISD::tCALL; |
| 1168 | } else { |
| 1169 | CallOpc = (isDirect || Subtarget->hasV5TOps()) |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 1170 | ? (isLocalARMFunc ? ARMISD::CALL_PRED : ARMISD::CALL) |
| 1171 | : ARMISD::CALL_NOLINK; |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1172 | } |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 1173 | if (CallOpc == ARMISD::CALL_NOLINK && !Subtarget->isThumb1Only()) { |
Lauro Ramos Venancio | b8a93a4 | 2007-03-27 16:19:21 +0000 | [diff] [blame] | 1174 | // implicit def LR - LR mustn't be allocated as GRP:$dst of CALL_NOLINK |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1175 | Chain = DAG.getCopyToReg(Chain, dl, ARM::LR, DAG.getUNDEF(MVT::i32),InFlag); |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1176 | InFlag = Chain.getValue(1); |
| 1177 | } |
| 1178 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1179 | std::vector<SDValue> Ops; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1180 | Ops.push_back(Chain); |
| 1181 | Ops.push_back(Callee); |
| 1182 | |
| 1183 | // Add argument registers to the end of the list so that they are known live |
| 1184 | // into the call. |
| 1185 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) |
| 1186 | Ops.push_back(DAG.getRegister(RegsToPass[i].first, |
| 1187 | RegsToPass[i].second.getValueType())); |
| 1188 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1189 | if (InFlag.getNode()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1190 | Ops.push_back(InFlag); |
Duncan Sands | 4bdcb61 | 2008-07-02 17:40:58 +0000 | [diff] [blame] | 1191 | // Returns a chain and a flag for retval copy to use. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1192 | Chain = DAG.getNode(CallOpc, dl, DAG.getVTList(MVT::Other, MVT::Flag), |
Duncan Sands | 4bdcb61 | 2008-07-02 17:40:58 +0000 | [diff] [blame] | 1193 | &Ops[0], Ops.size()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1194 | InFlag = Chain.getValue(1); |
| 1195 | |
Chris Lattner | e563bbc | 2008-10-11 22:08:30 +0000 | [diff] [blame] | 1196 | Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(NumBytes, true), |
| 1197 | DAG.getIntPtrConstant(0, true), InFlag); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1198 | if (!Ins.empty()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1199 | InFlag = Chain.getValue(1); |
| 1200 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1201 | // Handle result values, copying them out of physregs into vregs that we |
| 1202 | // return. |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1203 | return LowerCallResult(Chain, InFlag, CallConv, isVarArg, Ins, |
| 1204 | dl, DAG, InVals); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1205 | } |
| 1206 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1207 | SDValue |
| 1208 | ARMTargetLowering::LowerReturn(SDValue Chain, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1209 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1210 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1211 | DebugLoc dl, SelectionDAG &DAG) const { |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1212 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1213 | // CCValAssign - represent the assignment of the return value to a location. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1214 | SmallVector<CCValAssign, 16> RVLocs; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1215 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1216 | // CCState - Info about the registers and stack slots. |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1217 | CCState CCInfo(CallConv, isVarArg, getTargetMachine(), RVLocs, |
| 1218 | *DAG.getContext()); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1219 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1220 | // Analyze outgoing return values. |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1221 | CCInfo.AnalyzeReturn(Outs, CCAssignFnForNode(CallConv, /* Return */ true, |
| 1222 | isVarArg)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1223 | |
| 1224 | // If this is the first return lowered for this function, add |
| 1225 | // the regs to the liveout set for the function. |
| 1226 | if (DAG.getMachineFunction().getRegInfo().liveout_empty()) { |
| 1227 | for (unsigned i = 0; i != RVLocs.size(); ++i) |
| 1228 | if (RVLocs[i].isRegLoc()) |
| 1229 | DAG.getMachineFunction().getRegInfo().addLiveOut(RVLocs[i].getLocReg()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1230 | } |
| 1231 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1232 | SDValue Flag; |
| 1233 | |
| 1234 | // Copy the result values into the output registers. |
| 1235 | for (unsigned i = 0, realRVLocIdx = 0; |
| 1236 | i != RVLocs.size(); |
| 1237 | ++i, ++realRVLocIdx) { |
| 1238 | CCValAssign &VA = RVLocs[i]; |
| 1239 | assert(VA.isRegLoc() && "Can only return in registers!"); |
| 1240 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1241 | SDValue Arg = Outs[realRVLocIdx].Val; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1242 | |
| 1243 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1244 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1245 | case CCValAssign::Full: break; |
| 1246 | case CCValAssign::BCvt: |
| 1247 | Arg = DAG.getNode(ISD::BIT_CONVERT, dl, VA.getLocVT(), Arg); |
| 1248 | break; |
| 1249 | } |
| 1250 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1251 | if (VA.needsCustom()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1252 | if (VA.getLocVT() == MVT::v2f64) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1253 | // Extract the first half and return it in two registers. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1254 | SDValue Half = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1255 | DAG.getConstant(0, MVT::i32)); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1256 | SDValue HalfGPRs = DAG.getNode(ARMISD::VMOVRRD, dl, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1257 | DAG.getVTList(MVT::i32, MVT::i32), Half); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1258 | |
| 1259 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), HalfGPRs, Flag); |
| 1260 | Flag = Chain.getValue(1); |
| 1261 | VA = RVLocs[++i]; // skip ahead to next loc |
| 1262 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), |
| 1263 | HalfGPRs.getValue(1), Flag); |
| 1264 | Flag = Chain.getValue(1); |
| 1265 | VA = RVLocs[++i]; // skip ahead to next loc |
| 1266 | |
| 1267 | // 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] | 1268 | Arg = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1269 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1270 | } |
| 1271 | // Legalize ret f64 -> ret 2 x i32. We always have fmrrd if f64 is |
| 1272 | // available. |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1273 | SDValue fmrrd = DAG.getNode(ARMISD::VMOVRRD, dl, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1274 | DAG.getVTList(MVT::i32, MVT::i32), &Arg, 1); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1275 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), fmrrd, Flag); |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1276 | Flag = Chain.getValue(1); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1277 | VA = RVLocs[++i]; // skip ahead to next loc |
| 1278 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), fmrrd.getValue(1), |
| 1279 | Flag); |
| 1280 | } else |
| 1281 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), Arg, Flag); |
| 1282 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1283 | // Guarantee that all emitted copies are |
| 1284 | // stuck together, avoiding something bad. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1285 | Flag = Chain.getValue(1); |
| 1286 | } |
| 1287 | |
| 1288 | SDValue result; |
| 1289 | if (Flag.getNode()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1290 | result = DAG.getNode(ARMISD::RET_FLAG, dl, MVT::Other, Chain, Flag); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1291 | else // Return Void |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1292 | result = DAG.getNode(ARMISD::RET_FLAG, dl, MVT::Other, Chain); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1293 | |
| 1294 | return result; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1295 | } |
| 1296 | |
Bob Wilson | b62d257 | 2009-11-03 00:02:05 +0000 | [diff] [blame] | 1297 | // ConstantPool, JumpTable, GlobalAddress, and ExternalSymbol are lowered as |
| 1298 | // their target counterpart wrapped in the ARMISD::Wrapper node. Suppose N is |
| 1299 | // one of the above mentioned nodes. It has to be wrapped because otherwise |
| 1300 | // Select(N) returns N. So the raw TargetGlobalAddress nodes, etc. can only |
| 1301 | // be used to form addressing mode. These wrapped nodes will be selected |
| 1302 | // into MOVi. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1303 | static SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1304 | EVT PtrVT = Op.getValueType(); |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 1305 | // FIXME there is no actual debug info here |
| 1306 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1307 | ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1308 | SDValue Res; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1309 | if (CP->isMachineConstantPoolEntry()) |
| 1310 | Res = DAG.getTargetConstantPool(CP->getMachineCPVal(), PtrVT, |
| 1311 | CP->getAlignment()); |
| 1312 | else |
| 1313 | Res = DAG.getTargetConstantPool(CP->getConstVal(), PtrVT, |
| 1314 | CP->getAlignment()); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1315 | return DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Res); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1316 | } |
| 1317 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1318 | SDValue ARMTargetLowering::LowerBlockAddress(SDValue Op, |
| 1319 | SelectionDAG &DAG) const { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1320 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1321 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 1322 | unsigned ARMPCLabelIndex = 0; |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 1323 | DebugLoc DL = Op.getDebugLoc(); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 1324 | EVT PtrVT = getPointerTy(); |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 1325 | const BlockAddress *BA = cast<BlockAddressSDNode>(Op)->getBlockAddress(); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 1326 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| 1327 | SDValue CPAddr; |
| 1328 | if (RelocM == Reloc::Static) { |
| 1329 | CPAddr = DAG.getTargetConstantPool(BA, PtrVT, 4); |
| 1330 | } else { |
| 1331 | unsigned PCAdj = Subtarget->isThumb() ? 4 : 8; |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1332 | ARMPCLabelIndex = AFI->createConstPoolEntryUId(); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 1333 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(BA, ARMPCLabelIndex, |
| 1334 | ARMCP::CPBlockAddress, |
| 1335 | PCAdj); |
| 1336 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
| 1337 | } |
| 1338 | CPAddr = DAG.getNode(ARMISD::Wrapper, DL, PtrVT, CPAddr); |
| 1339 | SDValue Result = DAG.getLoad(PtrVT, DL, DAG.getEntryNode(), CPAddr, |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1340 | PseudoSourceValue::getConstantPool(), 0, |
| 1341 | false, false, 0); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 1342 | if (RelocM == Reloc::Static) |
| 1343 | return Result; |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1344 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 1345 | return DAG.getNode(ARMISD::PIC_ADD, DL, PtrVT, Result, PICLabel); |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 1346 | } |
| 1347 | |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1348 | // Lower ISD::GlobalTLSAddress using the "general dynamic" model |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1349 | SDValue |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1350 | ARMTargetLowering::LowerToTLSGeneralDynamicModel(GlobalAddressSDNode *GA, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1351 | SelectionDAG &DAG) const { |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1352 | DebugLoc dl = GA->getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1353 | EVT PtrVT = getPointerTy(); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1354 | unsigned char PCAdj = Subtarget->isThumb() ? 4 : 8; |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1355 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1356 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 1357 | unsigned ARMPCLabelIndex = AFI->createConstPoolEntryUId(); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1358 | ARMConstantPoolValue *CPV = |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 1359 | new ARMConstantPoolValue(GA->getGlobal(), ARMPCLabelIndex, |
Jim Grosbach | 3fb2b1e | 2009-09-01 01:57:56 +0000 | [diff] [blame] | 1360 | ARMCP::CPValue, PCAdj, "tlsgd", true); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1361 | SDValue Argument = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1362 | Argument = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Argument); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1363 | Argument = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Argument, |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1364 | PseudoSourceValue::getConstantPool(), 0, |
| 1365 | false, false, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1366 | SDValue Chain = Argument.getValue(1); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1367 | |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1368 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1369 | Argument = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Argument, PICLabel); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1370 | |
| 1371 | // call __tls_get_addr. |
| 1372 | ArgListTy Args; |
| 1373 | ArgListEntry Entry; |
| 1374 | Entry.Node = Argument; |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 1375 | Entry.Ty = (const Type *) Type::getInt32Ty(*DAG.getContext()); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1376 | Args.push_back(Entry); |
Dale Johannesen | 7d2ad62 | 2009-01-30 23:10:59 +0000 | [diff] [blame] | 1377 | // FIXME: is there useful debug info available here? |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1378 | std::pair<SDValue, SDValue> CallResult = |
Evan Cheng | 59bc060 | 2009-08-14 19:11:20 +0000 | [diff] [blame] | 1379 | LowerCallTo(Chain, (const Type *) Type::getInt32Ty(*DAG.getContext()), |
| 1380 | false, false, false, false, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1381 | 0, CallingConv::C, false, /*isReturnValueUsed=*/true, |
Bill Wendling | 46ada19 | 2010-03-02 01:55:18 +0000 | [diff] [blame] | 1382 | DAG.getExternalSymbol("__tls_get_addr", PtrVT), Args, DAG, dl); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1383 | return CallResult.first; |
| 1384 | } |
| 1385 | |
| 1386 | // Lower ISD::GlobalTLSAddress using the "initial exec" or |
| 1387 | // "local exec" model. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1388 | SDValue |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1389 | ARMTargetLowering::LowerToTLSExecModels(GlobalAddressSDNode *GA, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1390 | SelectionDAG &DAG) const { |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 1391 | const GlobalValue *GV = GA->getGlobal(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1392 | DebugLoc dl = GA->getDebugLoc(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1393 | SDValue Offset; |
| 1394 | SDValue Chain = DAG.getEntryNode(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1395 | EVT PtrVT = getPointerTy(); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1396 | // Get the Thread Pointer |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1397 | SDValue ThreadPointer = DAG.getNode(ARMISD::THREAD_POINTER, dl, PtrVT); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1398 | |
Chris Lattner | 4fb63d0 | 2009-07-15 04:12:33 +0000 | [diff] [blame] | 1399 | if (GV->isDeclaration()) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1400 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1401 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 1402 | unsigned ARMPCLabelIndex = AFI->createConstPoolEntryUId(); |
| 1403 | // Initial exec model. |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1404 | unsigned char PCAdj = Subtarget->isThumb() ? 4 : 8; |
| 1405 | ARMConstantPoolValue *CPV = |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 1406 | new ARMConstantPoolValue(GA->getGlobal(), ARMPCLabelIndex, |
Jim Grosbach | 3fb2b1e | 2009-09-01 01:57:56 +0000 | [diff] [blame] | 1407 | ARMCP::CPValue, PCAdj, "gottpoff", true); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1408 | Offset = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1409 | Offset = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Offset); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1410 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1411 | PseudoSourceValue::getConstantPool(), 0, |
| 1412 | false, false, 0); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1413 | Chain = Offset.getValue(1); |
| 1414 | |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1415 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1416 | Offset = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Offset, PICLabel); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1417 | |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1418 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1419 | PseudoSourceValue::getConstantPool(), 0, |
| 1420 | false, false, 0); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1421 | } else { |
| 1422 | // local exec model |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 1423 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GV, "tpoff"); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1424 | Offset = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1425 | Offset = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Offset); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1426 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1427 | PseudoSourceValue::getConstantPool(), 0, |
| 1428 | false, false, 0); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1429 | } |
| 1430 | |
| 1431 | // The address of the thread local variable is the add of the thread |
| 1432 | // pointer with the offset of the variable. |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1433 | return DAG.getNode(ISD::ADD, dl, PtrVT, ThreadPointer, Offset); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1434 | } |
| 1435 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1436 | SDValue |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1437 | ARMTargetLowering::LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const { |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1438 | // TODO: implement the "local dynamic" model |
| 1439 | assert(Subtarget->isTargetELF() && |
| 1440 | "TLS not implemented for non-ELF targets"); |
| 1441 | GlobalAddressSDNode *GA = cast<GlobalAddressSDNode>(Op); |
| 1442 | // If the relocation model is PIC, use the "General Dynamic" TLS Model, |
| 1443 | // otherwise use the "Local Exec" TLS Model |
| 1444 | if (getTargetMachine().getRelocationModel() == Reloc::PIC_) |
| 1445 | return LowerToTLSGeneralDynamicModel(GA, DAG); |
| 1446 | else |
| 1447 | return LowerToTLSExecModels(GA, DAG); |
| 1448 | } |
| 1449 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1450 | SDValue ARMTargetLowering::LowerGlobalAddressELF(SDValue Op, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1451 | SelectionDAG &DAG) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1452 | EVT PtrVT = getPointerTy(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1453 | DebugLoc dl = Op.getDebugLoc(); |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 1454 | const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 1455 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| 1456 | if (RelocM == Reloc::PIC_) { |
Rafael Espindola | bb46f52 | 2009-01-15 20:18:42 +0000 | [diff] [blame] | 1457 | bool UseGOTOFF = GV->hasLocalLinkage() || GV->hasHiddenVisibility(); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 1458 | ARMConstantPoolValue *CPV = |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 1459 | new ARMConstantPoolValue(GV, UseGOTOFF ? "GOTOFF" : "GOT"); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1460 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1461 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1462 | SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 1463 | CPAddr, |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1464 | PseudoSourceValue::getConstantPool(), 0, |
| 1465 | false, false, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1466 | SDValue Chain = Result.getValue(1); |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 1467 | SDValue GOT = DAG.getGLOBAL_OFFSET_TABLE(PtrVT); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1468 | Result = DAG.getNode(ISD::ADD, dl, PtrVT, Result, GOT); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 1469 | if (!UseGOTOFF) |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 1470 | Result = DAG.getLoad(PtrVT, dl, Chain, Result, |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1471 | PseudoSourceValue::getGOT(), 0, |
| 1472 | false, false, 0); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 1473 | return Result; |
| 1474 | } else { |
Anton Korobeynikov | 5cdc3a9 | 2009-11-24 00:44:37 +0000 | [diff] [blame] | 1475 | // If we have T2 ops, we can materialize the address directly via movt/movw |
| 1476 | // pair. This is always cheaper. |
| 1477 | if (Subtarget->useMovt()) { |
| 1478 | return DAG.getNode(ARMISD::Wrapper, dl, PtrVT, |
| 1479 | DAG.getTargetGlobalAddress(GV, PtrVT)); |
| 1480 | } else { |
| 1481 | SDValue CPAddr = DAG.getTargetConstantPool(GV, PtrVT, 4); |
| 1482 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| 1483 | return DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1484 | PseudoSourceValue::getConstantPool(), 0, |
| 1485 | false, false, 0); |
Anton Korobeynikov | 5cdc3a9 | 2009-11-24 00:44:37 +0000 | [diff] [blame] | 1486 | } |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 1487 | } |
| 1488 | } |
| 1489 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1490 | SDValue ARMTargetLowering::LowerGlobalAddressDarwin(SDValue Op, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1491 | SelectionDAG &DAG) const { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1492 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1493 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 1494 | unsigned ARMPCLabelIndex = 0; |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1495 | EVT PtrVT = getPointerTy(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1496 | DebugLoc dl = Op.getDebugLoc(); |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 1497 | const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1498 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1499 | SDValue CPAddr; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1500 | if (RelocM == Reloc::Static) |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1501 | CPAddr = DAG.getTargetConstantPool(GV, PtrVT, 4); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1502 | else { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1503 | ARMPCLabelIndex = AFI->createConstPoolEntryUId(); |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 1504 | unsigned PCAdj = (RelocM != Reloc::PIC_) ? 0 : (Subtarget->isThumb()?4:8); |
| 1505 | ARMConstantPoolValue *CPV = |
Jim Grosbach | 3fb2b1e | 2009-09-01 01:57:56 +0000 | [diff] [blame] | 1506 | new ARMConstantPoolValue(GV, ARMPCLabelIndex, ARMCP::CPValue, PCAdj); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1507 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1508 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1509 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1510 | |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1511 | SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1512 | PseudoSourceValue::getConstantPool(), 0, |
| 1513 | false, false, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1514 | SDValue Chain = Result.getValue(1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1515 | |
| 1516 | if (RelocM == Reloc::PIC_) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1517 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1518 | Result = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1519 | } |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 1520 | |
Evan Cheng | 63476a8 | 2009-09-03 07:04:02 +0000 | [diff] [blame] | 1521 | if (Subtarget->GVIsIndirectSymbol(GV, RelocM)) |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1522 | Result = DAG.getLoad(PtrVT, dl, Chain, Result, |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1523 | PseudoSourceValue::getGOT(), 0, |
| 1524 | false, false, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1525 | |
| 1526 | return Result; |
| 1527 | } |
| 1528 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1529 | SDValue ARMTargetLowering::LowerGLOBAL_OFFSET_TABLE(SDValue Op, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1530 | SelectionDAG &DAG) const { |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 1531 | assert(Subtarget->isTargetELF() && |
| 1532 | "GLOBAL OFFSET TABLE not implemented for non-ELF targets"); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1533 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1534 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 1535 | unsigned ARMPCLabelIndex = AFI->createConstPoolEntryUId(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1536 | EVT PtrVT = getPointerTy(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1537 | DebugLoc dl = Op.getDebugLoc(); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 1538 | unsigned PCAdj = Subtarget->isThumb() ? 4 : 8; |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 1539 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(*DAG.getContext(), |
| 1540 | "_GLOBAL_OFFSET_TABLE_", |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 1541 | ARMPCLabelIndex, PCAdj); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1542 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1543 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 1544 | SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1545 | PseudoSourceValue::getConstantPool(), 0, |
| 1546 | false, false, 0); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1547 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1548 | return DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 1549 | } |
| 1550 | |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 1551 | SDValue |
Jim Grosbach | 5eb1951 | 2010-05-22 01:06:18 +0000 | [diff] [blame^] | 1552 | ARMTargetLowering::LowerEH_SJLJ_LONGJMP(SDValue Op, SelectionDAG &DAG) const { |
| 1553 | DebugLoc dl = Op.getDebugLoc(); |
| 1554 | return DAG.getNode(ARMISD::EH_SJLJ_LONGJMP, dl, MVT::Other, Op.getOperand(0), |
| 1555 | Op.getOperand(1), DAG.getConstant(0, MVT::i32)); |
| 1556 | } |
| 1557 | |
| 1558 | SDValue |
Jim Grosbach | a87ded2 | 2010-02-08 23:22:00 +0000 | [diff] [blame] | 1559 | ARMTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1560 | const ARMSubtarget *Subtarget) |
| 1561 | const { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1562 | unsigned IntNo = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 1563 | DebugLoc dl = Op.getDebugLoc(); |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 1564 | switch (IntNo) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1565 | default: return SDValue(); // Don't custom lower most intrinsics. |
Bob Wilson | 916afdb | 2009-08-04 00:25:01 +0000 | [diff] [blame] | 1566 | case Intrinsic::arm_thread_pointer: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1567 | EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
Bob Wilson | 916afdb | 2009-08-04 00:25:01 +0000 | [diff] [blame] | 1568 | return DAG.getNode(ARMISD::THREAD_POINTER, dl, PtrVT); |
| 1569 | } |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 1570 | case Intrinsic::eh_sjlj_lsda: { |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 1571 | MachineFunction &MF = DAG.getMachineFunction(); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1572 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 1573 | unsigned ARMPCLabelIndex = AFI->createConstPoolEntryUId(); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 1574 | EVT PtrVT = getPointerTy(); |
| 1575 | DebugLoc dl = Op.getDebugLoc(); |
| 1576 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| 1577 | SDValue CPAddr; |
| 1578 | unsigned PCAdj = (RelocM != Reloc::PIC_) |
| 1579 | ? 0 : (Subtarget->isThumb() ? 4 : 8); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 1580 | ARMConstantPoolValue *CPV = |
Jim Grosbach | 3fb2b1e | 2009-09-01 01:57:56 +0000 | [diff] [blame] | 1581 | new ARMConstantPoolValue(MF.getFunction(), ARMPCLabelIndex, |
| 1582 | ARMCP::CPLSDA, PCAdj); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 1583 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1584 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 1585 | SDValue Result = |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1586 | DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1587 | PseudoSourceValue::getConstantPool(), 0, |
| 1588 | false, false, 0); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 1589 | SDValue Chain = Result.getValue(1); |
| 1590 | |
| 1591 | if (RelocM == Reloc::PIC_) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1592 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 1593 | Result = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
| 1594 | } |
| 1595 | return Result; |
| 1596 | } |
Jim Grosbach | f957012 | 2009-05-14 00:46:35 +0000 | [diff] [blame] | 1597 | case Intrinsic::eh_sjlj_setjmp: |
Jim Grosbach | a87ded2 | 2010-02-08 23:22:00 +0000 | [diff] [blame] | 1598 | SDValue Val = Subtarget->isThumb() ? |
| 1599 | DAG.getCopyFromReg(DAG.getEntryNode(), dl, ARM::SP, MVT::i32) : |
| 1600 | DAG.getConstant(0, MVT::i32); |
| 1601 | return DAG.getNode(ARMISD::EH_SJLJ_SETJMP, dl, MVT::i32, Op.getOperand(1), |
| 1602 | Val); |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 1603 | } |
| 1604 | } |
| 1605 | |
Jim Grosbach | 7c03dbd | 2009-12-14 21:24:16 +0000 | [diff] [blame] | 1606 | static SDValue LowerMEMBARRIER(SDValue Op, SelectionDAG &DAG, |
| 1607 | const ARMSubtarget *Subtarget) { |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 1608 | DebugLoc dl = Op.getDebugLoc(); |
| 1609 | SDValue Op5 = Op.getOperand(5); |
| 1610 | SDValue Res; |
| 1611 | unsigned isDeviceBarrier = cast<ConstantSDNode>(Op5)->getZExtValue(); |
| 1612 | if (isDeviceBarrier) { |
Jim Grosbach | 7c03dbd | 2009-12-14 21:24:16 +0000 | [diff] [blame] | 1613 | if (Subtarget->hasV7Ops()) |
| 1614 | Res = DAG.getNode(ARMISD::SYNCBARRIER, dl, MVT::Other, Op.getOperand(0)); |
| 1615 | else |
| 1616 | Res = DAG.getNode(ARMISD::SYNCBARRIER, dl, MVT::Other, Op.getOperand(0), |
| 1617 | DAG.getConstant(0, MVT::i32)); |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 1618 | } else { |
Jim Grosbach | 7c03dbd | 2009-12-14 21:24:16 +0000 | [diff] [blame] | 1619 | if (Subtarget->hasV7Ops()) |
| 1620 | Res = DAG.getNode(ARMISD::MEMBARRIER, dl, MVT::Other, Op.getOperand(0)); |
| 1621 | else |
| 1622 | Res = DAG.getNode(ARMISD::MEMBARRIER, dl, MVT::Other, Op.getOperand(0), |
| 1623 | DAG.getConstant(0, MVT::i32)); |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 1624 | } |
| 1625 | return Res; |
| 1626 | } |
| 1627 | |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 1628 | static SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) { |
| 1629 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1630 | ARMFunctionInfo *FuncInfo = MF.getInfo<ARMFunctionInfo>(); |
| 1631 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1632 | // vastart just stores the address of the VarArgsFrameIndex slot into the |
| 1633 | // memory location argument. |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1634 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1635 | EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 1636 | SDValue FR = DAG.getFrameIndex(FuncInfo->getVarArgsFrameIndex(), PtrVT); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 1637 | const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue(); |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1638 | return DAG.getStore(Op.getOperand(0), dl, FR, Op.getOperand(1), SV, 0, |
| 1639 | false, false, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1640 | } |
| 1641 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1642 | SDValue |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1643 | ARMTargetLowering::LowerDYNAMIC_STACKALLOC(SDValue Op, |
| 1644 | SelectionDAG &DAG) const { |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 1645 | SDNode *Node = Op.getNode(); |
| 1646 | DebugLoc dl = Node->getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1647 | EVT VT = Node->getValueType(0); |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 1648 | SDValue Chain = Op.getOperand(0); |
| 1649 | SDValue Size = Op.getOperand(1); |
| 1650 | SDValue Align = Op.getOperand(2); |
| 1651 | |
| 1652 | // Chain the dynamic stack allocation so that it doesn't modify the stack |
| 1653 | // pointer when other instructions are using the stack. |
| 1654 | Chain = DAG.getCALLSEQ_START(Chain, DAG.getIntPtrConstant(0, true)); |
| 1655 | |
| 1656 | unsigned AlignVal = cast<ConstantSDNode>(Align)->getZExtValue(); |
| 1657 | unsigned StackAlign = getTargetMachine().getFrameInfo()->getStackAlignment(); |
| 1658 | if (AlignVal > StackAlign) |
| 1659 | // Do this now since selection pass cannot introduce new target |
| 1660 | // independent node. |
| 1661 | Align = DAG.getConstant(-(uint64_t)AlignVal, VT); |
| 1662 | |
| 1663 | // In Thumb1 mode, there isn't a "sub r, sp, r" instruction, we will end up |
| 1664 | // using a "add r, sp, r" instead. Negate the size now so we don't have to |
| 1665 | // do even more horrible hack later. |
| 1666 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1667 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 1668 | if (AFI->isThumb1OnlyFunction()) { |
| 1669 | bool Negate = true; |
| 1670 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(Size); |
| 1671 | if (C) { |
| 1672 | uint32_t Val = C->getZExtValue(); |
| 1673 | if (Val <= 508 && ((Val & 3) == 0)) |
| 1674 | Negate = false; |
| 1675 | } |
| 1676 | if (Negate) |
| 1677 | Size = DAG.getNode(ISD::SUB, dl, VT, DAG.getConstant(0, VT), Size); |
| 1678 | } |
| 1679 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1680 | SDVTList VTList = DAG.getVTList(VT, MVT::Other); |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 1681 | SDValue Ops1[] = { Chain, Size, Align }; |
| 1682 | SDValue Res = DAG.getNode(ARMISD::DYN_ALLOC, dl, VTList, Ops1, 3); |
| 1683 | Chain = Res.getValue(1); |
| 1684 | Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(0, true), |
| 1685 | DAG.getIntPtrConstant(0, true), SDValue()); |
| 1686 | SDValue Ops2[] = { Res, Chain }; |
| 1687 | return DAG.getMergeValues(Ops2, 2, dl); |
| 1688 | } |
| 1689 | |
| 1690 | SDValue |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1691 | ARMTargetLowering::GetF64FormalArgument(CCValAssign &VA, CCValAssign &NextVA, |
| 1692 | SDValue &Root, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1693 | DebugLoc dl) const { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1694 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1695 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 1696 | |
| 1697 | TargetRegisterClass *RC; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 1698 | if (AFI->isThumb1OnlyFunction()) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1699 | RC = ARM::tGPRRegisterClass; |
| 1700 | else |
| 1701 | RC = ARM::GPRRegisterClass; |
| 1702 | |
| 1703 | // Transform the arguments stored in physical registers into virtual ones. |
| 1704 | unsigned Reg = MF.addLiveIn(VA.getLocReg(), RC); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1705 | SDValue ArgValue = DAG.getCopyFromReg(Root, dl, Reg, MVT::i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1706 | |
| 1707 | SDValue ArgValue2; |
| 1708 | if (NextVA.isMemLoc()) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1709 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
Bob Wilson | 6a234f0 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 1710 | int FI = MFI->CreateFixedObject(4, NextVA.getLocMemOffset(), true, false); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1711 | |
| 1712 | // Create load node to retrieve arguments from the stack. |
| 1713 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1714 | ArgValue2 = DAG.getLoad(MVT::i32, dl, Root, FIN, |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1715 | PseudoSourceValue::getFixedStack(FI), 0, |
| 1716 | false, false, 0); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1717 | } else { |
| 1718 | Reg = MF.addLiveIn(NextVA.getLocReg(), RC); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1719 | ArgValue2 = DAG.getCopyFromReg(Root, dl, Reg, MVT::i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1720 | } |
| 1721 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1722 | return DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, ArgValue, ArgValue2); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1723 | } |
| 1724 | |
| 1725 | SDValue |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1726 | ARMTargetLowering::LowerFormalArguments(SDValue Chain, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1727 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1728 | const SmallVectorImpl<ISD::InputArg> |
| 1729 | &Ins, |
| 1730 | DebugLoc dl, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1731 | SmallVectorImpl<SDValue> &InVals) |
| 1732 | const { |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1733 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1734 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1735 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 1736 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1737 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 1738 | |
| 1739 | // Assign locations to all of the incoming arguments. |
| 1740 | SmallVector<CCValAssign, 16> ArgLocs; |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1741 | CCState CCInfo(CallConv, isVarArg, getTargetMachine(), ArgLocs, |
| 1742 | *DAG.getContext()); |
| 1743 | CCInfo.AnalyzeFormalArguments(Ins, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1744 | CCAssignFnForNode(CallConv, /* Return*/ false, |
| 1745 | isVarArg)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1746 | |
| 1747 | SmallVector<SDValue, 16> ArgValues; |
| 1748 | |
| 1749 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| 1750 | CCValAssign &VA = ArgLocs[i]; |
| 1751 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1752 | // Arguments stored in registers. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1753 | if (VA.isRegLoc()) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1754 | EVT RegVT = VA.getLocVT(); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1755 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1756 | SDValue ArgValue; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1757 | if (VA.needsCustom()) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1758 | // f64 and vector types are split up into multiple registers or |
| 1759 | // combinations of registers and stack slots. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1760 | if (VA.getLocVT() == MVT::v2f64) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1761 | SDValue ArgValue1 = GetF64FormalArgument(VA, ArgLocs[++i], |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1762 | Chain, DAG, dl); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1763 | VA = ArgLocs[++i]; // skip ahead to next loc |
Bob Wilson | 6a234f0 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 1764 | SDValue ArgValue2; |
| 1765 | if (VA.isMemLoc()) { |
| 1766 | int FI = MFI->CreateFixedObject(8, VA.getLocMemOffset(), |
| 1767 | true, false); |
| 1768 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
| 1769 | ArgValue2 = DAG.getLoad(MVT::f64, dl, Chain, FIN, |
| 1770 | PseudoSourceValue::getFixedStack(FI), 0, |
| 1771 | false, false, 0); |
| 1772 | } else { |
| 1773 | ArgValue2 = GetF64FormalArgument(VA, ArgLocs[++i], |
| 1774 | Chain, DAG, dl); |
| 1775 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1776 | ArgValue = DAG.getNode(ISD::UNDEF, dl, MVT::v2f64); |
| 1777 | ArgValue = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1778 | ArgValue, ArgValue1, DAG.getIntPtrConstant(0)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1779 | ArgValue = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1780 | ArgValue, ArgValue2, DAG.getIntPtrConstant(1)); |
| 1781 | } else |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1782 | ArgValue = GetF64FormalArgument(VA, ArgLocs[++i], Chain, DAG, dl); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1783 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1784 | } else { |
| 1785 | TargetRegisterClass *RC; |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1786 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1787 | if (RegVT == MVT::f32) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1788 | RC = ARM::SPRRegisterClass; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1789 | else if (RegVT == MVT::f64) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1790 | RC = ARM::DPRRegisterClass; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1791 | else if (RegVT == MVT::v2f64) |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1792 | RC = ARM::QPRRegisterClass; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1793 | else if (RegVT == MVT::i32) |
Anton Korobeynikov | 058c251 | 2009-08-05 20:15:19 +0000 | [diff] [blame] | 1794 | RC = (AFI->isThumb1OnlyFunction() ? |
| 1795 | ARM::tGPRRegisterClass : ARM::GPRRegisterClass); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1796 | else |
Anton Korobeynikov | 058c251 | 2009-08-05 20:15:19 +0000 | [diff] [blame] | 1797 | llvm_unreachable("RegVT not supported by FORMAL_ARGUMENTS Lowering"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1798 | |
| 1799 | // Transform the arguments in physical registers into virtual ones. |
| 1800 | unsigned Reg = MF.addLiveIn(VA.getLocReg(), RC); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1801 | ArgValue = DAG.getCopyFromReg(Chain, dl, Reg, RegVT); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1802 | } |
| 1803 | |
| 1804 | // If this is an 8 or 16-bit value, it is really passed promoted |
| 1805 | // to 32 bits. Insert an assert[sz]ext to capture this, then |
| 1806 | // truncate to the right size. |
| 1807 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1808 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1809 | case CCValAssign::Full: break; |
| 1810 | case CCValAssign::BCvt: |
| 1811 | ArgValue = DAG.getNode(ISD::BIT_CONVERT, dl, VA.getValVT(), ArgValue); |
| 1812 | break; |
| 1813 | case CCValAssign::SExt: |
| 1814 | ArgValue = DAG.getNode(ISD::AssertSext, dl, RegVT, ArgValue, |
| 1815 | DAG.getValueType(VA.getValVT())); |
| 1816 | ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue); |
| 1817 | break; |
| 1818 | case CCValAssign::ZExt: |
| 1819 | ArgValue = DAG.getNode(ISD::AssertZext, dl, RegVT, ArgValue, |
| 1820 | DAG.getValueType(VA.getValVT())); |
| 1821 | ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue); |
| 1822 | break; |
| 1823 | } |
| 1824 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1825 | InVals.push_back(ArgValue); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1826 | |
| 1827 | } else { // VA.isRegLoc() |
| 1828 | |
| 1829 | // sanity check |
| 1830 | assert(VA.isMemLoc()); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1831 | assert(VA.getValVT() != MVT::i64 && "i64 should already be lowered"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1832 | |
| 1833 | unsigned ArgSize = VA.getLocVT().getSizeInBits()/8; |
David Greene | 3f2bf85 | 2009-11-12 20:49:22 +0000 | [diff] [blame] | 1834 | int FI = MFI->CreateFixedObject(ArgSize, VA.getLocMemOffset(), |
| 1835 | true, false); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1836 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1837 | // Create load nodes to retrieve arguments from the stack. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1838 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1839 | InVals.push_back(DAG.getLoad(VA.getValVT(), dl, Chain, FIN, |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1840 | PseudoSourceValue::getFixedStack(FI), 0, |
| 1841 | false, false, 0)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1842 | } |
| 1843 | } |
| 1844 | |
| 1845 | // varargs |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1846 | if (isVarArg) { |
| 1847 | static const unsigned GPRArgRegs[] = { |
| 1848 | ARM::R0, ARM::R1, ARM::R2, ARM::R3 |
| 1849 | }; |
| 1850 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1851 | unsigned NumGPRs = CCInfo.getFirstUnallocated |
| 1852 | (GPRArgRegs, sizeof(GPRArgRegs) / sizeof(GPRArgRegs[0])); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1853 | |
Lauro Ramos Venancio | 600c383 | 2007-02-23 20:32:57 +0000 | [diff] [blame] | 1854 | unsigned Align = MF.getTarget().getFrameInfo()->getStackAlignment(); |
| 1855 | unsigned VARegSize = (4 - NumGPRs) * 4; |
| 1856 | unsigned VARegSaveSize = (VARegSize + Align - 1) & ~(Align - 1); |
Rafael Espindola | c1382b7 | 2009-10-30 14:33:14 +0000 | [diff] [blame] | 1857 | unsigned ArgOffset = CCInfo.getNextStackOffset(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1858 | if (VARegSaveSize) { |
| 1859 | // If this function is vararg, store any remaining integer argument regs |
| 1860 | // to their spots on the stack so that they may be loaded by deferencing |
| 1861 | // the result of va_next. |
| 1862 | AFI->setVarArgsRegSaveSize(VARegSaveSize); |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 1863 | AFI->setVarArgsFrameIndex( |
| 1864 | MFI->CreateFixedObject(VARegSaveSize, |
| 1865 | ArgOffset + VARegSaveSize - VARegSize, |
| 1866 | true, false)); |
| 1867 | SDValue FIN = DAG.getFrameIndex(AFI->getVarArgsFrameIndex(), |
| 1868 | getPointerTy()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1869 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1870 | SmallVector<SDValue, 4> MemOps; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1871 | for (; NumGPRs < 4; ++NumGPRs) { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1872 | TargetRegisterClass *RC; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 1873 | if (AFI->isThumb1OnlyFunction()) |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1874 | RC = ARM::tGPRRegisterClass; |
Jim Grosbach | 30eae3c | 2009-04-07 20:34:09 +0000 | [diff] [blame] | 1875 | else |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1876 | RC = ARM::GPRRegisterClass; |
| 1877 | |
Bob Wilson | 998e125 | 2009-04-20 18:36:57 +0000 | [diff] [blame] | 1878 | unsigned VReg = MF.addLiveIn(GPRArgRegs[NumGPRs], RC); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1879 | SDValue Val = DAG.getCopyFromReg(Chain, dl, VReg, MVT::i32); |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 1880 | SDValue Store = |
| 1881 | DAG.getStore(Val.getValue(1), dl, Val, FIN, |
| 1882 | PseudoSourceValue::getFixedStack(AFI->getVarArgsFrameIndex()), 0, |
| 1883 | false, false, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1884 | MemOps.push_back(Store); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1885 | FIN = DAG.getNode(ISD::ADD, dl, getPointerTy(), FIN, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1886 | DAG.getConstant(4, getPointerTy())); |
| 1887 | } |
| 1888 | if (!MemOps.empty()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1889 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1890 | &MemOps[0], MemOps.size()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1891 | } else |
| 1892 | // This will point to the next argument passed via stack. |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 1893 | AFI->setVarArgsFrameIndex(MFI->CreateFixedObject(4, ArgOffset, |
| 1894 | true, false)); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1895 | } |
| 1896 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1897 | return Chain; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1898 | } |
| 1899 | |
| 1900 | /// isFloatingPointZero - Return true if this is +0.0. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1901 | static bool isFloatingPointZero(SDValue Op) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1902 | if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(Op)) |
Dale Johannesen | eaf0894 | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 1903 | return CFP->getValueAPF().isPosZero(); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1904 | else if (ISD::isEXTLoad(Op.getNode()) || ISD::isNON_EXTLoad(Op.getNode())) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1905 | // Maybe this has already been legalized into the constant pool? |
| 1906 | if (Op.getOperand(1).getOpcode() == ARMISD::Wrapper) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1907 | SDValue WrapperOp = Op.getOperand(1).getOperand(0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1908 | if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(WrapperOp)) |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 1909 | if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CP->getConstVal())) |
Dale Johannesen | eaf0894 | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 1910 | return CFP->getValueAPF().isPosZero(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1911 | } |
| 1912 | } |
| 1913 | return false; |
| 1914 | } |
| 1915 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1916 | /// Returns appropriate ARM CMP (cmp) and corresponding condition code for |
| 1917 | /// the given operands. |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 1918 | SDValue |
| 1919 | ARMTargetLowering::getARMCmp(SDValue LHS, SDValue RHS, ISD::CondCode CC, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1920 | SDValue &ARMCC, SelectionDAG &DAG, |
| 1921 | DebugLoc dl) const { |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1922 | if (ConstantSDNode *RHSC = dyn_cast<ConstantSDNode>(RHS.getNode())) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1923 | unsigned C = RHSC->getZExtValue(); |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 1924 | if (!isLegalICmpImmediate(C)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1925 | // Constant does not fit, try adjusting it by one? |
| 1926 | switch (CC) { |
| 1927 | default: break; |
| 1928 | case ISD::SETLT: |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1929 | case ISD::SETGE: |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 1930 | if (isLegalICmpImmediate(C-1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 1931 | CC = (CC == ISD::SETLT) ? ISD::SETLE : ISD::SETGT; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1932 | RHS = DAG.getConstant(C-1, MVT::i32); |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 1933 | } |
| 1934 | break; |
| 1935 | case ISD::SETULT: |
| 1936 | case ISD::SETUGE: |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 1937 | if (C > 0 && isLegalICmpImmediate(C-1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 1938 | CC = (CC == ISD::SETULT) ? ISD::SETULE : ISD::SETUGT; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1939 | RHS = DAG.getConstant(C-1, MVT::i32); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1940 | } |
| 1941 | break; |
| 1942 | case ISD::SETLE: |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1943 | case ISD::SETGT: |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 1944 | if (isLegalICmpImmediate(C+1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 1945 | CC = (CC == ISD::SETLE) ? ISD::SETLT : ISD::SETGE; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1946 | RHS = DAG.getConstant(C+1, MVT::i32); |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 1947 | } |
| 1948 | break; |
| 1949 | case ISD::SETULE: |
| 1950 | case ISD::SETUGT: |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 1951 | if (C < 0xffffffff && isLegalICmpImmediate(C+1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 1952 | CC = (CC == ISD::SETULE) ? ISD::SETULT : ISD::SETUGE; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1953 | RHS = DAG.getConstant(C+1, MVT::i32); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1954 | } |
| 1955 | break; |
| 1956 | } |
| 1957 | } |
| 1958 | } |
| 1959 | |
| 1960 | ARMCC::CondCodes CondCode = IntCCToARMCC(CC); |
Lauro Ramos Venancio | 9996663 | 2007-04-02 01:30:03 +0000 | [diff] [blame] | 1961 | ARMISD::NodeType CompareType; |
| 1962 | switch (CondCode) { |
| 1963 | default: |
| 1964 | CompareType = ARMISD::CMP; |
| 1965 | break; |
| 1966 | case ARMCC::EQ: |
| 1967 | case ARMCC::NE: |
David Goodwin | c0309b4 | 2009-06-29 15:33:01 +0000 | [diff] [blame] | 1968 | // Uses only Z Flag |
| 1969 | CompareType = ARMISD::CMPZ; |
Lauro Ramos Venancio | 9996663 | 2007-04-02 01:30:03 +0000 | [diff] [blame] | 1970 | break; |
| 1971 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1972 | ARMCC = DAG.getConstant(CondCode, MVT::i32); |
| 1973 | return DAG.getNode(CompareType, dl, MVT::Flag, LHS, RHS); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1974 | } |
| 1975 | |
| 1976 | /// Returns a appropriate VFP CMP (fcmp{s|d}+fmstat) for the given operands. |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1977 | static SDValue getVFPCmp(SDValue LHS, SDValue RHS, SelectionDAG &DAG, |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1978 | DebugLoc dl) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1979 | SDValue Cmp; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1980 | if (!isFloatingPointZero(RHS)) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1981 | Cmp = DAG.getNode(ARMISD::CMPFP, dl, MVT::Flag, LHS, RHS); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1982 | else |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1983 | Cmp = DAG.getNode(ARMISD::CMPFPw0, dl, MVT::Flag, LHS); |
| 1984 | return DAG.getNode(ARMISD::FMSTAT, dl, MVT::Flag, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1985 | } |
| 1986 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1987 | SDValue ARMTargetLowering::LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1988 | EVT VT = Op.getValueType(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1989 | SDValue LHS = Op.getOperand(0); |
| 1990 | SDValue RHS = Op.getOperand(1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1991 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(4))->get(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1992 | SDValue TrueVal = Op.getOperand(2); |
| 1993 | SDValue FalseVal = Op.getOperand(3); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1994 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1995 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1996 | if (LHS.getValueType() == MVT::i32) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1997 | SDValue ARMCC; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1998 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 1999 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMCC, DAG, dl); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2000 | return DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, ARMCC, CCR,Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2001 | } |
| 2002 | |
| 2003 | ARMCC::CondCodes CondCode, CondCode2; |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 2004 | FPCCToARMCC(CC, CondCode, CondCode2); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2005 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2006 | SDValue ARMCC = DAG.getConstant(CondCode, MVT::i32); |
| 2007 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2008 | SDValue Cmp = getVFPCmp(LHS, RHS, DAG, dl); |
| 2009 | SDValue Result = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, |
Evan Cheng | 0e1d379 | 2007-07-05 07:18:20 +0000 | [diff] [blame] | 2010 | ARMCC, CCR, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2011 | if (CondCode2 != ARMCC::AL) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2012 | SDValue ARMCC2 = DAG.getConstant(CondCode2, MVT::i32); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2013 | // FIXME: Needs another CMP because flag can have but one use. |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2014 | SDValue Cmp2 = getVFPCmp(LHS, RHS, DAG, dl); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2015 | Result = DAG.getNode(ARMISD::CMOV, dl, VT, |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2016 | Result, TrueVal, ARMCC2, CCR, Cmp2); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2017 | } |
| 2018 | return Result; |
| 2019 | } |
| 2020 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2021 | SDValue ARMTargetLowering::LowerBR_CC(SDValue Op, SelectionDAG &DAG) const { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2022 | SDValue Chain = Op.getOperand(0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2023 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2024 | SDValue LHS = Op.getOperand(2); |
| 2025 | SDValue RHS = Op.getOperand(3); |
| 2026 | SDValue Dest = Op.getOperand(4); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2027 | DebugLoc dl = Op.getDebugLoc(); |
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 | if (LHS.getValueType() == MVT::i32) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2030 | SDValue ARMCC; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2031 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 2032 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMCC, DAG, dl); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2033 | return DAG.getNode(ARMISD::BRCOND, dl, MVT::Other, |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2034 | Chain, Dest, ARMCC, CCR,Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2035 | } |
| 2036 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2037 | assert(LHS.getValueType() == MVT::f32 || LHS.getValueType() == MVT::f64); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2038 | ARMCC::CondCodes CondCode, CondCode2; |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 2039 | FPCCToARMCC(CC, CondCode, CondCode2); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2040 | |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2041 | SDValue Cmp = getVFPCmp(LHS, RHS, DAG, dl); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2042 | SDValue ARMCC = DAG.getConstant(CondCode, MVT::i32); |
| 2043 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| 2044 | SDVTList VTList = DAG.getVTList(MVT::Other, MVT::Flag); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2045 | SDValue Ops[] = { Chain, Dest, ARMCC, CCR, Cmp }; |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2046 | SDValue Res = DAG.getNode(ARMISD::BRCOND, dl, VTList, Ops, 5); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2047 | if (CondCode2 != ARMCC::AL) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2048 | ARMCC = DAG.getConstant(CondCode2, MVT::i32); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2049 | SDValue Ops[] = { Res, Dest, ARMCC, CCR, Res.getValue(1) }; |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2050 | Res = DAG.getNode(ARMISD::BRCOND, dl, VTList, Ops, 5); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2051 | } |
| 2052 | return Res; |
| 2053 | } |
| 2054 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2055 | SDValue ARMTargetLowering::LowerBR_JT(SDValue Op, SelectionDAG &DAG) const { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2056 | SDValue Chain = Op.getOperand(0); |
| 2057 | SDValue Table = Op.getOperand(1); |
| 2058 | SDValue Index = Op.getOperand(2); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2059 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2060 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2061 | EVT PTy = getPointerTy(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2062 | JumpTableSDNode *JT = cast<JumpTableSDNode>(Table); |
| 2063 | ARMFunctionInfo *AFI = DAG.getMachineFunction().getInfo<ARMFunctionInfo>(); |
Bob Wilson | 3eadf00 | 2009-07-14 18:44:34 +0000 | [diff] [blame] | 2064 | SDValue UId = DAG.getConstant(AFI->createJumpTableUId(), PTy); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2065 | SDValue JTI = DAG.getTargetJumpTable(JT->getIndex(), PTy); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2066 | Table = DAG.getNode(ARMISD::WrapperJT, dl, MVT::i32, JTI, UId); |
Evan Cheng | e7c329b | 2009-07-28 20:53:24 +0000 | [diff] [blame] | 2067 | Index = DAG.getNode(ISD::MUL, dl, PTy, Index, DAG.getConstant(4, PTy)); |
| 2068 | SDValue Addr = DAG.getNode(ISD::ADD, dl, PTy, Index, Table); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 2069 | if (Subtarget->isThumb2()) { |
| 2070 | // Thumb2 uses a two-level jump. That is, it jumps into the jump table |
| 2071 | // which does another jump to the destination. This also makes it easier |
| 2072 | // to translate it to TBB / TBH later. |
| 2073 | // FIXME: This might not work if the function is extremely large. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2074 | return DAG.getNode(ARMISD::BR2_JT, dl, MVT::Other, Chain, |
Evan Cheng | 5657c01 | 2009-07-29 02:18:14 +0000 | [diff] [blame] | 2075 | Addr, Op.getOperand(2), JTI, UId); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 2076 | } |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 2077 | if (getTargetMachine().getRelocationModel() == Reloc::PIC_) { |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2078 | Addr = DAG.getLoad((EVT)MVT::i32, dl, Chain, Addr, |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 2079 | PseudoSourceValue::getJumpTable(), 0, |
| 2080 | false, false, 0); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 2081 | Chain = Addr.getValue(1); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2082 | Addr = DAG.getNode(ISD::ADD, dl, PTy, Addr, Table); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2083 | 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] | 2084 | } else { |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2085 | Addr = DAG.getLoad(PTy, dl, Chain, Addr, |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 2086 | PseudoSourceValue::getJumpTable(), 0, false, false, 0); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 2087 | Chain = Addr.getValue(1); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2088 | 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] | 2089 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2090 | } |
| 2091 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 2092 | static SDValue LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG) { |
| 2093 | DebugLoc dl = Op.getDebugLoc(); |
| 2094 | unsigned Opc; |
| 2095 | |
| 2096 | switch (Op.getOpcode()) { |
| 2097 | default: |
| 2098 | assert(0 && "Invalid opcode!"); |
| 2099 | case ISD::FP_TO_SINT: |
| 2100 | Opc = ARMISD::FTOSI; |
| 2101 | break; |
| 2102 | case ISD::FP_TO_UINT: |
| 2103 | Opc = ARMISD::FTOUI; |
| 2104 | break; |
| 2105 | } |
| 2106 | Op = DAG.getNode(Opc, dl, MVT::f32, Op.getOperand(0)); |
| 2107 | return DAG.getNode(ISD::BIT_CONVERT, dl, MVT::i32, Op); |
| 2108 | } |
| 2109 | |
| 2110 | static SDValue LowerINT_TO_FP(SDValue Op, SelectionDAG &DAG) { |
| 2111 | EVT VT = Op.getValueType(); |
| 2112 | DebugLoc dl = Op.getDebugLoc(); |
| 2113 | unsigned Opc; |
| 2114 | |
| 2115 | switch (Op.getOpcode()) { |
| 2116 | default: |
| 2117 | assert(0 && "Invalid opcode!"); |
| 2118 | case ISD::SINT_TO_FP: |
| 2119 | Opc = ARMISD::SITOF; |
| 2120 | break; |
| 2121 | case ISD::UINT_TO_FP: |
| 2122 | Opc = ARMISD::UITOF; |
| 2123 | break; |
| 2124 | } |
| 2125 | |
| 2126 | Op = DAG.getNode(ISD::BIT_CONVERT, dl, MVT::f32, Op.getOperand(0)); |
| 2127 | return DAG.getNode(Opc, dl, VT, Op); |
| 2128 | } |
| 2129 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2130 | static SDValue LowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2131 | // Implement fcopysign with a fabs and a conditional fneg. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2132 | SDValue Tmp0 = Op.getOperand(0); |
| 2133 | SDValue Tmp1 = Op.getOperand(1); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2134 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2135 | EVT VT = Op.getValueType(); |
| 2136 | EVT SrcVT = Tmp1.getValueType(); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2137 | SDValue AbsVal = DAG.getNode(ISD::FABS, dl, VT, Tmp0); |
| 2138 | SDValue Cmp = getVFPCmp(Tmp1, DAG.getConstantFP(0.0, SrcVT), DAG, dl); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2139 | SDValue ARMCC = DAG.getConstant(ARMCC::LT, MVT::i32); |
| 2140 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2141 | return DAG.getNode(ARMISD::CNEG, dl, VT, AbsVal, AbsVal, ARMCC, CCR, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2142 | } |
| 2143 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2144 | SDValue ARMTargetLowering::LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const { |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 2145 | MachineFrameInfo *MFI = DAG.getMachineFunction().getFrameInfo(); |
| 2146 | MFI->setFrameAddressIsTaken(true); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2147 | EVT VT = Op.getValueType(); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 2148 | DebugLoc dl = Op.getDebugLoc(); // FIXME probably not meaningful |
| 2149 | unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
Evan Cheng | cd82861 | 2009-06-18 23:14:30 +0000 | [diff] [blame] | 2150 | unsigned FrameReg = (Subtarget->isThumb() || Subtarget->isTargetDarwin()) |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 2151 | ? ARM::R7 : ARM::R11; |
| 2152 | SDValue FrameAddr = DAG.getCopyFromReg(DAG.getEntryNode(), dl, FrameReg, VT); |
| 2153 | while (Depth--) |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 2154 | FrameAddr = DAG.getLoad(VT, dl, DAG.getEntryNode(), FrameAddr, NULL, 0, |
| 2155 | false, false, 0); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 2156 | return FrameAddr; |
| 2157 | } |
| 2158 | |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 2159 | /// ExpandBIT_CONVERT - If the target supports VFP, this function is called to |
| 2160 | /// expand a bit convert where either the source or destination type is i64 to |
| 2161 | /// use a VMOVDRR or VMOVRRD node. This should not be done when the non-i64 |
| 2162 | /// operand type is illegal (e.g., v2f32 for a target that doesn't support |
| 2163 | /// vectors), since the legalizer won't know what to do with that. |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 2164 | static SDValue ExpandBIT_CONVERT(SDNode *N, SelectionDAG &DAG) { |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 2165 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 2166 | DebugLoc dl = N->getDebugLoc(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2167 | SDValue Op = N->getOperand(0); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 2168 | |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 2169 | // This function is only supposed to be called for i64 types, either as the |
| 2170 | // source or destination of the bit convert. |
| 2171 | EVT SrcVT = Op.getValueType(); |
| 2172 | EVT DstVT = N->getValueType(0); |
| 2173 | assert((SrcVT == MVT::i64 || DstVT == MVT::i64) && |
| 2174 | "ExpandBIT_CONVERT called for non-i64 type"); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 2175 | |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 2176 | // Turn i64->f64 into VMOVDRR. |
| 2177 | if (SrcVT == MVT::i64 && TLI.isTypeLegal(DstVT)) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2178 | SDValue Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Op, |
| 2179 | DAG.getConstant(0, MVT::i32)); |
| 2180 | SDValue Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Op, |
| 2181 | DAG.getConstant(1, MVT::i32)); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 2182 | return DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
Evan Cheng | c7c7729 | 2008-11-04 19:57:48 +0000 | [diff] [blame] | 2183 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2184 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 2185 | // Turn f64->i64 into VMOVRRD. |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 2186 | if (DstVT == MVT::i64 && TLI.isTypeLegal(SrcVT)) { |
| 2187 | SDValue Cvt = DAG.getNode(ARMISD::VMOVRRD, dl, |
| 2188 | DAG.getVTList(MVT::i32, MVT::i32), &Op, 1); |
| 2189 | // Merge the pieces into a single i64 value. |
| 2190 | return DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Cvt, Cvt.getValue(1)); |
| 2191 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2192 | |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 2193 | return SDValue(); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 2194 | } |
| 2195 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2196 | /// getZeroVector - Returns a vector of specified type with all zero elements. |
| 2197 | /// |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2198 | static SDValue getZeroVector(EVT VT, SelectionDAG &DAG, DebugLoc dl) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2199 | assert(VT.isVector() && "Expected a vector type"); |
| 2200 | |
| 2201 | // Zero vectors are used to represent vector negation and in those cases |
| 2202 | // will be implemented with the NEON VNEG instruction. However, VNEG does |
| 2203 | // not support i64 elements, so sometimes the zero vectors will need to be |
| 2204 | // explicitly constructed. For those cases, and potentially other uses in |
Anton Korobeynikov | 2ba62ef | 2009-09-08 22:51:43 +0000 | [diff] [blame] | 2205 | // the future, always build zero vectors as <16 x i8> or <8 x i8> bitcasted |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2206 | // to their dest type. This ensures they get CSE'd. |
| 2207 | SDValue Vec; |
Anton Korobeynikov | 2ba62ef | 2009-09-08 22:51:43 +0000 | [diff] [blame] | 2208 | SDValue Cst = DAG.getTargetConstant(0, MVT::i8); |
| 2209 | SmallVector<SDValue, 8> Ops; |
| 2210 | MVT TVT; |
| 2211 | |
| 2212 | if (VT.getSizeInBits() == 64) { |
| 2213 | Ops.assign(8, Cst); TVT = MVT::v8i8; |
| 2214 | } else { |
| 2215 | Ops.assign(16, Cst); TVT = MVT::v16i8; |
| 2216 | } |
| 2217 | Vec = DAG.getNode(ISD::BUILD_VECTOR, dl, TVT, &Ops[0], Ops.size()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2218 | |
| 2219 | return DAG.getNode(ISD::BIT_CONVERT, dl, VT, Vec); |
| 2220 | } |
| 2221 | |
| 2222 | /// getOnesVector - Returns a vector of specified type with all bits set. |
| 2223 | /// |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2224 | static SDValue getOnesVector(EVT VT, SelectionDAG &DAG, DebugLoc dl) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2225 | assert(VT.isVector() && "Expected a vector type"); |
| 2226 | |
Bob Wilson | 929ffa2 | 2009-10-30 20:13:25 +0000 | [diff] [blame] | 2227 | // Always build ones vectors as <16 x i8> or <8 x i8> bitcasted to their |
Anton Korobeynikov | 2ba62ef | 2009-09-08 22:51:43 +0000 | [diff] [blame] | 2228 | // dest type. This ensures they get CSE'd. |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2229 | SDValue Vec; |
Anton Korobeynikov | 2ba62ef | 2009-09-08 22:51:43 +0000 | [diff] [blame] | 2230 | SDValue Cst = DAG.getTargetConstant(0xFF, MVT::i8); |
| 2231 | SmallVector<SDValue, 8> Ops; |
| 2232 | MVT TVT; |
| 2233 | |
| 2234 | if (VT.getSizeInBits() == 64) { |
| 2235 | Ops.assign(8, Cst); TVT = MVT::v8i8; |
| 2236 | } else { |
| 2237 | Ops.assign(16, Cst); TVT = MVT::v16i8; |
| 2238 | } |
| 2239 | Vec = DAG.getNode(ISD::BUILD_VECTOR, dl, TVT, &Ops[0], Ops.size()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2240 | |
| 2241 | return DAG.getNode(ISD::BIT_CONVERT, dl, VT, Vec); |
| 2242 | } |
| 2243 | |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 2244 | /// LowerShiftRightParts - Lower SRA_PARTS, which returns two |
| 2245 | /// 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] | 2246 | SDValue ARMTargetLowering::LowerShiftRightParts(SDValue Op, |
| 2247 | SelectionDAG &DAG) const { |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 2248 | assert(Op.getNumOperands() == 3 && "Not a double-shift!"); |
| 2249 | EVT VT = Op.getValueType(); |
| 2250 | unsigned VTBits = VT.getSizeInBits(); |
| 2251 | DebugLoc dl = Op.getDebugLoc(); |
| 2252 | SDValue ShOpLo = Op.getOperand(0); |
| 2253 | SDValue ShOpHi = Op.getOperand(1); |
| 2254 | SDValue ShAmt = Op.getOperand(2); |
| 2255 | SDValue ARMCC; |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 2256 | unsigned Opc = (Op.getOpcode() == ISD::SRA_PARTS) ? ISD::SRA : ISD::SRL; |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 2257 | |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 2258 | assert(Op.getOpcode() == ISD::SRA_PARTS || Op.getOpcode() == ISD::SRL_PARTS); |
| 2259 | |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 2260 | SDValue RevShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, |
| 2261 | DAG.getConstant(VTBits, MVT::i32), ShAmt); |
| 2262 | SDValue Tmp1 = DAG.getNode(ISD::SRL, dl, VT, ShOpLo, ShAmt); |
| 2263 | SDValue ExtraShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, ShAmt, |
| 2264 | DAG.getConstant(VTBits, MVT::i32)); |
| 2265 | SDValue Tmp2 = DAG.getNode(ISD::SHL, dl, VT, ShOpHi, RevShAmt); |
| 2266 | SDValue FalseVal = DAG.getNode(ISD::OR, dl, VT, Tmp1, Tmp2); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 2267 | SDValue TrueVal = DAG.getNode(Opc, dl, VT, ShOpHi, ExtraShAmt); |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 2268 | |
| 2269 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| 2270 | SDValue Cmp = getARMCmp(ExtraShAmt, DAG.getConstant(0, MVT::i32), ISD::SETGE, |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 2271 | ARMCC, DAG, dl); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 2272 | SDValue Hi = DAG.getNode(Opc, dl, VT, ShOpHi, ShAmt); |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 2273 | SDValue Lo = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, ARMCC, |
| 2274 | CCR, Cmp); |
| 2275 | |
| 2276 | SDValue Ops[2] = { Lo, Hi }; |
| 2277 | return DAG.getMergeValues(Ops, 2, dl); |
| 2278 | } |
| 2279 | |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 2280 | /// LowerShiftLeftParts - Lower SHL_PARTS, which returns two |
| 2281 | /// 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] | 2282 | SDValue ARMTargetLowering::LowerShiftLeftParts(SDValue Op, |
| 2283 | SelectionDAG &DAG) const { |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 2284 | assert(Op.getNumOperands() == 3 && "Not a double-shift!"); |
| 2285 | EVT VT = Op.getValueType(); |
| 2286 | unsigned VTBits = VT.getSizeInBits(); |
| 2287 | DebugLoc dl = Op.getDebugLoc(); |
| 2288 | SDValue ShOpLo = Op.getOperand(0); |
| 2289 | SDValue ShOpHi = Op.getOperand(1); |
| 2290 | SDValue ShAmt = Op.getOperand(2); |
| 2291 | SDValue ARMCC; |
| 2292 | |
| 2293 | assert(Op.getOpcode() == ISD::SHL_PARTS); |
| 2294 | SDValue RevShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, |
| 2295 | DAG.getConstant(VTBits, MVT::i32), ShAmt); |
| 2296 | SDValue Tmp1 = DAG.getNode(ISD::SRL, dl, VT, ShOpLo, RevShAmt); |
| 2297 | SDValue ExtraShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, ShAmt, |
| 2298 | DAG.getConstant(VTBits, MVT::i32)); |
| 2299 | SDValue Tmp2 = DAG.getNode(ISD::SHL, dl, VT, ShOpHi, ShAmt); |
| 2300 | SDValue Tmp3 = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ExtraShAmt); |
| 2301 | |
| 2302 | SDValue FalseVal = DAG.getNode(ISD::OR, dl, VT, Tmp1, Tmp2); |
| 2303 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| 2304 | SDValue Cmp = getARMCmp(ExtraShAmt, DAG.getConstant(0, MVT::i32), ISD::SETGE, |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 2305 | ARMCC, DAG, dl); |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 2306 | SDValue Lo = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ShAmt); |
| 2307 | SDValue Hi = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, Tmp3, ARMCC, |
| 2308 | CCR, Cmp); |
| 2309 | |
| 2310 | SDValue Ops[2] = { Lo, Hi }; |
| 2311 | return DAG.getMergeValues(Ops, 2, dl); |
| 2312 | } |
| 2313 | |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 2314 | static SDValue LowerCTTZ(SDNode *N, SelectionDAG &DAG, |
| 2315 | const ARMSubtarget *ST) { |
| 2316 | EVT VT = N->getValueType(0); |
| 2317 | DebugLoc dl = N->getDebugLoc(); |
| 2318 | |
| 2319 | if (!ST->hasV6T2Ops()) |
| 2320 | return SDValue(); |
| 2321 | |
| 2322 | SDValue rbit = DAG.getNode(ARMISD::RBIT, dl, VT, N->getOperand(0)); |
| 2323 | return DAG.getNode(ISD::CTLZ, dl, VT, rbit); |
| 2324 | } |
| 2325 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2326 | static SDValue LowerShift(SDNode *N, SelectionDAG &DAG, |
| 2327 | const ARMSubtarget *ST) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2328 | EVT VT = N->getValueType(0); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2329 | DebugLoc dl = N->getDebugLoc(); |
| 2330 | |
| 2331 | // Lower vector shifts on NEON to use VSHL. |
| 2332 | if (VT.isVector()) { |
| 2333 | assert(ST->hasNEON() && "unexpected vector shift"); |
| 2334 | |
| 2335 | // Left shifts translate directly to the vshiftu intrinsic. |
| 2336 | if (N->getOpcode() == ISD::SHL) |
| 2337 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2338 | DAG.getConstant(Intrinsic::arm_neon_vshiftu, MVT::i32), |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2339 | N->getOperand(0), N->getOperand(1)); |
| 2340 | |
| 2341 | assert((N->getOpcode() == ISD::SRA || |
| 2342 | N->getOpcode() == ISD::SRL) && "unexpected vector shift opcode"); |
| 2343 | |
| 2344 | // NEON uses the same intrinsics for both left and right shifts. For |
| 2345 | // right shifts, the shift amounts are negative, so negate the vector of |
| 2346 | // shift amounts. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2347 | EVT ShiftVT = N->getOperand(1).getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2348 | SDValue NegatedCount = DAG.getNode(ISD::SUB, dl, ShiftVT, |
| 2349 | getZeroVector(ShiftVT, DAG, dl), |
| 2350 | N->getOperand(1)); |
| 2351 | Intrinsic::ID vshiftInt = (N->getOpcode() == ISD::SRA ? |
| 2352 | Intrinsic::arm_neon_vshifts : |
| 2353 | Intrinsic::arm_neon_vshiftu); |
| 2354 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2355 | DAG.getConstant(vshiftInt, MVT::i32), |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2356 | N->getOperand(0), NegatedCount); |
| 2357 | } |
| 2358 | |
Eli Friedman | ce392eb | 2009-08-22 03:13:10 +0000 | [diff] [blame] | 2359 | // We can get here for a node like i32 = ISD::SHL i32, i64 |
| 2360 | if (VT != MVT::i64) |
| 2361 | return SDValue(); |
| 2362 | |
| 2363 | assert((N->getOpcode() == ISD::SRL || N->getOpcode() == ISD::SRA) && |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 2364 | "Unknown shift to lower!"); |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 2365 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 2366 | // We only lower SRA, SRL of 1 here, all others use generic lowering. |
| 2367 | if (!isa<ConstantSDNode>(N->getOperand(1)) || |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2368 | cast<ConstantSDNode>(N->getOperand(1))->getZExtValue() != 1) |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 2369 | return SDValue(); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2370 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 2371 | // If we are in thumb mode, we don't have RRX. |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 2372 | if (ST->isThumb1Only()) return SDValue(); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2373 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 2374 | // 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] | 2375 | SDValue Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, N->getOperand(0), |
| 2376 | DAG.getConstant(0, MVT::i32)); |
| 2377 | SDValue Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, N->getOperand(0), |
| 2378 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2379 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 2380 | // First, build a SRA_FLAG/SRL_FLAG op, which shifts the top part by one and |
| 2381 | // captures the result into a carry flag. |
| 2382 | unsigned Opc = N->getOpcode() == ISD::SRL ? ARMISD::SRL_FLAG:ARMISD::SRA_FLAG; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2383 | Hi = DAG.getNode(Opc, dl, DAG.getVTList(MVT::i32, MVT::Flag), &Hi, 1); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2384 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 2385 | // 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] | 2386 | Lo = DAG.getNode(ARMISD::RRX, dl, MVT::i32, Lo, Hi.getValue(1)); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2387 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 2388 | // Merge the pieces into a single i64 value. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2389 | return DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Lo, Hi); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 2390 | } |
| 2391 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2392 | static SDValue LowerVSETCC(SDValue Op, SelectionDAG &DAG) { |
| 2393 | SDValue TmpOp0, TmpOp1; |
| 2394 | bool Invert = false; |
| 2395 | bool Swap = false; |
| 2396 | unsigned Opc = 0; |
| 2397 | |
| 2398 | SDValue Op0 = Op.getOperand(0); |
| 2399 | SDValue Op1 = Op.getOperand(1); |
| 2400 | SDValue CC = Op.getOperand(2); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2401 | EVT VT = Op.getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2402 | ISD::CondCode SetCCOpcode = cast<CondCodeSDNode>(CC)->get(); |
| 2403 | DebugLoc dl = Op.getDebugLoc(); |
| 2404 | |
| 2405 | if (Op.getOperand(1).getValueType().isFloatingPoint()) { |
| 2406 | switch (SetCCOpcode) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 2407 | default: llvm_unreachable("Illegal FP comparison"); break; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2408 | case ISD::SETUNE: |
| 2409 | case ISD::SETNE: Invert = true; // Fallthrough |
| 2410 | case ISD::SETOEQ: |
| 2411 | case ISD::SETEQ: Opc = ARMISD::VCEQ; break; |
| 2412 | case ISD::SETOLT: |
| 2413 | case ISD::SETLT: Swap = true; // Fallthrough |
| 2414 | case ISD::SETOGT: |
| 2415 | case ISD::SETGT: Opc = ARMISD::VCGT; break; |
| 2416 | case ISD::SETOLE: |
| 2417 | case ISD::SETLE: Swap = true; // Fallthrough |
| 2418 | case ISD::SETOGE: |
| 2419 | case ISD::SETGE: Opc = ARMISD::VCGE; break; |
| 2420 | case ISD::SETUGE: Swap = true; // Fallthrough |
| 2421 | case ISD::SETULE: Invert = true; Opc = ARMISD::VCGT; break; |
| 2422 | case ISD::SETUGT: Swap = true; // Fallthrough |
| 2423 | case ISD::SETULT: Invert = true; Opc = ARMISD::VCGE; break; |
| 2424 | case ISD::SETUEQ: Invert = true; // Fallthrough |
| 2425 | case ISD::SETONE: |
| 2426 | // Expand this to (OLT | OGT). |
| 2427 | TmpOp0 = Op0; |
| 2428 | TmpOp1 = Op1; |
| 2429 | Opc = ISD::OR; |
| 2430 | Op0 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp1, TmpOp0); |
| 2431 | Op1 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp0, TmpOp1); |
| 2432 | break; |
| 2433 | case ISD::SETUO: Invert = true; // Fallthrough |
| 2434 | case ISD::SETO: |
| 2435 | // Expand this to (OLT | OGE). |
| 2436 | TmpOp0 = Op0; |
| 2437 | TmpOp1 = Op1; |
| 2438 | Opc = ISD::OR; |
| 2439 | Op0 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp1, TmpOp0); |
| 2440 | Op1 = DAG.getNode(ARMISD::VCGE, dl, VT, TmpOp0, TmpOp1); |
| 2441 | break; |
| 2442 | } |
| 2443 | } else { |
| 2444 | // Integer comparisons. |
| 2445 | switch (SetCCOpcode) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 2446 | default: llvm_unreachable("Illegal integer comparison"); break; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2447 | case ISD::SETNE: Invert = true; |
| 2448 | case ISD::SETEQ: Opc = ARMISD::VCEQ; break; |
| 2449 | case ISD::SETLT: Swap = true; |
| 2450 | case ISD::SETGT: Opc = ARMISD::VCGT; break; |
| 2451 | case ISD::SETLE: Swap = true; |
| 2452 | case ISD::SETGE: Opc = ARMISD::VCGE; break; |
| 2453 | case ISD::SETULT: Swap = true; |
| 2454 | case ISD::SETUGT: Opc = ARMISD::VCGTU; break; |
| 2455 | case ISD::SETULE: Swap = true; |
| 2456 | case ISD::SETUGE: Opc = ARMISD::VCGEU; break; |
| 2457 | } |
| 2458 | |
Nick Lewycky | 7f6aa2b | 2009-07-08 03:04:38 +0000 | [diff] [blame] | 2459 | // Detect VTST (Vector Test Bits) = icmp ne (and (op0, op1), zero). |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2460 | if (Opc == ARMISD::VCEQ) { |
| 2461 | |
| 2462 | SDValue AndOp; |
| 2463 | if (ISD::isBuildVectorAllZeros(Op1.getNode())) |
| 2464 | AndOp = Op0; |
| 2465 | else if (ISD::isBuildVectorAllZeros(Op0.getNode())) |
| 2466 | AndOp = Op1; |
| 2467 | |
| 2468 | // Ignore bitconvert. |
| 2469 | if (AndOp.getNode() && AndOp.getOpcode() == ISD::BIT_CONVERT) |
| 2470 | AndOp = AndOp.getOperand(0); |
| 2471 | |
| 2472 | if (AndOp.getNode() && AndOp.getOpcode() == ISD::AND) { |
| 2473 | Opc = ARMISD::VTST; |
| 2474 | Op0 = DAG.getNode(ISD::BIT_CONVERT, dl, VT, AndOp.getOperand(0)); |
| 2475 | Op1 = DAG.getNode(ISD::BIT_CONVERT, dl, VT, AndOp.getOperand(1)); |
| 2476 | Invert = !Invert; |
| 2477 | } |
| 2478 | } |
| 2479 | } |
| 2480 | |
| 2481 | if (Swap) |
| 2482 | std::swap(Op0, Op1); |
| 2483 | |
| 2484 | SDValue Result = DAG.getNode(Opc, dl, VT, Op0, Op1); |
| 2485 | |
| 2486 | if (Invert) |
| 2487 | Result = DAG.getNOT(dl, Result, VT); |
| 2488 | |
| 2489 | return Result; |
| 2490 | } |
| 2491 | |
| 2492 | /// isVMOVSplat - Check if the specified splat value corresponds to an immediate |
| 2493 | /// VMOV instruction, and if so, return the constant being splatted. |
| 2494 | static SDValue isVMOVSplat(uint64_t SplatBits, uint64_t SplatUndef, |
| 2495 | unsigned SplatBitSize, SelectionDAG &DAG) { |
| 2496 | switch (SplatBitSize) { |
| 2497 | case 8: |
| 2498 | // Any 1-byte value is OK. |
| 2499 | assert((SplatBits & ~0xff) == 0 && "one byte splat value is too big"); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2500 | return DAG.getTargetConstant(SplatBits, MVT::i8); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2501 | |
| 2502 | case 16: |
| 2503 | // NEON's 16-bit VMOV supports splat values where only one byte is nonzero. |
| 2504 | if ((SplatBits & ~0xff) == 0 || |
| 2505 | (SplatBits & ~0xff00) == 0) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2506 | return DAG.getTargetConstant(SplatBits, MVT::i16); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2507 | break; |
| 2508 | |
| 2509 | case 32: |
| 2510 | // NEON's 32-bit VMOV supports splat values where: |
| 2511 | // * only one byte is nonzero, or |
| 2512 | // * the least significant byte is 0xff and the second byte is nonzero, or |
| 2513 | // * the least significant 2 bytes are 0xff and the third is nonzero. |
| 2514 | if ((SplatBits & ~0xff) == 0 || |
| 2515 | (SplatBits & ~0xff00) == 0 || |
| 2516 | (SplatBits & ~0xff0000) == 0 || |
| 2517 | (SplatBits & ~0xff000000) == 0) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2518 | return DAG.getTargetConstant(SplatBits, MVT::i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2519 | |
| 2520 | if ((SplatBits & ~0xffff) == 0 && |
| 2521 | ((SplatBits | SplatUndef) & 0xff) == 0xff) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2522 | return DAG.getTargetConstant(SplatBits | 0xff, MVT::i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2523 | |
| 2524 | if ((SplatBits & ~0xffffff) == 0 && |
| 2525 | ((SplatBits | SplatUndef) & 0xffff) == 0xffff) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2526 | return DAG.getTargetConstant(SplatBits | 0xffff, MVT::i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2527 | |
| 2528 | // Note: there are a few 32-bit splat values (specifically: 00ffff00, |
| 2529 | // ff000000, ff0000ff, and ffff00ff) that are valid for VMOV.I64 but not |
| 2530 | // VMOV.I32. A (very) minor optimization would be to replicate the value |
| 2531 | // and fall through here to test for a valid 64-bit splat. But, then the |
| 2532 | // caller would also need to check and handle the change in size. |
| 2533 | break; |
| 2534 | |
| 2535 | case 64: { |
| 2536 | // NEON has a 64-bit VMOV splat where each byte is either 0 or 0xff. |
| 2537 | uint64_t BitMask = 0xff; |
| 2538 | uint64_t Val = 0; |
| 2539 | for (int ByteNum = 0; ByteNum < 8; ++ByteNum) { |
| 2540 | if (((SplatBits | SplatUndef) & BitMask) == BitMask) |
| 2541 | Val |= BitMask; |
| 2542 | else if ((SplatBits & BitMask) != 0) |
| 2543 | return SDValue(); |
| 2544 | BitMask <<= 8; |
| 2545 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2546 | return DAG.getTargetConstant(Val, MVT::i64); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2547 | } |
| 2548 | |
| 2549 | default: |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 2550 | llvm_unreachable("unexpected size for isVMOVSplat"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2551 | break; |
| 2552 | } |
| 2553 | |
| 2554 | return SDValue(); |
| 2555 | } |
| 2556 | |
| 2557 | /// getVMOVImm - If this is a build_vector of constants which can be |
| 2558 | /// formed by using a VMOV instruction of the specified element size, |
| 2559 | /// return the constant being splatted. The ByteSize field indicates the |
| 2560 | /// number of bytes of each element [1248]. |
| 2561 | SDValue ARM::getVMOVImm(SDNode *N, unsigned ByteSize, SelectionDAG &DAG) { |
| 2562 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(N); |
| 2563 | APInt SplatBits, SplatUndef; |
| 2564 | unsigned SplatBitSize; |
| 2565 | bool HasAnyUndefs; |
| 2566 | if (! BVN || ! BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, |
| 2567 | HasAnyUndefs, ByteSize * 8)) |
| 2568 | return SDValue(); |
| 2569 | |
| 2570 | if (SplatBitSize > ByteSize * 8) |
| 2571 | return SDValue(); |
| 2572 | |
| 2573 | return isVMOVSplat(SplatBits.getZExtValue(), SplatUndef.getZExtValue(), |
| 2574 | SplatBitSize, DAG); |
| 2575 | } |
| 2576 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 2577 | static bool isVEXTMask(const SmallVectorImpl<int> &M, EVT VT, |
| 2578 | bool &ReverseVEXT, unsigned &Imm) { |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 2579 | unsigned NumElts = VT.getVectorNumElements(); |
| 2580 | ReverseVEXT = false; |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 2581 | Imm = M[0]; |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 2582 | |
| 2583 | // If this is a VEXT shuffle, the immediate value is the index of the first |
| 2584 | // element. The other shuffle indices must be the successive elements after |
| 2585 | // the first one. |
| 2586 | unsigned ExpectedElt = Imm; |
| 2587 | for (unsigned i = 1; i < NumElts; ++i) { |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 2588 | // Increment the expected index. If it wraps around, it may still be |
| 2589 | // a VEXT but the source vectors must be swapped. |
| 2590 | ExpectedElt += 1; |
| 2591 | if (ExpectedElt == NumElts * 2) { |
| 2592 | ExpectedElt = 0; |
| 2593 | ReverseVEXT = true; |
| 2594 | } |
| 2595 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 2596 | if (ExpectedElt != static_cast<unsigned>(M[i])) |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 2597 | return false; |
| 2598 | } |
| 2599 | |
| 2600 | // Adjust the index value if the source operands will be swapped. |
| 2601 | if (ReverseVEXT) |
| 2602 | Imm -= NumElts; |
| 2603 | |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 2604 | return true; |
| 2605 | } |
| 2606 | |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 2607 | /// isVREVMask - Check if a vector shuffle corresponds to a VREV |
| 2608 | /// instruction with the specified blocksize. (The order of the elements |
| 2609 | /// within each block of the vector is reversed.) |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 2610 | static bool isVREVMask(const SmallVectorImpl<int> &M, EVT VT, |
| 2611 | unsigned BlockSize) { |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 2612 | assert((BlockSize==16 || BlockSize==32 || BlockSize==64) && |
| 2613 | "Only possible block sizes for VREV are: 16, 32, 64"); |
| 2614 | |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 2615 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 2616 | if (EltSz == 64) |
| 2617 | return false; |
| 2618 | |
| 2619 | unsigned NumElts = VT.getVectorNumElements(); |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 2620 | unsigned BlockElts = M[0] + 1; |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 2621 | |
| 2622 | if (BlockSize <= EltSz || BlockSize != BlockElts * EltSz) |
| 2623 | return false; |
| 2624 | |
| 2625 | for (unsigned i = 0; i < NumElts; ++i) { |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 2626 | if ((unsigned) M[i] != |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 2627 | (i - i%BlockElts) + (BlockElts - 1 - i%BlockElts)) |
| 2628 | return false; |
| 2629 | } |
| 2630 | |
| 2631 | return true; |
| 2632 | } |
| 2633 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 2634 | static bool isVTRNMask(const SmallVectorImpl<int> &M, EVT VT, |
| 2635 | unsigned &WhichResult) { |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 2636 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 2637 | if (EltSz == 64) |
| 2638 | return false; |
| 2639 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 2640 | unsigned NumElts = VT.getVectorNumElements(); |
| 2641 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 2642 | for (unsigned i = 0; i < NumElts; i += 2) { |
| 2643 | if ((unsigned) M[i] != i + WhichResult || |
| 2644 | (unsigned) M[i+1] != i + NumElts + WhichResult) |
| 2645 | return false; |
| 2646 | } |
| 2647 | return true; |
| 2648 | } |
| 2649 | |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 2650 | /// isVTRN_v_undef_Mask - Special case of isVTRNMask for canonical form of |
| 2651 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 2652 | /// Mask is e.g., <0, 0, 2, 2> instead of <0, 4, 2, 6>. |
| 2653 | static bool isVTRN_v_undef_Mask(const SmallVectorImpl<int> &M, EVT VT, |
| 2654 | unsigned &WhichResult) { |
| 2655 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 2656 | if (EltSz == 64) |
| 2657 | return false; |
| 2658 | |
| 2659 | unsigned NumElts = VT.getVectorNumElements(); |
| 2660 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 2661 | for (unsigned i = 0; i < NumElts; i += 2) { |
| 2662 | if ((unsigned) M[i] != i + WhichResult || |
| 2663 | (unsigned) M[i+1] != i + WhichResult) |
| 2664 | return false; |
| 2665 | } |
| 2666 | return true; |
| 2667 | } |
| 2668 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 2669 | static bool isVUZPMask(const SmallVectorImpl<int> &M, EVT VT, |
| 2670 | unsigned &WhichResult) { |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 2671 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 2672 | if (EltSz == 64) |
| 2673 | return false; |
| 2674 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 2675 | unsigned NumElts = VT.getVectorNumElements(); |
| 2676 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 2677 | for (unsigned i = 0; i != NumElts; ++i) { |
| 2678 | if ((unsigned) M[i] != 2 * i + WhichResult) |
| 2679 | return false; |
| 2680 | } |
| 2681 | |
| 2682 | // 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] | 2683 | if (VT.is64BitVector() && EltSz == 32) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 2684 | return false; |
| 2685 | |
| 2686 | return true; |
| 2687 | } |
| 2688 | |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 2689 | /// isVUZP_v_undef_Mask - Special case of isVUZPMask for canonical form of |
| 2690 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 2691 | /// Mask is e.g., <0, 2, 0, 2> instead of <0, 2, 4, 6>, |
| 2692 | static bool isVUZP_v_undef_Mask(const SmallVectorImpl<int> &M, EVT VT, |
| 2693 | unsigned &WhichResult) { |
| 2694 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 2695 | if (EltSz == 64) |
| 2696 | return false; |
| 2697 | |
| 2698 | unsigned Half = VT.getVectorNumElements() / 2; |
| 2699 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 2700 | for (unsigned j = 0; j != 2; ++j) { |
| 2701 | unsigned Idx = WhichResult; |
| 2702 | for (unsigned i = 0; i != Half; ++i) { |
| 2703 | if ((unsigned) M[i + j * Half] != Idx) |
| 2704 | return false; |
| 2705 | Idx += 2; |
| 2706 | } |
| 2707 | } |
| 2708 | |
| 2709 | // VUZP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32. |
| 2710 | if (VT.is64BitVector() && EltSz == 32) |
| 2711 | return false; |
| 2712 | |
| 2713 | return true; |
| 2714 | } |
| 2715 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 2716 | static bool isVZIPMask(const SmallVectorImpl<int> &M, EVT VT, |
| 2717 | unsigned &WhichResult) { |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 2718 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 2719 | if (EltSz == 64) |
| 2720 | return false; |
| 2721 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 2722 | unsigned NumElts = VT.getVectorNumElements(); |
| 2723 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 2724 | unsigned Idx = WhichResult * NumElts / 2; |
| 2725 | for (unsigned i = 0; i != NumElts; i += 2) { |
| 2726 | if ((unsigned) M[i] != Idx || |
| 2727 | (unsigned) M[i+1] != Idx + NumElts) |
| 2728 | return false; |
| 2729 | Idx += 1; |
| 2730 | } |
| 2731 | |
| 2732 | // 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] | 2733 | if (VT.is64BitVector() && EltSz == 32) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 2734 | return false; |
| 2735 | |
| 2736 | return true; |
| 2737 | } |
| 2738 | |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 2739 | /// isVZIP_v_undef_Mask - Special case of isVZIPMask for canonical form of |
| 2740 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 2741 | /// Mask is e.g., <0, 0, 1, 1> instead of <0, 4, 1, 5>. |
| 2742 | static bool isVZIP_v_undef_Mask(const SmallVectorImpl<int> &M, EVT VT, |
| 2743 | unsigned &WhichResult) { |
| 2744 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 2745 | if (EltSz == 64) |
| 2746 | return false; |
| 2747 | |
| 2748 | unsigned NumElts = VT.getVectorNumElements(); |
| 2749 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 2750 | unsigned Idx = WhichResult * NumElts / 2; |
| 2751 | for (unsigned i = 0; i != NumElts; i += 2) { |
| 2752 | if ((unsigned) M[i] != Idx || |
| 2753 | (unsigned) M[i+1] != Idx) |
| 2754 | return false; |
| 2755 | Idx += 1; |
| 2756 | } |
| 2757 | |
| 2758 | // VZIP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32. |
| 2759 | if (VT.is64BitVector() && EltSz == 32) |
| 2760 | return false; |
| 2761 | |
| 2762 | return true; |
| 2763 | } |
| 2764 | |
| 2765 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2766 | static SDValue BuildSplat(SDValue Val, EVT VT, SelectionDAG &DAG, DebugLoc dl) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2767 | // Canonicalize all-zeros and all-ones vectors. |
Bob Wilson | d06791f | 2009-08-13 01:57:47 +0000 | [diff] [blame] | 2768 | ConstantSDNode *ConstVal = cast<ConstantSDNode>(Val.getNode()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2769 | if (ConstVal->isNullValue()) |
| 2770 | return getZeroVector(VT, DAG, dl); |
| 2771 | if (ConstVal->isAllOnesValue()) |
| 2772 | return getOnesVector(VT, DAG, dl); |
| 2773 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2774 | EVT CanonicalVT; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2775 | if (VT.is64BitVector()) { |
| 2776 | switch (Val.getValueType().getSizeInBits()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2777 | case 8: CanonicalVT = MVT::v8i8; break; |
| 2778 | case 16: CanonicalVT = MVT::v4i16; break; |
| 2779 | case 32: CanonicalVT = MVT::v2i32; break; |
| 2780 | case 64: CanonicalVT = MVT::v1i64; break; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 2781 | default: llvm_unreachable("unexpected splat element type"); break; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2782 | } |
| 2783 | } else { |
| 2784 | assert(VT.is128BitVector() && "unknown splat vector size"); |
| 2785 | switch (Val.getValueType().getSizeInBits()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2786 | case 8: CanonicalVT = MVT::v16i8; break; |
| 2787 | case 16: CanonicalVT = MVT::v8i16; break; |
| 2788 | case 32: CanonicalVT = MVT::v4i32; break; |
| 2789 | case 64: CanonicalVT = MVT::v2i64; break; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 2790 | default: llvm_unreachable("unexpected splat element type"); break; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2791 | } |
| 2792 | } |
| 2793 | |
| 2794 | // Build a canonical splat for this value. |
| 2795 | SmallVector<SDValue, 8> Ops; |
| 2796 | Ops.assign(CanonicalVT.getVectorNumElements(), Val); |
| 2797 | SDValue Res = DAG.getNode(ISD::BUILD_VECTOR, dl, CanonicalVT, &Ops[0], |
| 2798 | Ops.size()); |
| 2799 | return DAG.getNode(ISD::BIT_CONVERT, dl, VT, Res); |
| 2800 | } |
| 2801 | |
| 2802 | // If this is a case we can't handle, return null and let the default |
| 2803 | // expansion code take care of it. |
| 2804 | static SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) { |
Bob Wilson | d06791f | 2009-08-13 01:57:47 +0000 | [diff] [blame] | 2805 | BuildVectorSDNode *BVN = cast<BuildVectorSDNode>(Op.getNode()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2806 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2807 | EVT VT = Op.getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2808 | |
| 2809 | APInt SplatBits, SplatUndef; |
| 2810 | unsigned SplatBitSize; |
| 2811 | bool HasAnyUndefs; |
| 2812 | if (BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { |
Anton Korobeynikov | 71624cc | 2009-08-29 00:08:18 +0000 | [diff] [blame] | 2813 | if (SplatBitSize <= 64) { |
| 2814 | SDValue Val = isVMOVSplat(SplatBits.getZExtValue(), |
| 2815 | SplatUndef.getZExtValue(), SplatBitSize, DAG); |
| 2816 | if (Val.getNode()) |
| 2817 | return BuildSplat(Val, VT, DAG, dl); |
| 2818 | } |
Bob Wilson | cf661e2 | 2009-07-30 00:31:25 +0000 | [diff] [blame] | 2819 | } |
| 2820 | |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 2821 | // Scan through the operands to see if only one value is used. |
| 2822 | unsigned NumElts = VT.getVectorNumElements(); |
| 2823 | bool isOnlyLowElement = true; |
| 2824 | bool usesOnlyOneValue = true; |
| 2825 | bool isConstant = true; |
| 2826 | SDValue Value; |
| 2827 | for (unsigned i = 0; i < NumElts; ++i) { |
| 2828 | SDValue V = Op.getOperand(i); |
| 2829 | if (V.getOpcode() == ISD::UNDEF) |
| 2830 | continue; |
| 2831 | if (i > 0) |
| 2832 | isOnlyLowElement = false; |
| 2833 | if (!isa<ConstantFPSDNode>(V) && !isa<ConstantSDNode>(V)) |
| 2834 | isConstant = false; |
| 2835 | |
| 2836 | if (!Value.getNode()) |
| 2837 | Value = V; |
| 2838 | else if (V != Value) |
| 2839 | usesOnlyOneValue = false; |
| 2840 | } |
| 2841 | |
| 2842 | if (!Value.getNode()) |
| 2843 | return DAG.getUNDEF(VT); |
| 2844 | |
| 2845 | if (isOnlyLowElement) |
| 2846 | return DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, VT, Value); |
| 2847 | |
| 2848 | // If all elements are constants, fall back to the default expansion, which |
| 2849 | // will generate a load from the constant pool. |
| 2850 | if (isConstant) |
| 2851 | return SDValue(); |
| 2852 | |
| 2853 | // Use VDUP for non-constant splats. |
| 2854 | if (usesOnlyOneValue) |
| 2855 | return DAG.getNode(ARMISD::VDUP, dl, VT, Value); |
| 2856 | |
| 2857 | // Vectors with 32- or 64-bit elements can be built by directly assigning |
| 2858 | // the subregisters. |
| 2859 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 2860 | if (EltSize >= 32) { |
| 2861 | // Do the expansion with floating-point types, since that is what the VFP |
| 2862 | // registers are defined to use, and since i64 is not legal. |
| 2863 | EVT EltVT = EVT::getFloatingPointVT(EltSize); |
| 2864 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), EltVT, NumElts); |
| 2865 | SDValue Val = DAG.getUNDEF(VecVT); |
| 2866 | for (unsigned i = 0; i < NumElts; ++i) { |
| 2867 | SDValue Elt = Op.getOperand(i); |
| 2868 | if (Elt.getOpcode() == ISD::UNDEF) |
| 2869 | continue; |
| 2870 | Elt = DAG.getNode(ISD::BIT_CONVERT, dl, EltVT, Elt); |
| 2871 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, VecVT, Val, Elt, |
| 2872 | DAG.getConstant(i, MVT::i32)); |
| 2873 | } |
| 2874 | return DAG.getNode(ISD::BIT_CONVERT, dl, VT, Val); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2875 | } |
| 2876 | |
| 2877 | return SDValue(); |
| 2878 | } |
| 2879 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 2880 | /// isShuffleMaskLegal - Targets can use this to indicate that they only |
| 2881 | /// support *some* VECTOR_SHUFFLE operations, those with specific masks. |
| 2882 | /// By default, if a target supports the VECTOR_SHUFFLE node, all mask values |
| 2883 | /// are assumed to be legal. |
| 2884 | bool |
| 2885 | ARMTargetLowering::isShuffleMaskLegal(const SmallVectorImpl<int> &M, |
| 2886 | EVT VT) const { |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 2887 | if (VT.getVectorNumElements() == 4 && |
| 2888 | (VT.is128BitVector() || VT.is64BitVector())) { |
| 2889 | unsigned PFIndexes[4]; |
| 2890 | for (unsigned i = 0; i != 4; ++i) { |
| 2891 | if (M[i] < 0) |
| 2892 | PFIndexes[i] = 8; |
| 2893 | else |
| 2894 | PFIndexes[i] = M[i]; |
| 2895 | } |
| 2896 | |
| 2897 | // Compute the index in the perfect shuffle table. |
| 2898 | unsigned PFTableIndex = |
| 2899 | PFIndexes[0]*9*9*9+PFIndexes[1]*9*9+PFIndexes[2]*9+PFIndexes[3]; |
| 2900 | unsigned PFEntry = PerfectShuffleTable[PFTableIndex]; |
| 2901 | unsigned Cost = (PFEntry >> 30); |
| 2902 | |
| 2903 | if (Cost <= 4) |
| 2904 | return true; |
| 2905 | } |
| 2906 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 2907 | bool ReverseVEXT; |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 2908 | unsigned Imm, WhichResult; |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 2909 | |
| 2910 | return (ShuffleVectorSDNode::isSplatMask(&M[0], VT) || |
| 2911 | isVREVMask(M, VT, 64) || |
| 2912 | isVREVMask(M, VT, 32) || |
| 2913 | isVREVMask(M, VT, 16) || |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 2914 | isVEXTMask(M, VT, ReverseVEXT, Imm) || |
| 2915 | isVTRNMask(M, VT, WhichResult) || |
| 2916 | isVUZPMask(M, VT, WhichResult) || |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 2917 | isVZIPMask(M, VT, WhichResult) || |
| 2918 | isVTRN_v_undef_Mask(M, VT, WhichResult) || |
| 2919 | isVUZP_v_undef_Mask(M, VT, WhichResult) || |
| 2920 | isVZIP_v_undef_Mask(M, VT, WhichResult)); |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 2921 | } |
| 2922 | |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 2923 | /// GeneratePerfectShuffle - Given an entry in the perfect-shuffle table, emit |
| 2924 | /// the specified operations to build the shuffle. |
| 2925 | static SDValue GeneratePerfectShuffle(unsigned PFEntry, SDValue LHS, |
| 2926 | SDValue RHS, SelectionDAG &DAG, |
| 2927 | DebugLoc dl) { |
| 2928 | unsigned OpNum = (PFEntry >> 26) & 0x0F; |
| 2929 | unsigned LHSID = (PFEntry >> 13) & ((1 << 13)-1); |
| 2930 | unsigned RHSID = (PFEntry >> 0) & ((1 << 13)-1); |
| 2931 | |
| 2932 | enum { |
| 2933 | OP_COPY = 0, // Copy, used for things like <u,u,u,3> to say it is <0,1,2,3> |
| 2934 | OP_VREV, |
| 2935 | OP_VDUP0, |
| 2936 | OP_VDUP1, |
| 2937 | OP_VDUP2, |
| 2938 | OP_VDUP3, |
| 2939 | OP_VEXT1, |
| 2940 | OP_VEXT2, |
| 2941 | OP_VEXT3, |
| 2942 | OP_VUZPL, // VUZP, left result |
| 2943 | OP_VUZPR, // VUZP, right result |
| 2944 | OP_VZIPL, // VZIP, left result |
| 2945 | OP_VZIPR, // VZIP, right result |
| 2946 | OP_VTRNL, // VTRN, left result |
| 2947 | OP_VTRNR // VTRN, right result |
| 2948 | }; |
| 2949 | |
| 2950 | if (OpNum == OP_COPY) { |
| 2951 | if (LHSID == (1*9+2)*9+3) return LHS; |
| 2952 | assert(LHSID == ((4*9+5)*9+6)*9+7 && "Illegal OP_COPY!"); |
| 2953 | return RHS; |
| 2954 | } |
| 2955 | |
| 2956 | SDValue OpLHS, OpRHS; |
| 2957 | OpLHS = GeneratePerfectShuffle(PerfectShuffleTable[LHSID], LHS, RHS, DAG, dl); |
| 2958 | OpRHS = GeneratePerfectShuffle(PerfectShuffleTable[RHSID], LHS, RHS, DAG, dl); |
| 2959 | EVT VT = OpLHS.getValueType(); |
| 2960 | |
| 2961 | switch (OpNum) { |
| 2962 | default: llvm_unreachable("Unknown shuffle opcode!"); |
| 2963 | case OP_VREV: |
| 2964 | return DAG.getNode(ARMISD::VREV64, dl, VT, OpLHS); |
| 2965 | case OP_VDUP0: |
| 2966 | case OP_VDUP1: |
| 2967 | case OP_VDUP2: |
| 2968 | case OP_VDUP3: |
| 2969 | return DAG.getNode(ARMISD::VDUPLANE, dl, VT, |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 2970 | OpLHS, DAG.getConstant(OpNum-OP_VDUP0, MVT::i32)); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 2971 | case OP_VEXT1: |
| 2972 | case OP_VEXT2: |
| 2973 | case OP_VEXT3: |
| 2974 | return DAG.getNode(ARMISD::VEXT, dl, VT, |
| 2975 | OpLHS, OpRHS, |
| 2976 | DAG.getConstant(OpNum-OP_VEXT1+1, MVT::i32)); |
| 2977 | case OP_VUZPL: |
| 2978 | case OP_VUZPR: |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 2979 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 2980 | OpLHS, OpRHS).getValue(OpNum-OP_VUZPL); |
| 2981 | case OP_VZIPL: |
| 2982 | case OP_VZIPR: |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 2983 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 2984 | OpLHS, OpRHS).getValue(OpNum-OP_VZIPL); |
| 2985 | case OP_VTRNL: |
| 2986 | case OP_VTRNR: |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 2987 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), |
| 2988 | OpLHS, OpRHS).getValue(OpNum-OP_VTRNL); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 2989 | } |
| 2990 | } |
| 2991 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2992 | static SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) { |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 2993 | SDValue V1 = Op.getOperand(0); |
| 2994 | SDValue V2 = Op.getOperand(1); |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 2995 | DebugLoc dl = Op.getDebugLoc(); |
| 2996 | EVT VT = Op.getValueType(); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 2997 | ShuffleVectorSDNode *SVN = cast<ShuffleVectorSDNode>(Op.getNode()); |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 2998 | SmallVector<int, 8> ShuffleMask; |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 2999 | |
Bob Wilson | 2886506 | 2009-08-13 02:13:04 +0000 | [diff] [blame] | 3000 | // Convert shuffles that are directly supported on NEON to target-specific |
| 3001 | // DAG nodes, instead of keeping them as shuffles and matching them again |
| 3002 | // during code selection. This is more efficient and avoids the possibility |
| 3003 | // of inconsistencies between legalization and selection. |
Bob Wilson | bfcbb50 | 2009-08-13 06:01:30 +0000 | [diff] [blame] | 3004 | // FIXME: floating-point vectors should be canonicalized to integer vectors |
| 3005 | // of the same time so that they get CSEd properly. |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3006 | SVN->getMask(ShuffleMask); |
| 3007 | |
| 3008 | if (ShuffleVectorSDNode::isSplatMask(&ShuffleMask[0], VT)) { |
Bob Wilson | 0ce3710 | 2009-08-14 05:08:32 +0000 | [diff] [blame] | 3009 | int Lane = SVN->getSplatIndex(); |
Anton Korobeynikov | 2ae0eec | 2009-11-02 00:12:06 +0000 | [diff] [blame] | 3010 | // If this is undef splat, generate it via "just" vdup, if possible. |
| 3011 | if (Lane == -1) Lane = 0; |
| 3012 | |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 3013 | if (Lane == 0 && V1.getOpcode() == ISD::SCALAR_TO_VECTOR) { |
| 3014 | return DAG.getNode(ARMISD::VDUP, dl, VT, V1.getOperand(0)); |
Bob Wilson | c1d287b | 2009-08-14 05:13:08 +0000 | [diff] [blame] | 3015 | } |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 3016 | return DAG.getNode(ARMISD::VDUPLANE, dl, VT, V1, |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3017 | DAG.getConstant(Lane, MVT::i32)); |
Bob Wilson | 0ce3710 | 2009-08-14 05:08:32 +0000 | [diff] [blame] | 3018 | } |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3019 | |
| 3020 | bool ReverseVEXT; |
| 3021 | unsigned Imm; |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3022 | if (isVEXTMask(ShuffleMask, VT, ReverseVEXT, Imm)) { |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3023 | if (ReverseVEXT) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3024 | std::swap(V1, V2); |
| 3025 | return DAG.getNode(ARMISD::VEXT, dl, VT, V1, V2, |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3026 | DAG.getConstant(Imm, MVT::i32)); |
| 3027 | } |
| 3028 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3029 | if (isVREVMask(ShuffleMask, VT, 64)) |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 3030 | return DAG.getNode(ARMISD::VREV64, dl, VT, V1); |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3031 | if (isVREVMask(ShuffleMask, VT, 32)) |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 3032 | return DAG.getNode(ARMISD::VREV32, dl, VT, V1); |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3033 | if (isVREVMask(ShuffleMask, VT, 16)) |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 3034 | return DAG.getNode(ARMISD::VREV16, dl, VT, V1); |
| 3035 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3036 | // Check for Neon shuffles that modify both input vectors in place. |
| 3037 | // If both results are used, i.e., if there are two shuffles with the same |
| 3038 | // source operands and with masks corresponding to both results of one of |
| 3039 | // these operations, DAG memoization will ensure that a single node is |
| 3040 | // used for both shuffles. |
| 3041 | unsigned WhichResult; |
| 3042 | if (isVTRNMask(ShuffleMask, VT, WhichResult)) |
| 3043 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), |
| 3044 | V1, V2).getValue(WhichResult); |
| 3045 | if (isVUZPMask(ShuffleMask, VT, WhichResult)) |
| 3046 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), |
| 3047 | V1, V2).getValue(WhichResult); |
| 3048 | if (isVZIPMask(ShuffleMask, VT, WhichResult)) |
| 3049 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), |
| 3050 | V1, V2).getValue(WhichResult); |
| 3051 | |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3052 | if (isVTRN_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 3053 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), |
| 3054 | V1, V1).getValue(WhichResult); |
| 3055 | if (isVUZP_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 3056 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), |
| 3057 | V1, V1).getValue(WhichResult); |
| 3058 | if (isVZIP_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 3059 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), |
| 3060 | V1, V1).getValue(WhichResult); |
| 3061 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3062 | // If the shuffle is not directly supported and it has 4 elements, use |
| 3063 | // the PerfectShuffle-generated table to synthesize it from other shuffles. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 3064 | unsigned NumElts = VT.getVectorNumElements(); |
| 3065 | if (NumElts == 4) { |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 3066 | unsigned PFIndexes[4]; |
| 3067 | for (unsigned i = 0; i != 4; ++i) { |
| 3068 | if (ShuffleMask[i] < 0) |
| 3069 | PFIndexes[i] = 8; |
| 3070 | else |
| 3071 | PFIndexes[i] = ShuffleMask[i]; |
| 3072 | } |
| 3073 | |
| 3074 | // Compute the index in the perfect shuffle table. |
| 3075 | unsigned PFTableIndex = |
| 3076 | 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] | 3077 | unsigned PFEntry = PerfectShuffleTable[PFTableIndex]; |
| 3078 | unsigned Cost = (PFEntry >> 30); |
| 3079 | |
| 3080 | if (Cost <= 4) |
| 3081 | return GeneratePerfectShuffle(PFEntry, V1, V2, DAG, dl); |
| 3082 | } |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 3083 | |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 3084 | // Implement shuffles with 32- or 64-bit elements as subreg copies. |
| 3085 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 3086 | if (EltSize >= 32) { |
| 3087 | // Do the expansion with floating-point types, since that is what the VFP |
| 3088 | // registers are defined to use, and since i64 is not legal. |
| 3089 | EVT EltVT = EVT::getFloatingPointVT(EltSize); |
| 3090 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), EltVT, NumElts); |
| 3091 | V1 = DAG.getNode(ISD::BIT_CONVERT, dl, VecVT, V1); |
| 3092 | V2 = DAG.getNode(ISD::BIT_CONVERT, dl, VecVT, V2); |
| 3093 | SDValue Val = DAG.getUNDEF(VecVT); |
| 3094 | for (unsigned i = 0; i < NumElts; ++i) { |
Bob Wilson | 63b8845 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 3095 | if (ShuffleMask[i] < 0) |
| 3096 | continue; |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 3097 | SDValue Elt = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, EltVT, |
| 3098 | ShuffleMask[i] < (int)NumElts ? V1 : V2, |
| 3099 | DAG.getConstant(ShuffleMask[i] & (NumElts-1), |
| 3100 | MVT::i32)); |
| 3101 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, VecVT, Val, |
Bob Wilson | 63b8845 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 3102 | Elt, DAG.getConstant(i, MVT::i32)); |
| 3103 | } |
| 3104 | return DAG.getNode(ISD::BIT_CONVERT, dl, VT, Val); |
| 3105 | } |
| 3106 | |
Bob Wilson | 22cac0d | 2009-08-14 05:16:33 +0000 | [diff] [blame] | 3107 | return SDValue(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3108 | } |
| 3109 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3110 | static SDValue LowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3111 | EVT VT = Op.getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3112 | DebugLoc dl = Op.getDebugLoc(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3113 | SDValue Vec = Op.getOperand(0); |
| 3114 | SDValue Lane = Op.getOperand(1); |
Bob Wilson | 934f98b | 2009-10-15 23:12:05 +0000 | [diff] [blame] | 3115 | assert(VT == MVT::i32 && |
| 3116 | Vec.getValueType().getVectorElementType().getSizeInBits() < 32 && |
| 3117 | "unexpected type for custom-lowering vector extract"); |
| 3118 | return DAG.getNode(ARMISD::VGETLANEu, dl, MVT::i32, Vec, Lane); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3119 | } |
| 3120 | |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 3121 | static SDValue LowerCONCAT_VECTORS(SDValue Op, SelectionDAG &DAG) { |
| 3122 | // The only time a CONCAT_VECTORS operation can have legal types is when |
| 3123 | // two 64-bit vectors are concatenated to a 128-bit vector. |
| 3124 | assert(Op.getValueType().is128BitVector() && Op.getNumOperands() == 2 && |
| 3125 | "unexpected CONCAT_VECTORS"); |
| 3126 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3127 | SDValue Val = DAG.getUNDEF(MVT::v2f64); |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 3128 | SDValue Op0 = Op.getOperand(0); |
| 3129 | SDValue Op1 = Op.getOperand(1); |
| 3130 | if (Op0.getOpcode() != ISD::UNDEF) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3131 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Val, |
| 3132 | DAG.getNode(ISD::BIT_CONVERT, dl, MVT::f64, Op0), |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 3133 | DAG.getIntPtrConstant(0)); |
| 3134 | if (Op1.getOpcode() != ISD::UNDEF) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3135 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Val, |
| 3136 | DAG.getNode(ISD::BIT_CONVERT, dl, MVT::f64, Op1), |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 3137 | DAG.getIntPtrConstant(1)); |
| 3138 | return DAG.getNode(ISD::BIT_CONVERT, dl, Op.getValueType(), Val); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3139 | } |
| 3140 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 3141 | SDValue ARMTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3142 | switch (Op.getOpcode()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 3143 | default: llvm_unreachable("Don't know how to custom lower this!"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3144 | case ISD::ConstantPool: return LowerConstantPool(Op, DAG); |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 3145 | case ISD::BlockAddress: return LowerBlockAddress(Op, DAG); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 3146 | case ISD::GlobalAddress: |
| 3147 | return Subtarget->isTargetDarwin() ? LowerGlobalAddressDarwin(Op, DAG) : |
| 3148 | LowerGlobalAddressELF(Op, DAG); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 3149 | case ISD::GlobalTLSAddress: return LowerGlobalTLSAddress(Op, DAG); |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 3150 | case ISD::SELECT_CC: return LowerSELECT_CC(Op, DAG); |
| 3151 | case ISD::BR_CC: return LowerBR_CC(Op, DAG); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3152 | case ISD::BR_JT: return LowerBR_JT(Op, DAG); |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 3153 | case ISD::DYNAMIC_STACKALLOC: return LowerDYNAMIC_STACKALLOC(Op, DAG); |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 3154 | case ISD::VASTART: return LowerVASTART(Op, DAG); |
Jim Grosbach | 7c03dbd | 2009-12-14 21:24:16 +0000 | [diff] [blame] | 3155 | case ISD::MEMBARRIER: return LowerMEMBARRIER(Op, DAG, Subtarget); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3156 | case ISD::SINT_TO_FP: |
| 3157 | case ISD::UINT_TO_FP: return LowerINT_TO_FP(Op, DAG); |
| 3158 | case ISD::FP_TO_SINT: |
| 3159 | case ISD::FP_TO_UINT: return LowerFP_TO_INT(Op, DAG); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3160 | case ISD::FCOPYSIGN: return LowerFCOPYSIGN(Op, DAG); |
Nate Begeman | bcc5f36 | 2007-01-29 22:58:52 +0000 | [diff] [blame] | 3161 | case ISD::RETURNADDR: break; |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3162 | case ISD::FRAMEADDR: return LowerFRAMEADDR(Op, DAG); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 3163 | case ISD::GLOBAL_OFFSET_TABLE: return LowerGLOBAL_OFFSET_TABLE(Op, DAG); |
Jim Grosbach | 5eb1951 | 2010-05-22 01:06:18 +0000 | [diff] [blame^] | 3164 | case ISD::EH_SJLJ_LONGJMP: return LowerEH_SJLJ_LONGJMP(Op, DAG); |
Jim Grosbach | a87ded2 | 2010-02-08 23:22:00 +0000 | [diff] [blame] | 3165 | case ISD::INTRINSIC_WO_CHAIN: return LowerINTRINSIC_WO_CHAIN(Op, DAG, |
| 3166 | Subtarget); |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 3167 | case ISD::BIT_CONVERT: return ExpandBIT_CONVERT(Op.getNode(), DAG); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3168 | case ISD::SHL: |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3169 | case ISD::SRL: |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3170 | case ISD::SRA: return LowerShift(Op.getNode(), DAG, Subtarget); |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 3171 | case ISD::SHL_PARTS: return LowerShiftLeftParts(Op, DAG); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 3172 | case ISD::SRL_PARTS: |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 3173 | case ISD::SRA_PARTS: return LowerShiftRightParts(Op, DAG); |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 3174 | case ISD::CTTZ: return LowerCTTZ(Op.getNode(), DAG, Subtarget); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3175 | case ISD::VSETCC: return LowerVSETCC(Op, DAG); |
| 3176 | case ISD::BUILD_VECTOR: return LowerBUILD_VECTOR(Op, DAG); |
| 3177 | case ISD::VECTOR_SHUFFLE: return LowerVECTOR_SHUFFLE(Op, DAG); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3178 | case ISD::EXTRACT_VECTOR_ELT: return LowerEXTRACT_VECTOR_ELT(Op, DAG); |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 3179 | case ISD::CONCAT_VECTORS: return LowerCONCAT_VECTORS(Op, DAG); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3180 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3181 | return SDValue(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3182 | } |
| 3183 | |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 3184 | /// ReplaceNodeResults - Replace the results of node with an illegal result |
| 3185 | /// type with new values built out of custom code. |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 3186 | void ARMTargetLowering::ReplaceNodeResults(SDNode *N, |
| 3187 | SmallVectorImpl<SDValue>&Results, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 3188 | SelectionDAG &DAG) const { |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 3189 | SDValue Res; |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3190 | switch (N->getOpcode()) { |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 3191 | default: |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 3192 | llvm_unreachable("Don't know how to custom expand this!"); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 3193 | break; |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 3194 | case ISD::BIT_CONVERT: |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 3195 | Res = ExpandBIT_CONVERT(N, DAG); |
| 3196 | break; |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3197 | case ISD::SRL: |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 3198 | case ISD::SRA: |
| 3199 | Res = LowerShift(N, DAG, Subtarget); |
| 3200 | break; |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 3201 | } |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 3202 | if (Res.getNode()) |
| 3203 | Results.push_back(Res); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3204 | } |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3205 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3206 | //===----------------------------------------------------------------------===// |
| 3207 | // ARM Scheduler Hooks |
| 3208 | //===----------------------------------------------------------------------===// |
| 3209 | |
| 3210 | MachineBasicBlock * |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 3211 | ARMTargetLowering::EmitAtomicCmpSwap(MachineInstr *MI, |
| 3212 | MachineBasicBlock *BB, |
| 3213 | unsigned Size) const { |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 3214 | unsigned dest = MI->getOperand(0).getReg(); |
| 3215 | unsigned ptr = MI->getOperand(1).getReg(); |
| 3216 | unsigned oldval = MI->getOperand(2).getReg(); |
| 3217 | unsigned newval = MI->getOperand(3).getReg(); |
| 3218 | unsigned scratch = BB->getParent()->getRegInfo() |
| 3219 | .createVirtualRegister(ARM::GPRRegisterClass); |
| 3220 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 3221 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 3222 | bool isThumb2 = Subtarget->isThumb2(); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 3223 | |
| 3224 | unsigned ldrOpc, strOpc; |
| 3225 | switch (Size) { |
| 3226 | default: llvm_unreachable("unsupported size for AtomicCmpSwap!"); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 3227 | case 1: |
| 3228 | ldrOpc = isThumb2 ? ARM::t2LDREXB : ARM::LDREXB; |
| 3229 | strOpc = isThumb2 ? ARM::t2LDREXB : ARM::STREXB; |
| 3230 | break; |
| 3231 | case 2: |
| 3232 | ldrOpc = isThumb2 ? ARM::t2LDREXH : ARM::LDREXH; |
| 3233 | strOpc = isThumb2 ? ARM::t2STREXH : ARM::STREXH; |
| 3234 | break; |
| 3235 | case 4: |
| 3236 | ldrOpc = isThumb2 ? ARM::t2LDREX : ARM::LDREX; |
| 3237 | strOpc = isThumb2 ? ARM::t2STREX : ARM::STREX; |
| 3238 | break; |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 3239 | } |
| 3240 | |
| 3241 | MachineFunction *MF = BB->getParent(); |
| 3242 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 3243 | MachineFunction::iterator It = BB; |
| 3244 | ++It; // insert the new blocks after the current block |
| 3245 | |
| 3246 | MachineBasicBlock *loop1MBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 3247 | MachineBasicBlock *loop2MBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 3248 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 3249 | MF->insert(It, loop1MBB); |
| 3250 | MF->insert(It, loop2MBB); |
| 3251 | MF->insert(It, exitMBB); |
| 3252 | exitMBB->transferSuccessors(BB); |
| 3253 | |
| 3254 | // thisMBB: |
| 3255 | // ... |
| 3256 | // fallthrough --> loop1MBB |
| 3257 | BB->addSuccessor(loop1MBB); |
| 3258 | |
| 3259 | // loop1MBB: |
| 3260 | // ldrex dest, [ptr] |
| 3261 | // cmp dest, oldval |
| 3262 | // bne exitMBB |
| 3263 | BB = loop1MBB; |
| 3264 | AddDefaultPred(BuildMI(BB, dl, TII->get(ldrOpc), dest).addReg(ptr)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 3265 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 3266 | .addReg(dest).addReg(oldval)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 3267 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 3268 | .addMBB(exitMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 3269 | BB->addSuccessor(loop2MBB); |
| 3270 | BB->addSuccessor(exitMBB); |
| 3271 | |
| 3272 | // loop2MBB: |
| 3273 | // strex scratch, newval, [ptr] |
| 3274 | // cmp scratch, #0 |
| 3275 | // bne loop1MBB |
| 3276 | BB = loop2MBB; |
| 3277 | AddDefaultPred(BuildMI(BB, dl, TII->get(strOpc), scratch).addReg(newval) |
| 3278 | .addReg(ptr)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 3279 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 3280 | .addReg(scratch).addImm(0)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 3281 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 3282 | .addMBB(loop1MBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 3283 | BB->addSuccessor(loop1MBB); |
| 3284 | BB->addSuccessor(exitMBB); |
| 3285 | |
| 3286 | // exitMBB: |
| 3287 | // ... |
| 3288 | BB = exitMBB; |
Jim Grosbach | 5efaed3 | 2010-01-15 00:18:34 +0000 | [diff] [blame] | 3289 | |
| 3290 | MF->DeleteMachineInstr(MI); // The instruction is gone now. |
| 3291 | |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 3292 | return BB; |
| 3293 | } |
| 3294 | |
| 3295 | MachineBasicBlock * |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 3296 | ARMTargetLowering::EmitAtomicBinary(MachineInstr *MI, MachineBasicBlock *BB, |
| 3297 | unsigned Size, unsigned BinOpcode) const { |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 3298 | // This also handles ATOMIC_SWAP, indicated by BinOpcode==0. |
| 3299 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 3300 | |
| 3301 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
Jim Grosbach | 867bbbf | 2010-01-15 00:22:18 +0000 | [diff] [blame] | 3302 | MachineFunction *MF = BB->getParent(); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 3303 | MachineFunction::iterator It = BB; |
| 3304 | ++It; |
| 3305 | |
| 3306 | unsigned dest = MI->getOperand(0).getReg(); |
| 3307 | unsigned ptr = MI->getOperand(1).getReg(); |
| 3308 | unsigned incr = MI->getOperand(2).getReg(); |
| 3309 | DebugLoc dl = MI->getDebugLoc(); |
Rafael Espindola | fda60d3 | 2009-12-18 16:59:39 +0000 | [diff] [blame] | 3310 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 3311 | bool isThumb2 = Subtarget->isThumb2(); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 3312 | unsigned ldrOpc, strOpc; |
| 3313 | switch (Size) { |
| 3314 | default: llvm_unreachable("unsupported size for AtomicCmpSwap!"); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 3315 | case 1: |
| 3316 | ldrOpc = isThumb2 ? ARM::t2LDREXB : ARM::LDREXB; |
Jakob Stoklund Olesen | 15913c9 | 2010-01-13 19:54:39 +0000 | [diff] [blame] | 3317 | strOpc = isThumb2 ? ARM::t2STREXB : ARM::STREXB; |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 3318 | break; |
| 3319 | case 2: |
| 3320 | ldrOpc = isThumb2 ? ARM::t2LDREXH : ARM::LDREXH; |
| 3321 | strOpc = isThumb2 ? ARM::t2STREXH : ARM::STREXH; |
| 3322 | break; |
| 3323 | case 4: |
| 3324 | ldrOpc = isThumb2 ? ARM::t2LDREX : ARM::LDREX; |
| 3325 | strOpc = isThumb2 ? ARM::t2STREX : ARM::STREX; |
| 3326 | break; |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 3327 | } |
| 3328 | |
Jim Grosbach | 867bbbf | 2010-01-15 00:22:18 +0000 | [diff] [blame] | 3329 | MachineBasicBlock *loopMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 3330 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 3331 | MF->insert(It, loopMBB); |
| 3332 | MF->insert(It, exitMBB); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 3333 | exitMBB->transferSuccessors(BB); |
| 3334 | |
Jim Grosbach | 867bbbf | 2010-01-15 00:22:18 +0000 | [diff] [blame] | 3335 | MachineRegisterInfo &RegInfo = MF->getRegInfo(); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 3336 | unsigned scratch = RegInfo.createVirtualRegister(ARM::GPRRegisterClass); |
| 3337 | unsigned scratch2 = (!BinOpcode) ? incr : |
| 3338 | RegInfo.createVirtualRegister(ARM::GPRRegisterClass); |
| 3339 | |
| 3340 | // thisMBB: |
| 3341 | // ... |
| 3342 | // fallthrough --> loopMBB |
| 3343 | BB->addSuccessor(loopMBB); |
| 3344 | |
| 3345 | // loopMBB: |
| 3346 | // ldrex dest, ptr |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 3347 | // <binop> scratch2, dest, incr |
| 3348 | // strex scratch, scratch2, ptr |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 3349 | // cmp scratch, #0 |
| 3350 | // bne- loopMBB |
| 3351 | // fallthrough --> exitMBB |
| 3352 | BB = loopMBB; |
| 3353 | AddDefaultPred(BuildMI(BB, dl, TII->get(ldrOpc), dest).addReg(ptr)); |
Jim Grosbach | c67b556 | 2009-12-15 00:12:35 +0000 | [diff] [blame] | 3354 | if (BinOpcode) { |
| 3355 | // operand order needs to go the other way for NAND |
| 3356 | if (BinOpcode == ARM::BICrr || BinOpcode == ARM::t2BICrr) |
| 3357 | AddDefaultPred(BuildMI(BB, dl, TII->get(BinOpcode), scratch2). |
| 3358 | addReg(incr).addReg(dest)).addReg(0); |
| 3359 | else |
| 3360 | AddDefaultPred(BuildMI(BB, dl, TII->get(BinOpcode), scratch2). |
| 3361 | addReg(dest).addReg(incr)).addReg(0); |
| 3362 | } |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 3363 | |
| 3364 | AddDefaultPred(BuildMI(BB, dl, TII->get(strOpc), scratch).addReg(scratch2) |
| 3365 | .addReg(ptr)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 3366 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 3367 | .addReg(scratch).addImm(0)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 3368 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 3369 | .addMBB(loopMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 3370 | |
| 3371 | BB->addSuccessor(loopMBB); |
| 3372 | BB->addSuccessor(exitMBB); |
| 3373 | |
| 3374 | // exitMBB: |
| 3375 | // ... |
| 3376 | BB = exitMBB; |
Evan Cheng | 102ebf1 | 2009-12-21 19:53:39 +0000 | [diff] [blame] | 3377 | |
Jim Grosbach | 867bbbf | 2010-01-15 00:22:18 +0000 | [diff] [blame] | 3378 | MF->DeleteMachineInstr(MI); // The instruction is gone now. |
Evan Cheng | 102ebf1 | 2009-12-21 19:53:39 +0000 | [diff] [blame] | 3379 | |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 3380 | return BB; |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 3381 | } |
| 3382 | |
| 3383 | MachineBasicBlock * |
Evan Cheng | ff9b373 | 2008-01-30 18:18:23 +0000 | [diff] [blame] | 3384 | ARMTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI, |
Dan Gohman | af1d8ca | 2010-05-01 00:01:06 +0000 | [diff] [blame] | 3385 | MachineBasicBlock *BB) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3386 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
Dale Johannesen | b672840 | 2009-02-13 02:25:56 +0000 | [diff] [blame] | 3387 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 3388 | bool isThumb2 = Subtarget->isThumb2(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3389 | switch (MI->getOpcode()) { |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 3390 | default: |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 3391 | MI->dump(); |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 3392 | llvm_unreachable("Unexpected instr type to insert"); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 3393 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 3394 | case ARM::ATOMIC_LOAD_ADD_I8: |
| 3395 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr); |
| 3396 | case ARM::ATOMIC_LOAD_ADD_I16: |
| 3397 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr); |
| 3398 | case ARM::ATOMIC_LOAD_ADD_I32: |
| 3399 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 3400 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 3401 | case ARM::ATOMIC_LOAD_AND_I8: |
| 3402 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
| 3403 | case ARM::ATOMIC_LOAD_AND_I16: |
| 3404 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
| 3405 | case ARM::ATOMIC_LOAD_AND_I32: |
| 3406 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 3407 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 3408 | case ARM::ATOMIC_LOAD_OR_I8: |
| 3409 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
| 3410 | case ARM::ATOMIC_LOAD_OR_I16: |
| 3411 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
| 3412 | case ARM::ATOMIC_LOAD_OR_I32: |
| 3413 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 3414 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 3415 | case ARM::ATOMIC_LOAD_XOR_I8: |
| 3416 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
| 3417 | case ARM::ATOMIC_LOAD_XOR_I16: |
| 3418 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
| 3419 | case ARM::ATOMIC_LOAD_XOR_I32: |
| 3420 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 3421 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 3422 | case ARM::ATOMIC_LOAD_NAND_I8: |
| 3423 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2BICrr : ARM::BICrr); |
| 3424 | case ARM::ATOMIC_LOAD_NAND_I16: |
| 3425 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2BICrr : ARM::BICrr); |
| 3426 | case ARM::ATOMIC_LOAD_NAND_I32: |
| 3427 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2BICrr : ARM::BICrr); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 3428 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 3429 | case ARM::ATOMIC_LOAD_SUB_I8: |
| 3430 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr); |
| 3431 | case ARM::ATOMIC_LOAD_SUB_I16: |
| 3432 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr); |
| 3433 | case ARM::ATOMIC_LOAD_SUB_I32: |
| 3434 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 3435 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 3436 | case ARM::ATOMIC_SWAP_I8: return EmitAtomicBinary(MI, BB, 1, 0); |
| 3437 | case ARM::ATOMIC_SWAP_I16: return EmitAtomicBinary(MI, BB, 2, 0); |
| 3438 | case ARM::ATOMIC_SWAP_I32: return EmitAtomicBinary(MI, BB, 4, 0); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 3439 | |
| 3440 | case ARM::ATOMIC_CMP_SWAP_I8: return EmitAtomicCmpSwap(MI, BB, 1); |
| 3441 | case ARM::ATOMIC_CMP_SWAP_I16: return EmitAtomicCmpSwap(MI, BB, 2); |
| 3442 | case ARM::ATOMIC_CMP_SWAP_I32: return EmitAtomicCmpSwap(MI, BB, 4); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 3443 | |
Evan Cheng | 007ea27 | 2009-08-12 05:17:19 +0000 | [diff] [blame] | 3444 | case ARM::tMOVCCr_pseudo: { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3445 | // To "insert" a SELECT_CC instruction, we actually have to insert the |
| 3446 | // diamond control-flow pattern. The incoming instruction knows the |
| 3447 | // destination vreg to set, the condition code register to branch on, the |
| 3448 | // true/false values to select between, and a branch opcode to use. |
| 3449 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 3450 | MachineFunction::iterator It = BB; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3451 | ++It; |
| 3452 | |
| 3453 | // thisMBB: |
| 3454 | // ... |
| 3455 | // TrueVal = ... |
| 3456 | // cmpTY ccX, r1, r2 |
| 3457 | // bCC copy1MBB |
| 3458 | // fallthrough --> copy0MBB |
| 3459 | MachineBasicBlock *thisMBB = BB; |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 3460 | MachineFunction *F = BB->getParent(); |
| 3461 | MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB); |
| 3462 | MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB); |
Dale Johannesen | b672840 | 2009-02-13 02:25:56 +0000 | [diff] [blame] | 3463 | BuildMI(BB, dl, TII->get(ARM::tBcc)).addMBB(sinkMBB) |
Evan Cheng | 0e1d379 | 2007-07-05 07:18:20 +0000 | [diff] [blame] | 3464 | .addImm(MI->getOperand(3).getImm()).addReg(MI->getOperand(4).getReg()); |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 3465 | F->insert(It, copy0MBB); |
| 3466 | F->insert(It, sinkMBB); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3467 | // Update machine-CFG edges by first adding all successors of the current |
| 3468 | // block to the new block which will contain the Phi node for the select. |
Evan Cheng | ce31910 | 2009-09-19 09:51:03 +0000 | [diff] [blame] | 3469 | for (MachineBasicBlock::succ_iterator I = BB->succ_begin(), |
Dan Gohman | af1d8ca | 2010-05-01 00:01:06 +0000 | [diff] [blame] | 3470 | E = BB->succ_end(); I != E; ++I) |
Evan Cheng | ce31910 | 2009-09-19 09:51:03 +0000 | [diff] [blame] | 3471 | sinkMBB->addSuccessor(*I); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3472 | // Next, remove all successors of the current block, and add the true |
| 3473 | // and fallthrough blocks as its successors. |
Evan Cheng | ce31910 | 2009-09-19 09:51:03 +0000 | [diff] [blame] | 3474 | while (!BB->succ_empty()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3475 | BB->removeSuccessor(BB->succ_begin()); |
| 3476 | BB->addSuccessor(copy0MBB); |
| 3477 | BB->addSuccessor(sinkMBB); |
| 3478 | |
| 3479 | // copy0MBB: |
| 3480 | // %FalseValue = ... |
| 3481 | // # fallthrough to sinkMBB |
| 3482 | BB = copy0MBB; |
| 3483 | |
| 3484 | // Update machine-CFG edges |
| 3485 | BB->addSuccessor(sinkMBB); |
| 3486 | |
| 3487 | // sinkMBB: |
| 3488 | // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ] |
| 3489 | // ... |
| 3490 | BB = sinkMBB; |
Dale Johannesen | b672840 | 2009-02-13 02:25:56 +0000 | [diff] [blame] | 3491 | BuildMI(BB, dl, TII->get(ARM::PHI), MI->getOperand(0).getReg()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3492 | .addReg(MI->getOperand(1).getReg()).addMBB(copy0MBB) |
| 3493 | .addReg(MI->getOperand(2).getReg()).addMBB(thisMBB); |
| 3494 | |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 3495 | F->DeleteMachineInstr(MI); // The pseudo instruction is gone now. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3496 | return BB; |
| 3497 | } |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 3498 | |
| 3499 | case ARM::tANDsp: |
| 3500 | case ARM::tADDspr_: |
| 3501 | case ARM::tSUBspi_: |
| 3502 | case ARM::t2SUBrSPi_: |
| 3503 | case ARM::t2SUBrSPi12_: |
| 3504 | case ARM::t2SUBrSPs_: { |
| 3505 | MachineFunction *MF = BB->getParent(); |
| 3506 | unsigned DstReg = MI->getOperand(0).getReg(); |
| 3507 | unsigned SrcReg = MI->getOperand(1).getReg(); |
| 3508 | bool DstIsDead = MI->getOperand(0).isDead(); |
| 3509 | bool SrcIsKill = MI->getOperand(1).isKill(); |
| 3510 | |
| 3511 | if (SrcReg != ARM::SP) { |
| 3512 | // Copy the source to SP from virtual register. |
| 3513 | const TargetRegisterClass *RC = MF->getRegInfo().getRegClass(SrcReg); |
| 3514 | unsigned CopyOpc = (RC == ARM::tGPRRegisterClass) |
| 3515 | ? ARM::tMOVtgpr2gpr : ARM::tMOVgpr2gpr; |
| 3516 | BuildMI(BB, dl, TII->get(CopyOpc), ARM::SP) |
| 3517 | .addReg(SrcReg, getKillRegState(SrcIsKill)); |
| 3518 | } |
| 3519 | |
| 3520 | unsigned OpOpc = 0; |
| 3521 | bool NeedPred = false, NeedCC = false, NeedOp3 = false; |
| 3522 | switch (MI->getOpcode()) { |
| 3523 | default: |
| 3524 | llvm_unreachable("Unexpected pseudo instruction!"); |
| 3525 | case ARM::tANDsp: |
| 3526 | OpOpc = ARM::tAND; |
| 3527 | NeedPred = true; |
| 3528 | break; |
| 3529 | case ARM::tADDspr_: |
| 3530 | OpOpc = ARM::tADDspr; |
| 3531 | break; |
| 3532 | case ARM::tSUBspi_: |
| 3533 | OpOpc = ARM::tSUBspi; |
| 3534 | break; |
| 3535 | case ARM::t2SUBrSPi_: |
| 3536 | OpOpc = ARM::t2SUBrSPi; |
| 3537 | NeedPred = true; NeedCC = true; |
| 3538 | break; |
| 3539 | case ARM::t2SUBrSPi12_: |
| 3540 | OpOpc = ARM::t2SUBrSPi12; |
| 3541 | NeedPred = true; |
| 3542 | break; |
| 3543 | case ARM::t2SUBrSPs_: |
| 3544 | OpOpc = ARM::t2SUBrSPs; |
| 3545 | NeedPred = true; NeedCC = true; NeedOp3 = true; |
| 3546 | break; |
| 3547 | } |
| 3548 | MachineInstrBuilder MIB = BuildMI(BB, dl, TII->get(OpOpc), ARM::SP); |
| 3549 | if (OpOpc == ARM::tAND) |
| 3550 | AddDefaultT1CC(MIB); |
| 3551 | MIB.addReg(ARM::SP); |
| 3552 | MIB.addOperand(MI->getOperand(2)); |
| 3553 | if (NeedOp3) |
| 3554 | MIB.addOperand(MI->getOperand(3)); |
| 3555 | if (NeedPred) |
| 3556 | AddDefaultPred(MIB); |
| 3557 | if (NeedCC) |
| 3558 | AddDefaultCC(MIB); |
| 3559 | |
| 3560 | // Copy the result from SP to virtual register. |
| 3561 | const TargetRegisterClass *RC = MF->getRegInfo().getRegClass(DstReg); |
| 3562 | unsigned CopyOpc = (RC == ARM::tGPRRegisterClass) |
| 3563 | ? ARM::tMOVgpr2tgpr : ARM::tMOVgpr2gpr; |
| 3564 | BuildMI(BB, dl, TII->get(CopyOpc)) |
| 3565 | .addReg(DstReg, getDefRegState(true) | getDeadRegState(DstIsDead)) |
| 3566 | .addReg(ARM::SP); |
| 3567 | MF->DeleteMachineInstr(MI); // The pseudo instruction is gone now. |
| 3568 | return BB; |
| 3569 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3570 | } |
| 3571 | } |
| 3572 | |
| 3573 | //===----------------------------------------------------------------------===// |
| 3574 | // ARM Optimization Hooks |
| 3575 | //===----------------------------------------------------------------------===// |
| 3576 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 3577 | static |
| 3578 | SDValue combineSelectAndUse(SDNode *N, SDValue Slct, SDValue OtherOp, |
| 3579 | TargetLowering::DAGCombinerInfo &DCI) { |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 3580 | SelectionDAG &DAG = DCI.DAG; |
| 3581 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3582 | EVT VT = N->getValueType(0); |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 3583 | unsigned Opc = N->getOpcode(); |
| 3584 | bool isSlctCC = Slct.getOpcode() == ISD::SELECT_CC; |
| 3585 | SDValue LHS = isSlctCC ? Slct.getOperand(2) : Slct.getOperand(1); |
| 3586 | SDValue RHS = isSlctCC ? Slct.getOperand(3) : Slct.getOperand(2); |
| 3587 | ISD::CondCode CC = ISD::SETCC_INVALID; |
| 3588 | |
| 3589 | if (isSlctCC) { |
| 3590 | CC = cast<CondCodeSDNode>(Slct.getOperand(4))->get(); |
| 3591 | } else { |
| 3592 | SDValue CCOp = Slct.getOperand(0); |
| 3593 | if (CCOp.getOpcode() == ISD::SETCC) |
| 3594 | CC = cast<CondCodeSDNode>(CCOp.getOperand(2))->get(); |
| 3595 | } |
| 3596 | |
| 3597 | bool DoXform = false; |
| 3598 | bool InvCC = false; |
| 3599 | assert ((Opc == ISD::ADD || (Opc == ISD::SUB && Slct == N->getOperand(1))) && |
| 3600 | "Bad input!"); |
| 3601 | |
| 3602 | if (LHS.getOpcode() == ISD::Constant && |
| 3603 | cast<ConstantSDNode>(LHS)->isNullValue()) { |
| 3604 | DoXform = true; |
| 3605 | } else if (CC != ISD::SETCC_INVALID && |
| 3606 | RHS.getOpcode() == ISD::Constant && |
| 3607 | cast<ConstantSDNode>(RHS)->isNullValue()) { |
| 3608 | std::swap(LHS, RHS); |
| 3609 | SDValue Op0 = Slct.getOperand(0); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3610 | EVT OpVT = isSlctCC ? Op0.getValueType() : |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 3611 | Op0.getOperand(0).getValueType(); |
| 3612 | bool isInt = OpVT.isInteger(); |
| 3613 | CC = ISD::getSetCCInverse(CC, isInt); |
| 3614 | |
| 3615 | if (!TLI.isCondCodeLegal(CC, OpVT)) |
| 3616 | return SDValue(); // Inverse operator isn't legal. |
| 3617 | |
| 3618 | DoXform = true; |
| 3619 | InvCC = true; |
| 3620 | } |
| 3621 | |
| 3622 | if (DoXform) { |
| 3623 | SDValue Result = DAG.getNode(Opc, RHS.getDebugLoc(), VT, OtherOp, RHS); |
| 3624 | if (isSlctCC) |
| 3625 | return DAG.getSelectCC(N->getDebugLoc(), OtherOp, Result, |
| 3626 | Slct.getOperand(0), Slct.getOperand(1), CC); |
| 3627 | SDValue CCOp = Slct.getOperand(0); |
| 3628 | if (InvCC) |
| 3629 | CCOp = DAG.getSetCC(Slct.getDebugLoc(), CCOp.getValueType(), |
| 3630 | CCOp.getOperand(0), CCOp.getOperand(1), CC); |
| 3631 | return DAG.getNode(ISD::SELECT, N->getDebugLoc(), VT, |
| 3632 | CCOp, OtherOp, Result); |
| 3633 | } |
| 3634 | return SDValue(); |
| 3635 | } |
| 3636 | |
| 3637 | /// PerformADDCombine - Target-specific dag combine xforms for ISD::ADD. |
| 3638 | static SDValue PerformADDCombine(SDNode *N, |
| 3639 | TargetLowering::DAGCombinerInfo &DCI) { |
| 3640 | // added by evan in r37685 with no testcase. |
| 3641 | SDValue N0 = N->getOperand(0), N1 = N->getOperand(1); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3642 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 3643 | // fold (add (select cc, 0, c), x) -> (select cc, x, (add, x, c)) |
| 3644 | if (N0.getOpcode() == ISD::SELECT && N0.getNode()->hasOneUse()) { |
| 3645 | SDValue Result = combineSelectAndUse(N, N0, N1, DCI); |
| 3646 | if (Result.getNode()) return Result; |
| 3647 | } |
| 3648 | if (N1.getOpcode() == ISD::SELECT && N1.getNode()->hasOneUse()) { |
| 3649 | SDValue Result = combineSelectAndUse(N, N1, N0, DCI); |
| 3650 | if (Result.getNode()) return Result; |
| 3651 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3652 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 3653 | return SDValue(); |
| 3654 | } |
| 3655 | |
| 3656 | /// PerformSUBCombine - Target-specific dag combine xforms for ISD::SUB. |
| 3657 | static SDValue PerformSUBCombine(SDNode *N, |
| 3658 | TargetLowering::DAGCombinerInfo &DCI) { |
| 3659 | // added by evan in r37685 with no testcase. |
| 3660 | SDValue N0 = N->getOperand(0), N1 = N->getOperand(1); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3661 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 3662 | // fold (sub x, (select cc, 0, c)) -> (select cc, x, (sub, x, c)) |
| 3663 | if (N1.getOpcode() == ISD::SELECT && N1.getNode()->hasOneUse()) { |
| 3664 | SDValue Result = combineSelectAndUse(N, N1, N0, DCI); |
| 3665 | if (Result.getNode()) return Result; |
| 3666 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3667 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 3668 | return SDValue(); |
| 3669 | } |
| 3670 | |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 3671 | static SDValue PerformMULCombine(SDNode *N, |
| 3672 | TargetLowering::DAGCombinerInfo &DCI, |
| 3673 | const ARMSubtarget *Subtarget) { |
| 3674 | SelectionDAG &DAG = DCI.DAG; |
| 3675 | |
| 3676 | if (Subtarget->isThumb1Only()) |
| 3677 | return SDValue(); |
| 3678 | |
| 3679 | if (DAG.getMachineFunction(). |
| 3680 | getFunction()->hasFnAttr(Attribute::OptimizeForSize)) |
| 3681 | return SDValue(); |
| 3682 | |
| 3683 | if (DCI.isBeforeLegalize() || DCI.isCalledByLegalizer()) |
| 3684 | return SDValue(); |
| 3685 | |
| 3686 | EVT VT = N->getValueType(0); |
| 3687 | if (VT != MVT::i32) |
| 3688 | return SDValue(); |
| 3689 | |
| 3690 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1)); |
| 3691 | if (!C) |
| 3692 | return SDValue(); |
| 3693 | |
| 3694 | uint64_t MulAmt = C->getZExtValue(); |
| 3695 | unsigned ShiftAmt = CountTrailingZeros_64(MulAmt); |
| 3696 | ShiftAmt = ShiftAmt & (32 - 1); |
| 3697 | SDValue V = N->getOperand(0); |
| 3698 | DebugLoc DL = N->getDebugLoc(); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 3699 | |
Anton Korobeynikov | 4878b84 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 3700 | SDValue Res; |
| 3701 | MulAmt >>= ShiftAmt; |
| 3702 | if (isPowerOf2_32(MulAmt - 1)) { |
| 3703 | // (mul x, 2^N + 1) => (add (shl x, N), x) |
| 3704 | Res = DAG.getNode(ISD::ADD, DL, VT, |
| 3705 | V, DAG.getNode(ISD::SHL, DL, VT, |
| 3706 | V, DAG.getConstant(Log2_32(MulAmt-1), |
| 3707 | MVT::i32))); |
| 3708 | } else if (isPowerOf2_32(MulAmt + 1)) { |
| 3709 | // (mul x, 2^N - 1) => (sub (shl x, N), x) |
| 3710 | Res = DAG.getNode(ISD::SUB, DL, VT, |
| 3711 | DAG.getNode(ISD::SHL, DL, VT, |
| 3712 | V, DAG.getConstant(Log2_32(MulAmt+1), |
| 3713 | MVT::i32)), |
| 3714 | V); |
| 3715 | } else |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 3716 | return SDValue(); |
Anton Korobeynikov | 4878b84 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 3717 | |
| 3718 | if (ShiftAmt != 0) |
| 3719 | Res = DAG.getNode(ISD::SHL, DL, VT, Res, |
| 3720 | DAG.getConstant(ShiftAmt, MVT::i32)); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 3721 | |
| 3722 | // Do not add new nodes to DAG combiner worklist. |
Anton Korobeynikov | 4878b84 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 3723 | DCI.CombineTo(N, Res, false); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 3724 | return SDValue(); |
| 3725 | } |
| 3726 | |
Bob Wilson | cb9a6aa | 2010-01-19 22:56:26 +0000 | [diff] [blame] | 3727 | /// PerformVMOVRRDCombine - Target-specific dag combine xforms for |
| 3728 | /// ARMISD::VMOVRRD. |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 3729 | static SDValue PerformVMOVRRDCombine(SDNode *N, |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3730 | TargetLowering::DAGCombinerInfo &DCI) { |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 3731 | // fmrrd(fmdrr x, y) -> x,y |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3732 | SDValue InDouble = N->getOperand(0); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 3733 | if (InDouble.getOpcode() == ARMISD::VMOVDRR) |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 3734 | return DCI.CombineTo(N, InDouble.getOperand(0), InDouble.getOperand(1)); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3735 | return SDValue(); |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 3736 | } |
| 3737 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3738 | /// getVShiftImm - Check if this is a valid build_vector for the immediate |
| 3739 | /// operand of a vector shift operation, where all the elements of the |
| 3740 | /// build_vector must have the same constant integer value. |
| 3741 | static bool getVShiftImm(SDValue Op, unsigned ElementBits, int64_t &Cnt) { |
| 3742 | // Ignore bit_converts. |
| 3743 | while (Op.getOpcode() == ISD::BIT_CONVERT) |
| 3744 | Op = Op.getOperand(0); |
| 3745 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(Op.getNode()); |
| 3746 | APInt SplatBits, SplatUndef; |
| 3747 | unsigned SplatBitSize; |
| 3748 | bool HasAnyUndefs; |
| 3749 | if (! BVN || ! BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, |
| 3750 | HasAnyUndefs, ElementBits) || |
| 3751 | SplatBitSize > ElementBits) |
| 3752 | return false; |
| 3753 | Cnt = SplatBits.getSExtValue(); |
| 3754 | return true; |
| 3755 | } |
| 3756 | |
| 3757 | /// isVShiftLImm - Check if this is a valid build_vector for the immediate |
| 3758 | /// operand of a vector shift left operation. That value must be in the range: |
| 3759 | /// 0 <= Value < ElementBits for a left shift; or |
| 3760 | /// 0 <= Value <= ElementBits for a long left shift. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3761 | static bool isVShiftLImm(SDValue Op, EVT VT, bool isLong, int64_t &Cnt) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3762 | assert(VT.isVector() && "vector shift count is not a vector type"); |
| 3763 | unsigned ElementBits = VT.getVectorElementType().getSizeInBits(); |
| 3764 | if (! getVShiftImm(Op, ElementBits, Cnt)) |
| 3765 | return false; |
| 3766 | return (Cnt >= 0 && (isLong ? Cnt-1 : Cnt) < ElementBits); |
| 3767 | } |
| 3768 | |
| 3769 | /// isVShiftRImm - Check if this is a valid build_vector for the immediate |
| 3770 | /// operand of a vector shift right operation. For a shift opcode, the value |
| 3771 | /// is positive, but for an intrinsic the value count must be negative. The |
| 3772 | /// absolute value must be in the range: |
| 3773 | /// 1 <= |Value| <= ElementBits for a right shift; or |
| 3774 | /// 1 <= |Value| <= ElementBits/2 for a narrow right shift. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3775 | static bool isVShiftRImm(SDValue Op, EVT VT, bool isNarrow, bool isIntrinsic, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3776 | int64_t &Cnt) { |
| 3777 | assert(VT.isVector() && "vector shift count is not a vector type"); |
| 3778 | unsigned ElementBits = VT.getVectorElementType().getSizeInBits(); |
| 3779 | if (! getVShiftImm(Op, ElementBits, Cnt)) |
| 3780 | return false; |
| 3781 | if (isIntrinsic) |
| 3782 | Cnt = -Cnt; |
| 3783 | return (Cnt >= 1 && Cnt <= (isNarrow ? ElementBits/2 : ElementBits)); |
| 3784 | } |
| 3785 | |
| 3786 | /// PerformIntrinsicCombine - ARM-specific DAG combining for intrinsics. |
| 3787 | static SDValue PerformIntrinsicCombine(SDNode *N, SelectionDAG &DAG) { |
| 3788 | unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue(); |
| 3789 | switch (IntNo) { |
| 3790 | default: |
| 3791 | // Don't do anything for most intrinsics. |
| 3792 | break; |
| 3793 | |
| 3794 | // Vector shifts: check for immediate versions and lower them. |
| 3795 | // Note: This is done during DAG combining instead of DAG legalizing because |
| 3796 | // the build_vectors for 64-bit vector element shift counts are generally |
| 3797 | // not legal, and it is hard to see their values after they get legalized to |
| 3798 | // loads from a constant pool. |
| 3799 | case Intrinsic::arm_neon_vshifts: |
| 3800 | case Intrinsic::arm_neon_vshiftu: |
| 3801 | case Intrinsic::arm_neon_vshiftls: |
| 3802 | case Intrinsic::arm_neon_vshiftlu: |
| 3803 | case Intrinsic::arm_neon_vshiftn: |
| 3804 | case Intrinsic::arm_neon_vrshifts: |
| 3805 | case Intrinsic::arm_neon_vrshiftu: |
| 3806 | case Intrinsic::arm_neon_vrshiftn: |
| 3807 | case Intrinsic::arm_neon_vqshifts: |
| 3808 | case Intrinsic::arm_neon_vqshiftu: |
| 3809 | case Intrinsic::arm_neon_vqshiftsu: |
| 3810 | case Intrinsic::arm_neon_vqshiftns: |
| 3811 | case Intrinsic::arm_neon_vqshiftnu: |
| 3812 | case Intrinsic::arm_neon_vqshiftnsu: |
| 3813 | case Intrinsic::arm_neon_vqrshiftns: |
| 3814 | case Intrinsic::arm_neon_vqrshiftnu: |
| 3815 | case Intrinsic::arm_neon_vqrshiftnsu: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3816 | EVT VT = N->getOperand(1).getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3817 | int64_t Cnt; |
| 3818 | unsigned VShiftOpc = 0; |
| 3819 | |
| 3820 | switch (IntNo) { |
| 3821 | case Intrinsic::arm_neon_vshifts: |
| 3822 | case Intrinsic::arm_neon_vshiftu: |
| 3823 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) { |
| 3824 | VShiftOpc = ARMISD::VSHL; |
| 3825 | break; |
| 3826 | } |
| 3827 | if (isVShiftRImm(N->getOperand(2), VT, false, true, Cnt)) { |
| 3828 | VShiftOpc = (IntNo == Intrinsic::arm_neon_vshifts ? |
| 3829 | ARMISD::VSHRs : ARMISD::VSHRu); |
| 3830 | break; |
| 3831 | } |
| 3832 | return SDValue(); |
| 3833 | |
| 3834 | case Intrinsic::arm_neon_vshiftls: |
| 3835 | case Intrinsic::arm_neon_vshiftlu: |
| 3836 | if (isVShiftLImm(N->getOperand(2), VT, true, Cnt)) |
| 3837 | break; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 3838 | llvm_unreachable("invalid shift count for vshll intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3839 | |
| 3840 | case Intrinsic::arm_neon_vrshifts: |
| 3841 | case Intrinsic::arm_neon_vrshiftu: |
| 3842 | if (isVShiftRImm(N->getOperand(2), VT, false, true, Cnt)) |
| 3843 | break; |
| 3844 | return SDValue(); |
| 3845 | |
| 3846 | case Intrinsic::arm_neon_vqshifts: |
| 3847 | case Intrinsic::arm_neon_vqshiftu: |
| 3848 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) |
| 3849 | break; |
| 3850 | return SDValue(); |
| 3851 | |
| 3852 | case Intrinsic::arm_neon_vqshiftsu: |
| 3853 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) |
| 3854 | break; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 3855 | llvm_unreachable("invalid shift count for vqshlu intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3856 | |
| 3857 | case Intrinsic::arm_neon_vshiftn: |
| 3858 | case Intrinsic::arm_neon_vrshiftn: |
| 3859 | case Intrinsic::arm_neon_vqshiftns: |
| 3860 | case Intrinsic::arm_neon_vqshiftnu: |
| 3861 | case Intrinsic::arm_neon_vqshiftnsu: |
| 3862 | case Intrinsic::arm_neon_vqrshiftns: |
| 3863 | case Intrinsic::arm_neon_vqrshiftnu: |
| 3864 | case Intrinsic::arm_neon_vqrshiftnsu: |
| 3865 | // Narrowing shifts require an immediate right shift. |
| 3866 | if (isVShiftRImm(N->getOperand(2), VT, true, true, Cnt)) |
| 3867 | break; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 3868 | llvm_unreachable("invalid shift count for narrowing vector shift intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3869 | |
| 3870 | default: |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 3871 | llvm_unreachable("unhandled vector shift"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3872 | } |
| 3873 | |
| 3874 | switch (IntNo) { |
| 3875 | case Intrinsic::arm_neon_vshifts: |
| 3876 | case Intrinsic::arm_neon_vshiftu: |
| 3877 | // Opcode already set above. |
| 3878 | break; |
| 3879 | case Intrinsic::arm_neon_vshiftls: |
| 3880 | case Intrinsic::arm_neon_vshiftlu: |
| 3881 | if (Cnt == VT.getVectorElementType().getSizeInBits()) |
| 3882 | VShiftOpc = ARMISD::VSHLLi; |
| 3883 | else |
| 3884 | VShiftOpc = (IntNo == Intrinsic::arm_neon_vshiftls ? |
| 3885 | ARMISD::VSHLLs : ARMISD::VSHLLu); |
| 3886 | break; |
| 3887 | case Intrinsic::arm_neon_vshiftn: |
| 3888 | VShiftOpc = ARMISD::VSHRN; break; |
| 3889 | case Intrinsic::arm_neon_vrshifts: |
| 3890 | VShiftOpc = ARMISD::VRSHRs; break; |
| 3891 | case Intrinsic::arm_neon_vrshiftu: |
| 3892 | VShiftOpc = ARMISD::VRSHRu; break; |
| 3893 | case Intrinsic::arm_neon_vrshiftn: |
| 3894 | VShiftOpc = ARMISD::VRSHRN; break; |
| 3895 | case Intrinsic::arm_neon_vqshifts: |
| 3896 | VShiftOpc = ARMISD::VQSHLs; break; |
| 3897 | case Intrinsic::arm_neon_vqshiftu: |
| 3898 | VShiftOpc = ARMISD::VQSHLu; break; |
| 3899 | case Intrinsic::arm_neon_vqshiftsu: |
| 3900 | VShiftOpc = ARMISD::VQSHLsu; break; |
| 3901 | case Intrinsic::arm_neon_vqshiftns: |
| 3902 | VShiftOpc = ARMISD::VQSHRNs; break; |
| 3903 | case Intrinsic::arm_neon_vqshiftnu: |
| 3904 | VShiftOpc = ARMISD::VQSHRNu; break; |
| 3905 | case Intrinsic::arm_neon_vqshiftnsu: |
| 3906 | VShiftOpc = ARMISD::VQSHRNsu; break; |
| 3907 | case Intrinsic::arm_neon_vqrshiftns: |
| 3908 | VShiftOpc = ARMISD::VQRSHRNs; break; |
| 3909 | case Intrinsic::arm_neon_vqrshiftnu: |
| 3910 | VShiftOpc = ARMISD::VQRSHRNu; break; |
| 3911 | case Intrinsic::arm_neon_vqrshiftnsu: |
| 3912 | VShiftOpc = ARMISD::VQRSHRNsu; break; |
| 3913 | } |
| 3914 | |
| 3915 | return DAG.getNode(VShiftOpc, N->getDebugLoc(), N->getValueType(0), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3916 | N->getOperand(1), DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3917 | } |
| 3918 | |
| 3919 | case Intrinsic::arm_neon_vshiftins: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3920 | EVT VT = N->getOperand(1).getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3921 | int64_t Cnt; |
| 3922 | unsigned VShiftOpc = 0; |
| 3923 | |
| 3924 | if (isVShiftLImm(N->getOperand(3), VT, false, Cnt)) |
| 3925 | VShiftOpc = ARMISD::VSLI; |
| 3926 | else if (isVShiftRImm(N->getOperand(3), VT, false, true, Cnt)) |
| 3927 | VShiftOpc = ARMISD::VSRI; |
| 3928 | else { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 3929 | llvm_unreachable("invalid shift count for vsli/vsri intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3930 | } |
| 3931 | |
| 3932 | return DAG.getNode(VShiftOpc, N->getDebugLoc(), N->getValueType(0), |
| 3933 | N->getOperand(1), N->getOperand(2), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3934 | DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3935 | } |
| 3936 | |
| 3937 | case Intrinsic::arm_neon_vqrshifts: |
| 3938 | case Intrinsic::arm_neon_vqrshiftu: |
| 3939 | // No immediate versions of these to check for. |
| 3940 | break; |
| 3941 | } |
| 3942 | |
| 3943 | return SDValue(); |
| 3944 | } |
| 3945 | |
| 3946 | /// PerformShiftCombine - Checks for immediate versions of vector shifts and |
| 3947 | /// lowers them. As with the vector shift intrinsics, this is done during DAG |
| 3948 | /// combining instead of DAG legalizing because the build_vectors for 64-bit |
| 3949 | /// vector element shift counts are generally not legal, and it is hard to see |
| 3950 | /// their values after they get legalized to loads from a constant pool. |
| 3951 | static SDValue PerformShiftCombine(SDNode *N, SelectionDAG &DAG, |
| 3952 | const ARMSubtarget *ST) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3953 | EVT VT = N->getValueType(0); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3954 | |
| 3955 | // Nothing to be done for scalar shifts. |
| 3956 | if (! VT.isVector()) |
| 3957 | return SDValue(); |
| 3958 | |
| 3959 | assert(ST->hasNEON() && "unexpected vector shift"); |
| 3960 | int64_t Cnt; |
| 3961 | |
| 3962 | switch (N->getOpcode()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 3963 | default: llvm_unreachable("unexpected shift opcode"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3964 | |
| 3965 | case ISD::SHL: |
| 3966 | if (isVShiftLImm(N->getOperand(1), VT, false, Cnt)) |
| 3967 | return DAG.getNode(ARMISD::VSHL, N->getDebugLoc(), VT, N->getOperand(0), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3968 | DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3969 | break; |
| 3970 | |
| 3971 | case ISD::SRA: |
| 3972 | case ISD::SRL: |
| 3973 | if (isVShiftRImm(N->getOperand(1), VT, false, false, Cnt)) { |
| 3974 | unsigned VShiftOpc = (N->getOpcode() == ISD::SRA ? |
| 3975 | ARMISD::VSHRs : ARMISD::VSHRu); |
| 3976 | return DAG.getNode(VShiftOpc, N->getDebugLoc(), VT, N->getOperand(0), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3977 | DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3978 | } |
| 3979 | } |
| 3980 | return SDValue(); |
| 3981 | } |
| 3982 | |
| 3983 | /// PerformExtendCombine - Target-specific DAG combining for ISD::SIGN_EXTEND, |
| 3984 | /// ISD::ZERO_EXTEND, and ISD::ANY_EXTEND. |
| 3985 | static SDValue PerformExtendCombine(SDNode *N, SelectionDAG &DAG, |
| 3986 | const ARMSubtarget *ST) { |
| 3987 | SDValue N0 = N->getOperand(0); |
| 3988 | |
| 3989 | // Check for sign- and zero-extensions of vector extract operations of 8- |
| 3990 | // and 16-bit vector elements. NEON supports these directly. They are |
| 3991 | // handled during DAG combining because type legalization will promote them |
| 3992 | // to 32-bit types and it is messy to recognize the operations after that. |
| 3993 | if (ST->hasNEON() && N0.getOpcode() == ISD::EXTRACT_VECTOR_ELT) { |
| 3994 | SDValue Vec = N0.getOperand(0); |
| 3995 | SDValue Lane = N0.getOperand(1); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3996 | EVT VT = N->getValueType(0); |
| 3997 | EVT EltVT = N0.getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3998 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 3999 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4000 | if (VT == MVT::i32 && |
| 4001 | (EltVT == MVT::i8 || EltVT == MVT::i16) && |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4002 | TLI.isTypeLegal(Vec.getValueType())) { |
| 4003 | |
| 4004 | unsigned Opc = 0; |
| 4005 | switch (N->getOpcode()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 4006 | default: llvm_unreachable("unexpected opcode"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4007 | case ISD::SIGN_EXTEND: |
| 4008 | Opc = ARMISD::VGETLANEs; |
| 4009 | break; |
| 4010 | case ISD::ZERO_EXTEND: |
| 4011 | case ISD::ANY_EXTEND: |
| 4012 | Opc = ARMISD::VGETLANEu; |
| 4013 | break; |
| 4014 | } |
| 4015 | return DAG.getNode(Opc, N->getDebugLoc(), VT, Vec, Lane); |
| 4016 | } |
| 4017 | } |
| 4018 | |
| 4019 | return SDValue(); |
| 4020 | } |
| 4021 | |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 4022 | /// PerformSELECT_CCCombine - Target-specific DAG combining for ISD::SELECT_CC |
| 4023 | /// to match f32 max/min patterns to use NEON vmax/vmin instructions. |
| 4024 | static SDValue PerformSELECT_CCCombine(SDNode *N, SelectionDAG &DAG, |
| 4025 | const ARMSubtarget *ST) { |
| 4026 | // If the target supports NEON, try to use vmax/vmin instructions for f32 |
| 4027 | // selects like "x < y ? x : y". Unless the FiniteOnlyFPMath option is set, |
| 4028 | // be careful about NaNs: NEON's vmax/vmin return NaN if either operand is |
| 4029 | // a NaN; only do the transformation when it matches that behavior. |
| 4030 | |
| 4031 | // For now only do this when using NEON for FP operations; if using VFP, it |
| 4032 | // is not obvious that the benefit outweighs the cost of switching to the |
| 4033 | // NEON pipeline. |
| 4034 | if (!ST->hasNEON() || !ST->useNEONForSinglePrecisionFP() || |
| 4035 | N->getValueType(0) != MVT::f32) |
| 4036 | return SDValue(); |
| 4037 | |
| 4038 | SDValue CondLHS = N->getOperand(0); |
| 4039 | SDValue CondRHS = N->getOperand(1); |
| 4040 | SDValue LHS = N->getOperand(2); |
| 4041 | SDValue RHS = N->getOperand(3); |
| 4042 | ISD::CondCode CC = cast<CondCodeSDNode>(N->getOperand(4))->get(); |
| 4043 | |
| 4044 | unsigned Opcode = 0; |
| 4045 | bool IsReversed; |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 4046 | if (DAG.isEqualTo(LHS, CondLHS) && DAG.isEqualTo(RHS, CondRHS)) { |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 4047 | IsReversed = false; // x CC y ? x : y |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 4048 | } else if (DAG.isEqualTo(LHS, CondRHS) && DAG.isEqualTo(RHS, CondLHS)) { |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 4049 | IsReversed = true ; // x CC y ? y : x |
| 4050 | } else { |
| 4051 | return SDValue(); |
| 4052 | } |
| 4053 | |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 4054 | bool IsUnordered; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 4055 | switch (CC) { |
| 4056 | default: break; |
| 4057 | case ISD::SETOLT: |
| 4058 | case ISD::SETOLE: |
| 4059 | case ISD::SETLT: |
| 4060 | case ISD::SETLE: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 4061 | case ISD::SETULT: |
| 4062 | case ISD::SETULE: |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 4063 | // If LHS is NaN, an ordered comparison will be false and the result will |
| 4064 | // be the RHS, but vmin(NaN, RHS) = NaN. Avoid this by checking that LHS |
| 4065 | // != NaN. Likewise, for unordered comparisons, check for RHS != NaN. |
| 4066 | IsUnordered = (CC == ISD::SETULT || CC == ISD::SETULE); |
| 4067 | if (!DAG.isKnownNeverNaN(IsUnordered ? RHS : LHS)) |
| 4068 | break; |
| 4069 | // For less-than-or-equal comparisons, "+0 <= -0" will be true but vmin |
| 4070 | // will return -0, so vmin can only be used for unsafe math or if one of |
| 4071 | // the operands is known to be nonzero. |
| 4072 | if ((CC == ISD::SETLE || CC == ISD::SETOLE || CC == ISD::SETULE) && |
| 4073 | !UnsafeFPMath && |
| 4074 | !(DAG.isKnownNeverZero(LHS) || DAG.isKnownNeverZero(RHS))) |
| 4075 | break; |
| 4076 | Opcode = IsReversed ? ARMISD::FMAX : ARMISD::FMIN; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 4077 | break; |
| 4078 | |
| 4079 | case ISD::SETOGT: |
| 4080 | case ISD::SETOGE: |
| 4081 | case ISD::SETGT: |
| 4082 | case ISD::SETGE: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 4083 | case ISD::SETUGT: |
| 4084 | case ISD::SETUGE: |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 4085 | // If LHS is NaN, an ordered comparison will be false and the result will |
| 4086 | // be the RHS, but vmax(NaN, RHS) = NaN. Avoid this by checking that LHS |
| 4087 | // != NaN. Likewise, for unordered comparisons, check for RHS != NaN. |
| 4088 | IsUnordered = (CC == ISD::SETUGT || CC == ISD::SETUGE); |
| 4089 | if (!DAG.isKnownNeverNaN(IsUnordered ? RHS : LHS)) |
| 4090 | break; |
| 4091 | // For greater-than-or-equal comparisons, "-0 >= +0" will be true but vmax |
| 4092 | // will return +0, so vmax can only be used for unsafe math or if one of |
| 4093 | // the operands is known to be nonzero. |
| 4094 | if ((CC == ISD::SETGE || CC == ISD::SETOGE || CC == ISD::SETUGE) && |
| 4095 | !UnsafeFPMath && |
| 4096 | !(DAG.isKnownNeverZero(LHS) || DAG.isKnownNeverZero(RHS))) |
| 4097 | break; |
| 4098 | Opcode = IsReversed ? ARMISD::FMIN : ARMISD::FMAX; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 4099 | break; |
| 4100 | } |
| 4101 | |
| 4102 | if (!Opcode) |
| 4103 | return SDValue(); |
| 4104 | return DAG.getNode(Opcode, N->getDebugLoc(), N->getValueType(0), LHS, RHS); |
| 4105 | } |
| 4106 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4107 | SDValue ARMTargetLowering::PerformDAGCombine(SDNode *N, |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 4108 | DAGCombinerInfo &DCI) const { |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 4109 | switch (N->getOpcode()) { |
| 4110 | default: break; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 4111 | case ISD::ADD: return PerformADDCombine(N, DCI); |
| 4112 | case ISD::SUB: return PerformSUBCombine(N, DCI); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 4113 | case ISD::MUL: return PerformMULCombine(N, DCI, Subtarget); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 4114 | case ARMISD::VMOVRRD: return PerformVMOVRRDCombine(N, DCI); |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 4115 | case ISD::INTRINSIC_WO_CHAIN: return PerformIntrinsicCombine(N, DCI.DAG); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4116 | case ISD::SHL: |
| 4117 | case ISD::SRA: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 4118 | case ISD::SRL: return PerformShiftCombine(N, DCI.DAG, Subtarget); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4119 | case ISD::SIGN_EXTEND: |
| 4120 | case ISD::ZERO_EXTEND: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 4121 | case ISD::ANY_EXTEND: return PerformExtendCombine(N, DCI.DAG, Subtarget); |
| 4122 | case ISD::SELECT_CC: return PerformSELECT_CCCombine(N, DCI.DAG, Subtarget); |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 4123 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4124 | return SDValue(); |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 4125 | } |
| 4126 | |
Bill Wendling | af56634 | 2009-08-15 21:21:19 +0000 | [diff] [blame] | 4127 | bool ARMTargetLowering::allowsUnalignedMemoryAccesses(EVT VT) const { |
| 4128 | if (!Subtarget->hasV6Ops()) |
| 4129 | // Pre-v6 does not support unaligned mem access. |
| 4130 | return false; |
Anton Korobeynikov | 90cfc13 | 2010-01-30 14:08:12 +0000 | [diff] [blame] | 4131 | else { |
| 4132 | // v6+ may or may not support unaligned mem access depending on the system |
| 4133 | // configuration. |
| 4134 | // FIXME: This is pretty conservative. Should we provide cmdline option to |
| 4135 | // control the behaviour? |
Bill Wendling | af56634 | 2009-08-15 21:21:19 +0000 | [diff] [blame] | 4136 | if (!Subtarget->isTargetDarwin()) |
| 4137 | return false; |
| 4138 | } |
| 4139 | |
| 4140 | switch (VT.getSimpleVT().SimpleTy) { |
| 4141 | default: |
| 4142 | return false; |
| 4143 | case MVT::i8: |
| 4144 | case MVT::i16: |
| 4145 | case MVT::i32: |
| 4146 | return true; |
| 4147 | // FIXME: VLD1 etc with standard alignment is legal. |
| 4148 | } |
| 4149 | } |
| 4150 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 4151 | static bool isLegalT1AddressImmediate(int64_t V, EVT VT) { |
| 4152 | if (V < 0) |
| 4153 | return false; |
| 4154 | |
| 4155 | unsigned Scale = 1; |
| 4156 | switch (VT.getSimpleVT().SimpleTy) { |
| 4157 | default: return false; |
| 4158 | case MVT::i1: |
| 4159 | case MVT::i8: |
| 4160 | // Scale == 1; |
| 4161 | break; |
| 4162 | case MVT::i16: |
| 4163 | // Scale == 2; |
| 4164 | Scale = 2; |
| 4165 | break; |
| 4166 | case MVT::i32: |
| 4167 | // Scale == 4; |
| 4168 | Scale = 4; |
| 4169 | break; |
| 4170 | } |
| 4171 | |
| 4172 | if ((V & (Scale - 1)) != 0) |
| 4173 | return false; |
| 4174 | V /= Scale; |
| 4175 | return V == (V & ((1LL << 5) - 1)); |
| 4176 | } |
| 4177 | |
| 4178 | static bool isLegalT2AddressImmediate(int64_t V, EVT VT, |
| 4179 | const ARMSubtarget *Subtarget) { |
| 4180 | bool isNeg = false; |
| 4181 | if (V < 0) { |
| 4182 | isNeg = true; |
| 4183 | V = - V; |
| 4184 | } |
| 4185 | |
| 4186 | switch (VT.getSimpleVT().SimpleTy) { |
| 4187 | default: return false; |
| 4188 | case MVT::i1: |
| 4189 | case MVT::i8: |
| 4190 | case MVT::i16: |
| 4191 | case MVT::i32: |
| 4192 | // + imm12 or - imm8 |
| 4193 | if (isNeg) |
| 4194 | return V == (V & ((1LL << 8) - 1)); |
| 4195 | return V == (V & ((1LL << 12) - 1)); |
| 4196 | case MVT::f32: |
| 4197 | case MVT::f64: |
| 4198 | // Same as ARM mode. FIXME: NEON? |
| 4199 | if (!Subtarget->hasVFP2()) |
| 4200 | return false; |
| 4201 | if ((V & 3) != 0) |
| 4202 | return false; |
| 4203 | V >>= 2; |
| 4204 | return V == (V & ((1LL << 8) - 1)); |
| 4205 | } |
| 4206 | } |
| 4207 | |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 4208 | /// isLegalAddressImmediate - Return true if the integer value can be used |
| 4209 | /// as the offset of the target addressing mode for load / store of the |
| 4210 | /// given type. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4211 | static bool isLegalAddressImmediate(int64_t V, EVT VT, |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 4212 | const ARMSubtarget *Subtarget) { |
Evan Cheng | 961f879 | 2007-03-13 20:37:59 +0000 | [diff] [blame] | 4213 | if (V == 0) |
| 4214 | return true; |
| 4215 | |
Evan Cheng | 6501153 | 2009-03-09 19:15:00 +0000 | [diff] [blame] | 4216 | if (!VT.isSimple()) |
| 4217 | return false; |
| 4218 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 4219 | if (Subtarget->isThumb1Only()) |
| 4220 | return isLegalT1AddressImmediate(V, VT); |
| 4221 | else if (Subtarget->isThumb2()) |
| 4222 | return isLegalT2AddressImmediate(V, VT, Subtarget); |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 4223 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 4224 | // ARM mode. |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 4225 | if (V < 0) |
| 4226 | V = - V; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4227 | switch (VT.getSimpleVT().SimpleTy) { |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 4228 | default: return false; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4229 | case MVT::i1: |
| 4230 | case MVT::i8: |
| 4231 | case MVT::i32: |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 4232 | // +- imm12 |
Anton Korobeynikov | 7c1c261 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 4233 | return V == (V & ((1LL << 12) - 1)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4234 | case MVT::i16: |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 4235 | // +- imm8 |
Anton Korobeynikov | 7c1c261 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 4236 | return V == (V & ((1LL << 8) - 1)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4237 | case MVT::f32: |
| 4238 | case MVT::f64: |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 4239 | if (!Subtarget->hasVFP2()) // FIXME: NEON? |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 4240 | return false; |
Evan Cheng | 0b0a9a9 | 2007-05-03 02:00:18 +0000 | [diff] [blame] | 4241 | if ((V & 3) != 0) |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 4242 | return false; |
| 4243 | V >>= 2; |
Anton Korobeynikov | 7c1c261 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 4244 | return V == (V & ((1LL << 8) - 1)); |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 4245 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4246 | } |
| 4247 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 4248 | bool ARMTargetLowering::isLegalT2ScaledAddressingMode(const AddrMode &AM, |
| 4249 | EVT VT) const { |
| 4250 | int Scale = AM.Scale; |
| 4251 | if (Scale < 0) |
| 4252 | return false; |
| 4253 | |
| 4254 | switch (VT.getSimpleVT().SimpleTy) { |
| 4255 | default: return false; |
| 4256 | case MVT::i1: |
| 4257 | case MVT::i8: |
| 4258 | case MVT::i16: |
| 4259 | case MVT::i32: |
| 4260 | if (Scale == 1) |
| 4261 | return true; |
| 4262 | // r + r << imm |
| 4263 | Scale = Scale & ~1; |
| 4264 | return Scale == 2 || Scale == 4 || Scale == 8; |
| 4265 | case MVT::i64: |
| 4266 | // r + r |
| 4267 | if (((unsigned)AM.HasBaseReg + Scale) <= 2) |
| 4268 | return true; |
| 4269 | return false; |
| 4270 | case MVT::isVoid: |
| 4271 | // Note, we allow "void" uses (basically, uses that aren't loads or |
| 4272 | // stores), because arm allows folding a scale into many arithmetic |
| 4273 | // operations. This should be made more precise and revisited later. |
| 4274 | |
| 4275 | // Allow r << imm, but the imm has to be a multiple of two. |
| 4276 | if (Scale & 1) return false; |
| 4277 | return isPowerOf2_32(Scale); |
| 4278 | } |
| 4279 | } |
| 4280 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 4281 | /// isLegalAddressingMode - Return true if the addressing mode represented |
| 4282 | /// 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] | 4283 | bool ARMTargetLowering::isLegalAddressingMode(const AddrMode &AM, |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 4284 | const Type *Ty) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4285 | EVT VT = getValueType(Ty, true); |
Bob Wilson | 2c7dab1 | 2009-04-08 17:55:28 +0000 | [diff] [blame] | 4286 | if (!isLegalAddressImmediate(AM.BaseOffs, VT, Subtarget)) |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 4287 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 4288 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 4289 | // Can never fold addr of global into load/store. |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 4290 | if (AM.BaseGV) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 4291 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 4292 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 4293 | switch (AM.Scale) { |
| 4294 | case 0: // no scale reg, must be "r+i" or "r", or "i". |
| 4295 | break; |
| 4296 | case 1: |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 4297 | if (Subtarget->isThumb1Only()) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 4298 | return false; |
Chris Lattner | 5a3d40d | 2007-04-13 06:50:55 +0000 | [diff] [blame] | 4299 | // FALL THROUGH. |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 4300 | default: |
Chris Lattner | 5a3d40d | 2007-04-13 06:50:55 +0000 | [diff] [blame] | 4301 | // ARM doesn't support any R+R*scale+imm addr modes. |
| 4302 | if (AM.BaseOffs) |
| 4303 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 4304 | |
Bob Wilson | 2c7dab1 | 2009-04-08 17:55:28 +0000 | [diff] [blame] | 4305 | if (!VT.isSimple()) |
| 4306 | return false; |
| 4307 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 4308 | if (Subtarget->isThumb2()) |
| 4309 | return isLegalT2ScaledAddressingMode(AM, VT); |
| 4310 | |
Chris Lattner | eb13d1b | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 4311 | int Scale = AM.Scale; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4312 | switch (VT.getSimpleVT().SimpleTy) { |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 4313 | default: return false; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4314 | case MVT::i1: |
| 4315 | case MVT::i8: |
| 4316 | case MVT::i32: |
Chris Lattner | eb13d1b | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 4317 | if (Scale < 0) Scale = -Scale; |
| 4318 | if (Scale == 1) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 4319 | return true; |
| 4320 | // r + r << imm |
Chris Lattner | e115294 | 2007-04-11 16:17:12 +0000 | [diff] [blame] | 4321 | return isPowerOf2_32(Scale & ~1); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4322 | case MVT::i16: |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 4323 | case MVT::i64: |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 4324 | // r + r |
Chris Lattner | eb13d1b | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 4325 | if (((unsigned)AM.HasBaseReg + Scale) <= 2) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 4326 | return true; |
Chris Lattner | e115294 | 2007-04-11 16:17:12 +0000 | [diff] [blame] | 4327 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 4328 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4329 | case MVT::isVoid: |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 4330 | // Note, we allow "void" uses (basically, uses that aren't loads or |
| 4331 | // stores), because arm allows folding a scale into many arithmetic |
| 4332 | // operations. This should be made more precise and revisited later. |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 4333 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 4334 | // 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] | 4335 | if (Scale & 1) return false; |
| 4336 | return isPowerOf2_32(Scale); |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 4337 | } |
| 4338 | break; |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 4339 | } |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 4340 | return true; |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 4341 | } |
| 4342 | |
Evan Cheng | 77e4751 | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 4343 | /// isLegalICmpImmediate - Return true if the specified immediate is legal |
| 4344 | /// icmp immediate, that is the target has icmp instructions which can compare |
| 4345 | /// a register against the immediate without having to materialize the |
| 4346 | /// immediate into a register. |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 4347 | bool ARMTargetLowering::isLegalICmpImmediate(int64_t Imm) const { |
Evan Cheng | 77e4751 | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 4348 | if (!Subtarget->isThumb()) |
| 4349 | return ARM_AM::getSOImmVal(Imm) != -1; |
| 4350 | if (Subtarget->isThumb2()) |
| 4351 | return ARM_AM::getT2SOImmVal(Imm) != -1; |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 4352 | return Imm >= 0 && Imm <= 255; |
Evan Cheng | 77e4751 | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 4353 | } |
| 4354 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4355 | static bool getARMIndexedAddressParts(SDNode *Ptr, EVT VT, |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 4356 | bool isSEXTLoad, SDValue &Base, |
| 4357 | SDValue &Offset, bool &isInc, |
| 4358 | SelectionDAG &DAG) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4359 | if (Ptr->getOpcode() != ISD::ADD && Ptr->getOpcode() != ISD::SUB) |
| 4360 | return false; |
| 4361 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4362 | if (VT == MVT::i16 || ((VT == MVT::i8 || VT == MVT::i1) && isSEXTLoad)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4363 | // AddressingMode 3 |
| 4364 | Base = Ptr->getOperand(0); |
| 4365 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 4366 | int RHSC = (int)RHS->getZExtValue(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4367 | if (RHSC < 0 && RHSC > -256) { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 4368 | assert(Ptr->getOpcode() == ISD::ADD); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4369 | isInc = false; |
| 4370 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); |
| 4371 | return true; |
| 4372 | } |
| 4373 | } |
| 4374 | isInc = (Ptr->getOpcode() == ISD::ADD); |
| 4375 | Offset = Ptr->getOperand(1); |
| 4376 | return true; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4377 | } else if (VT == MVT::i32 || VT == MVT::i8 || VT == MVT::i1) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4378 | // AddressingMode 2 |
| 4379 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 4380 | int RHSC = (int)RHS->getZExtValue(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4381 | if (RHSC < 0 && RHSC > -0x1000) { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 4382 | assert(Ptr->getOpcode() == ISD::ADD); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4383 | isInc = false; |
| 4384 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); |
| 4385 | Base = Ptr->getOperand(0); |
| 4386 | return true; |
| 4387 | } |
| 4388 | } |
| 4389 | |
| 4390 | if (Ptr->getOpcode() == ISD::ADD) { |
| 4391 | isInc = true; |
| 4392 | ARM_AM::ShiftOpc ShOpcVal= ARM_AM::getShiftOpcForNode(Ptr->getOperand(0)); |
| 4393 | if (ShOpcVal != ARM_AM::no_shift) { |
| 4394 | Base = Ptr->getOperand(1); |
| 4395 | Offset = Ptr->getOperand(0); |
| 4396 | } else { |
| 4397 | Base = Ptr->getOperand(0); |
| 4398 | Offset = Ptr->getOperand(1); |
| 4399 | } |
| 4400 | return true; |
| 4401 | } |
| 4402 | |
| 4403 | isInc = (Ptr->getOpcode() == ISD::ADD); |
| 4404 | Base = Ptr->getOperand(0); |
| 4405 | Offset = Ptr->getOperand(1); |
| 4406 | return true; |
| 4407 | } |
| 4408 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 4409 | // FIXME: Use VLDM / VSTM to emulate indexed FP load / store. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4410 | return false; |
| 4411 | } |
| 4412 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4413 | static bool getT2IndexedAddressParts(SDNode *Ptr, EVT VT, |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 4414 | bool isSEXTLoad, SDValue &Base, |
| 4415 | SDValue &Offset, bool &isInc, |
| 4416 | SelectionDAG &DAG) { |
| 4417 | if (Ptr->getOpcode() != ISD::ADD && Ptr->getOpcode() != ISD::SUB) |
| 4418 | return false; |
| 4419 | |
| 4420 | Base = Ptr->getOperand(0); |
| 4421 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
| 4422 | int RHSC = (int)RHS->getZExtValue(); |
| 4423 | if (RHSC < 0 && RHSC > -0x100) { // 8 bits. |
| 4424 | assert(Ptr->getOpcode() == ISD::ADD); |
| 4425 | isInc = false; |
| 4426 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); |
| 4427 | return true; |
| 4428 | } else if (RHSC > 0 && RHSC < 0x100) { // 8 bit, no zero. |
| 4429 | isInc = Ptr->getOpcode() == ISD::ADD; |
| 4430 | Offset = DAG.getConstant(RHSC, RHS->getValueType(0)); |
| 4431 | return true; |
| 4432 | } |
| 4433 | } |
| 4434 | |
| 4435 | return false; |
| 4436 | } |
| 4437 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4438 | /// getPreIndexedAddressParts - returns true by value, base pointer and |
| 4439 | /// offset pointer and addressing mode by reference if the node's address |
| 4440 | /// can be legally represented as pre-indexed load / store address. |
| 4441 | bool |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4442 | ARMTargetLowering::getPreIndexedAddressParts(SDNode *N, SDValue &Base, |
| 4443 | SDValue &Offset, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4444 | ISD::MemIndexedMode &AM, |
Dan Gohman | 73e0914 | 2009-01-15 16:29:45 +0000 | [diff] [blame] | 4445 | SelectionDAG &DAG) const { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 4446 | if (Subtarget->isThumb1Only()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4447 | return false; |
| 4448 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4449 | EVT VT; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4450 | SDValue Ptr; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4451 | bool isSEXTLoad = false; |
| 4452 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) { |
| 4453 | Ptr = LD->getBasePtr(); |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 4454 | VT = LD->getMemoryVT(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4455 | isSEXTLoad = LD->getExtensionType() == ISD::SEXTLOAD; |
| 4456 | } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) { |
| 4457 | Ptr = ST->getBasePtr(); |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 4458 | VT = ST->getMemoryVT(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4459 | } else |
| 4460 | return false; |
| 4461 | |
| 4462 | bool isInc; |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 4463 | bool isLegal = false; |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 4464 | if (Subtarget->isThumb2()) |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 4465 | isLegal = getT2IndexedAddressParts(Ptr.getNode(), VT, isSEXTLoad, Base, |
| 4466 | Offset, isInc, DAG); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 4467 | else |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 4468 | isLegal = getARMIndexedAddressParts(Ptr.getNode(), VT, isSEXTLoad, Base, |
Evan Cheng | 0412957 | 2009-07-02 06:44:30 +0000 | [diff] [blame] | 4469 | Offset, isInc, DAG); |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 4470 | if (!isLegal) |
| 4471 | return false; |
| 4472 | |
| 4473 | AM = isInc ? ISD::PRE_INC : ISD::PRE_DEC; |
| 4474 | return true; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4475 | } |
| 4476 | |
| 4477 | /// getPostIndexedAddressParts - returns true by value, base pointer and |
| 4478 | /// offset pointer and addressing mode by reference if this node can be |
| 4479 | /// combined with a load / store to form a post-indexed load / store. |
| 4480 | bool ARMTargetLowering::getPostIndexedAddressParts(SDNode *N, SDNode *Op, |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4481 | SDValue &Base, |
| 4482 | SDValue &Offset, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4483 | ISD::MemIndexedMode &AM, |
Dan Gohman | 73e0914 | 2009-01-15 16:29:45 +0000 | [diff] [blame] | 4484 | SelectionDAG &DAG) const { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 4485 | if (Subtarget->isThumb1Only()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4486 | return false; |
| 4487 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4488 | EVT VT; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4489 | SDValue Ptr; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4490 | bool isSEXTLoad = false; |
| 4491 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) { |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 4492 | VT = LD->getMemoryVT(); |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 4493 | Ptr = LD->getBasePtr(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4494 | isSEXTLoad = LD->getExtensionType() == ISD::SEXTLOAD; |
| 4495 | } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) { |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 4496 | VT = ST->getMemoryVT(); |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 4497 | Ptr = ST->getBasePtr(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4498 | } else |
| 4499 | return false; |
| 4500 | |
| 4501 | bool isInc; |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 4502 | bool isLegal = false; |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 4503 | if (Subtarget->isThumb2()) |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 4504 | isLegal = getT2IndexedAddressParts(Op, VT, isSEXTLoad, Base, Offset, |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 4505 | isInc, DAG); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 4506 | else |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 4507 | isLegal = getARMIndexedAddressParts(Op, VT, isSEXTLoad, Base, Offset, |
| 4508 | isInc, DAG); |
| 4509 | if (!isLegal) |
| 4510 | return false; |
| 4511 | |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 4512 | if (Ptr != Base) { |
| 4513 | // Swap base ptr and offset to catch more post-index load / store when |
| 4514 | // it's legal. In Thumb2 mode, offset must be an immediate. |
| 4515 | if (Ptr == Offset && Op->getOpcode() == ISD::ADD && |
| 4516 | !Subtarget->isThumb2()) |
| 4517 | std::swap(Base, Offset); |
| 4518 | |
| 4519 | // Post-indexed load / store update the base pointer. |
| 4520 | if (Ptr != Base) |
| 4521 | return false; |
| 4522 | } |
| 4523 | |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 4524 | AM = isInc ? ISD::POST_INC : ISD::POST_DEC; |
| 4525 | return true; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4526 | } |
| 4527 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4528 | void ARMTargetLowering::computeMaskedBitsForTargetNode(const SDValue Op, |
Dan Gohman | 977a76f | 2008-02-13 22:28:48 +0000 | [diff] [blame] | 4529 | const APInt &Mask, |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 4530 | APInt &KnownZero, |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 4531 | APInt &KnownOne, |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 4532 | const SelectionDAG &DAG, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4533 | unsigned Depth) const { |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 4534 | KnownZero = KnownOne = APInt(Mask.getBitWidth(), 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4535 | switch (Op.getOpcode()) { |
| 4536 | default: break; |
| 4537 | case ARMISD::CMOV: { |
| 4538 | // Bits are known zero/one if known on the LHS and RHS. |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 4539 | DAG.ComputeMaskedBits(Op.getOperand(0), Mask, KnownZero, KnownOne, Depth+1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4540 | if (KnownZero == 0 && KnownOne == 0) return; |
| 4541 | |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 4542 | APInt KnownZeroRHS, KnownOneRHS; |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 4543 | DAG.ComputeMaskedBits(Op.getOperand(1), Mask, |
| 4544 | KnownZeroRHS, KnownOneRHS, Depth+1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4545 | KnownZero &= KnownZeroRHS; |
| 4546 | KnownOne &= KnownOneRHS; |
| 4547 | return; |
| 4548 | } |
| 4549 | } |
| 4550 | } |
| 4551 | |
| 4552 | //===----------------------------------------------------------------------===// |
| 4553 | // ARM Inline Assembly Support |
| 4554 | //===----------------------------------------------------------------------===// |
| 4555 | |
| 4556 | /// getConstraintType - Given a constraint letter, return the type of |
| 4557 | /// constraint it is for this target. |
| 4558 | ARMTargetLowering::ConstraintType |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 4559 | ARMTargetLowering::getConstraintType(const std::string &Constraint) const { |
| 4560 | if (Constraint.size() == 1) { |
| 4561 | switch (Constraint[0]) { |
| 4562 | default: break; |
| 4563 | case 'l': return C_RegisterClass; |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 4564 | case 'w': return C_RegisterClass; |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 4565 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4566 | } |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 4567 | return TargetLowering::getConstraintType(Constraint); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4568 | } |
| 4569 | |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 4570 | std::pair<unsigned, const TargetRegisterClass*> |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4571 | ARMTargetLowering::getRegForInlineAsmConstraint(const std::string &Constraint, |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4572 | EVT VT) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4573 | if (Constraint.size() == 1) { |
Jakob Stoklund Olesen | 09bf003 | 2010-01-14 18:19:56 +0000 | [diff] [blame] | 4574 | // GCC ARM Constraint Letters |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4575 | switch (Constraint[0]) { |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 4576 | case 'l': |
Jakob Stoklund Olesen | 09bf003 | 2010-01-14 18:19:56 +0000 | [diff] [blame] | 4577 | if (Subtarget->isThumb()) |
Jim Grosbach | 30eae3c | 2009-04-07 20:34:09 +0000 | [diff] [blame] | 4578 | return std::make_pair(0U, ARM::tGPRRegisterClass); |
| 4579 | else |
| 4580 | return std::make_pair(0U, ARM::GPRRegisterClass); |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 4581 | case 'r': |
| 4582 | return std::make_pair(0U, ARM::GPRRegisterClass); |
| 4583 | case 'w': |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4584 | if (VT == MVT::f32) |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 4585 | return std::make_pair(0U, ARM::SPRRegisterClass); |
Bob Wilson | 5afffae | 2009-12-18 01:03:29 +0000 | [diff] [blame] | 4586 | if (VT.getSizeInBits() == 64) |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 4587 | return std::make_pair(0U, ARM::DPRRegisterClass); |
Evan Cheng | d831cda | 2009-12-08 23:06:22 +0000 | [diff] [blame] | 4588 | if (VT.getSizeInBits() == 128) |
| 4589 | return std::make_pair(0U, ARM::QPRRegisterClass); |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 4590 | break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4591 | } |
| 4592 | } |
Bob Wilson | 33cc5cb | 2010-03-15 23:09:18 +0000 | [diff] [blame] | 4593 | if (StringRef("{cc}").equals_lower(Constraint)) |
| 4594 | return std::make_pair(0U, ARM::CCRRegisterClass); |
| 4595 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4596 | return TargetLowering::getRegForInlineAsmConstraint(Constraint, VT); |
| 4597 | } |
| 4598 | |
| 4599 | std::vector<unsigned> ARMTargetLowering:: |
| 4600 | getRegClassForInlineAsmConstraint(const std::string &Constraint, |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4601 | EVT VT) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4602 | if (Constraint.size() != 1) |
| 4603 | return std::vector<unsigned>(); |
| 4604 | |
| 4605 | switch (Constraint[0]) { // GCC ARM Constraint Letters |
| 4606 | default: break; |
| 4607 | case 'l': |
Jim Grosbach | 30eae3c | 2009-04-07 20:34:09 +0000 | [diff] [blame] | 4608 | return make_vector<unsigned>(ARM::R0, ARM::R1, ARM::R2, ARM::R3, |
| 4609 | ARM::R4, ARM::R5, ARM::R6, ARM::R7, |
| 4610 | 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4611 | case 'r': |
| 4612 | return make_vector<unsigned>(ARM::R0, ARM::R1, ARM::R2, ARM::R3, |
| 4613 | ARM::R4, ARM::R5, ARM::R6, ARM::R7, |
| 4614 | ARM::R8, ARM::R9, ARM::R10, ARM::R11, |
| 4615 | ARM::R12, ARM::LR, 0); |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 4616 | case 'w': |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4617 | if (VT == MVT::f32) |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 4618 | return make_vector<unsigned>(ARM::S0, ARM::S1, ARM::S2, ARM::S3, |
| 4619 | ARM::S4, ARM::S5, ARM::S6, ARM::S7, |
| 4620 | ARM::S8, ARM::S9, ARM::S10, ARM::S11, |
| 4621 | ARM::S12,ARM::S13,ARM::S14,ARM::S15, |
| 4622 | ARM::S16,ARM::S17,ARM::S18,ARM::S19, |
| 4623 | ARM::S20,ARM::S21,ARM::S22,ARM::S23, |
| 4624 | ARM::S24,ARM::S25,ARM::S26,ARM::S27, |
| 4625 | ARM::S28,ARM::S29,ARM::S30,ARM::S31, 0); |
Bob Wilson | 5afffae | 2009-12-18 01:03:29 +0000 | [diff] [blame] | 4626 | if (VT.getSizeInBits() == 64) |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 4627 | return make_vector<unsigned>(ARM::D0, ARM::D1, ARM::D2, ARM::D3, |
| 4628 | ARM::D4, ARM::D5, ARM::D6, ARM::D7, |
| 4629 | ARM::D8, ARM::D9, ARM::D10,ARM::D11, |
| 4630 | ARM::D12,ARM::D13,ARM::D14,ARM::D15, 0); |
Evan Cheng | d831cda | 2009-12-08 23:06:22 +0000 | [diff] [blame] | 4631 | if (VT.getSizeInBits() == 128) |
| 4632 | return make_vector<unsigned>(ARM::Q0, ARM::Q1, ARM::Q2, ARM::Q3, |
| 4633 | ARM::Q4, ARM::Q5, ARM::Q6, ARM::Q7, 0); |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 4634 | break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4635 | } |
| 4636 | |
| 4637 | return std::vector<unsigned>(); |
| 4638 | } |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 4639 | |
| 4640 | /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops |
| 4641 | /// vector. If it is invalid, don't add anything to Ops. |
| 4642 | void ARMTargetLowering::LowerAsmOperandForConstraint(SDValue Op, |
| 4643 | char Constraint, |
| 4644 | bool hasMemory, |
| 4645 | std::vector<SDValue>&Ops, |
| 4646 | SelectionDAG &DAG) const { |
| 4647 | SDValue Result(0, 0); |
| 4648 | |
| 4649 | switch (Constraint) { |
| 4650 | default: break; |
| 4651 | case 'I': case 'J': case 'K': case 'L': |
| 4652 | case 'M': case 'N': case 'O': |
| 4653 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op); |
| 4654 | if (!C) |
| 4655 | return; |
| 4656 | |
| 4657 | int64_t CVal64 = C->getSExtValue(); |
| 4658 | int CVal = (int) CVal64; |
| 4659 | // None of these constraints allow values larger than 32 bits. Check |
| 4660 | // that the value fits in an int. |
| 4661 | if (CVal != CVal64) |
| 4662 | return; |
| 4663 | |
| 4664 | switch (Constraint) { |
| 4665 | case 'I': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 4666 | if (Subtarget->isThumb1Only()) { |
| 4667 | // This must be a constant between 0 and 255, for ADD |
| 4668 | // immediates. |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 4669 | if (CVal >= 0 && CVal <= 255) |
| 4670 | break; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 4671 | } else if (Subtarget->isThumb2()) { |
| 4672 | // A constant that can be used as an immediate value in a |
| 4673 | // data-processing instruction. |
| 4674 | if (ARM_AM::getT2SOImmVal(CVal) != -1) |
| 4675 | break; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 4676 | } else { |
| 4677 | // A constant that can be used as an immediate value in a |
| 4678 | // data-processing instruction. |
| 4679 | if (ARM_AM::getSOImmVal(CVal) != -1) |
| 4680 | break; |
| 4681 | } |
| 4682 | return; |
| 4683 | |
| 4684 | case 'J': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 4685 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 4686 | // This must be a constant between -255 and -1, for negated ADD |
| 4687 | // immediates. This can be used in GCC with an "n" modifier that |
| 4688 | // prints the negated value, for use with SUB instructions. It is |
| 4689 | // not useful otherwise but is implemented for compatibility. |
| 4690 | if (CVal >= -255 && CVal <= -1) |
| 4691 | break; |
| 4692 | } else { |
| 4693 | // This must be a constant between -4095 and 4095. It is not clear |
| 4694 | // what this constraint is intended for. Implemented for |
| 4695 | // compatibility with GCC. |
| 4696 | if (CVal >= -4095 && CVal <= 4095) |
| 4697 | break; |
| 4698 | } |
| 4699 | return; |
| 4700 | |
| 4701 | case 'K': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 4702 | if (Subtarget->isThumb1Only()) { |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 4703 | // A 32-bit value where only one byte has a nonzero value. Exclude |
| 4704 | // zero to match GCC. This constraint is used by GCC internally for |
| 4705 | // constants that can be loaded with a move/shift combination. |
| 4706 | // It is not useful otherwise but is implemented for compatibility. |
| 4707 | if (CVal != 0 && ARM_AM::isThumbImmShiftedVal(CVal)) |
| 4708 | break; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 4709 | } else if (Subtarget->isThumb2()) { |
| 4710 | // A constant whose bitwise inverse can be used as an immediate |
| 4711 | // value in a data-processing instruction. This can be used in GCC |
| 4712 | // with a "B" modifier that prints the inverted value, for use with |
| 4713 | // BIC and MVN instructions. It is not useful otherwise but is |
| 4714 | // implemented for compatibility. |
| 4715 | if (ARM_AM::getT2SOImmVal(~CVal) != -1) |
| 4716 | break; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 4717 | } else { |
| 4718 | // A constant whose bitwise inverse can be used as an immediate |
| 4719 | // value in a data-processing instruction. This can be used in GCC |
| 4720 | // with a "B" modifier that prints the inverted value, for use with |
| 4721 | // BIC and MVN instructions. It is not useful otherwise but is |
| 4722 | // implemented for compatibility. |
| 4723 | if (ARM_AM::getSOImmVal(~CVal) != -1) |
| 4724 | break; |
| 4725 | } |
| 4726 | return; |
| 4727 | |
| 4728 | case 'L': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 4729 | if (Subtarget->isThumb1Only()) { |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 4730 | // This must be a constant between -7 and 7, |
| 4731 | // for 3-operand ADD/SUB immediate instructions. |
| 4732 | if (CVal >= -7 && CVal < 7) |
| 4733 | break; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 4734 | } else if (Subtarget->isThumb2()) { |
| 4735 | // A constant whose negation can be used as an immediate value in a |
| 4736 | // data-processing instruction. This can be used in GCC with an "n" |
| 4737 | // modifier that prints the negated value, for use with SUB |
| 4738 | // instructions. It is not useful otherwise but is implemented for |
| 4739 | // compatibility. |
| 4740 | if (ARM_AM::getT2SOImmVal(-CVal) != -1) |
| 4741 | break; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 4742 | } else { |
| 4743 | // A constant whose negation can be used as an immediate value in a |
| 4744 | // data-processing instruction. This can be used in GCC with an "n" |
| 4745 | // modifier that prints the negated value, for use with SUB |
| 4746 | // instructions. It is not useful otherwise but is implemented for |
| 4747 | // compatibility. |
| 4748 | if (ARM_AM::getSOImmVal(-CVal) != -1) |
| 4749 | break; |
| 4750 | } |
| 4751 | return; |
| 4752 | |
| 4753 | case 'M': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 4754 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 4755 | // This must be a multiple of 4 between 0 and 1020, for |
| 4756 | // ADD sp + immediate. |
| 4757 | if ((CVal >= 0 && CVal <= 1020) && ((CVal & 3) == 0)) |
| 4758 | break; |
| 4759 | } else { |
| 4760 | // A power of two or a constant between 0 and 32. This is used in |
| 4761 | // GCC for the shift amount on shifted register operands, but it is |
| 4762 | // useful in general for any shift amounts. |
| 4763 | if ((CVal >= 0 && CVal <= 32) || ((CVal & (CVal - 1)) == 0)) |
| 4764 | break; |
| 4765 | } |
| 4766 | return; |
| 4767 | |
| 4768 | case 'N': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 4769 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 4770 | // This must be a constant between 0 and 31, for shift amounts. |
| 4771 | if (CVal >= 0 && CVal <= 31) |
| 4772 | break; |
| 4773 | } |
| 4774 | return; |
| 4775 | |
| 4776 | case 'O': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 4777 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 4778 | // This must be a multiple of 4 between -508 and 508, for |
| 4779 | // ADD/SUB sp = sp + immediate. |
| 4780 | if ((CVal >= -508 && CVal <= 508) && ((CVal & 3) == 0)) |
| 4781 | break; |
| 4782 | } |
| 4783 | return; |
| 4784 | } |
| 4785 | Result = DAG.getTargetConstant(CVal, Op.getValueType()); |
| 4786 | break; |
| 4787 | } |
| 4788 | |
| 4789 | if (Result.getNode()) { |
| 4790 | Ops.push_back(Result); |
| 4791 | return; |
| 4792 | } |
| 4793 | return TargetLowering::LowerAsmOperandForConstraint(Op, Constraint, hasMemory, |
| 4794 | Ops, DAG); |
| 4795 | } |
Anton Korobeynikov | 48e1935 | 2009-09-23 19:04:09 +0000 | [diff] [blame] | 4796 | |
| 4797 | bool |
| 4798 | ARMTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const { |
| 4799 | // The ARM target isn't yet aware of offsets. |
| 4800 | return false; |
| 4801 | } |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 4802 | |
| 4803 | int ARM::getVFPf32Imm(const APFloat &FPImm) { |
| 4804 | APInt Imm = FPImm.bitcastToAPInt(); |
| 4805 | uint32_t Sign = Imm.lshr(31).getZExtValue() & 1; |
| 4806 | int32_t Exp = (Imm.lshr(23).getSExtValue() & 0xff) - 127; // -126 to 127 |
| 4807 | int64_t Mantissa = Imm.getZExtValue() & 0x7fffff; // 23 bits |
| 4808 | |
| 4809 | // We can handle 4 bits of mantissa. |
| 4810 | // mantissa = (16+UInt(e:f:g:h))/16. |
| 4811 | if (Mantissa & 0x7ffff) |
| 4812 | return -1; |
| 4813 | Mantissa >>= 19; |
| 4814 | if ((Mantissa & 0xf) != Mantissa) |
| 4815 | return -1; |
| 4816 | |
| 4817 | // We can handle 3 bits of exponent: exp == UInt(NOT(b):c:d)-3 |
| 4818 | if (Exp < -3 || Exp > 4) |
| 4819 | return -1; |
| 4820 | Exp = ((Exp+3) & 0x7) ^ 4; |
| 4821 | |
| 4822 | return ((int)Sign << 7) | (Exp << 4) | Mantissa; |
| 4823 | } |
| 4824 | |
| 4825 | int ARM::getVFPf64Imm(const APFloat &FPImm) { |
| 4826 | APInt Imm = FPImm.bitcastToAPInt(); |
| 4827 | uint64_t Sign = Imm.lshr(63).getZExtValue() & 1; |
| 4828 | int64_t Exp = (Imm.lshr(52).getSExtValue() & 0x7ff) - 1023; // -1022 to 1023 |
| 4829 | uint64_t Mantissa = Imm.getZExtValue() & 0xfffffffffffffLL; |
| 4830 | |
| 4831 | // We can handle 4 bits of mantissa. |
| 4832 | // mantissa = (16+UInt(e:f:g:h))/16. |
| 4833 | if (Mantissa & 0xffffffffffffLL) |
| 4834 | return -1; |
| 4835 | Mantissa >>= 48; |
| 4836 | if ((Mantissa & 0xf) != Mantissa) |
| 4837 | return -1; |
| 4838 | |
| 4839 | // We can handle 3 bits of exponent: exp == UInt(NOT(b):c:d)-3 |
| 4840 | if (Exp < -3 || Exp > 4) |
| 4841 | return -1; |
| 4842 | Exp = ((Exp+3) & 0x7) ^ 4; |
| 4843 | |
| 4844 | return ((int)Sign << 7) | (Exp << 4) | Mantissa; |
| 4845 | } |
| 4846 | |
| 4847 | /// isFPImmLegal - Returns true if the target can instruction select the |
| 4848 | /// specified FP immediate natively. If false, the legalizer will |
| 4849 | /// materialize the FP immediate as a load from a constant pool. |
| 4850 | bool ARMTargetLowering::isFPImmLegal(const APFloat &Imm, EVT VT) const { |
| 4851 | if (!Subtarget->hasVFP3()) |
| 4852 | return false; |
| 4853 | if (VT == MVT::f32) |
| 4854 | return ARM::getVFPf32Imm(Imm) != -1; |
| 4855 | if (VT == MVT::f64) |
| 4856 | return ARM::getVFPf64Imm(Imm) != -1; |
| 4857 | return false; |
| 4858 | } |