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