blob: 2068fe31023ff1e5d1bac145df25db9b3a63dc6a [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"
Rafael Espindolaa224de02016-05-26 12:42:55 +000017#include "llvm/CodeGen/Analysis.h"
Tim Northover3b0846e2014-05-24 12:50:23 +000018#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
Tim Northover339c83e2015-11-10 00:44:23 +000034// If OS supports TBI, use this flag to enable it.
35static cl::opt<bool>
36UseAddressTopByteIgnored("aarch64-use-tbi", cl::desc("Assume that top byte of "
37 "an address is ignored"), cl::init(false), cl::Hidden);
38
Eric Christopher7c9d4e02014-06-11 00:46:34 +000039AArch64Subtarget &
40AArch64Subtarget::initializeSubtargetDependencies(StringRef FS) {
41 // Determine default and user-specified characteristics
42
43 if (CPUString.empty())
44 CPUString = "generic";
45
46 ParseSubtargetFeatures(CPUString, FS);
Matthias Braun651cff42016-06-02 18:03:53 +000047 initializeProperties();
48
Eric Christopher7c9d4e02014-06-11 00:46:34 +000049 return *this;
50}
51
Matthias Braun651cff42016-06-02 18:03:53 +000052void AArch64Subtarget::initializeProperties() {
53 // Initialize CPU specific properties. We should add a tablegen feature for
54 // this in the future so we can specify it together with the subtarget
55 // features.
56 switch (ARMProcFamily) {
57 case Cyclone:
58 CacheLineSize = 64;
59 PrefetchDistance = 280;
60 MinPrefetchStride = 2048;
61 MaxPrefetchIterationsAhead = 3;
62 break;
63 case CortexA57:
64 MaxInterleaveFactor = 4;
65 break;
Evandro Menezesa3a0a602016-06-10 16:00:18 +000066 case ExynosM1:
67 PrefFunctionAlignment = 4;
68 PrefLoopAlignment = 3;
69 break;
Matthias Braun651cff42016-06-02 18:03:53 +000070 case Kryo:
71 MaxInterleaveFactor = 4;
72 VectorInsertExtractBaseCost = 2;
Haicheng Wua783bac2016-06-21 22:47:56 +000073 CacheLineSize = 128;
74 PrefetchDistance = 740;
75 MinPrefetchStride = 1024;
76 MaxPrefetchIterationsAhead = 11;
Matthias Braun651cff42016-06-02 18:03:53 +000077 break;
Pankaj Godef4b25542016-06-30 06:42:31 +000078 case Vulcan:
79 MaxInterleaveFactor = 4;
80 break;
Matthias Braun651cff42016-06-02 18:03:53 +000081 case CortexA35: break;
82 case CortexA53: break;
Silviu Barangaaee40fc2016-06-21 15:53:54 +000083 case CortexA72: break;
84 case CortexA73: break;
Evandro Menezesa3a0a602016-06-10 16:00:18 +000085 case Others: break;
Matthias Braun651cff42016-06-02 18:03:53 +000086 }
87}
88
Daniel Sandersa73f1fd2015-06-10 12:11:26 +000089AArch64Subtarget::AArch64Subtarget(const Triple &TT, const std::string &CPU,
Eric Christopherf12e1ab2014-10-03 00:42:41 +000090 const std::string &FS,
Eric Christophera0de2532015-03-18 20:37:30 +000091 const TargetMachine &TM, bool LittleEndian)
Matthias Braun27b66922016-05-27 22:14:09 +000092 : AArch64GenSubtargetInfo(TT, CPU, FS), ReserveX18(TT.isOSDarwin()),
93 IsLittle(LittleEndian), CPUString(CPU), TargetTriple(TT), FrameLowering(),
Mehdi Amini157e5a62015-07-09 02:10:08 +000094 InstrInfo(initializeSubtargetDependencies(FS)), TSInfo(),
Tom Stellardcef0fe42016-04-14 17:45:38 +000095 TLInfo(TM, *this), GISel() {}
Quentin Colombetba2a0162016-02-16 19:26:02 +000096
97const CallLowering *AArch64Subtarget::getCallLowering() const {
Tom Stellardcef0fe42016-04-14 17:45:38 +000098 assert(GISel && "Access to GlobalISel APIs not set");
99 return GISel->getCallLowering();
Quentin Colombetc17f7442016-04-06 17:26:03 +0000100}
101
102const RegisterBankInfo *AArch64Subtarget::getRegBankInfo() const {
Tom Stellardcef0fe42016-04-14 17:45:38 +0000103 assert(GISel && "Access to GlobalISel APIs not set");
104 return GISel->getRegBankInfo();
Quentin Colombetba2a0162016-02-16 19:26:02 +0000105}
Tim Northover3b0846e2014-05-24 12:50:23 +0000106
Rafael Espindola6b93bf52016-05-25 22:44:06 +0000107/// Find the target operand flags that describe how a global value should be
108/// referenced for the current subtarget.
Tim Northover3b0846e2014-05-24 12:50:23 +0000109unsigned char
110AArch64Subtarget::ClassifyGlobalReference(const GlobalValue *GV,
Rafael Espindola6b93bf52016-05-25 22:44:06 +0000111 const TargetMachine &TM) const {
Tim Northover3b0846e2014-05-24 12:50:23 +0000112 // MachO large model always goes via a GOT, simply to get a single 8-byte
113 // absolute relocation on all global addresses.
114 if (TM.getCodeModel() == CodeModel::Large && isTargetMachO())
115 return AArch64II::MO_GOT;
116
Rafael Espindola3beef8d2016-06-27 23:15:57 +0000117 if (!TM.shouldAssumeDSOLocal(*GV->getParent(), GV))
Rafael Espindolaa224de02016-05-26 12:42:55 +0000118 return AArch64II::MO_GOT;
119
Tim Northover3b0846e2014-05-24 12:50:23 +0000120 // The small code mode's direct accesses use ADRP, which cannot necessarily
Asiri Rathnayake369c0302014-09-10 13:54:38 +0000121 // produce the value 0 (if the code is above 4GB).
Rafael Espindola4d290992016-05-31 18:31:14 +0000122 if (TM.getCodeModel() == CodeModel::Small && GV->hasExternalWeakLinkage())
123 return AArch64II::MO_GOT;
Tim Northover3b0846e2014-05-24 12:50:23 +0000124
Tim Northover3b0846e2014-05-24 12:50:23 +0000125 return AArch64II::MO_NO_FLAG;
126}
127
128/// This function returns the name of a function which has an interface
129/// like the non-standard bzero function, if such a function exists on
130/// the current subtarget and it is considered prefereable over
131/// memset with zero passed as the second argument. Otherwise it
132/// returns null.
133const char *AArch64Subtarget::getBZeroEntry() const {
134 // Prefer bzero on Darwin only.
135 if(isTargetDarwin())
136 return "bzero";
137
138 return nullptr;
139}
140
141void AArch64Subtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
142 MachineInstr *begin, MachineInstr *end,
143 unsigned NumRegionInstrs) const {
144 // LNT run (at least on Cyclone) showed reasonably significant gains for
145 // bi-directional scheduling. 253.perlbmk.
146 Policy.OnlyTopDown = false;
147 Policy.OnlyBottomUp = false;
Matthias Braund276de62015-10-22 18:07:38 +0000148 // Enabling or Disabling the latency heuristic is a close call: It seems to
149 // help nearly no benchmark on out-of-order architectures, on the other hand
150 // it regresses register pressure on a few benchmarking.
Matthias Braun651cff42016-06-02 18:03:53 +0000151 Policy.DisableLatencyHeuristic = DisableLatencySchedHeuristic;
Tim Northover3b0846e2014-05-24 12:50:23 +0000152}
153
154bool AArch64Subtarget::enableEarlyIfConversion() const {
155 return EnableEarlyIfConvert;
156}
Lang Hames8f31f442014-10-09 18:20:51 +0000157
Tim Northover339c83e2015-11-10 00:44:23 +0000158bool AArch64Subtarget::supportsAddressTopByteIgnored() const {
159 if (!UseAddressTopByteIgnored)
160 return false;
161
162 if (TargetTriple.isiOS()) {
163 unsigned Major, Minor, Micro;
164 TargetTriple.getiOSVersion(Major, Minor, Micro);
165 return Major >= 8;
166 }
167
168 return false;
169}
170
Lang Hames8f31f442014-10-09 18:20:51 +0000171std::unique_ptr<PBQPRAConstraint>
172AArch64Subtarget::getCustomPBQPConstraints() const {
Matthias Braun651cff42016-06-02 18:03:53 +0000173 return balanceFPOps() ? llvm::make_unique<A57ChainingConstraint>() : nullptr;
Lang Hames8f31f442014-10-09 18:20:51 +0000174}