blob: 5d0482918e0a2cea28df07cd6205d14448786ab4 [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/IRTranslator.h"
25#include "llvm/CodeGen/GlobalISel/InstructionSelect.h"
26#include "llvm/CodeGen/GlobalISel/Legalizer.h"
27#include "llvm/CodeGen/GlobalISel/RegBankSelect.h"
Tim Northover3b0846e2014-05-24 12:50:23 +000028#include "llvm/CodeGen/MachineScheduler.h"
29#include "llvm/IR/GlobalValue.h"
30#include "llvm/Support/TargetRegistry.h"
31
32using namespace llvm;
33
34#define DEBUG_TYPE "aarch64-subtarget"
35
36#define GET_SUBTARGETINFO_CTOR
37#define GET_SUBTARGETINFO_TARGET_DESC
38#include "AArch64GenSubtargetInfo.inc"
39
40static cl::opt<bool>
41EnableEarlyIfConvert("aarch64-early-ifcvt", cl::desc("Enable the early if "
42 "converter pass"), cl::init(true), cl::Hidden);
43
Tim Northover339c83e2015-11-10 00:44:23 +000044// If OS supports TBI, use this flag to enable it.
45static cl::opt<bool>
46UseAddressTopByteIgnored("aarch64-use-tbi", cl::desc("Assume that top byte of "
47 "an address is ignored"), cl::init(false), cl::Hidden);
48
Tim Northover46e36f02017-04-17 18:18:47 +000049static cl::opt<bool>
50 UseNonLazyBind("aarch64-enable-nonlazybind",
51 cl::desc("Call nonlazybind functions via direct GOT load"),
52 cl::init(false), cl::Hidden);
53
Eric Christopher7c9d4e02014-06-11 00:46:34 +000054AArch64Subtarget &
Matthias Brauna827ed82016-10-03 20:17:02 +000055AArch64Subtarget::initializeSubtargetDependencies(StringRef FS,
56 StringRef CPUString) {
Eric Christopher7c9d4e02014-06-11 00:46:34 +000057 // Determine default and user-specified characteristics
58
59 if (CPUString.empty())
60 CPUString = "generic";
61
62 ParseSubtargetFeatures(CPUString, FS);
Matthias Braun651cff42016-06-02 18:03:53 +000063 initializeProperties();
64
Eric Christopher7c9d4e02014-06-11 00:46:34 +000065 return *this;
66}
67
Matthias Braun651cff42016-06-02 18:03:53 +000068void AArch64Subtarget::initializeProperties() {
69 // Initialize CPU specific properties. We should add a tablegen feature for
70 // this in the future so we can specify it together with the subtarget
71 // features.
72 switch (ARMProcFamily) {
73 case Cyclone:
74 CacheLineSize = 64;
75 PrefetchDistance = 280;
76 MinPrefetchStride = 2048;
77 MaxPrefetchIterationsAhead = 3;
78 break;
79 case CortexA57:
80 MaxInterleaveFactor = 4;
Florian Hahnd4550ba2017-07-07 10:43:01 +000081 PrefFunctionAlignment = 4;
Matthias Braun651cff42016-06-02 18:03:53 +000082 break;
Evandro Menezesa3a0a602016-06-10 16:00:18 +000083 case ExynosM1:
Abderrazek Zaafrani9daf8112016-10-21 16:28:27 +000084 MaxInterleaveFactor = 4;
Evandro Menezes7696dc02016-10-25 20:05:42 +000085 MaxJumpTableSize = 8;
Evandro Menezesa3a0a602016-06-10 16:00:18 +000086 PrefFunctionAlignment = 4;
87 PrefLoopAlignment = 3;
88 break;
Chad Rosierecc77272016-11-22 14:25:02 +000089 case Falkor:
90 MaxInterleaveFactor = 4;
Adam Nemete29686e2017-05-15 21:15:01 +000091 // FIXME: remove this to enable 64-bit SLP if performance looks good.
92 MinVectorRegisterBitWidth = 128;
Haicheng Wuef790ff2017-06-12 16:34:19 +000093 CacheLineSize = 128;
94 PrefetchDistance = 820;
95 MinPrefetchStride = 2048;
96 MaxPrefetchIterationsAhead = 8;
Chad Rosierecc77272016-11-22 14:25:02 +000097 break;
Matthias Braun651cff42016-06-02 18:03:53 +000098 case Kryo:
99 MaxInterleaveFactor = 4;
100 VectorInsertExtractBaseCost = 2;
Haicheng Wua783bac2016-06-21 22:47:56 +0000101 CacheLineSize = 128;
102 PrefetchDistance = 740;
103 MinPrefetchStride = 1024;
104 MaxPrefetchIterationsAhead = 11;
Adam Nemete29686e2017-05-15 21:15:01 +0000105 // FIXME: remove this to enable 64-bit SLP if performance looks good.
106 MinVectorRegisterBitWidth = 128;
Matthias Braun651cff42016-06-02 18:03:53 +0000107 break;
Joel Jones28520882017-03-07 19:42:40 +0000108 case ThunderX2T99:
109 CacheLineSize = 64;
110 PrefFunctionAlignment = 3;
111 PrefLoopAlignment = 2;
Pankaj Godef4b25542016-06-30 06:42:31 +0000112 MaxInterleaveFactor = 4;
Joel Jones28520882017-03-07 19:42:40 +0000113 PrefetchDistance = 128;
114 MinPrefetchStride = 1024;
115 MaxPrefetchIterationsAhead = 4;
Adam Nemete29686e2017-05-15 21:15:01 +0000116 // FIXME: remove this to enable 64-bit SLP if performance looks good.
117 MinVectorRegisterBitWidth = 128;
Pankaj Godef4b25542016-06-30 06:42:31 +0000118 break;
Joel Jonesab0f3b42017-02-17 18:34:24 +0000119 case ThunderX:
120 case ThunderXT88:
121 case ThunderXT81:
122 case ThunderXT83:
123 CacheLineSize = 128;
Joel Jones28520882017-03-07 19:42:40 +0000124 PrefFunctionAlignment = 3;
125 PrefLoopAlignment = 2;
Adam Nemete29686e2017-05-15 21:15:01 +0000126 // FIXME: remove this to enable 64-bit SLP if performance looks good.
127 MinVectorRegisterBitWidth = 128;
Joel Jonesab0f3b42017-02-17 18:34:24 +0000128 break;
Matthias Braun651cff42016-06-02 18:03:53 +0000129 case CortexA35: break;
Florian Hahn2f86e3d2017-07-29 20:04:54 +0000130 case CortexA53:
131 PrefFunctionAlignment = 3;
132 break;
Florian Hahne3666ec2017-07-07 10:15:49 +0000133 case CortexA72:
134 PrefFunctionAlignment = 4;
135 break;
Florian Hahn35300942017-07-18 09:31:18 +0000136 case CortexA73:
137 PrefFunctionAlignment = 4;
138 break;
Evandro Menezesa3a0a602016-06-10 16:00:18 +0000139 case Others: break;
Matthias Braun651cff42016-06-02 18:03:53 +0000140 }
141}
142
Daniel Sandersa73f1fd2015-06-10 12:11:26 +0000143AArch64Subtarget::AArch64Subtarget(const Triple &TT, const std::string &CPU,
Eric Christopherf12e1ab2014-10-03 00:42:41 +0000144 const std::string &FS,
Daniel Sandersa1b2db792017-05-19 11:08:33 +0000145 const TargetMachine &TM, bool LittleEndian)
Mandeep Singh Grangd857b4c2017-07-18 20:41:33 +0000146 : AArch64GenSubtargetInfo(TT, CPU, FS),
Quentin Colombet61d71a12017-08-15 22:31:51 +0000147 ReserveX18(TT.isOSDarwin() || TT.isOSWindows()), IsLittle(LittleEndian),
148 TargetTriple(TT), FrameLowering(),
Matthias Brauna827ed82016-10-03 20:17:02 +0000149 InstrInfo(initializeSubtargetDependencies(FS, CPU)), TSInfo(),
Quentin Colombet61d71a12017-08-15 22:31:51 +0000150 TLInfo(TM, *this) {
151 CallLoweringInfo.reset(new AArch64CallLowering(*getTargetLowering()));
152 Legalizer.reset(new AArch64LegalizerInfo());
Quentin Colombetcdf8c812017-05-01 21:53:19 +0000153
154 auto *RBI = new AArch64RegisterBankInfo(*getRegisterInfo());
155
156 // FIXME: At this point, we can't rely on Subtarget having RBI.
157 // It's awkward to mix passing RBI and the Subtarget; should we pass
158 // TII/TRI as well?
Quentin Colombet61d71a12017-08-15 22:31:51 +0000159 InstSelector.reset(createAArch64InstructionSelector(
Quentin Colombetcdf8c812017-05-01 21:53:19 +0000160 *static_cast<const AArch64TargetMachine *>(&TM), *this, *RBI));
161
Quentin Colombet61d71a12017-08-15 22:31:51 +0000162 RegBankInfo.reset(RBI);
Quentin Colombetcdf8c812017-05-01 21:53:19 +0000163}
Quentin Colombetba2a0162016-02-16 19:26:02 +0000164
165const CallLowering *AArch64Subtarget::getCallLowering() const {
Quentin Colombet61d71a12017-08-15 22:31:51 +0000166 return CallLoweringInfo.get();
Quentin Colombetc17f7442016-04-06 17:26:03 +0000167}
168
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000169const InstructionSelector *AArch64Subtarget::getInstructionSelector() const {
Quentin Colombet61d71a12017-08-15 22:31:51 +0000170 return InstSelector.get();
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000171}
172
Tim Northover69fa84a2016-10-14 22:18:18 +0000173const LegalizerInfo *AArch64Subtarget::getLegalizerInfo() const {
Quentin Colombet61d71a12017-08-15 22:31:51 +0000174 return Legalizer.get();
Tim Northover33b07d62016-07-22 20:03:43 +0000175}
176
Quentin Colombetc17f7442016-04-06 17:26:03 +0000177const RegisterBankInfo *AArch64Subtarget::getRegBankInfo() const {
Quentin Colombet61d71a12017-08-15 22:31:51 +0000178 return RegBankInfo.get();
Quentin Colombetba2a0162016-02-16 19:26:02 +0000179}
Tim Northover3b0846e2014-05-24 12:50:23 +0000180
Rafael Espindola6b93bf52016-05-25 22:44:06 +0000181/// Find the target operand flags that describe how a global value should be
182/// referenced for the current subtarget.
Tim Northover3b0846e2014-05-24 12:50:23 +0000183unsigned char
184AArch64Subtarget::ClassifyGlobalReference(const GlobalValue *GV,
Rafael Espindola6b93bf52016-05-25 22:44:06 +0000185 const TargetMachine &TM) const {
Tim Northover3b0846e2014-05-24 12:50:23 +0000186 // MachO large model always goes via a GOT, simply to get a single 8-byte
187 // absolute relocation on all global addresses.
188 if (TM.getCodeModel() == CodeModel::Large && isTargetMachO())
189 return AArch64II::MO_GOT;
190
Rafael Espindola3beef8d2016-06-27 23:15:57 +0000191 if (!TM.shouldAssumeDSOLocal(*GV->getParent(), GV))
Rafael Espindolaa224de02016-05-26 12:42:55 +0000192 return AArch64II::MO_GOT;
193
Petr Hosek9eb0a1e2017-04-04 19:51:53 +0000194 // The small code model's direct accesses use ADRP, which cannot
195 // necessarily produce the value 0 (if the code is above 4GB).
196 if (useSmallAddressing() && GV->hasExternalWeakLinkage())
Rafael Espindola4d290992016-05-31 18:31:14 +0000197 return AArch64II::MO_GOT;
Tim Northover3b0846e2014-05-24 12:50:23 +0000198
Tim Northover3b0846e2014-05-24 12:50:23 +0000199 return AArch64II::MO_NO_FLAG;
200}
201
Tim Northover879a0b22017-04-17 17:27:56 +0000202unsigned char AArch64Subtarget::classifyGlobalFunctionReference(
203 const GlobalValue *GV, const TargetMachine &TM) const {
204 // MachO large model always goes via a GOT, because we don't have the
205 // relocations available to do anything else..
206 if (TM.getCodeModel() == CodeModel::Large && isTargetMachO() &&
207 !GV->hasInternalLinkage())
208 return AArch64II::MO_GOT;
209
210 // NonLazyBind goes via GOT unless we know it's available locally.
211 auto *F = dyn_cast<Function>(GV);
Tim Northover46e36f02017-04-17 18:18:47 +0000212 if (UseNonLazyBind && F && F->hasFnAttribute(Attribute::NonLazyBind) &&
Tim Northover879a0b22017-04-17 17:27:56 +0000213 !TM.shouldAssumeDSOLocal(*GV->getParent(), GV))
214 return AArch64II::MO_GOT;
215
216 return AArch64II::MO_NO_FLAG;
217}
218
Tim Northover3b0846e2014-05-24 12:50:23 +0000219/// This function returns the name of a function which has an interface
220/// like the non-standard bzero function, if such a function exists on
221/// the current subtarget and it is considered prefereable over
222/// memset with zero passed as the second argument. Otherwise it
223/// returns null.
224const char *AArch64Subtarget::getBZeroEntry() const {
225 // Prefer bzero on Darwin only.
226 if(isTargetDarwin())
227 return "bzero";
228
229 return nullptr;
230}
231
232void AArch64Subtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
Duncan P. N. Exon Smith63298722016-07-01 00:23:27 +0000233 unsigned NumRegionInstrs) const {
Tim Northover3b0846e2014-05-24 12:50:23 +0000234 // LNT run (at least on Cyclone) showed reasonably significant gains for
235 // bi-directional scheduling. 253.perlbmk.
236 Policy.OnlyTopDown = false;
237 Policy.OnlyBottomUp = false;
Matthias Braund276de62015-10-22 18:07:38 +0000238 // Enabling or Disabling the latency heuristic is a close call: It seems to
239 // help nearly no benchmark on out-of-order architectures, on the other hand
240 // it regresses register pressure on a few benchmarking.
Matthias Braun651cff42016-06-02 18:03:53 +0000241 Policy.DisableLatencyHeuristic = DisableLatencySchedHeuristic;
Tim Northover3b0846e2014-05-24 12:50:23 +0000242}
243
244bool AArch64Subtarget::enableEarlyIfConversion() const {
245 return EnableEarlyIfConvert;
246}
Lang Hames8f31f442014-10-09 18:20:51 +0000247
Tim Northover339c83e2015-11-10 00:44:23 +0000248bool AArch64Subtarget::supportsAddressTopByteIgnored() const {
249 if (!UseAddressTopByteIgnored)
250 return false;
251
252 if (TargetTriple.isiOS()) {
253 unsigned Major, Minor, Micro;
254 TargetTriple.getiOSVersion(Major, Minor, Micro);
255 return Major >= 8;
256 }
257
258 return false;
259}
260
Lang Hames8f31f442014-10-09 18:20:51 +0000261std::unique_ptr<PBQPRAConstraint>
262AArch64Subtarget::getCustomPBQPConstraints() const {
Matthias Braun651cff42016-06-02 18:03:53 +0000263 return balanceFPOps() ? llvm::make_unique<A57ChainingConstraint>() : nullptr;
Lang Hames8f31f442014-10-09 18:20:51 +0000264}