blob: a1e8b87ed9c57c738c89624a0963432a3a2b37fc [file] [log] [blame]
Tim Northover3b0846e2014-05-24 12:50:23 +00001//===-- 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 "AArch64InstrInfo.h"
15#include "AArch64Subtarget.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
21using namespace llvm;
22
23#define DEBUG_TYPE "aarch64-subtarget"
24
25#define GET_SUBTARGETINFO_CTOR
26#define GET_SUBTARGETINFO_TARGET_DESC
27#include "AArch64GenSubtargetInfo.inc"
28
29static cl::opt<bool>
30EnableEarlyIfConvert("aarch64-early-ifcvt", cl::desc("Enable the early if "
31 "converter pass"), cl::init(true), cl::Hidden);
32
33AArch64Subtarget::AArch64Subtarget(const std::string &TT,
34 const std::string &CPU,
Eric Christopher841da852014-06-10 23:26:45 +000035 const std::string &FS, TargetMachine &TM,
36 bool LittleEndian)
Tim Northover3b0846e2014-05-24 12:50:23 +000037 : AArch64GenSubtargetInfo(TT, CPU, FS), ARMProcFamily(Others),
38 HasFPARMv8(false), HasNEON(false), HasCrypto(false), HasCRC(false),
39 HasZeroCycleRegMove(false), HasZeroCycleZeroing(false), CPUString(CPU),
Eric Christopher17254ee2014-06-10 18:11:20 +000040 TargetTriple(TT),
Eric Christopher6f2a2032014-06-10 18:06:23 +000041 // This nested ternary is horrible, but DL needs to be properly
42 // initialized
43 // before TLInfo is constructed.
44 DL(isTargetMachO()
45 ? "e-m:o-i64:64-i128:128-n32:64-S128"
Eric Christopher17254ee2014-06-10 18:11:20 +000046 : (LittleEndian ? "e-m:e-i64:64-i128:128-n32:64-S128"
47 : "E-m:e-i64:64-i128:128-n32:64-S128")),
Eric Christopherf63bc642014-06-10 22:57:25 +000048 FrameLowering(), InstrInfo(*this), TSInfo(&DL) {
Tim Northover3b0846e2014-05-24 12:50:23 +000049 // Determine default and user-specified characteristics
50
51 if (CPUString.empty())
52 CPUString = "generic";
53
54 ParseSubtargetFeatures(CPUString, FS);
Eric Christopher841da852014-06-10 23:26:45 +000055 TLInfo = make_unique<AArch64TargetLowering>(TM);
Tim Northover3b0846e2014-05-24 12:50:23 +000056}
57
58/// ClassifyGlobalReference - Find the target operand flags that describe
59/// how a global value should be referenced for the current subtarget.
60unsigned char
61AArch64Subtarget::ClassifyGlobalReference(const GlobalValue *GV,
62 const TargetMachine &TM) const {
63
64 // Determine whether this is a reference to a definition or a declaration.
65 // Materializable GVs (in JIT lazy compilation mode) do not require an extra
66 // load from stub.
67 bool isDecl = GV->hasAvailableExternallyLinkage();
68 if (GV->isDeclaration() && !GV->isMaterializable())
69 isDecl = true;
70
71 // MachO large model always goes via a GOT, simply to get a single 8-byte
72 // absolute relocation on all global addresses.
73 if (TM.getCodeModel() == CodeModel::Large && isTargetMachO())
74 return AArch64II::MO_GOT;
75
76 // The small code mode's direct accesses use ADRP, which cannot necessarily
77 // produce the value 0 (if the code is above 4GB). Therefore they must use the
78 // GOT.
79 if (TM.getCodeModel() == CodeModel::Small && GV->isWeakForLinker() && isDecl)
80 return AArch64II::MO_GOT;
81
82 // If symbol visibility is hidden, the extra load is not needed if
83 // the symbol is definitely defined in the current translation unit.
84
85 // The handling of non-hidden symbols in PIC mode is rather target-dependent:
86 // + On MachO, if the symbol is defined in this module the GOT can be
87 // skipped.
88 // + On ELF, the R_AARCH64_COPY relocation means that even symbols actually
89 // defined could end up in unexpected places. Use a GOT.
90 if (TM.getRelocationModel() != Reloc::Static && GV->hasDefaultVisibility()) {
91 if (isTargetMachO())
92 return (isDecl || GV->isWeakForLinker()) ? AArch64II::MO_GOT
93 : AArch64II::MO_NO_FLAG;
94 else
95 // No need to go through the GOT for local symbols on ELF.
96 return GV->hasLocalLinkage() ? AArch64II::MO_NO_FLAG : AArch64II::MO_GOT;
97 }
98
99 return AArch64II::MO_NO_FLAG;
100}
101
102/// This function returns the name of a function which has an interface
103/// like the non-standard bzero function, if such a function exists on
104/// the current subtarget and it is considered prefereable over
105/// memset with zero passed as the second argument. Otherwise it
106/// returns null.
107const char *AArch64Subtarget::getBZeroEntry() const {
108 // Prefer bzero on Darwin only.
109 if(isTargetDarwin())
110 return "bzero";
111
112 return nullptr;
113}
114
115void AArch64Subtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
116 MachineInstr *begin, MachineInstr *end,
117 unsigned NumRegionInstrs) const {
118 // LNT run (at least on Cyclone) showed reasonably significant gains for
119 // bi-directional scheduling. 253.perlbmk.
120 Policy.OnlyTopDown = false;
121 Policy.OnlyBottomUp = false;
122}
123
124bool AArch64Subtarget::enableEarlyIfConversion() const {
125 return EnableEarlyIfConvert;
126}