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" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 16 | #include "ARM.h" |
Eric Christopher | 6f2ccef | 2010-09-10 22:42:06 +0000 | [diff] [blame] | 17 | #include "ARMCallingConv.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 18 | #include "ARMConstantPoolValue.h" |
| 19 | #include "ARMISelLowering.h" |
| 20 | #include "ARMMachineFunctionInfo.h" |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 21 | #include "ARMPerfectShuffle.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 22 | #include "ARMRegisterInfo.h" |
| 23 | #include "ARMSubtarget.h" |
| 24 | #include "ARMTargetMachine.h" |
Chris Lattner | 80ec279 | 2009-08-02 00:34:36 +0000 | [diff] [blame] | 25 | #include "ARMTargetObjectFile.h" |
Evan Cheng | ee04a6d | 2011-07-20 23:34:39 +0000 | [diff] [blame] | 26 | #include "MCTargetDesc/ARMAddressingModes.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 27 | #include "llvm/CallingConv.h" |
| 28 | #include "llvm/Constants.h" |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 29 | #include "llvm/Function.h" |
Benjamin Kramer | 174101e | 2009-10-20 11:44:38 +0000 | [diff] [blame] | 30 | #include "llvm/GlobalValue.h" |
Evan Cheng | 2770747 | 2007-03-16 08:43:56 +0000 | [diff] [blame] | 31 | #include "llvm/Instruction.h" |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 32 | #include "llvm/Instructions.h" |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 33 | #include "llvm/Intrinsics.h" |
Benjamin Kramer | 174101e | 2009-10-20 11:44:38 +0000 | [diff] [blame] | 34 | #include "llvm/Type.h" |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 35 | #include "llvm/CodeGen/CallingConvLower.h" |
Evan Cheng | 55d4200 | 2011-01-08 01:24:27 +0000 | [diff] [blame] | 36 | #include "llvm/CodeGen/IntrinsicLowering.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 37 | #include "llvm/CodeGen/MachineBasicBlock.h" |
| 38 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 39 | #include "llvm/CodeGen/MachineFunction.h" |
| 40 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 41 | #include "llvm/CodeGen/MachineModuleInfo.h" |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 42 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 43 | #include "llvm/CodeGen/SelectionDAG.h" |
Bill Wendling | 94a1c63 | 2010-03-09 02:46:12 +0000 | [diff] [blame] | 44 | #include "llvm/MC/MCSectionMachO.h" |
Evan Cheng | b6ab254 | 2007-01-31 08:40:13 +0000 | [diff] [blame] | 45 | #include "llvm/Target/TargetOptions.h" |
Evan Cheng | 55d4200 | 2011-01-08 01:24:27 +0000 | [diff] [blame] | 46 | #include "llvm/ADT/StringExtras.h" |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 47 | #include "llvm/ADT/Statistic.h" |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 48 | #include "llvm/Support/CommandLine.h" |
Torok Edwin | ab7c09b | 2009-07-08 18:01:40 +0000 | [diff] [blame] | 49 | #include "llvm/Support/ErrorHandling.h" |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 50 | #include "llvm/Support/MathExtras.h" |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 51 | #include "llvm/Support/raw_ostream.h" |
Jim Grosbach | 3fb2b1e | 2009-09-01 01:57:56 +0000 | [diff] [blame] | 52 | #include <sstream> |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 53 | using namespace llvm; |
| 54 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 55 | STATISTIC(NumTailCalls, "Number of tail calls"); |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 56 | STATISTIC(NumMovwMovt, "Number of GAs materialized with movw + movt"); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 57 | |
Bob Wilson | 703af3a | 2010-08-13 22:43:33 +0000 | [diff] [blame] | 58 | // This option should go away when tail calls fully work. |
| 59 | static cl::opt<bool> |
| 60 | EnableARMTailCalls("arm-tail-calls", cl::Hidden, |
| 61 | cl::desc("Generate tail calls (TEMPORARY OPTION)."), |
| 62 | cl::init(false)); |
| 63 | |
Eric Christopher | 836c624 | 2010-12-15 23:47:29 +0000 | [diff] [blame] | 64 | cl::opt<bool> |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 65 | EnableARMLongCalls("arm-long-calls", cl::Hidden, |
Evan Cheng | 515fe3a | 2010-07-08 02:08:50 +0000 | [diff] [blame] | 66 | cl::desc("Generate calls via indirect call instructions"), |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 67 | cl::init(false)); |
| 68 | |
Evan Cheng | 46df4eb | 2010-06-16 07:35:02 +0000 | [diff] [blame] | 69 | static cl::opt<bool> |
| 70 | ARMInterworking("arm-interworking", cl::Hidden, |
| 71 | cl::desc("Enable / disable ARM interworking (for debugging only)"), |
| 72 | cl::init(true)); |
| 73 | |
Benjamin Kramer | 0861f57 | 2011-11-26 23:01:57 +0000 | [diff] [blame] | 74 | namespace { |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 75 | class ARMCCState : public CCState { |
| 76 | public: |
| 77 | ARMCCState(CallingConv::ID CC, bool isVarArg, MachineFunction &MF, |
| 78 | const TargetMachine &TM, SmallVector<CCValAssign, 16> &locs, |
| 79 | LLVMContext &C, ParmContext PC) |
| 80 | : CCState(CC, isVarArg, MF, TM, locs, C) { |
| 81 | assert(((PC == Call) || (PC == Prologue)) && |
| 82 | "ARMCCState users must specify whether their context is call" |
| 83 | "or prologue generation."); |
| 84 | CallOrPrologue = PC; |
| 85 | } |
| 86 | }; |
| 87 | } |
| 88 | |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 89 | // The APCS parameter registers. |
| 90 | static const unsigned GPRArgRegs[] = { |
| 91 | ARM::R0, ARM::R1, ARM::R2, ARM::R3 |
| 92 | }; |
| 93 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 94 | void ARMTargetLowering::addTypeForNEON(EVT VT, EVT PromotedLdStVT, |
| 95 | EVT PromotedBitwiseVT) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 96 | if (VT != PromotedLdStVT) { |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 97 | setOperationAction(ISD::LOAD, VT.getSimpleVT(), Promote); |
Owen Anderson | d6662ad | 2009-08-10 20:46:15 +0000 | [diff] [blame] | 98 | AddPromotedToType (ISD::LOAD, VT.getSimpleVT(), |
| 99 | PromotedLdStVT.getSimpleVT()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 100 | |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 101 | setOperationAction(ISD::STORE, VT.getSimpleVT(), Promote); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 102 | AddPromotedToType (ISD::STORE, VT.getSimpleVT(), |
Owen Anderson | d6662ad | 2009-08-10 20:46:15 +0000 | [diff] [blame] | 103 | PromotedLdStVT.getSimpleVT()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 104 | } |
| 105 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 106 | EVT ElemTy = VT.getVectorElementType(); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 107 | if (ElemTy != MVT::i64 && ElemTy != MVT::f64) |
Duncan Sands | 28b77e9 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 108 | setOperationAction(ISD::SETCC, VT.getSimpleVT(), Custom); |
Eli Friedman | 5c89cb8 | 2011-10-24 23:08:52 +0000 | [diff] [blame] | 109 | setOperationAction(ISD::INSERT_VECTOR_ELT, VT.getSimpleVT(), Custom); |
Bob Wilson | 3468c2e | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 110 | setOperationAction(ISD::EXTRACT_VECTOR_ELT, VT.getSimpleVT(), Custom); |
Eli Friedman | 14e809c | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 111 | if (ElemTy == MVT::i32) { |
| 112 | setOperationAction(ISD::SINT_TO_FP, VT.getSimpleVT(), Custom); |
| 113 | setOperationAction(ISD::UINT_TO_FP, VT.getSimpleVT(), Custom); |
| 114 | setOperationAction(ISD::FP_TO_SINT, VT.getSimpleVT(), Custom); |
| 115 | setOperationAction(ISD::FP_TO_UINT, VT.getSimpleVT(), Custom); |
| 116 | } else { |
Bob Wilson | 0696fdf | 2009-09-16 20:20:44 +0000 | [diff] [blame] | 117 | setOperationAction(ISD::SINT_TO_FP, VT.getSimpleVT(), Expand); |
| 118 | setOperationAction(ISD::UINT_TO_FP, VT.getSimpleVT(), Expand); |
| 119 | setOperationAction(ISD::FP_TO_SINT, VT.getSimpleVT(), Expand); |
| 120 | setOperationAction(ISD::FP_TO_UINT, VT.getSimpleVT(), Expand); |
| 121 | } |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 122 | setOperationAction(ISD::BUILD_VECTOR, VT.getSimpleVT(), Custom); |
| 123 | setOperationAction(ISD::VECTOR_SHUFFLE, VT.getSimpleVT(), Custom); |
Bob Wilson | 07f6e80 | 2010-06-16 21:34:01 +0000 | [diff] [blame] | 124 | setOperationAction(ISD::CONCAT_VECTORS, VT.getSimpleVT(), Legal); |
Bob Wilson | 5e8b833 | 2011-01-07 04:59:04 +0000 | [diff] [blame] | 125 | setOperationAction(ISD::EXTRACT_SUBVECTOR, VT.getSimpleVT(), Legal); |
Bob Wilson | d0910c4 | 2010-04-06 22:02:24 +0000 | [diff] [blame] | 126 | setOperationAction(ISD::SELECT, VT.getSimpleVT(), Expand); |
| 127 | setOperationAction(ISD::SELECT_CC, VT.getSimpleVT(), Expand); |
Eli Friedman | 15f58c5 | 2011-11-11 03:16:38 +0000 | [diff] [blame] | 128 | setOperationAction(ISD::SIGN_EXTEND_INREG, VT.getSimpleVT(), Expand); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 129 | if (VT.isInteger()) { |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 130 | setOperationAction(ISD::SHL, VT.getSimpleVT(), Custom); |
| 131 | setOperationAction(ISD::SRA, VT.getSimpleVT(), Custom); |
| 132 | setOperationAction(ISD::SRL, VT.getSimpleVT(), Custom); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | // Promote all bit-wise operations. |
| 136 | if (VT.isInteger() && VT != PromotedBitwiseVT) { |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 137 | setOperationAction(ISD::AND, VT.getSimpleVT(), Promote); |
Owen Anderson | d6662ad | 2009-08-10 20:46:15 +0000 | [diff] [blame] | 138 | AddPromotedToType (ISD::AND, VT.getSimpleVT(), |
| 139 | PromotedBitwiseVT.getSimpleVT()); |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 140 | setOperationAction(ISD::OR, VT.getSimpleVT(), Promote); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 141 | AddPromotedToType (ISD::OR, VT.getSimpleVT(), |
Owen Anderson | d6662ad | 2009-08-10 20:46:15 +0000 | [diff] [blame] | 142 | PromotedBitwiseVT.getSimpleVT()); |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 143 | setOperationAction(ISD::XOR, VT.getSimpleVT(), Promote); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 144 | AddPromotedToType (ISD::XOR, VT.getSimpleVT(), |
Owen Anderson | d6662ad | 2009-08-10 20:46:15 +0000 | [diff] [blame] | 145 | PromotedBitwiseVT.getSimpleVT()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 146 | } |
Bob Wilson | 1633076 | 2009-09-16 00:17:28 +0000 | [diff] [blame] | 147 | |
| 148 | // Neon does not support vector divide/remainder operations. |
| 149 | setOperationAction(ISD::SDIV, VT.getSimpleVT(), Expand); |
| 150 | setOperationAction(ISD::UDIV, VT.getSimpleVT(), Expand); |
| 151 | setOperationAction(ISD::FDIV, VT.getSimpleVT(), Expand); |
| 152 | setOperationAction(ISD::SREM, VT.getSimpleVT(), Expand); |
| 153 | setOperationAction(ISD::UREM, VT.getSimpleVT(), Expand); |
| 154 | setOperationAction(ISD::FREM, VT.getSimpleVT(), Expand); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 155 | } |
| 156 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 157 | void ARMTargetLowering::addDRTypeForNEON(EVT VT) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 158 | addRegisterClass(VT, ARM::DPRRegisterClass); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 159 | addTypeForNEON(VT, MVT::f64, MVT::v2i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 160 | } |
| 161 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 162 | void ARMTargetLowering::addQRTypeForNEON(EVT VT) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 163 | addRegisterClass(VT, ARM::QPRRegisterClass); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 164 | addTypeForNEON(VT, MVT::v2f64, MVT::v4i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 165 | } |
| 166 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 167 | static TargetLoweringObjectFile *createTLOF(TargetMachine &TM) { |
| 168 | if (TM.getSubtarget<ARMSubtarget>().isTargetDarwin()) |
Bill Wendling | 505ad8b | 2010-03-15 21:09:38 +0000 | [diff] [blame] | 169 | return new TargetLoweringObjectFileMachO(); |
Bill Wendling | 94a1c63 | 2010-03-09 02:46:12 +0000 | [diff] [blame] | 170 | |
Chris Lattner | 80ec279 | 2009-08-02 00:34:36 +0000 | [diff] [blame] | 171 | return new ARMElfTargetObjectFile(); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 172 | } |
| 173 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 174 | ARMTargetLowering::ARMTargetLowering(TargetMachine &TM) |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 175 | : TargetLowering(TM, createTLOF(TM)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 176 | Subtarget = &TM.getSubtarget<ARMSubtarget>(); |
Evan Cheng | 3144687 | 2010-07-23 22:39:59 +0000 | [diff] [blame] | 177 | RegInfo = TM.getRegisterInfo(); |
Evan Cheng | 3ef1c87 | 2010-09-10 01:29:16 +0000 | [diff] [blame] | 178 | Itins = TM.getInstrItineraryData(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 179 | |
Duncan Sands | 28b77e9 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 180 | setBooleanVectorContents(ZeroOrNegativeOneBooleanContent); |
| 181 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 182 | if (Subtarget->isTargetDarwin()) { |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 183 | // Uses VFP for Thumb libfuncs if available. |
| 184 | if (Subtarget->isThumb() && Subtarget->hasVFP2()) { |
| 185 | // Single-precision floating-point arithmetic. |
| 186 | setLibcallName(RTLIB::ADD_F32, "__addsf3vfp"); |
| 187 | setLibcallName(RTLIB::SUB_F32, "__subsf3vfp"); |
| 188 | setLibcallName(RTLIB::MUL_F32, "__mulsf3vfp"); |
| 189 | setLibcallName(RTLIB::DIV_F32, "__divsf3vfp"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 190 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 191 | // Double-precision floating-point arithmetic. |
| 192 | setLibcallName(RTLIB::ADD_F64, "__adddf3vfp"); |
| 193 | setLibcallName(RTLIB::SUB_F64, "__subdf3vfp"); |
| 194 | setLibcallName(RTLIB::MUL_F64, "__muldf3vfp"); |
| 195 | setLibcallName(RTLIB::DIV_F64, "__divdf3vfp"); |
Evan Cheng | 193f850 | 2007-01-31 09:30:58 +0000 | [diff] [blame] | 196 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 197 | // Single-precision comparisons. |
| 198 | setLibcallName(RTLIB::OEQ_F32, "__eqsf2vfp"); |
| 199 | setLibcallName(RTLIB::UNE_F32, "__nesf2vfp"); |
| 200 | setLibcallName(RTLIB::OLT_F32, "__ltsf2vfp"); |
| 201 | setLibcallName(RTLIB::OLE_F32, "__lesf2vfp"); |
| 202 | setLibcallName(RTLIB::OGE_F32, "__gesf2vfp"); |
| 203 | setLibcallName(RTLIB::OGT_F32, "__gtsf2vfp"); |
| 204 | setLibcallName(RTLIB::UO_F32, "__unordsf2vfp"); |
| 205 | setLibcallName(RTLIB::O_F32, "__unordsf2vfp"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 206 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 207 | setCmpLibcallCC(RTLIB::OEQ_F32, ISD::SETNE); |
| 208 | setCmpLibcallCC(RTLIB::UNE_F32, ISD::SETNE); |
| 209 | setCmpLibcallCC(RTLIB::OLT_F32, ISD::SETNE); |
| 210 | setCmpLibcallCC(RTLIB::OLE_F32, ISD::SETNE); |
| 211 | setCmpLibcallCC(RTLIB::OGE_F32, ISD::SETNE); |
| 212 | setCmpLibcallCC(RTLIB::OGT_F32, ISD::SETNE); |
| 213 | setCmpLibcallCC(RTLIB::UO_F32, ISD::SETNE); |
| 214 | setCmpLibcallCC(RTLIB::O_F32, ISD::SETEQ); |
Evan Cheng | 193f850 | 2007-01-31 09:30:58 +0000 | [diff] [blame] | 215 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 216 | // Double-precision comparisons. |
| 217 | setLibcallName(RTLIB::OEQ_F64, "__eqdf2vfp"); |
| 218 | setLibcallName(RTLIB::UNE_F64, "__nedf2vfp"); |
| 219 | setLibcallName(RTLIB::OLT_F64, "__ltdf2vfp"); |
| 220 | setLibcallName(RTLIB::OLE_F64, "__ledf2vfp"); |
| 221 | setLibcallName(RTLIB::OGE_F64, "__gedf2vfp"); |
| 222 | setLibcallName(RTLIB::OGT_F64, "__gtdf2vfp"); |
| 223 | setLibcallName(RTLIB::UO_F64, "__unorddf2vfp"); |
| 224 | setLibcallName(RTLIB::O_F64, "__unorddf2vfp"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 225 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 226 | setCmpLibcallCC(RTLIB::OEQ_F64, ISD::SETNE); |
| 227 | setCmpLibcallCC(RTLIB::UNE_F64, ISD::SETNE); |
| 228 | setCmpLibcallCC(RTLIB::OLT_F64, ISD::SETNE); |
| 229 | setCmpLibcallCC(RTLIB::OLE_F64, ISD::SETNE); |
| 230 | setCmpLibcallCC(RTLIB::OGE_F64, ISD::SETNE); |
| 231 | setCmpLibcallCC(RTLIB::OGT_F64, ISD::SETNE); |
| 232 | setCmpLibcallCC(RTLIB::UO_F64, ISD::SETNE); |
| 233 | setCmpLibcallCC(RTLIB::O_F64, ISD::SETEQ); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 234 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 235 | // Floating-point to integer conversions. |
| 236 | // i64 conversions are done via library routines even when generating VFP |
| 237 | // instructions, so use the same ones. |
| 238 | setLibcallName(RTLIB::FPTOSINT_F64_I32, "__fixdfsivfp"); |
| 239 | setLibcallName(RTLIB::FPTOUINT_F64_I32, "__fixunsdfsivfp"); |
| 240 | setLibcallName(RTLIB::FPTOSINT_F32_I32, "__fixsfsivfp"); |
| 241 | setLibcallName(RTLIB::FPTOUINT_F32_I32, "__fixunssfsivfp"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 242 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 243 | // Conversions between floating types. |
| 244 | setLibcallName(RTLIB::FPROUND_F64_F32, "__truncdfsf2vfp"); |
| 245 | setLibcallName(RTLIB::FPEXT_F32_F64, "__extendsfdf2vfp"); |
| 246 | |
| 247 | // Integer to floating-point conversions. |
| 248 | // i64 conversions are done via library routines even when generating VFP |
| 249 | // instructions, so use the same ones. |
Bob Wilson | 2a14c52 | 2009-03-20 23:16:43 +0000 | [diff] [blame] | 250 | // FIXME: There appears to be some naming inconsistency in ARM libgcc: |
| 251 | // e.g., __floatunsidf vs. __floatunssidfvfp. |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 252 | setLibcallName(RTLIB::SINTTOFP_I32_F64, "__floatsidfvfp"); |
| 253 | setLibcallName(RTLIB::UINTTOFP_I32_F64, "__floatunssidfvfp"); |
| 254 | setLibcallName(RTLIB::SINTTOFP_I32_F32, "__floatsisfvfp"); |
| 255 | setLibcallName(RTLIB::UINTTOFP_I32_F32, "__floatunssisfvfp"); |
| 256 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 257 | } |
| 258 | |
Bob Wilson | 2f95461 | 2009-05-22 17:38:41 +0000 | [diff] [blame] | 259 | // These libcalls are not available in 32-bit. |
| 260 | setLibcallName(RTLIB::SHL_I128, 0); |
| 261 | setLibcallName(RTLIB::SRL_I128, 0); |
| 262 | setLibcallName(RTLIB::SRA_I128, 0); |
| 263 | |
Evan Cheng | 0704327 | 2012-02-21 20:46:00 +0000 | [diff] [blame] | 264 | if (Subtarget->isAAPCS_ABI() && !Subtarget->isTargetDarwin()) { |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 265 | // Double-precision floating-point arithmetic helper functions |
Anton Korobeynikov | 4f922f2 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 266 | // RTABI chapter 4.1.2, Table 2 |
| 267 | setLibcallName(RTLIB::ADD_F64, "__aeabi_dadd"); |
| 268 | setLibcallName(RTLIB::DIV_F64, "__aeabi_ddiv"); |
| 269 | setLibcallName(RTLIB::MUL_F64, "__aeabi_dmul"); |
| 270 | setLibcallName(RTLIB::SUB_F64, "__aeabi_dsub"); |
| 271 | setLibcallCallingConv(RTLIB::ADD_F64, CallingConv::ARM_AAPCS); |
| 272 | setLibcallCallingConv(RTLIB::DIV_F64, CallingConv::ARM_AAPCS); |
| 273 | setLibcallCallingConv(RTLIB::MUL_F64, CallingConv::ARM_AAPCS); |
| 274 | setLibcallCallingConv(RTLIB::SUB_F64, CallingConv::ARM_AAPCS); |
| 275 | |
| 276 | // Double-precision floating-point comparison helper functions |
| 277 | // RTABI chapter 4.1.2, Table 3 |
| 278 | setLibcallName(RTLIB::OEQ_F64, "__aeabi_dcmpeq"); |
| 279 | setCmpLibcallCC(RTLIB::OEQ_F64, ISD::SETNE); |
| 280 | setLibcallName(RTLIB::UNE_F64, "__aeabi_dcmpeq"); |
| 281 | setCmpLibcallCC(RTLIB::UNE_F64, ISD::SETEQ); |
| 282 | setLibcallName(RTLIB::OLT_F64, "__aeabi_dcmplt"); |
| 283 | setCmpLibcallCC(RTLIB::OLT_F64, ISD::SETNE); |
| 284 | setLibcallName(RTLIB::OLE_F64, "__aeabi_dcmple"); |
| 285 | setCmpLibcallCC(RTLIB::OLE_F64, ISD::SETNE); |
| 286 | setLibcallName(RTLIB::OGE_F64, "__aeabi_dcmpge"); |
| 287 | setCmpLibcallCC(RTLIB::OGE_F64, ISD::SETNE); |
| 288 | setLibcallName(RTLIB::OGT_F64, "__aeabi_dcmpgt"); |
| 289 | setCmpLibcallCC(RTLIB::OGT_F64, ISD::SETNE); |
| 290 | setLibcallName(RTLIB::UO_F64, "__aeabi_dcmpun"); |
| 291 | setCmpLibcallCC(RTLIB::UO_F64, ISD::SETNE); |
| 292 | setLibcallName(RTLIB::O_F64, "__aeabi_dcmpun"); |
| 293 | setCmpLibcallCC(RTLIB::O_F64, ISD::SETEQ); |
| 294 | setLibcallCallingConv(RTLIB::OEQ_F64, CallingConv::ARM_AAPCS); |
| 295 | setLibcallCallingConv(RTLIB::UNE_F64, CallingConv::ARM_AAPCS); |
| 296 | setLibcallCallingConv(RTLIB::OLT_F64, CallingConv::ARM_AAPCS); |
| 297 | setLibcallCallingConv(RTLIB::OLE_F64, CallingConv::ARM_AAPCS); |
| 298 | setLibcallCallingConv(RTLIB::OGE_F64, CallingConv::ARM_AAPCS); |
| 299 | setLibcallCallingConv(RTLIB::OGT_F64, CallingConv::ARM_AAPCS); |
| 300 | setLibcallCallingConv(RTLIB::UO_F64, CallingConv::ARM_AAPCS); |
| 301 | setLibcallCallingConv(RTLIB::O_F64, CallingConv::ARM_AAPCS); |
| 302 | |
| 303 | // Single-precision floating-point arithmetic helper functions |
| 304 | // RTABI chapter 4.1.2, Table 4 |
| 305 | setLibcallName(RTLIB::ADD_F32, "__aeabi_fadd"); |
| 306 | setLibcallName(RTLIB::DIV_F32, "__aeabi_fdiv"); |
| 307 | setLibcallName(RTLIB::MUL_F32, "__aeabi_fmul"); |
| 308 | setLibcallName(RTLIB::SUB_F32, "__aeabi_fsub"); |
| 309 | setLibcallCallingConv(RTLIB::ADD_F32, CallingConv::ARM_AAPCS); |
| 310 | setLibcallCallingConv(RTLIB::DIV_F32, CallingConv::ARM_AAPCS); |
| 311 | setLibcallCallingConv(RTLIB::MUL_F32, CallingConv::ARM_AAPCS); |
| 312 | setLibcallCallingConv(RTLIB::SUB_F32, CallingConv::ARM_AAPCS); |
| 313 | |
| 314 | // Single-precision floating-point comparison helper functions |
| 315 | // RTABI chapter 4.1.2, Table 5 |
| 316 | setLibcallName(RTLIB::OEQ_F32, "__aeabi_fcmpeq"); |
| 317 | setCmpLibcallCC(RTLIB::OEQ_F32, ISD::SETNE); |
| 318 | setLibcallName(RTLIB::UNE_F32, "__aeabi_fcmpeq"); |
| 319 | setCmpLibcallCC(RTLIB::UNE_F32, ISD::SETEQ); |
| 320 | setLibcallName(RTLIB::OLT_F32, "__aeabi_fcmplt"); |
| 321 | setCmpLibcallCC(RTLIB::OLT_F32, ISD::SETNE); |
| 322 | setLibcallName(RTLIB::OLE_F32, "__aeabi_fcmple"); |
| 323 | setCmpLibcallCC(RTLIB::OLE_F32, ISD::SETNE); |
| 324 | setLibcallName(RTLIB::OGE_F32, "__aeabi_fcmpge"); |
| 325 | setCmpLibcallCC(RTLIB::OGE_F32, ISD::SETNE); |
| 326 | setLibcallName(RTLIB::OGT_F32, "__aeabi_fcmpgt"); |
| 327 | setCmpLibcallCC(RTLIB::OGT_F32, ISD::SETNE); |
| 328 | setLibcallName(RTLIB::UO_F32, "__aeabi_fcmpun"); |
| 329 | setCmpLibcallCC(RTLIB::UO_F32, ISD::SETNE); |
| 330 | setLibcallName(RTLIB::O_F32, "__aeabi_fcmpun"); |
| 331 | setCmpLibcallCC(RTLIB::O_F32, ISD::SETEQ); |
| 332 | setLibcallCallingConv(RTLIB::OEQ_F32, CallingConv::ARM_AAPCS); |
| 333 | setLibcallCallingConv(RTLIB::UNE_F32, CallingConv::ARM_AAPCS); |
| 334 | setLibcallCallingConv(RTLIB::OLT_F32, CallingConv::ARM_AAPCS); |
| 335 | setLibcallCallingConv(RTLIB::OLE_F32, CallingConv::ARM_AAPCS); |
| 336 | setLibcallCallingConv(RTLIB::OGE_F32, CallingConv::ARM_AAPCS); |
| 337 | setLibcallCallingConv(RTLIB::OGT_F32, CallingConv::ARM_AAPCS); |
| 338 | setLibcallCallingConv(RTLIB::UO_F32, CallingConv::ARM_AAPCS); |
| 339 | setLibcallCallingConv(RTLIB::O_F32, CallingConv::ARM_AAPCS); |
| 340 | |
| 341 | // Floating-point to integer conversions. |
| 342 | // RTABI chapter 4.1.2, Table 6 |
| 343 | setLibcallName(RTLIB::FPTOSINT_F64_I32, "__aeabi_d2iz"); |
| 344 | setLibcallName(RTLIB::FPTOUINT_F64_I32, "__aeabi_d2uiz"); |
| 345 | setLibcallName(RTLIB::FPTOSINT_F64_I64, "__aeabi_d2lz"); |
| 346 | setLibcallName(RTLIB::FPTOUINT_F64_I64, "__aeabi_d2ulz"); |
| 347 | setLibcallName(RTLIB::FPTOSINT_F32_I32, "__aeabi_f2iz"); |
| 348 | setLibcallName(RTLIB::FPTOUINT_F32_I32, "__aeabi_f2uiz"); |
| 349 | setLibcallName(RTLIB::FPTOSINT_F32_I64, "__aeabi_f2lz"); |
| 350 | setLibcallName(RTLIB::FPTOUINT_F32_I64, "__aeabi_f2ulz"); |
| 351 | setLibcallCallingConv(RTLIB::FPTOSINT_F64_I32, CallingConv::ARM_AAPCS); |
| 352 | setLibcallCallingConv(RTLIB::FPTOUINT_F64_I32, CallingConv::ARM_AAPCS); |
| 353 | setLibcallCallingConv(RTLIB::FPTOSINT_F64_I64, CallingConv::ARM_AAPCS); |
| 354 | setLibcallCallingConv(RTLIB::FPTOUINT_F64_I64, CallingConv::ARM_AAPCS); |
| 355 | setLibcallCallingConv(RTLIB::FPTOSINT_F32_I32, CallingConv::ARM_AAPCS); |
| 356 | setLibcallCallingConv(RTLIB::FPTOUINT_F32_I32, CallingConv::ARM_AAPCS); |
| 357 | setLibcallCallingConv(RTLIB::FPTOSINT_F32_I64, CallingConv::ARM_AAPCS); |
| 358 | setLibcallCallingConv(RTLIB::FPTOUINT_F32_I64, CallingConv::ARM_AAPCS); |
| 359 | |
| 360 | // Conversions between floating types. |
| 361 | // RTABI chapter 4.1.2, Table 7 |
| 362 | setLibcallName(RTLIB::FPROUND_F64_F32, "__aeabi_d2f"); |
| 363 | setLibcallName(RTLIB::FPEXT_F32_F64, "__aeabi_f2d"); |
| 364 | setLibcallCallingConv(RTLIB::FPROUND_F64_F32, CallingConv::ARM_AAPCS); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 365 | setLibcallCallingConv(RTLIB::FPEXT_F32_F64, CallingConv::ARM_AAPCS); |
Anton Korobeynikov | 4f922f2 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 366 | |
| 367 | // Integer to floating-point conversions. |
| 368 | // RTABI chapter 4.1.2, Table 8 |
| 369 | setLibcallName(RTLIB::SINTTOFP_I32_F64, "__aeabi_i2d"); |
| 370 | setLibcallName(RTLIB::UINTTOFP_I32_F64, "__aeabi_ui2d"); |
| 371 | setLibcallName(RTLIB::SINTTOFP_I64_F64, "__aeabi_l2d"); |
| 372 | setLibcallName(RTLIB::UINTTOFP_I64_F64, "__aeabi_ul2d"); |
| 373 | setLibcallName(RTLIB::SINTTOFP_I32_F32, "__aeabi_i2f"); |
| 374 | setLibcallName(RTLIB::UINTTOFP_I32_F32, "__aeabi_ui2f"); |
| 375 | setLibcallName(RTLIB::SINTTOFP_I64_F32, "__aeabi_l2f"); |
| 376 | setLibcallName(RTLIB::UINTTOFP_I64_F32, "__aeabi_ul2f"); |
| 377 | setLibcallCallingConv(RTLIB::SINTTOFP_I32_F64, CallingConv::ARM_AAPCS); |
| 378 | setLibcallCallingConv(RTLIB::UINTTOFP_I32_F64, CallingConv::ARM_AAPCS); |
| 379 | setLibcallCallingConv(RTLIB::SINTTOFP_I64_F64, CallingConv::ARM_AAPCS); |
| 380 | setLibcallCallingConv(RTLIB::UINTTOFP_I64_F64, CallingConv::ARM_AAPCS); |
| 381 | setLibcallCallingConv(RTLIB::SINTTOFP_I32_F32, CallingConv::ARM_AAPCS); |
| 382 | setLibcallCallingConv(RTLIB::UINTTOFP_I32_F32, CallingConv::ARM_AAPCS); |
| 383 | setLibcallCallingConv(RTLIB::SINTTOFP_I64_F32, CallingConv::ARM_AAPCS); |
| 384 | setLibcallCallingConv(RTLIB::UINTTOFP_I64_F32, CallingConv::ARM_AAPCS); |
| 385 | |
| 386 | // Long long helper functions |
| 387 | // RTABI chapter 4.2, Table 9 |
| 388 | setLibcallName(RTLIB::MUL_I64, "__aeabi_lmul"); |
Anton Korobeynikov | 4f922f2 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 389 | setLibcallName(RTLIB::SHL_I64, "__aeabi_llsl"); |
| 390 | setLibcallName(RTLIB::SRL_I64, "__aeabi_llsr"); |
| 391 | setLibcallName(RTLIB::SRA_I64, "__aeabi_lasr"); |
| 392 | setLibcallCallingConv(RTLIB::MUL_I64, CallingConv::ARM_AAPCS); |
| 393 | setLibcallCallingConv(RTLIB::SDIV_I64, CallingConv::ARM_AAPCS); |
| 394 | setLibcallCallingConv(RTLIB::UDIV_I64, CallingConv::ARM_AAPCS); |
| 395 | setLibcallCallingConv(RTLIB::SHL_I64, CallingConv::ARM_AAPCS); |
| 396 | setLibcallCallingConv(RTLIB::SRL_I64, CallingConv::ARM_AAPCS); |
| 397 | setLibcallCallingConv(RTLIB::SRA_I64, CallingConv::ARM_AAPCS); |
| 398 | |
| 399 | // Integer division functions |
| 400 | // RTABI chapter 4.3.1 |
| 401 | setLibcallName(RTLIB::SDIV_I8, "__aeabi_idiv"); |
| 402 | setLibcallName(RTLIB::SDIV_I16, "__aeabi_idiv"); |
| 403 | setLibcallName(RTLIB::SDIV_I32, "__aeabi_idiv"); |
Anton Korobeynikov | 6edd588 | 2012-01-29 09:11:50 +0000 | [diff] [blame] | 404 | setLibcallName(RTLIB::SDIV_I64, "__aeabi_ldivmod"); |
Anton Korobeynikov | 4f922f2 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 405 | setLibcallName(RTLIB::UDIV_I8, "__aeabi_uidiv"); |
| 406 | setLibcallName(RTLIB::UDIV_I16, "__aeabi_uidiv"); |
| 407 | setLibcallName(RTLIB::UDIV_I32, "__aeabi_uidiv"); |
Anton Korobeynikov | 6edd588 | 2012-01-29 09:11:50 +0000 | [diff] [blame] | 408 | setLibcallName(RTLIB::UDIV_I64, "__aeabi_uldivmod"); |
Anton Korobeynikov | 4f922f2 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 409 | setLibcallCallingConv(RTLIB::SDIV_I8, CallingConv::ARM_AAPCS); |
| 410 | setLibcallCallingConv(RTLIB::SDIV_I16, CallingConv::ARM_AAPCS); |
| 411 | setLibcallCallingConv(RTLIB::SDIV_I32, CallingConv::ARM_AAPCS); |
Anton Korobeynikov | 6edd588 | 2012-01-29 09:11:50 +0000 | [diff] [blame] | 412 | setLibcallCallingConv(RTLIB::SDIV_I64, CallingConv::ARM_AAPCS); |
Anton Korobeynikov | 4f922f2 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 413 | setLibcallCallingConv(RTLIB::UDIV_I8, CallingConv::ARM_AAPCS); |
| 414 | setLibcallCallingConv(RTLIB::UDIV_I16, CallingConv::ARM_AAPCS); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 415 | setLibcallCallingConv(RTLIB::UDIV_I32, CallingConv::ARM_AAPCS); |
Anton Korobeynikov | 6edd588 | 2012-01-29 09:11:50 +0000 | [diff] [blame] | 416 | setLibcallCallingConv(RTLIB::UDIV_I64, CallingConv::ARM_AAPCS); |
Renato Golin | 1ec11fb | 2011-05-22 21:41:23 +0000 | [diff] [blame] | 417 | |
| 418 | // Memory operations |
| 419 | // RTABI chapter 4.3.4 |
| 420 | setLibcallName(RTLIB::MEMCPY, "__aeabi_memcpy"); |
| 421 | setLibcallName(RTLIB::MEMMOVE, "__aeabi_memmove"); |
| 422 | setLibcallName(RTLIB::MEMSET, "__aeabi_memset"); |
Anton Korobeynikov | 6edd588 | 2012-01-29 09:11:50 +0000 | [diff] [blame] | 423 | setLibcallCallingConv(RTLIB::MEMCPY, CallingConv::ARM_AAPCS); |
| 424 | setLibcallCallingConv(RTLIB::MEMMOVE, CallingConv::ARM_AAPCS); |
| 425 | setLibcallCallingConv(RTLIB::MEMSET, CallingConv::ARM_AAPCS); |
Anton Korobeynikov | 72977a4 | 2009-08-14 20:10:52 +0000 | [diff] [blame] | 426 | } |
| 427 | |
Bob Wilson | 2fef457 | 2011-10-07 16:59:21 +0000 | [diff] [blame] | 428 | // Use divmod compiler-rt calls for iOS 5.0 and later. |
| 429 | if (Subtarget->getTargetTriple().getOS() == Triple::IOS && |
| 430 | !Subtarget->getTargetTriple().isOSVersionLT(5, 0)) { |
| 431 | setLibcallName(RTLIB::SDIVREM_I32, "__divmodsi4"); |
| 432 | setLibcallName(RTLIB::UDIVREM_I32, "__udivmodsi4"); |
| 433 | } |
| 434 | |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 435 | if (Subtarget->isThumb1Only()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 436 | addRegisterClass(MVT::i32, ARM::tGPRRegisterClass); |
Jim Grosbach | 30eae3c | 2009-04-07 20:34:09 +0000 | [diff] [blame] | 437 | else |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 438 | addRegisterClass(MVT::i32, ARM::GPRRegisterClass); |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 439 | if (!TM.Options.UseSoftFloat && Subtarget->hasVFP2() && |
| 440 | !Subtarget->isThumb1Only()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 441 | addRegisterClass(MVT::f32, ARM::SPRRegisterClass); |
Jim Grosbach | fcba5e6 | 2010-08-11 15:44:15 +0000 | [diff] [blame] | 442 | if (!Subtarget->isFPOnlySP()) |
| 443 | addRegisterClass(MVT::f64, ARM::DPRRegisterClass); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 444 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 445 | setTruncStoreAction(MVT::f64, MVT::f32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 446 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 447 | |
Eli Friedman | 9f1f26a | 2011-11-08 01:43:53 +0000 | [diff] [blame] | 448 | for (unsigned VT = (unsigned)MVT::FIRST_VECTOR_VALUETYPE; |
| 449 | VT <= (unsigned)MVT::LAST_VECTOR_VALUETYPE; ++VT) { |
| 450 | for (unsigned InnerVT = (unsigned)MVT::FIRST_VECTOR_VALUETYPE; |
| 451 | InnerVT <= (unsigned)MVT::LAST_VECTOR_VALUETYPE; ++InnerVT) |
| 452 | setTruncStoreAction((MVT::SimpleValueType)VT, |
| 453 | (MVT::SimpleValueType)InnerVT, Expand); |
| 454 | setLoadExtAction(ISD::SEXTLOAD, (MVT::SimpleValueType)VT, Expand); |
| 455 | setLoadExtAction(ISD::ZEXTLOAD, (MVT::SimpleValueType)VT, Expand); |
| 456 | setLoadExtAction(ISD::EXTLOAD, (MVT::SimpleValueType)VT, Expand); |
| 457 | } |
| 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); |
Stepan Dyatkovskiy | 3e0dc06 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 510 | |
| 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 | |
Cameron Zwarich | 3339084 | 2011-07-08 21:39:21 +0000 | [diff] [blame] | 772 | setOperationAction(ISD::FMA, MVT::f64, Expand); |
| 773 | setOperationAction(ISD::FMA, MVT::f32, Expand); |
| 774 | |
Anton Korobeynikov | bec3dd2 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 775 | // Various VFP goodness |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 776 | if (!TM.Options.UseSoftFloat && !Subtarget->isThumb1Only()) { |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 777 | // int <-> fp are custom expanded into bit_convert + ARMISD ops. |
| 778 | if (Subtarget->hasVFP2()) { |
| 779 | setOperationAction(ISD::SINT_TO_FP, MVT::i32, Custom); |
| 780 | setOperationAction(ISD::UINT_TO_FP, MVT::i32, Custom); |
| 781 | setOperationAction(ISD::FP_TO_UINT, MVT::i32, Custom); |
| 782 | setOperationAction(ISD::FP_TO_SINT, MVT::i32, Custom); |
| 783 | } |
Anton Korobeynikov | bec3dd2 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 784 | // Special handling for half-precision FP. |
Anton Korobeynikov | f0d5007 | 2010-03-18 22:35:37 +0000 | [diff] [blame] | 785 | if (!Subtarget->hasFP16()) { |
| 786 | setOperationAction(ISD::FP16_TO_FP32, MVT::f32, Expand); |
| 787 | setOperationAction(ISD::FP32_TO_FP16, MVT::i32, Expand); |
Anton Korobeynikov | bec3dd2 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 788 | } |
Evan Cheng | 110cf48 | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 789 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 790 | |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 791 | // We have target-specific dag combine patterns for the following nodes: |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 792 | // ARMISD::VMOVRRD - No need to call setTargetDAGCombine |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 793 | setTargetDAGCombine(ISD::ADD); |
| 794 | setTargetDAGCombine(ISD::SUB); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 795 | setTargetDAGCombine(ISD::MUL); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 796 | |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 797 | if (Subtarget->hasV6T2Ops() || Subtarget->hasNEON()) { |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 798 | setTargetDAGCombine(ISD::AND); |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 799 | setTargetDAGCombine(ISD::OR); |
| 800 | setTargetDAGCombine(ISD::XOR); |
| 801 | } |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 802 | |
Evan Cheng | 5fb468a | 2012-02-23 02:58:19 +0000 | [diff] [blame^] | 803 | if (Subtarget->hasV6Ops()) |
| 804 | setTargetDAGCombine(ISD::SRL); |
| 805 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 806 | setStackPointerRegisterToSaveRestore(ARM::SP); |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 807 | |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 808 | if (TM.Options.UseSoftFloat || Subtarget->isThumb1Only() || |
| 809 | !Subtarget->hasVFP2()) |
Evan Cheng | f7d87ee | 2010-05-21 00:43:17 +0000 | [diff] [blame] | 810 | setSchedulingPreference(Sched::RegPressure); |
| 811 | else |
| 812 | setSchedulingPreference(Sched::Hybrid); |
Dale Johannesen | 8dd86c1 | 2007-05-17 21:31:21 +0000 | [diff] [blame] | 813 | |
Evan Cheng | 0521928 | 2011-01-06 06:52:41 +0000 | [diff] [blame] | 814 | //// temporary - rewrite interface to use type |
| 815 | maxStoresPerMemcpy = maxStoresPerMemcpyOptSize = 1; |
Lang Hames | 75757f9 | 2011-10-26 20:56:52 +0000 | [diff] [blame] | 816 | maxStoresPerMemset = 16; |
| 817 | maxStoresPerMemsetOptSize = Subtarget->isTargetDarwin() ? 8 : 4; |
Evan Cheng | f679939 | 2010-06-26 01:52:05 +0000 | [diff] [blame] | 818 | |
Rafael Espindola | cbeeae2 | 2010-07-11 04:01:49 +0000 | [diff] [blame] | 819 | // On ARM arguments smaller than 4 bytes are extended, so all arguments |
| 820 | // are at least 4 bytes aligned. |
| 821 | setMinStackArgumentAlignment(4); |
| 822 | |
Evan Cheng | fff606d | 2010-09-24 19:07:23 +0000 | [diff] [blame] | 823 | benefitFromCodePlacementOpt = true; |
Eli Friedman | fc5d305 | 2011-05-06 20:34:06 +0000 | [diff] [blame] | 824 | |
| 825 | setMinFunctionAlignment(Subtarget->isThumb() ? 1 : 2); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 826 | } |
| 827 | |
Andrew Trick | 32cec0a | 2011-01-19 02:35:27 +0000 | [diff] [blame] | 828 | // FIXME: It might make sense to define the representative register class as the |
| 829 | // nearest super-register that has a non-null superset. For example, DPR_VFP2 is |
| 830 | // a super-register of SPR, and DPR is a superset if DPR_VFP2. Consequently, |
| 831 | // SPR's representative would be DPR_VFP2. This should work well if register |
| 832 | // pressure tracking were modified such that a register use would increment the |
| 833 | // pressure of the register class's representative and all of it's super |
| 834 | // classes' representatives transitively. We have not implemented this because |
| 835 | // of the difficulty prior to coalescing of modeling operand register classes |
Chris Lattner | 7a2bdde | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 836 | // due to the common occurrence of cross class copies and subregister insertions |
Andrew Trick | 32cec0a | 2011-01-19 02:35:27 +0000 | [diff] [blame] | 837 | // and extractions. |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 838 | std::pair<const TargetRegisterClass*, uint8_t> |
| 839 | ARMTargetLowering::findRepresentativeClass(EVT VT) const{ |
| 840 | const TargetRegisterClass *RRC = 0; |
| 841 | uint8_t Cost = 1; |
| 842 | switch (VT.getSimpleVT().SimpleTy) { |
Evan Cheng | d70f57b | 2010-07-19 22:15:08 +0000 | [diff] [blame] | 843 | default: |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 844 | return TargetLowering::findRepresentativeClass(VT); |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 845 | // Use DPR as representative register class for all floating point |
| 846 | // and vector types. Since there are 32 SPR registers and 32 DPR registers so |
| 847 | // the cost is 1 for both f32 and f64. |
| 848 | case MVT::f32: case MVT::f64: case MVT::v8i8: case MVT::v4i16: |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 849 | case MVT::v2i32: case MVT::v1i64: case MVT::v2f32: |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 850 | RRC = ARM::DPRRegisterClass; |
Andrew Trick | 32cec0a | 2011-01-19 02:35:27 +0000 | [diff] [blame] | 851 | // When NEON is used for SP, only half of the register file is available |
| 852 | // because operations that define both SP and DP results will be constrained |
| 853 | // to the VFP2 class (D0-D15). We currently model this constraint prior to |
| 854 | // coalescing by double-counting the SP regs. See the FIXME above. |
| 855 | if (Subtarget->useNEONForSinglePrecisionFP()) |
| 856 | Cost = 2; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 857 | break; |
| 858 | case MVT::v16i8: case MVT::v8i16: case MVT::v4i32: case MVT::v2i64: |
| 859 | case MVT::v4f32: case MVT::v2f64: |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 860 | RRC = ARM::DPRRegisterClass; |
| 861 | Cost = 2; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 862 | break; |
| 863 | case MVT::v4i64: |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 864 | RRC = ARM::DPRRegisterClass; |
| 865 | Cost = 4; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 866 | break; |
| 867 | case MVT::v8i64: |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 868 | RRC = ARM::DPRRegisterClass; |
| 869 | Cost = 8; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 870 | break; |
Evan Cheng | d70f57b | 2010-07-19 22:15:08 +0000 | [diff] [blame] | 871 | } |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 872 | return std::make_pair(RRC, Cost); |
Evan Cheng | d70f57b | 2010-07-19 22:15:08 +0000 | [diff] [blame] | 873 | } |
| 874 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 875 | const char *ARMTargetLowering::getTargetNodeName(unsigned Opcode) const { |
| 876 | switch (Opcode) { |
| 877 | default: return 0; |
| 878 | case ARMISD::Wrapper: return "ARMISD::Wrapper"; |
Evan Cheng | 53519f0 | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 879 | case ARMISD::WrapperDYN: return "ARMISD::WrapperDYN"; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 880 | case ARMISD::WrapperPIC: return "ARMISD::WrapperPIC"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 881 | case ARMISD::WrapperJT: return "ARMISD::WrapperJT"; |
| 882 | case ARMISD::CALL: return "ARMISD::CALL"; |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 883 | case ARMISD::CALL_PRED: return "ARMISD::CALL_PRED"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 884 | case ARMISD::CALL_NOLINK: return "ARMISD::CALL_NOLINK"; |
| 885 | case ARMISD::tCALL: return "ARMISD::tCALL"; |
| 886 | case ARMISD::BRCOND: return "ARMISD::BRCOND"; |
| 887 | case ARMISD::BR_JT: return "ARMISD::BR_JT"; |
Evan Cheng | 5657c01 | 2009-07-29 02:18:14 +0000 | [diff] [blame] | 888 | case ARMISD::BR2_JT: return "ARMISD::BR2_JT"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 889 | case ARMISD::RET_FLAG: return "ARMISD::RET_FLAG"; |
| 890 | case ARMISD::PIC_ADD: return "ARMISD::PIC_ADD"; |
| 891 | case ARMISD::CMP: return "ARMISD::CMP"; |
David Goodwin | c0309b4 | 2009-06-29 15:33:01 +0000 | [diff] [blame] | 892 | case ARMISD::CMPZ: return "ARMISD::CMPZ"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 893 | case ARMISD::CMPFP: return "ARMISD::CMPFP"; |
| 894 | case ARMISD::CMPFPw0: return "ARMISD::CMPFPw0"; |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 895 | case ARMISD::BCC_i64: return "ARMISD::BCC_i64"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 896 | case ARMISD::FMSTAT: return "ARMISD::FMSTAT"; |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 897 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 898 | case ARMISD::CMOV: return "ARMISD::CMOV"; |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 899 | case ARMISD::CAND: return "ARMISD::CAND"; |
| 900 | case ARMISD::COR: return "ARMISD::COR"; |
| 901 | case ARMISD::CXOR: return "ARMISD::CXOR"; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 902 | |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 903 | case ARMISD::RBIT: return "ARMISD::RBIT"; |
| 904 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 905 | case ARMISD::FTOSI: return "ARMISD::FTOSI"; |
| 906 | case ARMISD::FTOUI: return "ARMISD::FTOUI"; |
| 907 | case ARMISD::SITOF: return "ARMISD::SITOF"; |
| 908 | case ARMISD::UITOF: return "ARMISD::UITOF"; |
| 909 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 910 | case ARMISD::SRL_FLAG: return "ARMISD::SRL_FLAG"; |
| 911 | case ARMISD::SRA_FLAG: return "ARMISD::SRA_FLAG"; |
| 912 | case ARMISD::RRX: return "ARMISD::RRX"; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 913 | |
Evan Cheng | 342e316 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 914 | case ARMISD::ADDC: return "ARMISD::ADDC"; |
| 915 | case ARMISD::ADDE: return "ARMISD::ADDE"; |
| 916 | case ARMISD::SUBC: return "ARMISD::SUBC"; |
| 917 | case ARMISD::SUBE: return "ARMISD::SUBE"; |
| 918 | |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 919 | case ARMISD::VMOVRRD: return "ARMISD::VMOVRRD"; |
| 920 | case ARMISD::VMOVDRR: return "ARMISD::VMOVDRR"; |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 921 | |
Evan Cheng | c594208 | 2009-10-28 06:55:03 +0000 | [diff] [blame] | 922 | case ARMISD::EH_SJLJ_SETJMP: return "ARMISD::EH_SJLJ_SETJMP"; |
| 923 | case ARMISD::EH_SJLJ_LONGJMP:return "ARMISD::EH_SJLJ_LONGJMP"; |
| 924 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 925 | case ARMISD::TC_RETURN: return "ARMISD::TC_RETURN"; |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 926 | |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 927 | case ARMISD::THREAD_POINTER:return "ARMISD::THREAD_POINTER"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 928 | |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 929 | case ARMISD::DYN_ALLOC: return "ARMISD::DYN_ALLOC"; |
| 930 | |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 931 | case ARMISD::MEMBARRIER: return "ARMISD::MEMBARRIER"; |
Bob Wilson | f74a429 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 932 | case ARMISD::MEMBARRIER_MCR: return "ARMISD::MEMBARRIER_MCR"; |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 933 | |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 934 | case ARMISD::PRELOAD: return "ARMISD::PRELOAD"; |
| 935 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 936 | case ARMISD::VCEQ: return "ARMISD::VCEQ"; |
Bob Wilson | 3a75b9b | 2010-12-18 00:04:26 +0000 | [diff] [blame] | 937 | case ARMISD::VCEQZ: return "ARMISD::VCEQZ"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 938 | case ARMISD::VCGE: return "ARMISD::VCGE"; |
Bob Wilson | 3a75b9b | 2010-12-18 00:04:26 +0000 | [diff] [blame] | 939 | case ARMISD::VCGEZ: return "ARMISD::VCGEZ"; |
| 940 | case ARMISD::VCLEZ: return "ARMISD::VCLEZ"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 941 | case ARMISD::VCGEU: return "ARMISD::VCGEU"; |
| 942 | case ARMISD::VCGT: return "ARMISD::VCGT"; |
Bob Wilson | 3a75b9b | 2010-12-18 00:04:26 +0000 | [diff] [blame] | 943 | case ARMISD::VCGTZ: return "ARMISD::VCGTZ"; |
| 944 | case ARMISD::VCLTZ: return "ARMISD::VCLTZ"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 945 | case ARMISD::VCGTU: return "ARMISD::VCGTU"; |
| 946 | case ARMISD::VTST: return "ARMISD::VTST"; |
| 947 | |
| 948 | case ARMISD::VSHL: return "ARMISD::VSHL"; |
| 949 | case ARMISD::VSHRs: return "ARMISD::VSHRs"; |
| 950 | case ARMISD::VSHRu: return "ARMISD::VSHRu"; |
| 951 | case ARMISD::VSHLLs: return "ARMISD::VSHLLs"; |
| 952 | case ARMISD::VSHLLu: return "ARMISD::VSHLLu"; |
| 953 | case ARMISD::VSHLLi: return "ARMISD::VSHLLi"; |
| 954 | case ARMISD::VSHRN: return "ARMISD::VSHRN"; |
| 955 | case ARMISD::VRSHRs: return "ARMISD::VRSHRs"; |
| 956 | case ARMISD::VRSHRu: return "ARMISD::VRSHRu"; |
| 957 | case ARMISD::VRSHRN: return "ARMISD::VRSHRN"; |
| 958 | case ARMISD::VQSHLs: return "ARMISD::VQSHLs"; |
| 959 | case ARMISD::VQSHLu: return "ARMISD::VQSHLu"; |
| 960 | case ARMISD::VQSHLsu: return "ARMISD::VQSHLsu"; |
| 961 | case ARMISD::VQSHRNs: return "ARMISD::VQSHRNs"; |
| 962 | case ARMISD::VQSHRNu: return "ARMISD::VQSHRNu"; |
| 963 | case ARMISD::VQSHRNsu: return "ARMISD::VQSHRNsu"; |
| 964 | case ARMISD::VQRSHRNs: return "ARMISD::VQRSHRNs"; |
| 965 | case ARMISD::VQRSHRNu: return "ARMISD::VQRSHRNu"; |
| 966 | case ARMISD::VQRSHRNsu: return "ARMISD::VQRSHRNsu"; |
| 967 | case ARMISD::VGETLANEu: return "ARMISD::VGETLANEu"; |
| 968 | case ARMISD::VGETLANEs: return "ARMISD::VGETLANEs"; |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 969 | case ARMISD::VMOVIMM: return "ARMISD::VMOVIMM"; |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 970 | case ARMISD::VMVNIMM: return "ARMISD::VMVNIMM"; |
Evan Cheng | eaa192a | 2011-11-15 02:12:34 +0000 | [diff] [blame] | 971 | case ARMISD::VMOVFPIMM: return "ARMISD::VMOVFPIMM"; |
Bob Wilson | c1d287b | 2009-08-14 05:13:08 +0000 | [diff] [blame] | 972 | case ARMISD::VDUP: return "ARMISD::VDUP"; |
Bob Wilson | 0ce3710 | 2009-08-14 05:08:32 +0000 | [diff] [blame] | 973 | case ARMISD::VDUPLANE: return "ARMISD::VDUPLANE"; |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 974 | case ARMISD::VEXT: return "ARMISD::VEXT"; |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 975 | case ARMISD::VREV64: return "ARMISD::VREV64"; |
| 976 | case ARMISD::VREV32: return "ARMISD::VREV32"; |
| 977 | case ARMISD::VREV16: return "ARMISD::VREV16"; |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 978 | case ARMISD::VZIP: return "ARMISD::VZIP"; |
| 979 | case ARMISD::VUZP: return "ARMISD::VUZP"; |
| 980 | case ARMISD::VTRN: return "ARMISD::VTRN"; |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 981 | case ARMISD::VTBL1: return "ARMISD::VTBL1"; |
| 982 | case ARMISD::VTBL2: return "ARMISD::VTBL2"; |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 983 | case ARMISD::VMULLs: return "ARMISD::VMULLs"; |
| 984 | case ARMISD::VMULLu: return "ARMISD::VMULLu"; |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 985 | case ARMISD::BUILD_VECTOR: return "ARMISD::BUILD_VECTOR"; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 986 | case ARMISD::FMAX: return "ARMISD::FMAX"; |
| 987 | case ARMISD::FMIN: return "ARMISD::FMIN"; |
Jim Grosbach | dd7d28a | 2010-07-17 01:50:57 +0000 | [diff] [blame] | 988 | case ARMISD::BFI: return "ARMISD::BFI"; |
Bob Wilson | 364a72a | 2010-11-28 06:51:11 +0000 | [diff] [blame] | 989 | case ARMISD::VORRIMM: return "ARMISD::VORRIMM"; |
| 990 | case ARMISD::VBICIMM: return "ARMISD::VBICIMM"; |
Cameron Zwarich | c0e6d78 | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 991 | case ARMISD::VBSL: return "ARMISD::VBSL"; |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 992 | case ARMISD::VLD2DUP: return "ARMISD::VLD2DUP"; |
| 993 | case ARMISD::VLD3DUP: return "ARMISD::VLD3DUP"; |
| 994 | case ARMISD::VLD4DUP: return "ARMISD::VLD4DUP"; |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 995 | case ARMISD::VLD1_UPD: return "ARMISD::VLD1_UPD"; |
| 996 | case ARMISD::VLD2_UPD: return "ARMISD::VLD2_UPD"; |
| 997 | case ARMISD::VLD3_UPD: return "ARMISD::VLD3_UPD"; |
| 998 | case ARMISD::VLD4_UPD: return "ARMISD::VLD4_UPD"; |
| 999 | case ARMISD::VLD2LN_UPD: return "ARMISD::VLD2LN_UPD"; |
| 1000 | case ARMISD::VLD3LN_UPD: return "ARMISD::VLD3LN_UPD"; |
| 1001 | case ARMISD::VLD4LN_UPD: return "ARMISD::VLD4LN_UPD"; |
| 1002 | case ARMISD::VLD2DUP_UPD: return "ARMISD::VLD2DUP_UPD"; |
| 1003 | case ARMISD::VLD3DUP_UPD: return "ARMISD::VLD3DUP_UPD"; |
| 1004 | case ARMISD::VLD4DUP_UPD: return "ARMISD::VLD4DUP_UPD"; |
| 1005 | case ARMISD::VST1_UPD: return "ARMISD::VST1_UPD"; |
| 1006 | case ARMISD::VST2_UPD: return "ARMISD::VST2_UPD"; |
| 1007 | case ARMISD::VST3_UPD: return "ARMISD::VST3_UPD"; |
| 1008 | case ARMISD::VST4_UPD: return "ARMISD::VST4_UPD"; |
| 1009 | case ARMISD::VST2LN_UPD: return "ARMISD::VST2LN_UPD"; |
| 1010 | case ARMISD::VST3LN_UPD: return "ARMISD::VST3LN_UPD"; |
| 1011 | case ARMISD::VST4LN_UPD: return "ARMISD::VST4LN_UPD"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1012 | } |
| 1013 | } |
| 1014 | |
Duncan Sands | 28b77e9 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 1015 | EVT ARMTargetLowering::getSetCCResultType(EVT VT) const { |
| 1016 | if (!VT.isVector()) return getPointerTy(); |
| 1017 | return VT.changeVectorElementTypeToInteger(); |
| 1018 | } |
| 1019 | |
Evan Cheng | 06b666c | 2010-05-15 02:18:07 +0000 | [diff] [blame] | 1020 | /// getRegClassFor - Return the register class that should be used for the |
| 1021 | /// specified value type. |
Craig Topper | 44d2382 | 2012-02-22 05:59:10 +0000 | [diff] [blame] | 1022 | const TargetRegisterClass *ARMTargetLowering::getRegClassFor(EVT VT) const { |
Evan Cheng | 06b666c | 2010-05-15 02:18:07 +0000 | [diff] [blame] | 1023 | // Map v4i64 to QQ registers but do not make the type legal. Similarly map |
| 1024 | // v8i64 to QQQQ registers. v4i64 and v8i64 are only used for REG_SEQUENCE to |
| 1025 | // load / store 4 to 8 consecutive D registers. |
Evan Cheng | 4782b1e | 2010-05-15 02:20:21 +0000 | [diff] [blame] | 1026 | if (Subtarget->hasNEON()) { |
| 1027 | if (VT == MVT::v4i64) |
| 1028 | return ARM::QQPRRegisterClass; |
| 1029 | else if (VT == MVT::v8i64) |
| 1030 | return ARM::QQQQPRRegisterClass; |
| 1031 | } |
Evan Cheng | 06b666c | 2010-05-15 02:18:07 +0000 | [diff] [blame] | 1032 | return TargetLowering::getRegClassFor(VT); |
| 1033 | } |
| 1034 | |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 1035 | // Create a fast isel object. |
| 1036 | FastISel * |
| 1037 | ARMTargetLowering::createFastISel(FunctionLoweringInfo &funcInfo) const { |
| 1038 | return ARM::createFastISel(funcInfo); |
| 1039 | } |
| 1040 | |
Anton Korobeynikov | cec36f4 | 2010-07-24 21:52:08 +0000 | [diff] [blame] | 1041 | /// getMaximalGlobalOffset - Returns the maximal possible offset which can |
| 1042 | /// be used for loads / stores from the global. |
| 1043 | unsigned ARMTargetLowering::getMaximalGlobalOffset() const { |
| 1044 | return (Subtarget->isThumb1Only() ? 127 : 4095); |
| 1045 | } |
| 1046 | |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1047 | Sched::Preference ARMTargetLowering::getSchedulingPreference(SDNode *N) const { |
Evan Cheng | c10f543 | 2010-05-28 23:25:23 +0000 | [diff] [blame] | 1048 | unsigned NumVals = N->getNumValues(); |
| 1049 | if (!NumVals) |
| 1050 | return Sched::RegPressure; |
| 1051 | |
| 1052 | for (unsigned i = 0; i != NumVals; ++i) { |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1053 | EVT VT = N->getValueType(i); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 1054 | if (VT == MVT::Glue || VT == MVT::Other) |
Evan Cheng | d7e473c | 2010-10-29 18:07:31 +0000 | [diff] [blame] | 1055 | continue; |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1056 | if (VT.isFloatingPoint() || VT.isVector()) |
Dan Gohman | 692c1d8 | 2011-10-24 17:55:11 +0000 | [diff] [blame] | 1057 | return Sched::ILP; |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1058 | } |
Evan Cheng | c10f543 | 2010-05-28 23:25:23 +0000 | [diff] [blame] | 1059 | |
| 1060 | if (!N->isMachineOpcode()) |
| 1061 | return Sched::RegPressure; |
| 1062 | |
| 1063 | // Load are scheduled for latency even if there instruction itinerary |
| 1064 | // is not available. |
| 1065 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 1066 | const MCInstrDesc &MCID = TII->get(N->getMachineOpcode()); |
Evan Cheng | d7e473c | 2010-10-29 18:07:31 +0000 | [diff] [blame] | 1067 | |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 1068 | if (MCID.getNumDefs() == 0) |
Evan Cheng | d7e473c | 2010-10-29 18:07:31 +0000 | [diff] [blame] | 1069 | return Sched::RegPressure; |
| 1070 | if (!Itins->isEmpty() && |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 1071 | Itins->getOperandCycle(MCID.getSchedClass(), 0) > 2) |
Dan Gohman | 692c1d8 | 2011-10-24 17:55:11 +0000 | [diff] [blame] | 1072 | return Sched::ILP; |
Evan Cheng | c10f543 | 2010-05-28 23:25:23 +0000 | [diff] [blame] | 1073 | |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1074 | return Sched::RegPressure; |
| 1075 | } |
| 1076 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1077 | //===----------------------------------------------------------------------===// |
| 1078 | // Lowering Code |
| 1079 | //===----------------------------------------------------------------------===// |
| 1080 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1081 | /// IntCCToARMCC - Convert a DAG integer condition code to an ARM CC |
| 1082 | static ARMCC::CondCodes IntCCToARMCC(ISD::CondCode CC) { |
| 1083 | switch (CC) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1084 | default: llvm_unreachable("Unknown condition code!"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1085 | case ISD::SETNE: return ARMCC::NE; |
| 1086 | case ISD::SETEQ: return ARMCC::EQ; |
| 1087 | case ISD::SETGT: return ARMCC::GT; |
| 1088 | case ISD::SETGE: return ARMCC::GE; |
| 1089 | case ISD::SETLT: return ARMCC::LT; |
| 1090 | case ISD::SETLE: return ARMCC::LE; |
| 1091 | case ISD::SETUGT: return ARMCC::HI; |
| 1092 | case ISD::SETUGE: return ARMCC::HS; |
| 1093 | case ISD::SETULT: return ARMCC::LO; |
| 1094 | case ISD::SETULE: return ARMCC::LS; |
| 1095 | } |
| 1096 | } |
| 1097 | |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 1098 | /// FPCCToARMCC - Convert a DAG fp condition code to an ARM CC. |
| 1099 | static void FPCCToARMCC(ISD::CondCode CC, ARMCC::CondCodes &CondCode, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1100 | ARMCC::CondCodes &CondCode2) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1101 | CondCode2 = ARMCC::AL; |
| 1102 | switch (CC) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1103 | default: llvm_unreachable("Unknown FP condition!"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1104 | case ISD::SETEQ: |
| 1105 | case ISD::SETOEQ: CondCode = ARMCC::EQ; break; |
| 1106 | case ISD::SETGT: |
| 1107 | case ISD::SETOGT: CondCode = ARMCC::GT; break; |
| 1108 | case ISD::SETGE: |
| 1109 | case ISD::SETOGE: CondCode = ARMCC::GE; break; |
| 1110 | case ISD::SETOLT: CondCode = ARMCC::MI; break; |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 1111 | case ISD::SETOLE: CondCode = ARMCC::LS; break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1112 | case ISD::SETONE: CondCode = ARMCC::MI; CondCode2 = ARMCC::GT; break; |
| 1113 | case ISD::SETO: CondCode = ARMCC::VC; break; |
| 1114 | case ISD::SETUO: CondCode = ARMCC::VS; break; |
| 1115 | case ISD::SETUEQ: CondCode = ARMCC::EQ; CondCode2 = ARMCC::VS; break; |
| 1116 | case ISD::SETUGT: CondCode = ARMCC::HI; break; |
| 1117 | case ISD::SETUGE: CondCode = ARMCC::PL; break; |
| 1118 | case ISD::SETLT: |
| 1119 | case ISD::SETULT: CondCode = ARMCC::LT; break; |
| 1120 | case ISD::SETLE: |
| 1121 | case ISD::SETULE: CondCode = ARMCC::LE; break; |
| 1122 | case ISD::SETNE: |
| 1123 | case ISD::SETUNE: CondCode = ARMCC::NE; break; |
| 1124 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1125 | } |
| 1126 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1127 | //===----------------------------------------------------------------------===// |
| 1128 | // Calling Convention Implementation |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1129 | //===----------------------------------------------------------------------===// |
| 1130 | |
| 1131 | #include "ARMGenCallingConv.inc" |
| 1132 | |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1133 | /// CCAssignFnForNode - Selects the correct CCAssignFn for a the |
| 1134 | /// given CallingConvention value. |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1135 | CCAssignFn *ARMTargetLowering::CCAssignFnForNode(CallingConv::ID CC, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1136 | bool Return, |
| 1137 | bool isVarArg) const { |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1138 | switch (CC) { |
| 1139 | default: |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1140 | llvm_unreachable("Unsupported calling convention"); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1141 | case CallingConv::Fast: |
Evan Cheng | 5c2d428 | 2010-10-23 02:19:37 +0000 | [diff] [blame] | 1142 | if (Subtarget->hasVFP2() && !isVarArg) { |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1143 | if (!Subtarget->isAAPCS_ABI()) |
| 1144 | return (Return ? RetFastCC_ARM_APCS : FastCC_ARM_APCS); |
| 1145 | // For AAPCS ABI targets, just use VFP variant of the calling convention. |
| 1146 | return (Return ? RetCC_ARM_AAPCS_VFP : CC_ARM_AAPCS_VFP); |
| 1147 | } |
| 1148 | // Fallthrough |
| 1149 | case CallingConv::C: { |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1150 | // Use target triple & subtarget features to do actual dispatch. |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1151 | if (!Subtarget->isAAPCS_ABI()) |
| 1152 | return (Return ? RetCC_ARM_APCS : CC_ARM_APCS); |
| 1153 | else if (Subtarget->hasVFP2() && |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 1154 | getTargetMachine().Options.FloatABIType == FloatABI::Hard && |
| 1155 | !isVarArg) |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1156 | return (Return ? RetCC_ARM_AAPCS_VFP : CC_ARM_AAPCS_VFP); |
| 1157 | return (Return ? RetCC_ARM_AAPCS : CC_ARM_AAPCS); |
| 1158 | } |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1159 | case CallingConv::ARM_AAPCS_VFP: |
Anton Korobeynikov | f349cb8 | 2012-01-29 09:06:09 +0000 | [diff] [blame] | 1160 | if (!isVarArg) |
| 1161 | return (Return ? RetCC_ARM_AAPCS_VFP : CC_ARM_AAPCS_VFP); |
| 1162 | // Fallthrough |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1163 | case CallingConv::ARM_AAPCS: |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1164 | return (Return ? RetCC_ARM_AAPCS : CC_ARM_AAPCS); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1165 | case CallingConv::ARM_APCS: |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1166 | return (Return ? RetCC_ARM_APCS : CC_ARM_APCS); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1167 | } |
| 1168 | } |
| 1169 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1170 | /// LowerCallResult - Lower the result values of a call into the |
| 1171 | /// appropriate copies out of appropriate physical registers. |
| 1172 | SDValue |
| 1173 | ARMTargetLowering::LowerCallResult(SDValue Chain, SDValue InFlag, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1174 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1175 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 1176 | DebugLoc dl, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1177 | SmallVectorImpl<SDValue> &InVals) const { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1178 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1179 | // Assign locations to each value returned by this call. |
| 1180 | SmallVector<CCValAssign, 16> RVLocs; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1181 | ARMCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), |
| 1182 | getTargetMachine(), RVLocs, *DAG.getContext(), Call); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1183 | CCInfo.AnalyzeCallResult(Ins, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1184 | CCAssignFnForNode(CallConv, /* Return*/ true, |
| 1185 | isVarArg)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1186 | |
| 1187 | // Copy all of the result registers out of their specified physreg. |
| 1188 | for (unsigned i = 0; i != RVLocs.size(); ++i) { |
| 1189 | CCValAssign VA = RVLocs[i]; |
| 1190 | |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1191 | SDValue Val; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1192 | if (VA.needsCustom()) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1193 | // Handle f64 or half of a v2f64. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1194 | SDValue Lo = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1195 | InFlag); |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1196 | Chain = Lo.getValue(1); |
| 1197 | InFlag = Lo.getValue(2); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1198 | VA = RVLocs[++i]; // skip ahead to next loc |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1199 | SDValue Hi = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1200 | InFlag); |
| 1201 | Chain = Hi.getValue(1); |
| 1202 | InFlag = Hi.getValue(2); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1203 | Val = DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1204 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1205 | if (VA.getLocVT() == MVT::v2f64) { |
| 1206 | SDValue Vec = DAG.getNode(ISD::UNDEF, dl, MVT::v2f64); |
| 1207 | Vec = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Vec, Val, |
| 1208 | DAG.getConstant(0, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1209 | |
| 1210 | VA = RVLocs[++i]; // skip ahead to next loc |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1211 | Lo = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, InFlag); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1212 | Chain = Lo.getValue(1); |
| 1213 | InFlag = Lo.getValue(2); |
| 1214 | VA = RVLocs[++i]; // skip ahead to next loc |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1215 | Hi = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, InFlag); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1216 | Chain = Hi.getValue(1); |
| 1217 | InFlag = Hi.getValue(2); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1218 | Val = DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1219 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Vec, Val, |
| 1220 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1221 | } |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1222 | } else { |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1223 | Val = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), VA.getLocVT(), |
| 1224 | InFlag); |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1225 | Chain = Val.getValue(1); |
| 1226 | InFlag = Val.getValue(2); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1227 | } |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1228 | |
| 1229 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1230 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1231 | case CCValAssign::Full: break; |
| 1232 | case CCValAssign::BCvt: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1233 | Val = DAG.getNode(ISD::BITCAST, dl, VA.getValVT(), Val); |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1234 | break; |
| 1235 | } |
| 1236 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1237 | InVals.push_back(Val); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1238 | } |
| 1239 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1240 | return Chain; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1241 | } |
| 1242 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1243 | /// LowerMemOpCallTo - Store the argument to the stack. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1244 | SDValue |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1245 | ARMTargetLowering::LowerMemOpCallTo(SDValue Chain, |
| 1246 | SDValue StackPtr, SDValue Arg, |
| 1247 | DebugLoc dl, SelectionDAG &DAG, |
| 1248 | const CCValAssign &VA, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1249 | ISD::ArgFlagsTy Flags) const { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1250 | unsigned LocMemOffset = VA.getLocMemOffset(); |
| 1251 | SDValue PtrOff = DAG.getIntPtrConstant(LocMemOffset); |
| 1252 | PtrOff = DAG.getNode(ISD::ADD, dl, getPointerTy(), StackPtr, PtrOff); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1253 | return DAG.getStore(Chain, dl, Arg, PtrOff, |
Chris Lattner | fc448ff | 2010-09-21 18:51:21 +0000 | [diff] [blame] | 1254 | MachinePointerInfo::getStack(LocMemOffset), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1255 | false, false, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1256 | } |
| 1257 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1258 | void ARMTargetLowering::PassF64ArgInRegs(DebugLoc dl, SelectionDAG &DAG, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1259 | SDValue Chain, SDValue &Arg, |
| 1260 | RegsToPassVector &RegsToPass, |
| 1261 | CCValAssign &VA, CCValAssign &NextVA, |
| 1262 | SDValue &StackPtr, |
| 1263 | SmallVector<SDValue, 8> &MemOpChains, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1264 | ISD::ArgFlagsTy Flags) const { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1265 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1266 | SDValue fmrrd = DAG.getNode(ARMISD::VMOVRRD, dl, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1267 | DAG.getVTList(MVT::i32, MVT::i32), Arg); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1268 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), fmrrd)); |
| 1269 | |
| 1270 | if (NextVA.isRegLoc()) |
| 1271 | RegsToPass.push_back(std::make_pair(NextVA.getLocReg(), fmrrd.getValue(1))); |
| 1272 | else { |
| 1273 | assert(NextVA.isMemLoc()); |
| 1274 | if (StackPtr.getNode() == 0) |
| 1275 | StackPtr = DAG.getCopyFromReg(Chain, dl, ARM::SP, getPointerTy()); |
| 1276 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1277 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, fmrrd.getValue(1), |
| 1278 | dl, DAG, NextVA, |
| 1279 | Flags)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1280 | } |
| 1281 | } |
| 1282 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1283 | /// LowerCall - Lowering a call into a callseq_start <- |
Evan Cheng | fc40342 | 2007-02-03 08:53:01 +0000 | [diff] [blame] | 1284 | /// ARMISD:CALL <- callseq_end chain. Also add input and output parameter |
| 1285 | /// nodes. |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1286 | SDValue |
Evan Cheng | 022d9e1 | 2010-02-02 23:55:14 +0000 | [diff] [blame] | 1287 | ARMTargetLowering::LowerCall(SDValue Chain, SDValue Callee, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1288 | CallingConv::ID CallConv, bool isVarArg, |
Evan Cheng | 0c439eb | 2010-01-27 00:07:07 +0000 | [diff] [blame] | 1289 | bool &isTailCall, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1290 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1291 | const SmallVectorImpl<SDValue> &OutVals, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1292 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 1293 | DebugLoc dl, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1294 | SmallVectorImpl<SDValue> &InVals) const { |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1295 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1296 | bool IsStructRet = (Outs.empty()) ? false : Outs[0].Flags.isSRet(); |
| 1297 | bool IsSibCall = false; |
Bob Wilson | 6d2f9ce | 2011-10-07 17:17:49 +0000 | [diff] [blame] | 1298 | // Disable tail calls if they're not supported. |
| 1299 | if (!EnableARMTailCalls && !Subtarget->supportsTailCall()) |
Bob Wilson | 703af3a | 2010-08-13 22:43:33 +0000 | [diff] [blame] | 1300 | isTailCall = false; |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1301 | if (isTailCall) { |
| 1302 | // Check if it's really possible to do a tail call. |
| 1303 | isTailCall = IsEligibleForTailCallOptimization(Callee, CallConv, |
| 1304 | isVarArg, IsStructRet, MF.getFunction()->hasStructRetAttr(), |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1305 | Outs, OutVals, Ins, DAG); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1306 | // We don't support GuaranteedTailCallOpt for ARM, only automatically |
| 1307 | // detected sibcalls. |
| 1308 | if (isTailCall) { |
| 1309 | ++NumTailCalls; |
| 1310 | IsSibCall = true; |
| 1311 | } |
| 1312 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1313 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1314 | // Analyze operands of the call, assigning locations to each operand. |
| 1315 | SmallVector<CCValAssign, 16> ArgLocs; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1316 | ARMCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), |
| 1317 | getTargetMachine(), ArgLocs, *DAG.getContext(), Call); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1318 | CCInfo.AnalyzeCallOperands(Outs, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1319 | CCAssignFnForNode(CallConv, /* Return*/ false, |
| 1320 | isVarArg)); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1321 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1322 | // Get a count of how many bytes are to be pushed on the stack. |
| 1323 | unsigned NumBytes = CCInfo.getNextStackOffset(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1324 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1325 | // For tail calls, memory operands are available in our caller's stack. |
| 1326 | if (IsSibCall) |
| 1327 | NumBytes = 0; |
| 1328 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1329 | // Adjust the stack pointer for the new arguments... |
| 1330 | // These operations are automatically eliminated by the prolog/epilog pass |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1331 | if (!IsSibCall) |
| 1332 | Chain = DAG.getCALLSEQ_START(Chain, DAG.getIntPtrConstant(NumBytes, true)); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1333 | |
Jim Grosbach | f9a4b76 | 2010-02-24 01:43:03 +0000 | [diff] [blame] | 1334 | SDValue StackPtr = DAG.getCopyFromReg(Chain, dl, ARM::SP, getPointerTy()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1335 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1336 | RegsToPassVector RegsToPass; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1337 | SmallVector<SDValue, 8> MemOpChains; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1338 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1339 | // Walk the register/memloc assignments, inserting copies/loads. In the case |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1340 | // of tail call optimization, arguments are handled later. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1341 | for (unsigned i = 0, realArgIdx = 0, e = ArgLocs.size(); |
| 1342 | i != e; |
| 1343 | ++i, ++realArgIdx) { |
| 1344 | CCValAssign &VA = ArgLocs[i]; |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1345 | SDValue Arg = OutVals[realArgIdx]; |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1346 | ISD::ArgFlagsTy Flags = Outs[realArgIdx].Flags; |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1347 | bool isByVal = Flags.isByVal(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1348 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1349 | // Promote the value if needed. |
| 1350 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1351 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1352 | case CCValAssign::Full: break; |
| 1353 | case CCValAssign::SExt: |
| 1354 | Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg); |
| 1355 | break; |
| 1356 | case CCValAssign::ZExt: |
| 1357 | Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg); |
| 1358 | break; |
| 1359 | case CCValAssign::AExt: |
| 1360 | Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg); |
| 1361 | break; |
| 1362 | case CCValAssign::BCvt: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1363 | Arg = DAG.getNode(ISD::BITCAST, dl, VA.getLocVT(), Arg); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1364 | break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1365 | } |
| 1366 | |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1367 | // 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] | 1368 | if (VA.needsCustom()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1369 | if (VA.getLocVT() == MVT::v2f64) { |
| 1370 | SDValue Op0 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1371 | DAG.getConstant(0, MVT::i32)); |
| 1372 | SDValue Op1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1373 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1374 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1375 | PassF64ArgInRegs(dl, DAG, Chain, Op0, RegsToPass, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1376 | VA, ArgLocs[++i], StackPtr, MemOpChains, Flags); |
| 1377 | |
| 1378 | VA = ArgLocs[++i]; // skip ahead to next loc |
| 1379 | if (VA.isRegLoc()) { |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1380 | PassF64ArgInRegs(dl, DAG, Chain, Op1, RegsToPass, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1381 | VA, ArgLocs[++i], StackPtr, MemOpChains, Flags); |
| 1382 | } else { |
| 1383 | assert(VA.isMemLoc()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1384 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1385 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, Op1, |
| 1386 | dl, DAG, VA, Flags)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1387 | } |
| 1388 | } else { |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1389 | PassF64ArgInRegs(dl, DAG, Chain, Arg, RegsToPass, VA, ArgLocs[++i], |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1390 | StackPtr, MemOpChains, Flags); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1391 | } |
| 1392 | } else if (VA.isRegLoc()) { |
| 1393 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg)); |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1394 | } else if (isByVal) { |
| 1395 | assert(VA.isMemLoc()); |
| 1396 | unsigned offset = 0; |
| 1397 | |
| 1398 | // True if this byval aggregate will be split between registers |
| 1399 | // and memory. |
| 1400 | if (CCInfo.isFirstByValRegValid()) { |
| 1401 | EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
| 1402 | unsigned int i, j; |
| 1403 | for (i = 0, j = CCInfo.getFirstByValReg(); j < ARM::R4; i++, j++) { |
| 1404 | SDValue Const = DAG.getConstant(4*i, MVT::i32); |
| 1405 | SDValue AddArg = DAG.getNode(ISD::ADD, dl, PtrVT, Arg, Const); |
| 1406 | SDValue Load = DAG.getLoad(PtrVT, dl, Chain, AddArg, |
| 1407 | MachinePointerInfo(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 1408 | false, false, false, 0); |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1409 | MemOpChains.push_back(Load.getValue(1)); |
| 1410 | RegsToPass.push_back(std::make_pair(j, Load)); |
| 1411 | } |
| 1412 | offset = ARM::R4 - CCInfo.getFirstByValReg(); |
| 1413 | CCInfo.clearFirstByValReg(); |
| 1414 | } |
| 1415 | |
| 1416 | unsigned LocMemOffset = VA.getLocMemOffset(); |
| 1417 | SDValue StkPtrOff = DAG.getIntPtrConstant(LocMemOffset); |
| 1418 | SDValue Dst = DAG.getNode(ISD::ADD, dl, getPointerTy(), StackPtr, |
| 1419 | StkPtrOff); |
| 1420 | SDValue SrcOffset = DAG.getIntPtrConstant(4*offset); |
| 1421 | SDValue Src = DAG.getNode(ISD::ADD, dl, getPointerTy(), Arg, SrcOffset); |
| 1422 | SDValue SizeNode = DAG.getConstant(Flags.getByValSize() - 4*offset, |
| 1423 | MVT::i32); |
| 1424 | MemOpChains.push_back(DAG.getMemcpy(Chain, dl, Dst, Src, SizeNode, |
| 1425 | Flags.getByValAlign(), |
| 1426 | /*isVolatile=*/false, |
Dan Gohman | 65fd656 | 2011-11-03 21:49:52 +0000 | [diff] [blame] | 1427 | /*AlwaysInline=*/false, |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1428 | MachinePointerInfo(0), |
| 1429 | MachinePointerInfo(0))); |
| 1430 | |
| 1431 | } else if (!IsSibCall) { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1432 | assert(VA.isMemLoc()); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1433 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1434 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, Arg, |
| 1435 | dl, DAG, VA, Flags)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1436 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1437 | } |
| 1438 | |
| 1439 | if (!MemOpChains.empty()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1440 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1441 | &MemOpChains[0], MemOpChains.size()); |
| 1442 | |
| 1443 | // Build a sequence of copy-to-reg nodes chained together with token chain |
| 1444 | // and flag operands which copy the outgoing args into the appropriate regs. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1445 | SDValue InFlag; |
Dale Johannesen | 6470a11 | 2010-06-15 22:08:33 +0000 | [diff] [blame] | 1446 | // Tail call byval lowering might overwrite argument registers so in case of |
| 1447 | // tail call optimization the copies to registers are lowered later. |
| 1448 | if (!isTailCall) |
| 1449 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 1450 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, |
| 1451 | RegsToPass[i].second, InFlag); |
| 1452 | InFlag = Chain.getValue(1); |
| 1453 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1454 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1455 | // For tail calls lower the arguments to the 'real' stack slot. |
| 1456 | if (isTailCall) { |
| 1457 | // Force all the incoming stack arguments to be loaded from the stack |
| 1458 | // before any new outgoing arguments are stored to the stack, because the |
| 1459 | // outgoing stack slots may alias the incoming argument stack slots, and |
| 1460 | // the alias isn't otherwise explicit. This is slightly more conservative |
| 1461 | // than necessary, because it means that each store effectively depends |
| 1462 | // on every argument instead of just those arguments it would clobber. |
| 1463 | |
Chris Lattner | 7a2bdde | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 1464 | // Do not flag preceding copytoreg stuff together with the following stuff. |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1465 | InFlag = SDValue(); |
| 1466 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 1467 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, |
| 1468 | RegsToPass[i].second, InFlag); |
| 1469 | InFlag = Chain.getValue(1); |
| 1470 | } |
| 1471 | InFlag =SDValue(); |
| 1472 | } |
| 1473 | |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1474 | // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every |
| 1475 | // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol |
| 1476 | // node so that legalize doesn't hack it. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1477 | bool isDirect = false; |
| 1478 | bool isARMFunc = false; |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 1479 | bool isLocalARMFunc = false; |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1480 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1481 | |
| 1482 | if (EnableARMLongCalls) { |
| 1483 | assert (getTargetMachine().getRelocationModel() == Reloc::Static |
| 1484 | && "long-calls with non-static relocation model!"); |
| 1485 | // Handle a global address or an external symbol. If it's not one of |
| 1486 | // those, the target's already in a register, so we don't need to do |
| 1487 | // anything extra. |
| 1488 | if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
Anders Carlsson | 0dbdca5 | 2010-04-15 03:11:28 +0000 | [diff] [blame] | 1489 | const GlobalValue *GV = G->getGlobal(); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1490 | // Create a constant pool entry for the callee address |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1491 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 1492 | ARMConstantPoolValue *CPV = |
| 1493 | ARMConstantPoolConstant::Create(GV, ARMPCLabelIndex, ARMCP::CPValue, 0); |
| 1494 | |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1495 | // Get the address of the callee into a register |
| 1496 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
| 1497 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| 1498 | Callee = DAG.getLoad(getPointerTy(), dl, |
| 1499 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1500 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 1501 | false, false, false, 0); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1502 | } else if (ExternalSymbolSDNode *S=dyn_cast<ExternalSymbolSDNode>(Callee)) { |
| 1503 | const char *Sym = S->getSymbol(); |
| 1504 | |
| 1505 | // Create a constant pool entry for the callee address |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1506 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Bill Wendling | fe31e67 | 2011-10-01 08:58:29 +0000 | [diff] [blame] | 1507 | ARMConstantPoolValue *CPV = |
| 1508 | ARMConstantPoolSymbol::Create(*DAG.getContext(), Sym, |
| 1509 | ARMPCLabelIndex, 0); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1510 | // Get the address of the callee into a register |
| 1511 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
| 1512 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| 1513 | Callee = DAG.getLoad(getPointerTy(), dl, |
| 1514 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1515 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 1516 | false, false, false, 0); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1517 | } |
| 1518 | } else if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 1519 | const GlobalValue *GV = G->getGlobal(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1520 | isDirect = true; |
Chris Lattner | 4fb63d0 | 2009-07-15 04:12:33 +0000 | [diff] [blame] | 1521 | bool isExt = GV->isDeclaration() || GV->isWeakForLinker(); |
Evan Cheng | 970a419 | 2007-01-19 19:28:01 +0000 | [diff] [blame] | 1522 | bool isStub = (isExt && Subtarget->isTargetDarwin()) && |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1523 | getTargetMachine().getRelocationModel() != Reloc::Static; |
| 1524 | isARMFunc = !Subtarget->isThumb() || isStub; |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 1525 | // ARM call to a local ARM function is predicable. |
Evan Cheng | 46df4eb | 2010-06-16 07:35:02 +0000 | [diff] [blame] | 1526 | isLocalARMFunc = !Subtarget->isThumb() && (!isExt || !ARMInterworking); |
Evan Cheng | c60e76d | 2007-01-30 20:37:08 +0000 | [diff] [blame] | 1527 | // tBX takes a register source operand. |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 1528 | if (isARMFunc && Subtarget->isThumb1Only() && !Subtarget->hasV5TOps()) { |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1529 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 1530 | ARMConstantPoolValue *CPV = |
| 1531 | ARMConstantPoolConstant::Create(GV, ARMPCLabelIndex, ARMCP::CPValue, 4); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1532 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1533 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1534 | Callee = DAG.getLoad(getPointerTy(), dl, |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1535 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1536 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 1537 | false, false, false, 0); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1538 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1539 | Callee = DAG.getNode(ARMISD::PIC_ADD, dl, |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1540 | getPointerTy(), Callee, PICLabel); |
Jim Grosbach | 637d89f | 2010-09-22 23:27:36 +0000 | [diff] [blame] | 1541 | } else { |
| 1542 | // On ELF targets for PIC code, direct calls should go through the PLT |
| 1543 | unsigned OpFlags = 0; |
| 1544 | if (Subtarget->isTargetELF() && |
| 1545 | getTargetMachine().getRelocationModel() == Reloc::PIC_) |
| 1546 | OpFlags = ARMII::MO_PLT; |
| 1547 | Callee = DAG.getTargetGlobalAddress(GV, dl, getPointerTy(), 0, OpFlags); |
| 1548 | } |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1549 | } else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1550 | isDirect = true; |
Evan Cheng | 970a419 | 2007-01-19 19:28:01 +0000 | [diff] [blame] | 1551 | bool isStub = Subtarget->isTargetDarwin() && |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1552 | getTargetMachine().getRelocationModel() != Reloc::Static; |
| 1553 | isARMFunc = !Subtarget->isThumb() || isStub; |
Evan Cheng | c60e76d | 2007-01-30 20:37:08 +0000 | [diff] [blame] | 1554 | // tBX takes a register source operand. |
| 1555 | const char *Sym = S->getSymbol(); |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 1556 | if (isARMFunc && Subtarget->isThumb1Only() && !Subtarget->hasV5TOps()) { |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1557 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Bill Wendling | fe31e67 | 2011-10-01 08:58:29 +0000 | [diff] [blame] | 1558 | ARMConstantPoolValue *CPV = |
| 1559 | ARMConstantPoolSymbol::Create(*DAG.getContext(), Sym, |
| 1560 | ARMPCLabelIndex, 4); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1561 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1562 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1563 | Callee = DAG.getLoad(getPointerTy(), dl, |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1564 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1565 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 1566 | false, false, false, 0); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1567 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1568 | Callee = DAG.getNode(ARMISD::PIC_ADD, dl, |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1569 | getPointerTy(), Callee, PICLabel); |
Jim Grosbach | 637d89f | 2010-09-22 23:27:36 +0000 | [diff] [blame] | 1570 | } else { |
| 1571 | unsigned OpFlags = 0; |
| 1572 | // On ELF targets for PIC code, direct calls should go through the PLT |
| 1573 | if (Subtarget->isTargetELF() && |
| 1574 | getTargetMachine().getRelocationModel() == Reloc::PIC_) |
| 1575 | OpFlags = ARMII::MO_PLT; |
| 1576 | Callee = DAG.getTargetExternalSymbol(Sym, getPointerTy(), OpFlags); |
| 1577 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1578 | } |
| 1579 | |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1580 | // FIXME: handle tail calls differently. |
| 1581 | unsigned CallOpc; |
Evan Cheng | b620724 | 2009-08-01 00:16:10 +0000 | [diff] [blame] | 1582 | if (Subtarget->isThumb()) { |
| 1583 | if ((!isDirect || isARMFunc) && !Subtarget->hasV5TOps()) |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1584 | CallOpc = ARMISD::CALL_NOLINK; |
| 1585 | else |
| 1586 | CallOpc = isARMFunc ? ARMISD::CALL : ARMISD::tCALL; |
| 1587 | } else { |
| 1588 | CallOpc = (isDirect || Subtarget->hasV5TOps()) |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 1589 | ? (isLocalARMFunc ? ARMISD::CALL_PRED : ARMISD::CALL) |
| 1590 | : ARMISD::CALL_NOLINK; |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1591 | } |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1592 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1593 | std::vector<SDValue> Ops; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1594 | Ops.push_back(Chain); |
| 1595 | Ops.push_back(Callee); |
| 1596 | |
| 1597 | // Add argument registers to the end of the list so that they are known live |
| 1598 | // into the call. |
| 1599 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) |
| 1600 | Ops.push_back(DAG.getRegister(RegsToPass[i].first, |
| 1601 | RegsToPass[i].second.getValueType())); |
| 1602 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1603 | if (InFlag.getNode()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1604 | Ops.push_back(InFlag); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1605 | |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 1606 | SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue); |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1607 | if (isTailCall) |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1608 | return DAG.getNode(ARMISD::TC_RETURN, dl, NodeTys, &Ops[0], Ops.size()); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1609 | |
Duncan Sands | 4bdcb61 | 2008-07-02 17:40:58 +0000 | [diff] [blame] | 1610 | // Returns a chain and a flag for retval copy to use. |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1611 | Chain = DAG.getNode(CallOpc, dl, NodeTys, &Ops[0], Ops.size()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1612 | InFlag = Chain.getValue(1); |
| 1613 | |
Chris Lattner | e563bbc | 2008-10-11 22:08:30 +0000 | [diff] [blame] | 1614 | Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(NumBytes, true), |
| 1615 | DAG.getIntPtrConstant(0, true), InFlag); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1616 | if (!Ins.empty()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1617 | InFlag = Chain.getValue(1); |
| 1618 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1619 | // Handle result values, copying them out of physregs into vregs that we |
| 1620 | // return. |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1621 | return LowerCallResult(Chain, InFlag, CallConv, isVarArg, Ins, |
| 1622 | dl, DAG, InVals); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1623 | } |
| 1624 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1625 | /// HandleByVal - Every parameter *after* a byval parameter is passed |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1626 | /// on the stack. Remember the next parameter register to allocate, |
| 1627 | /// and then confiscate the rest of the parameter registers to insure |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1628 | /// this. |
| 1629 | void |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1630 | llvm::ARMTargetLowering::HandleByVal(CCState *State, unsigned &size) const { |
| 1631 | unsigned reg = State->AllocateReg(GPRArgRegs, 4); |
| 1632 | assert((State->getCallOrPrologue() == Prologue || |
| 1633 | State->getCallOrPrologue() == Call) && |
| 1634 | "unhandled ParmContext"); |
| 1635 | if ((!State->isFirstByValRegValid()) && |
| 1636 | (ARM::R0 <= reg) && (reg <= ARM::R3)) { |
| 1637 | State->setFirstByValReg(reg); |
| 1638 | // At a call site, a byval parameter that is split between |
| 1639 | // registers and memory needs its size truncated here. In a |
| 1640 | // function prologue, such byval parameters are reassembled in |
| 1641 | // memory, and are not truncated. |
| 1642 | if (State->getCallOrPrologue() == Call) { |
| 1643 | unsigned excess = 4 * (ARM::R4 - reg); |
| 1644 | assert(size >= excess && "expected larger existing stack allocation"); |
| 1645 | size -= excess; |
| 1646 | } |
| 1647 | } |
| 1648 | // Confiscate any remaining parameter registers to preclude their |
| 1649 | // assignment to subsequent parameters. |
| 1650 | while (State->AllocateReg(GPRArgRegs, 4)) |
| 1651 | ; |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1652 | } |
| 1653 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1654 | /// MatchingStackOffset - Return true if the given stack call argument is |
| 1655 | /// already available in the same position (relatively) of the caller's |
| 1656 | /// incoming argument stack. |
| 1657 | static |
| 1658 | bool MatchingStackOffset(SDValue Arg, unsigned Offset, ISD::ArgFlagsTy Flags, |
| 1659 | MachineFrameInfo *MFI, const MachineRegisterInfo *MRI, |
| 1660 | const ARMInstrInfo *TII) { |
| 1661 | unsigned Bytes = Arg.getValueType().getSizeInBits() / 8; |
| 1662 | int FI = INT_MAX; |
| 1663 | if (Arg.getOpcode() == ISD::CopyFromReg) { |
| 1664 | unsigned VR = cast<RegisterSDNode>(Arg.getOperand(1))->getReg(); |
Jakob Stoklund Olesen | c9df025 | 2011-01-10 02:58:51 +0000 | [diff] [blame] | 1665 | if (!TargetRegisterInfo::isVirtualRegister(VR)) |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1666 | return false; |
| 1667 | MachineInstr *Def = MRI->getVRegDef(VR); |
| 1668 | if (!Def) |
| 1669 | return false; |
| 1670 | if (!Flags.isByVal()) { |
| 1671 | if (!TII->isLoadFromStackSlot(Def, FI)) |
| 1672 | return false; |
| 1673 | } else { |
Dale Johannesen | 7835f1f | 2010-07-08 01:18:23 +0000 | [diff] [blame] | 1674 | return false; |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1675 | } |
| 1676 | } else if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Arg)) { |
| 1677 | if (Flags.isByVal()) |
| 1678 | // ByVal argument is passed in as a pointer but it's now being |
| 1679 | // dereferenced. e.g. |
| 1680 | // define @foo(%struct.X* %A) { |
| 1681 | // tail call @bar(%struct.X* byval %A) |
| 1682 | // } |
| 1683 | return false; |
| 1684 | SDValue Ptr = Ld->getBasePtr(); |
| 1685 | FrameIndexSDNode *FINode = dyn_cast<FrameIndexSDNode>(Ptr); |
| 1686 | if (!FINode) |
| 1687 | return false; |
| 1688 | FI = FINode->getIndex(); |
| 1689 | } else |
| 1690 | return false; |
| 1691 | |
| 1692 | assert(FI != INT_MAX); |
| 1693 | if (!MFI->isFixedObjectIndex(FI)) |
| 1694 | return false; |
| 1695 | return Offset == MFI->getObjectOffset(FI) && Bytes == MFI->getObjectSize(FI); |
| 1696 | } |
| 1697 | |
| 1698 | /// IsEligibleForTailCallOptimization - Check whether the call is eligible |
| 1699 | /// for tail call optimization. Targets which want to do tail call |
| 1700 | /// optimization should implement this function. |
| 1701 | bool |
| 1702 | ARMTargetLowering::IsEligibleForTailCallOptimization(SDValue Callee, |
| 1703 | CallingConv::ID CalleeCC, |
| 1704 | bool isVarArg, |
| 1705 | bool isCalleeStructRet, |
| 1706 | bool isCallerStructRet, |
| 1707 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1708 | const SmallVectorImpl<SDValue> &OutVals, |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1709 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 1710 | SelectionDAG& DAG) const { |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1711 | const Function *CallerF = DAG.getMachineFunction().getFunction(); |
| 1712 | CallingConv::ID CallerCC = CallerF->getCallingConv(); |
| 1713 | bool CCMatch = CallerCC == CalleeCC; |
| 1714 | |
| 1715 | // Look for obvious safe cases to perform tail call optimization that do not |
| 1716 | // require ABI changes. This is what gcc calls sibcall. |
| 1717 | |
Jim Grosbach | 7616b64 | 2010-06-16 23:45:49 +0000 | [diff] [blame] | 1718 | // Do not sibcall optimize vararg calls unless the call site is not passing |
| 1719 | // any arguments. |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1720 | if (isVarArg && !Outs.empty()) |
| 1721 | return false; |
| 1722 | |
| 1723 | // Also avoid sibcall optimization if either caller or callee uses struct |
| 1724 | // return semantics. |
| 1725 | if (isCalleeStructRet || isCallerStructRet) |
| 1726 | return false; |
| 1727 | |
Dale Johannesen | e39fdbe | 2010-06-23 18:52:34 +0000 | [diff] [blame] | 1728 | // FIXME: Completely disable sibcall for Thumb1 since Thumb1RegisterInfo:: |
Jim Grosbach | 8dc41f3 | 2011-07-08 20:18:11 +0000 | [diff] [blame] | 1729 | // emitEpilogue is not ready for them. Thumb tail calls also use t2B, as |
| 1730 | // the Thumb1 16-bit unconditional branch doesn't have sufficient relocation |
| 1731 | // support in the assembler and linker to be used. This would need to be |
| 1732 | // fixed to fully support tail calls in Thumb1. |
| 1733 | // |
Dale Johannesen | 7835f1f | 2010-07-08 01:18:23 +0000 | [diff] [blame] | 1734 | // Doing this is tricky, since the LDM/POP instruction on Thumb doesn't take |
| 1735 | // LR. This means if we need to reload LR, it takes an extra instructions, |
| 1736 | // which outweighs the value of the tail call; but here we don't know yet |
| 1737 | // 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] | 1738 | // 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] | 1739 | // emitEpilogue if LR is used. |
Dale Johannesen | 7835f1f | 2010-07-08 01:18:23 +0000 | [diff] [blame] | 1740 | |
| 1741 | // Thumb1 PIC calls to external symbols use BX, so they can be tail calls, |
| 1742 | // but we need to make sure there are enough registers; the only valid |
| 1743 | // registers are the 4 used for parameters. We don't currently do this |
| 1744 | // case. |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1745 | if (Subtarget->isThumb1Only()) |
| 1746 | return false; |
Dale Johannesen | df50d7e | 2010-06-18 18:13:11 +0000 | [diff] [blame] | 1747 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1748 | // If the calling conventions do not match, then we'd better make sure the |
| 1749 | // results are returned in the same way as what the caller expects. |
| 1750 | if (!CCMatch) { |
| 1751 | SmallVector<CCValAssign, 16> RVLocs1; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1752 | ARMCCState CCInfo1(CalleeCC, false, DAG.getMachineFunction(), |
| 1753 | getTargetMachine(), RVLocs1, *DAG.getContext(), Call); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1754 | CCInfo1.AnalyzeCallResult(Ins, CCAssignFnForNode(CalleeCC, true, isVarArg)); |
| 1755 | |
| 1756 | SmallVector<CCValAssign, 16> RVLocs2; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1757 | ARMCCState CCInfo2(CallerCC, false, DAG.getMachineFunction(), |
| 1758 | getTargetMachine(), RVLocs2, *DAG.getContext(), Call); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1759 | CCInfo2.AnalyzeCallResult(Ins, CCAssignFnForNode(CallerCC, true, isVarArg)); |
| 1760 | |
| 1761 | if (RVLocs1.size() != RVLocs2.size()) |
| 1762 | return false; |
| 1763 | for (unsigned i = 0, e = RVLocs1.size(); i != e; ++i) { |
| 1764 | if (RVLocs1[i].isRegLoc() != RVLocs2[i].isRegLoc()) |
| 1765 | return false; |
| 1766 | if (RVLocs1[i].getLocInfo() != RVLocs2[i].getLocInfo()) |
| 1767 | return false; |
| 1768 | if (RVLocs1[i].isRegLoc()) { |
| 1769 | if (RVLocs1[i].getLocReg() != RVLocs2[i].getLocReg()) |
| 1770 | return false; |
| 1771 | } else { |
| 1772 | if (RVLocs1[i].getLocMemOffset() != RVLocs2[i].getLocMemOffset()) |
| 1773 | return false; |
| 1774 | } |
| 1775 | } |
| 1776 | } |
| 1777 | |
| 1778 | // If the callee takes no arguments then go on to check the results of the |
| 1779 | // call. |
| 1780 | if (!Outs.empty()) { |
| 1781 | // Check if stack adjustment is needed. For now, do not do this if any |
| 1782 | // argument is passed on the stack. |
| 1783 | SmallVector<CCValAssign, 16> ArgLocs; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1784 | ARMCCState CCInfo(CalleeCC, isVarArg, DAG.getMachineFunction(), |
| 1785 | getTargetMachine(), ArgLocs, *DAG.getContext(), Call); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1786 | CCInfo.AnalyzeCallOperands(Outs, |
| 1787 | CCAssignFnForNode(CalleeCC, false, isVarArg)); |
| 1788 | if (CCInfo.getNextStackOffset()) { |
| 1789 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1790 | |
| 1791 | // Check if the arguments are already laid out in the right way as |
| 1792 | // the caller's fixed stack objects. |
| 1793 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 1794 | const MachineRegisterInfo *MRI = &MF.getRegInfo(); |
| 1795 | const ARMInstrInfo *TII = |
| 1796 | ((ARMTargetMachine&)getTargetMachine()).getInstrInfo(); |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1797 | for (unsigned i = 0, realArgIdx = 0, e = ArgLocs.size(); |
| 1798 | i != e; |
| 1799 | ++i, ++realArgIdx) { |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1800 | CCValAssign &VA = ArgLocs[i]; |
| 1801 | EVT RegVT = VA.getLocVT(); |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1802 | SDValue Arg = OutVals[realArgIdx]; |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1803 | ISD::ArgFlagsTy Flags = Outs[realArgIdx].Flags; |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1804 | if (VA.getLocInfo() == CCValAssign::Indirect) |
| 1805 | return false; |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1806 | if (VA.needsCustom()) { |
| 1807 | // f64 and vector types are split into multiple registers or |
| 1808 | // register/stack-slot combinations. The types will not match |
| 1809 | // the registers; give up on memory f64 refs until we figure |
| 1810 | // out what to do about this. |
| 1811 | if (!VA.isRegLoc()) |
| 1812 | return false; |
| 1813 | if (!ArgLocs[++i].isRegLoc()) |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 1814 | return false; |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1815 | if (RegVT == MVT::v2f64) { |
| 1816 | if (!ArgLocs[++i].isRegLoc()) |
| 1817 | return false; |
| 1818 | if (!ArgLocs[++i].isRegLoc()) |
| 1819 | return false; |
| 1820 | } |
| 1821 | } else if (!VA.isRegLoc()) { |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1822 | if (!MatchingStackOffset(Arg, VA.getLocMemOffset(), Flags, |
| 1823 | MFI, MRI, TII)) |
| 1824 | return false; |
| 1825 | } |
| 1826 | } |
| 1827 | } |
| 1828 | } |
| 1829 | |
| 1830 | return true; |
| 1831 | } |
| 1832 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1833 | SDValue |
| 1834 | ARMTargetLowering::LowerReturn(SDValue Chain, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1835 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1836 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1837 | const SmallVectorImpl<SDValue> &OutVals, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1838 | DebugLoc dl, SelectionDAG &DAG) const { |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1839 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1840 | // CCValAssign - represent the assignment of the return value to a location. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1841 | SmallVector<CCValAssign, 16> RVLocs; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1842 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1843 | // CCState - Info about the registers and stack slots. |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1844 | ARMCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), |
| 1845 | getTargetMachine(), RVLocs, *DAG.getContext(), Call); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1846 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1847 | // Analyze outgoing return values. |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1848 | CCInfo.AnalyzeReturn(Outs, CCAssignFnForNode(CallConv, /* Return */ true, |
| 1849 | isVarArg)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1850 | |
| 1851 | // If this is the first return lowered for this function, add |
| 1852 | // the regs to the liveout set for the function. |
| 1853 | if (DAG.getMachineFunction().getRegInfo().liveout_empty()) { |
| 1854 | for (unsigned i = 0; i != RVLocs.size(); ++i) |
| 1855 | if (RVLocs[i].isRegLoc()) |
| 1856 | DAG.getMachineFunction().getRegInfo().addLiveOut(RVLocs[i].getLocReg()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1857 | } |
| 1858 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1859 | SDValue Flag; |
| 1860 | |
| 1861 | // Copy the result values into the output registers. |
| 1862 | for (unsigned i = 0, realRVLocIdx = 0; |
| 1863 | i != RVLocs.size(); |
| 1864 | ++i, ++realRVLocIdx) { |
| 1865 | CCValAssign &VA = RVLocs[i]; |
| 1866 | assert(VA.isRegLoc() && "Can only return in registers!"); |
| 1867 | |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1868 | SDValue Arg = OutVals[realRVLocIdx]; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1869 | |
| 1870 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1871 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1872 | case CCValAssign::Full: break; |
| 1873 | case CCValAssign::BCvt: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1874 | Arg = DAG.getNode(ISD::BITCAST, dl, VA.getLocVT(), Arg); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1875 | break; |
| 1876 | } |
| 1877 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1878 | if (VA.needsCustom()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1879 | if (VA.getLocVT() == MVT::v2f64) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1880 | // Extract the first half and return it in two registers. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1881 | SDValue Half = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1882 | DAG.getConstant(0, MVT::i32)); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1883 | SDValue HalfGPRs = DAG.getNode(ARMISD::VMOVRRD, dl, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1884 | DAG.getVTList(MVT::i32, MVT::i32), Half); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1885 | |
| 1886 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), HalfGPRs, Flag); |
| 1887 | Flag = Chain.getValue(1); |
| 1888 | VA = RVLocs[++i]; // skip ahead to next loc |
| 1889 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), |
| 1890 | HalfGPRs.getValue(1), Flag); |
| 1891 | Flag = Chain.getValue(1); |
| 1892 | VA = RVLocs[++i]; // skip ahead to next loc |
| 1893 | |
| 1894 | // 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] | 1895 | Arg = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1896 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1897 | } |
| 1898 | // Legalize ret f64 -> ret 2 x i32. We always have fmrrd if f64 is |
| 1899 | // available. |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1900 | SDValue fmrrd = DAG.getNode(ARMISD::VMOVRRD, dl, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1901 | DAG.getVTList(MVT::i32, MVT::i32), &Arg, 1); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1902 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), fmrrd, Flag); |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1903 | Flag = Chain.getValue(1); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1904 | VA = RVLocs[++i]; // skip ahead to next loc |
| 1905 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), fmrrd.getValue(1), |
| 1906 | Flag); |
| 1907 | } else |
| 1908 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), Arg, Flag); |
| 1909 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1910 | // Guarantee that all emitted copies are |
| 1911 | // stuck together, avoiding something bad. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1912 | Flag = Chain.getValue(1); |
| 1913 | } |
| 1914 | |
| 1915 | SDValue result; |
| 1916 | if (Flag.getNode()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1917 | result = DAG.getNode(ARMISD::RET_FLAG, dl, MVT::Other, Chain, Flag); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1918 | else // Return Void |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1919 | result = DAG.getNode(ARMISD::RET_FLAG, dl, MVT::Other, Chain); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1920 | |
| 1921 | return result; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1922 | } |
| 1923 | |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1924 | bool ARMTargetLowering::isUsedByReturnOnly(SDNode *N) const { |
| 1925 | if (N->getNumValues() != 1) |
| 1926 | return false; |
| 1927 | if (!N->hasNUsesOfValue(1, 0)) |
| 1928 | return false; |
| 1929 | |
| 1930 | unsigned NumCopies = 0; |
Jason W Kim | 1de886c | 2012-02-10 16:07:59 +0000 | [diff] [blame] | 1931 | SDNode* Copies[2] = { 0, 0 }; |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1932 | SDNode *Use = *N->use_begin(); |
| 1933 | if (Use->getOpcode() == ISD::CopyToReg) { |
| 1934 | Copies[NumCopies++] = Use; |
| 1935 | } else if (Use->getOpcode() == ARMISD::VMOVRRD) { |
| 1936 | // f64 returned in a pair of GPRs. |
| 1937 | for (SDNode::use_iterator UI = Use->use_begin(), UE = Use->use_end(); |
| 1938 | UI != UE; ++UI) { |
| 1939 | if (UI->getOpcode() != ISD::CopyToReg) |
| 1940 | return false; |
| 1941 | Copies[UI.getUse().getResNo()] = *UI; |
| 1942 | ++NumCopies; |
| 1943 | } |
| 1944 | } else if (Use->getOpcode() == ISD::BITCAST) { |
| 1945 | // f32 returned in a single GPR. |
| 1946 | if (!Use->hasNUsesOfValue(1, 0)) |
| 1947 | return false; |
| 1948 | Use = *Use->use_begin(); |
| 1949 | if (Use->getOpcode() != ISD::CopyToReg || !Use->hasNUsesOfValue(1, 0)) |
| 1950 | return false; |
| 1951 | Copies[NumCopies++] = Use; |
| 1952 | } else { |
| 1953 | return false; |
| 1954 | } |
| 1955 | |
| 1956 | if (NumCopies != 1 && NumCopies != 2) |
| 1957 | return false; |
Evan Cheng | 1bf891a | 2010-12-01 22:59:46 +0000 | [diff] [blame] | 1958 | |
| 1959 | bool HasRet = false; |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1960 | for (unsigned i = 0; i < NumCopies; ++i) { |
| 1961 | SDNode *Copy = Copies[i]; |
| 1962 | for (SDNode::use_iterator UI = Copy->use_begin(), UE = Copy->use_end(); |
| 1963 | UI != UE; ++UI) { |
| 1964 | if (UI->getOpcode() == ISD::CopyToReg) { |
| 1965 | SDNode *Use = *UI; |
Jason W Kim | 1de886c | 2012-02-10 16:07:59 +0000 | [diff] [blame] | 1966 | if (Use == Copies[0] || ((NumCopies == 2) && (Use == Copies[1]))) |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1967 | continue; |
| 1968 | return false; |
| 1969 | } |
| 1970 | if (UI->getOpcode() != ARMISD::RET_FLAG) |
| 1971 | return false; |
Evan Cheng | 1bf891a | 2010-12-01 22:59:46 +0000 | [diff] [blame] | 1972 | HasRet = true; |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1973 | } |
| 1974 | } |
| 1975 | |
Evan Cheng | 1bf891a | 2010-12-01 22:59:46 +0000 | [diff] [blame] | 1976 | return HasRet; |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1977 | } |
| 1978 | |
Evan Cheng | 485fafc | 2011-03-21 01:19:09 +0000 | [diff] [blame] | 1979 | bool ARMTargetLowering::mayBeEmittedAsTailCall(CallInst *CI) const { |
| 1980 | if (!EnableARMTailCalls) |
| 1981 | return false; |
| 1982 | |
| 1983 | if (!CI->isTailCall()) |
| 1984 | return false; |
| 1985 | |
| 1986 | return !Subtarget->isThumb1Only(); |
| 1987 | } |
| 1988 | |
Bob Wilson | b62d257 | 2009-11-03 00:02:05 +0000 | [diff] [blame] | 1989 | // ConstantPool, JumpTable, GlobalAddress, and ExternalSymbol are lowered as |
| 1990 | // their target counterpart wrapped in the ARMISD::Wrapper node. Suppose N is |
| 1991 | // one of the above mentioned nodes. It has to be wrapped because otherwise |
| 1992 | // Select(N) returns N. So the raw TargetGlobalAddress nodes, etc. can only |
| 1993 | // be used to form addressing mode. These wrapped nodes will be selected |
| 1994 | // into MOVi. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1995 | static SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1996 | EVT PtrVT = Op.getValueType(); |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 1997 | // FIXME there is no actual debug info here |
| 1998 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1999 | ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2000 | SDValue Res; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2001 | if (CP->isMachineConstantPoolEntry()) |
| 2002 | Res = DAG.getTargetConstantPool(CP->getMachineCPVal(), PtrVT, |
| 2003 | CP->getAlignment()); |
| 2004 | else |
| 2005 | Res = DAG.getTargetConstantPool(CP->getConstVal(), PtrVT, |
| 2006 | CP->getAlignment()); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2007 | return DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Res); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2008 | } |
| 2009 | |
Jim Grosbach | e1102ca | 2010-07-19 17:20:38 +0000 | [diff] [blame] | 2010 | unsigned ARMTargetLowering::getJumpTableEncoding() const { |
| 2011 | return MachineJumpTableInfo::EK_Inline; |
| 2012 | } |
| 2013 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2014 | SDValue ARMTargetLowering::LowerBlockAddress(SDValue Op, |
| 2015 | SelectionDAG &DAG) const { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2016 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2017 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2018 | unsigned ARMPCLabelIndex = 0; |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 2019 | DebugLoc DL = Op.getDebugLoc(); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2020 | EVT PtrVT = getPointerTy(); |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2021 | const BlockAddress *BA = cast<BlockAddressSDNode>(Op)->getBlockAddress(); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2022 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| 2023 | SDValue CPAddr; |
| 2024 | if (RelocM == Reloc::Static) { |
| 2025 | CPAddr = DAG.getTargetConstantPool(BA, PtrVT, 4); |
| 2026 | } else { |
| 2027 | unsigned PCAdj = Subtarget->isThumb() ? 4 : 8; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2028 | ARMPCLabelIndex = AFI->createPICLabelUId(); |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2029 | ARMConstantPoolValue *CPV = |
| 2030 | ARMConstantPoolConstant::Create(BA, ARMPCLabelIndex, |
| 2031 | ARMCP::CPBlockAddress, PCAdj); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2032 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
| 2033 | } |
| 2034 | CPAddr = DAG.getNode(ARMISD::Wrapper, DL, PtrVT, CPAddr); |
| 2035 | SDValue Result = DAG.getLoad(PtrVT, DL, DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2036 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2037 | false, false, false, 0); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2038 | if (RelocM == Reloc::Static) |
| 2039 | return Result; |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2040 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2041 | return DAG.getNode(ARMISD::PIC_ADD, DL, PtrVT, Result, PICLabel); |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 2042 | } |
| 2043 | |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2044 | // Lower ISD::GlobalTLSAddress using the "general dynamic" model |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2045 | SDValue |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2046 | ARMTargetLowering::LowerToTLSGeneralDynamicModel(GlobalAddressSDNode *GA, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2047 | SelectionDAG &DAG) const { |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2048 | DebugLoc dl = GA->getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2049 | EVT PtrVT = getPointerTy(); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2050 | unsigned char PCAdj = Subtarget->isThumb() ? 4 : 8; |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2051 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2052 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2053 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2054 | ARMConstantPoolValue *CPV = |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2055 | ARMConstantPoolConstant::Create(GA->getGlobal(), ARMPCLabelIndex, |
| 2056 | ARMCP::CPValue, PCAdj, ARMCP::TLSGD, true); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2057 | SDValue Argument = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2058 | Argument = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Argument); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2059 | Argument = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Argument, |
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); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2062 | SDValue Chain = Argument.getValue(1); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2063 | |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2064 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2065 | Argument = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Argument, PICLabel); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2066 | |
| 2067 | // call __tls_get_addr. |
| 2068 | ArgListTy Args; |
| 2069 | ArgListEntry Entry; |
| 2070 | Entry.Node = Argument; |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 2071 | Entry.Ty = (Type *) Type::getInt32Ty(*DAG.getContext()); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2072 | Args.push_back(Entry); |
Dale Johannesen | 7d2ad62 | 2009-01-30 23:10:59 +0000 | [diff] [blame] | 2073 | // FIXME: is there useful debug info available here? |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2074 | std::pair<SDValue, SDValue> CallResult = |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 2075 | LowerCallTo(Chain, (Type *) Type::getInt32Ty(*DAG.getContext()), |
Evan Cheng | 59bc060 | 2009-08-14 19:11:20 +0000 | [diff] [blame] | 2076 | false, false, false, false, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2077 | 0, CallingConv::C, false, /*isReturnValueUsed=*/true, |
Bill Wendling | 46ada19 | 2010-03-02 01:55:18 +0000 | [diff] [blame] | 2078 | DAG.getExternalSymbol("__tls_get_addr", PtrVT), Args, DAG, dl); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2079 | return CallResult.first; |
| 2080 | } |
| 2081 | |
| 2082 | // Lower ISD::GlobalTLSAddress using the "initial exec" or |
| 2083 | // "local exec" model. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2084 | SDValue |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2085 | ARMTargetLowering::LowerToTLSExecModels(GlobalAddressSDNode *GA, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2086 | SelectionDAG &DAG) const { |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2087 | const GlobalValue *GV = GA->getGlobal(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2088 | DebugLoc dl = GA->getDebugLoc(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2089 | SDValue Offset; |
| 2090 | SDValue Chain = DAG.getEntryNode(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2091 | EVT PtrVT = getPointerTy(); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2092 | // Get the Thread Pointer |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2093 | SDValue ThreadPointer = DAG.getNode(ARMISD::THREAD_POINTER, dl, PtrVT); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2094 | |
Chris Lattner | 4fb63d0 | 2009-07-15 04:12:33 +0000 | [diff] [blame] | 2095 | if (GV->isDeclaration()) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2096 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2097 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2098 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2099 | // Initial exec model. |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2100 | unsigned char PCAdj = Subtarget->isThumb() ? 4 : 8; |
| 2101 | ARMConstantPoolValue *CPV = |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2102 | ARMConstantPoolConstant::Create(GA->getGlobal(), ARMPCLabelIndex, |
| 2103 | ARMCP::CPValue, PCAdj, ARMCP::GOTTPOFF, |
| 2104 | true); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2105 | Offset = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2106 | Offset = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Offset); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2107 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2108 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2109 | false, false, false, 0); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2110 | Chain = Offset.getValue(1); |
| 2111 | |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2112 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2113 | Offset = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Offset, PICLabel); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2114 | |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2115 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2116 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2117 | false, false, false, 0); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2118 | } else { |
| 2119 | // local exec model |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2120 | ARMConstantPoolValue *CPV = |
| 2121 | ARMConstantPoolConstant::Create(GV, ARMCP::TPOFF); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2122 | Offset = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2123 | Offset = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Offset); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2124 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2125 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2126 | false, false, false, 0); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2127 | } |
| 2128 | |
| 2129 | // The address of the thread local variable is the add of the thread |
| 2130 | // pointer with the offset of the variable. |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2131 | return DAG.getNode(ISD::ADD, dl, PtrVT, ThreadPointer, Offset); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2132 | } |
| 2133 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2134 | SDValue |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2135 | ARMTargetLowering::LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const { |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2136 | // TODO: implement the "local dynamic" model |
| 2137 | assert(Subtarget->isTargetELF() && |
| 2138 | "TLS not implemented for non-ELF targets"); |
| 2139 | GlobalAddressSDNode *GA = cast<GlobalAddressSDNode>(Op); |
| 2140 | // If the relocation model is PIC, use the "General Dynamic" TLS Model, |
| 2141 | // otherwise use the "Local Exec" TLS Model |
| 2142 | if (getTargetMachine().getRelocationModel() == Reloc::PIC_) |
| 2143 | return LowerToTLSGeneralDynamicModel(GA, DAG); |
| 2144 | else |
| 2145 | return LowerToTLSExecModels(GA, DAG); |
| 2146 | } |
| 2147 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2148 | SDValue ARMTargetLowering::LowerGlobalAddressELF(SDValue Op, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2149 | SelectionDAG &DAG) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2150 | EVT PtrVT = getPointerTy(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2151 | DebugLoc dl = Op.getDebugLoc(); |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2152 | const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2153 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| 2154 | if (RelocM == Reloc::PIC_) { |
Rafael Espindola | bb46f52 | 2009-01-15 20:18:42 +0000 | [diff] [blame] | 2155 | bool UseGOTOFF = GV->hasLocalLinkage() || GV->hasHiddenVisibility(); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2156 | ARMConstantPoolValue *CPV = |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2157 | ARMConstantPoolConstant::Create(GV, |
| 2158 | UseGOTOFF ? ARMCP::GOTOFF : ARMCP::GOT); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2159 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2160 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2161 | SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 2162 | CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2163 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2164 | false, false, false, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2165 | SDValue Chain = Result.getValue(1); |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 2166 | SDValue GOT = DAG.getGLOBAL_OFFSET_TABLE(PtrVT); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2167 | Result = DAG.getNode(ISD::ADD, dl, PtrVT, Result, GOT); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2168 | if (!UseGOTOFF) |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 2169 | Result = DAG.getLoad(PtrVT, dl, Chain, Result, |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2170 | MachinePointerInfo::getGOT(), |
| 2171 | false, false, false, 0); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2172 | return Result; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2173 | } |
| 2174 | |
| 2175 | // 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] | 2176 | // pair. This is always cheaper. |
| 2177 | if (Subtarget->useMovt()) { |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2178 | ++NumMovwMovt; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2179 | // FIXME: Once remat is capable of dealing with instructions with register |
| 2180 | // operands, expand this into two nodes. |
| 2181 | return DAG.getNode(ARMISD::Wrapper, dl, PtrVT, |
| 2182 | DAG.getTargetGlobalAddress(GV, dl, PtrVT)); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2183 | } else { |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2184 | SDValue CPAddr = DAG.getTargetConstantPool(GV, PtrVT, 4); |
| 2185 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| 2186 | return DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
| 2187 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2188 | false, false, false, 0); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2189 | } |
| 2190 | } |
| 2191 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2192 | SDValue ARMTargetLowering::LowerGlobalAddressDarwin(SDValue Op, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2193 | SelectionDAG &DAG) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2194 | EVT PtrVT = getPointerTy(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2195 | DebugLoc dl = Op.getDebugLoc(); |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2196 | const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2197 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2198 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2199 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2200 | |
Jakob Stoklund Olesen | 8f37a24 | 2012-01-07 20:49:15 +0000 | [diff] [blame] | 2201 | // FIXME: Enable this for static codegen when tool issues are fixed. Also |
| 2202 | // update ARMFastISel::ARMMaterializeGV. |
Evan Cheng | f31151f | 2011-10-26 01:17:44 +0000 | [diff] [blame] | 2203 | if (Subtarget->useMovt() && RelocM != Reloc::Static) { |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2204 | ++NumMovwMovt; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2205 | // FIXME: Once remat is capable of dealing with instructions with register |
| 2206 | // operands, expand this into two nodes. |
Evan Cheng | 53519f0 | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 2207 | if (RelocM == Reloc::Static) |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2208 | return DAG.getNode(ARMISD::Wrapper, dl, PtrVT, |
| 2209 | DAG.getTargetGlobalAddress(GV, dl, PtrVT)); |
| 2210 | |
Evan Cheng | 53519f0 | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 2211 | unsigned Wrapper = (RelocM == Reloc::PIC_) |
| 2212 | ? ARMISD::WrapperPIC : ARMISD::WrapperDYN; |
| 2213 | SDValue Result = DAG.getNode(Wrapper, dl, PtrVT, |
Evan Cheng | 9fe2009 | 2011-01-20 08:34:58 +0000 | [diff] [blame] | 2214 | DAG.getTargetGlobalAddress(GV, dl, PtrVT)); |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2215 | if (Subtarget->GVIsIndirectSymbol(GV, RelocM)) |
| 2216 | Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Result, |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2217 | MachinePointerInfo::getGOT(), |
| 2218 | false, false, false, 0); |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2219 | return Result; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2220 | } |
| 2221 | |
| 2222 | unsigned ARMPCLabelIndex = 0; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2223 | SDValue CPAddr; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2224 | if (RelocM == Reloc::Static) { |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2225 | CPAddr = DAG.getTargetConstantPool(GV, PtrVT, 4); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2226 | } else { |
| 2227 | ARMPCLabelIndex = AFI->createPICLabelUId(); |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 2228 | unsigned PCAdj = (RelocM != Reloc::PIC_) ? 0 : (Subtarget->isThumb()?4:8); |
| 2229 | ARMConstantPoolValue *CPV = |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2230 | ARMConstantPoolConstant::Create(GV, ARMPCLabelIndex, ARMCP::CPValue, |
| 2231 | PCAdj); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2232 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2233 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2234 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2235 | |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2236 | SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2237 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2238 | false, false, false, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2239 | SDValue Chain = Result.getValue(1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2240 | |
| 2241 | if (RelocM == Reloc::PIC_) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2242 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2243 | Result = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2244 | } |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 2245 | |
Evan Cheng | 63476a8 | 2009-09-03 07:04:02 +0000 | [diff] [blame] | 2246 | if (Subtarget->GVIsIndirectSymbol(GV, RelocM)) |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2247 | Result = DAG.getLoad(PtrVT, dl, Chain, Result, MachinePointerInfo::getGOT(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2248 | false, false, false, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2249 | |
| 2250 | return Result; |
| 2251 | } |
| 2252 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2253 | SDValue ARMTargetLowering::LowerGLOBAL_OFFSET_TABLE(SDValue Op, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2254 | SelectionDAG &DAG) const { |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2255 | assert(Subtarget->isTargetELF() && |
| 2256 | "GLOBAL OFFSET TABLE not implemented for non-ELF targets"); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2257 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2258 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2259 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2260 | EVT PtrVT = getPointerTy(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2261 | DebugLoc dl = Op.getDebugLoc(); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2262 | unsigned PCAdj = Subtarget->isThumb() ? 4 : 8; |
Bill Wendling | fe31e67 | 2011-10-01 08:58:29 +0000 | [diff] [blame] | 2263 | ARMConstantPoolValue *CPV = |
| 2264 | ARMConstantPoolSymbol::Create(*DAG.getContext(), "_GLOBAL_OFFSET_TABLE_", |
| 2265 | ARMPCLabelIndex, PCAdj); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2266 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2267 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 2268 | SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2269 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2270 | false, false, false, 0); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2271 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2272 | return DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2273 | } |
| 2274 | |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 2275 | SDValue |
Jim Grosbach | 23ff7cf | 2010-05-26 20:22:18 +0000 | [diff] [blame] | 2276 | ARMTargetLowering::LowerEH_SJLJ_SETJMP(SDValue Op, SelectionDAG &DAG) const { |
| 2277 | DebugLoc dl = Op.getDebugLoc(); |
Jim Grosbach | 0798edd | 2010-05-27 23:49:24 +0000 | [diff] [blame] | 2278 | SDValue Val = DAG.getConstant(0, MVT::i32); |
Bill Wendling | ce370cf | 2011-10-07 21:25:38 +0000 | [diff] [blame] | 2279 | return DAG.getNode(ARMISD::EH_SJLJ_SETJMP, dl, |
| 2280 | DAG.getVTList(MVT::i32, MVT::Other), Op.getOperand(0), |
Jim Grosbach | 23ff7cf | 2010-05-26 20:22:18 +0000 | [diff] [blame] | 2281 | Op.getOperand(1), Val); |
| 2282 | } |
| 2283 | |
| 2284 | SDValue |
Jim Grosbach | 5eb1951 | 2010-05-22 01:06:18 +0000 | [diff] [blame] | 2285 | ARMTargetLowering::LowerEH_SJLJ_LONGJMP(SDValue Op, SelectionDAG &DAG) const { |
| 2286 | DebugLoc dl = Op.getDebugLoc(); |
| 2287 | return DAG.getNode(ARMISD::EH_SJLJ_LONGJMP, dl, MVT::Other, Op.getOperand(0), |
| 2288 | Op.getOperand(1), DAG.getConstant(0, MVT::i32)); |
| 2289 | } |
| 2290 | |
| 2291 | SDValue |
Jim Grosbach | a87ded2 | 2010-02-08 23:22:00 +0000 | [diff] [blame] | 2292 | ARMTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG, |
Jim Grosbach | 7616b64 | 2010-06-16 23:45:49 +0000 | [diff] [blame] | 2293 | const ARMSubtarget *Subtarget) const { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2294 | unsigned IntNo = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 2295 | DebugLoc dl = Op.getDebugLoc(); |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 2296 | switch (IntNo) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2297 | default: return SDValue(); // Don't custom lower most intrinsics. |
Bob Wilson | 916afdb | 2009-08-04 00:25:01 +0000 | [diff] [blame] | 2298 | case Intrinsic::arm_thread_pointer: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2299 | EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
Bob Wilson | 916afdb | 2009-08-04 00:25:01 +0000 | [diff] [blame] | 2300 | return DAG.getNode(ARMISD::THREAD_POINTER, dl, PtrVT); |
| 2301 | } |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2302 | case Intrinsic::eh_sjlj_lsda: { |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2303 | MachineFunction &MF = DAG.getMachineFunction(); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2304 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2305 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2306 | EVT PtrVT = getPointerTy(); |
| 2307 | DebugLoc dl = Op.getDebugLoc(); |
| 2308 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| 2309 | SDValue CPAddr; |
| 2310 | unsigned PCAdj = (RelocM != Reloc::PIC_) |
| 2311 | ? 0 : (Subtarget->isThumb() ? 4 : 8); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2312 | ARMConstantPoolValue *CPV = |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2313 | ARMConstantPoolConstant::Create(MF.getFunction(), ARMPCLabelIndex, |
| 2314 | ARMCP::CPLSDA, PCAdj); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2315 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2316 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2317 | SDValue Result = |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2318 | DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2319 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2320 | false, false, false, 0); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2321 | |
| 2322 | if (RelocM == Reloc::PIC_) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2323 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2324 | Result = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
| 2325 | } |
| 2326 | return Result; |
| 2327 | } |
Evan Cheng | 92e3916 | 2011-03-29 23:06:19 +0000 | [diff] [blame] | 2328 | case Intrinsic::arm_neon_vmulls: |
| 2329 | case Intrinsic::arm_neon_vmullu: { |
| 2330 | unsigned NewOpc = (IntNo == Intrinsic::arm_neon_vmulls) |
| 2331 | ? ARMISD::VMULLs : ARMISD::VMULLu; |
| 2332 | return DAG.getNode(NewOpc, Op.getDebugLoc(), Op.getValueType(), |
| 2333 | Op.getOperand(1), Op.getOperand(2)); |
| 2334 | } |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 2335 | } |
| 2336 | } |
| 2337 | |
Jim Grosbach | 7c03dbd | 2009-12-14 21:24:16 +0000 | [diff] [blame] | 2338 | static SDValue LowerMEMBARRIER(SDValue Op, SelectionDAG &DAG, |
Jim Grosbach | 7616b64 | 2010-06-16 23:45:49 +0000 | [diff] [blame] | 2339 | const ARMSubtarget *Subtarget) { |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 2340 | DebugLoc dl = Op.getDebugLoc(); |
Bob Wilson | f74a429 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 2341 | if (!Subtarget->hasDataBarrier()) { |
| 2342 | // Some ARMv6 cpus can support data barriers with an mcr instruction. |
| 2343 | // Thumb1 and pre-v6 ARM mode use a libcall instead and should never get |
| 2344 | // here. |
Bob Wilson | 54f9256 | 2010-11-09 22:50:44 +0000 | [diff] [blame] | 2345 | assert(Subtarget->hasV6Ops() && !Subtarget->isThumb() && |
Evan Cheng | 11db068 | 2010-08-11 06:22:01 +0000 | [diff] [blame] | 2346 | "Unexpected ISD::MEMBARRIER encountered. Should be libcall!"); |
Bob Wilson | f74a429 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 2347 | return DAG.getNode(ARMISD::MEMBARRIER_MCR, dl, MVT::Other, Op.getOperand(0), |
Jim Grosbach | c73993b | 2010-06-17 01:37:00 +0000 | [diff] [blame] | 2348 | DAG.getConstant(0, MVT::i32)); |
Evan Cheng | 11db068 | 2010-08-11 06:22:01 +0000 | [diff] [blame] | 2349 | } |
Bob Wilson | f74a429 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 2350 | |
| 2351 | SDValue Op5 = Op.getOperand(5); |
| 2352 | bool isDeviceBarrier = cast<ConstantSDNode>(Op5)->getZExtValue() != 0; |
| 2353 | unsigned isLL = cast<ConstantSDNode>(Op.getOperand(1))->getZExtValue(); |
| 2354 | unsigned isLS = cast<ConstantSDNode>(Op.getOperand(2))->getZExtValue(); |
| 2355 | bool isOnlyStoreBarrier = (isLL == 0 && isLS == 0); |
| 2356 | |
| 2357 | ARM_MB::MemBOpt DMBOpt; |
| 2358 | if (isDeviceBarrier) |
| 2359 | DMBOpt = isOnlyStoreBarrier ? ARM_MB::ST : ARM_MB::SY; |
| 2360 | else |
| 2361 | DMBOpt = isOnlyStoreBarrier ? ARM_MB::ISHST : ARM_MB::ISH; |
| 2362 | return DAG.getNode(ARMISD::MEMBARRIER, dl, MVT::Other, Op.getOperand(0), |
| 2363 | DAG.getConstant(DMBOpt, MVT::i32)); |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 2364 | } |
| 2365 | |
Eli Friedman | 26689ac | 2011-08-03 21:06:02 +0000 | [diff] [blame] | 2366 | |
| 2367 | static SDValue LowerATOMIC_FENCE(SDValue Op, SelectionDAG &DAG, |
| 2368 | const ARMSubtarget *Subtarget) { |
| 2369 | // FIXME: handle "fence singlethread" more efficiently. |
| 2370 | DebugLoc dl = Op.getDebugLoc(); |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 2371 | if (!Subtarget->hasDataBarrier()) { |
| 2372 | // Some ARMv6 cpus can support data barriers with an mcr instruction. |
| 2373 | // Thumb1 and pre-v6 ARM mode use a libcall instead and should never get |
| 2374 | // here. |
| 2375 | assert(Subtarget->hasV6Ops() && !Subtarget->isThumb() && |
| 2376 | "Unexpected ISD::MEMBARRIER encountered. Should be libcall!"); |
Eli Friedman | 26689ac | 2011-08-03 21:06:02 +0000 | [diff] [blame] | 2377 | return DAG.getNode(ARMISD::MEMBARRIER_MCR, dl, MVT::Other, Op.getOperand(0), |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 2378 | DAG.getConstant(0, MVT::i32)); |
| 2379 | } |
| 2380 | |
Eli Friedman | 26689ac | 2011-08-03 21:06:02 +0000 | [diff] [blame] | 2381 | return DAG.getNode(ARMISD::MEMBARRIER, dl, MVT::Other, Op.getOperand(0), |
Eli Friedman | 989f61e | 2011-08-02 22:44:16 +0000 | [diff] [blame] | 2382 | DAG.getConstant(ARM_MB::ISH, MVT::i32)); |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 2383 | } |
| 2384 | |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2385 | static SDValue LowerPREFETCH(SDValue Op, SelectionDAG &DAG, |
| 2386 | const ARMSubtarget *Subtarget) { |
| 2387 | // ARM pre v5TE and Thumb1 does not have preload instructions. |
| 2388 | if (!(Subtarget->isThumb2() || |
| 2389 | (!Subtarget->isThumb1Only() && Subtarget->hasV5TEOps()))) |
| 2390 | // Just preserve the chain. |
| 2391 | return Op.getOperand(0); |
| 2392 | |
| 2393 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 2394 | unsigned isRead = ~cast<ConstantSDNode>(Op.getOperand(2))->getZExtValue() & 1; |
| 2395 | if (!isRead && |
| 2396 | (!Subtarget->hasV7Ops() || !Subtarget->hasMPExtension())) |
| 2397 | // ARMv7 with MP extension has PLDW. |
| 2398 | return Op.getOperand(0); |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2399 | |
Bruno Cardoso Lopes | 9a76733 | 2011-06-14 04:58:37 +0000 | [diff] [blame] | 2400 | unsigned isData = cast<ConstantSDNode>(Op.getOperand(4))->getZExtValue(); |
| 2401 | if (Subtarget->isThumb()) { |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2402 | // Invert the bits. |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 2403 | isRead = ~isRead & 1; |
Bruno Cardoso Lopes | 9a76733 | 2011-06-14 04:58:37 +0000 | [diff] [blame] | 2404 | isData = ~isData & 1; |
| 2405 | } |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2406 | |
| 2407 | return DAG.getNode(ARMISD::PRELOAD, dl, MVT::Other, Op.getOperand(0), |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 2408 | Op.getOperand(1), DAG.getConstant(isRead, MVT::i32), |
| 2409 | DAG.getConstant(isData, MVT::i32)); |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2410 | } |
| 2411 | |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 2412 | static SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) { |
| 2413 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2414 | ARMFunctionInfo *FuncInfo = MF.getInfo<ARMFunctionInfo>(); |
| 2415 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2416 | // vastart just stores the address of the VarArgsFrameIndex slot into the |
| 2417 | // memory location argument. |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2418 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2419 | EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 2420 | SDValue FR = DAG.getFrameIndex(FuncInfo->getVarArgsFrameIndex(), PtrVT); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 2421 | const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue(); |
Chris Lattner | fc448ff | 2010-09-21 18:51:21 +0000 | [diff] [blame] | 2422 | return DAG.getStore(Op.getOperand(0), dl, FR, Op.getOperand(1), |
| 2423 | MachinePointerInfo(SV), false, false, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2424 | } |
| 2425 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2426 | SDValue |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2427 | ARMTargetLowering::GetF64FormalArgument(CCValAssign &VA, CCValAssign &NextVA, |
| 2428 | SDValue &Root, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2429 | DebugLoc dl) const { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2430 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2431 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2432 | |
Craig Topper | 44d2382 | 2012-02-22 05:59:10 +0000 | [diff] [blame] | 2433 | const TargetRegisterClass *RC; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 2434 | if (AFI->isThumb1OnlyFunction()) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2435 | RC = ARM::tGPRRegisterClass; |
| 2436 | else |
| 2437 | RC = ARM::GPRRegisterClass; |
| 2438 | |
| 2439 | // Transform the arguments stored in physical registers into virtual ones. |
Devang Patel | 68e6bee | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 2440 | unsigned Reg = MF.addLiveIn(VA.getLocReg(), RC); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2441 | SDValue ArgValue = DAG.getCopyFromReg(Root, dl, Reg, MVT::i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2442 | |
| 2443 | SDValue ArgValue2; |
| 2444 | if (NextVA.isMemLoc()) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2445 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
Evan Cheng | ed2ae13 | 2010-07-03 00:40:23 +0000 | [diff] [blame] | 2446 | int FI = MFI->CreateFixedObject(4, NextVA.getLocMemOffset(), true); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2447 | |
| 2448 | // Create load node to retrieve arguments from the stack. |
| 2449 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2450 | ArgValue2 = DAG.getLoad(MVT::i32, dl, Root, FIN, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2451 | MachinePointerInfo::getFixedStack(FI), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2452 | false, false, false, 0); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2453 | } else { |
Devang Patel | 68e6bee | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 2454 | Reg = MF.addLiveIn(NextVA.getLocReg(), RC); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2455 | ArgValue2 = DAG.getCopyFromReg(Root, dl, Reg, MVT::i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2456 | } |
| 2457 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 2458 | return DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, ArgValue, ArgValue2); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2459 | } |
| 2460 | |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2461 | void |
| 2462 | ARMTargetLowering::computeRegArea(CCState &CCInfo, MachineFunction &MF, |
| 2463 | unsigned &VARegSize, unsigned &VARegSaveSize) |
| 2464 | const { |
| 2465 | unsigned NumGPRs; |
| 2466 | if (CCInfo.isFirstByValRegValid()) |
| 2467 | NumGPRs = ARM::R4 - CCInfo.getFirstByValReg(); |
| 2468 | else { |
| 2469 | unsigned int firstUnalloced; |
| 2470 | firstUnalloced = CCInfo.getFirstUnallocated(GPRArgRegs, |
| 2471 | sizeof(GPRArgRegs) / |
| 2472 | sizeof(GPRArgRegs[0])); |
| 2473 | NumGPRs = (firstUnalloced <= 3) ? (4 - firstUnalloced) : 0; |
| 2474 | } |
| 2475 | |
| 2476 | unsigned Align = MF.getTarget().getFrameLowering()->getStackAlignment(); |
| 2477 | VARegSize = NumGPRs * 4; |
| 2478 | VARegSaveSize = (VARegSize + Align - 1) & ~(Align - 1); |
| 2479 | } |
| 2480 | |
| 2481 | // The remaining GPRs hold either the beginning of variable-argument |
| 2482 | // data, or the beginning of an aggregate passed by value (usuall |
| 2483 | // byval). Either way, we allocate stack slots adjacent to the data |
| 2484 | // provided by our caller, and store the unallocated registers there. |
| 2485 | // If this is a variadic function, the va_list pointer will begin with |
| 2486 | // these values; otherwise, this reassembles a (byval) structure that |
| 2487 | // was split between registers and memory. |
| 2488 | void |
| 2489 | ARMTargetLowering::VarArgStyleRegisters(CCState &CCInfo, SelectionDAG &DAG, |
| 2490 | DebugLoc dl, SDValue &Chain, |
| 2491 | unsigned ArgOffset) const { |
| 2492 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2493 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 2494 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2495 | unsigned firstRegToSaveIndex; |
| 2496 | if (CCInfo.isFirstByValRegValid()) |
| 2497 | firstRegToSaveIndex = CCInfo.getFirstByValReg() - ARM::R0; |
| 2498 | else { |
| 2499 | firstRegToSaveIndex = CCInfo.getFirstUnallocated |
| 2500 | (GPRArgRegs, sizeof(GPRArgRegs) / sizeof(GPRArgRegs[0])); |
| 2501 | } |
| 2502 | |
| 2503 | unsigned VARegSize, VARegSaveSize; |
| 2504 | computeRegArea(CCInfo, MF, VARegSize, VARegSaveSize); |
| 2505 | if (VARegSaveSize) { |
| 2506 | // If this function is vararg, store any remaining integer argument regs |
| 2507 | // to their spots on the stack so that they may be loaded by deferencing |
| 2508 | // the result of va_next. |
| 2509 | AFI->setVarArgsRegSaveSize(VARegSaveSize); |
Eric Christopher | 5ac179c | 2011-04-29 23:12:01 +0000 | [diff] [blame] | 2510 | AFI->setVarArgsFrameIndex(MFI->CreateFixedObject(VARegSaveSize, |
| 2511 | ArgOffset + VARegSaveSize |
| 2512 | - VARegSize, |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2513 | false)); |
| 2514 | SDValue FIN = DAG.getFrameIndex(AFI->getVarArgsFrameIndex(), |
| 2515 | getPointerTy()); |
| 2516 | |
| 2517 | SmallVector<SDValue, 4> MemOps; |
| 2518 | for (; firstRegToSaveIndex < 4; ++firstRegToSaveIndex) { |
Craig Topper | 44d2382 | 2012-02-22 05:59:10 +0000 | [diff] [blame] | 2519 | const TargetRegisterClass *RC; |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2520 | if (AFI->isThumb1OnlyFunction()) |
| 2521 | RC = ARM::tGPRRegisterClass; |
| 2522 | else |
| 2523 | RC = ARM::GPRRegisterClass; |
| 2524 | |
| 2525 | unsigned VReg = MF.addLiveIn(GPRArgRegs[firstRegToSaveIndex], RC); |
| 2526 | SDValue Val = DAG.getCopyFromReg(Chain, dl, VReg, MVT::i32); |
| 2527 | SDValue Store = |
| 2528 | DAG.getStore(Val.getValue(1), dl, Val, FIN, |
Eric Christopher | 5ac179c | 2011-04-29 23:12:01 +0000 | [diff] [blame] | 2529 | MachinePointerInfo::getFixedStack(AFI->getVarArgsFrameIndex()), |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2530 | false, false, 0); |
| 2531 | MemOps.push_back(Store); |
| 2532 | FIN = DAG.getNode(ISD::ADD, dl, getPointerTy(), FIN, |
| 2533 | DAG.getConstant(4, getPointerTy())); |
| 2534 | } |
| 2535 | if (!MemOps.empty()) |
| 2536 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, |
| 2537 | &MemOps[0], MemOps.size()); |
| 2538 | } else |
| 2539 | // This will point to the next argument passed via stack. |
| 2540 | AFI->setVarArgsFrameIndex(MFI->CreateFixedObject(4, ArgOffset, true)); |
| 2541 | } |
| 2542 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2543 | SDValue |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2544 | ARMTargetLowering::LowerFormalArguments(SDValue Chain, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 2545 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2546 | const SmallVectorImpl<ISD::InputArg> |
| 2547 | &Ins, |
| 2548 | DebugLoc dl, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2549 | SmallVectorImpl<SDValue> &InVals) |
| 2550 | const { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2551 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2552 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 2553 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2554 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2555 | |
| 2556 | // Assign locations to all of the incoming arguments. |
| 2557 | SmallVector<CCValAssign, 16> ArgLocs; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 2558 | ARMCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), |
| 2559 | getTargetMachine(), ArgLocs, *DAG.getContext(), Prologue); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2560 | CCInfo.AnalyzeFormalArguments(Ins, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 2561 | CCAssignFnForNode(CallConv, /* Return*/ false, |
| 2562 | isVarArg)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2563 | |
| 2564 | SmallVector<SDValue, 16> ArgValues; |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2565 | int lastInsIndex = -1; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2566 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2567 | SDValue ArgValue; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2568 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| 2569 | CCValAssign &VA = ArgLocs[i]; |
| 2570 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 2571 | // Arguments stored in registers. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2572 | if (VA.isRegLoc()) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2573 | EVT RegVT = VA.getLocVT(); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2574 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2575 | if (VA.needsCustom()) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2576 | // f64 and vector types are split up into multiple registers or |
| 2577 | // combinations of registers and stack slots. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2578 | if (VA.getLocVT() == MVT::v2f64) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2579 | SDValue ArgValue1 = GetF64FormalArgument(VA, ArgLocs[++i], |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2580 | Chain, DAG, dl); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2581 | VA = ArgLocs[++i]; // skip ahead to next loc |
Bob Wilson | 6a234f0 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 2582 | SDValue ArgValue2; |
| 2583 | if (VA.isMemLoc()) { |
Evan Cheng | ed2ae13 | 2010-07-03 00:40:23 +0000 | [diff] [blame] | 2584 | int FI = MFI->CreateFixedObject(8, VA.getLocMemOffset(), true); |
Bob Wilson | 6a234f0 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 2585 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
| 2586 | ArgValue2 = DAG.getLoad(MVT::f64, dl, Chain, FIN, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2587 | MachinePointerInfo::getFixedStack(FI), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2588 | false, false, false, 0); |
Bob Wilson | 6a234f0 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 2589 | } else { |
| 2590 | ArgValue2 = GetF64FormalArgument(VA, ArgLocs[++i], |
| 2591 | Chain, DAG, dl); |
| 2592 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2593 | ArgValue = DAG.getNode(ISD::UNDEF, dl, MVT::v2f64); |
| 2594 | ArgValue = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2595 | ArgValue, ArgValue1, DAG.getIntPtrConstant(0)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2596 | ArgValue = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2597 | ArgValue, ArgValue2, DAG.getIntPtrConstant(1)); |
| 2598 | } else |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2599 | ArgValue = GetF64FormalArgument(VA, ArgLocs[++i], Chain, DAG, dl); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2600 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2601 | } else { |
Craig Topper | 44d2382 | 2012-02-22 05:59:10 +0000 | [diff] [blame] | 2602 | const TargetRegisterClass *RC; |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 2603 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2604 | if (RegVT == MVT::f32) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2605 | RC = ARM::SPRRegisterClass; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2606 | else if (RegVT == MVT::f64) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2607 | RC = ARM::DPRRegisterClass; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2608 | else if (RegVT == MVT::v2f64) |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 2609 | RC = ARM::QPRRegisterClass; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2610 | else if (RegVT == MVT::i32) |
Anton Korobeynikov | 058c251 | 2009-08-05 20:15:19 +0000 | [diff] [blame] | 2611 | RC = (AFI->isThumb1OnlyFunction() ? |
| 2612 | ARM::tGPRRegisterClass : ARM::GPRRegisterClass); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2613 | else |
Anton Korobeynikov | 058c251 | 2009-08-05 20:15:19 +0000 | [diff] [blame] | 2614 | llvm_unreachable("RegVT not supported by FORMAL_ARGUMENTS Lowering"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2615 | |
| 2616 | // Transform the arguments in physical registers into virtual ones. |
Devang Patel | 68e6bee | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 2617 | unsigned Reg = MF.addLiveIn(VA.getLocReg(), RC); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2618 | ArgValue = DAG.getCopyFromReg(Chain, dl, Reg, RegVT); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2619 | } |
| 2620 | |
| 2621 | // If this is an 8 or 16-bit value, it is really passed promoted |
| 2622 | // to 32 bits. Insert an assert[sz]ext to capture this, then |
| 2623 | // truncate to the right size. |
| 2624 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 2625 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2626 | case CCValAssign::Full: break; |
| 2627 | case CCValAssign::BCvt: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2628 | ArgValue = DAG.getNode(ISD::BITCAST, dl, VA.getValVT(), ArgValue); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2629 | break; |
| 2630 | case CCValAssign::SExt: |
| 2631 | ArgValue = DAG.getNode(ISD::AssertSext, dl, RegVT, ArgValue, |
| 2632 | DAG.getValueType(VA.getValVT())); |
| 2633 | ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue); |
| 2634 | break; |
| 2635 | case CCValAssign::ZExt: |
| 2636 | ArgValue = DAG.getNode(ISD::AssertZext, dl, RegVT, ArgValue, |
| 2637 | DAG.getValueType(VA.getValVT())); |
| 2638 | ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue); |
| 2639 | break; |
| 2640 | } |
| 2641 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2642 | InVals.push_back(ArgValue); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2643 | |
| 2644 | } else { // VA.isRegLoc() |
| 2645 | |
| 2646 | // sanity check |
| 2647 | assert(VA.isMemLoc()); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2648 | assert(VA.getValVT() != MVT::i64 && "i64 should already be lowered"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2649 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2650 | int index = ArgLocs[i].getValNo(); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 2651 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2652 | // Some Ins[] entries become multiple ArgLoc[] entries. |
| 2653 | // Process them only once. |
| 2654 | if (index != lastInsIndex) |
| 2655 | { |
| 2656 | ISD::ArgFlagsTy Flags = Ins[index].Flags; |
Eric Christopher | 471e422 | 2011-06-08 23:55:35 +0000 | [diff] [blame] | 2657 | // FIXME: For now, all byval parameter objects are marked mutable. |
Eric Christopher | 5ac179c | 2011-04-29 23:12:01 +0000 | [diff] [blame] | 2658 | // This can be changed with more analysis. |
| 2659 | // In case of tail call optimization mark all arguments mutable. |
| 2660 | // Since they could be overwritten by lowering of arguments in case of |
| 2661 | // a tail call. |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2662 | if (Flags.isByVal()) { |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2663 | unsigned VARegSize, VARegSaveSize; |
| 2664 | computeRegArea(CCInfo, MF, VARegSize, VARegSaveSize); |
| 2665 | VarArgStyleRegisters(CCInfo, DAG, dl, Chain, 0); |
| 2666 | unsigned Bytes = Flags.getByValSize() - VARegSize; |
Evan Cheng | ee2e0e3 | 2011-03-30 23:44:13 +0000 | [diff] [blame] | 2667 | if (Bytes == 0) Bytes = 1; // Don't create zero-sized stack objects. |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2668 | int FI = MFI->CreateFixedObject(Bytes, |
| 2669 | VA.getLocMemOffset(), false); |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2670 | InVals.push_back(DAG.getFrameIndex(FI, getPointerTy())); |
| 2671 | } else { |
| 2672 | int FI = MFI->CreateFixedObject(VA.getLocVT().getSizeInBits()/8, |
| 2673 | VA.getLocMemOffset(), true); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2674 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2675 | // Create load nodes to retrieve arguments from the stack. |
| 2676 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
| 2677 | InVals.push_back(DAG.getLoad(VA.getValVT(), dl, Chain, FIN, |
| 2678 | MachinePointerInfo::getFixedStack(FI), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2679 | false, false, false, 0)); |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2680 | } |
| 2681 | lastInsIndex = index; |
| 2682 | } |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2683 | } |
| 2684 | } |
| 2685 | |
| 2686 | // varargs |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2687 | if (isVarArg) |
| 2688 | VarArgStyleRegisters(CCInfo, DAG, dl, Chain, CCInfo.getNextStackOffset()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2689 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2690 | return Chain; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2691 | } |
| 2692 | |
| 2693 | /// isFloatingPointZero - Return true if this is +0.0. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2694 | static bool isFloatingPointZero(SDValue Op) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2695 | if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(Op)) |
Dale Johannesen | eaf0894 | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 2696 | return CFP->getValueAPF().isPosZero(); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2697 | else if (ISD::isEXTLoad(Op.getNode()) || ISD::isNON_EXTLoad(Op.getNode())) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2698 | // Maybe this has already been legalized into the constant pool? |
| 2699 | if (Op.getOperand(1).getOpcode() == ARMISD::Wrapper) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2700 | SDValue WrapperOp = Op.getOperand(1).getOperand(0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2701 | if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(WrapperOp)) |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2702 | if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CP->getConstVal())) |
Dale Johannesen | eaf0894 | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 2703 | return CFP->getValueAPF().isPosZero(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2704 | } |
| 2705 | } |
| 2706 | return false; |
| 2707 | } |
| 2708 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2709 | /// Returns appropriate ARM CMP (cmp) and corresponding condition code for |
| 2710 | /// the given operands. |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 2711 | SDValue |
| 2712 | ARMTargetLowering::getARMCmp(SDValue LHS, SDValue RHS, ISD::CondCode CC, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2713 | SDValue &ARMcc, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2714 | DebugLoc dl) const { |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2715 | if (ConstantSDNode *RHSC = dyn_cast<ConstantSDNode>(RHS.getNode())) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2716 | unsigned C = RHSC->getZExtValue(); |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 2717 | if (!isLegalICmpImmediate(C)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2718 | // Constant does not fit, try adjusting it by one? |
| 2719 | switch (CC) { |
| 2720 | default: break; |
| 2721 | case ISD::SETLT: |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2722 | case ISD::SETGE: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 2723 | if (C != 0x80000000 && isLegalICmpImmediate(C-1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2724 | CC = (CC == ISD::SETLT) ? ISD::SETLE : ISD::SETGT; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2725 | RHS = DAG.getConstant(C-1, MVT::i32); |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2726 | } |
| 2727 | break; |
| 2728 | case ISD::SETULT: |
| 2729 | case ISD::SETUGE: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 2730 | if (C != 0 && isLegalICmpImmediate(C-1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2731 | CC = (CC == ISD::SETULT) ? ISD::SETULE : ISD::SETUGT; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2732 | RHS = DAG.getConstant(C-1, MVT::i32); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2733 | } |
| 2734 | break; |
| 2735 | case ISD::SETLE: |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2736 | case ISD::SETGT: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 2737 | if (C != 0x7fffffff && isLegalICmpImmediate(C+1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2738 | CC = (CC == ISD::SETLE) ? ISD::SETLT : ISD::SETGE; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2739 | RHS = DAG.getConstant(C+1, MVT::i32); |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2740 | } |
| 2741 | break; |
| 2742 | case ISD::SETULE: |
| 2743 | case ISD::SETUGT: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 2744 | if (C != 0xffffffff && isLegalICmpImmediate(C+1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2745 | CC = (CC == ISD::SETULE) ? ISD::SETULT : ISD::SETUGE; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2746 | RHS = DAG.getConstant(C+1, MVT::i32); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2747 | } |
| 2748 | break; |
| 2749 | } |
| 2750 | } |
| 2751 | } |
| 2752 | |
| 2753 | ARMCC::CondCodes CondCode = IntCCToARMCC(CC); |
Lauro Ramos Venancio | 9996663 | 2007-04-02 01:30:03 +0000 | [diff] [blame] | 2754 | ARMISD::NodeType CompareType; |
| 2755 | switch (CondCode) { |
| 2756 | default: |
| 2757 | CompareType = ARMISD::CMP; |
| 2758 | break; |
| 2759 | case ARMCC::EQ: |
| 2760 | case ARMCC::NE: |
David Goodwin | c0309b4 | 2009-06-29 15:33:01 +0000 | [diff] [blame] | 2761 | // Uses only Z Flag |
| 2762 | CompareType = ARMISD::CMPZ; |
Lauro Ramos Venancio | 9996663 | 2007-04-02 01:30:03 +0000 | [diff] [blame] | 2763 | break; |
| 2764 | } |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2765 | ARMcc = DAG.getConstant(CondCode, MVT::i32); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 2766 | return DAG.getNode(CompareType, dl, MVT::Glue, LHS, RHS); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2767 | } |
| 2768 | |
| 2769 | /// 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] | 2770 | SDValue |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2771 | ARMTargetLowering::getVFPCmp(SDValue LHS, SDValue RHS, SelectionDAG &DAG, |
Evan Cheng | 515fe3a | 2010-07-08 02:08:50 +0000 | [diff] [blame] | 2772 | DebugLoc dl) const { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2773 | SDValue Cmp; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2774 | if (!isFloatingPointZero(RHS)) |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 2775 | Cmp = DAG.getNode(ARMISD::CMPFP, dl, MVT::Glue, LHS, RHS); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2776 | else |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 2777 | Cmp = DAG.getNode(ARMISD::CMPFPw0, dl, MVT::Glue, LHS); |
| 2778 | return DAG.getNode(ARMISD::FMSTAT, dl, MVT::Glue, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2779 | } |
| 2780 | |
Bob Wilson | 79f56c9 | 2011-03-08 01:17:20 +0000 | [diff] [blame] | 2781 | /// duplicateCmp - Glue values can have only one use, so this function |
| 2782 | /// duplicates a comparison node. |
| 2783 | SDValue |
| 2784 | ARMTargetLowering::duplicateCmp(SDValue Cmp, SelectionDAG &DAG) const { |
| 2785 | unsigned Opc = Cmp.getOpcode(); |
| 2786 | DebugLoc DL = Cmp.getDebugLoc(); |
| 2787 | if (Opc == ARMISD::CMP || Opc == ARMISD::CMPZ) |
| 2788 | return DAG.getNode(Opc, DL, MVT::Glue, Cmp.getOperand(0),Cmp.getOperand(1)); |
| 2789 | |
| 2790 | assert(Opc == ARMISD::FMSTAT && "unexpected comparison operation"); |
| 2791 | Cmp = Cmp.getOperand(0); |
| 2792 | Opc = Cmp.getOpcode(); |
| 2793 | if (Opc == ARMISD::CMPFP) |
| 2794 | Cmp = DAG.getNode(Opc, DL, MVT::Glue, Cmp.getOperand(0),Cmp.getOperand(1)); |
| 2795 | else { |
| 2796 | assert(Opc == ARMISD::CMPFPw0 && "unexpected operand of FMSTAT"); |
| 2797 | Cmp = DAG.getNode(Opc, DL, MVT::Glue, Cmp.getOperand(0)); |
| 2798 | } |
| 2799 | return DAG.getNode(ARMISD::FMSTAT, DL, MVT::Glue, Cmp); |
| 2800 | } |
| 2801 | |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 2802 | SDValue ARMTargetLowering::LowerSELECT(SDValue Op, SelectionDAG &DAG) const { |
| 2803 | SDValue Cond = Op.getOperand(0); |
| 2804 | SDValue SelectTrue = Op.getOperand(1); |
| 2805 | SDValue SelectFalse = Op.getOperand(2); |
| 2806 | DebugLoc dl = Op.getDebugLoc(); |
| 2807 | |
| 2808 | // Convert: |
| 2809 | // |
| 2810 | // (select (cmov 1, 0, cond), t, f) -> (cmov t, f, cond) |
| 2811 | // (select (cmov 0, 1, cond), t, f) -> (cmov f, t, cond) |
| 2812 | // |
| 2813 | if (Cond.getOpcode() == ARMISD::CMOV && Cond.hasOneUse()) { |
| 2814 | const ConstantSDNode *CMOVTrue = |
| 2815 | dyn_cast<ConstantSDNode>(Cond.getOperand(0)); |
| 2816 | const ConstantSDNode *CMOVFalse = |
| 2817 | dyn_cast<ConstantSDNode>(Cond.getOperand(1)); |
| 2818 | |
| 2819 | if (CMOVTrue && CMOVFalse) { |
| 2820 | unsigned CMOVTrueVal = CMOVTrue->getZExtValue(); |
| 2821 | unsigned CMOVFalseVal = CMOVFalse->getZExtValue(); |
| 2822 | |
| 2823 | SDValue True; |
| 2824 | SDValue False; |
| 2825 | if (CMOVTrueVal == 1 && CMOVFalseVal == 0) { |
| 2826 | True = SelectTrue; |
| 2827 | False = SelectFalse; |
| 2828 | } else if (CMOVTrueVal == 0 && CMOVFalseVal == 1) { |
| 2829 | True = SelectFalse; |
| 2830 | False = SelectTrue; |
| 2831 | } |
| 2832 | |
| 2833 | if (True.getNode() && False.getNode()) { |
Evan Cheng | b936e30 | 2011-05-18 18:59:17 +0000 | [diff] [blame] | 2834 | EVT VT = Op.getValueType(); |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 2835 | SDValue ARMcc = Cond.getOperand(2); |
| 2836 | SDValue CCR = Cond.getOperand(3); |
Bob Wilson | 79f56c9 | 2011-03-08 01:17:20 +0000 | [diff] [blame] | 2837 | SDValue Cmp = duplicateCmp(Cond.getOperand(4), DAG); |
Evan Cheng | b936e30 | 2011-05-18 18:59:17 +0000 | [diff] [blame] | 2838 | assert(True.getValueType() == VT); |
| 2839 | return DAG.getNode(ARMISD::CMOV, dl, VT, True, False, ARMcc, CCR, Cmp); |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 2840 | } |
| 2841 | } |
| 2842 | } |
| 2843 | |
| 2844 | return DAG.getSelectCC(dl, Cond, |
| 2845 | DAG.getConstant(0, Cond.getValueType()), |
| 2846 | SelectTrue, SelectFalse, ISD::SETNE); |
| 2847 | } |
| 2848 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2849 | SDValue ARMTargetLowering::LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2850 | EVT VT = Op.getValueType(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2851 | SDValue LHS = Op.getOperand(0); |
| 2852 | SDValue RHS = Op.getOperand(1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2853 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(4))->get(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2854 | SDValue TrueVal = Op.getOperand(2); |
| 2855 | SDValue FalseVal = Op.getOperand(3); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2856 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2857 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2858 | if (LHS.getValueType() == MVT::i32) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2859 | SDValue ARMcc; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2860 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2861 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMcc, DAG, dl); |
Jim Grosbach | b04546f | 2011-09-13 20:30:37 +0000 | [diff] [blame] | 2862 | return DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, ARMcc, CCR,Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2863 | } |
| 2864 | |
| 2865 | ARMCC::CondCodes CondCode, CondCode2; |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 2866 | FPCCToARMCC(CC, CondCode, CondCode2); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2867 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2868 | SDValue ARMcc = DAG.getConstant(CondCode, MVT::i32); |
| 2869 | SDValue Cmp = getVFPCmp(LHS, RHS, DAG, dl); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2870 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2871 | SDValue Result = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2872 | ARMcc, CCR, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2873 | if (CondCode2 != ARMCC::AL) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2874 | SDValue ARMcc2 = DAG.getConstant(CondCode2, MVT::i32); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2875 | // FIXME: Needs another CMP because flag can have but one use. |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2876 | SDValue Cmp2 = getVFPCmp(LHS, RHS, DAG, dl); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2877 | Result = DAG.getNode(ARMISD::CMOV, dl, VT, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2878 | Result, TrueVal, ARMcc2, CCR, Cmp2); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2879 | } |
| 2880 | return Result; |
| 2881 | } |
| 2882 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2883 | /// canChangeToInt - Given the fp compare operand, return true if it is suitable |
| 2884 | /// to morph to an integer compare sequence. |
| 2885 | static bool canChangeToInt(SDValue Op, bool &SeenZero, |
| 2886 | const ARMSubtarget *Subtarget) { |
| 2887 | SDNode *N = Op.getNode(); |
| 2888 | if (!N->hasOneUse()) |
| 2889 | // Otherwise it requires moving the value from fp to integer registers. |
| 2890 | return false; |
| 2891 | if (!N->getNumValues()) |
| 2892 | return false; |
| 2893 | EVT VT = Op.getValueType(); |
| 2894 | if (VT != MVT::f32 && !Subtarget->isFPBrccSlow()) |
| 2895 | // f32 case is generally profitable. f64 case only makes sense when vcmpe + |
| 2896 | // vmrs are very slow, e.g. cortex-a8. |
| 2897 | return false; |
| 2898 | |
| 2899 | if (isFloatingPointZero(Op)) { |
| 2900 | SeenZero = true; |
| 2901 | return true; |
| 2902 | } |
| 2903 | return ISD::isNormalLoad(N); |
| 2904 | } |
| 2905 | |
| 2906 | static SDValue bitcastf32Toi32(SDValue Op, SelectionDAG &DAG) { |
| 2907 | if (isFloatingPointZero(Op)) |
| 2908 | return DAG.getConstant(0, MVT::i32); |
| 2909 | |
| 2910 | if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Op)) |
| 2911 | return DAG.getLoad(MVT::i32, Op.getDebugLoc(), |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2912 | Ld->getChain(), Ld->getBasePtr(), Ld->getPointerInfo(), |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2913 | Ld->isVolatile(), Ld->isNonTemporal(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2914 | Ld->isInvariant(), Ld->getAlignment()); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2915 | |
| 2916 | llvm_unreachable("Unknown VFP cmp argument!"); |
| 2917 | } |
| 2918 | |
| 2919 | static void expandf64Toi32(SDValue Op, SelectionDAG &DAG, |
| 2920 | SDValue &RetVal1, SDValue &RetVal2) { |
| 2921 | if (isFloatingPointZero(Op)) { |
| 2922 | RetVal1 = DAG.getConstant(0, MVT::i32); |
| 2923 | RetVal2 = DAG.getConstant(0, MVT::i32); |
| 2924 | return; |
| 2925 | } |
| 2926 | |
| 2927 | if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Op)) { |
| 2928 | SDValue Ptr = Ld->getBasePtr(); |
| 2929 | RetVal1 = DAG.getLoad(MVT::i32, Op.getDebugLoc(), |
| 2930 | Ld->getChain(), Ptr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2931 | Ld->getPointerInfo(), |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2932 | Ld->isVolatile(), Ld->isNonTemporal(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2933 | Ld->isInvariant(), Ld->getAlignment()); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2934 | |
| 2935 | EVT PtrType = Ptr.getValueType(); |
| 2936 | unsigned NewAlign = MinAlign(Ld->getAlignment(), 4); |
| 2937 | SDValue NewPtr = DAG.getNode(ISD::ADD, Op.getDebugLoc(), |
| 2938 | PtrType, Ptr, DAG.getConstant(4, PtrType)); |
| 2939 | RetVal2 = DAG.getLoad(MVT::i32, Op.getDebugLoc(), |
| 2940 | Ld->getChain(), NewPtr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2941 | Ld->getPointerInfo().getWithOffset(4), |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2942 | Ld->isVolatile(), Ld->isNonTemporal(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2943 | Ld->isInvariant(), NewAlign); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2944 | return; |
| 2945 | } |
| 2946 | |
| 2947 | llvm_unreachable("Unknown VFP cmp argument!"); |
| 2948 | } |
| 2949 | |
| 2950 | /// OptimizeVFPBrcond - With -enable-unsafe-fp-math, it's legal to optimize some |
| 2951 | /// f32 and even f64 comparisons to integer ones. |
| 2952 | SDValue |
| 2953 | ARMTargetLowering::OptimizeVFPBrcond(SDValue Op, SelectionDAG &DAG) const { |
| 2954 | SDValue Chain = Op.getOperand(0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2955 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get(); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2956 | SDValue LHS = Op.getOperand(2); |
| 2957 | SDValue RHS = Op.getOperand(3); |
| 2958 | SDValue Dest = Op.getOperand(4); |
| 2959 | DebugLoc dl = Op.getDebugLoc(); |
| 2960 | |
| 2961 | bool SeenZero = false; |
| 2962 | if (canChangeToInt(LHS, SeenZero, Subtarget) && |
| 2963 | canChangeToInt(RHS, SeenZero, Subtarget) && |
Evan Cheng | 60108e9 | 2010-07-15 22:07:12 +0000 | [diff] [blame] | 2964 | // If one of the operand is zero, it's safe to ignore the NaN case since |
| 2965 | // we only care about equality comparisons. |
| 2966 | (SeenZero || (DAG.isKnownNeverNaN(LHS) && DAG.isKnownNeverNaN(RHS)))) { |
Bob Wilson | 1b772f9 | 2011-03-08 01:17:16 +0000 | [diff] [blame] | 2967 | // If unsafe fp math optimization is enabled and there are no other uses of |
| 2968 | // 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] | 2969 | // to an integer comparison. |
| 2970 | if (CC == ISD::SETOEQ) |
| 2971 | CC = ISD::SETEQ; |
| 2972 | else if (CC == ISD::SETUNE) |
| 2973 | CC = ISD::SETNE; |
| 2974 | |
| 2975 | SDValue ARMcc; |
| 2976 | if (LHS.getValueType() == MVT::f32) { |
| 2977 | LHS = bitcastf32Toi32(LHS, DAG); |
| 2978 | RHS = bitcastf32Toi32(RHS, DAG); |
| 2979 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMcc, DAG, dl); |
| 2980 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| 2981 | return DAG.getNode(ARMISD::BRCOND, dl, MVT::Other, |
| 2982 | Chain, Dest, ARMcc, CCR, Cmp); |
| 2983 | } |
| 2984 | |
| 2985 | SDValue LHS1, LHS2; |
| 2986 | SDValue RHS1, RHS2; |
| 2987 | expandf64Toi32(LHS, DAG, LHS1, LHS2); |
| 2988 | expandf64Toi32(RHS, DAG, RHS1, RHS2); |
| 2989 | ARMCC::CondCodes CondCode = IntCCToARMCC(CC); |
| 2990 | ARMcc = DAG.getConstant(CondCode, MVT::i32); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 2991 | SDVTList VTList = DAG.getVTList(MVT::Other, MVT::Glue); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2992 | SDValue Ops[] = { Chain, ARMcc, LHS1, LHS2, RHS1, RHS2, Dest }; |
| 2993 | return DAG.getNode(ARMISD::BCC_i64, dl, VTList, Ops, 7); |
| 2994 | } |
| 2995 | |
| 2996 | return SDValue(); |
| 2997 | } |
| 2998 | |
| 2999 | SDValue ARMTargetLowering::LowerBR_CC(SDValue Op, SelectionDAG &DAG) const { |
| 3000 | SDValue Chain = Op.getOperand(0); |
| 3001 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get(); |
| 3002 | SDValue LHS = Op.getOperand(2); |
| 3003 | SDValue RHS = Op.getOperand(3); |
| 3004 | SDValue Dest = Op.getOperand(4); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 3005 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3006 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3007 | if (LHS.getValueType() == MVT::i32) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3008 | SDValue ARMcc; |
| 3009 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMcc, DAG, dl); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3010 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3011 | return DAG.getNode(ARMISD::BRCOND, dl, MVT::Other, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3012 | Chain, Dest, ARMcc, CCR, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3013 | } |
| 3014 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3015 | assert(LHS.getValueType() == MVT::f32 || LHS.getValueType() == MVT::f64); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3016 | |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 3017 | if (getTargetMachine().Options.UnsafeFPMath && |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3018 | (CC == ISD::SETEQ || CC == ISD::SETOEQ || |
| 3019 | CC == ISD::SETNE || CC == ISD::SETUNE)) { |
| 3020 | SDValue Result = OptimizeVFPBrcond(Op, DAG); |
| 3021 | if (Result.getNode()) |
| 3022 | return Result; |
| 3023 | } |
| 3024 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3025 | ARMCC::CondCodes CondCode, CondCode2; |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 3026 | FPCCToARMCC(CC, CondCode, CondCode2); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3027 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3028 | SDValue ARMcc = DAG.getConstant(CondCode, MVT::i32); |
| 3029 | SDValue Cmp = getVFPCmp(LHS, RHS, DAG, dl); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3030 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 3031 | SDVTList VTList = DAG.getVTList(MVT::Other, MVT::Glue); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3032 | SDValue Ops[] = { Chain, Dest, ARMcc, CCR, Cmp }; |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 3033 | SDValue Res = DAG.getNode(ARMISD::BRCOND, dl, VTList, Ops, 5); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3034 | if (CondCode2 != ARMCC::AL) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3035 | ARMcc = DAG.getConstant(CondCode2, MVT::i32); |
| 3036 | SDValue Ops[] = { Res, Dest, ARMcc, CCR, Res.getValue(1) }; |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 3037 | Res = DAG.getNode(ARMISD::BRCOND, dl, VTList, Ops, 5); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3038 | } |
| 3039 | return Res; |
| 3040 | } |
| 3041 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 3042 | SDValue ARMTargetLowering::LowerBR_JT(SDValue Op, SelectionDAG &DAG) const { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3043 | SDValue Chain = Op.getOperand(0); |
| 3044 | SDValue Table = Op.getOperand(1); |
| 3045 | SDValue Index = Op.getOperand(2); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 3046 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3047 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3048 | EVT PTy = getPointerTy(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3049 | JumpTableSDNode *JT = cast<JumpTableSDNode>(Table); |
| 3050 | ARMFunctionInfo *AFI = DAG.getMachineFunction().getInfo<ARMFunctionInfo>(); |
Bob Wilson | 3eadf00 | 2009-07-14 18:44:34 +0000 | [diff] [blame] | 3051 | SDValue UId = DAG.getConstant(AFI->createJumpTableUId(), PTy); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3052 | SDValue JTI = DAG.getTargetJumpTable(JT->getIndex(), PTy); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3053 | Table = DAG.getNode(ARMISD::WrapperJT, dl, MVT::i32, JTI, UId); |
Evan Cheng | e7c329b | 2009-07-28 20:53:24 +0000 | [diff] [blame] | 3054 | Index = DAG.getNode(ISD::MUL, dl, PTy, Index, DAG.getConstant(4, PTy)); |
| 3055 | SDValue Addr = DAG.getNode(ISD::ADD, dl, PTy, Index, Table); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3056 | if (Subtarget->isThumb2()) { |
| 3057 | // Thumb2 uses a two-level jump. That is, it jumps into the jump table |
| 3058 | // which does another jump to the destination. This also makes it easier |
| 3059 | // to translate it to TBB / TBH later. |
| 3060 | // FIXME: This might not work if the function is extremely large. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3061 | return DAG.getNode(ARMISD::BR2_JT, dl, MVT::Other, Chain, |
Evan Cheng | 5657c01 | 2009-07-29 02:18:14 +0000 | [diff] [blame] | 3062 | Addr, Op.getOperand(2), JTI, UId); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3063 | } |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3064 | if (getTargetMachine().getRelocationModel() == Reloc::PIC_) { |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 3065 | Addr = DAG.getLoad((EVT)MVT::i32, dl, Chain, Addr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 3066 | MachinePointerInfo::getJumpTable(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3067 | false, false, false, 0); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3068 | Chain = Addr.getValue(1); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 3069 | Addr = DAG.getNode(ISD::ADD, dl, PTy, Addr, Table); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3070 | 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] | 3071 | } else { |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 3072 | Addr = DAG.getLoad(PTy, dl, Chain, Addr, |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3073 | MachinePointerInfo::getJumpTable(), |
| 3074 | false, false, false, 0); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3075 | Chain = Addr.getValue(1); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3076 | 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] | 3077 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3078 | } |
| 3079 | |
Eli Friedman | 14e809c | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3080 | static SDValue LowerVectorFP_TO_INT(SDValue Op, SelectionDAG &DAG) { |
James Molloy | 873fd5f | 2012-02-20 09:24:05 +0000 | [diff] [blame] | 3081 | EVT VT = Op.getValueType(); |
| 3082 | DebugLoc dl = Op.getDebugLoc(); |
Eli Friedman | 14e809c | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3083 | |
James Molloy | 873fd5f | 2012-02-20 09:24:05 +0000 | [diff] [blame] | 3084 | if (Op.getValueType().getVectorElementType() == MVT::i32) { |
| 3085 | if (Op.getOperand(0).getValueType().getVectorElementType() == MVT::f32) |
| 3086 | return Op; |
| 3087 | return DAG.UnrollVectorOp(Op.getNode()); |
| 3088 | } |
| 3089 | |
| 3090 | assert(Op.getOperand(0).getValueType() == MVT::v4f32 && |
| 3091 | "Invalid type for custom lowering!"); |
| 3092 | if (VT != MVT::v4i16) |
| 3093 | return DAG.UnrollVectorOp(Op.getNode()); |
| 3094 | |
| 3095 | Op = DAG.getNode(Op.getOpcode(), dl, MVT::v4i32, Op.getOperand(0)); |
| 3096 | return DAG.getNode(ISD::TRUNCATE, dl, VT, Op); |
Eli Friedman | 14e809c | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3097 | } |
| 3098 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3099 | static SDValue LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG) { |
Eli Friedman | 14e809c | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3100 | EVT VT = Op.getValueType(); |
| 3101 | if (VT.isVector()) |
| 3102 | return LowerVectorFP_TO_INT(Op, DAG); |
| 3103 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3104 | DebugLoc dl = Op.getDebugLoc(); |
| 3105 | unsigned Opc; |
| 3106 | |
| 3107 | switch (Op.getOpcode()) { |
Craig Topper | bc21981 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 3108 | default: llvm_unreachable("Invalid opcode!"); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3109 | case ISD::FP_TO_SINT: |
| 3110 | Opc = ARMISD::FTOSI; |
| 3111 | break; |
| 3112 | case ISD::FP_TO_UINT: |
| 3113 | Opc = ARMISD::FTOUI; |
| 3114 | break; |
| 3115 | } |
| 3116 | Op = DAG.getNode(Opc, dl, MVT::f32, Op.getOperand(0)); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3117 | return DAG.getNode(ISD::BITCAST, dl, MVT::i32, Op); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3118 | } |
| 3119 | |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 3120 | static SDValue LowerVectorINT_TO_FP(SDValue Op, SelectionDAG &DAG) { |
| 3121 | EVT VT = Op.getValueType(); |
| 3122 | DebugLoc dl = Op.getDebugLoc(); |
| 3123 | |
Eli Friedman | 14e809c | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3124 | if (Op.getOperand(0).getValueType().getVectorElementType() == MVT::i32) { |
| 3125 | if (VT.getVectorElementType() == MVT::f32) |
| 3126 | return Op; |
| 3127 | return DAG.UnrollVectorOp(Op.getNode()); |
| 3128 | } |
| 3129 | |
Duncan Sands | 1f6a329 | 2011-08-12 14:54:45 +0000 | [diff] [blame] | 3130 | assert(Op.getOperand(0).getValueType() == MVT::v4i16 && |
| 3131 | "Invalid type for custom lowering!"); |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 3132 | if (VT != MVT::v4f32) |
| 3133 | return DAG.UnrollVectorOp(Op.getNode()); |
| 3134 | |
| 3135 | unsigned CastOpc; |
| 3136 | unsigned Opc; |
| 3137 | switch (Op.getOpcode()) { |
Craig Topper | bc21981 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 3138 | default: llvm_unreachable("Invalid opcode!"); |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 3139 | case ISD::SINT_TO_FP: |
| 3140 | CastOpc = ISD::SIGN_EXTEND; |
| 3141 | Opc = ISD::SINT_TO_FP; |
| 3142 | break; |
| 3143 | case ISD::UINT_TO_FP: |
| 3144 | CastOpc = ISD::ZERO_EXTEND; |
| 3145 | Opc = ISD::UINT_TO_FP; |
| 3146 | break; |
| 3147 | } |
| 3148 | |
| 3149 | Op = DAG.getNode(CastOpc, dl, MVT::v4i32, Op.getOperand(0)); |
| 3150 | return DAG.getNode(Opc, dl, VT, Op); |
| 3151 | } |
| 3152 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3153 | static SDValue LowerINT_TO_FP(SDValue Op, SelectionDAG &DAG) { |
| 3154 | EVT VT = Op.getValueType(); |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 3155 | if (VT.isVector()) |
| 3156 | return LowerVectorINT_TO_FP(Op, DAG); |
| 3157 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3158 | DebugLoc dl = Op.getDebugLoc(); |
| 3159 | unsigned Opc; |
| 3160 | |
| 3161 | switch (Op.getOpcode()) { |
Craig Topper | bc21981 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 3162 | default: llvm_unreachable("Invalid opcode!"); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3163 | case ISD::SINT_TO_FP: |
| 3164 | Opc = ARMISD::SITOF; |
| 3165 | break; |
| 3166 | case ISD::UINT_TO_FP: |
| 3167 | Opc = ARMISD::UITOF; |
| 3168 | break; |
| 3169 | } |
| 3170 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3171 | Op = DAG.getNode(ISD::BITCAST, dl, MVT::f32, Op.getOperand(0)); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3172 | return DAG.getNode(Opc, dl, VT, Op); |
| 3173 | } |
| 3174 | |
Evan Cheng | 515fe3a | 2010-07-08 02:08:50 +0000 | [diff] [blame] | 3175 | SDValue ARMTargetLowering::LowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3176 | // Implement fcopysign with a fabs and a conditional fneg. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3177 | SDValue Tmp0 = Op.getOperand(0); |
| 3178 | SDValue Tmp1 = Op.getOperand(1); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 3179 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3180 | EVT VT = Op.getValueType(); |
| 3181 | EVT SrcVT = Tmp1.getValueType(); |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3182 | bool InGPR = Tmp0.getOpcode() == ISD::BITCAST || |
| 3183 | Tmp0.getOpcode() == ARMISD::VMOVDRR; |
| 3184 | bool UseNEON = !InGPR && Subtarget->hasNEON(); |
| 3185 | |
| 3186 | if (UseNEON) { |
| 3187 | // Use VBSL to copy the sign bit. |
| 3188 | unsigned EncodedVal = ARM_AM::createNEONModImm(0x6, 0x80); |
| 3189 | SDValue Mask = DAG.getNode(ARMISD::VMOVIMM, dl, MVT::v2i32, |
| 3190 | DAG.getTargetConstant(EncodedVal, MVT::i32)); |
| 3191 | EVT OpVT = (VT == MVT::f32) ? MVT::v2i32 : MVT::v1i64; |
| 3192 | if (VT == MVT::f64) |
| 3193 | Mask = DAG.getNode(ARMISD::VSHL, dl, OpVT, |
| 3194 | DAG.getNode(ISD::BITCAST, dl, OpVT, Mask), |
| 3195 | DAG.getConstant(32, MVT::i32)); |
| 3196 | else /*if (VT == MVT::f32)*/ |
| 3197 | Tmp0 = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, MVT::v2f32, Tmp0); |
| 3198 | if (SrcVT == MVT::f32) { |
| 3199 | Tmp1 = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, MVT::v2f32, Tmp1); |
| 3200 | if (VT == MVT::f64) |
| 3201 | Tmp1 = DAG.getNode(ARMISD::VSHL, dl, OpVT, |
| 3202 | DAG.getNode(ISD::BITCAST, dl, OpVT, Tmp1), |
| 3203 | DAG.getConstant(32, MVT::i32)); |
Evan Cheng | 9eec66e | 2011-04-15 01:31:00 +0000 | [diff] [blame] | 3204 | } else if (VT == MVT::f32) |
| 3205 | Tmp1 = DAG.getNode(ARMISD::VSHRu, dl, MVT::v1i64, |
| 3206 | DAG.getNode(ISD::BITCAST, dl, MVT::v1i64, Tmp1), |
| 3207 | DAG.getConstant(32, MVT::i32)); |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3208 | Tmp0 = DAG.getNode(ISD::BITCAST, dl, OpVT, Tmp0); |
| 3209 | Tmp1 = DAG.getNode(ISD::BITCAST, dl, OpVT, Tmp1); |
| 3210 | |
| 3211 | SDValue AllOnes = DAG.getTargetConstant(ARM_AM::createNEONModImm(0xe, 0xff), |
| 3212 | MVT::i32); |
| 3213 | AllOnes = DAG.getNode(ARMISD::VMOVIMM, dl, MVT::v8i8, AllOnes); |
| 3214 | SDValue MaskNot = DAG.getNode(ISD::XOR, dl, OpVT, Mask, |
| 3215 | DAG.getNode(ISD::BITCAST, dl, OpVT, AllOnes)); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 3216 | |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3217 | SDValue Res = DAG.getNode(ISD::OR, dl, OpVT, |
| 3218 | DAG.getNode(ISD::AND, dl, OpVT, Tmp1, Mask), |
| 3219 | DAG.getNode(ISD::AND, dl, OpVT, Tmp0, MaskNot)); |
Evan Cheng | c24ab5c | 2011-02-28 18:45:27 +0000 | [diff] [blame] | 3220 | if (VT == MVT::f32) { |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3221 | Res = DAG.getNode(ISD::BITCAST, dl, MVT::v2f32, Res); |
| 3222 | Res = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f32, Res, |
| 3223 | DAG.getConstant(0, MVT::i32)); |
| 3224 | } else { |
| 3225 | Res = DAG.getNode(ISD::BITCAST, dl, MVT::f64, Res); |
| 3226 | } |
| 3227 | |
| 3228 | return Res; |
| 3229 | } |
Evan Cheng | c143dd4 | 2011-02-11 02:28:55 +0000 | [diff] [blame] | 3230 | |
| 3231 | // Bitcast operand 1 to i32. |
| 3232 | if (SrcVT == MVT::f64) |
| 3233 | Tmp1 = DAG.getNode(ARMISD::VMOVRRD, dl, DAG.getVTList(MVT::i32, MVT::i32), |
| 3234 | &Tmp1, 1).getValue(1); |
| 3235 | Tmp1 = DAG.getNode(ISD::BITCAST, dl, MVT::i32, Tmp1); |
| 3236 | |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3237 | // Or in the signbit with integer operations. |
| 3238 | SDValue Mask1 = DAG.getConstant(0x80000000, MVT::i32); |
| 3239 | SDValue Mask2 = DAG.getConstant(0x7fffffff, MVT::i32); |
| 3240 | Tmp1 = DAG.getNode(ISD::AND, dl, MVT::i32, Tmp1, Mask1); |
| 3241 | if (VT == MVT::f32) { |
| 3242 | Tmp0 = DAG.getNode(ISD::AND, dl, MVT::i32, |
| 3243 | DAG.getNode(ISD::BITCAST, dl, MVT::i32, Tmp0), Mask2); |
| 3244 | return DAG.getNode(ISD::BITCAST, dl, MVT::f32, |
| 3245 | DAG.getNode(ISD::OR, dl, MVT::i32, Tmp0, Tmp1)); |
Evan Cheng | c143dd4 | 2011-02-11 02:28:55 +0000 | [diff] [blame] | 3246 | } |
| 3247 | |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3248 | // f64: Or the high part with signbit and then combine two parts. |
| 3249 | Tmp0 = DAG.getNode(ARMISD::VMOVRRD, dl, DAG.getVTList(MVT::i32, MVT::i32), |
| 3250 | &Tmp0, 1); |
| 3251 | SDValue Lo = Tmp0.getValue(0); |
| 3252 | SDValue Hi = DAG.getNode(ISD::AND, dl, MVT::i32, Tmp0.getValue(1), Mask2); |
| 3253 | Hi = DAG.getNode(ISD::OR, dl, MVT::i32, Hi, Tmp1); |
| 3254 | return DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3255 | } |
| 3256 | |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3257 | SDValue ARMTargetLowering::LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const{ |
| 3258 | MachineFunction &MF = DAG.getMachineFunction(); |
| 3259 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 3260 | MFI->setReturnAddressIsTaken(true); |
| 3261 | |
| 3262 | EVT VT = Op.getValueType(); |
| 3263 | DebugLoc dl = Op.getDebugLoc(); |
| 3264 | unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
| 3265 | if (Depth) { |
| 3266 | SDValue FrameAddr = LowerFRAMEADDR(Op, DAG); |
| 3267 | SDValue Offset = DAG.getConstant(4, MVT::i32); |
| 3268 | return DAG.getLoad(VT, dl, DAG.getEntryNode(), |
| 3269 | DAG.getNode(ISD::ADD, dl, VT, FrameAddr, Offset), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3270 | MachinePointerInfo(), false, false, false, 0); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3271 | } |
| 3272 | |
| 3273 | // 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] | 3274 | unsigned Reg = MF.addLiveIn(ARM::LR, getRegClassFor(MVT::i32)); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3275 | return DAG.getCopyFromReg(DAG.getEntryNode(), dl, Reg, VT); |
| 3276 | } |
| 3277 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 3278 | SDValue ARMTargetLowering::LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const { |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3279 | MachineFrameInfo *MFI = DAG.getMachineFunction().getFrameInfo(); |
| 3280 | MFI->setFrameAddressIsTaken(true); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3281 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3282 | EVT VT = Op.getValueType(); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3283 | DebugLoc dl = Op.getDebugLoc(); // FIXME probably not meaningful |
| 3284 | unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
Evan Cheng | cd82861 | 2009-06-18 23:14:30 +0000 | [diff] [blame] | 3285 | unsigned FrameReg = (Subtarget->isThumb() || Subtarget->isTargetDarwin()) |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3286 | ? ARM::R7 : ARM::R11; |
| 3287 | SDValue FrameAddr = DAG.getCopyFromReg(DAG.getEntryNode(), dl, FrameReg, VT); |
| 3288 | while (Depth--) |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 3289 | FrameAddr = DAG.getLoad(VT, dl, DAG.getEntryNode(), FrameAddr, |
| 3290 | MachinePointerInfo(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3291 | false, false, false, 0); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3292 | return FrameAddr; |
| 3293 | } |
| 3294 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3295 | /// ExpandBITCAST - If the target supports VFP, this function is called to |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3296 | /// expand a bit convert where either the source or destination type is i64 to |
| 3297 | /// use a VMOVDRR or VMOVRRD node. This should not be done when the non-i64 |
| 3298 | /// operand type is illegal (e.g., v2f32 for a target that doesn't support |
| 3299 | /// vectors), since the legalizer won't know what to do with that. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3300 | static SDValue ExpandBITCAST(SDNode *N, SelectionDAG &DAG) { |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3301 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 3302 | DebugLoc dl = N->getDebugLoc(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3303 | SDValue Op = N->getOperand(0); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 3304 | |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3305 | // This function is only supposed to be called for i64 types, either as the |
| 3306 | // source or destination of the bit convert. |
| 3307 | EVT SrcVT = Op.getValueType(); |
| 3308 | EVT DstVT = N->getValueType(0); |
| 3309 | assert((SrcVT == MVT::i64 || DstVT == MVT::i64) && |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3310 | "ExpandBITCAST called for non-i64 type"); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 3311 | |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3312 | // Turn i64->f64 into VMOVDRR. |
| 3313 | if (SrcVT == MVT::i64 && TLI.isTypeLegal(DstVT)) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3314 | SDValue Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Op, |
| 3315 | DAG.getConstant(0, MVT::i32)); |
| 3316 | SDValue Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Op, |
| 3317 | DAG.getConstant(1, MVT::i32)); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3318 | return DAG.getNode(ISD::BITCAST, dl, DstVT, |
Bob Wilson | 1114f56 | 2010-06-11 22:45:25 +0000 | [diff] [blame] | 3319 | DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi)); |
Evan Cheng | c7c7729 | 2008-11-04 19:57:48 +0000 | [diff] [blame] | 3320 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3321 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 3322 | // Turn f64->i64 into VMOVRRD. |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3323 | if (DstVT == MVT::i64 && TLI.isTypeLegal(SrcVT)) { |
| 3324 | SDValue Cvt = DAG.getNode(ARMISD::VMOVRRD, dl, |
| 3325 | DAG.getVTList(MVT::i32, MVT::i32), &Op, 1); |
| 3326 | // Merge the pieces into a single i64 value. |
| 3327 | return DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Cvt, Cvt.getValue(1)); |
| 3328 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3329 | |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3330 | return SDValue(); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3331 | } |
| 3332 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3333 | /// getZeroVector - Returns a vector of specified type with all zero elements. |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3334 | /// Zero vectors are used to represent vector negation and in those cases |
| 3335 | /// will be implemented with the NEON VNEG instruction. However, VNEG does |
| 3336 | /// not support i64 elements, so sometimes the zero vectors will need to be |
| 3337 | /// explicitly constructed. Regardless, use a canonical VMOV to create the |
| 3338 | /// zero vector. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3339 | static SDValue getZeroVector(EVT VT, SelectionDAG &DAG, DebugLoc dl) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3340 | assert(VT.isVector() && "Expected a vector type"); |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3341 | // The canonical modified immediate encoding of a zero vector is....0! |
| 3342 | SDValue EncodedVal = DAG.getTargetConstant(0, MVT::i32); |
| 3343 | EVT VmovVT = VT.is128BitVector() ? MVT::v4i32 : MVT::v2i32; |
| 3344 | SDValue Vmov = DAG.getNode(ARMISD::VMOVIMM, dl, VmovVT, EncodedVal); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3345 | return DAG.getNode(ISD::BITCAST, dl, VT, Vmov); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3346 | } |
| 3347 | |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3348 | /// LowerShiftRightParts - Lower SRA_PARTS, which returns two |
| 3349 | /// 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] | 3350 | SDValue ARMTargetLowering::LowerShiftRightParts(SDValue Op, |
| 3351 | SelectionDAG &DAG) const { |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3352 | assert(Op.getNumOperands() == 3 && "Not a double-shift!"); |
| 3353 | EVT VT = Op.getValueType(); |
| 3354 | unsigned VTBits = VT.getSizeInBits(); |
| 3355 | DebugLoc dl = Op.getDebugLoc(); |
| 3356 | SDValue ShOpLo = Op.getOperand(0); |
| 3357 | SDValue ShOpHi = Op.getOperand(1); |
| 3358 | SDValue ShAmt = Op.getOperand(2); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3359 | SDValue ARMcc; |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 3360 | unsigned Opc = (Op.getOpcode() == ISD::SRA_PARTS) ? ISD::SRA : ISD::SRL; |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3361 | |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 3362 | assert(Op.getOpcode() == ISD::SRA_PARTS || Op.getOpcode() == ISD::SRL_PARTS); |
| 3363 | |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3364 | SDValue RevShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, |
| 3365 | DAG.getConstant(VTBits, MVT::i32), ShAmt); |
| 3366 | SDValue Tmp1 = DAG.getNode(ISD::SRL, dl, VT, ShOpLo, ShAmt); |
| 3367 | SDValue ExtraShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, ShAmt, |
| 3368 | DAG.getConstant(VTBits, MVT::i32)); |
| 3369 | SDValue Tmp2 = DAG.getNode(ISD::SHL, dl, VT, ShOpHi, RevShAmt); |
| 3370 | SDValue FalseVal = DAG.getNode(ISD::OR, dl, VT, Tmp1, Tmp2); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 3371 | SDValue TrueVal = DAG.getNode(Opc, dl, VT, ShOpHi, ExtraShAmt); |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3372 | |
| 3373 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| 3374 | SDValue Cmp = getARMCmp(ExtraShAmt, DAG.getConstant(0, MVT::i32), ISD::SETGE, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3375 | ARMcc, DAG, dl); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 3376 | SDValue Hi = DAG.getNode(Opc, dl, VT, ShOpHi, ShAmt); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3377 | SDValue Lo = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, ARMcc, |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3378 | CCR, Cmp); |
| 3379 | |
| 3380 | SDValue Ops[2] = { Lo, Hi }; |
| 3381 | return DAG.getMergeValues(Ops, 2, dl); |
| 3382 | } |
| 3383 | |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3384 | /// LowerShiftLeftParts - Lower SHL_PARTS, which returns two |
| 3385 | /// 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] | 3386 | SDValue ARMTargetLowering::LowerShiftLeftParts(SDValue Op, |
| 3387 | SelectionDAG &DAG) const { |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3388 | assert(Op.getNumOperands() == 3 && "Not a double-shift!"); |
| 3389 | EVT VT = Op.getValueType(); |
| 3390 | unsigned VTBits = VT.getSizeInBits(); |
| 3391 | DebugLoc dl = Op.getDebugLoc(); |
| 3392 | SDValue ShOpLo = Op.getOperand(0); |
| 3393 | SDValue ShOpHi = Op.getOperand(1); |
| 3394 | SDValue ShAmt = Op.getOperand(2); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3395 | SDValue ARMcc; |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3396 | |
| 3397 | assert(Op.getOpcode() == ISD::SHL_PARTS); |
| 3398 | SDValue RevShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, |
| 3399 | DAG.getConstant(VTBits, MVT::i32), ShAmt); |
| 3400 | SDValue Tmp1 = DAG.getNode(ISD::SRL, dl, VT, ShOpLo, RevShAmt); |
| 3401 | SDValue ExtraShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, ShAmt, |
| 3402 | DAG.getConstant(VTBits, MVT::i32)); |
| 3403 | SDValue Tmp2 = DAG.getNode(ISD::SHL, dl, VT, ShOpHi, ShAmt); |
| 3404 | SDValue Tmp3 = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ExtraShAmt); |
| 3405 | |
| 3406 | SDValue FalseVal = DAG.getNode(ISD::OR, dl, VT, Tmp1, Tmp2); |
| 3407 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| 3408 | SDValue Cmp = getARMCmp(ExtraShAmt, DAG.getConstant(0, MVT::i32), ISD::SETGE, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3409 | ARMcc, DAG, dl); |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3410 | SDValue Lo = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ShAmt); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3411 | SDValue Hi = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, Tmp3, ARMcc, |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3412 | CCR, Cmp); |
| 3413 | |
| 3414 | SDValue Ops[2] = { Lo, Hi }; |
| 3415 | return DAG.getMergeValues(Ops, 2, dl); |
| 3416 | } |
| 3417 | |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 3418 | SDValue ARMTargetLowering::LowerFLT_ROUNDS_(SDValue Op, |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 3419 | SelectionDAG &DAG) const { |
| 3420 | // The rounding mode is in bits 23:22 of the FPSCR. |
| 3421 | // The ARM rounding mode value to FLT_ROUNDS mapping is 0->1, 1->2, 2->3, 3->0 |
| 3422 | // The formula we use to implement this is (((FPSCR + 1 << 22) >> 22) & 3) |
| 3423 | // so that the shift + and get folded into a bitfield extract. |
| 3424 | DebugLoc dl = Op.getDebugLoc(); |
| 3425 | SDValue FPSCR = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::i32, |
| 3426 | DAG.getConstant(Intrinsic::arm_get_fpscr, |
| 3427 | MVT::i32)); |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 3428 | SDValue FltRounds = DAG.getNode(ISD::ADD, dl, MVT::i32, FPSCR, |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 3429 | DAG.getConstant(1U << 22, MVT::i32)); |
| 3430 | SDValue RMODE = DAG.getNode(ISD::SRL, dl, MVT::i32, FltRounds, |
| 3431 | DAG.getConstant(22, MVT::i32)); |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 3432 | return DAG.getNode(ISD::AND, dl, MVT::i32, RMODE, |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 3433 | DAG.getConstant(3, MVT::i32)); |
| 3434 | } |
| 3435 | |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 3436 | static SDValue LowerCTTZ(SDNode *N, SelectionDAG &DAG, |
| 3437 | const ARMSubtarget *ST) { |
| 3438 | EVT VT = N->getValueType(0); |
| 3439 | DebugLoc dl = N->getDebugLoc(); |
| 3440 | |
| 3441 | if (!ST->hasV6T2Ops()) |
| 3442 | return SDValue(); |
| 3443 | |
| 3444 | SDValue rbit = DAG.getNode(ARMISD::RBIT, dl, VT, N->getOperand(0)); |
| 3445 | return DAG.getNode(ISD::CTLZ, dl, VT, rbit); |
| 3446 | } |
| 3447 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3448 | static SDValue LowerShift(SDNode *N, SelectionDAG &DAG, |
| 3449 | const ARMSubtarget *ST) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3450 | EVT VT = N->getValueType(0); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3451 | DebugLoc dl = N->getDebugLoc(); |
| 3452 | |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3453 | if (!VT.isVector()) |
| 3454 | return SDValue(); |
| 3455 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3456 | // Lower vector shifts on NEON to use VSHL. |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3457 | assert(ST->hasNEON() && "unexpected vector shift"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3458 | |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3459 | // Left shifts translate directly to the vshiftu intrinsic. |
| 3460 | if (N->getOpcode() == ISD::SHL) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3461 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT, |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3462 | DAG.getConstant(Intrinsic::arm_neon_vshiftu, MVT::i32), |
| 3463 | N->getOperand(0), N->getOperand(1)); |
| 3464 | |
| 3465 | assert((N->getOpcode() == ISD::SRA || |
| 3466 | N->getOpcode() == ISD::SRL) && "unexpected vector shift opcode"); |
| 3467 | |
| 3468 | // NEON uses the same intrinsics for both left and right shifts. For |
| 3469 | // right shifts, the shift amounts are negative, so negate the vector of |
| 3470 | // shift amounts. |
| 3471 | EVT ShiftVT = N->getOperand(1).getValueType(); |
| 3472 | SDValue NegatedCount = DAG.getNode(ISD::SUB, dl, ShiftVT, |
| 3473 | getZeroVector(ShiftVT, DAG, dl), |
| 3474 | N->getOperand(1)); |
| 3475 | Intrinsic::ID vshiftInt = (N->getOpcode() == ISD::SRA ? |
| 3476 | Intrinsic::arm_neon_vshifts : |
| 3477 | Intrinsic::arm_neon_vshiftu); |
| 3478 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT, |
| 3479 | DAG.getConstant(vshiftInt, MVT::i32), |
| 3480 | N->getOperand(0), NegatedCount); |
| 3481 | } |
| 3482 | |
| 3483 | static SDValue Expand64BitShift(SDNode *N, SelectionDAG &DAG, |
| 3484 | const ARMSubtarget *ST) { |
| 3485 | EVT VT = N->getValueType(0); |
| 3486 | DebugLoc dl = N->getDebugLoc(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3487 | |
Eli Friedman | ce392eb | 2009-08-22 03:13:10 +0000 | [diff] [blame] | 3488 | // We can get here for a node like i32 = ISD::SHL i32, i64 |
| 3489 | if (VT != MVT::i64) |
| 3490 | return SDValue(); |
| 3491 | |
| 3492 | assert((N->getOpcode() == ISD::SRL || N->getOpcode() == ISD::SRA) && |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3493 | "Unknown shift to lower!"); |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 3494 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3495 | // We only lower SRA, SRL of 1 here, all others use generic lowering. |
| 3496 | if (!isa<ConstantSDNode>(N->getOperand(1)) || |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 3497 | cast<ConstantSDNode>(N->getOperand(1))->getZExtValue() != 1) |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 3498 | return SDValue(); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3499 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3500 | // If we are in thumb mode, we don't have RRX. |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 3501 | if (ST->isThumb1Only()) return SDValue(); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3502 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3503 | // 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] | 3504 | 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] | 3505 | DAG.getConstant(0, MVT::i32)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3506 | 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] | 3507 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3508 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3509 | // First, build a SRA_FLAG/SRL_FLAG op, which shifts the top part by one and |
| 3510 | // captures the result into a carry flag. |
| 3511 | unsigned Opc = N->getOpcode() == ISD::SRL ? ARMISD::SRL_FLAG:ARMISD::SRA_FLAG; |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 3512 | 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] | 3513 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3514 | // 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] | 3515 | Lo = DAG.getNode(ARMISD::RRX, dl, MVT::i32, Lo, Hi.getValue(1)); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3516 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3517 | // Merge the pieces into a single i64 value. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3518 | return DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Lo, Hi); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3519 | } |
| 3520 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3521 | static SDValue LowerVSETCC(SDValue Op, SelectionDAG &DAG) { |
| 3522 | SDValue TmpOp0, TmpOp1; |
| 3523 | bool Invert = false; |
| 3524 | bool Swap = false; |
| 3525 | unsigned Opc = 0; |
| 3526 | |
| 3527 | SDValue Op0 = Op.getOperand(0); |
| 3528 | SDValue Op1 = Op.getOperand(1); |
| 3529 | SDValue CC = Op.getOperand(2); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3530 | EVT VT = Op.getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3531 | ISD::CondCode SetCCOpcode = cast<CondCodeSDNode>(CC)->get(); |
| 3532 | DebugLoc dl = Op.getDebugLoc(); |
| 3533 | |
| 3534 | if (Op.getOperand(1).getValueType().isFloatingPoint()) { |
| 3535 | switch (SetCCOpcode) { |
David Blaikie | 4d6ccb5 | 2012-01-20 21:51:11 +0000 | [diff] [blame] | 3536 | default: llvm_unreachable("Illegal FP comparison"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3537 | case ISD::SETUNE: |
| 3538 | case ISD::SETNE: Invert = true; // Fallthrough |
| 3539 | case ISD::SETOEQ: |
| 3540 | case ISD::SETEQ: Opc = ARMISD::VCEQ; break; |
| 3541 | case ISD::SETOLT: |
| 3542 | case ISD::SETLT: Swap = true; // Fallthrough |
| 3543 | case ISD::SETOGT: |
| 3544 | case ISD::SETGT: Opc = ARMISD::VCGT; break; |
| 3545 | case ISD::SETOLE: |
| 3546 | case ISD::SETLE: Swap = true; // Fallthrough |
| 3547 | case ISD::SETOGE: |
| 3548 | case ISD::SETGE: Opc = ARMISD::VCGE; break; |
| 3549 | case ISD::SETUGE: Swap = true; // Fallthrough |
| 3550 | case ISD::SETULE: Invert = true; Opc = ARMISD::VCGT; break; |
| 3551 | case ISD::SETUGT: Swap = true; // Fallthrough |
| 3552 | case ISD::SETULT: Invert = true; Opc = ARMISD::VCGE; break; |
| 3553 | case ISD::SETUEQ: Invert = true; // Fallthrough |
| 3554 | case ISD::SETONE: |
| 3555 | // Expand this to (OLT | OGT). |
| 3556 | TmpOp0 = Op0; |
| 3557 | TmpOp1 = Op1; |
| 3558 | Opc = ISD::OR; |
| 3559 | Op0 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp1, TmpOp0); |
| 3560 | Op1 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp0, TmpOp1); |
| 3561 | break; |
| 3562 | case ISD::SETUO: Invert = true; // Fallthrough |
| 3563 | case ISD::SETO: |
| 3564 | // Expand this to (OLT | OGE). |
| 3565 | TmpOp0 = Op0; |
| 3566 | TmpOp1 = Op1; |
| 3567 | Opc = ISD::OR; |
| 3568 | Op0 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp1, TmpOp0); |
| 3569 | Op1 = DAG.getNode(ARMISD::VCGE, dl, VT, TmpOp0, TmpOp1); |
| 3570 | break; |
| 3571 | } |
| 3572 | } else { |
| 3573 | // Integer comparisons. |
| 3574 | switch (SetCCOpcode) { |
David Blaikie | 4d6ccb5 | 2012-01-20 21:51:11 +0000 | [diff] [blame] | 3575 | default: llvm_unreachable("Illegal integer comparison"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3576 | case ISD::SETNE: Invert = true; |
| 3577 | case ISD::SETEQ: Opc = ARMISD::VCEQ; break; |
| 3578 | case ISD::SETLT: Swap = true; |
| 3579 | case ISD::SETGT: Opc = ARMISD::VCGT; break; |
| 3580 | case ISD::SETLE: Swap = true; |
| 3581 | case ISD::SETGE: Opc = ARMISD::VCGE; break; |
| 3582 | case ISD::SETULT: Swap = true; |
| 3583 | case ISD::SETUGT: Opc = ARMISD::VCGTU; break; |
| 3584 | case ISD::SETULE: Swap = true; |
| 3585 | case ISD::SETUGE: Opc = ARMISD::VCGEU; break; |
| 3586 | } |
| 3587 | |
Nick Lewycky | 7f6aa2b | 2009-07-08 03:04:38 +0000 | [diff] [blame] | 3588 | // Detect VTST (Vector Test Bits) = icmp ne (and (op0, op1), zero). |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3589 | if (Opc == ARMISD::VCEQ) { |
| 3590 | |
| 3591 | SDValue AndOp; |
| 3592 | if (ISD::isBuildVectorAllZeros(Op1.getNode())) |
| 3593 | AndOp = Op0; |
| 3594 | else if (ISD::isBuildVectorAllZeros(Op0.getNode())) |
| 3595 | AndOp = Op1; |
| 3596 | |
| 3597 | // Ignore bitconvert. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3598 | if (AndOp.getNode() && AndOp.getOpcode() == ISD::BITCAST) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3599 | AndOp = AndOp.getOperand(0); |
| 3600 | |
| 3601 | if (AndOp.getNode() && AndOp.getOpcode() == ISD::AND) { |
| 3602 | Opc = ARMISD::VTST; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3603 | Op0 = DAG.getNode(ISD::BITCAST, dl, VT, AndOp.getOperand(0)); |
| 3604 | Op1 = DAG.getNode(ISD::BITCAST, dl, VT, AndOp.getOperand(1)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3605 | Invert = !Invert; |
| 3606 | } |
| 3607 | } |
| 3608 | } |
| 3609 | |
| 3610 | if (Swap) |
| 3611 | std::swap(Op0, Op1); |
| 3612 | |
Owen Anderson | c24cb35 | 2010-11-08 23:21:22 +0000 | [diff] [blame] | 3613 | // If one of the operands is a constant vector zero, attempt to fold the |
| 3614 | // comparison to a specialized compare-against-zero form. |
| 3615 | SDValue SingleOp; |
| 3616 | if (ISD::isBuildVectorAllZeros(Op1.getNode())) |
| 3617 | SingleOp = Op0; |
| 3618 | else if (ISD::isBuildVectorAllZeros(Op0.getNode())) { |
| 3619 | if (Opc == ARMISD::VCGE) |
| 3620 | Opc = ARMISD::VCLEZ; |
| 3621 | else if (Opc == ARMISD::VCGT) |
| 3622 | Opc = ARMISD::VCLTZ; |
| 3623 | SingleOp = Op1; |
| 3624 | } |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3625 | |
Owen Anderson | c24cb35 | 2010-11-08 23:21:22 +0000 | [diff] [blame] | 3626 | SDValue Result; |
| 3627 | if (SingleOp.getNode()) { |
| 3628 | switch (Opc) { |
| 3629 | case ARMISD::VCEQ: |
| 3630 | Result = DAG.getNode(ARMISD::VCEQZ, dl, VT, SingleOp); break; |
| 3631 | case ARMISD::VCGE: |
| 3632 | Result = DAG.getNode(ARMISD::VCGEZ, dl, VT, SingleOp); break; |
| 3633 | case ARMISD::VCLEZ: |
| 3634 | Result = DAG.getNode(ARMISD::VCLEZ, dl, VT, SingleOp); break; |
| 3635 | case ARMISD::VCGT: |
| 3636 | Result = DAG.getNode(ARMISD::VCGTZ, dl, VT, SingleOp); break; |
| 3637 | case ARMISD::VCLTZ: |
| 3638 | Result = DAG.getNode(ARMISD::VCLTZ, dl, VT, SingleOp); break; |
| 3639 | default: |
| 3640 | Result = DAG.getNode(Opc, dl, VT, Op0, Op1); |
| 3641 | } |
| 3642 | } else { |
| 3643 | Result = DAG.getNode(Opc, dl, VT, Op0, Op1); |
| 3644 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3645 | |
| 3646 | if (Invert) |
| 3647 | Result = DAG.getNOT(dl, Result, VT); |
| 3648 | |
| 3649 | return Result; |
| 3650 | } |
| 3651 | |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 3652 | /// isNEONModifiedImm - Check if the specified splat value corresponds to a |
| 3653 | /// valid vector constant for a NEON instruction with a "modified immediate" |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3654 | /// operand (e.g., VMOV). If so, return the encoded value. |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 3655 | static SDValue isNEONModifiedImm(uint64_t SplatBits, uint64_t SplatUndef, |
| 3656 | unsigned SplatBitSize, SelectionDAG &DAG, |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3657 | EVT &VT, bool is128Bits, NEONModImmType type) { |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3658 | unsigned OpCmode, Imm; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3659 | |
Bob Wilson | 827b210 | 2010-06-15 19:05:35 +0000 | [diff] [blame] | 3660 | // SplatBitSize is set to the smallest size that splats the vector, so a |
| 3661 | // zero vector will always have SplatBitSize == 8. However, NEON modified |
| 3662 | // immediate instructions others than VMOV do not support the 8-bit encoding |
| 3663 | // of a zero vector, and the default encoding of zero is supposed to be the |
| 3664 | // 32-bit version. |
| 3665 | if (SplatBits == 0) |
| 3666 | SplatBitSize = 32; |
| 3667 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3668 | switch (SplatBitSize) { |
| 3669 | case 8: |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3670 | if (type != VMOVModImm) |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 3671 | return SDValue(); |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3672 | // Any 1-byte value is OK. Op=0, Cmode=1110. |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3673 | assert((SplatBits & ~0xff) == 0 && "one byte splat value is too big"); |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3674 | OpCmode = 0xe; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3675 | Imm = SplatBits; |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3676 | VT = is128Bits ? MVT::v16i8 : MVT::v8i8; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3677 | break; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3678 | |
| 3679 | case 16: |
| 3680 | // 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] | 3681 | VT = is128Bits ? MVT::v8i16 : MVT::v4i16; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3682 | if ((SplatBits & ~0xff) == 0) { |
| 3683 | // Value = 0x00nn: Op=x, Cmode=100x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3684 | OpCmode = 0x8; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3685 | Imm = SplatBits; |
| 3686 | break; |
| 3687 | } |
| 3688 | if ((SplatBits & ~0xff00) == 0) { |
| 3689 | // Value = 0xnn00: Op=x, Cmode=101x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3690 | OpCmode = 0xa; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3691 | Imm = SplatBits >> 8; |
| 3692 | break; |
| 3693 | } |
| 3694 | return SDValue(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3695 | |
| 3696 | case 32: |
| 3697 | // NEON's 32-bit VMOV supports splat values where: |
| 3698 | // * only one byte is nonzero, or |
| 3699 | // * the least significant byte is 0xff and the second byte is nonzero, or |
| 3700 | // * the least significant 2 bytes are 0xff and the third is nonzero. |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3701 | VT = is128Bits ? MVT::v4i32 : MVT::v2i32; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3702 | if ((SplatBits & ~0xff) == 0) { |
| 3703 | // Value = 0x000000nn: Op=x, Cmode=000x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3704 | OpCmode = 0; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3705 | Imm = SplatBits; |
| 3706 | break; |
| 3707 | } |
| 3708 | if ((SplatBits & ~0xff00) == 0) { |
| 3709 | // Value = 0x0000nn00: Op=x, Cmode=001x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3710 | OpCmode = 0x2; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3711 | Imm = SplatBits >> 8; |
| 3712 | break; |
| 3713 | } |
| 3714 | if ((SplatBits & ~0xff0000) == 0) { |
| 3715 | // Value = 0x00nn0000: Op=x, Cmode=010x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3716 | OpCmode = 0x4; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3717 | Imm = SplatBits >> 16; |
| 3718 | break; |
| 3719 | } |
| 3720 | if ((SplatBits & ~0xff000000) == 0) { |
| 3721 | // Value = 0xnn000000: Op=x, Cmode=011x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3722 | OpCmode = 0x6; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3723 | Imm = SplatBits >> 24; |
| 3724 | break; |
| 3725 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3726 | |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3727 | // cmode == 0b1100 and cmode == 0b1101 are not supported for VORR or VBIC |
| 3728 | if (type == OtherModImm) return SDValue(); |
| 3729 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3730 | if ((SplatBits & ~0xffff) == 0 && |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3731 | ((SplatBits | SplatUndef) & 0xff) == 0xff) { |
| 3732 | // Value = 0x0000nnff: Op=x, Cmode=1100. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3733 | OpCmode = 0xc; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3734 | Imm = SplatBits >> 8; |
| 3735 | SplatBits |= 0xff; |
| 3736 | break; |
| 3737 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3738 | |
| 3739 | if ((SplatBits & ~0xffffff) == 0 && |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3740 | ((SplatBits | SplatUndef) & 0xffff) == 0xffff) { |
| 3741 | // Value = 0x00nnffff: Op=x, Cmode=1101. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3742 | OpCmode = 0xd; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3743 | Imm = SplatBits >> 16; |
| 3744 | SplatBits |= 0xffff; |
| 3745 | break; |
| 3746 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3747 | |
| 3748 | // Note: there are a few 32-bit splat values (specifically: 00ffff00, |
| 3749 | // ff000000, ff0000ff, and ffff00ff) that are valid for VMOV.I64 but not |
| 3750 | // VMOV.I32. A (very) minor optimization would be to replicate the value |
| 3751 | // and fall through here to test for a valid 64-bit splat. But, then the |
| 3752 | // caller would also need to check and handle the change in size. |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3753 | return SDValue(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3754 | |
| 3755 | case 64: { |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3756 | if (type != VMOVModImm) |
Bob Wilson | 827b210 | 2010-06-15 19:05:35 +0000 | [diff] [blame] | 3757 | return SDValue(); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 3758 | // 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] | 3759 | uint64_t BitMask = 0xff; |
| 3760 | uint64_t Val = 0; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3761 | unsigned ImmMask = 1; |
| 3762 | Imm = 0; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3763 | for (int ByteNum = 0; ByteNum < 8; ++ByteNum) { |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3764 | if (((SplatBits | SplatUndef) & BitMask) == BitMask) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3765 | Val |= BitMask; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3766 | Imm |= ImmMask; |
| 3767 | } else if ((SplatBits & BitMask) != 0) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3768 | return SDValue(); |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3769 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3770 | BitMask <<= 8; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3771 | ImmMask <<= 1; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3772 | } |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3773 | // Op=1, Cmode=1110. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3774 | OpCmode = 0x1e; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3775 | SplatBits = Val; |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3776 | VT = is128Bits ? MVT::v2i64 : MVT::v1i64; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3777 | break; |
| 3778 | } |
| 3779 | |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3780 | default: |
Bob Wilson | dc076da | 2010-06-19 05:32:09 +0000 | [diff] [blame] | 3781 | llvm_unreachable("unexpected size for isNEONModifiedImm"); |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3782 | } |
| 3783 | |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3784 | unsigned EncodedVal = ARM_AM::createNEONModImm(OpCmode, Imm); |
| 3785 | return DAG.getTargetConstant(EncodedVal, MVT::i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3786 | } |
| 3787 | |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 3788 | static bool isVEXTMask(ArrayRef<int> M, EVT VT, |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3789 | bool &ReverseVEXT, unsigned &Imm) { |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3790 | unsigned NumElts = VT.getVectorNumElements(); |
| 3791 | ReverseVEXT = false; |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3792 | |
| 3793 | // Assume that the first shuffle index is not UNDEF. Fail if it is. |
| 3794 | if (M[0] < 0) |
| 3795 | return false; |
| 3796 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3797 | Imm = M[0]; |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3798 | |
| 3799 | // If this is a VEXT shuffle, the immediate value is the index of the first |
| 3800 | // element. The other shuffle indices must be the successive elements after |
| 3801 | // the first one. |
| 3802 | unsigned ExpectedElt = Imm; |
| 3803 | for (unsigned i = 1; i < NumElts; ++i) { |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3804 | // Increment the expected index. If it wraps around, it may still be |
| 3805 | // a VEXT but the source vectors must be swapped. |
| 3806 | ExpectedElt += 1; |
| 3807 | if (ExpectedElt == NumElts * 2) { |
| 3808 | ExpectedElt = 0; |
| 3809 | ReverseVEXT = true; |
| 3810 | } |
| 3811 | |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3812 | if (M[i] < 0) continue; // ignore UNDEF indices |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3813 | if (ExpectedElt != static_cast<unsigned>(M[i])) |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3814 | return false; |
| 3815 | } |
| 3816 | |
| 3817 | // Adjust the index value if the source operands will be swapped. |
| 3818 | if (ReverseVEXT) |
| 3819 | Imm -= NumElts; |
| 3820 | |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3821 | return true; |
| 3822 | } |
| 3823 | |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 3824 | /// isVREVMask - Check if a vector shuffle corresponds to a VREV |
| 3825 | /// instruction with the specified blocksize. (The order of the elements |
| 3826 | /// within each block of the vector is reversed.) |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 3827 | static bool isVREVMask(ArrayRef<int> M, EVT VT, unsigned BlockSize) { |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 3828 | assert((BlockSize==16 || BlockSize==32 || BlockSize==64) && |
| 3829 | "Only possible block sizes for VREV are: 16, 32, 64"); |
| 3830 | |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 3831 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 3832 | if (EltSz == 64) |
| 3833 | return false; |
| 3834 | |
| 3835 | unsigned NumElts = VT.getVectorNumElements(); |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3836 | unsigned BlockElts = M[0] + 1; |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3837 | // If the first shuffle index is UNDEF, be optimistic. |
| 3838 | if (M[0] < 0) |
| 3839 | BlockElts = BlockSize / EltSz; |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 3840 | |
| 3841 | if (BlockSize <= EltSz || BlockSize != BlockElts * EltSz) |
| 3842 | return false; |
| 3843 | |
| 3844 | for (unsigned i = 0; i < NumElts; ++i) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3845 | if (M[i] < 0) continue; // ignore UNDEF indices |
| 3846 | if ((unsigned) M[i] != (i - i%BlockElts) + (BlockElts - 1 - i%BlockElts)) |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 3847 | return false; |
| 3848 | } |
| 3849 | |
| 3850 | return true; |
| 3851 | } |
| 3852 | |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 3853 | static bool isVTBLMask(ArrayRef<int> M, EVT VT) { |
Bill Wendling | 0d4c9d9 | 2011-03-15 21:15:20 +0000 | [diff] [blame] | 3854 | // We can handle <8 x i8> vector shuffles. If the index in the mask is out of |
| 3855 | // range, then 0 is placed into the resulting vector. So pretty much any mask |
| 3856 | // of 8 elements can work here. |
| 3857 | return VT == MVT::v8i8 && M.size() == 8; |
| 3858 | } |
| 3859 | |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 3860 | static bool isVTRNMask(ArrayRef<int> M, EVT VT, unsigned &WhichResult) { |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 3861 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3862 | if (EltSz == 64) |
| 3863 | return false; |
| 3864 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3865 | unsigned NumElts = VT.getVectorNumElements(); |
| 3866 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3867 | for (unsigned i = 0; i < NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3868 | if ((M[i] >= 0 && (unsigned) M[i] != i + WhichResult) || |
| 3869 | (M[i+1] >= 0 && (unsigned) M[i+1] != i + NumElts + WhichResult)) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3870 | return false; |
| 3871 | } |
| 3872 | return true; |
| 3873 | } |
| 3874 | |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3875 | /// isVTRN_v_undef_Mask - Special case of isVTRNMask for canonical form of |
| 3876 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 3877 | /// 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] | 3878 | 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] | 3879 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3880 | if (EltSz == 64) |
| 3881 | return false; |
| 3882 | |
| 3883 | unsigned NumElts = VT.getVectorNumElements(); |
| 3884 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3885 | for (unsigned i = 0; i < NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3886 | if ((M[i] >= 0 && (unsigned) M[i] != i + WhichResult) || |
| 3887 | (M[i+1] >= 0 && (unsigned) M[i+1] != i + WhichResult)) |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3888 | return false; |
| 3889 | } |
| 3890 | return true; |
| 3891 | } |
| 3892 | |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 3893 | static bool isVUZPMask(ArrayRef<int> M, EVT VT, unsigned &WhichResult) { |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 3894 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3895 | if (EltSz == 64) |
| 3896 | return false; |
| 3897 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3898 | unsigned NumElts = VT.getVectorNumElements(); |
| 3899 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3900 | for (unsigned i = 0; i != NumElts; ++i) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3901 | if (M[i] < 0) continue; // ignore UNDEF indices |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3902 | if ((unsigned) M[i] != 2 * i + WhichResult) |
| 3903 | return false; |
| 3904 | } |
| 3905 | |
| 3906 | // 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] | 3907 | if (VT.is64BitVector() && EltSz == 32) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3908 | return false; |
| 3909 | |
| 3910 | return true; |
| 3911 | } |
| 3912 | |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3913 | /// isVUZP_v_undef_Mask - Special case of isVUZPMask for canonical form of |
| 3914 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 3915 | /// 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] | 3916 | 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] | 3917 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3918 | if (EltSz == 64) |
| 3919 | return false; |
| 3920 | |
| 3921 | unsigned Half = VT.getVectorNumElements() / 2; |
| 3922 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3923 | for (unsigned j = 0; j != 2; ++j) { |
| 3924 | unsigned Idx = WhichResult; |
| 3925 | for (unsigned i = 0; i != Half; ++i) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3926 | int MIdx = M[i + j * Half]; |
| 3927 | if (MIdx >= 0 && (unsigned) MIdx != Idx) |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3928 | return false; |
| 3929 | Idx += 2; |
| 3930 | } |
| 3931 | } |
| 3932 | |
| 3933 | // VUZP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32. |
| 3934 | if (VT.is64BitVector() && EltSz == 32) |
| 3935 | return false; |
| 3936 | |
| 3937 | return true; |
| 3938 | } |
| 3939 | |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 3940 | static bool isVZIPMask(ArrayRef<int> M, EVT VT, unsigned &WhichResult) { |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 3941 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3942 | if (EltSz == 64) |
| 3943 | return false; |
| 3944 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3945 | unsigned NumElts = VT.getVectorNumElements(); |
| 3946 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3947 | unsigned Idx = WhichResult * NumElts / 2; |
| 3948 | for (unsigned i = 0; i != NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3949 | if ((M[i] >= 0 && (unsigned) M[i] != Idx) || |
| 3950 | (M[i+1] >= 0 && (unsigned) M[i+1] != Idx + NumElts)) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3951 | return false; |
| 3952 | Idx += 1; |
| 3953 | } |
| 3954 | |
| 3955 | // 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] | 3956 | if (VT.is64BitVector() && EltSz == 32) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3957 | return false; |
| 3958 | |
| 3959 | return true; |
| 3960 | } |
| 3961 | |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3962 | /// isVZIP_v_undef_Mask - Special case of isVZIPMask for canonical form of |
| 3963 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 3964 | /// 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] | 3965 | 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] | 3966 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3967 | if (EltSz == 64) |
| 3968 | return false; |
| 3969 | |
| 3970 | unsigned NumElts = VT.getVectorNumElements(); |
| 3971 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3972 | unsigned Idx = WhichResult * NumElts / 2; |
| 3973 | for (unsigned i = 0; i != NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3974 | if ((M[i] >= 0 && (unsigned) M[i] != Idx) || |
| 3975 | (M[i+1] >= 0 && (unsigned) M[i+1] != Idx)) |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3976 | return false; |
| 3977 | Idx += 1; |
| 3978 | } |
| 3979 | |
| 3980 | // VZIP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32. |
| 3981 | if (VT.is64BitVector() && EltSz == 32) |
| 3982 | return false; |
| 3983 | |
| 3984 | return true; |
| 3985 | } |
| 3986 | |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 3987 | // If N is an integer constant that can be moved into a register in one |
| 3988 | // instruction, return an SDValue of such a constant (will become a MOV |
| 3989 | // instruction). Otherwise return null. |
| 3990 | static SDValue IsSingleInstrConstant(SDValue N, SelectionDAG &DAG, |
| 3991 | const ARMSubtarget *ST, DebugLoc dl) { |
| 3992 | uint64_t Val; |
| 3993 | if (!isa<ConstantSDNode>(N)) |
| 3994 | return SDValue(); |
| 3995 | Val = cast<ConstantSDNode>(N)->getZExtValue(); |
| 3996 | |
| 3997 | if (ST->isThumb1Only()) { |
| 3998 | if (Val <= 255 || ~Val <= 255) |
| 3999 | return DAG.getConstant(Val, MVT::i32); |
| 4000 | } else { |
| 4001 | if (ARM_AM::getSOImmVal(Val) != -1 || ARM_AM::getSOImmVal(~Val) != -1) |
| 4002 | return DAG.getConstant(Val, MVT::i32); |
| 4003 | } |
| 4004 | return SDValue(); |
| 4005 | } |
| 4006 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4007 | // If this is a case we can't handle, return null and let the default |
| 4008 | // expansion code take care of it. |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4009 | SDValue ARMTargetLowering::LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG, |
| 4010 | const ARMSubtarget *ST) const { |
Bob Wilson | d06791f | 2009-08-13 01:57:47 +0000 | [diff] [blame] | 4011 | BuildVectorSDNode *BVN = cast<BuildVectorSDNode>(Op.getNode()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4012 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4013 | EVT VT = Op.getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4014 | |
| 4015 | APInt SplatBits, SplatUndef; |
| 4016 | unsigned SplatBitSize; |
| 4017 | bool HasAnyUndefs; |
| 4018 | if (BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { |
Anton Korobeynikov | 71624cc | 2009-08-29 00:08:18 +0000 | [diff] [blame] | 4019 | if (SplatBitSize <= 64) { |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 4020 | // Check if an immediate VMOV works. |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4021 | EVT VmovVT; |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 4022 | SDValue Val = isNEONModifiedImm(SplatBits.getZExtValue(), |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4023 | SplatUndef.getZExtValue(), SplatBitSize, |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 4024 | DAG, VmovVT, VT.is128BitVector(), |
| 4025 | VMOVModImm); |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4026 | if (Val.getNode()) { |
| 4027 | SDValue Vmov = DAG.getNode(ARMISD::VMOVIMM, dl, VmovVT, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4028 | return DAG.getNode(ISD::BITCAST, dl, VT, Vmov); |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4029 | } |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 4030 | |
| 4031 | // Try an immediate VMVN. |
Eli Friedman | 8e4d042 | 2011-10-13 22:40:23 +0000 | [diff] [blame] | 4032 | uint64_t NegatedImm = (~SplatBits).getZExtValue(); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 4033 | Val = isNEONModifiedImm(NegatedImm, |
| 4034 | SplatUndef.getZExtValue(), SplatBitSize, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4035 | DAG, VmovVT, VT.is128BitVector(), |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 4036 | VMVNModImm); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 4037 | if (Val.getNode()) { |
| 4038 | SDValue Vmov = DAG.getNode(ARMISD::VMVNIMM, dl, VmovVT, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4039 | return DAG.getNode(ISD::BITCAST, dl, VT, Vmov); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 4040 | } |
Evan Cheng | eaa192a | 2011-11-15 02:12:34 +0000 | [diff] [blame] | 4041 | |
| 4042 | // Use vmov.f32 to materialize other v2f32 and v4f32 splats. |
Eli Friedman | 2f21e8c | 2011-12-15 22:56:53 +0000 | [diff] [blame] | 4043 | if ((VT == MVT::v2f32 || VT == MVT::v4f32) && SplatBitSize == 32) { |
Eli Friedman | effab8f | 2011-12-09 23:54:42 +0000 | [diff] [blame] | 4044 | int ImmVal = ARM_AM::getFP32Imm(SplatBits); |
Evan Cheng | eaa192a | 2011-11-15 02:12:34 +0000 | [diff] [blame] | 4045 | if (ImmVal != -1) { |
| 4046 | SDValue Val = DAG.getTargetConstant(ImmVal, MVT::i32); |
| 4047 | return DAG.getNode(ARMISD::VMOVFPIMM, dl, VT, Val); |
| 4048 | } |
| 4049 | } |
Anton Korobeynikov | 71624cc | 2009-08-29 00:08:18 +0000 | [diff] [blame] | 4050 | } |
Bob Wilson | cf661e2 | 2009-07-30 00:31:25 +0000 | [diff] [blame] | 4051 | } |
| 4052 | |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4053 | // Scan through the operands to see if only one value is used. |
| 4054 | unsigned NumElts = VT.getVectorNumElements(); |
| 4055 | bool isOnlyLowElement = true; |
| 4056 | bool usesOnlyOneValue = true; |
| 4057 | bool isConstant = true; |
| 4058 | SDValue Value; |
| 4059 | for (unsigned i = 0; i < NumElts; ++i) { |
| 4060 | SDValue V = Op.getOperand(i); |
| 4061 | if (V.getOpcode() == ISD::UNDEF) |
| 4062 | continue; |
| 4063 | if (i > 0) |
| 4064 | isOnlyLowElement = false; |
| 4065 | if (!isa<ConstantFPSDNode>(V) && !isa<ConstantSDNode>(V)) |
| 4066 | isConstant = false; |
| 4067 | |
| 4068 | if (!Value.getNode()) |
| 4069 | Value = V; |
| 4070 | else if (V != Value) |
| 4071 | usesOnlyOneValue = false; |
| 4072 | } |
| 4073 | |
| 4074 | if (!Value.getNode()) |
| 4075 | return DAG.getUNDEF(VT); |
| 4076 | |
| 4077 | if (isOnlyLowElement) |
| 4078 | return DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, VT, Value); |
| 4079 | |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 4080 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 4081 | |
Dale Johannesen | 575cd14 | 2010-10-19 20:00:17 +0000 | [diff] [blame] | 4082 | // Use VDUP for non-constant splats. For f32 constant splats, reduce to |
| 4083 | // i32 and try again. |
| 4084 | if (usesOnlyOneValue && EltSize <= 32) { |
| 4085 | if (!isConstant) |
| 4086 | return DAG.getNode(ARMISD::VDUP, dl, VT, Value); |
| 4087 | if (VT.getVectorElementType().isFloatingPoint()) { |
| 4088 | SmallVector<SDValue, 8> Ops; |
| 4089 | for (unsigned i = 0; i < NumElts; ++i) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4090 | Ops.push_back(DAG.getNode(ISD::BITCAST, dl, MVT::i32, |
Dale Johannesen | 575cd14 | 2010-10-19 20:00:17 +0000 | [diff] [blame] | 4091 | Op.getOperand(i))); |
Nate Begeman | bf5be26 | 2010-11-10 21:35:41 +0000 | [diff] [blame] | 4092 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), MVT::i32, NumElts); |
| 4093 | SDValue Val = DAG.getNode(ISD::BUILD_VECTOR, dl, VecVT, &Ops[0], NumElts); |
Dale Johannesen | e4d3159 | 2010-10-20 22:03:37 +0000 | [diff] [blame] | 4094 | Val = LowerBUILD_VECTOR(Val, DAG, ST); |
| 4095 | if (Val.getNode()) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4096 | return DAG.getNode(ISD::BITCAST, dl, VT, Val); |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 4097 | } |
Dale Johannesen | 575cd14 | 2010-10-19 20:00:17 +0000 | [diff] [blame] | 4098 | SDValue Val = IsSingleInstrConstant(Value, DAG, ST, dl); |
| 4099 | if (Val.getNode()) |
| 4100 | return DAG.getNode(ARMISD::VDUP, dl, VT, Val); |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 4101 | } |
| 4102 | |
| 4103 | // If all elements are constants and the case above didn't get hit, fall back |
| 4104 | // to the default expansion, which will generate a load from the constant |
| 4105 | // pool. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4106 | if (isConstant) |
| 4107 | return SDValue(); |
| 4108 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4109 | // Empirical tests suggest this is rarely worth it for vectors of length <= 2. |
| 4110 | if (NumElts >= 4) { |
| 4111 | SDValue shuffle = ReconstructShuffle(Op, DAG); |
| 4112 | if (shuffle != SDValue()) |
| 4113 | return shuffle; |
| 4114 | } |
| 4115 | |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4116 | // 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] | 4117 | // the subregisters. Lower it to an ARMISD::BUILD_VECTOR so the operands |
| 4118 | // will be legalized. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4119 | if (EltSize >= 32) { |
| 4120 | // Do the expansion with floating-point types, since that is what the VFP |
| 4121 | // registers are defined to use, and since i64 is not legal. |
| 4122 | EVT EltVT = EVT::getFloatingPointVT(EltSize); |
| 4123 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), EltVT, NumElts); |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4124 | SmallVector<SDValue, 8> Ops; |
| 4125 | for (unsigned i = 0; i < NumElts; ++i) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4126 | Ops.push_back(DAG.getNode(ISD::BITCAST, dl, EltVT, Op.getOperand(i))); |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4127 | SDValue Val = DAG.getNode(ARMISD::BUILD_VECTOR, dl, VecVT, &Ops[0],NumElts); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4128 | return DAG.getNode(ISD::BITCAST, dl, VT, Val); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4129 | } |
| 4130 | |
| 4131 | return SDValue(); |
| 4132 | } |
| 4133 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4134 | // Gather data to see if the operation can be modelled as a |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4135 | // shuffle in combination with VEXTs. |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4136 | SDValue ARMTargetLowering::ReconstructShuffle(SDValue Op, |
| 4137 | SelectionDAG &DAG) const { |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4138 | DebugLoc dl = Op.getDebugLoc(); |
| 4139 | EVT VT = Op.getValueType(); |
| 4140 | unsigned NumElts = VT.getVectorNumElements(); |
| 4141 | |
| 4142 | SmallVector<SDValue, 2> SourceVecs; |
| 4143 | SmallVector<unsigned, 2> MinElts; |
| 4144 | SmallVector<unsigned, 2> MaxElts; |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4145 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4146 | for (unsigned i = 0; i < NumElts; ++i) { |
| 4147 | SDValue V = Op.getOperand(i); |
| 4148 | if (V.getOpcode() == ISD::UNDEF) |
| 4149 | continue; |
| 4150 | else if (V.getOpcode() != ISD::EXTRACT_VECTOR_ELT) { |
| 4151 | // A shuffle can only come from building a vector from various |
| 4152 | // elements of other vectors. |
| 4153 | return SDValue(); |
Eli Friedman | 46995fa | 2011-10-14 23:58:49 +0000 | [diff] [blame] | 4154 | } else if (V.getOperand(0).getValueType().getVectorElementType() != |
| 4155 | VT.getVectorElementType()) { |
| 4156 | // This code doesn't know how to handle shuffles where the vector |
| 4157 | // element types do not match (this happens because type legalization |
| 4158 | // promotes the return type of EXTRACT_VECTOR_ELT). |
| 4159 | // FIXME: It might be appropriate to extend this code to handle |
| 4160 | // mismatched types. |
| 4161 | return SDValue(); |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4162 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4163 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4164 | // Record this extraction against the appropriate vector if possible... |
| 4165 | SDValue SourceVec = V.getOperand(0); |
| 4166 | unsigned EltNo = cast<ConstantSDNode>(V.getOperand(1))->getZExtValue(); |
| 4167 | bool FoundSource = false; |
| 4168 | for (unsigned j = 0; j < SourceVecs.size(); ++j) { |
| 4169 | if (SourceVecs[j] == SourceVec) { |
| 4170 | if (MinElts[j] > EltNo) |
| 4171 | MinElts[j] = EltNo; |
| 4172 | if (MaxElts[j] < EltNo) |
| 4173 | MaxElts[j] = EltNo; |
| 4174 | FoundSource = true; |
| 4175 | break; |
| 4176 | } |
| 4177 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4178 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4179 | // Or record a new source if not... |
| 4180 | if (!FoundSource) { |
| 4181 | SourceVecs.push_back(SourceVec); |
| 4182 | MinElts.push_back(EltNo); |
| 4183 | MaxElts.push_back(EltNo); |
| 4184 | } |
| 4185 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4186 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4187 | // Currently only do something sane when at most two source vectors |
| 4188 | // involved. |
| 4189 | if (SourceVecs.size() > 2) |
| 4190 | return SDValue(); |
| 4191 | |
| 4192 | SDValue ShuffleSrcs[2] = {DAG.getUNDEF(VT), DAG.getUNDEF(VT) }; |
| 4193 | int VEXTOffsets[2] = {0, 0}; |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4194 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4195 | // This loop extracts the usage patterns of the source vectors |
| 4196 | // and prepares appropriate SDValues for a shuffle if possible. |
| 4197 | for (unsigned i = 0; i < SourceVecs.size(); ++i) { |
| 4198 | if (SourceVecs[i].getValueType() == VT) { |
| 4199 | // No VEXT necessary |
| 4200 | ShuffleSrcs[i] = SourceVecs[i]; |
| 4201 | VEXTOffsets[i] = 0; |
| 4202 | continue; |
| 4203 | } else if (SourceVecs[i].getValueType().getVectorNumElements() < NumElts) { |
| 4204 | // It probably isn't worth padding out a smaller vector just to |
| 4205 | // break it down again in a shuffle. |
| 4206 | return SDValue(); |
| 4207 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4208 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4209 | // Since only 64-bit and 128-bit vectors are legal on ARM and |
| 4210 | // we've eliminated the other cases... |
Bob Wilson | 70f8573 | 2011-01-07 23:40:46 +0000 | [diff] [blame] | 4211 | assert(SourceVecs[i].getValueType().getVectorNumElements() == 2*NumElts && |
| 4212 | "unexpected vector sizes in ReconstructShuffle"); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4213 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4214 | if (MaxElts[i] - MinElts[i] >= NumElts) { |
| 4215 | // Span too large for a VEXT to cope |
| 4216 | return SDValue(); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4217 | } |
| 4218 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4219 | if (MinElts[i] >= NumElts) { |
| 4220 | // The extraction can just take the second half |
| 4221 | VEXTOffsets[i] = NumElts; |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4222 | ShuffleSrcs[i] = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 4223 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4224 | DAG.getIntPtrConstant(NumElts)); |
| 4225 | } else if (MaxElts[i] < NumElts) { |
| 4226 | // The extraction can just take the first half |
| 4227 | VEXTOffsets[i] = 0; |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4228 | ShuffleSrcs[i] = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 4229 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4230 | DAG.getIntPtrConstant(0)); |
| 4231 | } else { |
| 4232 | // An actual VEXT is needed |
| 4233 | VEXTOffsets[i] = MinElts[i]; |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4234 | SDValue VEXTSrc1 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 4235 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4236 | DAG.getIntPtrConstant(0)); |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4237 | SDValue VEXTSrc2 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 4238 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4239 | DAG.getIntPtrConstant(NumElts)); |
| 4240 | ShuffleSrcs[i] = DAG.getNode(ARMISD::VEXT, dl, VT, VEXTSrc1, VEXTSrc2, |
| 4241 | DAG.getConstant(VEXTOffsets[i], MVT::i32)); |
| 4242 | } |
| 4243 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4244 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4245 | SmallVector<int, 8> Mask; |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4246 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4247 | for (unsigned i = 0; i < NumElts; ++i) { |
| 4248 | SDValue Entry = Op.getOperand(i); |
| 4249 | if (Entry.getOpcode() == ISD::UNDEF) { |
| 4250 | Mask.push_back(-1); |
| 4251 | continue; |
| 4252 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4253 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4254 | SDValue ExtractVec = Entry.getOperand(0); |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4255 | int ExtractElt = cast<ConstantSDNode>(Op.getOperand(i) |
| 4256 | .getOperand(1))->getSExtValue(); |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4257 | if (ExtractVec == SourceVecs[0]) { |
| 4258 | Mask.push_back(ExtractElt - VEXTOffsets[0]); |
| 4259 | } else { |
| 4260 | Mask.push_back(ExtractElt + NumElts - VEXTOffsets[1]); |
| 4261 | } |
| 4262 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4263 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4264 | // Final check before we try to produce nonsense... |
| 4265 | if (isShuffleMaskLegal(Mask, VT)) |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4266 | return DAG.getVectorShuffle(VT, dl, ShuffleSrcs[0], ShuffleSrcs[1], |
| 4267 | &Mask[0]); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4268 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4269 | return SDValue(); |
| 4270 | } |
| 4271 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4272 | /// isShuffleMaskLegal - Targets can use this to indicate that they only |
| 4273 | /// support *some* VECTOR_SHUFFLE operations, those with specific masks. |
| 4274 | /// By default, if a target supports the VECTOR_SHUFFLE node, all mask values |
| 4275 | /// are assumed to be legal. |
| 4276 | bool |
| 4277 | ARMTargetLowering::isShuffleMaskLegal(const SmallVectorImpl<int> &M, |
| 4278 | EVT VT) const { |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4279 | if (VT.getVectorNumElements() == 4 && |
| 4280 | (VT.is128BitVector() || VT.is64BitVector())) { |
| 4281 | unsigned PFIndexes[4]; |
| 4282 | for (unsigned i = 0; i != 4; ++i) { |
| 4283 | if (M[i] < 0) |
| 4284 | PFIndexes[i] = 8; |
| 4285 | else |
| 4286 | PFIndexes[i] = M[i]; |
| 4287 | } |
| 4288 | |
| 4289 | // Compute the index in the perfect shuffle table. |
| 4290 | unsigned PFTableIndex = |
| 4291 | PFIndexes[0]*9*9*9+PFIndexes[1]*9*9+PFIndexes[2]*9+PFIndexes[3]; |
| 4292 | unsigned PFEntry = PerfectShuffleTable[PFTableIndex]; |
| 4293 | unsigned Cost = (PFEntry >> 30); |
| 4294 | |
| 4295 | if (Cost <= 4) |
| 4296 | return true; |
| 4297 | } |
| 4298 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4299 | bool ReverseVEXT; |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4300 | unsigned Imm, WhichResult; |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4301 | |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4302 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 4303 | return (EltSize >= 32 || |
| 4304 | ShuffleVectorSDNode::isSplatMask(&M[0], VT) || |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4305 | isVREVMask(M, VT, 64) || |
| 4306 | isVREVMask(M, VT, 32) || |
| 4307 | isVREVMask(M, VT, 16) || |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4308 | isVEXTMask(M, VT, ReverseVEXT, Imm) || |
Bill Wendling | 0d4c9d9 | 2011-03-15 21:15:20 +0000 | [diff] [blame] | 4309 | isVTBLMask(M, VT) || |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4310 | isVTRNMask(M, VT, WhichResult) || |
| 4311 | isVUZPMask(M, VT, WhichResult) || |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4312 | isVZIPMask(M, VT, WhichResult) || |
| 4313 | isVTRN_v_undef_Mask(M, VT, WhichResult) || |
| 4314 | isVUZP_v_undef_Mask(M, VT, WhichResult) || |
| 4315 | isVZIP_v_undef_Mask(M, VT, WhichResult)); |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4316 | } |
| 4317 | |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4318 | /// GeneratePerfectShuffle - Given an entry in the perfect-shuffle table, emit |
| 4319 | /// the specified operations to build the shuffle. |
| 4320 | static SDValue GeneratePerfectShuffle(unsigned PFEntry, SDValue LHS, |
| 4321 | SDValue RHS, SelectionDAG &DAG, |
| 4322 | DebugLoc dl) { |
| 4323 | unsigned OpNum = (PFEntry >> 26) & 0x0F; |
| 4324 | unsigned LHSID = (PFEntry >> 13) & ((1 << 13)-1); |
| 4325 | unsigned RHSID = (PFEntry >> 0) & ((1 << 13)-1); |
| 4326 | |
| 4327 | enum { |
| 4328 | OP_COPY = 0, // Copy, used for things like <u,u,u,3> to say it is <0,1,2,3> |
| 4329 | OP_VREV, |
| 4330 | OP_VDUP0, |
| 4331 | OP_VDUP1, |
| 4332 | OP_VDUP2, |
| 4333 | OP_VDUP3, |
| 4334 | OP_VEXT1, |
| 4335 | OP_VEXT2, |
| 4336 | OP_VEXT3, |
| 4337 | OP_VUZPL, // VUZP, left result |
| 4338 | OP_VUZPR, // VUZP, right result |
| 4339 | OP_VZIPL, // VZIP, left result |
| 4340 | OP_VZIPR, // VZIP, right result |
| 4341 | OP_VTRNL, // VTRN, left result |
| 4342 | OP_VTRNR // VTRN, right result |
| 4343 | }; |
| 4344 | |
| 4345 | if (OpNum == OP_COPY) { |
| 4346 | if (LHSID == (1*9+2)*9+3) return LHS; |
| 4347 | assert(LHSID == ((4*9+5)*9+6)*9+7 && "Illegal OP_COPY!"); |
| 4348 | return RHS; |
| 4349 | } |
| 4350 | |
| 4351 | SDValue OpLHS, OpRHS; |
| 4352 | OpLHS = GeneratePerfectShuffle(PerfectShuffleTable[LHSID], LHS, RHS, DAG, dl); |
| 4353 | OpRHS = GeneratePerfectShuffle(PerfectShuffleTable[RHSID], LHS, RHS, DAG, dl); |
| 4354 | EVT VT = OpLHS.getValueType(); |
| 4355 | |
| 4356 | switch (OpNum) { |
| 4357 | default: llvm_unreachable("Unknown shuffle opcode!"); |
| 4358 | case OP_VREV: |
Tanya Lattner | 2a8eb72 | 2011-05-18 06:42:21 +0000 | [diff] [blame] | 4359 | // VREV divides the vector in half and swaps within the half. |
Tanya Lattner | db28247 | 2011-05-18 21:44:54 +0000 | [diff] [blame] | 4360 | if (VT.getVectorElementType() == MVT::i32 || |
| 4361 | VT.getVectorElementType() == MVT::f32) |
Tanya Lattner | 2a8eb72 | 2011-05-18 06:42:21 +0000 | [diff] [blame] | 4362 | return DAG.getNode(ARMISD::VREV64, dl, VT, OpLHS); |
| 4363 | // vrev <4 x i16> -> VREV32 |
| 4364 | if (VT.getVectorElementType() == MVT::i16) |
| 4365 | return DAG.getNode(ARMISD::VREV32, dl, VT, OpLHS); |
| 4366 | // vrev <4 x i8> -> VREV16 |
| 4367 | assert(VT.getVectorElementType() == MVT::i8); |
| 4368 | return DAG.getNode(ARMISD::VREV16, dl, VT, OpLHS); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4369 | case OP_VDUP0: |
| 4370 | case OP_VDUP1: |
| 4371 | case OP_VDUP2: |
| 4372 | case OP_VDUP3: |
| 4373 | return DAG.getNode(ARMISD::VDUPLANE, dl, VT, |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 4374 | OpLHS, DAG.getConstant(OpNum-OP_VDUP0, MVT::i32)); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4375 | case OP_VEXT1: |
| 4376 | case OP_VEXT2: |
| 4377 | case OP_VEXT3: |
| 4378 | return DAG.getNode(ARMISD::VEXT, dl, VT, |
| 4379 | OpLHS, OpRHS, |
| 4380 | DAG.getConstant(OpNum-OP_VEXT1+1, MVT::i32)); |
| 4381 | case OP_VUZPL: |
| 4382 | case OP_VUZPR: |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 4383 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4384 | OpLHS, OpRHS).getValue(OpNum-OP_VUZPL); |
| 4385 | case OP_VZIPL: |
| 4386 | case OP_VZIPR: |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 4387 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4388 | OpLHS, OpRHS).getValue(OpNum-OP_VZIPL); |
| 4389 | case OP_VTRNL: |
| 4390 | case OP_VTRNR: |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 4391 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), |
| 4392 | OpLHS, OpRHS).getValue(OpNum-OP_VTRNL); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4393 | } |
| 4394 | } |
| 4395 | |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4396 | static SDValue LowerVECTOR_SHUFFLEv8i8(SDValue Op, |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4397 | ArrayRef<int> ShuffleMask, |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4398 | SelectionDAG &DAG) { |
| 4399 | // Check to see if we can use the VTBL instruction. |
| 4400 | SDValue V1 = Op.getOperand(0); |
| 4401 | SDValue V2 = Op.getOperand(1); |
| 4402 | DebugLoc DL = Op.getDebugLoc(); |
| 4403 | |
| 4404 | SmallVector<SDValue, 8> VTBLMask; |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4405 | for (ArrayRef<int>::iterator |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4406 | I = ShuffleMask.begin(), E = ShuffleMask.end(); I != E; ++I) |
| 4407 | VTBLMask.push_back(DAG.getConstant(*I, MVT::i32)); |
| 4408 | |
| 4409 | if (V2.getNode()->getOpcode() == ISD::UNDEF) |
| 4410 | return DAG.getNode(ARMISD::VTBL1, DL, MVT::v8i8, V1, |
| 4411 | DAG.getNode(ISD::BUILD_VECTOR, DL, MVT::v8i8, |
| 4412 | &VTBLMask[0], 8)); |
Bill Wendling | a24cb40 | 2011-03-15 20:47:26 +0000 | [diff] [blame] | 4413 | |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4414 | return DAG.getNode(ARMISD::VTBL2, DL, MVT::v8i8, V1, V2, |
Bill Wendling | a24cb40 | 2011-03-15 20:47:26 +0000 | [diff] [blame] | 4415 | DAG.getNode(ISD::BUILD_VECTOR, DL, MVT::v8i8, |
| 4416 | &VTBLMask[0], 8)); |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4417 | } |
| 4418 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4419 | static SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) { |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4420 | SDValue V1 = Op.getOperand(0); |
| 4421 | SDValue V2 = Op.getOperand(1); |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 4422 | DebugLoc dl = Op.getDebugLoc(); |
| 4423 | EVT VT = Op.getValueType(); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4424 | ShuffleVectorSDNode *SVN = cast<ShuffleVectorSDNode>(Op.getNode()); |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 4425 | |
Bob Wilson | 2886506 | 2009-08-13 02:13:04 +0000 | [diff] [blame] | 4426 | // Convert shuffles that are directly supported on NEON to target-specific |
| 4427 | // DAG nodes, instead of keeping them as shuffles and matching them again |
| 4428 | // during code selection. This is more efficient and avoids the possibility |
| 4429 | // of inconsistencies between legalization and selection. |
Bob Wilson | bfcbb50 | 2009-08-13 06:01:30 +0000 | [diff] [blame] | 4430 | // FIXME: floating-point vectors should be canonicalized to integer vectors |
| 4431 | // of the same time so that they get CSEd properly. |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4432 | ArrayRef<int> ShuffleMask = SVN->getMask(); |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4433 | |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4434 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 4435 | if (EltSize <= 32) { |
| 4436 | if (ShuffleVectorSDNode::isSplatMask(&ShuffleMask[0], VT)) { |
| 4437 | int Lane = SVN->getSplatIndex(); |
| 4438 | // If this is undef splat, generate it via "just" vdup, if possible. |
| 4439 | if (Lane == -1) Lane = 0; |
Anton Korobeynikov | 2ae0eec | 2009-11-02 00:12:06 +0000 | [diff] [blame] | 4440 | |
Dan Gohman | 65fd656 | 2011-11-03 21:49:52 +0000 | [diff] [blame] | 4441 | // Test if V1 is a SCALAR_TO_VECTOR. |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4442 | if (Lane == 0 && V1.getOpcode() == ISD::SCALAR_TO_VECTOR) { |
| 4443 | return DAG.getNode(ARMISD::VDUP, dl, VT, V1.getOperand(0)); |
| 4444 | } |
Dan Gohman | 65fd656 | 2011-11-03 21:49:52 +0000 | [diff] [blame] | 4445 | // Test if V1 is a BUILD_VECTOR which is equivalent to a SCALAR_TO_VECTOR |
| 4446 | // (and probably will turn into a SCALAR_TO_VECTOR once legalization |
| 4447 | // reaches it). |
| 4448 | if (Lane == 0 && V1.getOpcode() == ISD::BUILD_VECTOR && |
| 4449 | !isa<ConstantSDNode>(V1.getOperand(0))) { |
| 4450 | bool IsScalarToVector = true; |
| 4451 | for (unsigned i = 1, e = V1.getNumOperands(); i != e; ++i) |
| 4452 | if (V1.getOperand(i).getOpcode() != ISD::UNDEF) { |
| 4453 | IsScalarToVector = false; |
| 4454 | break; |
| 4455 | } |
| 4456 | if (IsScalarToVector) |
| 4457 | return DAG.getNode(ARMISD::VDUP, dl, VT, V1.getOperand(0)); |
| 4458 | } |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4459 | return DAG.getNode(ARMISD::VDUPLANE, dl, VT, V1, |
| 4460 | DAG.getConstant(Lane, MVT::i32)); |
Bob Wilson | c1d287b | 2009-08-14 05:13:08 +0000 | [diff] [blame] | 4461 | } |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4462 | |
| 4463 | bool ReverseVEXT; |
| 4464 | unsigned Imm; |
| 4465 | if (isVEXTMask(ShuffleMask, VT, ReverseVEXT, Imm)) { |
| 4466 | if (ReverseVEXT) |
| 4467 | std::swap(V1, V2); |
| 4468 | return DAG.getNode(ARMISD::VEXT, dl, VT, V1, V2, |
| 4469 | DAG.getConstant(Imm, MVT::i32)); |
| 4470 | } |
| 4471 | |
| 4472 | if (isVREVMask(ShuffleMask, VT, 64)) |
| 4473 | return DAG.getNode(ARMISD::VREV64, dl, VT, V1); |
| 4474 | if (isVREVMask(ShuffleMask, VT, 32)) |
| 4475 | return DAG.getNode(ARMISD::VREV32, dl, VT, V1); |
| 4476 | if (isVREVMask(ShuffleMask, VT, 16)) |
| 4477 | return DAG.getNode(ARMISD::VREV16, dl, VT, V1); |
| 4478 | |
| 4479 | // Check for Neon shuffles that modify both input vectors in place. |
| 4480 | // If both results are used, i.e., if there are two shuffles with the same |
| 4481 | // source operands and with masks corresponding to both results of one of |
| 4482 | // these operations, DAG memoization will ensure that a single node is |
| 4483 | // used for both shuffles. |
| 4484 | unsigned WhichResult; |
| 4485 | if (isVTRNMask(ShuffleMask, VT, WhichResult)) |
| 4486 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), |
| 4487 | V1, V2).getValue(WhichResult); |
| 4488 | if (isVUZPMask(ShuffleMask, VT, WhichResult)) |
| 4489 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), |
| 4490 | V1, V2).getValue(WhichResult); |
| 4491 | if (isVZIPMask(ShuffleMask, VT, WhichResult)) |
| 4492 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), |
| 4493 | V1, V2).getValue(WhichResult); |
| 4494 | |
| 4495 | if (isVTRN_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 4496 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), |
| 4497 | V1, V1).getValue(WhichResult); |
| 4498 | if (isVUZP_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 4499 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), |
| 4500 | V1, V1).getValue(WhichResult); |
| 4501 | if (isVZIP_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 4502 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), |
| 4503 | V1, V1).getValue(WhichResult); |
Bob Wilson | 0ce3710 | 2009-08-14 05:08:32 +0000 | [diff] [blame] | 4504 | } |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 4505 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4506 | // If the shuffle is not directly supported and it has 4 elements, use |
| 4507 | // the PerfectShuffle-generated table to synthesize it from other shuffles. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4508 | unsigned NumElts = VT.getVectorNumElements(); |
| 4509 | if (NumElts == 4) { |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4510 | unsigned PFIndexes[4]; |
| 4511 | for (unsigned i = 0; i != 4; ++i) { |
| 4512 | if (ShuffleMask[i] < 0) |
| 4513 | PFIndexes[i] = 8; |
| 4514 | else |
| 4515 | PFIndexes[i] = ShuffleMask[i]; |
| 4516 | } |
| 4517 | |
| 4518 | // Compute the index in the perfect shuffle table. |
| 4519 | unsigned PFTableIndex = |
| 4520 | 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] | 4521 | unsigned PFEntry = PerfectShuffleTable[PFTableIndex]; |
| 4522 | unsigned Cost = (PFEntry >> 30); |
| 4523 | |
| 4524 | if (Cost <= 4) |
| 4525 | return GeneratePerfectShuffle(PFEntry, V1, V2, DAG, dl); |
| 4526 | } |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 4527 | |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4528 | // Implement shuffles with 32- or 64-bit elements as ARMISD::BUILD_VECTORs. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4529 | if (EltSize >= 32) { |
| 4530 | // Do the expansion with floating-point types, since that is what the VFP |
| 4531 | // registers are defined to use, and since i64 is not legal. |
| 4532 | EVT EltVT = EVT::getFloatingPointVT(EltSize); |
| 4533 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), EltVT, NumElts); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4534 | V1 = DAG.getNode(ISD::BITCAST, dl, VecVT, V1); |
| 4535 | V2 = DAG.getNode(ISD::BITCAST, dl, VecVT, V2); |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4536 | SmallVector<SDValue, 8> Ops; |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4537 | for (unsigned i = 0; i < NumElts; ++i) { |
Bob Wilson | 63b8845 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 4538 | if (ShuffleMask[i] < 0) |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4539 | Ops.push_back(DAG.getUNDEF(EltVT)); |
| 4540 | else |
| 4541 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, EltVT, |
| 4542 | ShuffleMask[i] < (int)NumElts ? V1 : V2, |
| 4543 | DAG.getConstant(ShuffleMask[i] & (NumElts-1), |
| 4544 | MVT::i32))); |
Bob Wilson | 63b8845 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 4545 | } |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4546 | SDValue Val = DAG.getNode(ARMISD::BUILD_VECTOR, dl, VecVT, &Ops[0],NumElts); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4547 | return DAG.getNode(ISD::BITCAST, dl, VT, Val); |
Bob Wilson | 63b8845 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 4548 | } |
| 4549 | |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4550 | if (VT == MVT::v8i8) { |
| 4551 | SDValue NewOp = LowerVECTOR_SHUFFLEv8i8(Op, ShuffleMask, DAG); |
| 4552 | if (NewOp.getNode()) |
| 4553 | return NewOp; |
| 4554 | } |
| 4555 | |
Bob Wilson | 22cac0d | 2009-08-14 05:16:33 +0000 | [diff] [blame] | 4556 | return SDValue(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4557 | } |
| 4558 | |
Eli Friedman | 5c89cb8 | 2011-10-24 23:08:52 +0000 | [diff] [blame] | 4559 | static SDValue LowerINSERT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) { |
| 4560 | // INSERT_VECTOR_ELT is legal only for immediate indexes. |
| 4561 | SDValue Lane = Op.getOperand(2); |
| 4562 | if (!isa<ConstantSDNode>(Lane)) |
| 4563 | return SDValue(); |
| 4564 | |
| 4565 | return Op; |
| 4566 | } |
| 4567 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4568 | static SDValue LowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) { |
Bob Wilson | 3468c2e | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 4569 | // EXTRACT_VECTOR_ELT is legal only for immediate indexes. |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4570 | SDValue Lane = Op.getOperand(1); |
Bob Wilson | 3468c2e | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 4571 | if (!isa<ConstantSDNode>(Lane)) |
| 4572 | return SDValue(); |
| 4573 | |
| 4574 | SDValue Vec = Op.getOperand(0); |
| 4575 | if (Op.getValueType() == MVT::i32 && |
| 4576 | Vec.getValueType().getVectorElementType().getSizeInBits() < 32) { |
| 4577 | DebugLoc dl = Op.getDebugLoc(); |
| 4578 | return DAG.getNode(ARMISD::VGETLANEu, dl, MVT::i32, Vec, Lane); |
| 4579 | } |
| 4580 | |
| 4581 | return Op; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4582 | } |
| 4583 | |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 4584 | static SDValue LowerCONCAT_VECTORS(SDValue Op, SelectionDAG &DAG) { |
| 4585 | // The only time a CONCAT_VECTORS operation can have legal types is when |
| 4586 | // two 64-bit vectors are concatenated to a 128-bit vector. |
| 4587 | assert(Op.getValueType().is128BitVector() && Op.getNumOperands() == 2 && |
| 4588 | "unexpected CONCAT_VECTORS"); |
| 4589 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4590 | SDValue Val = DAG.getUNDEF(MVT::v2f64); |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 4591 | SDValue Op0 = Op.getOperand(0); |
| 4592 | SDValue Op1 = Op.getOperand(1); |
| 4593 | if (Op0.getOpcode() != ISD::UNDEF) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4594 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Val, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4595 | DAG.getNode(ISD::BITCAST, dl, MVT::f64, Op0), |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 4596 | DAG.getIntPtrConstant(0)); |
| 4597 | if (Op1.getOpcode() != ISD::UNDEF) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4598 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Val, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4599 | DAG.getNode(ISD::BITCAST, dl, MVT::f64, Op1), |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 4600 | DAG.getIntPtrConstant(1)); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4601 | return DAG.getNode(ISD::BITCAST, dl, Op.getValueType(), Val); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4602 | } |
| 4603 | |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 4604 | /// isExtendedBUILD_VECTOR - Check if N is a constant BUILD_VECTOR where each |
| 4605 | /// element has been zero/sign-extended, depending on the isSigned parameter, |
| 4606 | /// from an integer type half its size. |
| 4607 | static bool isExtendedBUILD_VECTOR(SDNode *N, SelectionDAG &DAG, |
| 4608 | bool isSigned) { |
| 4609 | // A v2i64 BUILD_VECTOR will have been legalized to a BITCAST from v4i32. |
| 4610 | EVT VT = N->getValueType(0); |
| 4611 | if (VT == MVT::v2i64 && N->getOpcode() == ISD::BITCAST) { |
| 4612 | SDNode *BVN = N->getOperand(0).getNode(); |
| 4613 | if (BVN->getValueType(0) != MVT::v4i32 || |
| 4614 | BVN->getOpcode() != ISD::BUILD_VECTOR) |
| 4615 | return false; |
| 4616 | unsigned LoElt = DAG.getTargetLoweringInfo().isBigEndian() ? 1 : 0; |
| 4617 | unsigned HiElt = 1 - LoElt; |
| 4618 | ConstantSDNode *Lo0 = dyn_cast<ConstantSDNode>(BVN->getOperand(LoElt)); |
| 4619 | ConstantSDNode *Hi0 = dyn_cast<ConstantSDNode>(BVN->getOperand(HiElt)); |
| 4620 | ConstantSDNode *Lo1 = dyn_cast<ConstantSDNode>(BVN->getOperand(LoElt+2)); |
| 4621 | ConstantSDNode *Hi1 = dyn_cast<ConstantSDNode>(BVN->getOperand(HiElt+2)); |
| 4622 | if (!Lo0 || !Hi0 || !Lo1 || !Hi1) |
| 4623 | return false; |
| 4624 | if (isSigned) { |
| 4625 | if (Hi0->getSExtValue() == Lo0->getSExtValue() >> 32 && |
| 4626 | Hi1->getSExtValue() == Lo1->getSExtValue() >> 32) |
| 4627 | return true; |
| 4628 | } else { |
| 4629 | if (Hi0->isNullValue() && Hi1->isNullValue()) |
| 4630 | return true; |
| 4631 | } |
| 4632 | return false; |
| 4633 | } |
| 4634 | |
| 4635 | if (N->getOpcode() != ISD::BUILD_VECTOR) |
| 4636 | return false; |
| 4637 | |
| 4638 | for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) { |
| 4639 | SDNode *Elt = N->getOperand(i).getNode(); |
| 4640 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Elt)) { |
| 4641 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 4642 | unsigned HalfSize = EltSize / 2; |
| 4643 | if (isSigned) { |
Bob Wilson | 9d45de2 | 2011-10-18 18:46:49 +0000 | [diff] [blame] | 4644 | if (!isIntN(HalfSize, C->getSExtValue())) |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 4645 | return false; |
| 4646 | } else { |
Bob Wilson | 9d45de2 | 2011-10-18 18:46:49 +0000 | [diff] [blame] | 4647 | if (!isUIntN(HalfSize, C->getZExtValue())) |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 4648 | return false; |
| 4649 | } |
| 4650 | continue; |
| 4651 | } |
| 4652 | return false; |
| 4653 | } |
| 4654 | |
| 4655 | return true; |
| 4656 | } |
| 4657 | |
| 4658 | /// isSignExtended - Check if a node is a vector value that is sign-extended |
| 4659 | /// or a constant BUILD_VECTOR with sign-extended elements. |
| 4660 | static bool isSignExtended(SDNode *N, SelectionDAG &DAG) { |
| 4661 | if (N->getOpcode() == ISD::SIGN_EXTEND || ISD::isSEXTLoad(N)) |
| 4662 | return true; |
| 4663 | if (isExtendedBUILD_VECTOR(N, DAG, true)) |
| 4664 | return true; |
| 4665 | return false; |
| 4666 | } |
| 4667 | |
| 4668 | /// isZeroExtended - Check if a node is a vector value that is zero-extended |
| 4669 | /// or a constant BUILD_VECTOR with zero-extended elements. |
| 4670 | static bool isZeroExtended(SDNode *N, SelectionDAG &DAG) { |
| 4671 | if (N->getOpcode() == ISD::ZERO_EXTEND || ISD::isZEXTLoad(N)) |
| 4672 | return true; |
| 4673 | if (isExtendedBUILD_VECTOR(N, DAG, false)) |
| 4674 | return true; |
| 4675 | return false; |
| 4676 | } |
| 4677 | |
| 4678 | /// SkipExtension - For a node that is a SIGN_EXTEND, ZERO_EXTEND, extending |
| 4679 | /// load, or BUILD_VECTOR with extended elements, return the unextended value. |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4680 | static SDValue SkipExtension(SDNode *N, SelectionDAG &DAG) { |
| 4681 | if (N->getOpcode() == ISD::SIGN_EXTEND || N->getOpcode() == ISD::ZERO_EXTEND) |
| 4682 | return N->getOperand(0); |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 4683 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) |
| 4684 | return DAG.getLoad(LD->getMemoryVT(), N->getDebugLoc(), LD->getChain(), |
| 4685 | LD->getBasePtr(), LD->getPointerInfo(), LD->isVolatile(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 4686 | LD->isNonTemporal(), LD->isInvariant(), |
| 4687 | LD->getAlignment()); |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 4688 | // Otherwise, the value must be a BUILD_VECTOR. For v2i64, it will |
| 4689 | // have been legalized as a BITCAST from v4i32. |
| 4690 | if (N->getOpcode() == ISD::BITCAST) { |
| 4691 | SDNode *BVN = N->getOperand(0).getNode(); |
| 4692 | assert(BVN->getOpcode() == ISD::BUILD_VECTOR && |
| 4693 | BVN->getValueType(0) == MVT::v4i32 && "expected v4i32 BUILD_VECTOR"); |
| 4694 | unsigned LowElt = DAG.getTargetLoweringInfo().isBigEndian() ? 1 : 0; |
| 4695 | return DAG.getNode(ISD::BUILD_VECTOR, N->getDebugLoc(), MVT::v2i32, |
| 4696 | BVN->getOperand(LowElt), BVN->getOperand(LowElt+2)); |
| 4697 | } |
| 4698 | // Construct a new BUILD_VECTOR with elements truncated to half the size. |
| 4699 | assert(N->getOpcode() == ISD::BUILD_VECTOR && "expected BUILD_VECTOR"); |
| 4700 | EVT VT = N->getValueType(0); |
| 4701 | unsigned EltSize = VT.getVectorElementType().getSizeInBits() / 2; |
| 4702 | unsigned NumElts = VT.getVectorNumElements(); |
| 4703 | MVT TruncVT = MVT::getIntegerVT(EltSize); |
| 4704 | SmallVector<SDValue, 8> Ops; |
| 4705 | for (unsigned i = 0; i != NumElts; ++i) { |
| 4706 | ConstantSDNode *C = cast<ConstantSDNode>(N->getOperand(i)); |
| 4707 | const APInt &CInt = C->getAPIntValue(); |
Jay Foad | 40f8f62 | 2010-12-07 08:25:19 +0000 | [diff] [blame] | 4708 | Ops.push_back(DAG.getConstant(CInt.trunc(EltSize), TruncVT)); |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 4709 | } |
| 4710 | return DAG.getNode(ISD::BUILD_VECTOR, N->getDebugLoc(), |
| 4711 | MVT::getVectorVT(TruncVT, NumElts), Ops.data(), NumElts); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4712 | } |
| 4713 | |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 4714 | static bool isAddSubSExt(SDNode *N, SelectionDAG &DAG) { |
| 4715 | unsigned Opcode = N->getOpcode(); |
| 4716 | if (Opcode == ISD::ADD || Opcode == ISD::SUB) { |
| 4717 | SDNode *N0 = N->getOperand(0).getNode(); |
| 4718 | SDNode *N1 = N->getOperand(1).getNode(); |
| 4719 | return N0->hasOneUse() && N1->hasOneUse() && |
| 4720 | isSignExtended(N0, DAG) && isSignExtended(N1, DAG); |
| 4721 | } |
| 4722 | return false; |
| 4723 | } |
| 4724 | |
| 4725 | static bool isAddSubZExt(SDNode *N, SelectionDAG &DAG) { |
| 4726 | unsigned Opcode = N->getOpcode(); |
| 4727 | if (Opcode == ISD::ADD || Opcode == ISD::SUB) { |
| 4728 | SDNode *N0 = N->getOperand(0).getNode(); |
| 4729 | SDNode *N1 = N->getOperand(1).getNode(); |
| 4730 | return N0->hasOneUse() && N1->hasOneUse() && |
| 4731 | isZeroExtended(N0, DAG) && isZeroExtended(N1, DAG); |
| 4732 | } |
| 4733 | return false; |
| 4734 | } |
| 4735 | |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4736 | static SDValue LowerMUL(SDValue Op, SelectionDAG &DAG) { |
| 4737 | // Multiplications are only custom-lowered for 128-bit vectors so that |
| 4738 | // VMULL can be detected. Otherwise v2i64 multiplications are not legal. |
| 4739 | EVT VT = Op.getValueType(); |
| 4740 | assert(VT.is128BitVector() && "unexpected type for custom-lowering ISD::MUL"); |
| 4741 | SDNode *N0 = Op.getOperand(0).getNode(); |
| 4742 | SDNode *N1 = Op.getOperand(1).getNode(); |
| 4743 | unsigned NewOpc = 0; |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 4744 | bool isMLA = false; |
| 4745 | bool isN0SExt = isSignExtended(N0, DAG); |
| 4746 | bool isN1SExt = isSignExtended(N1, DAG); |
| 4747 | if (isN0SExt && isN1SExt) |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4748 | NewOpc = ARMISD::VMULLs; |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 4749 | else { |
| 4750 | bool isN0ZExt = isZeroExtended(N0, DAG); |
| 4751 | bool isN1ZExt = isZeroExtended(N1, DAG); |
| 4752 | if (isN0ZExt && isN1ZExt) |
| 4753 | NewOpc = ARMISD::VMULLu; |
| 4754 | else if (isN1SExt || isN1ZExt) { |
| 4755 | // Look for (s/zext A + s/zext B) * (s/zext C). We want to turn these |
| 4756 | // into (s/zext A * s/zext C) + (s/zext B * s/zext C) |
| 4757 | if (isN1SExt && isAddSubSExt(N0, DAG)) { |
| 4758 | NewOpc = ARMISD::VMULLs; |
| 4759 | isMLA = true; |
| 4760 | } else if (isN1ZExt && isAddSubZExt(N0, DAG)) { |
| 4761 | NewOpc = ARMISD::VMULLu; |
| 4762 | isMLA = true; |
| 4763 | } else if (isN0ZExt && isAddSubZExt(N1, DAG)) { |
| 4764 | std::swap(N0, N1); |
| 4765 | NewOpc = ARMISD::VMULLu; |
| 4766 | isMLA = true; |
| 4767 | } |
| 4768 | } |
| 4769 | |
| 4770 | if (!NewOpc) { |
| 4771 | if (VT == MVT::v2i64) |
| 4772 | // Fall through to expand this. It is not legal. |
| 4773 | return SDValue(); |
| 4774 | else |
| 4775 | // Other vector multiplications are legal. |
| 4776 | return Op; |
| 4777 | } |
| 4778 | } |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4779 | |
| 4780 | // Legalize to a VMULL instruction. |
| 4781 | DebugLoc DL = Op.getDebugLoc(); |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 4782 | SDValue Op0; |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4783 | SDValue Op1 = SkipExtension(N1, DAG); |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 4784 | if (!isMLA) { |
| 4785 | Op0 = SkipExtension(N0, DAG); |
| 4786 | assert(Op0.getValueType().is64BitVector() && |
| 4787 | Op1.getValueType().is64BitVector() && |
| 4788 | "unexpected types for extended operands to VMULL"); |
| 4789 | return DAG.getNode(NewOpc, DL, VT, Op0, Op1); |
| 4790 | } |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4791 | |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 4792 | // Optimizing (zext A + zext B) * C, to (VMULL A, C) + (VMULL B, C) during |
| 4793 | // isel lowering to take advantage of no-stall back to back vmul + vmla. |
| 4794 | // vmull q0, d4, d6 |
| 4795 | // vmlal q0, d5, d6 |
| 4796 | // is faster than |
| 4797 | // vaddl q0, d4, d5 |
| 4798 | // vmovl q1, d6 |
| 4799 | // vmul q0, q0, q1 |
| 4800 | SDValue N00 = SkipExtension(N0->getOperand(0).getNode(), DAG); |
| 4801 | SDValue N01 = SkipExtension(N0->getOperand(1).getNode(), DAG); |
| 4802 | EVT Op1VT = Op1.getValueType(); |
| 4803 | return DAG.getNode(N0->getOpcode(), DL, VT, |
| 4804 | DAG.getNode(NewOpc, DL, VT, |
| 4805 | DAG.getNode(ISD::BITCAST, DL, Op1VT, N00), Op1), |
| 4806 | DAG.getNode(NewOpc, DL, VT, |
| 4807 | DAG.getNode(ISD::BITCAST, DL, Op1VT, N01), Op1)); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4808 | } |
| 4809 | |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4810 | static SDValue |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4811 | LowerSDIV_v4i8(SDValue X, SDValue Y, DebugLoc dl, SelectionDAG &DAG) { |
| 4812 | // Convert to float |
| 4813 | // float4 xf = vcvt_f32_s32(vmovl_s16(a.lo)); |
| 4814 | // float4 yf = vcvt_f32_s32(vmovl_s16(b.lo)); |
| 4815 | X = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, X); |
| 4816 | Y = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, Y); |
| 4817 | X = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, X); |
| 4818 | Y = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, Y); |
| 4819 | // Get reciprocal estimate. |
| 4820 | // float4 recip = vrecpeq_f32(yf); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4821 | Y = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4822 | DAG.getConstant(Intrinsic::arm_neon_vrecpe, MVT::i32), Y); |
| 4823 | // Because char has a smaller range than uchar, we can actually get away |
| 4824 | // without any newton steps. This requires that we use a weird bias |
| 4825 | // of 0xb000, however (again, this has been exhaustively tested). |
| 4826 | // float4 result = as_float4(as_int4(xf*recip) + 0xb000); |
| 4827 | X = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, X, Y); |
| 4828 | X = DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, X); |
| 4829 | Y = DAG.getConstant(0xb000, MVT::i32); |
| 4830 | Y = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, Y, Y, Y, Y); |
| 4831 | X = DAG.getNode(ISD::ADD, dl, MVT::v4i32, X, Y); |
| 4832 | X = DAG.getNode(ISD::BITCAST, dl, MVT::v4f32, X); |
| 4833 | // Convert back to short. |
| 4834 | X = DAG.getNode(ISD::FP_TO_SINT, dl, MVT::v4i32, X); |
| 4835 | X = DAG.getNode(ISD::TRUNCATE, dl, MVT::v4i16, X); |
| 4836 | return X; |
| 4837 | } |
| 4838 | |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4839 | static SDValue |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4840 | LowerSDIV_v4i16(SDValue N0, SDValue N1, DebugLoc dl, SelectionDAG &DAG) { |
| 4841 | SDValue N2; |
| 4842 | // Convert to float. |
| 4843 | // float4 yf = vcvt_f32_s32(vmovl_s16(y)); |
| 4844 | // float4 xf = vcvt_f32_s32(vmovl_s16(x)); |
| 4845 | N0 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, N0); |
| 4846 | N1 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, N1); |
| 4847 | N0 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N0); |
| 4848 | N1 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4849 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4850 | // Use reciprocal estimate and one refinement step. |
| 4851 | // float4 recip = vrecpeq_f32(yf); |
| 4852 | // recip *= vrecpsq_f32(yf, recip); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4853 | N2 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4854 | DAG.getConstant(Intrinsic::arm_neon_vrecpe, MVT::i32), N1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4855 | N1 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4856 | DAG.getConstant(Intrinsic::arm_neon_vrecps, MVT::i32), |
| 4857 | N1, N2); |
| 4858 | N2 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N1, N2); |
| 4859 | // Because short has a smaller range than ushort, we can actually get away |
| 4860 | // with only a single newton step. This requires that we use a weird bias |
| 4861 | // of 89, however (again, this has been exhaustively tested). |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 4862 | // float4 result = as_float4(as_int4(xf*recip) + 0x89); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4863 | N0 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N0, N2); |
| 4864 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, N0); |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 4865 | N1 = DAG.getConstant(0x89, MVT::i32); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4866 | N1 = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, N1, N1, N1, N1); |
| 4867 | N0 = DAG.getNode(ISD::ADD, dl, MVT::v4i32, N0, N1); |
| 4868 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4f32, N0); |
| 4869 | // Convert back to integer and return. |
| 4870 | // return vmovn_s32(vcvt_s32_f32(result)); |
| 4871 | N0 = DAG.getNode(ISD::FP_TO_SINT, dl, MVT::v4i32, N0); |
| 4872 | N0 = DAG.getNode(ISD::TRUNCATE, dl, MVT::v4i16, N0); |
| 4873 | return N0; |
| 4874 | } |
| 4875 | |
| 4876 | static SDValue LowerSDIV(SDValue Op, SelectionDAG &DAG) { |
| 4877 | EVT VT = Op.getValueType(); |
| 4878 | assert((VT == MVT::v4i16 || VT == MVT::v8i8) && |
| 4879 | "unexpected type for custom-lowering ISD::SDIV"); |
| 4880 | |
| 4881 | DebugLoc dl = Op.getDebugLoc(); |
| 4882 | SDValue N0 = Op.getOperand(0); |
| 4883 | SDValue N1 = Op.getOperand(1); |
| 4884 | SDValue N2, N3; |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4885 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4886 | if (VT == MVT::v8i8) { |
| 4887 | N0 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v8i16, N0); |
| 4888 | N1 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v8i16, N1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4889 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4890 | N2 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| 4891 | DAG.getIntPtrConstant(4)); |
| 4892 | N3 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4893 | DAG.getIntPtrConstant(4)); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4894 | N0 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| 4895 | DAG.getIntPtrConstant(0)); |
| 4896 | N1 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
| 4897 | DAG.getIntPtrConstant(0)); |
| 4898 | |
| 4899 | N0 = LowerSDIV_v4i8(N0, N1, dl, DAG); // v4i16 |
| 4900 | N2 = LowerSDIV_v4i8(N2, N3, dl, DAG); // v4i16 |
| 4901 | |
| 4902 | N0 = DAG.getNode(ISD::CONCAT_VECTORS, dl, MVT::v8i16, N0, N2); |
| 4903 | N0 = LowerCONCAT_VECTORS(N0, DAG); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4904 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4905 | N0 = DAG.getNode(ISD::TRUNCATE, dl, MVT::v8i8, N0); |
| 4906 | return N0; |
| 4907 | } |
| 4908 | return LowerSDIV_v4i16(N0, N1, dl, DAG); |
| 4909 | } |
| 4910 | |
| 4911 | static SDValue LowerUDIV(SDValue Op, SelectionDAG &DAG) { |
| 4912 | EVT VT = Op.getValueType(); |
| 4913 | assert((VT == MVT::v4i16 || VT == MVT::v8i8) && |
| 4914 | "unexpected type for custom-lowering ISD::UDIV"); |
| 4915 | |
| 4916 | DebugLoc dl = Op.getDebugLoc(); |
| 4917 | SDValue N0 = Op.getOperand(0); |
| 4918 | SDValue N1 = Op.getOperand(1); |
| 4919 | SDValue N2, N3; |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4920 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4921 | if (VT == MVT::v8i8) { |
| 4922 | N0 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v8i16, N0); |
| 4923 | N1 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v8i16, N1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4924 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4925 | N2 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| 4926 | DAG.getIntPtrConstant(4)); |
| 4927 | N3 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4928 | DAG.getIntPtrConstant(4)); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4929 | N0 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| 4930 | DAG.getIntPtrConstant(0)); |
| 4931 | N1 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
| 4932 | DAG.getIntPtrConstant(0)); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4933 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4934 | N0 = LowerSDIV_v4i16(N0, N1, dl, DAG); // v4i16 |
| 4935 | N2 = LowerSDIV_v4i16(N2, N3, dl, DAG); // v4i16 |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4936 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4937 | N0 = DAG.getNode(ISD::CONCAT_VECTORS, dl, MVT::v8i16, N0, N2); |
| 4938 | N0 = LowerCONCAT_VECTORS(N0, DAG); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4939 | |
| 4940 | N0 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v8i8, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4941 | DAG.getConstant(Intrinsic::arm_neon_vqmovnsu, MVT::i32), |
| 4942 | N0); |
| 4943 | return N0; |
| 4944 | } |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4945 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4946 | // v4i16 sdiv ... Convert to float. |
| 4947 | // float4 yf = vcvt_f32_s32(vmovl_u16(y)); |
| 4948 | // float4 xf = vcvt_f32_s32(vmovl_u16(x)); |
| 4949 | N0 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v4i32, N0); |
| 4950 | N1 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v4i32, N1); |
| 4951 | N0 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N0); |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 4952 | SDValue BN1 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N1); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4953 | |
| 4954 | // Use reciprocal estimate and two refinement steps. |
| 4955 | // float4 recip = vrecpeq_f32(yf); |
| 4956 | // recip *= vrecpsq_f32(yf, recip); |
| 4957 | // recip *= vrecpsq_f32(yf, recip); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4958 | N2 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 4959 | DAG.getConstant(Intrinsic::arm_neon_vrecpe, MVT::i32), BN1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4960 | N1 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4961 | DAG.getConstant(Intrinsic::arm_neon_vrecps, MVT::i32), |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 4962 | BN1, N2); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4963 | N2 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N1, N2); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4964 | N1 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4965 | DAG.getConstant(Intrinsic::arm_neon_vrecps, MVT::i32), |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 4966 | BN1, N2); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4967 | N2 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N1, N2); |
| 4968 | // Simply multiplying by the reciprocal estimate can leave us a few ulps |
| 4969 | // too low, so we add 2 ulps (exhaustive testing shows that this is enough, |
| 4970 | // 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] | 4971 | // float4 result = as_float4(as_int4(xf*recip) + 2); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4972 | N0 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N0, N2); |
| 4973 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, N0); |
| 4974 | N1 = DAG.getConstant(2, MVT::i32); |
| 4975 | N1 = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, N1, N1, N1, N1); |
| 4976 | N0 = DAG.getNode(ISD::ADD, dl, MVT::v4i32, N0, N1); |
| 4977 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4f32, N0); |
| 4978 | // Convert back to integer and return. |
| 4979 | // return vmovn_u32(vcvt_s32_f32(result)); |
| 4980 | N0 = DAG.getNode(ISD::FP_TO_SINT, dl, MVT::v4i32, N0); |
| 4981 | N0 = DAG.getNode(ISD::TRUNCATE, dl, MVT::v4i16, N0); |
| 4982 | return N0; |
| 4983 | } |
| 4984 | |
Evan Cheng | 342e316 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 4985 | static SDValue LowerADDC_ADDE_SUBC_SUBE(SDValue Op, SelectionDAG &DAG) { |
| 4986 | EVT VT = Op.getNode()->getValueType(0); |
| 4987 | SDVTList VTs = DAG.getVTList(VT, MVT::i32); |
| 4988 | |
| 4989 | unsigned Opc; |
| 4990 | bool ExtraOp = false; |
| 4991 | switch (Op.getOpcode()) { |
Craig Topper | bc21981 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 4992 | default: llvm_unreachable("Invalid code"); |
Evan Cheng | 342e316 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 4993 | case ISD::ADDC: Opc = ARMISD::ADDC; break; |
| 4994 | case ISD::ADDE: Opc = ARMISD::ADDE; ExtraOp = true; break; |
| 4995 | case ISD::SUBC: Opc = ARMISD::SUBC; break; |
| 4996 | case ISD::SUBE: Opc = ARMISD::SUBE; ExtraOp = true; break; |
| 4997 | } |
| 4998 | |
| 4999 | if (!ExtraOp) |
| 5000 | return DAG.getNode(Opc, Op->getDebugLoc(), VTs, Op.getOperand(0), |
| 5001 | Op.getOperand(1)); |
| 5002 | return DAG.getNode(Opc, Op->getDebugLoc(), VTs, Op.getOperand(0), |
| 5003 | Op.getOperand(1), Op.getOperand(2)); |
| 5004 | } |
| 5005 | |
Eli Friedman | 74bf18c | 2011-09-15 22:26:18 +0000 | [diff] [blame] | 5006 | static SDValue LowerAtomicLoadStore(SDValue Op, SelectionDAG &DAG) { |
Eli Friedman | 7cc1566 | 2011-09-15 22:18:49 +0000 | [diff] [blame] | 5007 | // Monotonic load/store is legal for all targets |
| 5008 | if (cast<AtomicSDNode>(Op)->getOrdering() <= Monotonic) |
| 5009 | return Op; |
| 5010 | |
| 5011 | // Aquire/Release load/store is not legal for targets without a |
| 5012 | // dmb or equivalent available. |
| 5013 | return SDValue(); |
| 5014 | } |
| 5015 | |
| 5016 | |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5017 | static void |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5018 | ReplaceATOMIC_OP_64(SDNode *Node, SmallVectorImpl<SDValue>& Results, |
| 5019 | SelectionDAG &DAG, unsigned NewOp) { |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5020 | DebugLoc dl = Node->getDebugLoc(); |
Duncan Sands | 17001ce | 2011-10-18 12:44:00 +0000 | [diff] [blame] | 5021 | assert (Node->getValueType(0) == MVT::i64 && |
| 5022 | "Only know how to expand i64 atomics"); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5023 | |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5024 | SmallVector<SDValue, 6> Ops; |
| 5025 | Ops.push_back(Node->getOperand(0)); // Chain |
| 5026 | Ops.push_back(Node->getOperand(1)); // Ptr |
| 5027 | // Low part of Val1 |
| 5028 | Ops.push_back(DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, |
| 5029 | Node->getOperand(2), DAG.getIntPtrConstant(0))); |
| 5030 | // High part of Val1 |
| 5031 | Ops.push_back(DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, |
| 5032 | Node->getOperand(2), DAG.getIntPtrConstant(1))); |
Andrew Trick | 3af7a67 | 2011-09-20 03:06:13 +0000 | [diff] [blame] | 5033 | if (NewOp == ARMISD::ATOMCMPXCHG64_DAG) { |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5034 | // High part of Val1 |
| 5035 | Ops.push_back(DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, |
| 5036 | Node->getOperand(3), DAG.getIntPtrConstant(0))); |
| 5037 | // High part of Val2 |
| 5038 | Ops.push_back(DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, |
| 5039 | Node->getOperand(3), DAG.getIntPtrConstant(1))); |
| 5040 | } |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5041 | SDVTList Tys = DAG.getVTList(MVT::i32, MVT::i32, MVT::Other); |
| 5042 | SDValue Result = |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5043 | DAG.getMemIntrinsicNode(NewOp, dl, Tys, Ops.data(), Ops.size(), MVT::i64, |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5044 | cast<MemSDNode>(Node)->getMemOperand()); |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5045 | SDValue OpsF[] = { Result.getValue(0), Result.getValue(1) }; |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5046 | Results.push_back(DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, OpsF, 2)); |
| 5047 | Results.push_back(Result.getValue(2)); |
| 5048 | } |
| 5049 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 5050 | SDValue ARMTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5051 | switch (Op.getOpcode()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 5052 | default: llvm_unreachable("Don't know how to custom lower this!"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5053 | case ISD::ConstantPool: return LowerConstantPool(Op, DAG); |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 5054 | case ISD::BlockAddress: return LowerBlockAddress(Op, DAG); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 5055 | case ISD::GlobalAddress: |
| 5056 | return Subtarget->isTargetDarwin() ? LowerGlobalAddressDarwin(Op, DAG) : |
| 5057 | LowerGlobalAddressELF(Op, DAG); |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 5058 | case ISD::GlobalTLSAddress: return LowerGlobalTLSAddress(Op, DAG); |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 5059 | case ISD::SELECT: return LowerSELECT(Op, DAG); |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 5060 | case ISD::SELECT_CC: return LowerSELECT_CC(Op, DAG); |
| 5061 | case ISD::BR_CC: return LowerBR_CC(Op, DAG); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5062 | case ISD::BR_JT: return LowerBR_JT(Op, DAG); |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 5063 | case ISD::VASTART: return LowerVASTART(Op, DAG); |
Jim Grosbach | 7c03dbd | 2009-12-14 21:24:16 +0000 | [diff] [blame] | 5064 | case ISD::MEMBARRIER: return LowerMEMBARRIER(Op, DAG, Subtarget); |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 5065 | case ISD::ATOMIC_FENCE: return LowerATOMIC_FENCE(Op, DAG, Subtarget); |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 5066 | case ISD::PREFETCH: return LowerPREFETCH(Op, DAG, Subtarget); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 5067 | case ISD::SINT_TO_FP: |
| 5068 | case ISD::UINT_TO_FP: return LowerINT_TO_FP(Op, DAG); |
| 5069 | case ISD::FP_TO_SINT: |
| 5070 | case ISD::FP_TO_UINT: return LowerFP_TO_INT(Op, DAG); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5071 | case ISD::FCOPYSIGN: return LowerFCOPYSIGN(Op, DAG); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 5072 | case ISD::RETURNADDR: return LowerRETURNADDR(Op, DAG); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 5073 | case ISD::FRAMEADDR: return LowerFRAMEADDR(Op, DAG); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 5074 | case ISD::GLOBAL_OFFSET_TABLE: return LowerGLOBAL_OFFSET_TABLE(Op, DAG); |
Jim Grosbach | 23ff7cf | 2010-05-26 20:22:18 +0000 | [diff] [blame] | 5075 | case ISD::EH_SJLJ_SETJMP: return LowerEH_SJLJ_SETJMP(Op, DAG); |
Jim Grosbach | 5eb1951 | 2010-05-22 01:06:18 +0000 | [diff] [blame] | 5076 | case ISD::EH_SJLJ_LONGJMP: return LowerEH_SJLJ_LONGJMP(Op, DAG); |
Jim Grosbach | a87ded2 | 2010-02-08 23:22:00 +0000 | [diff] [blame] | 5077 | case ISD::INTRINSIC_WO_CHAIN: return LowerINTRINSIC_WO_CHAIN(Op, DAG, |
| 5078 | Subtarget); |
Evan Cheng | 21a6179 | 2011-03-14 18:02:30 +0000 | [diff] [blame] | 5079 | case ISD::BITCAST: return ExpandBITCAST(Op.getNode(), DAG); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5080 | case ISD::SHL: |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 5081 | case ISD::SRL: |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5082 | case ISD::SRA: return LowerShift(Op.getNode(), DAG, Subtarget); |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 5083 | case ISD::SHL_PARTS: return LowerShiftLeftParts(Op, DAG); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 5084 | case ISD::SRL_PARTS: |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 5085 | case ISD::SRA_PARTS: return LowerShiftRightParts(Op, DAG); |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 5086 | case ISD::CTTZ: return LowerCTTZ(Op.getNode(), DAG, Subtarget); |
Duncan Sands | 28b77e9 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 5087 | case ISD::SETCC: return LowerVSETCC(Op, DAG); |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 5088 | case ISD::BUILD_VECTOR: return LowerBUILD_VECTOR(Op, DAG, Subtarget); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5089 | case ISD::VECTOR_SHUFFLE: return LowerVECTOR_SHUFFLE(Op, DAG); |
Eli Friedman | 5c89cb8 | 2011-10-24 23:08:52 +0000 | [diff] [blame] | 5090 | case ISD::INSERT_VECTOR_ELT: return LowerINSERT_VECTOR_ELT(Op, DAG); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5091 | case ISD::EXTRACT_VECTOR_ELT: return LowerEXTRACT_VECTOR_ELT(Op, DAG); |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 5092 | case ISD::CONCAT_VECTORS: return LowerCONCAT_VECTORS(Op, DAG); |
Bob Wilson | b31a11b | 2010-08-20 04:54:02 +0000 | [diff] [blame] | 5093 | case ISD::FLT_ROUNDS_: return LowerFLT_ROUNDS_(Op, DAG); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 5094 | case ISD::MUL: return LowerMUL(Op, DAG); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5095 | case ISD::SDIV: return LowerSDIV(Op, DAG); |
| 5096 | case ISD::UDIV: return LowerUDIV(Op, DAG); |
Evan Cheng | 342e316 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 5097 | case ISD::ADDC: |
| 5098 | case ISD::ADDE: |
| 5099 | case ISD::SUBC: |
| 5100 | case ISD::SUBE: return LowerADDC_ADDE_SUBC_SUBE(Op, DAG); |
Eli Friedman | 7cc1566 | 2011-09-15 22:18:49 +0000 | [diff] [blame] | 5101 | case ISD::ATOMIC_LOAD: |
Eli Friedman | 74bf18c | 2011-09-15 22:26:18 +0000 | [diff] [blame] | 5102 | case ISD::ATOMIC_STORE: return LowerAtomicLoadStore(Op, DAG); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5103 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5104 | } |
| 5105 | |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 5106 | /// ReplaceNodeResults - Replace the results of node with an illegal result |
| 5107 | /// type with new values built out of custom code. |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 5108 | void ARMTargetLowering::ReplaceNodeResults(SDNode *N, |
| 5109 | SmallVectorImpl<SDValue>&Results, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 5110 | SelectionDAG &DAG) const { |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 5111 | SDValue Res; |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 5112 | switch (N->getOpcode()) { |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 5113 | default: |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 5114 | llvm_unreachable("Don't know how to custom expand this!"); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5115 | case ISD::BITCAST: |
| 5116 | Res = ExpandBITCAST(N, DAG); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 5117 | break; |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 5118 | case ISD::SRL: |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 5119 | case ISD::SRA: |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 5120 | Res = Expand64BitShift(N, DAG, Subtarget); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 5121 | break; |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5122 | case ISD::ATOMIC_LOAD_ADD: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5123 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMADD64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5124 | return; |
| 5125 | case ISD::ATOMIC_LOAD_AND: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5126 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMAND64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5127 | return; |
| 5128 | case ISD::ATOMIC_LOAD_NAND: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5129 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMNAND64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5130 | return; |
| 5131 | case ISD::ATOMIC_LOAD_OR: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5132 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMOR64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5133 | return; |
| 5134 | case ISD::ATOMIC_LOAD_SUB: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5135 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMSUB64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5136 | return; |
| 5137 | case ISD::ATOMIC_LOAD_XOR: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5138 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMXOR64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5139 | return; |
| 5140 | case ISD::ATOMIC_SWAP: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5141 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMSWAP64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5142 | return; |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5143 | case ISD::ATOMIC_CMP_SWAP: |
| 5144 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMCMPXCHG64_DAG); |
| 5145 | return; |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 5146 | } |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 5147 | if (Res.getNode()) |
| 5148 | Results.push_back(Res); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 5149 | } |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 5150 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5151 | //===----------------------------------------------------------------------===// |
| 5152 | // ARM Scheduler Hooks |
| 5153 | //===----------------------------------------------------------------------===// |
| 5154 | |
| 5155 | MachineBasicBlock * |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 5156 | ARMTargetLowering::EmitAtomicCmpSwap(MachineInstr *MI, |
| 5157 | MachineBasicBlock *BB, |
| 5158 | unsigned Size) const { |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5159 | unsigned dest = MI->getOperand(0).getReg(); |
| 5160 | unsigned ptr = MI->getOperand(1).getReg(); |
| 5161 | unsigned oldval = MI->getOperand(2).getReg(); |
| 5162 | unsigned newval = MI->getOperand(3).getReg(); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5163 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 5164 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5165 | bool isThumb2 = Subtarget->isThumb2(); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5166 | |
Cameron Zwarich | 7d336c0 | 2011-05-18 02:20:07 +0000 | [diff] [blame] | 5167 | MachineRegisterInfo &MRI = BB->getParent()->getRegInfo(); |
| 5168 | unsigned scratch = |
Cameron Zwarich | 141ec63 | 2011-05-18 02:29:50 +0000 | [diff] [blame] | 5169 | MRI.createVirtualRegister(isThumb2 ? ARM::rGPRRegisterClass |
Cameron Zwarich | 7d336c0 | 2011-05-18 02:20:07 +0000 | [diff] [blame] | 5170 | : ARM::GPRRegisterClass); |
| 5171 | |
| 5172 | if (isThumb2) { |
Cameron Zwarich | 141ec63 | 2011-05-18 02:29:50 +0000 | [diff] [blame] | 5173 | MRI.constrainRegClass(dest, ARM::rGPRRegisterClass); |
| 5174 | MRI.constrainRegClass(oldval, ARM::rGPRRegisterClass); |
| 5175 | MRI.constrainRegClass(newval, ARM::rGPRRegisterClass); |
Cameron Zwarich | 7d336c0 | 2011-05-18 02:20:07 +0000 | [diff] [blame] | 5176 | } |
| 5177 | |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5178 | unsigned ldrOpc, strOpc; |
| 5179 | switch (Size) { |
| 5180 | default: llvm_unreachable("unsupported size for AtomicCmpSwap!"); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5181 | case 1: |
| 5182 | ldrOpc = isThumb2 ? ARM::t2LDREXB : ARM::LDREXB; |
Evan Cheng | aa26102 | 2011-02-07 18:50:47 +0000 | [diff] [blame] | 5183 | strOpc = isThumb2 ? ARM::t2STREXB : ARM::STREXB; |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5184 | break; |
| 5185 | case 2: |
| 5186 | ldrOpc = isThumb2 ? ARM::t2LDREXH : ARM::LDREXH; |
| 5187 | strOpc = isThumb2 ? ARM::t2STREXH : ARM::STREXH; |
| 5188 | break; |
| 5189 | case 4: |
| 5190 | ldrOpc = isThumb2 ? ARM::t2LDREX : ARM::LDREX; |
| 5191 | strOpc = isThumb2 ? ARM::t2STREX : ARM::STREX; |
| 5192 | break; |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5193 | } |
| 5194 | |
| 5195 | MachineFunction *MF = BB->getParent(); |
| 5196 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 5197 | MachineFunction::iterator It = BB; |
| 5198 | ++It; // insert the new blocks after the current block |
| 5199 | |
| 5200 | MachineBasicBlock *loop1MBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5201 | MachineBasicBlock *loop2MBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5202 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5203 | MF->insert(It, loop1MBB); |
| 5204 | MF->insert(It, loop2MBB); |
| 5205 | MF->insert(It, exitMBB); |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 5206 | |
| 5207 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 5208 | exitMBB->splice(exitMBB->begin(), BB, |
| 5209 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 5210 | BB->end()); |
| 5211 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5212 | |
| 5213 | // thisMBB: |
| 5214 | // ... |
| 5215 | // fallthrough --> loop1MBB |
| 5216 | BB->addSuccessor(loop1MBB); |
| 5217 | |
| 5218 | // loop1MBB: |
| 5219 | // ldrex dest, [ptr] |
| 5220 | // cmp dest, oldval |
| 5221 | // bne exitMBB |
| 5222 | BB = loop1MBB; |
Jim Grosbach | b6aed50 | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 5223 | MachineInstrBuilder MIB = BuildMI(BB, dl, TII->get(ldrOpc), dest).addReg(ptr); |
| 5224 | if (ldrOpc == ARM::t2LDREX) |
| 5225 | MIB.addImm(0); |
| 5226 | AddDefaultPred(MIB); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5227 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5228 | .addReg(dest).addReg(oldval)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5229 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 5230 | .addMBB(exitMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5231 | BB->addSuccessor(loop2MBB); |
| 5232 | BB->addSuccessor(exitMBB); |
| 5233 | |
| 5234 | // loop2MBB: |
| 5235 | // strex scratch, newval, [ptr] |
| 5236 | // cmp scratch, #0 |
| 5237 | // bne loop1MBB |
| 5238 | BB = loop2MBB; |
Jim Grosbach | b6aed50 | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 5239 | MIB = BuildMI(BB, dl, TII->get(strOpc), scratch).addReg(newval).addReg(ptr); |
| 5240 | if (strOpc == ARM::t2STREX) |
| 5241 | MIB.addImm(0); |
| 5242 | AddDefaultPred(MIB); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5243 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5244 | .addReg(scratch).addImm(0)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5245 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 5246 | .addMBB(loop1MBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5247 | BB->addSuccessor(loop1MBB); |
| 5248 | BB->addSuccessor(exitMBB); |
| 5249 | |
| 5250 | // exitMBB: |
| 5251 | // ... |
| 5252 | BB = exitMBB; |
Jim Grosbach | 5efaed3 | 2010-01-15 00:18:34 +0000 | [diff] [blame] | 5253 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 5254 | MI->eraseFromParent(); // The instruction is gone now. |
Jim Grosbach | 5efaed3 | 2010-01-15 00:18:34 +0000 | [diff] [blame] | 5255 | |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5256 | return BB; |
| 5257 | } |
| 5258 | |
| 5259 | MachineBasicBlock * |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 5260 | ARMTargetLowering::EmitAtomicBinary(MachineInstr *MI, MachineBasicBlock *BB, |
| 5261 | unsigned Size, unsigned BinOpcode) const { |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5262 | // This also handles ATOMIC_SWAP, indicated by BinOpcode==0. |
| 5263 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 5264 | |
| 5265 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
Jim Grosbach | 867bbbf | 2010-01-15 00:22:18 +0000 | [diff] [blame] | 5266 | MachineFunction *MF = BB->getParent(); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5267 | MachineFunction::iterator It = BB; |
| 5268 | ++It; |
| 5269 | |
| 5270 | unsigned dest = MI->getOperand(0).getReg(); |
| 5271 | unsigned ptr = MI->getOperand(1).getReg(); |
| 5272 | unsigned incr = MI->getOperand(2).getReg(); |
| 5273 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5274 | bool isThumb2 = Subtarget->isThumb2(); |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 5275 | |
| 5276 | MachineRegisterInfo &MRI = BB->getParent()->getRegInfo(); |
| 5277 | if (isThumb2) { |
| 5278 | MRI.constrainRegClass(dest, ARM::rGPRRegisterClass); |
| 5279 | MRI.constrainRegClass(ptr, ARM::rGPRRegisterClass); |
| 5280 | } |
| 5281 | |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5282 | unsigned ldrOpc, strOpc; |
| 5283 | switch (Size) { |
| 5284 | default: llvm_unreachable("unsupported size for AtomicCmpSwap!"); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5285 | case 1: |
| 5286 | ldrOpc = isThumb2 ? ARM::t2LDREXB : ARM::LDREXB; |
Jakob Stoklund Olesen | 15913c9 | 2010-01-13 19:54:39 +0000 | [diff] [blame] | 5287 | strOpc = isThumb2 ? ARM::t2STREXB : ARM::STREXB; |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5288 | break; |
| 5289 | case 2: |
| 5290 | ldrOpc = isThumb2 ? ARM::t2LDREXH : ARM::LDREXH; |
| 5291 | strOpc = isThumb2 ? ARM::t2STREXH : ARM::STREXH; |
| 5292 | break; |
| 5293 | case 4: |
| 5294 | ldrOpc = isThumb2 ? ARM::t2LDREX : ARM::LDREX; |
| 5295 | strOpc = isThumb2 ? ARM::t2STREX : ARM::STREX; |
| 5296 | break; |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5297 | } |
| 5298 | |
Jim Grosbach | 867bbbf | 2010-01-15 00:22:18 +0000 | [diff] [blame] | 5299 | MachineBasicBlock *loopMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5300 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5301 | MF->insert(It, loopMBB); |
| 5302 | MF->insert(It, exitMBB); |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 5303 | |
| 5304 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 5305 | exitMBB->splice(exitMBB->begin(), BB, |
| 5306 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 5307 | BB->end()); |
| 5308 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5309 | |
Craig Topper | 44d2382 | 2012-02-22 05:59:10 +0000 | [diff] [blame] | 5310 | const TargetRegisterClass *TRC = |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 5311 | isThumb2 ? ARM::tGPRRegisterClass : ARM::GPRRegisterClass; |
| 5312 | unsigned scratch = MRI.createVirtualRegister(TRC); |
| 5313 | unsigned scratch2 = (!BinOpcode) ? incr : MRI.createVirtualRegister(TRC); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5314 | |
| 5315 | // thisMBB: |
| 5316 | // ... |
| 5317 | // fallthrough --> loopMBB |
| 5318 | BB->addSuccessor(loopMBB); |
| 5319 | |
| 5320 | // loopMBB: |
| 5321 | // ldrex dest, ptr |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5322 | // <binop> scratch2, dest, incr |
| 5323 | // strex scratch, scratch2, ptr |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5324 | // cmp scratch, #0 |
| 5325 | // bne- loopMBB |
| 5326 | // fallthrough --> exitMBB |
| 5327 | BB = loopMBB; |
Jim Grosbach | b6aed50 | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 5328 | MachineInstrBuilder MIB = BuildMI(BB, dl, TII->get(ldrOpc), dest).addReg(ptr); |
| 5329 | if (ldrOpc == ARM::t2LDREX) |
| 5330 | MIB.addImm(0); |
| 5331 | AddDefaultPred(MIB); |
Jim Grosbach | c67b556 | 2009-12-15 00:12:35 +0000 | [diff] [blame] | 5332 | if (BinOpcode) { |
| 5333 | // operand order needs to go the other way for NAND |
| 5334 | if (BinOpcode == ARM::BICrr || BinOpcode == ARM::t2BICrr) |
| 5335 | AddDefaultPred(BuildMI(BB, dl, TII->get(BinOpcode), scratch2). |
| 5336 | addReg(incr).addReg(dest)).addReg(0); |
| 5337 | else |
| 5338 | AddDefaultPred(BuildMI(BB, dl, TII->get(BinOpcode), scratch2). |
| 5339 | addReg(dest).addReg(incr)).addReg(0); |
| 5340 | } |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5341 | |
Jim Grosbach | b6aed50 | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 5342 | MIB = BuildMI(BB, dl, TII->get(strOpc), scratch).addReg(scratch2).addReg(ptr); |
| 5343 | if (strOpc == ARM::t2STREX) |
| 5344 | MIB.addImm(0); |
| 5345 | AddDefaultPred(MIB); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5346 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5347 | .addReg(scratch).addImm(0)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5348 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 5349 | .addMBB(loopMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5350 | |
| 5351 | BB->addSuccessor(loopMBB); |
| 5352 | BB->addSuccessor(exitMBB); |
| 5353 | |
| 5354 | // exitMBB: |
| 5355 | // ... |
| 5356 | BB = exitMBB; |
Evan Cheng | 102ebf1 | 2009-12-21 19:53:39 +0000 | [diff] [blame] | 5357 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 5358 | MI->eraseFromParent(); // The instruction is gone now. |
Evan Cheng | 102ebf1 | 2009-12-21 19:53:39 +0000 | [diff] [blame] | 5359 | |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5360 | return BB; |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 5361 | } |
| 5362 | |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5363 | MachineBasicBlock * |
| 5364 | ARMTargetLowering::EmitAtomicBinaryMinMax(MachineInstr *MI, |
| 5365 | MachineBasicBlock *BB, |
| 5366 | unsigned Size, |
| 5367 | bool signExtend, |
| 5368 | ARMCC::CondCodes Cond) const { |
| 5369 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 5370 | |
| 5371 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 5372 | MachineFunction *MF = BB->getParent(); |
| 5373 | MachineFunction::iterator It = BB; |
| 5374 | ++It; |
| 5375 | |
| 5376 | unsigned dest = MI->getOperand(0).getReg(); |
| 5377 | unsigned ptr = MI->getOperand(1).getReg(); |
| 5378 | unsigned incr = MI->getOperand(2).getReg(); |
| 5379 | unsigned oldval = dest; |
| 5380 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5381 | bool isThumb2 = Subtarget->isThumb2(); |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 5382 | |
| 5383 | MachineRegisterInfo &MRI = BB->getParent()->getRegInfo(); |
| 5384 | if (isThumb2) { |
| 5385 | MRI.constrainRegClass(dest, ARM::rGPRRegisterClass); |
| 5386 | MRI.constrainRegClass(ptr, ARM::rGPRRegisterClass); |
| 5387 | } |
| 5388 | |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5389 | unsigned ldrOpc, strOpc, extendOpc; |
| 5390 | switch (Size) { |
| 5391 | default: llvm_unreachable("unsupported size for AtomicCmpSwap!"); |
| 5392 | case 1: |
| 5393 | ldrOpc = isThumb2 ? ARM::t2LDREXB : ARM::LDREXB; |
| 5394 | strOpc = isThumb2 ? ARM::t2STREXB : ARM::STREXB; |
Jim Grosbach | c5a8c86 | 2011-07-27 16:47:19 +0000 | [diff] [blame] | 5395 | extendOpc = isThumb2 ? ARM::t2SXTB : ARM::SXTB; |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5396 | break; |
| 5397 | case 2: |
| 5398 | ldrOpc = isThumb2 ? ARM::t2LDREXH : ARM::LDREXH; |
| 5399 | strOpc = isThumb2 ? ARM::t2STREXH : ARM::STREXH; |
Jim Grosbach | c5a8c86 | 2011-07-27 16:47:19 +0000 | [diff] [blame] | 5400 | extendOpc = isThumb2 ? ARM::t2SXTH : ARM::SXTH; |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5401 | break; |
| 5402 | case 4: |
| 5403 | ldrOpc = isThumb2 ? ARM::t2LDREX : ARM::LDREX; |
| 5404 | strOpc = isThumb2 ? ARM::t2STREX : ARM::STREX; |
| 5405 | extendOpc = 0; |
| 5406 | break; |
| 5407 | } |
| 5408 | |
| 5409 | MachineBasicBlock *loopMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5410 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5411 | MF->insert(It, loopMBB); |
| 5412 | MF->insert(It, exitMBB); |
| 5413 | |
| 5414 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 5415 | exitMBB->splice(exitMBB->begin(), BB, |
| 5416 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 5417 | BB->end()); |
| 5418 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
| 5419 | |
Craig Topper | 44d2382 | 2012-02-22 05:59:10 +0000 | [diff] [blame] | 5420 | const TargetRegisterClass *TRC = |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 5421 | isThumb2 ? ARM::tGPRRegisterClass : ARM::GPRRegisterClass; |
| 5422 | unsigned scratch = MRI.createVirtualRegister(TRC); |
| 5423 | unsigned scratch2 = MRI.createVirtualRegister(TRC); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5424 | |
| 5425 | // thisMBB: |
| 5426 | // ... |
| 5427 | // fallthrough --> loopMBB |
| 5428 | BB->addSuccessor(loopMBB); |
| 5429 | |
| 5430 | // loopMBB: |
| 5431 | // ldrex dest, ptr |
| 5432 | // (sign extend dest, if required) |
| 5433 | // cmp dest, incr |
| 5434 | // cmov.cond scratch2, dest, incr |
| 5435 | // strex scratch, scratch2, ptr |
| 5436 | // cmp scratch, #0 |
| 5437 | // bne- loopMBB |
| 5438 | // fallthrough --> exitMBB |
| 5439 | BB = loopMBB; |
Jim Grosbach | b6aed50 | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 5440 | MachineInstrBuilder MIB = BuildMI(BB, dl, TII->get(ldrOpc), dest).addReg(ptr); |
| 5441 | if (ldrOpc == ARM::t2LDREX) |
| 5442 | MIB.addImm(0); |
| 5443 | AddDefaultPred(MIB); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5444 | |
| 5445 | // Sign extend the value, if necessary. |
| 5446 | if (signExtend && extendOpc) { |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 5447 | oldval = MRI.createVirtualRegister(ARM::GPRRegisterClass); |
Jim Grosbach | c5a8c86 | 2011-07-27 16:47:19 +0000 | [diff] [blame] | 5448 | AddDefaultPred(BuildMI(BB, dl, TII->get(extendOpc), oldval) |
| 5449 | .addReg(dest) |
| 5450 | .addImm(0)); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5451 | } |
| 5452 | |
| 5453 | // Build compare and cmov instructions. |
| 5454 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
| 5455 | .addReg(oldval).addReg(incr)); |
| 5456 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2MOVCCr : ARM::MOVCCr), scratch2) |
| 5457 | .addReg(oldval).addReg(incr).addImm(Cond).addReg(ARM::CPSR); |
| 5458 | |
Jim Grosbach | b6aed50 | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 5459 | MIB = BuildMI(BB, dl, TII->get(strOpc), scratch).addReg(scratch2).addReg(ptr); |
| 5460 | if (strOpc == ARM::t2STREX) |
| 5461 | MIB.addImm(0); |
| 5462 | AddDefaultPred(MIB); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5463 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 5464 | .addReg(scratch).addImm(0)); |
| 5465 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 5466 | .addMBB(loopMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
| 5467 | |
| 5468 | BB->addSuccessor(loopMBB); |
| 5469 | BB->addSuccessor(exitMBB); |
| 5470 | |
| 5471 | // exitMBB: |
| 5472 | // ... |
| 5473 | BB = exitMBB; |
| 5474 | |
| 5475 | MI->eraseFromParent(); // The instruction is gone now. |
| 5476 | |
| 5477 | return BB; |
| 5478 | } |
| 5479 | |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5480 | MachineBasicBlock * |
| 5481 | ARMTargetLowering::EmitAtomicBinary64(MachineInstr *MI, MachineBasicBlock *BB, |
| 5482 | unsigned Op1, unsigned Op2, |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5483 | bool NeedsCarry, bool IsCmpxchg) const { |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5484 | // This also handles ATOMIC_SWAP, indicated by Op1==0. |
| 5485 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 5486 | |
| 5487 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 5488 | MachineFunction *MF = BB->getParent(); |
| 5489 | MachineFunction::iterator It = BB; |
| 5490 | ++It; |
| 5491 | |
| 5492 | unsigned destlo = MI->getOperand(0).getReg(); |
| 5493 | unsigned desthi = MI->getOperand(1).getReg(); |
| 5494 | unsigned ptr = MI->getOperand(2).getReg(); |
| 5495 | unsigned vallo = MI->getOperand(3).getReg(); |
| 5496 | unsigned valhi = MI->getOperand(4).getReg(); |
| 5497 | DebugLoc dl = MI->getDebugLoc(); |
| 5498 | bool isThumb2 = Subtarget->isThumb2(); |
| 5499 | |
| 5500 | MachineRegisterInfo &MRI = BB->getParent()->getRegInfo(); |
| 5501 | if (isThumb2) { |
| 5502 | MRI.constrainRegClass(destlo, ARM::rGPRRegisterClass); |
| 5503 | MRI.constrainRegClass(desthi, ARM::rGPRRegisterClass); |
| 5504 | MRI.constrainRegClass(ptr, ARM::rGPRRegisterClass); |
| 5505 | } |
| 5506 | |
| 5507 | unsigned ldrOpc = isThumb2 ? ARM::t2LDREXD : ARM::LDREXD; |
| 5508 | unsigned strOpc = isThumb2 ? ARM::t2STREXD : ARM::STREXD; |
| 5509 | |
| 5510 | MachineBasicBlock *loopMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
Eli Friedman | 7df496d | 2011-09-01 22:27:41 +0000 | [diff] [blame] | 5511 | MachineBasicBlock *contBB = 0, *cont2BB = 0; |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5512 | if (IsCmpxchg) { |
| 5513 | contBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5514 | cont2BB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5515 | } |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5516 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5517 | MF->insert(It, loopMBB); |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5518 | if (IsCmpxchg) { |
| 5519 | MF->insert(It, contBB); |
| 5520 | MF->insert(It, cont2BB); |
| 5521 | } |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5522 | MF->insert(It, exitMBB); |
| 5523 | |
| 5524 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 5525 | exitMBB->splice(exitMBB->begin(), BB, |
| 5526 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 5527 | BB->end()); |
| 5528 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
| 5529 | |
Craig Topper | 44d2382 | 2012-02-22 05:59:10 +0000 | [diff] [blame] | 5530 | const TargetRegisterClass *TRC = |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5531 | isThumb2 ? ARM::tGPRRegisterClass : ARM::GPRRegisterClass; |
| 5532 | unsigned storesuccess = MRI.createVirtualRegister(TRC); |
| 5533 | |
| 5534 | // thisMBB: |
| 5535 | // ... |
| 5536 | // fallthrough --> loopMBB |
| 5537 | BB->addSuccessor(loopMBB); |
| 5538 | |
| 5539 | // loopMBB: |
| 5540 | // ldrexd r2, r3, ptr |
| 5541 | // <binopa> r0, r2, incr |
| 5542 | // <binopb> r1, r3, incr |
| 5543 | // strexd storesuccess, r0, r1, ptr |
| 5544 | // cmp storesuccess, #0 |
| 5545 | // bne- loopMBB |
| 5546 | // fallthrough --> exitMBB |
| 5547 | // |
| 5548 | // Note that the registers are explicitly specified because there is not any |
| 5549 | // way to force the register allocator to allocate a register pair. |
| 5550 | // |
Andrew Trick | 3af7a67 | 2011-09-20 03:06:13 +0000 | [diff] [blame] | 5551 | // FIXME: The hardcoded registers are not necessary for Thumb2, but we |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5552 | // need to properly enforce the restriction that the two output registers |
| 5553 | // for ldrexd must be different. |
| 5554 | BB = loopMBB; |
| 5555 | // Load |
| 5556 | AddDefaultPred(BuildMI(BB, dl, TII->get(ldrOpc)) |
| 5557 | .addReg(ARM::R2, RegState::Define) |
| 5558 | .addReg(ARM::R3, RegState::Define).addReg(ptr)); |
| 5559 | // Copy r2/r3 into dest. (This copy will normally be coalesced.) |
| 5560 | BuildMI(BB, dl, TII->get(TargetOpcode::COPY), destlo).addReg(ARM::R2); |
| 5561 | BuildMI(BB, dl, TII->get(TargetOpcode::COPY), desthi).addReg(ARM::R3); |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5562 | |
| 5563 | if (IsCmpxchg) { |
| 5564 | // Add early exit |
| 5565 | for (unsigned i = 0; i < 2; i++) { |
| 5566 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPrr : |
| 5567 | ARM::CMPrr)) |
| 5568 | .addReg(i == 0 ? destlo : desthi) |
| 5569 | .addReg(i == 0 ? vallo : valhi)); |
| 5570 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 5571 | .addMBB(exitMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
| 5572 | BB->addSuccessor(exitMBB); |
| 5573 | BB->addSuccessor(i == 0 ? contBB : cont2BB); |
| 5574 | BB = (i == 0 ? contBB : cont2BB); |
| 5575 | } |
| 5576 | |
| 5577 | // Copy to physregs for strexd |
| 5578 | unsigned setlo = MI->getOperand(5).getReg(); |
| 5579 | unsigned sethi = MI->getOperand(6).getReg(); |
| 5580 | BuildMI(BB, dl, TII->get(TargetOpcode::COPY), ARM::R0).addReg(setlo); |
| 5581 | BuildMI(BB, dl, TII->get(TargetOpcode::COPY), ARM::R1).addReg(sethi); |
| 5582 | } else if (Op1) { |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5583 | // Perform binary operation |
| 5584 | AddDefaultPred(BuildMI(BB, dl, TII->get(Op1), ARM::R0) |
| 5585 | .addReg(destlo).addReg(vallo)) |
| 5586 | .addReg(NeedsCarry ? ARM::CPSR : 0, getDefRegState(NeedsCarry)); |
| 5587 | AddDefaultPred(BuildMI(BB, dl, TII->get(Op2), ARM::R1) |
| 5588 | .addReg(desthi).addReg(valhi)).addReg(0); |
| 5589 | } else { |
| 5590 | // Copy to physregs for strexd |
| 5591 | BuildMI(BB, dl, TII->get(TargetOpcode::COPY), ARM::R0).addReg(vallo); |
| 5592 | BuildMI(BB, dl, TII->get(TargetOpcode::COPY), ARM::R1).addReg(valhi); |
| 5593 | } |
| 5594 | |
| 5595 | // Store |
| 5596 | AddDefaultPred(BuildMI(BB, dl, TII->get(strOpc), storesuccess) |
| 5597 | .addReg(ARM::R0).addReg(ARM::R1).addReg(ptr)); |
| 5598 | // Cmp+jump |
| 5599 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 5600 | .addReg(storesuccess).addImm(0)); |
| 5601 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 5602 | .addMBB(loopMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
| 5603 | |
| 5604 | BB->addSuccessor(loopMBB); |
| 5605 | BB->addSuccessor(exitMBB); |
| 5606 | |
| 5607 | // exitMBB: |
| 5608 | // ... |
| 5609 | BB = exitMBB; |
| 5610 | |
| 5611 | MI->eraseFromParent(); // The instruction is gone now. |
| 5612 | |
| 5613 | return BB; |
| 5614 | } |
| 5615 | |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 5616 | /// SetupEntryBlockForSjLj - Insert code into the entry block that creates and |
| 5617 | /// registers the function context. |
| 5618 | void ARMTargetLowering:: |
| 5619 | SetupEntryBlockForSjLj(MachineInstr *MI, MachineBasicBlock *MBB, |
| 5620 | MachineBasicBlock *DispatchBB, int FI) const { |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 5621 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 5622 | DebugLoc dl = MI->getDebugLoc(); |
| 5623 | MachineFunction *MF = MBB->getParent(); |
| 5624 | MachineRegisterInfo *MRI = &MF->getRegInfo(); |
| 5625 | MachineConstantPool *MCP = MF->getConstantPool(); |
| 5626 | ARMFunctionInfo *AFI = MF->getInfo<ARMFunctionInfo>(); |
| 5627 | const Function *F = MF->getFunction(); |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 5628 | |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 5629 | bool isThumb = Subtarget->isThumb(); |
Bill Wendling | ff4216a | 2011-10-03 22:44:15 +0000 | [diff] [blame] | 5630 | bool isThumb2 = Subtarget->isThumb2(); |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 5631 | |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 5632 | unsigned PCLabelId = AFI->createPICLabelUId(); |
Bill Wendling | ff4216a | 2011-10-03 22:44:15 +0000 | [diff] [blame] | 5633 | unsigned PCAdj = (isThumb || isThumb2) ? 4 : 8; |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 5634 | ARMConstantPoolValue *CPV = |
| 5635 | ARMConstantPoolMBB::Create(F->getContext(), DispatchBB, PCLabelId, PCAdj); |
| 5636 | unsigned CPI = MCP->getConstantPoolIndex(CPV, 4); |
| 5637 | |
| 5638 | const TargetRegisterClass *TRC = |
| 5639 | isThumb ? ARM::tGPRRegisterClass : ARM::GPRRegisterClass; |
| 5640 | |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 5641 | // Grab constant pool and fixed stack memory operands. |
| 5642 | MachineMemOperand *CPMMO = |
| 5643 | MF->getMachineMemOperand(MachinePointerInfo::getConstantPool(), |
| 5644 | MachineMemOperand::MOLoad, 4, 4); |
| 5645 | |
| 5646 | MachineMemOperand *FIMMOSt = |
| 5647 | MF->getMachineMemOperand(MachinePointerInfo::getFixedStack(FI), |
| 5648 | MachineMemOperand::MOStore, 4, 4); |
| 5649 | |
| 5650 | // Load the address of the dispatch MBB into the jump buffer. |
| 5651 | if (isThumb2) { |
| 5652 | // Incoming value: jbuf |
| 5653 | // ldr.n r5, LCPI1_1 |
| 5654 | // orr r5, r5, #1 |
| 5655 | // add r5, pc |
| 5656 | // str r5, [$jbuf, #+4] ; &jbuf[1] |
| 5657 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 5658 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::t2LDRpci), NewVReg1) |
| 5659 | .addConstantPoolIndex(CPI) |
| 5660 | .addMemOperand(CPMMO)); |
| 5661 | // Set the low bit because of thumb mode. |
| 5662 | unsigned NewVReg2 = MRI->createVirtualRegister(TRC); |
| 5663 | AddDefaultCC( |
| 5664 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::t2ORRri), NewVReg2) |
| 5665 | .addReg(NewVReg1, RegState::Kill) |
| 5666 | .addImm(0x01))); |
| 5667 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
| 5668 | BuildMI(*MBB, MI, dl, TII->get(ARM::tPICADD), NewVReg3) |
| 5669 | .addReg(NewVReg2, RegState::Kill) |
| 5670 | .addImm(PCLabelId); |
| 5671 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::t2STRi12)) |
| 5672 | .addReg(NewVReg3, RegState::Kill) |
| 5673 | .addFrameIndex(FI) |
| 5674 | .addImm(36) // &jbuf[1] :: pc |
| 5675 | .addMemOperand(FIMMOSt)); |
| 5676 | } else if (isThumb) { |
| 5677 | // Incoming value: jbuf |
| 5678 | // ldr.n r1, LCPI1_4 |
| 5679 | // add r1, pc |
| 5680 | // mov r2, #1 |
| 5681 | // orrs r1, r2 |
| 5682 | // add r2, $jbuf, #+4 ; &jbuf[1] |
| 5683 | // str r1, [r2] |
| 5684 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 5685 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tLDRpci), NewVReg1) |
| 5686 | .addConstantPoolIndex(CPI) |
| 5687 | .addMemOperand(CPMMO)); |
| 5688 | unsigned NewVReg2 = MRI->createVirtualRegister(TRC); |
| 5689 | BuildMI(*MBB, MI, dl, TII->get(ARM::tPICADD), NewVReg2) |
| 5690 | .addReg(NewVReg1, RegState::Kill) |
| 5691 | .addImm(PCLabelId); |
| 5692 | // Set the low bit because of thumb mode. |
| 5693 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
| 5694 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tMOVi8), NewVReg3) |
| 5695 | .addReg(ARM::CPSR, RegState::Define) |
| 5696 | .addImm(1)); |
| 5697 | unsigned NewVReg4 = MRI->createVirtualRegister(TRC); |
| 5698 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tORR), NewVReg4) |
| 5699 | .addReg(ARM::CPSR, RegState::Define) |
| 5700 | .addReg(NewVReg2, RegState::Kill) |
| 5701 | .addReg(NewVReg3, RegState::Kill)); |
| 5702 | unsigned NewVReg5 = MRI->createVirtualRegister(TRC); |
| 5703 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tADDrSPi), NewVReg5) |
| 5704 | .addFrameIndex(FI) |
| 5705 | .addImm(36)); // &jbuf[1] :: pc |
| 5706 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tSTRi)) |
| 5707 | .addReg(NewVReg4, RegState::Kill) |
| 5708 | .addReg(NewVReg5, RegState::Kill) |
| 5709 | .addImm(0) |
| 5710 | .addMemOperand(FIMMOSt)); |
| 5711 | } else { |
| 5712 | // Incoming value: jbuf |
| 5713 | // ldr r1, LCPI1_1 |
| 5714 | // add r1, pc, r1 |
| 5715 | // str r1, [$jbuf, #+4] ; &jbuf[1] |
| 5716 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 5717 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::LDRi12), NewVReg1) |
| 5718 | .addConstantPoolIndex(CPI) |
| 5719 | .addImm(0) |
| 5720 | .addMemOperand(CPMMO)); |
| 5721 | unsigned NewVReg2 = MRI->createVirtualRegister(TRC); |
| 5722 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::PICADD), NewVReg2) |
| 5723 | .addReg(NewVReg1, RegState::Kill) |
| 5724 | .addImm(PCLabelId)); |
| 5725 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::STRi12)) |
| 5726 | .addReg(NewVReg2, RegState::Kill) |
| 5727 | .addFrameIndex(FI) |
| 5728 | .addImm(36) // &jbuf[1] :: pc |
| 5729 | .addMemOperand(FIMMOSt)); |
| 5730 | } |
| 5731 | } |
| 5732 | |
| 5733 | MachineBasicBlock *ARMTargetLowering:: |
| 5734 | EmitSjLjDispatchBlock(MachineInstr *MI, MachineBasicBlock *MBB) const { |
| 5735 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 5736 | DebugLoc dl = MI->getDebugLoc(); |
| 5737 | MachineFunction *MF = MBB->getParent(); |
| 5738 | MachineRegisterInfo *MRI = &MF->getRegInfo(); |
| 5739 | ARMFunctionInfo *AFI = MF->getInfo<ARMFunctionInfo>(); |
| 5740 | MachineFrameInfo *MFI = MF->getFrameInfo(); |
| 5741 | int FI = MFI->getFunctionContextIndex(); |
| 5742 | |
| 5743 | const TargetRegisterClass *TRC = |
| 5744 | Subtarget->isThumb() ? ARM::tGPRRegisterClass : ARM::GPRRegisterClass; |
| 5745 | |
Bill Wendling | 04f15b4 | 2011-10-06 21:29:56 +0000 | [diff] [blame] | 5746 | // Get a mapping of the call site numbers to all of the landing pads they're |
| 5747 | // associated with. |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 5748 | DenseMap<unsigned, SmallVector<MachineBasicBlock*, 2> > CallSiteNumToLPad; |
| 5749 | unsigned MaxCSNum = 0; |
| 5750 | MachineModuleInfo &MMI = MF->getMMI(); |
| 5751 | for (MachineFunction::iterator BB = MF->begin(), E = MF->end(); BB != E; ++BB) { |
| 5752 | if (!BB->isLandingPad()) continue; |
| 5753 | |
| 5754 | // FIXME: We should assert that the EH_LABEL is the first MI in the landing |
| 5755 | // pad. |
| 5756 | for (MachineBasicBlock::iterator |
| 5757 | II = BB->begin(), IE = BB->end(); II != IE; ++II) { |
| 5758 | if (!II->isEHLabel()) continue; |
| 5759 | |
| 5760 | MCSymbol *Sym = II->getOperand(0).getMCSymbol(); |
Bill Wendling | 5cbef19 | 2011-10-05 23:28:57 +0000 | [diff] [blame] | 5761 | if (!MMI.hasCallSiteLandingPad(Sym)) continue; |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 5762 | |
Bill Wendling | 5cbef19 | 2011-10-05 23:28:57 +0000 | [diff] [blame] | 5763 | SmallVectorImpl<unsigned> &CallSiteIdxs = MMI.getCallSiteLandingPad(Sym); |
| 5764 | for (SmallVectorImpl<unsigned>::iterator |
| 5765 | CSI = CallSiteIdxs.begin(), CSE = CallSiteIdxs.end(); |
| 5766 | CSI != CSE; ++CSI) { |
| 5767 | CallSiteNumToLPad[*CSI].push_back(BB); |
| 5768 | MaxCSNum = std::max(MaxCSNum, *CSI); |
| 5769 | } |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 5770 | break; |
| 5771 | } |
| 5772 | } |
| 5773 | |
| 5774 | // Get an ordered list of the machine basic blocks for the jump table. |
| 5775 | std::vector<MachineBasicBlock*> LPadList; |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 5776 | SmallPtrSet<MachineBasicBlock*, 64> InvokeBBs; |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 5777 | LPadList.reserve(CallSiteNumToLPad.size()); |
| 5778 | for (unsigned I = 1; I <= MaxCSNum; ++I) { |
| 5779 | SmallVectorImpl<MachineBasicBlock*> &MBBList = CallSiteNumToLPad[I]; |
| 5780 | for (SmallVectorImpl<MachineBasicBlock*>::iterator |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 5781 | II = MBBList.begin(), IE = MBBList.end(); II != IE; ++II) { |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 5782 | LPadList.push_back(*II); |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 5783 | InvokeBBs.insert((*II)->pred_begin(), (*II)->pred_end()); |
| 5784 | } |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 5785 | } |
| 5786 | |
Bill Wendling | 5cbef19 | 2011-10-05 23:28:57 +0000 | [diff] [blame] | 5787 | assert(!LPadList.empty() && |
| 5788 | "No landing pad destinations for the dispatch jump table!"); |
| 5789 | |
Bill Wendling | 04f15b4 | 2011-10-06 21:29:56 +0000 | [diff] [blame] | 5790 | // Create the jump table and associated information. |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 5791 | MachineJumpTableInfo *JTI = |
| 5792 | MF->getOrCreateJumpTableInfo(MachineJumpTableInfo::EK_Inline); |
| 5793 | unsigned MJTI = JTI->createJumpTableIndex(LPadList); |
| 5794 | unsigned UId = AFI->createJumpTableUId(); |
| 5795 | |
Bill Wendling | 04f15b4 | 2011-10-06 21:29:56 +0000 | [diff] [blame] | 5796 | // Create the MBBs for the dispatch code. |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 5797 | |
| 5798 | // Shove the dispatch's address into the return slot in the function context. |
| 5799 | MachineBasicBlock *DispatchBB = MF->CreateMachineBasicBlock(); |
| 5800 | DispatchBB->setIsLandingPad(); |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 5801 | |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 5802 | MachineBasicBlock *TrapBB = MF->CreateMachineBasicBlock(); |
Bill Wendling | 083a8eb | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 5803 | BuildMI(TrapBB, dl, TII->get(Subtarget->isThumb() ? ARM::tTRAP : ARM::TRAP)); |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 5804 | DispatchBB->addSuccessor(TrapBB); |
| 5805 | |
| 5806 | MachineBasicBlock *DispContBB = MF->CreateMachineBasicBlock(); |
| 5807 | DispatchBB->addSuccessor(DispContBB); |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 5808 | |
Bill Wendling | a48ed4f | 2011-10-17 21:32:56 +0000 | [diff] [blame] | 5809 | // Insert and MBBs. |
Bill Wendling | 930193c | 2011-10-06 00:53:33 +0000 | [diff] [blame] | 5810 | MF->insert(MF->end(), DispatchBB); |
| 5811 | MF->insert(MF->end(), DispContBB); |
| 5812 | MF->insert(MF->end(), TrapBB); |
Bill Wendling | 930193c | 2011-10-06 00:53:33 +0000 | [diff] [blame] | 5813 | |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 5814 | // Insert code into the entry block that creates and registers the function |
| 5815 | // context. |
| 5816 | SetupEntryBlockForSjLj(MI, MBB, DispatchBB, FI); |
| 5817 | |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 5818 | MachineMemOperand *FIMMOLd = |
Bill Wendling | 04f15b4 | 2011-10-06 21:29:56 +0000 | [diff] [blame] | 5819 | MF->getMachineMemOperand(MachinePointerInfo::getFixedStack(FI), |
Bill Wendling | 083a8eb | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 5820 | MachineMemOperand::MOLoad | |
| 5821 | MachineMemOperand::MOVolatile, 4, 4); |
Bill Wendling | 930193c | 2011-10-06 00:53:33 +0000 | [diff] [blame] | 5822 | |
Bob Wilson | f4aea8f | 2011-12-22 23:39:48 +0000 | [diff] [blame] | 5823 | if (AFI->isThumb1OnlyFunction()) |
| 5824 | BuildMI(DispatchBB, dl, TII->get(ARM::tInt_eh_sjlj_dispatchsetup)); |
| 5825 | else if (!Subtarget->hasVFP2()) |
| 5826 | BuildMI(DispatchBB, dl, TII->get(ARM::Int_eh_sjlj_dispatchsetup_nofp)); |
| 5827 | else |
| 5828 | BuildMI(DispatchBB, dl, TII->get(ARM::Int_eh_sjlj_dispatchsetup)); |
Bob Wilson | eaab6ef | 2011-11-16 07:11:57 +0000 | [diff] [blame] | 5829 | |
Bill Wendling | 952cb50 | 2011-10-18 22:49:07 +0000 | [diff] [blame] | 5830 | unsigned NumLPads = LPadList.size(); |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 5831 | if (Subtarget->isThumb2()) { |
| 5832 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 5833 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2LDRi12), NewVReg1) |
| 5834 | .addFrameIndex(FI) |
| 5835 | .addImm(4) |
| 5836 | .addMemOperand(FIMMOLd)); |
Bill Wendling | b9fecf4 | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 5837 | |
Bill Wendling | 952cb50 | 2011-10-18 22:49:07 +0000 | [diff] [blame] | 5838 | if (NumLPads < 256) { |
| 5839 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2CMPri)) |
| 5840 | .addReg(NewVReg1) |
| 5841 | .addImm(LPadList.size())); |
| 5842 | } else { |
| 5843 | unsigned VReg1 = MRI->createVirtualRegister(TRC); |
| 5844 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2MOVi16), VReg1) |
Bill Wendling | 15a1a22 | 2011-10-18 23:19:55 +0000 | [diff] [blame] | 5845 | .addImm(NumLPads & 0xFFFF)); |
| 5846 | |
| 5847 | unsigned VReg2 = VReg1; |
| 5848 | if ((NumLPads & 0xFFFF0000) != 0) { |
| 5849 | VReg2 = MRI->createVirtualRegister(TRC); |
| 5850 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2MOVTi16), VReg2) |
| 5851 | .addReg(VReg1) |
| 5852 | .addImm(NumLPads >> 16)); |
| 5853 | } |
| 5854 | |
Bill Wendling | 952cb50 | 2011-10-18 22:49:07 +0000 | [diff] [blame] | 5855 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2CMPrr)) |
| 5856 | .addReg(NewVReg1) |
| 5857 | .addReg(VReg2)); |
| 5858 | } |
Bill Wendling | b9fecf4 | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 5859 | |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 5860 | BuildMI(DispatchBB, dl, TII->get(ARM::t2Bcc)) |
| 5861 | .addMBB(TrapBB) |
| 5862 | .addImm(ARMCC::HI) |
| 5863 | .addReg(ARM::CPSR); |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 5864 | |
Bill Wendling | b9fecf4 | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 5865 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
| 5866 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::t2LEApcrelJT),NewVReg3) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 5867 | .addJumpTableIndex(MJTI) |
| 5868 | .addImm(UId)); |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 5869 | |
Bill Wendling | b9fecf4 | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 5870 | unsigned NewVReg4 = MRI->createVirtualRegister(TRC); |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 5871 | AddDefaultCC( |
| 5872 | AddDefaultPred( |
Bill Wendling | b9fecf4 | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 5873 | BuildMI(DispContBB, dl, TII->get(ARM::t2ADDrs), NewVReg4) |
| 5874 | .addReg(NewVReg3, RegState::Kill) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 5875 | .addReg(NewVReg1) |
| 5876 | .addImm(ARM_AM::getSORegOpc(ARM_AM::lsl, 2)))); |
| 5877 | |
| 5878 | BuildMI(DispContBB, dl, TII->get(ARM::t2BR_JT)) |
Bill Wendling | b9fecf4 | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 5879 | .addReg(NewVReg4, RegState::Kill) |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 5880 | .addReg(NewVReg1) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 5881 | .addJumpTableIndex(MJTI) |
| 5882 | .addImm(UId); |
| 5883 | } else if (Subtarget->isThumb()) { |
Bill Wendling | 083a8eb | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 5884 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 5885 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::tLDRspi), NewVReg1) |
| 5886 | .addFrameIndex(FI) |
| 5887 | .addImm(1) |
| 5888 | .addMemOperand(FIMMOLd)); |
Bill Wendling | f1083d4 | 2011-10-07 22:08:37 +0000 | [diff] [blame] | 5889 | |
Bill Wendling | a5871dc | 2011-10-18 23:11:05 +0000 | [diff] [blame] | 5890 | if (NumLPads < 256) { |
| 5891 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::tCMPi8)) |
| 5892 | .addReg(NewVReg1) |
| 5893 | .addImm(NumLPads)); |
| 5894 | } else { |
| 5895 | MachineConstantPool *ConstantPool = MF->getConstantPool(); |
Bill Wendling | 922ad78 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 5896 | Type *Int32Ty = Type::getInt32Ty(MF->getFunction()->getContext()); |
| 5897 | const Constant *C = ConstantInt::get(Int32Ty, NumLPads); |
| 5898 | |
| 5899 | // MachineConstantPool wants an explicit alignment. |
| 5900 | unsigned Align = getTargetData()->getPrefTypeAlignment(Int32Ty); |
| 5901 | if (Align == 0) |
| 5902 | Align = getTargetData()->getTypeAllocSize(C->getType()); |
| 5903 | unsigned Idx = ConstantPool->getConstantPoolIndex(C, Align); |
Bill Wendling | a5871dc | 2011-10-18 23:11:05 +0000 | [diff] [blame] | 5904 | |
| 5905 | unsigned VReg1 = MRI->createVirtualRegister(TRC); |
| 5906 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::tLDRpci)) |
| 5907 | .addReg(VReg1, RegState::Define) |
| 5908 | .addConstantPoolIndex(Idx)); |
| 5909 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::tCMPr)) |
| 5910 | .addReg(NewVReg1) |
| 5911 | .addReg(VReg1)); |
| 5912 | } |
| 5913 | |
Bill Wendling | 083a8eb | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 5914 | BuildMI(DispatchBB, dl, TII->get(ARM::tBcc)) |
| 5915 | .addMBB(TrapBB) |
| 5916 | .addImm(ARMCC::HI) |
| 5917 | .addReg(ARM::CPSR); |
| 5918 | |
| 5919 | unsigned NewVReg2 = MRI->createVirtualRegister(TRC); |
| 5920 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tLSLri), NewVReg2) |
| 5921 | .addReg(ARM::CPSR, RegState::Define) |
| 5922 | .addReg(NewVReg1) |
| 5923 | .addImm(2)); |
| 5924 | |
| 5925 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
Bill Wendling | 217f0e9 | 2011-10-06 23:41:14 +0000 | [diff] [blame] | 5926 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tLEApcrelJT), NewVReg3) |
Bill Wendling | 083a8eb | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 5927 | .addJumpTableIndex(MJTI) |
| 5928 | .addImm(UId)); |
| 5929 | |
| 5930 | unsigned NewVReg4 = MRI->createVirtualRegister(TRC); |
| 5931 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tADDrr), NewVReg4) |
| 5932 | .addReg(ARM::CPSR, RegState::Define) |
| 5933 | .addReg(NewVReg2, RegState::Kill) |
| 5934 | .addReg(NewVReg3)); |
| 5935 | |
| 5936 | MachineMemOperand *JTMMOLd = |
| 5937 | MF->getMachineMemOperand(MachinePointerInfo::getJumpTable(), |
| 5938 | MachineMemOperand::MOLoad, 4, 4); |
| 5939 | |
| 5940 | unsigned NewVReg5 = MRI->createVirtualRegister(TRC); |
| 5941 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tLDRi), NewVReg5) |
| 5942 | .addReg(NewVReg4, RegState::Kill) |
| 5943 | .addImm(0) |
| 5944 | .addMemOperand(JTMMOLd)); |
| 5945 | |
| 5946 | unsigned NewVReg6 = MRI->createVirtualRegister(TRC); |
| 5947 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tADDrr), NewVReg6) |
| 5948 | .addReg(ARM::CPSR, RegState::Define) |
| 5949 | .addReg(NewVReg5, RegState::Kill) |
| 5950 | .addReg(NewVReg3)); |
| 5951 | |
| 5952 | BuildMI(DispContBB, dl, TII->get(ARM::tBR_JTr)) |
| 5953 | .addReg(NewVReg6, RegState::Kill) |
| 5954 | .addJumpTableIndex(MJTI) |
| 5955 | .addImm(UId); |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 5956 | } else { |
| 5957 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 5958 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::LDRi12), NewVReg1) |
| 5959 | .addFrameIndex(FI) |
| 5960 | .addImm(4) |
| 5961 | .addMemOperand(FIMMOLd)); |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 5962 | |
Bill Wendling | 85f3a0a | 2011-10-18 22:52:20 +0000 | [diff] [blame] | 5963 | if (NumLPads < 256) { |
| 5964 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::CMPri)) |
| 5965 | .addReg(NewVReg1) |
| 5966 | .addImm(NumLPads)); |
Bill Wendling | 922ad78 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 5967 | } else if (Subtarget->hasV6T2Ops() && isUInt<16>(NumLPads)) { |
Bill Wendling | 85f3a0a | 2011-10-18 22:52:20 +0000 | [diff] [blame] | 5968 | unsigned VReg1 = MRI->createVirtualRegister(TRC); |
| 5969 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::MOVi16), VReg1) |
Bill Wendling | 15a1a22 | 2011-10-18 23:19:55 +0000 | [diff] [blame] | 5970 | .addImm(NumLPads & 0xFFFF)); |
| 5971 | |
| 5972 | unsigned VReg2 = VReg1; |
| 5973 | if ((NumLPads & 0xFFFF0000) != 0) { |
| 5974 | VReg2 = MRI->createVirtualRegister(TRC); |
| 5975 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::MOVTi16), VReg2) |
| 5976 | .addReg(VReg1) |
| 5977 | .addImm(NumLPads >> 16)); |
| 5978 | } |
| 5979 | |
Bill Wendling | 85f3a0a | 2011-10-18 22:52:20 +0000 | [diff] [blame] | 5980 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::CMPrr)) |
| 5981 | .addReg(NewVReg1) |
| 5982 | .addReg(VReg2)); |
Bill Wendling | 922ad78 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 5983 | } else { |
| 5984 | MachineConstantPool *ConstantPool = MF->getConstantPool(); |
| 5985 | Type *Int32Ty = Type::getInt32Ty(MF->getFunction()->getContext()); |
| 5986 | const Constant *C = ConstantInt::get(Int32Ty, NumLPads); |
| 5987 | |
| 5988 | // MachineConstantPool wants an explicit alignment. |
| 5989 | unsigned Align = getTargetData()->getPrefTypeAlignment(Int32Ty); |
| 5990 | if (Align == 0) |
| 5991 | Align = getTargetData()->getTypeAllocSize(C->getType()); |
| 5992 | unsigned Idx = ConstantPool->getConstantPoolIndex(C, Align); |
| 5993 | |
| 5994 | unsigned VReg1 = MRI->createVirtualRegister(TRC); |
| 5995 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::LDRcp)) |
| 5996 | .addReg(VReg1, RegState::Define) |
Bill Wendling | 767f8be | 2011-10-20 20:37:11 +0000 | [diff] [blame] | 5997 | .addConstantPoolIndex(Idx) |
| 5998 | .addImm(0)); |
Bill Wendling | 922ad78 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 5999 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::CMPrr)) |
| 6000 | .addReg(NewVReg1) |
| 6001 | .addReg(VReg1, RegState::Kill)); |
Bill Wendling | 85f3a0a | 2011-10-18 22:52:20 +0000 | [diff] [blame] | 6002 | } |
| 6003 | |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6004 | BuildMI(DispatchBB, dl, TII->get(ARM::Bcc)) |
| 6005 | .addMBB(TrapBB) |
| 6006 | .addImm(ARMCC::HI) |
| 6007 | .addReg(ARM::CPSR); |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6008 | |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6009 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6010 | AddDefaultCC( |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6011 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::MOVsi), NewVReg3) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6012 | .addReg(NewVReg1) |
| 6013 | .addImm(ARM_AM::getSORegOpc(ARM_AM::lsl, 2)))); |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6014 | unsigned NewVReg4 = MRI->createVirtualRegister(TRC); |
| 6015 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::LEApcrelJT), NewVReg4) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6016 | .addJumpTableIndex(MJTI) |
| 6017 | .addImm(UId)); |
| 6018 | |
| 6019 | MachineMemOperand *JTMMOLd = |
| 6020 | MF->getMachineMemOperand(MachinePointerInfo::getJumpTable(), |
| 6021 | MachineMemOperand::MOLoad, 4, 4); |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6022 | unsigned NewVReg5 = MRI->createVirtualRegister(TRC); |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6023 | AddDefaultPred( |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6024 | BuildMI(DispContBB, dl, TII->get(ARM::LDRrs), NewVReg5) |
| 6025 | .addReg(NewVReg3, RegState::Kill) |
| 6026 | .addReg(NewVReg4) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6027 | .addImm(0) |
| 6028 | .addMemOperand(JTMMOLd)); |
| 6029 | |
| 6030 | BuildMI(DispContBB, dl, TII->get(ARM::BR_JTadd)) |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6031 | .addReg(NewVReg5, RegState::Kill) |
| 6032 | .addReg(NewVReg4) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6033 | .addJumpTableIndex(MJTI) |
| 6034 | .addImm(UId); |
| 6035 | } |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6036 | |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 6037 | // Add the jump table entries as successors to the MBB. |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6038 | MachineBasicBlock *PrevMBB = 0; |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 6039 | for (std::vector<MachineBasicBlock*>::iterator |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6040 | I = LPadList.begin(), E = LPadList.end(); I != E; ++I) { |
| 6041 | MachineBasicBlock *CurMBB = *I; |
| 6042 | if (PrevMBB != CurMBB) |
| 6043 | DispContBB->addSuccessor(CurMBB); |
| 6044 | PrevMBB = CurMBB; |
| 6045 | } |
| 6046 | |
Bill Wendling | 24bb925 | 2011-10-17 05:25:09 +0000 | [diff] [blame] | 6047 | // 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] | 6048 | const ARMBaseInstrInfo *AII = static_cast<const ARMBaseInstrInfo*>(TII); |
| 6049 | const ARMBaseRegisterInfo &RI = AII->getRegisterInfo(); |
| 6050 | const unsigned *SavedRegs = RI.getCalleeSavedRegs(MF); |
Bill Wendling | f7b0207 | 2011-10-18 18:30:49 +0000 | [diff] [blame] | 6051 | SmallVector<MachineBasicBlock*, 64> MBBLPads; |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6052 | for (SmallPtrSet<MachineBasicBlock*, 64>::iterator |
| 6053 | I = InvokeBBs.begin(), E = InvokeBBs.end(); I != E; ++I) { |
| 6054 | MachineBasicBlock *BB = *I; |
Bill Wendling | 969c9ef | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 6055 | |
| 6056 | // Remove the landing pad successor from the invoke block and replace it |
| 6057 | // with the new dispatch block. |
Bill Wendling | de39d86 | 2011-10-26 07:16:18 +0000 | [diff] [blame] | 6058 | SmallVector<MachineBasicBlock*, 4> Successors(BB->succ_begin(), |
| 6059 | BB->succ_end()); |
| 6060 | while (!Successors.empty()) { |
| 6061 | MachineBasicBlock *SMBB = Successors.pop_back_val(); |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6062 | if (SMBB->isLandingPad()) { |
| 6063 | BB->removeSuccessor(SMBB); |
Bill Wendling | f7b0207 | 2011-10-18 18:30:49 +0000 | [diff] [blame] | 6064 | MBBLPads.push_back(SMBB); |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6065 | } |
| 6066 | } |
| 6067 | |
| 6068 | BB->addSuccessor(DispatchBB); |
Bill Wendling | 969c9ef | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 6069 | |
| 6070 | // Find the invoke call and mark all of the callee-saved registers as |
| 6071 | // 'implicit defined' so that they're spilled. This prevents code from |
| 6072 | // moving instructions to before the EH block, where they will never be |
| 6073 | // executed. |
| 6074 | for (MachineBasicBlock::reverse_iterator |
| 6075 | II = BB->rbegin(), IE = BB->rend(); II != IE; ++II) { |
Evan Cheng | 5a96b3d | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 6076 | if (!II->isCall()) continue; |
Bill Wendling | 969c9ef | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 6077 | |
| 6078 | DenseMap<unsigned, bool> DefRegs; |
| 6079 | for (MachineInstr::mop_iterator |
| 6080 | OI = II->operands_begin(), OE = II->operands_end(); |
| 6081 | OI != OE; ++OI) { |
| 6082 | if (!OI->isReg()) continue; |
| 6083 | DefRegs[OI->getReg()] = true; |
| 6084 | } |
| 6085 | |
| 6086 | MachineInstrBuilder MIB(&*II); |
| 6087 | |
Bill Wendling | 5d79859 | 2011-10-14 23:55:44 +0000 | [diff] [blame] | 6088 | for (unsigned i = 0; SavedRegs[i] != 0; ++i) { |
Bill Wendling | b8dcb31 | 2011-10-22 00:29:28 +0000 | [diff] [blame] | 6089 | unsigned Reg = SavedRegs[i]; |
| 6090 | if (Subtarget->isThumb2() && |
| 6091 | !ARM::tGPRRegisterClass->contains(Reg) && |
| 6092 | !ARM::hGPRRegisterClass->contains(Reg)) |
| 6093 | continue; |
| 6094 | else if (Subtarget->isThumb1Only() && |
| 6095 | !ARM::tGPRRegisterClass->contains(Reg)) |
| 6096 | continue; |
| 6097 | else if (!Subtarget->isThumb() && |
| 6098 | !ARM::GPRRegisterClass->contains(Reg)) |
| 6099 | continue; |
| 6100 | if (!DefRegs[Reg]) |
| 6101 | MIB.addReg(Reg, RegState::ImplicitDefine | RegState::Dead); |
Bill Wendling | 5d79859 | 2011-10-14 23:55:44 +0000 | [diff] [blame] | 6102 | } |
Bill Wendling | 969c9ef | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 6103 | |
| 6104 | break; |
| 6105 | } |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6106 | } |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 6107 | |
Bill Wendling | f7b0207 | 2011-10-18 18:30:49 +0000 | [diff] [blame] | 6108 | // Mark all former landing pads as non-landing pads. The dispatch is the only |
| 6109 | // landing pad now. |
| 6110 | for (SmallVectorImpl<MachineBasicBlock*>::iterator |
| 6111 | I = MBBLPads.begin(), E = MBBLPads.end(); I != E; ++I) |
| 6112 | (*I)->setIsLandingPad(false); |
| 6113 | |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 6114 | // The instruction is gone now. |
| 6115 | MI->eraseFromParent(); |
| 6116 | |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 6117 | return MBB; |
| 6118 | } |
| 6119 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 6120 | static |
| 6121 | MachineBasicBlock *OtherSucc(MachineBasicBlock *MBB, MachineBasicBlock *Succ) { |
| 6122 | for (MachineBasicBlock::succ_iterator I = MBB->succ_begin(), |
| 6123 | E = MBB->succ_end(); I != E; ++I) |
| 6124 | if (*I != Succ) |
| 6125 | return *I; |
| 6126 | llvm_unreachable("Expecting a BB with two successors!"); |
| 6127 | } |
| 6128 | |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 6129 | MachineBasicBlock * |
Evan Cheng | ff9b373 | 2008-01-30 18:18:23 +0000 | [diff] [blame] | 6130 | ARMTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI, |
Dan Gohman | af1d8ca | 2010-05-01 00:01:06 +0000 | [diff] [blame] | 6131 | MachineBasicBlock *BB) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6132 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
Dale Johannesen | b672840 | 2009-02-13 02:25:56 +0000 | [diff] [blame] | 6133 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6134 | bool isThumb2 = Subtarget->isThumb2(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6135 | switch (MI->getOpcode()) { |
Andrew Trick | 1c3af77 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 6136 | default: { |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 6137 | MI->dump(); |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 6138 | llvm_unreachable("Unexpected instr type to insert"); |
Andrew Trick | 1c3af77 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 6139 | } |
Jim Grosbach | ee2c2a4 | 2011-09-16 21:55:56 +0000 | [diff] [blame] | 6140 | // The Thumb2 pre-indexed stores have the same MI operands, they just |
| 6141 | // define them differently in the .td files from the isel patterns, so |
| 6142 | // they need pseudos. |
| 6143 | case ARM::t2STR_preidx: |
| 6144 | MI->setDesc(TII->get(ARM::t2STR_PRE)); |
| 6145 | return BB; |
| 6146 | case ARM::t2STRB_preidx: |
| 6147 | MI->setDesc(TII->get(ARM::t2STRB_PRE)); |
| 6148 | return BB; |
| 6149 | case ARM::t2STRH_preidx: |
| 6150 | MI->setDesc(TII->get(ARM::t2STRH_PRE)); |
| 6151 | return BB; |
| 6152 | |
Jim Grosbach | 19dec20 | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 6153 | case ARM::STRi_preidx: |
| 6154 | case ARM::STRBi_preidx: { |
Jim Grosbach | 6cd5716 | 2011-08-09 21:22:41 +0000 | [diff] [blame] | 6155 | unsigned NewOpc = MI->getOpcode() == ARM::STRi_preidx ? |
Jim Grosbach | 19dec20 | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 6156 | ARM::STR_PRE_IMM : ARM::STRB_PRE_IMM; |
| 6157 | // Decode the offset. |
| 6158 | unsigned Offset = MI->getOperand(4).getImm(); |
| 6159 | bool isSub = ARM_AM::getAM2Op(Offset) == ARM_AM::sub; |
| 6160 | Offset = ARM_AM::getAM2Offset(Offset); |
| 6161 | if (isSub) |
| 6162 | Offset = -Offset; |
| 6163 | |
Jim Grosbach | 4dfe220 | 2011-08-12 21:02:34 +0000 | [diff] [blame] | 6164 | MachineMemOperand *MMO = *MI->memoperands_begin(); |
Benjamin Kramer | 2753ae3 | 2011-08-27 17:36:14 +0000 | [diff] [blame] | 6165 | BuildMI(*BB, MI, dl, TII->get(NewOpc)) |
Jim Grosbach | 19dec20 | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 6166 | .addOperand(MI->getOperand(0)) // Rn_wb |
| 6167 | .addOperand(MI->getOperand(1)) // Rt |
| 6168 | .addOperand(MI->getOperand(2)) // Rn |
| 6169 | .addImm(Offset) // offset (skip GPR==zero_reg) |
| 6170 | .addOperand(MI->getOperand(5)) // pred |
Jim Grosbach | 4dfe220 | 2011-08-12 21:02:34 +0000 | [diff] [blame] | 6171 | .addOperand(MI->getOperand(6)) |
| 6172 | .addMemOperand(MMO); |
Jim Grosbach | 19dec20 | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 6173 | MI->eraseFromParent(); |
| 6174 | return BB; |
| 6175 | } |
| 6176 | case ARM::STRr_preidx: |
Jim Grosbach | 7b8f46c | 2011-08-11 21:17:22 +0000 | [diff] [blame] | 6177 | case ARM::STRBr_preidx: |
| 6178 | case ARM::STRH_preidx: { |
| 6179 | unsigned NewOpc; |
| 6180 | switch (MI->getOpcode()) { |
| 6181 | default: llvm_unreachable("unexpected opcode!"); |
| 6182 | case ARM::STRr_preidx: NewOpc = ARM::STR_PRE_REG; break; |
| 6183 | case ARM::STRBr_preidx: NewOpc = ARM::STRB_PRE_REG; break; |
| 6184 | case ARM::STRH_preidx: NewOpc = ARM::STRH_PRE; break; |
| 6185 | } |
Jim Grosbach | 19dec20 | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 6186 | MachineInstrBuilder MIB = BuildMI(*BB, MI, dl, TII->get(NewOpc)); |
| 6187 | for (unsigned i = 0; i < MI->getNumOperands(); ++i) |
| 6188 | MIB.addOperand(MI->getOperand(i)); |
| 6189 | MI->eraseFromParent(); |
| 6190 | return BB; |
| 6191 | } |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6192 | case ARM::ATOMIC_LOAD_ADD_I8: |
| 6193 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr); |
| 6194 | case ARM::ATOMIC_LOAD_ADD_I16: |
| 6195 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr); |
| 6196 | case ARM::ATOMIC_LOAD_ADD_I32: |
| 6197 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 6198 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6199 | case ARM::ATOMIC_LOAD_AND_I8: |
| 6200 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
| 6201 | case ARM::ATOMIC_LOAD_AND_I16: |
| 6202 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
| 6203 | case ARM::ATOMIC_LOAD_AND_I32: |
| 6204 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 6205 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6206 | case ARM::ATOMIC_LOAD_OR_I8: |
| 6207 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
| 6208 | case ARM::ATOMIC_LOAD_OR_I16: |
| 6209 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
| 6210 | case ARM::ATOMIC_LOAD_OR_I32: |
| 6211 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 6212 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6213 | case ARM::ATOMIC_LOAD_XOR_I8: |
| 6214 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
| 6215 | case ARM::ATOMIC_LOAD_XOR_I16: |
| 6216 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
| 6217 | case ARM::ATOMIC_LOAD_XOR_I32: |
| 6218 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 6219 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6220 | case ARM::ATOMIC_LOAD_NAND_I8: |
| 6221 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2BICrr : ARM::BICrr); |
| 6222 | case ARM::ATOMIC_LOAD_NAND_I16: |
| 6223 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2BICrr : ARM::BICrr); |
| 6224 | case ARM::ATOMIC_LOAD_NAND_I32: |
| 6225 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2BICrr : ARM::BICrr); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 6226 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6227 | case ARM::ATOMIC_LOAD_SUB_I8: |
| 6228 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr); |
| 6229 | case ARM::ATOMIC_LOAD_SUB_I16: |
| 6230 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr); |
| 6231 | case ARM::ATOMIC_LOAD_SUB_I32: |
| 6232 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 6233 | |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 6234 | case ARM::ATOMIC_LOAD_MIN_I8: |
| 6235 | return EmitAtomicBinaryMinMax(MI, BB, 1, true, ARMCC::LT); |
| 6236 | case ARM::ATOMIC_LOAD_MIN_I16: |
| 6237 | return EmitAtomicBinaryMinMax(MI, BB, 2, true, ARMCC::LT); |
| 6238 | case ARM::ATOMIC_LOAD_MIN_I32: |
| 6239 | return EmitAtomicBinaryMinMax(MI, BB, 4, true, ARMCC::LT); |
| 6240 | |
| 6241 | case ARM::ATOMIC_LOAD_MAX_I8: |
| 6242 | return EmitAtomicBinaryMinMax(MI, BB, 1, true, ARMCC::GT); |
| 6243 | case ARM::ATOMIC_LOAD_MAX_I16: |
| 6244 | return EmitAtomicBinaryMinMax(MI, BB, 2, true, ARMCC::GT); |
| 6245 | case ARM::ATOMIC_LOAD_MAX_I32: |
| 6246 | return EmitAtomicBinaryMinMax(MI, BB, 4, true, ARMCC::GT); |
| 6247 | |
| 6248 | case ARM::ATOMIC_LOAD_UMIN_I8: |
| 6249 | return EmitAtomicBinaryMinMax(MI, BB, 1, false, ARMCC::LO); |
| 6250 | case ARM::ATOMIC_LOAD_UMIN_I16: |
| 6251 | return EmitAtomicBinaryMinMax(MI, BB, 2, false, ARMCC::LO); |
| 6252 | case ARM::ATOMIC_LOAD_UMIN_I32: |
| 6253 | return EmitAtomicBinaryMinMax(MI, BB, 4, false, ARMCC::LO); |
| 6254 | |
| 6255 | case ARM::ATOMIC_LOAD_UMAX_I8: |
| 6256 | return EmitAtomicBinaryMinMax(MI, BB, 1, false, ARMCC::HI); |
| 6257 | case ARM::ATOMIC_LOAD_UMAX_I16: |
| 6258 | return EmitAtomicBinaryMinMax(MI, BB, 2, false, ARMCC::HI); |
| 6259 | case ARM::ATOMIC_LOAD_UMAX_I32: |
| 6260 | return EmitAtomicBinaryMinMax(MI, BB, 4, false, ARMCC::HI); |
| 6261 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6262 | case ARM::ATOMIC_SWAP_I8: return EmitAtomicBinary(MI, BB, 1, 0); |
| 6263 | case ARM::ATOMIC_SWAP_I16: return EmitAtomicBinary(MI, BB, 2, 0); |
| 6264 | case ARM::ATOMIC_SWAP_I32: return EmitAtomicBinary(MI, BB, 4, 0); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 6265 | |
| 6266 | case ARM::ATOMIC_CMP_SWAP_I8: return EmitAtomicCmpSwap(MI, BB, 1); |
| 6267 | case ARM::ATOMIC_CMP_SWAP_I16: return EmitAtomicCmpSwap(MI, BB, 2); |
| 6268 | case ARM::ATOMIC_CMP_SWAP_I32: return EmitAtomicCmpSwap(MI, BB, 4); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 6269 | |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6270 | |
| 6271 | case ARM::ATOMADD6432: |
| 6272 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr, |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 6273 | isThumb2 ? ARM::t2ADCrr : ARM::ADCrr, |
| 6274 | /*NeedsCarry*/ true); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6275 | case ARM::ATOMSUB6432: |
| 6276 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr, |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 6277 | isThumb2 ? ARM::t2SBCrr : ARM::SBCrr, |
| 6278 | /*NeedsCarry*/ true); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6279 | case ARM::ATOMOR6432: |
| 6280 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr, |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 6281 | isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6282 | case ARM::ATOMXOR6432: |
| 6283 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2EORrr : ARM::EORrr, |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 6284 | isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6285 | case ARM::ATOMAND6432: |
| 6286 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr, |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 6287 | isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6288 | case ARM::ATOMSWAP6432: |
| 6289 | return EmitAtomicBinary64(MI, BB, 0, 0, false); |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 6290 | case ARM::ATOMCMPXCHG6432: |
| 6291 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr, |
| 6292 | isThumb2 ? ARM::t2SBCrr : ARM::SBCrr, |
| 6293 | /*NeedsCarry*/ false, /*IsCmpxchg*/true); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6294 | |
Evan Cheng | 007ea27 | 2009-08-12 05:17:19 +0000 | [diff] [blame] | 6295 | case ARM::tMOVCCr_pseudo: { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6296 | // To "insert" a SELECT_CC instruction, we actually have to insert the |
| 6297 | // diamond control-flow pattern. The incoming instruction knows the |
| 6298 | // destination vreg to set, the condition code register to branch on, the |
| 6299 | // true/false values to select between, and a branch opcode to use. |
| 6300 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 6301 | MachineFunction::iterator It = BB; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6302 | ++It; |
| 6303 | |
| 6304 | // thisMBB: |
| 6305 | // ... |
| 6306 | // TrueVal = ... |
| 6307 | // cmpTY ccX, r1, r2 |
| 6308 | // bCC copy1MBB |
| 6309 | // fallthrough --> copy0MBB |
| 6310 | MachineBasicBlock *thisMBB = BB; |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 6311 | MachineFunction *F = BB->getParent(); |
| 6312 | MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB); |
| 6313 | MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB); |
Dan Gohman | 258c58c | 2010-07-06 15:49:48 +0000 | [diff] [blame] | 6314 | F->insert(It, copy0MBB); |
| 6315 | F->insert(It, sinkMBB); |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 6316 | |
| 6317 | // Transfer the remainder of BB and its successor edges to sinkMBB. |
| 6318 | sinkMBB->splice(sinkMBB->begin(), BB, |
| 6319 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 6320 | BB->end()); |
| 6321 | sinkMBB->transferSuccessorsAndUpdatePHIs(BB); |
| 6322 | |
Dan Gohman | 258c58c | 2010-07-06 15:49:48 +0000 | [diff] [blame] | 6323 | BB->addSuccessor(copy0MBB); |
| 6324 | BB->addSuccessor(sinkMBB); |
Dan Gohman | b81c771 | 2010-07-06 15:18:19 +0000 | [diff] [blame] | 6325 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 6326 | BuildMI(BB, dl, TII->get(ARM::tBcc)).addMBB(sinkMBB) |
| 6327 | .addImm(MI->getOperand(3).getImm()).addReg(MI->getOperand(4).getReg()); |
| 6328 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6329 | // copy0MBB: |
| 6330 | // %FalseValue = ... |
| 6331 | // # fallthrough to sinkMBB |
| 6332 | BB = copy0MBB; |
| 6333 | |
| 6334 | // Update machine-CFG edges |
| 6335 | BB->addSuccessor(sinkMBB); |
| 6336 | |
| 6337 | // sinkMBB: |
| 6338 | // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ] |
| 6339 | // ... |
| 6340 | BB = sinkMBB; |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 6341 | BuildMI(*BB, BB->begin(), dl, |
| 6342 | TII->get(ARM::PHI), MI->getOperand(0).getReg()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6343 | .addReg(MI->getOperand(1).getReg()).addMBB(copy0MBB) |
| 6344 | .addReg(MI->getOperand(2).getReg()).addMBB(thisMBB); |
| 6345 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 6346 | MI->eraseFromParent(); // The pseudo instruction is gone now. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6347 | return BB; |
| 6348 | } |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 6349 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 6350 | case ARM::BCCi64: |
| 6351 | case ARM::BCCZi64: { |
Bob Wilson | 3c90469 | 2010-12-23 22:45:49 +0000 | [diff] [blame] | 6352 | // If there is an unconditional branch to the other successor, remove it. |
| 6353 | BB->erase(llvm::next(MachineBasicBlock::iterator(MI)), BB->end()); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 6354 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 6355 | // Compare both parts that make up the double comparison separately for |
| 6356 | // equality. |
| 6357 | bool RHSisZero = MI->getOpcode() == ARM::BCCZi64; |
| 6358 | |
| 6359 | unsigned LHS1 = MI->getOperand(1).getReg(); |
| 6360 | unsigned LHS2 = MI->getOperand(2).getReg(); |
| 6361 | if (RHSisZero) { |
| 6362 | AddDefaultPred(BuildMI(BB, dl, |
| 6363 | TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 6364 | .addReg(LHS1).addImm(0)); |
| 6365 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 6366 | .addReg(LHS2).addImm(0) |
| 6367 | .addImm(ARMCC::EQ).addReg(ARM::CPSR); |
| 6368 | } else { |
| 6369 | unsigned RHS1 = MI->getOperand(3).getReg(); |
| 6370 | unsigned RHS2 = MI->getOperand(4).getReg(); |
| 6371 | AddDefaultPred(BuildMI(BB, dl, |
| 6372 | TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
| 6373 | .addReg(LHS1).addReg(RHS1)); |
| 6374 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
| 6375 | .addReg(LHS2).addReg(RHS2) |
| 6376 | .addImm(ARMCC::EQ).addReg(ARM::CPSR); |
| 6377 | } |
| 6378 | |
| 6379 | MachineBasicBlock *destMBB = MI->getOperand(RHSisZero ? 3 : 5).getMBB(); |
| 6380 | MachineBasicBlock *exitMBB = OtherSucc(BB, destMBB); |
| 6381 | if (MI->getOperand(0).getImm() == ARMCC::NE) |
| 6382 | std::swap(destMBB, exitMBB); |
| 6383 | |
| 6384 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 6385 | .addMBB(destMBB).addImm(ARMCC::EQ).addReg(ARM::CPSR); |
Owen Anderson | 51f6a7a | 2011-09-09 21:48:23 +0000 | [diff] [blame] | 6386 | if (isThumb2) |
| 6387 | AddDefaultPred(BuildMI(BB, dl, TII->get(ARM::t2B)).addMBB(exitMBB)); |
| 6388 | else |
| 6389 | BuildMI(BB, dl, TII->get(ARM::B)) .addMBB(exitMBB); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 6390 | |
| 6391 | MI->eraseFromParent(); // The pseudo instruction is gone now. |
| 6392 | return BB; |
| 6393 | } |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 6394 | |
Bill Wendling | 5bc8528 | 2011-10-17 20:37:20 +0000 | [diff] [blame] | 6395 | case ARM::Int_eh_sjlj_setjmp: |
| 6396 | case ARM::Int_eh_sjlj_setjmp_nofp: |
| 6397 | case ARM::tInt_eh_sjlj_setjmp: |
| 6398 | case ARM::t2Int_eh_sjlj_setjmp: |
| 6399 | case ARM::t2Int_eh_sjlj_setjmp_nofp: |
| 6400 | EmitSjLjDispatchBlock(MI, BB); |
| 6401 | return BB; |
| 6402 | |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 6403 | case ARM::ABS: |
| 6404 | case ARM::t2ABS: { |
| 6405 | // To insert an ABS instruction, we have to insert the |
| 6406 | // diamond control-flow pattern. The incoming instruction knows the |
| 6407 | // source vreg to test against 0, the destination vreg to set, |
| 6408 | // the condition code register to branch on, the |
Andrew Trick | 7f5f0da | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 6409 | // true/false values to select between, and a branch opcode to use. |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 6410 | // It transforms |
| 6411 | // V1 = ABS V0 |
| 6412 | // into |
| 6413 | // V2 = MOVS V0 |
| 6414 | // BCC (branch to SinkBB if V0 >= 0) |
| 6415 | // RSBBB: V3 = RSBri V2, 0 (compute ABS if V2 < 0) |
Andrew Trick | 7f5f0da | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 6416 | // SinkBB: V1 = PHI(V2, V3) |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 6417 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 6418 | MachineFunction::iterator BBI = BB; |
| 6419 | ++BBI; |
| 6420 | MachineFunction *Fn = BB->getParent(); |
| 6421 | MachineBasicBlock *RSBBB = Fn->CreateMachineBasicBlock(LLVM_BB); |
| 6422 | MachineBasicBlock *SinkBB = Fn->CreateMachineBasicBlock(LLVM_BB); |
| 6423 | Fn->insert(BBI, RSBBB); |
| 6424 | Fn->insert(BBI, SinkBB); |
| 6425 | |
| 6426 | unsigned int ABSSrcReg = MI->getOperand(1).getReg(); |
| 6427 | unsigned int ABSDstReg = MI->getOperand(0).getReg(); |
| 6428 | bool isThumb2 = Subtarget->isThumb2(); |
| 6429 | MachineRegisterInfo &MRI = Fn->getRegInfo(); |
| 6430 | // In Thumb mode S must not be specified if source register is the SP or |
| 6431 | // PC and if destination register is the SP, so restrict register class |
| 6432 | unsigned NewMovDstReg = MRI.createVirtualRegister( |
| 6433 | isThumb2 ? ARM::rGPRRegisterClass : ARM::GPRRegisterClass); |
| 6434 | unsigned NewRsbDstReg = MRI.createVirtualRegister( |
| 6435 | isThumb2 ? ARM::rGPRRegisterClass : ARM::GPRRegisterClass); |
| 6436 | |
| 6437 | // Transfer the remainder of BB and its successor edges to sinkMBB. |
| 6438 | SinkBB->splice(SinkBB->begin(), BB, |
| 6439 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 6440 | BB->end()); |
| 6441 | SinkBB->transferSuccessorsAndUpdatePHIs(BB); |
| 6442 | |
| 6443 | BB->addSuccessor(RSBBB); |
| 6444 | BB->addSuccessor(SinkBB); |
| 6445 | |
| 6446 | // fall through to SinkMBB |
| 6447 | RSBBB->addSuccessor(SinkBB); |
| 6448 | |
| 6449 | // insert a movs at the end of BB |
| 6450 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2MOVr : ARM::MOVr), |
| 6451 | NewMovDstReg) |
| 6452 | .addReg(ABSSrcReg, RegState::Kill) |
| 6453 | .addImm((unsigned)ARMCC::AL).addReg(0) |
| 6454 | .addReg(ARM::CPSR, RegState::Define); |
| 6455 | |
| 6456 | // 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] | 6457 | BuildMI(BB, dl, |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 6458 | TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)).addMBB(SinkBB) |
| 6459 | .addImm(ARMCC::getOppositeCondition(ARMCC::MI)).addReg(ARM::CPSR); |
| 6460 | |
| 6461 | // insert rsbri in RSBBB |
| 6462 | // Note: BCC and rsbri will be converted into predicated rsbmi |
| 6463 | // by if-conversion pass |
Andrew Trick | 7f5f0da | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 6464 | BuildMI(*RSBBB, RSBBB->begin(), dl, |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 6465 | TII->get(isThumb2 ? ARM::t2RSBri : ARM::RSBri), NewRsbDstReg) |
| 6466 | .addReg(NewMovDstReg, RegState::Kill) |
| 6467 | .addImm(0).addImm((unsigned)ARMCC::AL).addReg(0).addReg(0); |
| 6468 | |
Andrew Trick | 7f5f0da | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 6469 | // insert PHI in SinkBB, |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 6470 | // reuse ABSDstReg to not change uses of ABS instruction |
| 6471 | BuildMI(*SinkBB, SinkBB->begin(), dl, |
| 6472 | TII->get(ARM::PHI), ABSDstReg) |
| 6473 | .addReg(NewRsbDstReg).addMBB(RSBBB) |
| 6474 | .addReg(NewMovDstReg).addMBB(BB); |
| 6475 | |
| 6476 | // remove ABS instruction |
Andrew Trick | 7f5f0da | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 6477 | MI->eraseFromParent(); |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 6478 | |
| 6479 | // return last added BB |
| 6480 | return SinkBB; |
| 6481 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6482 | } |
| 6483 | } |
| 6484 | |
Evan Cheng | 37fefc2 | 2011-08-30 19:09:48 +0000 | [diff] [blame] | 6485 | void ARMTargetLowering::AdjustInstrPostInstrSelection(MachineInstr *MI, |
| 6486 | SDNode *Node) const { |
Evan Cheng | 5a96b3d | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 6487 | if (!MI->hasPostISelHook()) { |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 6488 | assert(!convertAddSubFlagsOpcode(MI->getOpcode()) && |
| 6489 | "Pseudo flag-setting opcodes must be marked with 'hasPostISelHook'"); |
| 6490 | return; |
| 6491 | } |
| 6492 | |
Evan Cheng | 5a96b3d | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 6493 | const MCInstrDesc *MCID = &MI->getDesc(); |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6494 | // Adjust potentially 's' setting instructions after isel, i.e. ADC, SBC, RSB, |
| 6495 | // RSC. Coming out of isel, they have an implicit CPSR def, but the optional |
| 6496 | // operand is still set to noreg. If needed, set the optional operand's |
| 6497 | // register to CPSR, and remove the redundant implicit def. |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 6498 | // |
Andrew Trick | 90b7b12 | 2011-10-18 19:18:52 +0000 | [diff] [blame] | 6499 | // e.g. ADCS (..., CPSR<imp-def>) -> ADC (... opt:CPSR<def>). |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6500 | |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 6501 | // Rename pseudo opcodes. |
| 6502 | unsigned NewOpc = convertAddSubFlagsOpcode(MI->getOpcode()); |
| 6503 | if (NewOpc) { |
| 6504 | const ARMBaseInstrInfo *TII = |
| 6505 | static_cast<const ARMBaseInstrInfo*>(getTargetMachine().getInstrInfo()); |
Andrew Trick | 90b7b12 | 2011-10-18 19:18:52 +0000 | [diff] [blame] | 6506 | MCID = &TII->get(NewOpc); |
| 6507 | |
| 6508 | assert(MCID->getNumOperands() == MI->getDesc().getNumOperands() + 1 && |
| 6509 | "converted opcode should be the same except for cc_out"); |
| 6510 | |
| 6511 | MI->setDesc(*MCID); |
| 6512 | |
| 6513 | // Add the optional cc_out operand |
| 6514 | MI->addOperand(MachineOperand::CreateReg(0, /*isDef=*/true)); |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 6515 | } |
Andrew Trick | 90b7b12 | 2011-10-18 19:18:52 +0000 | [diff] [blame] | 6516 | unsigned ccOutIdx = MCID->getNumOperands() - 1; |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6517 | |
| 6518 | // Any ARM instruction that sets the 's' bit should specify an optional |
| 6519 | // "cc_out" operand in the last operand position. |
Evan Cheng | 5a96b3d | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 6520 | if (!MI->hasOptionalDef() || !MCID->OpInfo[ccOutIdx].isOptionalDef()) { |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 6521 | assert(!NewOpc && "Optional cc_out operand required"); |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6522 | return; |
| 6523 | } |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 6524 | // Look for an implicit def of CPSR added by MachineInstr ctor. Remove it |
| 6525 | // since we already have an optional CPSR def. |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6526 | bool definesCPSR = false; |
| 6527 | bool deadCPSR = false; |
Andrew Trick | 90b7b12 | 2011-10-18 19:18:52 +0000 | [diff] [blame] | 6528 | for (unsigned i = MCID->getNumOperands(), e = MI->getNumOperands(); |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6529 | i != e; ++i) { |
| 6530 | const MachineOperand &MO = MI->getOperand(i); |
| 6531 | if (MO.isReg() && MO.isDef() && MO.getReg() == ARM::CPSR) { |
| 6532 | definesCPSR = true; |
| 6533 | if (MO.isDead()) |
| 6534 | deadCPSR = true; |
| 6535 | MI->RemoveOperand(i); |
| 6536 | break; |
Evan Cheng | 37fefc2 | 2011-08-30 19:09:48 +0000 | [diff] [blame] | 6537 | } |
| 6538 | } |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6539 | if (!definesCPSR) { |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 6540 | assert(!NewOpc && "Optional cc_out operand required"); |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6541 | return; |
| 6542 | } |
| 6543 | assert(deadCPSR == !Node->hasAnyUseOfValue(1) && "inconsistent dead flag"); |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 6544 | if (deadCPSR) { |
| 6545 | assert(!MI->getOperand(ccOutIdx).getReg() && |
| 6546 | "expect uninitialized optional cc_out operand"); |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6547 | return; |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 6548 | } |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6549 | |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 6550 | // If this instruction was defined with an optional CPSR def and its dag node |
| 6551 | // had a live implicit CPSR def, then activate the optional CPSR def. |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6552 | MachineOperand &MO = MI->getOperand(ccOutIdx); |
| 6553 | MO.setReg(ARM::CPSR); |
| 6554 | MO.setIsDef(true); |
Evan Cheng | 37fefc2 | 2011-08-30 19:09:48 +0000 | [diff] [blame] | 6555 | } |
| 6556 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6557 | //===----------------------------------------------------------------------===// |
| 6558 | // ARM Optimization Hooks |
| 6559 | //===----------------------------------------------------------------------===// |
| 6560 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 6561 | static |
| 6562 | SDValue combineSelectAndUse(SDNode *N, SDValue Slct, SDValue OtherOp, |
| 6563 | TargetLowering::DAGCombinerInfo &DCI) { |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 6564 | SelectionDAG &DAG = DCI.DAG; |
| 6565 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6566 | EVT VT = N->getValueType(0); |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 6567 | unsigned Opc = N->getOpcode(); |
| 6568 | bool isSlctCC = Slct.getOpcode() == ISD::SELECT_CC; |
| 6569 | SDValue LHS = isSlctCC ? Slct.getOperand(2) : Slct.getOperand(1); |
| 6570 | SDValue RHS = isSlctCC ? Slct.getOperand(3) : Slct.getOperand(2); |
| 6571 | ISD::CondCode CC = ISD::SETCC_INVALID; |
| 6572 | |
| 6573 | if (isSlctCC) { |
| 6574 | CC = cast<CondCodeSDNode>(Slct.getOperand(4))->get(); |
| 6575 | } else { |
| 6576 | SDValue CCOp = Slct.getOperand(0); |
| 6577 | if (CCOp.getOpcode() == ISD::SETCC) |
| 6578 | CC = cast<CondCodeSDNode>(CCOp.getOperand(2))->get(); |
| 6579 | } |
| 6580 | |
| 6581 | bool DoXform = false; |
| 6582 | bool InvCC = false; |
| 6583 | assert ((Opc == ISD::ADD || (Opc == ISD::SUB && Slct == N->getOperand(1))) && |
| 6584 | "Bad input!"); |
| 6585 | |
| 6586 | if (LHS.getOpcode() == ISD::Constant && |
| 6587 | cast<ConstantSDNode>(LHS)->isNullValue()) { |
| 6588 | DoXform = true; |
| 6589 | } else if (CC != ISD::SETCC_INVALID && |
| 6590 | RHS.getOpcode() == ISD::Constant && |
| 6591 | cast<ConstantSDNode>(RHS)->isNullValue()) { |
| 6592 | std::swap(LHS, RHS); |
| 6593 | SDValue Op0 = Slct.getOperand(0); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6594 | EVT OpVT = isSlctCC ? Op0.getValueType() : |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 6595 | Op0.getOperand(0).getValueType(); |
| 6596 | bool isInt = OpVT.isInteger(); |
| 6597 | CC = ISD::getSetCCInverse(CC, isInt); |
| 6598 | |
| 6599 | if (!TLI.isCondCodeLegal(CC, OpVT)) |
| 6600 | return SDValue(); // Inverse operator isn't legal. |
| 6601 | |
| 6602 | DoXform = true; |
| 6603 | InvCC = true; |
| 6604 | } |
| 6605 | |
| 6606 | if (DoXform) { |
| 6607 | SDValue Result = DAG.getNode(Opc, RHS.getDebugLoc(), VT, OtherOp, RHS); |
| 6608 | if (isSlctCC) |
| 6609 | return DAG.getSelectCC(N->getDebugLoc(), OtherOp, Result, |
| 6610 | Slct.getOperand(0), Slct.getOperand(1), CC); |
| 6611 | SDValue CCOp = Slct.getOperand(0); |
| 6612 | if (InvCC) |
| 6613 | CCOp = DAG.getSetCC(Slct.getDebugLoc(), CCOp.getValueType(), |
| 6614 | CCOp.getOperand(0), CCOp.getOperand(1), CC); |
| 6615 | return DAG.getNode(ISD::SELECT, N->getDebugLoc(), VT, |
| 6616 | CCOp, OtherOp, Result); |
| 6617 | } |
| 6618 | return SDValue(); |
| 6619 | } |
| 6620 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 6621 | // AddCombineToVPADDL- For pair-wise add on neon, use the vpaddl instruction |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6622 | // (only after legalization). |
| 6623 | static SDValue AddCombineToVPADDL(SDNode *N, SDValue N0, SDValue N1, |
| 6624 | TargetLowering::DAGCombinerInfo &DCI, |
| 6625 | const ARMSubtarget *Subtarget) { |
| 6626 | |
| 6627 | // Only perform optimization if after legalize, and if NEON is available. We |
| 6628 | // also expected both operands to be BUILD_VECTORs. |
| 6629 | if (DCI.isBeforeLegalize() || !Subtarget->hasNEON() |
| 6630 | || N0.getOpcode() != ISD::BUILD_VECTOR |
| 6631 | || N1.getOpcode() != ISD::BUILD_VECTOR) |
| 6632 | return SDValue(); |
| 6633 | |
| 6634 | // Check output type since VPADDL operand elements can only be 8, 16, or 32. |
| 6635 | EVT VT = N->getValueType(0); |
| 6636 | if (!VT.isInteger() || VT.getVectorElementType() == MVT::i64) |
| 6637 | return SDValue(); |
| 6638 | |
| 6639 | // Check that the vector operands are of the right form. |
| 6640 | // N0 and N1 are BUILD_VECTOR nodes with N number of EXTRACT_VECTOR |
| 6641 | // operands, where N is the size of the formed vector. |
| 6642 | // Each EXTRACT_VECTOR should have the same input vector and odd or even |
| 6643 | // index such that we have a pair wise add pattern. |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6644 | |
| 6645 | // Grab the vector that all EXTRACT_VECTOR nodes should be referencing. |
Bob Wilson | 7a10ab7 | 2011-06-15 06:04:34 +0000 | [diff] [blame] | 6646 | if (N0->getOperand(0)->getOpcode() != ISD::EXTRACT_VECTOR_ELT) |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6647 | return SDValue(); |
Bob Wilson | 7a10ab7 | 2011-06-15 06:04:34 +0000 | [diff] [blame] | 6648 | SDValue Vec = N0->getOperand(0)->getOperand(0); |
| 6649 | SDNode *V = Vec.getNode(); |
| 6650 | unsigned nextIndex = 0; |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6651 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 6652 | // For each operands to the ADD which are BUILD_VECTORs, |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6653 | // check to see if each of their operands are an EXTRACT_VECTOR with |
| 6654 | // the same vector and appropriate index. |
| 6655 | for (unsigned i = 0, e = N0->getNumOperands(); i != e; ++i) { |
| 6656 | if (N0->getOperand(i)->getOpcode() == ISD::EXTRACT_VECTOR_ELT |
| 6657 | && N1->getOperand(i)->getOpcode() == ISD::EXTRACT_VECTOR_ELT) { |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 6658 | |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6659 | SDValue ExtVec0 = N0->getOperand(i); |
| 6660 | SDValue ExtVec1 = N1->getOperand(i); |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 6661 | |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6662 | // First operand is the vector, verify its the same. |
| 6663 | if (V != ExtVec0->getOperand(0).getNode() || |
| 6664 | V != ExtVec1->getOperand(0).getNode()) |
| 6665 | return SDValue(); |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 6666 | |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6667 | // Second is the constant, verify its correct. |
| 6668 | ConstantSDNode *C0 = dyn_cast<ConstantSDNode>(ExtVec0->getOperand(1)); |
| 6669 | ConstantSDNode *C1 = dyn_cast<ConstantSDNode>(ExtVec1->getOperand(1)); |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 6670 | |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6671 | // For the constant, we want to see all the even or all the odd. |
| 6672 | if (!C0 || !C1 || C0->getZExtValue() != nextIndex |
| 6673 | || C1->getZExtValue() != nextIndex+1) |
| 6674 | return SDValue(); |
| 6675 | |
| 6676 | // Increment index. |
| 6677 | nextIndex+=2; |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 6678 | } else |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6679 | return SDValue(); |
| 6680 | } |
| 6681 | |
| 6682 | // Create VPADDL node. |
| 6683 | SelectionDAG &DAG = DCI.DAG; |
| 6684 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6685 | |
| 6686 | // Build operand list. |
| 6687 | SmallVector<SDValue, 8> Ops; |
| 6688 | Ops.push_back(DAG.getConstant(Intrinsic::arm_neon_vpaddls, |
| 6689 | TLI.getPointerTy())); |
| 6690 | |
| 6691 | // Input is the vector. |
| 6692 | Ops.push_back(Vec); |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 6693 | |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6694 | // Get widened type and narrowed type. |
| 6695 | MVT widenType; |
| 6696 | unsigned numElem = VT.getVectorNumElements(); |
| 6697 | switch (VT.getVectorElementType().getSimpleVT().SimpleTy) { |
| 6698 | case MVT::i8: widenType = MVT::getVectorVT(MVT::i16, numElem); break; |
| 6699 | case MVT::i16: widenType = MVT::getVectorVT(MVT::i32, numElem); break; |
| 6700 | case MVT::i32: widenType = MVT::getVectorVT(MVT::i64, numElem); break; |
| 6701 | default: |
Craig Topper | bc21981 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 6702 | llvm_unreachable("Invalid vector element type for padd optimization."); |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6703 | } |
| 6704 | |
| 6705 | SDValue tmp = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, N->getDebugLoc(), |
| 6706 | widenType, &Ops[0], Ops.size()); |
| 6707 | return DAG.getNode(ISD::TRUNCATE, N->getDebugLoc(), VT, tmp); |
| 6708 | } |
| 6709 | |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 6710 | /// PerformADDCombineWithOperands - Try DAG combinations for an ADD with |
| 6711 | /// operands N0 and N1. This is a helper for PerformADDCombine that is |
| 6712 | /// called with the default operands, and if that fails, with commuted |
| 6713 | /// operands. |
| 6714 | static SDValue PerformADDCombineWithOperands(SDNode *N, SDValue N0, SDValue N1, |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6715 | TargetLowering::DAGCombinerInfo &DCI, |
| 6716 | const ARMSubtarget *Subtarget){ |
| 6717 | |
| 6718 | // Attempt to create vpaddl for this add. |
| 6719 | SDValue Result = AddCombineToVPADDL(N, N0, N1, DCI, Subtarget); |
| 6720 | if (Result.getNode()) |
| 6721 | return Result; |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 6722 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 6723 | // fold (add (select cc, 0, c), x) -> (select cc, x, (add, x, c)) |
| 6724 | if (N0.getOpcode() == ISD::SELECT && N0.getNode()->hasOneUse()) { |
| 6725 | SDValue Result = combineSelectAndUse(N, N0, N1, DCI); |
| 6726 | if (Result.getNode()) return Result; |
| 6727 | } |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 6728 | return SDValue(); |
| 6729 | } |
| 6730 | |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 6731 | /// PerformADDCombine - Target-specific dag combine xforms for ISD::ADD. |
| 6732 | /// |
| 6733 | static SDValue PerformADDCombine(SDNode *N, |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6734 | TargetLowering::DAGCombinerInfo &DCI, |
| 6735 | const ARMSubtarget *Subtarget) { |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 6736 | SDValue N0 = N->getOperand(0); |
| 6737 | SDValue N1 = N->getOperand(1); |
| 6738 | |
| 6739 | // First try with the default operand order. |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6740 | SDValue Result = PerformADDCombineWithOperands(N, N0, N1, DCI, Subtarget); |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 6741 | if (Result.getNode()) |
| 6742 | return Result; |
| 6743 | |
| 6744 | // If that didn't work, try again with the operands commuted. |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6745 | return PerformADDCombineWithOperands(N, N1, N0, DCI, Subtarget); |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 6746 | } |
| 6747 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 6748 | /// PerformSUBCombine - Target-specific dag combine xforms for ISD::SUB. |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 6749 | /// |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 6750 | static SDValue PerformSUBCombine(SDNode *N, |
| 6751 | TargetLowering::DAGCombinerInfo &DCI) { |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 6752 | SDValue N0 = N->getOperand(0); |
| 6753 | SDValue N1 = N->getOperand(1); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 6754 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 6755 | // fold (sub x, (select cc, 0, c)) -> (select cc, x, (sub, x, c)) |
| 6756 | if (N1.getOpcode() == ISD::SELECT && N1.getNode()->hasOneUse()) { |
| 6757 | SDValue Result = combineSelectAndUse(N, N1, N0, DCI); |
| 6758 | if (Result.getNode()) return Result; |
| 6759 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 6760 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 6761 | return SDValue(); |
| 6762 | } |
| 6763 | |
Evan Cheng | 463d358 | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 6764 | /// PerformVMULCombine |
| 6765 | /// Distribute (A + B) * C to (A * C) + (B * C) to take advantage of the |
| 6766 | /// special multiplier accumulator forwarding. |
| 6767 | /// vmul d3, d0, d2 |
| 6768 | /// vmla d3, d1, d2 |
| 6769 | /// is faster than |
| 6770 | /// vadd d3, d0, d1 |
| 6771 | /// vmul d3, d3, d2 |
| 6772 | static SDValue PerformVMULCombine(SDNode *N, |
| 6773 | TargetLowering::DAGCombinerInfo &DCI, |
| 6774 | const ARMSubtarget *Subtarget) { |
| 6775 | if (!Subtarget->hasVMLxForwarding()) |
| 6776 | return SDValue(); |
| 6777 | |
| 6778 | SelectionDAG &DAG = DCI.DAG; |
| 6779 | SDValue N0 = N->getOperand(0); |
| 6780 | SDValue N1 = N->getOperand(1); |
| 6781 | unsigned Opcode = N0.getOpcode(); |
| 6782 | if (Opcode != ISD::ADD && Opcode != ISD::SUB && |
| 6783 | Opcode != ISD::FADD && Opcode != ISD::FSUB) { |
Chad Rosier | 689edc8 | 2011-06-16 01:21:54 +0000 | [diff] [blame] | 6784 | Opcode = N1.getOpcode(); |
Evan Cheng | 463d358 | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 6785 | if (Opcode != ISD::ADD && Opcode != ISD::SUB && |
| 6786 | Opcode != ISD::FADD && Opcode != ISD::FSUB) |
| 6787 | return SDValue(); |
| 6788 | std::swap(N0, N1); |
| 6789 | } |
| 6790 | |
| 6791 | EVT VT = N->getValueType(0); |
| 6792 | DebugLoc DL = N->getDebugLoc(); |
| 6793 | SDValue N00 = N0->getOperand(0); |
| 6794 | SDValue N01 = N0->getOperand(1); |
| 6795 | return DAG.getNode(Opcode, DL, VT, |
| 6796 | DAG.getNode(ISD::MUL, DL, VT, N00, N1), |
| 6797 | DAG.getNode(ISD::MUL, DL, VT, N01, N1)); |
| 6798 | } |
| 6799 | |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 6800 | static SDValue PerformMULCombine(SDNode *N, |
| 6801 | TargetLowering::DAGCombinerInfo &DCI, |
| 6802 | const ARMSubtarget *Subtarget) { |
| 6803 | SelectionDAG &DAG = DCI.DAG; |
| 6804 | |
| 6805 | if (Subtarget->isThumb1Only()) |
| 6806 | return SDValue(); |
| 6807 | |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 6808 | if (DCI.isBeforeLegalize() || DCI.isCalledByLegalizer()) |
| 6809 | return SDValue(); |
| 6810 | |
| 6811 | EVT VT = N->getValueType(0); |
Evan Cheng | 463d358 | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 6812 | if (VT.is64BitVector() || VT.is128BitVector()) |
| 6813 | return PerformVMULCombine(N, DCI, Subtarget); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 6814 | if (VT != MVT::i32) |
| 6815 | return SDValue(); |
| 6816 | |
| 6817 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1)); |
| 6818 | if (!C) |
| 6819 | return SDValue(); |
| 6820 | |
| 6821 | uint64_t MulAmt = C->getZExtValue(); |
| 6822 | unsigned ShiftAmt = CountTrailingZeros_64(MulAmt); |
| 6823 | ShiftAmt = ShiftAmt & (32 - 1); |
| 6824 | SDValue V = N->getOperand(0); |
| 6825 | DebugLoc DL = N->getDebugLoc(); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 6826 | |
Anton Korobeynikov | 4878b84 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 6827 | SDValue Res; |
| 6828 | MulAmt >>= ShiftAmt; |
| 6829 | if (isPowerOf2_32(MulAmt - 1)) { |
| 6830 | // (mul x, 2^N + 1) => (add (shl x, N), x) |
| 6831 | Res = DAG.getNode(ISD::ADD, DL, VT, |
| 6832 | V, DAG.getNode(ISD::SHL, DL, VT, |
| 6833 | V, DAG.getConstant(Log2_32(MulAmt-1), |
| 6834 | MVT::i32))); |
| 6835 | } else if (isPowerOf2_32(MulAmt + 1)) { |
| 6836 | // (mul x, 2^N - 1) => (sub (shl x, N), x) |
| 6837 | Res = DAG.getNode(ISD::SUB, DL, VT, |
| 6838 | DAG.getNode(ISD::SHL, DL, VT, |
| 6839 | V, DAG.getConstant(Log2_32(MulAmt+1), |
| 6840 | MVT::i32)), |
| 6841 | V); |
| 6842 | } else |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 6843 | return SDValue(); |
Anton Korobeynikov | 4878b84 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 6844 | |
| 6845 | if (ShiftAmt != 0) |
| 6846 | Res = DAG.getNode(ISD::SHL, DL, VT, Res, |
| 6847 | DAG.getConstant(ShiftAmt, MVT::i32)); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 6848 | |
| 6849 | // Do not add new nodes to DAG combiner worklist. |
Anton Korobeynikov | 4878b84 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 6850 | DCI.CombineTo(N, Res, false); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 6851 | return SDValue(); |
| 6852 | } |
| 6853 | |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 6854 | static bool isCMOVWithZeroOrAllOnesLHS(SDValue N, bool AllOnes) { |
| 6855 | if (N.getOpcode() != ARMISD::CMOV || !N.getNode()->hasOneUse()) |
| 6856 | return false; |
| 6857 | |
| 6858 | SDValue FalseVal = N.getOperand(0); |
| 6859 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(FalseVal); |
| 6860 | if (!C) |
| 6861 | return false; |
| 6862 | if (AllOnes) |
| 6863 | return C->isAllOnesValue(); |
| 6864 | return C->isNullValue(); |
| 6865 | } |
| 6866 | |
| 6867 | /// formConditionalOp - Combine an operation with a conditional move operand |
| 6868 | /// to form a conditional op. e.g. (or x, (cmov 0, y, cond)) => (or.cond x, y) |
| 6869 | /// (and x, (cmov -1, y, cond)) => (and.cond, x, y) |
| 6870 | static SDValue formConditionalOp(SDNode *N, SelectionDAG &DAG, |
| 6871 | bool Commutable) { |
| 6872 | SDValue N0 = N->getOperand(0); |
| 6873 | SDValue N1 = N->getOperand(1); |
| 6874 | |
| 6875 | bool isAND = N->getOpcode() == ISD::AND; |
| 6876 | bool isCand = isCMOVWithZeroOrAllOnesLHS(N1, isAND); |
| 6877 | if (!isCand && Commutable) { |
| 6878 | isCand = isCMOVWithZeroOrAllOnesLHS(N0, isAND); |
| 6879 | if (isCand) |
| 6880 | std::swap(N0, N1); |
| 6881 | } |
| 6882 | if (!isCand) |
| 6883 | return SDValue(); |
| 6884 | |
| 6885 | unsigned Opc = 0; |
| 6886 | switch (N->getOpcode()) { |
| 6887 | default: llvm_unreachable("Unexpected node"); |
| 6888 | case ISD::AND: Opc = ARMISD::CAND; break; |
| 6889 | case ISD::OR: Opc = ARMISD::COR; break; |
| 6890 | case ISD::XOR: Opc = ARMISD::CXOR; break; |
| 6891 | } |
| 6892 | return DAG.getNode(Opc, N->getDebugLoc(), N->getValueType(0), N0, |
| 6893 | N1.getOperand(1), N1.getOperand(2), N1.getOperand(3), |
| 6894 | N1.getOperand(4)); |
| 6895 | } |
| 6896 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 6897 | static SDValue PerformANDCombine(SDNode *N, |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 6898 | TargetLowering::DAGCombinerInfo &DCI, |
| 6899 | const ARMSubtarget *Subtarget) { |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6900 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 6901 | // Attempt to use immediate-form VBIC |
| 6902 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(N->getOperand(1)); |
| 6903 | DebugLoc dl = N->getDebugLoc(); |
| 6904 | EVT VT = N->getValueType(0); |
| 6905 | SelectionDAG &DAG = DCI.DAG; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6906 | |
Tanya Lattner | 0433b21 | 2011-04-07 15:24:20 +0000 | [diff] [blame] | 6907 | if(!DAG.getTargetLoweringInfo().isTypeLegal(VT)) |
| 6908 | return SDValue(); |
Andrew Trick | 1c3af77 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 6909 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 6910 | APInt SplatBits, SplatUndef; |
| 6911 | unsigned SplatBitSize; |
| 6912 | bool HasAnyUndefs; |
| 6913 | if (BVN && |
| 6914 | BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { |
| 6915 | if (SplatBitSize <= 64) { |
| 6916 | EVT VbicVT; |
| 6917 | SDValue Val = isNEONModifiedImm((~SplatBits).getZExtValue(), |
| 6918 | SplatUndef.getZExtValue(), SplatBitSize, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6919 | DAG, VbicVT, VT.is128BitVector(), |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 6920 | OtherModImm); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 6921 | if (Val.getNode()) { |
| 6922 | SDValue Input = |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6923 | DAG.getNode(ISD::BITCAST, dl, VbicVT, N->getOperand(0)); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 6924 | SDValue Vbic = DAG.getNode(ARMISD::VBICIMM, dl, VbicVT, Input, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6925 | return DAG.getNode(ISD::BITCAST, dl, VT, Vbic); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 6926 | } |
| 6927 | } |
| 6928 | } |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6929 | |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 6930 | if (!Subtarget->isThumb1Only()) { |
| 6931 | // (and x, (cmov -1, y, cond)) => (and.cond x, y) |
| 6932 | SDValue CAND = formConditionalOp(N, DAG, true); |
| 6933 | if (CAND.getNode()) |
| 6934 | return CAND; |
| 6935 | } |
| 6936 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 6937 | return SDValue(); |
| 6938 | } |
| 6939 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 6940 | /// PerformORCombine - Target-specific dag combine xforms for ISD::OR |
| 6941 | static SDValue PerformORCombine(SDNode *N, |
| 6942 | TargetLowering::DAGCombinerInfo &DCI, |
| 6943 | const ARMSubtarget *Subtarget) { |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 6944 | // Attempt to use immediate-form VORR |
| 6945 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(N->getOperand(1)); |
| 6946 | DebugLoc dl = N->getDebugLoc(); |
| 6947 | EVT VT = N->getValueType(0); |
| 6948 | SelectionDAG &DAG = DCI.DAG; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6949 | |
Tanya Lattner | 0433b21 | 2011-04-07 15:24:20 +0000 | [diff] [blame] | 6950 | if(!DAG.getTargetLoweringInfo().isTypeLegal(VT)) |
| 6951 | return SDValue(); |
Andrew Trick | 1c3af77 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 6952 | |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 6953 | APInt SplatBits, SplatUndef; |
| 6954 | unsigned SplatBitSize; |
| 6955 | bool HasAnyUndefs; |
| 6956 | if (BVN && Subtarget->hasNEON() && |
| 6957 | BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { |
| 6958 | if (SplatBitSize <= 64) { |
| 6959 | EVT VorrVT; |
| 6960 | SDValue Val = isNEONModifiedImm(SplatBits.getZExtValue(), |
| 6961 | SplatUndef.getZExtValue(), SplatBitSize, |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 6962 | DAG, VorrVT, VT.is128BitVector(), |
| 6963 | OtherModImm); |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 6964 | if (Val.getNode()) { |
| 6965 | SDValue Input = |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6966 | DAG.getNode(ISD::BITCAST, dl, VorrVT, N->getOperand(0)); |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 6967 | SDValue Vorr = DAG.getNode(ARMISD::VORRIMM, dl, VorrVT, Input, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6968 | return DAG.getNode(ISD::BITCAST, dl, VT, Vorr); |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 6969 | } |
| 6970 | } |
| 6971 | } |
| 6972 | |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 6973 | if (!Subtarget->isThumb1Only()) { |
| 6974 | // (or x, (cmov 0, y, cond)) => (or.cond x, y) |
| 6975 | SDValue COR = formConditionalOp(N, DAG, true); |
| 6976 | if (COR.getNode()) |
| 6977 | return COR; |
| 6978 | } |
| 6979 | |
Cameron Zwarich | c0e6d78 | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 6980 | SDValue N0 = N->getOperand(0); |
| 6981 | if (N0.getOpcode() != ISD::AND) |
| 6982 | return SDValue(); |
| 6983 | SDValue N1 = N->getOperand(1); |
| 6984 | |
| 6985 | // (or (and B, A), (and C, ~A)) => (VBSL A, B, C) when A is a constant. |
| 6986 | if (Subtarget->hasNEON() && N1.getOpcode() == ISD::AND && VT.isVector() && |
| 6987 | DAG.getTargetLoweringInfo().isTypeLegal(VT)) { |
| 6988 | APInt SplatUndef; |
| 6989 | unsigned SplatBitSize; |
| 6990 | bool HasAnyUndefs; |
| 6991 | |
| 6992 | BuildVectorSDNode *BVN0 = dyn_cast<BuildVectorSDNode>(N0->getOperand(1)); |
| 6993 | APInt SplatBits0; |
| 6994 | if (BVN0 && BVN0->isConstantSplat(SplatBits0, SplatUndef, SplatBitSize, |
| 6995 | HasAnyUndefs) && !HasAnyUndefs) { |
| 6996 | BuildVectorSDNode *BVN1 = dyn_cast<BuildVectorSDNode>(N1->getOperand(1)); |
| 6997 | APInt SplatBits1; |
| 6998 | if (BVN1 && BVN1->isConstantSplat(SplatBits1, SplatUndef, SplatBitSize, |
| 6999 | HasAnyUndefs) && !HasAnyUndefs && |
| 7000 | SplatBits0 == ~SplatBits1) { |
| 7001 | // Canonicalize the vector type to make instruction selection simpler. |
| 7002 | EVT CanonicalVT = VT.is128BitVector() ? MVT::v4i32 : MVT::v2i32; |
| 7003 | SDValue Result = DAG.getNode(ARMISD::VBSL, dl, CanonicalVT, |
| 7004 | N0->getOperand(1), N0->getOperand(0), |
Cameron Zwarich | 5af60ce | 2011-04-13 21:01:19 +0000 | [diff] [blame] | 7005 | N1->getOperand(0)); |
Cameron Zwarich | c0e6d78 | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 7006 | return DAG.getNode(ISD::BITCAST, dl, VT, Result); |
| 7007 | } |
| 7008 | } |
| 7009 | } |
| 7010 | |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7011 | // Try to use the ARM/Thumb2 BFI (bitfield insert) instruction when |
| 7012 | // reasonable. |
| 7013 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 7014 | // BFI is only available on V6T2+ |
| 7015 | if (Subtarget->isThumb1Only() || !Subtarget->hasV6T2Ops()) |
| 7016 | return SDValue(); |
| 7017 | |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7018 | DebugLoc DL = N->getDebugLoc(); |
| 7019 | // 1) or (and A, mask), val => ARMbfi A, val, mask |
| 7020 | // iff (val & mask) == val |
| 7021 | // |
| 7022 | // 2) or (and A, mask), (and B, mask2) => ARMbfi A, (lsr B, amt), mask |
| 7023 | // 2a) iff isBitFieldInvertedMask(mask) && isBitFieldInvertedMask(~mask2) |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 7024 | // && mask == ~mask2 |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7025 | // 2b) iff isBitFieldInvertedMask(~mask) && isBitFieldInvertedMask(mask2) |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 7026 | // && ~mask == mask2 |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7027 | // (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] | 7028 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 7029 | if (VT != MVT::i32) |
| 7030 | return SDValue(); |
| 7031 | |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7032 | SDValue N00 = N0.getOperand(0); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7033 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 7034 | // The value and the mask need to be constants so we can verify this is |
| 7035 | // actually a bitfield set. If the mask is 0xffff, we can do better |
| 7036 | // via a movt instruction, so don't use BFI in that case. |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7037 | SDValue MaskOp = N0.getOperand(1); |
| 7038 | ConstantSDNode *MaskC = dyn_cast<ConstantSDNode>(MaskOp); |
| 7039 | if (!MaskC) |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 7040 | return SDValue(); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7041 | unsigned Mask = MaskC->getZExtValue(); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 7042 | if (Mask == 0xffff) |
| 7043 | return SDValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7044 | SDValue Res; |
| 7045 | // Case (1): or (and A, mask), val => ARMbfi A, val, mask |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7046 | ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1); |
| 7047 | if (N1C) { |
| 7048 | unsigned Val = N1C->getZExtValue(); |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 7049 | if ((Val & ~Mask) != Val) |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7050 | return SDValue(); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 7051 | |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 7052 | if (ARM::isBitFieldInvertedMask(Mask)) { |
| 7053 | Val >>= CountTrailingZeros_32(~Mask); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 7054 | |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7055 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N00, |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 7056 | DAG.getConstant(Val, MVT::i32), |
| 7057 | DAG.getConstant(Mask, MVT::i32)); |
| 7058 | |
| 7059 | // Do not add new nodes to DAG combiner worklist. |
| 7060 | DCI.CombineTo(N, Res, false); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7061 | return SDValue(); |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 7062 | } |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7063 | } else if (N1.getOpcode() == ISD::AND) { |
| 7064 | // 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] | 7065 | ConstantSDNode *N11C = dyn_cast<ConstantSDNode>(N1.getOperand(1)); |
| 7066 | if (!N11C) |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7067 | return SDValue(); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7068 | unsigned Mask2 = N11C->getZExtValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7069 | |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 7070 | // Mask and ~Mask2 (or reverse) must be equivalent for the BFI pattern |
| 7071 | // as is to match. |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7072 | if (ARM::isBitFieldInvertedMask(Mask) && |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 7073 | (Mask == ~Mask2)) { |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7074 | // The pack halfword instruction works better for masks that fit it, |
| 7075 | // so use that when it's available. |
| 7076 | if (Subtarget->hasT2ExtractPack() && |
| 7077 | (Mask == 0xffff || Mask == 0xffff0000)) |
| 7078 | return SDValue(); |
| 7079 | // 2a |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 7080 | unsigned amt = CountTrailingZeros_32(Mask2); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7081 | Res = DAG.getNode(ISD::SRL, DL, VT, N1.getOperand(0), |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 7082 | DAG.getConstant(amt, MVT::i32)); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7083 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N00, Res, |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7084 | DAG.getConstant(Mask, MVT::i32)); |
| 7085 | // Do not add new nodes to DAG combiner worklist. |
| 7086 | DCI.CombineTo(N, Res, false); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7087 | return SDValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7088 | } else if (ARM::isBitFieldInvertedMask(~Mask) && |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 7089 | (~Mask == Mask2)) { |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7090 | // The pack halfword instruction works better for masks that fit it, |
| 7091 | // so use that when it's available. |
| 7092 | if (Subtarget->hasT2ExtractPack() && |
| 7093 | (Mask2 == 0xffff || Mask2 == 0xffff0000)) |
| 7094 | return SDValue(); |
| 7095 | // 2b |
| 7096 | unsigned lsb = CountTrailingZeros_32(Mask); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7097 | Res = DAG.getNode(ISD::SRL, DL, VT, N00, |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7098 | DAG.getConstant(lsb, MVT::i32)); |
| 7099 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N1.getOperand(0), Res, |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 7100 | DAG.getConstant(Mask2, MVT::i32)); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7101 | // Do not add new nodes to DAG combiner worklist. |
| 7102 | DCI.CombineTo(N, Res, false); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7103 | return SDValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7104 | } |
| 7105 | } |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7106 | |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7107 | if (DAG.MaskedValueIsZero(N1, MaskC->getAPIntValue()) && |
| 7108 | N00.getOpcode() == ISD::SHL && isa<ConstantSDNode>(N00.getOperand(1)) && |
| 7109 | ARM::isBitFieldInvertedMask(~Mask)) { |
| 7110 | // Case (3): or (and (shl A, #shamt), mask), B => ARMbfi B, A, ~mask |
| 7111 | // where lsb(mask) == #shamt and masked bits of B are known zero. |
| 7112 | SDValue ShAmt = N00.getOperand(1); |
| 7113 | unsigned ShAmtC = cast<ConstantSDNode>(ShAmt)->getZExtValue(); |
| 7114 | unsigned LSB = CountTrailingZeros_32(Mask); |
| 7115 | if (ShAmtC != LSB) |
| 7116 | return SDValue(); |
| 7117 | |
| 7118 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N1, N00.getOperand(0), |
| 7119 | DAG.getConstant(~Mask, MVT::i32)); |
| 7120 | |
| 7121 | // Do not add new nodes to DAG combiner worklist. |
| 7122 | DCI.CombineTo(N, Res, false); |
| 7123 | } |
| 7124 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 7125 | return SDValue(); |
| 7126 | } |
| 7127 | |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 7128 | static SDValue PerformXORCombine(SDNode *N, |
| 7129 | TargetLowering::DAGCombinerInfo &DCI, |
| 7130 | const ARMSubtarget *Subtarget) { |
| 7131 | EVT VT = N->getValueType(0); |
| 7132 | SelectionDAG &DAG = DCI.DAG; |
| 7133 | |
| 7134 | if(!DAG.getTargetLoweringInfo().isTypeLegal(VT)) |
| 7135 | return SDValue(); |
| 7136 | |
| 7137 | if (!Subtarget->isThumb1Only()) { |
| 7138 | // (xor x, (cmov 0, y, cond)) => (xor.cond x, y) |
| 7139 | SDValue CXOR = formConditionalOp(N, DAG, true); |
| 7140 | if (CXOR.getNode()) |
| 7141 | return CXOR; |
| 7142 | } |
| 7143 | |
| 7144 | return SDValue(); |
| 7145 | } |
| 7146 | |
Evan Cheng | bf188ae | 2011-06-15 01:12:31 +0000 | [diff] [blame] | 7147 | /// PerformBFICombine - (bfi A, (and B, Mask1), Mask2) -> (bfi A, B, Mask2) iff |
| 7148 | /// 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] | 7149 | static SDValue PerformBFICombine(SDNode *N, |
| 7150 | TargetLowering::DAGCombinerInfo &DCI) { |
| 7151 | SDValue N1 = N->getOperand(1); |
| 7152 | if (N1.getOpcode() == ISD::AND) { |
| 7153 | ConstantSDNode *N11C = dyn_cast<ConstantSDNode>(N1.getOperand(1)); |
| 7154 | if (!N11C) |
| 7155 | return SDValue(); |
Evan Cheng | bf188ae | 2011-06-15 01:12:31 +0000 | [diff] [blame] | 7156 | unsigned InvMask = cast<ConstantSDNode>(N->getOperand(2))->getZExtValue(); |
| 7157 | unsigned LSB = CountTrailingZeros_32(~InvMask); |
| 7158 | unsigned Width = (32 - CountLeadingZeros_32(~InvMask)) - LSB; |
| 7159 | unsigned Mask = (1 << Width)-1; |
Evan Cheng | 0c1aec1 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 7160 | unsigned Mask2 = N11C->getZExtValue(); |
Evan Cheng | bf188ae | 2011-06-15 01:12:31 +0000 | [diff] [blame] | 7161 | if ((Mask & (~Mask2)) == 0) |
Evan Cheng | 0c1aec1 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 7162 | return DCI.DAG.getNode(ARMISD::BFI, N->getDebugLoc(), N->getValueType(0), |
| 7163 | N->getOperand(0), N1.getOperand(0), |
| 7164 | N->getOperand(2)); |
| 7165 | } |
| 7166 | return SDValue(); |
| 7167 | } |
| 7168 | |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 7169 | /// PerformVMOVRRDCombine - Target-specific dag combine xforms for |
| 7170 | /// ARMISD::VMOVRRD. |
| 7171 | static SDValue PerformVMOVRRDCombine(SDNode *N, |
| 7172 | TargetLowering::DAGCombinerInfo &DCI) { |
| 7173 | // vmovrrd(vmovdrr x, y) -> x,y |
| 7174 | SDValue InDouble = N->getOperand(0); |
| 7175 | if (InDouble.getOpcode() == ARMISD::VMOVDRR) |
| 7176 | return DCI.CombineTo(N, InDouble.getOperand(0), InDouble.getOperand(1)); |
Cameron Zwarich | 4071a71 | 2011-04-02 02:40:43 +0000 | [diff] [blame] | 7177 | |
| 7178 | // vmovrrd(load f64) -> (load i32), (load i32) |
| 7179 | SDNode *InNode = InDouble.getNode(); |
| 7180 | if (ISD::isNormalLoad(InNode) && InNode->hasOneUse() && |
| 7181 | InNode->getValueType(0) == MVT::f64 && |
| 7182 | InNode->getOperand(1).getOpcode() == ISD::FrameIndex && |
| 7183 | !cast<LoadSDNode>(InNode)->isVolatile()) { |
| 7184 | // TODO: Should this be done for non-FrameIndex operands? |
| 7185 | LoadSDNode *LD = cast<LoadSDNode>(InNode); |
| 7186 | |
| 7187 | SelectionDAG &DAG = DCI.DAG; |
| 7188 | DebugLoc DL = LD->getDebugLoc(); |
| 7189 | SDValue BasePtr = LD->getBasePtr(); |
| 7190 | SDValue NewLD1 = DAG.getLoad(MVT::i32, DL, LD->getChain(), BasePtr, |
| 7191 | LD->getPointerInfo(), LD->isVolatile(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 7192 | LD->isNonTemporal(), LD->isInvariant(), |
| 7193 | LD->getAlignment()); |
Cameron Zwarich | 4071a71 | 2011-04-02 02:40:43 +0000 | [diff] [blame] | 7194 | |
| 7195 | SDValue OffsetPtr = DAG.getNode(ISD::ADD, DL, MVT::i32, BasePtr, |
| 7196 | DAG.getConstant(4, MVT::i32)); |
| 7197 | SDValue NewLD2 = DAG.getLoad(MVT::i32, DL, NewLD1.getValue(1), OffsetPtr, |
| 7198 | LD->getPointerInfo(), LD->isVolatile(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 7199 | LD->isNonTemporal(), LD->isInvariant(), |
Cameron Zwarich | 4071a71 | 2011-04-02 02:40:43 +0000 | [diff] [blame] | 7200 | std::min(4U, LD->getAlignment() / 2)); |
| 7201 | |
| 7202 | DAG.ReplaceAllUsesOfValueWith(SDValue(LD, 1), NewLD2.getValue(1)); |
| 7203 | SDValue Result = DCI.CombineTo(N, NewLD1, NewLD2); |
| 7204 | DCI.RemoveFromWorklist(LD); |
| 7205 | DAG.DeleteNode(LD); |
| 7206 | return Result; |
| 7207 | } |
| 7208 | |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 7209 | return SDValue(); |
| 7210 | } |
| 7211 | |
| 7212 | /// PerformVMOVDRRCombine - Target-specific dag combine xforms for |
| 7213 | /// ARMISD::VMOVDRR. This is also used for BUILD_VECTORs with 2 operands. |
| 7214 | static SDValue PerformVMOVDRRCombine(SDNode *N, SelectionDAG &DAG) { |
| 7215 | // N=vmovrrd(X); vmovdrr(N:0, N:1) -> bit_convert(X) |
| 7216 | SDValue Op0 = N->getOperand(0); |
| 7217 | SDValue Op1 = N->getOperand(1); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7218 | if (Op0.getOpcode() == ISD::BITCAST) |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 7219 | Op0 = Op0.getOperand(0); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7220 | if (Op1.getOpcode() == ISD::BITCAST) |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 7221 | Op1 = Op1.getOperand(0); |
| 7222 | if (Op0.getOpcode() == ARMISD::VMOVRRD && |
| 7223 | Op0.getNode() == Op1.getNode() && |
| 7224 | Op0.getResNo() == 0 && Op1.getResNo() == 1) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7225 | return DAG.getNode(ISD::BITCAST, N->getDebugLoc(), |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 7226 | N->getValueType(0), Op0.getOperand(0)); |
| 7227 | return SDValue(); |
| 7228 | } |
| 7229 | |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 7230 | /// PerformSTORECombine - Target-specific dag combine xforms for |
| 7231 | /// ISD::STORE. |
| 7232 | static SDValue PerformSTORECombine(SDNode *N, |
| 7233 | TargetLowering::DAGCombinerInfo &DCI) { |
| 7234 | // Bitcast an i64 store extracted from a vector to f64. |
| 7235 | // Otherwise, the i64 value will be legalized to a pair of i32 values. |
| 7236 | StoreSDNode *St = cast<StoreSDNode>(N); |
| 7237 | SDValue StVal = St->getValue(); |
Cameron Zwarich | d0aacbc | 2011-04-12 02:24:17 +0000 | [diff] [blame] | 7238 | if (!ISD::isNormalStore(St) || St->isVolatile()) |
| 7239 | return SDValue(); |
| 7240 | |
| 7241 | if (StVal.getNode()->getOpcode() == ARMISD::VMOVDRR && |
| 7242 | StVal.getNode()->hasOneUse() && !St->isVolatile()) { |
| 7243 | SelectionDAG &DAG = DCI.DAG; |
| 7244 | DebugLoc DL = St->getDebugLoc(); |
| 7245 | SDValue BasePtr = St->getBasePtr(); |
| 7246 | SDValue NewST1 = DAG.getStore(St->getChain(), DL, |
| 7247 | StVal.getNode()->getOperand(0), BasePtr, |
| 7248 | St->getPointerInfo(), St->isVolatile(), |
| 7249 | St->isNonTemporal(), St->getAlignment()); |
| 7250 | |
| 7251 | SDValue OffsetPtr = DAG.getNode(ISD::ADD, DL, MVT::i32, BasePtr, |
| 7252 | DAG.getConstant(4, MVT::i32)); |
| 7253 | return DAG.getStore(NewST1.getValue(0), DL, StVal.getNode()->getOperand(1), |
| 7254 | OffsetPtr, St->getPointerInfo(), St->isVolatile(), |
| 7255 | St->isNonTemporal(), |
| 7256 | std::min(4U, St->getAlignment() / 2)); |
| 7257 | } |
| 7258 | |
| 7259 | if (StVal.getValueType() != MVT::i64 || |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 7260 | StVal.getNode()->getOpcode() != ISD::EXTRACT_VECTOR_ELT) |
| 7261 | return SDValue(); |
| 7262 | |
| 7263 | SelectionDAG &DAG = DCI.DAG; |
| 7264 | DebugLoc dl = StVal.getDebugLoc(); |
| 7265 | SDValue IntVec = StVal.getOperand(0); |
| 7266 | EVT FloatVT = EVT::getVectorVT(*DAG.getContext(), MVT::f64, |
| 7267 | IntVec.getValueType().getVectorNumElements()); |
| 7268 | SDValue Vec = DAG.getNode(ISD::BITCAST, dl, FloatVT, IntVec); |
| 7269 | SDValue ExtElt = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, |
| 7270 | Vec, StVal.getOperand(1)); |
| 7271 | dl = N->getDebugLoc(); |
| 7272 | SDValue V = DAG.getNode(ISD::BITCAST, dl, MVT::i64, ExtElt); |
| 7273 | // Make the DAGCombiner fold the bitcasts. |
| 7274 | DCI.AddToWorklist(Vec.getNode()); |
| 7275 | DCI.AddToWorklist(ExtElt.getNode()); |
| 7276 | DCI.AddToWorklist(V.getNode()); |
| 7277 | return DAG.getStore(St->getChain(), dl, V, St->getBasePtr(), |
| 7278 | St->getPointerInfo(), St->isVolatile(), |
| 7279 | St->isNonTemporal(), St->getAlignment(), |
| 7280 | St->getTBAAInfo()); |
| 7281 | } |
| 7282 | |
| 7283 | /// hasNormalLoadOperand - Check if any of the operands of a BUILD_VECTOR node |
| 7284 | /// are normal, non-volatile loads. If so, it is profitable to bitcast an |
| 7285 | /// i64 vector to have f64 elements, since the value can then be loaded |
| 7286 | /// directly into a VFP register. |
| 7287 | static bool hasNormalLoadOperand(SDNode *N) { |
| 7288 | unsigned NumElts = N->getValueType(0).getVectorNumElements(); |
| 7289 | for (unsigned i = 0; i < NumElts; ++i) { |
| 7290 | SDNode *Elt = N->getOperand(i).getNode(); |
| 7291 | if (ISD::isNormalLoad(Elt) && !cast<LoadSDNode>(Elt)->isVolatile()) |
| 7292 | return true; |
| 7293 | } |
| 7294 | return false; |
| 7295 | } |
| 7296 | |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 7297 | /// PerformBUILD_VECTORCombine - Target-specific dag combine xforms for |
| 7298 | /// ISD::BUILD_VECTOR. |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 7299 | static SDValue PerformBUILD_VECTORCombine(SDNode *N, |
| 7300 | TargetLowering::DAGCombinerInfo &DCI){ |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 7301 | // build_vector(N=ARMISD::VMOVRRD(X), N:1) -> bit_convert(X): |
| 7302 | // VMOVRRD is introduced when legalizing i64 types. It forces the i64 value |
| 7303 | // into a pair of GPRs, which is fine when the value is used as a scalar, |
| 7304 | // 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] | 7305 | SelectionDAG &DAG = DCI.DAG; |
| 7306 | if (N->getNumOperands() == 2) { |
| 7307 | SDValue RV = PerformVMOVDRRCombine(N, DAG); |
| 7308 | if (RV.getNode()) |
| 7309 | return RV; |
| 7310 | } |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 7311 | |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 7312 | // Load i64 elements as f64 values so that type legalization does not split |
| 7313 | // them up into i32 values. |
| 7314 | EVT VT = N->getValueType(0); |
| 7315 | if (VT.getVectorElementType() != MVT::i64 || !hasNormalLoadOperand(N)) |
| 7316 | return SDValue(); |
| 7317 | DebugLoc dl = N->getDebugLoc(); |
| 7318 | SmallVector<SDValue, 8> Ops; |
| 7319 | unsigned NumElts = VT.getVectorNumElements(); |
| 7320 | for (unsigned i = 0; i < NumElts; ++i) { |
| 7321 | SDValue V = DAG.getNode(ISD::BITCAST, dl, MVT::f64, N->getOperand(i)); |
| 7322 | Ops.push_back(V); |
| 7323 | // Make the DAGCombiner fold the bitcast. |
| 7324 | DCI.AddToWorklist(V.getNode()); |
| 7325 | } |
| 7326 | EVT FloatVT = EVT::getVectorVT(*DAG.getContext(), MVT::f64, NumElts); |
| 7327 | SDValue BV = DAG.getNode(ISD::BUILD_VECTOR, dl, FloatVT, Ops.data(), NumElts); |
| 7328 | return DAG.getNode(ISD::BITCAST, dl, VT, BV); |
| 7329 | } |
| 7330 | |
| 7331 | /// PerformInsertEltCombine - Target-specific dag combine xforms for |
| 7332 | /// ISD::INSERT_VECTOR_ELT. |
| 7333 | static SDValue PerformInsertEltCombine(SDNode *N, |
| 7334 | TargetLowering::DAGCombinerInfo &DCI) { |
| 7335 | // Bitcast an i64 load inserted into a vector to f64. |
| 7336 | // Otherwise, the i64 value will be legalized to a pair of i32 values. |
| 7337 | EVT VT = N->getValueType(0); |
| 7338 | SDNode *Elt = N->getOperand(1).getNode(); |
| 7339 | if (VT.getVectorElementType() != MVT::i64 || |
| 7340 | !ISD::isNormalLoad(Elt) || cast<LoadSDNode>(Elt)->isVolatile()) |
| 7341 | return SDValue(); |
| 7342 | |
| 7343 | SelectionDAG &DAG = DCI.DAG; |
| 7344 | DebugLoc dl = N->getDebugLoc(); |
| 7345 | EVT FloatVT = EVT::getVectorVT(*DAG.getContext(), MVT::f64, |
| 7346 | VT.getVectorNumElements()); |
| 7347 | SDValue Vec = DAG.getNode(ISD::BITCAST, dl, FloatVT, N->getOperand(0)); |
| 7348 | SDValue V = DAG.getNode(ISD::BITCAST, dl, MVT::f64, N->getOperand(1)); |
| 7349 | // Make the DAGCombiner fold the bitcasts. |
| 7350 | DCI.AddToWorklist(Vec.getNode()); |
| 7351 | DCI.AddToWorklist(V.getNode()); |
| 7352 | SDValue InsElt = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, FloatVT, |
| 7353 | Vec, V, N->getOperand(2)); |
| 7354 | return DAG.getNode(ISD::BITCAST, dl, VT, InsElt); |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 7355 | } |
| 7356 | |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 7357 | /// PerformVECTOR_SHUFFLECombine - Target-specific dag combine xforms for |
| 7358 | /// ISD::VECTOR_SHUFFLE. |
| 7359 | static SDValue PerformVECTOR_SHUFFLECombine(SDNode *N, SelectionDAG &DAG) { |
| 7360 | // The LLVM shufflevector instruction does not require the shuffle mask |
| 7361 | // length to match the operand vector length, but ISD::VECTOR_SHUFFLE does |
| 7362 | // have that requirement. When translating to ISD::VECTOR_SHUFFLE, if the |
| 7363 | // operands do not match the mask length, they are extended by concatenating |
| 7364 | // them with undef vectors. That is probably the right thing for other |
| 7365 | // targets, but for NEON it is better to concatenate two double-register |
| 7366 | // size vector operands into a single quad-register size vector. Do that |
| 7367 | // transformation here: |
| 7368 | // shuffle(concat(v1, undef), concat(v2, undef)) -> |
| 7369 | // shuffle(concat(v1, v2), undef) |
| 7370 | SDValue Op0 = N->getOperand(0); |
| 7371 | SDValue Op1 = N->getOperand(1); |
| 7372 | if (Op0.getOpcode() != ISD::CONCAT_VECTORS || |
| 7373 | Op1.getOpcode() != ISD::CONCAT_VECTORS || |
| 7374 | Op0.getNumOperands() != 2 || |
| 7375 | Op1.getNumOperands() != 2) |
| 7376 | return SDValue(); |
| 7377 | SDValue Concat0Op1 = Op0.getOperand(1); |
| 7378 | SDValue Concat1Op1 = Op1.getOperand(1); |
| 7379 | if (Concat0Op1.getOpcode() != ISD::UNDEF || |
| 7380 | Concat1Op1.getOpcode() != ISD::UNDEF) |
| 7381 | return SDValue(); |
| 7382 | // Skip the transformation if any of the types are illegal. |
| 7383 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 7384 | EVT VT = N->getValueType(0); |
| 7385 | if (!TLI.isTypeLegal(VT) || |
| 7386 | !TLI.isTypeLegal(Concat0Op1.getValueType()) || |
| 7387 | !TLI.isTypeLegal(Concat1Op1.getValueType())) |
| 7388 | return SDValue(); |
| 7389 | |
| 7390 | SDValue NewConcat = DAG.getNode(ISD::CONCAT_VECTORS, N->getDebugLoc(), VT, |
| 7391 | Op0.getOperand(0), Op1.getOperand(0)); |
| 7392 | // Translate the shuffle mask. |
| 7393 | SmallVector<int, 16> NewMask; |
| 7394 | unsigned NumElts = VT.getVectorNumElements(); |
| 7395 | unsigned HalfElts = NumElts/2; |
| 7396 | ShuffleVectorSDNode *SVN = cast<ShuffleVectorSDNode>(N); |
| 7397 | for (unsigned n = 0; n < NumElts; ++n) { |
| 7398 | int MaskElt = SVN->getMaskElt(n); |
| 7399 | int NewElt = -1; |
Bob Wilson | 1fa9d30 | 2010-10-27 23:49:00 +0000 | [diff] [blame] | 7400 | if (MaskElt < (int)HalfElts) |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 7401 | NewElt = MaskElt; |
Bob Wilson | 1fa9d30 | 2010-10-27 23:49:00 +0000 | [diff] [blame] | 7402 | else if (MaskElt >= (int)NumElts && MaskElt < (int)(NumElts + HalfElts)) |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 7403 | NewElt = HalfElts + MaskElt - NumElts; |
| 7404 | NewMask.push_back(NewElt); |
| 7405 | } |
| 7406 | return DAG.getVectorShuffle(VT, N->getDebugLoc(), NewConcat, |
| 7407 | DAG.getUNDEF(VT), NewMask.data()); |
| 7408 | } |
| 7409 | |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 7410 | /// CombineBaseUpdate - Target-specific DAG combine function for VLDDUP and |
| 7411 | /// NEON load/store intrinsics to merge base address updates. |
| 7412 | static SDValue CombineBaseUpdate(SDNode *N, |
| 7413 | TargetLowering::DAGCombinerInfo &DCI) { |
| 7414 | if (DCI.isBeforeLegalize() || DCI.isCalledByLegalizer()) |
| 7415 | return SDValue(); |
| 7416 | |
| 7417 | SelectionDAG &DAG = DCI.DAG; |
| 7418 | bool isIntrinsic = (N->getOpcode() == ISD::INTRINSIC_VOID || |
| 7419 | N->getOpcode() == ISD::INTRINSIC_W_CHAIN); |
| 7420 | unsigned AddrOpIdx = (isIntrinsic ? 2 : 1); |
| 7421 | SDValue Addr = N->getOperand(AddrOpIdx); |
| 7422 | |
| 7423 | // Search for a use of the address operand that is an increment. |
| 7424 | for (SDNode::use_iterator UI = Addr.getNode()->use_begin(), |
| 7425 | UE = Addr.getNode()->use_end(); UI != UE; ++UI) { |
| 7426 | SDNode *User = *UI; |
| 7427 | if (User->getOpcode() != ISD::ADD || |
| 7428 | UI.getUse().getResNo() != Addr.getResNo()) |
| 7429 | continue; |
| 7430 | |
| 7431 | // Check that the add is independent of the load/store. Otherwise, folding |
| 7432 | // it would create a cycle. |
| 7433 | if (User->isPredecessorOf(N) || N->isPredecessorOf(User)) |
| 7434 | continue; |
| 7435 | |
| 7436 | // Find the new opcode for the updating load/store. |
| 7437 | bool isLoad = true; |
| 7438 | bool isLaneOp = false; |
| 7439 | unsigned NewOpc = 0; |
| 7440 | unsigned NumVecs = 0; |
| 7441 | if (isIntrinsic) { |
| 7442 | unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue(); |
| 7443 | switch (IntNo) { |
Craig Topper | bc21981 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 7444 | default: llvm_unreachable("unexpected intrinsic for Neon base update"); |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 7445 | case Intrinsic::arm_neon_vld1: NewOpc = ARMISD::VLD1_UPD; |
| 7446 | NumVecs = 1; break; |
| 7447 | case Intrinsic::arm_neon_vld2: NewOpc = ARMISD::VLD2_UPD; |
| 7448 | NumVecs = 2; break; |
| 7449 | case Intrinsic::arm_neon_vld3: NewOpc = ARMISD::VLD3_UPD; |
| 7450 | NumVecs = 3; break; |
| 7451 | case Intrinsic::arm_neon_vld4: NewOpc = ARMISD::VLD4_UPD; |
| 7452 | NumVecs = 4; break; |
| 7453 | case Intrinsic::arm_neon_vld2lane: NewOpc = ARMISD::VLD2LN_UPD; |
| 7454 | NumVecs = 2; isLaneOp = true; break; |
| 7455 | case Intrinsic::arm_neon_vld3lane: NewOpc = ARMISD::VLD3LN_UPD; |
| 7456 | NumVecs = 3; isLaneOp = true; break; |
| 7457 | case Intrinsic::arm_neon_vld4lane: NewOpc = ARMISD::VLD4LN_UPD; |
| 7458 | NumVecs = 4; isLaneOp = true; break; |
| 7459 | case Intrinsic::arm_neon_vst1: NewOpc = ARMISD::VST1_UPD; |
| 7460 | NumVecs = 1; isLoad = false; break; |
| 7461 | case Intrinsic::arm_neon_vst2: NewOpc = ARMISD::VST2_UPD; |
| 7462 | NumVecs = 2; isLoad = false; break; |
| 7463 | case Intrinsic::arm_neon_vst3: NewOpc = ARMISD::VST3_UPD; |
| 7464 | NumVecs = 3; isLoad = false; break; |
| 7465 | case Intrinsic::arm_neon_vst4: NewOpc = ARMISD::VST4_UPD; |
| 7466 | NumVecs = 4; isLoad = false; break; |
| 7467 | case Intrinsic::arm_neon_vst2lane: NewOpc = ARMISD::VST2LN_UPD; |
| 7468 | NumVecs = 2; isLoad = false; isLaneOp = true; break; |
| 7469 | case Intrinsic::arm_neon_vst3lane: NewOpc = ARMISD::VST3LN_UPD; |
| 7470 | NumVecs = 3; isLoad = false; isLaneOp = true; break; |
| 7471 | case Intrinsic::arm_neon_vst4lane: NewOpc = ARMISD::VST4LN_UPD; |
| 7472 | NumVecs = 4; isLoad = false; isLaneOp = true; break; |
| 7473 | } |
| 7474 | } else { |
| 7475 | isLaneOp = true; |
| 7476 | switch (N->getOpcode()) { |
Craig Topper | bc21981 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 7477 | default: llvm_unreachable("unexpected opcode for Neon base update"); |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 7478 | case ARMISD::VLD2DUP: NewOpc = ARMISD::VLD2DUP_UPD; NumVecs = 2; break; |
| 7479 | case ARMISD::VLD3DUP: NewOpc = ARMISD::VLD3DUP_UPD; NumVecs = 3; break; |
| 7480 | case ARMISD::VLD4DUP: NewOpc = ARMISD::VLD4DUP_UPD; NumVecs = 4; break; |
| 7481 | } |
| 7482 | } |
| 7483 | |
| 7484 | // Find the size of memory referenced by the load/store. |
| 7485 | EVT VecTy; |
| 7486 | if (isLoad) |
| 7487 | VecTy = N->getValueType(0); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 7488 | else |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 7489 | VecTy = N->getOperand(AddrOpIdx+1).getValueType(); |
| 7490 | unsigned NumBytes = NumVecs * VecTy.getSizeInBits() / 8; |
| 7491 | if (isLaneOp) |
| 7492 | NumBytes /= VecTy.getVectorNumElements(); |
| 7493 | |
| 7494 | // If the increment is a constant, it must match the memory ref size. |
| 7495 | SDValue Inc = User->getOperand(User->getOperand(0) == Addr ? 1 : 0); |
| 7496 | if (ConstantSDNode *CInc = dyn_cast<ConstantSDNode>(Inc.getNode())) { |
| 7497 | uint64_t IncVal = CInc->getZExtValue(); |
| 7498 | if (IncVal != NumBytes) |
| 7499 | continue; |
| 7500 | } else if (NumBytes >= 3 * 16) { |
| 7501 | // VLD3/4 and VST3/4 for 128-bit vectors are implemented with two |
| 7502 | // separate instructions that make it harder to use a non-constant update. |
| 7503 | continue; |
| 7504 | } |
| 7505 | |
| 7506 | // Create the new updating load/store node. |
| 7507 | EVT Tys[6]; |
| 7508 | unsigned NumResultVecs = (isLoad ? NumVecs : 0); |
| 7509 | unsigned n; |
| 7510 | for (n = 0; n < NumResultVecs; ++n) |
| 7511 | Tys[n] = VecTy; |
| 7512 | Tys[n++] = MVT::i32; |
| 7513 | Tys[n] = MVT::Other; |
| 7514 | SDVTList SDTys = DAG.getVTList(Tys, NumResultVecs+2); |
| 7515 | SmallVector<SDValue, 8> Ops; |
| 7516 | Ops.push_back(N->getOperand(0)); // incoming chain |
| 7517 | Ops.push_back(N->getOperand(AddrOpIdx)); |
| 7518 | Ops.push_back(Inc); |
| 7519 | for (unsigned i = AddrOpIdx + 1; i < N->getNumOperands(); ++i) { |
| 7520 | Ops.push_back(N->getOperand(i)); |
| 7521 | } |
| 7522 | MemIntrinsicSDNode *MemInt = cast<MemIntrinsicSDNode>(N); |
| 7523 | SDValue UpdN = DAG.getMemIntrinsicNode(NewOpc, N->getDebugLoc(), SDTys, |
| 7524 | Ops.data(), Ops.size(), |
| 7525 | MemInt->getMemoryVT(), |
| 7526 | MemInt->getMemOperand()); |
| 7527 | |
| 7528 | // Update the uses. |
| 7529 | std::vector<SDValue> NewResults; |
| 7530 | for (unsigned i = 0; i < NumResultVecs; ++i) { |
| 7531 | NewResults.push_back(SDValue(UpdN.getNode(), i)); |
| 7532 | } |
| 7533 | NewResults.push_back(SDValue(UpdN.getNode(), NumResultVecs+1)); // chain |
| 7534 | DCI.CombineTo(N, NewResults); |
| 7535 | DCI.CombineTo(User, SDValue(UpdN.getNode(), NumResultVecs)); |
| 7536 | |
| 7537 | break; |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 7538 | } |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 7539 | return SDValue(); |
| 7540 | } |
| 7541 | |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 7542 | /// CombineVLDDUP - For a VDUPLANE node N, check if its source operand is a |
| 7543 | /// vldN-lane (N > 1) intrinsic, and if all the other uses of that intrinsic |
| 7544 | /// are also VDUPLANEs. If so, combine them to a vldN-dup operation and |
| 7545 | /// return true. |
| 7546 | static bool CombineVLDDUP(SDNode *N, TargetLowering::DAGCombinerInfo &DCI) { |
| 7547 | SelectionDAG &DAG = DCI.DAG; |
| 7548 | EVT VT = N->getValueType(0); |
| 7549 | // vldN-dup instructions only support 64-bit vectors for N > 1. |
| 7550 | if (!VT.is64BitVector()) |
| 7551 | return false; |
| 7552 | |
| 7553 | // Check if the VDUPLANE operand is a vldN-dup intrinsic. |
| 7554 | SDNode *VLD = N->getOperand(0).getNode(); |
| 7555 | if (VLD->getOpcode() != ISD::INTRINSIC_W_CHAIN) |
| 7556 | return false; |
| 7557 | unsigned NumVecs = 0; |
| 7558 | unsigned NewOpc = 0; |
| 7559 | unsigned IntNo = cast<ConstantSDNode>(VLD->getOperand(1))->getZExtValue(); |
| 7560 | if (IntNo == Intrinsic::arm_neon_vld2lane) { |
| 7561 | NumVecs = 2; |
| 7562 | NewOpc = ARMISD::VLD2DUP; |
| 7563 | } else if (IntNo == Intrinsic::arm_neon_vld3lane) { |
| 7564 | NumVecs = 3; |
| 7565 | NewOpc = ARMISD::VLD3DUP; |
| 7566 | } else if (IntNo == Intrinsic::arm_neon_vld4lane) { |
| 7567 | NumVecs = 4; |
| 7568 | NewOpc = ARMISD::VLD4DUP; |
| 7569 | } else { |
| 7570 | return false; |
| 7571 | } |
| 7572 | |
| 7573 | // First check that all the vldN-lane uses are VDUPLANEs and that the lane |
| 7574 | // numbers match the load. |
| 7575 | unsigned VLDLaneNo = |
| 7576 | cast<ConstantSDNode>(VLD->getOperand(NumVecs+3))->getZExtValue(); |
| 7577 | for (SDNode::use_iterator UI = VLD->use_begin(), UE = VLD->use_end(); |
| 7578 | UI != UE; ++UI) { |
| 7579 | // Ignore uses of the chain result. |
| 7580 | if (UI.getUse().getResNo() == NumVecs) |
| 7581 | continue; |
| 7582 | SDNode *User = *UI; |
| 7583 | if (User->getOpcode() != ARMISD::VDUPLANE || |
| 7584 | VLDLaneNo != cast<ConstantSDNode>(User->getOperand(1))->getZExtValue()) |
| 7585 | return false; |
| 7586 | } |
| 7587 | |
| 7588 | // Create the vldN-dup node. |
| 7589 | EVT Tys[5]; |
| 7590 | unsigned n; |
| 7591 | for (n = 0; n < NumVecs; ++n) |
| 7592 | Tys[n] = VT; |
| 7593 | Tys[n] = MVT::Other; |
| 7594 | SDVTList SDTys = DAG.getVTList(Tys, NumVecs+1); |
| 7595 | SDValue Ops[] = { VLD->getOperand(0), VLD->getOperand(2) }; |
| 7596 | MemIntrinsicSDNode *VLDMemInt = cast<MemIntrinsicSDNode>(VLD); |
| 7597 | SDValue VLDDup = DAG.getMemIntrinsicNode(NewOpc, VLD->getDebugLoc(), SDTys, |
| 7598 | Ops, 2, VLDMemInt->getMemoryVT(), |
| 7599 | VLDMemInt->getMemOperand()); |
| 7600 | |
| 7601 | // Update the uses. |
| 7602 | for (SDNode::use_iterator UI = VLD->use_begin(), UE = VLD->use_end(); |
| 7603 | UI != UE; ++UI) { |
| 7604 | unsigned ResNo = UI.getUse().getResNo(); |
| 7605 | // Ignore uses of the chain result. |
| 7606 | if (ResNo == NumVecs) |
| 7607 | continue; |
| 7608 | SDNode *User = *UI; |
| 7609 | DCI.CombineTo(User, SDValue(VLDDup.getNode(), ResNo)); |
| 7610 | } |
| 7611 | |
| 7612 | // Now the vldN-lane intrinsic is dead except for its chain result. |
| 7613 | // Update uses of the chain. |
| 7614 | std::vector<SDValue> VLDDupResults; |
| 7615 | for (unsigned n = 0; n < NumVecs; ++n) |
| 7616 | VLDDupResults.push_back(SDValue(VLDDup.getNode(), n)); |
| 7617 | VLDDupResults.push_back(SDValue(VLDDup.getNode(), NumVecs)); |
| 7618 | DCI.CombineTo(VLD, VLDDupResults); |
| 7619 | |
| 7620 | return true; |
| 7621 | } |
| 7622 | |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 7623 | /// PerformVDUPLANECombine - Target-specific dag combine xforms for |
| 7624 | /// ARMISD::VDUPLANE. |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 7625 | static SDValue PerformVDUPLANECombine(SDNode *N, |
| 7626 | TargetLowering::DAGCombinerInfo &DCI) { |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 7627 | SDValue Op = N->getOperand(0); |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 7628 | |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 7629 | // If the source is a vldN-lane (N > 1) intrinsic, and all the other uses |
| 7630 | // of that intrinsic are also VDUPLANEs, combine them to a vldN-dup operation. |
| 7631 | if (CombineVLDDUP(N, DCI)) |
| 7632 | return SDValue(N, 0); |
| 7633 | |
| 7634 | // If the source is already a VMOVIMM or VMVNIMM splat, the VDUPLANE is |
| 7635 | // redundant. Ignore bit_converts for now; element sizes are checked below. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7636 | while (Op.getOpcode() == ISD::BITCAST) |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 7637 | Op = Op.getOperand(0); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 7638 | if (Op.getOpcode() != ARMISD::VMOVIMM && Op.getOpcode() != ARMISD::VMVNIMM) |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 7639 | return SDValue(); |
| 7640 | |
| 7641 | // Make sure the VMOV element size is not bigger than the VDUPLANE elements. |
| 7642 | unsigned EltSize = Op.getValueType().getVectorElementType().getSizeInBits(); |
| 7643 | // The canonical VMOV for a zero vector uses a 32-bit element size. |
| 7644 | unsigned Imm = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
| 7645 | unsigned EltBits; |
| 7646 | if (ARM_AM::decodeNEONModImm(Imm, EltBits) == 0) |
| 7647 | EltSize = 8; |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 7648 | EVT VT = N->getValueType(0); |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 7649 | if (EltSize > VT.getVectorElementType().getSizeInBits()) |
| 7650 | return SDValue(); |
| 7651 | |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 7652 | return DCI.DAG.getNode(ISD::BITCAST, N->getDebugLoc(), VT, Op); |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 7653 | } |
| 7654 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7655 | // 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] | 7656 | // elements are the same constant, C, and Log2(C) ranges from 1 to 32. |
| 7657 | static bool isConstVecPow2(SDValue ConstVec, bool isSigned, uint64_t &C) |
| 7658 | { |
Chad Rosier | 118c9a0 | 2011-06-28 17:26:57 +0000 | [diff] [blame] | 7659 | integerPart cN; |
| 7660 | integerPart c0 = 0; |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 7661 | for (unsigned I = 0, E = ConstVec.getValueType().getVectorNumElements(); |
| 7662 | I != E; I++) { |
| 7663 | ConstantFPSDNode *C = dyn_cast<ConstantFPSDNode>(ConstVec.getOperand(I)); |
| 7664 | if (!C) |
| 7665 | return false; |
| 7666 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7667 | bool isExact; |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 7668 | APFloat APF = C->getValueAPF(); |
| 7669 | if (APF.convertToInteger(&cN, 64, isSigned, APFloat::rmTowardZero, &isExact) |
| 7670 | != APFloat::opOK || !isExact) |
| 7671 | return false; |
| 7672 | |
| 7673 | c0 = (I == 0) ? cN : c0; |
| 7674 | if (!isPowerOf2_64(cN) || c0 != cN || Log2_64(c0) < 1 || Log2_64(c0) > 32) |
| 7675 | return false; |
| 7676 | } |
| 7677 | C = c0; |
| 7678 | return true; |
| 7679 | } |
| 7680 | |
| 7681 | /// PerformVCVTCombine - VCVT (floating-point to fixed-point, Advanced SIMD) |
| 7682 | /// can replace combinations of VMUL and VCVT (floating-point to integer) |
| 7683 | /// when the VMUL has a constant operand that is a power of 2. |
| 7684 | /// |
| 7685 | /// Example (assume d17 = <float 8.000000e+00, float 8.000000e+00>): |
| 7686 | /// vmul.f32 d16, d17, d16 |
| 7687 | /// vcvt.s32.f32 d16, d16 |
| 7688 | /// becomes: |
| 7689 | /// vcvt.s32.f32 d16, d16, #3 |
| 7690 | static SDValue PerformVCVTCombine(SDNode *N, |
| 7691 | TargetLowering::DAGCombinerInfo &DCI, |
| 7692 | const ARMSubtarget *Subtarget) { |
| 7693 | SelectionDAG &DAG = DCI.DAG; |
| 7694 | SDValue Op = N->getOperand(0); |
| 7695 | |
| 7696 | if (!Subtarget->hasNEON() || !Op.getValueType().isVector() || |
| 7697 | Op.getOpcode() != ISD::FMUL) |
| 7698 | return SDValue(); |
| 7699 | |
| 7700 | uint64_t C; |
| 7701 | SDValue N0 = Op->getOperand(0); |
| 7702 | SDValue ConstVec = Op->getOperand(1); |
| 7703 | bool isSigned = N->getOpcode() == ISD::FP_TO_SINT; |
| 7704 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7705 | if (ConstVec.getOpcode() != ISD::BUILD_VECTOR || |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 7706 | !isConstVecPow2(ConstVec, isSigned, C)) |
| 7707 | return SDValue(); |
| 7708 | |
| 7709 | unsigned IntrinsicOpcode = isSigned ? Intrinsic::arm_neon_vcvtfp2fxs : |
| 7710 | Intrinsic::arm_neon_vcvtfp2fxu; |
| 7711 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, N->getDebugLoc(), |
| 7712 | N->getValueType(0), |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7713 | DAG.getConstant(IntrinsicOpcode, MVT::i32), N0, |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 7714 | DAG.getConstant(Log2_64(C), MVT::i32)); |
| 7715 | } |
| 7716 | |
| 7717 | /// PerformVDIVCombine - VCVT (fixed-point to floating-point, Advanced SIMD) |
| 7718 | /// can replace combinations of VCVT (integer to floating-point) and VDIV |
| 7719 | /// when the VDIV has a constant operand that is a power of 2. |
| 7720 | /// |
| 7721 | /// Example (assume d17 = <float 8.000000e+00, float 8.000000e+00>): |
| 7722 | /// vcvt.f32.s32 d16, d16 |
| 7723 | /// vdiv.f32 d16, d17, d16 |
| 7724 | /// becomes: |
| 7725 | /// vcvt.f32.s32 d16, d16, #3 |
| 7726 | static SDValue PerformVDIVCombine(SDNode *N, |
| 7727 | TargetLowering::DAGCombinerInfo &DCI, |
| 7728 | const ARMSubtarget *Subtarget) { |
| 7729 | SelectionDAG &DAG = DCI.DAG; |
| 7730 | SDValue Op = N->getOperand(0); |
| 7731 | unsigned OpOpcode = Op.getNode()->getOpcode(); |
| 7732 | |
| 7733 | if (!Subtarget->hasNEON() || !N->getValueType(0).isVector() || |
| 7734 | (OpOpcode != ISD::SINT_TO_FP && OpOpcode != ISD::UINT_TO_FP)) |
| 7735 | return SDValue(); |
| 7736 | |
| 7737 | uint64_t C; |
| 7738 | SDValue ConstVec = N->getOperand(1); |
| 7739 | bool isSigned = OpOpcode == ISD::SINT_TO_FP; |
| 7740 | |
| 7741 | if (ConstVec.getOpcode() != ISD::BUILD_VECTOR || |
| 7742 | !isConstVecPow2(ConstVec, isSigned, C)) |
| 7743 | return SDValue(); |
| 7744 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7745 | unsigned IntrinsicOpcode = isSigned ? Intrinsic::arm_neon_vcvtfxs2fp : |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 7746 | Intrinsic::arm_neon_vcvtfxu2fp; |
| 7747 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, N->getDebugLoc(), |
| 7748 | Op.getValueType(), |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7749 | DAG.getConstant(IntrinsicOpcode, MVT::i32), |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 7750 | Op.getOperand(0), DAG.getConstant(Log2_64(C), MVT::i32)); |
| 7751 | } |
| 7752 | |
| 7753 | /// Getvshiftimm - Check if this is a valid build_vector for the immediate |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7754 | /// operand of a vector shift operation, where all the elements of the |
| 7755 | /// build_vector must have the same constant integer value. |
| 7756 | static bool getVShiftImm(SDValue Op, unsigned ElementBits, int64_t &Cnt) { |
| 7757 | // Ignore bit_converts. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7758 | while (Op.getOpcode() == ISD::BITCAST) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7759 | Op = Op.getOperand(0); |
| 7760 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(Op.getNode()); |
| 7761 | APInt SplatBits, SplatUndef; |
| 7762 | unsigned SplatBitSize; |
| 7763 | bool HasAnyUndefs; |
| 7764 | if (! BVN || ! BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, |
| 7765 | HasAnyUndefs, ElementBits) || |
| 7766 | SplatBitSize > ElementBits) |
| 7767 | return false; |
| 7768 | Cnt = SplatBits.getSExtValue(); |
| 7769 | return true; |
| 7770 | } |
| 7771 | |
| 7772 | /// isVShiftLImm - Check if this is a valid build_vector for the immediate |
| 7773 | /// operand of a vector shift left operation. That value must be in the range: |
| 7774 | /// 0 <= Value < ElementBits for a left shift; or |
| 7775 | /// 0 <= Value <= ElementBits for a long left shift. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 7776 | static bool isVShiftLImm(SDValue Op, EVT VT, bool isLong, int64_t &Cnt) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7777 | assert(VT.isVector() && "vector shift count is not a vector type"); |
| 7778 | unsigned ElementBits = VT.getVectorElementType().getSizeInBits(); |
| 7779 | if (! getVShiftImm(Op, ElementBits, Cnt)) |
| 7780 | return false; |
| 7781 | return (Cnt >= 0 && (isLong ? Cnt-1 : Cnt) < ElementBits); |
| 7782 | } |
| 7783 | |
| 7784 | /// isVShiftRImm - Check if this is a valid build_vector for the immediate |
| 7785 | /// operand of a vector shift right operation. For a shift opcode, the value |
| 7786 | /// is positive, but for an intrinsic the value count must be negative. The |
| 7787 | /// absolute value must be in the range: |
| 7788 | /// 1 <= |Value| <= ElementBits for a right shift; or |
| 7789 | /// 1 <= |Value| <= ElementBits/2 for a narrow right shift. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 7790 | static bool isVShiftRImm(SDValue Op, EVT VT, bool isNarrow, bool isIntrinsic, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7791 | int64_t &Cnt) { |
| 7792 | assert(VT.isVector() && "vector shift count is not a vector type"); |
| 7793 | unsigned ElementBits = VT.getVectorElementType().getSizeInBits(); |
| 7794 | if (! getVShiftImm(Op, ElementBits, Cnt)) |
| 7795 | return false; |
| 7796 | if (isIntrinsic) |
| 7797 | Cnt = -Cnt; |
| 7798 | return (Cnt >= 1 && Cnt <= (isNarrow ? ElementBits/2 : ElementBits)); |
| 7799 | } |
| 7800 | |
| 7801 | /// PerformIntrinsicCombine - ARM-specific DAG combining for intrinsics. |
| 7802 | static SDValue PerformIntrinsicCombine(SDNode *N, SelectionDAG &DAG) { |
| 7803 | unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue(); |
| 7804 | switch (IntNo) { |
| 7805 | default: |
| 7806 | // Don't do anything for most intrinsics. |
| 7807 | break; |
| 7808 | |
| 7809 | // Vector shifts: check for immediate versions and lower them. |
| 7810 | // Note: This is done during DAG combining instead of DAG legalizing because |
| 7811 | // the build_vectors for 64-bit vector element shift counts are generally |
| 7812 | // not legal, and it is hard to see their values after they get legalized to |
| 7813 | // loads from a constant pool. |
| 7814 | case Intrinsic::arm_neon_vshifts: |
| 7815 | case Intrinsic::arm_neon_vshiftu: |
| 7816 | case Intrinsic::arm_neon_vshiftls: |
| 7817 | case Intrinsic::arm_neon_vshiftlu: |
| 7818 | case Intrinsic::arm_neon_vshiftn: |
| 7819 | case Intrinsic::arm_neon_vrshifts: |
| 7820 | case Intrinsic::arm_neon_vrshiftu: |
| 7821 | case Intrinsic::arm_neon_vrshiftn: |
| 7822 | case Intrinsic::arm_neon_vqshifts: |
| 7823 | case Intrinsic::arm_neon_vqshiftu: |
| 7824 | case Intrinsic::arm_neon_vqshiftsu: |
| 7825 | case Intrinsic::arm_neon_vqshiftns: |
| 7826 | case Intrinsic::arm_neon_vqshiftnu: |
| 7827 | case Intrinsic::arm_neon_vqshiftnsu: |
| 7828 | case Intrinsic::arm_neon_vqrshiftns: |
| 7829 | case Intrinsic::arm_neon_vqrshiftnu: |
| 7830 | case Intrinsic::arm_neon_vqrshiftnsu: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 7831 | EVT VT = N->getOperand(1).getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7832 | int64_t Cnt; |
| 7833 | unsigned VShiftOpc = 0; |
| 7834 | |
| 7835 | switch (IntNo) { |
| 7836 | case Intrinsic::arm_neon_vshifts: |
| 7837 | case Intrinsic::arm_neon_vshiftu: |
| 7838 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) { |
| 7839 | VShiftOpc = ARMISD::VSHL; |
| 7840 | break; |
| 7841 | } |
| 7842 | if (isVShiftRImm(N->getOperand(2), VT, false, true, Cnt)) { |
| 7843 | VShiftOpc = (IntNo == Intrinsic::arm_neon_vshifts ? |
| 7844 | ARMISD::VSHRs : ARMISD::VSHRu); |
| 7845 | break; |
| 7846 | } |
| 7847 | return SDValue(); |
| 7848 | |
| 7849 | case Intrinsic::arm_neon_vshiftls: |
| 7850 | case Intrinsic::arm_neon_vshiftlu: |
| 7851 | if (isVShiftLImm(N->getOperand(2), VT, true, Cnt)) |
| 7852 | break; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 7853 | llvm_unreachable("invalid shift count for vshll intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7854 | |
| 7855 | case Intrinsic::arm_neon_vrshifts: |
| 7856 | case Intrinsic::arm_neon_vrshiftu: |
| 7857 | if (isVShiftRImm(N->getOperand(2), VT, false, true, Cnt)) |
| 7858 | break; |
| 7859 | return SDValue(); |
| 7860 | |
| 7861 | case Intrinsic::arm_neon_vqshifts: |
| 7862 | case Intrinsic::arm_neon_vqshiftu: |
| 7863 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) |
| 7864 | break; |
| 7865 | return SDValue(); |
| 7866 | |
| 7867 | case Intrinsic::arm_neon_vqshiftsu: |
| 7868 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) |
| 7869 | break; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 7870 | llvm_unreachable("invalid shift count for vqshlu intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7871 | |
| 7872 | case Intrinsic::arm_neon_vshiftn: |
| 7873 | case Intrinsic::arm_neon_vrshiftn: |
| 7874 | case Intrinsic::arm_neon_vqshiftns: |
| 7875 | case Intrinsic::arm_neon_vqshiftnu: |
| 7876 | case Intrinsic::arm_neon_vqshiftnsu: |
| 7877 | case Intrinsic::arm_neon_vqrshiftns: |
| 7878 | case Intrinsic::arm_neon_vqrshiftnu: |
| 7879 | case Intrinsic::arm_neon_vqrshiftnsu: |
| 7880 | // Narrowing shifts require an immediate right shift. |
| 7881 | if (isVShiftRImm(N->getOperand(2), VT, true, true, Cnt)) |
| 7882 | break; |
Jim Grosbach | 18f30e6 | 2010-06-02 21:53:11 +0000 | [diff] [blame] | 7883 | llvm_unreachable("invalid shift count for narrowing vector shift " |
| 7884 | "intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7885 | |
| 7886 | default: |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 7887 | llvm_unreachable("unhandled vector shift"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7888 | } |
| 7889 | |
| 7890 | switch (IntNo) { |
| 7891 | case Intrinsic::arm_neon_vshifts: |
| 7892 | case Intrinsic::arm_neon_vshiftu: |
| 7893 | // Opcode already set above. |
| 7894 | break; |
| 7895 | case Intrinsic::arm_neon_vshiftls: |
| 7896 | case Intrinsic::arm_neon_vshiftlu: |
| 7897 | if (Cnt == VT.getVectorElementType().getSizeInBits()) |
| 7898 | VShiftOpc = ARMISD::VSHLLi; |
| 7899 | else |
| 7900 | VShiftOpc = (IntNo == Intrinsic::arm_neon_vshiftls ? |
| 7901 | ARMISD::VSHLLs : ARMISD::VSHLLu); |
| 7902 | break; |
| 7903 | case Intrinsic::arm_neon_vshiftn: |
| 7904 | VShiftOpc = ARMISD::VSHRN; break; |
| 7905 | case Intrinsic::arm_neon_vrshifts: |
| 7906 | VShiftOpc = ARMISD::VRSHRs; break; |
| 7907 | case Intrinsic::arm_neon_vrshiftu: |
| 7908 | VShiftOpc = ARMISD::VRSHRu; break; |
| 7909 | case Intrinsic::arm_neon_vrshiftn: |
| 7910 | VShiftOpc = ARMISD::VRSHRN; break; |
| 7911 | case Intrinsic::arm_neon_vqshifts: |
| 7912 | VShiftOpc = ARMISD::VQSHLs; break; |
| 7913 | case Intrinsic::arm_neon_vqshiftu: |
| 7914 | VShiftOpc = ARMISD::VQSHLu; break; |
| 7915 | case Intrinsic::arm_neon_vqshiftsu: |
| 7916 | VShiftOpc = ARMISD::VQSHLsu; break; |
| 7917 | case Intrinsic::arm_neon_vqshiftns: |
| 7918 | VShiftOpc = ARMISD::VQSHRNs; break; |
| 7919 | case Intrinsic::arm_neon_vqshiftnu: |
| 7920 | VShiftOpc = ARMISD::VQSHRNu; break; |
| 7921 | case Intrinsic::arm_neon_vqshiftnsu: |
| 7922 | VShiftOpc = ARMISD::VQSHRNsu; break; |
| 7923 | case Intrinsic::arm_neon_vqrshiftns: |
| 7924 | VShiftOpc = ARMISD::VQRSHRNs; break; |
| 7925 | case Intrinsic::arm_neon_vqrshiftnu: |
| 7926 | VShiftOpc = ARMISD::VQRSHRNu; break; |
| 7927 | case Intrinsic::arm_neon_vqrshiftnsu: |
| 7928 | VShiftOpc = ARMISD::VQRSHRNsu; break; |
| 7929 | } |
| 7930 | |
| 7931 | return DAG.getNode(VShiftOpc, N->getDebugLoc(), N->getValueType(0), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 7932 | N->getOperand(1), DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7933 | } |
| 7934 | |
| 7935 | case Intrinsic::arm_neon_vshiftins: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 7936 | EVT VT = N->getOperand(1).getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7937 | int64_t Cnt; |
| 7938 | unsigned VShiftOpc = 0; |
| 7939 | |
| 7940 | if (isVShiftLImm(N->getOperand(3), VT, false, Cnt)) |
| 7941 | VShiftOpc = ARMISD::VSLI; |
| 7942 | else if (isVShiftRImm(N->getOperand(3), VT, false, true, Cnt)) |
| 7943 | VShiftOpc = ARMISD::VSRI; |
| 7944 | else { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 7945 | llvm_unreachable("invalid shift count for vsli/vsri intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7946 | } |
| 7947 | |
| 7948 | return DAG.getNode(VShiftOpc, N->getDebugLoc(), N->getValueType(0), |
| 7949 | N->getOperand(1), N->getOperand(2), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 7950 | DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7951 | } |
| 7952 | |
| 7953 | case Intrinsic::arm_neon_vqrshifts: |
| 7954 | case Intrinsic::arm_neon_vqrshiftu: |
| 7955 | // No immediate versions of these to check for. |
| 7956 | break; |
| 7957 | } |
| 7958 | |
| 7959 | return SDValue(); |
| 7960 | } |
| 7961 | |
| 7962 | /// PerformShiftCombine - Checks for immediate versions of vector shifts and |
| 7963 | /// lowers them. As with the vector shift intrinsics, this is done during DAG |
| 7964 | /// combining instead of DAG legalizing because the build_vectors for 64-bit |
| 7965 | /// vector element shift counts are generally not legal, and it is hard to see |
| 7966 | /// their values after they get legalized to loads from a constant pool. |
| 7967 | static SDValue PerformShiftCombine(SDNode *N, SelectionDAG &DAG, |
| 7968 | const ARMSubtarget *ST) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 7969 | EVT VT = N->getValueType(0); |
Evan Cheng | 5fb468a | 2012-02-23 02:58:19 +0000 | [diff] [blame^] | 7970 | if (N->getOpcode() == ISD::SRL && VT == MVT::i32 && ST->hasV6Ops()) { |
| 7971 | // Canonicalize (srl (bswap x), 16) to (rotr (bswap x), 16) if the high |
| 7972 | // 16-bits of x is zero. This optimizes rev + lsr 16 to rev16. |
| 7973 | SDValue N1 = N->getOperand(1); |
| 7974 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N1)) { |
| 7975 | SDValue N0 = N->getOperand(0); |
| 7976 | if (C->getZExtValue() == 16 && N0.getOpcode() == ISD::BSWAP && |
| 7977 | DAG.MaskedValueIsZero(N0.getOperand(0), |
| 7978 | APInt::getHighBitsSet(32, 16))) |
| 7979 | return DAG.getNode(ISD::ROTR, N->getDebugLoc(), VT, N0, N1); |
| 7980 | } |
| 7981 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7982 | |
| 7983 | // Nothing to be done for scalar shifts. |
Tanya Lattner | 9684a7c | 2010-11-18 22:06:46 +0000 | [diff] [blame] | 7984 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 7985 | if (!VT.isVector() || !TLI.isTypeLegal(VT)) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7986 | return SDValue(); |
| 7987 | |
| 7988 | assert(ST->hasNEON() && "unexpected vector shift"); |
| 7989 | int64_t Cnt; |
| 7990 | |
| 7991 | switch (N->getOpcode()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 7992 | default: llvm_unreachable("unexpected shift opcode"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7993 | |
| 7994 | case ISD::SHL: |
| 7995 | if (isVShiftLImm(N->getOperand(1), VT, false, Cnt)) |
| 7996 | return DAG.getNode(ARMISD::VSHL, N->getDebugLoc(), VT, N->getOperand(0), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 7997 | DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7998 | break; |
| 7999 | |
| 8000 | case ISD::SRA: |
| 8001 | case ISD::SRL: |
| 8002 | if (isVShiftRImm(N->getOperand(1), VT, false, false, Cnt)) { |
| 8003 | unsigned VShiftOpc = (N->getOpcode() == ISD::SRA ? |
| 8004 | ARMISD::VSHRs : ARMISD::VSHRu); |
| 8005 | return DAG.getNode(VShiftOpc, N->getDebugLoc(), VT, N->getOperand(0), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8006 | DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8007 | } |
| 8008 | } |
| 8009 | return SDValue(); |
| 8010 | } |
| 8011 | |
| 8012 | /// PerformExtendCombine - Target-specific DAG combining for ISD::SIGN_EXTEND, |
| 8013 | /// ISD::ZERO_EXTEND, and ISD::ANY_EXTEND. |
| 8014 | static SDValue PerformExtendCombine(SDNode *N, SelectionDAG &DAG, |
| 8015 | const ARMSubtarget *ST) { |
| 8016 | SDValue N0 = N->getOperand(0); |
| 8017 | |
| 8018 | // Check for sign- and zero-extensions of vector extract operations of 8- |
| 8019 | // and 16-bit vector elements. NEON supports these directly. They are |
| 8020 | // handled during DAG combining because type legalization will promote them |
| 8021 | // to 32-bit types and it is messy to recognize the operations after that. |
| 8022 | if (ST->hasNEON() && N0.getOpcode() == ISD::EXTRACT_VECTOR_ELT) { |
| 8023 | SDValue Vec = N0.getOperand(0); |
| 8024 | SDValue Lane = N0.getOperand(1); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8025 | EVT VT = N->getValueType(0); |
| 8026 | EVT EltVT = N0.getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8027 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 8028 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8029 | if (VT == MVT::i32 && |
| 8030 | (EltVT == MVT::i8 || EltVT == MVT::i16) && |
Bob Wilson | 3468c2e | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 8031 | TLI.isTypeLegal(Vec.getValueType()) && |
| 8032 | isa<ConstantSDNode>(Lane)) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8033 | |
| 8034 | unsigned Opc = 0; |
| 8035 | switch (N->getOpcode()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 8036 | default: llvm_unreachable("unexpected opcode"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8037 | case ISD::SIGN_EXTEND: |
| 8038 | Opc = ARMISD::VGETLANEs; |
| 8039 | break; |
| 8040 | case ISD::ZERO_EXTEND: |
| 8041 | case ISD::ANY_EXTEND: |
| 8042 | Opc = ARMISD::VGETLANEu; |
| 8043 | break; |
| 8044 | } |
| 8045 | return DAG.getNode(Opc, N->getDebugLoc(), VT, Vec, Lane); |
| 8046 | } |
| 8047 | } |
| 8048 | |
| 8049 | return SDValue(); |
| 8050 | } |
| 8051 | |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8052 | /// PerformSELECT_CCCombine - Target-specific DAG combining for ISD::SELECT_CC |
| 8053 | /// to match f32 max/min patterns to use NEON vmax/vmin instructions. |
| 8054 | static SDValue PerformSELECT_CCCombine(SDNode *N, SelectionDAG &DAG, |
| 8055 | const ARMSubtarget *ST) { |
| 8056 | // 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] | 8057 | // selects like "x < y ? x : y". Unless the NoNaNsFPMath option is set, |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8058 | // be careful about NaNs: NEON's vmax/vmin return NaN if either operand is |
| 8059 | // a NaN; only do the transformation when it matches that behavior. |
| 8060 | |
| 8061 | // For now only do this when using NEON for FP operations; if using VFP, it |
| 8062 | // is not obvious that the benefit outweighs the cost of switching to the |
| 8063 | // NEON pipeline. |
| 8064 | if (!ST->hasNEON() || !ST->useNEONForSinglePrecisionFP() || |
| 8065 | N->getValueType(0) != MVT::f32) |
| 8066 | return SDValue(); |
| 8067 | |
| 8068 | SDValue CondLHS = N->getOperand(0); |
| 8069 | SDValue CondRHS = N->getOperand(1); |
| 8070 | SDValue LHS = N->getOperand(2); |
| 8071 | SDValue RHS = N->getOperand(3); |
| 8072 | ISD::CondCode CC = cast<CondCodeSDNode>(N->getOperand(4))->get(); |
| 8073 | |
| 8074 | unsigned Opcode = 0; |
| 8075 | bool IsReversed; |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 8076 | if (DAG.isEqualTo(LHS, CondLHS) && DAG.isEqualTo(RHS, CondRHS)) { |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8077 | IsReversed = false; // x CC y ? x : y |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 8078 | } else if (DAG.isEqualTo(LHS, CondRHS) && DAG.isEqualTo(RHS, CondLHS)) { |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8079 | IsReversed = true ; // x CC y ? y : x |
| 8080 | } else { |
| 8081 | return SDValue(); |
| 8082 | } |
| 8083 | |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 8084 | bool IsUnordered; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8085 | switch (CC) { |
| 8086 | default: break; |
| 8087 | case ISD::SETOLT: |
| 8088 | case ISD::SETOLE: |
| 8089 | case ISD::SETLT: |
| 8090 | case ISD::SETLE: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8091 | case ISD::SETULT: |
| 8092 | case ISD::SETULE: |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 8093 | // If LHS is NaN, an ordered comparison will be false and the result will |
| 8094 | // be the RHS, but vmin(NaN, RHS) = NaN. Avoid this by checking that LHS |
| 8095 | // != NaN. Likewise, for unordered comparisons, check for RHS != NaN. |
| 8096 | IsUnordered = (CC == ISD::SETULT || CC == ISD::SETULE); |
| 8097 | if (!DAG.isKnownNeverNaN(IsUnordered ? RHS : LHS)) |
| 8098 | break; |
| 8099 | // For less-than-or-equal comparisons, "+0 <= -0" will be true but vmin |
| 8100 | // will return -0, so vmin can only be used for unsafe math or if one of |
| 8101 | // the operands is known to be nonzero. |
| 8102 | if ((CC == ISD::SETLE || CC == ISD::SETOLE || CC == ISD::SETULE) && |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 8103 | !DAG.getTarget().Options.UnsafeFPMath && |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 8104 | !(DAG.isKnownNeverZero(LHS) || DAG.isKnownNeverZero(RHS))) |
| 8105 | break; |
| 8106 | Opcode = IsReversed ? ARMISD::FMAX : ARMISD::FMIN; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8107 | break; |
| 8108 | |
| 8109 | case ISD::SETOGT: |
| 8110 | case ISD::SETOGE: |
| 8111 | case ISD::SETGT: |
| 8112 | case ISD::SETGE: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8113 | case ISD::SETUGT: |
| 8114 | case ISD::SETUGE: |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 8115 | // If LHS is NaN, an ordered comparison will be false and the result will |
| 8116 | // be the RHS, but vmax(NaN, RHS) = NaN. Avoid this by checking that LHS |
| 8117 | // != NaN. Likewise, for unordered comparisons, check for RHS != NaN. |
| 8118 | IsUnordered = (CC == ISD::SETUGT || CC == ISD::SETUGE); |
| 8119 | if (!DAG.isKnownNeverNaN(IsUnordered ? RHS : LHS)) |
| 8120 | break; |
| 8121 | // For greater-than-or-equal comparisons, "-0 >= +0" will be true but vmax |
| 8122 | // will return +0, so vmax can only be used for unsafe math or if one of |
| 8123 | // the operands is known to be nonzero. |
| 8124 | if ((CC == ISD::SETGE || CC == ISD::SETOGE || CC == ISD::SETUGE) && |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 8125 | !DAG.getTarget().Options.UnsafeFPMath && |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 8126 | !(DAG.isKnownNeverZero(LHS) || DAG.isKnownNeverZero(RHS))) |
| 8127 | break; |
| 8128 | Opcode = IsReversed ? ARMISD::FMIN : ARMISD::FMAX; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8129 | break; |
| 8130 | } |
| 8131 | |
| 8132 | if (!Opcode) |
| 8133 | return SDValue(); |
| 8134 | return DAG.getNode(Opcode, N->getDebugLoc(), N->getValueType(0), LHS, RHS); |
| 8135 | } |
| 8136 | |
Evan Cheng | e721f5c | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 8137 | /// PerformCMOVCombine - Target-specific DAG combining for ARMISD::CMOV. |
| 8138 | SDValue |
| 8139 | ARMTargetLowering::PerformCMOVCombine(SDNode *N, SelectionDAG &DAG) const { |
| 8140 | SDValue Cmp = N->getOperand(4); |
| 8141 | if (Cmp.getOpcode() != ARMISD::CMPZ) |
| 8142 | // Only looking at EQ and NE cases. |
| 8143 | return SDValue(); |
| 8144 | |
| 8145 | EVT VT = N->getValueType(0); |
| 8146 | DebugLoc dl = N->getDebugLoc(); |
| 8147 | SDValue LHS = Cmp.getOperand(0); |
| 8148 | SDValue RHS = Cmp.getOperand(1); |
| 8149 | SDValue FalseVal = N->getOperand(0); |
| 8150 | SDValue TrueVal = N->getOperand(1); |
| 8151 | SDValue ARMcc = N->getOperand(2); |
Jim Grosbach | b04546f | 2011-09-13 20:30:37 +0000 | [diff] [blame] | 8152 | ARMCC::CondCodes CC = |
| 8153 | (ARMCC::CondCodes)cast<ConstantSDNode>(ARMcc)->getZExtValue(); |
Evan Cheng | e721f5c | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 8154 | |
| 8155 | // Simplify |
| 8156 | // mov r1, r0 |
| 8157 | // cmp r1, x |
| 8158 | // mov r0, y |
| 8159 | // moveq r0, x |
| 8160 | // to |
| 8161 | // cmp r0, x |
| 8162 | // movne r0, y |
| 8163 | // |
| 8164 | // mov r1, r0 |
| 8165 | // cmp r1, x |
| 8166 | // mov r0, x |
| 8167 | // movne r0, y |
| 8168 | // to |
| 8169 | // cmp r0, x |
| 8170 | // movne r0, y |
| 8171 | /// FIXME: Turn this into a target neutral optimization? |
| 8172 | SDValue Res; |
Evan Cheng | 9b88d2d | 2011-09-28 23:16:31 +0000 | [diff] [blame] | 8173 | if (CC == ARMCC::NE && FalseVal == RHS && FalseVal != LHS) { |
Evan Cheng | e721f5c | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 8174 | Res = DAG.getNode(ARMISD::CMOV, dl, VT, LHS, TrueVal, ARMcc, |
| 8175 | N->getOperand(3), Cmp); |
| 8176 | } else if (CC == ARMCC::EQ && TrueVal == RHS) { |
| 8177 | SDValue ARMcc; |
| 8178 | SDValue NewCmp = getARMCmp(LHS, RHS, ISD::SETNE, ARMcc, DAG, dl); |
| 8179 | Res = DAG.getNode(ARMISD::CMOV, dl, VT, LHS, FalseVal, ARMcc, |
| 8180 | N->getOperand(3), NewCmp); |
| 8181 | } |
| 8182 | |
| 8183 | if (Res.getNode()) { |
| 8184 | APInt KnownZero, KnownOne; |
| 8185 | APInt Mask = APInt::getAllOnesValue(VT.getScalarType().getSizeInBits()); |
| 8186 | DAG.ComputeMaskedBits(SDValue(N,0), Mask, KnownZero, KnownOne); |
| 8187 | // Capture demanded bits information that would be otherwise lost. |
| 8188 | if (KnownZero == 0xfffffffe) |
| 8189 | Res = DAG.getNode(ISD::AssertZext, dl, MVT::i32, Res, |
| 8190 | DAG.getValueType(MVT::i1)); |
| 8191 | else if (KnownZero == 0xffffff00) |
| 8192 | Res = DAG.getNode(ISD::AssertZext, dl, MVT::i32, Res, |
| 8193 | DAG.getValueType(MVT::i8)); |
| 8194 | else if (KnownZero == 0xffff0000) |
| 8195 | Res = DAG.getNode(ISD::AssertZext, dl, MVT::i32, Res, |
| 8196 | DAG.getValueType(MVT::i16)); |
| 8197 | } |
| 8198 | |
| 8199 | return Res; |
| 8200 | } |
| 8201 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 8202 | SDValue ARMTargetLowering::PerformDAGCombine(SDNode *N, |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 8203 | DAGCombinerInfo &DCI) const { |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 8204 | switch (N->getOpcode()) { |
| 8205 | default: break; |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8206 | case ISD::ADD: return PerformADDCombine(N, DCI, Subtarget); |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8207 | case ISD::SUB: return PerformSUBCombine(N, DCI); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 8208 | case ISD::MUL: return PerformMULCombine(N, DCI, Subtarget); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8209 | case ISD::OR: return PerformORCombine(N, DCI, Subtarget); |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 8210 | case ISD::XOR: return PerformXORCombine(N, DCI, Subtarget); |
| 8211 | case ISD::AND: return PerformANDCombine(N, DCI, Subtarget); |
Evan Cheng | 0c1aec1 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 8212 | case ARMISD::BFI: return PerformBFICombine(N, DCI); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 8213 | case ARMISD::VMOVRRD: return PerformVMOVRRDCombine(N, DCI); |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 8214 | case ARMISD::VMOVDRR: return PerformVMOVDRRCombine(N, DCI.DAG); |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 8215 | case ISD::STORE: return PerformSTORECombine(N, DCI); |
| 8216 | case ISD::BUILD_VECTOR: return PerformBUILD_VECTORCombine(N, DCI); |
| 8217 | case ISD::INSERT_VECTOR_ELT: return PerformInsertEltCombine(N, DCI); |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 8218 | case ISD::VECTOR_SHUFFLE: return PerformVECTOR_SHUFFLECombine(N, DCI.DAG); |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 8219 | case ARMISD::VDUPLANE: return PerformVDUPLANECombine(N, DCI); |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 8220 | case ISD::FP_TO_SINT: |
| 8221 | case ISD::FP_TO_UINT: return PerformVCVTCombine(N, DCI, Subtarget); |
| 8222 | case ISD::FDIV: return PerformVDIVCombine(N, DCI, Subtarget); |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8223 | case ISD::INTRINSIC_WO_CHAIN: return PerformIntrinsicCombine(N, DCI.DAG); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8224 | case ISD::SHL: |
| 8225 | case ISD::SRA: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8226 | case ISD::SRL: return PerformShiftCombine(N, DCI.DAG, Subtarget); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8227 | case ISD::SIGN_EXTEND: |
| 8228 | case ISD::ZERO_EXTEND: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8229 | case ISD::ANY_EXTEND: return PerformExtendCombine(N, DCI.DAG, Subtarget); |
| 8230 | case ISD::SELECT_CC: return PerformSELECT_CCCombine(N, DCI.DAG, Subtarget); |
Evan Cheng | e721f5c | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 8231 | case ARMISD::CMOV: return PerformCMOVCombine(N, DCI.DAG); |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 8232 | case ARMISD::VLD2DUP: |
| 8233 | case ARMISD::VLD3DUP: |
| 8234 | case ARMISD::VLD4DUP: |
| 8235 | return CombineBaseUpdate(N, DCI); |
| 8236 | case ISD::INTRINSIC_VOID: |
| 8237 | case ISD::INTRINSIC_W_CHAIN: |
| 8238 | switch (cast<ConstantSDNode>(N->getOperand(1))->getZExtValue()) { |
| 8239 | case Intrinsic::arm_neon_vld1: |
| 8240 | case Intrinsic::arm_neon_vld2: |
| 8241 | case Intrinsic::arm_neon_vld3: |
| 8242 | case Intrinsic::arm_neon_vld4: |
| 8243 | case Intrinsic::arm_neon_vld2lane: |
| 8244 | case Intrinsic::arm_neon_vld3lane: |
| 8245 | case Intrinsic::arm_neon_vld4lane: |
| 8246 | case Intrinsic::arm_neon_vst1: |
| 8247 | case Intrinsic::arm_neon_vst2: |
| 8248 | case Intrinsic::arm_neon_vst3: |
| 8249 | case Intrinsic::arm_neon_vst4: |
| 8250 | case Intrinsic::arm_neon_vst2lane: |
| 8251 | case Intrinsic::arm_neon_vst3lane: |
| 8252 | case Intrinsic::arm_neon_vst4lane: |
| 8253 | return CombineBaseUpdate(N, DCI); |
| 8254 | default: break; |
| 8255 | } |
| 8256 | break; |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 8257 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 8258 | return SDValue(); |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 8259 | } |
| 8260 | |
Evan Cheng | 31959b1 | 2011-02-02 01:06:55 +0000 | [diff] [blame] | 8261 | bool ARMTargetLowering::isDesirableToTransformToIntegerOp(unsigned Opc, |
| 8262 | EVT VT) const { |
| 8263 | return (VT == MVT::f32) && (Opc == ISD::LOAD || Opc == ISD::STORE); |
| 8264 | } |
| 8265 | |
Bill Wendling | af56634 | 2009-08-15 21:21:19 +0000 | [diff] [blame] | 8266 | bool ARMTargetLowering::allowsUnalignedMemoryAccesses(EVT VT) const { |
Bob Wilson | 02aba73 | 2010-09-28 04:09:35 +0000 | [diff] [blame] | 8267 | if (!Subtarget->allowsUnalignedMem()) |
Bob Wilson | 86fe66d | 2010-06-25 04:12:31 +0000 | [diff] [blame] | 8268 | return false; |
Bill Wendling | af56634 | 2009-08-15 21:21:19 +0000 | [diff] [blame] | 8269 | |
| 8270 | switch (VT.getSimpleVT().SimpleTy) { |
| 8271 | default: |
| 8272 | return false; |
| 8273 | case MVT::i8: |
| 8274 | case MVT::i16: |
| 8275 | case MVT::i32: |
| 8276 | return true; |
| 8277 | // FIXME: VLD1 etc with standard alignment is legal. |
| 8278 | } |
| 8279 | } |
| 8280 | |
Lang Hames | 1a1d1fc | 2011-11-02 22:52:45 +0000 | [diff] [blame] | 8281 | static bool memOpAlign(unsigned DstAlign, unsigned SrcAlign, |
| 8282 | unsigned AlignCheck) { |
| 8283 | return ((SrcAlign == 0 || SrcAlign % AlignCheck == 0) && |
| 8284 | (DstAlign == 0 || DstAlign % AlignCheck == 0)); |
| 8285 | } |
| 8286 | |
| 8287 | EVT ARMTargetLowering::getOptimalMemOpType(uint64_t Size, |
| 8288 | unsigned DstAlign, unsigned SrcAlign, |
Lang Hames | a1e7888 | 2011-11-02 23:37:04 +0000 | [diff] [blame] | 8289 | bool IsZeroVal, |
Lang Hames | 1a1d1fc | 2011-11-02 22:52:45 +0000 | [diff] [blame] | 8290 | bool MemcpyStrSrc, |
| 8291 | MachineFunction &MF) const { |
| 8292 | const Function *F = MF.getFunction(); |
| 8293 | |
| 8294 | // See if we can use NEON instructions for this... |
Lang Hames | a1e7888 | 2011-11-02 23:37:04 +0000 | [diff] [blame] | 8295 | if (IsZeroVal && |
Lang Hames | 1a1d1fc | 2011-11-02 22:52:45 +0000 | [diff] [blame] | 8296 | !F->hasFnAttr(Attribute::NoImplicitFloat) && |
| 8297 | Subtarget->hasNEON()) { |
| 8298 | if (memOpAlign(SrcAlign, DstAlign, 16) && Size >= 16) { |
| 8299 | return MVT::v4i32; |
| 8300 | } else if (memOpAlign(SrcAlign, DstAlign, 8) && Size >= 8) { |
| 8301 | return MVT::v2i32; |
| 8302 | } |
| 8303 | } |
| 8304 | |
Lang Hames | 5207bf2 | 2011-11-08 18:56:23 +0000 | [diff] [blame] | 8305 | // Lowering to i32/i16 if the size permits. |
| 8306 | if (Size >= 4) { |
| 8307 | return MVT::i32; |
| 8308 | } else if (Size >= 2) { |
| 8309 | return MVT::i16; |
| 8310 | } |
| 8311 | |
Lang Hames | 1a1d1fc | 2011-11-02 22:52:45 +0000 | [diff] [blame] | 8312 | // Let the target-independent logic figure it out. |
| 8313 | return MVT::Other; |
| 8314 | } |
| 8315 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 8316 | static bool isLegalT1AddressImmediate(int64_t V, EVT VT) { |
| 8317 | if (V < 0) |
| 8318 | return false; |
| 8319 | |
| 8320 | unsigned Scale = 1; |
| 8321 | switch (VT.getSimpleVT().SimpleTy) { |
| 8322 | default: return false; |
| 8323 | case MVT::i1: |
| 8324 | case MVT::i8: |
| 8325 | // Scale == 1; |
| 8326 | break; |
| 8327 | case MVT::i16: |
| 8328 | // Scale == 2; |
| 8329 | Scale = 2; |
| 8330 | break; |
| 8331 | case MVT::i32: |
| 8332 | // Scale == 4; |
| 8333 | Scale = 4; |
| 8334 | break; |
| 8335 | } |
| 8336 | |
| 8337 | if ((V & (Scale - 1)) != 0) |
| 8338 | return false; |
| 8339 | V /= Scale; |
| 8340 | return V == (V & ((1LL << 5) - 1)); |
| 8341 | } |
| 8342 | |
| 8343 | static bool isLegalT2AddressImmediate(int64_t V, EVT VT, |
| 8344 | const ARMSubtarget *Subtarget) { |
| 8345 | bool isNeg = false; |
| 8346 | if (V < 0) { |
| 8347 | isNeg = true; |
| 8348 | V = - V; |
| 8349 | } |
| 8350 | |
| 8351 | switch (VT.getSimpleVT().SimpleTy) { |
| 8352 | default: return false; |
| 8353 | case MVT::i1: |
| 8354 | case MVT::i8: |
| 8355 | case MVT::i16: |
| 8356 | case MVT::i32: |
| 8357 | // + imm12 or - imm8 |
| 8358 | if (isNeg) |
| 8359 | return V == (V & ((1LL << 8) - 1)); |
| 8360 | return V == (V & ((1LL << 12) - 1)); |
| 8361 | case MVT::f32: |
| 8362 | case MVT::f64: |
| 8363 | // Same as ARM mode. FIXME: NEON? |
| 8364 | if (!Subtarget->hasVFP2()) |
| 8365 | return false; |
| 8366 | if ((V & 3) != 0) |
| 8367 | return false; |
| 8368 | V >>= 2; |
| 8369 | return V == (V & ((1LL << 8) - 1)); |
| 8370 | } |
| 8371 | } |
| 8372 | |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8373 | /// isLegalAddressImmediate - Return true if the integer value can be used |
| 8374 | /// as the offset of the target addressing mode for load / store of the |
| 8375 | /// given type. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8376 | static bool isLegalAddressImmediate(int64_t V, EVT VT, |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8377 | const ARMSubtarget *Subtarget) { |
Evan Cheng | 961f879 | 2007-03-13 20:37:59 +0000 | [diff] [blame] | 8378 | if (V == 0) |
| 8379 | return true; |
| 8380 | |
Evan Cheng | 6501153 | 2009-03-09 19:15:00 +0000 | [diff] [blame] | 8381 | if (!VT.isSimple()) |
| 8382 | return false; |
| 8383 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 8384 | if (Subtarget->isThumb1Only()) |
| 8385 | return isLegalT1AddressImmediate(V, VT); |
| 8386 | else if (Subtarget->isThumb2()) |
| 8387 | return isLegalT2AddressImmediate(V, VT, Subtarget); |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8388 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 8389 | // ARM mode. |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8390 | if (V < 0) |
| 8391 | V = - V; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8392 | switch (VT.getSimpleVT().SimpleTy) { |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8393 | default: return false; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8394 | case MVT::i1: |
| 8395 | case MVT::i8: |
| 8396 | case MVT::i32: |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8397 | // +- imm12 |
Anton Korobeynikov | 7c1c261 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 8398 | return V == (V & ((1LL << 12) - 1)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8399 | case MVT::i16: |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8400 | // +- imm8 |
Anton Korobeynikov | 7c1c261 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 8401 | return V == (V & ((1LL << 8) - 1)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8402 | case MVT::f32: |
| 8403 | case MVT::f64: |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 8404 | if (!Subtarget->hasVFP2()) // FIXME: NEON? |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8405 | return false; |
Evan Cheng | 0b0a9a9 | 2007-05-03 02:00:18 +0000 | [diff] [blame] | 8406 | if ((V & 3) != 0) |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8407 | return false; |
| 8408 | V >>= 2; |
Anton Korobeynikov | 7c1c261 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 8409 | return V == (V & ((1LL << 8) - 1)); |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8410 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8411 | } |
| 8412 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 8413 | bool ARMTargetLowering::isLegalT2ScaledAddressingMode(const AddrMode &AM, |
| 8414 | EVT VT) const { |
| 8415 | int Scale = AM.Scale; |
| 8416 | if (Scale < 0) |
| 8417 | return false; |
| 8418 | |
| 8419 | switch (VT.getSimpleVT().SimpleTy) { |
| 8420 | default: return false; |
| 8421 | case MVT::i1: |
| 8422 | case MVT::i8: |
| 8423 | case MVT::i16: |
| 8424 | case MVT::i32: |
| 8425 | if (Scale == 1) |
| 8426 | return true; |
| 8427 | // r + r << imm |
| 8428 | Scale = Scale & ~1; |
| 8429 | return Scale == 2 || Scale == 4 || Scale == 8; |
| 8430 | case MVT::i64: |
| 8431 | // r + r |
| 8432 | if (((unsigned)AM.HasBaseReg + Scale) <= 2) |
| 8433 | return true; |
| 8434 | return false; |
| 8435 | case MVT::isVoid: |
| 8436 | // Note, we allow "void" uses (basically, uses that aren't loads or |
| 8437 | // stores), because arm allows folding a scale into many arithmetic |
| 8438 | // operations. This should be made more precise and revisited later. |
| 8439 | |
| 8440 | // Allow r << imm, but the imm has to be a multiple of two. |
| 8441 | if (Scale & 1) return false; |
| 8442 | return isPowerOf2_32(Scale); |
| 8443 | } |
| 8444 | } |
| 8445 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8446 | /// isLegalAddressingMode - Return true if the addressing mode represented |
| 8447 | /// 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] | 8448 | bool ARMTargetLowering::isLegalAddressingMode(const AddrMode &AM, |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 8449 | Type *Ty) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8450 | EVT VT = getValueType(Ty, true); |
Bob Wilson | 2c7dab1 | 2009-04-08 17:55:28 +0000 | [diff] [blame] | 8451 | if (!isLegalAddressImmediate(AM.BaseOffs, VT, Subtarget)) |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8452 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 8453 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8454 | // Can never fold addr of global into load/store. |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 8455 | if (AM.BaseGV) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8456 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 8457 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8458 | switch (AM.Scale) { |
| 8459 | case 0: // no scale reg, must be "r+i" or "r", or "i". |
| 8460 | break; |
| 8461 | case 1: |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 8462 | if (Subtarget->isThumb1Only()) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8463 | return false; |
Chris Lattner | 5a3d40d | 2007-04-13 06:50:55 +0000 | [diff] [blame] | 8464 | // FALL THROUGH. |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8465 | default: |
Chris Lattner | 5a3d40d | 2007-04-13 06:50:55 +0000 | [diff] [blame] | 8466 | // ARM doesn't support any R+R*scale+imm addr modes. |
| 8467 | if (AM.BaseOffs) |
| 8468 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 8469 | |
Bob Wilson | 2c7dab1 | 2009-04-08 17:55:28 +0000 | [diff] [blame] | 8470 | if (!VT.isSimple()) |
| 8471 | return false; |
| 8472 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 8473 | if (Subtarget->isThumb2()) |
| 8474 | return isLegalT2ScaledAddressingMode(AM, VT); |
| 8475 | |
Chris Lattner | eb13d1b | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 8476 | int Scale = AM.Scale; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8477 | switch (VT.getSimpleVT().SimpleTy) { |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8478 | default: return false; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8479 | case MVT::i1: |
| 8480 | case MVT::i8: |
| 8481 | case MVT::i32: |
Chris Lattner | eb13d1b | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 8482 | if (Scale < 0) Scale = -Scale; |
| 8483 | if (Scale == 1) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8484 | return true; |
| 8485 | // r + r << imm |
Chris Lattner | e115294 | 2007-04-11 16:17:12 +0000 | [diff] [blame] | 8486 | return isPowerOf2_32(Scale & ~1); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8487 | case MVT::i16: |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 8488 | case MVT::i64: |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8489 | // r + r |
Chris Lattner | eb13d1b | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 8490 | if (((unsigned)AM.HasBaseReg + Scale) <= 2) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8491 | return true; |
Chris Lattner | e115294 | 2007-04-11 16:17:12 +0000 | [diff] [blame] | 8492 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 8493 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8494 | case MVT::isVoid: |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8495 | // Note, we allow "void" uses (basically, uses that aren't loads or |
| 8496 | // stores), because arm allows folding a scale into many arithmetic |
| 8497 | // operations. This should be made more precise and revisited later. |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 8498 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8499 | // 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] | 8500 | if (Scale & 1) return false; |
| 8501 | return isPowerOf2_32(Scale); |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8502 | } |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8503 | } |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8504 | return true; |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8505 | } |
| 8506 | |
Evan Cheng | 77e4751 | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 8507 | /// isLegalICmpImmediate - Return true if the specified immediate is legal |
| 8508 | /// icmp immediate, that is the target has icmp instructions which can compare |
| 8509 | /// a register against the immediate without having to materialize the |
| 8510 | /// immediate into a register. |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 8511 | bool ARMTargetLowering::isLegalICmpImmediate(int64_t Imm) const { |
Evan Cheng | 77e4751 | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 8512 | if (!Subtarget->isThumb()) |
| 8513 | return ARM_AM::getSOImmVal(Imm) != -1; |
| 8514 | if (Subtarget->isThumb2()) |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 8515 | return ARM_AM::getT2SOImmVal(Imm) != -1; |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 8516 | return Imm >= 0 && Imm <= 255; |
Evan Cheng | 77e4751 | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 8517 | } |
| 8518 | |
Dan Gohman | cca8214 | 2011-05-03 00:46:49 +0000 | [diff] [blame] | 8519 | /// isLegalAddImmediate - Return true if the specified immediate is legal |
| 8520 | /// add immediate, that is the target has add instructions which can add |
| 8521 | /// a register with the immediate without having to materialize the |
| 8522 | /// immediate into a register. |
| 8523 | bool ARMTargetLowering::isLegalAddImmediate(int64_t Imm) const { |
| 8524 | return ARM_AM::getSOImmVal(Imm) != -1; |
| 8525 | } |
| 8526 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8527 | static bool getARMIndexedAddressParts(SDNode *Ptr, EVT VT, |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8528 | bool isSEXTLoad, SDValue &Base, |
| 8529 | SDValue &Offset, bool &isInc, |
| 8530 | SelectionDAG &DAG) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8531 | if (Ptr->getOpcode() != ISD::ADD && Ptr->getOpcode() != ISD::SUB) |
| 8532 | return false; |
| 8533 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8534 | if (VT == MVT::i16 || ((VT == MVT::i8 || VT == MVT::i1) && isSEXTLoad)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8535 | // AddressingMode 3 |
| 8536 | Base = Ptr->getOperand(0); |
| 8537 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 8538 | int RHSC = (int)RHS->getZExtValue(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8539 | if (RHSC < 0 && RHSC > -256) { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8540 | assert(Ptr->getOpcode() == ISD::ADD); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8541 | isInc = false; |
| 8542 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); |
| 8543 | return true; |
| 8544 | } |
| 8545 | } |
| 8546 | isInc = (Ptr->getOpcode() == ISD::ADD); |
| 8547 | Offset = Ptr->getOperand(1); |
| 8548 | return true; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8549 | } else if (VT == MVT::i32 || VT == MVT::i8 || VT == MVT::i1) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8550 | // AddressingMode 2 |
| 8551 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 8552 | int RHSC = (int)RHS->getZExtValue(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8553 | if (RHSC < 0 && RHSC > -0x1000) { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8554 | assert(Ptr->getOpcode() == ISD::ADD); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8555 | isInc = false; |
| 8556 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); |
| 8557 | Base = Ptr->getOperand(0); |
| 8558 | return true; |
| 8559 | } |
| 8560 | } |
| 8561 | |
| 8562 | if (Ptr->getOpcode() == ISD::ADD) { |
| 8563 | isInc = true; |
Evan Cheng | ee04a6d | 2011-07-20 23:34:39 +0000 | [diff] [blame] | 8564 | ARM_AM::ShiftOpc ShOpcVal= |
| 8565 | ARM_AM::getShiftOpcForNode(Ptr->getOperand(0).getOpcode()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8566 | if (ShOpcVal != ARM_AM::no_shift) { |
| 8567 | Base = Ptr->getOperand(1); |
| 8568 | Offset = Ptr->getOperand(0); |
| 8569 | } else { |
| 8570 | Base = Ptr->getOperand(0); |
| 8571 | Offset = Ptr->getOperand(1); |
| 8572 | } |
| 8573 | return true; |
| 8574 | } |
| 8575 | |
| 8576 | isInc = (Ptr->getOpcode() == ISD::ADD); |
| 8577 | Base = Ptr->getOperand(0); |
| 8578 | Offset = Ptr->getOperand(1); |
| 8579 | return true; |
| 8580 | } |
| 8581 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 8582 | // FIXME: Use VLDM / VSTM to emulate indexed FP load / store. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8583 | return false; |
| 8584 | } |
| 8585 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8586 | static bool getT2IndexedAddressParts(SDNode *Ptr, EVT VT, |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8587 | bool isSEXTLoad, SDValue &Base, |
| 8588 | SDValue &Offset, bool &isInc, |
| 8589 | SelectionDAG &DAG) { |
| 8590 | if (Ptr->getOpcode() != ISD::ADD && Ptr->getOpcode() != ISD::SUB) |
| 8591 | return false; |
| 8592 | |
| 8593 | Base = Ptr->getOperand(0); |
| 8594 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
| 8595 | int RHSC = (int)RHS->getZExtValue(); |
| 8596 | if (RHSC < 0 && RHSC > -0x100) { // 8 bits. |
| 8597 | assert(Ptr->getOpcode() == ISD::ADD); |
| 8598 | isInc = false; |
| 8599 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); |
| 8600 | return true; |
| 8601 | } else if (RHSC > 0 && RHSC < 0x100) { // 8 bit, no zero. |
| 8602 | isInc = Ptr->getOpcode() == ISD::ADD; |
| 8603 | Offset = DAG.getConstant(RHSC, RHS->getValueType(0)); |
| 8604 | return true; |
| 8605 | } |
| 8606 | } |
| 8607 | |
| 8608 | return false; |
| 8609 | } |
| 8610 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8611 | /// getPreIndexedAddressParts - returns true by value, base pointer and |
| 8612 | /// offset pointer and addressing mode by reference if the node's address |
| 8613 | /// can be legally represented as pre-indexed load / store address. |
| 8614 | bool |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 8615 | ARMTargetLowering::getPreIndexedAddressParts(SDNode *N, SDValue &Base, |
| 8616 | SDValue &Offset, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8617 | ISD::MemIndexedMode &AM, |
Dan Gohman | 73e0914 | 2009-01-15 16:29:45 +0000 | [diff] [blame] | 8618 | SelectionDAG &DAG) const { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8619 | if (Subtarget->isThumb1Only()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8620 | return false; |
| 8621 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8622 | EVT VT; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 8623 | SDValue Ptr; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8624 | bool isSEXTLoad = false; |
| 8625 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) { |
| 8626 | Ptr = LD->getBasePtr(); |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 8627 | VT = LD->getMemoryVT(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8628 | isSEXTLoad = LD->getExtensionType() == ISD::SEXTLOAD; |
| 8629 | } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) { |
| 8630 | Ptr = ST->getBasePtr(); |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 8631 | VT = ST->getMemoryVT(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8632 | } else |
| 8633 | return false; |
| 8634 | |
| 8635 | bool isInc; |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8636 | bool isLegal = false; |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 8637 | if (Subtarget->isThumb2()) |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8638 | isLegal = getT2IndexedAddressParts(Ptr.getNode(), VT, isSEXTLoad, Base, |
| 8639 | Offset, isInc, DAG); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 8640 | else |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8641 | isLegal = getARMIndexedAddressParts(Ptr.getNode(), VT, isSEXTLoad, Base, |
Evan Cheng | 0412957 | 2009-07-02 06:44:30 +0000 | [diff] [blame] | 8642 | Offset, isInc, DAG); |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8643 | if (!isLegal) |
| 8644 | return false; |
| 8645 | |
| 8646 | AM = isInc ? ISD::PRE_INC : ISD::PRE_DEC; |
| 8647 | return true; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8648 | } |
| 8649 | |
| 8650 | /// getPostIndexedAddressParts - returns true by value, base pointer and |
| 8651 | /// offset pointer and addressing mode by reference if this node can be |
| 8652 | /// combined with a load / store to form a post-indexed load / store. |
| 8653 | bool ARMTargetLowering::getPostIndexedAddressParts(SDNode *N, SDNode *Op, |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 8654 | SDValue &Base, |
| 8655 | SDValue &Offset, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8656 | ISD::MemIndexedMode &AM, |
Dan Gohman | 73e0914 | 2009-01-15 16:29:45 +0000 | [diff] [blame] | 8657 | SelectionDAG &DAG) const { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8658 | if (Subtarget->isThumb1Only()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8659 | return false; |
| 8660 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8661 | EVT VT; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 8662 | SDValue Ptr; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8663 | bool isSEXTLoad = false; |
| 8664 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) { |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 8665 | VT = LD->getMemoryVT(); |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 8666 | Ptr = LD->getBasePtr(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8667 | isSEXTLoad = LD->getExtensionType() == ISD::SEXTLOAD; |
| 8668 | } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) { |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 8669 | VT = ST->getMemoryVT(); |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 8670 | Ptr = ST->getBasePtr(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8671 | } else |
| 8672 | return false; |
| 8673 | |
| 8674 | bool isInc; |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8675 | bool isLegal = false; |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 8676 | if (Subtarget->isThumb2()) |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8677 | isLegal = getT2IndexedAddressParts(Op, VT, isSEXTLoad, Base, Offset, |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 8678 | isInc, DAG); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 8679 | else |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8680 | isLegal = getARMIndexedAddressParts(Op, VT, isSEXTLoad, Base, Offset, |
| 8681 | isInc, DAG); |
| 8682 | if (!isLegal) |
| 8683 | return false; |
| 8684 | |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 8685 | if (Ptr != Base) { |
| 8686 | // Swap base ptr and offset to catch more post-index load / store when |
| 8687 | // it's legal. In Thumb2 mode, offset must be an immediate. |
| 8688 | if (Ptr == Offset && Op->getOpcode() == ISD::ADD && |
| 8689 | !Subtarget->isThumb2()) |
| 8690 | std::swap(Base, Offset); |
| 8691 | |
| 8692 | // Post-indexed load / store update the base pointer. |
| 8693 | if (Ptr != Base) |
| 8694 | return false; |
| 8695 | } |
| 8696 | |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8697 | AM = isInc ? ISD::POST_INC : ISD::POST_DEC; |
| 8698 | return true; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8699 | } |
| 8700 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 8701 | void ARMTargetLowering::computeMaskedBitsForTargetNode(const SDValue Op, |
Dan Gohman | 977a76f | 2008-02-13 22:28:48 +0000 | [diff] [blame] | 8702 | const APInt &Mask, |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 8703 | APInt &KnownZero, |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 8704 | APInt &KnownOne, |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 8705 | const SelectionDAG &DAG, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8706 | unsigned Depth) const { |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 8707 | KnownZero = KnownOne = APInt(Mask.getBitWidth(), 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8708 | switch (Op.getOpcode()) { |
| 8709 | default: break; |
| 8710 | case ARMISD::CMOV: { |
| 8711 | // Bits are known zero/one if known on the LHS and RHS. |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 8712 | DAG.ComputeMaskedBits(Op.getOperand(0), Mask, KnownZero, KnownOne, Depth+1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8713 | if (KnownZero == 0 && KnownOne == 0) return; |
| 8714 | |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 8715 | APInt KnownZeroRHS, KnownOneRHS; |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 8716 | DAG.ComputeMaskedBits(Op.getOperand(1), Mask, |
| 8717 | KnownZeroRHS, KnownOneRHS, Depth+1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8718 | KnownZero &= KnownZeroRHS; |
| 8719 | KnownOne &= KnownOneRHS; |
| 8720 | return; |
| 8721 | } |
| 8722 | } |
| 8723 | } |
| 8724 | |
| 8725 | //===----------------------------------------------------------------------===// |
| 8726 | // ARM Inline Assembly Support |
| 8727 | //===----------------------------------------------------------------------===// |
| 8728 | |
Evan Cheng | 55d4200 | 2011-01-08 01:24:27 +0000 | [diff] [blame] | 8729 | bool ARMTargetLowering::ExpandInlineAsm(CallInst *CI) const { |
| 8730 | // Looking for "rev" which is V6+. |
| 8731 | if (!Subtarget->hasV6Ops()) |
| 8732 | return false; |
| 8733 | |
| 8734 | InlineAsm *IA = cast<InlineAsm>(CI->getCalledValue()); |
| 8735 | std::string AsmStr = IA->getAsmString(); |
| 8736 | SmallVector<StringRef, 4> AsmPieces; |
| 8737 | SplitString(AsmStr, AsmPieces, ";\n"); |
| 8738 | |
| 8739 | switch (AsmPieces.size()) { |
| 8740 | default: return false; |
| 8741 | case 1: |
| 8742 | AsmStr = AsmPieces[0]; |
| 8743 | AsmPieces.clear(); |
| 8744 | SplitString(AsmStr, AsmPieces, " \t,"); |
| 8745 | |
| 8746 | // rev $0, $1 |
| 8747 | if (AsmPieces.size() == 3 && |
| 8748 | AsmPieces[0] == "rev" && AsmPieces[1] == "$0" && AsmPieces[2] == "$1" && |
| 8749 | IA->getConstraintString().compare(0, 4, "=l,l") == 0) { |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 8750 | IntegerType *Ty = dyn_cast<IntegerType>(CI->getType()); |
Evan Cheng | 55d4200 | 2011-01-08 01:24:27 +0000 | [diff] [blame] | 8751 | if (Ty && Ty->getBitWidth() == 32) |
| 8752 | return IntrinsicLowering::LowerToByteSwap(CI); |
| 8753 | } |
| 8754 | break; |
| 8755 | } |
| 8756 | |
| 8757 | return false; |
| 8758 | } |
| 8759 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8760 | /// getConstraintType - Given a constraint letter, return the type of |
| 8761 | /// constraint it is for this target. |
| 8762 | ARMTargetLowering::ConstraintType |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 8763 | ARMTargetLowering::getConstraintType(const std::string &Constraint) const { |
| 8764 | if (Constraint.size() == 1) { |
| 8765 | switch (Constraint[0]) { |
| 8766 | default: break; |
| 8767 | case 'l': return C_RegisterClass; |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 8768 | case 'w': return C_RegisterClass; |
Eric Christopher | 73744df | 2011-06-30 23:23:01 +0000 | [diff] [blame] | 8769 | case 'h': return C_RegisterClass; |
Eric Christopher | 89bd71f | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 8770 | case 'x': return C_RegisterClass; |
Eric Christopher | d5dc9ec | 2011-07-01 00:30:46 +0000 | [diff] [blame] | 8771 | case 't': return C_RegisterClass; |
Eric Christopher | 5e653c9 | 2011-07-01 01:00:07 +0000 | [diff] [blame] | 8772 | case 'j': return C_Other; // Constant for movw. |
Eric Christopher | ef7f1e7 | 2011-07-29 21:18:58 +0000 | [diff] [blame] | 8773 | // An address with a single base register. Due to the way we |
| 8774 | // currently handle addresses it is the same as an 'r' memory constraint. |
| 8775 | case 'Q': return C_Memory; |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 8776 | } |
Eric Christopher | 1312ca8 | 2011-06-21 22:10:57 +0000 | [diff] [blame] | 8777 | } else if (Constraint.size() == 2) { |
| 8778 | switch (Constraint[0]) { |
| 8779 | default: break; |
| 8780 | // All 'U+' constraints are addresses. |
| 8781 | case 'U': return C_Memory; |
| 8782 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8783 | } |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 8784 | return TargetLowering::getConstraintType(Constraint); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8785 | } |
| 8786 | |
John Thompson | 44ab89e | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 8787 | /// Examine constraint type and operand type and determine a weight value. |
| 8788 | /// This object must already have been set up with the operand type |
| 8789 | /// and the current alternative constraint selected. |
| 8790 | TargetLowering::ConstraintWeight |
| 8791 | ARMTargetLowering::getSingleConstraintMatchWeight( |
| 8792 | AsmOperandInfo &info, const char *constraint) const { |
| 8793 | ConstraintWeight weight = CW_Invalid; |
| 8794 | Value *CallOperandVal = info.CallOperandVal; |
| 8795 | // If we don't have a value, we can't do a match, |
| 8796 | // but allow it at the lowest weight. |
| 8797 | if (CallOperandVal == NULL) |
| 8798 | return CW_Default; |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 8799 | Type *type = CallOperandVal->getType(); |
John Thompson | 44ab89e | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 8800 | // Look at the constraint type. |
| 8801 | switch (*constraint) { |
| 8802 | default: |
| 8803 | weight = TargetLowering::getSingleConstraintMatchWeight(info, constraint); |
| 8804 | break; |
| 8805 | case 'l': |
| 8806 | if (type->isIntegerTy()) { |
| 8807 | if (Subtarget->isThumb()) |
| 8808 | weight = CW_SpecificReg; |
| 8809 | else |
| 8810 | weight = CW_Register; |
| 8811 | } |
| 8812 | break; |
| 8813 | case 'w': |
| 8814 | if (type->isFloatingPointTy()) |
| 8815 | weight = CW_Register; |
| 8816 | break; |
| 8817 | } |
| 8818 | return weight; |
| 8819 | } |
| 8820 | |
Eric Christopher | 35e6d4d | 2011-06-30 23:50:52 +0000 | [diff] [blame] | 8821 | typedef std::pair<unsigned, const TargetRegisterClass*> RCPair; |
| 8822 | RCPair |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8823 | ARMTargetLowering::getRegForInlineAsmConstraint(const std::string &Constraint, |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8824 | EVT VT) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8825 | if (Constraint.size() == 1) { |
Jakob Stoklund Olesen | 09bf003 | 2010-01-14 18:19:56 +0000 | [diff] [blame] | 8826 | // GCC ARM Constraint Letters |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8827 | switch (Constraint[0]) { |
Eric Christopher | 73744df | 2011-06-30 23:23:01 +0000 | [diff] [blame] | 8828 | case 'l': // Low regs or general regs. |
Jakob Stoklund Olesen | 09bf003 | 2010-01-14 18:19:56 +0000 | [diff] [blame] | 8829 | if (Subtarget->isThumb()) |
Eric Christopher | 35e6d4d | 2011-06-30 23:50:52 +0000 | [diff] [blame] | 8830 | return RCPair(0U, ARM::tGPRRegisterClass); |
Jim Grosbach | 30eae3c | 2009-04-07 20:34:09 +0000 | [diff] [blame] | 8831 | else |
Eric Christopher | 35e6d4d | 2011-06-30 23:50:52 +0000 | [diff] [blame] | 8832 | return RCPair(0U, ARM::GPRRegisterClass); |
Eric Christopher | 73744df | 2011-06-30 23:23:01 +0000 | [diff] [blame] | 8833 | case 'h': // High regs or no regs. |
| 8834 | if (Subtarget->isThumb()) |
Andrew Trick | 3af7a67 | 2011-09-20 03:06:13 +0000 | [diff] [blame] | 8835 | return RCPair(0U, ARM::hGPRRegisterClass); |
Eric Christopher | 1070f82 | 2011-07-01 00:19:27 +0000 | [diff] [blame] | 8836 | break; |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 8837 | case 'r': |
Eric Christopher | 35e6d4d | 2011-06-30 23:50:52 +0000 | [diff] [blame] | 8838 | return RCPair(0U, ARM::GPRRegisterClass); |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 8839 | case 'w': |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8840 | if (VT == MVT::f32) |
Eric Christopher | 35e6d4d | 2011-06-30 23:50:52 +0000 | [diff] [blame] | 8841 | return RCPair(0U, ARM::SPRRegisterClass); |
Bob Wilson | 5afffae | 2009-12-18 01:03:29 +0000 | [diff] [blame] | 8842 | if (VT.getSizeInBits() == 64) |
Eric Christopher | 35e6d4d | 2011-06-30 23:50:52 +0000 | [diff] [blame] | 8843 | return RCPair(0U, ARM::DPRRegisterClass); |
Evan Cheng | d831cda | 2009-12-08 23:06:22 +0000 | [diff] [blame] | 8844 | if (VT.getSizeInBits() == 128) |
Eric Christopher | 35e6d4d | 2011-06-30 23:50:52 +0000 | [diff] [blame] | 8845 | return RCPair(0U, ARM::QPRRegisterClass); |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 8846 | break; |
Eric Christopher | 89bd71f | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 8847 | case 'x': |
| 8848 | if (VT == MVT::f32) |
Andrew Trick | 3af7a67 | 2011-09-20 03:06:13 +0000 | [diff] [blame] | 8849 | return RCPair(0U, ARM::SPR_8RegisterClass); |
Eric Christopher | 89bd71f | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 8850 | if (VT.getSizeInBits() == 64) |
Andrew Trick | 3af7a67 | 2011-09-20 03:06:13 +0000 | [diff] [blame] | 8851 | return RCPair(0U, ARM::DPR_8RegisterClass); |
Eric Christopher | 89bd71f | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 8852 | if (VT.getSizeInBits() == 128) |
Andrew Trick | 3af7a67 | 2011-09-20 03:06:13 +0000 | [diff] [blame] | 8853 | return RCPair(0U, ARM::QPR_8RegisterClass); |
Eric Christopher | 89bd71f | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 8854 | break; |
Eric Christopher | d5dc9ec | 2011-07-01 00:30:46 +0000 | [diff] [blame] | 8855 | case 't': |
| 8856 | if (VT == MVT::f32) |
Andrew Trick | 3af7a67 | 2011-09-20 03:06:13 +0000 | [diff] [blame] | 8857 | return RCPair(0U, ARM::SPRRegisterClass); |
Eric Christopher | d5dc9ec | 2011-07-01 00:30:46 +0000 | [diff] [blame] | 8858 | break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8859 | } |
| 8860 | } |
Bob Wilson | 33cc5cb | 2010-03-15 23:09:18 +0000 | [diff] [blame] | 8861 | if (StringRef("{cc}").equals_lower(Constraint)) |
Jakob Stoklund Olesen | 0d8ba33 | 2010-06-18 16:49:33 +0000 | [diff] [blame] | 8862 | return std::make_pair(unsigned(ARM::CPSR), ARM::CCRRegisterClass); |
Bob Wilson | 33cc5cb | 2010-03-15 23:09:18 +0000 | [diff] [blame] | 8863 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8864 | return TargetLowering::getRegForInlineAsmConstraint(Constraint, VT); |
| 8865 | } |
| 8866 | |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 8867 | /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops |
| 8868 | /// vector. If it is invalid, don't add anything to Ops. |
| 8869 | void ARMTargetLowering::LowerAsmOperandForConstraint(SDValue Op, |
Eric Christopher | 100c833 | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 8870 | std::string &Constraint, |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 8871 | std::vector<SDValue>&Ops, |
| 8872 | SelectionDAG &DAG) const { |
| 8873 | SDValue Result(0, 0); |
| 8874 | |
Eric Christopher | 100c833 | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 8875 | // Currently only support length 1 constraints. |
| 8876 | if (Constraint.length() != 1) return; |
Eric Christopher | 471e422 | 2011-06-08 23:55:35 +0000 | [diff] [blame] | 8877 | |
Eric Christopher | 100c833 | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 8878 | char ConstraintLetter = Constraint[0]; |
| 8879 | switch (ConstraintLetter) { |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 8880 | default: break; |
Eric Christopher | 5e653c9 | 2011-07-01 01:00:07 +0000 | [diff] [blame] | 8881 | case 'j': |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 8882 | case 'I': case 'J': case 'K': case 'L': |
| 8883 | case 'M': case 'N': case 'O': |
| 8884 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op); |
| 8885 | if (!C) |
| 8886 | return; |
| 8887 | |
| 8888 | int64_t CVal64 = C->getSExtValue(); |
| 8889 | int CVal = (int) CVal64; |
| 8890 | // None of these constraints allow values larger than 32 bits. Check |
| 8891 | // that the value fits in an int. |
| 8892 | if (CVal != CVal64) |
| 8893 | return; |
| 8894 | |
Eric Christopher | 100c833 | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 8895 | switch (ConstraintLetter) { |
Eric Christopher | 5e653c9 | 2011-07-01 01:00:07 +0000 | [diff] [blame] | 8896 | case 'j': |
Andrew Trick | 3af7a67 | 2011-09-20 03:06:13 +0000 | [diff] [blame] | 8897 | // Constant suitable for movw, must be between 0 and |
| 8898 | // 65535. |
| 8899 | if (Subtarget->hasV6T2Ops()) |
| 8900 | if (CVal >= 0 && CVal <= 65535) |
| 8901 | break; |
| 8902 | return; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 8903 | case 'I': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 8904 | if (Subtarget->isThumb1Only()) { |
| 8905 | // This must be a constant between 0 and 255, for ADD |
| 8906 | // immediates. |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 8907 | if (CVal >= 0 && CVal <= 255) |
| 8908 | break; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 8909 | } else if (Subtarget->isThumb2()) { |
| 8910 | // A constant that can be used as an immediate value in a |
| 8911 | // data-processing instruction. |
| 8912 | if (ARM_AM::getT2SOImmVal(CVal) != -1) |
| 8913 | break; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 8914 | } else { |
| 8915 | // A constant that can be used as an immediate value in a |
| 8916 | // data-processing instruction. |
| 8917 | if (ARM_AM::getSOImmVal(CVal) != -1) |
| 8918 | break; |
| 8919 | } |
| 8920 | return; |
| 8921 | |
| 8922 | case 'J': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 8923 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 8924 | // This must be a constant between -255 and -1, for negated ADD |
| 8925 | // immediates. This can be used in GCC with an "n" modifier that |
| 8926 | // prints the negated value, for use with SUB instructions. It is |
| 8927 | // not useful otherwise but is implemented for compatibility. |
| 8928 | if (CVal >= -255 && CVal <= -1) |
| 8929 | break; |
| 8930 | } else { |
| 8931 | // This must be a constant between -4095 and 4095. It is not clear |
| 8932 | // what this constraint is intended for. Implemented for |
| 8933 | // compatibility with GCC. |
| 8934 | if (CVal >= -4095 && CVal <= 4095) |
| 8935 | break; |
| 8936 | } |
| 8937 | return; |
| 8938 | |
| 8939 | case 'K': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 8940 | if (Subtarget->isThumb1Only()) { |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 8941 | // A 32-bit value where only one byte has a nonzero value. Exclude |
| 8942 | // zero to match GCC. This constraint is used by GCC internally for |
| 8943 | // constants that can be loaded with a move/shift combination. |
| 8944 | // It is not useful otherwise but is implemented for compatibility. |
| 8945 | if (CVal != 0 && ARM_AM::isThumbImmShiftedVal(CVal)) |
| 8946 | break; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 8947 | } else if (Subtarget->isThumb2()) { |
| 8948 | // A constant whose bitwise inverse can be used as an immediate |
| 8949 | // value in a data-processing instruction. This can be used in GCC |
| 8950 | // with a "B" modifier that prints the inverted value, for use with |
| 8951 | // BIC and MVN instructions. It is not useful otherwise but is |
| 8952 | // implemented for compatibility. |
| 8953 | if (ARM_AM::getT2SOImmVal(~CVal) != -1) |
| 8954 | break; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 8955 | } else { |
| 8956 | // A constant whose bitwise inverse can be used as an immediate |
| 8957 | // value in a data-processing instruction. This can be used in GCC |
| 8958 | // with a "B" modifier that prints the inverted value, for use with |
| 8959 | // BIC and MVN instructions. It is not useful otherwise but is |
| 8960 | // implemented for compatibility. |
| 8961 | if (ARM_AM::getSOImmVal(~CVal) != -1) |
| 8962 | break; |
| 8963 | } |
| 8964 | return; |
| 8965 | |
| 8966 | case 'L': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 8967 | if (Subtarget->isThumb1Only()) { |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 8968 | // This must be a constant between -7 and 7, |
| 8969 | // for 3-operand ADD/SUB immediate instructions. |
| 8970 | if (CVal >= -7 && CVal < 7) |
| 8971 | break; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 8972 | } else if (Subtarget->isThumb2()) { |
| 8973 | // A constant whose negation can be used as an immediate value in a |
| 8974 | // data-processing instruction. This can be used in GCC with an "n" |
| 8975 | // modifier that prints the negated value, for use with SUB |
| 8976 | // instructions. It is not useful otherwise but is implemented for |
| 8977 | // compatibility. |
| 8978 | if (ARM_AM::getT2SOImmVal(-CVal) != -1) |
| 8979 | break; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 8980 | } else { |
| 8981 | // A constant whose negation can be used as an immediate value in a |
| 8982 | // data-processing instruction. This can be used in GCC with an "n" |
| 8983 | // modifier that prints the negated value, for use with SUB |
| 8984 | // instructions. It is not useful otherwise but is implemented for |
| 8985 | // compatibility. |
| 8986 | if (ARM_AM::getSOImmVal(-CVal) != -1) |
| 8987 | break; |
| 8988 | } |
| 8989 | return; |
| 8990 | |
| 8991 | case 'M': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 8992 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 8993 | // This must be a multiple of 4 between 0 and 1020, for |
| 8994 | // ADD sp + immediate. |
| 8995 | if ((CVal >= 0 && CVal <= 1020) && ((CVal & 3) == 0)) |
| 8996 | break; |
| 8997 | } else { |
| 8998 | // A power of two or a constant between 0 and 32. This is used in |
| 8999 | // GCC for the shift amount on shifted register operands, but it is |
| 9000 | // useful in general for any shift amounts. |
| 9001 | if ((CVal >= 0 && CVal <= 32) || ((CVal & (CVal - 1)) == 0)) |
| 9002 | break; |
| 9003 | } |
| 9004 | return; |
| 9005 | |
| 9006 | case 'N': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 9007 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 9008 | // This must be a constant between 0 and 31, for shift amounts. |
| 9009 | if (CVal >= 0 && CVal <= 31) |
| 9010 | break; |
| 9011 | } |
| 9012 | return; |
| 9013 | |
| 9014 | case 'O': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 9015 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 9016 | // This must be a multiple of 4 between -508 and 508, for |
| 9017 | // ADD/SUB sp = sp + immediate. |
| 9018 | if ((CVal >= -508 && CVal <= 508) && ((CVal & 3) == 0)) |
| 9019 | break; |
| 9020 | } |
| 9021 | return; |
| 9022 | } |
| 9023 | Result = DAG.getTargetConstant(CVal, Op.getValueType()); |
| 9024 | break; |
| 9025 | } |
| 9026 | |
| 9027 | if (Result.getNode()) { |
| 9028 | Ops.push_back(Result); |
| 9029 | return; |
| 9030 | } |
Dale Johannesen | 1784d16 | 2010-06-25 21:55:36 +0000 | [diff] [blame] | 9031 | return TargetLowering::LowerAsmOperandForConstraint(Op, Constraint, Ops, DAG); |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 9032 | } |
Anton Korobeynikov | 48e1935 | 2009-09-23 19:04:09 +0000 | [diff] [blame] | 9033 | |
| 9034 | bool |
| 9035 | ARMTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const { |
| 9036 | // The ARM target isn't yet aware of offsets. |
| 9037 | return false; |
| 9038 | } |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 9039 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 9040 | bool ARM::isBitFieldInvertedMask(unsigned v) { |
| 9041 | if (v == 0xffffffff) |
| 9042 | return 0; |
| 9043 | // there can be 1's on either or both "outsides", all the "inside" |
| 9044 | // bits must be 0's |
| 9045 | unsigned int lsb = 0, msb = 31; |
| 9046 | while (v & (1 << msb)) --msb; |
| 9047 | while (v & (1 << lsb)) ++lsb; |
| 9048 | for (unsigned int i = lsb; i <= msb; ++i) { |
| 9049 | if (v & (1 << i)) |
| 9050 | return 0; |
| 9051 | } |
| 9052 | return 1; |
| 9053 | } |
| 9054 | |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 9055 | /// isFPImmLegal - Returns true if the target can instruction select the |
| 9056 | /// specified FP immediate natively. If false, the legalizer will |
| 9057 | /// materialize the FP immediate as a load from a constant pool. |
| 9058 | bool ARMTargetLowering::isFPImmLegal(const APFloat &Imm, EVT VT) const { |
| 9059 | if (!Subtarget->hasVFP3()) |
| 9060 | return false; |
| 9061 | if (VT == MVT::f32) |
Jim Grosbach | 4ebbf7b | 2011-09-30 00:50:06 +0000 | [diff] [blame] | 9062 | return ARM_AM::getFP32Imm(Imm) != -1; |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 9063 | if (VT == MVT::f64) |
Jim Grosbach | 4ebbf7b | 2011-09-30 00:50:06 +0000 | [diff] [blame] | 9064 | return ARM_AM::getFP64Imm(Imm) != -1; |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 9065 | return false; |
| 9066 | } |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 9067 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 9068 | /// getTgtMemIntrinsic - Represent NEON load and store intrinsics as |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 9069 | /// MemIntrinsicNodes. The associated MachineMemOperands record the alignment |
| 9070 | /// specified in the intrinsic calls. |
| 9071 | bool ARMTargetLowering::getTgtMemIntrinsic(IntrinsicInfo &Info, |
| 9072 | const CallInst &I, |
| 9073 | unsigned Intrinsic) const { |
| 9074 | switch (Intrinsic) { |
| 9075 | case Intrinsic::arm_neon_vld1: |
| 9076 | case Intrinsic::arm_neon_vld2: |
| 9077 | case Intrinsic::arm_neon_vld3: |
| 9078 | case Intrinsic::arm_neon_vld4: |
| 9079 | case Intrinsic::arm_neon_vld2lane: |
| 9080 | case Intrinsic::arm_neon_vld3lane: |
| 9081 | case Intrinsic::arm_neon_vld4lane: { |
| 9082 | Info.opc = ISD::INTRINSIC_W_CHAIN; |
| 9083 | // Conservatively set memVT to the entire set of vectors loaded. |
| 9084 | uint64_t NumElts = getTargetData()->getTypeAllocSize(I.getType()) / 8; |
| 9085 | Info.memVT = EVT::getVectorVT(I.getType()->getContext(), MVT::i64, NumElts); |
| 9086 | Info.ptrVal = I.getArgOperand(0); |
| 9087 | Info.offset = 0; |
| 9088 | Value *AlignArg = I.getArgOperand(I.getNumArgOperands() - 1); |
| 9089 | Info.align = cast<ConstantInt>(AlignArg)->getZExtValue(); |
| 9090 | Info.vol = false; // volatile loads with NEON intrinsics not supported |
| 9091 | Info.readMem = true; |
| 9092 | Info.writeMem = false; |
| 9093 | return true; |
| 9094 | } |
| 9095 | case Intrinsic::arm_neon_vst1: |
| 9096 | case Intrinsic::arm_neon_vst2: |
| 9097 | case Intrinsic::arm_neon_vst3: |
| 9098 | case Intrinsic::arm_neon_vst4: |
| 9099 | case Intrinsic::arm_neon_vst2lane: |
| 9100 | case Intrinsic::arm_neon_vst3lane: |
| 9101 | case Intrinsic::arm_neon_vst4lane: { |
| 9102 | Info.opc = ISD::INTRINSIC_VOID; |
| 9103 | // Conservatively set memVT to the entire set of vectors stored. |
| 9104 | unsigned NumElts = 0; |
| 9105 | for (unsigned ArgI = 1, ArgE = I.getNumArgOperands(); ArgI < ArgE; ++ArgI) { |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 9106 | Type *ArgTy = I.getArgOperand(ArgI)->getType(); |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 9107 | if (!ArgTy->isVectorTy()) |
| 9108 | break; |
| 9109 | NumElts += getTargetData()->getTypeAllocSize(ArgTy) / 8; |
| 9110 | } |
| 9111 | Info.memVT = EVT::getVectorVT(I.getType()->getContext(), MVT::i64, NumElts); |
| 9112 | Info.ptrVal = I.getArgOperand(0); |
| 9113 | Info.offset = 0; |
| 9114 | Value *AlignArg = I.getArgOperand(I.getNumArgOperands() - 1); |
| 9115 | Info.align = cast<ConstantInt>(AlignArg)->getZExtValue(); |
| 9116 | Info.vol = false; // volatile stores with NEON intrinsics not supported |
| 9117 | Info.readMem = false; |
| 9118 | Info.writeMem = true; |
| 9119 | return true; |
| 9120 | } |
Bruno Cardoso Lopes | a0112d0 | 2011-05-28 04:07:29 +0000 | [diff] [blame] | 9121 | case Intrinsic::arm_strexd: { |
| 9122 | Info.opc = ISD::INTRINSIC_W_CHAIN; |
| 9123 | Info.memVT = MVT::i64; |
| 9124 | Info.ptrVal = I.getArgOperand(2); |
| 9125 | Info.offset = 0; |
| 9126 | Info.align = 8; |
Bruno Cardoso Lopes | c75448c | 2011-06-16 18:11:32 +0000 | [diff] [blame] | 9127 | Info.vol = true; |
Bruno Cardoso Lopes | a0112d0 | 2011-05-28 04:07:29 +0000 | [diff] [blame] | 9128 | Info.readMem = false; |
| 9129 | Info.writeMem = true; |
| 9130 | return true; |
| 9131 | } |
| 9132 | case Intrinsic::arm_ldrexd: { |
| 9133 | Info.opc = ISD::INTRINSIC_W_CHAIN; |
| 9134 | Info.memVT = MVT::i64; |
| 9135 | Info.ptrVal = I.getArgOperand(0); |
| 9136 | Info.offset = 0; |
| 9137 | Info.align = 8; |
Bruno Cardoso Lopes | c75448c | 2011-06-16 18:11:32 +0000 | [diff] [blame] | 9138 | Info.vol = true; |
Bruno Cardoso Lopes | a0112d0 | 2011-05-28 04:07:29 +0000 | [diff] [blame] | 9139 | Info.readMem = true; |
| 9140 | Info.writeMem = false; |
| 9141 | return true; |
| 9142 | } |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 9143 | default: |
| 9144 | break; |
| 9145 | } |
| 9146 | |
| 9147 | return false; |
| 9148 | } |