LLVM  5.0.0
AArch64Subtarget.cpp
Go to the documentation of this file.
1 //===-- 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 
14 #include "AArch64Subtarget.h"
15 
16 #include "AArch64.h"
17 #include "AArch64InstrInfo.h"
18 #include "AArch64PBQPRegAlloc.h"
19 #include "AArch64TargetMachine.h"
20 
21 #ifdef LLVM_BUILD_GLOBAL_ISEL
22 #include "AArch64CallLowering.h"
23 #include "AArch64LegalizerInfo.h"
30 #endif
32 #include "llvm/IR/GlobalValue.h"
34 
35 using 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 
43 static cl::opt<bool>
44 EnableEarlyIfConvert("aarch64-early-ifcvt", cl::desc("Enable the early if "
45  "converter pass"), cl::init(true), cl::Hidden);
46 
47 // If OS supports TBI, use this flag to enable it.
48 static cl::opt<bool>
49 UseAddressTopByteIgnored("aarch64-use-tbi", cl::desc("Assume that top byte of "
50  "an address is ignored"), cl::init(false), cl::Hidden);
51 
52 static 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 
58 AArch64Subtarget::initializeSubtargetDependencies(StringRef FS,
59  StringRef CPUString) {
60  // Determine default and user-specified characteristics
61 
62  if (CPUString.empty())
63  CPUString = "generic";
64 
65  ParseSubtargetFeatures(CPUString, FS);
66  initializeProperties();
67 
68  return *this;
69 }
70 
71 void 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;
81  break;
82  case CortexA57:
85  break;
86  case ExynosM1:
88  MaxJumpTableSize = 8;
91  break;
92  case Falkor:
94  // FIXME: remove this to enable 64-bit SLP if performance looks good.
96  CacheLineSize = 128;
97  PrefetchDistance = 820;
98  MinPrefetchStride = 2048;
100  break;
101  case Kryo:
104  CacheLineSize = 128;
105  PrefetchDistance = 740;
106  MinPrefetchStride = 1024;
108  // FIXME: remove this to enable 64-bit SLP if performance looks good.
110  break;
111  case ThunderX2T99:
112  CacheLineSize = 64;
114  PrefLoopAlignment = 2;
116  PrefetchDistance = 128;
117  MinPrefetchStride = 1024;
119  // FIXME: remove this to enable 64-bit SLP if performance looks good.
121  break;
122  case ThunderX:
123  case ThunderXT88:
124  case ThunderXT81:
125  case ThunderXT83:
126  CacheLineSize = 128;
128  PrefLoopAlignment = 2;
129  // FIXME: remove this to enable 64-bit SLP if performance looks good.
131  break;
132  case CortexA35: break;
133  case CortexA53: break;
134  case CortexA72:
136  break;
137  case CortexA73:
139  break;
140  case Others: break;
141  }
142 }
143 
144 #ifdef LLVM_BUILD_GLOBAL_ISEL
145 namespace {
146 
147 struct AArch64GISelActualAccessor : public GISelAccessor {
148  std::unique_ptr<CallLowering> CallLoweringInfo;
149  std::unique_ptr<InstructionSelector> InstSelector;
150  std::unique_ptr<LegalizerInfo> Legalizer;
151  std::unique_ptr<RegisterBankInfo> RegBankInfo;
152 
153  const CallLowering *getCallLowering() const override {
154  return CallLoweringInfo.get();
155  }
156 
157  const InstructionSelector *getInstructionSelector() const override {
158  return InstSelector.get();
159  }
160 
161  const LegalizerInfo *getLegalizerInfo() const override {
162  return Legalizer.get();
163  }
164 
165  const RegisterBankInfo *getRegBankInfo() const override {
166  return RegBankInfo.get();
167  }
168 };
169 
170 } // end anonymous namespace
171 #endif
172 
173 AArch64Subtarget::AArch64Subtarget(const Triple &TT, const std::string &CPU,
174  const std::string &FS,
175  const TargetMachine &TM, bool LittleEndian)
176  : AArch64GenSubtargetInfo(TT, CPU, FS),
177  ReserveX18(TT.isOSDarwin() || TT.isOSWindows()),
178  IsLittle(LittleEndian), TargetTriple(TT), FrameLowering(),
179  InstrInfo(initializeSubtargetDependencies(FS, CPU)), TSInfo(),
180  TLInfo(TM, *this), GISel() {
181 #ifndef LLVM_BUILD_GLOBAL_ISEL
182  GISelAccessor *AArch64GISel = new GISelAccessor();
183 #else
184  AArch64GISelActualAccessor *AArch64GISel = new AArch64GISelActualAccessor();
185  AArch64GISel->CallLoweringInfo.reset(
187  AArch64GISel->Legalizer.reset(new AArch64LegalizerInfo());
188 
189  auto *RBI = new AArch64RegisterBankInfo(*getRegisterInfo());
190 
191  // FIXME: At this point, we can't rely on Subtarget having RBI.
192  // It's awkward to mix passing RBI and the Subtarget; should we pass
193  // TII/TRI as well?
194  AArch64GISel->InstSelector.reset(createAArch64InstructionSelector(
195  *static_cast<const AArch64TargetMachine *>(&TM), *this, *RBI));
196 
197  AArch64GISel->RegBankInfo.reset(RBI);
198 #endif
199  setGISelAccessor(*AArch64GISel);
200 }
201 
203  assert(GISel && "Access to GlobalISel APIs not set");
204  return GISel->getCallLowering();
205 }
206 
208  assert(GISel && "Access to GlobalISel APIs not set");
209  return GISel->getInstructionSelector();
210 }
211 
213  assert(GISel && "Access to GlobalISel APIs not set");
214  return GISel->getLegalizerInfo();
215 }
216 
218  assert(GISel && "Access to GlobalISel APIs not set");
219  return GISel->getRegBankInfo();
220 }
221 
222 /// Find the target operand flags that describe how a global value should be
223 /// referenced for the current subtarget.
224 unsigned char
226  const TargetMachine &TM) const {
227  // MachO large model always goes via a GOT, simply to get a single 8-byte
228  // absolute relocation on all global addresses.
230  return AArch64II::MO_GOT;
231 
232  if (!TM.shouldAssumeDSOLocal(*GV->getParent(), GV))
233  return AArch64II::MO_GOT;
234 
235  // The small code model's direct accesses use ADRP, which cannot
236  // necessarily produce the value 0 (if the code is above 4GB).
238  return AArch64II::MO_GOT;
239 
240  return AArch64II::MO_NO_FLAG;
241 }
242 
244  const GlobalValue *GV, const TargetMachine &TM) const {
245  // MachO large model always goes via a GOT, because we don't have the
246  // relocations available to do anything else..
247  if (TM.getCodeModel() == CodeModel::Large && isTargetMachO() &&
248  !GV->hasInternalLinkage())
249  return AArch64II::MO_GOT;
250 
251  // NonLazyBind goes via GOT unless we know it's available locally.
252  auto *F = dyn_cast<Function>(GV);
253  if (UseNonLazyBind && F && F->hasFnAttribute(Attribute::NonLazyBind) &&
254  !TM.shouldAssumeDSOLocal(*GV->getParent(), GV))
255  return AArch64II::MO_GOT;
256 
257  return AArch64II::MO_NO_FLAG;
258 }
259 
260 /// This function returns the name of a function which has an interface
261 /// like the non-standard bzero function, if such a function exists on
262 /// the current subtarget and it is considered prefereable over
263 /// memset with zero passed as the second argument. Otherwise it
264 /// returns null.
265 const char *AArch64Subtarget::getBZeroEntry() const {
266  // Prefer bzero on Darwin only.
267  if(isTargetDarwin())
268  return "bzero";
269 
270  return nullptr;
271 }
272 
274  unsigned NumRegionInstrs) const {
275  // LNT run (at least on Cyclone) showed reasonably significant gains for
276  // bi-directional scheduling. 253.perlbmk.
277  Policy.OnlyTopDown = false;
278  Policy.OnlyBottomUp = false;
279  // Enabling or Disabling the latency heuristic is a close call: It seems to
280  // help nearly no benchmark on out-of-order architectures, on the other hand
281  // it regresses register pressure on a few benchmarking.
283 }
284 
286  return EnableEarlyIfConvert;
287 }
288 
291  return false;
292 
293  if (TargetTriple.isiOS()) {
294  unsigned Major, Minor, Micro;
295  TargetTriple.getiOSVersion(Major, Minor, Micro);
296  return Major >= 8;
297  }
298 
299  return false;
300 }
301 
302 std::unique_ptr<PBQPRAConstraint>
304  return balanceFPOps() ? llvm::make_unique<A57ChainingConstraint>() : nullptr;
305 }
The goal of this helper class is to gather the accessor to all the APIs related to GlobalISel...
Definition: GISelAccessor.h:29
const InstructionSelector * getInstructionSelector() const override
This class provides the information for the target register banks.
const CallLowering * getCallLowering() const override
void overrideSchedPolicy(MachineSchedPolicy &Policy, unsigned NumRegionInstrs) const override
This file declares the targeting of the RegisterBankInfo class for AArch64.
Holds all the information related to register banks.
bool hasInternalLinkage() const
Definition: GlobalValue.h:414
#define F(x, y, z)
Definition: MD5.cpp:55
MO_GOT - This flag indicates that a symbol operand represents the address of the GOT entry for the sy...
const AArch64RegisterInfo * getRegisterInfo() const override
This file declares the targeting of the Machinelegalizer class for AArch64.
bool enableEarlyIfConversion() const override
bool isiOS() const
Is this an iOS triple.
Definition: Triple.h:447
const AArch64TargetLowering * getTargetLowering() const override
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:401
unsigned char classifyGlobalFunctionReference(const GlobalValue *GV, const TargetMachine &TM) const
CodeModel::Model getCodeModel() const
Returns the code model.
void setGISelAccessor(GISelAccessor &GISel)
This object will take onwership of GISelAccessor.
void getiOSVersion(unsigned &Major, unsigned &Minor, unsigned &Micro) const
getiOSVersion - Parse the version number as with getOSVersion.
Definition: Triple.cpp:1046
bool shouldAssumeDSOLocal(const Module &M, const GlobalValue *GV) const
unsigned char ClassifyGlobalReference(const GlobalValue *GV, const TargetMachine &TM) const
ClassifyGlobalReference - Find the target operand flags that describe how a global value should be re...
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
bool hasExternalWeakLinkage() const
Definition: GlobalValue.h:417
void ParseSubtargetFeatures(StringRef CPU, StringRef FS)
ParseSubtargetFeatures - Parses features string setting specified subtarget options.
const char * getBZeroEntry() const
This function returns the name of a function which has an interface like the non-standard bzero funct...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:133
static cl::opt< bool > UseAddressTopByteIgnored("aarch64-use-tbi", cl::desc("Assume that top byte of ""an address is ignored"), cl::init(false), cl::Hidden)
bool isTargetDarwin() const
Provides the logic to select generic machine instructions.
Define a generic scheduling policy for targets that don't provide their own MachineSchedStrategy.
This class provides the information for the target register banks.
std::unique_ptr< PBQPRAConstraint > getCustomPBQPConstraints() const override
AArch64Subtarget(const Triple &TT, const std::string &CPU, const std::string &FS, const TargetMachine &TM, bool LittleEndian)
This constructor initializes the data members to match that of the specified triple.
const LegalizerInfo * getLegalizerInfo() const override
static cl::opt< bool > UseNonLazyBind("aarch64-enable-nonlazybind", cl::desc("Call nonlazybind functions via direct GOT load"), cl::init(false), cl::Hidden)
InstructionSelector * createAArch64InstructionSelector(const AArch64TargetMachine &, AArch64Subtarget &, AArch64RegisterBankInfo &)
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:323
This file describes how to lower LLVM calls to machine code calls.
bool supportsAddressTopByteIgnored() const
CPU has TBI (top byte of addresses is ignored during HW address translation) and OS enables it...
Triple TargetTriple
TargetTriple - What processor and OS we're targeting.
ARMProcFamilyEnum ARMProcFamily
ARMProcFamily - ARM processor family: Cortex-A53, Cortex-A57, and others.
This file declares the IRTranslator pass.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool useSmallAddressing() const
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:545
const RegisterBankInfo * getRegBankInfo() const override
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:56
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
std::unique_ptr< GISelAccessor > GISel
Gather the accessor points to GlobalISel-related APIs.
static cl::opt< bool > EnableEarlyIfConvert("aarch64-early-ifcvt", cl::desc("Enable the early if ""converter pass"), cl::init(true), cl::Hidden)