Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1 | //===-- ARMISelLowering.cpp - ARM DAG Lowering Implementation -------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines the interfaces that ARM uses to lower LLVM code into a |
| 11 | // selection DAG. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "ARM.h" |
| 16 | #include "ARMAddressingModes.h" |
| 17 | #include "ARMConstantPoolValue.h" |
| 18 | #include "ARMISelLowering.h" |
| 19 | #include "ARMMachineFunctionInfo.h" |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 20 | #include "ARMPerfectShuffle.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 21 | #include "ARMRegisterInfo.h" |
| 22 | #include "ARMSubtarget.h" |
| 23 | #include "ARMTargetMachine.h" |
Chris Lattner | 80ec279 | 2009-08-02 00:34:36 +0000 | [diff] [blame] | 24 | #include "ARMTargetObjectFile.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 25 | #include "llvm/CallingConv.h" |
| 26 | #include "llvm/Constants.h" |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 27 | #include "llvm/Function.h" |
Benjamin Kramer | 174101e | 2009-10-20 11:44:38 +0000 | [diff] [blame] | 28 | #include "llvm/GlobalValue.h" |
Evan Cheng | 2770747 | 2007-03-16 08:43:56 +0000 | [diff] [blame] | 29 | #include "llvm/Instruction.h" |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 30 | #include "llvm/Intrinsics.h" |
Benjamin Kramer | 174101e | 2009-10-20 11:44:38 +0000 | [diff] [blame] | 31 | #include "llvm/Type.h" |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 32 | #include "llvm/CodeGen/CallingConvLower.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 33 | #include "llvm/CodeGen/MachineBasicBlock.h" |
| 34 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 35 | #include "llvm/CodeGen/MachineFunction.h" |
| 36 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 37 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 38 | #include "llvm/CodeGen/PseudoSourceValue.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 39 | #include "llvm/CodeGen/SelectionDAG.h" |
Bill Wendling | 94a1c63 | 2010-03-09 02:46:12 +0000 | [diff] [blame] | 40 | #include "llvm/MC/MCSectionMachO.h" |
Evan Cheng | b6ab254 | 2007-01-31 08:40:13 +0000 | [diff] [blame] | 41 | #include "llvm/Target/TargetOptions.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 42 | #include "llvm/ADT/VectorExtras.h" |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 43 | #include "llvm/Support/CommandLine.h" |
Torok Edwin | ab7c09b | 2009-07-08 18:01:40 +0000 | [diff] [blame] | 44 | #include "llvm/Support/ErrorHandling.h" |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 45 | #include "llvm/Support/MathExtras.h" |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 46 | #include "llvm/Support/raw_ostream.h" |
Jim Grosbach | 3fb2b1e | 2009-09-01 01:57:56 +0000 | [diff] [blame] | 47 | #include <sstream> |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 48 | using namespace llvm; |
| 49 | |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 50 | static cl::opt<bool> |
| 51 | EnableARMLongCalls("arm-long-calls", cl::Hidden, |
| 52 | cl::desc("Generate calls via indirect call instructions."), |
| 53 | cl::init(false)); |
| 54 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 55 | static bool CC_ARM_APCS_Custom_f64(unsigned &ValNo, EVT &ValVT, EVT &LocVT, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 56 | CCValAssign::LocInfo &LocInfo, |
| 57 | ISD::ArgFlagsTy &ArgFlags, |
| 58 | CCState &State); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 59 | static bool CC_ARM_AAPCS_Custom_f64(unsigned &ValNo, EVT &ValVT, EVT &LocVT, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 60 | CCValAssign::LocInfo &LocInfo, |
| 61 | ISD::ArgFlagsTy &ArgFlags, |
| 62 | CCState &State); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 63 | static bool RetCC_ARM_APCS_Custom_f64(unsigned &ValNo, EVT &ValVT, EVT &LocVT, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 64 | CCValAssign::LocInfo &LocInfo, |
| 65 | ISD::ArgFlagsTy &ArgFlags, |
| 66 | CCState &State); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 67 | static bool RetCC_ARM_AAPCS_Custom_f64(unsigned &ValNo, EVT &ValVT, EVT &LocVT, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 68 | CCValAssign::LocInfo &LocInfo, |
| 69 | ISD::ArgFlagsTy &ArgFlags, |
| 70 | CCState &State); |
| 71 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 72 | void ARMTargetLowering::addTypeForNEON(EVT VT, EVT PromotedLdStVT, |
| 73 | EVT PromotedBitwiseVT) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 74 | if (VT != PromotedLdStVT) { |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 75 | setOperationAction(ISD::LOAD, VT.getSimpleVT(), Promote); |
Owen Anderson | d6662ad | 2009-08-10 20:46:15 +0000 | [diff] [blame] | 76 | AddPromotedToType (ISD::LOAD, VT.getSimpleVT(), |
| 77 | PromotedLdStVT.getSimpleVT()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 78 | |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 79 | setOperationAction(ISD::STORE, VT.getSimpleVT(), Promote); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 80 | AddPromotedToType (ISD::STORE, VT.getSimpleVT(), |
Owen Anderson | d6662ad | 2009-08-10 20:46:15 +0000 | [diff] [blame] | 81 | PromotedLdStVT.getSimpleVT()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 82 | } |
| 83 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 84 | EVT ElemTy = VT.getVectorElementType(); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 85 | if (ElemTy != MVT::i64 && ElemTy != MVT::f64) |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 86 | setOperationAction(ISD::VSETCC, VT.getSimpleVT(), Custom); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 87 | if (ElemTy == MVT::i8 || ElemTy == MVT::i16) |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 88 | setOperationAction(ISD::EXTRACT_VECTOR_ELT, VT.getSimpleVT(), Custom); |
Bob Wilson | 0696fdf | 2009-09-16 20:20:44 +0000 | [diff] [blame] | 89 | if (ElemTy != MVT::i32) { |
| 90 | setOperationAction(ISD::SINT_TO_FP, VT.getSimpleVT(), Expand); |
| 91 | setOperationAction(ISD::UINT_TO_FP, VT.getSimpleVT(), Expand); |
| 92 | setOperationAction(ISD::FP_TO_SINT, VT.getSimpleVT(), Expand); |
| 93 | setOperationAction(ISD::FP_TO_UINT, VT.getSimpleVT(), Expand); |
| 94 | } |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 95 | setOperationAction(ISD::BUILD_VECTOR, VT.getSimpleVT(), Custom); |
| 96 | setOperationAction(ISD::VECTOR_SHUFFLE, VT.getSimpleVT(), Custom); |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 97 | setOperationAction(ISD::CONCAT_VECTORS, VT.getSimpleVT(), Custom); |
Anton Korobeynikov | 8e6c2b9 | 2009-08-21 12:40:35 +0000 | [diff] [blame] | 98 | setOperationAction(ISD::EXTRACT_SUBVECTOR, VT.getSimpleVT(), Expand); |
Bob Wilson | d0910c4 | 2010-04-06 22:02:24 +0000 | [diff] [blame] | 99 | setOperationAction(ISD::SELECT, VT.getSimpleVT(), Expand); |
| 100 | setOperationAction(ISD::SELECT_CC, VT.getSimpleVT(), Expand); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 101 | if (VT.isInteger()) { |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 102 | setOperationAction(ISD::SHL, VT.getSimpleVT(), Custom); |
| 103 | setOperationAction(ISD::SRA, VT.getSimpleVT(), Custom); |
| 104 | setOperationAction(ISD::SRL, VT.getSimpleVT(), Custom); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | // Promote all bit-wise operations. |
| 108 | if (VT.isInteger() && VT != PromotedBitwiseVT) { |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 109 | setOperationAction(ISD::AND, VT.getSimpleVT(), Promote); |
Owen Anderson | d6662ad | 2009-08-10 20:46:15 +0000 | [diff] [blame] | 110 | AddPromotedToType (ISD::AND, VT.getSimpleVT(), |
| 111 | PromotedBitwiseVT.getSimpleVT()); |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 112 | setOperationAction(ISD::OR, VT.getSimpleVT(), Promote); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 113 | AddPromotedToType (ISD::OR, VT.getSimpleVT(), |
Owen Anderson | d6662ad | 2009-08-10 20:46:15 +0000 | [diff] [blame] | 114 | PromotedBitwiseVT.getSimpleVT()); |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 115 | setOperationAction(ISD::XOR, VT.getSimpleVT(), Promote); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 116 | AddPromotedToType (ISD::XOR, VT.getSimpleVT(), |
Owen Anderson | d6662ad | 2009-08-10 20:46:15 +0000 | [diff] [blame] | 117 | PromotedBitwiseVT.getSimpleVT()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 118 | } |
Bob Wilson | 1633076 | 2009-09-16 00:17:28 +0000 | [diff] [blame] | 119 | |
| 120 | // Neon does not support vector divide/remainder operations. |
| 121 | setOperationAction(ISD::SDIV, VT.getSimpleVT(), Expand); |
| 122 | setOperationAction(ISD::UDIV, VT.getSimpleVT(), Expand); |
| 123 | setOperationAction(ISD::FDIV, VT.getSimpleVT(), Expand); |
| 124 | setOperationAction(ISD::SREM, VT.getSimpleVT(), Expand); |
| 125 | setOperationAction(ISD::UREM, VT.getSimpleVT(), Expand); |
| 126 | setOperationAction(ISD::FREM, VT.getSimpleVT(), Expand); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 127 | } |
| 128 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 129 | void ARMTargetLowering::addDRTypeForNEON(EVT VT) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 130 | addRegisterClass(VT, ARM::DPRRegisterClass); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 131 | addTypeForNEON(VT, MVT::f64, MVT::v2i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 132 | } |
| 133 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 134 | void ARMTargetLowering::addQRTypeForNEON(EVT VT) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 135 | addRegisterClass(VT, ARM::QPRRegisterClass); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 136 | addTypeForNEON(VT, MVT::v2f64, MVT::v4i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 137 | } |
| 138 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 139 | static TargetLoweringObjectFile *createTLOF(TargetMachine &TM) { |
| 140 | if (TM.getSubtarget<ARMSubtarget>().isTargetDarwin()) |
Bill Wendling | 505ad8b | 2010-03-15 21:09:38 +0000 | [diff] [blame] | 141 | return new TargetLoweringObjectFileMachO(); |
Bill Wendling | 94a1c63 | 2010-03-09 02:46:12 +0000 | [diff] [blame] | 142 | |
Chris Lattner | 80ec279 | 2009-08-02 00:34:36 +0000 | [diff] [blame] | 143 | return new ARMElfTargetObjectFile(); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 144 | } |
| 145 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 146 | ARMTargetLowering::ARMTargetLowering(TargetMachine &TM) |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 147 | : TargetLowering(TM, createTLOF(TM)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 148 | Subtarget = &TM.getSubtarget<ARMSubtarget>(); |
| 149 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 150 | if (Subtarget->isTargetDarwin()) { |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 151 | // Uses VFP for Thumb libfuncs if available. |
| 152 | if (Subtarget->isThumb() && Subtarget->hasVFP2()) { |
| 153 | // Single-precision floating-point arithmetic. |
| 154 | setLibcallName(RTLIB::ADD_F32, "__addsf3vfp"); |
| 155 | setLibcallName(RTLIB::SUB_F32, "__subsf3vfp"); |
| 156 | setLibcallName(RTLIB::MUL_F32, "__mulsf3vfp"); |
| 157 | setLibcallName(RTLIB::DIV_F32, "__divsf3vfp"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 158 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 159 | // Double-precision floating-point arithmetic. |
| 160 | setLibcallName(RTLIB::ADD_F64, "__adddf3vfp"); |
| 161 | setLibcallName(RTLIB::SUB_F64, "__subdf3vfp"); |
| 162 | setLibcallName(RTLIB::MUL_F64, "__muldf3vfp"); |
| 163 | setLibcallName(RTLIB::DIV_F64, "__divdf3vfp"); |
Evan Cheng | 193f850 | 2007-01-31 09:30:58 +0000 | [diff] [blame] | 164 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 165 | // Single-precision comparisons. |
| 166 | setLibcallName(RTLIB::OEQ_F32, "__eqsf2vfp"); |
| 167 | setLibcallName(RTLIB::UNE_F32, "__nesf2vfp"); |
| 168 | setLibcallName(RTLIB::OLT_F32, "__ltsf2vfp"); |
| 169 | setLibcallName(RTLIB::OLE_F32, "__lesf2vfp"); |
| 170 | setLibcallName(RTLIB::OGE_F32, "__gesf2vfp"); |
| 171 | setLibcallName(RTLIB::OGT_F32, "__gtsf2vfp"); |
| 172 | setLibcallName(RTLIB::UO_F32, "__unordsf2vfp"); |
| 173 | setLibcallName(RTLIB::O_F32, "__unordsf2vfp"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 174 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 175 | setCmpLibcallCC(RTLIB::OEQ_F32, ISD::SETNE); |
| 176 | setCmpLibcallCC(RTLIB::UNE_F32, ISD::SETNE); |
| 177 | setCmpLibcallCC(RTLIB::OLT_F32, ISD::SETNE); |
| 178 | setCmpLibcallCC(RTLIB::OLE_F32, ISD::SETNE); |
| 179 | setCmpLibcallCC(RTLIB::OGE_F32, ISD::SETNE); |
| 180 | setCmpLibcallCC(RTLIB::OGT_F32, ISD::SETNE); |
| 181 | setCmpLibcallCC(RTLIB::UO_F32, ISD::SETNE); |
| 182 | setCmpLibcallCC(RTLIB::O_F32, ISD::SETEQ); |
Evan Cheng | 193f850 | 2007-01-31 09:30:58 +0000 | [diff] [blame] | 183 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 184 | // Double-precision comparisons. |
| 185 | setLibcallName(RTLIB::OEQ_F64, "__eqdf2vfp"); |
| 186 | setLibcallName(RTLIB::UNE_F64, "__nedf2vfp"); |
| 187 | setLibcallName(RTLIB::OLT_F64, "__ltdf2vfp"); |
| 188 | setLibcallName(RTLIB::OLE_F64, "__ledf2vfp"); |
| 189 | setLibcallName(RTLIB::OGE_F64, "__gedf2vfp"); |
| 190 | setLibcallName(RTLIB::OGT_F64, "__gtdf2vfp"); |
| 191 | setLibcallName(RTLIB::UO_F64, "__unorddf2vfp"); |
| 192 | setLibcallName(RTLIB::O_F64, "__unorddf2vfp"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 193 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 194 | setCmpLibcallCC(RTLIB::OEQ_F64, ISD::SETNE); |
| 195 | setCmpLibcallCC(RTLIB::UNE_F64, ISD::SETNE); |
| 196 | setCmpLibcallCC(RTLIB::OLT_F64, ISD::SETNE); |
| 197 | setCmpLibcallCC(RTLIB::OLE_F64, ISD::SETNE); |
| 198 | setCmpLibcallCC(RTLIB::OGE_F64, ISD::SETNE); |
| 199 | setCmpLibcallCC(RTLIB::OGT_F64, ISD::SETNE); |
| 200 | setCmpLibcallCC(RTLIB::UO_F64, ISD::SETNE); |
| 201 | setCmpLibcallCC(RTLIB::O_F64, ISD::SETEQ); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 202 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 203 | // Floating-point to integer conversions. |
| 204 | // i64 conversions are done via library routines even when generating VFP |
| 205 | // instructions, so use the same ones. |
| 206 | setLibcallName(RTLIB::FPTOSINT_F64_I32, "__fixdfsivfp"); |
| 207 | setLibcallName(RTLIB::FPTOUINT_F64_I32, "__fixunsdfsivfp"); |
| 208 | setLibcallName(RTLIB::FPTOSINT_F32_I32, "__fixsfsivfp"); |
| 209 | setLibcallName(RTLIB::FPTOUINT_F32_I32, "__fixunssfsivfp"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 210 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 211 | // Conversions between floating types. |
| 212 | setLibcallName(RTLIB::FPROUND_F64_F32, "__truncdfsf2vfp"); |
| 213 | setLibcallName(RTLIB::FPEXT_F32_F64, "__extendsfdf2vfp"); |
| 214 | |
| 215 | // Integer to floating-point conversions. |
| 216 | // i64 conversions are done via library routines even when generating VFP |
| 217 | // instructions, so use the same ones. |
Bob Wilson | 2a14c52 | 2009-03-20 23:16:43 +0000 | [diff] [blame] | 218 | // FIXME: There appears to be some naming inconsistency in ARM libgcc: |
| 219 | // e.g., __floatunsidf vs. __floatunssidfvfp. |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 220 | setLibcallName(RTLIB::SINTTOFP_I32_F64, "__floatsidfvfp"); |
| 221 | setLibcallName(RTLIB::UINTTOFP_I32_F64, "__floatunssidfvfp"); |
| 222 | setLibcallName(RTLIB::SINTTOFP_I32_F32, "__floatsisfvfp"); |
| 223 | setLibcallName(RTLIB::UINTTOFP_I32_F32, "__floatunssisfvfp"); |
| 224 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 225 | } |
| 226 | |
Bob Wilson | 2f95461 | 2009-05-22 17:38:41 +0000 | [diff] [blame] | 227 | // These libcalls are not available in 32-bit. |
| 228 | setLibcallName(RTLIB::SHL_I128, 0); |
| 229 | setLibcallName(RTLIB::SRL_I128, 0); |
| 230 | setLibcallName(RTLIB::SRA_I128, 0); |
| 231 | |
Anton Korobeynikov | 72977a4 | 2009-08-14 20:10:52 +0000 | [diff] [blame] | 232 | // Libcalls should use the AAPCS base standard ABI, even if hard float |
| 233 | // is in effect, as per the ARM RTABI specification, section 4.1.2. |
| 234 | if (Subtarget->isAAPCS_ABI()) { |
| 235 | for (int i = 0; i < RTLIB::UNKNOWN_LIBCALL; ++i) { |
| 236 | setLibcallCallingConv(static_cast<RTLIB::Libcall>(i), |
| 237 | CallingConv::ARM_AAPCS); |
| 238 | } |
| 239 | } |
| 240 | |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 241 | if (Subtarget->isThumb1Only()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 242 | addRegisterClass(MVT::i32, ARM::tGPRRegisterClass); |
Jim Grosbach | 30eae3c | 2009-04-07 20:34:09 +0000 | [diff] [blame] | 243 | else |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 244 | addRegisterClass(MVT::i32, ARM::GPRRegisterClass); |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 245 | if (!UseSoftFloat && Subtarget->hasVFP2() && !Subtarget->isThumb1Only()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 246 | addRegisterClass(MVT::f32, ARM::SPRRegisterClass); |
| 247 | addRegisterClass(MVT::f64, ARM::DPRRegisterClass); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 248 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 249 | setTruncStoreAction(MVT::f64, MVT::f32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 250 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 251 | |
| 252 | if (Subtarget->hasNEON()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 253 | addDRTypeForNEON(MVT::v2f32); |
| 254 | addDRTypeForNEON(MVT::v8i8); |
| 255 | addDRTypeForNEON(MVT::v4i16); |
| 256 | addDRTypeForNEON(MVT::v2i32); |
| 257 | addDRTypeForNEON(MVT::v1i64); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 258 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 259 | addQRTypeForNEON(MVT::v4f32); |
| 260 | addQRTypeForNEON(MVT::v2f64); |
| 261 | addQRTypeForNEON(MVT::v16i8); |
| 262 | addQRTypeForNEON(MVT::v8i16); |
| 263 | addQRTypeForNEON(MVT::v4i32); |
| 264 | addQRTypeForNEON(MVT::v2i64); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 265 | |
Bob Wilson | 74dc72e | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 266 | // v2f64 is legal so that QR subregs can be extracted as f64 elements, but |
| 267 | // neither Neon nor VFP support any arithmetic operations on it. |
| 268 | setOperationAction(ISD::FADD, MVT::v2f64, Expand); |
| 269 | setOperationAction(ISD::FSUB, MVT::v2f64, Expand); |
| 270 | setOperationAction(ISD::FMUL, MVT::v2f64, Expand); |
| 271 | setOperationAction(ISD::FDIV, MVT::v2f64, Expand); |
| 272 | setOperationAction(ISD::FREM, MVT::v2f64, Expand); |
| 273 | setOperationAction(ISD::FCOPYSIGN, MVT::v2f64, Expand); |
| 274 | setOperationAction(ISD::VSETCC, MVT::v2f64, Expand); |
| 275 | setOperationAction(ISD::FNEG, MVT::v2f64, Expand); |
| 276 | setOperationAction(ISD::FABS, MVT::v2f64, Expand); |
| 277 | setOperationAction(ISD::FSQRT, MVT::v2f64, Expand); |
| 278 | setOperationAction(ISD::FSIN, MVT::v2f64, Expand); |
| 279 | setOperationAction(ISD::FCOS, MVT::v2f64, Expand); |
| 280 | setOperationAction(ISD::FPOWI, MVT::v2f64, Expand); |
| 281 | setOperationAction(ISD::FPOW, MVT::v2f64, Expand); |
| 282 | setOperationAction(ISD::FLOG, MVT::v2f64, Expand); |
| 283 | setOperationAction(ISD::FLOG2, MVT::v2f64, Expand); |
| 284 | setOperationAction(ISD::FLOG10, MVT::v2f64, Expand); |
| 285 | setOperationAction(ISD::FEXP, MVT::v2f64, Expand); |
| 286 | setOperationAction(ISD::FEXP2, MVT::v2f64, Expand); |
| 287 | setOperationAction(ISD::FCEIL, MVT::v2f64, Expand); |
| 288 | setOperationAction(ISD::FTRUNC, MVT::v2f64, Expand); |
| 289 | setOperationAction(ISD::FRINT, MVT::v2f64, Expand); |
| 290 | setOperationAction(ISD::FNEARBYINT, MVT::v2f64, Expand); |
| 291 | setOperationAction(ISD::FFLOOR, MVT::v2f64, Expand); |
| 292 | |
Bob Wilson | 642b329 | 2009-09-16 00:32:15 +0000 | [diff] [blame] | 293 | // Neon does not support some operations on v1i64 and v2i64 types. |
| 294 | setOperationAction(ISD::MUL, MVT::v1i64, Expand); |
| 295 | setOperationAction(ISD::MUL, MVT::v2i64, Expand); |
| 296 | setOperationAction(ISD::VSETCC, MVT::v1i64, Expand); |
| 297 | setOperationAction(ISD::VSETCC, MVT::v2i64, Expand); |
| 298 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 299 | setTargetDAGCombine(ISD::INTRINSIC_WO_CHAIN); |
| 300 | setTargetDAGCombine(ISD::SHL); |
| 301 | setTargetDAGCombine(ISD::SRL); |
| 302 | setTargetDAGCombine(ISD::SRA); |
| 303 | setTargetDAGCombine(ISD::SIGN_EXTEND); |
| 304 | setTargetDAGCombine(ISD::ZERO_EXTEND); |
| 305 | setTargetDAGCombine(ISD::ANY_EXTEND); |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 306 | setTargetDAGCombine(ISD::SELECT_CC); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 307 | } |
| 308 | |
Evan Cheng | 9f8cbd1 | 2007-05-18 00:19:34 +0000 | [diff] [blame] | 309 | computeRegisterProperties(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 310 | |
| 311 | // ARM does not have f32 extending load. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 312 | setLoadExtAction(ISD::EXTLOAD, MVT::f32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 313 | |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 314 | // ARM does not have i1 sign extending load. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 315 | setLoadExtAction(ISD::SEXTLOAD, MVT::i1, Promote); |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 316 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 317 | // ARM supports all 4 flavors of integer indexed load / store. |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 318 | if (!Subtarget->isThumb1Only()) { |
| 319 | for (unsigned im = (unsigned)ISD::PRE_INC; |
| 320 | im != (unsigned)ISD::LAST_INDEXED_MODE; ++im) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 321 | setIndexedLoadAction(im, MVT::i1, Legal); |
| 322 | setIndexedLoadAction(im, MVT::i8, Legal); |
| 323 | setIndexedLoadAction(im, MVT::i16, Legal); |
| 324 | setIndexedLoadAction(im, MVT::i32, Legal); |
| 325 | setIndexedStoreAction(im, MVT::i1, Legal); |
| 326 | setIndexedStoreAction(im, MVT::i8, Legal); |
| 327 | setIndexedStoreAction(im, MVT::i16, Legal); |
| 328 | setIndexedStoreAction(im, MVT::i32, Legal); |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 329 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | // i64 operation support. |
Evan Cheng | 5b9fcd1 | 2009-07-07 01:17:28 +0000 | [diff] [blame] | 333 | if (Subtarget->isThumb1Only()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 334 | setOperationAction(ISD::MUL, MVT::i64, Expand); |
| 335 | setOperationAction(ISD::MULHU, MVT::i32, Expand); |
| 336 | setOperationAction(ISD::MULHS, MVT::i32, Expand); |
| 337 | setOperationAction(ISD::UMUL_LOHI, MVT::i32, Expand); |
| 338 | setOperationAction(ISD::SMUL_LOHI, MVT::i32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 339 | } else { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 340 | setOperationAction(ISD::MUL, MVT::i64, Expand); |
| 341 | setOperationAction(ISD::MULHU, MVT::i32, Expand); |
Evan Cheng | b620724 | 2009-08-01 00:16:10 +0000 | [diff] [blame] | 342 | if (!Subtarget->hasV6Ops()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 343 | setOperationAction(ISD::MULHS, MVT::i32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 344 | } |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 345 | setOperationAction(ISD::SHL_PARTS, MVT::i32, Custom); |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 346 | setOperationAction(ISD::SRA_PARTS, MVT::i32, Custom); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 347 | setOperationAction(ISD::SRL_PARTS, MVT::i32, Custom); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 348 | setOperationAction(ISD::SRL, MVT::i64, Custom); |
| 349 | setOperationAction(ISD::SRA, MVT::i64, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 350 | |
| 351 | // ARM does not have ROTL. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 352 | setOperationAction(ISD::ROTL, MVT::i32, Expand); |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 353 | setOperationAction(ISD::CTTZ, MVT::i32, Custom); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 354 | setOperationAction(ISD::CTPOP, MVT::i32, Expand); |
David Goodwin | 24062ac | 2009-06-26 20:47:43 +0000 | [diff] [blame] | 355 | if (!Subtarget->hasV5TOps() || Subtarget->isThumb1Only()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 356 | setOperationAction(ISD::CTLZ, MVT::i32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 357 | |
Lauro Ramos Venancio | 368f20f | 2007-03-16 22:54:16 +0000 | [diff] [blame] | 358 | // Only ARMv6 has BSWAP. |
| 359 | if (!Subtarget->hasV6Ops()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 360 | setOperationAction(ISD::BSWAP, MVT::i32, Expand); |
Lauro Ramos Venancio | 368f20f | 2007-03-16 22:54:16 +0000 | [diff] [blame] | 361 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 362 | // These are expanded into libcalls. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 363 | setOperationAction(ISD::SDIV, MVT::i32, Expand); |
| 364 | setOperationAction(ISD::UDIV, MVT::i32, Expand); |
| 365 | setOperationAction(ISD::SREM, MVT::i32, Expand); |
| 366 | setOperationAction(ISD::UREM, MVT::i32, Expand); |
| 367 | setOperationAction(ISD::SDIVREM, MVT::i32, Expand); |
| 368 | setOperationAction(ISD::UDIVREM, MVT::i32, Expand); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 369 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 370 | setOperationAction(ISD::GlobalAddress, MVT::i32, Custom); |
| 371 | setOperationAction(ISD::ConstantPool, MVT::i32, Custom); |
| 372 | setOperationAction(ISD::GLOBAL_OFFSET_TABLE, MVT::i32, Custom); |
| 373 | setOperationAction(ISD::GlobalTLSAddress, MVT::i32, Custom); |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 374 | setOperationAction(ISD::BlockAddress, MVT::i32, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 375 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 376 | // Use the default implementation. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 377 | setOperationAction(ISD::VASTART, MVT::Other, Custom); |
| 378 | setOperationAction(ISD::VAARG, MVT::Other, Expand); |
| 379 | setOperationAction(ISD::VACOPY, MVT::Other, Expand); |
| 380 | setOperationAction(ISD::VAEND, MVT::Other, Expand); |
| 381 | setOperationAction(ISD::STACKSAVE, MVT::Other, Expand); |
| 382 | setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand); |
Jim Grosbach | bff3923 | 2009-08-12 17:38:44 +0000 | [diff] [blame] | 383 | setOperationAction(ISD::EHSELECTION, MVT::i32, Expand); |
| 384 | // FIXME: Shouldn't need this, since no register is used, but the legalizer |
| 385 | // doesn't yet know how to not do that for SjLj. |
| 386 | setExceptionSelectorRegister(ARM::R0); |
Evan Cheng | 3a1588a | 2010-04-15 22:20:34 +0000 | [diff] [blame] | 387 | setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32, Expand); |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 388 | setOperationAction(ISD::MEMBARRIER, MVT::Other, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 389 | |
Evan Cheng | d27c9fc | 2009-07-03 01:43:10 +0000 | [diff] [blame] | 390 | if (!Subtarget->hasV6Ops() && !Subtarget->isThumb2()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 391 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i16, Expand); |
| 392 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i8, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 393 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 394 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 395 | |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 396 | if (!UseSoftFloat && Subtarget->hasVFP2() && !Subtarget->isThumb1Only()) |
Bob Wilson | cb9a6aa | 2010-01-19 22:56:26 +0000 | [diff] [blame] | 397 | // Turn f64->i64 into VMOVRRD, i64 -> f64 to VMOVDRR |
| 398 | // iff target supports vfp2. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 399 | setOperationAction(ISD::BIT_CONVERT, MVT::i64, Custom); |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 400 | |
| 401 | // We want to custom lower some of our intrinsics. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 402 | setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom); |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 403 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 404 | setOperationAction(ISD::SETCC, MVT::i32, Expand); |
| 405 | setOperationAction(ISD::SETCC, MVT::f32, Expand); |
| 406 | setOperationAction(ISD::SETCC, MVT::f64, Expand); |
| 407 | setOperationAction(ISD::SELECT, MVT::i32, Expand); |
| 408 | setOperationAction(ISD::SELECT, MVT::f32, Expand); |
| 409 | setOperationAction(ISD::SELECT, MVT::f64, Expand); |
| 410 | setOperationAction(ISD::SELECT_CC, MVT::i32, Custom); |
| 411 | setOperationAction(ISD::SELECT_CC, MVT::f32, Custom); |
| 412 | setOperationAction(ISD::SELECT_CC, MVT::f64, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 413 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 414 | setOperationAction(ISD::BRCOND, MVT::Other, Expand); |
| 415 | setOperationAction(ISD::BR_CC, MVT::i32, Custom); |
| 416 | setOperationAction(ISD::BR_CC, MVT::f32, Custom); |
| 417 | setOperationAction(ISD::BR_CC, MVT::f64, Custom); |
| 418 | setOperationAction(ISD::BR_JT, MVT::Other, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 419 | |
Dan Gohman | f96e4de | 2007-10-11 23:21:31 +0000 | [diff] [blame] | 420 | // We don't support sin/cos/fmod/copysign/pow |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 421 | setOperationAction(ISD::FSIN, MVT::f64, Expand); |
| 422 | setOperationAction(ISD::FSIN, MVT::f32, Expand); |
| 423 | setOperationAction(ISD::FCOS, MVT::f32, Expand); |
| 424 | setOperationAction(ISD::FCOS, MVT::f64, Expand); |
| 425 | setOperationAction(ISD::FREM, MVT::f64, Expand); |
| 426 | setOperationAction(ISD::FREM, MVT::f32, Expand); |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 427 | if (!UseSoftFloat && Subtarget->hasVFP2() && !Subtarget->isThumb1Only()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 428 | setOperationAction(ISD::FCOPYSIGN, MVT::f64, Custom); |
| 429 | setOperationAction(ISD::FCOPYSIGN, MVT::f32, Custom); |
Evan Cheng | 110cf48 | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 430 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 431 | setOperationAction(ISD::FPOW, MVT::f64, Expand); |
| 432 | setOperationAction(ISD::FPOW, MVT::f32, Expand); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 433 | |
Anton Korobeynikov | bec3dd2 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 434 | // Various VFP goodness |
| 435 | if (!UseSoftFloat && !Subtarget->isThumb1Only()) { |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 436 | // int <-> fp are custom expanded into bit_convert + ARMISD ops. |
| 437 | if (Subtarget->hasVFP2()) { |
| 438 | setOperationAction(ISD::SINT_TO_FP, MVT::i32, Custom); |
| 439 | setOperationAction(ISD::UINT_TO_FP, MVT::i32, Custom); |
| 440 | setOperationAction(ISD::FP_TO_UINT, MVT::i32, Custom); |
| 441 | setOperationAction(ISD::FP_TO_SINT, MVT::i32, Custom); |
| 442 | } |
Anton Korobeynikov | bec3dd2 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 443 | // Special handling for half-precision FP. |
Anton Korobeynikov | f0d5007 | 2010-03-18 22:35:37 +0000 | [diff] [blame] | 444 | if (!Subtarget->hasFP16()) { |
| 445 | setOperationAction(ISD::FP16_TO_FP32, MVT::f32, Expand); |
| 446 | setOperationAction(ISD::FP32_TO_FP16, MVT::i32, Expand); |
Anton Korobeynikov | bec3dd2 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 447 | } |
Evan Cheng | 110cf48 | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 448 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 449 | |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 450 | // We have target-specific dag combine patterns for the following nodes: |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 451 | // ARMISD::VMOVRRD - No need to call setTargetDAGCombine |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 452 | setTargetDAGCombine(ISD::ADD); |
| 453 | setTargetDAGCombine(ISD::SUB); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 454 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 455 | setStackPointerRegisterToSaveRestore(ARM::SP); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 456 | setSchedulingPreference(SchedulingForRegPressure); |
Dale Johannesen | 8dd86c1 | 2007-05-17 21:31:21 +0000 | [diff] [blame] | 457 | |
Evan Cheng | bc9b754 | 2009-08-15 07:59:10 +0000 | [diff] [blame] | 458 | // FIXME: If-converter should use instruction latency to determine |
| 459 | // profitability rather than relying on fixed limits. |
| 460 | if (Subtarget->getCPUString() == "generic") { |
| 461 | // Generic (and overly aggressive) if-conversion limits. |
| 462 | setIfCvtBlockSizeLimit(10); |
| 463 | setIfCvtDupBlockSizeLimit(2); |
Jim Grosbach | 35075a7 | 2010-03-24 16:15:14 +0000 | [diff] [blame] | 464 | } else if (Subtarget->hasV7Ops()) { |
Jim Grosbach | fceabef | 2010-03-24 00:03:13 +0000 | [diff] [blame] | 465 | setIfCvtBlockSizeLimit(3); |
| 466 | setIfCvtDupBlockSizeLimit(1); |
Evan Cheng | bc9b754 | 2009-08-15 07:59:10 +0000 | [diff] [blame] | 467 | } else if (Subtarget->hasV6Ops()) { |
| 468 | setIfCvtBlockSizeLimit(2); |
| 469 | setIfCvtDupBlockSizeLimit(1); |
| 470 | } else { |
| 471 | setIfCvtBlockSizeLimit(3); |
| 472 | setIfCvtDupBlockSizeLimit(2); |
Evan Cheng | 8557c2b | 2009-06-19 01:51:50 +0000 | [diff] [blame] | 473 | } |
| 474 | |
Dale Johannesen | 8dd86c1 | 2007-05-17 21:31:21 +0000 | [diff] [blame] | 475 | maxStoresPerMemcpy = 1; //// temporary - rewrite interface to use type |
Bob Wilson | e6abdff | 2009-05-18 20:55:32 +0000 | [diff] [blame] | 476 | // Do not enable CodePlacementOpt for now: it currently runs after the |
| 477 | // ARMConstantIslandPass and messes up branch relaxation and placement |
| 478 | // of constant islands. |
| 479 | // benefitFromCodePlacementOpt = true; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 480 | } |
| 481 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 482 | const char *ARMTargetLowering::getTargetNodeName(unsigned Opcode) const { |
| 483 | switch (Opcode) { |
| 484 | default: return 0; |
| 485 | case ARMISD::Wrapper: return "ARMISD::Wrapper"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 486 | case ARMISD::WrapperJT: return "ARMISD::WrapperJT"; |
| 487 | case ARMISD::CALL: return "ARMISD::CALL"; |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 488 | case ARMISD::CALL_PRED: return "ARMISD::CALL_PRED"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 489 | case ARMISD::CALL_NOLINK: return "ARMISD::CALL_NOLINK"; |
| 490 | case ARMISD::tCALL: return "ARMISD::tCALL"; |
| 491 | case ARMISD::BRCOND: return "ARMISD::BRCOND"; |
| 492 | case ARMISD::BR_JT: return "ARMISD::BR_JT"; |
Evan Cheng | 5657c01 | 2009-07-29 02:18:14 +0000 | [diff] [blame] | 493 | case ARMISD::BR2_JT: return "ARMISD::BR2_JT"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 494 | case ARMISD::RET_FLAG: return "ARMISD::RET_FLAG"; |
| 495 | case ARMISD::PIC_ADD: return "ARMISD::PIC_ADD"; |
| 496 | case ARMISD::CMP: return "ARMISD::CMP"; |
David Goodwin | c0309b4 | 2009-06-29 15:33:01 +0000 | [diff] [blame] | 497 | case ARMISD::CMPZ: return "ARMISD::CMPZ"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 498 | case ARMISD::CMPFP: return "ARMISD::CMPFP"; |
| 499 | case ARMISD::CMPFPw0: return "ARMISD::CMPFPw0"; |
| 500 | case ARMISD::FMSTAT: return "ARMISD::FMSTAT"; |
| 501 | case ARMISD::CMOV: return "ARMISD::CMOV"; |
| 502 | case ARMISD::CNEG: return "ARMISD::CNEG"; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 503 | |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 504 | case ARMISD::RBIT: return "ARMISD::RBIT"; |
| 505 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 506 | case ARMISD::FTOSI: return "ARMISD::FTOSI"; |
| 507 | case ARMISD::FTOUI: return "ARMISD::FTOUI"; |
| 508 | case ARMISD::SITOF: return "ARMISD::SITOF"; |
| 509 | case ARMISD::UITOF: return "ARMISD::UITOF"; |
| 510 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 511 | case ARMISD::SRL_FLAG: return "ARMISD::SRL_FLAG"; |
| 512 | case ARMISD::SRA_FLAG: return "ARMISD::SRA_FLAG"; |
| 513 | case ARMISD::RRX: return "ARMISD::RRX"; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 514 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 515 | case ARMISD::VMOVRRD: return "ARMISD::VMOVRRD"; |
| 516 | case ARMISD::VMOVDRR: return "ARMISD::VMOVDRR"; |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 517 | |
Evan Cheng | c594208 | 2009-10-28 06:55:03 +0000 | [diff] [blame] | 518 | case ARMISD::EH_SJLJ_SETJMP: return "ARMISD::EH_SJLJ_SETJMP"; |
| 519 | case ARMISD::EH_SJLJ_LONGJMP:return "ARMISD::EH_SJLJ_LONGJMP"; |
| 520 | |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 521 | case ARMISD::THREAD_POINTER:return "ARMISD::THREAD_POINTER"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 522 | |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 523 | case ARMISD::DYN_ALLOC: return "ARMISD::DYN_ALLOC"; |
| 524 | |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 525 | case ARMISD::MEMBARRIER: return "ARMISD::MEMBARRIER"; |
| 526 | case ARMISD::SYNCBARRIER: return "ARMISD::SYNCBARRIER"; |
| 527 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 528 | case ARMISD::VCEQ: return "ARMISD::VCEQ"; |
| 529 | case ARMISD::VCGE: return "ARMISD::VCGE"; |
| 530 | case ARMISD::VCGEU: return "ARMISD::VCGEU"; |
| 531 | case ARMISD::VCGT: return "ARMISD::VCGT"; |
| 532 | case ARMISD::VCGTU: return "ARMISD::VCGTU"; |
| 533 | case ARMISD::VTST: return "ARMISD::VTST"; |
| 534 | |
| 535 | case ARMISD::VSHL: return "ARMISD::VSHL"; |
| 536 | case ARMISD::VSHRs: return "ARMISD::VSHRs"; |
| 537 | case ARMISD::VSHRu: return "ARMISD::VSHRu"; |
| 538 | case ARMISD::VSHLLs: return "ARMISD::VSHLLs"; |
| 539 | case ARMISD::VSHLLu: return "ARMISD::VSHLLu"; |
| 540 | case ARMISD::VSHLLi: return "ARMISD::VSHLLi"; |
| 541 | case ARMISD::VSHRN: return "ARMISD::VSHRN"; |
| 542 | case ARMISD::VRSHRs: return "ARMISD::VRSHRs"; |
| 543 | case ARMISD::VRSHRu: return "ARMISD::VRSHRu"; |
| 544 | case ARMISD::VRSHRN: return "ARMISD::VRSHRN"; |
| 545 | case ARMISD::VQSHLs: return "ARMISD::VQSHLs"; |
| 546 | case ARMISD::VQSHLu: return "ARMISD::VQSHLu"; |
| 547 | case ARMISD::VQSHLsu: return "ARMISD::VQSHLsu"; |
| 548 | case ARMISD::VQSHRNs: return "ARMISD::VQSHRNs"; |
| 549 | case ARMISD::VQSHRNu: return "ARMISD::VQSHRNu"; |
| 550 | case ARMISD::VQSHRNsu: return "ARMISD::VQSHRNsu"; |
| 551 | case ARMISD::VQRSHRNs: return "ARMISD::VQRSHRNs"; |
| 552 | case ARMISD::VQRSHRNu: return "ARMISD::VQRSHRNu"; |
| 553 | case ARMISD::VQRSHRNsu: return "ARMISD::VQRSHRNsu"; |
| 554 | case ARMISD::VGETLANEu: return "ARMISD::VGETLANEu"; |
| 555 | case ARMISD::VGETLANEs: return "ARMISD::VGETLANEs"; |
Bob Wilson | c1d287b | 2009-08-14 05:13:08 +0000 | [diff] [blame] | 556 | case ARMISD::VDUP: return "ARMISD::VDUP"; |
Bob Wilson | 0ce3710 | 2009-08-14 05:08:32 +0000 | [diff] [blame] | 557 | case ARMISD::VDUPLANE: return "ARMISD::VDUPLANE"; |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 558 | case ARMISD::VEXT: return "ARMISD::VEXT"; |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 559 | case ARMISD::VREV64: return "ARMISD::VREV64"; |
| 560 | case ARMISD::VREV32: return "ARMISD::VREV32"; |
| 561 | case ARMISD::VREV16: return "ARMISD::VREV16"; |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 562 | case ARMISD::VZIP: return "ARMISD::VZIP"; |
| 563 | case ARMISD::VUZP: return "ARMISD::VUZP"; |
| 564 | case ARMISD::VTRN: return "ARMISD::VTRN"; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 565 | case ARMISD::FMAX: return "ARMISD::FMAX"; |
| 566 | case ARMISD::FMIN: return "ARMISD::FMIN"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 567 | } |
| 568 | } |
| 569 | |
Bill Wendling | b4202b8 | 2009-07-01 18:50:55 +0000 | [diff] [blame] | 570 | /// getFunctionAlignment - Return the Log2 alignment of this function. |
Bill Wendling | 20c568f | 2009-06-30 22:38:32 +0000 | [diff] [blame] | 571 | unsigned ARMTargetLowering::getFunctionAlignment(const Function *F) const { |
Evan Cheng | 048e36f | 2009-10-02 06:57:25 +0000 | [diff] [blame] | 572 | return getTargetMachine().getSubtarget<ARMSubtarget>().isThumb() ? 0 : 1; |
Bill Wendling | 20c568f | 2009-06-30 22:38:32 +0000 | [diff] [blame] | 573 | } |
| 574 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 575 | //===----------------------------------------------------------------------===// |
| 576 | // Lowering Code |
| 577 | //===----------------------------------------------------------------------===// |
| 578 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 579 | /// IntCCToARMCC - Convert a DAG integer condition code to an ARM CC |
| 580 | static ARMCC::CondCodes IntCCToARMCC(ISD::CondCode CC) { |
| 581 | switch (CC) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 582 | default: llvm_unreachable("Unknown condition code!"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 583 | case ISD::SETNE: return ARMCC::NE; |
| 584 | case ISD::SETEQ: return ARMCC::EQ; |
| 585 | case ISD::SETGT: return ARMCC::GT; |
| 586 | case ISD::SETGE: return ARMCC::GE; |
| 587 | case ISD::SETLT: return ARMCC::LT; |
| 588 | case ISD::SETLE: return ARMCC::LE; |
| 589 | case ISD::SETUGT: return ARMCC::HI; |
| 590 | case ISD::SETUGE: return ARMCC::HS; |
| 591 | case ISD::SETULT: return ARMCC::LO; |
| 592 | case ISD::SETULE: return ARMCC::LS; |
| 593 | } |
| 594 | } |
| 595 | |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 596 | /// FPCCToARMCC - Convert a DAG fp condition code to an ARM CC. |
| 597 | static void FPCCToARMCC(ISD::CondCode CC, ARMCC::CondCodes &CondCode, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 598 | ARMCC::CondCodes &CondCode2) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 599 | CondCode2 = ARMCC::AL; |
| 600 | switch (CC) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 601 | default: llvm_unreachable("Unknown FP condition!"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 602 | case ISD::SETEQ: |
| 603 | case ISD::SETOEQ: CondCode = ARMCC::EQ; break; |
| 604 | case ISD::SETGT: |
| 605 | case ISD::SETOGT: CondCode = ARMCC::GT; break; |
| 606 | case ISD::SETGE: |
| 607 | case ISD::SETOGE: CondCode = ARMCC::GE; break; |
| 608 | case ISD::SETOLT: CondCode = ARMCC::MI; break; |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 609 | case ISD::SETOLE: CondCode = ARMCC::LS; break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 610 | case ISD::SETONE: CondCode = ARMCC::MI; CondCode2 = ARMCC::GT; break; |
| 611 | case ISD::SETO: CondCode = ARMCC::VC; break; |
| 612 | case ISD::SETUO: CondCode = ARMCC::VS; break; |
| 613 | case ISD::SETUEQ: CondCode = ARMCC::EQ; CondCode2 = ARMCC::VS; break; |
| 614 | case ISD::SETUGT: CondCode = ARMCC::HI; break; |
| 615 | case ISD::SETUGE: CondCode = ARMCC::PL; break; |
| 616 | case ISD::SETLT: |
| 617 | case ISD::SETULT: CondCode = ARMCC::LT; break; |
| 618 | case ISD::SETLE: |
| 619 | case ISD::SETULE: CondCode = ARMCC::LE; break; |
| 620 | case ISD::SETNE: |
| 621 | case ISD::SETUNE: CondCode = ARMCC::NE; break; |
| 622 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 623 | } |
| 624 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 625 | //===----------------------------------------------------------------------===// |
| 626 | // Calling Convention Implementation |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 627 | //===----------------------------------------------------------------------===// |
| 628 | |
| 629 | #include "ARMGenCallingConv.inc" |
| 630 | |
| 631 | // APCS f64 is in register pairs, possibly split to stack |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 632 | static bool f64AssignAPCS(unsigned &ValNo, EVT &ValVT, EVT &LocVT, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 633 | CCValAssign::LocInfo &LocInfo, |
| 634 | CCState &State, bool CanFail) { |
| 635 | static const unsigned RegList[] = { ARM::R0, ARM::R1, ARM::R2, ARM::R3 }; |
| 636 | |
| 637 | // Try to get the first register. |
| 638 | if (unsigned Reg = State.AllocateReg(RegList, 4)) |
| 639 | State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo)); |
| 640 | else { |
| 641 | // For the 2nd half of a v2f64, do not fail. |
| 642 | if (CanFail) |
| 643 | return false; |
| 644 | |
| 645 | // Put the whole thing on the stack. |
| 646 | State.addLoc(CCValAssign::getCustomMem(ValNo, ValVT, |
| 647 | State.AllocateStack(8, 4), |
| 648 | LocVT, LocInfo)); |
| 649 | return true; |
| 650 | } |
| 651 | |
| 652 | // Try to get the second register. |
| 653 | if (unsigned Reg = State.AllocateReg(RegList, 4)) |
| 654 | State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo)); |
| 655 | else |
| 656 | State.addLoc(CCValAssign::getCustomMem(ValNo, ValVT, |
| 657 | State.AllocateStack(4, 4), |
| 658 | LocVT, LocInfo)); |
| 659 | return true; |
| 660 | } |
| 661 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 662 | static bool CC_ARM_APCS_Custom_f64(unsigned &ValNo, EVT &ValVT, EVT &LocVT, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 663 | CCValAssign::LocInfo &LocInfo, |
| 664 | ISD::ArgFlagsTy &ArgFlags, |
| 665 | CCState &State) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 666 | if (!f64AssignAPCS(ValNo, ValVT, LocVT, LocInfo, State, true)) |
| 667 | return false; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 668 | if (LocVT == MVT::v2f64 && |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 669 | !f64AssignAPCS(ValNo, ValVT, LocVT, LocInfo, State, false)) |
| 670 | return false; |
Bob Wilson | e65586b | 2009-04-17 20:40:45 +0000 | [diff] [blame] | 671 | return true; // we handled it |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | // AAPCS f64 is in aligned register pairs |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 675 | static bool f64AssignAAPCS(unsigned &ValNo, EVT &ValVT, EVT &LocVT, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 676 | CCValAssign::LocInfo &LocInfo, |
| 677 | CCState &State, bool CanFail) { |
| 678 | static const unsigned HiRegList[] = { ARM::R0, ARM::R2 }; |
| 679 | static const unsigned LoRegList[] = { ARM::R1, ARM::R3 }; |
| 680 | |
| 681 | unsigned Reg = State.AllocateReg(HiRegList, LoRegList, 2); |
| 682 | if (Reg == 0) { |
| 683 | // For the 2nd half of a v2f64, do not just fail. |
| 684 | if (CanFail) |
| 685 | return false; |
| 686 | |
| 687 | // Put the whole thing on the stack. |
| 688 | State.addLoc(CCValAssign::getCustomMem(ValNo, ValVT, |
| 689 | State.AllocateStack(8, 8), |
| 690 | LocVT, LocInfo)); |
| 691 | return true; |
| 692 | } |
| 693 | |
| 694 | unsigned i; |
| 695 | for (i = 0; i < 2; ++i) |
| 696 | if (HiRegList[i] == Reg) |
| 697 | break; |
| 698 | |
| 699 | State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo)); |
| 700 | State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, LoRegList[i], |
| 701 | LocVT, LocInfo)); |
| 702 | return true; |
| 703 | } |
| 704 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 705 | static bool CC_ARM_AAPCS_Custom_f64(unsigned &ValNo, EVT &ValVT, EVT &LocVT, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 706 | CCValAssign::LocInfo &LocInfo, |
| 707 | ISD::ArgFlagsTy &ArgFlags, |
| 708 | CCState &State) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 709 | if (!f64AssignAAPCS(ValNo, ValVT, LocVT, LocInfo, State, true)) |
| 710 | return false; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 711 | if (LocVT == MVT::v2f64 && |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 712 | !f64AssignAAPCS(ValNo, ValVT, LocVT, LocInfo, State, false)) |
| 713 | return false; |
| 714 | return true; // we handled it |
| 715 | } |
| 716 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 717 | static bool f64RetAssign(unsigned &ValNo, EVT &ValVT, EVT &LocVT, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 718 | CCValAssign::LocInfo &LocInfo, CCState &State) { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 719 | static const unsigned HiRegList[] = { ARM::R0, ARM::R2 }; |
| 720 | static const unsigned LoRegList[] = { ARM::R1, ARM::R3 }; |
| 721 | |
Bob Wilson | e65586b | 2009-04-17 20:40:45 +0000 | [diff] [blame] | 722 | unsigned Reg = State.AllocateReg(HiRegList, LoRegList, 2); |
| 723 | if (Reg == 0) |
| 724 | return false; // we didn't handle it |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 725 | |
Bob Wilson | e65586b | 2009-04-17 20:40:45 +0000 | [diff] [blame] | 726 | unsigned i; |
| 727 | for (i = 0; i < 2; ++i) |
| 728 | if (HiRegList[i] == Reg) |
| 729 | break; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 730 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 731 | State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo)); |
Bob Wilson | e65586b | 2009-04-17 20:40:45 +0000 | [diff] [blame] | 732 | State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, LoRegList[i], |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 733 | LocVT, LocInfo)); |
| 734 | return true; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 735 | } |
| 736 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 737 | static bool RetCC_ARM_APCS_Custom_f64(unsigned &ValNo, EVT &ValVT, EVT &LocVT, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 738 | CCValAssign::LocInfo &LocInfo, |
| 739 | ISD::ArgFlagsTy &ArgFlags, |
| 740 | CCState &State) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 741 | if (!f64RetAssign(ValNo, ValVT, LocVT, LocInfo, State)) |
| 742 | return false; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 743 | if (LocVT == MVT::v2f64 && !f64RetAssign(ValNo, ValVT, LocVT, LocInfo, State)) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 744 | return false; |
Bob Wilson | e65586b | 2009-04-17 20:40:45 +0000 | [diff] [blame] | 745 | return true; // we handled it |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 746 | } |
| 747 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 748 | static bool RetCC_ARM_AAPCS_Custom_f64(unsigned &ValNo, EVT &ValVT, EVT &LocVT, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 749 | CCValAssign::LocInfo &LocInfo, |
| 750 | ISD::ArgFlagsTy &ArgFlags, |
| 751 | CCState &State) { |
| 752 | return RetCC_ARM_APCS_Custom_f64(ValNo, ValVT, LocVT, LocInfo, ArgFlags, |
| 753 | State); |
| 754 | } |
| 755 | |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 756 | /// CCAssignFnForNode - Selects the correct CCAssignFn for a the |
| 757 | /// given CallingConvention value. |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 758 | CCAssignFn *ARMTargetLowering::CCAssignFnForNode(CallingConv::ID CC, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 759 | bool Return, |
| 760 | bool isVarArg) const { |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 761 | switch (CC) { |
| 762 | default: |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 763 | llvm_unreachable("Unsupported calling convention"); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 764 | case CallingConv::C: |
| 765 | case CallingConv::Fast: |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 766 | // Use target triple & subtarget features to do actual dispatch. |
| 767 | if (Subtarget->isAAPCS_ABI()) { |
| 768 | if (Subtarget->hasVFP2() && |
| 769 | FloatABIType == FloatABI::Hard && !isVarArg) |
| 770 | return (Return ? RetCC_ARM_AAPCS_VFP: CC_ARM_AAPCS_VFP); |
| 771 | else |
| 772 | return (Return ? RetCC_ARM_AAPCS: CC_ARM_AAPCS); |
| 773 | } else |
| 774 | return (Return ? RetCC_ARM_APCS: CC_ARM_APCS); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 775 | case CallingConv::ARM_AAPCS_VFP: |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 776 | return (Return ? RetCC_ARM_AAPCS_VFP: CC_ARM_AAPCS_VFP); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 777 | case CallingConv::ARM_AAPCS: |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 778 | return (Return ? RetCC_ARM_AAPCS: CC_ARM_AAPCS); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 779 | case CallingConv::ARM_APCS: |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 780 | return (Return ? RetCC_ARM_APCS: CC_ARM_APCS); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 781 | } |
| 782 | } |
| 783 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 784 | /// LowerCallResult - Lower the result values of a call into the |
| 785 | /// appropriate copies out of appropriate physical registers. |
| 786 | SDValue |
| 787 | ARMTargetLowering::LowerCallResult(SDValue Chain, SDValue InFlag, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 788 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 789 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 790 | DebugLoc dl, SelectionDAG &DAG, |
| 791 | SmallVectorImpl<SDValue> &InVals) { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 792 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 793 | // Assign locations to each value returned by this call. |
| 794 | SmallVector<CCValAssign, 16> RVLocs; |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 795 | CCState CCInfo(CallConv, isVarArg, getTargetMachine(), |
Owen Anderson | e922c02 | 2009-07-22 00:24:57 +0000 | [diff] [blame] | 796 | RVLocs, *DAG.getContext()); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 797 | CCInfo.AnalyzeCallResult(Ins, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 798 | CCAssignFnForNode(CallConv, /* Return*/ true, |
| 799 | isVarArg)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 800 | |
| 801 | // Copy all of the result registers out of their specified physreg. |
| 802 | for (unsigned i = 0; i != RVLocs.size(); ++i) { |
| 803 | CCValAssign VA = RVLocs[i]; |
| 804 | |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 805 | SDValue Val; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 806 | if (VA.needsCustom()) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 807 | // Handle f64 or half of a v2f64. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 808 | SDValue Lo = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 809 | InFlag); |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 810 | Chain = Lo.getValue(1); |
| 811 | InFlag = Lo.getValue(2); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 812 | VA = RVLocs[++i]; // skip ahead to next loc |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 813 | SDValue Hi = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 814 | InFlag); |
| 815 | Chain = Hi.getValue(1); |
| 816 | InFlag = Hi.getValue(2); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 817 | Val = DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 818 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 819 | if (VA.getLocVT() == MVT::v2f64) { |
| 820 | SDValue Vec = DAG.getNode(ISD::UNDEF, dl, MVT::v2f64); |
| 821 | Vec = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Vec, Val, |
| 822 | DAG.getConstant(0, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 823 | |
| 824 | VA = RVLocs[++i]; // skip ahead to next loc |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 825 | Lo = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, InFlag); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 826 | Chain = Lo.getValue(1); |
| 827 | InFlag = Lo.getValue(2); |
| 828 | VA = RVLocs[++i]; // skip ahead to next loc |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 829 | Hi = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, InFlag); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 830 | Chain = Hi.getValue(1); |
| 831 | InFlag = Hi.getValue(2); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 832 | Val = DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 833 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Vec, Val, |
| 834 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 835 | } |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 836 | } else { |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 837 | Val = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), VA.getLocVT(), |
| 838 | InFlag); |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 839 | Chain = Val.getValue(1); |
| 840 | InFlag = Val.getValue(2); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 841 | } |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 842 | |
| 843 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 844 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 845 | case CCValAssign::Full: break; |
| 846 | case CCValAssign::BCvt: |
| 847 | Val = DAG.getNode(ISD::BIT_CONVERT, dl, VA.getValVT(), Val); |
| 848 | break; |
| 849 | } |
| 850 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 851 | InVals.push_back(Val); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 852 | } |
| 853 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 854 | return Chain; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | /// CreateCopyOfByValArgument - Make a copy of an aggregate at address specified |
| 858 | /// by "Src" to address "Dst" of size "Size". Alignment information is |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 859 | /// specified by the specific parameter attribute. The copy will be passed as |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 860 | /// a byval function parameter. |
| 861 | /// Sometimes what we are copying is the end of a larger object, the part that |
| 862 | /// does not fit in registers. |
| 863 | static SDValue |
| 864 | CreateCopyOfByValArgument(SDValue Src, SDValue Dst, SDValue Chain, |
| 865 | ISD::ArgFlagsTy Flags, SelectionDAG &DAG, |
| 866 | DebugLoc dl) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 867 | SDValue SizeNode = DAG.getConstant(Flags.getByValSize(), MVT::i32); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 868 | return DAG.getMemcpy(Chain, dl, Dst, Src, SizeNode, Flags.getByValAlign(), |
Mon P Wang | 20adc9d | 2010-04-04 03:10:48 +0000 | [diff] [blame] | 869 | /*isVolatile=*/false, /*AlwaysInline=*/false, |
| 870 | NULL, 0, NULL, 0); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 871 | } |
| 872 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 873 | /// LowerMemOpCallTo - Store the argument to the stack. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 874 | SDValue |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 875 | ARMTargetLowering::LowerMemOpCallTo(SDValue Chain, |
| 876 | SDValue StackPtr, SDValue Arg, |
| 877 | DebugLoc dl, SelectionDAG &DAG, |
| 878 | const CCValAssign &VA, |
| 879 | ISD::ArgFlagsTy Flags) { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 880 | unsigned LocMemOffset = VA.getLocMemOffset(); |
| 881 | SDValue PtrOff = DAG.getIntPtrConstant(LocMemOffset); |
| 882 | PtrOff = DAG.getNode(ISD::ADD, dl, getPointerTy(), StackPtr, PtrOff); |
| 883 | if (Flags.isByVal()) { |
| 884 | return CreateCopyOfByValArgument(Arg, PtrOff, Chain, Flags, DAG, dl); |
| 885 | } |
| 886 | return DAG.getStore(Chain, dl, Arg, PtrOff, |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 887 | PseudoSourceValue::getStack(), LocMemOffset, |
| 888 | false, false, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 889 | } |
| 890 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 891 | void ARMTargetLowering::PassF64ArgInRegs(DebugLoc dl, SelectionDAG &DAG, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 892 | SDValue Chain, SDValue &Arg, |
| 893 | RegsToPassVector &RegsToPass, |
| 894 | CCValAssign &VA, CCValAssign &NextVA, |
| 895 | SDValue &StackPtr, |
| 896 | SmallVector<SDValue, 8> &MemOpChains, |
| 897 | ISD::ArgFlagsTy Flags) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 898 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 899 | SDValue fmrrd = DAG.getNode(ARMISD::VMOVRRD, dl, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 900 | DAG.getVTList(MVT::i32, MVT::i32), Arg); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 901 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), fmrrd)); |
| 902 | |
| 903 | if (NextVA.isRegLoc()) |
| 904 | RegsToPass.push_back(std::make_pair(NextVA.getLocReg(), fmrrd.getValue(1))); |
| 905 | else { |
| 906 | assert(NextVA.isMemLoc()); |
| 907 | if (StackPtr.getNode() == 0) |
| 908 | StackPtr = DAG.getCopyFromReg(Chain, dl, ARM::SP, getPointerTy()); |
| 909 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 910 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, fmrrd.getValue(1), |
| 911 | dl, DAG, NextVA, |
| 912 | Flags)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 913 | } |
| 914 | } |
| 915 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 916 | /// LowerCall - Lowering a call into a callseq_start <- |
Evan Cheng | fc40342 | 2007-02-03 08:53:01 +0000 | [diff] [blame] | 917 | /// ARMISD:CALL <- callseq_end chain. Also add input and output parameter |
| 918 | /// nodes. |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 919 | SDValue |
Evan Cheng | 022d9e1 | 2010-02-02 23:55:14 +0000 | [diff] [blame] | 920 | ARMTargetLowering::LowerCall(SDValue Chain, SDValue Callee, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 921 | CallingConv::ID CallConv, bool isVarArg, |
Evan Cheng | 0c439eb | 2010-01-27 00:07:07 +0000 | [diff] [blame] | 922 | bool &isTailCall, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 923 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
| 924 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 925 | DebugLoc dl, SelectionDAG &DAG, |
| 926 | SmallVectorImpl<SDValue> &InVals) { |
Evan Cheng | 0c439eb | 2010-01-27 00:07:07 +0000 | [diff] [blame] | 927 | // ARM target does not yet support tail call optimization. |
| 928 | isTailCall = false; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 929 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 930 | // Analyze operands of the call, assigning locations to each operand. |
| 931 | SmallVector<CCValAssign, 16> ArgLocs; |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 932 | CCState CCInfo(CallConv, isVarArg, getTargetMachine(), ArgLocs, |
| 933 | *DAG.getContext()); |
| 934 | CCInfo.AnalyzeCallOperands(Outs, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 935 | CCAssignFnForNode(CallConv, /* Return*/ false, |
| 936 | isVarArg)); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 937 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 938 | // Get a count of how many bytes are to be pushed on the stack. |
| 939 | unsigned NumBytes = CCInfo.getNextStackOffset(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 940 | |
| 941 | // Adjust the stack pointer for the new arguments... |
| 942 | // These operations are automatically eliminated by the prolog/epilog pass |
Chris Lattner | e563bbc | 2008-10-11 22:08:30 +0000 | [diff] [blame] | 943 | Chain = DAG.getCALLSEQ_START(Chain, DAG.getIntPtrConstant(NumBytes, true)); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 944 | |
Jim Grosbach | f9a4b76 | 2010-02-24 01:43:03 +0000 | [diff] [blame] | 945 | SDValue StackPtr = DAG.getCopyFromReg(Chain, dl, ARM::SP, getPointerTy()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 946 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 947 | RegsToPassVector RegsToPass; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 948 | SmallVector<SDValue, 8> MemOpChains; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 949 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 950 | // Walk the register/memloc assignments, inserting copies/loads. In the case |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 951 | // of tail call optimization, arguments are handled later. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 952 | for (unsigned i = 0, realArgIdx = 0, e = ArgLocs.size(); |
| 953 | i != e; |
| 954 | ++i, ++realArgIdx) { |
| 955 | CCValAssign &VA = ArgLocs[i]; |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 956 | SDValue Arg = Outs[realArgIdx].Val; |
| 957 | ISD::ArgFlagsTy Flags = Outs[realArgIdx].Flags; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 958 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 959 | // Promote the value if needed. |
| 960 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 961 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 962 | case CCValAssign::Full: break; |
| 963 | case CCValAssign::SExt: |
| 964 | Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg); |
| 965 | break; |
| 966 | case CCValAssign::ZExt: |
| 967 | Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg); |
| 968 | break; |
| 969 | case CCValAssign::AExt: |
| 970 | Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg); |
| 971 | break; |
| 972 | case CCValAssign::BCvt: |
| 973 | Arg = DAG.getNode(ISD::BIT_CONVERT, dl, VA.getLocVT(), Arg); |
| 974 | break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 975 | } |
| 976 | |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 977 | // f64 and v2f64 might be passed in i32 pairs and must be split into pieces |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 978 | if (VA.needsCustom()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 979 | if (VA.getLocVT() == MVT::v2f64) { |
| 980 | SDValue Op0 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 981 | DAG.getConstant(0, MVT::i32)); |
| 982 | SDValue Op1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 983 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 984 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 985 | PassF64ArgInRegs(dl, DAG, Chain, Op0, RegsToPass, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 986 | VA, ArgLocs[++i], StackPtr, MemOpChains, Flags); |
| 987 | |
| 988 | VA = ArgLocs[++i]; // skip ahead to next loc |
| 989 | if (VA.isRegLoc()) { |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 990 | PassF64ArgInRegs(dl, DAG, Chain, Op1, RegsToPass, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 991 | VA, ArgLocs[++i], StackPtr, MemOpChains, Flags); |
| 992 | } else { |
| 993 | assert(VA.isMemLoc()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 994 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 995 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, Op1, |
| 996 | dl, DAG, VA, Flags)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 997 | } |
| 998 | } else { |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 999 | PassF64ArgInRegs(dl, DAG, Chain, Arg, RegsToPass, VA, ArgLocs[++i], |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1000 | StackPtr, MemOpChains, Flags); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1001 | } |
| 1002 | } else if (VA.isRegLoc()) { |
| 1003 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg)); |
| 1004 | } else { |
| 1005 | assert(VA.isMemLoc()); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1006 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1007 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, Arg, |
| 1008 | dl, DAG, VA, Flags)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1009 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | if (!MemOpChains.empty()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1013 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1014 | &MemOpChains[0], MemOpChains.size()); |
| 1015 | |
| 1016 | // Build a sequence of copy-to-reg nodes chained together with token chain |
| 1017 | // and flag operands which copy the outgoing args into the appropriate regs. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1018 | SDValue InFlag; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1019 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1020 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1021 | RegsToPass[i].second, InFlag); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1022 | InFlag = Chain.getValue(1); |
| 1023 | } |
| 1024 | |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1025 | // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every |
| 1026 | // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol |
| 1027 | // node so that legalize doesn't hack it. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1028 | bool isDirect = false; |
| 1029 | bool isARMFunc = false; |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 1030 | bool isLocalARMFunc = false; |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1031 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1032 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1033 | |
| 1034 | if (EnableARMLongCalls) { |
| 1035 | assert (getTargetMachine().getRelocationModel() == Reloc::Static |
| 1036 | && "long-calls with non-static relocation model!"); |
| 1037 | // Handle a global address or an external symbol. If it's not one of |
| 1038 | // those, the target's already in a register, so we don't need to do |
| 1039 | // anything extra. |
| 1040 | if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
Anders Carlsson | 0dbdca5 | 2010-04-15 03:11:28 +0000 | [diff] [blame] | 1041 | const GlobalValue *GV = G->getGlobal(); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1042 | // Create a constant pool entry for the callee address |
| 1043 | unsigned ARMPCLabelIndex = AFI->createConstPoolEntryUId(); |
| 1044 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GV, |
| 1045 | ARMPCLabelIndex, |
| 1046 | ARMCP::CPValue, 0); |
| 1047 | // Get the address of the callee into a register |
| 1048 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
| 1049 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| 1050 | Callee = DAG.getLoad(getPointerTy(), dl, |
| 1051 | DAG.getEntryNode(), CPAddr, |
| 1052 | PseudoSourceValue::getConstantPool(), 0, |
| 1053 | false, false, 0); |
| 1054 | } else if (ExternalSymbolSDNode *S=dyn_cast<ExternalSymbolSDNode>(Callee)) { |
| 1055 | const char *Sym = S->getSymbol(); |
| 1056 | |
| 1057 | // Create a constant pool entry for the callee address |
| 1058 | unsigned ARMPCLabelIndex = AFI->createConstPoolEntryUId(); |
| 1059 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(*DAG.getContext(), |
| 1060 | Sym, ARMPCLabelIndex, 0); |
| 1061 | // Get the address of the callee into a register |
| 1062 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
| 1063 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| 1064 | Callee = DAG.getLoad(getPointerTy(), dl, |
| 1065 | DAG.getEntryNode(), CPAddr, |
| 1066 | PseudoSourceValue::getConstantPool(), 0, |
| 1067 | false, false, 0); |
| 1068 | } |
| 1069 | } else if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 1070 | const GlobalValue *GV = G->getGlobal(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1071 | isDirect = true; |
Chris Lattner | 4fb63d0 | 2009-07-15 04:12:33 +0000 | [diff] [blame] | 1072 | bool isExt = GV->isDeclaration() || GV->isWeakForLinker(); |
Evan Cheng | 970a419 | 2007-01-19 19:28:01 +0000 | [diff] [blame] | 1073 | bool isStub = (isExt && Subtarget->isTargetDarwin()) && |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1074 | getTargetMachine().getRelocationModel() != Reloc::Static; |
| 1075 | isARMFunc = !Subtarget->isThumb() || isStub; |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 1076 | // ARM call to a local ARM function is predicable. |
| 1077 | isLocalARMFunc = !Subtarget->isThumb() && !isExt; |
Evan Cheng | c60e76d | 2007-01-30 20:37:08 +0000 | [diff] [blame] | 1078 | // tBX takes a register source operand. |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 1079 | if (isARMFunc && Subtarget->isThumb1Only() && !Subtarget->hasV5TOps()) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1080 | unsigned ARMPCLabelIndex = AFI->createConstPoolEntryUId(); |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 1081 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GV, |
Jim Grosbach | 3fb2b1e | 2009-09-01 01:57:56 +0000 | [diff] [blame] | 1082 | ARMPCLabelIndex, |
| 1083 | ARMCP::CPValue, 4); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1084 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1085 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1086 | Callee = DAG.getLoad(getPointerTy(), dl, |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1087 | DAG.getEntryNode(), CPAddr, |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1088 | PseudoSourceValue::getConstantPool(), 0, |
| 1089 | false, false, 0); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1090 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1091 | Callee = DAG.getNode(ARMISD::PIC_ADD, dl, |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1092 | getPointerTy(), Callee, PICLabel); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1093 | } else |
Evan Cheng | c60e76d | 2007-01-30 20:37:08 +0000 | [diff] [blame] | 1094 | Callee = DAG.getTargetGlobalAddress(GV, getPointerTy()); |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1095 | } else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1096 | isDirect = true; |
Evan Cheng | 970a419 | 2007-01-19 19:28:01 +0000 | [diff] [blame] | 1097 | bool isStub = Subtarget->isTargetDarwin() && |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1098 | getTargetMachine().getRelocationModel() != Reloc::Static; |
| 1099 | isARMFunc = !Subtarget->isThumb() || isStub; |
Evan Cheng | c60e76d | 2007-01-30 20:37:08 +0000 | [diff] [blame] | 1100 | // tBX takes a register source operand. |
| 1101 | const char *Sym = S->getSymbol(); |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 1102 | if (isARMFunc && Subtarget->isThumb1Only() && !Subtarget->hasV5TOps()) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1103 | unsigned ARMPCLabelIndex = AFI->createConstPoolEntryUId(); |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 1104 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(*DAG.getContext(), |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 1105 | Sym, ARMPCLabelIndex, 4); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1106 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1107 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1108 | Callee = DAG.getLoad(getPointerTy(), dl, |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1109 | DAG.getEntryNode(), CPAddr, |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1110 | PseudoSourceValue::getConstantPool(), 0, |
| 1111 | false, false, 0); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1112 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1113 | Callee = DAG.getNode(ARMISD::PIC_ADD, dl, |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1114 | getPointerTy(), Callee, PICLabel); |
Evan Cheng | c60e76d | 2007-01-30 20:37:08 +0000 | [diff] [blame] | 1115 | } else |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1116 | Callee = DAG.getTargetExternalSymbol(Sym, getPointerTy()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1117 | } |
| 1118 | |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1119 | // FIXME: handle tail calls differently. |
| 1120 | unsigned CallOpc; |
Evan Cheng | b620724 | 2009-08-01 00:16:10 +0000 | [diff] [blame] | 1121 | if (Subtarget->isThumb()) { |
| 1122 | if ((!isDirect || isARMFunc) && !Subtarget->hasV5TOps()) |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1123 | CallOpc = ARMISD::CALL_NOLINK; |
| 1124 | else |
| 1125 | CallOpc = isARMFunc ? ARMISD::CALL : ARMISD::tCALL; |
| 1126 | } else { |
| 1127 | CallOpc = (isDirect || Subtarget->hasV5TOps()) |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 1128 | ? (isLocalARMFunc ? ARMISD::CALL_PRED : ARMISD::CALL) |
| 1129 | : ARMISD::CALL_NOLINK; |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1130 | } |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 1131 | if (CallOpc == ARMISD::CALL_NOLINK && !Subtarget->isThumb1Only()) { |
Lauro Ramos Venancio | b8a93a4 | 2007-03-27 16:19:21 +0000 | [diff] [blame] | 1132 | // implicit def LR - LR mustn't be allocated as GRP:$dst of CALL_NOLINK |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1133 | 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] | 1134 | InFlag = Chain.getValue(1); |
| 1135 | } |
| 1136 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1137 | std::vector<SDValue> Ops; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1138 | Ops.push_back(Chain); |
| 1139 | Ops.push_back(Callee); |
| 1140 | |
| 1141 | // Add argument registers to the end of the list so that they are known live |
| 1142 | // into the call. |
| 1143 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) |
| 1144 | Ops.push_back(DAG.getRegister(RegsToPass[i].first, |
| 1145 | RegsToPass[i].second.getValueType())); |
| 1146 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1147 | if (InFlag.getNode()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1148 | Ops.push_back(InFlag); |
Duncan Sands | 4bdcb61 | 2008-07-02 17:40:58 +0000 | [diff] [blame] | 1149 | // Returns a chain and a flag for retval copy to use. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1150 | Chain = DAG.getNode(CallOpc, dl, DAG.getVTList(MVT::Other, MVT::Flag), |
Duncan Sands | 4bdcb61 | 2008-07-02 17:40:58 +0000 | [diff] [blame] | 1151 | &Ops[0], Ops.size()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1152 | InFlag = Chain.getValue(1); |
| 1153 | |
Chris Lattner | e563bbc | 2008-10-11 22:08:30 +0000 | [diff] [blame] | 1154 | Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(NumBytes, true), |
| 1155 | DAG.getIntPtrConstant(0, true), InFlag); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1156 | if (!Ins.empty()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1157 | InFlag = Chain.getValue(1); |
| 1158 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1159 | // Handle result values, copying them out of physregs into vregs that we |
| 1160 | // return. |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1161 | return LowerCallResult(Chain, InFlag, CallConv, isVarArg, Ins, |
| 1162 | dl, DAG, InVals); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1163 | } |
| 1164 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1165 | SDValue |
| 1166 | ARMTargetLowering::LowerReturn(SDValue Chain, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1167 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1168 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
| 1169 | DebugLoc dl, SelectionDAG &DAG) { |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1170 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1171 | // CCValAssign - represent the assignment of the return value to a location. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1172 | SmallVector<CCValAssign, 16> RVLocs; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1173 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1174 | // CCState - Info about the registers and stack slots. |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1175 | CCState CCInfo(CallConv, isVarArg, getTargetMachine(), RVLocs, |
| 1176 | *DAG.getContext()); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1177 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1178 | // Analyze outgoing return values. |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1179 | CCInfo.AnalyzeReturn(Outs, CCAssignFnForNode(CallConv, /* Return */ true, |
| 1180 | isVarArg)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1181 | |
| 1182 | // If this is the first return lowered for this function, add |
| 1183 | // the regs to the liveout set for the function. |
| 1184 | if (DAG.getMachineFunction().getRegInfo().liveout_empty()) { |
| 1185 | for (unsigned i = 0; i != RVLocs.size(); ++i) |
| 1186 | if (RVLocs[i].isRegLoc()) |
| 1187 | DAG.getMachineFunction().getRegInfo().addLiveOut(RVLocs[i].getLocReg()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1188 | } |
| 1189 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1190 | SDValue Flag; |
| 1191 | |
| 1192 | // Copy the result values into the output registers. |
| 1193 | for (unsigned i = 0, realRVLocIdx = 0; |
| 1194 | i != RVLocs.size(); |
| 1195 | ++i, ++realRVLocIdx) { |
| 1196 | CCValAssign &VA = RVLocs[i]; |
| 1197 | assert(VA.isRegLoc() && "Can only return in registers!"); |
| 1198 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1199 | SDValue Arg = Outs[realRVLocIdx].Val; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1200 | |
| 1201 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1202 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1203 | case CCValAssign::Full: break; |
| 1204 | case CCValAssign::BCvt: |
| 1205 | Arg = DAG.getNode(ISD::BIT_CONVERT, dl, VA.getLocVT(), Arg); |
| 1206 | break; |
| 1207 | } |
| 1208 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1209 | if (VA.needsCustom()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1210 | if (VA.getLocVT() == MVT::v2f64) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1211 | // Extract the first half and return it in two registers. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1212 | SDValue Half = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1213 | DAG.getConstant(0, MVT::i32)); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1214 | SDValue HalfGPRs = DAG.getNode(ARMISD::VMOVRRD, dl, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1215 | DAG.getVTList(MVT::i32, MVT::i32), Half); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1216 | |
| 1217 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), HalfGPRs, Flag); |
| 1218 | Flag = Chain.getValue(1); |
| 1219 | VA = RVLocs[++i]; // skip ahead to next loc |
| 1220 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), |
| 1221 | HalfGPRs.getValue(1), Flag); |
| 1222 | Flag = Chain.getValue(1); |
| 1223 | VA = RVLocs[++i]; // skip ahead to next loc |
| 1224 | |
| 1225 | // Extract the 2nd half and fall through to handle it as an f64 value. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1226 | Arg = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1227 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1228 | } |
| 1229 | // Legalize ret f64 -> ret 2 x i32. We always have fmrrd if f64 is |
| 1230 | // available. |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1231 | SDValue fmrrd = DAG.getNode(ARMISD::VMOVRRD, dl, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1232 | DAG.getVTList(MVT::i32, MVT::i32), &Arg, 1); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1233 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), fmrrd, Flag); |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1234 | Flag = Chain.getValue(1); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1235 | VA = RVLocs[++i]; // skip ahead to next loc |
| 1236 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), fmrrd.getValue(1), |
| 1237 | Flag); |
| 1238 | } else |
| 1239 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), Arg, Flag); |
| 1240 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1241 | // Guarantee that all emitted copies are |
| 1242 | // stuck together, avoiding something bad. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1243 | Flag = Chain.getValue(1); |
| 1244 | } |
| 1245 | |
| 1246 | SDValue result; |
| 1247 | if (Flag.getNode()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1248 | result = DAG.getNode(ARMISD::RET_FLAG, dl, MVT::Other, Chain, Flag); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1249 | else // Return Void |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1250 | result = DAG.getNode(ARMISD::RET_FLAG, dl, MVT::Other, Chain); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1251 | |
| 1252 | return result; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1253 | } |
| 1254 | |
Bob Wilson | b62d257 | 2009-11-03 00:02:05 +0000 | [diff] [blame] | 1255 | // ConstantPool, JumpTable, GlobalAddress, and ExternalSymbol are lowered as |
| 1256 | // their target counterpart wrapped in the ARMISD::Wrapper node. Suppose N is |
| 1257 | // one of the above mentioned nodes. It has to be wrapped because otherwise |
| 1258 | // Select(N) returns N. So the raw TargetGlobalAddress nodes, etc. can only |
| 1259 | // be used to form addressing mode. These wrapped nodes will be selected |
| 1260 | // into MOVi. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1261 | static SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1262 | EVT PtrVT = Op.getValueType(); |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 1263 | // FIXME there is no actual debug info here |
| 1264 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1265 | ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1266 | SDValue Res; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1267 | if (CP->isMachineConstantPoolEntry()) |
| 1268 | Res = DAG.getTargetConstantPool(CP->getMachineCPVal(), PtrVT, |
| 1269 | CP->getAlignment()); |
| 1270 | else |
| 1271 | Res = DAG.getTargetConstantPool(CP->getConstVal(), PtrVT, |
| 1272 | CP->getAlignment()); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1273 | return DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Res); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1274 | } |
| 1275 | |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 1276 | SDValue ARMTargetLowering::LowerBlockAddress(SDValue Op, SelectionDAG &DAG) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1277 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1278 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 1279 | unsigned ARMPCLabelIndex = 0; |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 1280 | DebugLoc DL = Op.getDebugLoc(); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 1281 | EVT PtrVT = getPointerTy(); |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 1282 | const BlockAddress *BA = cast<BlockAddressSDNode>(Op)->getBlockAddress(); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 1283 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| 1284 | SDValue CPAddr; |
| 1285 | if (RelocM == Reloc::Static) { |
| 1286 | CPAddr = DAG.getTargetConstantPool(BA, PtrVT, 4); |
| 1287 | } else { |
| 1288 | unsigned PCAdj = Subtarget->isThumb() ? 4 : 8; |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1289 | ARMPCLabelIndex = AFI->createConstPoolEntryUId(); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 1290 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(BA, ARMPCLabelIndex, |
| 1291 | ARMCP::CPBlockAddress, |
| 1292 | PCAdj); |
| 1293 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
| 1294 | } |
| 1295 | CPAddr = DAG.getNode(ARMISD::Wrapper, DL, PtrVT, CPAddr); |
| 1296 | SDValue Result = DAG.getLoad(PtrVT, DL, DAG.getEntryNode(), CPAddr, |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1297 | PseudoSourceValue::getConstantPool(), 0, |
| 1298 | false, false, 0); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 1299 | if (RelocM == Reloc::Static) |
| 1300 | return Result; |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1301 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 1302 | return DAG.getNode(ARMISD::PIC_ADD, DL, PtrVT, Result, PICLabel); |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 1303 | } |
| 1304 | |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1305 | // Lower ISD::GlobalTLSAddress using the "general dynamic" model |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1306 | SDValue |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1307 | ARMTargetLowering::LowerToTLSGeneralDynamicModel(GlobalAddressSDNode *GA, |
| 1308 | SelectionDAG &DAG) { |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1309 | DebugLoc dl = GA->getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1310 | EVT PtrVT = getPointerTy(); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1311 | unsigned char PCAdj = Subtarget->isThumb() ? 4 : 8; |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1312 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1313 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 1314 | unsigned ARMPCLabelIndex = AFI->createConstPoolEntryUId(); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1315 | ARMConstantPoolValue *CPV = |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 1316 | new ARMConstantPoolValue(GA->getGlobal(), ARMPCLabelIndex, |
Jim Grosbach | 3fb2b1e | 2009-09-01 01:57:56 +0000 | [diff] [blame] | 1317 | ARMCP::CPValue, PCAdj, "tlsgd", true); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1318 | SDValue Argument = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1319 | Argument = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Argument); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1320 | Argument = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Argument, |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1321 | PseudoSourceValue::getConstantPool(), 0, |
| 1322 | false, false, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1323 | SDValue Chain = Argument.getValue(1); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1324 | |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1325 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1326 | Argument = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Argument, PICLabel); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1327 | |
| 1328 | // call __tls_get_addr. |
| 1329 | ArgListTy Args; |
| 1330 | ArgListEntry Entry; |
| 1331 | Entry.Node = Argument; |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 1332 | Entry.Ty = (const Type *) Type::getInt32Ty(*DAG.getContext()); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1333 | Args.push_back(Entry); |
Dale Johannesen | 7d2ad62 | 2009-01-30 23:10:59 +0000 | [diff] [blame] | 1334 | // FIXME: is there useful debug info available here? |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1335 | std::pair<SDValue, SDValue> CallResult = |
Evan Cheng | 59bc060 | 2009-08-14 19:11:20 +0000 | [diff] [blame] | 1336 | LowerCallTo(Chain, (const Type *) Type::getInt32Ty(*DAG.getContext()), |
| 1337 | false, false, false, false, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1338 | 0, CallingConv::C, false, /*isReturnValueUsed=*/true, |
Bill Wendling | 46ada19 | 2010-03-02 01:55:18 +0000 | [diff] [blame] | 1339 | DAG.getExternalSymbol("__tls_get_addr", PtrVT), Args, DAG, dl); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1340 | return CallResult.first; |
| 1341 | } |
| 1342 | |
| 1343 | // Lower ISD::GlobalTLSAddress using the "initial exec" or |
| 1344 | // "local exec" model. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1345 | SDValue |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1346 | ARMTargetLowering::LowerToTLSExecModels(GlobalAddressSDNode *GA, |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1347 | SelectionDAG &DAG) { |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 1348 | const GlobalValue *GV = GA->getGlobal(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1349 | DebugLoc dl = GA->getDebugLoc(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1350 | SDValue Offset; |
| 1351 | SDValue Chain = DAG.getEntryNode(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1352 | EVT PtrVT = getPointerTy(); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1353 | // Get the Thread Pointer |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1354 | SDValue ThreadPointer = DAG.getNode(ARMISD::THREAD_POINTER, dl, PtrVT); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1355 | |
Chris Lattner | 4fb63d0 | 2009-07-15 04:12:33 +0000 | [diff] [blame] | 1356 | if (GV->isDeclaration()) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1357 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1358 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 1359 | unsigned ARMPCLabelIndex = AFI->createConstPoolEntryUId(); |
| 1360 | // Initial exec model. |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1361 | unsigned char PCAdj = Subtarget->isThumb() ? 4 : 8; |
| 1362 | ARMConstantPoolValue *CPV = |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 1363 | new ARMConstantPoolValue(GA->getGlobal(), ARMPCLabelIndex, |
Jim Grosbach | 3fb2b1e | 2009-09-01 01:57:56 +0000 | [diff] [blame] | 1364 | ARMCP::CPValue, PCAdj, "gottpoff", true); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1365 | Offset = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1366 | Offset = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Offset); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1367 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1368 | PseudoSourceValue::getConstantPool(), 0, |
| 1369 | false, false, 0); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1370 | Chain = Offset.getValue(1); |
| 1371 | |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1372 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1373 | Offset = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Offset, PICLabel); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1374 | |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1375 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1376 | PseudoSourceValue::getConstantPool(), 0, |
| 1377 | false, false, 0); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1378 | } else { |
| 1379 | // local exec model |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 1380 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GV, "tpoff"); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1381 | Offset = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1382 | Offset = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Offset); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1383 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1384 | PseudoSourceValue::getConstantPool(), 0, |
| 1385 | false, false, 0); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1386 | } |
| 1387 | |
| 1388 | // The address of the thread local variable is the add of the thread |
| 1389 | // pointer with the offset of the variable. |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1390 | return DAG.getNode(ISD::ADD, dl, PtrVT, ThreadPointer, Offset); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1391 | } |
| 1392 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1393 | SDValue |
| 1394 | ARMTargetLowering::LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) { |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1395 | // TODO: implement the "local dynamic" model |
| 1396 | assert(Subtarget->isTargetELF() && |
| 1397 | "TLS not implemented for non-ELF targets"); |
| 1398 | GlobalAddressSDNode *GA = cast<GlobalAddressSDNode>(Op); |
| 1399 | // If the relocation model is PIC, use the "General Dynamic" TLS Model, |
| 1400 | // otherwise use the "Local Exec" TLS Model |
| 1401 | if (getTargetMachine().getRelocationModel() == Reloc::PIC_) |
| 1402 | return LowerToTLSGeneralDynamicModel(GA, DAG); |
| 1403 | else |
| 1404 | return LowerToTLSExecModels(GA, DAG); |
| 1405 | } |
| 1406 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1407 | SDValue ARMTargetLowering::LowerGlobalAddressELF(SDValue Op, |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1408 | SelectionDAG &DAG) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1409 | EVT PtrVT = getPointerTy(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1410 | DebugLoc dl = Op.getDebugLoc(); |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 1411 | const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 1412 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| 1413 | if (RelocM == Reloc::PIC_) { |
Rafael Espindola | bb46f52 | 2009-01-15 20:18:42 +0000 | [diff] [blame] | 1414 | bool UseGOTOFF = GV->hasLocalLinkage() || GV->hasHiddenVisibility(); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 1415 | ARMConstantPoolValue *CPV = |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 1416 | new ARMConstantPoolValue(GV, UseGOTOFF ? "GOTOFF" : "GOT"); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1417 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1418 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1419 | SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 1420 | CPAddr, |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1421 | PseudoSourceValue::getConstantPool(), 0, |
| 1422 | false, false, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1423 | SDValue Chain = Result.getValue(1); |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 1424 | SDValue GOT = DAG.getGLOBAL_OFFSET_TABLE(PtrVT); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1425 | Result = DAG.getNode(ISD::ADD, dl, PtrVT, Result, GOT); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 1426 | if (!UseGOTOFF) |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 1427 | Result = DAG.getLoad(PtrVT, dl, Chain, Result, |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1428 | PseudoSourceValue::getGOT(), 0, |
| 1429 | false, false, 0); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 1430 | return Result; |
| 1431 | } else { |
Anton Korobeynikov | 5cdc3a9 | 2009-11-24 00:44:37 +0000 | [diff] [blame] | 1432 | // If we have T2 ops, we can materialize the address directly via movt/movw |
| 1433 | // pair. This is always cheaper. |
| 1434 | if (Subtarget->useMovt()) { |
| 1435 | return DAG.getNode(ARMISD::Wrapper, dl, PtrVT, |
| 1436 | DAG.getTargetGlobalAddress(GV, PtrVT)); |
| 1437 | } else { |
| 1438 | SDValue CPAddr = DAG.getTargetConstantPool(GV, PtrVT, 4); |
| 1439 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| 1440 | return DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1441 | PseudoSourceValue::getConstantPool(), 0, |
| 1442 | false, false, 0); |
Anton Korobeynikov | 5cdc3a9 | 2009-11-24 00:44:37 +0000 | [diff] [blame] | 1443 | } |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 1444 | } |
| 1445 | } |
| 1446 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1447 | SDValue ARMTargetLowering::LowerGlobalAddressDarwin(SDValue Op, |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1448 | SelectionDAG &DAG) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1449 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1450 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 1451 | unsigned ARMPCLabelIndex = 0; |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1452 | EVT PtrVT = getPointerTy(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1453 | DebugLoc dl = Op.getDebugLoc(); |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 1454 | const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1455 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1456 | SDValue CPAddr; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1457 | if (RelocM == Reloc::Static) |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1458 | CPAddr = DAG.getTargetConstantPool(GV, PtrVT, 4); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1459 | else { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1460 | ARMPCLabelIndex = AFI->createConstPoolEntryUId(); |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 1461 | unsigned PCAdj = (RelocM != Reloc::PIC_) ? 0 : (Subtarget->isThumb()?4:8); |
| 1462 | ARMConstantPoolValue *CPV = |
Jim Grosbach | 3fb2b1e | 2009-09-01 01:57:56 +0000 | [diff] [blame] | 1463 | new ARMConstantPoolValue(GV, ARMPCLabelIndex, ARMCP::CPValue, PCAdj); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1464 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1465 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1466 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1467 | |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1468 | SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1469 | PseudoSourceValue::getConstantPool(), 0, |
| 1470 | false, false, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1471 | SDValue Chain = Result.getValue(1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1472 | |
| 1473 | if (RelocM == Reloc::PIC_) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1474 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1475 | Result = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1476 | } |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 1477 | |
Evan Cheng | 63476a8 | 2009-09-03 07:04:02 +0000 | [diff] [blame] | 1478 | if (Subtarget->GVIsIndirectSymbol(GV, RelocM)) |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1479 | Result = DAG.getLoad(PtrVT, dl, Chain, Result, |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1480 | PseudoSourceValue::getGOT(), 0, |
| 1481 | false, false, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1482 | |
| 1483 | return Result; |
| 1484 | } |
| 1485 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1486 | SDValue ARMTargetLowering::LowerGLOBAL_OFFSET_TABLE(SDValue Op, |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1487 | SelectionDAG &DAG){ |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 1488 | assert(Subtarget->isTargetELF() && |
| 1489 | "GLOBAL OFFSET TABLE not implemented for non-ELF targets"); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1490 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1491 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 1492 | unsigned ARMPCLabelIndex = AFI->createConstPoolEntryUId(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1493 | EVT PtrVT = getPointerTy(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1494 | DebugLoc dl = Op.getDebugLoc(); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 1495 | unsigned PCAdj = Subtarget->isThumb() ? 4 : 8; |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 1496 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(*DAG.getContext(), |
| 1497 | "_GLOBAL_OFFSET_TABLE_", |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 1498 | ARMPCLabelIndex, PCAdj); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1499 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1500 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 1501 | SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1502 | PseudoSourceValue::getConstantPool(), 0, |
| 1503 | false, false, 0); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1504 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1505 | return DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 1506 | } |
| 1507 | |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 1508 | SDValue |
Jim Grosbach | a87ded2 | 2010-02-08 23:22:00 +0000 | [diff] [blame] | 1509 | ARMTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG, |
| 1510 | const ARMSubtarget *Subtarget) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1511 | unsigned IntNo = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 1512 | DebugLoc dl = Op.getDebugLoc(); |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 1513 | switch (IntNo) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1514 | default: return SDValue(); // Don't custom lower most intrinsics. |
Bob Wilson | 916afdb | 2009-08-04 00:25:01 +0000 | [diff] [blame] | 1515 | case Intrinsic::arm_thread_pointer: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1516 | EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
Bob Wilson | 916afdb | 2009-08-04 00:25:01 +0000 | [diff] [blame] | 1517 | return DAG.getNode(ARMISD::THREAD_POINTER, dl, PtrVT); |
| 1518 | } |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 1519 | case Intrinsic::eh_sjlj_lsda: { |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 1520 | MachineFunction &MF = DAG.getMachineFunction(); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1521 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 1522 | unsigned ARMPCLabelIndex = AFI->createConstPoolEntryUId(); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 1523 | EVT PtrVT = getPointerTy(); |
| 1524 | DebugLoc dl = Op.getDebugLoc(); |
| 1525 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| 1526 | SDValue CPAddr; |
| 1527 | unsigned PCAdj = (RelocM != Reloc::PIC_) |
| 1528 | ? 0 : (Subtarget->isThumb() ? 4 : 8); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 1529 | ARMConstantPoolValue *CPV = |
Jim Grosbach | 3fb2b1e | 2009-09-01 01:57:56 +0000 | [diff] [blame] | 1530 | new ARMConstantPoolValue(MF.getFunction(), ARMPCLabelIndex, |
| 1531 | ARMCP::CPLSDA, PCAdj); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 1532 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1533 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 1534 | SDValue Result = |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1535 | DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1536 | PseudoSourceValue::getConstantPool(), 0, |
| 1537 | false, false, 0); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 1538 | SDValue Chain = Result.getValue(1); |
| 1539 | |
| 1540 | if (RelocM == Reloc::PIC_) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1541 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 1542 | Result = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
| 1543 | } |
| 1544 | return Result; |
| 1545 | } |
Jim Grosbach | f957012 | 2009-05-14 00:46:35 +0000 | [diff] [blame] | 1546 | case Intrinsic::eh_sjlj_setjmp: |
Jim Grosbach | a87ded2 | 2010-02-08 23:22:00 +0000 | [diff] [blame] | 1547 | SDValue Val = Subtarget->isThumb() ? |
| 1548 | DAG.getCopyFromReg(DAG.getEntryNode(), dl, ARM::SP, MVT::i32) : |
| 1549 | DAG.getConstant(0, MVT::i32); |
| 1550 | return DAG.getNode(ARMISD::EH_SJLJ_SETJMP, dl, MVT::i32, Op.getOperand(1), |
| 1551 | Val); |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 1552 | } |
| 1553 | } |
| 1554 | |
Jim Grosbach | 7c03dbd | 2009-12-14 21:24:16 +0000 | [diff] [blame] | 1555 | static SDValue LowerMEMBARRIER(SDValue Op, SelectionDAG &DAG, |
| 1556 | const ARMSubtarget *Subtarget) { |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 1557 | DebugLoc dl = Op.getDebugLoc(); |
| 1558 | SDValue Op5 = Op.getOperand(5); |
| 1559 | SDValue Res; |
| 1560 | unsigned isDeviceBarrier = cast<ConstantSDNode>(Op5)->getZExtValue(); |
| 1561 | if (isDeviceBarrier) { |
Jim Grosbach | 7c03dbd | 2009-12-14 21:24:16 +0000 | [diff] [blame] | 1562 | if (Subtarget->hasV7Ops()) |
| 1563 | Res = DAG.getNode(ARMISD::SYNCBARRIER, dl, MVT::Other, Op.getOperand(0)); |
| 1564 | else |
| 1565 | Res = DAG.getNode(ARMISD::SYNCBARRIER, dl, MVT::Other, Op.getOperand(0), |
| 1566 | DAG.getConstant(0, MVT::i32)); |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 1567 | } else { |
Jim Grosbach | 7c03dbd | 2009-12-14 21:24:16 +0000 | [diff] [blame] | 1568 | if (Subtarget->hasV7Ops()) |
| 1569 | Res = DAG.getNode(ARMISD::MEMBARRIER, dl, MVT::Other, Op.getOperand(0)); |
| 1570 | else |
| 1571 | Res = DAG.getNode(ARMISD::MEMBARRIER, dl, MVT::Other, Op.getOperand(0), |
| 1572 | DAG.getConstant(0, MVT::i32)); |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 1573 | } |
| 1574 | return Res; |
| 1575 | } |
| 1576 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1577 | static SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG, |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1578 | unsigned VarArgsFrameIndex) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1579 | // vastart just stores the address of the VarArgsFrameIndex slot into the |
| 1580 | // memory location argument. |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1581 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1582 | EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1583 | SDValue FR = DAG.getFrameIndex(VarArgsFrameIndex, PtrVT); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 1584 | const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue(); |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1585 | return DAG.getStore(Op.getOperand(0), dl, FR, Op.getOperand(1), SV, 0, |
| 1586 | false, false, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1587 | } |
| 1588 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1589 | SDValue |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 1590 | ARMTargetLowering::LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) { |
| 1591 | SDNode *Node = Op.getNode(); |
| 1592 | DebugLoc dl = Node->getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1593 | EVT VT = Node->getValueType(0); |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 1594 | SDValue Chain = Op.getOperand(0); |
| 1595 | SDValue Size = Op.getOperand(1); |
| 1596 | SDValue Align = Op.getOperand(2); |
| 1597 | |
| 1598 | // Chain the dynamic stack allocation so that it doesn't modify the stack |
| 1599 | // pointer when other instructions are using the stack. |
| 1600 | Chain = DAG.getCALLSEQ_START(Chain, DAG.getIntPtrConstant(0, true)); |
| 1601 | |
| 1602 | unsigned AlignVal = cast<ConstantSDNode>(Align)->getZExtValue(); |
| 1603 | unsigned StackAlign = getTargetMachine().getFrameInfo()->getStackAlignment(); |
| 1604 | if (AlignVal > StackAlign) |
| 1605 | // Do this now since selection pass cannot introduce new target |
| 1606 | // independent node. |
| 1607 | Align = DAG.getConstant(-(uint64_t)AlignVal, VT); |
| 1608 | |
| 1609 | // In Thumb1 mode, there isn't a "sub r, sp, r" instruction, we will end up |
| 1610 | // using a "add r, sp, r" instead. Negate the size now so we don't have to |
| 1611 | // do even more horrible hack later. |
| 1612 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1613 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 1614 | if (AFI->isThumb1OnlyFunction()) { |
| 1615 | bool Negate = true; |
| 1616 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(Size); |
| 1617 | if (C) { |
| 1618 | uint32_t Val = C->getZExtValue(); |
| 1619 | if (Val <= 508 && ((Val & 3) == 0)) |
| 1620 | Negate = false; |
| 1621 | } |
| 1622 | if (Negate) |
| 1623 | Size = DAG.getNode(ISD::SUB, dl, VT, DAG.getConstant(0, VT), Size); |
| 1624 | } |
| 1625 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1626 | SDVTList VTList = DAG.getVTList(VT, MVT::Other); |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 1627 | SDValue Ops1[] = { Chain, Size, Align }; |
| 1628 | SDValue Res = DAG.getNode(ARMISD::DYN_ALLOC, dl, VTList, Ops1, 3); |
| 1629 | Chain = Res.getValue(1); |
| 1630 | Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(0, true), |
| 1631 | DAG.getIntPtrConstant(0, true), SDValue()); |
| 1632 | SDValue Ops2[] = { Res, Chain }; |
| 1633 | return DAG.getMergeValues(Ops2, 2, dl); |
| 1634 | } |
| 1635 | |
| 1636 | SDValue |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1637 | ARMTargetLowering::GetF64FormalArgument(CCValAssign &VA, CCValAssign &NextVA, |
| 1638 | SDValue &Root, SelectionDAG &DAG, |
| 1639 | DebugLoc dl) { |
| 1640 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1641 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 1642 | |
| 1643 | TargetRegisterClass *RC; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 1644 | if (AFI->isThumb1OnlyFunction()) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1645 | RC = ARM::tGPRRegisterClass; |
| 1646 | else |
| 1647 | RC = ARM::GPRRegisterClass; |
| 1648 | |
| 1649 | // Transform the arguments stored in physical registers into virtual ones. |
| 1650 | unsigned Reg = MF.addLiveIn(VA.getLocReg(), RC); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1651 | SDValue ArgValue = DAG.getCopyFromReg(Root, dl, Reg, MVT::i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1652 | |
| 1653 | SDValue ArgValue2; |
| 1654 | if (NextVA.isMemLoc()) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1655 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
Bob Wilson | 6a234f0 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 1656 | int FI = MFI->CreateFixedObject(4, NextVA.getLocMemOffset(), true, false); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1657 | |
| 1658 | // Create load node to retrieve arguments from the stack. |
| 1659 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1660 | ArgValue2 = DAG.getLoad(MVT::i32, dl, Root, FIN, |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1661 | PseudoSourceValue::getFixedStack(FI), 0, |
| 1662 | false, false, 0); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1663 | } else { |
| 1664 | Reg = MF.addLiveIn(NextVA.getLocReg(), RC); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1665 | ArgValue2 = DAG.getCopyFromReg(Root, dl, Reg, MVT::i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1666 | } |
| 1667 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1668 | return DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, ArgValue, ArgValue2); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1669 | } |
| 1670 | |
| 1671 | SDValue |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1672 | ARMTargetLowering::LowerFormalArguments(SDValue Chain, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1673 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1674 | const SmallVectorImpl<ISD::InputArg> |
| 1675 | &Ins, |
| 1676 | DebugLoc dl, SelectionDAG &DAG, |
| 1677 | SmallVectorImpl<SDValue> &InVals) { |
| 1678 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1679 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1680 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 1681 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1682 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 1683 | |
| 1684 | // Assign locations to all of the incoming arguments. |
| 1685 | SmallVector<CCValAssign, 16> ArgLocs; |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1686 | CCState CCInfo(CallConv, isVarArg, getTargetMachine(), ArgLocs, |
| 1687 | *DAG.getContext()); |
| 1688 | CCInfo.AnalyzeFormalArguments(Ins, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1689 | CCAssignFnForNode(CallConv, /* Return*/ false, |
| 1690 | isVarArg)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1691 | |
| 1692 | SmallVector<SDValue, 16> ArgValues; |
| 1693 | |
| 1694 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| 1695 | CCValAssign &VA = ArgLocs[i]; |
| 1696 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1697 | // Arguments stored in registers. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1698 | if (VA.isRegLoc()) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1699 | EVT RegVT = VA.getLocVT(); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1700 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1701 | SDValue ArgValue; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1702 | if (VA.needsCustom()) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1703 | // f64 and vector types are split up into multiple registers or |
| 1704 | // combinations of registers and stack slots. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1705 | if (VA.getLocVT() == MVT::v2f64) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1706 | SDValue ArgValue1 = GetF64FormalArgument(VA, ArgLocs[++i], |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1707 | Chain, DAG, dl); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1708 | VA = ArgLocs[++i]; // skip ahead to next loc |
Bob Wilson | 6a234f0 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 1709 | SDValue ArgValue2; |
| 1710 | if (VA.isMemLoc()) { |
| 1711 | int FI = MFI->CreateFixedObject(8, VA.getLocMemOffset(), |
| 1712 | true, false); |
| 1713 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
| 1714 | ArgValue2 = DAG.getLoad(MVT::f64, dl, Chain, FIN, |
| 1715 | PseudoSourceValue::getFixedStack(FI), 0, |
| 1716 | false, false, 0); |
| 1717 | } else { |
| 1718 | ArgValue2 = GetF64FormalArgument(VA, ArgLocs[++i], |
| 1719 | Chain, DAG, dl); |
| 1720 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1721 | ArgValue = DAG.getNode(ISD::UNDEF, dl, MVT::v2f64); |
| 1722 | ArgValue = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1723 | ArgValue, ArgValue1, DAG.getIntPtrConstant(0)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1724 | ArgValue = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1725 | ArgValue, ArgValue2, DAG.getIntPtrConstant(1)); |
| 1726 | } else |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1727 | ArgValue = GetF64FormalArgument(VA, ArgLocs[++i], Chain, DAG, dl); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1728 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1729 | } else { |
| 1730 | TargetRegisterClass *RC; |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1731 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1732 | if (RegVT == MVT::f32) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1733 | RC = ARM::SPRRegisterClass; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1734 | else if (RegVT == MVT::f64) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1735 | RC = ARM::DPRRegisterClass; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1736 | else if (RegVT == MVT::v2f64) |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1737 | RC = ARM::QPRRegisterClass; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1738 | else if (RegVT == MVT::i32) |
Anton Korobeynikov | 058c251 | 2009-08-05 20:15:19 +0000 | [diff] [blame] | 1739 | RC = (AFI->isThumb1OnlyFunction() ? |
| 1740 | ARM::tGPRRegisterClass : ARM::GPRRegisterClass); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1741 | else |
Anton Korobeynikov | 058c251 | 2009-08-05 20:15:19 +0000 | [diff] [blame] | 1742 | llvm_unreachable("RegVT not supported by FORMAL_ARGUMENTS Lowering"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1743 | |
| 1744 | // Transform the arguments in physical registers into virtual ones. |
| 1745 | unsigned Reg = MF.addLiveIn(VA.getLocReg(), RC); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1746 | ArgValue = DAG.getCopyFromReg(Chain, dl, Reg, RegVT); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1747 | } |
| 1748 | |
| 1749 | // If this is an 8 or 16-bit value, it is really passed promoted |
| 1750 | // to 32 bits. Insert an assert[sz]ext to capture this, then |
| 1751 | // truncate to the right size. |
| 1752 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1753 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1754 | case CCValAssign::Full: break; |
| 1755 | case CCValAssign::BCvt: |
| 1756 | ArgValue = DAG.getNode(ISD::BIT_CONVERT, dl, VA.getValVT(), ArgValue); |
| 1757 | break; |
| 1758 | case CCValAssign::SExt: |
| 1759 | ArgValue = DAG.getNode(ISD::AssertSext, dl, RegVT, ArgValue, |
| 1760 | DAG.getValueType(VA.getValVT())); |
| 1761 | ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue); |
| 1762 | break; |
| 1763 | case CCValAssign::ZExt: |
| 1764 | ArgValue = DAG.getNode(ISD::AssertZext, dl, RegVT, ArgValue, |
| 1765 | DAG.getValueType(VA.getValVT())); |
| 1766 | ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue); |
| 1767 | break; |
| 1768 | } |
| 1769 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1770 | InVals.push_back(ArgValue); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1771 | |
| 1772 | } else { // VA.isRegLoc() |
| 1773 | |
| 1774 | // sanity check |
| 1775 | assert(VA.isMemLoc()); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1776 | assert(VA.getValVT() != MVT::i64 && "i64 should already be lowered"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1777 | |
| 1778 | unsigned ArgSize = VA.getLocVT().getSizeInBits()/8; |
David Greene | 3f2bf85 | 2009-11-12 20:49:22 +0000 | [diff] [blame] | 1779 | int FI = MFI->CreateFixedObject(ArgSize, VA.getLocMemOffset(), |
| 1780 | true, false); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1781 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1782 | // Create load nodes to retrieve arguments from the stack. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1783 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1784 | InVals.push_back(DAG.getLoad(VA.getValVT(), dl, Chain, FIN, |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1785 | PseudoSourceValue::getFixedStack(FI), 0, |
| 1786 | false, false, 0)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1787 | } |
| 1788 | } |
| 1789 | |
| 1790 | // varargs |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1791 | if (isVarArg) { |
| 1792 | static const unsigned GPRArgRegs[] = { |
| 1793 | ARM::R0, ARM::R1, ARM::R2, ARM::R3 |
| 1794 | }; |
| 1795 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1796 | unsigned NumGPRs = CCInfo.getFirstUnallocated |
| 1797 | (GPRArgRegs, sizeof(GPRArgRegs) / sizeof(GPRArgRegs[0])); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1798 | |
Lauro Ramos Venancio | 600c383 | 2007-02-23 20:32:57 +0000 | [diff] [blame] | 1799 | unsigned Align = MF.getTarget().getFrameInfo()->getStackAlignment(); |
| 1800 | unsigned VARegSize = (4 - NumGPRs) * 4; |
| 1801 | unsigned VARegSaveSize = (VARegSize + Align - 1) & ~(Align - 1); |
Rafael Espindola | c1382b7 | 2009-10-30 14:33:14 +0000 | [diff] [blame] | 1802 | unsigned ArgOffset = CCInfo.getNextStackOffset(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1803 | if (VARegSaveSize) { |
| 1804 | // If this function is vararg, store any remaining integer argument regs |
| 1805 | // to their spots on the stack so that they may be loaded by deferencing |
| 1806 | // the result of va_next. |
| 1807 | AFI->setVarArgsRegSaveSize(VARegSaveSize); |
Lauro Ramos Venancio | 600c383 | 2007-02-23 20:32:57 +0000 | [diff] [blame] | 1808 | VarArgsFrameIndex = MFI->CreateFixedObject(VARegSaveSize, ArgOffset + |
David Greene | 3f2bf85 | 2009-11-12 20:49:22 +0000 | [diff] [blame] | 1809 | VARegSaveSize - VARegSize, |
| 1810 | true, false); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1811 | SDValue FIN = DAG.getFrameIndex(VarArgsFrameIndex, getPointerTy()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1812 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1813 | SmallVector<SDValue, 4> MemOps; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1814 | for (; NumGPRs < 4; ++NumGPRs) { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1815 | TargetRegisterClass *RC; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 1816 | if (AFI->isThumb1OnlyFunction()) |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1817 | RC = ARM::tGPRRegisterClass; |
Jim Grosbach | 30eae3c | 2009-04-07 20:34:09 +0000 | [diff] [blame] | 1818 | else |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1819 | RC = ARM::GPRRegisterClass; |
| 1820 | |
Bob Wilson | 998e125 | 2009-04-20 18:36:57 +0000 | [diff] [blame] | 1821 | unsigned VReg = MF.addLiveIn(GPRArgRegs[NumGPRs], RC); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1822 | SDValue Val = DAG.getCopyFromReg(Chain, dl, VReg, MVT::i32); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1823 | SDValue Store = DAG.getStore(Val.getValue(1), dl, Val, FIN, |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1824 | PseudoSourceValue::getFixedStack(VarArgsFrameIndex), 0, |
| 1825 | false, false, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1826 | MemOps.push_back(Store); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1827 | FIN = DAG.getNode(ISD::ADD, dl, getPointerTy(), FIN, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1828 | DAG.getConstant(4, getPointerTy())); |
| 1829 | } |
| 1830 | if (!MemOps.empty()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1831 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1832 | &MemOps[0], MemOps.size()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1833 | } else |
| 1834 | // This will point to the next argument passed via stack. |
David Greene | 3f2bf85 | 2009-11-12 20:49:22 +0000 | [diff] [blame] | 1835 | VarArgsFrameIndex = MFI->CreateFixedObject(4, ArgOffset, true, false); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1836 | } |
| 1837 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1838 | return Chain; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1839 | } |
| 1840 | |
| 1841 | /// isFloatingPointZero - Return true if this is +0.0. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1842 | static bool isFloatingPointZero(SDValue Op) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1843 | if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(Op)) |
Dale Johannesen | eaf0894 | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 1844 | return CFP->getValueAPF().isPosZero(); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1845 | else if (ISD::isEXTLoad(Op.getNode()) || ISD::isNON_EXTLoad(Op.getNode())) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1846 | // Maybe this has already been legalized into the constant pool? |
| 1847 | if (Op.getOperand(1).getOpcode() == ARMISD::Wrapper) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1848 | SDValue WrapperOp = Op.getOperand(1).getOperand(0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1849 | if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(WrapperOp)) |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 1850 | if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CP->getConstVal())) |
Dale Johannesen | eaf0894 | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 1851 | return CFP->getValueAPF().isPosZero(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1852 | } |
| 1853 | } |
| 1854 | return false; |
| 1855 | } |
| 1856 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1857 | /// Returns appropriate ARM CMP (cmp) and corresponding condition code for |
| 1858 | /// the given operands. |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 1859 | SDValue |
| 1860 | ARMTargetLowering::getARMCmp(SDValue LHS, SDValue RHS, ISD::CondCode CC, |
| 1861 | SDValue &ARMCC, SelectionDAG &DAG, DebugLoc dl) { |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1862 | if (ConstantSDNode *RHSC = dyn_cast<ConstantSDNode>(RHS.getNode())) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1863 | unsigned C = RHSC->getZExtValue(); |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 1864 | if (!isLegalICmpImmediate(C)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1865 | // Constant does not fit, try adjusting it by one? |
| 1866 | switch (CC) { |
| 1867 | default: break; |
| 1868 | case ISD::SETLT: |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1869 | case ISD::SETGE: |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 1870 | if (isLegalICmpImmediate(C-1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 1871 | CC = (CC == ISD::SETLT) ? ISD::SETLE : ISD::SETGT; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1872 | RHS = DAG.getConstant(C-1, MVT::i32); |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 1873 | } |
| 1874 | break; |
| 1875 | case ISD::SETULT: |
| 1876 | case ISD::SETUGE: |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 1877 | if (C > 0 && isLegalICmpImmediate(C-1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 1878 | CC = (CC == ISD::SETULT) ? ISD::SETULE : ISD::SETUGT; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1879 | RHS = DAG.getConstant(C-1, MVT::i32); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1880 | } |
| 1881 | break; |
| 1882 | case ISD::SETLE: |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1883 | case ISD::SETGT: |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 1884 | if (isLegalICmpImmediate(C+1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 1885 | CC = (CC == ISD::SETLE) ? ISD::SETLT : ISD::SETGE; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1886 | RHS = DAG.getConstant(C+1, MVT::i32); |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 1887 | } |
| 1888 | break; |
| 1889 | case ISD::SETULE: |
| 1890 | case ISD::SETUGT: |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 1891 | if (C < 0xffffffff && isLegalICmpImmediate(C+1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 1892 | CC = (CC == ISD::SETULE) ? ISD::SETULT : ISD::SETUGE; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1893 | RHS = DAG.getConstant(C+1, MVT::i32); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1894 | } |
| 1895 | break; |
| 1896 | } |
| 1897 | } |
| 1898 | } |
| 1899 | |
| 1900 | ARMCC::CondCodes CondCode = IntCCToARMCC(CC); |
Lauro Ramos Venancio | 9996663 | 2007-04-02 01:30:03 +0000 | [diff] [blame] | 1901 | ARMISD::NodeType CompareType; |
| 1902 | switch (CondCode) { |
| 1903 | default: |
| 1904 | CompareType = ARMISD::CMP; |
| 1905 | break; |
| 1906 | case ARMCC::EQ: |
| 1907 | case ARMCC::NE: |
David Goodwin | c0309b4 | 2009-06-29 15:33:01 +0000 | [diff] [blame] | 1908 | // Uses only Z Flag |
| 1909 | CompareType = ARMISD::CMPZ; |
Lauro Ramos Venancio | 9996663 | 2007-04-02 01:30:03 +0000 | [diff] [blame] | 1910 | break; |
| 1911 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1912 | ARMCC = DAG.getConstant(CondCode, MVT::i32); |
| 1913 | return DAG.getNode(CompareType, dl, MVT::Flag, LHS, RHS); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1914 | } |
| 1915 | |
| 1916 | /// 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] | 1917 | static SDValue getVFPCmp(SDValue LHS, SDValue RHS, SelectionDAG &DAG, |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1918 | DebugLoc dl) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1919 | SDValue Cmp; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1920 | if (!isFloatingPointZero(RHS)) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1921 | Cmp = DAG.getNode(ARMISD::CMPFP, dl, MVT::Flag, LHS, RHS); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1922 | else |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1923 | Cmp = DAG.getNode(ARMISD::CMPFPw0, dl, MVT::Flag, LHS); |
| 1924 | return DAG.getNode(ARMISD::FMSTAT, dl, MVT::Flag, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1925 | } |
| 1926 | |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 1927 | SDValue ARMTargetLowering::LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1928 | EVT VT = Op.getValueType(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1929 | SDValue LHS = Op.getOperand(0); |
| 1930 | SDValue RHS = Op.getOperand(1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1931 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(4))->get(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1932 | SDValue TrueVal = Op.getOperand(2); |
| 1933 | SDValue FalseVal = Op.getOperand(3); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1934 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1935 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1936 | if (LHS.getValueType() == MVT::i32) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1937 | SDValue ARMCC; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1938 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 1939 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMCC, DAG, dl); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1940 | return DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, ARMCC, CCR,Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1941 | } |
| 1942 | |
| 1943 | ARMCC::CondCodes CondCode, CondCode2; |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 1944 | FPCCToARMCC(CC, CondCode, CondCode2); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1945 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1946 | SDValue ARMCC = DAG.getConstant(CondCode, MVT::i32); |
| 1947 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1948 | SDValue Cmp = getVFPCmp(LHS, RHS, DAG, dl); |
| 1949 | SDValue Result = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, |
Evan Cheng | 0e1d379 | 2007-07-05 07:18:20 +0000 | [diff] [blame] | 1950 | ARMCC, CCR, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1951 | if (CondCode2 != ARMCC::AL) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1952 | SDValue ARMCC2 = DAG.getConstant(CondCode2, MVT::i32); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1953 | // FIXME: Needs another CMP because flag can have but one use. |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1954 | SDValue Cmp2 = getVFPCmp(LHS, RHS, DAG, dl); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1955 | Result = DAG.getNode(ARMISD::CMOV, dl, VT, |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1956 | Result, TrueVal, ARMCC2, CCR, Cmp2); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1957 | } |
| 1958 | return Result; |
| 1959 | } |
| 1960 | |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 1961 | SDValue ARMTargetLowering::LowerBR_CC(SDValue Op, SelectionDAG &DAG) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1962 | SDValue Chain = Op.getOperand(0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1963 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1964 | SDValue LHS = Op.getOperand(2); |
| 1965 | SDValue RHS = Op.getOperand(3); |
| 1966 | SDValue Dest = Op.getOperand(4); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1967 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1968 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1969 | if (LHS.getValueType() == MVT::i32) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1970 | SDValue ARMCC; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1971 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 1972 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMCC, DAG, dl); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1973 | return DAG.getNode(ARMISD::BRCOND, dl, MVT::Other, |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1974 | Chain, Dest, ARMCC, CCR,Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1975 | } |
| 1976 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1977 | assert(LHS.getValueType() == MVT::f32 || LHS.getValueType() == MVT::f64); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1978 | ARMCC::CondCodes CondCode, CondCode2; |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 1979 | FPCCToARMCC(CC, CondCode, CondCode2); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1980 | |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1981 | SDValue Cmp = getVFPCmp(LHS, RHS, DAG, dl); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1982 | SDValue ARMCC = DAG.getConstant(CondCode, MVT::i32); |
| 1983 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| 1984 | SDVTList VTList = DAG.getVTList(MVT::Other, MVT::Flag); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1985 | SDValue Ops[] = { Chain, Dest, ARMCC, CCR, Cmp }; |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1986 | SDValue Res = DAG.getNode(ARMISD::BRCOND, dl, VTList, Ops, 5); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1987 | if (CondCode2 != ARMCC::AL) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1988 | ARMCC = DAG.getConstant(CondCode2, MVT::i32); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1989 | SDValue Ops[] = { Res, Dest, ARMCC, CCR, Res.getValue(1) }; |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1990 | Res = DAG.getNode(ARMISD::BRCOND, dl, VTList, Ops, 5); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1991 | } |
| 1992 | return Res; |
| 1993 | } |
| 1994 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1995 | SDValue ARMTargetLowering::LowerBR_JT(SDValue Op, SelectionDAG &DAG) { |
| 1996 | SDValue Chain = Op.getOperand(0); |
| 1997 | SDValue Table = Op.getOperand(1); |
| 1998 | SDValue Index = Op.getOperand(2); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1999 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2000 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2001 | EVT PTy = getPointerTy(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2002 | JumpTableSDNode *JT = cast<JumpTableSDNode>(Table); |
| 2003 | ARMFunctionInfo *AFI = DAG.getMachineFunction().getInfo<ARMFunctionInfo>(); |
Bob Wilson | 3eadf00 | 2009-07-14 18:44:34 +0000 | [diff] [blame] | 2004 | SDValue UId = DAG.getConstant(AFI->createJumpTableUId(), PTy); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2005 | SDValue JTI = DAG.getTargetJumpTable(JT->getIndex(), PTy); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2006 | Table = DAG.getNode(ARMISD::WrapperJT, dl, MVT::i32, JTI, UId); |
Evan Cheng | e7c329b | 2009-07-28 20:53:24 +0000 | [diff] [blame] | 2007 | Index = DAG.getNode(ISD::MUL, dl, PTy, Index, DAG.getConstant(4, PTy)); |
| 2008 | SDValue Addr = DAG.getNode(ISD::ADD, dl, PTy, Index, Table); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 2009 | if (Subtarget->isThumb2()) { |
| 2010 | // Thumb2 uses a two-level jump. That is, it jumps into the jump table |
| 2011 | // which does another jump to the destination. This also makes it easier |
| 2012 | // to translate it to TBB / TBH later. |
| 2013 | // FIXME: This might not work if the function is extremely large. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2014 | return DAG.getNode(ARMISD::BR2_JT, dl, MVT::Other, Chain, |
Evan Cheng | 5657c01 | 2009-07-29 02:18:14 +0000 | [diff] [blame] | 2015 | Addr, Op.getOperand(2), JTI, UId); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 2016 | } |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 2017 | if (getTargetMachine().getRelocationModel() == Reloc::PIC_) { |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2018 | Addr = DAG.getLoad((EVT)MVT::i32, dl, Chain, Addr, |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 2019 | PseudoSourceValue::getJumpTable(), 0, |
| 2020 | false, false, 0); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 2021 | Chain = Addr.getValue(1); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2022 | Addr = DAG.getNode(ISD::ADD, dl, PTy, Addr, Table); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2023 | return DAG.getNode(ARMISD::BR_JT, dl, MVT::Other, Chain, Addr, JTI, UId); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 2024 | } else { |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2025 | Addr = DAG.getLoad(PTy, dl, Chain, Addr, |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 2026 | PseudoSourceValue::getJumpTable(), 0, false, false, 0); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 2027 | Chain = Addr.getValue(1); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2028 | return DAG.getNode(ARMISD::BR_JT, dl, MVT::Other, Chain, Addr, JTI, UId); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 2029 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2030 | } |
| 2031 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 2032 | static SDValue LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG) { |
| 2033 | DebugLoc dl = Op.getDebugLoc(); |
| 2034 | unsigned Opc; |
| 2035 | |
| 2036 | switch (Op.getOpcode()) { |
| 2037 | default: |
| 2038 | assert(0 && "Invalid opcode!"); |
| 2039 | case ISD::FP_TO_SINT: |
| 2040 | Opc = ARMISD::FTOSI; |
| 2041 | break; |
| 2042 | case ISD::FP_TO_UINT: |
| 2043 | Opc = ARMISD::FTOUI; |
| 2044 | break; |
| 2045 | } |
| 2046 | Op = DAG.getNode(Opc, dl, MVT::f32, Op.getOperand(0)); |
| 2047 | return DAG.getNode(ISD::BIT_CONVERT, dl, MVT::i32, Op); |
| 2048 | } |
| 2049 | |
| 2050 | static SDValue LowerINT_TO_FP(SDValue Op, SelectionDAG &DAG) { |
| 2051 | EVT VT = Op.getValueType(); |
| 2052 | DebugLoc dl = Op.getDebugLoc(); |
| 2053 | unsigned Opc; |
| 2054 | |
| 2055 | switch (Op.getOpcode()) { |
| 2056 | default: |
| 2057 | assert(0 && "Invalid opcode!"); |
| 2058 | case ISD::SINT_TO_FP: |
| 2059 | Opc = ARMISD::SITOF; |
| 2060 | break; |
| 2061 | case ISD::UINT_TO_FP: |
| 2062 | Opc = ARMISD::UITOF; |
| 2063 | break; |
| 2064 | } |
| 2065 | |
| 2066 | Op = DAG.getNode(ISD::BIT_CONVERT, dl, MVT::f32, Op.getOperand(0)); |
| 2067 | return DAG.getNode(Opc, dl, VT, Op); |
| 2068 | } |
| 2069 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2070 | static SDValue LowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2071 | // Implement fcopysign with a fabs and a conditional fneg. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2072 | SDValue Tmp0 = Op.getOperand(0); |
| 2073 | SDValue Tmp1 = Op.getOperand(1); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2074 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2075 | EVT VT = Op.getValueType(); |
| 2076 | EVT SrcVT = Tmp1.getValueType(); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2077 | SDValue AbsVal = DAG.getNode(ISD::FABS, dl, VT, Tmp0); |
| 2078 | SDValue Cmp = getVFPCmp(Tmp1, DAG.getConstantFP(0.0, SrcVT), DAG, dl); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2079 | SDValue ARMCC = DAG.getConstant(ARMCC::LT, MVT::i32); |
| 2080 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2081 | return DAG.getNode(ARMISD::CNEG, dl, VT, AbsVal, AbsVal, ARMCC, CCR, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2082 | } |
| 2083 | |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 2084 | SDValue ARMTargetLowering::LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) { |
| 2085 | MachineFrameInfo *MFI = DAG.getMachineFunction().getFrameInfo(); |
| 2086 | MFI->setFrameAddressIsTaken(true); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2087 | EVT VT = Op.getValueType(); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 2088 | DebugLoc dl = Op.getDebugLoc(); // FIXME probably not meaningful |
| 2089 | unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
Evan Cheng | cd82861 | 2009-06-18 23:14:30 +0000 | [diff] [blame] | 2090 | unsigned FrameReg = (Subtarget->isThumb() || Subtarget->isTargetDarwin()) |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 2091 | ? ARM::R7 : ARM::R11; |
| 2092 | SDValue FrameAddr = DAG.getCopyFromReg(DAG.getEntryNode(), dl, FrameReg, VT); |
| 2093 | while (Depth--) |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 2094 | FrameAddr = DAG.getLoad(VT, dl, DAG.getEntryNode(), FrameAddr, NULL, 0, |
| 2095 | false, false, 0); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 2096 | return FrameAddr; |
| 2097 | } |
| 2098 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2099 | SDValue |
Dale Johannesen | 0f502f6 | 2009-02-03 22:26:09 +0000 | [diff] [blame] | 2100 | ARMTargetLowering::EmitTargetCodeForMemcpy(SelectionDAG &DAG, DebugLoc dl, |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2101 | SDValue Chain, |
| 2102 | SDValue Dst, SDValue Src, |
| 2103 | SDValue Size, unsigned Align, |
Mon P Wang | 20adc9d | 2010-04-04 03:10:48 +0000 | [diff] [blame] | 2104 | bool isVolatile, bool AlwaysInline, |
Dan Gohman | 1f13c68 | 2008-04-28 17:15:20 +0000 | [diff] [blame] | 2105 | const Value *DstSV, uint64_t DstSVOff, |
| 2106 | const Value *SrcSV, uint64_t SrcSVOff){ |
Evan Cheng | 4102eb5 | 2007-10-22 22:11:27 +0000 | [diff] [blame] | 2107 | // Do repeated 4-byte loads and stores. To be improved. |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 2108 | // This requires 4-byte alignment. |
| 2109 | if ((Align & 3) != 0) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2110 | return SDValue(); |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 2111 | // This requires the copy size to be a constant, preferrably |
| 2112 | // within a subtarget-specific limit. |
| 2113 | ConstantSDNode *ConstantSize = dyn_cast<ConstantSDNode>(Size); |
| 2114 | if (!ConstantSize) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2115 | return SDValue(); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2116 | uint64_t SizeVal = ConstantSize->getZExtValue(); |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 2117 | if (!AlwaysInline && SizeVal > getSubtarget()->getMaxInlineSizeThreshold()) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2118 | return SDValue(); |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 2119 | |
| 2120 | unsigned BytesLeft = SizeVal & 3; |
| 2121 | unsigned NumMemOps = SizeVal >> 2; |
Dale Johannesen | 8dd86c1 | 2007-05-17 21:31:21 +0000 | [diff] [blame] | 2122 | unsigned EmittedNumMemOps = 0; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2123 | EVT VT = MVT::i32; |
Dale Johannesen | 8dd86c1 | 2007-05-17 21:31:21 +0000 | [diff] [blame] | 2124 | unsigned VTSize = 4; |
Evan Cheng | 4102eb5 | 2007-10-22 22:11:27 +0000 | [diff] [blame] | 2125 | unsigned i = 0; |
Evan Cheng | e5e7ce4 | 2007-05-18 01:19:57 +0000 | [diff] [blame] | 2126 | const unsigned MAX_LOADS_IN_LDM = 6; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2127 | SDValue TFOps[MAX_LOADS_IN_LDM]; |
| 2128 | SDValue Loads[MAX_LOADS_IN_LDM]; |
Dan Gohman | 1f13c68 | 2008-04-28 17:15:20 +0000 | [diff] [blame] | 2129 | uint64_t SrcOff = 0, DstOff = 0; |
Dale Johannesen | 8dd86c1 | 2007-05-17 21:31:21 +0000 | [diff] [blame] | 2130 | |
Evan Cheng | 4102eb5 | 2007-10-22 22:11:27 +0000 | [diff] [blame] | 2131 | // Emit up to MAX_LOADS_IN_LDM loads, then a TokenFactor barrier, then the |
| 2132 | // same number of stores. The loads and stores will get combined into |
Dale Johannesen | 8dd86c1 | 2007-05-17 21:31:21 +0000 | [diff] [blame] | 2133 | // ldm/stm later on. |
Evan Cheng | 4102eb5 | 2007-10-22 22:11:27 +0000 | [diff] [blame] | 2134 | while (EmittedNumMemOps < NumMemOps) { |
| 2135 | for (i = 0; |
| 2136 | i < MAX_LOADS_IN_LDM && EmittedNumMemOps + i < NumMemOps; ++i) { |
Dale Johannesen | 0f502f6 | 2009-02-03 22:26:09 +0000 | [diff] [blame] | 2137 | Loads[i] = DAG.getLoad(VT, dl, Chain, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2138 | DAG.getNode(ISD::ADD, dl, MVT::i32, Src, |
| 2139 | DAG.getConstant(SrcOff, MVT::i32)), |
Mon P Wang | 20adc9d | 2010-04-04 03:10:48 +0000 | [diff] [blame] | 2140 | SrcSV, SrcSVOff + SrcOff, isVolatile, false, 0); |
Evan Cheng | 4102eb5 | 2007-10-22 22:11:27 +0000 | [diff] [blame] | 2141 | TFOps[i] = Loads[i].getValue(1); |
Dale Johannesen | 8dd86c1 | 2007-05-17 21:31:21 +0000 | [diff] [blame] | 2142 | SrcOff += VTSize; |
| 2143 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2144 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, &TFOps[0], i); |
Dale Johannesen | 8dd86c1 | 2007-05-17 21:31:21 +0000 | [diff] [blame] | 2145 | |
Evan Cheng | 4102eb5 | 2007-10-22 22:11:27 +0000 | [diff] [blame] | 2146 | for (i = 0; |
| 2147 | i < MAX_LOADS_IN_LDM && EmittedNumMemOps + i < NumMemOps; ++i) { |
Dale Johannesen | 0f502f6 | 2009-02-03 22:26:09 +0000 | [diff] [blame] | 2148 | TFOps[i] = DAG.getStore(Chain, dl, Loads[i], |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 2149 | DAG.getNode(ISD::ADD, dl, MVT::i32, Dst, |
| 2150 | DAG.getConstant(DstOff, MVT::i32)), |
Mon P Wang | 20adc9d | 2010-04-04 03:10:48 +0000 | [diff] [blame] | 2151 | DstSV, DstSVOff + DstOff, isVolatile, false, 0); |
Dale Johannesen | 8dd86c1 | 2007-05-17 21:31:21 +0000 | [diff] [blame] | 2152 | DstOff += VTSize; |
| 2153 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2154 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, &TFOps[0], i); |
Evan Cheng | 4102eb5 | 2007-10-22 22:11:27 +0000 | [diff] [blame] | 2155 | |
Dale Johannesen | 8dd86c1 | 2007-05-17 21:31:21 +0000 | [diff] [blame] | 2156 | EmittedNumMemOps += i; |
| 2157 | } |
| 2158 | |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2159 | if (BytesLeft == 0) |
Evan Cheng | 4102eb5 | 2007-10-22 22:11:27 +0000 | [diff] [blame] | 2160 | return Chain; |
| 2161 | |
| 2162 | // Issue loads / stores for the trailing (1 - 3) bytes. |
| 2163 | unsigned BytesLeftSave = BytesLeft; |
| 2164 | i = 0; |
| 2165 | while (BytesLeft) { |
| 2166 | if (BytesLeft >= 2) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2167 | VT = MVT::i16; |
Evan Cheng | 4102eb5 | 2007-10-22 22:11:27 +0000 | [diff] [blame] | 2168 | VTSize = 2; |
| 2169 | } else { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2170 | VT = MVT::i8; |
Evan Cheng | 4102eb5 | 2007-10-22 22:11:27 +0000 | [diff] [blame] | 2171 | VTSize = 1; |
| 2172 | } |
| 2173 | |
Dale Johannesen | 0f502f6 | 2009-02-03 22:26:09 +0000 | [diff] [blame] | 2174 | Loads[i] = DAG.getLoad(VT, dl, Chain, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2175 | DAG.getNode(ISD::ADD, dl, MVT::i32, Src, |
| 2176 | DAG.getConstant(SrcOff, MVT::i32)), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 2177 | SrcSV, SrcSVOff + SrcOff, false, false, 0); |
Evan Cheng | 4102eb5 | 2007-10-22 22:11:27 +0000 | [diff] [blame] | 2178 | TFOps[i] = Loads[i].getValue(1); |
| 2179 | ++i; |
| 2180 | SrcOff += VTSize; |
| 2181 | BytesLeft -= VTSize; |
| 2182 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2183 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, &TFOps[0], i); |
Evan Cheng | 4102eb5 | 2007-10-22 22:11:27 +0000 | [diff] [blame] | 2184 | |
| 2185 | i = 0; |
| 2186 | BytesLeft = BytesLeftSave; |
| 2187 | while (BytesLeft) { |
| 2188 | if (BytesLeft >= 2) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2189 | VT = MVT::i16; |
Evan Cheng | 4102eb5 | 2007-10-22 22:11:27 +0000 | [diff] [blame] | 2190 | VTSize = 2; |
| 2191 | } else { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2192 | VT = MVT::i8; |
Evan Cheng | 4102eb5 | 2007-10-22 22:11:27 +0000 | [diff] [blame] | 2193 | VTSize = 1; |
| 2194 | } |
| 2195 | |
Dale Johannesen | 0f502f6 | 2009-02-03 22:26:09 +0000 | [diff] [blame] | 2196 | TFOps[i] = DAG.getStore(Chain, dl, Loads[i], |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2197 | DAG.getNode(ISD::ADD, dl, MVT::i32, Dst, |
| 2198 | DAG.getConstant(DstOff, MVT::i32)), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 2199 | DstSV, DstSVOff + DstOff, false, false, 0); |
Evan Cheng | 4102eb5 | 2007-10-22 22:11:27 +0000 | [diff] [blame] | 2200 | ++i; |
| 2201 | DstOff += VTSize; |
| 2202 | BytesLeft -= VTSize; |
| 2203 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2204 | return DAG.getNode(ISD::TokenFactor, dl, MVT::Other, &TFOps[0], i); |
Dale Johannesen | 8dd86c1 | 2007-05-17 21:31:21 +0000 | [diff] [blame] | 2205 | } |
| 2206 | |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 2207 | /// ExpandBIT_CONVERT - If the target supports VFP, this function is called to |
| 2208 | /// expand a bit convert where either the source or destination type is i64 to |
| 2209 | /// use a VMOVDRR or VMOVRRD node. This should not be done when the non-i64 |
| 2210 | /// operand type is illegal (e.g., v2f32 for a target that doesn't support |
| 2211 | /// vectors), since the legalizer won't know what to do with that. |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 2212 | static SDValue ExpandBIT_CONVERT(SDNode *N, SelectionDAG &DAG) { |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 2213 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 2214 | DebugLoc dl = N->getDebugLoc(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2215 | SDValue Op = N->getOperand(0); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 2216 | |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 2217 | // This function is only supposed to be called for i64 types, either as the |
| 2218 | // source or destination of the bit convert. |
| 2219 | EVT SrcVT = Op.getValueType(); |
| 2220 | EVT DstVT = N->getValueType(0); |
| 2221 | assert((SrcVT == MVT::i64 || DstVT == MVT::i64) && |
| 2222 | "ExpandBIT_CONVERT called for non-i64 type"); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 2223 | |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 2224 | // Turn i64->f64 into VMOVDRR. |
| 2225 | if (SrcVT == MVT::i64 && TLI.isTypeLegal(DstVT)) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2226 | SDValue Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Op, |
| 2227 | DAG.getConstant(0, MVT::i32)); |
| 2228 | SDValue Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Op, |
| 2229 | DAG.getConstant(1, MVT::i32)); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 2230 | return DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
Evan Cheng | c7c7729 | 2008-11-04 19:57:48 +0000 | [diff] [blame] | 2231 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2232 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 2233 | // Turn f64->i64 into VMOVRRD. |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 2234 | if (DstVT == MVT::i64 && TLI.isTypeLegal(SrcVT)) { |
| 2235 | SDValue Cvt = DAG.getNode(ARMISD::VMOVRRD, dl, |
| 2236 | DAG.getVTList(MVT::i32, MVT::i32), &Op, 1); |
| 2237 | // Merge the pieces into a single i64 value. |
| 2238 | return DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Cvt, Cvt.getValue(1)); |
| 2239 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2240 | |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 2241 | return SDValue(); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 2242 | } |
| 2243 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2244 | /// getZeroVector - Returns a vector of specified type with all zero elements. |
| 2245 | /// |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2246 | static SDValue getZeroVector(EVT VT, SelectionDAG &DAG, DebugLoc dl) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2247 | assert(VT.isVector() && "Expected a vector type"); |
| 2248 | |
| 2249 | // Zero vectors are used to represent vector negation and in those cases |
| 2250 | // will be implemented with the NEON VNEG instruction. However, VNEG does |
| 2251 | // not support i64 elements, so sometimes the zero vectors will need to be |
| 2252 | // explicitly constructed. For those cases, and potentially other uses in |
Anton Korobeynikov | 2ba62ef | 2009-09-08 22:51:43 +0000 | [diff] [blame] | 2253 | // the future, always build zero vectors as <16 x i8> or <8 x i8> bitcasted |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2254 | // to their dest type. This ensures they get CSE'd. |
| 2255 | SDValue Vec; |
Anton Korobeynikov | 2ba62ef | 2009-09-08 22:51:43 +0000 | [diff] [blame] | 2256 | SDValue Cst = DAG.getTargetConstant(0, MVT::i8); |
| 2257 | SmallVector<SDValue, 8> Ops; |
| 2258 | MVT TVT; |
| 2259 | |
| 2260 | if (VT.getSizeInBits() == 64) { |
| 2261 | Ops.assign(8, Cst); TVT = MVT::v8i8; |
| 2262 | } else { |
| 2263 | Ops.assign(16, Cst); TVT = MVT::v16i8; |
| 2264 | } |
| 2265 | Vec = DAG.getNode(ISD::BUILD_VECTOR, dl, TVT, &Ops[0], Ops.size()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2266 | |
| 2267 | return DAG.getNode(ISD::BIT_CONVERT, dl, VT, Vec); |
| 2268 | } |
| 2269 | |
| 2270 | /// getOnesVector - Returns a vector of specified type with all bits set. |
| 2271 | /// |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2272 | static SDValue getOnesVector(EVT VT, SelectionDAG &DAG, DebugLoc dl) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2273 | assert(VT.isVector() && "Expected a vector type"); |
| 2274 | |
Bob Wilson | 929ffa2 | 2009-10-30 20:13:25 +0000 | [diff] [blame] | 2275 | // Always build ones vectors as <16 x i8> or <8 x i8> bitcasted to their |
Anton Korobeynikov | 2ba62ef | 2009-09-08 22:51:43 +0000 | [diff] [blame] | 2276 | // dest type. This ensures they get CSE'd. |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2277 | SDValue Vec; |
Anton Korobeynikov | 2ba62ef | 2009-09-08 22:51:43 +0000 | [diff] [blame] | 2278 | SDValue Cst = DAG.getTargetConstant(0xFF, MVT::i8); |
| 2279 | SmallVector<SDValue, 8> Ops; |
| 2280 | MVT TVT; |
| 2281 | |
| 2282 | if (VT.getSizeInBits() == 64) { |
| 2283 | Ops.assign(8, Cst); TVT = MVT::v8i8; |
| 2284 | } else { |
| 2285 | Ops.assign(16, Cst); TVT = MVT::v16i8; |
| 2286 | } |
| 2287 | Vec = DAG.getNode(ISD::BUILD_VECTOR, dl, TVT, &Ops[0], Ops.size()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2288 | |
| 2289 | return DAG.getNode(ISD::BIT_CONVERT, dl, VT, Vec); |
| 2290 | } |
| 2291 | |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 2292 | /// LowerShiftRightParts - Lower SRA_PARTS, which returns two |
| 2293 | /// i32 values and take a 2 x i32 value to shift plus a shift amount. |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 2294 | SDValue ARMTargetLowering::LowerShiftRightParts(SDValue Op, SelectionDAG &DAG) { |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 2295 | assert(Op.getNumOperands() == 3 && "Not a double-shift!"); |
| 2296 | EVT VT = Op.getValueType(); |
| 2297 | unsigned VTBits = VT.getSizeInBits(); |
| 2298 | DebugLoc dl = Op.getDebugLoc(); |
| 2299 | SDValue ShOpLo = Op.getOperand(0); |
| 2300 | SDValue ShOpHi = Op.getOperand(1); |
| 2301 | SDValue ShAmt = Op.getOperand(2); |
| 2302 | SDValue ARMCC; |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 2303 | unsigned Opc = (Op.getOpcode() == ISD::SRA_PARTS) ? ISD::SRA : ISD::SRL; |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 2304 | |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 2305 | assert(Op.getOpcode() == ISD::SRA_PARTS || Op.getOpcode() == ISD::SRL_PARTS); |
| 2306 | |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 2307 | SDValue RevShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, |
| 2308 | DAG.getConstant(VTBits, MVT::i32), ShAmt); |
| 2309 | SDValue Tmp1 = DAG.getNode(ISD::SRL, dl, VT, ShOpLo, ShAmt); |
| 2310 | SDValue ExtraShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, ShAmt, |
| 2311 | DAG.getConstant(VTBits, MVT::i32)); |
| 2312 | SDValue Tmp2 = DAG.getNode(ISD::SHL, dl, VT, ShOpHi, RevShAmt); |
| 2313 | SDValue FalseVal = DAG.getNode(ISD::OR, dl, VT, Tmp1, Tmp2); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 2314 | SDValue TrueVal = DAG.getNode(Opc, dl, VT, ShOpHi, ExtraShAmt); |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 2315 | |
| 2316 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| 2317 | SDValue Cmp = getARMCmp(ExtraShAmt, DAG.getConstant(0, MVT::i32), ISD::SETGE, |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 2318 | ARMCC, DAG, dl); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 2319 | SDValue Hi = DAG.getNode(Opc, dl, VT, ShOpHi, ShAmt); |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 2320 | SDValue Lo = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, ARMCC, |
| 2321 | CCR, Cmp); |
| 2322 | |
| 2323 | SDValue Ops[2] = { Lo, Hi }; |
| 2324 | return DAG.getMergeValues(Ops, 2, dl); |
| 2325 | } |
| 2326 | |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 2327 | /// LowerShiftLeftParts - Lower SHL_PARTS, which returns two |
| 2328 | /// i32 values and take a 2 x i32 value to shift plus a shift amount. |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 2329 | SDValue ARMTargetLowering::LowerShiftLeftParts(SDValue Op, SelectionDAG &DAG) { |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 2330 | assert(Op.getNumOperands() == 3 && "Not a double-shift!"); |
| 2331 | EVT VT = Op.getValueType(); |
| 2332 | unsigned VTBits = VT.getSizeInBits(); |
| 2333 | DebugLoc dl = Op.getDebugLoc(); |
| 2334 | SDValue ShOpLo = Op.getOperand(0); |
| 2335 | SDValue ShOpHi = Op.getOperand(1); |
| 2336 | SDValue ShAmt = Op.getOperand(2); |
| 2337 | SDValue ARMCC; |
| 2338 | |
| 2339 | assert(Op.getOpcode() == ISD::SHL_PARTS); |
| 2340 | SDValue RevShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, |
| 2341 | DAG.getConstant(VTBits, MVT::i32), ShAmt); |
| 2342 | SDValue Tmp1 = DAG.getNode(ISD::SRL, dl, VT, ShOpLo, RevShAmt); |
| 2343 | SDValue ExtraShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, ShAmt, |
| 2344 | DAG.getConstant(VTBits, MVT::i32)); |
| 2345 | SDValue Tmp2 = DAG.getNode(ISD::SHL, dl, VT, ShOpHi, ShAmt); |
| 2346 | SDValue Tmp3 = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ExtraShAmt); |
| 2347 | |
| 2348 | SDValue FalseVal = DAG.getNode(ISD::OR, dl, VT, Tmp1, Tmp2); |
| 2349 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| 2350 | SDValue Cmp = getARMCmp(ExtraShAmt, DAG.getConstant(0, MVT::i32), ISD::SETGE, |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 2351 | ARMCC, DAG, dl); |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 2352 | SDValue Lo = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ShAmt); |
| 2353 | SDValue Hi = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, Tmp3, ARMCC, |
| 2354 | CCR, Cmp); |
| 2355 | |
| 2356 | SDValue Ops[2] = { Lo, Hi }; |
| 2357 | return DAG.getMergeValues(Ops, 2, dl); |
| 2358 | } |
| 2359 | |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 2360 | static SDValue LowerCTTZ(SDNode *N, SelectionDAG &DAG, |
| 2361 | const ARMSubtarget *ST) { |
| 2362 | EVT VT = N->getValueType(0); |
| 2363 | DebugLoc dl = N->getDebugLoc(); |
| 2364 | |
| 2365 | if (!ST->hasV6T2Ops()) |
| 2366 | return SDValue(); |
| 2367 | |
| 2368 | SDValue rbit = DAG.getNode(ARMISD::RBIT, dl, VT, N->getOperand(0)); |
| 2369 | return DAG.getNode(ISD::CTLZ, dl, VT, rbit); |
| 2370 | } |
| 2371 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2372 | static SDValue LowerShift(SDNode *N, SelectionDAG &DAG, |
| 2373 | const ARMSubtarget *ST) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2374 | EVT VT = N->getValueType(0); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2375 | DebugLoc dl = N->getDebugLoc(); |
| 2376 | |
| 2377 | // Lower vector shifts on NEON to use VSHL. |
| 2378 | if (VT.isVector()) { |
| 2379 | assert(ST->hasNEON() && "unexpected vector shift"); |
| 2380 | |
| 2381 | // Left shifts translate directly to the vshiftu intrinsic. |
| 2382 | if (N->getOpcode() == ISD::SHL) |
| 2383 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2384 | DAG.getConstant(Intrinsic::arm_neon_vshiftu, MVT::i32), |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2385 | N->getOperand(0), N->getOperand(1)); |
| 2386 | |
| 2387 | assert((N->getOpcode() == ISD::SRA || |
| 2388 | N->getOpcode() == ISD::SRL) && "unexpected vector shift opcode"); |
| 2389 | |
| 2390 | // NEON uses the same intrinsics for both left and right shifts. For |
| 2391 | // right shifts, the shift amounts are negative, so negate the vector of |
| 2392 | // shift amounts. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2393 | EVT ShiftVT = N->getOperand(1).getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2394 | SDValue NegatedCount = DAG.getNode(ISD::SUB, dl, ShiftVT, |
| 2395 | getZeroVector(ShiftVT, DAG, dl), |
| 2396 | N->getOperand(1)); |
| 2397 | Intrinsic::ID vshiftInt = (N->getOpcode() == ISD::SRA ? |
| 2398 | Intrinsic::arm_neon_vshifts : |
| 2399 | Intrinsic::arm_neon_vshiftu); |
| 2400 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2401 | DAG.getConstant(vshiftInt, MVT::i32), |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2402 | N->getOperand(0), NegatedCount); |
| 2403 | } |
| 2404 | |
Eli Friedman | ce392eb | 2009-08-22 03:13:10 +0000 | [diff] [blame] | 2405 | // We can get here for a node like i32 = ISD::SHL i32, i64 |
| 2406 | if (VT != MVT::i64) |
| 2407 | return SDValue(); |
| 2408 | |
| 2409 | assert((N->getOpcode() == ISD::SRL || N->getOpcode() == ISD::SRA) && |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 2410 | "Unknown shift to lower!"); |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 2411 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 2412 | // We only lower SRA, SRL of 1 here, all others use generic lowering. |
| 2413 | if (!isa<ConstantSDNode>(N->getOperand(1)) || |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2414 | cast<ConstantSDNode>(N->getOperand(1))->getZExtValue() != 1) |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 2415 | return SDValue(); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2416 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 2417 | // If we are in thumb mode, we don't have RRX. |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 2418 | if (ST->isThumb1Only()) return SDValue(); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2419 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 2420 | // Okay, we have a 64-bit SRA or SRL of 1. Lower this to an RRX expr. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2421 | SDValue Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, N->getOperand(0), |
| 2422 | DAG.getConstant(0, MVT::i32)); |
| 2423 | SDValue Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, N->getOperand(0), |
| 2424 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2425 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 2426 | // First, build a SRA_FLAG/SRL_FLAG op, which shifts the top part by one and |
| 2427 | // captures the result into a carry flag. |
| 2428 | unsigned Opc = N->getOpcode() == ISD::SRL ? ARMISD::SRL_FLAG:ARMISD::SRA_FLAG; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2429 | 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] | 2430 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 2431 | // The low part is an ARMISD::RRX operand, which shifts the carry in. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2432 | Lo = DAG.getNode(ARMISD::RRX, dl, MVT::i32, Lo, Hi.getValue(1)); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2433 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 2434 | // Merge the pieces into a single i64 value. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2435 | return DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Lo, Hi); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 2436 | } |
| 2437 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2438 | static SDValue LowerVSETCC(SDValue Op, SelectionDAG &DAG) { |
| 2439 | SDValue TmpOp0, TmpOp1; |
| 2440 | bool Invert = false; |
| 2441 | bool Swap = false; |
| 2442 | unsigned Opc = 0; |
| 2443 | |
| 2444 | SDValue Op0 = Op.getOperand(0); |
| 2445 | SDValue Op1 = Op.getOperand(1); |
| 2446 | SDValue CC = Op.getOperand(2); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2447 | EVT VT = Op.getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2448 | ISD::CondCode SetCCOpcode = cast<CondCodeSDNode>(CC)->get(); |
| 2449 | DebugLoc dl = Op.getDebugLoc(); |
| 2450 | |
| 2451 | if (Op.getOperand(1).getValueType().isFloatingPoint()) { |
| 2452 | switch (SetCCOpcode) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 2453 | default: llvm_unreachable("Illegal FP comparison"); break; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2454 | case ISD::SETUNE: |
| 2455 | case ISD::SETNE: Invert = true; // Fallthrough |
| 2456 | case ISD::SETOEQ: |
| 2457 | case ISD::SETEQ: Opc = ARMISD::VCEQ; break; |
| 2458 | case ISD::SETOLT: |
| 2459 | case ISD::SETLT: Swap = true; // Fallthrough |
| 2460 | case ISD::SETOGT: |
| 2461 | case ISD::SETGT: Opc = ARMISD::VCGT; break; |
| 2462 | case ISD::SETOLE: |
| 2463 | case ISD::SETLE: Swap = true; // Fallthrough |
| 2464 | case ISD::SETOGE: |
| 2465 | case ISD::SETGE: Opc = ARMISD::VCGE; break; |
| 2466 | case ISD::SETUGE: Swap = true; // Fallthrough |
| 2467 | case ISD::SETULE: Invert = true; Opc = ARMISD::VCGT; break; |
| 2468 | case ISD::SETUGT: Swap = true; // Fallthrough |
| 2469 | case ISD::SETULT: Invert = true; Opc = ARMISD::VCGE; break; |
| 2470 | case ISD::SETUEQ: Invert = true; // Fallthrough |
| 2471 | case ISD::SETONE: |
| 2472 | // Expand this to (OLT | OGT). |
| 2473 | TmpOp0 = Op0; |
| 2474 | TmpOp1 = Op1; |
| 2475 | Opc = ISD::OR; |
| 2476 | Op0 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp1, TmpOp0); |
| 2477 | Op1 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp0, TmpOp1); |
| 2478 | break; |
| 2479 | case ISD::SETUO: Invert = true; // Fallthrough |
| 2480 | case ISD::SETO: |
| 2481 | // Expand this to (OLT | OGE). |
| 2482 | TmpOp0 = Op0; |
| 2483 | TmpOp1 = Op1; |
| 2484 | Opc = ISD::OR; |
| 2485 | Op0 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp1, TmpOp0); |
| 2486 | Op1 = DAG.getNode(ARMISD::VCGE, dl, VT, TmpOp0, TmpOp1); |
| 2487 | break; |
| 2488 | } |
| 2489 | } else { |
| 2490 | // Integer comparisons. |
| 2491 | switch (SetCCOpcode) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 2492 | default: llvm_unreachable("Illegal integer comparison"); break; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2493 | case ISD::SETNE: Invert = true; |
| 2494 | case ISD::SETEQ: Opc = ARMISD::VCEQ; break; |
| 2495 | case ISD::SETLT: Swap = true; |
| 2496 | case ISD::SETGT: Opc = ARMISD::VCGT; break; |
| 2497 | case ISD::SETLE: Swap = true; |
| 2498 | case ISD::SETGE: Opc = ARMISD::VCGE; break; |
| 2499 | case ISD::SETULT: Swap = true; |
| 2500 | case ISD::SETUGT: Opc = ARMISD::VCGTU; break; |
| 2501 | case ISD::SETULE: Swap = true; |
| 2502 | case ISD::SETUGE: Opc = ARMISD::VCGEU; break; |
| 2503 | } |
| 2504 | |
Nick Lewycky | 7f6aa2b | 2009-07-08 03:04:38 +0000 | [diff] [blame] | 2505 | // Detect VTST (Vector Test Bits) = icmp ne (and (op0, op1), zero). |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2506 | if (Opc == ARMISD::VCEQ) { |
| 2507 | |
| 2508 | SDValue AndOp; |
| 2509 | if (ISD::isBuildVectorAllZeros(Op1.getNode())) |
| 2510 | AndOp = Op0; |
| 2511 | else if (ISD::isBuildVectorAllZeros(Op0.getNode())) |
| 2512 | AndOp = Op1; |
| 2513 | |
| 2514 | // Ignore bitconvert. |
| 2515 | if (AndOp.getNode() && AndOp.getOpcode() == ISD::BIT_CONVERT) |
| 2516 | AndOp = AndOp.getOperand(0); |
| 2517 | |
| 2518 | if (AndOp.getNode() && AndOp.getOpcode() == ISD::AND) { |
| 2519 | Opc = ARMISD::VTST; |
| 2520 | Op0 = DAG.getNode(ISD::BIT_CONVERT, dl, VT, AndOp.getOperand(0)); |
| 2521 | Op1 = DAG.getNode(ISD::BIT_CONVERT, dl, VT, AndOp.getOperand(1)); |
| 2522 | Invert = !Invert; |
| 2523 | } |
| 2524 | } |
| 2525 | } |
| 2526 | |
| 2527 | if (Swap) |
| 2528 | std::swap(Op0, Op1); |
| 2529 | |
| 2530 | SDValue Result = DAG.getNode(Opc, dl, VT, Op0, Op1); |
| 2531 | |
| 2532 | if (Invert) |
| 2533 | Result = DAG.getNOT(dl, Result, VT); |
| 2534 | |
| 2535 | return Result; |
| 2536 | } |
| 2537 | |
| 2538 | /// isVMOVSplat - Check if the specified splat value corresponds to an immediate |
| 2539 | /// VMOV instruction, and if so, return the constant being splatted. |
| 2540 | static SDValue isVMOVSplat(uint64_t SplatBits, uint64_t SplatUndef, |
| 2541 | unsigned SplatBitSize, SelectionDAG &DAG) { |
| 2542 | switch (SplatBitSize) { |
| 2543 | case 8: |
| 2544 | // Any 1-byte value is OK. |
| 2545 | assert((SplatBits & ~0xff) == 0 && "one byte splat value is too big"); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2546 | return DAG.getTargetConstant(SplatBits, MVT::i8); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2547 | |
| 2548 | case 16: |
| 2549 | // NEON's 16-bit VMOV supports splat values where only one byte is nonzero. |
| 2550 | if ((SplatBits & ~0xff) == 0 || |
| 2551 | (SplatBits & ~0xff00) == 0) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2552 | return DAG.getTargetConstant(SplatBits, MVT::i16); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2553 | break; |
| 2554 | |
| 2555 | case 32: |
| 2556 | // NEON's 32-bit VMOV supports splat values where: |
| 2557 | // * only one byte is nonzero, or |
| 2558 | // * the least significant byte is 0xff and the second byte is nonzero, or |
| 2559 | // * the least significant 2 bytes are 0xff and the third is nonzero. |
| 2560 | if ((SplatBits & ~0xff) == 0 || |
| 2561 | (SplatBits & ~0xff00) == 0 || |
| 2562 | (SplatBits & ~0xff0000) == 0 || |
| 2563 | (SplatBits & ~0xff000000) == 0) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2564 | return DAG.getTargetConstant(SplatBits, MVT::i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2565 | |
| 2566 | if ((SplatBits & ~0xffff) == 0 && |
| 2567 | ((SplatBits | SplatUndef) & 0xff) == 0xff) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2568 | return DAG.getTargetConstant(SplatBits | 0xff, MVT::i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2569 | |
| 2570 | if ((SplatBits & ~0xffffff) == 0 && |
| 2571 | ((SplatBits | SplatUndef) & 0xffff) == 0xffff) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2572 | return DAG.getTargetConstant(SplatBits | 0xffff, MVT::i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2573 | |
| 2574 | // Note: there are a few 32-bit splat values (specifically: 00ffff00, |
| 2575 | // ff000000, ff0000ff, and ffff00ff) that are valid for VMOV.I64 but not |
| 2576 | // VMOV.I32. A (very) minor optimization would be to replicate the value |
| 2577 | // and fall through here to test for a valid 64-bit splat. But, then the |
| 2578 | // caller would also need to check and handle the change in size. |
| 2579 | break; |
| 2580 | |
| 2581 | case 64: { |
| 2582 | // NEON has a 64-bit VMOV splat where each byte is either 0 or 0xff. |
| 2583 | uint64_t BitMask = 0xff; |
| 2584 | uint64_t Val = 0; |
| 2585 | for (int ByteNum = 0; ByteNum < 8; ++ByteNum) { |
| 2586 | if (((SplatBits | SplatUndef) & BitMask) == BitMask) |
| 2587 | Val |= BitMask; |
| 2588 | else if ((SplatBits & BitMask) != 0) |
| 2589 | return SDValue(); |
| 2590 | BitMask <<= 8; |
| 2591 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2592 | return DAG.getTargetConstant(Val, MVT::i64); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2593 | } |
| 2594 | |
| 2595 | default: |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 2596 | llvm_unreachable("unexpected size for isVMOVSplat"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2597 | break; |
| 2598 | } |
| 2599 | |
| 2600 | return SDValue(); |
| 2601 | } |
| 2602 | |
| 2603 | /// getVMOVImm - If this is a build_vector of constants which can be |
| 2604 | /// formed by using a VMOV instruction of the specified element size, |
| 2605 | /// return the constant being splatted. The ByteSize field indicates the |
| 2606 | /// number of bytes of each element [1248]. |
| 2607 | SDValue ARM::getVMOVImm(SDNode *N, unsigned ByteSize, SelectionDAG &DAG) { |
| 2608 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(N); |
| 2609 | APInt SplatBits, SplatUndef; |
| 2610 | unsigned SplatBitSize; |
| 2611 | bool HasAnyUndefs; |
| 2612 | if (! BVN || ! BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, |
| 2613 | HasAnyUndefs, ByteSize * 8)) |
| 2614 | return SDValue(); |
| 2615 | |
| 2616 | if (SplatBitSize > ByteSize * 8) |
| 2617 | return SDValue(); |
| 2618 | |
| 2619 | return isVMOVSplat(SplatBits.getZExtValue(), SplatUndef.getZExtValue(), |
| 2620 | SplatBitSize, DAG); |
| 2621 | } |
| 2622 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 2623 | static bool isVEXTMask(const SmallVectorImpl<int> &M, EVT VT, |
| 2624 | bool &ReverseVEXT, unsigned &Imm) { |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 2625 | unsigned NumElts = VT.getVectorNumElements(); |
| 2626 | ReverseVEXT = false; |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 2627 | Imm = M[0]; |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 2628 | |
| 2629 | // If this is a VEXT shuffle, the immediate value is the index of the first |
| 2630 | // element. The other shuffle indices must be the successive elements after |
| 2631 | // the first one. |
| 2632 | unsigned ExpectedElt = Imm; |
| 2633 | for (unsigned i = 1; i < NumElts; ++i) { |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 2634 | // Increment the expected index. If it wraps around, it may still be |
| 2635 | // a VEXT but the source vectors must be swapped. |
| 2636 | ExpectedElt += 1; |
| 2637 | if (ExpectedElt == NumElts * 2) { |
| 2638 | ExpectedElt = 0; |
| 2639 | ReverseVEXT = true; |
| 2640 | } |
| 2641 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 2642 | if (ExpectedElt != static_cast<unsigned>(M[i])) |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 2643 | return false; |
| 2644 | } |
| 2645 | |
| 2646 | // Adjust the index value if the source operands will be swapped. |
| 2647 | if (ReverseVEXT) |
| 2648 | Imm -= NumElts; |
| 2649 | |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 2650 | return true; |
| 2651 | } |
| 2652 | |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 2653 | /// isVREVMask - Check if a vector shuffle corresponds to a VREV |
| 2654 | /// instruction with the specified blocksize. (The order of the elements |
| 2655 | /// within each block of the vector is reversed.) |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 2656 | static bool isVREVMask(const SmallVectorImpl<int> &M, EVT VT, |
| 2657 | unsigned BlockSize) { |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 2658 | assert((BlockSize==16 || BlockSize==32 || BlockSize==64) && |
| 2659 | "Only possible block sizes for VREV are: 16, 32, 64"); |
| 2660 | |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 2661 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 2662 | if (EltSz == 64) |
| 2663 | return false; |
| 2664 | |
| 2665 | unsigned NumElts = VT.getVectorNumElements(); |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 2666 | unsigned BlockElts = M[0] + 1; |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 2667 | |
| 2668 | if (BlockSize <= EltSz || BlockSize != BlockElts * EltSz) |
| 2669 | return false; |
| 2670 | |
| 2671 | for (unsigned i = 0; i < NumElts; ++i) { |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 2672 | if ((unsigned) M[i] != |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 2673 | (i - i%BlockElts) + (BlockElts - 1 - i%BlockElts)) |
| 2674 | return false; |
| 2675 | } |
| 2676 | |
| 2677 | return true; |
| 2678 | } |
| 2679 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 2680 | static bool isVTRNMask(const SmallVectorImpl<int> &M, EVT VT, |
| 2681 | unsigned &WhichResult) { |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 2682 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 2683 | if (EltSz == 64) |
| 2684 | return false; |
| 2685 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 2686 | unsigned NumElts = VT.getVectorNumElements(); |
| 2687 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 2688 | for (unsigned i = 0; i < NumElts; i += 2) { |
| 2689 | if ((unsigned) M[i] != i + WhichResult || |
| 2690 | (unsigned) M[i+1] != i + NumElts + WhichResult) |
| 2691 | return false; |
| 2692 | } |
| 2693 | return true; |
| 2694 | } |
| 2695 | |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 2696 | /// isVTRN_v_undef_Mask - Special case of isVTRNMask for canonical form of |
| 2697 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 2698 | /// Mask is e.g., <0, 0, 2, 2> instead of <0, 4, 2, 6>. |
| 2699 | static bool isVTRN_v_undef_Mask(const SmallVectorImpl<int> &M, EVT VT, |
| 2700 | unsigned &WhichResult) { |
| 2701 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 2702 | if (EltSz == 64) |
| 2703 | return false; |
| 2704 | |
| 2705 | unsigned NumElts = VT.getVectorNumElements(); |
| 2706 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 2707 | for (unsigned i = 0; i < NumElts; i += 2) { |
| 2708 | if ((unsigned) M[i] != i + WhichResult || |
| 2709 | (unsigned) M[i+1] != i + WhichResult) |
| 2710 | return false; |
| 2711 | } |
| 2712 | return true; |
| 2713 | } |
| 2714 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 2715 | static bool isVUZPMask(const SmallVectorImpl<int> &M, EVT VT, |
| 2716 | unsigned &WhichResult) { |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 2717 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 2718 | if (EltSz == 64) |
| 2719 | return false; |
| 2720 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 2721 | unsigned NumElts = VT.getVectorNumElements(); |
| 2722 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 2723 | for (unsigned i = 0; i != NumElts; ++i) { |
| 2724 | if ((unsigned) M[i] != 2 * i + WhichResult) |
| 2725 | return false; |
| 2726 | } |
| 2727 | |
| 2728 | // VUZP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32. |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 2729 | if (VT.is64BitVector() && EltSz == 32) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 2730 | return false; |
| 2731 | |
| 2732 | return true; |
| 2733 | } |
| 2734 | |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 2735 | /// isVUZP_v_undef_Mask - Special case of isVUZPMask for canonical form of |
| 2736 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 2737 | /// Mask is e.g., <0, 2, 0, 2> instead of <0, 2, 4, 6>, |
| 2738 | static bool isVUZP_v_undef_Mask(const SmallVectorImpl<int> &M, EVT VT, |
| 2739 | unsigned &WhichResult) { |
| 2740 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 2741 | if (EltSz == 64) |
| 2742 | return false; |
| 2743 | |
| 2744 | unsigned Half = VT.getVectorNumElements() / 2; |
| 2745 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 2746 | for (unsigned j = 0; j != 2; ++j) { |
| 2747 | unsigned Idx = WhichResult; |
| 2748 | for (unsigned i = 0; i != Half; ++i) { |
| 2749 | if ((unsigned) M[i + j * Half] != Idx) |
| 2750 | return false; |
| 2751 | Idx += 2; |
| 2752 | } |
| 2753 | } |
| 2754 | |
| 2755 | // VUZP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32. |
| 2756 | if (VT.is64BitVector() && EltSz == 32) |
| 2757 | return false; |
| 2758 | |
| 2759 | return true; |
| 2760 | } |
| 2761 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 2762 | static bool isVZIPMask(const SmallVectorImpl<int> &M, EVT VT, |
| 2763 | unsigned &WhichResult) { |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 2764 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 2765 | if (EltSz == 64) |
| 2766 | return false; |
| 2767 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 2768 | unsigned NumElts = VT.getVectorNumElements(); |
| 2769 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 2770 | unsigned Idx = WhichResult * NumElts / 2; |
| 2771 | for (unsigned i = 0; i != NumElts; i += 2) { |
| 2772 | if ((unsigned) M[i] != Idx || |
| 2773 | (unsigned) M[i+1] != Idx + NumElts) |
| 2774 | return false; |
| 2775 | Idx += 1; |
| 2776 | } |
| 2777 | |
| 2778 | // VZIP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32. |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 2779 | if (VT.is64BitVector() && EltSz == 32) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 2780 | return false; |
| 2781 | |
| 2782 | return true; |
| 2783 | } |
| 2784 | |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 2785 | /// isVZIP_v_undef_Mask - Special case of isVZIPMask for canonical form of |
| 2786 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 2787 | /// Mask is e.g., <0, 0, 1, 1> instead of <0, 4, 1, 5>. |
| 2788 | static bool isVZIP_v_undef_Mask(const SmallVectorImpl<int> &M, EVT VT, |
| 2789 | unsigned &WhichResult) { |
| 2790 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 2791 | if (EltSz == 64) |
| 2792 | return false; |
| 2793 | |
| 2794 | unsigned NumElts = VT.getVectorNumElements(); |
| 2795 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 2796 | unsigned Idx = WhichResult * NumElts / 2; |
| 2797 | for (unsigned i = 0; i != NumElts; i += 2) { |
| 2798 | if ((unsigned) M[i] != Idx || |
| 2799 | (unsigned) M[i+1] != Idx) |
| 2800 | return false; |
| 2801 | Idx += 1; |
| 2802 | } |
| 2803 | |
| 2804 | // VZIP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32. |
| 2805 | if (VT.is64BitVector() && EltSz == 32) |
| 2806 | return false; |
| 2807 | |
| 2808 | return true; |
| 2809 | } |
| 2810 | |
| 2811 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2812 | static SDValue BuildSplat(SDValue Val, EVT VT, SelectionDAG &DAG, DebugLoc dl) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2813 | // Canonicalize all-zeros and all-ones vectors. |
Bob Wilson | d06791f | 2009-08-13 01:57:47 +0000 | [diff] [blame] | 2814 | ConstantSDNode *ConstVal = cast<ConstantSDNode>(Val.getNode()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2815 | if (ConstVal->isNullValue()) |
| 2816 | return getZeroVector(VT, DAG, dl); |
| 2817 | if (ConstVal->isAllOnesValue()) |
| 2818 | return getOnesVector(VT, DAG, dl); |
| 2819 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2820 | EVT CanonicalVT; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2821 | if (VT.is64BitVector()) { |
| 2822 | switch (Val.getValueType().getSizeInBits()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2823 | case 8: CanonicalVT = MVT::v8i8; break; |
| 2824 | case 16: CanonicalVT = MVT::v4i16; break; |
| 2825 | case 32: CanonicalVT = MVT::v2i32; break; |
| 2826 | case 64: CanonicalVT = MVT::v1i64; break; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 2827 | default: llvm_unreachable("unexpected splat element type"); break; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2828 | } |
| 2829 | } else { |
| 2830 | assert(VT.is128BitVector() && "unknown splat vector size"); |
| 2831 | switch (Val.getValueType().getSizeInBits()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2832 | case 8: CanonicalVT = MVT::v16i8; break; |
| 2833 | case 16: CanonicalVT = MVT::v8i16; break; |
| 2834 | case 32: CanonicalVT = MVT::v4i32; break; |
| 2835 | case 64: CanonicalVT = MVT::v2i64; break; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 2836 | default: llvm_unreachable("unexpected splat element type"); break; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2837 | } |
| 2838 | } |
| 2839 | |
| 2840 | // Build a canonical splat for this value. |
| 2841 | SmallVector<SDValue, 8> Ops; |
| 2842 | Ops.assign(CanonicalVT.getVectorNumElements(), Val); |
| 2843 | SDValue Res = DAG.getNode(ISD::BUILD_VECTOR, dl, CanonicalVT, &Ops[0], |
| 2844 | Ops.size()); |
| 2845 | return DAG.getNode(ISD::BIT_CONVERT, dl, VT, Res); |
| 2846 | } |
| 2847 | |
| 2848 | // If this is a case we can't handle, return null and let the default |
| 2849 | // expansion code take care of it. |
| 2850 | static SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) { |
Bob Wilson | d06791f | 2009-08-13 01:57:47 +0000 | [diff] [blame] | 2851 | BuildVectorSDNode *BVN = cast<BuildVectorSDNode>(Op.getNode()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2852 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2853 | EVT VT = Op.getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2854 | |
| 2855 | APInt SplatBits, SplatUndef; |
| 2856 | unsigned SplatBitSize; |
| 2857 | bool HasAnyUndefs; |
| 2858 | if (BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { |
Anton Korobeynikov | 71624cc | 2009-08-29 00:08:18 +0000 | [diff] [blame] | 2859 | if (SplatBitSize <= 64) { |
| 2860 | SDValue Val = isVMOVSplat(SplatBits.getZExtValue(), |
| 2861 | SplatUndef.getZExtValue(), SplatBitSize, DAG); |
| 2862 | if (Val.getNode()) |
| 2863 | return BuildSplat(Val, VT, DAG, dl); |
| 2864 | } |
Bob Wilson | cf661e2 | 2009-07-30 00:31:25 +0000 | [diff] [blame] | 2865 | } |
| 2866 | |
| 2867 | // If there are only 2 elements in a 128-bit vector, insert them into an |
| 2868 | // undef vector. This handles the common case for 128-bit vector argument |
| 2869 | // passing, where the insertions should be translated to subreg accesses |
| 2870 | // with no real instructions. |
| 2871 | if (VT.is128BitVector() && Op.getNumOperands() == 2) { |
| 2872 | SDValue Val = DAG.getUNDEF(VT); |
| 2873 | SDValue Op0 = Op.getOperand(0); |
| 2874 | SDValue Op1 = Op.getOperand(1); |
| 2875 | if (Op0.getOpcode() != ISD::UNDEF) |
| 2876 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, VT, Val, Op0, |
| 2877 | DAG.getIntPtrConstant(0)); |
| 2878 | if (Op1.getOpcode() != ISD::UNDEF) |
| 2879 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, VT, Val, Op1, |
| 2880 | DAG.getIntPtrConstant(1)); |
| 2881 | return Val; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2882 | } |
| 2883 | |
| 2884 | return SDValue(); |
| 2885 | } |
| 2886 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 2887 | /// isShuffleMaskLegal - Targets can use this to indicate that they only |
| 2888 | /// support *some* VECTOR_SHUFFLE operations, those with specific masks. |
| 2889 | /// By default, if a target supports the VECTOR_SHUFFLE node, all mask values |
| 2890 | /// are assumed to be legal. |
| 2891 | bool |
| 2892 | ARMTargetLowering::isShuffleMaskLegal(const SmallVectorImpl<int> &M, |
| 2893 | EVT VT) const { |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 2894 | if (VT.getVectorNumElements() == 4 && |
| 2895 | (VT.is128BitVector() || VT.is64BitVector())) { |
| 2896 | unsigned PFIndexes[4]; |
| 2897 | for (unsigned i = 0; i != 4; ++i) { |
| 2898 | if (M[i] < 0) |
| 2899 | PFIndexes[i] = 8; |
| 2900 | else |
| 2901 | PFIndexes[i] = M[i]; |
| 2902 | } |
| 2903 | |
| 2904 | // Compute the index in the perfect shuffle table. |
| 2905 | unsigned PFTableIndex = |
| 2906 | PFIndexes[0]*9*9*9+PFIndexes[1]*9*9+PFIndexes[2]*9+PFIndexes[3]; |
| 2907 | unsigned PFEntry = PerfectShuffleTable[PFTableIndex]; |
| 2908 | unsigned Cost = (PFEntry >> 30); |
| 2909 | |
| 2910 | if (Cost <= 4) |
| 2911 | return true; |
| 2912 | } |
| 2913 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 2914 | bool ReverseVEXT; |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 2915 | unsigned Imm, WhichResult; |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 2916 | |
| 2917 | return (ShuffleVectorSDNode::isSplatMask(&M[0], VT) || |
| 2918 | isVREVMask(M, VT, 64) || |
| 2919 | isVREVMask(M, VT, 32) || |
| 2920 | isVREVMask(M, VT, 16) || |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 2921 | isVEXTMask(M, VT, ReverseVEXT, Imm) || |
| 2922 | isVTRNMask(M, VT, WhichResult) || |
| 2923 | isVUZPMask(M, VT, WhichResult) || |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 2924 | isVZIPMask(M, VT, WhichResult) || |
| 2925 | isVTRN_v_undef_Mask(M, VT, WhichResult) || |
| 2926 | isVUZP_v_undef_Mask(M, VT, WhichResult) || |
| 2927 | isVZIP_v_undef_Mask(M, VT, WhichResult)); |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 2928 | } |
| 2929 | |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 2930 | /// GeneratePerfectShuffle - Given an entry in the perfect-shuffle table, emit |
| 2931 | /// the specified operations to build the shuffle. |
| 2932 | static SDValue GeneratePerfectShuffle(unsigned PFEntry, SDValue LHS, |
| 2933 | SDValue RHS, SelectionDAG &DAG, |
| 2934 | DebugLoc dl) { |
| 2935 | unsigned OpNum = (PFEntry >> 26) & 0x0F; |
| 2936 | unsigned LHSID = (PFEntry >> 13) & ((1 << 13)-1); |
| 2937 | unsigned RHSID = (PFEntry >> 0) & ((1 << 13)-1); |
| 2938 | |
| 2939 | enum { |
| 2940 | OP_COPY = 0, // Copy, used for things like <u,u,u,3> to say it is <0,1,2,3> |
| 2941 | OP_VREV, |
| 2942 | OP_VDUP0, |
| 2943 | OP_VDUP1, |
| 2944 | OP_VDUP2, |
| 2945 | OP_VDUP3, |
| 2946 | OP_VEXT1, |
| 2947 | OP_VEXT2, |
| 2948 | OP_VEXT3, |
| 2949 | OP_VUZPL, // VUZP, left result |
| 2950 | OP_VUZPR, // VUZP, right result |
| 2951 | OP_VZIPL, // VZIP, left result |
| 2952 | OP_VZIPR, // VZIP, right result |
| 2953 | OP_VTRNL, // VTRN, left result |
| 2954 | OP_VTRNR // VTRN, right result |
| 2955 | }; |
| 2956 | |
| 2957 | if (OpNum == OP_COPY) { |
| 2958 | if (LHSID == (1*9+2)*9+3) return LHS; |
| 2959 | assert(LHSID == ((4*9+5)*9+6)*9+7 && "Illegal OP_COPY!"); |
| 2960 | return RHS; |
| 2961 | } |
| 2962 | |
| 2963 | SDValue OpLHS, OpRHS; |
| 2964 | OpLHS = GeneratePerfectShuffle(PerfectShuffleTable[LHSID], LHS, RHS, DAG, dl); |
| 2965 | OpRHS = GeneratePerfectShuffle(PerfectShuffleTable[RHSID], LHS, RHS, DAG, dl); |
| 2966 | EVT VT = OpLHS.getValueType(); |
| 2967 | |
| 2968 | switch (OpNum) { |
| 2969 | default: llvm_unreachable("Unknown shuffle opcode!"); |
| 2970 | case OP_VREV: |
| 2971 | return DAG.getNode(ARMISD::VREV64, dl, VT, OpLHS); |
| 2972 | case OP_VDUP0: |
| 2973 | case OP_VDUP1: |
| 2974 | case OP_VDUP2: |
| 2975 | case OP_VDUP3: |
| 2976 | return DAG.getNode(ARMISD::VDUPLANE, dl, VT, |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 2977 | OpLHS, DAG.getConstant(OpNum-OP_VDUP0, MVT::i32)); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 2978 | case OP_VEXT1: |
| 2979 | case OP_VEXT2: |
| 2980 | case OP_VEXT3: |
| 2981 | return DAG.getNode(ARMISD::VEXT, dl, VT, |
| 2982 | OpLHS, OpRHS, |
| 2983 | DAG.getConstant(OpNum-OP_VEXT1+1, MVT::i32)); |
| 2984 | case OP_VUZPL: |
| 2985 | case OP_VUZPR: |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 2986 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 2987 | OpLHS, OpRHS).getValue(OpNum-OP_VUZPL); |
| 2988 | case OP_VZIPL: |
| 2989 | case OP_VZIPR: |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 2990 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 2991 | OpLHS, OpRHS).getValue(OpNum-OP_VZIPL); |
| 2992 | case OP_VTRNL: |
| 2993 | case OP_VTRNR: |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 2994 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), |
| 2995 | OpLHS, OpRHS).getValue(OpNum-OP_VTRNL); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 2996 | } |
| 2997 | } |
| 2998 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2999 | static SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) { |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 3000 | SDValue V1 = Op.getOperand(0); |
| 3001 | SDValue V2 = Op.getOperand(1); |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 3002 | DebugLoc dl = Op.getDebugLoc(); |
| 3003 | EVT VT = Op.getValueType(); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 3004 | ShuffleVectorSDNode *SVN = cast<ShuffleVectorSDNode>(Op.getNode()); |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3005 | SmallVector<int, 8> ShuffleMask; |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 3006 | |
Bob Wilson | 2886506 | 2009-08-13 02:13:04 +0000 | [diff] [blame] | 3007 | // Convert shuffles that are directly supported on NEON to target-specific |
| 3008 | // DAG nodes, instead of keeping them as shuffles and matching them again |
| 3009 | // during code selection. This is more efficient and avoids the possibility |
| 3010 | // of inconsistencies between legalization and selection. |
Bob Wilson | bfcbb50 | 2009-08-13 06:01:30 +0000 | [diff] [blame] | 3011 | // FIXME: floating-point vectors should be canonicalized to integer vectors |
| 3012 | // of the same time so that they get CSEd properly. |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3013 | SVN->getMask(ShuffleMask); |
| 3014 | |
| 3015 | if (ShuffleVectorSDNode::isSplatMask(&ShuffleMask[0], VT)) { |
Bob Wilson | 0ce3710 | 2009-08-14 05:08:32 +0000 | [diff] [blame] | 3016 | int Lane = SVN->getSplatIndex(); |
Anton Korobeynikov | 2ae0eec | 2009-11-02 00:12:06 +0000 | [diff] [blame] | 3017 | // If this is undef splat, generate it via "just" vdup, if possible. |
| 3018 | if (Lane == -1) Lane = 0; |
| 3019 | |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 3020 | if (Lane == 0 && V1.getOpcode() == ISD::SCALAR_TO_VECTOR) { |
| 3021 | return DAG.getNode(ARMISD::VDUP, dl, VT, V1.getOperand(0)); |
Bob Wilson | c1d287b | 2009-08-14 05:13:08 +0000 | [diff] [blame] | 3022 | } |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 3023 | return DAG.getNode(ARMISD::VDUPLANE, dl, VT, V1, |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3024 | DAG.getConstant(Lane, MVT::i32)); |
Bob Wilson | 0ce3710 | 2009-08-14 05:08:32 +0000 | [diff] [blame] | 3025 | } |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3026 | |
| 3027 | bool ReverseVEXT; |
| 3028 | unsigned Imm; |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3029 | if (isVEXTMask(ShuffleMask, VT, ReverseVEXT, Imm)) { |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3030 | if (ReverseVEXT) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3031 | std::swap(V1, V2); |
| 3032 | return DAG.getNode(ARMISD::VEXT, dl, VT, V1, V2, |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3033 | DAG.getConstant(Imm, MVT::i32)); |
| 3034 | } |
| 3035 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3036 | if (isVREVMask(ShuffleMask, VT, 64)) |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 3037 | return DAG.getNode(ARMISD::VREV64, dl, VT, V1); |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3038 | if (isVREVMask(ShuffleMask, VT, 32)) |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 3039 | return DAG.getNode(ARMISD::VREV32, dl, VT, V1); |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3040 | if (isVREVMask(ShuffleMask, VT, 16)) |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 3041 | return DAG.getNode(ARMISD::VREV16, dl, VT, V1); |
| 3042 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3043 | // Check for Neon shuffles that modify both input vectors in place. |
| 3044 | // If both results are used, i.e., if there are two shuffles with the same |
| 3045 | // source operands and with masks corresponding to both results of one of |
| 3046 | // these operations, DAG memoization will ensure that a single node is |
| 3047 | // used for both shuffles. |
| 3048 | unsigned WhichResult; |
| 3049 | if (isVTRNMask(ShuffleMask, VT, WhichResult)) |
| 3050 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), |
| 3051 | V1, V2).getValue(WhichResult); |
| 3052 | if (isVUZPMask(ShuffleMask, VT, WhichResult)) |
| 3053 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), |
| 3054 | V1, V2).getValue(WhichResult); |
| 3055 | if (isVZIPMask(ShuffleMask, VT, WhichResult)) |
| 3056 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), |
| 3057 | V1, V2).getValue(WhichResult); |
| 3058 | |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3059 | if (isVTRN_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 3060 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), |
| 3061 | V1, V1).getValue(WhichResult); |
| 3062 | if (isVUZP_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 3063 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), |
| 3064 | V1, V1).getValue(WhichResult); |
| 3065 | if (isVZIP_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 3066 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), |
| 3067 | V1, V1).getValue(WhichResult); |
| 3068 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3069 | // If the shuffle is not directly supported and it has 4 elements, use |
| 3070 | // the PerfectShuffle-generated table to synthesize it from other shuffles. |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 3071 | if (VT.getVectorNumElements() == 4 && |
| 3072 | (VT.is128BitVector() || VT.is64BitVector())) { |
| 3073 | unsigned PFIndexes[4]; |
| 3074 | for (unsigned i = 0; i != 4; ++i) { |
| 3075 | if (ShuffleMask[i] < 0) |
| 3076 | PFIndexes[i] = 8; |
| 3077 | else |
| 3078 | PFIndexes[i] = ShuffleMask[i]; |
| 3079 | } |
| 3080 | |
| 3081 | // Compute the index in the perfect shuffle table. |
| 3082 | unsigned PFTableIndex = |
| 3083 | PFIndexes[0]*9*9*9+PFIndexes[1]*9*9+PFIndexes[2]*9+PFIndexes[3]; |
| 3084 | |
| 3085 | unsigned PFEntry = PerfectShuffleTable[PFTableIndex]; |
| 3086 | unsigned Cost = (PFEntry >> 30); |
| 3087 | |
| 3088 | if (Cost <= 4) |
| 3089 | return GeneratePerfectShuffle(PFEntry, V1, V2, DAG, dl); |
| 3090 | } |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 3091 | |
Bob Wilson | 22cac0d | 2009-08-14 05:16:33 +0000 | [diff] [blame] | 3092 | return SDValue(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3093 | } |
| 3094 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3095 | static SDValue LowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3096 | EVT VT = Op.getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3097 | DebugLoc dl = Op.getDebugLoc(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3098 | SDValue Vec = Op.getOperand(0); |
| 3099 | SDValue Lane = Op.getOperand(1); |
Bob Wilson | 934f98b | 2009-10-15 23:12:05 +0000 | [diff] [blame] | 3100 | assert(VT == MVT::i32 && |
| 3101 | Vec.getValueType().getVectorElementType().getSizeInBits() < 32 && |
| 3102 | "unexpected type for custom-lowering vector extract"); |
| 3103 | return DAG.getNode(ARMISD::VGETLANEu, dl, MVT::i32, Vec, Lane); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3104 | } |
| 3105 | |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 3106 | static SDValue LowerCONCAT_VECTORS(SDValue Op, SelectionDAG &DAG) { |
| 3107 | // The only time a CONCAT_VECTORS operation can have legal types is when |
| 3108 | // two 64-bit vectors are concatenated to a 128-bit vector. |
| 3109 | assert(Op.getValueType().is128BitVector() && Op.getNumOperands() == 2 && |
| 3110 | "unexpected CONCAT_VECTORS"); |
| 3111 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3112 | SDValue Val = DAG.getUNDEF(MVT::v2f64); |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 3113 | SDValue Op0 = Op.getOperand(0); |
| 3114 | SDValue Op1 = Op.getOperand(1); |
| 3115 | if (Op0.getOpcode() != ISD::UNDEF) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3116 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Val, |
| 3117 | DAG.getNode(ISD::BIT_CONVERT, dl, MVT::f64, Op0), |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 3118 | DAG.getIntPtrConstant(0)); |
| 3119 | if (Op1.getOpcode() != ISD::UNDEF) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3120 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Val, |
| 3121 | DAG.getNode(ISD::BIT_CONVERT, dl, MVT::f64, Op1), |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 3122 | DAG.getIntPtrConstant(1)); |
| 3123 | return DAG.getNode(ISD::BIT_CONVERT, dl, Op.getValueType(), Val); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3124 | } |
| 3125 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3126 | SDValue ARMTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3127 | switch (Op.getOpcode()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 3128 | default: llvm_unreachable("Don't know how to custom lower this!"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3129 | case ISD::ConstantPool: return LowerConstantPool(Op, DAG); |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 3130 | case ISD::BlockAddress: return LowerBlockAddress(Op, DAG); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 3131 | case ISD::GlobalAddress: |
| 3132 | return Subtarget->isTargetDarwin() ? LowerGlobalAddressDarwin(Op, DAG) : |
| 3133 | LowerGlobalAddressELF(Op, DAG); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 3134 | case ISD::GlobalTLSAddress: return LowerGlobalTLSAddress(Op, DAG); |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 3135 | case ISD::SELECT_CC: return LowerSELECT_CC(Op, DAG); |
| 3136 | case ISD::BR_CC: return LowerBR_CC(Op, DAG); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3137 | case ISD::BR_JT: return LowerBR_JT(Op, DAG); |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 3138 | case ISD::DYNAMIC_STACKALLOC: return LowerDYNAMIC_STACKALLOC(Op, DAG); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3139 | case ISD::VASTART: return LowerVASTART(Op, DAG, VarArgsFrameIndex); |
Jim Grosbach | 7c03dbd | 2009-12-14 21:24:16 +0000 | [diff] [blame] | 3140 | case ISD::MEMBARRIER: return LowerMEMBARRIER(Op, DAG, Subtarget); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3141 | case ISD::SINT_TO_FP: |
| 3142 | case ISD::UINT_TO_FP: return LowerINT_TO_FP(Op, DAG); |
| 3143 | case ISD::FP_TO_SINT: |
| 3144 | case ISD::FP_TO_UINT: return LowerFP_TO_INT(Op, DAG); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3145 | case ISD::FCOPYSIGN: return LowerFCOPYSIGN(Op, DAG); |
Nate Begeman | bcc5f36 | 2007-01-29 22:58:52 +0000 | [diff] [blame] | 3146 | case ISD::RETURNADDR: break; |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3147 | case ISD::FRAMEADDR: return LowerFRAMEADDR(Op, DAG); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 3148 | case ISD::GLOBAL_OFFSET_TABLE: return LowerGLOBAL_OFFSET_TABLE(Op, DAG); |
Jim Grosbach | a87ded2 | 2010-02-08 23:22:00 +0000 | [diff] [blame] | 3149 | case ISD::INTRINSIC_WO_CHAIN: return LowerINTRINSIC_WO_CHAIN(Op, DAG, |
| 3150 | Subtarget); |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 3151 | case ISD::BIT_CONVERT: return ExpandBIT_CONVERT(Op.getNode(), DAG); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3152 | case ISD::SHL: |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3153 | case ISD::SRL: |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3154 | case ISD::SRA: return LowerShift(Op.getNode(), DAG, Subtarget); |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 3155 | case ISD::SHL_PARTS: return LowerShiftLeftParts(Op, DAG); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 3156 | case ISD::SRL_PARTS: |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 3157 | case ISD::SRA_PARTS: return LowerShiftRightParts(Op, DAG); |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 3158 | case ISD::CTTZ: return LowerCTTZ(Op.getNode(), DAG, Subtarget); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3159 | case ISD::VSETCC: return LowerVSETCC(Op, DAG); |
| 3160 | case ISD::BUILD_VECTOR: return LowerBUILD_VECTOR(Op, DAG); |
| 3161 | case ISD::VECTOR_SHUFFLE: return LowerVECTOR_SHUFFLE(Op, DAG); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3162 | case ISD::EXTRACT_VECTOR_ELT: return LowerEXTRACT_VECTOR_ELT(Op, DAG); |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 3163 | case ISD::CONCAT_VECTORS: return LowerCONCAT_VECTORS(Op, DAG); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3164 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3165 | return SDValue(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3166 | } |
| 3167 | |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 3168 | /// ReplaceNodeResults - Replace the results of node with an illegal result |
| 3169 | /// type with new values built out of custom code. |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 3170 | void ARMTargetLowering::ReplaceNodeResults(SDNode *N, |
| 3171 | SmallVectorImpl<SDValue>&Results, |
| 3172 | SelectionDAG &DAG) { |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 3173 | SDValue Res; |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3174 | switch (N->getOpcode()) { |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 3175 | default: |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 3176 | llvm_unreachable("Don't know how to custom expand this!"); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 3177 | break; |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 3178 | case ISD::BIT_CONVERT: |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 3179 | Res = ExpandBIT_CONVERT(N, DAG); |
| 3180 | break; |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3181 | case ISD::SRL: |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 3182 | case ISD::SRA: |
| 3183 | Res = LowerShift(N, DAG, Subtarget); |
| 3184 | break; |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 3185 | } |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 3186 | if (Res.getNode()) |
| 3187 | Results.push_back(Res); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3188 | } |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3189 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3190 | //===----------------------------------------------------------------------===// |
| 3191 | // ARM Scheduler Hooks |
| 3192 | //===----------------------------------------------------------------------===// |
| 3193 | |
| 3194 | MachineBasicBlock * |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 3195 | ARMTargetLowering::EmitAtomicCmpSwap(MachineInstr *MI, |
| 3196 | MachineBasicBlock *BB, |
| 3197 | unsigned Size) const { |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 3198 | unsigned dest = MI->getOperand(0).getReg(); |
| 3199 | unsigned ptr = MI->getOperand(1).getReg(); |
| 3200 | unsigned oldval = MI->getOperand(2).getReg(); |
| 3201 | unsigned newval = MI->getOperand(3).getReg(); |
| 3202 | unsigned scratch = BB->getParent()->getRegInfo() |
| 3203 | .createVirtualRegister(ARM::GPRRegisterClass); |
| 3204 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 3205 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 3206 | bool isThumb2 = Subtarget->isThumb2(); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 3207 | |
| 3208 | unsigned ldrOpc, strOpc; |
| 3209 | switch (Size) { |
| 3210 | default: llvm_unreachable("unsupported size for AtomicCmpSwap!"); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 3211 | case 1: |
| 3212 | ldrOpc = isThumb2 ? ARM::t2LDREXB : ARM::LDREXB; |
| 3213 | strOpc = isThumb2 ? ARM::t2LDREXB : ARM::STREXB; |
| 3214 | break; |
| 3215 | case 2: |
| 3216 | ldrOpc = isThumb2 ? ARM::t2LDREXH : ARM::LDREXH; |
| 3217 | strOpc = isThumb2 ? ARM::t2STREXH : ARM::STREXH; |
| 3218 | break; |
| 3219 | case 4: |
| 3220 | ldrOpc = isThumb2 ? ARM::t2LDREX : ARM::LDREX; |
| 3221 | strOpc = isThumb2 ? ARM::t2STREX : ARM::STREX; |
| 3222 | break; |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 3223 | } |
| 3224 | |
| 3225 | MachineFunction *MF = BB->getParent(); |
| 3226 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 3227 | MachineFunction::iterator It = BB; |
| 3228 | ++It; // insert the new blocks after the current block |
| 3229 | |
| 3230 | MachineBasicBlock *loop1MBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 3231 | MachineBasicBlock *loop2MBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 3232 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 3233 | MF->insert(It, loop1MBB); |
| 3234 | MF->insert(It, loop2MBB); |
| 3235 | MF->insert(It, exitMBB); |
| 3236 | exitMBB->transferSuccessors(BB); |
| 3237 | |
| 3238 | // thisMBB: |
| 3239 | // ... |
| 3240 | // fallthrough --> loop1MBB |
| 3241 | BB->addSuccessor(loop1MBB); |
| 3242 | |
| 3243 | // loop1MBB: |
| 3244 | // ldrex dest, [ptr] |
| 3245 | // cmp dest, oldval |
| 3246 | // bne exitMBB |
| 3247 | BB = loop1MBB; |
| 3248 | AddDefaultPred(BuildMI(BB, dl, TII->get(ldrOpc), dest).addReg(ptr)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 3249 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 3250 | .addReg(dest).addReg(oldval)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 3251 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 3252 | .addMBB(exitMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 3253 | BB->addSuccessor(loop2MBB); |
| 3254 | BB->addSuccessor(exitMBB); |
| 3255 | |
| 3256 | // loop2MBB: |
| 3257 | // strex scratch, newval, [ptr] |
| 3258 | // cmp scratch, #0 |
| 3259 | // bne loop1MBB |
| 3260 | BB = loop2MBB; |
| 3261 | AddDefaultPred(BuildMI(BB, dl, TII->get(strOpc), scratch).addReg(newval) |
| 3262 | .addReg(ptr)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 3263 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 3264 | .addReg(scratch).addImm(0)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 3265 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 3266 | .addMBB(loop1MBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 3267 | BB->addSuccessor(loop1MBB); |
| 3268 | BB->addSuccessor(exitMBB); |
| 3269 | |
| 3270 | // exitMBB: |
| 3271 | // ... |
| 3272 | BB = exitMBB; |
Jim Grosbach | 5efaed3 | 2010-01-15 00:18:34 +0000 | [diff] [blame] | 3273 | |
| 3274 | MF->DeleteMachineInstr(MI); // The instruction is gone now. |
| 3275 | |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 3276 | return BB; |
| 3277 | } |
| 3278 | |
| 3279 | MachineBasicBlock * |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 3280 | ARMTargetLowering::EmitAtomicBinary(MachineInstr *MI, MachineBasicBlock *BB, |
| 3281 | unsigned Size, unsigned BinOpcode) const { |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 3282 | // This also handles ATOMIC_SWAP, indicated by BinOpcode==0. |
| 3283 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 3284 | |
| 3285 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
Jim Grosbach | 867bbbf | 2010-01-15 00:22:18 +0000 | [diff] [blame] | 3286 | MachineFunction *MF = BB->getParent(); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 3287 | MachineFunction::iterator It = BB; |
| 3288 | ++It; |
| 3289 | |
| 3290 | unsigned dest = MI->getOperand(0).getReg(); |
| 3291 | unsigned ptr = MI->getOperand(1).getReg(); |
| 3292 | unsigned incr = MI->getOperand(2).getReg(); |
| 3293 | DebugLoc dl = MI->getDebugLoc(); |
Rafael Espindola | fda60d3 | 2009-12-18 16:59:39 +0000 | [diff] [blame] | 3294 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 3295 | bool isThumb2 = Subtarget->isThumb2(); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 3296 | unsigned ldrOpc, strOpc; |
| 3297 | switch (Size) { |
| 3298 | default: llvm_unreachable("unsupported size for AtomicCmpSwap!"); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 3299 | case 1: |
| 3300 | ldrOpc = isThumb2 ? ARM::t2LDREXB : ARM::LDREXB; |
Jakob Stoklund Olesen | 15913c9 | 2010-01-13 19:54:39 +0000 | [diff] [blame] | 3301 | strOpc = isThumb2 ? ARM::t2STREXB : ARM::STREXB; |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 3302 | break; |
| 3303 | case 2: |
| 3304 | ldrOpc = isThumb2 ? ARM::t2LDREXH : ARM::LDREXH; |
| 3305 | strOpc = isThumb2 ? ARM::t2STREXH : ARM::STREXH; |
| 3306 | break; |
| 3307 | case 4: |
| 3308 | ldrOpc = isThumb2 ? ARM::t2LDREX : ARM::LDREX; |
| 3309 | strOpc = isThumb2 ? ARM::t2STREX : ARM::STREX; |
| 3310 | break; |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 3311 | } |
| 3312 | |
Jim Grosbach | 867bbbf | 2010-01-15 00:22:18 +0000 | [diff] [blame] | 3313 | MachineBasicBlock *loopMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 3314 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 3315 | MF->insert(It, loopMBB); |
| 3316 | MF->insert(It, exitMBB); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 3317 | exitMBB->transferSuccessors(BB); |
| 3318 | |
Jim Grosbach | 867bbbf | 2010-01-15 00:22:18 +0000 | [diff] [blame] | 3319 | MachineRegisterInfo &RegInfo = MF->getRegInfo(); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 3320 | unsigned scratch = RegInfo.createVirtualRegister(ARM::GPRRegisterClass); |
| 3321 | unsigned scratch2 = (!BinOpcode) ? incr : |
| 3322 | RegInfo.createVirtualRegister(ARM::GPRRegisterClass); |
| 3323 | |
| 3324 | // thisMBB: |
| 3325 | // ... |
| 3326 | // fallthrough --> loopMBB |
| 3327 | BB->addSuccessor(loopMBB); |
| 3328 | |
| 3329 | // loopMBB: |
| 3330 | // ldrex dest, ptr |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 3331 | // <binop> scratch2, dest, incr |
| 3332 | // strex scratch, scratch2, ptr |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 3333 | // cmp scratch, #0 |
| 3334 | // bne- loopMBB |
| 3335 | // fallthrough --> exitMBB |
| 3336 | BB = loopMBB; |
| 3337 | AddDefaultPred(BuildMI(BB, dl, TII->get(ldrOpc), dest).addReg(ptr)); |
Jim Grosbach | c67b556 | 2009-12-15 00:12:35 +0000 | [diff] [blame] | 3338 | if (BinOpcode) { |
| 3339 | // operand order needs to go the other way for NAND |
| 3340 | if (BinOpcode == ARM::BICrr || BinOpcode == ARM::t2BICrr) |
| 3341 | AddDefaultPred(BuildMI(BB, dl, TII->get(BinOpcode), scratch2). |
| 3342 | addReg(incr).addReg(dest)).addReg(0); |
| 3343 | else |
| 3344 | AddDefaultPred(BuildMI(BB, dl, TII->get(BinOpcode), scratch2). |
| 3345 | addReg(dest).addReg(incr)).addReg(0); |
| 3346 | } |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 3347 | |
| 3348 | AddDefaultPred(BuildMI(BB, dl, TII->get(strOpc), scratch).addReg(scratch2) |
| 3349 | .addReg(ptr)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 3350 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 3351 | .addReg(scratch).addImm(0)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 3352 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 3353 | .addMBB(loopMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 3354 | |
| 3355 | BB->addSuccessor(loopMBB); |
| 3356 | BB->addSuccessor(exitMBB); |
| 3357 | |
| 3358 | // exitMBB: |
| 3359 | // ... |
| 3360 | BB = exitMBB; |
Evan Cheng | 102ebf1 | 2009-12-21 19:53:39 +0000 | [diff] [blame] | 3361 | |
Jim Grosbach | 867bbbf | 2010-01-15 00:22:18 +0000 | [diff] [blame] | 3362 | MF->DeleteMachineInstr(MI); // The instruction is gone now. |
Evan Cheng | 102ebf1 | 2009-12-21 19:53:39 +0000 | [diff] [blame] | 3363 | |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 3364 | return BB; |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 3365 | } |
| 3366 | |
| 3367 | MachineBasicBlock * |
Evan Cheng | ff9b373 | 2008-01-30 18:18:23 +0000 | [diff] [blame] | 3368 | ARMTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI, |
Evan Cheng | fb2e752 | 2009-09-18 21:02:19 +0000 | [diff] [blame] | 3369 | MachineBasicBlock *BB, |
| 3370 | DenseMap<MachineBasicBlock*, MachineBasicBlock*> *EM) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3371 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
Dale Johannesen | b672840 | 2009-02-13 02:25:56 +0000 | [diff] [blame] | 3372 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 3373 | bool isThumb2 = Subtarget->isThumb2(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3374 | switch (MI->getOpcode()) { |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 3375 | default: |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 3376 | MI->dump(); |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 3377 | llvm_unreachable("Unexpected instr type to insert"); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 3378 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 3379 | case ARM::ATOMIC_LOAD_ADD_I8: |
| 3380 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr); |
| 3381 | case ARM::ATOMIC_LOAD_ADD_I16: |
| 3382 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr); |
| 3383 | case ARM::ATOMIC_LOAD_ADD_I32: |
| 3384 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 3385 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 3386 | case ARM::ATOMIC_LOAD_AND_I8: |
| 3387 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
| 3388 | case ARM::ATOMIC_LOAD_AND_I16: |
| 3389 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
| 3390 | case ARM::ATOMIC_LOAD_AND_I32: |
| 3391 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 3392 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 3393 | case ARM::ATOMIC_LOAD_OR_I8: |
| 3394 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
| 3395 | case ARM::ATOMIC_LOAD_OR_I16: |
| 3396 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
| 3397 | case ARM::ATOMIC_LOAD_OR_I32: |
| 3398 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 3399 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 3400 | case ARM::ATOMIC_LOAD_XOR_I8: |
| 3401 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
| 3402 | case ARM::ATOMIC_LOAD_XOR_I16: |
| 3403 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
| 3404 | case ARM::ATOMIC_LOAD_XOR_I32: |
| 3405 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 3406 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 3407 | case ARM::ATOMIC_LOAD_NAND_I8: |
| 3408 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2BICrr : ARM::BICrr); |
| 3409 | case ARM::ATOMIC_LOAD_NAND_I16: |
| 3410 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2BICrr : ARM::BICrr); |
| 3411 | case ARM::ATOMIC_LOAD_NAND_I32: |
| 3412 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2BICrr : ARM::BICrr); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 3413 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 3414 | case ARM::ATOMIC_LOAD_SUB_I8: |
| 3415 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr); |
| 3416 | case ARM::ATOMIC_LOAD_SUB_I16: |
| 3417 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr); |
| 3418 | case ARM::ATOMIC_LOAD_SUB_I32: |
| 3419 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 3420 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 3421 | case ARM::ATOMIC_SWAP_I8: return EmitAtomicBinary(MI, BB, 1, 0); |
| 3422 | case ARM::ATOMIC_SWAP_I16: return EmitAtomicBinary(MI, BB, 2, 0); |
| 3423 | case ARM::ATOMIC_SWAP_I32: return EmitAtomicBinary(MI, BB, 4, 0); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 3424 | |
| 3425 | case ARM::ATOMIC_CMP_SWAP_I8: return EmitAtomicCmpSwap(MI, BB, 1); |
| 3426 | case ARM::ATOMIC_CMP_SWAP_I16: return EmitAtomicCmpSwap(MI, BB, 2); |
| 3427 | case ARM::ATOMIC_CMP_SWAP_I32: return EmitAtomicCmpSwap(MI, BB, 4); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 3428 | |
Evan Cheng | 007ea27 | 2009-08-12 05:17:19 +0000 | [diff] [blame] | 3429 | case ARM::tMOVCCr_pseudo: { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3430 | // To "insert" a SELECT_CC instruction, we actually have to insert the |
| 3431 | // diamond control-flow pattern. The incoming instruction knows the |
| 3432 | // destination vreg to set, the condition code register to branch on, the |
| 3433 | // true/false values to select between, and a branch opcode to use. |
| 3434 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 3435 | MachineFunction::iterator It = BB; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3436 | ++It; |
| 3437 | |
| 3438 | // thisMBB: |
| 3439 | // ... |
| 3440 | // TrueVal = ... |
| 3441 | // cmpTY ccX, r1, r2 |
| 3442 | // bCC copy1MBB |
| 3443 | // fallthrough --> copy0MBB |
| 3444 | MachineBasicBlock *thisMBB = BB; |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 3445 | MachineFunction *F = BB->getParent(); |
| 3446 | MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB); |
| 3447 | MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB); |
Dale Johannesen | b672840 | 2009-02-13 02:25:56 +0000 | [diff] [blame] | 3448 | BuildMI(BB, dl, TII->get(ARM::tBcc)).addMBB(sinkMBB) |
Evan Cheng | 0e1d379 | 2007-07-05 07:18:20 +0000 | [diff] [blame] | 3449 | .addImm(MI->getOperand(3).getImm()).addReg(MI->getOperand(4).getReg()); |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 3450 | F->insert(It, copy0MBB); |
| 3451 | F->insert(It, sinkMBB); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3452 | // Update machine-CFG edges by first adding all successors of the current |
| 3453 | // block to the new block which will contain the Phi node for the select. |
Evan Cheng | ce31910 | 2009-09-19 09:51:03 +0000 | [diff] [blame] | 3454 | // Also inform sdisel of the edge changes. |
| 3455 | for (MachineBasicBlock::succ_iterator I = BB->succ_begin(), |
| 3456 | E = BB->succ_end(); I != E; ++I) { |
| 3457 | EM->insert(std::make_pair(*I, sinkMBB)); |
| 3458 | sinkMBB->addSuccessor(*I); |
| 3459 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3460 | // Next, remove all successors of the current block, and add the true |
| 3461 | // and fallthrough blocks as its successors. |
Evan Cheng | ce31910 | 2009-09-19 09:51:03 +0000 | [diff] [blame] | 3462 | while (!BB->succ_empty()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3463 | BB->removeSuccessor(BB->succ_begin()); |
| 3464 | BB->addSuccessor(copy0MBB); |
| 3465 | BB->addSuccessor(sinkMBB); |
| 3466 | |
| 3467 | // copy0MBB: |
| 3468 | // %FalseValue = ... |
| 3469 | // # fallthrough to sinkMBB |
| 3470 | BB = copy0MBB; |
| 3471 | |
| 3472 | // Update machine-CFG edges |
| 3473 | BB->addSuccessor(sinkMBB); |
| 3474 | |
| 3475 | // sinkMBB: |
| 3476 | // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ] |
| 3477 | // ... |
| 3478 | BB = sinkMBB; |
Dale Johannesen | b672840 | 2009-02-13 02:25:56 +0000 | [diff] [blame] | 3479 | BuildMI(BB, dl, TII->get(ARM::PHI), MI->getOperand(0).getReg()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3480 | .addReg(MI->getOperand(1).getReg()).addMBB(copy0MBB) |
| 3481 | .addReg(MI->getOperand(2).getReg()).addMBB(thisMBB); |
| 3482 | |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 3483 | F->DeleteMachineInstr(MI); // The pseudo instruction is gone now. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3484 | return BB; |
| 3485 | } |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 3486 | |
| 3487 | case ARM::tANDsp: |
| 3488 | case ARM::tADDspr_: |
| 3489 | case ARM::tSUBspi_: |
| 3490 | case ARM::t2SUBrSPi_: |
| 3491 | case ARM::t2SUBrSPi12_: |
| 3492 | case ARM::t2SUBrSPs_: { |
| 3493 | MachineFunction *MF = BB->getParent(); |
| 3494 | unsigned DstReg = MI->getOperand(0).getReg(); |
| 3495 | unsigned SrcReg = MI->getOperand(1).getReg(); |
| 3496 | bool DstIsDead = MI->getOperand(0).isDead(); |
| 3497 | bool SrcIsKill = MI->getOperand(1).isKill(); |
| 3498 | |
| 3499 | if (SrcReg != ARM::SP) { |
| 3500 | // Copy the source to SP from virtual register. |
| 3501 | const TargetRegisterClass *RC = MF->getRegInfo().getRegClass(SrcReg); |
| 3502 | unsigned CopyOpc = (RC == ARM::tGPRRegisterClass) |
| 3503 | ? ARM::tMOVtgpr2gpr : ARM::tMOVgpr2gpr; |
| 3504 | BuildMI(BB, dl, TII->get(CopyOpc), ARM::SP) |
| 3505 | .addReg(SrcReg, getKillRegState(SrcIsKill)); |
| 3506 | } |
| 3507 | |
| 3508 | unsigned OpOpc = 0; |
| 3509 | bool NeedPred = false, NeedCC = false, NeedOp3 = false; |
| 3510 | switch (MI->getOpcode()) { |
| 3511 | default: |
| 3512 | llvm_unreachable("Unexpected pseudo instruction!"); |
| 3513 | case ARM::tANDsp: |
| 3514 | OpOpc = ARM::tAND; |
| 3515 | NeedPred = true; |
| 3516 | break; |
| 3517 | case ARM::tADDspr_: |
| 3518 | OpOpc = ARM::tADDspr; |
| 3519 | break; |
| 3520 | case ARM::tSUBspi_: |
| 3521 | OpOpc = ARM::tSUBspi; |
| 3522 | break; |
| 3523 | case ARM::t2SUBrSPi_: |
| 3524 | OpOpc = ARM::t2SUBrSPi; |
| 3525 | NeedPred = true; NeedCC = true; |
| 3526 | break; |
| 3527 | case ARM::t2SUBrSPi12_: |
| 3528 | OpOpc = ARM::t2SUBrSPi12; |
| 3529 | NeedPred = true; |
| 3530 | break; |
| 3531 | case ARM::t2SUBrSPs_: |
| 3532 | OpOpc = ARM::t2SUBrSPs; |
| 3533 | NeedPred = true; NeedCC = true; NeedOp3 = true; |
| 3534 | break; |
| 3535 | } |
| 3536 | MachineInstrBuilder MIB = BuildMI(BB, dl, TII->get(OpOpc), ARM::SP); |
| 3537 | if (OpOpc == ARM::tAND) |
| 3538 | AddDefaultT1CC(MIB); |
| 3539 | MIB.addReg(ARM::SP); |
| 3540 | MIB.addOperand(MI->getOperand(2)); |
| 3541 | if (NeedOp3) |
| 3542 | MIB.addOperand(MI->getOperand(3)); |
| 3543 | if (NeedPred) |
| 3544 | AddDefaultPred(MIB); |
| 3545 | if (NeedCC) |
| 3546 | AddDefaultCC(MIB); |
| 3547 | |
| 3548 | // Copy the result from SP to virtual register. |
| 3549 | const TargetRegisterClass *RC = MF->getRegInfo().getRegClass(DstReg); |
| 3550 | unsigned CopyOpc = (RC == ARM::tGPRRegisterClass) |
| 3551 | ? ARM::tMOVgpr2tgpr : ARM::tMOVgpr2gpr; |
| 3552 | BuildMI(BB, dl, TII->get(CopyOpc)) |
| 3553 | .addReg(DstReg, getDefRegState(true) | getDeadRegState(DstIsDead)) |
| 3554 | .addReg(ARM::SP); |
| 3555 | MF->DeleteMachineInstr(MI); // The pseudo instruction is gone now. |
| 3556 | return BB; |
| 3557 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3558 | } |
| 3559 | } |
| 3560 | |
| 3561 | //===----------------------------------------------------------------------===// |
| 3562 | // ARM Optimization Hooks |
| 3563 | //===----------------------------------------------------------------------===// |
| 3564 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 3565 | static |
| 3566 | SDValue combineSelectAndUse(SDNode *N, SDValue Slct, SDValue OtherOp, |
| 3567 | TargetLowering::DAGCombinerInfo &DCI) { |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 3568 | SelectionDAG &DAG = DCI.DAG; |
| 3569 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3570 | EVT VT = N->getValueType(0); |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 3571 | unsigned Opc = N->getOpcode(); |
| 3572 | bool isSlctCC = Slct.getOpcode() == ISD::SELECT_CC; |
| 3573 | SDValue LHS = isSlctCC ? Slct.getOperand(2) : Slct.getOperand(1); |
| 3574 | SDValue RHS = isSlctCC ? Slct.getOperand(3) : Slct.getOperand(2); |
| 3575 | ISD::CondCode CC = ISD::SETCC_INVALID; |
| 3576 | |
| 3577 | if (isSlctCC) { |
| 3578 | CC = cast<CondCodeSDNode>(Slct.getOperand(4))->get(); |
| 3579 | } else { |
| 3580 | SDValue CCOp = Slct.getOperand(0); |
| 3581 | if (CCOp.getOpcode() == ISD::SETCC) |
| 3582 | CC = cast<CondCodeSDNode>(CCOp.getOperand(2))->get(); |
| 3583 | } |
| 3584 | |
| 3585 | bool DoXform = false; |
| 3586 | bool InvCC = false; |
| 3587 | assert ((Opc == ISD::ADD || (Opc == ISD::SUB && Slct == N->getOperand(1))) && |
| 3588 | "Bad input!"); |
| 3589 | |
| 3590 | if (LHS.getOpcode() == ISD::Constant && |
| 3591 | cast<ConstantSDNode>(LHS)->isNullValue()) { |
| 3592 | DoXform = true; |
| 3593 | } else if (CC != ISD::SETCC_INVALID && |
| 3594 | RHS.getOpcode() == ISD::Constant && |
| 3595 | cast<ConstantSDNode>(RHS)->isNullValue()) { |
| 3596 | std::swap(LHS, RHS); |
| 3597 | SDValue Op0 = Slct.getOperand(0); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3598 | EVT OpVT = isSlctCC ? Op0.getValueType() : |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 3599 | Op0.getOperand(0).getValueType(); |
| 3600 | bool isInt = OpVT.isInteger(); |
| 3601 | CC = ISD::getSetCCInverse(CC, isInt); |
| 3602 | |
| 3603 | if (!TLI.isCondCodeLegal(CC, OpVT)) |
| 3604 | return SDValue(); // Inverse operator isn't legal. |
| 3605 | |
| 3606 | DoXform = true; |
| 3607 | InvCC = true; |
| 3608 | } |
| 3609 | |
| 3610 | if (DoXform) { |
| 3611 | SDValue Result = DAG.getNode(Opc, RHS.getDebugLoc(), VT, OtherOp, RHS); |
| 3612 | if (isSlctCC) |
| 3613 | return DAG.getSelectCC(N->getDebugLoc(), OtherOp, Result, |
| 3614 | Slct.getOperand(0), Slct.getOperand(1), CC); |
| 3615 | SDValue CCOp = Slct.getOperand(0); |
| 3616 | if (InvCC) |
| 3617 | CCOp = DAG.getSetCC(Slct.getDebugLoc(), CCOp.getValueType(), |
| 3618 | CCOp.getOperand(0), CCOp.getOperand(1), CC); |
| 3619 | return DAG.getNode(ISD::SELECT, N->getDebugLoc(), VT, |
| 3620 | CCOp, OtherOp, Result); |
| 3621 | } |
| 3622 | return SDValue(); |
| 3623 | } |
| 3624 | |
| 3625 | /// PerformADDCombine - Target-specific dag combine xforms for ISD::ADD. |
| 3626 | static SDValue PerformADDCombine(SDNode *N, |
| 3627 | TargetLowering::DAGCombinerInfo &DCI) { |
| 3628 | // added by evan in r37685 with no testcase. |
| 3629 | SDValue N0 = N->getOperand(0), N1 = N->getOperand(1); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3630 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 3631 | // fold (add (select cc, 0, c), x) -> (select cc, x, (add, x, c)) |
| 3632 | if (N0.getOpcode() == ISD::SELECT && N0.getNode()->hasOneUse()) { |
| 3633 | SDValue Result = combineSelectAndUse(N, N0, N1, DCI); |
| 3634 | if (Result.getNode()) return Result; |
| 3635 | } |
| 3636 | if (N1.getOpcode() == ISD::SELECT && N1.getNode()->hasOneUse()) { |
| 3637 | SDValue Result = combineSelectAndUse(N, N1, N0, DCI); |
| 3638 | if (Result.getNode()) return Result; |
| 3639 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3640 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 3641 | return SDValue(); |
| 3642 | } |
| 3643 | |
| 3644 | /// PerformSUBCombine - Target-specific dag combine xforms for ISD::SUB. |
| 3645 | static SDValue PerformSUBCombine(SDNode *N, |
| 3646 | TargetLowering::DAGCombinerInfo &DCI) { |
| 3647 | // added by evan in r37685 with no testcase. |
| 3648 | SDValue N0 = N->getOperand(0), N1 = N->getOperand(1); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3649 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 3650 | // fold (sub x, (select cc, 0, c)) -> (select cc, x, (sub, x, c)) |
| 3651 | if (N1.getOpcode() == ISD::SELECT && N1.getNode()->hasOneUse()) { |
| 3652 | SDValue Result = combineSelectAndUse(N, N1, N0, DCI); |
| 3653 | if (Result.getNode()) return Result; |
| 3654 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3655 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 3656 | return SDValue(); |
| 3657 | } |
| 3658 | |
Bob Wilson | cb9a6aa | 2010-01-19 22:56:26 +0000 | [diff] [blame] | 3659 | /// PerformVMOVRRDCombine - Target-specific dag combine xforms for |
| 3660 | /// ARMISD::VMOVRRD. |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 3661 | static SDValue PerformVMOVRRDCombine(SDNode *N, |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3662 | TargetLowering::DAGCombinerInfo &DCI) { |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 3663 | // fmrrd(fmdrr x, y) -> x,y |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3664 | SDValue InDouble = N->getOperand(0); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 3665 | if (InDouble.getOpcode() == ARMISD::VMOVDRR) |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 3666 | return DCI.CombineTo(N, InDouble.getOperand(0), InDouble.getOperand(1)); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3667 | return SDValue(); |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 3668 | } |
| 3669 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3670 | /// getVShiftImm - Check if this is a valid build_vector for the immediate |
| 3671 | /// operand of a vector shift operation, where all the elements of the |
| 3672 | /// build_vector must have the same constant integer value. |
| 3673 | static bool getVShiftImm(SDValue Op, unsigned ElementBits, int64_t &Cnt) { |
| 3674 | // Ignore bit_converts. |
| 3675 | while (Op.getOpcode() == ISD::BIT_CONVERT) |
| 3676 | Op = Op.getOperand(0); |
| 3677 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(Op.getNode()); |
| 3678 | APInt SplatBits, SplatUndef; |
| 3679 | unsigned SplatBitSize; |
| 3680 | bool HasAnyUndefs; |
| 3681 | if (! BVN || ! BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, |
| 3682 | HasAnyUndefs, ElementBits) || |
| 3683 | SplatBitSize > ElementBits) |
| 3684 | return false; |
| 3685 | Cnt = SplatBits.getSExtValue(); |
| 3686 | return true; |
| 3687 | } |
| 3688 | |
| 3689 | /// isVShiftLImm - Check if this is a valid build_vector for the immediate |
| 3690 | /// operand of a vector shift left operation. That value must be in the range: |
| 3691 | /// 0 <= Value < ElementBits for a left shift; or |
| 3692 | /// 0 <= Value <= ElementBits for a long left shift. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3693 | static bool isVShiftLImm(SDValue Op, EVT VT, bool isLong, int64_t &Cnt) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3694 | assert(VT.isVector() && "vector shift count is not a vector type"); |
| 3695 | unsigned ElementBits = VT.getVectorElementType().getSizeInBits(); |
| 3696 | if (! getVShiftImm(Op, ElementBits, Cnt)) |
| 3697 | return false; |
| 3698 | return (Cnt >= 0 && (isLong ? Cnt-1 : Cnt) < ElementBits); |
| 3699 | } |
| 3700 | |
| 3701 | /// isVShiftRImm - Check if this is a valid build_vector for the immediate |
| 3702 | /// operand of a vector shift right operation. For a shift opcode, the value |
| 3703 | /// is positive, but for an intrinsic the value count must be negative. The |
| 3704 | /// absolute value must be in the range: |
| 3705 | /// 1 <= |Value| <= ElementBits for a right shift; or |
| 3706 | /// 1 <= |Value| <= ElementBits/2 for a narrow right shift. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3707 | static bool isVShiftRImm(SDValue Op, EVT VT, bool isNarrow, bool isIntrinsic, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3708 | int64_t &Cnt) { |
| 3709 | assert(VT.isVector() && "vector shift count is not a vector type"); |
| 3710 | unsigned ElementBits = VT.getVectorElementType().getSizeInBits(); |
| 3711 | if (! getVShiftImm(Op, ElementBits, Cnt)) |
| 3712 | return false; |
| 3713 | if (isIntrinsic) |
| 3714 | Cnt = -Cnt; |
| 3715 | return (Cnt >= 1 && Cnt <= (isNarrow ? ElementBits/2 : ElementBits)); |
| 3716 | } |
| 3717 | |
| 3718 | /// PerformIntrinsicCombine - ARM-specific DAG combining for intrinsics. |
| 3719 | static SDValue PerformIntrinsicCombine(SDNode *N, SelectionDAG &DAG) { |
| 3720 | unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue(); |
| 3721 | switch (IntNo) { |
| 3722 | default: |
| 3723 | // Don't do anything for most intrinsics. |
| 3724 | break; |
| 3725 | |
| 3726 | // Vector shifts: check for immediate versions and lower them. |
| 3727 | // Note: This is done during DAG combining instead of DAG legalizing because |
| 3728 | // the build_vectors for 64-bit vector element shift counts are generally |
| 3729 | // not legal, and it is hard to see their values after they get legalized to |
| 3730 | // loads from a constant pool. |
| 3731 | case Intrinsic::arm_neon_vshifts: |
| 3732 | case Intrinsic::arm_neon_vshiftu: |
| 3733 | case Intrinsic::arm_neon_vshiftls: |
| 3734 | case Intrinsic::arm_neon_vshiftlu: |
| 3735 | case Intrinsic::arm_neon_vshiftn: |
| 3736 | case Intrinsic::arm_neon_vrshifts: |
| 3737 | case Intrinsic::arm_neon_vrshiftu: |
| 3738 | case Intrinsic::arm_neon_vrshiftn: |
| 3739 | case Intrinsic::arm_neon_vqshifts: |
| 3740 | case Intrinsic::arm_neon_vqshiftu: |
| 3741 | case Intrinsic::arm_neon_vqshiftsu: |
| 3742 | case Intrinsic::arm_neon_vqshiftns: |
| 3743 | case Intrinsic::arm_neon_vqshiftnu: |
| 3744 | case Intrinsic::arm_neon_vqshiftnsu: |
| 3745 | case Intrinsic::arm_neon_vqrshiftns: |
| 3746 | case Intrinsic::arm_neon_vqrshiftnu: |
| 3747 | case Intrinsic::arm_neon_vqrshiftnsu: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3748 | EVT VT = N->getOperand(1).getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3749 | int64_t Cnt; |
| 3750 | unsigned VShiftOpc = 0; |
| 3751 | |
| 3752 | switch (IntNo) { |
| 3753 | case Intrinsic::arm_neon_vshifts: |
| 3754 | case Intrinsic::arm_neon_vshiftu: |
| 3755 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) { |
| 3756 | VShiftOpc = ARMISD::VSHL; |
| 3757 | break; |
| 3758 | } |
| 3759 | if (isVShiftRImm(N->getOperand(2), VT, false, true, Cnt)) { |
| 3760 | VShiftOpc = (IntNo == Intrinsic::arm_neon_vshifts ? |
| 3761 | ARMISD::VSHRs : ARMISD::VSHRu); |
| 3762 | break; |
| 3763 | } |
| 3764 | return SDValue(); |
| 3765 | |
| 3766 | case Intrinsic::arm_neon_vshiftls: |
| 3767 | case Intrinsic::arm_neon_vshiftlu: |
| 3768 | if (isVShiftLImm(N->getOperand(2), VT, true, Cnt)) |
| 3769 | break; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 3770 | llvm_unreachable("invalid shift count for vshll intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3771 | |
| 3772 | case Intrinsic::arm_neon_vrshifts: |
| 3773 | case Intrinsic::arm_neon_vrshiftu: |
| 3774 | if (isVShiftRImm(N->getOperand(2), VT, false, true, Cnt)) |
| 3775 | break; |
| 3776 | return SDValue(); |
| 3777 | |
| 3778 | case Intrinsic::arm_neon_vqshifts: |
| 3779 | case Intrinsic::arm_neon_vqshiftu: |
| 3780 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) |
| 3781 | break; |
| 3782 | return SDValue(); |
| 3783 | |
| 3784 | case Intrinsic::arm_neon_vqshiftsu: |
| 3785 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) |
| 3786 | break; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 3787 | llvm_unreachable("invalid shift count for vqshlu intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3788 | |
| 3789 | case Intrinsic::arm_neon_vshiftn: |
| 3790 | case Intrinsic::arm_neon_vrshiftn: |
| 3791 | case Intrinsic::arm_neon_vqshiftns: |
| 3792 | case Intrinsic::arm_neon_vqshiftnu: |
| 3793 | case Intrinsic::arm_neon_vqshiftnsu: |
| 3794 | case Intrinsic::arm_neon_vqrshiftns: |
| 3795 | case Intrinsic::arm_neon_vqrshiftnu: |
| 3796 | case Intrinsic::arm_neon_vqrshiftnsu: |
| 3797 | // Narrowing shifts require an immediate right shift. |
| 3798 | if (isVShiftRImm(N->getOperand(2), VT, true, true, Cnt)) |
| 3799 | break; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 3800 | llvm_unreachable("invalid shift count for narrowing vector shift intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3801 | |
| 3802 | default: |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 3803 | llvm_unreachable("unhandled vector shift"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3804 | } |
| 3805 | |
| 3806 | switch (IntNo) { |
| 3807 | case Intrinsic::arm_neon_vshifts: |
| 3808 | case Intrinsic::arm_neon_vshiftu: |
| 3809 | // Opcode already set above. |
| 3810 | break; |
| 3811 | case Intrinsic::arm_neon_vshiftls: |
| 3812 | case Intrinsic::arm_neon_vshiftlu: |
| 3813 | if (Cnt == VT.getVectorElementType().getSizeInBits()) |
| 3814 | VShiftOpc = ARMISD::VSHLLi; |
| 3815 | else |
| 3816 | VShiftOpc = (IntNo == Intrinsic::arm_neon_vshiftls ? |
| 3817 | ARMISD::VSHLLs : ARMISD::VSHLLu); |
| 3818 | break; |
| 3819 | case Intrinsic::arm_neon_vshiftn: |
| 3820 | VShiftOpc = ARMISD::VSHRN; break; |
| 3821 | case Intrinsic::arm_neon_vrshifts: |
| 3822 | VShiftOpc = ARMISD::VRSHRs; break; |
| 3823 | case Intrinsic::arm_neon_vrshiftu: |
| 3824 | VShiftOpc = ARMISD::VRSHRu; break; |
| 3825 | case Intrinsic::arm_neon_vrshiftn: |
| 3826 | VShiftOpc = ARMISD::VRSHRN; break; |
| 3827 | case Intrinsic::arm_neon_vqshifts: |
| 3828 | VShiftOpc = ARMISD::VQSHLs; break; |
| 3829 | case Intrinsic::arm_neon_vqshiftu: |
| 3830 | VShiftOpc = ARMISD::VQSHLu; break; |
| 3831 | case Intrinsic::arm_neon_vqshiftsu: |
| 3832 | VShiftOpc = ARMISD::VQSHLsu; break; |
| 3833 | case Intrinsic::arm_neon_vqshiftns: |
| 3834 | VShiftOpc = ARMISD::VQSHRNs; break; |
| 3835 | case Intrinsic::arm_neon_vqshiftnu: |
| 3836 | VShiftOpc = ARMISD::VQSHRNu; break; |
| 3837 | case Intrinsic::arm_neon_vqshiftnsu: |
| 3838 | VShiftOpc = ARMISD::VQSHRNsu; break; |
| 3839 | case Intrinsic::arm_neon_vqrshiftns: |
| 3840 | VShiftOpc = ARMISD::VQRSHRNs; break; |
| 3841 | case Intrinsic::arm_neon_vqrshiftnu: |
| 3842 | VShiftOpc = ARMISD::VQRSHRNu; break; |
| 3843 | case Intrinsic::arm_neon_vqrshiftnsu: |
| 3844 | VShiftOpc = ARMISD::VQRSHRNsu; break; |
| 3845 | } |
| 3846 | |
| 3847 | return DAG.getNode(VShiftOpc, N->getDebugLoc(), N->getValueType(0), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3848 | N->getOperand(1), DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3849 | } |
| 3850 | |
| 3851 | case Intrinsic::arm_neon_vshiftins: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3852 | EVT VT = N->getOperand(1).getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3853 | int64_t Cnt; |
| 3854 | unsigned VShiftOpc = 0; |
| 3855 | |
| 3856 | if (isVShiftLImm(N->getOperand(3), VT, false, Cnt)) |
| 3857 | VShiftOpc = ARMISD::VSLI; |
| 3858 | else if (isVShiftRImm(N->getOperand(3), VT, false, true, Cnt)) |
| 3859 | VShiftOpc = ARMISD::VSRI; |
| 3860 | else { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 3861 | llvm_unreachable("invalid shift count for vsli/vsri intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3862 | } |
| 3863 | |
| 3864 | return DAG.getNode(VShiftOpc, N->getDebugLoc(), N->getValueType(0), |
| 3865 | N->getOperand(1), N->getOperand(2), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3866 | DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3867 | } |
| 3868 | |
| 3869 | case Intrinsic::arm_neon_vqrshifts: |
| 3870 | case Intrinsic::arm_neon_vqrshiftu: |
| 3871 | // No immediate versions of these to check for. |
| 3872 | break; |
| 3873 | } |
| 3874 | |
| 3875 | return SDValue(); |
| 3876 | } |
| 3877 | |
| 3878 | /// PerformShiftCombine - Checks for immediate versions of vector shifts and |
| 3879 | /// lowers them. As with the vector shift intrinsics, this is done during DAG |
| 3880 | /// combining instead of DAG legalizing because the build_vectors for 64-bit |
| 3881 | /// vector element shift counts are generally not legal, and it is hard to see |
| 3882 | /// their values after they get legalized to loads from a constant pool. |
| 3883 | static SDValue PerformShiftCombine(SDNode *N, SelectionDAG &DAG, |
| 3884 | const ARMSubtarget *ST) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3885 | EVT VT = N->getValueType(0); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3886 | |
| 3887 | // Nothing to be done for scalar shifts. |
| 3888 | if (! VT.isVector()) |
| 3889 | return SDValue(); |
| 3890 | |
| 3891 | assert(ST->hasNEON() && "unexpected vector shift"); |
| 3892 | int64_t Cnt; |
| 3893 | |
| 3894 | switch (N->getOpcode()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 3895 | default: llvm_unreachable("unexpected shift opcode"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3896 | |
| 3897 | case ISD::SHL: |
| 3898 | if (isVShiftLImm(N->getOperand(1), VT, false, Cnt)) |
| 3899 | return DAG.getNode(ARMISD::VSHL, N->getDebugLoc(), VT, N->getOperand(0), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3900 | DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3901 | break; |
| 3902 | |
| 3903 | case ISD::SRA: |
| 3904 | case ISD::SRL: |
| 3905 | if (isVShiftRImm(N->getOperand(1), VT, false, false, Cnt)) { |
| 3906 | unsigned VShiftOpc = (N->getOpcode() == ISD::SRA ? |
| 3907 | ARMISD::VSHRs : ARMISD::VSHRu); |
| 3908 | return DAG.getNode(VShiftOpc, N->getDebugLoc(), VT, N->getOperand(0), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3909 | DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3910 | } |
| 3911 | } |
| 3912 | return SDValue(); |
| 3913 | } |
| 3914 | |
| 3915 | /// PerformExtendCombine - Target-specific DAG combining for ISD::SIGN_EXTEND, |
| 3916 | /// ISD::ZERO_EXTEND, and ISD::ANY_EXTEND. |
| 3917 | static SDValue PerformExtendCombine(SDNode *N, SelectionDAG &DAG, |
| 3918 | const ARMSubtarget *ST) { |
| 3919 | SDValue N0 = N->getOperand(0); |
| 3920 | |
| 3921 | // Check for sign- and zero-extensions of vector extract operations of 8- |
| 3922 | // and 16-bit vector elements. NEON supports these directly. They are |
| 3923 | // handled during DAG combining because type legalization will promote them |
| 3924 | // to 32-bit types and it is messy to recognize the operations after that. |
| 3925 | if (ST->hasNEON() && N0.getOpcode() == ISD::EXTRACT_VECTOR_ELT) { |
| 3926 | SDValue Vec = N0.getOperand(0); |
| 3927 | SDValue Lane = N0.getOperand(1); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3928 | EVT VT = N->getValueType(0); |
| 3929 | EVT EltVT = N0.getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3930 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 3931 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3932 | if (VT == MVT::i32 && |
| 3933 | (EltVT == MVT::i8 || EltVT == MVT::i16) && |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3934 | TLI.isTypeLegal(Vec.getValueType())) { |
| 3935 | |
| 3936 | unsigned Opc = 0; |
| 3937 | switch (N->getOpcode()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 3938 | default: llvm_unreachable("unexpected opcode"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3939 | case ISD::SIGN_EXTEND: |
| 3940 | Opc = ARMISD::VGETLANEs; |
| 3941 | break; |
| 3942 | case ISD::ZERO_EXTEND: |
| 3943 | case ISD::ANY_EXTEND: |
| 3944 | Opc = ARMISD::VGETLANEu; |
| 3945 | break; |
| 3946 | } |
| 3947 | return DAG.getNode(Opc, N->getDebugLoc(), VT, Vec, Lane); |
| 3948 | } |
| 3949 | } |
| 3950 | |
| 3951 | return SDValue(); |
| 3952 | } |
| 3953 | |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 3954 | /// PerformSELECT_CCCombine - Target-specific DAG combining for ISD::SELECT_CC |
| 3955 | /// to match f32 max/min patterns to use NEON vmax/vmin instructions. |
| 3956 | static SDValue PerformSELECT_CCCombine(SDNode *N, SelectionDAG &DAG, |
| 3957 | const ARMSubtarget *ST) { |
| 3958 | // If the target supports NEON, try to use vmax/vmin instructions for f32 |
| 3959 | // selects like "x < y ? x : y". Unless the FiniteOnlyFPMath option is set, |
| 3960 | // be careful about NaNs: NEON's vmax/vmin return NaN if either operand is |
| 3961 | // a NaN; only do the transformation when it matches that behavior. |
| 3962 | |
| 3963 | // For now only do this when using NEON for FP operations; if using VFP, it |
| 3964 | // is not obvious that the benefit outweighs the cost of switching to the |
| 3965 | // NEON pipeline. |
| 3966 | if (!ST->hasNEON() || !ST->useNEONForSinglePrecisionFP() || |
| 3967 | N->getValueType(0) != MVT::f32) |
| 3968 | return SDValue(); |
| 3969 | |
| 3970 | SDValue CondLHS = N->getOperand(0); |
| 3971 | SDValue CondRHS = N->getOperand(1); |
| 3972 | SDValue LHS = N->getOperand(2); |
| 3973 | SDValue RHS = N->getOperand(3); |
| 3974 | ISD::CondCode CC = cast<CondCodeSDNode>(N->getOperand(4))->get(); |
| 3975 | |
| 3976 | unsigned Opcode = 0; |
| 3977 | bool IsReversed; |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 3978 | if (DAG.isEqualTo(LHS, CondLHS) && DAG.isEqualTo(RHS, CondRHS)) { |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 3979 | IsReversed = false; // x CC y ? x : y |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 3980 | } else if (DAG.isEqualTo(LHS, CondRHS) && DAG.isEqualTo(RHS, CondLHS)) { |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 3981 | IsReversed = true ; // x CC y ? y : x |
| 3982 | } else { |
| 3983 | return SDValue(); |
| 3984 | } |
| 3985 | |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 3986 | bool IsUnordered; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 3987 | switch (CC) { |
| 3988 | default: break; |
| 3989 | case ISD::SETOLT: |
| 3990 | case ISD::SETOLE: |
| 3991 | case ISD::SETLT: |
| 3992 | case ISD::SETLE: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 3993 | case ISD::SETULT: |
| 3994 | case ISD::SETULE: |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 3995 | // If LHS is NaN, an ordered comparison will be false and the result will |
| 3996 | // be the RHS, but vmin(NaN, RHS) = NaN. Avoid this by checking that LHS |
| 3997 | // != NaN. Likewise, for unordered comparisons, check for RHS != NaN. |
| 3998 | IsUnordered = (CC == ISD::SETULT || CC == ISD::SETULE); |
| 3999 | if (!DAG.isKnownNeverNaN(IsUnordered ? RHS : LHS)) |
| 4000 | break; |
| 4001 | // For less-than-or-equal comparisons, "+0 <= -0" will be true but vmin |
| 4002 | // will return -0, so vmin can only be used for unsafe math or if one of |
| 4003 | // the operands is known to be nonzero. |
| 4004 | if ((CC == ISD::SETLE || CC == ISD::SETOLE || CC == ISD::SETULE) && |
| 4005 | !UnsafeFPMath && |
| 4006 | !(DAG.isKnownNeverZero(LHS) || DAG.isKnownNeverZero(RHS))) |
| 4007 | break; |
| 4008 | Opcode = IsReversed ? ARMISD::FMAX : ARMISD::FMIN; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 4009 | break; |
| 4010 | |
| 4011 | case ISD::SETOGT: |
| 4012 | case ISD::SETOGE: |
| 4013 | case ISD::SETGT: |
| 4014 | case ISD::SETGE: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 4015 | case ISD::SETUGT: |
| 4016 | case ISD::SETUGE: |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 4017 | // If LHS is NaN, an ordered comparison will be false and the result will |
| 4018 | // be the RHS, but vmax(NaN, RHS) = NaN. Avoid this by checking that LHS |
| 4019 | // != NaN. Likewise, for unordered comparisons, check for RHS != NaN. |
| 4020 | IsUnordered = (CC == ISD::SETUGT || CC == ISD::SETUGE); |
| 4021 | if (!DAG.isKnownNeverNaN(IsUnordered ? RHS : LHS)) |
| 4022 | break; |
| 4023 | // For greater-than-or-equal comparisons, "-0 >= +0" will be true but vmax |
| 4024 | // will return +0, so vmax can only be used for unsafe math or if one of |
| 4025 | // the operands is known to be nonzero. |
| 4026 | if ((CC == ISD::SETGE || CC == ISD::SETOGE || CC == ISD::SETUGE) && |
| 4027 | !UnsafeFPMath && |
| 4028 | !(DAG.isKnownNeverZero(LHS) || DAG.isKnownNeverZero(RHS))) |
| 4029 | break; |
| 4030 | Opcode = IsReversed ? ARMISD::FMIN : ARMISD::FMAX; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 4031 | break; |
| 4032 | } |
| 4033 | |
| 4034 | if (!Opcode) |
| 4035 | return SDValue(); |
| 4036 | return DAG.getNode(Opcode, N->getDebugLoc(), N->getValueType(0), LHS, RHS); |
| 4037 | } |
| 4038 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4039 | SDValue ARMTargetLowering::PerformDAGCombine(SDNode *N, |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 4040 | DAGCombinerInfo &DCI) const { |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 4041 | switch (N->getOpcode()) { |
| 4042 | default: break; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 4043 | case ISD::ADD: return PerformADDCombine(N, DCI); |
| 4044 | case ISD::SUB: return PerformSUBCombine(N, DCI); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 4045 | case ARMISD::VMOVRRD: return PerformVMOVRRDCombine(N, DCI); |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 4046 | case ISD::INTRINSIC_WO_CHAIN: return PerformIntrinsicCombine(N, DCI.DAG); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4047 | case ISD::SHL: |
| 4048 | case ISD::SRA: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 4049 | case ISD::SRL: return PerformShiftCombine(N, DCI.DAG, Subtarget); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4050 | case ISD::SIGN_EXTEND: |
| 4051 | case ISD::ZERO_EXTEND: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 4052 | case ISD::ANY_EXTEND: return PerformExtendCombine(N, DCI.DAG, Subtarget); |
| 4053 | case ISD::SELECT_CC: return PerformSELECT_CCCombine(N, DCI.DAG, Subtarget); |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 4054 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4055 | return SDValue(); |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 4056 | } |
| 4057 | |
Bill Wendling | af56634 | 2009-08-15 21:21:19 +0000 | [diff] [blame] | 4058 | bool ARMTargetLowering::allowsUnalignedMemoryAccesses(EVT VT) const { |
| 4059 | if (!Subtarget->hasV6Ops()) |
| 4060 | // Pre-v6 does not support unaligned mem access. |
| 4061 | return false; |
Anton Korobeynikov | 90cfc13 | 2010-01-30 14:08:12 +0000 | [diff] [blame] | 4062 | else { |
| 4063 | // v6+ may or may not support unaligned mem access depending on the system |
| 4064 | // configuration. |
| 4065 | // FIXME: This is pretty conservative. Should we provide cmdline option to |
| 4066 | // control the behaviour? |
Bill Wendling | af56634 | 2009-08-15 21:21:19 +0000 | [diff] [blame] | 4067 | if (!Subtarget->isTargetDarwin()) |
| 4068 | return false; |
| 4069 | } |
| 4070 | |
| 4071 | switch (VT.getSimpleVT().SimpleTy) { |
| 4072 | default: |
| 4073 | return false; |
| 4074 | case MVT::i8: |
| 4075 | case MVT::i16: |
| 4076 | case MVT::i32: |
| 4077 | return true; |
| 4078 | // FIXME: VLD1 etc with standard alignment is legal. |
| 4079 | } |
| 4080 | } |
| 4081 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 4082 | static bool isLegalT1AddressImmediate(int64_t V, EVT VT) { |
| 4083 | if (V < 0) |
| 4084 | return false; |
| 4085 | |
| 4086 | unsigned Scale = 1; |
| 4087 | switch (VT.getSimpleVT().SimpleTy) { |
| 4088 | default: return false; |
| 4089 | case MVT::i1: |
| 4090 | case MVT::i8: |
| 4091 | // Scale == 1; |
| 4092 | break; |
| 4093 | case MVT::i16: |
| 4094 | // Scale == 2; |
| 4095 | Scale = 2; |
| 4096 | break; |
| 4097 | case MVT::i32: |
| 4098 | // Scale == 4; |
| 4099 | Scale = 4; |
| 4100 | break; |
| 4101 | } |
| 4102 | |
| 4103 | if ((V & (Scale - 1)) != 0) |
| 4104 | return false; |
| 4105 | V /= Scale; |
| 4106 | return V == (V & ((1LL << 5) - 1)); |
| 4107 | } |
| 4108 | |
| 4109 | static bool isLegalT2AddressImmediate(int64_t V, EVT VT, |
| 4110 | const ARMSubtarget *Subtarget) { |
| 4111 | bool isNeg = false; |
| 4112 | if (V < 0) { |
| 4113 | isNeg = true; |
| 4114 | V = - V; |
| 4115 | } |
| 4116 | |
| 4117 | switch (VT.getSimpleVT().SimpleTy) { |
| 4118 | default: return false; |
| 4119 | case MVT::i1: |
| 4120 | case MVT::i8: |
| 4121 | case MVT::i16: |
| 4122 | case MVT::i32: |
| 4123 | // + imm12 or - imm8 |
| 4124 | if (isNeg) |
| 4125 | return V == (V & ((1LL << 8) - 1)); |
| 4126 | return V == (V & ((1LL << 12) - 1)); |
| 4127 | case MVT::f32: |
| 4128 | case MVT::f64: |
| 4129 | // Same as ARM mode. FIXME: NEON? |
| 4130 | if (!Subtarget->hasVFP2()) |
| 4131 | return false; |
| 4132 | if ((V & 3) != 0) |
| 4133 | return false; |
| 4134 | V >>= 2; |
| 4135 | return V == (V & ((1LL << 8) - 1)); |
| 4136 | } |
| 4137 | } |
| 4138 | |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 4139 | /// isLegalAddressImmediate - Return true if the integer value can be used |
| 4140 | /// as the offset of the target addressing mode for load / store of the |
| 4141 | /// given type. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4142 | static bool isLegalAddressImmediate(int64_t V, EVT VT, |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 4143 | const ARMSubtarget *Subtarget) { |
Evan Cheng | 961f879 | 2007-03-13 20:37:59 +0000 | [diff] [blame] | 4144 | if (V == 0) |
| 4145 | return true; |
| 4146 | |
Evan Cheng | 6501153 | 2009-03-09 19:15:00 +0000 | [diff] [blame] | 4147 | if (!VT.isSimple()) |
| 4148 | return false; |
| 4149 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 4150 | if (Subtarget->isThumb1Only()) |
| 4151 | return isLegalT1AddressImmediate(V, VT); |
| 4152 | else if (Subtarget->isThumb2()) |
| 4153 | return isLegalT2AddressImmediate(V, VT, Subtarget); |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 4154 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 4155 | // ARM mode. |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 4156 | if (V < 0) |
| 4157 | V = - V; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4158 | switch (VT.getSimpleVT().SimpleTy) { |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 4159 | default: return false; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4160 | case MVT::i1: |
| 4161 | case MVT::i8: |
| 4162 | case MVT::i32: |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 4163 | // +- imm12 |
Anton Korobeynikov | 7c1c261 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 4164 | return V == (V & ((1LL << 12) - 1)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4165 | case MVT::i16: |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 4166 | // +- imm8 |
Anton Korobeynikov | 7c1c261 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 4167 | return V == (V & ((1LL << 8) - 1)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4168 | case MVT::f32: |
| 4169 | case MVT::f64: |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 4170 | if (!Subtarget->hasVFP2()) // FIXME: NEON? |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 4171 | return false; |
Evan Cheng | 0b0a9a9 | 2007-05-03 02:00:18 +0000 | [diff] [blame] | 4172 | if ((V & 3) != 0) |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 4173 | return false; |
| 4174 | V >>= 2; |
Anton Korobeynikov | 7c1c261 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 4175 | return V == (V & ((1LL << 8) - 1)); |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 4176 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4177 | } |
| 4178 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 4179 | bool ARMTargetLowering::isLegalT2ScaledAddressingMode(const AddrMode &AM, |
| 4180 | EVT VT) const { |
| 4181 | int Scale = AM.Scale; |
| 4182 | if (Scale < 0) |
| 4183 | return false; |
| 4184 | |
| 4185 | switch (VT.getSimpleVT().SimpleTy) { |
| 4186 | default: return false; |
| 4187 | case MVT::i1: |
| 4188 | case MVT::i8: |
| 4189 | case MVT::i16: |
| 4190 | case MVT::i32: |
| 4191 | if (Scale == 1) |
| 4192 | return true; |
| 4193 | // r + r << imm |
| 4194 | Scale = Scale & ~1; |
| 4195 | return Scale == 2 || Scale == 4 || Scale == 8; |
| 4196 | case MVT::i64: |
| 4197 | // r + r |
| 4198 | if (((unsigned)AM.HasBaseReg + Scale) <= 2) |
| 4199 | return true; |
| 4200 | return false; |
| 4201 | case MVT::isVoid: |
| 4202 | // Note, we allow "void" uses (basically, uses that aren't loads or |
| 4203 | // stores), because arm allows folding a scale into many arithmetic |
| 4204 | // operations. This should be made more precise and revisited later. |
| 4205 | |
| 4206 | // Allow r << imm, but the imm has to be a multiple of two. |
| 4207 | if (Scale & 1) return false; |
| 4208 | return isPowerOf2_32(Scale); |
| 4209 | } |
| 4210 | } |
| 4211 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 4212 | /// isLegalAddressingMode - Return true if the addressing mode represented |
| 4213 | /// 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] | 4214 | bool ARMTargetLowering::isLegalAddressingMode(const AddrMode &AM, |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 4215 | const Type *Ty) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4216 | EVT VT = getValueType(Ty, true); |
Bob Wilson | 2c7dab1 | 2009-04-08 17:55:28 +0000 | [diff] [blame] | 4217 | if (!isLegalAddressImmediate(AM.BaseOffs, VT, Subtarget)) |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 4218 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 4219 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 4220 | // Can never fold addr of global into load/store. |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 4221 | if (AM.BaseGV) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 4222 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 4223 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 4224 | switch (AM.Scale) { |
| 4225 | case 0: // no scale reg, must be "r+i" or "r", or "i". |
| 4226 | break; |
| 4227 | case 1: |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 4228 | if (Subtarget->isThumb1Only()) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 4229 | return false; |
Chris Lattner | 5a3d40d | 2007-04-13 06:50:55 +0000 | [diff] [blame] | 4230 | // FALL THROUGH. |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 4231 | default: |
Chris Lattner | 5a3d40d | 2007-04-13 06:50:55 +0000 | [diff] [blame] | 4232 | // ARM doesn't support any R+R*scale+imm addr modes. |
| 4233 | if (AM.BaseOffs) |
| 4234 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 4235 | |
Bob Wilson | 2c7dab1 | 2009-04-08 17:55:28 +0000 | [diff] [blame] | 4236 | if (!VT.isSimple()) |
| 4237 | return false; |
| 4238 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 4239 | if (Subtarget->isThumb2()) |
| 4240 | return isLegalT2ScaledAddressingMode(AM, VT); |
| 4241 | |
Chris Lattner | eb13d1b | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 4242 | int Scale = AM.Scale; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4243 | switch (VT.getSimpleVT().SimpleTy) { |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 4244 | default: return false; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4245 | case MVT::i1: |
| 4246 | case MVT::i8: |
| 4247 | case MVT::i32: |
Chris Lattner | eb13d1b | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 4248 | if (Scale < 0) Scale = -Scale; |
| 4249 | if (Scale == 1) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 4250 | return true; |
| 4251 | // r + r << imm |
Chris Lattner | e115294 | 2007-04-11 16:17:12 +0000 | [diff] [blame] | 4252 | return isPowerOf2_32(Scale & ~1); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4253 | case MVT::i16: |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 4254 | case MVT::i64: |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 4255 | // r + r |
Chris Lattner | eb13d1b | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 4256 | if (((unsigned)AM.HasBaseReg + Scale) <= 2) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 4257 | return true; |
Chris Lattner | e115294 | 2007-04-11 16:17:12 +0000 | [diff] [blame] | 4258 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 4259 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4260 | case MVT::isVoid: |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 4261 | // Note, we allow "void" uses (basically, uses that aren't loads or |
| 4262 | // stores), because arm allows folding a scale into many arithmetic |
| 4263 | // operations. This should be made more precise and revisited later. |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 4264 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 4265 | // Allow r << imm, but the imm has to be a multiple of two. |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 4266 | if (Scale & 1) return false; |
| 4267 | return isPowerOf2_32(Scale); |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 4268 | } |
| 4269 | break; |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 4270 | } |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 4271 | return true; |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 4272 | } |
| 4273 | |
Evan Cheng | 77e4751 | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 4274 | /// isLegalICmpImmediate - Return true if the specified immediate is legal |
| 4275 | /// icmp immediate, that is the target has icmp instructions which can compare |
| 4276 | /// a register against the immediate without having to materialize the |
| 4277 | /// immediate into a register. |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 4278 | bool ARMTargetLowering::isLegalICmpImmediate(int64_t Imm) const { |
Evan Cheng | 77e4751 | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 4279 | if (!Subtarget->isThumb()) |
| 4280 | return ARM_AM::getSOImmVal(Imm) != -1; |
| 4281 | if (Subtarget->isThumb2()) |
| 4282 | return ARM_AM::getT2SOImmVal(Imm) != -1; |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 4283 | return Imm >= 0 && Imm <= 255; |
Evan Cheng | 77e4751 | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 4284 | } |
| 4285 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4286 | static bool getARMIndexedAddressParts(SDNode *Ptr, EVT VT, |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 4287 | bool isSEXTLoad, SDValue &Base, |
| 4288 | SDValue &Offset, bool &isInc, |
| 4289 | SelectionDAG &DAG) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4290 | if (Ptr->getOpcode() != ISD::ADD && Ptr->getOpcode() != ISD::SUB) |
| 4291 | return false; |
| 4292 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4293 | if (VT == MVT::i16 || ((VT == MVT::i8 || VT == MVT::i1) && isSEXTLoad)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4294 | // AddressingMode 3 |
| 4295 | Base = Ptr->getOperand(0); |
| 4296 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 4297 | int RHSC = (int)RHS->getZExtValue(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4298 | if (RHSC < 0 && RHSC > -256) { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 4299 | assert(Ptr->getOpcode() == ISD::ADD); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4300 | isInc = false; |
| 4301 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); |
| 4302 | return true; |
| 4303 | } |
| 4304 | } |
| 4305 | isInc = (Ptr->getOpcode() == ISD::ADD); |
| 4306 | Offset = Ptr->getOperand(1); |
| 4307 | return true; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4308 | } else if (VT == MVT::i32 || VT == MVT::i8 || VT == MVT::i1) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4309 | // AddressingMode 2 |
| 4310 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 4311 | int RHSC = (int)RHS->getZExtValue(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4312 | if (RHSC < 0 && RHSC > -0x1000) { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 4313 | assert(Ptr->getOpcode() == ISD::ADD); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4314 | isInc = false; |
| 4315 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); |
| 4316 | Base = Ptr->getOperand(0); |
| 4317 | return true; |
| 4318 | } |
| 4319 | } |
| 4320 | |
| 4321 | if (Ptr->getOpcode() == ISD::ADD) { |
| 4322 | isInc = true; |
| 4323 | ARM_AM::ShiftOpc ShOpcVal= ARM_AM::getShiftOpcForNode(Ptr->getOperand(0)); |
| 4324 | if (ShOpcVal != ARM_AM::no_shift) { |
| 4325 | Base = Ptr->getOperand(1); |
| 4326 | Offset = Ptr->getOperand(0); |
| 4327 | } else { |
| 4328 | Base = Ptr->getOperand(0); |
| 4329 | Offset = Ptr->getOperand(1); |
| 4330 | } |
| 4331 | return true; |
| 4332 | } |
| 4333 | |
| 4334 | isInc = (Ptr->getOpcode() == ISD::ADD); |
| 4335 | Base = Ptr->getOperand(0); |
| 4336 | Offset = Ptr->getOperand(1); |
| 4337 | return true; |
| 4338 | } |
| 4339 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 4340 | // FIXME: Use VLDM / VSTM to emulate indexed FP load / store. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4341 | return false; |
| 4342 | } |
| 4343 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4344 | static bool getT2IndexedAddressParts(SDNode *Ptr, EVT VT, |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 4345 | bool isSEXTLoad, SDValue &Base, |
| 4346 | SDValue &Offset, bool &isInc, |
| 4347 | SelectionDAG &DAG) { |
| 4348 | if (Ptr->getOpcode() != ISD::ADD && Ptr->getOpcode() != ISD::SUB) |
| 4349 | return false; |
| 4350 | |
| 4351 | Base = Ptr->getOperand(0); |
| 4352 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
| 4353 | int RHSC = (int)RHS->getZExtValue(); |
| 4354 | if (RHSC < 0 && RHSC > -0x100) { // 8 bits. |
| 4355 | assert(Ptr->getOpcode() == ISD::ADD); |
| 4356 | isInc = false; |
| 4357 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); |
| 4358 | return true; |
| 4359 | } else if (RHSC > 0 && RHSC < 0x100) { // 8 bit, no zero. |
| 4360 | isInc = Ptr->getOpcode() == ISD::ADD; |
| 4361 | Offset = DAG.getConstant(RHSC, RHS->getValueType(0)); |
| 4362 | return true; |
| 4363 | } |
| 4364 | } |
| 4365 | |
| 4366 | return false; |
| 4367 | } |
| 4368 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4369 | /// getPreIndexedAddressParts - returns true by value, base pointer and |
| 4370 | /// offset pointer and addressing mode by reference if the node's address |
| 4371 | /// can be legally represented as pre-indexed load / store address. |
| 4372 | bool |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4373 | ARMTargetLowering::getPreIndexedAddressParts(SDNode *N, SDValue &Base, |
| 4374 | SDValue &Offset, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4375 | ISD::MemIndexedMode &AM, |
Dan Gohman | 73e0914 | 2009-01-15 16:29:45 +0000 | [diff] [blame] | 4376 | SelectionDAG &DAG) const { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 4377 | if (Subtarget->isThumb1Only()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4378 | return false; |
| 4379 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4380 | EVT VT; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4381 | SDValue Ptr; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4382 | bool isSEXTLoad = false; |
| 4383 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) { |
| 4384 | Ptr = LD->getBasePtr(); |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 4385 | VT = LD->getMemoryVT(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4386 | isSEXTLoad = LD->getExtensionType() == ISD::SEXTLOAD; |
| 4387 | } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) { |
| 4388 | Ptr = ST->getBasePtr(); |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 4389 | VT = ST->getMemoryVT(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4390 | } else |
| 4391 | return false; |
| 4392 | |
| 4393 | bool isInc; |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 4394 | bool isLegal = false; |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 4395 | if (Subtarget->isThumb2()) |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 4396 | isLegal = getT2IndexedAddressParts(Ptr.getNode(), VT, isSEXTLoad, Base, |
| 4397 | Offset, isInc, DAG); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 4398 | else |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 4399 | isLegal = getARMIndexedAddressParts(Ptr.getNode(), VT, isSEXTLoad, Base, |
Evan Cheng | 0412957 | 2009-07-02 06:44:30 +0000 | [diff] [blame] | 4400 | Offset, isInc, DAG); |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 4401 | if (!isLegal) |
| 4402 | return false; |
| 4403 | |
| 4404 | AM = isInc ? ISD::PRE_INC : ISD::PRE_DEC; |
| 4405 | return true; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4406 | } |
| 4407 | |
| 4408 | /// getPostIndexedAddressParts - returns true by value, base pointer and |
| 4409 | /// offset pointer and addressing mode by reference if this node can be |
| 4410 | /// combined with a load / store to form a post-indexed load / store. |
| 4411 | bool ARMTargetLowering::getPostIndexedAddressParts(SDNode *N, SDNode *Op, |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4412 | SDValue &Base, |
| 4413 | SDValue &Offset, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4414 | ISD::MemIndexedMode &AM, |
Dan Gohman | 73e0914 | 2009-01-15 16:29:45 +0000 | [diff] [blame] | 4415 | SelectionDAG &DAG) const { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 4416 | if (Subtarget->isThumb1Only()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4417 | return false; |
| 4418 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4419 | EVT VT; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4420 | SDValue Ptr; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4421 | bool isSEXTLoad = false; |
| 4422 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) { |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 4423 | VT = LD->getMemoryVT(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4424 | isSEXTLoad = LD->getExtensionType() == ISD::SEXTLOAD; |
| 4425 | } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) { |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 4426 | VT = ST->getMemoryVT(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4427 | } else |
| 4428 | return false; |
| 4429 | |
| 4430 | bool isInc; |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 4431 | bool isLegal = false; |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 4432 | if (Subtarget->isThumb2()) |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 4433 | isLegal = getT2IndexedAddressParts(Op, VT, isSEXTLoad, Base, Offset, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4434 | isInc, DAG); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 4435 | else |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 4436 | isLegal = getARMIndexedAddressParts(Op, VT, isSEXTLoad, Base, Offset, |
| 4437 | isInc, DAG); |
| 4438 | if (!isLegal) |
| 4439 | return false; |
| 4440 | |
| 4441 | AM = isInc ? ISD::POST_INC : ISD::POST_DEC; |
| 4442 | return true; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4443 | } |
| 4444 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4445 | void ARMTargetLowering::computeMaskedBitsForTargetNode(const SDValue Op, |
Dan Gohman | 977a76f | 2008-02-13 22:28:48 +0000 | [diff] [blame] | 4446 | const APInt &Mask, |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 4447 | APInt &KnownZero, |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 4448 | APInt &KnownOne, |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 4449 | const SelectionDAG &DAG, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4450 | unsigned Depth) const { |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 4451 | KnownZero = KnownOne = APInt(Mask.getBitWidth(), 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4452 | switch (Op.getOpcode()) { |
| 4453 | default: break; |
| 4454 | case ARMISD::CMOV: { |
| 4455 | // Bits are known zero/one if known on the LHS and RHS. |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 4456 | DAG.ComputeMaskedBits(Op.getOperand(0), Mask, KnownZero, KnownOne, Depth+1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4457 | if (KnownZero == 0 && KnownOne == 0) return; |
| 4458 | |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 4459 | APInt KnownZeroRHS, KnownOneRHS; |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 4460 | DAG.ComputeMaskedBits(Op.getOperand(1), Mask, |
| 4461 | KnownZeroRHS, KnownOneRHS, Depth+1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4462 | KnownZero &= KnownZeroRHS; |
| 4463 | KnownOne &= KnownOneRHS; |
| 4464 | return; |
| 4465 | } |
| 4466 | } |
| 4467 | } |
| 4468 | |
| 4469 | //===----------------------------------------------------------------------===// |
| 4470 | // ARM Inline Assembly Support |
| 4471 | //===----------------------------------------------------------------------===// |
| 4472 | |
| 4473 | /// getConstraintType - Given a constraint letter, return the type of |
| 4474 | /// constraint it is for this target. |
| 4475 | ARMTargetLowering::ConstraintType |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 4476 | ARMTargetLowering::getConstraintType(const std::string &Constraint) const { |
| 4477 | if (Constraint.size() == 1) { |
| 4478 | switch (Constraint[0]) { |
| 4479 | default: break; |
| 4480 | case 'l': return C_RegisterClass; |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 4481 | case 'w': return C_RegisterClass; |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 4482 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4483 | } |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 4484 | return TargetLowering::getConstraintType(Constraint); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4485 | } |
| 4486 | |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 4487 | std::pair<unsigned, const TargetRegisterClass*> |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4488 | ARMTargetLowering::getRegForInlineAsmConstraint(const std::string &Constraint, |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4489 | EVT VT) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4490 | if (Constraint.size() == 1) { |
Jakob Stoklund Olesen | 09bf003 | 2010-01-14 18:19:56 +0000 | [diff] [blame] | 4491 | // GCC ARM Constraint Letters |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4492 | switch (Constraint[0]) { |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 4493 | case 'l': |
Jakob Stoklund Olesen | 09bf003 | 2010-01-14 18:19:56 +0000 | [diff] [blame] | 4494 | if (Subtarget->isThumb()) |
Jim Grosbach | 30eae3c | 2009-04-07 20:34:09 +0000 | [diff] [blame] | 4495 | return std::make_pair(0U, ARM::tGPRRegisterClass); |
| 4496 | else |
| 4497 | return std::make_pair(0U, ARM::GPRRegisterClass); |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 4498 | case 'r': |
| 4499 | return std::make_pair(0U, ARM::GPRRegisterClass); |
| 4500 | case 'w': |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4501 | if (VT == MVT::f32) |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 4502 | return std::make_pair(0U, ARM::SPRRegisterClass); |
Bob Wilson | 5afffae | 2009-12-18 01:03:29 +0000 | [diff] [blame] | 4503 | if (VT.getSizeInBits() == 64) |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 4504 | return std::make_pair(0U, ARM::DPRRegisterClass); |
Evan Cheng | d831cda | 2009-12-08 23:06:22 +0000 | [diff] [blame] | 4505 | if (VT.getSizeInBits() == 128) |
| 4506 | return std::make_pair(0U, ARM::QPRRegisterClass); |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 4507 | break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4508 | } |
| 4509 | } |
Bob Wilson | 33cc5cb | 2010-03-15 23:09:18 +0000 | [diff] [blame] | 4510 | if (StringRef("{cc}").equals_lower(Constraint)) |
| 4511 | return std::make_pair(0U, ARM::CCRRegisterClass); |
| 4512 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4513 | return TargetLowering::getRegForInlineAsmConstraint(Constraint, VT); |
| 4514 | } |
| 4515 | |
| 4516 | std::vector<unsigned> ARMTargetLowering:: |
| 4517 | getRegClassForInlineAsmConstraint(const std::string &Constraint, |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4518 | EVT VT) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4519 | if (Constraint.size() != 1) |
| 4520 | return std::vector<unsigned>(); |
| 4521 | |
| 4522 | switch (Constraint[0]) { // GCC ARM Constraint Letters |
| 4523 | default: break; |
| 4524 | case 'l': |
Jim Grosbach | 30eae3c | 2009-04-07 20:34:09 +0000 | [diff] [blame] | 4525 | return make_vector<unsigned>(ARM::R0, ARM::R1, ARM::R2, ARM::R3, |
| 4526 | ARM::R4, ARM::R5, ARM::R6, ARM::R7, |
| 4527 | 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4528 | case 'r': |
| 4529 | return make_vector<unsigned>(ARM::R0, ARM::R1, ARM::R2, ARM::R3, |
| 4530 | ARM::R4, ARM::R5, ARM::R6, ARM::R7, |
| 4531 | ARM::R8, ARM::R9, ARM::R10, ARM::R11, |
| 4532 | ARM::R12, ARM::LR, 0); |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 4533 | case 'w': |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4534 | if (VT == MVT::f32) |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 4535 | return make_vector<unsigned>(ARM::S0, ARM::S1, ARM::S2, ARM::S3, |
| 4536 | ARM::S4, ARM::S5, ARM::S6, ARM::S7, |
| 4537 | ARM::S8, ARM::S9, ARM::S10, ARM::S11, |
| 4538 | ARM::S12,ARM::S13,ARM::S14,ARM::S15, |
| 4539 | ARM::S16,ARM::S17,ARM::S18,ARM::S19, |
| 4540 | ARM::S20,ARM::S21,ARM::S22,ARM::S23, |
| 4541 | ARM::S24,ARM::S25,ARM::S26,ARM::S27, |
| 4542 | ARM::S28,ARM::S29,ARM::S30,ARM::S31, 0); |
Bob Wilson | 5afffae | 2009-12-18 01:03:29 +0000 | [diff] [blame] | 4543 | if (VT.getSizeInBits() == 64) |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 4544 | return make_vector<unsigned>(ARM::D0, ARM::D1, ARM::D2, ARM::D3, |
| 4545 | ARM::D4, ARM::D5, ARM::D6, ARM::D7, |
| 4546 | ARM::D8, ARM::D9, ARM::D10,ARM::D11, |
| 4547 | ARM::D12,ARM::D13,ARM::D14,ARM::D15, 0); |
Evan Cheng | d831cda | 2009-12-08 23:06:22 +0000 | [diff] [blame] | 4548 | if (VT.getSizeInBits() == 128) |
| 4549 | return make_vector<unsigned>(ARM::Q0, ARM::Q1, ARM::Q2, ARM::Q3, |
| 4550 | ARM::Q4, ARM::Q5, ARM::Q6, ARM::Q7, 0); |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 4551 | break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4552 | } |
| 4553 | |
| 4554 | return std::vector<unsigned>(); |
| 4555 | } |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 4556 | |
| 4557 | /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops |
| 4558 | /// vector. If it is invalid, don't add anything to Ops. |
| 4559 | void ARMTargetLowering::LowerAsmOperandForConstraint(SDValue Op, |
| 4560 | char Constraint, |
| 4561 | bool hasMemory, |
| 4562 | std::vector<SDValue>&Ops, |
| 4563 | SelectionDAG &DAG) const { |
| 4564 | SDValue Result(0, 0); |
| 4565 | |
| 4566 | switch (Constraint) { |
| 4567 | default: break; |
| 4568 | case 'I': case 'J': case 'K': case 'L': |
| 4569 | case 'M': case 'N': case 'O': |
| 4570 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op); |
| 4571 | if (!C) |
| 4572 | return; |
| 4573 | |
| 4574 | int64_t CVal64 = C->getSExtValue(); |
| 4575 | int CVal = (int) CVal64; |
| 4576 | // None of these constraints allow values larger than 32 bits. Check |
| 4577 | // that the value fits in an int. |
| 4578 | if (CVal != CVal64) |
| 4579 | return; |
| 4580 | |
| 4581 | switch (Constraint) { |
| 4582 | case 'I': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 4583 | if (Subtarget->isThumb1Only()) { |
| 4584 | // This must be a constant between 0 and 255, for ADD |
| 4585 | // immediates. |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 4586 | if (CVal >= 0 && CVal <= 255) |
| 4587 | break; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 4588 | } else if (Subtarget->isThumb2()) { |
| 4589 | // A constant that can be used as an immediate value in a |
| 4590 | // data-processing instruction. |
| 4591 | if (ARM_AM::getT2SOImmVal(CVal) != -1) |
| 4592 | break; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 4593 | } else { |
| 4594 | // A constant that can be used as an immediate value in a |
| 4595 | // data-processing instruction. |
| 4596 | if (ARM_AM::getSOImmVal(CVal) != -1) |
| 4597 | break; |
| 4598 | } |
| 4599 | return; |
| 4600 | |
| 4601 | case 'J': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 4602 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 4603 | // This must be a constant between -255 and -1, for negated ADD |
| 4604 | // immediates. This can be used in GCC with an "n" modifier that |
| 4605 | // prints the negated value, for use with SUB instructions. It is |
| 4606 | // not useful otherwise but is implemented for compatibility. |
| 4607 | if (CVal >= -255 && CVal <= -1) |
| 4608 | break; |
| 4609 | } else { |
| 4610 | // This must be a constant between -4095 and 4095. It is not clear |
| 4611 | // what this constraint is intended for. Implemented for |
| 4612 | // compatibility with GCC. |
| 4613 | if (CVal >= -4095 && CVal <= 4095) |
| 4614 | break; |
| 4615 | } |
| 4616 | return; |
| 4617 | |
| 4618 | case 'K': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 4619 | if (Subtarget->isThumb1Only()) { |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 4620 | // A 32-bit value where only one byte has a nonzero value. Exclude |
| 4621 | // zero to match GCC. This constraint is used by GCC internally for |
| 4622 | // constants that can be loaded with a move/shift combination. |
| 4623 | // It is not useful otherwise but is implemented for compatibility. |
| 4624 | if (CVal != 0 && ARM_AM::isThumbImmShiftedVal(CVal)) |
| 4625 | break; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 4626 | } else if (Subtarget->isThumb2()) { |
| 4627 | // A constant whose bitwise inverse can be used as an immediate |
| 4628 | // value in a data-processing instruction. This can be used in GCC |
| 4629 | // with a "B" modifier that prints the inverted value, for use with |
| 4630 | // BIC and MVN instructions. It is not useful otherwise but is |
| 4631 | // implemented for compatibility. |
| 4632 | if (ARM_AM::getT2SOImmVal(~CVal) != -1) |
| 4633 | break; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 4634 | } else { |
| 4635 | // A constant whose bitwise inverse can be used as an immediate |
| 4636 | // value in a data-processing instruction. This can be used in GCC |
| 4637 | // with a "B" modifier that prints the inverted value, for use with |
| 4638 | // BIC and MVN instructions. It is not useful otherwise but is |
| 4639 | // implemented for compatibility. |
| 4640 | if (ARM_AM::getSOImmVal(~CVal) != -1) |
| 4641 | break; |
| 4642 | } |
| 4643 | return; |
| 4644 | |
| 4645 | case 'L': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 4646 | if (Subtarget->isThumb1Only()) { |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 4647 | // This must be a constant between -7 and 7, |
| 4648 | // for 3-operand ADD/SUB immediate instructions. |
| 4649 | if (CVal >= -7 && CVal < 7) |
| 4650 | break; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 4651 | } else if (Subtarget->isThumb2()) { |
| 4652 | // A constant whose negation can be used as an immediate value in a |
| 4653 | // data-processing instruction. This can be used in GCC with an "n" |
| 4654 | // modifier that prints the negated value, for use with SUB |
| 4655 | // instructions. It is not useful otherwise but is implemented for |
| 4656 | // compatibility. |
| 4657 | if (ARM_AM::getT2SOImmVal(-CVal) != -1) |
| 4658 | break; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 4659 | } else { |
| 4660 | // A constant whose negation can be used as an immediate value in a |
| 4661 | // data-processing instruction. This can be used in GCC with an "n" |
| 4662 | // modifier that prints the negated value, for use with SUB |
| 4663 | // instructions. It is not useful otherwise but is implemented for |
| 4664 | // compatibility. |
| 4665 | if (ARM_AM::getSOImmVal(-CVal) != -1) |
| 4666 | break; |
| 4667 | } |
| 4668 | return; |
| 4669 | |
| 4670 | case 'M': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 4671 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 4672 | // This must be a multiple of 4 between 0 and 1020, for |
| 4673 | // ADD sp + immediate. |
| 4674 | if ((CVal >= 0 && CVal <= 1020) && ((CVal & 3) == 0)) |
| 4675 | break; |
| 4676 | } else { |
| 4677 | // A power of two or a constant between 0 and 32. This is used in |
| 4678 | // GCC for the shift amount on shifted register operands, but it is |
| 4679 | // useful in general for any shift amounts. |
| 4680 | if ((CVal >= 0 && CVal <= 32) || ((CVal & (CVal - 1)) == 0)) |
| 4681 | break; |
| 4682 | } |
| 4683 | return; |
| 4684 | |
| 4685 | case 'N': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 4686 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 4687 | // This must be a constant between 0 and 31, for shift amounts. |
| 4688 | if (CVal >= 0 && CVal <= 31) |
| 4689 | break; |
| 4690 | } |
| 4691 | return; |
| 4692 | |
| 4693 | case 'O': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 4694 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 4695 | // This must be a multiple of 4 between -508 and 508, for |
| 4696 | // ADD/SUB sp = sp + immediate. |
| 4697 | if ((CVal >= -508 && CVal <= 508) && ((CVal & 3) == 0)) |
| 4698 | break; |
| 4699 | } |
| 4700 | return; |
| 4701 | } |
| 4702 | Result = DAG.getTargetConstant(CVal, Op.getValueType()); |
| 4703 | break; |
| 4704 | } |
| 4705 | |
| 4706 | if (Result.getNode()) { |
| 4707 | Ops.push_back(Result); |
| 4708 | return; |
| 4709 | } |
| 4710 | return TargetLowering::LowerAsmOperandForConstraint(Op, Constraint, hasMemory, |
| 4711 | Ops, DAG); |
| 4712 | } |
Anton Korobeynikov | 48e1935 | 2009-09-23 19:04:09 +0000 | [diff] [blame] | 4713 | |
| 4714 | bool |
| 4715 | ARMTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const { |
| 4716 | // The ARM target isn't yet aware of offsets. |
| 4717 | return false; |
| 4718 | } |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 4719 | |
| 4720 | int ARM::getVFPf32Imm(const APFloat &FPImm) { |
| 4721 | APInt Imm = FPImm.bitcastToAPInt(); |
| 4722 | uint32_t Sign = Imm.lshr(31).getZExtValue() & 1; |
| 4723 | int32_t Exp = (Imm.lshr(23).getSExtValue() & 0xff) - 127; // -126 to 127 |
| 4724 | int64_t Mantissa = Imm.getZExtValue() & 0x7fffff; // 23 bits |
| 4725 | |
| 4726 | // We can handle 4 bits of mantissa. |
| 4727 | // mantissa = (16+UInt(e:f:g:h))/16. |
| 4728 | if (Mantissa & 0x7ffff) |
| 4729 | return -1; |
| 4730 | Mantissa >>= 19; |
| 4731 | if ((Mantissa & 0xf) != Mantissa) |
| 4732 | return -1; |
| 4733 | |
| 4734 | // We can handle 3 bits of exponent: exp == UInt(NOT(b):c:d)-3 |
| 4735 | if (Exp < -3 || Exp > 4) |
| 4736 | return -1; |
| 4737 | Exp = ((Exp+3) & 0x7) ^ 4; |
| 4738 | |
| 4739 | return ((int)Sign << 7) | (Exp << 4) | Mantissa; |
| 4740 | } |
| 4741 | |
| 4742 | int ARM::getVFPf64Imm(const APFloat &FPImm) { |
| 4743 | APInt Imm = FPImm.bitcastToAPInt(); |
| 4744 | uint64_t Sign = Imm.lshr(63).getZExtValue() & 1; |
| 4745 | int64_t Exp = (Imm.lshr(52).getSExtValue() & 0x7ff) - 1023; // -1022 to 1023 |
| 4746 | uint64_t Mantissa = Imm.getZExtValue() & 0xfffffffffffffLL; |
| 4747 | |
| 4748 | // We can handle 4 bits of mantissa. |
| 4749 | // mantissa = (16+UInt(e:f:g:h))/16. |
| 4750 | if (Mantissa & 0xffffffffffffLL) |
| 4751 | return -1; |
| 4752 | Mantissa >>= 48; |
| 4753 | if ((Mantissa & 0xf) != Mantissa) |
| 4754 | return -1; |
| 4755 | |
| 4756 | // We can handle 3 bits of exponent: exp == UInt(NOT(b):c:d)-3 |
| 4757 | if (Exp < -3 || Exp > 4) |
| 4758 | return -1; |
| 4759 | Exp = ((Exp+3) & 0x7) ^ 4; |
| 4760 | |
| 4761 | return ((int)Sign << 7) | (Exp << 4) | Mantissa; |
| 4762 | } |
| 4763 | |
| 4764 | /// isFPImmLegal - Returns true if the target can instruction select the |
| 4765 | /// specified FP immediate natively. If false, the legalizer will |
| 4766 | /// materialize the FP immediate as a load from a constant pool. |
| 4767 | bool ARMTargetLowering::isFPImmLegal(const APFloat &Imm, EVT VT) const { |
| 4768 | if (!Subtarget->hasVFP3()) |
| 4769 | return false; |
| 4770 | if (VT == MVT::f32) |
| 4771 | return ARM::getVFPf32Imm(Imm) != -1; |
| 4772 | if (VT == MVT::f64) |
| 4773 | return ARM::getVFPf64Imm(Imm) != -1; |
| 4774 | return false; |
| 4775 | } |