blob: 7d8aa0c948561205ea7fe004927a3a42a82e70ab [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);
47 return *this;
48}
49
Daniel Sandersa73f1fd2015-06-10 12:11:26 +000050AArch64Subtarget::AArch64Subtarget(const Triple &TT, const std::string &CPU,
Eric Christopherf12e1ab2014-10-03 00:42:41 +000051 const std::string &FS,
Eric Christophera0de2532015-03-18 20:37:30 +000052 const TargetMachine &TM, bool LittleEndian)
Daniel Sanders50f17232015-09-15 16:17:27 +000053 : AArch64GenSubtargetInfo(TT, CPU, FS), ARMProcFamily(Others),
Oliver Stannard7cc0c4e2015-11-26 15:23:32 +000054 HasV8_1aOps(false), HasV8_2aOps(false), HasFPARMv8(false), HasNEON(false),
55 HasCrypto(false), HasCRC(false), HasPerfMon(false), HasFullFP16(false),
56 HasZeroCycleRegMove(false), HasZeroCycleZeroing(false),
57 StrictAlign(false), ReserveX18(TT.isOSDarwin()), IsLittle(LittleEndian),
58 CPUString(CPU), TargetTriple(TT), FrameLowering(),
Mehdi Amini157e5a62015-07-09 02:10:08 +000059 InstrInfo(initializeSubtargetDependencies(FS)), TSInfo(),
Tom Stellardcef0fe42016-04-14 17:45:38 +000060 TLInfo(TM, *this), GISel() {}
Quentin Colombetba2a0162016-02-16 19:26:02 +000061
62const CallLowering *AArch64Subtarget::getCallLowering() const {
Tom Stellardcef0fe42016-04-14 17:45:38 +000063 assert(GISel && "Access to GlobalISel APIs not set");
64 return GISel->getCallLowering();
Quentin Colombetc17f7442016-04-06 17:26:03 +000065}
66
67const RegisterBankInfo *AArch64Subtarget::getRegBankInfo() const {
Tom Stellardcef0fe42016-04-14 17:45:38 +000068 assert(GISel && "Access to GlobalISel APIs not set");
69 return GISel->getRegBankInfo();
Quentin Colombetba2a0162016-02-16 19:26:02 +000070}
Tim Northover3b0846e2014-05-24 12:50:23 +000071
Rafael Espindola6b93bf52016-05-25 22:44:06 +000072/// Find the target operand flags that describe how a global value should be
73/// referenced for the current subtarget.
Tim Northover3b0846e2014-05-24 12:50:23 +000074unsigned char
75AArch64Subtarget::ClassifyGlobalReference(const GlobalValue *GV,
Rafael Espindola6b93bf52016-05-25 22:44:06 +000076 const TargetMachine &TM) const {
Tim Northover3b0846e2014-05-24 12:50:23 +000077 // MachO large model always goes via a GOT, simply to get a single 8-byte
78 // absolute relocation on all global addresses.
79 if (TM.getCodeModel() == CodeModel::Large && isTargetMachO())
80 return AArch64II::MO_GOT;
81
Rafael Espindolaa224de02016-05-26 12:42:55 +000082 Reloc::Model RM = TM.getRelocationModel();
83 if (!shouldAssumeDSOLocal(RM, TargetTriple, *GV->getParent(), GV))
84 return AArch64II::MO_GOT;
85
Tim Northover3b0846e2014-05-24 12:50:23 +000086 // The small code mode's direct accesses use ADRP, which cannot necessarily
Asiri Rathnayake369c0302014-09-10 13:54:38 +000087 // produce the value 0 (if the code is above 4GB).
Peter Collingbourne6a9d1772015-07-05 20:52:35 +000088 if (TM.getCodeModel() == CodeModel::Small && GV->hasExternalWeakLinkage()) {
Asiri Rathnayake369c0302014-09-10 13:54:38 +000089 // In PIC mode use the GOT, but in absolute mode use a constant pool load.
Rafael Espindolaa224de02016-05-26 12:42:55 +000090 if (RM == Reloc::Static)
Rafael Espindola6b93bf52016-05-25 22:44:06 +000091 return AArch64II::MO_CONSTPOOL;
Asiri Rathnayake369c0302014-09-10 13:54:38 +000092 else
Rafael Espindola6b93bf52016-05-25 22:44:06 +000093 return AArch64II::MO_GOT;
Asiri Rathnayake369c0302014-09-10 13:54:38 +000094 }
Tim Northover3b0846e2014-05-24 12:50:23 +000095
Tim Northover3b0846e2014-05-24 12:50:23 +000096 return AArch64II::MO_NO_FLAG;
97}
98
99/// This function returns the name of a function which has an interface
100/// like the non-standard bzero function, if such a function exists on
101/// the current subtarget and it is considered prefereable over
102/// memset with zero passed as the second argument. Otherwise it
103/// returns null.
104const char *AArch64Subtarget::getBZeroEntry() const {
105 // Prefer bzero on Darwin only.
106 if(isTargetDarwin())
107 return "bzero";
108
109 return nullptr;
110}
111
112void AArch64Subtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
113 MachineInstr *begin, MachineInstr *end,
114 unsigned NumRegionInstrs) const {
115 // LNT run (at least on Cyclone) showed reasonably significant gains for
116 // bi-directional scheduling. 253.perlbmk.
117 Policy.OnlyTopDown = false;
118 Policy.OnlyBottomUp = false;
Matthias Braund276de62015-10-22 18:07:38 +0000119 // Enabling or Disabling the latency heuristic is a close call: It seems to
120 // help nearly no benchmark on out-of-order architectures, on the other hand
121 // it regresses register pressure on a few benchmarking.
122 if (isCyclone())
123 Policy.DisableLatencyHeuristic = true;
Tim Northover3b0846e2014-05-24 12:50:23 +0000124}
125
126bool AArch64Subtarget::enableEarlyIfConversion() const {
127 return EnableEarlyIfConvert;
128}
Lang Hames8f31f442014-10-09 18:20:51 +0000129
Tim Northover339c83e2015-11-10 00:44:23 +0000130bool AArch64Subtarget::supportsAddressTopByteIgnored() const {
131 if (!UseAddressTopByteIgnored)
132 return false;
133
134 if (TargetTriple.isiOS()) {
135 unsigned Major, Minor, Micro;
136 TargetTriple.getiOSVersion(Major, Minor, Micro);
137 return Major >= 8;
138 }
139
140 return false;
141}
142
Lang Hames8f31f442014-10-09 18:20:51 +0000143std::unique_ptr<PBQPRAConstraint>
144AArch64Subtarget::getCustomPBQPConstraints() const {
Arnaud A. de Grandmaison9b333052014-10-22 12:40:20 +0000145 if (!isCortexA57())
146 return nullptr;
147
148 return llvm::make_unique<A57ChainingConstraint>();
Lang Hames8f31f442014-10-09 18:20:51 +0000149}