1 //===-- AArch64Subtarget.cpp - AArch64 Subtarget Information ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the AArch64 specific subclass of TargetSubtarget.
12 //===----------------------------------------------------------------------===//
14 #include "AArch64Subtarget.h"
17 #include "AArch64InstrInfo.h"
18 #include "AArch64PBQPRegAlloc.h"
19 #include "AArch64TargetMachine.h"
21 #include "AArch64CallLowering.h"
22 #include "AArch64LegalizerInfo.h"
23 #include "AArch64RegisterBankInfo.h"
24 #include "llvm/CodeGen/GlobalISel/InstructionSelect.h"
25 #include "llvm/CodeGen/MachineScheduler.h"
26 #include "llvm/IR/GlobalValue.h"
30 #define DEBUG_TYPE "aarch64-subtarget"
32 #define GET_SUBTARGETINFO_CTOR
33 #define GET_SUBTARGETINFO_TARGET_DESC
34 #include "AArch64GenSubtargetInfo.inc"
37 EnableEarlyIfConvert("aarch64-early-ifcvt", cl::desc("Enable the early if "
38 "converter pass"), cl::init(true), cl::Hidden);
40 // If OS supports TBI, use this flag to enable it.
42 UseAddressTopByteIgnored("aarch64-use-tbi", cl::desc("Assume that top byte of "
43 "an address is ignored"), cl::init(false), cl::Hidden);
46 UseNonLazyBind("aarch64-enable-nonlazybind",
47 cl::desc("Call nonlazybind functions via direct GOT load"),
48 cl::init(false), cl::Hidden);
51 AArch64Subtarget::initializeSubtargetDependencies(StringRef FS,
52 StringRef CPUString) {
53 // Determine default and user-specified characteristics
55 if (CPUString.empty())
56 CPUString = "generic";
58 ParseSubtargetFeatures(CPUString, FS);
59 initializeProperties();
64 void 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
68 switch (ARMProcFamily) {
71 PrefetchDistance = 280;
72 MinPrefetchStride = 2048;
73 MaxPrefetchIterationsAhead = 3;
76 MaxInterleaveFactor = 4;
77 PrefFunctionAlignment = 4;
80 MaxInterleaveFactor = 4;
82 PrefFunctionAlignment = 4;
83 PrefLoopAlignment = 3;
86 MaxInterleaveFactor = 4;
87 // FIXME: remove this to enable 64-bit SLP if performance looks good.
88 MinVectorRegisterBitWidth = 128;
90 PrefetchDistance = 820;
91 MinPrefetchStride = 2048;
92 MaxPrefetchIterationsAhead = 8;
95 MaxInterleaveFactor = 4;
96 // FIXME: remove this to enable 64-bit SLP if performance looks good.
97 MinVectorRegisterBitWidth = 128;
100 MaxInterleaveFactor = 4;
101 VectorInsertExtractBaseCost = 2;
103 PrefetchDistance = 740;
104 MinPrefetchStride = 1024;
105 MaxPrefetchIterationsAhead = 11;
106 // FIXME: remove this to enable 64-bit SLP if performance looks good.
107 MinVectorRegisterBitWidth = 128;
111 PrefFunctionAlignment = 3;
112 PrefLoopAlignment = 2;
113 MaxInterleaveFactor = 4;
114 PrefetchDistance = 128;
115 MinPrefetchStride = 1024;
116 MaxPrefetchIterationsAhead = 4;
117 // FIXME: remove this to enable 64-bit SLP if performance looks good.
118 MinVectorRegisterBitWidth = 128;
125 PrefFunctionAlignment = 3;
126 PrefLoopAlignment = 2;
127 // FIXME: remove this to enable 64-bit SLP if performance looks good.
128 MinVectorRegisterBitWidth = 128;
130 case CortexA35: break;
132 PrefFunctionAlignment = 3;
134 case CortexA55: break;
138 PrefFunctionAlignment = 4;
144 AArch64Subtarget::AArch64Subtarget(const Triple &TT, const std::string &CPU,
145 const std::string &FS,
146 const TargetMachine &TM, bool LittleEndian)
147 : AArch64GenSubtargetInfo(TT, CPU, FS),
148 ReserveX18(TT.isOSDarwin() || TT.isOSWindows()), IsLittle(LittleEndian),
149 TargetTriple(TT), FrameLowering(),
150 InstrInfo(initializeSubtargetDependencies(FS, CPU)), TSInfo(),
152 CallLoweringInfo.reset(new AArch64CallLowering(*getTargetLowering()));
153 Legalizer.reset(new AArch64LegalizerInfo(*this));
155 auto *RBI = new AArch64RegisterBankInfo(*getRegisterInfo());
157 // FIXME: At this point, we can't rely on Subtarget having RBI.
158 // It's awkward to mix passing RBI and the Subtarget; should we pass
160 InstSelector.reset(createAArch64InstructionSelector(
161 *static_cast<const AArch64TargetMachine *>(&TM), *this, *RBI));
163 RegBankInfo.reset(RBI);
166 const CallLowering *AArch64Subtarget::getCallLowering() const {
167 return CallLoweringInfo.get();
170 const InstructionSelector *AArch64Subtarget::getInstructionSelector() const {
171 return InstSelector.get();
174 const LegalizerInfo *AArch64Subtarget::getLegalizerInfo() const {
175 return Legalizer.get();
178 const RegisterBankInfo *AArch64Subtarget::getRegBankInfo() const {
179 return RegBankInfo.get();
182 /// Find the target operand flags that describe how a global value should be
183 /// referenced for the current subtarget.
185 AArch64Subtarget::ClassifyGlobalReference(const GlobalValue *GV,
186 const TargetMachine &TM) const {
187 // MachO large model always goes via a GOT, simply to get a single 8-byte
188 // absolute relocation on all global addresses.
189 if (TM.getCodeModel() == CodeModel::Large && isTargetMachO())
190 return AArch64II::MO_GOT;
192 unsigned Flags = GV->hasDLLImportStorageClass() ? AArch64II::MO_DLLIMPORT
193 : AArch64II::MO_NO_FLAG;
195 if (!TM.shouldAssumeDSOLocal(*GV->getParent(), GV))
196 return AArch64II::MO_GOT | Flags;
198 // The small code model's direct accesses use ADRP, which cannot
199 // necessarily produce the value 0 (if the code is above 4GB).
200 if (useSmallAddressing() && GV->hasExternalWeakLinkage())
201 return AArch64II::MO_GOT | Flags;
206 unsigned char AArch64Subtarget::classifyGlobalFunctionReference(
207 const GlobalValue *GV, const TargetMachine &TM) const {
208 // MachO large model always goes via a GOT, because we don't have the
209 // relocations available to do anything else..
210 if (TM.getCodeModel() == CodeModel::Large && isTargetMachO() &&
211 !GV->hasInternalLinkage())
212 return AArch64II::MO_GOT;
214 // NonLazyBind goes via GOT unless we know it's available locally.
215 auto *F = dyn_cast<Function>(GV);
216 if (UseNonLazyBind && F && F->hasFnAttribute(Attribute::NonLazyBind) &&
217 !TM.shouldAssumeDSOLocal(*GV->getParent(), GV))
218 return AArch64II::MO_GOT;
220 return AArch64II::MO_NO_FLAG;
223 void AArch64Subtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
224 unsigned NumRegionInstrs) const {
225 // LNT run (at least on Cyclone) showed reasonably significant gains for
226 // bi-directional scheduling. 253.perlbmk.
227 Policy.OnlyTopDown = false;
228 Policy.OnlyBottomUp = false;
229 // Enabling or Disabling the latency heuristic is a close call: It seems to
230 // help nearly no benchmark on out-of-order architectures, on the other hand
231 // it regresses register pressure on a few benchmarking.
232 Policy.DisableLatencyHeuristic = DisableLatencySchedHeuristic;
235 bool AArch64Subtarget::enableEarlyIfConversion() const {
236 return EnableEarlyIfConvert;
239 bool AArch64Subtarget::supportsAddressTopByteIgnored() const {
240 if (!UseAddressTopByteIgnored)
243 if (TargetTriple.isiOS()) {
244 unsigned Major, Minor, Micro;
245 TargetTriple.getiOSVersion(Major, Minor, Micro);
252 std::unique_ptr<PBQPRAConstraint>
253 AArch64Subtarget::getCustomPBQPConstraints() const {
254 return balanceFPOps() ? llvm::make_unique<A57ChainingConstraint>() : nullptr;