Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 1 | //===-- AArch64Subtarget.cpp - AArch64 Subtarget Information ----*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the AArch64 specific subclass of TargetSubtarget. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Rafael Espindola | 6b4baa5 | 2016-05-25 21:37:29 +0000 | [diff] [blame] | 14 | #include "AArch64Subtarget.h" |
Quentin Colombet | cdf8c81 | 2017-05-01 21:53:19 +0000 | [diff] [blame] | 15 | |
| 16 | #include "AArch64.h" |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 17 | #include "AArch64InstrInfo.h" |
Lang Hames | 8f31f44 | 2014-10-09 18:20:51 +0000 | [diff] [blame] | 18 | #include "AArch64PBQPRegAlloc.h" |
Quentin Colombet | cdf8c81 | 2017-05-01 21:53:19 +0000 | [diff] [blame] | 19 | #include "AArch64TargetMachine.h" |
| 20 | |
| 21 | #ifdef LLVM_BUILD_GLOBAL_ISEL |
| 22 | #include "AArch64CallLowering.h" |
| 23 | #include "AArch64LegalizerInfo.h" |
| 24 | #include "AArch64RegisterBankInfo.h" |
| 25 | #include "llvm/CodeGen/GlobalISel/GISelAccessor.h" |
| 26 | #include "llvm/CodeGen/GlobalISel/IRTranslator.h" |
| 27 | #include "llvm/CodeGen/GlobalISel/InstructionSelect.h" |
| 28 | #include "llvm/CodeGen/GlobalISel/Legalizer.h" |
| 29 | #include "llvm/CodeGen/GlobalISel/RegBankSelect.h" |
| 30 | #endif |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 31 | #include "llvm/CodeGen/MachineScheduler.h" |
| 32 | #include "llvm/IR/GlobalValue.h" |
| 33 | #include "llvm/Support/TargetRegistry.h" |
| 34 | |
| 35 | using namespace llvm; |
| 36 | |
| 37 | #define DEBUG_TYPE "aarch64-subtarget" |
| 38 | |
| 39 | #define GET_SUBTARGETINFO_CTOR |
| 40 | #define GET_SUBTARGETINFO_TARGET_DESC |
| 41 | #include "AArch64GenSubtargetInfo.inc" |
| 42 | |
| 43 | static cl::opt<bool> |
| 44 | EnableEarlyIfConvert("aarch64-early-ifcvt", cl::desc("Enable the early if " |
| 45 | "converter pass"), cl::init(true), cl::Hidden); |
| 46 | |
Tim Northover | 339c83e | 2015-11-10 00:44:23 +0000 | [diff] [blame] | 47 | // If OS supports TBI, use this flag to enable it. |
| 48 | static cl::opt<bool> |
| 49 | UseAddressTopByteIgnored("aarch64-use-tbi", cl::desc("Assume that top byte of " |
| 50 | "an address is ignored"), cl::init(false), cl::Hidden); |
| 51 | |
Tim Northover | 46e36f0 | 2017-04-17 18:18:47 +0000 | [diff] [blame] | 52 | static cl::opt<bool> |
| 53 | UseNonLazyBind("aarch64-enable-nonlazybind", |
| 54 | cl::desc("Call nonlazybind functions via direct GOT load"), |
| 55 | cl::init(false), cl::Hidden); |
| 56 | |
Eric Christopher | 7c9d4e0 | 2014-06-11 00:46:34 +0000 | [diff] [blame] | 57 | AArch64Subtarget & |
Matthias Braun | a827ed8 | 2016-10-03 20:17:02 +0000 | [diff] [blame] | 58 | AArch64Subtarget::initializeSubtargetDependencies(StringRef FS, |
| 59 | StringRef CPUString) { |
Eric Christopher | 7c9d4e0 | 2014-06-11 00:46:34 +0000 | [diff] [blame] | 60 | // Determine default and user-specified characteristics |
| 61 | |
| 62 | if (CPUString.empty()) |
| 63 | CPUString = "generic"; |
| 64 | |
| 65 | ParseSubtargetFeatures(CPUString, FS); |
Matthias Braun | 651cff4 | 2016-06-02 18:03:53 +0000 | [diff] [blame] | 66 | initializeProperties(); |
| 67 | |
Eric Christopher | 7c9d4e0 | 2014-06-11 00:46:34 +0000 | [diff] [blame] | 68 | return *this; |
| 69 | } |
| 70 | |
Matthias Braun | 651cff4 | 2016-06-02 18:03:53 +0000 | [diff] [blame] | 71 | void AArch64Subtarget::initializeProperties() { |
| 72 | // Initialize CPU specific properties. We should add a tablegen feature for |
| 73 | // this in the future so we can specify it together with the subtarget |
| 74 | // features. |
| 75 | switch (ARMProcFamily) { |
| 76 | case Cyclone: |
| 77 | CacheLineSize = 64; |
| 78 | PrefetchDistance = 280; |
| 79 | MinPrefetchStride = 2048; |
| 80 | MaxPrefetchIterationsAhead = 3; |
| 81 | break; |
| 82 | case CortexA57: |
| 83 | MaxInterleaveFactor = 4; |
Florian Hahn | d4550ba | 2017-07-07 10:43:01 +0000 | [diff] [blame] | 84 | PrefFunctionAlignment = 4; |
Matthias Braun | 651cff4 | 2016-06-02 18:03:53 +0000 | [diff] [blame] | 85 | break; |
Evandro Menezes | a3a0a60 | 2016-06-10 16:00:18 +0000 | [diff] [blame] | 86 | case ExynosM1: |
Abderrazek Zaafrani | 9daf811 | 2016-10-21 16:28:27 +0000 | [diff] [blame] | 87 | MaxInterleaveFactor = 4; |
Evandro Menezes | 7696dc0 | 2016-10-25 20:05:42 +0000 | [diff] [blame] | 88 | MaxJumpTableSize = 8; |
Evandro Menezes | a3a0a60 | 2016-06-10 16:00:18 +0000 | [diff] [blame] | 89 | PrefFunctionAlignment = 4; |
| 90 | PrefLoopAlignment = 3; |
| 91 | break; |
Chad Rosier | ecc7727 | 2016-11-22 14:25:02 +0000 | [diff] [blame] | 92 | case Falkor: |
| 93 | MaxInterleaveFactor = 4; |
Adam Nemet | e29686e | 2017-05-15 21:15:01 +0000 | [diff] [blame] | 94 | // FIXME: remove this to enable 64-bit SLP if performance looks good. |
| 95 | MinVectorRegisterBitWidth = 128; |
Haicheng Wu | ef790ff | 2017-06-12 16:34:19 +0000 | [diff] [blame] | 96 | CacheLineSize = 128; |
| 97 | PrefetchDistance = 820; |
| 98 | MinPrefetchStride = 2048; |
| 99 | MaxPrefetchIterationsAhead = 8; |
Chad Rosier | ecc7727 | 2016-11-22 14:25:02 +0000 | [diff] [blame] | 100 | break; |
Matthias Braun | 651cff4 | 2016-06-02 18:03:53 +0000 | [diff] [blame] | 101 | case Kryo: |
| 102 | MaxInterleaveFactor = 4; |
| 103 | VectorInsertExtractBaseCost = 2; |
Haicheng Wu | a783bac | 2016-06-21 22:47:56 +0000 | [diff] [blame] | 104 | CacheLineSize = 128; |
| 105 | PrefetchDistance = 740; |
| 106 | MinPrefetchStride = 1024; |
| 107 | MaxPrefetchIterationsAhead = 11; |
Adam Nemet | e29686e | 2017-05-15 21:15:01 +0000 | [diff] [blame] | 108 | // FIXME: remove this to enable 64-bit SLP if performance looks good. |
| 109 | MinVectorRegisterBitWidth = 128; |
Matthias Braun | 651cff4 | 2016-06-02 18:03:53 +0000 | [diff] [blame] | 110 | break; |
Joel Jones | 2852088 | 2017-03-07 19:42:40 +0000 | [diff] [blame] | 111 | case ThunderX2T99: |
| 112 | CacheLineSize = 64; |
| 113 | PrefFunctionAlignment = 3; |
| 114 | PrefLoopAlignment = 2; |
Pankaj Gode | f4b2554 | 2016-06-30 06:42:31 +0000 | [diff] [blame] | 115 | MaxInterleaveFactor = 4; |
Joel Jones | 2852088 | 2017-03-07 19:42:40 +0000 | [diff] [blame] | 116 | PrefetchDistance = 128; |
| 117 | MinPrefetchStride = 1024; |
| 118 | MaxPrefetchIterationsAhead = 4; |
Adam Nemet | e29686e | 2017-05-15 21:15:01 +0000 | [diff] [blame] | 119 | // FIXME: remove this to enable 64-bit SLP if performance looks good. |
| 120 | MinVectorRegisterBitWidth = 128; |
Pankaj Gode | f4b2554 | 2016-06-30 06:42:31 +0000 | [diff] [blame] | 121 | break; |
Joel Jones | ab0f3b4 | 2017-02-17 18:34:24 +0000 | [diff] [blame] | 122 | case ThunderX: |
| 123 | case ThunderXT88: |
| 124 | case ThunderXT81: |
| 125 | case ThunderXT83: |
| 126 | CacheLineSize = 128; |
Joel Jones | 2852088 | 2017-03-07 19:42:40 +0000 | [diff] [blame] | 127 | PrefFunctionAlignment = 3; |
| 128 | PrefLoopAlignment = 2; |
Adam Nemet | e29686e | 2017-05-15 21:15:01 +0000 | [diff] [blame] | 129 | // FIXME: remove this to enable 64-bit SLP if performance looks good. |
| 130 | MinVectorRegisterBitWidth = 128; |
Joel Jones | ab0f3b4 | 2017-02-17 18:34:24 +0000 | [diff] [blame] | 131 | break; |
Matthias Braun | 651cff4 | 2016-06-02 18:03:53 +0000 | [diff] [blame] | 132 | case CortexA35: break; |
Florian Hahn | 2f86e3d | 2017-07-29 20:04:54 +0000 | [diff] [blame^] | 133 | case CortexA53: |
| 134 | PrefFunctionAlignment = 3; |
| 135 | break; |
Florian Hahn | e3666ec | 2017-07-07 10:15:49 +0000 | [diff] [blame] | 136 | case CortexA72: |
| 137 | PrefFunctionAlignment = 4; |
| 138 | break; |
Florian Hahn | 3530094 | 2017-07-18 09:31:18 +0000 | [diff] [blame] | 139 | case CortexA73: |
| 140 | PrefFunctionAlignment = 4; |
| 141 | break; |
Evandro Menezes | a3a0a60 | 2016-06-10 16:00:18 +0000 | [diff] [blame] | 142 | case Others: break; |
Matthias Braun | 651cff4 | 2016-06-02 18:03:53 +0000 | [diff] [blame] | 143 | } |
| 144 | } |
| 145 | |
Quentin Colombet | cdf8c81 | 2017-05-01 21:53:19 +0000 | [diff] [blame] | 146 | #ifdef LLVM_BUILD_GLOBAL_ISEL |
| 147 | namespace { |
| 148 | |
| 149 | struct AArch64GISelActualAccessor : public GISelAccessor { |
| 150 | std::unique_ptr<CallLowering> CallLoweringInfo; |
| 151 | std::unique_ptr<InstructionSelector> InstSelector; |
| 152 | std::unique_ptr<LegalizerInfo> Legalizer; |
| 153 | std::unique_ptr<RegisterBankInfo> RegBankInfo; |
| 154 | |
| 155 | const CallLowering *getCallLowering() const override { |
| 156 | return CallLoweringInfo.get(); |
| 157 | } |
| 158 | |
| 159 | const InstructionSelector *getInstructionSelector() const override { |
| 160 | return InstSelector.get(); |
| 161 | } |
| 162 | |
| 163 | const LegalizerInfo *getLegalizerInfo() const override { |
| 164 | return Legalizer.get(); |
| 165 | } |
| 166 | |
| 167 | const RegisterBankInfo *getRegBankInfo() const override { |
| 168 | return RegBankInfo.get(); |
| 169 | } |
| 170 | }; |
| 171 | |
| 172 | } // end anonymous namespace |
| 173 | #endif |
| 174 | |
Daniel Sanders | a73f1fd | 2015-06-10 12:11:26 +0000 | [diff] [blame] | 175 | AArch64Subtarget::AArch64Subtarget(const Triple &TT, const std::string &CPU, |
Eric Christopher | f12e1ab | 2014-10-03 00:42:41 +0000 | [diff] [blame] | 176 | const std::string &FS, |
Daniel Sanders | a1b2db79 | 2017-05-19 11:08:33 +0000 | [diff] [blame] | 177 | const TargetMachine &TM, bool LittleEndian) |
Mandeep Singh Grang | d857b4c | 2017-07-18 20:41:33 +0000 | [diff] [blame] | 178 | : AArch64GenSubtargetInfo(TT, CPU, FS), |
| 179 | ReserveX18(TT.isOSDarwin() || TT.isOSWindows()), |
Matthias Braun | a827ed8 | 2016-10-03 20:17:02 +0000 | [diff] [blame] | 180 | IsLittle(LittleEndian), TargetTriple(TT), FrameLowering(), |
| 181 | InstrInfo(initializeSubtargetDependencies(FS, CPU)), TSInfo(), |
Daniel Sanders | a1b2db79 | 2017-05-19 11:08:33 +0000 | [diff] [blame] | 182 | TLInfo(TM, *this), GISel() { |
Quentin Colombet | cdf8c81 | 2017-05-01 21:53:19 +0000 | [diff] [blame] | 183 | #ifndef LLVM_BUILD_GLOBAL_ISEL |
| 184 | GISelAccessor *AArch64GISel = new GISelAccessor(); |
| 185 | #else |
| 186 | AArch64GISelActualAccessor *AArch64GISel = new AArch64GISelActualAccessor(); |
| 187 | AArch64GISel->CallLoweringInfo.reset( |
| 188 | new AArch64CallLowering(*getTargetLowering())); |
| 189 | AArch64GISel->Legalizer.reset(new AArch64LegalizerInfo()); |
| 190 | |
| 191 | auto *RBI = new AArch64RegisterBankInfo(*getRegisterInfo()); |
| 192 | |
| 193 | // FIXME: At this point, we can't rely on Subtarget having RBI. |
| 194 | // It's awkward to mix passing RBI and the Subtarget; should we pass |
| 195 | // TII/TRI as well? |
| 196 | AArch64GISel->InstSelector.reset(createAArch64InstructionSelector( |
| 197 | *static_cast<const AArch64TargetMachine *>(&TM), *this, *RBI)); |
| 198 | |
| 199 | AArch64GISel->RegBankInfo.reset(RBI); |
| 200 | #endif |
| 201 | setGISelAccessor(*AArch64GISel); |
| 202 | } |
Quentin Colombet | ba2a016 | 2016-02-16 19:26:02 +0000 | [diff] [blame] | 203 | |
| 204 | const CallLowering *AArch64Subtarget::getCallLowering() const { |
Tom Stellard | cef0fe4 | 2016-04-14 17:45:38 +0000 | [diff] [blame] | 205 | assert(GISel && "Access to GlobalISel APIs not set"); |
| 206 | return GISel->getCallLowering(); |
Quentin Colombet | c17f744 | 2016-04-06 17:26:03 +0000 | [diff] [blame] | 207 | } |
| 208 | |
Ahmed Bougacha | 6756a2c | 2016-07-27 14:31:55 +0000 | [diff] [blame] | 209 | const InstructionSelector *AArch64Subtarget::getInstructionSelector() const { |
| 210 | assert(GISel && "Access to GlobalISel APIs not set"); |
| 211 | return GISel->getInstructionSelector(); |
| 212 | } |
| 213 | |
Tim Northover | 69fa84a | 2016-10-14 22:18:18 +0000 | [diff] [blame] | 214 | const LegalizerInfo *AArch64Subtarget::getLegalizerInfo() const { |
Tim Northover | 33b07d6 | 2016-07-22 20:03:43 +0000 | [diff] [blame] | 215 | assert(GISel && "Access to GlobalISel APIs not set"); |
Tim Northover | 69fa84a | 2016-10-14 22:18:18 +0000 | [diff] [blame] | 216 | return GISel->getLegalizerInfo(); |
Tim Northover | 33b07d6 | 2016-07-22 20:03:43 +0000 | [diff] [blame] | 217 | } |
| 218 | |
Quentin Colombet | c17f744 | 2016-04-06 17:26:03 +0000 | [diff] [blame] | 219 | const RegisterBankInfo *AArch64Subtarget::getRegBankInfo() const { |
Tom Stellard | cef0fe4 | 2016-04-14 17:45:38 +0000 | [diff] [blame] | 220 | assert(GISel && "Access to GlobalISel APIs not set"); |
| 221 | return GISel->getRegBankInfo(); |
Quentin Colombet | ba2a016 | 2016-02-16 19:26:02 +0000 | [diff] [blame] | 222 | } |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 223 | |
Rafael Espindola | 6b93bf5 | 2016-05-25 22:44:06 +0000 | [diff] [blame] | 224 | /// Find the target operand flags that describe how a global value should be |
| 225 | /// referenced for the current subtarget. |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 226 | unsigned char |
| 227 | AArch64Subtarget::ClassifyGlobalReference(const GlobalValue *GV, |
Rafael Espindola | 6b93bf5 | 2016-05-25 22:44:06 +0000 | [diff] [blame] | 228 | const TargetMachine &TM) const { |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 229 | // MachO large model always goes via a GOT, simply to get a single 8-byte |
| 230 | // absolute relocation on all global addresses. |
| 231 | if (TM.getCodeModel() == CodeModel::Large && isTargetMachO()) |
| 232 | return AArch64II::MO_GOT; |
| 233 | |
Rafael Espindola | 3beef8d | 2016-06-27 23:15:57 +0000 | [diff] [blame] | 234 | if (!TM.shouldAssumeDSOLocal(*GV->getParent(), GV)) |
Rafael Espindola | a224de0 | 2016-05-26 12:42:55 +0000 | [diff] [blame] | 235 | return AArch64II::MO_GOT; |
| 236 | |
Petr Hosek | 9eb0a1e | 2017-04-04 19:51:53 +0000 | [diff] [blame] | 237 | // The small code model's direct accesses use ADRP, which cannot |
| 238 | // necessarily produce the value 0 (if the code is above 4GB). |
| 239 | if (useSmallAddressing() && GV->hasExternalWeakLinkage()) |
Rafael Espindola | 4d29099 | 2016-05-31 18:31:14 +0000 | [diff] [blame] | 240 | return AArch64II::MO_GOT; |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 241 | |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 242 | return AArch64II::MO_NO_FLAG; |
| 243 | } |
| 244 | |
Tim Northover | 879a0b2 | 2017-04-17 17:27:56 +0000 | [diff] [blame] | 245 | unsigned char AArch64Subtarget::classifyGlobalFunctionReference( |
| 246 | const GlobalValue *GV, const TargetMachine &TM) const { |
| 247 | // MachO large model always goes via a GOT, because we don't have the |
| 248 | // relocations available to do anything else.. |
| 249 | if (TM.getCodeModel() == CodeModel::Large && isTargetMachO() && |
| 250 | !GV->hasInternalLinkage()) |
| 251 | return AArch64II::MO_GOT; |
| 252 | |
| 253 | // NonLazyBind goes via GOT unless we know it's available locally. |
| 254 | auto *F = dyn_cast<Function>(GV); |
Tim Northover | 46e36f0 | 2017-04-17 18:18:47 +0000 | [diff] [blame] | 255 | if (UseNonLazyBind && F && F->hasFnAttribute(Attribute::NonLazyBind) && |
Tim Northover | 879a0b2 | 2017-04-17 17:27:56 +0000 | [diff] [blame] | 256 | !TM.shouldAssumeDSOLocal(*GV->getParent(), GV)) |
| 257 | return AArch64II::MO_GOT; |
| 258 | |
| 259 | return AArch64II::MO_NO_FLAG; |
| 260 | } |
| 261 | |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 262 | /// This function returns the name of a function which has an interface |
| 263 | /// like the non-standard bzero function, if such a function exists on |
| 264 | /// the current subtarget and it is considered prefereable over |
| 265 | /// memset with zero passed as the second argument. Otherwise it |
| 266 | /// returns null. |
| 267 | const char *AArch64Subtarget::getBZeroEntry() const { |
| 268 | // Prefer bzero on Darwin only. |
| 269 | if(isTargetDarwin()) |
| 270 | return "bzero"; |
| 271 | |
| 272 | return nullptr; |
| 273 | } |
| 274 | |
| 275 | void AArch64Subtarget::overrideSchedPolicy(MachineSchedPolicy &Policy, |
Duncan P. N. Exon Smith | 6329872 | 2016-07-01 00:23:27 +0000 | [diff] [blame] | 276 | unsigned NumRegionInstrs) const { |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 277 | // LNT run (at least on Cyclone) showed reasonably significant gains for |
| 278 | // bi-directional scheduling. 253.perlbmk. |
| 279 | Policy.OnlyTopDown = false; |
| 280 | Policy.OnlyBottomUp = false; |
Matthias Braun | d276de6 | 2015-10-22 18:07:38 +0000 | [diff] [blame] | 281 | // Enabling or Disabling the latency heuristic is a close call: It seems to |
| 282 | // help nearly no benchmark on out-of-order architectures, on the other hand |
| 283 | // it regresses register pressure on a few benchmarking. |
Matthias Braun | 651cff4 | 2016-06-02 18:03:53 +0000 | [diff] [blame] | 284 | Policy.DisableLatencyHeuristic = DisableLatencySchedHeuristic; |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | bool AArch64Subtarget::enableEarlyIfConversion() const { |
| 288 | return EnableEarlyIfConvert; |
| 289 | } |
Lang Hames | 8f31f44 | 2014-10-09 18:20:51 +0000 | [diff] [blame] | 290 | |
Tim Northover | 339c83e | 2015-11-10 00:44:23 +0000 | [diff] [blame] | 291 | bool AArch64Subtarget::supportsAddressTopByteIgnored() const { |
| 292 | if (!UseAddressTopByteIgnored) |
| 293 | return false; |
| 294 | |
| 295 | if (TargetTriple.isiOS()) { |
| 296 | unsigned Major, Minor, Micro; |
| 297 | TargetTriple.getiOSVersion(Major, Minor, Micro); |
| 298 | return Major >= 8; |
| 299 | } |
| 300 | |
| 301 | return false; |
| 302 | } |
| 303 | |
Lang Hames | 8f31f44 | 2014-10-09 18:20:51 +0000 | [diff] [blame] | 304 | std::unique_ptr<PBQPRAConstraint> |
| 305 | AArch64Subtarget::getCustomPBQPConstraints() const { |
Matthias Braun | 651cff4 | 2016-06-02 18:03:53 +0000 | [diff] [blame] | 306 | return balanceFPOps() ? llvm::make_unique<A57ChainingConstraint>() : nullptr; |
Lang Hames | 8f31f44 | 2014-10-09 18:20:51 +0000 | [diff] [blame] | 307 | } |