blob: 4880ff6f9e7bcada35b494759a96d8c4dc9dc2ac [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
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 Northover3b0846e2014-05-24 12:50:23 +000031#include "llvm/CodeGen/MachineScheduler.h"
32#include "llvm/IR/GlobalValue.h"
33#include "llvm/Support/TargetRegistry.h"
34
35using 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
43static cl::opt<bool>
44EnableEarlyIfConvert("aarch64-early-ifcvt", cl::desc("Enable the early if "
45 "converter pass"), cl::init(true), cl::Hidden);
46
Tim Northover339c83e2015-11-10 00:44:23 +000047// If OS supports TBI, use this flag to enable it.
48static cl::opt<bool>
49UseAddressTopByteIgnored("aarch64-use-tbi", cl::desc("Assume that top byte of "
50 "an address is ignored"), cl::init(false), cl::Hidden);
51
Tim Northover46e36f02017-04-17 18:18:47 +000052static 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 Christopher7c9d4e02014-06-11 00:46:34 +000057AArch64Subtarget &
Matthias Brauna827ed82016-10-03 20:17:02 +000058AArch64Subtarget::initializeSubtargetDependencies(StringRef FS,
59 StringRef CPUString) {
Eric Christopher7c9d4e02014-06-11 00:46:34 +000060 // Determine default and user-specified characteristics
61
62 if (CPUString.empty())
63 CPUString = "generic";
64
65 ParseSubtargetFeatures(CPUString, FS);
Matthias Braun651cff42016-06-02 18:03:53 +000066 initializeProperties();
67
Eric Christopher7c9d4e02014-06-11 00:46:34 +000068 return *this;
69}
70
Matthias Braun651cff42016-06-02 18:03:53 +000071void 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 Hahnd4550ba2017-07-07 10:43:01 +000084 PrefFunctionAlignment = 4;
Matthias Braun651cff42016-06-02 18:03:53 +000085 break;
Evandro Menezesa3a0a602016-06-10 16:00:18 +000086 case ExynosM1:
Abderrazek Zaafrani9daf8112016-10-21 16:28:27 +000087 MaxInterleaveFactor = 4;
Evandro Menezes7696dc02016-10-25 20:05:42 +000088 MaxJumpTableSize = 8;
Evandro Menezesa3a0a602016-06-10 16:00:18 +000089 PrefFunctionAlignment = 4;
90 PrefLoopAlignment = 3;
91 break;
Chad Rosierecc77272016-11-22 14:25:02 +000092 case Falkor:
93 MaxInterleaveFactor = 4;
Adam Nemete29686e2017-05-15 21:15:01 +000094 // FIXME: remove this to enable 64-bit SLP if performance looks good.
95 MinVectorRegisterBitWidth = 128;
Haicheng Wuef790ff2017-06-12 16:34:19 +000096 CacheLineSize = 128;
97 PrefetchDistance = 820;
98 MinPrefetchStride = 2048;
99 MaxPrefetchIterationsAhead = 8;
Chad Rosierecc77272016-11-22 14:25:02 +0000100 break;
Matthias Braun651cff42016-06-02 18:03:53 +0000101 case Kryo:
102 MaxInterleaveFactor = 4;
103 VectorInsertExtractBaseCost = 2;
Haicheng Wua783bac2016-06-21 22:47:56 +0000104 CacheLineSize = 128;
105 PrefetchDistance = 740;
106 MinPrefetchStride = 1024;
107 MaxPrefetchIterationsAhead = 11;
Adam Nemete29686e2017-05-15 21:15:01 +0000108 // FIXME: remove this to enable 64-bit SLP if performance looks good.
109 MinVectorRegisterBitWidth = 128;
Matthias Braun651cff42016-06-02 18:03:53 +0000110 break;
Joel Jones28520882017-03-07 19:42:40 +0000111 case ThunderX2T99:
112 CacheLineSize = 64;
113 PrefFunctionAlignment = 3;
114 PrefLoopAlignment = 2;
Pankaj Godef4b25542016-06-30 06:42:31 +0000115 MaxInterleaveFactor = 4;
Joel Jones28520882017-03-07 19:42:40 +0000116 PrefetchDistance = 128;
117 MinPrefetchStride = 1024;
118 MaxPrefetchIterationsAhead = 4;
Adam Nemete29686e2017-05-15 21:15:01 +0000119 // FIXME: remove this to enable 64-bit SLP if performance looks good.
120 MinVectorRegisterBitWidth = 128;
Pankaj Godef4b25542016-06-30 06:42:31 +0000121 break;
Joel Jonesab0f3b42017-02-17 18:34:24 +0000122 case ThunderX:
123 case ThunderXT88:
124 case ThunderXT81:
125 case ThunderXT83:
126 CacheLineSize = 128;
Joel Jones28520882017-03-07 19:42:40 +0000127 PrefFunctionAlignment = 3;
128 PrefLoopAlignment = 2;
Adam Nemete29686e2017-05-15 21:15:01 +0000129 // FIXME: remove this to enable 64-bit SLP if performance looks good.
130 MinVectorRegisterBitWidth = 128;
Joel Jonesab0f3b42017-02-17 18:34:24 +0000131 break;
Matthias Braun651cff42016-06-02 18:03:53 +0000132 case CortexA35: break;
Florian Hahn2f86e3d2017-07-29 20:04:54 +0000133 case CortexA53:
134 PrefFunctionAlignment = 3;
135 break;
Florian Hahne3666ec2017-07-07 10:15:49 +0000136 case CortexA72:
137 PrefFunctionAlignment = 4;
138 break;
Florian Hahn35300942017-07-18 09:31:18 +0000139 case CortexA73:
140 PrefFunctionAlignment = 4;
141 break;
Evandro Menezesa3a0a602016-06-10 16:00:18 +0000142 case Others: break;
Matthias Braun651cff42016-06-02 18:03:53 +0000143 }
144}
145
Quentin Colombetcdf8c812017-05-01 21:53:19 +0000146#ifdef LLVM_BUILD_GLOBAL_ISEL
147namespace {
148
149struct 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 Sandersa73f1fd2015-06-10 12:11:26 +0000175AArch64Subtarget::AArch64Subtarget(const Triple &TT, const std::string &CPU,
Eric Christopherf12e1ab2014-10-03 00:42:41 +0000176 const std::string &FS,
Daniel Sandersa1b2db792017-05-19 11:08:33 +0000177 const TargetMachine &TM, bool LittleEndian)
Mandeep Singh Grangd857b4c2017-07-18 20:41:33 +0000178 : AArch64GenSubtargetInfo(TT, CPU, FS),
179 ReserveX18(TT.isOSDarwin() || TT.isOSWindows()),
Matthias Brauna827ed82016-10-03 20:17:02 +0000180 IsLittle(LittleEndian), TargetTriple(TT), FrameLowering(),
181 InstrInfo(initializeSubtargetDependencies(FS, CPU)), TSInfo(),
Daniel Sandersa1b2db792017-05-19 11:08:33 +0000182 TLInfo(TM, *this), GISel() {
Quentin Colombetcdf8c812017-05-01 21:53:19 +0000183#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 Colombetba2a0162016-02-16 19:26:02 +0000203
204const CallLowering *AArch64Subtarget::getCallLowering() const {
Tom Stellardcef0fe42016-04-14 17:45:38 +0000205 assert(GISel && "Access to GlobalISel APIs not set");
206 return GISel->getCallLowering();
Quentin Colombetc17f7442016-04-06 17:26:03 +0000207}
208
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000209const InstructionSelector *AArch64Subtarget::getInstructionSelector() const {
210 assert(GISel && "Access to GlobalISel APIs not set");
211 return GISel->getInstructionSelector();
212}
213
Tim Northover69fa84a2016-10-14 22:18:18 +0000214const LegalizerInfo *AArch64Subtarget::getLegalizerInfo() const {
Tim Northover33b07d62016-07-22 20:03:43 +0000215 assert(GISel && "Access to GlobalISel APIs not set");
Tim Northover69fa84a2016-10-14 22:18:18 +0000216 return GISel->getLegalizerInfo();
Tim Northover33b07d62016-07-22 20:03:43 +0000217}
218
Quentin Colombetc17f7442016-04-06 17:26:03 +0000219const RegisterBankInfo *AArch64Subtarget::getRegBankInfo() const {
Tom Stellardcef0fe42016-04-14 17:45:38 +0000220 assert(GISel && "Access to GlobalISel APIs not set");
221 return GISel->getRegBankInfo();
Quentin Colombetba2a0162016-02-16 19:26:02 +0000222}
Tim Northover3b0846e2014-05-24 12:50:23 +0000223
Rafael Espindola6b93bf52016-05-25 22:44:06 +0000224/// Find the target operand flags that describe how a global value should be
225/// referenced for the current subtarget.
Tim Northover3b0846e2014-05-24 12:50:23 +0000226unsigned char
227AArch64Subtarget::ClassifyGlobalReference(const GlobalValue *GV,
Rafael Espindola6b93bf52016-05-25 22:44:06 +0000228 const TargetMachine &TM) const {
Tim Northover3b0846e2014-05-24 12:50:23 +0000229 // 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 Espindola3beef8d2016-06-27 23:15:57 +0000234 if (!TM.shouldAssumeDSOLocal(*GV->getParent(), GV))
Rafael Espindolaa224de02016-05-26 12:42:55 +0000235 return AArch64II::MO_GOT;
236
Petr Hosek9eb0a1e2017-04-04 19:51:53 +0000237 // 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 Espindola4d290992016-05-31 18:31:14 +0000240 return AArch64II::MO_GOT;
Tim Northover3b0846e2014-05-24 12:50:23 +0000241
Tim Northover3b0846e2014-05-24 12:50:23 +0000242 return AArch64II::MO_NO_FLAG;
243}
244
Tim Northover879a0b22017-04-17 17:27:56 +0000245unsigned 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 Northover46e36f02017-04-17 18:18:47 +0000255 if (UseNonLazyBind && F && F->hasFnAttribute(Attribute::NonLazyBind) &&
Tim Northover879a0b22017-04-17 17:27:56 +0000256 !TM.shouldAssumeDSOLocal(*GV->getParent(), GV))
257 return AArch64II::MO_GOT;
258
259 return AArch64II::MO_NO_FLAG;
260}
261
Tim Northover3b0846e2014-05-24 12:50:23 +0000262/// 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.
267const char *AArch64Subtarget::getBZeroEntry() const {
268 // Prefer bzero on Darwin only.
269 if(isTargetDarwin())
270 return "bzero";
271
272 return nullptr;
273}
274
275void AArch64Subtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
Duncan P. N. Exon Smith63298722016-07-01 00:23:27 +0000276 unsigned NumRegionInstrs) const {
Tim Northover3b0846e2014-05-24 12:50:23 +0000277 // 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 Braund276de62015-10-22 18:07:38 +0000281 // 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 Braun651cff42016-06-02 18:03:53 +0000284 Policy.DisableLatencyHeuristic = DisableLatencySchedHeuristic;
Tim Northover3b0846e2014-05-24 12:50:23 +0000285}
286
287bool AArch64Subtarget::enableEarlyIfConversion() const {
288 return EnableEarlyIfConvert;
289}
Lang Hames8f31f442014-10-09 18:20:51 +0000290
Tim Northover339c83e2015-11-10 00:44:23 +0000291bool 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 Hames8f31f442014-10-09 18:20:51 +0000304std::unique_ptr<PBQPRAConstraint>
305AArch64Subtarget::getCustomPBQPConstraints() const {
Matthias Braun651cff42016-06-02 18:03:53 +0000306 return balanceFPOps() ? llvm::make_unique<A57ChainingConstraint>() : nullptr;
Lang Hames8f31f442014-10-09 18:20:51 +0000307}