blob: 8e131b0caa6df9ce1613a8e5e6e08aa81beacaca [file] [log] [blame]
Tim Northover3b0846e2014-05-24 12:50:23 +00001//===-- AArch64Subtarget.cpp - AArch64 Subtarget Information ----*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Tim Northover3b0846e2014-05-24 12:50:23 +00006//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the AArch64 specific subclass of TargetSubtarget.
10//
11//===----------------------------------------------------------------------===//
12
Rafael Espindola6b4baa52016-05-25 21:37:29 +000013#include "AArch64Subtarget.h"
Quentin Colombetcdf8c812017-05-01 21:53:19 +000014
15#include "AArch64.h"
Quentin Colombetcdf8c812017-05-01 21:53:19 +000016#include "AArch64CallLowering.h"
Evandro Menezesb02ac8b2018-11-26 21:47:28 +000017#include "AArch64InstrInfo.h"
Quentin Colombetcdf8c812017-05-01 21:53:19 +000018#include "AArch64LegalizerInfo.h"
Evandro Menezesb02ac8b2018-11-26 21:47:28 +000019#include "AArch64PBQPRegAlloc.h"
Quentin Colombetcdf8c812017-05-01 21:53:19 +000020#include "AArch64RegisterBankInfo.h"
Evandro Menezesb02ac8b2018-11-26 21:47:28 +000021#include "AArch64TargetMachine.h"
22#include "MCTargetDesc/AArch64AddressingModes.h"
Quentin Colombetcdf8c812017-05-01 21:53:19 +000023#include "llvm/CodeGen/GlobalISel/InstructionSelect.h"
Tim Northover3b0846e2014-05-24 12:50:23 +000024#include "llvm/CodeGen/MachineScheduler.h"
25#include "llvm/IR/GlobalValue.h"
Peter Collingbournef11eb3e2018-04-04 21:55:44 +000026#include "llvm/Support/TargetParser.h"
Tim Northover3b0846e2014-05-24 12:50:23 +000027
28using namespace llvm;
29
30#define DEBUG_TYPE "aarch64-subtarget"
31
32#define GET_SUBTARGETINFO_CTOR
33#define GET_SUBTARGETINFO_TARGET_DESC
34#include "AArch64GenSubtargetInfo.inc"
35
36static cl::opt<bool>
37EnableEarlyIfConvert("aarch64-early-ifcvt", cl::desc("Enable the early if "
38 "converter pass"), cl::init(true), cl::Hidden);
39
Tim Northover339c83e2015-11-10 00:44:23 +000040// If OS supports TBI, use this flag to enable it.
41static cl::opt<bool>
42UseAddressTopByteIgnored("aarch64-use-tbi", cl::desc("Assume that top byte of "
43 "an address is ignored"), cl::init(false), cl::Hidden);
44
Tim Northover46e36f02017-04-17 18:18:47 +000045static cl::opt<bool>
46 UseNonLazyBind("aarch64-enable-nonlazybind",
47 cl::desc("Call nonlazybind functions via direct GOT load"),
48 cl::init(false), cl::Hidden);
49
Eric Christopher7c9d4e02014-06-11 00:46:34 +000050AArch64Subtarget &
Matthias Brauna827ed82016-10-03 20:17:02 +000051AArch64Subtarget::initializeSubtargetDependencies(StringRef FS,
52 StringRef CPUString) {
Eric Christopher7c9d4e02014-06-11 00:46:34 +000053 // Determine default and user-specified characteristics
54
55 if (CPUString.empty())
56 CPUString = "generic";
57
58 ParseSubtargetFeatures(CPUString, FS);
Matthias Braun651cff42016-06-02 18:03:53 +000059 initializeProperties();
60
Eric Christopher7c9d4e02014-06-11 00:46:34 +000061 return *this;
62}
63
Matthias Braun651cff42016-06-02 18:03:53 +000064void AArch64Subtarget::initializeProperties() {
65 // Initialize CPU specific properties. We should add a tablegen feature for
66 // this in the future so we can specify it together with the subtarget
67 // features.
68 switch (ARMProcFamily) {
Evandro Menezes3a06c462018-10-31 21:56:49 +000069 case Others:
70 break;
71 case CortexA35:
72 break;
73 case CortexA53:
Guillaume Chateletaff45e42019-09-05 10:00:22 +000074 PrefFunctionLogAlignment = 3;
Evandro Menezes3a06c462018-10-31 21:56:49 +000075 break;
76 case CortexA55:
77 break;
78 case CortexA57:
79 MaxInterleaveFactor = 4;
Guillaume Chateletaff45e42019-09-05 10:00:22 +000080 PrefFunctionLogAlignment = 4;
Evandro Menezes3a06c462018-10-31 21:56:49 +000081 break;
Pablo Barrio27595452019-07-25 10:59:45 +000082 case CortexA65:
Guillaume Chateletaff45e42019-09-05 10:00:22 +000083 PrefFunctionLogAlignment = 3;
Pablo Barrio27595452019-07-25 10:59:45 +000084 break;
Evandro Menezes3a06c462018-10-31 21:56:49 +000085 case CortexA72:
86 case CortexA73:
87 case CortexA75:
Luke Cheeseman59f77e72019-02-25 15:08:27 +000088 case CortexA76:
Guillaume Chateletaff45e42019-09-05 10:00:22 +000089 PrefFunctionLogAlignment = 4;
Evandro Menezes3a06c462018-10-31 21:56:49 +000090 break;
Matthias Braun651cff42016-06-02 18:03:53 +000091 case Cyclone:
92 CacheLineSize = 64;
93 PrefetchDistance = 280;
94 MinPrefetchStride = 2048;
95 MaxPrefetchIterationsAhead = 3;
96 break;
Evandro Menezes9f9daa12018-01-30 15:40:16 +000097 case ExynosM3:
98 MaxInterleaveFactor = 4;
Hans Wennborg3740ae32019-09-27 09:54:26 +000099 MaxJumpTableSize = 20;
Guillaume Chateletaff45e42019-09-05 10:00:22 +0000100 PrefFunctionLogAlignment = 5;
101 PrefLoopLogAlignment = 4;
Evandro Menezes9f9daa12018-01-30 15:40:16 +0000102 break;
Chad Rosierecc77272016-11-22 14:25:02 +0000103 case Falkor:
104 MaxInterleaveFactor = 4;
Adam Nemete29686e2017-05-15 21:15:01 +0000105 // FIXME: remove this to enable 64-bit SLP if performance looks good.
106 MinVectorRegisterBitWidth = 128;
Haicheng Wuef790ff2017-06-12 16:34:19 +0000107 CacheLineSize = 128;
108 PrefetchDistance = 820;
109 MinPrefetchStride = 2048;
110 MaxPrefetchIterationsAhead = 8;
Chad Rosierecc77272016-11-22 14:25:02 +0000111 break;
Matthias Braun651cff42016-06-02 18:03:53 +0000112 case Kryo:
113 MaxInterleaveFactor = 4;
114 VectorInsertExtractBaseCost = 2;
Haicheng Wua783bac2016-06-21 22:47:56 +0000115 CacheLineSize = 128;
116 PrefetchDistance = 740;
117 MinPrefetchStride = 1024;
118 MaxPrefetchIterationsAhead = 11;
Adam Nemete29686e2017-05-15 21:15:01 +0000119 // FIXME: remove this to enable 64-bit SLP if performance looks good.
120 MinVectorRegisterBitWidth = 128;
Matthias Braun651cff42016-06-02 18:03:53 +0000121 break;
Pablo Barrio27595452019-07-25 10:59:45 +0000122 case NeoverseE1:
Guillaume Chateletaff45e42019-09-05 10:00:22 +0000123 PrefFunctionLogAlignment = 3;
Pablo Barrioa8426b42019-08-05 17:38:58 +0000124 break;
Pablo Barrio27595452019-07-25 10:59:45 +0000125 case NeoverseN1:
Guillaume Chateletaff45e42019-09-05 10:00:22 +0000126 PrefFunctionLogAlignment = 4;
Pablo Barrio27595452019-07-25 10:59:45 +0000127 break;
Evandro Menezes3a06c462018-10-31 21:56:49 +0000128 case Saphira:
129 MaxInterleaveFactor = 4;
130 // FIXME: remove this to enable 64-bit SLP if performance looks good.
131 MinVectorRegisterBitWidth = 128;
132 break;
Joel Jones28520882017-03-07 19:42:40 +0000133 case ThunderX2T99:
134 CacheLineSize = 64;
Guillaume Chateletaff45e42019-09-05 10:00:22 +0000135 PrefFunctionLogAlignment = 3;
136 PrefLoopLogAlignment = 2;
Pankaj Godef4b25542016-06-30 06:42:31 +0000137 MaxInterleaveFactor = 4;
Joel Jones28520882017-03-07 19:42:40 +0000138 PrefetchDistance = 128;
139 MinPrefetchStride = 1024;
140 MaxPrefetchIterationsAhead = 4;
Adam Nemete29686e2017-05-15 21:15:01 +0000141 // FIXME: remove this to enable 64-bit SLP if performance looks good.
142 MinVectorRegisterBitWidth = 128;
Pankaj Godef4b25542016-06-30 06:42:31 +0000143 break;
Joel Jonesab0f3b42017-02-17 18:34:24 +0000144 case ThunderX:
145 case ThunderXT88:
146 case ThunderXT81:
147 case ThunderXT83:
148 CacheLineSize = 128;
Guillaume Chateletaff45e42019-09-05 10:00:22 +0000149 PrefFunctionLogAlignment = 3;
150 PrefLoopLogAlignment = 2;
Adam Nemete29686e2017-05-15 21:15:01 +0000151 // FIXME: remove this to enable 64-bit SLP if performance looks good.
152 MinVectorRegisterBitWidth = 128;
Joel Jonesab0f3b42017-02-17 18:34:24 +0000153 break;
Bryan Chan12355392018-11-09 19:32:08 +0000154 case TSV110:
155 CacheLineSize = 64;
Guillaume Chateletaff45e42019-09-05 10:00:22 +0000156 PrefFunctionLogAlignment = 4;
157 PrefLoopLogAlignment = 2;
Bryan Chan12355392018-11-09 19:32:08 +0000158 break;
Matthias Braun651cff42016-06-02 18:03:53 +0000159 }
160}
161
Daniel Sandersa73f1fd2015-06-10 12:11:26 +0000162AArch64Subtarget::AArch64Subtarget(const Triple &TT, const std::string &CPU,
Eric Christopherf12e1ab2014-10-03 00:42:41 +0000163 const std::string &FS,
Daniel Sandersa1b2db792017-05-19 11:08:33 +0000164 const TargetMachine &TM, bool LittleEndian)
Mandeep Singh Grangd857b4c2017-07-18 20:41:33 +0000165 : AArch64GenSubtargetInfo(TT, CPU, FS),
Nick Desaulniers287a3be2018-09-07 20:58:57 +0000166 ReserveXRegister(AArch64::GPR64commonRegClass.getNumRegs()),
Tri Vo6c47c622018-09-22 22:17:50 +0000167 CustomCallSavedXRegs(AArch64::GPR64commonRegClass.getNumRegs()),
Nick Desaulniers287a3be2018-09-07 20:58:57 +0000168 IsLittle(LittleEndian),
Peter Collingbournef11eb3e2018-04-04 21:55:44 +0000169 TargetTriple(TT), FrameLowering(),
Matthias Brauna827ed82016-10-03 20:17:02 +0000170 InstrInfo(initializeSubtargetDependencies(FS, CPU)), TSInfo(),
Quentin Colombet61d71a12017-08-15 22:31:51 +0000171 TLInfo(TM, *this) {
Nick Desaulniers287a3be2018-09-07 20:58:57 +0000172 if (AArch64::isX18ReservedByDefault(TT))
173 ReserveXRegister.set(18);
174
Quentin Colombet61d71a12017-08-15 22:31:51 +0000175 CallLoweringInfo.reset(new AArch64CallLowering(*getTargetLowering()));
Daniel Sanders7fe7acc2017-11-28 20:21:15 +0000176 Legalizer.reset(new AArch64LegalizerInfo(*this));
Quentin Colombetcdf8c812017-05-01 21:53:19 +0000177
178 auto *RBI = new AArch64RegisterBankInfo(*getRegisterInfo());
179
180 // FIXME: At this point, we can't rely on Subtarget having RBI.
181 // It's awkward to mix passing RBI and the Subtarget; should we pass
182 // TII/TRI as well?
Quentin Colombet61d71a12017-08-15 22:31:51 +0000183 InstSelector.reset(createAArch64InstructionSelector(
Quentin Colombetcdf8c812017-05-01 21:53:19 +0000184 *static_cast<const AArch64TargetMachine *>(&TM), *this, *RBI));
185
Quentin Colombet61d71a12017-08-15 22:31:51 +0000186 RegBankInfo.reset(RBI);
Quentin Colombetcdf8c812017-05-01 21:53:19 +0000187}
Quentin Colombetba2a0162016-02-16 19:26:02 +0000188
189const CallLowering *AArch64Subtarget::getCallLowering() const {
Quentin Colombet61d71a12017-08-15 22:31:51 +0000190 return CallLoweringInfo.get();
Quentin Colombetc17f7442016-04-06 17:26:03 +0000191}
192
Amara Emersone14c91b2019-08-13 06:26:59 +0000193InstructionSelector *AArch64Subtarget::getInstructionSelector() const {
Quentin Colombet61d71a12017-08-15 22:31:51 +0000194 return InstSelector.get();
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000195}
196
Tim Northover69fa84a2016-10-14 22:18:18 +0000197const LegalizerInfo *AArch64Subtarget::getLegalizerInfo() const {
Quentin Colombet61d71a12017-08-15 22:31:51 +0000198 return Legalizer.get();
Tim Northover33b07d62016-07-22 20:03:43 +0000199}
200
Quentin Colombetc17f7442016-04-06 17:26:03 +0000201const RegisterBankInfo *AArch64Subtarget::getRegBankInfo() const {
Quentin Colombet61d71a12017-08-15 22:31:51 +0000202 return RegBankInfo.get();
Quentin Colombetba2a0162016-02-16 19:26:02 +0000203}
Tim Northover3b0846e2014-05-24 12:50:23 +0000204
Rafael Espindola6b93bf52016-05-25 22:44:06 +0000205/// Find the target operand flags that describe how a global value should be
206/// referenced for the current subtarget.
Peter Collingbourne33773d52019-07-31 20:14:09 +0000207unsigned
Tim Northover3b0846e2014-05-24 12:50:23 +0000208AArch64Subtarget::ClassifyGlobalReference(const GlobalValue *GV,
Rafael Espindola6b93bf52016-05-25 22:44:06 +0000209 const TargetMachine &TM) const {
Tim Northover3b0846e2014-05-24 12:50:23 +0000210 // MachO large model always goes via a GOT, simply to get a single 8-byte
211 // absolute relocation on all global addresses.
212 if (TM.getCodeModel() == CodeModel::Large && isTargetMachO())
213 return AArch64II::MO_GOT;
214
Martin Storsjo68df8122018-09-04 20:56:28 +0000215 if (!TM.shouldAssumeDSOLocal(*GV->getParent(), GV)) {
216 if (GV->hasDLLImportStorageClass())
217 return AArch64II::MO_GOT | AArch64II::MO_DLLIMPORT;
218 if (getTargetTriple().isOSWindows())
219 return AArch64II::MO_GOT | AArch64II::MO_COFFSTUB;
220 return AArch64II::MO_GOT;
221 }
Rafael Espindolaa224de02016-05-26 12:42:55 +0000222
Petr Hosek9eb0a1e2017-04-04 19:51:53 +0000223 // The small code model's direct accesses use ADRP, which cannot
224 // necessarily produce the value 0 (if the code is above 4GB).
David Green9dd1d452018-08-22 11:31:39 +0000225 // Same for the tiny code model, where we have a pc relative LDR.
226 if ((useSmallAddressing() || TM.getCodeModel() == CodeModel::Tiny) &&
227 GV->hasExternalWeakLinkage())
Martin Storsjo68df8122018-09-04 20:56:28 +0000228 return AArch64II::MO_GOT;
Tim Northover3b0846e2014-05-24 12:50:23 +0000229
Peter Collingbourne09f39962019-07-31 20:14:19 +0000230 // References to tagged globals are marked with MO_NC | MO_TAGGED to indicate
231 // that their nominal addresses are tagged and outside of the code model. In
232 // AArch64ExpandPseudo::expandMI we emit an additional instruction to set the
233 // tag if necessary based on MO_TAGGED.
234 if (AllowTaggedGlobals && !isa<FunctionType>(GV->getValueType()))
235 return AArch64II::MO_NC | AArch64II::MO_TAGGED;
236
Martin Storsjo68df8122018-09-04 20:56:28 +0000237 return AArch64II::MO_NO_FLAG;
Tim Northover3b0846e2014-05-24 12:50:23 +0000238}
239
Peter Collingbourne33773d52019-07-31 20:14:09 +0000240unsigned AArch64Subtarget::classifyGlobalFunctionReference(
Tim Northover879a0b22017-04-17 17:27:56 +0000241 const GlobalValue *GV, const TargetMachine &TM) const {
242 // MachO large model always goes via a GOT, because we don't have the
243 // relocations available to do anything else..
244 if (TM.getCodeModel() == CodeModel::Large && isTargetMachO() &&
245 !GV->hasInternalLinkage())
246 return AArch64II::MO_GOT;
247
248 // NonLazyBind goes via GOT unless we know it's available locally.
249 auto *F = dyn_cast<Function>(GV);
Tim Northover46e36f02017-04-17 18:18:47 +0000250 if (UseNonLazyBind && F && F->hasFnAttribute(Attribute::NonLazyBind) &&
Tim Northover879a0b22017-04-17 17:27:56 +0000251 !TM.shouldAssumeDSOLocal(*GV->getParent(), GV))
252 return AArch64II::MO_GOT;
253
254 return AArch64II::MO_NO_FLAG;
255}
256
Tim Northover3b0846e2014-05-24 12:50:23 +0000257void AArch64Subtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
Duncan P. N. Exon Smith63298722016-07-01 00:23:27 +0000258 unsigned NumRegionInstrs) const {
Tim Northover3b0846e2014-05-24 12:50:23 +0000259 // LNT run (at least on Cyclone) showed reasonably significant gains for
260 // bi-directional scheduling. 253.perlbmk.
261 Policy.OnlyTopDown = false;
262 Policy.OnlyBottomUp = false;
Matthias Braund276de62015-10-22 18:07:38 +0000263 // Enabling or Disabling the latency heuristic is a close call: It seems to
264 // help nearly no benchmark on out-of-order architectures, on the other hand
265 // it regresses register pressure on a few benchmarking.
Matthias Braun651cff42016-06-02 18:03:53 +0000266 Policy.DisableLatencyHeuristic = DisableLatencySchedHeuristic;
Tim Northover3b0846e2014-05-24 12:50:23 +0000267}
268
269bool AArch64Subtarget::enableEarlyIfConversion() const {
270 return EnableEarlyIfConvert;
271}
Lang Hames8f31f442014-10-09 18:20:51 +0000272
Tim Northover339c83e2015-11-10 00:44:23 +0000273bool AArch64Subtarget::supportsAddressTopByteIgnored() const {
274 if (!UseAddressTopByteIgnored)
275 return false;
276
277 if (TargetTriple.isiOS()) {
278 unsigned Major, Minor, Micro;
279 TargetTriple.getiOSVersion(Major, Minor, Micro);
280 return Major >= 8;
281 }
282
283 return false;
284}
285
Lang Hames8f31f442014-10-09 18:20:51 +0000286std::unique_ptr<PBQPRAConstraint>
287AArch64Subtarget::getCustomPBQPConstraints() const {
Jonas Devlieghere0eaee542019-08-15 15:54:37 +0000288 return balanceFPOps() ? std::make_unique<A57ChainingConstraint>() : nullptr;
Lang Hames8f31f442014-10-09 18:20:51 +0000289}
Matthias Braun5c290dc2018-01-19 03:16:36 +0000290
291void AArch64Subtarget::mirFileLoaded(MachineFunction &MF) const {
292 // We usually compute max call frame size after ISel. Do the computation now
293 // if the .mir file didn't specify it. Note that this will probably give you
294 // bogus values after PEI has eliminated the callframe setup/destroy pseudo
Calixte Denizet7413a432018-09-19 11:26:20 +0000295 // instructions, specify explicitly if you need it to be correct.
Matthias Braun5c290dc2018-01-19 03:16:36 +0000296 MachineFrameInfo &MFI = MF.getFrameInfo();
297 if (!MFI.isMaxCallFrameSizeComputed())
298 MFI.computeMaxCallFrameSize(MF);
299}