blob: 3c193bab70a24ae3253615e56692e15e50818f12 [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 &
Matthias Brauna827ed82016-10-03 20:17:02 +000039AArch64Subtarget::initializeSubtargetDependencies(StringRef FS,
40 StringRef CPUString) {
Eric Christopher7c9d4e02014-06-11 00:46:34 +000041 // 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:
Abderrazek Zaafrani9daf8112016-10-21 16:28:27 +000067 MaxInterleaveFactor = 4;
Evandro Menezesa3a0a602016-06-10 16:00:18 +000068 PrefFunctionAlignment = 4;
69 PrefLoopAlignment = 3;
Evandro Menezese45de8a2016-09-26 15:32:33 +000070 MaxJumpTableSize = 12;
Evandro Menezesa3a0a602016-06-10 16:00:18 +000071 break;
Matthias Braun651cff42016-06-02 18:03:53 +000072 case Kryo:
73 MaxInterleaveFactor = 4;
74 VectorInsertExtractBaseCost = 2;
Haicheng Wua783bac2016-06-21 22:47:56 +000075 CacheLineSize = 128;
76 PrefetchDistance = 740;
77 MinPrefetchStride = 1024;
78 MaxPrefetchIterationsAhead = 11;
Matthias Braun651cff42016-06-02 18:03:53 +000079 break;
Junmo Park5e4bd2e2016-07-06 23:15:18 +000080 case Vulcan:
Pankaj Godef4b25542016-06-30 06:42:31 +000081 MaxInterleaveFactor = 4;
82 break;
Matthias Braun651cff42016-06-02 18:03:53 +000083 case CortexA35: break;
84 case CortexA53: break;
Silviu Barangaaee40fc2016-06-21 15:53:54 +000085 case CortexA72: break;
86 case CortexA73: break;
Evandro Menezesa3a0a602016-06-10 16:00:18 +000087 case Others: break;
Matthias Braun651cff42016-06-02 18:03:53 +000088 }
89}
90
Daniel Sandersa73f1fd2015-06-10 12:11:26 +000091AArch64Subtarget::AArch64Subtarget(const Triple &TT, const std::string &CPU,
Eric Christopherf12e1ab2014-10-03 00:42:41 +000092 const std::string &FS,
Eric Christophera0de2532015-03-18 20:37:30 +000093 const TargetMachine &TM, bool LittleEndian)
Matthias Braun27b66922016-05-27 22:14:09 +000094 : AArch64GenSubtargetInfo(TT, CPU, FS), ReserveX18(TT.isOSDarwin()),
Matthias Brauna827ed82016-10-03 20:17:02 +000095 IsLittle(LittleEndian), TargetTriple(TT), FrameLowering(),
96 InstrInfo(initializeSubtargetDependencies(FS, CPU)), TSInfo(),
Tom Stellardcef0fe42016-04-14 17:45:38 +000097 TLInfo(TM, *this), GISel() {}
Quentin Colombetba2a0162016-02-16 19:26:02 +000098
99const CallLowering *AArch64Subtarget::getCallLowering() const {
Tom Stellardcef0fe42016-04-14 17:45:38 +0000100 assert(GISel && "Access to GlobalISel APIs not set");
101 return GISel->getCallLowering();
Quentin Colombetc17f7442016-04-06 17:26:03 +0000102}
103
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000104const InstructionSelector *AArch64Subtarget::getInstructionSelector() const {
105 assert(GISel && "Access to GlobalISel APIs not set");
106 return GISel->getInstructionSelector();
107}
108
Tim Northover69fa84a2016-10-14 22:18:18 +0000109const LegalizerInfo *AArch64Subtarget::getLegalizerInfo() const {
Tim Northover33b07d62016-07-22 20:03:43 +0000110 assert(GISel && "Access to GlobalISel APIs not set");
Tim Northover69fa84a2016-10-14 22:18:18 +0000111 return GISel->getLegalizerInfo();
Tim Northover33b07d62016-07-22 20:03:43 +0000112}
113
Quentin Colombetc17f7442016-04-06 17:26:03 +0000114const RegisterBankInfo *AArch64Subtarget::getRegBankInfo() const {
Tom Stellardcef0fe42016-04-14 17:45:38 +0000115 assert(GISel && "Access to GlobalISel APIs not set");
116 return GISel->getRegBankInfo();
Quentin Colombetba2a0162016-02-16 19:26:02 +0000117}
Tim Northover3b0846e2014-05-24 12:50:23 +0000118
Rafael Espindola6b93bf52016-05-25 22:44:06 +0000119/// Find the target operand flags that describe how a global value should be
120/// referenced for the current subtarget.
Tim Northover3b0846e2014-05-24 12:50:23 +0000121unsigned char
122AArch64Subtarget::ClassifyGlobalReference(const GlobalValue *GV,
Rafael Espindola6b93bf52016-05-25 22:44:06 +0000123 const TargetMachine &TM) const {
Tim Northover3b0846e2014-05-24 12:50:23 +0000124 // MachO large model always goes via a GOT, simply to get a single 8-byte
125 // absolute relocation on all global addresses.
126 if (TM.getCodeModel() == CodeModel::Large && isTargetMachO())
127 return AArch64II::MO_GOT;
128
Rafael Espindola3beef8d2016-06-27 23:15:57 +0000129 if (!TM.shouldAssumeDSOLocal(*GV->getParent(), GV))
Rafael Espindolaa224de02016-05-26 12:42:55 +0000130 return AArch64II::MO_GOT;
131
Tim Northover3b0846e2014-05-24 12:50:23 +0000132 // The small code mode's direct accesses use ADRP, which cannot necessarily
Asiri Rathnayake369c0302014-09-10 13:54:38 +0000133 // produce the value 0 (if the code is above 4GB).
Rafael Espindola4d290992016-05-31 18:31:14 +0000134 if (TM.getCodeModel() == CodeModel::Small && GV->hasExternalWeakLinkage())
135 return AArch64II::MO_GOT;
Tim Northover3b0846e2014-05-24 12:50:23 +0000136
Tim Northover3b0846e2014-05-24 12:50:23 +0000137 return AArch64II::MO_NO_FLAG;
138}
139
140/// This function returns the name of a function which has an interface
141/// like the non-standard bzero function, if such a function exists on
142/// the current subtarget and it is considered prefereable over
143/// memset with zero passed as the second argument. Otherwise it
144/// returns null.
145const char *AArch64Subtarget::getBZeroEntry() const {
146 // Prefer bzero on Darwin only.
147 if(isTargetDarwin())
148 return "bzero";
149
150 return nullptr;
151}
152
153void AArch64Subtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
Duncan P. N. Exon Smith63298722016-07-01 00:23:27 +0000154 unsigned NumRegionInstrs) const {
Tim Northover3b0846e2014-05-24 12:50:23 +0000155 // LNT run (at least on Cyclone) showed reasonably significant gains for
156 // bi-directional scheduling. 253.perlbmk.
157 Policy.OnlyTopDown = false;
158 Policy.OnlyBottomUp = false;
Matthias Braund276de62015-10-22 18:07:38 +0000159 // Enabling or Disabling the latency heuristic is a close call: It seems to
160 // help nearly no benchmark on out-of-order architectures, on the other hand
161 // it regresses register pressure on a few benchmarking.
Matthias Braun651cff42016-06-02 18:03:53 +0000162 Policy.DisableLatencyHeuristic = DisableLatencySchedHeuristic;
Tim Northover3b0846e2014-05-24 12:50:23 +0000163}
164
165bool AArch64Subtarget::enableEarlyIfConversion() const {
166 return EnableEarlyIfConvert;
167}
Lang Hames8f31f442014-10-09 18:20:51 +0000168
Tim Northover339c83e2015-11-10 00:44:23 +0000169bool AArch64Subtarget::supportsAddressTopByteIgnored() const {
170 if (!UseAddressTopByteIgnored)
171 return false;
172
173 if (TargetTriple.isiOS()) {
174 unsigned Major, Minor, Micro;
175 TargetTriple.getiOSVersion(Major, Minor, Micro);
176 return Major >= 8;
177 }
178
179 return false;
180}
181
Lang Hames8f31f442014-10-09 18:20:51 +0000182std::unique_ptr<PBQPRAConstraint>
183AArch64Subtarget::getCustomPBQPConstraints() const {
Matthias Braun651cff42016-06-02 18:03:53 +0000184 return balanceFPOps() ? llvm::make_unique<A57ChainingConstraint>() : nullptr;
Lang Hames8f31f442014-10-09 18:20:51 +0000185}