blob: e6ef6dc80e24aafc39d3e3f65efd044a3130330a [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"
17#include "llvm/ADT/SmallVector.h"
18#include "llvm/CodeGen/MachineScheduler.h"
19#include "llvm/IR/GlobalValue.h"
20#include "llvm/Support/TargetRegistry.h"
21
22using namespace llvm;
23
24#define DEBUG_TYPE "aarch64-subtarget"
25
26#define GET_SUBTARGETINFO_CTOR
27#define GET_SUBTARGETINFO_TARGET_DESC
28#include "AArch64GenSubtargetInfo.inc"
29
30static cl::opt<bool>
31EnableEarlyIfConvert("aarch64-early-ifcvt", cl::desc("Enable the early if "
32 "converter pass"), cl::init(true), cl::Hidden);
33
Eric Christopher7c9d4e02014-06-11 00:46:34 +000034AArch64Subtarget &
35AArch64Subtarget::initializeSubtargetDependencies(StringRef FS) {
36 // Determine default and user-specified characteristics
37
38 if (CPUString.empty())
39 CPUString = "generic";
40
41 ParseSubtargetFeatures(CPUString, FS);
42 return *this;
43}
44
Daniel Sandersa73f1fd2015-06-10 12:11:26 +000045AArch64Subtarget::AArch64Subtarget(const Triple &TT, const std::string &CPU,
Eric Christopherf12e1ab2014-10-03 00:42:41 +000046 const std::string &FS,
Eric Christophera0de2532015-03-18 20:37:30 +000047 const TargetMachine &TM, bool LittleEndian)
Daniel Sanders50f17232015-09-15 16:17:27 +000048 : AArch64GenSubtargetInfo(TT, CPU, FS), ARMProcFamily(Others),
Daniel Sandersa73f1fd2015-06-10 12:11:26 +000049 HasV8_1aOps(false), HasFPARMv8(false), HasNEON(false), HasCrypto(false),
Ahmed Bougachab0ff6432015-09-01 16:23:45 +000050 HasCRC(false), HasPerfMon(false), HasZeroCycleRegMove(false),
51 HasZeroCycleZeroing(false), StrictAlign(false), ReserveX18(false),
52 IsLittle(LittleEndian), CPUString(CPU), TargetTriple(TT), FrameLowering(),
Mehdi Amini157e5a62015-07-09 02:10:08 +000053 InstrInfo(initializeSubtargetDependencies(FS)), TSInfo(),
54 TLInfo(TM, *this) {}
Tim Northover3b0846e2014-05-24 12:50:23 +000055
56/// ClassifyGlobalReference - Find the target operand flags that describe
57/// how a global value should be referenced for the current subtarget.
58unsigned char
59AArch64Subtarget::ClassifyGlobalReference(const GlobalValue *GV,
60 const TargetMachine &TM) const {
Peter Collingbourne6a9d1772015-07-05 20:52:35 +000061 bool isDef = GV->isStrongDefinitionForLinker();
Tim Northover3b0846e2014-05-24 12:50:23 +000062
63 // MachO large model always goes via a GOT, simply to get a single 8-byte
64 // absolute relocation on all global addresses.
65 if (TM.getCodeModel() == CodeModel::Large && isTargetMachO())
66 return AArch64II::MO_GOT;
67
68 // The small code mode's direct accesses use ADRP, which cannot necessarily
Asiri Rathnayake369c0302014-09-10 13:54:38 +000069 // produce the value 0 (if the code is above 4GB).
Peter Collingbourne6a9d1772015-07-05 20:52:35 +000070 if (TM.getCodeModel() == CodeModel::Small && GV->hasExternalWeakLinkage()) {
Asiri Rathnayake369c0302014-09-10 13:54:38 +000071 // In PIC mode use the GOT, but in absolute mode use a constant pool load.
72 if (TM.getRelocationModel() == Reloc::Static)
73 return AArch64II::MO_CONSTPOOL;
74 else
75 return AArch64II::MO_GOT;
76 }
Tim Northover3b0846e2014-05-24 12:50:23 +000077
78 // If symbol visibility is hidden, the extra load is not needed if
79 // the symbol is definitely defined in the current translation unit.
80
81 // The handling of non-hidden symbols in PIC mode is rather target-dependent:
82 // + On MachO, if the symbol is defined in this module the GOT can be
83 // skipped.
84 // + On ELF, the R_AARCH64_COPY relocation means that even symbols actually
85 // defined could end up in unexpected places. Use a GOT.
86 if (TM.getRelocationModel() != Reloc::Static && GV->hasDefaultVisibility()) {
87 if (isTargetMachO())
Peter Collingbourne6a9d1772015-07-05 20:52:35 +000088 return isDef ? AArch64II::MO_NO_FLAG : AArch64II::MO_GOT;
Tim Northover3b0846e2014-05-24 12:50:23 +000089 else
90 // No need to go through the GOT for local symbols on ELF.
91 return GV->hasLocalLinkage() ? AArch64II::MO_NO_FLAG : AArch64II::MO_GOT;
92 }
93
94 return AArch64II::MO_NO_FLAG;
95}
96
97/// This function returns the name of a function which has an interface
98/// like the non-standard bzero function, if such a function exists on
99/// the current subtarget and it is considered prefereable over
100/// memset with zero passed as the second argument. Otherwise it
101/// returns null.
102const char *AArch64Subtarget::getBZeroEntry() const {
103 // Prefer bzero on Darwin only.
104 if(isTargetDarwin())
105 return "bzero";
106
107 return nullptr;
108}
109
110void AArch64Subtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
111 MachineInstr *begin, MachineInstr *end,
112 unsigned NumRegionInstrs) const {
113 // LNT run (at least on Cyclone) showed reasonably significant gains for
114 // bi-directional scheduling. 253.perlbmk.
115 Policy.OnlyTopDown = false;
116 Policy.OnlyBottomUp = false;
Matthias Braund276de62015-10-22 18:07:38 +0000117 // Enabling or Disabling the latency heuristic is a close call: It seems to
118 // help nearly no benchmark on out-of-order architectures, on the other hand
119 // it regresses register pressure on a few benchmarking.
120 if (isCyclone())
121 Policy.DisableLatencyHeuristic = true;
Tim Northover3b0846e2014-05-24 12:50:23 +0000122}
123
124bool AArch64Subtarget::enableEarlyIfConversion() const {
125 return EnableEarlyIfConvert;
126}
Lang Hames8f31f442014-10-09 18:20:51 +0000127
128std::unique_ptr<PBQPRAConstraint>
129AArch64Subtarget::getCustomPBQPConstraints() const {
Arnaud A. de Grandmaison9b333052014-10-22 12:40:20 +0000130 if (!isCortexA57())
131 return nullptr;
132
133 return llvm::make_unique<A57ChainingConstraint>();
Lang Hames8f31f442014-10-09 18:20:51 +0000134}