blob: 3312e8e93aba01790791c57bab19a1ab54dbeaf4 [file] [log] [blame]
Tim Northover00ed9962014-03-29 10:18:08 +00001//===-- ARM64Subtarget.cpp - ARM64 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 ARM64 specific subclass of TargetSubtarget.
11//
12//===----------------------------------------------------------------------===//
13
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"
20
21#define GET_SUBTARGETINFO_CTOR
22#define GET_SUBTARGETINFO_TARGET_DESC
23#include "ARM64GenSubtargetInfo.inc"
24
25using namespace llvm;
26
27ARM64Subtarget::ARM64Subtarget(const std::string &TT, const std::string &CPU,
28 const std::string &FS)
James Molloyd60571b2014-04-14 17:38:00 +000029 : ARM64GenSubtargetInfo(TT, CPU, FS), ARMProcFamily(Others),
30 HasFPARMv8(false), HasNEON(false), HasCrypto(false),
31 HasZeroCycleRegMove(false), HasZeroCycleZeroing(false),
32 CPUString(CPU), TargetTriple(TT) {
Tim Northover00ed9962014-03-29 10:18:08 +000033 // Determine default and user-specified characteristics
34
35 if (CPUString.empty())
Quentin Colombet72dad562014-04-15 19:08:46 +000036 CPUString = "generic";
Tim Northover00ed9962014-03-29 10:18:08 +000037
38 ParseSubtargetFeatures(CPUString, FS);
39}
40
41/// ClassifyGlobalReference - Find the target operand flags that describe
42/// how a global value should be referenced for the current subtarget.
43unsigned char
44ARM64Subtarget::ClassifyGlobalReference(const GlobalValue *GV,
45 const TargetMachine &TM) const {
46
47 // Determine whether this is a reference to a definition or a declaration.
48 // Materializable GVs (in JIT lazy compilation mode) do not require an extra
49 // load from stub.
50 bool isDecl = GV->hasAvailableExternallyLinkage();
51 if (GV->isDeclaration() && !GV->isMaterializable())
52 isDecl = true;
53
Tim Northover6d691682014-04-02 14:39:11 +000054 // MachO large model always goes via a GOT, simply to get a single 8-byte
55 // absolute relocation on all global addresses.
Tim Northover00ed9962014-03-29 10:18:08 +000056 if (TM.getCodeModel() == CodeModel::Large && isTargetMachO())
57 return ARM64II::MO_GOT;
58
Tim Northover6d691682014-04-02 14:39:11 +000059 // The small code mode's direct accesses use ADRP, which cannot necessarily
60 // produce the value 0 (if the code is above 4GB). Therefore they must use the
61 // GOT.
62 if (TM.getCodeModel() == CodeModel::Small && GV->isWeakForLinker() && isDecl)
63 return ARM64II::MO_GOT;
64
65 // If symbol visibility is hidden, the extra load is not needed if
66 // the symbol is definitely defined in the current translation unit.
67
68 // The handling of non-hidden symbols in PIC mode is rather target-dependent:
69 // + On MachO, if the symbol is defined in this module the GOT can be
70 // skipped.
71 // + On ELF, the R_AARCH64_COPY relocation means that even symbols actually
72 // defined could end up in unexpected places. Use a GOT.
73 if (TM.getRelocationModel() != Reloc::Static && GV->hasDefaultVisibility()) {
74 if (isTargetMachO())
75 return (isDecl || GV->isWeakForLinker()) ? ARM64II::MO_GOT
76 : ARM64II::MO_NO_FLAG;
77 else
78 return ARM64II::MO_GOT;
79 }
80
Tim Northover00ed9962014-03-29 10:18:08 +000081 return ARM64II::MO_NO_FLAG;
82}
83
84/// This function returns the name of a function which has an interface
85/// like the non-standard bzero function, if such a function exists on
86/// the current subtarget and it is considered prefereable over
87/// memset with zero passed as the second argument. Otherwise it
88/// returns null.
89const char *ARM64Subtarget::getBZeroEntry() const {
90 // At the moment, always prefer bzero.
91 return "bzero";
92}
93
94void ARM64Subtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
95 MachineInstr *begin, MachineInstr *end,
96 unsigned NumRegionInstrs) const {
97 // LNT run (at least on Cyclone) showed reasonably significant gains for
98 // bi-directional scheduling. 253.perlbmk.
99 Policy.OnlyTopDown = false;
100 Policy.OnlyBottomUp = false;
101}