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 "ARMSubtarget.h" |
| 23 | #include "ARMTargetMachine.h" |
Chris Lattner | 80ec279 | 2009-08-02 00:34:36 +0000 | [diff] [blame] | 24 | #include "ARMTargetObjectFile.h" |
Evan Cheng | ee04a6d | 2011-07-20 23:34:39 +0000 | [diff] [blame] | 25 | #include "MCTargetDesc/ARMAddressingModes.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 26 | #include "llvm/CallingConv.h" |
| 27 | #include "llvm/Constants.h" |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 28 | #include "llvm/Function.h" |
Benjamin Kramer | 174101e | 2009-10-20 11:44:38 +0000 | [diff] [blame] | 29 | #include "llvm/GlobalValue.h" |
Evan Cheng | 2770747 | 2007-03-16 08:43:56 +0000 | [diff] [blame] | 30 | #include "llvm/Instruction.h" |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 31 | #include "llvm/Instructions.h" |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 32 | #include "llvm/Intrinsics.h" |
Benjamin Kramer | 174101e | 2009-10-20 11:44:38 +0000 | [diff] [blame] | 33 | #include "llvm/Type.h" |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 34 | #include "llvm/CodeGen/CallingConvLower.h" |
Evan Cheng | 55d4200 | 2011-01-08 01:24:27 +0000 | [diff] [blame] | 35 | #include "llvm/CodeGen/IntrinsicLowering.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 36 | #include "llvm/CodeGen/MachineBasicBlock.h" |
| 37 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 38 | #include "llvm/CodeGen/MachineFunction.h" |
| 39 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 40 | #include "llvm/CodeGen/MachineModuleInfo.h" |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 41 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 42 | #include "llvm/CodeGen/SelectionDAG.h" |
Bill Wendling | 94a1c63 | 2010-03-09 02:46:12 +0000 | [diff] [blame] | 43 | #include "llvm/MC/MCSectionMachO.h" |
Evan Cheng | b6ab254 | 2007-01-31 08:40:13 +0000 | [diff] [blame] | 44 | #include "llvm/Target/TargetOptions.h" |
Evan Cheng | 55d4200 | 2011-01-08 01:24:27 +0000 | [diff] [blame] | 45 | #include "llvm/ADT/StringExtras.h" |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 46 | #include "llvm/ADT/Statistic.h" |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 47 | #include "llvm/Support/CommandLine.h" |
Torok Edwin | ab7c09b | 2009-07-08 18:01:40 +0000 | [diff] [blame] | 48 | #include "llvm/Support/ErrorHandling.h" |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 49 | #include "llvm/Support/MathExtras.h" |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 50 | #include "llvm/Support/raw_ostream.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 51 | using namespace llvm; |
| 52 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 53 | STATISTIC(NumTailCalls, "Number of tail calls"); |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 54 | STATISTIC(NumMovwMovt, "Number of GAs materialized with movw + movt"); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 55 | |
Bob Wilson | 703af3a | 2010-08-13 22:43:33 +0000 | [diff] [blame] | 56 | // This option should go away when tail calls fully work. |
| 57 | static cl::opt<bool> |
| 58 | EnableARMTailCalls("arm-tail-calls", cl::Hidden, |
| 59 | cl::desc("Generate tail calls (TEMPORARY OPTION)."), |
| 60 | cl::init(false)); |
| 61 | |
Eric Christopher | 836c624 | 2010-12-15 23:47:29 +0000 | [diff] [blame] | 62 | cl::opt<bool> |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 63 | EnableARMLongCalls("arm-long-calls", cl::Hidden, |
Evan Cheng | 515fe3a | 2010-07-08 02:08:50 +0000 | [diff] [blame] | 64 | cl::desc("Generate calls via indirect call instructions"), |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 65 | cl::init(false)); |
| 66 | |
Evan Cheng | 46df4eb | 2010-06-16 07:35:02 +0000 | [diff] [blame] | 67 | static cl::opt<bool> |
| 68 | ARMInterworking("arm-interworking", cl::Hidden, |
| 69 | cl::desc("Enable / disable ARM interworking (for debugging only)"), |
| 70 | cl::init(true)); |
| 71 | |
Benjamin Kramer | 0861f57 | 2011-11-26 23:01:57 +0000 | [diff] [blame] | 72 | namespace { |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 73 | class ARMCCState : public CCState { |
| 74 | public: |
| 75 | ARMCCState(CallingConv::ID CC, bool isVarArg, MachineFunction &MF, |
| 76 | const TargetMachine &TM, SmallVector<CCValAssign, 16> &locs, |
| 77 | LLVMContext &C, ParmContext PC) |
| 78 | : CCState(CC, isVarArg, MF, TM, locs, C) { |
| 79 | assert(((PC == Call) || (PC == Prologue)) && |
| 80 | "ARMCCState users must specify whether their context is call" |
| 81 | "or prologue generation."); |
| 82 | CallOrPrologue = PC; |
| 83 | } |
| 84 | }; |
| 85 | } |
| 86 | |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 87 | // The APCS parameter registers. |
Craig Topper | c5eaae4 | 2012-03-11 07:57:25 +0000 | [diff] [blame] | 88 | static const uint16_t GPRArgRegs[] = { |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 89 | ARM::R0, ARM::R1, ARM::R2, ARM::R3 |
| 90 | }; |
| 91 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 92 | void ARMTargetLowering::addTypeForNEON(EVT VT, EVT PromotedLdStVT, |
| 93 | EVT PromotedBitwiseVT) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 94 | if (VT != PromotedLdStVT) { |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 95 | setOperationAction(ISD::LOAD, VT.getSimpleVT(), Promote); |
Owen Anderson | d6662ad | 2009-08-10 20:46:15 +0000 | [diff] [blame] | 96 | AddPromotedToType (ISD::LOAD, VT.getSimpleVT(), |
| 97 | PromotedLdStVT.getSimpleVT()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 98 | |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 99 | setOperationAction(ISD::STORE, VT.getSimpleVT(), Promote); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 100 | AddPromotedToType (ISD::STORE, VT.getSimpleVT(), |
Owen Anderson | d6662ad | 2009-08-10 20:46:15 +0000 | [diff] [blame] | 101 | PromotedLdStVT.getSimpleVT()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 102 | } |
| 103 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 104 | EVT ElemTy = VT.getVectorElementType(); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 105 | if (ElemTy != MVT::i64 && ElemTy != MVT::f64) |
Duncan Sands | 28b77e9 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 106 | setOperationAction(ISD::SETCC, VT.getSimpleVT(), Custom); |
Eli Friedman | 5c89cb8 | 2011-10-24 23:08:52 +0000 | [diff] [blame] | 107 | setOperationAction(ISD::INSERT_VECTOR_ELT, VT.getSimpleVT(), Custom); |
Bob Wilson | 3468c2e | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 108 | setOperationAction(ISD::EXTRACT_VECTOR_ELT, VT.getSimpleVT(), Custom); |
Eli Friedman | 14e809c | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 109 | if (ElemTy == MVT::i32) { |
| 110 | setOperationAction(ISD::SINT_TO_FP, VT.getSimpleVT(), Custom); |
| 111 | setOperationAction(ISD::UINT_TO_FP, VT.getSimpleVT(), Custom); |
| 112 | setOperationAction(ISD::FP_TO_SINT, VT.getSimpleVT(), Custom); |
| 113 | setOperationAction(ISD::FP_TO_UINT, VT.getSimpleVT(), Custom); |
| 114 | } else { |
Bob Wilson | 0696fdf | 2009-09-16 20:20:44 +0000 | [diff] [blame] | 115 | setOperationAction(ISD::SINT_TO_FP, VT.getSimpleVT(), Expand); |
| 116 | setOperationAction(ISD::UINT_TO_FP, VT.getSimpleVT(), Expand); |
| 117 | setOperationAction(ISD::FP_TO_SINT, VT.getSimpleVT(), Expand); |
| 118 | setOperationAction(ISD::FP_TO_UINT, VT.getSimpleVT(), Expand); |
| 119 | } |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 120 | setOperationAction(ISD::BUILD_VECTOR, VT.getSimpleVT(), Custom); |
| 121 | setOperationAction(ISD::VECTOR_SHUFFLE, VT.getSimpleVT(), Custom); |
Bob Wilson | 07f6e80 | 2010-06-16 21:34:01 +0000 | [diff] [blame] | 122 | setOperationAction(ISD::CONCAT_VECTORS, VT.getSimpleVT(), Legal); |
Bob Wilson | 5e8b833 | 2011-01-07 04:59:04 +0000 | [diff] [blame] | 123 | setOperationAction(ISD::EXTRACT_SUBVECTOR, VT.getSimpleVT(), Legal); |
Bob Wilson | d0910c4 | 2010-04-06 22:02:24 +0000 | [diff] [blame] | 124 | setOperationAction(ISD::SELECT, VT.getSimpleVT(), Expand); |
| 125 | setOperationAction(ISD::SELECT_CC, VT.getSimpleVT(), Expand); |
Eli Friedman | 15f58c5 | 2011-11-11 03:16:38 +0000 | [diff] [blame] | 126 | setOperationAction(ISD::SIGN_EXTEND_INREG, VT.getSimpleVT(), Expand); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 127 | if (VT.isInteger()) { |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 128 | setOperationAction(ISD::SHL, VT.getSimpleVT(), Custom); |
| 129 | setOperationAction(ISD::SRA, VT.getSimpleVT(), Custom); |
| 130 | setOperationAction(ISD::SRL, VT.getSimpleVT(), Custom); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | // Promote all bit-wise operations. |
| 134 | if (VT.isInteger() && VT != PromotedBitwiseVT) { |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 135 | setOperationAction(ISD::AND, VT.getSimpleVT(), Promote); |
Owen Anderson | d6662ad | 2009-08-10 20:46:15 +0000 | [diff] [blame] | 136 | AddPromotedToType (ISD::AND, VT.getSimpleVT(), |
| 137 | PromotedBitwiseVT.getSimpleVT()); |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 138 | setOperationAction(ISD::OR, VT.getSimpleVT(), Promote); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 139 | AddPromotedToType (ISD::OR, VT.getSimpleVT(), |
Owen Anderson | d6662ad | 2009-08-10 20:46:15 +0000 | [diff] [blame] | 140 | PromotedBitwiseVT.getSimpleVT()); |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 141 | setOperationAction(ISD::XOR, VT.getSimpleVT(), Promote); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 142 | AddPromotedToType (ISD::XOR, VT.getSimpleVT(), |
Owen Anderson | d6662ad | 2009-08-10 20:46:15 +0000 | [diff] [blame] | 143 | PromotedBitwiseVT.getSimpleVT()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 144 | } |
Bob Wilson | 1633076 | 2009-09-16 00:17:28 +0000 | [diff] [blame] | 145 | |
| 146 | // Neon does not support vector divide/remainder operations. |
| 147 | setOperationAction(ISD::SDIV, VT.getSimpleVT(), Expand); |
| 148 | setOperationAction(ISD::UDIV, VT.getSimpleVT(), Expand); |
| 149 | setOperationAction(ISD::FDIV, VT.getSimpleVT(), Expand); |
| 150 | setOperationAction(ISD::SREM, VT.getSimpleVT(), Expand); |
| 151 | setOperationAction(ISD::UREM, VT.getSimpleVT(), Expand); |
| 152 | setOperationAction(ISD::FREM, VT.getSimpleVT(), Expand); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 153 | } |
| 154 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 155 | void ARMTargetLowering::addDRTypeForNEON(EVT VT) { |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 156 | addRegisterClass(VT, &ARM::DPRRegClass); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 157 | addTypeForNEON(VT, MVT::f64, MVT::v2i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 158 | } |
| 159 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 160 | void ARMTargetLowering::addQRTypeForNEON(EVT VT) { |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 161 | addRegisterClass(VT, &ARM::QPRRegClass); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 162 | addTypeForNEON(VT, MVT::v2f64, MVT::v4i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 163 | } |
| 164 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 165 | static TargetLoweringObjectFile *createTLOF(TargetMachine &TM) { |
| 166 | if (TM.getSubtarget<ARMSubtarget>().isTargetDarwin()) |
Bill Wendling | 505ad8b | 2010-03-15 21:09:38 +0000 | [diff] [blame] | 167 | return new TargetLoweringObjectFileMachO(); |
Bill Wendling | 94a1c63 | 2010-03-09 02:46:12 +0000 | [diff] [blame] | 168 | |
Chris Lattner | 80ec279 | 2009-08-02 00:34:36 +0000 | [diff] [blame] | 169 | return new ARMElfTargetObjectFile(); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 170 | } |
| 171 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 172 | ARMTargetLowering::ARMTargetLowering(TargetMachine &TM) |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 173 | : TargetLowering(TM, createTLOF(TM)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 174 | Subtarget = &TM.getSubtarget<ARMSubtarget>(); |
Evan Cheng | 3144687 | 2010-07-23 22:39:59 +0000 | [diff] [blame] | 175 | RegInfo = TM.getRegisterInfo(); |
Evan Cheng | 3ef1c87 | 2010-09-10 01:29:16 +0000 | [diff] [blame] | 176 | Itins = TM.getInstrItineraryData(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 177 | |
Duncan Sands | 28b77e9 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 178 | setBooleanVectorContents(ZeroOrNegativeOneBooleanContent); |
| 179 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 180 | if (Subtarget->isTargetDarwin()) { |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 181 | // Uses VFP for Thumb libfuncs if available. |
| 182 | if (Subtarget->isThumb() && Subtarget->hasVFP2()) { |
| 183 | // Single-precision floating-point arithmetic. |
| 184 | setLibcallName(RTLIB::ADD_F32, "__addsf3vfp"); |
| 185 | setLibcallName(RTLIB::SUB_F32, "__subsf3vfp"); |
| 186 | setLibcallName(RTLIB::MUL_F32, "__mulsf3vfp"); |
| 187 | setLibcallName(RTLIB::DIV_F32, "__divsf3vfp"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 188 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 189 | // Double-precision floating-point arithmetic. |
| 190 | setLibcallName(RTLIB::ADD_F64, "__adddf3vfp"); |
| 191 | setLibcallName(RTLIB::SUB_F64, "__subdf3vfp"); |
| 192 | setLibcallName(RTLIB::MUL_F64, "__muldf3vfp"); |
| 193 | setLibcallName(RTLIB::DIV_F64, "__divdf3vfp"); |
Evan Cheng | 193f850 | 2007-01-31 09:30:58 +0000 | [diff] [blame] | 194 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 195 | // Single-precision comparisons. |
| 196 | setLibcallName(RTLIB::OEQ_F32, "__eqsf2vfp"); |
| 197 | setLibcallName(RTLIB::UNE_F32, "__nesf2vfp"); |
| 198 | setLibcallName(RTLIB::OLT_F32, "__ltsf2vfp"); |
| 199 | setLibcallName(RTLIB::OLE_F32, "__lesf2vfp"); |
| 200 | setLibcallName(RTLIB::OGE_F32, "__gesf2vfp"); |
| 201 | setLibcallName(RTLIB::OGT_F32, "__gtsf2vfp"); |
| 202 | setLibcallName(RTLIB::UO_F32, "__unordsf2vfp"); |
| 203 | setLibcallName(RTLIB::O_F32, "__unordsf2vfp"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 204 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 205 | setCmpLibcallCC(RTLIB::OEQ_F32, ISD::SETNE); |
| 206 | setCmpLibcallCC(RTLIB::UNE_F32, ISD::SETNE); |
| 207 | setCmpLibcallCC(RTLIB::OLT_F32, ISD::SETNE); |
| 208 | setCmpLibcallCC(RTLIB::OLE_F32, ISD::SETNE); |
| 209 | setCmpLibcallCC(RTLIB::OGE_F32, ISD::SETNE); |
| 210 | setCmpLibcallCC(RTLIB::OGT_F32, ISD::SETNE); |
| 211 | setCmpLibcallCC(RTLIB::UO_F32, ISD::SETNE); |
| 212 | setCmpLibcallCC(RTLIB::O_F32, ISD::SETEQ); |
Evan Cheng | 193f850 | 2007-01-31 09:30:58 +0000 | [diff] [blame] | 213 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 214 | // Double-precision comparisons. |
| 215 | setLibcallName(RTLIB::OEQ_F64, "__eqdf2vfp"); |
| 216 | setLibcallName(RTLIB::UNE_F64, "__nedf2vfp"); |
| 217 | setLibcallName(RTLIB::OLT_F64, "__ltdf2vfp"); |
| 218 | setLibcallName(RTLIB::OLE_F64, "__ledf2vfp"); |
| 219 | setLibcallName(RTLIB::OGE_F64, "__gedf2vfp"); |
| 220 | setLibcallName(RTLIB::OGT_F64, "__gtdf2vfp"); |
| 221 | setLibcallName(RTLIB::UO_F64, "__unorddf2vfp"); |
| 222 | setLibcallName(RTLIB::O_F64, "__unorddf2vfp"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 223 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 224 | setCmpLibcallCC(RTLIB::OEQ_F64, ISD::SETNE); |
| 225 | setCmpLibcallCC(RTLIB::UNE_F64, ISD::SETNE); |
| 226 | setCmpLibcallCC(RTLIB::OLT_F64, ISD::SETNE); |
| 227 | setCmpLibcallCC(RTLIB::OLE_F64, ISD::SETNE); |
| 228 | setCmpLibcallCC(RTLIB::OGE_F64, ISD::SETNE); |
| 229 | setCmpLibcallCC(RTLIB::OGT_F64, ISD::SETNE); |
| 230 | setCmpLibcallCC(RTLIB::UO_F64, ISD::SETNE); |
| 231 | setCmpLibcallCC(RTLIB::O_F64, ISD::SETEQ); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 232 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 233 | // Floating-point to integer conversions. |
| 234 | // i64 conversions are done via library routines even when generating VFP |
| 235 | // instructions, so use the same ones. |
| 236 | setLibcallName(RTLIB::FPTOSINT_F64_I32, "__fixdfsivfp"); |
| 237 | setLibcallName(RTLIB::FPTOUINT_F64_I32, "__fixunsdfsivfp"); |
| 238 | setLibcallName(RTLIB::FPTOSINT_F32_I32, "__fixsfsivfp"); |
| 239 | setLibcallName(RTLIB::FPTOUINT_F32_I32, "__fixunssfsivfp"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 240 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 241 | // Conversions between floating types. |
| 242 | setLibcallName(RTLIB::FPROUND_F64_F32, "__truncdfsf2vfp"); |
| 243 | setLibcallName(RTLIB::FPEXT_F32_F64, "__extendsfdf2vfp"); |
| 244 | |
| 245 | // Integer to floating-point conversions. |
| 246 | // i64 conversions are done via library routines even when generating VFP |
| 247 | // instructions, so use the same ones. |
Bob Wilson | 2a14c52 | 2009-03-20 23:16:43 +0000 | [diff] [blame] | 248 | // FIXME: There appears to be some naming inconsistency in ARM libgcc: |
| 249 | // e.g., __floatunsidf vs. __floatunssidfvfp. |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 250 | setLibcallName(RTLIB::SINTTOFP_I32_F64, "__floatsidfvfp"); |
| 251 | setLibcallName(RTLIB::UINTTOFP_I32_F64, "__floatunssidfvfp"); |
| 252 | setLibcallName(RTLIB::SINTTOFP_I32_F32, "__floatsisfvfp"); |
| 253 | setLibcallName(RTLIB::UINTTOFP_I32_F32, "__floatunssisfvfp"); |
| 254 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 255 | } |
| 256 | |
Bob Wilson | 2f95461 | 2009-05-22 17:38:41 +0000 | [diff] [blame] | 257 | // These libcalls are not available in 32-bit. |
| 258 | setLibcallName(RTLIB::SHL_I128, 0); |
| 259 | setLibcallName(RTLIB::SRL_I128, 0); |
| 260 | setLibcallName(RTLIB::SRA_I128, 0); |
| 261 | |
Evan Cheng | 0704327 | 2012-02-21 20:46:00 +0000 | [diff] [blame] | 262 | if (Subtarget->isAAPCS_ABI() && !Subtarget->isTargetDarwin()) { |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 263 | // Double-precision floating-point arithmetic helper functions |
Anton Korobeynikov | 4f922f2 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 264 | // RTABI chapter 4.1.2, Table 2 |
| 265 | setLibcallName(RTLIB::ADD_F64, "__aeabi_dadd"); |
| 266 | setLibcallName(RTLIB::DIV_F64, "__aeabi_ddiv"); |
| 267 | setLibcallName(RTLIB::MUL_F64, "__aeabi_dmul"); |
| 268 | setLibcallName(RTLIB::SUB_F64, "__aeabi_dsub"); |
| 269 | setLibcallCallingConv(RTLIB::ADD_F64, CallingConv::ARM_AAPCS); |
| 270 | setLibcallCallingConv(RTLIB::DIV_F64, CallingConv::ARM_AAPCS); |
| 271 | setLibcallCallingConv(RTLIB::MUL_F64, CallingConv::ARM_AAPCS); |
| 272 | setLibcallCallingConv(RTLIB::SUB_F64, CallingConv::ARM_AAPCS); |
| 273 | |
| 274 | // Double-precision floating-point comparison helper functions |
| 275 | // RTABI chapter 4.1.2, Table 3 |
| 276 | setLibcallName(RTLIB::OEQ_F64, "__aeabi_dcmpeq"); |
| 277 | setCmpLibcallCC(RTLIB::OEQ_F64, ISD::SETNE); |
| 278 | setLibcallName(RTLIB::UNE_F64, "__aeabi_dcmpeq"); |
| 279 | setCmpLibcallCC(RTLIB::UNE_F64, ISD::SETEQ); |
| 280 | setLibcallName(RTLIB::OLT_F64, "__aeabi_dcmplt"); |
| 281 | setCmpLibcallCC(RTLIB::OLT_F64, ISD::SETNE); |
| 282 | setLibcallName(RTLIB::OLE_F64, "__aeabi_dcmple"); |
| 283 | setCmpLibcallCC(RTLIB::OLE_F64, ISD::SETNE); |
| 284 | setLibcallName(RTLIB::OGE_F64, "__aeabi_dcmpge"); |
| 285 | setCmpLibcallCC(RTLIB::OGE_F64, ISD::SETNE); |
| 286 | setLibcallName(RTLIB::OGT_F64, "__aeabi_dcmpgt"); |
| 287 | setCmpLibcallCC(RTLIB::OGT_F64, ISD::SETNE); |
| 288 | setLibcallName(RTLIB::UO_F64, "__aeabi_dcmpun"); |
| 289 | setCmpLibcallCC(RTLIB::UO_F64, ISD::SETNE); |
| 290 | setLibcallName(RTLIB::O_F64, "__aeabi_dcmpun"); |
| 291 | setCmpLibcallCC(RTLIB::O_F64, ISD::SETEQ); |
| 292 | setLibcallCallingConv(RTLIB::OEQ_F64, CallingConv::ARM_AAPCS); |
| 293 | setLibcallCallingConv(RTLIB::UNE_F64, CallingConv::ARM_AAPCS); |
| 294 | setLibcallCallingConv(RTLIB::OLT_F64, CallingConv::ARM_AAPCS); |
| 295 | setLibcallCallingConv(RTLIB::OLE_F64, CallingConv::ARM_AAPCS); |
| 296 | setLibcallCallingConv(RTLIB::OGE_F64, CallingConv::ARM_AAPCS); |
| 297 | setLibcallCallingConv(RTLIB::OGT_F64, CallingConv::ARM_AAPCS); |
| 298 | setLibcallCallingConv(RTLIB::UO_F64, CallingConv::ARM_AAPCS); |
| 299 | setLibcallCallingConv(RTLIB::O_F64, CallingConv::ARM_AAPCS); |
| 300 | |
| 301 | // Single-precision floating-point arithmetic helper functions |
| 302 | // RTABI chapter 4.1.2, Table 4 |
| 303 | setLibcallName(RTLIB::ADD_F32, "__aeabi_fadd"); |
| 304 | setLibcallName(RTLIB::DIV_F32, "__aeabi_fdiv"); |
| 305 | setLibcallName(RTLIB::MUL_F32, "__aeabi_fmul"); |
| 306 | setLibcallName(RTLIB::SUB_F32, "__aeabi_fsub"); |
| 307 | setLibcallCallingConv(RTLIB::ADD_F32, CallingConv::ARM_AAPCS); |
| 308 | setLibcallCallingConv(RTLIB::DIV_F32, CallingConv::ARM_AAPCS); |
| 309 | setLibcallCallingConv(RTLIB::MUL_F32, CallingConv::ARM_AAPCS); |
| 310 | setLibcallCallingConv(RTLIB::SUB_F32, CallingConv::ARM_AAPCS); |
| 311 | |
| 312 | // Single-precision floating-point comparison helper functions |
| 313 | // RTABI chapter 4.1.2, Table 5 |
| 314 | setLibcallName(RTLIB::OEQ_F32, "__aeabi_fcmpeq"); |
| 315 | setCmpLibcallCC(RTLIB::OEQ_F32, ISD::SETNE); |
| 316 | setLibcallName(RTLIB::UNE_F32, "__aeabi_fcmpeq"); |
| 317 | setCmpLibcallCC(RTLIB::UNE_F32, ISD::SETEQ); |
| 318 | setLibcallName(RTLIB::OLT_F32, "__aeabi_fcmplt"); |
| 319 | setCmpLibcallCC(RTLIB::OLT_F32, ISD::SETNE); |
| 320 | setLibcallName(RTLIB::OLE_F32, "__aeabi_fcmple"); |
| 321 | setCmpLibcallCC(RTLIB::OLE_F32, ISD::SETNE); |
| 322 | setLibcallName(RTLIB::OGE_F32, "__aeabi_fcmpge"); |
| 323 | setCmpLibcallCC(RTLIB::OGE_F32, ISD::SETNE); |
| 324 | setLibcallName(RTLIB::OGT_F32, "__aeabi_fcmpgt"); |
| 325 | setCmpLibcallCC(RTLIB::OGT_F32, ISD::SETNE); |
| 326 | setLibcallName(RTLIB::UO_F32, "__aeabi_fcmpun"); |
| 327 | setCmpLibcallCC(RTLIB::UO_F32, ISD::SETNE); |
| 328 | setLibcallName(RTLIB::O_F32, "__aeabi_fcmpun"); |
| 329 | setCmpLibcallCC(RTLIB::O_F32, ISD::SETEQ); |
| 330 | setLibcallCallingConv(RTLIB::OEQ_F32, CallingConv::ARM_AAPCS); |
| 331 | setLibcallCallingConv(RTLIB::UNE_F32, CallingConv::ARM_AAPCS); |
| 332 | setLibcallCallingConv(RTLIB::OLT_F32, CallingConv::ARM_AAPCS); |
| 333 | setLibcallCallingConv(RTLIB::OLE_F32, CallingConv::ARM_AAPCS); |
| 334 | setLibcallCallingConv(RTLIB::OGE_F32, CallingConv::ARM_AAPCS); |
| 335 | setLibcallCallingConv(RTLIB::OGT_F32, CallingConv::ARM_AAPCS); |
| 336 | setLibcallCallingConv(RTLIB::UO_F32, CallingConv::ARM_AAPCS); |
| 337 | setLibcallCallingConv(RTLIB::O_F32, CallingConv::ARM_AAPCS); |
| 338 | |
| 339 | // Floating-point to integer conversions. |
| 340 | // RTABI chapter 4.1.2, Table 6 |
| 341 | setLibcallName(RTLIB::FPTOSINT_F64_I32, "__aeabi_d2iz"); |
| 342 | setLibcallName(RTLIB::FPTOUINT_F64_I32, "__aeabi_d2uiz"); |
| 343 | setLibcallName(RTLIB::FPTOSINT_F64_I64, "__aeabi_d2lz"); |
| 344 | setLibcallName(RTLIB::FPTOUINT_F64_I64, "__aeabi_d2ulz"); |
| 345 | setLibcallName(RTLIB::FPTOSINT_F32_I32, "__aeabi_f2iz"); |
| 346 | setLibcallName(RTLIB::FPTOUINT_F32_I32, "__aeabi_f2uiz"); |
| 347 | setLibcallName(RTLIB::FPTOSINT_F32_I64, "__aeabi_f2lz"); |
| 348 | setLibcallName(RTLIB::FPTOUINT_F32_I64, "__aeabi_f2ulz"); |
| 349 | setLibcallCallingConv(RTLIB::FPTOSINT_F64_I32, CallingConv::ARM_AAPCS); |
| 350 | setLibcallCallingConv(RTLIB::FPTOUINT_F64_I32, CallingConv::ARM_AAPCS); |
| 351 | setLibcallCallingConv(RTLIB::FPTOSINT_F64_I64, CallingConv::ARM_AAPCS); |
| 352 | setLibcallCallingConv(RTLIB::FPTOUINT_F64_I64, CallingConv::ARM_AAPCS); |
| 353 | setLibcallCallingConv(RTLIB::FPTOSINT_F32_I32, CallingConv::ARM_AAPCS); |
| 354 | setLibcallCallingConv(RTLIB::FPTOUINT_F32_I32, CallingConv::ARM_AAPCS); |
| 355 | setLibcallCallingConv(RTLIB::FPTOSINT_F32_I64, CallingConv::ARM_AAPCS); |
| 356 | setLibcallCallingConv(RTLIB::FPTOUINT_F32_I64, CallingConv::ARM_AAPCS); |
| 357 | |
| 358 | // Conversions between floating types. |
| 359 | // RTABI chapter 4.1.2, Table 7 |
| 360 | setLibcallName(RTLIB::FPROUND_F64_F32, "__aeabi_d2f"); |
| 361 | setLibcallName(RTLIB::FPEXT_F32_F64, "__aeabi_f2d"); |
| 362 | setLibcallCallingConv(RTLIB::FPROUND_F64_F32, CallingConv::ARM_AAPCS); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 363 | setLibcallCallingConv(RTLIB::FPEXT_F32_F64, CallingConv::ARM_AAPCS); |
Anton Korobeynikov | 4f922f2 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 364 | |
| 365 | // Integer to floating-point conversions. |
| 366 | // RTABI chapter 4.1.2, Table 8 |
| 367 | setLibcallName(RTLIB::SINTTOFP_I32_F64, "__aeabi_i2d"); |
| 368 | setLibcallName(RTLIB::UINTTOFP_I32_F64, "__aeabi_ui2d"); |
| 369 | setLibcallName(RTLIB::SINTTOFP_I64_F64, "__aeabi_l2d"); |
| 370 | setLibcallName(RTLIB::UINTTOFP_I64_F64, "__aeabi_ul2d"); |
| 371 | setLibcallName(RTLIB::SINTTOFP_I32_F32, "__aeabi_i2f"); |
| 372 | setLibcallName(RTLIB::UINTTOFP_I32_F32, "__aeabi_ui2f"); |
| 373 | setLibcallName(RTLIB::SINTTOFP_I64_F32, "__aeabi_l2f"); |
| 374 | setLibcallName(RTLIB::UINTTOFP_I64_F32, "__aeabi_ul2f"); |
| 375 | setLibcallCallingConv(RTLIB::SINTTOFP_I32_F64, CallingConv::ARM_AAPCS); |
| 376 | setLibcallCallingConv(RTLIB::UINTTOFP_I32_F64, CallingConv::ARM_AAPCS); |
| 377 | setLibcallCallingConv(RTLIB::SINTTOFP_I64_F64, CallingConv::ARM_AAPCS); |
| 378 | setLibcallCallingConv(RTLIB::UINTTOFP_I64_F64, CallingConv::ARM_AAPCS); |
| 379 | setLibcallCallingConv(RTLIB::SINTTOFP_I32_F32, CallingConv::ARM_AAPCS); |
| 380 | setLibcallCallingConv(RTLIB::UINTTOFP_I32_F32, CallingConv::ARM_AAPCS); |
| 381 | setLibcallCallingConv(RTLIB::SINTTOFP_I64_F32, CallingConv::ARM_AAPCS); |
| 382 | setLibcallCallingConv(RTLIB::UINTTOFP_I64_F32, CallingConv::ARM_AAPCS); |
| 383 | |
| 384 | // Long long helper functions |
| 385 | // RTABI chapter 4.2, Table 9 |
| 386 | setLibcallName(RTLIB::MUL_I64, "__aeabi_lmul"); |
Anton Korobeynikov | 4f922f2 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 387 | setLibcallName(RTLIB::SHL_I64, "__aeabi_llsl"); |
| 388 | setLibcallName(RTLIB::SRL_I64, "__aeabi_llsr"); |
| 389 | setLibcallName(RTLIB::SRA_I64, "__aeabi_lasr"); |
| 390 | setLibcallCallingConv(RTLIB::MUL_I64, CallingConv::ARM_AAPCS); |
| 391 | setLibcallCallingConv(RTLIB::SDIV_I64, CallingConv::ARM_AAPCS); |
| 392 | setLibcallCallingConv(RTLIB::UDIV_I64, CallingConv::ARM_AAPCS); |
| 393 | setLibcallCallingConv(RTLIB::SHL_I64, CallingConv::ARM_AAPCS); |
| 394 | setLibcallCallingConv(RTLIB::SRL_I64, CallingConv::ARM_AAPCS); |
| 395 | setLibcallCallingConv(RTLIB::SRA_I64, CallingConv::ARM_AAPCS); |
| 396 | |
| 397 | // Integer division functions |
| 398 | // RTABI chapter 4.3.1 |
| 399 | setLibcallName(RTLIB::SDIV_I8, "__aeabi_idiv"); |
| 400 | setLibcallName(RTLIB::SDIV_I16, "__aeabi_idiv"); |
| 401 | setLibcallName(RTLIB::SDIV_I32, "__aeabi_idiv"); |
Anton Korobeynikov | 6edd588 | 2012-01-29 09:11:50 +0000 | [diff] [blame] | 402 | setLibcallName(RTLIB::SDIV_I64, "__aeabi_ldivmod"); |
Anton Korobeynikov | 4f922f2 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 403 | setLibcallName(RTLIB::UDIV_I8, "__aeabi_uidiv"); |
| 404 | setLibcallName(RTLIB::UDIV_I16, "__aeabi_uidiv"); |
| 405 | setLibcallName(RTLIB::UDIV_I32, "__aeabi_uidiv"); |
Anton Korobeynikov | 6edd588 | 2012-01-29 09:11:50 +0000 | [diff] [blame] | 406 | setLibcallName(RTLIB::UDIV_I64, "__aeabi_uldivmod"); |
Anton Korobeynikov | 4f922f2 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 407 | setLibcallCallingConv(RTLIB::SDIV_I8, CallingConv::ARM_AAPCS); |
| 408 | setLibcallCallingConv(RTLIB::SDIV_I16, CallingConv::ARM_AAPCS); |
| 409 | setLibcallCallingConv(RTLIB::SDIV_I32, CallingConv::ARM_AAPCS); |
Anton Korobeynikov | 6edd588 | 2012-01-29 09:11:50 +0000 | [diff] [blame] | 410 | setLibcallCallingConv(RTLIB::SDIV_I64, CallingConv::ARM_AAPCS); |
Anton Korobeynikov | 4f922f2 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 411 | setLibcallCallingConv(RTLIB::UDIV_I8, CallingConv::ARM_AAPCS); |
| 412 | setLibcallCallingConv(RTLIB::UDIV_I16, CallingConv::ARM_AAPCS); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 413 | setLibcallCallingConv(RTLIB::UDIV_I32, CallingConv::ARM_AAPCS); |
Anton Korobeynikov | 6edd588 | 2012-01-29 09:11:50 +0000 | [diff] [blame] | 414 | setLibcallCallingConv(RTLIB::UDIV_I64, CallingConv::ARM_AAPCS); |
Renato Golin | 1ec11fb | 2011-05-22 21:41:23 +0000 | [diff] [blame] | 415 | |
| 416 | // Memory operations |
| 417 | // RTABI chapter 4.3.4 |
| 418 | setLibcallName(RTLIB::MEMCPY, "__aeabi_memcpy"); |
| 419 | setLibcallName(RTLIB::MEMMOVE, "__aeabi_memmove"); |
| 420 | setLibcallName(RTLIB::MEMSET, "__aeabi_memset"); |
Anton Korobeynikov | 6edd588 | 2012-01-29 09:11:50 +0000 | [diff] [blame] | 421 | setLibcallCallingConv(RTLIB::MEMCPY, CallingConv::ARM_AAPCS); |
| 422 | setLibcallCallingConv(RTLIB::MEMMOVE, CallingConv::ARM_AAPCS); |
| 423 | setLibcallCallingConv(RTLIB::MEMSET, CallingConv::ARM_AAPCS); |
Anton Korobeynikov | 72977a4 | 2009-08-14 20:10:52 +0000 | [diff] [blame] | 424 | } |
| 425 | |
Bob Wilson | 2fef457 | 2011-10-07 16:59:21 +0000 | [diff] [blame] | 426 | // Use divmod compiler-rt calls for iOS 5.0 and later. |
| 427 | if (Subtarget->getTargetTriple().getOS() == Triple::IOS && |
| 428 | !Subtarget->getTargetTriple().isOSVersionLT(5, 0)) { |
| 429 | setLibcallName(RTLIB::SDIVREM_I32, "__divmodsi4"); |
| 430 | setLibcallName(RTLIB::UDIVREM_I32, "__udivmodsi4"); |
| 431 | } |
| 432 | |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 433 | if (Subtarget->isThumb1Only()) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 434 | addRegisterClass(MVT::i32, &ARM::tGPRRegClass); |
Jim Grosbach | 30eae3c | 2009-04-07 20:34:09 +0000 | [diff] [blame] | 435 | else |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 436 | addRegisterClass(MVT::i32, &ARM::GPRRegClass); |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 437 | if (!TM.Options.UseSoftFloat && Subtarget->hasVFP2() && |
| 438 | !Subtarget->isThumb1Only()) { |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 439 | addRegisterClass(MVT::f32, &ARM::SPRRegClass); |
Jim Grosbach | fcba5e6 | 2010-08-11 15:44:15 +0000 | [diff] [blame] | 440 | if (!Subtarget->isFPOnlySP()) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 441 | addRegisterClass(MVT::f64, &ARM::DPRRegClass); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 442 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 443 | setTruncStoreAction(MVT::f64, MVT::f32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 444 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 445 | |
Eli Friedman | 9f1f26a | 2011-11-08 01:43:53 +0000 | [diff] [blame] | 446 | for (unsigned VT = (unsigned)MVT::FIRST_VECTOR_VALUETYPE; |
| 447 | VT <= (unsigned)MVT::LAST_VECTOR_VALUETYPE; ++VT) { |
| 448 | for (unsigned InnerVT = (unsigned)MVT::FIRST_VECTOR_VALUETYPE; |
| 449 | InnerVT <= (unsigned)MVT::LAST_VECTOR_VALUETYPE; ++InnerVT) |
| 450 | setTruncStoreAction((MVT::SimpleValueType)VT, |
| 451 | (MVT::SimpleValueType)InnerVT, Expand); |
| 452 | setLoadExtAction(ISD::SEXTLOAD, (MVT::SimpleValueType)VT, Expand); |
| 453 | setLoadExtAction(ISD::ZEXTLOAD, (MVT::SimpleValueType)VT, Expand); |
| 454 | setLoadExtAction(ISD::EXTLOAD, (MVT::SimpleValueType)VT, Expand); |
| 455 | } |
| 456 | |
Lang Hames | 45b5f88 | 2012-03-15 18:49:02 +0000 | [diff] [blame] | 457 | setOperationAction(ISD::ConstantFP, MVT::f32, Custom); |
| 458 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 459 | if (Subtarget->hasNEON()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 460 | addDRTypeForNEON(MVT::v2f32); |
| 461 | addDRTypeForNEON(MVT::v8i8); |
| 462 | addDRTypeForNEON(MVT::v4i16); |
| 463 | addDRTypeForNEON(MVT::v2i32); |
| 464 | addDRTypeForNEON(MVT::v1i64); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 465 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 466 | addQRTypeForNEON(MVT::v4f32); |
| 467 | addQRTypeForNEON(MVT::v2f64); |
| 468 | addQRTypeForNEON(MVT::v16i8); |
| 469 | addQRTypeForNEON(MVT::v8i16); |
| 470 | addQRTypeForNEON(MVT::v4i32); |
| 471 | addQRTypeForNEON(MVT::v2i64); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 472 | |
Bob Wilson | 74dc72e | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 473 | // v2f64 is legal so that QR subregs can be extracted as f64 elements, but |
| 474 | // neither Neon nor VFP support any arithmetic operations on it. |
Stepan Dyatkovskiy | 3e0dc06 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 475 | // The same with v4f32. But keep in mind that vadd, vsub, vmul are natively |
| 476 | // supported for v4f32. |
Bob Wilson | 74dc72e | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 477 | setOperationAction(ISD::FADD, MVT::v2f64, Expand); |
| 478 | setOperationAction(ISD::FSUB, MVT::v2f64, Expand); |
| 479 | setOperationAction(ISD::FMUL, MVT::v2f64, Expand); |
Stepan Dyatkovskiy | 3e0dc06 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 480 | // FIXME: Code duplication: FDIV and FREM are expanded always, see |
| 481 | // ARMTargetLowering::addTypeForNEON method for details. |
Bob Wilson | 74dc72e | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 482 | setOperationAction(ISD::FDIV, MVT::v2f64, Expand); |
| 483 | setOperationAction(ISD::FREM, MVT::v2f64, Expand); |
Stepan Dyatkovskiy | 3e0dc06 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 484 | // FIXME: Create unittest. |
| 485 | // In another words, find a way when "copysign" appears in DAG with vector |
| 486 | // operands. |
Bob Wilson | 74dc72e | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 487 | setOperationAction(ISD::FCOPYSIGN, MVT::v2f64, Expand); |
Stepan Dyatkovskiy | 3e0dc06 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 488 | // FIXME: Code duplication: SETCC has custom operation action, see |
| 489 | // ARMTargetLowering::addTypeForNEON method for details. |
Duncan Sands | 28b77e9 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 490 | setOperationAction(ISD::SETCC, MVT::v2f64, Expand); |
Stepan Dyatkovskiy | 3e0dc06 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 491 | // FIXME: Create unittest for FNEG and for FABS. |
Bob Wilson | 74dc72e | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 492 | setOperationAction(ISD::FNEG, MVT::v2f64, Expand); |
| 493 | setOperationAction(ISD::FABS, MVT::v2f64, Expand); |
| 494 | setOperationAction(ISD::FSQRT, MVT::v2f64, Expand); |
| 495 | setOperationAction(ISD::FSIN, MVT::v2f64, Expand); |
| 496 | setOperationAction(ISD::FCOS, MVT::v2f64, Expand); |
| 497 | setOperationAction(ISD::FPOWI, MVT::v2f64, Expand); |
| 498 | setOperationAction(ISD::FPOW, MVT::v2f64, Expand); |
| 499 | setOperationAction(ISD::FLOG, MVT::v2f64, Expand); |
| 500 | setOperationAction(ISD::FLOG2, MVT::v2f64, Expand); |
| 501 | setOperationAction(ISD::FLOG10, MVT::v2f64, Expand); |
| 502 | setOperationAction(ISD::FEXP, MVT::v2f64, Expand); |
| 503 | setOperationAction(ISD::FEXP2, MVT::v2f64, Expand); |
Stepan Dyatkovskiy | 3e0dc06 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 504 | // FIXME: Create unittest for FCEIL, FTRUNC, FRINT, FNEARBYINT, FFLOOR. |
Bob Wilson | 74dc72e | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 505 | setOperationAction(ISD::FCEIL, MVT::v2f64, Expand); |
| 506 | setOperationAction(ISD::FTRUNC, MVT::v2f64, Expand); |
| 507 | setOperationAction(ISD::FRINT, MVT::v2f64, Expand); |
| 508 | setOperationAction(ISD::FNEARBYINT, MVT::v2f64, Expand); |
| 509 | setOperationAction(ISD::FFLOOR, MVT::v2f64, Expand); |
Lang Hames | c0a9f82 | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 510 | |
Stepan Dyatkovskiy | 3e0dc06 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 511 | setOperationAction(ISD::FSQRT, MVT::v4f32, Expand); |
| 512 | setOperationAction(ISD::FSIN, MVT::v4f32, Expand); |
| 513 | setOperationAction(ISD::FCOS, MVT::v4f32, Expand); |
| 514 | setOperationAction(ISD::FPOWI, MVT::v4f32, Expand); |
| 515 | setOperationAction(ISD::FPOW, MVT::v4f32, Expand); |
| 516 | setOperationAction(ISD::FLOG, MVT::v4f32, Expand); |
| 517 | setOperationAction(ISD::FLOG2, MVT::v4f32, Expand); |
| 518 | setOperationAction(ISD::FLOG10, MVT::v4f32, Expand); |
| 519 | setOperationAction(ISD::FEXP, MVT::v4f32, Expand); |
| 520 | setOperationAction(ISD::FEXP2, MVT::v4f32, Expand); |
Bob Wilson | 74dc72e | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 521 | |
Bob Wilson | 642b329 | 2009-09-16 00:32:15 +0000 | [diff] [blame] | 522 | // Neon does not support some operations on v1i64 and v2i64 types. |
| 523 | setOperationAction(ISD::MUL, MVT::v1i64, Expand); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 524 | // Custom handling for some quad-vector types to detect VMULL. |
| 525 | setOperationAction(ISD::MUL, MVT::v8i16, Custom); |
| 526 | setOperationAction(ISD::MUL, MVT::v4i32, Custom); |
| 527 | setOperationAction(ISD::MUL, MVT::v2i64, Custom); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 528 | // Custom handling for some vector types to avoid expensive expansions |
| 529 | setOperationAction(ISD::SDIV, MVT::v4i16, Custom); |
| 530 | setOperationAction(ISD::SDIV, MVT::v8i8, Custom); |
| 531 | setOperationAction(ISD::UDIV, MVT::v4i16, Custom); |
| 532 | setOperationAction(ISD::UDIV, MVT::v8i8, Custom); |
Duncan Sands | 28b77e9 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 533 | setOperationAction(ISD::SETCC, MVT::v1i64, Expand); |
| 534 | setOperationAction(ISD::SETCC, MVT::v2i64, Expand); |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 535 | // 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] | 536 | // a destination type that is wider than the source, and nor does |
| 537 | // it have a FP_TO_[SU]INT instruction with a narrower destination than |
| 538 | // source. |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 539 | setOperationAction(ISD::SINT_TO_FP, MVT::v4i16, Custom); |
| 540 | setOperationAction(ISD::UINT_TO_FP, MVT::v4i16, Custom); |
James Molloy | 873fd5f | 2012-02-20 09:24:05 +0000 | [diff] [blame] | 541 | setOperationAction(ISD::FP_TO_UINT, MVT::v4i16, Custom); |
| 542 | setOperationAction(ISD::FP_TO_SINT, MVT::v4i16, Custom); |
Bob Wilson | 642b329 | 2009-09-16 00:32:15 +0000 | [diff] [blame] | 543 | |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 544 | setTargetDAGCombine(ISD::INTRINSIC_VOID); |
| 545 | setTargetDAGCombine(ISD::INTRINSIC_W_CHAIN); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 546 | setTargetDAGCombine(ISD::INTRINSIC_WO_CHAIN); |
| 547 | setTargetDAGCombine(ISD::SHL); |
| 548 | setTargetDAGCombine(ISD::SRL); |
| 549 | setTargetDAGCombine(ISD::SRA); |
| 550 | setTargetDAGCombine(ISD::SIGN_EXTEND); |
| 551 | setTargetDAGCombine(ISD::ZERO_EXTEND); |
| 552 | setTargetDAGCombine(ISD::ANY_EXTEND); |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 553 | setTargetDAGCombine(ISD::SELECT_CC); |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 554 | setTargetDAGCombine(ISD::BUILD_VECTOR); |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 555 | setTargetDAGCombine(ISD::VECTOR_SHUFFLE); |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 556 | setTargetDAGCombine(ISD::INSERT_VECTOR_ELT); |
| 557 | setTargetDAGCombine(ISD::STORE); |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 558 | setTargetDAGCombine(ISD::FP_TO_SINT); |
| 559 | setTargetDAGCombine(ISD::FP_TO_UINT); |
| 560 | setTargetDAGCombine(ISD::FDIV); |
Nadav Rotem | 004a24b | 2011-10-15 20:03:12 +0000 | [diff] [blame] | 561 | |
James Molloy | 873fd5f | 2012-02-20 09:24:05 +0000 | [diff] [blame] | 562 | // It is legal to extload from v4i8 to v4i16 or v4i32. |
| 563 | MVT Tys[6] = {MVT::v8i8, MVT::v4i8, MVT::v2i8, |
| 564 | MVT::v4i16, MVT::v2i16, |
| 565 | MVT::v2i32}; |
| 566 | for (unsigned i = 0; i < 6; ++i) { |
| 567 | setLoadExtAction(ISD::EXTLOAD, Tys[i], Legal); |
| 568 | setLoadExtAction(ISD::ZEXTLOAD, Tys[i], Legal); |
| 569 | setLoadExtAction(ISD::SEXTLOAD, Tys[i], Legal); |
| 570 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 571 | } |
| 572 | |
Evan Cheng | 9f8cbd1 | 2007-05-18 00:19:34 +0000 | [diff] [blame] | 573 | computeRegisterProperties(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 574 | |
| 575 | // ARM does not have f32 extending load. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 576 | setLoadExtAction(ISD::EXTLOAD, MVT::f32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 577 | |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 578 | // ARM does not have i1 sign extending load. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 579 | setLoadExtAction(ISD::SEXTLOAD, MVT::i1, Promote); |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 580 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 581 | // ARM supports all 4 flavors of integer indexed load / store. |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 582 | if (!Subtarget->isThumb1Only()) { |
| 583 | for (unsigned im = (unsigned)ISD::PRE_INC; |
| 584 | im != (unsigned)ISD::LAST_INDEXED_MODE; ++im) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 585 | setIndexedLoadAction(im, MVT::i1, Legal); |
| 586 | setIndexedLoadAction(im, MVT::i8, Legal); |
| 587 | setIndexedLoadAction(im, MVT::i16, Legal); |
| 588 | setIndexedLoadAction(im, MVT::i32, Legal); |
| 589 | setIndexedStoreAction(im, MVT::i1, Legal); |
| 590 | setIndexedStoreAction(im, MVT::i8, Legal); |
| 591 | setIndexedStoreAction(im, MVT::i16, Legal); |
| 592 | setIndexedStoreAction(im, MVT::i32, Legal); |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 593 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | // i64 operation support. |
Eric Christopher | 2cc4013 | 2011-04-19 18:49:19 +0000 | [diff] [blame] | 597 | setOperationAction(ISD::MUL, MVT::i64, Expand); |
| 598 | setOperationAction(ISD::MULHU, MVT::i32, Expand); |
Evan Cheng | 5b9fcd1 | 2009-07-07 01:17:28 +0000 | [diff] [blame] | 599 | if (Subtarget->isThumb1Only()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 600 | setOperationAction(ISD::UMUL_LOHI, MVT::i32, Expand); |
| 601 | setOperationAction(ISD::SMUL_LOHI, MVT::i32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 602 | } |
Jim Grosbach | a760398 | 2011-07-01 21:12:19 +0000 | [diff] [blame] | 603 | if (Subtarget->isThumb1Only() || !Subtarget->hasV6Ops() |
| 604 | || (Subtarget->isThumb2() && !Subtarget->hasThumb2DSP())) |
Eric Christopher | 2cc4013 | 2011-04-19 18:49:19 +0000 | [diff] [blame] | 605 | setOperationAction(ISD::MULHS, MVT::i32, Expand); |
| 606 | |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 607 | setOperationAction(ISD::SHL_PARTS, MVT::i32, Custom); |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 608 | setOperationAction(ISD::SRA_PARTS, MVT::i32, Custom); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 609 | setOperationAction(ISD::SRL_PARTS, MVT::i32, Custom); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 610 | setOperationAction(ISD::SRL, MVT::i64, Custom); |
| 611 | setOperationAction(ISD::SRA, MVT::i64, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 612 | |
Evan Cheng | 342e316 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 613 | if (!Subtarget->isThumb1Only()) { |
| 614 | // FIXME: We should do this for Thumb1 as well. |
| 615 | setOperationAction(ISD::ADDC, MVT::i32, Custom); |
| 616 | setOperationAction(ISD::ADDE, MVT::i32, Custom); |
| 617 | setOperationAction(ISD::SUBC, MVT::i32, Custom); |
| 618 | setOperationAction(ISD::SUBE, MVT::i32, Custom); |
| 619 | } |
| 620 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 621 | // ARM does not have ROTL. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 622 | setOperationAction(ISD::ROTL, MVT::i32, Expand); |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 623 | setOperationAction(ISD::CTTZ, MVT::i32, Custom); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 624 | setOperationAction(ISD::CTPOP, MVT::i32, Expand); |
David Goodwin | 24062ac | 2009-06-26 20:47:43 +0000 | [diff] [blame] | 625 | if (!Subtarget->hasV5TOps() || Subtarget->isThumb1Only()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 626 | setOperationAction(ISD::CTLZ, MVT::i32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 627 | |
Chandler Carruth | 63974b2 | 2011-12-13 01:56:10 +0000 | [diff] [blame] | 628 | // These just redirect to CTTZ and CTLZ on ARM. |
| 629 | setOperationAction(ISD::CTTZ_ZERO_UNDEF , MVT::i32 , Expand); |
| 630 | setOperationAction(ISD::CTLZ_ZERO_UNDEF , MVT::i32 , Expand); |
| 631 | |
Lauro Ramos Venancio | 368f20f | 2007-03-16 22:54:16 +0000 | [diff] [blame] | 632 | // Only ARMv6 has BSWAP. |
| 633 | if (!Subtarget->hasV6Ops()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 634 | setOperationAction(ISD::BSWAP, MVT::i32, Expand); |
Lauro Ramos Venancio | 368f20f | 2007-03-16 22:54:16 +0000 | [diff] [blame] | 635 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 636 | // These are expanded into libcalls. |
Evan Cheng | 1f190c8 | 2010-11-19 06:28:11 +0000 | [diff] [blame] | 637 | if (!Subtarget->hasDivide() || !Subtarget->isThumb2()) { |
Jim Grosbach | b1dc393 | 2010-05-05 20:44:35 +0000 | [diff] [blame] | 638 | // v7M has a hardware divider |
| 639 | setOperationAction(ISD::SDIV, MVT::i32, Expand); |
| 640 | setOperationAction(ISD::UDIV, MVT::i32, Expand); |
| 641 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 642 | setOperationAction(ISD::SREM, MVT::i32, Expand); |
| 643 | setOperationAction(ISD::UREM, MVT::i32, Expand); |
| 644 | setOperationAction(ISD::SDIVREM, MVT::i32, Expand); |
| 645 | setOperationAction(ISD::UDIVREM, MVT::i32, Expand); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 646 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 647 | setOperationAction(ISD::GlobalAddress, MVT::i32, Custom); |
| 648 | setOperationAction(ISD::ConstantPool, MVT::i32, Custom); |
| 649 | setOperationAction(ISD::GLOBAL_OFFSET_TABLE, MVT::i32, Custom); |
| 650 | setOperationAction(ISD::GlobalTLSAddress, MVT::i32, Custom); |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 651 | setOperationAction(ISD::BlockAddress, MVT::i32, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 652 | |
Evan Cheng | 4da0c7c | 2011-04-08 21:37:21 +0000 | [diff] [blame] | 653 | setOperationAction(ISD::TRAP, MVT::Other, Legal); |
Evan Cheng | fb3611d | 2010-05-11 07:26:32 +0000 | [diff] [blame] | 654 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 655 | // Use the default implementation. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 656 | setOperationAction(ISD::VASTART, MVT::Other, Custom); |
| 657 | setOperationAction(ISD::VAARG, MVT::Other, Expand); |
| 658 | setOperationAction(ISD::VACOPY, MVT::Other, Expand); |
| 659 | setOperationAction(ISD::VAEND, MVT::Other, Expand); |
| 660 | setOperationAction(ISD::STACKSAVE, MVT::Other, Expand); |
| 661 | setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand); |
Bill Wendling | bdf9db6 | 2012-02-13 23:47:16 +0000 | [diff] [blame] | 662 | |
| 663 | if (!Subtarget->isTargetDarwin()) { |
| 664 | // Non-Darwin platforms may return values in these registers via the |
| 665 | // personality function. |
| 666 | setOperationAction(ISD::EHSELECTION, MVT::i32, Expand); |
| 667 | setOperationAction(ISD::EXCEPTIONADDR, MVT::i32, Expand); |
| 668 | setExceptionPointerRegister(ARM::R0); |
| 669 | setExceptionSelectorRegister(ARM::R1); |
| 670 | } |
Anton Korobeynikov | 5899a60 | 2011-01-24 22:38:45 +0000 | [diff] [blame] | 671 | |
Evan Cheng | 3a1588a | 2010-04-15 22:20:34 +0000 | [diff] [blame] | 672 | setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32, Expand); |
Evan Cheng | 11db068 | 2010-08-11 06:22:01 +0000 | [diff] [blame] | 673 | // ARMv6 Thumb1 (except for CPUs that support dmb / dsb) and earlier use |
| 674 | // the default expansion. |
Eli Friedman | 4db5aca | 2011-08-29 18:23:02 +0000 | [diff] [blame] | 675 | // FIXME: This should be checking for v6k, not just v6. |
Evan Cheng | 11db068 | 2010-08-11 06:22:01 +0000 | [diff] [blame] | 676 | if (Subtarget->hasDataBarrier() || |
Bob Wilson | 54f9256 | 2010-11-09 22:50:44 +0000 | [diff] [blame] | 677 | (Subtarget->hasV6Ops() && !Subtarget->isThumb())) { |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 678 | // membarrier needs custom lowering; the rest are legal and handled |
| 679 | // normally. |
| 680 | setOperationAction(ISD::MEMBARRIER, MVT::Other, Custom); |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 681 | setOperationAction(ISD::ATOMIC_FENCE, MVT::Other, Custom); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 682 | // Custom lowering for 64-bit ops |
| 683 | setOperationAction(ISD::ATOMIC_LOAD_ADD, MVT::i64, Custom); |
| 684 | setOperationAction(ISD::ATOMIC_LOAD_SUB, MVT::i64, Custom); |
| 685 | setOperationAction(ISD::ATOMIC_LOAD_AND, MVT::i64, Custom); |
| 686 | setOperationAction(ISD::ATOMIC_LOAD_OR, MVT::i64, Custom); |
| 687 | setOperationAction(ISD::ATOMIC_LOAD_XOR, MVT::i64, Custom); |
| 688 | setOperationAction(ISD::ATOMIC_SWAP, MVT::i64, Custom); |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 689 | setOperationAction(ISD::ATOMIC_CMP_SWAP, MVT::i64, Custom); |
Eli Friedman | 26689ac | 2011-08-03 21:06:02 +0000 | [diff] [blame] | 690 | // Automatically insert fences (dmb ist) around ATOMIC_SWAP etc. |
| 691 | setInsertFencesForAtomic(true); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 692 | } else { |
| 693 | // Set them all for expansion, which will force libcalls. |
| 694 | setOperationAction(ISD::MEMBARRIER, MVT::Other, Expand); |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 695 | setOperationAction(ISD::ATOMIC_FENCE, MVT::Other, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 696 | setOperationAction(ISD::ATOMIC_CMP_SWAP, MVT::i32, Expand); |
Jim Grosbach | ef6eb9c | 2010-06-18 23:03:10 +0000 | [diff] [blame] | 697 | setOperationAction(ISD::ATOMIC_SWAP, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 698 | setOperationAction(ISD::ATOMIC_LOAD_ADD, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 699 | setOperationAction(ISD::ATOMIC_LOAD_SUB, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 700 | setOperationAction(ISD::ATOMIC_LOAD_AND, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 701 | setOperationAction(ISD::ATOMIC_LOAD_OR, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 702 | setOperationAction(ISD::ATOMIC_LOAD_XOR, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 703 | setOperationAction(ISD::ATOMIC_LOAD_NAND, MVT::i32, Expand); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 704 | setOperationAction(ISD::ATOMIC_LOAD_MIN, MVT::i32, Expand); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 705 | setOperationAction(ISD::ATOMIC_LOAD_MAX, MVT::i32, Expand); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 706 | setOperationAction(ISD::ATOMIC_LOAD_UMIN, MVT::i32, Expand); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 707 | setOperationAction(ISD::ATOMIC_LOAD_UMAX, MVT::i32, Expand); |
Eli Friedman | 7cc1566 | 2011-09-15 22:18:49 +0000 | [diff] [blame] | 708 | // Mark ATOMIC_LOAD and ATOMIC_STORE custom so we can handle the |
| 709 | // Unordered/Monotonic case. |
| 710 | setOperationAction(ISD::ATOMIC_LOAD, MVT::i32, Custom); |
| 711 | setOperationAction(ISD::ATOMIC_STORE, MVT::i32, Custom); |
Jim Grosbach | 5def57a | 2010-06-23 16:08:49 +0000 | [diff] [blame] | 712 | // Since the libcalls include locking, fold in the fences |
| 713 | setShouldFoldAtomicFences(true); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 714 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 715 | |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 716 | setOperationAction(ISD::PREFETCH, MVT::Other, Custom); |
Evan Cheng | bc7deb0 | 2010-11-03 05:14:24 +0000 | [diff] [blame] | 717 | |
Eli Friedman | a2c6f45 | 2010-06-26 04:36:50 +0000 | [diff] [blame] | 718 | // Requires SXTB/SXTH, available on v6 and up in both ARM and Thumb modes. |
| 719 | if (!Subtarget->hasV6Ops()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 720 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i16, Expand); |
| 721 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i8, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 722 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 723 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 724 | |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 725 | if (!TM.Options.UseSoftFloat && Subtarget->hasVFP2() && |
| 726 | !Subtarget->isThumb1Only()) { |
Bob Wilson | cb9a6aa | 2010-01-19 22:56:26 +0000 | [diff] [blame] | 727 | // Turn f64->i64 into VMOVRRD, i64 -> f64 to VMOVDRR |
| 728 | // iff target supports vfp2. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 729 | setOperationAction(ISD::BITCAST, MVT::i64, Custom); |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 730 | setOperationAction(ISD::FLT_ROUNDS_, MVT::i32, Custom); |
| 731 | } |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 732 | |
| 733 | // We want to custom lower some of our intrinsics. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 734 | setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom); |
Jim Grosbach | e97f968 | 2010-07-07 00:07:57 +0000 | [diff] [blame] | 735 | if (Subtarget->isTargetDarwin()) { |
| 736 | setOperationAction(ISD::EH_SJLJ_SETJMP, MVT::i32, Custom); |
| 737 | setOperationAction(ISD::EH_SJLJ_LONGJMP, MVT::Other, Custom); |
John McCall | 5f8fd54 | 2011-05-29 19:50:32 +0000 | [diff] [blame] | 738 | setLibcallName(RTLIB::UNWIND_RESUME, "_Unwind_SjLj_Resume"); |
Jim Grosbach | e97f968 | 2010-07-07 00:07:57 +0000 | [diff] [blame] | 739 | } |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 740 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 741 | setOperationAction(ISD::SETCC, MVT::i32, Expand); |
| 742 | setOperationAction(ISD::SETCC, MVT::f32, Expand); |
| 743 | setOperationAction(ISD::SETCC, MVT::f64, Expand); |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 744 | setOperationAction(ISD::SELECT, MVT::i32, Custom); |
| 745 | setOperationAction(ISD::SELECT, MVT::f32, Custom); |
| 746 | setOperationAction(ISD::SELECT, MVT::f64, Custom); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 747 | setOperationAction(ISD::SELECT_CC, MVT::i32, Custom); |
| 748 | setOperationAction(ISD::SELECT_CC, MVT::f32, Custom); |
| 749 | setOperationAction(ISD::SELECT_CC, MVT::f64, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 750 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 751 | setOperationAction(ISD::BRCOND, MVT::Other, Expand); |
| 752 | setOperationAction(ISD::BR_CC, MVT::i32, Custom); |
| 753 | setOperationAction(ISD::BR_CC, MVT::f32, Custom); |
| 754 | setOperationAction(ISD::BR_CC, MVT::f64, Custom); |
| 755 | setOperationAction(ISD::BR_JT, MVT::Other, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 756 | |
Dan Gohman | f96e4de | 2007-10-11 23:21:31 +0000 | [diff] [blame] | 757 | // We don't support sin/cos/fmod/copysign/pow |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 758 | setOperationAction(ISD::FSIN, MVT::f64, Expand); |
| 759 | setOperationAction(ISD::FSIN, MVT::f32, Expand); |
| 760 | setOperationAction(ISD::FCOS, MVT::f32, Expand); |
| 761 | setOperationAction(ISD::FCOS, MVT::f64, Expand); |
| 762 | setOperationAction(ISD::FREM, MVT::f64, Expand); |
| 763 | setOperationAction(ISD::FREM, MVT::f32, Expand); |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 764 | if (!TM.Options.UseSoftFloat && Subtarget->hasVFP2() && |
| 765 | !Subtarget->isThumb1Only()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 766 | setOperationAction(ISD::FCOPYSIGN, MVT::f64, Custom); |
| 767 | setOperationAction(ISD::FCOPYSIGN, MVT::f32, Custom); |
Evan Cheng | 110cf48 | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 768 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 769 | setOperationAction(ISD::FPOW, MVT::f64, Expand); |
| 770 | setOperationAction(ISD::FPOW, MVT::f32, Expand); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 771 | |
Evan Cheng | 3aef2ff | 2012-04-10 21:40:28 +0000 | [diff] [blame] | 772 | if (!Subtarget->hasVFP4()) { |
| 773 | setOperationAction(ISD::FMA, MVT::f64, Expand); |
| 774 | setOperationAction(ISD::FMA, MVT::f32, Expand); |
| 775 | } |
Cameron Zwarich | 3339084 | 2011-07-08 21:39:21 +0000 | [diff] [blame] | 776 | |
Anton Korobeynikov | bec3dd2 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 777 | // Various VFP goodness |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 778 | if (!TM.Options.UseSoftFloat && !Subtarget->isThumb1Only()) { |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 779 | // int <-> fp are custom expanded into bit_convert + ARMISD ops. |
| 780 | if (Subtarget->hasVFP2()) { |
| 781 | setOperationAction(ISD::SINT_TO_FP, MVT::i32, Custom); |
| 782 | setOperationAction(ISD::UINT_TO_FP, MVT::i32, Custom); |
| 783 | setOperationAction(ISD::FP_TO_UINT, MVT::i32, Custom); |
| 784 | setOperationAction(ISD::FP_TO_SINT, MVT::i32, Custom); |
| 785 | } |
Anton Korobeynikov | bec3dd2 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 786 | // Special handling for half-precision FP. |
Anton Korobeynikov | f0d5007 | 2010-03-18 22:35:37 +0000 | [diff] [blame] | 787 | if (!Subtarget->hasFP16()) { |
| 788 | setOperationAction(ISD::FP16_TO_FP32, MVT::f32, Expand); |
| 789 | setOperationAction(ISD::FP32_TO_FP16, MVT::i32, Expand); |
Anton Korobeynikov | bec3dd2 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 790 | } |
Evan Cheng | 110cf48 | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 791 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 792 | |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 793 | // We have target-specific dag combine patterns for the following nodes: |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 794 | // ARMISD::VMOVRRD - No need to call setTargetDAGCombine |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 795 | setTargetDAGCombine(ISD::ADD); |
| 796 | setTargetDAGCombine(ISD::SUB); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 797 | setTargetDAGCombine(ISD::MUL); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 798 | |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 799 | if (Subtarget->hasV6T2Ops() || Subtarget->hasNEON()) { |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 800 | setTargetDAGCombine(ISD::AND); |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 801 | setTargetDAGCombine(ISD::OR); |
| 802 | setTargetDAGCombine(ISD::XOR); |
| 803 | } |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 804 | |
Evan Cheng | 5fb468a | 2012-02-23 02:58:19 +0000 | [diff] [blame] | 805 | if (Subtarget->hasV6Ops()) |
| 806 | setTargetDAGCombine(ISD::SRL); |
| 807 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 808 | setStackPointerRegisterToSaveRestore(ARM::SP); |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 809 | |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 810 | if (TM.Options.UseSoftFloat || Subtarget->isThumb1Only() || |
| 811 | !Subtarget->hasVFP2()) |
Evan Cheng | f7d87ee | 2010-05-21 00:43:17 +0000 | [diff] [blame] | 812 | setSchedulingPreference(Sched::RegPressure); |
| 813 | else |
| 814 | setSchedulingPreference(Sched::Hybrid); |
Dale Johannesen | 8dd86c1 | 2007-05-17 21:31:21 +0000 | [diff] [blame] | 815 | |
Evan Cheng | 0521928 | 2011-01-06 06:52:41 +0000 | [diff] [blame] | 816 | //// temporary - rewrite interface to use type |
| 817 | maxStoresPerMemcpy = maxStoresPerMemcpyOptSize = 1; |
Lang Hames | 75757f9 | 2011-10-26 20:56:52 +0000 | [diff] [blame] | 818 | maxStoresPerMemset = 16; |
| 819 | maxStoresPerMemsetOptSize = Subtarget->isTargetDarwin() ? 8 : 4; |
Evan Cheng | f679939 | 2010-06-26 01:52:05 +0000 | [diff] [blame] | 820 | |
Rafael Espindola | cbeeae2 | 2010-07-11 04:01:49 +0000 | [diff] [blame] | 821 | // On ARM arguments smaller than 4 bytes are extended, so all arguments |
| 822 | // are at least 4 bytes aligned. |
| 823 | setMinStackArgumentAlignment(4); |
| 824 | |
Evan Cheng | fff606d | 2010-09-24 19:07:23 +0000 | [diff] [blame] | 825 | benefitFromCodePlacementOpt = true; |
Eli Friedman | fc5d305 | 2011-05-06 20:34:06 +0000 | [diff] [blame] | 826 | |
| 827 | setMinFunctionAlignment(Subtarget->isThumb() ? 1 : 2); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 828 | } |
| 829 | |
Andrew Trick | 32cec0a | 2011-01-19 02:35:27 +0000 | [diff] [blame] | 830 | // FIXME: It might make sense to define the representative register class as the |
| 831 | // nearest super-register that has a non-null superset. For example, DPR_VFP2 is |
| 832 | // a super-register of SPR, and DPR is a superset if DPR_VFP2. Consequently, |
| 833 | // SPR's representative would be DPR_VFP2. This should work well if register |
| 834 | // pressure tracking were modified such that a register use would increment the |
| 835 | // pressure of the register class's representative and all of it's super |
| 836 | // classes' representatives transitively. We have not implemented this because |
| 837 | // of the difficulty prior to coalescing of modeling operand register classes |
Chris Lattner | 7a2bdde | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 838 | // due to the common occurrence of cross class copies and subregister insertions |
Andrew Trick | 32cec0a | 2011-01-19 02:35:27 +0000 | [diff] [blame] | 839 | // and extractions. |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 840 | std::pair<const TargetRegisterClass*, uint8_t> |
| 841 | ARMTargetLowering::findRepresentativeClass(EVT VT) const{ |
| 842 | const TargetRegisterClass *RRC = 0; |
| 843 | uint8_t Cost = 1; |
| 844 | switch (VT.getSimpleVT().SimpleTy) { |
Evan Cheng | d70f57b | 2010-07-19 22:15:08 +0000 | [diff] [blame] | 845 | default: |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 846 | return TargetLowering::findRepresentativeClass(VT); |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 847 | // Use DPR as representative register class for all floating point |
| 848 | // and vector types. Since there are 32 SPR registers and 32 DPR registers so |
| 849 | // the cost is 1 for both f32 and f64. |
| 850 | case MVT::f32: case MVT::f64: case MVT::v8i8: case MVT::v4i16: |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 851 | case MVT::v2i32: case MVT::v1i64: case MVT::v2f32: |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 852 | RRC = &ARM::DPRRegClass; |
Andrew Trick | 32cec0a | 2011-01-19 02:35:27 +0000 | [diff] [blame] | 853 | // When NEON is used for SP, only half of the register file is available |
| 854 | // because operations that define both SP and DP results will be constrained |
| 855 | // to the VFP2 class (D0-D15). We currently model this constraint prior to |
| 856 | // coalescing by double-counting the SP regs. See the FIXME above. |
| 857 | if (Subtarget->useNEONForSinglePrecisionFP()) |
| 858 | Cost = 2; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 859 | break; |
| 860 | case MVT::v16i8: case MVT::v8i16: case MVT::v4i32: case MVT::v2i64: |
| 861 | case MVT::v4f32: case MVT::v2f64: |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 862 | RRC = &ARM::DPRRegClass; |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 863 | Cost = 2; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 864 | break; |
| 865 | case MVT::v4i64: |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 866 | RRC = &ARM::DPRRegClass; |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 867 | Cost = 4; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 868 | break; |
| 869 | case MVT::v8i64: |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 870 | RRC = &ARM::DPRRegClass; |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 871 | Cost = 8; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 872 | break; |
Evan Cheng | d70f57b | 2010-07-19 22:15:08 +0000 | [diff] [blame] | 873 | } |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 874 | return std::make_pair(RRC, Cost); |
Evan Cheng | d70f57b | 2010-07-19 22:15:08 +0000 | [diff] [blame] | 875 | } |
| 876 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 877 | const char *ARMTargetLowering::getTargetNodeName(unsigned Opcode) const { |
| 878 | switch (Opcode) { |
| 879 | default: return 0; |
| 880 | case ARMISD::Wrapper: return "ARMISD::Wrapper"; |
Evan Cheng | 53519f0 | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 881 | case ARMISD::WrapperDYN: return "ARMISD::WrapperDYN"; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 882 | case ARMISD::WrapperPIC: return "ARMISD::WrapperPIC"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 883 | case ARMISD::WrapperJT: return "ARMISD::WrapperJT"; |
| 884 | case ARMISD::CALL: return "ARMISD::CALL"; |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 885 | case ARMISD::CALL_PRED: return "ARMISD::CALL_PRED"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 886 | case ARMISD::CALL_NOLINK: return "ARMISD::CALL_NOLINK"; |
| 887 | case ARMISD::tCALL: return "ARMISD::tCALL"; |
| 888 | case ARMISD::BRCOND: return "ARMISD::BRCOND"; |
| 889 | case ARMISD::BR_JT: return "ARMISD::BR_JT"; |
Evan Cheng | 5657c01 | 2009-07-29 02:18:14 +0000 | [diff] [blame] | 890 | case ARMISD::BR2_JT: return "ARMISD::BR2_JT"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 891 | case ARMISD::RET_FLAG: return "ARMISD::RET_FLAG"; |
| 892 | case ARMISD::PIC_ADD: return "ARMISD::PIC_ADD"; |
| 893 | case ARMISD::CMP: return "ARMISD::CMP"; |
David Goodwin | c0309b4 | 2009-06-29 15:33:01 +0000 | [diff] [blame] | 894 | case ARMISD::CMPZ: return "ARMISD::CMPZ"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 895 | case ARMISD::CMPFP: return "ARMISD::CMPFP"; |
| 896 | case ARMISD::CMPFPw0: return "ARMISD::CMPFPw0"; |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 897 | case ARMISD::BCC_i64: return "ARMISD::BCC_i64"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 898 | case ARMISD::FMSTAT: return "ARMISD::FMSTAT"; |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 899 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 900 | case ARMISD::CMOV: return "ARMISD::CMOV"; |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 901 | case ARMISD::CAND: return "ARMISD::CAND"; |
| 902 | case ARMISD::COR: return "ARMISD::COR"; |
| 903 | case ARMISD::CXOR: return "ARMISD::CXOR"; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 904 | |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 905 | case ARMISD::RBIT: return "ARMISD::RBIT"; |
| 906 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 907 | case ARMISD::FTOSI: return "ARMISD::FTOSI"; |
| 908 | case ARMISD::FTOUI: return "ARMISD::FTOUI"; |
| 909 | case ARMISD::SITOF: return "ARMISD::SITOF"; |
| 910 | case ARMISD::UITOF: return "ARMISD::UITOF"; |
| 911 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 912 | case ARMISD::SRL_FLAG: return "ARMISD::SRL_FLAG"; |
| 913 | case ARMISD::SRA_FLAG: return "ARMISD::SRA_FLAG"; |
| 914 | case ARMISD::RRX: return "ARMISD::RRX"; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 915 | |
Evan Cheng | 342e316 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 916 | case ARMISD::ADDC: return "ARMISD::ADDC"; |
| 917 | case ARMISD::ADDE: return "ARMISD::ADDE"; |
| 918 | case ARMISD::SUBC: return "ARMISD::SUBC"; |
| 919 | case ARMISD::SUBE: return "ARMISD::SUBE"; |
| 920 | |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 921 | case ARMISD::VMOVRRD: return "ARMISD::VMOVRRD"; |
| 922 | case ARMISD::VMOVDRR: return "ARMISD::VMOVDRR"; |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 923 | |
Evan Cheng | c594208 | 2009-10-28 06:55:03 +0000 | [diff] [blame] | 924 | case ARMISD::EH_SJLJ_SETJMP: return "ARMISD::EH_SJLJ_SETJMP"; |
| 925 | case ARMISD::EH_SJLJ_LONGJMP:return "ARMISD::EH_SJLJ_LONGJMP"; |
| 926 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 927 | case ARMISD::TC_RETURN: return "ARMISD::TC_RETURN"; |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 928 | |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 929 | case ARMISD::THREAD_POINTER:return "ARMISD::THREAD_POINTER"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 930 | |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 931 | case ARMISD::DYN_ALLOC: return "ARMISD::DYN_ALLOC"; |
| 932 | |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 933 | case ARMISD::MEMBARRIER: return "ARMISD::MEMBARRIER"; |
Bob Wilson | f74a429 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 934 | case ARMISD::MEMBARRIER_MCR: return "ARMISD::MEMBARRIER_MCR"; |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 935 | |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 936 | case ARMISD::PRELOAD: return "ARMISD::PRELOAD"; |
| 937 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 938 | case ARMISD::VCEQ: return "ARMISD::VCEQ"; |
Bob Wilson | 3a75b9b | 2010-12-18 00:04:26 +0000 | [diff] [blame] | 939 | case ARMISD::VCEQZ: return "ARMISD::VCEQZ"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 940 | case ARMISD::VCGE: return "ARMISD::VCGE"; |
Bob Wilson | 3a75b9b | 2010-12-18 00:04:26 +0000 | [diff] [blame] | 941 | case ARMISD::VCGEZ: return "ARMISD::VCGEZ"; |
| 942 | case ARMISD::VCLEZ: return "ARMISD::VCLEZ"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 943 | case ARMISD::VCGEU: return "ARMISD::VCGEU"; |
| 944 | case ARMISD::VCGT: return "ARMISD::VCGT"; |
Bob Wilson | 3a75b9b | 2010-12-18 00:04:26 +0000 | [diff] [blame] | 945 | case ARMISD::VCGTZ: return "ARMISD::VCGTZ"; |
| 946 | case ARMISD::VCLTZ: return "ARMISD::VCLTZ"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 947 | case ARMISD::VCGTU: return "ARMISD::VCGTU"; |
| 948 | case ARMISD::VTST: return "ARMISD::VTST"; |
| 949 | |
| 950 | case ARMISD::VSHL: return "ARMISD::VSHL"; |
| 951 | case ARMISD::VSHRs: return "ARMISD::VSHRs"; |
| 952 | case ARMISD::VSHRu: return "ARMISD::VSHRu"; |
| 953 | case ARMISD::VSHLLs: return "ARMISD::VSHLLs"; |
| 954 | case ARMISD::VSHLLu: return "ARMISD::VSHLLu"; |
| 955 | case ARMISD::VSHLLi: return "ARMISD::VSHLLi"; |
| 956 | case ARMISD::VSHRN: return "ARMISD::VSHRN"; |
| 957 | case ARMISD::VRSHRs: return "ARMISD::VRSHRs"; |
| 958 | case ARMISD::VRSHRu: return "ARMISD::VRSHRu"; |
| 959 | case ARMISD::VRSHRN: return "ARMISD::VRSHRN"; |
| 960 | case ARMISD::VQSHLs: return "ARMISD::VQSHLs"; |
| 961 | case ARMISD::VQSHLu: return "ARMISD::VQSHLu"; |
| 962 | case ARMISD::VQSHLsu: return "ARMISD::VQSHLsu"; |
| 963 | case ARMISD::VQSHRNs: return "ARMISD::VQSHRNs"; |
| 964 | case ARMISD::VQSHRNu: return "ARMISD::VQSHRNu"; |
| 965 | case ARMISD::VQSHRNsu: return "ARMISD::VQSHRNsu"; |
| 966 | case ARMISD::VQRSHRNs: return "ARMISD::VQRSHRNs"; |
| 967 | case ARMISD::VQRSHRNu: return "ARMISD::VQRSHRNu"; |
| 968 | case ARMISD::VQRSHRNsu: return "ARMISD::VQRSHRNsu"; |
| 969 | case ARMISD::VGETLANEu: return "ARMISD::VGETLANEu"; |
| 970 | case ARMISD::VGETLANEs: return "ARMISD::VGETLANEs"; |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 971 | case ARMISD::VMOVIMM: return "ARMISD::VMOVIMM"; |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 972 | case ARMISD::VMVNIMM: return "ARMISD::VMVNIMM"; |
Evan Cheng | eaa192a | 2011-11-15 02:12:34 +0000 | [diff] [blame] | 973 | case ARMISD::VMOVFPIMM: return "ARMISD::VMOVFPIMM"; |
Bob Wilson | c1d287b | 2009-08-14 05:13:08 +0000 | [diff] [blame] | 974 | case ARMISD::VDUP: return "ARMISD::VDUP"; |
Bob Wilson | 0ce3710 | 2009-08-14 05:08:32 +0000 | [diff] [blame] | 975 | case ARMISD::VDUPLANE: return "ARMISD::VDUPLANE"; |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 976 | case ARMISD::VEXT: return "ARMISD::VEXT"; |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 977 | case ARMISD::VREV64: return "ARMISD::VREV64"; |
| 978 | case ARMISD::VREV32: return "ARMISD::VREV32"; |
| 979 | case ARMISD::VREV16: return "ARMISD::VREV16"; |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 980 | case ARMISD::VZIP: return "ARMISD::VZIP"; |
| 981 | case ARMISD::VUZP: return "ARMISD::VUZP"; |
| 982 | case ARMISD::VTRN: return "ARMISD::VTRN"; |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 983 | case ARMISD::VTBL1: return "ARMISD::VTBL1"; |
| 984 | case ARMISD::VTBL2: return "ARMISD::VTBL2"; |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 985 | case ARMISD::VMULLs: return "ARMISD::VMULLs"; |
| 986 | case ARMISD::VMULLu: return "ARMISD::VMULLu"; |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 987 | case ARMISD::BUILD_VECTOR: return "ARMISD::BUILD_VECTOR"; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 988 | case ARMISD::FMAX: return "ARMISD::FMAX"; |
| 989 | case ARMISD::FMIN: return "ARMISD::FMIN"; |
Jim Grosbach | dd7d28a | 2010-07-17 01:50:57 +0000 | [diff] [blame] | 990 | case ARMISD::BFI: return "ARMISD::BFI"; |
Bob Wilson | 364a72a | 2010-11-28 06:51:11 +0000 | [diff] [blame] | 991 | case ARMISD::VORRIMM: return "ARMISD::VORRIMM"; |
| 992 | case ARMISD::VBICIMM: return "ARMISD::VBICIMM"; |
Cameron Zwarich | c0e6d78 | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 993 | case ARMISD::VBSL: return "ARMISD::VBSL"; |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 994 | case ARMISD::VLD2DUP: return "ARMISD::VLD2DUP"; |
| 995 | case ARMISD::VLD3DUP: return "ARMISD::VLD3DUP"; |
| 996 | case ARMISD::VLD4DUP: return "ARMISD::VLD4DUP"; |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 997 | case ARMISD::VLD1_UPD: return "ARMISD::VLD1_UPD"; |
| 998 | case ARMISD::VLD2_UPD: return "ARMISD::VLD2_UPD"; |
| 999 | case ARMISD::VLD3_UPD: return "ARMISD::VLD3_UPD"; |
| 1000 | case ARMISD::VLD4_UPD: return "ARMISD::VLD4_UPD"; |
| 1001 | case ARMISD::VLD2LN_UPD: return "ARMISD::VLD2LN_UPD"; |
| 1002 | case ARMISD::VLD3LN_UPD: return "ARMISD::VLD3LN_UPD"; |
| 1003 | case ARMISD::VLD4LN_UPD: return "ARMISD::VLD4LN_UPD"; |
| 1004 | case ARMISD::VLD2DUP_UPD: return "ARMISD::VLD2DUP_UPD"; |
| 1005 | case ARMISD::VLD3DUP_UPD: return "ARMISD::VLD3DUP_UPD"; |
| 1006 | case ARMISD::VLD4DUP_UPD: return "ARMISD::VLD4DUP_UPD"; |
| 1007 | case ARMISD::VST1_UPD: return "ARMISD::VST1_UPD"; |
| 1008 | case ARMISD::VST2_UPD: return "ARMISD::VST2_UPD"; |
| 1009 | case ARMISD::VST3_UPD: return "ARMISD::VST3_UPD"; |
| 1010 | case ARMISD::VST4_UPD: return "ARMISD::VST4_UPD"; |
| 1011 | case ARMISD::VST2LN_UPD: return "ARMISD::VST2LN_UPD"; |
| 1012 | case ARMISD::VST3LN_UPD: return "ARMISD::VST3LN_UPD"; |
| 1013 | case ARMISD::VST4LN_UPD: return "ARMISD::VST4LN_UPD"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1014 | } |
| 1015 | } |
| 1016 | |
Duncan Sands | 28b77e9 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 1017 | EVT ARMTargetLowering::getSetCCResultType(EVT VT) const { |
| 1018 | if (!VT.isVector()) return getPointerTy(); |
| 1019 | return VT.changeVectorElementTypeToInteger(); |
| 1020 | } |
| 1021 | |
Evan Cheng | 06b666c | 2010-05-15 02:18:07 +0000 | [diff] [blame] | 1022 | /// getRegClassFor - Return the register class that should be used for the |
| 1023 | /// specified value type. |
Craig Topper | 44d2382 | 2012-02-22 05:59:10 +0000 | [diff] [blame] | 1024 | const TargetRegisterClass *ARMTargetLowering::getRegClassFor(EVT VT) const { |
Evan Cheng | 06b666c | 2010-05-15 02:18:07 +0000 | [diff] [blame] | 1025 | // Map v4i64 to QQ registers but do not make the type legal. Similarly map |
| 1026 | // v8i64 to QQQQ registers. v4i64 and v8i64 are only used for REG_SEQUENCE to |
| 1027 | // load / store 4 to 8 consecutive D registers. |
Evan Cheng | 4782b1e | 2010-05-15 02:20:21 +0000 | [diff] [blame] | 1028 | if (Subtarget->hasNEON()) { |
| 1029 | if (VT == MVT::v4i64) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 1030 | return &ARM::QQPRRegClass; |
| 1031 | if (VT == MVT::v8i64) |
| 1032 | return &ARM::QQQQPRRegClass; |
Evan Cheng | 4782b1e | 2010-05-15 02:20:21 +0000 | [diff] [blame] | 1033 | } |
Evan Cheng | 06b666c | 2010-05-15 02:18:07 +0000 | [diff] [blame] | 1034 | return TargetLowering::getRegClassFor(VT); |
| 1035 | } |
| 1036 | |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 1037 | // Create a fast isel object. |
| 1038 | FastISel * |
| 1039 | ARMTargetLowering::createFastISel(FunctionLoweringInfo &funcInfo) const { |
| 1040 | return ARM::createFastISel(funcInfo); |
| 1041 | } |
| 1042 | |
Anton Korobeynikov | cec36f4 | 2010-07-24 21:52:08 +0000 | [diff] [blame] | 1043 | /// getMaximalGlobalOffset - Returns the maximal possible offset which can |
| 1044 | /// be used for loads / stores from the global. |
| 1045 | unsigned ARMTargetLowering::getMaximalGlobalOffset() const { |
| 1046 | return (Subtarget->isThumb1Only() ? 127 : 4095); |
| 1047 | } |
| 1048 | |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1049 | Sched::Preference ARMTargetLowering::getSchedulingPreference(SDNode *N) const { |
Evan Cheng | c10f543 | 2010-05-28 23:25:23 +0000 | [diff] [blame] | 1050 | unsigned NumVals = N->getNumValues(); |
| 1051 | if (!NumVals) |
| 1052 | return Sched::RegPressure; |
| 1053 | |
| 1054 | for (unsigned i = 0; i != NumVals; ++i) { |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1055 | EVT VT = N->getValueType(i); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 1056 | if (VT == MVT::Glue || VT == MVT::Other) |
Evan Cheng | d7e473c | 2010-10-29 18:07:31 +0000 | [diff] [blame] | 1057 | continue; |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1058 | if (VT.isFloatingPoint() || VT.isVector()) |
Dan Gohman | 692c1d8 | 2011-10-24 17:55:11 +0000 | [diff] [blame] | 1059 | return Sched::ILP; |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1060 | } |
Evan Cheng | c10f543 | 2010-05-28 23:25:23 +0000 | [diff] [blame] | 1061 | |
| 1062 | if (!N->isMachineOpcode()) |
| 1063 | return Sched::RegPressure; |
| 1064 | |
| 1065 | // Load are scheduled for latency even if there instruction itinerary |
| 1066 | // is not available. |
| 1067 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 1068 | const MCInstrDesc &MCID = TII->get(N->getMachineOpcode()); |
Evan Cheng | d7e473c | 2010-10-29 18:07:31 +0000 | [diff] [blame] | 1069 | |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 1070 | if (MCID.getNumDefs() == 0) |
Evan Cheng | d7e473c | 2010-10-29 18:07:31 +0000 | [diff] [blame] | 1071 | return Sched::RegPressure; |
| 1072 | if (!Itins->isEmpty() && |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 1073 | Itins->getOperandCycle(MCID.getSchedClass(), 0) > 2) |
Dan Gohman | 692c1d8 | 2011-10-24 17:55:11 +0000 | [diff] [blame] | 1074 | return Sched::ILP; |
Evan Cheng | c10f543 | 2010-05-28 23:25:23 +0000 | [diff] [blame] | 1075 | |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1076 | return Sched::RegPressure; |
| 1077 | } |
| 1078 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1079 | //===----------------------------------------------------------------------===// |
| 1080 | // Lowering Code |
| 1081 | //===----------------------------------------------------------------------===// |
| 1082 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1083 | /// IntCCToARMCC - Convert a DAG integer condition code to an ARM CC |
| 1084 | static ARMCC::CondCodes IntCCToARMCC(ISD::CondCode CC) { |
| 1085 | switch (CC) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1086 | default: llvm_unreachable("Unknown condition code!"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1087 | case ISD::SETNE: return ARMCC::NE; |
| 1088 | case ISD::SETEQ: return ARMCC::EQ; |
| 1089 | case ISD::SETGT: return ARMCC::GT; |
| 1090 | case ISD::SETGE: return ARMCC::GE; |
| 1091 | case ISD::SETLT: return ARMCC::LT; |
| 1092 | case ISD::SETLE: return ARMCC::LE; |
| 1093 | case ISD::SETUGT: return ARMCC::HI; |
| 1094 | case ISD::SETUGE: return ARMCC::HS; |
| 1095 | case ISD::SETULT: return ARMCC::LO; |
| 1096 | case ISD::SETULE: return ARMCC::LS; |
| 1097 | } |
| 1098 | } |
| 1099 | |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 1100 | /// FPCCToARMCC - Convert a DAG fp condition code to an ARM CC. |
| 1101 | static void FPCCToARMCC(ISD::CondCode CC, ARMCC::CondCodes &CondCode, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1102 | ARMCC::CondCodes &CondCode2) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1103 | CondCode2 = ARMCC::AL; |
| 1104 | switch (CC) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1105 | default: llvm_unreachable("Unknown FP condition!"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1106 | case ISD::SETEQ: |
| 1107 | case ISD::SETOEQ: CondCode = ARMCC::EQ; break; |
| 1108 | case ISD::SETGT: |
| 1109 | case ISD::SETOGT: CondCode = ARMCC::GT; break; |
| 1110 | case ISD::SETGE: |
| 1111 | case ISD::SETOGE: CondCode = ARMCC::GE; break; |
| 1112 | case ISD::SETOLT: CondCode = ARMCC::MI; break; |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 1113 | case ISD::SETOLE: CondCode = ARMCC::LS; break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1114 | case ISD::SETONE: CondCode = ARMCC::MI; CondCode2 = ARMCC::GT; break; |
| 1115 | case ISD::SETO: CondCode = ARMCC::VC; break; |
| 1116 | case ISD::SETUO: CondCode = ARMCC::VS; break; |
| 1117 | case ISD::SETUEQ: CondCode = ARMCC::EQ; CondCode2 = ARMCC::VS; break; |
| 1118 | case ISD::SETUGT: CondCode = ARMCC::HI; break; |
| 1119 | case ISD::SETUGE: CondCode = ARMCC::PL; break; |
| 1120 | case ISD::SETLT: |
| 1121 | case ISD::SETULT: CondCode = ARMCC::LT; break; |
| 1122 | case ISD::SETLE: |
| 1123 | case ISD::SETULE: CondCode = ARMCC::LE; break; |
| 1124 | case ISD::SETNE: |
| 1125 | case ISD::SETUNE: CondCode = ARMCC::NE; break; |
| 1126 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1127 | } |
| 1128 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1129 | //===----------------------------------------------------------------------===// |
| 1130 | // Calling Convention Implementation |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1131 | //===----------------------------------------------------------------------===// |
| 1132 | |
| 1133 | #include "ARMGenCallingConv.inc" |
| 1134 | |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1135 | /// CCAssignFnForNode - Selects the correct CCAssignFn for a the |
| 1136 | /// given CallingConvention value. |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1137 | CCAssignFn *ARMTargetLowering::CCAssignFnForNode(CallingConv::ID CC, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1138 | bool Return, |
| 1139 | bool isVarArg) const { |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1140 | switch (CC) { |
| 1141 | default: |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1142 | llvm_unreachable("Unsupported calling convention"); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1143 | case CallingConv::Fast: |
Evan Cheng | 5c2d428 | 2010-10-23 02:19:37 +0000 | [diff] [blame] | 1144 | if (Subtarget->hasVFP2() && !isVarArg) { |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1145 | if (!Subtarget->isAAPCS_ABI()) |
| 1146 | return (Return ? RetFastCC_ARM_APCS : FastCC_ARM_APCS); |
| 1147 | // For AAPCS ABI targets, just use VFP variant of the calling convention. |
| 1148 | return (Return ? RetCC_ARM_AAPCS_VFP : CC_ARM_AAPCS_VFP); |
| 1149 | } |
| 1150 | // Fallthrough |
| 1151 | case CallingConv::C: { |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1152 | // Use target triple & subtarget features to do actual dispatch. |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1153 | if (!Subtarget->isAAPCS_ABI()) |
| 1154 | return (Return ? RetCC_ARM_APCS : CC_ARM_APCS); |
| 1155 | else if (Subtarget->hasVFP2() && |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 1156 | getTargetMachine().Options.FloatABIType == FloatABI::Hard && |
| 1157 | !isVarArg) |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1158 | return (Return ? RetCC_ARM_AAPCS_VFP : CC_ARM_AAPCS_VFP); |
| 1159 | return (Return ? RetCC_ARM_AAPCS : CC_ARM_AAPCS); |
| 1160 | } |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1161 | case CallingConv::ARM_AAPCS_VFP: |
Anton Korobeynikov | f349cb8 | 2012-01-29 09:06:09 +0000 | [diff] [blame] | 1162 | if (!isVarArg) |
| 1163 | return (Return ? RetCC_ARM_AAPCS_VFP : CC_ARM_AAPCS_VFP); |
| 1164 | // Fallthrough |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1165 | case CallingConv::ARM_AAPCS: |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1166 | return (Return ? RetCC_ARM_AAPCS : CC_ARM_AAPCS); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1167 | case CallingConv::ARM_APCS: |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1168 | return (Return ? RetCC_ARM_APCS : CC_ARM_APCS); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1169 | } |
| 1170 | } |
| 1171 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1172 | /// LowerCallResult - Lower the result values of a call into the |
| 1173 | /// appropriate copies out of appropriate physical registers. |
| 1174 | SDValue |
| 1175 | ARMTargetLowering::LowerCallResult(SDValue Chain, SDValue InFlag, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1176 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1177 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 1178 | DebugLoc dl, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1179 | SmallVectorImpl<SDValue> &InVals) const { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1180 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1181 | // Assign locations to each value returned by this call. |
| 1182 | SmallVector<CCValAssign, 16> RVLocs; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1183 | ARMCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), |
| 1184 | getTargetMachine(), RVLocs, *DAG.getContext(), Call); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1185 | CCInfo.AnalyzeCallResult(Ins, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1186 | CCAssignFnForNode(CallConv, /* Return*/ true, |
| 1187 | isVarArg)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1188 | |
| 1189 | // Copy all of the result registers out of their specified physreg. |
| 1190 | for (unsigned i = 0; i != RVLocs.size(); ++i) { |
| 1191 | CCValAssign VA = RVLocs[i]; |
| 1192 | |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1193 | SDValue Val; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1194 | if (VA.needsCustom()) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1195 | // Handle f64 or half of a v2f64. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1196 | SDValue Lo = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1197 | InFlag); |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1198 | Chain = Lo.getValue(1); |
| 1199 | InFlag = Lo.getValue(2); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1200 | VA = RVLocs[++i]; // skip ahead to next loc |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1201 | SDValue Hi = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1202 | InFlag); |
| 1203 | Chain = Hi.getValue(1); |
| 1204 | InFlag = Hi.getValue(2); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1205 | Val = DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1206 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1207 | if (VA.getLocVT() == MVT::v2f64) { |
| 1208 | SDValue Vec = DAG.getNode(ISD::UNDEF, dl, MVT::v2f64); |
| 1209 | Vec = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Vec, Val, |
| 1210 | DAG.getConstant(0, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1211 | |
| 1212 | VA = RVLocs[++i]; // skip ahead to next loc |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1213 | Lo = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, InFlag); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1214 | Chain = Lo.getValue(1); |
| 1215 | InFlag = Lo.getValue(2); |
| 1216 | VA = RVLocs[++i]; // skip ahead to next loc |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1217 | Hi = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, InFlag); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1218 | Chain = Hi.getValue(1); |
| 1219 | InFlag = Hi.getValue(2); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1220 | Val = DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1221 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Vec, Val, |
| 1222 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1223 | } |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1224 | } else { |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1225 | Val = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), VA.getLocVT(), |
| 1226 | InFlag); |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1227 | Chain = Val.getValue(1); |
| 1228 | InFlag = Val.getValue(2); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1229 | } |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1230 | |
| 1231 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1232 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1233 | case CCValAssign::Full: break; |
| 1234 | case CCValAssign::BCvt: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1235 | Val = DAG.getNode(ISD::BITCAST, dl, VA.getValVT(), Val); |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1236 | break; |
| 1237 | } |
| 1238 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1239 | InVals.push_back(Val); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1240 | } |
| 1241 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1242 | return Chain; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1243 | } |
| 1244 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1245 | /// LowerMemOpCallTo - Store the argument to the stack. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1246 | SDValue |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1247 | ARMTargetLowering::LowerMemOpCallTo(SDValue Chain, |
| 1248 | SDValue StackPtr, SDValue Arg, |
| 1249 | DebugLoc dl, SelectionDAG &DAG, |
| 1250 | const CCValAssign &VA, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1251 | ISD::ArgFlagsTy Flags) const { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1252 | unsigned LocMemOffset = VA.getLocMemOffset(); |
| 1253 | SDValue PtrOff = DAG.getIntPtrConstant(LocMemOffset); |
| 1254 | PtrOff = DAG.getNode(ISD::ADD, dl, getPointerTy(), StackPtr, PtrOff); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1255 | return DAG.getStore(Chain, dl, Arg, PtrOff, |
Chris Lattner | fc448ff | 2010-09-21 18:51:21 +0000 | [diff] [blame] | 1256 | MachinePointerInfo::getStack(LocMemOffset), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1257 | false, false, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1258 | } |
| 1259 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1260 | void ARMTargetLowering::PassF64ArgInRegs(DebugLoc dl, SelectionDAG &DAG, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1261 | SDValue Chain, SDValue &Arg, |
| 1262 | RegsToPassVector &RegsToPass, |
| 1263 | CCValAssign &VA, CCValAssign &NextVA, |
| 1264 | SDValue &StackPtr, |
| 1265 | SmallVector<SDValue, 8> &MemOpChains, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1266 | ISD::ArgFlagsTy Flags) const { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1267 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1268 | SDValue fmrrd = DAG.getNode(ARMISD::VMOVRRD, dl, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1269 | DAG.getVTList(MVT::i32, MVT::i32), Arg); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1270 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), fmrrd)); |
| 1271 | |
| 1272 | if (NextVA.isRegLoc()) |
| 1273 | RegsToPass.push_back(std::make_pair(NextVA.getLocReg(), fmrrd.getValue(1))); |
| 1274 | else { |
| 1275 | assert(NextVA.isMemLoc()); |
| 1276 | if (StackPtr.getNode() == 0) |
| 1277 | StackPtr = DAG.getCopyFromReg(Chain, dl, ARM::SP, getPointerTy()); |
| 1278 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1279 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, fmrrd.getValue(1), |
| 1280 | dl, DAG, NextVA, |
| 1281 | Flags)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1282 | } |
| 1283 | } |
| 1284 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1285 | /// LowerCall - Lowering a call into a callseq_start <- |
Evan Cheng | fc40342 | 2007-02-03 08:53:01 +0000 | [diff] [blame] | 1286 | /// ARMISD:CALL <- callseq_end chain. Also add input and output parameter |
| 1287 | /// nodes. |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1288 | SDValue |
Evan Cheng | 022d9e1 | 2010-02-02 23:55:14 +0000 | [diff] [blame] | 1289 | ARMTargetLowering::LowerCall(SDValue Chain, SDValue Callee, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1290 | CallingConv::ID CallConv, bool isVarArg, |
Evan Cheng | 4bfcd4a | 2012-02-28 18:51:51 +0000 | [diff] [blame] | 1291 | bool doesNotRet, bool &isTailCall, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1292 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1293 | const SmallVectorImpl<SDValue> &OutVals, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1294 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 1295 | DebugLoc dl, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1296 | SmallVectorImpl<SDValue> &InVals) const { |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1297 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1298 | bool IsStructRet = (Outs.empty()) ? false : Outs[0].Flags.isSRet(); |
| 1299 | bool IsSibCall = false; |
Bob Wilson | 6d2f9ce | 2011-10-07 17:17:49 +0000 | [diff] [blame] | 1300 | // Disable tail calls if they're not supported. |
| 1301 | if (!EnableARMTailCalls && !Subtarget->supportsTailCall()) |
Bob Wilson | 703af3a | 2010-08-13 22:43:33 +0000 | [diff] [blame] | 1302 | isTailCall = false; |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1303 | if (isTailCall) { |
| 1304 | // Check if it's really possible to do a tail call. |
| 1305 | isTailCall = IsEligibleForTailCallOptimization(Callee, CallConv, |
| 1306 | isVarArg, IsStructRet, MF.getFunction()->hasStructRetAttr(), |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1307 | Outs, OutVals, Ins, DAG); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1308 | // We don't support GuaranteedTailCallOpt for ARM, only automatically |
| 1309 | // detected sibcalls. |
| 1310 | if (isTailCall) { |
| 1311 | ++NumTailCalls; |
| 1312 | IsSibCall = true; |
| 1313 | } |
| 1314 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1315 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1316 | // Analyze operands of the call, assigning locations to each operand. |
| 1317 | SmallVector<CCValAssign, 16> ArgLocs; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1318 | ARMCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), |
| 1319 | getTargetMachine(), ArgLocs, *DAG.getContext(), Call); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1320 | CCInfo.AnalyzeCallOperands(Outs, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1321 | CCAssignFnForNode(CallConv, /* Return*/ false, |
| 1322 | isVarArg)); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1323 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1324 | // Get a count of how many bytes are to be pushed on the stack. |
| 1325 | unsigned NumBytes = CCInfo.getNextStackOffset(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1326 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1327 | // For tail calls, memory operands are available in our caller's stack. |
| 1328 | if (IsSibCall) |
| 1329 | NumBytes = 0; |
| 1330 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1331 | // Adjust the stack pointer for the new arguments... |
| 1332 | // These operations are automatically eliminated by the prolog/epilog pass |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1333 | if (!IsSibCall) |
| 1334 | Chain = DAG.getCALLSEQ_START(Chain, DAG.getIntPtrConstant(NumBytes, true)); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1335 | |
Jim Grosbach | f9a4b76 | 2010-02-24 01:43:03 +0000 | [diff] [blame] | 1336 | SDValue StackPtr = DAG.getCopyFromReg(Chain, dl, ARM::SP, getPointerTy()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1337 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1338 | RegsToPassVector RegsToPass; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1339 | SmallVector<SDValue, 8> MemOpChains; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1340 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1341 | // Walk the register/memloc assignments, inserting copies/loads. In the case |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1342 | // of tail call optimization, arguments are handled later. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1343 | for (unsigned i = 0, realArgIdx = 0, e = ArgLocs.size(); |
| 1344 | i != e; |
| 1345 | ++i, ++realArgIdx) { |
| 1346 | CCValAssign &VA = ArgLocs[i]; |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1347 | SDValue Arg = OutVals[realArgIdx]; |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1348 | ISD::ArgFlagsTy Flags = Outs[realArgIdx].Flags; |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1349 | bool isByVal = Flags.isByVal(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1350 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1351 | // Promote the value if needed. |
| 1352 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1353 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1354 | case CCValAssign::Full: break; |
| 1355 | case CCValAssign::SExt: |
| 1356 | Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg); |
| 1357 | break; |
| 1358 | case CCValAssign::ZExt: |
| 1359 | Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg); |
| 1360 | break; |
| 1361 | case CCValAssign::AExt: |
| 1362 | Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg); |
| 1363 | break; |
| 1364 | case CCValAssign::BCvt: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1365 | Arg = DAG.getNode(ISD::BITCAST, dl, VA.getLocVT(), Arg); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1366 | break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1367 | } |
| 1368 | |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1369 | // 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] | 1370 | if (VA.needsCustom()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1371 | if (VA.getLocVT() == MVT::v2f64) { |
| 1372 | SDValue Op0 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1373 | DAG.getConstant(0, MVT::i32)); |
| 1374 | SDValue Op1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1375 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1376 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1377 | PassF64ArgInRegs(dl, DAG, Chain, Op0, RegsToPass, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1378 | VA, ArgLocs[++i], StackPtr, MemOpChains, Flags); |
| 1379 | |
| 1380 | VA = ArgLocs[++i]; // skip ahead to next loc |
| 1381 | if (VA.isRegLoc()) { |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1382 | PassF64ArgInRegs(dl, DAG, Chain, Op1, RegsToPass, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1383 | VA, ArgLocs[++i], StackPtr, MemOpChains, Flags); |
| 1384 | } else { |
| 1385 | assert(VA.isMemLoc()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1386 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1387 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, Op1, |
| 1388 | dl, DAG, VA, Flags)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1389 | } |
| 1390 | } else { |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1391 | PassF64ArgInRegs(dl, DAG, Chain, Arg, RegsToPass, VA, ArgLocs[++i], |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1392 | StackPtr, MemOpChains, Flags); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1393 | } |
| 1394 | } else if (VA.isRegLoc()) { |
| 1395 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg)); |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1396 | } else if (isByVal) { |
| 1397 | assert(VA.isMemLoc()); |
| 1398 | unsigned offset = 0; |
| 1399 | |
| 1400 | // True if this byval aggregate will be split between registers |
| 1401 | // and memory. |
| 1402 | if (CCInfo.isFirstByValRegValid()) { |
| 1403 | EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
| 1404 | unsigned int i, j; |
| 1405 | for (i = 0, j = CCInfo.getFirstByValReg(); j < ARM::R4; i++, j++) { |
| 1406 | SDValue Const = DAG.getConstant(4*i, MVT::i32); |
| 1407 | SDValue AddArg = DAG.getNode(ISD::ADD, dl, PtrVT, Arg, Const); |
| 1408 | SDValue Load = DAG.getLoad(PtrVT, dl, Chain, AddArg, |
| 1409 | MachinePointerInfo(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 1410 | false, false, false, 0); |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1411 | MemOpChains.push_back(Load.getValue(1)); |
| 1412 | RegsToPass.push_back(std::make_pair(j, Load)); |
| 1413 | } |
| 1414 | offset = ARM::R4 - CCInfo.getFirstByValReg(); |
| 1415 | CCInfo.clearFirstByValReg(); |
| 1416 | } |
| 1417 | |
| 1418 | unsigned LocMemOffset = VA.getLocMemOffset(); |
| 1419 | SDValue StkPtrOff = DAG.getIntPtrConstant(LocMemOffset); |
| 1420 | SDValue Dst = DAG.getNode(ISD::ADD, dl, getPointerTy(), StackPtr, |
| 1421 | StkPtrOff); |
| 1422 | SDValue SrcOffset = DAG.getIntPtrConstant(4*offset); |
| 1423 | SDValue Src = DAG.getNode(ISD::ADD, dl, getPointerTy(), Arg, SrcOffset); |
| 1424 | SDValue SizeNode = DAG.getConstant(Flags.getByValSize() - 4*offset, |
| 1425 | MVT::i32); |
| 1426 | MemOpChains.push_back(DAG.getMemcpy(Chain, dl, Dst, Src, SizeNode, |
| 1427 | Flags.getByValAlign(), |
| 1428 | /*isVolatile=*/false, |
Dan Gohman | 65fd656 | 2011-11-03 21:49:52 +0000 | [diff] [blame] | 1429 | /*AlwaysInline=*/false, |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1430 | MachinePointerInfo(0), |
| 1431 | MachinePointerInfo(0))); |
| 1432 | |
| 1433 | } else if (!IsSibCall) { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1434 | assert(VA.isMemLoc()); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1435 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1436 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, Arg, |
| 1437 | dl, DAG, VA, Flags)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1438 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1439 | } |
| 1440 | |
| 1441 | if (!MemOpChains.empty()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1442 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1443 | &MemOpChains[0], MemOpChains.size()); |
| 1444 | |
| 1445 | // Build a sequence of copy-to-reg nodes chained together with token chain |
| 1446 | // and flag operands which copy the outgoing args into the appropriate regs. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1447 | SDValue InFlag; |
Dale Johannesen | 6470a11 | 2010-06-15 22:08:33 +0000 | [diff] [blame] | 1448 | // Tail call byval lowering might overwrite argument registers so in case of |
| 1449 | // tail call optimization the copies to registers are lowered later. |
| 1450 | if (!isTailCall) |
| 1451 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 1452 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, |
| 1453 | RegsToPass[i].second, InFlag); |
| 1454 | InFlag = Chain.getValue(1); |
| 1455 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1456 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1457 | // For tail calls lower the arguments to the 'real' stack slot. |
| 1458 | if (isTailCall) { |
| 1459 | // Force all the incoming stack arguments to be loaded from the stack |
| 1460 | // before any new outgoing arguments are stored to the stack, because the |
| 1461 | // outgoing stack slots may alias the incoming argument stack slots, and |
| 1462 | // the alias isn't otherwise explicit. This is slightly more conservative |
| 1463 | // than necessary, because it means that each store effectively depends |
| 1464 | // on every argument instead of just those arguments it would clobber. |
| 1465 | |
Chris Lattner | 7a2bdde | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 1466 | // Do not flag preceding copytoreg stuff together with the following stuff. |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1467 | InFlag = SDValue(); |
| 1468 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 1469 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, |
| 1470 | RegsToPass[i].second, InFlag); |
| 1471 | InFlag = Chain.getValue(1); |
| 1472 | } |
| 1473 | InFlag =SDValue(); |
| 1474 | } |
| 1475 | |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1476 | // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every |
| 1477 | // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol |
| 1478 | // node so that legalize doesn't hack it. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1479 | bool isDirect = false; |
| 1480 | bool isARMFunc = false; |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 1481 | bool isLocalARMFunc = false; |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1482 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1483 | |
| 1484 | if (EnableARMLongCalls) { |
| 1485 | assert (getTargetMachine().getRelocationModel() == Reloc::Static |
| 1486 | && "long-calls with non-static relocation model!"); |
| 1487 | // Handle a global address or an external symbol. If it's not one of |
| 1488 | // those, the target's already in a register, so we don't need to do |
| 1489 | // anything extra. |
| 1490 | if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
Anders Carlsson | 0dbdca5 | 2010-04-15 03:11:28 +0000 | [diff] [blame] | 1491 | const GlobalValue *GV = G->getGlobal(); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1492 | // Create a constant pool entry for the callee address |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1493 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 1494 | ARMConstantPoolValue *CPV = |
| 1495 | ARMConstantPoolConstant::Create(GV, ARMPCLabelIndex, ARMCP::CPValue, 0); |
| 1496 | |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1497 | // Get the address of the callee into a register |
| 1498 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
| 1499 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| 1500 | Callee = DAG.getLoad(getPointerTy(), dl, |
| 1501 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1502 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 1503 | false, false, false, 0); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1504 | } else if (ExternalSymbolSDNode *S=dyn_cast<ExternalSymbolSDNode>(Callee)) { |
| 1505 | const char *Sym = S->getSymbol(); |
| 1506 | |
| 1507 | // Create a constant pool entry for the callee address |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1508 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Bill Wendling | fe31e67 | 2011-10-01 08:58:29 +0000 | [diff] [blame] | 1509 | ARMConstantPoolValue *CPV = |
| 1510 | ARMConstantPoolSymbol::Create(*DAG.getContext(), Sym, |
| 1511 | ARMPCLabelIndex, 0); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1512 | // Get the address of the callee into a register |
| 1513 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
| 1514 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| 1515 | Callee = DAG.getLoad(getPointerTy(), dl, |
| 1516 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1517 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 1518 | false, false, false, 0); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1519 | } |
| 1520 | } else if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 1521 | const GlobalValue *GV = G->getGlobal(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1522 | isDirect = true; |
Chris Lattner | 4fb63d0 | 2009-07-15 04:12:33 +0000 | [diff] [blame] | 1523 | bool isExt = GV->isDeclaration() || GV->isWeakForLinker(); |
Evan Cheng | 970a419 | 2007-01-19 19:28:01 +0000 | [diff] [blame] | 1524 | bool isStub = (isExt && Subtarget->isTargetDarwin()) && |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1525 | getTargetMachine().getRelocationModel() != Reloc::Static; |
| 1526 | isARMFunc = !Subtarget->isThumb() || isStub; |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 1527 | // ARM call to a local ARM function is predicable. |
Evan Cheng | 46df4eb | 2010-06-16 07:35:02 +0000 | [diff] [blame] | 1528 | isLocalARMFunc = !Subtarget->isThumb() && (!isExt || !ARMInterworking); |
Evan Cheng | c60e76d | 2007-01-30 20:37:08 +0000 | [diff] [blame] | 1529 | // tBX takes a register source operand. |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 1530 | if (isARMFunc && Subtarget->isThumb1Only() && !Subtarget->hasV5TOps()) { |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1531 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 1532 | ARMConstantPoolValue *CPV = |
| 1533 | ARMConstantPoolConstant::Create(GV, ARMPCLabelIndex, ARMCP::CPValue, 4); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1534 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1535 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1536 | Callee = DAG.getLoad(getPointerTy(), dl, |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1537 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1538 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 1539 | false, false, false, 0); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1540 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1541 | Callee = DAG.getNode(ARMISD::PIC_ADD, dl, |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1542 | getPointerTy(), Callee, PICLabel); |
Jim Grosbach | 637d89f | 2010-09-22 23:27:36 +0000 | [diff] [blame] | 1543 | } else { |
| 1544 | // On ELF targets for PIC code, direct calls should go through the PLT |
| 1545 | unsigned OpFlags = 0; |
| 1546 | if (Subtarget->isTargetELF() && |
| 1547 | getTargetMachine().getRelocationModel() == Reloc::PIC_) |
| 1548 | OpFlags = ARMII::MO_PLT; |
| 1549 | Callee = DAG.getTargetGlobalAddress(GV, dl, getPointerTy(), 0, OpFlags); |
| 1550 | } |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1551 | } else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1552 | isDirect = true; |
Evan Cheng | 970a419 | 2007-01-19 19:28:01 +0000 | [diff] [blame] | 1553 | bool isStub = Subtarget->isTargetDarwin() && |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1554 | getTargetMachine().getRelocationModel() != Reloc::Static; |
| 1555 | isARMFunc = !Subtarget->isThumb() || isStub; |
Evan Cheng | c60e76d | 2007-01-30 20:37:08 +0000 | [diff] [blame] | 1556 | // tBX takes a register source operand. |
| 1557 | const char *Sym = S->getSymbol(); |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 1558 | if (isARMFunc && Subtarget->isThumb1Only() && !Subtarget->hasV5TOps()) { |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1559 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Bill Wendling | fe31e67 | 2011-10-01 08:58:29 +0000 | [diff] [blame] | 1560 | ARMConstantPoolValue *CPV = |
| 1561 | ARMConstantPoolSymbol::Create(*DAG.getContext(), Sym, |
| 1562 | ARMPCLabelIndex, 4); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1563 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1564 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1565 | Callee = DAG.getLoad(getPointerTy(), dl, |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1566 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1567 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 1568 | false, false, false, 0); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1569 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1570 | Callee = DAG.getNode(ARMISD::PIC_ADD, dl, |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1571 | getPointerTy(), Callee, PICLabel); |
Jim Grosbach | 637d89f | 2010-09-22 23:27:36 +0000 | [diff] [blame] | 1572 | } else { |
| 1573 | unsigned OpFlags = 0; |
| 1574 | // On ELF targets for PIC code, direct calls should go through the PLT |
| 1575 | if (Subtarget->isTargetELF() && |
| 1576 | getTargetMachine().getRelocationModel() == Reloc::PIC_) |
| 1577 | OpFlags = ARMII::MO_PLT; |
| 1578 | Callee = DAG.getTargetExternalSymbol(Sym, getPointerTy(), OpFlags); |
| 1579 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1580 | } |
| 1581 | |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1582 | // FIXME: handle tail calls differently. |
| 1583 | unsigned CallOpc; |
Evan Cheng | b620724 | 2009-08-01 00:16:10 +0000 | [diff] [blame] | 1584 | if (Subtarget->isThumb()) { |
| 1585 | if ((!isDirect || isARMFunc) && !Subtarget->hasV5TOps()) |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1586 | CallOpc = ARMISD::CALL_NOLINK; |
Evan Cheng | 4bfcd4a | 2012-02-28 18:51:51 +0000 | [diff] [blame] | 1587 | else if (doesNotRet && isDirect && !isARMFunc && |
| 1588 | Subtarget->hasRAS() && !Subtarget->isThumb1Only()) |
| 1589 | // "mov lr, pc; b _foo" to avoid confusing the RSP |
| 1590 | CallOpc = ARMISD::CALL_NOLINK; |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1591 | else |
| 1592 | CallOpc = isARMFunc ? ARMISD::CALL : ARMISD::tCALL; |
| 1593 | } else { |
Evan Cheng | 4bfcd4a | 2012-02-28 18:51:51 +0000 | [diff] [blame] | 1594 | if (!isDirect && !Subtarget->hasV5TOps()) { |
| 1595 | CallOpc = ARMISD::CALL_NOLINK; |
| 1596 | } else if (doesNotRet && isDirect && Subtarget->hasRAS()) |
| 1597 | // "mov lr, pc; b _foo" to avoid confusing the RSP |
| 1598 | CallOpc = ARMISD::CALL_NOLINK; |
| 1599 | else |
| 1600 | CallOpc = isLocalARMFunc ? ARMISD::CALL_PRED : ARMISD::CALL; |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1601 | } |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1602 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1603 | std::vector<SDValue> Ops; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1604 | Ops.push_back(Chain); |
| 1605 | Ops.push_back(Callee); |
| 1606 | |
| 1607 | // Add argument registers to the end of the list so that they are known live |
| 1608 | // into the call. |
| 1609 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) |
| 1610 | Ops.push_back(DAG.getRegister(RegsToPass[i].first, |
| 1611 | RegsToPass[i].second.getValueType())); |
| 1612 | |
Jakob Stoklund Olesen | c54f634 | 2012-02-24 01:19:29 +0000 | [diff] [blame] | 1613 | // Add a register mask operand representing the call-preserved registers. |
| 1614 | const TargetRegisterInfo *TRI = getTargetMachine().getRegisterInfo(); |
| 1615 | const uint32_t *Mask = TRI->getCallPreservedMask(CallConv); |
| 1616 | assert(Mask && "Missing call preserved mask for calling convention"); |
| 1617 | Ops.push_back(DAG.getRegisterMask(Mask)); |
| 1618 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1619 | if (InFlag.getNode()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1620 | Ops.push_back(InFlag); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1621 | |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 1622 | SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue); |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1623 | if (isTailCall) |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1624 | return DAG.getNode(ARMISD::TC_RETURN, dl, NodeTys, &Ops[0], Ops.size()); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1625 | |
Duncan Sands | 4bdcb61 | 2008-07-02 17:40:58 +0000 | [diff] [blame] | 1626 | // Returns a chain and a flag for retval copy to use. |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1627 | Chain = DAG.getNode(CallOpc, dl, NodeTys, &Ops[0], Ops.size()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1628 | InFlag = Chain.getValue(1); |
| 1629 | |
Chris Lattner | e563bbc | 2008-10-11 22:08:30 +0000 | [diff] [blame] | 1630 | Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(NumBytes, true), |
| 1631 | DAG.getIntPtrConstant(0, true), InFlag); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1632 | if (!Ins.empty()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1633 | InFlag = Chain.getValue(1); |
| 1634 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1635 | // Handle result values, copying them out of physregs into vregs that we |
| 1636 | // return. |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1637 | return LowerCallResult(Chain, InFlag, CallConv, isVarArg, Ins, |
| 1638 | dl, DAG, InVals); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1639 | } |
| 1640 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1641 | /// HandleByVal - Every parameter *after* a byval parameter is passed |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1642 | /// on the stack. Remember the next parameter register to allocate, |
| 1643 | /// and then confiscate the rest of the parameter registers to insure |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1644 | /// this. |
| 1645 | void |
Craig Topper | c89c744 | 2012-03-27 07:21:54 +0000 | [diff] [blame] | 1646 | ARMTargetLowering::HandleByVal(CCState *State, unsigned &size) const { |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1647 | unsigned reg = State->AllocateReg(GPRArgRegs, 4); |
| 1648 | assert((State->getCallOrPrologue() == Prologue || |
| 1649 | State->getCallOrPrologue() == Call) && |
| 1650 | "unhandled ParmContext"); |
| 1651 | if ((!State->isFirstByValRegValid()) && |
| 1652 | (ARM::R0 <= reg) && (reg <= ARM::R3)) { |
| 1653 | State->setFirstByValReg(reg); |
| 1654 | // At a call site, a byval parameter that is split between |
| 1655 | // registers and memory needs its size truncated here. In a |
| 1656 | // function prologue, such byval parameters are reassembled in |
| 1657 | // memory, and are not truncated. |
| 1658 | if (State->getCallOrPrologue() == Call) { |
| 1659 | unsigned excess = 4 * (ARM::R4 - reg); |
| 1660 | assert(size >= excess && "expected larger existing stack allocation"); |
| 1661 | size -= excess; |
| 1662 | } |
| 1663 | } |
| 1664 | // Confiscate any remaining parameter registers to preclude their |
| 1665 | // assignment to subsequent parameters. |
| 1666 | while (State->AllocateReg(GPRArgRegs, 4)) |
| 1667 | ; |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1668 | } |
| 1669 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1670 | /// MatchingStackOffset - Return true if the given stack call argument is |
| 1671 | /// already available in the same position (relatively) of the caller's |
| 1672 | /// incoming argument stack. |
| 1673 | static |
| 1674 | bool MatchingStackOffset(SDValue Arg, unsigned Offset, ISD::ArgFlagsTy Flags, |
| 1675 | MachineFrameInfo *MFI, const MachineRegisterInfo *MRI, |
Craig Topper | acf2077 | 2012-03-25 23:49:58 +0000 | [diff] [blame] | 1676 | const TargetInstrInfo *TII) { |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1677 | unsigned Bytes = Arg.getValueType().getSizeInBits() / 8; |
| 1678 | int FI = INT_MAX; |
| 1679 | if (Arg.getOpcode() == ISD::CopyFromReg) { |
| 1680 | unsigned VR = cast<RegisterSDNode>(Arg.getOperand(1))->getReg(); |
Jakob Stoklund Olesen | c9df025 | 2011-01-10 02:58:51 +0000 | [diff] [blame] | 1681 | if (!TargetRegisterInfo::isVirtualRegister(VR)) |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1682 | return false; |
| 1683 | MachineInstr *Def = MRI->getVRegDef(VR); |
| 1684 | if (!Def) |
| 1685 | return false; |
| 1686 | if (!Flags.isByVal()) { |
| 1687 | if (!TII->isLoadFromStackSlot(Def, FI)) |
| 1688 | return false; |
| 1689 | } else { |
Dale Johannesen | 7835f1f | 2010-07-08 01:18:23 +0000 | [diff] [blame] | 1690 | return false; |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1691 | } |
| 1692 | } else if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Arg)) { |
| 1693 | if (Flags.isByVal()) |
| 1694 | // ByVal argument is passed in as a pointer but it's now being |
| 1695 | // dereferenced. e.g. |
| 1696 | // define @foo(%struct.X* %A) { |
| 1697 | // tail call @bar(%struct.X* byval %A) |
| 1698 | // } |
| 1699 | return false; |
| 1700 | SDValue Ptr = Ld->getBasePtr(); |
| 1701 | FrameIndexSDNode *FINode = dyn_cast<FrameIndexSDNode>(Ptr); |
| 1702 | if (!FINode) |
| 1703 | return false; |
| 1704 | FI = FINode->getIndex(); |
| 1705 | } else |
| 1706 | return false; |
| 1707 | |
| 1708 | assert(FI != INT_MAX); |
| 1709 | if (!MFI->isFixedObjectIndex(FI)) |
| 1710 | return false; |
| 1711 | return Offset == MFI->getObjectOffset(FI) && Bytes == MFI->getObjectSize(FI); |
| 1712 | } |
| 1713 | |
| 1714 | /// IsEligibleForTailCallOptimization - Check whether the call is eligible |
| 1715 | /// for tail call optimization. Targets which want to do tail call |
| 1716 | /// optimization should implement this function. |
| 1717 | bool |
| 1718 | ARMTargetLowering::IsEligibleForTailCallOptimization(SDValue Callee, |
| 1719 | CallingConv::ID CalleeCC, |
| 1720 | bool isVarArg, |
| 1721 | bool isCalleeStructRet, |
| 1722 | bool isCallerStructRet, |
| 1723 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1724 | const SmallVectorImpl<SDValue> &OutVals, |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1725 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 1726 | SelectionDAG& DAG) const { |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1727 | const Function *CallerF = DAG.getMachineFunction().getFunction(); |
| 1728 | CallingConv::ID CallerCC = CallerF->getCallingConv(); |
| 1729 | bool CCMatch = CallerCC == CalleeCC; |
| 1730 | |
| 1731 | // Look for obvious safe cases to perform tail call optimization that do not |
| 1732 | // require ABI changes. This is what gcc calls sibcall. |
| 1733 | |
Jim Grosbach | 7616b64 | 2010-06-16 23:45:49 +0000 | [diff] [blame] | 1734 | // Do not sibcall optimize vararg calls unless the call site is not passing |
| 1735 | // any arguments. |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1736 | if (isVarArg && !Outs.empty()) |
| 1737 | return false; |
| 1738 | |
| 1739 | // Also avoid sibcall optimization if either caller or callee uses struct |
| 1740 | // return semantics. |
| 1741 | if (isCalleeStructRet || isCallerStructRet) |
| 1742 | return false; |
| 1743 | |
Dale Johannesen | e39fdbe | 2010-06-23 18:52:34 +0000 | [diff] [blame] | 1744 | // FIXME: Completely disable sibcall for Thumb1 since Thumb1RegisterInfo:: |
Jim Grosbach | 8dc41f3 | 2011-07-08 20:18:11 +0000 | [diff] [blame] | 1745 | // emitEpilogue is not ready for them. Thumb tail calls also use t2B, as |
| 1746 | // the Thumb1 16-bit unconditional branch doesn't have sufficient relocation |
| 1747 | // support in the assembler and linker to be used. This would need to be |
| 1748 | // fixed to fully support tail calls in Thumb1. |
| 1749 | // |
Dale Johannesen | 7835f1f | 2010-07-08 01:18:23 +0000 | [diff] [blame] | 1750 | // Doing this is tricky, since the LDM/POP instruction on Thumb doesn't take |
| 1751 | // LR. This means if we need to reload LR, it takes an extra instructions, |
| 1752 | // which outweighs the value of the tail call; but here we don't know yet |
| 1753 | // 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] | 1754 | // 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] | 1755 | // emitEpilogue if LR is used. |
Dale Johannesen | 7835f1f | 2010-07-08 01:18:23 +0000 | [diff] [blame] | 1756 | |
| 1757 | // Thumb1 PIC calls to external symbols use BX, so they can be tail calls, |
| 1758 | // but we need to make sure there are enough registers; the only valid |
| 1759 | // registers are the 4 used for parameters. We don't currently do this |
| 1760 | // case. |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1761 | if (Subtarget->isThumb1Only()) |
| 1762 | return false; |
Dale Johannesen | df50d7e | 2010-06-18 18:13:11 +0000 | [diff] [blame] | 1763 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1764 | // If the calling conventions do not match, then we'd better make sure the |
| 1765 | // results are returned in the same way as what the caller expects. |
| 1766 | if (!CCMatch) { |
| 1767 | SmallVector<CCValAssign, 16> RVLocs1; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1768 | ARMCCState CCInfo1(CalleeCC, false, DAG.getMachineFunction(), |
| 1769 | getTargetMachine(), RVLocs1, *DAG.getContext(), Call); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1770 | CCInfo1.AnalyzeCallResult(Ins, CCAssignFnForNode(CalleeCC, true, isVarArg)); |
| 1771 | |
| 1772 | SmallVector<CCValAssign, 16> RVLocs2; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1773 | ARMCCState CCInfo2(CallerCC, false, DAG.getMachineFunction(), |
| 1774 | getTargetMachine(), RVLocs2, *DAG.getContext(), Call); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1775 | CCInfo2.AnalyzeCallResult(Ins, CCAssignFnForNode(CallerCC, true, isVarArg)); |
| 1776 | |
| 1777 | if (RVLocs1.size() != RVLocs2.size()) |
| 1778 | return false; |
| 1779 | for (unsigned i = 0, e = RVLocs1.size(); i != e; ++i) { |
| 1780 | if (RVLocs1[i].isRegLoc() != RVLocs2[i].isRegLoc()) |
| 1781 | return false; |
| 1782 | if (RVLocs1[i].getLocInfo() != RVLocs2[i].getLocInfo()) |
| 1783 | return false; |
| 1784 | if (RVLocs1[i].isRegLoc()) { |
| 1785 | if (RVLocs1[i].getLocReg() != RVLocs2[i].getLocReg()) |
| 1786 | return false; |
| 1787 | } else { |
| 1788 | if (RVLocs1[i].getLocMemOffset() != RVLocs2[i].getLocMemOffset()) |
| 1789 | return false; |
| 1790 | } |
| 1791 | } |
| 1792 | } |
| 1793 | |
| 1794 | // If the callee takes no arguments then go on to check the results of the |
| 1795 | // call. |
| 1796 | if (!Outs.empty()) { |
| 1797 | // Check if stack adjustment is needed. For now, do not do this if any |
| 1798 | // argument is passed on the stack. |
| 1799 | SmallVector<CCValAssign, 16> ArgLocs; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1800 | ARMCCState CCInfo(CalleeCC, isVarArg, DAG.getMachineFunction(), |
| 1801 | getTargetMachine(), ArgLocs, *DAG.getContext(), Call); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1802 | CCInfo.AnalyzeCallOperands(Outs, |
| 1803 | CCAssignFnForNode(CalleeCC, false, isVarArg)); |
| 1804 | if (CCInfo.getNextStackOffset()) { |
| 1805 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1806 | |
| 1807 | // Check if the arguments are already laid out in the right way as |
| 1808 | // the caller's fixed stack objects. |
| 1809 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 1810 | const MachineRegisterInfo *MRI = &MF.getRegInfo(); |
Craig Topper | acf2077 | 2012-03-25 23:49:58 +0000 | [diff] [blame] | 1811 | const TargetInstrInfo *TII = 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 | bf010eb | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 1939 | bool ARMTargetLowering::isUsedByReturnOnly(SDNode *N, SDValue &Chain) const { |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1940 | if (N->getNumValues() != 1) |
| 1941 | return false; |
| 1942 | if (!N->hasNUsesOfValue(1, 0)) |
| 1943 | return false; |
| 1944 | |
Evan Cheng | bf010eb | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 1945 | SDValue TCChain = Chain; |
| 1946 | SDNode *Copy = *N->use_begin(); |
| 1947 | if (Copy->getOpcode() == ISD::CopyToReg) { |
| 1948 | // If the copy has a glue operand, we conservatively assume it isn't safe to |
| 1949 | // perform a tail call. |
| 1950 | if (Copy->getOperand(Copy->getNumOperands()-1).getValueType() == MVT::Glue) |
| 1951 | return false; |
| 1952 | TCChain = Copy->getOperand(0); |
| 1953 | } else if (Copy->getOpcode() == ARMISD::VMOVRRD) { |
| 1954 | SDNode *VMov = Copy; |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1955 | // f64 returned in a pair of GPRs. |
Evan Cheng | bf010eb | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 1956 | SmallPtrSet<SDNode*, 2> Copies; |
| 1957 | for (SDNode::use_iterator UI = VMov->use_begin(), UE = VMov->use_end(); |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1958 | UI != UE; ++UI) { |
| 1959 | if (UI->getOpcode() != ISD::CopyToReg) |
| 1960 | return false; |
Evan Cheng | bf010eb | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 1961 | Copies.insert(*UI); |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1962 | } |
Evan Cheng | bf010eb | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 1963 | if (Copies.size() > 2) |
| 1964 | return false; |
| 1965 | |
| 1966 | for (SDNode::use_iterator UI = VMov->use_begin(), UE = VMov->use_end(); |
| 1967 | UI != UE; ++UI) { |
| 1968 | SDValue UseChain = UI->getOperand(0); |
| 1969 | if (Copies.count(UseChain.getNode())) |
| 1970 | // Second CopyToReg |
| 1971 | Copy = *UI; |
| 1972 | else |
| 1973 | // First CopyToReg |
| 1974 | TCChain = UseChain; |
| 1975 | } |
| 1976 | } else if (Copy->getOpcode() == ISD::BITCAST) { |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1977 | // f32 returned in a single GPR. |
Evan Cheng | bf010eb | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 1978 | if (!Copy->hasOneUse()) |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1979 | return false; |
Evan Cheng | bf010eb | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 1980 | Copy = *Copy->use_begin(); |
| 1981 | if (Copy->getOpcode() != ISD::CopyToReg || !Copy->hasNUsesOfValue(1, 0)) |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1982 | return false; |
Evan Cheng | bf010eb | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 1983 | Chain = Copy->getOperand(0); |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1984 | } else { |
| 1985 | return false; |
| 1986 | } |
| 1987 | |
Evan Cheng | 1bf891a | 2010-12-01 22:59:46 +0000 | [diff] [blame] | 1988 | bool HasRet = false; |
Evan Cheng | bf010eb | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 1989 | for (SDNode::use_iterator UI = Copy->use_begin(), UE = Copy->use_end(); |
| 1990 | UI != UE; ++UI) { |
| 1991 | if (UI->getOpcode() != ARMISD::RET_FLAG) |
| 1992 | return false; |
| 1993 | HasRet = true; |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1994 | } |
| 1995 | |
Evan Cheng | bf010eb | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 1996 | if (!HasRet) |
| 1997 | return false; |
| 1998 | |
| 1999 | Chain = TCChain; |
| 2000 | return true; |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2001 | } |
| 2002 | |
Evan Cheng | 485fafc | 2011-03-21 01:19:09 +0000 | [diff] [blame] | 2003 | bool ARMTargetLowering::mayBeEmittedAsTailCall(CallInst *CI) const { |
Evan Cheng | 1c80f56 | 2012-03-30 01:24:39 +0000 | [diff] [blame] | 2004 | if (!EnableARMTailCalls && !Subtarget->supportsTailCall()) |
Evan Cheng | 485fafc | 2011-03-21 01:19:09 +0000 | [diff] [blame] | 2005 | return false; |
| 2006 | |
| 2007 | if (!CI->isTailCall()) |
| 2008 | return false; |
| 2009 | |
| 2010 | return !Subtarget->isThumb1Only(); |
| 2011 | } |
| 2012 | |
Bob Wilson | b62d257 | 2009-11-03 00:02:05 +0000 | [diff] [blame] | 2013 | // ConstantPool, JumpTable, GlobalAddress, and ExternalSymbol are lowered as |
| 2014 | // their target counterpart wrapped in the ARMISD::Wrapper node. Suppose N is |
| 2015 | // one of the above mentioned nodes. It has to be wrapped because otherwise |
| 2016 | // Select(N) returns N. So the raw TargetGlobalAddress nodes, etc. can only |
| 2017 | // be used to form addressing mode. These wrapped nodes will be selected |
| 2018 | // into MOVi. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2019 | static SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2020 | EVT PtrVT = Op.getValueType(); |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 2021 | // FIXME there is no actual debug info here |
| 2022 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2023 | ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2024 | SDValue Res; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2025 | if (CP->isMachineConstantPoolEntry()) |
| 2026 | Res = DAG.getTargetConstantPool(CP->getMachineCPVal(), PtrVT, |
| 2027 | CP->getAlignment()); |
| 2028 | else |
| 2029 | Res = DAG.getTargetConstantPool(CP->getConstVal(), PtrVT, |
| 2030 | CP->getAlignment()); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2031 | return DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Res); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2032 | } |
| 2033 | |
Jim Grosbach | e1102ca | 2010-07-19 17:20:38 +0000 | [diff] [blame] | 2034 | unsigned ARMTargetLowering::getJumpTableEncoding() const { |
| 2035 | return MachineJumpTableInfo::EK_Inline; |
| 2036 | } |
| 2037 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2038 | SDValue ARMTargetLowering::LowerBlockAddress(SDValue Op, |
| 2039 | SelectionDAG &DAG) const { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2040 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2041 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2042 | unsigned ARMPCLabelIndex = 0; |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 2043 | DebugLoc DL = Op.getDebugLoc(); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2044 | EVT PtrVT = getPointerTy(); |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2045 | const BlockAddress *BA = cast<BlockAddressSDNode>(Op)->getBlockAddress(); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2046 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| 2047 | SDValue CPAddr; |
| 2048 | if (RelocM == Reloc::Static) { |
| 2049 | CPAddr = DAG.getTargetConstantPool(BA, PtrVT, 4); |
| 2050 | } else { |
| 2051 | unsigned PCAdj = Subtarget->isThumb() ? 4 : 8; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2052 | ARMPCLabelIndex = AFI->createPICLabelUId(); |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2053 | ARMConstantPoolValue *CPV = |
| 2054 | ARMConstantPoolConstant::Create(BA, ARMPCLabelIndex, |
| 2055 | ARMCP::CPBlockAddress, PCAdj); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2056 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
| 2057 | } |
| 2058 | CPAddr = DAG.getNode(ARMISD::Wrapper, DL, PtrVT, CPAddr); |
| 2059 | SDValue Result = DAG.getLoad(PtrVT, DL, DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2060 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2061 | false, false, false, 0); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2062 | if (RelocM == Reloc::Static) |
| 2063 | return Result; |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2064 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2065 | return DAG.getNode(ARMISD::PIC_ADD, DL, PtrVT, Result, PICLabel); |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 2066 | } |
| 2067 | |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2068 | // Lower ISD::GlobalTLSAddress using the "general dynamic" model |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2069 | SDValue |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2070 | ARMTargetLowering::LowerToTLSGeneralDynamicModel(GlobalAddressSDNode *GA, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2071 | SelectionDAG &DAG) const { |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2072 | DebugLoc dl = GA->getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2073 | EVT PtrVT = getPointerTy(); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2074 | unsigned char PCAdj = Subtarget->isThumb() ? 4 : 8; |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2075 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2076 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2077 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2078 | ARMConstantPoolValue *CPV = |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2079 | ARMConstantPoolConstant::Create(GA->getGlobal(), ARMPCLabelIndex, |
| 2080 | ARMCP::CPValue, PCAdj, ARMCP::TLSGD, true); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2081 | SDValue Argument = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2082 | Argument = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Argument); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2083 | Argument = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Argument, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2084 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2085 | false, false, false, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2086 | SDValue Chain = Argument.getValue(1); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2087 | |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2088 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2089 | Argument = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Argument, PICLabel); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2090 | |
| 2091 | // call __tls_get_addr. |
| 2092 | ArgListTy Args; |
| 2093 | ArgListEntry Entry; |
| 2094 | Entry.Node = Argument; |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 2095 | Entry.Ty = (Type *) Type::getInt32Ty(*DAG.getContext()); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2096 | Args.push_back(Entry); |
Dale Johannesen | 7d2ad62 | 2009-01-30 23:10:59 +0000 | [diff] [blame] | 2097 | // FIXME: is there useful debug info available here? |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2098 | std::pair<SDValue, SDValue> CallResult = |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 2099 | LowerCallTo(Chain, (Type *) Type::getInt32Ty(*DAG.getContext()), |
Evan Cheng | 59bc060 | 2009-08-14 19:11:20 +0000 | [diff] [blame] | 2100 | false, false, false, false, |
Evan Cheng | 4bfcd4a | 2012-02-28 18:51:51 +0000 | [diff] [blame] | 2101 | 0, CallingConv::C, /*isTailCall=*/false, |
| 2102 | /*doesNotRet=*/false, /*isReturnValueUsed=*/true, |
Bill Wendling | 46ada19 | 2010-03-02 01:55:18 +0000 | [diff] [blame] | 2103 | DAG.getExternalSymbol("__tls_get_addr", PtrVT), Args, DAG, dl); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2104 | return CallResult.first; |
| 2105 | } |
| 2106 | |
| 2107 | // Lower ISD::GlobalTLSAddress using the "initial exec" or |
| 2108 | // "local exec" model. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2109 | SDValue |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2110 | ARMTargetLowering::LowerToTLSExecModels(GlobalAddressSDNode *GA, |
Hans Wennborg | fd5abd5 | 2012-05-04 09:40:39 +0000 | [diff] [blame] | 2111 | SelectionDAG &DAG, |
| 2112 | TLSModel::Model model) const { |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2113 | const GlobalValue *GV = GA->getGlobal(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2114 | DebugLoc dl = GA->getDebugLoc(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2115 | SDValue Offset; |
| 2116 | SDValue Chain = DAG.getEntryNode(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2117 | EVT PtrVT = getPointerTy(); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2118 | // Get the Thread Pointer |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2119 | SDValue ThreadPointer = DAG.getNode(ARMISD::THREAD_POINTER, dl, PtrVT); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2120 | |
Hans Wennborg | fd5abd5 | 2012-05-04 09:40:39 +0000 | [diff] [blame] | 2121 | if (model == TLSModel::InitialExec) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2122 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2123 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2124 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2125 | // Initial exec model. |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2126 | unsigned char PCAdj = Subtarget->isThumb() ? 4 : 8; |
| 2127 | ARMConstantPoolValue *CPV = |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2128 | ARMConstantPoolConstant::Create(GA->getGlobal(), ARMPCLabelIndex, |
| 2129 | ARMCP::CPValue, PCAdj, ARMCP::GOTTPOFF, |
| 2130 | true); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2131 | Offset = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2132 | Offset = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Offset); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2133 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2134 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2135 | false, false, false, 0); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2136 | Chain = Offset.getValue(1); |
| 2137 | |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2138 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2139 | Offset = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Offset, PICLabel); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2140 | |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2141 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2142 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2143 | false, false, false, 0); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2144 | } else { |
| 2145 | // local exec model |
Hans Wennborg | fd5abd5 | 2012-05-04 09:40:39 +0000 | [diff] [blame] | 2146 | assert(model == TLSModel::LocalExec); |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2147 | ARMConstantPoolValue *CPV = |
| 2148 | ARMConstantPoolConstant::Create(GV, ARMCP::TPOFF); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2149 | Offset = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2150 | Offset = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Offset); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2151 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2152 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2153 | false, false, false, 0); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2154 | } |
| 2155 | |
| 2156 | // The address of the thread local variable is the add of the thread |
| 2157 | // pointer with the offset of the variable. |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2158 | return DAG.getNode(ISD::ADD, dl, PtrVT, ThreadPointer, Offset); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2159 | } |
| 2160 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2161 | SDValue |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2162 | ARMTargetLowering::LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const { |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2163 | // TODO: implement the "local dynamic" model |
| 2164 | assert(Subtarget->isTargetELF() && |
| 2165 | "TLS not implemented for non-ELF targets"); |
| 2166 | GlobalAddressSDNode *GA = cast<GlobalAddressSDNode>(Op); |
Hans Wennborg | fd5abd5 | 2012-05-04 09:40:39 +0000 | [diff] [blame] | 2167 | |
| 2168 | TLSModel::Model model = getTargetMachine().getTLSModel(GA->getGlobal()); |
| 2169 | |
| 2170 | switch (model) { |
| 2171 | case TLSModel::GeneralDynamic: |
| 2172 | case TLSModel::LocalDynamic: |
| 2173 | return LowerToTLSGeneralDynamicModel(GA, DAG); |
| 2174 | case TLSModel::InitialExec: |
| 2175 | case TLSModel::LocalExec: |
| 2176 | return LowerToTLSExecModels(GA, DAG, model); |
| 2177 | } |
Matt Beaumont-Gay | 39af944 | 2012-05-04 18:34:27 +0000 | [diff] [blame] | 2178 | llvm_unreachable("bogus TLS model"); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2179 | } |
| 2180 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2181 | SDValue ARMTargetLowering::LowerGlobalAddressELF(SDValue Op, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2182 | SelectionDAG &DAG) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2183 | EVT PtrVT = getPointerTy(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2184 | DebugLoc dl = Op.getDebugLoc(); |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2185 | const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2186 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| 2187 | if (RelocM == Reloc::PIC_) { |
Rafael Espindola | bb46f52 | 2009-01-15 20:18:42 +0000 | [diff] [blame] | 2188 | bool UseGOTOFF = GV->hasLocalLinkage() || GV->hasHiddenVisibility(); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2189 | ARMConstantPoolValue *CPV = |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2190 | ARMConstantPoolConstant::Create(GV, |
| 2191 | UseGOTOFF ? ARMCP::GOTOFF : ARMCP::GOT); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2192 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2193 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2194 | SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 2195 | CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2196 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2197 | false, false, false, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2198 | SDValue Chain = Result.getValue(1); |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 2199 | SDValue GOT = DAG.getGLOBAL_OFFSET_TABLE(PtrVT); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2200 | Result = DAG.getNode(ISD::ADD, dl, PtrVT, Result, GOT); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2201 | if (!UseGOTOFF) |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 2202 | Result = DAG.getLoad(PtrVT, dl, Chain, Result, |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2203 | MachinePointerInfo::getGOT(), |
| 2204 | false, false, false, 0); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2205 | return Result; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2206 | } |
| 2207 | |
| 2208 | // 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] | 2209 | // pair. This is always cheaper. |
| 2210 | if (Subtarget->useMovt()) { |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2211 | ++NumMovwMovt; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2212 | // FIXME: Once remat is capable of dealing with instructions with register |
| 2213 | // operands, expand this into two nodes. |
| 2214 | return DAG.getNode(ARMISD::Wrapper, dl, PtrVT, |
| 2215 | DAG.getTargetGlobalAddress(GV, dl, PtrVT)); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2216 | } else { |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2217 | SDValue CPAddr = DAG.getTargetConstantPool(GV, PtrVT, 4); |
| 2218 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| 2219 | return DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
| 2220 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2221 | false, false, false, 0); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2222 | } |
| 2223 | } |
| 2224 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2225 | SDValue ARMTargetLowering::LowerGlobalAddressDarwin(SDValue Op, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2226 | SelectionDAG &DAG) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2227 | EVT PtrVT = getPointerTy(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2228 | DebugLoc dl = Op.getDebugLoc(); |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2229 | const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2230 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2231 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2232 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2233 | |
Jakob Stoklund Olesen | 8f37a24 | 2012-01-07 20:49:15 +0000 | [diff] [blame] | 2234 | // FIXME: Enable this for static codegen when tool issues are fixed. Also |
| 2235 | // update ARMFastISel::ARMMaterializeGV. |
Evan Cheng | f31151f | 2011-10-26 01:17:44 +0000 | [diff] [blame] | 2236 | if (Subtarget->useMovt() && RelocM != Reloc::Static) { |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2237 | ++NumMovwMovt; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2238 | // FIXME: Once remat is capable of dealing with instructions with register |
| 2239 | // operands, expand this into two nodes. |
Evan Cheng | 53519f0 | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 2240 | if (RelocM == Reloc::Static) |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2241 | return DAG.getNode(ARMISD::Wrapper, dl, PtrVT, |
| 2242 | DAG.getTargetGlobalAddress(GV, dl, PtrVT)); |
| 2243 | |
Evan Cheng | 53519f0 | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 2244 | unsigned Wrapper = (RelocM == Reloc::PIC_) |
| 2245 | ? ARMISD::WrapperPIC : ARMISD::WrapperDYN; |
| 2246 | SDValue Result = DAG.getNode(Wrapper, dl, PtrVT, |
Evan Cheng | 9fe2009 | 2011-01-20 08:34:58 +0000 | [diff] [blame] | 2247 | DAG.getTargetGlobalAddress(GV, dl, PtrVT)); |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2248 | if (Subtarget->GVIsIndirectSymbol(GV, RelocM)) |
| 2249 | Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Result, |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2250 | MachinePointerInfo::getGOT(), |
| 2251 | false, false, false, 0); |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2252 | return Result; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2253 | } |
| 2254 | |
| 2255 | unsigned ARMPCLabelIndex = 0; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2256 | SDValue CPAddr; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2257 | if (RelocM == Reloc::Static) { |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2258 | CPAddr = DAG.getTargetConstantPool(GV, PtrVT, 4); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2259 | } else { |
| 2260 | ARMPCLabelIndex = AFI->createPICLabelUId(); |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 2261 | unsigned PCAdj = (RelocM != Reloc::PIC_) ? 0 : (Subtarget->isThumb()?4:8); |
| 2262 | ARMConstantPoolValue *CPV = |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2263 | ARMConstantPoolConstant::Create(GV, ARMPCLabelIndex, ARMCP::CPValue, |
| 2264 | PCAdj); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2265 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2266 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2267 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2268 | |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2269 | SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2270 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2271 | false, false, false, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2272 | SDValue Chain = Result.getValue(1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2273 | |
| 2274 | if (RelocM == Reloc::PIC_) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2275 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2276 | Result = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2277 | } |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 2278 | |
Evan Cheng | 63476a8 | 2009-09-03 07:04:02 +0000 | [diff] [blame] | 2279 | if (Subtarget->GVIsIndirectSymbol(GV, RelocM)) |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2280 | Result = DAG.getLoad(PtrVT, dl, Chain, Result, MachinePointerInfo::getGOT(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2281 | false, false, false, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2282 | |
| 2283 | return Result; |
| 2284 | } |
| 2285 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2286 | SDValue ARMTargetLowering::LowerGLOBAL_OFFSET_TABLE(SDValue Op, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2287 | SelectionDAG &DAG) const { |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2288 | assert(Subtarget->isTargetELF() && |
| 2289 | "GLOBAL OFFSET TABLE not implemented for non-ELF targets"); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2290 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2291 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2292 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2293 | EVT PtrVT = getPointerTy(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2294 | DebugLoc dl = Op.getDebugLoc(); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2295 | unsigned PCAdj = Subtarget->isThumb() ? 4 : 8; |
Bill Wendling | fe31e67 | 2011-10-01 08:58:29 +0000 | [diff] [blame] | 2296 | ARMConstantPoolValue *CPV = |
| 2297 | ARMConstantPoolSymbol::Create(*DAG.getContext(), "_GLOBAL_OFFSET_TABLE_", |
| 2298 | ARMPCLabelIndex, PCAdj); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2299 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2300 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 2301 | SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2302 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2303 | false, false, false, 0); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2304 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2305 | return DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2306 | } |
| 2307 | |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 2308 | SDValue |
Jim Grosbach | 23ff7cf | 2010-05-26 20:22:18 +0000 | [diff] [blame] | 2309 | ARMTargetLowering::LowerEH_SJLJ_SETJMP(SDValue Op, SelectionDAG &DAG) const { |
| 2310 | DebugLoc dl = Op.getDebugLoc(); |
Jim Grosbach | 0798edd | 2010-05-27 23:49:24 +0000 | [diff] [blame] | 2311 | SDValue Val = DAG.getConstant(0, MVT::i32); |
Bill Wendling | ce370cf | 2011-10-07 21:25:38 +0000 | [diff] [blame] | 2312 | return DAG.getNode(ARMISD::EH_SJLJ_SETJMP, dl, |
| 2313 | DAG.getVTList(MVT::i32, MVT::Other), Op.getOperand(0), |
Jim Grosbach | 23ff7cf | 2010-05-26 20:22:18 +0000 | [diff] [blame] | 2314 | Op.getOperand(1), Val); |
| 2315 | } |
| 2316 | |
| 2317 | SDValue |
Jim Grosbach | 5eb1951 | 2010-05-22 01:06:18 +0000 | [diff] [blame] | 2318 | ARMTargetLowering::LowerEH_SJLJ_LONGJMP(SDValue Op, SelectionDAG &DAG) const { |
| 2319 | DebugLoc dl = Op.getDebugLoc(); |
| 2320 | return DAG.getNode(ARMISD::EH_SJLJ_LONGJMP, dl, MVT::Other, Op.getOperand(0), |
| 2321 | Op.getOperand(1), DAG.getConstant(0, MVT::i32)); |
| 2322 | } |
| 2323 | |
| 2324 | SDValue |
Jim Grosbach | a87ded2 | 2010-02-08 23:22:00 +0000 | [diff] [blame] | 2325 | ARMTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG, |
Jim Grosbach | 7616b64 | 2010-06-16 23:45:49 +0000 | [diff] [blame] | 2326 | const ARMSubtarget *Subtarget) const { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2327 | unsigned IntNo = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 2328 | DebugLoc dl = Op.getDebugLoc(); |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 2329 | switch (IntNo) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2330 | default: return SDValue(); // Don't custom lower most intrinsics. |
Bob Wilson | 916afdb | 2009-08-04 00:25:01 +0000 | [diff] [blame] | 2331 | case Intrinsic::arm_thread_pointer: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2332 | EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
Bob Wilson | 916afdb | 2009-08-04 00:25:01 +0000 | [diff] [blame] | 2333 | return DAG.getNode(ARMISD::THREAD_POINTER, dl, PtrVT); |
| 2334 | } |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2335 | case Intrinsic::eh_sjlj_lsda: { |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2336 | MachineFunction &MF = DAG.getMachineFunction(); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2337 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2338 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2339 | EVT PtrVT = getPointerTy(); |
| 2340 | DebugLoc dl = Op.getDebugLoc(); |
| 2341 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| 2342 | SDValue CPAddr; |
| 2343 | unsigned PCAdj = (RelocM != Reloc::PIC_) |
| 2344 | ? 0 : (Subtarget->isThumb() ? 4 : 8); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2345 | ARMConstantPoolValue *CPV = |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2346 | ARMConstantPoolConstant::Create(MF.getFunction(), ARMPCLabelIndex, |
| 2347 | ARMCP::CPLSDA, PCAdj); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2348 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2349 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2350 | SDValue Result = |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2351 | DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2352 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2353 | false, false, false, 0); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2354 | |
| 2355 | if (RelocM == Reloc::PIC_) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2356 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2357 | Result = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
| 2358 | } |
| 2359 | return Result; |
| 2360 | } |
Evan Cheng | 92e3916 | 2011-03-29 23:06:19 +0000 | [diff] [blame] | 2361 | case Intrinsic::arm_neon_vmulls: |
| 2362 | case Intrinsic::arm_neon_vmullu: { |
| 2363 | unsigned NewOpc = (IntNo == Intrinsic::arm_neon_vmulls) |
| 2364 | ? ARMISD::VMULLs : ARMISD::VMULLu; |
| 2365 | return DAG.getNode(NewOpc, Op.getDebugLoc(), Op.getValueType(), |
| 2366 | Op.getOperand(1), Op.getOperand(2)); |
| 2367 | } |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 2368 | } |
| 2369 | } |
| 2370 | |
Jim Grosbach | 7c03dbd | 2009-12-14 21:24:16 +0000 | [diff] [blame] | 2371 | static SDValue LowerMEMBARRIER(SDValue Op, SelectionDAG &DAG, |
Jim Grosbach | 7616b64 | 2010-06-16 23:45:49 +0000 | [diff] [blame] | 2372 | const ARMSubtarget *Subtarget) { |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 2373 | DebugLoc dl = Op.getDebugLoc(); |
Bob Wilson | f74a429 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 2374 | if (!Subtarget->hasDataBarrier()) { |
| 2375 | // Some ARMv6 cpus can support data barriers with an mcr instruction. |
| 2376 | // Thumb1 and pre-v6 ARM mode use a libcall instead and should never get |
| 2377 | // here. |
Bob Wilson | 54f9256 | 2010-11-09 22:50:44 +0000 | [diff] [blame] | 2378 | assert(Subtarget->hasV6Ops() && !Subtarget->isThumb() && |
Evan Cheng | 11db068 | 2010-08-11 06:22:01 +0000 | [diff] [blame] | 2379 | "Unexpected ISD::MEMBARRIER encountered. Should be libcall!"); |
Bob Wilson | f74a429 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 2380 | return DAG.getNode(ARMISD::MEMBARRIER_MCR, dl, MVT::Other, Op.getOperand(0), |
Jim Grosbach | c73993b | 2010-06-17 01:37:00 +0000 | [diff] [blame] | 2381 | DAG.getConstant(0, MVT::i32)); |
Evan Cheng | 11db068 | 2010-08-11 06:22:01 +0000 | [diff] [blame] | 2382 | } |
Bob Wilson | f74a429 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 2383 | |
| 2384 | SDValue Op5 = Op.getOperand(5); |
| 2385 | bool isDeviceBarrier = cast<ConstantSDNode>(Op5)->getZExtValue() != 0; |
| 2386 | unsigned isLL = cast<ConstantSDNode>(Op.getOperand(1))->getZExtValue(); |
| 2387 | unsigned isLS = cast<ConstantSDNode>(Op.getOperand(2))->getZExtValue(); |
| 2388 | bool isOnlyStoreBarrier = (isLL == 0 && isLS == 0); |
| 2389 | |
| 2390 | ARM_MB::MemBOpt DMBOpt; |
| 2391 | if (isDeviceBarrier) |
| 2392 | DMBOpt = isOnlyStoreBarrier ? ARM_MB::ST : ARM_MB::SY; |
| 2393 | else |
| 2394 | DMBOpt = isOnlyStoreBarrier ? ARM_MB::ISHST : ARM_MB::ISH; |
| 2395 | return DAG.getNode(ARMISD::MEMBARRIER, dl, MVT::Other, Op.getOperand(0), |
| 2396 | DAG.getConstant(DMBOpt, MVT::i32)); |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 2397 | } |
| 2398 | |
Eli Friedman | 26689ac | 2011-08-03 21:06:02 +0000 | [diff] [blame] | 2399 | |
| 2400 | static SDValue LowerATOMIC_FENCE(SDValue Op, SelectionDAG &DAG, |
| 2401 | const ARMSubtarget *Subtarget) { |
| 2402 | // FIXME: handle "fence singlethread" more efficiently. |
| 2403 | DebugLoc dl = Op.getDebugLoc(); |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 2404 | if (!Subtarget->hasDataBarrier()) { |
| 2405 | // Some ARMv6 cpus can support data barriers with an mcr instruction. |
| 2406 | // Thumb1 and pre-v6 ARM mode use a libcall instead and should never get |
| 2407 | // here. |
| 2408 | assert(Subtarget->hasV6Ops() && !Subtarget->isThumb() && |
| 2409 | "Unexpected ISD::MEMBARRIER encountered. Should be libcall!"); |
Eli Friedman | 26689ac | 2011-08-03 21:06:02 +0000 | [diff] [blame] | 2410 | return DAG.getNode(ARMISD::MEMBARRIER_MCR, dl, MVT::Other, Op.getOperand(0), |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 2411 | DAG.getConstant(0, MVT::i32)); |
| 2412 | } |
| 2413 | |
Eli Friedman | 26689ac | 2011-08-03 21:06:02 +0000 | [diff] [blame] | 2414 | return DAG.getNode(ARMISD::MEMBARRIER, dl, MVT::Other, Op.getOperand(0), |
Eli Friedman | 989f61e | 2011-08-02 22:44:16 +0000 | [diff] [blame] | 2415 | DAG.getConstant(ARM_MB::ISH, MVT::i32)); |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 2416 | } |
| 2417 | |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2418 | static SDValue LowerPREFETCH(SDValue Op, SelectionDAG &DAG, |
| 2419 | const ARMSubtarget *Subtarget) { |
| 2420 | // ARM pre v5TE and Thumb1 does not have preload instructions. |
| 2421 | if (!(Subtarget->isThumb2() || |
| 2422 | (!Subtarget->isThumb1Only() && Subtarget->hasV5TEOps()))) |
| 2423 | // Just preserve the chain. |
| 2424 | return Op.getOperand(0); |
| 2425 | |
| 2426 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 2427 | unsigned isRead = ~cast<ConstantSDNode>(Op.getOperand(2))->getZExtValue() & 1; |
| 2428 | if (!isRead && |
| 2429 | (!Subtarget->hasV7Ops() || !Subtarget->hasMPExtension())) |
| 2430 | // ARMv7 with MP extension has PLDW. |
| 2431 | return Op.getOperand(0); |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2432 | |
Bruno Cardoso Lopes | 9a76733 | 2011-06-14 04:58:37 +0000 | [diff] [blame] | 2433 | unsigned isData = cast<ConstantSDNode>(Op.getOperand(4))->getZExtValue(); |
| 2434 | if (Subtarget->isThumb()) { |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2435 | // Invert the bits. |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 2436 | isRead = ~isRead & 1; |
Bruno Cardoso Lopes | 9a76733 | 2011-06-14 04:58:37 +0000 | [diff] [blame] | 2437 | isData = ~isData & 1; |
| 2438 | } |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2439 | |
| 2440 | return DAG.getNode(ARMISD::PRELOAD, dl, MVT::Other, Op.getOperand(0), |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 2441 | Op.getOperand(1), DAG.getConstant(isRead, MVT::i32), |
| 2442 | DAG.getConstant(isData, MVT::i32)); |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2443 | } |
| 2444 | |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 2445 | static SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) { |
| 2446 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2447 | ARMFunctionInfo *FuncInfo = MF.getInfo<ARMFunctionInfo>(); |
| 2448 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2449 | // vastart just stores the address of the VarArgsFrameIndex slot into the |
| 2450 | // memory location argument. |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2451 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2452 | EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 2453 | SDValue FR = DAG.getFrameIndex(FuncInfo->getVarArgsFrameIndex(), PtrVT); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 2454 | const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue(); |
Chris Lattner | fc448ff | 2010-09-21 18:51:21 +0000 | [diff] [blame] | 2455 | return DAG.getStore(Op.getOperand(0), dl, FR, Op.getOperand(1), |
| 2456 | MachinePointerInfo(SV), false, false, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2457 | } |
| 2458 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2459 | SDValue |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2460 | ARMTargetLowering::GetF64FormalArgument(CCValAssign &VA, CCValAssign &NextVA, |
| 2461 | SDValue &Root, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2462 | DebugLoc dl) const { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2463 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2464 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2465 | |
Craig Topper | 44d2382 | 2012-02-22 05:59:10 +0000 | [diff] [blame] | 2466 | const TargetRegisterClass *RC; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 2467 | if (AFI->isThumb1OnlyFunction()) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 2468 | RC = &ARM::tGPRRegClass; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2469 | else |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 2470 | RC = &ARM::GPRRegClass; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2471 | |
| 2472 | // Transform the arguments stored in physical registers into virtual ones. |
Devang Patel | 68e6bee | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 2473 | unsigned Reg = MF.addLiveIn(VA.getLocReg(), RC); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2474 | SDValue ArgValue = DAG.getCopyFromReg(Root, dl, Reg, MVT::i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2475 | |
| 2476 | SDValue ArgValue2; |
| 2477 | if (NextVA.isMemLoc()) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2478 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
Evan Cheng | ed2ae13 | 2010-07-03 00:40:23 +0000 | [diff] [blame] | 2479 | int FI = MFI->CreateFixedObject(4, NextVA.getLocMemOffset(), true); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2480 | |
| 2481 | // Create load node to retrieve arguments from the stack. |
| 2482 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2483 | ArgValue2 = DAG.getLoad(MVT::i32, dl, Root, FIN, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2484 | MachinePointerInfo::getFixedStack(FI), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2485 | false, false, false, 0); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2486 | } else { |
Devang Patel | 68e6bee | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 2487 | Reg = MF.addLiveIn(NextVA.getLocReg(), RC); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2488 | ArgValue2 = DAG.getCopyFromReg(Root, dl, Reg, MVT::i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2489 | } |
| 2490 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 2491 | return DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, ArgValue, ArgValue2); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2492 | } |
| 2493 | |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2494 | void |
| 2495 | ARMTargetLowering::computeRegArea(CCState &CCInfo, MachineFunction &MF, |
| 2496 | unsigned &VARegSize, unsigned &VARegSaveSize) |
| 2497 | const { |
| 2498 | unsigned NumGPRs; |
| 2499 | if (CCInfo.isFirstByValRegValid()) |
| 2500 | NumGPRs = ARM::R4 - CCInfo.getFirstByValReg(); |
| 2501 | else { |
| 2502 | unsigned int firstUnalloced; |
| 2503 | firstUnalloced = CCInfo.getFirstUnallocated(GPRArgRegs, |
| 2504 | sizeof(GPRArgRegs) / |
| 2505 | sizeof(GPRArgRegs[0])); |
| 2506 | NumGPRs = (firstUnalloced <= 3) ? (4 - firstUnalloced) : 0; |
| 2507 | } |
| 2508 | |
| 2509 | unsigned Align = MF.getTarget().getFrameLowering()->getStackAlignment(); |
| 2510 | VARegSize = NumGPRs * 4; |
| 2511 | VARegSaveSize = (VARegSize + Align - 1) & ~(Align - 1); |
| 2512 | } |
| 2513 | |
| 2514 | // The remaining GPRs hold either the beginning of variable-argument |
| 2515 | // data, or the beginning of an aggregate passed by value (usuall |
| 2516 | // byval). Either way, we allocate stack slots adjacent to the data |
| 2517 | // provided by our caller, and store the unallocated registers there. |
| 2518 | // If this is a variadic function, the va_list pointer will begin with |
| 2519 | // these values; otherwise, this reassembles a (byval) structure that |
| 2520 | // was split between registers and memory. |
| 2521 | void |
| 2522 | ARMTargetLowering::VarArgStyleRegisters(CCState &CCInfo, SelectionDAG &DAG, |
| 2523 | DebugLoc dl, SDValue &Chain, |
| 2524 | unsigned ArgOffset) const { |
| 2525 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2526 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 2527 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2528 | unsigned firstRegToSaveIndex; |
| 2529 | if (CCInfo.isFirstByValRegValid()) |
| 2530 | firstRegToSaveIndex = CCInfo.getFirstByValReg() - ARM::R0; |
| 2531 | else { |
| 2532 | firstRegToSaveIndex = CCInfo.getFirstUnallocated |
| 2533 | (GPRArgRegs, sizeof(GPRArgRegs) / sizeof(GPRArgRegs[0])); |
| 2534 | } |
| 2535 | |
| 2536 | unsigned VARegSize, VARegSaveSize; |
| 2537 | computeRegArea(CCInfo, MF, VARegSize, VARegSaveSize); |
| 2538 | if (VARegSaveSize) { |
| 2539 | // If this function is vararg, store any remaining integer argument regs |
| 2540 | // to their spots on the stack so that they may be loaded by deferencing |
| 2541 | // the result of va_next. |
| 2542 | AFI->setVarArgsRegSaveSize(VARegSaveSize); |
Eric Christopher | 5ac179c | 2011-04-29 23:12:01 +0000 | [diff] [blame] | 2543 | AFI->setVarArgsFrameIndex(MFI->CreateFixedObject(VARegSaveSize, |
| 2544 | ArgOffset + VARegSaveSize |
| 2545 | - VARegSize, |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2546 | false)); |
| 2547 | SDValue FIN = DAG.getFrameIndex(AFI->getVarArgsFrameIndex(), |
| 2548 | getPointerTy()); |
| 2549 | |
| 2550 | SmallVector<SDValue, 4> MemOps; |
| 2551 | for (; firstRegToSaveIndex < 4; ++firstRegToSaveIndex) { |
Craig Topper | 44d2382 | 2012-02-22 05:59:10 +0000 | [diff] [blame] | 2552 | const TargetRegisterClass *RC; |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2553 | if (AFI->isThumb1OnlyFunction()) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 2554 | RC = &ARM::tGPRRegClass; |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2555 | else |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 2556 | RC = &ARM::GPRRegClass; |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2557 | |
| 2558 | unsigned VReg = MF.addLiveIn(GPRArgRegs[firstRegToSaveIndex], RC); |
| 2559 | SDValue Val = DAG.getCopyFromReg(Chain, dl, VReg, MVT::i32); |
| 2560 | SDValue Store = |
| 2561 | DAG.getStore(Val.getValue(1), dl, Val, FIN, |
Eric Christopher | 5ac179c | 2011-04-29 23:12:01 +0000 | [diff] [blame] | 2562 | MachinePointerInfo::getFixedStack(AFI->getVarArgsFrameIndex()), |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2563 | false, false, 0); |
| 2564 | MemOps.push_back(Store); |
| 2565 | FIN = DAG.getNode(ISD::ADD, dl, getPointerTy(), FIN, |
| 2566 | DAG.getConstant(4, getPointerTy())); |
| 2567 | } |
| 2568 | if (!MemOps.empty()) |
| 2569 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, |
| 2570 | &MemOps[0], MemOps.size()); |
| 2571 | } else |
| 2572 | // This will point to the next argument passed via stack. |
| 2573 | AFI->setVarArgsFrameIndex(MFI->CreateFixedObject(4, ArgOffset, true)); |
| 2574 | } |
| 2575 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2576 | SDValue |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2577 | ARMTargetLowering::LowerFormalArguments(SDValue Chain, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 2578 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2579 | const SmallVectorImpl<ISD::InputArg> |
| 2580 | &Ins, |
| 2581 | DebugLoc dl, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2582 | SmallVectorImpl<SDValue> &InVals) |
| 2583 | const { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2584 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2585 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 2586 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2587 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2588 | |
| 2589 | // Assign locations to all of the incoming arguments. |
| 2590 | SmallVector<CCValAssign, 16> ArgLocs; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 2591 | ARMCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), |
| 2592 | getTargetMachine(), ArgLocs, *DAG.getContext(), Prologue); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2593 | CCInfo.AnalyzeFormalArguments(Ins, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 2594 | CCAssignFnForNode(CallConv, /* Return*/ false, |
| 2595 | isVarArg)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2596 | |
| 2597 | SmallVector<SDValue, 16> ArgValues; |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2598 | int lastInsIndex = -1; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2599 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2600 | SDValue ArgValue; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2601 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| 2602 | CCValAssign &VA = ArgLocs[i]; |
| 2603 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 2604 | // Arguments stored in registers. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2605 | if (VA.isRegLoc()) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2606 | EVT RegVT = VA.getLocVT(); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2607 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2608 | if (VA.needsCustom()) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2609 | // f64 and vector types are split up into multiple registers or |
| 2610 | // combinations of registers and stack slots. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2611 | if (VA.getLocVT() == MVT::v2f64) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2612 | SDValue ArgValue1 = GetF64FormalArgument(VA, ArgLocs[++i], |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2613 | Chain, DAG, dl); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2614 | VA = ArgLocs[++i]; // skip ahead to next loc |
Bob Wilson | 6a234f0 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 2615 | SDValue ArgValue2; |
| 2616 | if (VA.isMemLoc()) { |
Evan Cheng | ed2ae13 | 2010-07-03 00:40:23 +0000 | [diff] [blame] | 2617 | int FI = MFI->CreateFixedObject(8, VA.getLocMemOffset(), true); |
Bob Wilson | 6a234f0 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 2618 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
| 2619 | ArgValue2 = DAG.getLoad(MVT::f64, dl, Chain, FIN, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2620 | MachinePointerInfo::getFixedStack(FI), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2621 | false, false, false, 0); |
Bob Wilson | 6a234f0 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 2622 | } else { |
| 2623 | ArgValue2 = GetF64FormalArgument(VA, ArgLocs[++i], |
| 2624 | Chain, DAG, dl); |
| 2625 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2626 | ArgValue = DAG.getNode(ISD::UNDEF, dl, MVT::v2f64); |
| 2627 | ArgValue = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2628 | ArgValue, ArgValue1, DAG.getIntPtrConstant(0)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2629 | ArgValue = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2630 | ArgValue, ArgValue2, DAG.getIntPtrConstant(1)); |
| 2631 | } else |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2632 | ArgValue = GetF64FormalArgument(VA, ArgLocs[++i], Chain, DAG, dl); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2633 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2634 | } else { |
Craig Topper | 44d2382 | 2012-02-22 05:59:10 +0000 | [diff] [blame] | 2635 | const TargetRegisterClass *RC; |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 2636 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2637 | if (RegVT == MVT::f32) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 2638 | RC = &ARM::SPRRegClass; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2639 | else if (RegVT == MVT::f64) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 2640 | RC = &ARM::DPRRegClass; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2641 | else if (RegVT == MVT::v2f64) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 2642 | RC = &ARM::QPRRegClass; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2643 | else if (RegVT == MVT::i32) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 2644 | RC = AFI->isThumb1OnlyFunction() ? |
| 2645 | (const TargetRegisterClass*)&ARM::tGPRRegClass : |
| 2646 | (const TargetRegisterClass*)&ARM::GPRRegClass; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2647 | else |
Anton Korobeynikov | 058c251 | 2009-08-05 20:15:19 +0000 | [diff] [blame] | 2648 | llvm_unreachable("RegVT not supported by FORMAL_ARGUMENTS Lowering"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2649 | |
| 2650 | // Transform the arguments in physical registers into virtual ones. |
Devang Patel | 68e6bee | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 2651 | unsigned Reg = MF.addLiveIn(VA.getLocReg(), RC); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2652 | ArgValue = DAG.getCopyFromReg(Chain, dl, Reg, RegVT); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2653 | } |
| 2654 | |
| 2655 | // If this is an 8 or 16-bit value, it is really passed promoted |
| 2656 | // to 32 bits. Insert an assert[sz]ext to capture this, then |
| 2657 | // truncate to the right size. |
| 2658 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 2659 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2660 | case CCValAssign::Full: break; |
| 2661 | case CCValAssign::BCvt: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2662 | ArgValue = DAG.getNode(ISD::BITCAST, dl, VA.getValVT(), ArgValue); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2663 | break; |
| 2664 | case CCValAssign::SExt: |
| 2665 | ArgValue = DAG.getNode(ISD::AssertSext, dl, RegVT, ArgValue, |
| 2666 | DAG.getValueType(VA.getValVT())); |
| 2667 | ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue); |
| 2668 | break; |
| 2669 | case CCValAssign::ZExt: |
| 2670 | ArgValue = DAG.getNode(ISD::AssertZext, dl, RegVT, ArgValue, |
| 2671 | DAG.getValueType(VA.getValVT())); |
| 2672 | ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue); |
| 2673 | break; |
| 2674 | } |
| 2675 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2676 | InVals.push_back(ArgValue); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2677 | |
| 2678 | } else { // VA.isRegLoc() |
| 2679 | |
| 2680 | // sanity check |
| 2681 | assert(VA.isMemLoc()); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2682 | assert(VA.getValVT() != MVT::i64 && "i64 should already be lowered"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2683 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2684 | int index = ArgLocs[i].getValNo(); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 2685 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2686 | // Some Ins[] entries become multiple ArgLoc[] entries. |
| 2687 | // Process them only once. |
| 2688 | if (index != lastInsIndex) |
| 2689 | { |
| 2690 | ISD::ArgFlagsTy Flags = Ins[index].Flags; |
Eric Christopher | 471e422 | 2011-06-08 23:55:35 +0000 | [diff] [blame] | 2691 | // FIXME: For now, all byval parameter objects are marked mutable. |
Eric Christopher | 5ac179c | 2011-04-29 23:12:01 +0000 | [diff] [blame] | 2692 | // This can be changed with more analysis. |
| 2693 | // In case of tail call optimization mark all arguments mutable. |
| 2694 | // Since they could be overwritten by lowering of arguments in case of |
| 2695 | // a tail call. |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2696 | if (Flags.isByVal()) { |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2697 | unsigned VARegSize, VARegSaveSize; |
| 2698 | computeRegArea(CCInfo, MF, VARegSize, VARegSaveSize); |
| 2699 | VarArgStyleRegisters(CCInfo, DAG, dl, Chain, 0); |
| 2700 | unsigned Bytes = Flags.getByValSize() - VARegSize; |
Evan Cheng | ee2e0e3 | 2011-03-30 23:44:13 +0000 | [diff] [blame] | 2701 | if (Bytes == 0) Bytes = 1; // Don't create zero-sized stack objects. |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2702 | int FI = MFI->CreateFixedObject(Bytes, |
| 2703 | VA.getLocMemOffset(), false); |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2704 | InVals.push_back(DAG.getFrameIndex(FI, getPointerTy())); |
| 2705 | } else { |
| 2706 | int FI = MFI->CreateFixedObject(VA.getLocVT().getSizeInBits()/8, |
| 2707 | VA.getLocMemOffset(), true); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2708 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2709 | // Create load nodes to retrieve arguments from the stack. |
| 2710 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
| 2711 | InVals.push_back(DAG.getLoad(VA.getValVT(), dl, Chain, FIN, |
| 2712 | MachinePointerInfo::getFixedStack(FI), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2713 | false, false, false, 0)); |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2714 | } |
| 2715 | lastInsIndex = index; |
| 2716 | } |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2717 | } |
| 2718 | } |
| 2719 | |
| 2720 | // varargs |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2721 | if (isVarArg) |
| 2722 | VarArgStyleRegisters(CCInfo, DAG, dl, Chain, CCInfo.getNextStackOffset()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2723 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2724 | return Chain; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2725 | } |
| 2726 | |
| 2727 | /// isFloatingPointZero - Return true if this is +0.0. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2728 | static bool isFloatingPointZero(SDValue Op) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2729 | if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(Op)) |
Dale Johannesen | eaf0894 | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 2730 | return CFP->getValueAPF().isPosZero(); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2731 | else if (ISD::isEXTLoad(Op.getNode()) || ISD::isNON_EXTLoad(Op.getNode())) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2732 | // Maybe this has already been legalized into the constant pool? |
| 2733 | if (Op.getOperand(1).getOpcode() == ARMISD::Wrapper) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2734 | SDValue WrapperOp = Op.getOperand(1).getOperand(0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2735 | if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(WrapperOp)) |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2736 | if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CP->getConstVal())) |
Dale Johannesen | eaf0894 | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 2737 | return CFP->getValueAPF().isPosZero(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2738 | } |
| 2739 | } |
| 2740 | return false; |
| 2741 | } |
| 2742 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2743 | /// Returns appropriate ARM CMP (cmp) and corresponding condition code for |
| 2744 | /// the given operands. |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 2745 | SDValue |
| 2746 | ARMTargetLowering::getARMCmp(SDValue LHS, SDValue RHS, ISD::CondCode CC, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2747 | SDValue &ARMcc, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2748 | DebugLoc dl) const { |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2749 | if (ConstantSDNode *RHSC = dyn_cast<ConstantSDNode>(RHS.getNode())) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2750 | unsigned C = RHSC->getZExtValue(); |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 2751 | if (!isLegalICmpImmediate(C)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2752 | // Constant does not fit, try adjusting it by one? |
| 2753 | switch (CC) { |
| 2754 | default: break; |
| 2755 | case ISD::SETLT: |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2756 | case ISD::SETGE: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 2757 | if (C != 0x80000000 && isLegalICmpImmediate(C-1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2758 | CC = (CC == ISD::SETLT) ? ISD::SETLE : ISD::SETGT; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2759 | RHS = DAG.getConstant(C-1, MVT::i32); |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2760 | } |
| 2761 | break; |
| 2762 | case ISD::SETULT: |
| 2763 | case ISD::SETUGE: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 2764 | if (C != 0 && isLegalICmpImmediate(C-1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2765 | CC = (CC == ISD::SETULT) ? ISD::SETULE : ISD::SETUGT; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2766 | RHS = DAG.getConstant(C-1, MVT::i32); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2767 | } |
| 2768 | break; |
| 2769 | case ISD::SETLE: |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2770 | case ISD::SETGT: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 2771 | if (C != 0x7fffffff && isLegalICmpImmediate(C+1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2772 | CC = (CC == ISD::SETLE) ? ISD::SETLT : ISD::SETGE; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2773 | RHS = DAG.getConstant(C+1, MVT::i32); |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2774 | } |
| 2775 | break; |
| 2776 | case ISD::SETULE: |
| 2777 | case ISD::SETUGT: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 2778 | if (C != 0xffffffff && isLegalICmpImmediate(C+1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2779 | CC = (CC == ISD::SETULE) ? ISD::SETULT : ISD::SETUGE; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2780 | RHS = DAG.getConstant(C+1, MVT::i32); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2781 | } |
| 2782 | break; |
| 2783 | } |
| 2784 | } |
| 2785 | } |
| 2786 | |
| 2787 | ARMCC::CondCodes CondCode = IntCCToARMCC(CC); |
Lauro Ramos Venancio | 9996663 | 2007-04-02 01:30:03 +0000 | [diff] [blame] | 2788 | ARMISD::NodeType CompareType; |
| 2789 | switch (CondCode) { |
| 2790 | default: |
| 2791 | CompareType = ARMISD::CMP; |
| 2792 | break; |
| 2793 | case ARMCC::EQ: |
| 2794 | case ARMCC::NE: |
David Goodwin | c0309b4 | 2009-06-29 15:33:01 +0000 | [diff] [blame] | 2795 | // Uses only Z Flag |
| 2796 | CompareType = ARMISD::CMPZ; |
Lauro Ramos Venancio | 9996663 | 2007-04-02 01:30:03 +0000 | [diff] [blame] | 2797 | break; |
| 2798 | } |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2799 | ARMcc = DAG.getConstant(CondCode, MVT::i32); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 2800 | return DAG.getNode(CompareType, dl, MVT::Glue, LHS, RHS); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2801 | } |
| 2802 | |
| 2803 | /// 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] | 2804 | SDValue |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2805 | ARMTargetLowering::getVFPCmp(SDValue LHS, SDValue RHS, SelectionDAG &DAG, |
Evan Cheng | 515fe3a | 2010-07-08 02:08:50 +0000 | [diff] [blame] | 2806 | DebugLoc dl) const { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2807 | SDValue Cmp; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2808 | if (!isFloatingPointZero(RHS)) |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 2809 | Cmp = DAG.getNode(ARMISD::CMPFP, dl, MVT::Glue, LHS, RHS); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2810 | else |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 2811 | Cmp = DAG.getNode(ARMISD::CMPFPw0, dl, MVT::Glue, LHS); |
| 2812 | return DAG.getNode(ARMISD::FMSTAT, dl, MVT::Glue, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2813 | } |
| 2814 | |
Bob Wilson | 79f56c9 | 2011-03-08 01:17:20 +0000 | [diff] [blame] | 2815 | /// duplicateCmp - Glue values can have only one use, so this function |
| 2816 | /// duplicates a comparison node. |
| 2817 | SDValue |
| 2818 | ARMTargetLowering::duplicateCmp(SDValue Cmp, SelectionDAG &DAG) const { |
| 2819 | unsigned Opc = Cmp.getOpcode(); |
| 2820 | DebugLoc DL = Cmp.getDebugLoc(); |
| 2821 | if (Opc == ARMISD::CMP || Opc == ARMISD::CMPZ) |
| 2822 | return DAG.getNode(Opc, DL, MVT::Glue, Cmp.getOperand(0),Cmp.getOperand(1)); |
| 2823 | |
| 2824 | assert(Opc == ARMISD::FMSTAT && "unexpected comparison operation"); |
| 2825 | Cmp = Cmp.getOperand(0); |
| 2826 | Opc = Cmp.getOpcode(); |
| 2827 | if (Opc == ARMISD::CMPFP) |
| 2828 | Cmp = DAG.getNode(Opc, DL, MVT::Glue, Cmp.getOperand(0),Cmp.getOperand(1)); |
| 2829 | else { |
| 2830 | assert(Opc == ARMISD::CMPFPw0 && "unexpected operand of FMSTAT"); |
| 2831 | Cmp = DAG.getNode(Opc, DL, MVT::Glue, Cmp.getOperand(0)); |
| 2832 | } |
| 2833 | return DAG.getNode(ARMISD::FMSTAT, DL, MVT::Glue, Cmp); |
| 2834 | } |
| 2835 | |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 2836 | SDValue ARMTargetLowering::LowerSELECT(SDValue Op, SelectionDAG &DAG) const { |
| 2837 | SDValue Cond = Op.getOperand(0); |
| 2838 | SDValue SelectTrue = Op.getOperand(1); |
| 2839 | SDValue SelectFalse = Op.getOperand(2); |
| 2840 | DebugLoc dl = Op.getDebugLoc(); |
| 2841 | |
| 2842 | // Convert: |
| 2843 | // |
| 2844 | // (select (cmov 1, 0, cond), t, f) -> (cmov t, f, cond) |
| 2845 | // (select (cmov 0, 1, cond), t, f) -> (cmov f, t, cond) |
| 2846 | // |
| 2847 | if (Cond.getOpcode() == ARMISD::CMOV && Cond.hasOneUse()) { |
| 2848 | const ConstantSDNode *CMOVTrue = |
| 2849 | dyn_cast<ConstantSDNode>(Cond.getOperand(0)); |
| 2850 | const ConstantSDNode *CMOVFalse = |
| 2851 | dyn_cast<ConstantSDNode>(Cond.getOperand(1)); |
| 2852 | |
| 2853 | if (CMOVTrue && CMOVFalse) { |
| 2854 | unsigned CMOVTrueVal = CMOVTrue->getZExtValue(); |
| 2855 | unsigned CMOVFalseVal = CMOVFalse->getZExtValue(); |
| 2856 | |
| 2857 | SDValue True; |
| 2858 | SDValue False; |
| 2859 | if (CMOVTrueVal == 1 && CMOVFalseVal == 0) { |
| 2860 | True = SelectTrue; |
| 2861 | False = SelectFalse; |
| 2862 | } else if (CMOVTrueVal == 0 && CMOVFalseVal == 1) { |
| 2863 | True = SelectFalse; |
| 2864 | False = SelectTrue; |
| 2865 | } |
| 2866 | |
| 2867 | if (True.getNode() && False.getNode()) { |
Evan Cheng | b936e30 | 2011-05-18 18:59:17 +0000 | [diff] [blame] | 2868 | EVT VT = Op.getValueType(); |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 2869 | SDValue ARMcc = Cond.getOperand(2); |
| 2870 | SDValue CCR = Cond.getOperand(3); |
Bob Wilson | 79f56c9 | 2011-03-08 01:17:20 +0000 | [diff] [blame] | 2871 | SDValue Cmp = duplicateCmp(Cond.getOperand(4), DAG); |
Evan Cheng | b936e30 | 2011-05-18 18:59:17 +0000 | [diff] [blame] | 2872 | assert(True.getValueType() == VT); |
| 2873 | return DAG.getNode(ARMISD::CMOV, dl, VT, True, False, ARMcc, CCR, Cmp); |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 2874 | } |
| 2875 | } |
| 2876 | } |
| 2877 | |
Dan Gohman | db95389 | 2012-02-24 00:09:36 +0000 | [diff] [blame] | 2878 | // ARM's BooleanContents value is UndefinedBooleanContent. Mask out the |
| 2879 | // undefined bits before doing a full-word comparison with zero. |
| 2880 | Cond = DAG.getNode(ISD::AND, dl, Cond.getValueType(), Cond, |
| 2881 | DAG.getConstant(1, Cond.getValueType())); |
| 2882 | |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 2883 | return DAG.getSelectCC(dl, Cond, |
| 2884 | DAG.getConstant(0, Cond.getValueType()), |
| 2885 | SelectTrue, SelectFalse, ISD::SETNE); |
| 2886 | } |
| 2887 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2888 | SDValue ARMTargetLowering::LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2889 | EVT VT = Op.getValueType(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2890 | SDValue LHS = Op.getOperand(0); |
| 2891 | SDValue RHS = Op.getOperand(1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2892 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(4))->get(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2893 | SDValue TrueVal = Op.getOperand(2); |
| 2894 | SDValue FalseVal = Op.getOperand(3); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2895 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2896 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2897 | if (LHS.getValueType() == MVT::i32) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2898 | SDValue ARMcc; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2899 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2900 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMcc, DAG, dl); |
Jim Grosbach | b04546f | 2011-09-13 20:30:37 +0000 | [diff] [blame] | 2901 | return DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, ARMcc, CCR,Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2902 | } |
| 2903 | |
| 2904 | ARMCC::CondCodes CondCode, CondCode2; |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 2905 | FPCCToARMCC(CC, CondCode, CondCode2); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2906 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2907 | SDValue ARMcc = DAG.getConstant(CondCode, MVT::i32); |
| 2908 | SDValue Cmp = getVFPCmp(LHS, RHS, DAG, dl); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2909 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2910 | SDValue Result = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2911 | ARMcc, CCR, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2912 | if (CondCode2 != ARMCC::AL) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2913 | SDValue ARMcc2 = DAG.getConstant(CondCode2, MVT::i32); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2914 | // FIXME: Needs another CMP because flag can have but one use. |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2915 | SDValue Cmp2 = getVFPCmp(LHS, RHS, DAG, dl); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2916 | Result = DAG.getNode(ARMISD::CMOV, dl, VT, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2917 | Result, TrueVal, ARMcc2, CCR, Cmp2); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2918 | } |
| 2919 | return Result; |
| 2920 | } |
| 2921 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2922 | /// canChangeToInt - Given the fp compare operand, return true if it is suitable |
| 2923 | /// to morph to an integer compare sequence. |
| 2924 | static bool canChangeToInt(SDValue Op, bool &SeenZero, |
| 2925 | const ARMSubtarget *Subtarget) { |
| 2926 | SDNode *N = Op.getNode(); |
| 2927 | if (!N->hasOneUse()) |
| 2928 | // Otherwise it requires moving the value from fp to integer registers. |
| 2929 | return false; |
| 2930 | if (!N->getNumValues()) |
| 2931 | return false; |
| 2932 | EVT VT = Op.getValueType(); |
| 2933 | if (VT != MVT::f32 && !Subtarget->isFPBrccSlow()) |
| 2934 | // f32 case is generally profitable. f64 case only makes sense when vcmpe + |
| 2935 | // vmrs are very slow, e.g. cortex-a8. |
| 2936 | return false; |
| 2937 | |
| 2938 | if (isFloatingPointZero(Op)) { |
| 2939 | SeenZero = true; |
| 2940 | return true; |
| 2941 | } |
| 2942 | return ISD::isNormalLoad(N); |
| 2943 | } |
| 2944 | |
| 2945 | static SDValue bitcastf32Toi32(SDValue Op, SelectionDAG &DAG) { |
| 2946 | if (isFloatingPointZero(Op)) |
| 2947 | return DAG.getConstant(0, MVT::i32); |
| 2948 | |
| 2949 | if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Op)) |
| 2950 | return DAG.getLoad(MVT::i32, Op.getDebugLoc(), |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2951 | Ld->getChain(), Ld->getBasePtr(), Ld->getPointerInfo(), |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2952 | Ld->isVolatile(), Ld->isNonTemporal(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2953 | Ld->isInvariant(), Ld->getAlignment()); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2954 | |
| 2955 | llvm_unreachable("Unknown VFP cmp argument!"); |
| 2956 | } |
| 2957 | |
| 2958 | static void expandf64Toi32(SDValue Op, SelectionDAG &DAG, |
| 2959 | SDValue &RetVal1, SDValue &RetVal2) { |
| 2960 | if (isFloatingPointZero(Op)) { |
| 2961 | RetVal1 = DAG.getConstant(0, MVT::i32); |
| 2962 | RetVal2 = DAG.getConstant(0, MVT::i32); |
| 2963 | return; |
| 2964 | } |
| 2965 | |
| 2966 | if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Op)) { |
| 2967 | SDValue Ptr = Ld->getBasePtr(); |
| 2968 | RetVal1 = DAG.getLoad(MVT::i32, Op.getDebugLoc(), |
| 2969 | Ld->getChain(), Ptr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2970 | Ld->getPointerInfo(), |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2971 | Ld->isVolatile(), Ld->isNonTemporal(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2972 | Ld->isInvariant(), Ld->getAlignment()); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2973 | |
| 2974 | EVT PtrType = Ptr.getValueType(); |
| 2975 | unsigned NewAlign = MinAlign(Ld->getAlignment(), 4); |
| 2976 | SDValue NewPtr = DAG.getNode(ISD::ADD, Op.getDebugLoc(), |
| 2977 | PtrType, Ptr, DAG.getConstant(4, PtrType)); |
| 2978 | RetVal2 = DAG.getLoad(MVT::i32, Op.getDebugLoc(), |
| 2979 | Ld->getChain(), NewPtr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2980 | Ld->getPointerInfo().getWithOffset(4), |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2981 | Ld->isVolatile(), Ld->isNonTemporal(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2982 | Ld->isInvariant(), NewAlign); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2983 | return; |
| 2984 | } |
| 2985 | |
| 2986 | llvm_unreachable("Unknown VFP cmp argument!"); |
| 2987 | } |
| 2988 | |
| 2989 | /// OptimizeVFPBrcond - With -enable-unsafe-fp-math, it's legal to optimize some |
| 2990 | /// f32 and even f64 comparisons to integer ones. |
| 2991 | SDValue |
| 2992 | ARMTargetLowering::OptimizeVFPBrcond(SDValue Op, SelectionDAG &DAG) const { |
| 2993 | SDValue Chain = Op.getOperand(0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2994 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get(); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2995 | SDValue LHS = Op.getOperand(2); |
| 2996 | SDValue RHS = Op.getOperand(3); |
| 2997 | SDValue Dest = Op.getOperand(4); |
| 2998 | DebugLoc dl = Op.getDebugLoc(); |
| 2999 | |
Evan Cheng | fc501a3 | 2012-03-01 23:27:13 +0000 | [diff] [blame] | 3000 | bool LHSSeenZero = false; |
| 3001 | bool LHSOk = canChangeToInt(LHS, LHSSeenZero, Subtarget); |
| 3002 | bool RHSSeenZero = false; |
| 3003 | bool RHSOk = canChangeToInt(RHS, RHSSeenZero, Subtarget); |
| 3004 | if (LHSOk && RHSOk && (LHSSeenZero || RHSSeenZero)) { |
Bob Wilson | 1b772f9 | 2011-03-08 01:17:16 +0000 | [diff] [blame] | 3005 | // If unsafe fp math optimization is enabled and there are no other uses of |
| 3006 | // 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] | 3007 | // to an integer comparison. |
| 3008 | if (CC == ISD::SETOEQ) |
| 3009 | CC = ISD::SETEQ; |
| 3010 | else if (CC == ISD::SETUNE) |
| 3011 | CC = ISD::SETNE; |
| 3012 | |
Evan Cheng | fc501a3 | 2012-03-01 23:27:13 +0000 | [diff] [blame] | 3013 | SDValue Mask = DAG.getConstant(0x7fffffff, MVT::i32); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3014 | SDValue ARMcc; |
| 3015 | if (LHS.getValueType() == MVT::f32) { |
Evan Cheng | fc501a3 | 2012-03-01 23:27:13 +0000 | [diff] [blame] | 3016 | LHS = DAG.getNode(ISD::AND, dl, MVT::i32, |
| 3017 | bitcastf32Toi32(LHS, DAG), Mask); |
| 3018 | RHS = DAG.getNode(ISD::AND, dl, MVT::i32, |
| 3019 | bitcastf32Toi32(RHS, DAG), Mask); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3020 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMcc, DAG, dl); |
| 3021 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| 3022 | return DAG.getNode(ARMISD::BRCOND, dl, MVT::Other, |
| 3023 | Chain, Dest, ARMcc, CCR, Cmp); |
| 3024 | } |
| 3025 | |
| 3026 | SDValue LHS1, LHS2; |
| 3027 | SDValue RHS1, RHS2; |
| 3028 | expandf64Toi32(LHS, DAG, LHS1, LHS2); |
| 3029 | expandf64Toi32(RHS, DAG, RHS1, RHS2); |
Evan Cheng | fc501a3 | 2012-03-01 23:27:13 +0000 | [diff] [blame] | 3030 | LHS2 = DAG.getNode(ISD::AND, dl, MVT::i32, LHS2, Mask); |
| 3031 | RHS2 = DAG.getNode(ISD::AND, dl, MVT::i32, RHS2, Mask); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3032 | ARMCC::CondCodes CondCode = IntCCToARMCC(CC); |
| 3033 | ARMcc = DAG.getConstant(CondCode, MVT::i32); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 3034 | SDVTList VTList = DAG.getVTList(MVT::Other, MVT::Glue); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3035 | SDValue Ops[] = { Chain, ARMcc, LHS1, LHS2, RHS1, RHS2, Dest }; |
| 3036 | return DAG.getNode(ARMISD::BCC_i64, dl, VTList, Ops, 7); |
| 3037 | } |
| 3038 | |
| 3039 | return SDValue(); |
| 3040 | } |
| 3041 | |
| 3042 | SDValue ARMTargetLowering::LowerBR_CC(SDValue Op, SelectionDAG &DAG) const { |
| 3043 | SDValue Chain = Op.getOperand(0); |
| 3044 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get(); |
| 3045 | SDValue LHS = Op.getOperand(2); |
| 3046 | SDValue RHS = Op.getOperand(3); |
| 3047 | SDValue Dest = Op.getOperand(4); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 3048 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3049 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3050 | if (LHS.getValueType() == MVT::i32) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3051 | SDValue ARMcc; |
| 3052 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMcc, DAG, dl); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3053 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3054 | return DAG.getNode(ARMISD::BRCOND, dl, MVT::Other, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3055 | Chain, Dest, ARMcc, CCR, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3056 | } |
| 3057 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3058 | assert(LHS.getValueType() == MVT::f32 || LHS.getValueType() == MVT::f64); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3059 | |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 3060 | if (getTargetMachine().Options.UnsafeFPMath && |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3061 | (CC == ISD::SETEQ || CC == ISD::SETOEQ || |
| 3062 | CC == ISD::SETNE || CC == ISD::SETUNE)) { |
| 3063 | SDValue Result = OptimizeVFPBrcond(Op, DAG); |
| 3064 | if (Result.getNode()) |
| 3065 | return Result; |
| 3066 | } |
| 3067 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3068 | ARMCC::CondCodes CondCode, CondCode2; |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 3069 | FPCCToARMCC(CC, CondCode, CondCode2); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3070 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3071 | SDValue ARMcc = DAG.getConstant(CondCode, MVT::i32); |
| 3072 | SDValue Cmp = getVFPCmp(LHS, RHS, DAG, dl); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3073 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 3074 | SDVTList VTList = DAG.getVTList(MVT::Other, MVT::Glue); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3075 | SDValue Ops[] = { Chain, Dest, ARMcc, CCR, Cmp }; |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 3076 | SDValue Res = DAG.getNode(ARMISD::BRCOND, dl, VTList, Ops, 5); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3077 | if (CondCode2 != ARMCC::AL) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3078 | ARMcc = DAG.getConstant(CondCode2, MVT::i32); |
| 3079 | SDValue Ops[] = { Res, Dest, ARMcc, CCR, Res.getValue(1) }; |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 3080 | Res = DAG.getNode(ARMISD::BRCOND, dl, VTList, Ops, 5); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3081 | } |
| 3082 | return Res; |
| 3083 | } |
| 3084 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 3085 | SDValue ARMTargetLowering::LowerBR_JT(SDValue Op, SelectionDAG &DAG) const { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3086 | SDValue Chain = Op.getOperand(0); |
| 3087 | SDValue Table = Op.getOperand(1); |
| 3088 | SDValue Index = Op.getOperand(2); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 3089 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3090 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3091 | EVT PTy = getPointerTy(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3092 | JumpTableSDNode *JT = cast<JumpTableSDNode>(Table); |
| 3093 | ARMFunctionInfo *AFI = DAG.getMachineFunction().getInfo<ARMFunctionInfo>(); |
Bob Wilson | 3eadf00 | 2009-07-14 18:44:34 +0000 | [diff] [blame] | 3094 | SDValue UId = DAG.getConstant(AFI->createJumpTableUId(), PTy); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3095 | SDValue JTI = DAG.getTargetJumpTable(JT->getIndex(), PTy); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3096 | Table = DAG.getNode(ARMISD::WrapperJT, dl, MVT::i32, JTI, UId); |
Evan Cheng | e7c329b | 2009-07-28 20:53:24 +0000 | [diff] [blame] | 3097 | Index = DAG.getNode(ISD::MUL, dl, PTy, Index, DAG.getConstant(4, PTy)); |
| 3098 | SDValue Addr = DAG.getNode(ISD::ADD, dl, PTy, Index, Table); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3099 | if (Subtarget->isThumb2()) { |
| 3100 | // Thumb2 uses a two-level jump. That is, it jumps into the jump table |
| 3101 | // which does another jump to the destination. This also makes it easier |
| 3102 | // to translate it to TBB / TBH later. |
| 3103 | // FIXME: This might not work if the function is extremely large. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3104 | return DAG.getNode(ARMISD::BR2_JT, dl, MVT::Other, Chain, |
Evan Cheng | 5657c01 | 2009-07-29 02:18:14 +0000 | [diff] [blame] | 3105 | Addr, Op.getOperand(2), JTI, UId); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3106 | } |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3107 | if (getTargetMachine().getRelocationModel() == Reloc::PIC_) { |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 3108 | Addr = DAG.getLoad((EVT)MVT::i32, dl, Chain, Addr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 3109 | MachinePointerInfo::getJumpTable(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3110 | false, false, false, 0); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3111 | Chain = Addr.getValue(1); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 3112 | Addr = DAG.getNode(ISD::ADD, dl, PTy, Addr, Table); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3113 | 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] | 3114 | } else { |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 3115 | Addr = DAG.getLoad(PTy, dl, Chain, Addr, |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3116 | MachinePointerInfo::getJumpTable(), |
| 3117 | false, false, false, 0); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3118 | Chain = Addr.getValue(1); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3119 | 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] | 3120 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3121 | } |
| 3122 | |
Eli Friedman | 14e809c | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3123 | static SDValue LowerVectorFP_TO_INT(SDValue Op, SelectionDAG &DAG) { |
James Molloy | 873fd5f | 2012-02-20 09:24:05 +0000 | [diff] [blame] | 3124 | EVT VT = Op.getValueType(); |
| 3125 | DebugLoc dl = Op.getDebugLoc(); |
Eli Friedman | 14e809c | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3126 | |
James Molloy | 873fd5f | 2012-02-20 09:24:05 +0000 | [diff] [blame] | 3127 | if (Op.getValueType().getVectorElementType() == MVT::i32) { |
| 3128 | if (Op.getOperand(0).getValueType().getVectorElementType() == MVT::f32) |
| 3129 | return Op; |
| 3130 | return DAG.UnrollVectorOp(Op.getNode()); |
| 3131 | } |
| 3132 | |
| 3133 | assert(Op.getOperand(0).getValueType() == MVT::v4f32 && |
| 3134 | "Invalid type for custom lowering!"); |
| 3135 | if (VT != MVT::v4i16) |
| 3136 | return DAG.UnrollVectorOp(Op.getNode()); |
| 3137 | |
| 3138 | Op = DAG.getNode(Op.getOpcode(), dl, MVT::v4i32, Op.getOperand(0)); |
| 3139 | return DAG.getNode(ISD::TRUNCATE, dl, VT, Op); |
Eli Friedman | 14e809c | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3140 | } |
| 3141 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3142 | static SDValue LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG) { |
Eli Friedman | 14e809c | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3143 | EVT VT = Op.getValueType(); |
| 3144 | if (VT.isVector()) |
| 3145 | return LowerVectorFP_TO_INT(Op, DAG); |
| 3146 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3147 | DebugLoc dl = Op.getDebugLoc(); |
| 3148 | unsigned Opc; |
| 3149 | |
| 3150 | switch (Op.getOpcode()) { |
Craig Topper | bc21981 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 3151 | default: llvm_unreachable("Invalid opcode!"); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3152 | case ISD::FP_TO_SINT: |
| 3153 | Opc = ARMISD::FTOSI; |
| 3154 | break; |
| 3155 | case ISD::FP_TO_UINT: |
| 3156 | Opc = ARMISD::FTOUI; |
| 3157 | break; |
| 3158 | } |
| 3159 | Op = DAG.getNode(Opc, dl, MVT::f32, Op.getOperand(0)); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3160 | return DAG.getNode(ISD::BITCAST, dl, MVT::i32, Op); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3161 | } |
| 3162 | |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 3163 | static SDValue LowerVectorINT_TO_FP(SDValue Op, SelectionDAG &DAG) { |
| 3164 | EVT VT = Op.getValueType(); |
| 3165 | DebugLoc dl = Op.getDebugLoc(); |
| 3166 | |
Eli Friedman | 14e809c | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3167 | if (Op.getOperand(0).getValueType().getVectorElementType() == MVT::i32) { |
| 3168 | if (VT.getVectorElementType() == MVT::f32) |
| 3169 | return Op; |
| 3170 | return DAG.UnrollVectorOp(Op.getNode()); |
| 3171 | } |
| 3172 | |
Duncan Sands | 1f6a329 | 2011-08-12 14:54:45 +0000 | [diff] [blame] | 3173 | assert(Op.getOperand(0).getValueType() == MVT::v4i16 && |
| 3174 | "Invalid type for custom lowering!"); |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 3175 | if (VT != MVT::v4f32) |
| 3176 | return DAG.UnrollVectorOp(Op.getNode()); |
| 3177 | |
| 3178 | unsigned CastOpc; |
| 3179 | unsigned Opc; |
| 3180 | switch (Op.getOpcode()) { |
Craig Topper | bc21981 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 3181 | default: llvm_unreachable("Invalid opcode!"); |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 3182 | case ISD::SINT_TO_FP: |
| 3183 | CastOpc = ISD::SIGN_EXTEND; |
| 3184 | Opc = ISD::SINT_TO_FP; |
| 3185 | break; |
| 3186 | case ISD::UINT_TO_FP: |
| 3187 | CastOpc = ISD::ZERO_EXTEND; |
| 3188 | Opc = ISD::UINT_TO_FP; |
| 3189 | break; |
| 3190 | } |
| 3191 | |
| 3192 | Op = DAG.getNode(CastOpc, dl, MVT::v4i32, Op.getOperand(0)); |
| 3193 | return DAG.getNode(Opc, dl, VT, Op); |
| 3194 | } |
| 3195 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3196 | static SDValue LowerINT_TO_FP(SDValue Op, SelectionDAG &DAG) { |
| 3197 | EVT VT = Op.getValueType(); |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 3198 | if (VT.isVector()) |
| 3199 | return LowerVectorINT_TO_FP(Op, DAG); |
| 3200 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3201 | DebugLoc dl = Op.getDebugLoc(); |
| 3202 | unsigned Opc; |
| 3203 | |
| 3204 | switch (Op.getOpcode()) { |
Craig Topper | bc21981 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 3205 | default: llvm_unreachable("Invalid opcode!"); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3206 | case ISD::SINT_TO_FP: |
| 3207 | Opc = ARMISD::SITOF; |
| 3208 | break; |
| 3209 | case ISD::UINT_TO_FP: |
| 3210 | Opc = ARMISD::UITOF; |
| 3211 | break; |
| 3212 | } |
| 3213 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3214 | Op = DAG.getNode(ISD::BITCAST, dl, MVT::f32, Op.getOperand(0)); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3215 | return DAG.getNode(Opc, dl, VT, Op); |
| 3216 | } |
| 3217 | |
Evan Cheng | 515fe3a | 2010-07-08 02:08:50 +0000 | [diff] [blame] | 3218 | SDValue ARMTargetLowering::LowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3219 | // Implement fcopysign with a fabs and a conditional fneg. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3220 | SDValue Tmp0 = Op.getOperand(0); |
| 3221 | SDValue Tmp1 = Op.getOperand(1); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 3222 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3223 | EVT VT = Op.getValueType(); |
| 3224 | EVT SrcVT = Tmp1.getValueType(); |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3225 | bool InGPR = Tmp0.getOpcode() == ISD::BITCAST || |
| 3226 | Tmp0.getOpcode() == ARMISD::VMOVDRR; |
| 3227 | bool UseNEON = !InGPR && Subtarget->hasNEON(); |
| 3228 | |
| 3229 | if (UseNEON) { |
| 3230 | // Use VBSL to copy the sign bit. |
| 3231 | unsigned EncodedVal = ARM_AM::createNEONModImm(0x6, 0x80); |
| 3232 | SDValue Mask = DAG.getNode(ARMISD::VMOVIMM, dl, MVT::v2i32, |
| 3233 | DAG.getTargetConstant(EncodedVal, MVT::i32)); |
| 3234 | EVT OpVT = (VT == MVT::f32) ? MVT::v2i32 : MVT::v1i64; |
| 3235 | if (VT == MVT::f64) |
| 3236 | Mask = DAG.getNode(ARMISD::VSHL, dl, OpVT, |
| 3237 | DAG.getNode(ISD::BITCAST, dl, OpVT, Mask), |
| 3238 | DAG.getConstant(32, MVT::i32)); |
| 3239 | else /*if (VT == MVT::f32)*/ |
| 3240 | Tmp0 = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, MVT::v2f32, Tmp0); |
| 3241 | if (SrcVT == MVT::f32) { |
| 3242 | Tmp1 = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, MVT::v2f32, Tmp1); |
| 3243 | if (VT == MVT::f64) |
| 3244 | Tmp1 = DAG.getNode(ARMISD::VSHL, dl, OpVT, |
| 3245 | DAG.getNode(ISD::BITCAST, dl, OpVT, Tmp1), |
| 3246 | DAG.getConstant(32, MVT::i32)); |
Evan Cheng | 9eec66e | 2011-04-15 01:31:00 +0000 | [diff] [blame] | 3247 | } else if (VT == MVT::f32) |
| 3248 | Tmp1 = DAG.getNode(ARMISD::VSHRu, dl, MVT::v1i64, |
| 3249 | DAG.getNode(ISD::BITCAST, dl, MVT::v1i64, Tmp1), |
| 3250 | DAG.getConstant(32, MVT::i32)); |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3251 | Tmp0 = DAG.getNode(ISD::BITCAST, dl, OpVT, Tmp0); |
| 3252 | Tmp1 = DAG.getNode(ISD::BITCAST, dl, OpVT, Tmp1); |
| 3253 | |
| 3254 | SDValue AllOnes = DAG.getTargetConstant(ARM_AM::createNEONModImm(0xe, 0xff), |
| 3255 | MVT::i32); |
| 3256 | AllOnes = DAG.getNode(ARMISD::VMOVIMM, dl, MVT::v8i8, AllOnes); |
| 3257 | SDValue MaskNot = DAG.getNode(ISD::XOR, dl, OpVT, Mask, |
| 3258 | DAG.getNode(ISD::BITCAST, dl, OpVT, AllOnes)); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 3259 | |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3260 | SDValue Res = DAG.getNode(ISD::OR, dl, OpVT, |
| 3261 | DAG.getNode(ISD::AND, dl, OpVT, Tmp1, Mask), |
| 3262 | DAG.getNode(ISD::AND, dl, OpVT, Tmp0, MaskNot)); |
Evan Cheng | c24ab5c | 2011-02-28 18:45:27 +0000 | [diff] [blame] | 3263 | if (VT == MVT::f32) { |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3264 | Res = DAG.getNode(ISD::BITCAST, dl, MVT::v2f32, Res); |
| 3265 | Res = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f32, Res, |
| 3266 | DAG.getConstant(0, MVT::i32)); |
| 3267 | } else { |
| 3268 | Res = DAG.getNode(ISD::BITCAST, dl, MVT::f64, Res); |
| 3269 | } |
| 3270 | |
| 3271 | return Res; |
| 3272 | } |
Evan Cheng | c143dd4 | 2011-02-11 02:28:55 +0000 | [diff] [blame] | 3273 | |
| 3274 | // Bitcast operand 1 to i32. |
| 3275 | if (SrcVT == MVT::f64) |
| 3276 | Tmp1 = DAG.getNode(ARMISD::VMOVRRD, dl, DAG.getVTList(MVT::i32, MVT::i32), |
| 3277 | &Tmp1, 1).getValue(1); |
| 3278 | Tmp1 = DAG.getNode(ISD::BITCAST, dl, MVT::i32, Tmp1); |
| 3279 | |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3280 | // Or in the signbit with integer operations. |
| 3281 | SDValue Mask1 = DAG.getConstant(0x80000000, MVT::i32); |
| 3282 | SDValue Mask2 = DAG.getConstant(0x7fffffff, MVT::i32); |
| 3283 | Tmp1 = DAG.getNode(ISD::AND, dl, MVT::i32, Tmp1, Mask1); |
| 3284 | if (VT == MVT::f32) { |
| 3285 | Tmp0 = DAG.getNode(ISD::AND, dl, MVT::i32, |
| 3286 | DAG.getNode(ISD::BITCAST, dl, MVT::i32, Tmp0), Mask2); |
| 3287 | return DAG.getNode(ISD::BITCAST, dl, MVT::f32, |
| 3288 | DAG.getNode(ISD::OR, dl, MVT::i32, Tmp0, Tmp1)); |
Evan Cheng | c143dd4 | 2011-02-11 02:28:55 +0000 | [diff] [blame] | 3289 | } |
| 3290 | |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3291 | // f64: Or the high part with signbit and then combine two parts. |
| 3292 | Tmp0 = DAG.getNode(ARMISD::VMOVRRD, dl, DAG.getVTList(MVT::i32, MVT::i32), |
| 3293 | &Tmp0, 1); |
| 3294 | SDValue Lo = Tmp0.getValue(0); |
| 3295 | SDValue Hi = DAG.getNode(ISD::AND, dl, MVT::i32, Tmp0.getValue(1), Mask2); |
| 3296 | Hi = DAG.getNode(ISD::OR, dl, MVT::i32, Hi, Tmp1); |
| 3297 | return DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3298 | } |
| 3299 | |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3300 | SDValue ARMTargetLowering::LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const{ |
| 3301 | MachineFunction &MF = DAG.getMachineFunction(); |
| 3302 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 3303 | MFI->setReturnAddressIsTaken(true); |
| 3304 | |
| 3305 | EVT VT = Op.getValueType(); |
| 3306 | DebugLoc dl = Op.getDebugLoc(); |
| 3307 | unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
| 3308 | if (Depth) { |
| 3309 | SDValue FrameAddr = LowerFRAMEADDR(Op, DAG); |
| 3310 | SDValue Offset = DAG.getConstant(4, MVT::i32); |
| 3311 | return DAG.getLoad(VT, dl, DAG.getEntryNode(), |
| 3312 | DAG.getNode(ISD::ADD, dl, VT, FrameAddr, Offset), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3313 | MachinePointerInfo(), false, false, false, 0); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3314 | } |
| 3315 | |
| 3316 | // 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] | 3317 | unsigned Reg = MF.addLiveIn(ARM::LR, getRegClassFor(MVT::i32)); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3318 | return DAG.getCopyFromReg(DAG.getEntryNode(), dl, Reg, VT); |
| 3319 | } |
| 3320 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 3321 | SDValue ARMTargetLowering::LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const { |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3322 | MachineFrameInfo *MFI = DAG.getMachineFunction().getFrameInfo(); |
| 3323 | MFI->setFrameAddressIsTaken(true); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3324 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3325 | EVT VT = Op.getValueType(); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3326 | DebugLoc dl = Op.getDebugLoc(); // FIXME probably not meaningful |
| 3327 | unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
Evan Cheng | cd82861 | 2009-06-18 23:14:30 +0000 | [diff] [blame] | 3328 | unsigned FrameReg = (Subtarget->isThumb() || Subtarget->isTargetDarwin()) |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3329 | ? ARM::R7 : ARM::R11; |
| 3330 | SDValue FrameAddr = DAG.getCopyFromReg(DAG.getEntryNode(), dl, FrameReg, VT); |
| 3331 | while (Depth--) |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 3332 | FrameAddr = DAG.getLoad(VT, dl, DAG.getEntryNode(), FrameAddr, |
| 3333 | MachinePointerInfo(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3334 | false, false, false, 0); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3335 | return FrameAddr; |
| 3336 | } |
| 3337 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3338 | /// ExpandBITCAST - If the target supports VFP, this function is called to |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3339 | /// expand a bit convert where either the source or destination type is i64 to |
| 3340 | /// use a VMOVDRR or VMOVRRD node. This should not be done when the non-i64 |
| 3341 | /// operand type is illegal (e.g., v2f32 for a target that doesn't support |
| 3342 | /// vectors), since the legalizer won't know what to do with that. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3343 | static SDValue ExpandBITCAST(SDNode *N, SelectionDAG &DAG) { |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3344 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 3345 | DebugLoc dl = N->getDebugLoc(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3346 | SDValue Op = N->getOperand(0); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 3347 | |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3348 | // This function is only supposed to be called for i64 types, either as the |
| 3349 | // source or destination of the bit convert. |
| 3350 | EVT SrcVT = Op.getValueType(); |
| 3351 | EVT DstVT = N->getValueType(0); |
| 3352 | assert((SrcVT == MVT::i64 || DstVT == MVT::i64) && |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3353 | "ExpandBITCAST called for non-i64 type"); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 3354 | |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3355 | // Turn i64->f64 into VMOVDRR. |
| 3356 | if (SrcVT == MVT::i64 && TLI.isTypeLegal(DstVT)) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3357 | SDValue Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Op, |
| 3358 | DAG.getConstant(0, MVT::i32)); |
| 3359 | SDValue Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Op, |
| 3360 | DAG.getConstant(1, MVT::i32)); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3361 | return DAG.getNode(ISD::BITCAST, dl, DstVT, |
Bob Wilson | 1114f56 | 2010-06-11 22:45:25 +0000 | [diff] [blame] | 3362 | DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi)); |
Evan Cheng | c7c7729 | 2008-11-04 19:57:48 +0000 | [diff] [blame] | 3363 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3364 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 3365 | // Turn f64->i64 into VMOVRRD. |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3366 | if (DstVT == MVT::i64 && TLI.isTypeLegal(SrcVT)) { |
| 3367 | SDValue Cvt = DAG.getNode(ARMISD::VMOVRRD, dl, |
| 3368 | DAG.getVTList(MVT::i32, MVT::i32), &Op, 1); |
| 3369 | // Merge the pieces into a single i64 value. |
| 3370 | return DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Cvt, Cvt.getValue(1)); |
| 3371 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3372 | |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3373 | return SDValue(); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3374 | } |
| 3375 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3376 | /// getZeroVector - Returns a vector of specified type with all zero elements. |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3377 | /// Zero vectors are used to represent vector negation and in those cases |
| 3378 | /// will be implemented with the NEON VNEG instruction. However, VNEG does |
| 3379 | /// not support i64 elements, so sometimes the zero vectors will need to be |
| 3380 | /// explicitly constructed. Regardless, use a canonical VMOV to create the |
| 3381 | /// zero vector. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3382 | static SDValue getZeroVector(EVT VT, SelectionDAG &DAG, DebugLoc dl) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3383 | assert(VT.isVector() && "Expected a vector type"); |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3384 | // The canonical modified immediate encoding of a zero vector is....0! |
| 3385 | SDValue EncodedVal = DAG.getTargetConstant(0, MVT::i32); |
| 3386 | EVT VmovVT = VT.is128BitVector() ? MVT::v4i32 : MVT::v2i32; |
| 3387 | SDValue Vmov = DAG.getNode(ARMISD::VMOVIMM, dl, VmovVT, EncodedVal); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3388 | return DAG.getNode(ISD::BITCAST, dl, VT, Vmov); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3389 | } |
| 3390 | |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3391 | /// LowerShiftRightParts - Lower SRA_PARTS, which returns two |
| 3392 | /// 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] | 3393 | SDValue ARMTargetLowering::LowerShiftRightParts(SDValue Op, |
| 3394 | SelectionDAG &DAG) const { |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3395 | assert(Op.getNumOperands() == 3 && "Not a double-shift!"); |
| 3396 | EVT VT = Op.getValueType(); |
| 3397 | unsigned VTBits = VT.getSizeInBits(); |
| 3398 | DebugLoc dl = Op.getDebugLoc(); |
| 3399 | SDValue ShOpLo = Op.getOperand(0); |
| 3400 | SDValue ShOpHi = Op.getOperand(1); |
| 3401 | SDValue ShAmt = Op.getOperand(2); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3402 | SDValue ARMcc; |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 3403 | unsigned Opc = (Op.getOpcode() == ISD::SRA_PARTS) ? ISD::SRA : ISD::SRL; |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3404 | |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 3405 | assert(Op.getOpcode() == ISD::SRA_PARTS || Op.getOpcode() == ISD::SRL_PARTS); |
| 3406 | |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3407 | SDValue RevShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, |
| 3408 | DAG.getConstant(VTBits, MVT::i32), ShAmt); |
| 3409 | SDValue Tmp1 = DAG.getNode(ISD::SRL, dl, VT, ShOpLo, ShAmt); |
| 3410 | SDValue ExtraShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, ShAmt, |
| 3411 | DAG.getConstant(VTBits, MVT::i32)); |
| 3412 | SDValue Tmp2 = DAG.getNode(ISD::SHL, dl, VT, ShOpHi, RevShAmt); |
| 3413 | SDValue FalseVal = DAG.getNode(ISD::OR, dl, VT, Tmp1, Tmp2); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 3414 | SDValue TrueVal = DAG.getNode(Opc, dl, VT, ShOpHi, ExtraShAmt); |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3415 | |
| 3416 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| 3417 | SDValue Cmp = getARMCmp(ExtraShAmt, DAG.getConstant(0, MVT::i32), ISD::SETGE, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3418 | ARMcc, DAG, dl); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 3419 | SDValue Hi = DAG.getNode(Opc, dl, VT, ShOpHi, ShAmt); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3420 | SDValue Lo = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, ARMcc, |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3421 | CCR, Cmp); |
| 3422 | |
| 3423 | SDValue Ops[2] = { Lo, Hi }; |
| 3424 | return DAG.getMergeValues(Ops, 2, dl); |
| 3425 | } |
| 3426 | |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3427 | /// LowerShiftLeftParts - Lower SHL_PARTS, which returns two |
| 3428 | /// 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] | 3429 | SDValue ARMTargetLowering::LowerShiftLeftParts(SDValue Op, |
| 3430 | SelectionDAG &DAG) const { |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3431 | assert(Op.getNumOperands() == 3 && "Not a double-shift!"); |
| 3432 | EVT VT = Op.getValueType(); |
| 3433 | unsigned VTBits = VT.getSizeInBits(); |
| 3434 | DebugLoc dl = Op.getDebugLoc(); |
| 3435 | SDValue ShOpLo = Op.getOperand(0); |
| 3436 | SDValue ShOpHi = Op.getOperand(1); |
| 3437 | SDValue ShAmt = Op.getOperand(2); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3438 | SDValue ARMcc; |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3439 | |
| 3440 | assert(Op.getOpcode() == ISD::SHL_PARTS); |
| 3441 | SDValue RevShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, |
| 3442 | DAG.getConstant(VTBits, MVT::i32), ShAmt); |
| 3443 | SDValue Tmp1 = DAG.getNode(ISD::SRL, dl, VT, ShOpLo, RevShAmt); |
| 3444 | SDValue ExtraShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, ShAmt, |
| 3445 | DAG.getConstant(VTBits, MVT::i32)); |
| 3446 | SDValue Tmp2 = DAG.getNode(ISD::SHL, dl, VT, ShOpHi, ShAmt); |
| 3447 | SDValue Tmp3 = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ExtraShAmt); |
| 3448 | |
| 3449 | SDValue FalseVal = DAG.getNode(ISD::OR, dl, VT, Tmp1, Tmp2); |
| 3450 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| 3451 | SDValue Cmp = getARMCmp(ExtraShAmt, DAG.getConstant(0, MVT::i32), ISD::SETGE, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3452 | ARMcc, DAG, dl); |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3453 | SDValue Lo = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ShAmt); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3454 | SDValue Hi = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, Tmp3, ARMcc, |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3455 | CCR, Cmp); |
| 3456 | |
| 3457 | SDValue Ops[2] = { Lo, Hi }; |
| 3458 | return DAG.getMergeValues(Ops, 2, dl); |
| 3459 | } |
| 3460 | |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 3461 | SDValue ARMTargetLowering::LowerFLT_ROUNDS_(SDValue Op, |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 3462 | SelectionDAG &DAG) const { |
| 3463 | // The rounding mode is in bits 23:22 of the FPSCR. |
| 3464 | // The ARM rounding mode value to FLT_ROUNDS mapping is 0->1, 1->2, 2->3, 3->0 |
| 3465 | // The formula we use to implement this is (((FPSCR + 1 << 22) >> 22) & 3) |
| 3466 | // so that the shift + and get folded into a bitfield extract. |
| 3467 | DebugLoc dl = Op.getDebugLoc(); |
| 3468 | SDValue FPSCR = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::i32, |
| 3469 | DAG.getConstant(Intrinsic::arm_get_fpscr, |
| 3470 | MVT::i32)); |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 3471 | SDValue FltRounds = DAG.getNode(ISD::ADD, dl, MVT::i32, FPSCR, |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 3472 | DAG.getConstant(1U << 22, MVT::i32)); |
| 3473 | SDValue RMODE = DAG.getNode(ISD::SRL, dl, MVT::i32, FltRounds, |
| 3474 | DAG.getConstant(22, MVT::i32)); |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 3475 | return DAG.getNode(ISD::AND, dl, MVT::i32, RMODE, |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 3476 | DAG.getConstant(3, MVT::i32)); |
| 3477 | } |
| 3478 | |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 3479 | static SDValue LowerCTTZ(SDNode *N, SelectionDAG &DAG, |
| 3480 | const ARMSubtarget *ST) { |
| 3481 | EVT VT = N->getValueType(0); |
| 3482 | DebugLoc dl = N->getDebugLoc(); |
| 3483 | |
| 3484 | if (!ST->hasV6T2Ops()) |
| 3485 | return SDValue(); |
| 3486 | |
| 3487 | SDValue rbit = DAG.getNode(ARMISD::RBIT, dl, VT, N->getOperand(0)); |
| 3488 | return DAG.getNode(ISD::CTLZ, dl, VT, rbit); |
| 3489 | } |
| 3490 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3491 | static SDValue LowerShift(SDNode *N, SelectionDAG &DAG, |
| 3492 | const ARMSubtarget *ST) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3493 | EVT VT = N->getValueType(0); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3494 | DebugLoc dl = N->getDebugLoc(); |
| 3495 | |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3496 | if (!VT.isVector()) |
| 3497 | return SDValue(); |
| 3498 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3499 | // Lower vector shifts on NEON to use VSHL. |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3500 | assert(ST->hasNEON() && "unexpected vector shift"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3501 | |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3502 | // Left shifts translate directly to the vshiftu intrinsic. |
| 3503 | if (N->getOpcode() == ISD::SHL) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3504 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT, |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3505 | DAG.getConstant(Intrinsic::arm_neon_vshiftu, MVT::i32), |
| 3506 | N->getOperand(0), N->getOperand(1)); |
| 3507 | |
| 3508 | assert((N->getOpcode() == ISD::SRA || |
| 3509 | N->getOpcode() == ISD::SRL) && "unexpected vector shift opcode"); |
| 3510 | |
| 3511 | // NEON uses the same intrinsics for both left and right shifts. For |
| 3512 | // right shifts, the shift amounts are negative, so negate the vector of |
| 3513 | // shift amounts. |
| 3514 | EVT ShiftVT = N->getOperand(1).getValueType(); |
| 3515 | SDValue NegatedCount = DAG.getNode(ISD::SUB, dl, ShiftVT, |
| 3516 | getZeroVector(ShiftVT, DAG, dl), |
| 3517 | N->getOperand(1)); |
| 3518 | Intrinsic::ID vshiftInt = (N->getOpcode() == ISD::SRA ? |
| 3519 | Intrinsic::arm_neon_vshifts : |
| 3520 | Intrinsic::arm_neon_vshiftu); |
| 3521 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT, |
| 3522 | DAG.getConstant(vshiftInt, MVT::i32), |
| 3523 | N->getOperand(0), NegatedCount); |
| 3524 | } |
| 3525 | |
| 3526 | static SDValue Expand64BitShift(SDNode *N, SelectionDAG &DAG, |
| 3527 | const ARMSubtarget *ST) { |
| 3528 | EVT VT = N->getValueType(0); |
| 3529 | DebugLoc dl = N->getDebugLoc(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3530 | |
Eli Friedman | ce392eb | 2009-08-22 03:13:10 +0000 | [diff] [blame] | 3531 | // We can get here for a node like i32 = ISD::SHL i32, i64 |
| 3532 | if (VT != MVT::i64) |
| 3533 | return SDValue(); |
| 3534 | |
| 3535 | assert((N->getOpcode() == ISD::SRL || N->getOpcode() == ISD::SRA) && |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3536 | "Unknown shift to lower!"); |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 3537 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3538 | // We only lower SRA, SRL of 1 here, all others use generic lowering. |
| 3539 | if (!isa<ConstantSDNode>(N->getOperand(1)) || |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 3540 | cast<ConstantSDNode>(N->getOperand(1))->getZExtValue() != 1) |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 3541 | return SDValue(); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3542 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3543 | // If we are in thumb mode, we don't have RRX. |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 3544 | if (ST->isThumb1Only()) return SDValue(); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3545 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3546 | // 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] | 3547 | 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] | 3548 | DAG.getConstant(0, MVT::i32)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3549 | 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] | 3550 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3551 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3552 | // First, build a SRA_FLAG/SRL_FLAG op, which shifts the top part by one and |
| 3553 | // captures the result into a carry flag. |
| 3554 | unsigned Opc = N->getOpcode() == ISD::SRL ? ARMISD::SRL_FLAG:ARMISD::SRA_FLAG; |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 3555 | 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] | 3556 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3557 | // 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] | 3558 | Lo = DAG.getNode(ARMISD::RRX, dl, MVT::i32, Lo, Hi.getValue(1)); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3559 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3560 | // Merge the pieces into a single i64 value. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3561 | return DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Lo, Hi); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3562 | } |
| 3563 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3564 | static SDValue LowerVSETCC(SDValue Op, SelectionDAG &DAG) { |
| 3565 | SDValue TmpOp0, TmpOp1; |
| 3566 | bool Invert = false; |
| 3567 | bool Swap = false; |
| 3568 | unsigned Opc = 0; |
| 3569 | |
| 3570 | SDValue Op0 = Op.getOperand(0); |
| 3571 | SDValue Op1 = Op.getOperand(1); |
| 3572 | SDValue CC = Op.getOperand(2); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3573 | EVT VT = Op.getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3574 | ISD::CondCode SetCCOpcode = cast<CondCodeSDNode>(CC)->get(); |
| 3575 | DebugLoc dl = Op.getDebugLoc(); |
| 3576 | |
| 3577 | if (Op.getOperand(1).getValueType().isFloatingPoint()) { |
| 3578 | switch (SetCCOpcode) { |
David Blaikie | 4d6ccb5 | 2012-01-20 21:51:11 +0000 | [diff] [blame] | 3579 | default: llvm_unreachable("Illegal FP comparison"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3580 | case ISD::SETUNE: |
| 3581 | case ISD::SETNE: Invert = true; // Fallthrough |
| 3582 | case ISD::SETOEQ: |
| 3583 | case ISD::SETEQ: Opc = ARMISD::VCEQ; break; |
| 3584 | case ISD::SETOLT: |
| 3585 | case ISD::SETLT: Swap = true; // Fallthrough |
| 3586 | case ISD::SETOGT: |
| 3587 | case ISD::SETGT: Opc = ARMISD::VCGT; break; |
| 3588 | case ISD::SETOLE: |
| 3589 | case ISD::SETLE: Swap = true; // Fallthrough |
| 3590 | case ISD::SETOGE: |
| 3591 | case ISD::SETGE: Opc = ARMISD::VCGE; break; |
| 3592 | case ISD::SETUGE: Swap = true; // Fallthrough |
| 3593 | case ISD::SETULE: Invert = true; Opc = ARMISD::VCGT; break; |
| 3594 | case ISD::SETUGT: Swap = true; // Fallthrough |
| 3595 | case ISD::SETULT: Invert = true; Opc = ARMISD::VCGE; break; |
| 3596 | case ISD::SETUEQ: Invert = true; // Fallthrough |
| 3597 | case ISD::SETONE: |
| 3598 | // Expand this to (OLT | OGT). |
| 3599 | TmpOp0 = Op0; |
| 3600 | TmpOp1 = Op1; |
| 3601 | Opc = ISD::OR; |
| 3602 | Op0 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp1, TmpOp0); |
| 3603 | Op1 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp0, TmpOp1); |
| 3604 | break; |
| 3605 | case ISD::SETUO: Invert = true; // Fallthrough |
| 3606 | case ISD::SETO: |
| 3607 | // Expand this to (OLT | OGE). |
| 3608 | TmpOp0 = Op0; |
| 3609 | TmpOp1 = Op1; |
| 3610 | Opc = ISD::OR; |
| 3611 | Op0 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp1, TmpOp0); |
| 3612 | Op1 = DAG.getNode(ARMISD::VCGE, dl, VT, TmpOp0, TmpOp1); |
| 3613 | break; |
| 3614 | } |
| 3615 | } else { |
| 3616 | // Integer comparisons. |
| 3617 | switch (SetCCOpcode) { |
David Blaikie | 4d6ccb5 | 2012-01-20 21:51:11 +0000 | [diff] [blame] | 3618 | default: llvm_unreachable("Illegal integer comparison"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3619 | case ISD::SETNE: Invert = true; |
| 3620 | case ISD::SETEQ: Opc = ARMISD::VCEQ; break; |
| 3621 | case ISD::SETLT: Swap = true; |
| 3622 | case ISD::SETGT: Opc = ARMISD::VCGT; break; |
| 3623 | case ISD::SETLE: Swap = true; |
| 3624 | case ISD::SETGE: Opc = ARMISD::VCGE; break; |
| 3625 | case ISD::SETULT: Swap = true; |
| 3626 | case ISD::SETUGT: Opc = ARMISD::VCGTU; break; |
| 3627 | case ISD::SETULE: Swap = true; |
| 3628 | case ISD::SETUGE: Opc = ARMISD::VCGEU; break; |
| 3629 | } |
| 3630 | |
Nick Lewycky | 7f6aa2b | 2009-07-08 03:04:38 +0000 | [diff] [blame] | 3631 | // Detect VTST (Vector Test Bits) = icmp ne (and (op0, op1), zero). |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3632 | if (Opc == ARMISD::VCEQ) { |
| 3633 | |
| 3634 | SDValue AndOp; |
| 3635 | if (ISD::isBuildVectorAllZeros(Op1.getNode())) |
| 3636 | AndOp = Op0; |
| 3637 | else if (ISD::isBuildVectorAllZeros(Op0.getNode())) |
| 3638 | AndOp = Op1; |
| 3639 | |
| 3640 | // Ignore bitconvert. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3641 | if (AndOp.getNode() && AndOp.getOpcode() == ISD::BITCAST) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3642 | AndOp = AndOp.getOperand(0); |
| 3643 | |
| 3644 | if (AndOp.getNode() && AndOp.getOpcode() == ISD::AND) { |
| 3645 | Opc = ARMISD::VTST; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3646 | Op0 = DAG.getNode(ISD::BITCAST, dl, VT, AndOp.getOperand(0)); |
| 3647 | Op1 = DAG.getNode(ISD::BITCAST, dl, VT, AndOp.getOperand(1)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3648 | Invert = !Invert; |
| 3649 | } |
| 3650 | } |
| 3651 | } |
| 3652 | |
| 3653 | if (Swap) |
| 3654 | std::swap(Op0, Op1); |
| 3655 | |
Owen Anderson | c24cb35 | 2010-11-08 23:21:22 +0000 | [diff] [blame] | 3656 | // If one of the operands is a constant vector zero, attempt to fold the |
| 3657 | // comparison to a specialized compare-against-zero form. |
| 3658 | SDValue SingleOp; |
| 3659 | if (ISD::isBuildVectorAllZeros(Op1.getNode())) |
| 3660 | SingleOp = Op0; |
| 3661 | else if (ISD::isBuildVectorAllZeros(Op0.getNode())) { |
| 3662 | if (Opc == ARMISD::VCGE) |
| 3663 | Opc = ARMISD::VCLEZ; |
| 3664 | else if (Opc == ARMISD::VCGT) |
| 3665 | Opc = ARMISD::VCLTZ; |
| 3666 | SingleOp = Op1; |
| 3667 | } |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3668 | |
Owen Anderson | c24cb35 | 2010-11-08 23:21:22 +0000 | [diff] [blame] | 3669 | SDValue Result; |
| 3670 | if (SingleOp.getNode()) { |
| 3671 | switch (Opc) { |
| 3672 | case ARMISD::VCEQ: |
| 3673 | Result = DAG.getNode(ARMISD::VCEQZ, dl, VT, SingleOp); break; |
| 3674 | case ARMISD::VCGE: |
| 3675 | Result = DAG.getNode(ARMISD::VCGEZ, dl, VT, SingleOp); break; |
| 3676 | case ARMISD::VCLEZ: |
| 3677 | Result = DAG.getNode(ARMISD::VCLEZ, dl, VT, SingleOp); break; |
| 3678 | case ARMISD::VCGT: |
| 3679 | Result = DAG.getNode(ARMISD::VCGTZ, dl, VT, SingleOp); break; |
| 3680 | case ARMISD::VCLTZ: |
| 3681 | Result = DAG.getNode(ARMISD::VCLTZ, dl, VT, SingleOp); break; |
| 3682 | default: |
| 3683 | Result = DAG.getNode(Opc, dl, VT, Op0, Op1); |
| 3684 | } |
| 3685 | } else { |
| 3686 | Result = DAG.getNode(Opc, dl, VT, Op0, Op1); |
| 3687 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3688 | |
| 3689 | if (Invert) |
| 3690 | Result = DAG.getNOT(dl, Result, VT); |
| 3691 | |
| 3692 | return Result; |
| 3693 | } |
| 3694 | |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 3695 | /// isNEONModifiedImm - Check if the specified splat value corresponds to a |
| 3696 | /// valid vector constant for a NEON instruction with a "modified immediate" |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3697 | /// operand (e.g., VMOV). If so, return the encoded value. |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 3698 | static SDValue isNEONModifiedImm(uint64_t SplatBits, uint64_t SplatUndef, |
| 3699 | unsigned SplatBitSize, SelectionDAG &DAG, |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3700 | EVT &VT, bool is128Bits, NEONModImmType type) { |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3701 | unsigned OpCmode, Imm; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3702 | |
Bob Wilson | 827b210 | 2010-06-15 19:05:35 +0000 | [diff] [blame] | 3703 | // SplatBitSize is set to the smallest size that splats the vector, so a |
| 3704 | // zero vector will always have SplatBitSize == 8. However, NEON modified |
| 3705 | // immediate instructions others than VMOV do not support the 8-bit encoding |
| 3706 | // of a zero vector, and the default encoding of zero is supposed to be the |
| 3707 | // 32-bit version. |
| 3708 | if (SplatBits == 0) |
| 3709 | SplatBitSize = 32; |
| 3710 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3711 | switch (SplatBitSize) { |
| 3712 | case 8: |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3713 | if (type != VMOVModImm) |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 3714 | return SDValue(); |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3715 | // Any 1-byte value is OK. Op=0, Cmode=1110. |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3716 | assert((SplatBits & ~0xff) == 0 && "one byte splat value is too big"); |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3717 | OpCmode = 0xe; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3718 | Imm = SplatBits; |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3719 | VT = is128Bits ? MVT::v16i8 : MVT::v8i8; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3720 | break; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3721 | |
| 3722 | case 16: |
| 3723 | // 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] | 3724 | VT = is128Bits ? MVT::v8i16 : MVT::v4i16; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3725 | if ((SplatBits & ~0xff) == 0) { |
| 3726 | // Value = 0x00nn: Op=x, Cmode=100x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3727 | OpCmode = 0x8; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3728 | Imm = SplatBits; |
| 3729 | break; |
| 3730 | } |
| 3731 | if ((SplatBits & ~0xff00) == 0) { |
| 3732 | // Value = 0xnn00: Op=x, Cmode=101x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3733 | OpCmode = 0xa; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3734 | Imm = SplatBits >> 8; |
| 3735 | break; |
| 3736 | } |
| 3737 | return SDValue(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3738 | |
| 3739 | case 32: |
| 3740 | // NEON's 32-bit VMOV supports splat values where: |
| 3741 | // * only one byte is nonzero, or |
| 3742 | // * the least significant byte is 0xff and the second byte is nonzero, or |
| 3743 | // * the least significant 2 bytes are 0xff and the third is nonzero. |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3744 | VT = is128Bits ? MVT::v4i32 : MVT::v2i32; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3745 | if ((SplatBits & ~0xff) == 0) { |
| 3746 | // Value = 0x000000nn: Op=x, Cmode=000x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3747 | OpCmode = 0; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3748 | Imm = SplatBits; |
| 3749 | break; |
| 3750 | } |
| 3751 | if ((SplatBits & ~0xff00) == 0) { |
| 3752 | // Value = 0x0000nn00: Op=x, Cmode=001x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3753 | OpCmode = 0x2; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3754 | Imm = SplatBits >> 8; |
| 3755 | break; |
| 3756 | } |
| 3757 | if ((SplatBits & ~0xff0000) == 0) { |
| 3758 | // Value = 0x00nn0000: Op=x, Cmode=010x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3759 | OpCmode = 0x4; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3760 | Imm = SplatBits >> 16; |
| 3761 | break; |
| 3762 | } |
| 3763 | if ((SplatBits & ~0xff000000) == 0) { |
| 3764 | // Value = 0xnn000000: Op=x, Cmode=011x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3765 | OpCmode = 0x6; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3766 | Imm = SplatBits >> 24; |
| 3767 | break; |
| 3768 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3769 | |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3770 | // cmode == 0b1100 and cmode == 0b1101 are not supported for VORR or VBIC |
| 3771 | if (type == OtherModImm) return SDValue(); |
| 3772 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3773 | if ((SplatBits & ~0xffff) == 0 && |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3774 | ((SplatBits | SplatUndef) & 0xff) == 0xff) { |
| 3775 | // Value = 0x0000nnff: Op=x, Cmode=1100. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3776 | OpCmode = 0xc; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3777 | Imm = SplatBits >> 8; |
| 3778 | SplatBits |= 0xff; |
| 3779 | break; |
| 3780 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3781 | |
| 3782 | if ((SplatBits & ~0xffffff) == 0 && |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3783 | ((SplatBits | SplatUndef) & 0xffff) == 0xffff) { |
| 3784 | // Value = 0x00nnffff: Op=x, Cmode=1101. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3785 | OpCmode = 0xd; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3786 | Imm = SplatBits >> 16; |
| 3787 | SplatBits |= 0xffff; |
| 3788 | break; |
| 3789 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3790 | |
| 3791 | // Note: there are a few 32-bit splat values (specifically: 00ffff00, |
| 3792 | // ff000000, ff0000ff, and ffff00ff) that are valid for VMOV.I64 but not |
| 3793 | // VMOV.I32. A (very) minor optimization would be to replicate the value |
| 3794 | // and fall through here to test for a valid 64-bit splat. But, then the |
| 3795 | // caller would also need to check and handle the change in size. |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3796 | return SDValue(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3797 | |
| 3798 | case 64: { |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3799 | if (type != VMOVModImm) |
Bob Wilson | 827b210 | 2010-06-15 19:05:35 +0000 | [diff] [blame] | 3800 | return SDValue(); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 3801 | // 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] | 3802 | uint64_t BitMask = 0xff; |
| 3803 | uint64_t Val = 0; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3804 | unsigned ImmMask = 1; |
| 3805 | Imm = 0; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3806 | for (int ByteNum = 0; ByteNum < 8; ++ByteNum) { |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3807 | if (((SplatBits | SplatUndef) & BitMask) == BitMask) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3808 | Val |= BitMask; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3809 | Imm |= ImmMask; |
| 3810 | } else if ((SplatBits & BitMask) != 0) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3811 | return SDValue(); |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3812 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3813 | BitMask <<= 8; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3814 | ImmMask <<= 1; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3815 | } |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3816 | // Op=1, Cmode=1110. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3817 | OpCmode = 0x1e; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3818 | SplatBits = Val; |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3819 | VT = is128Bits ? MVT::v2i64 : MVT::v1i64; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3820 | break; |
| 3821 | } |
| 3822 | |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3823 | default: |
Bob Wilson | dc076da | 2010-06-19 05:32:09 +0000 | [diff] [blame] | 3824 | llvm_unreachable("unexpected size for isNEONModifiedImm"); |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3825 | } |
| 3826 | |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3827 | unsigned EncodedVal = ARM_AM::createNEONModImm(OpCmode, Imm); |
| 3828 | return DAG.getTargetConstant(EncodedVal, MVT::i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3829 | } |
| 3830 | |
Lang Hames | c0a9f82 | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 3831 | SDValue ARMTargetLowering::LowerConstantFP(SDValue Op, SelectionDAG &DAG, |
| 3832 | const ARMSubtarget *ST) const { |
| 3833 | if (!ST->useNEONForSinglePrecisionFP() || !ST->hasVFP3() || ST->hasD16()) |
| 3834 | return SDValue(); |
| 3835 | |
| 3836 | ConstantFPSDNode *CFP = cast<ConstantFPSDNode>(Op); |
| 3837 | assert(Op.getValueType() == MVT::f32 && |
| 3838 | "ConstantFP custom lowering should only occur for f32."); |
| 3839 | |
| 3840 | // Try splatting with a VMOV.f32... |
| 3841 | APFloat FPVal = CFP->getValueAPF(); |
| 3842 | int ImmVal = ARM_AM::getFP32Imm(FPVal); |
| 3843 | if (ImmVal != -1) { |
| 3844 | DebugLoc DL = Op.getDebugLoc(); |
| 3845 | SDValue NewVal = DAG.getTargetConstant(ImmVal, MVT::i32); |
| 3846 | SDValue VecConstant = DAG.getNode(ARMISD::VMOVFPIMM, DL, MVT::v2f32, |
| 3847 | NewVal); |
| 3848 | return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::f32, VecConstant, |
| 3849 | DAG.getConstant(0, MVT::i32)); |
| 3850 | } |
| 3851 | |
| 3852 | // If that fails, try a VMOV.i32 |
| 3853 | EVT VMovVT; |
| 3854 | unsigned iVal = FPVal.bitcastToAPInt().getZExtValue(); |
| 3855 | SDValue NewVal = isNEONModifiedImm(iVal, 0, 32, DAG, VMovVT, false, |
| 3856 | VMOVModImm); |
| 3857 | if (NewVal != SDValue()) { |
| 3858 | DebugLoc DL = Op.getDebugLoc(); |
| 3859 | SDValue VecConstant = DAG.getNode(ARMISD::VMOVIMM, DL, VMovVT, |
| 3860 | NewVal); |
| 3861 | SDValue VecFConstant = DAG.getNode(ISD::BITCAST, DL, MVT::v2f32, |
| 3862 | VecConstant); |
| 3863 | return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::f32, VecFConstant, |
| 3864 | DAG.getConstant(0, MVT::i32)); |
| 3865 | } |
| 3866 | |
| 3867 | // Finally, try a VMVN.i32 |
| 3868 | NewVal = isNEONModifiedImm(~iVal & 0xffffffff, 0, 32, DAG, VMovVT, false, |
| 3869 | VMVNModImm); |
| 3870 | if (NewVal != SDValue()) { |
| 3871 | DebugLoc DL = Op.getDebugLoc(); |
| 3872 | SDValue VecConstant = DAG.getNode(ARMISD::VMVNIMM, DL, VMovVT, NewVal); |
| 3873 | SDValue VecFConstant = DAG.getNode(ISD::BITCAST, DL, MVT::v2f32, |
| 3874 | VecConstant); |
| 3875 | return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::f32, VecFConstant, |
| 3876 | DAG.getConstant(0, MVT::i32)); |
| 3877 | } |
| 3878 | |
| 3879 | return SDValue(); |
| 3880 | } |
| 3881 | |
| 3882 | |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 3883 | static bool isVEXTMask(ArrayRef<int> M, EVT VT, |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3884 | bool &ReverseVEXT, unsigned &Imm) { |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3885 | unsigned NumElts = VT.getVectorNumElements(); |
| 3886 | ReverseVEXT = false; |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3887 | |
| 3888 | // Assume that the first shuffle index is not UNDEF. Fail if it is. |
| 3889 | if (M[0] < 0) |
| 3890 | return false; |
| 3891 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3892 | Imm = M[0]; |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3893 | |
| 3894 | // If this is a VEXT shuffle, the immediate value is the index of the first |
| 3895 | // element. The other shuffle indices must be the successive elements after |
| 3896 | // the first one. |
| 3897 | unsigned ExpectedElt = Imm; |
| 3898 | for (unsigned i = 1; i < NumElts; ++i) { |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3899 | // Increment the expected index. If it wraps around, it may still be |
| 3900 | // a VEXT but the source vectors must be swapped. |
| 3901 | ExpectedElt += 1; |
| 3902 | if (ExpectedElt == NumElts * 2) { |
| 3903 | ExpectedElt = 0; |
| 3904 | ReverseVEXT = true; |
| 3905 | } |
| 3906 | |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3907 | if (M[i] < 0) continue; // ignore UNDEF indices |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3908 | if (ExpectedElt != static_cast<unsigned>(M[i])) |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3909 | return false; |
| 3910 | } |
| 3911 | |
| 3912 | // Adjust the index value if the source operands will be swapped. |
| 3913 | if (ReverseVEXT) |
| 3914 | Imm -= NumElts; |
| 3915 | |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3916 | return true; |
| 3917 | } |
| 3918 | |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 3919 | /// isVREVMask - Check if a vector shuffle corresponds to a VREV |
| 3920 | /// instruction with the specified blocksize. (The order of the elements |
| 3921 | /// within each block of the vector is reversed.) |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 3922 | static bool isVREVMask(ArrayRef<int> M, EVT VT, unsigned BlockSize) { |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 3923 | assert((BlockSize==16 || BlockSize==32 || BlockSize==64) && |
| 3924 | "Only possible block sizes for VREV are: 16, 32, 64"); |
| 3925 | |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 3926 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 3927 | if (EltSz == 64) |
| 3928 | return false; |
| 3929 | |
| 3930 | unsigned NumElts = VT.getVectorNumElements(); |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3931 | unsigned BlockElts = M[0] + 1; |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3932 | // If the first shuffle index is UNDEF, be optimistic. |
| 3933 | if (M[0] < 0) |
| 3934 | BlockElts = BlockSize / EltSz; |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 3935 | |
| 3936 | if (BlockSize <= EltSz || BlockSize != BlockElts * EltSz) |
| 3937 | return false; |
| 3938 | |
| 3939 | for (unsigned i = 0; i < NumElts; ++i) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3940 | if (M[i] < 0) continue; // ignore UNDEF indices |
| 3941 | if ((unsigned) M[i] != (i - i%BlockElts) + (BlockElts - 1 - i%BlockElts)) |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 3942 | return false; |
| 3943 | } |
| 3944 | |
| 3945 | return true; |
| 3946 | } |
| 3947 | |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 3948 | static bool isVTBLMask(ArrayRef<int> M, EVT VT) { |
Bill Wendling | 0d4c9d9 | 2011-03-15 21:15:20 +0000 | [diff] [blame] | 3949 | // We can handle <8 x i8> vector shuffles. If the index in the mask is out of |
| 3950 | // range, then 0 is placed into the resulting vector. So pretty much any mask |
| 3951 | // of 8 elements can work here. |
| 3952 | return VT == MVT::v8i8 && M.size() == 8; |
| 3953 | } |
| 3954 | |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 3955 | static bool isVTRNMask(ArrayRef<int> M, EVT VT, unsigned &WhichResult) { |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 3956 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3957 | if (EltSz == 64) |
| 3958 | return false; |
| 3959 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3960 | unsigned NumElts = VT.getVectorNumElements(); |
| 3961 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3962 | for (unsigned i = 0; i < NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3963 | if ((M[i] >= 0 && (unsigned) M[i] != i + WhichResult) || |
| 3964 | (M[i+1] >= 0 && (unsigned) M[i+1] != i + NumElts + WhichResult)) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3965 | return false; |
| 3966 | } |
| 3967 | return true; |
| 3968 | } |
| 3969 | |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3970 | /// isVTRN_v_undef_Mask - Special case of isVTRNMask for canonical form of |
| 3971 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 3972 | /// 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] | 3973 | 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] | 3974 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3975 | if (EltSz == 64) |
| 3976 | return false; |
| 3977 | |
| 3978 | unsigned NumElts = VT.getVectorNumElements(); |
| 3979 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3980 | for (unsigned i = 0; i < NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3981 | if ((M[i] >= 0 && (unsigned) M[i] != i + WhichResult) || |
| 3982 | (M[i+1] >= 0 && (unsigned) M[i+1] != i + WhichResult)) |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3983 | return false; |
| 3984 | } |
| 3985 | return true; |
| 3986 | } |
| 3987 | |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 3988 | static bool isVUZPMask(ArrayRef<int> M, EVT VT, unsigned &WhichResult) { |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 3989 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3990 | if (EltSz == 64) |
| 3991 | return false; |
| 3992 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3993 | unsigned NumElts = VT.getVectorNumElements(); |
| 3994 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3995 | for (unsigned i = 0; i != NumElts; ++i) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3996 | if (M[i] < 0) continue; // ignore UNDEF indices |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3997 | if ((unsigned) M[i] != 2 * i + WhichResult) |
| 3998 | return false; |
| 3999 | } |
| 4000 | |
| 4001 | // 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] | 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 | /// isVUZP_v_undef_Mask - Special case of isVUZPMask for canonical form of |
| 4009 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 4010 | /// 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] | 4011 | 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] | 4012 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 4013 | if (EltSz == 64) |
| 4014 | return false; |
| 4015 | |
| 4016 | unsigned Half = VT.getVectorNumElements() / 2; |
| 4017 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 4018 | for (unsigned j = 0; j != 2; ++j) { |
| 4019 | unsigned Idx = WhichResult; |
| 4020 | for (unsigned i = 0; i != Half; ++i) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4021 | int MIdx = M[i + j * Half]; |
| 4022 | if (MIdx >= 0 && (unsigned) MIdx != Idx) |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4023 | return false; |
| 4024 | Idx += 2; |
| 4025 | } |
| 4026 | } |
| 4027 | |
| 4028 | // VUZP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32. |
| 4029 | if (VT.is64BitVector() && EltSz == 32) |
| 4030 | return false; |
| 4031 | |
| 4032 | return true; |
| 4033 | } |
| 4034 | |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4035 | static bool isVZIPMask(ArrayRef<int> M, EVT VT, unsigned &WhichResult) { |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 4036 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 4037 | if (EltSz == 64) |
| 4038 | return false; |
| 4039 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4040 | unsigned NumElts = VT.getVectorNumElements(); |
| 4041 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 4042 | unsigned Idx = WhichResult * NumElts / 2; |
| 4043 | for (unsigned i = 0; i != NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4044 | if ((M[i] >= 0 && (unsigned) M[i] != Idx) || |
| 4045 | (M[i+1] >= 0 && (unsigned) M[i+1] != Idx + NumElts)) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4046 | return false; |
| 4047 | Idx += 1; |
| 4048 | } |
| 4049 | |
| 4050 | // 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] | 4051 | if (VT.is64BitVector() && EltSz == 32) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4052 | return false; |
| 4053 | |
| 4054 | return true; |
| 4055 | } |
| 4056 | |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4057 | /// isVZIP_v_undef_Mask - Special case of isVZIPMask for canonical form of |
| 4058 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 4059 | /// 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] | 4060 | 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] | 4061 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 4062 | if (EltSz == 64) |
| 4063 | return false; |
| 4064 | |
| 4065 | unsigned NumElts = VT.getVectorNumElements(); |
| 4066 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 4067 | unsigned Idx = WhichResult * NumElts / 2; |
| 4068 | for (unsigned i = 0; i != NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4069 | if ((M[i] >= 0 && (unsigned) M[i] != Idx) || |
| 4070 | (M[i+1] >= 0 && (unsigned) M[i+1] != Idx)) |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4071 | return false; |
| 4072 | Idx += 1; |
| 4073 | } |
| 4074 | |
| 4075 | // VZIP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32. |
| 4076 | if (VT.is64BitVector() && EltSz == 32) |
| 4077 | return false; |
| 4078 | |
| 4079 | return true; |
| 4080 | } |
| 4081 | |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 4082 | // If N is an integer constant that can be moved into a register in one |
| 4083 | // instruction, return an SDValue of such a constant (will become a MOV |
| 4084 | // instruction). Otherwise return null. |
| 4085 | static SDValue IsSingleInstrConstant(SDValue N, SelectionDAG &DAG, |
| 4086 | const ARMSubtarget *ST, DebugLoc dl) { |
| 4087 | uint64_t Val; |
| 4088 | if (!isa<ConstantSDNode>(N)) |
| 4089 | return SDValue(); |
| 4090 | Val = cast<ConstantSDNode>(N)->getZExtValue(); |
| 4091 | |
| 4092 | if (ST->isThumb1Only()) { |
| 4093 | if (Val <= 255 || ~Val <= 255) |
| 4094 | return DAG.getConstant(Val, MVT::i32); |
| 4095 | } else { |
| 4096 | if (ARM_AM::getSOImmVal(Val) != -1 || ARM_AM::getSOImmVal(~Val) != -1) |
| 4097 | return DAG.getConstant(Val, MVT::i32); |
| 4098 | } |
| 4099 | return SDValue(); |
| 4100 | } |
| 4101 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4102 | // If this is a case we can't handle, return null and let the default |
| 4103 | // expansion code take care of it. |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4104 | SDValue ARMTargetLowering::LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG, |
| 4105 | const ARMSubtarget *ST) const { |
Bob Wilson | d06791f | 2009-08-13 01:57:47 +0000 | [diff] [blame] | 4106 | BuildVectorSDNode *BVN = cast<BuildVectorSDNode>(Op.getNode()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4107 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4108 | EVT VT = Op.getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4109 | |
| 4110 | APInt SplatBits, SplatUndef; |
| 4111 | unsigned SplatBitSize; |
| 4112 | bool HasAnyUndefs; |
| 4113 | if (BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { |
Anton Korobeynikov | 71624cc | 2009-08-29 00:08:18 +0000 | [diff] [blame] | 4114 | if (SplatBitSize <= 64) { |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 4115 | // Check if an immediate VMOV works. |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4116 | EVT VmovVT; |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 4117 | SDValue Val = isNEONModifiedImm(SplatBits.getZExtValue(), |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4118 | SplatUndef.getZExtValue(), SplatBitSize, |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 4119 | DAG, VmovVT, VT.is128BitVector(), |
| 4120 | VMOVModImm); |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4121 | if (Val.getNode()) { |
| 4122 | SDValue Vmov = DAG.getNode(ARMISD::VMOVIMM, dl, VmovVT, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4123 | return DAG.getNode(ISD::BITCAST, dl, VT, Vmov); |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4124 | } |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 4125 | |
| 4126 | // Try an immediate VMVN. |
Eli Friedman | 8e4d042 | 2011-10-13 22:40:23 +0000 | [diff] [blame] | 4127 | uint64_t NegatedImm = (~SplatBits).getZExtValue(); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 4128 | Val = isNEONModifiedImm(NegatedImm, |
| 4129 | SplatUndef.getZExtValue(), SplatBitSize, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4130 | DAG, VmovVT, VT.is128BitVector(), |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 4131 | VMVNModImm); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 4132 | if (Val.getNode()) { |
| 4133 | SDValue Vmov = DAG.getNode(ARMISD::VMVNIMM, dl, VmovVT, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4134 | return DAG.getNode(ISD::BITCAST, dl, VT, Vmov); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 4135 | } |
Evan Cheng | eaa192a | 2011-11-15 02:12:34 +0000 | [diff] [blame] | 4136 | |
| 4137 | // Use vmov.f32 to materialize other v2f32 and v4f32 splats. |
Eli Friedman | 2f21e8c | 2011-12-15 22:56:53 +0000 | [diff] [blame] | 4138 | if ((VT == MVT::v2f32 || VT == MVT::v4f32) && SplatBitSize == 32) { |
Eli Friedman | effab8f | 2011-12-09 23:54:42 +0000 | [diff] [blame] | 4139 | int ImmVal = ARM_AM::getFP32Imm(SplatBits); |
Evan Cheng | eaa192a | 2011-11-15 02:12:34 +0000 | [diff] [blame] | 4140 | if (ImmVal != -1) { |
| 4141 | SDValue Val = DAG.getTargetConstant(ImmVal, MVT::i32); |
| 4142 | return DAG.getNode(ARMISD::VMOVFPIMM, dl, VT, Val); |
| 4143 | } |
| 4144 | } |
Anton Korobeynikov | 71624cc | 2009-08-29 00:08:18 +0000 | [diff] [blame] | 4145 | } |
Bob Wilson | cf661e2 | 2009-07-30 00:31:25 +0000 | [diff] [blame] | 4146 | } |
| 4147 | |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4148 | // Scan through the operands to see if only one value is used. |
| 4149 | unsigned NumElts = VT.getVectorNumElements(); |
| 4150 | bool isOnlyLowElement = true; |
| 4151 | bool usesOnlyOneValue = true; |
| 4152 | bool isConstant = true; |
| 4153 | SDValue Value; |
| 4154 | for (unsigned i = 0; i < NumElts; ++i) { |
| 4155 | SDValue V = Op.getOperand(i); |
| 4156 | if (V.getOpcode() == ISD::UNDEF) |
| 4157 | continue; |
| 4158 | if (i > 0) |
| 4159 | isOnlyLowElement = false; |
| 4160 | if (!isa<ConstantFPSDNode>(V) && !isa<ConstantSDNode>(V)) |
| 4161 | isConstant = false; |
| 4162 | |
| 4163 | if (!Value.getNode()) |
| 4164 | Value = V; |
| 4165 | else if (V != Value) |
| 4166 | usesOnlyOneValue = false; |
| 4167 | } |
| 4168 | |
| 4169 | if (!Value.getNode()) |
| 4170 | return DAG.getUNDEF(VT); |
| 4171 | |
| 4172 | if (isOnlyLowElement) |
| 4173 | return DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, VT, Value); |
| 4174 | |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 4175 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 4176 | |
Dale Johannesen | 575cd14 | 2010-10-19 20:00:17 +0000 | [diff] [blame] | 4177 | // Use VDUP for non-constant splats. For f32 constant splats, reduce to |
| 4178 | // i32 and try again. |
| 4179 | if (usesOnlyOneValue && EltSize <= 32) { |
| 4180 | if (!isConstant) |
| 4181 | return DAG.getNode(ARMISD::VDUP, dl, VT, Value); |
| 4182 | if (VT.getVectorElementType().isFloatingPoint()) { |
| 4183 | SmallVector<SDValue, 8> Ops; |
| 4184 | for (unsigned i = 0; i < NumElts; ++i) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4185 | Ops.push_back(DAG.getNode(ISD::BITCAST, dl, MVT::i32, |
Dale Johannesen | 575cd14 | 2010-10-19 20:00:17 +0000 | [diff] [blame] | 4186 | Op.getOperand(i))); |
Nate Begeman | bf5be26 | 2010-11-10 21:35:41 +0000 | [diff] [blame] | 4187 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), MVT::i32, NumElts); |
| 4188 | SDValue Val = DAG.getNode(ISD::BUILD_VECTOR, dl, VecVT, &Ops[0], NumElts); |
Dale Johannesen | e4d3159 | 2010-10-20 22:03:37 +0000 | [diff] [blame] | 4189 | Val = LowerBUILD_VECTOR(Val, DAG, ST); |
| 4190 | if (Val.getNode()) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4191 | return DAG.getNode(ISD::BITCAST, dl, VT, Val); |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 4192 | } |
Dale Johannesen | 575cd14 | 2010-10-19 20:00:17 +0000 | [diff] [blame] | 4193 | SDValue Val = IsSingleInstrConstant(Value, DAG, ST, dl); |
| 4194 | if (Val.getNode()) |
| 4195 | return DAG.getNode(ARMISD::VDUP, dl, VT, Val); |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 4196 | } |
| 4197 | |
| 4198 | // If all elements are constants and the case above didn't get hit, fall back |
| 4199 | // to the default expansion, which will generate a load from the constant |
| 4200 | // pool. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4201 | if (isConstant) |
| 4202 | return SDValue(); |
| 4203 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4204 | // Empirical tests suggest this is rarely worth it for vectors of length <= 2. |
| 4205 | if (NumElts >= 4) { |
| 4206 | SDValue shuffle = ReconstructShuffle(Op, DAG); |
| 4207 | if (shuffle != SDValue()) |
| 4208 | return shuffle; |
| 4209 | } |
| 4210 | |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4211 | // 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] | 4212 | // the subregisters. Lower it to an ARMISD::BUILD_VECTOR so the operands |
| 4213 | // will be legalized. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4214 | if (EltSize >= 32) { |
| 4215 | // Do the expansion with floating-point types, since that is what the VFP |
| 4216 | // registers are defined to use, and since i64 is not legal. |
| 4217 | EVT EltVT = EVT::getFloatingPointVT(EltSize); |
| 4218 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), EltVT, NumElts); |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4219 | SmallVector<SDValue, 8> Ops; |
| 4220 | for (unsigned i = 0; i < NumElts; ++i) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4221 | Ops.push_back(DAG.getNode(ISD::BITCAST, dl, EltVT, Op.getOperand(i))); |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4222 | SDValue Val = DAG.getNode(ARMISD::BUILD_VECTOR, dl, VecVT, &Ops[0],NumElts); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4223 | return DAG.getNode(ISD::BITCAST, dl, VT, Val); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4224 | } |
| 4225 | |
| 4226 | return SDValue(); |
| 4227 | } |
| 4228 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4229 | // Gather data to see if the operation can be modelled as a |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4230 | // shuffle in combination with VEXTs. |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4231 | SDValue ARMTargetLowering::ReconstructShuffle(SDValue Op, |
| 4232 | SelectionDAG &DAG) const { |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4233 | DebugLoc dl = Op.getDebugLoc(); |
| 4234 | EVT VT = Op.getValueType(); |
| 4235 | unsigned NumElts = VT.getVectorNumElements(); |
| 4236 | |
| 4237 | SmallVector<SDValue, 2> SourceVecs; |
| 4238 | SmallVector<unsigned, 2> MinElts; |
| 4239 | SmallVector<unsigned, 2> MaxElts; |
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 | for (unsigned i = 0; i < NumElts; ++i) { |
| 4242 | SDValue V = Op.getOperand(i); |
| 4243 | if (V.getOpcode() == ISD::UNDEF) |
| 4244 | continue; |
| 4245 | else if (V.getOpcode() != ISD::EXTRACT_VECTOR_ELT) { |
| 4246 | // A shuffle can only come from building a vector from various |
| 4247 | // elements of other vectors. |
| 4248 | return SDValue(); |
Eli Friedman | 46995fa | 2011-10-14 23:58:49 +0000 | [diff] [blame] | 4249 | } else if (V.getOperand(0).getValueType().getVectorElementType() != |
| 4250 | VT.getVectorElementType()) { |
| 4251 | // This code doesn't know how to handle shuffles where the vector |
| 4252 | // element types do not match (this happens because type legalization |
| 4253 | // promotes the return type of EXTRACT_VECTOR_ELT). |
| 4254 | // FIXME: It might be appropriate to extend this code to handle |
| 4255 | // mismatched types. |
| 4256 | return SDValue(); |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4257 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4258 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4259 | // Record this extraction against the appropriate vector if possible... |
| 4260 | SDValue SourceVec = V.getOperand(0); |
| 4261 | unsigned EltNo = cast<ConstantSDNode>(V.getOperand(1))->getZExtValue(); |
| 4262 | bool FoundSource = false; |
| 4263 | for (unsigned j = 0; j < SourceVecs.size(); ++j) { |
| 4264 | if (SourceVecs[j] == SourceVec) { |
| 4265 | if (MinElts[j] > EltNo) |
| 4266 | MinElts[j] = EltNo; |
| 4267 | if (MaxElts[j] < EltNo) |
| 4268 | MaxElts[j] = EltNo; |
| 4269 | FoundSource = true; |
| 4270 | break; |
| 4271 | } |
| 4272 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4273 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4274 | // Or record a new source if not... |
| 4275 | if (!FoundSource) { |
| 4276 | SourceVecs.push_back(SourceVec); |
| 4277 | MinElts.push_back(EltNo); |
| 4278 | MaxElts.push_back(EltNo); |
| 4279 | } |
| 4280 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4281 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4282 | // Currently only do something sane when at most two source vectors |
| 4283 | // involved. |
| 4284 | if (SourceVecs.size() > 2) |
| 4285 | return SDValue(); |
| 4286 | |
| 4287 | SDValue ShuffleSrcs[2] = {DAG.getUNDEF(VT), DAG.getUNDEF(VT) }; |
| 4288 | int VEXTOffsets[2] = {0, 0}; |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4289 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4290 | // This loop extracts the usage patterns of the source vectors |
| 4291 | // and prepares appropriate SDValues for a shuffle if possible. |
| 4292 | for (unsigned i = 0; i < SourceVecs.size(); ++i) { |
| 4293 | if (SourceVecs[i].getValueType() == VT) { |
| 4294 | // No VEXT necessary |
| 4295 | ShuffleSrcs[i] = SourceVecs[i]; |
| 4296 | VEXTOffsets[i] = 0; |
| 4297 | continue; |
| 4298 | } else if (SourceVecs[i].getValueType().getVectorNumElements() < NumElts) { |
| 4299 | // It probably isn't worth padding out a smaller vector just to |
| 4300 | // break it down again in a shuffle. |
| 4301 | return SDValue(); |
| 4302 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4303 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4304 | // Since only 64-bit and 128-bit vectors are legal on ARM and |
| 4305 | // we've eliminated the other cases... |
Bob Wilson | 70f8573 | 2011-01-07 23:40:46 +0000 | [diff] [blame] | 4306 | assert(SourceVecs[i].getValueType().getVectorNumElements() == 2*NumElts && |
| 4307 | "unexpected vector sizes in ReconstructShuffle"); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4308 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4309 | if (MaxElts[i] - MinElts[i] >= NumElts) { |
| 4310 | // Span too large for a VEXT to cope |
| 4311 | return SDValue(); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4312 | } |
| 4313 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4314 | if (MinElts[i] >= NumElts) { |
| 4315 | // The extraction can just take the second half |
| 4316 | VEXTOffsets[i] = NumElts; |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4317 | ShuffleSrcs[i] = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 4318 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4319 | DAG.getIntPtrConstant(NumElts)); |
| 4320 | } else if (MaxElts[i] < NumElts) { |
| 4321 | // The extraction can just take the first half |
| 4322 | VEXTOffsets[i] = 0; |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4323 | ShuffleSrcs[i] = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 4324 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4325 | DAG.getIntPtrConstant(0)); |
| 4326 | } else { |
| 4327 | // An actual VEXT is needed |
| 4328 | VEXTOffsets[i] = MinElts[i]; |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4329 | SDValue VEXTSrc1 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 4330 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4331 | DAG.getIntPtrConstant(0)); |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4332 | SDValue VEXTSrc2 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 4333 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4334 | DAG.getIntPtrConstant(NumElts)); |
| 4335 | ShuffleSrcs[i] = DAG.getNode(ARMISD::VEXT, dl, VT, VEXTSrc1, VEXTSrc2, |
| 4336 | DAG.getConstant(VEXTOffsets[i], MVT::i32)); |
| 4337 | } |
| 4338 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4339 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4340 | SmallVector<int, 8> Mask; |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4341 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4342 | for (unsigned i = 0; i < NumElts; ++i) { |
| 4343 | SDValue Entry = Op.getOperand(i); |
| 4344 | if (Entry.getOpcode() == ISD::UNDEF) { |
| 4345 | Mask.push_back(-1); |
| 4346 | continue; |
| 4347 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4348 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4349 | SDValue ExtractVec = Entry.getOperand(0); |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4350 | int ExtractElt = cast<ConstantSDNode>(Op.getOperand(i) |
| 4351 | .getOperand(1))->getSExtValue(); |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4352 | if (ExtractVec == SourceVecs[0]) { |
| 4353 | Mask.push_back(ExtractElt - VEXTOffsets[0]); |
| 4354 | } else { |
| 4355 | Mask.push_back(ExtractElt + NumElts - VEXTOffsets[1]); |
| 4356 | } |
| 4357 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4358 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4359 | // Final check before we try to produce nonsense... |
| 4360 | if (isShuffleMaskLegal(Mask, VT)) |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4361 | return DAG.getVectorShuffle(VT, dl, ShuffleSrcs[0], ShuffleSrcs[1], |
| 4362 | &Mask[0]); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4363 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4364 | return SDValue(); |
| 4365 | } |
| 4366 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4367 | /// isShuffleMaskLegal - Targets can use this to indicate that they only |
| 4368 | /// support *some* VECTOR_SHUFFLE operations, those with specific masks. |
| 4369 | /// By default, if a target supports the VECTOR_SHUFFLE node, all mask values |
| 4370 | /// are assumed to be legal. |
| 4371 | bool |
| 4372 | ARMTargetLowering::isShuffleMaskLegal(const SmallVectorImpl<int> &M, |
| 4373 | EVT VT) const { |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4374 | if (VT.getVectorNumElements() == 4 && |
| 4375 | (VT.is128BitVector() || VT.is64BitVector())) { |
| 4376 | unsigned PFIndexes[4]; |
| 4377 | for (unsigned i = 0; i != 4; ++i) { |
| 4378 | if (M[i] < 0) |
| 4379 | PFIndexes[i] = 8; |
| 4380 | else |
| 4381 | PFIndexes[i] = M[i]; |
| 4382 | } |
| 4383 | |
| 4384 | // Compute the index in the perfect shuffle table. |
| 4385 | unsigned PFTableIndex = |
| 4386 | PFIndexes[0]*9*9*9+PFIndexes[1]*9*9+PFIndexes[2]*9+PFIndexes[3]; |
| 4387 | unsigned PFEntry = PerfectShuffleTable[PFTableIndex]; |
| 4388 | unsigned Cost = (PFEntry >> 30); |
| 4389 | |
| 4390 | if (Cost <= 4) |
| 4391 | return true; |
| 4392 | } |
| 4393 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4394 | bool ReverseVEXT; |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4395 | unsigned Imm, WhichResult; |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4396 | |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4397 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 4398 | return (EltSize >= 32 || |
| 4399 | ShuffleVectorSDNode::isSplatMask(&M[0], VT) || |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4400 | isVREVMask(M, VT, 64) || |
| 4401 | isVREVMask(M, VT, 32) || |
| 4402 | isVREVMask(M, VT, 16) || |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4403 | isVEXTMask(M, VT, ReverseVEXT, Imm) || |
Bill Wendling | 0d4c9d9 | 2011-03-15 21:15:20 +0000 | [diff] [blame] | 4404 | isVTBLMask(M, VT) || |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4405 | isVTRNMask(M, VT, WhichResult) || |
| 4406 | isVUZPMask(M, VT, WhichResult) || |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4407 | isVZIPMask(M, VT, WhichResult) || |
| 4408 | isVTRN_v_undef_Mask(M, VT, WhichResult) || |
| 4409 | isVUZP_v_undef_Mask(M, VT, WhichResult) || |
| 4410 | isVZIP_v_undef_Mask(M, VT, WhichResult)); |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4411 | } |
| 4412 | |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4413 | /// GeneratePerfectShuffle - Given an entry in the perfect-shuffle table, emit |
| 4414 | /// the specified operations to build the shuffle. |
| 4415 | static SDValue GeneratePerfectShuffle(unsigned PFEntry, SDValue LHS, |
| 4416 | SDValue RHS, SelectionDAG &DAG, |
| 4417 | DebugLoc dl) { |
| 4418 | unsigned OpNum = (PFEntry >> 26) & 0x0F; |
| 4419 | unsigned LHSID = (PFEntry >> 13) & ((1 << 13)-1); |
| 4420 | unsigned RHSID = (PFEntry >> 0) & ((1 << 13)-1); |
| 4421 | |
| 4422 | enum { |
| 4423 | OP_COPY = 0, // Copy, used for things like <u,u,u,3> to say it is <0,1,2,3> |
| 4424 | OP_VREV, |
| 4425 | OP_VDUP0, |
| 4426 | OP_VDUP1, |
| 4427 | OP_VDUP2, |
| 4428 | OP_VDUP3, |
| 4429 | OP_VEXT1, |
| 4430 | OP_VEXT2, |
| 4431 | OP_VEXT3, |
| 4432 | OP_VUZPL, // VUZP, left result |
| 4433 | OP_VUZPR, // VUZP, right result |
| 4434 | OP_VZIPL, // VZIP, left result |
| 4435 | OP_VZIPR, // VZIP, right result |
| 4436 | OP_VTRNL, // VTRN, left result |
| 4437 | OP_VTRNR // VTRN, right result |
| 4438 | }; |
| 4439 | |
| 4440 | if (OpNum == OP_COPY) { |
| 4441 | if (LHSID == (1*9+2)*9+3) return LHS; |
| 4442 | assert(LHSID == ((4*9+5)*9+6)*9+7 && "Illegal OP_COPY!"); |
| 4443 | return RHS; |
| 4444 | } |
| 4445 | |
| 4446 | SDValue OpLHS, OpRHS; |
| 4447 | OpLHS = GeneratePerfectShuffle(PerfectShuffleTable[LHSID], LHS, RHS, DAG, dl); |
| 4448 | OpRHS = GeneratePerfectShuffle(PerfectShuffleTable[RHSID], LHS, RHS, DAG, dl); |
| 4449 | EVT VT = OpLHS.getValueType(); |
| 4450 | |
| 4451 | switch (OpNum) { |
| 4452 | default: llvm_unreachable("Unknown shuffle opcode!"); |
| 4453 | case OP_VREV: |
Tanya Lattner | 2a8eb72 | 2011-05-18 06:42:21 +0000 | [diff] [blame] | 4454 | // VREV divides the vector in half and swaps within the half. |
Tanya Lattner | db28247 | 2011-05-18 21:44:54 +0000 | [diff] [blame] | 4455 | if (VT.getVectorElementType() == MVT::i32 || |
| 4456 | VT.getVectorElementType() == MVT::f32) |
Tanya Lattner | 2a8eb72 | 2011-05-18 06:42:21 +0000 | [diff] [blame] | 4457 | return DAG.getNode(ARMISD::VREV64, dl, VT, OpLHS); |
| 4458 | // vrev <4 x i16> -> VREV32 |
| 4459 | if (VT.getVectorElementType() == MVT::i16) |
| 4460 | return DAG.getNode(ARMISD::VREV32, dl, VT, OpLHS); |
| 4461 | // vrev <4 x i8> -> VREV16 |
| 4462 | assert(VT.getVectorElementType() == MVT::i8); |
| 4463 | return DAG.getNode(ARMISD::VREV16, dl, VT, OpLHS); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4464 | case OP_VDUP0: |
| 4465 | case OP_VDUP1: |
| 4466 | case OP_VDUP2: |
| 4467 | case OP_VDUP3: |
| 4468 | return DAG.getNode(ARMISD::VDUPLANE, dl, VT, |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 4469 | OpLHS, DAG.getConstant(OpNum-OP_VDUP0, MVT::i32)); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4470 | case OP_VEXT1: |
| 4471 | case OP_VEXT2: |
| 4472 | case OP_VEXT3: |
| 4473 | return DAG.getNode(ARMISD::VEXT, dl, VT, |
| 4474 | OpLHS, OpRHS, |
| 4475 | DAG.getConstant(OpNum-OP_VEXT1+1, MVT::i32)); |
| 4476 | case OP_VUZPL: |
| 4477 | case OP_VUZPR: |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 4478 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4479 | OpLHS, OpRHS).getValue(OpNum-OP_VUZPL); |
| 4480 | case OP_VZIPL: |
| 4481 | case OP_VZIPR: |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 4482 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4483 | OpLHS, OpRHS).getValue(OpNum-OP_VZIPL); |
| 4484 | case OP_VTRNL: |
| 4485 | case OP_VTRNR: |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 4486 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), |
| 4487 | OpLHS, OpRHS).getValue(OpNum-OP_VTRNL); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4488 | } |
| 4489 | } |
| 4490 | |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4491 | static SDValue LowerVECTOR_SHUFFLEv8i8(SDValue Op, |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4492 | ArrayRef<int> ShuffleMask, |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4493 | SelectionDAG &DAG) { |
| 4494 | // Check to see if we can use the VTBL instruction. |
| 4495 | SDValue V1 = Op.getOperand(0); |
| 4496 | SDValue V2 = Op.getOperand(1); |
| 4497 | DebugLoc DL = Op.getDebugLoc(); |
| 4498 | |
| 4499 | SmallVector<SDValue, 8> VTBLMask; |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4500 | for (ArrayRef<int>::iterator |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4501 | I = ShuffleMask.begin(), E = ShuffleMask.end(); I != E; ++I) |
| 4502 | VTBLMask.push_back(DAG.getConstant(*I, MVT::i32)); |
| 4503 | |
| 4504 | if (V2.getNode()->getOpcode() == ISD::UNDEF) |
| 4505 | return DAG.getNode(ARMISD::VTBL1, DL, MVT::v8i8, V1, |
| 4506 | DAG.getNode(ISD::BUILD_VECTOR, DL, MVT::v8i8, |
| 4507 | &VTBLMask[0], 8)); |
Bill Wendling | a24cb40 | 2011-03-15 20:47:26 +0000 | [diff] [blame] | 4508 | |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4509 | return DAG.getNode(ARMISD::VTBL2, DL, MVT::v8i8, V1, V2, |
Bill Wendling | a24cb40 | 2011-03-15 20:47:26 +0000 | [diff] [blame] | 4510 | DAG.getNode(ISD::BUILD_VECTOR, DL, MVT::v8i8, |
| 4511 | &VTBLMask[0], 8)); |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4512 | } |
| 4513 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4514 | static SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) { |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4515 | SDValue V1 = Op.getOperand(0); |
| 4516 | SDValue V2 = Op.getOperand(1); |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 4517 | DebugLoc dl = Op.getDebugLoc(); |
| 4518 | EVT VT = Op.getValueType(); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4519 | ShuffleVectorSDNode *SVN = cast<ShuffleVectorSDNode>(Op.getNode()); |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 4520 | |
Bob Wilson | 2886506 | 2009-08-13 02:13:04 +0000 | [diff] [blame] | 4521 | // Convert shuffles that are directly supported on NEON to target-specific |
| 4522 | // DAG nodes, instead of keeping them as shuffles and matching them again |
| 4523 | // during code selection. This is more efficient and avoids the possibility |
| 4524 | // of inconsistencies between legalization and selection. |
Bob Wilson | bfcbb50 | 2009-08-13 06:01:30 +0000 | [diff] [blame] | 4525 | // FIXME: floating-point vectors should be canonicalized to integer vectors |
| 4526 | // of the same time so that they get CSEd properly. |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4527 | ArrayRef<int> ShuffleMask = SVN->getMask(); |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4528 | |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4529 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 4530 | if (EltSize <= 32) { |
| 4531 | if (ShuffleVectorSDNode::isSplatMask(&ShuffleMask[0], VT)) { |
| 4532 | int Lane = SVN->getSplatIndex(); |
| 4533 | // If this is undef splat, generate it via "just" vdup, if possible. |
| 4534 | if (Lane == -1) Lane = 0; |
Anton Korobeynikov | 2ae0eec | 2009-11-02 00:12:06 +0000 | [diff] [blame] | 4535 | |
Dan Gohman | 65fd656 | 2011-11-03 21:49:52 +0000 | [diff] [blame] | 4536 | // Test if V1 is a SCALAR_TO_VECTOR. |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4537 | if (Lane == 0 && V1.getOpcode() == ISD::SCALAR_TO_VECTOR) { |
| 4538 | return DAG.getNode(ARMISD::VDUP, dl, VT, V1.getOperand(0)); |
| 4539 | } |
Dan Gohman | 65fd656 | 2011-11-03 21:49:52 +0000 | [diff] [blame] | 4540 | // Test if V1 is a BUILD_VECTOR which is equivalent to a SCALAR_TO_VECTOR |
| 4541 | // (and probably will turn into a SCALAR_TO_VECTOR once legalization |
| 4542 | // reaches it). |
| 4543 | if (Lane == 0 && V1.getOpcode() == ISD::BUILD_VECTOR && |
| 4544 | !isa<ConstantSDNode>(V1.getOperand(0))) { |
| 4545 | bool IsScalarToVector = true; |
| 4546 | for (unsigned i = 1, e = V1.getNumOperands(); i != e; ++i) |
| 4547 | if (V1.getOperand(i).getOpcode() != ISD::UNDEF) { |
| 4548 | IsScalarToVector = false; |
| 4549 | break; |
| 4550 | } |
| 4551 | if (IsScalarToVector) |
| 4552 | return DAG.getNode(ARMISD::VDUP, dl, VT, V1.getOperand(0)); |
| 4553 | } |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4554 | return DAG.getNode(ARMISD::VDUPLANE, dl, VT, V1, |
| 4555 | DAG.getConstant(Lane, MVT::i32)); |
Bob Wilson | c1d287b | 2009-08-14 05:13:08 +0000 | [diff] [blame] | 4556 | } |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4557 | |
| 4558 | bool ReverseVEXT; |
| 4559 | unsigned Imm; |
| 4560 | if (isVEXTMask(ShuffleMask, VT, ReverseVEXT, Imm)) { |
| 4561 | if (ReverseVEXT) |
| 4562 | std::swap(V1, V2); |
| 4563 | return DAG.getNode(ARMISD::VEXT, dl, VT, V1, V2, |
| 4564 | DAG.getConstant(Imm, MVT::i32)); |
| 4565 | } |
| 4566 | |
| 4567 | if (isVREVMask(ShuffleMask, VT, 64)) |
| 4568 | return DAG.getNode(ARMISD::VREV64, dl, VT, V1); |
| 4569 | if (isVREVMask(ShuffleMask, VT, 32)) |
| 4570 | return DAG.getNode(ARMISD::VREV32, dl, VT, V1); |
| 4571 | if (isVREVMask(ShuffleMask, VT, 16)) |
| 4572 | return DAG.getNode(ARMISD::VREV16, dl, VT, V1); |
| 4573 | |
| 4574 | // Check for Neon shuffles that modify both input vectors in place. |
| 4575 | // If both results are used, i.e., if there are two shuffles with the same |
| 4576 | // source operands and with masks corresponding to both results of one of |
| 4577 | // these operations, DAG memoization will ensure that a single node is |
| 4578 | // used for both shuffles. |
| 4579 | unsigned WhichResult; |
| 4580 | if (isVTRNMask(ShuffleMask, VT, WhichResult)) |
| 4581 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), |
| 4582 | V1, V2).getValue(WhichResult); |
| 4583 | if (isVUZPMask(ShuffleMask, VT, WhichResult)) |
| 4584 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), |
| 4585 | V1, V2).getValue(WhichResult); |
| 4586 | if (isVZIPMask(ShuffleMask, VT, WhichResult)) |
| 4587 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), |
| 4588 | V1, V2).getValue(WhichResult); |
| 4589 | |
| 4590 | if (isVTRN_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 4591 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), |
| 4592 | V1, V1).getValue(WhichResult); |
| 4593 | if (isVUZP_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 4594 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), |
| 4595 | V1, V1).getValue(WhichResult); |
| 4596 | if (isVZIP_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 4597 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), |
| 4598 | V1, V1).getValue(WhichResult); |
Bob Wilson | 0ce3710 | 2009-08-14 05:08:32 +0000 | [diff] [blame] | 4599 | } |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 4600 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4601 | // If the shuffle is not directly supported and it has 4 elements, use |
| 4602 | // the PerfectShuffle-generated table to synthesize it from other shuffles. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4603 | unsigned NumElts = VT.getVectorNumElements(); |
| 4604 | if (NumElts == 4) { |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4605 | unsigned PFIndexes[4]; |
| 4606 | for (unsigned i = 0; i != 4; ++i) { |
| 4607 | if (ShuffleMask[i] < 0) |
| 4608 | PFIndexes[i] = 8; |
| 4609 | else |
| 4610 | PFIndexes[i] = ShuffleMask[i]; |
| 4611 | } |
| 4612 | |
| 4613 | // Compute the index in the perfect shuffle table. |
| 4614 | unsigned PFTableIndex = |
| 4615 | 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] | 4616 | unsigned PFEntry = PerfectShuffleTable[PFTableIndex]; |
| 4617 | unsigned Cost = (PFEntry >> 30); |
| 4618 | |
| 4619 | if (Cost <= 4) |
| 4620 | return GeneratePerfectShuffle(PFEntry, V1, V2, DAG, dl); |
| 4621 | } |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 4622 | |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4623 | // Implement shuffles with 32- or 64-bit elements as ARMISD::BUILD_VECTORs. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4624 | if (EltSize >= 32) { |
| 4625 | // Do the expansion with floating-point types, since that is what the VFP |
| 4626 | // registers are defined to use, and since i64 is not legal. |
| 4627 | EVT EltVT = EVT::getFloatingPointVT(EltSize); |
| 4628 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), EltVT, NumElts); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4629 | V1 = DAG.getNode(ISD::BITCAST, dl, VecVT, V1); |
| 4630 | V2 = DAG.getNode(ISD::BITCAST, dl, VecVT, V2); |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4631 | SmallVector<SDValue, 8> Ops; |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4632 | for (unsigned i = 0; i < NumElts; ++i) { |
Bob Wilson | 63b8845 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 4633 | if (ShuffleMask[i] < 0) |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4634 | Ops.push_back(DAG.getUNDEF(EltVT)); |
| 4635 | else |
| 4636 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, EltVT, |
| 4637 | ShuffleMask[i] < (int)NumElts ? V1 : V2, |
| 4638 | DAG.getConstant(ShuffleMask[i] & (NumElts-1), |
| 4639 | MVT::i32))); |
Bob Wilson | 63b8845 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 4640 | } |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4641 | SDValue Val = DAG.getNode(ARMISD::BUILD_VECTOR, dl, VecVT, &Ops[0],NumElts); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4642 | return DAG.getNode(ISD::BITCAST, dl, VT, Val); |
Bob Wilson | 63b8845 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 4643 | } |
| 4644 | |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4645 | if (VT == MVT::v8i8) { |
| 4646 | SDValue NewOp = LowerVECTOR_SHUFFLEv8i8(Op, ShuffleMask, DAG); |
| 4647 | if (NewOp.getNode()) |
| 4648 | return NewOp; |
| 4649 | } |
| 4650 | |
Bob Wilson | 22cac0d | 2009-08-14 05:16:33 +0000 | [diff] [blame] | 4651 | return SDValue(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4652 | } |
| 4653 | |
Eli Friedman | 5c89cb8 | 2011-10-24 23:08:52 +0000 | [diff] [blame] | 4654 | static SDValue LowerINSERT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) { |
| 4655 | // INSERT_VECTOR_ELT is legal only for immediate indexes. |
| 4656 | SDValue Lane = Op.getOperand(2); |
| 4657 | if (!isa<ConstantSDNode>(Lane)) |
| 4658 | return SDValue(); |
| 4659 | |
| 4660 | return Op; |
| 4661 | } |
| 4662 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4663 | static SDValue LowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) { |
Bob Wilson | 3468c2e | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 4664 | // EXTRACT_VECTOR_ELT is legal only for immediate indexes. |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4665 | SDValue Lane = Op.getOperand(1); |
Bob Wilson | 3468c2e | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 4666 | if (!isa<ConstantSDNode>(Lane)) |
| 4667 | return SDValue(); |
| 4668 | |
| 4669 | SDValue Vec = Op.getOperand(0); |
| 4670 | if (Op.getValueType() == MVT::i32 && |
| 4671 | Vec.getValueType().getVectorElementType().getSizeInBits() < 32) { |
| 4672 | DebugLoc dl = Op.getDebugLoc(); |
| 4673 | return DAG.getNode(ARMISD::VGETLANEu, dl, MVT::i32, Vec, Lane); |
| 4674 | } |
| 4675 | |
| 4676 | return Op; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4677 | } |
| 4678 | |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 4679 | static SDValue LowerCONCAT_VECTORS(SDValue Op, SelectionDAG &DAG) { |
| 4680 | // The only time a CONCAT_VECTORS operation can have legal types is when |
| 4681 | // two 64-bit vectors are concatenated to a 128-bit vector. |
| 4682 | assert(Op.getValueType().is128BitVector() && Op.getNumOperands() == 2 && |
| 4683 | "unexpected CONCAT_VECTORS"); |
| 4684 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4685 | SDValue Val = DAG.getUNDEF(MVT::v2f64); |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 4686 | SDValue Op0 = Op.getOperand(0); |
| 4687 | SDValue Op1 = Op.getOperand(1); |
| 4688 | if (Op0.getOpcode() != ISD::UNDEF) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4689 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Val, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4690 | DAG.getNode(ISD::BITCAST, dl, MVT::f64, Op0), |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 4691 | DAG.getIntPtrConstant(0)); |
| 4692 | if (Op1.getOpcode() != ISD::UNDEF) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4693 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Val, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4694 | DAG.getNode(ISD::BITCAST, dl, MVT::f64, Op1), |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 4695 | DAG.getIntPtrConstant(1)); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4696 | return DAG.getNode(ISD::BITCAST, dl, Op.getValueType(), Val); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4697 | } |
| 4698 | |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 4699 | /// isExtendedBUILD_VECTOR - Check if N is a constant BUILD_VECTOR where each |
| 4700 | /// element has been zero/sign-extended, depending on the isSigned parameter, |
| 4701 | /// from an integer type half its size. |
| 4702 | static bool isExtendedBUILD_VECTOR(SDNode *N, SelectionDAG &DAG, |
| 4703 | bool isSigned) { |
| 4704 | // A v2i64 BUILD_VECTOR will have been legalized to a BITCAST from v4i32. |
| 4705 | EVT VT = N->getValueType(0); |
| 4706 | if (VT == MVT::v2i64 && N->getOpcode() == ISD::BITCAST) { |
| 4707 | SDNode *BVN = N->getOperand(0).getNode(); |
| 4708 | if (BVN->getValueType(0) != MVT::v4i32 || |
| 4709 | BVN->getOpcode() != ISD::BUILD_VECTOR) |
| 4710 | return false; |
| 4711 | unsigned LoElt = DAG.getTargetLoweringInfo().isBigEndian() ? 1 : 0; |
| 4712 | unsigned HiElt = 1 - LoElt; |
| 4713 | ConstantSDNode *Lo0 = dyn_cast<ConstantSDNode>(BVN->getOperand(LoElt)); |
| 4714 | ConstantSDNode *Hi0 = dyn_cast<ConstantSDNode>(BVN->getOperand(HiElt)); |
| 4715 | ConstantSDNode *Lo1 = dyn_cast<ConstantSDNode>(BVN->getOperand(LoElt+2)); |
| 4716 | ConstantSDNode *Hi1 = dyn_cast<ConstantSDNode>(BVN->getOperand(HiElt+2)); |
| 4717 | if (!Lo0 || !Hi0 || !Lo1 || !Hi1) |
| 4718 | return false; |
| 4719 | if (isSigned) { |
| 4720 | if (Hi0->getSExtValue() == Lo0->getSExtValue() >> 32 && |
| 4721 | Hi1->getSExtValue() == Lo1->getSExtValue() >> 32) |
| 4722 | return true; |
| 4723 | } else { |
| 4724 | if (Hi0->isNullValue() && Hi1->isNullValue()) |
| 4725 | return true; |
| 4726 | } |
| 4727 | return false; |
| 4728 | } |
| 4729 | |
| 4730 | if (N->getOpcode() != ISD::BUILD_VECTOR) |
| 4731 | return false; |
| 4732 | |
| 4733 | for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) { |
| 4734 | SDNode *Elt = N->getOperand(i).getNode(); |
| 4735 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Elt)) { |
| 4736 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 4737 | unsigned HalfSize = EltSize / 2; |
| 4738 | if (isSigned) { |
Bob Wilson | 9d45de2 | 2011-10-18 18:46:49 +0000 | [diff] [blame] | 4739 | if (!isIntN(HalfSize, C->getSExtValue())) |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 4740 | return false; |
| 4741 | } else { |
Bob Wilson | 9d45de2 | 2011-10-18 18:46:49 +0000 | [diff] [blame] | 4742 | if (!isUIntN(HalfSize, C->getZExtValue())) |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 4743 | return false; |
| 4744 | } |
| 4745 | continue; |
| 4746 | } |
| 4747 | return false; |
| 4748 | } |
| 4749 | |
| 4750 | return true; |
| 4751 | } |
| 4752 | |
| 4753 | /// isSignExtended - Check if a node is a vector value that is sign-extended |
| 4754 | /// or a constant BUILD_VECTOR with sign-extended elements. |
| 4755 | static bool isSignExtended(SDNode *N, SelectionDAG &DAG) { |
| 4756 | if (N->getOpcode() == ISD::SIGN_EXTEND || ISD::isSEXTLoad(N)) |
| 4757 | return true; |
| 4758 | if (isExtendedBUILD_VECTOR(N, DAG, true)) |
| 4759 | return true; |
| 4760 | return false; |
| 4761 | } |
| 4762 | |
| 4763 | /// isZeroExtended - Check if a node is a vector value that is zero-extended |
| 4764 | /// or a constant BUILD_VECTOR with zero-extended elements. |
| 4765 | static bool isZeroExtended(SDNode *N, SelectionDAG &DAG) { |
| 4766 | if (N->getOpcode() == ISD::ZERO_EXTEND || ISD::isZEXTLoad(N)) |
| 4767 | return true; |
| 4768 | if (isExtendedBUILD_VECTOR(N, DAG, false)) |
| 4769 | return true; |
| 4770 | return false; |
| 4771 | } |
| 4772 | |
| 4773 | /// SkipExtension - For a node that is a SIGN_EXTEND, ZERO_EXTEND, extending |
| 4774 | /// load, or BUILD_VECTOR with extended elements, return the unextended value. |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4775 | static SDValue SkipExtension(SDNode *N, SelectionDAG &DAG) { |
| 4776 | if (N->getOpcode() == ISD::SIGN_EXTEND || N->getOpcode() == ISD::ZERO_EXTEND) |
| 4777 | return N->getOperand(0); |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 4778 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) |
| 4779 | return DAG.getLoad(LD->getMemoryVT(), N->getDebugLoc(), LD->getChain(), |
| 4780 | LD->getBasePtr(), LD->getPointerInfo(), LD->isVolatile(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 4781 | LD->isNonTemporal(), LD->isInvariant(), |
| 4782 | LD->getAlignment()); |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 4783 | // Otherwise, the value must be a BUILD_VECTOR. For v2i64, it will |
| 4784 | // have been legalized as a BITCAST from v4i32. |
| 4785 | if (N->getOpcode() == ISD::BITCAST) { |
| 4786 | SDNode *BVN = N->getOperand(0).getNode(); |
| 4787 | assert(BVN->getOpcode() == ISD::BUILD_VECTOR && |
| 4788 | BVN->getValueType(0) == MVT::v4i32 && "expected v4i32 BUILD_VECTOR"); |
| 4789 | unsigned LowElt = DAG.getTargetLoweringInfo().isBigEndian() ? 1 : 0; |
| 4790 | return DAG.getNode(ISD::BUILD_VECTOR, N->getDebugLoc(), MVT::v2i32, |
| 4791 | BVN->getOperand(LowElt), BVN->getOperand(LowElt+2)); |
| 4792 | } |
| 4793 | // Construct a new BUILD_VECTOR with elements truncated to half the size. |
| 4794 | assert(N->getOpcode() == ISD::BUILD_VECTOR && "expected BUILD_VECTOR"); |
| 4795 | EVT VT = N->getValueType(0); |
| 4796 | unsigned EltSize = VT.getVectorElementType().getSizeInBits() / 2; |
| 4797 | unsigned NumElts = VT.getVectorNumElements(); |
| 4798 | MVT TruncVT = MVT::getIntegerVT(EltSize); |
| 4799 | SmallVector<SDValue, 8> Ops; |
| 4800 | for (unsigned i = 0; i != NumElts; ++i) { |
| 4801 | ConstantSDNode *C = cast<ConstantSDNode>(N->getOperand(i)); |
| 4802 | const APInt &CInt = C->getAPIntValue(); |
Bob Wilson | ff73d8f | 2012-04-30 16:53:34 +0000 | [diff] [blame] | 4803 | // Element types smaller than 32 bits are not legal, so use i32 elements. |
| 4804 | // The values are implicitly truncated so sext vs. zext doesn't matter. |
| 4805 | Ops.push_back(DAG.getConstant(CInt.zextOrTrunc(32), MVT::i32)); |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 4806 | } |
| 4807 | return DAG.getNode(ISD::BUILD_VECTOR, N->getDebugLoc(), |
| 4808 | MVT::getVectorVT(TruncVT, NumElts), Ops.data(), NumElts); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4809 | } |
| 4810 | |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 4811 | static bool isAddSubSExt(SDNode *N, SelectionDAG &DAG) { |
| 4812 | unsigned Opcode = N->getOpcode(); |
| 4813 | if (Opcode == ISD::ADD || Opcode == ISD::SUB) { |
| 4814 | SDNode *N0 = N->getOperand(0).getNode(); |
| 4815 | SDNode *N1 = N->getOperand(1).getNode(); |
| 4816 | return N0->hasOneUse() && N1->hasOneUse() && |
| 4817 | isSignExtended(N0, DAG) && isSignExtended(N1, DAG); |
| 4818 | } |
| 4819 | return false; |
| 4820 | } |
| 4821 | |
| 4822 | static bool isAddSubZExt(SDNode *N, SelectionDAG &DAG) { |
| 4823 | unsigned Opcode = N->getOpcode(); |
| 4824 | if (Opcode == ISD::ADD || Opcode == ISD::SUB) { |
| 4825 | SDNode *N0 = N->getOperand(0).getNode(); |
| 4826 | SDNode *N1 = N->getOperand(1).getNode(); |
| 4827 | return N0->hasOneUse() && N1->hasOneUse() && |
| 4828 | isZeroExtended(N0, DAG) && isZeroExtended(N1, DAG); |
| 4829 | } |
| 4830 | return false; |
| 4831 | } |
| 4832 | |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4833 | static SDValue LowerMUL(SDValue Op, SelectionDAG &DAG) { |
| 4834 | // Multiplications are only custom-lowered for 128-bit vectors so that |
| 4835 | // VMULL can be detected. Otherwise v2i64 multiplications are not legal. |
| 4836 | EVT VT = Op.getValueType(); |
| 4837 | assert(VT.is128BitVector() && "unexpected type for custom-lowering ISD::MUL"); |
| 4838 | SDNode *N0 = Op.getOperand(0).getNode(); |
| 4839 | SDNode *N1 = Op.getOperand(1).getNode(); |
| 4840 | unsigned NewOpc = 0; |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 4841 | bool isMLA = false; |
| 4842 | bool isN0SExt = isSignExtended(N0, DAG); |
| 4843 | bool isN1SExt = isSignExtended(N1, DAG); |
| 4844 | if (isN0SExt && isN1SExt) |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4845 | NewOpc = ARMISD::VMULLs; |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 4846 | else { |
| 4847 | bool isN0ZExt = isZeroExtended(N0, DAG); |
| 4848 | bool isN1ZExt = isZeroExtended(N1, DAG); |
| 4849 | if (isN0ZExt && isN1ZExt) |
| 4850 | NewOpc = ARMISD::VMULLu; |
| 4851 | else if (isN1SExt || isN1ZExt) { |
| 4852 | // Look for (s/zext A + s/zext B) * (s/zext C). We want to turn these |
| 4853 | // into (s/zext A * s/zext C) + (s/zext B * s/zext C) |
| 4854 | if (isN1SExt && isAddSubSExt(N0, DAG)) { |
| 4855 | NewOpc = ARMISD::VMULLs; |
| 4856 | isMLA = true; |
| 4857 | } else if (isN1ZExt && isAddSubZExt(N0, DAG)) { |
| 4858 | NewOpc = ARMISD::VMULLu; |
| 4859 | isMLA = true; |
| 4860 | } else if (isN0ZExt && isAddSubZExt(N1, DAG)) { |
| 4861 | std::swap(N0, N1); |
| 4862 | NewOpc = ARMISD::VMULLu; |
| 4863 | isMLA = true; |
| 4864 | } |
| 4865 | } |
| 4866 | |
| 4867 | if (!NewOpc) { |
| 4868 | if (VT == MVT::v2i64) |
| 4869 | // Fall through to expand this. It is not legal. |
| 4870 | return SDValue(); |
| 4871 | else |
| 4872 | // Other vector multiplications are legal. |
| 4873 | return Op; |
| 4874 | } |
| 4875 | } |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4876 | |
| 4877 | // Legalize to a VMULL instruction. |
| 4878 | DebugLoc DL = Op.getDebugLoc(); |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 4879 | SDValue Op0; |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4880 | SDValue Op1 = SkipExtension(N1, DAG); |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 4881 | if (!isMLA) { |
| 4882 | Op0 = SkipExtension(N0, DAG); |
| 4883 | assert(Op0.getValueType().is64BitVector() && |
| 4884 | Op1.getValueType().is64BitVector() && |
| 4885 | "unexpected types for extended operands to VMULL"); |
| 4886 | return DAG.getNode(NewOpc, DL, VT, Op0, Op1); |
| 4887 | } |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4888 | |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 4889 | // Optimizing (zext A + zext B) * C, to (VMULL A, C) + (VMULL B, C) during |
| 4890 | // isel lowering to take advantage of no-stall back to back vmul + vmla. |
| 4891 | // vmull q0, d4, d6 |
| 4892 | // vmlal q0, d5, d6 |
| 4893 | // is faster than |
| 4894 | // vaddl q0, d4, d5 |
| 4895 | // vmovl q1, d6 |
| 4896 | // vmul q0, q0, q1 |
| 4897 | SDValue N00 = SkipExtension(N0->getOperand(0).getNode(), DAG); |
| 4898 | SDValue N01 = SkipExtension(N0->getOperand(1).getNode(), DAG); |
| 4899 | EVT Op1VT = Op1.getValueType(); |
| 4900 | return DAG.getNode(N0->getOpcode(), DL, VT, |
| 4901 | DAG.getNode(NewOpc, DL, VT, |
| 4902 | DAG.getNode(ISD::BITCAST, DL, Op1VT, N00), Op1), |
| 4903 | DAG.getNode(NewOpc, DL, VT, |
| 4904 | DAG.getNode(ISD::BITCAST, DL, Op1VT, N01), Op1)); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4905 | } |
| 4906 | |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4907 | static SDValue |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4908 | LowerSDIV_v4i8(SDValue X, SDValue Y, DebugLoc dl, SelectionDAG &DAG) { |
| 4909 | // Convert to float |
| 4910 | // float4 xf = vcvt_f32_s32(vmovl_s16(a.lo)); |
| 4911 | // float4 yf = vcvt_f32_s32(vmovl_s16(b.lo)); |
| 4912 | X = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, X); |
| 4913 | Y = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, Y); |
| 4914 | X = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, X); |
| 4915 | Y = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, Y); |
| 4916 | // Get reciprocal estimate. |
| 4917 | // float4 recip = vrecpeq_f32(yf); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4918 | Y = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4919 | DAG.getConstant(Intrinsic::arm_neon_vrecpe, MVT::i32), Y); |
| 4920 | // Because char has a smaller range than uchar, we can actually get away |
| 4921 | // without any newton steps. This requires that we use a weird bias |
| 4922 | // of 0xb000, however (again, this has been exhaustively tested). |
| 4923 | // float4 result = as_float4(as_int4(xf*recip) + 0xb000); |
| 4924 | X = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, X, Y); |
| 4925 | X = DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, X); |
| 4926 | Y = DAG.getConstant(0xb000, MVT::i32); |
| 4927 | Y = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, Y, Y, Y, Y); |
| 4928 | X = DAG.getNode(ISD::ADD, dl, MVT::v4i32, X, Y); |
| 4929 | X = DAG.getNode(ISD::BITCAST, dl, MVT::v4f32, X); |
| 4930 | // Convert back to short. |
| 4931 | X = DAG.getNode(ISD::FP_TO_SINT, dl, MVT::v4i32, X); |
| 4932 | X = DAG.getNode(ISD::TRUNCATE, dl, MVT::v4i16, X); |
| 4933 | return X; |
| 4934 | } |
| 4935 | |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4936 | static SDValue |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4937 | LowerSDIV_v4i16(SDValue N0, SDValue N1, DebugLoc dl, SelectionDAG &DAG) { |
| 4938 | SDValue N2; |
| 4939 | // Convert to float. |
| 4940 | // float4 yf = vcvt_f32_s32(vmovl_s16(y)); |
| 4941 | // float4 xf = vcvt_f32_s32(vmovl_s16(x)); |
| 4942 | N0 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, N0); |
| 4943 | N1 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, N1); |
| 4944 | N0 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N0); |
| 4945 | N1 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4946 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4947 | // Use reciprocal estimate and one refinement step. |
| 4948 | // float4 recip = vrecpeq_f32(yf); |
| 4949 | // recip *= vrecpsq_f32(yf, recip); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4950 | N2 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4951 | DAG.getConstant(Intrinsic::arm_neon_vrecpe, MVT::i32), N1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4952 | N1 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4953 | DAG.getConstant(Intrinsic::arm_neon_vrecps, MVT::i32), |
| 4954 | N1, N2); |
| 4955 | N2 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N1, N2); |
| 4956 | // Because short has a smaller range than ushort, we can actually get away |
| 4957 | // with only a single newton step. This requires that we use a weird bias |
| 4958 | // of 89, however (again, this has been exhaustively tested). |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 4959 | // float4 result = as_float4(as_int4(xf*recip) + 0x89); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4960 | N0 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N0, N2); |
| 4961 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, N0); |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 4962 | N1 = DAG.getConstant(0x89, MVT::i32); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4963 | N1 = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, N1, N1, N1, N1); |
| 4964 | N0 = DAG.getNode(ISD::ADD, dl, MVT::v4i32, N0, N1); |
| 4965 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4f32, N0); |
| 4966 | // Convert back to integer and return. |
| 4967 | // return vmovn_s32(vcvt_s32_f32(result)); |
| 4968 | N0 = DAG.getNode(ISD::FP_TO_SINT, dl, MVT::v4i32, N0); |
| 4969 | N0 = DAG.getNode(ISD::TRUNCATE, dl, MVT::v4i16, N0); |
| 4970 | return N0; |
| 4971 | } |
| 4972 | |
| 4973 | static SDValue LowerSDIV(SDValue Op, SelectionDAG &DAG) { |
| 4974 | EVT VT = Op.getValueType(); |
| 4975 | assert((VT == MVT::v4i16 || VT == MVT::v8i8) && |
| 4976 | "unexpected type for custom-lowering ISD::SDIV"); |
| 4977 | |
| 4978 | DebugLoc dl = Op.getDebugLoc(); |
| 4979 | SDValue N0 = Op.getOperand(0); |
| 4980 | SDValue N1 = Op.getOperand(1); |
| 4981 | SDValue N2, N3; |
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 | if (VT == MVT::v8i8) { |
| 4984 | N0 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v8i16, N0); |
| 4985 | N1 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v8i16, N1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4986 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4987 | N2 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| 4988 | DAG.getIntPtrConstant(4)); |
| 4989 | N3 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4990 | DAG.getIntPtrConstant(4)); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4991 | N0 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| 4992 | DAG.getIntPtrConstant(0)); |
| 4993 | N1 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
| 4994 | DAG.getIntPtrConstant(0)); |
| 4995 | |
| 4996 | N0 = LowerSDIV_v4i8(N0, N1, dl, DAG); // v4i16 |
| 4997 | N2 = LowerSDIV_v4i8(N2, N3, dl, DAG); // v4i16 |
| 4998 | |
| 4999 | N0 = DAG.getNode(ISD::CONCAT_VECTORS, dl, MVT::v8i16, N0, N2); |
| 5000 | N0 = LowerCONCAT_VECTORS(N0, DAG); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5001 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5002 | N0 = DAG.getNode(ISD::TRUNCATE, dl, MVT::v8i8, N0); |
| 5003 | return N0; |
| 5004 | } |
| 5005 | return LowerSDIV_v4i16(N0, N1, dl, DAG); |
| 5006 | } |
| 5007 | |
| 5008 | static SDValue LowerUDIV(SDValue Op, SelectionDAG &DAG) { |
| 5009 | EVT VT = Op.getValueType(); |
| 5010 | assert((VT == MVT::v4i16 || VT == MVT::v8i8) && |
| 5011 | "unexpected type for custom-lowering ISD::UDIV"); |
| 5012 | |
| 5013 | DebugLoc dl = Op.getDebugLoc(); |
| 5014 | SDValue N0 = Op.getOperand(0); |
| 5015 | SDValue N1 = Op.getOperand(1); |
| 5016 | SDValue N2, N3; |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5017 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5018 | if (VT == MVT::v8i8) { |
| 5019 | N0 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v8i16, N0); |
| 5020 | N1 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v8i16, N1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5021 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5022 | N2 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| 5023 | DAG.getIntPtrConstant(4)); |
| 5024 | N3 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5025 | DAG.getIntPtrConstant(4)); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5026 | N0 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| 5027 | DAG.getIntPtrConstant(0)); |
| 5028 | N1 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
| 5029 | DAG.getIntPtrConstant(0)); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5030 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5031 | N0 = LowerSDIV_v4i16(N0, N1, dl, DAG); // v4i16 |
| 5032 | N2 = LowerSDIV_v4i16(N2, N3, dl, DAG); // v4i16 |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5033 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5034 | N0 = DAG.getNode(ISD::CONCAT_VECTORS, dl, MVT::v8i16, N0, N2); |
| 5035 | N0 = LowerCONCAT_VECTORS(N0, DAG); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5036 | |
| 5037 | N0 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v8i8, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5038 | DAG.getConstant(Intrinsic::arm_neon_vqmovnsu, MVT::i32), |
| 5039 | N0); |
| 5040 | return N0; |
| 5041 | } |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5042 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5043 | // v4i16 sdiv ... Convert to float. |
| 5044 | // float4 yf = vcvt_f32_s32(vmovl_u16(y)); |
| 5045 | // float4 xf = vcvt_f32_s32(vmovl_u16(x)); |
| 5046 | N0 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v4i32, N0); |
| 5047 | N1 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v4i32, N1); |
| 5048 | N0 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N0); |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 5049 | SDValue BN1 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N1); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5050 | |
| 5051 | // Use reciprocal estimate and two refinement steps. |
| 5052 | // float4 recip = vrecpeq_f32(yf); |
| 5053 | // recip *= vrecpsq_f32(yf, recip); |
| 5054 | // recip *= vrecpsq_f32(yf, recip); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5055 | N2 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 5056 | DAG.getConstant(Intrinsic::arm_neon_vrecpe, MVT::i32), BN1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5057 | N1 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5058 | DAG.getConstant(Intrinsic::arm_neon_vrecps, MVT::i32), |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 5059 | BN1, N2); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5060 | N2 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N1, N2); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5061 | N1 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5062 | DAG.getConstant(Intrinsic::arm_neon_vrecps, MVT::i32), |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 5063 | BN1, N2); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5064 | N2 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N1, N2); |
| 5065 | // Simply multiplying by the reciprocal estimate can leave us a few ulps |
| 5066 | // too low, so we add 2 ulps (exhaustive testing shows that this is enough, |
| 5067 | // 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] | 5068 | // float4 result = as_float4(as_int4(xf*recip) + 2); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5069 | N0 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N0, N2); |
| 5070 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, N0); |
| 5071 | N1 = DAG.getConstant(2, MVT::i32); |
| 5072 | N1 = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, N1, N1, N1, N1); |
| 5073 | N0 = DAG.getNode(ISD::ADD, dl, MVT::v4i32, N0, N1); |
| 5074 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4f32, N0); |
| 5075 | // Convert back to integer and return. |
| 5076 | // return vmovn_u32(vcvt_s32_f32(result)); |
| 5077 | N0 = DAG.getNode(ISD::FP_TO_SINT, dl, MVT::v4i32, N0); |
| 5078 | N0 = DAG.getNode(ISD::TRUNCATE, dl, MVT::v4i16, N0); |
| 5079 | return N0; |
| 5080 | } |
| 5081 | |
Evan Cheng | 342e316 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 5082 | static SDValue LowerADDC_ADDE_SUBC_SUBE(SDValue Op, SelectionDAG &DAG) { |
| 5083 | EVT VT = Op.getNode()->getValueType(0); |
| 5084 | SDVTList VTs = DAG.getVTList(VT, MVT::i32); |
| 5085 | |
| 5086 | unsigned Opc; |
| 5087 | bool ExtraOp = false; |
| 5088 | switch (Op.getOpcode()) { |
Craig Topper | bc21981 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 5089 | default: llvm_unreachable("Invalid code"); |
Evan Cheng | 342e316 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 5090 | case ISD::ADDC: Opc = ARMISD::ADDC; break; |
| 5091 | case ISD::ADDE: Opc = ARMISD::ADDE; ExtraOp = true; break; |
| 5092 | case ISD::SUBC: Opc = ARMISD::SUBC; break; |
| 5093 | case ISD::SUBE: Opc = ARMISD::SUBE; ExtraOp = true; break; |
| 5094 | } |
| 5095 | |
| 5096 | if (!ExtraOp) |
| 5097 | return DAG.getNode(Opc, Op->getDebugLoc(), VTs, Op.getOperand(0), |
| 5098 | Op.getOperand(1)); |
| 5099 | return DAG.getNode(Opc, Op->getDebugLoc(), VTs, Op.getOperand(0), |
| 5100 | Op.getOperand(1), Op.getOperand(2)); |
| 5101 | } |
| 5102 | |
Eli Friedman | 74bf18c | 2011-09-15 22:26:18 +0000 | [diff] [blame] | 5103 | static SDValue LowerAtomicLoadStore(SDValue Op, SelectionDAG &DAG) { |
Eli Friedman | 7cc1566 | 2011-09-15 22:18:49 +0000 | [diff] [blame] | 5104 | // Monotonic load/store is legal for all targets |
| 5105 | if (cast<AtomicSDNode>(Op)->getOrdering() <= Monotonic) |
| 5106 | return Op; |
| 5107 | |
| 5108 | // Aquire/Release load/store is not legal for targets without a |
| 5109 | // dmb or equivalent available. |
| 5110 | return SDValue(); |
| 5111 | } |
| 5112 | |
| 5113 | |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5114 | static void |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5115 | ReplaceATOMIC_OP_64(SDNode *Node, SmallVectorImpl<SDValue>& Results, |
| 5116 | SelectionDAG &DAG, unsigned NewOp) { |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5117 | DebugLoc dl = Node->getDebugLoc(); |
Duncan Sands | 17001ce | 2011-10-18 12:44:00 +0000 | [diff] [blame] | 5118 | assert (Node->getValueType(0) == MVT::i64 && |
| 5119 | "Only know how to expand i64 atomics"); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5120 | |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5121 | SmallVector<SDValue, 6> Ops; |
| 5122 | Ops.push_back(Node->getOperand(0)); // Chain |
| 5123 | Ops.push_back(Node->getOperand(1)); // Ptr |
| 5124 | // Low part of Val1 |
| 5125 | Ops.push_back(DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, |
| 5126 | Node->getOperand(2), DAG.getIntPtrConstant(0))); |
| 5127 | // High part of Val1 |
| 5128 | Ops.push_back(DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, |
| 5129 | Node->getOperand(2), DAG.getIntPtrConstant(1))); |
Andrew Trick | 3af7a67 | 2011-09-20 03:06:13 +0000 | [diff] [blame] | 5130 | if (NewOp == ARMISD::ATOMCMPXCHG64_DAG) { |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5131 | // High part of Val1 |
| 5132 | Ops.push_back(DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, |
| 5133 | Node->getOperand(3), DAG.getIntPtrConstant(0))); |
| 5134 | // High part of Val2 |
| 5135 | Ops.push_back(DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, |
| 5136 | Node->getOperand(3), DAG.getIntPtrConstant(1))); |
| 5137 | } |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5138 | SDVTList Tys = DAG.getVTList(MVT::i32, MVT::i32, MVT::Other); |
| 5139 | SDValue Result = |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5140 | DAG.getMemIntrinsicNode(NewOp, dl, Tys, Ops.data(), Ops.size(), MVT::i64, |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5141 | cast<MemSDNode>(Node)->getMemOperand()); |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5142 | SDValue OpsF[] = { Result.getValue(0), Result.getValue(1) }; |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5143 | Results.push_back(DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, OpsF, 2)); |
| 5144 | Results.push_back(Result.getValue(2)); |
| 5145 | } |
| 5146 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 5147 | SDValue ARMTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5148 | switch (Op.getOpcode()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 5149 | default: llvm_unreachable("Don't know how to custom lower this!"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5150 | case ISD::ConstantPool: return LowerConstantPool(Op, DAG); |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 5151 | case ISD::BlockAddress: return LowerBlockAddress(Op, DAG); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 5152 | case ISD::GlobalAddress: |
| 5153 | return Subtarget->isTargetDarwin() ? LowerGlobalAddressDarwin(Op, DAG) : |
| 5154 | LowerGlobalAddressELF(Op, DAG); |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 5155 | case ISD::GlobalTLSAddress: return LowerGlobalTLSAddress(Op, DAG); |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 5156 | case ISD::SELECT: return LowerSELECT(Op, DAG); |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 5157 | case ISD::SELECT_CC: return LowerSELECT_CC(Op, DAG); |
| 5158 | case ISD::BR_CC: return LowerBR_CC(Op, DAG); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5159 | case ISD::BR_JT: return LowerBR_JT(Op, DAG); |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 5160 | case ISD::VASTART: return LowerVASTART(Op, DAG); |
Jim Grosbach | 7c03dbd | 2009-12-14 21:24:16 +0000 | [diff] [blame] | 5161 | case ISD::MEMBARRIER: return LowerMEMBARRIER(Op, DAG, Subtarget); |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 5162 | case ISD::ATOMIC_FENCE: return LowerATOMIC_FENCE(Op, DAG, Subtarget); |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 5163 | case ISD::PREFETCH: return LowerPREFETCH(Op, DAG, Subtarget); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 5164 | case ISD::SINT_TO_FP: |
| 5165 | case ISD::UINT_TO_FP: return LowerINT_TO_FP(Op, DAG); |
| 5166 | case ISD::FP_TO_SINT: |
| 5167 | case ISD::FP_TO_UINT: return LowerFP_TO_INT(Op, DAG); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5168 | case ISD::FCOPYSIGN: return LowerFCOPYSIGN(Op, DAG); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 5169 | case ISD::RETURNADDR: return LowerRETURNADDR(Op, DAG); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 5170 | case ISD::FRAMEADDR: return LowerFRAMEADDR(Op, DAG); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 5171 | case ISD::GLOBAL_OFFSET_TABLE: return LowerGLOBAL_OFFSET_TABLE(Op, DAG); |
Jim Grosbach | 23ff7cf | 2010-05-26 20:22:18 +0000 | [diff] [blame] | 5172 | case ISD::EH_SJLJ_SETJMP: return LowerEH_SJLJ_SETJMP(Op, DAG); |
Jim Grosbach | 5eb1951 | 2010-05-22 01:06:18 +0000 | [diff] [blame] | 5173 | case ISD::EH_SJLJ_LONGJMP: return LowerEH_SJLJ_LONGJMP(Op, DAG); |
Jim Grosbach | a87ded2 | 2010-02-08 23:22:00 +0000 | [diff] [blame] | 5174 | case ISD::INTRINSIC_WO_CHAIN: return LowerINTRINSIC_WO_CHAIN(Op, DAG, |
| 5175 | Subtarget); |
Evan Cheng | 21a6179 | 2011-03-14 18:02:30 +0000 | [diff] [blame] | 5176 | case ISD::BITCAST: return ExpandBITCAST(Op.getNode(), DAG); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5177 | case ISD::SHL: |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 5178 | case ISD::SRL: |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5179 | case ISD::SRA: return LowerShift(Op.getNode(), DAG, Subtarget); |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 5180 | case ISD::SHL_PARTS: return LowerShiftLeftParts(Op, DAG); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 5181 | case ISD::SRL_PARTS: |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 5182 | case ISD::SRA_PARTS: return LowerShiftRightParts(Op, DAG); |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 5183 | case ISD::CTTZ: return LowerCTTZ(Op.getNode(), DAG, Subtarget); |
Duncan Sands | 28b77e9 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 5184 | case ISD::SETCC: return LowerVSETCC(Op, DAG); |
Lang Hames | 45b5f88 | 2012-03-15 18:49:02 +0000 | [diff] [blame] | 5185 | case ISD::ConstantFP: return LowerConstantFP(Op, DAG, Subtarget); |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 5186 | case ISD::BUILD_VECTOR: return LowerBUILD_VECTOR(Op, DAG, Subtarget); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5187 | case ISD::VECTOR_SHUFFLE: return LowerVECTOR_SHUFFLE(Op, DAG); |
Eli Friedman | 5c89cb8 | 2011-10-24 23:08:52 +0000 | [diff] [blame] | 5188 | case ISD::INSERT_VECTOR_ELT: return LowerINSERT_VECTOR_ELT(Op, DAG); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5189 | case ISD::EXTRACT_VECTOR_ELT: return LowerEXTRACT_VECTOR_ELT(Op, DAG); |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 5190 | case ISD::CONCAT_VECTORS: return LowerCONCAT_VECTORS(Op, DAG); |
Bob Wilson | b31a11b | 2010-08-20 04:54:02 +0000 | [diff] [blame] | 5191 | case ISD::FLT_ROUNDS_: return LowerFLT_ROUNDS_(Op, DAG); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 5192 | case ISD::MUL: return LowerMUL(Op, DAG); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5193 | case ISD::SDIV: return LowerSDIV(Op, DAG); |
| 5194 | case ISD::UDIV: return LowerUDIV(Op, DAG); |
Evan Cheng | 342e316 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 5195 | case ISD::ADDC: |
| 5196 | case ISD::ADDE: |
| 5197 | case ISD::SUBC: |
| 5198 | case ISD::SUBE: return LowerADDC_ADDE_SUBC_SUBE(Op, DAG); |
Eli Friedman | 7cc1566 | 2011-09-15 22:18:49 +0000 | [diff] [blame] | 5199 | case ISD::ATOMIC_LOAD: |
Eli Friedman | 74bf18c | 2011-09-15 22:26:18 +0000 | [diff] [blame] | 5200 | case ISD::ATOMIC_STORE: return LowerAtomicLoadStore(Op, DAG); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5201 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5202 | } |
| 5203 | |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 5204 | /// ReplaceNodeResults - Replace the results of node with an illegal result |
| 5205 | /// type with new values built out of custom code. |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 5206 | void ARMTargetLowering::ReplaceNodeResults(SDNode *N, |
| 5207 | SmallVectorImpl<SDValue>&Results, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 5208 | SelectionDAG &DAG) const { |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 5209 | SDValue Res; |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 5210 | switch (N->getOpcode()) { |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 5211 | default: |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 5212 | llvm_unreachable("Don't know how to custom expand this!"); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5213 | case ISD::BITCAST: |
| 5214 | Res = ExpandBITCAST(N, DAG); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 5215 | break; |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 5216 | case ISD::SRL: |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 5217 | case ISD::SRA: |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 5218 | Res = Expand64BitShift(N, DAG, Subtarget); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 5219 | break; |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5220 | case ISD::ATOMIC_LOAD_ADD: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5221 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMADD64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5222 | return; |
| 5223 | case ISD::ATOMIC_LOAD_AND: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5224 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMAND64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5225 | return; |
| 5226 | case ISD::ATOMIC_LOAD_NAND: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5227 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMNAND64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5228 | return; |
| 5229 | case ISD::ATOMIC_LOAD_OR: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5230 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMOR64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5231 | return; |
| 5232 | case ISD::ATOMIC_LOAD_SUB: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5233 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMSUB64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5234 | return; |
| 5235 | case ISD::ATOMIC_LOAD_XOR: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5236 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMXOR64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5237 | return; |
| 5238 | case ISD::ATOMIC_SWAP: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5239 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMSWAP64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5240 | return; |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5241 | case ISD::ATOMIC_CMP_SWAP: |
| 5242 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMCMPXCHG64_DAG); |
| 5243 | return; |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 5244 | } |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 5245 | if (Res.getNode()) |
| 5246 | Results.push_back(Res); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 5247 | } |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 5248 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5249 | //===----------------------------------------------------------------------===// |
| 5250 | // ARM Scheduler Hooks |
| 5251 | //===----------------------------------------------------------------------===// |
| 5252 | |
| 5253 | MachineBasicBlock * |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 5254 | ARMTargetLowering::EmitAtomicCmpSwap(MachineInstr *MI, |
| 5255 | MachineBasicBlock *BB, |
| 5256 | unsigned Size) const { |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5257 | unsigned dest = MI->getOperand(0).getReg(); |
| 5258 | unsigned ptr = MI->getOperand(1).getReg(); |
| 5259 | unsigned oldval = MI->getOperand(2).getReg(); |
| 5260 | unsigned newval = MI->getOperand(3).getReg(); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5261 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 5262 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5263 | bool isThumb2 = Subtarget->isThumb2(); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5264 | |
Cameron Zwarich | 7d336c0 | 2011-05-18 02:20:07 +0000 | [diff] [blame] | 5265 | MachineRegisterInfo &MRI = BB->getParent()->getRegInfo(); |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 5266 | unsigned scratch = MRI.createVirtualRegister(isThumb2 ? |
| 5267 | (const TargetRegisterClass*)&ARM::rGPRRegClass : |
| 5268 | (const TargetRegisterClass*)&ARM::GPRRegClass); |
Cameron Zwarich | 7d336c0 | 2011-05-18 02:20:07 +0000 | [diff] [blame] | 5269 | |
| 5270 | if (isThumb2) { |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 5271 | MRI.constrainRegClass(dest, &ARM::rGPRRegClass); |
| 5272 | MRI.constrainRegClass(oldval, &ARM::rGPRRegClass); |
| 5273 | MRI.constrainRegClass(newval, &ARM::rGPRRegClass); |
Cameron Zwarich | 7d336c0 | 2011-05-18 02:20:07 +0000 | [diff] [blame] | 5274 | } |
| 5275 | |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5276 | unsigned ldrOpc, strOpc; |
| 5277 | switch (Size) { |
| 5278 | default: llvm_unreachable("unsupported size for AtomicCmpSwap!"); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5279 | case 1: |
| 5280 | ldrOpc = isThumb2 ? ARM::t2LDREXB : ARM::LDREXB; |
Evan Cheng | aa26102 | 2011-02-07 18:50:47 +0000 | [diff] [blame] | 5281 | strOpc = isThumb2 ? ARM::t2STREXB : ARM::STREXB; |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5282 | break; |
| 5283 | case 2: |
| 5284 | ldrOpc = isThumb2 ? ARM::t2LDREXH : ARM::LDREXH; |
| 5285 | strOpc = isThumb2 ? ARM::t2STREXH : ARM::STREXH; |
| 5286 | break; |
| 5287 | case 4: |
| 5288 | ldrOpc = isThumb2 ? ARM::t2LDREX : ARM::LDREX; |
| 5289 | strOpc = isThumb2 ? ARM::t2STREX : ARM::STREX; |
| 5290 | break; |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5291 | } |
| 5292 | |
| 5293 | MachineFunction *MF = BB->getParent(); |
| 5294 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 5295 | MachineFunction::iterator It = BB; |
| 5296 | ++It; // insert the new blocks after the current block |
| 5297 | |
| 5298 | MachineBasicBlock *loop1MBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5299 | MachineBasicBlock *loop2MBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5300 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5301 | MF->insert(It, loop1MBB); |
| 5302 | MF->insert(It, loop2MBB); |
| 5303 | MF->insert(It, exitMBB); |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 5304 | |
| 5305 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 5306 | exitMBB->splice(exitMBB->begin(), BB, |
| 5307 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 5308 | BB->end()); |
| 5309 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5310 | |
| 5311 | // thisMBB: |
| 5312 | // ... |
| 5313 | // fallthrough --> loop1MBB |
| 5314 | BB->addSuccessor(loop1MBB); |
| 5315 | |
| 5316 | // loop1MBB: |
| 5317 | // ldrex dest, [ptr] |
| 5318 | // cmp dest, oldval |
| 5319 | // bne exitMBB |
| 5320 | BB = loop1MBB; |
Jim Grosbach | b6aed50 | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 5321 | MachineInstrBuilder MIB = BuildMI(BB, dl, TII->get(ldrOpc), dest).addReg(ptr); |
| 5322 | if (ldrOpc == ARM::t2LDREX) |
| 5323 | MIB.addImm(0); |
| 5324 | AddDefaultPred(MIB); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5325 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5326 | .addReg(dest).addReg(oldval)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5327 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 5328 | .addMBB(exitMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5329 | BB->addSuccessor(loop2MBB); |
| 5330 | BB->addSuccessor(exitMBB); |
| 5331 | |
| 5332 | // loop2MBB: |
| 5333 | // strex scratch, newval, [ptr] |
| 5334 | // cmp scratch, #0 |
| 5335 | // bne loop1MBB |
| 5336 | BB = loop2MBB; |
Jim Grosbach | b6aed50 | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 5337 | MIB = BuildMI(BB, dl, TII->get(strOpc), scratch).addReg(newval).addReg(ptr); |
| 5338 | if (strOpc == ARM::t2STREX) |
| 5339 | MIB.addImm(0); |
| 5340 | AddDefaultPred(MIB); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5341 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5342 | .addReg(scratch).addImm(0)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5343 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 5344 | .addMBB(loop1MBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5345 | BB->addSuccessor(loop1MBB); |
| 5346 | BB->addSuccessor(exitMBB); |
| 5347 | |
| 5348 | // exitMBB: |
| 5349 | // ... |
| 5350 | BB = exitMBB; |
Jim Grosbach | 5efaed3 | 2010-01-15 00:18:34 +0000 | [diff] [blame] | 5351 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 5352 | MI->eraseFromParent(); // The instruction is gone now. |
Jim Grosbach | 5efaed3 | 2010-01-15 00:18:34 +0000 | [diff] [blame] | 5353 | |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5354 | return BB; |
| 5355 | } |
| 5356 | |
| 5357 | MachineBasicBlock * |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 5358 | ARMTargetLowering::EmitAtomicBinary(MachineInstr *MI, MachineBasicBlock *BB, |
| 5359 | unsigned Size, unsigned BinOpcode) const { |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5360 | // This also handles ATOMIC_SWAP, indicated by BinOpcode==0. |
| 5361 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 5362 | |
| 5363 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
Jim Grosbach | 867bbbf | 2010-01-15 00:22:18 +0000 | [diff] [blame] | 5364 | MachineFunction *MF = BB->getParent(); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5365 | MachineFunction::iterator It = BB; |
| 5366 | ++It; |
| 5367 | |
| 5368 | unsigned dest = MI->getOperand(0).getReg(); |
| 5369 | unsigned ptr = MI->getOperand(1).getReg(); |
| 5370 | unsigned incr = MI->getOperand(2).getReg(); |
| 5371 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5372 | bool isThumb2 = Subtarget->isThumb2(); |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 5373 | |
| 5374 | MachineRegisterInfo &MRI = BB->getParent()->getRegInfo(); |
| 5375 | if (isThumb2) { |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 5376 | MRI.constrainRegClass(dest, &ARM::rGPRRegClass); |
| 5377 | MRI.constrainRegClass(ptr, &ARM::rGPRRegClass); |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 5378 | } |
| 5379 | |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5380 | unsigned ldrOpc, strOpc; |
| 5381 | switch (Size) { |
| 5382 | default: llvm_unreachable("unsupported size for AtomicCmpSwap!"); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5383 | case 1: |
| 5384 | ldrOpc = isThumb2 ? ARM::t2LDREXB : ARM::LDREXB; |
Jakob Stoklund Olesen | 15913c9 | 2010-01-13 19:54:39 +0000 | [diff] [blame] | 5385 | strOpc = isThumb2 ? ARM::t2STREXB : ARM::STREXB; |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5386 | break; |
| 5387 | case 2: |
| 5388 | ldrOpc = isThumb2 ? ARM::t2LDREXH : ARM::LDREXH; |
| 5389 | strOpc = isThumb2 ? ARM::t2STREXH : ARM::STREXH; |
| 5390 | break; |
| 5391 | case 4: |
| 5392 | ldrOpc = isThumb2 ? ARM::t2LDREX : ARM::LDREX; |
| 5393 | strOpc = isThumb2 ? ARM::t2STREX : ARM::STREX; |
| 5394 | break; |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5395 | } |
| 5396 | |
Jim Grosbach | 867bbbf | 2010-01-15 00:22:18 +0000 | [diff] [blame] | 5397 | MachineBasicBlock *loopMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5398 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5399 | MF->insert(It, loopMBB); |
| 5400 | MF->insert(It, exitMBB); |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 5401 | |
| 5402 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 5403 | exitMBB->splice(exitMBB->begin(), BB, |
| 5404 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 5405 | BB->end()); |
| 5406 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5407 | |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 5408 | const TargetRegisterClass *TRC = isThumb2 ? |
| 5409 | (const TargetRegisterClass*)&ARM::tGPRRegClass : |
| 5410 | (const TargetRegisterClass*)&ARM::GPRRegClass; |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 5411 | unsigned scratch = MRI.createVirtualRegister(TRC); |
| 5412 | unsigned scratch2 = (!BinOpcode) ? incr : MRI.createVirtualRegister(TRC); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5413 | |
| 5414 | // thisMBB: |
| 5415 | // ... |
| 5416 | // fallthrough --> loopMBB |
| 5417 | BB->addSuccessor(loopMBB); |
| 5418 | |
| 5419 | // loopMBB: |
| 5420 | // ldrex dest, ptr |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5421 | // <binop> scratch2, dest, incr |
| 5422 | // strex scratch, scratch2, ptr |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5423 | // cmp scratch, #0 |
| 5424 | // bne- loopMBB |
| 5425 | // fallthrough --> exitMBB |
| 5426 | BB = loopMBB; |
Jim Grosbach | b6aed50 | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 5427 | MachineInstrBuilder MIB = BuildMI(BB, dl, TII->get(ldrOpc), dest).addReg(ptr); |
| 5428 | if (ldrOpc == ARM::t2LDREX) |
| 5429 | MIB.addImm(0); |
| 5430 | AddDefaultPred(MIB); |
Jim Grosbach | c67b556 | 2009-12-15 00:12:35 +0000 | [diff] [blame] | 5431 | if (BinOpcode) { |
| 5432 | // operand order needs to go the other way for NAND |
| 5433 | if (BinOpcode == ARM::BICrr || BinOpcode == ARM::t2BICrr) |
| 5434 | AddDefaultPred(BuildMI(BB, dl, TII->get(BinOpcode), scratch2). |
| 5435 | addReg(incr).addReg(dest)).addReg(0); |
| 5436 | else |
| 5437 | AddDefaultPred(BuildMI(BB, dl, TII->get(BinOpcode), scratch2). |
| 5438 | addReg(dest).addReg(incr)).addReg(0); |
| 5439 | } |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5440 | |
Jim Grosbach | b6aed50 | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 5441 | MIB = BuildMI(BB, dl, TII->get(strOpc), scratch).addReg(scratch2).addReg(ptr); |
| 5442 | if (strOpc == ARM::t2STREX) |
| 5443 | MIB.addImm(0); |
| 5444 | AddDefaultPred(MIB); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5445 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5446 | .addReg(scratch).addImm(0)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5447 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 5448 | .addMBB(loopMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5449 | |
| 5450 | BB->addSuccessor(loopMBB); |
| 5451 | BB->addSuccessor(exitMBB); |
| 5452 | |
| 5453 | // exitMBB: |
| 5454 | // ... |
| 5455 | BB = exitMBB; |
Evan Cheng | 102ebf1 | 2009-12-21 19:53:39 +0000 | [diff] [blame] | 5456 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 5457 | MI->eraseFromParent(); // The instruction is gone now. |
Evan Cheng | 102ebf1 | 2009-12-21 19:53:39 +0000 | [diff] [blame] | 5458 | |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5459 | return BB; |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 5460 | } |
| 5461 | |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5462 | MachineBasicBlock * |
| 5463 | ARMTargetLowering::EmitAtomicBinaryMinMax(MachineInstr *MI, |
| 5464 | MachineBasicBlock *BB, |
| 5465 | unsigned Size, |
| 5466 | bool signExtend, |
| 5467 | ARMCC::CondCodes Cond) const { |
| 5468 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 5469 | |
| 5470 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 5471 | MachineFunction *MF = BB->getParent(); |
| 5472 | MachineFunction::iterator It = BB; |
| 5473 | ++It; |
| 5474 | |
| 5475 | unsigned dest = MI->getOperand(0).getReg(); |
| 5476 | unsigned ptr = MI->getOperand(1).getReg(); |
| 5477 | unsigned incr = MI->getOperand(2).getReg(); |
| 5478 | unsigned oldval = dest; |
| 5479 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5480 | bool isThumb2 = Subtarget->isThumb2(); |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 5481 | |
| 5482 | MachineRegisterInfo &MRI = BB->getParent()->getRegInfo(); |
| 5483 | if (isThumb2) { |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 5484 | MRI.constrainRegClass(dest, &ARM::rGPRRegClass); |
| 5485 | MRI.constrainRegClass(ptr, &ARM::rGPRRegClass); |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 5486 | } |
| 5487 | |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5488 | unsigned ldrOpc, strOpc, extendOpc; |
| 5489 | switch (Size) { |
| 5490 | default: llvm_unreachable("unsupported size for AtomicCmpSwap!"); |
| 5491 | case 1: |
| 5492 | ldrOpc = isThumb2 ? ARM::t2LDREXB : ARM::LDREXB; |
| 5493 | strOpc = isThumb2 ? ARM::t2STREXB : ARM::STREXB; |
Jim Grosbach | c5a8c86 | 2011-07-27 16:47:19 +0000 | [diff] [blame] | 5494 | extendOpc = isThumb2 ? ARM::t2SXTB : ARM::SXTB; |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5495 | break; |
| 5496 | case 2: |
| 5497 | ldrOpc = isThumb2 ? ARM::t2LDREXH : ARM::LDREXH; |
| 5498 | strOpc = isThumb2 ? ARM::t2STREXH : ARM::STREXH; |
Jim Grosbach | c5a8c86 | 2011-07-27 16:47:19 +0000 | [diff] [blame] | 5499 | extendOpc = isThumb2 ? ARM::t2SXTH : ARM::SXTH; |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5500 | break; |
| 5501 | case 4: |
| 5502 | ldrOpc = isThumb2 ? ARM::t2LDREX : ARM::LDREX; |
| 5503 | strOpc = isThumb2 ? ARM::t2STREX : ARM::STREX; |
| 5504 | extendOpc = 0; |
| 5505 | break; |
| 5506 | } |
| 5507 | |
| 5508 | MachineBasicBlock *loopMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5509 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5510 | MF->insert(It, loopMBB); |
| 5511 | MF->insert(It, exitMBB); |
| 5512 | |
| 5513 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 5514 | exitMBB->splice(exitMBB->begin(), BB, |
| 5515 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 5516 | BB->end()); |
| 5517 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
| 5518 | |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 5519 | const TargetRegisterClass *TRC = isThumb2 ? |
| 5520 | (const TargetRegisterClass*)&ARM::tGPRRegClass : |
| 5521 | (const TargetRegisterClass*)&ARM::GPRRegClass; |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 5522 | unsigned scratch = MRI.createVirtualRegister(TRC); |
| 5523 | unsigned scratch2 = MRI.createVirtualRegister(TRC); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5524 | |
| 5525 | // thisMBB: |
| 5526 | // ... |
| 5527 | // fallthrough --> loopMBB |
| 5528 | BB->addSuccessor(loopMBB); |
| 5529 | |
| 5530 | // loopMBB: |
| 5531 | // ldrex dest, ptr |
| 5532 | // (sign extend dest, if required) |
| 5533 | // cmp dest, incr |
| 5534 | // cmov.cond scratch2, dest, incr |
| 5535 | // strex scratch, scratch2, ptr |
| 5536 | // cmp scratch, #0 |
| 5537 | // bne- loopMBB |
| 5538 | // fallthrough --> exitMBB |
| 5539 | BB = loopMBB; |
Jim Grosbach | b6aed50 | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 5540 | MachineInstrBuilder MIB = BuildMI(BB, dl, TII->get(ldrOpc), dest).addReg(ptr); |
| 5541 | if (ldrOpc == ARM::t2LDREX) |
| 5542 | MIB.addImm(0); |
| 5543 | AddDefaultPred(MIB); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5544 | |
| 5545 | // Sign extend the value, if necessary. |
| 5546 | if (signExtend && extendOpc) { |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 5547 | oldval = MRI.createVirtualRegister(&ARM::GPRRegClass); |
Jim Grosbach | c5a8c86 | 2011-07-27 16:47:19 +0000 | [diff] [blame] | 5548 | AddDefaultPred(BuildMI(BB, dl, TII->get(extendOpc), oldval) |
| 5549 | .addReg(dest) |
| 5550 | .addImm(0)); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5551 | } |
| 5552 | |
| 5553 | // Build compare and cmov instructions. |
| 5554 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
| 5555 | .addReg(oldval).addReg(incr)); |
| 5556 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2MOVCCr : ARM::MOVCCr), scratch2) |
| 5557 | .addReg(oldval).addReg(incr).addImm(Cond).addReg(ARM::CPSR); |
| 5558 | |
Jim Grosbach | b6aed50 | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 5559 | MIB = BuildMI(BB, dl, TII->get(strOpc), scratch).addReg(scratch2).addReg(ptr); |
| 5560 | if (strOpc == ARM::t2STREX) |
| 5561 | MIB.addImm(0); |
| 5562 | AddDefaultPred(MIB); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5563 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 5564 | .addReg(scratch).addImm(0)); |
| 5565 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 5566 | .addMBB(loopMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
| 5567 | |
| 5568 | BB->addSuccessor(loopMBB); |
| 5569 | BB->addSuccessor(exitMBB); |
| 5570 | |
| 5571 | // exitMBB: |
| 5572 | // ... |
| 5573 | BB = exitMBB; |
| 5574 | |
| 5575 | MI->eraseFromParent(); // The instruction is gone now. |
| 5576 | |
| 5577 | return BB; |
| 5578 | } |
| 5579 | |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5580 | MachineBasicBlock * |
| 5581 | ARMTargetLowering::EmitAtomicBinary64(MachineInstr *MI, MachineBasicBlock *BB, |
| 5582 | unsigned Op1, unsigned Op2, |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5583 | bool NeedsCarry, bool IsCmpxchg) const { |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5584 | // This also handles ATOMIC_SWAP, indicated by Op1==0. |
| 5585 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 5586 | |
| 5587 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 5588 | MachineFunction *MF = BB->getParent(); |
| 5589 | MachineFunction::iterator It = BB; |
| 5590 | ++It; |
| 5591 | |
| 5592 | unsigned destlo = MI->getOperand(0).getReg(); |
| 5593 | unsigned desthi = MI->getOperand(1).getReg(); |
| 5594 | unsigned ptr = MI->getOperand(2).getReg(); |
| 5595 | unsigned vallo = MI->getOperand(3).getReg(); |
| 5596 | unsigned valhi = MI->getOperand(4).getReg(); |
| 5597 | DebugLoc dl = MI->getDebugLoc(); |
| 5598 | bool isThumb2 = Subtarget->isThumb2(); |
| 5599 | |
| 5600 | MachineRegisterInfo &MRI = BB->getParent()->getRegInfo(); |
| 5601 | if (isThumb2) { |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 5602 | MRI.constrainRegClass(destlo, &ARM::rGPRRegClass); |
| 5603 | MRI.constrainRegClass(desthi, &ARM::rGPRRegClass); |
| 5604 | MRI.constrainRegClass(ptr, &ARM::rGPRRegClass); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5605 | } |
| 5606 | |
| 5607 | unsigned ldrOpc = isThumb2 ? ARM::t2LDREXD : ARM::LDREXD; |
| 5608 | unsigned strOpc = isThumb2 ? ARM::t2STREXD : ARM::STREXD; |
| 5609 | |
| 5610 | MachineBasicBlock *loopMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
Eli Friedman | 7df496d | 2011-09-01 22:27:41 +0000 | [diff] [blame] | 5611 | MachineBasicBlock *contBB = 0, *cont2BB = 0; |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5612 | if (IsCmpxchg) { |
| 5613 | contBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5614 | cont2BB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5615 | } |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5616 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5617 | MF->insert(It, loopMBB); |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5618 | if (IsCmpxchg) { |
| 5619 | MF->insert(It, contBB); |
| 5620 | MF->insert(It, cont2BB); |
| 5621 | } |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5622 | MF->insert(It, exitMBB); |
| 5623 | |
| 5624 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 5625 | exitMBB->splice(exitMBB->begin(), BB, |
| 5626 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 5627 | BB->end()); |
| 5628 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
| 5629 | |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 5630 | const TargetRegisterClass *TRC = isThumb2 ? |
| 5631 | (const TargetRegisterClass*)&ARM::tGPRRegClass : |
| 5632 | (const TargetRegisterClass*)&ARM::GPRRegClass; |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5633 | unsigned storesuccess = MRI.createVirtualRegister(TRC); |
| 5634 | |
| 5635 | // thisMBB: |
| 5636 | // ... |
| 5637 | // fallthrough --> loopMBB |
| 5638 | BB->addSuccessor(loopMBB); |
| 5639 | |
| 5640 | // loopMBB: |
| 5641 | // ldrexd r2, r3, ptr |
| 5642 | // <binopa> r0, r2, incr |
| 5643 | // <binopb> r1, r3, incr |
| 5644 | // strexd storesuccess, r0, r1, ptr |
| 5645 | // cmp storesuccess, #0 |
| 5646 | // bne- loopMBB |
| 5647 | // fallthrough --> exitMBB |
| 5648 | // |
| 5649 | // Note that the registers are explicitly specified because there is not any |
| 5650 | // way to force the register allocator to allocate a register pair. |
| 5651 | // |
Andrew Trick | 3af7a67 | 2011-09-20 03:06:13 +0000 | [diff] [blame] | 5652 | // FIXME: The hardcoded registers are not necessary for Thumb2, but we |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5653 | // need to properly enforce the restriction that the two output registers |
| 5654 | // for ldrexd must be different. |
| 5655 | BB = loopMBB; |
| 5656 | // Load |
| 5657 | AddDefaultPred(BuildMI(BB, dl, TII->get(ldrOpc)) |
| 5658 | .addReg(ARM::R2, RegState::Define) |
| 5659 | .addReg(ARM::R3, RegState::Define).addReg(ptr)); |
| 5660 | // Copy r2/r3 into dest. (This copy will normally be coalesced.) |
| 5661 | BuildMI(BB, dl, TII->get(TargetOpcode::COPY), destlo).addReg(ARM::R2); |
| 5662 | BuildMI(BB, dl, TII->get(TargetOpcode::COPY), desthi).addReg(ARM::R3); |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5663 | |
| 5664 | if (IsCmpxchg) { |
| 5665 | // Add early exit |
| 5666 | for (unsigned i = 0; i < 2; i++) { |
| 5667 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPrr : |
| 5668 | ARM::CMPrr)) |
| 5669 | .addReg(i == 0 ? destlo : desthi) |
| 5670 | .addReg(i == 0 ? vallo : valhi)); |
| 5671 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 5672 | .addMBB(exitMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
| 5673 | BB->addSuccessor(exitMBB); |
| 5674 | BB->addSuccessor(i == 0 ? contBB : cont2BB); |
| 5675 | BB = (i == 0 ? contBB : cont2BB); |
| 5676 | } |
| 5677 | |
| 5678 | // Copy to physregs for strexd |
| 5679 | unsigned setlo = MI->getOperand(5).getReg(); |
| 5680 | unsigned sethi = MI->getOperand(6).getReg(); |
| 5681 | BuildMI(BB, dl, TII->get(TargetOpcode::COPY), ARM::R0).addReg(setlo); |
| 5682 | BuildMI(BB, dl, TII->get(TargetOpcode::COPY), ARM::R1).addReg(sethi); |
| 5683 | } else if (Op1) { |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5684 | // Perform binary operation |
| 5685 | AddDefaultPred(BuildMI(BB, dl, TII->get(Op1), ARM::R0) |
| 5686 | .addReg(destlo).addReg(vallo)) |
| 5687 | .addReg(NeedsCarry ? ARM::CPSR : 0, getDefRegState(NeedsCarry)); |
| 5688 | AddDefaultPred(BuildMI(BB, dl, TII->get(Op2), ARM::R1) |
| 5689 | .addReg(desthi).addReg(valhi)).addReg(0); |
| 5690 | } else { |
| 5691 | // Copy to physregs for strexd |
| 5692 | BuildMI(BB, dl, TII->get(TargetOpcode::COPY), ARM::R0).addReg(vallo); |
| 5693 | BuildMI(BB, dl, TII->get(TargetOpcode::COPY), ARM::R1).addReg(valhi); |
| 5694 | } |
| 5695 | |
| 5696 | // Store |
| 5697 | AddDefaultPred(BuildMI(BB, dl, TII->get(strOpc), storesuccess) |
| 5698 | .addReg(ARM::R0).addReg(ARM::R1).addReg(ptr)); |
| 5699 | // Cmp+jump |
| 5700 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 5701 | .addReg(storesuccess).addImm(0)); |
| 5702 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 5703 | .addMBB(loopMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
| 5704 | |
| 5705 | BB->addSuccessor(loopMBB); |
| 5706 | BB->addSuccessor(exitMBB); |
| 5707 | |
| 5708 | // exitMBB: |
| 5709 | // ... |
| 5710 | BB = exitMBB; |
| 5711 | |
| 5712 | MI->eraseFromParent(); // The instruction is gone now. |
| 5713 | |
| 5714 | return BB; |
| 5715 | } |
| 5716 | |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 5717 | /// SetupEntryBlockForSjLj - Insert code into the entry block that creates and |
| 5718 | /// registers the function context. |
| 5719 | void ARMTargetLowering:: |
| 5720 | SetupEntryBlockForSjLj(MachineInstr *MI, MachineBasicBlock *MBB, |
| 5721 | MachineBasicBlock *DispatchBB, int FI) const { |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 5722 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 5723 | DebugLoc dl = MI->getDebugLoc(); |
| 5724 | MachineFunction *MF = MBB->getParent(); |
| 5725 | MachineRegisterInfo *MRI = &MF->getRegInfo(); |
| 5726 | MachineConstantPool *MCP = MF->getConstantPool(); |
| 5727 | ARMFunctionInfo *AFI = MF->getInfo<ARMFunctionInfo>(); |
| 5728 | const Function *F = MF->getFunction(); |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 5729 | |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 5730 | bool isThumb = Subtarget->isThumb(); |
Bill Wendling | ff4216a | 2011-10-03 22:44:15 +0000 | [diff] [blame] | 5731 | bool isThumb2 = Subtarget->isThumb2(); |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 5732 | |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 5733 | unsigned PCLabelId = AFI->createPICLabelUId(); |
Bill Wendling | ff4216a | 2011-10-03 22:44:15 +0000 | [diff] [blame] | 5734 | unsigned PCAdj = (isThumb || isThumb2) ? 4 : 8; |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 5735 | ARMConstantPoolValue *CPV = |
| 5736 | ARMConstantPoolMBB::Create(F->getContext(), DispatchBB, PCLabelId, PCAdj); |
| 5737 | unsigned CPI = MCP->getConstantPoolIndex(CPV, 4); |
| 5738 | |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 5739 | const TargetRegisterClass *TRC = isThumb ? |
| 5740 | (const TargetRegisterClass*)&ARM::tGPRRegClass : |
| 5741 | (const TargetRegisterClass*)&ARM::GPRRegClass; |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 5742 | |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 5743 | // Grab constant pool and fixed stack memory operands. |
| 5744 | MachineMemOperand *CPMMO = |
| 5745 | MF->getMachineMemOperand(MachinePointerInfo::getConstantPool(), |
| 5746 | MachineMemOperand::MOLoad, 4, 4); |
| 5747 | |
| 5748 | MachineMemOperand *FIMMOSt = |
| 5749 | MF->getMachineMemOperand(MachinePointerInfo::getFixedStack(FI), |
| 5750 | MachineMemOperand::MOStore, 4, 4); |
| 5751 | |
| 5752 | // Load the address of the dispatch MBB into the jump buffer. |
| 5753 | if (isThumb2) { |
| 5754 | // Incoming value: jbuf |
| 5755 | // ldr.n r5, LCPI1_1 |
| 5756 | // orr r5, r5, #1 |
| 5757 | // add r5, pc |
| 5758 | // str r5, [$jbuf, #+4] ; &jbuf[1] |
| 5759 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 5760 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::t2LDRpci), NewVReg1) |
| 5761 | .addConstantPoolIndex(CPI) |
| 5762 | .addMemOperand(CPMMO)); |
| 5763 | // Set the low bit because of thumb mode. |
| 5764 | unsigned NewVReg2 = MRI->createVirtualRegister(TRC); |
| 5765 | AddDefaultCC( |
| 5766 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::t2ORRri), NewVReg2) |
| 5767 | .addReg(NewVReg1, RegState::Kill) |
| 5768 | .addImm(0x01))); |
| 5769 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
| 5770 | BuildMI(*MBB, MI, dl, TII->get(ARM::tPICADD), NewVReg3) |
| 5771 | .addReg(NewVReg2, RegState::Kill) |
| 5772 | .addImm(PCLabelId); |
| 5773 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::t2STRi12)) |
| 5774 | .addReg(NewVReg3, RegState::Kill) |
| 5775 | .addFrameIndex(FI) |
| 5776 | .addImm(36) // &jbuf[1] :: pc |
| 5777 | .addMemOperand(FIMMOSt)); |
| 5778 | } else if (isThumb) { |
| 5779 | // Incoming value: jbuf |
| 5780 | // ldr.n r1, LCPI1_4 |
| 5781 | // add r1, pc |
| 5782 | // mov r2, #1 |
| 5783 | // orrs r1, r2 |
| 5784 | // add r2, $jbuf, #+4 ; &jbuf[1] |
| 5785 | // str r1, [r2] |
| 5786 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 5787 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tLDRpci), NewVReg1) |
| 5788 | .addConstantPoolIndex(CPI) |
| 5789 | .addMemOperand(CPMMO)); |
| 5790 | unsigned NewVReg2 = MRI->createVirtualRegister(TRC); |
| 5791 | BuildMI(*MBB, MI, dl, TII->get(ARM::tPICADD), NewVReg2) |
| 5792 | .addReg(NewVReg1, RegState::Kill) |
| 5793 | .addImm(PCLabelId); |
| 5794 | // Set the low bit because of thumb mode. |
| 5795 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
| 5796 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tMOVi8), NewVReg3) |
| 5797 | .addReg(ARM::CPSR, RegState::Define) |
| 5798 | .addImm(1)); |
| 5799 | unsigned NewVReg4 = MRI->createVirtualRegister(TRC); |
| 5800 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tORR), NewVReg4) |
| 5801 | .addReg(ARM::CPSR, RegState::Define) |
| 5802 | .addReg(NewVReg2, RegState::Kill) |
| 5803 | .addReg(NewVReg3, RegState::Kill)); |
| 5804 | unsigned NewVReg5 = MRI->createVirtualRegister(TRC); |
| 5805 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tADDrSPi), NewVReg5) |
| 5806 | .addFrameIndex(FI) |
| 5807 | .addImm(36)); // &jbuf[1] :: pc |
| 5808 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tSTRi)) |
| 5809 | .addReg(NewVReg4, RegState::Kill) |
| 5810 | .addReg(NewVReg5, RegState::Kill) |
| 5811 | .addImm(0) |
| 5812 | .addMemOperand(FIMMOSt)); |
| 5813 | } else { |
| 5814 | // Incoming value: jbuf |
| 5815 | // ldr r1, LCPI1_1 |
| 5816 | // add r1, pc, r1 |
| 5817 | // str r1, [$jbuf, #+4] ; &jbuf[1] |
| 5818 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 5819 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::LDRi12), NewVReg1) |
| 5820 | .addConstantPoolIndex(CPI) |
| 5821 | .addImm(0) |
| 5822 | .addMemOperand(CPMMO)); |
| 5823 | unsigned NewVReg2 = MRI->createVirtualRegister(TRC); |
| 5824 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::PICADD), NewVReg2) |
| 5825 | .addReg(NewVReg1, RegState::Kill) |
| 5826 | .addImm(PCLabelId)); |
| 5827 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::STRi12)) |
| 5828 | .addReg(NewVReg2, RegState::Kill) |
| 5829 | .addFrameIndex(FI) |
| 5830 | .addImm(36) // &jbuf[1] :: pc |
| 5831 | .addMemOperand(FIMMOSt)); |
| 5832 | } |
| 5833 | } |
| 5834 | |
| 5835 | MachineBasicBlock *ARMTargetLowering:: |
| 5836 | EmitSjLjDispatchBlock(MachineInstr *MI, MachineBasicBlock *MBB) const { |
| 5837 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 5838 | DebugLoc dl = MI->getDebugLoc(); |
| 5839 | MachineFunction *MF = MBB->getParent(); |
| 5840 | MachineRegisterInfo *MRI = &MF->getRegInfo(); |
| 5841 | ARMFunctionInfo *AFI = MF->getInfo<ARMFunctionInfo>(); |
| 5842 | MachineFrameInfo *MFI = MF->getFrameInfo(); |
| 5843 | int FI = MFI->getFunctionContextIndex(); |
| 5844 | |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 5845 | const TargetRegisterClass *TRC = Subtarget->isThumb() ? |
| 5846 | (const TargetRegisterClass*)&ARM::tGPRRegClass : |
| 5847 | (const TargetRegisterClass*)&ARM::GPRRegClass; |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 5848 | |
Bill Wendling | 04f15b4 | 2011-10-06 21:29:56 +0000 | [diff] [blame] | 5849 | // Get a mapping of the call site numbers to all of the landing pads they're |
| 5850 | // associated with. |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 5851 | DenseMap<unsigned, SmallVector<MachineBasicBlock*, 2> > CallSiteNumToLPad; |
| 5852 | unsigned MaxCSNum = 0; |
| 5853 | MachineModuleInfo &MMI = MF->getMMI(); |
Jim Grosbach | d4f020a | 2012-04-06 23:43:50 +0000 | [diff] [blame] | 5854 | for (MachineFunction::iterator BB = MF->begin(), E = MF->end(); BB != E; |
| 5855 | ++BB) { |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 5856 | if (!BB->isLandingPad()) continue; |
| 5857 | |
| 5858 | // FIXME: We should assert that the EH_LABEL is the first MI in the landing |
| 5859 | // pad. |
| 5860 | for (MachineBasicBlock::iterator |
| 5861 | II = BB->begin(), IE = BB->end(); II != IE; ++II) { |
| 5862 | if (!II->isEHLabel()) continue; |
| 5863 | |
| 5864 | MCSymbol *Sym = II->getOperand(0).getMCSymbol(); |
Bill Wendling | 5cbef19 | 2011-10-05 23:28:57 +0000 | [diff] [blame] | 5865 | if (!MMI.hasCallSiteLandingPad(Sym)) continue; |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 5866 | |
Bill Wendling | 5cbef19 | 2011-10-05 23:28:57 +0000 | [diff] [blame] | 5867 | SmallVectorImpl<unsigned> &CallSiteIdxs = MMI.getCallSiteLandingPad(Sym); |
| 5868 | for (SmallVectorImpl<unsigned>::iterator |
| 5869 | CSI = CallSiteIdxs.begin(), CSE = CallSiteIdxs.end(); |
| 5870 | CSI != CSE; ++CSI) { |
| 5871 | CallSiteNumToLPad[*CSI].push_back(BB); |
| 5872 | MaxCSNum = std::max(MaxCSNum, *CSI); |
| 5873 | } |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 5874 | break; |
| 5875 | } |
| 5876 | } |
| 5877 | |
| 5878 | // Get an ordered list of the machine basic blocks for the jump table. |
| 5879 | std::vector<MachineBasicBlock*> LPadList; |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 5880 | SmallPtrSet<MachineBasicBlock*, 64> InvokeBBs; |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 5881 | LPadList.reserve(CallSiteNumToLPad.size()); |
| 5882 | for (unsigned I = 1; I <= MaxCSNum; ++I) { |
| 5883 | SmallVectorImpl<MachineBasicBlock*> &MBBList = CallSiteNumToLPad[I]; |
| 5884 | for (SmallVectorImpl<MachineBasicBlock*>::iterator |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 5885 | II = MBBList.begin(), IE = MBBList.end(); II != IE; ++II) { |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 5886 | LPadList.push_back(*II); |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 5887 | InvokeBBs.insert((*II)->pred_begin(), (*II)->pred_end()); |
| 5888 | } |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 5889 | } |
| 5890 | |
Bill Wendling | 5cbef19 | 2011-10-05 23:28:57 +0000 | [diff] [blame] | 5891 | assert(!LPadList.empty() && |
| 5892 | "No landing pad destinations for the dispatch jump table!"); |
| 5893 | |
Bill Wendling | 04f15b4 | 2011-10-06 21:29:56 +0000 | [diff] [blame] | 5894 | // Create the jump table and associated information. |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 5895 | MachineJumpTableInfo *JTI = |
| 5896 | MF->getOrCreateJumpTableInfo(MachineJumpTableInfo::EK_Inline); |
| 5897 | unsigned MJTI = JTI->createJumpTableIndex(LPadList); |
| 5898 | unsigned UId = AFI->createJumpTableUId(); |
| 5899 | |
Bill Wendling | 04f15b4 | 2011-10-06 21:29:56 +0000 | [diff] [blame] | 5900 | // Create the MBBs for the dispatch code. |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 5901 | |
| 5902 | // Shove the dispatch's address into the return slot in the function context. |
| 5903 | MachineBasicBlock *DispatchBB = MF->CreateMachineBasicBlock(); |
| 5904 | DispatchBB->setIsLandingPad(); |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 5905 | |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 5906 | MachineBasicBlock *TrapBB = MF->CreateMachineBasicBlock(); |
Bill Wendling | 083a8eb | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 5907 | BuildMI(TrapBB, dl, TII->get(Subtarget->isThumb() ? ARM::tTRAP : ARM::TRAP)); |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 5908 | DispatchBB->addSuccessor(TrapBB); |
| 5909 | |
| 5910 | MachineBasicBlock *DispContBB = MF->CreateMachineBasicBlock(); |
| 5911 | DispatchBB->addSuccessor(DispContBB); |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 5912 | |
Bill Wendling | a48ed4f | 2011-10-17 21:32:56 +0000 | [diff] [blame] | 5913 | // Insert and MBBs. |
Bill Wendling | 930193c | 2011-10-06 00:53:33 +0000 | [diff] [blame] | 5914 | MF->insert(MF->end(), DispatchBB); |
| 5915 | MF->insert(MF->end(), DispContBB); |
| 5916 | MF->insert(MF->end(), TrapBB); |
Bill Wendling | 930193c | 2011-10-06 00:53:33 +0000 | [diff] [blame] | 5917 | |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 5918 | // Insert code into the entry block that creates and registers the function |
| 5919 | // context. |
| 5920 | SetupEntryBlockForSjLj(MI, MBB, DispatchBB, FI); |
| 5921 | |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 5922 | MachineMemOperand *FIMMOLd = |
Bill Wendling | 04f15b4 | 2011-10-06 21:29:56 +0000 | [diff] [blame] | 5923 | MF->getMachineMemOperand(MachinePointerInfo::getFixedStack(FI), |
Bill Wendling | 083a8eb | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 5924 | MachineMemOperand::MOLoad | |
| 5925 | MachineMemOperand::MOVolatile, 4, 4); |
Bill Wendling | 930193c | 2011-10-06 00:53:33 +0000 | [diff] [blame] | 5926 | |
Bob Wilson | f4aea8f | 2011-12-22 23:39:48 +0000 | [diff] [blame] | 5927 | if (AFI->isThumb1OnlyFunction()) |
| 5928 | BuildMI(DispatchBB, dl, TII->get(ARM::tInt_eh_sjlj_dispatchsetup)); |
| 5929 | else if (!Subtarget->hasVFP2()) |
| 5930 | BuildMI(DispatchBB, dl, TII->get(ARM::Int_eh_sjlj_dispatchsetup_nofp)); |
Lang Hames | c0a9f82 | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 5931 | else |
Bob Wilson | f4aea8f | 2011-12-22 23:39:48 +0000 | [diff] [blame] | 5932 | BuildMI(DispatchBB, dl, TII->get(ARM::Int_eh_sjlj_dispatchsetup)); |
Bob Wilson | eaab6ef | 2011-11-16 07:11:57 +0000 | [diff] [blame] | 5933 | |
Bill Wendling | 952cb50 | 2011-10-18 22:49:07 +0000 | [diff] [blame] | 5934 | unsigned NumLPads = LPadList.size(); |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 5935 | if (Subtarget->isThumb2()) { |
| 5936 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 5937 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2LDRi12), NewVReg1) |
| 5938 | .addFrameIndex(FI) |
| 5939 | .addImm(4) |
| 5940 | .addMemOperand(FIMMOLd)); |
Bill Wendling | b9fecf4 | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 5941 | |
Bill Wendling | 952cb50 | 2011-10-18 22:49:07 +0000 | [diff] [blame] | 5942 | if (NumLPads < 256) { |
| 5943 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2CMPri)) |
| 5944 | .addReg(NewVReg1) |
| 5945 | .addImm(LPadList.size())); |
| 5946 | } else { |
| 5947 | unsigned VReg1 = MRI->createVirtualRegister(TRC); |
| 5948 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2MOVi16), VReg1) |
Bill Wendling | 15a1a22 | 2011-10-18 23:19:55 +0000 | [diff] [blame] | 5949 | .addImm(NumLPads & 0xFFFF)); |
| 5950 | |
| 5951 | unsigned VReg2 = VReg1; |
| 5952 | if ((NumLPads & 0xFFFF0000) != 0) { |
| 5953 | VReg2 = MRI->createVirtualRegister(TRC); |
| 5954 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2MOVTi16), VReg2) |
| 5955 | .addReg(VReg1) |
| 5956 | .addImm(NumLPads >> 16)); |
| 5957 | } |
| 5958 | |
Bill Wendling | 952cb50 | 2011-10-18 22:49:07 +0000 | [diff] [blame] | 5959 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2CMPrr)) |
| 5960 | .addReg(NewVReg1) |
| 5961 | .addReg(VReg2)); |
| 5962 | } |
Bill Wendling | b9fecf4 | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 5963 | |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 5964 | BuildMI(DispatchBB, dl, TII->get(ARM::t2Bcc)) |
| 5965 | .addMBB(TrapBB) |
| 5966 | .addImm(ARMCC::HI) |
| 5967 | .addReg(ARM::CPSR); |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 5968 | |
Bill Wendling | b9fecf4 | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 5969 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
| 5970 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::t2LEApcrelJT),NewVReg3) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 5971 | .addJumpTableIndex(MJTI) |
| 5972 | .addImm(UId)); |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 5973 | |
Bill Wendling | b9fecf4 | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 5974 | unsigned NewVReg4 = MRI->createVirtualRegister(TRC); |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 5975 | AddDefaultCC( |
| 5976 | AddDefaultPred( |
Bill Wendling | b9fecf4 | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 5977 | BuildMI(DispContBB, dl, TII->get(ARM::t2ADDrs), NewVReg4) |
| 5978 | .addReg(NewVReg3, RegState::Kill) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 5979 | .addReg(NewVReg1) |
| 5980 | .addImm(ARM_AM::getSORegOpc(ARM_AM::lsl, 2)))); |
| 5981 | |
| 5982 | BuildMI(DispContBB, dl, TII->get(ARM::t2BR_JT)) |
Bill Wendling | b9fecf4 | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 5983 | .addReg(NewVReg4, RegState::Kill) |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 5984 | .addReg(NewVReg1) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 5985 | .addJumpTableIndex(MJTI) |
| 5986 | .addImm(UId); |
| 5987 | } else if (Subtarget->isThumb()) { |
Bill Wendling | 083a8eb | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 5988 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 5989 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::tLDRspi), NewVReg1) |
| 5990 | .addFrameIndex(FI) |
| 5991 | .addImm(1) |
| 5992 | .addMemOperand(FIMMOLd)); |
Bill Wendling | f1083d4 | 2011-10-07 22:08:37 +0000 | [diff] [blame] | 5993 | |
Bill Wendling | a5871dc | 2011-10-18 23:11:05 +0000 | [diff] [blame] | 5994 | if (NumLPads < 256) { |
| 5995 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::tCMPi8)) |
| 5996 | .addReg(NewVReg1) |
| 5997 | .addImm(NumLPads)); |
| 5998 | } else { |
| 5999 | MachineConstantPool *ConstantPool = MF->getConstantPool(); |
Bill Wendling | 922ad78 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 6000 | Type *Int32Ty = Type::getInt32Ty(MF->getFunction()->getContext()); |
| 6001 | const Constant *C = ConstantInt::get(Int32Ty, NumLPads); |
| 6002 | |
| 6003 | // MachineConstantPool wants an explicit alignment. |
| 6004 | unsigned Align = getTargetData()->getPrefTypeAlignment(Int32Ty); |
| 6005 | if (Align == 0) |
| 6006 | Align = getTargetData()->getTypeAllocSize(C->getType()); |
| 6007 | unsigned Idx = ConstantPool->getConstantPoolIndex(C, Align); |
Bill Wendling | a5871dc | 2011-10-18 23:11:05 +0000 | [diff] [blame] | 6008 | |
| 6009 | unsigned VReg1 = MRI->createVirtualRegister(TRC); |
| 6010 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::tLDRpci)) |
| 6011 | .addReg(VReg1, RegState::Define) |
| 6012 | .addConstantPoolIndex(Idx)); |
| 6013 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::tCMPr)) |
| 6014 | .addReg(NewVReg1) |
| 6015 | .addReg(VReg1)); |
| 6016 | } |
| 6017 | |
Bill Wendling | 083a8eb | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 6018 | BuildMI(DispatchBB, dl, TII->get(ARM::tBcc)) |
| 6019 | .addMBB(TrapBB) |
| 6020 | .addImm(ARMCC::HI) |
| 6021 | .addReg(ARM::CPSR); |
| 6022 | |
| 6023 | unsigned NewVReg2 = MRI->createVirtualRegister(TRC); |
| 6024 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tLSLri), NewVReg2) |
| 6025 | .addReg(ARM::CPSR, RegState::Define) |
| 6026 | .addReg(NewVReg1) |
| 6027 | .addImm(2)); |
| 6028 | |
| 6029 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
Bill Wendling | 217f0e9 | 2011-10-06 23:41:14 +0000 | [diff] [blame] | 6030 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tLEApcrelJT), NewVReg3) |
Bill Wendling | 083a8eb | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 6031 | .addJumpTableIndex(MJTI) |
| 6032 | .addImm(UId)); |
| 6033 | |
| 6034 | unsigned NewVReg4 = MRI->createVirtualRegister(TRC); |
| 6035 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tADDrr), NewVReg4) |
| 6036 | .addReg(ARM::CPSR, RegState::Define) |
| 6037 | .addReg(NewVReg2, RegState::Kill) |
| 6038 | .addReg(NewVReg3)); |
| 6039 | |
| 6040 | MachineMemOperand *JTMMOLd = |
| 6041 | MF->getMachineMemOperand(MachinePointerInfo::getJumpTable(), |
| 6042 | MachineMemOperand::MOLoad, 4, 4); |
| 6043 | |
| 6044 | unsigned NewVReg5 = MRI->createVirtualRegister(TRC); |
| 6045 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tLDRi), NewVReg5) |
| 6046 | .addReg(NewVReg4, RegState::Kill) |
| 6047 | .addImm(0) |
| 6048 | .addMemOperand(JTMMOLd)); |
| 6049 | |
| 6050 | unsigned NewVReg6 = MRI->createVirtualRegister(TRC); |
| 6051 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tADDrr), NewVReg6) |
| 6052 | .addReg(ARM::CPSR, RegState::Define) |
| 6053 | .addReg(NewVReg5, RegState::Kill) |
| 6054 | .addReg(NewVReg3)); |
| 6055 | |
| 6056 | BuildMI(DispContBB, dl, TII->get(ARM::tBR_JTr)) |
| 6057 | .addReg(NewVReg6, RegState::Kill) |
| 6058 | .addJumpTableIndex(MJTI) |
| 6059 | .addImm(UId); |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6060 | } else { |
| 6061 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 6062 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::LDRi12), NewVReg1) |
| 6063 | .addFrameIndex(FI) |
| 6064 | .addImm(4) |
| 6065 | .addMemOperand(FIMMOLd)); |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6066 | |
Bill Wendling | 85f3a0a | 2011-10-18 22:52:20 +0000 | [diff] [blame] | 6067 | if (NumLPads < 256) { |
| 6068 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::CMPri)) |
| 6069 | .addReg(NewVReg1) |
| 6070 | .addImm(NumLPads)); |
Bill Wendling | 922ad78 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 6071 | } else if (Subtarget->hasV6T2Ops() && isUInt<16>(NumLPads)) { |
Bill Wendling | 85f3a0a | 2011-10-18 22:52:20 +0000 | [diff] [blame] | 6072 | unsigned VReg1 = MRI->createVirtualRegister(TRC); |
| 6073 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::MOVi16), VReg1) |
Bill Wendling | 15a1a22 | 2011-10-18 23:19:55 +0000 | [diff] [blame] | 6074 | .addImm(NumLPads & 0xFFFF)); |
| 6075 | |
| 6076 | unsigned VReg2 = VReg1; |
| 6077 | if ((NumLPads & 0xFFFF0000) != 0) { |
| 6078 | VReg2 = MRI->createVirtualRegister(TRC); |
| 6079 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::MOVTi16), VReg2) |
| 6080 | .addReg(VReg1) |
| 6081 | .addImm(NumLPads >> 16)); |
| 6082 | } |
| 6083 | |
Bill Wendling | 85f3a0a | 2011-10-18 22:52:20 +0000 | [diff] [blame] | 6084 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::CMPrr)) |
| 6085 | .addReg(NewVReg1) |
| 6086 | .addReg(VReg2)); |
Bill Wendling | 922ad78 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 6087 | } else { |
| 6088 | MachineConstantPool *ConstantPool = MF->getConstantPool(); |
| 6089 | Type *Int32Ty = Type::getInt32Ty(MF->getFunction()->getContext()); |
| 6090 | const Constant *C = ConstantInt::get(Int32Ty, NumLPads); |
| 6091 | |
| 6092 | // MachineConstantPool wants an explicit alignment. |
| 6093 | unsigned Align = getTargetData()->getPrefTypeAlignment(Int32Ty); |
| 6094 | if (Align == 0) |
| 6095 | Align = getTargetData()->getTypeAllocSize(C->getType()); |
| 6096 | unsigned Idx = ConstantPool->getConstantPoolIndex(C, Align); |
| 6097 | |
| 6098 | unsigned VReg1 = MRI->createVirtualRegister(TRC); |
| 6099 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::LDRcp)) |
| 6100 | .addReg(VReg1, RegState::Define) |
Bill Wendling | 767f8be | 2011-10-20 20:37:11 +0000 | [diff] [blame] | 6101 | .addConstantPoolIndex(Idx) |
| 6102 | .addImm(0)); |
Bill Wendling | 922ad78 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 6103 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::CMPrr)) |
| 6104 | .addReg(NewVReg1) |
| 6105 | .addReg(VReg1, RegState::Kill)); |
Bill Wendling | 85f3a0a | 2011-10-18 22:52:20 +0000 | [diff] [blame] | 6106 | } |
| 6107 | |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6108 | BuildMI(DispatchBB, dl, TII->get(ARM::Bcc)) |
| 6109 | .addMBB(TrapBB) |
| 6110 | .addImm(ARMCC::HI) |
| 6111 | .addReg(ARM::CPSR); |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6112 | |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6113 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6114 | AddDefaultCC( |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6115 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::MOVsi), NewVReg3) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6116 | .addReg(NewVReg1) |
| 6117 | .addImm(ARM_AM::getSORegOpc(ARM_AM::lsl, 2)))); |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6118 | unsigned NewVReg4 = MRI->createVirtualRegister(TRC); |
| 6119 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::LEApcrelJT), NewVReg4) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6120 | .addJumpTableIndex(MJTI) |
| 6121 | .addImm(UId)); |
| 6122 | |
| 6123 | MachineMemOperand *JTMMOLd = |
| 6124 | MF->getMachineMemOperand(MachinePointerInfo::getJumpTable(), |
| 6125 | MachineMemOperand::MOLoad, 4, 4); |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6126 | unsigned NewVReg5 = MRI->createVirtualRegister(TRC); |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6127 | AddDefaultPred( |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6128 | BuildMI(DispContBB, dl, TII->get(ARM::LDRrs), NewVReg5) |
| 6129 | .addReg(NewVReg3, RegState::Kill) |
| 6130 | .addReg(NewVReg4) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6131 | .addImm(0) |
| 6132 | .addMemOperand(JTMMOLd)); |
| 6133 | |
| 6134 | BuildMI(DispContBB, dl, TII->get(ARM::BR_JTadd)) |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6135 | .addReg(NewVReg5, RegState::Kill) |
| 6136 | .addReg(NewVReg4) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6137 | .addJumpTableIndex(MJTI) |
| 6138 | .addImm(UId); |
| 6139 | } |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6140 | |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 6141 | // Add the jump table entries as successors to the MBB. |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6142 | MachineBasicBlock *PrevMBB = 0; |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 6143 | for (std::vector<MachineBasicBlock*>::iterator |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6144 | I = LPadList.begin(), E = LPadList.end(); I != E; ++I) { |
| 6145 | MachineBasicBlock *CurMBB = *I; |
| 6146 | if (PrevMBB != CurMBB) |
| 6147 | DispContBB->addSuccessor(CurMBB); |
| 6148 | PrevMBB = CurMBB; |
| 6149 | } |
| 6150 | |
Bill Wendling | 24bb925 | 2011-10-17 05:25:09 +0000 | [diff] [blame] | 6151 | // 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] | 6152 | const ARMBaseInstrInfo *AII = static_cast<const ARMBaseInstrInfo*>(TII); |
| 6153 | const ARMBaseRegisterInfo &RI = AII->getRegisterInfo(); |
Craig Topper | 015f228 | 2012-03-04 03:33:22 +0000 | [diff] [blame] | 6154 | const uint16_t *SavedRegs = RI.getCalleeSavedRegs(MF); |
Bill Wendling | f7b0207 | 2011-10-18 18:30:49 +0000 | [diff] [blame] | 6155 | SmallVector<MachineBasicBlock*, 64> MBBLPads; |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6156 | for (SmallPtrSet<MachineBasicBlock*, 64>::iterator |
| 6157 | I = InvokeBBs.begin(), E = InvokeBBs.end(); I != E; ++I) { |
| 6158 | MachineBasicBlock *BB = *I; |
Bill Wendling | 969c9ef | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 6159 | |
| 6160 | // Remove the landing pad successor from the invoke block and replace it |
| 6161 | // with the new dispatch block. |
Bill Wendling | de39d86 | 2011-10-26 07:16:18 +0000 | [diff] [blame] | 6162 | SmallVector<MachineBasicBlock*, 4> Successors(BB->succ_begin(), |
| 6163 | BB->succ_end()); |
| 6164 | while (!Successors.empty()) { |
| 6165 | MachineBasicBlock *SMBB = Successors.pop_back_val(); |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6166 | if (SMBB->isLandingPad()) { |
| 6167 | BB->removeSuccessor(SMBB); |
Bill Wendling | f7b0207 | 2011-10-18 18:30:49 +0000 | [diff] [blame] | 6168 | MBBLPads.push_back(SMBB); |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6169 | } |
| 6170 | } |
| 6171 | |
| 6172 | BB->addSuccessor(DispatchBB); |
Bill Wendling | 969c9ef | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 6173 | |
| 6174 | // Find the invoke call and mark all of the callee-saved registers as |
| 6175 | // 'implicit defined' so that they're spilled. This prevents code from |
| 6176 | // moving instructions to before the EH block, where they will never be |
| 6177 | // executed. |
| 6178 | for (MachineBasicBlock::reverse_iterator |
| 6179 | II = BB->rbegin(), IE = BB->rend(); II != IE; ++II) { |
Evan Cheng | 5a96b3d | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 6180 | if (!II->isCall()) continue; |
Bill Wendling | 969c9ef | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 6181 | |
| 6182 | DenseMap<unsigned, bool> DefRegs; |
| 6183 | for (MachineInstr::mop_iterator |
| 6184 | OI = II->operands_begin(), OE = II->operands_end(); |
| 6185 | OI != OE; ++OI) { |
| 6186 | if (!OI->isReg()) continue; |
| 6187 | DefRegs[OI->getReg()] = true; |
| 6188 | } |
| 6189 | |
| 6190 | MachineInstrBuilder MIB(&*II); |
| 6191 | |
Bill Wendling | 5d79859 | 2011-10-14 23:55:44 +0000 | [diff] [blame] | 6192 | for (unsigned i = 0; SavedRegs[i] != 0; ++i) { |
Bill Wendling | b8dcb31 | 2011-10-22 00:29:28 +0000 | [diff] [blame] | 6193 | unsigned Reg = SavedRegs[i]; |
| 6194 | if (Subtarget->isThumb2() && |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 6195 | !ARM::tGPRRegClass.contains(Reg) && |
| 6196 | !ARM::hGPRRegClass.contains(Reg)) |
Bill Wendling | b8dcb31 | 2011-10-22 00:29:28 +0000 | [diff] [blame] | 6197 | continue; |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 6198 | if (Subtarget->isThumb1Only() && !ARM::tGPRRegClass.contains(Reg)) |
Bill Wendling | b8dcb31 | 2011-10-22 00:29:28 +0000 | [diff] [blame] | 6199 | continue; |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 6200 | if (!Subtarget->isThumb() && !ARM::GPRRegClass.contains(Reg)) |
Bill Wendling | b8dcb31 | 2011-10-22 00:29:28 +0000 | [diff] [blame] | 6201 | continue; |
| 6202 | if (!DefRegs[Reg]) |
| 6203 | MIB.addReg(Reg, RegState::ImplicitDefine | RegState::Dead); |
Bill Wendling | 5d79859 | 2011-10-14 23:55:44 +0000 | [diff] [blame] | 6204 | } |
Bill Wendling | 969c9ef | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 6205 | |
| 6206 | break; |
| 6207 | } |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6208 | } |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 6209 | |
Bill Wendling | f7b0207 | 2011-10-18 18:30:49 +0000 | [diff] [blame] | 6210 | // Mark all former landing pads as non-landing pads. The dispatch is the only |
| 6211 | // landing pad now. |
| 6212 | for (SmallVectorImpl<MachineBasicBlock*>::iterator |
| 6213 | I = MBBLPads.begin(), E = MBBLPads.end(); I != E; ++I) |
| 6214 | (*I)->setIsLandingPad(false); |
| 6215 | |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 6216 | // The instruction is gone now. |
| 6217 | MI->eraseFromParent(); |
| 6218 | |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 6219 | return MBB; |
| 6220 | } |
| 6221 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 6222 | static |
| 6223 | MachineBasicBlock *OtherSucc(MachineBasicBlock *MBB, MachineBasicBlock *Succ) { |
| 6224 | for (MachineBasicBlock::succ_iterator I = MBB->succ_begin(), |
| 6225 | E = MBB->succ_end(); I != E; ++I) |
| 6226 | if (*I != Succ) |
| 6227 | return *I; |
| 6228 | llvm_unreachable("Expecting a BB with two successors!"); |
| 6229 | } |
| 6230 | |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 6231 | MachineBasicBlock * |
Evan Cheng | ff9b373 | 2008-01-30 18:18:23 +0000 | [diff] [blame] | 6232 | ARMTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI, |
Dan Gohman | af1d8ca | 2010-05-01 00:01:06 +0000 | [diff] [blame] | 6233 | MachineBasicBlock *BB) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6234 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
Dale Johannesen | b672840 | 2009-02-13 02:25:56 +0000 | [diff] [blame] | 6235 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6236 | bool isThumb2 = Subtarget->isThumb2(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6237 | switch (MI->getOpcode()) { |
Andrew Trick | 1c3af77 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 6238 | default: { |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 6239 | MI->dump(); |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 6240 | llvm_unreachable("Unexpected instr type to insert"); |
Andrew Trick | 1c3af77 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 6241 | } |
Jim Grosbach | ee2c2a4 | 2011-09-16 21:55:56 +0000 | [diff] [blame] | 6242 | // The Thumb2 pre-indexed stores have the same MI operands, they just |
| 6243 | // define them differently in the .td files from the isel patterns, so |
| 6244 | // they need pseudos. |
| 6245 | case ARM::t2STR_preidx: |
| 6246 | MI->setDesc(TII->get(ARM::t2STR_PRE)); |
| 6247 | return BB; |
| 6248 | case ARM::t2STRB_preidx: |
| 6249 | MI->setDesc(TII->get(ARM::t2STRB_PRE)); |
| 6250 | return BB; |
| 6251 | case ARM::t2STRH_preidx: |
| 6252 | MI->setDesc(TII->get(ARM::t2STRH_PRE)); |
| 6253 | return BB; |
| 6254 | |
Jim Grosbach | 19dec20 | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 6255 | case ARM::STRi_preidx: |
| 6256 | case ARM::STRBi_preidx: { |
Jim Grosbach | 6cd5716 | 2011-08-09 21:22:41 +0000 | [diff] [blame] | 6257 | unsigned NewOpc = MI->getOpcode() == ARM::STRi_preidx ? |
Jim Grosbach | 19dec20 | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 6258 | ARM::STR_PRE_IMM : ARM::STRB_PRE_IMM; |
| 6259 | // Decode the offset. |
| 6260 | unsigned Offset = MI->getOperand(4).getImm(); |
| 6261 | bool isSub = ARM_AM::getAM2Op(Offset) == ARM_AM::sub; |
| 6262 | Offset = ARM_AM::getAM2Offset(Offset); |
| 6263 | if (isSub) |
| 6264 | Offset = -Offset; |
| 6265 | |
Jim Grosbach | 4dfe220 | 2011-08-12 21:02:34 +0000 | [diff] [blame] | 6266 | MachineMemOperand *MMO = *MI->memoperands_begin(); |
Benjamin Kramer | 2753ae3 | 2011-08-27 17:36:14 +0000 | [diff] [blame] | 6267 | BuildMI(*BB, MI, dl, TII->get(NewOpc)) |
Jim Grosbach | 19dec20 | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 6268 | .addOperand(MI->getOperand(0)) // Rn_wb |
| 6269 | .addOperand(MI->getOperand(1)) // Rt |
| 6270 | .addOperand(MI->getOperand(2)) // Rn |
| 6271 | .addImm(Offset) // offset (skip GPR==zero_reg) |
| 6272 | .addOperand(MI->getOperand(5)) // pred |
Jim Grosbach | 4dfe220 | 2011-08-12 21:02:34 +0000 | [diff] [blame] | 6273 | .addOperand(MI->getOperand(6)) |
| 6274 | .addMemOperand(MMO); |
Jim Grosbach | 19dec20 | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 6275 | MI->eraseFromParent(); |
| 6276 | return BB; |
| 6277 | } |
| 6278 | case ARM::STRr_preidx: |
Jim Grosbach | 7b8f46c | 2011-08-11 21:17:22 +0000 | [diff] [blame] | 6279 | case ARM::STRBr_preidx: |
| 6280 | case ARM::STRH_preidx: { |
| 6281 | unsigned NewOpc; |
| 6282 | switch (MI->getOpcode()) { |
| 6283 | default: llvm_unreachable("unexpected opcode!"); |
| 6284 | case ARM::STRr_preidx: NewOpc = ARM::STR_PRE_REG; break; |
| 6285 | case ARM::STRBr_preidx: NewOpc = ARM::STRB_PRE_REG; break; |
| 6286 | case ARM::STRH_preidx: NewOpc = ARM::STRH_PRE; break; |
| 6287 | } |
Jim Grosbach | 19dec20 | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 6288 | MachineInstrBuilder MIB = BuildMI(*BB, MI, dl, TII->get(NewOpc)); |
| 6289 | for (unsigned i = 0; i < MI->getNumOperands(); ++i) |
| 6290 | MIB.addOperand(MI->getOperand(i)); |
| 6291 | MI->eraseFromParent(); |
| 6292 | return BB; |
| 6293 | } |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6294 | case ARM::ATOMIC_LOAD_ADD_I8: |
| 6295 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr); |
| 6296 | case ARM::ATOMIC_LOAD_ADD_I16: |
| 6297 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr); |
| 6298 | case ARM::ATOMIC_LOAD_ADD_I32: |
| 6299 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 6300 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6301 | case ARM::ATOMIC_LOAD_AND_I8: |
| 6302 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
| 6303 | case ARM::ATOMIC_LOAD_AND_I16: |
| 6304 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
| 6305 | case ARM::ATOMIC_LOAD_AND_I32: |
| 6306 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 6307 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6308 | case ARM::ATOMIC_LOAD_OR_I8: |
| 6309 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
| 6310 | case ARM::ATOMIC_LOAD_OR_I16: |
| 6311 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
| 6312 | case ARM::ATOMIC_LOAD_OR_I32: |
| 6313 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 6314 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6315 | case ARM::ATOMIC_LOAD_XOR_I8: |
| 6316 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
| 6317 | case ARM::ATOMIC_LOAD_XOR_I16: |
| 6318 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
| 6319 | case ARM::ATOMIC_LOAD_XOR_I32: |
| 6320 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 6321 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6322 | case ARM::ATOMIC_LOAD_NAND_I8: |
| 6323 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2BICrr : ARM::BICrr); |
| 6324 | case ARM::ATOMIC_LOAD_NAND_I16: |
| 6325 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2BICrr : ARM::BICrr); |
| 6326 | case ARM::ATOMIC_LOAD_NAND_I32: |
| 6327 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2BICrr : ARM::BICrr); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 6328 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6329 | case ARM::ATOMIC_LOAD_SUB_I8: |
| 6330 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr); |
| 6331 | case ARM::ATOMIC_LOAD_SUB_I16: |
| 6332 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr); |
| 6333 | case ARM::ATOMIC_LOAD_SUB_I32: |
| 6334 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 6335 | |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 6336 | case ARM::ATOMIC_LOAD_MIN_I8: |
| 6337 | return EmitAtomicBinaryMinMax(MI, BB, 1, true, ARMCC::LT); |
| 6338 | case ARM::ATOMIC_LOAD_MIN_I16: |
| 6339 | return EmitAtomicBinaryMinMax(MI, BB, 2, true, ARMCC::LT); |
| 6340 | case ARM::ATOMIC_LOAD_MIN_I32: |
| 6341 | return EmitAtomicBinaryMinMax(MI, BB, 4, true, ARMCC::LT); |
| 6342 | |
| 6343 | case ARM::ATOMIC_LOAD_MAX_I8: |
| 6344 | return EmitAtomicBinaryMinMax(MI, BB, 1, true, ARMCC::GT); |
| 6345 | case ARM::ATOMIC_LOAD_MAX_I16: |
| 6346 | return EmitAtomicBinaryMinMax(MI, BB, 2, true, ARMCC::GT); |
| 6347 | case ARM::ATOMIC_LOAD_MAX_I32: |
| 6348 | return EmitAtomicBinaryMinMax(MI, BB, 4, true, ARMCC::GT); |
| 6349 | |
| 6350 | case ARM::ATOMIC_LOAD_UMIN_I8: |
| 6351 | return EmitAtomicBinaryMinMax(MI, BB, 1, false, ARMCC::LO); |
| 6352 | case ARM::ATOMIC_LOAD_UMIN_I16: |
| 6353 | return EmitAtomicBinaryMinMax(MI, BB, 2, false, ARMCC::LO); |
| 6354 | case ARM::ATOMIC_LOAD_UMIN_I32: |
| 6355 | return EmitAtomicBinaryMinMax(MI, BB, 4, false, ARMCC::LO); |
| 6356 | |
| 6357 | case ARM::ATOMIC_LOAD_UMAX_I8: |
| 6358 | return EmitAtomicBinaryMinMax(MI, BB, 1, false, ARMCC::HI); |
| 6359 | case ARM::ATOMIC_LOAD_UMAX_I16: |
| 6360 | return EmitAtomicBinaryMinMax(MI, BB, 2, false, ARMCC::HI); |
| 6361 | case ARM::ATOMIC_LOAD_UMAX_I32: |
| 6362 | return EmitAtomicBinaryMinMax(MI, BB, 4, false, ARMCC::HI); |
| 6363 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6364 | case ARM::ATOMIC_SWAP_I8: return EmitAtomicBinary(MI, BB, 1, 0); |
| 6365 | case ARM::ATOMIC_SWAP_I16: return EmitAtomicBinary(MI, BB, 2, 0); |
| 6366 | case ARM::ATOMIC_SWAP_I32: return EmitAtomicBinary(MI, BB, 4, 0); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 6367 | |
| 6368 | case ARM::ATOMIC_CMP_SWAP_I8: return EmitAtomicCmpSwap(MI, BB, 1); |
| 6369 | case ARM::ATOMIC_CMP_SWAP_I16: return EmitAtomicCmpSwap(MI, BB, 2); |
| 6370 | case ARM::ATOMIC_CMP_SWAP_I32: return EmitAtomicCmpSwap(MI, BB, 4); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 6371 | |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6372 | |
| 6373 | case ARM::ATOMADD6432: |
| 6374 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr, |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 6375 | isThumb2 ? ARM::t2ADCrr : ARM::ADCrr, |
| 6376 | /*NeedsCarry*/ true); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6377 | case ARM::ATOMSUB6432: |
| 6378 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr, |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 6379 | isThumb2 ? ARM::t2SBCrr : ARM::SBCrr, |
| 6380 | /*NeedsCarry*/ true); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6381 | case ARM::ATOMOR6432: |
| 6382 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr, |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 6383 | isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6384 | case ARM::ATOMXOR6432: |
| 6385 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2EORrr : ARM::EORrr, |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 6386 | isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6387 | case ARM::ATOMAND6432: |
| 6388 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr, |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 6389 | isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6390 | case ARM::ATOMSWAP6432: |
| 6391 | return EmitAtomicBinary64(MI, BB, 0, 0, false); |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 6392 | case ARM::ATOMCMPXCHG6432: |
| 6393 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr, |
| 6394 | isThumb2 ? ARM::t2SBCrr : ARM::SBCrr, |
| 6395 | /*NeedsCarry*/ false, /*IsCmpxchg*/true); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6396 | |
Evan Cheng | 007ea27 | 2009-08-12 05:17:19 +0000 | [diff] [blame] | 6397 | case ARM::tMOVCCr_pseudo: { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6398 | // To "insert" a SELECT_CC instruction, we actually have to insert the |
| 6399 | // diamond control-flow pattern. The incoming instruction knows the |
| 6400 | // destination vreg to set, the condition code register to branch on, the |
| 6401 | // true/false values to select between, and a branch opcode to use. |
| 6402 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 6403 | MachineFunction::iterator It = BB; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6404 | ++It; |
| 6405 | |
| 6406 | // thisMBB: |
| 6407 | // ... |
| 6408 | // TrueVal = ... |
| 6409 | // cmpTY ccX, r1, r2 |
| 6410 | // bCC copy1MBB |
| 6411 | // fallthrough --> copy0MBB |
| 6412 | MachineBasicBlock *thisMBB = BB; |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 6413 | MachineFunction *F = BB->getParent(); |
| 6414 | MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB); |
| 6415 | MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB); |
Dan Gohman | 258c58c | 2010-07-06 15:49:48 +0000 | [diff] [blame] | 6416 | F->insert(It, copy0MBB); |
| 6417 | F->insert(It, sinkMBB); |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 6418 | |
| 6419 | // Transfer the remainder of BB and its successor edges to sinkMBB. |
| 6420 | sinkMBB->splice(sinkMBB->begin(), BB, |
| 6421 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 6422 | BB->end()); |
| 6423 | sinkMBB->transferSuccessorsAndUpdatePHIs(BB); |
| 6424 | |
Dan Gohman | 258c58c | 2010-07-06 15:49:48 +0000 | [diff] [blame] | 6425 | BB->addSuccessor(copy0MBB); |
| 6426 | BB->addSuccessor(sinkMBB); |
Dan Gohman | b81c771 | 2010-07-06 15:18:19 +0000 | [diff] [blame] | 6427 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 6428 | BuildMI(BB, dl, TII->get(ARM::tBcc)).addMBB(sinkMBB) |
| 6429 | .addImm(MI->getOperand(3).getImm()).addReg(MI->getOperand(4).getReg()); |
| 6430 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6431 | // copy0MBB: |
| 6432 | // %FalseValue = ... |
| 6433 | // # fallthrough to sinkMBB |
| 6434 | BB = copy0MBB; |
| 6435 | |
| 6436 | // Update machine-CFG edges |
| 6437 | BB->addSuccessor(sinkMBB); |
| 6438 | |
| 6439 | // sinkMBB: |
| 6440 | // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ] |
| 6441 | // ... |
| 6442 | BB = sinkMBB; |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 6443 | BuildMI(*BB, BB->begin(), dl, |
| 6444 | TII->get(ARM::PHI), MI->getOperand(0).getReg()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6445 | .addReg(MI->getOperand(1).getReg()).addMBB(copy0MBB) |
| 6446 | .addReg(MI->getOperand(2).getReg()).addMBB(thisMBB); |
| 6447 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 6448 | MI->eraseFromParent(); // The pseudo instruction is gone now. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6449 | return BB; |
| 6450 | } |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 6451 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 6452 | case ARM::BCCi64: |
| 6453 | case ARM::BCCZi64: { |
Bob Wilson | 3c90469 | 2010-12-23 22:45:49 +0000 | [diff] [blame] | 6454 | // If there is an unconditional branch to the other successor, remove it. |
| 6455 | BB->erase(llvm::next(MachineBasicBlock::iterator(MI)), BB->end()); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 6456 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 6457 | // Compare both parts that make up the double comparison separately for |
| 6458 | // equality. |
| 6459 | bool RHSisZero = MI->getOpcode() == ARM::BCCZi64; |
| 6460 | |
| 6461 | unsigned LHS1 = MI->getOperand(1).getReg(); |
| 6462 | unsigned LHS2 = MI->getOperand(2).getReg(); |
| 6463 | if (RHSisZero) { |
| 6464 | AddDefaultPred(BuildMI(BB, dl, |
| 6465 | TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 6466 | .addReg(LHS1).addImm(0)); |
| 6467 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 6468 | .addReg(LHS2).addImm(0) |
| 6469 | .addImm(ARMCC::EQ).addReg(ARM::CPSR); |
| 6470 | } else { |
| 6471 | unsigned RHS1 = MI->getOperand(3).getReg(); |
| 6472 | unsigned RHS2 = MI->getOperand(4).getReg(); |
| 6473 | AddDefaultPred(BuildMI(BB, dl, |
| 6474 | TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
| 6475 | .addReg(LHS1).addReg(RHS1)); |
| 6476 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
| 6477 | .addReg(LHS2).addReg(RHS2) |
| 6478 | .addImm(ARMCC::EQ).addReg(ARM::CPSR); |
| 6479 | } |
| 6480 | |
| 6481 | MachineBasicBlock *destMBB = MI->getOperand(RHSisZero ? 3 : 5).getMBB(); |
| 6482 | MachineBasicBlock *exitMBB = OtherSucc(BB, destMBB); |
| 6483 | if (MI->getOperand(0).getImm() == ARMCC::NE) |
| 6484 | std::swap(destMBB, exitMBB); |
| 6485 | |
| 6486 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 6487 | .addMBB(destMBB).addImm(ARMCC::EQ).addReg(ARM::CPSR); |
Owen Anderson | 51f6a7a | 2011-09-09 21:48:23 +0000 | [diff] [blame] | 6488 | if (isThumb2) |
| 6489 | AddDefaultPred(BuildMI(BB, dl, TII->get(ARM::t2B)).addMBB(exitMBB)); |
| 6490 | else |
| 6491 | BuildMI(BB, dl, TII->get(ARM::B)) .addMBB(exitMBB); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 6492 | |
| 6493 | MI->eraseFromParent(); // The pseudo instruction is gone now. |
| 6494 | return BB; |
| 6495 | } |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 6496 | |
Bill Wendling | 5bc8528 | 2011-10-17 20:37:20 +0000 | [diff] [blame] | 6497 | case ARM::Int_eh_sjlj_setjmp: |
| 6498 | case ARM::Int_eh_sjlj_setjmp_nofp: |
| 6499 | case ARM::tInt_eh_sjlj_setjmp: |
| 6500 | case ARM::t2Int_eh_sjlj_setjmp: |
| 6501 | case ARM::t2Int_eh_sjlj_setjmp_nofp: |
| 6502 | EmitSjLjDispatchBlock(MI, BB); |
| 6503 | return BB; |
| 6504 | |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 6505 | case ARM::ABS: |
| 6506 | case ARM::t2ABS: { |
| 6507 | // To insert an ABS instruction, we have to insert the |
| 6508 | // diamond control-flow pattern. The incoming instruction knows the |
| 6509 | // source vreg to test against 0, the destination vreg to set, |
| 6510 | // the condition code register to branch on, the |
Andrew Trick | 7f5f0da | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 6511 | // true/false values to select between, and a branch opcode to use. |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 6512 | // It transforms |
| 6513 | // V1 = ABS V0 |
| 6514 | // into |
| 6515 | // V2 = MOVS V0 |
| 6516 | // BCC (branch to SinkBB if V0 >= 0) |
| 6517 | // RSBBB: V3 = RSBri V2, 0 (compute ABS if V2 < 0) |
Andrew Trick | 7f5f0da | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 6518 | // SinkBB: V1 = PHI(V2, V3) |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 6519 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 6520 | MachineFunction::iterator BBI = BB; |
| 6521 | ++BBI; |
| 6522 | MachineFunction *Fn = BB->getParent(); |
| 6523 | MachineBasicBlock *RSBBB = Fn->CreateMachineBasicBlock(LLVM_BB); |
| 6524 | MachineBasicBlock *SinkBB = Fn->CreateMachineBasicBlock(LLVM_BB); |
| 6525 | Fn->insert(BBI, RSBBB); |
| 6526 | Fn->insert(BBI, SinkBB); |
| 6527 | |
| 6528 | unsigned int ABSSrcReg = MI->getOperand(1).getReg(); |
| 6529 | unsigned int ABSDstReg = MI->getOperand(0).getReg(); |
| 6530 | bool isThumb2 = Subtarget->isThumb2(); |
| 6531 | MachineRegisterInfo &MRI = Fn->getRegInfo(); |
| 6532 | // In Thumb mode S must not be specified if source register is the SP or |
| 6533 | // PC and if destination register is the SP, so restrict register class |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 6534 | unsigned NewMovDstReg = MRI.createVirtualRegister(isThumb2 ? |
| 6535 | (const TargetRegisterClass*)&ARM::rGPRRegClass : |
| 6536 | (const TargetRegisterClass*)&ARM::GPRRegClass); |
| 6537 | unsigned NewRsbDstReg = MRI.createVirtualRegister(isThumb2 ? |
| 6538 | (const TargetRegisterClass*)&ARM::rGPRRegClass : |
| 6539 | (const TargetRegisterClass*)&ARM::GPRRegClass); |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 6540 | |
| 6541 | // Transfer the remainder of BB and its successor edges to sinkMBB. |
| 6542 | SinkBB->splice(SinkBB->begin(), BB, |
| 6543 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 6544 | BB->end()); |
| 6545 | SinkBB->transferSuccessorsAndUpdatePHIs(BB); |
| 6546 | |
| 6547 | BB->addSuccessor(RSBBB); |
| 6548 | BB->addSuccessor(SinkBB); |
| 6549 | |
| 6550 | // fall through to SinkMBB |
| 6551 | RSBBB->addSuccessor(SinkBB); |
| 6552 | |
| 6553 | // insert a movs at the end of BB |
| 6554 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2MOVr : ARM::MOVr), |
| 6555 | NewMovDstReg) |
| 6556 | .addReg(ABSSrcReg, RegState::Kill) |
| 6557 | .addImm((unsigned)ARMCC::AL).addReg(0) |
| 6558 | .addReg(ARM::CPSR, RegState::Define); |
| 6559 | |
| 6560 | // 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] | 6561 | BuildMI(BB, dl, |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 6562 | TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)).addMBB(SinkBB) |
| 6563 | .addImm(ARMCC::getOppositeCondition(ARMCC::MI)).addReg(ARM::CPSR); |
| 6564 | |
| 6565 | // insert rsbri in RSBBB |
| 6566 | // Note: BCC and rsbri will be converted into predicated rsbmi |
| 6567 | // by if-conversion pass |
Andrew Trick | 7f5f0da | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 6568 | BuildMI(*RSBBB, RSBBB->begin(), dl, |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 6569 | TII->get(isThumb2 ? ARM::t2RSBri : ARM::RSBri), NewRsbDstReg) |
| 6570 | .addReg(NewMovDstReg, RegState::Kill) |
| 6571 | .addImm(0).addImm((unsigned)ARMCC::AL).addReg(0).addReg(0); |
| 6572 | |
Andrew Trick | 7f5f0da | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 6573 | // insert PHI in SinkBB, |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 6574 | // reuse ABSDstReg to not change uses of ABS instruction |
| 6575 | BuildMI(*SinkBB, SinkBB->begin(), dl, |
| 6576 | TII->get(ARM::PHI), ABSDstReg) |
| 6577 | .addReg(NewRsbDstReg).addMBB(RSBBB) |
| 6578 | .addReg(NewMovDstReg).addMBB(BB); |
| 6579 | |
| 6580 | // remove ABS instruction |
Andrew Trick | 7f5f0da | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 6581 | MI->eraseFromParent(); |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 6582 | |
| 6583 | // return last added BB |
| 6584 | return SinkBB; |
| 6585 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6586 | } |
| 6587 | } |
| 6588 | |
Evan Cheng | 37fefc2 | 2011-08-30 19:09:48 +0000 | [diff] [blame] | 6589 | void ARMTargetLowering::AdjustInstrPostInstrSelection(MachineInstr *MI, |
| 6590 | SDNode *Node) const { |
Evan Cheng | 5a96b3d | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 6591 | if (!MI->hasPostISelHook()) { |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 6592 | assert(!convertAddSubFlagsOpcode(MI->getOpcode()) && |
| 6593 | "Pseudo flag-setting opcodes must be marked with 'hasPostISelHook'"); |
| 6594 | return; |
| 6595 | } |
| 6596 | |
Evan Cheng | 5a96b3d | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 6597 | const MCInstrDesc *MCID = &MI->getDesc(); |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6598 | // Adjust potentially 's' setting instructions after isel, i.e. ADC, SBC, RSB, |
| 6599 | // RSC. Coming out of isel, they have an implicit CPSR def, but the optional |
| 6600 | // operand is still set to noreg. If needed, set the optional operand's |
| 6601 | // register to CPSR, and remove the redundant implicit def. |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 6602 | // |
Andrew Trick | 90b7b12 | 2011-10-18 19:18:52 +0000 | [diff] [blame] | 6603 | // e.g. ADCS (..., CPSR<imp-def>) -> ADC (... opt:CPSR<def>). |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6604 | |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 6605 | // Rename pseudo opcodes. |
| 6606 | unsigned NewOpc = convertAddSubFlagsOpcode(MI->getOpcode()); |
| 6607 | if (NewOpc) { |
| 6608 | const ARMBaseInstrInfo *TII = |
| 6609 | static_cast<const ARMBaseInstrInfo*>(getTargetMachine().getInstrInfo()); |
Andrew Trick | 90b7b12 | 2011-10-18 19:18:52 +0000 | [diff] [blame] | 6610 | MCID = &TII->get(NewOpc); |
| 6611 | |
| 6612 | assert(MCID->getNumOperands() == MI->getDesc().getNumOperands() + 1 && |
| 6613 | "converted opcode should be the same except for cc_out"); |
| 6614 | |
| 6615 | MI->setDesc(*MCID); |
| 6616 | |
| 6617 | // Add the optional cc_out operand |
| 6618 | MI->addOperand(MachineOperand::CreateReg(0, /*isDef=*/true)); |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 6619 | } |
Andrew Trick | 90b7b12 | 2011-10-18 19:18:52 +0000 | [diff] [blame] | 6620 | unsigned ccOutIdx = MCID->getNumOperands() - 1; |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6621 | |
| 6622 | // Any ARM instruction that sets the 's' bit should specify an optional |
| 6623 | // "cc_out" operand in the last operand position. |
Evan Cheng | 5a96b3d | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 6624 | if (!MI->hasOptionalDef() || !MCID->OpInfo[ccOutIdx].isOptionalDef()) { |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 6625 | assert(!NewOpc && "Optional cc_out operand required"); |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6626 | return; |
| 6627 | } |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 6628 | // Look for an implicit def of CPSR added by MachineInstr ctor. Remove it |
| 6629 | // since we already have an optional CPSR def. |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6630 | bool definesCPSR = false; |
| 6631 | bool deadCPSR = false; |
Andrew Trick | 90b7b12 | 2011-10-18 19:18:52 +0000 | [diff] [blame] | 6632 | for (unsigned i = MCID->getNumOperands(), e = MI->getNumOperands(); |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6633 | i != e; ++i) { |
| 6634 | const MachineOperand &MO = MI->getOperand(i); |
| 6635 | if (MO.isReg() && MO.isDef() && MO.getReg() == ARM::CPSR) { |
| 6636 | definesCPSR = true; |
| 6637 | if (MO.isDead()) |
| 6638 | deadCPSR = true; |
| 6639 | MI->RemoveOperand(i); |
| 6640 | break; |
Evan Cheng | 37fefc2 | 2011-08-30 19:09:48 +0000 | [diff] [blame] | 6641 | } |
| 6642 | } |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6643 | if (!definesCPSR) { |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 6644 | assert(!NewOpc && "Optional cc_out operand required"); |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6645 | return; |
| 6646 | } |
| 6647 | assert(deadCPSR == !Node->hasAnyUseOfValue(1) && "inconsistent dead flag"); |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 6648 | if (deadCPSR) { |
| 6649 | assert(!MI->getOperand(ccOutIdx).getReg() && |
| 6650 | "expect uninitialized optional cc_out operand"); |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6651 | return; |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 6652 | } |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6653 | |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 6654 | // If this instruction was defined with an optional CPSR def and its dag node |
| 6655 | // had a live implicit CPSR def, then activate the optional CPSR def. |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6656 | MachineOperand &MO = MI->getOperand(ccOutIdx); |
| 6657 | MO.setReg(ARM::CPSR); |
| 6658 | MO.setIsDef(true); |
Evan Cheng | 37fefc2 | 2011-08-30 19:09:48 +0000 | [diff] [blame] | 6659 | } |
| 6660 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6661 | //===----------------------------------------------------------------------===// |
| 6662 | // ARM Optimization Hooks |
| 6663 | //===----------------------------------------------------------------------===// |
| 6664 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 6665 | static |
| 6666 | SDValue combineSelectAndUse(SDNode *N, SDValue Slct, SDValue OtherOp, |
| 6667 | TargetLowering::DAGCombinerInfo &DCI) { |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 6668 | SelectionDAG &DAG = DCI.DAG; |
| 6669 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6670 | EVT VT = N->getValueType(0); |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 6671 | unsigned Opc = N->getOpcode(); |
| 6672 | bool isSlctCC = Slct.getOpcode() == ISD::SELECT_CC; |
| 6673 | SDValue LHS = isSlctCC ? Slct.getOperand(2) : Slct.getOperand(1); |
| 6674 | SDValue RHS = isSlctCC ? Slct.getOperand(3) : Slct.getOperand(2); |
| 6675 | ISD::CondCode CC = ISD::SETCC_INVALID; |
| 6676 | |
| 6677 | if (isSlctCC) { |
| 6678 | CC = cast<CondCodeSDNode>(Slct.getOperand(4))->get(); |
| 6679 | } else { |
| 6680 | SDValue CCOp = Slct.getOperand(0); |
| 6681 | if (CCOp.getOpcode() == ISD::SETCC) |
| 6682 | CC = cast<CondCodeSDNode>(CCOp.getOperand(2))->get(); |
| 6683 | } |
| 6684 | |
| 6685 | bool DoXform = false; |
| 6686 | bool InvCC = false; |
| 6687 | assert ((Opc == ISD::ADD || (Opc == ISD::SUB && Slct == N->getOperand(1))) && |
| 6688 | "Bad input!"); |
| 6689 | |
| 6690 | if (LHS.getOpcode() == ISD::Constant && |
| 6691 | cast<ConstantSDNode>(LHS)->isNullValue()) { |
| 6692 | DoXform = true; |
| 6693 | } else if (CC != ISD::SETCC_INVALID && |
| 6694 | RHS.getOpcode() == ISD::Constant && |
| 6695 | cast<ConstantSDNode>(RHS)->isNullValue()) { |
| 6696 | std::swap(LHS, RHS); |
| 6697 | SDValue Op0 = Slct.getOperand(0); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6698 | EVT OpVT = isSlctCC ? Op0.getValueType() : |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 6699 | Op0.getOperand(0).getValueType(); |
| 6700 | bool isInt = OpVT.isInteger(); |
| 6701 | CC = ISD::getSetCCInverse(CC, isInt); |
| 6702 | |
| 6703 | if (!TLI.isCondCodeLegal(CC, OpVT)) |
| 6704 | return SDValue(); // Inverse operator isn't legal. |
| 6705 | |
| 6706 | DoXform = true; |
| 6707 | InvCC = true; |
| 6708 | } |
| 6709 | |
| 6710 | if (DoXform) { |
| 6711 | SDValue Result = DAG.getNode(Opc, RHS.getDebugLoc(), VT, OtherOp, RHS); |
| 6712 | if (isSlctCC) |
| 6713 | return DAG.getSelectCC(N->getDebugLoc(), OtherOp, Result, |
| 6714 | Slct.getOperand(0), Slct.getOperand(1), CC); |
| 6715 | SDValue CCOp = Slct.getOperand(0); |
| 6716 | if (InvCC) |
| 6717 | CCOp = DAG.getSetCC(Slct.getDebugLoc(), CCOp.getValueType(), |
| 6718 | CCOp.getOperand(0), CCOp.getOperand(1), CC); |
| 6719 | return DAG.getNode(ISD::SELECT, N->getDebugLoc(), VT, |
| 6720 | CCOp, OtherOp, Result); |
| 6721 | } |
| 6722 | return SDValue(); |
| 6723 | } |
| 6724 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 6725 | // AddCombineToVPADDL- For pair-wise add on neon, use the vpaddl instruction |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6726 | // (only after legalization). |
| 6727 | static SDValue AddCombineToVPADDL(SDNode *N, SDValue N0, SDValue N1, |
| 6728 | TargetLowering::DAGCombinerInfo &DCI, |
| 6729 | const ARMSubtarget *Subtarget) { |
| 6730 | |
| 6731 | // Only perform optimization if after legalize, and if NEON is available. We |
| 6732 | // also expected both operands to be BUILD_VECTORs. |
| 6733 | if (DCI.isBeforeLegalize() || !Subtarget->hasNEON() |
| 6734 | || N0.getOpcode() != ISD::BUILD_VECTOR |
| 6735 | || N1.getOpcode() != ISD::BUILD_VECTOR) |
| 6736 | return SDValue(); |
| 6737 | |
| 6738 | // Check output type since VPADDL operand elements can only be 8, 16, or 32. |
| 6739 | EVT VT = N->getValueType(0); |
| 6740 | if (!VT.isInteger() || VT.getVectorElementType() == MVT::i64) |
| 6741 | return SDValue(); |
| 6742 | |
| 6743 | // Check that the vector operands are of the right form. |
| 6744 | // N0 and N1 are BUILD_VECTOR nodes with N number of EXTRACT_VECTOR |
| 6745 | // operands, where N is the size of the formed vector. |
| 6746 | // Each EXTRACT_VECTOR should have the same input vector and odd or even |
| 6747 | // index such that we have a pair wise add pattern. |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6748 | |
| 6749 | // Grab the vector that all EXTRACT_VECTOR nodes should be referencing. |
Bob Wilson | 7a10ab7 | 2011-06-15 06:04:34 +0000 | [diff] [blame] | 6750 | if (N0->getOperand(0)->getOpcode() != ISD::EXTRACT_VECTOR_ELT) |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6751 | return SDValue(); |
Bob Wilson | 7a10ab7 | 2011-06-15 06:04:34 +0000 | [diff] [blame] | 6752 | SDValue Vec = N0->getOperand(0)->getOperand(0); |
| 6753 | SDNode *V = Vec.getNode(); |
| 6754 | unsigned nextIndex = 0; |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6755 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 6756 | // For each operands to the ADD which are BUILD_VECTORs, |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6757 | // check to see if each of their operands are an EXTRACT_VECTOR with |
| 6758 | // the same vector and appropriate index. |
| 6759 | for (unsigned i = 0, e = N0->getNumOperands(); i != e; ++i) { |
| 6760 | if (N0->getOperand(i)->getOpcode() == ISD::EXTRACT_VECTOR_ELT |
| 6761 | && N1->getOperand(i)->getOpcode() == ISD::EXTRACT_VECTOR_ELT) { |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 6762 | |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6763 | SDValue ExtVec0 = N0->getOperand(i); |
| 6764 | SDValue ExtVec1 = N1->getOperand(i); |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 6765 | |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6766 | // First operand is the vector, verify its the same. |
| 6767 | if (V != ExtVec0->getOperand(0).getNode() || |
| 6768 | V != ExtVec1->getOperand(0).getNode()) |
| 6769 | return SDValue(); |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 6770 | |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6771 | // Second is the constant, verify its correct. |
| 6772 | ConstantSDNode *C0 = dyn_cast<ConstantSDNode>(ExtVec0->getOperand(1)); |
| 6773 | ConstantSDNode *C1 = dyn_cast<ConstantSDNode>(ExtVec1->getOperand(1)); |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 6774 | |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6775 | // For the constant, we want to see all the even or all the odd. |
| 6776 | if (!C0 || !C1 || C0->getZExtValue() != nextIndex |
| 6777 | || C1->getZExtValue() != nextIndex+1) |
| 6778 | return SDValue(); |
| 6779 | |
| 6780 | // Increment index. |
| 6781 | nextIndex+=2; |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 6782 | } else |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6783 | return SDValue(); |
| 6784 | } |
| 6785 | |
| 6786 | // Create VPADDL node. |
| 6787 | SelectionDAG &DAG = DCI.DAG; |
| 6788 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6789 | |
| 6790 | // Build operand list. |
| 6791 | SmallVector<SDValue, 8> Ops; |
| 6792 | Ops.push_back(DAG.getConstant(Intrinsic::arm_neon_vpaddls, |
| 6793 | TLI.getPointerTy())); |
| 6794 | |
| 6795 | // Input is the vector. |
| 6796 | Ops.push_back(Vec); |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 6797 | |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6798 | // Get widened type and narrowed type. |
| 6799 | MVT widenType; |
| 6800 | unsigned numElem = VT.getVectorNumElements(); |
| 6801 | switch (VT.getVectorElementType().getSimpleVT().SimpleTy) { |
| 6802 | case MVT::i8: widenType = MVT::getVectorVT(MVT::i16, numElem); break; |
| 6803 | case MVT::i16: widenType = MVT::getVectorVT(MVT::i32, numElem); break; |
| 6804 | case MVT::i32: widenType = MVT::getVectorVT(MVT::i64, numElem); break; |
| 6805 | default: |
Craig Topper | bc21981 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 6806 | llvm_unreachable("Invalid vector element type for padd optimization."); |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6807 | } |
| 6808 | |
| 6809 | SDValue tmp = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, N->getDebugLoc(), |
| 6810 | widenType, &Ops[0], Ops.size()); |
| 6811 | return DAG.getNode(ISD::TRUNCATE, N->getDebugLoc(), VT, tmp); |
| 6812 | } |
| 6813 | |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 6814 | /// PerformADDCombineWithOperands - Try DAG combinations for an ADD with |
| 6815 | /// operands N0 and N1. This is a helper for PerformADDCombine that is |
| 6816 | /// called with the default operands, and if that fails, with commuted |
| 6817 | /// operands. |
| 6818 | static SDValue PerformADDCombineWithOperands(SDNode *N, SDValue N0, SDValue N1, |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6819 | TargetLowering::DAGCombinerInfo &DCI, |
| 6820 | const ARMSubtarget *Subtarget){ |
| 6821 | |
| 6822 | // Attempt to create vpaddl for this add. |
| 6823 | SDValue Result = AddCombineToVPADDL(N, N0, N1, DCI, Subtarget); |
| 6824 | if (Result.getNode()) |
| 6825 | return Result; |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 6826 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 6827 | // fold (add (select cc, 0, c), x) -> (select cc, x, (add, x, c)) |
| 6828 | if (N0.getOpcode() == ISD::SELECT && N0.getNode()->hasOneUse()) { |
| 6829 | SDValue Result = combineSelectAndUse(N, N0, N1, DCI); |
| 6830 | if (Result.getNode()) return Result; |
| 6831 | } |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 6832 | return SDValue(); |
| 6833 | } |
| 6834 | |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 6835 | /// PerformADDCombine - Target-specific dag combine xforms for ISD::ADD. |
| 6836 | /// |
| 6837 | static SDValue PerformADDCombine(SDNode *N, |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6838 | TargetLowering::DAGCombinerInfo &DCI, |
| 6839 | const ARMSubtarget *Subtarget) { |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 6840 | SDValue N0 = N->getOperand(0); |
| 6841 | SDValue N1 = N->getOperand(1); |
| 6842 | |
| 6843 | // First try with the default operand order. |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6844 | SDValue Result = PerformADDCombineWithOperands(N, N0, N1, DCI, Subtarget); |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 6845 | if (Result.getNode()) |
| 6846 | return Result; |
| 6847 | |
| 6848 | // If that didn't work, try again with the operands commuted. |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6849 | return PerformADDCombineWithOperands(N, N1, N0, DCI, Subtarget); |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 6850 | } |
| 6851 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 6852 | /// PerformSUBCombine - Target-specific dag combine xforms for ISD::SUB. |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 6853 | /// |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 6854 | static SDValue PerformSUBCombine(SDNode *N, |
| 6855 | TargetLowering::DAGCombinerInfo &DCI) { |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 6856 | SDValue N0 = N->getOperand(0); |
| 6857 | SDValue N1 = N->getOperand(1); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 6858 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 6859 | // fold (sub x, (select cc, 0, c)) -> (select cc, x, (sub, x, c)) |
| 6860 | if (N1.getOpcode() == ISD::SELECT && N1.getNode()->hasOneUse()) { |
| 6861 | SDValue Result = combineSelectAndUse(N, N1, N0, DCI); |
| 6862 | if (Result.getNode()) return Result; |
| 6863 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 6864 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 6865 | return SDValue(); |
| 6866 | } |
| 6867 | |
Evan Cheng | 463d358 | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 6868 | /// PerformVMULCombine |
| 6869 | /// Distribute (A + B) * C to (A * C) + (B * C) to take advantage of the |
| 6870 | /// special multiplier accumulator forwarding. |
| 6871 | /// vmul d3, d0, d2 |
| 6872 | /// vmla d3, d1, d2 |
| 6873 | /// is faster than |
| 6874 | /// vadd d3, d0, d1 |
| 6875 | /// vmul d3, d3, d2 |
| 6876 | static SDValue PerformVMULCombine(SDNode *N, |
| 6877 | TargetLowering::DAGCombinerInfo &DCI, |
| 6878 | const ARMSubtarget *Subtarget) { |
| 6879 | if (!Subtarget->hasVMLxForwarding()) |
| 6880 | return SDValue(); |
| 6881 | |
| 6882 | SelectionDAG &DAG = DCI.DAG; |
| 6883 | SDValue N0 = N->getOperand(0); |
| 6884 | SDValue N1 = N->getOperand(1); |
| 6885 | unsigned Opcode = N0.getOpcode(); |
| 6886 | if (Opcode != ISD::ADD && Opcode != ISD::SUB && |
| 6887 | Opcode != ISD::FADD && Opcode != ISD::FSUB) { |
Chad Rosier | 689edc8 | 2011-06-16 01:21:54 +0000 | [diff] [blame] | 6888 | Opcode = N1.getOpcode(); |
Evan Cheng | 463d358 | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 6889 | if (Opcode != ISD::ADD && Opcode != ISD::SUB && |
| 6890 | Opcode != ISD::FADD && Opcode != ISD::FSUB) |
| 6891 | return SDValue(); |
| 6892 | std::swap(N0, N1); |
| 6893 | } |
| 6894 | |
| 6895 | EVT VT = N->getValueType(0); |
| 6896 | DebugLoc DL = N->getDebugLoc(); |
| 6897 | SDValue N00 = N0->getOperand(0); |
| 6898 | SDValue N01 = N0->getOperand(1); |
| 6899 | return DAG.getNode(Opcode, DL, VT, |
| 6900 | DAG.getNode(ISD::MUL, DL, VT, N00, N1), |
| 6901 | DAG.getNode(ISD::MUL, DL, VT, N01, N1)); |
| 6902 | } |
| 6903 | |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 6904 | static SDValue PerformMULCombine(SDNode *N, |
| 6905 | TargetLowering::DAGCombinerInfo &DCI, |
| 6906 | const ARMSubtarget *Subtarget) { |
| 6907 | SelectionDAG &DAG = DCI.DAG; |
| 6908 | |
| 6909 | if (Subtarget->isThumb1Only()) |
| 6910 | return SDValue(); |
| 6911 | |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 6912 | if (DCI.isBeforeLegalize() || DCI.isCalledByLegalizer()) |
| 6913 | return SDValue(); |
| 6914 | |
| 6915 | EVT VT = N->getValueType(0); |
Evan Cheng | 463d358 | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 6916 | if (VT.is64BitVector() || VT.is128BitVector()) |
| 6917 | return PerformVMULCombine(N, DCI, Subtarget); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 6918 | if (VT != MVT::i32) |
| 6919 | return SDValue(); |
| 6920 | |
| 6921 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1)); |
| 6922 | if (!C) |
| 6923 | return SDValue(); |
| 6924 | |
Anton Korobeynikov | 2d7ea04 | 2012-03-19 19:19:50 +0000 | [diff] [blame] | 6925 | int64_t MulAmt = C->getSExtValue(); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 6926 | unsigned ShiftAmt = CountTrailingZeros_64(MulAmt); |
Anton Korobeynikov | 2d7ea04 | 2012-03-19 19:19:50 +0000 | [diff] [blame] | 6927 | |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 6928 | ShiftAmt = ShiftAmt & (32 - 1); |
| 6929 | SDValue V = N->getOperand(0); |
| 6930 | DebugLoc DL = N->getDebugLoc(); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 6931 | |
Anton Korobeynikov | 4878b84 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 6932 | SDValue Res; |
| 6933 | MulAmt >>= ShiftAmt; |
Anton Korobeynikov | 2d7ea04 | 2012-03-19 19:19:50 +0000 | [diff] [blame] | 6934 | |
| 6935 | if (MulAmt >= 0) { |
| 6936 | if (isPowerOf2_32(MulAmt - 1)) { |
| 6937 | // (mul x, 2^N + 1) => (add (shl x, N), x) |
| 6938 | Res = DAG.getNode(ISD::ADD, DL, VT, |
| 6939 | V, |
| 6940 | DAG.getNode(ISD::SHL, DL, VT, |
| 6941 | V, |
| 6942 | DAG.getConstant(Log2_32(MulAmt - 1), |
| 6943 | MVT::i32))); |
| 6944 | } else if (isPowerOf2_32(MulAmt + 1)) { |
| 6945 | // (mul x, 2^N - 1) => (sub (shl x, N), x) |
| 6946 | Res = DAG.getNode(ISD::SUB, DL, VT, |
| 6947 | DAG.getNode(ISD::SHL, DL, VT, |
| 6948 | V, |
| 6949 | DAG.getConstant(Log2_32(MulAmt + 1), |
| 6950 | MVT::i32)), |
| 6951 | V); |
| 6952 | } else |
| 6953 | return SDValue(); |
| 6954 | } else { |
| 6955 | uint64_t MulAmtAbs = -MulAmt; |
| 6956 | if (isPowerOf2_32(MulAmtAbs + 1)) { |
| 6957 | // (mul x, -(2^N - 1)) => (sub x, (shl x, N)) |
| 6958 | Res = DAG.getNode(ISD::SUB, DL, VT, |
| 6959 | V, |
| 6960 | DAG.getNode(ISD::SHL, DL, VT, |
| 6961 | V, |
| 6962 | DAG.getConstant(Log2_32(MulAmtAbs + 1), |
| 6963 | MVT::i32))); |
| 6964 | } else if (isPowerOf2_32(MulAmtAbs - 1)) { |
| 6965 | // (mul x, -(2^N + 1)) => - (add (shl x, N), x) |
| 6966 | Res = DAG.getNode(ISD::ADD, DL, VT, |
| 6967 | V, |
| 6968 | DAG.getNode(ISD::SHL, DL, VT, |
| 6969 | V, |
| 6970 | DAG.getConstant(Log2_32(MulAmtAbs-1), |
| 6971 | MVT::i32))); |
| 6972 | Res = DAG.getNode(ISD::SUB, DL, VT, |
| 6973 | DAG.getConstant(0, MVT::i32),Res); |
| 6974 | |
| 6975 | } else |
| 6976 | return SDValue(); |
| 6977 | } |
Anton Korobeynikov | 4878b84 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 6978 | |
| 6979 | if (ShiftAmt != 0) |
Anton Korobeynikov | 2d7ea04 | 2012-03-19 19:19:50 +0000 | [diff] [blame] | 6980 | Res = DAG.getNode(ISD::SHL, DL, VT, |
| 6981 | Res, DAG.getConstant(ShiftAmt, MVT::i32)); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 6982 | |
| 6983 | // Do not add new nodes to DAG combiner worklist. |
Anton Korobeynikov | 4878b84 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 6984 | DCI.CombineTo(N, Res, false); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 6985 | return SDValue(); |
| 6986 | } |
| 6987 | |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 6988 | static bool isCMOVWithZeroOrAllOnesLHS(SDValue N, bool AllOnes) { |
| 6989 | if (N.getOpcode() != ARMISD::CMOV || !N.getNode()->hasOneUse()) |
| 6990 | return false; |
| 6991 | |
| 6992 | SDValue FalseVal = N.getOperand(0); |
| 6993 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(FalseVal); |
| 6994 | if (!C) |
| 6995 | return false; |
| 6996 | if (AllOnes) |
| 6997 | return C->isAllOnesValue(); |
| 6998 | return C->isNullValue(); |
| 6999 | } |
| 7000 | |
| 7001 | /// formConditionalOp - Combine an operation with a conditional move operand |
| 7002 | /// to form a conditional op. e.g. (or x, (cmov 0, y, cond)) => (or.cond x, y) |
| 7003 | /// (and x, (cmov -1, y, cond)) => (and.cond, x, y) |
| 7004 | static SDValue formConditionalOp(SDNode *N, SelectionDAG &DAG, |
| 7005 | bool Commutable) { |
| 7006 | SDValue N0 = N->getOperand(0); |
| 7007 | SDValue N1 = N->getOperand(1); |
| 7008 | |
| 7009 | bool isAND = N->getOpcode() == ISD::AND; |
| 7010 | bool isCand = isCMOVWithZeroOrAllOnesLHS(N1, isAND); |
| 7011 | if (!isCand && Commutable) { |
| 7012 | isCand = isCMOVWithZeroOrAllOnesLHS(N0, isAND); |
| 7013 | if (isCand) |
| 7014 | std::swap(N0, N1); |
| 7015 | } |
| 7016 | if (!isCand) |
| 7017 | return SDValue(); |
| 7018 | |
| 7019 | unsigned Opc = 0; |
| 7020 | switch (N->getOpcode()) { |
| 7021 | default: llvm_unreachable("Unexpected node"); |
| 7022 | case ISD::AND: Opc = ARMISD::CAND; break; |
| 7023 | case ISD::OR: Opc = ARMISD::COR; break; |
| 7024 | case ISD::XOR: Opc = ARMISD::CXOR; break; |
| 7025 | } |
| 7026 | return DAG.getNode(Opc, N->getDebugLoc(), N->getValueType(0), N0, |
| 7027 | N1.getOperand(1), N1.getOperand(2), N1.getOperand(3), |
| 7028 | N1.getOperand(4)); |
| 7029 | } |
| 7030 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 7031 | static SDValue PerformANDCombine(SDNode *N, |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 7032 | TargetLowering::DAGCombinerInfo &DCI, |
| 7033 | const ARMSubtarget *Subtarget) { |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 7034 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 7035 | // Attempt to use immediate-form VBIC |
| 7036 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(N->getOperand(1)); |
| 7037 | DebugLoc dl = N->getDebugLoc(); |
| 7038 | EVT VT = N->getValueType(0); |
| 7039 | SelectionDAG &DAG = DCI.DAG; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7040 | |
Tanya Lattner | 0433b21 | 2011-04-07 15:24:20 +0000 | [diff] [blame] | 7041 | if(!DAG.getTargetLoweringInfo().isTypeLegal(VT)) |
| 7042 | return SDValue(); |
Andrew Trick | 1c3af77 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 7043 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 7044 | APInt SplatBits, SplatUndef; |
| 7045 | unsigned SplatBitSize; |
| 7046 | bool HasAnyUndefs; |
| 7047 | if (BVN && |
| 7048 | BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { |
| 7049 | if (SplatBitSize <= 64) { |
| 7050 | EVT VbicVT; |
| 7051 | SDValue Val = isNEONModifiedImm((~SplatBits).getZExtValue(), |
| 7052 | SplatUndef.getZExtValue(), SplatBitSize, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7053 | DAG, VbicVT, VT.is128BitVector(), |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 7054 | OtherModImm); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 7055 | if (Val.getNode()) { |
| 7056 | SDValue Input = |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7057 | DAG.getNode(ISD::BITCAST, dl, VbicVT, N->getOperand(0)); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 7058 | SDValue Vbic = DAG.getNode(ARMISD::VBICIMM, dl, VbicVT, Input, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7059 | return DAG.getNode(ISD::BITCAST, dl, VT, Vbic); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 7060 | } |
| 7061 | } |
| 7062 | } |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7063 | |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 7064 | if (!Subtarget->isThumb1Only()) { |
| 7065 | // (and x, (cmov -1, y, cond)) => (and.cond x, y) |
| 7066 | SDValue CAND = formConditionalOp(N, DAG, true); |
| 7067 | if (CAND.getNode()) |
| 7068 | return CAND; |
| 7069 | } |
| 7070 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 7071 | return SDValue(); |
| 7072 | } |
| 7073 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 7074 | /// PerformORCombine - Target-specific dag combine xforms for ISD::OR |
| 7075 | static SDValue PerformORCombine(SDNode *N, |
| 7076 | TargetLowering::DAGCombinerInfo &DCI, |
| 7077 | const ARMSubtarget *Subtarget) { |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 7078 | // Attempt to use immediate-form VORR |
| 7079 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(N->getOperand(1)); |
| 7080 | DebugLoc dl = N->getDebugLoc(); |
| 7081 | EVT VT = N->getValueType(0); |
| 7082 | SelectionDAG &DAG = DCI.DAG; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7083 | |
Tanya Lattner | 0433b21 | 2011-04-07 15:24:20 +0000 | [diff] [blame] | 7084 | if(!DAG.getTargetLoweringInfo().isTypeLegal(VT)) |
| 7085 | return SDValue(); |
Andrew Trick | 1c3af77 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 7086 | |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 7087 | APInt SplatBits, SplatUndef; |
| 7088 | unsigned SplatBitSize; |
| 7089 | bool HasAnyUndefs; |
| 7090 | if (BVN && Subtarget->hasNEON() && |
| 7091 | BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { |
| 7092 | if (SplatBitSize <= 64) { |
| 7093 | EVT VorrVT; |
| 7094 | SDValue Val = isNEONModifiedImm(SplatBits.getZExtValue(), |
| 7095 | SplatUndef.getZExtValue(), SplatBitSize, |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 7096 | DAG, VorrVT, VT.is128BitVector(), |
| 7097 | OtherModImm); |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 7098 | if (Val.getNode()) { |
| 7099 | SDValue Input = |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7100 | DAG.getNode(ISD::BITCAST, dl, VorrVT, N->getOperand(0)); |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 7101 | SDValue Vorr = DAG.getNode(ARMISD::VORRIMM, dl, VorrVT, Input, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7102 | return DAG.getNode(ISD::BITCAST, dl, VT, Vorr); |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 7103 | } |
| 7104 | } |
| 7105 | } |
| 7106 | |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 7107 | if (!Subtarget->isThumb1Only()) { |
| 7108 | // (or x, (cmov 0, y, cond)) => (or.cond x, y) |
| 7109 | SDValue COR = formConditionalOp(N, DAG, true); |
| 7110 | if (COR.getNode()) |
| 7111 | return COR; |
| 7112 | } |
| 7113 | |
Cameron Zwarich | c0e6d78 | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 7114 | SDValue N0 = N->getOperand(0); |
| 7115 | if (N0.getOpcode() != ISD::AND) |
| 7116 | return SDValue(); |
| 7117 | SDValue N1 = N->getOperand(1); |
| 7118 | |
| 7119 | // (or (and B, A), (and C, ~A)) => (VBSL A, B, C) when A is a constant. |
| 7120 | if (Subtarget->hasNEON() && N1.getOpcode() == ISD::AND && VT.isVector() && |
| 7121 | DAG.getTargetLoweringInfo().isTypeLegal(VT)) { |
| 7122 | APInt SplatUndef; |
| 7123 | unsigned SplatBitSize; |
| 7124 | bool HasAnyUndefs; |
| 7125 | |
| 7126 | BuildVectorSDNode *BVN0 = dyn_cast<BuildVectorSDNode>(N0->getOperand(1)); |
| 7127 | APInt SplatBits0; |
| 7128 | if (BVN0 && BVN0->isConstantSplat(SplatBits0, SplatUndef, SplatBitSize, |
| 7129 | HasAnyUndefs) && !HasAnyUndefs) { |
| 7130 | BuildVectorSDNode *BVN1 = dyn_cast<BuildVectorSDNode>(N1->getOperand(1)); |
| 7131 | APInt SplatBits1; |
| 7132 | if (BVN1 && BVN1->isConstantSplat(SplatBits1, SplatUndef, SplatBitSize, |
| 7133 | HasAnyUndefs) && !HasAnyUndefs && |
| 7134 | SplatBits0 == ~SplatBits1) { |
| 7135 | // Canonicalize the vector type to make instruction selection simpler. |
| 7136 | EVT CanonicalVT = VT.is128BitVector() ? MVT::v4i32 : MVT::v2i32; |
| 7137 | SDValue Result = DAG.getNode(ARMISD::VBSL, dl, CanonicalVT, |
| 7138 | N0->getOperand(1), N0->getOperand(0), |
Cameron Zwarich | 5af60ce | 2011-04-13 21:01:19 +0000 | [diff] [blame] | 7139 | N1->getOperand(0)); |
Cameron Zwarich | c0e6d78 | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 7140 | return DAG.getNode(ISD::BITCAST, dl, VT, Result); |
| 7141 | } |
| 7142 | } |
| 7143 | } |
| 7144 | |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7145 | // Try to use the ARM/Thumb2 BFI (bitfield insert) instruction when |
| 7146 | // reasonable. |
| 7147 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 7148 | // BFI is only available on V6T2+ |
| 7149 | if (Subtarget->isThumb1Only() || !Subtarget->hasV6T2Ops()) |
| 7150 | return SDValue(); |
| 7151 | |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7152 | DebugLoc DL = N->getDebugLoc(); |
| 7153 | // 1) or (and A, mask), val => ARMbfi A, val, mask |
| 7154 | // iff (val & mask) == val |
| 7155 | // |
| 7156 | // 2) or (and A, mask), (and B, mask2) => ARMbfi A, (lsr B, amt), mask |
| 7157 | // 2a) iff isBitFieldInvertedMask(mask) && isBitFieldInvertedMask(~mask2) |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 7158 | // && mask == ~mask2 |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7159 | // 2b) iff isBitFieldInvertedMask(~mask) && isBitFieldInvertedMask(mask2) |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 7160 | // && ~mask == mask2 |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7161 | // (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] | 7162 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 7163 | if (VT != MVT::i32) |
| 7164 | return SDValue(); |
| 7165 | |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7166 | SDValue N00 = N0.getOperand(0); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7167 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 7168 | // The value and the mask need to be constants so we can verify this is |
| 7169 | // actually a bitfield set. If the mask is 0xffff, we can do better |
| 7170 | // via a movt instruction, so don't use BFI in that case. |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7171 | SDValue MaskOp = N0.getOperand(1); |
| 7172 | ConstantSDNode *MaskC = dyn_cast<ConstantSDNode>(MaskOp); |
| 7173 | if (!MaskC) |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 7174 | return SDValue(); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7175 | unsigned Mask = MaskC->getZExtValue(); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 7176 | if (Mask == 0xffff) |
| 7177 | return SDValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7178 | SDValue Res; |
| 7179 | // Case (1): or (and A, mask), val => ARMbfi A, val, mask |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7180 | ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1); |
| 7181 | if (N1C) { |
| 7182 | unsigned Val = N1C->getZExtValue(); |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 7183 | if ((Val & ~Mask) != Val) |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7184 | return SDValue(); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 7185 | |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 7186 | if (ARM::isBitFieldInvertedMask(Mask)) { |
| 7187 | Val >>= CountTrailingZeros_32(~Mask); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 7188 | |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7189 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N00, |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 7190 | DAG.getConstant(Val, MVT::i32), |
| 7191 | DAG.getConstant(Mask, MVT::i32)); |
| 7192 | |
| 7193 | // Do not add new nodes to DAG combiner worklist. |
| 7194 | DCI.CombineTo(N, Res, false); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7195 | return SDValue(); |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 7196 | } |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7197 | } else if (N1.getOpcode() == ISD::AND) { |
| 7198 | // 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] | 7199 | ConstantSDNode *N11C = dyn_cast<ConstantSDNode>(N1.getOperand(1)); |
| 7200 | if (!N11C) |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7201 | return SDValue(); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7202 | unsigned Mask2 = N11C->getZExtValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7203 | |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 7204 | // Mask and ~Mask2 (or reverse) must be equivalent for the BFI pattern |
| 7205 | // as is to match. |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7206 | if (ARM::isBitFieldInvertedMask(Mask) && |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 7207 | (Mask == ~Mask2)) { |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7208 | // The pack halfword instruction works better for masks that fit it, |
| 7209 | // so use that when it's available. |
| 7210 | if (Subtarget->hasT2ExtractPack() && |
| 7211 | (Mask == 0xffff || Mask == 0xffff0000)) |
| 7212 | return SDValue(); |
| 7213 | // 2a |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 7214 | unsigned amt = CountTrailingZeros_32(Mask2); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7215 | Res = DAG.getNode(ISD::SRL, DL, VT, N1.getOperand(0), |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 7216 | DAG.getConstant(amt, MVT::i32)); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7217 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N00, Res, |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7218 | DAG.getConstant(Mask, MVT::i32)); |
| 7219 | // Do not add new nodes to DAG combiner worklist. |
| 7220 | DCI.CombineTo(N, Res, false); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7221 | return SDValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7222 | } else if (ARM::isBitFieldInvertedMask(~Mask) && |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 7223 | (~Mask == Mask2)) { |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7224 | // The pack halfword instruction works better for masks that fit it, |
| 7225 | // so use that when it's available. |
| 7226 | if (Subtarget->hasT2ExtractPack() && |
| 7227 | (Mask2 == 0xffff || Mask2 == 0xffff0000)) |
| 7228 | return SDValue(); |
| 7229 | // 2b |
| 7230 | unsigned lsb = CountTrailingZeros_32(Mask); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7231 | Res = DAG.getNode(ISD::SRL, DL, VT, N00, |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7232 | DAG.getConstant(lsb, MVT::i32)); |
| 7233 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N1.getOperand(0), Res, |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 7234 | DAG.getConstant(Mask2, MVT::i32)); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7235 | // Do not add new nodes to DAG combiner worklist. |
| 7236 | DCI.CombineTo(N, Res, false); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7237 | return SDValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7238 | } |
| 7239 | } |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7240 | |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7241 | if (DAG.MaskedValueIsZero(N1, MaskC->getAPIntValue()) && |
| 7242 | N00.getOpcode() == ISD::SHL && isa<ConstantSDNode>(N00.getOperand(1)) && |
| 7243 | ARM::isBitFieldInvertedMask(~Mask)) { |
| 7244 | // Case (3): or (and (shl A, #shamt), mask), B => ARMbfi B, A, ~mask |
| 7245 | // where lsb(mask) == #shamt and masked bits of B are known zero. |
| 7246 | SDValue ShAmt = N00.getOperand(1); |
| 7247 | unsigned ShAmtC = cast<ConstantSDNode>(ShAmt)->getZExtValue(); |
| 7248 | unsigned LSB = CountTrailingZeros_32(Mask); |
| 7249 | if (ShAmtC != LSB) |
| 7250 | return SDValue(); |
| 7251 | |
| 7252 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N1, N00.getOperand(0), |
| 7253 | DAG.getConstant(~Mask, MVT::i32)); |
| 7254 | |
| 7255 | // Do not add new nodes to DAG combiner worklist. |
| 7256 | DCI.CombineTo(N, Res, false); |
| 7257 | } |
| 7258 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 7259 | return SDValue(); |
| 7260 | } |
| 7261 | |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 7262 | static SDValue PerformXORCombine(SDNode *N, |
| 7263 | TargetLowering::DAGCombinerInfo &DCI, |
| 7264 | const ARMSubtarget *Subtarget) { |
| 7265 | EVT VT = N->getValueType(0); |
| 7266 | SelectionDAG &DAG = DCI.DAG; |
| 7267 | |
| 7268 | if(!DAG.getTargetLoweringInfo().isTypeLegal(VT)) |
| 7269 | return SDValue(); |
| 7270 | |
| 7271 | if (!Subtarget->isThumb1Only()) { |
| 7272 | // (xor x, (cmov 0, y, cond)) => (xor.cond x, y) |
| 7273 | SDValue CXOR = formConditionalOp(N, DAG, true); |
| 7274 | if (CXOR.getNode()) |
| 7275 | return CXOR; |
| 7276 | } |
| 7277 | |
| 7278 | return SDValue(); |
| 7279 | } |
| 7280 | |
Evan Cheng | bf188ae | 2011-06-15 01:12:31 +0000 | [diff] [blame] | 7281 | /// PerformBFICombine - (bfi A, (and B, Mask1), Mask2) -> (bfi A, B, Mask2) iff |
| 7282 | /// 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] | 7283 | static SDValue PerformBFICombine(SDNode *N, |
| 7284 | TargetLowering::DAGCombinerInfo &DCI) { |
| 7285 | SDValue N1 = N->getOperand(1); |
| 7286 | if (N1.getOpcode() == ISD::AND) { |
| 7287 | ConstantSDNode *N11C = dyn_cast<ConstantSDNode>(N1.getOperand(1)); |
| 7288 | if (!N11C) |
| 7289 | return SDValue(); |
Evan Cheng | bf188ae | 2011-06-15 01:12:31 +0000 | [diff] [blame] | 7290 | unsigned InvMask = cast<ConstantSDNode>(N->getOperand(2))->getZExtValue(); |
| 7291 | unsigned LSB = CountTrailingZeros_32(~InvMask); |
| 7292 | unsigned Width = (32 - CountLeadingZeros_32(~InvMask)) - LSB; |
| 7293 | unsigned Mask = (1 << Width)-1; |
Evan Cheng | 0c1aec1 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 7294 | unsigned Mask2 = N11C->getZExtValue(); |
Evan Cheng | bf188ae | 2011-06-15 01:12:31 +0000 | [diff] [blame] | 7295 | if ((Mask & (~Mask2)) == 0) |
Evan Cheng | 0c1aec1 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 7296 | return DCI.DAG.getNode(ARMISD::BFI, N->getDebugLoc(), N->getValueType(0), |
| 7297 | N->getOperand(0), N1.getOperand(0), |
| 7298 | N->getOperand(2)); |
| 7299 | } |
| 7300 | return SDValue(); |
| 7301 | } |
| 7302 | |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 7303 | /// PerformVMOVRRDCombine - Target-specific dag combine xforms for |
| 7304 | /// ARMISD::VMOVRRD. |
| 7305 | static SDValue PerformVMOVRRDCombine(SDNode *N, |
| 7306 | TargetLowering::DAGCombinerInfo &DCI) { |
| 7307 | // vmovrrd(vmovdrr x, y) -> x,y |
| 7308 | SDValue InDouble = N->getOperand(0); |
| 7309 | if (InDouble.getOpcode() == ARMISD::VMOVDRR) |
| 7310 | return DCI.CombineTo(N, InDouble.getOperand(0), InDouble.getOperand(1)); |
Cameron Zwarich | 4071a71 | 2011-04-02 02:40:43 +0000 | [diff] [blame] | 7311 | |
| 7312 | // vmovrrd(load f64) -> (load i32), (load i32) |
| 7313 | SDNode *InNode = InDouble.getNode(); |
| 7314 | if (ISD::isNormalLoad(InNode) && InNode->hasOneUse() && |
| 7315 | InNode->getValueType(0) == MVT::f64 && |
| 7316 | InNode->getOperand(1).getOpcode() == ISD::FrameIndex && |
| 7317 | !cast<LoadSDNode>(InNode)->isVolatile()) { |
| 7318 | // TODO: Should this be done for non-FrameIndex operands? |
| 7319 | LoadSDNode *LD = cast<LoadSDNode>(InNode); |
| 7320 | |
| 7321 | SelectionDAG &DAG = DCI.DAG; |
| 7322 | DebugLoc DL = LD->getDebugLoc(); |
| 7323 | SDValue BasePtr = LD->getBasePtr(); |
| 7324 | SDValue NewLD1 = DAG.getLoad(MVT::i32, DL, LD->getChain(), BasePtr, |
| 7325 | LD->getPointerInfo(), LD->isVolatile(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 7326 | LD->isNonTemporal(), LD->isInvariant(), |
| 7327 | LD->getAlignment()); |
Cameron Zwarich | 4071a71 | 2011-04-02 02:40:43 +0000 | [diff] [blame] | 7328 | |
| 7329 | SDValue OffsetPtr = DAG.getNode(ISD::ADD, DL, MVT::i32, BasePtr, |
| 7330 | DAG.getConstant(4, MVT::i32)); |
| 7331 | SDValue NewLD2 = DAG.getLoad(MVT::i32, DL, NewLD1.getValue(1), OffsetPtr, |
| 7332 | LD->getPointerInfo(), LD->isVolatile(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 7333 | LD->isNonTemporal(), LD->isInvariant(), |
Cameron Zwarich | 4071a71 | 2011-04-02 02:40:43 +0000 | [diff] [blame] | 7334 | std::min(4U, LD->getAlignment() / 2)); |
| 7335 | |
| 7336 | DAG.ReplaceAllUsesOfValueWith(SDValue(LD, 1), NewLD2.getValue(1)); |
| 7337 | SDValue Result = DCI.CombineTo(N, NewLD1, NewLD2); |
| 7338 | DCI.RemoveFromWorklist(LD); |
| 7339 | DAG.DeleteNode(LD); |
| 7340 | return Result; |
| 7341 | } |
| 7342 | |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 7343 | return SDValue(); |
| 7344 | } |
| 7345 | |
| 7346 | /// PerformVMOVDRRCombine - Target-specific dag combine xforms for |
| 7347 | /// ARMISD::VMOVDRR. This is also used for BUILD_VECTORs with 2 operands. |
| 7348 | static SDValue PerformVMOVDRRCombine(SDNode *N, SelectionDAG &DAG) { |
| 7349 | // N=vmovrrd(X); vmovdrr(N:0, N:1) -> bit_convert(X) |
| 7350 | SDValue Op0 = N->getOperand(0); |
| 7351 | SDValue Op1 = N->getOperand(1); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7352 | if (Op0.getOpcode() == ISD::BITCAST) |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 7353 | Op0 = Op0.getOperand(0); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7354 | if (Op1.getOpcode() == ISD::BITCAST) |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 7355 | Op1 = Op1.getOperand(0); |
| 7356 | if (Op0.getOpcode() == ARMISD::VMOVRRD && |
| 7357 | Op0.getNode() == Op1.getNode() && |
| 7358 | Op0.getResNo() == 0 && Op1.getResNo() == 1) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7359 | return DAG.getNode(ISD::BITCAST, N->getDebugLoc(), |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 7360 | N->getValueType(0), Op0.getOperand(0)); |
| 7361 | return SDValue(); |
| 7362 | } |
| 7363 | |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 7364 | /// PerformSTORECombine - Target-specific dag combine xforms for |
| 7365 | /// ISD::STORE. |
| 7366 | static SDValue PerformSTORECombine(SDNode *N, |
| 7367 | TargetLowering::DAGCombinerInfo &DCI) { |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 7368 | StoreSDNode *St = cast<StoreSDNode>(N); |
Chad Rosier | 7f35455 | 2012-04-09 20:32:02 +0000 | [diff] [blame] | 7369 | if (St->isVolatile()) |
| 7370 | return SDValue(); |
| 7371 | |
| 7372 | // Optimize trunc store (of multiple scalars) to shuffle and store. First, |
| 7373 | // pack all of the elements in one place. Next, store to memory in fewer |
| 7374 | // chunks. |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 7375 | SDValue StVal = St->getValue(); |
Chad Rosier | 7f35455 | 2012-04-09 20:32:02 +0000 | [diff] [blame] | 7376 | EVT VT = StVal.getValueType(); |
| 7377 | if (St->isTruncatingStore() && VT.isVector()) { |
| 7378 | SelectionDAG &DAG = DCI.DAG; |
| 7379 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 7380 | EVT StVT = St->getMemoryVT(); |
| 7381 | unsigned NumElems = VT.getVectorNumElements(); |
| 7382 | assert(StVT != VT && "Cannot truncate to the same type"); |
| 7383 | unsigned FromEltSz = VT.getVectorElementType().getSizeInBits(); |
| 7384 | unsigned ToEltSz = StVT.getVectorElementType().getSizeInBits(); |
| 7385 | |
| 7386 | // From, To sizes and ElemCount must be pow of two |
| 7387 | if (!isPowerOf2_32(NumElems * FromEltSz * ToEltSz)) return SDValue(); |
| 7388 | |
| 7389 | // We are going to use the original vector elt for storing. |
| 7390 | // Accumulated smaller vector elements must be a multiple of the store size. |
| 7391 | if (0 != (NumElems * FromEltSz) % ToEltSz) return SDValue(); |
| 7392 | |
| 7393 | unsigned SizeRatio = FromEltSz / ToEltSz; |
| 7394 | assert(SizeRatio * NumElems * ToEltSz == VT.getSizeInBits()); |
| 7395 | |
| 7396 | // Create a type on which we perform the shuffle. |
| 7397 | EVT WideVecVT = EVT::getVectorVT(*DAG.getContext(), StVT.getScalarType(), |
| 7398 | NumElems*SizeRatio); |
| 7399 | assert(WideVecVT.getSizeInBits() == VT.getSizeInBits()); |
| 7400 | |
| 7401 | DebugLoc DL = St->getDebugLoc(); |
| 7402 | SDValue WideVec = DAG.getNode(ISD::BITCAST, DL, WideVecVT, StVal); |
| 7403 | SmallVector<int, 8> ShuffleVec(NumElems * SizeRatio, -1); |
| 7404 | for (unsigned i = 0; i < NumElems; ++i) ShuffleVec[i] = i * SizeRatio; |
| 7405 | |
| 7406 | // Can't shuffle using an illegal type. |
| 7407 | if (!TLI.isTypeLegal(WideVecVT)) return SDValue(); |
| 7408 | |
| 7409 | SDValue Shuff = DAG.getVectorShuffle(WideVecVT, DL, WideVec, |
| 7410 | DAG.getUNDEF(WideVec.getValueType()), |
| 7411 | ShuffleVec.data()); |
| 7412 | // At this point all of the data is stored at the bottom of the |
| 7413 | // register. We now need to save it to mem. |
| 7414 | |
| 7415 | // Find the largest store unit |
| 7416 | MVT StoreType = MVT::i8; |
| 7417 | for (unsigned tp = MVT::FIRST_INTEGER_VALUETYPE; |
| 7418 | tp < MVT::LAST_INTEGER_VALUETYPE; ++tp) { |
| 7419 | MVT Tp = (MVT::SimpleValueType)tp; |
| 7420 | if (TLI.isTypeLegal(Tp) && Tp.getSizeInBits() <= NumElems * ToEltSz) |
| 7421 | StoreType = Tp; |
| 7422 | } |
| 7423 | // Didn't find a legal store type. |
| 7424 | if (!TLI.isTypeLegal(StoreType)) |
| 7425 | return SDValue(); |
| 7426 | |
| 7427 | // Bitcast the original vector into a vector of store-size units |
| 7428 | EVT StoreVecVT = EVT::getVectorVT(*DAG.getContext(), |
| 7429 | StoreType, VT.getSizeInBits()/EVT(StoreType).getSizeInBits()); |
| 7430 | assert(StoreVecVT.getSizeInBits() == VT.getSizeInBits()); |
| 7431 | SDValue ShuffWide = DAG.getNode(ISD::BITCAST, DL, StoreVecVT, Shuff); |
| 7432 | SmallVector<SDValue, 8> Chains; |
| 7433 | SDValue Increment = DAG.getConstant(StoreType.getSizeInBits()/8, |
| 7434 | TLI.getPointerTy()); |
| 7435 | SDValue BasePtr = St->getBasePtr(); |
| 7436 | |
| 7437 | // Perform one or more big stores into memory. |
| 7438 | unsigned E = (ToEltSz*NumElems)/StoreType.getSizeInBits(); |
| 7439 | for (unsigned I = 0; I < E; I++) { |
| 7440 | SDValue SubVec = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, |
| 7441 | StoreType, ShuffWide, |
| 7442 | DAG.getIntPtrConstant(I)); |
| 7443 | SDValue Ch = DAG.getStore(St->getChain(), DL, SubVec, BasePtr, |
| 7444 | St->getPointerInfo(), St->isVolatile(), |
| 7445 | St->isNonTemporal(), St->getAlignment()); |
| 7446 | BasePtr = DAG.getNode(ISD::ADD, DL, BasePtr.getValueType(), BasePtr, |
| 7447 | Increment); |
| 7448 | Chains.push_back(Ch); |
| 7449 | } |
| 7450 | return DAG.getNode(ISD::TokenFactor, DL, MVT::Other, &Chains[0], |
| 7451 | Chains.size()); |
| 7452 | } |
| 7453 | |
| 7454 | if (!ISD::isNormalStore(St)) |
Cameron Zwarich | d0aacbc | 2011-04-12 02:24:17 +0000 | [diff] [blame] | 7455 | return SDValue(); |
| 7456 | |
Chad Rosier | 96b66d6 | 2012-04-09 19:38:15 +0000 | [diff] [blame] | 7457 | // Split a store of a VMOVDRR into two integer stores to avoid mixing NEON and |
| 7458 | // ARM stores of arguments in the same cache line. |
Cameron Zwarich | d0aacbc | 2011-04-12 02:24:17 +0000 | [diff] [blame] | 7459 | if (StVal.getNode()->getOpcode() == ARMISD::VMOVDRR && |
Chad Rosier | 96b66d6 | 2012-04-09 19:38:15 +0000 | [diff] [blame] | 7460 | StVal.getNode()->hasOneUse()) { |
Cameron Zwarich | d0aacbc | 2011-04-12 02:24:17 +0000 | [diff] [blame] | 7461 | SelectionDAG &DAG = DCI.DAG; |
| 7462 | DebugLoc DL = St->getDebugLoc(); |
| 7463 | SDValue BasePtr = St->getBasePtr(); |
| 7464 | SDValue NewST1 = DAG.getStore(St->getChain(), DL, |
| 7465 | StVal.getNode()->getOperand(0), BasePtr, |
| 7466 | St->getPointerInfo(), St->isVolatile(), |
| 7467 | St->isNonTemporal(), St->getAlignment()); |
| 7468 | |
| 7469 | SDValue OffsetPtr = DAG.getNode(ISD::ADD, DL, MVT::i32, BasePtr, |
| 7470 | DAG.getConstant(4, MVT::i32)); |
| 7471 | return DAG.getStore(NewST1.getValue(0), DL, StVal.getNode()->getOperand(1), |
| 7472 | OffsetPtr, St->getPointerInfo(), St->isVolatile(), |
| 7473 | St->isNonTemporal(), |
| 7474 | std::min(4U, St->getAlignment() / 2)); |
| 7475 | } |
| 7476 | |
| 7477 | if (StVal.getValueType() != MVT::i64 || |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 7478 | StVal.getNode()->getOpcode() != ISD::EXTRACT_VECTOR_ELT) |
| 7479 | return SDValue(); |
| 7480 | |
Chad Rosier | 96b66d6 | 2012-04-09 19:38:15 +0000 | [diff] [blame] | 7481 | // Bitcast an i64 store extracted from a vector to f64. |
| 7482 | // Otherwise, the i64 value will be legalized to a pair of i32 values. |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 7483 | SelectionDAG &DAG = DCI.DAG; |
| 7484 | DebugLoc dl = StVal.getDebugLoc(); |
| 7485 | SDValue IntVec = StVal.getOperand(0); |
| 7486 | EVT FloatVT = EVT::getVectorVT(*DAG.getContext(), MVT::f64, |
| 7487 | IntVec.getValueType().getVectorNumElements()); |
| 7488 | SDValue Vec = DAG.getNode(ISD::BITCAST, dl, FloatVT, IntVec); |
| 7489 | SDValue ExtElt = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, |
| 7490 | Vec, StVal.getOperand(1)); |
| 7491 | dl = N->getDebugLoc(); |
| 7492 | SDValue V = DAG.getNode(ISD::BITCAST, dl, MVT::i64, ExtElt); |
| 7493 | // Make the DAGCombiner fold the bitcasts. |
| 7494 | DCI.AddToWorklist(Vec.getNode()); |
| 7495 | DCI.AddToWorklist(ExtElt.getNode()); |
| 7496 | DCI.AddToWorklist(V.getNode()); |
| 7497 | return DAG.getStore(St->getChain(), dl, V, St->getBasePtr(), |
| 7498 | St->getPointerInfo(), St->isVolatile(), |
| 7499 | St->isNonTemporal(), St->getAlignment(), |
| 7500 | St->getTBAAInfo()); |
| 7501 | } |
| 7502 | |
| 7503 | /// hasNormalLoadOperand - Check if any of the operands of a BUILD_VECTOR node |
| 7504 | /// are normal, non-volatile loads. If so, it is profitable to bitcast an |
| 7505 | /// i64 vector to have f64 elements, since the value can then be loaded |
| 7506 | /// directly into a VFP register. |
| 7507 | static bool hasNormalLoadOperand(SDNode *N) { |
| 7508 | unsigned NumElts = N->getValueType(0).getVectorNumElements(); |
| 7509 | for (unsigned i = 0; i < NumElts; ++i) { |
| 7510 | SDNode *Elt = N->getOperand(i).getNode(); |
| 7511 | if (ISD::isNormalLoad(Elt) && !cast<LoadSDNode>(Elt)->isVolatile()) |
| 7512 | return true; |
| 7513 | } |
| 7514 | return false; |
| 7515 | } |
| 7516 | |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 7517 | /// PerformBUILD_VECTORCombine - Target-specific dag combine xforms for |
| 7518 | /// ISD::BUILD_VECTOR. |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 7519 | static SDValue PerformBUILD_VECTORCombine(SDNode *N, |
| 7520 | TargetLowering::DAGCombinerInfo &DCI){ |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 7521 | // build_vector(N=ARMISD::VMOVRRD(X), N:1) -> bit_convert(X): |
| 7522 | // VMOVRRD is introduced when legalizing i64 types. It forces the i64 value |
| 7523 | // into a pair of GPRs, which is fine when the value is used as a scalar, |
| 7524 | // 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] | 7525 | SelectionDAG &DAG = DCI.DAG; |
| 7526 | if (N->getNumOperands() == 2) { |
| 7527 | SDValue RV = PerformVMOVDRRCombine(N, DAG); |
| 7528 | if (RV.getNode()) |
| 7529 | return RV; |
| 7530 | } |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 7531 | |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 7532 | // Load i64 elements as f64 values so that type legalization does not split |
| 7533 | // them up into i32 values. |
| 7534 | EVT VT = N->getValueType(0); |
| 7535 | if (VT.getVectorElementType() != MVT::i64 || !hasNormalLoadOperand(N)) |
| 7536 | return SDValue(); |
| 7537 | DebugLoc dl = N->getDebugLoc(); |
| 7538 | SmallVector<SDValue, 8> Ops; |
| 7539 | unsigned NumElts = VT.getVectorNumElements(); |
| 7540 | for (unsigned i = 0; i < NumElts; ++i) { |
| 7541 | SDValue V = DAG.getNode(ISD::BITCAST, dl, MVT::f64, N->getOperand(i)); |
| 7542 | Ops.push_back(V); |
| 7543 | // Make the DAGCombiner fold the bitcast. |
| 7544 | DCI.AddToWorklist(V.getNode()); |
| 7545 | } |
| 7546 | EVT FloatVT = EVT::getVectorVT(*DAG.getContext(), MVT::f64, NumElts); |
| 7547 | SDValue BV = DAG.getNode(ISD::BUILD_VECTOR, dl, FloatVT, Ops.data(), NumElts); |
| 7548 | return DAG.getNode(ISD::BITCAST, dl, VT, BV); |
| 7549 | } |
| 7550 | |
| 7551 | /// PerformInsertEltCombine - Target-specific dag combine xforms for |
| 7552 | /// ISD::INSERT_VECTOR_ELT. |
| 7553 | static SDValue PerformInsertEltCombine(SDNode *N, |
| 7554 | TargetLowering::DAGCombinerInfo &DCI) { |
| 7555 | // Bitcast an i64 load inserted into a vector to f64. |
| 7556 | // Otherwise, the i64 value will be legalized to a pair of i32 values. |
| 7557 | EVT VT = N->getValueType(0); |
| 7558 | SDNode *Elt = N->getOperand(1).getNode(); |
| 7559 | if (VT.getVectorElementType() != MVT::i64 || |
| 7560 | !ISD::isNormalLoad(Elt) || cast<LoadSDNode>(Elt)->isVolatile()) |
| 7561 | return SDValue(); |
| 7562 | |
| 7563 | SelectionDAG &DAG = DCI.DAG; |
| 7564 | DebugLoc dl = N->getDebugLoc(); |
| 7565 | EVT FloatVT = EVT::getVectorVT(*DAG.getContext(), MVT::f64, |
| 7566 | VT.getVectorNumElements()); |
| 7567 | SDValue Vec = DAG.getNode(ISD::BITCAST, dl, FloatVT, N->getOperand(0)); |
| 7568 | SDValue V = DAG.getNode(ISD::BITCAST, dl, MVT::f64, N->getOperand(1)); |
| 7569 | // Make the DAGCombiner fold the bitcasts. |
| 7570 | DCI.AddToWorklist(Vec.getNode()); |
| 7571 | DCI.AddToWorklist(V.getNode()); |
| 7572 | SDValue InsElt = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, FloatVT, |
| 7573 | Vec, V, N->getOperand(2)); |
| 7574 | return DAG.getNode(ISD::BITCAST, dl, VT, InsElt); |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 7575 | } |
| 7576 | |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 7577 | /// PerformVECTOR_SHUFFLECombine - Target-specific dag combine xforms for |
| 7578 | /// ISD::VECTOR_SHUFFLE. |
| 7579 | static SDValue PerformVECTOR_SHUFFLECombine(SDNode *N, SelectionDAG &DAG) { |
| 7580 | // The LLVM shufflevector instruction does not require the shuffle mask |
| 7581 | // length to match the operand vector length, but ISD::VECTOR_SHUFFLE does |
| 7582 | // have that requirement. When translating to ISD::VECTOR_SHUFFLE, if the |
| 7583 | // operands do not match the mask length, they are extended by concatenating |
| 7584 | // them with undef vectors. That is probably the right thing for other |
| 7585 | // targets, but for NEON it is better to concatenate two double-register |
| 7586 | // size vector operands into a single quad-register size vector. Do that |
| 7587 | // transformation here: |
| 7588 | // shuffle(concat(v1, undef), concat(v2, undef)) -> |
| 7589 | // shuffle(concat(v1, v2), undef) |
| 7590 | SDValue Op0 = N->getOperand(0); |
| 7591 | SDValue Op1 = N->getOperand(1); |
| 7592 | if (Op0.getOpcode() != ISD::CONCAT_VECTORS || |
| 7593 | Op1.getOpcode() != ISD::CONCAT_VECTORS || |
| 7594 | Op0.getNumOperands() != 2 || |
| 7595 | Op1.getNumOperands() != 2) |
| 7596 | return SDValue(); |
| 7597 | SDValue Concat0Op1 = Op0.getOperand(1); |
| 7598 | SDValue Concat1Op1 = Op1.getOperand(1); |
| 7599 | if (Concat0Op1.getOpcode() != ISD::UNDEF || |
| 7600 | Concat1Op1.getOpcode() != ISD::UNDEF) |
| 7601 | return SDValue(); |
| 7602 | // Skip the transformation if any of the types are illegal. |
| 7603 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 7604 | EVT VT = N->getValueType(0); |
| 7605 | if (!TLI.isTypeLegal(VT) || |
| 7606 | !TLI.isTypeLegal(Concat0Op1.getValueType()) || |
| 7607 | !TLI.isTypeLegal(Concat1Op1.getValueType())) |
| 7608 | return SDValue(); |
| 7609 | |
| 7610 | SDValue NewConcat = DAG.getNode(ISD::CONCAT_VECTORS, N->getDebugLoc(), VT, |
| 7611 | Op0.getOperand(0), Op1.getOperand(0)); |
| 7612 | // Translate the shuffle mask. |
| 7613 | SmallVector<int, 16> NewMask; |
| 7614 | unsigned NumElts = VT.getVectorNumElements(); |
| 7615 | unsigned HalfElts = NumElts/2; |
| 7616 | ShuffleVectorSDNode *SVN = cast<ShuffleVectorSDNode>(N); |
| 7617 | for (unsigned n = 0; n < NumElts; ++n) { |
| 7618 | int MaskElt = SVN->getMaskElt(n); |
| 7619 | int NewElt = -1; |
Bob Wilson | 1fa9d30 | 2010-10-27 23:49:00 +0000 | [diff] [blame] | 7620 | if (MaskElt < (int)HalfElts) |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 7621 | NewElt = MaskElt; |
Bob Wilson | 1fa9d30 | 2010-10-27 23:49:00 +0000 | [diff] [blame] | 7622 | else if (MaskElt >= (int)NumElts && MaskElt < (int)(NumElts + HalfElts)) |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 7623 | NewElt = HalfElts + MaskElt - NumElts; |
| 7624 | NewMask.push_back(NewElt); |
| 7625 | } |
| 7626 | return DAG.getVectorShuffle(VT, N->getDebugLoc(), NewConcat, |
| 7627 | DAG.getUNDEF(VT), NewMask.data()); |
| 7628 | } |
| 7629 | |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 7630 | /// CombineBaseUpdate - Target-specific DAG combine function for VLDDUP and |
| 7631 | /// NEON load/store intrinsics to merge base address updates. |
| 7632 | static SDValue CombineBaseUpdate(SDNode *N, |
| 7633 | TargetLowering::DAGCombinerInfo &DCI) { |
| 7634 | if (DCI.isBeforeLegalize() || DCI.isCalledByLegalizer()) |
| 7635 | return SDValue(); |
| 7636 | |
| 7637 | SelectionDAG &DAG = DCI.DAG; |
| 7638 | bool isIntrinsic = (N->getOpcode() == ISD::INTRINSIC_VOID || |
| 7639 | N->getOpcode() == ISD::INTRINSIC_W_CHAIN); |
| 7640 | unsigned AddrOpIdx = (isIntrinsic ? 2 : 1); |
| 7641 | SDValue Addr = N->getOperand(AddrOpIdx); |
| 7642 | |
| 7643 | // Search for a use of the address operand that is an increment. |
| 7644 | for (SDNode::use_iterator UI = Addr.getNode()->use_begin(), |
| 7645 | UE = Addr.getNode()->use_end(); UI != UE; ++UI) { |
| 7646 | SDNode *User = *UI; |
| 7647 | if (User->getOpcode() != ISD::ADD || |
| 7648 | UI.getUse().getResNo() != Addr.getResNo()) |
| 7649 | continue; |
| 7650 | |
| 7651 | // Check that the add is independent of the load/store. Otherwise, folding |
| 7652 | // it would create a cycle. |
| 7653 | if (User->isPredecessorOf(N) || N->isPredecessorOf(User)) |
| 7654 | continue; |
| 7655 | |
| 7656 | // Find the new opcode for the updating load/store. |
| 7657 | bool isLoad = true; |
| 7658 | bool isLaneOp = false; |
| 7659 | unsigned NewOpc = 0; |
| 7660 | unsigned NumVecs = 0; |
| 7661 | if (isIntrinsic) { |
| 7662 | unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue(); |
| 7663 | switch (IntNo) { |
Craig Topper | bc21981 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 7664 | default: llvm_unreachable("unexpected intrinsic for Neon base update"); |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 7665 | case Intrinsic::arm_neon_vld1: NewOpc = ARMISD::VLD1_UPD; |
| 7666 | NumVecs = 1; break; |
| 7667 | case Intrinsic::arm_neon_vld2: NewOpc = ARMISD::VLD2_UPD; |
| 7668 | NumVecs = 2; break; |
| 7669 | case Intrinsic::arm_neon_vld3: NewOpc = ARMISD::VLD3_UPD; |
| 7670 | NumVecs = 3; break; |
| 7671 | case Intrinsic::arm_neon_vld4: NewOpc = ARMISD::VLD4_UPD; |
| 7672 | NumVecs = 4; break; |
| 7673 | case Intrinsic::arm_neon_vld2lane: NewOpc = ARMISD::VLD2LN_UPD; |
| 7674 | NumVecs = 2; isLaneOp = true; break; |
| 7675 | case Intrinsic::arm_neon_vld3lane: NewOpc = ARMISD::VLD3LN_UPD; |
| 7676 | NumVecs = 3; isLaneOp = true; break; |
| 7677 | case Intrinsic::arm_neon_vld4lane: NewOpc = ARMISD::VLD4LN_UPD; |
| 7678 | NumVecs = 4; isLaneOp = true; break; |
| 7679 | case Intrinsic::arm_neon_vst1: NewOpc = ARMISD::VST1_UPD; |
| 7680 | NumVecs = 1; isLoad = false; break; |
| 7681 | case Intrinsic::arm_neon_vst2: NewOpc = ARMISD::VST2_UPD; |
| 7682 | NumVecs = 2; isLoad = false; break; |
| 7683 | case Intrinsic::arm_neon_vst3: NewOpc = ARMISD::VST3_UPD; |
| 7684 | NumVecs = 3; isLoad = false; break; |
| 7685 | case Intrinsic::arm_neon_vst4: NewOpc = ARMISD::VST4_UPD; |
| 7686 | NumVecs = 4; isLoad = false; break; |
| 7687 | case Intrinsic::arm_neon_vst2lane: NewOpc = ARMISD::VST2LN_UPD; |
| 7688 | NumVecs = 2; isLoad = false; isLaneOp = true; break; |
| 7689 | case Intrinsic::arm_neon_vst3lane: NewOpc = ARMISD::VST3LN_UPD; |
| 7690 | NumVecs = 3; isLoad = false; isLaneOp = true; break; |
| 7691 | case Intrinsic::arm_neon_vst4lane: NewOpc = ARMISD::VST4LN_UPD; |
| 7692 | NumVecs = 4; isLoad = false; isLaneOp = true; break; |
| 7693 | } |
| 7694 | } else { |
| 7695 | isLaneOp = true; |
| 7696 | switch (N->getOpcode()) { |
Craig Topper | bc21981 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 7697 | default: llvm_unreachable("unexpected opcode for Neon base update"); |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 7698 | case ARMISD::VLD2DUP: NewOpc = ARMISD::VLD2DUP_UPD; NumVecs = 2; break; |
| 7699 | case ARMISD::VLD3DUP: NewOpc = ARMISD::VLD3DUP_UPD; NumVecs = 3; break; |
| 7700 | case ARMISD::VLD4DUP: NewOpc = ARMISD::VLD4DUP_UPD; NumVecs = 4; break; |
| 7701 | } |
| 7702 | } |
| 7703 | |
| 7704 | // Find the size of memory referenced by the load/store. |
| 7705 | EVT VecTy; |
| 7706 | if (isLoad) |
| 7707 | VecTy = N->getValueType(0); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 7708 | else |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 7709 | VecTy = N->getOperand(AddrOpIdx+1).getValueType(); |
| 7710 | unsigned NumBytes = NumVecs * VecTy.getSizeInBits() / 8; |
| 7711 | if (isLaneOp) |
| 7712 | NumBytes /= VecTy.getVectorNumElements(); |
| 7713 | |
| 7714 | // If the increment is a constant, it must match the memory ref size. |
| 7715 | SDValue Inc = User->getOperand(User->getOperand(0) == Addr ? 1 : 0); |
| 7716 | if (ConstantSDNode *CInc = dyn_cast<ConstantSDNode>(Inc.getNode())) { |
| 7717 | uint64_t IncVal = CInc->getZExtValue(); |
| 7718 | if (IncVal != NumBytes) |
| 7719 | continue; |
| 7720 | } else if (NumBytes >= 3 * 16) { |
| 7721 | // VLD3/4 and VST3/4 for 128-bit vectors are implemented with two |
| 7722 | // separate instructions that make it harder to use a non-constant update. |
| 7723 | continue; |
| 7724 | } |
| 7725 | |
| 7726 | // Create the new updating load/store node. |
| 7727 | EVT Tys[6]; |
| 7728 | unsigned NumResultVecs = (isLoad ? NumVecs : 0); |
| 7729 | unsigned n; |
| 7730 | for (n = 0; n < NumResultVecs; ++n) |
| 7731 | Tys[n] = VecTy; |
| 7732 | Tys[n++] = MVT::i32; |
| 7733 | Tys[n] = MVT::Other; |
| 7734 | SDVTList SDTys = DAG.getVTList(Tys, NumResultVecs+2); |
| 7735 | SmallVector<SDValue, 8> Ops; |
| 7736 | Ops.push_back(N->getOperand(0)); // incoming chain |
| 7737 | Ops.push_back(N->getOperand(AddrOpIdx)); |
| 7738 | Ops.push_back(Inc); |
| 7739 | for (unsigned i = AddrOpIdx + 1; i < N->getNumOperands(); ++i) { |
| 7740 | Ops.push_back(N->getOperand(i)); |
| 7741 | } |
| 7742 | MemIntrinsicSDNode *MemInt = cast<MemIntrinsicSDNode>(N); |
| 7743 | SDValue UpdN = DAG.getMemIntrinsicNode(NewOpc, N->getDebugLoc(), SDTys, |
| 7744 | Ops.data(), Ops.size(), |
| 7745 | MemInt->getMemoryVT(), |
| 7746 | MemInt->getMemOperand()); |
| 7747 | |
| 7748 | // Update the uses. |
| 7749 | std::vector<SDValue> NewResults; |
| 7750 | for (unsigned i = 0; i < NumResultVecs; ++i) { |
| 7751 | NewResults.push_back(SDValue(UpdN.getNode(), i)); |
| 7752 | } |
| 7753 | NewResults.push_back(SDValue(UpdN.getNode(), NumResultVecs+1)); // chain |
| 7754 | DCI.CombineTo(N, NewResults); |
| 7755 | DCI.CombineTo(User, SDValue(UpdN.getNode(), NumResultVecs)); |
| 7756 | |
| 7757 | break; |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 7758 | } |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 7759 | return SDValue(); |
| 7760 | } |
| 7761 | |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 7762 | /// CombineVLDDUP - For a VDUPLANE node N, check if its source operand is a |
| 7763 | /// vldN-lane (N > 1) intrinsic, and if all the other uses of that intrinsic |
| 7764 | /// are also VDUPLANEs. If so, combine them to a vldN-dup operation and |
| 7765 | /// return true. |
| 7766 | static bool CombineVLDDUP(SDNode *N, TargetLowering::DAGCombinerInfo &DCI) { |
| 7767 | SelectionDAG &DAG = DCI.DAG; |
| 7768 | EVT VT = N->getValueType(0); |
| 7769 | // vldN-dup instructions only support 64-bit vectors for N > 1. |
| 7770 | if (!VT.is64BitVector()) |
| 7771 | return false; |
| 7772 | |
| 7773 | // Check if the VDUPLANE operand is a vldN-dup intrinsic. |
| 7774 | SDNode *VLD = N->getOperand(0).getNode(); |
| 7775 | if (VLD->getOpcode() != ISD::INTRINSIC_W_CHAIN) |
| 7776 | return false; |
| 7777 | unsigned NumVecs = 0; |
| 7778 | unsigned NewOpc = 0; |
| 7779 | unsigned IntNo = cast<ConstantSDNode>(VLD->getOperand(1))->getZExtValue(); |
| 7780 | if (IntNo == Intrinsic::arm_neon_vld2lane) { |
| 7781 | NumVecs = 2; |
| 7782 | NewOpc = ARMISD::VLD2DUP; |
| 7783 | } else if (IntNo == Intrinsic::arm_neon_vld3lane) { |
| 7784 | NumVecs = 3; |
| 7785 | NewOpc = ARMISD::VLD3DUP; |
| 7786 | } else if (IntNo == Intrinsic::arm_neon_vld4lane) { |
| 7787 | NumVecs = 4; |
| 7788 | NewOpc = ARMISD::VLD4DUP; |
| 7789 | } else { |
| 7790 | return false; |
| 7791 | } |
| 7792 | |
| 7793 | // First check that all the vldN-lane uses are VDUPLANEs and that the lane |
| 7794 | // numbers match the load. |
| 7795 | unsigned VLDLaneNo = |
| 7796 | cast<ConstantSDNode>(VLD->getOperand(NumVecs+3))->getZExtValue(); |
| 7797 | for (SDNode::use_iterator UI = VLD->use_begin(), UE = VLD->use_end(); |
| 7798 | UI != UE; ++UI) { |
| 7799 | // Ignore uses of the chain result. |
| 7800 | if (UI.getUse().getResNo() == NumVecs) |
| 7801 | continue; |
| 7802 | SDNode *User = *UI; |
| 7803 | if (User->getOpcode() != ARMISD::VDUPLANE || |
| 7804 | VLDLaneNo != cast<ConstantSDNode>(User->getOperand(1))->getZExtValue()) |
| 7805 | return false; |
| 7806 | } |
| 7807 | |
| 7808 | // Create the vldN-dup node. |
| 7809 | EVT Tys[5]; |
| 7810 | unsigned n; |
| 7811 | for (n = 0; n < NumVecs; ++n) |
| 7812 | Tys[n] = VT; |
| 7813 | Tys[n] = MVT::Other; |
| 7814 | SDVTList SDTys = DAG.getVTList(Tys, NumVecs+1); |
| 7815 | SDValue Ops[] = { VLD->getOperand(0), VLD->getOperand(2) }; |
| 7816 | MemIntrinsicSDNode *VLDMemInt = cast<MemIntrinsicSDNode>(VLD); |
| 7817 | SDValue VLDDup = DAG.getMemIntrinsicNode(NewOpc, VLD->getDebugLoc(), SDTys, |
| 7818 | Ops, 2, VLDMemInt->getMemoryVT(), |
| 7819 | VLDMemInt->getMemOperand()); |
| 7820 | |
| 7821 | // Update the uses. |
| 7822 | for (SDNode::use_iterator UI = VLD->use_begin(), UE = VLD->use_end(); |
| 7823 | UI != UE; ++UI) { |
| 7824 | unsigned ResNo = UI.getUse().getResNo(); |
| 7825 | // Ignore uses of the chain result. |
| 7826 | if (ResNo == NumVecs) |
| 7827 | continue; |
| 7828 | SDNode *User = *UI; |
| 7829 | DCI.CombineTo(User, SDValue(VLDDup.getNode(), ResNo)); |
| 7830 | } |
| 7831 | |
| 7832 | // Now the vldN-lane intrinsic is dead except for its chain result. |
| 7833 | // Update uses of the chain. |
| 7834 | std::vector<SDValue> VLDDupResults; |
| 7835 | for (unsigned n = 0; n < NumVecs; ++n) |
| 7836 | VLDDupResults.push_back(SDValue(VLDDup.getNode(), n)); |
| 7837 | VLDDupResults.push_back(SDValue(VLDDup.getNode(), NumVecs)); |
| 7838 | DCI.CombineTo(VLD, VLDDupResults); |
| 7839 | |
| 7840 | return true; |
| 7841 | } |
| 7842 | |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 7843 | /// PerformVDUPLANECombine - Target-specific dag combine xforms for |
| 7844 | /// ARMISD::VDUPLANE. |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 7845 | static SDValue PerformVDUPLANECombine(SDNode *N, |
| 7846 | TargetLowering::DAGCombinerInfo &DCI) { |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 7847 | SDValue Op = N->getOperand(0); |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 7848 | |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 7849 | // If the source is a vldN-lane (N > 1) intrinsic, and all the other uses |
| 7850 | // of that intrinsic are also VDUPLANEs, combine them to a vldN-dup operation. |
| 7851 | if (CombineVLDDUP(N, DCI)) |
| 7852 | return SDValue(N, 0); |
| 7853 | |
| 7854 | // If the source is already a VMOVIMM or VMVNIMM splat, the VDUPLANE is |
| 7855 | // redundant. Ignore bit_converts for now; element sizes are checked below. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7856 | while (Op.getOpcode() == ISD::BITCAST) |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 7857 | Op = Op.getOperand(0); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 7858 | if (Op.getOpcode() != ARMISD::VMOVIMM && Op.getOpcode() != ARMISD::VMVNIMM) |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 7859 | return SDValue(); |
| 7860 | |
| 7861 | // Make sure the VMOV element size is not bigger than the VDUPLANE elements. |
| 7862 | unsigned EltSize = Op.getValueType().getVectorElementType().getSizeInBits(); |
| 7863 | // The canonical VMOV for a zero vector uses a 32-bit element size. |
| 7864 | unsigned Imm = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
| 7865 | unsigned EltBits; |
| 7866 | if (ARM_AM::decodeNEONModImm(Imm, EltBits) == 0) |
| 7867 | EltSize = 8; |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 7868 | EVT VT = N->getValueType(0); |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 7869 | if (EltSize > VT.getVectorElementType().getSizeInBits()) |
| 7870 | return SDValue(); |
| 7871 | |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 7872 | return DCI.DAG.getNode(ISD::BITCAST, N->getDebugLoc(), VT, Op); |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 7873 | } |
| 7874 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7875 | // 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] | 7876 | // elements are the same constant, C, and Log2(C) ranges from 1 to 32. |
| 7877 | static bool isConstVecPow2(SDValue ConstVec, bool isSigned, uint64_t &C) |
| 7878 | { |
Chad Rosier | 118c9a0 | 2011-06-28 17:26:57 +0000 | [diff] [blame] | 7879 | integerPart cN; |
| 7880 | integerPart c0 = 0; |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 7881 | for (unsigned I = 0, E = ConstVec.getValueType().getVectorNumElements(); |
| 7882 | I != E; I++) { |
| 7883 | ConstantFPSDNode *C = dyn_cast<ConstantFPSDNode>(ConstVec.getOperand(I)); |
| 7884 | if (!C) |
| 7885 | return false; |
| 7886 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7887 | bool isExact; |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 7888 | APFloat APF = C->getValueAPF(); |
| 7889 | if (APF.convertToInteger(&cN, 64, isSigned, APFloat::rmTowardZero, &isExact) |
| 7890 | != APFloat::opOK || !isExact) |
| 7891 | return false; |
| 7892 | |
| 7893 | c0 = (I == 0) ? cN : c0; |
| 7894 | if (!isPowerOf2_64(cN) || c0 != cN || Log2_64(c0) < 1 || Log2_64(c0) > 32) |
| 7895 | return false; |
| 7896 | } |
| 7897 | C = c0; |
| 7898 | return true; |
| 7899 | } |
| 7900 | |
| 7901 | /// PerformVCVTCombine - VCVT (floating-point to fixed-point, Advanced SIMD) |
| 7902 | /// can replace combinations of VMUL and VCVT (floating-point to integer) |
| 7903 | /// when the VMUL has a constant operand that is a power of 2. |
| 7904 | /// |
| 7905 | /// Example (assume d17 = <float 8.000000e+00, float 8.000000e+00>): |
| 7906 | /// vmul.f32 d16, d17, d16 |
| 7907 | /// vcvt.s32.f32 d16, d16 |
| 7908 | /// becomes: |
| 7909 | /// vcvt.s32.f32 d16, d16, #3 |
| 7910 | static SDValue PerformVCVTCombine(SDNode *N, |
| 7911 | TargetLowering::DAGCombinerInfo &DCI, |
| 7912 | const ARMSubtarget *Subtarget) { |
| 7913 | SelectionDAG &DAG = DCI.DAG; |
| 7914 | SDValue Op = N->getOperand(0); |
| 7915 | |
| 7916 | if (!Subtarget->hasNEON() || !Op.getValueType().isVector() || |
| 7917 | Op.getOpcode() != ISD::FMUL) |
| 7918 | return SDValue(); |
| 7919 | |
| 7920 | uint64_t C; |
| 7921 | SDValue N0 = Op->getOperand(0); |
| 7922 | SDValue ConstVec = Op->getOperand(1); |
| 7923 | bool isSigned = N->getOpcode() == ISD::FP_TO_SINT; |
| 7924 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7925 | if (ConstVec.getOpcode() != ISD::BUILD_VECTOR || |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 7926 | !isConstVecPow2(ConstVec, isSigned, C)) |
| 7927 | return SDValue(); |
| 7928 | |
| 7929 | unsigned IntrinsicOpcode = isSigned ? Intrinsic::arm_neon_vcvtfp2fxs : |
| 7930 | Intrinsic::arm_neon_vcvtfp2fxu; |
| 7931 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, N->getDebugLoc(), |
| 7932 | N->getValueType(0), |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7933 | DAG.getConstant(IntrinsicOpcode, MVT::i32), N0, |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 7934 | DAG.getConstant(Log2_64(C), MVT::i32)); |
| 7935 | } |
| 7936 | |
| 7937 | /// PerformVDIVCombine - VCVT (fixed-point to floating-point, Advanced SIMD) |
| 7938 | /// can replace combinations of VCVT (integer to floating-point) and VDIV |
| 7939 | /// when the VDIV has a constant operand that is a power of 2. |
| 7940 | /// |
| 7941 | /// Example (assume d17 = <float 8.000000e+00, float 8.000000e+00>): |
| 7942 | /// vcvt.f32.s32 d16, d16 |
| 7943 | /// vdiv.f32 d16, d17, d16 |
| 7944 | /// becomes: |
| 7945 | /// vcvt.f32.s32 d16, d16, #3 |
| 7946 | static SDValue PerformVDIVCombine(SDNode *N, |
| 7947 | TargetLowering::DAGCombinerInfo &DCI, |
| 7948 | const ARMSubtarget *Subtarget) { |
| 7949 | SelectionDAG &DAG = DCI.DAG; |
| 7950 | SDValue Op = N->getOperand(0); |
| 7951 | unsigned OpOpcode = Op.getNode()->getOpcode(); |
| 7952 | |
| 7953 | if (!Subtarget->hasNEON() || !N->getValueType(0).isVector() || |
| 7954 | (OpOpcode != ISD::SINT_TO_FP && OpOpcode != ISD::UINT_TO_FP)) |
| 7955 | return SDValue(); |
| 7956 | |
| 7957 | uint64_t C; |
| 7958 | SDValue ConstVec = N->getOperand(1); |
| 7959 | bool isSigned = OpOpcode == ISD::SINT_TO_FP; |
| 7960 | |
| 7961 | if (ConstVec.getOpcode() != ISD::BUILD_VECTOR || |
| 7962 | !isConstVecPow2(ConstVec, isSigned, C)) |
| 7963 | return SDValue(); |
| 7964 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7965 | unsigned IntrinsicOpcode = isSigned ? Intrinsic::arm_neon_vcvtfxs2fp : |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 7966 | Intrinsic::arm_neon_vcvtfxu2fp; |
| 7967 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, N->getDebugLoc(), |
| 7968 | Op.getValueType(), |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7969 | DAG.getConstant(IntrinsicOpcode, MVT::i32), |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 7970 | Op.getOperand(0), DAG.getConstant(Log2_64(C), MVT::i32)); |
| 7971 | } |
| 7972 | |
| 7973 | /// Getvshiftimm - Check if this is a valid build_vector for the immediate |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7974 | /// operand of a vector shift operation, where all the elements of the |
| 7975 | /// build_vector must have the same constant integer value. |
| 7976 | static bool getVShiftImm(SDValue Op, unsigned ElementBits, int64_t &Cnt) { |
| 7977 | // Ignore bit_converts. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7978 | while (Op.getOpcode() == ISD::BITCAST) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7979 | Op = Op.getOperand(0); |
| 7980 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(Op.getNode()); |
| 7981 | APInt SplatBits, SplatUndef; |
| 7982 | unsigned SplatBitSize; |
| 7983 | bool HasAnyUndefs; |
| 7984 | if (! BVN || ! BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, |
| 7985 | HasAnyUndefs, ElementBits) || |
| 7986 | SplatBitSize > ElementBits) |
| 7987 | return false; |
| 7988 | Cnt = SplatBits.getSExtValue(); |
| 7989 | return true; |
| 7990 | } |
| 7991 | |
| 7992 | /// isVShiftLImm - Check if this is a valid build_vector for the immediate |
| 7993 | /// operand of a vector shift left operation. That value must be in the range: |
| 7994 | /// 0 <= Value < ElementBits for a left shift; or |
| 7995 | /// 0 <= Value <= ElementBits for a long left shift. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 7996 | static bool isVShiftLImm(SDValue Op, EVT VT, bool isLong, int64_t &Cnt) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7997 | assert(VT.isVector() && "vector shift count is not a vector type"); |
| 7998 | unsigned ElementBits = VT.getVectorElementType().getSizeInBits(); |
| 7999 | if (! getVShiftImm(Op, ElementBits, Cnt)) |
| 8000 | return false; |
| 8001 | return (Cnt >= 0 && (isLong ? Cnt-1 : Cnt) < ElementBits); |
| 8002 | } |
| 8003 | |
| 8004 | /// isVShiftRImm - Check if this is a valid build_vector for the immediate |
| 8005 | /// operand of a vector shift right operation. For a shift opcode, the value |
| 8006 | /// is positive, but for an intrinsic the value count must be negative. The |
| 8007 | /// absolute value must be in the range: |
| 8008 | /// 1 <= |Value| <= ElementBits for a right shift; or |
| 8009 | /// 1 <= |Value| <= ElementBits/2 for a narrow right shift. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8010 | static bool isVShiftRImm(SDValue Op, EVT VT, bool isNarrow, bool isIntrinsic, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8011 | int64_t &Cnt) { |
| 8012 | assert(VT.isVector() && "vector shift count is not a vector type"); |
| 8013 | unsigned ElementBits = VT.getVectorElementType().getSizeInBits(); |
| 8014 | if (! getVShiftImm(Op, ElementBits, Cnt)) |
| 8015 | return false; |
| 8016 | if (isIntrinsic) |
| 8017 | Cnt = -Cnt; |
| 8018 | return (Cnt >= 1 && Cnt <= (isNarrow ? ElementBits/2 : ElementBits)); |
| 8019 | } |
| 8020 | |
| 8021 | /// PerformIntrinsicCombine - ARM-specific DAG combining for intrinsics. |
| 8022 | static SDValue PerformIntrinsicCombine(SDNode *N, SelectionDAG &DAG) { |
| 8023 | unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue(); |
| 8024 | switch (IntNo) { |
| 8025 | default: |
| 8026 | // Don't do anything for most intrinsics. |
| 8027 | break; |
| 8028 | |
| 8029 | // Vector shifts: check for immediate versions and lower them. |
| 8030 | // Note: This is done during DAG combining instead of DAG legalizing because |
| 8031 | // the build_vectors for 64-bit vector element shift counts are generally |
| 8032 | // not legal, and it is hard to see their values after they get legalized to |
| 8033 | // loads from a constant pool. |
| 8034 | case Intrinsic::arm_neon_vshifts: |
| 8035 | case Intrinsic::arm_neon_vshiftu: |
| 8036 | case Intrinsic::arm_neon_vshiftls: |
| 8037 | case Intrinsic::arm_neon_vshiftlu: |
| 8038 | case Intrinsic::arm_neon_vshiftn: |
| 8039 | case Intrinsic::arm_neon_vrshifts: |
| 8040 | case Intrinsic::arm_neon_vrshiftu: |
| 8041 | case Intrinsic::arm_neon_vrshiftn: |
| 8042 | case Intrinsic::arm_neon_vqshifts: |
| 8043 | case Intrinsic::arm_neon_vqshiftu: |
| 8044 | case Intrinsic::arm_neon_vqshiftsu: |
| 8045 | case Intrinsic::arm_neon_vqshiftns: |
| 8046 | case Intrinsic::arm_neon_vqshiftnu: |
| 8047 | case Intrinsic::arm_neon_vqshiftnsu: |
| 8048 | case Intrinsic::arm_neon_vqrshiftns: |
| 8049 | case Intrinsic::arm_neon_vqrshiftnu: |
| 8050 | case Intrinsic::arm_neon_vqrshiftnsu: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8051 | EVT VT = N->getOperand(1).getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8052 | int64_t Cnt; |
| 8053 | unsigned VShiftOpc = 0; |
| 8054 | |
| 8055 | switch (IntNo) { |
| 8056 | case Intrinsic::arm_neon_vshifts: |
| 8057 | case Intrinsic::arm_neon_vshiftu: |
| 8058 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) { |
| 8059 | VShiftOpc = ARMISD::VSHL; |
| 8060 | break; |
| 8061 | } |
| 8062 | if (isVShiftRImm(N->getOperand(2), VT, false, true, Cnt)) { |
| 8063 | VShiftOpc = (IntNo == Intrinsic::arm_neon_vshifts ? |
| 8064 | ARMISD::VSHRs : ARMISD::VSHRu); |
| 8065 | break; |
| 8066 | } |
| 8067 | return SDValue(); |
| 8068 | |
| 8069 | case Intrinsic::arm_neon_vshiftls: |
| 8070 | case Intrinsic::arm_neon_vshiftlu: |
| 8071 | if (isVShiftLImm(N->getOperand(2), VT, true, Cnt)) |
| 8072 | break; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 8073 | llvm_unreachable("invalid shift count for vshll intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8074 | |
| 8075 | case Intrinsic::arm_neon_vrshifts: |
| 8076 | case Intrinsic::arm_neon_vrshiftu: |
| 8077 | if (isVShiftRImm(N->getOperand(2), VT, false, true, Cnt)) |
| 8078 | break; |
| 8079 | return SDValue(); |
| 8080 | |
| 8081 | case Intrinsic::arm_neon_vqshifts: |
| 8082 | case Intrinsic::arm_neon_vqshiftu: |
| 8083 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) |
| 8084 | break; |
| 8085 | return SDValue(); |
| 8086 | |
| 8087 | case Intrinsic::arm_neon_vqshiftsu: |
| 8088 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) |
| 8089 | break; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 8090 | llvm_unreachable("invalid shift count for vqshlu intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8091 | |
| 8092 | case Intrinsic::arm_neon_vshiftn: |
| 8093 | case Intrinsic::arm_neon_vrshiftn: |
| 8094 | case Intrinsic::arm_neon_vqshiftns: |
| 8095 | case Intrinsic::arm_neon_vqshiftnu: |
| 8096 | case Intrinsic::arm_neon_vqshiftnsu: |
| 8097 | case Intrinsic::arm_neon_vqrshiftns: |
| 8098 | case Intrinsic::arm_neon_vqrshiftnu: |
| 8099 | case Intrinsic::arm_neon_vqrshiftnsu: |
| 8100 | // Narrowing shifts require an immediate right shift. |
| 8101 | if (isVShiftRImm(N->getOperand(2), VT, true, true, Cnt)) |
| 8102 | break; |
Jim Grosbach | 18f30e6 | 2010-06-02 21:53:11 +0000 | [diff] [blame] | 8103 | llvm_unreachable("invalid shift count for narrowing vector shift " |
| 8104 | "intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8105 | |
| 8106 | default: |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 8107 | llvm_unreachable("unhandled vector shift"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8108 | } |
| 8109 | |
| 8110 | switch (IntNo) { |
| 8111 | case Intrinsic::arm_neon_vshifts: |
| 8112 | case Intrinsic::arm_neon_vshiftu: |
| 8113 | // Opcode already set above. |
| 8114 | break; |
| 8115 | case Intrinsic::arm_neon_vshiftls: |
| 8116 | case Intrinsic::arm_neon_vshiftlu: |
| 8117 | if (Cnt == VT.getVectorElementType().getSizeInBits()) |
| 8118 | VShiftOpc = ARMISD::VSHLLi; |
| 8119 | else |
| 8120 | VShiftOpc = (IntNo == Intrinsic::arm_neon_vshiftls ? |
| 8121 | ARMISD::VSHLLs : ARMISD::VSHLLu); |
| 8122 | break; |
| 8123 | case Intrinsic::arm_neon_vshiftn: |
| 8124 | VShiftOpc = ARMISD::VSHRN; break; |
| 8125 | case Intrinsic::arm_neon_vrshifts: |
| 8126 | VShiftOpc = ARMISD::VRSHRs; break; |
| 8127 | case Intrinsic::arm_neon_vrshiftu: |
| 8128 | VShiftOpc = ARMISD::VRSHRu; break; |
| 8129 | case Intrinsic::arm_neon_vrshiftn: |
| 8130 | VShiftOpc = ARMISD::VRSHRN; break; |
| 8131 | case Intrinsic::arm_neon_vqshifts: |
| 8132 | VShiftOpc = ARMISD::VQSHLs; break; |
| 8133 | case Intrinsic::arm_neon_vqshiftu: |
| 8134 | VShiftOpc = ARMISD::VQSHLu; break; |
| 8135 | case Intrinsic::arm_neon_vqshiftsu: |
| 8136 | VShiftOpc = ARMISD::VQSHLsu; break; |
| 8137 | case Intrinsic::arm_neon_vqshiftns: |
| 8138 | VShiftOpc = ARMISD::VQSHRNs; break; |
| 8139 | case Intrinsic::arm_neon_vqshiftnu: |
| 8140 | VShiftOpc = ARMISD::VQSHRNu; break; |
| 8141 | case Intrinsic::arm_neon_vqshiftnsu: |
| 8142 | VShiftOpc = ARMISD::VQSHRNsu; break; |
| 8143 | case Intrinsic::arm_neon_vqrshiftns: |
| 8144 | VShiftOpc = ARMISD::VQRSHRNs; break; |
| 8145 | case Intrinsic::arm_neon_vqrshiftnu: |
| 8146 | VShiftOpc = ARMISD::VQRSHRNu; break; |
| 8147 | case Intrinsic::arm_neon_vqrshiftnsu: |
| 8148 | VShiftOpc = ARMISD::VQRSHRNsu; break; |
| 8149 | } |
| 8150 | |
| 8151 | return DAG.getNode(VShiftOpc, N->getDebugLoc(), N->getValueType(0), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8152 | N->getOperand(1), DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8153 | } |
| 8154 | |
| 8155 | case Intrinsic::arm_neon_vshiftins: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8156 | EVT VT = N->getOperand(1).getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8157 | int64_t Cnt; |
| 8158 | unsigned VShiftOpc = 0; |
| 8159 | |
| 8160 | if (isVShiftLImm(N->getOperand(3), VT, false, Cnt)) |
| 8161 | VShiftOpc = ARMISD::VSLI; |
| 8162 | else if (isVShiftRImm(N->getOperand(3), VT, false, true, Cnt)) |
| 8163 | VShiftOpc = ARMISD::VSRI; |
| 8164 | else { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 8165 | llvm_unreachable("invalid shift count for vsli/vsri intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8166 | } |
| 8167 | |
| 8168 | return DAG.getNode(VShiftOpc, N->getDebugLoc(), N->getValueType(0), |
| 8169 | N->getOperand(1), N->getOperand(2), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8170 | DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8171 | } |
| 8172 | |
| 8173 | case Intrinsic::arm_neon_vqrshifts: |
| 8174 | case Intrinsic::arm_neon_vqrshiftu: |
| 8175 | // No immediate versions of these to check for. |
| 8176 | break; |
| 8177 | } |
| 8178 | |
| 8179 | return SDValue(); |
| 8180 | } |
| 8181 | |
| 8182 | /// PerformShiftCombine - Checks for immediate versions of vector shifts and |
| 8183 | /// lowers them. As with the vector shift intrinsics, this is done during DAG |
| 8184 | /// combining instead of DAG legalizing because the build_vectors for 64-bit |
| 8185 | /// vector element shift counts are generally not legal, and it is hard to see |
| 8186 | /// their values after they get legalized to loads from a constant pool. |
| 8187 | static SDValue PerformShiftCombine(SDNode *N, SelectionDAG &DAG, |
| 8188 | const ARMSubtarget *ST) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8189 | EVT VT = N->getValueType(0); |
Evan Cheng | 5fb468a | 2012-02-23 02:58:19 +0000 | [diff] [blame] | 8190 | if (N->getOpcode() == ISD::SRL && VT == MVT::i32 && ST->hasV6Ops()) { |
| 8191 | // Canonicalize (srl (bswap x), 16) to (rotr (bswap x), 16) if the high |
| 8192 | // 16-bits of x is zero. This optimizes rev + lsr 16 to rev16. |
| 8193 | SDValue N1 = N->getOperand(1); |
| 8194 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N1)) { |
| 8195 | SDValue N0 = N->getOperand(0); |
| 8196 | if (C->getZExtValue() == 16 && N0.getOpcode() == ISD::BSWAP && |
| 8197 | DAG.MaskedValueIsZero(N0.getOperand(0), |
| 8198 | APInt::getHighBitsSet(32, 16))) |
| 8199 | return DAG.getNode(ISD::ROTR, N->getDebugLoc(), VT, N0, N1); |
| 8200 | } |
| 8201 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8202 | |
| 8203 | // Nothing to be done for scalar shifts. |
Tanya Lattner | 9684a7c | 2010-11-18 22:06:46 +0000 | [diff] [blame] | 8204 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 8205 | if (!VT.isVector() || !TLI.isTypeLegal(VT)) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8206 | return SDValue(); |
| 8207 | |
| 8208 | assert(ST->hasNEON() && "unexpected vector shift"); |
| 8209 | int64_t Cnt; |
| 8210 | |
| 8211 | switch (N->getOpcode()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 8212 | default: llvm_unreachable("unexpected shift opcode"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8213 | |
| 8214 | case ISD::SHL: |
| 8215 | if (isVShiftLImm(N->getOperand(1), VT, false, Cnt)) |
| 8216 | return DAG.getNode(ARMISD::VSHL, N->getDebugLoc(), VT, N->getOperand(0), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8217 | DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8218 | break; |
| 8219 | |
| 8220 | case ISD::SRA: |
| 8221 | case ISD::SRL: |
| 8222 | if (isVShiftRImm(N->getOperand(1), VT, false, false, Cnt)) { |
| 8223 | unsigned VShiftOpc = (N->getOpcode() == ISD::SRA ? |
| 8224 | ARMISD::VSHRs : ARMISD::VSHRu); |
| 8225 | return DAG.getNode(VShiftOpc, N->getDebugLoc(), VT, N->getOperand(0), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8226 | DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8227 | } |
| 8228 | } |
| 8229 | return SDValue(); |
| 8230 | } |
| 8231 | |
| 8232 | /// PerformExtendCombine - Target-specific DAG combining for ISD::SIGN_EXTEND, |
| 8233 | /// ISD::ZERO_EXTEND, and ISD::ANY_EXTEND. |
| 8234 | static SDValue PerformExtendCombine(SDNode *N, SelectionDAG &DAG, |
| 8235 | const ARMSubtarget *ST) { |
| 8236 | SDValue N0 = N->getOperand(0); |
| 8237 | |
| 8238 | // Check for sign- and zero-extensions of vector extract operations of 8- |
| 8239 | // and 16-bit vector elements. NEON supports these directly. They are |
| 8240 | // handled during DAG combining because type legalization will promote them |
| 8241 | // to 32-bit types and it is messy to recognize the operations after that. |
| 8242 | if (ST->hasNEON() && N0.getOpcode() == ISD::EXTRACT_VECTOR_ELT) { |
| 8243 | SDValue Vec = N0.getOperand(0); |
| 8244 | SDValue Lane = N0.getOperand(1); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8245 | EVT VT = N->getValueType(0); |
| 8246 | EVT EltVT = N0.getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8247 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 8248 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8249 | if (VT == MVT::i32 && |
| 8250 | (EltVT == MVT::i8 || EltVT == MVT::i16) && |
Bob Wilson | 3468c2e | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 8251 | TLI.isTypeLegal(Vec.getValueType()) && |
| 8252 | isa<ConstantSDNode>(Lane)) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8253 | |
| 8254 | unsigned Opc = 0; |
| 8255 | switch (N->getOpcode()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 8256 | default: llvm_unreachable("unexpected opcode"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8257 | case ISD::SIGN_EXTEND: |
| 8258 | Opc = ARMISD::VGETLANEs; |
| 8259 | break; |
| 8260 | case ISD::ZERO_EXTEND: |
| 8261 | case ISD::ANY_EXTEND: |
| 8262 | Opc = ARMISD::VGETLANEu; |
| 8263 | break; |
| 8264 | } |
| 8265 | return DAG.getNode(Opc, N->getDebugLoc(), VT, Vec, Lane); |
| 8266 | } |
| 8267 | } |
| 8268 | |
| 8269 | return SDValue(); |
| 8270 | } |
| 8271 | |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8272 | /// PerformSELECT_CCCombine - Target-specific DAG combining for ISD::SELECT_CC |
| 8273 | /// to match f32 max/min patterns to use NEON vmax/vmin instructions. |
| 8274 | static SDValue PerformSELECT_CCCombine(SDNode *N, SelectionDAG &DAG, |
| 8275 | const ARMSubtarget *ST) { |
| 8276 | // 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] | 8277 | // selects like "x < y ? x : y". Unless the NoNaNsFPMath option is set, |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8278 | // be careful about NaNs: NEON's vmax/vmin return NaN if either operand is |
| 8279 | // a NaN; only do the transformation when it matches that behavior. |
| 8280 | |
| 8281 | // For now only do this when using NEON for FP operations; if using VFP, it |
| 8282 | // is not obvious that the benefit outweighs the cost of switching to the |
| 8283 | // NEON pipeline. |
| 8284 | if (!ST->hasNEON() || !ST->useNEONForSinglePrecisionFP() || |
| 8285 | N->getValueType(0) != MVT::f32) |
| 8286 | return SDValue(); |
| 8287 | |
| 8288 | SDValue CondLHS = N->getOperand(0); |
| 8289 | SDValue CondRHS = N->getOperand(1); |
| 8290 | SDValue LHS = N->getOperand(2); |
| 8291 | SDValue RHS = N->getOperand(3); |
| 8292 | ISD::CondCode CC = cast<CondCodeSDNode>(N->getOperand(4))->get(); |
| 8293 | |
| 8294 | unsigned Opcode = 0; |
| 8295 | bool IsReversed; |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 8296 | if (DAG.isEqualTo(LHS, CondLHS) && DAG.isEqualTo(RHS, CondRHS)) { |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8297 | IsReversed = false; // x CC y ? x : y |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 8298 | } else if (DAG.isEqualTo(LHS, CondRHS) && DAG.isEqualTo(RHS, CondLHS)) { |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8299 | IsReversed = true ; // x CC y ? y : x |
| 8300 | } else { |
| 8301 | return SDValue(); |
| 8302 | } |
| 8303 | |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 8304 | bool IsUnordered; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8305 | switch (CC) { |
| 8306 | default: break; |
| 8307 | case ISD::SETOLT: |
| 8308 | case ISD::SETOLE: |
| 8309 | case ISD::SETLT: |
| 8310 | case ISD::SETLE: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8311 | case ISD::SETULT: |
| 8312 | case ISD::SETULE: |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 8313 | // If LHS is NaN, an ordered comparison will be false and the result will |
| 8314 | // be the RHS, but vmin(NaN, RHS) = NaN. Avoid this by checking that LHS |
| 8315 | // != NaN. Likewise, for unordered comparisons, check for RHS != NaN. |
| 8316 | IsUnordered = (CC == ISD::SETULT || CC == ISD::SETULE); |
| 8317 | if (!DAG.isKnownNeverNaN(IsUnordered ? RHS : LHS)) |
| 8318 | break; |
| 8319 | // For less-than-or-equal comparisons, "+0 <= -0" will be true but vmin |
| 8320 | // will return -0, so vmin can only be used for unsafe math or if one of |
| 8321 | // the operands is known to be nonzero. |
| 8322 | if ((CC == ISD::SETLE || CC == ISD::SETOLE || CC == ISD::SETULE) && |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 8323 | !DAG.getTarget().Options.UnsafeFPMath && |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 8324 | !(DAG.isKnownNeverZero(LHS) || DAG.isKnownNeverZero(RHS))) |
| 8325 | break; |
| 8326 | Opcode = IsReversed ? ARMISD::FMAX : ARMISD::FMIN; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8327 | break; |
| 8328 | |
| 8329 | case ISD::SETOGT: |
| 8330 | case ISD::SETOGE: |
| 8331 | case ISD::SETGT: |
| 8332 | case ISD::SETGE: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8333 | case ISD::SETUGT: |
| 8334 | case ISD::SETUGE: |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 8335 | // If LHS is NaN, an ordered comparison will be false and the result will |
| 8336 | // be the RHS, but vmax(NaN, RHS) = NaN. Avoid this by checking that LHS |
| 8337 | // != NaN. Likewise, for unordered comparisons, check for RHS != NaN. |
| 8338 | IsUnordered = (CC == ISD::SETUGT || CC == ISD::SETUGE); |
| 8339 | if (!DAG.isKnownNeverNaN(IsUnordered ? RHS : LHS)) |
| 8340 | break; |
| 8341 | // For greater-than-or-equal comparisons, "-0 >= +0" will be true but vmax |
| 8342 | // will return +0, so vmax can only be used for unsafe math or if one of |
| 8343 | // the operands is known to be nonzero. |
| 8344 | if ((CC == ISD::SETGE || CC == ISD::SETOGE || CC == ISD::SETUGE) && |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 8345 | !DAG.getTarget().Options.UnsafeFPMath && |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 8346 | !(DAG.isKnownNeverZero(LHS) || DAG.isKnownNeverZero(RHS))) |
| 8347 | break; |
| 8348 | Opcode = IsReversed ? ARMISD::FMIN : ARMISD::FMAX; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8349 | break; |
| 8350 | } |
| 8351 | |
| 8352 | if (!Opcode) |
| 8353 | return SDValue(); |
| 8354 | return DAG.getNode(Opcode, N->getDebugLoc(), N->getValueType(0), LHS, RHS); |
| 8355 | } |
| 8356 | |
Evan Cheng | e721f5c | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 8357 | /// PerformCMOVCombine - Target-specific DAG combining for ARMISD::CMOV. |
| 8358 | SDValue |
| 8359 | ARMTargetLowering::PerformCMOVCombine(SDNode *N, SelectionDAG &DAG) const { |
| 8360 | SDValue Cmp = N->getOperand(4); |
| 8361 | if (Cmp.getOpcode() != ARMISD::CMPZ) |
| 8362 | // Only looking at EQ and NE cases. |
| 8363 | return SDValue(); |
| 8364 | |
| 8365 | EVT VT = N->getValueType(0); |
| 8366 | DebugLoc dl = N->getDebugLoc(); |
| 8367 | SDValue LHS = Cmp.getOperand(0); |
| 8368 | SDValue RHS = Cmp.getOperand(1); |
| 8369 | SDValue FalseVal = N->getOperand(0); |
| 8370 | SDValue TrueVal = N->getOperand(1); |
| 8371 | SDValue ARMcc = N->getOperand(2); |
Jim Grosbach | b04546f | 2011-09-13 20:30:37 +0000 | [diff] [blame] | 8372 | ARMCC::CondCodes CC = |
| 8373 | (ARMCC::CondCodes)cast<ConstantSDNode>(ARMcc)->getZExtValue(); |
Evan Cheng | e721f5c | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 8374 | |
| 8375 | // Simplify |
| 8376 | // mov r1, r0 |
| 8377 | // cmp r1, x |
| 8378 | // mov r0, y |
| 8379 | // moveq r0, x |
| 8380 | // to |
| 8381 | // cmp r0, x |
| 8382 | // movne r0, y |
| 8383 | // |
| 8384 | // mov r1, r0 |
| 8385 | // cmp r1, x |
| 8386 | // mov r0, x |
| 8387 | // movne r0, y |
| 8388 | // to |
| 8389 | // cmp r0, x |
| 8390 | // movne r0, y |
| 8391 | /// FIXME: Turn this into a target neutral optimization? |
| 8392 | SDValue Res; |
Evan Cheng | 9b88d2d | 2011-09-28 23:16:31 +0000 | [diff] [blame] | 8393 | if (CC == ARMCC::NE && FalseVal == RHS && FalseVal != LHS) { |
Evan Cheng | e721f5c | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 8394 | Res = DAG.getNode(ARMISD::CMOV, dl, VT, LHS, TrueVal, ARMcc, |
| 8395 | N->getOperand(3), Cmp); |
| 8396 | } else if (CC == ARMCC::EQ && TrueVal == RHS) { |
| 8397 | SDValue ARMcc; |
| 8398 | SDValue NewCmp = getARMCmp(LHS, RHS, ISD::SETNE, ARMcc, DAG, dl); |
| 8399 | Res = DAG.getNode(ARMISD::CMOV, dl, VT, LHS, FalseVal, ARMcc, |
| 8400 | N->getOperand(3), NewCmp); |
| 8401 | } |
| 8402 | |
| 8403 | if (Res.getNode()) { |
| 8404 | APInt KnownZero, KnownOne; |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 8405 | DAG.ComputeMaskedBits(SDValue(N,0), KnownZero, KnownOne); |
Evan Cheng | e721f5c | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 8406 | // Capture demanded bits information that would be otherwise lost. |
| 8407 | if (KnownZero == 0xfffffffe) |
| 8408 | Res = DAG.getNode(ISD::AssertZext, dl, MVT::i32, Res, |
| 8409 | DAG.getValueType(MVT::i1)); |
| 8410 | else if (KnownZero == 0xffffff00) |
| 8411 | Res = DAG.getNode(ISD::AssertZext, dl, MVT::i32, Res, |
| 8412 | DAG.getValueType(MVT::i8)); |
| 8413 | else if (KnownZero == 0xffff0000) |
| 8414 | Res = DAG.getNode(ISD::AssertZext, dl, MVT::i32, Res, |
| 8415 | DAG.getValueType(MVT::i16)); |
| 8416 | } |
| 8417 | |
| 8418 | return Res; |
| 8419 | } |
| 8420 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 8421 | SDValue ARMTargetLowering::PerformDAGCombine(SDNode *N, |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 8422 | DAGCombinerInfo &DCI) const { |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 8423 | switch (N->getOpcode()) { |
| 8424 | default: break; |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8425 | case ISD::ADD: return PerformADDCombine(N, DCI, Subtarget); |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8426 | case ISD::SUB: return PerformSUBCombine(N, DCI); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 8427 | case ISD::MUL: return PerformMULCombine(N, DCI, Subtarget); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8428 | case ISD::OR: return PerformORCombine(N, DCI, Subtarget); |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 8429 | case ISD::XOR: return PerformXORCombine(N, DCI, Subtarget); |
| 8430 | case ISD::AND: return PerformANDCombine(N, DCI, Subtarget); |
Evan Cheng | 0c1aec1 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 8431 | case ARMISD::BFI: return PerformBFICombine(N, DCI); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 8432 | case ARMISD::VMOVRRD: return PerformVMOVRRDCombine(N, DCI); |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 8433 | case ARMISD::VMOVDRR: return PerformVMOVDRRCombine(N, DCI.DAG); |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 8434 | case ISD::STORE: return PerformSTORECombine(N, DCI); |
| 8435 | case ISD::BUILD_VECTOR: return PerformBUILD_VECTORCombine(N, DCI); |
| 8436 | case ISD::INSERT_VECTOR_ELT: return PerformInsertEltCombine(N, DCI); |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 8437 | case ISD::VECTOR_SHUFFLE: return PerformVECTOR_SHUFFLECombine(N, DCI.DAG); |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 8438 | case ARMISD::VDUPLANE: return PerformVDUPLANECombine(N, DCI); |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 8439 | case ISD::FP_TO_SINT: |
| 8440 | case ISD::FP_TO_UINT: return PerformVCVTCombine(N, DCI, Subtarget); |
| 8441 | case ISD::FDIV: return PerformVDIVCombine(N, DCI, Subtarget); |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8442 | case ISD::INTRINSIC_WO_CHAIN: return PerformIntrinsicCombine(N, DCI.DAG); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8443 | case ISD::SHL: |
| 8444 | case ISD::SRA: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8445 | case ISD::SRL: return PerformShiftCombine(N, DCI.DAG, Subtarget); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8446 | case ISD::SIGN_EXTEND: |
| 8447 | case ISD::ZERO_EXTEND: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8448 | case ISD::ANY_EXTEND: return PerformExtendCombine(N, DCI.DAG, Subtarget); |
| 8449 | case ISD::SELECT_CC: return PerformSELECT_CCCombine(N, DCI.DAG, Subtarget); |
Evan Cheng | e721f5c | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 8450 | case ARMISD::CMOV: return PerformCMOVCombine(N, DCI.DAG); |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 8451 | case ARMISD::VLD2DUP: |
| 8452 | case ARMISD::VLD3DUP: |
| 8453 | case ARMISD::VLD4DUP: |
| 8454 | return CombineBaseUpdate(N, DCI); |
| 8455 | case ISD::INTRINSIC_VOID: |
| 8456 | case ISD::INTRINSIC_W_CHAIN: |
| 8457 | switch (cast<ConstantSDNode>(N->getOperand(1))->getZExtValue()) { |
| 8458 | case Intrinsic::arm_neon_vld1: |
| 8459 | case Intrinsic::arm_neon_vld2: |
| 8460 | case Intrinsic::arm_neon_vld3: |
| 8461 | case Intrinsic::arm_neon_vld4: |
| 8462 | case Intrinsic::arm_neon_vld2lane: |
| 8463 | case Intrinsic::arm_neon_vld3lane: |
| 8464 | case Intrinsic::arm_neon_vld4lane: |
| 8465 | case Intrinsic::arm_neon_vst1: |
| 8466 | case Intrinsic::arm_neon_vst2: |
| 8467 | case Intrinsic::arm_neon_vst3: |
| 8468 | case Intrinsic::arm_neon_vst4: |
| 8469 | case Intrinsic::arm_neon_vst2lane: |
| 8470 | case Intrinsic::arm_neon_vst3lane: |
| 8471 | case Intrinsic::arm_neon_vst4lane: |
| 8472 | return CombineBaseUpdate(N, DCI); |
| 8473 | default: break; |
| 8474 | } |
| 8475 | break; |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 8476 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 8477 | return SDValue(); |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 8478 | } |
| 8479 | |
Evan Cheng | 31959b1 | 2011-02-02 01:06:55 +0000 | [diff] [blame] | 8480 | bool ARMTargetLowering::isDesirableToTransformToIntegerOp(unsigned Opc, |
| 8481 | EVT VT) const { |
| 8482 | return (VT == MVT::f32) && (Opc == ISD::LOAD || Opc == ISD::STORE); |
| 8483 | } |
| 8484 | |
Bill Wendling | af56634 | 2009-08-15 21:21:19 +0000 | [diff] [blame] | 8485 | bool ARMTargetLowering::allowsUnalignedMemoryAccesses(EVT VT) const { |
Bob Wilson | 02aba73 | 2010-09-28 04:09:35 +0000 | [diff] [blame] | 8486 | if (!Subtarget->allowsUnalignedMem()) |
Bob Wilson | 86fe66d | 2010-06-25 04:12:31 +0000 | [diff] [blame] | 8487 | return false; |
Bill Wendling | af56634 | 2009-08-15 21:21:19 +0000 | [diff] [blame] | 8488 | |
| 8489 | switch (VT.getSimpleVT().SimpleTy) { |
| 8490 | default: |
| 8491 | return false; |
| 8492 | case MVT::i8: |
| 8493 | case MVT::i16: |
| 8494 | case MVT::i32: |
| 8495 | return true; |
| 8496 | // FIXME: VLD1 etc with standard alignment is legal. |
| 8497 | } |
| 8498 | } |
| 8499 | |
Lang Hames | 1a1d1fc | 2011-11-02 22:52:45 +0000 | [diff] [blame] | 8500 | static bool memOpAlign(unsigned DstAlign, unsigned SrcAlign, |
| 8501 | unsigned AlignCheck) { |
| 8502 | return ((SrcAlign == 0 || SrcAlign % AlignCheck == 0) && |
| 8503 | (DstAlign == 0 || DstAlign % AlignCheck == 0)); |
| 8504 | } |
| 8505 | |
| 8506 | EVT ARMTargetLowering::getOptimalMemOpType(uint64_t Size, |
| 8507 | unsigned DstAlign, unsigned SrcAlign, |
Lang Hames | a1e7888 | 2011-11-02 23:37:04 +0000 | [diff] [blame] | 8508 | bool IsZeroVal, |
Lang Hames | 1a1d1fc | 2011-11-02 22:52:45 +0000 | [diff] [blame] | 8509 | bool MemcpyStrSrc, |
| 8510 | MachineFunction &MF) const { |
| 8511 | const Function *F = MF.getFunction(); |
| 8512 | |
| 8513 | // See if we can use NEON instructions for this... |
Lang Hames | a1e7888 | 2011-11-02 23:37:04 +0000 | [diff] [blame] | 8514 | if (IsZeroVal && |
Lang Hames | 1a1d1fc | 2011-11-02 22:52:45 +0000 | [diff] [blame] | 8515 | !F->hasFnAttr(Attribute::NoImplicitFloat) && |
| 8516 | Subtarget->hasNEON()) { |
| 8517 | if (memOpAlign(SrcAlign, DstAlign, 16) && Size >= 16) { |
| 8518 | return MVT::v4i32; |
| 8519 | } else if (memOpAlign(SrcAlign, DstAlign, 8) && Size >= 8) { |
| 8520 | return MVT::v2i32; |
| 8521 | } |
| 8522 | } |
| 8523 | |
Lang Hames | 5207bf2 | 2011-11-08 18:56:23 +0000 | [diff] [blame] | 8524 | // Lowering to i32/i16 if the size permits. |
| 8525 | if (Size >= 4) { |
| 8526 | return MVT::i32; |
| 8527 | } else if (Size >= 2) { |
| 8528 | return MVT::i16; |
| 8529 | } |
| 8530 | |
Lang Hames | 1a1d1fc | 2011-11-02 22:52:45 +0000 | [diff] [blame] | 8531 | // Let the target-independent logic figure it out. |
| 8532 | return MVT::Other; |
| 8533 | } |
| 8534 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 8535 | static bool isLegalT1AddressImmediate(int64_t V, EVT VT) { |
| 8536 | if (V < 0) |
| 8537 | return false; |
| 8538 | |
| 8539 | unsigned Scale = 1; |
| 8540 | switch (VT.getSimpleVT().SimpleTy) { |
| 8541 | default: return false; |
| 8542 | case MVT::i1: |
| 8543 | case MVT::i8: |
| 8544 | // Scale == 1; |
| 8545 | break; |
| 8546 | case MVT::i16: |
| 8547 | // Scale == 2; |
| 8548 | Scale = 2; |
| 8549 | break; |
| 8550 | case MVT::i32: |
| 8551 | // Scale == 4; |
| 8552 | Scale = 4; |
| 8553 | break; |
| 8554 | } |
| 8555 | |
| 8556 | if ((V & (Scale - 1)) != 0) |
| 8557 | return false; |
| 8558 | V /= Scale; |
| 8559 | return V == (V & ((1LL << 5) - 1)); |
| 8560 | } |
| 8561 | |
| 8562 | static bool isLegalT2AddressImmediate(int64_t V, EVT VT, |
| 8563 | const ARMSubtarget *Subtarget) { |
| 8564 | bool isNeg = false; |
| 8565 | if (V < 0) { |
| 8566 | isNeg = true; |
| 8567 | V = - V; |
| 8568 | } |
| 8569 | |
| 8570 | switch (VT.getSimpleVT().SimpleTy) { |
| 8571 | default: return false; |
| 8572 | case MVT::i1: |
| 8573 | case MVT::i8: |
| 8574 | case MVT::i16: |
| 8575 | case MVT::i32: |
| 8576 | // + imm12 or - imm8 |
| 8577 | if (isNeg) |
| 8578 | return V == (V & ((1LL << 8) - 1)); |
| 8579 | return V == (V & ((1LL << 12) - 1)); |
| 8580 | case MVT::f32: |
| 8581 | case MVT::f64: |
| 8582 | // Same as ARM mode. FIXME: NEON? |
| 8583 | if (!Subtarget->hasVFP2()) |
| 8584 | return false; |
| 8585 | if ((V & 3) != 0) |
| 8586 | return false; |
| 8587 | V >>= 2; |
| 8588 | return V == (V & ((1LL << 8) - 1)); |
| 8589 | } |
| 8590 | } |
| 8591 | |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8592 | /// isLegalAddressImmediate - Return true if the integer value can be used |
| 8593 | /// as the offset of the target addressing mode for load / store of the |
| 8594 | /// given type. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8595 | static bool isLegalAddressImmediate(int64_t V, EVT VT, |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8596 | const ARMSubtarget *Subtarget) { |
Evan Cheng | 961f879 | 2007-03-13 20:37:59 +0000 | [diff] [blame] | 8597 | if (V == 0) |
| 8598 | return true; |
| 8599 | |
Evan Cheng | 6501153 | 2009-03-09 19:15:00 +0000 | [diff] [blame] | 8600 | if (!VT.isSimple()) |
| 8601 | return false; |
| 8602 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 8603 | if (Subtarget->isThumb1Only()) |
| 8604 | return isLegalT1AddressImmediate(V, VT); |
| 8605 | else if (Subtarget->isThumb2()) |
| 8606 | return isLegalT2AddressImmediate(V, VT, Subtarget); |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8607 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 8608 | // ARM mode. |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8609 | if (V < 0) |
| 8610 | V = - V; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8611 | switch (VT.getSimpleVT().SimpleTy) { |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8612 | default: return false; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8613 | case MVT::i1: |
| 8614 | case MVT::i8: |
| 8615 | case MVT::i32: |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8616 | // +- imm12 |
Anton Korobeynikov | 7c1c261 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 8617 | return V == (V & ((1LL << 12) - 1)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8618 | case MVT::i16: |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8619 | // +- imm8 |
Anton Korobeynikov | 7c1c261 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 8620 | return V == (V & ((1LL << 8) - 1)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8621 | case MVT::f32: |
| 8622 | case MVT::f64: |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 8623 | if (!Subtarget->hasVFP2()) // FIXME: NEON? |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8624 | return false; |
Evan Cheng | 0b0a9a9 | 2007-05-03 02:00:18 +0000 | [diff] [blame] | 8625 | if ((V & 3) != 0) |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8626 | return false; |
| 8627 | V >>= 2; |
Anton Korobeynikov | 7c1c261 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 8628 | return V == (V & ((1LL << 8) - 1)); |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8629 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8630 | } |
| 8631 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 8632 | bool ARMTargetLowering::isLegalT2ScaledAddressingMode(const AddrMode &AM, |
| 8633 | EVT VT) const { |
| 8634 | int Scale = AM.Scale; |
| 8635 | if (Scale < 0) |
| 8636 | return false; |
| 8637 | |
| 8638 | switch (VT.getSimpleVT().SimpleTy) { |
| 8639 | default: return false; |
| 8640 | case MVT::i1: |
| 8641 | case MVT::i8: |
| 8642 | case MVT::i16: |
| 8643 | case MVT::i32: |
| 8644 | if (Scale == 1) |
| 8645 | return true; |
| 8646 | // r + r << imm |
| 8647 | Scale = Scale & ~1; |
| 8648 | return Scale == 2 || Scale == 4 || Scale == 8; |
| 8649 | case MVT::i64: |
| 8650 | // r + r |
| 8651 | if (((unsigned)AM.HasBaseReg + Scale) <= 2) |
| 8652 | return true; |
| 8653 | return false; |
| 8654 | case MVT::isVoid: |
| 8655 | // Note, we allow "void" uses (basically, uses that aren't loads or |
| 8656 | // stores), because arm allows folding a scale into many arithmetic |
| 8657 | // operations. This should be made more precise and revisited later. |
| 8658 | |
| 8659 | // Allow r << imm, but the imm has to be a multiple of two. |
| 8660 | if (Scale & 1) return false; |
| 8661 | return isPowerOf2_32(Scale); |
| 8662 | } |
| 8663 | } |
| 8664 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8665 | /// isLegalAddressingMode - Return true if the addressing mode represented |
| 8666 | /// 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] | 8667 | bool ARMTargetLowering::isLegalAddressingMode(const AddrMode &AM, |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 8668 | Type *Ty) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8669 | EVT VT = getValueType(Ty, true); |
Bob Wilson | 2c7dab1 | 2009-04-08 17:55:28 +0000 | [diff] [blame] | 8670 | if (!isLegalAddressImmediate(AM.BaseOffs, VT, Subtarget)) |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8671 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 8672 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8673 | // Can never fold addr of global into load/store. |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 8674 | if (AM.BaseGV) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8675 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 8676 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8677 | switch (AM.Scale) { |
| 8678 | case 0: // no scale reg, must be "r+i" or "r", or "i". |
| 8679 | break; |
| 8680 | case 1: |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 8681 | if (Subtarget->isThumb1Only()) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8682 | return false; |
Chris Lattner | 5a3d40d | 2007-04-13 06:50:55 +0000 | [diff] [blame] | 8683 | // FALL THROUGH. |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8684 | default: |
Chris Lattner | 5a3d40d | 2007-04-13 06:50:55 +0000 | [diff] [blame] | 8685 | // ARM doesn't support any R+R*scale+imm addr modes. |
| 8686 | if (AM.BaseOffs) |
| 8687 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 8688 | |
Bob Wilson | 2c7dab1 | 2009-04-08 17:55:28 +0000 | [diff] [blame] | 8689 | if (!VT.isSimple()) |
| 8690 | return false; |
| 8691 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 8692 | if (Subtarget->isThumb2()) |
| 8693 | return isLegalT2ScaledAddressingMode(AM, VT); |
| 8694 | |
Chris Lattner | eb13d1b | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 8695 | int Scale = AM.Scale; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8696 | switch (VT.getSimpleVT().SimpleTy) { |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8697 | default: return false; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8698 | case MVT::i1: |
| 8699 | case MVT::i8: |
| 8700 | case MVT::i32: |
Chris Lattner | eb13d1b | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 8701 | if (Scale < 0) Scale = -Scale; |
| 8702 | if (Scale == 1) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8703 | return true; |
| 8704 | // r + r << imm |
Chris Lattner | e115294 | 2007-04-11 16:17:12 +0000 | [diff] [blame] | 8705 | return isPowerOf2_32(Scale & ~1); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8706 | case MVT::i16: |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 8707 | case MVT::i64: |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8708 | // r + r |
Chris Lattner | eb13d1b | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 8709 | if (((unsigned)AM.HasBaseReg + Scale) <= 2) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8710 | return true; |
Chris Lattner | e115294 | 2007-04-11 16:17:12 +0000 | [diff] [blame] | 8711 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 8712 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8713 | case MVT::isVoid: |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8714 | // Note, we allow "void" uses (basically, uses that aren't loads or |
| 8715 | // stores), because arm allows folding a scale into many arithmetic |
| 8716 | // operations. This should be made more precise and revisited later. |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 8717 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8718 | // 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] | 8719 | if (Scale & 1) return false; |
| 8720 | return isPowerOf2_32(Scale); |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8721 | } |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8722 | } |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8723 | return true; |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8724 | } |
| 8725 | |
Evan Cheng | 77e4751 | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 8726 | /// isLegalICmpImmediate - Return true if the specified immediate is legal |
| 8727 | /// icmp immediate, that is the target has icmp instructions which can compare |
| 8728 | /// a register against the immediate without having to materialize the |
| 8729 | /// immediate into a register. |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 8730 | bool ARMTargetLowering::isLegalICmpImmediate(int64_t Imm) const { |
Jakob Stoklund Olesen | 70fbea7 | 2012-04-06 17:45:04 +0000 | [diff] [blame] | 8731 | // Thumb2 and ARM modes can use cmn for negative immediates. |
Evan Cheng | 77e4751 | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 8732 | if (!Subtarget->isThumb()) |
Chandler Carruth | ba4d457 | 2012-04-06 20:10:52 +0000 | [diff] [blame] | 8733 | return ARM_AM::getSOImmVal(llvm::abs64(Imm)) != -1; |
Evan Cheng | 77e4751 | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 8734 | if (Subtarget->isThumb2()) |
Chandler Carruth | ba4d457 | 2012-04-06 20:10:52 +0000 | [diff] [blame] | 8735 | return ARM_AM::getT2SOImmVal(llvm::abs64(Imm)) != -1; |
Jakob Stoklund Olesen | 70fbea7 | 2012-04-06 17:45:04 +0000 | [diff] [blame] | 8736 | // Thumb1 doesn't have cmn, and only 8-bit immediates. |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 8737 | return Imm >= 0 && Imm <= 255; |
Evan Cheng | 77e4751 | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 8738 | } |
| 8739 | |
Dan Gohman | cca8214 | 2011-05-03 00:46:49 +0000 | [diff] [blame] | 8740 | /// isLegalAddImmediate - Return true if the specified immediate is legal |
| 8741 | /// add immediate, that is the target has add instructions which can add |
| 8742 | /// a register with the immediate without having to materialize the |
| 8743 | /// immediate into a register. |
| 8744 | bool ARMTargetLowering::isLegalAddImmediate(int64_t Imm) const { |
| 8745 | return ARM_AM::getSOImmVal(Imm) != -1; |
| 8746 | } |
| 8747 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8748 | static bool getARMIndexedAddressParts(SDNode *Ptr, EVT VT, |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8749 | bool isSEXTLoad, SDValue &Base, |
| 8750 | SDValue &Offset, bool &isInc, |
| 8751 | SelectionDAG &DAG) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8752 | if (Ptr->getOpcode() != ISD::ADD && Ptr->getOpcode() != ISD::SUB) |
| 8753 | return false; |
| 8754 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8755 | if (VT == MVT::i16 || ((VT == MVT::i8 || VT == MVT::i1) && isSEXTLoad)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8756 | // AddressingMode 3 |
| 8757 | Base = Ptr->getOperand(0); |
| 8758 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 8759 | int RHSC = (int)RHS->getZExtValue(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8760 | if (RHSC < 0 && RHSC > -256) { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8761 | assert(Ptr->getOpcode() == ISD::ADD); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8762 | isInc = false; |
| 8763 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); |
| 8764 | return true; |
| 8765 | } |
| 8766 | } |
| 8767 | isInc = (Ptr->getOpcode() == ISD::ADD); |
| 8768 | Offset = Ptr->getOperand(1); |
| 8769 | return true; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8770 | } else if (VT == MVT::i32 || VT == MVT::i8 || VT == MVT::i1) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8771 | // AddressingMode 2 |
| 8772 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 8773 | int RHSC = (int)RHS->getZExtValue(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8774 | if (RHSC < 0 && RHSC > -0x1000) { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8775 | assert(Ptr->getOpcode() == ISD::ADD); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8776 | isInc = false; |
| 8777 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); |
| 8778 | Base = Ptr->getOperand(0); |
| 8779 | return true; |
| 8780 | } |
| 8781 | } |
| 8782 | |
| 8783 | if (Ptr->getOpcode() == ISD::ADD) { |
| 8784 | isInc = true; |
Evan Cheng | ee04a6d | 2011-07-20 23:34:39 +0000 | [diff] [blame] | 8785 | ARM_AM::ShiftOpc ShOpcVal= |
| 8786 | ARM_AM::getShiftOpcForNode(Ptr->getOperand(0).getOpcode()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8787 | if (ShOpcVal != ARM_AM::no_shift) { |
| 8788 | Base = Ptr->getOperand(1); |
| 8789 | Offset = Ptr->getOperand(0); |
| 8790 | } else { |
| 8791 | Base = Ptr->getOperand(0); |
| 8792 | Offset = Ptr->getOperand(1); |
| 8793 | } |
| 8794 | return true; |
| 8795 | } |
| 8796 | |
| 8797 | isInc = (Ptr->getOpcode() == ISD::ADD); |
| 8798 | Base = Ptr->getOperand(0); |
| 8799 | Offset = Ptr->getOperand(1); |
| 8800 | return true; |
| 8801 | } |
| 8802 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 8803 | // FIXME: Use VLDM / VSTM to emulate indexed FP load / store. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8804 | return false; |
| 8805 | } |
| 8806 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8807 | static bool getT2IndexedAddressParts(SDNode *Ptr, EVT VT, |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8808 | bool isSEXTLoad, SDValue &Base, |
| 8809 | SDValue &Offset, bool &isInc, |
| 8810 | SelectionDAG &DAG) { |
| 8811 | if (Ptr->getOpcode() != ISD::ADD && Ptr->getOpcode() != ISD::SUB) |
| 8812 | return false; |
| 8813 | |
| 8814 | Base = Ptr->getOperand(0); |
| 8815 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
| 8816 | int RHSC = (int)RHS->getZExtValue(); |
| 8817 | if (RHSC < 0 && RHSC > -0x100) { // 8 bits. |
| 8818 | assert(Ptr->getOpcode() == ISD::ADD); |
| 8819 | isInc = false; |
| 8820 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); |
| 8821 | return true; |
| 8822 | } else if (RHSC > 0 && RHSC < 0x100) { // 8 bit, no zero. |
| 8823 | isInc = Ptr->getOpcode() == ISD::ADD; |
| 8824 | Offset = DAG.getConstant(RHSC, RHS->getValueType(0)); |
| 8825 | return true; |
| 8826 | } |
| 8827 | } |
| 8828 | |
| 8829 | return false; |
| 8830 | } |
| 8831 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8832 | /// getPreIndexedAddressParts - returns true by value, base pointer and |
| 8833 | /// offset pointer and addressing mode by reference if the node's address |
| 8834 | /// can be legally represented as pre-indexed load / store address. |
| 8835 | bool |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 8836 | ARMTargetLowering::getPreIndexedAddressParts(SDNode *N, SDValue &Base, |
| 8837 | SDValue &Offset, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8838 | ISD::MemIndexedMode &AM, |
Dan Gohman | 73e0914 | 2009-01-15 16:29:45 +0000 | [diff] [blame] | 8839 | SelectionDAG &DAG) const { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8840 | if (Subtarget->isThumb1Only()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8841 | return false; |
| 8842 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8843 | EVT VT; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 8844 | SDValue Ptr; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8845 | bool isSEXTLoad = false; |
| 8846 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) { |
| 8847 | Ptr = LD->getBasePtr(); |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 8848 | VT = LD->getMemoryVT(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8849 | isSEXTLoad = LD->getExtensionType() == ISD::SEXTLOAD; |
| 8850 | } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) { |
| 8851 | Ptr = ST->getBasePtr(); |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 8852 | VT = ST->getMemoryVT(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8853 | } else |
| 8854 | return false; |
| 8855 | |
| 8856 | bool isInc; |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8857 | bool isLegal = false; |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 8858 | if (Subtarget->isThumb2()) |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8859 | isLegal = getT2IndexedAddressParts(Ptr.getNode(), VT, isSEXTLoad, Base, |
| 8860 | Offset, isInc, DAG); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 8861 | else |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8862 | isLegal = getARMIndexedAddressParts(Ptr.getNode(), VT, isSEXTLoad, Base, |
Evan Cheng | 0412957 | 2009-07-02 06:44:30 +0000 | [diff] [blame] | 8863 | Offset, isInc, DAG); |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8864 | if (!isLegal) |
| 8865 | return false; |
| 8866 | |
| 8867 | AM = isInc ? ISD::PRE_INC : ISD::PRE_DEC; |
| 8868 | return true; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8869 | } |
| 8870 | |
| 8871 | /// getPostIndexedAddressParts - returns true by value, base pointer and |
| 8872 | /// offset pointer and addressing mode by reference if this node can be |
| 8873 | /// combined with a load / store to form a post-indexed load / store. |
| 8874 | bool ARMTargetLowering::getPostIndexedAddressParts(SDNode *N, SDNode *Op, |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 8875 | SDValue &Base, |
| 8876 | SDValue &Offset, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8877 | ISD::MemIndexedMode &AM, |
Dan Gohman | 73e0914 | 2009-01-15 16:29:45 +0000 | [diff] [blame] | 8878 | SelectionDAG &DAG) const { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8879 | if (Subtarget->isThumb1Only()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8880 | return false; |
| 8881 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8882 | EVT VT; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 8883 | SDValue Ptr; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8884 | bool isSEXTLoad = false; |
| 8885 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) { |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 8886 | VT = LD->getMemoryVT(); |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 8887 | Ptr = LD->getBasePtr(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8888 | isSEXTLoad = LD->getExtensionType() == ISD::SEXTLOAD; |
| 8889 | } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) { |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 8890 | VT = ST->getMemoryVT(); |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 8891 | Ptr = ST->getBasePtr(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8892 | } else |
| 8893 | return false; |
| 8894 | |
| 8895 | bool isInc; |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8896 | bool isLegal = false; |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 8897 | if (Subtarget->isThumb2()) |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8898 | isLegal = getT2IndexedAddressParts(Op, VT, isSEXTLoad, Base, Offset, |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 8899 | isInc, DAG); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 8900 | else |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8901 | isLegal = getARMIndexedAddressParts(Op, VT, isSEXTLoad, Base, Offset, |
| 8902 | isInc, DAG); |
| 8903 | if (!isLegal) |
| 8904 | return false; |
| 8905 | |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 8906 | if (Ptr != Base) { |
| 8907 | // Swap base ptr and offset to catch more post-index load / store when |
| 8908 | // it's legal. In Thumb2 mode, offset must be an immediate. |
| 8909 | if (Ptr == Offset && Op->getOpcode() == ISD::ADD && |
| 8910 | !Subtarget->isThumb2()) |
| 8911 | std::swap(Base, Offset); |
| 8912 | |
| 8913 | // Post-indexed load / store update the base pointer. |
| 8914 | if (Ptr != Base) |
| 8915 | return false; |
| 8916 | } |
| 8917 | |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8918 | AM = isInc ? ISD::POST_INC : ISD::POST_DEC; |
| 8919 | return true; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8920 | } |
| 8921 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 8922 | void ARMTargetLowering::computeMaskedBitsForTargetNode(const SDValue Op, |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 8923 | APInt &KnownZero, |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 8924 | APInt &KnownOne, |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 8925 | const SelectionDAG &DAG, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8926 | unsigned Depth) const { |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 8927 | KnownZero = KnownOne = APInt(KnownOne.getBitWidth(), 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8928 | switch (Op.getOpcode()) { |
| 8929 | default: break; |
| 8930 | case ARMISD::CMOV: { |
| 8931 | // Bits are known zero/one if known on the LHS and RHS. |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 8932 | DAG.ComputeMaskedBits(Op.getOperand(0), KnownZero, KnownOne, Depth+1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8933 | if (KnownZero == 0 && KnownOne == 0) return; |
| 8934 | |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 8935 | APInt KnownZeroRHS, KnownOneRHS; |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 8936 | DAG.ComputeMaskedBits(Op.getOperand(1), KnownZeroRHS, KnownOneRHS, Depth+1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8937 | KnownZero &= KnownZeroRHS; |
| 8938 | KnownOne &= KnownOneRHS; |
| 8939 | return; |
| 8940 | } |
| 8941 | } |
| 8942 | } |
| 8943 | |
| 8944 | //===----------------------------------------------------------------------===// |
| 8945 | // ARM Inline Assembly Support |
| 8946 | //===----------------------------------------------------------------------===// |
| 8947 | |
Evan Cheng | 55d4200 | 2011-01-08 01:24:27 +0000 | [diff] [blame] | 8948 | bool ARMTargetLowering::ExpandInlineAsm(CallInst *CI) const { |
| 8949 | // Looking for "rev" which is V6+. |
| 8950 | if (!Subtarget->hasV6Ops()) |
| 8951 | return false; |
| 8952 | |
| 8953 | InlineAsm *IA = cast<InlineAsm>(CI->getCalledValue()); |
| 8954 | std::string AsmStr = IA->getAsmString(); |
| 8955 | SmallVector<StringRef, 4> AsmPieces; |
| 8956 | SplitString(AsmStr, AsmPieces, ";\n"); |
| 8957 | |
| 8958 | switch (AsmPieces.size()) { |
| 8959 | default: return false; |
| 8960 | case 1: |
| 8961 | AsmStr = AsmPieces[0]; |
| 8962 | AsmPieces.clear(); |
| 8963 | SplitString(AsmStr, AsmPieces, " \t,"); |
| 8964 | |
| 8965 | // rev $0, $1 |
| 8966 | if (AsmPieces.size() == 3 && |
| 8967 | AsmPieces[0] == "rev" && AsmPieces[1] == "$0" && AsmPieces[2] == "$1" && |
| 8968 | IA->getConstraintString().compare(0, 4, "=l,l") == 0) { |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 8969 | IntegerType *Ty = dyn_cast<IntegerType>(CI->getType()); |
Evan Cheng | 55d4200 | 2011-01-08 01:24:27 +0000 | [diff] [blame] | 8970 | if (Ty && Ty->getBitWidth() == 32) |
| 8971 | return IntrinsicLowering::LowerToByteSwap(CI); |
| 8972 | } |
| 8973 | break; |
| 8974 | } |
| 8975 | |
| 8976 | return false; |
| 8977 | } |
| 8978 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8979 | /// getConstraintType - Given a constraint letter, return the type of |
| 8980 | /// constraint it is for this target. |
| 8981 | ARMTargetLowering::ConstraintType |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 8982 | ARMTargetLowering::getConstraintType(const std::string &Constraint) const { |
| 8983 | if (Constraint.size() == 1) { |
| 8984 | switch (Constraint[0]) { |
| 8985 | default: break; |
| 8986 | case 'l': return C_RegisterClass; |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 8987 | case 'w': return C_RegisterClass; |
Eric Christopher | 73744df | 2011-06-30 23:23:01 +0000 | [diff] [blame] | 8988 | case 'h': return C_RegisterClass; |
Eric Christopher | 89bd71f | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 8989 | case 'x': return C_RegisterClass; |
Eric Christopher | d5dc9ec | 2011-07-01 00:30:46 +0000 | [diff] [blame] | 8990 | case 't': return C_RegisterClass; |
Eric Christopher | 5e653c9 | 2011-07-01 01:00:07 +0000 | [diff] [blame] | 8991 | case 'j': return C_Other; // Constant for movw. |
Eric Christopher | ef7f1e7 | 2011-07-29 21:18:58 +0000 | [diff] [blame] | 8992 | // An address with a single base register. Due to the way we |
| 8993 | // currently handle addresses it is the same as an 'r' memory constraint. |
| 8994 | case 'Q': return C_Memory; |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 8995 | } |
Eric Christopher | 1312ca8 | 2011-06-21 22:10:57 +0000 | [diff] [blame] | 8996 | } else if (Constraint.size() == 2) { |
| 8997 | switch (Constraint[0]) { |
| 8998 | default: break; |
| 8999 | // All 'U+' constraints are addresses. |
| 9000 | case 'U': return C_Memory; |
| 9001 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9002 | } |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 9003 | return TargetLowering::getConstraintType(Constraint); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9004 | } |
| 9005 | |
John Thompson | 44ab89e | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 9006 | /// Examine constraint type and operand type and determine a weight value. |
| 9007 | /// This object must already have been set up with the operand type |
| 9008 | /// and the current alternative constraint selected. |
| 9009 | TargetLowering::ConstraintWeight |
| 9010 | ARMTargetLowering::getSingleConstraintMatchWeight( |
| 9011 | AsmOperandInfo &info, const char *constraint) const { |
| 9012 | ConstraintWeight weight = CW_Invalid; |
| 9013 | Value *CallOperandVal = info.CallOperandVal; |
| 9014 | // If we don't have a value, we can't do a match, |
| 9015 | // but allow it at the lowest weight. |
| 9016 | if (CallOperandVal == NULL) |
| 9017 | return CW_Default; |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 9018 | Type *type = CallOperandVal->getType(); |
John Thompson | 44ab89e | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 9019 | // Look at the constraint type. |
| 9020 | switch (*constraint) { |
| 9021 | default: |
| 9022 | weight = TargetLowering::getSingleConstraintMatchWeight(info, constraint); |
| 9023 | break; |
| 9024 | case 'l': |
| 9025 | if (type->isIntegerTy()) { |
| 9026 | if (Subtarget->isThumb()) |
| 9027 | weight = CW_SpecificReg; |
| 9028 | else |
| 9029 | weight = CW_Register; |
| 9030 | } |
| 9031 | break; |
| 9032 | case 'w': |
| 9033 | if (type->isFloatingPointTy()) |
| 9034 | weight = CW_Register; |
| 9035 | break; |
| 9036 | } |
| 9037 | return weight; |
| 9038 | } |
| 9039 | |
Eric Christopher | 35e6d4d | 2011-06-30 23:50:52 +0000 | [diff] [blame] | 9040 | typedef std::pair<unsigned, const TargetRegisterClass*> RCPair; |
| 9041 | RCPair |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9042 | ARMTargetLowering::getRegForInlineAsmConstraint(const std::string &Constraint, |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 9043 | EVT VT) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9044 | if (Constraint.size() == 1) { |
Jakob Stoklund Olesen | 09bf003 | 2010-01-14 18:19:56 +0000 | [diff] [blame] | 9045 | // GCC ARM Constraint Letters |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9046 | switch (Constraint[0]) { |
Eric Christopher | 73744df | 2011-06-30 23:23:01 +0000 | [diff] [blame] | 9047 | case 'l': // Low regs or general regs. |
Jakob Stoklund Olesen | 09bf003 | 2010-01-14 18:19:56 +0000 | [diff] [blame] | 9048 | if (Subtarget->isThumb()) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 9049 | return RCPair(0U, &ARM::tGPRRegClass); |
| 9050 | return RCPair(0U, &ARM::GPRRegClass); |
Eric Christopher | 73744df | 2011-06-30 23:23:01 +0000 | [diff] [blame] | 9051 | case 'h': // High regs or no regs. |
| 9052 | if (Subtarget->isThumb()) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 9053 | return RCPair(0U, &ARM::hGPRRegClass); |
Eric Christopher | 1070f82 | 2011-07-01 00:19:27 +0000 | [diff] [blame] | 9054 | break; |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 9055 | case 'r': |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 9056 | return RCPair(0U, &ARM::GPRRegClass); |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 9057 | case 'w': |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9058 | if (VT == MVT::f32) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 9059 | return RCPair(0U, &ARM::SPRRegClass); |
Bob Wilson | 5afffae | 2009-12-18 01:03:29 +0000 | [diff] [blame] | 9060 | if (VT.getSizeInBits() == 64) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 9061 | return RCPair(0U, &ARM::DPRRegClass); |
Evan Cheng | d831cda | 2009-12-08 23:06:22 +0000 | [diff] [blame] | 9062 | if (VT.getSizeInBits() == 128) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 9063 | return RCPair(0U, &ARM::QPRRegClass); |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 9064 | break; |
Eric Christopher | 89bd71f | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 9065 | case 'x': |
| 9066 | if (VT == MVT::f32) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 9067 | return RCPair(0U, &ARM::SPR_8RegClass); |
Eric Christopher | 89bd71f | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 9068 | if (VT.getSizeInBits() == 64) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 9069 | return RCPair(0U, &ARM::DPR_8RegClass); |
Eric Christopher | 89bd71f | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 9070 | if (VT.getSizeInBits() == 128) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 9071 | return RCPair(0U, &ARM::QPR_8RegClass); |
Eric Christopher | 89bd71f | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 9072 | break; |
Eric Christopher | d5dc9ec | 2011-07-01 00:30:46 +0000 | [diff] [blame] | 9073 | case 't': |
| 9074 | if (VT == MVT::f32) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 9075 | return RCPair(0U, &ARM::SPRRegClass); |
Eric Christopher | d5dc9ec | 2011-07-01 00:30:46 +0000 | [diff] [blame] | 9076 | break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9077 | } |
| 9078 | } |
Bob Wilson | 33cc5cb | 2010-03-15 23:09:18 +0000 | [diff] [blame] | 9079 | if (StringRef("{cc}").equals_lower(Constraint)) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 9080 | return std::make_pair(unsigned(ARM::CPSR), &ARM::CCRRegClass); |
Bob Wilson | 33cc5cb | 2010-03-15 23:09:18 +0000 | [diff] [blame] | 9081 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9082 | return TargetLowering::getRegForInlineAsmConstraint(Constraint, VT); |
| 9083 | } |
| 9084 | |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 9085 | /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops |
| 9086 | /// vector. If it is invalid, don't add anything to Ops. |
| 9087 | void ARMTargetLowering::LowerAsmOperandForConstraint(SDValue Op, |
Eric Christopher | 100c833 | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 9088 | std::string &Constraint, |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 9089 | std::vector<SDValue>&Ops, |
| 9090 | SelectionDAG &DAG) const { |
| 9091 | SDValue Result(0, 0); |
| 9092 | |
Eric Christopher | 100c833 | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 9093 | // Currently only support length 1 constraints. |
| 9094 | if (Constraint.length() != 1) return; |
Eric Christopher | 471e422 | 2011-06-08 23:55:35 +0000 | [diff] [blame] | 9095 | |
Eric Christopher | 100c833 | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 9096 | char ConstraintLetter = Constraint[0]; |
| 9097 | switch (ConstraintLetter) { |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 9098 | default: break; |
Eric Christopher | 5e653c9 | 2011-07-01 01:00:07 +0000 | [diff] [blame] | 9099 | case 'j': |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 9100 | case 'I': case 'J': case 'K': case 'L': |
| 9101 | case 'M': case 'N': case 'O': |
| 9102 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op); |
| 9103 | if (!C) |
| 9104 | return; |
| 9105 | |
| 9106 | int64_t CVal64 = C->getSExtValue(); |
| 9107 | int CVal = (int) CVal64; |
| 9108 | // None of these constraints allow values larger than 32 bits. Check |
| 9109 | // that the value fits in an int. |
| 9110 | if (CVal != CVal64) |
| 9111 | return; |
| 9112 | |
Eric Christopher | 100c833 | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 9113 | switch (ConstraintLetter) { |
Eric Christopher | 5e653c9 | 2011-07-01 01:00:07 +0000 | [diff] [blame] | 9114 | case 'j': |
Andrew Trick | 3af7a67 | 2011-09-20 03:06:13 +0000 | [diff] [blame] | 9115 | // Constant suitable for movw, must be between 0 and |
| 9116 | // 65535. |
| 9117 | if (Subtarget->hasV6T2Ops()) |
| 9118 | if (CVal >= 0 && CVal <= 65535) |
| 9119 | break; |
| 9120 | return; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 9121 | case 'I': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 9122 | if (Subtarget->isThumb1Only()) { |
| 9123 | // This must be a constant between 0 and 255, for ADD |
| 9124 | // immediates. |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 9125 | if (CVal >= 0 && CVal <= 255) |
| 9126 | break; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 9127 | } else if (Subtarget->isThumb2()) { |
| 9128 | // A constant that can be used as an immediate value in a |
| 9129 | // data-processing instruction. |
| 9130 | if (ARM_AM::getT2SOImmVal(CVal) != -1) |
| 9131 | break; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 9132 | } else { |
| 9133 | // A constant that can be used as an immediate value in a |
| 9134 | // data-processing instruction. |
| 9135 | if (ARM_AM::getSOImmVal(CVal) != -1) |
| 9136 | break; |
| 9137 | } |
| 9138 | return; |
| 9139 | |
| 9140 | case 'J': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 9141 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 9142 | // This must be a constant between -255 and -1, for negated ADD |
| 9143 | // immediates. This can be used in GCC with an "n" modifier that |
| 9144 | // prints the negated value, for use with SUB instructions. It is |
| 9145 | // not useful otherwise but is implemented for compatibility. |
| 9146 | if (CVal >= -255 && CVal <= -1) |
| 9147 | break; |
| 9148 | } else { |
| 9149 | // This must be a constant between -4095 and 4095. It is not clear |
| 9150 | // what this constraint is intended for. Implemented for |
| 9151 | // compatibility with GCC. |
| 9152 | if (CVal >= -4095 && CVal <= 4095) |
| 9153 | break; |
| 9154 | } |
| 9155 | return; |
| 9156 | |
| 9157 | case 'K': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 9158 | if (Subtarget->isThumb1Only()) { |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 9159 | // A 32-bit value where only one byte has a nonzero value. Exclude |
| 9160 | // zero to match GCC. This constraint is used by GCC internally for |
| 9161 | // constants that can be loaded with a move/shift combination. |
| 9162 | // It is not useful otherwise but is implemented for compatibility. |
| 9163 | if (CVal != 0 && ARM_AM::isThumbImmShiftedVal(CVal)) |
| 9164 | break; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 9165 | } else if (Subtarget->isThumb2()) { |
| 9166 | // A constant whose bitwise inverse can be used as an immediate |
| 9167 | // value in a data-processing instruction. This can be used in GCC |
| 9168 | // with a "B" modifier that prints the inverted value, for use with |
| 9169 | // BIC and MVN instructions. It is not useful otherwise but is |
| 9170 | // implemented for compatibility. |
| 9171 | if (ARM_AM::getT2SOImmVal(~CVal) != -1) |
| 9172 | break; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 9173 | } else { |
| 9174 | // A constant whose bitwise inverse can be used as an immediate |
| 9175 | // value in a data-processing instruction. This can be used in GCC |
| 9176 | // with a "B" modifier that prints the inverted value, for use with |
| 9177 | // BIC and MVN instructions. It is not useful otherwise but is |
| 9178 | // implemented for compatibility. |
| 9179 | if (ARM_AM::getSOImmVal(~CVal) != -1) |
| 9180 | break; |
| 9181 | } |
| 9182 | return; |
| 9183 | |
| 9184 | case 'L': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 9185 | if (Subtarget->isThumb1Only()) { |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 9186 | // This must be a constant between -7 and 7, |
| 9187 | // for 3-operand ADD/SUB immediate instructions. |
| 9188 | if (CVal >= -7 && CVal < 7) |
| 9189 | break; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 9190 | } else if (Subtarget->isThumb2()) { |
| 9191 | // A constant whose negation can be used as an immediate value in a |
| 9192 | // data-processing instruction. This can be used in GCC with an "n" |
| 9193 | // modifier that prints the negated value, for use with SUB |
| 9194 | // instructions. It is not useful otherwise but is implemented for |
| 9195 | // compatibility. |
| 9196 | if (ARM_AM::getT2SOImmVal(-CVal) != -1) |
| 9197 | break; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 9198 | } else { |
| 9199 | // A constant whose negation can be used as an immediate value in a |
| 9200 | // data-processing instruction. This can be used in GCC with an "n" |
| 9201 | // modifier that prints the negated value, for use with SUB |
| 9202 | // instructions. It is not useful otherwise but is implemented for |
| 9203 | // compatibility. |
| 9204 | if (ARM_AM::getSOImmVal(-CVal) != -1) |
| 9205 | break; |
| 9206 | } |
| 9207 | return; |
| 9208 | |
| 9209 | case 'M': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 9210 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 9211 | // This must be a multiple of 4 between 0 and 1020, for |
| 9212 | // ADD sp + immediate. |
| 9213 | if ((CVal >= 0 && CVal <= 1020) && ((CVal & 3) == 0)) |
| 9214 | break; |
| 9215 | } else { |
| 9216 | // A power of two or a constant between 0 and 32. This is used in |
| 9217 | // GCC for the shift amount on shifted register operands, but it is |
| 9218 | // useful in general for any shift amounts. |
| 9219 | if ((CVal >= 0 && CVal <= 32) || ((CVal & (CVal - 1)) == 0)) |
| 9220 | break; |
| 9221 | } |
| 9222 | return; |
| 9223 | |
| 9224 | case 'N': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 9225 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 9226 | // This must be a constant between 0 and 31, for shift amounts. |
| 9227 | if (CVal >= 0 && CVal <= 31) |
| 9228 | break; |
| 9229 | } |
| 9230 | return; |
| 9231 | |
| 9232 | case 'O': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 9233 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 9234 | // This must be a multiple of 4 between -508 and 508, for |
| 9235 | // ADD/SUB sp = sp + immediate. |
| 9236 | if ((CVal >= -508 && CVal <= 508) && ((CVal & 3) == 0)) |
| 9237 | break; |
| 9238 | } |
| 9239 | return; |
| 9240 | } |
| 9241 | Result = DAG.getTargetConstant(CVal, Op.getValueType()); |
| 9242 | break; |
| 9243 | } |
| 9244 | |
| 9245 | if (Result.getNode()) { |
| 9246 | Ops.push_back(Result); |
| 9247 | return; |
| 9248 | } |
Dale Johannesen | 1784d16 | 2010-06-25 21:55:36 +0000 | [diff] [blame] | 9249 | return TargetLowering::LowerAsmOperandForConstraint(Op, Constraint, Ops, DAG); |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 9250 | } |
Anton Korobeynikov | 48e1935 | 2009-09-23 19:04:09 +0000 | [diff] [blame] | 9251 | |
| 9252 | bool |
| 9253 | ARMTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const { |
| 9254 | // The ARM target isn't yet aware of offsets. |
| 9255 | return false; |
| 9256 | } |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 9257 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 9258 | bool ARM::isBitFieldInvertedMask(unsigned v) { |
| 9259 | if (v == 0xffffffff) |
| 9260 | return 0; |
| 9261 | // there can be 1's on either or both "outsides", all the "inside" |
| 9262 | // bits must be 0's |
| 9263 | unsigned int lsb = 0, msb = 31; |
| 9264 | while (v & (1 << msb)) --msb; |
| 9265 | while (v & (1 << lsb)) ++lsb; |
| 9266 | for (unsigned int i = lsb; i <= msb; ++i) { |
| 9267 | if (v & (1 << i)) |
| 9268 | return 0; |
| 9269 | } |
| 9270 | return 1; |
| 9271 | } |
| 9272 | |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 9273 | /// isFPImmLegal - Returns true if the target can instruction select the |
| 9274 | /// specified FP immediate natively. If false, the legalizer will |
| 9275 | /// materialize the FP immediate as a load from a constant pool. |
| 9276 | bool ARMTargetLowering::isFPImmLegal(const APFloat &Imm, EVT VT) const { |
| 9277 | if (!Subtarget->hasVFP3()) |
| 9278 | return false; |
| 9279 | if (VT == MVT::f32) |
Jim Grosbach | 4ebbf7b | 2011-09-30 00:50:06 +0000 | [diff] [blame] | 9280 | return ARM_AM::getFP32Imm(Imm) != -1; |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 9281 | if (VT == MVT::f64) |
Jim Grosbach | 4ebbf7b | 2011-09-30 00:50:06 +0000 | [diff] [blame] | 9282 | return ARM_AM::getFP64Imm(Imm) != -1; |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 9283 | return false; |
| 9284 | } |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 9285 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 9286 | /// getTgtMemIntrinsic - Represent NEON load and store intrinsics as |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 9287 | /// MemIntrinsicNodes. The associated MachineMemOperands record the alignment |
| 9288 | /// specified in the intrinsic calls. |
| 9289 | bool ARMTargetLowering::getTgtMemIntrinsic(IntrinsicInfo &Info, |
| 9290 | const CallInst &I, |
| 9291 | unsigned Intrinsic) const { |
| 9292 | switch (Intrinsic) { |
| 9293 | case Intrinsic::arm_neon_vld1: |
| 9294 | case Intrinsic::arm_neon_vld2: |
| 9295 | case Intrinsic::arm_neon_vld3: |
| 9296 | case Intrinsic::arm_neon_vld4: |
| 9297 | case Intrinsic::arm_neon_vld2lane: |
| 9298 | case Intrinsic::arm_neon_vld3lane: |
| 9299 | case Intrinsic::arm_neon_vld4lane: { |
| 9300 | Info.opc = ISD::INTRINSIC_W_CHAIN; |
| 9301 | // Conservatively set memVT to the entire set of vectors loaded. |
| 9302 | uint64_t NumElts = getTargetData()->getTypeAllocSize(I.getType()) / 8; |
| 9303 | Info.memVT = EVT::getVectorVT(I.getType()->getContext(), MVT::i64, NumElts); |
| 9304 | Info.ptrVal = I.getArgOperand(0); |
| 9305 | Info.offset = 0; |
| 9306 | Value *AlignArg = I.getArgOperand(I.getNumArgOperands() - 1); |
| 9307 | Info.align = cast<ConstantInt>(AlignArg)->getZExtValue(); |
| 9308 | Info.vol = false; // volatile loads with NEON intrinsics not supported |
| 9309 | Info.readMem = true; |
| 9310 | Info.writeMem = false; |
| 9311 | return true; |
| 9312 | } |
| 9313 | case Intrinsic::arm_neon_vst1: |
| 9314 | case Intrinsic::arm_neon_vst2: |
| 9315 | case Intrinsic::arm_neon_vst3: |
| 9316 | case Intrinsic::arm_neon_vst4: |
| 9317 | case Intrinsic::arm_neon_vst2lane: |
| 9318 | case Intrinsic::arm_neon_vst3lane: |
| 9319 | case Intrinsic::arm_neon_vst4lane: { |
| 9320 | Info.opc = ISD::INTRINSIC_VOID; |
| 9321 | // Conservatively set memVT to the entire set of vectors stored. |
| 9322 | unsigned NumElts = 0; |
| 9323 | for (unsigned ArgI = 1, ArgE = I.getNumArgOperands(); ArgI < ArgE; ++ArgI) { |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 9324 | Type *ArgTy = I.getArgOperand(ArgI)->getType(); |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 9325 | if (!ArgTy->isVectorTy()) |
| 9326 | break; |
| 9327 | NumElts += getTargetData()->getTypeAllocSize(ArgTy) / 8; |
| 9328 | } |
| 9329 | Info.memVT = EVT::getVectorVT(I.getType()->getContext(), MVT::i64, NumElts); |
| 9330 | Info.ptrVal = I.getArgOperand(0); |
| 9331 | Info.offset = 0; |
| 9332 | Value *AlignArg = I.getArgOperand(I.getNumArgOperands() - 1); |
| 9333 | Info.align = cast<ConstantInt>(AlignArg)->getZExtValue(); |
| 9334 | Info.vol = false; // volatile stores with NEON intrinsics not supported |
| 9335 | Info.readMem = false; |
| 9336 | Info.writeMem = true; |
| 9337 | return true; |
| 9338 | } |
Bruno Cardoso Lopes | a0112d0 | 2011-05-28 04:07:29 +0000 | [diff] [blame] | 9339 | case Intrinsic::arm_strexd: { |
| 9340 | Info.opc = ISD::INTRINSIC_W_CHAIN; |
| 9341 | Info.memVT = MVT::i64; |
| 9342 | Info.ptrVal = I.getArgOperand(2); |
| 9343 | Info.offset = 0; |
| 9344 | Info.align = 8; |
Bruno Cardoso Lopes | c75448c | 2011-06-16 18:11:32 +0000 | [diff] [blame] | 9345 | Info.vol = true; |
Bruno Cardoso Lopes | a0112d0 | 2011-05-28 04:07:29 +0000 | [diff] [blame] | 9346 | Info.readMem = false; |
| 9347 | Info.writeMem = true; |
| 9348 | return true; |
| 9349 | } |
| 9350 | case Intrinsic::arm_ldrexd: { |
| 9351 | Info.opc = ISD::INTRINSIC_W_CHAIN; |
| 9352 | Info.memVT = MVT::i64; |
| 9353 | Info.ptrVal = I.getArgOperand(0); |
| 9354 | Info.offset = 0; |
| 9355 | Info.align = 8; |
Bruno Cardoso Lopes | c75448c | 2011-06-16 18:11:32 +0000 | [diff] [blame] | 9356 | Info.vol = true; |
Bruno Cardoso Lopes | a0112d0 | 2011-05-28 04:07:29 +0000 | [diff] [blame] | 9357 | Info.readMem = true; |
| 9358 | Info.writeMem = false; |
| 9359 | return true; |
| 9360 | } |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 9361 | default: |
| 9362 | break; |
| 9363 | } |
| 9364 | |
| 9365 | return false; |
| 9366 | } |