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