blob: f7a8b82c965d24352489fc5ca52f1366d5de8a5f [file] [log] [blame]
Tim Northover3b0846e2014-05-24 12:50:23 +00001//===-- 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 Espindola6b4baa52016-05-25 21:37:29 +000014#include "AArch64Subtarget.h"
Quentin Colombetcdf8c812017-05-01 21:53:19 +000015
16#include "AArch64.h"
Tim Northover3b0846e2014-05-24 12:50:23 +000017#include "AArch64InstrInfo.h"
Lang Hames8f31f442014-10-09 18:20:51 +000018#include "AArch64PBQPRegAlloc.h"
Quentin Colombetcdf8c812017-05-01 21:53:19 +000019#include "AArch64TargetMachine.h"
20
Quentin Colombetcdf8c812017-05-01 21:53:19 +000021#include "AArch64CallLowering.h"
22#include "AArch64LegalizerInfo.h"
23#include "AArch64RegisterBankInfo.h"
Quentin Colombetcdf8c812017-05-01 21:53:19 +000024#include "llvm/CodeGen/GlobalISel/InstructionSelect.h"
Tim Northover3b0846e2014-05-24 12:50:23 +000025#include "llvm/CodeGen/MachineScheduler.h"
26#include "llvm/IR/GlobalValue.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) {
69 case Cyclone:
70 CacheLineSize = 64;
71 PrefetchDistance = 280;
72 MinPrefetchStride = 2048;
73 MaxPrefetchIterationsAhead = 3;
74 break;
75 case CortexA57:
76 MaxInterleaveFactor = 4;
Florian Hahnd4550ba2017-07-07 10:43:01 +000077 PrefFunctionAlignment = 4;
Matthias Braun651cff42016-06-02 18:03:53 +000078 break;
Evandro Menezesa3a0a602016-06-10 16:00:18 +000079 case ExynosM1:
Abderrazek Zaafrani9daf8112016-10-21 16:28:27 +000080 MaxInterleaveFactor = 4;
Evandro Menezes7696dc02016-10-25 20:05:42 +000081 MaxJumpTableSize = 8;
Evandro Menezesa3a0a602016-06-10 16:00:18 +000082 PrefFunctionAlignment = 4;
83 PrefLoopAlignment = 3;
84 break;
Evandro Menezes9f9daa12018-01-30 15:40:16 +000085 case ExynosM3:
86 MaxInterleaveFactor = 4;
87 MaxJumpTableSize = 20;
88 PrefFunctionAlignment = 5;
89 PrefLoopAlignment = 4;
90 break;
Chad Rosierecc77272016-11-22 14:25:02 +000091 case Falkor:
92 MaxInterleaveFactor = 4;
Adam Nemete29686e2017-05-15 21:15:01 +000093 // FIXME: remove this to enable 64-bit SLP if performance looks good.
94 MinVectorRegisterBitWidth = 128;
Haicheng Wuef790ff2017-06-12 16:34:19 +000095 CacheLineSize = 128;
96 PrefetchDistance = 820;
97 MinPrefetchStride = 2048;
98 MaxPrefetchIterationsAhead = 8;
Chad Rosierecc77272016-11-22 14:25:02 +000099 break;
Chad Rosier71070852017-09-25 14:05:00 +0000100 case Saphira:
101 MaxInterleaveFactor = 4;
102 // FIXME: remove this to enable 64-bit SLP if performance looks good.
103 MinVectorRegisterBitWidth = 128;
104 break;
Matthias Braun651cff42016-06-02 18:03:53 +0000105 case Kryo:
106 MaxInterleaveFactor = 4;
107 VectorInsertExtractBaseCost = 2;
Haicheng Wua783bac2016-06-21 22:47:56 +0000108 CacheLineSize = 128;
109 PrefetchDistance = 740;
110 MinPrefetchStride = 1024;
111 MaxPrefetchIterationsAhead = 11;
Adam Nemete29686e2017-05-15 21:15:01 +0000112 // FIXME: remove this to enable 64-bit SLP if performance looks good.
113 MinVectorRegisterBitWidth = 128;
Matthias Braun651cff42016-06-02 18:03:53 +0000114 break;
Joel Jones28520882017-03-07 19:42:40 +0000115 case ThunderX2T99:
116 CacheLineSize = 64;
117 PrefFunctionAlignment = 3;
118 PrefLoopAlignment = 2;
Pankaj Godef4b25542016-06-30 06:42:31 +0000119 MaxInterleaveFactor = 4;
Joel Jones28520882017-03-07 19:42:40 +0000120 PrefetchDistance = 128;
121 MinPrefetchStride = 1024;
122 MaxPrefetchIterationsAhead = 4;
Adam Nemete29686e2017-05-15 21:15:01 +0000123 // FIXME: remove this to enable 64-bit SLP if performance looks good.
124 MinVectorRegisterBitWidth = 128;
Pankaj Godef4b25542016-06-30 06:42:31 +0000125 break;
Joel Jonesab0f3b42017-02-17 18:34:24 +0000126 case ThunderX:
127 case ThunderXT88:
128 case ThunderXT81:
129 case ThunderXT83:
130 CacheLineSize = 128;
Joel Jones28520882017-03-07 19:42:40 +0000131 PrefFunctionAlignment = 3;
132 PrefLoopAlignment = 2;
Adam Nemete29686e2017-05-15 21:15:01 +0000133 // FIXME: remove this to enable 64-bit SLP if performance looks good.
134 MinVectorRegisterBitWidth = 128;
Joel Jonesab0f3b42017-02-17 18:34:24 +0000135 break;
Matthias Braun651cff42016-06-02 18:03:53 +0000136 case CortexA35: break;
Florian Hahn2f86e3d2017-07-29 20:04:54 +0000137 case CortexA53:
138 PrefFunctionAlignment = 3;
139 break;
Sam Parkerb252ffd2017-08-21 08:43:06 +0000140 case CortexA55: break;
Florian Hahne3666ec2017-07-07 10:15:49 +0000141 case CortexA72:
Florian Hahn35300942017-07-18 09:31:18 +0000142 case CortexA73:
Sam Parkerb252ffd2017-08-21 08:43:06 +0000143 case CortexA75:
Florian Hahn35300942017-07-18 09:31:18 +0000144 PrefFunctionAlignment = 4;
145 break;
Evandro Menezesa3a0a602016-06-10 16:00:18 +0000146 case Others: break;
Matthias Braun651cff42016-06-02 18:03:53 +0000147 }
148}
149
Daniel Sandersa73f1fd2015-06-10 12:11:26 +0000150AArch64Subtarget::AArch64Subtarget(const Triple &TT, const std::string &CPU,
Eric Christopherf12e1ab2014-10-03 00:42:41 +0000151 const std::string &FS,
Daniel Sandersa1b2db792017-05-19 11:08:33 +0000152 const TargetMachine &TM, bool LittleEndian)
Mandeep Singh Grangd857b4c2017-07-18 20:41:33 +0000153 : AArch64GenSubtargetInfo(TT, CPU, FS),
Quentin Colombet61d71a12017-08-15 22:31:51 +0000154 ReserveX18(TT.isOSDarwin() || TT.isOSWindows()), IsLittle(LittleEndian),
155 TargetTriple(TT), FrameLowering(),
Matthias Brauna827ed82016-10-03 20:17:02 +0000156 InstrInfo(initializeSubtargetDependencies(FS, CPU)), TSInfo(),
Quentin Colombet61d71a12017-08-15 22:31:51 +0000157 TLInfo(TM, *this) {
158 CallLoweringInfo.reset(new AArch64CallLowering(*getTargetLowering()));
Daniel Sanders7fe7acc2017-11-28 20:21:15 +0000159 Legalizer.reset(new AArch64LegalizerInfo(*this));
Quentin Colombetcdf8c812017-05-01 21:53:19 +0000160
161 auto *RBI = new AArch64RegisterBankInfo(*getRegisterInfo());
162
163 // FIXME: At this point, we can't rely on Subtarget having RBI.
164 // It's awkward to mix passing RBI and the Subtarget; should we pass
165 // TII/TRI as well?
Quentin Colombet61d71a12017-08-15 22:31:51 +0000166 InstSelector.reset(createAArch64InstructionSelector(
Quentin Colombetcdf8c812017-05-01 21:53:19 +0000167 *static_cast<const AArch64TargetMachine *>(&TM), *this, *RBI));
168
Quentin Colombet61d71a12017-08-15 22:31:51 +0000169 RegBankInfo.reset(RBI);
Quentin Colombetcdf8c812017-05-01 21:53:19 +0000170}
Quentin Colombetba2a0162016-02-16 19:26:02 +0000171
172const CallLowering *AArch64Subtarget::getCallLowering() const {
Quentin Colombet61d71a12017-08-15 22:31:51 +0000173 return CallLoweringInfo.get();
Quentin Colombetc17f7442016-04-06 17:26:03 +0000174}
175
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000176const InstructionSelector *AArch64Subtarget::getInstructionSelector() const {
Quentin Colombet61d71a12017-08-15 22:31:51 +0000177 return InstSelector.get();
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000178}
179
Tim Northover69fa84a2016-10-14 22:18:18 +0000180const LegalizerInfo *AArch64Subtarget::getLegalizerInfo() const {
Quentin Colombet61d71a12017-08-15 22:31:51 +0000181 return Legalizer.get();
Tim Northover33b07d62016-07-22 20:03:43 +0000182}
183
Quentin Colombetc17f7442016-04-06 17:26:03 +0000184const RegisterBankInfo *AArch64Subtarget::getRegBankInfo() const {
Quentin Colombet61d71a12017-08-15 22:31:51 +0000185 return RegBankInfo.get();
Quentin Colombetba2a0162016-02-16 19:26:02 +0000186}
Tim Northover3b0846e2014-05-24 12:50:23 +0000187
Rafael Espindola6b93bf52016-05-25 22:44:06 +0000188/// Find the target operand flags that describe how a global value should be
189/// referenced for the current subtarget.
Tim Northover3b0846e2014-05-24 12:50:23 +0000190unsigned char
191AArch64Subtarget::ClassifyGlobalReference(const GlobalValue *GV,
Rafael Espindola6b93bf52016-05-25 22:44:06 +0000192 const TargetMachine &TM) const {
Tim Northover3b0846e2014-05-24 12:50:23 +0000193 // MachO large model always goes via a GOT, simply to get a single 8-byte
194 // absolute relocation on all global addresses.
195 if (TM.getCodeModel() == CodeModel::Large && isTargetMachO())
196 return AArch64II::MO_GOT;
197
Rafael Espindola3beef8d2016-06-27 23:15:57 +0000198 if (!TM.shouldAssumeDSOLocal(*GV->getParent(), GV))
Rafael Espindolaa224de02016-05-26 12:42:55 +0000199 return AArch64II::MO_GOT;
200
Petr Hosek9eb0a1e2017-04-04 19:51:53 +0000201 // The small code model's direct accesses use ADRP, which cannot
202 // necessarily produce the value 0 (if the code is above 4GB).
203 if (useSmallAddressing() && GV->hasExternalWeakLinkage())
Rafael Espindola4d290992016-05-31 18:31:14 +0000204 return AArch64II::MO_GOT;
Tim Northover3b0846e2014-05-24 12:50:23 +0000205
Tim Northover3b0846e2014-05-24 12:50:23 +0000206 return AArch64II::MO_NO_FLAG;
207}
208
Tim Northover879a0b22017-04-17 17:27:56 +0000209unsigned char AArch64Subtarget::classifyGlobalFunctionReference(
210 const GlobalValue *GV, const TargetMachine &TM) const {
211 // MachO large model always goes via a GOT, because we don't have the
212 // relocations available to do anything else..
213 if (TM.getCodeModel() == CodeModel::Large && isTargetMachO() &&
214 !GV->hasInternalLinkage())
215 return AArch64II::MO_GOT;
216
217 // NonLazyBind goes via GOT unless we know it's available locally.
218 auto *F = dyn_cast<Function>(GV);
Tim Northover46e36f02017-04-17 18:18:47 +0000219 if (UseNonLazyBind && F && F->hasFnAttribute(Attribute::NonLazyBind) &&
Tim Northover879a0b22017-04-17 17:27:56 +0000220 !TM.shouldAssumeDSOLocal(*GV->getParent(), GV))
221 return AArch64II::MO_GOT;
222
223 return AArch64II::MO_NO_FLAG;
224}
225
Tim Northover3b0846e2014-05-24 12:50:23 +0000226void AArch64Subtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
Duncan P. N. Exon Smith63298722016-07-01 00:23:27 +0000227 unsigned NumRegionInstrs) const {
Tim Northover3b0846e2014-05-24 12:50:23 +0000228 // LNT run (at least on Cyclone) showed reasonably significant gains for
229 // bi-directional scheduling. 253.perlbmk.
230 Policy.OnlyTopDown = false;
231 Policy.OnlyBottomUp = false;
Matthias Braund276de62015-10-22 18:07:38 +0000232 // Enabling or Disabling the latency heuristic is a close call: It seems to
233 // help nearly no benchmark on out-of-order architectures, on the other hand
234 // it regresses register pressure on a few benchmarking.
Matthias Braun651cff42016-06-02 18:03:53 +0000235 Policy.DisableLatencyHeuristic = DisableLatencySchedHeuristic;
Tim Northover3b0846e2014-05-24 12:50:23 +0000236}
237
238bool AArch64Subtarget::enableEarlyIfConversion() const {
239 return EnableEarlyIfConvert;
240}
Lang Hames8f31f442014-10-09 18:20:51 +0000241
Tim Northover339c83e2015-11-10 00:44:23 +0000242bool AArch64Subtarget::supportsAddressTopByteIgnored() const {
243 if (!UseAddressTopByteIgnored)
244 return false;
245
246 if (TargetTriple.isiOS()) {
247 unsigned Major, Minor, Micro;
248 TargetTriple.getiOSVersion(Major, Minor, Micro);
249 return Major >= 8;
250 }
251
252 return false;
253}
254
Lang Hames8f31f442014-10-09 18:20:51 +0000255std::unique_ptr<PBQPRAConstraint>
256AArch64Subtarget::getCustomPBQPConstraints() const {
Matthias Braun651cff42016-06-02 18:03:53 +0000257 return balanceFPOps() ? llvm::make_unique<A57ChainingConstraint>() : nullptr;
Lang Hames8f31f442014-10-09 18:20:51 +0000258}
Matthias Braun5c290dc2018-01-19 03:16:36 +0000259
260void AArch64Subtarget::mirFileLoaded(MachineFunction &MF) const {
261 // We usually compute max call frame size after ISel. Do the computation now
262 // if the .mir file didn't specify it. Note that this will probably give you
263 // bogus values after PEI has eliminated the callframe setup/destroy pseudo
264 // instructions, specify explicitely if you need it to be correct.
265 MachineFrameInfo &MFI = MF.getFrameInfo();
266 if (!MFI.isMaxCallFrameSizeComputed())
267 MFI.computeMaxCallFrameSize(MF);
268}