Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1 | //===-- ARMISelLowering.cpp - ARM DAG Lowering Implementation -------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines the interfaces that ARM uses to lower LLVM code into a |
| 11 | // selection DAG. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 15 | #define DEBUG_TYPE "arm-isel" |
Craig Topper | c1f6f42 | 2012-03-17 07:33:42 +0000 | [diff] [blame] | 16 | #include "ARMISelLowering.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 17 | #include "ARM.h" |
Eric Christopher | 6f2ccef | 2010-09-10 22:42:06 +0000 | [diff] [blame] | 18 | #include "ARMCallingConv.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 19 | #include "ARMConstantPoolValue.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 20 | #include "ARMMachineFunctionInfo.h" |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 21 | #include "ARMPerfectShuffle.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 22 | #include "ARMRegisterInfo.h" |
| 23 | #include "ARMSubtarget.h" |
| 24 | #include "ARMTargetMachine.h" |
Chris Lattner | 80ec279 | 2009-08-02 00:34:36 +0000 | [diff] [blame] | 25 | #include "ARMTargetObjectFile.h" |
Evan Cheng | ee04a6d | 2011-07-20 23:34:39 +0000 | [diff] [blame] | 26 | #include "MCTargetDesc/ARMAddressingModes.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 27 | #include "llvm/CallingConv.h" |
| 28 | #include "llvm/Constants.h" |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 29 | #include "llvm/Function.h" |
Benjamin Kramer | 174101e | 2009-10-20 11:44:38 +0000 | [diff] [blame] | 30 | #include "llvm/GlobalValue.h" |
Evan Cheng | 2770747 | 2007-03-16 08:43:56 +0000 | [diff] [blame] | 31 | #include "llvm/Instruction.h" |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 32 | #include "llvm/Instructions.h" |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 33 | #include "llvm/Intrinsics.h" |
Benjamin Kramer | 174101e | 2009-10-20 11:44:38 +0000 | [diff] [blame] | 34 | #include "llvm/Type.h" |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 35 | #include "llvm/CodeGen/CallingConvLower.h" |
Evan Cheng | 55d4200 | 2011-01-08 01:24:27 +0000 | [diff] [blame] | 36 | #include "llvm/CodeGen/IntrinsicLowering.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 37 | #include "llvm/CodeGen/MachineBasicBlock.h" |
| 38 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 39 | #include "llvm/CodeGen/MachineFunction.h" |
| 40 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 41 | #include "llvm/CodeGen/MachineModuleInfo.h" |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 42 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 43 | #include "llvm/CodeGen/SelectionDAG.h" |
Bill Wendling | 94a1c63 | 2010-03-09 02:46:12 +0000 | [diff] [blame] | 44 | #include "llvm/MC/MCSectionMachO.h" |
Evan Cheng | b6ab254 | 2007-01-31 08:40:13 +0000 | [diff] [blame] | 45 | #include "llvm/Target/TargetOptions.h" |
Evan Cheng | 55d4200 | 2011-01-08 01:24:27 +0000 | [diff] [blame] | 46 | #include "llvm/ADT/StringExtras.h" |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 47 | #include "llvm/ADT/Statistic.h" |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 48 | #include "llvm/Support/CommandLine.h" |
Torok Edwin | ab7c09b | 2009-07-08 18:01:40 +0000 | [diff] [blame] | 49 | #include "llvm/Support/ErrorHandling.h" |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 50 | #include "llvm/Support/MathExtras.h" |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 51 | #include "llvm/Support/raw_ostream.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 52 | using namespace llvm; |
| 53 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 54 | STATISTIC(NumTailCalls, "Number of tail calls"); |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 55 | STATISTIC(NumMovwMovt, "Number of GAs materialized with movw + movt"); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 56 | |
Bob Wilson | 703af3a | 2010-08-13 22:43:33 +0000 | [diff] [blame] | 57 | // This option should go away when tail calls fully work. |
| 58 | static cl::opt<bool> |
| 59 | EnableARMTailCalls("arm-tail-calls", cl::Hidden, |
| 60 | cl::desc("Generate tail calls (TEMPORARY OPTION)."), |
| 61 | cl::init(false)); |
| 62 | |
Eric Christopher | 836c624 | 2010-12-15 23:47:29 +0000 | [diff] [blame] | 63 | cl::opt<bool> |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 64 | EnableARMLongCalls("arm-long-calls", cl::Hidden, |
Evan Cheng | 515fe3a | 2010-07-08 02:08:50 +0000 | [diff] [blame] | 65 | cl::desc("Generate calls via indirect call instructions"), |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 66 | cl::init(false)); |
| 67 | |
Evan Cheng | 46df4eb | 2010-06-16 07:35:02 +0000 | [diff] [blame] | 68 | static cl::opt<bool> |
| 69 | ARMInterworking("arm-interworking", cl::Hidden, |
| 70 | cl::desc("Enable / disable ARM interworking (for debugging only)"), |
| 71 | cl::init(true)); |
| 72 | |
Benjamin Kramer | 0861f57 | 2011-11-26 23:01:57 +0000 | [diff] [blame] | 73 | namespace { |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 74 | class ARMCCState : public CCState { |
| 75 | public: |
| 76 | ARMCCState(CallingConv::ID CC, bool isVarArg, MachineFunction &MF, |
| 77 | const TargetMachine &TM, SmallVector<CCValAssign, 16> &locs, |
| 78 | LLVMContext &C, ParmContext PC) |
| 79 | : CCState(CC, isVarArg, MF, TM, locs, C) { |
| 80 | assert(((PC == Call) || (PC == Prologue)) && |
| 81 | "ARMCCState users must specify whether their context is call" |
| 82 | "or prologue generation."); |
| 83 | CallOrPrologue = PC; |
| 84 | } |
| 85 | }; |
| 86 | } |
| 87 | |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 88 | // The APCS parameter registers. |
Craig Topper | c5eaae4 | 2012-03-11 07:57:25 +0000 | [diff] [blame] | 89 | static const uint16_t GPRArgRegs[] = { |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 90 | ARM::R0, ARM::R1, ARM::R2, ARM::R3 |
| 91 | }; |
| 92 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 93 | void ARMTargetLowering::addTypeForNEON(EVT VT, EVT PromotedLdStVT, |
| 94 | EVT PromotedBitwiseVT) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 95 | if (VT != PromotedLdStVT) { |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 96 | setOperationAction(ISD::LOAD, VT.getSimpleVT(), Promote); |
Owen Anderson | d6662ad | 2009-08-10 20:46:15 +0000 | [diff] [blame] | 97 | AddPromotedToType (ISD::LOAD, VT.getSimpleVT(), |
| 98 | PromotedLdStVT.getSimpleVT()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 99 | |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 100 | setOperationAction(ISD::STORE, VT.getSimpleVT(), Promote); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 101 | AddPromotedToType (ISD::STORE, VT.getSimpleVT(), |
Owen Anderson | d6662ad | 2009-08-10 20:46:15 +0000 | [diff] [blame] | 102 | PromotedLdStVT.getSimpleVT()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 103 | } |
| 104 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 105 | EVT ElemTy = VT.getVectorElementType(); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 106 | if (ElemTy != MVT::i64 && ElemTy != MVT::f64) |
Duncan Sands | 28b77e9 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 107 | setOperationAction(ISD::SETCC, VT.getSimpleVT(), Custom); |
Eli Friedman | 5c89cb8 | 2011-10-24 23:08:52 +0000 | [diff] [blame] | 108 | setOperationAction(ISD::INSERT_VECTOR_ELT, VT.getSimpleVT(), Custom); |
Bob Wilson | 3468c2e | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 109 | setOperationAction(ISD::EXTRACT_VECTOR_ELT, VT.getSimpleVT(), Custom); |
Eli Friedman | 14e809c | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 110 | if (ElemTy == MVT::i32) { |
| 111 | setOperationAction(ISD::SINT_TO_FP, VT.getSimpleVT(), Custom); |
| 112 | setOperationAction(ISD::UINT_TO_FP, VT.getSimpleVT(), Custom); |
| 113 | setOperationAction(ISD::FP_TO_SINT, VT.getSimpleVT(), Custom); |
| 114 | setOperationAction(ISD::FP_TO_UINT, VT.getSimpleVT(), Custom); |
| 115 | } else { |
Bob Wilson | 0696fdf | 2009-09-16 20:20:44 +0000 | [diff] [blame] | 116 | setOperationAction(ISD::SINT_TO_FP, VT.getSimpleVT(), Expand); |
| 117 | setOperationAction(ISD::UINT_TO_FP, VT.getSimpleVT(), Expand); |
| 118 | setOperationAction(ISD::FP_TO_SINT, VT.getSimpleVT(), Expand); |
| 119 | setOperationAction(ISD::FP_TO_UINT, VT.getSimpleVT(), Expand); |
| 120 | } |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 121 | setOperationAction(ISD::BUILD_VECTOR, VT.getSimpleVT(), Custom); |
| 122 | setOperationAction(ISD::VECTOR_SHUFFLE, VT.getSimpleVT(), Custom); |
Bob Wilson | 07f6e80 | 2010-06-16 21:34:01 +0000 | [diff] [blame] | 123 | setOperationAction(ISD::CONCAT_VECTORS, VT.getSimpleVT(), Legal); |
Bob Wilson | 5e8b833 | 2011-01-07 04:59:04 +0000 | [diff] [blame] | 124 | setOperationAction(ISD::EXTRACT_SUBVECTOR, VT.getSimpleVT(), Legal); |
Bob Wilson | d0910c4 | 2010-04-06 22:02:24 +0000 | [diff] [blame] | 125 | setOperationAction(ISD::SELECT, VT.getSimpleVT(), Expand); |
| 126 | setOperationAction(ISD::SELECT_CC, VT.getSimpleVT(), Expand); |
Eli Friedman | 15f58c5 | 2011-11-11 03:16:38 +0000 | [diff] [blame] | 127 | setOperationAction(ISD::SIGN_EXTEND_INREG, VT.getSimpleVT(), Expand); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 128 | if (VT.isInteger()) { |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 129 | setOperationAction(ISD::SHL, VT.getSimpleVT(), Custom); |
| 130 | setOperationAction(ISD::SRA, VT.getSimpleVT(), Custom); |
| 131 | setOperationAction(ISD::SRL, VT.getSimpleVT(), Custom); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | // Promote all bit-wise operations. |
| 135 | if (VT.isInteger() && VT != PromotedBitwiseVT) { |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 136 | setOperationAction(ISD::AND, VT.getSimpleVT(), Promote); |
Owen Anderson | d6662ad | 2009-08-10 20:46:15 +0000 | [diff] [blame] | 137 | AddPromotedToType (ISD::AND, VT.getSimpleVT(), |
| 138 | PromotedBitwiseVT.getSimpleVT()); |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 139 | setOperationAction(ISD::OR, VT.getSimpleVT(), Promote); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 140 | AddPromotedToType (ISD::OR, VT.getSimpleVT(), |
Owen Anderson | d6662ad | 2009-08-10 20:46:15 +0000 | [diff] [blame] | 141 | PromotedBitwiseVT.getSimpleVT()); |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 142 | setOperationAction(ISD::XOR, VT.getSimpleVT(), Promote); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 143 | AddPromotedToType (ISD::XOR, VT.getSimpleVT(), |
Owen Anderson | d6662ad | 2009-08-10 20:46:15 +0000 | [diff] [blame] | 144 | PromotedBitwiseVT.getSimpleVT()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 145 | } |
Bob Wilson | 1633076 | 2009-09-16 00:17:28 +0000 | [diff] [blame] | 146 | |
| 147 | // Neon does not support vector divide/remainder operations. |
| 148 | setOperationAction(ISD::SDIV, VT.getSimpleVT(), Expand); |
| 149 | setOperationAction(ISD::UDIV, VT.getSimpleVT(), Expand); |
| 150 | setOperationAction(ISD::FDIV, VT.getSimpleVT(), Expand); |
| 151 | setOperationAction(ISD::SREM, VT.getSimpleVT(), Expand); |
| 152 | setOperationAction(ISD::UREM, VT.getSimpleVT(), Expand); |
| 153 | setOperationAction(ISD::FREM, VT.getSimpleVT(), Expand); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 154 | } |
| 155 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 156 | void ARMTargetLowering::addDRTypeForNEON(EVT VT) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 157 | addRegisterClass(VT, ARM::DPRRegisterClass); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 158 | addTypeForNEON(VT, MVT::f64, MVT::v2i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 159 | } |
| 160 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 161 | void ARMTargetLowering::addQRTypeForNEON(EVT VT) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 162 | addRegisterClass(VT, ARM::QPRRegisterClass); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 163 | addTypeForNEON(VT, MVT::v2f64, MVT::v4i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 164 | } |
| 165 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 166 | static TargetLoweringObjectFile *createTLOF(TargetMachine &TM) { |
| 167 | if (TM.getSubtarget<ARMSubtarget>().isTargetDarwin()) |
Bill Wendling | 505ad8b | 2010-03-15 21:09:38 +0000 | [diff] [blame] | 168 | return new TargetLoweringObjectFileMachO(); |
Bill Wendling | 94a1c63 | 2010-03-09 02:46:12 +0000 | [diff] [blame] | 169 | |
Chris Lattner | 80ec279 | 2009-08-02 00:34:36 +0000 | [diff] [blame] | 170 | return new ARMElfTargetObjectFile(); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 171 | } |
| 172 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 173 | ARMTargetLowering::ARMTargetLowering(TargetMachine &TM) |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 174 | : TargetLowering(TM, createTLOF(TM)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 175 | Subtarget = &TM.getSubtarget<ARMSubtarget>(); |
Evan Cheng | 3144687 | 2010-07-23 22:39:59 +0000 | [diff] [blame] | 176 | RegInfo = TM.getRegisterInfo(); |
Evan Cheng | 3ef1c87 | 2010-09-10 01:29:16 +0000 | [diff] [blame] | 177 | Itins = TM.getInstrItineraryData(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 178 | |
Duncan Sands | 28b77e9 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 179 | setBooleanVectorContents(ZeroOrNegativeOneBooleanContent); |
| 180 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 181 | if (Subtarget->isTargetDarwin()) { |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 182 | // Uses VFP for Thumb libfuncs if available. |
| 183 | if (Subtarget->isThumb() && Subtarget->hasVFP2()) { |
| 184 | // Single-precision floating-point arithmetic. |
| 185 | setLibcallName(RTLIB::ADD_F32, "__addsf3vfp"); |
| 186 | setLibcallName(RTLIB::SUB_F32, "__subsf3vfp"); |
| 187 | setLibcallName(RTLIB::MUL_F32, "__mulsf3vfp"); |
| 188 | setLibcallName(RTLIB::DIV_F32, "__divsf3vfp"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 189 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 190 | // Double-precision floating-point arithmetic. |
| 191 | setLibcallName(RTLIB::ADD_F64, "__adddf3vfp"); |
| 192 | setLibcallName(RTLIB::SUB_F64, "__subdf3vfp"); |
| 193 | setLibcallName(RTLIB::MUL_F64, "__muldf3vfp"); |
| 194 | setLibcallName(RTLIB::DIV_F64, "__divdf3vfp"); |
Evan Cheng | 193f850 | 2007-01-31 09:30:58 +0000 | [diff] [blame] | 195 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 196 | // Single-precision comparisons. |
| 197 | setLibcallName(RTLIB::OEQ_F32, "__eqsf2vfp"); |
| 198 | setLibcallName(RTLIB::UNE_F32, "__nesf2vfp"); |
| 199 | setLibcallName(RTLIB::OLT_F32, "__ltsf2vfp"); |
| 200 | setLibcallName(RTLIB::OLE_F32, "__lesf2vfp"); |
| 201 | setLibcallName(RTLIB::OGE_F32, "__gesf2vfp"); |
| 202 | setLibcallName(RTLIB::OGT_F32, "__gtsf2vfp"); |
| 203 | setLibcallName(RTLIB::UO_F32, "__unordsf2vfp"); |
| 204 | setLibcallName(RTLIB::O_F32, "__unordsf2vfp"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 205 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 206 | setCmpLibcallCC(RTLIB::OEQ_F32, ISD::SETNE); |
| 207 | setCmpLibcallCC(RTLIB::UNE_F32, ISD::SETNE); |
| 208 | setCmpLibcallCC(RTLIB::OLT_F32, ISD::SETNE); |
| 209 | setCmpLibcallCC(RTLIB::OLE_F32, ISD::SETNE); |
| 210 | setCmpLibcallCC(RTLIB::OGE_F32, ISD::SETNE); |
| 211 | setCmpLibcallCC(RTLIB::OGT_F32, ISD::SETNE); |
| 212 | setCmpLibcallCC(RTLIB::UO_F32, ISD::SETNE); |
| 213 | setCmpLibcallCC(RTLIB::O_F32, ISD::SETEQ); |
Evan Cheng | 193f850 | 2007-01-31 09:30:58 +0000 | [diff] [blame] | 214 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 215 | // Double-precision comparisons. |
| 216 | setLibcallName(RTLIB::OEQ_F64, "__eqdf2vfp"); |
| 217 | setLibcallName(RTLIB::UNE_F64, "__nedf2vfp"); |
| 218 | setLibcallName(RTLIB::OLT_F64, "__ltdf2vfp"); |
| 219 | setLibcallName(RTLIB::OLE_F64, "__ledf2vfp"); |
| 220 | setLibcallName(RTLIB::OGE_F64, "__gedf2vfp"); |
| 221 | setLibcallName(RTLIB::OGT_F64, "__gtdf2vfp"); |
| 222 | setLibcallName(RTLIB::UO_F64, "__unorddf2vfp"); |
| 223 | setLibcallName(RTLIB::O_F64, "__unorddf2vfp"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 224 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 225 | setCmpLibcallCC(RTLIB::OEQ_F64, ISD::SETNE); |
| 226 | setCmpLibcallCC(RTLIB::UNE_F64, ISD::SETNE); |
| 227 | setCmpLibcallCC(RTLIB::OLT_F64, ISD::SETNE); |
| 228 | setCmpLibcallCC(RTLIB::OLE_F64, ISD::SETNE); |
| 229 | setCmpLibcallCC(RTLIB::OGE_F64, ISD::SETNE); |
| 230 | setCmpLibcallCC(RTLIB::OGT_F64, ISD::SETNE); |
| 231 | setCmpLibcallCC(RTLIB::UO_F64, ISD::SETNE); |
| 232 | setCmpLibcallCC(RTLIB::O_F64, ISD::SETEQ); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 233 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 234 | // Floating-point to integer conversions. |
| 235 | // i64 conversions are done via library routines even when generating VFP |
| 236 | // instructions, so use the same ones. |
| 237 | setLibcallName(RTLIB::FPTOSINT_F64_I32, "__fixdfsivfp"); |
| 238 | setLibcallName(RTLIB::FPTOUINT_F64_I32, "__fixunsdfsivfp"); |
| 239 | setLibcallName(RTLIB::FPTOSINT_F32_I32, "__fixsfsivfp"); |
| 240 | setLibcallName(RTLIB::FPTOUINT_F32_I32, "__fixunssfsivfp"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 241 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 242 | // Conversions between floating types. |
| 243 | setLibcallName(RTLIB::FPROUND_F64_F32, "__truncdfsf2vfp"); |
| 244 | setLibcallName(RTLIB::FPEXT_F32_F64, "__extendsfdf2vfp"); |
| 245 | |
| 246 | // Integer to floating-point conversions. |
| 247 | // i64 conversions are done via library routines even when generating VFP |
| 248 | // instructions, so use the same ones. |
Bob Wilson | 2a14c52 | 2009-03-20 23:16:43 +0000 | [diff] [blame] | 249 | // FIXME: There appears to be some naming inconsistency in ARM libgcc: |
| 250 | // e.g., __floatunsidf vs. __floatunssidfvfp. |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 251 | setLibcallName(RTLIB::SINTTOFP_I32_F64, "__floatsidfvfp"); |
| 252 | setLibcallName(RTLIB::UINTTOFP_I32_F64, "__floatunssidfvfp"); |
| 253 | setLibcallName(RTLIB::SINTTOFP_I32_F32, "__floatsisfvfp"); |
| 254 | setLibcallName(RTLIB::UINTTOFP_I32_F32, "__floatunssisfvfp"); |
| 255 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 256 | } |
| 257 | |
Bob Wilson | 2f95461 | 2009-05-22 17:38:41 +0000 | [diff] [blame] | 258 | // These libcalls are not available in 32-bit. |
| 259 | setLibcallName(RTLIB::SHL_I128, 0); |
| 260 | setLibcallName(RTLIB::SRL_I128, 0); |
| 261 | setLibcallName(RTLIB::SRA_I128, 0); |
| 262 | |
Evan Cheng | 0704327 | 2012-02-21 20:46:00 +0000 | [diff] [blame] | 263 | if (Subtarget->isAAPCS_ABI() && !Subtarget->isTargetDarwin()) { |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 264 | // Double-precision floating-point arithmetic helper functions |
Anton Korobeynikov | 4f922f2 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 265 | // RTABI chapter 4.1.2, Table 2 |
| 266 | setLibcallName(RTLIB::ADD_F64, "__aeabi_dadd"); |
| 267 | setLibcallName(RTLIB::DIV_F64, "__aeabi_ddiv"); |
| 268 | setLibcallName(RTLIB::MUL_F64, "__aeabi_dmul"); |
| 269 | setLibcallName(RTLIB::SUB_F64, "__aeabi_dsub"); |
| 270 | setLibcallCallingConv(RTLIB::ADD_F64, CallingConv::ARM_AAPCS); |
| 271 | setLibcallCallingConv(RTLIB::DIV_F64, CallingConv::ARM_AAPCS); |
| 272 | setLibcallCallingConv(RTLIB::MUL_F64, CallingConv::ARM_AAPCS); |
| 273 | setLibcallCallingConv(RTLIB::SUB_F64, CallingConv::ARM_AAPCS); |
| 274 | |
| 275 | // Double-precision floating-point comparison helper functions |
| 276 | // RTABI chapter 4.1.2, Table 3 |
| 277 | setLibcallName(RTLIB::OEQ_F64, "__aeabi_dcmpeq"); |
| 278 | setCmpLibcallCC(RTLIB::OEQ_F64, ISD::SETNE); |
| 279 | setLibcallName(RTLIB::UNE_F64, "__aeabi_dcmpeq"); |
| 280 | setCmpLibcallCC(RTLIB::UNE_F64, ISD::SETEQ); |
| 281 | setLibcallName(RTLIB::OLT_F64, "__aeabi_dcmplt"); |
| 282 | setCmpLibcallCC(RTLIB::OLT_F64, ISD::SETNE); |
| 283 | setLibcallName(RTLIB::OLE_F64, "__aeabi_dcmple"); |
| 284 | setCmpLibcallCC(RTLIB::OLE_F64, ISD::SETNE); |
| 285 | setLibcallName(RTLIB::OGE_F64, "__aeabi_dcmpge"); |
| 286 | setCmpLibcallCC(RTLIB::OGE_F64, ISD::SETNE); |
| 287 | setLibcallName(RTLIB::OGT_F64, "__aeabi_dcmpgt"); |
| 288 | setCmpLibcallCC(RTLIB::OGT_F64, ISD::SETNE); |
| 289 | setLibcallName(RTLIB::UO_F64, "__aeabi_dcmpun"); |
| 290 | setCmpLibcallCC(RTLIB::UO_F64, ISD::SETNE); |
| 291 | setLibcallName(RTLIB::O_F64, "__aeabi_dcmpun"); |
| 292 | setCmpLibcallCC(RTLIB::O_F64, ISD::SETEQ); |
| 293 | setLibcallCallingConv(RTLIB::OEQ_F64, CallingConv::ARM_AAPCS); |
| 294 | setLibcallCallingConv(RTLIB::UNE_F64, CallingConv::ARM_AAPCS); |
| 295 | setLibcallCallingConv(RTLIB::OLT_F64, CallingConv::ARM_AAPCS); |
| 296 | setLibcallCallingConv(RTLIB::OLE_F64, CallingConv::ARM_AAPCS); |
| 297 | setLibcallCallingConv(RTLIB::OGE_F64, CallingConv::ARM_AAPCS); |
| 298 | setLibcallCallingConv(RTLIB::OGT_F64, CallingConv::ARM_AAPCS); |
| 299 | setLibcallCallingConv(RTLIB::UO_F64, CallingConv::ARM_AAPCS); |
| 300 | setLibcallCallingConv(RTLIB::O_F64, CallingConv::ARM_AAPCS); |
| 301 | |
| 302 | // Single-precision floating-point arithmetic helper functions |
| 303 | // RTABI chapter 4.1.2, Table 4 |
| 304 | setLibcallName(RTLIB::ADD_F32, "__aeabi_fadd"); |
| 305 | setLibcallName(RTLIB::DIV_F32, "__aeabi_fdiv"); |
| 306 | setLibcallName(RTLIB::MUL_F32, "__aeabi_fmul"); |
| 307 | setLibcallName(RTLIB::SUB_F32, "__aeabi_fsub"); |
| 308 | setLibcallCallingConv(RTLIB::ADD_F32, CallingConv::ARM_AAPCS); |
| 309 | setLibcallCallingConv(RTLIB::DIV_F32, CallingConv::ARM_AAPCS); |
| 310 | setLibcallCallingConv(RTLIB::MUL_F32, CallingConv::ARM_AAPCS); |
| 311 | setLibcallCallingConv(RTLIB::SUB_F32, CallingConv::ARM_AAPCS); |
| 312 | |
| 313 | // Single-precision floating-point comparison helper functions |
| 314 | // RTABI chapter 4.1.2, Table 5 |
| 315 | setLibcallName(RTLIB::OEQ_F32, "__aeabi_fcmpeq"); |
| 316 | setCmpLibcallCC(RTLIB::OEQ_F32, ISD::SETNE); |
| 317 | setLibcallName(RTLIB::UNE_F32, "__aeabi_fcmpeq"); |
| 318 | setCmpLibcallCC(RTLIB::UNE_F32, ISD::SETEQ); |
| 319 | setLibcallName(RTLIB::OLT_F32, "__aeabi_fcmplt"); |
| 320 | setCmpLibcallCC(RTLIB::OLT_F32, ISD::SETNE); |
| 321 | setLibcallName(RTLIB::OLE_F32, "__aeabi_fcmple"); |
| 322 | setCmpLibcallCC(RTLIB::OLE_F32, ISD::SETNE); |
| 323 | setLibcallName(RTLIB::OGE_F32, "__aeabi_fcmpge"); |
| 324 | setCmpLibcallCC(RTLIB::OGE_F32, ISD::SETNE); |
| 325 | setLibcallName(RTLIB::OGT_F32, "__aeabi_fcmpgt"); |
| 326 | setCmpLibcallCC(RTLIB::OGT_F32, ISD::SETNE); |
| 327 | setLibcallName(RTLIB::UO_F32, "__aeabi_fcmpun"); |
| 328 | setCmpLibcallCC(RTLIB::UO_F32, ISD::SETNE); |
| 329 | setLibcallName(RTLIB::O_F32, "__aeabi_fcmpun"); |
| 330 | setCmpLibcallCC(RTLIB::O_F32, ISD::SETEQ); |
| 331 | setLibcallCallingConv(RTLIB::OEQ_F32, CallingConv::ARM_AAPCS); |
| 332 | setLibcallCallingConv(RTLIB::UNE_F32, CallingConv::ARM_AAPCS); |
| 333 | setLibcallCallingConv(RTLIB::OLT_F32, CallingConv::ARM_AAPCS); |
| 334 | setLibcallCallingConv(RTLIB::OLE_F32, CallingConv::ARM_AAPCS); |
| 335 | setLibcallCallingConv(RTLIB::OGE_F32, CallingConv::ARM_AAPCS); |
| 336 | setLibcallCallingConv(RTLIB::OGT_F32, CallingConv::ARM_AAPCS); |
| 337 | setLibcallCallingConv(RTLIB::UO_F32, CallingConv::ARM_AAPCS); |
| 338 | setLibcallCallingConv(RTLIB::O_F32, CallingConv::ARM_AAPCS); |
| 339 | |
| 340 | // Floating-point to integer conversions. |
| 341 | // RTABI chapter 4.1.2, Table 6 |
| 342 | setLibcallName(RTLIB::FPTOSINT_F64_I32, "__aeabi_d2iz"); |
| 343 | setLibcallName(RTLIB::FPTOUINT_F64_I32, "__aeabi_d2uiz"); |
| 344 | setLibcallName(RTLIB::FPTOSINT_F64_I64, "__aeabi_d2lz"); |
| 345 | setLibcallName(RTLIB::FPTOUINT_F64_I64, "__aeabi_d2ulz"); |
| 346 | setLibcallName(RTLIB::FPTOSINT_F32_I32, "__aeabi_f2iz"); |
| 347 | setLibcallName(RTLIB::FPTOUINT_F32_I32, "__aeabi_f2uiz"); |
| 348 | setLibcallName(RTLIB::FPTOSINT_F32_I64, "__aeabi_f2lz"); |
| 349 | setLibcallName(RTLIB::FPTOUINT_F32_I64, "__aeabi_f2ulz"); |
| 350 | setLibcallCallingConv(RTLIB::FPTOSINT_F64_I32, CallingConv::ARM_AAPCS); |
| 351 | setLibcallCallingConv(RTLIB::FPTOUINT_F64_I32, CallingConv::ARM_AAPCS); |
| 352 | setLibcallCallingConv(RTLIB::FPTOSINT_F64_I64, CallingConv::ARM_AAPCS); |
| 353 | setLibcallCallingConv(RTLIB::FPTOUINT_F64_I64, CallingConv::ARM_AAPCS); |
| 354 | setLibcallCallingConv(RTLIB::FPTOSINT_F32_I32, CallingConv::ARM_AAPCS); |
| 355 | setLibcallCallingConv(RTLIB::FPTOUINT_F32_I32, CallingConv::ARM_AAPCS); |
| 356 | setLibcallCallingConv(RTLIB::FPTOSINT_F32_I64, CallingConv::ARM_AAPCS); |
| 357 | setLibcallCallingConv(RTLIB::FPTOUINT_F32_I64, CallingConv::ARM_AAPCS); |
| 358 | |
| 359 | // Conversions between floating types. |
| 360 | // RTABI chapter 4.1.2, Table 7 |
| 361 | setLibcallName(RTLIB::FPROUND_F64_F32, "__aeabi_d2f"); |
| 362 | setLibcallName(RTLIB::FPEXT_F32_F64, "__aeabi_f2d"); |
| 363 | setLibcallCallingConv(RTLIB::FPROUND_F64_F32, CallingConv::ARM_AAPCS); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 364 | setLibcallCallingConv(RTLIB::FPEXT_F32_F64, CallingConv::ARM_AAPCS); |
Anton Korobeynikov | 4f922f2 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 365 | |
| 366 | // Integer to floating-point conversions. |
| 367 | // RTABI chapter 4.1.2, Table 8 |
| 368 | setLibcallName(RTLIB::SINTTOFP_I32_F64, "__aeabi_i2d"); |
| 369 | setLibcallName(RTLIB::UINTTOFP_I32_F64, "__aeabi_ui2d"); |
| 370 | setLibcallName(RTLIB::SINTTOFP_I64_F64, "__aeabi_l2d"); |
| 371 | setLibcallName(RTLIB::UINTTOFP_I64_F64, "__aeabi_ul2d"); |
| 372 | setLibcallName(RTLIB::SINTTOFP_I32_F32, "__aeabi_i2f"); |
| 373 | setLibcallName(RTLIB::UINTTOFP_I32_F32, "__aeabi_ui2f"); |
| 374 | setLibcallName(RTLIB::SINTTOFP_I64_F32, "__aeabi_l2f"); |
| 375 | setLibcallName(RTLIB::UINTTOFP_I64_F32, "__aeabi_ul2f"); |
| 376 | setLibcallCallingConv(RTLIB::SINTTOFP_I32_F64, CallingConv::ARM_AAPCS); |
| 377 | setLibcallCallingConv(RTLIB::UINTTOFP_I32_F64, CallingConv::ARM_AAPCS); |
| 378 | setLibcallCallingConv(RTLIB::SINTTOFP_I64_F64, CallingConv::ARM_AAPCS); |
| 379 | setLibcallCallingConv(RTLIB::UINTTOFP_I64_F64, CallingConv::ARM_AAPCS); |
| 380 | setLibcallCallingConv(RTLIB::SINTTOFP_I32_F32, CallingConv::ARM_AAPCS); |
| 381 | setLibcallCallingConv(RTLIB::UINTTOFP_I32_F32, CallingConv::ARM_AAPCS); |
| 382 | setLibcallCallingConv(RTLIB::SINTTOFP_I64_F32, CallingConv::ARM_AAPCS); |
| 383 | setLibcallCallingConv(RTLIB::UINTTOFP_I64_F32, CallingConv::ARM_AAPCS); |
| 384 | |
| 385 | // Long long helper functions |
| 386 | // RTABI chapter 4.2, Table 9 |
| 387 | setLibcallName(RTLIB::MUL_I64, "__aeabi_lmul"); |
Anton Korobeynikov | 4f922f2 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 388 | setLibcallName(RTLIB::SHL_I64, "__aeabi_llsl"); |
| 389 | setLibcallName(RTLIB::SRL_I64, "__aeabi_llsr"); |
| 390 | setLibcallName(RTLIB::SRA_I64, "__aeabi_lasr"); |
| 391 | setLibcallCallingConv(RTLIB::MUL_I64, CallingConv::ARM_AAPCS); |
| 392 | setLibcallCallingConv(RTLIB::SDIV_I64, CallingConv::ARM_AAPCS); |
| 393 | setLibcallCallingConv(RTLIB::UDIV_I64, CallingConv::ARM_AAPCS); |
| 394 | setLibcallCallingConv(RTLIB::SHL_I64, CallingConv::ARM_AAPCS); |
| 395 | setLibcallCallingConv(RTLIB::SRL_I64, CallingConv::ARM_AAPCS); |
| 396 | setLibcallCallingConv(RTLIB::SRA_I64, CallingConv::ARM_AAPCS); |
| 397 | |
| 398 | // Integer division functions |
| 399 | // RTABI chapter 4.3.1 |
| 400 | setLibcallName(RTLIB::SDIV_I8, "__aeabi_idiv"); |
| 401 | setLibcallName(RTLIB::SDIV_I16, "__aeabi_idiv"); |
| 402 | setLibcallName(RTLIB::SDIV_I32, "__aeabi_idiv"); |
Anton Korobeynikov | 6edd588 | 2012-01-29 09:11:50 +0000 | [diff] [blame] | 403 | setLibcallName(RTLIB::SDIV_I64, "__aeabi_ldivmod"); |
Anton Korobeynikov | 4f922f2 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 404 | setLibcallName(RTLIB::UDIV_I8, "__aeabi_uidiv"); |
| 405 | setLibcallName(RTLIB::UDIV_I16, "__aeabi_uidiv"); |
| 406 | setLibcallName(RTLIB::UDIV_I32, "__aeabi_uidiv"); |
Anton Korobeynikov | 6edd588 | 2012-01-29 09:11:50 +0000 | [diff] [blame] | 407 | setLibcallName(RTLIB::UDIV_I64, "__aeabi_uldivmod"); |
Anton Korobeynikov | 4f922f2 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 408 | setLibcallCallingConv(RTLIB::SDIV_I8, CallingConv::ARM_AAPCS); |
| 409 | setLibcallCallingConv(RTLIB::SDIV_I16, CallingConv::ARM_AAPCS); |
| 410 | setLibcallCallingConv(RTLIB::SDIV_I32, CallingConv::ARM_AAPCS); |
Anton Korobeynikov | 6edd588 | 2012-01-29 09:11:50 +0000 | [diff] [blame] | 411 | setLibcallCallingConv(RTLIB::SDIV_I64, CallingConv::ARM_AAPCS); |
Anton Korobeynikov | 4f922f2 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 412 | setLibcallCallingConv(RTLIB::UDIV_I8, CallingConv::ARM_AAPCS); |
| 413 | setLibcallCallingConv(RTLIB::UDIV_I16, CallingConv::ARM_AAPCS); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 414 | setLibcallCallingConv(RTLIB::UDIV_I32, CallingConv::ARM_AAPCS); |
Anton Korobeynikov | 6edd588 | 2012-01-29 09:11:50 +0000 | [diff] [blame] | 415 | setLibcallCallingConv(RTLIB::UDIV_I64, CallingConv::ARM_AAPCS); |
Renato Golin | 1ec11fb | 2011-05-22 21:41:23 +0000 | [diff] [blame] | 416 | |
| 417 | // Memory operations |
| 418 | // RTABI chapter 4.3.4 |
| 419 | setLibcallName(RTLIB::MEMCPY, "__aeabi_memcpy"); |
| 420 | setLibcallName(RTLIB::MEMMOVE, "__aeabi_memmove"); |
| 421 | setLibcallName(RTLIB::MEMSET, "__aeabi_memset"); |
Anton Korobeynikov | 6edd588 | 2012-01-29 09:11:50 +0000 | [diff] [blame] | 422 | setLibcallCallingConv(RTLIB::MEMCPY, CallingConv::ARM_AAPCS); |
| 423 | setLibcallCallingConv(RTLIB::MEMMOVE, CallingConv::ARM_AAPCS); |
| 424 | setLibcallCallingConv(RTLIB::MEMSET, CallingConv::ARM_AAPCS); |
Anton Korobeynikov | 72977a4 | 2009-08-14 20:10:52 +0000 | [diff] [blame] | 425 | } |
| 426 | |
Bob Wilson | 2fef457 | 2011-10-07 16:59:21 +0000 | [diff] [blame] | 427 | // Use divmod compiler-rt calls for iOS 5.0 and later. |
| 428 | if (Subtarget->getTargetTriple().getOS() == Triple::IOS && |
| 429 | !Subtarget->getTargetTriple().isOSVersionLT(5, 0)) { |
| 430 | setLibcallName(RTLIB::SDIVREM_I32, "__divmodsi4"); |
| 431 | setLibcallName(RTLIB::UDIVREM_I32, "__udivmodsi4"); |
| 432 | } |
| 433 | |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 434 | if (Subtarget->isThumb1Only()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 435 | addRegisterClass(MVT::i32, ARM::tGPRRegisterClass); |
Jim Grosbach | 30eae3c | 2009-04-07 20:34:09 +0000 | [diff] [blame] | 436 | else |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 437 | addRegisterClass(MVT::i32, ARM::GPRRegisterClass); |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 438 | if (!TM.Options.UseSoftFloat && Subtarget->hasVFP2() && |
| 439 | !Subtarget->isThumb1Only()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 440 | addRegisterClass(MVT::f32, ARM::SPRRegisterClass); |
Jim Grosbach | fcba5e6 | 2010-08-11 15:44:15 +0000 | [diff] [blame] | 441 | if (!Subtarget->isFPOnlySP()) |
| 442 | addRegisterClass(MVT::f64, ARM::DPRRegisterClass); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 443 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 444 | setTruncStoreAction(MVT::f64, MVT::f32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 445 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 446 | |
Eli Friedman | 9f1f26a | 2011-11-08 01:43:53 +0000 | [diff] [blame] | 447 | for (unsigned VT = (unsigned)MVT::FIRST_VECTOR_VALUETYPE; |
| 448 | VT <= (unsigned)MVT::LAST_VECTOR_VALUETYPE; ++VT) { |
| 449 | for (unsigned InnerVT = (unsigned)MVT::FIRST_VECTOR_VALUETYPE; |
| 450 | InnerVT <= (unsigned)MVT::LAST_VECTOR_VALUETYPE; ++InnerVT) |
| 451 | setTruncStoreAction((MVT::SimpleValueType)VT, |
| 452 | (MVT::SimpleValueType)InnerVT, Expand); |
| 453 | setLoadExtAction(ISD::SEXTLOAD, (MVT::SimpleValueType)VT, Expand); |
| 454 | setLoadExtAction(ISD::ZEXTLOAD, (MVT::SimpleValueType)VT, Expand); |
| 455 | setLoadExtAction(ISD::EXTLOAD, (MVT::SimpleValueType)VT, Expand); |
| 456 | } |
| 457 | |
Lang Hames | 45b5f88 | 2012-03-15 18:49:02 +0000 | [diff] [blame] | 458 | setOperationAction(ISD::ConstantFP, MVT::f32, Custom); |
| 459 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 460 | if (Subtarget->hasNEON()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 461 | addDRTypeForNEON(MVT::v2f32); |
| 462 | addDRTypeForNEON(MVT::v8i8); |
| 463 | addDRTypeForNEON(MVT::v4i16); |
| 464 | addDRTypeForNEON(MVT::v2i32); |
| 465 | addDRTypeForNEON(MVT::v1i64); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 466 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 467 | addQRTypeForNEON(MVT::v4f32); |
| 468 | addQRTypeForNEON(MVT::v2f64); |
| 469 | addQRTypeForNEON(MVT::v16i8); |
| 470 | addQRTypeForNEON(MVT::v8i16); |
| 471 | addQRTypeForNEON(MVT::v4i32); |
| 472 | addQRTypeForNEON(MVT::v2i64); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 473 | |
Bob Wilson | 74dc72e | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 474 | // v2f64 is legal so that QR subregs can be extracted as f64 elements, but |
| 475 | // neither Neon nor VFP support any arithmetic operations on it. |
Stepan Dyatkovskiy | 3e0dc06 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 476 | // The same with v4f32. But keep in mind that vadd, vsub, vmul are natively |
| 477 | // supported for v4f32. |
Bob Wilson | 74dc72e | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 478 | setOperationAction(ISD::FADD, MVT::v2f64, Expand); |
| 479 | setOperationAction(ISD::FSUB, MVT::v2f64, Expand); |
| 480 | setOperationAction(ISD::FMUL, MVT::v2f64, Expand); |
Stepan Dyatkovskiy | 3e0dc06 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 481 | // FIXME: Code duplication: FDIV and FREM are expanded always, see |
| 482 | // ARMTargetLowering::addTypeForNEON method for details. |
Bob Wilson | 74dc72e | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 483 | setOperationAction(ISD::FDIV, MVT::v2f64, Expand); |
| 484 | setOperationAction(ISD::FREM, MVT::v2f64, Expand); |
Stepan Dyatkovskiy | 3e0dc06 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 485 | // FIXME: Create unittest. |
| 486 | // In another words, find a way when "copysign" appears in DAG with vector |
| 487 | // operands. |
Bob Wilson | 74dc72e | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 488 | setOperationAction(ISD::FCOPYSIGN, MVT::v2f64, Expand); |
Stepan Dyatkovskiy | 3e0dc06 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 489 | // FIXME: Code duplication: SETCC has custom operation action, see |
| 490 | // ARMTargetLowering::addTypeForNEON method for details. |
Duncan Sands | 28b77e9 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 491 | setOperationAction(ISD::SETCC, MVT::v2f64, Expand); |
Stepan Dyatkovskiy | 3e0dc06 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 492 | // FIXME: Create unittest for FNEG and for FABS. |
Bob Wilson | 74dc72e | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 493 | setOperationAction(ISD::FNEG, MVT::v2f64, Expand); |
| 494 | setOperationAction(ISD::FABS, MVT::v2f64, Expand); |
| 495 | setOperationAction(ISD::FSQRT, MVT::v2f64, Expand); |
| 496 | setOperationAction(ISD::FSIN, MVT::v2f64, Expand); |
| 497 | setOperationAction(ISD::FCOS, MVT::v2f64, Expand); |
| 498 | setOperationAction(ISD::FPOWI, MVT::v2f64, Expand); |
| 499 | setOperationAction(ISD::FPOW, MVT::v2f64, Expand); |
| 500 | setOperationAction(ISD::FLOG, MVT::v2f64, Expand); |
| 501 | setOperationAction(ISD::FLOG2, MVT::v2f64, Expand); |
| 502 | setOperationAction(ISD::FLOG10, MVT::v2f64, Expand); |
| 503 | setOperationAction(ISD::FEXP, MVT::v2f64, Expand); |
| 504 | setOperationAction(ISD::FEXP2, MVT::v2f64, Expand); |
Stepan Dyatkovskiy | 3e0dc06 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 505 | // FIXME: Create unittest for FCEIL, FTRUNC, FRINT, FNEARBYINT, FFLOOR. |
Bob Wilson | 74dc72e | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 506 | setOperationAction(ISD::FCEIL, MVT::v2f64, Expand); |
| 507 | setOperationAction(ISD::FTRUNC, MVT::v2f64, Expand); |
| 508 | setOperationAction(ISD::FRINT, MVT::v2f64, Expand); |
| 509 | setOperationAction(ISD::FNEARBYINT, MVT::v2f64, Expand); |
| 510 | setOperationAction(ISD::FFLOOR, MVT::v2f64, Expand); |
Stepan Dyatkovskiy | 3e0dc06 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 511 | |
| 512 | setOperationAction(ISD::FSQRT, MVT::v4f32, Expand); |
| 513 | setOperationAction(ISD::FSIN, MVT::v4f32, Expand); |
| 514 | setOperationAction(ISD::FCOS, MVT::v4f32, Expand); |
| 515 | setOperationAction(ISD::FPOWI, MVT::v4f32, Expand); |
| 516 | setOperationAction(ISD::FPOW, MVT::v4f32, Expand); |
| 517 | setOperationAction(ISD::FLOG, MVT::v4f32, Expand); |
| 518 | setOperationAction(ISD::FLOG2, MVT::v4f32, Expand); |
| 519 | setOperationAction(ISD::FLOG10, MVT::v4f32, Expand); |
| 520 | setOperationAction(ISD::FEXP, MVT::v4f32, Expand); |
| 521 | setOperationAction(ISD::FEXP2, MVT::v4f32, Expand); |
Bob Wilson | 74dc72e | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 522 | |
Bob Wilson | 642b329 | 2009-09-16 00:32:15 +0000 | [diff] [blame] | 523 | // Neon does not support some operations on v1i64 and v2i64 types. |
| 524 | setOperationAction(ISD::MUL, MVT::v1i64, Expand); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 525 | // Custom handling for some quad-vector types to detect VMULL. |
| 526 | setOperationAction(ISD::MUL, MVT::v8i16, Custom); |
| 527 | setOperationAction(ISD::MUL, MVT::v4i32, Custom); |
| 528 | setOperationAction(ISD::MUL, MVT::v2i64, Custom); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 529 | // Custom handling for some vector types to avoid expensive expansions |
| 530 | setOperationAction(ISD::SDIV, MVT::v4i16, Custom); |
| 531 | setOperationAction(ISD::SDIV, MVT::v8i8, Custom); |
| 532 | setOperationAction(ISD::UDIV, MVT::v4i16, Custom); |
| 533 | setOperationAction(ISD::UDIV, MVT::v8i8, Custom); |
Duncan Sands | 28b77e9 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 534 | setOperationAction(ISD::SETCC, MVT::v1i64, Expand); |
| 535 | setOperationAction(ISD::SETCC, MVT::v2i64, Expand); |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 536 | // Neon does not have single instruction SINT_TO_FP and UINT_TO_FP with |
James Molloy | 873fd5f | 2012-02-20 09:24:05 +0000 | [diff] [blame] | 537 | // a destination type that is wider than the source, and nor does |
| 538 | // it have a FP_TO_[SU]INT instruction with a narrower destination than |
| 539 | // source. |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 540 | setOperationAction(ISD::SINT_TO_FP, MVT::v4i16, Custom); |
| 541 | setOperationAction(ISD::UINT_TO_FP, MVT::v4i16, Custom); |
James Molloy | 873fd5f | 2012-02-20 09:24:05 +0000 | [diff] [blame] | 542 | setOperationAction(ISD::FP_TO_UINT, MVT::v4i16, Custom); |
| 543 | setOperationAction(ISD::FP_TO_SINT, MVT::v4i16, Custom); |
Bob Wilson | 642b329 | 2009-09-16 00:32:15 +0000 | [diff] [blame] | 544 | |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 545 | setTargetDAGCombine(ISD::INTRINSIC_VOID); |
| 546 | setTargetDAGCombine(ISD::INTRINSIC_W_CHAIN); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 547 | setTargetDAGCombine(ISD::INTRINSIC_WO_CHAIN); |
| 548 | setTargetDAGCombine(ISD::SHL); |
| 549 | setTargetDAGCombine(ISD::SRL); |
| 550 | setTargetDAGCombine(ISD::SRA); |
| 551 | setTargetDAGCombine(ISD::SIGN_EXTEND); |
| 552 | setTargetDAGCombine(ISD::ZERO_EXTEND); |
| 553 | setTargetDAGCombine(ISD::ANY_EXTEND); |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 554 | setTargetDAGCombine(ISD::SELECT_CC); |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 555 | setTargetDAGCombine(ISD::BUILD_VECTOR); |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 556 | setTargetDAGCombine(ISD::VECTOR_SHUFFLE); |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 557 | setTargetDAGCombine(ISD::INSERT_VECTOR_ELT); |
| 558 | setTargetDAGCombine(ISD::STORE); |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 559 | setTargetDAGCombine(ISD::FP_TO_SINT); |
| 560 | setTargetDAGCombine(ISD::FP_TO_UINT); |
| 561 | setTargetDAGCombine(ISD::FDIV); |
Nadav Rotem | 004a24b | 2011-10-15 20:03:12 +0000 | [diff] [blame] | 562 | |
James Molloy | 873fd5f | 2012-02-20 09:24:05 +0000 | [diff] [blame] | 563 | // It is legal to extload from v4i8 to v4i16 or v4i32. |
| 564 | MVT Tys[6] = {MVT::v8i8, MVT::v4i8, MVT::v2i8, |
| 565 | MVT::v4i16, MVT::v2i16, |
| 566 | MVT::v2i32}; |
| 567 | for (unsigned i = 0; i < 6; ++i) { |
| 568 | setLoadExtAction(ISD::EXTLOAD, Tys[i], Legal); |
| 569 | setLoadExtAction(ISD::ZEXTLOAD, Tys[i], Legal); |
| 570 | setLoadExtAction(ISD::SEXTLOAD, Tys[i], Legal); |
| 571 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 572 | } |
| 573 | |
Evan Cheng | 9f8cbd1 | 2007-05-18 00:19:34 +0000 | [diff] [blame] | 574 | computeRegisterProperties(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 575 | |
| 576 | // ARM does not have f32 extending load. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 577 | setLoadExtAction(ISD::EXTLOAD, MVT::f32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 578 | |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 579 | // ARM does not have i1 sign extending load. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 580 | setLoadExtAction(ISD::SEXTLOAD, MVT::i1, Promote); |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 581 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 582 | // ARM supports all 4 flavors of integer indexed load / store. |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 583 | if (!Subtarget->isThumb1Only()) { |
| 584 | for (unsigned im = (unsigned)ISD::PRE_INC; |
| 585 | im != (unsigned)ISD::LAST_INDEXED_MODE; ++im) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 586 | setIndexedLoadAction(im, MVT::i1, Legal); |
| 587 | setIndexedLoadAction(im, MVT::i8, Legal); |
| 588 | setIndexedLoadAction(im, MVT::i16, Legal); |
| 589 | setIndexedLoadAction(im, MVT::i32, Legal); |
| 590 | setIndexedStoreAction(im, MVT::i1, Legal); |
| 591 | setIndexedStoreAction(im, MVT::i8, Legal); |
| 592 | setIndexedStoreAction(im, MVT::i16, Legal); |
| 593 | setIndexedStoreAction(im, MVT::i32, Legal); |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 594 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | // i64 operation support. |
Eric Christopher | 2cc4013 | 2011-04-19 18:49:19 +0000 | [diff] [blame] | 598 | setOperationAction(ISD::MUL, MVT::i64, Expand); |
| 599 | setOperationAction(ISD::MULHU, MVT::i32, Expand); |
Evan Cheng | 5b9fcd1 | 2009-07-07 01:17:28 +0000 | [diff] [blame] | 600 | if (Subtarget->isThumb1Only()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 601 | setOperationAction(ISD::UMUL_LOHI, MVT::i32, Expand); |
| 602 | setOperationAction(ISD::SMUL_LOHI, MVT::i32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 603 | } |
Jim Grosbach | a760398 | 2011-07-01 21:12:19 +0000 | [diff] [blame] | 604 | if (Subtarget->isThumb1Only() || !Subtarget->hasV6Ops() |
| 605 | || (Subtarget->isThumb2() && !Subtarget->hasThumb2DSP())) |
Eric Christopher | 2cc4013 | 2011-04-19 18:49:19 +0000 | [diff] [blame] | 606 | setOperationAction(ISD::MULHS, MVT::i32, Expand); |
| 607 | |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 608 | setOperationAction(ISD::SHL_PARTS, MVT::i32, Custom); |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 609 | setOperationAction(ISD::SRA_PARTS, MVT::i32, Custom); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 610 | setOperationAction(ISD::SRL_PARTS, MVT::i32, Custom); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 611 | setOperationAction(ISD::SRL, MVT::i64, Custom); |
| 612 | setOperationAction(ISD::SRA, MVT::i64, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 613 | |
Evan Cheng | 342e316 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 614 | if (!Subtarget->isThumb1Only()) { |
| 615 | // FIXME: We should do this for Thumb1 as well. |
| 616 | setOperationAction(ISD::ADDC, MVT::i32, Custom); |
| 617 | setOperationAction(ISD::ADDE, MVT::i32, Custom); |
| 618 | setOperationAction(ISD::SUBC, MVT::i32, Custom); |
| 619 | setOperationAction(ISD::SUBE, MVT::i32, Custom); |
| 620 | } |
| 621 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 622 | // ARM does not have ROTL. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 623 | setOperationAction(ISD::ROTL, MVT::i32, Expand); |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 624 | setOperationAction(ISD::CTTZ, MVT::i32, Custom); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 625 | setOperationAction(ISD::CTPOP, MVT::i32, Expand); |
David Goodwin | 24062ac | 2009-06-26 20:47:43 +0000 | [diff] [blame] | 626 | if (!Subtarget->hasV5TOps() || Subtarget->isThumb1Only()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 627 | setOperationAction(ISD::CTLZ, MVT::i32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 628 | |
Chandler Carruth | 63974b2 | 2011-12-13 01:56:10 +0000 | [diff] [blame] | 629 | // These just redirect to CTTZ and CTLZ on ARM. |
| 630 | setOperationAction(ISD::CTTZ_ZERO_UNDEF , MVT::i32 , Expand); |
| 631 | setOperationAction(ISD::CTLZ_ZERO_UNDEF , MVT::i32 , Expand); |
| 632 | |
Lauro Ramos Venancio | 368f20f | 2007-03-16 22:54:16 +0000 | [diff] [blame] | 633 | // Only ARMv6 has BSWAP. |
| 634 | if (!Subtarget->hasV6Ops()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 635 | setOperationAction(ISD::BSWAP, MVT::i32, Expand); |
Lauro Ramos Venancio | 368f20f | 2007-03-16 22:54:16 +0000 | [diff] [blame] | 636 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 637 | // These are expanded into libcalls. |
Evan Cheng | 1f190c8 | 2010-11-19 06:28:11 +0000 | [diff] [blame] | 638 | if (!Subtarget->hasDivide() || !Subtarget->isThumb2()) { |
Jim Grosbach | b1dc393 | 2010-05-05 20:44:35 +0000 | [diff] [blame] | 639 | // v7M has a hardware divider |
| 640 | setOperationAction(ISD::SDIV, MVT::i32, Expand); |
| 641 | setOperationAction(ISD::UDIV, MVT::i32, Expand); |
| 642 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 643 | setOperationAction(ISD::SREM, MVT::i32, Expand); |
| 644 | setOperationAction(ISD::UREM, MVT::i32, Expand); |
| 645 | setOperationAction(ISD::SDIVREM, MVT::i32, Expand); |
| 646 | setOperationAction(ISD::UDIVREM, MVT::i32, Expand); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 647 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 648 | setOperationAction(ISD::GlobalAddress, MVT::i32, Custom); |
| 649 | setOperationAction(ISD::ConstantPool, MVT::i32, Custom); |
| 650 | setOperationAction(ISD::GLOBAL_OFFSET_TABLE, MVT::i32, Custom); |
| 651 | setOperationAction(ISD::GlobalTLSAddress, MVT::i32, Custom); |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 652 | setOperationAction(ISD::BlockAddress, MVT::i32, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 653 | |
Evan Cheng | 4da0c7c | 2011-04-08 21:37:21 +0000 | [diff] [blame] | 654 | setOperationAction(ISD::TRAP, MVT::Other, Legal); |
Evan Cheng | fb3611d | 2010-05-11 07:26:32 +0000 | [diff] [blame] | 655 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 656 | // Use the default implementation. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 657 | setOperationAction(ISD::VASTART, MVT::Other, Custom); |
| 658 | setOperationAction(ISD::VAARG, MVT::Other, Expand); |
| 659 | setOperationAction(ISD::VACOPY, MVT::Other, Expand); |
| 660 | setOperationAction(ISD::VAEND, MVT::Other, Expand); |
| 661 | setOperationAction(ISD::STACKSAVE, MVT::Other, Expand); |
| 662 | setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand); |
Bill Wendling | bdf9db6 | 2012-02-13 23:47:16 +0000 | [diff] [blame] | 663 | |
| 664 | if (!Subtarget->isTargetDarwin()) { |
| 665 | // Non-Darwin platforms may return values in these registers via the |
| 666 | // personality function. |
| 667 | setOperationAction(ISD::EHSELECTION, MVT::i32, Expand); |
| 668 | setOperationAction(ISD::EXCEPTIONADDR, MVT::i32, Expand); |
| 669 | setExceptionPointerRegister(ARM::R0); |
| 670 | setExceptionSelectorRegister(ARM::R1); |
| 671 | } |
Anton Korobeynikov | 5899a60 | 2011-01-24 22:38:45 +0000 | [diff] [blame] | 672 | |
Evan Cheng | 3a1588a | 2010-04-15 22:20:34 +0000 | [diff] [blame] | 673 | setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32, Expand); |
Evan Cheng | 11db068 | 2010-08-11 06:22:01 +0000 | [diff] [blame] | 674 | // ARMv6 Thumb1 (except for CPUs that support dmb / dsb) and earlier use |
| 675 | // the default expansion. |
Eli Friedman | 4db5aca | 2011-08-29 18:23:02 +0000 | [diff] [blame] | 676 | // FIXME: This should be checking for v6k, not just v6. |
Evan Cheng | 11db068 | 2010-08-11 06:22:01 +0000 | [diff] [blame] | 677 | if (Subtarget->hasDataBarrier() || |
Bob Wilson | 54f9256 | 2010-11-09 22:50:44 +0000 | [diff] [blame] | 678 | (Subtarget->hasV6Ops() && !Subtarget->isThumb())) { |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 679 | // membarrier needs custom lowering; the rest are legal and handled |
| 680 | // normally. |
| 681 | setOperationAction(ISD::MEMBARRIER, MVT::Other, Custom); |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 682 | setOperationAction(ISD::ATOMIC_FENCE, MVT::Other, Custom); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 683 | // Custom lowering for 64-bit ops |
| 684 | setOperationAction(ISD::ATOMIC_LOAD_ADD, MVT::i64, Custom); |
| 685 | setOperationAction(ISD::ATOMIC_LOAD_SUB, MVT::i64, Custom); |
| 686 | setOperationAction(ISD::ATOMIC_LOAD_AND, MVT::i64, Custom); |
| 687 | setOperationAction(ISD::ATOMIC_LOAD_OR, MVT::i64, Custom); |
| 688 | setOperationAction(ISD::ATOMIC_LOAD_XOR, MVT::i64, Custom); |
| 689 | setOperationAction(ISD::ATOMIC_SWAP, MVT::i64, Custom); |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 690 | setOperationAction(ISD::ATOMIC_CMP_SWAP, MVT::i64, Custom); |
Eli Friedman | 26689ac | 2011-08-03 21:06:02 +0000 | [diff] [blame] | 691 | // Automatically insert fences (dmb ist) around ATOMIC_SWAP etc. |
| 692 | setInsertFencesForAtomic(true); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 693 | } else { |
| 694 | // Set them all for expansion, which will force libcalls. |
| 695 | setOperationAction(ISD::MEMBARRIER, MVT::Other, Expand); |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 696 | setOperationAction(ISD::ATOMIC_FENCE, MVT::Other, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 697 | setOperationAction(ISD::ATOMIC_CMP_SWAP, MVT::i32, Expand); |
Jim Grosbach | ef6eb9c | 2010-06-18 23:03:10 +0000 | [diff] [blame] | 698 | setOperationAction(ISD::ATOMIC_SWAP, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 699 | setOperationAction(ISD::ATOMIC_LOAD_ADD, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 700 | setOperationAction(ISD::ATOMIC_LOAD_SUB, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 701 | setOperationAction(ISD::ATOMIC_LOAD_AND, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 702 | setOperationAction(ISD::ATOMIC_LOAD_OR, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 703 | setOperationAction(ISD::ATOMIC_LOAD_XOR, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 704 | setOperationAction(ISD::ATOMIC_LOAD_NAND, MVT::i32, Expand); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 705 | setOperationAction(ISD::ATOMIC_LOAD_MIN, MVT::i32, Expand); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 706 | setOperationAction(ISD::ATOMIC_LOAD_MAX, MVT::i32, Expand); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 707 | setOperationAction(ISD::ATOMIC_LOAD_UMIN, MVT::i32, Expand); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 708 | setOperationAction(ISD::ATOMIC_LOAD_UMAX, MVT::i32, Expand); |
Eli Friedman | 7cc1566 | 2011-09-15 22:18:49 +0000 | [diff] [blame] | 709 | // Mark ATOMIC_LOAD and ATOMIC_STORE custom so we can handle the |
| 710 | // Unordered/Monotonic case. |
| 711 | setOperationAction(ISD::ATOMIC_LOAD, MVT::i32, Custom); |
| 712 | setOperationAction(ISD::ATOMIC_STORE, MVT::i32, Custom); |
Jim Grosbach | 5def57a | 2010-06-23 16:08:49 +0000 | [diff] [blame] | 713 | // Since the libcalls include locking, fold in the fences |
| 714 | setShouldFoldAtomicFences(true); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 715 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 716 | |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 717 | setOperationAction(ISD::PREFETCH, MVT::Other, Custom); |
Evan Cheng | bc7deb0 | 2010-11-03 05:14:24 +0000 | [diff] [blame] | 718 | |
Eli Friedman | a2c6f45 | 2010-06-26 04:36:50 +0000 | [diff] [blame] | 719 | // Requires SXTB/SXTH, available on v6 and up in both ARM and Thumb modes. |
| 720 | if (!Subtarget->hasV6Ops()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 721 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i16, Expand); |
| 722 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i8, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 723 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 724 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 725 | |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 726 | if (!TM.Options.UseSoftFloat && Subtarget->hasVFP2() && |
| 727 | !Subtarget->isThumb1Only()) { |
Bob Wilson | cb9a6aa | 2010-01-19 22:56:26 +0000 | [diff] [blame] | 728 | // Turn f64->i64 into VMOVRRD, i64 -> f64 to VMOVDRR |
| 729 | // iff target supports vfp2. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 730 | setOperationAction(ISD::BITCAST, MVT::i64, Custom); |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 731 | setOperationAction(ISD::FLT_ROUNDS_, MVT::i32, Custom); |
| 732 | } |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 733 | |
| 734 | // We want to custom lower some of our intrinsics. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 735 | setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom); |
Jim Grosbach | e97f968 | 2010-07-07 00:07:57 +0000 | [diff] [blame] | 736 | if (Subtarget->isTargetDarwin()) { |
| 737 | setOperationAction(ISD::EH_SJLJ_SETJMP, MVT::i32, Custom); |
| 738 | setOperationAction(ISD::EH_SJLJ_LONGJMP, MVT::Other, Custom); |
John McCall | 5f8fd54 | 2011-05-29 19:50:32 +0000 | [diff] [blame] | 739 | setLibcallName(RTLIB::UNWIND_RESUME, "_Unwind_SjLj_Resume"); |
Jim Grosbach | e97f968 | 2010-07-07 00:07:57 +0000 | [diff] [blame] | 740 | } |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 741 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 742 | setOperationAction(ISD::SETCC, MVT::i32, Expand); |
| 743 | setOperationAction(ISD::SETCC, MVT::f32, Expand); |
| 744 | setOperationAction(ISD::SETCC, MVT::f64, Expand); |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 745 | setOperationAction(ISD::SELECT, MVT::i32, Custom); |
| 746 | setOperationAction(ISD::SELECT, MVT::f32, Custom); |
| 747 | setOperationAction(ISD::SELECT, MVT::f64, Custom); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 748 | setOperationAction(ISD::SELECT_CC, MVT::i32, Custom); |
| 749 | setOperationAction(ISD::SELECT_CC, MVT::f32, Custom); |
| 750 | setOperationAction(ISD::SELECT_CC, MVT::f64, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 751 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 752 | setOperationAction(ISD::BRCOND, MVT::Other, Expand); |
| 753 | setOperationAction(ISD::BR_CC, MVT::i32, Custom); |
| 754 | setOperationAction(ISD::BR_CC, MVT::f32, Custom); |
| 755 | setOperationAction(ISD::BR_CC, MVT::f64, Custom); |
| 756 | setOperationAction(ISD::BR_JT, MVT::Other, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 757 | |
Dan Gohman | f96e4de | 2007-10-11 23:21:31 +0000 | [diff] [blame] | 758 | // We don't support sin/cos/fmod/copysign/pow |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 759 | setOperationAction(ISD::FSIN, MVT::f64, Expand); |
| 760 | setOperationAction(ISD::FSIN, MVT::f32, Expand); |
| 761 | setOperationAction(ISD::FCOS, MVT::f32, Expand); |
| 762 | setOperationAction(ISD::FCOS, MVT::f64, Expand); |
| 763 | setOperationAction(ISD::FREM, MVT::f64, Expand); |
| 764 | setOperationAction(ISD::FREM, MVT::f32, Expand); |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 765 | if (!TM.Options.UseSoftFloat && Subtarget->hasVFP2() && |
| 766 | !Subtarget->isThumb1Only()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 767 | setOperationAction(ISD::FCOPYSIGN, MVT::f64, Custom); |
| 768 | setOperationAction(ISD::FCOPYSIGN, MVT::f32, Custom); |
Evan Cheng | 110cf48 | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 769 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 770 | setOperationAction(ISD::FPOW, MVT::f64, Expand); |
| 771 | setOperationAction(ISD::FPOW, MVT::f32, Expand); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 772 | |
Cameron Zwarich | 3339084 | 2011-07-08 21:39:21 +0000 | [diff] [blame] | 773 | setOperationAction(ISD::FMA, MVT::f64, Expand); |
| 774 | setOperationAction(ISD::FMA, MVT::f32, Expand); |
| 775 | |
Anton Korobeynikov | bec3dd2 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 776 | // Various VFP goodness |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 777 | if (!TM.Options.UseSoftFloat && !Subtarget->isThumb1Only()) { |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 778 | // int <-> fp are custom expanded into bit_convert + ARMISD ops. |
| 779 | if (Subtarget->hasVFP2()) { |
| 780 | setOperationAction(ISD::SINT_TO_FP, MVT::i32, Custom); |
| 781 | setOperationAction(ISD::UINT_TO_FP, MVT::i32, Custom); |
| 782 | setOperationAction(ISD::FP_TO_UINT, MVT::i32, Custom); |
| 783 | setOperationAction(ISD::FP_TO_SINT, MVT::i32, Custom); |
| 784 | } |
Anton Korobeynikov | bec3dd2 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 785 | // Special handling for half-precision FP. |
Anton Korobeynikov | f0d5007 | 2010-03-18 22:35:37 +0000 | [diff] [blame] | 786 | if (!Subtarget->hasFP16()) { |
| 787 | setOperationAction(ISD::FP16_TO_FP32, MVT::f32, Expand); |
| 788 | setOperationAction(ISD::FP32_TO_FP16, MVT::i32, Expand); |
Anton Korobeynikov | bec3dd2 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 789 | } |
Evan Cheng | 110cf48 | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 790 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 791 | |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 792 | // We have target-specific dag combine patterns for the following nodes: |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 793 | // ARMISD::VMOVRRD - No need to call setTargetDAGCombine |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 794 | setTargetDAGCombine(ISD::ADD); |
| 795 | setTargetDAGCombine(ISD::SUB); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 796 | setTargetDAGCombine(ISD::MUL); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 797 | |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 798 | if (Subtarget->hasV6T2Ops() || Subtarget->hasNEON()) { |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 799 | setTargetDAGCombine(ISD::AND); |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 800 | setTargetDAGCombine(ISD::OR); |
| 801 | setTargetDAGCombine(ISD::XOR); |
| 802 | } |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 803 | |
Evan Cheng | 5fb468a | 2012-02-23 02:58:19 +0000 | [diff] [blame] | 804 | if (Subtarget->hasV6Ops()) |
| 805 | setTargetDAGCombine(ISD::SRL); |
| 806 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 807 | setStackPointerRegisterToSaveRestore(ARM::SP); |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 808 | |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 809 | if (TM.Options.UseSoftFloat || Subtarget->isThumb1Only() || |
| 810 | !Subtarget->hasVFP2()) |
Evan Cheng | f7d87ee | 2010-05-21 00:43:17 +0000 | [diff] [blame] | 811 | setSchedulingPreference(Sched::RegPressure); |
| 812 | else |
| 813 | setSchedulingPreference(Sched::Hybrid); |
Dale Johannesen | 8dd86c1 | 2007-05-17 21:31:21 +0000 | [diff] [blame] | 814 | |
Evan Cheng | 0521928 | 2011-01-06 06:52:41 +0000 | [diff] [blame] | 815 | //// temporary - rewrite interface to use type |
| 816 | maxStoresPerMemcpy = maxStoresPerMemcpyOptSize = 1; |
Lang Hames | 75757f9 | 2011-10-26 20:56:52 +0000 | [diff] [blame] | 817 | maxStoresPerMemset = 16; |
| 818 | maxStoresPerMemsetOptSize = Subtarget->isTargetDarwin() ? 8 : 4; |
Evan Cheng | f679939 | 2010-06-26 01:52:05 +0000 | [diff] [blame] | 819 | |
Rafael Espindola | cbeeae2 | 2010-07-11 04:01:49 +0000 | [diff] [blame] | 820 | // On ARM arguments smaller than 4 bytes are extended, so all arguments |
| 821 | // are at least 4 bytes aligned. |
| 822 | setMinStackArgumentAlignment(4); |
| 823 | |
Evan Cheng | fff606d | 2010-09-24 19:07:23 +0000 | [diff] [blame] | 824 | benefitFromCodePlacementOpt = true; |
Eli Friedman | fc5d305 | 2011-05-06 20:34:06 +0000 | [diff] [blame] | 825 | |
| 826 | setMinFunctionAlignment(Subtarget->isThumb() ? 1 : 2); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 827 | } |
| 828 | |
Andrew Trick | 32cec0a | 2011-01-19 02:35:27 +0000 | [diff] [blame] | 829 | // FIXME: It might make sense to define the representative register class as the |
| 830 | // nearest super-register that has a non-null superset. For example, DPR_VFP2 is |
| 831 | // a super-register of SPR, and DPR is a superset if DPR_VFP2. Consequently, |
| 832 | // SPR's representative would be DPR_VFP2. This should work well if register |
| 833 | // pressure tracking were modified such that a register use would increment the |
| 834 | // pressure of the register class's representative and all of it's super |
| 835 | // classes' representatives transitively. We have not implemented this because |
| 836 | // of the difficulty prior to coalescing of modeling operand register classes |
Chris Lattner | 7a2bdde | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 837 | // due to the common occurrence of cross class copies and subregister insertions |
Andrew Trick | 32cec0a | 2011-01-19 02:35:27 +0000 | [diff] [blame] | 838 | // and extractions. |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 839 | std::pair<const TargetRegisterClass*, uint8_t> |
| 840 | ARMTargetLowering::findRepresentativeClass(EVT VT) const{ |
| 841 | const TargetRegisterClass *RRC = 0; |
| 842 | uint8_t Cost = 1; |
| 843 | switch (VT.getSimpleVT().SimpleTy) { |
Evan Cheng | d70f57b | 2010-07-19 22:15:08 +0000 | [diff] [blame] | 844 | default: |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 845 | return TargetLowering::findRepresentativeClass(VT); |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 846 | // Use DPR as representative register class for all floating point |
| 847 | // and vector types. Since there are 32 SPR registers and 32 DPR registers so |
| 848 | // the cost is 1 for both f32 and f64. |
| 849 | case MVT::f32: case MVT::f64: case MVT::v8i8: case MVT::v4i16: |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 850 | case MVT::v2i32: case MVT::v1i64: case MVT::v2f32: |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 851 | RRC = ARM::DPRRegisterClass; |
Andrew Trick | 32cec0a | 2011-01-19 02:35:27 +0000 | [diff] [blame] | 852 | // When NEON is used for SP, only half of the register file is available |
| 853 | // because operations that define both SP and DP results will be constrained |
| 854 | // to the VFP2 class (D0-D15). We currently model this constraint prior to |
| 855 | // coalescing by double-counting the SP regs. See the FIXME above. |
| 856 | if (Subtarget->useNEONForSinglePrecisionFP()) |
| 857 | Cost = 2; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 858 | break; |
| 859 | case MVT::v16i8: case MVT::v8i16: case MVT::v4i32: case MVT::v2i64: |
| 860 | case MVT::v4f32: case MVT::v2f64: |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 861 | RRC = ARM::DPRRegisterClass; |
| 862 | Cost = 2; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 863 | break; |
| 864 | case MVT::v4i64: |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 865 | RRC = ARM::DPRRegisterClass; |
| 866 | Cost = 4; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 867 | break; |
| 868 | case MVT::v8i64: |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 869 | RRC = ARM::DPRRegisterClass; |
| 870 | Cost = 8; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 871 | break; |
Evan Cheng | d70f57b | 2010-07-19 22:15:08 +0000 | [diff] [blame] | 872 | } |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 873 | return std::make_pair(RRC, Cost); |
Evan Cheng | d70f57b | 2010-07-19 22:15:08 +0000 | [diff] [blame] | 874 | } |
| 875 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 876 | const char *ARMTargetLowering::getTargetNodeName(unsigned Opcode) const { |
| 877 | switch (Opcode) { |
| 878 | default: return 0; |
| 879 | case ARMISD::Wrapper: return "ARMISD::Wrapper"; |
Evan Cheng | 53519f0 | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 880 | case ARMISD::WrapperDYN: return "ARMISD::WrapperDYN"; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 881 | case ARMISD::WrapperPIC: return "ARMISD::WrapperPIC"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 882 | case ARMISD::WrapperJT: return "ARMISD::WrapperJT"; |
| 883 | case ARMISD::CALL: return "ARMISD::CALL"; |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 884 | case ARMISD::CALL_PRED: return "ARMISD::CALL_PRED"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 885 | case ARMISD::CALL_NOLINK: return "ARMISD::CALL_NOLINK"; |
| 886 | case ARMISD::tCALL: return "ARMISD::tCALL"; |
| 887 | case ARMISD::BRCOND: return "ARMISD::BRCOND"; |
| 888 | case ARMISD::BR_JT: return "ARMISD::BR_JT"; |
Evan Cheng | 5657c01 | 2009-07-29 02:18:14 +0000 | [diff] [blame] | 889 | case ARMISD::BR2_JT: return "ARMISD::BR2_JT"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 890 | case ARMISD::RET_FLAG: return "ARMISD::RET_FLAG"; |
| 891 | case ARMISD::PIC_ADD: return "ARMISD::PIC_ADD"; |
| 892 | case ARMISD::CMP: return "ARMISD::CMP"; |
David Goodwin | c0309b4 | 2009-06-29 15:33:01 +0000 | [diff] [blame] | 893 | case ARMISD::CMPZ: return "ARMISD::CMPZ"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 894 | case ARMISD::CMPFP: return "ARMISD::CMPFP"; |
| 895 | case ARMISD::CMPFPw0: return "ARMISD::CMPFPw0"; |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 896 | case ARMISD::BCC_i64: return "ARMISD::BCC_i64"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 897 | case ARMISD::FMSTAT: return "ARMISD::FMSTAT"; |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 898 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 899 | case ARMISD::CMOV: return "ARMISD::CMOV"; |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 900 | case ARMISD::CAND: return "ARMISD::CAND"; |
| 901 | case ARMISD::COR: return "ARMISD::COR"; |
| 902 | case ARMISD::CXOR: return "ARMISD::CXOR"; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 903 | |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 904 | case ARMISD::RBIT: return "ARMISD::RBIT"; |
| 905 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 906 | case ARMISD::FTOSI: return "ARMISD::FTOSI"; |
| 907 | case ARMISD::FTOUI: return "ARMISD::FTOUI"; |
| 908 | case ARMISD::SITOF: return "ARMISD::SITOF"; |
| 909 | case ARMISD::UITOF: return "ARMISD::UITOF"; |
| 910 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 911 | case ARMISD::SRL_FLAG: return "ARMISD::SRL_FLAG"; |
| 912 | case ARMISD::SRA_FLAG: return "ARMISD::SRA_FLAG"; |
| 913 | case ARMISD::RRX: return "ARMISD::RRX"; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 914 | |
Evan Cheng | 342e316 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 915 | case ARMISD::ADDC: return "ARMISD::ADDC"; |
| 916 | case ARMISD::ADDE: return "ARMISD::ADDE"; |
| 917 | case ARMISD::SUBC: return "ARMISD::SUBC"; |
| 918 | case ARMISD::SUBE: return "ARMISD::SUBE"; |
| 919 | |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 920 | case ARMISD::VMOVRRD: return "ARMISD::VMOVRRD"; |
| 921 | case ARMISD::VMOVDRR: return "ARMISD::VMOVDRR"; |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 922 | |
Evan Cheng | c594208 | 2009-10-28 06:55:03 +0000 | [diff] [blame] | 923 | case ARMISD::EH_SJLJ_SETJMP: return "ARMISD::EH_SJLJ_SETJMP"; |
| 924 | case ARMISD::EH_SJLJ_LONGJMP:return "ARMISD::EH_SJLJ_LONGJMP"; |
| 925 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 926 | case ARMISD::TC_RETURN: return "ARMISD::TC_RETURN"; |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 927 | |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 928 | case ARMISD::THREAD_POINTER:return "ARMISD::THREAD_POINTER"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 929 | |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 930 | case ARMISD::DYN_ALLOC: return "ARMISD::DYN_ALLOC"; |
| 931 | |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 932 | case ARMISD::MEMBARRIER: return "ARMISD::MEMBARRIER"; |
Bob Wilson | f74a429 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 933 | case ARMISD::MEMBARRIER_MCR: return "ARMISD::MEMBARRIER_MCR"; |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 934 | |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 935 | case ARMISD::PRELOAD: return "ARMISD::PRELOAD"; |
| 936 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 937 | case ARMISD::VCEQ: return "ARMISD::VCEQ"; |
Bob Wilson | 3a75b9b | 2010-12-18 00:04:26 +0000 | [diff] [blame] | 938 | case ARMISD::VCEQZ: return "ARMISD::VCEQZ"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 939 | case ARMISD::VCGE: return "ARMISD::VCGE"; |
Bob Wilson | 3a75b9b | 2010-12-18 00:04:26 +0000 | [diff] [blame] | 940 | case ARMISD::VCGEZ: return "ARMISD::VCGEZ"; |
| 941 | case ARMISD::VCLEZ: return "ARMISD::VCLEZ"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 942 | case ARMISD::VCGEU: return "ARMISD::VCGEU"; |
| 943 | case ARMISD::VCGT: return "ARMISD::VCGT"; |
Bob Wilson | 3a75b9b | 2010-12-18 00:04:26 +0000 | [diff] [blame] | 944 | case ARMISD::VCGTZ: return "ARMISD::VCGTZ"; |
| 945 | case ARMISD::VCLTZ: return "ARMISD::VCLTZ"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 946 | case ARMISD::VCGTU: return "ARMISD::VCGTU"; |
| 947 | case ARMISD::VTST: return "ARMISD::VTST"; |
| 948 | |
| 949 | case ARMISD::VSHL: return "ARMISD::VSHL"; |
| 950 | case ARMISD::VSHRs: return "ARMISD::VSHRs"; |
| 951 | case ARMISD::VSHRu: return "ARMISD::VSHRu"; |
| 952 | case ARMISD::VSHLLs: return "ARMISD::VSHLLs"; |
| 953 | case ARMISD::VSHLLu: return "ARMISD::VSHLLu"; |
| 954 | case ARMISD::VSHLLi: return "ARMISD::VSHLLi"; |
| 955 | case ARMISD::VSHRN: return "ARMISD::VSHRN"; |
| 956 | case ARMISD::VRSHRs: return "ARMISD::VRSHRs"; |
| 957 | case ARMISD::VRSHRu: return "ARMISD::VRSHRu"; |
| 958 | case ARMISD::VRSHRN: return "ARMISD::VRSHRN"; |
| 959 | case ARMISD::VQSHLs: return "ARMISD::VQSHLs"; |
| 960 | case ARMISD::VQSHLu: return "ARMISD::VQSHLu"; |
| 961 | case ARMISD::VQSHLsu: return "ARMISD::VQSHLsu"; |
| 962 | case ARMISD::VQSHRNs: return "ARMISD::VQSHRNs"; |
| 963 | case ARMISD::VQSHRNu: return "ARMISD::VQSHRNu"; |
| 964 | case ARMISD::VQSHRNsu: return "ARMISD::VQSHRNsu"; |
| 965 | case ARMISD::VQRSHRNs: return "ARMISD::VQRSHRNs"; |
| 966 | case ARMISD::VQRSHRNu: return "ARMISD::VQRSHRNu"; |
| 967 | case ARMISD::VQRSHRNsu: return "ARMISD::VQRSHRNsu"; |
| 968 | case ARMISD::VGETLANEu: return "ARMISD::VGETLANEu"; |
| 969 | case ARMISD::VGETLANEs: return "ARMISD::VGETLANEs"; |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 970 | case ARMISD::VMOVIMM: return "ARMISD::VMOVIMM"; |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 971 | case ARMISD::VMVNIMM: return "ARMISD::VMVNIMM"; |
Evan Cheng | eaa192a | 2011-11-15 02:12:34 +0000 | [diff] [blame] | 972 | case ARMISD::VMOVFPIMM: return "ARMISD::VMOVFPIMM"; |
Bob Wilson | c1d287b | 2009-08-14 05:13:08 +0000 | [diff] [blame] | 973 | case ARMISD::VDUP: return "ARMISD::VDUP"; |
Bob Wilson | 0ce3710 | 2009-08-14 05:08:32 +0000 | [diff] [blame] | 974 | case ARMISD::VDUPLANE: return "ARMISD::VDUPLANE"; |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 975 | case ARMISD::VEXT: return "ARMISD::VEXT"; |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 976 | case ARMISD::VREV64: return "ARMISD::VREV64"; |
| 977 | case ARMISD::VREV32: return "ARMISD::VREV32"; |
| 978 | case ARMISD::VREV16: return "ARMISD::VREV16"; |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 979 | case ARMISD::VZIP: return "ARMISD::VZIP"; |
| 980 | case ARMISD::VUZP: return "ARMISD::VUZP"; |
| 981 | case ARMISD::VTRN: return "ARMISD::VTRN"; |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 982 | case ARMISD::VTBL1: return "ARMISD::VTBL1"; |
| 983 | case ARMISD::VTBL2: return "ARMISD::VTBL2"; |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 984 | case ARMISD::VMULLs: return "ARMISD::VMULLs"; |
| 985 | case ARMISD::VMULLu: return "ARMISD::VMULLu"; |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 986 | case ARMISD::BUILD_VECTOR: return "ARMISD::BUILD_VECTOR"; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 987 | case ARMISD::FMAX: return "ARMISD::FMAX"; |
| 988 | case ARMISD::FMIN: return "ARMISD::FMIN"; |
Jim Grosbach | dd7d28a | 2010-07-17 01:50:57 +0000 | [diff] [blame] | 989 | case ARMISD::BFI: return "ARMISD::BFI"; |
Bob Wilson | 364a72a | 2010-11-28 06:51:11 +0000 | [diff] [blame] | 990 | case ARMISD::VORRIMM: return "ARMISD::VORRIMM"; |
| 991 | case ARMISD::VBICIMM: return "ARMISD::VBICIMM"; |
Cameron Zwarich | c0e6d78 | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 992 | case ARMISD::VBSL: return "ARMISD::VBSL"; |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 993 | case ARMISD::VLD2DUP: return "ARMISD::VLD2DUP"; |
| 994 | case ARMISD::VLD3DUP: return "ARMISD::VLD3DUP"; |
| 995 | case ARMISD::VLD4DUP: return "ARMISD::VLD4DUP"; |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 996 | case ARMISD::VLD1_UPD: return "ARMISD::VLD1_UPD"; |
| 997 | case ARMISD::VLD2_UPD: return "ARMISD::VLD2_UPD"; |
| 998 | case ARMISD::VLD3_UPD: return "ARMISD::VLD3_UPD"; |
| 999 | case ARMISD::VLD4_UPD: return "ARMISD::VLD4_UPD"; |
| 1000 | case ARMISD::VLD2LN_UPD: return "ARMISD::VLD2LN_UPD"; |
| 1001 | case ARMISD::VLD3LN_UPD: return "ARMISD::VLD3LN_UPD"; |
| 1002 | case ARMISD::VLD4LN_UPD: return "ARMISD::VLD4LN_UPD"; |
| 1003 | case ARMISD::VLD2DUP_UPD: return "ARMISD::VLD2DUP_UPD"; |
| 1004 | case ARMISD::VLD3DUP_UPD: return "ARMISD::VLD3DUP_UPD"; |
| 1005 | case ARMISD::VLD4DUP_UPD: return "ARMISD::VLD4DUP_UPD"; |
| 1006 | case ARMISD::VST1_UPD: return "ARMISD::VST1_UPD"; |
| 1007 | case ARMISD::VST2_UPD: return "ARMISD::VST2_UPD"; |
| 1008 | case ARMISD::VST3_UPD: return "ARMISD::VST3_UPD"; |
| 1009 | case ARMISD::VST4_UPD: return "ARMISD::VST4_UPD"; |
| 1010 | case ARMISD::VST2LN_UPD: return "ARMISD::VST2LN_UPD"; |
| 1011 | case ARMISD::VST3LN_UPD: return "ARMISD::VST3LN_UPD"; |
| 1012 | case ARMISD::VST4LN_UPD: return "ARMISD::VST4LN_UPD"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1013 | } |
| 1014 | } |
| 1015 | |
Duncan Sands | 28b77e9 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 1016 | EVT ARMTargetLowering::getSetCCResultType(EVT VT) const { |
| 1017 | if (!VT.isVector()) return getPointerTy(); |
| 1018 | return VT.changeVectorElementTypeToInteger(); |
| 1019 | } |
| 1020 | |
Evan Cheng | 06b666c | 2010-05-15 02:18:07 +0000 | [diff] [blame] | 1021 | /// getRegClassFor - Return the register class that should be used for the |
| 1022 | /// specified value type. |
Craig Topper | 44d2382 | 2012-02-22 05:59:10 +0000 | [diff] [blame] | 1023 | const TargetRegisterClass *ARMTargetLowering::getRegClassFor(EVT VT) const { |
Evan Cheng | 06b666c | 2010-05-15 02:18:07 +0000 | [diff] [blame] | 1024 | // Map v4i64 to QQ registers but do not make the type legal. Similarly map |
| 1025 | // v8i64 to QQQQ registers. v4i64 and v8i64 are only used for REG_SEQUENCE to |
| 1026 | // load / store 4 to 8 consecutive D registers. |
Evan Cheng | 4782b1e | 2010-05-15 02:20:21 +0000 | [diff] [blame] | 1027 | if (Subtarget->hasNEON()) { |
| 1028 | if (VT == MVT::v4i64) |
| 1029 | return ARM::QQPRRegisterClass; |
| 1030 | else if (VT == MVT::v8i64) |
| 1031 | return ARM::QQQQPRRegisterClass; |
| 1032 | } |
Evan Cheng | 06b666c | 2010-05-15 02:18:07 +0000 | [diff] [blame] | 1033 | return TargetLowering::getRegClassFor(VT); |
| 1034 | } |
| 1035 | |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 1036 | // Create a fast isel object. |
| 1037 | FastISel * |
| 1038 | ARMTargetLowering::createFastISel(FunctionLoweringInfo &funcInfo) const { |
| 1039 | return ARM::createFastISel(funcInfo); |
| 1040 | } |
| 1041 | |
Anton Korobeynikov | cec36f4 | 2010-07-24 21:52:08 +0000 | [diff] [blame] | 1042 | /// getMaximalGlobalOffset - Returns the maximal possible offset which can |
| 1043 | /// be used for loads / stores from the global. |
| 1044 | unsigned ARMTargetLowering::getMaximalGlobalOffset() const { |
| 1045 | return (Subtarget->isThumb1Only() ? 127 : 4095); |
| 1046 | } |
| 1047 | |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1048 | Sched::Preference ARMTargetLowering::getSchedulingPreference(SDNode *N) const { |
Evan Cheng | c10f543 | 2010-05-28 23:25:23 +0000 | [diff] [blame] | 1049 | unsigned NumVals = N->getNumValues(); |
| 1050 | if (!NumVals) |
| 1051 | return Sched::RegPressure; |
| 1052 | |
| 1053 | for (unsigned i = 0; i != NumVals; ++i) { |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1054 | EVT VT = N->getValueType(i); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 1055 | if (VT == MVT::Glue || VT == MVT::Other) |
Evan Cheng | d7e473c | 2010-10-29 18:07:31 +0000 | [diff] [blame] | 1056 | continue; |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1057 | if (VT.isFloatingPoint() || VT.isVector()) |
Dan Gohman | 692c1d8 | 2011-10-24 17:55:11 +0000 | [diff] [blame] | 1058 | return Sched::ILP; |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1059 | } |
Evan Cheng | c10f543 | 2010-05-28 23:25:23 +0000 | [diff] [blame] | 1060 | |
| 1061 | if (!N->isMachineOpcode()) |
| 1062 | return Sched::RegPressure; |
| 1063 | |
| 1064 | // Load are scheduled for latency even if there instruction itinerary |
| 1065 | // is not available. |
| 1066 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 1067 | const MCInstrDesc &MCID = TII->get(N->getMachineOpcode()); |
Evan Cheng | d7e473c | 2010-10-29 18:07:31 +0000 | [diff] [blame] | 1068 | |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 1069 | if (MCID.getNumDefs() == 0) |
Evan Cheng | d7e473c | 2010-10-29 18:07:31 +0000 | [diff] [blame] | 1070 | return Sched::RegPressure; |
| 1071 | if (!Itins->isEmpty() && |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 1072 | Itins->getOperandCycle(MCID.getSchedClass(), 0) > 2) |
Dan Gohman | 692c1d8 | 2011-10-24 17:55:11 +0000 | [diff] [blame] | 1073 | return Sched::ILP; |
Evan Cheng | c10f543 | 2010-05-28 23:25:23 +0000 | [diff] [blame] | 1074 | |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1075 | return Sched::RegPressure; |
| 1076 | } |
| 1077 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1078 | //===----------------------------------------------------------------------===// |
| 1079 | // Lowering Code |
| 1080 | //===----------------------------------------------------------------------===// |
| 1081 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1082 | /// IntCCToARMCC - Convert a DAG integer condition code to an ARM CC |
| 1083 | static ARMCC::CondCodes IntCCToARMCC(ISD::CondCode CC) { |
| 1084 | switch (CC) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1085 | default: llvm_unreachable("Unknown condition code!"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1086 | case ISD::SETNE: return ARMCC::NE; |
| 1087 | case ISD::SETEQ: return ARMCC::EQ; |
| 1088 | case ISD::SETGT: return ARMCC::GT; |
| 1089 | case ISD::SETGE: return ARMCC::GE; |
| 1090 | case ISD::SETLT: return ARMCC::LT; |
| 1091 | case ISD::SETLE: return ARMCC::LE; |
| 1092 | case ISD::SETUGT: return ARMCC::HI; |
| 1093 | case ISD::SETUGE: return ARMCC::HS; |
| 1094 | case ISD::SETULT: return ARMCC::LO; |
| 1095 | case ISD::SETULE: return ARMCC::LS; |
| 1096 | } |
| 1097 | } |
| 1098 | |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 1099 | /// FPCCToARMCC - Convert a DAG fp condition code to an ARM CC. |
| 1100 | static void FPCCToARMCC(ISD::CondCode CC, ARMCC::CondCodes &CondCode, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1101 | ARMCC::CondCodes &CondCode2) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1102 | CondCode2 = ARMCC::AL; |
| 1103 | switch (CC) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1104 | default: llvm_unreachable("Unknown FP condition!"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1105 | case ISD::SETEQ: |
| 1106 | case ISD::SETOEQ: CondCode = ARMCC::EQ; break; |
| 1107 | case ISD::SETGT: |
| 1108 | case ISD::SETOGT: CondCode = ARMCC::GT; break; |
| 1109 | case ISD::SETGE: |
| 1110 | case ISD::SETOGE: CondCode = ARMCC::GE; break; |
| 1111 | case ISD::SETOLT: CondCode = ARMCC::MI; break; |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 1112 | case ISD::SETOLE: CondCode = ARMCC::LS; break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1113 | case ISD::SETONE: CondCode = ARMCC::MI; CondCode2 = ARMCC::GT; break; |
| 1114 | case ISD::SETO: CondCode = ARMCC::VC; break; |
| 1115 | case ISD::SETUO: CondCode = ARMCC::VS; break; |
| 1116 | case ISD::SETUEQ: CondCode = ARMCC::EQ; CondCode2 = ARMCC::VS; break; |
| 1117 | case ISD::SETUGT: CondCode = ARMCC::HI; break; |
| 1118 | case ISD::SETUGE: CondCode = ARMCC::PL; break; |
| 1119 | case ISD::SETLT: |
| 1120 | case ISD::SETULT: CondCode = ARMCC::LT; break; |
| 1121 | case ISD::SETLE: |
| 1122 | case ISD::SETULE: CondCode = ARMCC::LE; break; |
| 1123 | case ISD::SETNE: |
| 1124 | case ISD::SETUNE: CondCode = ARMCC::NE; break; |
| 1125 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1126 | } |
| 1127 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1128 | //===----------------------------------------------------------------------===// |
| 1129 | // Calling Convention Implementation |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1130 | //===----------------------------------------------------------------------===// |
| 1131 | |
| 1132 | #include "ARMGenCallingConv.inc" |
| 1133 | |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1134 | /// CCAssignFnForNode - Selects the correct CCAssignFn for a the |
| 1135 | /// given CallingConvention value. |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1136 | CCAssignFn *ARMTargetLowering::CCAssignFnForNode(CallingConv::ID CC, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1137 | bool Return, |
| 1138 | bool isVarArg) const { |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1139 | switch (CC) { |
| 1140 | default: |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1141 | llvm_unreachable("Unsupported calling convention"); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1142 | case CallingConv::Fast: |
Evan Cheng | 5c2d428 | 2010-10-23 02:19:37 +0000 | [diff] [blame] | 1143 | if (Subtarget->hasVFP2() && !isVarArg) { |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1144 | if (!Subtarget->isAAPCS_ABI()) |
| 1145 | return (Return ? RetFastCC_ARM_APCS : FastCC_ARM_APCS); |
| 1146 | // For AAPCS ABI targets, just use VFP variant of the calling convention. |
| 1147 | return (Return ? RetCC_ARM_AAPCS_VFP : CC_ARM_AAPCS_VFP); |
| 1148 | } |
| 1149 | // Fallthrough |
| 1150 | case CallingConv::C: { |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1151 | // Use target triple & subtarget features to do actual dispatch. |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1152 | if (!Subtarget->isAAPCS_ABI()) |
| 1153 | return (Return ? RetCC_ARM_APCS : CC_ARM_APCS); |
| 1154 | else if (Subtarget->hasVFP2() && |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 1155 | getTargetMachine().Options.FloatABIType == FloatABI::Hard && |
| 1156 | !isVarArg) |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1157 | return (Return ? RetCC_ARM_AAPCS_VFP : CC_ARM_AAPCS_VFP); |
| 1158 | return (Return ? RetCC_ARM_AAPCS : CC_ARM_AAPCS); |
| 1159 | } |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1160 | case CallingConv::ARM_AAPCS_VFP: |
Anton Korobeynikov | f349cb8 | 2012-01-29 09:06:09 +0000 | [diff] [blame] | 1161 | if (!isVarArg) |
| 1162 | return (Return ? RetCC_ARM_AAPCS_VFP : CC_ARM_AAPCS_VFP); |
| 1163 | // Fallthrough |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1164 | case CallingConv::ARM_AAPCS: |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1165 | return (Return ? RetCC_ARM_AAPCS : CC_ARM_AAPCS); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1166 | case CallingConv::ARM_APCS: |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1167 | return (Return ? RetCC_ARM_APCS : CC_ARM_APCS); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1168 | } |
| 1169 | } |
| 1170 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1171 | /// LowerCallResult - Lower the result values of a call into the |
| 1172 | /// appropriate copies out of appropriate physical registers. |
| 1173 | SDValue |
| 1174 | ARMTargetLowering::LowerCallResult(SDValue Chain, SDValue InFlag, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1175 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1176 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 1177 | DebugLoc dl, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1178 | SmallVectorImpl<SDValue> &InVals) const { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1179 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1180 | // Assign locations to each value returned by this call. |
| 1181 | SmallVector<CCValAssign, 16> RVLocs; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1182 | ARMCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), |
| 1183 | getTargetMachine(), RVLocs, *DAG.getContext(), Call); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1184 | CCInfo.AnalyzeCallResult(Ins, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1185 | CCAssignFnForNode(CallConv, /* Return*/ true, |
| 1186 | isVarArg)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1187 | |
| 1188 | // Copy all of the result registers out of their specified physreg. |
| 1189 | for (unsigned i = 0; i != RVLocs.size(); ++i) { |
| 1190 | CCValAssign VA = RVLocs[i]; |
| 1191 | |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1192 | SDValue Val; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1193 | if (VA.needsCustom()) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1194 | // Handle f64 or half of a v2f64. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1195 | SDValue Lo = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1196 | InFlag); |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1197 | Chain = Lo.getValue(1); |
| 1198 | InFlag = Lo.getValue(2); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1199 | VA = RVLocs[++i]; // skip ahead to next loc |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1200 | SDValue Hi = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1201 | InFlag); |
| 1202 | Chain = Hi.getValue(1); |
| 1203 | InFlag = Hi.getValue(2); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1204 | Val = DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1205 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1206 | if (VA.getLocVT() == MVT::v2f64) { |
| 1207 | SDValue Vec = DAG.getNode(ISD::UNDEF, dl, MVT::v2f64); |
| 1208 | Vec = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Vec, Val, |
| 1209 | DAG.getConstant(0, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1210 | |
| 1211 | VA = RVLocs[++i]; // skip ahead to next loc |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1212 | Lo = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, InFlag); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1213 | Chain = Lo.getValue(1); |
| 1214 | InFlag = Lo.getValue(2); |
| 1215 | VA = RVLocs[++i]; // skip ahead to next loc |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1216 | Hi = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, InFlag); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1217 | Chain = Hi.getValue(1); |
| 1218 | InFlag = Hi.getValue(2); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1219 | Val = DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1220 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Vec, Val, |
| 1221 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1222 | } |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1223 | } else { |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1224 | Val = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), VA.getLocVT(), |
| 1225 | InFlag); |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1226 | Chain = Val.getValue(1); |
| 1227 | InFlag = Val.getValue(2); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1228 | } |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1229 | |
| 1230 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1231 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1232 | case CCValAssign::Full: break; |
| 1233 | case CCValAssign::BCvt: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1234 | Val = DAG.getNode(ISD::BITCAST, dl, VA.getValVT(), Val); |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1235 | break; |
| 1236 | } |
| 1237 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1238 | InVals.push_back(Val); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1239 | } |
| 1240 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1241 | return Chain; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1242 | } |
| 1243 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1244 | /// LowerMemOpCallTo - Store the argument to the stack. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1245 | SDValue |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1246 | ARMTargetLowering::LowerMemOpCallTo(SDValue Chain, |
| 1247 | SDValue StackPtr, SDValue Arg, |
| 1248 | DebugLoc dl, SelectionDAG &DAG, |
| 1249 | const CCValAssign &VA, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1250 | ISD::ArgFlagsTy Flags) const { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1251 | unsigned LocMemOffset = VA.getLocMemOffset(); |
| 1252 | SDValue PtrOff = DAG.getIntPtrConstant(LocMemOffset); |
| 1253 | PtrOff = DAG.getNode(ISD::ADD, dl, getPointerTy(), StackPtr, PtrOff); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1254 | return DAG.getStore(Chain, dl, Arg, PtrOff, |
Chris Lattner | fc448ff | 2010-09-21 18:51:21 +0000 | [diff] [blame] | 1255 | MachinePointerInfo::getStack(LocMemOffset), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1256 | false, false, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1257 | } |
| 1258 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1259 | void ARMTargetLowering::PassF64ArgInRegs(DebugLoc dl, SelectionDAG &DAG, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1260 | SDValue Chain, SDValue &Arg, |
| 1261 | RegsToPassVector &RegsToPass, |
| 1262 | CCValAssign &VA, CCValAssign &NextVA, |
| 1263 | SDValue &StackPtr, |
| 1264 | SmallVector<SDValue, 8> &MemOpChains, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1265 | ISD::ArgFlagsTy Flags) const { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1266 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1267 | SDValue fmrrd = DAG.getNode(ARMISD::VMOVRRD, dl, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1268 | DAG.getVTList(MVT::i32, MVT::i32), Arg); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1269 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), fmrrd)); |
| 1270 | |
| 1271 | if (NextVA.isRegLoc()) |
| 1272 | RegsToPass.push_back(std::make_pair(NextVA.getLocReg(), fmrrd.getValue(1))); |
| 1273 | else { |
| 1274 | assert(NextVA.isMemLoc()); |
| 1275 | if (StackPtr.getNode() == 0) |
| 1276 | StackPtr = DAG.getCopyFromReg(Chain, dl, ARM::SP, getPointerTy()); |
| 1277 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1278 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, fmrrd.getValue(1), |
| 1279 | dl, DAG, NextVA, |
| 1280 | Flags)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1281 | } |
| 1282 | } |
| 1283 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1284 | /// LowerCall - Lowering a call into a callseq_start <- |
Evan Cheng | fc40342 | 2007-02-03 08:53:01 +0000 | [diff] [blame] | 1285 | /// ARMISD:CALL <- callseq_end chain. Also add input and output parameter |
| 1286 | /// nodes. |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1287 | SDValue |
Evan Cheng | 022d9e1 | 2010-02-02 23:55:14 +0000 | [diff] [blame] | 1288 | ARMTargetLowering::LowerCall(SDValue Chain, SDValue Callee, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1289 | CallingConv::ID CallConv, bool isVarArg, |
Evan Cheng | 4bfcd4a | 2012-02-28 18:51:51 +0000 | [diff] [blame] | 1290 | bool doesNotRet, bool &isTailCall, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1291 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1292 | const SmallVectorImpl<SDValue> &OutVals, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1293 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 1294 | DebugLoc dl, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1295 | SmallVectorImpl<SDValue> &InVals) const { |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1296 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1297 | bool IsStructRet = (Outs.empty()) ? false : Outs[0].Flags.isSRet(); |
| 1298 | bool IsSibCall = false; |
Bob Wilson | 6d2f9ce | 2011-10-07 17:17:49 +0000 | [diff] [blame] | 1299 | // Disable tail calls if they're not supported. |
| 1300 | if (!EnableARMTailCalls && !Subtarget->supportsTailCall()) |
Bob Wilson | 703af3a | 2010-08-13 22:43:33 +0000 | [diff] [blame] | 1301 | isTailCall = false; |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1302 | if (isTailCall) { |
| 1303 | // Check if it's really possible to do a tail call. |
| 1304 | isTailCall = IsEligibleForTailCallOptimization(Callee, CallConv, |
| 1305 | isVarArg, IsStructRet, MF.getFunction()->hasStructRetAttr(), |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1306 | Outs, OutVals, Ins, DAG); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1307 | // We don't support GuaranteedTailCallOpt for ARM, only automatically |
| 1308 | // detected sibcalls. |
| 1309 | if (isTailCall) { |
| 1310 | ++NumTailCalls; |
| 1311 | IsSibCall = true; |
| 1312 | } |
| 1313 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1314 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1315 | // Analyze operands of the call, assigning locations to each operand. |
| 1316 | SmallVector<CCValAssign, 16> ArgLocs; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1317 | ARMCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), |
| 1318 | getTargetMachine(), ArgLocs, *DAG.getContext(), Call); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1319 | CCInfo.AnalyzeCallOperands(Outs, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1320 | CCAssignFnForNode(CallConv, /* Return*/ false, |
| 1321 | isVarArg)); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1322 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1323 | // Get a count of how many bytes are to be pushed on the stack. |
| 1324 | unsigned NumBytes = CCInfo.getNextStackOffset(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1325 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1326 | // For tail calls, memory operands are available in our caller's stack. |
| 1327 | if (IsSibCall) |
| 1328 | NumBytes = 0; |
| 1329 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1330 | // Adjust the stack pointer for the new arguments... |
| 1331 | // These operations are automatically eliminated by the prolog/epilog pass |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1332 | if (!IsSibCall) |
| 1333 | Chain = DAG.getCALLSEQ_START(Chain, DAG.getIntPtrConstant(NumBytes, true)); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1334 | |
Jim Grosbach | f9a4b76 | 2010-02-24 01:43:03 +0000 | [diff] [blame] | 1335 | SDValue StackPtr = DAG.getCopyFromReg(Chain, dl, ARM::SP, getPointerTy()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1336 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1337 | RegsToPassVector RegsToPass; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1338 | SmallVector<SDValue, 8> MemOpChains; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1339 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1340 | // Walk the register/memloc assignments, inserting copies/loads. In the case |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1341 | // of tail call optimization, arguments are handled later. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1342 | for (unsigned i = 0, realArgIdx = 0, e = ArgLocs.size(); |
| 1343 | i != e; |
| 1344 | ++i, ++realArgIdx) { |
| 1345 | CCValAssign &VA = ArgLocs[i]; |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1346 | SDValue Arg = OutVals[realArgIdx]; |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1347 | ISD::ArgFlagsTy Flags = Outs[realArgIdx].Flags; |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1348 | bool isByVal = Flags.isByVal(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1349 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1350 | // Promote the value if needed. |
| 1351 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1352 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1353 | case CCValAssign::Full: break; |
| 1354 | case CCValAssign::SExt: |
| 1355 | Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg); |
| 1356 | break; |
| 1357 | case CCValAssign::ZExt: |
| 1358 | Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg); |
| 1359 | break; |
| 1360 | case CCValAssign::AExt: |
| 1361 | Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg); |
| 1362 | break; |
| 1363 | case CCValAssign::BCvt: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1364 | Arg = DAG.getNode(ISD::BITCAST, dl, VA.getLocVT(), Arg); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1365 | break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1366 | } |
| 1367 | |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1368 | // 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] | 1369 | if (VA.needsCustom()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1370 | if (VA.getLocVT() == MVT::v2f64) { |
| 1371 | SDValue Op0 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1372 | DAG.getConstant(0, MVT::i32)); |
| 1373 | SDValue Op1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1374 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1375 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1376 | PassF64ArgInRegs(dl, DAG, Chain, Op0, RegsToPass, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1377 | VA, ArgLocs[++i], StackPtr, MemOpChains, Flags); |
| 1378 | |
| 1379 | VA = ArgLocs[++i]; // skip ahead to next loc |
| 1380 | if (VA.isRegLoc()) { |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1381 | PassF64ArgInRegs(dl, DAG, Chain, Op1, RegsToPass, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1382 | VA, ArgLocs[++i], StackPtr, MemOpChains, Flags); |
| 1383 | } else { |
| 1384 | assert(VA.isMemLoc()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1385 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1386 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, Op1, |
| 1387 | dl, DAG, VA, Flags)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1388 | } |
| 1389 | } else { |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1390 | PassF64ArgInRegs(dl, DAG, Chain, Arg, RegsToPass, VA, ArgLocs[++i], |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1391 | StackPtr, MemOpChains, Flags); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1392 | } |
| 1393 | } else if (VA.isRegLoc()) { |
| 1394 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg)); |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1395 | } else if (isByVal) { |
| 1396 | assert(VA.isMemLoc()); |
| 1397 | unsigned offset = 0; |
| 1398 | |
| 1399 | // True if this byval aggregate will be split between registers |
| 1400 | // and memory. |
| 1401 | if (CCInfo.isFirstByValRegValid()) { |
| 1402 | EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
| 1403 | unsigned int i, j; |
| 1404 | for (i = 0, j = CCInfo.getFirstByValReg(); j < ARM::R4; i++, j++) { |
| 1405 | SDValue Const = DAG.getConstant(4*i, MVT::i32); |
| 1406 | SDValue AddArg = DAG.getNode(ISD::ADD, dl, PtrVT, Arg, Const); |
| 1407 | SDValue Load = DAG.getLoad(PtrVT, dl, Chain, AddArg, |
| 1408 | MachinePointerInfo(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 1409 | false, false, false, 0); |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1410 | MemOpChains.push_back(Load.getValue(1)); |
| 1411 | RegsToPass.push_back(std::make_pair(j, Load)); |
| 1412 | } |
| 1413 | offset = ARM::R4 - CCInfo.getFirstByValReg(); |
| 1414 | CCInfo.clearFirstByValReg(); |
| 1415 | } |
| 1416 | |
| 1417 | unsigned LocMemOffset = VA.getLocMemOffset(); |
| 1418 | SDValue StkPtrOff = DAG.getIntPtrConstant(LocMemOffset); |
| 1419 | SDValue Dst = DAG.getNode(ISD::ADD, dl, getPointerTy(), StackPtr, |
| 1420 | StkPtrOff); |
| 1421 | SDValue SrcOffset = DAG.getIntPtrConstant(4*offset); |
| 1422 | SDValue Src = DAG.getNode(ISD::ADD, dl, getPointerTy(), Arg, SrcOffset); |
| 1423 | SDValue SizeNode = DAG.getConstant(Flags.getByValSize() - 4*offset, |
| 1424 | MVT::i32); |
| 1425 | MemOpChains.push_back(DAG.getMemcpy(Chain, dl, Dst, Src, SizeNode, |
| 1426 | Flags.getByValAlign(), |
| 1427 | /*isVolatile=*/false, |
Dan Gohman | 65fd656 | 2011-11-03 21:49:52 +0000 | [diff] [blame] | 1428 | /*AlwaysInline=*/false, |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1429 | MachinePointerInfo(0), |
| 1430 | MachinePointerInfo(0))); |
| 1431 | |
| 1432 | } else if (!IsSibCall) { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1433 | assert(VA.isMemLoc()); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1434 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1435 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, Arg, |
| 1436 | dl, DAG, VA, Flags)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1437 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1438 | } |
| 1439 | |
| 1440 | if (!MemOpChains.empty()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1441 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1442 | &MemOpChains[0], MemOpChains.size()); |
| 1443 | |
| 1444 | // Build a sequence of copy-to-reg nodes chained together with token chain |
| 1445 | // and flag operands which copy the outgoing args into the appropriate regs. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1446 | SDValue InFlag; |
Dale Johannesen | 6470a11 | 2010-06-15 22:08:33 +0000 | [diff] [blame] | 1447 | // Tail call byval lowering might overwrite argument registers so in case of |
| 1448 | // tail call optimization the copies to registers are lowered later. |
| 1449 | if (!isTailCall) |
| 1450 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 1451 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, |
| 1452 | RegsToPass[i].second, InFlag); |
| 1453 | InFlag = Chain.getValue(1); |
| 1454 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1455 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1456 | // For tail calls lower the arguments to the 'real' stack slot. |
| 1457 | if (isTailCall) { |
| 1458 | // Force all the incoming stack arguments to be loaded from the stack |
| 1459 | // before any new outgoing arguments are stored to the stack, because the |
| 1460 | // outgoing stack slots may alias the incoming argument stack slots, and |
| 1461 | // the alias isn't otherwise explicit. This is slightly more conservative |
| 1462 | // than necessary, because it means that each store effectively depends |
| 1463 | // on every argument instead of just those arguments it would clobber. |
| 1464 | |
Chris Lattner | 7a2bdde | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 1465 | // Do not flag preceding copytoreg stuff together with the following stuff. |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1466 | InFlag = SDValue(); |
| 1467 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 1468 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, |
| 1469 | RegsToPass[i].second, InFlag); |
| 1470 | InFlag = Chain.getValue(1); |
| 1471 | } |
| 1472 | InFlag =SDValue(); |
| 1473 | } |
| 1474 | |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1475 | // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every |
| 1476 | // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol |
| 1477 | // node so that legalize doesn't hack it. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1478 | bool isDirect = false; |
| 1479 | bool isARMFunc = false; |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 1480 | bool isLocalARMFunc = false; |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1481 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1482 | |
| 1483 | if (EnableARMLongCalls) { |
| 1484 | assert (getTargetMachine().getRelocationModel() == Reloc::Static |
| 1485 | && "long-calls with non-static relocation model!"); |
| 1486 | // Handle a global address or an external symbol. If it's not one of |
| 1487 | // those, the target's already in a register, so we don't need to do |
| 1488 | // anything extra. |
| 1489 | if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
Anders Carlsson | 0dbdca5 | 2010-04-15 03:11:28 +0000 | [diff] [blame] | 1490 | const GlobalValue *GV = G->getGlobal(); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1491 | // Create a constant pool entry for the callee address |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1492 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 1493 | ARMConstantPoolValue *CPV = |
| 1494 | ARMConstantPoolConstant::Create(GV, ARMPCLabelIndex, ARMCP::CPValue, 0); |
| 1495 | |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1496 | // Get the address of the callee into a register |
| 1497 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
| 1498 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| 1499 | Callee = DAG.getLoad(getPointerTy(), dl, |
| 1500 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1501 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 1502 | false, false, false, 0); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1503 | } else if (ExternalSymbolSDNode *S=dyn_cast<ExternalSymbolSDNode>(Callee)) { |
| 1504 | const char *Sym = S->getSymbol(); |
| 1505 | |
| 1506 | // Create a constant pool entry for the callee address |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1507 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Bill Wendling | fe31e67 | 2011-10-01 08:58:29 +0000 | [diff] [blame] | 1508 | ARMConstantPoolValue *CPV = |
| 1509 | ARMConstantPoolSymbol::Create(*DAG.getContext(), Sym, |
| 1510 | ARMPCLabelIndex, 0); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1511 | // Get the address of the callee into a register |
| 1512 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
| 1513 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| 1514 | Callee = DAG.getLoad(getPointerTy(), dl, |
| 1515 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1516 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 1517 | false, false, false, 0); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1518 | } |
| 1519 | } else if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 1520 | const GlobalValue *GV = G->getGlobal(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1521 | isDirect = true; |
Chris Lattner | 4fb63d0 | 2009-07-15 04:12:33 +0000 | [diff] [blame] | 1522 | bool isExt = GV->isDeclaration() || GV->isWeakForLinker(); |
Evan Cheng | 970a419 | 2007-01-19 19:28:01 +0000 | [diff] [blame] | 1523 | bool isStub = (isExt && Subtarget->isTargetDarwin()) && |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1524 | getTargetMachine().getRelocationModel() != Reloc::Static; |
| 1525 | isARMFunc = !Subtarget->isThumb() || isStub; |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 1526 | // ARM call to a local ARM function is predicable. |
Evan Cheng | 46df4eb | 2010-06-16 07:35:02 +0000 | [diff] [blame] | 1527 | isLocalARMFunc = !Subtarget->isThumb() && (!isExt || !ARMInterworking); |
Evan Cheng | c60e76d | 2007-01-30 20:37:08 +0000 | [diff] [blame] | 1528 | // tBX takes a register source operand. |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 1529 | if (isARMFunc && Subtarget->isThumb1Only() && !Subtarget->hasV5TOps()) { |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1530 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 1531 | ARMConstantPoolValue *CPV = |
| 1532 | ARMConstantPoolConstant::Create(GV, ARMPCLabelIndex, ARMCP::CPValue, 4); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1533 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1534 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1535 | Callee = DAG.getLoad(getPointerTy(), dl, |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1536 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1537 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 1538 | false, false, false, 0); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1539 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1540 | Callee = DAG.getNode(ARMISD::PIC_ADD, dl, |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1541 | getPointerTy(), Callee, PICLabel); |
Jim Grosbach | 637d89f | 2010-09-22 23:27:36 +0000 | [diff] [blame] | 1542 | } else { |
| 1543 | // On ELF targets for PIC code, direct calls should go through the PLT |
| 1544 | unsigned OpFlags = 0; |
| 1545 | if (Subtarget->isTargetELF() && |
| 1546 | getTargetMachine().getRelocationModel() == Reloc::PIC_) |
| 1547 | OpFlags = ARMII::MO_PLT; |
| 1548 | Callee = DAG.getTargetGlobalAddress(GV, dl, getPointerTy(), 0, OpFlags); |
| 1549 | } |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1550 | } else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1551 | isDirect = true; |
Evan Cheng | 970a419 | 2007-01-19 19:28:01 +0000 | [diff] [blame] | 1552 | bool isStub = Subtarget->isTargetDarwin() && |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1553 | getTargetMachine().getRelocationModel() != Reloc::Static; |
| 1554 | isARMFunc = !Subtarget->isThumb() || isStub; |
Evan Cheng | c60e76d | 2007-01-30 20:37:08 +0000 | [diff] [blame] | 1555 | // tBX takes a register source operand. |
| 1556 | const char *Sym = S->getSymbol(); |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 1557 | if (isARMFunc && Subtarget->isThumb1Only() && !Subtarget->hasV5TOps()) { |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1558 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Bill Wendling | fe31e67 | 2011-10-01 08:58:29 +0000 | [diff] [blame] | 1559 | ARMConstantPoolValue *CPV = |
| 1560 | ARMConstantPoolSymbol::Create(*DAG.getContext(), Sym, |
| 1561 | ARMPCLabelIndex, 4); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1562 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1563 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1564 | Callee = DAG.getLoad(getPointerTy(), dl, |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1565 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1566 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 1567 | false, false, false, 0); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1568 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1569 | Callee = DAG.getNode(ARMISD::PIC_ADD, dl, |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1570 | getPointerTy(), Callee, PICLabel); |
Jim Grosbach | 637d89f | 2010-09-22 23:27:36 +0000 | [diff] [blame] | 1571 | } else { |
| 1572 | unsigned OpFlags = 0; |
| 1573 | // On ELF targets for PIC code, direct calls should go through the PLT |
| 1574 | if (Subtarget->isTargetELF() && |
| 1575 | getTargetMachine().getRelocationModel() == Reloc::PIC_) |
| 1576 | OpFlags = ARMII::MO_PLT; |
| 1577 | Callee = DAG.getTargetExternalSymbol(Sym, getPointerTy(), OpFlags); |
| 1578 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1579 | } |
| 1580 | |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1581 | // FIXME: handle tail calls differently. |
| 1582 | unsigned CallOpc; |
Evan Cheng | b620724 | 2009-08-01 00:16:10 +0000 | [diff] [blame] | 1583 | if (Subtarget->isThumb()) { |
| 1584 | if ((!isDirect || isARMFunc) && !Subtarget->hasV5TOps()) |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1585 | CallOpc = ARMISD::CALL_NOLINK; |
Evan Cheng | 4bfcd4a | 2012-02-28 18:51:51 +0000 | [diff] [blame] | 1586 | else if (doesNotRet && isDirect && !isARMFunc && |
| 1587 | Subtarget->hasRAS() && !Subtarget->isThumb1Only()) |
| 1588 | // "mov lr, pc; b _foo" to avoid confusing the RSP |
| 1589 | CallOpc = ARMISD::CALL_NOLINK; |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1590 | else |
| 1591 | CallOpc = isARMFunc ? ARMISD::CALL : ARMISD::tCALL; |
| 1592 | } else { |
Evan Cheng | 4bfcd4a | 2012-02-28 18:51:51 +0000 | [diff] [blame] | 1593 | if (!isDirect && !Subtarget->hasV5TOps()) { |
| 1594 | CallOpc = ARMISD::CALL_NOLINK; |
| 1595 | } else if (doesNotRet && isDirect && Subtarget->hasRAS()) |
| 1596 | // "mov lr, pc; b _foo" to avoid confusing the RSP |
| 1597 | CallOpc = ARMISD::CALL_NOLINK; |
| 1598 | else |
| 1599 | CallOpc = isLocalARMFunc ? ARMISD::CALL_PRED : ARMISD::CALL; |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1600 | } |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1601 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1602 | std::vector<SDValue> Ops; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1603 | Ops.push_back(Chain); |
| 1604 | Ops.push_back(Callee); |
| 1605 | |
| 1606 | // Add argument registers to the end of the list so that they are known live |
| 1607 | // into the call. |
| 1608 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) |
| 1609 | Ops.push_back(DAG.getRegister(RegsToPass[i].first, |
| 1610 | RegsToPass[i].second.getValueType())); |
| 1611 | |
Jakob Stoklund Olesen | c54f634 | 2012-02-24 01:19:29 +0000 | [diff] [blame] | 1612 | // Add a register mask operand representing the call-preserved registers. |
| 1613 | const TargetRegisterInfo *TRI = getTargetMachine().getRegisterInfo(); |
| 1614 | const uint32_t *Mask = TRI->getCallPreservedMask(CallConv); |
| 1615 | assert(Mask && "Missing call preserved mask for calling convention"); |
| 1616 | Ops.push_back(DAG.getRegisterMask(Mask)); |
| 1617 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1618 | if (InFlag.getNode()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1619 | Ops.push_back(InFlag); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1620 | |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 1621 | SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue); |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1622 | if (isTailCall) |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1623 | return DAG.getNode(ARMISD::TC_RETURN, dl, NodeTys, &Ops[0], Ops.size()); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1624 | |
Duncan Sands | 4bdcb61 | 2008-07-02 17:40:58 +0000 | [diff] [blame] | 1625 | // Returns a chain and a flag for retval copy to use. |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1626 | Chain = DAG.getNode(CallOpc, dl, NodeTys, &Ops[0], Ops.size()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1627 | InFlag = Chain.getValue(1); |
| 1628 | |
Chris Lattner | e563bbc | 2008-10-11 22:08:30 +0000 | [diff] [blame] | 1629 | Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(NumBytes, true), |
| 1630 | DAG.getIntPtrConstant(0, true), InFlag); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1631 | if (!Ins.empty()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1632 | InFlag = Chain.getValue(1); |
| 1633 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1634 | // Handle result values, copying them out of physregs into vregs that we |
| 1635 | // return. |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1636 | return LowerCallResult(Chain, InFlag, CallConv, isVarArg, Ins, |
| 1637 | dl, DAG, InVals); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1638 | } |
| 1639 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1640 | /// HandleByVal - Every parameter *after* a byval parameter is passed |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1641 | /// on the stack. Remember the next parameter register to allocate, |
| 1642 | /// and then confiscate the rest of the parameter registers to insure |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1643 | /// this. |
| 1644 | void |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1645 | llvm::ARMTargetLowering::HandleByVal(CCState *State, unsigned &size) const { |
| 1646 | unsigned reg = State->AllocateReg(GPRArgRegs, 4); |
| 1647 | assert((State->getCallOrPrologue() == Prologue || |
| 1648 | State->getCallOrPrologue() == Call) && |
| 1649 | "unhandled ParmContext"); |
| 1650 | if ((!State->isFirstByValRegValid()) && |
| 1651 | (ARM::R0 <= reg) && (reg <= ARM::R3)) { |
| 1652 | State->setFirstByValReg(reg); |
| 1653 | // At a call site, a byval parameter that is split between |
| 1654 | // registers and memory needs its size truncated here. In a |
| 1655 | // function prologue, such byval parameters are reassembled in |
| 1656 | // memory, and are not truncated. |
| 1657 | if (State->getCallOrPrologue() == Call) { |
| 1658 | unsigned excess = 4 * (ARM::R4 - reg); |
| 1659 | assert(size >= excess && "expected larger existing stack allocation"); |
| 1660 | size -= excess; |
| 1661 | } |
| 1662 | } |
| 1663 | // Confiscate any remaining parameter registers to preclude their |
| 1664 | // assignment to subsequent parameters. |
| 1665 | while (State->AllocateReg(GPRArgRegs, 4)) |
| 1666 | ; |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1667 | } |
| 1668 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1669 | /// MatchingStackOffset - Return true if the given stack call argument is |
| 1670 | /// already available in the same position (relatively) of the caller's |
| 1671 | /// incoming argument stack. |
| 1672 | static |
| 1673 | bool MatchingStackOffset(SDValue Arg, unsigned Offset, ISD::ArgFlagsTy Flags, |
| 1674 | MachineFrameInfo *MFI, const MachineRegisterInfo *MRI, |
| 1675 | const ARMInstrInfo *TII) { |
| 1676 | unsigned Bytes = Arg.getValueType().getSizeInBits() / 8; |
| 1677 | int FI = INT_MAX; |
| 1678 | if (Arg.getOpcode() == ISD::CopyFromReg) { |
| 1679 | unsigned VR = cast<RegisterSDNode>(Arg.getOperand(1))->getReg(); |
Jakob Stoklund Olesen | c9df025 | 2011-01-10 02:58:51 +0000 | [diff] [blame] | 1680 | if (!TargetRegisterInfo::isVirtualRegister(VR)) |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1681 | return false; |
| 1682 | MachineInstr *Def = MRI->getVRegDef(VR); |
| 1683 | if (!Def) |
| 1684 | return false; |
| 1685 | if (!Flags.isByVal()) { |
| 1686 | if (!TII->isLoadFromStackSlot(Def, FI)) |
| 1687 | return false; |
| 1688 | } else { |
Dale Johannesen | 7835f1f | 2010-07-08 01:18:23 +0000 | [diff] [blame] | 1689 | return false; |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1690 | } |
| 1691 | } else if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Arg)) { |
| 1692 | if (Flags.isByVal()) |
| 1693 | // ByVal argument is passed in as a pointer but it's now being |
| 1694 | // dereferenced. e.g. |
| 1695 | // define @foo(%struct.X* %A) { |
| 1696 | // tail call @bar(%struct.X* byval %A) |
| 1697 | // } |
| 1698 | return false; |
| 1699 | SDValue Ptr = Ld->getBasePtr(); |
| 1700 | FrameIndexSDNode *FINode = dyn_cast<FrameIndexSDNode>(Ptr); |
| 1701 | if (!FINode) |
| 1702 | return false; |
| 1703 | FI = FINode->getIndex(); |
| 1704 | } else |
| 1705 | return false; |
| 1706 | |
| 1707 | assert(FI != INT_MAX); |
| 1708 | if (!MFI->isFixedObjectIndex(FI)) |
| 1709 | return false; |
| 1710 | return Offset == MFI->getObjectOffset(FI) && Bytes == MFI->getObjectSize(FI); |
| 1711 | } |
| 1712 | |
| 1713 | /// IsEligibleForTailCallOptimization - Check whether the call is eligible |
| 1714 | /// for tail call optimization. Targets which want to do tail call |
| 1715 | /// optimization should implement this function. |
| 1716 | bool |
| 1717 | ARMTargetLowering::IsEligibleForTailCallOptimization(SDValue Callee, |
| 1718 | CallingConv::ID CalleeCC, |
| 1719 | bool isVarArg, |
| 1720 | bool isCalleeStructRet, |
| 1721 | bool isCallerStructRet, |
| 1722 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1723 | const SmallVectorImpl<SDValue> &OutVals, |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1724 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 1725 | SelectionDAG& DAG) const { |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1726 | const Function *CallerF = DAG.getMachineFunction().getFunction(); |
| 1727 | CallingConv::ID CallerCC = CallerF->getCallingConv(); |
| 1728 | bool CCMatch = CallerCC == CalleeCC; |
| 1729 | |
| 1730 | // Look for obvious safe cases to perform tail call optimization that do not |
| 1731 | // require ABI changes. This is what gcc calls sibcall. |
| 1732 | |
Jim Grosbach | 7616b64 | 2010-06-16 23:45:49 +0000 | [diff] [blame] | 1733 | // Do not sibcall optimize vararg calls unless the call site is not passing |
| 1734 | // any arguments. |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1735 | if (isVarArg && !Outs.empty()) |
| 1736 | return false; |
| 1737 | |
| 1738 | // Also avoid sibcall optimization if either caller or callee uses struct |
| 1739 | // return semantics. |
| 1740 | if (isCalleeStructRet || isCallerStructRet) |
| 1741 | return false; |
| 1742 | |
Dale Johannesen | e39fdbe | 2010-06-23 18:52:34 +0000 | [diff] [blame] | 1743 | // FIXME: Completely disable sibcall for Thumb1 since Thumb1RegisterInfo:: |
Jim Grosbach | 8dc41f3 | 2011-07-08 20:18:11 +0000 | [diff] [blame] | 1744 | // emitEpilogue is not ready for them. Thumb tail calls also use t2B, as |
| 1745 | // the Thumb1 16-bit unconditional branch doesn't have sufficient relocation |
| 1746 | // support in the assembler and linker to be used. This would need to be |
| 1747 | // fixed to fully support tail calls in Thumb1. |
| 1748 | // |
Dale Johannesen | 7835f1f | 2010-07-08 01:18:23 +0000 | [diff] [blame] | 1749 | // Doing this is tricky, since the LDM/POP instruction on Thumb doesn't take |
| 1750 | // LR. This means if we need to reload LR, it takes an extra instructions, |
| 1751 | // which outweighs the value of the tail call; but here we don't know yet |
| 1752 | // whether LR is going to be used. Probably the right approach is to |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 1753 | // generate the tail call here and turn it back into CALL/RET in |
Dale Johannesen | 7835f1f | 2010-07-08 01:18:23 +0000 | [diff] [blame] | 1754 | // emitEpilogue if LR is used. |
Dale Johannesen | 7835f1f | 2010-07-08 01:18:23 +0000 | [diff] [blame] | 1755 | |
| 1756 | // Thumb1 PIC calls to external symbols use BX, so they can be tail calls, |
| 1757 | // but we need to make sure there are enough registers; the only valid |
| 1758 | // registers are the 4 used for parameters. We don't currently do this |
| 1759 | // case. |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1760 | if (Subtarget->isThumb1Only()) |
| 1761 | return false; |
Dale Johannesen | df50d7e | 2010-06-18 18:13:11 +0000 | [diff] [blame] | 1762 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1763 | // If the calling conventions do not match, then we'd better make sure the |
| 1764 | // results are returned in the same way as what the caller expects. |
| 1765 | if (!CCMatch) { |
| 1766 | SmallVector<CCValAssign, 16> RVLocs1; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1767 | ARMCCState CCInfo1(CalleeCC, false, DAG.getMachineFunction(), |
| 1768 | getTargetMachine(), RVLocs1, *DAG.getContext(), Call); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1769 | CCInfo1.AnalyzeCallResult(Ins, CCAssignFnForNode(CalleeCC, true, isVarArg)); |
| 1770 | |
| 1771 | SmallVector<CCValAssign, 16> RVLocs2; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1772 | ARMCCState CCInfo2(CallerCC, false, DAG.getMachineFunction(), |
| 1773 | getTargetMachine(), RVLocs2, *DAG.getContext(), Call); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1774 | CCInfo2.AnalyzeCallResult(Ins, CCAssignFnForNode(CallerCC, true, isVarArg)); |
| 1775 | |
| 1776 | if (RVLocs1.size() != RVLocs2.size()) |
| 1777 | return false; |
| 1778 | for (unsigned i = 0, e = RVLocs1.size(); i != e; ++i) { |
| 1779 | if (RVLocs1[i].isRegLoc() != RVLocs2[i].isRegLoc()) |
| 1780 | return false; |
| 1781 | if (RVLocs1[i].getLocInfo() != RVLocs2[i].getLocInfo()) |
| 1782 | return false; |
| 1783 | if (RVLocs1[i].isRegLoc()) { |
| 1784 | if (RVLocs1[i].getLocReg() != RVLocs2[i].getLocReg()) |
| 1785 | return false; |
| 1786 | } else { |
| 1787 | if (RVLocs1[i].getLocMemOffset() != RVLocs2[i].getLocMemOffset()) |
| 1788 | return false; |
| 1789 | } |
| 1790 | } |
| 1791 | } |
| 1792 | |
| 1793 | // If the callee takes no arguments then go on to check the results of the |
| 1794 | // call. |
| 1795 | if (!Outs.empty()) { |
| 1796 | // Check if stack adjustment is needed. For now, do not do this if any |
| 1797 | // argument is passed on the stack. |
| 1798 | SmallVector<CCValAssign, 16> ArgLocs; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1799 | ARMCCState CCInfo(CalleeCC, isVarArg, DAG.getMachineFunction(), |
| 1800 | getTargetMachine(), ArgLocs, *DAG.getContext(), Call); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1801 | CCInfo.AnalyzeCallOperands(Outs, |
| 1802 | CCAssignFnForNode(CalleeCC, false, isVarArg)); |
| 1803 | if (CCInfo.getNextStackOffset()) { |
| 1804 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1805 | |
| 1806 | // Check if the arguments are already laid out in the right way as |
| 1807 | // the caller's fixed stack objects. |
| 1808 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 1809 | const MachineRegisterInfo *MRI = &MF.getRegInfo(); |
| 1810 | const ARMInstrInfo *TII = |
| 1811 | ((ARMTargetMachine&)getTargetMachine()).getInstrInfo(); |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1812 | for (unsigned i = 0, realArgIdx = 0, e = ArgLocs.size(); |
| 1813 | i != e; |
| 1814 | ++i, ++realArgIdx) { |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1815 | CCValAssign &VA = ArgLocs[i]; |
| 1816 | EVT RegVT = VA.getLocVT(); |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1817 | SDValue Arg = OutVals[realArgIdx]; |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1818 | ISD::ArgFlagsTy Flags = Outs[realArgIdx].Flags; |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1819 | if (VA.getLocInfo() == CCValAssign::Indirect) |
| 1820 | return false; |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1821 | if (VA.needsCustom()) { |
| 1822 | // f64 and vector types are split into multiple registers or |
| 1823 | // register/stack-slot combinations. The types will not match |
| 1824 | // the registers; give up on memory f64 refs until we figure |
| 1825 | // out what to do about this. |
| 1826 | if (!VA.isRegLoc()) |
| 1827 | return false; |
| 1828 | if (!ArgLocs[++i].isRegLoc()) |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 1829 | return false; |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1830 | if (RegVT == MVT::v2f64) { |
| 1831 | if (!ArgLocs[++i].isRegLoc()) |
| 1832 | return false; |
| 1833 | if (!ArgLocs[++i].isRegLoc()) |
| 1834 | return false; |
| 1835 | } |
| 1836 | } else if (!VA.isRegLoc()) { |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1837 | if (!MatchingStackOffset(Arg, VA.getLocMemOffset(), Flags, |
| 1838 | MFI, MRI, TII)) |
| 1839 | return false; |
| 1840 | } |
| 1841 | } |
| 1842 | } |
| 1843 | } |
| 1844 | |
| 1845 | return true; |
| 1846 | } |
| 1847 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1848 | SDValue |
| 1849 | ARMTargetLowering::LowerReturn(SDValue Chain, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1850 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1851 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1852 | const SmallVectorImpl<SDValue> &OutVals, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1853 | DebugLoc dl, SelectionDAG &DAG) const { |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1854 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1855 | // CCValAssign - represent the assignment of the return value to a location. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1856 | SmallVector<CCValAssign, 16> RVLocs; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1857 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1858 | // CCState - Info about the registers and stack slots. |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1859 | ARMCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), |
| 1860 | getTargetMachine(), RVLocs, *DAG.getContext(), Call); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1861 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1862 | // Analyze outgoing return values. |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1863 | CCInfo.AnalyzeReturn(Outs, CCAssignFnForNode(CallConv, /* Return */ true, |
| 1864 | isVarArg)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1865 | |
| 1866 | // If this is the first return lowered for this function, add |
| 1867 | // the regs to the liveout set for the function. |
| 1868 | if (DAG.getMachineFunction().getRegInfo().liveout_empty()) { |
| 1869 | for (unsigned i = 0; i != RVLocs.size(); ++i) |
| 1870 | if (RVLocs[i].isRegLoc()) |
| 1871 | DAG.getMachineFunction().getRegInfo().addLiveOut(RVLocs[i].getLocReg()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1872 | } |
| 1873 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1874 | SDValue Flag; |
| 1875 | |
| 1876 | // Copy the result values into the output registers. |
| 1877 | for (unsigned i = 0, realRVLocIdx = 0; |
| 1878 | i != RVLocs.size(); |
| 1879 | ++i, ++realRVLocIdx) { |
| 1880 | CCValAssign &VA = RVLocs[i]; |
| 1881 | assert(VA.isRegLoc() && "Can only return in registers!"); |
| 1882 | |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1883 | SDValue Arg = OutVals[realRVLocIdx]; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1884 | |
| 1885 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1886 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1887 | case CCValAssign::Full: break; |
| 1888 | case CCValAssign::BCvt: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1889 | Arg = DAG.getNode(ISD::BITCAST, dl, VA.getLocVT(), Arg); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1890 | break; |
| 1891 | } |
| 1892 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1893 | if (VA.needsCustom()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1894 | if (VA.getLocVT() == MVT::v2f64) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1895 | // Extract the first half and return it in two registers. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1896 | SDValue Half = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1897 | DAG.getConstant(0, MVT::i32)); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1898 | SDValue HalfGPRs = DAG.getNode(ARMISD::VMOVRRD, dl, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1899 | DAG.getVTList(MVT::i32, MVT::i32), Half); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1900 | |
| 1901 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), HalfGPRs, Flag); |
| 1902 | Flag = Chain.getValue(1); |
| 1903 | VA = RVLocs[++i]; // skip ahead to next loc |
| 1904 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), |
| 1905 | HalfGPRs.getValue(1), Flag); |
| 1906 | Flag = Chain.getValue(1); |
| 1907 | VA = RVLocs[++i]; // skip ahead to next loc |
| 1908 | |
| 1909 | // 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] | 1910 | Arg = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1911 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1912 | } |
| 1913 | // Legalize ret f64 -> ret 2 x i32. We always have fmrrd if f64 is |
| 1914 | // available. |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1915 | SDValue fmrrd = DAG.getNode(ARMISD::VMOVRRD, dl, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1916 | DAG.getVTList(MVT::i32, MVT::i32), &Arg, 1); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1917 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), fmrrd, Flag); |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1918 | Flag = Chain.getValue(1); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1919 | VA = RVLocs[++i]; // skip ahead to next loc |
| 1920 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), fmrrd.getValue(1), |
| 1921 | Flag); |
| 1922 | } else |
| 1923 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), Arg, Flag); |
| 1924 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1925 | // Guarantee that all emitted copies are |
| 1926 | // stuck together, avoiding something bad. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1927 | Flag = Chain.getValue(1); |
| 1928 | } |
| 1929 | |
| 1930 | SDValue result; |
| 1931 | if (Flag.getNode()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1932 | result = DAG.getNode(ARMISD::RET_FLAG, dl, MVT::Other, Chain, Flag); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1933 | else // Return Void |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1934 | result = DAG.getNode(ARMISD::RET_FLAG, dl, MVT::Other, Chain); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1935 | |
| 1936 | return result; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1937 | } |
| 1938 | |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1939 | bool ARMTargetLowering::isUsedByReturnOnly(SDNode *N) const { |
| 1940 | if (N->getNumValues() != 1) |
| 1941 | return false; |
| 1942 | if (!N->hasNUsesOfValue(1, 0)) |
| 1943 | return false; |
| 1944 | |
| 1945 | unsigned NumCopies = 0; |
Jason W Kim | 1de886c | 2012-02-10 16:07:59 +0000 | [diff] [blame] | 1946 | SDNode* Copies[2] = { 0, 0 }; |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1947 | SDNode *Use = *N->use_begin(); |
| 1948 | if (Use->getOpcode() == ISD::CopyToReg) { |
| 1949 | Copies[NumCopies++] = Use; |
| 1950 | } else if (Use->getOpcode() == ARMISD::VMOVRRD) { |
| 1951 | // f64 returned in a pair of GPRs. |
| 1952 | for (SDNode::use_iterator UI = Use->use_begin(), UE = Use->use_end(); |
| 1953 | UI != UE; ++UI) { |
| 1954 | if (UI->getOpcode() != ISD::CopyToReg) |
| 1955 | return false; |
| 1956 | Copies[UI.getUse().getResNo()] = *UI; |
| 1957 | ++NumCopies; |
| 1958 | } |
| 1959 | } else if (Use->getOpcode() == ISD::BITCAST) { |
| 1960 | // f32 returned in a single GPR. |
| 1961 | if (!Use->hasNUsesOfValue(1, 0)) |
| 1962 | return false; |
| 1963 | Use = *Use->use_begin(); |
| 1964 | if (Use->getOpcode() != ISD::CopyToReg || !Use->hasNUsesOfValue(1, 0)) |
| 1965 | return false; |
| 1966 | Copies[NumCopies++] = Use; |
| 1967 | } else { |
| 1968 | return false; |
| 1969 | } |
| 1970 | |
| 1971 | if (NumCopies != 1 && NumCopies != 2) |
| 1972 | return false; |
Evan Cheng | 1bf891a | 2010-12-01 22:59:46 +0000 | [diff] [blame] | 1973 | |
| 1974 | bool HasRet = false; |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1975 | for (unsigned i = 0; i < NumCopies; ++i) { |
| 1976 | SDNode *Copy = Copies[i]; |
| 1977 | for (SDNode::use_iterator UI = Copy->use_begin(), UE = Copy->use_end(); |
| 1978 | UI != UE; ++UI) { |
| 1979 | if (UI->getOpcode() == ISD::CopyToReg) { |
| 1980 | SDNode *Use = *UI; |
Jason W Kim | 1de886c | 2012-02-10 16:07:59 +0000 | [diff] [blame] | 1981 | if (Use == Copies[0] || ((NumCopies == 2) && (Use == Copies[1]))) |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1982 | continue; |
| 1983 | return false; |
| 1984 | } |
| 1985 | if (UI->getOpcode() != ARMISD::RET_FLAG) |
| 1986 | return false; |
Evan Cheng | 1bf891a | 2010-12-01 22:59:46 +0000 | [diff] [blame] | 1987 | HasRet = true; |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1988 | } |
| 1989 | } |
| 1990 | |
Evan Cheng | 1bf891a | 2010-12-01 22:59:46 +0000 | [diff] [blame] | 1991 | return HasRet; |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1992 | } |
| 1993 | |
Evan Cheng | 485fafc | 2011-03-21 01:19:09 +0000 | [diff] [blame] | 1994 | bool ARMTargetLowering::mayBeEmittedAsTailCall(CallInst *CI) const { |
| 1995 | if (!EnableARMTailCalls) |
| 1996 | return false; |
| 1997 | |
| 1998 | if (!CI->isTailCall()) |
| 1999 | return false; |
| 2000 | |
| 2001 | return !Subtarget->isThumb1Only(); |
| 2002 | } |
| 2003 | |
Bob Wilson | b62d257 | 2009-11-03 00:02:05 +0000 | [diff] [blame] | 2004 | // ConstantPool, JumpTable, GlobalAddress, and ExternalSymbol are lowered as |
| 2005 | // their target counterpart wrapped in the ARMISD::Wrapper node. Suppose N is |
| 2006 | // one of the above mentioned nodes. It has to be wrapped because otherwise |
| 2007 | // Select(N) returns N. So the raw TargetGlobalAddress nodes, etc. can only |
| 2008 | // be used to form addressing mode. These wrapped nodes will be selected |
| 2009 | // into MOVi. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2010 | static SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2011 | EVT PtrVT = Op.getValueType(); |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 2012 | // FIXME there is no actual debug info here |
| 2013 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2014 | ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2015 | SDValue Res; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2016 | if (CP->isMachineConstantPoolEntry()) |
| 2017 | Res = DAG.getTargetConstantPool(CP->getMachineCPVal(), PtrVT, |
| 2018 | CP->getAlignment()); |
| 2019 | else |
| 2020 | Res = DAG.getTargetConstantPool(CP->getConstVal(), PtrVT, |
| 2021 | CP->getAlignment()); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2022 | return DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Res); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2023 | } |
| 2024 | |
Jim Grosbach | e1102ca | 2010-07-19 17:20:38 +0000 | [diff] [blame] | 2025 | unsigned ARMTargetLowering::getJumpTableEncoding() const { |
| 2026 | return MachineJumpTableInfo::EK_Inline; |
| 2027 | } |
| 2028 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2029 | SDValue ARMTargetLowering::LowerBlockAddress(SDValue Op, |
| 2030 | SelectionDAG &DAG) const { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2031 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2032 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2033 | unsigned ARMPCLabelIndex = 0; |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 2034 | DebugLoc DL = Op.getDebugLoc(); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2035 | EVT PtrVT = getPointerTy(); |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2036 | const BlockAddress *BA = cast<BlockAddressSDNode>(Op)->getBlockAddress(); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2037 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| 2038 | SDValue CPAddr; |
| 2039 | if (RelocM == Reloc::Static) { |
| 2040 | CPAddr = DAG.getTargetConstantPool(BA, PtrVT, 4); |
| 2041 | } else { |
| 2042 | unsigned PCAdj = Subtarget->isThumb() ? 4 : 8; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2043 | ARMPCLabelIndex = AFI->createPICLabelUId(); |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2044 | ARMConstantPoolValue *CPV = |
| 2045 | ARMConstantPoolConstant::Create(BA, ARMPCLabelIndex, |
| 2046 | ARMCP::CPBlockAddress, PCAdj); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2047 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
| 2048 | } |
| 2049 | CPAddr = DAG.getNode(ARMISD::Wrapper, DL, PtrVT, CPAddr); |
| 2050 | SDValue Result = DAG.getLoad(PtrVT, DL, DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2051 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2052 | false, false, false, 0); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2053 | if (RelocM == Reloc::Static) |
| 2054 | return Result; |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2055 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2056 | return DAG.getNode(ARMISD::PIC_ADD, DL, PtrVT, Result, PICLabel); |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 2057 | } |
| 2058 | |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2059 | // Lower ISD::GlobalTLSAddress using the "general dynamic" model |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2060 | SDValue |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2061 | ARMTargetLowering::LowerToTLSGeneralDynamicModel(GlobalAddressSDNode *GA, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2062 | SelectionDAG &DAG) const { |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2063 | DebugLoc dl = GA->getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2064 | EVT PtrVT = getPointerTy(); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2065 | unsigned char PCAdj = Subtarget->isThumb() ? 4 : 8; |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2066 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2067 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2068 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2069 | ARMConstantPoolValue *CPV = |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2070 | ARMConstantPoolConstant::Create(GA->getGlobal(), ARMPCLabelIndex, |
| 2071 | ARMCP::CPValue, PCAdj, ARMCP::TLSGD, true); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2072 | SDValue Argument = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2073 | Argument = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Argument); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2074 | Argument = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Argument, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2075 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2076 | false, false, false, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2077 | SDValue Chain = Argument.getValue(1); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2078 | |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2079 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2080 | Argument = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Argument, PICLabel); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2081 | |
| 2082 | // call __tls_get_addr. |
| 2083 | ArgListTy Args; |
| 2084 | ArgListEntry Entry; |
| 2085 | Entry.Node = Argument; |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 2086 | Entry.Ty = (Type *) Type::getInt32Ty(*DAG.getContext()); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2087 | Args.push_back(Entry); |
Dale Johannesen | 7d2ad62 | 2009-01-30 23:10:59 +0000 | [diff] [blame] | 2088 | // FIXME: is there useful debug info available here? |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2089 | std::pair<SDValue, SDValue> CallResult = |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 2090 | LowerCallTo(Chain, (Type *) Type::getInt32Ty(*DAG.getContext()), |
Evan Cheng | 59bc060 | 2009-08-14 19:11:20 +0000 | [diff] [blame] | 2091 | false, false, false, false, |
Evan Cheng | 4bfcd4a | 2012-02-28 18:51:51 +0000 | [diff] [blame] | 2092 | 0, CallingConv::C, /*isTailCall=*/false, |
| 2093 | /*doesNotRet=*/false, /*isReturnValueUsed=*/true, |
Bill Wendling | 46ada19 | 2010-03-02 01:55:18 +0000 | [diff] [blame] | 2094 | DAG.getExternalSymbol("__tls_get_addr", PtrVT), Args, DAG, dl); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2095 | return CallResult.first; |
| 2096 | } |
| 2097 | |
| 2098 | // Lower ISD::GlobalTLSAddress using the "initial exec" or |
| 2099 | // "local exec" model. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2100 | SDValue |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2101 | ARMTargetLowering::LowerToTLSExecModels(GlobalAddressSDNode *GA, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2102 | SelectionDAG &DAG) const { |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2103 | const GlobalValue *GV = GA->getGlobal(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2104 | DebugLoc dl = GA->getDebugLoc(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2105 | SDValue Offset; |
| 2106 | SDValue Chain = DAG.getEntryNode(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2107 | EVT PtrVT = getPointerTy(); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2108 | // Get the Thread Pointer |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2109 | SDValue ThreadPointer = DAG.getNode(ARMISD::THREAD_POINTER, dl, PtrVT); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2110 | |
Chris Lattner | 4fb63d0 | 2009-07-15 04:12:33 +0000 | [diff] [blame] | 2111 | if (GV->isDeclaration()) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2112 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2113 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2114 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2115 | // Initial exec model. |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2116 | unsigned char PCAdj = Subtarget->isThumb() ? 4 : 8; |
| 2117 | ARMConstantPoolValue *CPV = |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2118 | ARMConstantPoolConstant::Create(GA->getGlobal(), ARMPCLabelIndex, |
| 2119 | ARMCP::CPValue, PCAdj, ARMCP::GOTTPOFF, |
| 2120 | true); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2121 | Offset = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2122 | Offset = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Offset); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2123 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2124 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2125 | false, false, false, 0); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2126 | Chain = Offset.getValue(1); |
| 2127 | |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2128 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2129 | Offset = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Offset, PICLabel); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2130 | |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2131 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2132 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2133 | false, false, false, 0); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2134 | } else { |
| 2135 | // local exec model |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2136 | ARMConstantPoolValue *CPV = |
| 2137 | ARMConstantPoolConstant::Create(GV, ARMCP::TPOFF); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2138 | Offset = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2139 | Offset = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Offset); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2140 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2141 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2142 | false, false, false, 0); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2143 | } |
| 2144 | |
| 2145 | // The address of the thread local variable is the add of the thread |
| 2146 | // pointer with the offset of the variable. |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2147 | return DAG.getNode(ISD::ADD, dl, PtrVT, ThreadPointer, Offset); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2148 | } |
| 2149 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2150 | SDValue |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2151 | ARMTargetLowering::LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const { |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2152 | // TODO: implement the "local dynamic" model |
| 2153 | assert(Subtarget->isTargetELF() && |
| 2154 | "TLS not implemented for non-ELF targets"); |
| 2155 | GlobalAddressSDNode *GA = cast<GlobalAddressSDNode>(Op); |
| 2156 | // If the relocation model is PIC, use the "General Dynamic" TLS Model, |
| 2157 | // otherwise use the "Local Exec" TLS Model |
| 2158 | if (getTargetMachine().getRelocationModel() == Reloc::PIC_) |
| 2159 | return LowerToTLSGeneralDynamicModel(GA, DAG); |
| 2160 | else |
| 2161 | return LowerToTLSExecModels(GA, DAG); |
| 2162 | } |
| 2163 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2164 | SDValue ARMTargetLowering::LowerGlobalAddressELF(SDValue Op, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2165 | SelectionDAG &DAG) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2166 | EVT PtrVT = getPointerTy(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2167 | DebugLoc dl = Op.getDebugLoc(); |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2168 | const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2169 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| 2170 | if (RelocM == Reloc::PIC_) { |
Rafael Espindola | bb46f52 | 2009-01-15 20:18:42 +0000 | [diff] [blame] | 2171 | bool UseGOTOFF = GV->hasLocalLinkage() || GV->hasHiddenVisibility(); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2172 | ARMConstantPoolValue *CPV = |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2173 | ARMConstantPoolConstant::Create(GV, |
| 2174 | UseGOTOFF ? ARMCP::GOTOFF : ARMCP::GOT); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2175 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2176 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2177 | SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 2178 | CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2179 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2180 | false, false, false, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2181 | SDValue Chain = Result.getValue(1); |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 2182 | SDValue GOT = DAG.getGLOBAL_OFFSET_TABLE(PtrVT); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2183 | Result = DAG.getNode(ISD::ADD, dl, PtrVT, Result, GOT); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2184 | if (!UseGOTOFF) |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 2185 | Result = DAG.getLoad(PtrVT, dl, Chain, Result, |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2186 | MachinePointerInfo::getGOT(), |
| 2187 | false, false, false, 0); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2188 | return Result; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2189 | } |
| 2190 | |
| 2191 | // If we have T2 ops, we can materialize the address directly via movt/movw |
James Molloy | 015cca6 | 2011-10-26 08:53:19 +0000 | [diff] [blame] | 2192 | // pair. This is always cheaper. |
| 2193 | if (Subtarget->useMovt()) { |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2194 | ++NumMovwMovt; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2195 | // FIXME: Once remat is capable of dealing with instructions with register |
| 2196 | // operands, expand this into two nodes. |
| 2197 | return DAG.getNode(ARMISD::Wrapper, dl, PtrVT, |
| 2198 | DAG.getTargetGlobalAddress(GV, dl, PtrVT)); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2199 | } else { |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2200 | SDValue CPAddr = DAG.getTargetConstantPool(GV, PtrVT, 4); |
| 2201 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| 2202 | return DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
| 2203 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2204 | false, false, false, 0); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2205 | } |
| 2206 | } |
| 2207 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2208 | SDValue ARMTargetLowering::LowerGlobalAddressDarwin(SDValue Op, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2209 | SelectionDAG &DAG) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2210 | EVT PtrVT = getPointerTy(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2211 | DebugLoc dl = Op.getDebugLoc(); |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2212 | const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2213 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2214 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2215 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2216 | |
Jakob Stoklund Olesen | 8f37a24 | 2012-01-07 20:49:15 +0000 | [diff] [blame] | 2217 | // FIXME: Enable this for static codegen when tool issues are fixed. Also |
| 2218 | // update ARMFastISel::ARMMaterializeGV. |
Evan Cheng | f31151f | 2011-10-26 01:17:44 +0000 | [diff] [blame] | 2219 | if (Subtarget->useMovt() && RelocM != Reloc::Static) { |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2220 | ++NumMovwMovt; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2221 | // FIXME: Once remat is capable of dealing with instructions with register |
| 2222 | // operands, expand this into two nodes. |
Evan Cheng | 53519f0 | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 2223 | if (RelocM == Reloc::Static) |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2224 | return DAG.getNode(ARMISD::Wrapper, dl, PtrVT, |
| 2225 | DAG.getTargetGlobalAddress(GV, dl, PtrVT)); |
| 2226 | |
Evan Cheng | 53519f0 | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 2227 | unsigned Wrapper = (RelocM == Reloc::PIC_) |
| 2228 | ? ARMISD::WrapperPIC : ARMISD::WrapperDYN; |
| 2229 | SDValue Result = DAG.getNode(Wrapper, dl, PtrVT, |
Evan Cheng | 9fe2009 | 2011-01-20 08:34:58 +0000 | [diff] [blame] | 2230 | DAG.getTargetGlobalAddress(GV, dl, PtrVT)); |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2231 | if (Subtarget->GVIsIndirectSymbol(GV, RelocM)) |
| 2232 | Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Result, |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2233 | MachinePointerInfo::getGOT(), |
| 2234 | false, false, false, 0); |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2235 | return Result; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2236 | } |
| 2237 | |
| 2238 | unsigned ARMPCLabelIndex = 0; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2239 | SDValue CPAddr; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2240 | if (RelocM == Reloc::Static) { |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2241 | CPAddr = DAG.getTargetConstantPool(GV, PtrVT, 4); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2242 | } else { |
| 2243 | ARMPCLabelIndex = AFI->createPICLabelUId(); |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 2244 | unsigned PCAdj = (RelocM != Reloc::PIC_) ? 0 : (Subtarget->isThumb()?4:8); |
| 2245 | ARMConstantPoolValue *CPV = |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2246 | ARMConstantPoolConstant::Create(GV, ARMPCLabelIndex, ARMCP::CPValue, |
| 2247 | PCAdj); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2248 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2249 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2250 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2251 | |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2252 | SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2253 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2254 | false, false, false, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2255 | SDValue Chain = Result.getValue(1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2256 | |
| 2257 | if (RelocM == Reloc::PIC_) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2258 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2259 | Result = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2260 | } |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 2261 | |
Evan Cheng | 63476a8 | 2009-09-03 07:04:02 +0000 | [diff] [blame] | 2262 | if (Subtarget->GVIsIndirectSymbol(GV, RelocM)) |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2263 | Result = DAG.getLoad(PtrVT, dl, Chain, Result, MachinePointerInfo::getGOT(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2264 | false, false, false, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2265 | |
| 2266 | return Result; |
| 2267 | } |
| 2268 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2269 | SDValue ARMTargetLowering::LowerGLOBAL_OFFSET_TABLE(SDValue Op, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2270 | SelectionDAG &DAG) const { |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2271 | assert(Subtarget->isTargetELF() && |
| 2272 | "GLOBAL OFFSET TABLE not implemented for non-ELF targets"); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2273 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2274 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2275 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2276 | EVT PtrVT = getPointerTy(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2277 | DebugLoc dl = Op.getDebugLoc(); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2278 | unsigned PCAdj = Subtarget->isThumb() ? 4 : 8; |
Bill Wendling | fe31e67 | 2011-10-01 08:58:29 +0000 | [diff] [blame] | 2279 | ARMConstantPoolValue *CPV = |
| 2280 | ARMConstantPoolSymbol::Create(*DAG.getContext(), "_GLOBAL_OFFSET_TABLE_", |
| 2281 | ARMPCLabelIndex, PCAdj); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2282 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2283 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 2284 | SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2285 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2286 | false, false, false, 0); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2287 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2288 | return DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2289 | } |
| 2290 | |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 2291 | SDValue |
Jim Grosbach | 23ff7cf | 2010-05-26 20:22:18 +0000 | [diff] [blame] | 2292 | ARMTargetLowering::LowerEH_SJLJ_SETJMP(SDValue Op, SelectionDAG &DAG) const { |
| 2293 | DebugLoc dl = Op.getDebugLoc(); |
Jim Grosbach | 0798edd | 2010-05-27 23:49:24 +0000 | [diff] [blame] | 2294 | SDValue Val = DAG.getConstant(0, MVT::i32); |
Bill Wendling | ce370cf | 2011-10-07 21:25:38 +0000 | [diff] [blame] | 2295 | return DAG.getNode(ARMISD::EH_SJLJ_SETJMP, dl, |
| 2296 | DAG.getVTList(MVT::i32, MVT::Other), Op.getOperand(0), |
Jim Grosbach | 23ff7cf | 2010-05-26 20:22:18 +0000 | [diff] [blame] | 2297 | Op.getOperand(1), Val); |
| 2298 | } |
| 2299 | |
| 2300 | SDValue |
Jim Grosbach | 5eb1951 | 2010-05-22 01:06:18 +0000 | [diff] [blame] | 2301 | ARMTargetLowering::LowerEH_SJLJ_LONGJMP(SDValue Op, SelectionDAG &DAG) const { |
| 2302 | DebugLoc dl = Op.getDebugLoc(); |
| 2303 | return DAG.getNode(ARMISD::EH_SJLJ_LONGJMP, dl, MVT::Other, Op.getOperand(0), |
| 2304 | Op.getOperand(1), DAG.getConstant(0, MVT::i32)); |
| 2305 | } |
| 2306 | |
| 2307 | SDValue |
Jim Grosbach | a87ded2 | 2010-02-08 23:22:00 +0000 | [diff] [blame] | 2308 | ARMTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG, |
Jim Grosbach | 7616b64 | 2010-06-16 23:45:49 +0000 | [diff] [blame] | 2309 | const ARMSubtarget *Subtarget) const { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2310 | unsigned IntNo = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 2311 | DebugLoc dl = Op.getDebugLoc(); |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 2312 | switch (IntNo) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2313 | default: return SDValue(); // Don't custom lower most intrinsics. |
Bob Wilson | 916afdb | 2009-08-04 00:25:01 +0000 | [diff] [blame] | 2314 | case Intrinsic::arm_thread_pointer: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2315 | EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
Bob Wilson | 916afdb | 2009-08-04 00:25:01 +0000 | [diff] [blame] | 2316 | return DAG.getNode(ARMISD::THREAD_POINTER, dl, PtrVT); |
| 2317 | } |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2318 | case Intrinsic::eh_sjlj_lsda: { |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2319 | MachineFunction &MF = DAG.getMachineFunction(); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2320 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2321 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2322 | EVT PtrVT = getPointerTy(); |
| 2323 | DebugLoc dl = Op.getDebugLoc(); |
| 2324 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| 2325 | SDValue CPAddr; |
| 2326 | unsigned PCAdj = (RelocM != Reloc::PIC_) |
| 2327 | ? 0 : (Subtarget->isThumb() ? 4 : 8); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2328 | ARMConstantPoolValue *CPV = |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2329 | ARMConstantPoolConstant::Create(MF.getFunction(), ARMPCLabelIndex, |
| 2330 | ARMCP::CPLSDA, PCAdj); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2331 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2332 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2333 | SDValue Result = |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2334 | DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2335 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2336 | false, false, false, 0); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2337 | |
| 2338 | if (RelocM == Reloc::PIC_) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2339 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2340 | Result = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
| 2341 | } |
| 2342 | return Result; |
| 2343 | } |
Evan Cheng | 92e3916 | 2011-03-29 23:06:19 +0000 | [diff] [blame] | 2344 | case Intrinsic::arm_neon_vmulls: |
| 2345 | case Intrinsic::arm_neon_vmullu: { |
| 2346 | unsigned NewOpc = (IntNo == Intrinsic::arm_neon_vmulls) |
| 2347 | ? ARMISD::VMULLs : ARMISD::VMULLu; |
| 2348 | return DAG.getNode(NewOpc, Op.getDebugLoc(), Op.getValueType(), |
| 2349 | Op.getOperand(1), Op.getOperand(2)); |
| 2350 | } |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 2351 | } |
| 2352 | } |
| 2353 | |
Jim Grosbach | 7c03dbd | 2009-12-14 21:24:16 +0000 | [diff] [blame] | 2354 | static SDValue LowerMEMBARRIER(SDValue Op, SelectionDAG &DAG, |
Jim Grosbach | 7616b64 | 2010-06-16 23:45:49 +0000 | [diff] [blame] | 2355 | const ARMSubtarget *Subtarget) { |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 2356 | DebugLoc dl = Op.getDebugLoc(); |
Bob Wilson | f74a429 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 2357 | if (!Subtarget->hasDataBarrier()) { |
| 2358 | // Some ARMv6 cpus can support data barriers with an mcr instruction. |
| 2359 | // Thumb1 and pre-v6 ARM mode use a libcall instead and should never get |
| 2360 | // here. |
Bob Wilson | 54f9256 | 2010-11-09 22:50:44 +0000 | [diff] [blame] | 2361 | assert(Subtarget->hasV6Ops() && !Subtarget->isThumb() && |
Evan Cheng | 11db068 | 2010-08-11 06:22:01 +0000 | [diff] [blame] | 2362 | "Unexpected ISD::MEMBARRIER encountered. Should be libcall!"); |
Bob Wilson | f74a429 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 2363 | return DAG.getNode(ARMISD::MEMBARRIER_MCR, dl, MVT::Other, Op.getOperand(0), |
Jim Grosbach | c73993b | 2010-06-17 01:37:00 +0000 | [diff] [blame] | 2364 | DAG.getConstant(0, MVT::i32)); |
Evan Cheng | 11db068 | 2010-08-11 06:22:01 +0000 | [diff] [blame] | 2365 | } |
Bob Wilson | f74a429 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 2366 | |
| 2367 | SDValue Op5 = Op.getOperand(5); |
| 2368 | bool isDeviceBarrier = cast<ConstantSDNode>(Op5)->getZExtValue() != 0; |
| 2369 | unsigned isLL = cast<ConstantSDNode>(Op.getOperand(1))->getZExtValue(); |
| 2370 | unsigned isLS = cast<ConstantSDNode>(Op.getOperand(2))->getZExtValue(); |
| 2371 | bool isOnlyStoreBarrier = (isLL == 0 && isLS == 0); |
| 2372 | |
| 2373 | ARM_MB::MemBOpt DMBOpt; |
| 2374 | if (isDeviceBarrier) |
| 2375 | DMBOpt = isOnlyStoreBarrier ? ARM_MB::ST : ARM_MB::SY; |
| 2376 | else |
| 2377 | DMBOpt = isOnlyStoreBarrier ? ARM_MB::ISHST : ARM_MB::ISH; |
| 2378 | return DAG.getNode(ARMISD::MEMBARRIER, dl, MVT::Other, Op.getOperand(0), |
| 2379 | DAG.getConstant(DMBOpt, MVT::i32)); |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 2380 | } |
| 2381 | |
Eli Friedman | 26689ac | 2011-08-03 21:06:02 +0000 | [diff] [blame] | 2382 | |
| 2383 | static SDValue LowerATOMIC_FENCE(SDValue Op, SelectionDAG &DAG, |
| 2384 | const ARMSubtarget *Subtarget) { |
| 2385 | // FIXME: handle "fence singlethread" more efficiently. |
| 2386 | DebugLoc dl = Op.getDebugLoc(); |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 2387 | if (!Subtarget->hasDataBarrier()) { |
| 2388 | // Some ARMv6 cpus can support data barriers with an mcr instruction. |
| 2389 | // Thumb1 and pre-v6 ARM mode use a libcall instead and should never get |
| 2390 | // here. |
| 2391 | assert(Subtarget->hasV6Ops() && !Subtarget->isThumb() && |
| 2392 | "Unexpected ISD::MEMBARRIER encountered. Should be libcall!"); |
Eli Friedman | 26689ac | 2011-08-03 21:06:02 +0000 | [diff] [blame] | 2393 | return DAG.getNode(ARMISD::MEMBARRIER_MCR, dl, MVT::Other, Op.getOperand(0), |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 2394 | DAG.getConstant(0, MVT::i32)); |
| 2395 | } |
| 2396 | |
Eli Friedman | 26689ac | 2011-08-03 21:06:02 +0000 | [diff] [blame] | 2397 | return DAG.getNode(ARMISD::MEMBARRIER, dl, MVT::Other, Op.getOperand(0), |
Eli Friedman | 989f61e | 2011-08-02 22:44:16 +0000 | [diff] [blame] | 2398 | DAG.getConstant(ARM_MB::ISH, MVT::i32)); |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 2399 | } |
| 2400 | |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2401 | static SDValue LowerPREFETCH(SDValue Op, SelectionDAG &DAG, |
| 2402 | const ARMSubtarget *Subtarget) { |
| 2403 | // ARM pre v5TE and Thumb1 does not have preload instructions. |
| 2404 | if (!(Subtarget->isThumb2() || |
| 2405 | (!Subtarget->isThumb1Only() && Subtarget->hasV5TEOps()))) |
| 2406 | // Just preserve the chain. |
| 2407 | return Op.getOperand(0); |
| 2408 | |
| 2409 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 2410 | unsigned isRead = ~cast<ConstantSDNode>(Op.getOperand(2))->getZExtValue() & 1; |
| 2411 | if (!isRead && |
| 2412 | (!Subtarget->hasV7Ops() || !Subtarget->hasMPExtension())) |
| 2413 | // ARMv7 with MP extension has PLDW. |
| 2414 | return Op.getOperand(0); |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2415 | |
Bruno Cardoso Lopes | 9a76733 | 2011-06-14 04:58:37 +0000 | [diff] [blame] | 2416 | unsigned isData = cast<ConstantSDNode>(Op.getOperand(4))->getZExtValue(); |
| 2417 | if (Subtarget->isThumb()) { |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2418 | // Invert the bits. |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 2419 | isRead = ~isRead & 1; |
Bruno Cardoso Lopes | 9a76733 | 2011-06-14 04:58:37 +0000 | [diff] [blame] | 2420 | isData = ~isData & 1; |
| 2421 | } |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2422 | |
| 2423 | return DAG.getNode(ARMISD::PRELOAD, dl, MVT::Other, Op.getOperand(0), |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 2424 | Op.getOperand(1), DAG.getConstant(isRead, MVT::i32), |
| 2425 | DAG.getConstant(isData, MVT::i32)); |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2426 | } |
| 2427 | |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 2428 | static SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) { |
| 2429 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2430 | ARMFunctionInfo *FuncInfo = MF.getInfo<ARMFunctionInfo>(); |
| 2431 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2432 | // vastart just stores the address of the VarArgsFrameIndex slot into the |
| 2433 | // memory location argument. |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2434 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2435 | EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 2436 | SDValue FR = DAG.getFrameIndex(FuncInfo->getVarArgsFrameIndex(), PtrVT); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 2437 | const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue(); |
Chris Lattner | fc448ff | 2010-09-21 18:51:21 +0000 | [diff] [blame] | 2438 | return DAG.getStore(Op.getOperand(0), dl, FR, Op.getOperand(1), |
| 2439 | MachinePointerInfo(SV), false, false, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2440 | } |
| 2441 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2442 | SDValue |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2443 | ARMTargetLowering::GetF64FormalArgument(CCValAssign &VA, CCValAssign &NextVA, |
| 2444 | SDValue &Root, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2445 | DebugLoc dl) const { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2446 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2447 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2448 | |
Craig Topper | 44d2382 | 2012-02-22 05:59:10 +0000 | [diff] [blame] | 2449 | const TargetRegisterClass *RC; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 2450 | if (AFI->isThumb1OnlyFunction()) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2451 | RC = ARM::tGPRRegisterClass; |
| 2452 | else |
| 2453 | RC = ARM::GPRRegisterClass; |
| 2454 | |
| 2455 | // Transform the arguments stored in physical registers into virtual ones. |
Devang Patel | 68e6bee | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 2456 | unsigned Reg = MF.addLiveIn(VA.getLocReg(), RC); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2457 | SDValue ArgValue = DAG.getCopyFromReg(Root, dl, Reg, MVT::i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2458 | |
| 2459 | SDValue ArgValue2; |
| 2460 | if (NextVA.isMemLoc()) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2461 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
Evan Cheng | ed2ae13 | 2010-07-03 00:40:23 +0000 | [diff] [blame] | 2462 | int FI = MFI->CreateFixedObject(4, NextVA.getLocMemOffset(), true); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2463 | |
| 2464 | // Create load node to retrieve arguments from the stack. |
| 2465 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2466 | ArgValue2 = DAG.getLoad(MVT::i32, dl, Root, FIN, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2467 | MachinePointerInfo::getFixedStack(FI), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2468 | false, false, false, 0); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2469 | } else { |
Devang Patel | 68e6bee | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 2470 | Reg = MF.addLiveIn(NextVA.getLocReg(), RC); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2471 | ArgValue2 = DAG.getCopyFromReg(Root, dl, Reg, MVT::i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2472 | } |
| 2473 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 2474 | return DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, ArgValue, ArgValue2); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2475 | } |
| 2476 | |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2477 | void |
| 2478 | ARMTargetLowering::computeRegArea(CCState &CCInfo, MachineFunction &MF, |
| 2479 | unsigned &VARegSize, unsigned &VARegSaveSize) |
| 2480 | const { |
| 2481 | unsigned NumGPRs; |
| 2482 | if (CCInfo.isFirstByValRegValid()) |
| 2483 | NumGPRs = ARM::R4 - CCInfo.getFirstByValReg(); |
| 2484 | else { |
| 2485 | unsigned int firstUnalloced; |
| 2486 | firstUnalloced = CCInfo.getFirstUnallocated(GPRArgRegs, |
| 2487 | sizeof(GPRArgRegs) / |
| 2488 | sizeof(GPRArgRegs[0])); |
| 2489 | NumGPRs = (firstUnalloced <= 3) ? (4 - firstUnalloced) : 0; |
| 2490 | } |
| 2491 | |
| 2492 | unsigned Align = MF.getTarget().getFrameLowering()->getStackAlignment(); |
| 2493 | VARegSize = NumGPRs * 4; |
| 2494 | VARegSaveSize = (VARegSize + Align - 1) & ~(Align - 1); |
| 2495 | } |
| 2496 | |
| 2497 | // The remaining GPRs hold either the beginning of variable-argument |
| 2498 | // data, or the beginning of an aggregate passed by value (usuall |
| 2499 | // byval). Either way, we allocate stack slots adjacent to the data |
| 2500 | // provided by our caller, and store the unallocated registers there. |
| 2501 | // If this is a variadic function, the va_list pointer will begin with |
| 2502 | // these values; otherwise, this reassembles a (byval) structure that |
| 2503 | // was split between registers and memory. |
| 2504 | void |
| 2505 | ARMTargetLowering::VarArgStyleRegisters(CCState &CCInfo, SelectionDAG &DAG, |
| 2506 | DebugLoc dl, SDValue &Chain, |
| 2507 | unsigned ArgOffset) const { |
| 2508 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2509 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 2510 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2511 | unsigned firstRegToSaveIndex; |
| 2512 | if (CCInfo.isFirstByValRegValid()) |
| 2513 | firstRegToSaveIndex = CCInfo.getFirstByValReg() - ARM::R0; |
| 2514 | else { |
| 2515 | firstRegToSaveIndex = CCInfo.getFirstUnallocated |
| 2516 | (GPRArgRegs, sizeof(GPRArgRegs) / sizeof(GPRArgRegs[0])); |
| 2517 | } |
| 2518 | |
| 2519 | unsigned VARegSize, VARegSaveSize; |
| 2520 | computeRegArea(CCInfo, MF, VARegSize, VARegSaveSize); |
| 2521 | if (VARegSaveSize) { |
| 2522 | // If this function is vararg, store any remaining integer argument regs |
| 2523 | // to their spots on the stack so that they may be loaded by deferencing |
| 2524 | // the result of va_next. |
| 2525 | AFI->setVarArgsRegSaveSize(VARegSaveSize); |
Eric Christopher | 5ac179c | 2011-04-29 23:12:01 +0000 | [diff] [blame] | 2526 | AFI->setVarArgsFrameIndex(MFI->CreateFixedObject(VARegSaveSize, |
| 2527 | ArgOffset + VARegSaveSize |
| 2528 | - VARegSize, |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2529 | false)); |
| 2530 | SDValue FIN = DAG.getFrameIndex(AFI->getVarArgsFrameIndex(), |
| 2531 | getPointerTy()); |
| 2532 | |
| 2533 | SmallVector<SDValue, 4> MemOps; |
| 2534 | for (; firstRegToSaveIndex < 4; ++firstRegToSaveIndex) { |
Craig Topper | 44d2382 | 2012-02-22 05:59:10 +0000 | [diff] [blame] | 2535 | const TargetRegisterClass *RC; |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2536 | if (AFI->isThumb1OnlyFunction()) |
| 2537 | RC = ARM::tGPRRegisterClass; |
| 2538 | else |
| 2539 | RC = ARM::GPRRegisterClass; |
| 2540 | |
| 2541 | unsigned VReg = MF.addLiveIn(GPRArgRegs[firstRegToSaveIndex], RC); |
| 2542 | SDValue Val = DAG.getCopyFromReg(Chain, dl, VReg, MVT::i32); |
| 2543 | SDValue Store = |
| 2544 | DAG.getStore(Val.getValue(1), dl, Val, FIN, |
Eric Christopher | 5ac179c | 2011-04-29 23:12:01 +0000 | [diff] [blame] | 2545 | MachinePointerInfo::getFixedStack(AFI->getVarArgsFrameIndex()), |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2546 | false, false, 0); |
| 2547 | MemOps.push_back(Store); |
| 2548 | FIN = DAG.getNode(ISD::ADD, dl, getPointerTy(), FIN, |
| 2549 | DAG.getConstant(4, getPointerTy())); |
| 2550 | } |
| 2551 | if (!MemOps.empty()) |
| 2552 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, |
| 2553 | &MemOps[0], MemOps.size()); |
| 2554 | } else |
| 2555 | // This will point to the next argument passed via stack. |
| 2556 | AFI->setVarArgsFrameIndex(MFI->CreateFixedObject(4, ArgOffset, true)); |
| 2557 | } |
| 2558 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2559 | SDValue |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2560 | ARMTargetLowering::LowerFormalArguments(SDValue Chain, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 2561 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2562 | const SmallVectorImpl<ISD::InputArg> |
| 2563 | &Ins, |
| 2564 | DebugLoc dl, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2565 | SmallVectorImpl<SDValue> &InVals) |
| 2566 | const { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2567 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2568 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 2569 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2570 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2571 | |
| 2572 | // Assign locations to all of the incoming arguments. |
| 2573 | SmallVector<CCValAssign, 16> ArgLocs; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 2574 | ARMCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), |
| 2575 | getTargetMachine(), ArgLocs, *DAG.getContext(), Prologue); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2576 | CCInfo.AnalyzeFormalArguments(Ins, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 2577 | CCAssignFnForNode(CallConv, /* Return*/ false, |
| 2578 | isVarArg)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2579 | |
| 2580 | SmallVector<SDValue, 16> ArgValues; |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2581 | int lastInsIndex = -1; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2582 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2583 | SDValue ArgValue; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2584 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| 2585 | CCValAssign &VA = ArgLocs[i]; |
| 2586 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 2587 | // Arguments stored in registers. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2588 | if (VA.isRegLoc()) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2589 | EVT RegVT = VA.getLocVT(); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2590 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2591 | if (VA.needsCustom()) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2592 | // f64 and vector types are split up into multiple registers or |
| 2593 | // combinations of registers and stack slots. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2594 | if (VA.getLocVT() == MVT::v2f64) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2595 | SDValue ArgValue1 = GetF64FormalArgument(VA, ArgLocs[++i], |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2596 | Chain, DAG, dl); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2597 | VA = ArgLocs[++i]; // skip ahead to next loc |
Bob Wilson | 6a234f0 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 2598 | SDValue ArgValue2; |
| 2599 | if (VA.isMemLoc()) { |
Evan Cheng | ed2ae13 | 2010-07-03 00:40:23 +0000 | [diff] [blame] | 2600 | int FI = MFI->CreateFixedObject(8, VA.getLocMemOffset(), true); |
Bob Wilson | 6a234f0 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 2601 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
| 2602 | ArgValue2 = DAG.getLoad(MVT::f64, dl, Chain, FIN, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2603 | MachinePointerInfo::getFixedStack(FI), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2604 | false, false, false, 0); |
Bob Wilson | 6a234f0 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 2605 | } else { |
| 2606 | ArgValue2 = GetF64FormalArgument(VA, ArgLocs[++i], |
| 2607 | Chain, DAG, dl); |
| 2608 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2609 | ArgValue = DAG.getNode(ISD::UNDEF, dl, MVT::v2f64); |
| 2610 | ArgValue = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2611 | ArgValue, ArgValue1, DAG.getIntPtrConstant(0)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2612 | ArgValue = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2613 | ArgValue, ArgValue2, DAG.getIntPtrConstant(1)); |
| 2614 | } else |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2615 | ArgValue = GetF64FormalArgument(VA, ArgLocs[++i], Chain, DAG, dl); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2616 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2617 | } else { |
Craig Topper | 44d2382 | 2012-02-22 05:59:10 +0000 | [diff] [blame] | 2618 | const TargetRegisterClass *RC; |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 2619 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2620 | if (RegVT == MVT::f32) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2621 | RC = ARM::SPRRegisterClass; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2622 | else if (RegVT == MVT::f64) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2623 | RC = ARM::DPRRegisterClass; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2624 | else if (RegVT == MVT::v2f64) |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 2625 | RC = ARM::QPRRegisterClass; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2626 | else if (RegVT == MVT::i32) |
Anton Korobeynikov | 058c251 | 2009-08-05 20:15:19 +0000 | [diff] [blame] | 2627 | RC = (AFI->isThumb1OnlyFunction() ? |
| 2628 | ARM::tGPRRegisterClass : ARM::GPRRegisterClass); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2629 | else |
Anton Korobeynikov | 058c251 | 2009-08-05 20:15:19 +0000 | [diff] [blame] | 2630 | llvm_unreachable("RegVT not supported by FORMAL_ARGUMENTS Lowering"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2631 | |
| 2632 | // Transform the arguments in physical registers into virtual ones. |
Devang Patel | 68e6bee | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 2633 | unsigned Reg = MF.addLiveIn(VA.getLocReg(), RC); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2634 | ArgValue = DAG.getCopyFromReg(Chain, dl, Reg, RegVT); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2635 | } |
| 2636 | |
| 2637 | // If this is an 8 or 16-bit value, it is really passed promoted |
| 2638 | // to 32 bits. Insert an assert[sz]ext to capture this, then |
| 2639 | // truncate to the right size. |
| 2640 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 2641 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2642 | case CCValAssign::Full: break; |
| 2643 | case CCValAssign::BCvt: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2644 | ArgValue = DAG.getNode(ISD::BITCAST, dl, VA.getValVT(), ArgValue); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2645 | break; |
| 2646 | case CCValAssign::SExt: |
| 2647 | ArgValue = DAG.getNode(ISD::AssertSext, dl, RegVT, ArgValue, |
| 2648 | DAG.getValueType(VA.getValVT())); |
| 2649 | ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue); |
| 2650 | break; |
| 2651 | case CCValAssign::ZExt: |
| 2652 | ArgValue = DAG.getNode(ISD::AssertZext, dl, RegVT, ArgValue, |
| 2653 | DAG.getValueType(VA.getValVT())); |
| 2654 | ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue); |
| 2655 | break; |
| 2656 | } |
| 2657 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2658 | InVals.push_back(ArgValue); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2659 | |
| 2660 | } else { // VA.isRegLoc() |
| 2661 | |
| 2662 | // sanity check |
| 2663 | assert(VA.isMemLoc()); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2664 | assert(VA.getValVT() != MVT::i64 && "i64 should already be lowered"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2665 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2666 | int index = ArgLocs[i].getValNo(); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 2667 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2668 | // Some Ins[] entries become multiple ArgLoc[] entries. |
| 2669 | // Process them only once. |
| 2670 | if (index != lastInsIndex) |
| 2671 | { |
| 2672 | ISD::ArgFlagsTy Flags = Ins[index].Flags; |
Eric Christopher | 471e422 | 2011-06-08 23:55:35 +0000 | [diff] [blame] | 2673 | // FIXME: For now, all byval parameter objects are marked mutable. |
Eric Christopher | 5ac179c | 2011-04-29 23:12:01 +0000 | [diff] [blame] | 2674 | // This can be changed with more analysis. |
| 2675 | // In case of tail call optimization mark all arguments mutable. |
| 2676 | // Since they could be overwritten by lowering of arguments in case of |
| 2677 | // a tail call. |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2678 | if (Flags.isByVal()) { |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2679 | unsigned VARegSize, VARegSaveSize; |
| 2680 | computeRegArea(CCInfo, MF, VARegSize, VARegSaveSize); |
| 2681 | VarArgStyleRegisters(CCInfo, DAG, dl, Chain, 0); |
| 2682 | unsigned Bytes = Flags.getByValSize() - VARegSize; |
Evan Cheng | ee2e0e3 | 2011-03-30 23:44:13 +0000 | [diff] [blame] | 2683 | if (Bytes == 0) Bytes = 1; // Don't create zero-sized stack objects. |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2684 | int FI = MFI->CreateFixedObject(Bytes, |
| 2685 | VA.getLocMemOffset(), false); |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2686 | InVals.push_back(DAG.getFrameIndex(FI, getPointerTy())); |
| 2687 | } else { |
| 2688 | int FI = MFI->CreateFixedObject(VA.getLocVT().getSizeInBits()/8, |
| 2689 | VA.getLocMemOffset(), true); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2690 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2691 | // Create load nodes to retrieve arguments from the stack. |
| 2692 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
| 2693 | InVals.push_back(DAG.getLoad(VA.getValVT(), dl, Chain, FIN, |
| 2694 | MachinePointerInfo::getFixedStack(FI), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2695 | false, false, false, 0)); |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2696 | } |
| 2697 | lastInsIndex = index; |
| 2698 | } |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2699 | } |
| 2700 | } |
| 2701 | |
| 2702 | // varargs |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2703 | if (isVarArg) |
| 2704 | VarArgStyleRegisters(CCInfo, DAG, dl, Chain, CCInfo.getNextStackOffset()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2705 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2706 | return Chain; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2707 | } |
| 2708 | |
| 2709 | /// isFloatingPointZero - Return true if this is +0.0. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2710 | static bool isFloatingPointZero(SDValue Op) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2711 | if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(Op)) |
Dale Johannesen | eaf0894 | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 2712 | return CFP->getValueAPF().isPosZero(); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2713 | else if (ISD::isEXTLoad(Op.getNode()) || ISD::isNON_EXTLoad(Op.getNode())) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2714 | // Maybe this has already been legalized into the constant pool? |
| 2715 | if (Op.getOperand(1).getOpcode() == ARMISD::Wrapper) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2716 | SDValue WrapperOp = Op.getOperand(1).getOperand(0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2717 | if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(WrapperOp)) |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2718 | if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CP->getConstVal())) |
Dale Johannesen | eaf0894 | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 2719 | return CFP->getValueAPF().isPosZero(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2720 | } |
| 2721 | } |
| 2722 | return false; |
| 2723 | } |
| 2724 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2725 | /// Returns appropriate ARM CMP (cmp) and corresponding condition code for |
| 2726 | /// the given operands. |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 2727 | SDValue |
| 2728 | ARMTargetLowering::getARMCmp(SDValue LHS, SDValue RHS, ISD::CondCode CC, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2729 | SDValue &ARMcc, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2730 | DebugLoc dl) const { |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2731 | if (ConstantSDNode *RHSC = dyn_cast<ConstantSDNode>(RHS.getNode())) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2732 | unsigned C = RHSC->getZExtValue(); |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 2733 | if (!isLegalICmpImmediate(C)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2734 | // Constant does not fit, try adjusting it by one? |
| 2735 | switch (CC) { |
| 2736 | default: break; |
| 2737 | case ISD::SETLT: |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2738 | case ISD::SETGE: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 2739 | if (C != 0x80000000 && isLegalICmpImmediate(C-1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2740 | CC = (CC == ISD::SETLT) ? ISD::SETLE : ISD::SETGT; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2741 | RHS = DAG.getConstant(C-1, MVT::i32); |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2742 | } |
| 2743 | break; |
| 2744 | case ISD::SETULT: |
| 2745 | case ISD::SETUGE: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 2746 | if (C != 0 && isLegalICmpImmediate(C-1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2747 | CC = (CC == ISD::SETULT) ? ISD::SETULE : ISD::SETUGT; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2748 | RHS = DAG.getConstant(C-1, MVT::i32); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2749 | } |
| 2750 | break; |
| 2751 | case ISD::SETLE: |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2752 | case ISD::SETGT: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 2753 | if (C != 0x7fffffff && isLegalICmpImmediate(C+1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2754 | CC = (CC == ISD::SETLE) ? ISD::SETLT : ISD::SETGE; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2755 | RHS = DAG.getConstant(C+1, MVT::i32); |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2756 | } |
| 2757 | break; |
| 2758 | case ISD::SETULE: |
| 2759 | case ISD::SETUGT: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 2760 | if (C != 0xffffffff && isLegalICmpImmediate(C+1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2761 | CC = (CC == ISD::SETULE) ? ISD::SETULT : ISD::SETUGE; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2762 | RHS = DAG.getConstant(C+1, MVT::i32); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2763 | } |
| 2764 | break; |
| 2765 | } |
| 2766 | } |
| 2767 | } |
| 2768 | |
| 2769 | ARMCC::CondCodes CondCode = IntCCToARMCC(CC); |
Lauro Ramos Venancio | 9996663 | 2007-04-02 01:30:03 +0000 | [diff] [blame] | 2770 | ARMISD::NodeType CompareType; |
| 2771 | switch (CondCode) { |
| 2772 | default: |
| 2773 | CompareType = ARMISD::CMP; |
| 2774 | break; |
| 2775 | case ARMCC::EQ: |
| 2776 | case ARMCC::NE: |
David Goodwin | c0309b4 | 2009-06-29 15:33:01 +0000 | [diff] [blame] | 2777 | // Uses only Z Flag |
| 2778 | CompareType = ARMISD::CMPZ; |
Lauro Ramos Venancio | 9996663 | 2007-04-02 01:30:03 +0000 | [diff] [blame] | 2779 | break; |
| 2780 | } |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2781 | ARMcc = DAG.getConstant(CondCode, MVT::i32); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 2782 | return DAG.getNode(CompareType, dl, MVT::Glue, LHS, RHS); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2783 | } |
| 2784 | |
| 2785 | /// Returns a appropriate VFP CMP (fcmp{s|d}+fmstat) for the given operands. |
Evan Cheng | 515fe3a | 2010-07-08 02:08:50 +0000 | [diff] [blame] | 2786 | SDValue |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2787 | ARMTargetLowering::getVFPCmp(SDValue LHS, SDValue RHS, SelectionDAG &DAG, |
Evan Cheng | 515fe3a | 2010-07-08 02:08:50 +0000 | [diff] [blame] | 2788 | DebugLoc dl) const { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2789 | SDValue Cmp; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2790 | if (!isFloatingPointZero(RHS)) |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 2791 | Cmp = DAG.getNode(ARMISD::CMPFP, dl, MVT::Glue, LHS, RHS); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2792 | else |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 2793 | Cmp = DAG.getNode(ARMISD::CMPFPw0, dl, MVT::Glue, LHS); |
| 2794 | return DAG.getNode(ARMISD::FMSTAT, dl, MVT::Glue, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2795 | } |
| 2796 | |
Bob Wilson | 79f56c9 | 2011-03-08 01:17:20 +0000 | [diff] [blame] | 2797 | /// duplicateCmp - Glue values can have only one use, so this function |
| 2798 | /// duplicates a comparison node. |
| 2799 | SDValue |
| 2800 | ARMTargetLowering::duplicateCmp(SDValue Cmp, SelectionDAG &DAG) const { |
| 2801 | unsigned Opc = Cmp.getOpcode(); |
| 2802 | DebugLoc DL = Cmp.getDebugLoc(); |
| 2803 | if (Opc == ARMISD::CMP || Opc == ARMISD::CMPZ) |
| 2804 | return DAG.getNode(Opc, DL, MVT::Glue, Cmp.getOperand(0),Cmp.getOperand(1)); |
| 2805 | |
| 2806 | assert(Opc == ARMISD::FMSTAT && "unexpected comparison operation"); |
| 2807 | Cmp = Cmp.getOperand(0); |
| 2808 | Opc = Cmp.getOpcode(); |
| 2809 | if (Opc == ARMISD::CMPFP) |
| 2810 | Cmp = DAG.getNode(Opc, DL, MVT::Glue, Cmp.getOperand(0),Cmp.getOperand(1)); |
| 2811 | else { |
| 2812 | assert(Opc == ARMISD::CMPFPw0 && "unexpected operand of FMSTAT"); |
| 2813 | Cmp = DAG.getNode(Opc, DL, MVT::Glue, Cmp.getOperand(0)); |
| 2814 | } |
| 2815 | return DAG.getNode(ARMISD::FMSTAT, DL, MVT::Glue, Cmp); |
| 2816 | } |
| 2817 | |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 2818 | SDValue ARMTargetLowering::LowerSELECT(SDValue Op, SelectionDAG &DAG) const { |
| 2819 | SDValue Cond = Op.getOperand(0); |
| 2820 | SDValue SelectTrue = Op.getOperand(1); |
| 2821 | SDValue SelectFalse = Op.getOperand(2); |
| 2822 | DebugLoc dl = Op.getDebugLoc(); |
| 2823 | |
| 2824 | // Convert: |
| 2825 | // |
| 2826 | // (select (cmov 1, 0, cond), t, f) -> (cmov t, f, cond) |
| 2827 | // (select (cmov 0, 1, cond), t, f) -> (cmov f, t, cond) |
| 2828 | // |
| 2829 | if (Cond.getOpcode() == ARMISD::CMOV && Cond.hasOneUse()) { |
| 2830 | const ConstantSDNode *CMOVTrue = |
| 2831 | dyn_cast<ConstantSDNode>(Cond.getOperand(0)); |
| 2832 | const ConstantSDNode *CMOVFalse = |
| 2833 | dyn_cast<ConstantSDNode>(Cond.getOperand(1)); |
| 2834 | |
| 2835 | if (CMOVTrue && CMOVFalse) { |
| 2836 | unsigned CMOVTrueVal = CMOVTrue->getZExtValue(); |
| 2837 | unsigned CMOVFalseVal = CMOVFalse->getZExtValue(); |
| 2838 | |
| 2839 | SDValue True; |
| 2840 | SDValue False; |
| 2841 | if (CMOVTrueVal == 1 && CMOVFalseVal == 0) { |
| 2842 | True = SelectTrue; |
| 2843 | False = SelectFalse; |
| 2844 | } else if (CMOVTrueVal == 0 && CMOVFalseVal == 1) { |
| 2845 | True = SelectFalse; |
| 2846 | False = SelectTrue; |
| 2847 | } |
| 2848 | |
| 2849 | if (True.getNode() && False.getNode()) { |
Evan Cheng | b936e30 | 2011-05-18 18:59:17 +0000 | [diff] [blame] | 2850 | EVT VT = Op.getValueType(); |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 2851 | SDValue ARMcc = Cond.getOperand(2); |
| 2852 | SDValue CCR = Cond.getOperand(3); |
Bob Wilson | 79f56c9 | 2011-03-08 01:17:20 +0000 | [diff] [blame] | 2853 | SDValue Cmp = duplicateCmp(Cond.getOperand(4), DAG); |
Evan Cheng | b936e30 | 2011-05-18 18:59:17 +0000 | [diff] [blame] | 2854 | assert(True.getValueType() == VT); |
| 2855 | return DAG.getNode(ARMISD::CMOV, dl, VT, True, False, ARMcc, CCR, Cmp); |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 2856 | } |
| 2857 | } |
| 2858 | } |
| 2859 | |
Dan Gohman | db95389 | 2012-02-24 00:09:36 +0000 | [diff] [blame] | 2860 | // ARM's BooleanContents value is UndefinedBooleanContent. Mask out the |
| 2861 | // undefined bits before doing a full-word comparison with zero. |
| 2862 | Cond = DAG.getNode(ISD::AND, dl, Cond.getValueType(), Cond, |
| 2863 | DAG.getConstant(1, Cond.getValueType())); |
| 2864 | |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 2865 | return DAG.getSelectCC(dl, Cond, |
| 2866 | DAG.getConstant(0, Cond.getValueType()), |
| 2867 | SelectTrue, SelectFalse, ISD::SETNE); |
| 2868 | } |
| 2869 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2870 | SDValue ARMTargetLowering::LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2871 | EVT VT = Op.getValueType(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2872 | SDValue LHS = Op.getOperand(0); |
| 2873 | SDValue RHS = Op.getOperand(1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2874 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(4))->get(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2875 | SDValue TrueVal = Op.getOperand(2); |
| 2876 | SDValue FalseVal = Op.getOperand(3); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2877 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2878 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2879 | if (LHS.getValueType() == MVT::i32) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2880 | SDValue ARMcc; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2881 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2882 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMcc, DAG, dl); |
Jim Grosbach | b04546f | 2011-09-13 20:30:37 +0000 | [diff] [blame] | 2883 | return DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, ARMcc, CCR,Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2884 | } |
| 2885 | |
| 2886 | ARMCC::CondCodes CondCode, CondCode2; |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 2887 | FPCCToARMCC(CC, CondCode, CondCode2); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2888 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2889 | SDValue ARMcc = DAG.getConstant(CondCode, MVT::i32); |
| 2890 | SDValue Cmp = getVFPCmp(LHS, RHS, DAG, dl); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2891 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2892 | SDValue Result = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2893 | ARMcc, CCR, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2894 | if (CondCode2 != ARMCC::AL) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2895 | SDValue ARMcc2 = DAG.getConstant(CondCode2, MVT::i32); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2896 | // FIXME: Needs another CMP because flag can have but one use. |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2897 | SDValue Cmp2 = getVFPCmp(LHS, RHS, DAG, dl); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2898 | Result = DAG.getNode(ARMISD::CMOV, dl, VT, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2899 | Result, TrueVal, ARMcc2, CCR, Cmp2); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2900 | } |
| 2901 | return Result; |
| 2902 | } |
| 2903 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2904 | /// canChangeToInt - Given the fp compare operand, return true if it is suitable |
| 2905 | /// to morph to an integer compare sequence. |
| 2906 | static bool canChangeToInt(SDValue Op, bool &SeenZero, |
| 2907 | const ARMSubtarget *Subtarget) { |
| 2908 | SDNode *N = Op.getNode(); |
| 2909 | if (!N->hasOneUse()) |
| 2910 | // Otherwise it requires moving the value from fp to integer registers. |
| 2911 | return false; |
| 2912 | if (!N->getNumValues()) |
| 2913 | return false; |
| 2914 | EVT VT = Op.getValueType(); |
| 2915 | if (VT != MVT::f32 && !Subtarget->isFPBrccSlow()) |
| 2916 | // f32 case is generally profitable. f64 case only makes sense when vcmpe + |
| 2917 | // vmrs are very slow, e.g. cortex-a8. |
| 2918 | return false; |
| 2919 | |
| 2920 | if (isFloatingPointZero(Op)) { |
| 2921 | SeenZero = true; |
| 2922 | return true; |
| 2923 | } |
| 2924 | return ISD::isNormalLoad(N); |
| 2925 | } |
| 2926 | |
| 2927 | static SDValue bitcastf32Toi32(SDValue Op, SelectionDAG &DAG) { |
| 2928 | if (isFloatingPointZero(Op)) |
| 2929 | return DAG.getConstant(0, MVT::i32); |
| 2930 | |
| 2931 | if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Op)) |
| 2932 | return DAG.getLoad(MVT::i32, Op.getDebugLoc(), |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2933 | Ld->getChain(), Ld->getBasePtr(), Ld->getPointerInfo(), |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2934 | Ld->isVolatile(), Ld->isNonTemporal(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2935 | Ld->isInvariant(), Ld->getAlignment()); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2936 | |
| 2937 | llvm_unreachable("Unknown VFP cmp argument!"); |
| 2938 | } |
| 2939 | |
| 2940 | static void expandf64Toi32(SDValue Op, SelectionDAG &DAG, |
| 2941 | SDValue &RetVal1, SDValue &RetVal2) { |
| 2942 | if (isFloatingPointZero(Op)) { |
| 2943 | RetVal1 = DAG.getConstant(0, MVT::i32); |
| 2944 | RetVal2 = DAG.getConstant(0, MVT::i32); |
| 2945 | return; |
| 2946 | } |
| 2947 | |
| 2948 | if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Op)) { |
| 2949 | SDValue Ptr = Ld->getBasePtr(); |
| 2950 | RetVal1 = DAG.getLoad(MVT::i32, Op.getDebugLoc(), |
| 2951 | Ld->getChain(), Ptr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2952 | Ld->getPointerInfo(), |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2953 | Ld->isVolatile(), Ld->isNonTemporal(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2954 | Ld->isInvariant(), Ld->getAlignment()); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2955 | |
| 2956 | EVT PtrType = Ptr.getValueType(); |
| 2957 | unsigned NewAlign = MinAlign(Ld->getAlignment(), 4); |
| 2958 | SDValue NewPtr = DAG.getNode(ISD::ADD, Op.getDebugLoc(), |
| 2959 | PtrType, Ptr, DAG.getConstant(4, PtrType)); |
| 2960 | RetVal2 = DAG.getLoad(MVT::i32, Op.getDebugLoc(), |
| 2961 | Ld->getChain(), NewPtr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2962 | Ld->getPointerInfo().getWithOffset(4), |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2963 | Ld->isVolatile(), Ld->isNonTemporal(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2964 | Ld->isInvariant(), NewAlign); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2965 | return; |
| 2966 | } |
| 2967 | |
| 2968 | llvm_unreachable("Unknown VFP cmp argument!"); |
| 2969 | } |
| 2970 | |
| 2971 | /// OptimizeVFPBrcond - With -enable-unsafe-fp-math, it's legal to optimize some |
| 2972 | /// f32 and even f64 comparisons to integer ones. |
| 2973 | SDValue |
| 2974 | ARMTargetLowering::OptimizeVFPBrcond(SDValue Op, SelectionDAG &DAG) const { |
| 2975 | SDValue Chain = Op.getOperand(0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2976 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get(); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2977 | SDValue LHS = Op.getOperand(2); |
| 2978 | SDValue RHS = Op.getOperand(3); |
| 2979 | SDValue Dest = Op.getOperand(4); |
| 2980 | DebugLoc dl = Op.getDebugLoc(); |
| 2981 | |
Evan Cheng | fc501a3 | 2012-03-01 23:27:13 +0000 | [diff] [blame] | 2982 | bool LHSSeenZero = false; |
| 2983 | bool LHSOk = canChangeToInt(LHS, LHSSeenZero, Subtarget); |
| 2984 | bool RHSSeenZero = false; |
| 2985 | bool RHSOk = canChangeToInt(RHS, RHSSeenZero, Subtarget); |
| 2986 | if (LHSOk && RHSOk && (LHSSeenZero || RHSSeenZero)) { |
Bob Wilson | 1b772f9 | 2011-03-08 01:17:16 +0000 | [diff] [blame] | 2987 | // If unsafe fp math optimization is enabled and there are no other uses of |
| 2988 | // the CMP operands, and the condition code is EQ or NE, we can optimize it |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2989 | // to an integer comparison. |
| 2990 | if (CC == ISD::SETOEQ) |
| 2991 | CC = ISD::SETEQ; |
| 2992 | else if (CC == ISD::SETUNE) |
| 2993 | CC = ISD::SETNE; |
| 2994 | |
Evan Cheng | fc501a3 | 2012-03-01 23:27:13 +0000 | [diff] [blame] | 2995 | SDValue Mask = DAG.getConstant(0x7fffffff, MVT::i32); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2996 | SDValue ARMcc; |
| 2997 | if (LHS.getValueType() == MVT::f32) { |
Evan Cheng | fc501a3 | 2012-03-01 23:27:13 +0000 | [diff] [blame] | 2998 | LHS = DAG.getNode(ISD::AND, dl, MVT::i32, |
| 2999 | bitcastf32Toi32(LHS, DAG), Mask); |
| 3000 | RHS = DAG.getNode(ISD::AND, dl, MVT::i32, |
| 3001 | bitcastf32Toi32(RHS, DAG), Mask); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3002 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMcc, DAG, dl); |
| 3003 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| 3004 | return DAG.getNode(ARMISD::BRCOND, dl, MVT::Other, |
| 3005 | Chain, Dest, ARMcc, CCR, Cmp); |
| 3006 | } |
| 3007 | |
| 3008 | SDValue LHS1, LHS2; |
| 3009 | SDValue RHS1, RHS2; |
| 3010 | expandf64Toi32(LHS, DAG, LHS1, LHS2); |
| 3011 | expandf64Toi32(RHS, DAG, RHS1, RHS2); |
Evan Cheng | fc501a3 | 2012-03-01 23:27:13 +0000 | [diff] [blame] | 3012 | LHS2 = DAG.getNode(ISD::AND, dl, MVT::i32, LHS2, Mask); |
| 3013 | RHS2 = DAG.getNode(ISD::AND, dl, MVT::i32, RHS2, Mask); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3014 | ARMCC::CondCodes CondCode = IntCCToARMCC(CC); |
| 3015 | ARMcc = DAG.getConstant(CondCode, MVT::i32); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 3016 | SDVTList VTList = DAG.getVTList(MVT::Other, MVT::Glue); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3017 | SDValue Ops[] = { Chain, ARMcc, LHS1, LHS2, RHS1, RHS2, Dest }; |
| 3018 | return DAG.getNode(ARMISD::BCC_i64, dl, VTList, Ops, 7); |
| 3019 | } |
| 3020 | |
| 3021 | return SDValue(); |
| 3022 | } |
| 3023 | |
| 3024 | SDValue ARMTargetLowering::LowerBR_CC(SDValue Op, SelectionDAG &DAG) const { |
| 3025 | SDValue Chain = Op.getOperand(0); |
| 3026 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get(); |
| 3027 | SDValue LHS = Op.getOperand(2); |
| 3028 | SDValue RHS = Op.getOperand(3); |
| 3029 | SDValue Dest = Op.getOperand(4); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 3030 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3031 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3032 | if (LHS.getValueType() == MVT::i32) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3033 | SDValue ARMcc; |
| 3034 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMcc, DAG, dl); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3035 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3036 | return DAG.getNode(ARMISD::BRCOND, dl, MVT::Other, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3037 | Chain, Dest, ARMcc, CCR, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3038 | } |
| 3039 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3040 | assert(LHS.getValueType() == MVT::f32 || LHS.getValueType() == MVT::f64); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3041 | |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 3042 | if (getTargetMachine().Options.UnsafeFPMath && |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3043 | (CC == ISD::SETEQ || CC == ISD::SETOEQ || |
| 3044 | CC == ISD::SETNE || CC == ISD::SETUNE)) { |
| 3045 | SDValue Result = OptimizeVFPBrcond(Op, DAG); |
| 3046 | if (Result.getNode()) |
| 3047 | return Result; |
| 3048 | } |
| 3049 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3050 | ARMCC::CondCodes CondCode, CondCode2; |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 3051 | FPCCToARMCC(CC, CondCode, CondCode2); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3052 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3053 | SDValue ARMcc = DAG.getConstant(CondCode, MVT::i32); |
| 3054 | SDValue Cmp = getVFPCmp(LHS, RHS, DAG, dl); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3055 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 3056 | SDVTList VTList = DAG.getVTList(MVT::Other, MVT::Glue); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3057 | SDValue Ops[] = { Chain, Dest, ARMcc, CCR, Cmp }; |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 3058 | SDValue Res = DAG.getNode(ARMISD::BRCOND, dl, VTList, Ops, 5); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3059 | if (CondCode2 != ARMCC::AL) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3060 | ARMcc = DAG.getConstant(CondCode2, MVT::i32); |
| 3061 | SDValue Ops[] = { Res, Dest, ARMcc, CCR, Res.getValue(1) }; |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 3062 | Res = DAG.getNode(ARMISD::BRCOND, dl, VTList, Ops, 5); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3063 | } |
| 3064 | return Res; |
| 3065 | } |
| 3066 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 3067 | SDValue ARMTargetLowering::LowerBR_JT(SDValue Op, SelectionDAG &DAG) const { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3068 | SDValue Chain = Op.getOperand(0); |
| 3069 | SDValue Table = Op.getOperand(1); |
| 3070 | SDValue Index = Op.getOperand(2); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 3071 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3072 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3073 | EVT PTy = getPointerTy(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3074 | JumpTableSDNode *JT = cast<JumpTableSDNode>(Table); |
| 3075 | ARMFunctionInfo *AFI = DAG.getMachineFunction().getInfo<ARMFunctionInfo>(); |
Bob Wilson | 3eadf00 | 2009-07-14 18:44:34 +0000 | [diff] [blame] | 3076 | SDValue UId = DAG.getConstant(AFI->createJumpTableUId(), PTy); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3077 | SDValue JTI = DAG.getTargetJumpTable(JT->getIndex(), PTy); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3078 | Table = DAG.getNode(ARMISD::WrapperJT, dl, MVT::i32, JTI, UId); |
Evan Cheng | e7c329b | 2009-07-28 20:53:24 +0000 | [diff] [blame] | 3079 | Index = DAG.getNode(ISD::MUL, dl, PTy, Index, DAG.getConstant(4, PTy)); |
| 3080 | SDValue Addr = DAG.getNode(ISD::ADD, dl, PTy, Index, Table); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3081 | if (Subtarget->isThumb2()) { |
| 3082 | // Thumb2 uses a two-level jump. That is, it jumps into the jump table |
| 3083 | // which does another jump to the destination. This also makes it easier |
| 3084 | // to translate it to TBB / TBH later. |
| 3085 | // FIXME: This might not work if the function is extremely large. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3086 | return DAG.getNode(ARMISD::BR2_JT, dl, MVT::Other, Chain, |
Evan Cheng | 5657c01 | 2009-07-29 02:18:14 +0000 | [diff] [blame] | 3087 | Addr, Op.getOperand(2), JTI, UId); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3088 | } |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3089 | if (getTargetMachine().getRelocationModel() == Reloc::PIC_) { |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 3090 | Addr = DAG.getLoad((EVT)MVT::i32, dl, Chain, Addr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 3091 | MachinePointerInfo::getJumpTable(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3092 | false, false, false, 0); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3093 | Chain = Addr.getValue(1); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 3094 | Addr = DAG.getNode(ISD::ADD, dl, PTy, Addr, Table); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3095 | 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] | 3096 | } else { |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 3097 | Addr = DAG.getLoad(PTy, dl, Chain, Addr, |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3098 | MachinePointerInfo::getJumpTable(), |
| 3099 | false, false, false, 0); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3100 | Chain = Addr.getValue(1); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3101 | 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] | 3102 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3103 | } |
| 3104 | |
Eli Friedman | 14e809c | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3105 | static SDValue LowerVectorFP_TO_INT(SDValue Op, SelectionDAG &DAG) { |
James Molloy | 873fd5f | 2012-02-20 09:24:05 +0000 | [diff] [blame] | 3106 | EVT VT = Op.getValueType(); |
| 3107 | DebugLoc dl = Op.getDebugLoc(); |
Eli Friedman | 14e809c | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3108 | |
James Molloy | 873fd5f | 2012-02-20 09:24:05 +0000 | [diff] [blame] | 3109 | if (Op.getValueType().getVectorElementType() == MVT::i32) { |
| 3110 | if (Op.getOperand(0).getValueType().getVectorElementType() == MVT::f32) |
| 3111 | return Op; |
| 3112 | return DAG.UnrollVectorOp(Op.getNode()); |
| 3113 | } |
| 3114 | |
| 3115 | assert(Op.getOperand(0).getValueType() == MVT::v4f32 && |
| 3116 | "Invalid type for custom lowering!"); |
| 3117 | if (VT != MVT::v4i16) |
| 3118 | return DAG.UnrollVectorOp(Op.getNode()); |
| 3119 | |
| 3120 | Op = DAG.getNode(Op.getOpcode(), dl, MVT::v4i32, Op.getOperand(0)); |
| 3121 | return DAG.getNode(ISD::TRUNCATE, dl, VT, Op); |
Eli Friedman | 14e809c | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3122 | } |
| 3123 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3124 | static SDValue LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG) { |
Eli Friedman | 14e809c | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3125 | EVT VT = Op.getValueType(); |
| 3126 | if (VT.isVector()) |
| 3127 | return LowerVectorFP_TO_INT(Op, DAG); |
| 3128 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3129 | DebugLoc dl = Op.getDebugLoc(); |
| 3130 | unsigned Opc; |
| 3131 | |
| 3132 | switch (Op.getOpcode()) { |
Craig Topper | bc21981 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 3133 | default: llvm_unreachable("Invalid opcode!"); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3134 | case ISD::FP_TO_SINT: |
| 3135 | Opc = ARMISD::FTOSI; |
| 3136 | break; |
| 3137 | case ISD::FP_TO_UINT: |
| 3138 | Opc = ARMISD::FTOUI; |
| 3139 | break; |
| 3140 | } |
| 3141 | Op = DAG.getNode(Opc, dl, MVT::f32, Op.getOperand(0)); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3142 | return DAG.getNode(ISD::BITCAST, dl, MVT::i32, Op); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3143 | } |
| 3144 | |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 3145 | static SDValue LowerVectorINT_TO_FP(SDValue Op, SelectionDAG &DAG) { |
| 3146 | EVT VT = Op.getValueType(); |
| 3147 | DebugLoc dl = Op.getDebugLoc(); |
| 3148 | |
Eli Friedman | 14e809c | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3149 | if (Op.getOperand(0).getValueType().getVectorElementType() == MVT::i32) { |
| 3150 | if (VT.getVectorElementType() == MVT::f32) |
| 3151 | return Op; |
| 3152 | return DAG.UnrollVectorOp(Op.getNode()); |
| 3153 | } |
| 3154 | |
Duncan Sands | 1f6a329 | 2011-08-12 14:54:45 +0000 | [diff] [blame] | 3155 | assert(Op.getOperand(0).getValueType() == MVT::v4i16 && |
| 3156 | "Invalid type for custom lowering!"); |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 3157 | if (VT != MVT::v4f32) |
| 3158 | return DAG.UnrollVectorOp(Op.getNode()); |
| 3159 | |
| 3160 | unsigned CastOpc; |
| 3161 | unsigned Opc; |
| 3162 | switch (Op.getOpcode()) { |
Craig Topper | bc21981 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 3163 | default: llvm_unreachable("Invalid opcode!"); |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 3164 | case ISD::SINT_TO_FP: |
| 3165 | CastOpc = ISD::SIGN_EXTEND; |
| 3166 | Opc = ISD::SINT_TO_FP; |
| 3167 | break; |
| 3168 | case ISD::UINT_TO_FP: |
| 3169 | CastOpc = ISD::ZERO_EXTEND; |
| 3170 | Opc = ISD::UINT_TO_FP; |
| 3171 | break; |
| 3172 | } |
| 3173 | |
| 3174 | Op = DAG.getNode(CastOpc, dl, MVT::v4i32, Op.getOperand(0)); |
| 3175 | return DAG.getNode(Opc, dl, VT, Op); |
| 3176 | } |
| 3177 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3178 | static SDValue LowerINT_TO_FP(SDValue Op, SelectionDAG &DAG) { |
| 3179 | EVT VT = Op.getValueType(); |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 3180 | if (VT.isVector()) |
| 3181 | return LowerVectorINT_TO_FP(Op, DAG); |
| 3182 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3183 | DebugLoc dl = Op.getDebugLoc(); |
| 3184 | unsigned Opc; |
| 3185 | |
| 3186 | switch (Op.getOpcode()) { |
Craig Topper | bc21981 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 3187 | default: llvm_unreachable("Invalid opcode!"); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3188 | case ISD::SINT_TO_FP: |
| 3189 | Opc = ARMISD::SITOF; |
| 3190 | break; |
| 3191 | case ISD::UINT_TO_FP: |
| 3192 | Opc = ARMISD::UITOF; |
| 3193 | break; |
| 3194 | } |
| 3195 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3196 | Op = DAG.getNode(ISD::BITCAST, dl, MVT::f32, Op.getOperand(0)); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3197 | return DAG.getNode(Opc, dl, VT, Op); |
| 3198 | } |
| 3199 | |
Evan Cheng | 515fe3a | 2010-07-08 02:08:50 +0000 | [diff] [blame] | 3200 | SDValue ARMTargetLowering::LowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3201 | // Implement fcopysign with a fabs and a conditional fneg. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3202 | SDValue Tmp0 = Op.getOperand(0); |
| 3203 | SDValue Tmp1 = Op.getOperand(1); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 3204 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3205 | EVT VT = Op.getValueType(); |
| 3206 | EVT SrcVT = Tmp1.getValueType(); |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3207 | bool InGPR = Tmp0.getOpcode() == ISD::BITCAST || |
| 3208 | Tmp0.getOpcode() == ARMISD::VMOVDRR; |
| 3209 | bool UseNEON = !InGPR && Subtarget->hasNEON(); |
| 3210 | |
| 3211 | if (UseNEON) { |
| 3212 | // Use VBSL to copy the sign bit. |
| 3213 | unsigned EncodedVal = ARM_AM::createNEONModImm(0x6, 0x80); |
| 3214 | SDValue Mask = DAG.getNode(ARMISD::VMOVIMM, dl, MVT::v2i32, |
| 3215 | DAG.getTargetConstant(EncodedVal, MVT::i32)); |
| 3216 | EVT OpVT = (VT == MVT::f32) ? MVT::v2i32 : MVT::v1i64; |
| 3217 | if (VT == MVT::f64) |
| 3218 | Mask = DAG.getNode(ARMISD::VSHL, dl, OpVT, |
| 3219 | DAG.getNode(ISD::BITCAST, dl, OpVT, Mask), |
| 3220 | DAG.getConstant(32, MVT::i32)); |
| 3221 | else /*if (VT == MVT::f32)*/ |
| 3222 | Tmp0 = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, MVT::v2f32, Tmp0); |
| 3223 | if (SrcVT == MVT::f32) { |
| 3224 | Tmp1 = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, MVT::v2f32, Tmp1); |
| 3225 | if (VT == MVT::f64) |
| 3226 | Tmp1 = DAG.getNode(ARMISD::VSHL, dl, OpVT, |
| 3227 | DAG.getNode(ISD::BITCAST, dl, OpVT, Tmp1), |
| 3228 | DAG.getConstant(32, MVT::i32)); |
Evan Cheng | 9eec66e | 2011-04-15 01:31:00 +0000 | [diff] [blame] | 3229 | } else if (VT == MVT::f32) |
| 3230 | Tmp1 = DAG.getNode(ARMISD::VSHRu, dl, MVT::v1i64, |
| 3231 | DAG.getNode(ISD::BITCAST, dl, MVT::v1i64, Tmp1), |
| 3232 | DAG.getConstant(32, MVT::i32)); |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3233 | Tmp0 = DAG.getNode(ISD::BITCAST, dl, OpVT, Tmp0); |
| 3234 | Tmp1 = DAG.getNode(ISD::BITCAST, dl, OpVT, Tmp1); |
| 3235 | |
| 3236 | SDValue AllOnes = DAG.getTargetConstant(ARM_AM::createNEONModImm(0xe, 0xff), |
| 3237 | MVT::i32); |
| 3238 | AllOnes = DAG.getNode(ARMISD::VMOVIMM, dl, MVT::v8i8, AllOnes); |
| 3239 | SDValue MaskNot = DAG.getNode(ISD::XOR, dl, OpVT, Mask, |
| 3240 | DAG.getNode(ISD::BITCAST, dl, OpVT, AllOnes)); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 3241 | |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3242 | SDValue Res = DAG.getNode(ISD::OR, dl, OpVT, |
| 3243 | DAG.getNode(ISD::AND, dl, OpVT, Tmp1, Mask), |
| 3244 | DAG.getNode(ISD::AND, dl, OpVT, Tmp0, MaskNot)); |
Evan Cheng | c24ab5c | 2011-02-28 18:45:27 +0000 | [diff] [blame] | 3245 | if (VT == MVT::f32) { |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3246 | Res = DAG.getNode(ISD::BITCAST, dl, MVT::v2f32, Res); |
| 3247 | Res = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f32, Res, |
| 3248 | DAG.getConstant(0, MVT::i32)); |
| 3249 | } else { |
| 3250 | Res = DAG.getNode(ISD::BITCAST, dl, MVT::f64, Res); |
| 3251 | } |
| 3252 | |
| 3253 | return Res; |
| 3254 | } |
Evan Cheng | c143dd4 | 2011-02-11 02:28:55 +0000 | [diff] [blame] | 3255 | |
| 3256 | // Bitcast operand 1 to i32. |
| 3257 | if (SrcVT == MVT::f64) |
| 3258 | Tmp1 = DAG.getNode(ARMISD::VMOVRRD, dl, DAG.getVTList(MVT::i32, MVT::i32), |
| 3259 | &Tmp1, 1).getValue(1); |
| 3260 | Tmp1 = DAG.getNode(ISD::BITCAST, dl, MVT::i32, Tmp1); |
| 3261 | |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3262 | // Or in the signbit with integer operations. |
| 3263 | SDValue Mask1 = DAG.getConstant(0x80000000, MVT::i32); |
| 3264 | SDValue Mask2 = DAG.getConstant(0x7fffffff, MVT::i32); |
| 3265 | Tmp1 = DAG.getNode(ISD::AND, dl, MVT::i32, Tmp1, Mask1); |
| 3266 | if (VT == MVT::f32) { |
| 3267 | Tmp0 = DAG.getNode(ISD::AND, dl, MVT::i32, |
| 3268 | DAG.getNode(ISD::BITCAST, dl, MVT::i32, Tmp0), Mask2); |
| 3269 | return DAG.getNode(ISD::BITCAST, dl, MVT::f32, |
| 3270 | DAG.getNode(ISD::OR, dl, MVT::i32, Tmp0, Tmp1)); |
Evan Cheng | c143dd4 | 2011-02-11 02:28:55 +0000 | [diff] [blame] | 3271 | } |
| 3272 | |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3273 | // f64: Or the high part with signbit and then combine two parts. |
| 3274 | Tmp0 = DAG.getNode(ARMISD::VMOVRRD, dl, DAG.getVTList(MVT::i32, MVT::i32), |
| 3275 | &Tmp0, 1); |
| 3276 | SDValue Lo = Tmp0.getValue(0); |
| 3277 | SDValue Hi = DAG.getNode(ISD::AND, dl, MVT::i32, Tmp0.getValue(1), Mask2); |
| 3278 | Hi = DAG.getNode(ISD::OR, dl, MVT::i32, Hi, Tmp1); |
| 3279 | return DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3280 | } |
| 3281 | |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3282 | SDValue ARMTargetLowering::LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const{ |
| 3283 | MachineFunction &MF = DAG.getMachineFunction(); |
| 3284 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 3285 | MFI->setReturnAddressIsTaken(true); |
| 3286 | |
| 3287 | EVT VT = Op.getValueType(); |
| 3288 | DebugLoc dl = Op.getDebugLoc(); |
| 3289 | unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
| 3290 | if (Depth) { |
| 3291 | SDValue FrameAddr = LowerFRAMEADDR(Op, DAG); |
| 3292 | SDValue Offset = DAG.getConstant(4, MVT::i32); |
| 3293 | return DAG.getLoad(VT, dl, DAG.getEntryNode(), |
| 3294 | DAG.getNode(ISD::ADD, dl, VT, FrameAddr, Offset), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3295 | MachinePointerInfo(), false, false, false, 0); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3296 | } |
| 3297 | |
| 3298 | // Return LR, which contains the return address. Mark it an implicit live-in. |
Devang Patel | 68e6bee | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 3299 | unsigned Reg = MF.addLiveIn(ARM::LR, getRegClassFor(MVT::i32)); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3300 | return DAG.getCopyFromReg(DAG.getEntryNode(), dl, Reg, VT); |
| 3301 | } |
| 3302 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 3303 | SDValue ARMTargetLowering::LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const { |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3304 | MachineFrameInfo *MFI = DAG.getMachineFunction().getFrameInfo(); |
| 3305 | MFI->setFrameAddressIsTaken(true); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3306 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3307 | EVT VT = Op.getValueType(); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3308 | DebugLoc dl = Op.getDebugLoc(); // FIXME probably not meaningful |
| 3309 | unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
Evan Cheng | cd82861 | 2009-06-18 23:14:30 +0000 | [diff] [blame] | 3310 | unsigned FrameReg = (Subtarget->isThumb() || Subtarget->isTargetDarwin()) |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3311 | ? ARM::R7 : ARM::R11; |
| 3312 | SDValue FrameAddr = DAG.getCopyFromReg(DAG.getEntryNode(), dl, FrameReg, VT); |
| 3313 | while (Depth--) |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 3314 | FrameAddr = DAG.getLoad(VT, dl, DAG.getEntryNode(), FrameAddr, |
| 3315 | MachinePointerInfo(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3316 | false, false, false, 0); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3317 | return FrameAddr; |
| 3318 | } |
| 3319 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3320 | /// ExpandBITCAST - If the target supports VFP, this function is called to |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3321 | /// expand a bit convert where either the source or destination type is i64 to |
| 3322 | /// use a VMOVDRR or VMOVRRD node. This should not be done when the non-i64 |
| 3323 | /// operand type is illegal (e.g., v2f32 for a target that doesn't support |
| 3324 | /// vectors), since the legalizer won't know what to do with that. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3325 | static SDValue ExpandBITCAST(SDNode *N, SelectionDAG &DAG) { |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3326 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 3327 | DebugLoc dl = N->getDebugLoc(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3328 | SDValue Op = N->getOperand(0); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 3329 | |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3330 | // This function is only supposed to be called for i64 types, either as the |
| 3331 | // source or destination of the bit convert. |
| 3332 | EVT SrcVT = Op.getValueType(); |
| 3333 | EVT DstVT = N->getValueType(0); |
| 3334 | assert((SrcVT == MVT::i64 || DstVT == MVT::i64) && |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3335 | "ExpandBITCAST called for non-i64 type"); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 3336 | |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3337 | // Turn i64->f64 into VMOVDRR. |
| 3338 | if (SrcVT == MVT::i64 && TLI.isTypeLegal(DstVT)) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3339 | SDValue Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Op, |
| 3340 | DAG.getConstant(0, MVT::i32)); |
| 3341 | SDValue Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Op, |
| 3342 | DAG.getConstant(1, MVT::i32)); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3343 | return DAG.getNode(ISD::BITCAST, dl, DstVT, |
Bob Wilson | 1114f56 | 2010-06-11 22:45:25 +0000 | [diff] [blame] | 3344 | DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi)); |
Evan Cheng | c7c7729 | 2008-11-04 19:57:48 +0000 | [diff] [blame] | 3345 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3346 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 3347 | // Turn f64->i64 into VMOVRRD. |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3348 | if (DstVT == MVT::i64 && TLI.isTypeLegal(SrcVT)) { |
| 3349 | SDValue Cvt = DAG.getNode(ARMISD::VMOVRRD, dl, |
| 3350 | DAG.getVTList(MVT::i32, MVT::i32), &Op, 1); |
| 3351 | // Merge the pieces into a single i64 value. |
| 3352 | return DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Cvt, Cvt.getValue(1)); |
| 3353 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3354 | |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3355 | return SDValue(); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3356 | } |
| 3357 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3358 | /// getZeroVector - Returns a vector of specified type with all zero elements. |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3359 | /// Zero vectors are used to represent vector negation and in those cases |
| 3360 | /// will be implemented with the NEON VNEG instruction. However, VNEG does |
| 3361 | /// not support i64 elements, so sometimes the zero vectors will need to be |
| 3362 | /// explicitly constructed. Regardless, use a canonical VMOV to create the |
| 3363 | /// zero vector. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3364 | static SDValue getZeroVector(EVT VT, SelectionDAG &DAG, DebugLoc dl) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3365 | assert(VT.isVector() && "Expected a vector type"); |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3366 | // The canonical modified immediate encoding of a zero vector is....0! |
| 3367 | SDValue EncodedVal = DAG.getTargetConstant(0, MVT::i32); |
| 3368 | EVT VmovVT = VT.is128BitVector() ? MVT::v4i32 : MVT::v2i32; |
| 3369 | SDValue Vmov = DAG.getNode(ARMISD::VMOVIMM, dl, VmovVT, EncodedVal); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3370 | return DAG.getNode(ISD::BITCAST, dl, VT, Vmov); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3371 | } |
| 3372 | |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3373 | /// LowerShiftRightParts - Lower SRA_PARTS, which returns two |
| 3374 | /// i32 values and take a 2 x i32 value to shift plus a shift amount. |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 3375 | SDValue ARMTargetLowering::LowerShiftRightParts(SDValue Op, |
| 3376 | SelectionDAG &DAG) const { |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3377 | assert(Op.getNumOperands() == 3 && "Not a double-shift!"); |
| 3378 | EVT VT = Op.getValueType(); |
| 3379 | unsigned VTBits = VT.getSizeInBits(); |
| 3380 | DebugLoc dl = Op.getDebugLoc(); |
| 3381 | SDValue ShOpLo = Op.getOperand(0); |
| 3382 | SDValue ShOpHi = Op.getOperand(1); |
| 3383 | SDValue ShAmt = Op.getOperand(2); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3384 | SDValue ARMcc; |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 3385 | unsigned Opc = (Op.getOpcode() == ISD::SRA_PARTS) ? ISD::SRA : ISD::SRL; |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3386 | |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 3387 | assert(Op.getOpcode() == ISD::SRA_PARTS || Op.getOpcode() == ISD::SRL_PARTS); |
| 3388 | |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3389 | SDValue RevShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, |
| 3390 | DAG.getConstant(VTBits, MVT::i32), ShAmt); |
| 3391 | SDValue Tmp1 = DAG.getNode(ISD::SRL, dl, VT, ShOpLo, ShAmt); |
| 3392 | SDValue ExtraShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, ShAmt, |
| 3393 | DAG.getConstant(VTBits, MVT::i32)); |
| 3394 | SDValue Tmp2 = DAG.getNode(ISD::SHL, dl, VT, ShOpHi, RevShAmt); |
| 3395 | SDValue FalseVal = DAG.getNode(ISD::OR, dl, VT, Tmp1, Tmp2); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 3396 | SDValue TrueVal = DAG.getNode(Opc, dl, VT, ShOpHi, ExtraShAmt); |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3397 | |
| 3398 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| 3399 | SDValue Cmp = getARMCmp(ExtraShAmt, DAG.getConstant(0, MVT::i32), ISD::SETGE, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3400 | ARMcc, DAG, dl); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 3401 | SDValue Hi = DAG.getNode(Opc, dl, VT, ShOpHi, ShAmt); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3402 | SDValue Lo = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, ARMcc, |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3403 | CCR, Cmp); |
| 3404 | |
| 3405 | SDValue Ops[2] = { Lo, Hi }; |
| 3406 | return DAG.getMergeValues(Ops, 2, dl); |
| 3407 | } |
| 3408 | |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3409 | /// LowerShiftLeftParts - Lower SHL_PARTS, which returns two |
| 3410 | /// i32 values and take a 2 x i32 value to shift plus a shift amount. |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 3411 | SDValue ARMTargetLowering::LowerShiftLeftParts(SDValue Op, |
| 3412 | SelectionDAG &DAG) const { |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3413 | assert(Op.getNumOperands() == 3 && "Not a double-shift!"); |
| 3414 | EVT VT = Op.getValueType(); |
| 3415 | unsigned VTBits = VT.getSizeInBits(); |
| 3416 | DebugLoc dl = Op.getDebugLoc(); |
| 3417 | SDValue ShOpLo = Op.getOperand(0); |
| 3418 | SDValue ShOpHi = Op.getOperand(1); |
| 3419 | SDValue ShAmt = Op.getOperand(2); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3420 | SDValue ARMcc; |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3421 | |
| 3422 | assert(Op.getOpcode() == ISD::SHL_PARTS); |
| 3423 | SDValue RevShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, |
| 3424 | DAG.getConstant(VTBits, MVT::i32), ShAmt); |
| 3425 | SDValue Tmp1 = DAG.getNode(ISD::SRL, dl, VT, ShOpLo, RevShAmt); |
| 3426 | SDValue ExtraShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, ShAmt, |
| 3427 | DAG.getConstant(VTBits, MVT::i32)); |
| 3428 | SDValue Tmp2 = DAG.getNode(ISD::SHL, dl, VT, ShOpHi, ShAmt); |
| 3429 | SDValue Tmp3 = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ExtraShAmt); |
| 3430 | |
| 3431 | SDValue FalseVal = DAG.getNode(ISD::OR, dl, VT, Tmp1, Tmp2); |
| 3432 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| 3433 | SDValue Cmp = getARMCmp(ExtraShAmt, DAG.getConstant(0, MVT::i32), ISD::SETGE, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3434 | ARMcc, DAG, dl); |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3435 | SDValue Lo = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ShAmt); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3436 | SDValue Hi = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, Tmp3, ARMcc, |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3437 | CCR, Cmp); |
| 3438 | |
| 3439 | SDValue Ops[2] = { Lo, Hi }; |
| 3440 | return DAG.getMergeValues(Ops, 2, dl); |
| 3441 | } |
| 3442 | |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 3443 | SDValue ARMTargetLowering::LowerFLT_ROUNDS_(SDValue Op, |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 3444 | SelectionDAG &DAG) const { |
| 3445 | // The rounding mode is in bits 23:22 of the FPSCR. |
| 3446 | // The ARM rounding mode value to FLT_ROUNDS mapping is 0->1, 1->2, 2->3, 3->0 |
| 3447 | // The formula we use to implement this is (((FPSCR + 1 << 22) >> 22) & 3) |
| 3448 | // so that the shift + and get folded into a bitfield extract. |
| 3449 | DebugLoc dl = Op.getDebugLoc(); |
| 3450 | SDValue FPSCR = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::i32, |
| 3451 | DAG.getConstant(Intrinsic::arm_get_fpscr, |
| 3452 | MVT::i32)); |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 3453 | SDValue FltRounds = DAG.getNode(ISD::ADD, dl, MVT::i32, FPSCR, |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 3454 | DAG.getConstant(1U << 22, MVT::i32)); |
| 3455 | SDValue RMODE = DAG.getNode(ISD::SRL, dl, MVT::i32, FltRounds, |
| 3456 | DAG.getConstant(22, MVT::i32)); |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 3457 | return DAG.getNode(ISD::AND, dl, MVT::i32, RMODE, |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 3458 | DAG.getConstant(3, MVT::i32)); |
| 3459 | } |
| 3460 | |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 3461 | static SDValue LowerCTTZ(SDNode *N, SelectionDAG &DAG, |
| 3462 | const ARMSubtarget *ST) { |
| 3463 | EVT VT = N->getValueType(0); |
| 3464 | DebugLoc dl = N->getDebugLoc(); |
| 3465 | |
| 3466 | if (!ST->hasV6T2Ops()) |
| 3467 | return SDValue(); |
| 3468 | |
| 3469 | SDValue rbit = DAG.getNode(ARMISD::RBIT, dl, VT, N->getOperand(0)); |
| 3470 | return DAG.getNode(ISD::CTLZ, dl, VT, rbit); |
| 3471 | } |
| 3472 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3473 | static SDValue LowerShift(SDNode *N, SelectionDAG &DAG, |
| 3474 | const ARMSubtarget *ST) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3475 | EVT VT = N->getValueType(0); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3476 | DebugLoc dl = N->getDebugLoc(); |
| 3477 | |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3478 | if (!VT.isVector()) |
| 3479 | return SDValue(); |
| 3480 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3481 | // Lower vector shifts on NEON to use VSHL. |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3482 | assert(ST->hasNEON() && "unexpected vector shift"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3483 | |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3484 | // Left shifts translate directly to the vshiftu intrinsic. |
| 3485 | if (N->getOpcode() == ISD::SHL) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3486 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT, |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3487 | DAG.getConstant(Intrinsic::arm_neon_vshiftu, MVT::i32), |
| 3488 | N->getOperand(0), N->getOperand(1)); |
| 3489 | |
| 3490 | assert((N->getOpcode() == ISD::SRA || |
| 3491 | N->getOpcode() == ISD::SRL) && "unexpected vector shift opcode"); |
| 3492 | |
| 3493 | // NEON uses the same intrinsics for both left and right shifts. For |
| 3494 | // right shifts, the shift amounts are negative, so negate the vector of |
| 3495 | // shift amounts. |
| 3496 | EVT ShiftVT = N->getOperand(1).getValueType(); |
| 3497 | SDValue NegatedCount = DAG.getNode(ISD::SUB, dl, ShiftVT, |
| 3498 | getZeroVector(ShiftVT, DAG, dl), |
| 3499 | N->getOperand(1)); |
| 3500 | Intrinsic::ID vshiftInt = (N->getOpcode() == ISD::SRA ? |
| 3501 | Intrinsic::arm_neon_vshifts : |
| 3502 | Intrinsic::arm_neon_vshiftu); |
| 3503 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT, |
| 3504 | DAG.getConstant(vshiftInt, MVT::i32), |
| 3505 | N->getOperand(0), NegatedCount); |
| 3506 | } |
| 3507 | |
| 3508 | static SDValue Expand64BitShift(SDNode *N, SelectionDAG &DAG, |
| 3509 | const ARMSubtarget *ST) { |
| 3510 | EVT VT = N->getValueType(0); |
| 3511 | DebugLoc dl = N->getDebugLoc(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3512 | |
Eli Friedman | ce392eb | 2009-08-22 03:13:10 +0000 | [diff] [blame] | 3513 | // We can get here for a node like i32 = ISD::SHL i32, i64 |
| 3514 | if (VT != MVT::i64) |
| 3515 | return SDValue(); |
| 3516 | |
| 3517 | assert((N->getOpcode() == ISD::SRL || N->getOpcode() == ISD::SRA) && |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3518 | "Unknown shift to lower!"); |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 3519 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3520 | // We only lower SRA, SRL of 1 here, all others use generic lowering. |
| 3521 | if (!isa<ConstantSDNode>(N->getOperand(1)) || |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 3522 | cast<ConstantSDNode>(N->getOperand(1))->getZExtValue() != 1) |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 3523 | return SDValue(); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3524 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3525 | // If we are in thumb mode, we don't have RRX. |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 3526 | if (ST->isThumb1Only()) return SDValue(); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3527 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3528 | // 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] | 3529 | SDValue Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, N->getOperand(0), |
Bob Wilson | ab3912e | 2010-05-25 03:36:52 +0000 | [diff] [blame] | 3530 | DAG.getConstant(0, MVT::i32)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3531 | SDValue Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, N->getOperand(0), |
Bob Wilson | ab3912e | 2010-05-25 03:36:52 +0000 | [diff] [blame] | 3532 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3533 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3534 | // First, build a SRA_FLAG/SRL_FLAG op, which shifts the top part by one and |
| 3535 | // captures the result into a carry flag. |
| 3536 | unsigned Opc = N->getOpcode() == ISD::SRL ? ARMISD::SRL_FLAG:ARMISD::SRA_FLAG; |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 3537 | Hi = DAG.getNode(Opc, dl, DAG.getVTList(MVT::i32, MVT::Glue), &Hi, 1); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3538 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3539 | // 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] | 3540 | Lo = DAG.getNode(ARMISD::RRX, dl, MVT::i32, Lo, Hi.getValue(1)); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3541 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3542 | // Merge the pieces into a single i64 value. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3543 | return DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Lo, Hi); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3544 | } |
| 3545 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3546 | static SDValue LowerVSETCC(SDValue Op, SelectionDAG &DAG) { |
| 3547 | SDValue TmpOp0, TmpOp1; |
| 3548 | bool Invert = false; |
| 3549 | bool Swap = false; |
| 3550 | unsigned Opc = 0; |
| 3551 | |
| 3552 | SDValue Op0 = Op.getOperand(0); |
| 3553 | SDValue Op1 = Op.getOperand(1); |
| 3554 | SDValue CC = Op.getOperand(2); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3555 | EVT VT = Op.getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3556 | ISD::CondCode SetCCOpcode = cast<CondCodeSDNode>(CC)->get(); |
| 3557 | DebugLoc dl = Op.getDebugLoc(); |
| 3558 | |
| 3559 | if (Op.getOperand(1).getValueType().isFloatingPoint()) { |
| 3560 | switch (SetCCOpcode) { |
David Blaikie | 4d6ccb5 | 2012-01-20 21:51:11 +0000 | [diff] [blame] | 3561 | default: llvm_unreachable("Illegal FP comparison"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3562 | case ISD::SETUNE: |
| 3563 | case ISD::SETNE: Invert = true; // Fallthrough |
| 3564 | case ISD::SETOEQ: |
| 3565 | case ISD::SETEQ: Opc = ARMISD::VCEQ; break; |
| 3566 | case ISD::SETOLT: |
| 3567 | case ISD::SETLT: Swap = true; // Fallthrough |
| 3568 | case ISD::SETOGT: |
| 3569 | case ISD::SETGT: Opc = ARMISD::VCGT; break; |
| 3570 | case ISD::SETOLE: |
| 3571 | case ISD::SETLE: Swap = true; // Fallthrough |
| 3572 | case ISD::SETOGE: |
| 3573 | case ISD::SETGE: Opc = ARMISD::VCGE; break; |
| 3574 | case ISD::SETUGE: Swap = true; // Fallthrough |
| 3575 | case ISD::SETULE: Invert = true; Opc = ARMISD::VCGT; break; |
| 3576 | case ISD::SETUGT: Swap = true; // Fallthrough |
| 3577 | case ISD::SETULT: Invert = true; Opc = ARMISD::VCGE; break; |
| 3578 | case ISD::SETUEQ: Invert = true; // Fallthrough |
| 3579 | case ISD::SETONE: |
| 3580 | // Expand this to (OLT | OGT). |
| 3581 | TmpOp0 = Op0; |
| 3582 | TmpOp1 = Op1; |
| 3583 | Opc = ISD::OR; |
| 3584 | Op0 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp1, TmpOp0); |
| 3585 | Op1 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp0, TmpOp1); |
| 3586 | break; |
| 3587 | case ISD::SETUO: Invert = true; // Fallthrough |
| 3588 | case ISD::SETO: |
| 3589 | // Expand this to (OLT | OGE). |
| 3590 | TmpOp0 = Op0; |
| 3591 | TmpOp1 = Op1; |
| 3592 | Opc = ISD::OR; |
| 3593 | Op0 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp1, TmpOp0); |
| 3594 | Op1 = DAG.getNode(ARMISD::VCGE, dl, VT, TmpOp0, TmpOp1); |
| 3595 | break; |
| 3596 | } |
| 3597 | } else { |
| 3598 | // Integer comparisons. |
| 3599 | switch (SetCCOpcode) { |
David Blaikie | 4d6ccb5 | 2012-01-20 21:51:11 +0000 | [diff] [blame] | 3600 | default: llvm_unreachable("Illegal integer comparison"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3601 | case ISD::SETNE: Invert = true; |
| 3602 | case ISD::SETEQ: Opc = ARMISD::VCEQ; break; |
| 3603 | case ISD::SETLT: Swap = true; |
| 3604 | case ISD::SETGT: Opc = ARMISD::VCGT; break; |
| 3605 | case ISD::SETLE: Swap = true; |
| 3606 | case ISD::SETGE: Opc = ARMISD::VCGE; break; |
| 3607 | case ISD::SETULT: Swap = true; |
| 3608 | case ISD::SETUGT: Opc = ARMISD::VCGTU; break; |
| 3609 | case ISD::SETULE: Swap = true; |
| 3610 | case ISD::SETUGE: Opc = ARMISD::VCGEU; break; |
| 3611 | } |
| 3612 | |
Nick Lewycky | 7f6aa2b | 2009-07-08 03:04:38 +0000 | [diff] [blame] | 3613 | // Detect VTST (Vector Test Bits) = icmp ne (and (op0, op1), zero). |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3614 | if (Opc == ARMISD::VCEQ) { |
| 3615 | |
| 3616 | SDValue AndOp; |
| 3617 | if (ISD::isBuildVectorAllZeros(Op1.getNode())) |
| 3618 | AndOp = Op0; |
| 3619 | else if (ISD::isBuildVectorAllZeros(Op0.getNode())) |
| 3620 | AndOp = Op1; |
| 3621 | |
| 3622 | // Ignore bitconvert. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3623 | if (AndOp.getNode() && AndOp.getOpcode() == ISD::BITCAST) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3624 | AndOp = AndOp.getOperand(0); |
| 3625 | |
| 3626 | if (AndOp.getNode() && AndOp.getOpcode() == ISD::AND) { |
| 3627 | Opc = ARMISD::VTST; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3628 | Op0 = DAG.getNode(ISD::BITCAST, dl, VT, AndOp.getOperand(0)); |
| 3629 | Op1 = DAG.getNode(ISD::BITCAST, dl, VT, AndOp.getOperand(1)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3630 | Invert = !Invert; |
| 3631 | } |
| 3632 | } |
| 3633 | } |
| 3634 | |
| 3635 | if (Swap) |
| 3636 | std::swap(Op0, Op1); |
| 3637 | |
Owen Anderson | c24cb35 | 2010-11-08 23:21:22 +0000 | [diff] [blame] | 3638 | // If one of the operands is a constant vector zero, attempt to fold the |
| 3639 | // comparison to a specialized compare-against-zero form. |
| 3640 | SDValue SingleOp; |
| 3641 | if (ISD::isBuildVectorAllZeros(Op1.getNode())) |
| 3642 | SingleOp = Op0; |
| 3643 | else if (ISD::isBuildVectorAllZeros(Op0.getNode())) { |
| 3644 | if (Opc == ARMISD::VCGE) |
| 3645 | Opc = ARMISD::VCLEZ; |
| 3646 | else if (Opc == ARMISD::VCGT) |
| 3647 | Opc = ARMISD::VCLTZ; |
| 3648 | SingleOp = Op1; |
| 3649 | } |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3650 | |
Owen Anderson | c24cb35 | 2010-11-08 23:21:22 +0000 | [diff] [blame] | 3651 | SDValue Result; |
| 3652 | if (SingleOp.getNode()) { |
| 3653 | switch (Opc) { |
| 3654 | case ARMISD::VCEQ: |
| 3655 | Result = DAG.getNode(ARMISD::VCEQZ, dl, VT, SingleOp); break; |
| 3656 | case ARMISD::VCGE: |
| 3657 | Result = DAG.getNode(ARMISD::VCGEZ, dl, VT, SingleOp); break; |
| 3658 | case ARMISD::VCLEZ: |
| 3659 | Result = DAG.getNode(ARMISD::VCLEZ, dl, VT, SingleOp); break; |
| 3660 | case ARMISD::VCGT: |
| 3661 | Result = DAG.getNode(ARMISD::VCGTZ, dl, VT, SingleOp); break; |
| 3662 | case ARMISD::VCLTZ: |
| 3663 | Result = DAG.getNode(ARMISD::VCLTZ, dl, VT, SingleOp); break; |
| 3664 | default: |
| 3665 | Result = DAG.getNode(Opc, dl, VT, Op0, Op1); |
| 3666 | } |
| 3667 | } else { |
| 3668 | Result = DAG.getNode(Opc, dl, VT, Op0, Op1); |
| 3669 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3670 | |
| 3671 | if (Invert) |
| 3672 | Result = DAG.getNOT(dl, Result, VT); |
| 3673 | |
| 3674 | return Result; |
| 3675 | } |
| 3676 | |
Lang Hames | 45b5f88 | 2012-03-15 18:49:02 +0000 | [diff] [blame] | 3677 | SDValue ARMTargetLowering::LowerConstantFP(SDValue Op, SelectionDAG &DAG, |
| 3678 | const ARMSubtarget *ST) const { |
| 3679 | if (!ST->useNEONForSinglePrecisionFP() || !ST->hasVFP3() || ST->hasD16()) |
| 3680 | return SDValue(); |
| 3681 | |
| 3682 | ConstantFPSDNode *CFP = cast<ConstantFPSDNode>(Op); |
| 3683 | assert(Op.getValueType() == MVT::f32 && |
| 3684 | "ConstantFP custom lowering should only occur for f32."); |
| 3685 | |
| 3686 | APFloat FPVal = CFP->getValueAPF(); |
| 3687 | int ImmVal = ARM_AM::getFP32Imm(FPVal); |
| 3688 | if (ImmVal == -1) |
| 3689 | return SDValue(); |
| 3690 | |
| 3691 | DebugLoc DL = Op.getDebugLoc(); |
| 3692 | SDValue NewVal = DAG.getTargetConstant(ImmVal, MVT::i32); |
| 3693 | SDValue VecConstant = DAG.getNode(ARMISD::VMOVFPIMM, DL, MVT::v2f32, NewVal); |
| 3694 | return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::f32, VecConstant, |
| 3695 | DAG.getConstant(0, MVT::i32)); |
| 3696 | } |
| 3697 | |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 3698 | /// isNEONModifiedImm - Check if the specified splat value corresponds to a |
| 3699 | /// valid vector constant for a NEON instruction with a "modified immediate" |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3700 | /// operand (e.g., VMOV). If so, return the encoded value. |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 3701 | static SDValue isNEONModifiedImm(uint64_t SplatBits, uint64_t SplatUndef, |
| 3702 | unsigned SplatBitSize, SelectionDAG &DAG, |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3703 | EVT &VT, bool is128Bits, NEONModImmType type) { |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3704 | unsigned OpCmode, Imm; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3705 | |
Bob Wilson | 827b210 | 2010-06-15 19:05:35 +0000 | [diff] [blame] | 3706 | // SplatBitSize is set to the smallest size that splats the vector, so a |
| 3707 | // zero vector will always have SplatBitSize == 8. However, NEON modified |
| 3708 | // immediate instructions others than VMOV do not support the 8-bit encoding |
| 3709 | // of a zero vector, and the default encoding of zero is supposed to be the |
| 3710 | // 32-bit version. |
| 3711 | if (SplatBits == 0) |
| 3712 | SplatBitSize = 32; |
| 3713 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3714 | switch (SplatBitSize) { |
| 3715 | case 8: |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3716 | if (type != VMOVModImm) |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 3717 | return SDValue(); |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3718 | // Any 1-byte value is OK. Op=0, Cmode=1110. |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3719 | assert((SplatBits & ~0xff) == 0 && "one byte splat value is too big"); |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3720 | OpCmode = 0xe; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3721 | Imm = SplatBits; |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3722 | VT = is128Bits ? MVT::v16i8 : MVT::v8i8; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3723 | break; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3724 | |
| 3725 | case 16: |
| 3726 | // NEON's 16-bit VMOV supports splat values where only one byte is nonzero. |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3727 | VT = is128Bits ? MVT::v8i16 : MVT::v4i16; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3728 | if ((SplatBits & ~0xff) == 0) { |
| 3729 | // Value = 0x00nn: Op=x, Cmode=100x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3730 | OpCmode = 0x8; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3731 | Imm = SplatBits; |
| 3732 | break; |
| 3733 | } |
| 3734 | if ((SplatBits & ~0xff00) == 0) { |
| 3735 | // Value = 0xnn00: Op=x, Cmode=101x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3736 | OpCmode = 0xa; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3737 | Imm = SplatBits >> 8; |
| 3738 | break; |
| 3739 | } |
| 3740 | return SDValue(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3741 | |
| 3742 | case 32: |
| 3743 | // NEON's 32-bit VMOV supports splat values where: |
| 3744 | // * only one byte is nonzero, or |
| 3745 | // * the least significant byte is 0xff and the second byte is nonzero, or |
| 3746 | // * the least significant 2 bytes are 0xff and the third is nonzero. |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3747 | VT = is128Bits ? MVT::v4i32 : MVT::v2i32; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3748 | if ((SplatBits & ~0xff) == 0) { |
| 3749 | // Value = 0x000000nn: Op=x, Cmode=000x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3750 | OpCmode = 0; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3751 | Imm = SplatBits; |
| 3752 | break; |
| 3753 | } |
| 3754 | if ((SplatBits & ~0xff00) == 0) { |
| 3755 | // Value = 0x0000nn00: Op=x, Cmode=001x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3756 | OpCmode = 0x2; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3757 | Imm = SplatBits >> 8; |
| 3758 | break; |
| 3759 | } |
| 3760 | if ((SplatBits & ~0xff0000) == 0) { |
| 3761 | // Value = 0x00nn0000: Op=x, Cmode=010x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3762 | OpCmode = 0x4; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3763 | Imm = SplatBits >> 16; |
| 3764 | break; |
| 3765 | } |
| 3766 | if ((SplatBits & ~0xff000000) == 0) { |
| 3767 | // Value = 0xnn000000: Op=x, Cmode=011x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3768 | OpCmode = 0x6; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3769 | Imm = SplatBits >> 24; |
| 3770 | break; |
| 3771 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3772 | |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3773 | // cmode == 0b1100 and cmode == 0b1101 are not supported for VORR or VBIC |
| 3774 | if (type == OtherModImm) return SDValue(); |
| 3775 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3776 | if ((SplatBits & ~0xffff) == 0 && |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3777 | ((SplatBits | SplatUndef) & 0xff) == 0xff) { |
| 3778 | // Value = 0x0000nnff: Op=x, Cmode=1100. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3779 | OpCmode = 0xc; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3780 | Imm = SplatBits >> 8; |
| 3781 | SplatBits |= 0xff; |
| 3782 | break; |
| 3783 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3784 | |
| 3785 | if ((SplatBits & ~0xffffff) == 0 && |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3786 | ((SplatBits | SplatUndef) & 0xffff) == 0xffff) { |
| 3787 | // Value = 0x00nnffff: Op=x, Cmode=1101. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3788 | OpCmode = 0xd; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3789 | Imm = SplatBits >> 16; |
| 3790 | SplatBits |= 0xffff; |
| 3791 | break; |
| 3792 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3793 | |
| 3794 | // Note: there are a few 32-bit splat values (specifically: 00ffff00, |
| 3795 | // ff000000, ff0000ff, and ffff00ff) that are valid for VMOV.I64 but not |
| 3796 | // VMOV.I32. A (very) minor optimization would be to replicate the value |
| 3797 | // and fall through here to test for a valid 64-bit splat. But, then the |
| 3798 | // caller would also need to check and handle the change in size. |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3799 | return SDValue(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3800 | |
| 3801 | case 64: { |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3802 | if (type != VMOVModImm) |
Bob Wilson | 827b210 | 2010-06-15 19:05:35 +0000 | [diff] [blame] | 3803 | return SDValue(); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 3804 | // NEON has a 64-bit VMOV splat where each byte is either 0 or 0xff. |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3805 | uint64_t BitMask = 0xff; |
| 3806 | uint64_t Val = 0; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3807 | unsigned ImmMask = 1; |
| 3808 | Imm = 0; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3809 | for (int ByteNum = 0; ByteNum < 8; ++ByteNum) { |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3810 | if (((SplatBits | SplatUndef) & BitMask) == BitMask) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3811 | Val |= BitMask; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3812 | Imm |= ImmMask; |
| 3813 | } else if ((SplatBits & BitMask) != 0) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3814 | return SDValue(); |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3815 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3816 | BitMask <<= 8; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3817 | ImmMask <<= 1; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3818 | } |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3819 | // Op=1, Cmode=1110. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3820 | OpCmode = 0x1e; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3821 | SplatBits = Val; |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3822 | VT = is128Bits ? MVT::v2i64 : MVT::v1i64; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3823 | break; |
| 3824 | } |
| 3825 | |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3826 | default: |
Bob Wilson | dc076da | 2010-06-19 05:32:09 +0000 | [diff] [blame] | 3827 | llvm_unreachable("unexpected size for isNEONModifiedImm"); |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3828 | } |
| 3829 | |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3830 | unsigned EncodedVal = ARM_AM::createNEONModImm(OpCmode, Imm); |
| 3831 | return DAG.getTargetConstant(EncodedVal, MVT::i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3832 | } |
| 3833 | |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 3834 | static bool isVEXTMask(ArrayRef<int> M, EVT VT, |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3835 | bool &ReverseVEXT, unsigned &Imm) { |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3836 | unsigned NumElts = VT.getVectorNumElements(); |
| 3837 | ReverseVEXT = false; |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3838 | |
| 3839 | // Assume that the first shuffle index is not UNDEF. Fail if it is. |
| 3840 | if (M[0] < 0) |
| 3841 | return false; |
| 3842 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3843 | Imm = M[0]; |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3844 | |
| 3845 | // If this is a VEXT shuffle, the immediate value is the index of the first |
| 3846 | // element. The other shuffle indices must be the successive elements after |
| 3847 | // the first one. |
| 3848 | unsigned ExpectedElt = Imm; |
| 3849 | for (unsigned i = 1; i < NumElts; ++i) { |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3850 | // Increment the expected index. If it wraps around, it may still be |
| 3851 | // a VEXT but the source vectors must be swapped. |
| 3852 | ExpectedElt += 1; |
| 3853 | if (ExpectedElt == NumElts * 2) { |
| 3854 | ExpectedElt = 0; |
| 3855 | ReverseVEXT = true; |
| 3856 | } |
| 3857 | |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3858 | if (M[i] < 0) continue; // ignore UNDEF indices |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3859 | if (ExpectedElt != static_cast<unsigned>(M[i])) |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3860 | return false; |
| 3861 | } |
| 3862 | |
| 3863 | // Adjust the index value if the source operands will be swapped. |
| 3864 | if (ReverseVEXT) |
| 3865 | Imm -= NumElts; |
| 3866 | |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3867 | return true; |
| 3868 | } |
| 3869 | |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 3870 | /// isVREVMask - Check if a vector shuffle corresponds to a VREV |
| 3871 | /// instruction with the specified blocksize. (The order of the elements |
| 3872 | /// within each block of the vector is reversed.) |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 3873 | static bool isVREVMask(ArrayRef<int> M, EVT VT, unsigned BlockSize) { |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 3874 | assert((BlockSize==16 || BlockSize==32 || BlockSize==64) && |
| 3875 | "Only possible block sizes for VREV are: 16, 32, 64"); |
| 3876 | |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 3877 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 3878 | if (EltSz == 64) |
| 3879 | return false; |
| 3880 | |
| 3881 | unsigned NumElts = VT.getVectorNumElements(); |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3882 | unsigned BlockElts = M[0] + 1; |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3883 | // If the first shuffle index is UNDEF, be optimistic. |
| 3884 | if (M[0] < 0) |
| 3885 | BlockElts = BlockSize / EltSz; |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 3886 | |
| 3887 | if (BlockSize <= EltSz || BlockSize != BlockElts * EltSz) |
| 3888 | return false; |
| 3889 | |
| 3890 | for (unsigned i = 0; i < NumElts; ++i) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3891 | if (M[i] < 0) continue; // ignore UNDEF indices |
| 3892 | if ((unsigned) M[i] != (i - i%BlockElts) + (BlockElts - 1 - i%BlockElts)) |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 3893 | return false; |
| 3894 | } |
| 3895 | |
| 3896 | return true; |
| 3897 | } |
| 3898 | |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 3899 | static bool isVTBLMask(ArrayRef<int> M, EVT VT) { |
Bill Wendling | 0d4c9d9 | 2011-03-15 21:15:20 +0000 | [diff] [blame] | 3900 | // We can handle <8 x i8> vector shuffles. If the index in the mask is out of |
| 3901 | // range, then 0 is placed into the resulting vector. So pretty much any mask |
| 3902 | // of 8 elements can work here. |
| 3903 | return VT == MVT::v8i8 && M.size() == 8; |
| 3904 | } |
| 3905 | |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 3906 | static bool isVTRNMask(ArrayRef<int> M, EVT VT, unsigned &WhichResult) { |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 3907 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3908 | if (EltSz == 64) |
| 3909 | return false; |
| 3910 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3911 | unsigned NumElts = VT.getVectorNumElements(); |
| 3912 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3913 | for (unsigned i = 0; i < NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3914 | if ((M[i] >= 0 && (unsigned) M[i] != i + WhichResult) || |
| 3915 | (M[i+1] >= 0 && (unsigned) M[i+1] != i + NumElts + WhichResult)) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3916 | return false; |
| 3917 | } |
| 3918 | return true; |
| 3919 | } |
| 3920 | |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3921 | /// isVTRN_v_undef_Mask - Special case of isVTRNMask for canonical form of |
| 3922 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 3923 | /// Mask is e.g., <0, 0, 2, 2> instead of <0, 4, 2, 6>. |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 3924 | static bool isVTRN_v_undef_Mask(ArrayRef<int> M, EVT VT, unsigned &WhichResult){ |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3925 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3926 | if (EltSz == 64) |
| 3927 | return false; |
| 3928 | |
| 3929 | unsigned NumElts = VT.getVectorNumElements(); |
| 3930 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3931 | for (unsigned i = 0; i < NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3932 | if ((M[i] >= 0 && (unsigned) M[i] != i + WhichResult) || |
| 3933 | (M[i+1] >= 0 && (unsigned) M[i+1] != i + WhichResult)) |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3934 | return false; |
| 3935 | } |
| 3936 | return true; |
| 3937 | } |
| 3938 | |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 3939 | static bool isVUZPMask(ArrayRef<int> M, EVT VT, unsigned &WhichResult) { |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 3940 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3941 | if (EltSz == 64) |
| 3942 | return false; |
| 3943 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3944 | unsigned NumElts = VT.getVectorNumElements(); |
| 3945 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3946 | for (unsigned i = 0; i != NumElts; ++i) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3947 | if (M[i] < 0) continue; // ignore UNDEF indices |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3948 | if ((unsigned) M[i] != 2 * i + WhichResult) |
| 3949 | return false; |
| 3950 | } |
| 3951 | |
| 3952 | // 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] | 3953 | if (VT.is64BitVector() && EltSz == 32) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3954 | return false; |
| 3955 | |
| 3956 | return true; |
| 3957 | } |
| 3958 | |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3959 | /// isVUZP_v_undef_Mask - Special case of isVUZPMask for canonical form of |
| 3960 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 3961 | /// Mask is e.g., <0, 2, 0, 2> instead of <0, 2, 4, 6>, |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 3962 | static bool isVUZP_v_undef_Mask(ArrayRef<int> M, EVT VT, unsigned &WhichResult){ |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3963 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3964 | if (EltSz == 64) |
| 3965 | return false; |
| 3966 | |
| 3967 | unsigned Half = VT.getVectorNumElements() / 2; |
| 3968 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3969 | for (unsigned j = 0; j != 2; ++j) { |
| 3970 | unsigned Idx = WhichResult; |
| 3971 | for (unsigned i = 0; i != Half; ++i) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3972 | int MIdx = M[i + j * Half]; |
| 3973 | if (MIdx >= 0 && (unsigned) MIdx != Idx) |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3974 | return false; |
| 3975 | Idx += 2; |
| 3976 | } |
| 3977 | } |
| 3978 | |
| 3979 | // VUZP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32. |
| 3980 | if (VT.is64BitVector() && EltSz == 32) |
| 3981 | return false; |
| 3982 | |
| 3983 | return true; |
| 3984 | } |
| 3985 | |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 3986 | static bool isVZIPMask(ArrayRef<int> M, EVT VT, unsigned &WhichResult) { |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 3987 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3988 | if (EltSz == 64) |
| 3989 | return false; |
| 3990 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3991 | unsigned NumElts = VT.getVectorNumElements(); |
| 3992 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3993 | unsigned Idx = WhichResult * NumElts / 2; |
| 3994 | for (unsigned i = 0; i != NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3995 | if ((M[i] >= 0 && (unsigned) M[i] != Idx) || |
| 3996 | (M[i+1] >= 0 && (unsigned) M[i+1] != Idx + NumElts)) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3997 | return false; |
| 3998 | Idx += 1; |
| 3999 | } |
| 4000 | |
| 4001 | // 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] | 4002 | if (VT.is64BitVector() && EltSz == 32) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4003 | return false; |
| 4004 | |
| 4005 | return true; |
| 4006 | } |
| 4007 | |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4008 | /// isVZIP_v_undef_Mask - Special case of isVZIPMask for canonical form of |
| 4009 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 4010 | /// Mask is e.g., <0, 0, 1, 1> instead of <0, 4, 1, 5>. |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4011 | static bool isVZIP_v_undef_Mask(ArrayRef<int> M, EVT VT, unsigned &WhichResult){ |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4012 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 4013 | if (EltSz == 64) |
| 4014 | return false; |
| 4015 | |
| 4016 | unsigned NumElts = VT.getVectorNumElements(); |
| 4017 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 4018 | unsigned Idx = WhichResult * NumElts / 2; |
| 4019 | for (unsigned i = 0; i != NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4020 | if ((M[i] >= 0 && (unsigned) M[i] != Idx) || |
| 4021 | (M[i+1] >= 0 && (unsigned) M[i+1] != Idx)) |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4022 | return false; |
| 4023 | Idx += 1; |
| 4024 | } |
| 4025 | |
| 4026 | // VZIP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32. |
| 4027 | if (VT.is64BitVector() && EltSz == 32) |
| 4028 | return false; |
| 4029 | |
| 4030 | return true; |
| 4031 | } |
| 4032 | |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 4033 | // If N is an integer constant that can be moved into a register in one |
| 4034 | // instruction, return an SDValue of such a constant (will become a MOV |
| 4035 | // instruction). Otherwise return null. |
| 4036 | static SDValue IsSingleInstrConstant(SDValue N, SelectionDAG &DAG, |
| 4037 | const ARMSubtarget *ST, DebugLoc dl) { |
| 4038 | uint64_t Val; |
| 4039 | if (!isa<ConstantSDNode>(N)) |
| 4040 | return SDValue(); |
| 4041 | Val = cast<ConstantSDNode>(N)->getZExtValue(); |
| 4042 | |
| 4043 | if (ST->isThumb1Only()) { |
| 4044 | if (Val <= 255 || ~Val <= 255) |
| 4045 | return DAG.getConstant(Val, MVT::i32); |
| 4046 | } else { |
| 4047 | if (ARM_AM::getSOImmVal(Val) != -1 || ARM_AM::getSOImmVal(~Val) != -1) |
| 4048 | return DAG.getConstant(Val, MVT::i32); |
| 4049 | } |
| 4050 | return SDValue(); |
| 4051 | } |
| 4052 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4053 | // If this is a case we can't handle, return null and let the default |
| 4054 | // expansion code take care of it. |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4055 | SDValue ARMTargetLowering::LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG, |
| 4056 | const ARMSubtarget *ST) const { |
Bob Wilson | d06791f | 2009-08-13 01:57:47 +0000 | [diff] [blame] | 4057 | BuildVectorSDNode *BVN = cast<BuildVectorSDNode>(Op.getNode()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4058 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4059 | EVT VT = Op.getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4060 | |
| 4061 | APInt SplatBits, SplatUndef; |
| 4062 | unsigned SplatBitSize; |
| 4063 | bool HasAnyUndefs; |
| 4064 | if (BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { |
Anton Korobeynikov | 71624cc | 2009-08-29 00:08:18 +0000 | [diff] [blame] | 4065 | if (SplatBitSize <= 64) { |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 4066 | // Check if an immediate VMOV works. |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4067 | EVT VmovVT; |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 4068 | SDValue Val = isNEONModifiedImm(SplatBits.getZExtValue(), |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4069 | SplatUndef.getZExtValue(), SplatBitSize, |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 4070 | DAG, VmovVT, VT.is128BitVector(), |
| 4071 | VMOVModImm); |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4072 | if (Val.getNode()) { |
| 4073 | SDValue Vmov = DAG.getNode(ARMISD::VMOVIMM, dl, VmovVT, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4074 | return DAG.getNode(ISD::BITCAST, dl, VT, Vmov); |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4075 | } |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 4076 | |
| 4077 | // Try an immediate VMVN. |
Eli Friedman | 8e4d042 | 2011-10-13 22:40:23 +0000 | [diff] [blame] | 4078 | uint64_t NegatedImm = (~SplatBits).getZExtValue(); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 4079 | Val = isNEONModifiedImm(NegatedImm, |
| 4080 | SplatUndef.getZExtValue(), SplatBitSize, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4081 | DAG, VmovVT, VT.is128BitVector(), |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 4082 | VMVNModImm); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 4083 | if (Val.getNode()) { |
| 4084 | SDValue Vmov = DAG.getNode(ARMISD::VMVNIMM, dl, VmovVT, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4085 | return DAG.getNode(ISD::BITCAST, dl, VT, Vmov); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 4086 | } |
Evan Cheng | eaa192a | 2011-11-15 02:12:34 +0000 | [diff] [blame] | 4087 | |
| 4088 | // Use vmov.f32 to materialize other v2f32 and v4f32 splats. |
Eli Friedman | 2f21e8c | 2011-12-15 22:56:53 +0000 | [diff] [blame] | 4089 | if ((VT == MVT::v2f32 || VT == MVT::v4f32) && SplatBitSize == 32) { |
Eli Friedman | effab8f | 2011-12-09 23:54:42 +0000 | [diff] [blame] | 4090 | int ImmVal = ARM_AM::getFP32Imm(SplatBits); |
Evan Cheng | eaa192a | 2011-11-15 02:12:34 +0000 | [diff] [blame] | 4091 | if (ImmVal != -1) { |
| 4092 | SDValue Val = DAG.getTargetConstant(ImmVal, MVT::i32); |
| 4093 | return DAG.getNode(ARMISD::VMOVFPIMM, dl, VT, Val); |
| 4094 | } |
| 4095 | } |
Anton Korobeynikov | 71624cc | 2009-08-29 00:08:18 +0000 | [diff] [blame] | 4096 | } |
Bob Wilson | cf661e2 | 2009-07-30 00:31:25 +0000 | [diff] [blame] | 4097 | } |
| 4098 | |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4099 | // Scan through the operands to see if only one value is used. |
| 4100 | unsigned NumElts = VT.getVectorNumElements(); |
| 4101 | bool isOnlyLowElement = true; |
| 4102 | bool usesOnlyOneValue = true; |
| 4103 | bool isConstant = true; |
| 4104 | SDValue Value; |
| 4105 | for (unsigned i = 0; i < NumElts; ++i) { |
| 4106 | SDValue V = Op.getOperand(i); |
| 4107 | if (V.getOpcode() == ISD::UNDEF) |
| 4108 | continue; |
| 4109 | if (i > 0) |
| 4110 | isOnlyLowElement = false; |
| 4111 | if (!isa<ConstantFPSDNode>(V) && !isa<ConstantSDNode>(V)) |
| 4112 | isConstant = false; |
| 4113 | |
| 4114 | if (!Value.getNode()) |
| 4115 | Value = V; |
| 4116 | else if (V != Value) |
| 4117 | usesOnlyOneValue = false; |
| 4118 | } |
| 4119 | |
| 4120 | if (!Value.getNode()) |
| 4121 | return DAG.getUNDEF(VT); |
| 4122 | |
| 4123 | if (isOnlyLowElement) |
| 4124 | return DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, VT, Value); |
| 4125 | |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 4126 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 4127 | |
Dale Johannesen | 575cd14 | 2010-10-19 20:00:17 +0000 | [diff] [blame] | 4128 | // Use VDUP for non-constant splats. For f32 constant splats, reduce to |
| 4129 | // i32 and try again. |
| 4130 | if (usesOnlyOneValue && EltSize <= 32) { |
| 4131 | if (!isConstant) |
| 4132 | return DAG.getNode(ARMISD::VDUP, dl, VT, Value); |
| 4133 | if (VT.getVectorElementType().isFloatingPoint()) { |
| 4134 | SmallVector<SDValue, 8> Ops; |
| 4135 | for (unsigned i = 0; i < NumElts; ++i) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4136 | Ops.push_back(DAG.getNode(ISD::BITCAST, dl, MVT::i32, |
Dale Johannesen | 575cd14 | 2010-10-19 20:00:17 +0000 | [diff] [blame] | 4137 | Op.getOperand(i))); |
Nate Begeman | bf5be26 | 2010-11-10 21:35:41 +0000 | [diff] [blame] | 4138 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), MVT::i32, NumElts); |
| 4139 | SDValue Val = DAG.getNode(ISD::BUILD_VECTOR, dl, VecVT, &Ops[0], NumElts); |
Dale Johannesen | e4d3159 | 2010-10-20 22:03:37 +0000 | [diff] [blame] | 4140 | Val = LowerBUILD_VECTOR(Val, DAG, ST); |
| 4141 | if (Val.getNode()) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4142 | return DAG.getNode(ISD::BITCAST, dl, VT, Val); |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 4143 | } |
Dale Johannesen | 575cd14 | 2010-10-19 20:00:17 +0000 | [diff] [blame] | 4144 | SDValue Val = IsSingleInstrConstant(Value, DAG, ST, dl); |
| 4145 | if (Val.getNode()) |
| 4146 | return DAG.getNode(ARMISD::VDUP, dl, VT, Val); |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 4147 | } |
| 4148 | |
| 4149 | // If all elements are constants and the case above didn't get hit, fall back |
| 4150 | // to the default expansion, which will generate a load from the constant |
| 4151 | // pool. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4152 | if (isConstant) |
| 4153 | return SDValue(); |
| 4154 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4155 | // Empirical tests suggest this is rarely worth it for vectors of length <= 2. |
| 4156 | if (NumElts >= 4) { |
| 4157 | SDValue shuffle = ReconstructShuffle(Op, DAG); |
| 4158 | if (shuffle != SDValue()) |
| 4159 | return shuffle; |
| 4160 | } |
| 4161 | |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4162 | // Vectors with 32- or 64-bit elements can be built by directly assigning |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4163 | // the subregisters. Lower it to an ARMISD::BUILD_VECTOR so the operands |
| 4164 | // will be legalized. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4165 | if (EltSize >= 32) { |
| 4166 | // Do the expansion with floating-point types, since that is what the VFP |
| 4167 | // registers are defined to use, and since i64 is not legal. |
| 4168 | EVT EltVT = EVT::getFloatingPointVT(EltSize); |
| 4169 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), EltVT, NumElts); |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4170 | SmallVector<SDValue, 8> Ops; |
| 4171 | for (unsigned i = 0; i < NumElts; ++i) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4172 | Ops.push_back(DAG.getNode(ISD::BITCAST, dl, EltVT, Op.getOperand(i))); |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4173 | SDValue Val = DAG.getNode(ARMISD::BUILD_VECTOR, dl, VecVT, &Ops[0],NumElts); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4174 | return DAG.getNode(ISD::BITCAST, dl, VT, Val); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4175 | } |
| 4176 | |
| 4177 | return SDValue(); |
| 4178 | } |
| 4179 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4180 | // Gather data to see if the operation can be modelled as a |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4181 | // shuffle in combination with VEXTs. |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4182 | SDValue ARMTargetLowering::ReconstructShuffle(SDValue Op, |
| 4183 | SelectionDAG &DAG) const { |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4184 | DebugLoc dl = Op.getDebugLoc(); |
| 4185 | EVT VT = Op.getValueType(); |
| 4186 | unsigned NumElts = VT.getVectorNumElements(); |
| 4187 | |
| 4188 | SmallVector<SDValue, 2> SourceVecs; |
| 4189 | SmallVector<unsigned, 2> MinElts; |
| 4190 | SmallVector<unsigned, 2> MaxElts; |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4191 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4192 | for (unsigned i = 0; i < NumElts; ++i) { |
| 4193 | SDValue V = Op.getOperand(i); |
| 4194 | if (V.getOpcode() == ISD::UNDEF) |
| 4195 | continue; |
| 4196 | else if (V.getOpcode() != ISD::EXTRACT_VECTOR_ELT) { |
| 4197 | // A shuffle can only come from building a vector from various |
| 4198 | // elements of other vectors. |
| 4199 | return SDValue(); |
Eli Friedman | 46995fa | 2011-10-14 23:58:49 +0000 | [diff] [blame] | 4200 | } else if (V.getOperand(0).getValueType().getVectorElementType() != |
| 4201 | VT.getVectorElementType()) { |
| 4202 | // This code doesn't know how to handle shuffles where the vector |
| 4203 | // element types do not match (this happens because type legalization |
| 4204 | // promotes the return type of EXTRACT_VECTOR_ELT). |
| 4205 | // FIXME: It might be appropriate to extend this code to handle |
| 4206 | // mismatched types. |
| 4207 | return SDValue(); |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4208 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4209 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4210 | // Record this extraction against the appropriate vector if possible... |
| 4211 | SDValue SourceVec = V.getOperand(0); |
| 4212 | unsigned EltNo = cast<ConstantSDNode>(V.getOperand(1))->getZExtValue(); |
| 4213 | bool FoundSource = false; |
| 4214 | for (unsigned j = 0; j < SourceVecs.size(); ++j) { |
| 4215 | if (SourceVecs[j] == SourceVec) { |
| 4216 | if (MinElts[j] > EltNo) |
| 4217 | MinElts[j] = EltNo; |
| 4218 | if (MaxElts[j] < EltNo) |
| 4219 | MaxElts[j] = EltNo; |
| 4220 | FoundSource = true; |
| 4221 | break; |
| 4222 | } |
| 4223 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4224 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4225 | // Or record a new source if not... |
| 4226 | if (!FoundSource) { |
| 4227 | SourceVecs.push_back(SourceVec); |
| 4228 | MinElts.push_back(EltNo); |
| 4229 | MaxElts.push_back(EltNo); |
| 4230 | } |
| 4231 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4232 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4233 | // Currently only do something sane when at most two source vectors |
| 4234 | // involved. |
| 4235 | if (SourceVecs.size() > 2) |
| 4236 | return SDValue(); |
| 4237 | |
| 4238 | SDValue ShuffleSrcs[2] = {DAG.getUNDEF(VT), DAG.getUNDEF(VT) }; |
| 4239 | int VEXTOffsets[2] = {0, 0}; |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4240 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4241 | // This loop extracts the usage patterns of the source vectors |
| 4242 | // and prepares appropriate SDValues for a shuffle if possible. |
| 4243 | for (unsigned i = 0; i < SourceVecs.size(); ++i) { |
| 4244 | if (SourceVecs[i].getValueType() == VT) { |
| 4245 | // No VEXT necessary |
| 4246 | ShuffleSrcs[i] = SourceVecs[i]; |
| 4247 | VEXTOffsets[i] = 0; |
| 4248 | continue; |
| 4249 | } else if (SourceVecs[i].getValueType().getVectorNumElements() < NumElts) { |
| 4250 | // It probably isn't worth padding out a smaller vector just to |
| 4251 | // break it down again in a shuffle. |
| 4252 | return SDValue(); |
| 4253 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4254 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4255 | // Since only 64-bit and 128-bit vectors are legal on ARM and |
| 4256 | // we've eliminated the other cases... |
Bob Wilson | 70f8573 | 2011-01-07 23:40:46 +0000 | [diff] [blame] | 4257 | assert(SourceVecs[i].getValueType().getVectorNumElements() == 2*NumElts && |
| 4258 | "unexpected vector sizes in ReconstructShuffle"); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4259 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4260 | if (MaxElts[i] - MinElts[i] >= NumElts) { |
| 4261 | // Span too large for a VEXT to cope |
| 4262 | return SDValue(); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4263 | } |
| 4264 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4265 | if (MinElts[i] >= NumElts) { |
| 4266 | // The extraction can just take the second half |
| 4267 | VEXTOffsets[i] = NumElts; |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4268 | ShuffleSrcs[i] = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 4269 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4270 | DAG.getIntPtrConstant(NumElts)); |
| 4271 | } else if (MaxElts[i] < NumElts) { |
| 4272 | // The extraction can just take the first half |
| 4273 | VEXTOffsets[i] = 0; |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4274 | ShuffleSrcs[i] = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 4275 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4276 | DAG.getIntPtrConstant(0)); |
| 4277 | } else { |
| 4278 | // An actual VEXT is needed |
| 4279 | VEXTOffsets[i] = MinElts[i]; |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4280 | SDValue VEXTSrc1 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 4281 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4282 | DAG.getIntPtrConstant(0)); |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4283 | SDValue VEXTSrc2 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 4284 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4285 | DAG.getIntPtrConstant(NumElts)); |
| 4286 | ShuffleSrcs[i] = DAG.getNode(ARMISD::VEXT, dl, VT, VEXTSrc1, VEXTSrc2, |
| 4287 | DAG.getConstant(VEXTOffsets[i], MVT::i32)); |
| 4288 | } |
| 4289 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4290 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4291 | SmallVector<int, 8> Mask; |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4292 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4293 | for (unsigned i = 0; i < NumElts; ++i) { |
| 4294 | SDValue Entry = Op.getOperand(i); |
| 4295 | if (Entry.getOpcode() == ISD::UNDEF) { |
| 4296 | Mask.push_back(-1); |
| 4297 | continue; |
| 4298 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4299 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4300 | SDValue ExtractVec = Entry.getOperand(0); |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4301 | int ExtractElt = cast<ConstantSDNode>(Op.getOperand(i) |
| 4302 | .getOperand(1))->getSExtValue(); |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4303 | if (ExtractVec == SourceVecs[0]) { |
| 4304 | Mask.push_back(ExtractElt - VEXTOffsets[0]); |
| 4305 | } else { |
| 4306 | Mask.push_back(ExtractElt + NumElts - VEXTOffsets[1]); |
| 4307 | } |
| 4308 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4309 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4310 | // Final check before we try to produce nonsense... |
| 4311 | if (isShuffleMaskLegal(Mask, VT)) |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4312 | return DAG.getVectorShuffle(VT, dl, ShuffleSrcs[0], ShuffleSrcs[1], |
| 4313 | &Mask[0]); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4314 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4315 | return SDValue(); |
| 4316 | } |
| 4317 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4318 | /// isShuffleMaskLegal - Targets can use this to indicate that they only |
| 4319 | /// support *some* VECTOR_SHUFFLE operations, those with specific masks. |
| 4320 | /// By default, if a target supports the VECTOR_SHUFFLE node, all mask values |
| 4321 | /// are assumed to be legal. |
| 4322 | bool |
| 4323 | ARMTargetLowering::isShuffleMaskLegal(const SmallVectorImpl<int> &M, |
| 4324 | EVT VT) const { |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4325 | if (VT.getVectorNumElements() == 4 && |
| 4326 | (VT.is128BitVector() || VT.is64BitVector())) { |
| 4327 | unsigned PFIndexes[4]; |
| 4328 | for (unsigned i = 0; i != 4; ++i) { |
| 4329 | if (M[i] < 0) |
| 4330 | PFIndexes[i] = 8; |
| 4331 | else |
| 4332 | PFIndexes[i] = M[i]; |
| 4333 | } |
| 4334 | |
| 4335 | // Compute the index in the perfect shuffle table. |
| 4336 | unsigned PFTableIndex = |
| 4337 | PFIndexes[0]*9*9*9+PFIndexes[1]*9*9+PFIndexes[2]*9+PFIndexes[3]; |
| 4338 | unsigned PFEntry = PerfectShuffleTable[PFTableIndex]; |
| 4339 | unsigned Cost = (PFEntry >> 30); |
| 4340 | |
| 4341 | if (Cost <= 4) |
| 4342 | return true; |
| 4343 | } |
| 4344 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4345 | bool ReverseVEXT; |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4346 | unsigned Imm, WhichResult; |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4347 | |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4348 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 4349 | return (EltSize >= 32 || |
| 4350 | ShuffleVectorSDNode::isSplatMask(&M[0], VT) || |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4351 | isVREVMask(M, VT, 64) || |
| 4352 | isVREVMask(M, VT, 32) || |
| 4353 | isVREVMask(M, VT, 16) || |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4354 | isVEXTMask(M, VT, ReverseVEXT, Imm) || |
Bill Wendling | 0d4c9d9 | 2011-03-15 21:15:20 +0000 | [diff] [blame] | 4355 | isVTBLMask(M, VT) || |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4356 | isVTRNMask(M, VT, WhichResult) || |
| 4357 | isVUZPMask(M, VT, WhichResult) || |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4358 | isVZIPMask(M, VT, WhichResult) || |
| 4359 | isVTRN_v_undef_Mask(M, VT, WhichResult) || |
| 4360 | isVUZP_v_undef_Mask(M, VT, WhichResult) || |
| 4361 | isVZIP_v_undef_Mask(M, VT, WhichResult)); |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4362 | } |
| 4363 | |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4364 | /// GeneratePerfectShuffle - Given an entry in the perfect-shuffle table, emit |
| 4365 | /// the specified operations to build the shuffle. |
| 4366 | static SDValue GeneratePerfectShuffle(unsigned PFEntry, SDValue LHS, |
| 4367 | SDValue RHS, SelectionDAG &DAG, |
| 4368 | DebugLoc dl) { |
| 4369 | unsigned OpNum = (PFEntry >> 26) & 0x0F; |
| 4370 | unsigned LHSID = (PFEntry >> 13) & ((1 << 13)-1); |
| 4371 | unsigned RHSID = (PFEntry >> 0) & ((1 << 13)-1); |
| 4372 | |
| 4373 | enum { |
| 4374 | OP_COPY = 0, // Copy, used for things like <u,u,u,3> to say it is <0,1,2,3> |
| 4375 | OP_VREV, |
| 4376 | OP_VDUP0, |
| 4377 | OP_VDUP1, |
| 4378 | OP_VDUP2, |
| 4379 | OP_VDUP3, |
| 4380 | OP_VEXT1, |
| 4381 | OP_VEXT2, |
| 4382 | OP_VEXT3, |
| 4383 | OP_VUZPL, // VUZP, left result |
| 4384 | OP_VUZPR, // VUZP, right result |
| 4385 | OP_VZIPL, // VZIP, left result |
| 4386 | OP_VZIPR, // VZIP, right result |
| 4387 | OP_VTRNL, // VTRN, left result |
| 4388 | OP_VTRNR // VTRN, right result |
| 4389 | }; |
| 4390 | |
| 4391 | if (OpNum == OP_COPY) { |
| 4392 | if (LHSID == (1*9+2)*9+3) return LHS; |
| 4393 | assert(LHSID == ((4*9+5)*9+6)*9+7 && "Illegal OP_COPY!"); |
| 4394 | return RHS; |
| 4395 | } |
| 4396 | |
| 4397 | SDValue OpLHS, OpRHS; |
| 4398 | OpLHS = GeneratePerfectShuffle(PerfectShuffleTable[LHSID], LHS, RHS, DAG, dl); |
| 4399 | OpRHS = GeneratePerfectShuffle(PerfectShuffleTable[RHSID], LHS, RHS, DAG, dl); |
| 4400 | EVT VT = OpLHS.getValueType(); |
| 4401 | |
| 4402 | switch (OpNum) { |
| 4403 | default: llvm_unreachable("Unknown shuffle opcode!"); |
| 4404 | case OP_VREV: |
Tanya Lattner | 2a8eb72 | 2011-05-18 06:42:21 +0000 | [diff] [blame] | 4405 | // VREV divides the vector in half and swaps within the half. |
Tanya Lattner | db28247 | 2011-05-18 21:44:54 +0000 | [diff] [blame] | 4406 | if (VT.getVectorElementType() == MVT::i32 || |
| 4407 | VT.getVectorElementType() == MVT::f32) |
Tanya Lattner | 2a8eb72 | 2011-05-18 06:42:21 +0000 | [diff] [blame] | 4408 | return DAG.getNode(ARMISD::VREV64, dl, VT, OpLHS); |
| 4409 | // vrev <4 x i16> -> VREV32 |
| 4410 | if (VT.getVectorElementType() == MVT::i16) |
| 4411 | return DAG.getNode(ARMISD::VREV32, dl, VT, OpLHS); |
| 4412 | // vrev <4 x i8> -> VREV16 |
| 4413 | assert(VT.getVectorElementType() == MVT::i8); |
| 4414 | return DAG.getNode(ARMISD::VREV16, dl, VT, OpLHS); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4415 | case OP_VDUP0: |
| 4416 | case OP_VDUP1: |
| 4417 | case OP_VDUP2: |
| 4418 | case OP_VDUP3: |
| 4419 | return DAG.getNode(ARMISD::VDUPLANE, dl, VT, |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 4420 | OpLHS, DAG.getConstant(OpNum-OP_VDUP0, MVT::i32)); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4421 | case OP_VEXT1: |
| 4422 | case OP_VEXT2: |
| 4423 | case OP_VEXT3: |
| 4424 | return DAG.getNode(ARMISD::VEXT, dl, VT, |
| 4425 | OpLHS, OpRHS, |
| 4426 | DAG.getConstant(OpNum-OP_VEXT1+1, MVT::i32)); |
| 4427 | case OP_VUZPL: |
| 4428 | case OP_VUZPR: |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 4429 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4430 | OpLHS, OpRHS).getValue(OpNum-OP_VUZPL); |
| 4431 | case OP_VZIPL: |
| 4432 | case OP_VZIPR: |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 4433 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4434 | OpLHS, OpRHS).getValue(OpNum-OP_VZIPL); |
| 4435 | case OP_VTRNL: |
| 4436 | case OP_VTRNR: |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 4437 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), |
| 4438 | OpLHS, OpRHS).getValue(OpNum-OP_VTRNL); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4439 | } |
| 4440 | } |
| 4441 | |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4442 | static SDValue LowerVECTOR_SHUFFLEv8i8(SDValue Op, |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4443 | ArrayRef<int> ShuffleMask, |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4444 | SelectionDAG &DAG) { |
| 4445 | // Check to see if we can use the VTBL instruction. |
| 4446 | SDValue V1 = Op.getOperand(0); |
| 4447 | SDValue V2 = Op.getOperand(1); |
| 4448 | DebugLoc DL = Op.getDebugLoc(); |
| 4449 | |
| 4450 | SmallVector<SDValue, 8> VTBLMask; |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4451 | for (ArrayRef<int>::iterator |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4452 | I = ShuffleMask.begin(), E = ShuffleMask.end(); I != E; ++I) |
| 4453 | VTBLMask.push_back(DAG.getConstant(*I, MVT::i32)); |
| 4454 | |
| 4455 | if (V2.getNode()->getOpcode() == ISD::UNDEF) |
| 4456 | return DAG.getNode(ARMISD::VTBL1, DL, MVT::v8i8, V1, |
| 4457 | DAG.getNode(ISD::BUILD_VECTOR, DL, MVT::v8i8, |
| 4458 | &VTBLMask[0], 8)); |
Bill Wendling | a24cb40 | 2011-03-15 20:47:26 +0000 | [diff] [blame] | 4459 | |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4460 | return DAG.getNode(ARMISD::VTBL2, DL, MVT::v8i8, V1, V2, |
Bill Wendling | a24cb40 | 2011-03-15 20:47:26 +0000 | [diff] [blame] | 4461 | DAG.getNode(ISD::BUILD_VECTOR, DL, MVT::v8i8, |
| 4462 | &VTBLMask[0], 8)); |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4463 | } |
| 4464 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4465 | static SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) { |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4466 | SDValue V1 = Op.getOperand(0); |
| 4467 | SDValue V2 = Op.getOperand(1); |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 4468 | DebugLoc dl = Op.getDebugLoc(); |
| 4469 | EVT VT = Op.getValueType(); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4470 | ShuffleVectorSDNode *SVN = cast<ShuffleVectorSDNode>(Op.getNode()); |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 4471 | |
Bob Wilson | 2886506 | 2009-08-13 02:13:04 +0000 | [diff] [blame] | 4472 | // Convert shuffles that are directly supported on NEON to target-specific |
| 4473 | // DAG nodes, instead of keeping them as shuffles and matching them again |
| 4474 | // during code selection. This is more efficient and avoids the possibility |
| 4475 | // of inconsistencies between legalization and selection. |
Bob Wilson | bfcbb50 | 2009-08-13 06:01:30 +0000 | [diff] [blame] | 4476 | // FIXME: floating-point vectors should be canonicalized to integer vectors |
| 4477 | // of the same time so that they get CSEd properly. |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4478 | ArrayRef<int> ShuffleMask = SVN->getMask(); |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4479 | |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4480 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 4481 | if (EltSize <= 32) { |
| 4482 | if (ShuffleVectorSDNode::isSplatMask(&ShuffleMask[0], VT)) { |
| 4483 | int Lane = SVN->getSplatIndex(); |
| 4484 | // If this is undef splat, generate it via "just" vdup, if possible. |
| 4485 | if (Lane == -1) Lane = 0; |
Anton Korobeynikov | 2ae0eec | 2009-11-02 00:12:06 +0000 | [diff] [blame] | 4486 | |
Dan Gohman | 65fd656 | 2011-11-03 21:49:52 +0000 | [diff] [blame] | 4487 | // Test if V1 is a SCALAR_TO_VECTOR. |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4488 | if (Lane == 0 && V1.getOpcode() == ISD::SCALAR_TO_VECTOR) { |
| 4489 | return DAG.getNode(ARMISD::VDUP, dl, VT, V1.getOperand(0)); |
| 4490 | } |
Dan Gohman | 65fd656 | 2011-11-03 21:49:52 +0000 | [diff] [blame] | 4491 | // Test if V1 is a BUILD_VECTOR which is equivalent to a SCALAR_TO_VECTOR |
| 4492 | // (and probably will turn into a SCALAR_TO_VECTOR once legalization |
| 4493 | // reaches it). |
| 4494 | if (Lane == 0 && V1.getOpcode() == ISD::BUILD_VECTOR && |
| 4495 | !isa<ConstantSDNode>(V1.getOperand(0))) { |
| 4496 | bool IsScalarToVector = true; |
| 4497 | for (unsigned i = 1, e = V1.getNumOperands(); i != e; ++i) |
| 4498 | if (V1.getOperand(i).getOpcode() != ISD::UNDEF) { |
| 4499 | IsScalarToVector = false; |
| 4500 | break; |
| 4501 | } |
| 4502 | if (IsScalarToVector) |
| 4503 | return DAG.getNode(ARMISD::VDUP, dl, VT, V1.getOperand(0)); |
| 4504 | } |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4505 | return DAG.getNode(ARMISD::VDUPLANE, dl, VT, V1, |
| 4506 | DAG.getConstant(Lane, MVT::i32)); |
Bob Wilson | c1d287b | 2009-08-14 05:13:08 +0000 | [diff] [blame] | 4507 | } |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4508 | |
| 4509 | bool ReverseVEXT; |
| 4510 | unsigned Imm; |
| 4511 | if (isVEXTMask(ShuffleMask, VT, ReverseVEXT, Imm)) { |
| 4512 | if (ReverseVEXT) |
| 4513 | std::swap(V1, V2); |
| 4514 | return DAG.getNode(ARMISD::VEXT, dl, VT, V1, V2, |
| 4515 | DAG.getConstant(Imm, MVT::i32)); |
| 4516 | } |
| 4517 | |
| 4518 | if (isVREVMask(ShuffleMask, VT, 64)) |
| 4519 | return DAG.getNode(ARMISD::VREV64, dl, VT, V1); |
| 4520 | if (isVREVMask(ShuffleMask, VT, 32)) |
| 4521 | return DAG.getNode(ARMISD::VREV32, dl, VT, V1); |
| 4522 | if (isVREVMask(ShuffleMask, VT, 16)) |
| 4523 | return DAG.getNode(ARMISD::VREV16, dl, VT, V1); |
| 4524 | |
| 4525 | // Check for Neon shuffles that modify both input vectors in place. |
| 4526 | // If both results are used, i.e., if there are two shuffles with the same |
| 4527 | // source operands and with masks corresponding to both results of one of |
| 4528 | // these operations, DAG memoization will ensure that a single node is |
| 4529 | // used for both shuffles. |
| 4530 | unsigned WhichResult; |
| 4531 | if (isVTRNMask(ShuffleMask, VT, WhichResult)) |
| 4532 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), |
| 4533 | V1, V2).getValue(WhichResult); |
| 4534 | if (isVUZPMask(ShuffleMask, VT, WhichResult)) |
| 4535 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), |
| 4536 | V1, V2).getValue(WhichResult); |
| 4537 | if (isVZIPMask(ShuffleMask, VT, WhichResult)) |
| 4538 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), |
| 4539 | V1, V2).getValue(WhichResult); |
| 4540 | |
| 4541 | if (isVTRN_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 4542 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), |
| 4543 | V1, V1).getValue(WhichResult); |
| 4544 | if (isVUZP_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 4545 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), |
| 4546 | V1, V1).getValue(WhichResult); |
| 4547 | if (isVZIP_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 4548 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), |
| 4549 | V1, V1).getValue(WhichResult); |
Bob Wilson | 0ce3710 | 2009-08-14 05:08:32 +0000 | [diff] [blame] | 4550 | } |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 4551 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4552 | // If the shuffle is not directly supported and it has 4 elements, use |
| 4553 | // the PerfectShuffle-generated table to synthesize it from other shuffles. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4554 | unsigned NumElts = VT.getVectorNumElements(); |
| 4555 | if (NumElts == 4) { |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4556 | unsigned PFIndexes[4]; |
| 4557 | for (unsigned i = 0; i != 4; ++i) { |
| 4558 | if (ShuffleMask[i] < 0) |
| 4559 | PFIndexes[i] = 8; |
| 4560 | else |
| 4561 | PFIndexes[i] = ShuffleMask[i]; |
| 4562 | } |
| 4563 | |
| 4564 | // Compute the index in the perfect shuffle table. |
| 4565 | unsigned PFTableIndex = |
| 4566 | PFIndexes[0]*9*9*9+PFIndexes[1]*9*9+PFIndexes[2]*9+PFIndexes[3]; |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4567 | unsigned PFEntry = PerfectShuffleTable[PFTableIndex]; |
| 4568 | unsigned Cost = (PFEntry >> 30); |
| 4569 | |
| 4570 | if (Cost <= 4) |
| 4571 | return GeneratePerfectShuffle(PFEntry, V1, V2, DAG, dl); |
| 4572 | } |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 4573 | |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4574 | // Implement shuffles with 32- or 64-bit elements as ARMISD::BUILD_VECTORs. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4575 | if (EltSize >= 32) { |
| 4576 | // Do the expansion with floating-point types, since that is what the VFP |
| 4577 | // registers are defined to use, and since i64 is not legal. |
| 4578 | EVT EltVT = EVT::getFloatingPointVT(EltSize); |
| 4579 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), EltVT, NumElts); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4580 | V1 = DAG.getNode(ISD::BITCAST, dl, VecVT, V1); |
| 4581 | V2 = DAG.getNode(ISD::BITCAST, dl, VecVT, V2); |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4582 | SmallVector<SDValue, 8> Ops; |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4583 | for (unsigned i = 0; i < NumElts; ++i) { |
Bob Wilson | 63b8845 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 4584 | if (ShuffleMask[i] < 0) |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4585 | Ops.push_back(DAG.getUNDEF(EltVT)); |
| 4586 | else |
| 4587 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, EltVT, |
| 4588 | ShuffleMask[i] < (int)NumElts ? V1 : V2, |
| 4589 | DAG.getConstant(ShuffleMask[i] & (NumElts-1), |
| 4590 | MVT::i32))); |
Bob Wilson | 63b8845 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 4591 | } |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4592 | SDValue Val = DAG.getNode(ARMISD::BUILD_VECTOR, dl, VecVT, &Ops[0],NumElts); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4593 | return DAG.getNode(ISD::BITCAST, dl, VT, Val); |
Bob Wilson | 63b8845 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 4594 | } |
| 4595 | |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4596 | if (VT == MVT::v8i8) { |
| 4597 | SDValue NewOp = LowerVECTOR_SHUFFLEv8i8(Op, ShuffleMask, DAG); |
| 4598 | if (NewOp.getNode()) |
| 4599 | return NewOp; |
| 4600 | } |
| 4601 | |
Bob Wilson | 22cac0d | 2009-08-14 05:16:33 +0000 | [diff] [blame] | 4602 | return SDValue(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4603 | } |
| 4604 | |
Eli Friedman | 5c89cb8 | 2011-10-24 23:08:52 +0000 | [diff] [blame] | 4605 | static SDValue LowerINSERT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) { |
| 4606 | // INSERT_VECTOR_ELT is legal only for immediate indexes. |
| 4607 | SDValue Lane = Op.getOperand(2); |
| 4608 | if (!isa<ConstantSDNode>(Lane)) |
| 4609 | return SDValue(); |
| 4610 | |
| 4611 | return Op; |
| 4612 | } |
| 4613 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4614 | static SDValue LowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) { |
Bob Wilson | 3468c2e | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 4615 | // EXTRACT_VECTOR_ELT is legal only for immediate indexes. |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4616 | SDValue Lane = Op.getOperand(1); |
Bob Wilson | 3468c2e | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 4617 | if (!isa<ConstantSDNode>(Lane)) |
| 4618 | return SDValue(); |
| 4619 | |
| 4620 | SDValue Vec = Op.getOperand(0); |
| 4621 | if (Op.getValueType() == MVT::i32 && |
| 4622 | Vec.getValueType().getVectorElementType().getSizeInBits() < 32) { |
| 4623 | DebugLoc dl = Op.getDebugLoc(); |
| 4624 | return DAG.getNode(ARMISD::VGETLANEu, dl, MVT::i32, Vec, Lane); |
| 4625 | } |
| 4626 | |
| 4627 | return Op; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4628 | } |
| 4629 | |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 4630 | static SDValue LowerCONCAT_VECTORS(SDValue Op, SelectionDAG &DAG) { |
| 4631 | // The only time a CONCAT_VECTORS operation can have legal types is when |
| 4632 | // two 64-bit vectors are concatenated to a 128-bit vector. |
| 4633 | assert(Op.getValueType().is128BitVector() && Op.getNumOperands() == 2 && |
| 4634 | "unexpected CONCAT_VECTORS"); |
| 4635 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4636 | SDValue Val = DAG.getUNDEF(MVT::v2f64); |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 4637 | SDValue Op0 = Op.getOperand(0); |
| 4638 | SDValue Op1 = Op.getOperand(1); |
| 4639 | if (Op0.getOpcode() != ISD::UNDEF) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4640 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Val, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4641 | DAG.getNode(ISD::BITCAST, dl, MVT::f64, Op0), |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 4642 | DAG.getIntPtrConstant(0)); |
| 4643 | if (Op1.getOpcode() != ISD::UNDEF) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4644 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Val, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4645 | DAG.getNode(ISD::BITCAST, dl, MVT::f64, Op1), |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 4646 | DAG.getIntPtrConstant(1)); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4647 | return DAG.getNode(ISD::BITCAST, dl, Op.getValueType(), Val); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4648 | } |
| 4649 | |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 4650 | /// isExtendedBUILD_VECTOR - Check if N is a constant BUILD_VECTOR where each |
| 4651 | /// element has been zero/sign-extended, depending on the isSigned parameter, |
| 4652 | /// from an integer type half its size. |
| 4653 | static bool isExtendedBUILD_VECTOR(SDNode *N, SelectionDAG &DAG, |
| 4654 | bool isSigned) { |
| 4655 | // A v2i64 BUILD_VECTOR will have been legalized to a BITCAST from v4i32. |
| 4656 | EVT VT = N->getValueType(0); |
| 4657 | if (VT == MVT::v2i64 && N->getOpcode() == ISD::BITCAST) { |
| 4658 | SDNode *BVN = N->getOperand(0).getNode(); |
| 4659 | if (BVN->getValueType(0) != MVT::v4i32 || |
| 4660 | BVN->getOpcode() != ISD::BUILD_VECTOR) |
| 4661 | return false; |
| 4662 | unsigned LoElt = DAG.getTargetLoweringInfo().isBigEndian() ? 1 : 0; |
| 4663 | unsigned HiElt = 1 - LoElt; |
| 4664 | ConstantSDNode *Lo0 = dyn_cast<ConstantSDNode>(BVN->getOperand(LoElt)); |
| 4665 | ConstantSDNode *Hi0 = dyn_cast<ConstantSDNode>(BVN->getOperand(HiElt)); |
| 4666 | ConstantSDNode *Lo1 = dyn_cast<ConstantSDNode>(BVN->getOperand(LoElt+2)); |
| 4667 | ConstantSDNode *Hi1 = dyn_cast<ConstantSDNode>(BVN->getOperand(HiElt+2)); |
| 4668 | if (!Lo0 || !Hi0 || !Lo1 || !Hi1) |
| 4669 | return false; |
| 4670 | if (isSigned) { |
| 4671 | if (Hi0->getSExtValue() == Lo0->getSExtValue() >> 32 && |
| 4672 | Hi1->getSExtValue() == Lo1->getSExtValue() >> 32) |
| 4673 | return true; |
| 4674 | } else { |
| 4675 | if (Hi0->isNullValue() && Hi1->isNullValue()) |
| 4676 | return true; |
| 4677 | } |
| 4678 | return false; |
| 4679 | } |
| 4680 | |
| 4681 | if (N->getOpcode() != ISD::BUILD_VECTOR) |
| 4682 | return false; |
| 4683 | |
| 4684 | for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) { |
| 4685 | SDNode *Elt = N->getOperand(i).getNode(); |
| 4686 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Elt)) { |
| 4687 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 4688 | unsigned HalfSize = EltSize / 2; |
| 4689 | if (isSigned) { |
Bob Wilson | 9d45de2 | 2011-10-18 18:46:49 +0000 | [diff] [blame] | 4690 | if (!isIntN(HalfSize, C->getSExtValue())) |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 4691 | return false; |
| 4692 | } else { |
Bob Wilson | 9d45de2 | 2011-10-18 18:46:49 +0000 | [diff] [blame] | 4693 | if (!isUIntN(HalfSize, C->getZExtValue())) |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 4694 | return false; |
| 4695 | } |
| 4696 | continue; |
| 4697 | } |
| 4698 | return false; |
| 4699 | } |
| 4700 | |
| 4701 | return true; |
| 4702 | } |
| 4703 | |
| 4704 | /// isSignExtended - Check if a node is a vector value that is sign-extended |
| 4705 | /// or a constant BUILD_VECTOR with sign-extended elements. |
| 4706 | static bool isSignExtended(SDNode *N, SelectionDAG &DAG) { |
| 4707 | if (N->getOpcode() == ISD::SIGN_EXTEND || ISD::isSEXTLoad(N)) |
| 4708 | return true; |
| 4709 | if (isExtendedBUILD_VECTOR(N, DAG, true)) |
| 4710 | return true; |
| 4711 | return false; |
| 4712 | } |
| 4713 | |
| 4714 | /// isZeroExtended - Check if a node is a vector value that is zero-extended |
| 4715 | /// or a constant BUILD_VECTOR with zero-extended elements. |
| 4716 | static bool isZeroExtended(SDNode *N, SelectionDAG &DAG) { |
| 4717 | if (N->getOpcode() == ISD::ZERO_EXTEND || ISD::isZEXTLoad(N)) |
| 4718 | return true; |
| 4719 | if (isExtendedBUILD_VECTOR(N, DAG, false)) |
| 4720 | return true; |
| 4721 | return false; |
| 4722 | } |
| 4723 | |
| 4724 | /// SkipExtension - For a node that is a SIGN_EXTEND, ZERO_EXTEND, extending |
| 4725 | /// load, or BUILD_VECTOR with extended elements, return the unextended value. |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4726 | static SDValue SkipExtension(SDNode *N, SelectionDAG &DAG) { |
| 4727 | if (N->getOpcode() == ISD::SIGN_EXTEND || N->getOpcode() == ISD::ZERO_EXTEND) |
| 4728 | return N->getOperand(0); |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 4729 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) |
| 4730 | return DAG.getLoad(LD->getMemoryVT(), N->getDebugLoc(), LD->getChain(), |
| 4731 | LD->getBasePtr(), LD->getPointerInfo(), LD->isVolatile(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 4732 | LD->isNonTemporal(), LD->isInvariant(), |
| 4733 | LD->getAlignment()); |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 4734 | // Otherwise, the value must be a BUILD_VECTOR. For v2i64, it will |
| 4735 | // have been legalized as a BITCAST from v4i32. |
| 4736 | if (N->getOpcode() == ISD::BITCAST) { |
| 4737 | SDNode *BVN = N->getOperand(0).getNode(); |
| 4738 | assert(BVN->getOpcode() == ISD::BUILD_VECTOR && |
| 4739 | BVN->getValueType(0) == MVT::v4i32 && "expected v4i32 BUILD_VECTOR"); |
| 4740 | unsigned LowElt = DAG.getTargetLoweringInfo().isBigEndian() ? 1 : 0; |
| 4741 | return DAG.getNode(ISD::BUILD_VECTOR, N->getDebugLoc(), MVT::v2i32, |
| 4742 | BVN->getOperand(LowElt), BVN->getOperand(LowElt+2)); |
| 4743 | } |
| 4744 | // Construct a new BUILD_VECTOR with elements truncated to half the size. |
| 4745 | assert(N->getOpcode() == ISD::BUILD_VECTOR && "expected BUILD_VECTOR"); |
| 4746 | EVT VT = N->getValueType(0); |
| 4747 | unsigned EltSize = VT.getVectorElementType().getSizeInBits() / 2; |
| 4748 | unsigned NumElts = VT.getVectorNumElements(); |
| 4749 | MVT TruncVT = MVT::getIntegerVT(EltSize); |
| 4750 | SmallVector<SDValue, 8> Ops; |
| 4751 | for (unsigned i = 0; i != NumElts; ++i) { |
| 4752 | ConstantSDNode *C = cast<ConstantSDNode>(N->getOperand(i)); |
| 4753 | const APInt &CInt = C->getAPIntValue(); |
Jay Foad | 40f8f62 | 2010-12-07 08:25:19 +0000 | [diff] [blame] | 4754 | Ops.push_back(DAG.getConstant(CInt.trunc(EltSize), TruncVT)); |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 4755 | } |
| 4756 | return DAG.getNode(ISD::BUILD_VECTOR, N->getDebugLoc(), |
| 4757 | MVT::getVectorVT(TruncVT, NumElts), Ops.data(), NumElts); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4758 | } |
| 4759 | |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 4760 | static bool isAddSubSExt(SDNode *N, SelectionDAG &DAG) { |
| 4761 | unsigned Opcode = N->getOpcode(); |
| 4762 | if (Opcode == ISD::ADD || Opcode == ISD::SUB) { |
| 4763 | SDNode *N0 = N->getOperand(0).getNode(); |
| 4764 | SDNode *N1 = N->getOperand(1).getNode(); |
| 4765 | return N0->hasOneUse() && N1->hasOneUse() && |
| 4766 | isSignExtended(N0, DAG) && isSignExtended(N1, DAG); |
| 4767 | } |
| 4768 | return false; |
| 4769 | } |
| 4770 | |
| 4771 | static bool isAddSubZExt(SDNode *N, SelectionDAG &DAG) { |
| 4772 | unsigned Opcode = N->getOpcode(); |
| 4773 | if (Opcode == ISD::ADD || Opcode == ISD::SUB) { |
| 4774 | SDNode *N0 = N->getOperand(0).getNode(); |
| 4775 | SDNode *N1 = N->getOperand(1).getNode(); |
| 4776 | return N0->hasOneUse() && N1->hasOneUse() && |
| 4777 | isZeroExtended(N0, DAG) && isZeroExtended(N1, DAG); |
| 4778 | } |
| 4779 | return false; |
| 4780 | } |
| 4781 | |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4782 | static SDValue LowerMUL(SDValue Op, SelectionDAG &DAG) { |
| 4783 | // Multiplications are only custom-lowered for 128-bit vectors so that |
| 4784 | // VMULL can be detected. Otherwise v2i64 multiplications are not legal. |
| 4785 | EVT VT = Op.getValueType(); |
| 4786 | assert(VT.is128BitVector() && "unexpected type for custom-lowering ISD::MUL"); |
| 4787 | SDNode *N0 = Op.getOperand(0).getNode(); |
| 4788 | SDNode *N1 = Op.getOperand(1).getNode(); |
| 4789 | unsigned NewOpc = 0; |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 4790 | bool isMLA = false; |
| 4791 | bool isN0SExt = isSignExtended(N0, DAG); |
| 4792 | bool isN1SExt = isSignExtended(N1, DAG); |
| 4793 | if (isN0SExt && isN1SExt) |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4794 | NewOpc = ARMISD::VMULLs; |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 4795 | else { |
| 4796 | bool isN0ZExt = isZeroExtended(N0, DAG); |
| 4797 | bool isN1ZExt = isZeroExtended(N1, DAG); |
| 4798 | if (isN0ZExt && isN1ZExt) |
| 4799 | NewOpc = ARMISD::VMULLu; |
| 4800 | else if (isN1SExt || isN1ZExt) { |
| 4801 | // Look for (s/zext A + s/zext B) * (s/zext C). We want to turn these |
| 4802 | // into (s/zext A * s/zext C) + (s/zext B * s/zext C) |
| 4803 | if (isN1SExt && isAddSubSExt(N0, DAG)) { |
| 4804 | NewOpc = ARMISD::VMULLs; |
| 4805 | isMLA = true; |
| 4806 | } else if (isN1ZExt && isAddSubZExt(N0, DAG)) { |
| 4807 | NewOpc = ARMISD::VMULLu; |
| 4808 | isMLA = true; |
| 4809 | } else if (isN0ZExt && isAddSubZExt(N1, DAG)) { |
| 4810 | std::swap(N0, N1); |
| 4811 | NewOpc = ARMISD::VMULLu; |
| 4812 | isMLA = true; |
| 4813 | } |
| 4814 | } |
| 4815 | |
| 4816 | if (!NewOpc) { |
| 4817 | if (VT == MVT::v2i64) |
| 4818 | // Fall through to expand this. It is not legal. |
| 4819 | return SDValue(); |
| 4820 | else |
| 4821 | // Other vector multiplications are legal. |
| 4822 | return Op; |
| 4823 | } |
| 4824 | } |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4825 | |
| 4826 | // Legalize to a VMULL instruction. |
| 4827 | DebugLoc DL = Op.getDebugLoc(); |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 4828 | SDValue Op0; |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4829 | SDValue Op1 = SkipExtension(N1, DAG); |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 4830 | if (!isMLA) { |
| 4831 | Op0 = SkipExtension(N0, DAG); |
| 4832 | assert(Op0.getValueType().is64BitVector() && |
| 4833 | Op1.getValueType().is64BitVector() && |
| 4834 | "unexpected types for extended operands to VMULL"); |
| 4835 | return DAG.getNode(NewOpc, DL, VT, Op0, Op1); |
| 4836 | } |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4837 | |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 4838 | // Optimizing (zext A + zext B) * C, to (VMULL A, C) + (VMULL B, C) during |
| 4839 | // isel lowering to take advantage of no-stall back to back vmul + vmla. |
| 4840 | // vmull q0, d4, d6 |
| 4841 | // vmlal q0, d5, d6 |
| 4842 | // is faster than |
| 4843 | // vaddl q0, d4, d5 |
| 4844 | // vmovl q1, d6 |
| 4845 | // vmul q0, q0, q1 |
| 4846 | SDValue N00 = SkipExtension(N0->getOperand(0).getNode(), DAG); |
| 4847 | SDValue N01 = SkipExtension(N0->getOperand(1).getNode(), DAG); |
| 4848 | EVT Op1VT = Op1.getValueType(); |
| 4849 | return DAG.getNode(N0->getOpcode(), DL, VT, |
| 4850 | DAG.getNode(NewOpc, DL, VT, |
| 4851 | DAG.getNode(ISD::BITCAST, DL, Op1VT, N00), Op1), |
| 4852 | DAG.getNode(NewOpc, DL, VT, |
| 4853 | DAG.getNode(ISD::BITCAST, DL, Op1VT, N01), Op1)); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4854 | } |
| 4855 | |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4856 | static SDValue |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4857 | LowerSDIV_v4i8(SDValue X, SDValue Y, DebugLoc dl, SelectionDAG &DAG) { |
| 4858 | // Convert to float |
| 4859 | // float4 xf = vcvt_f32_s32(vmovl_s16(a.lo)); |
| 4860 | // float4 yf = vcvt_f32_s32(vmovl_s16(b.lo)); |
| 4861 | X = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, X); |
| 4862 | Y = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, Y); |
| 4863 | X = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, X); |
| 4864 | Y = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, Y); |
| 4865 | // Get reciprocal estimate. |
| 4866 | // float4 recip = vrecpeq_f32(yf); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4867 | Y = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4868 | DAG.getConstant(Intrinsic::arm_neon_vrecpe, MVT::i32), Y); |
| 4869 | // Because char has a smaller range than uchar, we can actually get away |
| 4870 | // without any newton steps. This requires that we use a weird bias |
| 4871 | // of 0xb000, however (again, this has been exhaustively tested). |
| 4872 | // float4 result = as_float4(as_int4(xf*recip) + 0xb000); |
| 4873 | X = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, X, Y); |
| 4874 | X = DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, X); |
| 4875 | Y = DAG.getConstant(0xb000, MVT::i32); |
| 4876 | Y = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, Y, Y, Y, Y); |
| 4877 | X = DAG.getNode(ISD::ADD, dl, MVT::v4i32, X, Y); |
| 4878 | X = DAG.getNode(ISD::BITCAST, dl, MVT::v4f32, X); |
| 4879 | // Convert back to short. |
| 4880 | X = DAG.getNode(ISD::FP_TO_SINT, dl, MVT::v4i32, X); |
| 4881 | X = DAG.getNode(ISD::TRUNCATE, dl, MVT::v4i16, X); |
| 4882 | return X; |
| 4883 | } |
| 4884 | |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4885 | static SDValue |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4886 | LowerSDIV_v4i16(SDValue N0, SDValue N1, DebugLoc dl, SelectionDAG &DAG) { |
| 4887 | SDValue N2; |
| 4888 | // Convert to float. |
| 4889 | // float4 yf = vcvt_f32_s32(vmovl_s16(y)); |
| 4890 | // float4 xf = vcvt_f32_s32(vmovl_s16(x)); |
| 4891 | N0 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, N0); |
| 4892 | N1 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, N1); |
| 4893 | N0 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N0); |
| 4894 | N1 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4895 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4896 | // Use reciprocal estimate and one refinement step. |
| 4897 | // float4 recip = vrecpeq_f32(yf); |
| 4898 | // recip *= vrecpsq_f32(yf, recip); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4899 | N2 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4900 | DAG.getConstant(Intrinsic::arm_neon_vrecpe, MVT::i32), N1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4901 | N1 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4902 | DAG.getConstant(Intrinsic::arm_neon_vrecps, MVT::i32), |
| 4903 | N1, N2); |
| 4904 | N2 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N1, N2); |
| 4905 | // Because short has a smaller range than ushort, we can actually get away |
| 4906 | // with only a single newton step. This requires that we use a weird bias |
| 4907 | // of 89, however (again, this has been exhaustively tested). |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 4908 | // float4 result = as_float4(as_int4(xf*recip) + 0x89); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4909 | N0 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N0, N2); |
| 4910 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, N0); |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 4911 | N1 = DAG.getConstant(0x89, MVT::i32); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4912 | N1 = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, N1, N1, N1, N1); |
| 4913 | N0 = DAG.getNode(ISD::ADD, dl, MVT::v4i32, N0, N1); |
| 4914 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4f32, N0); |
| 4915 | // Convert back to integer and return. |
| 4916 | // return vmovn_s32(vcvt_s32_f32(result)); |
| 4917 | N0 = DAG.getNode(ISD::FP_TO_SINT, dl, MVT::v4i32, N0); |
| 4918 | N0 = DAG.getNode(ISD::TRUNCATE, dl, MVT::v4i16, N0); |
| 4919 | return N0; |
| 4920 | } |
| 4921 | |
| 4922 | static SDValue LowerSDIV(SDValue Op, SelectionDAG &DAG) { |
| 4923 | EVT VT = Op.getValueType(); |
| 4924 | assert((VT == MVT::v4i16 || VT == MVT::v8i8) && |
| 4925 | "unexpected type for custom-lowering ISD::SDIV"); |
| 4926 | |
| 4927 | DebugLoc dl = Op.getDebugLoc(); |
| 4928 | SDValue N0 = Op.getOperand(0); |
| 4929 | SDValue N1 = Op.getOperand(1); |
| 4930 | SDValue N2, N3; |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4931 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4932 | if (VT == MVT::v8i8) { |
| 4933 | N0 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v8i16, N0); |
| 4934 | N1 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v8i16, N1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4935 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4936 | N2 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| 4937 | DAG.getIntPtrConstant(4)); |
| 4938 | N3 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4939 | DAG.getIntPtrConstant(4)); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4940 | N0 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| 4941 | DAG.getIntPtrConstant(0)); |
| 4942 | N1 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
| 4943 | DAG.getIntPtrConstant(0)); |
| 4944 | |
| 4945 | N0 = LowerSDIV_v4i8(N0, N1, dl, DAG); // v4i16 |
| 4946 | N2 = LowerSDIV_v4i8(N2, N3, dl, DAG); // v4i16 |
| 4947 | |
| 4948 | N0 = DAG.getNode(ISD::CONCAT_VECTORS, dl, MVT::v8i16, N0, N2); |
| 4949 | N0 = LowerCONCAT_VECTORS(N0, DAG); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4950 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4951 | N0 = DAG.getNode(ISD::TRUNCATE, dl, MVT::v8i8, N0); |
| 4952 | return N0; |
| 4953 | } |
| 4954 | return LowerSDIV_v4i16(N0, N1, dl, DAG); |
| 4955 | } |
| 4956 | |
| 4957 | static SDValue LowerUDIV(SDValue Op, SelectionDAG &DAG) { |
| 4958 | EVT VT = Op.getValueType(); |
| 4959 | assert((VT == MVT::v4i16 || VT == MVT::v8i8) && |
| 4960 | "unexpected type for custom-lowering ISD::UDIV"); |
| 4961 | |
| 4962 | DebugLoc dl = Op.getDebugLoc(); |
| 4963 | SDValue N0 = Op.getOperand(0); |
| 4964 | SDValue N1 = Op.getOperand(1); |
| 4965 | SDValue N2, N3; |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4966 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4967 | if (VT == MVT::v8i8) { |
| 4968 | N0 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v8i16, N0); |
| 4969 | N1 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v8i16, N1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4970 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4971 | N2 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| 4972 | DAG.getIntPtrConstant(4)); |
| 4973 | N3 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4974 | DAG.getIntPtrConstant(4)); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4975 | N0 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| 4976 | DAG.getIntPtrConstant(0)); |
| 4977 | N1 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
| 4978 | DAG.getIntPtrConstant(0)); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4979 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4980 | N0 = LowerSDIV_v4i16(N0, N1, dl, DAG); // v4i16 |
| 4981 | N2 = LowerSDIV_v4i16(N2, N3, dl, DAG); // v4i16 |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4982 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4983 | N0 = DAG.getNode(ISD::CONCAT_VECTORS, dl, MVT::v8i16, N0, N2); |
| 4984 | N0 = LowerCONCAT_VECTORS(N0, DAG); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4985 | |
| 4986 | N0 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v8i8, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4987 | DAG.getConstant(Intrinsic::arm_neon_vqmovnsu, MVT::i32), |
| 4988 | N0); |
| 4989 | return N0; |
| 4990 | } |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4991 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4992 | // v4i16 sdiv ... Convert to float. |
| 4993 | // float4 yf = vcvt_f32_s32(vmovl_u16(y)); |
| 4994 | // float4 xf = vcvt_f32_s32(vmovl_u16(x)); |
| 4995 | N0 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v4i32, N0); |
| 4996 | N1 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v4i32, N1); |
| 4997 | N0 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N0); |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 4998 | SDValue BN1 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N1); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4999 | |
| 5000 | // Use reciprocal estimate and two refinement steps. |
| 5001 | // float4 recip = vrecpeq_f32(yf); |
| 5002 | // recip *= vrecpsq_f32(yf, recip); |
| 5003 | // recip *= vrecpsq_f32(yf, recip); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5004 | N2 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 5005 | DAG.getConstant(Intrinsic::arm_neon_vrecpe, MVT::i32), BN1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5006 | N1 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5007 | DAG.getConstant(Intrinsic::arm_neon_vrecps, MVT::i32), |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 5008 | BN1, N2); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5009 | N2 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N1, N2); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5010 | N1 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5011 | DAG.getConstant(Intrinsic::arm_neon_vrecps, MVT::i32), |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 5012 | BN1, N2); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5013 | N2 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N1, N2); |
| 5014 | // Simply multiplying by the reciprocal estimate can leave us a few ulps |
| 5015 | // too low, so we add 2 ulps (exhaustive testing shows that this is enough, |
| 5016 | // and that it will never cause us to return an answer too large). |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 5017 | // float4 result = as_float4(as_int4(xf*recip) + 2); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5018 | N0 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N0, N2); |
| 5019 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, N0); |
| 5020 | N1 = DAG.getConstant(2, MVT::i32); |
| 5021 | N1 = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, N1, N1, N1, N1); |
| 5022 | N0 = DAG.getNode(ISD::ADD, dl, MVT::v4i32, N0, N1); |
| 5023 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4f32, N0); |
| 5024 | // Convert back to integer and return. |
| 5025 | // return vmovn_u32(vcvt_s32_f32(result)); |
| 5026 | N0 = DAG.getNode(ISD::FP_TO_SINT, dl, MVT::v4i32, N0); |
| 5027 | N0 = DAG.getNode(ISD::TRUNCATE, dl, MVT::v4i16, N0); |
| 5028 | return N0; |
| 5029 | } |
| 5030 | |
Evan Cheng | 342e316 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 5031 | static SDValue LowerADDC_ADDE_SUBC_SUBE(SDValue Op, SelectionDAG &DAG) { |
| 5032 | EVT VT = Op.getNode()->getValueType(0); |
| 5033 | SDVTList VTs = DAG.getVTList(VT, MVT::i32); |
| 5034 | |
| 5035 | unsigned Opc; |
| 5036 | bool ExtraOp = false; |
| 5037 | switch (Op.getOpcode()) { |
Craig Topper | bc21981 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 5038 | default: llvm_unreachable("Invalid code"); |
Evan Cheng | 342e316 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 5039 | case ISD::ADDC: Opc = ARMISD::ADDC; break; |
| 5040 | case ISD::ADDE: Opc = ARMISD::ADDE; ExtraOp = true; break; |
| 5041 | case ISD::SUBC: Opc = ARMISD::SUBC; break; |
| 5042 | case ISD::SUBE: Opc = ARMISD::SUBE; ExtraOp = true; break; |
| 5043 | } |
| 5044 | |
| 5045 | if (!ExtraOp) |
| 5046 | return DAG.getNode(Opc, Op->getDebugLoc(), VTs, Op.getOperand(0), |
| 5047 | Op.getOperand(1)); |
| 5048 | return DAG.getNode(Opc, Op->getDebugLoc(), VTs, Op.getOperand(0), |
| 5049 | Op.getOperand(1), Op.getOperand(2)); |
| 5050 | } |
| 5051 | |
Eli Friedman | 74bf18c | 2011-09-15 22:26:18 +0000 | [diff] [blame] | 5052 | static SDValue LowerAtomicLoadStore(SDValue Op, SelectionDAG &DAG) { |
Eli Friedman | 7cc1566 | 2011-09-15 22:18:49 +0000 | [diff] [blame] | 5053 | // Monotonic load/store is legal for all targets |
| 5054 | if (cast<AtomicSDNode>(Op)->getOrdering() <= Monotonic) |
| 5055 | return Op; |
| 5056 | |
| 5057 | // Aquire/Release load/store is not legal for targets without a |
| 5058 | // dmb or equivalent available. |
| 5059 | return SDValue(); |
| 5060 | } |
| 5061 | |
| 5062 | |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5063 | static void |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5064 | ReplaceATOMIC_OP_64(SDNode *Node, SmallVectorImpl<SDValue>& Results, |
| 5065 | SelectionDAG &DAG, unsigned NewOp) { |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5066 | DebugLoc dl = Node->getDebugLoc(); |
Duncan Sands | 17001ce | 2011-10-18 12:44:00 +0000 | [diff] [blame] | 5067 | assert (Node->getValueType(0) == MVT::i64 && |
| 5068 | "Only know how to expand i64 atomics"); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5069 | |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5070 | SmallVector<SDValue, 6> Ops; |
| 5071 | Ops.push_back(Node->getOperand(0)); // Chain |
| 5072 | Ops.push_back(Node->getOperand(1)); // Ptr |
| 5073 | // Low part of Val1 |
| 5074 | Ops.push_back(DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, |
| 5075 | Node->getOperand(2), DAG.getIntPtrConstant(0))); |
| 5076 | // High part of Val1 |
| 5077 | Ops.push_back(DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, |
| 5078 | Node->getOperand(2), DAG.getIntPtrConstant(1))); |
Andrew Trick | 3af7a67 | 2011-09-20 03:06:13 +0000 | [diff] [blame] | 5079 | if (NewOp == ARMISD::ATOMCMPXCHG64_DAG) { |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5080 | // High part of Val1 |
| 5081 | Ops.push_back(DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, |
| 5082 | Node->getOperand(3), DAG.getIntPtrConstant(0))); |
| 5083 | // High part of Val2 |
| 5084 | Ops.push_back(DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, |
| 5085 | Node->getOperand(3), DAG.getIntPtrConstant(1))); |
| 5086 | } |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5087 | SDVTList Tys = DAG.getVTList(MVT::i32, MVT::i32, MVT::Other); |
| 5088 | SDValue Result = |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5089 | DAG.getMemIntrinsicNode(NewOp, dl, Tys, Ops.data(), Ops.size(), MVT::i64, |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5090 | cast<MemSDNode>(Node)->getMemOperand()); |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5091 | SDValue OpsF[] = { Result.getValue(0), Result.getValue(1) }; |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5092 | Results.push_back(DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, OpsF, 2)); |
| 5093 | Results.push_back(Result.getValue(2)); |
| 5094 | } |
| 5095 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 5096 | SDValue ARMTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5097 | switch (Op.getOpcode()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 5098 | default: llvm_unreachable("Don't know how to custom lower this!"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5099 | case ISD::ConstantPool: return LowerConstantPool(Op, DAG); |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 5100 | case ISD::BlockAddress: return LowerBlockAddress(Op, DAG); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 5101 | case ISD::GlobalAddress: |
| 5102 | return Subtarget->isTargetDarwin() ? LowerGlobalAddressDarwin(Op, DAG) : |
| 5103 | LowerGlobalAddressELF(Op, DAG); |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 5104 | case ISD::GlobalTLSAddress: return LowerGlobalTLSAddress(Op, DAG); |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 5105 | case ISD::SELECT: return LowerSELECT(Op, DAG); |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 5106 | case ISD::SELECT_CC: return LowerSELECT_CC(Op, DAG); |
| 5107 | case ISD::BR_CC: return LowerBR_CC(Op, DAG); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5108 | case ISD::BR_JT: return LowerBR_JT(Op, DAG); |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 5109 | case ISD::VASTART: return LowerVASTART(Op, DAG); |
Jim Grosbach | 7c03dbd | 2009-12-14 21:24:16 +0000 | [diff] [blame] | 5110 | case ISD::MEMBARRIER: return LowerMEMBARRIER(Op, DAG, Subtarget); |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 5111 | case ISD::ATOMIC_FENCE: return LowerATOMIC_FENCE(Op, DAG, Subtarget); |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 5112 | case ISD::PREFETCH: return LowerPREFETCH(Op, DAG, Subtarget); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 5113 | case ISD::SINT_TO_FP: |
| 5114 | case ISD::UINT_TO_FP: return LowerINT_TO_FP(Op, DAG); |
| 5115 | case ISD::FP_TO_SINT: |
| 5116 | case ISD::FP_TO_UINT: return LowerFP_TO_INT(Op, DAG); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5117 | case ISD::FCOPYSIGN: return LowerFCOPYSIGN(Op, DAG); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 5118 | case ISD::RETURNADDR: return LowerRETURNADDR(Op, DAG); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 5119 | case ISD::FRAMEADDR: return LowerFRAMEADDR(Op, DAG); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 5120 | case ISD::GLOBAL_OFFSET_TABLE: return LowerGLOBAL_OFFSET_TABLE(Op, DAG); |
Jim Grosbach | 23ff7cf | 2010-05-26 20:22:18 +0000 | [diff] [blame] | 5121 | case ISD::EH_SJLJ_SETJMP: return LowerEH_SJLJ_SETJMP(Op, DAG); |
Jim Grosbach | 5eb1951 | 2010-05-22 01:06:18 +0000 | [diff] [blame] | 5122 | case ISD::EH_SJLJ_LONGJMP: return LowerEH_SJLJ_LONGJMP(Op, DAG); |
Jim Grosbach | a87ded2 | 2010-02-08 23:22:00 +0000 | [diff] [blame] | 5123 | case ISD::INTRINSIC_WO_CHAIN: return LowerINTRINSIC_WO_CHAIN(Op, DAG, |
| 5124 | Subtarget); |
Evan Cheng | 21a6179 | 2011-03-14 18:02:30 +0000 | [diff] [blame] | 5125 | case ISD::BITCAST: return ExpandBITCAST(Op.getNode(), DAG); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5126 | case ISD::SHL: |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 5127 | case ISD::SRL: |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5128 | case ISD::SRA: return LowerShift(Op.getNode(), DAG, Subtarget); |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 5129 | case ISD::SHL_PARTS: return LowerShiftLeftParts(Op, DAG); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 5130 | case ISD::SRL_PARTS: |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 5131 | case ISD::SRA_PARTS: return LowerShiftRightParts(Op, DAG); |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 5132 | case ISD::CTTZ: return LowerCTTZ(Op.getNode(), DAG, Subtarget); |
Duncan Sands | 28b77e9 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 5133 | case ISD::SETCC: return LowerVSETCC(Op, DAG); |
Lang Hames | 45b5f88 | 2012-03-15 18:49:02 +0000 | [diff] [blame] | 5134 | case ISD::ConstantFP: return LowerConstantFP(Op, DAG, Subtarget); |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 5135 | case ISD::BUILD_VECTOR: return LowerBUILD_VECTOR(Op, DAG, Subtarget); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5136 | case ISD::VECTOR_SHUFFLE: return LowerVECTOR_SHUFFLE(Op, DAG); |
Eli Friedman | 5c89cb8 | 2011-10-24 23:08:52 +0000 | [diff] [blame] | 5137 | case ISD::INSERT_VECTOR_ELT: return LowerINSERT_VECTOR_ELT(Op, DAG); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5138 | case ISD::EXTRACT_VECTOR_ELT: return LowerEXTRACT_VECTOR_ELT(Op, DAG); |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 5139 | case ISD::CONCAT_VECTORS: return LowerCONCAT_VECTORS(Op, DAG); |
Bob Wilson | b31a11b | 2010-08-20 04:54:02 +0000 | [diff] [blame] | 5140 | case ISD::FLT_ROUNDS_: return LowerFLT_ROUNDS_(Op, DAG); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 5141 | case ISD::MUL: return LowerMUL(Op, DAG); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5142 | case ISD::SDIV: return LowerSDIV(Op, DAG); |
| 5143 | case ISD::UDIV: return LowerUDIV(Op, DAG); |
Evan Cheng | 342e316 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 5144 | case ISD::ADDC: |
| 5145 | case ISD::ADDE: |
| 5146 | case ISD::SUBC: |
| 5147 | case ISD::SUBE: return LowerADDC_ADDE_SUBC_SUBE(Op, DAG); |
Eli Friedman | 7cc1566 | 2011-09-15 22:18:49 +0000 | [diff] [blame] | 5148 | case ISD::ATOMIC_LOAD: |
Eli Friedman | 74bf18c | 2011-09-15 22:26:18 +0000 | [diff] [blame] | 5149 | case ISD::ATOMIC_STORE: return LowerAtomicLoadStore(Op, DAG); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5150 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5151 | } |
| 5152 | |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 5153 | /// ReplaceNodeResults - Replace the results of node with an illegal result |
| 5154 | /// type with new values built out of custom code. |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 5155 | void ARMTargetLowering::ReplaceNodeResults(SDNode *N, |
| 5156 | SmallVectorImpl<SDValue>&Results, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 5157 | SelectionDAG &DAG) const { |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 5158 | SDValue Res; |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 5159 | switch (N->getOpcode()) { |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 5160 | default: |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 5161 | llvm_unreachable("Don't know how to custom expand this!"); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5162 | case ISD::BITCAST: |
| 5163 | Res = ExpandBITCAST(N, DAG); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 5164 | break; |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 5165 | case ISD::SRL: |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 5166 | case ISD::SRA: |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 5167 | Res = Expand64BitShift(N, DAG, Subtarget); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 5168 | break; |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5169 | case ISD::ATOMIC_LOAD_ADD: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5170 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMADD64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5171 | return; |
| 5172 | case ISD::ATOMIC_LOAD_AND: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5173 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMAND64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5174 | return; |
| 5175 | case ISD::ATOMIC_LOAD_NAND: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5176 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMNAND64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5177 | return; |
| 5178 | case ISD::ATOMIC_LOAD_OR: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5179 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMOR64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5180 | return; |
| 5181 | case ISD::ATOMIC_LOAD_SUB: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5182 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMSUB64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5183 | return; |
| 5184 | case ISD::ATOMIC_LOAD_XOR: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5185 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMXOR64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5186 | return; |
| 5187 | case ISD::ATOMIC_SWAP: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5188 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMSWAP64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5189 | return; |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5190 | case ISD::ATOMIC_CMP_SWAP: |
| 5191 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMCMPXCHG64_DAG); |
| 5192 | return; |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 5193 | } |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 5194 | if (Res.getNode()) |
| 5195 | Results.push_back(Res); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 5196 | } |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 5197 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5198 | //===----------------------------------------------------------------------===// |
| 5199 | // ARM Scheduler Hooks |
| 5200 | //===----------------------------------------------------------------------===// |
| 5201 | |
| 5202 | MachineBasicBlock * |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 5203 | ARMTargetLowering::EmitAtomicCmpSwap(MachineInstr *MI, |
| 5204 | MachineBasicBlock *BB, |
| 5205 | unsigned Size) const { |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5206 | unsigned dest = MI->getOperand(0).getReg(); |
| 5207 | unsigned ptr = MI->getOperand(1).getReg(); |
| 5208 | unsigned oldval = MI->getOperand(2).getReg(); |
| 5209 | unsigned newval = MI->getOperand(3).getReg(); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5210 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 5211 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5212 | bool isThumb2 = Subtarget->isThumb2(); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5213 | |
Cameron Zwarich | 7d336c0 | 2011-05-18 02:20:07 +0000 | [diff] [blame] | 5214 | MachineRegisterInfo &MRI = BB->getParent()->getRegInfo(); |
| 5215 | unsigned scratch = |
Cameron Zwarich | 141ec63 | 2011-05-18 02:29:50 +0000 | [diff] [blame] | 5216 | MRI.createVirtualRegister(isThumb2 ? ARM::rGPRRegisterClass |
Cameron Zwarich | 7d336c0 | 2011-05-18 02:20:07 +0000 | [diff] [blame] | 5217 | : ARM::GPRRegisterClass); |
| 5218 | |
| 5219 | if (isThumb2) { |
Cameron Zwarich | 141ec63 | 2011-05-18 02:29:50 +0000 | [diff] [blame] | 5220 | MRI.constrainRegClass(dest, ARM::rGPRRegisterClass); |
| 5221 | MRI.constrainRegClass(oldval, ARM::rGPRRegisterClass); |
| 5222 | MRI.constrainRegClass(newval, ARM::rGPRRegisterClass); |
Cameron Zwarich | 7d336c0 | 2011-05-18 02:20:07 +0000 | [diff] [blame] | 5223 | } |
| 5224 | |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5225 | unsigned ldrOpc, strOpc; |
| 5226 | switch (Size) { |
| 5227 | default: llvm_unreachable("unsupported size for AtomicCmpSwap!"); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5228 | case 1: |
| 5229 | ldrOpc = isThumb2 ? ARM::t2LDREXB : ARM::LDREXB; |
Evan Cheng | aa26102 | 2011-02-07 18:50:47 +0000 | [diff] [blame] | 5230 | strOpc = isThumb2 ? ARM::t2STREXB : ARM::STREXB; |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5231 | break; |
| 5232 | case 2: |
| 5233 | ldrOpc = isThumb2 ? ARM::t2LDREXH : ARM::LDREXH; |
| 5234 | strOpc = isThumb2 ? ARM::t2STREXH : ARM::STREXH; |
| 5235 | break; |
| 5236 | case 4: |
| 5237 | ldrOpc = isThumb2 ? ARM::t2LDREX : ARM::LDREX; |
| 5238 | strOpc = isThumb2 ? ARM::t2STREX : ARM::STREX; |
| 5239 | break; |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5240 | } |
| 5241 | |
| 5242 | MachineFunction *MF = BB->getParent(); |
| 5243 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 5244 | MachineFunction::iterator It = BB; |
| 5245 | ++It; // insert the new blocks after the current block |
| 5246 | |
| 5247 | MachineBasicBlock *loop1MBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5248 | MachineBasicBlock *loop2MBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5249 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5250 | MF->insert(It, loop1MBB); |
| 5251 | MF->insert(It, loop2MBB); |
| 5252 | MF->insert(It, exitMBB); |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 5253 | |
| 5254 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 5255 | exitMBB->splice(exitMBB->begin(), BB, |
| 5256 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 5257 | BB->end()); |
| 5258 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5259 | |
| 5260 | // thisMBB: |
| 5261 | // ... |
| 5262 | // fallthrough --> loop1MBB |
| 5263 | BB->addSuccessor(loop1MBB); |
| 5264 | |
| 5265 | // loop1MBB: |
| 5266 | // ldrex dest, [ptr] |
| 5267 | // cmp dest, oldval |
| 5268 | // bne exitMBB |
| 5269 | BB = loop1MBB; |
Jim Grosbach | b6aed50 | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 5270 | MachineInstrBuilder MIB = BuildMI(BB, dl, TII->get(ldrOpc), dest).addReg(ptr); |
| 5271 | if (ldrOpc == ARM::t2LDREX) |
| 5272 | MIB.addImm(0); |
| 5273 | AddDefaultPred(MIB); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5274 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5275 | .addReg(dest).addReg(oldval)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5276 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 5277 | .addMBB(exitMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5278 | BB->addSuccessor(loop2MBB); |
| 5279 | BB->addSuccessor(exitMBB); |
| 5280 | |
| 5281 | // loop2MBB: |
| 5282 | // strex scratch, newval, [ptr] |
| 5283 | // cmp scratch, #0 |
| 5284 | // bne loop1MBB |
| 5285 | BB = loop2MBB; |
Jim Grosbach | b6aed50 | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 5286 | MIB = BuildMI(BB, dl, TII->get(strOpc), scratch).addReg(newval).addReg(ptr); |
| 5287 | if (strOpc == ARM::t2STREX) |
| 5288 | MIB.addImm(0); |
| 5289 | AddDefaultPred(MIB); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5290 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5291 | .addReg(scratch).addImm(0)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5292 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 5293 | .addMBB(loop1MBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5294 | BB->addSuccessor(loop1MBB); |
| 5295 | BB->addSuccessor(exitMBB); |
| 5296 | |
| 5297 | // exitMBB: |
| 5298 | // ... |
| 5299 | BB = exitMBB; |
Jim Grosbach | 5efaed3 | 2010-01-15 00:18:34 +0000 | [diff] [blame] | 5300 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 5301 | MI->eraseFromParent(); // The instruction is gone now. |
Jim Grosbach | 5efaed3 | 2010-01-15 00:18:34 +0000 | [diff] [blame] | 5302 | |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5303 | return BB; |
| 5304 | } |
| 5305 | |
| 5306 | MachineBasicBlock * |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 5307 | ARMTargetLowering::EmitAtomicBinary(MachineInstr *MI, MachineBasicBlock *BB, |
| 5308 | unsigned Size, unsigned BinOpcode) const { |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5309 | // This also handles ATOMIC_SWAP, indicated by BinOpcode==0. |
| 5310 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 5311 | |
| 5312 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
Jim Grosbach | 867bbbf | 2010-01-15 00:22:18 +0000 | [diff] [blame] | 5313 | MachineFunction *MF = BB->getParent(); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5314 | MachineFunction::iterator It = BB; |
| 5315 | ++It; |
| 5316 | |
| 5317 | unsigned dest = MI->getOperand(0).getReg(); |
| 5318 | unsigned ptr = MI->getOperand(1).getReg(); |
| 5319 | unsigned incr = MI->getOperand(2).getReg(); |
| 5320 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5321 | bool isThumb2 = Subtarget->isThumb2(); |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 5322 | |
| 5323 | MachineRegisterInfo &MRI = BB->getParent()->getRegInfo(); |
| 5324 | if (isThumb2) { |
| 5325 | MRI.constrainRegClass(dest, ARM::rGPRRegisterClass); |
| 5326 | MRI.constrainRegClass(ptr, ARM::rGPRRegisterClass); |
| 5327 | } |
| 5328 | |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5329 | unsigned ldrOpc, strOpc; |
| 5330 | switch (Size) { |
| 5331 | default: llvm_unreachable("unsupported size for AtomicCmpSwap!"); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5332 | case 1: |
| 5333 | ldrOpc = isThumb2 ? ARM::t2LDREXB : ARM::LDREXB; |
Jakob Stoklund Olesen | 15913c9 | 2010-01-13 19:54:39 +0000 | [diff] [blame] | 5334 | strOpc = isThumb2 ? ARM::t2STREXB : ARM::STREXB; |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5335 | break; |
| 5336 | case 2: |
| 5337 | ldrOpc = isThumb2 ? ARM::t2LDREXH : ARM::LDREXH; |
| 5338 | strOpc = isThumb2 ? ARM::t2STREXH : ARM::STREXH; |
| 5339 | break; |
| 5340 | case 4: |
| 5341 | ldrOpc = isThumb2 ? ARM::t2LDREX : ARM::LDREX; |
| 5342 | strOpc = isThumb2 ? ARM::t2STREX : ARM::STREX; |
| 5343 | break; |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5344 | } |
| 5345 | |
Jim Grosbach | 867bbbf | 2010-01-15 00:22:18 +0000 | [diff] [blame] | 5346 | MachineBasicBlock *loopMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5347 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5348 | MF->insert(It, loopMBB); |
| 5349 | MF->insert(It, exitMBB); |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 5350 | |
| 5351 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 5352 | exitMBB->splice(exitMBB->begin(), BB, |
| 5353 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 5354 | BB->end()); |
| 5355 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5356 | |
Craig Topper | 44d2382 | 2012-02-22 05:59:10 +0000 | [diff] [blame] | 5357 | const TargetRegisterClass *TRC = |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 5358 | isThumb2 ? ARM::tGPRRegisterClass : ARM::GPRRegisterClass; |
| 5359 | unsigned scratch = MRI.createVirtualRegister(TRC); |
| 5360 | unsigned scratch2 = (!BinOpcode) ? incr : MRI.createVirtualRegister(TRC); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5361 | |
| 5362 | // thisMBB: |
| 5363 | // ... |
| 5364 | // fallthrough --> loopMBB |
| 5365 | BB->addSuccessor(loopMBB); |
| 5366 | |
| 5367 | // loopMBB: |
| 5368 | // ldrex dest, ptr |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5369 | // <binop> scratch2, dest, incr |
| 5370 | // strex scratch, scratch2, ptr |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5371 | // cmp scratch, #0 |
| 5372 | // bne- loopMBB |
| 5373 | // fallthrough --> exitMBB |
| 5374 | BB = loopMBB; |
Jim Grosbach | b6aed50 | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 5375 | MachineInstrBuilder MIB = BuildMI(BB, dl, TII->get(ldrOpc), dest).addReg(ptr); |
| 5376 | if (ldrOpc == ARM::t2LDREX) |
| 5377 | MIB.addImm(0); |
| 5378 | AddDefaultPred(MIB); |
Jim Grosbach | c67b556 | 2009-12-15 00:12:35 +0000 | [diff] [blame] | 5379 | if (BinOpcode) { |
| 5380 | // operand order needs to go the other way for NAND |
| 5381 | if (BinOpcode == ARM::BICrr || BinOpcode == ARM::t2BICrr) |
| 5382 | AddDefaultPred(BuildMI(BB, dl, TII->get(BinOpcode), scratch2). |
| 5383 | addReg(incr).addReg(dest)).addReg(0); |
| 5384 | else |
| 5385 | AddDefaultPred(BuildMI(BB, dl, TII->get(BinOpcode), scratch2). |
| 5386 | addReg(dest).addReg(incr)).addReg(0); |
| 5387 | } |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5388 | |
Jim Grosbach | b6aed50 | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 5389 | MIB = BuildMI(BB, dl, TII->get(strOpc), scratch).addReg(scratch2).addReg(ptr); |
| 5390 | if (strOpc == ARM::t2STREX) |
| 5391 | MIB.addImm(0); |
| 5392 | AddDefaultPred(MIB); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5393 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5394 | .addReg(scratch).addImm(0)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5395 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 5396 | .addMBB(loopMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5397 | |
| 5398 | BB->addSuccessor(loopMBB); |
| 5399 | BB->addSuccessor(exitMBB); |
| 5400 | |
| 5401 | // exitMBB: |
| 5402 | // ... |
| 5403 | BB = exitMBB; |
Evan Cheng | 102ebf1 | 2009-12-21 19:53:39 +0000 | [diff] [blame] | 5404 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 5405 | MI->eraseFromParent(); // The instruction is gone now. |
Evan Cheng | 102ebf1 | 2009-12-21 19:53:39 +0000 | [diff] [blame] | 5406 | |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5407 | return BB; |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 5408 | } |
| 5409 | |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5410 | MachineBasicBlock * |
| 5411 | ARMTargetLowering::EmitAtomicBinaryMinMax(MachineInstr *MI, |
| 5412 | MachineBasicBlock *BB, |
| 5413 | unsigned Size, |
| 5414 | bool signExtend, |
| 5415 | ARMCC::CondCodes Cond) const { |
| 5416 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 5417 | |
| 5418 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 5419 | MachineFunction *MF = BB->getParent(); |
| 5420 | MachineFunction::iterator It = BB; |
| 5421 | ++It; |
| 5422 | |
| 5423 | unsigned dest = MI->getOperand(0).getReg(); |
| 5424 | unsigned ptr = MI->getOperand(1).getReg(); |
| 5425 | unsigned incr = MI->getOperand(2).getReg(); |
| 5426 | unsigned oldval = dest; |
| 5427 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5428 | bool isThumb2 = Subtarget->isThumb2(); |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 5429 | |
| 5430 | MachineRegisterInfo &MRI = BB->getParent()->getRegInfo(); |
| 5431 | if (isThumb2) { |
| 5432 | MRI.constrainRegClass(dest, ARM::rGPRRegisterClass); |
| 5433 | MRI.constrainRegClass(ptr, ARM::rGPRRegisterClass); |
| 5434 | } |
| 5435 | |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5436 | unsigned ldrOpc, strOpc, extendOpc; |
| 5437 | switch (Size) { |
| 5438 | default: llvm_unreachable("unsupported size for AtomicCmpSwap!"); |
| 5439 | case 1: |
| 5440 | ldrOpc = isThumb2 ? ARM::t2LDREXB : ARM::LDREXB; |
| 5441 | strOpc = isThumb2 ? ARM::t2STREXB : ARM::STREXB; |
Jim Grosbach | c5a8c86 | 2011-07-27 16:47:19 +0000 | [diff] [blame] | 5442 | extendOpc = isThumb2 ? ARM::t2SXTB : ARM::SXTB; |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5443 | break; |
| 5444 | case 2: |
| 5445 | ldrOpc = isThumb2 ? ARM::t2LDREXH : ARM::LDREXH; |
| 5446 | strOpc = isThumb2 ? ARM::t2STREXH : ARM::STREXH; |
Jim Grosbach | c5a8c86 | 2011-07-27 16:47:19 +0000 | [diff] [blame] | 5447 | extendOpc = isThumb2 ? ARM::t2SXTH : ARM::SXTH; |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5448 | break; |
| 5449 | case 4: |
| 5450 | ldrOpc = isThumb2 ? ARM::t2LDREX : ARM::LDREX; |
| 5451 | strOpc = isThumb2 ? ARM::t2STREX : ARM::STREX; |
| 5452 | extendOpc = 0; |
| 5453 | break; |
| 5454 | } |
| 5455 | |
| 5456 | MachineBasicBlock *loopMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5457 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5458 | MF->insert(It, loopMBB); |
| 5459 | MF->insert(It, exitMBB); |
| 5460 | |
| 5461 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 5462 | exitMBB->splice(exitMBB->begin(), BB, |
| 5463 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 5464 | BB->end()); |
| 5465 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
| 5466 | |
Craig Topper | 44d2382 | 2012-02-22 05:59:10 +0000 | [diff] [blame] | 5467 | const TargetRegisterClass *TRC = |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 5468 | isThumb2 ? ARM::tGPRRegisterClass : ARM::GPRRegisterClass; |
| 5469 | unsigned scratch = MRI.createVirtualRegister(TRC); |
| 5470 | unsigned scratch2 = MRI.createVirtualRegister(TRC); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5471 | |
| 5472 | // thisMBB: |
| 5473 | // ... |
| 5474 | // fallthrough --> loopMBB |
| 5475 | BB->addSuccessor(loopMBB); |
| 5476 | |
| 5477 | // loopMBB: |
| 5478 | // ldrex dest, ptr |
| 5479 | // (sign extend dest, if required) |
| 5480 | // cmp dest, incr |
| 5481 | // cmov.cond scratch2, dest, incr |
| 5482 | // strex scratch, scratch2, ptr |
| 5483 | // cmp scratch, #0 |
| 5484 | // bne- loopMBB |
| 5485 | // fallthrough --> exitMBB |
| 5486 | BB = loopMBB; |
Jim Grosbach | b6aed50 | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 5487 | MachineInstrBuilder MIB = BuildMI(BB, dl, TII->get(ldrOpc), dest).addReg(ptr); |
| 5488 | if (ldrOpc == ARM::t2LDREX) |
| 5489 | MIB.addImm(0); |
| 5490 | AddDefaultPred(MIB); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5491 | |
| 5492 | // Sign extend the value, if necessary. |
| 5493 | if (signExtend && extendOpc) { |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 5494 | oldval = MRI.createVirtualRegister(ARM::GPRRegisterClass); |
Jim Grosbach | c5a8c86 | 2011-07-27 16:47:19 +0000 | [diff] [blame] | 5495 | AddDefaultPred(BuildMI(BB, dl, TII->get(extendOpc), oldval) |
| 5496 | .addReg(dest) |
| 5497 | .addImm(0)); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5498 | } |
| 5499 | |
| 5500 | // Build compare and cmov instructions. |
| 5501 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
| 5502 | .addReg(oldval).addReg(incr)); |
| 5503 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2MOVCCr : ARM::MOVCCr), scratch2) |
| 5504 | .addReg(oldval).addReg(incr).addImm(Cond).addReg(ARM::CPSR); |
| 5505 | |
Jim Grosbach | b6aed50 | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 5506 | MIB = BuildMI(BB, dl, TII->get(strOpc), scratch).addReg(scratch2).addReg(ptr); |
| 5507 | if (strOpc == ARM::t2STREX) |
| 5508 | MIB.addImm(0); |
| 5509 | AddDefaultPred(MIB); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5510 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 5511 | .addReg(scratch).addImm(0)); |
| 5512 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 5513 | .addMBB(loopMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
| 5514 | |
| 5515 | BB->addSuccessor(loopMBB); |
| 5516 | BB->addSuccessor(exitMBB); |
| 5517 | |
| 5518 | // exitMBB: |
| 5519 | // ... |
| 5520 | BB = exitMBB; |
| 5521 | |
| 5522 | MI->eraseFromParent(); // The instruction is gone now. |
| 5523 | |
| 5524 | return BB; |
| 5525 | } |
| 5526 | |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5527 | MachineBasicBlock * |
| 5528 | ARMTargetLowering::EmitAtomicBinary64(MachineInstr *MI, MachineBasicBlock *BB, |
| 5529 | unsigned Op1, unsigned Op2, |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5530 | bool NeedsCarry, bool IsCmpxchg) const { |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5531 | // This also handles ATOMIC_SWAP, indicated by Op1==0. |
| 5532 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 5533 | |
| 5534 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 5535 | MachineFunction *MF = BB->getParent(); |
| 5536 | MachineFunction::iterator It = BB; |
| 5537 | ++It; |
| 5538 | |
| 5539 | unsigned destlo = MI->getOperand(0).getReg(); |
| 5540 | unsigned desthi = MI->getOperand(1).getReg(); |
| 5541 | unsigned ptr = MI->getOperand(2).getReg(); |
| 5542 | unsigned vallo = MI->getOperand(3).getReg(); |
| 5543 | unsigned valhi = MI->getOperand(4).getReg(); |
| 5544 | DebugLoc dl = MI->getDebugLoc(); |
| 5545 | bool isThumb2 = Subtarget->isThumb2(); |
| 5546 | |
| 5547 | MachineRegisterInfo &MRI = BB->getParent()->getRegInfo(); |
| 5548 | if (isThumb2) { |
| 5549 | MRI.constrainRegClass(destlo, ARM::rGPRRegisterClass); |
| 5550 | MRI.constrainRegClass(desthi, ARM::rGPRRegisterClass); |
| 5551 | MRI.constrainRegClass(ptr, ARM::rGPRRegisterClass); |
| 5552 | } |
| 5553 | |
| 5554 | unsigned ldrOpc = isThumb2 ? ARM::t2LDREXD : ARM::LDREXD; |
| 5555 | unsigned strOpc = isThumb2 ? ARM::t2STREXD : ARM::STREXD; |
| 5556 | |
| 5557 | MachineBasicBlock *loopMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
Eli Friedman | 7df496d | 2011-09-01 22:27:41 +0000 | [diff] [blame] | 5558 | MachineBasicBlock *contBB = 0, *cont2BB = 0; |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5559 | if (IsCmpxchg) { |
| 5560 | contBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5561 | cont2BB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5562 | } |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5563 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5564 | MF->insert(It, loopMBB); |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5565 | if (IsCmpxchg) { |
| 5566 | MF->insert(It, contBB); |
| 5567 | MF->insert(It, cont2BB); |
| 5568 | } |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5569 | MF->insert(It, exitMBB); |
| 5570 | |
| 5571 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 5572 | exitMBB->splice(exitMBB->begin(), BB, |
| 5573 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 5574 | BB->end()); |
| 5575 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
| 5576 | |
Craig Topper | 44d2382 | 2012-02-22 05:59:10 +0000 | [diff] [blame] | 5577 | const TargetRegisterClass *TRC = |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5578 | isThumb2 ? ARM::tGPRRegisterClass : ARM::GPRRegisterClass; |
| 5579 | unsigned storesuccess = MRI.createVirtualRegister(TRC); |
| 5580 | |
| 5581 | // thisMBB: |
| 5582 | // ... |
| 5583 | // fallthrough --> loopMBB |
| 5584 | BB->addSuccessor(loopMBB); |
| 5585 | |
| 5586 | // loopMBB: |
| 5587 | // ldrexd r2, r3, ptr |
| 5588 | // <binopa> r0, r2, incr |
| 5589 | // <binopb> r1, r3, incr |
| 5590 | // strexd storesuccess, r0, r1, ptr |
| 5591 | // cmp storesuccess, #0 |
| 5592 | // bne- loopMBB |
| 5593 | // fallthrough --> exitMBB |
| 5594 | // |
| 5595 | // Note that the registers are explicitly specified because there is not any |
| 5596 | // way to force the register allocator to allocate a register pair. |
| 5597 | // |
Andrew Trick | 3af7a67 | 2011-09-20 03:06:13 +0000 | [diff] [blame] | 5598 | // FIXME: The hardcoded registers are not necessary for Thumb2, but we |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5599 | // need to properly enforce the restriction that the two output registers |
| 5600 | // for ldrexd must be different. |
| 5601 | BB = loopMBB; |
| 5602 | // Load |
| 5603 | AddDefaultPred(BuildMI(BB, dl, TII->get(ldrOpc)) |
| 5604 | .addReg(ARM::R2, RegState::Define) |
| 5605 | .addReg(ARM::R3, RegState::Define).addReg(ptr)); |
| 5606 | // Copy r2/r3 into dest. (This copy will normally be coalesced.) |
| 5607 | BuildMI(BB, dl, TII->get(TargetOpcode::COPY), destlo).addReg(ARM::R2); |
| 5608 | BuildMI(BB, dl, TII->get(TargetOpcode::COPY), desthi).addReg(ARM::R3); |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5609 | |
| 5610 | if (IsCmpxchg) { |
| 5611 | // Add early exit |
| 5612 | for (unsigned i = 0; i < 2; i++) { |
| 5613 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPrr : |
| 5614 | ARM::CMPrr)) |
| 5615 | .addReg(i == 0 ? destlo : desthi) |
| 5616 | .addReg(i == 0 ? vallo : valhi)); |
| 5617 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 5618 | .addMBB(exitMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
| 5619 | BB->addSuccessor(exitMBB); |
| 5620 | BB->addSuccessor(i == 0 ? contBB : cont2BB); |
| 5621 | BB = (i == 0 ? contBB : cont2BB); |
| 5622 | } |
| 5623 | |
| 5624 | // Copy to physregs for strexd |
| 5625 | unsigned setlo = MI->getOperand(5).getReg(); |
| 5626 | unsigned sethi = MI->getOperand(6).getReg(); |
| 5627 | BuildMI(BB, dl, TII->get(TargetOpcode::COPY), ARM::R0).addReg(setlo); |
| 5628 | BuildMI(BB, dl, TII->get(TargetOpcode::COPY), ARM::R1).addReg(sethi); |
| 5629 | } else if (Op1) { |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5630 | // Perform binary operation |
| 5631 | AddDefaultPred(BuildMI(BB, dl, TII->get(Op1), ARM::R0) |
| 5632 | .addReg(destlo).addReg(vallo)) |
| 5633 | .addReg(NeedsCarry ? ARM::CPSR : 0, getDefRegState(NeedsCarry)); |
| 5634 | AddDefaultPred(BuildMI(BB, dl, TII->get(Op2), ARM::R1) |
| 5635 | .addReg(desthi).addReg(valhi)).addReg(0); |
| 5636 | } else { |
| 5637 | // Copy to physregs for strexd |
| 5638 | BuildMI(BB, dl, TII->get(TargetOpcode::COPY), ARM::R0).addReg(vallo); |
| 5639 | BuildMI(BB, dl, TII->get(TargetOpcode::COPY), ARM::R1).addReg(valhi); |
| 5640 | } |
| 5641 | |
| 5642 | // Store |
| 5643 | AddDefaultPred(BuildMI(BB, dl, TII->get(strOpc), storesuccess) |
| 5644 | .addReg(ARM::R0).addReg(ARM::R1).addReg(ptr)); |
| 5645 | // Cmp+jump |
| 5646 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 5647 | .addReg(storesuccess).addImm(0)); |
| 5648 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 5649 | .addMBB(loopMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
| 5650 | |
| 5651 | BB->addSuccessor(loopMBB); |
| 5652 | BB->addSuccessor(exitMBB); |
| 5653 | |
| 5654 | // exitMBB: |
| 5655 | // ... |
| 5656 | BB = exitMBB; |
| 5657 | |
| 5658 | MI->eraseFromParent(); // The instruction is gone now. |
| 5659 | |
| 5660 | return BB; |
| 5661 | } |
| 5662 | |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 5663 | /// SetupEntryBlockForSjLj - Insert code into the entry block that creates and |
| 5664 | /// registers the function context. |
| 5665 | void ARMTargetLowering:: |
| 5666 | SetupEntryBlockForSjLj(MachineInstr *MI, MachineBasicBlock *MBB, |
| 5667 | MachineBasicBlock *DispatchBB, int FI) const { |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 5668 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 5669 | DebugLoc dl = MI->getDebugLoc(); |
| 5670 | MachineFunction *MF = MBB->getParent(); |
| 5671 | MachineRegisterInfo *MRI = &MF->getRegInfo(); |
| 5672 | MachineConstantPool *MCP = MF->getConstantPool(); |
| 5673 | ARMFunctionInfo *AFI = MF->getInfo<ARMFunctionInfo>(); |
| 5674 | const Function *F = MF->getFunction(); |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 5675 | |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 5676 | bool isThumb = Subtarget->isThumb(); |
Bill Wendling | ff4216a | 2011-10-03 22:44:15 +0000 | [diff] [blame] | 5677 | bool isThumb2 = Subtarget->isThumb2(); |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 5678 | |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 5679 | unsigned PCLabelId = AFI->createPICLabelUId(); |
Bill Wendling | ff4216a | 2011-10-03 22:44:15 +0000 | [diff] [blame] | 5680 | unsigned PCAdj = (isThumb || isThumb2) ? 4 : 8; |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 5681 | ARMConstantPoolValue *CPV = |
| 5682 | ARMConstantPoolMBB::Create(F->getContext(), DispatchBB, PCLabelId, PCAdj); |
| 5683 | unsigned CPI = MCP->getConstantPoolIndex(CPV, 4); |
| 5684 | |
| 5685 | const TargetRegisterClass *TRC = |
| 5686 | isThumb ? ARM::tGPRRegisterClass : ARM::GPRRegisterClass; |
| 5687 | |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 5688 | // Grab constant pool and fixed stack memory operands. |
| 5689 | MachineMemOperand *CPMMO = |
| 5690 | MF->getMachineMemOperand(MachinePointerInfo::getConstantPool(), |
| 5691 | MachineMemOperand::MOLoad, 4, 4); |
| 5692 | |
| 5693 | MachineMemOperand *FIMMOSt = |
| 5694 | MF->getMachineMemOperand(MachinePointerInfo::getFixedStack(FI), |
| 5695 | MachineMemOperand::MOStore, 4, 4); |
| 5696 | |
| 5697 | // Load the address of the dispatch MBB into the jump buffer. |
| 5698 | if (isThumb2) { |
| 5699 | // Incoming value: jbuf |
| 5700 | // ldr.n r5, LCPI1_1 |
| 5701 | // orr r5, r5, #1 |
| 5702 | // add r5, pc |
| 5703 | // str r5, [$jbuf, #+4] ; &jbuf[1] |
| 5704 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 5705 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::t2LDRpci), NewVReg1) |
| 5706 | .addConstantPoolIndex(CPI) |
| 5707 | .addMemOperand(CPMMO)); |
| 5708 | // Set the low bit because of thumb mode. |
| 5709 | unsigned NewVReg2 = MRI->createVirtualRegister(TRC); |
| 5710 | AddDefaultCC( |
| 5711 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::t2ORRri), NewVReg2) |
| 5712 | .addReg(NewVReg1, RegState::Kill) |
| 5713 | .addImm(0x01))); |
| 5714 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
| 5715 | BuildMI(*MBB, MI, dl, TII->get(ARM::tPICADD), NewVReg3) |
| 5716 | .addReg(NewVReg2, RegState::Kill) |
| 5717 | .addImm(PCLabelId); |
| 5718 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::t2STRi12)) |
| 5719 | .addReg(NewVReg3, RegState::Kill) |
| 5720 | .addFrameIndex(FI) |
| 5721 | .addImm(36) // &jbuf[1] :: pc |
| 5722 | .addMemOperand(FIMMOSt)); |
| 5723 | } else if (isThumb) { |
| 5724 | // Incoming value: jbuf |
| 5725 | // ldr.n r1, LCPI1_4 |
| 5726 | // add r1, pc |
| 5727 | // mov r2, #1 |
| 5728 | // orrs r1, r2 |
| 5729 | // add r2, $jbuf, #+4 ; &jbuf[1] |
| 5730 | // str r1, [r2] |
| 5731 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 5732 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tLDRpci), NewVReg1) |
| 5733 | .addConstantPoolIndex(CPI) |
| 5734 | .addMemOperand(CPMMO)); |
| 5735 | unsigned NewVReg2 = MRI->createVirtualRegister(TRC); |
| 5736 | BuildMI(*MBB, MI, dl, TII->get(ARM::tPICADD), NewVReg2) |
| 5737 | .addReg(NewVReg1, RegState::Kill) |
| 5738 | .addImm(PCLabelId); |
| 5739 | // Set the low bit because of thumb mode. |
| 5740 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
| 5741 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tMOVi8), NewVReg3) |
| 5742 | .addReg(ARM::CPSR, RegState::Define) |
| 5743 | .addImm(1)); |
| 5744 | unsigned NewVReg4 = MRI->createVirtualRegister(TRC); |
| 5745 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tORR), NewVReg4) |
| 5746 | .addReg(ARM::CPSR, RegState::Define) |
| 5747 | .addReg(NewVReg2, RegState::Kill) |
| 5748 | .addReg(NewVReg3, RegState::Kill)); |
| 5749 | unsigned NewVReg5 = MRI->createVirtualRegister(TRC); |
| 5750 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tADDrSPi), NewVReg5) |
| 5751 | .addFrameIndex(FI) |
| 5752 | .addImm(36)); // &jbuf[1] :: pc |
| 5753 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tSTRi)) |
| 5754 | .addReg(NewVReg4, RegState::Kill) |
| 5755 | .addReg(NewVReg5, RegState::Kill) |
| 5756 | .addImm(0) |
| 5757 | .addMemOperand(FIMMOSt)); |
| 5758 | } else { |
| 5759 | // Incoming value: jbuf |
| 5760 | // ldr r1, LCPI1_1 |
| 5761 | // add r1, pc, r1 |
| 5762 | // str r1, [$jbuf, #+4] ; &jbuf[1] |
| 5763 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 5764 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::LDRi12), NewVReg1) |
| 5765 | .addConstantPoolIndex(CPI) |
| 5766 | .addImm(0) |
| 5767 | .addMemOperand(CPMMO)); |
| 5768 | unsigned NewVReg2 = MRI->createVirtualRegister(TRC); |
| 5769 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::PICADD), NewVReg2) |
| 5770 | .addReg(NewVReg1, RegState::Kill) |
| 5771 | .addImm(PCLabelId)); |
| 5772 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::STRi12)) |
| 5773 | .addReg(NewVReg2, RegState::Kill) |
| 5774 | .addFrameIndex(FI) |
| 5775 | .addImm(36) // &jbuf[1] :: pc |
| 5776 | .addMemOperand(FIMMOSt)); |
| 5777 | } |
| 5778 | } |
| 5779 | |
| 5780 | MachineBasicBlock *ARMTargetLowering:: |
| 5781 | EmitSjLjDispatchBlock(MachineInstr *MI, MachineBasicBlock *MBB) const { |
| 5782 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 5783 | DebugLoc dl = MI->getDebugLoc(); |
| 5784 | MachineFunction *MF = MBB->getParent(); |
| 5785 | MachineRegisterInfo *MRI = &MF->getRegInfo(); |
| 5786 | ARMFunctionInfo *AFI = MF->getInfo<ARMFunctionInfo>(); |
| 5787 | MachineFrameInfo *MFI = MF->getFrameInfo(); |
| 5788 | int FI = MFI->getFunctionContextIndex(); |
| 5789 | |
| 5790 | const TargetRegisterClass *TRC = |
| 5791 | Subtarget->isThumb() ? ARM::tGPRRegisterClass : ARM::GPRRegisterClass; |
| 5792 | |
Bill Wendling | 04f15b4 | 2011-10-06 21:29:56 +0000 | [diff] [blame] | 5793 | // Get a mapping of the call site numbers to all of the landing pads they're |
| 5794 | // associated with. |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 5795 | DenseMap<unsigned, SmallVector<MachineBasicBlock*, 2> > CallSiteNumToLPad; |
| 5796 | unsigned MaxCSNum = 0; |
| 5797 | MachineModuleInfo &MMI = MF->getMMI(); |
| 5798 | for (MachineFunction::iterator BB = MF->begin(), E = MF->end(); BB != E; ++BB) { |
| 5799 | if (!BB->isLandingPad()) continue; |
| 5800 | |
| 5801 | // FIXME: We should assert that the EH_LABEL is the first MI in the landing |
| 5802 | // pad. |
| 5803 | for (MachineBasicBlock::iterator |
| 5804 | II = BB->begin(), IE = BB->end(); II != IE; ++II) { |
| 5805 | if (!II->isEHLabel()) continue; |
| 5806 | |
| 5807 | MCSymbol *Sym = II->getOperand(0).getMCSymbol(); |
Bill Wendling | 5cbef19 | 2011-10-05 23:28:57 +0000 | [diff] [blame] | 5808 | if (!MMI.hasCallSiteLandingPad(Sym)) continue; |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 5809 | |
Bill Wendling | 5cbef19 | 2011-10-05 23:28:57 +0000 | [diff] [blame] | 5810 | SmallVectorImpl<unsigned> &CallSiteIdxs = MMI.getCallSiteLandingPad(Sym); |
| 5811 | for (SmallVectorImpl<unsigned>::iterator |
| 5812 | CSI = CallSiteIdxs.begin(), CSE = CallSiteIdxs.end(); |
| 5813 | CSI != CSE; ++CSI) { |
| 5814 | CallSiteNumToLPad[*CSI].push_back(BB); |
| 5815 | MaxCSNum = std::max(MaxCSNum, *CSI); |
| 5816 | } |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 5817 | break; |
| 5818 | } |
| 5819 | } |
| 5820 | |
| 5821 | // Get an ordered list of the machine basic blocks for the jump table. |
| 5822 | std::vector<MachineBasicBlock*> LPadList; |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 5823 | SmallPtrSet<MachineBasicBlock*, 64> InvokeBBs; |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 5824 | LPadList.reserve(CallSiteNumToLPad.size()); |
| 5825 | for (unsigned I = 1; I <= MaxCSNum; ++I) { |
| 5826 | SmallVectorImpl<MachineBasicBlock*> &MBBList = CallSiteNumToLPad[I]; |
| 5827 | for (SmallVectorImpl<MachineBasicBlock*>::iterator |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 5828 | II = MBBList.begin(), IE = MBBList.end(); II != IE; ++II) { |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 5829 | LPadList.push_back(*II); |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 5830 | InvokeBBs.insert((*II)->pred_begin(), (*II)->pred_end()); |
| 5831 | } |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 5832 | } |
| 5833 | |
Bill Wendling | 5cbef19 | 2011-10-05 23:28:57 +0000 | [diff] [blame] | 5834 | assert(!LPadList.empty() && |
| 5835 | "No landing pad destinations for the dispatch jump table!"); |
| 5836 | |
Bill Wendling | 04f15b4 | 2011-10-06 21:29:56 +0000 | [diff] [blame] | 5837 | // Create the jump table and associated information. |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 5838 | MachineJumpTableInfo *JTI = |
| 5839 | MF->getOrCreateJumpTableInfo(MachineJumpTableInfo::EK_Inline); |
| 5840 | unsigned MJTI = JTI->createJumpTableIndex(LPadList); |
| 5841 | unsigned UId = AFI->createJumpTableUId(); |
| 5842 | |
Bill Wendling | 04f15b4 | 2011-10-06 21:29:56 +0000 | [diff] [blame] | 5843 | // Create the MBBs for the dispatch code. |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 5844 | |
| 5845 | // Shove the dispatch's address into the return slot in the function context. |
| 5846 | MachineBasicBlock *DispatchBB = MF->CreateMachineBasicBlock(); |
| 5847 | DispatchBB->setIsLandingPad(); |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 5848 | |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 5849 | MachineBasicBlock *TrapBB = MF->CreateMachineBasicBlock(); |
Bill Wendling | 083a8eb | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 5850 | BuildMI(TrapBB, dl, TII->get(Subtarget->isThumb() ? ARM::tTRAP : ARM::TRAP)); |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 5851 | DispatchBB->addSuccessor(TrapBB); |
| 5852 | |
| 5853 | MachineBasicBlock *DispContBB = MF->CreateMachineBasicBlock(); |
| 5854 | DispatchBB->addSuccessor(DispContBB); |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 5855 | |
Bill Wendling | a48ed4f | 2011-10-17 21:32:56 +0000 | [diff] [blame] | 5856 | // Insert and MBBs. |
Bill Wendling | 930193c | 2011-10-06 00:53:33 +0000 | [diff] [blame] | 5857 | MF->insert(MF->end(), DispatchBB); |
| 5858 | MF->insert(MF->end(), DispContBB); |
| 5859 | MF->insert(MF->end(), TrapBB); |
Bill Wendling | 930193c | 2011-10-06 00:53:33 +0000 | [diff] [blame] | 5860 | |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 5861 | // Insert code into the entry block that creates and registers the function |
| 5862 | // context. |
| 5863 | SetupEntryBlockForSjLj(MI, MBB, DispatchBB, FI); |
| 5864 | |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 5865 | MachineMemOperand *FIMMOLd = |
Bill Wendling | 04f15b4 | 2011-10-06 21:29:56 +0000 | [diff] [blame] | 5866 | MF->getMachineMemOperand(MachinePointerInfo::getFixedStack(FI), |
Bill Wendling | 083a8eb | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 5867 | MachineMemOperand::MOLoad | |
| 5868 | MachineMemOperand::MOVolatile, 4, 4); |
Bill Wendling | 930193c | 2011-10-06 00:53:33 +0000 | [diff] [blame] | 5869 | |
Bob Wilson | f4aea8f | 2011-12-22 23:39:48 +0000 | [diff] [blame] | 5870 | if (AFI->isThumb1OnlyFunction()) |
| 5871 | BuildMI(DispatchBB, dl, TII->get(ARM::tInt_eh_sjlj_dispatchsetup)); |
| 5872 | else if (!Subtarget->hasVFP2()) |
| 5873 | BuildMI(DispatchBB, dl, TII->get(ARM::Int_eh_sjlj_dispatchsetup_nofp)); |
| 5874 | else |
| 5875 | BuildMI(DispatchBB, dl, TII->get(ARM::Int_eh_sjlj_dispatchsetup)); |
Bob Wilson | eaab6ef | 2011-11-16 07:11:57 +0000 | [diff] [blame] | 5876 | |
Bill Wendling | 952cb50 | 2011-10-18 22:49:07 +0000 | [diff] [blame] | 5877 | unsigned NumLPads = LPadList.size(); |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 5878 | if (Subtarget->isThumb2()) { |
| 5879 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 5880 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2LDRi12), NewVReg1) |
| 5881 | .addFrameIndex(FI) |
| 5882 | .addImm(4) |
| 5883 | .addMemOperand(FIMMOLd)); |
Bill Wendling | b9fecf4 | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 5884 | |
Bill Wendling | 952cb50 | 2011-10-18 22:49:07 +0000 | [diff] [blame] | 5885 | if (NumLPads < 256) { |
| 5886 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2CMPri)) |
| 5887 | .addReg(NewVReg1) |
| 5888 | .addImm(LPadList.size())); |
| 5889 | } else { |
| 5890 | unsigned VReg1 = MRI->createVirtualRegister(TRC); |
| 5891 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2MOVi16), VReg1) |
Bill Wendling | 15a1a22 | 2011-10-18 23:19:55 +0000 | [diff] [blame] | 5892 | .addImm(NumLPads & 0xFFFF)); |
| 5893 | |
| 5894 | unsigned VReg2 = VReg1; |
| 5895 | if ((NumLPads & 0xFFFF0000) != 0) { |
| 5896 | VReg2 = MRI->createVirtualRegister(TRC); |
| 5897 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2MOVTi16), VReg2) |
| 5898 | .addReg(VReg1) |
| 5899 | .addImm(NumLPads >> 16)); |
| 5900 | } |
| 5901 | |
Bill Wendling | 952cb50 | 2011-10-18 22:49:07 +0000 | [diff] [blame] | 5902 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2CMPrr)) |
| 5903 | .addReg(NewVReg1) |
| 5904 | .addReg(VReg2)); |
| 5905 | } |
Bill Wendling | b9fecf4 | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 5906 | |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 5907 | BuildMI(DispatchBB, dl, TII->get(ARM::t2Bcc)) |
| 5908 | .addMBB(TrapBB) |
| 5909 | .addImm(ARMCC::HI) |
| 5910 | .addReg(ARM::CPSR); |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 5911 | |
Bill Wendling | b9fecf4 | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 5912 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
| 5913 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::t2LEApcrelJT),NewVReg3) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 5914 | .addJumpTableIndex(MJTI) |
| 5915 | .addImm(UId)); |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 5916 | |
Bill Wendling | b9fecf4 | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 5917 | unsigned NewVReg4 = MRI->createVirtualRegister(TRC); |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 5918 | AddDefaultCC( |
| 5919 | AddDefaultPred( |
Bill Wendling | b9fecf4 | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 5920 | BuildMI(DispContBB, dl, TII->get(ARM::t2ADDrs), NewVReg4) |
| 5921 | .addReg(NewVReg3, RegState::Kill) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 5922 | .addReg(NewVReg1) |
| 5923 | .addImm(ARM_AM::getSORegOpc(ARM_AM::lsl, 2)))); |
| 5924 | |
| 5925 | BuildMI(DispContBB, dl, TII->get(ARM::t2BR_JT)) |
Bill Wendling | b9fecf4 | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 5926 | .addReg(NewVReg4, RegState::Kill) |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 5927 | .addReg(NewVReg1) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 5928 | .addJumpTableIndex(MJTI) |
| 5929 | .addImm(UId); |
| 5930 | } else if (Subtarget->isThumb()) { |
Bill Wendling | 083a8eb | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 5931 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 5932 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::tLDRspi), NewVReg1) |
| 5933 | .addFrameIndex(FI) |
| 5934 | .addImm(1) |
| 5935 | .addMemOperand(FIMMOLd)); |
Bill Wendling | f1083d4 | 2011-10-07 22:08:37 +0000 | [diff] [blame] | 5936 | |
Bill Wendling | a5871dc | 2011-10-18 23:11:05 +0000 | [diff] [blame] | 5937 | if (NumLPads < 256) { |
| 5938 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::tCMPi8)) |
| 5939 | .addReg(NewVReg1) |
| 5940 | .addImm(NumLPads)); |
| 5941 | } else { |
| 5942 | MachineConstantPool *ConstantPool = MF->getConstantPool(); |
Bill Wendling | 922ad78 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 5943 | Type *Int32Ty = Type::getInt32Ty(MF->getFunction()->getContext()); |
| 5944 | const Constant *C = ConstantInt::get(Int32Ty, NumLPads); |
| 5945 | |
| 5946 | // MachineConstantPool wants an explicit alignment. |
| 5947 | unsigned Align = getTargetData()->getPrefTypeAlignment(Int32Ty); |
| 5948 | if (Align == 0) |
| 5949 | Align = getTargetData()->getTypeAllocSize(C->getType()); |
| 5950 | unsigned Idx = ConstantPool->getConstantPoolIndex(C, Align); |
Bill Wendling | a5871dc | 2011-10-18 23:11:05 +0000 | [diff] [blame] | 5951 | |
| 5952 | unsigned VReg1 = MRI->createVirtualRegister(TRC); |
| 5953 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::tLDRpci)) |
| 5954 | .addReg(VReg1, RegState::Define) |
| 5955 | .addConstantPoolIndex(Idx)); |
| 5956 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::tCMPr)) |
| 5957 | .addReg(NewVReg1) |
| 5958 | .addReg(VReg1)); |
| 5959 | } |
| 5960 | |
Bill Wendling | 083a8eb | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 5961 | BuildMI(DispatchBB, dl, TII->get(ARM::tBcc)) |
| 5962 | .addMBB(TrapBB) |
| 5963 | .addImm(ARMCC::HI) |
| 5964 | .addReg(ARM::CPSR); |
| 5965 | |
| 5966 | unsigned NewVReg2 = MRI->createVirtualRegister(TRC); |
| 5967 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tLSLri), NewVReg2) |
| 5968 | .addReg(ARM::CPSR, RegState::Define) |
| 5969 | .addReg(NewVReg1) |
| 5970 | .addImm(2)); |
| 5971 | |
| 5972 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
Bill Wendling | 217f0e9 | 2011-10-06 23:41:14 +0000 | [diff] [blame] | 5973 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tLEApcrelJT), NewVReg3) |
Bill Wendling | 083a8eb | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 5974 | .addJumpTableIndex(MJTI) |
| 5975 | .addImm(UId)); |
| 5976 | |
| 5977 | unsigned NewVReg4 = MRI->createVirtualRegister(TRC); |
| 5978 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tADDrr), NewVReg4) |
| 5979 | .addReg(ARM::CPSR, RegState::Define) |
| 5980 | .addReg(NewVReg2, RegState::Kill) |
| 5981 | .addReg(NewVReg3)); |
| 5982 | |
| 5983 | MachineMemOperand *JTMMOLd = |
| 5984 | MF->getMachineMemOperand(MachinePointerInfo::getJumpTable(), |
| 5985 | MachineMemOperand::MOLoad, 4, 4); |
| 5986 | |
| 5987 | unsigned NewVReg5 = MRI->createVirtualRegister(TRC); |
| 5988 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tLDRi), NewVReg5) |
| 5989 | .addReg(NewVReg4, RegState::Kill) |
| 5990 | .addImm(0) |
| 5991 | .addMemOperand(JTMMOLd)); |
| 5992 | |
| 5993 | unsigned NewVReg6 = MRI->createVirtualRegister(TRC); |
| 5994 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tADDrr), NewVReg6) |
| 5995 | .addReg(ARM::CPSR, RegState::Define) |
| 5996 | .addReg(NewVReg5, RegState::Kill) |
| 5997 | .addReg(NewVReg3)); |
| 5998 | |
| 5999 | BuildMI(DispContBB, dl, TII->get(ARM::tBR_JTr)) |
| 6000 | .addReg(NewVReg6, RegState::Kill) |
| 6001 | .addJumpTableIndex(MJTI) |
| 6002 | .addImm(UId); |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6003 | } else { |
| 6004 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 6005 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::LDRi12), NewVReg1) |
| 6006 | .addFrameIndex(FI) |
| 6007 | .addImm(4) |
| 6008 | .addMemOperand(FIMMOLd)); |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6009 | |
Bill Wendling | 85f3a0a | 2011-10-18 22:52:20 +0000 | [diff] [blame] | 6010 | if (NumLPads < 256) { |
| 6011 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::CMPri)) |
| 6012 | .addReg(NewVReg1) |
| 6013 | .addImm(NumLPads)); |
Bill Wendling | 922ad78 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 6014 | } else if (Subtarget->hasV6T2Ops() && isUInt<16>(NumLPads)) { |
Bill Wendling | 85f3a0a | 2011-10-18 22:52:20 +0000 | [diff] [blame] | 6015 | unsigned VReg1 = MRI->createVirtualRegister(TRC); |
| 6016 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::MOVi16), VReg1) |
Bill Wendling | 15a1a22 | 2011-10-18 23:19:55 +0000 | [diff] [blame] | 6017 | .addImm(NumLPads & 0xFFFF)); |
| 6018 | |
| 6019 | unsigned VReg2 = VReg1; |
| 6020 | if ((NumLPads & 0xFFFF0000) != 0) { |
| 6021 | VReg2 = MRI->createVirtualRegister(TRC); |
| 6022 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::MOVTi16), VReg2) |
| 6023 | .addReg(VReg1) |
| 6024 | .addImm(NumLPads >> 16)); |
| 6025 | } |
| 6026 | |
Bill Wendling | 85f3a0a | 2011-10-18 22:52:20 +0000 | [diff] [blame] | 6027 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::CMPrr)) |
| 6028 | .addReg(NewVReg1) |
| 6029 | .addReg(VReg2)); |
Bill Wendling | 922ad78 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 6030 | } else { |
| 6031 | MachineConstantPool *ConstantPool = MF->getConstantPool(); |
| 6032 | Type *Int32Ty = Type::getInt32Ty(MF->getFunction()->getContext()); |
| 6033 | const Constant *C = ConstantInt::get(Int32Ty, NumLPads); |
| 6034 | |
| 6035 | // MachineConstantPool wants an explicit alignment. |
| 6036 | unsigned Align = getTargetData()->getPrefTypeAlignment(Int32Ty); |
| 6037 | if (Align == 0) |
| 6038 | Align = getTargetData()->getTypeAllocSize(C->getType()); |
| 6039 | unsigned Idx = ConstantPool->getConstantPoolIndex(C, Align); |
| 6040 | |
| 6041 | unsigned VReg1 = MRI->createVirtualRegister(TRC); |
| 6042 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::LDRcp)) |
| 6043 | .addReg(VReg1, RegState::Define) |
Bill Wendling | 767f8be | 2011-10-20 20:37:11 +0000 | [diff] [blame] | 6044 | .addConstantPoolIndex(Idx) |
| 6045 | .addImm(0)); |
Bill Wendling | 922ad78 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 6046 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::CMPrr)) |
| 6047 | .addReg(NewVReg1) |
| 6048 | .addReg(VReg1, RegState::Kill)); |
Bill Wendling | 85f3a0a | 2011-10-18 22:52:20 +0000 | [diff] [blame] | 6049 | } |
| 6050 | |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6051 | BuildMI(DispatchBB, dl, TII->get(ARM::Bcc)) |
| 6052 | .addMBB(TrapBB) |
| 6053 | .addImm(ARMCC::HI) |
| 6054 | .addReg(ARM::CPSR); |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6055 | |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6056 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6057 | AddDefaultCC( |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6058 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::MOVsi), NewVReg3) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6059 | .addReg(NewVReg1) |
| 6060 | .addImm(ARM_AM::getSORegOpc(ARM_AM::lsl, 2)))); |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6061 | unsigned NewVReg4 = MRI->createVirtualRegister(TRC); |
| 6062 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::LEApcrelJT), NewVReg4) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6063 | .addJumpTableIndex(MJTI) |
| 6064 | .addImm(UId)); |
| 6065 | |
| 6066 | MachineMemOperand *JTMMOLd = |
| 6067 | MF->getMachineMemOperand(MachinePointerInfo::getJumpTable(), |
| 6068 | MachineMemOperand::MOLoad, 4, 4); |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6069 | unsigned NewVReg5 = MRI->createVirtualRegister(TRC); |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6070 | AddDefaultPred( |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6071 | BuildMI(DispContBB, dl, TII->get(ARM::LDRrs), NewVReg5) |
| 6072 | .addReg(NewVReg3, RegState::Kill) |
| 6073 | .addReg(NewVReg4) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6074 | .addImm(0) |
| 6075 | .addMemOperand(JTMMOLd)); |
| 6076 | |
| 6077 | BuildMI(DispContBB, dl, TII->get(ARM::BR_JTadd)) |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6078 | .addReg(NewVReg5, RegState::Kill) |
| 6079 | .addReg(NewVReg4) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6080 | .addJumpTableIndex(MJTI) |
| 6081 | .addImm(UId); |
| 6082 | } |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6083 | |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 6084 | // Add the jump table entries as successors to the MBB. |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6085 | MachineBasicBlock *PrevMBB = 0; |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 6086 | for (std::vector<MachineBasicBlock*>::iterator |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6087 | I = LPadList.begin(), E = LPadList.end(); I != E; ++I) { |
| 6088 | MachineBasicBlock *CurMBB = *I; |
| 6089 | if (PrevMBB != CurMBB) |
| 6090 | DispContBB->addSuccessor(CurMBB); |
| 6091 | PrevMBB = CurMBB; |
| 6092 | } |
| 6093 | |
Bill Wendling | 24bb925 | 2011-10-17 05:25:09 +0000 | [diff] [blame] | 6094 | // N.B. the order the invoke BBs are processed in doesn't matter here. |
Bill Wendling | 969c9ef | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 6095 | const ARMBaseInstrInfo *AII = static_cast<const ARMBaseInstrInfo*>(TII); |
| 6096 | const ARMBaseRegisterInfo &RI = AII->getRegisterInfo(); |
Craig Topper | 015f228 | 2012-03-04 03:33:22 +0000 | [diff] [blame] | 6097 | const uint16_t *SavedRegs = RI.getCalleeSavedRegs(MF); |
Bill Wendling | f7b0207 | 2011-10-18 18:30:49 +0000 | [diff] [blame] | 6098 | SmallVector<MachineBasicBlock*, 64> MBBLPads; |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6099 | for (SmallPtrSet<MachineBasicBlock*, 64>::iterator |
| 6100 | I = InvokeBBs.begin(), E = InvokeBBs.end(); I != E; ++I) { |
| 6101 | MachineBasicBlock *BB = *I; |
Bill Wendling | 969c9ef | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 6102 | |
| 6103 | // Remove the landing pad successor from the invoke block and replace it |
| 6104 | // with the new dispatch block. |
Bill Wendling | de39d86 | 2011-10-26 07:16:18 +0000 | [diff] [blame] | 6105 | SmallVector<MachineBasicBlock*, 4> Successors(BB->succ_begin(), |
| 6106 | BB->succ_end()); |
| 6107 | while (!Successors.empty()) { |
| 6108 | MachineBasicBlock *SMBB = Successors.pop_back_val(); |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6109 | if (SMBB->isLandingPad()) { |
| 6110 | BB->removeSuccessor(SMBB); |
Bill Wendling | f7b0207 | 2011-10-18 18:30:49 +0000 | [diff] [blame] | 6111 | MBBLPads.push_back(SMBB); |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6112 | } |
| 6113 | } |
| 6114 | |
| 6115 | BB->addSuccessor(DispatchBB); |
Bill Wendling | 969c9ef | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 6116 | |
| 6117 | // Find the invoke call and mark all of the callee-saved registers as |
| 6118 | // 'implicit defined' so that they're spilled. This prevents code from |
| 6119 | // moving instructions to before the EH block, where they will never be |
| 6120 | // executed. |
| 6121 | for (MachineBasicBlock::reverse_iterator |
| 6122 | II = BB->rbegin(), IE = BB->rend(); II != IE; ++II) { |
Evan Cheng | 5a96b3d | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 6123 | if (!II->isCall()) continue; |
Bill Wendling | 969c9ef | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 6124 | |
| 6125 | DenseMap<unsigned, bool> DefRegs; |
| 6126 | for (MachineInstr::mop_iterator |
| 6127 | OI = II->operands_begin(), OE = II->operands_end(); |
| 6128 | OI != OE; ++OI) { |
| 6129 | if (!OI->isReg()) continue; |
| 6130 | DefRegs[OI->getReg()] = true; |
| 6131 | } |
| 6132 | |
| 6133 | MachineInstrBuilder MIB(&*II); |
| 6134 | |
Bill Wendling | 5d79859 | 2011-10-14 23:55:44 +0000 | [diff] [blame] | 6135 | for (unsigned i = 0; SavedRegs[i] != 0; ++i) { |
Bill Wendling | b8dcb31 | 2011-10-22 00:29:28 +0000 | [diff] [blame] | 6136 | unsigned Reg = SavedRegs[i]; |
| 6137 | if (Subtarget->isThumb2() && |
| 6138 | !ARM::tGPRRegisterClass->contains(Reg) && |
| 6139 | !ARM::hGPRRegisterClass->contains(Reg)) |
| 6140 | continue; |
| 6141 | else if (Subtarget->isThumb1Only() && |
| 6142 | !ARM::tGPRRegisterClass->contains(Reg)) |
| 6143 | continue; |
| 6144 | else if (!Subtarget->isThumb() && |
| 6145 | !ARM::GPRRegisterClass->contains(Reg)) |
| 6146 | continue; |
| 6147 | if (!DefRegs[Reg]) |
| 6148 | MIB.addReg(Reg, RegState::ImplicitDefine | RegState::Dead); |
Bill Wendling | 5d79859 | 2011-10-14 23:55:44 +0000 | [diff] [blame] | 6149 | } |
Bill Wendling | 969c9ef | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 6150 | |
| 6151 | break; |
| 6152 | } |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6153 | } |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 6154 | |
Bill Wendling | f7b0207 | 2011-10-18 18:30:49 +0000 | [diff] [blame] | 6155 | // Mark all former landing pads as non-landing pads. The dispatch is the only |
| 6156 | // landing pad now. |
| 6157 | for (SmallVectorImpl<MachineBasicBlock*>::iterator |
| 6158 | I = MBBLPads.begin(), E = MBBLPads.end(); I != E; ++I) |
| 6159 | (*I)->setIsLandingPad(false); |
| 6160 | |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 6161 | // The instruction is gone now. |
| 6162 | MI->eraseFromParent(); |
| 6163 | |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 6164 | return MBB; |
| 6165 | } |
| 6166 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 6167 | static |
| 6168 | MachineBasicBlock *OtherSucc(MachineBasicBlock *MBB, MachineBasicBlock *Succ) { |
| 6169 | for (MachineBasicBlock::succ_iterator I = MBB->succ_begin(), |
| 6170 | E = MBB->succ_end(); I != E; ++I) |
| 6171 | if (*I != Succ) |
| 6172 | return *I; |
| 6173 | llvm_unreachable("Expecting a BB with two successors!"); |
| 6174 | } |
| 6175 | |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 6176 | MachineBasicBlock * |
Evan Cheng | ff9b373 | 2008-01-30 18:18:23 +0000 | [diff] [blame] | 6177 | ARMTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI, |
Dan Gohman | af1d8ca | 2010-05-01 00:01:06 +0000 | [diff] [blame] | 6178 | MachineBasicBlock *BB) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6179 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
Dale Johannesen | b672840 | 2009-02-13 02:25:56 +0000 | [diff] [blame] | 6180 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6181 | bool isThumb2 = Subtarget->isThumb2(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6182 | switch (MI->getOpcode()) { |
Andrew Trick | 1c3af77 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 6183 | default: { |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 6184 | MI->dump(); |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 6185 | llvm_unreachable("Unexpected instr type to insert"); |
Andrew Trick | 1c3af77 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 6186 | } |
Jim Grosbach | ee2c2a4 | 2011-09-16 21:55:56 +0000 | [diff] [blame] | 6187 | // The Thumb2 pre-indexed stores have the same MI operands, they just |
| 6188 | // define them differently in the .td files from the isel patterns, so |
| 6189 | // they need pseudos. |
| 6190 | case ARM::t2STR_preidx: |
| 6191 | MI->setDesc(TII->get(ARM::t2STR_PRE)); |
| 6192 | return BB; |
| 6193 | case ARM::t2STRB_preidx: |
| 6194 | MI->setDesc(TII->get(ARM::t2STRB_PRE)); |
| 6195 | return BB; |
| 6196 | case ARM::t2STRH_preidx: |
| 6197 | MI->setDesc(TII->get(ARM::t2STRH_PRE)); |
| 6198 | return BB; |
| 6199 | |
Jim Grosbach | 19dec20 | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 6200 | case ARM::STRi_preidx: |
| 6201 | case ARM::STRBi_preidx: { |
Jim Grosbach | 6cd5716 | 2011-08-09 21:22:41 +0000 | [diff] [blame] | 6202 | unsigned NewOpc = MI->getOpcode() == ARM::STRi_preidx ? |
Jim Grosbach | 19dec20 | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 6203 | ARM::STR_PRE_IMM : ARM::STRB_PRE_IMM; |
| 6204 | // Decode the offset. |
| 6205 | unsigned Offset = MI->getOperand(4).getImm(); |
| 6206 | bool isSub = ARM_AM::getAM2Op(Offset) == ARM_AM::sub; |
| 6207 | Offset = ARM_AM::getAM2Offset(Offset); |
| 6208 | if (isSub) |
| 6209 | Offset = -Offset; |
| 6210 | |
Jim Grosbach | 4dfe220 | 2011-08-12 21:02:34 +0000 | [diff] [blame] | 6211 | MachineMemOperand *MMO = *MI->memoperands_begin(); |
Benjamin Kramer | 2753ae3 | 2011-08-27 17:36:14 +0000 | [diff] [blame] | 6212 | BuildMI(*BB, MI, dl, TII->get(NewOpc)) |
Jim Grosbach | 19dec20 | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 6213 | .addOperand(MI->getOperand(0)) // Rn_wb |
| 6214 | .addOperand(MI->getOperand(1)) // Rt |
| 6215 | .addOperand(MI->getOperand(2)) // Rn |
| 6216 | .addImm(Offset) // offset (skip GPR==zero_reg) |
| 6217 | .addOperand(MI->getOperand(5)) // pred |
Jim Grosbach | 4dfe220 | 2011-08-12 21:02:34 +0000 | [diff] [blame] | 6218 | .addOperand(MI->getOperand(6)) |
| 6219 | .addMemOperand(MMO); |
Jim Grosbach | 19dec20 | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 6220 | MI->eraseFromParent(); |
| 6221 | return BB; |
| 6222 | } |
| 6223 | case ARM::STRr_preidx: |
Jim Grosbach | 7b8f46c | 2011-08-11 21:17:22 +0000 | [diff] [blame] | 6224 | case ARM::STRBr_preidx: |
| 6225 | case ARM::STRH_preidx: { |
| 6226 | unsigned NewOpc; |
| 6227 | switch (MI->getOpcode()) { |
| 6228 | default: llvm_unreachable("unexpected opcode!"); |
| 6229 | case ARM::STRr_preidx: NewOpc = ARM::STR_PRE_REG; break; |
| 6230 | case ARM::STRBr_preidx: NewOpc = ARM::STRB_PRE_REG; break; |
| 6231 | case ARM::STRH_preidx: NewOpc = ARM::STRH_PRE; break; |
| 6232 | } |
Jim Grosbach | 19dec20 | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 6233 | MachineInstrBuilder MIB = BuildMI(*BB, MI, dl, TII->get(NewOpc)); |
| 6234 | for (unsigned i = 0; i < MI->getNumOperands(); ++i) |
| 6235 | MIB.addOperand(MI->getOperand(i)); |
| 6236 | MI->eraseFromParent(); |
| 6237 | return BB; |
| 6238 | } |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6239 | case ARM::ATOMIC_LOAD_ADD_I8: |
| 6240 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr); |
| 6241 | case ARM::ATOMIC_LOAD_ADD_I16: |
| 6242 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr); |
| 6243 | case ARM::ATOMIC_LOAD_ADD_I32: |
| 6244 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 6245 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6246 | case ARM::ATOMIC_LOAD_AND_I8: |
| 6247 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
| 6248 | case ARM::ATOMIC_LOAD_AND_I16: |
| 6249 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
| 6250 | case ARM::ATOMIC_LOAD_AND_I32: |
| 6251 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 6252 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6253 | case ARM::ATOMIC_LOAD_OR_I8: |
| 6254 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
| 6255 | case ARM::ATOMIC_LOAD_OR_I16: |
| 6256 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
| 6257 | case ARM::ATOMIC_LOAD_OR_I32: |
| 6258 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 6259 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6260 | case ARM::ATOMIC_LOAD_XOR_I8: |
| 6261 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
| 6262 | case ARM::ATOMIC_LOAD_XOR_I16: |
| 6263 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
| 6264 | case ARM::ATOMIC_LOAD_XOR_I32: |
| 6265 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 6266 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6267 | case ARM::ATOMIC_LOAD_NAND_I8: |
| 6268 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2BICrr : ARM::BICrr); |
| 6269 | case ARM::ATOMIC_LOAD_NAND_I16: |
| 6270 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2BICrr : ARM::BICrr); |
| 6271 | case ARM::ATOMIC_LOAD_NAND_I32: |
| 6272 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2BICrr : ARM::BICrr); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 6273 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6274 | case ARM::ATOMIC_LOAD_SUB_I8: |
| 6275 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr); |
| 6276 | case ARM::ATOMIC_LOAD_SUB_I16: |
| 6277 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr); |
| 6278 | case ARM::ATOMIC_LOAD_SUB_I32: |
| 6279 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 6280 | |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 6281 | case ARM::ATOMIC_LOAD_MIN_I8: |
| 6282 | return EmitAtomicBinaryMinMax(MI, BB, 1, true, ARMCC::LT); |
| 6283 | case ARM::ATOMIC_LOAD_MIN_I16: |
| 6284 | return EmitAtomicBinaryMinMax(MI, BB, 2, true, ARMCC::LT); |
| 6285 | case ARM::ATOMIC_LOAD_MIN_I32: |
| 6286 | return EmitAtomicBinaryMinMax(MI, BB, 4, true, ARMCC::LT); |
| 6287 | |
| 6288 | case ARM::ATOMIC_LOAD_MAX_I8: |
| 6289 | return EmitAtomicBinaryMinMax(MI, BB, 1, true, ARMCC::GT); |
| 6290 | case ARM::ATOMIC_LOAD_MAX_I16: |
| 6291 | return EmitAtomicBinaryMinMax(MI, BB, 2, true, ARMCC::GT); |
| 6292 | case ARM::ATOMIC_LOAD_MAX_I32: |
| 6293 | return EmitAtomicBinaryMinMax(MI, BB, 4, true, ARMCC::GT); |
| 6294 | |
| 6295 | case ARM::ATOMIC_LOAD_UMIN_I8: |
| 6296 | return EmitAtomicBinaryMinMax(MI, BB, 1, false, ARMCC::LO); |
| 6297 | case ARM::ATOMIC_LOAD_UMIN_I16: |
| 6298 | return EmitAtomicBinaryMinMax(MI, BB, 2, false, ARMCC::LO); |
| 6299 | case ARM::ATOMIC_LOAD_UMIN_I32: |
| 6300 | return EmitAtomicBinaryMinMax(MI, BB, 4, false, ARMCC::LO); |
| 6301 | |
| 6302 | case ARM::ATOMIC_LOAD_UMAX_I8: |
| 6303 | return EmitAtomicBinaryMinMax(MI, BB, 1, false, ARMCC::HI); |
| 6304 | case ARM::ATOMIC_LOAD_UMAX_I16: |
| 6305 | return EmitAtomicBinaryMinMax(MI, BB, 2, false, ARMCC::HI); |
| 6306 | case ARM::ATOMIC_LOAD_UMAX_I32: |
| 6307 | return EmitAtomicBinaryMinMax(MI, BB, 4, false, ARMCC::HI); |
| 6308 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6309 | case ARM::ATOMIC_SWAP_I8: return EmitAtomicBinary(MI, BB, 1, 0); |
| 6310 | case ARM::ATOMIC_SWAP_I16: return EmitAtomicBinary(MI, BB, 2, 0); |
| 6311 | case ARM::ATOMIC_SWAP_I32: return EmitAtomicBinary(MI, BB, 4, 0); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 6312 | |
| 6313 | case ARM::ATOMIC_CMP_SWAP_I8: return EmitAtomicCmpSwap(MI, BB, 1); |
| 6314 | case ARM::ATOMIC_CMP_SWAP_I16: return EmitAtomicCmpSwap(MI, BB, 2); |
| 6315 | case ARM::ATOMIC_CMP_SWAP_I32: return EmitAtomicCmpSwap(MI, BB, 4); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 6316 | |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6317 | |
| 6318 | case ARM::ATOMADD6432: |
| 6319 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr, |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 6320 | isThumb2 ? ARM::t2ADCrr : ARM::ADCrr, |
| 6321 | /*NeedsCarry*/ true); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6322 | case ARM::ATOMSUB6432: |
| 6323 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr, |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 6324 | isThumb2 ? ARM::t2SBCrr : ARM::SBCrr, |
| 6325 | /*NeedsCarry*/ true); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6326 | case ARM::ATOMOR6432: |
| 6327 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr, |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 6328 | isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6329 | case ARM::ATOMXOR6432: |
| 6330 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2EORrr : ARM::EORrr, |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 6331 | isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6332 | case ARM::ATOMAND6432: |
| 6333 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr, |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 6334 | isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6335 | case ARM::ATOMSWAP6432: |
| 6336 | return EmitAtomicBinary64(MI, BB, 0, 0, false); |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 6337 | case ARM::ATOMCMPXCHG6432: |
| 6338 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr, |
| 6339 | isThumb2 ? ARM::t2SBCrr : ARM::SBCrr, |
| 6340 | /*NeedsCarry*/ false, /*IsCmpxchg*/true); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6341 | |
Evan Cheng | 007ea27 | 2009-08-12 05:17:19 +0000 | [diff] [blame] | 6342 | case ARM::tMOVCCr_pseudo: { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6343 | // To "insert" a SELECT_CC instruction, we actually have to insert the |
| 6344 | // diamond control-flow pattern. The incoming instruction knows the |
| 6345 | // destination vreg to set, the condition code register to branch on, the |
| 6346 | // true/false values to select between, and a branch opcode to use. |
| 6347 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 6348 | MachineFunction::iterator It = BB; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6349 | ++It; |
| 6350 | |
| 6351 | // thisMBB: |
| 6352 | // ... |
| 6353 | // TrueVal = ... |
| 6354 | // cmpTY ccX, r1, r2 |
| 6355 | // bCC copy1MBB |
| 6356 | // fallthrough --> copy0MBB |
| 6357 | MachineBasicBlock *thisMBB = BB; |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 6358 | MachineFunction *F = BB->getParent(); |
| 6359 | MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB); |
| 6360 | MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB); |
Dan Gohman | 258c58c | 2010-07-06 15:49:48 +0000 | [diff] [blame] | 6361 | F->insert(It, copy0MBB); |
| 6362 | F->insert(It, sinkMBB); |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 6363 | |
| 6364 | // Transfer the remainder of BB and its successor edges to sinkMBB. |
| 6365 | sinkMBB->splice(sinkMBB->begin(), BB, |
| 6366 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 6367 | BB->end()); |
| 6368 | sinkMBB->transferSuccessorsAndUpdatePHIs(BB); |
| 6369 | |
Dan Gohman | 258c58c | 2010-07-06 15:49:48 +0000 | [diff] [blame] | 6370 | BB->addSuccessor(copy0MBB); |
| 6371 | BB->addSuccessor(sinkMBB); |
Dan Gohman | b81c771 | 2010-07-06 15:18:19 +0000 | [diff] [blame] | 6372 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 6373 | BuildMI(BB, dl, TII->get(ARM::tBcc)).addMBB(sinkMBB) |
| 6374 | .addImm(MI->getOperand(3).getImm()).addReg(MI->getOperand(4).getReg()); |
| 6375 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6376 | // copy0MBB: |
| 6377 | // %FalseValue = ... |
| 6378 | // # fallthrough to sinkMBB |
| 6379 | BB = copy0MBB; |
| 6380 | |
| 6381 | // Update machine-CFG edges |
| 6382 | BB->addSuccessor(sinkMBB); |
| 6383 | |
| 6384 | // sinkMBB: |
| 6385 | // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ] |
| 6386 | // ... |
| 6387 | BB = sinkMBB; |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 6388 | BuildMI(*BB, BB->begin(), dl, |
| 6389 | TII->get(ARM::PHI), MI->getOperand(0).getReg()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6390 | .addReg(MI->getOperand(1).getReg()).addMBB(copy0MBB) |
| 6391 | .addReg(MI->getOperand(2).getReg()).addMBB(thisMBB); |
| 6392 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 6393 | MI->eraseFromParent(); // The pseudo instruction is gone now. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6394 | return BB; |
| 6395 | } |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 6396 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 6397 | case ARM::BCCi64: |
| 6398 | case ARM::BCCZi64: { |
Bob Wilson | 3c90469 | 2010-12-23 22:45:49 +0000 | [diff] [blame] | 6399 | // If there is an unconditional branch to the other successor, remove it. |
| 6400 | BB->erase(llvm::next(MachineBasicBlock::iterator(MI)), BB->end()); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 6401 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 6402 | // Compare both parts that make up the double comparison separately for |
| 6403 | // equality. |
| 6404 | bool RHSisZero = MI->getOpcode() == ARM::BCCZi64; |
| 6405 | |
| 6406 | unsigned LHS1 = MI->getOperand(1).getReg(); |
| 6407 | unsigned LHS2 = MI->getOperand(2).getReg(); |
| 6408 | if (RHSisZero) { |
| 6409 | AddDefaultPred(BuildMI(BB, dl, |
| 6410 | TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 6411 | .addReg(LHS1).addImm(0)); |
| 6412 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 6413 | .addReg(LHS2).addImm(0) |
| 6414 | .addImm(ARMCC::EQ).addReg(ARM::CPSR); |
| 6415 | } else { |
| 6416 | unsigned RHS1 = MI->getOperand(3).getReg(); |
| 6417 | unsigned RHS2 = MI->getOperand(4).getReg(); |
| 6418 | AddDefaultPred(BuildMI(BB, dl, |
| 6419 | TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
| 6420 | .addReg(LHS1).addReg(RHS1)); |
| 6421 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
| 6422 | .addReg(LHS2).addReg(RHS2) |
| 6423 | .addImm(ARMCC::EQ).addReg(ARM::CPSR); |
| 6424 | } |
| 6425 | |
| 6426 | MachineBasicBlock *destMBB = MI->getOperand(RHSisZero ? 3 : 5).getMBB(); |
| 6427 | MachineBasicBlock *exitMBB = OtherSucc(BB, destMBB); |
| 6428 | if (MI->getOperand(0).getImm() == ARMCC::NE) |
| 6429 | std::swap(destMBB, exitMBB); |
| 6430 | |
| 6431 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 6432 | .addMBB(destMBB).addImm(ARMCC::EQ).addReg(ARM::CPSR); |
Owen Anderson | 51f6a7a | 2011-09-09 21:48:23 +0000 | [diff] [blame] | 6433 | if (isThumb2) |
| 6434 | AddDefaultPred(BuildMI(BB, dl, TII->get(ARM::t2B)).addMBB(exitMBB)); |
| 6435 | else |
| 6436 | BuildMI(BB, dl, TII->get(ARM::B)) .addMBB(exitMBB); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 6437 | |
| 6438 | MI->eraseFromParent(); // The pseudo instruction is gone now. |
| 6439 | return BB; |
| 6440 | } |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 6441 | |
Bill Wendling | 5bc8528 | 2011-10-17 20:37:20 +0000 | [diff] [blame] | 6442 | case ARM::Int_eh_sjlj_setjmp: |
| 6443 | case ARM::Int_eh_sjlj_setjmp_nofp: |
| 6444 | case ARM::tInt_eh_sjlj_setjmp: |
| 6445 | case ARM::t2Int_eh_sjlj_setjmp: |
| 6446 | case ARM::t2Int_eh_sjlj_setjmp_nofp: |
| 6447 | EmitSjLjDispatchBlock(MI, BB); |
| 6448 | return BB; |
| 6449 | |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 6450 | case ARM::ABS: |
| 6451 | case ARM::t2ABS: { |
| 6452 | // To insert an ABS instruction, we have to insert the |
| 6453 | // diamond control-flow pattern. The incoming instruction knows the |
| 6454 | // source vreg to test against 0, the destination vreg to set, |
| 6455 | // the condition code register to branch on, the |
Andrew Trick | 7f5f0da | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 6456 | // true/false values to select between, and a branch opcode to use. |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 6457 | // It transforms |
| 6458 | // V1 = ABS V0 |
| 6459 | // into |
| 6460 | // V2 = MOVS V0 |
| 6461 | // BCC (branch to SinkBB if V0 >= 0) |
| 6462 | // RSBBB: V3 = RSBri V2, 0 (compute ABS if V2 < 0) |
Andrew Trick | 7f5f0da | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 6463 | // SinkBB: V1 = PHI(V2, V3) |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 6464 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 6465 | MachineFunction::iterator BBI = BB; |
| 6466 | ++BBI; |
| 6467 | MachineFunction *Fn = BB->getParent(); |
| 6468 | MachineBasicBlock *RSBBB = Fn->CreateMachineBasicBlock(LLVM_BB); |
| 6469 | MachineBasicBlock *SinkBB = Fn->CreateMachineBasicBlock(LLVM_BB); |
| 6470 | Fn->insert(BBI, RSBBB); |
| 6471 | Fn->insert(BBI, SinkBB); |
| 6472 | |
| 6473 | unsigned int ABSSrcReg = MI->getOperand(1).getReg(); |
| 6474 | unsigned int ABSDstReg = MI->getOperand(0).getReg(); |
| 6475 | bool isThumb2 = Subtarget->isThumb2(); |
| 6476 | MachineRegisterInfo &MRI = Fn->getRegInfo(); |
| 6477 | // In Thumb mode S must not be specified if source register is the SP or |
| 6478 | // PC and if destination register is the SP, so restrict register class |
| 6479 | unsigned NewMovDstReg = MRI.createVirtualRegister( |
| 6480 | isThumb2 ? ARM::rGPRRegisterClass : ARM::GPRRegisterClass); |
| 6481 | unsigned NewRsbDstReg = MRI.createVirtualRegister( |
| 6482 | isThumb2 ? ARM::rGPRRegisterClass : ARM::GPRRegisterClass); |
| 6483 | |
| 6484 | // Transfer the remainder of BB and its successor edges to sinkMBB. |
| 6485 | SinkBB->splice(SinkBB->begin(), BB, |
| 6486 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 6487 | BB->end()); |
| 6488 | SinkBB->transferSuccessorsAndUpdatePHIs(BB); |
| 6489 | |
| 6490 | BB->addSuccessor(RSBBB); |
| 6491 | BB->addSuccessor(SinkBB); |
| 6492 | |
| 6493 | // fall through to SinkMBB |
| 6494 | RSBBB->addSuccessor(SinkBB); |
| 6495 | |
| 6496 | // insert a movs at the end of BB |
| 6497 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2MOVr : ARM::MOVr), |
| 6498 | NewMovDstReg) |
| 6499 | .addReg(ABSSrcReg, RegState::Kill) |
| 6500 | .addImm((unsigned)ARMCC::AL).addReg(0) |
| 6501 | .addReg(ARM::CPSR, RegState::Define); |
| 6502 | |
| 6503 | // insert a bcc with opposite CC to ARMCC::MI at the end of BB |
Andrew Trick | 7f5f0da | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 6504 | BuildMI(BB, dl, |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 6505 | TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)).addMBB(SinkBB) |
| 6506 | .addImm(ARMCC::getOppositeCondition(ARMCC::MI)).addReg(ARM::CPSR); |
| 6507 | |
| 6508 | // insert rsbri in RSBBB |
| 6509 | // Note: BCC and rsbri will be converted into predicated rsbmi |
| 6510 | // by if-conversion pass |
Andrew Trick | 7f5f0da | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 6511 | BuildMI(*RSBBB, RSBBB->begin(), dl, |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 6512 | TII->get(isThumb2 ? ARM::t2RSBri : ARM::RSBri), NewRsbDstReg) |
| 6513 | .addReg(NewMovDstReg, RegState::Kill) |
| 6514 | .addImm(0).addImm((unsigned)ARMCC::AL).addReg(0).addReg(0); |
| 6515 | |
Andrew Trick | 7f5f0da | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 6516 | // insert PHI in SinkBB, |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 6517 | // reuse ABSDstReg to not change uses of ABS instruction |
| 6518 | BuildMI(*SinkBB, SinkBB->begin(), dl, |
| 6519 | TII->get(ARM::PHI), ABSDstReg) |
| 6520 | .addReg(NewRsbDstReg).addMBB(RSBBB) |
| 6521 | .addReg(NewMovDstReg).addMBB(BB); |
| 6522 | |
| 6523 | // remove ABS instruction |
Andrew Trick | 7f5f0da | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 6524 | MI->eraseFromParent(); |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 6525 | |
| 6526 | // return last added BB |
| 6527 | return SinkBB; |
| 6528 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6529 | } |
| 6530 | } |
| 6531 | |
Evan Cheng | 37fefc2 | 2011-08-30 19:09:48 +0000 | [diff] [blame] | 6532 | void ARMTargetLowering::AdjustInstrPostInstrSelection(MachineInstr *MI, |
| 6533 | SDNode *Node) const { |
Evan Cheng | 5a96b3d | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 6534 | if (!MI->hasPostISelHook()) { |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 6535 | assert(!convertAddSubFlagsOpcode(MI->getOpcode()) && |
| 6536 | "Pseudo flag-setting opcodes must be marked with 'hasPostISelHook'"); |
| 6537 | return; |
| 6538 | } |
| 6539 | |
Evan Cheng | 5a96b3d | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 6540 | const MCInstrDesc *MCID = &MI->getDesc(); |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6541 | // Adjust potentially 's' setting instructions after isel, i.e. ADC, SBC, RSB, |
| 6542 | // RSC. Coming out of isel, they have an implicit CPSR def, but the optional |
| 6543 | // operand is still set to noreg. If needed, set the optional operand's |
| 6544 | // register to CPSR, and remove the redundant implicit def. |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 6545 | // |
Andrew Trick | 90b7b12 | 2011-10-18 19:18:52 +0000 | [diff] [blame] | 6546 | // e.g. ADCS (..., CPSR<imp-def>) -> ADC (... opt:CPSR<def>). |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6547 | |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 6548 | // Rename pseudo opcodes. |
| 6549 | unsigned NewOpc = convertAddSubFlagsOpcode(MI->getOpcode()); |
| 6550 | if (NewOpc) { |
| 6551 | const ARMBaseInstrInfo *TII = |
| 6552 | static_cast<const ARMBaseInstrInfo*>(getTargetMachine().getInstrInfo()); |
Andrew Trick | 90b7b12 | 2011-10-18 19:18:52 +0000 | [diff] [blame] | 6553 | MCID = &TII->get(NewOpc); |
| 6554 | |
| 6555 | assert(MCID->getNumOperands() == MI->getDesc().getNumOperands() + 1 && |
| 6556 | "converted opcode should be the same except for cc_out"); |
| 6557 | |
| 6558 | MI->setDesc(*MCID); |
| 6559 | |
| 6560 | // Add the optional cc_out operand |
| 6561 | MI->addOperand(MachineOperand::CreateReg(0, /*isDef=*/true)); |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 6562 | } |
Andrew Trick | 90b7b12 | 2011-10-18 19:18:52 +0000 | [diff] [blame] | 6563 | unsigned ccOutIdx = MCID->getNumOperands() - 1; |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6564 | |
| 6565 | // Any ARM instruction that sets the 's' bit should specify an optional |
| 6566 | // "cc_out" operand in the last operand position. |
Evan Cheng | 5a96b3d | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 6567 | if (!MI->hasOptionalDef() || !MCID->OpInfo[ccOutIdx].isOptionalDef()) { |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 6568 | assert(!NewOpc && "Optional cc_out operand required"); |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6569 | return; |
| 6570 | } |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 6571 | // Look for an implicit def of CPSR added by MachineInstr ctor. Remove it |
| 6572 | // since we already have an optional CPSR def. |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6573 | bool definesCPSR = false; |
| 6574 | bool deadCPSR = false; |
Andrew Trick | 90b7b12 | 2011-10-18 19:18:52 +0000 | [diff] [blame] | 6575 | for (unsigned i = MCID->getNumOperands(), e = MI->getNumOperands(); |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6576 | i != e; ++i) { |
| 6577 | const MachineOperand &MO = MI->getOperand(i); |
| 6578 | if (MO.isReg() && MO.isDef() && MO.getReg() == ARM::CPSR) { |
| 6579 | definesCPSR = true; |
| 6580 | if (MO.isDead()) |
| 6581 | deadCPSR = true; |
| 6582 | MI->RemoveOperand(i); |
| 6583 | break; |
Evan Cheng | 37fefc2 | 2011-08-30 19:09:48 +0000 | [diff] [blame] | 6584 | } |
| 6585 | } |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6586 | if (!definesCPSR) { |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 6587 | assert(!NewOpc && "Optional cc_out operand required"); |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6588 | return; |
| 6589 | } |
| 6590 | assert(deadCPSR == !Node->hasAnyUseOfValue(1) && "inconsistent dead flag"); |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 6591 | if (deadCPSR) { |
| 6592 | assert(!MI->getOperand(ccOutIdx).getReg() && |
| 6593 | "expect uninitialized optional cc_out operand"); |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6594 | return; |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 6595 | } |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6596 | |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 6597 | // If this instruction was defined with an optional CPSR def and its dag node |
| 6598 | // had a live implicit CPSR def, then activate the optional CPSR def. |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6599 | MachineOperand &MO = MI->getOperand(ccOutIdx); |
| 6600 | MO.setReg(ARM::CPSR); |
| 6601 | MO.setIsDef(true); |
Evan Cheng | 37fefc2 | 2011-08-30 19:09:48 +0000 | [diff] [blame] | 6602 | } |
| 6603 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6604 | //===----------------------------------------------------------------------===// |
| 6605 | // ARM Optimization Hooks |
| 6606 | //===----------------------------------------------------------------------===// |
| 6607 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 6608 | static |
| 6609 | SDValue combineSelectAndUse(SDNode *N, SDValue Slct, SDValue OtherOp, |
| 6610 | TargetLowering::DAGCombinerInfo &DCI) { |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 6611 | SelectionDAG &DAG = DCI.DAG; |
| 6612 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6613 | EVT VT = N->getValueType(0); |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 6614 | unsigned Opc = N->getOpcode(); |
| 6615 | bool isSlctCC = Slct.getOpcode() == ISD::SELECT_CC; |
| 6616 | SDValue LHS = isSlctCC ? Slct.getOperand(2) : Slct.getOperand(1); |
| 6617 | SDValue RHS = isSlctCC ? Slct.getOperand(3) : Slct.getOperand(2); |
| 6618 | ISD::CondCode CC = ISD::SETCC_INVALID; |
| 6619 | |
| 6620 | if (isSlctCC) { |
| 6621 | CC = cast<CondCodeSDNode>(Slct.getOperand(4))->get(); |
| 6622 | } else { |
| 6623 | SDValue CCOp = Slct.getOperand(0); |
| 6624 | if (CCOp.getOpcode() == ISD::SETCC) |
| 6625 | CC = cast<CondCodeSDNode>(CCOp.getOperand(2))->get(); |
| 6626 | } |
| 6627 | |
| 6628 | bool DoXform = false; |
| 6629 | bool InvCC = false; |
| 6630 | assert ((Opc == ISD::ADD || (Opc == ISD::SUB && Slct == N->getOperand(1))) && |
| 6631 | "Bad input!"); |
| 6632 | |
| 6633 | if (LHS.getOpcode() == ISD::Constant && |
| 6634 | cast<ConstantSDNode>(LHS)->isNullValue()) { |
| 6635 | DoXform = true; |
| 6636 | } else if (CC != ISD::SETCC_INVALID && |
| 6637 | RHS.getOpcode() == ISD::Constant && |
| 6638 | cast<ConstantSDNode>(RHS)->isNullValue()) { |
| 6639 | std::swap(LHS, RHS); |
| 6640 | SDValue Op0 = Slct.getOperand(0); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6641 | EVT OpVT = isSlctCC ? Op0.getValueType() : |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 6642 | Op0.getOperand(0).getValueType(); |
| 6643 | bool isInt = OpVT.isInteger(); |
| 6644 | CC = ISD::getSetCCInverse(CC, isInt); |
| 6645 | |
| 6646 | if (!TLI.isCondCodeLegal(CC, OpVT)) |
| 6647 | return SDValue(); // Inverse operator isn't legal. |
| 6648 | |
| 6649 | DoXform = true; |
| 6650 | InvCC = true; |
| 6651 | } |
| 6652 | |
| 6653 | if (DoXform) { |
| 6654 | SDValue Result = DAG.getNode(Opc, RHS.getDebugLoc(), VT, OtherOp, RHS); |
| 6655 | if (isSlctCC) |
| 6656 | return DAG.getSelectCC(N->getDebugLoc(), OtherOp, Result, |
| 6657 | Slct.getOperand(0), Slct.getOperand(1), CC); |
| 6658 | SDValue CCOp = Slct.getOperand(0); |
| 6659 | if (InvCC) |
| 6660 | CCOp = DAG.getSetCC(Slct.getDebugLoc(), CCOp.getValueType(), |
| 6661 | CCOp.getOperand(0), CCOp.getOperand(1), CC); |
| 6662 | return DAG.getNode(ISD::SELECT, N->getDebugLoc(), VT, |
| 6663 | CCOp, OtherOp, Result); |
| 6664 | } |
| 6665 | return SDValue(); |
| 6666 | } |
| 6667 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 6668 | // AddCombineToVPADDL- For pair-wise add on neon, use the vpaddl instruction |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6669 | // (only after legalization). |
| 6670 | static SDValue AddCombineToVPADDL(SDNode *N, SDValue N0, SDValue N1, |
| 6671 | TargetLowering::DAGCombinerInfo &DCI, |
| 6672 | const ARMSubtarget *Subtarget) { |
| 6673 | |
| 6674 | // Only perform optimization if after legalize, and if NEON is available. We |
| 6675 | // also expected both operands to be BUILD_VECTORs. |
| 6676 | if (DCI.isBeforeLegalize() || !Subtarget->hasNEON() |
| 6677 | || N0.getOpcode() != ISD::BUILD_VECTOR |
| 6678 | || N1.getOpcode() != ISD::BUILD_VECTOR) |
| 6679 | return SDValue(); |
| 6680 | |
| 6681 | // Check output type since VPADDL operand elements can only be 8, 16, or 32. |
| 6682 | EVT VT = N->getValueType(0); |
| 6683 | if (!VT.isInteger() || VT.getVectorElementType() == MVT::i64) |
| 6684 | return SDValue(); |
| 6685 | |
| 6686 | // Check that the vector operands are of the right form. |
| 6687 | // N0 and N1 are BUILD_VECTOR nodes with N number of EXTRACT_VECTOR |
| 6688 | // operands, where N is the size of the formed vector. |
| 6689 | // Each EXTRACT_VECTOR should have the same input vector and odd or even |
| 6690 | // index such that we have a pair wise add pattern. |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6691 | |
| 6692 | // Grab the vector that all EXTRACT_VECTOR nodes should be referencing. |
Bob Wilson | 7a10ab7 | 2011-06-15 06:04:34 +0000 | [diff] [blame] | 6693 | if (N0->getOperand(0)->getOpcode() != ISD::EXTRACT_VECTOR_ELT) |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6694 | return SDValue(); |
Bob Wilson | 7a10ab7 | 2011-06-15 06:04:34 +0000 | [diff] [blame] | 6695 | SDValue Vec = N0->getOperand(0)->getOperand(0); |
| 6696 | SDNode *V = Vec.getNode(); |
| 6697 | unsigned nextIndex = 0; |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6698 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 6699 | // For each operands to the ADD which are BUILD_VECTORs, |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6700 | // check to see if each of their operands are an EXTRACT_VECTOR with |
| 6701 | // the same vector and appropriate index. |
| 6702 | for (unsigned i = 0, e = N0->getNumOperands(); i != e; ++i) { |
| 6703 | if (N0->getOperand(i)->getOpcode() == ISD::EXTRACT_VECTOR_ELT |
| 6704 | && N1->getOperand(i)->getOpcode() == ISD::EXTRACT_VECTOR_ELT) { |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 6705 | |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6706 | SDValue ExtVec0 = N0->getOperand(i); |
| 6707 | SDValue ExtVec1 = N1->getOperand(i); |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 6708 | |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6709 | // First operand is the vector, verify its the same. |
| 6710 | if (V != ExtVec0->getOperand(0).getNode() || |
| 6711 | V != ExtVec1->getOperand(0).getNode()) |
| 6712 | return SDValue(); |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 6713 | |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6714 | // Second is the constant, verify its correct. |
| 6715 | ConstantSDNode *C0 = dyn_cast<ConstantSDNode>(ExtVec0->getOperand(1)); |
| 6716 | ConstantSDNode *C1 = dyn_cast<ConstantSDNode>(ExtVec1->getOperand(1)); |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 6717 | |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6718 | // For the constant, we want to see all the even or all the odd. |
| 6719 | if (!C0 || !C1 || C0->getZExtValue() != nextIndex |
| 6720 | || C1->getZExtValue() != nextIndex+1) |
| 6721 | return SDValue(); |
| 6722 | |
| 6723 | // Increment index. |
| 6724 | nextIndex+=2; |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 6725 | } else |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6726 | return SDValue(); |
| 6727 | } |
| 6728 | |
| 6729 | // Create VPADDL node. |
| 6730 | SelectionDAG &DAG = DCI.DAG; |
| 6731 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6732 | |
| 6733 | // Build operand list. |
| 6734 | SmallVector<SDValue, 8> Ops; |
| 6735 | Ops.push_back(DAG.getConstant(Intrinsic::arm_neon_vpaddls, |
| 6736 | TLI.getPointerTy())); |
| 6737 | |
| 6738 | // Input is the vector. |
| 6739 | Ops.push_back(Vec); |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 6740 | |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6741 | // Get widened type and narrowed type. |
| 6742 | MVT widenType; |
| 6743 | unsigned numElem = VT.getVectorNumElements(); |
| 6744 | switch (VT.getVectorElementType().getSimpleVT().SimpleTy) { |
| 6745 | case MVT::i8: widenType = MVT::getVectorVT(MVT::i16, numElem); break; |
| 6746 | case MVT::i16: widenType = MVT::getVectorVT(MVT::i32, numElem); break; |
| 6747 | case MVT::i32: widenType = MVT::getVectorVT(MVT::i64, numElem); break; |
| 6748 | default: |
Craig Topper | bc21981 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 6749 | llvm_unreachable("Invalid vector element type for padd optimization."); |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6750 | } |
| 6751 | |
| 6752 | SDValue tmp = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, N->getDebugLoc(), |
| 6753 | widenType, &Ops[0], Ops.size()); |
| 6754 | return DAG.getNode(ISD::TRUNCATE, N->getDebugLoc(), VT, tmp); |
| 6755 | } |
| 6756 | |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 6757 | /// PerformADDCombineWithOperands - Try DAG combinations for an ADD with |
| 6758 | /// operands N0 and N1. This is a helper for PerformADDCombine that is |
| 6759 | /// called with the default operands, and if that fails, with commuted |
| 6760 | /// operands. |
| 6761 | static SDValue PerformADDCombineWithOperands(SDNode *N, SDValue N0, SDValue N1, |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6762 | TargetLowering::DAGCombinerInfo &DCI, |
| 6763 | const ARMSubtarget *Subtarget){ |
| 6764 | |
| 6765 | // Attempt to create vpaddl for this add. |
| 6766 | SDValue Result = AddCombineToVPADDL(N, N0, N1, DCI, Subtarget); |
| 6767 | if (Result.getNode()) |
| 6768 | return Result; |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 6769 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 6770 | // fold (add (select cc, 0, c), x) -> (select cc, x, (add, x, c)) |
| 6771 | if (N0.getOpcode() == ISD::SELECT && N0.getNode()->hasOneUse()) { |
| 6772 | SDValue Result = combineSelectAndUse(N, N0, N1, DCI); |
| 6773 | if (Result.getNode()) return Result; |
| 6774 | } |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 6775 | return SDValue(); |
| 6776 | } |
| 6777 | |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 6778 | /// PerformADDCombine - Target-specific dag combine xforms for ISD::ADD. |
| 6779 | /// |
| 6780 | static SDValue PerformADDCombine(SDNode *N, |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6781 | TargetLowering::DAGCombinerInfo &DCI, |
| 6782 | const ARMSubtarget *Subtarget) { |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 6783 | SDValue N0 = N->getOperand(0); |
| 6784 | SDValue N1 = N->getOperand(1); |
| 6785 | |
| 6786 | // First try with the default operand order. |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6787 | SDValue Result = PerformADDCombineWithOperands(N, N0, N1, DCI, Subtarget); |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 6788 | if (Result.getNode()) |
| 6789 | return Result; |
| 6790 | |
| 6791 | // If that didn't work, try again with the operands commuted. |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6792 | return PerformADDCombineWithOperands(N, N1, N0, DCI, Subtarget); |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 6793 | } |
| 6794 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 6795 | /// PerformSUBCombine - Target-specific dag combine xforms for ISD::SUB. |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 6796 | /// |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 6797 | static SDValue PerformSUBCombine(SDNode *N, |
| 6798 | TargetLowering::DAGCombinerInfo &DCI) { |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 6799 | SDValue N0 = N->getOperand(0); |
| 6800 | SDValue N1 = N->getOperand(1); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 6801 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 6802 | // fold (sub x, (select cc, 0, c)) -> (select cc, x, (sub, x, c)) |
| 6803 | if (N1.getOpcode() == ISD::SELECT && N1.getNode()->hasOneUse()) { |
| 6804 | SDValue Result = combineSelectAndUse(N, N1, N0, DCI); |
| 6805 | if (Result.getNode()) return Result; |
| 6806 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 6807 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 6808 | return SDValue(); |
| 6809 | } |
| 6810 | |
Evan Cheng | 463d358 | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 6811 | /// PerformVMULCombine |
| 6812 | /// Distribute (A + B) * C to (A * C) + (B * C) to take advantage of the |
| 6813 | /// special multiplier accumulator forwarding. |
| 6814 | /// vmul d3, d0, d2 |
| 6815 | /// vmla d3, d1, d2 |
| 6816 | /// is faster than |
| 6817 | /// vadd d3, d0, d1 |
| 6818 | /// vmul d3, d3, d2 |
| 6819 | static SDValue PerformVMULCombine(SDNode *N, |
| 6820 | TargetLowering::DAGCombinerInfo &DCI, |
| 6821 | const ARMSubtarget *Subtarget) { |
| 6822 | if (!Subtarget->hasVMLxForwarding()) |
| 6823 | return SDValue(); |
| 6824 | |
| 6825 | SelectionDAG &DAG = DCI.DAG; |
| 6826 | SDValue N0 = N->getOperand(0); |
| 6827 | SDValue N1 = N->getOperand(1); |
| 6828 | unsigned Opcode = N0.getOpcode(); |
| 6829 | if (Opcode != ISD::ADD && Opcode != ISD::SUB && |
| 6830 | Opcode != ISD::FADD && Opcode != ISD::FSUB) { |
Chad Rosier | 689edc8 | 2011-06-16 01:21:54 +0000 | [diff] [blame] | 6831 | Opcode = N1.getOpcode(); |
Evan Cheng | 463d358 | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 6832 | if (Opcode != ISD::ADD && Opcode != ISD::SUB && |
| 6833 | Opcode != ISD::FADD && Opcode != ISD::FSUB) |
| 6834 | return SDValue(); |
| 6835 | std::swap(N0, N1); |
| 6836 | } |
| 6837 | |
| 6838 | EVT VT = N->getValueType(0); |
| 6839 | DebugLoc DL = N->getDebugLoc(); |
| 6840 | SDValue N00 = N0->getOperand(0); |
| 6841 | SDValue N01 = N0->getOperand(1); |
| 6842 | return DAG.getNode(Opcode, DL, VT, |
| 6843 | DAG.getNode(ISD::MUL, DL, VT, N00, N1), |
| 6844 | DAG.getNode(ISD::MUL, DL, VT, N01, N1)); |
| 6845 | } |
| 6846 | |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 6847 | static SDValue PerformMULCombine(SDNode *N, |
| 6848 | TargetLowering::DAGCombinerInfo &DCI, |
| 6849 | const ARMSubtarget *Subtarget) { |
| 6850 | SelectionDAG &DAG = DCI.DAG; |
| 6851 | |
| 6852 | if (Subtarget->isThumb1Only()) |
| 6853 | return SDValue(); |
| 6854 | |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 6855 | if (DCI.isBeforeLegalize() || DCI.isCalledByLegalizer()) |
| 6856 | return SDValue(); |
| 6857 | |
| 6858 | EVT VT = N->getValueType(0); |
Evan Cheng | 463d358 | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 6859 | if (VT.is64BitVector() || VT.is128BitVector()) |
| 6860 | return PerformVMULCombine(N, DCI, Subtarget); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 6861 | if (VT != MVT::i32) |
| 6862 | return SDValue(); |
| 6863 | |
| 6864 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1)); |
| 6865 | if (!C) |
| 6866 | return SDValue(); |
| 6867 | |
Anton Korobeynikov | 2d7ea04 | 2012-03-19 19:19:50 +0000 | [diff] [blame^] | 6868 | int64_t MulAmt = C->getSExtValue(); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 6869 | unsigned ShiftAmt = CountTrailingZeros_64(MulAmt); |
Anton Korobeynikov | 2d7ea04 | 2012-03-19 19:19:50 +0000 | [diff] [blame^] | 6870 | |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 6871 | ShiftAmt = ShiftAmt & (32 - 1); |
| 6872 | SDValue V = N->getOperand(0); |
| 6873 | DebugLoc DL = N->getDebugLoc(); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 6874 | |
Anton Korobeynikov | 4878b84 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 6875 | SDValue Res; |
| 6876 | MulAmt >>= ShiftAmt; |
Anton Korobeynikov | 2d7ea04 | 2012-03-19 19:19:50 +0000 | [diff] [blame^] | 6877 | |
| 6878 | if (MulAmt >= 0) { |
| 6879 | if (isPowerOf2_32(MulAmt - 1)) { |
| 6880 | // (mul x, 2^N + 1) => (add (shl x, N), x) |
| 6881 | Res = DAG.getNode(ISD::ADD, DL, VT, |
| 6882 | V, |
| 6883 | DAG.getNode(ISD::SHL, DL, VT, |
| 6884 | V, |
| 6885 | DAG.getConstant(Log2_32(MulAmt - 1), |
| 6886 | MVT::i32))); |
| 6887 | } else if (isPowerOf2_32(MulAmt + 1)) { |
| 6888 | // (mul x, 2^N - 1) => (sub (shl x, N), x) |
| 6889 | Res = DAG.getNode(ISD::SUB, DL, VT, |
| 6890 | DAG.getNode(ISD::SHL, DL, VT, |
| 6891 | V, |
| 6892 | DAG.getConstant(Log2_32(MulAmt + 1), |
| 6893 | MVT::i32)), |
| 6894 | V); |
| 6895 | } else |
| 6896 | return SDValue(); |
| 6897 | } else { |
| 6898 | uint64_t MulAmtAbs = -MulAmt; |
| 6899 | if (isPowerOf2_32(MulAmtAbs + 1)) { |
| 6900 | // (mul x, -(2^N - 1)) => (sub x, (shl x, N)) |
| 6901 | Res = DAG.getNode(ISD::SUB, DL, VT, |
| 6902 | V, |
| 6903 | DAG.getNode(ISD::SHL, DL, VT, |
| 6904 | V, |
| 6905 | DAG.getConstant(Log2_32(MulAmtAbs + 1), |
| 6906 | MVT::i32))); |
| 6907 | } else if (isPowerOf2_32(MulAmtAbs - 1)) { |
| 6908 | // (mul x, -(2^N + 1)) => - (add (shl x, N), x) |
| 6909 | Res = DAG.getNode(ISD::ADD, DL, VT, |
| 6910 | V, |
| 6911 | DAG.getNode(ISD::SHL, DL, VT, |
| 6912 | V, |
| 6913 | DAG.getConstant(Log2_32(MulAmtAbs-1), |
| 6914 | MVT::i32))); |
| 6915 | Res = DAG.getNode(ISD::SUB, DL, VT, |
| 6916 | DAG.getConstant(0, MVT::i32),Res); |
| 6917 | |
| 6918 | } else |
| 6919 | return SDValue(); |
| 6920 | } |
Anton Korobeynikov | 4878b84 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 6921 | |
| 6922 | if (ShiftAmt != 0) |
Anton Korobeynikov | 2d7ea04 | 2012-03-19 19:19:50 +0000 | [diff] [blame^] | 6923 | Res = DAG.getNode(ISD::SHL, DL, VT, |
| 6924 | Res, DAG.getConstant(ShiftAmt, MVT::i32)); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 6925 | |
| 6926 | // Do not add new nodes to DAG combiner worklist. |
Anton Korobeynikov | 4878b84 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 6927 | DCI.CombineTo(N, Res, false); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 6928 | return SDValue(); |
| 6929 | } |
| 6930 | |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 6931 | static bool isCMOVWithZeroOrAllOnesLHS(SDValue N, bool AllOnes) { |
| 6932 | if (N.getOpcode() != ARMISD::CMOV || !N.getNode()->hasOneUse()) |
| 6933 | return false; |
| 6934 | |
| 6935 | SDValue FalseVal = N.getOperand(0); |
| 6936 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(FalseVal); |
| 6937 | if (!C) |
| 6938 | return false; |
| 6939 | if (AllOnes) |
| 6940 | return C->isAllOnesValue(); |
| 6941 | return C->isNullValue(); |
| 6942 | } |
| 6943 | |
| 6944 | /// formConditionalOp - Combine an operation with a conditional move operand |
| 6945 | /// to form a conditional op. e.g. (or x, (cmov 0, y, cond)) => (or.cond x, y) |
| 6946 | /// (and x, (cmov -1, y, cond)) => (and.cond, x, y) |
| 6947 | static SDValue formConditionalOp(SDNode *N, SelectionDAG &DAG, |
| 6948 | bool Commutable) { |
| 6949 | SDValue N0 = N->getOperand(0); |
| 6950 | SDValue N1 = N->getOperand(1); |
| 6951 | |
| 6952 | bool isAND = N->getOpcode() == ISD::AND; |
| 6953 | bool isCand = isCMOVWithZeroOrAllOnesLHS(N1, isAND); |
| 6954 | if (!isCand && Commutable) { |
| 6955 | isCand = isCMOVWithZeroOrAllOnesLHS(N0, isAND); |
| 6956 | if (isCand) |
| 6957 | std::swap(N0, N1); |
| 6958 | } |
| 6959 | if (!isCand) |
| 6960 | return SDValue(); |
| 6961 | |
| 6962 | unsigned Opc = 0; |
| 6963 | switch (N->getOpcode()) { |
| 6964 | default: llvm_unreachable("Unexpected node"); |
| 6965 | case ISD::AND: Opc = ARMISD::CAND; break; |
| 6966 | case ISD::OR: Opc = ARMISD::COR; break; |
| 6967 | case ISD::XOR: Opc = ARMISD::CXOR; break; |
| 6968 | } |
| 6969 | return DAG.getNode(Opc, N->getDebugLoc(), N->getValueType(0), N0, |
| 6970 | N1.getOperand(1), N1.getOperand(2), N1.getOperand(3), |
| 6971 | N1.getOperand(4)); |
| 6972 | } |
| 6973 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 6974 | static SDValue PerformANDCombine(SDNode *N, |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 6975 | TargetLowering::DAGCombinerInfo &DCI, |
| 6976 | const ARMSubtarget *Subtarget) { |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6977 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 6978 | // Attempt to use immediate-form VBIC |
| 6979 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(N->getOperand(1)); |
| 6980 | DebugLoc dl = N->getDebugLoc(); |
| 6981 | EVT VT = N->getValueType(0); |
| 6982 | SelectionDAG &DAG = DCI.DAG; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6983 | |
Tanya Lattner | 0433b21 | 2011-04-07 15:24:20 +0000 | [diff] [blame] | 6984 | if(!DAG.getTargetLoweringInfo().isTypeLegal(VT)) |
| 6985 | return SDValue(); |
Andrew Trick | 1c3af77 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 6986 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 6987 | APInt SplatBits, SplatUndef; |
| 6988 | unsigned SplatBitSize; |
| 6989 | bool HasAnyUndefs; |
| 6990 | if (BVN && |
| 6991 | BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { |
| 6992 | if (SplatBitSize <= 64) { |
| 6993 | EVT VbicVT; |
| 6994 | SDValue Val = isNEONModifiedImm((~SplatBits).getZExtValue(), |
| 6995 | SplatUndef.getZExtValue(), SplatBitSize, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6996 | DAG, VbicVT, VT.is128BitVector(), |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 6997 | OtherModImm); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 6998 | if (Val.getNode()) { |
| 6999 | SDValue Input = |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7000 | DAG.getNode(ISD::BITCAST, dl, VbicVT, N->getOperand(0)); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 7001 | SDValue Vbic = DAG.getNode(ARMISD::VBICIMM, dl, VbicVT, Input, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7002 | return DAG.getNode(ISD::BITCAST, dl, VT, Vbic); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 7003 | } |
| 7004 | } |
| 7005 | } |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7006 | |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 7007 | if (!Subtarget->isThumb1Only()) { |
| 7008 | // (and x, (cmov -1, y, cond)) => (and.cond x, y) |
| 7009 | SDValue CAND = formConditionalOp(N, DAG, true); |
| 7010 | if (CAND.getNode()) |
| 7011 | return CAND; |
| 7012 | } |
| 7013 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 7014 | return SDValue(); |
| 7015 | } |
| 7016 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 7017 | /// PerformORCombine - Target-specific dag combine xforms for ISD::OR |
| 7018 | static SDValue PerformORCombine(SDNode *N, |
| 7019 | TargetLowering::DAGCombinerInfo &DCI, |
| 7020 | const ARMSubtarget *Subtarget) { |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 7021 | // Attempt to use immediate-form VORR |
| 7022 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(N->getOperand(1)); |
| 7023 | DebugLoc dl = N->getDebugLoc(); |
| 7024 | EVT VT = N->getValueType(0); |
| 7025 | SelectionDAG &DAG = DCI.DAG; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7026 | |
Tanya Lattner | 0433b21 | 2011-04-07 15:24:20 +0000 | [diff] [blame] | 7027 | if(!DAG.getTargetLoweringInfo().isTypeLegal(VT)) |
| 7028 | return SDValue(); |
Andrew Trick | 1c3af77 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 7029 | |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 7030 | APInt SplatBits, SplatUndef; |
| 7031 | unsigned SplatBitSize; |
| 7032 | bool HasAnyUndefs; |
| 7033 | if (BVN && Subtarget->hasNEON() && |
| 7034 | BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { |
| 7035 | if (SplatBitSize <= 64) { |
| 7036 | EVT VorrVT; |
| 7037 | SDValue Val = isNEONModifiedImm(SplatBits.getZExtValue(), |
| 7038 | SplatUndef.getZExtValue(), SplatBitSize, |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 7039 | DAG, VorrVT, VT.is128BitVector(), |
| 7040 | OtherModImm); |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 7041 | if (Val.getNode()) { |
| 7042 | SDValue Input = |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7043 | DAG.getNode(ISD::BITCAST, dl, VorrVT, N->getOperand(0)); |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 7044 | SDValue Vorr = DAG.getNode(ARMISD::VORRIMM, dl, VorrVT, Input, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7045 | return DAG.getNode(ISD::BITCAST, dl, VT, Vorr); |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 7046 | } |
| 7047 | } |
| 7048 | } |
| 7049 | |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 7050 | if (!Subtarget->isThumb1Only()) { |
| 7051 | // (or x, (cmov 0, y, cond)) => (or.cond x, y) |
| 7052 | SDValue COR = formConditionalOp(N, DAG, true); |
| 7053 | if (COR.getNode()) |
| 7054 | return COR; |
| 7055 | } |
| 7056 | |
Cameron Zwarich | c0e6d78 | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 7057 | SDValue N0 = N->getOperand(0); |
| 7058 | if (N0.getOpcode() != ISD::AND) |
| 7059 | return SDValue(); |
| 7060 | SDValue N1 = N->getOperand(1); |
| 7061 | |
| 7062 | // (or (and B, A), (and C, ~A)) => (VBSL A, B, C) when A is a constant. |
| 7063 | if (Subtarget->hasNEON() && N1.getOpcode() == ISD::AND && VT.isVector() && |
| 7064 | DAG.getTargetLoweringInfo().isTypeLegal(VT)) { |
| 7065 | APInt SplatUndef; |
| 7066 | unsigned SplatBitSize; |
| 7067 | bool HasAnyUndefs; |
| 7068 | |
| 7069 | BuildVectorSDNode *BVN0 = dyn_cast<BuildVectorSDNode>(N0->getOperand(1)); |
| 7070 | APInt SplatBits0; |
| 7071 | if (BVN0 && BVN0->isConstantSplat(SplatBits0, SplatUndef, SplatBitSize, |
| 7072 | HasAnyUndefs) && !HasAnyUndefs) { |
| 7073 | BuildVectorSDNode *BVN1 = dyn_cast<BuildVectorSDNode>(N1->getOperand(1)); |
| 7074 | APInt SplatBits1; |
| 7075 | if (BVN1 && BVN1->isConstantSplat(SplatBits1, SplatUndef, SplatBitSize, |
| 7076 | HasAnyUndefs) && !HasAnyUndefs && |
| 7077 | SplatBits0 == ~SplatBits1) { |
| 7078 | // Canonicalize the vector type to make instruction selection simpler. |
| 7079 | EVT CanonicalVT = VT.is128BitVector() ? MVT::v4i32 : MVT::v2i32; |
| 7080 | SDValue Result = DAG.getNode(ARMISD::VBSL, dl, CanonicalVT, |
| 7081 | N0->getOperand(1), N0->getOperand(0), |
Cameron Zwarich | 5af60ce | 2011-04-13 21:01:19 +0000 | [diff] [blame] | 7082 | N1->getOperand(0)); |
Cameron Zwarich | c0e6d78 | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 7083 | return DAG.getNode(ISD::BITCAST, dl, VT, Result); |
| 7084 | } |
| 7085 | } |
| 7086 | } |
| 7087 | |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7088 | // Try to use the ARM/Thumb2 BFI (bitfield insert) instruction when |
| 7089 | // reasonable. |
| 7090 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 7091 | // BFI is only available on V6T2+ |
| 7092 | if (Subtarget->isThumb1Only() || !Subtarget->hasV6T2Ops()) |
| 7093 | return SDValue(); |
| 7094 | |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7095 | DebugLoc DL = N->getDebugLoc(); |
| 7096 | // 1) or (and A, mask), val => ARMbfi A, val, mask |
| 7097 | // iff (val & mask) == val |
| 7098 | // |
| 7099 | // 2) or (and A, mask), (and B, mask2) => ARMbfi A, (lsr B, amt), mask |
| 7100 | // 2a) iff isBitFieldInvertedMask(mask) && isBitFieldInvertedMask(~mask2) |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 7101 | // && mask == ~mask2 |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7102 | // 2b) iff isBitFieldInvertedMask(~mask) && isBitFieldInvertedMask(mask2) |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 7103 | // && ~mask == mask2 |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7104 | // (i.e., copy a bitfield value into another bitfield of the same width) |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 7105 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 7106 | if (VT != MVT::i32) |
| 7107 | return SDValue(); |
| 7108 | |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7109 | SDValue N00 = N0.getOperand(0); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7110 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 7111 | // The value and the mask need to be constants so we can verify this is |
| 7112 | // actually a bitfield set. If the mask is 0xffff, we can do better |
| 7113 | // via a movt instruction, so don't use BFI in that case. |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7114 | SDValue MaskOp = N0.getOperand(1); |
| 7115 | ConstantSDNode *MaskC = dyn_cast<ConstantSDNode>(MaskOp); |
| 7116 | if (!MaskC) |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 7117 | return SDValue(); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7118 | unsigned Mask = MaskC->getZExtValue(); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 7119 | if (Mask == 0xffff) |
| 7120 | return SDValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7121 | SDValue Res; |
| 7122 | // Case (1): or (and A, mask), val => ARMbfi A, val, mask |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7123 | ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1); |
| 7124 | if (N1C) { |
| 7125 | unsigned Val = N1C->getZExtValue(); |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 7126 | if ((Val & ~Mask) != Val) |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7127 | return SDValue(); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 7128 | |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 7129 | if (ARM::isBitFieldInvertedMask(Mask)) { |
| 7130 | Val >>= CountTrailingZeros_32(~Mask); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 7131 | |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7132 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N00, |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 7133 | DAG.getConstant(Val, MVT::i32), |
| 7134 | DAG.getConstant(Mask, MVT::i32)); |
| 7135 | |
| 7136 | // Do not add new nodes to DAG combiner worklist. |
| 7137 | DCI.CombineTo(N, Res, false); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7138 | return SDValue(); |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 7139 | } |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7140 | } else if (N1.getOpcode() == ISD::AND) { |
| 7141 | // case (2) or (and A, mask), (and B, mask2) => ARMbfi A, (lsr B, amt), mask |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7142 | ConstantSDNode *N11C = dyn_cast<ConstantSDNode>(N1.getOperand(1)); |
| 7143 | if (!N11C) |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7144 | return SDValue(); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7145 | unsigned Mask2 = N11C->getZExtValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7146 | |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 7147 | // Mask and ~Mask2 (or reverse) must be equivalent for the BFI pattern |
| 7148 | // as is to match. |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7149 | if (ARM::isBitFieldInvertedMask(Mask) && |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 7150 | (Mask == ~Mask2)) { |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7151 | // The pack halfword instruction works better for masks that fit it, |
| 7152 | // so use that when it's available. |
| 7153 | if (Subtarget->hasT2ExtractPack() && |
| 7154 | (Mask == 0xffff || Mask == 0xffff0000)) |
| 7155 | return SDValue(); |
| 7156 | // 2a |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 7157 | unsigned amt = CountTrailingZeros_32(Mask2); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7158 | Res = DAG.getNode(ISD::SRL, DL, VT, N1.getOperand(0), |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 7159 | DAG.getConstant(amt, MVT::i32)); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7160 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N00, Res, |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7161 | DAG.getConstant(Mask, MVT::i32)); |
| 7162 | // Do not add new nodes to DAG combiner worklist. |
| 7163 | DCI.CombineTo(N, Res, false); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7164 | return SDValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7165 | } else if (ARM::isBitFieldInvertedMask(~Mask) && |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 7166 | (~Mask == Mask2)) { |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7167 | // The pack halfword instruction works better for masks that fit it, |
| 7168 | // so use that when it's available. |
| 7169 | if (Subtarget->hasT2ExtractPack() && |
| 7170 | (Mask2 == 0xffff || Mask2 == 0xffff0000)) |
| 7171 | return SDValue(); |
| 7172 | // 2b |
| 7173 | unsigned lsb = CountTrailingZeros_32(Mask); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7174 | Res = DAG.getNode(ISD::SRL, DL, VT, N00, |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7175 | DAG.getConstant(lsb, MVT::i32)); |
| 7176 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N1.getOperand(0), Res, |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 7177 | DAG.getConstant(Mask2, MVT::i32)); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7178 | // Do not add new nodes to DAG combiner worklist. |
| 7179 | DCI.CombineTo(N, Res, false); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7180 | return SDValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7181 | } |
| 7182 | } |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7183 | |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7184 | if (DAG.MaskedValueIsZero(N1, MaskC->getAPIntValue()) && |
| 7185 | N00.getOpcode() == ISD::SHL && isa<ConstantSDNode>(N00.getOperand(1)) && |
| 7186 | ARM::isBitFieldInvertedMask(~Mask)) { |
| 7187 | // Case (3): or (and (shl A, #shamt), mask), B => ARMbfi B, A, ~mask |
| 7188 | // where lsb(mask) == #shamt and masked bits of B are known zero. |
| 7189 | SDValue ShAmt = N00.getOperand(1); |
| 7190 | unsigned ShAmtC = cast<ConstantSDNode>(ShAmt)->getZExtValue(); |
| 7191 | unsigned LSB = CountTrailingZeros_32(Mask); |
| 7192 | if (ShAmtC != LSB) |
| 7193 | return SDValue(); |
| 7194 | |
| 7195 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N1, N00.getOperand(0), |
| 7196 | DAG.getConstant(~Mask, MVT::i32)); |
| 7197 | |
| 7198 | // Do not add new nodes to DAG combiner worklist. |
| 7199 | DCI.CombineTo(N, Res, false); |
| 7200 | } |
| 7201 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 7202 | return SDValue(); |
| 7203 | } |
| 7204 | |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 7205 | static SDValue PerformXORCombine(SDNode *N, |
| 7206 | TargetLowering::DAGCombinerInfo &DCI, |
| 7207 | const ARMSubtarget *Subtarget) { |
| 7208 | EVT VT = N->getValueType(0); |
| 7209 | SelectionDAG &DAG = DCI.DAG; |
| 7210 | |
| 7211 | if(!DAG.getTargetLoweringInfo().isTypeLegal(VT)) |
| 7212 | return SDValue(); |
| 7213 | |
| 7214 | if (!Subtarget->isThumb1Only()) { |
| 7215 | // (xor x, (cmov 0, y, cond)) => (xor.cond x, y) |
| 7216 | SDValue CXOR = formConditionalOp(N, DAG, true); |
| 7217 | if (CXOR.getNode()) |
| 7218 | return CXOR; |
| 7219 | } |
| 7220 | |
| 7221 | return SDValue(); |
| 7222 | } |
| 7223 | |
Evan Cheng | bf188ae | 2011-06-15 01:12:31 +0000 | [diff] [blame] | 7224 | /// PerformBFICombine - (bfi A, (and B, Mask1), Mask2) -> (bfi A, B, Mask2) iff |
| 7225 | /// the bits being cleared by the AND are not demanded by the BFI. |
Evan Cheng | 0c1aec1 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 7226 | static SDValue PerformBFICombine(SDNode *N, |
| 7227 | TargetLowering::DAGCombinerInfo &DCI) { |
| 7228 | SDValue N1 = N->getOperand(1); |
| 7229 | if (N1.getOpcode() == ISD::AND) { |
| 7230 | ConstantSDNode *N11C = dyn_cast<ConstantSDNode>(N1.getOperand(1)); |
| 7231 | if (!N11C) |
| 7232 | return SDValue(); |
Evan Cheng | bf188ae | 2011-06-15 01:12:31 +0000 | [diff] [blame] | 7233 | unsigned InvMask = cast<ConstantSDNode>(N->getOperand(2))->getZExtValue(); |
| 7234 | unsigned LSB = CountTrailingZeros_32(~InvMask); |
| 7235 | unsigned Width = (32 - CountLeadingZeros_32(~InvMask)) - LSB; |
| 7236 | unsigned Mask = (1 << Width)-1; |
Evan Cheng | 0c1aec1 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 7237 | unsigned Mask2 = N11C->getZExtValue(); |
Evan Cheng | bf188ae | 2011-06-15 01:12:31 +0000 | [diff] [blame] | 7238 | if ((Mask & (~Mask2)) == 0) |
Evan Cheng | 0c1aec1 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 7239 | return DCI.DAG.getNode(ARMISD::BFI, N->getDebugLoc(), N->getValueType(0), |
| 7240 | N->getOperand(0), N1.getOperand(0), |
| 7241 | N->getOperand(2)); |
| 7242 | } |
| 7243 | return SDValue(); |
| 7244 | } |
| 7245 | |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 7246 | /// PerformVMOVRRDCombine - Target-specific dag combine xforms for |
| 7247 | /// ARMISD::VMOVRRD. |
| 7248 | static SDValue PerformVMOVRRDCombine(SDNode *N, |
| 7249 | TargetLowering::DAGCombinerInfo &DCI) { |
| 7250 | // vmovrrd(vmovdrr x, y) -> x,y |
| 7251 | SDValue InDouble = N->getOperand(0); |
| 7252 | if (InDouble.getOpcode() == ARMISD::VMOVDRR) |
| 7253 | return DCI.CombineTo(N, InDouble.getOperand(0), InDouble.getOperand(1)); |
Cameron Zwarich | 4071a71 | 2011-04-02 02:40:43 +0000 | [diff] [blame] | 7254 | |
| 7255 | // vmovrrd(load f64) -> (load i32), (load i32) |
| 7256 | SDNode *InNode = InDouble.getNode(); |
| 7257 | if (ISD::isNormalLoad(InNode) && InNode->hasOneUse() && |
| 7258 | InNode->getValueType(0) == MVT::f64 && |
| 7259 | InNode->getOperand(1).getOpcode() == ISD::FrameIndex && |
| 7260 | !cast<LoadSDNode>(InNode)->isVolatile()) { |
| 7261 | // TODO: Should this be done for non-FrameIndex operands? |
| 7262 | LoadSDNode *LD = cast<LoadSDNode>(InNode); |
| 7263 | |
| 7264 | SelectionDAG &DAG = DCI.DAG; |
| 7265 | DebugLoc DL = LD->getDebugLoc(); |
| 7266 | SDValue BasePtr = LD->getBasePtr(); |
| 7267 | SDValue NewLD1 = DAG.getLoad(MVT::i32, DL, LD->getChain(), BasePtr, |
| 7268 | LD->getPointerInfo(), LD->isVolatile(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 7269 | LD->isNonTemporal(), LD->isInvariant(), |
| 7270 | LD->getAlignment()); |
Cameron Zwarich | 4071a71 | 2011-04-02 02:40:43 +0000 | [diff] [blame] | 7271 | |
| 7272 | SDValue OffsetPtr = DAG.getNode(ISD::ADD, DL, MVT::i32, BasePtr, |
| 7273 | DAG.getConstant(4, MVT::i32)); |
| 7274 | SDValue NewLD2 = DAG.getLoad(MVT::i32, DL, NewLD1.getValue(1), OffsetPtr, |
| 7275 | LD->getPointerInfo(), LD->isVolatile(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 7276 | LD->isNonTemporal(), LD->isInvariant(), |
Cameron Zwarich | 4071a71 | 2011-04-02 02:40:43 +0000 | [diff] [blame] | 7277 | std::min(4U, LD->getAlignment() / 2)); |
| 7278 | |
| 7279 | DAG.ReplaceAllUsesOfValueWith(SDValue(LD, 1), NewLD2.getValue(1)); |
| 7280 | SDValue Result = DCI.CombineTo(N, NewLD1, NewLD2); |
| 7281 | DCI.RemoveFromWorklist(LD); |
| 7282 | DAG.DeleteNode(LD); |
| 7283 | return Result; |
| 7284 | } |
| 7285 | |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 7286 | return SDValue(); |
| 7287 | } |
| 7288 | |
| 7289 | /// PerformVMOVDRRCombine - Target-specific dag combine xforms for |
| 7290 | /// ARMISD::VMOVDRR. This is also used for BUILD_VECTORs with 2 operands. |
| 7291 | static SDValue PerformVMOVDRRCombine(SDNode *N, SelectionDAG &DAG) { |
| 7292 | // N=vmovrrd(X); vmovdrr(N:0, N:1) -> bit_convert(X) |
| 7293 | SDValue Op0 = N->getOperand(0); |
| 7294 | SDValue Op1 = N->getOperand(1); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7295 | if (Op0.getOpcode() == ISD::BITCAST) |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 7296 | Op0 = Op0.getOperand(0); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7297 | if (Op1.getOpcode() == ISD::BITCAST) |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 7298 | Op1 = Op1.getOperand(0); |
| 7299 | if (Op0.getOpcode() == ARMISD::VMOVRRD && |
| 7300 | Op0.getNode() == Op1.getNode() && |
| 7301 | Op0.getResNo() == 0 && Op1.getResNo() == 1) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7302 | return DAG.getNode(ISD::BITCAST, N->getDebugLoc(), |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 7303 | N->getValueType(0), Op0.getOperand(0)); |
| 7304 | return SDValue(); |
| 7305 | } |
| 7306 | |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 7307 | /// PerformSTORECombine - Target-specific dag combine xforms for |
| 7308 | /// ISD::STORE. |
| 7309 | static SDValue PerformSTORECombine(SDNode *N, |
| 7310 | TargetLowering::DAGCombinerInfo &DCI) { |
| 7311 | // Bitcast an i64 store extracted from a vector to f64. |
| 7312 | // Otherwise, the i64 value will be legalized to a pair of i32 values. |
| 7313 | StoreSDNode *St = cast<StoreSDNode>(N); |
| 7314 | SDValue StVal = St->getValue(); |
Cameron Zwarich | d0aacbc | 2011-04-12 02:24:17 +0000 | [diff] [blame] | 7315 | if (!ISD::isNormalStore(St) || St->isVolatile()) |
| 7316 | return SDValue(); |
| 7317 | |
| 7318 | if (StVal.getNode()->getOpcode() == ARMISD::VMOVDRR && |
| 7319 | StVal.getNode()->hasOneUse() && !St->isVolatile()) { |
| 7320 | SelectionDAG &DAG = DCI.DAG; |
| 7321 | DebugLoc DL = St->getDebugLoc(); |
| 7322 | SDValue BasePtr = St->getBasePtr(); |
| 7323 | SDValue NewST1 = DAG.getStore(St->getChain(), DL, |
| 7324 | StVal.getNode()->getOperand(0), BasePtr, |
| 7325 | St->getPointerInfo(), St->isVolatile(), |
| 7326 | St->isNonTemporal(), St->getAlignment()); |
| 7327 | |
| 7328 | SDValue OffsetPtr = DAG.getNode(ISD::ADD, DL, MVT::i32, BasePtr, |
| 7329 | DAG.getConstant(4, MVT::i32)); |
| 7330 | return DAG.getStore(NewST1.getValue(0), DL, StVal.getNode()->getOperand(1), |
| 7331 | OffsetPtr, St->getPointerInfo(), St->isVolatile(), |
| 7332 | St->isNonTemporal(), |
| 7333 | std::min(4U, St->getAlignment() / 2)); |
| 7334 | } |
| 7335 | |
| 7336 | if (StVal.getValueType() != MVT::i64 || |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 7337 | StVal.getNode()->getOpcode() != ISD::EXTRACT_VECTOR_ELT) |
| 7338 | return SDValue(); |
| 7339 | |
| 7340 | SelectionDAG &DAG = DCI.DAG; |
| 7341 | DebugLoc dl = StVal.getDebugLoc(); |
| 7342 | SDValue IntVec = StVal.getOperand(0); |
| 7343 | EVT FloatVT = EVT::getVectorVT(*DAG.getContext(), MVT::f64, |
| 7344 | IntVec.getValueType().getVectorNumElements()); |
| 7345 | SDValue Vec = DAG.getNode(ISD::BITCAST, dl, FloatVT, IntVec); |
| 7346 | SDValue ExtElt = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, |
| 7347 | Vec, StVal.getOperand(1)); |
| 7348 | dl = N->getDebugLoc(); |
| 7349 | SDValue V = DAG.getNode(ISD::BITCAST, dl, MVT::i64, ExtElt); |
| 7350 | // Make the DAGCombiner fold the bitcasts. |
| 7351 | DCI.AddToWorklist(Vec.getNode()); |
| 7352 | DCI.AddToWorklist(ExtElt.getNode()); |
| 7353 | DCI.AddToWorklist(V.getNode()); |
| 7354 | return DAG.getStore(St->getChain(), dl, V, St->getBasePtr(), |
| 7355 | St->getPointerInfo(), St->isVolatile(), |
| 7356 | St->isNonTemporal(), St->getAlignment(), |
| 7357 | St->getTBAAInfo()); |
| 7358 | } |
| 7359 | |
| 7360 | /// hasNormalLoadOperand - Check if any of the operands of a BUILD_VECTOR node |
| 7361 | /// are normal, non-volatile loads. If so, it is profitable to bitcast an |
| 7362 | /// i64 vector to have f64 elements, since the value can then be loaded |
| 7363 | /// directly into a VFP register. |
| 7364 | static bool hasNormalLoadOperand(SDNode *N) { |
| 7365 | unsigned NumElts = N->getValueType(0).getVectorNumElements(); |
| 7366 | for (unsigned i = 0; i < NumElts; ++i) { |
| 7367 | SDNode *Elt = N->getOperand(i).getNode(); |
| 7368 | if (ISD::isNormalLoad(Elt) && !cast<LoadSDNode>(Elt)->isVolatile()) |
| 7369 | return true; |
| 7370 | } |
| 7371 | return false; |
| 7372 | } |
| 7373 | |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 7374 | /// PerformBUILD_VECTORCombine - Target-specific dag combine xforms for |
| 7375 | /// ISD::BUILD_VECTOR. |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 7376 | static SDValue PerformBUILD_VECTORCombine(SDNode *N, |
| 7377 | TargetLowering::DAGCombinerInfo &DCI){ |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 7378 | // build_vector(N=ARMISD::VMOVRRD(X), N:1) -> bit_convert(X): |
| 7379 | // VMOVRRD is introduced when legalizing i64 types. It forces the i64 value |
| 7380 | // into a pair of GPRs, which is fine when the value is used as a scalar, |
| 7381 | // but if the i64 value is converted to a vector, we need to undo the VMOVRRD. |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 7382 | SelectionDAG &DAG = DCI.DAG; |
| 7383 | if (N->getNumOperands() == 2) { |
| 7384 | SDValue RV = PerformVMOVDRRCombine(N, DAG); |
| 7385 | if (RV.getNode()) |
| 7386 | return RV; |
| 7387 | } |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 7388 | |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 7389 | // Load i64 elements as f64 values so that type legalization does not split |
| 7390 | // them up into i32 values. |
| 7391 | EVT VT = N->getValueType(0); |
| 7392 | if (VT.getVectorElementType() != MVT::i64 || !hasNormalLoadOperand(N)) |
| 7393 | return SDValue(); |
| 7394 | DebugLoc dl = N->getDebugLoc(); |
| 7395 | SmallVector<SDValue, 8> Ops; |
| 7396 | unsigned NumElts = VT.getVectorNumElements(); |
| 7397 | for (unsigned i = 0; i < NumElts; ++i) { |
| 7398 | SDValue V = DAG.getNode(ISD::BITCAST, dl, MVT::f64, N->getOperand(i)); |
| 7399 | Ops.push_back(V); |
| 7400 | // Make the DAGCombiner fold the bitcast. |
| 7401 | DCI.AddToWorklist(V.getNode()); |
| 7402 | } |
| 7403 | EVT FloatVT = EVT::getVectorVT(*DAG.getContext(), MVT::f64, NumElts); |
| 7404 | SDValue BV = DAG.getNode(ISD::BUILD_VECTOR, dl, FloatVT, Ops.data(), NumElts); |
| 7405 | return DAG.getNode(ISD::BITCAST, dl, VT, BV); |
| 7406 | } |
| 7407 | |
| 7408 | /// PerformInsertEltCombine - Target-specific dag combine xforms for |
| 7409 | /// ISD::INSERT_VECTOR_ELT. |
| 7410 | static SDValue PerformInsertEltCombine(SDNode *N, |
| 7411 | TargetLowering::DAGCombinerInfo &DCI) { |
| 7412 | // Bitcast an i64 load inserted into a vector to f64. |
| 7413 | // Otherwise, the i64 value will be legalized to a pair of i32 values. |
| 7414 | EVT VT = N->getValueType(0); |
| 7415 | SDNode *Elt = N->getOperand(1).getNode(); |
| 7416 | if (VT.getVectorElementType() != MVT::i64 || |
| 7417 | !ISD::isNormalLoad(Elt) || cast<LoadSDNode>(Elt)->isVolatile()) |
| 7418 | return SDValue(); |
| 7419 | |
| 7420 | SelectionDAG &DAG = DCI.DAG; |
| 7421 | DebugLoc dl = N->getDebugLoc(); |
| 7422 | EVT FloatVT = EVT::getVectorVT(*DAG.getContext(), MVT::f64, |
| 7423 | VT.getVectorNumElements()); |
| 7424 | SDValue Vec = DAG.getNode(ISD::BITCAST, dl, FloatVT, N->getOperand(0)); |
| 7425 | SDValue V = DAG.getNode(ISD::BITCAST, dl, MVT::f64, N->getOperand(1)); |
| 7426 | // Make the DAGCombiner fold the bitcasts. |
| 7427 | DCI.AddToWorklist(Vec.getNode()); |
| 7428 | DCI.AddToWorklist(V.getNode()); |
| 7429 | SDValue InsElt = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, FloatVT, |
| 7430 | Vec, V, N->getOperand(2)); |
| 7431 | return DAG.getNode(ISD::BITCAST, dl, VT, InsElt); |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 7432 | } |
| 7433 | |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 7434 | /// PerformVECTOR_SHUFFLECombine - Target-specific dag combine xforms for |
| 7435 | /// ISD::VECTOR_SHUFFLE. |
| 7436 | static SDValue PerformVECTOR_SHUFFLECombine(SDNode *N, SelectionDAG &DAG) { |
| 7437 | // The LLVM shufflevector instruction does not require the shuffle mask |
| 7438 | // length to match the operand vector length, but ISD::VECTOR_SHUFFLE does |
| 7439 | // have that requirement. When translating to ISD::VECTOR_SHUFFLE, if the |
| 7440 | // operands do not match the mask length, they are extended by concatenating |
| 7441 | // them with undef vectors. That is probably the right thing for other |
| 7442 | // targets, but for NEON it is better to concatenate two double-register |
| 7443 | // size vector operands into a single quad-register size vector. Do that |
| 7444 | // transformation here: |
| 7445 | // shuffle(concat(v1, undef), concat(v2, undef)) -> |
| 7446 | // shuffle(concat(v1, v2), undef) |
| 7447 | SDValue Op0 = N->getOperand(0); |
| 7448 | SDValue Op1 = N->getOperand(1); |
| 7449 | if (Op0.getOpcode() != ISD::CONCAT_VECTORS || |
| 7450 | Op1.getOpcode() != ISD::CONCAT_VECTORS || |
| 7451 | Op0.getNumOperands() != 2 || |
| 7452 | Op1.getNumOperands() != 2) |
| 7453 | return SDValue(); |
| 7454 | SDValue Concat0Op1 = Op0.getOperand(1); |
| 7455 | SDValue Concat1Op1 = Op1.getOperand(1); |
| 7456 | if (Concat0Op1.getOpcode() != ISD::UNDEF || |
| 7457 | Concat1Op1.getOpcode() != ISD::UNDEF) |
| 7458 | return SDValue(); |
| 7459 | // Skip the transformation if any of the types are illegal. |
| 7460 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 7461 | EVT VT = N->getValueType(0); |
| 7462 | if (!TLI.isTypeLegal(VT) || |
| 7463 | !TLI.isTypeLegal(Concat0Op1.getValueType()) || |
| 7464 | !TLI.isTypeLegal(Concat1Op1.getValueType())) |
| 7465 | return SDValue(); |
| 7466 | |
| 7467 | SDValue NewConcat = DAG.getNode(ISD::CONCAT_VECTORS, N->getDebugLoc(), VT, |
| 7468 | Op0.getOperand(0), Op1.getOperand(0)); |
| 7469 | // Translate the shuffle mask. |
| 7470 | SmallVector<int, 16> NewMask; |
| 7471 | unsigned NumElts = VT.getVectorNumElements(); |
| 7472 | unsigned HalfElts = NumElts/2; |
| 7473 | ShuffleVectorSDNode *SVN = cast<ShuffleVectorSDNode>(N); |
| 7474 | for (unsigned n = 0; n < NumElts; ++n) { |
| 7475 | int MaskElt = SVN->getMaskElt(n); |
| 7476 | int NewElt = -1; |
Bob Wilson | 1fa9d30 | 2010-10-27 23:49:00 +0000 | [diff] [blame] | 7477 | if (MaskElt < (int)HalfElts) |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 7478 | NewElt = MaskElt; |
Bob Wilson | 1fa9d30 | 2010-10-27 23:49:00 +0000 | [diff] [blame] | 7479 | else if (MaskElt >= (int)NumElts && MaskElt < (int)(NumElts + HalfElts)) |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 7480 | NewElt = HalfElts + MaskElt - NumElts; |
| 7481 | NewMask.push_back(NewElt); |
| 7482 | } |
| 7483 | return DAG.getVectorShuffle(VT, N->getDebugLoc(), NewConcat, |
| 7484 | DAG.getUNDEF(VT), NewMask.data()); |
| 7485 | } |
| 7486 | |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 7487 | /// CombineBaseUpdate - Target-specific DAG combine function for VLDDUP and |
| 7488 | /// NEON load/store intrinsics to merge base address updates. |
| 7489 | static SDValue CombineBaseUpdate(SDNode *N, |
| 7490 | TargetLowering::DAGCombinerInfo &DCI) { |
| 7491 | if (DCI.isBeforeLegalize() || DCI.isCalledByLegalizer()) |
| 7492 | return SDValue(); |
| 7493 | |
| 7494 | SelectionDAG &DAG = DCI.DAG; |
| 7495 | bool isIntrinsic = (N->getOpcode() == ISD::INTRINSIC_VOID || |
| 7496 | N->getOpcode() == ISD::INTRINSIC_W_CHAIN); |
| 7497 | unsigned AddrOpIdx = (isIntrinsic ? 2 : 1); |
| 7498 | SDValue Addr = N->getOperand(AddrOpIdx); |
| 7499 | |
| 7500 | // Search for a use of the address operand that is an increment. |
| 7501 | for (SDNode::use_iterator UI = Addr.getNode()->use_begin(), |
| 7502 | UE = Addr.getNode()->use_end(); UI != UE; ++UI) { |
| 7503 | SDNode *User = *UI; |
| 7504 | if (User->getOpcode() != ISD::ADD || |
| 7505 | UI.getUse().getResNo() != Addr.getResNo()) |
| 7506 | continue; |
| 7507 | |
| 7508 | // Check that the add is independent of the load/store. Otherwise, folding |
| 7509 | // it would create a cycle. |
| 7510 | if (User->isPredecessorOf(N) || N->isPredecessorOf(User)) |
| 7511 | continue; |
| 7512 | |
| 7513 | // Find the new opcode for the updating load/store. |
| 7514 | bool isLoad = true; |
| 7515 | bool isLaneOp = false; |
| 7516 | unsigned NewOpc = 0; |
| 7517 | unsigned NumVecs = 0; |
| 7518 | if (isIntrinsic) { |
| 7519 | unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue(); |
| 7520 | switch (IntNo) { |
Craig Topper | bc21981 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 7521 | default: llvm_unreachable("unexpected intrinsic for Neon base update"); |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 7522 | case Intrinsic::arm_neon_vld1: NewOpc = ARMISD::VLD1_UPD; |
| 7523 | NumVecs = 1; break; |
| 7524 | case Intrinsic::arm_neon_vld2: NewOpc = ARMISD::VLD2_UPD; |
| 7525 | NumVecs = 2; break; |
| 7526 | case Intrinsic::arm_neon_vld3: NewOpc = ARMISD::VLD3_UPD; |
| 7527 | NumVecs = 3; break; |
| 7528 | case Intrinsic::arm_neon_vld4: NewOpc = ARMISD::VLD4_UPD; |
| 7529 | NumVecs = 4; break; |
| 7530 | case Intrinsic::arm_neon_vld2lane: NewOpc = ARMISD::VLD2LN_UPD; |
| 7531 | NumVecs = 2; isLaneOp = true; break; |
| 7532 | case Intrinsic::arm_neon_vld3lane: NewOpc = ARMISD::VLD3LN_UPD; |
| 7533 | NumVecs = 3; isLaneOp = true; break; |
| 7534 | case Intrinsic::arm_neon_vld4lane: NewOpc = ARMISD::VLD4LN_UPD; |
| 7535 | NumVecs = 4; isLaneOp = true; break; |
| 7536 | case Intrinsic::arm_neon_vst1: NewOpc = ARMISD::VST1_UPD; |
| 7537 | NumVecs = 1; isLoad = false; break; |
| 7538 | case Intrinsic::arm_neon_vst2: NewOpc = ARMISD::VST2_UPD; |
| 7539 | NumVecs = 2; isLoad = false; break; |
| 7540 | case Intrinsic::arm_neon_vst3: NewOpc = ARMISD::VST3_UPD; |
| 7541 | NumVecs = 3; isLoad = false; break; |
| 7542 | case Intrinsic::arm_neon_vst4: NewOpc = ARMISD::VST4_UPD; |
| 7543 | NumVecs = 4; isLoad = false; break; |
| 7544 | case Intrinsic::arm_neon_vst2lane: NewOpc = ARMISD::VST2LN_UPD; |
| 7545 | NumVecs = 2; isLoad = false; isLaneOp = true; break; |
| 7546 | case Intrinsic::arm_neon_vst3lane: NewOpc = ARMISD::VST3LN_UPD; |
| 7547 | NumVecs = 3; isLoad = false; isLaneOp = true; break; |
| 7548 | case Intrinsic::arm_neon_vst4lane: NewOpc = ARMISD::VST4LN_UPD; |
| 7549 | NumVecs = 4; isLoad = false; isLaneOp = true; break; |
| 7550 | } |
| 7551 | } else { |
| 7552 | isLaneOp = true; |
| 7553 | switch (N->getOpcode()) { |
Craig Topper | bc21981 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 7554 | default: llvm_unreachable("unexpected opcode for Neon base update"); |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 7555 | case ARMISD::VLD2DUP: NewOpc = ARMISD::VLD2DUP_UPD; NumVecs = 2; break; |
| 7556 | case ARMISD::VLD3DUP: NewOpc = ARMISD::VLD3DUP_UPD; NumVecs = 3; break; |
| 7557 | case ARMISD::VLD4DUP: NewOpc = ARMISD::VLD4DUP_UPD; NumVecs = 4; break; |
| 7558 | } |
| 7559 | } |
| 7560 | |
| 7561 | // Find the size of memory referenced by the load/store. |
| 7562 | EVT VecTy; |
| 7563 | if (isLoad) |
| 7564 | VecTy = N->getValueType(0); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 7565 | else |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 7566 | VecTy = N->getOperand(AddrOpIdx+1).getValueType(); |
| 7567 | unsigned NumBytes = NumVecs * VecTy.getSizeInBits() / 8; |
| 7568 | if (isLaneOp) |
| 7569 | NumBytes /= VecTy.getVectorNumElements(); |
| 7570 | |
| 7571 | // If the increment is a constant, it must match the memory ref size. |
| 7572 | SDValue Inc = User->getOperand(User->getOperand(0) == Addr ? 1 : 0); |
| 7573 | if (ConstantSDNode *CInc = dyn_cast<ConstantSDNode>(Inc.getNode())) { |
| 7574 | uint64_t IncVal = CInc->getZExtValue(); |
| 7575 | if (IncVal != NumBytes) |
| 7576 | continue; |
| 7577 | } else if (NumBytes >= 3 * 16) { |
| 7578 | // VLD3/4 and VST3/4 for 128-bit vectors are implemented with two |
| 7579 | // separate instructions that make it harder to use a non-constant update. |
| 7580 | continue; |
| 7581 | } |
| 7582 | |
| 7583 | // Create the new updating load/store node. |
| 7584 | EVT Tys[6]; |
| 7585 | unsigned NumResultVecs = (isLoad ? NumVecs : 0); |
| 7586 | unsigned n; |
| 7587 | for (n = 0; n < NumResultVecs; ++n) |
| 7588 | Tys[n] = VecTy; |
| 7589 | Tys[n++] = MVT::i32; |
| 7590 | Tys[n] = MVT::Other; |
| 7591 | SDVTList SDTys = DAG.getVTList(Tys, NumResultVecs+2); |
| 7592 | SmallVector<SDValue, 8> Ops; |
| 7593 | Ops.push_back(N->getOperand(0)); // incoming chain |
| 7594 | Ops.push_back(N->getOperand(AddrOpIdx)); |
| 7595 | Ops.push_back(Inc); |
| 7596 | for (unsigned i = AddrOpIdx + 1; i < N->getNumOperands(); ++i) { |
| 7597 | Ops.push_back(N->getOperand(i)); |
| 7598 | } |
| 7599 | MemIntrinsicSDNode *MemInt = cast<MemIntrinsicSDNode>(N); |
| 7600 | SDValue UpdN = DAG.getMemIntrinsicNode(NewOpc, N->getDebugLoc(), SDTys, |
| 7601 | Ops.data(), Ops.size(), |
| 7602 | MemInt->getMemoryVT(), |
| 7603 | MemInt->getMemOperand()); |
| 7604 | |
| 7605 | // Update the uses. |
| 7606 | std::vector<SDValue> NewResults; |
| 7607 | for (unsigned i = 0; i < NumResultVecs; ++i) { |
| 7608 | NewResults.push_back(SDValue(UpdN.getNode(), i)); |
| 7609 | } |
| 7610 | NewResults.push_back(SDValue(UpdN.getNode(), NumResultVecs+1)); // chain |
| 7611 | DCI.CombineTo(N, NewResults); |
| 7612 | DCI.CombineTo(User, SDValue(UpdN.getNode(), NumResultVecs)); |
| 7613 | |
| 7614 | break; |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 7615 | } |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 7616 | return SDValue(); |
| 7617 | } |
| 7618 | |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 7619 | /// CombineVLDDUP - For a VDUPLANE node N, check if its source operand is a |
| 7620 | /// vldN-lane (N > 1) intrinsic, and if all the other uses of that intrinsic |
| 7621 | /// are also VDUPLANEs. If so, combine them to a vldN-dup operation and |
| 7622 | /// return true. |
| 7623 | static bool CombineVLDDUP(SDNode *N, TargetLowering::DAGCombinerInfo &DCI) { |
| 7624 | SelectionDAG &DAG = DCI.DAG; |
| 7625 | EVT VT = N->getValueType(0); |
| 7626 | // vldN-dup instructions only support 64-bit vectors for N > 1. |
| 7627 | if (!VT.is64BitVector()) |
| 7628 | return false; |
| 7629 | |
| 7630 | // Check if the VDUPLANE operand is a vldN-dup intrinsic. |
| 7631 | SDNode *VLD = N->getOperand(0).getNode(); |
| 7632 | if (VLD->getOpcode() != ISD::INTRINSIC_W_CHAIN) |
| 7633 | return false; |
| 7634 | unsigned NumVecs = 0; |
| 7635 | unsigned NewOpc = 0; |
| 7636 | unsigned IntNo = cast<ConstantSDNode>(VLD->getOperand(1))->getZExtValue(); |
| 7637 | if (IntNo == Intrinsic::arm_neon_vld2lane) { |
| 7638 | NumVecs = 2; |
| 7639 | NewOpc = ARMISD::VLD2DUP; |
| 7640 | } else if (IntNo == Intrinsic::arm_neon_vld3lane) { |
| 7641 | NumVecs = 3; |
| 7642 | NewOpc = ARMISD::VLD3DUP; |
| 7643 | } else if (IntNo == Intrinsic::arm_neon_vld4lane) { |
| 7644 | NumVecs = 4; |
| 7645 | NewOpc = ARMISD::VLD4DUP; |
| 7646 | } else { |
| 7647 | return false; |
| 7648 | } |
| 7649 | |
| 7650 | // First check that all the vldN-lane uses are VDUPLANEs and that the lane |
| 7651 | // numbers match the load. |
| 7652 | unsigned VLDLaneNo = |
| 7653 | cast<ConstantSDNode>(VLD->getOperand(NumVecs+3))->getZExtValue(); |
| 7654 | for (SDNode::use_iterator UI = VLD->use_begin(), UE = VLD->use_end(); |
| 7655 | UI != UE; ++UI) { |
| 7656 | // Ignore uses of the chain result. |
| 7657 | if (UI.getUse().getResNo() == NumVecs) |
| 7658 | continue; |
| 7659 | SDNode *User = *UI; |
| 7660 | if (User->getOpcode() != ARMISD::VDUPLANE || |
| 7661 | VLDLaneNo != cast<ConstantSDNode>(User->getOperand(1))->getZExtValue()) |
| 7662 | return false; |
| 7663 | } |
| 7664 | |
| 7665 | // Create the vldN-dup node. |
| 7666 | EVT Tys[5]; |
| 7667 | unsigned n; |
| 7668 | for (n = 0; n < NumVecs; ++n) |
| 7669 | Tys[n] = VT; |
| 7670 | Tys[n] = MVT::Other; |
| 7671 | SDVTList SDTys = DAG.getVTList(Tys, NumVecs+1); |
| 7672 | SDValue Ops[] = { VLD->getOperand(0), VLD->getOperand(2) }; |
| 7673 | MemIntrinsicSDNode *VLDMemInt = cast<MemIntrinsicSDNode>(VLD); |
| 7674 | SDValue VLDDup = DAG.getMemIntrinsicNode(NewOpc, VLD->getDebugLoc(), SDTys, |
| 7675 | Ops, 2, VLDMemInt->getMemoryVT(), |
| 7676 | VLDMemInt->getMemOperand()); |
| 7677 | |
| 7678 | // Update the uses. |
| 7679 | for (SDNode::use_iterator UI = VLD->use_begin(), UE = VLD->use_end(); |
| 7680 | UI != UE; ++UI) { |
| 7681 | unsigned ResNo = UI.getUse().getResNo(); |
| 7682 | // Ignore uses of the chain result. |
| 7683 | if (ResNo == NumVecs) |
| 7684 | continue; |
| 7685 | SDNode *User = *UI; |
| 7686 | DCI.CombineTo(User, SDValue(VLDDup.getNode(), ResNo)); |
| 7687 | } |
| 7688 | |
| 7689 | // Now the vldN-lane intrinsic is dead except for its chain result. |
| 7690 | // Update uses of the chain. |
| 7691 | std::vector<SDValue> VLDDupResults; |
| 7692 | for (unsigned n = 0; n < NumVecs; ++n) |
| 7693 | VLDDupResults.push_back(SDValue(VLDDup.getNode(), n)); |
| 7694 | VLDDupResults.push_back(SDValue(VLDDup.getNode(), NumVecs)); |
| 7695 | DCI.CombineTo(VLD, VLDDupResults); |
| 7696 | |
| 7697 | return true; |
| 7698 | } |
| 7699 | |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 7700 | /// PerformVDUPLANECombine - Target-specific dag combine xforms for |
| 7701 | /// ARMISD::VDUPLANE. |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 7702 | static SDValue PerformVDUPLANECombine(SDNode *N, |
| 7703 | TargetLowering::DAGCombinerInfo &DCI) { |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 7704 | SDValue Op = N->getOperand(0); |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 7705 | |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 7706 | // If the source is a vldN-lane (N > 1) intrinsic, and all the other uses |
| 7707 | // of that intrinsic are also VDUPLANEs, combine them to a vldN-dup operation. |
| 7708 | if (CombineVLDDUP(N, DCI)) |
| 7709 | return SDValue(N, 0); |
| 7710 | |
| 7711 | // If the source is already a VMOVIMM or VMVNIMM splat, the VDUPLANE is |
| 7712 | // redundant. Ignore bit_converts for now; element sizes are checked below. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7713 | while (Op.getOpcode() == ISD::BITCAST) |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 7714 | Op = Op.getOperand(0); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 7715 | if (Op.getOpcode() != ARMISD::VMOVIMM && Op.getOpcode() != ARMISD::VMVNIMM) |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 7716 | return SDValue(); |
| 7717 | |
| 7718 | // Make sure the VMOV element size is not bigger than the VDUPLANE elements. |
| 7719 | unsigned EltSize = Op.getValueType().getVectorElementType().getSizeInBits(); |
| 7720 | // The canonical VMOV for a zero vector uses a 32-bit element size. |
| 7721 | unsigned Imm = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
| 7722 | unsigned EltBits; |
| 7723 | if (ARM_AM::decodeNEONModImm(Imm, EltBits) == 0) |
| 7724 | EltSize = 8; |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 7725 | EVT VT = N->getValueType(0); |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 7726 | if (EltSize > VT.getVectorElementType().getSizeInBits()) |
| 7727 | return SDValue(); |
| 7728 | |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 7729 | return DCI.DAG.getNode(ISD::BITCAST, N->getDebugLoc(), VT, Op); |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 7730 | } |
| 7731 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7732 | // isConstVecPow2 - Return true if each vector element is a power of 2, all |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 7733 | // elements are the same constant, C, and Log2(C) ranges from 1 to 32. |
| 7734 | static bool isConstVecPow2(SDValue ConstVec, bool isSigned, uint64_t &C) |
| 7735 | { |
Chad Rosier | 118c9a0 | 2011-06-28 17:26:57 +0000 | [diff] [blame] | 7736 | integerPart cN; |
| 7737 | integerPart c0 = 0; |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 7738 | for (unsigned I = 0, E = ConstVec.getValueType().getVectorNumElements(); |
| 7739 | I != E; I++) { |
| 7740 | ConstantFPSDNode *C = dyn_cast<ConstantFPSDNode>(ConstVec.getOperand(I)); |
| 7741 | if (!C) |
| 7742 | return false; |
| 7743 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7744 | bool isExact; |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 7745 | APFloat APF = C->getValueAPF(); |
| 7746 | if (APF.convertToInteger(&cN, 64, isSigned, APFloat::rmTowardZero, &isExact) |
| 7747 | != APFloat::opOK || !isExact) |
| 7748 | return false; |
| 7749 | |
| 7750 | c0 = (I == 0) ? cN : c0; |
| 7751 | if (!isPowerOf2_64(cN) || c0 != cN || Log2_64(c0) < 1 || Log2_64(c0) > 32) |
| 7752 | return false; |
| 7753 | } |
| 7754 | C = c0; |
| 7755 | return true; |
| 7756 | } |
| 7757 | |
| 7758 | /// PerformVCVTCombine - VCVT (floating-point to fixed-point, Advanced SIMD) |
| 7759 | /// can replace combinations of VMUL and VCVT (floating-point to integer) |
| 7760 | /// when the VMUL has a constant operand that is a power of 2. |
| 7761 | /// |
| 7762 | /// Example (assume d17 = <float 8.000000e+00, float 8.000000e+00>): |
| 7763 | /// vmul.f32 d16, d17, d16 |
| 7764 | /// vcvt.s32.f32 d16, d16 |
| 7765 | /// becomes: |
| 7766 | /// vcvt.s32.f32 d16, d16, #3 |
| 7767 | static SDValue PerformVCVTCombine(SDNode *N, |
| 7768 | TargetLowering::DAGCombinerInfo &DCI, |
| 7769 | const ARMSubtarget *Subtarget) { |
| 7770 | SelectionDAG &DAG = DCI.DAG; |
| 7771 | SDValue Op = N->getOperand(0); |
| 7772 | |
| 7773 | if (!Subtarget->hasNEON() || !Op.getValueType().isVector() || |
| 7774 | Op.getOpcode() != ISD::FMUL) |
| 7775 | return SDValue(); |
| 7776 | |
| 7777 | uint64_t C; |
| 7778 | SDValue N0 = Op->getOperand(0); |
| 7779 | SDValue ConstVec = Op->getOperand(1); |
| 7780 | bool isSigned = N->getOpcode() == ISD::FP_TO_SINT; |
| 7781 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7782 | if (ConstVec.getOpcode() != ISD::BUILD_VECTOR || |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 7783 | !isConstVecPow2(ConstVec, isSigned, C)) |
| 7784 | return SDValue(); |
| 7785 | |
| 7786 | unsigned IntrinsicOpcode = isSigned ? Intrinsic::arm_neon_vcvtfp2fxs : |
| 7787 | Intrinsic::arm_neon_vcvtfp2fxu; |
| 7788 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, N->getDebugLoc(), |
| 7789 | N->getValueType(0), |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7790 | DAG.getConstant(IntrinsicOpcode, MVT::i32), N0, |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 7791 | DAG.getConstant(Log2_64(C), MVT::i32)); |
| 7792 | } |
| 7793 | |
| 7794 | /// PerformVDIVCombine - VCVT (fixed-point to floating-point, Advanced SIMD) |
| 7795 | /// can replace combinations of VCVT (integer to floating-point) and VDIV |
| 7796 | /// when the VDIV has a constant operand that is a power of 2. |
| 7797 | /// |
| 7798 | /// Example (assume d17 = <float 8.000000e+00, float 8.000000e+00>): |
| 7799 | /// vcvt.f32.s32 d16, d16 |
| 7800 | /// vdiv.f32 d16, d17, d16 |
| 7801 | /// becomes: |
| 7802 | /// vcvt.f32.s32 d16, d16, #3 |
| 7803 | static SDValue PerformVDIVCombine(SDNode *N, |
| 7804 | TargetLowering::DAGCombinerInfo &DCI, |
| 7805 | const ARMSubtarget *Subtarget) { |
| 7806 | SelectionDAG &DAG = DCI.DAG; |
| 7807 | SDValue Op = N->getOperand(0); |
| 7808 | unsigned OpOpcode = Op.getNode()->getOpcode(); |
| 7809 | |
| 7810 | if (!Subtarget->hasNEON() || !N->getValueType(0).isVector() || |
| 7811 | (OpOpcode != ISD::SINT_TO_FP && OpOpcode != ISD::UINT_TO_FP)) |
| 7812 | return SDValue(); |
| 7813 | |
| 7814 | uint64_t C; |
| 7815 | SDValue ConstVec = N->getOperand(1); |
| 7816 | bool isSigned = OpOpcode == ISD::SINT_TO_FP; |
| 7817 | |
| 7818 | if (ConstVec.getOpcode() != ISD::BUILD_VECTOR || |
| 7819 | !isConstVecPow2(ConstVec, isSigned, C)) |
| 7820 | return SDValue(); |
| 7821 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7822 | unsigned IntrinsicOpcode = isSigned ? Intrinsic::arm_neon_vcvtfxs2fp : |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 7823 | Intrinsic::arm_neon_vcvtfxu2fp; |
| 7824 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, N->getDebugLoc(), |
| 7825 | Op.getValueType(), |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7826 | DAG.getConstant(IntrinsicOpcode, MVT::i32), |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 7827 | Op.getOperand(0), DAG.getConstant(Log2_64(C), MVT::i32)); |
| 7828 | } |
| 7829 | |
| 7830 | /// Getvshiftimm - Check if this is a valid build_vector for the immediate |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7831 | /// operand of a vector shift operation, where all the elements of the |
| 7832 | /// build_vector must have the same constant integer value. |
| 7833 | static bool getVShiftImm(SDValue Op, unsigned ElementBits, int64_t &Cnt) { |
| 7834 | // Ignore bit_converts. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7835 | while (Op.getOpcode() == ISD::BITCAST) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7836 | Op = Op.getOperand(0); |
| 7837 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(Op.getNode()); |
| 7838 | APInt SplatBits, SplatUndef; |
| 7839 | unsigned SplatBitSize; |
| 7840 | bool HasAnyUndefs; |
| 7841 | if (! BVN || ! BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, |
| 7842 | HasAnyUndefs, ElementBits) || |
| 7843 | SplatBitSize > ElementBits) |
| 7844 | return false; |
| 7845 | Cnt = SplatBits.getSExtValue(); |
| 7846 | return true; |
| 7847 | } |
| 7848 | |
| 7849 | /// isVShiftLImm - Check if this is a valid build_vector for the immediate |
| 7850 | /// operand of a vector shift left operation. That value must be in the range: |
| 7851 | /// 0 <= Value < ElementBits for a left shift; or |
| 7852 | /// 0 <= Value <= ElementBits for a long left shift. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 7853 | static bool isVShiftLImm(SDValue Op, EVT VT, bool isLong, int64_t &Cnt) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7854 | assert(VT.isVector() && "vector shift count is not a vector type"); |
| 7855 | unsigned ElementBits = VT.getVectorElementType().getSizeInBits(); |
| 7856 | if (! getVShiftImm(Op, ElementBits, Cnt)) |
| 7857 | return false; |
| 7858 | return (Cnt >= 0 && (isLong ? Cnt-1 : Cnt) < ElementBits); |
| 7859 | } |
| 7860 | |
| 7861 | /// isVShiftRImm - Check if this is a valid build_vector for the immediate |
| 7862 | /// operand of a vector shift right operation. For a shift opcode, the value |
| 7863 | /// is positive, but for an intrinsic the value count must be negative. The |
| 7864 | /// absolute value must be in the range: |
| 7865 | /// 1 <= |Value| <= ElementBits for a right shift; or |
| 7866 | /// 1 <= |Value| <= ElementBits/2 for a narrow right shift. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 7867 | static bool isVShiftRImm(SDValue Op, EVT VT, bool isNarrow, bool isIntrinsic, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7868 | int64_t &Cnt) { |
| 7869 | assert(VT.isVector() && "vector shift count is not a vector type"); |
| 7870 | unsigned ElementBits = VT.getVectorElementType().getSizeInBits(); |
| 7871 | if (! getVShiftImm(Op, ElementBits, Cnt)) |
| 7872 | return false; |
| 7873 | if (isIntrinsic) |
| 7874 | Cnt = -Cnt; |
| 7875 | return (Cnt >= 1 && Cnt <= (isNarrow ? ElementBits/2 : ElementBits)); |
| 7876 | } |
| 7877 | |
| 7878 | /// PerformIntrinsicCombine - ARM-specific DAG combining for intrinsics. |
| 7879 | static SDValue PerformIntrinsicCombine(SDNode *N, SelectionDAG &DAG) { |
| 7880 | unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue(); |
| 7881 | switch (IntNo) { |
| 7882 | default: |
| 7883 | // Don't do anything for most intrinsics. |
| 7884 | break; |
| 7885 | |
| 7886 | // Vector shifts: check for immediate versions and lower them. |
| 7887 | // Note: This is done during DAG combining instead of DAG legalizing because |
| 7888 | // the build_vectors for 64-bit vector element shift counts are generally |
| 7889 | // not legal, and it is hard to see their values after they get legalized to |
| 7890 | // loads from a constant pool. |
| 7891 | case Intrinsic::arm_neon_vshifts: |
| 7892 | case Intrinsic::arm_neon_vshiftu: |
| 7893 | case Intrinsic::arm_neon_vshiftls: |
| 7894 | case Intrinsic::arm_neon_vshiftlu: |
| 7895 | case Intrinsic::arm_neon_vshiftn: |
| 7896 | case Intrinsic::arm_neon_vrshifts: |
| 7897 | case Intrinsic::arm_neon_vrshiftu: |
| 7898 | case Intrinsic::arm_neon_vrshiftn: |
| 7899 | case Intrinsic::arm_neon_vqshifts: |
| 7900 | case Intrinsic::arm_neon_vqshiftu: |
| 7901 | case Intrinsic::arm_neon_vqshiftsu: |
| 7902 | case Intrinsic::arm_neon_vqshiftns: |
| 7903 | case Intrinsic::arm_neon_vqshiftnu: |
| 7904 | case Intrinsic::arm_neon_vqshiftnsu: |
| 7905 | case Intrinsic::arm_neon_vqrshiftns: |
| 7906 | case Intrinsic::arm_neon_vqrshiftnu: |
| 7907 | case Intrinsic::arm_neon_vqrshiftnsu: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 7908 | EVT VT = N->getOperand(1).getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7909 | int64_t Cnt; |
| 7910 | unsigned VShiftOpc = 0; |
| 7911 | |
| 7912 | switch (IntNo) { |
| 7913 | case Intrinsic::arm_neon_vshifts: |
| 7914 | case Intrinsic::arm_neon_vshiftu: |
| 7915 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) { |
| 7916 | VShiftOpc = ARMISD::VSHL; |
| 7917 | break; |
| 7918 | } |
| 7919 | if (isVShiftRImm(N->getOperand(2), VT, false, true, Cnt)) { |
| 7920 | VShiftOpc = (IntNo == Intrinsic::arm_neon_vshifts ? |
| 7921 | ARMISD::VSHRs : ARMISD::VSHRu); |
| 7922 | break; |
| 7923 | } |
| 7924 | return SDValue(); |
| 7925 | |
| 7926 | case Intrinsic::arm_neon_vshiftls: |
| 7927 | case Intrinsic::arm_neon_vshiftlu: |
| 7928 | if (isVShiftLImm(N->getOperand(2), VT, true, Cnt)) |
| 7929 | break; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 7930 | llvm_unreachable("invalid shift count for vshll intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7931 | |
| 7932 | case Intrinsic::arm_neon_vrshifts: |
| 7933 | case Intrinsic::arm_neon_vrshiftu: |
| 7934 | if (isVShiftRImm(N->getOperand(2), VT, false, true, Cnt)) |
| 7935 | break; |
| 7936 | return SDValue(); |
| 7937 | |
| 7938 | case Intrinsic::arm_neon_vqshifts: |
| 7939 | case Intrinsic::arm_neon_vqshiftu: |
| 7940 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) |
| 7941 | break; |
| 7942 | return SDValue(); |
| 7943 | |
| 7944 | case Intrinsic::arm_neon_vqshiftsu: |
| 7945 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) |
| 7946 | break; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 7947 | llvm_unreachable("invalid shift count for vqshlu intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7948 | |
| 7949 | case Intrinsic::arm_neon_vshiftn: |
| 7950 | case Intrinsic::arm_neon_vrshiftn: |
| 7951 | case Intrinsic::arm_neon_vqshiftns: |
| 7952 | case Intrinsic::arm_neon_vqshiftnu: |
| 7953 | case Intrinsic::arm_neon_vqshiftnsu: |
| 7954 | case Intrinsic::arm_neon_vqrshiftns: |
| 7955 | case Intrinsic::arm_neon_vqrshiftnu: |
| 7956 | case Intrinsic::arm_neon_vqrshiftnsu: |
| 7957 | // Narrowing shifts require an immediate right shift. |
| 7958 | if (isVShiftRImm(N->getOperand(2), VT, true, true, Cnt)) |
| 7959 | break; |
Jim Grosbach | 18f30e6 | 2010-06-02 21:53:11 +0000 | [diff] [blame] | 7960 | llvm_unreachable("invalid shift count for narrowing vector shift " |
| 7961 | "intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7962 | |
| 7963 | default: |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 7964 | llvm_unreachable("unhandled vector shift"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7965 | } |
| 7966 | |
| 7967 | switch (IntNo) { |
| 7968 | case Intrinsic::arm_neon_vshifts: |
| 7969 | case Intrinsic::arm_neon_vshiftu: |
| 7970 | // Opcode already set above. |
| 7971 | break; |
| 7972 | case Intrinsic::arm_neon_vshiftls: |
| 7973 | case Intrinsic::arm_neon_vshiftlu: |
| 7974 | if (Cnt == VT.getVectorElementType().getSizeInBits()) |
| 7975 | VShiftOpc = ARMISD::VSHLLi; |
| 7976 | else |
| 7977 | VShiftOpc = (IntNo == Intrinsic::arm_neon_vshiftls ? |
| 7978 | ARMISD::VSHLLs : ARMISD::VSHLLu); |
| 7979 | break; |
| 7980 | case Intrinsic::arm_neon_vshiftn: |
| 7981 | VShiftOpc = ARMISD::VSHRN; break; |
| 7982 | case Intrinsic::arm_neon_vrshifts: |
| 7983 | VShiftOpc = ARMISD::VRSHRs; break; |
| 7984 | case Intrinsic::arm_neon_vrshiftu: |
| 7985 | VShiftOpc = ARMISD::VRSHRu; break; |
| 7986 | case Intrinsic::arm_neon_vrshiftn: |
| 7987 | VShiftOpc = ARMISD::VRSHRN; break; |
| 7988 | case Intrinsic::arm_neon_vqshifts: |
| 7989 | VShiftOpc = ARMISD::VQSHLs; break; |
| 7990 | case Intrinsic::arm_neon_vqshiftu: |
| 7991 | VShiftOpc = ARMISD::VQSHLu; break; |
| 7992 | case Intrinsic::arm_neon_vqshiftsu: |
| 7993 | VShiftOpc = ARMISD::VQSHLsu; break; |
| 7994 | case Intrinsic::arm_neon_vqshiftns: |
| 7995 | VShiftOpc = ARMISD::VQSHRNs; break; |
| 7996 | case Intrinsic::arm_neon_vqshiftnu: |
| 7997 | VShiftOpc = ARMISD::VQSHRNu; break; |
| 7998 | case Intrinsic::arm_neon_vqshiftnsu: |
| 7999 | VShiftOpc = ARMISD::VQSHRNsu; break; |
| 8000 | case Intrinsic::arm_neon_vqrshiftns: |
| 8001 | VShiftOpc = ARMISD::VQRSHRNs; break; |
| 8002 | case Intrinsic::arm_neon_vqrshiftnu: |
| 8003 | VShiftOpc = ARMISD::VQRSHRNu; break; |
| 8004 | case Intrinsic::arm_neon_vqrshiftnsu: |
| 8005 | VShiftOpc = ARMISD::VQRSHRNsu; break; |
| 8006 | } |
| 8007 | |
| 8008 | return DAG.getNode(VShiftOpc, N->getDebugLoc(), N->getValueType(0), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8009 | N->getOperand(1), DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8010 | } |
| 8011 | |
| 8012 | case Intrinsic::arm_neon_vshiftins: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8013 | EVT VT = N->getOperand(1).getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8014 | int64_t Cnt; |
| 8015 | unsigned VShiftOpc = 0; |
| 8016 | |
| 8017 | if (isVShiftLImm(N->getOperand(3), VT, false, Cnt)) |
| 8018 | VShiftOpc = ARMISD::VSLI; |
| 8019 | else if (isVShiftRImm(N->getOperand(3), VT, false, true, Cnt)) |
| 8020 | VShiftOpc = ARMISD::VSRI; |
| 8021 | else { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 8022 | llvm_unreachable("invalid shift count for vsli/vsri intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8023 | } |
| 8024 | |
| 8025 | return DAG.getNode(VShiftOpc, N->getDebugLoc(), N->getValueType(0), |
| 8026 | N->getOperand(1), N->getOperand(2), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8027 | DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8028 | } |
| 8029 | |
| 8030 | case Intrinsic::arm_neon_vqrshifts: |
| 8031 | case Intrinsic::arm_neon_vqrshiftu: |
| 8032 | // No immediate versions of these to check for. |
| 8033 | break; |
| 8034 | } |
| 8035 | |
| 8036 | return SDValue(); |
| 8037 | } |
| 8038 | |
| 8039 | /// PerformShiftCombine - Checks for immediate versions of vector shifts and |
| 8040 | /// lowers them. As with the vector shift intrinsics, this is done during DAG |
| 8041 | /// combining instead of DAG legalizing because the build_vectors for 64-bit |
| 8042 | /// vector element shift counts are generally not legal, and it is hard to see |
| 8043 | /// their values after they get legalized to loads from a constant pool. |
| 8044 | static SDValue PerformShiftCombine(SDNode *N, SelectionDAG &DAG, |
| 8045 | const ARMSubtarget *ST) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8046 | EVT VT = N->getValueType(0); |
Evan Cheng | 5fb468a | 2012-02-23 02:58:19 +0000 | [diff] [blame] | 8047 | if (N->getOpcode() == ISD::SRL && VT == MVT::i32 && ST->hasV6Ops()) { |
| 8048 | // Canonicalize (srl (bswap x), 16) to (rotr (bswap x), 16) if the high |
| 8049 | // 16-bits of x is zero. This optimizes rev + lsr 16 to rev16. |
| 8050 | SDValue N1 = N->getOperand(1); |
| 8051 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N1)) { |
| 8052 | SDValue N0 = N->getOperand(0); |
| 8053 | if (C->getZExtValue() == 16 && N0.getOpcode() == ISD::BSWAP && |
| 8054 | DAG.MaskedValueIsZero(N0.getOperand(0), |
| 8055 | APInt::getHighBitsSet(32, 16))) |
| 8056 | return DAG.getNode(ISD::ROTR, N->getDebugLoc(), VT, N0, N1); |
| 8057 | } |
| 8058 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8059 | |
| 8060 | // Nothing to be done for scalar shifts. |
Tanya Lattner | 9684a7c | 2010-11-18 22:06:46 +0000 | [diff] [blame] | 8061 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 8062 | if (!VT.isVector() || !TLI.isTypeLegal(VT)) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8063 | return SDValue(); |
| 8064 | |
| 8065 | assert(ST->hasNEON() && "unexpected vector shift"); |
| 8066 | int64_t Cnt; |
| 8067 | |
| 8068 | switch (N->getOpcode()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 8069 | default: llvm_unreachable("unexpected shift opcode"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8070 | |
| 8071 | case ISD::SHL: |
| 8072 | if (isVShiftLImm(N->getOperand(1), VT, false, Cnt)) |
| 8073 | return DAG.getNode(ARMISD::VSHL, N->getDebugLoc(), VT, N->getOperand(0), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8074 | DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8075 | break; |
| 8076 | |
| 8077 | case ISD::SRA: |
| 8078 | case ISD::SRL: |
| 8079 | if (isVShiftRImm(N->getOperand(1), VT, false, false, Cnt)) { |
| 8080 | unsigned VShiftOpc = (N->getOpcode() == ISD::SRA ? |
| 8081 | ARMISD::VSHRs : ARMISD::VSHRu); |
| 8082 | return DAG.getNode(VShiftOpc, N->getDebugLoc(), VT, N->getOperand(0), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8083 | DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8084 | } |
| 8085 | } |
| 8086 | return SDValue(); |
| 8087 | } |
| 8088 | |
| 8089 | /// PerformExtendCombine - Target-specific DAG combining for ISD::SIGN_EXTEND, |
| 8090 | /// ISD::ZERO_EXTEND, and ISD::ANY_EXTEND. |
| 8091 | static SDValue PerformExtendCombine(SDNode *N, SelectionDAG &DAG, |
| 8092 | const ARMSubtarget *ST) { |
| 8093 | SDValue N0 = N->getOperand(0); |
| 8094 | |
| 8095 | // Check for sign- and zero-extensions of vector extract operations of 8- |
| 8096 | // and 16-bit vector elements. NEON supports these directly. They are |
| 8097 | // handled during DAG combining because type legalization will promote them |
| 8098 | // to 32-bit types and it is messy to recognize the operations after that. |
| 8099 | if (ST->hasNEON() && N0.getOpcode() == ISD::EXTRACT_VECTOR_ELT) { |
| 8100 | SDValue Vec = N0.getOperand(0); |
| 8101 | SDValue Lane = N0.getOperand(1); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8102 | EVT VT = N->getValueType(0); |
| 8103 | EVT EltVT = N0.getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8104 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 8105 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8106 | if (VT == MVT::i32 && |
| 8107 | (EltVT == MVT::i8 || EltVT == MVT::i16) && |
Bob Wilson | 3468c2e | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 8108 | TLI.isTypeLegal(Vec.getValueType()) && |
| 8109 | isa<ConstantSDNode>(Lane)) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8110 | |
| 8111 | unsigned Opc = 0; |
| 8112 | switch (N->getOpcode()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 8113 | default: llvm_unreachable("unexpected opcode"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8114 | case ISD::SIGN_EXTEND: |
| 8115 | Opc = ARMISD::VGETLANEs; |
| 8116 | break; |
| 8117 | case ISD::ZERO_EXTEND: |
| 8118 | case ISD::ANY_EXTEND: |
| 8119 | Opc = ARMISD::VGETLANEu; |
| 8120 | break; |
| 8121 | } |
| 8122 | return DAG.getNode(Opc, N->getDebugLoc(), VT, Vec, Lane); |
| 8123 | } |
| 8124 | } |
| 8125 | |
| 8126 | return SDValue(); |
| 8127 | } |
| 8128 | |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8129 | /// PerformSELECT_CCCombine - Target-specific DAG combining for ISD::SELECT_CC |
| 8130 | /// to match f32 max/min patterns to use NEON vmax/vmin instructions. |
| 8131 | static SDValue PerformSELECT_CCCombine(SDNode *N, SelectionDAG &DAG, |
| 8132 | const ARMSubtarget *ST) { |
| 8133 | // If the target supports NEON, try to use vmax/vmin instructions for f32 |
Evan Cheng | 60108e9 | 2010-07-15 22:07:12 +0000 | [diff] [blame] | 8134 | // selects like "x < y ? x : y". Unless the NoNaNsFPMath option is set, |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8135 | // be careful about NaNs: NEON's vmax/vmin return NaN if either operand is |
| 8136 | // a NaN; only do the transformation when it matches that behavior. |
| 8137 | |
| 8138 | // For now only do this when using NEON for FP operations; if using VFP, it |
| 8139 | // is not obvious that the benefit outweighs the cost of switching to the |
| 8140 | // NEON pipeline. |
| 8141 | if (!ST->hasNEON() || !ST->useNEONForSinglePrecisionFP() || |
| 8142 | N->getValueType(0) != MVT::f32) |
| 8143 | return SDValue(); |
| 8144 | |
| 8145 | SDValue CondLHS = N->getOperand(0); |
| 8146 | SDValue CondRHS = N->getOperand(1); |
| 8147 | SDValue LHS = N->getOperand(2); |
| 8148 | SDValue RHS = N->getOperand(3); |
| 8149 | ISD::CondCode CC = cast<CondCodeSDNode>(N->getOperand(4))->get(); |
| 8150 | |
| 8151 | unsigned Opcode = 0; |
| 8152 | bool IsReversed; |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 8153 | if (DAG.isEqualTo(LHS, CondLHS) && DAG.isEqualTo(RHS, CondRHS)) { |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8154 | IsReversed = false; // x CC y ? x : y |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 8155 | } else if (DAG.isEqualTo(LHS, CondRHS) && DAG.isEqualTo(RHS, CondLHS)) { |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8156 | IsReversed = true ; // x CC y ? y : x |
| 8157 | } else { |
| 8158 | return SDValue(); |
| 8159 | } |
| 8160 | |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 8161 | bool IsUnordered; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8162 | switch (CC) { |
| 8163 | default: break; |
| 8164 | case ISD::SETOLT: |
| 8165 | case ISD::SETOLE: |
| 8166 | case ISD::SETLT: |
| 8167 | case ISD::SETLE: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8168 | case ISD::SETULT: |
| 8169 | case ISD::SETULE: |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 8170 | // If LHS is NaN, an ordered comparison will be false and the result will |
| 8171 | // be the RHS, but vmin(NaN, RHS) = NaN. Avoid this by checking that LHS |
| 8172 | // != NaN. Likewise, for unordered comparisons, check for RHS != NaN. |
| 8173 | IsUnordered = (CC == ISD::SETULT || CC == ISD::SETULE); |
| 8174 | if (!DAG.isKnownNeverNaN(IsUnordered ? RHS : LHS)) |
| 8175 | break; |
| 8176 | // For less-than-or-equal comparisons, "+0 <= -0" will be true but vmin |
| 8177 | // will return -0, so vmin can only be used for unsafe math or if one of |
| 8178 | // the operands is known to be nonzero. |
| 8179 | if ((CC == ISD::SETLE || CC == ISD::SETOLE || CC == ISD::SETULE) && |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 8180 | !DAG.getTarget().Options.UnsafeFPMath && |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 8181 | !(DAG.isKnownNeverZero(LHS) || DAG.isKnownNeverZero(RHS))) |
| 8182 | break; |
| 8183 | Opcode = IsReversed ? ARMISD::FMAX : ARMISD::FMIN; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8184 | break; |
| 8185 | |
| 8186 | case ISD::SETOGT: |
| 8187 | case ISD::SETOGE: |
| 8188 | case ISD::SETGT: |
| 8189 | case ISD::SETGE: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8190 | case ISD::SETUGT: |
| 8191 | case ISD::SETUGE: |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 8192 | // If LHS is NaN, an ordered comparison will be false and the result will |
| 8193 | // be the RHS, but vmax(NaN, RHS) = NaN. Avoid this by checking that LHS |
| 8194 | // != NaN. Likewise, for unordered comparisons, check for RHS != NaN. |
| 8195 | IsUnordered = (CC == ISD::SETUGT || CC == ISD::SETUGE); |
| 8196 | if (!DAG.isKnownNeverNaN(IsUnordered ? RHS : LHS)) |
| 8197 | break; |
| 8198 | // For greater-than-or-equal comparisons, "-0 >= +0" will be true but vmax |
| 8199 | // will return +0, so vmax can only be used for unsafe math or if one of |
| 8200 | // the operands is known to be nonzero. |
| 8201 | if ((CC == ISD::SETGE || CC == ISD::SETOGE || CC == ISD::SETUGE) && |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 8202 | !DAG.getTarget().Options.UnsafeFPMath && |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 8203 | !(DAG.isKnownNeverZero(LHS) || DAG.isKnownNeverZero(RHS))) |
| 8204 | break; |
| 8205 | Opcode = IsReversed ? ARMISD::FMIN : ARMISD::FMAX; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8206 | break; |
| 8207 | } |
| 8208 | |
| 8209 | if (!Opcode) |
| 8210 | return SDValue(); |
| 8211 | return DAG.getNode(Opcode, N->getDebugLoc(), N->getValueType(0), LHS, RHS); |
| 8212 | } |
| 8213 | |
Evan Cheng | e721f5c | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 8214 | /// PerformCMOVCombine - Target-specific DAG combining for ARMISD::CMOV. |
| 8215 | SDValue |
| 8216 | ARMTargetLowering::PerformCMOVCombine(SDNode *N, SelectionDAG &DAG) const { |
| 8217 | SDValue Cmp = N->getOperand(4); |
| 8218 | if (Cmp.getOpcode() != ARMISD::CMPZ) |
| 8219 | // Only looking at EQ and NE cases. |
| 8220 | return SDValue(); |
| 8221 | |
| 8222 | EVT VT = N->getValueType(0); |
| 8223 | DebugLoc dl = N->getDebugLoc(); |
| 8224 | SDValue LHS = Cmp.getOperand(0); |
| 8225 | SDValue RHS = Cmp.getOperand(1); |
| 8226 | SDValue FalseVal = N->getOperand(0); |
| 8227 | SDValue TrueVal = N->getOperand(1); |
| 8228 | SDValue ARMcc = N->getOperand(2); |
Jim Grosbach | b04546f | 2011-09-13 20:30:37 +0000 | [diff] [blame] | 8229 | ARMCC::CondCodes CC = |
| 8230 | (ARMCC::CondCodes)cast<ConstantSDNode>(ARMcc)->getZExtValue(); |
Evan Cheng | e721f5c | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 8231 | |
| 8232 | // Simplify |
| 8233 | // mov r1, r0 |
| 8234 | // cmp r1, x |
| 8235 | // mov r0, y |
| 8236 | // moveq r0, x |
| 8237 | // to |
| 8238 | // cmp r0, x |
| 8239 | // movne r0, y |
| 8240 | // |
| 8241 | // mov r1, r0 |
| 8242 | // cmp r1, x |
| 8243 | // mov r0, x |
| 8244 | // movne r0, y |
| 8245 | // to |
| 8246 | // cmp r0, x |
| 8247 | // movne r0, y |
| 8248 | /// FIXME: Turn this into a target neutral optimization? |
| 8249 | SDValue Res; |
Evan Cheng | 9b88d2d | 2011-09-28 23:16:31 +0000 | [diff] [blame] | 8250 | if (CC == ARMCC::NE && FalseVal == RHS && FalseVal != LHS) { |
Evan Cheng | e721f5c | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 8251 | Res = DAG.getNode(ARMISD::CMOV, dl, VT, LHS, TrueVal, ARMcc, |
| 8252 | N->getOperand(3), Cmp); |
| 8253 | } else if (CC == ARMCC::EQ && TrueVal == RHS) { |
| 8254 | SDValue ARMcc; |
| 8255 | SDValue NewCmp = getARMCmp(LHS, RHS, ISD::SETNE, ARMcc, DAG, dl); |
| 8256 | Res = DAG.getNode(ARMISD::CMOV, dl, VT, LHS, FalseVal, ARMcc, |
| 8257 | N->getOperand(3), NewCmp); |
| 8258 | } |
| 8259 | |
| 8260 | if (Res.getNode()) { |
| 8261 | APInt KnownZero, KnownOne; |
| 8262 | APInt Mask = APInt::getAllOnesValue(VT.getScalarType().getSizeInBits()); |
| 8263 | DAG.ComputeMaskedBits(SDValue(N,0), Mask, KnownZero, KnownOne); |
| 8264 | // Capture demanded bits information that would be otherwise lost. |
| 8265 | if (KnownZero == 0xfffffffe) |
| 8266 | Res = DAG.getNode(ISD::AssertZext, dl, MVT::i32, Res, |
| 8267 | DAG.getValueType(MVT::i1)); |
| 8268 | else if (KnownZero == 0xffffff00) |
| 8269 | Res = DAG.getNode(ISD::AssertZext, dl, MVT::i32, Res, |
| 8270 | DAG.getValueType(MVT::i8)); |
| 8271 | else if (KnownZero == 0xffff0000) |
| 8272 | Res = DAG.getNode(ISD::AssertZext, dl, MVT::i32, Res, |
| 8273 | DAG.getValueType(MVT::i16)); |
| 8274 | } |
| 8275 | |
| 8276 | return Res; |
| 8277 | } |
| 8278 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 8279 | SDValue ARMTargetLowering::PerformDAGCombine(SDNode *N, |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 8280 | DAGCombinerInfo &DCI) const { |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 8281 | switch (N->getOpcode()) { |
| 8282 | default: break; |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8283 | case ISD::ADD: return PerformADDCombine(N, DCI, Subtarget); |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8284 | case ISD::SUB: return PerformSUBCombine(N, DCI); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 8285 | case ISD::MUL: return PerformMULCombine(N, DCI, Subtarget); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8286 | case ISD::OR: return PerformORCombine(N, DCI, Subtarget); |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 8287 | case ISD::XOR: return PerformXORCombine(N, DCI, Subtarget); |
| 8288 | case ISD::AND: return PerformANDCombine(N, DCI, Subtarget); |
Evan Cheng | 0c1aec1 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 8289 | case ARMISD::BFI: return PerformBFICombine(N, DCI); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 8290 | case ARMISD::VMOVRRD: return PerformVMOVRRDCombine(N, DCI); |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 8291 | case ARMISD::VMOVDRR: return PerformVMOVDRRCombine(N, DCI.DAG); |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 8292 | case ISD::STORE: return PerformSTORECombine(N, DCI); |
| 8293 | case ISD::BUILD_VECTOR: return PerformBUILD_VECTORCombine(N, DCI); |
| 8294 | case ISD::INSERT_VECTOR_ELT: return PerformInsertEltCombine(N, DCI); |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 8295 | case ISD::VECTOR_SHUFFLE: return PerformVECTOR_SHUFFLECombine(N, DCI.DAG); |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 8296 | case ARMISD::VDUPLANE: return PerformVDUPLANECombine(N, DCI); |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 8297 | case ISD::FP_TO_SINT: |
| 8298 | case ISD::FP_TO_UINT: return PerformVCVTCombine(N, DCI, Subtarget); |
| 8299 | case ISD::FDIV: return PerformVDIVCombine(N, DCI, Subtarget); |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8300 | case ISD::INTRINSIC_WO_CHAIN: return PerformIntrinsicCombine(N, DCI.DAG); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8301 | case ISD::SHL: |
| 8302 | case ISD::SRA: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8303 | case ISD::SRL: return PerformShiftCombine(N, DCI.DAG, Subtarget); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8304 | case ISD::SIGN_EXTEND: |
| 8305 | case ISD::ZERO_EXTEND: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8306 | case ISD::ANY_EXTEND: return PerformExtendCombine(N, DCI.DAG, Subtarget); |
| 8307 | case ISD::SELECT_CC: return PerformSELECT_CCCombine(N, DCI.DAG, Subtarget); |
Evan Cheng | e721f5c | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 8308 | case ARMISD::CMOV: return PerformCMOVCombine(N, DCI.DAG); |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 8309 | case ARMISD::VLD2DUP: |
| 8310 | case ARMISD::VLD3DUP: |
| 8311 | case ARMISD::VLD4DUP: |
| 8312 | return CombineBaseUpdate(N, DCI); |
| 8313 | case ISD::INTRINSIC_VOID: |
| 8314 | case ISD::INTRINSIC_W_CHAIN: |
| 8315 | switch (cast<ConstantSDNode>(N->getOperand(1))->getZExtValue()) { |
| 8316 | case Intrinsic::arm_neon_vld1: |
| 8317 | case Intrinsic::arm_neon_vld2: |
| 8318 | case Intrinsic::arm_neon_vld3: |
| 8319 | case Intrinsic::arm_neon_vld4: |
| 8320 | case Intrinsic::arm_neon_vld2lane: |
| 8321 | case Intrinsic::arm_neon_vld3lane: |
| 8322 | case Intrinsic::arm_neon_vld4lane: |
| 8323 | case Intrinsic::arm_neon_vst1: |
| 8324 | case Intrinsic::arm_neon_vst2: |
| 8325 | case Intrinsic::arm_neon_vst3: |
| 8326 | case Intrinsic::arm_neon_vst4: |
| 8327 | case Intrinsic::arm_neon_vst2lane: |
| 8328 | case Intrinsic::arm_neon_vst3lane: |
| 8329 | case Intrinsic::arm_neon_vst4lane: |
| 8330 | return CombineBaseUpdate(N, DCI); |
| 8331 | default: break; |
| 8332 | } |
| 8333 | break; |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 8334 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 8335 | return SDValue(); |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 8336 | } |
| 8337 | |
Evan Cheng | 31959b1 | 2011-02-02 01:06:55 +0000 | [diff] [blame] | 8338 | bool ARMTargetLowering::isDesirableToTransformToIntegerOp(unsigned Opc, |
| 8339 | EVT VT) const { |
| 8340 | return (VT == MVT::f32) && (Opc == ISD::LOAD || Opc == ISD::STORE); |
| 8341 | } |
| 8342 | |
Bill Wendling | af56634 | 2009-08-15 21:21:19 +0000 | [diff] [blame] | 8343 | bool ARMTargetLowering::allowsUnalignedMemoryAccesses(EVT VT) const { |
Bob Wilson | 02aba73 | 2010-09-28 04:09:35 +0000 | [diff] [blame] | 8344 | if (!Subtarget->allowsUnalignedMem()) |
Bob Wilson | 86fe66d | 2010-06-25 04:12:31 +0000 | [diff] [blame] | 8345 | return false; |
Bill Wendling | af56634 | 2009-08-15 21:21:19 +0000 | [diff] [blame] | 8346 | |
| 8347 | switch (VT.getSimpleVT().SimpleTy) { |
| 8348 | default: |
| 8349 | return false; |
| 8350 | case MVT::i8: |
| 8351 | case MVT::i16: |
| 8352 | case MVT::i32: |
| 8353 | return true; |
| 8354 | // FIXME: VLD1 etc with standard alignment is legal. |
| 8355 | } |
| 8356 | } |
| 8357 | |
Lang Hames | 1a1d1fc | 2011-11-02 22:52:45 +0000 | [diff] [blame] | 8358 | static bool memOpAlign(unsigned DstAlign, unsigned SrcAlign, |
| 8359 | unsigned AlignCheck) { |
| 8360 | return ((SrcAlign == 0 || SrcAlign % AlignCheck == 0) && |
| 8361 | (DstAlign == 0 || DstAlign % AlignCheck == 0)); |
| 8362 | } |
| 8363 | |
| 8364 | EVT ARMTargetLowering::getOptimalMemOpType(uint64_t Size, |
| 8365 | unsigned DstAlign, unsigned SrcAlign, |
Lang Hames | a1e7888 | 2011-11-02 23:37:04 +0000 | [diff] [blame] | 8366 | bool IsZeroVal, |
Lang Hames | 1a1d1fc | 2011-11-02 22:52:45 +0000 | [diff] [blame] | 8367 | bool MemcpyStrSrc, |
| 8368 | MachineFunction &MF) const { |
| 8369 | const Function *F = MF.getFunction(); |
| 8370 | |
| 8371 | // See if we can use NEON instructions for this... |
Lang Hames | a1e7888 | 2011-11-02 23:37:04 +0000 | [diff] [blame] | 8372 | if (IsZeroVal && |
Lang Hames | 1a1d1fc | 2011-11-02 22:52:45 +0000 | [diff] [blame] | 8373 | !F->hasFnAttr(Attribute::NoImplicitFloat) && |
| 8374 | Subtarget->hasNEON()) { |
| 8375 | if (memOpAlign(SrcAlign, DstAlign, 16) && Size >= 16) { |
| 8376 | return MVT::v4i32; |
| 8377 | } else if (memOpAlign(SrcAlign, DstAlign, 8) && Size >= 8) { |
| 8378 | return MVT::v2i32; |
| 8379 | } |
| 8380 | } |
| 8381 | |
Lang Hames | 5207bf2 | 2011-11-08 18:56:23 +0000 | [diff] [blame] | 8382 | // Lowering to i32/i16 if the size permits. |
| 8383 | if (Size >= 4) { |
| 8384 | return MVT::i32; |
| 8385 | } else if (Size >= 2) { |
| 8386 | return MVT::i16; |
| 8387 | } |
| 8388 | |
Lang Hames | 1a1d1fc | 2011-11-02 22:52:45 +0000 | [diff] [blame] | 8389 | // Let the target-independent logic figure it out. |
| 8390 | return MVT::Other; |
| 8391 | } |
| 8392 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 8393 | static bool isLegalT1AddressImmediate(int64_t V, EVT VT) { |
| 8394 | if (V < 0) |
| 8395 | return false; |
| 8396 | |
| 8397 | unsigned Scale = 1; |
| 8398 | switch (VT.getSimpleVT().SimpleTy) { |
| 8399 | default: return false; |
| 8400 | case MVT::i1: |
| 8401 | case MVT::i8: |
| 8402 | // Scale == 1; |
| 8403 | break; |
| 8404 | case MVT::i16: |
| 8405 | // Scale == 2; |
| 8406 | Scale = 2; |
| 8407 | break; |
| 8408 | case MVT::i32: |
| 8409 | // Scale == 4; |
| 8410 | Scale = 4; |
| 8411 | break; |
| 8412 | } |
| 8413 | |
| 8414 | if ((V & (Scale - 1)) != 0) |
| 8415 | return false; |
| 8416 | V /= Scale; |
| 8417 | return V == (V & ((1LL << 5) - 1)); |
| 8418 | } |
| 8419 | |
| 8420 | static bool isLegalT2AddressImmediate(int64_t V, EVT VT, |
| 8421 | const ARMSubtarget *Subtarget) { |
| 8422 | bool isNeg = false; |
| 8423 | if (V < 0) { |
| 8424 | isNeg = true; |
| 8425 | V = - V; |
| 8426 | } |
| 8427 | |
| 8428 | switch (VT.getSimpleVT().SimpleTy) { |
| 8429 | default: return false; |
| 8430 | case MVT::i1: |
| 8431 | case MVT::i8: |
| 8432 | case MVT::i16: |
| 8433 | case MVT::i32: |
| 8434 | // + imm12 or - imm8 |
| 8435 | if (isNeg) |
| 8436 | return V == (V & ((1LL << 8) - 1)); |
| 8437 | return V == (V & ((1LL << 12) - 1)); |
| 8438 | case MVT::f32: |
| 8439 | case MVT::f64: |
| 8440 | // Same as ARM mode. FIXME: NEON? |
| 8441 | if (!Subtarget->hasVFP2()) |
| 8442 | return false; |
| 8443 | if ((V & 3) != 0) |
| 8444 | return false; |
| 8445 | V >>= 2; |
| 8446 | return V == (V & ((1LL << 8) - 1)); |
| 8447 | } |
| 8448 | } |
| 8449 | |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8450 | /// isLegalAddressImmediate - Return true if the integer value can be used |
| 8451 | /// as the offset of the target addressing mode for load / store of the |
| 8452 | /// given type. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8453 | static bool isLegalAddressImmediate(int64_t V, EVT VT, |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8454 | const ARMSubtarget *Subtarget) { |
Evan Cheng | 961f879 | 2007-03-13 20:37:59 +0000 | [diff] [blame] | 8455 | if (V == 0) |
| 8456 | return true; |
| 8457 | |
Evan Cheng | 6501153 | 2009-03-09 19:15:00 +0000 | [diff] [blame] | 8458 | if (!VT.isSimple()) |
| 8459 | return false; |
| 8460 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 8461 | if (Subtarget->isThumb1Only()) |
| 8462 | return isLegalT1AddressImmediate(V, VT); |
| 8463 | else if (Subtarget->isThumb2()) |
| 8464 | return isLegalT2AddressImmediate(V, VT, Subtarget); |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8465 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 8466 | // ARM mode. |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8467 | if (V < 0) |
| 8468 | V = - V; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8469 | switch (VT.getSimpleVT().SimpleTy) { |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8470 | default: return false; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8471 | case MVT::i1: |
| 8472 | case MVT::i8: |
| 8473 | case MVT::i32: |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8474 | // +- imm12 |
Anton Korobeynikov | 7c1c261 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 8475 | return V == (V & ((1LL << 12) - 1)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8476 | case MVT::i16: |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8477 | // +- imm8 |
Anton Korobeynikov | 7c1c261 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 8478 | return V == (V & ((1LL << 8) - 1)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8479 | case MVT::f32: |
| 8480 | case MVT::f64: |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 8481 | if (!Subtarget->hasVFP2()) // FIXME: NEON? |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8482 | return false; |
Evan Cheng | 0b0a9a9 | 2007-05-03 02:00:18 +0000 | [diff] [blame] | 8483 | if ((V & 3) != 0) |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8484 | return false; |
| 8485 | V >>= 2; |
Anton Korobeynikov | 7c1c261 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 8486 | return V == (V & ((1LL << 8) - 1)); |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8487 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8488 | } |
| 8489 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 8490 | bool ARMTargetLowering::isLegalT2ScaledAddressingMode(const AddrMode &AM, |
| 8491 | EVT VT) const { |
| 8492 | int Scale = AM.Scale; |
| 8493 | if (Scale < 0) |
| 8494 | return false; |
| 8495 | |
| 8496 | switch (VT.getSimpleVT().SimpleTy) { |
| 8497 | default: return false; |
| 8498 | case MVT::i1: |
| 8499 | case MVT::i8: |
| 8500 | case MVT::i16: |
| 8501 | case MVT::i32: |
| 8502 | if (Scale == 1) |
| 8503 | return true; |
| 8504 | // r + r << imm |
| 8505 | Scale = Scale & ~1; |
| 8506 | return Scale == 2 || Scale == 4 || Scale == 8; |
| 8507 | case MVT::i64: |
| 8508 | // r + r |
| 8509 | if (((unsigned)AM.HasBaseReg + Scale) <= 2) |
| 8510 | return true; |
| 8511 | return false; |
| 8512 | case MVT::isVoid: |
| 8513 | // Note, we allow "void" uses (basically, uses that aren't loads or |
| 8514 | // stores), because arm allows folding a scale into many arithmetic |
| 8515 | // operations. This should be made more precise and revisited later. |
| 8516 | |
| 8517 | // Allow r << imm, but the imm has to be a multiple of two. |
| 8518 | if (Scale & 1) return false; |
| 8519 | return isPowerOf2_32(Scale); |
| 8520 | } |
| 8521 | } |
| 8522 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8523 | /// isLegalAddressingMode - Return true if the addressing mode represented |
| 8524 | /// 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] | 8525 | bool ARMTargetLowering::isLegalAddressingMode(const AddrMode &AM, |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 8526 | Type *Ty) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8527 | EVT VT = getValueType(Ty, true); |
Bob Wilson | 2c7dab1 | 2009-04-08 17:55:28 +0000 | [diff] [blame] | 8528 | if (!isLegalAddressImmediate(AM.BaseOffs, VT, Subtarget)) |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8529 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 8530 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8531 | // Can never fold addr of global into load/store. |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 8532 | if (AM.BaseGV) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8533 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 8534 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8535 | switch (AM.Scale) { |
| 8536 | case 0: // no scale reg, must be "r+i" or "r", or "i". |
| 8537 | break; |
| 8538 | case 1: |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 8539 | if (Subtarget->isThumb1Only()) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8540 | return false; |
Chris Lattner | 5a3d40d | 2007-04-13 06:50:55 +0000 | [diff] [blame] | 8541 | // FALL THROUGH. |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8542 | default: |
Chris Lattner | 5a3d40d | 2007-04-13 06:50:55 +0000 | [diff] [blame] | 8543 | // ARM doesn't support any R+R*scale+imm addr modes. |
| 8544 | if (AM.BaseOffs) |
| 8545 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 8546 | |
Bob Wilson | 2c7dab1 | 2009-04-08 17:55:28 +0000 | [diff] [blame] | 8547 | if (!VT.isSimple()) |
| 8548 | return false; |
| 8549 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 8550 | if (Subtarget->isThumb2()) |
| 8551 | return isLegalT2ScaledAddressingMode(AM, VT); |
| 8552 | |
Chris Lattner | eb13d1b | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 8553 | int Scale = AM.Scale; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8554 | switch (VT.getSimpleVT().SimpleTy) { |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8555 | default: return false; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8556 | case MVT::i1: |
| 8557 | case MVT::i8: |
| 8558 | case MVT::i32: |
Chris Lattner | eb13d1b | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 8559 | if (Scale < 0) Scale = -Scale; |
| 8560 | if (Scale == 1) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8561 | return true; |
| 8562 | // r + r << imm |
Chris Lattner | e115294 | 2007-04-11 16:17:12 +0000 | [diff] [blame] | 8563 | return isPowerOf2_32(Scale & ~1); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8564 | case MVT::i16: |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 8565 | case MVT::i64: |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8566 | // r + r |
Chris Lattner | eb13d1b | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 8567 | if (((unsigned)AM.HasBaseReg + Scale) <= 2) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8568 | return true; |
Chris Lattner | e115294 | 2007-04-11 16:17:12 +0000 | [diff] [blame] | 8569 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 8570 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8571 | case MVT::isVoid: |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8572 | // Note, we allow "void" uses (basically, uses that aren't loads or |
| 8573 | // stores), because arm allows folding a scale into many arithmetic |
| 8574 | // operations. This should be made more precise and revisited later. |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 8575 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8576 | // 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] | 8577 | if (Scale & 1) return false; |
| 8578 | return isPowerOf2_32(Scale); |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8579 | } |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8580 | } |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8581 | return true; |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8582 | } |
| 8583 | |
Evan Cheng | 77e4751 | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 8584 | /// isLegalICmpImmediate - Return true if the specified immediate is legal |
| 8585 | /// icmp immediate, that is the target has icmp instructions which can compare |
| 8586 | /// a register against the immediate without having to materialize the |
| 8587 | /// immediate into a register. |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 8588 | bool ARMTargetLowering::isLegalICmpImmediate(int64_t Imm) const { |
Evan Cheng | 77e4751 | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 8589 | if (!Subtarget->isThumb()) |
| 8590 | return ARM_AM::getSOImmVal(Imm) != -1; |
| 8591 | if (Subtarget->isThumb2()) |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 8592 | return ARM_AM::getT2SOImmVal(Imm) != -1; |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 8593 | return Imm >= 0 && Imm <= 255; |
Evan Cheng | 77e4751 | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 8594 | } |
| 8595 | |
Dan Gohman | cca8214 | 2011-05-03 00:46:49 +0000 | [diff] [blame] | 8596 | /// isLegalAddImmediate - Return true if the specified immediate is legal |
| 8597 | /// add immediate, that is the target has add instructions which can add |
| 8598 | /// a register with the immediate without having to materialize the |
| 8599 | /// immediate into a register. |
| 8600 | bool ARMTargetLowering::isLegalAddImmediate(int64_t Imm) const { |
| 8601 | return ARM_AM::getSOImmVal(Imm) != -1; |
| 8602 | } |
| 8603 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8604 | static bool getARMIndexedAddressParts(SDNode *Ptr, EVT VT, |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8605 | bool isSEXTLoad, SDValue &Base, |
| 8606 | SDValue &Offset, bool &isInc, |
| 8607 | SelectionDAG &DAG) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8608 | if (Ptr->getOpcode() != ISD::ADD && Ptr->getOpcode() != ISD::SUB) |
| 8609 | return false; |
| 8610 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8611 | if (VT == MVT::i16 || ((VT == MVT::i8 || VT == MVT::i1) && isSEXTLoad)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8612 | // AddressingMode 3 |
| 8613 | Base = Ptr->getOperand(0); |
| 8614 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 8615 | int RHSC = (int)RHS->getZExtValue(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8616 | if (RHSC < 0 && RHSC > -256) { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8617 | assert(Ptr->getOpcode() == ISD::ADD); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8618 | isInc = false; |
| 8619 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); |
| 8620 | return true; |
| 8621 | } |
| 8622 | } |
| 8623 | isInc = (Ptr->getOpcode() == ISD::ADD); |
| 8624 | Offset = Ptr->getOperand(1); |
| 8625 | return true; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8626 | } else if (VT == MVT::i32 || VT == MVT::i8 || VT == MVT::i1) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8627 | // AddressingMode 2 |
| 8628 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 8629 | int RHSC = (int)RHS->getZExtValue(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8630 | if (RHSC < 0 && RHSC > -0x1000) { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8631 | assert(Ptr->getOpcode() == ISD::ADD); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8632 | isInc = false; |
| 8633 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); |
| 8634 | Base = Ptr->getOperand(0); |
| 8635 | return true; |
| 8636 | } |
| 8637 | } |
| 8638 | |
| 8639 | if (Ptr->getOpcode() == ISD::ADD) { |
| 8640 | isInc = true; |
Evan Cheng | ee04a6d | 2011-07-20 23:34:39 +0000 | [diff] [blame] | 8641 | ARM_AM::ShiftOpc ShOpcVal= |
| 8642 | ARM_AM::getShiftOpcForNode(Ptr->getOperand(0).getOpcode()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8643 | if (ShOpcVal != ARM_AM::no_shift) { |
| 8644 | Base = Ptr->getOperand(1); |
| 8645 | Offset = Ptr->getOperand(0); |
| 8646 | } else { |
| 8647 | Base = Ptr->getOperand(0); |
| 8648 | Offset = Ptr->getOperand(1); |
| 8649 | } |
| 8650 | return true; |
| 8651 | } |
| 8652 | |
| 8653 | isInc = (Ptr->getOpcode() == ISD::ADD); |
| 8654 | Base = Ptr->getOperand(0); |
| 8655 | Offset = Ptr->getOperand(1); |
| 8656 | return true; |
| 8657 | } |
| 8658 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 8659 | // FIXME: Use VLDM / VSTM to emulate indexed FP load / store. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8660 | return false; |
| 8661 | } |
| 8662 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8663 | static bool getT2IndexedAddressParts(SDNode *Ptr, EVT VT, |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8664 | bool isSEXTLoad, SDValue &Base, |
| 8665 | SDValue &Offset, bool &isInc, |
| 8666 | SelectionDAG &DAG) { |
| 8667 | if (Ptr->getOpcode() != ISD::ADD && Ptr->getOpcode() != ISD::SUB) |
| 8668 | return false; |
| 8669 | |
| 8670 | Base = Ptr->getOperand(0); |
| 8671 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
| 8672 | int RHSC = (int)RHS->getZExtValue(); |
| 8673 | if (RHSC < 0 && RHSC > -0x100) { // 8 bits. |
| 8674 | assert(Ptr->getOpcode() == ISD::ADD); |
| 8675 | isInc = false; |
| 8676 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); |
| 8677 | return true; |
| 8678 | } else if (RHSC > 0 && RHSC < 0x100) { // 8 bit, no zero. |
| 8679 | isInc = Ptr->getOpcode() == ISD::ADD; |
| 8680 | Offset = DAG.getConstant(RHSC, RHS->getValueType(0)); |
| 8681 | return true; |
| 8682 | } |
| 8683 | } |
| 8684 | |
| 8685 | return false; |
| 8686 | } |
| 8687 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8688 | /// getPreIndexedAddressParts - returns true by value, base pointer and |
| 8689 | /// offset pointer and addressing mode by reference if the node's address |
| 8690 | /// can be legally represented as pre-indexed load / store address. |
| 8691 | bool |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 8692 | ARMTargetLowering::getPreIndexedAddressParts(SDNode *N, SDValue &Base, |
| 8693 | SDValue &Offset, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8694 | ISD::MemIndexedMode &AM, |
Dan Gohman | 73e0914 | 2009-01-15 16:29:45 +0000 | [diff] [blame] | 8695 | SelectionDAG &DAG) const { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8696 | if (Subtarget->isThumb1Only()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8697 | return false; |
| 8698 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8699 | EVT VT; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 8700 | SDValue Ptr; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8701 | bool isSEXTLoad = false; |
| 8702 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) { |
| 8703 | Ptr = LD->getBasePtr(); |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 8704 | VT = LD->getMemoryVT(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8705 | isSEXTLoad = LD->getExtensionType() == ISD::SEXTLOAD; |
| 8706 | } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) { |
| 8707 | Ptr = ST->getBasePtr(); |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 8708 | VT = ST->getMemoryVT(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8709 | } else |
| 8710 | return false; |
| 8711 | |
| 8712 | bool isInc; |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8713 | bool isLegal = false; |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 8714 | if (Subtarget->isThumb2()) |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8715 | isLegal = getT2IndexedAddressParts(Ptr.getNode(), VT, isSEXTLoad, Base, |
| 8716 | Offset, isInc, DAG); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 8717 | else |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8718 | isLegal = getARMIndexedAddressParts(Ptr.getNode(), VT, isSEXTLoad, Base, |
Evan Cheng | 0412957 | 2009-07-02 06:44:30 +0000 | [diff] [blame] | 8719 | Offset, isInc, DAG); |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8720 | if (!isLegal) |
| 8721 | return false; |
| 8722 | |
| 8723 | AM = isInc ? ISD::PRE_INC : ISD::PRE_DEC; |
| 8724 | return true; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8725 | } |
| 8726 | |
| 8727 | /// getPostIndexedAddressParts - returns true by value, base pointer and |
| 8728 | /// offset pointer and addressing mode by reference if this node can be |
| 8729 | /// combined with a load / store to form a post-indexed load / store. |
| 8730 | bool ARMTargetLowering::getPostIndexedAddressParts(SDNode *N, SDNode *Op, |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 8731 | SDValue &Base, |
| 8732 | SDValue &Offset, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8733 | ISD::MemIndexedMode &AM, |
Dan Gohman | 73e0914 | 2009-01-15 16:29:45 +0000 | [diff] [blame] | 8734 | SelectionDAG &DAG) const { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8735 | if (Subtarget->isThumb1Only()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8736 | return false; |
| 8737 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8738 | EVT VT; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 8739 | SDValue Ptr; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8740 | bool isSEXTLoad = false; |
| 8741 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) { |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 8742 | VT = LD->getMemoryVT(); |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 8743 | Ptr = LD->getBasePtr(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8744 | isSEXTLoad = LD->getExtensionType() == ISD::SEXTLOAD; |
| 8745 | } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) { |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 8746 | VT = ST->getMemoryVT(); |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 8747 | Ptr = ST->getBasePtr(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8748 | } else |
| 8749 | return false; |
| 8750 | |
| 8751 | bool isInc; |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8752 | bool isLegal = false; |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 8753 | if (Subtarget->isThumb2()) |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8754 | isLegal = getT2IndexedAddressParts(Op, VT, isSEXTLoad, Base, Offset, |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 8755 | isInc, DAG); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 8756 | else |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8757 | isLegal = getARMIndexedAddressParts(Op, VT, isSEXTLoad, Base, Offset, |
| 8758 | isInc, DAG); |
| 8759 | if (!isLegal) |
| 8760 | return false; |
| 8761 | |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 8762 | if (Ptr != Base) { |
| 8763 | // Swap base ptr and offset to catch more post-index load / store when |
| 8764 | // it's legal. In Thumb2 mode, offset must be an immediate. |
| 8765 | if (Ptr == Offset && Op->getOpcode() == ISD::ADD && |
| 8766 | !Subtarget->isThumb2()) |
| 8767 | std::swap(Base, Offset); |
| 8768 | |
| 8769 | // Post-indexed load / store update the base pointer. |
| 8770 | if (Ptr != Base) |
| 8771 | return false; |
| 8772 | } |
| 8773 | |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8774 | AM = isInc ? ISD::POST_INC : ISD::POST_DEC; |
| 8775 | return true; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8776 | } |
| 8777 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 8778 | void ARMTargetLowering::computeMaskedBitsForTargetNode(const SDValue Op, |
Dan Gohman | 977a76f | 2008-02-13 22:28:48 +0000 | [diff] [blame] | 8779 | const APInt &Mask, |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 8780 | APInt &KnownZero, |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 8781 | APInt &KnownOne, |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 8782 | const SelectionDAG &DAG, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8783 | unsigned Depth) const { |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 8784 | KnownZero = KnownOne = APInt(Mask.getBitWidth(), 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8785 | switch (Op.getOpcode()) { |
| 8786 | default: break; |
| 8787 | case ARMISD::CMOV: { |
| 8788 | // Bits are known zero/one if known on the LHS and RHS. |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 8789 | DAG.ComputeMaskedBits(Op.getOperand(0), Mask, KnownZero, KnownOne, Depth+1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8790 | if (KnownZero == 0 && KnownOne == 0) return; |
| 8791 | |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 8792 | APInt KnownZeroRHS, KnownOneRHS; |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 8793 | DAG.ComputeMaskedBits(Op.getOperand(1), Mask, |
| 8794 | KnownZeroRHS, KnownOneRHS, Depth+1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8795 | KnownZero &= KnownZeroRHS; |
| 8796 | KnownOne &= KnownOneRHS; |
| 8797 | return; |
| 8798 | } |
| 8799 | } |
| 8800 | } |
| 8801 | |
| 8802 | //===----------------------------------------------------------------------===// |
| 8803 | // ARM Inline Assembly Support |
| 8804 | //===----------------------------------------------------------------------===// |
| 8805 | |
Evan Cheng | 55d4200 | 2011-01-08 01:24:27 +0000 | [diff] [blame] | 8806 | bool ARMTargetLowering::ExpandInlineAsm(CallInst *CI) const { |
| 8807 | // Looking for "rev" which is V6+. |
| 8808 | if (!Subtarget->hasV6Ops()) |
| 8809 | return false; |
| 8810 | |
| 8811 | InlineAsm *IA = cast<InlineAsm>(CI->getCalledValue()); |
| 8812 | std::string AsmStr = IA->getAsmString(); |
| 8813 | SmallVector<StringRef, 4> AsmPieces; |
| 8814 | SplitString(AsmStr, AsmPieces, ";\n"); |
| 8815 | |
| 8816 | switch (AsmPieces.size()) { |
| 8817 | default: return false; |
| 8818 | case 1: |
| 8819 | AsmStr = AsmPieces[0]; |
| 8820 | AsmPieces.clear(); |
| 8821 | SplitString(AsmStr, AsmPieces, " \t,"); |
| 8822 | |
| 8823 | // rev $0, $1 |
| 8824 | if (AsmPieces.size() == 3 && |
| 8825 | AsmPieces[0] == "rev" && AsmPieces[1] == "$0" && AsmPieces[2] == "$1" && |
| 8826 | IA->getConstraintString().compare(0, 4, "=l,l") == 0) { |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 8827 | IntegerType *Ty = dyn_cast<IntegerType>(CI->getType()); |
Evan Cheng | 55d4200 | 2011-01-08 01:24:27 +0000 | [diff] [blame] | 8828 | if (Ty && Ty->getBitWidth() == 32) |
| 8829 | return IntrinsicLowering::LowerToByteSwap(CI); |
| 8830 | } |
| 8831 | break; |
| 8832 | } |
| 8833 | |
| 8834 | return false; |
| 8835 | } |
| 8836 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8837 | /// getConstraintType - Given a constraint letter, return the type of |
| 8838 | /// constraint it is for this target. |
| 8839 | ARMTargetLowering::ConstraintType |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 8840 | ARMTargetLowering::getConstraintType(const std::string &Constraint) const { |
| 8841 | if (Constraint.size() == 1) { |
| 8842 | switch (Constraint[0]) { |
| 8843 | default: break; |
| 8844 | case 'l': return C_RegisterClass; |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 8845 | case 'w': return C_RegisterClass; |
Eric Christopher | 73744df | 2011-06-30 23:23:01 +0000 | [diff] [blame] | 8846 | case 'h': return C_RegisterClass; |
Eric Christopher | 89bd71f | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 8847 | case 'x': return C_RegisterClass; |
Eric Christopher | d5dc9ec | 2011-07-01 00:30:46 +0000 | [diff] [blame] | 8848 | case 't': return C_RegisterClass; |
Eric Christopher | 5e653c9 | 2011-07-01 01:00:07 +0000 | [diff] [blame] | 8849 | case 'j': return C_Other; // Constant for movw. |
Eric Christopher | ef7f1e7 | 2011-07-29 21:18:58 +0000 | [diff] [blame] | 8850 | // An address with a single base register. Due to the way we |
| 8851 | // currently handle addresses it is the same as an 'r' memory constraint. |
| 8852 | case 'Q': return C_Memory; |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 8853 | } |
Eric Christopher | 1312ca8 | 2011-06-21 22:10:57 +0000 | [diff] [blame] | 8854 | } else if (Constraint.size() == 2) { |
| 8855 | switch (Constraint[0]) { |
| 8856 | default: break; |
| 8857 | // All 'U+' constraints are addresses. |
| 8858 | case 'U': return C_Memory; |
| 8859 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8860 | } |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 8861 | return TargetLowering::getConstraintType(Constraint); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8862 | } |
| 8863 | |
John Thompson | 44ab89e | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 8864 | /// Examine constraint type and operand type and determine a weight value. |
| 8865 | /// This object must already have been set up with the operand type |
| 8866 | /// and the current alternative constraint selected. |
| 8867 | TargetLowering::ConstraintWeight |
| 8868 | ARMTargetLowering::getSingleConstraintMatchWeight( |
| 8869 | AsmOperandInfo &info, const char *constraint) const { |
| 8870 | ConstraintWeight weight = CW_Invalid; |
| 8871 | Value *CallOperandVal = info.CallOperandVal; |
| 8872 | // If we don't have a value, we can't do a match, |
| 8873 | // but allow it at the lowest weight. |
| 8874 | if (CallOperandVal == NULL) |
| 8875 | return CW_Default; |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 8876 | Type *type = CallOperandVal->getType(); |
John Thompson | 44ab89e | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 8877 | // Look at the constraint type. |
| 8878 | switch (*constraint) { |
| 8879 | default: |
| 8880 | weight = TargetLowering::getSingleConstraintMatchWeight(info, constraint); |
| 8881 | break; |
| 8882 | case 'l': |
| 8883 | if (type->isIntegerTy()) { |
| 8884 | if (Subtarget->isThumb()) |
| 8885 | weight = CW_SpecificReg; |
| 8886 | else |
| 8887 | weight = CW_Register; |
| 8888 | } |
| 8889 | break; |
| 8890 | case 'w': |
| 8891 | if (type->isFloatingPointTy()) |
| 8892 | weight = CW_Register; |
| 8893 | break; |
| 8894 | } |
| 8895 | return weight; |
| 8896 | } |
| 8897 | |
Eric Christopher | 35e6d4d | 2011-06-30 23:50:52 +0000 | [diff] [blame] | 8898 | typedef std::pair<unsigned, const TargetRegisterClass*> RCPair; |
| 8899 | RCPair |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8900 | ARMTargetLowering::getRegForInlineAsmConstraint(const std::string &Constraint, |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8901 | EVT VT) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8902 | if (Constraint.size() == 1) { |
Jakob Stoklund Olesen | 09bf003 | 2010-01-14 18:19:56 +0000 | [diff] [blame] | 8903 | // GCC ARM Constraint Letters |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8904 | switch (Constraint[0]) { |
Eric Christopher | 73744df | 2011-06-30 23:23:01 +0000 | [diff] [blame] | 8905 | case 'l': // Low regs or general regs. |
Jakob Stoklund Olesen | 09bf003 | 2010-01-14 18:19:56 +0000 | [diff] [blame] | 8906 | if (Subtarget->isThumb()) |
Eric Christopher | 35e6d4d | 2011-06-30 23:50:52 +0000 | [diff] [blame] | 8907 | return RCPair(0U, ARM::tGPRRegisterClass); |
Jim Grosbach | 30eae3c | 2009-04-07 20:34:09 +0000 | [diff] [blame] | 8908 | else |
Eric Christopher | 35e6d4d | 2011-06-30 23:50:52 +0000 | [diff] [blame] | 8909 | return RCPair(0U, ARM::GPRRegisterClass); |
Eric Christopher | 73744df | 2011-06-30 23:23:01 +0000 | [diff] [blame] | 8910 | case 'h': // High regs or no regs. |
| 8911 | if (Subtarget->isThumb()) |
Andrew Trick | 3af7a67 | 2011-09-20 03:06:13 +0000 | [diff] [blame] | 8912 | return RCPair(0U, ARM::hGPRRegisterClass); |
Eric Christopher | 1070f82 | 2011-07-01 00:19:27 +0000 | [diff] [blame] | 8913 | break; |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 8914 | case 'r': |
Eric Christopher | 35e6d4d | 2011-06-30 23:50:52 +0000 | [diff] [blame] | 8915 | return RCPair(0U, ARM::GPRRegisterClass); |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 8916 | case 'w': |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8917 | if (VT == MVT::f32) |
Eric Christopher | 35e6d4d | 2011-06-30 23:50:52 +0000 | [diff] [blame] | 8918 | return RCPair(0U, ARM::SPRRegisterClass); |
Bob Wilson | 5afffae | 2009-12-18 01:03:29 +0000 | [diff] [blame] | 8919 | if (VT.getSizeInBits() == 64) |
Eric Christopher | 35e6d4d | 2011-06-30 23:50:52 +0000 | [diff] [blame] | 8920 | return RCPair(0U, ARM::DPRRegisterClass); |
Evan Cheng | d831cda | 2009-12-08 23:06:22 +0000 | [diff] [blame] | 8921 | if (VT.getSizeInBits() == 128) |
Eric Christopher | 35e6d4d | 2011-06-30 23:50:52 +0000 | [diff] [blame] | 8922 | return RCPair(0U, ARM::QPRRegisterClass); |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 8923 | break; |
Eric Christopher | 89bd71f | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 8924 | case 'x': |
| 8925 | if (VT == MVT::f32) |
Andrew Trick | 3af7a67 | 2011-09-20 03:06:13 +0000 | [diff] [blame] | 8926 | return RCPair(0U, ARM::SPR_8RegisterClass); |
Eric Christopher | 89bd71f | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 8927 | if (VT.getSizeInBits() == 64) |
Andrew Trick | 3af7a67 | 2011-09-20 03:06:13 +0000 | [diff] [blame] | 8928 | return RCPair(0U, ARM::DPR_8RegisterClass); |
Eric Christopher | 89bd71f | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 8929 | if (VT.getSizeInBits() == 128) |
Andrew Trick | 3af7a67 | 2011-09-20 03:06:13 +0000 | [diff] [blame] | 8930 | return RCPair(0U, ARM::QPR_8RegisterClass); |
Eric Christopher | 89bd71f | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 8931 | break; |
Eric Christopher | d5dc9ec | 2011-07-01 00:30:46 +0000 | [diff] [blame] | 8932 | case 't': |
| 8933 | if (VT == MVT::f32) |
Andrew Trick | 3af7a67 | 2011-09-20 03:06:13 +0000 | [diff] [blame] | 8934 | return RCPair(0U, ARM::SPRRegisterClass); |
Eric Christopher | d5dc9ec | 2011-07-01 00:30:46 +0000 | [diff] [blame] | 8935 | break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8936 | } |
| 8937 | } |
Bob Wilson | 33cc5cb | 2010-03-15 23:09:18 +0000 | [diff] [blame] | 8938 | if (StringRef("{cc}").equals_lower(Constraint)) |
Jakob Stoklund Olesen | 0d8ba33 | 2010-06-18 16:49:33 +0000 | [diff] [blame] | 8939 | return std::make_pair(unsigned(ARM::CPSR), ARM::CCRRegisterClass); |
Bob Wilson | 33cc5cb | 2010-03-15 23:09:18 +0000 | [diff] [blame] | 8940 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8941 | return TargetLowering::getRegForInlineAsmConstraint(Constraint, VT); |
| 8942 | } |
| 8943 | |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 8944 | /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops |
| 8945 | /// vector. If it is invalid, don't add anything to Ops. |
| 8946 | void ARMTargetLowering::LowerAsmOperandForConstraint(SDValue Op, |
Eric Christopher | 100c833 | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 8947 | std::string &Constraint, |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 8948 | std::vector<SDValue>&Ops, |
| 8949 | SelectionDAG &DAG) const { |
| 8950 | SDValue Result(0, 0); |
| 8951 | |
Eric Christopher | 100c833 | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 8952 | // Currently only support length 1 constraints. |
| 8953 | if (Constraint.length() != 1) return; |
Eric Christopher | 471e422 | 2011-06-08 23:55:35 +0000 | [diff] [blame] | 8954 | |
Eric Christopher | 100c833 | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 8955 | char ConstraintLetter = Constraint[0]; |
| 8956 | switch (ConstraintLetter) { |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 8957 | default: break; |
Eric Christopher | 5e653c9 | 2011-07-01 01:00:07 +0000 | [diff] [blame] | 8958 | case 'j': |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 8959 | case 'I': case 'J': case 'K': case 'L': |
| 8960 | case 'M': case 'N': case 'O': |
| 8961 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op); |
| 8962 | if (!C) |
| 8963 | return; |
| 8964 | |
| 8965 | int64_t CVal64 = C->getSExtValue(); |
| 8966 | int CVal = (int) CVal64; |
| 8967 | // None of these constraints allow values larger than 32 bits. Check |
| 8968 | // that the value fits in an int. |
| 8969 | if (CVal != CVal64) |
| 8970 | return; |
| 8971 | |
Eric Christopher | 100c833 | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 8972 | switch (ConstraintLetter) { |
Eric Christopher | 5e653c9 | 2011-07-01 01:00:07 +0000 | [diff] [blame] | 8973 | case 'j': |
Andrew Trick | 3af7a67 | 2011-09-20 03:06:13 +0000 | [diff] [blame] | 8974 | // Constant suitable for movw, must be between 0 and |
| 8975 | // 65535. |
| 8976 | if (Subtarget->hasV6T2Ops()) |
| 8977 | if (CVal >= 0 && CVal <= 65535) |
| 8978 | break; |
| 8979 | return; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 8980 | case 'I': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 8981 | if (Subtarget->isThumb1Only()) { |
| 8982 | // This must be a constant between 0 and 255, for ADD |
| 8983 | // immediates. |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 8984 | if (CVal >= 0 && CVal <= 255) |
| 8985 | break; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 8986 | } else if (Subtarget->isThumb2()) { |
| 8987 | // A constant that can be used as an immediate value in a |
| 8988 | // data-processing instruction. |
| 8989 | if (ARM_AM::getT2SOImmVal(CVal) != -1) |
| 8990 | break; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 8991 | } else { |
| 8992 | // A constant that can be used as an immediate value in a |
| 8993 | // data-processing instruction. |
| 8994 | if (ARM_AM::getSOImmVal(CVal) != -1) |
| 8995 | break; |
| 8996 | } |
| 8997 | return; |
| 8998 | |
| 8999 | case 'J': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 9000 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 9001 | // This must be a constant between -255 and -1, for negated ADD |
| 9002 | // immediates. This can be used in GCC with an "n" modifier that |
| 9003 | // prints the negated value, for use with SUB instructions. It is |
| 9004 | // not useful otherwise but is implemented for compatibility. |
| 9005 | if (CVal >= -255 && CVal <= -1) |
| 9006 | break; |
| 9007 | } else { |
| 9008 | // This must be a constant between -4095 and 4095. It is not clear |
| 9009 | // what this constraint is intended for. Implemented for |
| 9010 | // compatibility with GCC. |
| 9011 | if (CVal >= -4095 && CVal <= 4095) |
| 9012 | break; |
| 9013 | } |
| 9014 | return; |
| 9015 | |
| 9016 | case 'K': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 9017 | if (Subtarget->isThumb1Only()) { |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 9018 | // A 32-bit value where only one byte has a nonzero value. Exclude |
| 9019 | // zero to match GCC. This constraint is used by GCC internally for |
| 9020 | // constants that can be loaded with a move/shift combination. |
| 9021 | // It is not useful otherwise but is implemented for compatibility. |
| 9022 | if (CVal != 0 && ARM_AM::isThumbImmShiftedVal(CVal)) |
| 9023 | break; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 9024 | } else if (Subtarget->isThumb2()) { |
| 9025 | // A constant whose bitwise inverse can be used as an immediate |
| 9026 | // value in a data-processing instruction. This can be used in GCC |
| 9027 | // with a "B" modifier that prints the inverted value, for use with |
| 9028 | // BIC and MVN instructions. It is not useful otherwise but is |
| 9029 | // implemented for compatibility. |
| 9030 | if (ARM_AM::getT2SOImmVal(~CVal) != -1) |
| 9031 | break; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 9032 | } else { |
| 9033 | // A constant whose bitwise inverse can be used as an immediate |
| 9034 | // value in a data-processing instruction. This can be used in GCC |
| 9035 | // with a "B" modifier that prints the inverted value, for use with |
| 9036 | // BIC and MVN instructions. It is not useful otherwise but is |
| 9037 | // implemented for compatibility. |
| 9038 | if (ARM_AM::getSOImmVal(~CVal) != -1) |
| 9039 | break; |
| 9040 | } |
| 9041 | return; |
| 9042 | |
| 9043 | case 'L': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 9044 | if (Subtarget->isThumb1Only()) { |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 9045 | // This must be a constant between -7 and 7, |
| 9046 | // for 3-operand ADD/SUB immediate instructions. |
| 9047 | if (CVal >= -7 && CVal < 7) |
| 9048 | break; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 9049 | } else if (Subtarget->isThumb2()) { |
| 9050 | // A constant whose negation can be used as an immediate value in a |
| 9051 | // data-processing instruction. This can be used in GCC with an "n" |
| 9052 | // modifier that prints the negated value, for use with SUB |
| 9053 | // instructions. It is not useful otherwise but is implemented for |
| 9054 | // compatibility. |
| 9055 | if (ARM_AM::getT2SOImmVal(-CVal) != -1) |
| 9056 | break; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 9057 | } else { |
| 9058 | // A constant whose negation can be used as an immediate value in a |
| 9059 | // data-processing instruction. This can be used in GCC with an "n" |
| 9060 | // modifier that prints the negated value, for use with SUB |
| 9061 | // instructions. It is not useful otherwise but is implemented for |
| 9062 | // compatibility. |
| 9063 | if (ARM_AM::getSOImmVal(-CVal) != -1) |
| 9064 | break; |
| 9065 | } |
| 9066 | return; |
| 9067 | |
| 9068 | case 'M': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 9069 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 9070 | // This must be a multiple of 4 between 0 and 1020, for |
| 9071 | // ADD sp + immediate. |
| 9072 | if ((CVal >= 0 && CVal <= 1020) && ((CVal & 3) == 0)) |
| 9073 | break; |
| 9074 | } else { |
| 9075 | // A power of two or a constant between 0 and 32. This is used in |
| 9076 | // GCC for the shift amount on shifted register operands, but it is |
| 9077 | // useful in general for any shift amounts. |
| 9078 | if ((CVal >= 0 && CVal <= 32) || ((CVal & (CVal - 1)) == 0)) |
| 9079 | break; |
| 9080 | } |
| 9081 | return; |
| 9082 | |
| 9083 | case 'N': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 9084 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 9085 | // This must be a constant between 0 and 31, for shift amounts. |
| 9086 | if (CVal >= 0 && CVal <= 31) |
| 9087 | break; |
| 9088 | } |
| 9089 | return; |
| 9090 | |
| 9091 | case 'O': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 9092 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 9093 | // This must be a multiple of 4 between -508 and 508, for |
| 9094 | // ADD/SUB sp = sp + immediate. |
| 9095 | if ((CVal >= -508 && CVal <= 508) && ((CVal & 3) == 0)) |
| 9096 | break; |
| 9097 | } |
| 9098 | return; |
| 9099 | } |
| 9100 | Result = DAG.getTargetConstant(CVal, Op.getValueType()); |
| 9101 | break; |
| 9102 | } |
| 9103 | |
| 9104 | if (Result.getNode()) { |
| 9105 | Ops.push_back(Result); |
| 9106 | return; |
| 9107 | } |
Dale Johannesen | 1784d16 | 2010-06-25 21:55:36 +0000 | [diff] [blame] | 9108 | return TargetLowering::LowerAsmOperandForConstraint(Op, Constraint, Ops, DAG); |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 9109 | } |
Anton Korobeynikov | 48e1935 | 2009-09-23 19:04:09 +0000 | [diff] [blame] | 9110 | |
| 9111 | bool |
| 9112 | ARMTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const { |
| 9113 | // The ARM target isn't yet aware of offsets. |
| 9114 | return false; |
| 9115 | } |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 9116 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 9117 | bool ARM::isBitFieldInvertedMask(unsigned v) { |
| 9118 | if (v == 0xffffffff) |
| 9119 | return 0; |
| 9120 | // there can be 1's on either or both "outsides", all the "inside" |
| 9121 | // bits must be 0's |
| 9122 | unsigned int lsb = 0, msb = 31; |
| 9123 | while (v & (1 << msb)) --msb; |
| 9124 | while (v & (1 << lsb)) ++lsb; |
| 9125 | for (unsigned int i = lsb; i <= msb; ++i) { |
| 9126 | if (v & (1 << i)) |
| 9127 | return 0; |
| 9128 | } |
| 9129 | return 1; |
| 9130 | } |
| 9131 | |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 9132 | /// isFPImmLegal - Returns true if the target can instruction select the |
| 9133 | /// specified FP immediate natively. If false, the legalizer will |
| 9134 | /// materialize the FP immediate as a load from a constant pool. |
| 9135 | bool ARMTargetLowering::isFPImmLegal(const APFloat &Imm, EVT VT) const { |
| 9136 | if (!Subtarget->hasVFP3()) |
| 9137 | return false; |
| 9138 | if (VT == MVT::f32) |
Jim Grosbach | 4ebbf7b | 2011-09-30 00:50:06 +0000 | [diff] [blame] | 9139 | return ARM_AM::getFP32Imm(Imm) != -1; |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 9140 | if (VT == MVT::f64) |
Jim Grosbach | 4ebbf7b | 2011-09-30 00:50:06 +0000 | [diff] [blame] | 9141 | return ARM_AM::getFP64Imm(Imm) != -1; |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 9142 | return false; |
| 9143 | } |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 9144 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 9145 | /// getTgtMemIntrinsic - Represent NEON load and store intrinsics as |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 9146 | /// MemIntrinsicNodes. The associated MachineMemOperands record the alignment |
| 9147 | /// specified in the intrinsic calls. |
| 9148 | bool ARMTargetLowering::getTgtMemIntrinsic(IntrinsicInfo &Info, |
| 9149 | const CallInst &I, |
| 9150 | unsigned Intrinsic) const { |
| 9151 | switch (Intrinsic) { |
| 9152 | case Intrinsic::arm_neon_vld1: |
| 9153 | case Intrinsic::arm_neon_vld2: |
| 9154 | case Intrinsic::arm_neon_vld3: |
| 9155 | case Intrinsic::arm_neon_vld4: |
| 9156 | case Intrinsic::arm_neon_vld2lane: |
| 9157 | case Intrinsic::arm_neon_vld3lane: |
| 9158 | case Intrinsic::arm_neon_vld4lane: { |
| 9159 | Info.opc = ISD::INTRINSIC_W_CHAIN; |
| 9160 | // Conservatively set memVT to the entire set of vectors loaded. |
| 9161 | uint64_t NumElts = getTargetData()->getTypeAllocSize(I.getType()) / 8; |
| 9162 | Info.memVT = EVT::getVectorVT(I.getType()->getContext(), MVT::i64, NumElts); |
| 9163 | Info.ptrVal = I.getArgOperand(0); |
| 9164 | Info.offset = 0; |
| 9165 | Value *AlignArg = I.getArgOperand(I.getNumArgOperands() - 1); |
| 9166 | Info.align = cast<ConstantInt>(AlignArg)->getZExtValue(); |
| 9167 | Info.vol = false; // volatile loads with NEON intrinsics not supported |
| 9168 | Info.readMem = true; |
| 9169 | Info.writeMem = false; |
| 9170 | return true; |
| 9171 | } |
| 9172 | case Intrinsic::arm_neon_vst1: |
| 9173 | case Intrinsic::arm_neon_vst2: |
| 9174 | case Intrinsic::arm_neon_vst3: |
| 9175 | case Intrinsic::arm_neon_vst4: |
| 9176 | case Intrinsic::arm_neon_vst2lane: |
| 9177 | case Intrinsic::arm_neon_vst3lane: |
| 9178 | case Intrinsic::arm_neon_vst4lane: { |
| 9179 | Info.opc = ISD::INTRINSIC_VOID; |
| 9180 | // Conservatively set memVT to the entire set of vectors stored. |
| 9181 | unsigned NumElts = 0; |
| 9182 | for (unsigned ArgI = 1, ArgE = I.getNumArgOperands(); ArgI < ArgE; ++ArgI) { |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 9183 | Type *ArgTy = I.getArgOperand(ArgI)->getType(); |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 9184 | if (!ArgTy->isVectorTy()) |
| 9185 | break; |
| 9186 | NumElts += getTargetData()->getTypeAllocSize(ArgTy) / 8; |
| 9187 | } |
| 9188 | Info.memVT = EVT::getVectorVT(I.getType()->getContext(), MVT::i64, NumElts); |
| 9189 | Info.ptrVal = I.getArgOperand(0); |
| 9190 | Info.offset = 0; |
| 9191 | Value *AlignArg = I.getArgOperand(I.getNumArgOperands() - 1); |
| 9192 | Info.align = cast<ConstantInt>(AlignArg)->getZExtValue(); |
| 9193 | Info.vol = false; // volatile stores with NEON intrinsics not supported |
| 9194 | Info.readMem = false; |
| 9195 | Info.writeMem = true; |
| 9196 | return true; |
| 9197 | } |
Bruno Cardoso Lopes | a0112d0 | 2011-05-28 04:07:29 +0000 | [diff] [blame] | 9198 | case Intrinsic::arm_strexd: { |
| 9199 | Info.opc = ISD::INTRINSIC_W_CHAIN; |
| 9200 | Info.memVT = MVT::i64; |
| 9201 | Info.ptrVal = I.getArgOperand(2); |
| 9202 | Info.offset = 0; |
| 9203 | Info.align = 8; |
Bruno Cardoso Lopes | c75448c | 2011-06-16 18:11:32 +0000 | [diff] [blame] | 9204 | Info.vol = true; |
Bruno Cardoso Lopes | a0112d0 | 2011-05-28 04:07:29 +0000 | [diff] [blame] | 9205 | Info.readMem = false; |
| 9206 | Info.writeMem = true; |
| 9207 | return true; |
| 9208 | } |
| 9209 | case Intrinsic::arm_ldrexd: { |
| 9210 | Info.opc = ISD::INTRINSIC_W_CHAIN; |
| 9211 | Info.memVT = MVT::i64; |
| 9212 | Info.ptrVal = I.getArgOperand(0); |
| 9213 | Info.offset = 0; |
| 9214 | Info.align = 8; |
Bruno Cardoso Lopes | c75448c | 2011-06-16 18:11:32 +0000 | [diff] [blame] | 9215 | Info.vol = true; |
Bruno Cardoso Lopes | a0112d0 | 2011-05-28 04:07:29 +0000 | [diff] [blame] | 9216 | Info.readMem = true; |
| 9217 | Info.writeMem = false; |
| 9218 | return true; |
| 9219 | } |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 9220 | default: |
| 9221 | break; |
| 9222 | } |
| 9223 | |
| 9224 | return false; |
| 9225 | } |