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