Jia Liu | b22310f | 2012-02-18 12:03:15 +0000 | [diff] [blame] | 1 | //===-- ARMSubtarget.cpp - ARM Subtarget Information ----------------------===// |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | f3ebc3f | 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 | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Evan Cheng | 0d639a2 | 2011-07-01 21:01:15 +0000 | [diff] [blame] | 10 | // This file implements the ARM specific subclass of TargetSubtargetInfo. |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "ARMSubtarget.h" |
Eric Christopher | 80b24ef | 2014-06-26 19:30:02 +0000 | [diff] [blame] | 15 | #include "ARMFrameLowering.h" |
| 16 | #include "ARMISelLowering.h" |
| 17 | #include "ARMInstrInfo.h" |
Eric Christopher | 80b24ef | 2014-06-26 19:30:02 +0000 | [diff] [blame] | 18 | #include "ARMSelectionDAGInfo.h" |
| 19 | #include "ARMSubtarget.h" |
Chris Bieneman | 03695ab | 2014-07-15 17:18:41 +0000 | [diff] [blame] | 20 | #include "ARMMachineFunctionInfo.h" |
Eric Christopher | 80b24ef | 2014-06-26 19:30:02 +0000 | [diff] [blame] | 21 | #include "Thumb1FrameLowering.h" |
| 22 | #include "Thumb1InstrInfo.h" |
| 23 | #include "Thumb2InstrInfo.h" |
Bill Wendling | 5a92eec | 2013-02-15 22:41:25 +0000 | [diff] [blame] | 24 | #include "llvm/IR/Attributes.h" |
Bill Wendling | 5a92eec | 2013-02-15 22:41:25 +0000 | [diff] [blame] | 25 | #include "llvm/IR/Function.h" |
Chandler Carruth | 8a8cd2b | 2014-01-07 11:48:04 +0000 | [diff] [blame] | 26 | #include "llvm/IR/GlobalValue.h" |
Bob Wilson | 4582530 | 2009-06-22 21:01:46 +0000 | [diff] [blame] | 27 | #include "llvm/Support/CommandLine.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 28 | #include "llvm/Target/TargetInstrInfo.h" |
Renato Golin | b4dd6c5 | 2013-03-21 18:47:47 +0000 | [diff] [blame] | 29 | #include "llvm/Target/TargetOptions.h" |
Chris Bieneman | 03695ab | 2014-07-15 17:18:41 +0000 | [diff] [blame] | 30 | #include "llvm/Target/TargetRegisterInfo.h" |
| 31 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 32 | |
Chandler Carruth | d174b72 | 2014-04-22 02:03:14 +0000 | [diff] [blame] | 33 | using namespace llvm; |
| 34 | |
Chandler Carruth | e96dd89 | 2014-04-21 22:55:11 +0000 | [diff] [blame] | 35 | #define DEBUG_TYPE "arm-subtarget" |
| 36 | |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 37 | #define GET_SUBTARGETINFO_TARGET_DESC |
Evan Cheng | 4d1ca96 | 2011-07-08 01:53:10 +0000 | [diff] [blame] | 38 | #define GET_SUBTARGETINFO_CTOR |
Evan Cheng | c9c090d | 2011-07-01 22:36:09 +0000 | [diff] [blame] | 39 | #include "ARMGenSubtargetInfo.inc" |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 40 | |
Bob Wilson | 4582530 | 2009-06-22 21:01:46 +0000 | [diff] [blame] | 41 | static cl::opt<bool> |
| 42 | ReserveR9("arm-reserve-r9", cl::Hidden, |
| 43 | cl::desc("Reserve R9, making it unavailable as GPR")); |
| 44 | |
Anton Korobeynikov | 2522908 | 2009-11-24 00:44:37 +0000 | [diff] [blame] | 45 | static cl::opt<bool> |
Renato Golin | ca57063 | 2013-08-15 20:54:38 +0000 | [diff] [blame] | 46 | ArmUseMOVT("arm-use-movt", cl::init(true), cl::Hidden); |
Anton Korobeynikov | 2522908 | 2009-11-24 00:44:37 +0000 | [diff] [blame] | 47 | |
Bob Wilson | 3dc9732 | 2010-09-28 04:09:35 +0000 | [diff] [blame] | 48 | static cl::opt<bool> |
Bob Wilson | e8a549c | 2012-09-29 21:43:49 +0000 | [diff] [blame] | 49 | UseFusedMulOps("arm-use-mulops", |
| 50 | cl::init(true), cl::Hidden); |
| 51 | |
Alexey Samsonov | f17f03e | 2014-08-19 18:40:39 +0000 | [diff] [blame] | 52 | namespace { |
JF Bastien | 97b08c40 | 2013-05-17 23:49:01 +0000 | [diff] [blame] | 53 | enum AlignMode { |
| 54 | DefaultAlign, |
| 55 | StrictAlign, |
| 56 | NoStrictAlign |
| 57 | }; |
Alexey Samsonov | f17f03e | 2014-08-19 18:40:39 +0000 | [diff] [blame] | 58 | } |
JF Bastien | 97b08c40 | 2013-05-17 23:49:01 +0000 | [diff] [blame] | 59 | |
| 60 | static cl::opt<AlignMode> |
| 61 | Align(cl::desc("Load/store alignment support"), |
| 62 | cl::Hidden, cl::init(DefaultAlign), |
| 63 | cl::values( |
| 64 | clEnumValN(DefaultAlign, "arm-default-align", |
| 65 | "Generate unaligned accesses only on hardware/OS " |
| 66 | "combinations that are known to support them"), |
| 67 | clEnumValN(StrictAlign, "arm-strict-align", |
| 68 | "Disallow all unaligned memory accesses"), |
| 69 | clEnumValN(NoStrictAlign, "arm-no-strict-align", |
| 70 | "Allow unaligned memory accesses"), |
| 71 | clEnumValEnd)); |
Bob Wilson | 3dc9732 | 2010-09-28 04:09:35 +0000 | [diff] [blame] | 72 | |
Weiming Zhao | 0da5cc0 | 2013-11-13 18:29:49 +0000 | [diff] [blame] | 73 | enum ITMode { |
| 74 | DefaultIT, |
| 75 | RestrictedIT, |
| 76 | NoRestrictedIT |
| 77 | }; |
| 78 | |
| 79 | static cl::opt<ITMode> |
| 80 | IT(cl::desc("IT block support"), cl::Hidden, cl::init(DefaultIT), |
| 81 | cl::ZeroOrMore, |
| 82 | cl::values(clEnumValN(DefaultIT, "arm-default-it", |
| 83 | "Generate IT block based on arch"), |
| 84 | clEnumValN(RestrictedIT, "arm-restrict-it", |
| 85 | "Disallow deprecated IT based on ARMv8"), |
| 86 | clEnumValN(NoRestrictedIT, "arm-no-restrict-it", |
| 87 | "Allow IT blocks based on ARMv7"), |
| 88 | clEnumValEnd)); |
| 89 | |
Eric Christopher | a47f680 | 2014-06-13 00:20:35 +0000 | [diff] [blame] | 90 | static std::string computeDataLayout(ARMSubtarget &ST) { |
| 91 | std::string Ret = ""; |
| 92 | |
| 93 | if (ST.isLittle()) |
| 94 | // Little endian. |
| 95 | Ret += "e"; |
| 96 | else |
| 97 | // Big endian. |
| 98 | Ret += "E"; |
| 99 | |
| 100 | Ret += DataLayout::getManglingComponent(ST.getTargetTriple()); |
| 101 | |
| 102 | // Pointers are 32 bits and aligned to 32 bits. |
| 103 | Ret += "-p:32:32"; |
| 104 | |
Eric Christopher | a47f680 | 2014-06-13 00:20:35 +0000 | [diff] [blame] | 105 | // ABIs other than APCS have 64 bit integers with natural alignment. |
| 106 | if (!ST.isAPCS_ABI()) |
| 107 | Ret += "-i64:64"; |
| 108 | |
| 109 | // We have 64 bits floats. The APCS ABI requires them to be aligned to 32 |
| 110 | // bits, others to 64 bits. We always try to align to 64 bits. |
| 111 | if (ST.isAPCS_ABI()) |
| 112 | Ret += "-f64:32:64"; |
| 113 | |
| 114 | // We have 128 and 64 bit vectors. The APCS ABI aligns them to 32 bits, others |
| 115 | // to 64. We always ty to give them natural alignment. |
| 116 | if (ST.isAPCS_ABI()) |
| 117 | Ret += "-v64:32:64-v128:32:128"; |
| 118 | else |
| 119 | Ret += "-v128:64:128"; |
| 120 | |
Tim Northover | aa09ac6 | 2014-10-14 20:57:26 +0000 | [diff] [blame] | 121 | // Try to align aggregates to 32 bits (the default is 64 bits, which has no |
| 122 | // particular hardware support on 32-bit ARM). |
| 123 | Ret += "-a:0:32"; |
Eric Christopher | a47f680 | 2014-06-13 00:20:35 +0000 | [diff] [blame] | 124 | |
| 125 | // Integer registers are 32 bits. |
| 126 | Ret += "-n32"; |
| 127 | |
| 128 | // The stack is 128 bit aligned on NaCl, 64 bit aligned on AAPCS and 32 bit |
| 129 | // aligned everywhere else. |
| 130 | if (ST.isTargetNaCl()) |
| 131 | Ret += "-S128"; |
| 132 | else if (ST.isAAPCS_ABI()) |
| 133 | Ret += "-S64"; |
| 134 | else |
| 135 | Ret += "-S32"; |
| 136 | |
| 137 | return Ret; |
| 138 | } |
| 139 | |
| 140 | /// initializeSubtargetDependencies - Initializes using a CPU and feature string |
| 141 | /// so that we can use initializer lists for subtarget initialization. |
| 142 | ARMSubtarget &ARMSubtarget::initializeSubtargetDependencies(StringRef CPU, |
| 143 | StringRef FS) { |
| 144 | initializeEnvironment(); |
Eric Christopher | b68e253 | 2014-09-03 20:36:31 +0000 | [diff] [blame] | 145 | initSubtargetFeatures(CPU, FS); |
Eric Christopher | a47f680 | 2014-06-13 00:20:35 +0000 | [diff] [blame] | 146 | return *this; |
| 147 | } |
| 148 | |
Evan Cheng | fe6e405 | 2011-06-30 01:53:36 +0000 | [diff] [blame] | 149 | ARMSubtarget::ARMSubtarget(const std::string &TT, const std::string &CPU, |
Eric Christopher | 5312afe | 2014-10-03 00:17:59 +0000 | [diff] [blame] | 150 | const std::string &FS, const TargetMachine &TM, |
Eric Christopher | a94e592 | 2014-10-03 00:10:03 +0000 | [diff] [blame] | 151 | bool IsLittle) |
Eric Christopher | a47f680 | 2014-06-13 00:20:35 +0000 | [diff] [blame] | 152 | : ARMGenSubtargetInfo(TT, CPU, FS), ARMProcFamily(Others), |
| 153 | ARMProcClass(None), stackAlignment(4), CPUString(CPU), IsLittle(IsLittle), |
Eric Christopher | a94e592 | 2014-10-03 00:10:03 +0000 | [diff] [blame] | 154 | TargetTriple(TT), Options(TM.Options), TargetABI(ARM_ABI_UNKNOWN), |
Eric Christopher | 030294e | 2014-06-13 00:20:39 +0000 | [diff] [blame] | 155 | DL(computeDataLayout(initializeSubtargetDependencies(CPU, FS))), |
Eric Christopher | 79cc1e3 | 2014-09-02 22:28:02 +0000 | [diff] [blame] | 156 | TSInfo(DL), |
Eric Christopher | 80b24ef | 2014-06-26 19:30:02 +0000 | [diff] [blame] | 157 | InstrInfo(isThumb1Only() |
| 158 | ? (ARMBaseInstrInfo *)new Thumb1InstrInfo(*this) |
| 159 | : !isThumb() |
| 160 | ? (ARMBaseInstrInfo *)new ARMInstrInfo(*this) |
| 161 | : (ARMBaseInstrInfo *)new Thumb2InstrInfo(*this)), |
| 162 | TLInfo(TM), |
| 163 | FrameLowering(!isThumb1Only() |
| 164 | ? new ARMFrameLowering(*this) |
| 165 | : (ARMFrameLowering *)new Thumb1FrameLowering(*this)) {} |
Bill Wendling | 5a92eec | 2013-02-15 22:41:25 +0000 | [diff] [blame] | 166 | |
Bill Wendling | 61375d8 | 2013-02-16 01:36:26 +0000 | [diff] [blame] | 167 | void ARMSubtarget::initializeEnvironment() { |
| 168 | HasV4TOps = false; |
| 169 | HasV5TOps = false; |
| 170 | HasV5TEOps = false; |
| 171 | HasV6Ops = false; |
Amara Emerson | 5035ee0 | 2013-10-07 16:55:23 +0000 | [diff] [blame] | 172 | HasV6MOps = false; |
Bill Wendling | 61375d8 | 2013-02-16 01:36:26 +0000 | [diff] [blame] | 173 | HasV6T2Ops = false; |
| 174 | HasV7Ops = false; |
Joey Gouly | b3f550e | 2013-06-26 16:58:26 +0000 | [diff] [blame] | 175 | HasV8Ops = false; |
Bill Wendling | 61375d8 | 2013-02-16 01:36:26 +0000 | [diff] [blame] | 176 | HasVFPv2 = false; |
| 177 | HasVFPv3 = false; |
| 178 | HasVFPv4 = false; |
Joey Gouly | ccd0489 | 2013-09-13 13:46:57 +0000 | [diff] [blame] | 179 | HasFPARMv8 = false; |
Bill Wendling | 61375d8 | 2013-02-16 01:36:26 +0000 | [diff] [blame] | 180 | HasNEON = false; |
| 181 | UseNEONForSinglePrecisionFP = false; |
| 182 | UseMulOps = UseFusedMulOps; |
| 183 | SlowFPVMLx = false; |
| 184 | HasVMLxForwarding = false; |
| 185 | SlowFPBrcc = false; |
| 186 | InThumbMode = false; |
| 187 | HasThumb2 = false; |
Bill Wendling | 61375d8 | 2013-02-16 01:36:26 +0000 | [diff] [blame] | 188 | NoARM = false; |
Bill Wendling | 61375d8 | 2013-02-16 01:36:26 +0000 | [diff] [blame] | 189 | IsR9Reserved = ReserveR9; |
| 190 | UseMovt = false; |
| 191 | SupportsTailCall = false; |
| 192 | HasFP16 = false; |
| 193 | HasD16 = false; |
| 194 | HasHardwareDivide = false; |
| 195 | HasHardwareDivideInARM = false; |
| 196 | HasT2ExtractPack = false; |
| 197 | HasDataBarrier = false; |
| 198 | Pref32BitThumb = false; |
| 199 | AvoidCPSRPartialUpdate = false; |
| 200 | AvoidMOVsShifterOperand = false; |
| 201 | HasRAS = false; |
| 202 | HasMPExtension = false; |
Bradley Smith | 2521975 | 2013-11-01 13:27:35 +0000 | [diff] [blame] | 203 | HasVirtualization = false; |
Bill Wendling | 61375d8 | 2013-02-16 01:36:26 +0000 | [diff] [blame] | 204 | FPOnlySP = false; |
Tim Northover | cedd481 | 2013-05-23 19:11:14 +0000 | [diff] [blame] | 205 | HasPerfMon = false; |
Tim Northover | c604765 | 2013-04-10 12:08:35 +0000 | [diff] [blame] | 206 | HasTrustZone = false; |
Amara Emerson | 3308909 | 2013-09-19 11:59:01 +0000 | [diff] [blame] | 207 | HasCrypto = false; |
Amara Emerson | f9a67fc | 2013-10-29 16:54:52 +0000 | [diff] [blame] | 208 | HasCRC = false; |
Tim Northover | 1351030 | 2014-04-01 13:22:02 +0000 | [diff] [blame] | 209 | HasZeroCycleZeroing = false; |
Bill Wendling | 61375d8 | 2013-02-16 01:36:26 +0000 | [diff] [blame] | 210 | AllowsUnalignedMem = false; |
| 211 | Thumb2DSP = false; |
| 212 | UseNaClTrap = false; |
Renato Golin | b4dd6c5 | 2013-03-21 18:47:47 +0000 | [diff] [blame] | 213 | UnsafeFPMath = false; |
Bill Wendling | 61375d8 | 2013-02-16 01:36:26 +0000 | [diff] [blame] | 214 | } |
| 215 | |
Eric Christopher | b68e253 | 2014-09-03 20:36:31 +0000 | [diff] [blame] | 216 | void ARMSubtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) { |
Tilmann Scheller | 63872ce | 2013-09-02 17:09:01 +0000 | [diff] [blame] | 217 | if (CPUString.empty()) { |
| 218 | if (isTargetIOS() && TargetTriple.getArchName().endswith("v7s")) |
| 219 | // Default to the Swift CPU when targeting armv7s/thumbv7s. |
| 220 | CPUString = "swift"; |
| 221 | else |
| 222 | CPUString = "generic"; |
| 223 | } |
Evan Cheng | ec415ef | 2009-03-08 04:02:49 +0000 | [diff] [blame] | 224 | |
Evan Cheng | 0b33a32 | 2011-06-30 02:12:44 +0000 | [diff] [blame] | 225 | // Insert the architecture feature derived from the target triple into the |
| 226 | // feature string. This is important for setting features that are implied |
| 227 | // based on the architecture version. |
Bill Wendling | 5a92eec | 2013-02-15 22:41:25 +0000 | [diff] [blame] | 228 | std::string ArchFS = ARM_MC::ParseARMTriple(TargetTriple.getTriple(), |
| 229 | CPUString); |
Evan Cheng | 2bd6536 | 2011-07-07 00:08:19 +0000 | [diff] [blame] | 230 | if (!FS.empty()) { |
| 231 | if (!ArchFS.empty()) |
Bill Wendling | 5a92eec | 2013-02-15 22:41:25 +0000 | [diff] [blame] | 232 | ArchFS = ArchFS + "," + FS.str(); |
Evan Cheng | 2bd6536 | 2011-07-07 00:08:19 +0000 | [diff] [blame] | 233 | else |
| 234 | ArchFS = FS; |
| 235 | } |
Evan Cheng | 1a72add6 | 2011-07-07 07:07:08 +0000 | [diff] [blame] | 236 | ParseSubtargetFeatures(CPUString, ArchFS); |
Evan Cheng | 2bd6536 | 2011-07-07 00:08:19 +0000 | [diff] [blame] | 237 | |
Joerg Sonnenberger | 002a147 | 2013-12-13 11:16:00 +0000 | [diff] [blame] | 238 | // FIXME: This used enable V6T2 support implicitly for Thumb2 mode. |
| 239 | // Assert this for now to make the change obvious. |
| 240 | assert(hasV6T2Ops() || !hasThumb2()); |
Bob Wilson | d0046ca | 2010-11-09 22:50:47 +0000 | [diff] [blame] | 241 | |
Andrew Trick | 352abc1 | 2012-08-08 02:44:16 +0000 | [diff] [blame] | 242 | // Keep a pointer to static instruction cost data for the specified CPU. |
| 243 | SchedModel = getSchedModelForCPU(CPUString); |
| 244 | |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 245 | // Initialize scheduling itinerary for the specified CPU. |
| 246 | InstrItins = getInstrItineraryForCPU(CPUString); |
| 247 | |
Rafael Espindola | d89b16d | 2014-01-02 13:40:08 +0000 | [diff] [blame] | 248 | if (TargetABI == ARM_ABI_UNKNOWN) { |
| 249 | switch (TargetTriple.getEnvironment()) { |
| 250 | case Triple::Android: |
| 251 | case Triple::EABI: |
| 252 | case Triple::EABIHF: |
| 253 | case Triple::GNUEABI: |
| 254 | case Triple::GNUEABIHF: |
Joerg Sonnenberger | 7466979 | 2013-12-15 00:12:52 +0000 | [diff] [blame] | 255 | TargetABI = ARM_ABI_AAPCS; |
Rafael Espindola | d89b16d | 2014-01-02 13:40:08 +0000 | [diff] [blame] | 256 | break; |
| 257 | default: |
Tim Northover | e9ff4c2 | 2014-10-15 01:05:01 +0000 | [diff] [blame] | 258 | if (TargetTriple.isOSBinFormatMachO() && |
| 259 | TargetTriple.getOS() == Triple::UnknownOS) |
Rafael Espindola | d89b16d | 2014-01-02 13:40:08 +0000 | [diff] [blame] | 260 | TargetABI = ARM_ABI_AAPCS; |
| 261 | else |
| 262 | TargetABI = ARM_ABI_APCS; |
| 263 | break; |
| 264 | } |
Joerg Sonnenberger | 7466979 | 2013-12-15 00:12:52 +0000 | [diff] [blame] | 265 | } |
Evan Cheng | 1a72add6 | 2011-07-07 07:07:08 +0000 | [diff] [blame] | 266 | |
Saleem Abdulrasool | cd13082 | 2014-04-02 20:32:05 +0000 | [diff] [blame] | 267 | // FIXME: this is invalid for WindowsCE |
| 268 | if (isTargetWindows()) { |
| 269 | TargetABI = ARM_ABI_AAPCS; |
| 270 | NoARM = true; |
| 271 | } |
| 272 | |
Lauro Ramos Venancio | 048e16ff | 2007-02-13 19:52:28 +0000 | [diff] [blame] | 273 | if (isAAPCS_ABI()) |
| 274 | stackAlignment = 8; |
Mark Seaborn | be266aa | 2014-02-16 18:59:48 +0000 | [diff] [blame] | 275 | if (isTargetNaCl()) |
| 276 | stackAlignment = 16; |
Lauro Ramos Venancio | 048e16ff | 2007-02-13 19:52:28 +0000 | [diff] [blame] | 277 | |
Renato Golin | ca57063 | 2013-08-15 20:54:38 +0000 | [diff] [blame] | 278 | UseMovt = hasV6T2Ops() && ArmUseMOVT; |
| 279 | |
Tim Northover | d6a729b | 2014-01-06 14:28:05 +0000 | [diff] [blame] | 280 | if (isTargetMachO()) { |
Richard Trieu | 1fbe1a8 | 2014-09-17 01:47:52 +0000 | [diff] [blame] | 281 | IsR9Reserved = ReserveR9 || !HasV6Ops; |
Tim Northover | d6a729b | 2014-01-06 14:28:05 +0000 | [diff] [blame] | 282 | SupportsTailCall = !isTargetIOS() || !getTargetTriple().isOSVersionLT(5, 0); |
Saleem Abdulrasool | ec1ec1b | 2014-03-11 15:09:44 +0000 | [diff] [blame] | 283 | } else { |
Tim Northover | d6a729b | 2014-01-06 14:28:05 +0000 | [diff] [blame] | 284 | IsR9Reserved = ReserveR9; |
Saleem Abdulrasool | ec1ec1b | 2014-03-11 15:09:44 +0000 | [diff] [blame] | 285 | SupportsTailCall = !isThumb1Only(); |
| 286 | } |
David Goodwin | 9a051a5 | 2009-10-01 21:46:35 +0000 | [diff] [blame] | 287 | |
Renato Golin | 51dc3f4 | 2014-10-08 12:26:13 +0000 | [diff] [blame] | 288 | if (Align == DefaultAlign) { |
| 289 | // Assume pre-ARMv6 doesn't support unaligned accesses. |
| 290 | // |
| 291 | // ARMv6 may or may not support unaligned accesses depending on the |
| 292 | // SCTLR.U bit, which is architecture-specific. We assume ARMv6 |
| 293 | // Darwin and NetBSD targets support unaligned accesses, and others don't. |
| 294 | // |
| 295 | // ARMv7 always has SCTLR.U set to 1, but it has a new SCTLR.A bit |
| 296 | // which raises an alignment fault on unaligned accesses. Linux |
| 297 | // defaults this bit to 0 and handles it as a system-wide (not |
| 298 | // per-process) setting. It is therefore safe to assume that ARMv7+ |
| 299 | // Linux targets support unaligned accesses. The same goes for NaCl. |
| 300 | // |
| 301 | // The above behavior is consistent with GCC. |
| 302 | AllowsUnalignedMem = |
| 303 | (hasV7Ops() && (isTargetLinux() || isTargetNaCl() || |
| 304 | isTargetNetBSD())) || |
| 305 | (hasV6Ops() && (isTargetMachO() || isTargetNetBSD())); |
Renato Golin | 51dc3f4 | 2014-10-08 12:26:13 +0000 | [diff] [blame] | 306 | } else { |
| 307 | AllowsUnalignedMem = !(Align == StrictAlign); |
JF Bastien | 97b08c40 | 2013-05-17 23:49:01 +0000 | [diff] [blame] | 308 | } |
Renato Golin | b4dd6c5 | 2013-03-21 18:47:47 +0000 | [diff] [blame] | 309 | |
Renato Golin | bab5ace | 2014-10-08 12:26:16 +0000 | [diff] [blame] | 310 | // No v6M core supports unaligned memory access (v6M ARM ARM A3.2) |
| 311 | if (isV6M()) |
| 312 | AllowsUnalignedMem = false; |
| 313 | |
Weiming Zhao | 0da5cc0 | 2013-11-13 18:29:49 +0000 | [diff] [blame] | 314 | switch (IT) { |
| 315 | case DefaultIT: |
| 316 | RestrictIT = hasV8Ops() ? true : false; |
| 317 | break; |
| 318 | case RestrictedIT: |
| 319 | RestrictIT = true; |
| 320 | break; |
| 321 | case NoRestrictedIT: |
| 322 | RestrictIT = false; |
| 323 | break; |
| 324 | } |
| 325 | |
Renato Golin | b4dd6c5 | 2013-03-21 18:47:47 +0000 | [diff] [blame] | 326 | // NEON f32 ops are non-IEEE 754 compliant. Darwin is ok with it by default. |
| 327 | uint64_t Bits = getFeatureBits(); |
| 328 | if ((Bits & ARM::ProcA5 || Bits & ARM::ProcA8) && // Where this matters |
| 329 | (Options.UnsafeFPMath || isTargetDarwin())) |
| 330 | UseNEONForSinglePrecisionFP = true; |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 331 | } |
Evan Cheng | 43b9ca6 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 332 | |
| 333 | /// GVIsIndirectSymbol - true if the GV will be accessed via an indirect symbol. |
Evan Cheng | 1b38952 | 2009-09-03 07:04:02 +0000 | [diff] [blame] | 334 | bool |
Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 335 | ARMSubtarget::GVIsIndirectSymbol(const GlobalValue *GV, |
| 336 | Reloc::Model RelocM) const { |
Evan Cheng | 1b38952 | 2009-09-03 07:04:02 +0000 | [diff] [blame] | 337 | if (RelocM == Reloc::Static) |
Evan Cheng | 43b9ca6 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 338 | return false; |
Evan Cheng | 1b38952 | 2009-09-03 07:04:02 +0000 | [diff] [blame] | 339 | |
Jeffrey Yasskin | 091217b | 2010-01-27 20:34:15 +0000 | [diff] [blame] | 340 | // Materializable GVs (in JIT lazy compilation mode) do not require an extra |
| 341 | // load from stub. |
Evan Cheng | 2ce6630 | 2011-02-22 06:58:34 +0000 | [diff] [blame] | 342 | bool isDecl = GV->hasAvailableExternallyLinkage(); |
| 343 | if (GV->isDeclaration() && !GV->isMaterializable()) |
| 344 | isDecl = true; |
Evan Cheng | 1b38952 | 2009-09-03 07:04:02 +0000 | [diff] [blame] | 345 | |
Tim Northover | d6a729b | 2014-01-06 14:28:05 +0000 | [diff] [blame] | 346 | if (!isTargetMachO()) { |
Evan Cheng | 1b38952 | 2009-09-03 07:04:02 +0000 | [diff] [blame] | 347 | // Extra load is needed for all externally visible. |
| 348 | if (GV->hasLocalLinkage() || GV->hasHiddenVisibility()) |
| 349 | return false; |
| 350 | return true; |
| 351 | } else { |
| 352 | if (RelocM == Reloc::PIC_) { |
| 353 | // If this is a strong reference to a definition, it is definitely not |
| 354 | // through a stub. |
| 355 | if (!isDecl && !GV->isWeakForLinker()) |
| 356 | return false; |
| 357 | |
| 358 | // Unless we have a symbol with hidden visibility, we have to go through a |
| 359 | // normal $non_lazy_ptr stub because this symbol might be resolved late. |
| 360 | if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference. |
| 361 | return true; |
| 362 | |
| 363 | // If symbol visibility is hidden, we have a stub for common symbol |
| 364 | // references and external declarations. |
| 365 | if (isDecl || GV->hasCommonLinkage()) |
| 366 | // Hidden $non_lazy_ptr reference. |
| 367 | return true; |
| 368 | |
| 369 | return false; |
| 370 | } else { |
| 371 | // If this is a strong reference to a definition, it is definitely not |
| 372 | // through a stub. |
| 373 | if (!isDecl && !GV->isWeakForLinker()) |
| 374 | return false; |
Andrew Trick | c416ba6 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 375 | |
Evan Cheng | 1b38952 | 2009-09-03 07:04:02 +0000 | [diff] [blame] | 376 | // Unless we have a symbol with hidden visibility, we have to go through a |
| 377 | // normal $non_lazy_ptr stub because this symbol might be resolved late. |
| 378 | if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference. |
| 379 | return true; |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | return false; |
Evan Cheng | 43b9ca6 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 384 | } |
David Goodwin | 0d412c2 | 2009-11-10 00:48:55 +0000 | [diff] [blame] | 385 | |
Owen Anderson | a3181e2 | 2010-09-28 21:57:50 +0000 | [diff] [blame] | 386 | unsigned ARMSubtarget::getMispredictionPenalty() const { |
Pete Cooper | 1175945 | 2014-09-02 17:43:54 +0000 | [diff] [blame] | 387 | return SchedModel.MispredictPenalty; |
Owen Anderson | a3181e2 | 2010-09-28 21:57:50 +0000 | [diff] [blame] | 388 | } |
| 389 | |
Bob Wilson | e7dde0c | 2013-11-03 06:14:38 +0000 | [diff] [blame] | 390 | bool ARMSubtarget::hasSinCos() const { |
Bob Wilson | 9868d71 | 2014-10-09 05:43:30 +0000 | [diff] [blame] | 391 | return getTargetTriple().isiOS() && !getTargetTriple().isOSVersionLT(7, 0); |
Bob Wilson | e7dde0c | 2013-11-03 06:14:38 +0000 | [diff] [blame] | 392 | } |
| 393 | |
Sanjay Patel | a2f658d | 2014-07-15 22:39:58 +0000 | [diff] [blame] | 394 | // This overrides the PostRAScheduler bit in the SchedModel for any CPU. |
Andrew Trick | 8d2ee37 | 2014-06-04 07:06:27 +0000 | [diff] [blame] | 395 | bool ARMSubtarget::enablePostMachineScheduler() const { |
Sanjay Patel | a2f658d | 2014-07-15 22:39:58 +0000 | [diff] [blame] | 396 | return (!isThumb() || hasThumb2()); |
Andrew Trick | 8d2ee37 | 2014-06-04 07:06:27 +0000 | [diff] [blame] | 397 | } |
| 398 | |
Robin Morisset | 59c23cd | 2014-08-21 21:50:01 +0000 | [diff] [blame] | 399 | bool ARMSubtarget::enableAtomicExpand() const { |
Eric Christopher | c40e5ed | 2014-06-19 21:03:04 +0000 | [diff] [blame] | 400 | return hasAnyDataBarrier() && !isThumb1Only(); |
| 401 | } |
| 402 | |
Eric Christopher | c1058df | 2014-07-04 01:55:26 +0000 | [diff] [blame] | 403 | bool ARMSubtarget::useMovt(const MachineFunction &MF) const { |
| 404 | // NOTE Windows on ARM needs to use mov.w/mov.t pairs to materialise 32-bit |
| 405 | // immediates as it is inherently position independent, and may be out of |
| 406 | // range otherwise. |
| 407 | return UseMovt && (isTargetWindows() || |
| 408 | !MF.getFunction()->getAttributes().hasAttribute( |
| 409 | AttributeSet::FunctionIndex, Attribute::MinSize)); |
| 410 | } |