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