1 //===-- ARM64Subtarget.cpp - ARM64 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 ARM64 specific subclass of TargetSubtarget.
12 //===----------------------------------------------------------------------===//
14 #include "ARM64InstrInfo.h"
15 #include "ARM64Subtarget.h"
16 #include "llvm/ADT/SmallVector.h"
17 #include "llvm/CodeGen/MachineScheduler.h"
18 #include "llvm/IR/GlobalValue.h"
19 #include "llvm/Support/TargetRegistry.h"
21 #define GET_SUBTARGETINFO_CTOR
22 #define GET_SUBTARGETINFO_TARGET_DESC
23 #include "ARM64GenSubtargetInfo.inc"
27 ARM64Subtarget::ARM64Subtarget(const std::string &TT, const std::string &CPU,
28 const std::string &FS)
29 : ARM64GenSubtargetInfo(TT, CPU, FS), ARMProcFamily(Others),
30 HasFPARMv8(false), HasNEON(false), HasCrypto(false),
31 HasZeroCycleRegMove(false), HasZeroCycleZeroing(false),
32 CPUString(CPU), TargetTriple(TT) {
33 // Determine default and user-specified characteristics
35 // FIXME: Make this darwin-only.
36 if (CPUString.empty())
37 // We default to Cyclone for now, on Darwin.
38 CPUString = "cyclone";
40 ParseSubtargetFeatures(CPUString, FS);
43 /// ClassifyGlobalReference - Find the target operand flags that describe
44 /// how a global value should be referenced for the current subtarget.
46 ARM64Subtarget::ClassifyGlobalReference(const GlobalValue *GV,
47 const TargetMachine &TM) const {
49 // Determine whether this is a reference to a definition or a declaration.
50 // Materializable GVs (in JIT lazy compilation mode) do not require an extra
52 bool isDecl = GV->hasAvailableExternallyLinkage();
53 if (GV->isDeclaration() && !GV->isMaterializable())
56 // MachO large model always goes via a GOT, simply to get a single 8-byte
57 // absolute relocation on all global addresses.
58 if (TM.getCodeModel() == CodeModel::Large && isTargetMachO())
59 return ARM64II::MO_GOT;
61 // The small code mode's direct accesses use ADRP, which cannot necessarily
62 // produce the value 0 (if the code is above 4GB). Therefore they must use the
64 if (TM.getCodeModel() == CodeModel::Small && GV->isWeakForLinker() && isDecl)
65 return ARM64II::MO_GOT;
67 // If symbol visibility is hidden, the extra load is not needed if
68 // the symbol is definitely defined in the current translation unit.
70 // The handling of non-hidden symbols in PIC mode is rather target-dependent:
71 // + On MachO, if the symbol is defined in this module the GOT can be
73 // + On ELF, the R_AARCH64_COPY relocation means that even symbols actually
74 // defined could end up in unexpected places. Use a GOT.
75 if (TM.getRelocationModel() != Reloc::Static && GV->hasDefaultVisibility()) {
77 return (isDecl || GV->isWeakForLinker()) ? ARM64II::MO_GOT
78 : ARM64II::MO_NO_FLAG;
80 return ARM64II::MO_GOT;
83 return ARM64II::MO_NO_FLAG;
86 /// This function returns the name of a function which has an interface
87 /// like the non-standard bzero function, if such a function exists on
88 /// the current subtarget and it is considered prefereable over
89 /// memset with zero passed as the second argument. Otherwise it
91 const char *ARM64Subtarget::getBZeroEntry() const {
92 // At the moment, always prefer bzero.
96 void ARM64Subtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
97 MachineInstr *begin, MachineInstr *end,
98 unsigned NumRegionInstrs) const {
99 // LNT run (at least on Cyclone) showed reasonably significant gains for
100 // bi-directional scheduling. 253.perlbmk.
101 Policy.OnlyTopDown = false;
102 Policy.OnlyBottomUp = false;