blob: cde6e4438fc7a13e34ece2f3addadc3e92229d92 [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
Rafael Espindola6b4baa52016-05-25 21:37:29 +000014#include "AArch64Subtarget.h"
Tim Northover3b0846e2014-05-24 12:50:23 +000015#include "AArch64InstrInfo.h"
Lang Hames8f31f442014-10-09 18:20:51 +000016#include "AArch64PBQPRegAlloc.h"
Tim Northover3b0846e2014-05-24 12:50:23 +000017#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
Tim Northover339c83e2015-11-10 00:44:23 +000033// If OS supports TBI, use this flag to enable it.
34static cl::opt<bool>
35UseAddressTopByteIgnored("aarch64-use-tbi", cl::desc("Assume that top byte of "
36 "an address is ignored"), cl::init(false), cl::Hidden);
37
Eric Christopher7c9d4e02014-06-11 00:46:34 +000038AArch64Subtarget &
39AArch64Subtarget::initializeSubtargetDependencies(StringRef FS) {
40 // Determine default and user-specified characteristics
41
42 if (CPUString.empty())
43 CPUString = "generic";
44
45 ParseSubtargetFeatures(CPUString, FS);
Matthias Braun651cff42016-06-02 18:03:53 +000046 initializeProperties();
47
Eric Christopher7c9d4e02014-06-11 00:46:34 +000048 return *this;
49}
50
Matthias Braun651cff42016-06-02 18:03:53 +000051void AArch64Subtarget::initializeProperties() {
52 // Initialize CPU specific properties. We should add a tablegen feature for
53 // this in the future so we can specify it together with the subtarget
54 // features.
55 switch (ARMProcFamily) {
56 case Cyclone:
57 CacheLineSize = 64;
58 PrefetchDistance = 280;
59 MinPrefetchStride = 2048;
60 MaxPrefetchIterationsAhead = 3;
61 break;
62 case CortexA57:
63 MaxInterleaveFactor = 4;
64 break;
Evandro Menezesa3a0a602016-06-10 16:00:18 +000065 case ExynosM1:
66 PrefFunctionAlignment = 4;
67 PrefLoopAlignment = 3;
68 break;
Matthias Braun651cff42016-06-02 18:03:53 +000069 case Kryo:
70 MaxInterleaveFactor = 4;
71 VectorInsertExtractBaseCost = 2;
Haicheng Wua783bac2016-06-21 22:47:56 +000072 CacheLineSize = 128;
73 PrefetchDistance = 740;
74 MinPrefetchStride = 1024;
75 MaxPrefetchIterationsAhead = 11;
Matthias Braun651cff42016-06-02 18:03:53 +000076 break;
Pankaj Godef4b25542016-06-30 06:42:31 +000077 case Vulcan:
78 MaxInterleaveFactor = 4;
79 break;
Matthias Braun651cff42016-06-02 18:03:53 +000080 case CortexA35: break;
81 case CortexA53: break;
Silviu Barangaaee40fc2016-06-21 15:53:54 +000082 case CortexA72: break;
83 case CortexA73: break;
Evandro Menezesa3a0a602016-06-10 16:00:18 +000084 case Others: break;
Matthias Braun651cff42016-06-02 18:03:53 +000085 }
86}
87
Daniel Sandersa73f1fd2015-06-10 12:11:26 +000088AArch64Subtarget::AArch64Subtarget(const Triple &TT, const std::string &CPU,
Eric Christopherf12e1ab2014-10-03 00:42:41 +000089 const std::string &FS,
Eric Christophera0de2532015-03-18 20:37:30 +000090 const TargetMachine &TM, bool LittleEndian)
Matthias Braun27b66922016-05-27 22:14:09 +000091 : AArch64GenSubtargetInfo(TT, CPU, FS), ReserveX18(TT.isOSDarwin()),
92 IsLittle(LittleEndian), CPUString(CPU), TargetTriple(TT), FrameLowering(),
Mehdi Amini157e5a62015-07-09 02:10:08 +000093 InstrInfo(initializeSubtargetDependencies(FS)), TSInfo(),
Tom Stellardcef0fe42016-04-14 17:45:38 +000094 TLInfo(TM, *this), GISel() {}
Quentin Colombetba2a0162016-02-16 19:26:02 +000095
96const CallLowering *AArch64Subtarget::getCallLowering() const {
Tom Stellardcef0fe42016-04-14 17:45:38 +000097 assert(GISel && "Access to GlobalISel APIs not set");
98 return GISel->getCallLowering();
Quentin Colombetc17f7442016-04-06 17:26:03 +000099}
100
101const RegisterBankInfo *AArch64Subtarget::getRegBankInfo() const {
Tom Stellardcef0fe42016-04-14 17:45:38 +0000102 assert(GISel && "Access to GlobalISel APIs not set");
103 return GISel->getRegBankInfo();
Quentin Colombetba2a0162016-02-16 19:26:02 +0000104}
Tim Northover3b0846e2014-05-24 12:50:23 +0000105
Rafael Espindola6b93bf52016-05-25 22:44:06 +0000106/// Find the target operand flags that describe how a global value should be
107/// referenced for the current subtarget.
Tim Northover3b0846e2014-05-24 12:50:23 +0000108unsigned char
109AArch64Subtarget::ClassifyGlobalReference(const GlobalValue *GV,
Rafael Espindola6b93bf52016-05-25 22:44:06 +0000110 const TargetMachine &TM) const {
Tim Northover3b0846e2014-05-24 12:50:23 +0000111 // MachO large model always goes via a GOT, simply to get a single 8-byte
112 // absolute relocation on all global addresses.
113 if (TM.getCodeModel() == CodeModel::Large && isTargetMachO())
114 return AArch64II::MO_GOT;
115
Rafael Espindola3beef8d2016-06-27 23:15:57 +0000116 if (!TM.shouldAssumeDSOLocal(*GV->getParent(), GV))
Rafael Espindolaa224de02016-05-26 12:42:55 +0000117 return AArch64II::MO_GOT;
118
Tim Northover3b0846e2014-05-24 12:50:23 +0000119 // The small code mode's direct accesses use ADRP, which cannot necessarily
Asiri Rathnayake369c0302014-09-10 13:54:38 +0000120 // produce the value 0 (if the code is above 4GB).
Rafael Espindola4d290992016-05-31 18:31:14 +0000121 if (TM.getCodeModel() == CodeModel::Small && GV->hasExternalWeakLinkage())
122 return AArch64II::MO_GOT;
Tim Northover3b0846e2014-05-24 12:50:23 +0000123
Tim Northover3b0846e2014-05-24 12:50:23 +0000124 return AArch64II::MO_NO_FLAG;
125}
126
127/// This function returns the name of a function which has an interface
128/// like the non-standard bzero function, if such a function exists on
129/// the current subtarget and it is considered prefereable over
130/// memset with zero passed as the second argument. Otherwise it
131/// returns null.
132const char *AArch64Subtarget::getBZeroEntry() const {
133 // Prefer bzero on Darwin only.
134 if(isTargetDarwin())
135 return "bzero";
136
137 return nullptr;
138}
139
140void AArch64Subtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
141 MachineInstr *begin, MachineInstr *end,
142 unsigned NumRegionInstrs) const {
143 // LNT run (at least on Cyclone) showed reasonably significant gains for
144 // bi-directional scheduling. 253.perlbmk.
145 Policy.OnlyTopDown = false;
146 Policy.OnlyBottomUp = false;
Matthias Braund276de62015-10-22 18:07:38 +0000147 // Enabling or Disabling the latency heuristic is a close call: It seems to
148 // help nearly no benchmark on out-of-order architectures, on the other hand
149 // it regresses register pressure on a few benchmarking.
Matthias Braun651cff42016-06-02 18:03:53 +0000150 Policy.DisableLatencyHeuristic = DisableLatencySchedHeuristic;
Tim Northover3b0846e2014-05-24 12:50:23 +0000151}
152
153bool AArch64Subtarget::enableEarlyIfConversion() const {
154 return EnableEarlyIfConvert;
155}
Lang Hames8f31f442014-10-09 18:20:51 +0000156
Tim Northover339c83e2015-11-10 00:44:23 +0000157bool AArch64Subtarget::supportsAddressTopByteIgnored() const {
158 if (!UseAddressTopByteIgnored)
159 return false;
160
161 if (TargetTriple.isiOS()) {
162 unsigned Major, Minor, Micro;
163 TargetTriple.getiOSVersion(Major, Minor, Micro);
164 return Major >= 8;
165 }
166
167 return false;
168}
169
Lang Hames8f31f442014-10-09 18:20:51 +0000170std::unique_ptr<PBQPRAConstraint>
171AArch64Subtarget::getCustomPBQPConstraints() const {
Matthias Braun651cff42016-06-02 18:03:53 +0000172 return balanceFPOps() ? llvm::make_unique<A57ChainingConstraint>() : nullptr;
Lang Hames8f31f442014-10-09 18:20:51 +0000173}