blob: 7b04b1a735034b40bdd1ff8fd5c70235a3f64c84 [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"
Lang Hames8f31f442014-10-09 18:20:51 +000015#include "AArch64PBQPRegAlloc.h"
Tim Northover3b0846e2014-05-24 12:50:23 +000016#include "AArch64Subtarget.h"
Eric Christopher1b585ae2015-03-12 21:04:46 +000017#include "AArch64TargetMachine.h"
Tim Northover3b0846e2014-05-24 12:50:23 +000018#include "llvm/ADT/SmallVector.h"
19#include "llvm/CodeGen/MachineScheduler.h"
20#include "llvm/IR/GlobalValue.h"
21#include "llvm/Support/TargetRegistry.h"
22
23using namespace llvm;
24
25#define DEBUG_TYPE "aarch64-subtarget"
26
27#define GET_SUBTARGETINFO_CTOR
28#define GET_SUBTARGETINFO_TARGET_DESC
29#include "AArch64GenSubtargetInfo.inc"
30
31static cl::opt<bool>
32EnableEarlyIfConvert("aarch64-early-ifcvt", cl::desc("Enable the early if "
33 "converter pass"), cl::init(true), cl::Hidden);
34
Eric Christopher7c9d4e02014-06-11 00:46:34 +000035AArch64Subtarget &
36AArch64Subtarget::initializeSubtargetDependencies(StringRef FS) {
37 // Determine default and user-specified characteristics
38
39 if (CPUString.empty())
40 CPUString = "generic";
41
42 ParseSubtargetFeatures(CPUString, FS);
43 return *this;
44}
45
Tim Northover3b0846e2014-05-24 12:50:23 +000046AArch64Subtarget::AArch64Subtarget(const std::string &TT,
47 const std::string &CPU,
Eric Christopherf12e1ab2014-10-03 00:42:41 +000048 const std::string &FS,
Eric Christopher1b585ae2015-03-12 21:04:46 +000049 const AArch64TargetMachine &TM,
50 bool LittleEndian)
Tim Northover3b0846e2014-05-24 12:50:23 +000051 : AArch64GenSubtargetInfo(TT, CPU, FS), ARMProcFamily(Others),
52 HasFPARMv8(false), HasNEON(false), HasCrypto(false), HasCRC(false),
Eric Christopher8b770652015-01-26 19:03:15 +000053 HasZeroCycleRegMove(false), HasZeroCycleZeroing(false),
Eric Christopher1b585ae2015-03-12 21:04:46 +000054 IsLittle(LittleEndian), CPUString(CPU), TargetTriple(TT), TM(TM),
55 FrameLowering(), InstrInfo(initializeSubtargetDependencies(FS)),
Eric Christopher905f12d2015-01-29 00:19:42 +000056 TSInfo(TM.getDataLayout()), TLInfo(TM, *this) {}
Tim Northover3b0846e2014-05-24 12:50:23 +000057
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 {
Rafael Espindola246c4fb2014-11-01 16:46:18 +000063 bool isDecl = GV->isDeclarationForLinker();
Tim Northover3b0846e2014-05-24 12:50:23 +000064
65 // MachO large model always goes via a GOT, simply to get a single 8-byte
66 // absolute relocation on all global addresses.
67 if (TM.getCodeModel() == CodeModel::Large && isTargetMachO())
68 return AArch64II::MO_GOT;
69
70 // The small code mode's direct accesses use ADRP, which cannot necessarily
Asiri Rathnayake369c0302014-09-10 13:54:38 +000071 // produce the value 0 (if the code is above 4GB).
72 if (TM.getCodeModel() == CodeModel::Small &&
73 GV->isWeakForLinker() && isDecl) {
74 // In PIC mode use the GOT, but in absolute mode use a constant pool load.
75 if (TM.getRelocationModel() == Reloc::Static)
76 return AArch64II::MO_CONSTPOOL;
77 else
78 return AArch64II::MO_GOT;
79 }
Tim Northover3b0846e2014-05-24 12:50:23 +000080
81 // If symbol visibility is hidden, the extra load is not needed if
82 // the symbol is definitely defined in the current translation unit.
83
84 // The handling of non-hidden symbols in PIC mode is rather target-dependent:
85 // + On MachO, if the symbol is defined in this module the GOT can be
86 // skipped.
87 // + On ELF, the R_AARCH64_COPY relocation means that even symbols actually
88 // defined could end up in unexpected places. Use a GOT.
89 if (TM.getRelocationModel() != Reloc::Static && GV->hasDefaultVisibility()) {
90 if (isTargetMachO())
91 return (isDecl || GV->isWeakForLinker()) ? AArch64II::MO_GOT
92 : AArch64II::MO_NO_FLAG;
93 else
94 // No need to go through the GOT for local symbols on ELF.
95 return GV->hasLocalLinkage() ? AArch64II::MO_NO_FLAG : AArch64II::MO_GOT;
96 }
97
98 return AArch64II::MO_NO_FLAG;
99}
100
101/// This function returns the name of a function which has an interface
102/// like the non-standard bzero function, if such a function exists on
103/// the current subtarget and it is considered prefereable over
104/// memset with zero passed as the second argument. Otherwise it
105/// returns null.
106const char *AArch64Subtarget::getBZeroEntry() const {
107 // Prefer bzero on Darwin only.
108 if(isTargetDarwin())
109 return "bzero";
110
111 return nullptr;
112}
113
114void AArch64Subtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
115 MachineInstr *begin, MachineInstr *end,
116 unsigned NumRegionInstrs) const {
117 // LNT run (at least on Cyclone) showed reasonably significant gains for
118 // bi-directional scheduling. 253.perlbmk.
119 Policy.OnlyTopDown = false;
120 Policy.OnlyBottomUp = false;
121}
122
123bool AArch64Subtarget::enableEarlyIfConversion() const {
124 return EnableEarlyIfConvert;
125}
Lang Hames8f31f442014-10-09 18:20:51 +0000126
127std::unique_ptr<PBQPRAConstraint>
128AArch64Subtarget::getCustomPBQPConstraints() const {
Arnaud A. de Grandmaison9b333052014-10-22 12:40:20 +0000129 if (!isCortexA57())
130 return nullptr;
131
132 return llvm::make_unique<A57ChainingConstraint>();
Lang Hames8f31f442014-10-09 18:20:51 +0000133}
Eric Christopher1b585ae2015-03-12 21:04:46 +0000134
135const AArch64RegisterInfo *AArch64Subtarget::getRegisterInfo() const {
136 return getTargetMachine().getRegisterInfo();
137}