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 | |
Anton Korobeynikov | 72977a4 | 2009-08-14 20:10:52 +0000 | [diff] [blame] | 264 | if (Subtarget->isAAPCS_ABI()) { |
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"); |
| 389 | setLibcallName(RTLIB::SDIV_I64, "__aeabi_ldivmod"); |
| 390 | setLibcallName(RTLIB::UDIV_I64, "__aeabi_uldivmod"); |
| 391 | setLibcallName(RTLIB::SHL_I64, "__aeabi_llsl"); |
| 392 | setLibcallName(RTLIB::SRL_I64, "__aeabi_llsr"); |
| 393 | setLibcallName(RTLIB::SRA_I64, "__aeabi_lasr"); |
| 394 | setLibcallCallingConv(RTLIB::MUL_I64, CallingConv::ARM_AAPCS); |
| 395 | setLibcallCallingConv(RTLIB::SDIV_I64, CallingConv::ARM_AAPCS); |
| 396 | setLibcallCallingConv(RTLIB::UDIV_I64, CallingConv::ARM_AAPCS); |
| 397 | setLibcallCallingConv(RTLIB::SHL_I64, CallingConv::ARM_AAPCS); |
| 398 | setLibcallCallingConv(RTLIB::SRL_I64, CallingConv::ARM_AAPCS); |
| 399 | setLibcallCallingConv(RTLIB::SRA_I64, CallingConv::ARM_AAPCS); |
| 400 | |
| 401 | // Integer division functions |
| 402 | // RTABI chapter 4.3.1 |
| 403 | setLibcallName(RTLIB::SDIV_I8, "__aeabi_idiv"); |
| 404 | setLibcallName(RTLIB::SDIV_I16, "__aeabi_idiv"); |
| 405 | setLibcallName(RTLIB::SDIV_I32, "__aeabi_idiv"); |
| 406 | setLibcallName(RTLIB::UDIV_I8, "__aeabi_uidiv"); |
| 407 | setLibcallName(RTLIB::UDIV_I16, "__aeabi_uidiv"); |
| 408 | setLibcallName(RTLIB::UDIV_I32, "__aeabi_uidiv"); |
| 409 | setLibcallCallingConv(RTLIB::SDIV_I8, CallingConv::ARM_AAPCS); |
| 410 | setLibcallCallingConv(RTLIB::SDIV_I16, CallingConv::ARM_AAPCS); |
| 411 | setLibcallCallingConv(RTLIB::SDIV_I32, CallingConv::ARM_AAPCS); |
| 412 | setLibcallCallingConv(RTLIB::UDIV_I8, CallingConv::ARM_AAPCS); |
| 413 | setLibcallCallingConv(RTLIB::UDIV_I16, CallingConv::ARM_AAPCS); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 414 | setLibcallCallingConv(RTLIB::UDIV_I32, CallingConv::ARM_AAPCS); |
Renato Golin | 1ec11fb | 2011-05-22 21:41:23 +0000 | [diff] [blame] | 415 | |
| 416 | // Memory operations |
| 417 | // RTABI chapter 4.3.4 |
| 418 | setLibcallName(RTLIB::MEMCPY, "__aeabi_memcpy"); |
| 419 | setLibcallName(RTLIB::MEMMOVE, "__aeabi_memmove"); |
| 420 | setLibcallName(RTLIB::MEMSET, "__aeabi_memset"); |
Anton Korobeynikov | 72977a4 | 2009-08-14 20:10:52 +0000 | [diff] [blame] | 421 | } |
| 422 | |
Bob Wilson | 2fef457 | 2011-10-07 16:59:21 +0000 | [diff] [blame] | 423 | // Use divmod compiler-rt calls for iOS 5.0 and later. |
| 424 | if (Subtarget->getTargetTriple().getOS() == Triple::IOS && |
| 425 | !Subtarget->getTargetTriple().isOSVersionLT(5, 0)) { |
| 426 | setLibcallName(RTLIB::SDIVREM_I32, "__divmodsi4"); |
| 427 | setLibcallName(RTLIB::UDIVREM_I32, "__udivmodsi4"); |
| 428 | } |
| 429 | |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 430 | if (Subtarget->isThumb1Only()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 431 | addRegisterClass(MVT::i32, ARM::tGPRRegisterClass); |
Jim Grosbach | 30eae3c | 2009-04-07 20:34:09 +0000 | [diff] [blame] | 432 | else |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 433 | addRegisterClass(MVT::i32, ARM::GPRRegisterClass); |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 434 | if (!TM.Options.UseSoftFloat && Subtarget->hasVFP2() && |
| 435 | !Subtarget->isThumb1Only()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 436 | addRegisterClass(MVT::f32, ARM::SPRRegisterClass); |
Jim Grosbach | fcba5e6 | 2010-08-11 15:44:15 +0000 | [diff] [blame] | 437 | if (!Subtarget->isFPOnlySP()) |
| 438 | addRegisterClass(MVT::f64, ARM::DPRRegisterClass); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 439 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 440 | setTruncStoreAction(MVT::f64, MVT::f32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 441 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 442 | |
Eli Friedman | 9f1f26a | 2011-11-08 01:43:53 +0000 | [diff] [blame] | 443 | for (unsigned VT = (unsigned)MVT::FIRST_VECTOR_VALUETYPE; |
| 444 | VT <= (unsigned)MVT::LAST_VECTOR_VALUETYPE; ++VT) { |
| 445 | for (unsigned InnerVT = (unsigned)MVT::FIRST_VECTOR_VALUETYPE; |
| 446 | InnerVT <= (unsigned)MVT::LAST_VECTOR_VALUETYPE; ++InnerVT) |
| 447 | setTruncStoreAction((MVT::SimpleValueType)VT, |
| 448 | (MVT::SimpleValueType)InnerVT, Expand); |
| 449 | setLoadExtAction(ISD::SEXTLOAD, (MVT::SimpleValueType)VT, Expand); |
| 450 | setLoadExtAction(ISD::ZEXTLOAD, (MVT::SimpleValueType)VT, Expand); |
| 451 | setLoadExtAction(ISD::EXTLOAD, (MVT::SimpleValueType)VT, Expand); |
| 452 | } |
| 453 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 454 | if (Subtarget->hasNEON()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 455 | addDRTypeForNEON(MVT::v2f32); |
| 456 | addDRTypeForNEON(MVT::v8i8); |
| 457 | addDRTypeForNEON(MVT::v4i16); |
| 458 | addDRTypeForNEON(MVT::v2i32); |
| 459 | addDRTypeForNEON(MVT::v1i64); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 460 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 461 | addQRTypeForNEON(MVT::v4f32); |
| 462 | addQRTypeForNEON(MVT::v2f64); |
| 463 | addQRTypeForNEON(MVT::v16i8); |
| 464 | addQRTypeForNEON(MVT::v8i16); |
| 465 | addQRTypeForNEON(MVT::v4i32); |
| 466 | addQRTypeForNEON(MVT::v2i64); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 467 | |
Bob Wilson | 74dc72e | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 468 | // v2f64 is legal so that QR subregs can be extracted as f64 elements, but |
| 469 | // neither Neon nor VFP support any arithmetic operations on it. |
Stepan Dyatkovskiy | 3e0dc06 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 470 | // The same with v4f32. But keep in mind that vadd, vsub, vmul are natively |
| 471 | // supported for v4f32. |
Bob Wilson | 74dc72e | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 472 | setOperationAction(ISD::FADD, MVT::v2f64, Expand); |
| 473 | setOperationAction(ISD::FSUB, MVT::v2f64, Expand); |
| 474 | setOperationAction(ISD::FMUL, MVT::v2f64, Expand); |
Stepan Dyatkovskiy | 3e0dc06 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 475 | // FIXME: Code duplication: FDIV and FREM are expanded always, see |
| 476 | // ARMTargetLowering::addTypeForNEON method for details. |
Bob Wilson | 74dc72e | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 477 | setOperationAction(ISD::FDIV, MVT::v2f64, Expand); |
| 478 | setOperationAction(ISD::FREM, MVT::v2f64, Expand); |
Stepan Dyatkovskiy | 3e0dc06 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 479 | // FIXME: Create unittest. |
| 480 | // In another words, find a way when "copysign" appears in DAG with vector |
| 481 | // operands. |
Bob Wilson | 74dc72e | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 482 | setOperationAction(ISD::FCOPYSIGN, MVT::v2f64, Expand); |
Stepan Dyatkovskiy | 3e0dc06 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 483 | // FIXME: Code duplication: SETCC has custom operation action, see |
| 484 | // ARMTargetLowering::addTypeForNEON method for details. |
Duncan Sands | 28b77e9 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 485 | setOperationAction(ISD::SETCC, MVT::v2f64, Expand); |
Stepan Dyatkovskiy | 3e0dc06 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 486 | // FIXME: Create unittest for FNEG and for FABS. |
Bob Wilson | 74dc72e | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 487 | setOperationAction(ISD::FNEG, MVT::v2f64, Expand); |
| 488 | setOperationAction(ISD::FABS, MVT::v2f64, Expand); |
| 489 | setOperationAction(ISD::FSQRT, MVT::v2f64, Expand); |
| 490 | setOperationAction(ISD::FSIN, MVT::v2f64, Expand); |
| 491 | setOperationAction(ISD::FCOS, MVT::v2f64, Expand); |
| 492 | setOperationAction(ISD::FPOWI, MVT::v2f64, Expand); |
| 493 | setOperationAction(ISD::FPOW, MVT::v2f64, Expand); |
| 494 | setOperationAction(ISD::FLOG, MVT::v2f64, Expand); |
| 495 | setOperationAction(ISD::FLOG2, MVT::v2f64, Expand); |
| 496 | setOperationAction(ISD::FLOG10, MVT::v2f64, Expand); |
| 497 | setOperationAction(ISD::FEXP, MVT::v2f64, Expand); |
| 498 | setOperationAction(ISD::FEXP2, MVT::v2f64, Expand); |
Stepan Dyatkovskiy | 3e0dc06 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 499 | // FIXME: Create unittest for FCEIL, FTRUNC, FRINT, FNEARBYINT, FFLOOR. |
Bob Wilson | 74dc72e | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 500 | setOperationAction(ISD::FCEIL, MVT::v2f64, Expand); |
| 501 | setOperationAction(ISD::FTRUNC, MVT::v2f64, Expand); |
| 502 | setOperationAction(ISD::FRINT, MVT::v2f64, Expand); |
| 503 | setOperationAction(ISD::FNEARBYINT, MVT::v2f64, Expand); |
| 504 | setOperationAction(ISD::FFLOOR, MVT::v2f64, Expand); |
Stepan Dyatkovskiy | 3e0dc06 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 505 | |
| 506 | setOperationAction(ISD::FSQRT, MVT::v4f32, Expand); |
| 507 | setOperationAction(ISD::FSIN, MVT::v4f32, Expand); |
| 508 | setOperationAction(ISD::FCOS, MVT::v4f32, Expand); |
| 509 | setOperationAction(ISD::FPOWI, MVT::v4f32, Expand); |
| 510 | setOperationAction(ISD::FPOW, MVT::v4f32, Expand); |
| 511 | setOperationAction(ISD::FLOG, MVT::v4f32, Expand); |
| 512 | setOperationAction(ISD::FLOG2, MVT::v4f32, Expand); |
| 513 | setOperationAction(ISD::FLOG10, MVT::v4f32, Expand); |
| 514 | setOperationAction(ISD::FEXP, MVT::v4f32, Expand); |
| 515 | setOperationAction(ISD::FEXP2, MVT::v4f32, Expand); |
Bob Wilson | 74dc72e | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 516 | |
Bob Wilson | 642b329 | 2009-09-16 00:32:15 +0000 | [diff] [blame] | 517 | // Neon does not support some operations on v1i64 and v2i64 types. |
| 518 | setOperationAction(ISD::MUL, MVT::v1i64, Expand); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 519 | // Custom handling for some quad-vector types to detect VMULL. |
| 520 | setOperationAction(ISD::MUL, MVT::v8i16, Custom); |
| 521 | setOperationAction(ISD::MUL, MVT::v4i32, Custom); |
| 522 | setOperationAction(ISD::MUL, MVT::v2i64, Custom); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 523 | // Custom handling for some vector types to avoid expensive expansions |
| 524 | setOperationAction(ISD::SDIV, MVT::v4i16, Custom); |
| 525 | setOperationAction(ISD::SDIV, MVT::v8i8, Custom); |
| 526 | setOperationAction(ISD::UDIV, MVT::v4i16, Custom); |
| 527 | setOperationAction(ISD::UDIV, MVT::v8i8, Custom); |
Duncan Sands | 28b77e9 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 528 | setOperationAction(ISD::SETCC, MVT::v1i64, Expand); |
| 529 | setOperationAction(ISD::SETCC, MVT::v2i64, Expand); |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 530 | // Neon does not have single instruction SINT_TO_FP and UINT_TO_FP with |
| 531 | // a destination type that is wider than the source. |
| 532 | setOperationAction(ISD::SINT_TO_FP, MVT::v4i16, Custom); |
| 533 | setOperationAction(ISD::UINT_TO_FP, MVT::v4i16, Custom); |
Bob Wilson | 642b329 | 2009-09-16 00:32:15 +0000 | [diff] [blame] | 534 | |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 535 | setTargetDAGCombine(ISD::INTRINSIC_VOID); |
| 536 | setTargetDAGCombine(ISD::INTRINSIC_W_CHAIN); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 537 | setTargetDAGCombine(ISD::INTRINSIC_WO_CHAIN); |
| 538 | setTargetDAGCombine(ISD::SHL); |
| 539 | setTargetDAGCombine(ISD::SRL); |
| 540 | setTargetDAGCombine(ISD::SRA); |
| 541 | setTargetDAGCombine(ISD::SIGN_EXTEND); |
| 542 | setTargetDAGCombine(ISD::ZERO_EXTEND); |
| 543 | setTargetDAGCombine(ISD::ANY_EXTEND); |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 544 | setTargetDAGCombine(ISD::SELECT_CC); |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 545 | setTargetDAGCombine(ISD::BUILD_VECTOR); |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 546 | setTargetDAGCombine(ISD::VECTOR_SHUFFLE); |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 547 | setTargetDAGCombine(ISD::INSERT_VECTOR_ELT); |
| 548 | setTargetDAGCombine(ISD::STORE); |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 549 | setTargetDAGCombine(ISD::FP_TO_SINT); |
| 550 | setTargetDAGCombine(ISD::FP_TO_UINT); |
| 551 | setTargetDAGCombine(ISD::FDIV); |
Nadav Rotem | 004a24b | 2011-10-15 20:03:12 +0000 | [diff] [blame] | 552 | |
| 553 | setLoadExtAction(ISD::EXTLOAD, MVT::v4i8, Expand); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 554 | } |
| 555 | |
Evan Cheng | 9f8cbd1 | 2007-05-18 00:19:34 +0000 | [diff] [blame] | 556 | computeRegisterProperties(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 557 | |
| 558 | // ARM does not have f32 extending load. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 559 | setLoadExtAction(ISD::EXTLOAD, MVT::f32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 560 | |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 561 | // ARM does not have i1 sign extending load. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 562 | setLoadExtAction(ISD::SEXTLOAD, MVT::i1, Promote); |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 563 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 564 | // ARM supports all 4 flavors of integer indexed load / store. |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 565 | if (!Subtarget->isThumb1Only()) { |
| 566 | for (unsigned im = (unsigned)ISD::PRE_INC; |
| 567 | im != (unsigned)ISD::LAST_INDEXED_MODE; ++im) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 568 | setIndexedLoadAction(im, MVT::i1, Legal); |
| 569 | setIndexedLoadAction(im, MVT::i8, Legal); |
| 570 | setIndexedLoadAction(im, MVT::i16, Legal); |
| 571 | setIndexedLoadAction(im, MVT::i32, Legal); |
| 572 | setIndexedStoreAction(im, MVT::i1, Legal); |
| 573 | setIndexedStoreAction(im, MVT::i8, Legal); |
| 574 | setIndexedStoreAction(im, MVT::i16, Legal); |
| 575 | setIndexedStoreAction(im, MVT::i32, Legal); |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 576 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | // i64 operation support. |
Eric Christopher | 2cc4013 | 2011-04-19 18:49:19 +0000 | [diff] [blame] | 580 | setOperationAction(ISD::MUL, MVT::i64, Expand); |
| 581 | setOperationAction(ISD::MULHU, MVT::i32, Expand); |
Evan Cheng | 5b9fcd1 | 2009-07-07 01:17:28 +0000 | [diff] [blame] | 582 | if (Subtarget->isThumb1Only()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 583 | setOperationAction(ISD::UMUL_LOHI, MVT::i32, Expand); |
| 584 | setOperationAction(ISD::SMUL_LOHI, MVT::i32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 585 | } |
Jim Grosbach | a760398 | 2011-07-01 21:12:19 +0000 | [diff] [blame] | 586 | if (Subtarget->isThumb1Only() || !Subtarget->hasV6Ops() |
| 587 | || (Subtarget->isThumb2() && !Subtarget->hasThumb2DSP())) |
Eric Christopher | 2cc4013 | 2011-04-19 18:49:19 +0000 | [diff] [blame] | 588 | setOperationAction(ISD::MULHS, MVT::i32, Expand); |
| 589 | |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 590 | setOperationAction(ISD::SHL_PARTS, MVT::i32, Custom); |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 591 | setOperationAction(ISD::SRA_PARTS, MVT::i32, Custom); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 592 | setOperationAction(ISD::SRL_PARTS, MVT::i32, Custom); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 593 | setOperationAction(ISD::SRL, MVT::i64, Custom); |
| 594 | setOperationAction(ISD::SRA, MVT::i64, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 595 | |
Evan Cheng | 342e316 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 596 | if (!Subtarget->isThumb1Only()) { |
| 597 | // FIXME: We should do this for Thumb1 as well. |
| 598 | setOperationAction(ISD::ADDC, MVT::i32, Custom); |
| 599 | setOperationAction(ISD::ADDE, MVT::i32, Custom); |
| 600 | setOperationAction(ISD::SUBC, MVT::i32, Custom); |
| 601 | setOperationAction(ISD::SUBE, MVT::i32, Custom); |
| 602 | } |
| 603 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 604 | // ARM does not have ROTL. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 605 | setOperationAction(ISD::ROTL, MVT::i32, Expand); |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 606 | setOperationAction(ISD::CTTZ, MVT::i32, Custom); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 607 | setOperationAction(ISD::CTPOP, MVT::i32, Expand); |
David Goodwin | 24062ac | 2009-06-26 20:47:43 +0000 | [diff] [blame] | 608 | if (!Subtarget->hasV5TOps() || Subtarget->isThumb1Only()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 609 | setOperationAction(ISD::CTLZ, MVT::i32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 610 | |
Chandler Carruth | 63974b2 | 2011-12-13 01:56:10 +0000 | [diff] [blame] | 611 | // These just redirect to CTTZ and CTLZ on ARM. |
| 612 | setOperationAction(ISD::CTTZ_ZERO_UNDEF , MVT::i32 , Expand); |
| 613 | setOperationAction(ISD::CTLZ_ZERO_UNDEF , MVT::i32 , Expand); |
| 614 | |
Lauro Ramos Venancio | 368f20f | 2007-03-16 22:54:16 +0000 | [diff] [blame] | 615 | // Only ARMv6 has BSWAP. |
| 616 | if (!Subtarget->hasV6Ops()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 617 | setOperationAction(ISD::BSWAP, MVT::i32, Expand); |
Lauro Ramos Venancio | 368f20f | 2007-03-16 22:54:16 +0000 | [diff] [blame] | 618 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 619 | // These are expanded into libcalls. |
Evan Cheng | 1f190c8 | 2010-11-19 06:28:11 +0000 | [diff] [blame] | 620 | if (!Subtarget->hasDivide() || !Subtarget->isThumb2()) { |
Jim Grosbach | b1dc393 | 2010-05-05 20:44:35 +0000 | [diff] [blame] | 621 | // v7M has a hardware divider |
| 622 | setOperationAction(ISD::SDIV, MVT::i32, Expand); |
| 623 | setOperationAction(ISD::UDIV, MVT::i32, Expand); |
| 624 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 625 | setOperationAction(ISD::SREM, MVT::i32, Expand); |
| 626 | setOperationAction(ISD::UREM, MVT::i32, Expand); |
| 627 | setOperationAction(ISD::SDIVREM, MVT::i32, Expand); |
| 628 | setOperationAction(ISD::UDIVREM, MVT::i32, Expand); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 629 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 630 | setOperationAction(ISD::GlobalAddress, MVT::i32, Custom); |
| 631 | setOperationAction(ISD::ConstantPool, MVT::i32, Custom); |
| 632 | setOperationAction(ISD::GLOBAL_OFFSET_TABLE, MVT::i32, Custom); |
| 633 | setOperationAction(ISD::GlobalTLSAddress, MVT::i32, Custom); |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 634 | setOperationAction(ISD::BlockAddress, MVT::i32, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 635 | |
Evan Cheng | 4da0c7c | 2011-04-08 21:37:21 +0000 | [diff] [blame] | 636 | setOperationAction(ISD::TRAP, MVT::Other, Legal); |
Evan Cheng | fb3611d | 2010-05-11 07:26:32 +0000 | [diff] [blame] | 637 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 638 | // Use the default implementation. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 639 | setOperationAction(ISD::VASTART, MVT::Other, Custom); |
| 640 | setOperationAction(ISD::VAARG, MVT::Other, Expand); |
| 641 | setOperationAction(ISD::VACOPY, MVT::Other, Expand); |
| 642 | setOperationAction(ISD::VAEND, MVT::Other, Expand); |
| 643 | setOperationAction(ISD::STACKSAVE, MVT::Other, Expand); |
| 644 | setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand); |
Jim Grosbach | bff3923 | 2009-08-12 17:38:44 +0000 | [diff] [blame] | 645 | setOperationAction(ISD::EHSELECTION, MVT::i32, Expand); |
Anton Korobeynikov | 5899a60 | 2011-01-24 22:38:45 +0000 | [diff] [blame] | 646 | setOperationAction(ISD::EXCEPTIONADDR, MVT::i32, Expand); |
| 647 | setExceptionPointerRegister(ARM::R0); |
| 648 | setExceptionSelectorRegister(ARM::R1); |
| 649 | |
Evan Cheng | 3a1588a | 2010-04-15 22:20:34 +0000 | [diff] [blame] | 650 | setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32, Expand); |
Evan Cheng | 11db068 | 2010-08-11 06:22:01 +0000 | [diff] [blame] | 651 | // ARMv6 Thumb1 (except for CPUs that support dmb / dsb) and earlier use |
| 652 | // the default expansion. |
Eli Friedman | 4db5aca | 2011-08-29 18:23:02 +0000 | [diff] [blame] | 653 | // FIXME: This should be checking for v6k, not just v6. |
Evan Cheng | 11db068 | 2010-08-11 06:22:01 +0000 | [diff] [blame] | 654 | if (Subtarget->hasDataBarrier() || |
Bob Wilson | 54f9256 | 2010-11-09 22:50:44 +0000 | [diff] [blame] | 655 | (Subtarget->hasV6Ops() && !Subtarget->isThumb())) { |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 656 | // membarrier needs custom lowering; the rest are legal and handled |
| 657 | // normally. |
| 658 | setOperationAction(ISD::MEMBARRIER, MVT::Other, Custom); |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 659 | setOperationAction(ISD::ATOMIC_FENCE, MVT::Other, Custom); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 660 | // Custom lowering for 64-bit ops |
| 661 | setOperationAction(ISD::ATOMIC_LOAD_ADD, MVT::i64, Custom); |
| 662 | setOperationAction(ISD::ATOMIC_LOAD_SUB, MVT::i64, Custom); |
| 663 | setOperationAction(ISD::ATOMIC_LOAD_AND, MVT::i64, Custom); |
| 664 | setOperationAction(ISD::ATOMIC_LOAD_OR, MVT::i64, Custom); |
| 665 | setOperationAction(ISD::ATOMIC_LOAD_XOR, MVT::i64, Custom); |
| 666 | setOperationAction(ISD::ATOMIC_SWAP, MVT::i64, Custom); |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 667 | setOperationAction(ISD::ATOMIC_CMP_SWAP, MVT::i64, Custom); |
Eli Friedman | 26689ac | 2011-08-03 21:06:02 +0000 | [diff] [blame] | 668 | // Automatically insert fences (dmb ist) around ATOMIC_SWAP etc. |
| 669 | setInsertFencesForAtomic(true); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 670 | } else { |
| 671 | // Set them all for expansion, which will force libcalls. |
| 672 | setOperationAction(ISD::MEMBARRIER, MVT::Other, Expand); |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 673 | setOperationAction(ISD::ATOMIC_FENCE, MVT::Other, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 674 | setOperationAction(ISD::ATOMIC_CMP_SWAP, MVT::i32, Expand); |
Jim Grosbach | ef6eb9c | 2010-06-18 23:03:10 +0000 | [diff] [blame] | 675 | setOperationAction(ISD::ATOMIC_SWAP, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 676 | setOperationAction(ISD::ATOMIC_LOAD_ADD, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 677 | setOperationAction(ISD::ATOMIC_LOAD_SUB, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 678 | setOperationAction(ISD::ATOMIC_LOAD_AND, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 679 | setOperationAction(ISD::ATOMIC_LOAD_OR, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 680 | setOperationAction(ISD::ATOMIC_LOAD_XOR, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 681 | setOperationAction(ISD::ATOMIC_LOAD_NAND, MVT::i32, Expand); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 682 | setOperationAction(ISD::ATOMIC_LOAD_MIN, MVT::i32, Expand); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 683 | setOperationAction(ISD::ATOMIC_LOAD_MAX, MVT::i32, Expand); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 684 | setOperationAction(ISD::ATOMIC_LOAD_UMIN, MVT::i32, Expand); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 685 | setOperationAction(ISD::ATOMIC_LOAD_UMAX, MVT::i32, Expand); |
Eli Friedman | 7cc1566 | 2011-09-15 22:18:49 +0000 | [diff] [blame] | 686 | // Mark ATOMIC_LOAD and ATOMIC_STORE custom so we can handle the |
| 687 | // Unordered/Monotonic case. |
| 688 | setOperationAction(ISD::ATOMIC_LOAD, MVT::i32, Custom); |
| 689 | setOperationAction(ISD::ATOMIC_STORE, MVT::i32, Custom); |
Jim Grosbach | 5def57a | 2010-06-23 16:08:49 +0000 | [diff] [blame] | 690 | // Since the libcalls include locking, fold in the fences |
| 691 | setShouldFoldAtomicFences(true); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 692 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 693 | |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 694 | setOperationAction(ISD::PREFETCH, MVT::Other, Custom); |
Evan Cheng | bc7deb0 | 2010-11-03 05:14:24 +0000 | [diff] [blame] | 695 | |
Eli Friedman | a2c6f45 | 2010-06-26 04:36:50 +0000 | [diff] [blame] | 696 | // Requires SXTB/SXTH, available on v6 and up in both ARM and Thumb modes. |
| 697 | if (!Subtarget->hasV6Ops()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 698 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i16, Expand); |
| 699 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i8, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 700 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 701 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 702 | |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 703 | if (!TM.Options.UseSoftFloat && Subtarget->hasVFP2() && |
| 704 | !Subtarget->isThumb1Only()) { |
Bob Wilson | cb9a6aa | 2010-01-19 22:56:26 +0000 | [diff] [blame] | 705 | // Turn f64->i64 into VMOVRRD, i64 -> f64 to VMOVDRR |
| 706 | // iff target supports vfp2. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 707 | setOperationAction(ISD::BITCAST, MVT::i64, Custom); |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 708 | setOperationAction(ISD::FLT_ROUNDS_, MVT::i32, Custom); |
| 709 | } |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 710 | |
| 711 | // We want to custom lower some of our intrinsics. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 712 | setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom); |
Jim Grosbach | e97f968 | 2010-07-07 00:07:57 +0000 | [diff] [blame] | 713 | if (Subtarget->isTargetDarwin()) { |
| 714 | setOperationAction(ISD::EH_SJLJ_SETJMP, MVT::i32, Custom); |
| 715 | setOperationAction(ISD::EH_SJLJ_LONGJMP, MVT::Other, Custom); |
John McCall | 5f8fd54 | 2011-05-29 19:50:32 +0000 | [diff] [blame] | 716 | setLibcallName(RTLIB::UNWIND_RESUME, "_Unwind_SjLj_Resume"); |
Jim Grosbach | e97f968 | 2010-07-07 00:07:57 +0000 | [diff] [blame] | 717 | } |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 718 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 719 | setOperationAction(ISD::SETCC, MVT::i32, Expand); |
| 720 | setOperationAction(ISD::SETCC, MVT::f32, Expand); |
| 721 | setOperationAction(ISD::SETCC, MVT::f64, Expand); |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 722 | setOperationAction(ISD::SELECT, MVT::i32, Custom); |
| 723 | setOperationAction(ISD::SELECT, MVT::f32, Custom); |
| 724 | setOperationAction(ISD::SELECT, MVT::f64, Custom); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 725 | setOperationAction(ISD::SELECT_CC, MVT::i32, Custom); |
| 726 | setOperationAction(ISD::SELECT_CC, MVT::f32, Custom); |
| 727 | setOperationAction(ISD::SELECT_CC, MVT::f64, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 728 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 729 | setOperationAction(ISD::BRCOND, MVT::Other, Expand); |
| 730 | setOperationAction(ISD::BR_CC, MVT::i32, Custom); |
| 731 | setOperationAction(ISD::BR_CC, MVT::f32, Custom); |
| 732 | setOperationAction(ISD::BR_CC, MVT::f64, Custom); |
| 733 | setOperationAction(ISD::BR_JT, MVT::Other, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 734 | |
Dan Gohman | f96e4de | 2007-10-11 23:21:31 +0000 | [diff] [blame] | 735 | // We don't support sin/cos/fmod/copysign/pow |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 736 | setOperationAction(ISD::FSIN, MVT::f64, Expand); |
| 737 | setOperationAction(ISD::FSIN, MVT::f32, Expand); |
| 738 | setOperationAction(ISD::FCOS, MVT::f32, Expand); |
| 739 | setOperationAction(ISD::FCOS, MVT::f64, Expand); |
| 740 | setOperationAction(ISD::FREM, MVT::f64, Expand); |
| 741 | setOperationAction(ISD::FREM, MVT::f32, Expand); |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 742 | if (!TM.Options.UseSoftFloat && Subtarget->hasVFP2() && |
| 743 | !Subtarget->isThumb1Only()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 744 | setOperationAction(ISD::FCOPYSIGN, MVT::f64, Custom); |
| 745 | setOperationAction(ISD::FCOPYSIGN, MVT::f32, Custom); |
Evan Cheng | 110cf48 | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 746 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 747 | setOperationAction(ISD::FPOW, MVT::f64, Expand); |
| 748 | setOperationAction(ISD::FPOW, MVT::f32, Expand); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 749 | |
Cameron Zwarich | 3339084 | 2011-07-08 21:39:21 +0000 | [diff] [blame] | 750 | setOperationAction(ISD::FMA, MVT::f64, Expand); |
| 751 | setOperationAction(ISD::FMA, MVT::f32, Expand); |
| 752 | |
Anton Korobeynikov | bec3dd2 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 753 | // Various VFP goodness |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 754 | if (!TM.Options.UseSoftFloat && !Subtarget->isThumb1Only()) { |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 755 | // int <-> fp are custom expanded into bit_convert + ARMISD ops. |
| 756 | if (Subtarget->hasVFP2()) { |
| 757 | setOperationAction(ISD::SINT_TO_FP, MVT::i32, Custom); |
| 758 | setOperationAction(ISD::UINT_TO_FP, MVT::i32, Custom); |
| 759 | setOperationAction(ISD::FP_TO_UINT, MVT::i32, Custom); |
| 760 | setOperationAction(ISD::FP_TO_SINT, MVT::i32, Custom); |
| 761 | } |
Anton Korobeynikov | bec3dd2 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 762 | // Special handling for half-precision FP. |
Anton Korobeynikov | f0d5007 | 2010-03-18 22:35:37 +0000 | [diff] [blame] | 763 | if (!Subtarget->hasFP16()) { |
| 764 | setOperationAction(ISD::FP16_TO_FP32, MVT::f32, Expand); |
| 765 | setOperationAction(ISD::FP32_TO_FP16, MVT::i32, Expand); |
Anton Korobeynikov | bec3dd2 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 766 | } |
Evan Cheng | 110cf48 | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 767 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 768 | |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 769 | // We have target-specific dag combine patterns for the following nodes: |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 770 | // ARMISD::VMOVRRD - No need to call setTargetDAGCombine |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 771 | setTargetDAGCombine(ISD::ADD); |
| 772 | setTargetDAGCombine(ISD::SUB); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 773 | setTargetDAGCombine(ISD::MUL); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 774 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 775 | if (Subtarget->hasV6T2Ops() || Subtarget->hasNEON()) |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 776 | setTargetDAGCombine(ISD::OR); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 777 | if (Subtarget->hasNEON()) |
| 778 | setTargetDAGCombine(ISD::AND); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 779 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 780 | setStackPointerRegisterToSaveRestore(ARM::SP); |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 781 | |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 782 | if (TM.Options.UseSoftFloat || Subtarget->isThumb1Only() || |
| 783 | !Subtarget->hasVFP2()) |
Evan Cheng | f7d87ee | 2010-05-21 00:43:17 +0000 | [diff] [blame] | 784 | setSchedulingPreference(Sched::RegPressure); |
| 785 | else |
| 786 | setSchedulingPreference(Sched::Hybrid); |
Dale Johannesen | 8dd86c1 | 2007-05-17 21:31:21 +0000 | [diff] [blame] | 787 | |
Evan Cheng | 0521928 | 2011-01-06 06:52:41 +0000 | [diff] [blame] | 788 | //// temporary - rewrite interface to use type |
| 789 | maxStoresPerMemcpy = maxStoresPerMemcpyOptSize = 1; |
Lang Hames | 75757f9 | 2011-10-26 20:56:52 +0000 | [diff] [blame] | 790 | maxStoresPerMemset = 16; |
| 791 | maxStoresPerMemsetOptSize = Subtarget->isTargetDarwin() ? 8 : 4; |
Evan Cheng | f679939 | 2010-06-26 01:52:05 +0000 | [diff] [blame] | 792 | |
Rafael Espindola | cbeeae2 | 2010-07-11 04:01:49 +0000 | [diff] [blame] | 793 | // On ARM arguments smaller than 4 bytes are extended, so all arguments |
| 794 | // are at least 4 bytes aligned. |
| 795 | setMinStackArgumentAlignment(4); |
| 796 | |
Evan Cheng | fff606d | 2010-09-24 19:07:23 +0000 | [diff] [blame] | 797 | benefitFromCodePlacementOpt = true; |
Eli Friedman | fc5d305 | 2011-05-06 20:34:06 +0000 | [diff] [blame] | 798 | |
| 799 | setMinFunctionAlignment(Subtarget->isThumb() ? 1 : 2); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 800 | } |
| 801 | |
Andrew Trick | 32cec0a | 2011-01-19 02:35:27 +0000 | [diff] [blame] | 802 | // FIXME: It might make sense to define the representative register class as the |
| 803 | // nearest super-register that has a non-null superset. For example, DPR_VFP2 is |
| 804 | // a super-register of SPR, and DPR is a superset if DPR_VFP2. Consequently, |
| 805 | // SPR's representative would be DPR_VFP2. This should work well if register |
| 806 | // pressure tracking were modified such that a register use would increment the |
| 807 | // pressure of the register class's representative and all of it's super |
| 808 | // classes' representatives transitively. We have not implemented this because |
| 809 | // of the difficulty prior to coalescing of modeling operand register classes |
Chris Lattner | 7a2bdde | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 810 | // due to the common occurrence of cross class copies and subregister insertions |
Andrew Trick | 32cec0a | 2011-01-19 02:35:27 +0000 | [diff] [blame] | 811 | // and extractions. |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 812 | std::pair<const TargetRegisterClass*, uint8_t> |
| 813 | ARMTargetLowering::findRepresentativeClass(EVT VT) const{ |
| 814 | const TargetRegisterClass *RRC = 0; |
| 815 | uint8_t Cost = 1; |
| 816 | switch (VT.getSimpleVT().SimpleTy) { |
Evan Cheng | d70f57b | 2010-07-19 22:15:08 +0000 | [diff] [blame] | 817 | default: |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 818 | return TargetLowering::findRepresentativeClass(VT); |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 819 | // Use DPR as representative register class for all floating point |
| 820 | // and vector types. Since there are 32 SPR registers and 32 DPR registers so |
| 821 | // the cost is 1 for both f32 and f64. |
| 822 | case MVT::f32: case MVT::f64: case MVT::v8i8: case MVT::v4i16: |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 823 | case MVT::v2i32: case MVT::v1i64: case MVT::v2f32: |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 824 | RRC = ARM::DPRRegisterClass; |
Andrew Trick | 32cec0a | 2011-01-19 02:35:27 +0000 | [diff] [blame] | 825 | // When NEON is used for SP, only half of the register file is available |
| 826 | // because operations that define both SP and DP results will be constrained |
| 827 | // to the VFP2 class (D0-D15). We currently model this constraint prior to |
| 828 | // coalescing by double-counting the SP regs. See the FIXME above. |
| 829 | if (Subtarget->useNEONForSinglePrecisionFP()) |
| 830 | Cost = 2; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 831 | break; |
| 832 | case MVT::v16i8: case MVT::v8i16: case MVT::v4i32: case MVT::v2i64: |
| 833 | case MVT::v4f32: case MVT::v2f64: |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 834 | RRC = ARM::DPRRegisterClass; |
| 835 | Cost = 2; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 836 | break; |
| 837 | case MVT::v4i64: |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 838 | RRC = ARM::DPRRegisterClass; |
| 839 | Cost = 4; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 840 | break; |
| 841 | case MVT::v8i64: |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 842 | RRC = ARM::DPRRegisterClass; |
| 843 | Cost = 8; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 844 | break; |
Evan Cheng | d70f57b | 2010-07-19 22:15:08 +0000 | [diff] [blame] | 845 | } |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 846 | return std::make_pair(RRC, Cost); |
Evan Cheng | d70f57b | 2010-07-19 22:15:08 +0000 | [diff] [blame] | 847 | } |
| 848 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 849 | const char *ARMTargetLowering::getTargetNodeName(unsigned Opcode) const { |
| 850 | switch (Opcode) { |
| 851 | default: return 0; |
| 852 | case ARMISD::Wrapper: return "ARMISD::Wrapper"; |
Evan Cheng | 53519f0 | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 853 | case ARMISD::WrapperDYN: return "ARMISD::WrapperDYN"; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 854 | case ARMISD::WrapperPIC: return "ARMISD::WrapperPIC"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 855 | case ARMISD::WrapperJT: return "ARMISD::WrapperJT"; |
| 856 | case ARMISD::CALL: return "ARMISD::CALL"; |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 857 | case ARMISD::CALL_PRED: return "ARMISD::CALL_PRED"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 858 | case ARMISD::CALL_NOLINK: return "ARMISD::CALL_NOLINK"; |
| 859 | case ARMISD::tCALL: return "ARMISD::tCALL"; |
| 860 | case ARMISD::BRCOND: return "ARMISD::BRCOND"; |
| 861 | case ARMISD::BR_JT: return "ARMISD::BR_JT"; |
Evan Cheng | 5657c01 | 2009-07-29 02:18:14 +0000 | [diff] [blame] | 862 | case ARMISD::BR2_JT: return "ARMISD::BR2_JT"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 863 | case ARMISD::RET_FLAG: return "ARMISD::RET_FLAG"; |
| 864 | case ARMISD::PIC_ADD: return "ARMISD::PIC_ADD"; |
| 865 | case ARMISD::CMP: return "ARMISD::CMP"; |
David Goodwin | c0309b4 | 2009-06-29 15:33:01 +0000 | [diff] [blame] | 866 | case ARMISD::CMPZ: return "ARMISD::CMPZ"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 867 | case ARMISD::CMPFP: return "ARMISD::CMPFP"; |
| 868 | case ARMISD::CMPFPw0: return "ARMISD::CMPFPw0"; |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 869 | case ARMISD::BCC_i64: return "ARMISD::BCC_i64"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 870 | case ARMISD::FMSTAT: return "ARMISD::FMSTAT"; |
| 871 | case ARMISD::CMOV: return "ARMISD::CMOV"; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 872 | |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 873 | case ARMISD::RBIT: return "ARMISD::RBIT"; |
| 874 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 875 | case ARMISD::FTOSI: return "ARMISD::FTOSI"; |
| 876 | case ARMISD::FTOUI: return "ARMISD::FTOUI"; |
| 877 | case ARMISD::SITOF: return "ARMISD::SITOF"; |
| 878 | case ARMISD::UITOF: return "ARMISD::UITOF"; |
| 879 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 880 | case ARMISD::SRL_FLAG: return "ARMISD::SRL_FLAG"; |
| 881 | case ARMISD::SRA_FLAG: return "ARMISD::SRA_FLAG"; |
| 882 | case ARMISD::RRX: return "ARMISD::RRX"; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 883 | |
Evan Cheng | 342e316 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 884 | case ARMISD::ADDC: return "ARMISD::ADDC"; |
| 885 | case ARMISD::ADDE: return "ARMISD::ADDE"; |
| 886 | case ARMISD::SUBC: return "ARMISD::SUBC"; |
| 887 | case ARMISD::SUBE: return "ARMISD::SUBE"; |
| 888 | |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 889 | case ARMISD::VMOVRRD: return "ARMISD::VMOVRRD"; |
| 890 | case ARMISD::VMOVDRR: return "ARMISD::VMOVDRR"; |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 891 | |
Evan Cheng | c594208 | 2009-10-28 06:55:03 +0000 | [diff] [blame] | 892 | case ARMISD::EH_SJLJ_SETJMP: return "ARMISD::EH_SJLJ_SETJMP"; |
| 893 | case ARMISD::EH_SJLJ_LONGJMP:return "ARMISD::EH_SJLJ_LONGJMP"; |
| 894 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 895 | case ARMISD::TC_RETURN: return "ARMISD::TC_RETURN"; |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 896 | |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 897 | case ARMISD::THREAD_POINTER:return "ARMISD::THREAD_POINTER"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 898 | |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 899 | case ARMISD::DYN_ALLOC: return "ARMISD::DYN_ALLOC"; |
| 900 | |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 901 | case ARMISD::MEMBARRIER: return "ARMISD::MEMBARRIER"; |
Bob Wilson | f74a429 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 902 | case ARMISD::MEMBARRIER_MCR: return "ARMISD::MEMBARRIER_MCR"; |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 903 | |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 904 | case ARMISD::PRELOAD: return "ARMISD::PRELOAD"; |
| 905 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 906 | case ARMISD::VCEQ: return "ARMISD::VCEQ"; |
Bob Wilson | 3a75b9b | 2010-12-18 00:04:26 +0000 | [diff] [blame] | 907 | case ARMISD::VCEQZ: return "ARMISD::VCEQZ"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 908 | case ARMISD::VCGE: return "ARMISD::VCGE"; |
Bob Wilson | 3a75b9b | 2010-12-18 00:04:26 +0000 | [diff] [blame] | 909 | case ARMISD::VCGEZ: return "ARMISD::VCGEZ"; |
| 910 | case ARMISD::VCLEZ: return "ARMISD::VCLEZ"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 911 | case ARMISD::VCGEU: return "ARMISD::VCGEU"; |
| 912 | case ARMISD::VCGT: return "ARMISD::VCGT"; |
Bob Wilson | 3a75b9b | 2010-12-18 00:04:26 +0000 | [diff] [blame] | 913 | case ARMISD::VCGTZ: return "ARMISD::VCGTZ"; |
| 914 | case ARMISD::VCLTZ: return "ARMISD::VCLTZ"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 915 | case ARMISD::VCGTU: return "ARMISD::VCGTU"; |
| 916 | case ARMISD::VTST: return "ARMISD::VTST"; |
| 917 | |
| 918 | case ARMISD::VSHL: return "ARMISD::VSHL"; |
| 919 | case ARMISD::VSHRs: return "ARMISD::VSHRs"; |
| 920 | case ARMISD::VSHRu: return "ARMISD::VSHRu"; |
| 921 | case ARMISD::VSHLLs: return "ARMISD::VSHLLs"; |
| 922 | case ARMISD::VSHLLu: return "ARMISD::VSHLLu"; |
| 923 | case ARMISD::VSHLLi: return "ARMISD::VSHLLi"; |
| 924 | case ARMISD::VSHRN: return "ARMISD::VSHRN"; |
| 925 | case ARMISD::VRSHRs: return "ARMISD::VRSHRs"; |
| 926 | case ARMISD::VRSHRu: return "ARMISD::VRSHRu"; |
| 927 | case ARMISD::VRSHRN: return "ARMISD::VRSHRN"; |
| 928 | case ARMISD::VQSHLs: return "ARMISD::VQSHLs"; |
| 929 | case ARMISD::VQSHLu: return "ARMISD::VQSHLu"; |
| 930 | case ARMISD::VQSHLsu: return "ARMISD::VQSHLsu"; |
| 931 | case ARMISD::VQSHRNs: return "ARMISD::VQSHRNs"; |
| 932 | case ARMISD::VQSHRNu: return "ARMISD::VQSHRNu"; |
| 933 | case ARMISD::VQSHRNsu: return "ARMISD::VQSHRNsu"; |
| 934 | case ARMISD::VQRSHRNs: return "ARMISD::VQRSHRNs"; |
| 935 | case ARMISD::VQRSHRNu: return "ARMISD::VQRSHRNu"; |
| 936 | case ARMISD::VQRSHRNsu: return "ARMISD::VQRSHRNsu"; |
| 937 | case ARMISD::VGETLANEu: return "ARMISD::VGETLANEu"; |
| 938 | case ARMISD::VGETLANEs: return "ARMISD::VGETLANEs"; |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 939 | case ARMISD::VMOVIMM: return "ARMISD::VMOVIMM"; |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 940 | case ARMISD::VMVNIMM: return "ARMISD::VMVNIMM"; |
Evan Cheng | eaa192a | 2011-11-15 02:12:34 +0000 | [diff] [blame] | 941 | case ARMISD::VMOVFPIMM: return "ARMISD::VMOVFPIMM"; |
Bob Wilson | c1d287b | 2009-08-14 05:13:08 +0000 | [diff] [blame] | 942 | case ARMISD::VDUP: return "ARMISD::VDUP"; |
Bob Wilson | 0ce3710 | 2009-08-14 05:08:32 +0000 | [diff] [blame] | 943 | case ARMISD::VDUPLANE: return "ARMISD::VDUPLANE"; |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 944 | case ARMISD::VEXT: return "ARMISD::VEXT"; |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 945 | case ARMISD::VREV64: return "ARMISD::VREV64"; |
| 946 | case ARMISD::VREV32: return "ARMISD::VREV32"; |
| 947 | case ARMISD::VREV16: return "ARMISD::VREV16"; |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 948 | case ARMISD::VZIP: return "ARMISD::VZIP"; |
| 949 | case ARMISD::VUZP: return "ARMISD::VUZP"; |
| 950 | case ARMISD::VTRN: return "ARMISD::VTRN"; |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 951 | case ARMISD::VTBL1: return "ARMISD::VTBL1"; |
| 952 | case ARMISD::VTBL2: return "ARMISD::VTBL2"; |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 953 | case ARMISD::VMULLs: return "ARMISD::VMULLs"; |
| 954 | case ARMISD::VMULLu: return "ARMISD::VMULLu"; |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 955 | case ARMISD::BUILD_VECTOR: return "ARMISD::BUILD_VECTOR"; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 956 | case ARMISD::FMAX: return "ARMISD::FMAX"; |
| 957 | case ARMISD::FMIN: return "ARMISD::FMIN"; |
Jim Grosbach | dd7d28a | 2010-07-17 01:50:57 +0000 | [diff] [blame] | 958 | case ARMISD::BFI: return "ARMISD::BFI"; |
Bob Wilson | 364a72a | 2010-11-28 06:51:11 +0000 | [diff] [blame] | 959 | case ARMISD::VORRIMM: return "ARMISD::VORRIMM"; |
| 960 | case ARMISD::VBICIMM: return "ARMISD::VBICIMM"; |
Cameron Zwarich | c0e6d78 | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 961 | case ARMISD::VBSL: return "ARMISD::VBSL"; |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 962 | case ARMISD::VLD2DUP: return "ARMISD::VLD2DUP"; |
| 963 | case ARMISD::VLD3DUP: return "ARMISD::VLD3DUP"; |
| 964 | case ARMISD::VLD4DUP: return "ARMISD::VLD4DUP"; |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 965 | case ARMISD::VLD1_UPD: return "ARMISD::VLD1_UPD"; |
| 966 | case ARMISD::VLD2_UPD: return "ARMISD::VLD2_UPD"; |
| 967 | case ARMISD::VLD3_UPD: return "ARMISD::VLD3_UPD"; |
| 968 | case ARMISD::VLD4_UPD: return "ARMISD::VLD4_UPD"; |
| 969 | case ARMISD::VLD2LN_UPD: return "ARMISD::VLD2LN_UPD"; |
| 970 | case ARMISD::VLD3LN_UPD: return "ARMISD::VLD3LN_UPD"; |
| 971 | case ARMISD::VLD4LN_UPD: return "ARMISD::VLD4LN_UPD"; |
| 972 | case ARMISD::VLD2DUP_UPD: return "ARMISD::VLD2DUP_UPD"; |
| 973 | case ARMISD::VLD3DUP_UPD: return "ARMISD::VLD3DUP_UPD"; |
| 974 | case ARMISD::VLD4DUP_UPD: return "ARMISD::VLD4DUP_UPD"; |
| 975 | case ARMISD::VST1_UPD: return "ARMISD::VST1_UPD"; |
| 976 | case ARMISD::VST2_UPD: return "ARMISD::VST2_UPD"; |
| 977 | case ARMISD::VST3_UPD: return "ARMISD::VST3_UPD"; |
| 978 | case ARMISD::VST4_UPD: return "ARMISD::VST4_UPD"; |
| 979 | case ARMISD::VST2LN_UPD: return "ARMISD::VST2LN_UPD"; |
| 980 | case ARMISD::VST3LN_UPD: return "ARMISD::VST3LN_UPD"; |
| 981 | case ARMISD::VST4LN_UPD: return "ARMISD::VST4LN_UPD"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 982 | } |
| 983 | } |
| 984 | |
Duncan Sands | 28b77e9 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 985 | EVT ARMTargetLowering::getSetCCResultType(EVT VT) const { |
| 986 | if (!VT.isVector()) return getPointerTy(); |
| 987 | return VT.changeVectorElementTypeToInteger(); |
| 988 | } |
| 989 | |
Evan Cheng | 06b666c | 2010-05-15 02:18:07 +0000 | [diff] [blame] | 990 | /// getRegClassFor - Return the register class that should be used for the |
| 991 | /// specified value type. |
| 992 | TargetRegisterClass *ARMTargetLowering::getRegClassFor(EVT VT) const { |
| 993 | // Map v4i64 to QQ registers but do not make the type legal. Similarly map |
| 994 | // v8i64 to QQQQ registers. v4i64 and v8i64 are only used for REG_SEQUENCE to |
| 995 | // load / store 4 to 8 consecutive D registers. |
Evan Cheng | 4782b1e | 2010-05-15 02:20:21 +0000 | [diff] [blame] | 996 | if (Subtarget->hasNEON()) { |
| 997 | if (VT == MVT::v4i64) |
| 998 | return ARM::QQPRRegisterClass; |
| 999 | else if (VT == MVT::v8i64) |
| 1000 | return ARM::QQQQPRRegisterClass; |
| 1001 | } |
Evan Cheng | 06b666c | 2010-05-15 02:18:07 +0000 | [diff] [blame] | 1002 | return TargetLowering::getRegClassFor(VT); |
| 1003 | } |
| 1004 | |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 1005 | // Create a fast isel object. |
| 1006 | FastISel * |
| 1007 | ARMTargetLowering::createFastISel(FunctionLoweringInfo &funcInfo) const { |
| 1008 | return ARM::createFastISel(funcInfo); |
| 1009 | } |
| 1010 | |
Anton Korobeynikov | cec36f4 | 2010-07-24 21:52:08 +0000 | [diff] [blame] | 1011 | /// getMaximalGlobalOffset - Returns the maximal possible offset which can |
| 1012 | /// be used for loads / stores from the global. |
| 1013 | unsigned ARMTargetLowering::getMaximalGlobalOffset() const { |
| 1014 | return (Subtarget->isThumb1Only() ? 127 : 4095); |
| 1015 | } |
| 1016 | |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1017 | Sched::Preference ARMTargetLowering::getSchedulingPreference(SDNode *N) const { |
Evan Cheng | c10f543 | 2010-05-28 23:25:23 +0000 | [diff] [blame] | 1018 | unsigned NumVals = N->getNumValues(); |
| 1019 | if (!NumVals) |
| 1020 | return Sched::RegPressure; |
| 1021 | |
| 1022 | for (unsigned i = 0; i != NumVals; ++i) { |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1023 | EVT VT = N->getValueType(i); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 1024 | if (VT == MVT::Glue || VT == MVT::Other) |
Evan Cheng | d7e473c | 2010-10-29 18:07:31 +0000 | [diff] [blame] | 1025 | continue; |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1026 | if (VT.isFloatingPoint() || VT.isVector()) |
Dan Gohman | 692c1d8 | 2011-10-24 17:55:11 +0000 | [diff] [blame] | 1027 | return Sched::ILP; |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1028 | } |
Evan Cheng | c10f543 | 2010-05-28 23:25:23 +0000 | [diff] [blame] | 1029 | |
| 1030 | if (!N->isMachineOpcode()) |
| 1031 | return Sched::RegPressure; |
| 1032 | |
| 1033 | // Load are scheduled for latency even if there instruction itinerary |
| 1034 | // is not available. |
| 1035 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 1036 | const MCInstrDesc &MCID = TII->get(N->getMachineOpcode()); |
Evan Cheng | d7e473c | 2010-10-29 18:07:31 +0000 | [diff] [blame] | 1037 | |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 1038 | if (MCID.getNumDefs() == 0) |
Evan Cheng | d7e473c | 2010-10-29 18:07:31 +0000 | [diff] [blame] | 1039 | return Sched::RegPressure; |
| 1040 | if (!Itins->isEmpty() && |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 1041 | Itins->getOperandCycle(MCID.getSchedClass(), 0) > 2) |
Dan Gohman | 692c1d8 | 2011-10-24 17:55:11 +0000 | [diff] [blame] | 1042 | return Sched::ILP; |
Evan Cheng | c10f543 | 2010-05-28 23:25:23 +0000 | [diff] [blame] | 1043 | |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1044 | return Sched::RegPressure; |
| 1045 | } |
| 1046 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1047 | //===----------------------------------------------------------------------===// |
| 1048 | // Lowering Code |
| 1049 | //===----------------------------------------------------------------------===// |
| 1050 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1051 | /// IntCCToARMCC - Convert a DAG integer condition code to an ARM CC |
| 1052 | static ARMCC::CondCodes IntCCToARMCC(ISD::CondCode CC) { |
| 1053 | switch (CC) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1054 | default: llvm_unreachable("Unknown condition code!"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1055 | case ISD::SETNE: return ARMCC::NE; |
| 1056 | case ISD::SETEQ: return ARMCC::EQ; |
| 1057 | case ISD::SETGT: return ARMCC::GT; |
| 1058 | case ISD::SETGE: return ARMCC::GE; |
| 1059 | case ISD::SETLT: return ARMCC::LT; |
| 1060 | case ISD::SETLE: return ARMCC::LE; |
| 1061 | case ISD::SETUGT: return ARMCC::HI; |
| 1062 | case ISD::SETUGE: return ARMCC::HS; |
| 1063 | case ISD::SETULT: return ARMCC::LO; |
| 1064 | case ISD::SETULE: return ARMCC::LS; |
| 1065 | } |
| 1066 | } |
| 1067 | |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 1068 | /// FPCCToARMCC - Convert a DAG fp condition code to an ARM CC. |
| 1069 | static void FPCCToARMCC(ISD::CondCode CC, ARMCC::CondCodes &CondCode, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1070 | ARMCC::CondCodes &CondCode2) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1071 | CondCode2 = ARMCC::AL; |
| 1072 | switch (CC) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1073 | default: llvm_unreachable("Unknown FP condition!"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1074 | case ISD::SETEQ: |
| 1075 | case ISD::SETOEQ: CondCode = ARMCC::EQ; break; |
| 1076 | case ISD::SETGT: |
| 1077 | case ISD::SETOGT: CondCode = ARMCC::GT; break; |
| 1078 | case ISD::SETGE: |
| 1079 | case ISD::SETOGE: CondCode = ARMCC::GE; break; |
| 1080 | case ISD::SETOLT: CondCode = ARMCC::MI; break; |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 1081 | case ISD::SETOLE: CondCode = ARMCC::LS; break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1082 | case ISD::SETONE: CondCode = ARMCC::MI; CondCode2 = ARMCC::GT; break; |
| 1083 | case ISD::SETO: CondCode = ARMCC::VC; break; |
| 1084 | case ISD::SETUO: CondCode = ARMCC::VS; break; |
| 1085 | case ISD::SETUEQ: CondCode = ARMCC::EQ; CondCode2 = ARMCC::VS; break; |
| 1086 | case ISD::SETUGT: CondCode = ARMCC::HI; break; |
| 1087 | case ISD::SETUGE: CondCode = ARMCC::PL; break; |
| 1088 | case ISD::SETLT: |
| 1089 | case ISD::SETULT: CondCode = ARMCC::LT; break; |
| 1090 | case ISD::SETLE: |
| 1091 | case ISD::SETULE: CondCode = ARMCC::LE; break; |
| 1092 | case ISD::SETNE: |
| 1093 | case ISD::SETUNE: CondCode = ARMCC::NE; break; |
| 1094 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1095 | } |
| 1096 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1097 | //===----------------------------------------------------------------------===// |
| 1098 | // Calling Convention Implementation |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1099 | //===----------------------------------------------------------------------===// |
| 1100 | |
| 1101 | #include "ARMGenCallingConv.inc" |
| 1102 | |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1103 | /// CCAssignFnForNode - Selects the correct CCAssignFn for a the |
| 1104 | /// given CallingConvention value. |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1105 | CCAssignFn *ARMTargetLowering::CCAssignFnForNode(CallingConv::ID CC, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1106 | bool Return, |
| 1107 | bool isVarArg) const { |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1108 | switch (CC) { |
| 1109 | default: |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1110 | llvm_unreachable("Unsupported calling convention"); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1111 | case CallingConv::Fast: |
Evan Cheng | 5c2d428 | 2010-10-23 02:19:37 +0000 | [diff] [blame] | 1112 | if (Subtarget->hasVFP2() && !isVarArg) { |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1113 | if (!Subtarget->isAAPCS_ABI()) |
| 1114 | return (Return ? RetFastCC_ARM_APCS : FastCC_ARM_APCS); |
| 1115 | // For AAPCS ABI targets, just use VFP variant of the calling convention. |
| 1116 | return (Return ? RetCC_ARM_AAPCS_VFP : CC_ARM_AAPCS_VFP); |
| 1117 | } |
| 1118 | // Fallthrough |
| 1119 | case CallingConv::C: { |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1120 | // Use target triple & subtarget features to do actual dispatch. |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1121 | if (!Subtarget->isAAPCS_ABI()) |
| 1122 | return (Return ? RetCC_ARM_APCS : CC_ARM_APCS); |
| 1123 | else if (Subtarget->hasVFP2() && |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 1124 | getTargetMachine().Options.FloatABIType == FloatABI::Hard && |
| 1125 | !isVarArg) |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1126 | return (Return ? RetCC_ARM_AAPCS_VFP : CC_ARM_AAPCS_VFP); |
| 1127 | return (Return ? RetCC_ARM_AAPCS : CC_ARM_AAPCS); |
| 1128 | } |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1129 | case CallingConv::ARM_AAPCS_VFP: |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1130 | return (Return ? RetCC_ARM_AAPCS_VFP : CC_ARM_AAPCS_VFP); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1131 | case CallingConv::ARM_AAPCS: |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1132 | return (Return ? RetCC_ARM_AAPCS : CC_ARM_AAPCS); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1133 | case CallingConv::ARM_APCS: |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1134 | return (Return ? RetCC_ARM_APCS : CC_ARM_APCS); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1135 | } |
| 1136 | } |
| 1137 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1138 | /// LowerCallResult - Lower the result values of a call into the |
| 1139 | /// appropriate copies out of appropriate physical registers. |
| 1140 | SDValue |
| 1141 | ARMTargetLowering::LowerCallResult(SDValue Chain, SDValue InFlag, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1142 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1143 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 1144 | DebugLoc dl, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1145 | SmallVectorImpl<SDValue> &InVals) const { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1146 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1147 | // Assign locations to each value returned by this call. |
| 1148 | SmallVector<CCValAssign, 16> RVLocs; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1149 | ARMCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), |
| 1150 | getTargetMachine(), RVLocs, *DAG.getContext(), Call); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1151 | CCInfo.AnalyzeCallResult(Ins, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1152 | CCAssignFnForNode(CallConv, /* Return*/ true, |
| 1153 | isVarArg)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1154 | |
| 1155 | // Copy all of the result registers out of their specified physreg. |
| 1156 | for (unsigned i = 0; i != RVLocs.size(); ++i) { |
| 1157 | CCValAssign VA = RVLocs[i]; |
| 1158 | |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1159 | SDValue Val; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1160 | if (VA.needsCustom()) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1161 | // Handle f64 or half of a v2f64. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1162 | SDValue Lo = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1163 | InFlag); |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1164 | Chain = Lo.getValue(1); |
| 1165 | InFlag = Lo.getValue(2); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1166 | VA = RVLocs[++i]; // skip ahead to next loc |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1167 | SDValue Hi = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1168 | InFlag); |
| 1169 | Chain = Hi.getValue(1); |
| 1170 | InFlag = Hi.getValue(2); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1171 | Val = DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1172 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1173 | if (VA.getLocVT() == MVT::v2f64) { |
| 1174 | SDValue Vec = DAG.getNode(ISD::UNDEF, dl, MVT::v2f64); |
| 1175 | Vec = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Vec, Val, |
| 1176 | DAG.getConstant(0, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1177 | |
| 1178 | VA = RVLocs[++i]; // skip ahead to next loc |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1179 | Lo = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, InFlag); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1180 | Chain = Lo.getValue(1); |
| 1181 | InFlag = Lo.getValue(2); |
| 1182 | VA = RVLocs[++i]; // skip ahead to next loc |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1183 | Hi = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, InFlag); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1184 | Chain = Hi.getValue(1); |
| 1185 | InFlag = Hi.getValue(2); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1186 | Val = DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1187 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Vec, Val, |
| 1188 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1189 | } |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1190 | } else { |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1191 | Val = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), VA.getLocVT(), |
| 1192 | InFlag); |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1193 | Chain = Val.getValue(1); |
| 1194 | InFlag = Val.getValue(2); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1195 | } |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1196 | |
| 1197 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1198 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1199 | case CCValAssign::Full: break; |
| 1200 | case CCValAssign::BCvt: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1201 | Val = DAG.getNode(ISD::BITCAST, dl, VA.getValVT(), Val); |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1202 | break; |
| 1203 | } |
| 1204 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1205 | InVals.push_back(Val); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1206 | } |
| 1207 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1208 | return Chain; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1209 | } |
| 1210 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1211 | /// LowerMemOpCallTo - Store the argument to the stack. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1212 | SDValue |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1213 | ARMTargetLowering::LowerMemOpCallTo(SDValue Chain, |
| 1214 | SDValue StackPtr, SDValue Arg, |
| 1215 | DebugLoc dl, SelectionDAG &DAG, |
| 1216 | const CCValAssign &VA, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1217 | ISD::ArgFlagsTy Flags) const { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1218 | unsigned LocMemOffset = VA.getLocMemOffset(); |
| 1219 | SDValue PtrOff = DAG.getIntPtrConstant(LocMemOffset); |
| 1220 | PtrOff = DAG.getNode(ISD::ADD, dl, getPointerTy(), StackPtr, PtrOff); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1221 | return DAG.getStore(Chain, dl, Arg, PtrOff, |
Chris Lattner | fc448ff | 2010-09-21 18:51:21 +0000 | [diff] [blame] | 1222 | MachinePointerInfo::getStack(LocMemOffset), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1223 | false, false, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1224 | } |
| 1225 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1226 | void ARMTargetLowering::PassF64ArgInRegs(DebugLoc dl, SelectionDAG &DAG, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1227 | SDValue Chain, SDValue &Arg, |
| 1228 | RegsToPassVector &RegsToPass, |
| 1229 | CCValAssign &VA, CCValAssign &NextVA, |
| 1230 | SDValue &StackPtr, |
| 1231 | SmallVector<SDValue, 8> &MemOpChains, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1232 | ISD::ArgFlagsTy Flags) const { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1233 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1234 | SDValue fmrrd = DAG.getNode(ARMISD::VMOVRRD, dl, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1235 | DAG.getVTList(MVT::i32, MVT::i32), Arg); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1236 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), fmrrd)); |
| 1237 | |
| 1238 | if (NextVA.isRegLoc()) |
| 1239 | RegsToPass.push_back(std::make_pair(NextVA.getLocReg(), fmrrd.getValue(1))); |
| 1240 | else { |
| 1241 | assert(NextVA.isMemLoc()); |
| 1242 | if (StackPtr.getNode() == 0) |
| 1243 | StackPtr = DAG.getCopyFromReg(Chain, dl, ARM::SP, getPointerTy()); |
| 1244 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1245 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, fmrrd.getValue(1), |
| 1246 | dl, DAG, NextVA, |
| 1247 | Flags)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1248 | } |
| 1249 | } |
| 1250 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1251 | /// LowerCall - Lowering a call into a callseq_start <- |
Evan Cheng | fc40342 | 2007-02-03 08:53:01 +0000 | [diff] [blame] | 1252 | /// ARMISD:CALL <- callseq_end chain. Also add input and output parameter |
| 1253 | /// nodes. |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1254 | SDValue |
Evan Cheng | 022d9e1 | 2010-02-02 23:55:14 +0000 | [diff] [blame] | 1255 | ARMTargetLowering::LowerCall(SDValue Chain, SDValue Callee, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1256 | CallingConv::ID CallConv, bool isVarArg, |
Evan Cheng | 0c439eb | 2010-01-27 00:07:07 +0000 | [diff] [blame] | 1257 | bool &isTailCall, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1258 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1259 | const SmallVectorImpl<SDValue> &OutVals, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1260 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 1261 | DebugLoc dl, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1262 | SmallVectorImpl<SDValue> &InVals) const { |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1263 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1264 | bool IsStructRet = (Outs.empty()) ? false : Outs[0].Flags.isSRet(); |
| 1265 | bool IsSibCall = false; |
Bob Wilson | 6d2f9ce | 2011-10-07 17:17:49 +0000 | [diff] [blame] | 1266 | // Disable tail calls if they're not supported. |
| 1267 | if (!EnableARMTailCalls && !Subtarget->supportsTailCall()) |
Bob Wilson | 703af3a | 2010-08-13 22:43:33 +0000 | [diff] [blame] | 1268 | isTailCall = false; |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1269 | if (isTailCall) { |
| 1270 | // Check if it's really possible to do a tail call. |
| 1271 | isTailCall = IsEligibleForTailCallOptimization(Callee, CallConv, |
| 1272 | isVarArg, IsStructRet, MF.getFunction()->hasStructRetAttr(), |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1273 | Outs, OutVals, Ins, DAG); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1274 | // We don't support GuaranteedTailCallOpt for ARM, only automatically |
| 1275 | // detected sibcalls. |
| 1276 | if (isTailCall) { |
| 1277 | ++NumTailCalls; |
| 1278 | IsSibCall = true; |
| 1279 | } |
| 1280 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1281 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1282 | // Analyze operands of the call, assigning locations to each operand. |
| 1283 | SmallVector<CCValAssign, 16> ArgLocs; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1284 | ARMCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), |
| 1285 | getTargetMachine(), ArgLocs, *DAG.getContext(), Call); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1286 | CCInfo.AnalyzeCallOperands(Outs, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1287 | CCAssignFnForNode(CallConv, /* Return*/ false, |
| 1288 | isVarArg)); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1289 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1290 | // Get a count of how many bytes are to be pushed on the stack. |
| 1291 | unsigned NumBytes = CCInfo.getNextStackOffset(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1292 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1293 | // For tail calls, memory operands are available in our caller's stack. |
| 1294 | if (IsSibCall) |
| 1295 | NumBytes = 0; |
| 1296 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1297 | // Adjust the stack pointer for the new arguments... |
| 1298 | // These operations are automatically eliminated by the prolog/epilog pass |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1299 | if (!IsSibCall) |
| 1300 | Chain = DAG.getCALLSEQ_START(Chain, DAG.getIntPtrConstant(NumBytes, true)); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1301 | |
Jim Grosbach | f9a4b76 | 2010-02-24 01:43:03 +0000 | [diff] [blame] | 1302 | SDValue StackPtr = DAG.getCopyFromReg(Chain, dl, ARM::SP, getPointerTy()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1303 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1304 | RegsToPassVector RegsToPass; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1305 | SmallVector<SDValue, 8> MemOpChains; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1306 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1307 | // Walk the register/memloc assignments, inserting copies/loads. In the case |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1308 | // of tail call optimization, arguments are handled later. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1309 | for (unsigned i = 0, realArgIdx = 0, e = ArgLocs.size(); |
| 1310 | i != e; |
| 1311 | ++i, ++realArgIdx) { |
| 1312 | CCValAssign &VA = ArgLocs[i]; |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1313 | SDValue Arg = OutVals[realArgIdx]; |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1314 | ISD::ArgFlagsTy Flags = Outs[realArgIdx].Flags; |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1315 | bool isByVal = Flags.isByVal(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1316 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1317 | // Promote the value if needed. |
| 1318 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1319 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1320 | case CCValAssign::Full: break; |
| 1321 | case CCValAssign::SExt: |
| 1322 | Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg); |
| 1323 | break; |
| 1324 | case CCValAssign::ZExt: |
| 1325 | Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg); |
| 1326 | break; |
| 1327 | case CCValAssign::AExt: |
| 1328 | Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg); |
| 1329 | break; |
| 1330 | case CCValAssign::BCvt: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1331 | Arg = DAG.getNode(ISD::BITCAST, dl, VA.getLocVT(), Arg); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1332 | break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1333 | } |
| 1334 | |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1335 | // 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] | 1336 | if (VA.needsCustom()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1337 | if (VA.getLocVT() == MVT::v2f64) { |
| 1338 | SDValue Op0 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1339 | DAG.getConstant(0, MVT::i32)); |
| 1340 | SDValue Op1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1341 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1342 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1343 | PassF64ArgInRegs(dl, DAG, Chain, Op0, RegsToPass, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1344 | VA, ArgLocs[++i], StackPtr, MemOpChains, Flags); |
| 1345 | |
| 1346 | VA = ArgLocs[++i]; // skip ahead to next loc |
| 1347 | if (VA.isRegLoc()) { |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1348 | PassF64ArgInRegs(dl, DAG, Chain, Op1, RegsToPass, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1349 | VA, ArgLocs[++i], StackPtr, MemOpChains, Flags); |
| 1350 | } else { |
| 1351 | assert(VA.isMemLoc()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1352 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1353 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, Op1, |
| 1354 | dl, DAG, VA, Flags)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1355 | } |
| 1356 | } else { |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1357 | PassF64ArgInRegs(dl, DAG, Chain, Arg, RegsToPass, VA, ArgLocs[++i], |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1358 | StackPtr, MemOpChains, Flags); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1359 | } |
| 1360 | } else if (VA.isRegLoc()) { |
| 1361 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg)); |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1362 | } else if (isByVal) { |
| 1363 | assert(VA.isMemLoc()); |
| 1364 | unsigned offset = 0; |
| 1365 | |
| 1366 | // True if this byval aggregate will be split between registers |
| 1367 | // and memory. |
| 1368 | if (CCInfo.isFirstByValRegValid()) { |
| 1369 | EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
| 1370 | unsigned int i, j; |
| 1371 | for (i = 0, j = CCInfo.getFirstByValReg(); j < ARM::R4; i++, j++) { |
| 1372 | SDValue Const = DAG.getConstant(4*i, MVT::i32); |
| 1373 | SDValue AddArg = DAG.getNode(ISD::ADD, dl, PtrVT, Arg, Const); |
| 1374 | SDValue Load = DAG.getLoad(PtrVT, dl, Chain, AddArg, |
| 1375 | MachinePointerInfo(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 1376 | false, false, false, 0); |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1377 | MemOpChains.push_back(Load.getValue(1)); |
| 1378 | RegsToPass.push_back(std::make_pair(j, Load)); |
| 1379 | } |
| 1380 | offset = ARM::R4 - CCInfo.getFirstByValReg(); |
| 1381 | CCInfo.clearFirstByValReg(); |
| 1382 | } |
| 1383 | |
| 1384 | unsigned LocMemOffset = VA.getLocMemOffset(); |
| 1385 | SDValue StkPtrOff = DAG.getIntPtrConstant(LocMemOffset); |
| 1386 | SDValue Dst = DAG.getNode(ISD::ADD, dl, getPointerTy(), StackPtr, |
| 1387 | StkPtrOff); |
| 1388 | SDValue SrcOffset = DAG.getIntPtrConstant(4*offset); |
| 1389 | SDValue Src = DAG.getNode(ISD::ADD, dl, getPointerTy(), Arg, SrcOffset); |
| 1390 | SDValue SizeNode = DAG.getConstant(Flags.getByValSize() - 4*offset, |
| 1391 | MVT::i32); |
| 1392 | MemOpChains.push_back(DAG.getMemcpy(Chain, dl, Dst, Src, SizeNode, |
| 1393 | Flags.getByValAlign(), |
| 1394 | /*isVolatile=*/false, |
Dan Gohman | 65fd656 | 2011-11-03 21:49:52 +0000 | [diff] [blame] | 1395 | /*AlwaysInline=*/false, |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1396 | MachinePointerInfo(0), |
| 1397 | MachinePointerInfo(0))); |
| 1398 | |
| 1399 | } else if (!IsSibCall) { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1400 | assert(VA.isMemLoc()); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1401 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1402 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, Arg, |
| 1403 | dl, DAG, VA, Flags)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1404 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1405 | } |
| 1406 | |
| 1407 | if (!MemOpChains.empty()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1408 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1409 | &MemOpChains[0], MemOpChains.size()); |
| 1410 | |
| 1411 | // Build a sequence of copy-to-reg nodes chained together with token chain |
| 1412 | // and flag operands which copy the outgoing args into the appropriate regs. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1413 | SDValue InFlag; |
Dale Johannesen | 6470a11 | 2010-06-15 22:08:33 +0000 | [diff] [blame] | 1414 | // Tail call byval lowering might overwrite argument registers so in case of |
| 1415 | // tail call optimization the copies to registers are lowered later. |
| 1416 | if (!isTailCall) |
| 1417 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 1418 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, |
| 1419 | RegsToPass[i].second, InFlag); |
| 1420 | InFlag = Chain.getValue(1); |
| 1421 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1422 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1423 | // For tail calls lower the arguments to the 'real' stack slot. |
| 1424 | if (isTailCall) { |
| 1425 | // Force all the incoming stack arguments to be loaded from the stack |
| 1426 | // before any new outgoing arguments are stored to the stack, because the |
| 1427 | // outgoing stack slots may alias the incoming argument stack slots, and |
| 1428 | // the alias isn't otherwise explicit. This is slightly more conservative |
| 1429 | // than necessary, because it means that each store effectively depends |
| 1430 | // on every argument instead of just those arguments it would clobber. |
| 1431 | |
Chris Lattner | 7a2bdde | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 1432 | // Do not flag preceding copytoreg stuff together with the following stuff. |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1433 | InFlag = SDValue(); |
| 1434 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 1435 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, |
| 1436 | RegsToPass[i].second, InFlag); |
| 1437 | InFlag = Chain.getValue(1); |
| 1438 | } |
| 1439 | InFlag =SDValue(); |
| 1440 | } |
| 1441 | |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1442 | // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every |
| 1443 | // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol |
| 1444 | // node so that legalize doesn't hack it. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1445 | bool isDirect = false; |
| 1446 | bool isARMFunc = false; |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 1447 | bool isLocalARMFunc = false; |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1448 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1449 | |
| 1450 | if (EnableARMLongCalls) { |
| 1451 | assert (getTargetMachine().getRelocationModel() == Reloc::Static |
| 1452 | && "long-calls with non-static relocation model!"); |
| 1453 | // Handle a global address or an external symbol. If it's not one of |
| 1454 | // those, the target's already in a register, so we don't need to do |
| 1455 | // anything extra. |
| 1456 | if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
Anders Carlsson | 0dbdca5 | 2010-04-15 03:11:28 +0000 | [diff] [blame] | 1457 | const GlobalValue *GV = G->getGlobal(); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1458 | // Create a constant pool entry for the callee address |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1459 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 1460 | ARMConstantPoolValue *CPV = |
| 1461 | ARMConstantPoolConstant::Create(GV, ARMPCLabelIndex, ARMCP::CPValue, 0); |
| 1462 | |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1463 | // Get the address of the callee into a register |
| 1464 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
| 1465 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| 1466 | Callee = DAG.getLoad(getPointerTy(), dl, |
| 1467 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1468 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 1469 | false, false, false, 0); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1470 | } else if (ExternalSymbolSDNode *S=dyn_cast<ExternalSymbolSDNode>(Callee)) { |
| 1471 | const char *Sym = S->getSymbol(); |
| 1472 | |
| 1473 | // Create a constant pool entry for the callee address |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1474 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Bill Wendling | fe31e67 | 2011-10-01 08:58:29 +0000 | [diff] [blame] | 1475 | ARMConstantPoolValue *CPV = |
| 1476 | ARMConstantPoolSymbol::Create(*DAG.getContext(), Sym, |
| 1477 | ARMPCLabelIndex, 0); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1478 | // Get the address of the callee into a register |
| 1479 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
| 1480 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| 1481 | Callee = DAG.getLoad(getPointerTy(), dl, |
| 1482 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1483 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 1484 | false, false, false, 0); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1485 | } |
| 1486 | } else if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 1487 | const GlobalValue *GV = G->getGlobal(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1488 | isDirect = true; |
Chris Lattner | 4fb63d0 | 2009-07-15 04:12:33 +0000 | [diff] [blame] | 1489 | bool isExt = GV->isDeclaration() || GV->isWeakForLinker(); |
Evan Cheng | 970a419 | 2007-01-19 19:28:01 +0000 | [diff] [blame] | 1490 | bool isStub = (isExt && Subtarget->isTargetDarwin()) && |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1491 | getTargetMachine().getRelocationModel() != Reloc::Static; |
| 1492 | isARMFunc = !Subtarget->isThumb() || isStub; |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 1493 | // ARM call to a local ARM function is predicable. |
Evan Cheng | 46df4eb | 2010-06-16 07:35:02 +0000 | [diff] [blame] | 1494 | isLocalARMFunc = !Subtarget->isThumb() && (!isExt || !ARMInterworking); |
Evan Cheng | c60e76d | 2007-01-30 20:37:08 +0000 | [diff] [blame] | 1495 | // tBX takes a register source operand. |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 1496 | if (isARMFunc && Subtarget->isThumb1Only() && !Subtarget->hasV5TOps()) { |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1497 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 1498 | ARMConstantPoolValue *CPV = |
| 1499 | ARMConstantPoolConstant::Create(GV, ARMPCLabelIndex, ARMCP::CPValue, 4); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1500 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1501 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1502 | Callee = DAG.getLoad(getPointerTy(), dl, |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1503 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1504 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 1505 | false, false, false, 0); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1506 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1507 | Callee = DAG.getNode(ARMISD::PIC_ADD, dl, |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1508 | getPointerTy(), Callee, PICLabel); |
Jim Grosbach | 637d89f | 2010-09-22 23:27:36 +0000 | [diff] [blame] | 1509 | } else { |
| 1510 | // On ELF targets for PIC code, direct calls should go through the PLT |
| 1511 | unsigned OpFlags = 0; |
| 1512 | if (Subtarget->isTargetELF() && |
| 1513 | getTargetMachine().getRelocationModel() == Reloc::PIC_) |
| 1514 | OpFlags = ARMII::MO_PLT; |
| 1515 | Callee = DAG.getTargetGlobalAddress(GV, dl, getPointerTy(), 0, OpFlags); |
| 1516 | } |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1517 | } else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1518 | isDirect = true; |
Evan Cheng | 970a419 | 2007-01-19 19:28:01 +0000 | [diff] [blame] | 1519 | bool isStub = Subtarget->isTargetDarwin() && |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1520 | getTargetMachine().getRelocationModel() != Reloc::Static; |
| 1521 | isARMFunc = !Subtarget->isThumb() || isStub; |
Evan Cheng | c60e76d | 2007-01-30 20:37:08 +0000 | [diff] [blame] | 1522 | // tBX takes a register source operand. |
| 1523 | const char *Sym = S->getSymbol(); |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 1524 | if (isARMFunc && Subtarget->isThumb1Only() && !Subtarget->hasV5TOps()) { |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1525 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Bill Wendling | fe31e67 | 2011-10-01 08:58:29 +0000 | [diff] [blame] | 1526 | ARMConstantPoolValue *CPV = |
| 1527 | ARMConstantPoolSymbol::Create(*DAG.getContext(), Sym, |
| 1528 | ARMPCLabelIndex, 4); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1529 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1530 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1531 | Callee = DAG.getLoad(getPointerTy(), dl, |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1532 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1533 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 1534 | false, false, false, 0); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1535 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1536 | Callee = DAG.getNode(ARMISD::PIC_ADD, dl, |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1537 | getPointerTy(), Callee, PICLabel); |
Jim Grosbach | 637d89f | 2010-09-22 23:27:36 +0000 | [diff] [blame] | 1538 | } else { |
| 1539 | unsigned OpFlags = 0; |
| 1540 | // On ELF targets for PIC code, direct calls should go through the PLT |
| 1541 | if (Subtarget->isTargetELF() && |
| 1542 | getTargetMachine().getRelocationModel() == Reloc::PIC_) |
| 1543 | OpFlags = ARMII::MO_PLT; |
| 1544 | Callee = DAG.getTargetExternalSymbol(Sym, getPointerTy(), OpFlags); |
| 1545 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1546 | } |
| 1547 | |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1548 | // FIXME: handle tail calls differently. |
| 1549 | unsigned CallOpc; |
Evan Cheng | b620724 | 2009-08-01 00:16:10 +0000 | [diff] [blame] | 1550 | if (Subtarget->isThumb()) { |
| 1551 | if ((!isDirect || isARMFunc) && !Subtarget->hasV5TOps()) |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1552 | CallOpc = ARMISD::CALL_NOLINK; |
| 1553 | else |
| 1554 | CallOpc = isARMFunc ? ARMISD::CALL : ARMISD::tCALL; |
| 1555 | } else { |
| 1556 | CallOpc = (isDirect || Subtarget->hasV5TOps()) |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 1557 | ? (isLocalARMFunc ? ARMISD::CALL_PRED : ARMISD::CALL) |
| 1558 | : ARMISD::CALL_NOLINK; |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1559 | } |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1560 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1561 | std::vector<SDValue> Ops; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1562 | Ops.push_back(Chain); |
| 1563 | Ops.push_back(Callee); |
| 1564 | |
| 1565 | // Add argument registers to the end of the list so that they are known live |
| 1566 | // into the call. |
| 1567 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) |
| 1568 | Ops.push_back(DAG.getRegister(RegsToPass[i].first, |
| 1569 | RegsToPass[i].second.getValueType())); |
| 1570 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1571 | if (InFlag.getNode()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1572 | Ops.push_back(InFlag); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1573 | |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 1574 | SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue); |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1575 | if (isTailCall) |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1576 | return DAG.getNode(ARMISD::TC_RETURN, dl, NodeTys, &Ops[0], Ops.size()); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1577 | |
Duncan Sands | 4bdcb61 | 2008-07-02 17:40:58 +0000 | [diff] [blame] | 1578 | // Returns a chain and a flag for retval copy to use. |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1579 | Chain = DAG.getNode(CallOpc, dl, NodeTys, &Ops[0], Ops.size()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1580 | InFlag = Chain.getValue(1); |
| 1581 | |
Chris Lattner | e563bbc | 2008-10-11 22:08:30 +0000 | [diff] [blame] | 1582 | Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(NumBytes, true), |
| 1583 | DAG.getIntPtrConstant(0, true), InFlag); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1584 | if (!Ins.empty()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1585 | InFlag = Chain.getValue(1); |
| 1586 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1587 | // Handle result values, copying them out of physregs into vregs that we |
| 1588 | // return. |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1589 | return LowerCallResult(Chain, InFlag, CallConv, isVarArg, Ins, |
| 1590 | dl, DAG, InVals); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1591 | } |
| 1592 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1593 | /// HandleByVal - Every parameter *after* a byval parameter is passed |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1594 | /// on the stack. Remember the next parameter register to allocate, |
| 1595 | /// and then confiscate the rest of the parameter registers to insure |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1596 | /// this. |
| 1597 | void |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1598 | llvm::ARMTargetLowering::HandleByVal(CCState *State, unsigned &size) const { |
| 1599 | unsigned reg = State->AllocateReg(GPRArgRegs, 4); |
| 1600 | assert((State->getCallOrPrologue() == Prologue || |
| 1601 | State->getCallOrPrologue() == Call) && |
| 1602 | "unhandled ParmContext"); |
| 1603 | if ((!State->isFirstByValRegValid()) && |
| 1604 | (ARM::R0 <= reg) && (reg <= ARM::R3)) { |
| 1605 | State->setFirstByValReg(reg); |
| 1606 | // At a call site, a byval parameter that is split between |
| 1607 | // registers and memory needs its size truncated here. In a |
| 1608 | // function prologue, such byval parameters are reassembled in |
| 1609 | // memory, and are not truncated. |
| 1610 | if (State->getCallOrPrologue() == Call) { |
| 1611 | unsigned excess = 4 * (ARM::R4 - reg); |
| 1612 | assert(size >= excess && "expected larger existing stack allocation"); |
| 1613 | size -= excess; |
| 1614 | } |
| 1615 | } |
| 1616 | // Confiscate any remaining parameter registers to preclude their |
| 1617 | // assignment to subsequent parameters. |
| 1618 | while (State->AllocateReg(GPRArgRegs, 4)) |
| 1619 | ; |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1620 | } |
| 1621 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1622 | /// MatchingStackOffset - Return true if the given stack call argument is |
| 1623 | /// already available in the same position (relatively) of the caller's |
| 1624 | /// incoming argument stack. |
| 1625 | static |
| 1626 | bool MatchingStackOffset(SDValue Arg, unsigned Offset, ISD::ArgFlagsTy Flags, |
| 1627 | MachineFrameInfo *MFI, const MachineRegisterInfo *MRI, |
| 1628 | const ARMInstrInfo *TII) { |
| 1629 | unsigned Bytes = Arg.getValueType().getSizeInBits() / 8; |
| 1630 | int FI = INT_MAX; |
| 1631 | if (Arg.getOpcode() == ISD::CopyFromReg) { |
| 1632 | unsigned VR = cast<RegisterSDNode>(Arg.getOperand(1))->getReg(); |
Jakob Stoklund Olesen | c9df025 | 2011-01-10 02:58:51 +0000 | [diff] [blame] | 1633 | if (!TargetRegisterInfo::isVirtualRegister(VR)) |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1634 | return false; |
| 1635 | MachineInstr *Def = MRI->getVRegDef(VR); |
| 1636 | if (!Def) |
| 1637 | return false; |
| 1638 | if (!Flags.isByVal()) { |
| 1639 | if (!TII->isLoadFromStackSlot(Def, FI)) |
| 1640 | return false; |
| 1641 | } else { |
Dale Johannesen | 7835f1f | 2010-07-08 01:18:23 +0000 | [diff] [blame] | 1642 | return false; |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1643 | } |
| 1644 | } else if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Arg)) { |
| 1645 | if (Flags.isByVal()) |
| 1646 | // ByVal argument is passed in as a pointer but it's now being |
| 1647 | // dereferenced. e.g. |
| 1648 | // define @foo(%struct.X* %A) { |
| 1649 | // tail call @bar(%struct.X* byval %A) |
| 1650 | // } |
| 1651 | return false; |
| 1652 | SDValue Ptr = Ld->getBasePtr(); |
| 1653 | FrameIndexSDNode *FINode = dyn_cast<FrameIndexSDNode>(Ptr); |
| 1654 | if (!FINode) |
| 1655 | return false; |
| 1656 | FI = FINode->getIndex(); |
| 1657 | } else |
| 1658 | return false; |
| 1659 | |
| 1660 | assert(FI != INT_MAX); |
| 1661 | if (!MFI->isFixedObjectIndex(FI)) |
| 1662 | return false; |
| 1663 | return Offset == MFI->getObjectOffset(FI) && Bytes == MFI->getObjectSize(FI); |
| 1664 | } |
| 1665 | |
| 1666 | /// IsEligibleForTailCallOptimization - Check whether the call is eligible |
| 1667 | /// for tail call optimization. Targets which want to do tail call |
| 1668 | /// optimization should implement this function. |
| 1669 | bool |
| 1670 | ARMTargetLowering::IsEligibleForTailCallOptimization(SDValue Callee, |
| 1671 | CallingConv::ID CalleeCC, |
| 1672 | bool isVarArg, |
| 1673 | bool isCalleeStructRet, |
| 1674 | bool isCallerStructRet, |
| 1675 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1676 | const SmallVectorImpl<SDValue> &OutVals, |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1677 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 1678 | SelectionDAG& DAG) const { |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1679 | const Function *CallerF = DAG.getMachineFunction().getFunction(); |
| 1680 | CallingConv::ID CallerCC = CallerF->getCallingConv(); |
| 1681 | bool CCMatch = CallerCC == CalleeCC; |
| 1682 | |
| 1683 | // Look for obvious safe cases to perform tail call optimization that do not |
| 1684 | // require ABI changes. This is what gcc calls sibcall. |
| 1685 | |
Jim Grosbach | 7616b64 | 2010-06-16 23:45:49 +0000 | [diff] [blame] | 1686 | // Do not sibcall optimize vararg calls unless the call site is not passing |
| 1687 | // any arguments. |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1688 | if (isVarArg && !Outs.empty()) |
| 1689 | return false; |
| 1690 | |
| 1691 | // Also avoid sibcall optimization if either caller or callee uses struct |
| 1692 | // return semantics. |
| 1693 | if (isCalleeStructRet || isCallerStructRet) |
| 1694 | return false; |
| 1695 | |
Dale Johannesen | e39fdbe | 2010-06-23 18:52:34 +0000 | [diff] [blame] | 1696 | // FIXME: Completely disable sibcall for Thumb1 since Thumb1RegisterInfo:: |
Jim Grosbach | 8dc41f3 | 2011-07-08 20:18:11 +0000 | [diff] [blame] | 1697 | // emitEpilogue is not ready for them. Thumb tail calls also use t2B, as |
| 1698 | // the Thumb1 16-bit unconditional branch doesn't have sufficient relocation |
| 1699 | // support in the assembler and linker to be used. This would need to be |
| 1700 | // fixed to fully support tail calls in Thumb1. |
| 1701 | // |
Dale Johannesen | 7835f1f | 2010-07-08 01:18:23 +0000 | [diff] [blame] | 1702 | // Doing this is tricky, since the LDM/POP instruction on Thumb doesn't take |
| 1703 | // LR. This means if we need to reload LR, it takes an extra instructions, |
| 1704 | // which outweighs the value of the tail call; but here we don't know yet |
| 1705 | // 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] | 1706 | // 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] | 1707 | // emitEpilogue if LR is used. |
Dale Johannesen | 7835f1f | 2010-07-08 01:18:23 +0000 | [diff] [blame] | 1708 | |
| 1709 | // Thumb1 PIC calls to external symbols use BX, so they can be tail calls, |
| 1710 | // but we need to make sure there are enough registers; the only valid |
| 1711 | // registers are the 4 used for parameters. We don't currently do this |
| 1712 | // case. |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1713 | if (Subtarget->isThumb1Only()) |
| 1714 | return false; |
Dale Johannesen | df50d7e | 2010-06-18 18:13:11 +0000 | [diff] [blame] | 1715 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1716 | // If the calling conventions do not match, then we'd better make sure the |
| 1717 | // results are returned in the same way as what the caller expects. |
| 1718 | if (!CCMatch) { |
| 1719 | SmallVector<CCValAssign, 16> RVLocs1; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1720 | ARMCCState CCInfo1(CalleeCC, false, DAG.getMachineFunction(), |
| 1721 | getTargetMachine(), RVLocs1, *DAG.getContext(), Call); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1722 | CCInfo1.AnalyzeCallResult(Ins, CCAssignFnForNode(CalleeCC, true, isVarArg)); |
| 1723 | |
| 1724 | SmallVector<CCValAssign, 16> RVLocs2; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1725 | ARMCCState CCInfo2(CallerCC, false, DAG.getMachineFunction(), |
| 1726 | getTargetMachine(), RVLocs2, *DAG.getContext(), Call); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1727 | CCInfo2.AnalyzeCallResult(Ins, CCAssignFnForNode(CallerCC, true, isVarArg)); |
| 1728 | |
| 1729 | if (RVLocs1.size() != RVLocs2.size()) |
| 1730 | return false; |
| 1731 | for (unsigned i = 0, e = RVLocs1.size(); i != e; ++i) { |
| 1732 | if (RVLocs1[i].isRegLoc() != RVLocs2[i].isRegLoc()) |
| 1733 | return false; |
| 1734 | if (RVLocs1[i].getLocInfo() != RVLocs2[i].getLocInfo()) |
| 1735 | return false; |
| 1736 | if (RVLocs1[i].isRegLoc()) { |
| 1737 | if (RVLocs1[i].getLocReg() != RVLocs2[i].getLocReg()) |
| 1738 | return false; |
| 1739 | } else { |
| 1740 | if (RVLocs1[i].getLocMemOffset() != RVLocs2[i].getLocMemOffset()) |
| 1741 | return false; |
| 1742 | } |
| 1743 | } |
| 1744 | } |
| 1745 | |
| 1746 | // If the callee takes no arguments then go on to check the results of the |
| 1747 | // call. |
| 1748 | if (!Outs.empty()) { |
| 1749 | // Check if stack adjustment is needed. For now, do not do this if any |
| 1750 | // argument is passed on the stack. |
| 1751 | SmallVector<CCValAssign, 16> ArgLocs; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1752 | ARMCCState CCInfo(CalleeCC, isVarArg, DAG.getMachineFunction(), |
| 1753 | getTargetMachine(), ArgLocs, *DAG.getContext(), Call); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1754 | CCInfo.AnalyzeCallOperands(Outs, |
| 1755 | CCAssignFnForNode(CalleeCC, false, isVarArg)); |
| 1756 | if (CCInfo.getNextStackOffset()) { |
| 1757 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1758 | |
| 1759 | // Check if the arguments are already laid out in the right way as |
| 1760 | // the caller's fixed stack objects. |
| 1761 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 1762 | const MachineRegisterInfo *MRI = &MF.getRegInfo(); |
| 1763 | const ARMInstrInfo *TII = |
| 1764 | ((ARMTargetMachine&)getTargetMachine()).getInstrInfo(); |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1765 | for (unsigned i = 0, realArgIdx = 0, e = ArgLocs.size(); |
| 1766 | i != e; |
| 1767 | ++i, ++realArgIdx) { |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1768 | CCValAssign &VA = ArgLocs[i]; |
| 1769 | EVT RegVT = VA.getLocVT(); |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1770 | SDValue Arg = OutVals[realArgIdx]; |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1771 | ISD::ArgFlagsTy Flags = Outs[realArgIdx].Flags; |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1772 | if (VA.getLocInfo() == CCValAssign::Indirect) |
| 1773 | return false; |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1774 | if (VA.needsCustom()) { |
| 1775 | // f64 and vector types are split into multiple registers or |
| 1776 | // register/stack-slot combinations. The types will not match |
| 1777 | // the registers; give up on memory f64 refs until we figure |
| 1778 | // out what to do about this. |
| 1779 | if (!VA.isRegLoc()) |
| 1780 | return false; |
| 1781 | if (!ArgLocs[++i].isRegLoc()) |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 1782 | return false; |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1783 | if (RegVT == MVT::v2f64) { |
| 1784 | if (!ArgLocs[++i].isRegLoc()) |
| 1785 | return false; |
| 1786 | if (!ArgLocs[++i].isRegLoc()) |
| 1787 | return false; |
| 1788 | } |
| 1789 | } else if (!VA.isRegLoc()) { |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1790 | if (!MatchingStackOffset(Arg, VA.getLocMemOffset(), Flags, |
| 1791 | MFI, MRI, TII)) |
| 1792 | return false; |
| 1793 | } |
| 1794 | } |
| 1795 | } |
| 1796 | } |
| 1797 | |
| 1798 | return true; |
| 1799 | } |
| 1800 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1801 | SDValue |
| 1802 | ARMTargetLowering::LowerReturn(SDValue Chain, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1803 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1804 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1805 | const SmallVectorImpl<SDValue> &OutVals, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1806 | DebugLoc dl, SelectionDAG &DAG) const { |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1807 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1808 | // CCValAssign - represent the assignment of the return value to a location. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1809 | SmallVector<CCValAssign, 16> RVLocs; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1810 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1811 | // CCState - Info about the registers and stack slots. |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1812 | ARMCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), |
| 1813 | getTargetMachine(), RVLocs, *DAG.getContext(), Call); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1814 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1815 | // Analyze outgoing return values. |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1816 | CCInfo.AnalyzeReturn(Outs, CCAssignFnForNode(CallConv, /* Return */ true, |
| 1817 | isVarArg)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1818 | |
| 1819 | // If this is the first return lowered for this function, add |
| 1820 | // the regs to the liveout set for the function. |
| 1821 | if (DAG.getMachineFunction().getRegInfo().liveout_empty()) { |
| 1822 | for (unsigned i = 0; i != RVLocs.size(); ++i) |
| 1823 | if (RVLocs[i].isRegLoc()) |
| 1824 | DAG.getMachineFunction().getRegInfo().addLiveOut(RVLocs[i].getLocReg()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1825 | } |
| 1826 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1827 | SDValue Flag; |
| 1828 | |
| 1829 | // Copy the result values into the output registers. |
| 1830 | for (unsigned i = 0, realRVLocIdx = 0; |
| 1831 | i != RVLocs.size(); |
| 1832 | ++i, ++realRVLocIdx) { |
| 1833 | CCValAssign &VA = RVLocs[i]; |
| 1834 | assert(VA.isRegLoc() && "Can only return in registers!"); |
| 1835 | |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1836 | SDValue Arg = OutVals[realRVLocIdx]; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1837 | |
| 1838 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1839 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1840 | case CCValAssign::Full: break; |
| 1841 | case CCValAssign::BCvt: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1842 | Arg = DAG.getNode(ISD::BITCAST, dl, VA.getLocVT(), Arg); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1843 | break; |
| 1844 | } |
| 1845 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1846 | if (VA.needsCustom()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1847 | if (VA.getLocVT() == MVT::v2f64) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1848 | // Extract the first half and return it in two registers. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1849 | SDValue Half = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1850 | DAG.getConstant(0, MVT::i32)); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1851 | SDValue HalfGPRs = DAG.getNode(ARMISD::VMOVRRD, dl, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1852 | DAG.getVTList(MVT::i32, MVT::i32), Half); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1853 | |
| 1854 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), HalfGPRs, Flag); |
| 1855 | Flag = Chain.getValue(1); |
| 1856 | VA = RVLocs[++i]; // skip ahead to next loc |
| 1857 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), |
| 1858 | HalfGPRs.getValue(1), Flag); |
| 1859 | Flag = Chain.getValue(1); |
| 1860 | VA = RVLocs[++i]; // skip ahead to next loc |
| 1861 | |
| 1862 | // 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] | 1863 | Arg = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1864 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1865 | } |
| 1866 | // Legalize ret f64 -> ret 2 x i32. We always have fmrrd if f64 is |
| 1867 | // available. |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1868 | SDValue fmrrd = DAG.getNode(ARMISD::VMOVRRD, dl, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1869 | DAG.getVTList(MVT::i32, MVT::i32), &Arg, 1); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1870 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), fmrrd, Flag); |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1871 | Flag = Chain.getValue(1); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1872 | VA = RVLocs[++i]; // skip ahead to next loc |
| 1873 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), fmrrd.getValue(1), |
| 1874 | Flag); |
| 1875 | } else |
| 1876 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), Arg, Flag); |
| 1877 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1878 | // Guarantee that all emitted copies are |
| 1879 | // stuck together, avoiding something bad. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1880 | Flag = Chain.getValue(1); |
| 1881 | } |
| 1882 | |
| 1883 | SDValue result; |
| 1884 | if (Flag.getNode()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1885 | result = DAG.getNode(ARMISD::RET_FLAG, dl, MVT::Other, Chain, Flag); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1886 | else // Return Void |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1887 | result = DAG.getNode(ARMISD::RET_FLAG, dl, MVT::Other, Chain); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1888 | |
| 1889 | return result; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1890 | } |
| 1891 | |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1892 | bool ARMTargetLowering::isUsedByReturnOnly(SDNode *N) const { |
| 1893 | if (N->getNumValues() != 1) |
| 1894 | return false; |
| 1895 | if (!N->hasNUsesOfValue(1, 0)) |
| 1896 | return false; |
| 1897 | |
| 1898 | unsigned NumCopies = 0; |
| 1899 | SDNode* Copies[2]; |
| 1900 | SDNode *Use = *N->use_begin(); |
| 1901 | if (Use->getOpcode() == ISD::CopyToReg) { |
| 1902 | Copies[NumCopies++] = Use; |
| 1903 | } else if (Use->getOpcode() == ARMISD::VMOVRRD) { |
| 1904 | // f64 returned in a pair of GPRs. |
| 1905 | for (SDNode::use_iterator UI = Use->use_begin(), UE = Use->use_end(); |
| 1906 | UI != UE; ++UI) { |
| 1907 | if (UI->getOpcode() != ISD::CopyToReg) |
| 1908 | return false; |
| 1909 | Copies[UI.getUse().getResNo()] = *UI; |
| 1910 | ++NumCopies; |
| 1911 | } |
| 1912 | } else if (Use->getOpcode() == ISD::BITCAST) { |
| 1913 | // f32 returned in a single GPR. |
| 1914 | if (!Use->hasNUsesOfValue(1, 0)) |
| 1915 | return false; |
| 1916 | Use = *Use->use_begin(); |
| 1917 | if (Use->getOpcode() != ISD::CopyToReg || !Use->hasNUsesOfValue(1, 0)) |
| 1918 | return false; |
| 1919 | Copies[NumCopies++] = Use; |
| 1920 | } else { |
| 1921 | return false; |
| 1922 | } |
| 1923 | |
| 1924 | if (NumCopies != 1 && NumCopies != 2) |
| 1925 | return false; |
Evan Cheng | 1bf891a | 2010-12-01 22:59:46 +0000 | [diff] [blame] | 1926 | |
| 1927 | bool HasRet = false; |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1928 | for (unsigned i = 0; i < NumCopies; ++i) { |
| 1929 | SDNode *Copy = Copies[i]; |
| 1930 | for (SDNode::use_iterator UI = Copy->use_begin(), UE = Copy->use_end(); |
| 1931 | UI != UE; ++UI) { |
| 1932 | if (UI->getOpcode() == ISD::CopyToReg) { |
| 1933 | SDNode *Use = *UI; |
| 1934 | if (Use == Copies[0] || Use == Copies[1]) |
| 1935 | continue; |
| 1936 | return false; |
| 1937 | } |
| 1938 | if (UI->getOpcode() != ARMISD::RET_FLAG) |
| 1939 | return false; |
Evan Cheng | 1bf891a | 2010-12-01 22:59:46 +0000 | [diff] [blame] | 1940 | HasRet = true; |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1941 | } |
| 1942 | } |
| 1943 | |
Evan Cheng | 1bf891a | 2010-12-01 22:59:46 +0000 | [diff] [blame] | 1944 | return HasRet; |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1945 | } |
| 1946 | |
Evan Cheng | 485fafc | 2011-03-21 01:19:09 +0000 | [diff] [blame] | 1947 | bool ARMTargetLowering::mayBeEmittedAsTailCall(CallInst *CI) const { |
| 1948 | if (!EnableARMTailCalls) |
| 1949 | return false; |
| 1950 | |
| 1951 | if (!CI->isTailCall()) |
| 1952 | return false; |
| 1953 | |
| 1954 | return !Subtarget->isThumb1Only(); |
| 1955 | } |
| 1956 | |
Bob Wilson | b62d257 | 2009-11-03 00:02:05 +0000 | [diff] [blame] | 1957 | // ConstantPool, JumpTable, GlobalAddress, and ExternalSymbol are lowered as |
| 1958 | // their target counterpart wrapped in the ARMISD::Wrapper node. Suppose N is |
| 1959 | // one of the above mentioned nodes. It has to be wrapped because otherwise |
| 1960 | // Select(N) returns N. So the raw TargetGlobalAddress nodes, etc. can only |
| 1961 | // be used to form addressing mode. These wrapped nodes will be selected |
| 1962 | // into MOVi. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1963 | static SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1964 | EVT PtrVT = Op.getValueType(); |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 1965 | // FIXME there is no actual debug info here |
| 1966 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1967 | ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1968 | SDValue Res; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1969 | if (CP->isMachineConstantPoolEntry()) |
| 1970 | Res = DAG.getTargetConstantPool(CP->getMachineCPVal(), PtrVT, |
| 1971 | CP->getAlignment()); |
| 1972 | else |
| 1973 | Res = DAG.getTargetConstantPool(CP->getConstVal(), PtrVT, |
| 1974 | CP->getAlignment()); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1975 | return DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Res); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1976 | } |
| 1977 | |
Jim Grosbach | e1102ca | 2010-07-19 17:20:38 +0000 | [diff] [blame] | 1978 | unsigned ARMTargetLowering::getJumpTableEncoding() const { |
| 1979 | return MachineJumpTableInfo::EK_Inline; |
| 1980 | } |
| 1981 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1982 | SDValue ARMTargetLowering::LowerBlockAddress(SDValue Op, |
| 1983 | SelectionDAG &DAG) const { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1984 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1985 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 1986 | unsigned ARMPCLabelIndex = 0; |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 1987 | DebugLoc DL = Op.getDebugLoc(); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 1988 | EVT PtrVT = getPointerTy(); |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 1989 | const BlockAddress *BA = cast<BlockAddressSDNode>(Op)->getBlockAddress(); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 1990 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| 1991 | SDValue CPAddr; |
| 1992 | if (RelocM == Reloc::Static) { |
| 1993 | CPAddr = DAG.getTargetConstantPool(BA, PtrVT, 4); |
| 1994 | } else { |
| 1995 | unsigned PCAdj = Subtarget->isThumb() ? 4 : 8; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1996 | ARMPCLabelIndex = AFI->createPICLabelUId(); |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 1997 | ARMConstantPoolValue *CPV = |
| 1998 | ARMConstantPoolConstant::Create(BA, ARMPCLabelIndex, |
| 1999 | ARMCP::CPBlockAddress, PCAdj); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2000 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
| 2001 | } |
| 2002 | CPAddr = DAG.getNode(ARMISD::Wrapper, DL, PtrVT, CPAddr); |
| 2003 | SDValue Result = DAG.getLoad(PtrVT, DL, DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2004 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2005 | false, false, false, 0); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2006 | if (RelocM == Reloc::Static) |
| 2007 | return Result; |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2008 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2009 | return DAG.getNode(ARMISD::PIC_ADD, DL, PtrVT, Result, PICLabel); |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 2010 | } |
| 2011 | |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2012 | // Lower ISD::GlobalTLSAddress using the "general dynamic" model |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2013 | SDValue |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2014 | ARMTargetLowering::LowerToTLSGeneralDynamicModel(GlobalAddressSDNode *GA, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2015 | SelectionDAG &DAG) const { |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2016 | DebugLoc dl = GA->getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2017 | EVT PtrVT = getPointerTy(); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2018 | unsigned char PCAdj = Subtarget->isThumb() ? 4 : 8; |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2019 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2020 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2021 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2022 | ARMConstantPoolValue *CPV = |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2023 | ARMConstantPoolConstant::Create(GA->getGlobal(), ARMPCLabelIndex, |
| 2024 | ARMCP::CPValue, PCAdj, ARMCP::TLSGD, true); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2025 | SDValue Argument = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2026 | Argument = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Argument); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2027 | Argument = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Argument, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2028 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2029 | false, false, false, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2030 | SDValue Chain = Argument.getValue(1); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2031 | |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2032 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2033 | Argument = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Argument, PICLabel); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2034 | |
| 2035 | // call __tls_get_addr. |
| 2036 | ArgListTy Args; |
| 2037 | ArgListEntry Entry; |
| 2038 | Entry.Node = Argument; |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 2039 | Entry.Ty = (Type *) Type::getInt32Ty(*DAG.getContext()); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2040 | Args.push_back(Entry); |
Dale Johannesen | 7d2ad62 | 2009-01-30 23:10:59 +0000 | [diff] [blame] | 2041 | // FIXME: is there useful debug info available here? |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2042 | std::pair<SDValue, SDValue> CallResult = |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 2043 | LowerCallTo(Chain, (Type *) Type::getInt32Ty(*DAG.getContext()), |
Evan Cheng | 59bc060 | 2009-08-14 19:11:20 +0000 | [diff] [blame] | 2044 | false, false, false, false, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2045 | 0, CallingConv::C, false, /*isReturnValueUsed=*/true, |
Bill Wendling | 46ada19 | 2010-03-02 01:55:18 +0000 | [diff] [blame] | 2046 | DAG.getExternalSymbol("__tls_get_addr", PtrVT), Args, DAG, dl); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2047 | return CallResult.first; |
| 2048 | } |
| 2049 | |
| 2050 | // Lower ISD::GlobalTLSAddress using the "initial exec" or |
| 2051 | // "local exec" model. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2052 | SDValue |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2053 | ARMTargetLowering::LowerToTLSExecModels(GlobalAddressSDNode *GA, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2054 | SelectionDAG &DAG) const { |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2055 | const GlobalValue *GV = GA->getGlobal(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2056 | DebugLoc dl = GA->getDebugLoc(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2057 | SDValue Offset; |
| 2058 | SDValue Chain = DAG.getEntryNode(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2059 | EVT PtrVT = getPointerTy(); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2060 | // Get the Thread Pointer |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2061 | SDValue ThreadPointer = DAG.getNode(ARMISD::THREAD_POINTER, dl, PtrVT); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2062 | |
Chris Lattner | 4fb63d0 | 2009-07-15 04:12:33 +0000 | [diff] [blame] | 2063 | if (GV->isDeclaration()) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2064 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2065 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2066 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2067 | // Initial exec model. |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2068 | unsigned char PCAdj = Subtarget->isThumb() ? 4 : 8; |
| 2069 | ARMConstantPoolValue *CPV = |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2070 | ARMConstantPoolConstant::Create(GA->getGlobal(), ARMPCLabelIndex, |
| 2071 | ARMCP::CPValue, PCAdj, ARMCP::GOTTPOFF, |
| 2072 | true); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2073 | Offset = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2074 | Offset = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Offset); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2075 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2076 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2077 | false, false, false, 0); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2078 | Chain = Offset.getValue(1); |
| 2079 | |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2080 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2081 | Offset = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Offset, PICLabel); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2082 | |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2083 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2084 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2085 | false, false, false, 0); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2086 | } else { |
| 2087 | // local exec model |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2088 | ARMConstantPoolValue *CPV = |
| 2089 | ARMConstantPoolConstant::Create(GV, ARMCP::TPOFF); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2090 | Offset = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2091 | Offset = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Offset); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2092 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2093 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2094 | false, false, false, 0); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2095 | } |
| 2096 | |
| 2097 | // The address of the thread local variable is the add of the thread |
| 2098 | // pointer with the offset of the variable. |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2099 | return DAG.getNode(ISD::ADD, dl, PtrVT, ThreadPointer, Offset); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2100 | } |
| 2101 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2102 | SDValue |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2103 | ARMTargetLowering::LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const { |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2104 | // TODO: implement the "local dynamic" model |
| 2105 | assert(Subtarget->isTargetELF() && |
| 2106 | "TLS not implemented for non-ELF targets"); |
| 2107 | GlobalAddressSDNode *GA = cast<GlobalAddressSDNode>(Op); |
| 2108 | // If the relocation model is PIC, use the "General Dynamic" TLS Model, |
| 2109 | // otherwise use the "Local Exec" TLS Model |
| 2110 | if (getTargetMachine().getRelocationModel() == Reloc::PIC_) |
| 2111 | return LowerToTLSGeneralDynamicModel(GA, DAG); |
| 2112 | else |
| 2113 | return LowerToTLSExecModels(GA, DAG); |
| 2114 | } |
| 2115 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2116 | SDValue ARMTargetLowering::LowerGlobalAddressELF(SDValue Op, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2117 | SelectionDAG &DAG) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2118 | EVT PtrVT = getPointerTy(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2119 | DebugLoc dl = Op.getDebugLoc(); |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2120 | const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2121 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| 2122 | if (RelocM == Reloc::PIC_) { |
Rafael Espindola | bb46f52 | 2009-01-15 20:18:42 +0000 | [diff] [blame] | 2123 | bool UseGOTOFF = GV->hasLocalLinkage() || GV->hasHiddenVisibility(); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2124 | ARMConstantPoolValue *CPV = |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2125 | ARMConstantPoolConstant::Create(GV, |
| 2126 | UseGOTOFF ? ARMCP::GOTOFF : ARMCP::GOT); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2127 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2128 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2129 | SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 2130 | CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2131 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2132 | false, false, false, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2133 | SDValue Chain = Result.getValue(1); |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 2134 | SDValue GOT = DAG.getGLOBAL_OFFSET_TABLE(PtrVT); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2135 | Result = DAG.getNode(ISD::ADD, dl, PtrVT, Result, GOT); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2136 | if (!UseGOTOFF) |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 2137 | Result = DAG.getLoad(PtrVT, dl, Chain, Result, |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2138 | MachinePointerInfo::getGOT(), |
| 2139 | false, false, false, 0); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2140 | return Result; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2141 | } |
| 2142 | |
| 2143 | // 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] | 2144 | // pair. This is always cheaper. |
| 2145 | if (Subtarget->useMovt()) { |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2146 | ++NumMovwMovt; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2147 | // FIXME: Once remat is capable of dealing with instructions with register |
| 2148 | // operands, expand this into two nodes. |
| 2149 | return DAG.getNode(ARMISD::Wrapper, dl, PtrVT, |
| 2150 | DAG.getTargetGlobalAddress(GV, dl, PtrVT)); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2151 | } else { |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2152 | SDValue CPAddr = DAG.getTargetConstantPool(GV, PtrVT, 4); |
| 2153 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| 2154 | return DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
| 2155 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2156 | false, false, false, 0); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2157 | } |
| 2158 | } |
| 2159 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2160 | SDValue ARMTargetLowering::LowerGlobalAddressDarwin(SDValue Op, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2161 | SelectionDAG &DAG) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2162 | EVT PtrVT = getPointerTy(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2163 | DebugLoc dl = Op.getDebugLoc(); |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2164 | const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2165 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2166 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2167 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2168 | |
Jakob Stoklund Olesen | 8f37a24 | 2012-01-07 20:49:15 +0000 | [diff] [blame] | 2169 | // FIXME: Enable this for static codegen when tool issues are fixed. Also |
| 2170 | // update ARMFastISel::ARMMaterializeGV. |
Evan Cheng | f31151f | 2011-10-26 01:17:44 +0000 | [diff] [blame] | 2171 | if (Subtarget->useMovt() && RelocM != Reloc::Static) { |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2172 | ++NumMovwMovt; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2173 | // FIXME: Once remat is capable of dealing with instructions with register |
| 2174 | // operands, expand this into two nodes. |
Evan Cheng | 53519f0 | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 2175 | if (RelocM == Reloc::Static) |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2176 | return DAG.getNode(ARMISD::Wrapper, dl, PtrVT, |
| 2177 | DAG.getTargetGlobalAddress(GV, dl, PtrVT)); |
| 2178 | |
Evan Cheng | 53519f0 | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 2179 | unsigned Wrapper = (RelocM == Reloc::PIC_) |
| 2180 | ? ARMISD::WrapperPIC : ARMISD::WrapperDYN; |
| 2181 | SDValue Result = DAG.getNode(Wrapper, dl, PtrVT, |
Evan Cheng | 9fe2009 | 2011-01-20 08:34:58 +0000 | [diff] [blame] | 2182 | DAG.getTargetGlobalAddress(GV, dl, PtrVT)); |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2183 | if (Subtarget->GVIsIndirectSymbol(GV, RelocM)) |
| 2184 | Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Result, |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2185 | MachinePointerInfo::getGOT(), |
| 2186 | false, false, false, 0); |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2187 | return Result; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2188 | } |
| 2189 | |
| 2190 | unsigned ARMPCLabelIndex = 0; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2191 | SDValue CPAddr; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2192 | if (RelocM == Reloc::Static) { |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2193 | CPAddr = DAG.getTargetConstantPool(GV, PtrVT, 4); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2194 | } else { |
| 2195 | ARMPCLabelIndex = AFI->createPICLabelUId(); |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 2196 | unsigned PCAdj = (RelocM != Reloc::PIC_) ? 0 : (Subtarget->isThumb()?4:8); |
| 2197 | ARMConstantPoolValue *CPV = |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2198 | ARMConstantPoolConstant::Create(GV, ARMPCLabelIndex, ARMCP::CPValue, |
| 2199 | PCAdj); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2200 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2201 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2202 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2203 | |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2204 | SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2205 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2206 | false, false, false, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2207 | SDValue Chain = Result.getValue(1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2208 | |
| 2209 | if (RelocM == Reloc::PIC_) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2210 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2211 | Result = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2212 | } |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 2213 | |
Evan Cheng | 63476a8 | 2009-09-03 07:04:02 +0000 | [diff] [blame] | 2214 | if (Subtarget->GVIsIndirectSymbol(GV, RelocM)) |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2215 | Result = DAG.getLoad(PtrVT, dl, Chain, Result, MachinePointerInfo::getGOT(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2216 | false, false, false, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2217 | |
| 2218 | return Result; |
| 2219 | } |
| 2220 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2221 | SDValue ARMTargetLowering::LowerGLOBAL_OFFSET_TABLE(SDValue Op, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2222 | SelectionDAG &DAG) const { |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2223 | assert(Subtarget->isTargetELF() && |
| 2224 | "GLOBAL OFFSET TABLE not implemented for non-ELF targets"); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2225 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2226 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2227 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2228 | EVT PtrVT = getPointerTy(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2229 | DebugLoc dl = Op.getDebugLoc(); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2230 | unsigned PCAdj = Subtarget->isThumb() ? 4 : 8; |
Bill Wendling | fe31e67 | 2011-10-01 08:58:29 +0000 | [diff] [blame] | 2231 | ARMConstantPoolValue *CPV = |
| 2232 | ARMConstantPoolSymbol::Create(*DAG.getContext(), "_GLOBAL_OFFSET_TABLE_", |
| 2233 | ARMPCLabelIndex, PCAdj); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2234 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2235 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +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); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2239 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2240 | return DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2241 | } |
| 2242 | |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 2243 | SDValue |
Jim Grosbach | 23ff7cf | 2010-05-26 20:22:18 +0000 | [diff] [blame] | 2244 | ARMTargetLowering::LowerEH_SJLJ_SETJMP(SDValue Op, SelectionDAG &DAG) const { |
| 2245 | DebugLoc dl = Op.getDebugLoc(); |
Jim Grosbach | 0798edd | 2010-05-27 23:49:24 +0000 | [diff] [blame] | 2246 | SDValue Val = DAG.getConstant(0, MVT::i32); |
Bill Wendling | ce370cf | 2011-10-07 21:25:38 +0000 | [diff] [blame] | 2247 | return DAG.getNode(ARMISD::EH_SJLJ_SETJMP, dl, |
| 2248 | DAG.getVTList(MVT::i32, MVT::Other), Op.getOperand(0), |
Jim Grosbach | 23ff7cf | 2010-05-26 20:22:18 +0000 | [diff] [blame] | 2249 | Op.getOperand(1), Val); |
| 2250 | } |
| 2251 | |
| 2252 | SDValue |
Jim Grosbach | 5eb1951 | 2010-05-22 01:06:18 +0000 | [diff] [blame] | 2253 | ARMTargetLowering::LowerEH_SJLJ_LONGJMP(SDValue Op, SelectionDAG &DAG) const { |
| 2254 | DebugLoc dl = Op.getDebugLoc(); |
| 2255 | return DAG.getNode(ARMISD::EH_SJLJ_LONGJMP, dl, MVT::Other, Op.getOperand(0), |
| 2256 | Op.getOperand(1), DAG.getConstant(0, MVT::i32)); |
| 2257 | } |
| 2258 | |
| 2259 | SDValue |
Jim Grosbach | a87ded2 | 2010-02-08 23:22:00 +0000 | [diff] [blame] | 2260 | ARMTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG, |
Jim Grosbach | 7616b64 | 2010-06-16 23:45:49 +0000 | [diff] [blame] | 2261 | const ARMSubtarget *Subtarget) const { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2262 | unsigned IntNo = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 2263 | DebugLoc dl = Op.getDebugLoc(); |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 2264 | switch (IntNo) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2265 | default: return SDValue(); // Don't custom lower most intrinsics. |
Bob Wilson | 916afdb | 2009-08-04 00:25:01 +0000 | [diff] [blame] | 2266 | case Intrinsic::arm_thread_pointer: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2267 | EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
Bob Wilson | 916afdb | 2009-08-04 00:25:01 +0000 | [diff] [blame] | 2268 | return DAG.getNode(ARMISD::THREAD_POINTER, dl, PtrVT); |
| 2269 | } |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2270 | case Intrinsic::eh_sjlj_lsda: { |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2271 | MachineFunction &MF = DAG.getMachineFunction(); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2272 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2273 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2274 | EVT PtrVT = getPointerTy(); |
| 2275 | DebugLoc dl = Op.getDebugLoc(); |
| 2276 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| 2277 | SDValue CPAddr; |
| 2278 | unsigned PCAdj = (RelocM != Reloc::PIC_) |
| 2279 | ? 0 : (Subtarget->isThumb() ? 4 : 8); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2280 | ARMConstantPoolValue *CPV = |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2281 | ARMConstantPoolConstant::Create(MF.getFunction(), ARMPCLabelIndex, |
| 2282 | ARMCP::CPLSDA, PCAdj); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2283 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2284 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2285 | SDValue Result = |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2286 | DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2287 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2288 | false, false, false, 0); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2289 | |
| 2290 | if (RelocM == Reloc::PIC_) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2291 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2292 | Result = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
| 2293 | } |
| 2294 | return Result; |
| 2295 | } |
Evan Cheng | 92e3916 | 2011-03-29 23:06:19 +0000 | [diff] [blame] | 2296 | case Intrinsic::arm_neon_vmulls: |
| 2297 | case Intrinsic::arm_neon_vmullu: { |
| 2298 | unsigned NewOpc = (IntNo == Intrinsic::arm_neon_vmulls) |
| 2299 | ? ARMISD::VMULLs : ARMISD::VMULLu; |
| 2300 | return DAG.getNode(NewOpc, Op.getDebugLoc(), Op.getValueType(), |
| 2301 | Op.getOperand(1), Op.getOperand(2)); |
| 2302 | } |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 2303 | } |
| 2304 | } |
| 2305 | |
Jim Grosbach | 7c03dbd | 2009-12-14 21:24:16 +0000 | [diff] [blame] | 2306 | static SDValue LowerMEMBARRIER(SDValue Op, SelectionDAG &DAG, |
Jim Grosbach | 7616b64 | 2010-06-16 23:45:49 +0000 | [diff] [blame] | 2307 | const ARMSubtarget *Subtarget) { |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 2308 | DebugLoc dl = Op.getDebugLoc(); |
Bob Wilson | f74a429 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 2309 | if (!Subtarget->hasDataBarrier()) { |
| 2310 | // Some ARMv6 cpus can support data barriers with an mcr instruction. |
| 2311 | // Thumb1 and pre-v6 ARM mode use a libcall instead and should never get |
| 2312 | // here. |
Bob Wilson | 54f9256 | 2010-11-09 22:50:44 +0000 | [diff] [blame] | 2313 | assert(Subtarget->hasV6Ops() && !Subtarget->isThumb() && |
Evan Cheng | 11db068 | 2010-08-11 06:22:01 +0000 | [diff] [blame] | 2314 | "Unexpected ISD::MEMBARRIER encountered. Should be libcall!"); |
Bob Wilson | f74a429 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 2315 | return DAG.getNode(ARMISD::MEMBARRIER_MCR, dl, MVT::Other, Op.getOperand(0), |
Jim Grosbach | c73993b | 2010-06-17 01:37:00 +0000 | [diff] [blame] | 2316 | DAG.getConstant(0, MVT::i32)); |
Evan Cheng | 11db068 | 2010-08-11 06:22:01 +0000 | [diff] [blame] | 2317 | } |
Bob Wilson | f74a429 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 2318 | |
| 2319 | SDValue Op5 = Op.getOperand(5); |
| 2320 | bool isDeviceBarrier = cast<ConstantSDNode>(Op5)->getZExtValue() != 0; |
| 2321 | unsigned isLL = cast<ConstantSDNode>(Op.getOperand(1))->getZExtValue(); |
| 2322 | unsigned isLS = cast<ConstantSDNode>(Op.getOperand(2))->getZExtValue(); |
| 2323 | bool isOnlyStoreBarrier = (isLL == 0 && isLS == 0); |
| 2324 | |
| 2325 | ARM_MB::MemBOpt DMBOpt; |
| 2326 | if (isDeviceBarrier) |
| 2327 | DMBOpt = isOnlyStoreBarrier ? ARM_MB::ST : ARM_MB::SY; |
| 2328 | else |
| 2329 | DMBOpt = isOnlyStoreBarrier ? ARM_MB::ISHST : ARM_MB::ISH; |
| 2330 | return DAG.getNode(ARMISD::MEMBARRIER, dl, MVT::Other, Op.getOperand(0), |
| 2331 | DAG.getConstant(DMBOpt, MVT::i32)); |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 2332 | } |
| 2333 | |
Eli Friedman | 26689ac | 2011-08-03 21:06:02 +0000 | [diff] [blame] | 2334 | |
| 2335 | static SDValue LowerATOMIC_FENCE(SDValue Op, SelectionDAG &DAG, |
| 2336 | const ARMSubtarget *Subtarget) { |
| 2337 | // FIXME: handle "fence singlethread" more efficiently. |
| 2338 | DebugLoc dl = Op.getDebugLoc(); |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 2339 | if (!Subtarget->hasDataBarrier()) { |
| 2340 | // Some ARMv6 cpus can support data barriers with an mcr instruction. |
| 2341 | // Thumb1 and pre-v6 ARM mode use a libcall instead and should never get |
| 2342 | // here. |
| 2343 | assert(Subtarget->hasV6Ops() && !Subtarget->isThumb() && |
| 2344 | "Unexpected ISD::MEMBARRIER encountered. Should be libcall!"); |
Eli Friedman | 26689ac | 2011-08-03 21:06:02 +0000 | [diff] [blame] | 2345 | return DAG.getNode(ARMISD::MEMBARRIER_MCR, dl, MVT::Other, Op.getOperand(0), |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 2346 | DAG.getConstant(0, MVT::i32)); |
| 2347 | } |
| 2348 | |
Eli Friedman | 26689ac | 2011-08-03 21:06:02 +0000 | [diff] [blame] | 2349 | return DAG.getNode(ARMISD::MEMBARRIER, dl, MVT::Other, Op.getOperand(0), |
Eli Friedman | 989f61e | 2011-08-02 22:44:16 +0000 | [diff] [blame] | 2350 | DAG.getConstant(ARM_MB::ISH, MVT::i32)); |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 2351 | } |
| 2352 | |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2353 | static SDValue LowerPREFETCH(SDValue Op, SelectionDAG &DAG, |
| 2354 | const ARMSubtarget *Subtarget) { |
| 2355 | // ARM pre v5TE and Thumb1 does not have preload instructions. |
| 2356 | if (!(Subtarget->isThumb2() || |
| 2357 | (!Subtarget->isThumb1Only() && Subtarget->hasV5TEOps()))) |
| 2358 | // Just preserve the chain. |
| 2359 | return Op.getOperand(0); |
| 2360 | |
| 2361 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 2362 | unsigned isRead = ~cast<ConstantSDNode>(Op.getOperand(2))->getZExtValue() & 1; |
| 2363 | if (!isRead && |
| 2364 | (!Subtarget->hasV7Ops() || !Subtarget->hasMPExtension())) |
| 2365 | // ARMv7 with MP extension has PLDW. |
| 2366 | return Op.getOperand(0); |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2367 | |
Bruno Cardoso Lopes | 9a76733 | 2011-06-14 04:58:37 +0000 | [diff] [blame] | 2368 | unsigned isData = cast<ConstantSDNode>(Op.getOperand(4))->getZExtValue(); |
| 2369 | if (Subtarget->isThumb()) { |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2370 | // Invert the bits. |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 2371 | isRead = ~isRead & 1; |
Bruno Cardoso Lopes | 9a76733 | 2011-06-14 04:58:37 +0000 | [diff] [blame] | 2372 | isData = ~isData & 1; |
| 2373 | } |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2374 | |
| 2375 | return DAG.getNode(ARMISD::PRELOAD, dl, MVT::Other, Op.getOperand(0), |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 2376 | Op.getOperand(1), DAG.getConstant(isRead, MVT::i32), |
| 2377 | DAG.getConstant(isData, MVT::i32)); |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2378 | } |
| 2379 | |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 2380 | static SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) { |
| 2381 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2382 | ARMFunctionInfo *FuncInfo = MF.getInfo<ARMFunctionInfo>(); |
| 2383 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2384 | // vastart just stores the address of the VarArgsFrameIndex slot into the |
| 2385 | // memory location argument. |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2386 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2387 | EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 2388 | SDValue FR = DAG.getFrameIndex(FuncInfo->getVarArgsFrameIndex(), PtrVT); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 2389 | const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue(); |
Chris Lattner | fc448ff | 2010-09-21 18:51:21 +0000 | [diff] [blame] | 2390 | return DAG.getStore(Op.getOperand(0), dl, FR, Op.getOperand(1), |
| 2391 | MachinePointerInfo(SV), false, false, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2392 | } |
| 2393 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2394 | SDValue |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2395 | ARMTargetLowering::GetF64FormalArgument(CCValAssign &VA, CCValAssign &NextVA, |
| 2396 | SDValue &Root, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2397 | DebugLoc dl) const { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2398 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2399 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2400 | |
| 2401 | TargetRegisterClass *RC; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 2402 | if (AFI->isThumb1OnlyFunction()) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2403 | RC = ARM::tGPRRegisterClass; |
| 2404 | else |
| 2405 | RC = ARM::GPRRegisterClass; |
| 2406 | |
| 2407 | // Transform the arguments stored in physical registers into virtual ones. |
Devang Patel | 68e6bee | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 2408 | unsigned Reg = MF.addLiveIn(VA.getLocReg(), RC); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2409 | SDValue ArgValue = DAG.getCopyFromReg(Root, dl, Reg, MVT::i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2410 | |
| 2411 | SDValue ArgValue2; |
| 2412 | if (NextVA.isMemLoc()) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2413 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
Evan Cheng | ed2ae13 | 2010-07-03 00:40:23 +0000 | [diff] [blame] | 2414 | int FI = MFI->CreateFixedObject(4, NextVA.getLocMemOffset(), true); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2415 | |
| 2416 | // Create load node to retrieve arguments from the stack. |
| 2417 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2418 | ArgValue2 = DAG.getLoad(MVT::i32, dl, Root, FIN, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2419 | MachinePointerInfo::getFixedStack(FI), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2420 | false, false, false, 0); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2421 | } else { |
Devang Patel | 68e6bee | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 2422 | Reg = MF.addLiveIn(NextVA.getLocReg(), RC); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2423 | ArgValue2 = DAG.getCopyFromReg(Root, dl, Reg, MVT::i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2424 | } |
| 2425 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 2426 | return DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, ArgValue, ArgValue2); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2427 | } |
| 2428 | |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2429 | void |
| 2430 | ARMTargetLowering::computeRegArea(CCState &CCInfo, MachineFunction &MF, |
| 2431 | unsigned &VARegSize, unsigned &VARegSaveSize) |
| 2432 | const { |
| 2433 | unsigned NumGPRs; |
| 2434 | if (CCInfo.isFirstByValRegValid()) |
| 2435 | NumGPRs = ARM::R4 - CCInfo.getFirstByValReg(); |
| 2436 | else { |
| 2437 | unsigned int firstUnalloced; |
| 2438 | firstUnalloced = CCInfo.getFirstUnallocated(GPRArgRegs, |
| 2439 | sizeof(GPRArgRegs) / |
| 2440 | sizeof(GPRArgRegs[0])); |
| 2441 | NumGPRs = (firstUnalloced <= 3) ? (4 - firstUnalloced) : 0; |
| 2442 | } |
| 2443 | |
| 2444 | unsigned Align = MF.getTarget().getFrameLowering()->getStackAlignment(); |
| 2445 | VARegSize = NumGPRs * 4; |
| 2446 | VARegSaveSize = (VARegSize + Align - 1) & ~(Align - 1); |
| 2447 | } |
| 2448 | |
| 2449 | // The remaining GPRs hold either the beginning of variable-argument |
| 2450 | // data, or the beginning of an aggregate passed by value (usuall |
| 2451 | // byval). Either way, we allocate stack slots adjacent to the data |
| 2452 | // provided by our caller, and store the unallocated registers there. |
| 2453 | // If this is a variadic function, the va_list pointer will begin with |
| 2454 | // these values; otherwise, this reassembles a (byval) structure that |
| 2455 | // was split between registers and memory. |
| 2456 | void |
| 2457 | ARMTargetLowering::VarArgStyleRegisters(CCState &CCInfo, SelectionDAG &DAG, |
| 2458 | DebugLoc dl, SDValue &Chain, |
| 2459 | unsigned ArgOffset) const { |
| 2460 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2461 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 2462 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2463 | unsigned firstRegToSaveIndex; |
| 2464 | if (CCInfo.isFirstByValRegValid()) |
| 2465 | firstRegToSaveIndex = CCInfo.getFirstByValReg() - ARM::R0; |
| 2466 | else { |
| 2467 | firstRegToSaveIndex = CCInfo.getFirstUnallocated |
| 2468 | (GPRArgRegs, sizeof(GPRArgRegs) / sizeof(GPRArgRegs[0])); |
| 2469 | } |
| 2470 | |
| 2471 | unsigned VARegSize, VARegSaveSize; |
| 2472 | computeRegArea(CCInfo, MF, VARegSize, VARegSaveSize); |
| 2473 | if (VARegSaveSize) { |
| 2474 | // If this function is vararg, store any remaining integer argument regs |
| 2475 | // to their spots on the stack so that they may be loaded by deferencing |
| 2476 | // the result of va_next. |
| 2477 | AFI->setVarArgsRegSaveSize(VARegSaveSize); |
Eric Christopher | 5ac179c | 2011-04-29 23:12:01 +0000 | [diff] [blame] | 2478 | AFI->setVarArgsFrameIndex(MFI->CreateFixedObject(VARegSaveSize, |
| 2479 | ArgOffset + VARegSaveSize |
| 2480 | - VARegSize, |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2481 | false)); |
| 2482 | SDValue FIN = DAG.getFrameIndex(AFI->getVarArgsFrameIndex(), |
| 2483 | getPointerTy()); |
| 2484 | |
| 2485 | SmallVector<SDValue, 4> MemOps; |
| 2486 | for (; firstRegToSaveIndex < 4; ++firstRegToSaveIndex) { |
| 2487 | TargetRegisterClass *RC; |
| 2488 | if (AFI->isThumb1OnlyFunction()) |
| 2489 | RC = ARM::tGPRRegisterClass; |
| 2490 | else |
| 2491 | RC = ARM::GPRRegisterClass; |
| 2492 | |
| 2493 | unsigned VReg = MF.addLiveIn(GPRArgRegs[firstRegToSaveIndex], RC); |
| 2494 | SDValue Val = DAG.getCopyFromReg(Chain, dl, VReg, MVT::i32); |
| 2495 | SDValue Store = |
| 2496 | DAG.getStore(Val.getValue(1), dl, Val, FIN, |
Eric Christopher | 5ac179c | 2011-04-29 23:12:01 +0000 | [diff] [blame] | 2497 | MachinePointerInfo::getFixedStack(AFI->getVarArgsFrameIndex()), |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2498 | false, false, 0); |
| 2499 | MemOps.push_back(Store); |
| 2500 | FIN = DAG.getNode(ISD::ADD, dl, getPointerTy(), FIN, |
| 2501 | DAG.getConstant(4, getPointerTy())); |
| 2502 | } |
| 2503 | if (!MemOps.empty()) |
| 2504 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, |
| 2505 | &MemOps[0], MemOps.size()); |
| 2506 | } else |
| 2507 | // This will point to the next argument passed via stack. |
| 2508 | AFI->setVarArgsFrameIndex(MFI->CreateFixedObject(4, ArgOffset, true)); |
| 2509 | } |
| 2510 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2511 | SDValue |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2512 | ARMTargetLowering::LowerFormalArguments(SDValue Chain, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 2513 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2514 | const SmallVectorImpl<ISD::InputArg> |
| 2515 | &Ins, |
| 2516 | DebugLoc dl, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2517 | SmallVectorImpl<SDValue> &InVals) |
| 2518 | const { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2519 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2520 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 2521 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2522 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2523 | |
| 2524 | // Assign locations to all of the incoming arguments. |
| 2525 | SmallVector<CCValAssign, 16> ArgLocs; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 2526 | ARMCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), |
| 2527 | getTargetMachine(), ArgLocs, *DAG.getContext(), Prologue); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2528 | CCInfo.AnalyzeFormalArguments(Ins, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 2529 | CCAssignFnForNode(CallConv, /* Return*/ false, |
| 2530 | isVarArg)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2531 | |
| 2532 | SmallVector<SDValue, 16> ArgValues; |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2533 | int lastInsIndex = -1; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2534 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2535 | SDValue ArgValue; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2536 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| 2537 | CCValAssign &VA = ArgLocs[i]; |
| 2538 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 2539 | // Arguments stored in registers. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2540 | if (VA.isRegLoc()) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2541 | EVT RegVT = VA.getLocVT(); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2542 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2543 | if (VA.needsCustom()) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2544 | // f64 and vector types are split up into multiple registers or |
| 2545 | // combinations of registers and stack slots. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2546 | if (VA.getLocVT() == MVT::v2f64) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2547 | SDValue ArgValue1 = GetF64FormalArgument(VA, ArgLocs[++i], |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2548 | Chain, DAG, dl); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2549 | VA = ArgLocs[++i]; // skip ahead to next loc |
Bob Wilson | 6a234f0 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 2550 | SDValue ArgValue2; |
| 2551 | if (VA.isMemLoc()) { |
Evan Cheng | ed2ae13 | 2010-07-03 00:40:23 +0000 | [diff] [blame] | 2552 | int FI = MFI->CreateFixedObject(8, VA.getLocMemOffset(), true); |
Bob Wilson | 6a234f0 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 2553 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
| 2554 | ArgValue2 = DAG.getLoad(MVT::f64, dl, Chain, FIN, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2555 | MachinePointerInfo::getFixedStack(FI), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2556 | false, false, false, 0); |
Bob Wilson | 6a234f0 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 2557 | } else { |
| 2558 | ArgValue2 = GetF64FormalArgument(VA, ArgLocs[++i], |
| 2559 | Chain, DAG, dl); |
| 2560 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2561 | ArgValue = DAG.getNode(ISD::UNDEF, dl, MVT::v2f64); |
| 2562 | ArgValue = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2563 | ArgValue, ArgValue1, DAG.getIntPtrConstant(0)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2564 | ArgValue = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2565 | ArgValue, ArgValue2, DAG.getIntPtrConstant(1)); |
| 2566 | } else |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2567 | ArgValue = GetF64FormalArgument(VA, ArgLocs[++i], Chain, DAG, dl); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2568 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2569 | } else { |
| 2570 | TargetRegisterClass *RC; |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 2571 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2572 | if (RegVT == MVT::f32) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2573 | RC = ARM::SPRRegisterClass; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2574 | else if (RegVT == MVT::f64) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2575 | RC = ARM::DPRRegisterClass; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2576 | else if (RegVT == MVT::v2f64) |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 2577 | RC = ARM::QPRRegisterClass; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2578 | else if (RegVT == MVT::i32) |
Anton Korobeynikov | 058c251 | 2009-08-05 20:15:19 +0000 | [diff] [blame] | 2579 | RC = (AFI->isThumb1OnlyFunction() ? |
| 2580 | ARM::tGPRRegisterClass : ARM::GPRRegisterClass); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2581 | else |
Anton Korobeynikov | 058c251 | 2009-08-05 20:15:19 +0000 | [diff] [blame] | 2582 | llvm_unreachable("RegVT not supported by FORMAL_ARGUMENTS Lowering"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2583 | |
| 2584 | // Transform the arguments in physical registers into virtual ones. |
Devang Patel | 68e6bee | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 2585 | unsigned Reg = MF.addLiveIn(VA.getLocReg(), RC); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2586 | ArgValue = DAG.getCopyFromReg(Chain, dl, Reg, RegVT); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2587 | } |
| 2588 | |
| 2589 | // If this is an 8 or 16-bit value, it is really passed promoted |
| 2590 | // to 32 bits. Insert an assert[sz]ext to capture this, then |
| 2591 | // truncate to the right size. |
| 2592 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 2593 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2594 | case CCValAssign::Full: break; |
| 2595 | case CCValAssign::BCvt: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2596 | ArgValue = DAG.getNode(ISD::BITCAST, dl, VA.getValVT(), ArgValue); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2597 | break; |
| 2598 | case CCValAssign::SExt: |
| 2599 | ArgValue = DAG.getNode(ISD::AssertSext, dl, RegVT, ArgValue, |
| 2600 | DAG.getValueType(VA.getValVT())); |
| 2601 | ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue); |
| 2602 | break; |
| 2603 | case CCValAssign::ZExt: |
| 2604 | ArgValue = DAG.getNode(ISD::AssertZext, dl, RegVT, ArgValue, |
| 2605 | DAG.getValueType(VA.getValVT())); |
| 2606 | ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue); |
| 2607 | break; |
| 2608 | } |
| 2609 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2610 | InVals.push_back(ArgValue); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2611 | |
| 2612 | } else { // VA.isRegLoc() |
| 2613 | |
| 2614 | // sanity check |
| 2615 | assert(VA.isMemLoc()); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2616 | assert(VA.getValVT() != MVT::i64 && "i64 should already be lowered"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2617 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2618 | int index = ArgLocs[i].getValNo(); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 2619 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2620 | // Some Ins[] entries become multiple ArgLoc[] entries. |
| 2621 | // Process them only once. |
| 2622 | if (index != lastInsIndex) |
| 2623 | { |
| 2624 | ISD::ArgFlagsTy Flags = Ins[index].Flags; |
Eric Christopher | 471e422 | 2011-06-08 23:55:35 +0000 | [diff] [blame] | 2625 | // FIXME: For now, all byval parameter objects are marked mutable. |
Eric Christopher | 5ac179c | 2011-04-29 23:12:01 +0000 | [diff] [blame] | 2626 | // This can be changed with more analysis. |
| 2627 | // In case of tail call optimization mark all arguments mutable. |
| 2628 | // Since they could be overwritten by lowering of arguments in case of |
| 2629 | // a tail call. |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2630 | if (Flags.isByVal()) { |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2631 | unsigned VARegSize, VARegSaveSize; |
| 2632 | computeRegArea(CCInfo, MF, VARegSize, VARegSaveSize); |
| 2633 | VarArgStyleRegisters(CCInfo, DAG, dl, Chain, 0); |
| 2634 | unsigned Bytes = Flags.getByValSize() - VARegSize; |
Evan Cheng | ee2e0e3 | 2011-03-30 23:44:13 +0000 | [diff] [blame] | 2635 | if (Bytes == 0) Bytes = 1; // Don't create zero-sized stack objects. |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2636 | int FI = MFI->CreateFixedObject(Bytes, |
| 2637 | VA.getLocMemOffset(), false); |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2638 | InVals.push_back(DAG.getFrameIndex(FI, getPointerTy())); |
| 2639 | } else { |
| 2640 | int FI = MFI->CreateFixedObject(VA.getLocVT().getSizeInBits()/8, |
| 2641 | VA.getLocMemOffset(), true); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2642 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2643 | // Create load nodes to retrieve arguments from the stack. |
| 2644 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
| 2645 | InVals.push_back(DAG.getLoad(VA.getValVT(), dl, Chain, FIN, |
| 2646 | MachinePointerInfo::getFixedStack(FI), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2647 | false, false, false, 0)); |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2648 | } |
| 2649 | lastInsIndex = index; |
| 2650 | } |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2651 | } |
| 2652 | } |
| 2653 | |
| 2654 | // varargs |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2655 | if (isVarArg) |
| 2656 | VarArgStyleRegisters(CCInfo, DAG, dl, Chain, CCInfo.getNextStackOffset()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2657 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2658 | return Chain; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2659 | } |
| 2660 | |
| 2661 | /// isFloatingPointZero - Return true if this is +0.0. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2662 | static bool isFloatingPointZero(SDValue Op) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2663 | if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(Op)) |
Dale Johannesen | eaf0894 | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 2664 | return CFP->getValueAPF().isPosZero(); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2665 | else if (ISD::isEXTLoad(Op.getNode()) || ISD::isNON_EXTLoad(Op.getNode())) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2666 | // Maybe this has already been legalized into the constant pool? |
| 2667 | if (Op.getOperand(1).getOpcode() == ARMISD::Wrapper) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2668 | SDValue WrapperOp = Op.getOperand(1).getOperand(0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2669 | if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(WrapperOp)) |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2670 | if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CP->getConstVal())) |
Dale Johannesen | eaf0894 | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 2671 | return CFP->getValueAPF().isPosZero(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2672 | } |
| 2673 | } |
| 2674 | return false; |
| 2675 | } |
| 2676 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2677 | /// Returns appropriate ARM CMP (cmp) and corresponding condition code for |
| 2678 | /// the given operands. |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 2679 | SDValue |
| 2680 | ARMTargetLowering::getARMCmp(SDValue LHS, SDValue RHS, ISD::CondCode CC, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2681 | SDValue &ARMcc, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2682 | DebugLoc dl) const { |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2683 | if (ConstantSDNode *RHSC = dyn_cast<ConstantSDNode>(RHS.getNode())) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2684 | unsigned C = RHSC->getZExtValue(); |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 2685 | if (!isLegalICmpImmediate(C)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2686 | // Constant does not fit, try adjusting it by one? |
| 2687 | switch (CC) { |
| 2688 | default: break; |
| 2689 | case ISD::SETLT: |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2690 | case ISD::SETGE: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 2691 | if (C != 0x80000000 && isLegalICmpImmediate(C-1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2692 | CC = (CC == ISD::SETLT) ? ISD::SETLE : ISD::SETGT; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2693 | RHS = DAG.getConstant(C-1, MVT::i32); |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2694 | } |
| 2695 | break; |
| 2696 | case ISD::SETULT: |
| 2697 | case ISD::SETUGE: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 2698 | if (C != 0 && isLegalICmpImmediate(C-1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2699 | CC = (CC == ISD::SETULT) ? ISD::SETULE : ISD::SETUGT; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2700 | RHS = DAG.getConstant(C-1, MVT::i32); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2701 | } |
| 2702 | break; |
| 2703 | case ISD::SETLE: |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2704 | case ISD::SETGT: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 2705 | if (C != 0x7fffffff && isLegalICmpImmediate(C+1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2706 | CC = (CC == ISD::SETLE) ? ISD::SETLT : ISD::SETGE; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2707 | RHS = DAG.getConstant(C+1, MVT::i32); |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2708 | } |
| 2709 | break; |
| 2710 | case ISD::SETULE: |
| 2711 | case ISD::SETUGT: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 2712 | if (C != 0xffffffff && isLegalICmpImmediate(C+1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2713 | CC = (CC == ISD::SETULE) ? ISD::SETULT : ISD::SETUGE; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2714 | RHS = DAG.getConstant(C+1, MVT::i32); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2715 | } |
| 2716 | break; |
| 2717 | } |
| 2718 | } |
| 2719 | } |
| 2720 | |
| 2721 | ARMCC::CondCodes CondCode = IntCCToARMCC(CC); |
Lauro Ramos Venancio | 9996663 | 2007-04-02 01:30:03 +0000 | [diff] [blame] | 2722 | ARMISD::NodeType CompareType; |
| 2723 | switch (CondCode) { |
| 2724 | default: |
| 2725 | CompareType = ARMISD::CMP; |
| 2726 | break; |
| 2727 | case ARMCC::EQ: |
| 2728 | case ARMCC::NE: |
David Goodwin | c0309b4 | 2009-06-29 15:33:01 +0000 | [diff] [blame] | 2729 | // Uses only Z Flag |
| 2730 | CompareType = ARMISD::CMPZ; |
Lauro Ramos Venancio | 9996663 | 2007-04-02 01:30:03 +0000 | [diff] [blame] | 2731 | break; |
| 2732 | } |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2733 | ARMcc = DAG.getConstant(CondCode, MVT::i32); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 2734 | return DAG.getNode(CompareType, dl, MVT::Glue, LHS, RHS); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2735 | } |
| 2736 | |
| 2737 | /// 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] | 2738 | SDValue |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2739 | ARMTargetLowering::getVFPCmp(SDValue LHS, SDValue RHS, SelectionDAG &DAG, |
Evan Cheng | 515fe3a | 2010-07-08 02:08:50 +0000 | [diff] [blame] | 2740 | DebugLoc dl) const { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2741 | SDValue Cmp; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2742 | if (!isFloatingPointZero(RHS)) |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 2743 | Cmp = DAG.getNode(ARMISD::CMPFP, dl, MVT::Glue, LHS, RHS); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2744 | else |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 2745 | Cmp = DAG.getNode(ARMISD::CMPFPw0, dl, MVT::Glue, LHS); |
| 2746 | return DAG.getNode(ARMISD::FMSTAT, dl, MVT::Glue, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2747 | } |
| 2748 | |
Bob Wilson | 79f56c9 | 2011-03-08 01:17:20 +0000 | [diff] [blame] | 2749 | /// duplicateCmp - Glue values can have only one use, so this function |
| 2750 | /// duplicates a comparison node. |
| 2751 | SDValue |
| 2752 | ARMTargetLowering::duplicateCmp(SDValue Cmp, SelectionDAG &DAG) const { |
| 2753 | unsigned Opc = Cmp.getOpcode(); |
| 2754 | DebugLoc DL = Cmp.getDebugLoc(); |
| 2755 | if (Opc == ARMISD::CMP || Opc == ARMISD::CMPZ) |
| 2756 | return DAG.getNode(Opc, DL, MVT::Glue, Cmp.getOperand(0),Cmp.getOperand(1)); |
| 2757 | |
| 2758 | assert(Opc == ARMISD::FMSTAT && "unexpected comparison operation"); |
| 2759 | Cmp = Cmp.getOperand(0); |
| 2760 | Opc = Cmp.getOpcode(); |
| 2761 | if (Opc == ARMISD::CMPFP) |
| 2762 | Cmp = DAG.getNode(Opc, DL, MVT::Glue, Cmp.getOperand(0),Cmp.getOperand(1)); |
| 2763 | else { |
| 2764 | assert(Opc == ARMISD::CMPFPw0 && "unexpected operand of FMSTAT"); |
| 2765 | Cmp = DAG.getNode(Opc, DL, MVT::Glue, Cmp.getOperand(0)); |
| 2766 | } |
| 2767 | return DAG.getNode(ARMISD::FMSTAT, DL, MVT::Glue, Cmp); |
| 2768 | } |
| 2769 | |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 2770 | SDValue ARMTargetLowering::LowerSELECT(SDValue Op, SelectionDAG &DAG) const { |
| 2771 | SDValue Cond = Op.getOperand(0); |
| 2772 | SDValue SelectTrue = Op.getOperand(1); |
| 2773 | SDValue SelectFalse = Op.getOperand(2); |
| 2774 | DebugLoc dl = Op.getDebugLoc(); |
| 2775 | |
| 2776 | // Convert: |
| 2777 | // |
| 2778 | // (select (cmov 1, 0, cond), t, f) -> (cmov t, f, cond) |
| 2779 | // (select (cmov 0, 1, cond), t, f) -> (cmov f, t, cond) |
| 2780 | // |
| 2781 | if (Cond.getOpcode() == ARMISD::CMOV && Cond.hasOneUse()) { |
| 2782 | const ConstantSDNode *CMOVTrue = |
| 2783 | dyn_cast<ConstantSDNode>(Cond.getOperand(0)); |
| 2784 | const ConstantSDNode *CMOVFalse = |
| 2785 | dyn_cast<ConstantSDNode>(Cond.getOperand(1)); |
| 2786 | |
| 2787 | if (CMOVTrue && CMOVFalse) { |
| 2788 | unsigned CMOVTrueVal = CMOVTrue->getZExtValue(); |
| 2789 | unsigned CMOVFalseVal = CMOVFalse->getZExtValue(); |
| 2790 | |
| 2791 | SDValue True; |
| 2792 | SDValue False; |
| 2793 | if (CMOVTrueVal == 1 && CMOVFalseVal == 0) { |
| 2794 | True = SelectTrue; |
| 2795 | False = SelectFalse; |
| 2796 | } else if (CMOVTrueVal == 0 && CMOVFalseVal == 1) { |
| 2797 | True = SelectFalse; |
| 2798 | False = SelectTrue; |
| 2799 | } |
| 2800 | |
| 2801 | if (True.getNode() && False.getNode()) { |
Evan Cheng | b936e30 | 2011-05-18 18:59:17 +0000 | [diff] [blame] | 2802 | EVT VT = Op.getValueType(); |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 2803 | SDValue ARMcc = Cond.getOperand(2); |
| 2804 | SDValue CCR = Cond.getOperand(3); |
Bob Wilson | 79f56c9 | 2011-03-08 01:17:20 +0000 | [diff] [blame] | 2805 | SDValue Cmp = duplicateCmp(Cond.getOperand(4), DAG); |
Evan Cheng | b936e30 | 2011-05-18 18:59:17 +0000 | [diff] [blame] | 2806 | assert(True.getValueType() == VT); |
| 2807 | return DAG.getNode(ARMISD::CMOV, dl, VT, True, False, ARMcc, CCR, Cmp); |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 2808 | } |
| 2809 | } |
| 2810 | } |
| 2811 | |
| 2812 | return DAG.getSelectCC(dl, Cond, |
| 2813 | DAG.getConstant(0, Cond.getValueType()), |
| 2814 | SelectTrue, SelectFalse, ISD::SETNE); |
| 2815 | } |
| 2816 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2817 | SDValue ARMTargetLowering::LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2818 | EVT VT = Op.getValueType(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2819 | SDValue LHS = Op.getOperand(0); |
| 2820 | SDValue RHS = Op.getOperand(1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2821 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(4))->get(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2822 | SDValue TrueVal = Op.getOperand(2); |
| 2823 | SDValue FalseVal = Op.getOperand(3); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2824 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2825 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2826 | if (LHS.getValueType() == MVT::i32) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2827 | SDValue ARMcc; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2828 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2829 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMcc, DAG, dl); |
Jim Grosbach | b04546f | 2011-09-13 20:30:37 +0000 | [diff] [blame] | 2830 | return DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, ARMcc, CCR,Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2831 | } |
| 2832 | |
| 2833 | ARMCC::CondCodes CondCode, CondCode2; |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 2834 | FPCCToARMCC(CC, CondCode, CondCode2); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2835 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2836 | SDValue ARMcc = DAG.getConstant(CondCode, MVT::i32); |
| 2837 | SDValue Cmp = getVFPCmp(LHS, RHS, DAG, dl); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2838 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2839 | SDValue Result = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2840 | ARMcc, CCR, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2841 | if (CondCode2 != ARMCC::AL) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2842 | SDValue ARMcc2 = DAG.getConstant(CondCode2, MVT::i32); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2843 | // FIXME: Needs another CMP because flag can have but one use. |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2844 | SDValue Cmp2 = getVFPCmp(LHS, RHS, DAG, dl); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2845 | Result = DAG.getNode(ARMISD::CMOV, dl, VT, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2846 | Result, TrueVal, ARMcc2, CCR, Cmp2); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2847 | } |
| 2848 | return Result; |
| 2849 | } |
| 2850 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2851 | /// canChangeToInt - Given the fp compare operand, return true if it is suitable |
| 2852 | /// to morph to an integer compare sequence. |
| 2853 | static bool canChangeToInt(SDValue Op, bool &SeenZero, |
| 2854 | const ARMSubtarget *Subtarget) { |
| 2855 | SDNode *N = Op.getNode(); |
| 2856 | if (!N->hasOneUse()) |
| 2857 | // Otherwise it requires moving the value from fp to integer registers. |
| 2858 | return false; |
| 2859 | if (!N->getNumValues()) |
| 2860 | return false; |
| 2861 | EVT VT = Op.getValueType(); |
| 2862 | if (VT != MVT::f32 && !Subtarget->isFPBrccSlow()) |
| 2863 | // f32 case is generally profitable. f64 case only makes sense when vcmpe + |
| 2864 | // vmrs are very slow, e.g. cortex-a8. |
| 2865 | return false; |
| 2866 | |
| 2867 | if (isFloatingPointZero(Op)) { |
| 2868 | SeenZero = true; |
| 2869 | return true; |
| 2870 | } |
| 2871 | return ISD::isNormalLoad(N); |
| 2872 | } |
| 2873 | |
| 2874 | static SDValue bitcastf32Toi32(SDValue Op, SelectionDAG &DAG) { |
| 2875 | if (isFloatingPointZero(Op)) |
| 2876 | return DAG.getConstant(0, MVT::i32); |
| 2877 | |
| 2878 | if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Op)) |
| 2879 | return DAG.getLoad(MVT::i32, Op.getDebugLoc(), |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2880 | Ld->getChain(), Ld->getBasePtr(), Ld->getPointerInfo(), |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2881 | Ld->isVolatile(), Ld->isNonTemporal(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2882 | Ld->isInvariant(), Ld->getAlignment()); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2883 | |
| 2884 | llvm_unreachable("Unknown VFP cmp argument!"); |
| 2885 | } |
| 2886 | |
| 2887 | static void expandf64Toi32(SDValue Op, SelectionDAG &DAG, |
| 2888 | SDValue &RetVal1, SDValue &RetVal2) { |
| 2889 | if (isFloatingPointZero(Op)) { |
| 2890 | RetVal1 = DAG.getConstant(0, MVT::i32); |
| 2891 | RetVal2 = DAG.getConstant(0, MVT::i32); |
| 2892 | return; |
| 2893 | } |
| 2894 | |
| 2895 | if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Op)) { |
| 2896 | SDValue Ptr = Ld->getBasePtr(); |
| 2897 | RetVal1 = DAG.getLoad(MVT::i32, Op.getDebugLoc(), |
| 2898 | Ld->getChain(), Ptr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2899 | Ld->getPointerInfo(), |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2900 | Ld->isVolatile(), Ld->isNonTemporal(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2901 | Ld->isInvariant(), Ld->getAlignment()); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2902 | |
| 2903 | EVT PtrType = Ptr.getValueType(); |
| 2904 | unsigned NewAlign = MinAlign(Ld->getAlignment(), 4); |
| 2905 | SDValue NewPtr = DAG.getNode(ISD::ADD, Op.getDebugLoc(), |
| 2906 | PtrType, Ptr, DAG.getConstant(4, PtrType)); |
| 2907 | RetVal2 = DAG.getLoad(MVT::i32, Op.getDebugLoc(), |
| 2908 | Ld->getChain(), NewPtr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2909 | Ld->getPointerInfo().getWithOffset(4), |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2910 | Ld->isVolatile(), Ld->isNonTemporal(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2911 | Ld->isInvariant(), NewAlign); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2912 | return; |
| 2913 | } |
| 2914 | |
| 2915 | llvm_unreachable("Unknown VFP cmp argument!"); |
| 2916 | } |
| 2917 | |
| 2918 | /// OptimizeVFPBrcond - With -enable-unsafe-fp-math, it's legal to optimize some |
| 2919 | /// f32 and even f64 comparisons to integer ones. |
| 2920 | SDValue |
| 2921 | ARMTargetLowering::OptimizeVFPBrcond(SDValue Op, SelectionDAG &DAG) const { |
| 2922 | SDValue Chain = Op.getOperand(0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2923 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get(); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2924 | SDValue LHS = Op.getOperand(2); |
| 2925 | SDValue RHS = Op.getOperand(3); |
| 2926 | SDValue Dest = Op.getOperand(4); |
| 2927 | DebugLoc dl = Op.getDebugLoc(); |
| 2928 | |
| 2929 | bool SeenZero = false; |
| 2930 | if (canChangeToInt(LHS, SeenZero, Subtarget) && |
| 2931 | canChangeToInt(RHS, SeenZero, Subtarget) && |
Evan Cheng | 60108e9 | 2010-07-15 22:07:12 +0000 | [diff] [blame] | 2932 | // If one of the operand is zero, it's safe to ignore the NaN case since |
| 2933 | // we only care about equality comparisons. |
| 2934 | (SeenZero || (DAG.isKnownNeverNaN(LHS) && DAG.isKnownNeverNaN(RHS)))) { |
Bob Wilson | 1b772f9 | 2011-03-08 01:17:16 +0000 | [diff] [blame] | 2935 | // If unsafe fp math optimization is enabled and there are no other uses of |
| 2936 | // 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] | 2937 | // to an integer comparison. |
| 2938 | if (CC == ISD::SETOEQ) |
| 2939 | CC = ISD::SETEQ; |
| 2940 | else if (CC == ISD::SETUNE) |
| 2941 | CC = ISD::SETNE; |
| 2942 | |
| 2943 | SDValue ARMcc; |
| 2944 | if (LHS.getValueType() == MVT::f32) { |
| 2945 | LHS = bitcastf32Toi32(LHS, DAG); |
| 2946 | RHS = bitcastf32Toi32(RHS, DAG); |
| 2947 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMcc, DAG, dl); |
| 2948 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| 2949 | return DAG.getNode(ARMISD::BRCOND, dl, MVT::Other, |
| 2950 | Chain, Dest, ARMcc, CCR, Cmp); |
| 2951 | } |
| 2952 | |
| 2953 | SDValue LHS1, LHS2; |
| 2954 | SDValue RHS1, RHS2; |
| 2955 | expandf64Toi32(LHS, DAG, LHS1, LHS2); |
| 2956 | expandf64Toi32(RHS, DAG, RHS1, RHS2); |
| 2957 | ARMCC::CondCodes CondCode = IntCCToARMCC(CC); |
| 2958 | ARMcc = DAG.getConstant(CondCode, MVT::i32); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 2959 | SDVTList VTList = DAG.getVTList(MVT::Other, MVT::Glue); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2960 | SDValue Ops[] = { Chain, ARMcc, LHS1, LHS2, RHS1, RHS2, Dest }; |
| 2961 | return DAG.getNode(ARMISD::BCC_i64, dl, VTList, Ops, 7); |
| 2962 | } |
| 2963 | |
| 2964 | return SDValue(); |
| 2965 | } |
| 2966 | |
| 2967 | SDValue ARMTargetLowering::LowerBR_CC(SDValue Op, SelectionDAG &DAG) const { |
| 2968 | SDValue Chain = Op.getOperand(0); |
| 2969 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get(); |
| 2970 | SDValue LHS = Op.getOperand(2); |
| 2971 | SDValue RHS = Op.getOperand(3); |
| 2972 | SDValue Dest = Op.getOperand(4); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2973 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2974 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2975 | if (LHS.getValueType() == MVT::i32) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2976 | SDValue ARMcc; |
| 2977 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMcc, DAG, dl); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2978 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2979 | return DAG.getNode(ARMISD::BRCOND, dl, MVT::Other, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2980 | Chain, Dest, ARMcc, CCR, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2981 | } |
| 2982 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2983 | assert(LHS.getValueType() == MVT::f32 || LHS.getValueType() == MVT::f64); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2984 | |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 2985 | if (getTargetMachine().Options.UnsafeFPMath && |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2986 | (CC == ISD::SETEQ || CC == ISD::SETOEQ || |
| 2987 | CC == ISD::SETNE || CC == ISD::SETUNE)) { |
| 2988 | SDValue Result = OptimizeVFPBrcond(Op, DAG); |
| 2989 | if (Result.getNode()) |
| 2990 | return Result; |
| 2991 | } |
| 2992 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2993 | ARMCC::CondCodes CondCode, CondCode2; |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 2994 | FPCCToARMCC(CC, CondCode, CondCode2); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2995 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2996 | SDValue ARMcc = DAG.getConstant(CondCode, MVT::i32); |
| 2997 | SDValue Cmp = getVFPCmp(LHS, RHS, DAG, dl); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2998 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 2999 | SDVTList VTList = DAG.getVTList(MVT::Other, MVT::Glue); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3000 | SDValue Ops[] = { Chain, Dest, ARMcc, CCR, Cmp }; |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 3001 | SDValue Res = DAG.getNode(ARMISD::BRCOND, dl, VTList, Ops, 5); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3002 | if (CondCode2 != ARMCC::AL) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3003 | ARMcc = DAG.getConstant(CondCode2, MVT::i32); |
| 3004 | SDValue Ops[] = { Res, Dest, ARMcc, CCR, Res.getValue(1) }; |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 3005 | Res = DAG.getNode(ARMISD::BRCOND, dl, VTList, Ops, 5); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3006 | } |
| 3007 | return Res; |
| 3008 | } |
| 3009 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 3010 | SDValue ARMTargetLowering::LowerBR_JT(SDValue Op, SelectionDAG &DAG) const { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3011 | SDValue Chain = Op.getOperand(0); |
| 3012 | SDValue Table = Op.getOperand(1); |
| 3013 | SDValue Index = Op.getOperand(2); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 3014 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3015 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3016 | EVT PTy = getPointerTy(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3017 | JumpTableSDNode *JT = cast<JumpTableSDNode>(Table); |
| 3018 | ARMFunctionInfo *AFI = DAG.getMachineFunction().getInfo<ARMFunctionInfo>(); |
Bob Wilson | 3eadf00 | 2009-07-14 18:44:34 +0000 | [diff] [blame] | 3019 | SDValue UId = DAG.getConstant(AFI->createJumpTableUId(), PTy); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3020 | SDValue JTI = DAG.getTargetJumpTable(JT->getIndex(), PTy); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3021 | Table = DAG.getNode(ARMISD::WrapperJT, dl, MVT::i32, JTI, UId); |
Evan Cheng | e7c329b | 2009-07-28 20:53:24 +0000 | [diff] [blame] | 3022 | Index = DAG.getNode(ISD::MUL, dl, PTy, Index, DAG.getConstant(4, PTy)); |
| 3023 | SDValue Addr = DAG.getNode(ISD::ADD, dl, PTy, Index, Table); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3024 | if (Subtarget->isThumb2()) { |
| 3025 | // Thumb2 uses a two-level jump. That is, it jumps into the jump table |
| 3026 | // which does another jump to the destination. This also makes it easier |
| 3027 | // to translate it to TBB / TBH later. |
| 3028 | // FIXME: This might not work if the function is extremely large. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3029 | return DAG.getNode(ARMISD::BR2_JT, dl, MVT::Other, Chain, |
Evan Cheng | 5657c01 | 2009-07-29 02:18:14 +0000 | [diff] [blame] | 3030 | Addr, Op.getOperand(2), JTI, UId); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3031 | } |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3032 | if (getTargetMachine().getRelocationModel() == Reloc::PIC_) { |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 3033 | Addr = DAG.getLoad((EVT)MVT::i32, dl, Chain, Addr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 3034 | MachinePointerInfo::getJumpTable(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3035 | false, false, false, 0); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3036 | Chain = Addr.getValue(1); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 3037 | Addr = DAG.getNode(ISD::ADD, dl, PTy, Addr, Table); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3038 | 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] | 3039 | } else { |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 3040 | Addr = DAG.getLoad(PTy, dl, Chain, Addr, |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3041 | MachinePointerInfo::getJumpTable(), |
| 3042 | false, false, false, 0); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3043 | Chain = Addr.getValue(1); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3044 | 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] | 3045 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3046 | } |
| 3047 | |
Eli Friedman | 14e809c | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3048 | static SDValue LowerVectorFP_TO_INT(SDValue Op, SelectionDAG &DAG) { |
David Blaikie | 810d6d3 | 2012-01-16 05:17:39 +0000 | [diff] [blame] | 3049 | assert(Op.getValueType().getVectorElementType() == MVT::i32 |
| 3050 | && "Unexpected custom lowering"); |
Eli Friedman | 14e809c | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3051 | |
| 3052 | if (Op.getOperand(0).getValueType().getVectorElementType() == MVT::f32) |
| 3053 | return Op; |
| 3054 | return DAG.UnrollVectorOp(Op.getNode()); |
| 3055 | } |
| 3056 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3057 | static SDValue LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG) { |
Eli Friedman | 14e809c | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3058 | EVT VT = Op.getValueType(); |
| 3059 | if (VT.isVector()) |
| 3060 | return LowerVectorFP_TO_INT(Op, DAG); |
| 3061 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3062 | DebugLoc dl = Op.getDebugLoc(); |
| 3063 | unsigned Opc; |
| 3064 | |
| 3065 | switch (Op.getOpcode()) { |
| 3066 | default: |
| 3067 | assert(0 && "Invalid opcode!"); |
| 3068 | case ISD::FP_TO_SINT: |
| 3069 | Opc = ARMISD::FTOSI; |
| 3070 | break; |
| 3071 | case ISD::FP_TO_UINT: |
| 3072 | Opc = ARMISD::FTOUI; |
| 3073 | break; |
| 3074 | } |
| 3075 | Op = DAG.getNode(Opc, dl, MVT::f32, Op.getOperand(0)); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3076 | return DAG.getNode(ISD::BITCAST, dl, MVT::i32, Op); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3077 | } |
| 3078 | |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 3079 | static SDValue LowerVectorINT_TO_FP(SDValue Op, SelectionDAG &DAG) { |
| 3080 | EVT VT = Op.getValueType(); |
| 3081 | DebugLoc dl = Op.getDebugLoc(); |
| 3082 | |
Eli Friedman | 14e809c | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3083 | if (Op.getOperand(0).getValueType().getVectorElementType() == MVT::i32) { |
| 3084 | if (VT.getVectorElementType() == MVT::f32) |
| 3085 | return Op; |
| 3086 | return DAG.UnrollVectorOp(Op.getNode()); |
| 3087 | } |
| 3088 | |
Duncan Sands | 1f6a329 | 2011-08-12 14:54:45 +0000 | [diff] [blame] | 3089 | assert(Op.getOperand(0).getValueType() == MVT::v4i16 && |
| 3090 | "Invalid type for custom lowering!"); |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 3091 | if (VT != MVT::v4f32) |
| 3092 | return DAG.UnrollVectorOp(Op.getNode()); |
| 3093 | |
| 3094 | unsigned CastOpc; |
| 3095 | unsigned Opc; |
| 3096 | switch (Op.getOpcode()) { |
| 3097 | default: |
| 3098 | assert(0 && "Invalid opcode!"); |
| 3099 | case ISD::SINT_TO_FP: |
| 3100 | CastOpc = ISD::SIGN_EXTEND; |
| 3101 | Opc = ISD::SINT_TO_FP; |
| 3102 | break; |
| 3103 | case ISD::UINT_TO_FP: |
| 3104 | CastOpc = ISD::ZERO_EXTEND; |
| 3105 | Opc = ISD::UINT_TO_FP; |
| 3106 | break; |
| 3107 | } |
| 3108 | |
| 3109 | Op = DAG.getNode(CastOpc, dl, MVT::v4i32, Op.getOperand(0)); |
| 3110 | return DAG.getNode(Opc, dl, VT, Op); |
| 3111 | } |
| 3112 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3113 | static SDValue LowerINT_TO_FP(SDValue Op, SelectionDAG &DAG) { |
| 3114 | EVT VT = Op.getValueType(); |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 3115 | if (VT.isVector()) |
| 3116 | return LowerVectorINT_TO_FP(Op, DAG); |
| 3117 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3118 | DebugLoc dl = Op.getDebugLoc(); |
| 3119 | unsigned Opc; |
| 3120 | |
| 3121 | switch (Op.getOpcode()) { |
| 3122 | default: |
| 3123 | assert(0 && "Invalid opcode!"); |
| 3124 | case ISD::SINT_TO_FP: |
| 3125 | Opc = ARMISD::SITOF; |
| 3126 | break; |
| 3127 | case ISD::UINT_TO_FP: |
| 3128 | Opc = ARMISD::UITOF; |
| 3129 | break; |
| 3130 | } |
| 3131 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3132 | Op = DAG.getNode(ISD::BITCAST, dl, MVT::f32, Op.getOperand(0)); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3133 | return DAG.getNode(Opc, dl, VT, Op); |
| 3134 | } |
| 3135 | |
Evan Cheng | 515fe3a | 2010-07-08 02:08:50 +0000 | [diff] [blame] | 3136 | SDValue ARMTargetLowering::LowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3137 | // Implement fcopysign with a fabs and a conditional fneg. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3138 | SDValue Tmp0 = Op.getOperand(0); |
| 3139 | SDValue Tmp1 = Op.getOperand(1); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 3140 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3141 | EVT VT = Op.getValueType(); |
| 3142 | EVT SrcVT = Tmp1.getValueType(); |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3143 | bool InGPR = Tmp0.getOpcode() == ISD::BITCAST || |
| 3144 | Tmp0.getOpcode() == ARMISD::VMOVDRR; |
| 3145 | bool UseNEON = !InGPR && Subtarget->hasNEON(); |
| 3146 | |
| 3147 | if (UseNEON) { |
| 3148 | // Use VBSL to copy the sign bit. |
| 3149 | unsigned EncodedVal = ARM_AM::createNEONModImm(0x6, 0x80); |
| 3150 | SDValue Mask = DAG.getNode(ARMISD::VMOVIMM, dl, MVT::v2i32, |
| 3151 | DAG.getTargetConstant(EncodedVal, MVT::i32)); |
| 3152 | EVT OpVT = (VT == MVT::f32) ? MVT::v2i32 : MVT::v1i64; |
| 3153 | if (VT == MVT::f64) |
| 3154 | Mask = DAG.getNode(ARMISD::VSHL, dl, OpVT, |
| 3155 | DAG.getNode(ISD::BITCAST, dl, OpVT, Mask), |
| 3156 | DAG.getConstant(32, MVT::i32)); |
| 3157 | else /*if (VT == MVT::f32)*/ |
| 3158 | Tmp0 = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, MVT::v2f32, Tmp0); |
| 3159 | if (SrcVT == MVT::f32) { |
| 3160 | Tmp1 = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, MVT::v2f32, Tmp1); |
| 3161 | if (VT == MVT::f64) |
| 3162 | Tmp1 = DAG.getNode(ARMISD::VSHL, dl, OpVT, |
| 3163 | DAG.getNode(ISD::BITCAST, dl, OpVT, Tmp1), |
| 3164 | DAG.getConstant(32, MVT::i32)); |
Evan Cheng | 9eec66e | 2011-04-15 01:31:00 +0000 | [diff] [blame] | 3165 | } else if (VT == MVT::f32) |
| 3166 | Tmp1 = DAG.getNode(ARMISD::VSHRu, dl, MVT::v1i64, |
| 3167 | DAG.getNode(ISD::BITCAST, dl, MVT::v1i64, Tmp1), |
| 3168 | DAG.getConstant(32, MVT::i32)); |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3169 | Tmp0 = DAG.getNode(ISD::BITCAST, dl, OpVT, Tmp0); |
| 3170 | Tmp1 = DAG.getNode(ISD::BITCAST, dl, OpVT, Tmp1); |
| 3171 | |
| 3172 | SDValue AllOnes = DAG.getTargetConstant(ARM_AM::createNEONModImm(0xe, 0xff), |
| 3173 | MVT::i32); |
| 3174 | AllOnes = DAG.getNode(ARMISD::VMOVIMM, dl, MVT::v8i8, AllOnes); |
| 3175 | SDValue MaskNot = DAG.getNode(ISD::XOR, dl, OpVT, Mask, |
| 3176 | DAG.getNode(ISD::BITCAST, dl, OpVT, AllOnes)); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 3177 | |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3178 | SDValue Res = DAG.getNode(ISD::OR, dl, OpVT, |
| 3179 | DAG.getNode(ISD::AND, dl, OpVT, Tmp1, Mask), |
| 3180 | DAG.getNode(ISD::AND, dl, OpVT, Tmp0, MaskNot)); |
Evan Cheng | c24ab5c | 2011-02-28 18:45:27 +0000 | [diff] [blame] | 3181 | if (VT == MVT::f32) { |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3182 | Res = DAG.getNode(ISD::BITCAST, dl, MVT::v2f32, Res); |
| 3183 | Res = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f32, Res, |
| 3184 | DAG.getConstant(0, MVT::i32)); |
| 3185 | } else { |
| 3186 | Res = DAG.getNode(ISD::BITCAST, dl, MVT::f64, Res); |
| 3187 | } |
| 3188 | |
| 3189 | return Res; |
| 3190 | } |
Evan Cheng | c143dd4 | 2011-02-11 02:28:55 +0000 | [diff] [blame] | 3191 | |
| 3192 | // Bitcast operand 1 to i32. |
| 3193 | if (SrcVT == MVT::f64) |
| 3194 | Tmp1 = DAG.getNode(ARMISD::VMOVRRD, dl, DAG.getVTList(MVT::i32, MVT::i32), |
| 3195 | &Tmp1, 1).getValue(1); |
| 3196 | Tmp1 = DAG.getNode(ISD::BITCAST, dl, MVT::i32, Tmp1); |
| 3197 | |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3198 | // Or in the signbit with integer operations. |
| 3199 | SDValue Mask1 = DAG.getConstant(0x80000000, MVT::i32); |
| 3200 | SDValue Mask2 = DAG.getConstant(0x7fffffff, MVT::i32); |
| 3201 | Tmp1 = DAG.getNode(ISD::AND, dl, MVT::i32, Tmp1, Mask1); |
| 3202 | if (VT == MVT::f32) { |
| 3203 | Tmp0 = DAG.getNode(ISD::AND, dl, MVT::i32, |
| 3204 | DAG.getNode(ISD::BITCAST, dl, MVT::i32, Tmp0), Mask2); |
| 3205 | return DAG.getNode(ISD::BITCAST, dl, MVT::f32, |
| 3206 | DAG.getNode(ISD::OR, dl, MVT::i32, Tmp0, Tmp1)); |
Evan Cheng | c143dd4 | 2011-02-11 02:28:55 +0000 | [diff] [blame] | 3207 | } |
| 3208 | |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3209 | // f64: Or the high part with signbit and then combine two parts. |
| 3210 | Tmp0 = DAG.getNode(ARMISD::VMOVRRD, dl, DAG.getVTList(MVT::i32, MVT::i32), |
| 3211 | &Tmp0, 1); |
| 3212 | SDValue Lo = Tmp0.getValue(0); |
| 3213 | SDValue Hi = DAG.getNode(ISD::AND, dl, MVT::i32, Tmp0.getValue(1), Mask2); |
| 3214 | Hi = DAG.getNode(ISD::OR, dl, MVT::i32, Hi, Tmp1); |
| 3215 | return DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3216 | } |
| 3217 | |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3218 | SDValue ARMTargetLowering::LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const{ |
| 3219 | MachineFunction &MF = DAG.getMachineFunction(); |
| 3220 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 3221 | MFI->setReturnAddressIsTaken(true); |
| 3222 | |
| 3223 | EVT VT = Op.getValueType(); |
| 3224 | DebugLoc dl = Op.getDebugLoc(); |
| 3225 | unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
| 3226 | if (Depth) { |
| 3227 | SDValue FrameAddr = LowerFRAMEADDR(Op, DAG); |
| 3228 | SDValue Offset = DAG.getConstant(4, MVT::i32); |
| 3229 | return DAG.getLoad(VT, dl, DAG.getEntryNode(), |
| 3230 | DAG.getNode(ISD::ADD, dl, VT, FrameAddr, Offset), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3231 | MachinePointerInfo(), false, false, false, 0); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3232 | } |
| 3233 | |
| 3234 | // 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] | 3235 | unsigned Reg = MF.addLiveIn(ARM::LR, getRegClassFor(MVT::i32)); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3236 | return DAG.getCopyFromReg(DAG.getEntryNode(), dl, Reg, VT); |
| 3237 | } |
| 3238 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 3239 | SDValue ARMTargetLowering::LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const { |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3240 | MachineFrameInfo *MFI = DAG.getMachineFunction().getFrameInfo(); |
| 3241 | MFI->setFrameAddressIsTaken(true); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3242 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3243 | EVT VT = Op.getValueType(); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3244 | DebugLoc dl = Op.getDebugLoc(); // FIXME probably not meaningful |
| 3245 | unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
Evan Cheng | cd82861 | 2009-06-18 23:14:30 +0000 | [diff] [blame] | 3246 | unsigned FrameReg = (Subtarget->isThumb() || Subtarget->isTargetDarwin()) |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3247 | ? ARM::R7 : ARM::R11; |
| 3248 | SDValue FrameAddr = DAG.getCopyFromReg(DAG.getEntryNode(), dl, FrameReg, VT); |
| 3249 | while (Depth--) |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 3250 | FrameAddr = DAG.getLoad(VT, dl, DAG.getEntryNode(), FrameAddr, |
| 3251 | MachinePointerInfo(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3252 | false, false, false, 0); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3253 | return FrameAddr; |
| 3254 | } |
| 3255 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3256 | /// ExpandBITCAST - If the target supports VFP, this function is called to |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3257 | /// expand a bit convert where either the source or destination type is i64 to |
| 3258 | /// use a VMOVDRR or VMOVRRD node. This should not be done when the non-i64 |
| 3259 | /// operand type is illegal (e.g., v2f32 for a target that doesn't support |
| 3260 | /// vectors), since the legalizer won't know what to do with that. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3261 | static SDValue ExpandBITCAST(SDNode *N, SelectionDAG &DAG) { |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3262 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 3263 | DebugLoc dl = N->getDebugLoc(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3264 | SDValue Op = N->getOperand(0); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 3265 | |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3266 | // This function is only supposed to be called for i64 types, either as the |
| 3267 | // source or destination of the bit convert. |
| 3268 | EVT SrcVT = Op.getValueType(); |
| 3269 | EVT DstVT = N->getValueType(0); |
| 3270 | assert((SrcVT == MVT::i64 || DstVT == MVT::i64) && |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3271 | "ExpandBITCAST called for non-i64 type"); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 3272 | |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3273 | // Turn i64->f64 into VMOVDRR. |
| 3274 | if (SrcVT == MVT::i64 && TLI.isTypeLegal(DstVT)) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3275 | SDValue Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Op, |
| 3276 | DAG.getConstant(0, MVT::i32)); |
| 3277 | SDValue Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Op, |
| 3278 | DAG.getConstant(1, MVT::i32)); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3279 | return DAG.getNode(ISD::BITCAST, dl, DstVT, |
Bob Wilson | 1114f56 | 2010-06-11 22:45:25 +0000 | [diff] [blame] | 3280 | DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi)); |
Evan Cheng | c7c7729 | 2008-11-04 19:57:48 +0000 | [diff] [blame] | 3281 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3282 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 3283 | // Turn f64->i64 into VMOVRRD. |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3284 | if (DstVT == MVT::i64 && TLI.isTypeLegal(SrcVT)) { |
| 3285 | SDValue Cvt = DAG.getNode(ARMISD::VMOVRRD, dl, |
| 3286 | DAG.getVTList(MVT::i32, MVT::i32), &Op, 1); |
| 3287 | // Merge the pieces into a single i64 value. |
| 3288 | return DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Cvt, Cvt.getValue(1)); |
| 3289 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3290 | |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3291 | return SDValue(); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3292 | } |
| 3293 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3294 | /// getZeroVector - Returns a vector of specified type with all zero elements. |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3295 | /// Zero vectors are used to represent vector negation and in those cases |
| 3296 | /// will be implemented with the NEON VNEG instruction. However, VNEG does |
| 3297 | /// not support i64 elements, so sometimes the zero vectors will need to be |
| 3298 | /// explicitly constructed. Regardless, use a canonical VMOV to create the |
| 3299 | /// zero vector. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3300 | static SDValue getZeroVector(EVT VT, SelectionDAG &DAG, DebugLoc dl) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3301 | assert(VT.isVector() && "Expected a vector type"); |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3302 | // The canonical modified immediate encoding of a zero vector is....0! |
| 3303 | SDValue EncodedVal = DAG.getTargetConstant(0, MVT::i32); |
| 3304 | EVT VmovVT = VT.is128BitVector() ? MVT::v4i32 : MVT::v2i32; |
| 3305 | SDValue Vmov = DAG.getNode(ARMISD::VMOVIMM, dl, VmovVT, EncodedVal); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3306 | return DAG.getNode(ISD::BITCAST, dl, VT, Vmov); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3307 | } |
| 3308 | |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3309 | /// LowerShiftRightParts - Lower SRA_PARTS, which returns two |
| 3310 | /// 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] | 3311 | SDValue ARMTargetLowering::LowerShiftRightParts(SDValue Op, |
| 3312 | SelectionDAG &DAG) const { |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3313 | assert(Op.getNumOperands() == 3 && "Not a double-shift!"); |
| 3314 | EVT VT = Op.getValueType(); |
| 3315 | unsigned VTBits = VT.getSizeInBits(); |
| 3316 | DebugLoc dl = Op.getDebugLoc(); |
| 3317 | SDValue ShOpLo = Op.getOperand(0); |
| 3318 | SDValue ShOpHi = Op.getOperand(1); |
| 3319 | SDValue ShAmt = Op.getOperand(2); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3320 | SDValue ARMcc; |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 3321 | unsigned Opc = (Op.getOpcode() == ISD::SRA_PARTS) ? ISD::SRA : ISD::SRL; |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3322 | |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 3323 | assert(Op.getOpcode() == ISD::SRA_PARTS || Op.getOpcode() == ISD::SRL_PARTS); |
| 3324 | |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3325 | SDValue RevShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, |
| 3326 | DAG.getConstant(VTBits, MVT::i32), ShAmt); |
| 3327 | SDValue Tmp1 = DAG.getNode(ISD::SRL, dl, VT, ShOpLo, ShAmt); |
| 3328 | SDValue ExtraShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, ShAmt, |
| 3329 | DAG.getConstant(VTBits, MVT::i32)); |
| 3330 | SDValue Tmp2 = DAG.getNode(ISD::SHL, dl, VT, ShOpHi, RevShAmt); |
| 3331 | SDValue FalseVal = DAG.getNode(ISD::OR, dl, VT, Tmp1, Tmp2); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 3332 | SDValue TrueVal = DAG.getNode(Opc, dl, VT, ShOpHi, ExtraShAmt); |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3333 | |
| 3334 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| 3335 | SDValue Cmp = getARMCmp(ExtraShAmt, DAG.getConstant(0, MVT::i32), ISD::SETGE, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3336 | ARMcc, DAG, dl); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 3337 | SDValue Hi = DAG.getNode(Opc, dl, VT, ShOpHi, ShAmt); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3338 | SDValue Lo = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, ARMcc, |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3339 | CCR, Cmp); |
| 3340 | |
| 3341 | SDValue Ops[2] = { Lo, Hi }; |
| 3342 | return DAG.getMergeValues(Ops, 2, dl); |
| 3343 | } |
| 3344 | |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3345 | /// LowerShiftLeftParts - Lower SHL_PARTS, which returns two |
| 3346 | /// 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] | 3347 | SDValue ARMTargetLowering::LowerShiftLeftParts(SDValue Op, |
| 3348 | SelectionDAG &DAG) const { |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3349 | assert(Op.getNumOperands() == 3 && "Not a double-shift!"); |
| 3350 | EVT VT = Op.getValueType(); |
| 3351 | unsigned VTBits = VT.getSizeInBits(); |
| 3352 | DebugLoc dl = Op.getDebugLoc(); |
| 3353 | SDValue ShOpLo = Op.getOperand(0); |
| 3354 | SDValue ShOpHi = Op.getOperand(1); |
| 3355 | SDValue ShAmt = Op.getOperand(2); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3356 | SDValue ARMcc; |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3357 | |
| 3358 | assert(Op.getOpcode() == ISD::SHL_PARTS); |
| 3359 | SDValue RevShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, |
| 3360 | DAG.getConstant(VTBits, MVT::i32), ShAmt); |
| 3361 | SDValue Tmp1 = DAG.getNode(ISD::SRL, dl, VT, ShOpLo, RevShAmt); |
| 3362 | SDValue ExtraShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, ShAmt, |
| 3363 | DAG.getConstant(VTBits, MVT::i32)); |
| 3364 | SDValue Tmp2 = DAG.getNode(ISD::SHL, dl, VT, ShOpHi, ShAmt); |
| 3365 | SDValue Tmp3 = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ExtraShAmt); |
| 3366 | |
| 3367 | SDValue FalseVal = DAG.getNode(ISD::OR, dl, VT, Tmp1, Tmp2); |
| 3368 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| 3369 | SDValue Cmp = getARMCmp(ExtraShAmt, DAG.getConstant(0, MVT::i32), ISD::SETGE, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3370 | ARMcc, DAG, dl); |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3371 | SDValue Lo = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ShAmt); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3372 | SDValue Hi = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, Tmp3, ARMcc, |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3373 | CCR, Cmp); |
| 3374 | |
| 3375 | SDValue Ops[2] = { Lo, Hi }; |
| 3376 | return DAG.getMergeValues(Ops, 2, dl); |
| 3377 | } |
| 3378 | |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 3379 | SDValue ARMTargetLowering::LowerFLT_ROUNDS_(SDValue Op, |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 3380 | SelectionDAG &DAG) const { |
| 3381 | // The rounding mode is in bits 23:22 of the FPSCR. |
| 3382 | // The ARM rounding mode value to FLT_ROUNDS mapping is 0->1, 1->2, 2->3, 3->0 |
| 3383 | // The formula we use to implement this is (((FPSCR + 1 << 22) >> 22) & 3) |
| 3384 | // so that the shift + and get folded into a bitfield extract. |
| 3385 | DebugLoc dl = Op.getDebugLoc(); |
| 3386 | SDValue FPSCR = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::i32, |
| 3387 | DAG.getConstant(Intrinsic::arm_get_fpscr, |
| 3388 | MVT::i32)); |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 3389 | SDValue FltRounds = DAG.getNode(ISD::ADD, dl, MVT::i32, FPSCR, |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 3390 | DAG.getConstant(1U << 22, MVT::i32)); |
| 3391 | SDValue RMODE = DAG.getNode(ISD::SRL, dl, MVT::i32, FltRounds, |
| 3392 | DAG.getConstant(22, MVT::i32)); |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 3393 | return DAG.getNode(ISD::AND, dl, MVT::i32, RMODE, |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 3394 | DAG.getConstant(3, MVT::i32)); |
| 3395 | } |
| 3396 | |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 3397 | static SDValue LowerCTTZ(SDNode *N, SelectionDAG &DAG, |
| 3398 | const ARMSubtarget *ST) { |
| 3399 | EVT VT = N->getValueType(0); |
| 3400 | DebugLoc dl = N->getDebugLoc(); |
| 3401 | |
| 3402 | if (!ST->hasV6T2Ops()) |
| 3403 | return SDValue(); |
| 3404 | |
| 3405 | SDValue rbit = DAG.getNode(ARMISD::RBIT, dl, VT, N->getOperand(0)); |
| 3406 | return DAG.getNode(ISD::CTLZ, dl, VT, rbit); |
| 3407 | } |
| 3408 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3409 | static SDValue LowerShift(SDNode *N, SelectionDAG &DAG, |
| 3410 | const ARMSubtarget *ST) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3411 | EVT VT = N->getValueType(0); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3412 | DebugLoc dl = N->getDebugLoc(); |
| 3413 | |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3414 | if (!VT.isVector()) |
| 3415 | return SDValue(); |
| 3416 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3417 | // Lower vector shifts on NEON to use VSHL. |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3418 | assert(ST->hasNEON() && "unexpected vector shift"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3419 | |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3420 | // Left shifts translate directly to the vshiftu intrinsic. |
| 3421 | if (N->getOpcode() == ISD::SHL) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3422 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT, |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3423 | DAG.getConstant(Intrinsic::arm_neon_vshiftu, MVT::i32), |
| 3424 | N->getOperand(0), N->getOperand(1)); |
| 3425 | |
| 3426 | assert((N->getOpcode() == ISD::SRA || |
| 3427 | N->getOpcode() == ISD::SRL) && "unexpected vector shift opcode"); |
| 3428 | |
| 3429 | // NEON uses the same intrinsics for both left and right shifts. For |
| 3430 | // right shifts, the shift amounts are negative, so negate the vector of |
| 3431 | // shift amounts. |
| 3432 | EVT ShiftVT = N->getOperand(1).getValueType(); |
| 3433 | SDValue NegatedCount = DAG.getNode(ISD::SUB, dl, ShiftVT, |
| 3434 | getZeroVector(ShiftVT, DAG, dl), |
| 3435 | N->getOperand(1)); |
| 3436 | Intrinsic::ID vshiftInt = (N->getOpcode() == ISD::SRA ? |
| 3437 | Intrinsic::arm_neon_vshifts : |
| 3438 | Intrinsic::arm_neon_vshiftu); |
| 3439 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT, |
| 3440 | DAG.getConstant(vshiftInt, MVT::i32), |
| 3441 | N->getOperand(0), NegatedCount); |
| 3442 | } |
| 3443 | |
| 3444 | static SDValue Expand64BitShift(SDNode *N, SelectionDAG &DAG, |
| 3445 | const ARMSubtarget *ST) { |
| 3446 | EVT VT = N->getValueType(0); |
| 3447 | DebugLoc dl = N->getDebugLoc(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3448 | |
Eli Friedman | ce392eb | 2009-08-22 03:13:10 +0000 | [diff] [blame] | 3449 | // We can get here for a node like i32 = ISD::SHL i32, i64 |
| 3450 | if (VT != MVT::i64) |
| 3451 | return SDValue(); |
| 3452 | |
| 3453 | assert((N->getOpcode() == ISD::SRL || N->getOpcode() == ISD::SRA) && |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3454 | "Unknown shift to lower!"); |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 3455 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3456 | // We only lower SRA, SRL of 1 here, all others use generic lowering. |
| 3457 | if (!isa<ConstantSDNode>(N->getOperand(1)) || |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 3458 | cast<ConstantSDNode>(N->getOperand(1))->getZExtValue() != 1) |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 3459 | return SDValue(); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3460 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3461 | // If we are in thumb mode, we don't have RRX. |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 3462 | if (ST->isThumb1Only()) return SDValue(); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3463 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3464 | // 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] | 3465 | 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] | 3466 | DAG.getConstant(0, MVT::i32)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3467 | 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] | 3468 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3469 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3470 | // First, build a SRA_FLAG/SRL_FLAG op, which shifts the top part by one and |
| 3471 | // captures the result into a carry flag. |
| 3472 | unsigned Opc = N->getOpcode() == ISD::SRL ? ARMISD::SRL_FLAG:ARMISD::SRA_FLAG; |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 3473 | 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] | 3474 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3475 | // 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] | 3476 | Lo = DAG.getNode(ARMISD::RRX, dl, MVT::i32, Lo, Hi.getValue(1)); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3477 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3478 | // Merge the pieces into a single i64 value. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3479 | return DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Lo, Hi); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3480 | } |
| 3481 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3482 | static SDValue LowerVSETCC(SDValue Op, SelectionDAG &DAG) { |
| 3483 | SDValue TmpOp0, TmpOp1; |
| 3484 | bool Invert = false; |
| 3485 | bool Swap = false; |
| 3486 | unsigned Opc = 0; |
| 3487 | |
| 3488 | SDValue Op0 = Op.getOperand(0); |
| 3489 | SDValue Op1 = Op.getOperand(1); |
| 3490 | SDValue CC = Op.getOperand(2); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3491 | EVT VT = Op.getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3492 | ISD::CondCode SetCCOpcode = cast<CondCodeSDNode>(CC)->get(); |
| 3493 | DebugLoc dl = Op.getDebugLoc(); |
| 3494 | |
| 3495 | if (Op.getOperand(1).getValueType().isFloatingPoint()) { |
| 3496 | switch (SetCCOpcode) { |
David Blaikie | 4d6ccb5 | 2012-01-20 21:51:11 +0000 | [diff] [blame^] | 3497 | default: llvm_unreachable("Illegal FP comparison"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3498 | case ISD::SETUNE: |
| 3499 | case ISD::SETNE: Invert = true; // Fallthrough |
| 3500 | case ISD::SETOEQ: |
| 3501 | case ISD::SETEQ: Opc = ARMISD::VCEQ; break; |
| 3502 | case ISD::SETOLT: |
| 3503 | case ISD::SETLT: Swap = true; // Fallthrough |
| 3504 | case ISD::SETOGT: |
| 3505 | case ISD::SETGT: Opc = ARMISD::VCGT; break; |
| 3506 | case ISD::SETOLE: |
| 3507 | case ISD::SETLE: Swap = true; // Fallthrough |
| 3508 | case ISD::SETOGE: |
| 3509 | case ISD::SETGE: Opc = ARMISD::VCGE; break; |
| 3510 | case ISD::SETUGE: Swap = true; // Fallthrough |
| 3511 | case ISD::SETULE: Invert = true; Opc = ARMISD::VCGT; break; |
| 3512 | case ISD::SETUGT: Swap = true; // Fallthrough |
| 3513 | case ISD::SETULT: Invert = true; Opc = ARMISD::VCGE; break; |
| 3514 | case ISD::SETUEQ: Invert = true; // Fallthrough |
| 3515 | case ISD::SETONE: |
| 3516 | // Expand this to (OLT | OGT). |
| 3517 | TmpOp0 = Op0; |
| 3518 | TmpOp1 = Op1; |
| 3519 | Opc = ISD::OR; |
| 3520 | Op0 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp1, TmpOp0); |
| 3521 | Op1 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp0, TmpOp1); |
| 3522 | break; |
| 3523 | case ISD::SETUO: Invert = true; // Fallthrough |
| 3524 | case ISD::SETO: |
| 3525 | // Expand this to (OLT | OGE). |
| 3526 | TmpOp0 = Op0; |
| 3527 | TmpOp1 = Op1; |
| 3528 | Opc = ISD::OR; |
| 3529 | Op0 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp1, TmpOp0); |
| 3530 | Op1 = DAG.getNode(ARMISD::VCGE, dl, VT, TmpOp0, TmpOp1); |
| 3531 | break; |
| 3532 | } |
| 3533 | } else { |
| 3534 | // Integer comparisons. |
| 3535 | switch (SetCCOpcode) { |
David Blaikie | 4d6ccb5 | 2012-01-20 21:51:11 +0000 | [diff] [blame^] | 3536 | default: llvm_unreachable("Illegal integer comparison"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3537 | case ISD::SETNE: Invert = true; |
| 3538 | case ISD::SETEQ: Opc = ARMISD::VCEQ; break; |
| 3539 | case ISD::SETLT: Swap = true; |
| 3540 | case ISD::SETGT: Opc = ARMISD::VCGT; break; |
| 3541 | case ISD::SETLE: Swap = true; |
| 3542 | case ISD::SETGE: Opc = ARMISD::VCGE; break; |
| 3543 | case ISD::SETULT: Swap = true; |
| 3544 | case ISD::SETUGT: Opc = ARMISD::VCGTU; break; |
| 3545 | case ISD::SETULE: Swap = true; |
| 3546 | case ISD::SETUGE: Opc = ARMISD::VCGEU; break; |
| 3547 | } |
| 3548 | |
Nick Lewycky | 7f6aa2b | 2009-07-08 03:04:38 +0000 | [diff] [blame] | 3549 | // Detect VTST (Vector Test Bits) = icmp ne (and (op0, op1), zero). |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3550 | if (Opc == ARMISD::VCEQ) { |
| 3551 | |
| 3552 | SDValue AndOp; |
| 3553 | if (ISD::isBuildVectorAllZeros(Op1.getNode())) |
| 3554 | AndOp = Op0; |
| 3555 | else if (ISD::isBuildVectorAllZeros(Op0.getNode())) |
| 3556 | AndOp = Op1; |
| 3557 | |
| 3558 | // Ignore bitconvert. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3559 | if (AndOp.getNode() && AndOp.getOpcode() == ISD::BITCAST) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3560 | AndOp = AndOp.getOperand(0); |
| 3561 | |
| 3562 | if (AndOp.getNode() && AndOp.getOpcode() == ISD::AND) { |
| 3563 | Opc = ARMISD::VTST; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3564 | Op0 = DAG.getNode(ISD::BITCAST, dl, VT, AndOp.getOperand(0)); |
| 3565 | Op1 = DAG.getNode(ISD::BITCAST, dl, VT, AndOp.getOperand(1)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3566 | Invert = !Invert; |
| 3567 | } |
| 3568 | } |
| 3569 | } |
| 3570 | |
| 3571 | if (Swap) |
| 3572 | std::swap(Op0, Op1); |
| 3573 | |
Owen Anderson | c24cb35 | 2010-11-08 23:21:22 +0000 | [diff] [blame] | 3574 | // If one of the operands is a constant vector zero, attempt to fold the |
| 3575 | // comparison to a specialized compare-against-zero form. |
| 3576 | SDValue SingleOp; |
| 3577 | if (ISD::isBuildVectorAllZeros(Op1.getNode())) |
| 3578 | SingleOp = Op0; |
| 3579 | else if (ISD::isBuildVectorAllZeros(Op0.getNode())) { |
| 3580 | if (Opc == ARMISD::VCGE) |
| 3581 | Opc = ARMISD::VCLEZ; |
| 3582 | else if (Opc == ARMISD::VCGT) |
| 3583 | Opc = ARMISD::VCLTZ; |
| 3584 | SingleOp = Op1; |
| 3585 | } |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3586 | |
Owen Anderson | c24cb35 | 2010-11-08 23:21:22 +0000 | [diff] [blame] | 3587 | SDValue Result; |
| 3588 | if (SingleOp.getNode()) { |
| 3589 | switch (Opc) { |
| 3590 | case ARMISD::VCEQ: |
| 3591 | Result = DAG.getNode(ARMISD::VCEQZ, dl, VT, SingleOp); break; |
| 3592 | case ARMISD::VCGE: |
| 3593 | Result = DAG.getNode(ARMISD::VCGEZ, dl, VT, SingleOp); break; |
| 3594 | case ARMISD::VCLEZ: |
| 3595 | Result = DAG.getNode(ARMISD::VCLEZ, dl, VT, SingleOp); break; |
| 3596 | case ARMISD::VCGT: |
| 3597 | Result = DAG.getNode(ARMISD::VCGTZ, dl, VT, SingleOp); break; |
| 3598 | case ARMISD::VCLTZ: |
| 3599 | Result = DAG.getNode(ARMISD::VCLTZ, dl, VT, SingleOp); break; |
| 3600 | default: |
| 3601 | Result = DAG.getNode(Opc, dl, VT, Op0, Op1); |
| 3602 | } |
| 3603 | } else { |
| 3604 | Result = DAG.getNode(Opc, dl, VT, Op0, Op1); |
| 3605 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3606 | |
| 3607 | if (Invert) |
| 3608 | Result = DAG.getNOT(dl, Result, VT); |
| 3609 | |
| 3610 | return Result; |
| 3611 | } |
| 3612 | |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 3613 | /// isNEONModifiedImm - Check if the specified splat value corresponds to a |
| 3614 | /// valid vector constant for a NEON instruction with a "modified immediate" |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3615 | /// operand (e.g., VMOV). If so, return the encoded value. |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 3616 | static SDValue isNEONModifiedImm(uint64_t SplatBits, uint64_t SplatUndef, |
| 3617 | unsigned SplatBitSize, SelectionDAG &DAG, |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3618 | EVT &VT, bool is128Bits, NEONModImmType type) { |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3619 | unsigned OpCmode, Imm; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3620 | |
Bob Wilson | 827b210 | 2010-06-15 19:05:35 +0000 | [diff] [blame] | 3621 | // SplatBitSize is set to the smallest size that splats the vector, so a |
| 3622 | // zero vector will always have SplatBitSize == 8. However, NEON modified |
| 3623 | // immediate instructions others than VMOV do not support the 8-bit encoding |
| 3624 | // of a zero vector, and the default encoding of zero is supposed to be the |
| 3625 | // 32-bit version. |
| 3626 | if (SplatBits == 0) |
| 3627 | SplatBitSize = 32; |
| 3628 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3629 | switch (SplatBitSize) { |
| 3630 | case 8: |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3631 | if (type != VMOVModImm) |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 3632 | return SDValue(); |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3633 | // Any 1-byte value is OK. Op=0, Cmode=1110. |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3634 | assert((SplatBits & ~0xff) == 0 && "one byte splat value is too big"); |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3635 | OpCmode = 0xe; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3636 | Imm = SplatBits; |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3637 | VT = is128Bits ? MVT::v16i8 : MVT::v8i8; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3638 | break; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3639 | |
| 3640 | case 16: |
| 3641 | // 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] | 3642 | VT = is128Bits ? MVT::v8i16 : MVT::v4i16; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3643 | if ((SplatBits & ~0xff) == 0) { |
| 3644 | // Value = 0x00nn: Op=x, Cmode=100x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3645 | OpCmode = 0x8; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3646 | Imm = SplatBits; |
| 3647 | break; |
| 3648 | } |
| 3649 | if ((SplatBits & ~0xff00) == 0) { |
| 3650 | // Value = 0xnn00: Op=x, Cmode=101x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3651 | OpCmode = 0xa; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3652 | Imm = SplatBits >> 8; |
| 3653 | break; |
| 3654 | } |
| 3655 | return SDValue(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3656 | |
| 3657 | case 32: |
| 3658 | // NEON's 32-bit VMOV supports splat values where: |
| 3659 | // * only one byte is nonzero, or |
| 3660 | // * the least significant byte is 0xff and the second byte is nonzero, or |
| 3661 | // * the least significant 2 bytes are 0xff and the third is nonzero. |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3662 | VT = is128Bits ? MVT::v4i32 : MVT::v2i32; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3663 | if ((SplatBits & ~0xff) == 0) { |
| 3664 | // Value = 0x000000nn: Op=x, Cmode=000x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3665 | OpCmode = 0; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3666 | Imm = SplatBits; |
| 3667 | break; |
| 3668 | } |
| 3669 | if ((SplatBits & ~0xff00) == 0) { |
| 3670 | // Value = 0x0000nn00: Op=x, Cmode=001x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3671 | OpCmode = 0x2; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3672 | Imm = SplatBits >> 8; |
| 3673 | break; |
| 3674 | } |
| 3675 | if ((SplatBits & ~0xff0000) == 0) { |
| 3676 | // Value = 0x00nn0000: Op=x, Cmode=010x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3677 | OpCmode = 0x4; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3678 | Imm = SplatBits >> 16; |
| 3679 | break; |
| 3680 | } |
| 3681 | if ((SplatBits & ~0xff000000) == 0) { |
| 3682 | // Value = 0xnn000000: Op=x, Cmode=011x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3683 | OpCmode = 0x6; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3684 | Imm = SplatBits >> 24; |
| 3685 | break; |
| 3686 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3687 | |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3688 | // cmode == 0b1100 and cmode == 0b1101 are not supported for VORR or VBIC |
| 3689 | if (type == OtherModImm) return SDValue(); |
| 3690 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3691 | if ((SplatBits & ~0xffff) == 0 && |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3692 | ((SplatBits | SplatUndef) & 0xff) == 0xff) { |
| 3693 | // Value = 0x0000nnff: Op=x, Cmode=1100. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3694 | OpCmode = 0xc; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3695 | Imm = SplatBits >> 8; |
| 3696 | SplatBits |= 0xff; |
| 3697 | break; |
| 3698 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3699 | |
| 3700 | if ((SplatBits & ~0xffffff) == 0 && |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3701 | ((SplatBits | SplatUndef) & 0xffff) == 0xffff) { |
| 3702 | // Value = 0x00nnffff: Op=x, Cmode=1101. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3703 | OpCmode = 0xd; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3704 | Imm = SplatBits >> 16; |
| 3705 | SplatBits |= 0xffff; |
| 3706 | break; |
| 3707 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3708 | |
| 3709 | // Note: there are a few 32-bit splat values (specifically: 00ffff00, |
| 3710 | // ff000000, ff0000ff, and ffff00ff) that are valid for VMOV.I64 but not |
| 3711 | // VMOV.I32. A (very) minor optimization would be to replicate the value |
| 3712 | // and fall through here to test for a valid 64-bit splat. But, then the |
| 3713 | // caller would also need to check and handle the change in size. |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3714 | return SDValue(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3715 | |
| 3716 | case 64: { |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3717 | if (type != VMOVModImm) |
Bob Wilson | 827b210 | 2010-06-15 19:05:35 +0000 | [diff] [blame] | 3718 | return SDValue(); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 3719 | // 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] | 3720 | uint64_t BitMask = 0xff; |
| 3721 | uint64_t Val = 0; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3722 | unsigned ImmMask = 1; |
| 3723 | Imm = 0; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3724 | for (int ByteNum = 0; ByteNum < 8; ++ByteNum) { |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3725 | if (((SplatBits | SplatUndef) & BitMask) == BitMask) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3726 | Val |= BitMask; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3727 | Imm |= ImmMask; |
| 3728 | } else if ((SplatBits & BitMask) != 0) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3729 | return SDValue(); |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3730 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3731 | BitMask <<= 8; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3732 | ImmMask <<= 1; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3733 | } |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3734 | // Op=1, Cmode=1110. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3735 | OpCmode = 0x1e; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3736 | SplatBits = Val; |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3737 | VT = is128Bits ? MVT::v2i64 : MVT::v1i64; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3738 | break; |
| 3739 | } |
| 3740 | |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3741 | default: |
Bob Wilson | dc076da | 2010-06-19 05:32:09 +0000 | [diff] [blame] | 3742 | llvm_unreachable("unexpected size for isNEONModifiedImm"); |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3743 | } |
| 3744 | |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3745 | unsigned EncodedVal = ARM_AM::createNEONModImm(OpCmode, Imm); |
| 3746 | return DAG.getTargetConstant(EncodedVal, MVT::i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3747 | } |
| 3748 | |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 3749 | static bool isVEXTMask(ArrayRef<int> M, EVT VT, |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3750 | bool &ReverseVEXT, unsigned &Imm) { |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3751 | unsigned NumElts = VT.getVectorNumElements(); |
| 3752 | ReverseVEXT = false; |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3753 | |
| 3754 | // Assume that the first shuffle index is not UNDEF. Fail if it is. |
| 3755 | if (M[0] < 0) |
| 3756 | return false; |
| 3757 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3758 | Imm = M[0]; |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3759 | |
| 3760 | // If this is a VEXT shuffle, the immediate value is the index of the first |
| 3761 | // element. The other shuffle indices must be the successive elements after |
| 3762 | // the first one. |
| 3763 | unsigned ExpectedElt = Imm; |
| 3764 | for (unsigned i = 1; i < NumElts; ++i) { |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3765 | // Increment the expected index. If it wraps around, it may still be |
| 3766 | // a VEXT but the source vectors must be swapped. |
| 3767 | ExpectedElt += 1; |
| 3768 | if (ExpectedElt == NumElts * 2) { |
| 3769 | ExpectedElt = 0; |
| 3770 | ReverseVEXT = true; |
| 3771 | } |
| 3772 | |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3773 | if (M[i] < 0) continue; // ignore UNDEF indices |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3774 | if (ExpectedElt != static_cast<unsigned>(M[i])) |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3775 | return false; |
| 3776 | } |
| 3777 | |
| 3778 | // Adjust the index value if the source operands will be swapped. |
| 3779 | if (ReverseVEXT) |
| 3780 | Imm -= NumElts; |
| 3781 | |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3782 | return true; |
| 3783 | } |
| 3784 | |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 3785 | /// isVREVMask - Check if a vector shuffle corresponds to a VREV |
| 3786 | /// instruction with the specified blocksize. (The order of the elements |
| 3787 | /// within each block of the vector is reversed.) |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 3788 | static bool isVREVMask(ArrayRef<int> M, EVT VT, unsigned BlockSize) { |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 3789 | assert((BlockSize==16 || BlockSize==32 || BlockSize==64) && |
| 3790 | "Only possible block sizes for VREV are: 16, 32, 64"); |
| 3791 | |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 3792 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 3793 | if (EltSz == 64) |
| 3794 | return false; |
| 3795 | |
| 3796 | unsigned NumElts = VT.getVectorNumElements(); |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3797 | unsigned BlockElts = M[0] + 1; |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3798 | // If the first shuffle index is UNDEF, be optimistic. |
| 3799 | if (M[0] < 0) |
| 3800 | BlockElts = BlockSize / EltSz; |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 3801 | |
| 3802 | if (BlockSize <= EltSz || BlockSize != BlockElts * EltSz) |
| 3803 | return false; |
| 3804 | |
| 3805 | for (unsigned i = 0; i < NumElts; ++i) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3806 | if (M[i] < 0) continue; // ignore UNDEF indices |
| 3807 | if ((unsigned) M[i] != (i - i%BlockElts) + (BlockElts - 1 - i%BlockElts)) |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 3808 | return false; |
| 3809 | } |
| 3810 | |
| 3811 | return true; |
| 3812 | } |
| 3813 | |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 3814 | static bool isVTBLMask(ArrayRef<int> M, EVT VT) { |
Bill Wendling | 0d4c9d9 | 2011-03-15 21:15:20 +0000 | [diff] [blame] | 3815 | // We can handle <8 x i8> vector shuffles. If the index in the mask is out of |
| 3816 | // range, then 0 is placed into the resulting vector. So pretty much any mask |
| 3817 | // of 8 elements can work here. |
| 3818 | return VT == MVT::v8i8 && M.size() == 8; |
| 3819 | } |
| 3820 | |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 3821 | static bool isVTRNMask(ArrayRef<int> M, EVT VT, unsigned &WhichResult) { |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 3822 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3823 | if (EltSz == 64) |
| 3824 | return false; |
| 3825 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3826 | unsigned NumElts = VT.getVectorNumElements(); |
| 3827 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3828 | for (unsigned i = 0; i < NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3829 | if ((M[i] >= 0 && (unsigned) M[i] != i + WhichResult) || |
| 3830 | (M[i+1] >= 0 && (unsigned) M[i+1] != i + NumElts + WhichResult)) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3831 | return false; |
| 3832 | } |
| 3833 | return true; |
| 3834 | } |
| 3835 | |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3836 | /// isVTRN_v_undef_Mask - Special case of isVTRNMask for canonical form of |
| 3837 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 3838 | /// 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] | 3839 | 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] | 3840 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3841 | if (EltSz == 64) |
| 3842 | return false; |
| 3843 | |
| 3844 | unsigned NumElts = VT.getVectorNumElements(); |
| 3845 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3846 | for (unsigned i = 0; i < NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3847 | if ((M[i] >= 0 && (unsigned) M[i] != i + WhichResult) || |
| 3848 | (M[i+1] >= 0 && (unsigned) M[i+1] != i + WhichResult)) |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3849 | return false; |
| 3850 | } |
| 3851 | return true; |
| 3852 | } |
| 3853 | |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 3854 | static bool isVUZPMask(ArrayRef<int> M, EVT VT, unsigned &WhichResult) { |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 3855 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3856 | if (EltSz == 64) |
| 3857 | return false; |
| 3858 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3859 | unsigned NumElts = VT.getVectorNumElements(); |
| 3860 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3861 | for (unsigned i = 0; i != NumElts; ++i) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3862 | if (M[i] < 0) continue; // ignore UNDEF indices |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3863 | if ((unsigned) M[i] != 2 * i + WhichResult) |
| 3864 | return false; |
| 3865 | } |
| 3866 | |
| 3867 | // 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] | 3868 | if (VT.is64BitVector() && EltSz == 32) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3869 | return false; |
| 3870 | |
| 3871 | return true; |
| 3872 | } |
| 3873 | |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3874 | /// isVUZP_v_undef_Mask - Special case of isVUZPMask for canonical form of |
| 3875 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 3876 | /// 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] | 3877 | 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] | 3878 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3879 | if (EltSz == 64) |
| 3880 | return false; |
| 3881 | |
| 3882 | unsigned Half = VT.getVectorNumElements() / 2; |
| 3883 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3884 | for (unsigned j = 0; j != 2; ++j) { |
| 3885 | unsigned Idx = WhichResult; |
| 3886 | for (unsigned i = 0; i != Half; ++i) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3887 | int MIdx = M[i + j * Half]; |
| 3888 | if (MIdx >= 0 && (unsigned) MIdx != Idx) |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3889 | return false; |
| 3890 | Idx += 2; |
| 3891 | } |
| 3892 | } |
| 3893 | |
| 3894 | // VUZP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32. |
| 3895 | if (VT.is64BitVector() && EltSz == 32) |
| 3896 | return false; |
| 3897 | |
| 3898 | return true; |
| 3899 | } |
| 3900 | |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 3901 | static bool isVZIPMask(ArrayRef<int> M, EVT VT, unsigned &WhichResult) { |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 3902 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3903 | if (EltSz == 64) |
| 3904 | return false; |
| 3905 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3906 | unsigned NumElts = VT.getVectorNumElements(); |
| 3907 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3908 | unsigned Idx = WhichResult * NumElts / 2; |
| 3909 | for (unsigned i = 0; i != NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3910 | if ((M[i] >= 0 && (unsigned) M[i] != Idx) || |
| 3911 | (M[i+1] >= 0 && (unsigned) M[i+1] != Idx + NumElts)) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3912 | return false; |
| 3913 | Idx += 1; |
| 3914 | } |
| 3915 | |
| 3916 | // 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] | 3917 | if (VT.is64BitVector() && EltSz == 32) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3918 | return false; |
| 3919 | |
| 3920 | return true; |
| 3921 | } |
| 3922 | |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3923 | /// isVZIP_v_undef_Mask - Special case of isVZIPMask for canonical form of |
| 3924 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 3925 | /// 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] | 3926 | 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] | 3927 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3928 | if (EltSz == 64) |
| 3929 | return false; |
| 3930 | |
| 3931 | unsigned NumElts = VT.getVectorNumElements(); |
| 3932 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3933 | unsigned Idx = WhichResult * NumElts / 2; |
| 3934 | for (unsigned i = 0; i != NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3935 | if ((M[i] >= 0 && (unsigned) M[i] != Idx) || |
| 3936 | (M[i+1] >= 0 && (unsigned) M[i+1] != Idx)) |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3937 | return false; |
| 3938 | Idx += 1; |
| 3939 | } |
| 3940 | |
| 3941 | // VZIP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32. |
| 3942 | if (VT.is64BitVector() && EltSz == 32) |
| 3943 | return false; |
| 3944 | |
| 3945 | return true; |
| 3946 | } |
| 3947 | |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 3948 | // If N is an integer constant that can be moved into a register in one |
| 3949 | // instruction, return an SDValue of such a constant (will become a MOV |
| 3950 | // instruction). Otherwise return null. |
| 3951 | static SDValue IsSingleInstrConstant(SDValue N, SelectionDAG &DAG, |
| 3952 | const ARMSubtarget *ST, DebugLoc dl) { |
| 3953 | uint64_t Val; |
| 3954 | if (!isa<ConstantSDNode>(N)) |
| 3955 | return SDValue(); |
| 3956 | Val = cast<ConstantSDNode>(N)->getZExtValue(); |
| 3957 | |
| 3958 | if (ST->isThumb1Only()) { |
| 3959 | if (Val <= 255 || ~Val <= 255) |
| 3960 | return DAG.getConstant(Val, MVT::i32); |
| 3961 | } else { |
| 3962 | if (ARM_AM::getSOImmVal(Val) != -1 || ARM_AM::getSOImmVal(~Val) != -1) |
| 3963 | return DAG.getConstant(Val, MVT::i32); |
| 3964 | } |
| 3965 | return SDValue(); |
| 3966 | } |
| 3967 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3968 | // If this is a case we can't handle, return null and let the default |
| 3969 | // expansion code take care of it. |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3970 | SDValue ARMTargetLowering::LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG, |
| 3971 | const ARMSubtarget *ST) const { |
Bob Wilson | d06791f | 2009-08-13 01:57:47 +0000 | [diff] [blame] | 3972 | BuildVectorSDNode *BVN = cast<BuildVectorSDNode>(Op.getNode()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3973 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3974 | EVT VT = Op.getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3975 | |
| 3976 | APInt SplatBits, SplatUndef; |
| 3977 | unsigned SplatBitSize; |
| 3978 | bool HasAnyUndefs; |
| 3979 | if (BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { |
Anton Korobeynikov | 71624cc | 2009-08-29 00:08:18 +0000 | [diff] [blame] | 3980 | if (SplatBitSize <= 64) { |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 3981 | // Check if an immediate VMOV works. |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3982 | EVT VmovVT; |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 3983 | SDValue Val = isNEONModifiedImm(SplatBits.getZExtValue(), |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3984 | SplatUndef.getZExtValue(), SplatBitSize, |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3985 | DAG, VmovVT, VT.is128BitVector(), |
| 3986 | VMOVModImm); |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3987 | if (Val.getNode()) { |
| 3988 | SDValue Vmov = DAG.getNode(ARMISD::VMOVIMM, dl, VmovVT, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3989 | return DAG.getNode(ISD::BITCAST, dl, VT, Vmov); |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3990 | } |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 3991 | |
| 3992 | // Try an immediate VMVN. |
Eli Friedman | 8e4d042 | 2011-10-13 22:40:23 +0000 | [diff] [blame] | 3993 | uint64_t NegatedImm = (~SplatBits).getZExtValue(); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 3994 | Val = isNEONModifiedImm(NegatedImm, |
| 3995 | SplatUndef.getZExtValue(), SplatBitSize, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3996 | DAG, VmovVT, VT.is128BitVector(), |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3997 | VMVNModImm); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 3998 | if (Val.getNode()) { |
| 3999 | SDValue Vmov = DAG.getNode(ARMISD::VMVNIMM, dl, VmovVT, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4000 | return DAG.getNode(ISD::BITCAST, dl, VT, Vmov); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 4001 | } |
Evan Cheng | eaa192a | 2011-11-15 02:12:34 +0000 | [diff] [blame] | 4002 | |
| 4003 | // Use vmov.f32 to materialize other v2f32 and v4f32 splats. |
Eli Friedman | 2f21e8c | 2011-12-15 22:56:53 +0000 | [diff] [blame] | 4004 | if ((VT == MVT::v2f32 || VT == MVT::v4f32) && SplatBitSize == 32) { |
Eli Friedman | effab8f | 2011-12-09 23:54:42 +0000 | [diff] [blame] | 4005 | int ImmVal = ARM_AM::getFP32Imm(SplatBits); |
Evan Cheng | eaa192a | 2011-11-15 02:12:34 +0000 | [diff] [blame] | 4006 | if (ImmVal != -1) { |
| 4007 | SDValue Val = DAG.getTargetConstant(ImmVal, MVT::i32); |
| 4008 | return DAG.getNode(ARMISD::VMOVFPIMM, dl, VT, Val); |
| 4009 | } |
| 4010 | } |
Anton Korobeynikov | 71624cc | 2009-08-29 00:08:18 +0000 | [diff] [blame] | 4011 | } |
Bob Wilson | cf661e2 | 2009-07-30 00:31:25 +0000 | [diff] [blame] | 4012 | } |
| 4013 | |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4014 | // Scan through the operands to see if only one value is used. |
| 4015 | unsigned NumElts = VT.getVectorNumElements(); |
| 4016 | bool isOnlyLowElement = true; |
| 4017 | bool usesOnlyOneValue = true; |
| 4018 | bool isConstant = true; |
| 4019 | SDValue Value; |
| 4020 | for (unsigned i = 0; i < NumElts; ++i) { |
| 4021 | SDValue V = Op.getOperand(i); |
| 4022 | if (V.getOpcode() == ISD::UNDEF) |
| 4023 | continue; |
| 4024 | if (i > 0) |
| 4025 | isOnlyLowElement = false; |
| 4026 | if (!isa<ConstantFPSDNode>(V) && !isa<ConstantSDNode>(V)) |
| 4027 | isConstant = false; |
| 4028 | |
| 4029 | if (!Value.getNode()) |
| 4030 | Value = V; |
| 4031 | else if (V != Value) |
| 4032 | usesOnlyOneValue = false; |
| 4033 | } |
| 4034 | |
| 4035 | if (!Value.getNode()) |
| 4036 | return DAG.getUNDEF(VT); |
| 4037 | |
| 4038 | if (isOnlyLowElement) |
| 4039 | return DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, VT, Value); |
| 4040 | |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 4041 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 4042 | |
Dale Johannesen | 575cd14 | 2010-10-19 20:00:17 +0000 | [diff] [blame] | 4043 | // Use VDUP for non-constant splats. For f32 constant splats, reduce to |
| 4044 | // i32 and try again. |
| 4045 | if (usesOnlyOneValue && EltSize <= 32) { |
| 4046 | if (!isConstant) |
| 4047 | return DAG.getNode(ARMISD::VDUP, dl, VT, Value); |
| 4048 | if (VT.getVectorElementType().isFloatingPoint()) { |
| 4049 | SmallVector<SDValue, 8> Ops; |
| 4050 | for (unsigned i = 0; i < NumElts; ++i) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4051 | Ops.push_back(DAG.getNode(ISD::BITCAST, dl, MVT::i32, |
Dale Johannesen | 575cd14 | 2010-10-19 20:00:17 +0000 | [diff] [blame] | 4052 | Op.getOperand(i))); |
Nate Begeman | bf5be26 | 2010-11-10 21:35:41 +0000 | [diff] [blame] | 4053 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), MVT::i32, NumElts); |
| 4054 | SDValue Val = DAG.getNode(ISD::BUILD_VECTOR, dl, VecVT, &Ops[0], NumElts); |
Dale Johannesen | e4d3159 | 2010-10-20 22:03:37 +0000 | [diff] [blame] | 4055 | Val = LowerBUILD_VECTOR(Val, DAG, ST); |
| 4056 | if (Val.getNode()) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4057 | return DAG.getNode(ISD::BITCAST, dl, VT, Val); |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 4058 | } |
Dale Johannesen | 575cd14 | 2010-10-19 20:00:17 +0000 | [diff] [blame] | 4059 | SDValue Val = IsSingleInstrConstant(Value, DAG, ST, dl); |
| 4060 | if (Val.getNode()) |
| 4061 | return DAG.getNode(ARMISD::VDUP, dl, VT, Val); |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 4062 | } |
| 4063 | |
| 4064 | // If all elements are constants and the case above didn't get hit, fall back |
| 4065 | // to the default expansion, which will generate a load from the constant |
| 4066 | // pool. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4067 | if (isConstant) |
| 4068 | return SDValue(); |
| 4069 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4070 | // Empirical tests suggest this is rarely worth it for vectors of length <= 2. |
| 4071 | if (NumElts >= 4) { |
| 4072 | SDValue shuffle = ReconstructShuffle(Op, DAG); |
| 4073 | if (shuffle != SDValue()) |
| 4074 | return shuffle; |
| 4075 | } |
| 4076 | |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4077 | // 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] | 4078 | // the subregisters. Lower it to an ARMISD::BUILD_VECTOR so the operands |
| 4079 | // will be legalized. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4080 | if (EltSize >= 32) { |
| 4081 | // Do the expansion with floating-point types, since that is what the VFP |
| 4082 | // registers are defined to use, and since i64 is not legal. |
| 4083 | EVT EltVT = EVT::getFloatingPointVT(EltSize); |
| 4084 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), EltVT, NumElts); |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4085 | SmallVector<SDValue, 8> Ops; |
| 4086 | for (unsigned i = 0; i < NumElts; ++i) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4087 | Ops.push_back(DAG.getNode(ISD::BITCAST, dl, EltVT, Op.getOperand(i))); |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4088 | SDValue Val = DAG.getNode(ARMISD::BUILD_VECTOR, dl, VecVT, &Ops[0],NumElts); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4089 | return DAG.getNode(ISD::BITCAST, dl, VT, Val); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4090 | } |
| 4091 | |
| 4092 | return SDValue(); |
| 4093 | } |
| 4094 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4095 | // Gather data to see if the operation can be modelled as a |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4096 | // shuffle in combination with VEXTs. |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4097 | SDValue ARMTargetLowering::ReconstructShuffle(SDValue Op, |
| 4098 | SelectionDAG &DAG) const { |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4099 | DebugLoc dl = Op.getDebugLoc(); |
| 4100 | EVT VT = Op.getValueType(); |
| 4101 | unsigned NumElts = VT.getVectorNumElements(); |
| 4102 | |
| 4103 | SmallVector<SDValue, 2> SourceVecs; |
| 4104 | SmallVector<unsigned, 2> MinElts; |
| 4105 | SmallVector<unsigned, 2> MaxElts; |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4106 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4107 | for (unsigned i = 0; i < NumElts; ++i) { |
| 4108 | SDValue V = Op.getOperand(i); |
| 4109 | if (V.getOpcode() == ISD::UNDEF) |
| 4110 | continue; |
| 4111 | else if (V.getOpcode() != ISD::EXTRACT_VECTOR_ELT) { |
| 4112 | // A shuffle can only come from building a vector from various |
| 4113 | // elements of other vectors. |
| 4114 | return SDValue(); |
Eli Friedman | 46995fa | 2011-10-14 23:58:49 +0000 | [diff] [blame] | 4115 | } else if (V.getOperand(0).getValueType().getVectorElementType() != |
| 4116 | VT.getVectorElementType()) { |
| 4117 | // This code doesn't know how to handle shuffles where the vector |
| 4118 | // element types do not match (this happens because type legalization |
| 4119 | // promotes the return type of EXTRACT_VECTOR_ELT). |
| 4120 | // FIXME: It might be appropriate to extend this code to handle |
| 4121 | // mismatched types. |
| 4122 | return SDValue(); |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4123 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4124 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4125 | // Record this extraction against the appropriate vector if possible... |
| 4126 | SDValue SourceVec = V.getOperand(0); |
| 4127 | unsigned EltNo = cast<ConstantSDNode>(V.getOperand(1))->getZExtValue(); |
| 4128 | bool FoundSource = false; |
| 4129 | for (unsigned j = 0; j < SourceVecs.size(); ++j) { |
| 4130 | if (SourceVecs[j] == SourceVec) { |
| 4131 | if (MinElts[j] > EltNo) |
| 4132 | MinElts[j] = EltNo; |
| 4133 | if (MaxElts[j] < EltNo) |
| 4134 | MaxElts[j] = EltNo; |
| 4135 | FoundSource = true; |
| 4136 | break; |
| 4137 | } |
| 4138 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4139 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4140 | // Or record a new source if not... |
| 4141 | if (!FoundSource) { |
| 4142 | SourceVecs.push_back(SourceVec); |
| 4143 | MinElts.push_back(EltNo); |
| 4144 | MaxElts.push_back(EltNo); |
| 4145 | } |
| 4146 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4147 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4148 | // Currently only do something sane when at most two source vectors |
| 4149 | // involved. |
| 4150 | if (SourceVecs.size() > 2) |
| 4151 | return SDValue(); |
| 4152 | |
| 4153 | SDValue ShuffleSrcs[2] = {DAG.getUNDEF(VT), DAG.getUNDEF(VT) }; |
| 4154 | int VEXTOffsets[2] = {0, 0}; |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4155 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4156 | // This loop extracts the usage patterns of the source vectors |
| 4157 | // and prepares appropriate SDValues for a shuffle if possible. |
| 4158 | for (unsigned i = 0; i < SourceVecs.size(); ++i) { |
| 4159 | if (SourceVecs[i].getValueType() == VT) { |
| 4160 | // No VEXT necessary |
| 4161 | ShuffleSrcs[i] = SourceVecs[i]; |
| 4162 | VEXTOffsets[i] = 0; |
| 4163 | continue; |
| 4164 | } else if (SourceVecs[i].getValueType().getVectorNumElements() < NumElts) { |
| 4165 | // It probably isn't worth padding out a smaller vector just to |
| 4166 | // break it down again in a shuffle. |
| 4167 | return SDValue(); |
| 4168 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4169 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4170 | // Since only 64-bit and 128-bit vectors are legal on ARM and |
| 4171 | // we've eliminated the other cases... |
Bob Wilson | 70f8573 | 2011-01-07 23:40:46 +0000 | [diff] [blame] | 4172 | assert(SourceVecs[i].getValueType().getVectorNumElements() == 2*NumElts && |
| 4173 | "unexpected vector sizes in ReconstructShuffle"); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4174 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4175 | if (MaxElts[i] - MinElts[i] >= NumElts) { |
| 4176 | // Span too large for a VEXT to cope |
| 4177 | return SDValue(); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4178 | } |
| 4179 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4180 | if (MinElts[i] >= NumElts) { |
| 4181 | // The extraction can just take the second half |
| 4182 | VEXTOffsets[i] = NumElts; |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4183 | ShuffleSrcs[i] = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 4184 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4185 | DAG.getIntPtrConstant(NumElts)); |
| 4186 | } else if (MaxElts[i] < NumElts) { |
| 4187 | // The extraction can just take the first half |
| 4188 | VEXTOffsets[i] = 0; |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4189 | ShuffleSrcs[i] = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 4190 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4191 | DAG.getIntPtrConstant(0)); |
| 4192 | } else { |
| 4193 | // An actual VEXT is needed |
| 4194 | VEXTOffsets[i] = MinElts[i]; |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4195 | SDValue VEXTSrc1 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 4196 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4197 | DAG.getIntPtrConstant(0)); |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4198 | SDValue VEXTSrc2 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 4199 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4200 | DAG.getIntPtrConstant(NumElts)); |
| 4201 | ShuffleSrcs[i] = DAG.getNode(ARMISD::VEXT, dl, VT, VEXTSrc1, VEXTSrc2, |
| 4202 | DAG.getConstant(VEXTOffsets[i], MVT::i32)); |
| 4203 | } |
| 4204 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4205 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4206 | SmallVector<int, 8> Mask; |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4207 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4208 | for (unsigned i = 0; i < NumElts; ++i) { |
| 4209 | SDValue Entry = Op.getOperand(i); |
| 4210 | if (Entry.getOpcode() == ISD::UNDEF) { |
| 4211 | Mask.push_back(-1); |
| 4212 | continue; |
| 4213 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4214 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4215 | SDValue ExtractVec = Entry.getOperand(0); |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4216 | int ExtractElt = cast<ConstantSDNode>(Op.getOperand(i) |
| 4217 | .getOperand(1))->getSExtValue(); |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4218 | if (ExtractVec == SourceVecs[0]) { |
| 4219 | Mask.push_back(ExtractElt - VEXTOffsets[0]); |
| 4220 | } else { |
| 4221 | Mask.push_back(ExtractElt + NumElts - VEXTOffsets[1]); |
| 4222 | } |
| 4223 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4224 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4225 | // Final check before we try to produce nonsense... |
| 4226 | if (isShuffleMaskLegal(Mask, VT)) |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4227 | return DAG.getVectorShuffle(VT, dl, ShuffleSrcs[0], ShuffleSrcs[1], |
| 4228 | &Mask[0]); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4229 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4230 | return SDValue(); |
| 4231 | } |
| 4232 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4233 | /// isShuffleMaskLegal - Targets can use this to indicate that they only |
| 4234 | /// support *some* VECTOR_SHUFFLE operations, those with specific masks. |
| 4235 | /// By default, if a target supports the VECTOR_SHUFFLE node, all mask values |
| 4236 | /// are assumed to be legal. |
| 4237 | bool |
| 4238 | ARMTargetLowering::isShuffleMaskLegal(const SmallVectorImpl<int> &M, |
| 4239 | EVT VT) const { |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4240 | if (VT.getVectorNumElements() == 4 && |
| 4241 | (VT.is128BitVector() || VT.is64BitVector())) { |
| 4242 | unsigned PFIndexes[4]; |
| 4243 | for (unsigned i = 0; i != 4; ++i) { |
| 4244 | if (M[i] < 0) |
| 4245 | PFIndexes[i] = 8; |
| 4246 | else |
| 4247 | PFIndexes[i] = M[i]; |
| 4248 | } |
| 4249 | |
| 4250 | // Compute the index in the perfect shuffle table. |
| 4251 | unsigned PFTableIndex = |
| 4252 | PFIndexes[0]*9*9*9+PFIndexes[1]*9*9+PFIndexes[2]*9+PFIndexes[3]; |
| 4253 | unsigned PFEntry = PerfectShuffleTable[PFTableIndex]; |
| 4254 | unsigned Cost = (PFEntry >> 30); |
| 4255 | |
| 4256 | if (Cost <= 4) |
| 4257 | return true; |
| 4258 | } |
| 4259 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4260 | bool ReverseVEXT; |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4261 | unsigned Imm, WhichResult; |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4262 | |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4263 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 4264 | return (EltSize >= 32 || |
| 4265 | ShuffleVectorSDNode::isSplatMask(&M[0], VT) || |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4266 | isVREVMask(M, VT, 64) || |
| 4267 | isVREVMask(M, VT, 32) || |
| 4268 | isVREVMask(M, VT, 16) || |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4269 | isVEXTMask(M, VT, ReverseVEXT, Imm) || |
Bill Wendling | 0d4c9d9 | 2011-03-15 21:15:20 +0000 | [diff] [blame] | 4270 | isVTBLMask(M, VT) || |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4271 | isVTRNMask(M, VT, WhichResult) || |
| 4272 | isVUZPMask(M, VT, WhichResult) || |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4273 | isVZIPMask(M, VT, WhichResult) || |
| 4274 | isVTRN_v_undef_Mask(M, VT, WhichResult) || |
| 4275 | isVUZP_v_undef_Mask(M, VT, WhichResult) || |
| 4276 | isVZIP_v_undef_Mask(M, VT, WhichResult)); |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4277 | } |
| 4278 | |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4279 | /// GeneratePerfectShuffle - Given an entry in the perfect-shuffle table, emit |
| 4280 | /// the specified operations to build the shuffle. |
| 4281 | static SDValue GeneratePerfectShuffle(unsigned PFEntry, SDValue LHS, |
| 4282 | SDValue RHS, SelectionDAG &DAG, |
| 4283 | DebugLoc dl) { |
| 4284 | unsigned OpNum = (PFEntry >> 26) & 0x0F; |
| 4285 | unsigned LHSID = (PFEntry >> 13) & ((1 << 13)-1); |
| 4286 | unsigned RHSID = (PFEntry >> 0) & ((1 << 13)-1); |
| 4287 | |
| 4288 | enum { |
| 4289 | OP_COPY = 0, // Copy, used for things like <u,u,u,3> to say it is <0,1,2,3> |
| 4290 | OP_VREV, |
| 4291 | OP_VDUP0, |
| 4292 | OP_VDUP1, |
| 4293 | OP_VDUP2, |
| 4294 | OP_VDUP3, |
| 4295 | OP_VEXT1, |
| 4296 | OP_VEXT2, |
| 4297 | OP_VEXT3, |
| 4298 | OP_VUZPL, // VUZP, left result |
| 4299 | OP_VUZPR, // VUZP, right result |
| 4300 | OP_VZIPL, // VZIP, left result |
| 4301 | OP_VZIPR, // VZIP, right result |
| 4302 | OP_VTRNL, // VTRN, left result |
| 4303 | OP_VTRNR // VTRN, right result |
| 4304 | }; |
| 4305 | |
| 4306 | if (OpNum == OP_COPY) { |
| 4307 | if (LHSID == (1*9+2)*9+3) return LHS; |
| 4308 | assert(LHSID == ((4*9+5)*9+6)*9+7 && "Illegal OP_COPY!"); |
| 4309 | return RHS; |
| 4310 | } |
| 4311 | |
| 4312 | SDValue OpLHS, OpRHS; |
| 4313 | OpLHS = GeneratePerfectShuffle(PerfectShuffleTable[LHSID], LHS, RHS, DAG, dl); |
| 4314 | OpRHS = GeneratePerfectShuffle(PerfectShuffleTable[RHSID], LHS, RHS, DAG, dl); |
| 4315 | EVT VT = OpLHS.getValueType(); |
| 4316 | |
| 4317 | switch (OpNum) { |
| 4318 | default: llvm_unreachable("Unknown shuffle opcode!"); |
| 4319 | case OP_VREV: |
Tanya Lattner | 2a8eb72 | 2011-05-18 06:42:21 +0000 | [diff] [blame] | 4320 | // VREV divides the vector in half and swaps within the half. |
Tanya Lattner | db28247 | 2011-05-18 21:44:54 +0000 | [diff] [blame] | 4321 | if (VT.getVectorElementType() == MVT::i32 || |
| 4322 | VT.getVectorElementType() == MVT::f32) |
Tanya Lattner | 2a8eb72 | 2011-05-18 06:42:21 +0000 | [diff] [blame] | 4323 | return DAG.getNode(ARMISD::VREV64, dl, VT, OpLHS); |
| 4324 | // vrev <4 x i16> -> VREV32 |
| 4325 | if (VT.getVectorElementType() == MVT::i16) |
| 4326 | return DAG.getNode(ARMISD::VREV32, dl, VT, OpLHS); |
| 4327 | // vrev <4 x i8> -> VREV16 |
| 4328 | assert(VT.getVectorElementType() == MVT::i8); |
| 4329 | return DAG.getNode(ARMISD::VREV16, dl, VT, OpLHS); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4330 | case OP_VDUP0: |
| 4331 | case OP_VDUP1: |
| 4332 | case OP_VDUP2: |
| 4333 | case OP_VDUP3: |
| 4334 | return DAG.getNode(ARMISD::VDUPLANE, dl, VT, |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 4335 | OpLHS, DAG.getConstant(OpNum-OP_VDUP0, MVT::i32)); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4336 | case OP_VEXT1: |
| 4337 | case OP_VEXT2: |
| 4338 | case OP_VEXT3: |
| 4339 | return DAG.getNode(ARMISD::VEXT, dl, VT, |
| 4340 | OpLHS, OpRHS, |
| 4341 | DAG.getConstant(OpNum-OP_VEXT1+1, MVT::i32)); |
| 4342 | case OP_VUZPL: |
| 4343 | case OP_VUZPR: |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 4344 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4345 | OpLHS, OpRHS).getValue(OpNum-OP_VUZPL); |
| 4346 | case OP_VZIPL: |
| 4347 | case OP_VZIPR: |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 4348 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4349 | OpLHS, OpRHS).getValue(OpNum-OP_VZIPL); |
| 4350 | case OP_VTRNL: |
| 4351 | case OP_VTRNR: |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 4352 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), |
| 4353 | OpLHS, OpRHS).getValue(OpNum-OP_VTRNL); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4354 | } |
| 4355 | } |
| 4356 | |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4357 | static SDValue LowerVECTOR_SHUFFLEv8i8(SDValue Op, |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4358 | ArrayRef<int> ShuffleMask, |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4359 | SelectionDAG &DAG) { |
| 4360 | // Check to see if we can use the VTBL instruction. |
| 4361 | SDValue V1 = Op.getOperand(0); |
| 4362 | SDValue V2 = Op.getOperand(1); |
| 4363 | DebugLoc DL = Op.getDebugLoc(); |
| 4364 | |
| 4365 | SmallVector<SDValue, 8> VTBLMask; |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4366 | for (ArrayRef<int>::iterator |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4367 | I = ShuffleMask.begin(), E = ShuffleMask.end(); I != E; ++I) |
| 4368 | VTBLMask.push_back(DAG.getConstant(*I, MVT::i32)); |
| 4369 | |
| 4370 | if (V2.getNode()->getOpcode() == ISD::UNDEF) |
| 4371 | return DAG.getNode(ARMISD::VTBL1, DL, MVT::v8i8, V1, |
| 4372 | DAG.getNode(ISD::BUILD_VECTOR, DL, MVT::v8i8, |
| 4373 | &VTBLMask[0], 8)); |
Bill Wendling | a24cb40 | 2011-03-15 20:47:26 +0000 | [diff] [blame] | 4374 | |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4375 | return DAG.getNode(ARMISD::VTBL2, DL, MVT::v8i8, V1, V2, |
Bill Wendling | a24cb40 | 2011-03-15 20:47:26 +0000 | [diff] [blame] | 4376 | DAG.getNode(ISD::BUILD_VECTOR, DL, MVT::v8i8, |
| 4377 | &VTBLMask[0], 8)); |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4378 | } |
| 4379 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4380 | static SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) { |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4381 | SDValue V1 = Op.getOperand(0); |
| 4382 | SDValue V2 = Op.getOperand(1); |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 4383 | DebugLoc dl = Op.getDebugLoc(); |
| 4384 | EVT VT = Op.getValueType(); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4385 | ShuffleVectorSDNode *SVN = cast<ShuffleVectorSDNode>(Op.getNode()); |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 4386 | |
Bob Wilson | 2886506 | 2009-08-13 02:13:04 +0000 | [diff] [blame] | 4387 | // Convert shuffles that are directly supported on NEON to target-specific |
| 4388 | // DAG nodes, instead of keeping them as shuffles and matching them again |
| 4389 | // during code selection. This is more efficient and avoids the possibility |
| 4390 | // of inconsistencies between legalization and selection. |
Bob Wilson | bfcbb50 | 2009-08-13 06:01:30 +0000 | [diff] [blame] | 4391 | // FIXME: floating-point vectors should be canonicalized to integer vectors |
| 4392 | // of the same time so that they get CSEd properly. |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4393 | ArrayRef<int> ShuffleMask = SVN->getMask(); |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4394 | |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4395 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 4396 | if (EltSize <= 32) { |
| 4397 | if (ShuffleVectorSDNode::isSplatMask(&ShuffleMask[0], VT)) { |
| 4398 | int Lane = SVN->getSplatIndex(); |
| 4399 | // If this is undef splat, generate it via "just" vdup, if possible. |
| 4400 | if (Lane == -1) Lane = 0; |
Anton Korobeynikov | 2ae0eec | 2009-11-02 00:12:06 +0000 | [diff] [blame] | 4401 | |
Dan Gohman | 65fd656 | 2011-11-03 21:49:52 +0000 | [diff] [blame] | 4402 | // Test if V1 is a SCALAR_TO_VECTOR. |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4403 | if (Lane == 0 && V1.getOpcode() == ISD::SCALAR_TO_VECTOR) { |
| 4404 | return DAG.getNode(ARMISD::VDUP, dl, VT, V1.getOperand(0)); |
| 4405 | } |
Dan Gohman | 65fd656 | 2011-11-03 21:49:52 +0000 | [diff] [blame] | 4406 | // Test if V1 is a BUILD_VECTOR which is equivalent to a SCALAR_TO_VECTOR |
| 4407 | // (and probably will turn into a SCALAR_TO_VECTOR once legalization |
| 4408 | // reaches it). |
| 4409 | if (Lane == 0 && V1.getOpcode() == ISD::BUILD_VECTOR && |
| 4410 | !isa<ConstantSDNode>(V1.getOperand(0))) { |
| 4411 | bool IsScalarToVector = true; |
| 4412 | for (unsigned i = 1, e = V1.getNumOperands(); i != e; ++i) |
| 4413 | if (V1.getOperand(i).getOpcode() != ISD::UNDEF) { |
| 4414 | IsScalarToVector = false; |
| 4415 | break; |
| 4416 | } |
| 4417 | if (IsScalarToVector) |
| 4418 | return DAG.getNode(ARMISD::VDUP, dl, VT, V1.getOperand(0)); |
| 4419 | } |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4420 | return DAG.getNode(ARMISD::VDUPLANE, dl, VT, V1, |
| 4421 | DAG.getConstant(Lane, MVT::i32)); |
Bob Wilson | c1d287b | 2009-08-14 05:13:08 +0000 | [diff] [blame] | 4422 | } |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4423 | |
| 4424 | bool ReverseVEXT; |
| 4425 | unsigned Imm; |
| 4426 | if (isVEXTMask(ShuffleMask, VT, ReverseVEXT, Imm)) { |
| 4427 | if (ReverseVEXT) |
| 4428 | std::swap(V1, V2); |
| 4429 | return DAG.getNode(ARMISD::VEXT, dl, VT, V1, V2, |
| 4430 | DAG.getConstant(Imm, MVT::i32)); |
| 4431 | } |
| 4432 | |
| 4433 | if (isVREVMask(ShuffleMask, VT, 64)) |
| 4434 | return DAG.getNode(ARMISD::VREV64, dl, VT, V1); |
| 4435 | if (isVREVMask(ShuffleMask, VT, 32)) |
| 4436 | return DAG.getNode(ARMISD::VREV32, dl, VT, V1); |
| 4437 | if (isVREVMask(ShuffleMask, VT, 16)) |
| 4438 | return DAG.getNode(ARMISD::VREV16, dl, VT, V1); |
| 4439 | |
| 4440 | // Check for Neon shuffles that modify both input vectors in place. |
| 4441 | // If both results are used, i.e., if there are two shuffles with the same |
| 4442 | // source operands and with masks corresponding to both results of one of |
| 4443 | // these operations, DAG memoization will ensure that a single node is |
| 4444 | // used for both shuffles. |
| 4445 | unsigned WhichResult; |
| 4446 | if (isVTRNMask(ShuffleMask, VT, WhichResult)) |
| 4447 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), |
| 4448 | V1, V2).getValue(WhichResult); |
| 4449 | if (isVUZPMask(ShuffleMask, VT, WhichResult)) |
| 4450 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), |
| 4451 | V1, V2).getValue(WhichResult); |
| 4452 | if (isVZIPMask(ShuffleMask, VT, WhichResult)) |
| 4453 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), |
| 4454 | V1, V2).getValue(WhichResult); |
| 4455 | |
| 4456 | if (isVTRN_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 4457 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), |
| 4458 | V1, V1).getValue(WhichResult); |
| 4459 | if (isVUZP_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 4460 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), |
| 4461 | V1, V1).getValue(WhichResult); |
| 4462 | if (isVZIP_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 4463 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), |
| 4464 | V1, V1).getValue(WhichResult); |
Bob Wilson | 0ce3710 | 2009-08-14 05:08:32 +0000 | [diff] [blame] | 4465 | } |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 4466 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4467 | // If the shuffle is not directly supported and it has 4 elements, use |
| 4468 | // the PerfectShuffle-generated table to synthesize it from other shuffles. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4469 | unsigned NumElts = VT.getVectorNumElements(); |
| 4470 | if (NumElts == 4) { |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4471 | unsigned PFIndexes[4]; |
| 4472 | for (unsigned i = 0; i != 4; ++i) { |
| 4473 | if (ShuffleMask[i] < 0) |
| 4474 | PFIndexes[i] = 8; |
| 4475 | else |
| 4476 | PFIndexes[i] = ShuffleMask[i]; |
| 4477 | } |
| 4478 | |
| 4479 | // Compute the index in the perfect shuffle table. |
| 4480 | unsigned PFTableIndex = |
| 4481 | 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] | 4482 | unsigned PFEntry = PerfectShuffleTable[PFTableIndex]; |
| 4483 | unsigned Cost = (PFEntry >> 30); |
| 4484 | |
| 4485 | if (Cost <= 4) |
| 4486 | return GeneratePerfectShuffle(PFEntry, V1, V2, DAG, dl); |
| 4487 | } |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 4488 | |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4489 | // Implement shuffles with 32- or 64-bit elements as ARMISD::BUILD_VECTORs. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4490 | if (EltSize >= 32) { |
| 4491 | // Do the expansion with floating-point types, since that is what the VFP |
| 4492 | // registers are defined to use, and since i64 is not legal. |
| 4493 | EVT EltVT = EVT::getFloatingPointVT(EltSize); |
| 4494 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), EltVT, NumElts); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4495 | V1 = DAG.getNode(ISD::BITCAST, dl, VecVT, V1); |
| 4496 | V2 = DAG.getNode(ISD::BITCAST, dl, VecVT, V2); |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4497 | SmallVector<SDValue, 8> Ops; |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4498 | for (unsigned i = 0; i < NumElts; ++i) { |
Bob Wilson | 63b8845 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 4499 | if (ShuffleMask[i] < 0) |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4500 | Ops.push_back(DAG.getUNDEF(EltVT)); |
| 4501 | else |
| 4502 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, EltVT, |
| 4503 | ShuffleMask[i] < (int)NumElts ? V1 : V2, |
| 4504 | DAG.getConstant(ShuffleMask[i] & (NumElts-1), |
| 4505 | MVT::i32))); |
Bob Wilson | 63b8845 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 4506 | } |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4507 | SDValue Val = DAG.getNode(ARMISD::BUILD_VECTOR, dl, VecVT, &Ops[0],NumElts); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4508 | return DAG.getNode(ISD::BITCAST, dl, VT, Val); |
Bob Wilson | 63b8845 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 4509 | } |
| 4510 | |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4511 | if (VT == MVT::v8i8) { |
| 4512 | SDValue NewOp = LowerVECTOR_SHUFFLEv8i8(Op, ShuffleMask, DAG); |
| 4513 | if (NewOp.getNode()) |
| 4514 | return NewOp; |
| 4515 | } |
| 4516 | |
Bob Wilson | 22cac0d | 2009-08-14 05:16:33 +0000 | [diff] [blame] | 4517 | return SDValue(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4518 | } |
| 4519 | |
Eli Friedman | 5c89cb8 | 2011-10-24 23:08:52 +0000 | [diff] [blame] | 4520 | static SDValue LowerINSERT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) { |
| 4521 | // INSERT_VECTOR_ELT is legal only for immediate indexes. |
| 4522 | SDValue Lane = Op.getOperand(2); |
| 4523 | if (!isa<ConstantSDNode>(Lane)) |
| 4524 | return SDValue(); |
| 4525 | |
| 4526 | return Op; |
| 4527 | } |
| 4528 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4529 | static SDValue LowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) { |
Bob Wilson | 3468c2e | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 4530 | // EXTRACT_VECTOR_ELT is legal only for immediate indexes. |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4531 | SDValue Lane = Op.getOperand(1); |
Bob Wilson | 3468c2e | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 4532 | if (!isa<ConstantSDNode>(Lane)) |
| 4533 | return SDValue(); |
| 4534 | |
| 4535 | SDValue Vec = Op.getOperand(0); |
| 4536 | if (Op.getValueType() == MVT::i32 && |
| 4537 | Vec.getValueType().getVectorElementType().getSizeInBits() < 32) { |
| 4538 | DebugLoc dl = Op.getDebugLoc(); |
| 4539 | return DAG.getNode(ARMISD::VGETLANEu, dl, MVT::i32, Vec, Lane); |
| 4540 | } |
| 4541 | |
| 4542 | return Op; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4543 | } |
| 4544 | |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 4545 | static SDValue LowerCONCAT_VECTORS(SDValue Op, SelectionDAG &DAG) { |
| 4546 | // The only time a CONCAT_VECTORS operation can have legal types is when |
| 4547 | // two 64-bit vectors are concatenated to a 128-bit vector. |
| 4548 | assert(Op.getValueType().is128BitVector() && Op.getNumOperands() == 2 && |
| 4549 | "unexpected CONCAT_VECTORS"); |
| 4550 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4551 | SDValue Val = DAG.getUNDEF(MVT::v2f64); |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 4552 | SDValue Op0 = Op.getOperand(0); |
| 4553 | SDValue Op1 = Op.getOperand(1); |
| 4554 | if (Op0.getOpcode() != ISD::UNDEF) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4555 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Val, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4556 | DAG.getNode(ISD::BITCAST, dl, MVT::f64, Op0), |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 4557 | DAG.getIntPtrConstant(0)); |
| 4558 | if (Op1.getOpcode() != ISD::UNDEF) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4559 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Val, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4560 | DAG.getNode(ISD::BITCAST, dl, MVT::f64, Op1), |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 4561 | DAG.getIntPtrConstant(1)); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4562 | return DAG.getNode(ISD::BITCAST, dl, Op.getValueType(), Val); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4563 | } |
| 4564 | |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 4565 | /// isExtendedBUILD_VECTOR - Check if N is a constant BUILD_VECTOR where each |
| 4566 | /// element has been zero/sign-extended, depending on the isSigned parameter, |
| 4567 | /// from an integer type half its size. |
| 4568 | static bool isExtendedBUILD_VECTOR(SDNode *N, SelectionDAG &DAG, |
| 4569 | bool isSigned) { |
| 4570 | // A v2i64 BUILD_VECTOR will have been legalized to a BITCAST from v4i32. |
| 4571 | EVT VT = N->getValueType(0); |
| 4572 | if (VT == MVT::v2i64 && N->getOpcode() == ISD::BITCAST) { |
| 4573 | SDNode *BVN = N->getOperand(0).getNode(); |
| 4574 | if (BVN->getValueType(0) != MVT::v4i32 || |
| 4575 | BVN->getOpcode() != ISD::BUILD_VECTOR) |
| 4576 | return false; |
| 4577 | unsigned LoElt = DAG.getTargetLoweringInfo().isBigEndian() ? 1 : 0; |
| 4578 | unsigned HiElt = 1 - LoElt; |
| 4579 | ConstantSDNode *Lo0 = dyn_cast<ConstantSDNode>(BVN->getOperand(LoElt)); |
| 4580 | ConstantSDNode *Hi0 = dyn_cast<ConstantSDNode>(BVN->getOperand(HiElt)); |
| 4581 | ConstantSDNode *Lo1 = dyn_cast<ConstantSDNode>(BVN->getOperand(LoElt+2)); |
| 4582 | ConstantSDNode *Hi1 = dyn_cast<ConstantSDNode>(BVN->getOperand(HiElt+2)); |
| 4583 | if (!Lo0 || !Hi0 || !Lo1 || !Hi1) |
| 4584 | return false; |
| 4585 | if (isSigned) { |
| 4586 | if (Hi0->getSExtValue() == Lo0->getSExtValue() >> 32 && |
| 4587 | Hi1->getSExtValue() == Lo1->getSExtValue() >> 32) |
| 4588 | return true; |
| 4589 | } else { |
| 4590 | if (Hi0->isNullValue() && Hi1->isNullValue()) |
| 4591 | return true; |
| 4592 | } |
| 4593 | return false; |
| 4594 | } |
| 4595 | |
| 4596 | if (N->getOpcode() != ISD::BUILD_VECTOR) |
| 4597 | return false; |
| 4598 | |
| 4599 | for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) { |
| 4600 | SDNode *Elt = N->getOperand(i).getNode(); |
| 4601 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Elt)) { |
| 4602 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 4603 | unsigned HalfSize = EltSize / 2; |
| 4604 | if (isSigned) { |
Bob Wilson | 9d45de2 | 2011-10-18 18:46:49 +0000 | [diff] [blame] | 4605 | if (!isIntN(HalfSize, C->getSExtValue())) |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 4606 | return false; |
| 4607 | } else { |
Bob Wilson | 9d45de2 | 2011-10-18 18:46:49 +0000 | [diff] [blame] | 4608 | if (!isUIntN(HalfSize, C->getZExtValue())) |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 4609 | return false; |
| 4610 | } |
| 4611 | continue; |
| 4612 | } |
| 4613 | return false; |
| 4614 | } |
| 4615 | |
| 4616 | return true; |
| 4617 | } |
| 4618 | |
| 4619 | /// isSignExtended - Check if a node is a vector value that is sign-extended |
| 4620 | /// or a constant BUILD_VECTOR with sign-extended elements. |
| 4621 | static bool isSignExtended(SDNode *N, SelectionDAG &DAG) { |
| 4622 | if (N->getOpcode() == ISD::SIGN_EXTEND || ISD::isSEXTLoad(N)) |
| 4623 | return true; |
| 4624 | if (isExtendedBUILD_VECTOR(N, DAG, true)) |
| 4625 | return true; |
| 4626 | return false; |
| 4627 | } |
| 4628 | |
| 4629 | /// isZeroExtended - Check if a node is a vector value that is zero-extended |
| 4630 | /// or a constant BUILD_VECTOR with zero-extended elements. |
| 4631 | static bool isZeroExtended(SDNode *N, SelectionDAG &DAG) { |
| 4632 | if (N->getOpcode() == ISD::ZERO_EXTEND || ISD::isZEXTLoad(N)) |
| 4633 | return true; |
| 4634 | if (isExtendedBUILD_VECTOR(N, DAG, false)) |
| 4635 | return true; |
| 4636 | return false; |
| 4637 | } |
| 4638 | |
| 4639 | /// SkipExtension - For a node that is a SIGN_EXTEND, ZERO_EXTEND, extending |
| 4640 | /// load, or BUILD_VECTOR with extended elements, return the unextended value. |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4641 | static SDValue SkipExtension(SDNode *N, SelectionDAG &DAG) { |
| 4642 | if (N->getOpcode() == ISD::SIGN_EXTEND || N->getOpcode() == ISD::ZERO_EXTEND) |
| 4643 | return N->getOperand(0); |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 4644 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) |
| 4645 | return DAG.getLoad(LD->getMemoryVT(), N->getDebugLoc(), LD->getChain(), |
| 4646 | LD->getBasePtr(), LD->getPointerInfo(), LD->isVolatile(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 4647 | LD->isNonTemporal(), LD->isInvariant(), |
| 4648 | LD->getAlignment()); |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 4649 | // Otherwise, the value must be a BUILD_VECTOR. For v2i64, it will |
| 4650 | // have been legalized as a BITCAST from v4i32. |
| 4651 | if (N->getOpcode() == ISD::BITCAST) { |
| 4652 | SDNode *BVN = N->getOperand(0).getNode(); |
| 4653 | assert(BVN->getOpcode() == ISD::BUILD_VECTOR && |
| 4654 | BVN->getValueType(0) == MVT::v4i32 && "expected v4i32 BUILD_VECTOR"); |
| 4655 | unsigned LowElt = DAG.getTargetLoweringInfo().isBigEndian() ? 1 : 0; |
| 4656 | return DAG.getNode(ISD::BUILD_VECTOR, N->getDebugLoc(), MVT::v2i32, |
| 4657 | BVN->getOperand(LowElt), BVN->getOperand(LowElt+2)); |
| 4658 | } |
| 4659 | // Construct a new BUILD_VECTOR with elements truncated to half the size. |
| 4660 | assert(N->getOpcode() == ISD::BUILD_VECTOR && "expected BUILD_VECTOR"); |
| 4661 | EVT VT = N->getValueType(0); |
| 4662 | unsigned EltSize = VT.getVectorElementType().getSizeInBits() / 2; |
| 4663 | unsigned NumElts = VT.getVectorNumElements(); |
| 4664 | MVT TruncVT = MVT::getIntegerVT(EltSize); |
| 4665 | SmallVector<SDValue, 8> Ops; |
| 4666 | for (unsigned i = 0; i != NumElts; ++i) { |
| 4667 | ConstantSDNode *C = cast<ConstantSDNode>(N->getOperand(i)); |
| 4668 | const APInt &CInt = C->getAPIntValue(); |
Jay Foad | 40f8f62 | 2010-12-07 08:25:19 +0000 | [diff] [blame] | 4669 | Ops.push_back(DAG.getConstant(CInt.trunc(EltSize), TruncVT)); |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 4670 | } |
| 4671 | return DAG.getNode(ISD::BUILD_VECTOR, N->getDebugLoc(), |
| 4672 | MVT::getVectorVT(TruncVT, NumElts), Ops.data(), NumElts); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4673 | } |
| 4674 | |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 4675 | static bool isAddSubSExt(SDNode *N, SelectionDAG &DAG) { |
| 4676 | unsigned Opcode = N->getOpcode(); |
| 4677 | if (Opcode == ISD::ADD || Opcode == ISD::SUB) { |
| 4678 | SDNode *N0 = N->getOperand(0).getNode(); |
| 4679 | SDNode *N1 = N->getOperand(1).getNode(); |
| 4680 | return N0->hasOneUse() && N1->hasOneUse() && |
| 4681 | isSignExtended(N0, DAG) && isSignExtended(N1, DAG); |
| 4682 | } |
| 4683 | return false; |
| 4684 | } |
| 4685 | |
| 4686 | static bool isAddSubZExt(SDNode *N, SelectionDAG &DAG) { |
| 4687 | unsigned Opcode = N->getOpcode(); |
| 4688 | if (Opcode == ISD::ADD || Opcode == ISD::SUB) { |
| 4689 | SDNode *N0 = N->getOperand(0).getNode(); |
| 4690 | SDNode *N1 = N->getOperand(1).getNode(); |
| 4691 | return N0->hasOneUse() && N1->hasOneUse() && |
| 4692 | isZeroExtended(N0, DAG) && isZeroExtended(N1, DAG); |
| 4693 | } |
| 4694 | return false; |
| 4695 | } |
| 4696 | |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4697 | static SDValue LowerMUL(SDValue Op, SelectionDAG &DAG) { |
| 4698 | // Multiplications are only custom-lowered for 128-bit vectors so that |
| 4699 | // VMULL can be detected. Otherwise v2i64 multiplications are not legal. |
| 4700 | EVT VT = Op.getValueType(); |
| 4701 | assert(VT.is128BitVector() && "unexpected type for custom-lowering ISD::MUL"); |
| 4702 | SDNode *N0 = Op.getOperand(0).getNode(); |
| 4703 | SDNode *N1 = Op.getOperand(1).getNode(); |
| 4704 | unsigned NewOpc = 0; |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 4705 | bool isMLA = false; |
| 4706 | bool isN0SExt = isSignExtended(N0, DAG); |
| 4707 | bool isN1SExt = isSignExtended(N1, DAG); |
| 4708 | if (isN0SExt && isN1SExt) |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4709 | NewOpc = ARMISD::VMULLs; |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 4710 | else { |
| 4711 | bool isN0ZExt = isZeroExtended(N0, DAG); |
| 4712 | bool isN1ZExt = isZeroExtended(N1, DAG); |
| 4713 | if (isN0ZExt && isN1ZExt) |
| 4714 | NewOpc = ARMISD::VMULLu; |
| 4715 | else if (isN1SExt || isN1ZExt) { |
| 4716 | // Look for (s/zext A + s/zext B) * (s/zext C). We want to turn these |
| 4717 | // into (s/zext A * s/zext C) + (s/zext B * s/zext C) |
| 4718 | if (isN1SExt && isAddSubSExt(N0, DAG)) { |
| 4719 | NewOpc = ARMISD::VMULLs; |
| 4720 | isMLA = true; |
| 4721 | } else if (isN1ZExt && isAddSubZExt(N0, DAG)) { |
| 4722 | NewOpc = ARMISD::VMULLu; |
| 4723 | isMLA = true; |
| 4724 | } else if (isN0ZExt && isAddSubZExt(N1, DAG)) { |
| 4725 | std::swap(N0, N1); |
| 4726 | NewOpc = ARMISD::VMULLu; |
| 4727 | isMLA = true; |
| 4728 | } |
| 4729 | } |
| 4730 | |
| 4731 | if (!NewOpc) { |
| 4732 | if (VT == MVT::v2i64) |
| 4733 | // Fall through to expand this. It is not legal. |
| 4734 | return SDValue(); |
| 4735 | else |
| 4736 | // Other vector multiplications are legal. |
| 4737 | return Op; |
| 4738 | } |
| 4739 | } |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4740 | |
| 4741 | // Legalize to a VMULL instruction. |
| 4742 | DebugLoc DL = Op.getDebugLoc(); |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 4743 | SDValue Op0; |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4744 | SDValue Op1 = SkipExtension(N1, DAG); |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 4745 | if (!isMLA) { |
| 4746 | Op0 = SkipExtension(N0, DAG); |
| 4747 | assert(Op0.getValueType().is64BitVector() && |
| 4748 | Op1.getValueType().is64BitVector() && |
| 4749 | "unexpected types for extended operands to VMULL"); |
| 4750 | return DAG.getNode(NewOpc, DL, VT, Op0, Op1); |
| 4751 | } |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4752 | |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 4753 | // Optimizing (zext A + zext B) * C, to (VMULL A, C) + (VMULL B, C) during |
| 4754 | // isel lowering to take advantage of no-stall back to back vmul + vmla. |
| 4755 | // vmull q0, d4, d6 |
| 4756 | // vmlal q0, d5, d6 |
| 4757 | // is faster than |
| 4758 | // vaddl q0, d4, d5 |
| 4759 | // vmovl q1, d6 |
| 4760 | // vmul q0, q0, q1 |
| 4761 | SDValue N00 = SkipExtension(N0->getOperand(0).getNode(), DAG); |
| 4762 | SDValue N01 = SkipExtension(N0->getOperand(1).getNode(), DAG); |
| 4763 | EVT Op1VT = Op1.getValueType(); |
| 4764 | return DAG.getNode(N0->getOpcode(), DL, VT, |
| 4765 | DAG.getNode(NewOpc, DL, VT, |
| 4766 | DAG.getNode(ISD::BITCAST, DL, Op1VT, N00), Op1), |
| 4767 | DAG.getNode(NewOpc, DL, VT, |
| 4768 | DAG.getNode(ISD::BITCAST, DL, Op1VT, N01), Op1)); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4769 | } |
| 4770 | |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4771 | static SDValue |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4772 | LowerSDIV_v4i8(SDValue X, SDValue Y, DebugLoc dl, SelectionDAG &DAG) { |
| 4773 | // Convert to float |
| 4774 | // float4 xf = vcvt_f32_s32(vmovl_s16(a.lo)); |
| 4775 | // float4 yf = vcvt_f32_s32(vmovl_s16(b.lo)); |
| 4776 | X = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, X); |
| 4777 | Y = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, Y); |
| 4778 | X = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, X); |
| 4779 | Y = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, Y); |
| 4780 | // Get reciprocal estimate. |
| 4781 | // float4 recip = vrecpeq_f32(yf); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4782 | Y = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4783 | DAG.getConstant(Intrinsic::arm_neon_vrecpe, MVT::i32), Y); |
| 4784 | // Because char has a smaller range than uchar, we can actually get away |
| 4785 | // without any newton steps. This requires that we use a weird bias |
| 4786 | // of 0xb000, however (again, this has been exhaustively tested). |
| 4787 | // float4 result = as_float4(as_int4(xf*recip) + 0xb000); |
| 4788 | X = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, X, Y); |
| 4789 | X = DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, X); |
| 4790 | Y = DAG.getConstant(0xb000, MVT::i32); |
| 4791 | Y = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, Y, Y, Y, Y); |
| 4792 | X = DAG.getNode(ISD::ADD, dl, MVT::v4i32, X, Y); |
| 4793 | X = DAG.getNode(ISD::BITCAST, dl, MVT::v4f32, X); |
| 4794 | // Convert back to short. |
| 4795 | X = DAG.getNode(ISD::FP_TO_SINT, dl, MVT::v4i32, X); |
| 4796 | X = DAG.getNode(ISD::TRUNCATE, dl, MVT::v4i16, X); |
| 4797 | return X; |
| 4798 | } |
| 4799 | |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4800 | static SDValue |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4801 | LowerSDIV_v4i16(SDValue N0, SDValue N1, DebugLoc dl, SelectionDAG &DAG) { |
| 4802 | SDValue N2; |
| 4803 | // Convert to float. |
| 4804 | // float4 yf = vcvt_f32_s32(vmovl_s16(y)); |
| 4805 | // float4 xf = vcvt_f32_s32(vmovl_s16(x)); |
| 4806 | N0 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, N0); |
| 4807 | N1 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, N1); |
| 4808 | N0 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N0); |
| 4809 | N1 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4810 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4811 | // Use reciprocal estimate and one refinement step. |
| 4812 | // float4 recip = vrecpeq_f32(yf); |
| 4813 | // recip *= vrecpsq_f32(yf, recip); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4814 | N2 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4815 | DAG.getConstant(Intrinsic::arm_neon_vrecpe, MVT::i32), N1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4816 | N1 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4817 | DAG.getConstant(Intrinsic::arm_neon_vrecps, MVT::i32), |
| 4818 | N1, N2); |
| 4819 | N2 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N1, N2); |
| 4820 | // Because short has a smaller range than ushort, we can actually get away |
| 4821 | // with only a single newton step. This requires that we use a weird bias |
| 4822 | // of 89, however (again, this has been exhaustively tested). |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 4823 | // float4 result = as_float4(as_int4(xf*recip) + 0x89); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4824 | N0 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N0, N2); |
| 4825 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, N0); |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 4826 | N1 = DAG.getConstant(0x89, MVT::i32); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4827 | N1 = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, N1, N1, N1, N1); |
| 4828 | N0 = DAG.getNode(ISD::ADD, dl, MVT::v4i32, N0, N1); |
| 4829 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4f32, N0); |
| 4830 | // Convert back to integer and return. |
| 4831 | // return vmovn_s32(vcvt_s32_f32(result)); |
| 4832 | N0 = DAG.getNode(ISD::FP_TO_SINT, dl, MVT::v4i32, N0); |
| 4833 | N0 = DAG.getNode(ISD::TRUNCATE, dl, MVT::v4i16, N0); |
| 4834 | return N0; |
| 4835 | } |
| 4836 | |
| 4837 | static SDValue LowerSDIV(SDValue Op, SelectionDAG &DAG) { |
| 4838 | EVT VT = Op.getValueType(); |
| 4839 | assert((VT == MVT::v4i16 || VT == MVT::v8i8) && |
| 4840 | "unexpected type for custom-lowering ISD::SDIV"); |
| 4841 | |
| 4842 | DebugLoc dl = Op.getDebugLoc(); |
| 4843 | SDValue N0 = Op.getOperand(0); |
| 4844 | SDValue N1 = Op.getOperand(1); |
| 4845 | SDValue N2, N3; |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4846 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4847 | if (VT == MVT::v8i8) { |
| 4848 | N0 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v8i16, N0); |
| 4849 | N1 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v8i16, N1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4850 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4851 | N2 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| 4852 | DAG.getIntPtrConstant(4)); |
| 4853 | N3 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4854 | DAG.getIntPtrConstant(4)); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4855 | N0 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| 4856 | DAG.getIntPtrConstant(0)); |
| 4857 | N1 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
| 4858 | DAG.getIntPtrConstant(0)); |
| 4859 | |
| 4860 | N0 = LowerSDIV_v4i8(N0, N1, dl, DAG); // v4i16 |
| 4861 | N2 = LowerSDIV_v4i8(N2, N3, dl, DAG); // v4i16 |
| 4862 | |
| 4863 | N0 = DAG.getNode(ISD::CONCAT_VECTORS, dl, MVT::v8i16, N0, N2); |
| 4864 | N0 = LowerCONCAT_VECTORS(N0, DAG); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4865 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4866 | N0 = DAG.getNode(ISD::TRUNCATE, dl, MVT::v8i8, N0); |
| 4867 | return N0; |
| 4868 | } |
| 4869 | return LowerSDIV_v4i16(N0, N1, dl, DAG); |
| 4870 | } |
| 4871 | |
| 4872 | static SDValue LowerUDIV(SDValue Op, SelectionDAG &DAG) { |
| 4873 | EVT VT = Op.getValueType(); |
| 4874 | assert((VT == MVT::v4i16 || VT == MVT::v8i8) && |
| 4875 | "unexpected type for custom-lowering ISD::UDIV"); |
| 4876 | |
| 4877 | DebugLoc dl = Op.getDebugLoc(); |
| 4878 | SDValue N0 = Op.getOperand(0); |
| 4879 | SDValue N1 = Op.getOperand(1); |
| 4880 | SDValue N2, N3; |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4881 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4882 | if (VT == MVT::v8i8) { |
| 4883 | N0 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v8i16, N0); |
| 4884 | N1 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v8i16, N1); |
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 | N2 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| 4887 | DAG.getIntPtrConstant(4)); |
| 4888 | N3 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4889 | DAG.getIntPtrConstant(4)); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4890 | N0 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| 4891 | DAG.getIntPtrConstant(0)); |
| 4892 | N1 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
| 4893 | DAG.getIntPtrConstant(0)); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4894 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4895 | N0 = LowerSDIV_v4i16(N0, N1, dl, DAG); // v4i16 |
| 4896 | N2 = LowerSDIV_v4i16(N2, N3, dl, DAG); // v4i16 |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4897 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4898 | N0 = DAG.getNode(ISD::CONCAT_VECTORS, dl, MVT::v8i16, N0, N2); |
| 4899 | N0 = LowerCONCAT_VECTORS(N0, DAG); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4900 | |
| 4901 | N0 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v8i8, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4902 | DAG.getConstant(Intrinsic::arm_neon_vqmovnsu, MVT::i32), |
| 4903 | N0); |
| 4904 | return N0; |
| 4905 | } |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4906 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4907 | // v4i16 sdiv ... Convert to float. |
| 4908 | // float4 yf = vcvt_f32_s32(vmovl_u16(y)); |
| 4909 | // float4 xf = vcvt_f32_s32(vmovl_u16(x)); |
| 4910 | N0 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v4i32, N0); |
| 4911 | N1 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v4i32, N1); |
| 4912 | N0 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N0); |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 4913 | SDValue BN1 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N1); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4914 | |
| 4915 | // Use reciprocal estimate and two refinement steps. |
| 4916 | // float4 recip = vrecpeq_f32(yf); |
| 4917 | // recip *= vrecpsq_f32(yf, recip); |
| 4918 | // recip *= vrecpsq_f32(yf, recip); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4919 | N2 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 4920 | DAG.getConstant(Intrinsic::arm_neon_vrecpe, MVT::i32), BN1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4921 | N1 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4922 | DAG.getConstant(Intrinsic::arm_neon_vrecps, MVT::i32), |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 4923 | BN1, N2); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4924 | N2 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N1, N2); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4925 | N1 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4926 | DAG.getConstant(Intrinsic::arm_neon_vrecps, MVT::i32), |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 4927 | BN1, N2); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4928 | N2 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N1, N2); |
| 4929 | // Simply multiplying by the reciprocal estimate can leave us a few ulps |
| 4930 | // too low, so we add 2 ulps (exhaustive testing shows that this is enough, |
| 4931 | // 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] | 4932 | // float4 result = as_float4(as_int4(xf*recip) + 2); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4933 | N0 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N0, N2); |
| 4934 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, N0); |
| 4935 | N1 = DAG.getConstant(2, MVT::i32); |
| 4936 | N1 = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, N1, N1, N1, N1); |
| 4937 | N0 = DAG.getNode(ISD::ADD, dl, MVT::v4i32, N0, N1); |
| 4938 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4f32, N0); |
| 4939 | // Convert back to integer and return. |
| 4940 | // return vmovn_u32(vcvt_s32_f32(result)); |
| 4941 | N0 = DAG.getNode(ISD::FP_TO_SINT, dl, MVT::v4i32, N0); |
| 4942 | N0 = DAG.getNode(ISD::TRUNCATE, dl, MVT::v4i16, N0); |
| 4943 | return N0; |
| 4944 | } |
| 4945 | |
Evan Cheng | 342e316 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 4946 | static SDValue LowerADDC_ADDE_SUBC_SUBE(SDValue Op, SelectionDAG &DAG) { |
| 4947 | EVT VT = Op.getNode()->getValueType(0); |
| 4948 | SDVTList VTs = DAG.getVTList(VT, MVT::i32); |
| 4949 | |
| 4950 | unsigned Opc; |
| 4951 | bool ExtraOp = false; |
| 4952 | switch (Op.getOpcode()) { |
| 4953 | default: assert(0 && "Invalid code"); |
| 4954 | case ISD::ADDC: Opc = ARMISD::ADDC; break; |
| 4955 | case ISD::ADDE: Opc = ARMISD::ADDE; ExtraOp = true; break; |
| 4956 | case ISD::SUBC: Opc = ARMISD::SUBC; break; |
| 4957 | case ISD::SUBE: Opc = ARMISD::SUBE; ExtraOp = true; break; |
| 4958 | } |
| 4959 | |
| 4960 | if (!ExtraOp) |
| 4961 | return DAG.getNode(Opc, Op->getDebugLoc(), VTs, Op.getOperand(0), |
| 4962 | Op.getOperand(1)); |
| 4963 | return DAG.getNode(Opc, Op->getDebugLoc(), VTs, Op.getOperand(0), |
| 4964 | Op.getOperand(1), Op.getOperand(2)); |
| 4965 | } |
| 4966 | |
Eli Friedman | 74bf18c | 2011-09-15 22:26:18 +0000 | [diff] [blame] | 4967 | static SDValue LowerAtomicLoadStore(SDValue Op, SelectionDAG &DAG) { |
Eli Friedman | 7cc1566 | 2011-09-15 22:18:49 +0000 | [diff] [blame] | 4968 | // Monotonic load/store is legal for all targets |
| 4969 | if (cast<AtomicSDNode>(Op)->getOrdering() <= Monotonic) |
| 4970 | return Op; |
| 4971 | |
| 4972 | // Aquire/Release load/store is not legal for targets without a |
| 4973 | // dmb or equivalent available. |
| 4974 | return SDValue(); |
| 4975 | } |
| 4976 | |
| 4977 | |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 4978 | static void |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 4979 | ReplaceATOMIC_OP_64(SDNode *Node, SmallVectorImpl<SDValue>& Results, |
| 4980 | SelectionDAG &DAG, unsigned NewOp) { |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 4981 | DebugLoc dl = Node->getDebugLoc(); |
Duncan Sands | 17001ce | 2011-10-18 12:44:00 +0000 | [diff] [blame] | 4982 | assert (Node->getValueType(0) == MVT::i64 && |
| 4983 | "Only know how to expand i64 atomics"); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 4984 | |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 4985 | SmallVector<SDValue, 6> Ops; |
| 4986 | Ops.push_back(Node->getOperand(0)); // Chain |
| 4987 | Ops.push_back(Node->getOperand(1)); // Ptr |
| 4988 | // Low part of Val1 |
| 4989 | Ops.push_back(DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, |
| 4990 | Node->getOperand(2), DAG.getIntPtrConstant(0))); |
| 4991 | // High part of Val1 |
| 4992 | Ops.push_back(DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, |
| 4993 | Node->getOperand(2), DAG.getIntPtrConstant(1))); |
Andrew Trick | 3af7a67 | 2011-09-20 03:06:13 +0000 | [diff] [blame] | 4994 | if (NewOp == ARMISD::ATOMCMPXCHG64_DAG) { |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 4995 | // High part of Val1 |
| 4996 | Ops.push_back(DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, |
| 4997 | Node->getOperand(3), DAG.getIntPtrConstant(0))); |
| 4998 | // High part of Val2 |
| 4999 | Ops.push_back(DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, |
| 5000 | Node->getOperand(3), DAG.getIntPtrConstant(1))); |
| 5001 | } |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5002 | SDVTList Tys = DAG.getVTList(MVT::i32, MVT::i32, MVT::Other); |
| 5003 | SDValue Result = |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5004 | DAG.getMemIntrinsicNode(NewOp, dl, Tys, Ops.data(), Ops.size(), MVT::i64, |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5005 | cast<MemSDNode>(Node)->getMemOperand()); |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5006 | SDValue OpsF[] = { Result.getValue(0), Result.getValue(1) }; |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5007 | Results.push_back(DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, OpsF, 2)); |
| 5008 | Results.push_back(Result.getValue(2)); |
| 5009 | } |
| 5010 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 5011 | SDValue ARMTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5012 | switch (Op.getOpcode()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 5013 | default: llvm_unreachable("Don't know how to custom lower this!"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5014 | case ISD::ConstantPool: return LowerConstantPool(Op, DAG); |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 5015 | case ISD::BlockAddress: return LowerBlockAddress(Op, DAG); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 5016 | case ISD::GlobalAddress: |
| 5017 | return Subtarget->isTargetDarwin() ? LowerGlobalAddressDarwin(Op, DAG) : |
| 5018 | LowerGlobalAddressELF(Op, DAG); |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 5019 | case ISD::GlobalTLSAddress: return LowerGlobalTLSAddress(Op, DAG); |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 5020 | case ISD::SELECT: return LowerSELECT(Op, DAG); |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 5021 | case ISD::SELECT_CC: return LowerSELECT_CC(Op, DAG); |
| 5022 | case ISD::BR_CC: return LowerBR_CC(Op, DAG); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5023 | case ISD::BR_JT: return LowerBR_JT(Op, DAG); |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 5024 | case ISD::VASTART: return LowerVASTART(Op, DAG); |
Jim Grosbach | 7c03dbd | 2009-12-14 21:24:16 +0000 | [diff] [blame] | 5025 | case ISD::MEMBARRIER: return LowerMEMBARRIER(Op, DAG, Subtarget); |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 5026 | case ISD::ATOMIC_FENCE: return LowerATOMIC_FENCE(Op, DAG, Subtarget); |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 5027 | case ISD::PREFETCH: return LowerPREFETCH(Op, DAG, Subtarget); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 5028 | case ISD::SINT_TO_FP: |
| 5029 | case ISD::UINT_TO_FP: return LowerINT_TO_FP(Op, DAG); |
| 5030 | case ISD::FP_TO_SINT: |
| 5031 | case ISD::FP_TO_UINT: return LowerFP_TO_INT(Op, DAG); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5032 | case ISD::FCOPYSIGN: return LowerFCOPYSIGN(Op, DAG); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 5033 | case ISD::RETURNADDR: return LowerRETURNADDR(Op, DAG); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 5034 | case ISD::FRAMEADDR: return LowerFRAMEADDR(Op, DAG); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 5035 | case ISD::GLOBAL_OFFSET_TABLE: return LowerGLOBAL_OFFSET_TABLE(Op, DAG); |
Jim Grosbach | 23ff7cf | 2010-05-26 20:22:18 +0000 | [diff] [blame] | 5036 | case ISD::EH_SJLJ_SETJMP: return LowerEH_SJLJ_SETJMP(Op, DAG); |
Jim Grosbach | 5eb1951 | 2010-05-22 01:06:18 +0000 | [diff] [blame] | 5037 | case ISD::EH_SJLJ_LONGJMP: return LowerEH_SJLJ_LONGJMP(Op, DAG); |
Jim Grosbach | a87ded2 | 2010-02-08 23:22:00 +0000 | [diff] [blame] | 5038 | case ISD::INTRINSIC_WO_CHAIN: return LowerINTRINSIC_WO_CHAIN(Op, DAG, |
| 5039 | Subtarget); |
Evan Cheng | 21a6179 | 2011-03-14 18:02:30 +0000 | [diff] [blame] | 5040 | case ISD::BITCAST: return ExpandBITCAST(Op.getNode(), DAG); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5041 | case ISD::SHL: |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 5042 | case ISD::SRL: |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5043 | case ISD::SRA: return LowerShift(Op.getNode(), DAG, Subtarget); |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 5044 | case ISD::SHL_PARTS: return LowerShiftLeftParts(Op, DAG); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 5045 | case ISD::SRL_PARTS: |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 5046 | case ISD::SRA_PARTS: return LowerShiftRightParts(Op, DAG); |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 5047 | case ISD::CTTZ: return LowerCTTZ(Op.getNode(), DAG, Subtarget); |
Duncan Sands | 28b77e9 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 5048 | case ISD::SETCC: return LowerVSETCC(Op, DAG); |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 5049 | case ISD::BUILD_VECTOR: return LowerBUILD_VECTOR(Op, DAG, Subtarget); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5050 | case ISD::VECTOR_SHUFFLE: return LowerVECTOR_SHUFFLE(Op, DAG); |
Eli Friedman | 5c89cb8 | 2011-10-24 23:08:52 +0000 | [diff] [blame] | 5051 | case ISD::INSERT_VECTOR_ELT: return LowerINSERT_VECTOR_ELT(Op, DAG); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5052 | case ISD::EXTRACT_VECTOR_ELT: return LowerEXTRACT_VECTOR_ELT(Op, DAG); |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 5053 | case ISD::CONCAT_VECTORS: return LowerCONCAT_VECTORS(Op, DAG); |
Bob Wilson | b31a11b | 2010-08-20 04:54:02 +0000 | [diff] [blame] | 5054 | case ISD::FLT_ROUNDS_: return LowerFLT_ROUNDS_(Op, DAG); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 5055 | case ISD::MUL: return LowerMUL(Op, DAG); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5056 | case ISD::SDIV: return LowerSDIV(Op, DAG); |
| 5057 | case ISD::UDIV: return LowerUDIV(Op, DAG); |
Evan Cheng | 342e316 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 5058 | case ISD::ADDC: |
| 5059 | case ISD::ADDE: |
| 5060 | case ISD::SUBC: |
| 5061 | case ISD::SUBE: return LowerADDC_ADDE_SUBC_SUBE(Op, DAG); |
Eli Friedman | 7cc1566 | 2011-09-15 22:18:49 +0000 | [diff] [blame] | 5062 | case ISD::ATOMIC_LOAD: |
Eli Friedman | 74bf18c | 2011-09-15 22:26:18 +0000 | [diff] [blame] | 5063 | case ISD::ATOMIC_STORE: return LowerAtomicLoadStore(Op, DAG); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5064 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5065 | } |
| 5066 | |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 5067 | /// ReplaceNodeResults - Replace the results of node with an illegal result |
| 5068 | /// type with new values built out of custom code. |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 5069 | void ARMTargetLowering::ReplaceNodeResults(SDNode *N, |
| 5070 | SmallVectorImpl<SDValue>&Results, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 5071 | SelectionDAG &DAG) const { |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 5072 | SDValue Res; |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 5073 | switch (N->getOpcode()) { |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 5074 | default: |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 5075 | llvm_unreachable("Don't know how to custom expand this!"); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5076 | case ISD::BITCAST: |
| 5077 | Res = ExpandBITCAST(N, DAG); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 5078 | break; |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 5079 | case ISD::SRL: |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 5080 | case ISD::SRA: |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 5081 | Res = Expand64BitShift(N, DAG, Subtarget); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 5082 | break; |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5083 | case ISD::ATOMIC_LOAD_ADD: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5084 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMADD64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5085 | return; |
| 5086 | case ISD::ATOMIC_LOAD_AND: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5087 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMAND64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5088 | return; |
| 5089 | case ISD::ATOMIC_LOAD_NAND: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5090 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMNAND64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5091 | return; |
| 5092 | case ISD::ATOMIC_LOAD_OR: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5093 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMOR64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5094 | return; |
| 5095 | case ISD::ATOMIC_LOAD_SUB: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5096 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMSUB64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5097 | return; |
| 5098 | case ISD::ATOMIC_LOAD_XOR: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5099 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMXOR64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5100 | return; |
| 5101 | case ISD::ATOMIC_SWAP: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5102 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMSWAP64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5103 | return; |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5104 | case ISD::ATOMIC_CMP_SWAP: |
| 5105 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMCMPXCHG64_DAG); |
| 5106 | return; |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 5107 | } |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 5108 | if (Res.getNode()) |
| 5109 | Results.push_back(Res); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 5110 | } |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 5111 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5112 | //===----------------------------------------------------------------------===// |
| 5113 | // ARM Scheduler Hooks |
| 5114 | //===----------------------------------------------------------------------===// |
| 5115 | |
| 5116 | MachineBasicBlock * |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 5117 | ARMTargetLowering::EmitAtomicCmpSwap(MachineInstr *MI, |
| 5118 | MachineBasicBlock *BB, |
| 5119 | unsigned Size) const { |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5120 | unsigned dest = MI->getOperand(0).getReg(); |
| 5121 | unsigned ptr = MI->getOperand(1).getReg(); |
| 5122 | unsigned oldval = MI->getOperand(2).getReg(); |
| 5123 | unsigned newval = MI->getOperand(3).getReg(); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5124 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 5125 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5126 | bool isThumb2 = Subtarget->isThumb2(); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5127 | |
Cameron Zwarich | 7d336c0 | 2011-05-18 02:20:07 +0000 | [diff] [blame] | 5128 | MachineRegisterInfo &MRI = BB->getParent()->getRegInfo(); |
| 5129 | unsigned scratch = |
Cameron Zwarich | 141ec63 | 2011-05-18 02:29:50 +0000 | [diff] [blame] | 5130 | MRI.createVirtualRegister(isThumb2 ? ARM::rGPRRegisterClass |
Cameron Zwarich | 7d336c0 | 2011-05-18 02:20:07 +0000 | [diff] [blame] | 5131 | : ARM::GPRRegisterClass); |
| 5132 | |
| 5133 | if (isThumb2) { |
Cameron Zwarich | 141ec63 | 2011-05-18 02:29:50 +0000 | [diff] [blame] | 5134 | MRI.constrainRegClass(dest, ARM::rGPRRegisterClass); |
| 5135 | MRI.constrainRegClass(oldval, ARM::rGPRRegisterClass); |
| 5136 | MRI.constrainRegClass(newval, ARM::rGPRRegisterClass); |
Cameron Zwarich | 7d336c0 | 2011-05-18 02:20:07 +0000 | [diff] [blame] | 5137 | } |
| 5138 | |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5139 | unsigned ldrOpc, strOpc; |
| 5140 | switch (Size) { |
| 5141 | default: llvm_unreachable("unsupported size for AtomicCmpSwap!"); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5142 | case 1: |
| 5143 | ldrOpc = isThumb2 ? ARM::t2LDREXB : ARM::LDREXB; |
Evan Cheng | aa26102 | 2011-02-07 18:50:47 +0000 | [diff] [blame] | 5144 | strOpc = isThumb2 ? ARM::t2STREXB : ARM::STREXB; |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5145 | break; |
| 5146 | case 2: |
| 5147 | ldrOpc = isThumb2 ? ARM::t2LDREXH : ARM::LDREXH; |
| 5148 | strOpc = isThumb2 ? ARM::t2STREXH : ARM::STREXH; |
| 5149 | break; |
| 5150 | case 4: |
| 5151 | ldrOpc = isThumb2 ? ARM::t2LDREX : ARM::LDREX; |
| 5152 | strOpc = isThumb2 ? ARM::t2STREX : ARM::STREX; |
| 5153 | break; |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5154 | } |
| 5155 | |
| 5156 | MachineFunction *MF = BB->getParent(); |
| 5157 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 5158 | MachineFunction::iterator It = BB; |
| 5159 | ++It; // insert the new blocks after the current block |
| 5160 | |
| 5161 | MachineBasicBlock *loop1MBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5162 | MachineBasicBlock *loop2MBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5163 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5164 | MF->insert(It, loop1MBB); |
| 5165 | MF->insert(It, loop2MBB); |
| 5166 | MF->insert(It, exitMBB); |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 5167 | |
| 5168 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 5169 | exitMBB->splice(exitMBB->begin(), BB, |
| 5170 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 5171 | BB->end()); |
| 5172 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5173 | |
| 5174 | // thisMBB: |
| 5175 | // ... |
| 5176 | // fallthrough --> loop1MBB |
| 5177 | BB->addSuccessor(loop1MBB); |
| 5178 | |
| 5179 | // loop1MBB: |
| 5180 | // ldrex dest, [ptr] |
| 5181 | // cmp dest, oldval |
| 5182 | // bne exitMBB |
| 5183 | BB = loop1MBB; |
Jim Grosbach | b6aed50 | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 5184 | MachineInstrBuilder MIB = BuildMI(BB, dl, TII->get(ldrOpc), dest).addReg(ptr); |
| 5185 | if (ldrOpc == ARM::t2LDREX) |
| 5186 | MIB.addImm(0); |
| 5187 | AddDefaultPred(MIB); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5188 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5189 | .addReg(dest).addReg(oldval)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5190 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 5191 | .addMBB(exitMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5192 | BB->addSuccessor(loop2MBB); |
| 5193 | BB->addSuccessor(exitMBB); |
| 5194 | |
| 5195 | // loop2MBB: |
| 5196 | // strex scratch, newval, [ptr] |
| 5197 | // cmp scratch, #0 |
| 5198 | // bne loop1MBB |
| 5199 | BB = loop2MBB; |
Jim Grosbach | b6aed50 | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 5200 | MIB = BuildMI(BB, dl, TII->get(strOpc), scratch).addReg(newval).addReg(ptr); |
| 5201 | if (strOpc == ARM::t2STREX) |
| 5202 | MIB.addImm(0); |
| 5203 | AddDefaultPred(MIB); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5204 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5205 | .addReg(scratch).addImm(0)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5206 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 5207 | .addMBB(loop1MBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5208 | BB->addSuccessor(loop1MBB); |
| 5209 | BB->addSuccessor(exitMBB); |
| 5210 | |
| 5211 | // exitMBB: |
| 5212 | // ... |
| 5213 | BB = exitMBB; |
Jim Grosbach | 5efaed3 | 2010-01-15 00:18:34 +0000 | [diff] [blame] | 5214 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 5215 | MI->eraseFromParent(); // The instruction is gone now. |
Jim Grosbach | 5efaed3 | 2010-01-15 00:18:34 +0000 | [diff] [blame] | 5216 | |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5217 | return BB; |
| 5218 | } |
| 5219 | |
| 5220 | MachineBasicBlock * |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 5221 | ARMTargetLowering::EmitAtomicBinary(MachineInstr *MI, MachineBasicBlock *BB, |
| 5222 | unsigned Size, unsigned BinOpcode) const { |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5223 | // This also handles ATOMIC_SWAP, indicated by BinOpcode==0. |
| 5224 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 5225 | |
| 5226 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
Jim Grosbach | 867bbbf | 2010-01-15 00:22:18 +0000 | [diff] [blame] | 5227 | MachineFunction *MF = BB->getParent(); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5228 | MachineFunction::iterator It = BB; |
| 5229 | ++It; |
| 5230 | |
| 5231 | unsigned dest = MI->getOperand(0).getReg(); |
| 5232 | unsigned ptr = MI->getOperand(1).getReg(); |
| 5233 | unsigned incr = MI->getOperand(2).getReg(); |
| 5234 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5235 | bool isThumb2 = Subtarget->isThumb2(); |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 5236 | |
| 5237 | MachineRegisterInfo &MRI = BB->getParent()->getRegInfo(); |
| 5238 | if (isThumb2) { |
| 5239 | MRI.constrainRegClass(dest, ARM::rGPRRegisterClass); |
| 5240 | MRI.constrainRegClass(ptr, ARM::rGPRRegisterClass); |
| 5241 | } |
| 5242 | |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5243 | unsigned ldrOpc, strOpc; |
| 5244 | switch (Size) { |
| 5245 | default: llvm_unreachable("unsupported size for AtomicCmpSwap!"); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5246 | case 1: |
| 5247 | ldrOpc = isThumb2 ? ARM::t2LDREXB : ARM::LDREXB; |
Jakob Stoklund Olesen | 15913c9 | 2010-01-13 19:54:39 +0000 | [diff] [blame] | 5248 | strOpc = isThumb2 ? ARM::t2STREXB : ARM::STREXB; |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5249 | break; |
| 5250 | case 2: |
| 5251 | ldrOpc = isThumb2 ? ARM::t2LDREXH : ARM::LDREXH; |
| 5252 | strOpc = isThumb2 ? ARM::t2STREXH : ARM::STREXH; |
| 5253 | break; |
| 5254 | case 4: |
| 5255 | ldrOpc = isThumb2 ? ARM::t2LDREX : ARM::LDREX; |
| 5256 | strOpc = isThumb2 ? ARM::t2STREX : ARM::STREX; |
| 5257 | break; |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5258 | } |
| 5259 | |
Jim Grosbach | 867bbbf | 2010-01-15 00:22:18 +0000 | [diff] [blame] | 5260 | MachineBasicBlock *loopMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5261 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5262 | MF->insert(It, loopMBB); |
| 5263 | MF->insert(It, exitMBB); |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 5264 | |
| 5265 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 5266 | exitMBB->splice(exitMBB->begin(), BB, |
| 5267 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 5268 | BB->end()); |
| 5269 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5270 | |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 5271 | TargetRegisterClass *TRC = |
| 5272 | isThumb2 ? ARM::tGPRRegisterClass : ARM::GPRRegisterClass; |
| 5273 | unsigned scratch = MRI.createVirtualRegister(TRC); |
| 5274 | unsigned scratch2 = (!BinOpcode) ? incr : MRI.createVirtualRegister(TRC); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5275 | |
| 5276 | // thisMBB: |
| 5277 | // ... |
| 5278 | // fallthrough --> loopMBB |
| 5279 | BB->addSuccessor(loopMBB); |
| 5280 | |
| 5281 | // loopMBB: |
| 5282 | // ldrex dest, ptr |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5283 | // <binop> scratch2, dest, incr |
| 5284 | // strex scratch, scratch2, ptr |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5285 | // cmp scratch, #0 |
| 5286 | // bne- loopMBB |
| 5287 | // fallthrough --> exitMBB |
| 5288 | BB = loopMBB; |
Jim Grosbach | b6aed50 | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 5289 | MachineInstrBuilder MIB = BuildMI(BB, dl, TII->get(ldrOpc), dest).addReg(ptr); |
| 5290 | if (ldrOpc == ARM::t2LDREX) |
| 5291 | MIB.addImm(0); |
| 5292 | AddDefaultPred(MIB); |
Jim Grosbach | c67b556 | 2009-12-15 00:12:35 +0000 | [diff] [blame] | 5293 | if (BinOpcode) { |
| 5294 | // operand order needs to go the other way for NAND |
| 5295 | if (BinOpcode == ARM::BICrr || BinOpcode == ARM::t2BICrr) |
| 5296 | AddDefaultPred(BuildMI(BB, dl, TII->get(BinOpcode), scratch2). |
| 5297 | addReg(incr).addReg(dest)).addReg(0); |
| 5298 | else |
| 5299 | AddDefaultPred(BuildMI(BB, dl, TII->get(BinOpcode), scratch2). |
| 5300 | addReg(dest).addReg(incr)).addReg(0); |
| 5301 | } |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5302 | |
Jim Grosbach | b6aed50 | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 5303 | MIB = BuildMI(BB, dl, TII->get(strOpc), scratch).addReg(scratch2).addReg(ptr); |
| 5304 | if (strOpc == ARM::t2STREX) |
| 5305 | MIB.addImm(0); |
| 5306 | AddDefaultPred(MIB); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5307 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5308 | .addReg(scratch).addImm(0)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5309 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 5310 | .addMBB(loopMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5311 | |
| 5312 | BB->addSuccessor(loopMBB); |
| 5313 | BB->addSuccessor(exitMBB); |
| 5314 | |
| 5315 | // exitMBB: |
| 5316 | // ... |
| 5317 | BB = exitMBB; |
Evan Cheng | 102ebf1 | 2009-12-21 19:53:39 +0000 | [diff] [blame] | 5318 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 5319 | MI->eraseFromParent(); // The instruction is gone now. |
Evan Cheng | 102ebf1 | 2009-12-21 19:53:39 +0000 | [diff] [blame] | 5320 | |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5321 | return BB; |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 5322 | } |
| 5323 | |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5324 | MachineBasicBlock * |
| 5325 | ARMTargetLowering::EmitAtomicBinaryMinMax(MachineInstr *MI, |
| 5326 | MachineBasicBlock *BB, |
| 5327 | unsigned Size, |
| 5328 | bool signExtend, |
| 5329 | ARMCC::CondCodes Cond) const { |
| 5330 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 5331 | |
| 5332 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 5333 | MachineFunction *MF = BB->getParent(); |
| 5334 | MachineFunction::iterator It = BB; |
| 5335 | ++It; |
| 5336 | |
| 5337 | unsigned dest = MI->getOperand(0).getReg(); |
| 5338 | unsigned ptr = MI->getOperand(1).getReg(); |
| 5339 | unsigned incr = MI->getOperand(2).getReg(); |
| 5340 | unsigned oldval = dest; |
| 5341 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5342 | bool isThumb2 = Subtarget->isThumb2(); |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 5343 | |
| 5344 | MachineRegisterInfo &MRI = BB->getParent()->getRegInfo(); |
| 5345 | if (isThumb2) { |
| 5346 | MRI.constrainRegClass(dest, ARM::rGPRRegisterClass); |
| 5347 | MRI.constrainRegClass(ptr, ARM::rGPRRegisterClass); |
| 5348 | } |
| 5349 | |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5350 | unsigned ldrOpc, strOpc, extendOpc; |
| 5351 | switch (Size) { |
| 5352 | default: llvm_unreachable("unsupported size for AtomicCmpSwap!"); |
| 5353 | case 1: |
| 5354 | ldrOpc = isThumb2 ? ARM::t2LDREXB : ARM::LDREXB; |
| 5355 | strOpc = isThumb2 ? ARM::t2STREXB : ARM::STREXB; |
Jim Grosbach | c5a8c86 | 2011-07-27 16:47:19 +0000 | [diff] [blame] | 5356 | extendOpc = isThumb2 ? ARM::t2SXTB : ARM::SXTB; |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5357 | break; |
| 5358 | case 2: |
| 5359 | ldrOpc = isThumb2 ? ARM::t2LDREXH : ARM::LDREXH; |
| 5360 | strOpc = isThumb2 ? ARM::t2STREXH : ARM::STREXH; |
Jim Grosbach | c5a8c86 | 2011-07-27 16:47:19 +0000 | [diff] [blame] | 5361 | extendOpc = isThumb2 ? ARM::t2SXTH : ARM::SXTH; |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5362 | break; |
| 5363 | case 4: |
| 5364 | ldrOpc = isThumb2 ? ARM::t2LDREX : ARM::LDREX; |
| 5365 | strOpc = isThumb2 ? ARM::t2STREX : ARM::STREX; |
| 5366 | extendOpc = 0; |
| 5367 | break; |
| 5368 | } |
| 5369 | |
| 5370 | MachineBasicBlock *loopMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5371 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5372 | MF->insert(It, loopMBB); |
| 5373 | MF->insert(It, exitMBB); |
| 5374 | |
| 5375 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 5376 | exitMBB->splice(exitMBB->begin(), BB, |
| 5377 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 5378 | BB->end()); |
| 5379 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
| 5380 | |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 5381 | TargetRegisterClass *TRC = |
| 5382 | isThumb2 ? ARM::tGPRRegisterClass : ARM::GPRRegisterClass; |
| 5383 | unsigned scratch = MRI.createVirtualRegister(TRC); |
| 5384 | unsigned scratch2 = MRI.createVirtualRegister(TRC); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5385 | |
| 5386 | // thisMBB: |
| 5387 | // ... |
| 5388 | // fallthrough --> loopMBB |
| 5389 | BB->addSuccessor(loopMBB); |
| 5390 | |
| 5391 | // loopMBB: |
| 5392 | // ldrex dest, ptr |
| 5393 | // (sign extend dest, if required) |
| 5394 | // cmp dest, incr |
| 5395 | // cmov.cond scratch2, dest, incr |
| 5396 | // strex scratch, scratch2, ptr |
| 5397 | // cmp scratch, #0 |
| 5398 | // bne- loopMBB |
| 5399 | // fallthrough --> exitMBB |
| 5400 | BB = loopMBB; |
Jim Grosbach | b6aed50 | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 5401 | MachineInstrBuilder MIB = BuildMI(BB, dl, TII->get(ldrOpc), dest).addReg(ptr); |
| 5402 | if (ldrOpc == ARM::t2LDREX) |
| 5403 | MIB.addImm(0); |
| 5404 | AddDefaultPred(MIB); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5405 | |
| 5406 | // Sign extend the value, if necessary. |
| 5407 | if (signExtend && extendOpc) { |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 5408 | oldval = MRI.createVirtualRegister(ARM::GPRRegisterClass); |
Jim Grosbach | c5a8c86 | 2011-07-27 16:47:19 +0000 | [diff] [blame] | 5409 | AddDefaultPred(BuildMI(BB, dl, TII->get(extendOpc), oldval) |
| 5410 | .addReg(dest) |
| 5411 | .addImm(0)); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5412 | } |
| 5413 | |
| 5414 | // Build compare and cmov instructions. |
| 5415 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
| 5416 | .addReg(oldval).addReg(incr)); |
| 5417 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2MOVCCr : ARM::MOVCCr), scratch2) |
| 5418 | .addReg(oldval).addReg(incr).addImm(Cond).addReg(ARM::CPSR); |
| 5419 | |
Jim Grosbach | b6aed50 | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 5420 | MIB = BuildMI(BB, dl, TII->get(strOpc), scratch).addReg(scratch2).addReg(ptr); |
| 5421 | if (strOpc == ARM::t2STREX) |
| 5422 | MIB.addImm(0); |
| 5423 | AddDefaultPred(MIB); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5424 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 5425 | .addReg(scratch).addImm(0)); |
| 5426 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 5427 | .addMBB(loopMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
| 5428 | |
| 5429 | BB->addSuccessor(loopMBB); |
| 5430 | BB->addSuccessor(exitMBB); |
| 5431 | |
| 5432 | // exitMBB: |
| 5433 | // ... |
| 5434 | BB = exitMBB; |
| 5435 | |
| 5436 | MI->eraseFromParent(); // The instruction is gone now. |
| 5437 | |
| 5438 | return BB; |
| 5439 | } |
| 5440 | |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5441 | MachineBasicBlock * |
| 5442 | ARMTargetLowering::EmitAtomicBinary64(MachineInstr *MI, MachineBasicBlock *BB, |
| 5443 | unsigned Op1, unsigned Op2, |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5444 | bool NeedsCarry, bool IsCmpxchg) const { |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5445 | // This also handles ATOMIC_SWAP, indicated by Op1==0. |
| 5446 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 5447 | |
| 5448 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 5449 | MachineFunction *MF = BB->getParent(); |
| 5450 | MachineFunction::iterator It = BB; |
| 5451 | ++It; |
| 5452 | |
| 5453 | unsigned destlo = MI->getOperand(0).getReg(); |
| 5454 | unsigned desthi = MI->getOperand(1).getReg(); |
| 5455 | unsigned ptr = MI->getOperand(2).getReg(); |
| 5456 | unsigned vallo = MI->getOperand(3).getReg(); |
| 5457 | unsigned valhi = MI->getOperand(4).getReg(); |
| 5458 | DebugLoc dl = MI->getDebugLoc(); |
| 5459 | bool isThumb2 = Subtarget->isThumb2(); |
| 5460 | |
| 5461 | MachineRegisterInfo &MRI = BB->getParent()->getRegInfo(); |
| 5462 | if (isThumb2) { |
| 5463 | MRI.constrainRegClass(destlo, ARM::rGPRRegisterClass); |
| 5464 | MRI.constrainRegClass(desthi, ARM::rGPRRegisterClass); |
| 5465 | MRI.constrainRegClass(ptr, ARM::rGPRRegisterClass); |
| 5466 | } |
| 5467 | |
| 5468 | unsigned ldrOpc = isThumb2 ? ARM::t2LDREXD : ARM::LDREXD; |
| 5469 | unsigned strOpc = isThumb2 ? ARM::t2STREXD : ARM::STREXD; |
| 5470 | |
| 5471 | MachineBasicBlock *loopMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
Eli Friedman | 7df496d | 2011-09-01 22:27:41 +0000 | [diff] [blame] | 5472 | MachineBasicBlock *contBB = 0, *cont2BB = 0; |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5473 | if (IsCmpxchg) { |
| 5474 | contBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5475 | cont2BB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5476 | } |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5477 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5478 | MF->insert(It, loopMBB); |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5479 | if (IsCmpxchg) { |
| 5480 | MF->insert(It, contBB); |
| 5481 | MF->insert(It, cont2BB); |
| 5482 | } |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5483 | MF->insert(It, exitMBB); |
| 5484 | |
| 5485 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 5486 | exitMBB->splice(exitMBB->begin(), BB, |
| 5487 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 5488 | BB->end()); |
| 5489 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
| 5490 | |
| 5491 | TargetRegisterClass *TRC = |
| 5492 | isThumb2 ? ARM::tGPRRegisterClass : ARM::GPRRegisterClass; |
| 5493 | unsigned storesuccess = MRI.createVirtualRegister(TRC); |
| 5494 | |
| 5495 | // thisMBB: |
| 5496 | // ... |
| 5497 | // fallthrough --> loopMBB |
| 5498 | BB->addSuccessor(loopMBB); |
| 5499 | |
| 5500 | // loopMBB: |
| 5501 | // ldrexd r2, r3, ptr |
| 5502 | // <binopa> r0, r2, incr |
| 5503 | // <binopb> r1, r3, incr |
| 5504 | // strexd storesuccess, r0, r1, ptr |
| 5505 | // cmp storesuccess, #0 |
| 5506 | // bne- loopMBB |
| 5507 | // fallthrough --> exitMBB |
| 5508 | // |
| 5509 | // Note that the registers are explicitly specified because there is not any |
| 5510 | // way to force the register allocator to allocate a register pair. |
| 5511 | // |
Andrew Trick | 3af7a67 | 2011-09-20 03:06:13 +0000 | [diff] [blame] | 5512 | // FIXME: The hardcoded registers are not necessary for Thumb2, but we |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5513 | // need to properly enforce the restriction that the two output registers |
| 5514 | // for ldrexd must be different. |
| 5515 | BB = loopMBB; |
| 5516 | // Load |
| 5517 | AddDefaultPred(BuildMI(BB, dl, TII->get(ldrOpc)) |
| 5518 | .addReg(ARM::R2, RegState::Define) |
| 5519 | .addReg(ARM::R3, RegState::Define).addReg(ptr)); |
| 5520 | // Copy r2/r3 into dest. (This copy will normally be coalesced.) |
| 5521 | BuildMI(BB, dl, TII->get(TargetOpcode::COPY), destlo).addReg(ARM::R2); |
| 5522 | BuildMI(BB, dl, TII->get(TargetOpcode::COPY), desthi).addReg(ARM::R3); |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5523 | |
| 5524 | if (IsCmpxchg) { |
| 5525 | // Add early exit |
| 5526 | for (unsigned i = 0; i < 2; i++) { |
| 5527 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPrr : |
| 5528 | ARM::CMPrr)) |
| 5529 | .addReg(i == 0 ? destlo : desthi) |
| 5530 | .addReg(i == 0 ? vallo : valhi)); |
| 5531 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 5532 | .addMBB(exitMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
| 5533 | BB->addSuccessor(exitMBB); |
| 5534 | BB->addSuccessor(i == 0 ? contBB : cont2BB); |
| 5535 | BB = (i == 0 ? contBB : cont2BB); |
| 5536 | } |
| 5537 | |
| 5538 | // Copy to physregs for strexd |
| 5539 | unsigned setlo = MI->getOperand(5).getReg(); |
| 5540 | unsigned sethi = MI->getOperand(6).getReg(); |
| 5541 | BuildMI(BB, dl, TII->get(TargetOpcode::COPY), ARM::R0).addReg(setlo); |
| 5542 | BuildMI(BB, dl, TII->get(TargetOpcode::COPY), ARM::R1).addReg(sethi); |
| 5543 | } else if (Op1) { |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5544 | // Perform binary operation |
| 5545 | AddDefaultPred(BuildMI(BB, dl, TII->get(Op1), ARM::R0) |
| 5546 | .addReg(destlo).addReg(vallo)) |
| 5547 | .addReg(NeedsCarry ? ARM::CPSR : 0, getDefRegState(NeedsCarry)); |
| 5548 | AddDefaultPred(BuildMI(BB, dl, TII->get(Op2), ARM::R1) |
| 5549 | .addReg(desthi).addReg(valhi)).addReg(0); |
| 5550 | } else { |
| 5551 | // Copy to physregs for strexd |
| 5552 | BuildMI(BB, dl, TII->get(TargetOpcode::COPY), ARM::R0).addReg(vallo); |
| 5553 | BuildMI(BB, dl, TII->get(TargetOpcode::COPY), ARM::R1).addReg(valhi); |
| 5554 | } |
| 5555 | |
| 5556 | // Store |
| 5557 | AddDefaultPred(BuildMI(BB, dl, TII->get(strOpc), storesuccess) |
| 5558 | .addReg(ARM::R0).addReg(ARM::R1).addReg(ptr)); |
| 5559 | // Cmp+jump |
| 5560 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 5561 | .addReg(storesuccess).addImm(0)); |
| 5562 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 5563 | .addMBB(loopMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
| 5564 | |
| 5565 | BB->addSuccessor(loopMBB); |
| 5566 | BB->addSuccessor(exitMBB); |
| 5567 | |
| 5568 | // exitMBB: |
| 5569 | // ... |
| 5570 | BB = exitMBB; |
| 5571 | |
| 5572 | MI->eraseFromParent(); // The instruction is gone now. |
| 5573 | |
| 5574 | return BB; |
| 5575 | } |
| 5576 | |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 5577 | /// SetupEntryBlockForSjLj - Insert code into the entry block that creates and |
| 5578 | /// registers the function context. |
| 5579 | void ARMTargetLowering:: |
| 5580 | SetupEntryBlockForSjLj(MachineInstr *MI, MachineBasicBlock *MBB, |
| 5581 | MachineBasicBlock *DispatchBB, int FI) const { |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 5582 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 5583 | DebugLoc dl = MI->getDebugLoc(); |
| 5584 | MachineFunction *MF = MBB->getParent(); |
| 5585 | MachineRegisterInfo *MRI = &MF->getRegInfo(); |
| 5586 | MachineConstantPool *MCP = MF->getConstantPool(); |
| 5587 | ARMFunctionInfo *AFI = MF->getInfo<ARMFunctionInfo>(); |
| 5588 | const Function *F = MF->getFunction(); |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 5589 | |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 5590 | bool isThumb = Subtarget->isThumb(); |
Bill Wendling | ff4216a | 2011-10-03 22:44:15 +0000 | [diff] [blame] | 5591 | bool isThumb2 = Subtarget->isThumb2(); |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 5592 | |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 5593 | unsigned PCLabelId = AFI->createPICLabelUId(); |
Bill Wendling | ff4216a | 2011-10-03 22:44:15 +0000 | [diff] [blame] | 5594 | unsigned PCAdj = (isThumb || isThumb2) ? 4 : 8; |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 5595 | ARMConstantPoolValue *CPV = |
| 5596 | ARMConstantPoolMBB::Create(F->getContext(), DispatchBB, PCLabelId, PCAdj); |
| 5597 | unsigned CPI = MCP->getConstantPoolIndex(CPV, 4); |
| 5598 | |
| 5599 | const TargetRegisterClass *TRC = |
| 5600 | isThumb ? ARM::tGPRRegisterClass : ARM::GPRRegisterClass; |
| 5601 | |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 5602 | // Grab constant pool and fixed stack memory operands. |
| 5603 | MachineMemOperand *CPMMO = |
| 5604 | MF->getMachineMemOperand(MachinePointerInfo::getConstantPool(), |
| 5605 | MachineMemOperand::MOLoad, 4, 4); |
| 5606 | |
| 5607 | MachineMemOperand *FIMMOSt = |
| 5608 | MF->getMachineMemOperand(MachinePointerInfo::getFixedStack(FI), |
| 5609 | MachineMemOperand::MOStore, 4, 4); |
| 5610 | |
| 5611 | // Load the address of the dispatch MBB into the jump buffer. |
| 5612 | if (isThumb2) { |
| 5613 | // Incoming value: jbuf |
| 5614 | // ldr.n r5, LCPI1_1 |
| 5615 | // orr r5, r5, #1 |
| 5616 | // add r5, pc |
| 5617 | // str r5, [$jbuf, #+4] ; &jbuf[1] |
| 5618 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 5619 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::t2LDRpci), NewVReg1) |
| 5620 | .addConstantPoolIndex(CPI) |
| 5621 | .addMemOperand(CPMMO)); |
| 5622 | // Set the low bit because of thumb mode. |
| 5623 | unsigned NewVReg2 = MRI->createVirtualRegister(TRC); |
| 5624 | AddDefaultCC( |
| 5625 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::t2ORRri), NewVReg2) |
| 5626 | .addReg(NewVReg1, RegState::Kill) |
| 5627 | .addImm(0x01))); |
| 5628 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
| 5629 | BuildMI(*MBB, MI, dl, TII->get(ARM::tPICADD), NewVReg3) |
| 5630 | .addReg(NewVReg2, RegState::Kill) |
| 5631 | .addImm(PCLabelId); |
| 5632 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::t2STRi12)) |
| 5633 | .addReg(NewVReg3, RegState::Kill) |
| 5634 | .addFrameIndex(FI) |
| 5635 | .addImm(36) // &jbuf[1] :: pc |
| 5636 | .addMemOperand(FIMMOSt)); |
| 5637 | } else if (isThumb) { |
| 5638 | // Incoming value: jbuf |
| 5639 | // ldr.n r1, LCPI1_4 |
| 5640 | // add r1, pc |
| 5641 | // mov r2, #1 |
| 5642 | // orrs r1, r2 |
| 5643 | // add r2, $jbuf, #+4 ; &jbuf[1] |
| 5644 | // str r1, [r2] |
| 5645 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 5646 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tLDRpci), NewVReg1) |
| 5647 | .addConstantPoolIndex(CPI) |
| 5648 | .addMemOperand(CPMMO)); |
| 5649 | unsigned NewVReg2 = MRI->createVirtualRegister(TRC); |
| 5650 | BuildMI(*MBB, MI, dl, TII->get(ARM::tPICADD), NewVReg2) |
| 5651 | .addReg(NewVReg1, RegState::Kill) |
| 5652 | .addImm(PCLabelId); |
| 5653 | // Set the low bit because of thumb mode. |
| 5654 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
| 5655 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tMOVi8), NewVReg3) |
| 5656 | .addReg(ARM::CPSR, RegState::Define) |
| 5657 | .addImm(1)); |
| 5658 | unsigned NewVReg4 = MRI->createVirtualRegister(TRC); |
| 5659 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tORR), NewVReg4) |
| 5660 | .addReg(ARM::CPSR, RegState::Define) |
| 5661 | .addReg(NewVReg2, RegState::Kill) |
| 5662 | .addReg(NewVReg3, RegState::Kill)); |
| 5663 | unsigned NewVReg5 = MRI->createVirtualRegister(TRC); |
| 5664 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tADDrSPi), NewVReg5) |
| 5665 | .addFrameIndex(FI) |
| 5666 | .addImm(36)); // &jbuf[1] :: pc |
| 5667 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tSTRi)) |
| 5668 | .addReg(NewVReg4, RegState::Kill) |
| 5669 | .addReg(NewVReg5, RegState::Kill) |
| 5670 | .addImm(0) |
| 5671 | .addMemOperand(FIMMOSt)); |
| 5672 | } else { |
| 5673 | // Incoming value: jbuf |
| 5674 | // ldr r1, LCPI1_1 |
| 5675 | // add r1, pc, r1 |
| 5676 | // str r1, [$jbuf, #+4] ; &jbuf[1] |
| 5677 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 5678 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::LDRi12), NewVReg1) |
| 5679 | .addConstantPoolIndex(CPI) |
| 5680 | .addImm(0) |
| 5681 | .addMemOperand(CPMMO)); |
| 5682 | unsigned NewVReg2 = MRI->createVirtualRegister(TRC); |
| 5683 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::PICADD), NewVReg2) |
| 5684 | .addReg(NewVReg1, RegState::Kill) |
| 5685 | .addImm(PCLabelId)); |
| 5686 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::STRi12)) |
| 5687 | .addReg(NewVReg2, RegState::Kill) |
| 5688 | .addFrameIndex(FI) |
| 5689 | .addImm(36) // &jbuf[1] :: pc |
| 5690 | .addMemOperand(FIMMOSt)); |
| 5691 | } |
| 5692 | } |
| 5693 | |
| 5694 | MachineBasicBlock *ARMTargetLowering:: |
| 5695 | EmitSjLjDispatchBlock(MachineInstr *MI, MachineBasicBlock *MBB) const { |
| 5696 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 5697 | DebugLoc dl = MI->getDebugLoc(); |
| 5698 | MachineFunction *MF = MBB->getParent(); |
| 5699 | MachineRegisterInfo *MRI = &MF->getRegInfo(); |
| 5700 | ARMFunctionInfo *AFI = MF->getInfo<ARMFunctionInfo>(); |
| 5701 | MachineFrameInfo *MFI = MF->getFrameInfo(); |
| 5702 | int FI = MFI->getFunctionContextIndex(); |
| 5703 | |
| 5704 | const TargetRegisterClass *TRC = |
| 5705 | Subtarget->isThumb() ? ARM::tGPRRegisterClass : ARM::GPRRegisterClass; |
| 5706 | |
Bill Wendling | 04f15b4 | 2011-10-06 21:29:56 +0000 | [diff] [blame] | 5707 | // Get a mapping of the call site numbers to all of the landing pads they're |
| 5708 | // associated with. |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 5709 | DenseMap<unsigned, SmallVector<MachineBasicBlock*, 2> > CallSiteNumToLPad; |
| 5710 | unsigned MaxCSNum = 0; |
| 5711 | MachineModuleInfo &MMI = MF->getMMI(); |
| 5712 | for (MachineFunction::iterator BB = MF->begin(), E = MF->end(); BB != E; ++BB) { |
| 5713 | if (!BB->isLandingPad()) continue; |
| 5714 | |
| 5715 | // FIXME: We should assert that the EH_LABEL is the first MI in the landing |
| 5716 | // pad. |
| 5717 | for (MachineBasicBlock::iterator |
| 5718 | II = BB->begin(), IE = BB->end(); II != IE; ++II) { |
| 5719 | if (!II->isEHLabel()) continue; |
| 5720 | |
| 5721 | MCSymbol *Sym = II->getOperand(0).getMCSymbol(); |
Bill Wendling | 5cbef19 | 2011-10-05 23:28:57 +0000 | [diff] [blame] | 5722 | if (!MMI.hasCallSiteLandingPad(Sym)) continue; |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 5723 | |
Bill Wendling | 5cbef19 | 2011-10-05 23:28:57 +0000 | [diff] [blame] | 5724 | SmallVectorImpl<unsigned> &CallSiteIdxs = MMI.getCallSiteLandingPad(Sym); |
| 5725 | for (SmallVectorImpl<unsigned>::iterator |
| 5726 | CSI = CallSiteIdxs.begin(), CSE = CallSiteIdxs.end(); |
| 5727 | CSI != CSE; ++CSI) { |
| 5728 | CallSiteNumToLPad[*CSI].push_back(BB); |
| 5729 | MaxCSNum = std::max(MaxCSNum, *CSI); |
| 5730 | } |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 5731 | break; |
| 5732 | } |
| 5733 | } |
| 5734 | |
| 5735 | // Get an ordered list of the machine basic blocks for the jump table. |
| 5736 | std::vector<MachineBasicBlock*> LPadList; |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 5737 | SmallPtrSet<MachineBasicBlock*, 64> InvokeBBs; |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 5738 | LPadList.reserve(CallSiteNumToLPad.size()); |
| 5739 | for (unsigned I = 1; I <= MaxCSNum; ++I) { |
| 5740 | SmallVectorImpl<MachineBasicBlock*> &MBBList = CallSiteNumToLPad[I]; |
| 5741 | for (SmallVectorImpl<MachineBasicBlock*>::iterator |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 5742 | II = MBBList.begin(), IE = MBBList.end(); II != IE; ++II) { |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 5743 | LPadList.push_back(*II); |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 5744 | InvokeBBs.insert((*II)->pred_begin(), (*II)->pred_end()); |
| 5745 | } |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 5746 | } |
| 5747 | |
Bill Wendling | 5cbef19 | 2011-10-05 23:28:57 +0000 | [diff] [blame] | 5748 | assert(!LPadList.empty() && |
| 5749 | "No landing pad destinations for the dispatch jump table!"); |
| 5750 | |
Bill Wendling | 04f15b4 | 2011-10-06 21:29:56 +0000 | [diff] [blame] | 5751 | // Create the jump table and associated information. |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 5752 | MachineJumpTableInfo *JTI = |
| 5753 | MF->getOrCreateJumpTableInfo(MachineJumpTableInfo::EK_Inline); |
| 5754 | unsigned MJTI = JTI->createJumpTableIndex(LPadList); |
| 5755 | unsigned UId = AFI->createJumpTableUId(); |
| 5756 | |
Bill Wendling | 04f15b4 | 2011-10-06 21:29:56 +0000 | [diff] [blame] | 5757 | // Create the MBBs for the dispatch code. |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 5758 | |
| 5759 | // Shove the dispatch's address into the return slot in the function context. |
| 5760 | MachineBasicBlock *DispatchBB = MF->CreateMachineBasicBlock(); |
| 5761 | DispatchBB->setIsLandingPad(); |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 5762 | |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 5763 | MachineBasicBlock *TrapBB = MF->CreateMachineBasicBlock(); |
Bill Wendling | 083a8eb | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 5764 | BuildMI(TrapBB, dl, TII->get(Subtarget->isThumb() ? ARM::tTRAP : ARM::TRAP)); |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 5765 | DispatchBB->addSuccessor(TrapBB); |
| 5766 | |
| 5767 | MachineBasicBlock *DispContBB = MF->CreateMachineBasicBlock(); |
| 5768 | DispatchBB->addSuccessor(DispContBB); |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 5769 | |
Bill Wendling | a48ed4f | 2011-10-17 21:32:56 +0000 | [diff] [blame] | 5770 | // Insert and MBBs. |
Bill Wendling | 930193c | 2011-10-06 00:53:33 +0000 | [diff] [blame] | 5771 | MF->insert(MF->end(), DispatchBB); |
| 5772 | MF->insert(MF->end(), DispContBB); |
| 5773 | MF->insert(MF->end(), TrapBB); |
Bill Wendling | 930193c | 2011-10-06 00:53:33 +0000 | [diff] [blame] | 5774 | |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 5775 | // Insert code into the entry block that creates and registers the function |
| 5776 | // context. |
| 5777 | SetupEntryBlockForSjLj(MI, MBB, DispatchBB, FI); |
| 5778 | |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 5779 | MachineMemOperand *FIMMOLd = |
Bill Wendling | 04f15b4 | 2011-10-06 21:29:56 +0000 | [diff] [blame] | 5780 | MF->getMachineMemOperand(MachinePointerInfo::getFixedStack(FI), |
Bill Wendling | 083a8eb | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 5781 | MachineMemOperand::MOLoad | |
| 5782 | MachineMemOperand::MOVolatile, 4, 4); |
Bill Wendling | 930193c | 2011-10-06 00:53:33 +0000 | [diff] [blame] | 5783 | |
Bob Wilson | f4aea8f | 2011-12-22 23:39:48 +0000 | [diff] [blame] | 5784 | if (AFI->isThumb1OnlyFunction()) |
| 5785 | BuildMI(DispatchBB, dl, TII->get(ARM::tInt_eh_sjlj_dispatchsetup)); |
| 5786 | else if (!Subtarget->hasVFP2()) |
| 5787 | BuildMI(DispatchBB, dl, TII->get(ARM::Int_eh_sjlj_dispatchsetup_nofp)); |
| 5788 | else |
| 5789 | BuildMI(DispatchBB, dl, TII->get(ARM::Int_eh_sjlj_dispatchsetup)); |
Bob Wilson | eaab6ef | 2011-11-16 07:11:57 +0000 | [diff] [blame] | 5790 | |
Bill Wendling | 952cb50 | 2011-10-18 22:49:07 +0000 | [diff] [blame] | 5791 | unsigned NumLPads = LPadList.size(); |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 5792 | if (Subtarget->isThumb2()) { |
| 5793 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 5794 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2LDRi12), NewVReg1) |
| 5795 | .addFrameIndex(FI) |
| 5796 | .addImm(4) |
| 5797 | .addMemOperand(FIMMOLd)); |
Bill Wendling | b9fecf4 | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 5798 | |
Bill Wendling | 952cb50 | 2011-10-18 22:49:07 +0000 | [diff] [blame] | 5799 | if (NumLPads < 256) { |
| 5800 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2CMPri)) |
| 5801 | .addReg(NewVReg1) |
| 5802 | .addImm(LPadList.size())); |
| 5803 | } else { |
| 5804 | unsigned VReg1 = MRI->createVirtualRegister(TRC); |
| 5805 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2MOVi16), VReg1) |
Bill Wendling | 15a1a22 | 2011-10-18 23:19:55 +0000 | [diff] [blame] | 5806 | .addImm(NumLPads & 0xFFFF)); |
| 5807 | |
| 5808 | unsigned VReg2 = VReg1; |
| 5809 | if ((NumLPads & 0xFFFF0000) != 0) { |
| 5810 | VReg2 = MRI->createVirtualRegister(TRC); |
| 5811 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2MOVTi16), VReg2) |
| 5812 | .addReg(VReg1) |
| 5813 | .addImm(NumLPads >> 16)); |
| 5814 | } |
| 5815 | |
Bill Wendling | 952cb50 | 2011-10-18 22:49:07 +0000 | [diff] [blame] | 5816 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2CMPrr)) |
| 5817 | .addReg(NewVReg1) |
| 5818 | .addReg(VReg2)); |
| 5819 | } |
Bill Wendling | b9fecf4 | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 5820 | |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 5821 | BuildMI(DispatchBB, dl, TII->get(ARM::t2Bcc)) |
| 5822 | .addMBB(TrapBB) |
| 5823 | .addImm(ARMCC::HI) |
| 5824 | .addReg(ARM::CPSR); |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 5825 | |
Bill Wendling | b9fecf4 | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 5826 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
| 5827 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::t2LEApcrelJT),NewVReg3) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 5828 | .addJumpTableIndex(MJTI) |
| 5829 | .addImm(UId)); |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 5830 | |
Bill Wendling | b9fecf4 | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 5831 | unsigned NewVReg4 = MRI->createVirtualRegister(TRC); |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 5832 | AddDefaultCC( |
| 5833 | AddDefaultPred( |
Bill Wendling | b9fecf4 | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 5834 | BuildMI(DispContBB, dl, TII->get(ARM::t2ADDrs), NewVReg4) |
| 5835 | .addReg(NewVReg3, RegState::Kill) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 5836 | .addReg(NewVReg1) |
| 5837 | .addImm(ARM_AM::getSORegOpc(ARM_AM::lsl, 2)))); |
| 5838 | |
| 5839 | BuildMI(DispContBB, dl, TII->get(ARM::t2BR_JT)) |
Bill Wendling | b9fecf4 | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 5840 | .addReg(NewVReg4, RegState::Kill) |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 5841 | .addReg(NewVReg1) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 5842 | .addJumpTableIndex(MJTI) |
| 5843 | .addImm(UId); |
| 5844 | } else if (Subtarget->isThumb()) { |
Bill Wendling | 083a8eb | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 5845 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 5846 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::tLDRspi), NewVReg1) |
| 5847 | .addFrameIndex(FI) |
| 5848 | .addImm(1) |
| 5849 | .addMemOperand(FIMMOLd)); |
Bill Wendling | f1083d4 | 2011-10-07 22:08:37 +0000 | [diff] [blame] | 5850 | |
Bill Wendling | a5871dc | 2011-10-18 23:11:05 +0000 | [diff] [blame] | 5851 | if (NumLPads < 256) { |
| 5852 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::tCMPi8)) |
| 5853 | .addReg(NewVReg1) |
| 5854 | .addImm(NumLPads)); |
| 5855 | } else { |
| 5856 | MachineConstantPool *ConstantPool = MF->getConstantPool(); |
Bill Wendling | 922ad78 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 5857 | Type *Int32Ty = Type::getInt32Ty(MF->getFunction()->getContext()); |
| 5858 | const Constant *C = ConstantInt::get(Int32Ty, NumLPads); |
| 5859 | |
| 5860 | // MachineConstantPool wants an explicit alignment. |
| 5861 | unsigned Align = getTargetData()->getPrefTypeAlignment(Int32Ty); |
| 5862 | if (Align == 0) |
| 5863 | Align = getTargetData()->getTypeAllocSize(C->getType()); |
| 5864 | unsigned Idx = ConstantPool->getConstantPoolIndex(C, Align); |
Bill Wendling | a5871dc | 2011-10-18 23:11:05 +0000 | [diff] [blame] | 5865 | |
| 5866 | unsigned VReg1 = MRI->createVirtualRegister(TRC); |
| 5867 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::tLDRpci)) |
| 5868 | .addReg(VReg1, RegState::Define) |
| 5869 | .addConstantPoolIndex(Idx)); |
| 5870 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::tCMPr)) |
| 5871 | .addReg(NewVReg1) |
| 5872 | .addReg(VReg1)); |
| 5873 | } |
| 5874 | |
Bill Wendling | 083a8eb | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 5875 | BuildMI(DispatchBB, dl, TII->get(ARM::tBcc)) |
| 5876 | .addMBB(TrapBB) |
| 5877 | .addImm(ARMCC::HI) |
| 5878 | .addReg(ARM::CPSR); |
| 5879 | |
| 5880 | unsigned NewVReg2 = MRI->createVirtualRegister(TRC); |
| 5881 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tLSLri), NewVReg2) |
| 5882 | .addReg(ARM::CPSR, RegState::Define) |
| 5883 | .addReg(NewVReg1) |
| 5884 | .addImm(2)); |
| 5885 | |
| 5886 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
Bill Wendling | 217f0e9 | 2011-10-06 23:41:14 +0000 | [diff] [blame] | 5887 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tLEApcrelJT), NewVReg3) |
Bill Wendling | 083a8eb | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 5888 | .addJumpTableIndex(MJTI) |
| 5889 | .addImm(UId)); |
| 5890 | |
| 5891 | unsigned NewVReg4 = MRI->createVirtualRegister(TRC); |
| 5892 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tADDrr), NewVReg4) |
| 5893 | .addReg(ARM::CPSR, RegState::Define) |
| 5894 | .addReg(NewVReg2, RegState::Kill) |
| 5895 | .addReg(NewVReg3)); |
| 5896 | |
| 5897 | MachineMemOperand *JTMMOLd = |
| 5898 | MF->getMachineMemOperand(MachinePointerInfo::getJumpTable(), |
| 5899 | MachineMemOperand::MOLoad, 4, 4); |
| 5900 | |
| 5901 | unsigned NewVReg5 = MRI->createVirtualRegister(TRC); |
| 5902 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tLDRi), NewVReg5) |
| 5903 | .addReg(NewVReg4, RegState::Kill) |
| 5904 | .addImm(0) |
| 5905 | .addMemOperand(JTMMOLd)); |
| 5906 | |
| 5907 | unsigned NewVReg6 = MRI->createVirtualRegister(TRC); |
| 5908 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tADDrr), NewVReg6) |
| 5909 | .addReg(ARM::CPSR, RegState::Define) |
| 5910 | .addReg(NewVReg5, RegState::Kill) |
| 5911 | .addReg(NewVReg3)); |
| 5912 | |
| 5913 | BuildMI(DispContBB, dl, TII->get(ARM::tBR_JTr)) |
| 5914 | .addReg(NewVReg6, RegState::Kill) |
| 5915 | .addJumpTableIndex(MJTI) |
| 5916 | .addImm(UId); |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 5917 | } else { |
| 5918 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 5919 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::LDRi12), NewVReg1) |
| 5920 | .addFrameIndex(FI) |
| 5921 | .addImm(4) |
| 5922 | .addMemOperand(FIMMOLd)); |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 5923 | |
Bill Wendling | 85f3a0a | 2011-10-18 22:52:20 +0000 | [diff] [blame] | 5924 | if (NumLPads < 256) { |
| 5925 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::CMPri)) |
| 5926 | .addReg(NewVReg1) |
| 5927 | .addImm(NumLPads)); |
Bill Wendling | 922ad78 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 5928 | } else if (Subtarget->hasV6T2Ops() && isUInt<16>(NumLPads)) { |
Bill Wendling | 85f3a0a | 2011-10-18 22:52:20 +0000 | [diff] [blame] | 5929 | unsigned VReg1 = MRI->createVirtualRegister(TRC); |
| 5930 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::MOVi16), VReg1) |
Bill Wendling | 15a1a22 | 2011-10-18 23:19:55 +0000 | [diff] [blame] | 5931 | .addImm(NumLPads & 0xFFFF)); |
| 5932 | |
| 5933 | unsigned VReg2 = VReg1; |
| 5934 | if ((NumLPads & 0xFFFF0000) != 0) { |
| 5935 | VReg2 = MRI->createVirtualRegister(TRC); |
| 5936 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::MOVTi16), VReg2) |
| 5937 | .addReg(VReg1) |
| 5938 | .addImm(NumLPads >> 16)); |
| 5939 | } |
| 5940 | |
Bill Wendling | 85f3a0a | 2011-10-18 22:52:20 +0000 | [diff] [blame] | 5941 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::CMPrr)) |
| 5942 | .addReg(NewVReg1) |
| 5943 | .addReg(VReg2)); |
Bill Wendling | 922ad78 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 5944 | } else { |
| 5945 | MachineConstantPool *ConstantPool = MF->getConstantPool(); |
| 5946 | Type *Int32Ty = Type::getInt32Ty(MF->getFunction()->getContext()); |
| 5947 | const Constant *C = ConstantInt::get(Int32Ty, NumLPads); |
| 5948 | |
| 5949 | // MachineConstantPool wants an explicit alignment. |
| 5950 | unsigned Align = getTargetData()->getPrefTypeAlignment(Int32Ty); |
| 5951 | if (Align == 0) |
| 5952 | Align = getTargetData()->getTypeAllocSize(C->getType()); |
| 5953 | unsigned Idx = ConstantPool->getConstantPoolIndex(C, Align); |
| 5954 | |
| 5955 | unsigned VReg1 = MRI->createVirtualRegister(TRC); |
| 5956 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::LDRcp)) |
| 5957 | .addReg(VReg1, RegState::Define) |
Bill Wendling | 767f8be | 2011-10-20 20:37:11 +0000 | [diff] [blame] | 5958 | .addConstantPoolIndex(Idx) |
| 5959 | .addImm(0)); |
Bill Wendling | 922ad78 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 5960 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::CMPrr)) |
| 5961 | .addReg(NewVReg1) |
| 5962 | .addReg(VReg1, RegState::Kill)); |
Bill Wendling | 85f3a0a | 2011-10-18 22:52:20 +0000 | [diff] [blame] | 5963 | } |
| 5964 | |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 5965 | BuildMI(DispatchBB, dl, TII->get(ARM::Bcc)) |
| 5966 | .addMBB(TrapBB) |
| 5967 | .addImm(ARMCC::HI) |
| 5968 | .addReg(ARM::CPSR); |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 5969 | |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 5970 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 5971 | AddDefaultCC( |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 5972 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::MOVsi), NewVReg3) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 5973 | .addReg(NewVReg1) |
| 5974 | .addImm(ARM_AM::getSORegOpc(ARM_AM::lsl, 2)))); |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 5975 | unsigned NewVReg4 = MRI->createVirtualRegister(TRC); |
| 5976 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::LEApcrelJT), NewVReg4) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 5977 | .addJumpTableIndex(MJTI) |
| 5978 | .addImm(UId)); |
| 5979 | |
| 5980 | MachineMemOperand *JTMMOLd = |
| 5981 | MF->getMachineMemOperand(MachinePointerInfo::getJumpTable(), |
| 5982 | MachineMemOperand::MOLoad, 4, 4); |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 5983 | unsigned NewVReg5 = MRI->createVirtualRegister(TRC); |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 5984 | AddDefaultPred( |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 5985 | BuildMI(DispContBB, dl, TII->get(ARM::LDRrs), NewVReg5) |
| 5986 | .addReg(NewVReg3, RegState::Kill) |
| 5987 | .addReg(NewVReg4) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 5988 | .addImm(0) |
| 5989 | .addMemOperand(JTMMOLd)); |
| 5990 | |
| 5991 | BuildMI(DispContBB, dl, TII->get(ARM::BR_JTadd)) |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 5992 | .addReg(NewVReg5, RegState::Kill) |
| 5993 | .addReg(NewVReg4) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 5994 | .addJumpTableIndex(MJTI) |
| 5995 | .addImm(UId); |
| 5996 | } |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 5997 | |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 5998 | // Add the jump table entries as successors to the MBB. |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 5999 | MachineBasicBlock *PrevMBB = 0; |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 6000 | for (std::vector<MachineBasicBlock*>::iterator |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6001 | I = LPadList.begin(), E = LPadList.end(); I != E; ++I) { |
| 6002 | MachineBasicBlock *CurMBB = *I; |
| 6003 | if (PrevMBB != CurMBB) |
| 6004 | DispContBB->addSuccessor(CurMBB); |
| 6005 | PrevMBB = CurMBB; |
| 6006 | } |
| 6007 | |
Bill Wendling | 24bb925 | 2011-10-17 05:25:09 +0000 | [diff] [blame] | 6008 | // 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] | 6009 | const ARMBaseInstrInfo *AII = static_cast<const ARMBaseInstrInfo*>(TII); |
| 6010 | const ARMBaseRegisterInfo &RI = AII->getRegisterInfo(); |
| 6011 | const unsigned *SavedRegs = RI.getCalleeSavedRegs(MF); |
Bill Wendling | f7b0207 | 2011-10-18 18:30:49 +0000 | [diff] [blame] | 6012 | SmallVector<MachineBasicBlock*, 64> MBBLPads; |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6013 | for (SmallPtrSet<MachineBasicBlock*, 64>::iterator |
| 6014 | I = InvokeBBs.begin(), E = InvokeBBs.end(); I != E; ++I) { |
| 6015 | MachineBasicBlock *BB = *I; |
Bill Wendling | 969c9ef | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 6016 | |
| 6017 | // Remove the landing pad successor from the invoke block and replace it |
| 6018 | // with the new dispatch block. |
Bill Wendling | de39d86 | 2011-10-26 07:16:18 +0000 | [diff] [blame] | 6019 | SmallVector<MachineBasicBlock*, 4> Successors(BB->succ_begin(), |
| 6020 | BB->succ_end()); |
| 6021 | while (!Successors.empty()) { |
| 6022 | MachineBasicBlock *SMBB = Successors.pop_back_val(); |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6023 | if (SMBB->isLandingPad()) { |
| 6024 | BB->removeSuccessor(SMBB); |
Bill Wendling | f7b0207 | 2011-10-18 18:30:49 +0000 | [diff] [blame] | 6025 | MBBLPads.push_back(SMBB); |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6026 | } |
| 6027 | } |
| 6028 | |
| 6029 | BB->addSuccessor(DispatchBB); |
Bill Wendling | 969c9ef | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 6030 | |
| 6031 | // Find the invoke call and mark all of the callee-saved registers as |
| 6032 | // 'implicit defined' so that they're spilled. This prevents code from |
| 6033 | // moving instructions to before the EH block, where they will never be |
| 6034 | // executed. |
| 6035 | for (MachineBasicBlock::reverse_iterator |
| 6036 | II = BB->rbegin(), IE = BB->rend(); II != IE; ++II) { |
Evan Cheng | 5a96b3d | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 6037 | if (!II->isCall()) continue; |
Bill Wendling | 969c9ef | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 6038 | |
| 6039 | DenseMap<unsigned, bool> DefRegs; |
| 6040 | for (MachineInstr::mop_iterator |
| 6041 | OI = II->operands_begin(), OE = II->operands_end(); |
| 6042 | OI != OE; ++OI) { |
| 6043 | if (!OI->isReg()) continue; |
| 6044 | DefRegs[OI->getReg()] = true; |
| 6045 | } |
| 6046 | |
| 6047 | MachineInstrBuilder MIB(&*II); |
| 6048 | |
Bill Wendling | 5d79859 | 2011-10-14 23:55:44 +0000 | [diff] [blame] | 6049 | for (unsigned i = 0; SavedRegs[i] != 0; ++i) { |
Bill Wendling | b8dcb31 | 2011-10-22 00:29:28 +0000 | [diff] [blame] | 6050 | unsigned Reg = SavedRegs[i]; |
| 6051 | if (Subtarget->isThumb2() && |
| 6052 | !ARM::tGPRRegisterClass->contains(Reg) && |
| 6053 | !ARM::hGPRRegisterClass->contains(Reg)) |
| 6054 | continue; |
| 6055 | else if (Subtarget->isThumb1Only() && |
| 6056 | !ARM::tGPRRegisterClass->contains(Reg)) |
| 6057 | continue; |
| 6058 | else if (!Subtarget->isThumb() && |
| 6059 | !ARM::GPRRegisterClass->contains(Reg)) |
| 6060 | continue; |
| 6061 | if (!DefRegs[Reg]) |
| 6062 | MIB.addReg(Reg, RegState::ImplicitDefine | RegState::Dead); |
Bill Wendling | 5d79859 | 2011-10-14 23:55:44 +0000 | [diff] [blame] | 6063 | } |
Bill Wendling | 969c9ef | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 6064 | |
| 6065 | break; |
| 6066 | } |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6067 | } |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 6068 | |
Bill Wendling | f7b0207 | 2011-10-18 18:30:49 +0000 | [diff] [blame] | 6069 | // Mark all former landing pads as non-landing pads. The dispatch is the only |
| 6070 | // landing pad now. |
| 6071 | for (SmallVectorImpl<MachineBasicBlock*>::iterator |
| 6072 | I = MBBLPads.begin(), E = MBBLPads.end(); I != E; ++I) |
| 6073 | (*I)->setIsLandingPad(false); |
| 6074 | |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 6075 | // The instruction is gone now. |
| 6076 | MI->eraseFromParent(); |
| 6077 | |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 6078 | return MBB; |
| 6079 | } |
| 6080 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 6081 | static |
| 6082 | MachineBasicBlock *OtherSucc(MachineBasicBlock *MBB, MachineBasicBlock *Succ) { |
| 6083 | for (MachineBasicBlock::succ_iterator I = MBB->succ_begin(), |
| 6084 | E = MBB->succ_end(); I != E; ++I) |
| 6085 | if (*I != Succ) |
| 6086 | return *I; |
| 6087 | llvm_unreachable("Expecting a BB with two successors!"); |
| 6088 | } |
| 6089 | |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 6090 | MachineBasicBlock * |
Evan Cheng | ff9b373 | 2008-01-30 18:18:23 +0000 | [diff] [blame] | 6091 | ARMTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI, |
Dan Gohman | af1d8ca | 2010-05-01 00:01:06 +0000 | [diff] [blame] | 6092 | MachineBasicBlock *BB) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6093 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
Dale Johannesen | b672840 | 2009-02-13 02:25:56 +0000 | [diff] [blame] | 6094 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6095 | bool isThumb2 = Subtarget->isThumb2(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6096 | switch (MI->getOpcode()) { |
Andrew Trick | 1c3af77 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 6097 | default: { |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 6098 | MI->dump(); |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 6099 | llvm_unreachable("Unexpected instr type to insert"); |
Andrew Trick | 1c3af77 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 6100 | } |
Jim Grosbach | ee2c2a4 | 2011-09-16 21:55:56 +0000 | [diff] [blame] | 6101 | // The Thumb2 pre-indexed stores have the same MI operands, they just |
| 6102 | // define them differently in the .td files from the isel patterns, so |
| 6103 | // they need pseudos. |
| 6104 | case ARM::t2STR_preidx: |
| 6105 | MI->setDesc(TII->get(ARM::t2STR_PRE)); |
| 6106 | return BB; |
| 6107 | case ARM::t2STRB_preidx: |
| 6108 | MI->setDesc(TII->get(ARM::t2STRB_PRE)); |
| 6109 | return BB; |
| 6110 | case ARM::t2STRH_preidx: |
| 6111 | MI->setDesc(TII->get(ARM::t2STRH_PRE)); |
| 6112 | return BB; |
| 6113 | |
Jim Grosbach | 19dec20 | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 6114 | case ARM::STRi_preidx: |
| 6115 | case ARM::STRBi_preidx: { |
Jim Grosbach | 6cd5716 | 2011-08-09 21:22:41 +0000 | [diff] [blame] | 6116 | unsigned NewOpc = MI->getOpcode() == ARM::STRi_preidx ? |
Jim Grosbach | 19dec20 | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 6117 | ARM::STR_PRE_IMM : ARM::STRB_PRE_IMM; |
| 6118 | // Decode the offset. |
| 6119 | unsigned Offset = MI->getOperand(4).getImm(); |
| 6120 | bool isSub = ARM_AM::getAM2Op(Offset) == ARM_AM::sub; |
| 6121 | Offset = ARM_AM::getAM2Offset(Offset); |
| 6122 | if (isSub) |
| 6123 | Offset = -Offset; |
| 6124 | |
Jim Grosbach | 4dfe220 | 2011-08-12 21:02:34 +0000 | [diff] [blame] | 6125 | MachineMemOperand *MMO = *MI->memoperands_begin(); |
Benjamin Kramer | 2753ae3 | 2011-08-27 17:36:14 +0000 | [diff] [blame] | 6126 | BuildMI(*BB, MI, dl, TII->get(NewOpc)) |
Jim Grosbach | 19dec20 | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 6127 | .addOperand(MI->getOperand(0)) // Rn_wb |
| 6128 | .addOperand(MI->getOperand(1)) // Rt |
| 6129 | .addOperand(MI->getOperand(2)) // Rn |
| 6130 | .addImm(Offset) // offset (skip GPR==zero_reg) |
| 6131 | .addOperand(MI->getOperand(5)) // pred |
Jim Grosbach | 4dfe220 | 2011-08-12 21:02:34 +0000 | [diff] [blame] | 6132 | .addOperand(MI->getOperand(6)) |
| 6133 | .addMemOperand(MMO); |
Jim Grosbach | 19dec20 | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 6134 | MI->eraseFromParent(); |
| 6135 | return BB; |
| 6136 | } |
| 6137 | case ARM::STRr_preidx: |
Jim Grosbach | 7b8f46c | 2011-08-11 21:17:22 +0000 | [diff] [blame] | 6138 | case ARM::STRBr_preidx: |
| 6139 | case ARM::STRH_preidx: { |
| 6140 | unsigned NewOpc; |
| 6141 | switch (MI->getOpcode()) { |
| 6142 | default: llvm_unreachable("unexpected opcode!"); |
| 6143 | case ARM::STRr_preidx: NewOpc = ARM::STR_PRE_REG; break; |
| 6144 | case ARM::STRBr_preidx: NewOpc = ARM::STRB_PRE_REG; break; |
| 6145 | case ARM::STRH_preidx: NewOpc = ARM::STRH_PRE; break; |
| 6146 | } |
Jim Grosbach | 19dec20 | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 6147 | MachineInstrBuilder MIB = BuildMI(*BB, MI, dl, TII->get(NewOpc)); |
| 6148 | for (unsigned i = 0; i < MI->getNumOperands(); ++i) |
| 6149 | MIB.addOperand(MI->getOperand(i)); |
| 6150 | MI->eraseFromParent(); |
| 6151 | return BB; |
| 6152 | } |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6153 | case ARM::ATOMIC_LOAD_ADD_I8: |
| 6154 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr); |
| 6155 | case ARM::ATOMIC_LOAD_ADD_I16: |
| 6156 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr); |
| 6157 | case ARM::ATOMIC_LOAD_ADD_I32: |
| 6158 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 6159 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6160 | case ARM::ATOMIC_LOAD_AND_I8: |
| 6161 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
| 6162 | case ARM::ATOMIC_LOAD_AND_I16: |
| 6163 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
| 6164 | case ARM::ATOMIC_LOAD_AND_I32: |
| 6165 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 6166 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6167 | case ARM::ATOMIC_LOAD_OR_I8: |
| 6168 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
| 6169 | case ARM::ATOMIC_LOAD_OR_I16: |
| 6170 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
| 6171 | case ARM::ATOMIC_LOAD_OR_I32: |
| 6172 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 6173 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6174 | case ARM::ATOMIC_LOAD_XOR_I8: |
| 6175 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
| 6176 | case ARM::ATOMIC_LOAD_XOR_I16: |
| 6177 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
| 6178 | case ARM::ATOMIC_LOAD_XOR_I32: |
| 6179 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 6180 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6181 | case ARM::ATOMIC_LOAD_NAND_I8: |
| 6182 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2BICrr : ARM::BICrr); |
| 6183 | case ARM::ATOMIC_LOAD_NAND_I16: |
| 6184 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2BICrr : ARM::BICrr); |
| 6185 | case ARM::ATOMIC_LOAD_NAND_I32: |
| 6186 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2BICrr : ARM::BICrr); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 6187 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6188 | case ARM::ATOMIC_LOAD_SUB_I8: |
| 6189 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr); |
| 6190 | case ARM::ATOMIC_LOAD_SUB_I16: |
| 6191 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr); |
| 6192 | case ARM::ATOMIC_LOAD_SUB_I32: |
| 6193 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 6194 | |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 6195 | case ARM::ATOMIC_LOAD_MIN_I8: |
| 6196 | return EmitAtomicBinaryMinMax(MI, BB, 1, true, ARMCC::LT); |
| 6197 | case ARM::ATOMIC_LOAD_MIN_I16: |
| 6198 | return EmitAtomicBinaryMinMax(MI, BB, 2, true, ARMCC::LT); |
| 6199 | case ARM::ATOMIC_LOAD_MIN_I32: |
| 6200 | return EmitAtomicBinaryMinMax(MI, BB, 4, true, ARMCC::LT); |
| 6201 | |
| 6202 | case ARM::ATOMIC_LOAD_MAX_I8: |
| 6203 | return EmitAtomicBinaryMinMax(MI, BB, 1, true, ARMCC::GT); |
| 6204 | case ARM::ATOMIC_LOAD_MAX_I16: |
| 6205 | return EmitAtomicBinaryMinMax(MI, BB, 2, true, ARMCC::GT); |
| 6206 | case ARM::ATOMIC_LOAD_MAX_I32: |
| 6207 | return EmitAtomicBinaryMinMax(MI, BB, 4, true, ARMCC::GT); |
| 6208 | |
| 6209 | case ARM::ATOMIC_LOAD_UMIN_I8: |
| 6210 | return EmitAtomicBinaryMinMax(MI, BB, 1, false, ARMCC::LO); |
| 6211 | case ARM::ATOMIC_LOAD_UMIN_I16: |
| 6212 | return EmitAtomicBinaryMinMax(MI, BB, 2, false, ARMCC::LO); |
| 6213 | case ARM::ATOMIC_LOAD_UMIN_I32: |
| 6214 | return EmitAtomicBinaryMinMax(MI, BB, 4, false, ARMCC::LO); |
| 6215 | |
| 6216 | case ARM::ATOMIC_LOAD_UMAX_I8: |
| 6217 | return EmitAtomicBinaryMinMax(MI, BB, 1, false, ARMCC::HI); |
| 6218 | case ARM::ATOMIC_LOAD_UMAX_I16: |
| 6219 | return EmitAtomicBinaryMinMax(MI, BB, 2, false, ARMCC::HI); |
| 6220 | case ARM::ATOMIC_LOAD_UMAX_I32: |
| 6221 | return EmitAtomicBinaryMinMax(MI, BB, 4, false, ARMCC::HI); |
| 6222 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6223 | case ARM::ATOMIC_SWAP_I8: return EmitAtomicBinary(MI, BB, 1, 0); |
| 6224 | case ARM::ATOMIC_SWAP_I16: return EmitAtomicBinary(MI, BB, 2, 0); |
| 6225 | case ARM::ATOMIC_SWAP_I32: return EmitAtomicBinary(MI, BB, 4, 0); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 6226 | |
| 6227 | case ARM::ATOMIC_CMP_SWAP_I8: return EmitAtomicCmpSwap(MI, BB, 1); |
| 6228 | case ARM::ATOMIC_CMP_SWAP_I16: return EmitAtomicCmpSwap(MI, BB, 2); |
| 6229 | case ARM::ATOMIC_CMP_SWAP_I32: return EmitAtomicCmpSwap(MI, BB, 4); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 6230 | |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6231 | |
| 6232 | case ARM::ATOMADD6432: |
| 6233 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr, |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 6234 | isThumb2 ? ARM::t2ADCrr : ARM::ADCrr, |
| 6235 | /*NeedsCarry*/ true); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6236 | case ARM::ATOMSUB6432: |
| 6237 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr, |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 6238 | isThumb2 ? ARM::t2SBCrr : ARM::SBCrr, |
| 6239 | /*NeedsCarry*/ true); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6240 | case ARM::ATOMOR6432: |
| 6241 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr, |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 6242 | isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6243 | case ARM::ATOMXOR6432: |
| 6244 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2EORrr : ARM::EORrr, |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 6245 | isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6246 | case ARM::ATOMAND6432: |
| 6247 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr, |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 6248 | isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6249 | case ARM::ATOMSWAP6432: |
| 6250 | return EmitAtomicBinary64(MI, BB, 0, 0, false); |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 6251 | case ARM::ATOMCMPXCHG6432: |
| 6252 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr, |
| 6253 | isThumb2 ? ARM::t2SBCrr : ARM::SBCrr, |
| 6254 | /*NeedsCarry*/ false, /*IsCmpxchg*/true); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6255 | |
Evan Cheng | 007ea27 | 2009-08-12 05:17:19 +0000 | [diff] [blame] | 6256 | case ARM::tMOVCCr_pseudo: { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6257 | // To "insert" a SELECT_CC instruction, we actually have to insert the |
| 6258 | // diamond control-flow pattern. The incoming instruction knows the |
| 6259 | // destination vreg to set, the condition code register to branch on, the |
| 6260 | // true/false values to select between, and a branch opcode to use. |
| 6261 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 6262 | MachineFunction::iterator It = BB; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6263 | ++It; |
| 6264 | |
| 6265 | // thisMBB: |
| 6266 | // ... |
| 6267 | // TrueVal = ... |
| 6268 | // cmpTY ccX, r1, r2 |
| 6269 | // bCC copy1MBB |
| 6270 | // fallthrough --> copy0MBB |
| 6271 | MachineBasicBlock *thisMBB = BB; |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 6272 | MachineFunction *F = BB->getParent(); |
| 6273 | MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB); |
| 6274 | MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB); |
Dan Gohman | 258c58c | 2010-07-06 15:49:48 +0000 | [diff] [blame] | 6275 | F->insert(It, copy0MBB); |
| 6276 | F->insert(It, sinkMBB); |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 6277 | |
| 6278 | // Transfer the remainder of BB and its successor edges to sinkMBB. |
| 6279 | sinkMBB->splice(sinkMBB->begin(), BB, |
| 6280 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 6281 | BB->end()); |
| 6282 | sinkMBB->transferSuccessorsAndUpdatePHIs(BB); |
| 6283 | |
Dan Gohman | 258c58c | 2010-07-06 15:49:48 +0000 | [diff] [blame] | 6284 | BB->addSuccessor(copy0MBB); |
| 6285 | BB->addSuccessor(sinkMBB); |
Dan Gohman | b81c771 | 2010-07-06 15:18:19 +0000 | [diff] [blame] | 6286 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 6287 | BuildMI(BB, dl, TII->get(ARM::tBcc)).addMBB(sinkMBB) |
| 6288 | .addImm(MI->getOperand(3).getImm()).addReg(MI->getOperand(4).getReg()); |
| 6289 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6290 | // copy0MBB: |
| 6291 | // %FalseValue = ... |
| 6292 | // # fallthrough to sinkMBB |
| 6293 | BB = copy0MBB; |
| 6294 | |
| 6295 | // Update machine-CFG edges |
| 6296 | BB->addSuccessor(sinkMBB); |
| 6297 | |
| 6298 | // sinkMBB: |
| 6299 | // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ] |
| 6300 | // ... |
| 6301 | BB = sinkMBB; |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 6302 | BuildMI(*BB, BB->begin(), dl, |
| 6303 | TII->get(ARM::PHI), MI->getOperand(0).getReg()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6304 | .addReg(MI->getOperand(1).getReg()).addMBB(copy0MBB) |
| 6305 | .addReg(MI->getOperand(2).getReg()).addMBB(thisMBB); |
| 6306 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 6307 | MI->eraseFromParent(); // The pseudo instruction is gone now. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6308 | return BB; |
| 6309 | } |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 6310 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 6311 | case ARM::BCCi64: |
| 6312 | case ARM::BCCZi64: { |
Bob Wilson | 3c90469 | 2010-12-23 22:45:49 +0000 | [diff] [blame] | 6313 | // If there is an unconditional branch to the other successor, remove it. |
| 6314 | BB->erase(llvm::next(MachineBasicBlock::iterator(MI)), BB->end()); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 6315 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 6316 | // Compare both parts that make up the double comparison separately for |
| 6317 | // equality. |
| 6318 | bool RHSisZero = MI->getOpcode() == ARM::BCCZi64; |
| 6319 | |
| 6320 | unsigned LHS1 = MI->getOperand(1).getReg(); |
| 6321 | unsigned LHS2 = MI->getOperand(2).getReg(); |
| 6322 | if (RHSisZero) { |
| 6323 | AddDefaultPred(BuildMI(BB, dl, |
| 6324 | TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 6325 | .addReg(LHS1).addImm(0)); |
| 6326 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 6327 | .addReg(LHS2).addImm(0) |
| 6328 | .addImm(ARMCC::EQ).addReg(ARM::CPSR); |
| 6329 | } else { |
| 6330 | unsigned RHS1 = MI->getOperand(3).getReg(); |
| 6331 | unsigned RHS2 = MI->getOperand(4).getReg(); |
| 6332 | AddDefaultPred(BuildMI(BB, dl, |
| 6333 | TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
| 6334 | .addReg(LHS1).addReg(RHS1)); |
| 6335 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
| 6336 | .addReg(LHS2).addReg(RHS2) |
| 6337 | .addImm(ARMCC::EQ).addReg(ARM::CPSR); |
| 6338 | } |
| 6339 | |
| 6340 | MachineBasicBlock *destMBB = MI->getOperand(RHSisZero ? 3 : 5).getMBB(); |
| 6341 | MachineBasicBlock *exitMBB = OtherSucc(BB, destMBB); |
| 6342 | if (MI->getOperand(0).getImm() == ARMCC::NE) |
| 6343 | std::swap(destMBB, exitMBB); |
| 6344 | |
| 6345 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 6346 | .addMBB(destMBB).addImm(ARMCC::EQ).addReg(ARM::CPSR); |
Owen Anderson | 51f6a7a | 2011-09-09 21:48:23 +0000 | [diff] [blame] | 6347 | if (isThumb2) |
| 6348 | AddDefaultPred(BuildMI(BB, dl, TII->get(ARM::t2B)).addMBB(exitMBB)); |
| 6349 | else |
| 6350 | BuildMI(BB, dl, TII->get(ARM::B)) .addMBB(exitMBB); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 6351 | |
| 6352 | MI->eraseFromParent(); // The pseudo instruction is gone now. |
| 6353 | return BB; |
| 6354 | } |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 6355 | |
Bill Wendling | 5bc8528 | 2011-10-17 20:37:20 +0000 | [diff] [blame] | 6356 | case ARM::Int_eh_sjlj_setjmp: |
| 6357 | case ARM::Int_eh_sjlj_setjmp_nofp: |
| 6358 | case ARM::tInt_eh_sjlj_setjmp: |
| 6359 | case ARM::t2Int_eh_sjlj_setjmp: |
| 6360 | case ARM::t2Int_eh_sjlj_setjmp_nofp: |
| 6361 | EmitSjLjDispatchBlock(MI, BB); |
| 6362 | return BB; |
| 6363 | |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 6364 | case ARM::ABS: |
| 6365 | case ARM::t2ABS: { |
| 6366 | // To insert an ABS instruction, we have to insert the |
| 6367 | // diamond control-flow pattern. The incoming instruction knows the |
| 6368 | // source vreg to test against 0, the destination vreg to set, |
| 6369 | // the condition code register to branch on, the |
Andrew Trick | 7f5f0da | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 6370 | // true/false values to select between, and a branch opcode to use. |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 6371 | // It transforms |
| 6372 | // V1 = ABS V0 |
| 6373 | // into |
| 6374 | // V2 = MOVS V0 |
| 6375 | // BCC (branch to SinkBB if V0 >= 0) |
| 6376 | // RSBBB: V3 = RSBri V2, 0 (compute ABS if V2 < 0) |
Andrew Trick | 7f5f0da | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 6377 | // SinkBB: V1 = PHI(V2, V3) |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 6378 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 6379 | MachineFunction::iterator BBI = BB; |
| 6380 | ++BBI; |
| 6381 | MachineFunction *Fn = BB->getParent(); |
| 6382 | MachineBasicBlock *RSBBB = Fn->CreateMachineBasicBlock(LLVM_BB); |
| 6383 | MachineBasicBlock *SinkBB = Fn->CreateMachineBasicBlock(LLVM_BB); |
| 6384 | Fn->insert(BBI, RSBBB); |
| 6385 | Fn->insert(BBI, SinkBB); |
| 6386 | |
| 6387 | unsigned int ABSSrcReg = MI->getOperand(1).getReg(); |
| 6388 | unsigned int ABSDstReg = MI->getOperand(0).getReg(); |
| 6389 | bool isThumb2 = Subtarget->isThumb2(); |
| 6390 | MachineRegisterInfo &MRI = Fn->getRegInfo(); |
| 6391 | // In Thumb mode S must not be specified if source register is the SP or |
| 6392 | // PC and if destination register is the SP, so restrict register class |
| 6393 | unsigned NewMovDstReg = MRI.createVirtualRegister( |
| 6394 | isThumb2 ? ARM::rGPRRegisterClass : ARM::GPRRegisterClass); |
| 6395 | unsigned NewRsbDstReg = MRI.createVirtualRegister( |
| 6396 | isThumb2 ? ARM::rGPRRegisterClass : ARM::GPRRegisterClass); |
| 6397 | |
| 6398 | // Transfer the remainder of BB and its successor edges to sinkMBB. |
| 6399 | SinkBB->splice(SinkBB->begin(), BB, |
| 6400 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 6401 | BB->end()); |
| 6402 | SinkBB->transferSuccessorsAndUpdatePHIs(BB); |
| 6403 | |
| 6404 | BB->addSuccessor(RSBBB); |
| 6405 | BB->addSuccessor(SinkBB); |
| 6406 | |
| 6407 | // fall through to SinkMBB |
| 6408 | RSBBB->addSuccessor(SinkBB); |
| 6409 | |
| 6410 | // insert a movs at the end of BB |
| 6411 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2MOVr : ARM::MOVr), |
| 6412 | NewMovDstReg) |
| 6413 | .addReg(ABSSrcReg, RegState::Kill) |
| 6414 | .addImm((unsigned)ARMCC::AL).addReg(0) |
| 6415 | .addReg(ARM::CPSR, RegState::Define); |
| 6416 | |
| 6417 | // 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] | 6418 | BuildMI(BB, dl, |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 6419 | TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)).addMBB(SinkBB) |
| 6420 | .addImm(ARMCC::getOppositeCondition(ARMCC::MI)).addReg(ARM::CPSR); |
| 6421 | |
| 6422 | // insert rsbri in RSBBB |
| 6423 | // Note: BCC and rsbri will be converted into predicated rsbmi |
| 6424 | // by if-conversion pass |
Andrew Trick | 7f5f0da | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 6425 | BuildMI(*RSBBB, RSBBB->begin(), dl, |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 6426 | TII->get(isThumb2 ? ARM::t2RSBri : ARM::RSBri), NewRsbDstReg) |
| 6427 | .addReg(NewMovDstReg, RegState::Kill) |
| 6428 | .addImm(0).addImm((unsigned)ARMCC::AL).addReg(0).addReg(0); |
| 6429 | |
Andrew Trick | 7f5f0da | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 6430 | // insert PHI in SinkBB, |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 6431 | // reuse ABSDstReg to not change uses of ABS instruction |
| 6432 | BuildMI(*SinkBB, SinkBB->begin(), dl, |
| 6433 | TII->get(ARM::PHI), ABSDstReg) |
| 6434 | .addReg(NewRsbDstReg).addMBB(RSBBB) |
| 6435 | .addReg(NewMovDstReg).addMBB(BB); |
| 6436 | |
| 6437 | // remove ABS instruction |
Andrew Trick | 7f5f0da | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 6438 | MI->eraseFromParent(); |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 6439 | |
| 6440 | // return last added BB |
| 6441 | return SinkBB; |
| 6442 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6443 | } |
| 6444 | } |
| 6445 | |
Evan Cheng | 37fefc2 | 2011-08-30 19:09:48 +0000 | [diff] [blame] | 6446 | void ARMTargetLowering::AdjustInstrPostInstrSelection(MachineInstr *MI, |
| 6447 | SDNode *Node) const { |
Evan Cheng | 5a96b3d | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 6448 | if (!MI->hasPostISelHook()) { |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 6449 | assert(!convertAddSubFlagsOpcode(MI->getOpcode()) && |
| 6450 | "Pseudo flag-setting opcodes must be marked with 'hasPostISelHook'"); |
| 6451 | return; |
| 6452 | } |
| 6453 | |
Evan Cheng | 5a96b3d | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 6454 | const MCInstrDesc *MCID = &MI->getDesc(); |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6455 | // Adjust potentially 's' setting instructions after isel, i.e. ADC, SBC, RSB, |
| 6456 | // RSC. Coming out of isel, they have an implicit CPSR def, but the optional |
| 6457 | // operand is still set to noreg. If needed, set the optional operand's |
| 6458 | // register to CPSR, and remove the redundant implicit def. |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 6459 | // |
Andrew Trick | 90b7b12 | 2011-10-18 19:18:52 +0000 | [diff] [blame] | 6460 | // e.g. ADCS (..., CPSR<imp-def>) -> ADC (... opt:CPSR<def>). |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6461 | |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 6462 | // Rename pseudo opcodes. |
| 6463 | unsigned NewOpc = convertAddSubFlagsOpcode(MI->getOpcode()); |
| 6464 | if (NewOpc) { |
| 6465 | const ARMBaseInstrInfo *TII = |
| 6466 | static_cast<const ARMBaseInstrInfo*>(getTargetMachine().getInstrInfo()); |
Andrew Trick | 90b7b12 | 2011-10-18 19:18:52 +0000 | [diff] [blame] | 6467 | MCID = &TII->get(NewOpc); |
| 6468 | |
| 6469 | assert(MCID->getNumOperands() == MI->getDesc().getNumOperands() + 1 && |
| 6470 | "converted opcode should be the same except for cc_out"); |
| 6471 | |
| 6472 | MI->setDesc(*MCID); |
| 6473 | |
| 6474 | // Add the optional cc_out operand |
| 6475 | MI->addOperand(MachineOperand::CreateReg(0, /*isDef=*/true)); |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 6476 | } |
Andrew Trick | 90b7b12 | 2011-10-18 19:18:52 +0000 | [diff] [blame] | 6477 | unsigned ccOutIdx = MCID->getNumOperands() - 1; |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6478 | |
| 6479 | // Any ARM instruction that sets the 's' bit should specify an optional |
| 6480 | // "cc_out" operand in the last operand position. |
Evan Cheng | 5a96b3d | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 6481 | if (!MI->hasOptionalDef() || !MCID->OpInfo[ccOutIdx].isOptionalDef()) { |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 6482 | assert(!NewOpc && "Optional cc_out operand required"); |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6483 | return; |
| 6484 | } |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 6485 | // Look for an implicit def of CPSR added by MachineInstr ctor. Remove it |
| 6486 | // since we already have an optional CPSR def. |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6487 | bool definesCPSR = false; |
| 6488 | bool deadCPSR = false; |
Andrew Trick | 90b7b12 | 2011-10-18 19:18:52 +0000 | [diff] [blame] | 6489 | for (unsigned i = MCID->getNumOperands(), e = MI->getNumOperands(); |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6490 | i != e; ++i) { |
| 6491 | const MachineOperand &MO = MI->getOperand(i); |
| 6492 | if (MO.isReg() && MO.isDef() && MO.getReg() == ARM::CPSR) { |
| 6493 | definesCPSR = true; |
| 6494 | if (MO.isDead()) |
| 6495 | deadCPSR = true; |
| 6496 | MI->RemoveOperand(i); |
| 6497 | break; |
Evan Cheng | 37fefc2 | 2011-08-30 19:09:48 +0000 | [diff] [blame] | 6498 | } |
| 6499 | } |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6500 | if (!definesCPSR) { |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 6501 | assert(!NewOpc && "Optional cc_out operand required"); |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6502 | return; |
| 6503 | } |
| 6504 | assert(deadCPSR == !Node->hasAnyUseOfValue(1) && "inconsistent dead flag"); |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 6505 | if (deadCPSR) { |
| 6506 | assert(!MI->getOperand(ccOutIdx).getReg() && |
| 6507 | "expect uninitialized optional cc_out operand"); |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6508 | return; |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 6509 | } |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6510 | |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 6511 | // If this instruction was defined with an optional CPSR def and its dag node |
| 6512 | // had a live implicit CPSR def, then activate the optional CPSR def. |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 6513 | MachineOperand &MO = MI->getOperand(ccOutIdx); |
| 6514 | MO.setReg(ARM::CPSR); |
| 6515 | MO.setIsDef(true); |
Evan Cheng | 37fefc2 | 2011-08-30 19:09:48 +0000 | [diff] [blame] | 6516 | } |
| 6517 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6518 | //===----------------------------------------------------------------------===// |
| 6519 | // ARM Optimization Hooks |
| 6520 | //===----------------------------------------------------------------------===// |
| 6521 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 6522 | static |
| 6523 | SDValue combineSelectAndUse(SDNode *N, SDValue Slct, SDValue OtherOp, |
| 6524 | TargetLowering::DAGCombinerInfo &DCI) { |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 6525 | SelectionDAG &DAG = DCI.DAG; |
| 6526 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6527 | EVT VT = N->getValueType(0); |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 6528 | unsigned Opc = N->getOpcode(); |
| 6529 | bool isSlctCC = Slct.getOpcode() == ISD::SELECT_CC; |
| 6530 | SDValue LHS = isSlctCC ? Slct.getOperand(2) : Slct.getOperand(1); |
| 6531 | SDValue RHS = isSlctCC ? Slct.getOperand(3) : Slct.getOperand(2); |
| 6532 | ISD::CondCode CC = ISD::SETCC_INVALID; |
| 6533 | |
| 6534 | if (isSlctCC) { |
| 6535 | CC = cast<CondCodeSDNode>(Slct.getOperand(4))->get(); |
| 6536 | } else { |
| 6537 | SDValue CCOp = Slct.getOperand(0); |
| 6538 | if (CCOp.getOpcode() == ISD::SETCC) |
| 6539 | CC = cast<CondCodeSDNode>(CCOp.getOperand(2))->get(); |
| 6540 | } |
| 6541 | |
| 6542 | bool DoXform = false; |
| 6543 | bool InvCC = false; |
| 6544 | assert ((Opc == ISD::ADD || (Opc == ISD::SUB && Slct == N->getOperand(1))) && |
| 6545 | "Bad input!"); |
| 6546 | |
| 6547 | if (LHS.getOpcode() == ISD::Constant && |
| 6548 | cast<ConstantSDNode>(LHS)->isNullValue()) { |
| 6549 | DoXform = true; |
| 6550 | } else if (CC != ISD::SETCC_INVALID && |
| 6551 | RHS.getOpcode() == ISD::Constant && |
| 6552 | cast<ConstantSDNode>(RHS)->isNullValue()) { |
| 6553 | std::swap(LHS, RHS); |
| 6554 | SDValue Op0 = Slct.getOperand(0); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6555 | EVT OpVT = isSlctCC ? Op0.getValueType() : |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 6556 | Op0.getOperand(0).getValueType(); |
| 6557 | bool isInt = OpVT.isInteger(); |
| 6558 | CC = ISD::getSetCCInverse(CC, isInt); |
| 6559 | |
| 6560 | if (!TLI.isCondCodeLegal(CC, OpVT)) |
| 6561 | return SDValue(); // Inverse operator isn't legal. |
| 6562 | |
| 6563 | DoXform = true; |
| 6564 | InvCC = true; |
| 6565 | } |
| 6566 | |
| 6567 | if (DoXform) { |
| 6568 | SDValue Result = DAG.getNode(Opc, RHS.getDebugLoc(), VT, OtherOp, RHS); |
| 6569 | if (isSlctCC) |
| 6570 | return DAG.getSelectCC(N->getDebugLoc(), OtherOp, Result, |
| 6571 | Slct.getOperand(0), Slct.getOperand(1), CC); |
| 6572 | SDValue CCOp = Slct.getOperand(0); |
| 6573 | if (InvCC) |
| 6574 | CCOp = DAG.getSetCC(Slct.getDebugLoc(), CCOp.getValueType(), |
| 6575 | CCOp.getOperand(0), CCOp.getOperand(1), CC); |
| 6576 | return DAG.getNode(ISD::SELECT, N->getDebugLoc(), VT, |
| 6577 | CCOp, OtherOp, Result); |
| 6578 | } |
| 6579 | return SDValue(); |
| 6580 | } |
| 6581 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 6582 | // AddCombineToVPADDL- For pair-wise add on neon, use the vpaddl instruction |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6583 | // (only after legalization). |
| 6584 | static SDValue AddCombineToVPADDL(SDNode *N, SDValue N0, SDValue N1, |
| 6585 | TargetLowering::DAGCombinerInfo &DCI, |
| 6586 | const ARMSubtarget *Subtarget) { |
| 6587 | |
| 6588 | // Only perform optimization if after legalize, and if NEON is available. We |
| 6589 | // also expected both operands to be BUILD_VECTORs. |
| 6590 | if (DCI.isBeforeLegalize() || !Subtarget->hasNEON() |
| 6591 | || N0.getOpcode() != ISD::BUILD_VECTOR |
| 6592 | || N1.getOpcode() != ISD::BUILD_VECTOR) |
| 6593 | return SDValue(); |
| 6594 | |
| 6595 | // Check output type since VPADDL operand elements can only be 8, 16, or 32. |
| 6596 | EVT VT = N->getValueType(0); |
| 6597 | if (!VT.isInteger() || VT.getVectorElementType() == MVT::i64) |
| 6598 | return SDValue(); |
| 6599 | |
| 6600 | // Check that the vector operands are of the right form. |
| 6601 | // N0 and N1 are BUILD_VECTOR nodes with N number of EXTRACT_VECTOR |
| 6602 | // operands, where N is the size of the formed vector. |
| 6603 | // Each EXTRACT_VECTOR should have the same input vector and odd or even |
| 6604 | // index such that we have a pair wise add pattern. |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6605 | |
| 6606 | // Grab the vector that all EXTRACT_VECTOR nodes should be referencing. |
Bob Wilson | 7a10ab7 | 2011-06-15 06:04:34 +0000 | [diff] [blame] | 6607 | if (N0->getOperand(0)->getOpcode() != ISD::EXTRACT_VECTOR_ELT) |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6608 | return SDValue(); |
Bob Wilson | 7a10ab7 | 2011-06-15 06:04:34 +0000 | [diff] [blame] | 6609 | SDValue Vec = N0->getOperand(0)->getOperand(0); |
| 6610 | SDNode *V = Vec.getNode(); |
| 6611 | unsigned nextIndex = 0; |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6612 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 6613 | // For each operands to the ADD which are BUILD_VECTORs, |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6614 | // check to see if each of their operands are an EXTRACT_VECTOR with |
| 6615 | // the same vector and appropriate index. |
| 6616 | for (unsigned i = 0, e = N0->getNumOperands(); i != e; ++i) { |
| 6617 | if (N0->getOperand(i)->getOpcode() == ISD::EXTRACT_VECTOR_ELT |
| 6618 | && N1->getOperand(i)->getOpcode() == ISD::EXTRACT_VECTOR_ELT) { |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 6619 | |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6620 | SDValue ExtVec0 = N0->getOperand(i); |
| 6621 | SDValue ExtVec1 = N1->getOperand(i); |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 6622 | |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6623 | // First operand is the vector, verify its the same. |
| 6624 | if (V != ExtVec0->getOperand(0).getNode() || |
| 6625 | V != ExtVec1->getOperand(0).getNode()) |
| 6626 | return SDValue(); |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 6627 | |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6628 | // Second is the constant, verify its correct. |
| 6629 | ConstantSDNode *C0 = dyn_cast<ConstantSDNode>(ExtVec0->getOperand(1)); |
| 6630 | ConstantSDNode *C1 = dyn_cast<ConstantSDNode>(ExtVec1->getOperand(1)); |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 6631 | |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6632 | // For the constant, we want to see all the even or all the odd. |
| 6633 | if (!C0 || !C1 || C0->getZExtValue() != nextIndex |
| 6634 | || C1->getZExtValue() != nextIndex+1) |
| 6635 | return SDValue(); |
| 6636 | |
| 6637 | // Increment index. |
| 6638 | nextIndex+=2; |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 6639 | } else |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6640 | return SDValue(); |
| 6641 | } |
| 6642 | |
| 6643 | // Create VPADDL node. |
| 6644 | SelectionDAG &DAG = DCI.DAG; |
| 6645 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6646 | |
| 6647 | // Build operand list. |
| 6648 | SmallVector<SDValue, 8> Ops; |
| 6649 | Ops.push_back(DAG.getConstant(Intrinsic::arm_neon_vpaddls, |
| 6650 | TLI.getPointerTy())); |
| 6651 | |
| 6652 | // Input is the vector. |
| 6653 | Ops.push_back(Vec); |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 6654 | |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6655 | // Get widened type and narrowed type. |
| 6656 | MVT widenType; |
| 6657 | unsigned numElem = VT.getVectorNumElements(); |
| 6658 | switch (VT.getVectorElementType().getSimpleVT().SimpleTy) { |
| 6659 | case MVT::i8: widenType = MVT::getVectorVT(MVT::i16, numElem); break; |
| 6660 | case MVT::i16: widenType = MVT::getVectorVT(MVT::i32, numElem); break; |
| 6661 | case MVT::i32: widenType = MVT::getVectorVT(MVT::i64, numElem); break; |
| 6662 | default: |
| 6663 | assert(0 && "Invalid vector element type for padd optimization."); |
| 6664 | } |
| 6665 | |
| 6666 | SDValue tmp = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, N->getDebugLoc(), |
| 6667 | widenType, &Ops[0], Ops.size()); |
| 6668 | return DAG.getNode(ISD::TRUNCATE, N->getDebugLoc(), VT, tmp); |
| 6669 | } |
| 6670 | |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 6671 | /// PerformADDCombineWithOperands - Try DAG combinations for an ADD with |
| 6672 | /// operands N0 and N1. This is a helper for PerformADDCombine that is |
| 6673 | /// called with the default operands, and if that fails, with commuted |
| 6674 | /// operands. |
| 6675 | static SDValue PerformADDCombineWithOperands(SDNode *N, SDValue N0, SDValue N1, |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6676 | TargetLowering::DAGCombinerInfo &DCI, |
| 6677 | const ARMSubtarget *Subtarget){ |
| 6678 | |
| 6679 | // Attempt to create vpaddl for this add. |
| 6680 | SDValue Result = AddCombineToVPADDL(N, N0, N1, DCI, Subtarget); |
| 6681 | if (Result.getNode()) |
| 6682 | return Result; |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 6683 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 6684 | // fold (add (select cc, 0, c), x) -> (select cc, x, (add, x, c)) |
| 6685 | if (N0.getOpcode() == ISD::SELECT && N0.getNode()->hasOneUse()) { |
| 6686 | SDValue Result = combineSelectAndUse(N, N0, N1, DCI); |
| 6687 | if (Result.getNode()) return Result; |
| 6688 | } |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 6689 | return SDValue(); |
| 6690 | } |
| 6691 | |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 6692 | /// PerformADDCombine - Target-specific dag combine xforms for ISD::ADD. |
| 6693 | /// |
| 6694 | static SDValue PerformADDCombine(SDNode *N, |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6695 | TargetLowering::DAGCombinerInfo &DCI, |
| 6696 | const ARMSubtarget *Subtarget) { |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 6697 | SDValue N0 = N->getOperand(0); |
| 6698 | SDValue N1 = N->getOperand(1); |
| 6699 | |
| 6700 | // First try with the default operand order. |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6701 | SDValue Result = PerformADDCombineWithOperands(N, N0, N1, DCI, Subtarget); |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 6702 | if (Result.getNode()) |
| 6703 | return Result; |
| 6704 | |
| 6705 | // If that didn't work, try again with the operands commuted. |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 6706 | return PerformADDCombineWithOperands(N, N1, N0, DCI, Subtarget); |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 6707 | } |
| 6708 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 6709 | /// PerformSUBCombine - Target-specific dag combine xforms for ISD::SUB. |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 6710 | /// |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 6711 | static SDValue PerformSUBCombine(SDNode *N, |
| 6712 | TargetLowering::DAGCombinerInfo &DCI) { |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 6713 | SDValue N0 = N->getOperand(0); |
| 6714 | SDValue N1 = N->getOperand(1); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 6715 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 6716 | // fold (sub x, (select cc, 0, c)) -> (select cc, x, (sub, x, c)) |
| 6717 | if (N1.getOpcode() == ISD::SELECT && N1.getNode()->hasOneUse()) { |
| 6718 | SDValue Result = combineSelectAndUse(N, N1, N0, DCI); |
| 6719 | if (Result.getNode()) return Result; |
| 6720 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 6721 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 6722 | return SDValue(); |
| 6723 | } |
| 6724 | |
Evan Cheng | 463d358 | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 6725 | /// PerformVMULCombine |
| 6726 | /// Distribute (A + B) * C to (A * C) + (B * C) to take advantage of the |
| 6727 | /// special multiplier accumulator forwarding. |
| 6728 | /// vmul d3, d0, d2 |
| 6729 | /// vmla d3, d1, d2 |
| 6730 | /// is faster than |
| 6731 | /// vadd d3, d0, d1 |
| 6732 | /// vmul d3, d3, d2 |
| 6733 | static SDValue PerformVMULCombine(SDNode *N, |
| 6734 | TargetLowering::DAGCombinerInfo &DCI, |
| 6735 | const ARMSubtarget *Subtarget) { |
| 6736 | if (!Subtarget->hasVMLxForwarding()) |
| 6737 | return SDValue(); |
| 6738 | |
| 6739 | SelectionDAG &DAG = DCI.DAG; |
| 6740 | SDValue N0 = N->getOperand(0); |
| 6741 | SDValue N1 = N->getOperand(1); |
| 6742 | unsigned Opcode = N0.getOpcode(); |
| 6743 | if (Opcode != ISD::ADD && Opcode != ISD::SUB && |
| 6744 | Opcode != ISD::FADD && Opcode != ISD::FSUB) { |
Chad Rosier | 689edc8 | 2011-06-16 01:21:54 +0000 | [diff] [blame] | 6745 | Opcode = N1.getOpcode(); |
Evan Cheng | 463d358 | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 6746 | if (Opcode != ISD::ADD && Opcode != ISD::SUB && |
| 6747 | Opcode != ISD::FADD && Opcode != ISD::FSUB) |
| 6748 | return SDValue(); |
| 6749 | std::swap(N0, N1); |
| 6750 | } |
| 6751 | |
| 6752 | EVT VT = N->getValueType(0); |
| 6753 | DebugLoc DL = N->getDebugLoc(); |
| 6754 | SDValue N00 = N0->getOperand(0); |
| 6755 | SDValue N01 = N0->getOperand(1); |
| 6756 | return DAG.getNode(Opcode, DL, VT, |
| 6757 | DAG.getNode(ISD::MUL, DL, VT, N00, N1), |
| 6758 | DAG.getNode(ISD::MUL, DL, VT, N01, N1)); |
| 6759 | } |
| 6760 | |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 6761 | static SDValue PerformMULCombine(SDNode *N, |
| 6762 | TargetLowering::DAGCombinerInfo &DCI, |
| 6763 | const ARMSubtarget *Subtarget) { |
| 6764 | SelectionDAG &DAG = DCI.DAG; |
| 6765 | |
| 6766 | if (Subtarget->isThumb1Only()) |
| 6767 | return SDValue(); |
| 6768 | |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 6769 | if (DCI.isBeforeLegalize() || DCI.isCalledByLegalizer()) |
| 6770 | return SDValue(); |
| 6771 | |
| 6772 | EVT VT = N->getValueType(0); |
Evan Cheng | 463d358 | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 6773 | if (VT.is64BitVector() || VT.is128BitVector()) |
| 6774 | return PerformVMULCombine(N, DCI, Subtarget); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 6775 | if (VT != MVT::i32) |
| 6776 | return SDValue(); |
| 6777 | |
| 6778 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1)); |
| 6779 | if (!C) |
| 6780 | return SDValue(); |
| 6781 | |
| 6782 | uint64_t MulAmt = C->getZExtValue(); |
| 6783 | unsigned ShiftAmt = CountTrailingZeros_64(MulAmt); |
| 6784 | ShiftAmt = ShiftAmt & (32 - 1); |
| 6785 | SDValue V = N->getOperand(0); |
| 6786 | DebugLoc DL = N->getDebugLoc(); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 6787 | |
Anton Korobeynikov | 4878b84 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 6788 | SDValue Res; |
| 6789 | MulAmt >>= ShiftAmt; |
| 6790 | if (isPowerOf2_32(MulAmt - 1)) { |
| 6791 | // (mul x, 2^N + 1) => (add (shl x, N), x) |
| 6792 | Res = DAG.getNode(ISD::ADD, DL, VT, |
| 6793 | V, DAG.getNode(ISD::SHL, DL, VT, |
| 6794 | V, DAG.getConstant(Log2_32(MulAmt-1), |
| 6795 | MVT::i32))); |
| 6796 | } else if (isPowerOf2_32(MulAmt + 1)) { |
| 6797 | // (mul x, 2^N - 1) => (sub (shl x, N), x) |
| 6798 | Res = DAG.getNode(ISD::SUB, DL, VT, |
| 6799 | DAG.getNode(ISD::SHL, DL, VT, |
| 6800 | V, DAG.getConstant(Log2_32(MulAmt+1), |
| 6801 | MVT::i32)), |
| 6802 | V); |
| 6803 | } else |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 6804 | return SDValue(); |
Anton Korobeynikov | 4878b84 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 6805 | |
| 6806 | if (ShiftAmt != 0) |
| 6807 | Res = DAG.getNode(ISD::SHL, DL, VT, Res, |
| 6808 | DAG.getConstant(ShiftAmt, MVT::i32)); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 6809 | |
| 6810 | // Do not add new nodes to DAG combiner worklist. |
Anton Korobeynikov | 4878b84 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 6811 | DCI.CombineTo(N, Res, false); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 6812 | return SDValue(); |
| 6813 | } |
| 6814 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 6815 | static SDValue PerformANDCombine(SDNode *N, |
| 6816 | TargetLowering::DAGCombinerInfo &DCI) { |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6817 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 6818 | // Attempt to use immediate-form VBIC |
| 6819 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(N->getOperand(1)); |
| 6820 | DebugLoc dl = N->getDebugLoc(); |
| 6821 | EVT VT = N->getValueType(0); |
| 6822 | SelectionDAG &DAG = DCI.DAG; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6823 | |
Tanya Lattner | 0433b21 | 2011-04-07 15:24:20 +0000 | [diff] [blame] | 6824 | if(!DAG.getTargetLoweringInfo().isTypeLegal(VT)) |
| 6825 | return SDValue(); |
Andrew Trick | 1c3af77 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 6826 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 6827 | APInt SplatBits, SplatUndef; |
| 6828 | unsigned SplatBitSize; |
| 6829 | bool HasAnyUndefs; |
| 6830 | if (BVN && |
| 6831 | BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { |
| 6832 | if (SplatBitSize <= 64) { |
| 6833 | EVT VbicVT; |
| 6834 | SDValue Val = isNEONModifiedImm((~SplatBits).getZExtValue(), |
| 6835 | SplatUndef.getZExtValue(), SplatBitSize, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6836 | DAG, VbicVT, VT.is128BitVector(), |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 6837 | OtherModImm); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 6838 | if (Val.getNode()) { |
| 6839 | SDValue Input = |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6840 | DAG.getNode(ISD::BITCAST, dl, VbicVT, N->getOperand(0)); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 6841 | SDValue Vbic = DAG.getNode(ARMISD::VBICIMM, dl, VbicVT, Input, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6842 | return DAG.getNode(ISD::BITCAST, dl, VT, Vbic); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 6843 | } |
| 6844 | } |
| 6845 | } |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6846 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 6847 | return SDValue(); |
| 6848 | } |
| 6849 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 6850 | /// PerformORCombine - Target-specific dag combine xforms for ISD::OR |
| 6851 | static SDValue PerformORCombine(SDNode *N, |
| 6852 | TargetLowering::DAGCombinerInfo &DCI, |
| 6853 | const ARMSubtarget *Subtarget) { |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 6854 | // Attempt to use immediate-form VORR |
| 6855 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(N->getOperand(1)); |
| 6856 | DebugLoc dl = N->getDebugLoc(); |
| 6857 | EVT VT = N->getValueType(0); |
| 6858 | SelectionDAG &DAG = DCI.DAG; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6859 | |
Tanya Lattner | 0433b21 | 2011-04-07 15:24:20 +0000 | [diff] [blame] | 6860 | if(!DAG.getTargetLoweringInfo().isTypeLegal(VT)) |
| 6861 | return SDValue(); |
Andrew Trick | 1c3af77 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 6862 | |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 6863 | APInt SplatBits, SplatUndef; |
| 6864 | unsigned SplatBitSize; |
| 6865 | bool HasAnyUndefs; |
| 6866 | if (BVN && Subtarget->hasNEON() && |
| 6867 | BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { |
| 6868 | if (SplatBitSize <= 64) { |
| 6869 | EVT VorrVT; |
| 6870 | SDValue Val = isNEONModifiedImm(SplatBits.getZExtValue(), |
| 6871 | SplatUndef.getZExtValue(), SplatBitSize, |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 6872 | DAG, VorrVT, VT.is128BitVector(), |
| 6873 | OtherModImm); |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 6874 | if (Val.getNode()) { |
| 6875 | SDValue Input = |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6876 | DAG.getNode(ISD::BITCAST, dl, VorrVT, N->getOperand(0)); |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 6877 | SDValue Vorr = DAG.getNode(ARMISD::VORRIMM, dl, VorrVT, Input, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6878 | return DAG.getNode(ISD::BITCAST, dl, VT, Vorr); |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 6879 | } |
| 6880 | } |
| 6881 | } |
| 6882 | |
Cameron Zwarich | c0e6d78 | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 6883 | SDValue N0 = N->getOperand(0); |
| 6884 | if (N0.getOpcode() != ISD::AND) |
| 6885 | return SDValue(); |
| 6886 | SDValue N1 = N->getOperand(1); |
| 6887 | |
| 6888 | // (or (and B, A), (and C, ~A)) => (VBSL A, B, C) when A is a constant. |
| 6889 | if (Subtarget->hasNEON() && N1.getOpcode() == ISD::AND && VT.isVector() && |
| 6890 | DAG.getTargetLoweringInfo().isTypeLegal(VT)) { |
| 6891 | APInt SplatUndef; |
| 6892 | unsigned SplatBitSize; |
| 6893 | bool HasAnyUndefs; |
| 6894 | |
| 6895 | BuildVectorSDNode *BVN0 = dyn_cast<BuildVectorSDNode>(N0->getOperand(1)); |
| 6896 | APInt SplatBits0; |
| 6897 | if (BVN0 && BVN0->isConstantSplat(SplatBits0, SplatUndef, SplatBitSize, |
| 6898 | HasAnyUndefs) && !HasAnyUndefs) { |
| 6899 | BuildVectorSDNode *BVN1 = dyn_cast<BuildVectorSDNode>(N1->getOperand(1)); |
| 6900 | APInt SplatBits1; |
| 6901 | if (BVN1 && BVN1->isConstantSplat(SplatBits1, SplatUndef, SplatBitSize, |
| 6902 | HasAnyUndefs) && !HasAnyUndefs && |
| 6903 | SplatBits0 == ~SplatBits1) { |
| 6904 | // Canonicalize the vector type to make instruction selection simpler. |
| 6905 | EVT CanonicalVT = VT.is128BitVector() ? MVT::v4i32 : MVT::v2i32; |
| 6906 | SDValue Result = DAG.getNode(ARMISD::VBSL, dl, CanonicalVT, |
| 6907 | N0->getOperand(1), N0->getOperand(0), |
Cameron Zwarich | 5af60ce | 2011-04-13 21:01:19 +0000 | [diff] [blame] | 6908 | N1->getOperand(0)); |
Cameron Zwarich | c0e6d78 | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 6909 | return DAG.getNode(ISD::BITCAST, dl, VT, Result); |
| 6910 | } |
| 6911 | } |
| 6912 | } |
| 6913 | |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 6914 | // Try to use the ARM/Thumb2 BFI (bitfield insert) instruction when |
| 6915 | // reasonable. |
| 6916 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 6917 | // BFI is only available on V6T2+ |
| 6918 | if (Subtarget->isThumb1Only() || !Subtarget->hasV6T2Ops()) |
| 6919 | return SDValue(); |
| 6920 | |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 6921 | DebugLoc DL = N->getDebugLoc(); |
| 6922 | // 1) or (and A, mask), val => ARMbfi A, val, mask |
| 6923 | // iff (val & mask) == val |
| 6924 | // |
| 6925 | // 2) or (and A, mask), (and B, mask2) => ARMbfi A, (lsr B, amt), mask |
| 6926 | // 2a) iff isBitFieldInvertedMask(mask) && isBitFieldInvertedMask(~mask2) |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 6927 | // && mask == ~mask2 |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 6928 | // 2b) iff isBitFieldInvertedMask(~mask) && isBitFieldInvertedMask(mask2) |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 6929 | // && ~mask == mask2 |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 6930 | // (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] | 6931 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 6932 | if (VT != MVT::i32) |
| 6933 | return SDValue(); |
| 6934 | |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 6935 | SDValue N00 = N0.getOperand(0); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 6936 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 6937 | // The value and the mask need to be constants so we can verify this is |
| 6938 | // actually a bitfield set. If the mask is 0xffff, we can do better |
| 6939 | // via a movt instruction, so don't use BFI in that case. |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 6940 | SDValue MaskOp = N0.getOperand(1); |
| 6941 | ConstantSDNode *MaskC = dyn_cast<ConstantSDNode>(MaskOp); |
| 6942 | if (!MaskC) |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 6943 | return SDValue(); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 6944 | unsigned Mask = MaskC->getZExtValue(); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 6945 | if (Mask == 0xffff) |
| 6946 | return SDValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 6947 | SDValue Res; |
| 6948 | // Case (1): or (and A, mask), val => ARMbfi A, val, mask |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 6949 | ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1); |
| 6950 | if (N1C) { |
| 6951 | unsigned Val = N1C->getZExtValue(); |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 6952 | if ((Val & ~Mask) != Val) |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 6953 | return SDValue(); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 6954 | |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 6955 | if (ARM::isBitFieldInvertedMask(Mask)) { |
| 6956 | Val >>= CountTrailingZeros_32(~Mask); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 6957 | |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 6958 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N00, |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 6959 | DAG.getConstant(Val, MVT::i32), |
| 6960 | DAG.getConstant(Mask, MVT::i32)); |
| 6961 | |
| 6962 | // Do not add new nodes to DAG combiner worklist. |
| 6963 | DCI.CombineTo(N, Res, false); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 6964 | return SDValue(); |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 6965 | } |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 6966 | } else if (N1.getOpcode() == ISD::AND) { |
| 6967 | // 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] | 6968 | ConstantSDNode *N11C = dyn_cast<ConstantSDNode>(N1.getOperand(1)); |
| 6969 | if (!N11C) |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 6970 | return SDValue(); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 6971 | unsigned Mask2 = N11C->getZExtValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 6972 | |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 6973 | // Mask and ~Mask2 (or reverse) must be equivalent for the BFI pattern |
| 6974 | // as is to match. |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 6975 | if (ARM::isBitFieldInvertedMask(Mask) && |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 6976 | (Mask == ~Mask2)) { |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 6977 | // The pack halfword instruction works better for masks that fit it, |
| 6978 | // so use that when it's available. |
| 6979 | if (Subtarget->hasT2ExtractPack() && |
| 6980 | (Mask == 0xffff || Mask == 0xffff0000)) |
| 6981 | return SDValue(); |
| 6982 | // 2a |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 6983 | unsigned amt = CountTrailingZeros_32(Mask2); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 6984 | Res = DAG.getNode(ISD::SRL, DL, VT, N1.getOperand(0), |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 6985 | DAG.getConstant(amt, MVT::i32)); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 6986 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N00, Res, |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 6987 | DAG.getConstant(Mask, MVT::i32)); |
| 6988 | // Do not add new nodes to DAG combiner worklist. |
| 6989 | DCI.CombineTo(N, Res, false); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 6990 | return SDValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 6991 | } else if (ARM::isBitFieldInvertedMask(~Mask) && |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 6992 | (~Mask == Mask2)) { |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 6993 | // The pack halfword instruction works better for masks that fit it, |
| 6994 | // so use that when it's available. |
| 6995 | if (Subtarget->hasT2ExtractPack() && |
| 6996 | (Mask2 == 0xffff || Mask2 == 0xffff0000)) |
| 6997 | return SDValue(); |
| 6998 | // 2b |
| 6999 | unsigned lsb = CountTrailingZeros_32(Mask); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7000 | Res = DAG.getNode(ISD::SRL, DL, VT, N00, |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7001 | DAG.getConstant(lsb, MVT::i32)); |
| 7002 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N1.getOperand(0), Res, |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 7003 | DAG.getConstant(Mask2, MVT::i32)); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7004 | // Do not add new nodes to DAG combiner worklist. |
| 7005 | DCI.CombineTo(N, Res, false); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7006 | return SDValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7007 | } |
| 7008 | } |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7009 | |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7010 | if (DAG.MaskedValueIsZero(N1, MaskC->getAPIntValue()) && |
| 7011 | N00.getOpcode() == ISD::SHL && isa<ConstantSDNode>(N00.getOperand(1)) && |
| 7012 | ARM::isBitFieldInvertedMask(~Mask)) { |
| 7013 | // Case (3): or (and (shl A, #shamt), mask), B => ARMbfi B, A, ~mask |
| 7014 | // where lsb(mask) == #shamt and masked bits of B are known zero. |
| 7015 | SDValue ShAmt = N00.getOperand(1); |
| 7016 | unsigned ShAmtC = cast<ConstantSDNode>(ShAmt)->getZExtValue(); |
| 7017 | unsigned LSB = CountTrailingZeros_32(Mask); |
| 7018 | if (ShAmtC != LSB) |
| 7019 | return SDValue(); |
| 7020 | |
| 7021 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N1, N00.getOperand(0), |
| 7022 | DAG.getConstant(~Mask, MVT::i32)); |
| 7023 | |
| 7024 | // Do not add new nodes to DAG combiner worklist. |
| 7025 | DCI.CombineTo(N, Res, false); |
| 7026 | } |
| 7027 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 7028 | return SDValue(); |
| 7029 | } |
| 7030 | |
Evan Cheng | bf188ae | 2011-06-15 01:12:31 +0000 | [diff] [blame] | 7031 | /// PerformBFICombine - (bfi A, (and B, Mask1), Mask2) -> (bfi A, B, Mask2) iff |
| 7032 | /// 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] | 7033 | static SDValue PerformBFICombine(SDNode *N, |
| 7034 | TargetLowering::DAGCombinerInfo &DCI) { |
| 7035 | SDValue N1 = N->getOperand(1); |
| 7036 | if (N1.getOpcode() == ISD::AND) { |
| 7037 | ConstantSDNode *N11C = dyn_cast<ConstantSDNode>(N1.getOperand(1)); |
| 7038 | if (!N11C) |
| 7039 | return SDValue(); |
Evan Cheng | bf188ae | 2011-06-15 01:12:31 +0000 | [diff] [blame] | 7040 | unsigned InvMask = cast<ConstantSDNode>(N->getOperand(2))->getZExtValue(); |
| 7041 | unsigned LSB = CountTrailingZeros_32(~InvMask); |
| 7042 | unsigned Width = (32 - CountLeadingZeros_32(~InvMask)) - LSB; |
| 7043 | unsigned Mask = (1 << Width)-1; |
Evan Cheng | 0c1aec1 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 7044 | unsigned Mask2 = N11C->getZExtValue(); |
Evan Cheng | bf188ae | 2011-06-15 01:12:31 +0000 | [diff] [blame] | 7045 | if ((Mask & (~Mask2)) == 0) |
Evan Cheng | 0c1aec1 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 7046 | return DCI.DAG.getNode(ARMISD::BFI, N->getDebugLoc(), N->getValueType(0), |
| 7047 | N->getOperand(0), N1.getOperand(0), |
| 7048 | N->getOperand(2)); |
| 7049 | } |
| 7050 | return SDValue(); |
| 7051 | } |
| 7052 | |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 7053 | /// PerformVMOVRRDCombine - Target-specific dag combine xforms for |
| 7054 | /// ARMISD::VMOVRRD. |
| 7055 | static SDValue PerformVMOVRRDCombine(SDNode *N, |
| 7056 | TargetLowering::DAGCombinerInfo &DCI) { |
| 7057 | // vmovrrd(vmovdrr x, y) -> x,y |
| 7058 | SDValue InDouble = N->getOperand(0); |
| 7059 | if (InDouble.getOpcode() == ARMISD::VMOVDRR) |
| 7060 | return DCI.CombineTo(N, InDouble.getOperand(0), InDouble.getOperand(1)); |
Cameron Zwarich | 4071a71 | 2011-04-02 02:40:43 +0000 | [diff] [blame] | 7061 | |
| 7062 | // vmovrrd(load f64) -> (load i32), (load i32) |
| 7063 | SDNode *InNode = InDouble.getNode(); |
| 7064 | if (ISD::isNormalLoad(InNode) && InNode->hasOneUse() && |
| 7065 | InNode->getValueType(0) == MVT::f64 && |
| 7066 | InNode->getOperand(1).getOpcode() == ISD::FrameIndex && |
| 7067 | !cast<LoadSDNode>(InNode)->isVolatile()) { |
| 7068 | // TODO: Should this be done for non-FrameIndex operands? |
| 7069 | LoadSDNode *LD = cast<LoadSDNode>(InNode); |
| 7070 | |
| 7071 | SelectionDAG &DAG = DCI.DAG; |
| 7072 | DebugLoc DL = LD->getDebugLoc(); |
| 7073 | SDValue BasePtr = LD->getBasePtr(); |
| 7074 | SDValue NewLD1 = DAG.getLoad(MVT::i32, DL, LD->getChain(), BasePtr, |
| 7075 | LD->getPointerInfo(), LD->isVolatile(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 7076 | LD->isNonTemporal(), LD->isInvariant(), |
| 7077 | LD->getAlignment()); |
Cameron Zwarich | 4071a71 | 2011-04-02 02:40:43 +0000 | [diff] [blame] | 7078 | |
| 7079 | SDValue OffsetPtr = DAG.getNode(ISD::ADD, DL, MVT::i32, BasePtr, |
| 7080 | DAG.getConstant(4, MVT::i32)); |
| 7081 | SDValue NewLD2 = DAG.getLoad(MVT::i32, DL, NewLD1.getValue(1), OffsetPtr, |
| 7082 | LD->getPointerInfo(), LD->isVolatile(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 7083 | LD->isNonTemporal(), LD->isInvariant(), |
Cameron Zwarich | 4071a71 | 2011-04-02 02:40:43 +0000 | [diff] [blame] | 7084 | std::min(4U, LD->getAlignment() / 2)); |
| 7085 | |
| 7086 | DAG.ReplaceAllUsesOfValueWith(SDValue(LD, 1), NewLD2.getValue(1)); |
| 7087 | SDValue Result = DCI.CombineTo(N, NewLD1, NewLD2); |
| 7088 | DCI.RemoveFromWorklist(LD); |
| 7089 | DAG.DeleteNode(LD); |
| 7090 | return Result; |
| 7091 | } |
| 7092 | |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 7093 | return SDValue(); |
| 7094 | } |
| 7095 | |
| 7096 | /// PerformVMOVDRRCombine - Target-specific dag combine xforms for |
| 7097 | /// ARMISD::VMOVDRR. This is also used for BUILD_VECTORs with 2 operands. |
| 7098 | static SDValue PerformVMOVDRRCombine(SDNode *N, SelectionDAG &DAG) { |
| 7099 | // N=vmovrrd(X); vmovdrr(N:0, N:1) -> bit_convert(X) |
| 7100 | SDValue Op0 = N->getOperand(0); |
| 7101 | SDValue Op1 = N->getOperand(1); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7102 | if (Op0.getOpcode() == ISD::BITCAST) |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 7103 | Op0 = Op0.getOperand(0); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7104 | if (Op1.getOpcode() == ISD::BITCAST) |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 7105 | Op1 = Op1.getOperand(0); |
| 7106 | if (Op0.getOpcode() == ARMISD::VMOVRRD && |
| 7107 | Op0.getNode() == Op1.getNode() && |
| 7108 | Op0.getResNo() == 0 && Op1.getResNo() == 1) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7109 | return DAG.getNode(ISD::BITCAST, N->getDebugLoc(), |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 7110 | N->getValueType(0), Op0.getOperand(0)); |
| 7111 | return SDValue(); |
| 7112 | } |
| 7113 | |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 7114 | /// PerformSTORECombine - Target-specific dag combine xforms for |
| 7115 | /// ISD::STORE. |
| 7116 | static SDValue PerformSTORECombine(SDNode *N, |
| 7117 | TargetLowering::DAGCombinerInfo &DCI) { |
| 7118 | // Bitcast an i64 store extracted from a vector to f64. |
| 7119 | // Otherwise, the i64 value will be legalized to a pair of i32 values. |
| 7120 | StoreSDNode *St = cast<StoreSDNode>(N); |
| 7121 | SDValue StVal = St->getValue(); |
Cameron Zwarich | d0aacbc | 2011-04-12 02:24:17 +0000 | [diff] [blame] | 7122 | if (!ISD::isNormalStore(St) || St->isVolatile()) |
| 7123 | return SDValue(); |
| 7124 | |
| 7125 | if (StVal.getNode()->getOpcode() == ARMISD::VMOVDRR && |
| 7126 | StVal.getNode()->hasOneUse() && !St->isVolatile()) { |
| 7127 | SelectionDAG &DAG = DCI.DAG; |
| 7128 | DebugLoc DL = St->getDebugLoc(); |
| 7129 | SDValue BasePtr = St->getBasePtr(); |
| 7130 | SDValue NewST1 = DAG.getStore(St->getChain(), DL, |
| 7131 | StVal.getNode()->getOperand(0), BasePtr, |
| 7132 | St->getPointerInfo(), St->isVolatile(), |
| 7133 | St->isNonTemporal(), St->getAlignment()); |
| 7134 | |
| 7135 | SDValue OffsetPtr = DAG.getNode(ISD::ADD, DL, MVT::i32, BasePtr, |
| 7136 | DAG.getConstant(4, MVT::i32)); |
| 7137 | return DAG.getStore(NewST1.getValue(0), DL, StVal.getNode()->getOperand(1), |
| 7138 | OffsetPtr, St->getPointerInfo(), St->isVolatile(), |
| 7139 | St->isNonTemporal(), |
| 7140 | std::min(4U, St->getAlignment() / 2)); |
| 7141 | } |
| 7142 | |
| 7143 | if (StVal.getValueType() != MVT::i64 || |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 7144 | StVal.getNode()->getOpcode() != ISD::EXTRACT_VECTOR_ELT) |
| 7145 | return SDValue(); |
| 7146 | |
| 7147 | SelectionDAG &DAG = DCI.DAG; |
| 7148 | DebugLoc dl = StVal.getDebugLoc(); |
| 7149 | SDValue IntVec = StVal.getOperand(0); |
| 7150 | EVT FloatVT = EVT::getVectorVT(*DAG.getContext(), MVT::f64, |
| 7151 | IntVec.getValueType().getVectorNumElements()); |
| 7152 | SDValue Vec = DAG.getNode(ISD::BITCAST, dl, FloatVT, IntVec); |
| 7153 | SDValue ExtElt = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, |
| 7154 | Vec, StVal.getOperand(1)); |
| 7155 | dl = N->getDebugLoc(); |
| 7156 | SDValue V = DAG.getNode(ISD::BITCAST, dl, MVT::i64, ExtElt); |
| 7157 | // Make the DAGCombiner fold the bitcasts. |
| 7158 | DCI.AddToWorklist(Vec.getNode()); |
| 7159 | DCI.AddToWorklist(ExtElt.getNode()); |
| 7160 | DCI.AddToWorklist(V.getNode()); |
| 7161 | return DAG.getStore(St->getChain(), dl, V, St->getBasePtr(), |
| 7162 | St->getPointerInfo(), St->isVolatile(), |
| 7163 | St->isNonTemporal(), St->getAlignment(), |
| 7164 | St->getTBAAInfo()); |
| 7165 | } |
| 7166 | |
| 7167 | /// hasNormalLoadOperand - Check if any of the operands of a BUILD_VECTOR node |
| 7168 | /// are normal, non-volatile loads. If so, it is profitable to bitcast an |
| 7169 | /// i64 vector to have f64 elements, since the value can then be loaded |
| 7170 | /// directly into a VFP register. |
| 7171 | static bool hasNormalLoadOperand(SDNode *N) { |
| 7172 | unsigned NumElts = N->getValueType(0).getVectorNumElements(); |
| 7173 | for (unsigned i = 0; i < NumElts; ++i) { |
| 7174 | SDNode *Elt = N->getOperand(i).getNode(); |
| 7175 | if (ISD::isNormalLoad(Elt) && !cast<LoadSDNode>(Elt)->isVolatile()) |
| 7176 | return true; |
| 7177 | } |
| 7178 | return false; |
| 7179 | } |
| 7180 | |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 7181 | /// PerformBUILD_VECTORCombine - Target-specific dag combine xforms for |
| 7182 | /// ISD::BUILD_VECTOR. |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 7183 | static SDValue PerformBUILD_VECTORCombine(SDNode *N, |
| 7184 | TargetLowering::DAGCombinerInfo &DCI){ |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 7185 | // build_vector(N=ARMISD::VMOVRRD(X), N:1) -> bit_convert(X): |
| 7186 | // VMOVRRD is introduced when legalizing i64 types. It forces the i64 value |
| 7187 | // into a pair of GPRs, which is fine when the value is used as a scalar, |
| 7188 | // 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] | 7189 | SelectionDAG &DAG = DCI.DAG; |
| 7190 | if (N->getNumOperands() == 2) { |
| 7191 | SDValue RV = PerformVMOVDRRCombine(N, DAG); |
| 7192 | if (RV.getNode()) |
| 7193 | return RV; |
| 7194 | } |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 7195 | |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 7196 | // Load i64 elements as f64 values so that type legalization does not split |
| 7197 | // them up into i32 values. |
| 7198 | EVT VT = N->getValueType(0); |
| 7199 | if (VT.getVectorElementType() != MVT::i64 || !hasNormalLoadOperand(N)) |
| 7200 | return SDValue(); |
| 7201 | DebugLoc dl = N->getDebugLoc(); |
| 7202 | SmallVector<SDValue, 8> Ops; |
| 7203 | unsigned NumElts = VT.getVectorNumElements(); |
| 7204 | for (unsigned i = 0; i < NumElts; ++i) { |
| 7205 | SDValue V = DAG.getNode(ISD::BITCAST, dl, MVT::f64, N->getOperand(i)); |
| 7206 | Ops.push_back(V); |
| 7207 | // Make the DAGCombiner fold the bitcast. |
| 7208 | DCI.AddToWorklist(V.getNode()); |
| 7209 | } |
| 7210 | EVT FloatVT = EVT::getVectorVT(*DAG.getContext(), MVT::f64, NumElts); |
| 7211 | SDValue BV = DAG.getNode(ISD::BUILD_VECTOR, dl, FloatVT, Ops.data(), NumElts); |
| 7212 | return DAG.getNode(ISD::BITCAST, dl, VT, BV); |
| 7213 | } |
| 7214 | |
| 7215 | /// PerformInsertEltCombine - Target-specific dag combine xforms for |
| 7216 | /// ISD::INSERT_VECTOR_ELT. |
| 7217 | static SDValue PerformInsertEltCombine(SDNode *N, |
| 7218 | TargetLowering::DAGCombinerInfo &DCI) { |
| 7219 | // Bitcast an i64 load inserted into a vector to f64. |
| 7220 | // Otherwise, the i64 value will be legalized to a pair of i32 values. |
| 7221 | EVT VT = N->getValueType(0); |
| 7222 | SDNode *Elt = N->getOperand(1).getNode(); |
| 7223 | if (VT.getVectorElementType() != MVT::i64 || |
| 7224 | !ISD::isNormalLoad(Elt) || cast<LoadSDNode>(Elt)->isVolatile()) |
| 7225 | return SDValue(); |
| 7226 | |
| 7227 | SelectionDAG &DAG = DCI.DAG; |
| 7228 | DebugLoc dl = N->getDebugLoc(); |
| 7229 | EVT FloatVT = EVT::getVectorVT(*DAG.getContext(), MVT::f64, |
| 7230 | VT.getVectorNumElements()); |
| 7231 | SDValue Vec = DAG.getNode(ISD::BITCAST, dl, FloatVT, N->getOperand(0)); |
| 7232 | SDValue V = DAG.getNode(ISD::BITCAST, dl, MVT::f64, N->getOperand(1)); |
| 7233 | // Make the DAGCombiner fold the bitcasts. |
| 7234 | DCI.AddToWorklist(Vec.getNode()); |
| 7235 | DCI.AddToWorklist(V.getNode()); |
| 7236 | SDValue InsElt = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, FloatVT, |
| 7237 | Vec, V, N->getOperand(2)); |
| 7238 | return DAG.getNode(ISD::BITCAST, dl, VT, InsElt); |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 7239 | } |
| 7240 | |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 7241 | /// PerformVECTOR_SHUFFLECombine - Target-specific dag combine xforms for |
| 7242 | /// ISD::VECTOR_SHUFFLE. |
| 7243 | static SDValue PerformVECTOR_SHUFFLECombine(SDNode *N, SelectionDAG &DAG) { |
| 7244 | // The LLVM shufflevector instruction does not require the shuffle mask |
| 7245 | // length to match the operand vector length, but ISD::VECTOR_SHUFFLE does |
| 7246 | // have that requirement. When translating to ISD::VECTOR_SHUFFLE, if the |
| 7247 | // operands do not match the mask length, they are extended by concatenating |
| 7248 | // them with undef vectors. That is probably the right thing for other |
| 7249 | // targets, but for NEON it is better to concatenate two double-register |
| 7250 | // size vector operands into a single quad-register size vector. Do that |
| 7251 | // transformation here: |
| 7252 | // shuffle(concat(v1, undef), concat(v2, undef)) -> |
| 7253 | // shuffle(concat(v1, v2), undef) |
| 7254 | SDValue Op0 = N->getOperand(0); |
| 7255 | SDValue Op1 = N->getOperand(1); |
| 7256 | if (Op0.getOpcode() != ISD::CONCAT_VECTORS || |
| 7257 | Op1.getOpcode() != ISD::CONCAT_VECTORS || |
| 7258 | Op0.getNumOperands() != 2 || |
| 7259 | Op1.getNumOperands() != 2) |
| 7260 | return SDValue(); |
| 7261 | SDValue Concat0Op1 = Op0.getOperand(1); |
| 7262 | SDValue Concat1Op1 = Op1.getOperand(1); |
| 7263 | if (Concat0Op1.getOpcode() != ISD::UNDEF || |
| 7264 | Concat1Op1.getOpcode() != ISD::UNDEF) |
| 7265 | return SDValue(); |
| 7266 | // Skip the transformation if any of the types are illegal. |
| 7267 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 7268 | EVT VT = N->getValueType(0); |
| 7269 | if (!TLI.isTypeLegal(VT) || |
| 7270 | !TLI.isTypeLegal(Concat0Op1.getValueType()) || |
| 7271 | !TLI.isTypeLegal(Concat1Op1.getValueType())) |
| 7272 | return SDValue(); |
| 7273 | |
| 7274 | SDValue NewConcat = DAG.getNode(ISD::CONCAT_VECTORS, N->getDebugLoc(), VT, |
| 7275 | Op0.getOperand(0), Op1.getOperand(0)); |
| 7276 | // Translate the shuffle mask. |
| 7277 | SmallVector<int, 16> NewMask; |
| 7278 | unsigned NumElts = VT.getVectorNumElements(); |
| 7279 | unsigned HalfElts = NumElts/2; |
| 7280 | ShuffleVectorSDNode *SVN = cast<ShuffleVectorSDNode>(N); |
| 7281 | for (unsigned n = 0; n < NumElts; ++n) { |
| 7282 | int MaskElt = SVN->getMaskElt(n); |
| 7283 | int NewElt = -1; |
Bob Wilson | 1fa9d30 | 2010-10-27 23:49:00 +0000 | [diff] [blame] | 7284 | if (MaskElt < (int)HalfElts) |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 7285 | NewElt = MaskElt; |
Bob Wilson | 1fa9d30 | 2010-10-27 23:49:00 +0000 | [diff] [blame] | 7286 | else if (MaskElt >= (int)NumElts && MaskElt < (int)(NumElts + HalfElts)) |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 7287 | NewElt = HalfElts + MaskElt - NumElts; |
| 7288 | NewMask.push_back(NewElt); |
| 7289 | } |
| 7290 | return DAG.getVectorShuffle(VT, N->getDebugLoc(), NewConcat, |
| 7291 | DAG.getUNDEF(VT), NewMask.data()); |
| 7292 | } |
| 7293 | |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 7294 | /// CombineBaseUpdate - Target-specific DAG combine function for VLDDUP and |
| 7295 | /// NEON load/store intrinsics to merge base address updates. |
| 7296 | static SDValue CombineBaseUpdate(SDNode *N, |
| 7297 | TargetLowering::DAGCombinerInfo &DCI) { |
| 7298 | if (DCI.isBeforeLegalize() || DCI.isCalledByLegalizer()) |
| 7299 | return SDValue(); |
| 7300 | |
| 7301 | SelectionDAG &DAG = DCI.DAG; |
| 7302 | bool isIntrinsic = (N->getOpcode() == ISD::INTRINSIC_VOID || |
| 7303 | N->getOpcode() == ISD::INTRINSIC_W_CHAIN); |
| 7304 | unsigned AddrOpIdx = (isIntrinsic ? 2 : 1); |
| 7305 | SDValue Addr = N->getOperand(AddrOpIdx); |
| 7306 | |
| 7307 | // Search for a use of the address operand that is an increment. |
| 7308 | for (SDNode::use_iterator UI = Addr.getNode()->use_begin(), |
| 7309 | UE = Addr.getNode()->use_end(); UI != UE; ++UI) { |
| 7310 | SDNode *User = *UI; |
| 7311 | if (User->getOpcode() != ISD::ADD || |
| 7312 | UI.getUse().getResNo() != Addr.getResNo()) |
| 7313 | continue; |
| 7314 | |
| 7315 | // Check that the add is independent of the load/store. Otherwise, folding |
| 7316 | // it would create a cycle. |
| 7317 | if (User->isPredecessorOf(N) || N->isPredecessorOf(User)) |
| 7318 | continue; |
| 7319 | |
| 7320 | // Find the new opcode for the updating load/store. |
| 7321 | bool isLoad = true; |
| 7322 | bool isLaneOp = false; |
| 7323 | unsigned NewOpc = 0; |
| 7324 | unsigned NumVecs = 0; |
| 7325 | if (isIntrinsic) { |
| 7326 | unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue(); |
| 7327 | switch (IntNo) { |
| 7328 | default: assert(0 && "unexpected intrinsic for Neon base update"); |
| 7329 | case Intrinsic::arm_neon_vld1: NewOpc = ARMISD::VLD1_UPD; |
| 7330 | NumVecs = 1; break; |
| 7331 | case Intrinsic::arm_neon_vld2: NewOpc = ARMISD::VLD2_UPD; |
| 7332 | NumVecs = 2; break; |
| 7333 | case Intrinsic::arm_neon_vld3: NewOpc = ARMISD::VLD3_UPD; |
| 7334 | NumVecs = 3; break; |
| 7335 | case Intrinsic::arm_neon_vld4: NewOpc = ARMISD::VLD4_UPD; |
| 7336 | NumVecs = 4; break; |
| 7337 | case Intrinsic::arm_neon_vld2lane: NewOpc = ARMISD::VLD2LN_UPD; |
| 7338 | NumVecs = 2; isLaneOp = true; break; |
| 7339 | case Intrinsic::arm_neon_vld3lane: NewOpc = ARMISD::VLD3LN_UPD; |
| 7340 | NumVecs = 3; isLaneOp = true; break; |
| 7341 | case Intrinsic::arm_neon_vld4lane: NewOpc = ARMISD::VLD4LN_UPD; |
| 7342 | NumVecs = 4; isLaneOp = true; break; |
| 7343 | case Intrinsic::arm_neon_vst1: NewOpc = ARMISD::VST1_UPD; |
| 7344 | NumVecs = 1; isLoad = false; break; |
| 7345 | case Intrinsic::arm_neon_vst2: NewOpc = ARMISD::VST2_UPD; |
| 7346 | NumVecs = 2; isLoad = false; break; |
| 7347 | case Intrinsic::arm_neon_vst3: NewOpc = ARMISD::VST3_UPD; |
| 7348 | NumVecs = 3; isLoad = false; break; |
| 7349 | case Intrinsic::arm_neon_vst4: NewOpc = ARMISD::VST4_UPD; |
| 7350 | NumVecs = 4; isLoad = false; break; |
| 7351 | case Intrinsic::arm_neon_vst2lane: NewOpc = ARMISD::VST2LN_UPD; |
| 7352 | NumVecs = 2; isLoad = false; isLaneOp = true; break; |
| 7353 | case Intrinsic::arm_neon_vst3lane: NewOpc = ARMISD::VST3LN_UPD; |
| 7354 | NumVecs = 3; isLoad = false; isLaneOp = true; break; |
| 7355 | case Intrinsic::arm_neon_vst4lane: NewOpc = ARMISD::VST4LN_UPD; |
| 7356 | NumVecs = 4; isLoad = false; isLaneOp = true; break; |
| 7357 | } |
| 7358 | } else { |
| 7359 | isLaneOp = true; |
| 7360 | switch (N->getOpcode()) { |
| 7361 | default: assert(0 && "unexpected opcode for Neon base update"); |
| 7362 | case ARMISD::VLD2DUP: NewOpc = ARMISD::VLD2DUP_UPD; NumVecs = 2; break; |
| 7363 | case ARMISD::VLD3DUP: NewOpc = ARMISD::VLD3DUP_UPD; NumVecs = 3; break; |
| 7364 | case ARMISD::VLD4DUP: NewOpc = ARMISD::VLD4DUP_UPD; NumVecs = 4; break; |
| 7365 | } |
| 7366 | } |
| 7367 | |
| 7368 | // Find the size of memory referenced by the load/store. |
| 7369 | EVT VecTy; |
| 7370 | if (isLoad) |
| 7371 | VecTy = N->getValueType(0); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 7372 | else |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 7373 | VecTy = N->getOperand(AddrOpIdx+1).getValueType(); |
| 7374 | unsigned NumBytes = NumVecs * VecTy.getSizeInBits() / 8; |
| 7375 | if (isLaneOp) |
| 7376 | NumBytes /= VecTy.getVectorNumElements(); |
| 7377 | |
| 7378 | // If the increment is a constant, it must match the memory ref size. |
| 7379 | SDValue Inc = User->getOperand(User->getOperand(0) == Addr ? 1 : 0); |
| 7380 | if (ConstantSDNode *CInc = dyn_cast<ConstantSDNode>(Inc.getNode())) { |
| 7381 | uint64_t IncVal = CInc->getZExtValue(); |
| 7382 | if (IncVal != NumBytes) |
| 7383 | continue; |
| 7384 | } else if (NumBytes >= 3 * 16) { |
| 7385 | // VLD3/4 and VST3/4 for 128-bit vectors are implemented with two |
| 7386 | // separate instructions that make it harder to use a non-constant update. |
| 7387 | continue; |
| 7388 | } |
| 7389 | |
| 7390 | // Create the new updating load/store node. |
| 7391 | EVT Tys[6]; |
| 7392 | unsigned NumResultVecs = (isLoad ? NumVecs : 0); |
| 7393 | unsigned n; |
| 7394 | for (n = 0; n < NumResultVecs; ++n) |
| 7395 | Tys[n] = VecTy; |
| 7396 | Tys[n++] = MVT::i32; |
| 7397 | Tys[n] = MVT::Other; |
| 7398 | SDVTList SDTys = DAG.getVTList(Tys, NumResultVecs+2); |
| 7399 | SmallVector<SDValue, 8> Ops; |
| 7400 | Ops.push_back(N->getOperand(0)); // incoming chain |
| 7401 | Ops.push_back(N->getOperand(AddrOpIdx)); |
| 7402 | Ops.push_back(Inc); |
| 7403 | for (unsigned i = AddrOpIdx + 1; i < N->getNumOperands(); ++i) { |
| 7404 | Ops.push_back(N->getOperand(i)); |
| 7405 | } |
| 7406 | MemIntrinsicSDNode *MemInt = cast<MemIntrinsicSDNode>(N); |
| 7407 | SDValue UpdN = DAG.getMemIntrinsicNode(NewOpc, N->getDebugLoc(), SDTys, |
| 7408 | Ops.data(), Ops.size(), |
| 7409 | MemInt->getMemoryVT(), |
| 7410 | MemInt->getMemOperand()); |
| 7411 | |
| 7412 | // Update the uses. |
| 7413 | std::vector<SDValue> NewResults; |
| 7414 | for (unsigned i = 0; i < NumResultVecs; ++i) { |
| 7415 | NewResults.push_back(SDValue(UpdN.getNode(), i)); |
| 7416 | } |
| 7417 | NewResults.push_back(SDValue(UpdN.getNode(), NumResultVecs+1)); // chain |
| 7418 | DCI.CombineTo(N, NewResults); |
| 7419 | DCI.CombineTo(User, SDValue(UpdN.getNode(), NumResultVecs)); |
| 7420 | |
| 7421 | break; |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 7422 | } |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 7423 | return SDValue(); |
| 7424 | } |
| 7425 | |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 7426 | /// CombineVLDDUP - For a VDUPLANE node N, check if its source operand is a |
| 7427 | /// vldN-lane (N > 1) intrinsic, and if all the other uses of that intrinsic |
| 7428 | /// are also VDUPLANEs. If so, combine them to a vldN-dup operation and |
| 7429 | /// return true. |
| 7430 | static bool CombineVLDDUP(SDNode *N, TargetLowering::DAGCombinerInfo &DCI) { |
| 7431 | SelectionDAG &DAG = DCI.DAG; |
| 7432 | EVT VT = N->getValueType(0); |
| 7433 | // vldN-dup instructions only support 64-bit vectors for N > 1. |
| 7434 | if (!VT.is64BitVector()) |
| 7435 | return false; |
| 7436 | |
| 7437 | // Check if the VDUPLANE operand is a vldN-dup intrinsic. |
| 7438 | SDNode *VLD = N->getOperand(0).getNode(); |
| 7439 | if (VLD->getOpcode() != ISD::INTRINSIC_W_CHAIN) |
| 7440 | return false; |
| 7441 | unsigned NumVecs = 0; |
| 7442 | unsigned NewOpc = 0; |
| 7443 | unsigned IntNo = cast<ConstantSDNode>(VLD->getOperand(1))->getZExtValue(); |
| 7444 | if (IntNo == Intrinsic::arm_neon_vld2lane) { |
| 7445 | NumVecs = 2; |
| 7446 | NewOpc = ARMISD::VLD2DUP; |
| 7447 | } else if (IntNo == Intrinsic::arm_neon_vld3lane) { |
| 7448 | NumVecs = 3; |
| 7449 | NewOpc = ARMISD::VLD3DUP; |
| 7450 | } else if (IntNo == Intrinsic::arm_neon_vld4lane) { |
| 7451 | NumVecs = 4; |
| 7452 | NewOpc = ARMISD::VLD4DUP; |
| 7453 | } else { |
| 7454 | return false; |
| 7455 | } |
| 7456 | |
| 7457 | // First check that all the vldN-lane uses are VDUPLANEs and that the lane |
| 7458 | // numbers match the load. |
| 7459 | unsigned VLDLaneNo = |
| 7460 | cast<ConstantSDNode>(VLD->getOperand(NumVecs+3))->getZExtValue(); |
| 7461 | for (SDNode::use_iterator UI = VLD->use_begin(), UE = VLD->use_end(); |
| 7462 | UI != UE; ++UI) { |
| 7463 | // Ignore uses of the chain result. |
| 7464 | if (UI.getUse().getResNo() == NumVecs) |
| 7465 | continue; |
| 7466 | SDNode *User = *UI; |
| 7467 | if (User->getOpcode() != ARMISD::VDUPLANE || |
| 7468 | VLDLaneNo != cast<ConstantSDNode>(User->getOperand(1))->getZExtValue()) |
| 7469 | return false; |
| 7470 | } |
| 7471 | |
| 7472 | // Create the vldN-dup node. |
| 7473 | EVT Tys[5]; |
| 7474 | unsigned n; |
| 7475 | for (n = 0; n < NumVecs; ++n) |
| 7476 | Tys[n] = VT; |
| 7477 | Tys[n] = MVT::Other; |
| 7478 | SDVTList SDTys = DAG.getVTList(Tys, NumVecs+1); |
| 7479 | SDValue Ops[] = { VLD->getOperand(0), VLD->getOperand(2) }; |
| 7480 | MemIntrinsicSDNode *VLDMemInt = cast<MemIntrinsicSDNode>(VLD); |
| 7481 | SDValue VLDDup = DAG.getMemIntrinsicNode(NewOpc, VLD->getDebugLoc(), SDTys, |
| 7482 | Ops, 2, VLDMemInt->getMemoryVT(), |
| 7483 | VLDMemInt->getMemOperand()); |
| 7484 | |
| 7485 | // Update the uses. |
| 7486 | for (SDNode::use_iterator UI = VLD->use_begin(), UE = VLD->use_end(); |
| 7487 | UI != UE; ++UI) { |
| 7488 | unsigned ResNo = UI.getUse().getResNo(); |
| 7489 | // Ignore uses of the chain result. |
| 7490 | if (ResNo == NumVecs) |
| 7491 | continue; |
| 7492 | SDNode *User = *UI; |
| 7493 | DCI.CombineTo(User, SDValue(VLDDup.getNode(), ResNo)); |
| 7494 | } |
| 7495 | |
| 7496 | // Now the vldN-lane intrinsic is dead except for its chain result. |
| 7497 | // Update uses of the chain. |
| 7498 | std::vector<SDValue> VLDDupResults; |
| 7499 | for (unsigned n = 0; n < NumVecs; ++n) |
| 7500 | VLDDupResults.push_back(SDValue(VLDDup.getNode(), n)); |
| 7501 | VLDDupResults.push_back(SDValue(VLDDup.getNode(), NumVecs)); |
| 7502 | DCI.CombineTo(VLD, VLDDupResults); |
| 7503 | |
| 7504 | return true; |
| 7505 | } |
| 7506 | |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 7507 | /// PerformVDUPLANECombine - Target-specific dag combine xforms for |
| 7508 | /// ARMISD::VDUPLANE. |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 7509 | static SDValue PerformVDUPLANECombine(SDNode *N, |
| 7510 | TargetLowering::DAGCombinerInfo &DCI) { |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 7511 | SDValue Op = N->getOperand(0); |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 7512 | |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 7513 | // If the source is a vldN-lane (N > 1) intrinsic, and all the other uses |
| 7514 | // of that intrinsic are also VDUPLANEs, combine them to a vldN-dup operation. |
| 7515 | if (CombineVLDDUP(N, DCI)) |
| 7516 | return SDValue(N, 0); |
| 7517 | |
| 7518 | // If the source is already a VMOVIMM or VMVNIMM splat, the VDUPLANE is |
| 7519 | // redundant. Ignore bit_converts for now; element sizes are checked below. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7520 | while (Op.getOpcode() == ISD::BITCAST) |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 7521 | Op = Op.getOperand(0); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 7522 | if (Op.getOpcode() != ARMISD::VMOVIMM && Op.getOpcode() != ARMISD::VMVNIMM) |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 7523 | return SDValue(); |
| 7524 | |
| 7525 | // Make sure the VMOV element size is not bigger than the VDUPLANE elements. |
| 7526 | unsigned EltSize = Op.getValueType().getVectorElementType().getSizeInBits(); |
| 7527 | // The canonical VMOV for a zero vector uses a 32-bit element size. |
| 7528 | unsigned Imm = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
| 7529 | unsigned EltBits; |
| 7530 | if (ARM_AM::decodeNEONModImm(Imm, EltBits) == 0) |
| 7531 | EltSize = 8; |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 7532 | EVT VT = N->getValueType(0); |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 7533 | if (EltSize > VT.getVectorElementType().getSizeInBits()) |
| 7534 | return SDValue(); |
| 7535 | |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 7536 | return DCI.DAG.getNode(ISD::BITCAST, N->getDebugLoc(), VT, Op); |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 7537 | } |
| 7538 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7539 | // 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] | 7540 | // elements are the same constant, C, and Log2(C) ranges from 1 to 32. |
| 7541 | static bool isConstVecPow2(SDValue ConstVec, bool isSigned, uint64_t &C) |
| 7542 | { |
Chad Rosier | 118c9a0 | 2011-06-28 17:26:57 +0000 | [diff] [blame] | 7543 | integerPart cN; |
| 7544 | integerPart c0 = 0; |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 7545 | for (unsigned I = 0, E = ConstVec.getValueType().getVectorNumElements(); |
| 7546 | I != E; I++) { |
| 7547 | ConstantFPSDNode *C = dyn_cast<ConstantFPSDNode>(ConstVec.getOperand(I)); |
| 7548 | if (!C) |
| 7549 | return false; |
| 7550 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7551 | bool isExact; |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 7552 | APFloat APF = C->getValueAPF(); |
| 7553 | if (APF.convertToInteger(&cN, 64, isSigned, APFloat::rmTowardZero, &isExact) |
| 7554 | != APFloat::opOK || !isExact) |
| 7555 | return false; |
| 7556 | |
| 7557 | c0 = (I == 0) ? cN : c0; |
| 7558 | if (!isPowerOf2_64(cN) || c0 != cN || Log2_64(c0) < 1 || Log2_64(c0) > 32) |
| 7559 | return false; |
| 7560 | } |
| 7561 | C = c0; |
| 7562 | return true; |
| 7563 | } |
| 7564 | |
| 7565 | /// PerformVCVTCombine - VCVT (floating-point to fixed-point, Advanced SIMD) |
| 7566 | /// can replace combinations of VMUL and VCVT (floating-point to integer) |
| 7567 | /// when the VMUL has a constant operand that is a power of 2. |
| 7568 | /// |
| 7569 | /// Example (assume d17 = <float 8.000000e+00, float 8.000000e+00>): |
| 7570 | /// vmul.f32 d16, d17, d16 |
| 7571 | /// vcvt.s32.f32 d16, d16 |
| 7572 | /// becomes: |
| 7573 | /// vcvt.s32.f32 d16, d16, #3 |
| 7574 | static SDValue PerformVCVTCombine(SDNode *N, |
| 7575 | TargetLowering::DAGCombinerInfo &DCI, |
| 7576 | const ARMSubtarget *Subtarget) { |
| 7577 | SelectionDAG &DAG = DCI.DAG; |
| 7578 | SDValue Op = N->getOperand(0); |
| 7579 | |
| 7580 | if (!Subtarget->hasNEON() || !Op.getValueType().isVector() || |
| 7581 | Op.getOpcode() != ISD::FMUL) |
| 7582 | return SDValue(); |
| 7583 | |
| 7584 | uint64_t C; |
| 7585 | SDValue N0 = Op->getOperand(0); |
| 7586 | SDValue ConstVec = Op->getOperand(1); |
| 7587 | bool isSigned = N->getOpcode() == ISD::FP_TO_SINT; |
| 7588 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7589 | if (ConstVec.getOpcode() != ISD::BUILD_VECTOR || |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 7590 | !isConstVecPow2(ConstVec, isSigned, C)) |
| 7591 | return SDValue(); |
| 7592 | |
| 7593 | unsigned IntrinsicOpcode = isSigned ? Intrinsic::arm_neon_vcvtfp2fxs : |
| 7594 | Intrinsic::arm_neon_vcvtfp2fxu; |
| 7595 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, N->getDebugLoc(), |
| 7596 | N->getValueType(0), |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7597 | DAG.getConstant(IntrinsicOpcode, MVT::i32), N0, |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 7598 | DAG.getConstant(Log2_64(C), MVT::i32)); |
| 7599 | } |
| 7600 | |
| 7601 | /// PerformVDIVCombine - VCVT (fixed-point to floating-point, Advanced SIMD) |
| 7602 | /// can replace combinations of VCVT (integer to floating-point) and VDIV |
| 7603 | /// when the VDIV has a constant operand that is a power of 2. |
| 7604 | /// |
| 7605 | /// Example (assume d17 = <float 8.000000e+00, float 8.000000e+00>): |
| 7606 | /// vcvt.f32.s32 d16, d16 |
| 7607 | /// vdiv.f32 d16, d17, d16 |
| 7608 | /// becomes: |
| 7609 | /// vcvt.f32.s32 d16, d16, #3 |
| 7610 | static SDValue PerformVDIVCombine(SDNode *N, |
| 7611 | TargetLowering::DAGCombinerInfo &DCI, |
| 7612 | const ARMSubtarget *Subtarget) { |
| 7613 | SelectionDAG &DAG = DCI.DAG; |
| 7614 | SDValue Op = N->getOperand(0); |
| 7615 | unsigned OpOpcode = Op.getNode()->getOpcode(); |
| 7616 | |
| 7617 | if (!Subtarget->hasNEON() || !N->getValueType(0).isVector() || |
| 7618 | (OpOpcode != ISD::SINT_TO_FP && OpOpcode != ISD::UINT_TO_FP)) |
| 7619 | return SDValue(); |
| 7620 | |
| 7621 | uint64_t C; |
| 7622 | SDValue ConstVec = N->getOperand(1); |
| 7623 | bool isSigned = OpOpcode == ISD::SINT_TO_FP; |
| 7624 | |
| 7625 | if (ConstVec.getOpcode() != ISD::BUILD_VECTOR || |
| 7626 | !isConstVecPow2(ConstVec, isSigned, C)) |
| 7627 | return SDValue(); |
| 7628 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7629 | unsigned IntrinsicOpcode = isSigned ? Intrinsic::arm_neon_vcvtfxs2fp : |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 7630 | Intrinsic::arm_neon_vcvtfxu2fp; |
| 7631 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, N->getDebugLoc(), |
| 7632 | Op.getValueType(), |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7633 | DAG.getConstant(IntrinsicOpcode, MVT::i32), |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 7634 | Op.getOperand(0), DAG.getConstant(Log2_64(C), MVT::i32)); |
| 7635 | } |
| 7636 | |
| 7637 | /// Getvshiftimm - Check if this is a valid build_vector for the immediate |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7638 | /// operand of a vector shift operation, where all the elements of the |
| 7639 | /// build_vector must have the same constant integer value. |
| 7640 | static bool getVShiftImm(SDValue Op, unsigned ElementBits, int64_t &Cnt) { |
| 7641 | // Ignore bit_converts. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7642 | while (Op.getOpcode() == ISD::BITCAST) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7643 | Op = Op.getOperand(0); |
| 7644 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(Op.getNode()); |
| 7645 | APInt SplatBits, SplatUndef; |
| 7646 | unsigned SplatBitSize; |
| 7647 | bool HasAnyUndefs; |
| 7648 | if (! BVN || ! BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, |
| 7649 | HasAnyUndefs, ElementBits) || |
| 7650 | SplatBitSize > ElementBits) |
| 7651 | return false; |
| 7652 | Cnt = SplatBits.getSExtValue(); |
| 7653 | return true; |
| 7654 | } |
| 7655 | |
| 7656 | /// isVShiftLImm - Check if this is a valid build_vector for the immediate |
| 7657 | /// operand of a vector shift left operation. That value must be in the range: |
| 7658 | /// 0 <= Value < ElementBits for a left shift; or |
| 7659 | /// 0 <= Value <= ElementBits for a long left shift. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 7660 | static bool isVShiftLImm(SDValue Op, EVT VT, bool isLong, int64_t &Cnt) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7661 | assert(VT.isVector() && "vector shift count is not a vector type"); |
| 7662 | unsigned ElementBits = VT.getVectorElementType().getSizeInBits(); |
| 7663 | if (! getVShiftImm(Op, ElementBits, Cnt)) |
| 7664 | return false; |
| 7665 | return (Cnt >= 0 && (isLong ? Cnt-1 : Cnt) < ElementBits); |
| 7666 | } |
| 7667 | |
| 7668 | /// isVShiftRImm - Check if this is a valid build_vector for the immediate |
| 7669 | /// operand of a vector shift right operation. For a shift opcode, the value |
| 7670 | /// is positive, but for an intrinsic the value count must be negative. The |
| 7671 | /// absolute value must be in the range: |
| 7672 | /// 1 <= |Value| <= ElementBits for a right shift; or |
| 7673 | /// 1 <= |Value| <= ElementBits/2 for a narrow right shift. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 7674 | static bool isVShiftRImm(SDValue Op, EVT VT, bool isNarrow, bool isIntrinsic, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7675 | int64_t &Cnt) { |
| 7676 | assert(VT.isVector() && "vector shift count is not a vector type"); |
| 7677 | unsigned ElementBits = VT.getVectorElementType().getSizeInBits(); |
| 7678 | if (! getVShiftImm(Op, ElementBits, Cnt)) |
| 7679 | return false; |
| 7680 | if (isIntrinsic) |
| 7681 | Cnt = -Cnt; |
| 7682 | return (Cnt >= 1 && Cnt <= (isNarrow ? ElementBits/2 : ElementBits)); |
| 7683 | } |
| 7684 | |
| 7685 | /// PerformIntrinsicCombine - ARM-specific DAG combining for intrinsics. |
| 7686 | static SDValue PerformIntrinsicCombine(SDNode *N, SelectionDAG &DAG) { |
| 7687 | unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue(); |
| 7688 | switch (IntNo) { |
| 7689 | default: |
| 7690 | // Don't do anything for most intrinsics. |
| 7691 | break; |
| 7692 | |
| 7693 | // Vector shifts: check for immediate versions and lower them. |
| 7694 | // Note: This is done during DAG combining instead of DAG legalizing because |
| 7695 | // the build_vectors for 64-bit vector element shift counts are generally |
| 7696 | // not legal, and it is hard to see their values after they get legalized to |
| 7697 | // loads from a constant pool. |
| 7698 | case Intrinsic::arm_neon_vshifts: |
| 7699 | case Intrinsic::arm_neon_vshiftu: |
| 7700 | case Intrinsic::arm_neon_vshiftls: |
| 7701 | case Intrinsic::arm_neon_vshiftlu: |
| 7702 | case Intrinsic::arm_neon_vshiftn: |
| 7703 | case Intrinsic::arm_neon_vrshifts: |
| 7704 | case Intrinsic::arm_neon_vrshiftu: |
| 7705 | case Intrinsic::arm_neon_vrshiftn: |
| 7706 | case Intrinsic::arm_neon_vqshifts: |
| 7707 | case Intrinsic::arm_neon_vqshiftu: |
| 7708 | case Intrinsic::arm_neon_vqshiftsu: |
| 7709 | case Intrinsic::arm_neon_vqshiftns: |
| 7710 | case Intrinsic::arm_neon_vqshiftnu: |
| 7711 | case Intrinsic::arm_neon_vqshiftnsu: |
| 7712 | case Intrinsic::arm_neon_vqrshiftns: |
| 7713 | case Intrinsic::arm_neon_vqrshiftnu: |
| 7714 | case Intrinsic::arm_neon_vqrshiftnsu: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 7715 | EVT VT = N->getOperand(1).getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7716 | int64_t Cnt; |
| 7717 | unsigned VShiftOpc = 0; |
| 7718 | |
| 7719 | switch (IntNo) { |
| 7720 | case Intrinsic::arm_neon_vshifts: |
| 7721 | case Intrinsic::arm_neon_vshiftu: |
| 7722 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) { |
| 7723 | VShiftOpc = ARMISD::VSHL; |
| 7724 | break; |
| 7725 | } |
| 7726 | if (isVShiftRImm(N->getOperand(2), VT, false, true, Cnt)) { |
| 7727 | VShiftOpc = (IntNo == Intrinsic::arm_neon_vshifts ? |
| 7728 | ARMISD::VSHRs : ARMISD::VSHRu); |
| 7729 | break; |
| 7730 | } |
| 7731 | return SDValue(); |
| 7732 | |
| 7733 | case Intrinsic::arm_neon_vshiftls: |
| 7734 | case Intrinsic::arm_neon_vshiftlu: |
| 7735 | if (isVShiftLImm(N->getOperand(2), VT, true, Cnt)) |
| 7736 | break; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 7737 | llvm_unreachable("invalid shift count for vshll intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7738 | |
| 7739 | case Intrinsic::arm_neon_vrshifts: |
| 7740 | case Intrinsic::arm_neon_vrshiftu: |
| 7741 | if (isVShiftRImm(N->getOperand(2), VT, false, true, Cnt)) |
| 7742 | break; |
| 7743 | return SDValue(); |
| 7744 | |
| 7745 | case Intrinsic::arm_neon_vqshifts: |
| 7746 | case Intrinsic::arm_neon_vqshiftu: |
| 7747 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) |
| 7748 | break; |
| 7749 | return SDValue(); |
| 7750 | |
| 7751 | case Intrinsic::arm_neon_vqshiftsu: |
| 7752 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) |
| 7753 | break; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 7754 | llvm_unreachable("invalid shift count for vqshlu intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7755 | |
| 7756 | case Intrinsic::arm_neon_vshiftn: |
| 7757 | case Intrinsic::arm_neon_vrshiftn: |
| 7758 | case Intrinsic::arm_neon_vqshiftns: |
| 7759 | case Intrinsic::arm_neon_vqshiftnu: |
| 7760 | case Intrinsic::arm_neon_vqshiftnsu: |
| 7761 | case Intrinsic::arm_neon_vqrshiftns: |
| 7762 | case Intrinsic::arm_neon_vqrshiftnu: |
| 7763 | case Intrinsic::arm_neon_vqrshiftnsu: |
| 7764 | // Narrowing shifts require an immediate right shift. |
| 7765 | if (isVShiftRImm(N->getOperand(2), VT, true, true, Cnt)) |
| 7766 | break; |
Jim Grosbach | 18f30e6 | 2010-06-02 21:53:11 +0000 | [diff] [blame] | 7767 | llvm_unreachable("invalid shift count for narrowing vector shift " |
| 7768 | "intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7769 | |
| 7770 | default: |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 7771 | llvm_unreachable("unhandled vector shift"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7772 | } |
| 7773 | |
| 7774 | switch (IntNo) { |
| 7775 | case Intrinsic::arm_neon_vshifts: |
| 7776 | case Intrinsic::arm_neon_vshiftu: |
| 7777 | // Opcode already set above. |
| 7778 | break; |
| 7779 | case Intrinsic::arm_neon_vshiftls: |
| 7780 | case Intrinsic::arm_neon_vshiftlu: |
| 7781 | if (Cnt == VT.getVectorElementType().getSizeInBits()) |
| 7782 | VShiftOpc = ARMISD::VSHLLi; |
| 7783 | else |
| 7784 | VShiftOpc = (IntNo == Intrinsic::arm_neon_vshiftls ? |
| 7785 | ARMISD::VSHLLs : ARMISD::VSHLLu); |
| 7786 | break; |
| 7787 | case Intrinsic::arm_neon_vshiftn: |
| 7788 | VShiftOpc = ARMISD::VSHRN; break; |
| 7789 | case Intrinsic::arm_neon_vrshifts: |
| 7790 | VShiftOpc = ARMISD::VRSHRs; break; |
| 7791 | case Intrinsic::arm_neon_vrshiftu: |
| 7792 | VShiftOpc = ARMISD::VRSHRu; break; |
| 7793 | case Intrinsic::arm_neon_vrshiftn: |
| 7794 | VShiftOpc = ARMISD::VRSHRN; break; |
| 7795 | case Intrinsic::arm_neon_vqshifts: |
| 7796 | VShiftOpc = ARMISD::VQSHLs; break; |
| 7797 | case Intrinsic::arm_neon_vqshiftu: |
| 7798 | VShiftOpc = ARMISD::VQSHLu; break; |
| 7799 | case Intrinsic::arm_neon_vqshiftsu: |
| 7800 | VShiftOpc = ARMISD::VQSHLsu; break; |
| 7801 | case Intrinsic::arm_neon_vqshiftns: |
| 7802 | VShiftOpc = ARMISD::VQSHRNs; break; |
| 7803 | case Intrinsic::arm_neon_vqshiftnu: |
| 7804 | VShiftOpc = ARMISD::VQSHRNu; break; |
| 7805 | case Intrinsic::arm_neon_vqshiftnsu: |
| 7806 | VShiftOpc = ARMISD::VQSHRNsu; break; |
| 7807 | case Intrinsic::arm_neon_vqrshiftns: |
| 7808 | VShiftOpc = ARMISD::VQRSHRNs; break; |
| 7809 | case Intrinsic::arm_neon_vqrshiftnu: |
| 7810 | VShiftOpc = ARMISD::VQRSHRNu; break; |
| 7811 | case Intrinsic::arm_neon_vqrshiftnsu: |
| 7812 | VShiftOpc = ARMISD::VQRSHRNsu; break; |
| 7813 | } |
| 7814 | |
| 7815 | return DAG.getNode(VShiftOpc, N->getDebugLoc(), N->getValueType(0), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 7816 | N->getOperand(1), DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7817 | } |
| 7818 | |
| 7819 | case Intrinsic::arm_neon_vshiftins: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 7820 | EVT VT = N->getOperand(1).getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7821 | int64_t Cnt; |
| 7822 | unsigned VShiftOpc = 0; |
| 7823 | |
| 7824 | if (isVShiftLImm(N->getOperand(3), VT, false, Cnt)) |
| 7825 | VShiftOpc = ARMISD::VSLI; |
| 7826 | else if (isVShiftRImm(N->getOperand(3), VT, false, true, Cnt)) |
| 7827 | VShiftOpc = ARMISD::VSRI; |
| 7828 | else { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 7829 | llvm_unreachable("invalid shift count for vsli/vsri intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7830 | } |
| 7831 | |
| 7832 | return DAG.getNode(VShiftOpc, N->getDebugLoc(), N->getValueType(0), |
| 7833 | N->getOperand(1), N->getOperand(2), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 7834 | DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7835 | } |
| 7836 | |
| 7837 | case Intrinsic::arm_neon_vqrshifts: |
| 7838 | case Intrinsic::arm_neon_vqrshiftu: |
| 7839 | // No immediate versions of these to check for. |
| 7840 | break; |
| 7841 | } |
| 7842 | |
| 7843 | return SDValue(); |
| 7844 | } |
| 7845 | |
| 7846 | /// PerformShiftCombine - Checks for immediate versions of vector shifts and |
| 7847 | /// lowers them. As with the vector shift intrinsics, this is done during DAG |
| 7848 | /// combining instead of DAG legalizing because the build_vectors for 64-bit |
| 7849 | /// vector element shift counts are generally not legal, and it is hard to see |
| 7850 | /// their values after they get legalized to loads from a constant pool. |
| 7851 | static SDValue PerformShiftCombine(SDNode *N, SelectionDAG &DAG, |
| 7852 | const ARMSubtarget *ST) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 7853 | EVT VT = N->getValueType(0); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7854 | |
| 7855 | // Nothing to be done for scalar shifts. |
Tanya Lattner | 9684a7c | 2010-11-18 22:06:46 +0000 | [diff] [blame] | 7856 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 7857 | if (!VT.isVector() || !TLI.isTypeLegal(VT)) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7858 | return SDValue(); |
| 7859 | |
| 7860 | assert(ST->hasNEON() && "unexpected vector shift"); |
| 7861 | int64_t Cnt; |
| 7862 | |
| 7863 | switch (N->getOpcode()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 7864 | default: llvm_unreachable("unexpected shift opcode"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7865 | |
| 7866 | case ISD::SHL: |
| 7867 | if (isVShiftLImm(N->getOperand(1), VT, false, Cnt)) |
| 7868 | return DAG.getNode(ARMISD::VSHL, N->getDebugLoc(), VT, N->getOperand(0), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 7869 | DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7870 | break; |
| 7871 | |
| 7872 | case ISD::SRA: |
| 7873 | case ISD::SRL: |
| 7874 | if (isVShiftRImm(N->getOperand(1), VT, false, false, Cnt)) { |
| 7875 | unsigned VShiftOpc = (N->getOpcode() == ISD::SRA ? |
| 7876 | ARMISD::VSHRs : ARMISD::VSHRu); |
| 7877 | return DAG.getNode(VShiftOpc, N->getDebugLoc(), VT, N->getOperand(0), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 7878 | DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7879 | } |
| 7880 | } |
| 7881 | return SDValue(); |
| 7882 | } |
| 7883 | |
| 7884 | /// PerformExtendCombine - Target-specific DAG combining for ISD::SIGN_EXTEND, |
| 7885 | /// ISD::ZERO_EXTEND, and ISD::ANY_EXTEND. |
| 7886 | static SDValue PerformExtendCombine(SDNode *N, SelectionDAG &DAG, |
| 7887 | const ARMSubtarget *ST) { |
| 7888 | SDValue N0 = N->getOperand(0); |
| 7889 | |
| 7890 | // Check for sign- and zero-extensions of vector extract operations of 8- |
| 7891 | // and 16-bit vector elements. NEON supports these directly. They are |
| 7892 | // handled during DAG combining because type legalization will promote them |
| 7893 | // to 32-bit types and it is messy to recognize the operations after that. |
| 7894 | if (ST->hasNEON() && N0.getOpcode() == ISD::EXTRACT_VECTOR_ELT) { |
| 7895 | SDValue Vec = N0.getOperand(0); |
| 7896 | SDValue Lane = N0.getOperand(1); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 7897 | EVT VT = N->getValueType(0); |
| 7898 | EVT EltVT = N0.getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7899 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 7900 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 7901 | if (VT == MVT::i32 && |
| 7902 | (EltVT == MVT::i8 || EltVT == MVT::i16) && |
Bob Wilson | 3468c2e | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 7903 | TLI.isTypeLegal(Vec.getValueType()) && |
| 7904 | isa<ConstantSDNode>(Lane)) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7905 | |
| 7906 | unsigned Opc = 0; |
| 7907 | switch (N->getOpcode()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 7908 | default: llvm_unreachable("unexpected opcode"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7909 | case ISD::SIGN_EXTEND: |
| 7910 | Opc = ARMISD::VGETLANEs; |
| 7911 | break; |
| 7912 | case ISD::ZERO_EXTEND: |
| 7913 | case ISD::ANY_EXTEND: |
| 7914 | Opc = ARMISD::VGETLANEu; |
| 7915 | break; |
| 7916 | } |
| 7917 | return DAG.getNode(Opc, N->getDebugLoc(), VT, Vec, Lane); |
| 7918 | } |
| 7919 | } |
| 7920 | |
| 7921 | return SDValue(); |
| 7922 | } |
| 7923 | |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 7924 | /// PerformSELECT_CCCombine - Target-specific DAG combining for ISD::SELECT_CC |
| 7925 | /// to match f32 max/min patterns to use NEON vmax/vmin instructions. |
| 7926 | static SDValue PerformSELECT_CCCombine(SDNode *N, SelectionDAG &DAG, |
| 7927 | const ARMSubtarget *ST) { |
| 7928 | // 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] | 7929 | // selects like "x < y ? x : y". Unless the NoNaNsFPMath option is set, |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 7930 | // be careful about NaNs: NEON's vmax/vmin return NaN if either operand is |
| 7931 | // a NaN; only do the transformation when it matches that behavior. |
| 7932 | |
| 7933 | // For now only do this when using NEON for FP operations; if using VFP, it |
| 7934 | // is not obvious that the benefit outweighs the cost of switching to the |
| 7935 | // NEON pipeline. |
| 7936 | if (!ST->hasNEON() || !ST->useNEONForSinglePrecisionFP() || |
| 7937 | N->getValueType(0) != MVT::f32) |
| 7938 | return SDValue(); |
| 7939 | |
| 7940 | SDValue CondLHS = N->getOperand(0); |
| 7941 | SDValue CondRHS = N->getOperand(1); |
| 7942 | SDValue LHS = N->getOperand(2); |
| 7943 | SDValue RHS = N->getOperand(3); |
| 7944 | ISD::CondCode CC = cast<CondCodeSDNode>(N->getOperand(4))->get(); |
| 7945 | |
| 7946 | unsigned Opcode = 0; |
| 7947 | bool IsReversed; |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 7948 | if (DAG.isEqualTo(LHS, CondLHS) && DAG.isEqualTo(RHS, CondRHS)) { |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 7949 | IsReversed = false; // x CC y ? x : y |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 7950 | } else if (DAG.isEqualTo(LHS, CondRHS) && DAG.isEqualTo(RHS, CondLHS)) { |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 7951 | IsReversed = true ; // x CC y ? y : x |
| 7952 | } else { |
| 7953 | return SDValue(); |
| 7954 | } |
| 7955 | |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 7956 | bool IsUnordered; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 7957 | switch (CC) { |
| 7958 | default: break; |
| 7959 | case ISD::SETOLT: |
| 7960 | case ISD::SETOLE: |
| 7961 | case ISD::SETLT: |
| 7962 | case ISD::SETLE: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 7963 | case ISD::SETULT: |
| 7964 | case ISD::SETULE: |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 7965 | // If LHS is NaN, an ordered comparison will be false and the result will |
| 7966 | // be the RHS, but vmin(NaN, RHS) = NaN. Avoid this by checking that LHS |
| 7967 | // != NaN. Likewise, for unordered comparisons, check for RHS != NaN. |
| 7968 | IsUnordered = (CC == ISD::SETULT || CC == ISD::SETULE); |
| 7969 | if (!DAG.isKnownNeverNaN(IsUnordered ? RHS : LHS)) |
| 7970 | break; |
| 7971 | // For less-than-or-equal comparisons, "+0 <= -0" will be true but vmin |
| 7972 | // will return -0, so vmin can only be used for unsafe math or if one of |
| 7973 | // the operands is known to be nonzero. |
| 7974 | if ((CC == ISD::SETLE || CC == ISD::SETOLE || CC == ISD::SETULE) && |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 7975 | !DAG.getTarget().Options.UnsafeFPMath && |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 7976 | !(DAG.isKnownNeverZero(LHS) || DAG.isKnownNeverZero(RHS))) |
| 7977 | break; |
| 7978 | Opcode = IsReversed ? ARMISD::FMAX : ARMISD::FMIN; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 7979 | break; |
| 7980 | |
| 7981 | case ISD::SETOGT: |
| 7982 | case ISD::SETOGE: |
| 7983 | case ISD::SETGT: |
| 7984 | case ISD::SETGE: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 7985 | case ISD::SETUGT: |
| 7986 | case ISD::SETUGE: |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 7987 | // If LHS is NaN, an ordered comparison will be false and the result will |
| 7988 | // be the RHS, but vmax(NaN, RHS) = NaN. Avoid this by checking that LHS |
| 7989 | // != NaN. Likewise, for unordered comparisons, check for RHS != NaN. |
| 7990 | IsUnordered = (CC == ISD::SETUGT || CC == ISD::SETUGE); |
| 7991 | if (!DAG.isKnownNeverNaN(IsUnordered ? RHS : LHS)) |
| 7992 | break; |
| 7993 | // For greater-than-or-equal comparisons, "-0 >= +0" will be true but vmax |
| 7994 | // will return +0, so vmax can only be used for unsafe math or if one of |
| 7995 | // the operands is known to be nonzero. |
| 7996 | if ((CC == ISD::SETGE || CC == ISD::SETOGE || CC == ISD::SETUGE) && |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 7997 | !DAG.getTarget().Options.UnsafeFPMath && |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 7998 | !(DAG.isKnownNeverZero(LHS) || DAG.isKnownNeverZero(RHS))) |
| 7999 | break; |
| 8000 | Opcode = IsReversed ? ARMISD::FMIN : ARMISD::FMAX; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8001 | break; |
| 8002 | } |
| 8003 | |
| 8004 | if (!Opcode) |
| 8005 | return SDValue(); |
| 8006 | return DAG.getNode(Opcode, N->getDebugLoc(), N->getValueType(0), LHS, RHS); |
| 8007 | } |
| 8008 | |
Evan Cheng | e721f5c | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 8009 | /// PerformCMOVCombine - Target-specific DAG combining for ARMISD::CMOV. |
| 8010 | SDValue |
| 8011 | ARMTargetLowering::PerformCMOVCombine(SDNode *N, SelectionDAG &DAG) const { |
| 8012 | SDValue Cmp = N->getOperand(4); |
| 8013 | if (Cmp.getOpcode() != ARMISD::CMPZ) |
| 8014 | // Only looking at EQ and NE cases. |
| 8015 | return SDValue(); |
| 8016 | |
| 8017 | EVT VT = N->getValueType(0); |
| 8018 | DebugLoc dl = N->getDebugLoc(); |
| 8019 | SDValue LHS = Cmp.getOperand(0); |
| 8020 | SDValue RHS = Cmp.getOperand(1); |
| 8021 | SDValue FalseVal = N->getOperand(0); |
| 8022 | SDValue TrueVal = N->getOperand(1); |
| 8023 | SDValue ARMcc = N->getOperand(2); |
Jim Grosbach | b04546f | 2011-09-13 20:30:37 +0000 | [diff] [blame] | 8024 | ARMCC::CondCodes CC = |
| 8025 | (ARMCC::CondCodes)cast<ConstantSDNode>(ARMcc)->getZExtValue(); |
Evan Cheng | e721f5c | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 8026 | |
| 8027 | // Simplify |
| 8028 | // mov r1, r0 |
| 8029 | // cmp r1, x |
| 8030 | // mov r0, y |
| 8031 | // moveq r0, x |
| 8032 | // to |
| 8033 | // cmp r0, x |
| 8034 | // movne r0, y |
| 8035 | // |
| 8036 | // mov r1, r0 |
| 8037 | // cmp r1, x |
| 8038 | // mov r0, x |
| 8039 | // movne r0, y |
| 8040 | // to |
| 8041 | // cmp r0, x |
| 8042 | // movne r0, y |
| 8043 | /// FIXME: Turn this into a target neutral optimization? |
| 8044 | SDValue Res; |
Evan Cheng | 9b88d2d | 2011-09-28 23:16:31 +0000 | [diff] [blame] | 8045 | if (CC == ARMCC::NE && FalseVal == RHS && FalseVal != LHS) { |
Evan Cheng | e721f5c | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 8046 | Res = DAG.getNode(ARMISD::CMOV, dl, VT, LHS, TrueVal, ARMcc, |
| 8047 | N->getOperand(3), Cmp); |
| 8048 | } else if (CC == ARMCC::EQ && TrueVal == RHS) { |
| 8049 | SDValue ARMcc; |
| 8050 | SDValue NewCmp = getARMCmp(LHS, RHS, ISD::SETNE, ARMcc, DAG, dl); |
| 8051 | Res = DAG.getNode(ARMISD::CMOV, dl, VT, LHS, FalseVal, ARMcc, |
| 8052 | N->getOperand(3), NewCmp); |
| 8053 | } |
| 8054 | |
| 8055 | if (Res.getNode()) { |
| 8056 | APInt KnownZero, KnownOne; |
| 8057 | APInt Mask = APInt::getAllOnesValue(VT.getScalarType().getSizeInBits()); |
| 8058 | DAG.ComputeMaskedBits(SDValue(N,0), Mask, KnownZero, KnownOne); |
| 8059 | // Capture demanded bits information that would be otherwise lost. |
| 8060 | if (KnownZero == 0xfffffffe) |
| 8061 | Res = DAG.getNode(ISD::AssertZext, dl, MVT::i32, Res, |
| 8062 | DAG.getValueType(MVT::i1)); |
| 8063 | else if (KnownZero == 0xffffff00) |
| 8064 | Res = DAG.getNode(ISD::AssertZext, dl, MVT::i32, Res, |
| 8065 | DAG.getValueType(MVT::i8)); |
| 8066 | else if (KnownZero == 0xffff0000) |
| 8067 | Res = DAG.getNode(ISD::AssertZext, dl, MVT::i32, Res, |
| 8068 | DAG.getValueType(MVT::i16)); |
| 8069 | } |
| 8070 | |
| 8071 | return Res; |
| 8072 | } |
| 8073 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 8074 | SDValue ARMTargetLowering::PerformDAGCombine(SDNode *N, |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 8075 | DAGCombinerInfo &DCI) const { |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 8076 | switch (N->getOpcode()) { |
| 8077 | default: break; |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8078 | case ISD::ADD: return PerformADDCombine(N, DCI, Subtarget); |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8079 | case ISD::SUB: return PerformSUBCombine(N, DCI); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 8080 | case ISD::MUL: return PerformMULCombine(N, DCI, Subtarget); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8081 | case ISD::OR: return PerformORCombine(N, DCI, Subtarget); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 8082 | case ISD::AND: return PerformANDCombine(N, DCI); |
Evan Cheng | 0c1aec1 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 8083 | case ARMISD::BFI: return PerformBFICombine(N, DCI); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 8084 | case ARMISD::VMOVRRD: return PerformVMOVRRDCombine(N, DCI); |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 8085 | case ARMISD::VMOVDRR: return PerformVMOVDRRCombine(N, DCI.DAG); |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 8086 | case ISD::STORE: return PerformSTORECombine(N, DCI); |
| 8087 | case ISD::BUILD_VECTOR: return PerformBUILD_VECTORCombine(N, DCI); |
| 8088 | case ISD::INSERT_VECTOR_ELT: return PerformInsertEltCombine(N, DCI); |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 8089 | case ISD::VECTOR_SHUFFLE: return PerformVECTOR_SHUFFLECombine(N, DCI.DAG); |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 8090 | case ARMISD::VDUPLANE: return PerformVDUPLANECombine(N, DCI); |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 8091 | case ISD::FP_TO_SINT: |
| 8092 | case ISD::FP_TO_UINT: return PerformVCVTCombine(N, DCI, Subtarget); |
| 8093 | case ISD::FDIV: return PerformVDIVCombine(N, DCI, Subtarget); |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8094 | case ISD::INTRINSIC_WO_CHAIN: return PerformIntrinsicCombine(N, DCI.DAG); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8095 | case ISD::SHL: |
| 8096 | case ISD::SRA: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8097 | case ISD::SRL: return PerformShiftCombine(N, DCI.DAG, Subtarget); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8098 | case ISD::SIGN_EXTEND: |
| 8099 | case ISD::ZERO_EXTEND: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 8100 | case ISD::ANY_EXTEND: return PerformExtendCombine(N, DCI.DAG, Subtarget); |
| 8101 | case ISD::SELECT_CC: return PerformSELECT_CCCombine(N, DCI.DAG, Subtarget); |
Evan Cheng | e721f5c | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 8102 | case ARMISD::CMOV: return PerformCMOVCombine(N, DCI.DAG); |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 8103 | case ARMISD::VLD2DUP: |
| 8104 | case ARMISD::VLD3DUP: |
| 8105 | case ARMISD::VLD4DUP: |
| 8106 | return CombineBaseUpdate(N, DCI); |
| 8107 | case ISD::INTRINSIC_VOID: |
| 8108 | case ISD::INTRINSIC_W_CHAIN: |
| 8109 | switch (cast<ConstantSDNode>(N->getOperand(1))->getZExtValue()) { |
| 8110 | case Intrinsic::arm_neon_vld1: |
| 8111 | case Intrinsic::arm_neon_vld2: |
| 8112 | case Intrinsic::arm_neon_vld3: |
| 8113 | case Intrinsic::arm_neon_vld4: |
| 8114 | case Intrinsic::arm_neon_vld2lane: |
| 8115 | case Intrinsic::arm_neon_vld3lane: |
| 8116 | case Intrinsic::arm_neon_vld4lane: |
| 8117 | case Intrinsic::arm_neon_vst1: |
| 8118 | case Intrinsic::arm_neon_vst2: |
| 8119 | case Intrinsic::arm_neon_vst3: |
| 8120 | case Intrinsic::arm_neon_vst4: |
| 8121 | case Intrinsic::arm_neon_vst2lane: |
| 8122 | case Intrinsic::arm_neon_vst3lane: |
| 8123 | case Intrinsic::arm_neon_vst4lane: |
| 8124 | return CombineBaseUpdate(N, DCI); |
| 8125 | default: break; |
| 8126 | } |
| 8127 | break; |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 8128 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 8129 | return SDValue(); |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 8130 | } |
| 8131 | |
Evan Cheng | 31959b1 | 2011-02-02 01:06:55 +0000 | [diff] [blame] | 8132 | bool ARMTargetLowering::isDesirableToTransformToIntegerOp(unsigned Opc, |
| 8133 | EVT VT) const { |
| 8134 | return (VT == MVT::f32) && (Opc == ISD::LOAD || Opc == ISD::STORE); |
| 8135 | } |
| 8136 | |
Bill Wendling | af56634 | 2009-08-15 21:21:19 +0000 | [diff] [blame] | 8137 | bool ARMTargetLowering::allowsUnalignedMemoryAccesses(EVT VT) const { |
Bob Wilson | 02aba73 | 2010-09-28 04:09:35 +0000 | [diff] [blame] | 8138 | if (!Subtarget->allowsUnalignedMem()) |
Bob Wilson | 86fe66d | 2010-06-25 04:12:31 +0000 | [diff] [blame] | 8139 | return false; |
Bill Wendling | af56634 | 2009-08-15 21:21:19 +0000 | [diff] [blame] | 8140 | |
| 8141 | switch (VT.getSimpleVT().SimpleTy) { |
| 8142 | default: |
| 8143 | return false; |
| 8144 | case MVT::i8: |
| 8145 | case MVT::i16: |
| 8146 | case MVT::i32: |
| 8147 | return true; |
| 8148 | // FIXME: VLD1 etc with standard alignment is legal. |
| 8149 | } |
| 8150 | } |
| 8151 | |
Lang Hames | 1a1d1fc | 2011-11-02 22:52:45 +0000 | [diff] [blame] | 8152 | static bool memOpAlign(unsigned DstAlign, unsigned SrcAlign, |
| 8153 | unsigned AlignCheck) { |
| 8154 | return ((SrcAlign == 0 || SrcAlign % AlignCheck == 0) && |
| 8155 | (DstAlign == 0 || DstAlign % AlignCheck == 0)); |
| 8156 | } |
| 8157 | |
| 8158 | EVT ARMTargetLowering::getOptimalMemOpType(uint64_t Size, |
| 8159 | unsigned DstAlign, unsigned SrcAlign, |
Lang Hames | a1e7888 | 2011-11-02 23:37:04 +0000 | [diff] [blame] | 8160 | bool IsZeroVal, |
Lang Hames | 1a1d1fc | 2011-11-02 22:52:45 +0000 | [diff] [blame] | 8161 | bool MemcpyStrSrc, |
| 8162 | MachineFunction &MF) const { |
| 8163 | const Function *F = MF.getFunction(); |
| 8164 | |
| 8165 | // See if we can use NEON instructions for this... |
Lang Hames | a1e7888 | 2011-11-02 23:37:04 +0000 | [diff] [blame] | 8166 | if (IsZeroVal && |
Lang Hames | 1a1d1fc | 2011-11-02 22:52:45 +0000 | [diff] [blame] | 8167 | !F->hasFnAttr(Attribute::NoImplicitFloat) && |
| 8168 | Subtarget->hasNEON()) { |
| 8169 | if (memOpAlign(SrcAlign, DstAlign, 16) && Size >= 16) { |
| 8170 | return MVT::v4i32; |
| 8171 | } else if (memOpAlign(SrcAlign, DstAlign, 8) && Size >= 8) { |
| 8172 | return MVT::v2i32; |
| 8173 | } |
| 8174 | } |
| 8175 | |
Lang Hames | 5207bf2 | 2011-11-08 18:56:23 +0000 | [diff] [blame] | 8176 | // Lowering to i32/i16 if the size permits. |
| 8177 | if (Size >= 4) { |
| 8178 | return MVT::i32; |
| 8179 | } else if (Size >= 2) { |
| 8180 | return MVT::i16; |
| 8181 | } |
| 8182 | |
Lang Hames | 1a1d1fc | 2011-11-02 22:52:45 +0000 | [diff] [blame] | 8183 | // Let the target-independent logic figure it out. |
| 8184 | return MVT::Other; |
| 8185 | } |
| 8186 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 8187 | static bool isLegalT1AddressImmediate(int64_t V, EVT VT) { |
| 8188 | if (V < 0) |
| 8189 | return false; |
| 8190 | |
| 8191 | unsigned Scale = 1; |
| 8192 | switch (VT.getSimpleVT().SimpleTy) { |
| 8193 | default: return false; |
| 8194 | case MVT::i1: |
| 8195 | case MVT::i8: |
| 8196 | // Scale == 1; |
| 8197 | break; |
| 8198 | case MVT::i16: |
| 8199 | // Scale == 2; |
| 8200 | Scale = 2; |
| 8201 | break; |
| 8202 | case MVT::i32: |
| 8203 | // Scale == 4; |
| 8204 | Scale = 4; |
| 8205 | break; |
| 8206 | } |
| 8207 | |
| 8208 | if ((V & (Scale - 1)) != 0) |
| 8209 | return false; |
| 8210 | V /= Scale; |
| 8211 | return V == (V & ((1LL << 5) - 1)); |
| 8212 | } |
| 8213 | |
| 8214 | static bool isLegalT2AddressImmediate(int64_t V, EVT VT, |
| 8215 | const ARMSubtarget *Subtarget) { |
| 8216 | bool isNeg = false; |
| 8217 | if (V < 0) { |
| 8218 | isNeg = true; |
| 8219 | V = - V; |
| 8220 | } |
| 8221 | |
| 8222 | switch (VT.getSimpleVT().SimpleTy) { |
| 8223 | default: return false; |
| 8224 | case MVT::i1: |
| 8225 | case MVT::i8: |
| 8226 | case MVT::i16: |
| 8227 | case MVT::i32: |
| 8228 | // + imm12 or - imm8 |
| 8229 | if (isNeg) |
| 8230 | return V == (V & ((1LL << 8) - 1)); |
| 8231 | return V == (V & ((1LL << 12) - 1)); |
| 8232 | case MVT::f32: |
| 8233 | case MVT::f64: |
| 8234 | // Same as ARM mode. FIXME: NEON? |
| 8235 | if (!Subtarget->hasVFP2()) |
| 8236 | return false; |
| 8237 | if ((V & 3) != 0) |
| 8238 | return false; |
| 8239 | V >>= 2; |
| 8240 | return V == (V & ((1LL << 8) - 1)); |
| 8241 | } |
| 8242 | } |
| 8243 | |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8244 | /// isLegalAddressImmediate - Return true if the integer value can be used |
| 8245 | /// as the offset of the target addressing mode for load / store of the |
| 8246 | /// given type. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8247 | static bool isLegalAddressImmediate(int64_t V, EVT VT, |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8248 | const ARMSubtarget *Subtarget) { |
Evan Cheng | 961f879 | 2007-03-13 20:37:59 +0000 | [diff] [blame] | 8249 | if (V == 0) |
| 8250 | return true; |
| 8251 | |
Evan Cheng | 6501153 | 2009-03-09 19:15:00 +0000 | [diff] [blame] | 8252 | if (!VT.isSimple()) |
| 8253 | return false; |
| 8254 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 8255 | if (Subtarget->isThumb1Only()) |
| 8256 | return isLegalT1AddressImmediate(V, VT); |
| 8257 | else if (Subtarget->isThumb2()) |
| 8258 | return isLegalT2AddressImmediate(V, VT, Subtarget); |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8259 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 8260 | // ARM mode. |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8261 | if (V < 0) |
| 8262 | V = - V; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8263 | switch (VT.getSimpleVT().SimpleTy) { |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8264 | default: return false; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8265 | case MVT::i1: |
| 8266 | case MVT::i8: |
| 8267 | case MVT::i32: |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8268 | // +- imm12 |
Anton Korobeynikov | 7c1c261 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 8269 | return V == (V & ((1LL << 12) - 1)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8270 | case MVT::i16: |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8271 | // +- imm8 |
Anton Korobeynikov | 7c1c261 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 8272 | return V == (V & ((1LL << 8) - 1)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8273 | case MVT::f32: |
| 8274 | case MVT::f64: |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 8275 | if (!Subtarget->hasVFP2()) // FIXME: NEON? |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8276 | return false; |
Evan Cheng | 0b0a9a9 | 2007-05-03 02:00:18 +0000 | [diff] [blame] | 8277 | if ((V & 3) != 0) |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8278 | return false; |
| 8279 | V >>= 2; |
Anton Korobeynikov | 7c1c261 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 8280 | return V == (V & ((1LL << 8) - 1)); |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8281 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8282 | } |
| 8283 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 8284 | bool ARMTargetLowering::isLegalT2ScaledAddressingMode(const AddrMode &AM, |
| 8285 | EVT VT) const { |
| 8286 | int Scale = AM.Scale; |
| 8287 | if (Scale < 0) |
| 8288 | return false; |
| 8289 | |
| 8290 | switch (VT.getSimpleVT().SimpleTy) { |
| 8291 | default: return false; |
| 8292 | case MVT::i1: |
| 8293 | case MVT::i8: |
| 8294 | case MVT::i16: |
| 8295 | case MVT::i32: |
| 8296 | if (Scale == 1) |
| 8297 | return true; |
| 8298 | // r + r << imm |
| 8299 | Scale = Scale & ~1; |
| 8300 | return Scale == 2 || Scale == 4 || Scale == 8; |
| 8301 | case MVT::i64: |
| 8302 | // r + r |
| 8303 | if (((unsigned)AM.HasBaseReg + Scale) <= 2) |
| 8304 | return true; |
| 8305 | return false; |
| 8306 | case MVT::isVoid: |
| 8307 | // Note, we allow "void" uses (basically, uses that aren't loads or |
| 8308 | // stores), because arm allows folding a scale into many arithmetic |
| 8309 | // operations. This should be made more precise and revisited later. |
| 8310 | |
| 8311 | // Allow r << imm, but the imm has to be a multiple of two. |
| 8312 | if (Scale & 1) return false; |
| 8313 | return isPowerOf2_32(Scale); |
| 8314 | } |
| 8315 | } |
| 8316 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8317 | /// isLegalAddressingMode - Return true if the addressing mode represented |
| 8318 | /// 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] | 8319 | bool ARMTargetLowering::isLegalAddressingMode(const AddrMode &AM, |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 8320 | Type *Ty) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8321 | EVT VT = getValueType(Ty, true); |
Bob Wilson | 2c7dab1 | 2009-04-08 17:55:28 +0000 | [diff] [blame] | 8322 | if (!isLegalAddressImmediate(AM.BaseOffs, VT, Subtarget)) |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8323 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 8324 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8325 | // Can never fold addr of global into load/store. |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 8326 | if (AM.BaseGV) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8327 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 8328 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8329 | switch (AM.Scale) { |
| 8330 | case 0: // no scale reg, must be "r+i" or "r", or "i". |
| 8331 | break; |
| 8332 | case 1: |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 8333 | if (Subtarget->isThumb1Only()) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8334 | return false; |
Chris Lattner | 5a3d40d | 2007-04-13 06:50:55 +0000 | [diff] [blame] | 8335 | // FALL THROUGH. |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8336 | default: |
Chris Lattner | 5a3d40d | 2007-04-13 06:50:55 +0000 | [diff] [blame] | 8337 | // ARM doesn't support any R+R*scale+imm addr modes. |
| 8338 | if (AM.BaseOffs) |
| 8339 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 8340 | |
Bob Wilson | 2c7dab1 | 2009-04-08 17:55:28 +0000 | [diff] [blame] | 8341 | if (!VT.isSimple()) |
| 8342 | return false; |
| 8343 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 8344 | if (Subtarget->isThumb2()) |
| 8345 | return isLegalT2ScaledAddressingMode(AM, VT); |
| 8346 | |
Chris Lattner | eb13d1b | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 8347 | int Scale = AM.Scale; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8348 | switch (VT.getSimpleVT().SimpleTy) { |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8349 | default: return false; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8350 | case MVT::i1: |
| 8351 | case MVT::i8: |
| 8352 | case MVT::i32: |
Chris Lattner | eb13d1b | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 8353 | if (Scale < 0) Scale = -Scale; |
| 8354 | if (Scale == 1) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8355 | return true; |
| 8356 | // r + r << imm |
Chris Lattner | e115294 | 2007-04-11 16:17:12 +0000 | [diff] [blame] | 8357 | return isPowerOf2_32(Scale & ~1); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8358 | case MVT::i16: |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 8359 | case MVT::i64: |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8360 | // r + r |
Chris Lattner | eb13d1b | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 8361 | if (((unsigned)AM.HasBaseReg + Scale) <= 2) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8362 | return true; |
Chris Lattner | e115294 | 2007-04-11 16:17:12 +0000 | [diff] [blame] | 8363 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 8364 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8365 | case MVT::isVoid: |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8366 | // Note, we allow "void" uses (basically, uses that aren't loads or |
| 8367 | // stores), because arm allows folding a scale into many arithmetic |
| 8368 | // operations. This should be made more precise and revisited later. |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 8369 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8370 | // 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] | 8371 | if (Scale & 1) return false; |
| 8372 | return isPowerOf2_32(Scale); |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8373 | } |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8374 | } |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 8375 | return true; |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 8376 | } |
| 8377 | |
Evan Cheng | 77e4751 | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 8378 | /// isLegalICmpImmediate - Return true if the specified immediate is legal |
| 8379 | /// icmp immediate, that is the target has icmp instructions which can compare |
| 8380 | /// a register against the immediate without having to materialize the |
| 8381 | /// immediate into a register. |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 8382 | bool ARMTargetLowering::isLegalICmpImmediate(int64_t Imm) const { |
Evan Cheng | 77e4751 | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 8383 | if (!Subtarget->isThumb()) |
| 8384 | return ARM_AM::getSOImmVal(Imm) != -1; |
| 8385 | if (Subtarget->isThumb2()) |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 8386 | return ARM_AM::getT2SOImmVal(Imm) != -1; |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 8387 | return Imm >= 0 && Imm <= 255; |
Evan Cheng | 77e4751 | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 8388 | } |
| 8389 | |
Dan Gohman | cca8214 | 2011-05-03 00:46:49 +0000 | [diff] [blame] | 8390 | /// isLegalAddImmediate - Return true if the specified immediate is legal |
| 8391 | /// add immediate, that is the target has add instructions which can add |
| 8392 | /// a register with the immediate without having to materialize the |
| 8393 | /// immediate into a register. |
| 8394 | bool ARMTargetLowering::isLegalAddImmediate(int64_t Imm) const { |
| 8395 | return ARM_AM::getSOImmVal(Imm) != -1; |
| 8396 | } |
| 8397 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8398 | static bool getARMIndexedAddressParts(SDNode *Ptr, EVT VT, |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8399 | bool isSEXTLoad, SDValue &Base, |
| 8400 | SDValue &Offset, bool &isInc, |
| 8401 | SelectionDAG &DAG) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8402 | if (Ptr->getOpcode() != ISD::ADD && Ptr->getOpcode() != ISD::SUB) |
| 8403 | return false; |
| 8404 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8405 | if (VT == MVT::i16 || ((VT == MVT::i8 || VT == MVT::i1) && isSEXTLoad)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8406 | // AddressingMode 3 |
| 8407 | Base = Ptr->getOperand(0); |
| 8408 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 8409 | int RHSC = (int)RHS->getZExtValue(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8410 | if (RHSC < 0 && RHSC > -256) { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8411 | assert(Ptr->getOpcode() == ISD::ADD); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8412 | isInc = false; |
| 8413 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); |
| 8414 | return true; |
| 8415 | } |
| 8416 | } |
| 8417 | isInc = (Ptr->getOpcode() == ISD::ADD); |
| 8418 | Offset = Ptr->getOperand(1); |
| 8419 | return true; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8420 | } else if (VT == MVT::i32 || VT == MVT::i8 || VT == MVT::i1) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8421 | // AddressingMode 2 |
| 8422 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 8423 | int RHSC = (int)RHS->getZExtValue(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8424 | if (RHSC < 0 && RHSC > -0x1000) { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8425 | assert(Ptr->getOpcode() == ISD::ADD); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8426 | isInc = false; |
| 8427 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); |
| 8428 | Base = Ptr->getOperand(0); |
| 8429 | return true; |
| 8430 | } |
| 8431 | } |
| 8432 | |
| 8433 | if (Ptr->getOpcode() == ISD::ADD) { |
| 8434 | isInc = true; |
Evan Cheng | ee04a6d | 2011-07-20 23:34:39 +0000 | [diff] [blame] | 8435 | ARM_AM::ShiftOpc ShOpcVal= |
| 8436 | ARM_AM::getShiftOpcForNode(Ptr->getOperand(0).getOpcode()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8437 | if (ShOpcVal != ARM_AM::no_shift) { |
| 8438 | Base = Ptr->getOperand(1); |
| 8439 | Offset = Ptr->getOperand(0); |
| 8440 | } else { |
| 8441 | Base = Ptr->getOperand(0); |
| 8442 | Offset = Ptr->getOperand(1); |
| 8443 | } |
| 8444 | return true; |
| 8445 | } |
| 8446 | |
| 8447 | isInc = (Ptr->getOpcode() == ISD::ADD); |
| 8448 | Base = Ptr->getOperand(0); |
| 8449 | Offset = Ptr->getOperand(1); |
| 8450 | return true; |
| 8451 | } |
| 8452 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 8453 | // FIXME: Use VLDM / VSTM to emulate indexed FP load / store. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8454 | return false; |
| 8455 | } |
| 8456 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8457 | static bool getT2IndexedAddressParts(SDNode *Ptr, EVT VT, |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8458 | bool isSEXTLoad, SDValue &Base, |
| 8459 | SDValue &Offset, bool &isInc, |
| 8460 | SelectionDAG &DAG) { |
| 8461 | if (Ptr->getOpcode() != ISD::ADD && Ptr->getOpcode() != ISD::SUB) |
| 8462 | return false; |
| 8463 | |
| 8464 | Base = Ptr->getOperand(0); |
| 8465 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
| 8466 | int RHSC = (int)RHS->getZExtValue(); |
| 8467 | if (RHSC < 0 && RHSC > -0x100) { // 8 bits. |
| 8468 | assert(Ptr->getOpcode() == ISD::ADD); |
| 8469 | isInc = false; |
| 8470 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); |
| 8471 | return true; |
| 8472 | } else if (RHSC > 0 && RHSC < 0x100) { // 8 bit, no zero. |
| 8473 | isInc = Ptr->getOpcode() == ISD::ADD; |
| 8474 | Offset = DAG.getConstant(RHSC, RHS->getValueType(0)); |
| 8475 | return true; |
| 8476 | } |
| 8477 | } |
| 8478 | |
| 8479 | return false; |
| 8480 | } |
| 8481 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8482 | /// getPreIndexedAddressParts - returns true by value, base pointer and |
| 8483 | /// offset pointer and addressing mode by reference if the node's address |
| 8484 | /// can be legally represented as pre-indexed load / store address. |
| 8485 | bool |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 8486 | ARMTargetLowering::getPreIndexedAddressParts(SDNode *N, SDValue &Base, |
| 8487 | SDValue &Offset, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8488 | ISD::MemIndexedMode &AM, |
Dan Gohman | 73e0914 | 2009-01-15 16:29:45 +0000 | [diff] [blame] | 8489 | SelectionDAG &DAG) const { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8490 | if (Subtarget->isThumb1Only()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8491 | return false; |
| 8492 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8493 | EVT VT; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 8494 | SDValue Ptr; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8495 | bool isSEXTLoad = false; |
| 8496 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) { |
| 8497 | Ptr = LD->getBasePtr(); |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 8498 | VT = LD->getMemoryVT(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8499 | isSEXTLoad = LD->getExtensionType() == ISD::SEXTLOAD; |
| 8500 | } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) { |
| 8501 | Ptr = ST->getBasePtr(); |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 8502 | VT = ST->getMemoryVT(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8503 | } else |
| 8504 | return false; |
| 8505 | |
| 8506 | bool isInc; |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8507 | bool isLegal = false; |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 8508 | if (Subtarget->isThumb2()) |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8509 | isLegal = getT2IndexedAddressParts(Ptr.getNode(), VT, isSEXTLoad, Base, |
| 8510 | Offset, isInc, DAG); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 8511 | else |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8512 | isLegal = getARMIndexedAddressParts(Ptr.getNode(), VT, isSEXTLoad, Base, |
Evan Cheng | 0412957 | 2009-07-02 06:44:30 +0000 | [diff] [blame] | 8513 | Offset, isInc, DAG); |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8514 | if (!isLegal) |
| 8515 | return false; |
| 8516 | |
| 8517 | AM = isInc ? ISD::PRE_INC : ISD::PRE_DEC; |
| 8518 | return true; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8519 | } |
| 8520 | |
| 8521 | /// getPostIndexedAddressParts - returns true by value, base pointer and |
| 8522 | /// offset pointer and addressing mode by reference if this node can be |
| 8523 | /// combined with a load / store to form a post-indexed load / store. |
| 8524 | bool ARMTargetLowering::getPostIndexedAddressParts(SDNode *N, SDNode *Op, |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 8525 | SDValue &Base, |
| 8526 | SDValue &Offset, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8527 | ISD::MemIndexedMode &AM, |
Dan Gohman | 73e0914 | 2009-01-15 16:29:45 +0000 | [diff] [blame] | 8528 | SelectionDAG &DAG) const { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8529 | if (Subtarget->isThumb1Only()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8530 | return false; |
| 8531 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8532 | EVT VT; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 8533 | SDValue Ptr; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8534 | bool isSEXTLoad = false; |
| 8535 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) { |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 8536 | VT = LD->getMemoryVT(); |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 8537 | Ptr = LD->getBasePtr(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8538 | isSEXTLoad = LD->getExtensionType() == ISD::SEXTLOAD; |
| 8539 | } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) { |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 8540 | VT = ST->getMemoryVT(); |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 8541 | Ptr = ST->getBasePtr(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8542 | } else |
| 8543 | return false; |
| 8544 | |
| 8545 | bool isInc; |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8546 | bool isLegal = false; |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 8547 | if (Subtarget->isThumb2()) |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8548 | isLegal = getT2IndexedAddressParts(Op, VT, isSEXTLoad, Base, Offset, |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 8549 | isInc, DAG); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 8550 | else |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8551 | isLegal = getARMIndexedAddressParts(Op, VT, isSEXTLoad, Base, Offset, |
| 8552 | isInc, DAG); |
| 8553 | if (!isLegal) |
| 8554 | return false; |
| 8555 | |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 8556 | if (Ptr != Base) { |
| 8557 | // Swap base ptr and offset to catch more post-index load / store when |
| 8558 | // it's legal. In Thumb2 mode, offset must be an immediate. |
| 8559 | if (Ptr == Offset && Op->getOpcode() == ISD::ADD && |
| 8560 | !Subtarget->isThumb2()) |
| 8561 | std::swap(Base, Offset); |
| 8562 | |
| 8563 | // Post-indexed load / store update the base pointer. |
| 8564 | if (Ptr != Base) |
| 8565 | return false; |
| 8566 | } |
| 8567 | |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 8568 | AM = isInc ? ISD::POST_INC : ISD::POST_DEC; |
| 8569 | return true; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8570 | } |
| 8571 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 8572 | void ARMTargetLowering::computeMaskedBitsForTargetNode(const SDValue Op, |
Dan Gohman | 977a76f | 2008-02-13 22:28:48 +0000 | [diff] [blame] | 8573 | const APInt &Mask, |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 8574 | APInt &KnownZero, |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 8575 | APInt &KnownOne, |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 8576 | const SelectionDAG &DAG, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8577 | unsigned Depth) const { |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 8578 | KnownZero = KnownOne = APInt(Mask.getBitWidth(), 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8579 | switch (Op.getOpcode()) { |
| 8580 | default: break; |
| 8581 | case ARMISD::CMOV: { |
| 8582 | // Bits are known zero/one if known on the LHS and RHS. |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 8583 | DAG.ComputeMaskedBits(Op.getOperand(0), Mask, KnownZero, KnownOne, Depth+1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8584 | if (KnownZero == 0 && KnownOne == 0) return; |
| 8585 | |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 8586 | APInt KnownZeroRHS, KnownOneRHS; |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 8587 | DAG.ComputeMaskedBits(Op.getOperand(1), Mask, |
| 8588 | KnownZeroRHS, KnownOneRHS, Depth+1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8589 | KnownZero &= KnownZeroRHS; |
| 8590 | KnownOne &= KnownOneRHS; |
| 8591 | return; |
| 8592 | } |
| 8593 | } |
| 8594 | } |
| 8595 | |
| 8596 | //===----------------------------------------------------------------------===// |
| 8597 | // ARM Inline Assembly Support |
| 8598 | //===----------------------------------------------------------------------===// |
| 8599 | |
Evan Cheng | 55d4200 | 2011-01-08 01:24:27 +0000 | [diff] [blame] | 8600 | bool ARMTargetLowering::ExpandInlineAsm(CallInst *CI) const { |
| 8601 | // Looking for "rev" which is V6+. |
| 8602 | if (!Subtarget->hasV6Ops()) |
| 8603 | return false; |
| 8604 | |
| 8605 | InlineAsm *IA = cast<InlineAsm>(CI->getCalledValue()); |
| 8606 | std::string AsmStr = IA->getAsmString(); |
| 8607 | SmallVector<StringRef, 4> AsmPieces; |
| 8608 | SplitString(AsmStr, AsmPieces, ";\n"); |
| 8609 | |
| 8610 | switch (AsmPieces.size()) { |
| 8611 | default: return false; |
| 8612 | case 1: |
| 8613 | AsmStr = AsmPieces[0]; |
| 8614 | AsmPieces.clear(); |
| 8615 | SplitString(AsmStr, AsmPieces, " \t,"); |
| 8616 | |
| 8617 | // rev $0, $1 |
| 8618 | if (AsmPieces.size() == 3 && |
| 8619 | AsmPieces[0] == "rev" && AsmPieces[1] == "$0" && AsmPieces[2] == "$1" && |
| 8620 | IA->getConstraintString().compare(0, 4, "=l,l") == 0) { |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 8621 | IntegerType *Ty = dyn_cast<IntegerType>(CI->getType()); |
Evan Cheng | 55d4200 | 2011-01-08 01:24:27 +0000 | [diff] [blame] | 8622 | if (Ty && Ty->getBitWidth() == 32) |
| 8623 | return IntrinsicLowering::LowerToByteSwap(CI); |
| 8624 | } |
| 8625 | break; |
| 8626 | } |
| 8627 | |
| 8628 | return false; |
| 8629 | } |
| 8630 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8631 | /// getConstraintType - Given a constraint letter, return the type of |
| 8632 | /// constraint it is for this target. |
| 8633 | ARMTargetLowering::ConstraintType |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 8634 | ARMTargetLowering::getConstraintType(const std::string &Constraint) const { |
| 8635 | if (Constraint.size() == 1) { |
| 8636 | switch (Constraint[0]) { |
| 8637 | default: break; |
| 8638 | case 'l': return C_RegisterClass; |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 8639 | case 'w': return C_RegisterClass; |
Eric Christopher | 73744df | 2011-06-30 23:23:01 +0000 | [diff] [blame] | 8640 | case 'h': return C_RegisterClass; |
Eric Christopher | 89bd71f | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 8641 | case 'x': return C_RegisterClass; |
Eric Christopher | d5dc9ec | 2011-07-01 00:30:46 +0000 | [diff] [blame] | 8642 | case 't': return C_RegisterClass; |
Eric Christopher | 5e653c9 | 2011-07-01 01:00:07 +0000 | [diff] [blame] | 8643 | case 'j': return C_Other; // Constant for movw. |
Eric Christopher | ef7f1e7 | 2011-07-29 21:18:58 +0000 | [diff] [blame] | 8644 | // An address with a single base register. Due to the way we |
| 8645 | // currently handle addresses it is the same as an 'r' memory constraint. |
| 8646 | case 'Q': return C_Memory; |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 8647 | } |
Eric Christopher | 1312ca8 | 2011-06-21 22:10:57 +0000 | [diff] [blame] | 8648 | } else if (Constraint.size() == 2) { |
| 8649 | switch (Constraint[0]) { |
| 8650 | default: break; |
| 8651 | // All 'U+' constraints are addresses. |
| 8652 | case 'U': return C_Memory; |
| 8653 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8654 | } |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 8655 | return TargetLowering::getConstraintType(Constraint); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8656 | } |
| 8657 | |
John Thompson | 44ab89e | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 8658 | /// Examine constraint type and operand type and determine a weight value. |
| 8659 | /// This object must already have been set up with the operand type |
| 8660 | /// and the current alternative constraint selected. |
| 8661 | TargetLowering::ConstraintWeight |
| 8662 | ARMTargetLowering::getSingleConstraintMatchWeight( |
| 8663 | AsmOperandInfo &info, const char *constraint) const { |
| 8664 | ConstraintWeight weight = CW_Invalid; |
| 8665 | Value *CallOperandVal = info.CallOperandVal; |
| 8666 | // If we don't have a value, we can't do a match, |
| 8667 | // but allow it at the lowest weight. |
| 8668 | if (CallOperandVal == NULL) |
| 8669 | return CW_Default; |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 8670 | Type *type = CallOperandVal->getType(); |
John Thompson | 44ab89e | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 8671 | // Look at the constraint type. |
| 8672 | switch (*constraint) { |
| 8673 | default: |
| 8674 | weight = TargetLowering::getSingleConstraintMatchWeight(info, constraint); |
| 8675 | break; |
| 8676 | case 'l': |
| 8677 | if (type->isIntegerTy()) { |
| 8678 | if (Subtarget->isThumb()) |
| 8679 | weight = CW_SpecificReg; |
| 8680 | else |
| 8681 | weight = CW_Register; |
| 8682 | } |
| 8683 | break; |
| 8684 | case 'w': |
| 8685 | if (type->isFloatingPointTy()) |
| 8686 | weight = CW_Register; |
| 8687 | break; |
| 8688 | } |
| 8689 | return weight; |
| 8690 | } |
| 8691 | |
Eric Christopher | 35e6d4d | 2011-06-30 23:50:52 +0000 | [diff] [blame] | 8692 | typedef std::pair<unsigned, const TargetRegisterClass*> RCPair; |
| 8693 | RCPair |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8694 | ARMTargetLowering::getRegForInlineAsmConstraint(const std::string &Constraint, |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8695 | EVT VT) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8696 | if (Constraint.size() == 1) { |
Jakob Stoklund Olesen | 09bf003 | 2010-01-14 18:19:56 +0000 | [diff] [blame] | 8697 | // GCC ARM Constraint Letters |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8698 | switch (Constraint[0]) { |
Eric Christopher | 73744df | 2011-06-30 23:23:01 +0000 | [diff] [blame] | 8699 | case 'l': // Low regs or general regs. |
Jakob Stoklund Olesen | 09bf003 | 2010-01-14 18:19:56 +0000 | [diff] [blame] | 8700 | if (Subtarget->isThumb()) |
Eric Christopher | 35e6d4d | 2011-06-30 23:50:52 +0000 | [diff] [blame] | 8701 | return RCPair(0U, ARM::tGPRRegisterClass); |
Jim Grosbach | 30eae3c | 2009-04-07 20:34:09 +0000 | [diff] [blame] | 8702 | else |
Eric Christopher | 35e6d4d | 2011-06-30 23:50:52 +0000 | [diff] [blame] | 8703 | return RCPair(0U, ARM::GPRRegisterClass); |
Eric Christopher | 73744df | 2011-06-30 23:23:01 +0000 | [diff] [blame] | 8704 | case 'h': // High regs or no regs. |
| 8705 | if (Subtarget->isThumb()) |
Andrew Trick | 3af7a67 | 2011-09-20 03:06:13 +0000 | [diff] [blame] | 8706 | return RCPair(0U, ARM::hGPRRegisterClass); |
Eric Christopher | 1070f82 | 2011-07-01 00:19:27 +0000 | [diff] [blame] | 8707 | break; |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 8708 | case 'r': |
Eric Christopher | 35e6d4d | 2011-06-30 23:50:52 +0000 | [diff] [blame] | 8709 | return RCPair(0U, ARM::GPRRegisterClass); |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 8710 | case 'w': |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8711 | if (VT == MVT::f32) |
Eric Christopher | 35e6d4d | 2011-06-30 23:50:52 +0000 | [diff] [blame] | 8712 | return RCPair(0U, ARM::SPRRegisterClass); |
Bob Wilson | 5afffae | 2009-12-18 01:03:29 +0000 | [diff] [blame] | 8713 | if (VT.getSizeInBits() == 64) |
Eric Christopher | 35e6d4d | 2011-06-30 23:50:52 +0000 | [diff] [blame] | 8714 | return RCPair(0U, ARM::DPRRegisterClass); |
Evan Cheng | d831cda | 2009-12-08 23:06:22 +0000 | [diff] [blame] | 8715 | if (VT.getSizeInBits() == 128) |
Eric Christopher | 35e6d4d | 2011-06-30 23:50:52 +0000 | [diff] [blame] | 8716 | return RCPair(0U, ARM::QPRRegisterClass); |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 8717 | break; |
Eric Christopher | 89bd71f | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 8718 | case 'x': |
| 8719 | if (VT == MVT::f32) |
Andrew Trick | 3af7a67 | 2011-09-20 03:06:13 +0000 | [diff] [blame] | 8720 | return RCPair(0U, ARM::SPR_8RegisterClass); |
Eric Christopher | 89bd71f | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 8721 | if (VT.getSizeInBits() == 64) |
Andrew Trick | 3af7a67 | 2011-09-20 03:06:13 +0000 | [diff] [blame] | 8722 | return RCPair(0U, ARM::DPR_8RegisterClass); |
Eric Christopher | 89bd71f | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 8723 | if (VT.getSizeInBits() == 128) |
Andrew Trick | 3af7a67 | 2011-09-20 03:06:13 +0000 | [diff] [blame] | 8724 | return RCPair(0U, ARM::QPR_8RegisterClass); |
Eric Christopher | 89bd71f | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 8725 | break; |
Eric Christopher | d5dc9ec | 2011-07-01 00:30:46 +0000 | [diff] [blame] | 8726 | case 't': |
| 8727 | if (VT == MVT::f32) |
Andrew Trick | 3af7a67 | 2011-09-20 03:06:13 +0000 | [diff] [blame] | 8728 | return RCPair(0U, ARM::SPRRegisterClass); |
Eric Christopher | d5dc9ec | 2011-07-01 00:30:46 +0000 | [diff] [blame] | 8729 | break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8730 | } |
| 8731 | } |
Bob Wilson | 33cc5cb | 2010-03-15 23:09:18 +0000 | [diff] [blame] | 8732 | if (StringRef("{cc}").equals_lower(Constraint)) |
Jakob Stoklund Olesen | 0d8ba33 | 2010-06-18 16:49:33 +0000 | [diff] [blame] | 8733 | return std::make_pair(unsigned(ARM::CPSR), ARM::CCRRegisterClass); |
Bob Wilson | 33cc5cb | 2010-03-15 23:09:18 +0000 | [diff] [blame] | 8734 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8735 | return TargetLowering::getRegForInlineAsmConstraint(Constraint, VT); |
| 8736 | } |
| 8737 | |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 8738 | /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops |
| 8739 | /// vector. If it is invalid, don't add anything to Ops. |
| 8740 | void ARMTargetLowering::LowerAsmOperandForConstraint(SDValue Op, |
Eric Christopher | 100c833 | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 8741 | std::string &Constraint, |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 8742 | std::vector<SDValue>&Ops, |
| 8743 | SelectionDAG &DAG) const { |
| 8744 | SDValue Result(0, 0); |
| 8745 | |
Eric Christopher | 100c833 | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 8746 | // Currently only support length 1 constraints. |
| 8747 | if (Constraint.length() != 1) return; |
Eric Christopher | 471e422 | 2011-06-08 23:55:35 +0000 | [diff] [blame] | 8748 | |
Eric Christopher | 100c833 | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 8749 | char ConstraintLetter = Constraint[0]; |
| 8750 | switch (ConstraintLetter) { |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 8751 | default: break; |
Eric Christopher | 5e653c9 | 2011-07-01 01:00:07 +0000 | [diff] [blame] | 8752 | case 'j': |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 8753 | case 'I': case 'J': case 'K': case 'L': |
| 8754 | case 'M': case 'N': case 'O': |
| 8755 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op); |
| 8756 | if (!C) |
| 8757 | return; |
| 8758 | |
| 8759 | int64_t CVal64 = C->getSExtValue(); |
| 8760 | int CVal = (int) CVal64; |
| 8761 | // None of these constraints allow values larger than 32 bits. Check |
| 8762 | // that the value fits in an int. |
| 8763 | if (CVal != CVal64) |
| 8764 | return; |
| 8765 | |
Eric Christopher | 100c833 | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 8766 | switch (ConstraintLetter) { |
Eric Christopher | 5e653c9 | 2011-07-01 01:00:07 +0000 | [diff] [blame] | 8767 | case 'j': |
Andrew Trick | 3af7a67 | 2011-09-20 03:06:13 +0000 | [diff] [blame] | 8768 | // Constant suitable for movw, must be between 0 and |
| 8769 | // 65535. |
| 8770 | if (Subtarget->hasV6T2Ops()) |
| 8771 | if (CVal >= 0 && CVal <= 65535) |
| 8772 | break; |
| 8773 | return; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 8774 | case 'I': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 8775 | if (Subtarget->isThumb1Only()) { |
| 8776 | // This must be a constant between 0 and 255, for ADD |
| 8777 | // immediates. |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 8778 | if (CVal >= 0 && CVal <= 255) |
| 8779 | break; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 8780 | } else if (Subtarget->isThumb2()) { |
| 8781 | // A constant that can be used as an immediate value in a |
| 8782 | // data-processing instruction. |
| 8783 | if (ARM_AM::getT2SOImmVal(CVal) != -1) |
| 8784 | break; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 8785 | } else { |
| 8786 | // A constant that can be used as an immediate value in a |
| 8787 | // data-processing instruction. |
| 8788 | if (ARM_AM::getSOImmVal(CVal) != -1) |
| 8789 | break; |
| 8790 | } |
| 8791 | return; |
| 8792 | |
| 8793 | case 'J': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 8794 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 8795 | // This must be a constant between -255 and -1, for negated ADD |
| 8796 | // immediates. This can be used in GCC with an "n" modifier that |
| 8797 | // prints the negated value, for use with SUB instructions. It is |
| 8798 | // not useful otherwise but is implemented for compatibility. |
| 8799 | if (CVal >= -255 && CVal <= -1) |
| 8800 | break; |
| 8801 | } else { |
| 8802 | // This must be a constant between -4095 and 4095. It is not clear |
| 8803 | // what this constraint is intended for. Implemented for |
| 8804 | // compatibility with GCC. |
| 8805 | if (CVal >= -4095 && CVal <= 4095) |
| 8806 | break; |
| 8807 | } |
| 8808 | return; |
| 8809 | |
| 8810 | case 'K': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 8811 | if (Subtarget->isThumb1Only()) { |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 8812 | // A 32-bit value where only one byte has a nonzero value. Exclude |
| 8813 | // zero to match GCC. This constraint is used by GCC internally for |
| 8814 | // constants that can be loaded with a move/shift combination. |
| 8815 | // It is not useful otherwise but is implemented for compatibility. |
| 8816 | if (CVal != 0 && ARM_AM::isThumbImmShiftedVal(CVal)) |
| 8817 | break; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 8818 | } else if (Subtarget->isThumb2()) { |
| 8819 | // A constant whose bitwise inverse can be used as an immediate |
| 8820 | // value in a data-processing instruction. This can be used in GCC |
| 8821 | // with a "B" modifier that prints the inverted value, for use with |
| 8822 | // BIC and MVN instructions. It is not useful otherwise but is |
| 8823 | // implemented for compatibility. |
| 8824 | if (ARM_AM::getT2SOImmVal(~CVal) != -1) |
| 8825 | break; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 8826 | } else { |
| 8827 | // A constant whose bitwise inverse can be used as an immediate |
| 8828 | // value in a data-processing instruction. This can be used in GCC |
| 8829 | // with a "B" modifier that prints the inverted value, for use with |
| 8830 | // BIC and MVN instructions. It is not useful otherwise but is |
| 8831 | // implemented for compatibility. |
| 8832 | if (ARM_AM::getSOImmVal(~CVal) != -1) |
| 8833 | break; |
| 8834 | } |
| 8835 | return; |
| 8836 | |
| 8837 | case 'L': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 8838 | if (Subtarget->isThumb1Only()) { |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 8839 | // This must be a constant between -7 and 7, |
| 8840 | // for 3-operand ADD/SUB immediate instructions. |
| 8841 | if (CVal >= -7 && CVal < 7) |
| 8842 | break; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 8843 | } else if (Subtarget->isThumb2()) { |
| 8844 | // A constant whose negation can be used as an immediate value in a |
| 8845 | // data-processing instruction. This can be used in GCC with an "n" |
| 8846 | // modifier that prints the negated value, for use with SUB |
| 8847 | // instructions. It is not useful otherwise but is implemented for |
| 8848 | // compatibility. |
| 8849 | if (ARM_AM::getT2SOImmVal(-CVal) != -1) |
| 8850 | break; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 8851 | } else { |
| 8852 | // A constant whose negation can be used as an immediate value in a |
| 8853 | // data-processing instruction. This can be used in GCC with an "n" |
| 8854 | // modifier that prints the negated value, for use with SUB |
| 8855 | // instructions. It is not useful otherwise but is implemented for |
| 8856 | // compatibility. |
| 8857 | if (ARM_AM::getSOImmVal(-CVal) != -1) |
| 8858 | break; |
| 8859 | } |
| 8860 | return; |
| 8861 | |
| 8862 | case 'M': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 8863 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 8864 | // This must be a multiple of 4 between 0 and 1020, for |
| 8865 | // ADD sp + immediate. |
| 8866 | if ((CVal >= 0 && CVal <= 1020) && ((CVal & 3) == 0)) |
| 8867 | break; |
| 8868 | } else { |
| 8869 | // A power of two or a constant between 0 and 32. This is used in |
| 8870 | // GCC for the shift amount on shifted register operands, but it is |
| 8871 | // useful in general for any shift amounts. |
| 8872 | if ((CVal >= 0 && CVal <= 32) || ((CVal & (CVal - 1)) == 0)) |
| 8873 | break; |
| 8874 | } |
| 8875 | return; |
| 8876 | |
| 8877 | case 'N': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 8878 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 8879 | // This must be a constant between 0 and 31, for shift amounts. |
| 8880 | if (CVal >= 0 && CVal <= 31) |
| 8881 | break; |
| 8882 | } |
| 8883 | return; |
| 8884 | |
| 8885 | case 'O': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 8886 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 8887 | // This must be a multiple of 4 between -508 and 508, for |
| 8888 | // ADD/SUB sp = sp + immediate. |
| 8889 | if ((CVal >= -508 && CVal <= 508) && ((CVal & 3) == 0)) |
| 8890 | break; |
| 8891 | } |
| 8892 | return; |
| 8893 | } |
| 8894 | Result = DAG.getTargetConstant(CVal, Op.getValueType()); |
| 8895 | break; |
| 8896 | } |
| 8897 | |
| 8898 | if (Result.getNode()) { |
| 8899 | Ops.push_back(Result); |
| 8900 | return; |
| 8901 | } |
Dale Johannesen | 1784d16 | 2010-06-25 21:55:36 +0000 | [diff] [blame] | 8902 | return TargetLowering::LowerAsmOperandForConstraint(Op, Constraint, Ops, DAG); |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 8903 | } |
Anton Korobeynikov | 48e1935 | 2009-09-23 19:04:09 +0000 | [diff] [blame] | 8904 | |
| 8905 | bool |
| 8906 | ARMTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const { |
| 8907 | // The ARM target isn't yet aware of offsets. |
| 8908 | return false; |
| 8909 | } |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 8910 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8911 | bool ARM::isBitFieldInvertedMask(unsigned v) { |
| 8912 | if (v == 0xffffffff) |
| 8913 | return 0; |
| 8914 | // there can be 1's on either or both "outsides", all the "inside" |
| 8915 | // bits must be 0's |
| 8916 | unsigned int lsb = 0, msb = 31; |
| 8917 | while (v & (1 << msb)) --msb; |
| 8918 | while (v & (1 << lsb)) ++lsb; |
| 8919 | for (unsigned int i = lsb; i <= msb; ++i) { |
| 8920 | if (v & (1 << i)) |
| 8921 | return 0; |
| 8922 | } |
| 8923 | return 1; |
| 8924 | } |
| 8925 | |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 8926 | /// isFPImmLegal - Returns true if the target can instruction select the |
| 8927 | /// specified FP immediate natively. If false, the legalizer will |
| 8928 | /// materialize the FP immediate as a load from a constant pool. |
| 8929 | bool ARMTargetLowering::isFPImmLegal(const APFloat &Imm, EVT VT) const { |
| 8930 | if (!Subtarget->hasVFP3()) |
| 8931 | return false; |
| 8932 | if (VT == MVT::f32) |
Jim Grosbach | 4ebbf7b | 2011-09-30 00:50:06 +0000 | [diff] [blame] | 8933 | return ARM_AM::getFP32Imm(Imm) != -1; |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 8934 | if (VT == MVT::f64) |
Jim Grosbach | 4ebbf7b | 2011-09-30 00:50:06 +0000 | [diff] [blame] | 8935 | return ARM_AM::getFP64Imm(Imm) != -1; |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 8936 | return false; |
| 8937 | } |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 8938 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8939 | /// getTgtMemIntrinsic - Represent NEON load and store intrinsics as |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 8940 | /// MemIntrinsicNodes. The associated MachineMemOperands record the alignment |
| 8941 | /// specified in the intrinsic calls. |
| 8942 | bool ARMTargetLowering::getTgtMemIntrinsic(IntrinsicInfo &Info, |
| 8943 | const CallInst &I, |
| 8944 | unsigned Intrinsic) const { |
| 8945 | switch (Intrinsic) { |
| 8946 | case Intrinsic::arm_neon_vld1: |
| 8947 | case Intrinsic::arm_neon_vld2: |
| 8948 | case Intrinsic::arm_neon_vld3: |
| 8949 | case Intrinsic::arm_neon_vld4: |
| 8950 | case Intrinsic::arm_neon_vld2lane: |
| 8951 | case Intrinsic::arm_neon_vld3lane: |
| 8952 | case Intrinsic::arm_neon_vld4lane: { |
| 8953 | Info.opc = ISD::INTRINSIC_W_CHAIN; |
| 8954 | // Conservatively set memVT to the entire set of vectors loaded. |
| 8955 | uint64_t NumElts = getTargetData()->getTypeAllocSize(I.getType()) / 8; |
| 8956 | Info.memVT = EVT::getVectorVT(I.getType()->getContext(), MVT::i64, NumElts); |
| 8957 | Info.ptrVal = I.getArgOperand(0); |
| 8958 | Info.offset = 0; |
| 8959 | Value *AlignArg = I.getArgOperand(I.getNumArgOperands() - 1); |
| 8960 | Info.align = cast<ConstantInt>(AlignArg)->getZExtValue(); |
| 8961 | Info.vol = false; // volatile loads with NEON intrinsics not supported |
| 8962 | Info.readMem = true; |
| 8963 | Info.writeMem = false; |
| 8964 | return true; |
| 8965 | } |
| 8966 | case Intrinsic::arm_neon_vst1: |
| 8967 | case Intrinsic::arm_neon_vst2: |
| 8968 | case Intrinsic::arm_neon_vst3: |
| 8969 | case Intrinsic::arm_neon_vst4: |
| 8970 | case Intrinsic::arm_neon_vst2lane: |
| 8971 | case Intrinsic::arm_neon_vst3lane: |
| 8972 | case Intrinsic::arm_neon_vst4lane: { |
| 8973 | Info.opc = ISD::INTRINSIC_VOID; |
| 8974 | // Conservatively set memVT to the entire set of vectors stored. |
| 8975 | unsigned NumElts = 0; |
| 8976 | for (unsigned ArgI = 1, ArgE = I.getNumArgOperands(); ArgI < ArgE; ++ArgI) { |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 8977 | Type *ArgTy = I.getArgOperand(ArgI)->getType(); |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 8978 | if (!ArgTy->isVectorTy()) |
| 8979 | break; |
| 8980 | NumElts += getTargetData()->getTypeAllocSize(ArgTy) / 8; |
| 8981 | } |
| 8982 | Info.memVT = EVT::getVectorVT(I.getType()->getContext(), MVT::i64, NumElts); |
| 8983 | Info.ptrVal = I.getArgOperand(0); |
| 8984 | Info.offset = 0; |
| 8985 | Value *AlignArg = I.getArgOperand(I.getNumArgOperands() - 1); |
| 8986 | Info.align = cast<ConstantInt>(AlignArg)->getZExtValue(); |
| 8987 | Info.vol = false; // volatile stores with NEON intrinsics not supported |
| 8988 | Info.readMem = false; |
| 8989 | Info.writeMem = true; |
| 8990 | return true; |
| 8991 | } |
Bruno Cardoso Lopes | a0112d0 | 2011-05-28 04:07:29 +0000 | [diff] [blame] | 8992 | case Intrinsic::arm_strexd: { |
| 8993 | Info.opc = ISD::INTRINSIC_W_CHAIN; |
| 8994 | Info.memVT = MVT::i64; |
| 8995 | Info.ptrVal = I.getArgOperand(2); |
| 8996 | Info.offset = 0; |
| 8997 | Info.align = 8; |
Bruno Cardoso Lopes | c75448c | 2011-06-16 18:11:32 +0000 | [diff] [blame] | 8998 | Info.vol = true; |
Bruno Cardoso Lopes | a0112d0 | 2011-05-28 04:07:29 +0000 | [diff] [blame] | 8999 | Info.readMem = false; |
| 9000 | Info.writeMem = true; |
| 9001 | return true; |
| 9002 | } |
| 9003 | case Intrinsic::arm_ldrexd: { |
| 9004 | Info.opc = ISD::INTRINSIC_W_CHAIN; |
| 9005 | Info.memVT = MVT::i64; |
| 9006 | Info.ptrVal = I.getArgOperand(0); |
| 9007 | Info.offset = 0; |
| 9008 | Info.align = 8; |
Bruno Cardoso Lopes | c75448c | 2011-06-16 18:11:32 +0000 | [diff] [blame] | 9009 | Info.vol = true; |
Bruno Cardoso Lopes | a0112d0 | 2011-05-28 04:07:29 +0000 | [diff] [blame] | 9010 | Info.readMem = true; |
| 9011 | Info.writeMem = false; |
| 9012 | return true; |
| 9013 | } |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 9014 | default: |
| 9015 | break; |
| 9016 | } |
| 9017 | |
| 9018 | return false; |
| 9019 | } |