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" |
| 20 | #include "ARMRegisterInfo.h" |
| 21 | #include "ARMSubtarget.h" |
| 22 | #include "ARMTargetMachine.h" |
| 23 | #include "llvm/CallingConv.h" |
| 24 | #include "llvm/Constants.h" |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 25 | #include "llvm/Function.h" |
Evan Cheng | 2770747 | 2007-03-16 08:43:56 +0000 | [diff] [blame] | 26 | #include "llvm/Instruction.h" |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 27 | #include "llvm/Intrinsics.h" |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 28 | #include "llvm/GlobalValue.h" |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 29 | #include "llvm/CodeGen/CallingConvLower.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 30 | #include "llvm/CodeGen/MachineBasicBlock.h" |
| 31 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 32 | #include "llvm/CodeGen/MachineFunction.h" |
| 33 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 34 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 35 | #include "llvm/CodeGen/PseudoSourceValue.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 36 | #include "llvm/CodeGen/SelectionDAG.h" |
Evan Cheng | b6ab254 | 2007-01-31 08:40:13 +0000 | [diff] [blame] | 37 | #include "llvm/Target/TargetOptions.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 38 | #include "llvm/ADT/VectorExtras.h" |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 39 | #include "llvm/Support/MathExtras.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 40 | using namespace llvm; |
| 41 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 42 | static bool CC_ARM_APCS_Custom_f64(unsigned &ValNo, MVT &ValVT, MVT &LocVT, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 43 | CCValAssign::LocInfo &LocInfo, |
| 44 | ISD::ArgFlagsTy &ArgFlags, |
| 45 | CCState &State); |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 46 | static bool CC_ARM_AAPCS_Custom_f64(unsigned &ValNo, MVT &ValVT, MVT &LocVT, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 47 | CCValAssign::LocInfo &LocInfo, |
| 48 | ISD::ArgFlagsTy &ArgFlags, |
| 49 | CCState &State); |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 50 | static bool RetCC_ARM_APCS_Custom_f64(unsigned &ValNo, MVT &ValVT, MVT &LocVT, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 51 | CCValAssign::LocInfo &LocInfo, |
| 52 | ISD::ArgFlagsTy &ArgFlags, |
| 53 | CCState &State); |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 54 | static bool RetCC_ARM_AAPCS_Custom_f64(unsigned &ValNo, MVT &ValVT, MVT &LocVT, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 55 | CCValAssign::LocInfo &LocInfo, |
| 56 | ISD::ArgFlagsTy &ArgFlags, |
| 57 | CCState &State); |
| 58 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 59 | void ARMTargetLowering::addTypeForNEON(MVT VT, MVT PromotedLdStVT, |
| 60 | MVT PromotedBitwiseVT) { |
| 61 | if (VT != PromotedLdStVT) { |
| 62 | setOperationAction(ISD::LOAD, VT, Promote); |
| 63 | AddPromotedToType (ISD::LOAD, VT, PromotedLdStVT); |
| 64 | |
| 65 | setOperationAction(ISD::STORE, VT, Promote); |
| 66 | AddPromotedToType (ISD::STORE, VT, PromotedLdStVT); |
| 67 | } |
| 68 | |
| 69 | MVT ElemTy = VT.getVectorElementType(); |
| 70 | if (ElemTy != MVT::i64 && ElemTy != MVT::f64) |
| 71 | setOperationAction(ISD::VSETCC, VT, Custom); |
| 72 | if (ElemTy == MVT::i8 || ElemTy == MVT::i16) |
| 73 | setOperationAction(ISD::EXTRACT_VECTOR_ELT, VT, Custom); |
| 74 | setOperationAction(ISD::BUILD_VECTOR, VT, Custom); |
| 75 | setOperationAction(ISD::VECTOR_SHUFFLE, VT, Custom); |
| 76 | setOperationAction(ISD::SCALAR_TO_VECTOR, VT, Custom); |
| 77 | setOperationAction(ISD::CONCAT_VECTORS, VT, Custom); |
| 78 | if (VT.isInteger()) { |
| 79 | setOperationAction(ISD::SHL, VT, Custom); |
| 80 | setOperationAction(ISD::SRA, VT, Custom); |
| 81 | setOperationAction(ISD::SRL, VT, Custom); |
| 82 | } |
| 83 | |
| 84 | // Promote all bit-wise operations. |
| 85 | if (VT.isInteger() && VT != PromotedBitwiseVT) { |
| 86 | setOperationAction(ISD::AND, VT, Promote); |
| 87 | AddPromotedToType (ISD::AND, VT, PromotedBitwiseVT); |
| 88 | setOperationAction(ISD::OR, VT, Promote); |
| 89 | AddPromotedToType (ISD::OR, VT, PromotedBitwiseVT); |
| 90 | setOperationAction(ISD::XOR, VT, Promote); |
| 91 | AddPromotedToType (ISD::XOR, VT, PromotedBitwiseVT); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | void ARMTargetLowering::addDRTypeForNEON(MVT VT) { |
| 96 | addRegisterClass(VT, ARM::DPRRegisterClass); |
| 97 | addTypeForNEON(VT, MVT::f64, MVT::v2i32); |
| 98 | } |
| 99 | |
| 100 | void ARMTargetLowering::addQRTypeForNEON(MVT VT) { |
| 101 | addRegisterClass(VT, ARM::QPRRegisterClass); |
| 102 | addTypeForNEON(VT, MVT::v2f64, MVT::v4i32); |
| 103 | } |
| 104 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 105 | ARMTargetLowering::ARMTargetLowering(TargetMachine &TM) |
| 106 | : TargetLowering(TM), ARMPCLabelIndex(0) { |
| 107 | Subtarget = &TM.getSubtarget<ARMSubtarget>(); |
| 108 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 109 | if (Subtarget->isTargetDarwin()) { |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 110 | // Uses VFP for Thumb libfuncs if available. |
| 111 | if (Subtarget->isThumb() && Subtarget->hasVFP2()) { |
| 112 | // Single-precision floating-point arithmetic. |
| 113 | setLibcallName(RTLIB::ADD_F32, "__addsf3vfp"); |
| 114 | setLibcallName(RTLIB::SUB_F32, "__subsf3vfp"); |
| 115 | setLibcallName(RTLIB::MUL_F32, "__mulsf3vfp"); |
| 116 | setLibcallName(RTLIB::DIV_F32, "__divsf3vfp"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 117 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 118 | // Double-precision floating-point arithmetic. |
| 119 | setLibcallName(RTLIB::ADD_F64, "__adddf3vfp"); |
| 120 | setLibcallName(RTLIB::SUB_F64, "__subdf3vfp"); |
| 121 | setLibcallName(RTLIB::MUL_F64, "__muldf3vfp"); |
| 122 | setLibcallName(RTLIB::DIV_F64, "__divdf3vfp"); |
Evan Cheng | 193f850 | 2007-01-31 09:30:58 +0000 | [diff] [blame] | 123 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 124 | // Single-precision comparisons. |
| 125 | setLibcallName(RTLIB::OEQ_F32, "__eqsf2vfp"); |
| 126 | setLibcallName(RTLIB::UNE_F32, "__nesf2vfp"); |
| 127 | setLibcallName(RTLIB::OLT_F32, "__ltsf2vfp"); |
| 128 | setLibcallName(RTLIB::OLE_F32, "__lesf2vfp"); |
| 129 | setLibcallName(RTLIB::OGE_F32, "__gesf2vfp"); |
| 130 | setLibcallName(RTLIB::OGT_F32, "__gtsf2vfp"); |
| 131 | setLibcallName(RTLIB::UO_F32, "__unordsf2vfp"); |
| 132 | setLibcallName(RTLIB::O_F32, "__unordsf2vfp"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 133 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 134 | setCmpLibcallCC(RTLIB::OEQ_F32, ISD::SETNE); |
| 135 | setCmpLibcallCC(RTLIB::UNE_F32, ISD::SETNE); |
| 136 | setCmpLibcallCC(RTLIB::OLT_F32, ISD::SETNE); |
| 137 | setCmpLibcallCC(RTLIB::OLE_F32, ISD::SETNE); |
| 138 | setCmpLibcallCC(RTLIB::OGE_F32, ISD::SETNE); |
| 139 | setCmpLibcallCC(RTLIB::OGT_F32, ISD::SETNE); |
| 140 | setCmpLibcallCC(RTLIB::UO_F32, ISD::SETNE); |
| 141 | setCmpLibcallCC(RTLIB::O_F32, ISD::SETEQ); |
Evan Cheng | 193f850 | 2007-01-31 09:30:58 +0000 | [diff] [blame] | 142 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 143 | // Double-precision comparisons. |
| 144 | setLibcallName(RTLIB::OEQ_F64, "__eqdf2vfp"); |
| 145 | setLibcallName(RTLIB::UNE_F64, "__nedf2vfp"); |
| 146 | setLibcallName(RTLIB::OLT_F64, "__ltdf2vfp"); |
| 147 | setLibcallName(RTLIB::OLE_F64, "__ledf2vfp"); |
| 148 | setLibcallName(RTLIB::OGE_F64, "__gedf2vfp"); |
| 149 | setLibcallName(RTLIB::OGT_F64, "__gtdf2vfp"); |
| 150 | setLibcallName(RTLIB::UO_F64, "__unorddf2vfp"); |
| 151 | setLibcallName(RTLIB::O_F64, "__unorddf2vfp"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 152 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 153 | setCmpLibcallCC(RTLIB::OEQ_F64, ISD::SETNE); |
| 154 | setCmpLibcallCC(RTLIB::UNE_F64, ISD::SETNE); |
| 155 | setCmpLibcallCC(RTLIB::OLT_F64, ISD::SETNE); |
| 156 | setCmpLibcallCC(RTLIB::OLE_F64, ISD::SETNE); |
| 157 | setCmpLibcallCC(RTLIB::OGE_F64, ISD::SETNE); |
| 158 | setCmpLibcallCC(RTLIB::OGT_F64, ISD::SETNE); |
| 159 | setCmpLibcallCC(RTLIB::UO_F64, ISD::SETNE); |
| 160 | setCmpLibcallCC(RTLIB::O_F64, ISD::SETEQ); |
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 | // Floating-point to integer conversions. |
| 163 | // i64 conversions are done via library routines even when generating VFP |
| 164 | // instructions, so use the same ones. |
| 165 | setLibcallName(RTLIB::FPTOSINT_F64_I32, "__fixdfsivfp"); |
| 166 | setLibcallName(RTLIB::FPTOUINT_F64_I32, "__fixunsdfsivfp"); |
| 167 | setLibcallName(RTLIB::FPTOSINT_F32_I32, "__fixsfsivfp"); |
| 168 | setLibcallName(RTLIB::FPTOUINT_F32_I32, "__fixunssfsivfp"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 169 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 170 | // Conversions between floating types. |
| 171 | setLibcallName(RTLIB::FPROUND_F64_F32, "__truncdfsf2vfp"); |
| 172 | setLibcallName(RTLIB::FPEXT_F32_F64, "__extendsfdf2vfp"); |
| 173 | |
| 174 | // Integer to floating-point conversions. |
| 175 | // i64 conversions are done via library routines even when generating VFP |
| 176 | // instructions, so use the same ones. |
Bob Wilson | 2a14c52 | 2009-03-20 23:16:43 +0000 | [diff] [blame] | 177 | // FIXME: There appears to be some naming inconsistency in ARM libgcc: |
| 178 | // e.g., __floatunsidf vs. __floatunssidfvfp. |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 179 | setLibcallName(RTLIB::SINTTOFP_I32_F64, "__floatsidfvfp"); |
| 180 | setLibcallName(RTLIB::UINTTOFP_I32_F64, "__floatunssidfvfp"); |
| 181 | setLibcallName(RTLIB::SINTTOFP_I32_F32, "__floatsisfvfp"); |
| 182 | setLibcallName(RTLIB::UINTTOFP_I32_F32, "__floatunssisfvfp"); |
| 183 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 184 | } |
| 185 | |
Bob Wilson | 2f95461 | 2009-05-22 17:38:41 +0000 | [diff] [blame] | 186 | // These libcalls are not available in 32-bit. |
| 187 | setLibcallName(RTLIB::SHL_I128, 0); |
| 188 | setLibcallName(RTLIB::SRL_I128, 0); |
| 189 | setLibcallName(RTLIB::SRA_I128, 0); |
| 190 | |
Jim Grosbach | 30eae3c | 2009-04-07 20:34:09 +0000 | [diff] [blame] | 191 | if (Subtarget->isThumb()) |
| 192 | addRegisterClass(MVT::i32, ARM::tGPRRegisterClass); |
| 193 | else |
| 194 | addRegisterClass(MVT::i32, ARM::GPRRegisterClass); |
Evan Cheng | b6ab254 | 2007-01-31 08:40:13 +0000 | [diff] [blame] | 195 | if (!UseSoftFloat && Subtarget->hasVFP2() && !Subtarget->isThumb()) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 196 | addRegisterClass(MVT::f32, ARM::SPRRegisterClass); |
| 197 | addRegisterClass(MVT::f64, ARM::DPRRegisterClass); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 198 | |
Chris Lattner | ddf8956 | 2008-01-17 19:59:44 +0000 | [diff] [blame] | 199 | setTruncStoreAction(MVT::f64, MVT::f32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 200 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 201 | |
| 202 | if (Subtarget->hasNEON()) { |
| 203 | addDRTypeForNEON(MVT::v2f32); |
| 204 | addDRTypeForNEON(MVT::v8i8); |
| 205 | addDRTypeForNEON(MVT::v4i16); |
| 206 | addDRTypeForNEON(MVT::v2i32); |
| 207 | addDRTypeForNEON(MVT::v1i64); |
| 208 | |
| 209 | addQRTypeForNEON(MVT::v4f32); |
| 210 | addQRTypeForNEON(MVT::v2f64); |
| 211 | addQRTypeForNEON(MVT::v16i8); |
| 212 | addQRTypeForNEON(MVT::v8i16); |
| 213 | addQRTypeForNEON(MVT::v4i32); |
| 214 | addQRTypeForNEON(MVT::v2i64); |
| 215 | |
| 216 | setTargetDAGCombine(ISD::INTRINSIC_WO_CHAIN); |
| 217 | setTargetDAGCombine(ISD::SHL); |
| 218 | setTargetDAGCombine(ISD::SRL); |
| 219 | setTargetDAGCombine(ISD::SRA); |
| 220 | setTargetDAGCombine(ISD::SIGN_EXTEND); |
| 221 | setTargetDAGCombine(ISD::ZERO_EXTEND); |
| 222 | setTargetDAGCombine(ISD::ANY_EXTEND); |
| 223 | } |
| 224 | |
Evan Cheng | 9f8cbd1 | 2007-05-18 00:19:34 +0000 | [diff] [blame] | 225 | computeRegisterProperties(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 226 | |
| 227 | // ARM does not have f32 extending load. |
Evan Cheng | 0329466 | 2008-10-14 21:26:46 +0000 | [diff] [blame] | 228 | setLoadExtAction(ISD::EXTLOAD, MVT::f32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 229 | |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 230 | // ARM does not have i1 sign extending load. |
Evan Cheng | 0329466 | 2008-10-14 21:26:46 +0000 | [diff] [blame] | 231 | setLoadExtAction(ISD::SEXTLOAD, MVT::i1, Promote); |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 232 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 233 | // ARM supports all 4 flavors of integer indexed load / store. |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 234 | if (!Subtarget->isThumb1Only()) { |
| 235 | for (unsigned im = (unsigned)ISD::PRE_INC; |
| 236 | im != (unsigned)ISD::LAST_INDEXED_MODE; ++im) { |
| 237 | setIndexedLoadAction(im, MVT::i1, Legal); |
| 238 | setIndexedLoadAction(im, MVT::i8, Legal); |
| 239 | setIndexedLoadAction(im, MVT::i16, Legal); |
| 240 | setIndexedLoadAction(im, MVT::i32, Legal); |
| 241 | setIndexedStoreAction(im, MVT::i1, Legal); |
| 242 | setIndexedStoreAction(im, MVT::i8, Legal); |
| 243 | setIndexedStoreAction(im, MVT::i16, Legal); |
| 244 | setIndexedStoreAction(im, MVT::i32, Legal); |
| 245 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | // i64 operation support. |
| 249 | if (Subtarget->isThumb()) { |
| 250 | setOperationAction(ISD::MUL, MVT::i64, Expand); |
| 251 | setOperationAction(ISD::MULHU, MVT::i32, Expand); |
| 252 | setOperationAction(ISD::MULHS, MVT::i32, Expand); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 253 | setOperationAction(ISD::UMUL_LOHI, MVT::i32, Expand); |
| 254 | setOperationAction(ISD::SMUL_LOHI, MVT::i32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 255 | } else { |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 256 | setOperationAction(ISD::MUL, MVT::i64, Expand); |
| 257 | setOperationAction(ISD::MULHU, MVT::i32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 258 | if (!Subtarget->hasV6Ops()) |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 259 | setOperationAction(ISD::MULHS, MVT::i32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 260 | } |
| 261 | setOperationAction(ISD::SHL_PARTS, MVT::i32, Expand); |
| 262 | setOperationAction(ISD::SRA_PARTS, MVT::i32, Expand); |
| 263 | setOperationAction(ISD::SRL_PARTS, MVT::i32, Expand); |
| 264 | setOperationAction(ISD::SRL, MVT::i64, Custom); |
| 265 | setOperationAction(ISD::SRA, MVT::i64, Custom); |
| 266 | |
| 267 | // ARM does not have ROTL. |
| 268 | setOperationAction(ISD::ROTL, MVT::i32, Expand); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 269 | setOperationAction(ISD::CTTZ, MVT::i32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 270 | setOperationAction(ISD::CTPOP, MVT::i32, Expand); |
David Goodwin | 24062ac | 2009-06-26 20:47:43 +0000 | [diff] [blame] | 271 | if (!Subtarget->hasV5TOps() || Subtarget->isThumb1Only()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 272 | setOperationAction(ISD::CTLZ, MVT::i32, Expand); |
| 273 | |
Lauro Ramos Venancio | 368f20f | 2007-03-16 22:54:16 +0000 | [diff] [blame] | 274 | // Only ARMv6 has BSWAP. |
| 275 | if (!Subtarget->hasV6Ops()) |
Chris Lattner | 1719e13 | 2007-03-20 02:25:53 +0000 | [diff] [blame] | 276 | setOperationAction(ISD::BSWAP, MVT::i32, Expand); |
Lauro Ramos Venancio | 368f20f | 2007-03-16 22:54:16 +0000 | [diff] [blame] | 277 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 278 | // These are expanded into libcalls. |
| 279 | setOperationAction(ISD::SDIV, MVT::i32, Expand); |
| 280 | setOperationAction(ISD::UDIV, MVT::i32, Expand); |
| 281 | setOperationAction(ISD::SREM, MVT::i32, Expand); |
| 282 | setOperationAction(ISD::UREM, MVT::i32, Expand); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 283 | setOperationAction(ISD::SDIVREM, MVT::i32, Expand); |
| 284 | setOperationAction(ISD::UDIVREM, MVT::i32, Expand); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 285 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 286 | // Support label based line numbers. |
Dan Gohman | 7f46020 | 2008-06-30 20:59:49 +0000 | [diff] [blame] | 287 | setOperationAction(ISD::DBG_STOPPOINT, MVT::Other, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 288 | setOperationAction(ISD::DEBUG_LOC, MVT::Other, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 289 | |
| 290 | setOperationAction(ISD::RET, MVT::Other, Custom); |
| 291 | setOperationAction(ISD::GlobalAddress, MVT::i32, Custom); |
| 292 | setOperationAction(ISD::ConstantPool, MVT::i32, Custom); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 293 | setOperationAction(ISD::GLOBAL_OFFSET_TABLE, MVT::i32, Custom); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 294 | setOperationAction(ISD::GlobalTLSAddress, MVT::i32, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 295 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 296 | // Use the default implementation. |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 297 | setOperationAction(ISD::VASTART, MVT::Other, Custom); |
| 298 | setOperationAction(ISD::VAARG, MVT::Other, Expand); |
| 299 | setOperationAction(ISD::VACOPY, MVT::Other, Expand); |
| 300 | setOperationAction(ISD::VAEND, MVT::Other, Expand); |
| 301 | setOperationAction(ISD::STACKSAVE, MVT::Other, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 302 | setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 303 | setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32, Expand); |
| 304 | setOperationAction(ISD::MEMBARRIER, MVT::Other, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 305 | |
Evan Cheng | d27c9fc | 2009-07-03 01:43:10 +0000 | [diff] [blame^] | 306 | if (!Subtarget->hasV6Ops() && !Subtarget->isThumb2()) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 307 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i16, Expand); |
| 308 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i8, Expand); |
| 309 | } |
| 310 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand); |
| 311 | |
Evan Cheng | b6ab254 | 2007-01-31 08:40:13 +0000 | [diff] [blame] | 312 | if (!UseSoftFloat && Subtarget->hasVFP2() && !Subtarget->isThumb()) |
Evan Cheng | c7c7729 | 2008-11-04 19:57:48 +0000 | [diff] [blame] | 313 | // Turn f64->i64 into FMRRD, i64 -> f64 to FMDRR iff target supports vfp2. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 314 | setOperationAction(ISD::BIT_CONVERT, MVT::i64, Custom); |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 315 | |
| 316 | // We want to custom lower some of our intrinsics. |
| 317 | setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom); |
| 318 | |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 319 | setOperationAction(ISD::SETCC, MVT::i32, Expand); |
| 320 | setOperationAction(ISD::SETCC, MVT::f32, Expand); |
| 321 | setOperationAction(ISD::SETCC, MVT::f64, Expand); |
| 322 | setOperationAction(ISD::SELECT, MVT::i32, Expand); |
| 323 | setOperationAction(ISD::SELECT, MVT::f32, Expand); |
| 324 | setOperationAction(ISD::SELECT, MVT::f64, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 325 | setOperationAction(ISD::SELECT_CC, MVT::i32, Custom); |
| 326 | setOperationAction(ISD::SELECT_CC, MVT::f32, Custom); |
| 327 | setOperationAction(ISD::SELECT_CC, MVT::f64, Custom); |
| 328 | |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 329 | setOperationAction(ISD::BRCOND, MVT::Other, Expand); |
| 330 | setOperationAction(ISD::BR_CC, MVT::i32, Custom); |
| 331 | setOperationAction(ISD::BR_CC, MVT::f32, Custom); |
| 332 | setOperationAction(ISD::BR_CC, MVT::f64, Custom); |
| 333 | setOperationAction(ISD::BR_JT, MVT::Other, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 334 | |
Dan Gohman | f96e4de | 2007-10-11 23:21:31 +0000 | [diff] [blame] | 335 | // We don't support sin/cos/fmod/copysign/pow |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 336 | setOperationAction(ISD::FSIN, MVT::f64, Expand); |
| 337 | setOperationAction(ISD::FSIN, MVT::f32, Expand); |
| 338 | setOperationAction(ISD::FCOS, MVT::f32, Expand); |
| 339 | setOperationAction(ISD::FCOS, MVT::f64, Expand); |
| 340 | setOperationAction(ISD::FREM, MVT::f64, Expand); |
| 341 | setOperationAction(ISD::FREM, MVT::f32, Expand); |
Evan Cheng | 110cf48 | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 342 | if (!UseSoftFloat && Subtarget->hasVFP2() && !Subtarget->isThumb()) { |
| 343 | setOperationAction(ISD::FCOPYSIGN, MVT::f64, Custom); |
| 344 | setOperationAction(ISD::FCOPYSIGN, MVT::f32, Custom); |
| 345 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 346 | setOperationAction(ISD::FPOW, MVT::f64, Expand); |
| 347 | setOperationAction(ISD::FPOW, MVT::f32, Expand); |
| 348 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 349 | // int <-> fp are custom expanded into bit_convert + ARMISD ops. |
Evan Cheng | 110cf48 | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 350 | if (!UseSoftFloat && Subtarget->hasVFP2() && !Subtarget->isThumb()) { |
| 351 | setOperationAction(ISD::SINT_TO_FP, MVT::i32, Custom); |
| 352 | setOperationAction(ISD::UINT_TO_FP, MVT::i32, Custom); |
| 353 | setOperationAction(ISD::FP_TO_UINT, MVT::i32, Custom); |
| 354 | setOperationAction(ISD::FP_TO_SINT, MVT::i32, Custom); |
| 355 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 356 | |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 357 | // We have target-specific dag combine patterns for the following nodes: |
| 358 | // ARMISD::FMRRD - No need to call setTargetDAGCombine |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 359 | setTargetDAGCombine(ISD::ADD); |
| 360 | setTargetDAGCombine(ISD::SUB); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 361 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 362 | setStackPointerRegisterToSaveRestore(ARM::SP); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 363 | setSchedulingPreference(SchedulingForRegPressure); |
Evan Cheng | 9f8cbd1 | 2007-05-18 00:19:34 +0000 | [diff] [blame] | 364 | setIfCvtBlockSizeLimit(Subtarget->isThumb() ? 0 : 10); |
Evan Cheng | 97e604e | 2007-06-19 23:55:02 +0000 | [diff] [blame] | 365 | setIfCvtDupBlockSizeLimit(Subtarget->isThumb() ? 0 : 2); |
Dale Johannesen | 8dd86c1 | 2007-05-17 21:31:21 +0000 | [diff] [blame] | 366 | |
Evan Cheng | 8557c2b | 2009-06-19 01:51:50 +0000 | [diff] [blame] | 367 | if (!Subtarget->isThumb()) { |
| 368 | // Use branch latency information to determine if-conversion limits. |
Evan Cheng | b101948 | 2009-06-19 07:06:07 +0000 | [diff] [blame] | 369 | // FIXME: If-converter should use instruction latency of the branch being |
| 370 | // eliminated to compute the threshold. For ARMv6, the branch "latency" |
| 371 | // varies depending on whether it's dynamically or statically predicted |
| 372 | // and on whether the destination is in the prefetch buffer. |
Evan Cheng | 8557c2b | 2009-06-19 01:51:50 +0000 | [diff] [blame] | 373 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 374 | const InstrItineraryData &InstrItins = Subtarget->getInstrItineraryData(); |
Evan Cheng | 7a42b08 | 2009-06-19 06:56:26 +0000 | [diff] [blame] | 375 | unsigned Latency= InstrItins.getLatency(TII->get(ARM::Bcc).getSchedClass()); |
Evan Cheng | 8557c2b | 2009-06-19 01:51:50 +0000 | [diff] [blame] | 376 | if (Latency > 1) { |
| 377 | setIfCvtBlockSizeLimit(Latency-1); |
| 378 | if (Latency > 2) |
| 379 | setIfCvtDupBlockSizeLimit(Latency-2); |
| 380 | } else { |
| 381 | setIfCvtBlockSizeLimit(10); |
| 382 | setIfCvtDupBlockSizeLimit(2); |
| 383 | } |
| 384 | } |
| 385 | |
Dale Johannesen | 8dd86c1 | 2007-05-17 21:31:21 +0000 | [diff] [blame] | 386 | maxStoresPerMemcpy = 1; //// temporary - rewrite interface to use type |
Bob Wilson | e6abdff | 2009-05-18 20:55:32 +0000 | [diff] [blame] | 387 | // Do not enable CodePlacementOpt for now: it currently runs after the |
| 388 | // ARMConstantIslandPass and messes up branch relaxation and placement |
| 389 | // of constant islands. |
| 390 | // benefitFromCodePlacementOpt = true; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 391 | } |
| 392 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 393 | const char *ARMTargetLowering::getTargetNodeName(unsigned Opcode) const { |
| 394 | switch (Opcode) { |
| 395 | default: return 0; |
| 396 | case ARMISD::Wrapper: return "ARMISD::Wrapper"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 397 | case ARMISD::WrapperJT: return "ARMISD::WrapperJT"; |
| 398 | case ARMISD::CALL: return "ARMISD::CALL"; |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 399 | case ARMISD::CALL_PRED: return "ARMISD::CALL_PRED"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 400 | case ARMISD::CALL_NOLINK: return "ARMISD::CALL_NOLINK"; |
| 401 | case ARMISD::tCALL: return "ARMISD::tCALL"; |
| 402 | case ARMISD::BRCOND: return "ARMISD::BRCOND"; |
| 403 | case ARMISD::BR_JT: return "ARMISD::BR_JT"; |
| 404 | case ARMISD::RET_FLAG: return "ARMISD::RET_FLAG"; |
| 405 | case ARMISD::PIC_ADD: return "ARMISD::PIC_ADD"; |
| 406 | case ARMISD::CMP: return "ARMISD::CMP"; |
David Goodwin | c0309b4 | 2009-06-29 15:33:01 +0000 | [diff] [blame] | 407 | case ARMISD::CMPZ: return "ARMISD::CMPZ"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 408 | case ARMISD::CMPFP: return "ARMISD::CMPFP"; |
| 409 | case ARMISD::CMPFPw0: return "ARMISD::CMPFPw0"; |
| 410 | case ARMISD::FMSTAT: return "ARMISD::FMSTAT"; |
| 411 | case ARMISD::CMOV: return "ARMISD::CMOV"; |
| 412 | case ARMISD::CNEG: return "ARMISD::CNEG"; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 413 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 414 | case ARMISD::FTOSI: return "ARMISD::FTOSI"; |
| 415 | case ARMISD::FTOUI: return "ARMISD::FTOUI"; |
| 416 | case ARMISD::SITOF: return "ARMISD::SITOF"; |
| 417 | case ARMISD::UITOF: return "ARMISD::UITOF"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 418 | |
| 419 | case ARMISD::SRL_FLAG: return "ARMISD::SRL_FLAG"; |
| 420 | case ARMISD::SRA_FLAG: return "ARMISD::SRA_FLAG"; |
| 421 | case ARMISD::RRX: return "ARMISD::RRX"; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 422 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 423 | case ARMISD::FMRRD: return "ARMISD::FMRRD"; |
| 424 | case ARMISD::FMDRR: return "ARMISD::FMDRR"; |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 425 | |
| 426 | case ARMISD::THREAD_POINTER:return "ARMISD::THREAD_POINTER"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 427 | |
| 428 | case ARMISD::VCEQ: return "ARMISD::VCEQ"; |
| 429 | case ARMISD::VCGE: return "ARMISD::VCGE"; |
| 430 | case ARMISD::VCGEU: return "ARMISD::VCGEU"; |
| 431 | case ARMISD::VCGT: return "ARMISD::VCGT"; |
| 432 | case ARMISD::VCGTU: return "ARMISD::VCGTU"; |
| 433 | case ARMISD::VTST: return "ARMISD::VTST"; |
| 434 | |
| 435 | case ARMISD::VSHL: return "ARMISD::VSHL"; |
| 436 | case ARMISD::VSHRs: return "ARMISD::VSHRs"; |
| 437 | case ARMISD::VSHRu: return "ARMISD::VSHRu"; |
| 438 | case ARMISD::VSHLLs: return "ARMISD::VSHLLs"; |
| 439 | case ARMISD::VSHLLu: return "ARMISD::VSHLLu"; |
| 440 | case ARMISD::VSHLLi: return "ARMISD::VSHLLi"; |
| 441 | case ARMISD::VSHRN: return "ARMISD::VSHRN"; |
| 442 | case ARMISD::VRSHRs: return "ARMISD::VRSHRs"; |
| 443 | case ARMISD::VRSHRu: return "ARMISD::VRSHRu"; |
| 444 | case ARMISD::VRSHRN: return "ARMISD::VRSHRN"; |
| 445 | case ARMISD::VQSHLs: return "ARMISD::VQSHLs"; |
| 446 | case ARMISD::VQSHLu: return "ARMISD::VQSHLu"; |
| 447 | case ARMISD::VQSHLsu: return "ARMISD::VQSHLsu"; |
| 448 | case ARMISD::VQSHRNs: return "ARMISD::VQSHRNs"; |
| 449 | case ARMISD::VQSHRNu: return "ARMISD::VQSHRNu"; |
| 450 | case ARMISD::VQSHRNsu: return "ARMISD::VQSHRNsu"; |
| 451 | case ARMISD::VQRSHRNs: return "ARMISD::VQRSHRNs"; |
| 452 | case ARMISD::VQRSHRNu: return "ARMISD::VQRSHRNu"; |
| 453 | case ARMISD::VQRSHRNsu: return "ARMISD::VQRSHRNsu"; |
| 454 | case ARMISD::VGETLANEu: return "ARMISD::VGETLANEu"; |
| 455 | case ARMISD::VGETLANEs: return "ARMISD::VGETLANEs"; |
| 456 | case ARMISD::VDUPLANEQ: return "ARMISD::VDUPLANEQ"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 457 | } |
| 458 | } |
| 459 | |
Bill Wendling | b4202b8 | 2009-07-01 18:50:55 +0000 | [diff] [blame] | 460 | /// getFunctionAlignment - Return the Log2 alignment of this function. |
Bill Wendling | 20c568f | 2009-06-30 22:38:32 +0000 | [diff] [blame] | 461 | unsigned ARMTargetLowering::getFunctionAlignment(const Function *F) const { |
| 462 | return getTargetMachine().getSubtarget<ARMSubtarget>().isThumb() ? 1 : 2; |
| 463 | } |
| 464 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 465 | //===----------------------------------------------------------------------===// |
| 466 | // Lowering Code |
| 467 | //===----------------------------------------------------------------------===// |
| 468 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 469 | /// IntCCToARMCC - Convert a DAG integer condition code to an ARM CC |
| 470 | static ARMCC::CondCodes IntCCToARMCC(ISD::CondCode CC) { |
| 471 | switch (CC) { |
| 472 | default: assert(0 && "Unknown condition code!"); |
| 473 | case ISD::SETNE: return ARMCC::NE; |
| 474 | case ISD::SETEQ: return ARMCC::EQ; |
| 475 | case ISD::SETGT: return ARMCC::GT; |
| 476 | case ISD::SETGE: return ARMCC::GE; |
| 477 | case ISD::SETLT: return ARMCC::LT; |
| 478 | case ISD::SETLE: return ARMCC::LE; |
| 479 | case ISD::SETUGT: return ARMCC::HI; |
| 480 | case ISD::SETUGE: return ARMCC::HS; |
| 481 | case ISD::SETULT: return ARMCC::LO; |
| 482 | case ISD::SETULE: return ARMCC::LS; |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | /// FPCCToARMCC - Convert a DAG fp condition code to an ARM CC. It |
| 487 | /// returns true if the operands should be inverted to form the proper |
| 488 | /// comparison. |
| 489 | static bool FPCCToARMCC(ISD::CondCode CC, ARMCC::CondCodes &CondCode, |
| 490 | ARMCC::CondCodes &CondCode2) { |
| 491 | bool Invert = false; |
| 492 | CondCode2 = ARMCC::AL; |
| 493 | switch (CC) { |
| 494 | default: assert(0 && "Unknown FP condition!"); |
| 495 | case ISD::SETEQ: |
| 496 | case ISD::SETOEQ: CondCode = ARMCC::EQ; break; |
| 497 | case ISD::SETGT: |
| 498 | case ISD::SETOGT: CondCode = ARMCC::GT; break; |
| 499 | case ISD::SETGE: |
| 500 | case ISD::SETOGE: CondCode = ARMCC::GE; break; |
| 501 | case ISD::SETOLT: CondCode = ARMCC::MI; break; |
| 502 | case ISD::SETOLE: CondCode = ARMCC::GT; Invert = true; break; |
| 503 | case ISD::SETONE: CondCode = ARMCC::MI; CondCode2 = ARMCC::GT; break; |
| 504 | case ISD::SETO: CondCode = ARMCC::VC; break; |
| 505 | case ISD::SETUO: CondCode = ARMCC::VS; break; |
| 506 | case ISD::SETUEQ: CondCode = ARMCC::EQ; CondCode2 = ARMCC::VS; break; |
| 507 | case ISD::SETUGT: CondCode = ARMCC::HI; break; |
| 508 | case ISD::SETUGE: CondCode = ARMCC::PL; break; |
| 509 | case ISD::SETLT: |
| 510 | case ISD::SETULT: CondCode = ARMCC::LT; break; |
| 511 | case ISD::SETLE: |
| 512 | case ISD::SETULE: CondCode = ARMCC::LE; break; |
| 513 | case ISD::SETNE: |
| 514 | case ISD::SETUNE: CondCode = ARMCC::NE; break; |
| 515 | } |
| 516 | return Invert; |
| 517 | } |
| 518 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 519 | //===----------------------------------------------------------------------===// |
| 520 | // Calling Convention Implementation |
| 521 | // |
| 522 | // The lower operations present on calling convention works on this order: |
| 523 | // LowerCALL (virt regs --> phys regs, virt regs --> stack) |
| 524 | // LowerFORMAL_ARGUMENTS (phys --> virt regs, stack --> virt regs) |
| 525 | // LowerRET (virt regs --> phys regs) |
| 526 | // LowerCALL (phys regs --> virt regs) |
| 527 | // |
| 528 | //===----------------------------------------------------------------------===// |
| 529 | |
| 530 | #include "ARMGenCallingConv.inc" |
| 531 | |
| 532 | // APCS f64 is in register pairs, possibly split to stack |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 533 | static bool f64AssignAPCS(unsigned &ValNo, MVT &ValVT, MVT &LocVT, |
| 534 | CCValAssign::LocInfo &LocInfo, |
| 535 | CCState &State, bool CanFail) { |
| 536 | static const unsigned RegList[] = { ARM::R0, ARM::R1, ARM::R2, ARM::R3 }; |
| 537 | |
| 538 | // Try to get the first register. |
| 539 | if (unsigned Reg = State.AllocateReg(RegList, 4)) |
| 540 | State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo)); |
| 541 | else { |
| 542 | // For the 2nd half of a v2f64, do not fail. |
| 543 | if (CanFail) |
| 544 | return false; |
| 545 | |
| 546 | // Put the whole thing on the stack. |
| 547 | State.addLoc(CCValAssign::getCustomMem(ValNo, ValVT, |
| 548 | State.AllocateStack(8, 4), |
| 549 | LocVT, LocInfo)); |
| 550 | return true; |
| 551 | } |
| 552 | |
| 553 | // Try to get the second register. |
| 554 | if (unsigned Reg = State.AllocateReg(RegList, 4)) |
| 555 | State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo)); |
| 556 | else |
| 557 | State.addLoc(CCValAssign::getCustomMem(ValNo, ValVT, |
| 558 | State.AllocateStack(4, 4), |
| 559 | LocVT, LocInfo)); |
| 560 | return true; |
| 561 | } |
| 562 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 563 | static bool CC_ARM_APCS_Custom_f64(unsigned &ValNo, MVT &ValVT, MVT &LocVT, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 564 | CCValAssign::LocInfo &LocInfo, |
| 565 | ISD::ArgFlagsTy &ArgFlags, |
| 566 | CCState &State) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 567 | if (!f64AssignAPCS(ValNo, ValVT, LocVT, LocInfo, State, true)) |
| 568 | return false; |
| 569 | if (LocVT == MVT::v2f64 && |
| 570 | !f64AssignAPCS(ValNo, ValVT, LocVT, LocInfo, State, false)) |
| 571 | return false; |
Bob Wilson | e65586b | 2009-04-17 20:40:45 +0000 | [diff] [blame] | 572 | return true; // we handled it |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | // AAPCS f64 is in aligned register pairs |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 576 | static bool f64AssignAAPCS(unsigned &ValNo, MVT &ValVT, MVT &LocVT, |
| 577 | CCValAssign::LocInfo &LocInfo, |
| 578 | CCState &State, bool CanFail) { |
| 579 | static const unsigned HiRegList[] = { ARM::R0, ARM::R2 }; |
| 580 | static const unsigned LoRegList[] = { ARM::R1, ARM::R3 }; |
| 581 | |
| 582 | unsigned Reg = State.AllocateReg(HiRegList, LoRegList, 2); |
| 583 | if (Reg == 0) { |
| 584 | // For the 2nd half of a v2f64, do not just fail. |
| 585 | if (CanFail) |
| 586 | return false; |
| 587 | |
| 588 | // Put the whole thing on the stack. |
| 589 | State.addLoc(CCValAssign::getCustomMem(ValNo, ValVT, |
| 590 | State.AllocateStack(8, 8), |
| 591 | LocVT, LocInfo)); |
| 592 | return true; |
| 593 | } |
| 594 | |
| 595 | unsigned i; |
| 596 | for (i = 0; i < 2; ++i) |
| 597 | if (HiRegList[i] == Reg) |
| 598 | break; |
| 599 | |
| 600 | State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo)); |
| 601 | State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, LoRegList[i], |
| 602 | LocVT, LocInfo)); |
| 603 | return true; |
| 604 | } |
| 605 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 606 | static bool CC_ARM_AAPCS_Custom_f64(unsigned &ValNo, MVT &ValVT, MVT &LocVT, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 607 | CCValAssign::LocInfo &LocInfo, |
| 608 | ISD::ArgFlagsTy &ArgFlags, |
| 609 | CCState &State) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 610 | if (!f64AssignAAPCS(ValNo, ValVT, LocVT, LocInfo, State, true)) |
| 611 | return false; |
| 612 | if (LocVT == MVT::v2f64 && |
| 613 | !f64AssignAAPCS(ValNo, ValVT, LocVT, LocInfo, State, false)) |
| 614 | return false; |
| 615 | return true; // we handled it |
| 616 | } |
| 617 | |
| 618 | static bool f64RetAssign(unsigned &ValNo, MVT &ValVT, MVT &LocVT, |
| 619 | CCValAssign::LocInfo &LocInfo, CCState &State) { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 620 | static const unsigned HiRegList[] = { ARM::R0, ARM::R2 }; |
| 621 | static const unsigned LoRegList[] = { ARM::R1, ARM::R3 }; |
| 622 | |
Bob Wilson | e65586b | 2009-04-17 20:40:45 +0000 | [diff] [blame] | 623 | unsigned Reg = State.AllocateReg(HiRegList, LoRegList, 2); |
| 624 | if (Reg == 0) |
| 625 | return false; // we didn't handle it |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 626 | |
Bob Wilson | e65586b | 2009-04-17 20:40:45 +0000 | [diff] [blame] | 627 | unsigned i; |
| 628 | for (i = 0; i < 2; ++i) |
| 629 | if (HiRegList[i] == Reg) |
| 630 | break; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 631 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 632 | State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo)); |
Bob Wilson | e65586b | 2009-04-17 20:40:45 +0000 | [diff] [blame] | 633 | State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, LoRegList[i], |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 634 | LocVT, LocInfo)); |
| 635 | return true; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 636 | } |
| 637 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 638 | static bool RetCC_ARM_APCS_Custom_f64(unsigned &ValNo, MVT &ValVT, MVT &LocVT, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 639 | CCValAssign::LocInfo &LocInfo, |
| 640 | ISD::ArgFlagsTy &ArgFlags, |
| 641 | CCState &State) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 642 | if (!f64RetAssign(ValNo, ValVT, LocVT, LocInfo, State)) |
| 643 | return false; |
| 644 | if (LocVT == MVT::v2f64 && !f64RetAssign(ValNo, ValVT, LocVT, LocInfo, State)) |
| 645 | return false; |
Bob Wilson | e65586b | 2009-04-17 20:40:45 +0000 | [diff] [blame] | 646 | return true; // we handled it |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 647 | } |
| 648 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 649 | static bool RetCC_ARM_AAPCS_Custom_f64(unsigned &ValNo, MVT &ValVT, MVT &LocVT, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 650 | CCValAssign::LocInfo &LocInfo, |
| 651 | ISD::ArgFlagsTy &ArgFlags, |
| 652 | CCState &State) { |
| 653 | return RetCC_ARM_APCS_Custom_f64(ValNo, ValVT, LocVT, LocInfo, ArgFlags, |
| 654 | State); |
| 655 | } |
| 656 | |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 657 | /// CCAssignFnForNode - Selects the correct CCAssignFn for a the |
| 658 | /// given CallingConvention value. |
| 659 | CCAssignFn *ARMTargetLowering::CCAssignFnForNode(unsigned CC, |
| 660 | bool Return) const { |
| 661 | switch (CC) { |
| 662 | default: |
| 663 | assert(0 && "Unsupported calling convention"); |
| 664 | case CallingConv::C: |
| 665 | case CallingConv::Fast: |
| 666 | // Use target triple & subtarget features to do actual dispatch. |
| 667 | if (Subtarget->isAAPCS_ABI()) { |
| 668 | if (Subtarget->hasVFP2() && |
| 669 | FloatABIType == FloatABI::Hard) |
| 670 | return (Return ? RetCC_ARM_AAPCS_VFP: CC_ARM_AAPCS_VFP); |
| 671 | else |
| 672 | return (Return ? RetCC_ARM_AAPCS: CC_ARM_AAPCS); |
| 673 | } else |
| 674 | return (Return ? RetCC_ARM_APCS: CC_ARM_APCS); |
| 675 | case CallingConv::ARM_AAPCS_VFP: |
| 676 | return (Return ? RetCC_ARM_AAPCS_VFP: CC_ARM_AAPCS_VFP); |
| 677 | case CallingConv::ARM_AAPCS: |
| 678 | return (Return ? RetCC_ARM_AAPCS: CC_ARM_AAPCS); |
| 679 | case CallingConv::ARM_APCS: |
| 680 | return (Return ? RetCC_ARM_APCS: CC_ARM_APCS); |
| 681 | } |
| 682 | } |
| 683 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 684 | /// LowerCallResult - Lower the result values of an ISD::CALL into the |
| 685 | /// appropriate copies out of appropriate physical registers. This assumes that |
| 686 | /// Chain/InFlag are the input chain/flag to use, and that TheCall is the call |
| 687 | /// being lowered. The returns a SDNode with the same number of values as the |
| 688 | /// ISD::CALL. |
| 689 | SDNode *ARMTargetLowering:: |
| 690 | LowerCallResult(SDValue Chain, SDValue InFlag, CallSDNode *TheCall, |
| 691 | unsigned CallingConv, SelectionDAG &DAG) { |
| 692 | |
| 693 | DebugLoc dl = TheCall->getDebugLoc(); |
| 694 | // Assign locations to each value returned by this call. |
| 695 | SmallVector<CCValAssign, 16> RVLocs; |
| 696 | bool isVarArg = TheCall->isVarArg(); |
| 697 | CCState CCInfo(CallingConv, isVarArg, getTargetMachine(), RVLocs); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 698 | CCInfo.AnalyzeCallResult(TheCall, |
| 699 | CCAssignFnForNode(CallingConv, /* Return*/ true)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 700 | |
| 701 | SmallVector<SDValue, 8> ResultVals; |
| 702 | |
| 703 | // Copy all of the result registers out of their specified physreg. |
| 704 | for (unsigned i = 0; i != RVLocs.size(); ++i) { |
| 705 | CCValAssign VA = RVLocs[i]; |
| 706 | |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 707 | SDValue Val; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 708 | if (VA.needsCustom()) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 709 | // Handle f64 or half of a v2f64. |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 710 | SDValue Lo = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 711 | InFlag); |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 712 | Chain = Lo.getValue(1); |
| 713 | InFlag = Lo.getValue(2); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 714 | VA = RVLocs[++i]; // skip ahead to next loc |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 715 | SDValue Hi = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 716 | InFlag); |
| 717 | Chain = Hi.getValue(1); |
| 718 | InFlag = Hi.getValue(2); |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 719 | Val = DAG.getNode(ARMISD::FMDRR, dl, MVT::f64, Lo, Hi); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 720 | |
| 721 | if (VA.getLocVT() == MVT::v2f64) { |
| 722 | SDValue Vec = DAG.getNode(ISD::UNDEF, dl, MVT::v2f64); |
| 723 | Vec = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Vec, Val, |
| 724 | DAG.getConstant(0, MVT::i32)); |
| 725 | |
| 726 | VA = RVLocs[++i]; // skip ahead to next loc |
| 727 | Lo = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, InFlag); |
| 728 | Chain = Lo.getValue(1); |
| 729 | InFlag = Lo.getValue(2); |
| 730 | VA = RVLocs[++i]; // skip ahead to next loc |
| 731 | Hi = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, InFlag); |
| 732 | Chain = Hi.getValue(1); |
| 733 | InFlag = Hi.getValue(2); |
| 734 | Val = DAG.getNode(ARMISD::FMDRR, dl, MVT::f64, Lo, Hi); |
| 735 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Vec, Val, |
| 736 | DAG.getConstant(1, MVT::i32)); |
| 737 | } |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 738 | } else { |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 739 | Val = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), VA.getLocVT(), |
| 740 | InFlag); |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 741 | Chain = Val.getValue(1); |
| 742 | InFlag = Val.getValue(2); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 743 | } |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 744 | |
| 745 | switch (VA.getLocInfo()) { |
| 746 | default: assert(0 && "Unknown loc info!"); |
| 747 | case CCValAssign::Full: break; |
| 748 | case CCValAssign::BCvt: |
| 749 | Val = DAG.getNode(ISD::BIT_CONVERT, dl, VA.getValVT(), Val); |
| 750 | break; |
| 751 | } |
| 752 | |
| 753 | ResultVals.push_back(Val); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | // Merge everything together with a MERGE_VALUES node. |
| 757 | ResultVals.push_back(Chain); |
| 758 | return DAG.getNode(ISD::MERGE_VALUES, dl, TheCall->getVTList(), |
| 759 | &ResultVals[0], ResultVals.size()).getNode(); |
| 760 | } |
| 761 | |
| 762 | /// CreateCopyOfByValArgument - Make a copy of an aggregate at address specified |
| 763 | /// by "Src" to address "Dst" of size "Size". Alignment information is |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 764 | /// specified by the specific parameter attribute. The copy will be passed as |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 765 | /// a byval function parameter. |
| 766 | /// Sometimes what we are copying is the end of a larger object, the part that |
| 767 | /// does not fit in registers. |
| 768 | static SDValue |
| 769 | CreateCopyOfByValArgument(SDValue Src, SDValue Dst, SDValue Chain, |
| 770 | ISD::ArgFlagsTy Flags, SelectionDAG &DAG, |
| 771 | DebugLoc dl) { |
| 772 | SDValue SizeNode = DAG.getConstant(Flags.getByValSize(), MVT::i32); |
| 773 | return DAG.getMemcpy(Chain, dl, Dst, Src, SizeNode, Flags.getByValAlign(), |
| 774 | /*AlwaysInline=*/false, NULL, 0, NULL, 0); |
| 775 | } |
| 776 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 777 | /// LowerMemOpCallTo - Store the argument to the stack. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 778 | SDValue |
| 779 | ARMTargetLowering::LowerMemOpCallTo(CallSDNode *TheCall, SelectionDAG &DAG, |
| 780 | const SDValue &StackPtr, |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 781 | const CCValAssign &VA, SDValue Chain, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 782 | SDValue Arg, ISD::ArgFlagsTy Flags) { |
| 783 | DebugLoc dl = TheCall->getDebugLoc(); |
| 784 | unsigned LocMemOffset = VA.getLocMemOffset(); |
| 785 | SDValue PtrOff = DAG.getIntPtrConstant(LocMemOffset); |
| 786 | PtrOff = DAG.getNode(ISD::ADD, dl, getPointerTy(), StackPtr, PtrOff); |
| 787 | if (Flags.isByVal()) { |
| 788 | return CreateCopyOfByValArgument(Arg, PtrOff, Chain, Flags, DAG, dl); |
| 789 | } |
| 790 | return DAG.getStore(Chain, dl, Arg, PtrOff, |
| 791 | PseudoSourceValue::getStack(), LocMemOffset); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 792 | } |
| 793 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 794 | void ARMTargetLowering::PassF64ArgInRegs(CallSDNode *TheCall, SelectionDAG &DAG, |
| 795 | SDValue Chain, SDValue &Arg, |
| 796 | RegsToPassVector &RegsToPass, |
| 797 | CCValAssign &VA, CCValAssign &NextVA, |
| 798 | SDValue &StackPtr, |
| 799 | SmallVector<SDValue, 8> &MemOpChains, |
| 800 | ISD::ArgFlagsTy Flags) { |
| 801 | DebugLoc dl = TheCall->getDebugLoc(); |
| 802 | |
| 803 | SDValue fmrrd = DAG.getNode(ARMISD::FMRRD, dl, |
| 804 | DAG.getVTList(MVT::i32, MVT::i32), Arg); |
| 805 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), fmrrd)); |
| 806 | |
| 807 | if (NextVA.isRegLoc()) |
| 808 | RegsToPass.push_back(std::make_pair(NextVA.getLocReg(), fmrrd.getValue(1))); |
| 809 | else { |
| 810 | assert(NextVA.isMemLoc()); |
| 811 | if (StackPtr.getNode() == 0) |
| 812 | StackPtr = DAG.getCopyFromReg(Chain, dl, ARM::SP, getPointerTy()); |
| 813 | |
| 814 | MemOpChains.push_back(LowerMemOpCallTo(TheCall, DAG, StackPtr, NextVA, |
| 815 | Chain, fmrrd.getValue(1), Flags)); |
| 816 | } |
| 817 | } |
| 818 | |
Evan Cheng | fc40342 | 2007-02-03 08:53:01 +0000 | [diff] [blame] | 819 | /// LowerCALL - Lowering a ISD::CALL node into a callseq_start <- |
| 820 | /// ARMISD:CALL <- callseq_end chain. Also add input and output parameter |
| 821 | /// nodes. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 822 | SDValue ARMTargetLowering::LowerCALL(SDValue Op, SelectionDAG &DAG) { |
Dan Gohman | 095cc29 | 2008-09-13 01:54:27 +0000 | [diff] [blame] | 823 | CallSDNode *TheCall = cast<CallSDNode>(Op.getNode()); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 824 | MVT RetVT = TheCall->getRetValType(0); |
| 825 | SDValue Chain = TheCall->getChain(); |
| 826 | unsigned CC = TheCall->getCallingConv(); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 827 | bool isVarArg = TheCall->isVarArg(); |
| 828 | SDValue Callee = TheCall->getCallee(); |
| 829 | DebugLoc dl = TheCall->getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 830 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 831 | // Analyze operands of the call, assigning locations to each operand. |
| 832 | SmallVector<CCValAssign, 16> ArgLocs; |
| 833 | CCState CCInfo(CC, isVarArg, getTargetMachine(), ArgLocs); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 834 | CCInfo.AnalyzeCallOperands(TheCall, CCAssignFnForNode(CC, /* Return*/ false)); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 835 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 836 | // Get a count of how many bytes are to be pushed on the stack. |
| 837 | unsigned NumBytes = CCInfo.getNextStackOffset(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 838 | |
| 839 | // Adjust the stack pointer for the new arguments... |
| 840 | // These operations are automatically eliminated by the prolog/epilog pass |
Chris Lattner | e563bbc | 2008-10-11 22:08:30 +0000 | [diff] [blame] | 841 | Chain = DAG.getCALLSEQ_START(Chain, DAG.getIntPtrConstant(NumBytes, true)); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 842 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 843 | SDValue StackPtr = DAG.getRegister(ARM::SP, MVT::i32); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 844 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 845 | RegsToPassVector RegsToPass; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 846 | SmallVector<SDValue, 8> MemOpChains; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 847 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 848 | // Walk the register/memloc assignments, inserting copies/loads. In the case |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 849 | // of tail call optimization, arguments are handled later. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 850 | for (unsigned i = 0, realArgIdx = 0, e = ArgLocs.size(); |
| 851 | i != e; |
| 852 | ++i, ++realArgIdx) { |
| 853 | CCValAssign &VA = ArgLocs[i]; |
| 854 | SDValue Arg = TheCall->getArg(realArgIdx); |
| 855 | ISD::ArgFlagsTy Flags = TheCall->getArgFlags(realArgIdx); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 856 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 857 | // Promote the value if needed. |
| 858 | switch (VA.getLocInfo()) { |
| 859 | default: assert(0 && "Unknown loc info!"); |
| 860 | case CCValAssign::Full: break; |
| 861 | case CCValAssign::SExt: |
| 862 | Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg); |
| 863 | break; |
| 864 | case CCValAssign::ZExt: |
| 865 | Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg); |
| 866 | break; |
| 867 | case CCValAssign::AExt: |
| 868 | Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg); |
| 869 | break; |
| 870 | case CCValAssign::BCvt: |
| 871 | Arg = DAG.getNode(ISD::BIT_CONVERT, dl, VA.getLocVT(), Arg); |
| 872 | break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 873 | } |
| 874 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 875 | // f64 and v2f64 are passed in i32 pairs and must be split into pieces |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 876 | if (VA.needsCustom()) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 877 | if (VA.getLocVT() == MVT::v2f64) { |
| 878 | SDValue Op0 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 879 | DAG.getConstant(0, MVT::i32)); |
| 880 | SDValue Op1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 881 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 882 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 883 | PassF64ArgInRegs(TheCall, DAG, Chain, Op0, RegsToPass, |
| 884 | VA, ArgLocs[++i], StackPtr, MemOpChains, Flags); |
| 885 | |
| 886 | VA = ArgLocs[++i]; // skip ahead to next loc |
| 887 | if (VA.isRegLoc()) { |
| 888 | PassF64ArgInRegs(TheCall, DAG, Chain, Op1, RegsToPass, |
| 889 | VA, ArgLocs[++i], StackPtr, MemOpChains, Flags); |
| 890 | } else { |
| 891 | assert(VA.isMemLoc()); |
| 892 | if (StackPtr.getNode() == 0) |
| 893 | StackPtr = DAG.getCopyFromReg(Chain, dl, ARM::SP, getPointerTy()); |
| 894 | |
| 895 | MemOpChains.push_back(LowerMemOpCallTo(TheCall, DAG, StackPtr, VA, |
| 896 | Chain, Op1, Flags)); |
| 897 | } |
| 898 | } else { |
| 899 | PassF64ArgInRegs(TheCall, DAG, Chain, Arg, RegsToPass, VA, ArgLocs[++i], |
| 900 | StackPtr, MemOpChains, Flags); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 901 | } |
| 902 | } else if (VA.isRegLoc()) { |
| 903 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg)); |
| 904 | } else { |
| 905 | assert(VA.isMemLoc()); |
| 906 | if (StackPtr.getNode() == 0) |
| 907 | StackPtr = DAG.getCopyFromReg(Chain, dl, ARM::SP, getPointerTy()); |
| 908 | |
| 909 | MemOpChains.push_back(LowerMemOpCallTo(TheCall, DAG, StackPtr, VA, |
| 910 | Chain, Arg, Flags)); |
| 911 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 912 | } |
| 913 | |
| 914 | if (!MemOpChains.empty()) |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 915 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 916 | &MemOpChains[0], MemOpChains.size()); |
| 917 | |
| 918 | // Build a sequence of copy-to-reg nodes chained together with token chain |
| 919 | // and flag operands which copy the outgoing args into the appropriate regs. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 920 | SDValue InFlag; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 921 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 922 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 923 | RegsToPass[i].second, InFlag); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 924 | InFlag = Chain.getValue(1); |
| 925 | } |
| 926 | |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 927 | // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every |
| 928 | // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol |
| 929 | // node so that legalize doesn't hack it. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 930 | bool isDirect = false; |
| 931 | bool isARMFunc = false; |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 932 | bool isLocalARMFunc = false; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 933 | if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
| 934 | GlobalValue *GV = G->getGlobal(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 935 | isDirect = true; |
Reid Spencer | 5cbf985 | 2007-01-30 20:08:39 +0000 | [diff] [blame] | 936 | bool isExt = (GV->isDeclaration() || GV->hasWeakLinkage() || |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 937 | GV->hasLinkOnceLinkage()); |
Evan Cheng | 970a419 | 2007-01-19 19:28:01 +0000 | [diff] [blame] | 938 | bool isStub = (isExt && Subtarget->isTargetDarwin()) && |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 939 | getTargetMachine().getRelocationModel() != Reloc::Static; |
| 940 | isARMFunc = !Subtarget->isThumb() || isStub; |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 941 | // ARM call to a local ARM function is predicable. |
| 942 | isLocalARMFunc = !Subtarget->isThumb() && !isExt; |
Evan Cheng | c60e76d | 2007-01-30 20:37:08 +0000 | [diff] [blame] | 943 | // tBX takes a register source operand. |
| 944 | if (isARMFunc && Subtarget->isThumb() && !Subtarget->hasV5TOps()) { |
| 945 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GV, ARMPCLabelIndex, |
| 946 | ARMCP::CPStub, 4); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 947 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 948 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 949 | Callee = DAG.getLoad(getPointerTy(), dl, |
| 950 | DAG.getEntryNode(), CPAddr, NULL, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 951 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex++, MVT::i32); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 952 | Callee = DAG.getNode(ARMISD::PIC_ADD, dl, |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 953 | getPointerTy(), Callee, PICLabel); |
Evan Cheng | c60e76d | 2007-01-30 20:37:08 +0000 | [diff] [blame] | 954 | } else |
| 955 | Callee = DAG.getTargetGlobalAddress(GV, getPointerTy()); |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 956 | } else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 957 | isDirect = true; |
Evan Cheng | 970a419 | 2007-01-19 19:28:01 +0000 | [diff] [blame] | 958 | bool isStub = Subtarget->isTargetDarwin() && |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 959 | getTargetMachine().getRelocationModel() != Reloc::Static; |
| 960 | isARMFunc = !Subtarget->isThumb() || isStub; |
Evan Cheng | c60e76d | 2007-01-30 20:37:08 +0000 | [diff] [blame] | 961 | // tBX takes a register source operand. |
| 962 | const char *Sym = S->getSymbol(); |
| 963 | if (isARMFunc && Subtarget->isThumb() && !Subtarget->hasV5TOps()) { |
| 964 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(Sym, ARMPCLabelIndex, |
| 965 | ARMCP::CPStub, 4); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 966 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 967 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 968 | Callee = DAG.getLoad(getPointerTy(), dl, |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 969 | DAG.getEntryNode(), CPAddr, NULL, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 970 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex++, MVT::i32); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 971 | Callee = DAG.getNode(ARMISD::PIC_ADD, dl, |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 972 | getPointerTy(), Callee, PICLabel); |
Evan Cheng | c60e76d | 2007-01-30 20:37:08 +0000 | [diff] [blame] | 973 | } else |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 974 | Callee = DAG.getTargetExternalSymbol(Sym, getPointerTy()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 975 | } |
| 976 | |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 977 | // FIXME: handle tail calls differently. |
| 978 | unsigned CallOpc; |
| 979 | if (Subtarget->isThumb()) { |
| 980 | if (!Subtarget->hasV5TOps() && (!isDirect || isARMFunc)) |
| 981 | CallOpc = ARMISD::CALL_NOLINK; |
| 982 | else |
| 983 | CallOpc = isARMFunc ? ARMISD::CALL : ARMISD::tCALL; |
| 984 | } else { |
| 985 | CallOpc = (isDirect || Subtarget->hasV5TOps()) |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 986 | ? (isLocalARMFunc ? ARMISD::CALL_PRED : ARMISD::CALL) |
| 987 | : ARMISD::CALL_NOLINK; |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 988 | } |
Lauro Ramos Venancio | b8a93a4 | 2007-03-27 16:19:21 +0000 | [diff] [blame] | 989 | if (CallOpc == ARMISD::CALL_NOLINK && !Subtarget->isThumb()) { |
| 990 | // implicit def LR - LR mustn't be allocated as GRP:$dst of CALL_NOLINK |
Dale Johannesen | e8d7230 | 2009-02-06 23:05:02 +0000 | [diff] [blame] | 991 | 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] | 992 | InFlag = Chain.getValue(1); |
| 993 | } |
| 994 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 995 | std::vector<SDValue> Ops; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 996 | Ops.push_back(Chain); |
| 997 | Ops.push_back(Callee); |
| 998 | |
| 999 | // Add argument registers to the end of the list so that they are known live |
| 1000 | // into the call. |
| 1001 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) |
| 1002 | Ops.push_back(DAG.getRegister(RegsToPass[i].first, |
| 1003 | RegsToPass[i].second.getValueType())); |
| 1004 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1005 | if (InFlag.getNode()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1006 | Ops.push_back(InFlag); |
Duncan Sands | 4bdcb61 | 2008-07-02 17:40:58 +0000 | [diff] [blame] | 1007 | // Returns a chain and a flag for retval copy to use. |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1008 | Chain = DAG.getNode(CallOpc, dl, DAG.getVTList(MVT::Other, MVT::Flag), |
Duncan Sands | 4bdcb61 | 2008-07-02 17:40:58 +0000 | [diff] [blame] | 1009 | &Ops[0], Ops.size()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1010 | InFlag = Chain.getValue(1); |
| 1011 | |
Chris Lattner | e563bbc | 2008-10-11 22:08:30 +0000 | [diff] [blame] | 1012 | Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(NumBytes, true), |
| 1013 | DAG.getIntPtrConstant(0, true), InFlag); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1014 | if (RetVT != MVT::Other) |
| 1015 | InFlag = Chain.getValue(1); |
| 1016 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1017 | // Handle result values, copying them out of physregs into vregs that we |
| 1018 | // return. |
| 1019 | return SDValue(LowerCallResult(Chain, InFlag, TheCall, CC, DAG), |
| 1020 | Op.getResNo()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1021 | } |
| 1022 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1023 | SDValue ARMTargetLowering::LowerRET(SDValue Op, SelectionDAG &DAG) { |
| 1024 | // The chain is always operand #0 |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1025 | SDValue Chain = Op.getOperand(0); |
Dale Johannesen | a05dca4 | 2009-02-04 23:02:30 +0000 | [diff] [blame] | 1026 | DebugLoc dl = Op.getDebugLoc(); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1027 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1028 | // CCValAssign - represent the assignment of the return value to a location. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1029 | SmallVector<CCValAssign, 16> RVLocs; |
| 1030 | unsigned CC = DAG.getMachineFunction().getFunction()->getCallingConv(); |
| 1031 | bool isVarArg = DAG.getMachineFunction().getFunction()->isVarArg(); |
| 1032 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1033 | // CCState - Info about the registers and stack slots. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1034 | CCState CCInfo(CC, isVarArg, getTargetMachine(), RVLocs); |
| 1035 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1036 | // Analyze return values of ISD::RET. |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1037 | CCInfo.AnalyzeReturn(Op.getNode(), CCAssignFnForNode(CC, /* Return */ true)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1038 | |
| 1039 | // If this is the first return lowered for this function, add |
| 1040 | // the regs to the liveout set for the function. |
| 1041 | if (DAG.getMachineFunction().getRegInfo().liveout_empty()) { |
| 1042 | for (unsigned i = 0; i != RVLocs.size(); ++i) |
| 1043 | if (RVLocs[i].isRegLoc()) |
| 1044 | DAG.getMachineFunction().getRegInfo().addLiveOut(RVLocs[i].getLocReg()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1045 | } |
| 1046 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1047 | SDValue Flag; |
| 1048 | |
| 1049 | // Copy the result values into the output registers. |
| 1050 | for (unsigned i = 0, realRVLocIdx = 0; |
| 1051 | i != RVLocs.size(); |
| 1052 | ++i, ++realRVLocIdx) { |
| 1053 | CCValAssign &VA = RVLocs[i]; |
| 1054 | assert(VA.isRegLoc() && "Can only return in registers!"); |
| 1055 | |
| 1056 | // ISD::RET => ret chain, (regnum1,val1), ... |
| 1057 | // So i*2+1 index only the regnums |
| 1058 | SDValue Arg = Op.getOperand(realRVLocIdx*2+1); |
| 1059 | |
| 1060 | switch (VA.getLocInfo()) { |
| 1061 | default: assert(0 && "Unknown loc info!"); |
| 1062 | case CCValAssign::Full: break; |
| 1063 | case CCValAssign::BCvt: |
| 1064 | Arg = DAG.getNode(ISD::BIT_CONVERT, dl, VA.getLocVT(), Arg); |
| 1065 | break; |
| 1066 | } |
| 1067 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1068 | if (VA.needsCustom()) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1069 | if (VA.getLocVT() == MVT::v2f64) { |
| 1070 | // Extract the first half and return it in two registers. |
| 1071 | SDValue Half = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1072 | DAG.getConstant(0, MVT::i32)); |
| 1073 | SDValue HalfGPRs = DAG.getNode(ARMISD::FMRRD, dl, |
| 1074 | DAG.getVTList(MVT::i32, MVT::i32), Half); |
| 1075 | |
| 1076 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), HalfGPRs, Flag); |
| 1077 | Flag = Chain.getValue(1); |
| 1078 | VA = RVLocs[++i]; // skip ahead to next loc |
| 1079 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), |
| 1080 | HalfGPRs.getValue(1), Flag); |
| 1081 | Flag = Chain.getValue(1); |
| 1082 | VA = RVLocs[++i]; // skip ahead to next loc |
| 1083 | |
| 1084 | // Extract the 2nd half and fall through to handle it as an f64 value. |
| 1085 | Arg = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1086 | DAG.getConstant(1, MVT::i32)); |
| 1087 | } |
| 1088 | // Legalize ret f64 -> ret 2 x i32. We always have fmrrd if f64 is |
| 1089 | // available. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1090 | SDValue fmrrd = DAG.getNode(ARMISD::FMRRD, dl, |
| 1091 | DAG.getVTList(MVT::i32, MVT::i32), &Arg, 1); |
| 1092 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), fmrrd, Flag); |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1093 | Flag = Chain.getValue(1); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1094 | VA = RVLocs[++i]; // skip ahead to next loc |
| 1095 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), fmrrd.getValue(1), |
| 1096 | Flag); |
| 1097 | } else |
| 1098 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), Arg, Flag); |
| 1099 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1100 | // Guarantee that all emitted copies are |
| 1101 | // stuck together, avoiding something bad. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1102 | Flag = Chain.getValue(1); |
| 1103 | } |
| 1104 | |
| 1105 | SDValue result; |
| 1106 | if (Flag.getNode()) |
| 1107 | result = DAG.getNode(ARMISD::RET_FLAG, dl, MVT::Other, Chain, Flag); |
| 1108 | else // Return Void |
| 1109 | result = DAG.getNode(ARMISD::RET_FLAG, dl, MVT::Other, Chain); |
| 1110 | |
| 1111 | return result; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1112 | } |
| 1113 | |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1114 | // ConstantPool, JumpTable, GlobalAddress, and ExternalSymbol are lowered as |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1115 | // their target countpart wrapped in the ARMISD::Wrapper node. Suppose N is |
| 1116 | // one of the above mentioned nodes. It has to be wrapped because otherwise |
| 1117 | // Select(N) returns N. So the raw TargetGlobalAddress nodes, etc. can only |
| 1118 | // be used to form addressing mode. These wrapped nodes will be selected |
| 1119 | // into MOVi. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1120 | static SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1121 | MVT PtrVT = Op.getValueType(); |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 1122 | // FIXME there is no actual debug info here |
| 1123 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1124 | ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1125 | SDValue Res; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1126 | if (CP->isMachineConstantPoolEntry()) |
| 1127 | Res = DAG.getTargetConstantPool(CP->getMachineCPVal(), PtrVT, |
| 1128 | CP->getAlignment()); |
| 1129 | else |
| 1130 | Res = DAG.getTargetConstantPool(CP->getConstVal(), PtrVT, |
| 1131 | CP->getAlignment()); |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 1132 | return DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Res); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1133 | } |
| 1134 | |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1135 | // Lower ISD::GlobalTLSAddress using the "general dynamic" model |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1136 | SDValue |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1137 | ARMTargetLowering::LowerToTLSGeneralDynamicModel(GlobalAddressSDNode *GA, |
| 1138 | SelectionDAG &DAG) { |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1139 | DebugLoc dl = GA->getDebugLoc(); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1140 | MVT PtrVT = getPointerTy(); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1141 | unsigned char PCAdj = Subtarget->isThumb() ? 4 : 8; |
| 1142 | ARMConstantPoolValue *CPV = |
| 1143 | new ARMConstantPoolValue(GA->getGlobal(), ARMPCLabelIndex, ARMCP::CPValue, |
| 1144 | PCAdj, "tlsgd", true); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1145 | SDValue Argument = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 1146 | Argument = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Argument); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1147 | Argument = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Argument, NULL, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1148 | SDValue Chain = Argument.getValue(1); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1149 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1150 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex++, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1151 | Argument = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Argument, PICLabel); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1152 | |
| 1153 | // call __tls_get_addr. |
| 1154 | ArgListTy Args; |
| 1155 | ArgListEntry Entry; |
| 1156 | Entry.Node = Argument; |
| 1157 | Entry.Ty = (const Type *) Type::Int32Ty; |
| 1158 | Args.push_back(Entry); |
Dale Johannesen | 7d2ad62 | 2009-01-30 23:10:59 +0000 | [diff] [blame] | 1159 | // FIXME: is there useful debug info available here? |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1160 | std::pair<SDValue, SDValue> CallResult = |
Dale Johannesen | 86098bd | 2008-09-26 19:31:26 +0000 | [diff] [blame] | 1161 | LowerCallTo(Chain, (const Type *) Type::Int32Ty, false, false, false, false, |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1162 | CallingConv::C, false, |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1163 | DAG.getExternalSymbol("__tls_get_addr", PtrVT), Args, DAG, dl); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1164 | return CallResult.first; |
| 1165 | } |
| 1166 | |
| 1167 | // Lower ISD::GlobalTLSAddress using the "initial exec" or |
| 1168 | // "local exec" model. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1169 | SDValue |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1170 | ARMTargetLowering::LowerToTLSExecModels(GlobalAddressSDNode *GA, |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1171 | SelectionDAG &DAG) { |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1172 | GlobalValue *GV = GA->getGlobal(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1173 | DebugLoc dl = GA->getDebugLoc(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1174 | SDValue Offset; |
| 1175 | SDValue Chain = DAG.getEntryNode(); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1176 | MVT PtrVT = getPointerTy(); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1177 | // Get the Thread Pointer |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1178 | SDValue ThreadPointer = DAG.getNode(ARMISD::THREAD_POINTER, dl, PtrVT); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1179 | |
| 1180 | if (GV->isDeclaration()){ |
| 1181 | // initial exec model |
| 1182 | unsigned char PCAdj = Subtarget->isThumb() ? 4 : 8; |
| 1183 | ARMConstantPoolValue *CPV = |
| 1184 | new ARMConstantPoolValue(GA->getGlobal(), ARMPCLabelIndex, ARMCP::CPValue, |
| 1185 | PCAdj, "gottpoff", true); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1186 | Offset = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 1187 | Offset = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Offset); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1188 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, NULL, 0); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1189 | Chain = Offset.getValue(1); |
| 1190 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1191 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex++, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1192 | Offset = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Offset, PICLabel); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1193 | |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1194 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, NULL, 0); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1195 | } else { |
| 1196 | // local exec model |
| 1197 | ARMConstantPoolValue *CPV = |
| 1198 | new ARMConstantPoolValue(GV, ARMCP::CPValue, "tpoff"); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1199 | Offset = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 1200 | Offset = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Offset); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1201 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, NULL, 0); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1202 | } |
| 1203 | |
| 1204 | // The address of the thread local variable is the add of the thread |
| 1205 | // pointer with the offset of the variable. |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1206 | return DAG.getNode(ISD::ADD, dl, PtrVT, ThreadPointer, Offset); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1207 | } |
| 1208 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1209 | SDValue |
| 1210 | ARMTargetLowering::LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) { |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1211 | // TODO: implement the "local dynamic" model |
| 1212 | assert(Subtarget->isTargetELF() && |
| 1213 | "TLS not implemented for non-ELF targets"); |
| 1214 | GlobalAddressSDNode *GA = cast<GlobalAddressSDNode>(Op); |
| 1215 | // If the relocation model is PIC, use the "General Dynamic" TLS Model, |
| 1216 | // otherwise use the "Local Exec" TLS Model |
| 1217 | if (getTargetMachine().getRelocationModel() == Reloc::PIC_) |
| 1218 | return LowerToTLSGeneralDynamicModel(GA, DAG); |
| 1219 | else |
| 1220 | return LowerToTLSExecModels(GA, DAG); |
| 1221 | } |
| 1222 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1223 | SDValue ARMTargetLowering::LowerGlobalAddressELF(SDValue Op, |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1224 | SelectionDAG &DAG) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1225 | MVT PtrVT = getPointerTy(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1226 | DebugLoc dl = Op.getDebugLoc(); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 1227 | GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
| 1228 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| 1229 | if (RelocM == Reloc::PIC_) { |
Rafael Espindola | bb46f52 | 2009-01-15 20:18:42 +0000 | [diff] [blame] | 1230 | bool UseGOTOFF = GV->hasLocalLinkage() || GV->hasHiddenVisibility(); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 1231 | ARMConstantPoolValue *CPV = |
| 1232 | new ARMConstantPoolValue(GV, ARMCP::CPValue, UseGOTOFF ? "GOTOFF":"GOT"); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1233 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 1234 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1235 | SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1236 | CPAddr, NULL, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1237 | SDValue Chain = Result.getValue(1); |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 1238 | SDValue GOT = DAG.getGLOBAL_OFFSET_TABLE(PtrVT); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1239 | Result = DAG.getNode(ISD::ADD, dl, PtrVT, Result, GOT); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 1240 | if (!UseGOTOFF) |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1241 | Result = DAG.getLoad(PtrVT, dl, Chain, Result, NULL, 0); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 1242 | return Result; |
| 1243 | } else { |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1244 | SDValue CPAddr = DAG.getTargetConstantPool(GV, PtrVT, 4); |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 1245 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1246 | return DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, NULL, 0); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 1247 | } |
| 1248 | } |
| 1249 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1250 | /// GVIsIndirectSymbol - true if the GV will be accessed via an indirect symbol |
Evan Cheng | 97c9bb5 | 2007-05-04 00:26:58 +0000 | [diff] [blame] | 1251 | /// even in non-static mode. |
| 1252 | static bool GVIsIndirectSymbol(GlobalValue *GV, Reloc::Model RelocM) { |
Evan Cheng | ae94e59 | 2008-12-05 01:06:39 +0000 | [diff] [blame] | 1253 | // If symbol visibility is hidden, the extra load is not needed if |
| 1254 | // the symbol is definitely defined in the current translation unit. |
| 1255 | bool isDecl = GV->isDeclaration() && !GV->hasNotBeenReadFromBitcode(); |
| 1256 | if (GV->hasHiddenVisibility() && (!isDecl && !GV->hasCommonLinkage())) |
| 1257 | return false; |
Duncan Sands | 667d4b8 | 2009-03-07 15:45:40 +0000 | [diff] [blame] | 1258 | return RelocM != Reloc::Static && (isDecl || GV->isWeakForLinker()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1259 | } |
| 1260 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1261 | SDValue ARMTargetLowering::LowerGlobalAddressDarwin(SDValue Op, |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1262 | SelectionDAG &DAG) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1263 | MVT PtrVT = getPointerTy(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1264 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1265 | GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
| 1266 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
Evan Cheng | 97c9bb5 | 2007-05-04 00:26:58 +0000 | [diff] [blame] | 1267 | bool IsIndirect = GVIsIndirectSymbol(GV, RelocM); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1268 | SDValue CPAddr; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1269 | if (RelocM == Reloc::Static) |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1270 | CPAddr = DAG.getTargetConstantPool(GV, PtrVT, 4); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1271 | else { |
| 1272 | unsigned PCAdj = (RelocM != Reloc::PIC_) |
| 1273 | ? 0 : (Subtarget->isThumb() ? 4 : 8); |
Evan Cheng | c60e76d | 2007-01-30 20:37:08 +0000 | [diff] [blame] | 1274 | ARMCP::ARMCPKind Kind = IsIndirect ? ARMCP::CPNonLazyPtr |
| 1275 | : ARMCP::CPValue; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1276 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GV, ARMPCLabelIndex, |
Evan Cheng | c60e76d | 2007-01-30 20:37:08 +0000 | [diff] [blame] | 1277 | Kind, PCAdj); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1278 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1279 | } |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 1280 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1281 | |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1282 | SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, NULL, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1283 | SDValue Chain = Result.getValue(1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1284 | |
| 1285 | if (RelocM == Reloc::PIC_) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1286 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex++, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1287 | Result = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1288 | } |
| 1289 | if (IsIndirect) |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1290 | Result = DAG.getLoad(PtrVT, dl, Chain, Result, NULL, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1291 | |
| 1292 | return Result; |
| 1293 | } |
| 1294 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1295 | SDValue ARMTargetLowering::LowerGLOBAL_OFFSET_TABLE(SDValue Op, |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1296 | SelectionDAG &DAG){ |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 1297 | assert(Subtarget->isTargetELF() && |
| 1298 | "GLOBAL OFFSET TABLE not implemented for non-ELF targets"); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1299 | MVT PtrVT = getPointerTy(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1300 | DebugLoc dl = Op.getDebugLoc(); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 1301 | unsigned PCAdj = Subtarget->isThumb() ? 4 : 8; |
| 1302 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue("_GLOBAL_OFFSET_TABLE_", |
| 1303 | ARMPCLabelIndex, |
| 1304 | ARMCP::CPValue, PCAdj); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1305 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 1306 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1307 | SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, NULL, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1308 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex++, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1309 | return DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 1310 | } |
| 1311 | |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 1312 | SDValue |
| 1313 | ARMTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1314 | MVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1315 | unsigned IntNo = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 1316 | DebugLoc dl = Op.getDebugLoc(); |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 1317 | switch (IntNo) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1318 | default: return SDValue(); // Don't custom lower most intrinsics. |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 1319 | case Intrinsic::arm_thread_pointer: |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 1320 | return DAG.getNode(ARMISD::THREAD_POINTER, dl, PtrVT); |
Jim Grosbach | f957012 | 2009-05-14 00:46:35 +0000 | [diff] [blame] | 1321 | case Intrinsic::eh_sjlj_setjmp: |
| 1322 | SDValue Res = DAG.getNode(ARMISD::EH_SJLJ_SETJMP, dl, MVT::i32, |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 1323 | Op.getOperand(1)); |
| 1324 | return Res; |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 1325 | } |
| 1326 | } |
| 1327 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1328 | static SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG, |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1329 | unsigned VarArgsFrameIndex) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1330 | // vastart just stores the address of the VarArgsFrameIndex slot into the |
| 1331 | // memory location argument. |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1332 | DebugLoc dl = Op.getDebugLoc(); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1333 | MVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1334 | SDValue FR = DAG.getFrameIndex(VarArgsFrameIndex, PtrVT); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 1335 | const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1336 | return DAG.getStore(Op.getOperand(0), dl, FR, Op.getOperand(1), SV, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1337 | } |
| 1338 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1339 | SDValue |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1340 | ARMTargetLowering::GetF64FormalArgument(CCValAssign &VA, CCValAssign &NextVA, |
| 1341 | SDValue &Root, SelectionDAG &DAG, |
| 1342 | DebugLoc dl) { |
| 1343 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1344 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 1345 | |
| 1346 | TargetRegisterClass *RC; |
| 1347 | if (AFI->isThumbFunction()) |
| 1348 | RC = ARM::tGPRRegisterClass; |
| 1349 | else |
| 1350 | RC = ARM::GPRRegisterClass; |
| 1351 | |
| 1352 | // Transform the arguments stored in physical registers into virtual ones. |
| 1353 | unsigned Reg = MF.addLiveIn(VA.getLocReg(), RC); |
| 1354 | SDValue ArgValue = DAG.getCopyFromReg(Root, dl, Reg, MVT::i32); |
| 1355 | |
| 1356 | SDValue ArgValue2; |
| 1357 | if (NextVA.isMemLoc()) { |
| 1358 | unsigned ArgSize = NextVA.getLocVT().getSizeInBits()/8; |
| 1359 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 1360 | int FI = MFI->CreateFixedObject(ArgSize, NextVA.getLocMemOffset()); |
| 1361 | |
| 1362 | // Create load node to retrieve arguments from the stack. |
| 1363 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
| 1364 | ArgValue2 = DAG.getLoad(MVT::i32, dl, Root, FIN, NULL, 0); |
| 1365 | } else { |
| 1366 | Reg = MF.addLiveIn(NextVA.getLocReg(), RC); |
| 1367 | ArgValue2 = DAG.getCopyFromReg(Root, dl, Reg, MVT::i32); |
| 1368 | } |
| 1369 | |
| 1370 | return DAG.getNode(ARMISD::FMDRR, dl, MVT::f64, ArgValue, ArgValue2); |
| 1371 | } |
| 1372 | |
| 1373 | SDValue |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1374 | ARMTargetLowering::LowerFORMAL_ARGUMENTS(SDValue Op, SelectionDAG &DAG) { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1375 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1376 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 1377 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1378 | SDValue Root = Op.getOperand(0); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1379 | DebugLoc dl = Op.getDebugLoc(); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1380 | bool isVarArg = cast<ConstantSDNode>(Op.getOperand(2))->getZExtValue() != 0; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1381 | unsigned CC = MF.getFunction()->getCallingConv(); |
| 1382 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 1383 | |
| 1384 | // Assign locations to all of the incoming arguments. |
| 1385 | SmallVector<CCValAssign, 16> ArgLocs; |
| 1386 | CCState CCInfo(CC, isVarArg, getTargetMachine(), ArgLocs); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1387 | CCInfo.AnalyzeFormalArguments(Op.getNode(), |
| 1388 | CCAssignFnForNode(CC, /* Return*/ false)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1389 | |
| 1390 | SmallVector<SDValue, 16> ArgValues; |
| 1391 | |
| 1392 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| 1393 | CCValAssign &VA = ArgLocs[i]; |
| 1394 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1395 | // Arguments stored in registers. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1396 | if (VA.isRegLoc()) { |
| 1397 | MVT RegVT = VA.getLocVT(); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1398 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1399 | SDValue ArgValue; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1400 | if (VA.needsCustom()) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1401 | // f64 and vector types are split up into multiple registers or |
| 1402 | // combinations of registers and stack slots. |
| 1403 | RegVT = MVT::i32; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1404 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1405 | if (VA.getLocVT() == MVT::v2f64) { |
| 1406 | SDValue ArgValue1 = GetF64FormalArgument(VA, ArgLocs[++i], |
| 1407 | Root, DAG, dl); |
| 1408 | VA = ArgLocs[++i]; // skip ahead to next loc |
| 1409 | SDValue ArgValue2 = GetF64FormalArgument(VA, ArgLocs[++i], |
| 1410 | Root, DAG, dl); |
| 1411 | ArgValue = DAG.getNode(ISD::UNDEF, dl, MVT::v2f64); |
| 1412 | ArgValue = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, |
| 1413 | ArgValue, ArgValue1, DAG.getIntPtrConstant(0)); |
| 1414 | ArgValue = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, |
| 1415 | ArgValue, ArgValue2, DAG.getIntPtrConstant(1)); |
| 1416 | } else |
| 1417 | ArgValue = GetF64FormalArgument(VA, ArgLocs[++i], Root, DAG, dl); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1418 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1419 | } else { |
| 1420 | TargetRegisterClass *RC; |
| 1421 | if (FloatABIType == FloatABI::Hard && RegVT == MVT::f32) |
| 1422 | RC = ARM::SPRRegisterClass; |
| 1423 | else if (FloatABIType == FloatABI::Hard && RegVT == MVT::f64) |
| 1424 | RC = ARM::DPRRegisterClass; |
| 1425 | else if (AFI->isThumbFunction()) |
| 1426 | RC = ARM::tGPRRegisterClass; |
| 1427 | else |
| 1428 | RC = ARM::GPRRegisterClass; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1429 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1430 | assert((RegVT == MVT::i32 || RegVT == MVT::f32 || |
| 1431 | (FloatABIType == FloatABI::Hard && RegVT == MVT::f64)) && |
| 1432 | "RegVT not supported by FORMAL_ARGUMENTS Lowering"); |
| 1433 | |
| 1434 | // Transform the arguments in physical registers into virtual ones. |
| 1435 | unsigned Reg = MF.addLiveIn(VA.getLocReg(), RC); |
| 1436 | ArgValue = DAG.getCopyFromReg(Root, dl, Reg, RegVT); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1437 | } |
| 1438 | |
| 1439 | // If this is an 8 or 16-bit value, it is really passed promoted |
| 1440 | // to 32 bits. Insert an assert[sz]ext to capture this, then |
| 1441 | // truncate to the right size. |
| 1442 | switch (VA.getLocInfo()) { |
| 1443 | default: assert(0 && "Unknown loc info!"); |
| 1444 | case CCValAssign::Full: break; |
| 1445 | case CCValAssign::BCvt: |
| 1446 | ArgValue = DAG.getNode(ISD::BIT_CONVERT, dl, VA.getValVT(), ArgValue); |
| 1447 | break; |
| 1448 | case CCValAssign::SExt: |
| 1449 | ArgValue = DAG.getNode(ISD::AssertSext, dl, RegVT, ArgValue, |
| 1450 | DAG.getValueType(VA.getValVT())); |
| 1451 | ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue); |
| 1452 | break; |
| 1453 | case CCValAssign::ZExt: |
| 1454 | ArgValue = DAG.getNode(ISD::AssertZext, dl, RegVT, ArgValue, |
| 1455 | DAG.getValueType(VA.getValVT())); |
| 1456 | ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue); |
| 1457 | break; |
| 1458 | } |
| 1459 | |
| 1460 | ArgValues.push_back(ArgValue); |
| 1461 | |
| 1462 | } else { // VA.isRegLoc() |
| 1463 | |
| 1464 | // sanity check |
| 1465 | assert(VA.isMemLoc()); |
| 1466 | assert(VA.getValVT() != MVT::i64 && "i64 should already be lowered"); |
| 1467 | |
| 1468 | unsigned ArgSize = VA.getLocVT().getSizeInBits()/8; |
| 1469 | int FI = MFI->CreateFixedObject(ArgSize, VA.getLocMemOffset()); |
| 1470 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1471 | // Create load nodes to retrieve arguments from the stack. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1472 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
| 1473 | ArgValues.push_back(DAG.getLoad(VA.getValVT(), dl, Root, FIN, NULL, 0)); |
| 1474 | } |
| 1475 | } |
| 1476 | |
| 1477 | // varargs |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1478 | if (isVarArg) { |
| 1479 | static const unsigned GPRArgRegs[] = { |
| 1480 | ARM::R0, ARM::R1, ARM::R2, ARM::R3 |
| 1481 | }; |
| 1482 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1483 | unsigned NumGPRs = CCInfo.getFirstUnallocated |
| 1484 | (GPRArgRegs, sizeof(GPRArgRegs) / sizeof(GPRArgRegs[0])); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1485 | |
Lauro Ramos Venancio | 600c383 | 2007-02-23 20:32:57 +0000 | [diff] [blame] | 1486 | unsigned Align = MF.getTarget().getFrameInfo()->getStackAlignment(); |
| 1487 | unsigned VARegSize = (4 - NumGPRs) * 4; |
| 1488 | unsigned VARegSaveSize = (VARegSize + Align - 1) & ~(Align - 1); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1489 | unsigned ArgOffset = 0; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1490 | if (VARegSaveSize) { |
| 1491 | // If this function is vararg, store any remaining integer argument regs |
| 1492 | // to their spots on the stack so that they may be loaded by deferencing |
| 1493 | // the result of va_next. |
| 1494 | AFI->setVarArgsRegSaveSize(VARegSaveSize); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1495 | ArgOffset = CCInfo.getNextStackOffset(); |
Lauro Ramos Venancio | 600c383 | 2007-02-23 20:32:57 +0000 | [diff] [blame] | 1496 | VarArgsFrameIndex = MFI->CreateFixedObject(VARegSaveSize, ArgOffset + |
| 1497 | VARegSaveSize - VARegSize); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1498 | SDValue FIN = DAG.getFrameIndex(VarArgsFrameIndex, getPointerTy()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1499 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1500 | SmallVector<SDValue, 4> MemOps; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1501 | for (; NumGPRs < 4; ++NumGPRs) { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1502 | TargetRegisterClass *RC; |
Jim Grosbach | 30eae3c | 2009-04-07 20:34:09 +0000 | [diff] [blame] | 1503 | if (AFI->isThumbFunction()) |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1504 | RC = ARM::tGPRRegisterClass; |
Jim Grosbach | 30eae3c | 2009-04-07 20:34:09 +0000 | [diff] [blame] | 1505 | else |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1506 | RC = ARM::GPRRegisterClass; |
| 1507 | |
Bob Wilson | 998e125 | 2009-04-20 18:36:57 +0000 | [diff] [blame] | 1508 | unsigned VReg = MF.addLiveIn(GPRArgRegs[NumGPRs], RC); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1509 | SDValue Val = DAG.getCopyFromReg(Root, dl, VReg, MVT::i32); |
| 1510 | SDValue Store = DAG.getStore(Val.getValue(1), dl, Val, FIN, NULL, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1511 | MemOps.push_back(Store); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1512 | FIN = DAG.getNode(ISD::ADD, dl, getPointerTy(), FIN, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1513 | DAG.getConstant(4, getPointerTy())); |
| 1514 | } |
| 1515 | if (!MemOps.empty()) |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1516 | Root = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1517 | &MemOps[0], MemOps.size()); |
| 1518 | } else |
| 1519 | // This will point to the next argument passed via stack. |
| 1520 | VarArgsFrameIndex = MFI->CreateFixedObject(4, ArgOffset); |
| 1521 | } |
| 1522 | |
| 1523 | ArgValues.push_back(Root); |
| 1524 | |
| 1525 | // Return the new list of results. |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1526 | return DAG.getNode(ISD::MERGE_VALUES, dl, Op.getNode()->getVTList(), |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1527 | &ArgValues[0], ArgValues.size()).getValue(Op.getResNo()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1528 | } |
| 1529 | |
| 1530 | /// isFloatingPointZero - Return true if this is +0.0. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1531 | static bool isFloatingPointZero(SDValue Op) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1532 | if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(Op)) |
Dale Johannesen | eaf0894 | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 1533 | return CFP->getValueAPF().isPosZero(); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1534 | else if (ISD::isEXTLoad(Op.getNode()) || ISD::isNON_EXTLoad(Op.getNode())) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1535 | // Maybe this has already been legalized into the constant pool? |
| 1536 | if (Op.getOperand(1).getOpcode() == ARMISD::Wrapper) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1537 | SDValue WrapperOp = Op.getOperand(1).getOperand(0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1538 | if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(WrapperOp)) |
| 1539 | if (ConstantFP *CFP = dyn_cast<ConstantFP>(CP->getConstVal())) |
Dale Johannesen | eaf0894 | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 1540 | return CFP->getValueAPF().isPosZero(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1541 | } |
| 1542 | } |
| 1543 | return false; |
| 1544 | } |
| 1545 | |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 1546 | static bool isLegalCmpImmediate(unsigned C, bool isThumb) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1547 | return ( isThumb && (C & ~255U) == 0) || |
| 1548 | (!isThumb && ARM_AM::getSOImmVal(C) != -1); |
| 1549 | } |
| 1550 | |
| 1551 | /// Returns appropriate ARM CMP (cmp) and corresponding condition code for |
| 1552 | /// the given operands. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1553 | static SDValue getARMCmp(SDValue LHS, SDValue RHS, ISD::CondCode CC, |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1554 | SDValue &ARMCC, SelectionDAG &DAG, bool isThumb, |
| 1555 | DebugLoc dl) { |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1556 | if (ConstantSDNode *RHSC = dyn_cast<ConstantSDNode>(RHS.getNode())) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1557 | unsigned C = RHSC->getZExtValue(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1558 | if (!isLegalCmpImmediate(C, isThumb)) { |
| 1559 | // Constant does not fit, try adjusting it by one? |
| 1560 | switch (CC) { |
| 1561 | default: break; |
| 1562 | case ISD::SETLT: |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1563 | case ISD::SETGE: |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1564 | if (isLegalCmpImmediate(C-1, isThumb)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 1565 | CC = (CC == ISD::SETLT) ? ISD::SETLE : ISD::SETGT; |
| 1566 | RHS = DAG.getConstant(C-1, MVT::i32); |
| 1567 | } |
| 1568 | break; |
| 1569 | case ISD::SETULT: |
| 1570 | case ISD::SETUGE: |
| 1571 | if (C > 0 && isLegalCmpImmediate(C-1, isThumb)) { |
| 1572 | CC = (CC == ISD::SETULT) ? ISD::SETULE : ISD::SETUGT; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1573 | RHS = DAG.getConstant(C-1, MVT::i32); |
| 1574 | } |
| 1575 | break; |
| 1576 | case ISD::SETLE: |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1577 | case ISD::SETGT: |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1578 | if (isLegalCmpImmediate(C+1, isThumb)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 1579 | CC = (CC == ISD::SETLE) ? ISD::SETLT : ISD::SETGE; |
| 1580 | RHS = DAG.getConstant(C+1, MVT::i32); |
| 1581 | } |
| 1582 | break; |
| 1583 | case ISD::SETULE: |
| 1584 | case ISD::SETUGT: |
| 1585 | if (C < 0xffffffff && isLegalCmpImmediate(C+1, isThumb)) { |
| 1586 | CC = (CC == ISD::SETULE) ? ISD::SETULT : ISD::SETUGE; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1587 | RHS = DAG.getConstant(C+1, MVT::i32); |
| 1588 | } |
| 1589 | break; |
| 1590 | } |
| 1591 | } |
| 1592 | } |
| 1593 | |
| 1594 | ARMCC::CondCodes CondCode = IntCCToARMCC(CC); |
Lauro Ramos Venancio | 9996663 | 2007-04-02 01:30:03 +0000 | [diff] [blame] | 1595 | ARMISD::NodeType CompareType; |
| 1596 | switch (CondCode) { |
| 1597 | default: |
| 1598 | CompareType = ARMISD::CMP; |
| 1599 | break; |
| 1600 | case ARMCC::EQ: |
| 1601 | case ARMCC::NE: |
David Goodwin | c0309b4 | 2009-06-29 15:33:01 +0000 | [diff] [blame] | 1602 | // Uses only Z Flag |
| 1603 | CompareType = ARMISD::CMPZ; |
Lauro Ramos Venancio | 9996663 | 2007-04-02 01:30:03 +0000 | [diff] [blame] | 1604 | break; |
| 1605 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1606 | ARMCC = DAG.getConstant(CondCode, MVT::i32); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1607 | return DAG.getNode(CompareType, dl, MVT::Flag, LHS, RHS); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1608 | } |
| 1609 | |
| 1610 | /// 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] | 1611 | static SDValue getVFPCmp(SDValue LHS, SDValue RHS, SelectionDAG &DAG, |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1612 | DebugLoc dl) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1613 | SDValue Cmp; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1614 | if (!isFloatingPointZero(RHS)) |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1615 | Cmp = DAG.getNode(ARMISD::CMPFP, dl, MVT::Flag, LHS, RHS); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1616 | else |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1617 | Cmp = DAG.getNode(ARMISD::CMPFPw0, dl, MVT::Flag, LHS); |
| 1618 | return DAG.getNode(ARMISD::FMSTAT, dl, MVT::Flag, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1619 | } |
| 1620 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1621 | static SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG, |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1622 | const ARMSubtarget *ST) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1623 | MVT VT = Op.getValueType(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1624 | SDValue LHS = Op.getOperand(0); |
| 1625 | SDValue RHS = Op.getOperand(1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1626 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(4))->get(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1627 | SDValue TrueVal = Op.getOperand(2); |
| 1628 | SDValue FalseVal = Op.getOperand(3); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1629 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1630 | |
| 1631 | if (LHS.getValueType() == MVT::i32) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1632 | SDValue ARMCC; |
| 1633 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1634 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMCC, DAG, ST->isThumb(), dl); |
| 1635 | return DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, ARMCC, CCR,Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1636 | } |
| 1637 | |
| 1638 | ARMCC::CondCodes CondCode, CondCode2; |
| 1639 | if (FPCCToARMCC(CC, CondCode, CondCode2)) |
| 1640 | std::swap(TrueVal, FalseVal); |
| 1641 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1642 | SDValue ARMCC = DAG.getConstant(CondCode, MVT::i32); |
| 1643 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1644 | SDValue Cmp = getVFPCmp(LHS, RHS, DAG, dl); |
| 1645 | SDValue Result = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, |
Evan Cheng | 0e1d379 | 2007-07-05 07:18:20 +0000 | [diff] [blame] | 1646 | ARMCC, CCR, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1647 | if (CondCode2 != ARMCC::AL) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1648 | SDValue ARMCC2 = DAG.getConstant(CondCode2, MVT::i32); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1649 | // FIXME: Needs another CMP because flag can have but one use. |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1650 | SDValue Cmp2 = getVFPCmp(LHS, RHS, DAG, dl); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1651 | Result = DAG.getNode(ARMISD::CMOV, dl, VT, |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1652 | Result, TrueVal, ARMCC2, CCR, Cmp2); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1653 | } |
| 1654 | return Result; |
| 1655 | } |
| 1656 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1657 | static SDValue LowerBR_CC(SDValue Op, SelectionDAG &DAG, |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1658 | const ARMSubtarget *ST) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1659 | SDValue Chain = Op.getOperand(0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1660 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1661 | SDValue LHS = Op.getOperand(2); |
| 1662 | SDValue RHS = Op.getOperand(3); |
| 1663 | SDValue Dest = Op.getOperand(4); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1664 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1665 | |
| 1666 | if (LHS.getValueType() == MVT::i32) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1667 | SDValue ARMCC; |
| 1668 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1669 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMCC, DAG, ST->isThumb(), dl); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1670 | return DAG.getNode(ARMISD::BRCOND, dl, MVT::Other, |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1671 | Chain, Dest, ARMCC, CCR,Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1672 | } |
| 1673 | |
| 1674 | assert(LHS.getValueType() == MVT::f32 || LHS.getValueType() == MVT::f64); |
| 1675 | ARMCC::CondCodes CondCode, CondCode2; |
| 1676 | if (FPCCToARMCC(CC, CondCode, CondCode2)) |
| 1677 | // Swap the LHS/RHS of the comparison if needed. |
| 1678 | std::swap(LHS, RHS); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1679 | |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1680 | SDValue Cmp = getVFPCmp(LHS, RHS, DAG, dl); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1681 | SDValue ARMCC = DAG.getConstant(CondCode, MVT::i32); |
| 1682 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1683 | SDVTList VTList = DAG.getVTList(MVT::Other, MVT::Flag); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1684 | SDValue Ops[] = { Chain, Dest, ARMCC, CCR, Cmp }; |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1685 | SDValue Res = DAG.getNode(ARMISD::BRCOND, dl, VTList, Ops, 5); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1686 | if (CondCode2 != ARMCC::AL) { |
| 1687 | ARMCC = DAG.getConstant(CondCode2, MVT::i32); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1688 | SDValue Ops[] = { Res, Dest, ARMCC, CCR, Res.getValue(1) }; |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1689 | Res = DAG.getNode(ARMISD::BRCOND, dl, VTList, Ops, 5); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1690 | } |
| 1691 | return Res; |
| 1692 | } |
| 1693 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1694 | SDValue ARMTargetLowering::LowerBR_JT(SDValue Op, SelectionDAG &DAG) { |
| 1695 | SDValue Chain = Op.getOperand(0); |
| 1696 | SDValue Table = Op.getOperand(1); |
| 1697 | SDValue Index = Op.getOperand(2); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1698 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1699 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1700 | MVT PTy = getPointerTy(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1701 | JumpTableSDNode *JT = cast<JumpTableSDNode>(Table); |
| 1702 | ARMFunctionInfo *AFI = DAG.getMachineFunction().getInfo<ARMFunctionInfo>(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1703 | SDValue UId = DAG.getConstant(AFI->createJumpTableUId(), PTy); |
| 1704 | SDValue JTI = DAG.getTargetJumpTable(JT->getIndex(), PTy); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1705 | Table = DAG.getNode(ARMISD::WrapperJT, dl, MVT::i32, JTI, UId); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1706 | Index = DAG.getNode(ISD::MUL, dl, PTy, Index, DAG.getConstant(4, PTy)); |
| 1707 | SDValue Addr = DAG.getNode(ISD::ADD, dl, PTy, Index, Table); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1708 | bool isPIC = getTargetMachine().getRelocationModel() == Reloc::PIC_; |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1709 | Addr = DAG.getLoad(isPIC ? (MVT)MVT::i32 : PTy, dl, |
Evan Cheng | e2446c6 | 2007-06-26 18:31:22 +0000 | [diff] [blame] | 1710 | Chain, Addr, NULL, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1711 | Chain = Addr.getValue(1); |
| 1712 | if (isPIC) |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1713 | Addr = DAG.getNode(ISD::ADD, dl, PTy, Addr, Table); |
| 1714 | return DAG.getNode(ARMISD::BR_JT, dl, MVT::Other, Chain, Addr, JTI, UId); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1715 | } |
| 1716 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1717 | static SDValue LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG) { |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1718 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1719 | unsigned Opc = |
| 1720 | Op.getOpcode() == ISD::FP_TO_SINT ? ARMISD::FTOSI : ARMISD::FTOUI; |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1721 | Op = DAG.getNode(Opc, dl, MVT::f32, Op.getOperand(0)); |
| 1722 | return DAG.getNode(ISD::BIT_CONVERT, dl, MVT::i32, Op); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1723 | } |
| 1724 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1725 | static SDValue LowerINT_TO_FP(SDValue Op, SelectionDAG &DAG) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1726 | MVT VT = Op.getValueType(); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1727 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1728 | unsigned Opc = |
| 1729 | Op.getOpcode() == ISD::SINT_TO_FP ? ARMISD::SITOF : ARMISD::UITOF; |
| 1730 | |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1731 | Op = DAG.getNode(ISD::BIT_CONVERT, dl, MVT::f32, Op.getOperand(0)); |
| 1732 | return DAG.getNode(Opc, dl, VT, Op); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1733 | } |
| 1734 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1735 | static SDValue LowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1736 | // Implement fcopysign with a fabs and a conditional fneg. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1737 | SDValue Tmp0 = Op.getOperand(0); |
| 1738 | SDValue Tmp1 = Op.getOperand(1); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1739 | DebugLoc dl = Op.getDebugLoc(); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1740 | MVT VT = Op.getValueType(); |
| 1741 | MVT SrcVT = Tmp1.getValueType(); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1742 | SDValue AbsVal = DAG.getNode(ISD::FABS, dl, VT, Tmp0); |
| 1743 | SDValue Cmp = getVFPCmp(Tmp1, DAG.getConstantFP(0.0, SrcVT), DAG, dl); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1744 | SDValue ARMCC = DAG.getConstant(ARMCC::LT, MVT::i32); |
| 1745 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1746 | return DAG.getNode(ARMISD::CNEG, dl, VT, AbsVal, AbsVal, ARMCC, CCR, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1747 | } |
| 1748 | |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 1749 | SDValue ARMTargetLowering::LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) { |
| 1750 | MachineFrameInfo *MFI = DAG.getMachineFunction().getFrameInfo(); |
| 1751 | MFI->setFrameAddressIsTaken(true); |
| 1752 | MVT VT = Op.getValueType(); |
| 1753 | DebugLoc dl = Op.getDebugLoc(); // FIXME probably not meaningful |
| 1754 | unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
Evan Cheng | cd82861 | 2009-06-18 23:14:30 +0000 | [diff] [blame] | 1755 | unsigned FrameReg = (Subtarget->isThumb() || Subtarget->isTargetDarwin()) |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 1756 | ? ARM::R7 : ARM::R11; |
| 1757 | SDValue FrameAddr = DAG.getCopyFromReg(DAG.getEntryNode(), dl, FrameReg, VT); |
| 1758 | while (Depth--) |
| 1759 | FrameAddr = DAG.getLoad(VT, dl, DAG.getEntryNode(), FrameAddr, NULL, 0); |
| 1760 | return FrameAddr; |
| 1761 | } |
| 1762 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1763 | SDValue |
Dale Johannesen | 0f502f6 | 2009-02-03 22:26:09 +0000 | [diff] [blame] | 1764 | ARMTargetLowering::EmitTargetCodeForMemcpy(SelectionDAG &DAG, DebugLoc dl, |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1765 | SDValue Chain, |
| 1766 | SDValue Dst, SDValue Src, |
| 1767 | SDValue Size, unsigned Align, |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 1768 | bool AlwaysInline, |
Dan Gohman | 1f13c68 | 2008-04-28 17:15:20 +0000 | [diff] [blame] | 1769 | const Value *DstSV, uint64_t DstSVOff, |
| 1770 | const Value *SrcSV, uint64_t SrcSVOff){ |
Evan Cheng | 4102eb5 | 2007-10-22 22:11:27 +0000 | [diff] [blame] | 1771 | // Do repeated 4-byte loads and stores. To be improved. |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 1772 | // This requires 4-byte alignment. |
| 1773 | if ((Align & 3) != 0) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1774 | return SDValue(); |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 1775 | // This requires the copy size to be a constant, preferrably |
| 1776 | // within a subtarget-specific limit. |
| 1777 | ConstantSDNode *ConstantSize = dyn_cast<ConstantSDNode>(Size); |
| 1778 | if (!ConstantSize) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1779 | return SDValue(); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1780 | uint64_t SizeVal = ConstantSize->getZExtValue(); |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 1781 | if (!AlwaysInline && SizeVal > getSubtarget()->getMaxInlineSizeThreshold()) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1782 | return SDValue(); |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 1783 | |
| 1784 | unsigned BytesLeft = SizeVal & 3; |
| 1785 | unsigned NumMemOps = SizeVal >> 2; |
Dale Johannesen | 8dd86c1 | 2007-05-17 21:31:21 +0000 | [diff] [blame] | 1786 | unsigned EmittedNumMemOps = 0; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1787 | MVT VT = MVT::i32; |
Dale Johannesen | 8dd86c1 | 2007-05-17 21:31:21 +0000 | [diff] [blame] | 1788 | unsigned VTSize = 4; |
Evan Cheng | 4102eb5 | 2007-10-22 22:11:27 +0000 | [diff] [blame] | 1789 | unsigned i = 0; |
Evan Cheng | e5e7ce4 | 2007-05-18 01:19:57 +0000 | [diff] [blame] | 1790 | const unsigned MAX_LOADS_IN_LDM = 6; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1791 | SDValue TFOps[MAX_LOADS_IN_LDM]; |
| 1792 | SDValue Loads[MAX_LOADS_IN_LDM]; |
Dan Gohman | 1f13c68 | 2008-04-28 17:15:20 +0000 | [diff] [blame] | 1793 | uint64_t SrcOff = 0, DstOff = 0; |
Dale Johannesen | 8dd86c1 | 2007-05-17 21:31:21 +0000 | [diff] [blame] | 1794 | |
Evan Cheng | 4102eb5 | 2007-10-22 22:11:27 +0000 | [diff] [blame] | 1795 | // Emit up to MAX_LOADS_IN_LDM loads, then a TokenFactor barrier, then the |
| 1796 | // same number of stores. The loads and stores will get combined into |
Dale Johannesen | 8dd86c1 | 2007-05-17 21:31:21 +0000 | [diff] [blame] | 1797 | // ldm/stm later on. |
Evan Cheng | 4102eb5 | 2007-10-22 22:11:27 +0000 | [diff] [blame] | 1798 | while (EmittedNumMemOps < NumMemOps) { |
| 1799 | for (i = 0; |
| 1800 | i < MAX_LOADS_IN_LDM && EmittedNumMemOps + i < NumMemOps; ++i) { |
Dale Johannesen | 0f502f6 | 2009-02-03 22:26:09 +0000 | [diff] [blame] | 1801 | Loads[i] = DAG.getLoad(VT, dl, Chain, |
| 1802 | DAG.getNode(ISD::ADD, dl, MVT::i32, Src, |
Evan Cheng | 4102eb5 | 2007-10-22 22:11:27 +0000 | [diff] [blame] | 1803 | DAG.getConstant(SrcOff, MVT::i32)), |
Dan Gohman | 1f13c68 | 2008-04-28 17:15:20 +0000 | [diff] [blame] | 1804 | SrcSV, SrcSVOff + SrcOff); |
Evan Cheng | 4102eb5 | 2007-10-22 22:11:27 +0000 | [diff] [blame] | 1805 | TFOps[i] = Loads[i].getValue(1); |
Dale Johannesen | 8dd86c1 | 2007-05-17 21:31:21 +0000 | [diff] [blame] | 1806 | SrcOff += VTSize; |
| 1807 | } |
Dale Johannesen | 0f502f6 | 2009-02-03 22:26:09 +0000 | [diff] [blame] | 1808 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, &TFOps[0], i); |
Dale Johannesen | 8dd86c1 | 2007-05-17 21:31:21 +0000 | [diff] [blame] | 1809 | |
Evan Cheng | 4102eb5 | 2007-10-22 22:11:27 +0000 | [diff] [blame] | 1810 | for (i = 0; |
| 1811 | i < MAX_LOADS_IN_LDM && EmittedNumMemOps + i < NumMemOps; ++i) { |
Dale Johannesen | 0f502f6 | 2009-02-03 22:26:09 +0000 | [diff] [blame] | 1812 | TFOps[i] = DAG.getStore(Chain, dl, Loads[i], |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1813 | DAG.getNode(ISD::ADD, dl, MVT::i32, Dst, |
Evan Cheng | 4102eb5 | 2007-10-22 22:11:27 +0000 | [diff] [blame] | 1814 | DAG.getConstant(DstOff, MVT::i32)), |
Dan Gohman | 1f13c68 | 2008-04-28 17:15:20 +0000 | [diff] [blame] | 1815 | DstSV, DstSVOff + DstOff); |
Dale Johannesen | 8dd86c1 | 2007-05-17 21:31:21 +0000 | [diff] [blame] | 1816 | DstOff += VTSize; |
| 1817 | } |
Dale Johannesen | 0f502f6 | 2009-02-03 22:26:09 +0000 | [diff] [blame] | 1818 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, &TFOps[0], i); |
Evan Cheng | 4102eb5 | 2007-10-22 22:11:27 +0000 | [diff] [blame] | 1819 | |
Dale Johannesen | 8dd86c1 | 2007-05-17 21:31:21 +0000 | [diff] [blame] | 1820 | EmittedNumMemOps += i; |
| 1821 | } |
| 1822 | |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1823 | if (BytesLeft == 0) |
Evan Cheng | 4102eb5 | 2007-10-22 22:11:27 +0000 | [diff] [blame] | 1824 | return Chain; |
| 1825 | |
| 1826 | // Issue loads / stores for the trailing (1 - 3) bytes. |
| 1827 | unsigned BytesLeftSave = BytesLeft; |
| 1828 | i = 0; |
| 1829 | while (BytesLeft) { |
| 1830 | if (BytesLeft >= 2) { |
| 1831 | VT = MVT::i16; |
| 1832 | VTSize = 2; |
| 1833 | } else { |
| 1834 | VT = MVT::i8; |
| 1835 | VTSize = 1; |
| 1836 | } |
| 1837 | |
Dale Johannesen | 0f502f6 | 2009-02-03 22:26:09 +0000 | [diff] [blame] | 1838 | Loads[i] = DAG.getLoad(VT, dl, Chain, |
| 1839 | DAG.getNode(ISD::ADD, dl, MVT::i32, Src, |
Evan Cheng | 4102eb5 | 2007-10-22 22:11:27 +0000 | [diff] [blame] | 1840 | DAG.getConstant(SrcOff, MVT::i32)), |
Dan Gohman | 1f13c68 | 2008-04-28 17:15:20 +0000 | [diff] [blame] | 1841 | SrcSV, SrcSVOff + SrcOff); |
Evan Cheng | 4102eb5 | 2007-10-22 22:11:27 +0000 | [diff] [blame] | 1842 | TFOps[i] = Loads[i].getValue(1); |
| 1843 | ++i; |
| 1844 | SrcOff += VTSize; |
| 1845 | BytesLeft -= VTSize; |
| 1846 | } |
Dale Johannesen | 0f502f6 | 2009-02-03 22:26:09 +0000 | [diff] [blame] | 1847 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, &TFOps[0], i); |
Evan Cheng | 4102eb5 | 2007-10-22 22:11:27 +0000 | [diff] [blame] | 1848 | |
| 1849 | i = 0; |
| 1850 | BytesLeft = BytesLeftSave; |
| 1851 | while (BytesLeft) { |
| 1852 | if (BytesLeft >= 2) { |
| 1853 | VT = MVT::i16; |
| 1854 | VTSize = 2; |
| 1855 | } else { |
| 1856 | VT = MVT::i8; |
| 1857 | VTSize = 1; |
| 1858 | } |
| 1859 | |
Dale Johannesen | 0f502f6 | 2009-02-03 22:26:09 +0000 | [diff] [blame] | 1860 | TFOps[i] = DAG.getStore(Chain, dl, Loads[i], |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1861 | DAG.getNode(ISD::ADD, dl, MVT::i32, Dst, |
Evan Cheng | 4102eb5 | 2007-10-22 22:11:27 +0000 | [diff] [blame] | 1862 | DAG.getConstant(DstOff, MVT::i32)), |
Dan Gohman | 1f13c68 | 2008-04-28 17:15:20 +0000 | [diff] [blame] | 1863 | DstSV, DstSVOff + DstOff); |
Evan Cheng | 4102eb5 | 2007-10-22 22:11:27 +0000 | [diff] [blame] | 1864 | ++i; |
| 1865 | DstOff += VTSize; |
| 1866 | BytesLeft -= VTSize; |
| 1867 | } |
Dale Johannesen | 0f502f6 | 2009-02-03 22:26:09 +0000 | [diff] [blame] | 1868 | return DAG.getNode(ISD::TokenFactor, dl, MVT::Other, &TFOps[0], i); |
Dale Johannesen | 8dd86c1 | 2007-05-17 21:31:21 +0000 | [diff] [blame] | 1869 | } |
| 1870 | |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 1871 | static SDValue ExpandBIT_CONVERT(SDNode *N, SelectionDAG &DAG) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1872 | SDValue Op = N->getOperand(0); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1873 | DebugLoc dl = N->getDebugLoc(); |
Evan Cheng | c7c7729 | 2008-11-04 19:57:48 +0000 | [diff] [blame] | 1874 | if (N->getValueType(0) == MVT::f64) { |
| 1875 | // Turn i64->f64 into FMDRR. |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1876 | SDValue Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Op, |
Evan Cheng | c7c7729 | 2008-11-04 19:57:48 +0000 | [diff] [blame] | 1877 | DAG.getConstant(0, MVT::i32)); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1878 | SDValue Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Op, |
Evan Cheng | c7c7729 | 2008-11-04 19:57:48 +0000 | [diff] [blame] | 1879 | DAG.getConstant(1, MVT::i32)); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1880 | return DAG.getNode(ARMISD::FMDRR, dl, MVT::f64, Lo, Hi); |
Evan Cheng | c7c7729 | 2008-11-04 19:57:48 +0000 | [diff] [blame] | 1881 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1882 | |
Evan Cheng | c7c7729 | 2008-11-04 19:57:48 +0000 | [diff] [blame] | 1883 | // Turn f64->i64 into FMRRD. |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1884 | SDValue Cvt = DAG.getNode(ARMISD::FMRRD, dl, |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1885 | DAG.getVTList(MVT::i32, MVT::i32), &Op, 1); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1886 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 1887 | // Merge the pieces into a single i64 value. |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1888 | return DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Cvt, Cvt.getValue(1)); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 1889 | } |
| 1890 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1891 | /// getZeroVector - Returns a vector of specified type with all zero elements. |
| 1892 | /// |
| 1893 | static SDValue getZeroVector(MVT VT, SelectionDAG &DAG, DebugLoc dl) { |
| 1894 | assert(VT.isVector() && "Expected a vector type"); |
| 1895 | |
| 1896 | // Zero vectors are used to represent vector negation and in those cases |
| 1897 | // will be implemented with the NEON VNEG instruction. However, VNEG does |
| 1898 | // not support i64 elements, so sometimes the zero vectors will need to be |
| 1899 | // explicitly constructed. For those cases, and potentially other uses in |
| 1900 | // the future, always build zero vectors as <4 x i32> or <2 x i32> bitcasted |
| 1901 | // to their dest type. This ensures they get CSE'd. |
| 1902 | SDValue Vec; |
| 1903 | SDValue Cst = DAG.getTargetConstant(0, MVT::i32); |
| 1904 | if (VT.getSizeInBits() == 64) |
| 1905 | Vec = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v2i32, Cst, Cst); |
| 1906 | else |
| 1907 | Vec = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, Cst, Cst, Cst, Cst); |
| 1908 | |
| 1909 | return DAG.getNode(ISD::BIT_CONVERT, dl, VT, Vec); |
| 1910 | } |
| 1911 | |
| 1912 | /// getOnesVector - Returns a vector of specified type with all bits set. |
| 1913 | /// |
| 1914 | static SDValue getOnesVector(MVT VT, SelectionDAG &DAG, DebugLoc dl) { |
| 1915 | assert(VT.isVector() && "Expected a vector type"); |
| 1916 | |
| 1917 | // Always build ones vectors as <4 x i32> or <2 x i32> bitcasted to their dest |
| 1918 | // type. This ensures they get CSE'd. |
| 1919 | SDValue Vec; |
| 1920 | SDValue Cst = DAG.getTargetConstant(~0U, MVT::i32); |
| 1921 | if (VT.getSizeInBits() == 64) |
| 1922 | Vec = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v2i32, Cst, Cst); |
| 1923 | else |
| 1924 | Vec = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, Cst, Cst, Cst, Cst); |
| 1925 | |
| 1926 | return DAG.getNode(ISD::BIT_CONVERT, dl, VT, Vec); |
| 1927 | } |
| 1928 | |
| 1929 | static SDValue LowerShift(SDNode *N, SelectionDAG &DAG, |
| 1930 | const ARMSubtarget *ST) { |
| 1931 | MVT VT = N->getValueType(0); |
| 1932 | DebugLoc dl = N->getDebugLoc(); |
| 1933 | |
| 1934 | // Lower vector shifts on NEON to use VSHL. |
| 1935 | if (VT.isVector()) { |
| 1936 | assert(ST->hasNEON() && "unexpected vector shift"); |
| 1937 | |
| 1938 | // Left shifts translate directly to the vshiftu intrinsic. |
| 1939 | if (N->getOpcode() == ISD::SHL) |
| 1940 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT, |
| 1941 | DAG.getConstant(Intrinsic::arm_neon_vshiftu, MVT::i32), |
| 1942 | N->getOperand(0), N->getOperand(1)); |
| 1943 | |
| 1944 | assert((N->getOpcode() == ISD::SRA || |
| 1945 | N->getOpcode() == ISD::SRL) && "unexpected vector shift opcode"); |
| 1946 | |
| 1947 | // NEON uses the same intrinsics for both left and right shifts. For |
| 1948 | // right shifts, the shift amounts are negative, so negate the vector of |
| 1949 | // shift amounts. |
| 1950 | MVT ShiftVT = N->getOperand(1).getValueType(); |
| 1951 | SDValue NegatedCount = DAG.getNode(ISD::SUB, dl, ShiftVT, |
| 1952 | getZeroVector(ShiftVT, DAG, dl), |
| 1953 | N->getOperand(1)); |
| 1954 | Intrinsic::ID vshiftInt = (N->getOpcode() == ISD::SRA ? |
| 1955 | Intrinsic::arm_neon_vshifts : |
| 1956 | Intrinsic::arm_neon_vshiftu); |
| 1957 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT, |
| 1958 | DAG.getConstant(vshiftInt, MVT::i32), |
| 1959 | N->getOperand(0), NegatedCount); |
| 1960 | } |
| 1961 | |
| 1962 | assert(VT == MVT::i64 && |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 1963 | (N->getOpcode() == ISD::SRL || N->getOpcode() == ISD::SRA) && |
| 1964 | "Unknown shift to lower!"); |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 1965 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 1966 | // We only lower SRA, SRL of 1 here, all others use generic lowering. |
| 1967 | if (!isa<ConstantSDNode>(N->getOperand(1)) || |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1968 | cast<ConstantSDNode>(N->getOperand(1))->getZExtValue() != 1) |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 1969 | return SDValue(); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1970 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 1971 | // If we are in thumb mode, we don't have RRX. |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 1972 | if (ST->isThumb()) return SDValue(); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1973 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 1974 | // Okay, we have a 64-bit SRA or SRL of 1. Lower this to an RRX expr. |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1975 | SDValue Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, N->getOperand(0), |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 1976 | DAG.getConstant(0, MVT::i32)); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1977 | SDValue Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, N->getOperand(0), |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 1978 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1979 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 1980 | // First, build a SRA_FLAG/SRL_FLAG op, which shifts the top part by one and |
| 1981 | // captures the result into a carry flag. |
| 1982 | unsigned Opc = N->getOpcode() == ISD::SRL ? ARMISD::SRL_FLAG:ARMISD::SRA_FLAG; |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1983 | 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] | 1984 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 1985 | // The low part is an ARMISD::RRX operand, which shifts the carry in. |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1986 | Lo = DAG.getNode(ARMISD::RRX, dl, MVT::i32, Lo, Hi.getValue(1)); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1987 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 1988 | // Merge the pieces into a single i64 value. |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1989 | return DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Lo, Hi); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 1990 | } |
| 1991 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1992 | static SDValue LowerVSETCC(SDValue Op, SelectionDAG &DAG) { |
| 1993 | SDValue TmpOp0, TmpOp1; |
| 1994 | bool Invert = false; |
| 1995 | bool Swap = false; |
| 1996 | unsigned Opc = 0; |
| 1997 | |
| 1998 | SDValue Op0 = Op.getOperand(0); |
| 1999 | SDValue Op1 = Op.getOperand(1); |
| 2000 | SDValue CC = Op.getOperand(2); |
| 2001 | MVT VT = Op.getValueType(); |
| 2002 | ISD::CondCode SetCCOpcode = cast<CondCodeSDNode>(CC)->get(); |
| 2003 | DebugLoc dl = Op.getDebugLoc(); |
| 2004 | |
| 2005 | if (Op.getOperand(1).getValueType().isFloatingPoint()) { |
| 2006 | switch (SetCCOpcode) { |
| 2007 | default: assert(0 && "Illegal FP comparison"); break; |
| 2008 | case ISD::SETUNE: |
| 2009 | case ISD::SETNE: Invert = true; // Fallthrough |
| 2010 | case ISD::SETOEQ: |
| 2011 | case ISD::SETEQ: Opc = ARMISD::VCEQ; break; |
| 2012 | case ISD::SETOLT: |
| 2013 | case ISD::SETLT: Swap = true; // Fallthrough |
| 2014 | case ISD::SETOGT: |
| 2015 | case ISD::SETGT: Opc = ARMISD::VCGT; break; |
| 2016 | case ISD::SETOLE: |
| 2017 | case ISD::SETLE: Swap = true; // Fallthrough |
| 2018 | case ISD::SETOGE: |
| 2019 | case ISD::SETGE: Opc = ARMISD::VCGE; break; |
| 2020 | case ISD::SETUGE: Swap = true; // Fallthrough |
| 2021 | case ISD::SETULE: Invert = true; Opc = ARMISD::VCGT; break; |
| 2022 | case ISD::SETUGT: Swap = true; // Fallthrough |
| 2023 | case ISD::SETULT: Invert = true; Opc = ARMISD::VCGE; break; |
| 2024 | case ISD::SETUEQ: Invert = true; // Fallthrough |
| 2025 | case ISD::SETONE: |
| 2026 | // Expand this to (OLT | OGT). |
| 2027 | TmpOp0 = Op0; |
| 2028 | TmpOp1 = Op1; |
| 2029 | Opc = ISD::OR; |
| 2030 | Op0 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp1, TmpOp0); |
| 2031 | Op1 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp0, TmpOp1); |
| 2032 | break; |
| 2033 | case ISD::SETUO: Invert = true; // Fallthrough |
| 2034 | case ISD::SETO: |
| 2035 | // Expand this to (OLT | OGE). |
| 2036 | TmpOp0 = Op0; |
| 2037 | TmpOp1 = Op1; |
| 2038 | Opc = ISD::OR; |
| 2039 | Op0 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp1, TmpOp0); |
| 2040 | Op1 = DAG.getNode(ARMISD::VCGE, dl, VT, TmpOp0, TmpOp1); |
| 2041 | break; |
| 2042 | } |
| 2043 | } else { |
| 2044 | // Integer comparisons. |
| 2045 | switch (SetCCOpcode) { |
| 2046 | default: assert(0 && "Illegal integer comparison"); break; |
| 2047 | case ISD::SETNE: Invert = true; |
| 2048 | case ISD::SETEQ: Opc = ARMISD::VCEQ; break; |
| 2049 | case ISD::SETLT: Swap = true; |
| 2050 | case ISD::SETGT: Opc = ARMISD::VCGT; break; |
| 2051 | case ISD::SETLE: Swap = true; |
| 2052 | case ISD::SETGE: Opc = ARMISD::VCGE; break; |
| 2053 | case ISD::SETULT: Swap = true; |
| 2054 | case ISD::SETUGT: Opc = ARMISD::VCGTU; break; |
| 2055 | case ISD::SETULE: Swap = true; |
| 2056 | case ISD::SETUGE: Opc = ARMISD::VCGEU; break; |
| 2057 | } |
| 2058 | |
| 2059 | // Detect VTST (Vector Test Bits) = vicmp ne (and (op0, op1), zero). |
| 2060 | if (Opc == ARMISD::VCEQ) { |
| 2061 | |
| 2062 | SDValue AndOp; |
| 2063 | if (ISD::isBuildVectorAllZeros(Op1.getNode())) |
| 2064 | AndOp = Op0; |
| 2065 | else if (ISD::isBuildVectorAllZeros(Op0.getNode())) |
| 2066 | AndOp = Op1; |
| 2067 | |
| 2068 | // Ignore bitconvert. |
| 2069 | if (AndOp.getNode() && AndOp.getOpcode() == ISD::BIT_CONVERT) |
| 2070 | AndOp = AndOp.getOperand(0); |
| 2071 | |
| 2072 | if (AndOp.getNode() && AndOp.getOpcode() == ISD::AND) { |
| 2073 | Opc = ARMISD::VTST; |
| 2074 | Op0 = DAG.getNode(ISD::BIT_CONVERT, dl, VT, AndOp.getOperand(0)); |
| 2075 | Op1 = DAG.getNode(ISD::BIT_CONVERT, dl, VT, AndOp.getOperand(1)); |
| 2076 | Invert = !Invert; |
| 2077 | } |
| 2078 | } |
| 2079 | } |
| 2080 | |
| 2081 | if (Swap) |
| 2082 | std::swap(Op0, Op1); |
| 2083 | |
| 2084 | SDValue Result = DAG.getNode(Opc, dl, VT, Op0, Op1); |
| 2085 | |
| 2086 | if (Invert) |
| 2087 | Result = DAG.getNOT(dl, Result, VT); |
| 2088 | |
| 2089 | return Result; |
| 2090 | } |
| 2091 | |
| 2092 | /// isVMOVSplat - Check if the specified splat value corresponds to an immediate |
| 2093 | /// VMOV instruction, and if so, return the constant being splatted. |
| 2094 | static SDValue isVMOVSplat(uint64_t SplatBits, uint64_t SplatUndef, |
| 2095 | unsigned SplatBitSize, SelectionDAG &DAG) { |
| 2096 | switch (SplatBitSize) { |
| 2097 | case 8: |
| 2098 | // Any 1-byte value is OK. |
| 2099 | assert((SplatBits & ~0xff) == 0 && "one byte splat value is too big"); |
| 2100 | return DAG.getTargetConstant(SplatBits, MVT::i8); |
| 2101 | |
| 2102 | case 16: |
| 2103 | // NEON's 16-bit VMOV supports splat values where only one byte is nonzero. |
| 2104 | if ((SplatBits & ~0xff) == 0 || |
| 2105 | (SplatBits & ~0xff00) == 0) |
| 2106 | return DAG.getTargetConstant(SplatBits, MVT::i16); |
| 2107 | break; |
| 2108 | |
| 2109 | case 32: |
| 2110 | // NEON's 32-bit VMOV supports splat values where: |
| 2111 | // * only one byte is nonzero, or |
| 2112 | // * the least significant byte is 0xff and the second byte is nonzero, or |
| 2113 | // * the least significant 2 bytes are 0xff and the third is nonzero. |
| 2114 | if ((SplatBits & ~0xff) == 0 || |
| 2115 | (SplatBits & ~0xff00) == 0 || |
| 2116 | (SplatBits & ~0xff0000) == 0 || |
| 2117 | (SplatBits & ~0xff000000) == 0) |
| 2118 | return DAG.getTargetConstant(SplatBits, MVT::i32); |
| 2119 | |
| 2120 | if ((SplatBits & ~0xffff) == 0 && |
| 2121 | ((SplatBits | SplatUndef) & 0xff) == 0xff) |
| 2122 | return DAG.getTargetConstant(SplatBits | 0xff, MVT::i32); |
| 2123 | |
| 2124 | if ((SplatBits & ~0xffffff) == 0 && |
| 2125 | ((SplatBits | SplatUndef) & 0xffff) == 0xffff) |
| 2126 | return DAG.getTargetConstant(SplatBits | 0xffff, MVT::i32); |
| 2127 | |
| 2128 | // Note: there are a few 32-bit splat values (specifically: 00ffff00, |
| 2129 | // ff000000, ff0000ff, and ffff00ff) that are valid for VMOV.I64 but not |
| 2130 | // VMOV.I32. A (very) minor optimization would be to replicate the value |
| 2131 | // and fall through here to test for a valid 64-bit splat. But, then the |
| 2132 | // caller would also need to check and handle the change in size. |
| 2133 | break; |
| 2134 | |
| 2135 | case 64: { |
| 2136 | // NEON has a 64-bit VMOV splat where each byte is either 0 or 0xff. |
| 2137 | uint64_t BitMask = 0xff; |
| 2138 | uint64_t Val = 0; |
| 2139 | for (int ByteNum = 0; ByteNum < 8; ++ByteNum) { |
| 2140 | if (((SplatBits | SplatUndef) & BitMask) == BitMask) |
| 2141 | Val |= BitMask; |
| 2142 | else if ((SplatBits & BitMask) != 0) |
| 2143 | return SDValue(); |
| 2144 | BitMask <<= 8; |
| 2145 | } |
| 2146 | return DAG.getTargetConstant(Val, MVT::i64); |
| 2147 | } |
| 2148 | |
| 2149 | default: |
| 2150 | assert(0 && "unexpected size for isVMOVSplat"); |
| 2151 | break; |
| 2152 | } |
| 2153 | |
| 2154 | return SDValue(); |
| 2155 | } |
| 2156 | |
| 2157 | /// getVMOVImm - If this is a build_vector of constants which can be |
| 2158 | /// formed by using a VMOV instruction of the specified element size, |
| 2159 | /// return the constant being splatted. The ByteSize field indicates the |
| 2160 | /// number of bytes of each element [1248]. |
| 2161 | SDValue ARM::getVMOVImm(SDNode *N, unsigned ByteSize, SelectionDAG &DAG) { |
| 2162 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(N); |
| 2163 | APInt SplatBits, SplatUndef; |
| 2164 | unsigned SplatBitSize; |
| 2165 | bool HasAnyUndefs; |
| 2166 | if (! BVN || ! BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, |
| 2167 | HasAnyUndefs, ByteSize * 8)) |
| 2168 | return SDValue(); |
| 2169 | |
| 2170 | if (SplatBitSize > ByteSize * 8) |
| 2171 | return SDValue(); |
| 2172 | |
| 2173 | return isVMOVSplat(SplatBits.getZExtValue(), SplatUndef.getZExtValue(), |
| 2174 | SplatBitSize, DAG); |
| 2175 | } |
| 2176 | |
| 2177 | static SDValue BuildSplat(SDValue Val, MVT VT, SelectionDAG &DAG, DebugLoc dl) { |
| 2178 | // Canonicalize all-zeros and all-ones vectors. |
| 2179 | ConstantSDNode *ConstVal = dyn_cast<ConstantSDNode>(Val.getNode()); |
| 2180 | if (ConstVal->isNullValue()) |
| 2181 | return getZeroVector(VT, DAG, dl); |
| 2182 | if (ConstVal->isAllOnesValue()) |
| 2183 | return getOnesVector(VT, DAG, dl); |
| 2184 | |
| 2185 | MVT CanonicalVT; |
| 2186 | if (VT.is64BitVector()) { |
| 2187 | switch (Val.getValueType().getSizeInBits()) { |
| 2188 | case 8: CanonicalVT = MVT::v8i8; break; |
| 2189 | case 16: CanonicalVT = MVT::v4i16; break; |
| 2190 | case 32: CanonicalVT = MVT::v2i32; break; |
| 2191 | case 64: CanonicalVT = MVT::v1i64; break; |
| 2192 | default: assert(0 && "unexpected splat element type"); break; |
| 2193 | } |
| 2194 | } else { |
| 2195 | assert(VT.is128BitVector() && "unknown splat vector size"); |
| 2196 | switch (Val.getValueType().getSizeInBits()) { |
| 2197 | case 8: CanonicalVT = MVT::v16i8; break; |
| 2198 | case 16: CanonicalVT = MVT::v8i16; break; |
| 2199 | case 32: CanonicalVT = MVT::v4i32; break; |
| 2200 | case 64: CanonicalVT = MVT::v2i64; break; |
| 2201 | default: assert(0 && "unexpected splat element type"); break; |
| 2202 | } |
| 2203 | } |
| 2204 | |
| 2205 | // Build a canonical splat for this value. |
| 2206 | SmallVector<SDValue, 8> Ops; |
| 2207 | Ops.assign(CanonicalVT.getVectorNumElements(), Val); |
| 2208 | SDValue Res = DAG.getNode(ISD::BUILD_VECTOR, dl, CanonicalVT, &Ops[0], |
| 2209 | Ops.size()); |
| 2210 | return DAG.getNode(ISD::BIT_CONVERT, dl, VT, Res); |
| 2211 | } |
| 2212 | |
| 2213 | // If this is a case we can't handle, return null and let the default |
| 2214 | // expansion code take care of it. |
| 2215 | static SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) { |
| 2216 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(Op.getNode()); |
| 2217 | assert(BVN != 0 && "Expected a BuildVectorSDNode in LowerBUILD_VECTOR"); |
| 2218 | DebugLoc dl = Op.getDebugLoc(); |
| 2219 | |
| 2220 | APInt SplatBits, SplatUndef; |
| 2221 | unsigned SplatBitSize; |
| 2222 | bool HasAnyUndefs; |
| 2223 | if (BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { |
| 2224 | SDValue Val = isVMOVSplat(SplatBits.getZExtValue(), |
| 2225 | SplatUndef.getZExtValue(), SplatBitSize, DAG); |
| 2226 | if (Val.getNode()) |
| 2227 | return BuildSplat(Val, Op.getValueType(), DAG, dl); |
| 2228 | } |
| 2229 | |
| 2230 | return SDValue(); |
| 2231 | } |
| 2232 | |
| 2233 | static SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) { |
| 2234 | return Op; |
| 2235 | } |
| 2236 | |
| 2237 | static SDValue LowerSCALAR_TO_VECTOR(SDValue Op, SelectionDAG &DAG) { |
| 2238 | return Op; |
| 2239 | } |
| 2240 | |
| 2241 | static SDValue LowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) { |
| 2242 | MVT VT = Op.getValueType(); |
| 2243 | DebugLoc dl = Op.getDebugLoc(); |
| 2244 | assert((VT == MVT::i8 || VT == MVT::i16) && |
| 2245 | "unexpected type for custom-lowering vector extract"); |
| 2246 | SDValue Vec = Op.getOperand(0); |
| 2247 | SDValue Lane = Op.getOperand(1); |
| 2248 | Op = DAG.getNode(ARMISD::VGETLANEu, dl, MVT::i32, Vec, Lane); |
| 2249 | Op = DAG.getNode(ISD::AssertZext, dl, MVT::i32, Op, DAG.getValueType(VT)); |
| 2250 | return DAG.getNode(ISD::TRUNCATE, dl, VT, Op); |
| 2251 | } |
| 2252 | |
| 2253 | static SDValue LowerCONCAT_VECTORS(SDValue Op) { |
| 2254 | if (Op.getValueType().is128BitVector() && Op.getNumOperands() == 2) |
| 2255 | return Op; |
| 2256 | return SDValue(); |
| 2257 | } |
| 2258 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2259 | SDValue ARMTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2260 | switch (Op.getOpcode()) { |
| 2261 | default: assert(0 && "Don't know how to custom lower this!"); abort(); |
| 2262 | case ISD::ConstantPool: return LowerConstantPool(Op, DAG); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2263 | case ISD::GlobalAddress: |
| 2264 | return Subtarget->isTargetDarwin() ? LowerGlobalAddressDarwin(Op, DAG) : |
| 2265 | LowerGlobalAddressELF(Op, DAG); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2266 | case ISD::GlobalTLSAddress: return LowerGlobalTLSAddress(Op, DAG); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2267 | case ISD::CALL: return LowerCALL(Op, DAG); |
| 2268 | case ISD::RET: return LowerRET(Op, DAG); |
| 2269 | case ISD::SELECT_CC: return LowerSELECT_CC(Op, DAG, Subtarget); |
| 2270 | case ISD::BR_CC: return LowerBR_CC(Op, DAG, Subtarget); |
| 2271 | case ISD::BR_JT: return LowerBR_JT(Op, DAG); |
| 2272 | case ISD::VASTART: return LowerVASTART(Op, DAG, VarArgsFrameIndex); |
| 2273 | case ISD::SINT_TO_FP: |
| 2274 | case ISD::UINT_TO_FP: return LowerINT_TO_FP(Op, DAG); |
| 2275 | case ISD::FP_TO_SINT: |
| 2276 | case ISD::FP_TO_UINT: return LowerFP_TO_INT(Op, DAG); |
| 2277 | case ISD::FCOPYSIGN: return LowerFCOPYSIGN(Op, DAG); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 2278 | case ISD::FORMAL_ARGUMENTS: return LowerFORMAL_ARGUMENTS(Op, DAG); |
Nate Begeman | bcc5f36 | 2007-01-29 22:58:52 +0000 | [diff] [blame] | 2279 | case ISD::RETURNADDR: break; |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 2280 | case ISD::FRAMEADDR: return LowerFRAMEADDR(Op, DAG); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2281 | case ISD::GLOBAL_OFFSET_TABLE: return LowerGLOBAL_OFFSET_TABLE(Op, DAG); |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 2282 | case ISD::INTRINSIC_WO_CHAIN: return LowerINTRINSIC_WO_CHAIN(Op, DAG); |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 2283 | case ISD::BIT_CONVERT: return ExpandBIT_CONVERT(Op.getNode(), DAG); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2284 | case ISD::SHL: |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 2285 | case ISD::SRL: |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2286 | case ISD::SRA: return LowerShift(Op.getNode(), DAG, Subtarget); |
| 2287 | case ISD::VSETCC: return LowerVSETCC(Op, DAG); |
| 2288 | case ISD::BUILD_VECTOR: return LowerBUILD_VECTOR(Op, DAG); |
| 2289 | case ISD::VECTOR_SHUFFLE: return LowerVECTOR_SHUFFLE(Op, DAG); |
| 2290 | case ISD::SCALAR_TO_VECTOR: return LowerSCALAR_TO_VECTOR(Op, DAG); |
| 2291 | case ISD::EXTRACT_VECTOR_ELT: return LowerEXTRACT_VECTOR_ELT(Op, DAG); |
| 2292 | case ISD::CONCAT_VECTORS: return LowerCONCAT_VECTORS(Op); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2293 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2294 | return SDValue(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2295 | } |
| 2296 | |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 2297 | /// ReplaceNodeResults - Replace the results of node with an illegal result |
| 2298 | /// type with new values built out of custom code. |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 2299 | void ARMTargetLowering::ReplaceNodeResults(SDNode *N, |
| 2300 | SmallVectorImpl<SDValue>&Results, |
| 2301 | SelectionDAG &DAG) { |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 2302 | switch (N->getOpcode()) { |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 2303 | default: |
| 2304 | assert(0 && "Don't know how to custom expand this!"); |
| 2305 | return; |
| 2306 | case ISD::BIT_CONVERT: |
| 2307 | Results.push_back(ExpandBIT_CONVERT(N, DAG)); |
| 2308 | return; |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 2309 | case ISD::SRL: |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 2310 | case ISD::SRA: { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2311 | SDValue Res = LowerShift(N, DAG, Subtarget); |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 2312 | if (Res.getNode()) |
| 2313 | Results.push_back(Res); |
| 2314 | return; |
| 2315 | } |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 2316 | } |
| 2317 | } |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 2318 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2319 | //===----------------------------------------------------------------------===// |
| 2320 | // ARM Scheduler Hooks |
| 2321 | //===----------------------------------------------------------------------===// |
| 2322 | |
| 2323 | MachineBasicBlock * |
Evan Cheng | ff9b373 | 2008-01-30 18:18:23 +0000 | [diff] [blame] | 2324 | ARMTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI, |
Dan Gohman | 1fdbc1d | 2009-02-07 16:15:20 +0000 | [diff] [blame] | 2325 | MachineBasicBlock *BB) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2326 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
Dale Johannesen | b672840 | 2009-02-13 02:25:56 +0000 | [diff] [blame] | 2327 | DebugLoc dl = MI->getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2328 | switch (MI->getOpcode()) { |
| 2329 | default: assert(false && "Unexpected instr type to insert"); |
| 2330 | case ARM::tMOVCCr: { |
| 2331 | // To "insert" a SELECT_CC instruction, we actually have to insert the |
| 2332 | // diamond control-flow pattern. The incoming instruction knows the |
| 2333 | // destination vreg to set, the condition code register to branch on, the |
| 2334 | // true/false values to select between, and a branch opcode to use. |
| 2335 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 2336 | MachineFunction::iterator It = BB; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2337 | ++It; |
| 2338 | |
| 2339 | // thisMBB: |
| 2340 | // ... |
| 2341 | // TrueVal = ... |
| 2342 | // cmpTY ccX, r1, r2 |
| 2343 | // bCC copy1MBB |
| 2344 | // fallthrough --> copy0MBB |
| 2345 | MachineBasicBlock *thisMBB = BB; |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 2346 | MachineFunction *F = BB->getParent(); |
| 2347 | MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB); |
| 2348 | MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB); |
Dale Johannesen | b672840 | 2009-02-13 02:25:56 +0000 | [diff] [blame] | 2349 | BuildMI(BB, dl, TII->get(ARM::tBcc)).addMBB(sinkMBB) |
Evan Cheng | 0e1d379 | 2007-07-05 07:18:20 +0000 | [diff] [blame] | 2350 | .addImm(MI->getOperand(3).getImm()).addReg(MI->getOperand(4).getReg()); |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 2351 | F->insert(It, copy0MBB); |
| 2352 | F->insert(It, sinkMBB); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2353 | // Update machine-CFG edges by first adding all successors of the current |
| 2354 | // block to the new block which will contain the Phi node for the select. |
| 2355 | for(MachineBasicBlock::succ_iterator i = BB->succ_begin(), |
| 2356 | e = BB->succ_end(); i != e; ++i) |
| 2357 | sinkMBB->addSuccessor(*i); |
| 2358 | // Next, remove all successors of the current block, and add the true |
| 2359 | // and fallthrough blocks as its successors. |
| 2360 | while(!BB->succ_empty()) |
| 2361 | BB->removeSuccessor(BB->succ_begin()); |
| 2362 | BB->addSuccessor(copy0MBB); |
| 2363 | BB->addSuccessor(sinkMBB); |
| 2364 | |
| 2365 | // copy0MBB: |
| 2366 | // %FalseValue = ... |
| 2367 | // # fallthrough to sinkMBB |
| 2368 | BB = copy0MBB; |
| 2369 | |
| 2370 | // Update machine-CFG edges |
| 2371 | BB->addSuccessor(sinkMBB); |
| 2372 | |
| 2373 | // sinkMBB: |
| 2374 | // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ] |
| 2375 | // ... |
| 2376 | BB = sinkMBB; |
Dale Johannesen | b672840 | 2009-02-13 02:25:56 +0000 | [diff] [blame] | 2377 | BuildMI(BB, dl, TII->get(ARM::PHI), MI->getOperand(0).getReg()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2378 | .addReg(MI->getOperand(1).getReg()).addMBB(copy0MBB) |
| 2379 | .addReg(MI->getOperand(2).getReg()).addMBB(thisMBB); |
| 2380 | |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 2381 | F->DeleteMachineInstr(MI); // The pseudo instruction is gone now. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2382 | return BB; |
| 2383 | } |
| 2384 | } |
| 2385 | } |
| 2386 | |
| 2387 | //===----------------------------------------------------------------------===// |
| 2388 | // ARM Optimization Hooks |
| 2389 | //===----------------------------------------------------------------------===// |
| 2390 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 2391 | static |
| 2392 | SDValue combineSelectAndUse(SDNode *N, SDValue Slct, SDValue OtherOp, |
| 2393 | TargetLowering::DAGCombinerInfo &DCI) { |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 2394 | SelectionDAG &DAG = DCI.DAG; |
| 2395 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 2396 | MVT VT = N->getValueType(0); |
| 2397 | unsigned Opc = N->getOpcode(); |
| 2398 | bool isSlctCC = Slct.getOpcode() == ISD::SELECT_CC; |
| 2399 | SDValue LHS = isSlctCC ? Slct.getOperand(2) : Slct.getOperand(1); |
| 2400 | SDValue RHS = isSlctCC ? Slct.getOperand(3) : Slct.getOperand(2); |
| 2401 | ISD::CondCode CC = ISD::SETCC_INVALID; |
| 2402 | |
| 2403 | if (isSlctCC) { |
| 2404 | CC = cast<CondCodeSDNode>(Slct.getOperand(4))->get(); |
| 2405 | } else { |
| 2406 | SDValue CCOp = Slct.getOperand(0); |
| 2407 | if (CCOp.getOpcode() == ISD::SETCC) |
| 2408 | CC = cast<CondCodeSDNode>(CCOp.getOperand(2))->get(); |
| 2409 | } |
| 2410 | |
| 2411 | bool DoXform = false; |
| 2412 | bool InvCC = false; |
| 2413 | assert ((Opc == ISD::ADD || (Opc == ISD::SUB && Slct == N->getOperand(1))) && |
| 2414 | "Bad input!"); |
| 2415 | |
| 2416 | if (LHS.getOpcode() == ISD::Constant && |
| 2417 | cast<ConstantSDNode>(LHS)->isNullValue()) { |
| 2418 | DoXform = true; |
| 2419 | } else if (CC != ISD::SETCC_INVALID && |
| 2420 | RHS.getOpcode() == ISD::Constant && |
| 2421 | cast<ConstantSDNode>(RHS)->isNullValue()) { |
| 2422 | std::swap(LHS, RHS); |
| 2423 | SDValue Op0 = Slct.getOperand(0); |
| 2424 | MVT OpVT = isSlctCC ? Op0.getValueType() : |
| 2425 | Op0.getOperand(0).getValueType(); |
| 2426 | bool isInt = OpVT.isInteger(); |
| 2427 | CC = ISD::getSetCCInverse(CC, isInt); |
| 2428 | |
| 2429 | if (!TLI.isCondCodeLegal(CC, OpVT)) |
| 2430 | return SDValue(); // Inverse operator isn't legal. |
| 2431 | |
| 2432 | DoXform = true; |
| 2433 | InvCC = true; |
| 2434 | } |
| 2435 | |
| 2436 | if (DoXform) { |
| 2437 | SDValue Result = DAG.getNode(Opc, RHS.getDebugLoc(), VT, OtherOp, RHS); |
| 2438 | if (isSlctCC) |
| 2439 | return DAG.getSelectCC(N->getDebugLoc(), OtherOp, Result, |
| 2440 | Slct.getOperand(0), Slct.getOperand(1), CC); |
| 2441 | SDValue CCOp = Slct.getOperand(0); |
| 2442 | if (InvCC) |
| 2443 | CCOp = DAG.getSetCC(Slct.getDebugLoc(), CCOp.getValueType(), |
| 2444 | CCOp.getOperand(0), CCOp.getOperand(1), CC); |
| 2445 | return DAG.getNode(ISD::SELECT, N->getDebugLoc(), VT, |
| 2446 | CCOp, OtherOp, Result); |
| 2447 | } |
| 2448 | return SDValue(); |
| 2449 | } |
| 2450 | |
| 2451 | /// PerformADDCombine - Target-specific dag combine xforms for ISD::ADD. |
| 2452 | static SDValue PerformADDCombine(SDNode *N, |
| 2453 | TargetLowering::DAGCombinerInfo &DCI) { |
| 2454 | // added by evan in r37685 with no testcase. |
| 2455 | SDValue N0 = N->getOperand(0), N1 = N->getOperand(1); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2456 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 2457 | // fold (add (select cc, 0, c), x) -> (select cc, x, (add, x, c)) |
| 2458 | if (N0.getOpcode() == ISD::SELECT && N0.getNode()->hasOneUse()) { |
| 2459 | SDValue Result = combineSelectAndUse(N, N0, N1, DCI); |
| 2460 | if (Result.getNode()) return Result; |
| 2461 | } |
| 2462 | if (N1.getOpcode() == ISD::SELECT && N1.getNode()->hasOneUse()) { |
| 2463 | SDValue Result = combineSelectAndUse(N, N1, N0, DCI); |
| 2464 | if (Result.getNode()) return Result; |
| 2465 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2466 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 2467 | return SDValue(); |
| 2468 | } |
| 2469 | |
| 2470 | /// PerformSUBCombine - Target-specific dag combine xforms for ISD::SUB. |
| 2471 | static SDValue PerformSUBCombine(SDNode *N, |
| 2472 | TargetLowering::DAGCombinerInfo &DCI) { |
| 2473 | // added by evan in r37685 with no testcase. |
| 2474 | SDValue N0 = N->getOperand(0), N1 = N->getOperand(1); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2475 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 2476 | // fold (sub x, (select cc, 0, c)) -> (select cc, x, (sub, x, c)) |
| 2477 | if (N1.getOpcode() == ISD::SELECT && N1.getNode()->hasOneUse()) { |
| 2478 | SDValue Result = combineSelectAndUse(N, N1, N0, DCI); |
| 2479 | if (Result.getNode()) return Result; |
| 2480 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2481 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 2482 | return SDValue(); |
| 2483 | } |
| 2484 | |
| 2485 | |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 2486 | /// PerformFMRRDCombine - Target-specific dag combine xforms for ARMISD::FMRRD. |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2487 | static SDValue PerformFMRRDCombine(SDNode *N, |
| 2488 | TargetLowering::DAGCombinerInfo &DCI) { |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 2489 | // fmrrd(fmdrr x, y) -> x,y |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2490 | SDValue InDouble = N->getOperand(0); |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 2491 | if (InDouble.getOpcode() == ARMISD::FMDRR) |
| 2492 | return DCI.CombineTo(N, InDouble.getOperand(0), InDouble.getOperand(1)); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2493 | return SDValue(); |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 2494 | } |
| 2495 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2496 | /// getVShiftImm - Check if this is a valid build_vector for the immediate |
| 2497 | /// operand of a vector shift operation, where all the elements of the |
| 2498 | /// build_vector must have the same constant integer value. |
| 2499 | static bool getVShiftImm(SDValue Op, unsigned ElementBits, int64_t &Cnt) { |
| 2500 | // Ignore bit_converts. |
| 2501 | while (Op.getOpcode() == ISD::BIT_CONVERT) |
| 2502 | Op = Op.getOperand(0); |
| 2503 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(Op.getNode()); |
| 2504 | APInt SplatBits, SplatUndef; |
| 2505 | unsigned SplatBitSize; |
| 2506 | bool HasAnyUndefs; |
| 2507 | if (! BVN || ! BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, |
| 2508 | HasAnyUndefs, ElementBits) || |
| 2509 | SplatBitSize > ElementBits) |
| 2510 | return false; |
| 2511 | Cnt = SplatBits.getSExtValue(); |
| 2512 | return true; |
| 2513 | } |
| 2514 | |
| 2515 | /// isVShiftLImm - Check if this is a valid build_vector for the immediate |
| 2516 | /// operand of a vector shift left operation. That value must be in the range: |
| 2517 | /// 0 <= Value < ElementBits for a left shift; or |
| 2518 | /// 0 <= Value <= ElementBits for a long left shift. |
| 2519 | static bool isVShiftLImm(SDValue Op, MVT VT, bool isLong, int64_t &Cnt) { |
| 2520 | assert(VT.isVector() && "vector shift count is not a vector type"); |
| 2521 | unsigned ElementBits = VT.getVectorElementType().getSizeInBits(); |
| 2522 | if (! getVShiftImm(Op, ElementBits, Cnt)) |
| 2523 | return false; |
| 2524 | return (Cnt >= 0 && (isLong ? Cnt-1 : Cnt) < ElementBits); |
| 2525 | } |
| 2526 | |
| 2527 | /// isVShiftRImm - Check if this is a valid build_vector for the immediate |
| 2528 | /// operand of a vector shift right operation. For a shift opcode, the value |
| 2529 | /// is positive, but for an intrinsic the value count must be negative. The |
| 2530 | /// absolute value must be in the range: |
| 2531 | /// 1 <= |Value| <= ElementBits for a right shift; or |
| 2532 | /// 1 <= |Value| <= ElementBits/2 for a narrow right shift. |
| 2533 | static bool isVShiftRImm(SDValue Op, MVT VT, bool isNarrow, bool isIntrinsic, |
| 2534 | int64_t &Cnt) { |
| 2535 | assert(VT.isVector() && "vector shift count is not a vector type"); |
| 2536 | unsigned ElementBits = VT.getVectorElementType().getSizeInBits(); |
| 2537 | if (! getVShiftImm(Op, ElementBits, Cnt)) |
| 2538 | return false; |
| 2539 | if (isIntrinsic) |
| 2540 | Cnt = -Cnt; |
| 2541 | return (Cnt >= 1 && Cnt <= (isNarrow ? ElementBits/2 : ElementBits)); |
| 2542 | } |
| 2543 | |
| 2544 | /// PerformIntrinsicCombine - ARM-specific DAG combining for intrinsics. |
| 2545 | static SDValue PerformIntrinsicCombine(SDNode *N, SelectionDAG &DAG) { |
| 2546 | unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue(); |
| 2547 | switch (IntNo) { |
| 2548 | default: |
| 2549 | // Don't do anything for most intrinsics. |
| 2550 | break; |
| 2551 | |
| 2552 | // Vector shifts: check for immediate versions and lower them. |
| 2553 | // Note: This is done during DAG combining instead of DAG legalizing because |
| 2554 | // the build_vectors for 64-bit vector element shift counts are generally |
| 2555 | // not legal, and it is hard to see their values after they get legalized to |
| 2556 | // loads from a constant pool. |
| 2557 | case Intrinsic::arm_neon_vshifts: |
| 2558 | case Intrinsic::arm_neon_vshiftu: |
| 2559 | case Intrinsic::arm_neon_vshiftls: |
| 2560 | case Intrinsic::arm_neon_vshiftlu: |
| 2561 | case Intrinsic::arm_neon_vshiftn: |
| 2562 | case Intrinsic::arm_neon_vrshifts: |
| 2563 | case Intrinsic::arm_neon_vrshiftu: |
| 2564 | case Intrinsic::arm_neon_vrshiftn: |
| 2565 | case Intrinsic::arm_neon_vqshifts: |
| 2566 | case Intrinsic::arm_neon_vqshiftu: |
| 2567 | case Intrinsic::arm_neon_vqshiftsu: |
| 2568 | case Intrinsic::arm_neon_vqshiftns: |
| 2569 | case Intrinsic::arm_neon_vqshiftnu: |
| 2570 | case Intrinsic::arm_neon_vqshiftnsu: |
| 2571 | case Intrinsic::arm_neon_vqrshiftns: |
| 2572 | case Intrinsic::arm_neon_vqrshiftnu: |
| 2573 | case Intrinsic::arm_neon_vqrshiftnsu: { |
| 2574 | MVT VT = N->getOperand(1).getValueType(); |
| 2575 | int64_t Cnt; |
| 2576 | unsigned VShiftOpc = 0; |
| 2577 | |
| 2578 | switch (IntNo) { |
| 2579 | case Intrinsic::arm_neon_vshifts: |
| 2580 | case Intrinsic::arm_neon_vshiftu: |
| 2581 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) { |
| 2582 | VShiftOpc = ARMISD::VSHL; |
| 2583 | break; |
| 2584 | } |
| 2585 | if (isVShiftRImm(N->getOperand(2), VT, false, true, Cnt)) { |
| 2586 | VShiftOpc = (IntNo == Intrinsic::arm_neon_vshifts ? |
| 2587 | ARMISD::VSHRs : ARMISD::VSHRu); |
| 2588 | break; |
| 2589 | } |
| 2590 | return SDValue(); |
| 2591 | |
| 2592 | case Intrinsic::arm_neon_vshiftls: |
| 2593 | case Intrinsic::arm_neon_vshiftlu: |
| 2594 | if (isVShiftLImm(N->getOperand(2), VT, true, Cnt)) |
| 2595 | break; |
| 2596 | assert(0 && "invalid shift count for vshll intrinsic"); |
| 2597 | abort(); |
| 2598 | |
| 2599 | case Intrinsic::arm_neon_vrshifts: |
| 2600 | case Intrinsic::arm_neon_vrshiftu: |
| 2601 | if (isVShiftRImm(N->getOperand(2), VT, false, true, Cnt)) |
| 2602 | break; |
| 2603 | return SDValue(); |
| 2604 | |
| 2605 | case Intrinsic::arm_neon_vqshifts: |
| 2606 | case Intrinsic::arm_neon_vqshiftu: |
| 2607 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) |
| 2608 | break; |
| 2609 | return SDValue(); |
| 2610 | |
| 2611 | case Intrinsic::arm_neon_vqshiftsu: |
| 2612 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) |
| 2613 | break; |
| 2614 | assert(0 && "invalid shift count for vqshlu intrinsic"); |
| 2615 | abort(); |
| 2616 | |
| 2617 | case Intrinsic::arm_neon_vshiftn: |
| 2618 | case Intrinsic::arm_neon_vrshiftn: |
| 2619 | case Intrinsic::arm_neon_vqshiftns: |
| 2620 | case Intrinsic::arm_neon_vqshiftnu: |
| 2621 | case Intrinsic::arm_neon_vqshiftnsu: |
| 2622 | case Intrinsic::arm_neon_vqrshiftns: |
| 2623 | case Intrinsic::arm_neon_vqrshiftnu: |
| 2624 | case Intrinsic::arm_neon_vqrshiftnsu: |
| 2625 | // Narrowing shifts require an immediate right shift. |
| 2626 | if (isVShiftRImm(N->getOperand(2), VT, true, true, Cnt)) |
| 2627 | break; |
| 2628 | assert(0 && "invalid shift count for narrowing vector shift intrinsic"); |
| 2629 | abort(); |
| 2630 | |
| 2631 | default: |
| 2632 | assert(0 && "unhandled vector shift"); |
| 2633 | } |
| 2634 | |
| 2635 | switch (IntNo) { |
| 2636 | case Intrinsic::arm_neon_vshifts: |
| 2637 | case Intrinsic::arm_neon_vshiftu: |
| 2638 | // Opcode already set above. |
| 2639 | break; |
| 2640 | case Intrinsic::arm_neon_vshiftls: |
| 2641 | case Intrinsic::arm_neon_vshiftlu: |
| 2642 | if (Cnt == VT.getVectorElementType().getSizeInBits()) |
| 2643 | VShiftOpc = ARMISD::VSHLLi; |
| 2644 | else |
| 2645 | VShiftOpc = (IntNo == Intrinsic::arm_neon_vshiftls ? |
| 2646 | ARMISD::VSHLLs : ARMISD::VSHLLu); |
| 2647 | break; |
| 2648 | case Intrinsic::arm_neon_vshiftn: |
| 2649 | VShiftOpc = ARMISD::VSHRN; break; |
| 2650 | case Intrinsic::arm_neon_vrshifts: |
| 2651 | VShiftOpc = ARMISD::VRSHRs; break; |
| 2652 | case Intrinsic::arm_neon_vrshiftu: |
| 2653 | VShiftOpc = ARMISD::VRSHRu; break; |
| 2654 | case Intrinsic::arm_neon_vrshiftn: |
| 2655 | VShiftOpc = ARMISD::VRSHRN; break; |
| 2656 | case Intrinsic::arm_neon_vqshifts: |
| 2657 | VShiftOpc = ARMISD::VQSHLs; break; |
| 2658 | case Intrinsic::arm_neon_vqshiftu: |
| 2659 | VShiftOpc = ARMISD::VQSHLu; break; |
| 2660 | case Intrinsic::arm_neon_vqshiftsu: |
| 2661 | VShiftOpc = ARMISD::VQSHLsu; break; |
| 2662 | case Intrinsic::arm_neon_vqshiftns: |
| 2663 | VShiftOpc = ARMISD::VQSHRNs; break; |
| 2664 | case Intrinsic::arm_neon_vqshiftnu: |
| 2665 | VShiftOpc = ARMISD::VQSHRNu; break; |
| 2666 | case Intrinsic::arm_neon_vqshiftnsu: |
| 2667 | VShiftOpc = ARMISD::VQSHRNsu; break; |
| 2668 | case Intrinsic::arm_neon_vqrshiftns: |
| 2669 | VShiftOpc = ARMISD::VQRSHRNs; break; |
| 2670 | case Intrinsic::arm_neon_vqrshiftnu: |
| 2671 | VShiftOpc = ARMISD::VQRSHRNu; break; |
| 2672 | case Intrinsic::arm_neon_vqrshiftnsu: |
| 2673 | VShiftOpc = ARMISD::VQRSHRNsu; break; |
| 2674 | } |
| 2675 | |
| 2676 | return DAG.getNode(VShiftOpc, N->getDebugLoc(), N->getValueType(0), |
| 2677 | N->getOperand(1), DAG.getConstant(Cnt, MVT::i32)); |
| 2678 | } |
| 2679 | |
| 2680 | case Intrinsic::arm_neon_vshiftins: { |
| 2681 | MVT VT = N->getOperand(1).getValueType(); |
| 2682 | int64_t Cnt; |
| 2683 | unsigned VShiftOpc = 0; |
| 2684 | |
| 2685 | if (isVShiftLImm(N->getOperand(3), VT, false, Cnt)) |
| 2686 | VShiftOpc = ARMISD::VSLI; |
| 2687 | else if (isVShiftRImm(N->getOperand(3), VT, false, true, Cnt)) |
| 2688 | VShiftOpc = ARMISD::VSRI; |
| 2689 | else { |
| 2690 | assert(0 && "invalid shift count for vsli/vsri intrinsic"); |
| 2691 | abort(); |
| 2692 | } |
| 2693 | |
| 2694 | return DAG.getNode(VShiftOpc, N->getDebugLoc(), N->getValueType(0), |
| 2695 | N->getOperand(1), N->getOperand(2), |
| 2696 | DAG.getConstant(Cnt, MVT::i32)); |
| 2697 | } |
| 2698 | |
| 2699 | case Intrinsic::arm_neon_vqrshifts: |
| 2700 | case Intrinsic::arm_neon_vqrshiftu: |
| 2701 | // No immediate versions of these to check for. |
| 2702 | break; |
| 2703 | } |
| 2704 | |
| 2705 | return SDValue(); |
| 2706 | } |
| 2707 | |
| 2708 | /// PerformShiftCombine - Checks for immediate versions of vector shifts and |
| 2709 | /// lowers them. As with the vector shift intrinsics, this is done during DAG |
| 2710 | /// combining instead of DAG legalizing because the build_vectors for 64-bit |
| 2711 | /// vector element shift counts are generally not legal, and it is hard to see |
| 2712 | /// their values after they get legalized to loads from a constant pool. |
| 2713 | static SDValue PerformShiftCombine(SDNode *N, SelectionDAG &DAG, |
| 2714 | const ARMSubtarget *ST) { |
| 2715 | MVT VT = N->getValueType(0); |
| 2716 | |
| 2717 | // Nothing to be done for scalar shifts. |
| 2718 | if (! VT.isVector()) |
| 2719 | return SDValue(); |
| 2720 | |
| 2721 | assert(ST->hasNEON() && "unexpected vector shift"); |
| 2722 | int64_t Cnt; |
| 2723 | |
| 2724 | switch (N->getOpcode()) { |
| 2725 | default: assert(0 && "unexpected shift opcode"); |
| 2726 | |
| 2727 | case ISD::SHL: |
| 2728 | if (isVShiftLImm(N->getOperand(1), VT, false, Cnt)) |
| 2729 | return DAG.getNode(ARMISD::VSHL, N->getDebugLoc(), VT, N->getOperand(0), |
| 2730 | DAG.getConstant(Cnt, MVT::i32)); |
| 2731 | break; |
| 2732 | |
| 2733 | case ISD::SRA: |
| 2734 | case ISD::SRL: |
| 2735 | if (isVShiftRImm(N->getOperand(1), VT, false, false, Cnt)) { |
| 2736 | unsigned VShiftOpc = (N->getOpcode() == ISD::SRA ? |
| 2737 | ARMISD::VSHRs : ARMISD::VSHRu); |
| 2738 | return DAG.getNode(VShiftOpc, N->getDebugLoc(), VT, N->getOperand(0), |
| 2739 | DAG.getConstant(Cnt, MVT::i32)); |
| 2740 | } |
| 2741 | } |
| 2742 | return SDValue(); |
| 2743 | } |
| 2744 | |
| 2745 | /// PerformExtendCombine - Target-specific DAG combining for ISD::SIGN_EXTEND, |
| 2746 | /// ISD::ZERO_EXTEND, and ISD::ANY_EXTEND. |
| 2747 | static SDValue PerformExtendCombine(SDNode *N, SelectionDAG &DAG, |
| 2748 | const ARMSubtarget *ST) { |
| 2749 | SDValue N0 = N->getOperand(0); |
| 2750 | |
| 2751 | // Check for sign- and zero-extensions of vector extract operations of 8- |
| 2752 | // and 16-bit vector elements. NEON supports these directly. They are |
| 2753 | // handled during DAG combining because type legalization will promote them |
| 2754 | // to 32-bit types and it is messy to recognize the operations after that. |
| 2755 | if (ST->hasNEON() && N0.getOpcode() == ISD::EXTRACT_VECTOR_ELT) { |
| 2756 | SDValue Vec = N0.getOperand(0); |
| 2757 | SDValue Lane = N0.getOperand(1); |
| 2758 | MVT VT = N->getValueType(0); |
| 2759 | MVT EltVT = N0.getValueType(); |
| 2760 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 2761 | |
| 2762 | if (VT == MVT::i32 && |
| 2763 | (EltVT == MVT::i8 || EltVT == MVT::i16) && |
| 2764 | TLI.isTypeLegal(Vec.getValueType())) { |
| 2765 | |
| 2766 | unsigned Opc = 0; |
| 2767 | switch (N->getOpcode()) { |
| 2768 | default: assert(0 && "unexpected opcode"); |
| 2769 | case ISD::SIGN_EXTEND: |
| 2770 | Opc = ARMISD::VGETLANEs; |
| 2771 | break; |
| 2772 | case ISD::ZERO_EXTEND: |
| 2773 | case ISD::ANY_EXTEND: |
| 2774 | Opc = ARMISD::VGETLANEu; |
| 2775 | break; |
| 2776 | } |
| 2777 | return DAG.getNode(Opc, N->getDebugLoc(), VT, Vec, Lane); |
| 2778 | } |
| 2779 | } |
| 2780 | |
| 2781 | return SDValue(); |
| 2782 | } |
| 2783 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2784 | SDValue ARMTargetLowering::PerformDAGCombine(SDNode *N, |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2785 | DAGCombinerInfo &DCI) const { |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 2786 | switch (N->getOpcode()) { |
| 2787 | default: break; |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 2788 | case ISD::ADD: return PerformADDCombine(N, DCI); |
| 2789 | case ISD::SUB: return PerformSUBCombine(N, DCI); |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 2790 | case ARMISD::FMRRD: return PerformFMRRDCombine(N, DCI); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2791 | case ISD::INTRINSIC_WO_CHAIN: |
| 2792 | return PerformIntrinsicCombine(N, DCI.DAG); |
| 2793 | case ISD::SHL: |
| 2794 | case ISD::SRA: |
| 2795 | case ISD::SRL: |
| 2796 | return PerformShiftCombine(N, DCI.DAG, Subtarget); |
| 2797 | case ISD::SIGN_EXTEND: |
| 2798 | case ISD::ZERO_EXTEND: |
| 2799 | case ISD::ANY_EXTEND: |
| 2800 | return PerformExtendCombine(N, DCI.DAG, Subtarget); |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 2801 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2802 | return SDValue(); |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 2803 | } |
| 2804 | |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 2805 | /// isLegalAddressImmediate - Return true if the integer value can be used |
| 2806 | /// as the offset of the target addressing mode for load / store of the |
| 2807 | /// given type. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2808 | static bool isLegalAddressImmediate(int64_t V, MVT VT, |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 2809 | const ARMSubtarget *Subtarget) { |
Evan Cheng | 961f879 | 2007-03-13 20:37:59 +0000 | [diff] [blame] | 2810 | if (V == 0) |
| 2811 | return true; |
| 2812 | |
Evan Cheng | 6501153 | 2009-03-09 19:15:00 +0000 | [diff] [blame] | 2813 | if (!VT.isSimple()) |
| 2814 | return false; |
| 2815 | |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 2816 | if (Subtarget->isThumb()) { |
| 2817 | if (V < 0) |
| 2818 | return false; |
| 2819 | |
| 2820 | unsigned Scale = 1; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2821 | switch (VT.getSimpleVT()) { |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 2822 | default: return false; |
| 2823 | case MVT::i1: |
| 2824 | case MVT::i8: |
| 2825 | // Scale == 1; |
| 2826 | break; |
| 2827 | case MVT::i16: |
| 2828 | // Scale == 2; |
| 2829 | Scale = 2; |
| 2830 | break; |
| 2831 | case MVT::i32: |
| 2832 | // Scale == 4; |
| 2833 | Scale = 4; |
| 2834 | break; |
| 2835 | } |
| 2836 | |
| 2837 | if ((V & (Scale - 1)) != 0) |
| 2838 | return false; |
| 2839 | V /= Scale; |
Anton Korobeynikov | 7c1c261 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 2840 | return V == (V & ((1LL << 5) - 1)); |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 2841 | } |
| 2842 | |
| 2843 | if (V < 0) |
| 2844 | V = - V; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2845 | switch (VT.getSimpleVT()) { |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 2846 | default: return false; |
| 2847 | case MVT::i1: |
| 2848 | case MVT::i8: |
| 2849 | case MVT::i32: |
| 2850 | // +- imm12 |
Anton Korobeynikov | 7c1c261 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 2851 | return V == (V & ((1LL << 12) - 1)); |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 2852 | case MVT::i16: |
| 2853 | // +- imm8 |
Anton Korobeynikov | 7c1c261 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 2854 | return V == (V & ((1LL << 8) - 1)); |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 2855 | case MVT::f32: |
| 2856 | case MVT::f64: |
| 2857 | if (!Subtarget->hasVFP2()) |
| 2858 | return false; |
Evan Cheng | 0b0a9a9 | 2007-05-03 02:00:18 +0000 | [diff] [blame] | 2859 | if ((V & 3) != 0) |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 2860 | return false; |
| 2861 | V >>= 2; |
Anton Korobeynikov | 7c1c261 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 2862 | return V == (V & ((1LL << 8) - 1)); |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 2863 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2864 | } |
| 2865 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 2866 | /// isLegalAddressingMode - Return true if the addressing mode represented |
| 2867 | /// 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] | 2868 | bool ARMTargetLowering::isLegalAddressingMode(const AddrMode &AM, |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 2869 | const Type *Ty) const { |
Bob Wilson | 2c7dab1 | 2009-04-08 17:55:28 +0000 | [diff] [blame] | 2870 | MVT VT = getValueType(Ty, true); |
| 2871 | if (!isLegalAddressImmediate(AM.BaseOffs, VT, Subtarget)) |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 2872 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2873 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 2874 | // Can never fold addr of global into load/store. |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2875 | if (AM.BaseGV) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 2876 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2877 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 2878 | switch (AM.Scale) { |
| 2879 | case 0: // no scale reg, must be "r+i" or "r", or "i". |
| 2880 | break; |
| 2881 | case 1: |
| 2882 | if (Subtarget->isThumb()) |
| 2883 | return false; |
Chris Lattner | 5a3d40d | 2007-04-13 06:50:55 +0000 | [diff] [blame] | 2884 | // FALL THROUGH. |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 2885 | default: |
Chris Lattner | 5a3d40d | 2007-04-13 06:50:55 +0000 | [diff] [blame] | 2886 | // ARM doesn't support any R+R*scale+imm addr modes. |
| 2887 | if (AM.BaseOffs) |
| 2888 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2889 | |
Bob Wilson | 2c7dab1 | 2009-04-08 17:55:28 +0000 | [diff] [blame] | 2890 | if (!VT.isSimple()) |
| 2891 | return false; |
| 2892 | |
Chris Lattner | eb13d1b | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 2893 | int Scale = AM.Scale; |
Bob Wilson | 2c7dab1 | 2009-04-08 17:55:28 +0000 | [diff] [blame] | 2894 | switch (VT.getSimpleVT()) { |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 2895 | default: return false; |
| 2896 | case MVT::i1: |
| 2897 | case MVT::i8: |
| 2898 | case MVT::i32: |
| 2899 | case MVT::i64: |
| 2900 | // This assumes i64 is legalized to a pair of i32. If not (i.e. |
| 2901 | // ldrd / strd are used, then its address mode is same as i16. |
| 2902 | // r + r |
Chris Lattner | eb13d1b | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 2903 | if (Scale < 0) Scale = -Scale; |
| 2904 | if (Scale == 1) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 2905 | return true; |
| 2906 | // r + r << imm |
Chris Lattner | e115294 | 2007-04-11 16:17:12 +0000 | [diff] [blame] | 2907 | return isPowerOf2_32(Scale & ~1); |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 2908 | case MVT::i16: |
| 2909 | // r + r |
Chris Lattner | eb13d1b | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 2910 | if (((unsigned)AM.HasBaseReg + Scale) <= 2) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 2911 | return true; |
Chris Lattner | e115294 | 2007-04-11 16:17:12 +0000 | [diff] [blame] | 2912 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2913 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 2914 | case MVT::isVoid: |
| 2915 | // Note, we allow "void" uses (basically, uses that aren't loads or |
| 2916 | // stores), because arm allows folding a scale into many arithmetic |
| 2917 | // operations. This should be made more precise and revisited later. |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2918 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 2919 | // Allow r << imm, but the imm has to be a multiple of two. |
| 2920 | if (AM.Scale & 1) return false; |
| 2921 | return isPowerOf2_32(AM.Scale); |
| 2922 | } |
| 2923 | break; |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 2924 | } |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 2925 | return true; |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 2926 | } |
| 2927 | |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 2928 | static bool getARMIndexedAddressParts(SDNode *Ptr, MVT VT, |
| 2929 | bool isSEXTLoad, SDValue &Base, |
| 2930 | SDValue &Offset, bool &isInc, |
| 2931 | SelectionDAG &DAG) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2932 | if (Ptr->getOpcode() != ISD::ADD && Ptr->getOpcode() != ISD::SUB) |
| 2933 | return false; |
| 2934 | |
| 2935 | if (VT == MVT::i16 || ((VT == MVT::i8 || VT == MVT::i1) && isSEXTLoad)) { |
| 2936 | // AddressingMode 3 |
| 2937 | Base = Ptr->getOperand(0); |
| 2938 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2939 | int RHSC = (int)RHS->getZExtValue(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2940 | if (RHSC < 0 && RHSC > -256) { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 2941 | assert(Ptr->getOpcode() == ISD::ADD); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2942 | isInc = false; |
| 2943 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); |
| 2944 | return true; |
| 2945 | } |
| 2946 | } |
| 2947 | isInc = (Ptr->getOpcode() == ISD::ADD); |
| 2948 | Offset = Ptr->getOperand(1); |
| 2949 | return true; |
| 2950 | } else if (VT == MVT::i32 || VT == MVT::i8 || VT == MVT::i1) { |
| 2951 | // AddressingMode 2 |
| 2952 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2953 | int RHSC = (int)RHS->getZExtValue(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2954 | if (RHSC < 0 && RHSC > -0x1000) { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 2955 | assert(Ptr->getOpcode() == ISD::ADD); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2956 | isInc = false; |
| 2957 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); |
| 2958 | Base = Ptr->getOperand(0); |
| 2959 | return true; |
| 2960 | } |
| 2961 | } |
| 2962 | |
| 2963 | if (Ptr->getOpcode() == ISD::ADD) { |
| 2964 | isInc = true; |
| 2965 | ARM_AM::ShiftOpc ShOpcVal= ARM_AM::getShiftOpcForNode(Ptr->getOperand(0)); |
| 2966 | if (ShOpcVal != ARM_AM::no_shift) { |
| 2967 | Base = Ptr->getOperand(1); |
| 2968 | Offset = Ptr->getOperand(0); |
| 2969 | } else { |
| 2970 | Base = Ptr->getOperand(0); |
| 2971 | Offset = Ptr->getOperand(1); |
| 2972 | } |
| 2973 | return true; |
| 2974 | } |
| 2975 | |
| 2976 | isInc = (Ptr->getOpcode() == ISD::ADD); |
| 2977 | Base = Ptr->getOperand(0); |
| 2978 | Offset = Ptr->getOperand(1); |
| 2979 | return true; |
| 2980 | } |
| 2981 | |
| 2982 | // FIXME: Use FLDM / FSTM to emulate indexed FP load / store. |
| 2983 | return false; |
| 2984 | } |
| 2985 | |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 2986 | static bool getT2IndexedAddressParts(SDNode *Ptr, MVT VT, |
| 2987 | bool isSEXTLoad, SDValue &Base, |
| 2988 | SDValue &Offset, bool &isInc, |
| 2989 | SelectionDAG &DAG) { |
| 2990 | if (Ptr->getOpcode() != ISD::ADD && Ptr->getOpcode() != ISD::SUB) |
| 2991 | return false; |
| 2992 | |
| 2993 | Base = Ptr->getOperand(0); |
| 2994 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
| 2995 | int RHSC = (int)RHS->getZExtValue(); |
| 2996 | if (RHSC < 0 && RHSC > -0x100) { // 8 bits. |
| 2997 | assert(Ptr->getOpcode() == ISD::ADD); |
| 2998 | isInc = false; |
| 2999 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); |
| 3000 | return true; |
| 3001 | } else if (RHSC > 0 && RHSC < 0x100) { // 8 bit, no zero. |
| 3002 | isInc = Ptr->getOpcode() == ISD::ADD; |
| 3003 | Offset = DAG.getConstant(RHSC, RHS->getValueType(0)); |
| 3004 | return true; |
| 3005 | } |
| 3006 | } |
| 3007 | |
| 3008 | return false; |
| 3009 | } |
| 3010 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3011 | /// getPreIndexedAddressParts - returns true by value, base pointer and |
| 3012 | /// offset pointer and addressing mode by reference if the node's address |
| 3013 | /// can be legally represented as pre-indexed load / store address. |
| 3014 | bool |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3015 | ARMTargetLowering::getPreIndexedAddressParts(SDNode *N, SDValue &Base, |
| 3016 | SDValue &Offset, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3017 | ISD::MemIndexedMode &AM, |
Dan Gohman | 73e0914 | 2009-01-15 16:29:45 +0000 | [diff] [blame] | 3018 | SelectionDAG &DAG) const { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 3019 | if (Subtarget->isThumb1Only()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3020 | return false; |
| 3021 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3022 | MVT VT; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3023 | SDValue Ptr; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3024 | bool isSEXTLoad = false; |
| 3025 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) { |
| 3026 | Ptr = LD->getBasePtr(); |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 3027 | VT = LD->getMemoryVT(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3028 | isSEXTLoad = LD->getExtensionType() == ISD::SEXTLOAD; |
| 3029 | } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) { |
| 3030 | Ptr = ST->getBasePtr(); |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 3031 | VT = ST->getMemoryVT(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3032 | } else |
| 3033 | return false; |
| 3034 | |
| 3035 | bool isInc; |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 3036 | bool isLegal = false; |
| 3037 | if (Subtarget->isThumb2()) |
| 3038 | isLegal = getT2IndexedAddressParts(Ptr.getNode(), VT, isSEXTLoad, Base, |
| 3039 | Offset, isInc, DAG); |
| 3040 | else |
| 3041 | isLegal = getARMIndexedAddressParts(Ptr.getNode(), VT, isSEXTLoad, Base, |
Evan Cheng | 0412957 | 2009-07-02 06:44:30 +0000 | [diff] [blame] | 3042 | Offset, isInc, DAG); |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 3043 | if (!isLegal) |
| 3044 | return false; |
| 3045 | |
| 3046 | AM = isInc ? ISD::PRE_INC : ISD::PRE_DEC; |
| 3047 | return true; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3048 | } |
| 3049 | |
| 3050 | /// getPostIndexedAddressParts - returns true by value, base pointer and |
| 3051 | /// offset pointer and addressing mode by reference if this node can be |
| 3052 | /// combined with a load / store to form a post-indexed load / store. |
| 3053 | bool ARMTargetLowering::getPostIndexedAddressParts(SDNode *N, SDNode *Op, |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3054 | SDValue &Base, |
| 3055 | SDValue &Offset, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3056 | ISD::MemIndexedMode &AM, |
Dan Gohman | 73e0914 | 2009-01-15 16:29:45 +0000 | [diff] [blame] | 3057 | SelectionDAG &DAG) const { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 3058 | if (Subtarget->isThumb1Only()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3059 | return false; |
| 3060 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3061 | MVT VT; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3062 | SDValue Ptr; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3063 | bool isSEXTLoad = false; |
| 3064 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) { |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 3065 | VT = LD->getMemoryVT(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3066 | isSEXTLoad = LD->getExtensionType() == ISD::SEXTLOAD; |
| 3067 | } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) { |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 3068 | VT = ST->getMemoryVT(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3069 | } else |
| 3070 | return false; |
| 3071 | |
| 3072 | bool isInc; |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 3073 | bool isLegal = false; |
| 3074 | if (Subtarget->isThumb2()) |
| 3075 | isLegal = getT2IndexedAddressParts(Op, VT, isSEXTLoad, Base, Offset, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3076 | isInc, DAG); |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 3077 | else |
| 3078 | isLegal = getARMIndexedAddressParts(Op, VT, isSEXTLoad, Base, Offset, |
| 3079 | isInc, DAG); |
| 3080 | if (!isLegal) |
| 3081 | return false; |
| 3082 | |
| 3083 | AM = isInc ? ISD::POST_INC : ISD::POST_DEC; |
| 3084 | return true; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3085 | } |
| 3086 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3087 | void ARMTargetLowering::computeMaskedBitsForTargetNode(const SDValue Op, |
Dan Gohman | 977a76f | 2008-02-13 22:28:48 +0000 | [diff] [blame] | 3088 | const APInt &Mask, |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3089 | APInt &KnownZero, |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 3090 | APInt &KnownOne, |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 3091 | const SelectionDAG &DAG, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3092 | unsigned Depth) const { |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 3093 | KnownZero = KnownOne = APInt(Mask.getBitWidth(), 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3094 | switch (Op.getOpcode()) { |
| 3095 | default: break; |
| 3096 | case ARMISD::CMOV: { |
| 3097 | // Bits are known zero/one if known on the LHS and RHS. |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 3098 | DAG.ComputeMaskedBits(Op.getOperand(0), Mask, KnownZero, KnownOne, Depth+1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3099 | if (KnownZero == 0 && KnownOne == 0) return; |
| 3100 | |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 3101 | APInt KnownZeroRHS, KnownOneRHS; |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 3102 | DAG.ComputeMaskedBits(Op.getOperand(1), Mask, |
| 3103 | KnownZeroRHS, KnownOneRHS, Depth+1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3104 | KnownZero &= KnownZeroRHS; |
| 3105 | KnownOne &= KnownOneRHS; |
| 3106 | return; |
| 3107 | } |
| 3108 | } |
| 3109 | } |
| 3110 | |
| 3111 | //===----------------------------------------------------------------------===// |
| 3112 | // ARM Inline Assembly Support |
| 3113 | //===----------------------------------------------------------------------===// |
| 3114 | |
| 3115 | /// getConstraintType - Given a constraint letter, return the type of |
| 3116 | /// constraint it is for this target. |
| 3117 | ARMTargetLowering::ConstraintType |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 3118 | ARMTargetLowering::getConstraintType(const std::string &Constraint) const { |
| 3119 | if (Constraint.size() == 1) { |
| 3120 | switch (Constraint[0]) { |
| 3121 | default: break; |
| 3122 | case 'l': return C_RegisterClass; |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 3123 | case 'w': return C_RegisterClass; |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 3124 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3125 | } |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 3126 | return TargetLowering::getConstraintType(Constraint); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3127 | } |
| 3128 | |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3129 | std::pair<unsigned, const TargetRegisterClass*> |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3130 | ARMTargetLowering::getRegForInlineAsmConstraint(const std::string &Constraint, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3131 | MVT VT) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3132 | if (Constraint.size() == 1) { |
| 3133 | // GCC RS6000 Constraint Letters |
| 3134 | switch (Constraint[0]) { |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 3135 | case 'l': |
Jim Grosbach | 30eae3c | 2009-04-07 20:34:09 +0000 | [diff] [blame] | 3136 | if (Subtarget->isThumb()) |
| 3137 | return std::make_pair(0U, ARM::tGPRRegisterClass); |
| 3138 | else |
| 3139 | return std::make_pair(0U, ARM::GPRRegisterClass); |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 3140 | case 'r': |
| 3141 | return std::make_pair(0U, ARM::GPRRegisterClass); |
| 3142 | case 'w': |
| 3143 | if (VT == MVT::f32) |
| 3144 | return std::make_pair(0U, ARM::SPRRegisterClass); |
Evan Cheng | 0a7baa2 | 2007-04-04 00:06:07 +0000 | [diff] [blame] | 3145 | if (VT == MVT::f64) |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 3146 | return std::make_pair(0U, ARM::DPRRegisterClass); |
| 3147 | break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3148 | } |
| 3149 | } |
| 3150 | return TargetLowering::getRegForInlineAsmConstraint(Constraint, VT); |
| 3151 | } |
| 3152 | |
| 3153 | std::vector<unsigned> ARMTargetLowering:: |
| 3154 | getRegClassForInlineAsmConstraint(const std::string &Constraint, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3155 | MVT VT) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3156 | if (Constraint.size() != 1) |
| 3157 | return std::vector<unsigned>(); |
| 3158 | |
| 3159 | switch (Constraint[0]) { // GCC ARM Constraint Letters |
| 3160 | default: break; |
| 3161 | case 'l': |
Jim Grosbach | 30eae3c | 2009-04-07 20:34:09 +0000 | [diff] [blame] | 3162 | return make_vector<unsigned>(ARM::R0, ARM::R1, ARM::R2, ARM::R3, |
| 3163 | ARM::R4, ARM::R5, ARM::R6, ARM::R7, |
| 3164 | 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3165 | case 'r': |
| 3166 | return make_vector<unsigned>(ARM::R0, ARM::R1, ARM::R2, ARM::R3, |
| 3167 | ARM::R4, ARM::R5, ARM::R6, ARM::R7, |
| 3168 | ARM::R8, ARM::R9, ARM::R10, ARM::R11, |
| 3169 | ARM::R12, ARM::LR, 0); |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 3170 | case 'w': |
| 3171 | if (VT == MVT::f32) |
| 3172 | return make_vector<unsigned>(ARM::S0, ARM::S1, ARM::S2, ARM::S3, |
| 3173 | ARM::S4, ARM::S5, ARM::S6, ARM::S7, |
| 3174 | ARM::S8, ARM::S9, ARM::S10, ARM::S11, |
| 3175 | ARM::S12,ARM::S13,ARM::S14,ARM::S15, |
| 3176 | ARM::S16,ARM::S17,ARM::S18,ARM::S19, |
| 3177 | ARM::S20,ARM::S21,ARM::S22,ARM::S23, |
| 3178 | ARM::S24,ARM::S25,ARM::S26,ARM::S27, |
| 3179 | ARM::S28,ARM::S29,ARM::S30,ARM::S31, 0); |
| 3180 | if (VT == MVT::f64) |
| 3181 | return make_vector<unsigned>(ARM::D0, ARM::D1, ARM::D2, ARM::D3, |
| 3182 | ARM::D4, ARM::D5, ARM::D6, ARM::D7, |
| 3183 | ARM::D8, ARM::D9, ARM::D10,ARM::D11, |
| 3184 | ARM::D12,ARM::D13,ARM::D14,ARM::D15, 0); |
| 3185 | break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3186 | } |
| 3187 | |
| 3188 | return std::vector<unsigned>(); |
| 3189 | } |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 3190 | |
| 3191 | /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops |
| 3192 | /// vector. If it is invalid, don't add anything to Ops. |
| 3193 | void ARMTargetLowering::LowerAsmOperandForConstraint(SDValue Op, |
| 3194 | char Constraint, |
| 3195 | bool hasMemory, |
| 3196 | std::vector<SDValue>&Ops, |
| 3197 | SelectionDAG &DAG) const { |
| 3198 | SDValue Result(0, 0); |
| 3199 | |
| 3200 | switch (Constraint) { |
| 3201 | default: break; |
| 3202 | case 'I': case 'J': case 'K': case 'L': |
| 3203 | case 'M': case 'N': case 'O': |
| 3204 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op); |
| 3205 | if (!C) |
| 3206 | return; |
| 3207 | |
| 3208 | int64_t CVal64 = C->getSExtValue(); |
| 3209 | int CVal = (int) CVal64; |
| 3210 | // None of these constraints allow values larger than 32 bits. Check |
| 3211 | // that the value fits in an int. |
| 3212 | if (CVal != CVal64) |
| 3213 | return; |
| 3214 | |
| 3215 | switch (Constraint) { |
| 3216 | case 'I': |
| 3217 | if (Subtarget->isThumb()) { |
| 3218 | // This must be a constant between 0 and 255, for ADD immediates. |
| 3219 | if (CVal >= 0 && CVal <= 255) |
| 3220 | break; |
| 3221 | } else { |
| 3222 | // A constant that can be used as an immediate value in a |
| 3223 | // data-processing instruction. |
| 3224 | if (ARM_AM::getSOImmVal(CVal) != -1) |
| 3225 | break; |
| 3226 | } |
| 3227 | return; |
| 3228 | |
| 3229 | case 'J': |
| 3230 | if (Subtarget->isThumb()) { |
| 3231 | // This must be a constant between -255 and -1, for negated ADD |
| 3232 | // immediates. This can be used in GCC with an "n" modifier that |
| 3233 | // prints the negated value, for use with SUB instructions. It is |
| 3234 | // not useful otherwise but is implemented for compatibility. |
| 3235 | if (CVal >= -255 && CVal <= -1) |
| 3236 | break; |
| 3237 | } else { |
| 3238 | // This must be a constant between -4095 and 4095. It is not clear |
| 3239 | // what this constraint is intended for. Implemented for |
| 3240 | // compatibility with GCC. |
| 3241 | if (CVal >= -4095 && CVal <= 4095) |
| 3242 | break; |
| 3243 | } |
| 3244 | return; |
| 3245 | |
| 3246 | case 'K': |
| 3247 | if (Subtarget->isThumb()) { |
| 3248 | // A 32-bit value where only one byte has a nonzero value. Exclude |
| 3249 | // zero to match GCC. This constraint is used by GCC internally for |
| 3250 | // constants that can be loaded with a move/shift combination. |
| 3251 | // It is not useful otherwise but is implemented for compatibility. |
| 3252 | if (CVal != 0 && ARM_AM::isThumbImmShiftedVal(CVal)) |
| 3253 | break; |
| 3254 | } else { |
| 3255 | // A constant whose bitwise inverse can be used as an immediate |
| 3256 | // value in a data-processing instruction. This can be used in GCC |
| 3257 | // with a "B" modifier that prints the inverted value, for use with |
| 3258 | // BIC and MVN instructions. It is not useful otherwise but is |
| 3259 | // implemented for compatibility. |
| 3260 | if (ARM_AM::getSOImmVal(~CVal) != -1) |
| 3261 | break; |
| 3262 | } |
| 3263 | return; |
| 3264 | |
| 3265 | case 'L': |
| 3266 | if (Subtarget->isThumb()) { |
| 3267 | // This must be a constant between -7 and 7, |
| 3268 | // for 3-operand ADD/SUB immediate instructions. |
| 3269 | if (CVal >= -7 && CVal < 7) |
| 3270 | break; |
| 3271 | } else { |
| 3272 | // A constant whose negation can be used as an immediate value in a |
| 3273 | // data-processing instruction. This can be used in GCC with an "n" |
| 3274 | // modifier that prints the negated value, for use with SUB |
| 3275 | // instructions. It is not useful otherwise but is implemented for |
| 3276 | // compatibility. |
| 3277 | if (ARM_AM::getSOImmVal(-CVal) != -1) |
| 3278 | break; |
| 3279 | } |
| 3280 | return; |
| 3281 | |
| 3282 | case 'M': |
| 3283 | if (Subtarget->isThumb()) { |
| 3284 | // This must be a multiple of 4 between 0 and 1020, for |
| 3285 | // ADD sp + immediate. |
| 3286 | if ((CVal >= 0 && CVal <= 1020) && ((CVal & 3) == 0)) |
| 3287 | break; |
| 3288 | } else { |
| 3289 | // A power of two or a constant between 0 and 32. This is used in |
| 3290 | // GCC for the shift amount on shifted register operands, but it is |
| 3291 | // useful in general for any shift amounts. |
| 3292 | if ((CVal >= 0 && CVal <= 32) || ((CVal & (CVal - 1)) == 0)) |
| 3293 | break; |
| 3294 | } |
| 3295 | return; |
| 3296 | |
| 3297 | case 'N': |
| 3298 | if (Subtarget->isThumb()) { |
| 3299 | // This must be a constant between 0 and 31, for shift amounts. |
| 3300 | if (CVal >= 0 && CVal <= 31) |
| 3301 | break; |
| 3302 | } |
| 3303 | return; |
| 3304 | |
| 3305 | case 'O': |
| 3306 | if (Subtarget->isThumb()) { |
| 3307 | // This must be a multiple of 4 between -508 and 508, for |
| 3308 | // ADD/SUB sp = sp + immediate. |
| 3309 | if ((CVal >= -508 && CVal <= 508) && ((CVal & 3) == 0)) |
| 3310 | break; |
| 3311 | } |
| 3312 | return; |
| 3313 | } |
| 3314 | Result = DAG.getTargetConstant(CVal, Op.getValueType()); |
| 3315 | break; |
| 3316 | } |
| 3317 | |
| 3318 | if (Result.getNode()) { |
| 3319 | Ops.push_back(Result); |
| 3320 | return; |
| 3321 | } |
| 3322 | return TargetLowering::LowerAsmOperandForConstraint(Op, Constraint, hasMemory, |
| 3323 | Ops, DAG); |
| 3324 | } |