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