blob: e22ce44ecb991dffa67c8e85ff13256d644a0487 [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:
74 PrefFunctionAlignment = 3;
75 break;
76 case CortexA55:
77 break;
78 case CortexA57:
79 MaxInterleaveFactor = 4;
80 PrefFunctionAlignment = 4;
81 break;
82 case CortexA72:
83 case CortexA73:
84 case CortexA75:
85 PrefFunctionAlignment = 4;
86 break;
Matthias Braun651cff42016-06-02 18:03:53 +000087 case Cyclone:
88 CacheLineSize = 64;
89 PrefetchDistance = 280;
90 MinPrefetchStride = 2048;
91 MaxPrefetchIterationsAhead = 3;
92 break;
Evandro Menezesa3a0a602016-06-10 16:00:18 +000093 case ExynosM1:
Abderrazek Zaafrani9daf8112016-10-21 16:28:27 +000094 MaxInterleaveFactor = 4;
Evandro Menezes7696dc02016-10-25 20:05:42 +000095 MaxJumpTableSize = 8;
Evandro Menezesa3a0a602016-06-10 16:00:18 +000096 PrefFunctionAlignment = 4;
97 PrefLoopAlignment = 3;
98 break;
Evandro Menezes9f9daa12018-01-30 15:40:16 +000099 case ExynosM3:
100 MaxInterleaveFactor = 4;
101 MaxJumpTableSize = 20;
102 PrefFunctionAlignment = 5;
103 PrefLoopAlignment = 4;
104 break;
Chad Rosierecc77272016-11-22 14:25:02 +0000105 case Falkor:
106 MaxInterleaveFactor = 4;
Adam Nemete29686e2017-05-15 21:15:01 +0000107 // FIXME: remove this to enable 64-bit SLP if performance looks good.
108 MinVectorRegisterBitWidth = 128;
Haicheng Wuef790ff2017-06-12 16:34:19 +0000109 CacheLineSize = 128;
110 PrefetchDistance = 820;
111 MinPrefetchStride = 2048;
112 MaxPrefetchIterationsAhead = 8;
Chad Rosierecc77272016-11-22 14:25:02 +0000113 break;
Matthias Braun651cff42016-06-02 18:03:53 +0000114 case Kryo:
115 MaxInterleaveFactor = 4;
116 VectorInsertExtractBaseCost = 2;
Haicheng Wua783bac2016-06-21 22:47:56 +0000117 CacheLineSize = 128;
118 PrefetchDistance = 740;
119 MinPrefetchStride = 1024;
120 MaxPrefetchIterationsAhead = 11;
Adam Nemete29686e2017-05-15 21:15:01 +0000121 // FIXME: remove this to enable 64-bit SLP if performance looks good.
122 MinVectorRegisterBitWidth = 128;
Matthias Braun651cff42016-06-02 18:03:53 +0000123 break;
Evandro Menezes3a06c462018-10-31 21:56:49 +0000124 case Saphira:
125 MaxInterleaveFactor = 4;
126 // FIXME: remove this to enable 64-bit SLP if performance looks good.
127 MinVectorRegisterBitWidth = 128;
128 break;
Joel Jones28520882017-03-07 19:42:40 +0000129 case ThunderX2T99:
130 CacheLineSize = 64;
131 PrefFunctionAlignment = 3;
132 PrefLoopAlignment = 2;
Pankaj Godef4b25542016-06-30 06:42:31 +0000133 MaxInterleaveFactor = 4;
Joel Jones28520882017-03-07 19:42:40 +0000134 PrefetchDistance = 128;
135 MinPrefetchStride = 1024;
136 MaxPrefetchIterationsAhead = 4;
Adam Nemete29686e2017-05-15 21:15:01 +0000137 // FIXME: remove this to enable 64-bit SLP if performance looks good.
138 MinVectorRegisterBitWidth = 128;
Pankaj Godef4b25542016-06-30 06:42:31 +0000139 break;
Joel Jonesab0f3b42017-02-17 18:34:24 +0000140 case ThunderX:
141 case ThunderXT88:
142 case ThunderXT81:
143 case ThunderXT83:
144 CacheLineSize = 128;
Joel Jones28520882017-03-07 19:42:40 +0000145 PrefFunctionAlignment = 3;
146 PrefLoopAlignment = 2;
Adam Nemete29686e2017-05-15 21:15:01 +0000147 // FIXME: remove this to enable 64-bit SLP if performance looks good.
148 MinVectorRegisterBitWidth = 128;
Joel Jonesab0f3b42017-02-17 18:34:24 +0000149 break;
Bryan Chan12355392018-11-09 19:32:08 +0000150 case TSV110:
151 CacheLineSize = 64;
152 PrefFunctionAlignment = 4;
153 PrefLoopAlignment = 2;
154 break;
Matthias Braun651cff42016-06-02 18:03:53 +0000155 }
156}
157
Daniel Sandersa73f1fd2015-06-10 12:11:26 +0000158AArch64Subtarget::AArch64Subtarget(const Triple &TT, const std::string &CPU,
Eric Christopherf12e1ab2014-10-03 00:42:41 +0000159 const std::string &FS,
Daniel Sandersa1b2db792017-05-19 11:08:33 +0000160 const TargetMachine &TM, bool LittleEndian)
Mandeep Singh Grangd857b4c2017-07-18 20:41:33 +0000161 : AArch64GenSubtargetInfo(TT, CPU, FS),
Nick Desaulniers287a3be2018-09-07 20:58:57 +0000162 ReserveXRegister(AArch64::GPR64commonRegClass.getNumRegs()),
Tri Vo6c47c622018-09-22 22:17:50 +0000163 CustomCallSavedXRegs(AArch64::GPR64commonRegClass.getNumRegs()),
Nick Desaulniers287a3be2018-09-07 20:58:57 +0000164 IsLittle(LittleEndian),
Peter Collingbournef11eb3e2018-04-04 21:55:44 +0000165 TargetTriple(TT), FrameLowering(),
Matthias Brauna827ed82016-10-03 20:17:02 +0000166 InstrInfo(initializeSubtargetDependencies(FS, CPU)), TSInfo(),
Quentin Colombet61d71a12017-08-15 22:31:51 +0000167 TLInfo(TM, *this) {
Nick Desaulniers287a3be2018-09-07 20:58:57 +0000168 if (AArch64::isX18ReservedByDefault(TT))
169 ReserveXRegister.set(18);
170
Quentin Colombet61d71a12017-08-15 22:31:51 +0000171 CallLoweringInfo.reset(new AArch64CallLowering(*getTargetLowering()));
Daniel Sanders7fe7acc2017-11-28 20:21:15 +0000172 Legalizer.reset(new AArch64LegalizerInfo(*this));
Quentin Colombetcdf8c812017-05-01 21:53:19 +0000173
174 auto *RBI = new AArch64RegisterBankInfo(*getRegisterInfo());
175
176 // FIXME: At this point, we can't rely on Subtarget having RBI.
177 // It's awkward to mix passing RBI and the Subtarget; should we pass
178 // TII/TRI as well?
Quentin Colombet61d71a12017-08-15 22:31:51 +0000179 InstSelector.reset(createAArch64InstructionSelector(
Quentin Colombetcdf8c812017-05-01 21:53:19 +0000180 *static_cast<const AArch64TargetMachine *>(&TM), *this, *RBI));
181
Quentin Colombet61d71a12017-08-15 22:31:51 +0000182 RegBankInfo.reset(RBI);
Quentin Colombetcdf8c812017-05-01 21:53:19 +0000183}
Quentin Colombetba2a0162016-02-16 19:26:02 +0000184
185const CallLowering *AArch64Subtarget::getCallLowering() const {
Quentin Colombet61d71a12017-08-15 22:31:51 +0000186 return CallLoweringInfo.get();
Quentin Colombetc17f7442016-04-06 17:26:03 +0000187}
188
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000189const InstructionSelector *AArch64Subtarget::getInstructionSelector() const {
Quentin Colombet61d71a12017-08-15 22:31:51 +0000190 return InstSelector.get();
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000191}
192
Tim Northover69fa84a2016-10-14 22:18:18 +0000193const LegalizerInfo *AArch64Subtarget::getLegalizerInfo() const {
Quentin Colombet61d71a12017-08-15 22:31:51 +0000194 return Legalizer.get();
Tim Northover33b07d62016-07-22 20:03:43 +0000195}
196
Quentin Colombetc17f7442016-04-06 17:26:03 +0000197const RegisterBankInfo *AArch64Subtarget::getRegBankInfo() const {
Quentin Colombet61d71a12017-08-15 22:31:51 +0000198 return RegBankInfo.get();
Quentin Colombetba2a0162016-02-16 19:26:02 +0000199}
Tim Northover3b0846e2014-05-24 12:50:23 +0000200
Rafael Espindola6b93bf52016-05-25 22:44:06 +0000201/// Find the target operand flags that describe how a global value should be
202/// referenced for the current subtarget.
Tim Northover3b0846e2014-05-24 12:50:23 +0000203unsigned char
204AArch64Subtarget::ClassifyGlobalReference(const GlobalValue *GV,
Rafael Espindola6b93bf52016-05-25 22:44:06 +0000205 const TargetMachine &TM) const {
Tim Northover3b0846e2014-05-24 12:50:23 +0000206 // MachO large model always goes via a GOT, simply to get a single 8-byte
207 // absolute relocation on all global addresses.
208 if (TM.getCodeModel() == CodeModel::Large && isTargetMachO())
209 return AArch64II::MO_GOT;
210
Martin Storsjo68df8122018-09-04 20:56:28 +0000211 if (!TM.shouldAssumeDSOLocal(*GV->getParent(), GV)) {
212 if (GV->hasDLLImportStorageClass())
213 return AArch64II::MO_GOT | AArch64II::MO_DLLIMPORT;
214 if (getTargetTriple().isOSWindows())
215 return AArch64II::MO_GOT | AArch64II::MO_COFFSTUB;
216 return AArch64II::MO_GOT;
217 }
Rafael Espindolaa224de02016-05-26 12:42:55 +0000218
Petr Hosek9eb0a1e2017-04-04 19:51:53 +0000219 // The small code model's direct accesses use ADRP, which cannot
220 // necessarily produce the value 0 (if the code is above 4GB).
David Green9dd1d452018-08-22 11:31:39 +0000221 // Same for the tiny code model, where we have a pc relative LDR.
222 if ((useSmallAddressing() || TM.getCodeModel() == CodeModel::Tiny) &&
223 GV->hasExternalWeakLinkage())
Martin Storsjo68df8122018-09-04 20:56:28 +0000224 return AArch64II::MO_GOT;
Tim Northover3b0846e2014-05-24 12:50:23 +0000225
Martin Storsjo68df8122018-09-04 20:56:28 +0000226 return AArch64II::MO_NO_FLAG;
Tim Northover3b0846e2014-05-24 12:50:23 +0000227}
228
Tim Northover879a0b22017-04-17 17:27:56 +0000229unsigned char AArch64Subtarget::classifyGlobalFunctionReference(
230 const GlobalValue *GV, const TargetMachine &TM) const {
231 // MachO large model always goes via a GOT, because we don't have the
232 // relocations available to do anything else..
233 if (TM.getCodeModel() == CodeModel::Large && isTargetMachO() &&
234 !GV->hasInternalLinkage())
235 return AArch64II::MO_GOT;
236
237 // NonLazyBind goes via GOT unless we know it's available locally.
238 auto *F = dyn_cast<Function>(GV);
Tim Northover46e36f02017-04-17 18:18:47 +0000239 if (UseNonLazyBind && F && F->hasFnAttribute(Attribute::NonLazyBind) &&
Tim Northover879a0b22017-04-17 17:27:56 +0000240 !TM.shouldAssumeDSOLocal(*GV->getParent(), GV))
241 return AArch64II::MO_GOT;
242
243 return AArch64II::MO_NO_FLAG;
244}
245
Tim Northover3b0846e2014-05-24 12:50:23 +0000246void AArch64Subtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
Duncan P. N. Exon Smith63298722016-07-01 00:23:27 +0000247 unsigned NumRegionInstrs) const {
Tim Northover3b0846e2014-05-24 12:50:23 +0000248 // LNT run (at least on Cyclone) showed reasonably significant gains for
249 // bi-directional scheduling. 253.perlbmk.
250 Policy.OnlyTopDown = false;
251 Policy.OnlyBottomUp = false;
Matthias Braund276de62015-10-22 18:07:38 +0000252 // Enabling or Disabling the latency heuristic is a close call: It seems to
253 // help nearly no benchmark on out-of-order architectures, on the other hand
254 // it regresses register pressure on a few benchmarking.
Matthias Braun651cff42016-06-02 18:03:53 +0000255 Policy.DisableLatencyHeuristic = DisableLatencySchedHeuristic;
Tim Northover3b0846e2014-05-24 12:50:23 +0000256}
257
258bool AArch64Subtarget::enableEarlyIfConversion() const {
259 return EnableEarlyIfConvert;
260}
Lang Hames8f31f442014-10-09 18:20:51 +0000261
Tim Northover339c83e2015-11-10 00:44:23 +0000262bool AArch64Subtarget::supportsAddressTopByteIgnored() const {
263 if (!UseAddressTopByteIgnored)
264 return false;
265
266 if (TargetTriple.isiOS()) {
267 unsigned Major, Minor, Micro;
268 TargetTriple.getiOSVersion(Major, Minor, Micro);
269 return Major >= 8;
270 }
271
272 return false;
273}
274
Lang Hames8f31f442014-10-09 18:20:51 +0000275std::unique_ptr<PBQPRAConstraint>
276AArch64Subtarget::getCustomPBQPConstraints() const {
Matthias Braun651cff42016-06-02 18:03:53 +0000277 return balanceFPOps() ? llvm::make_unique<A57ChainingConstraint>() : nullptr;
Lang Hames8f31f442014-10-09 18:20:51 +0000278}
Matthias Braun5c290dc2018-01-19 03:16:36 +0000279
280void AArch64Subtarget::mirFileLoaded(MachineFunction &MF) const {
281 // We usually compute max call frame size after ISel. Do the computation now
282 // if the .mir file didn't specify it. Note that this will probably give you
283 // bogus values after PEI has eliminated the callframe setup/destroy pseudo
Calixte Denizet7413a432018-09-19 11:26:20 +0000284 // instructions, specify explicitly if you need it to be correct.
Matthias Braun5c290dc2018-01-19 03:16:36 +0000285 MachineFrameInfo &MFI = MF.getFrameInfo();
286 if (!MFI.isMaxCallFrameSizeComputed())
287 MFI.computeMaxCallFrameSize(MF);
288}