]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Target/AArch64/AArch64Subtarget.cpp
Merge llvm, clang, lld, lldb, compiler-rt and libc++ r302069, and update
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / Target / AArch64 / AArch64Subtarget.cpp
1 //===-- 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 "AArch64Subtarget.h"
15
16 #include "AArch64.h"
17 #include "AArch64InstrInfo.h"
18 #include "AArch64PBQPRegAlloc.h"
19 #include "AArch64TargetMachine.h"
20
21 #ifdef LLVM_BUILD_GLOBAL_ISEL
22 #include "AArch64CallLowering.h"
23 #include "AArch64LegalizerInfo.h"
24 #include "AArch64RegisterBankInfo.h"
25 #include "llvm/CodeGen/GlobalISel/GISelAccessor.h"
26 #include "llvm/CodeGen/GlobalISel/IRTranslator.h"
27 #include "llvm/CodeGen/GlobalISel/InstructionSelect.h"
28 #include "llvm/CodeGen/GlobalISel/Legalizer.h"
29 #include "llvm/CodeGen/GlobalISel/RegBankSelect.h"
30 #endif
31 #include "llvm/CodeGen/MachineScheduler.h"
32 #include "llvm/IR/GlobalValue.h"
33 #include "llvm/Support/TargetRegistry.h"
34
35 using namespace llvm;
36
37 #define DEBUG_TYPE "aarch64-subtarget"
38
39 #define GET_SUBTARGETINFO_CTOR
40 #define GET_SUBTARGETINFO_TARGET_DESC
41 #include "AArch64GenSubtargetInfo.inc"
42
43 static cl::opt<bool>
44 EnableEarlyIfConvert("aarch64-early-ifcvt", cl::desc("Enable the early if "
45                      "converter pass"), cl::init(true), cl::Hidden);
46
47 // If OS supports TBI, use this flag to enable it.
48 static cl::opt<bool>
49 UseAddressTopByteIgnored("aarch64-use-tbi", cl::desc("Assume that top byte of "
50                          "an address is ignored"), cl::init(false), cl::Hidden);
51
52 static cl::opt<bool>
53     UseNonLazyBind("aarch64-enable-nonlazybind",
54                    cl::desc("Call nonlazybind functions via direct GOT load"),
55                    cl::init(false), cl::Hidden);
56
57 AArch64Subtarget &
58 AArch64Subtarget::initializeSubtargetDependencies(StringRef FS,
59                                                   StringRef CPUString) {
60   // Determine default and user-specified characteristics
61
62   if (CPUString.empty())
63     CPUString = "generic";
64
65   ParseSubtargetFeatures(CPUString, FS);
66   initializeProperties();
67
68   return *this;
69 }
70
71 void AArch64Subtarget::initializeProperties() {
72   // Initialize CPU specific properties. We should add a tablegen feature for
73   // this in the future so we can specify it together with the subtarget
74   // features.
75   switch (ARMProcFamily) {
76   case Cyclone:
77     CacheLineSize = 64;
78     PrefetchDistance = 280;
79     MinPrefetchStride = 2048;
80     MaxPrefetchIterationsAhead = 3;
81     break;
82   case CortexA57:
83     MaxInterleaveFactor = 4;
84     break;
85   case ExynosM1:
86     MaxInterleaveFactor = 4;
87     MaxJumpTableSize = 8;
88     PrefFunctionAlignment = 4;
89     PrefLoopAlignment = 3;
90     break;
91   case Falkor:
92     MaxInterleaveFactor = 4;
93     VectorInsertExtractBaseCost = 2;
94     break;
95   case Kryo:
96     MaxInterleaveFactor = 4;
97     VectorInsertExtractBaseCost = 2;
98     CacheLineSize = 128;
99     PrefetchDistance = 740;
100     MinPrefetchStride = 1024;
101     MaxPrefetchIterationsAhead = 11;
102     break;
103   case ThunderX2T99:
104     CacheLineSize = 64;
105     PrefFunctionAlignment = 3;
106     PrefLoopAlignment = 2;
107     MaxInterleaveFactor = 4;
108     PrefetchDistance = 128;
109     MinPrefetchStride = 1024;
110     MaxPrefetchIterationsAhead = 4;
111     break;
112   case ThunderX:
113   case ThunderXT88:
114   case ThunderXT81:
115   case ThunderXT83:
116     CacheLineSize = 128;
117     PrefFunctionAlignment = 3;
118     PrefLoopAlignment = 2;
119     break;
120   case CortexA35: break;
121   case CortexA53: break;
122   case CortexA72: break;
123   case CortexA73: break;
124   case Others: break;
125   }
126 }
127
128 #ifdef LLVM_BUILD_GLOBAL_ISEL
129 namespace {
130
131 struct AArch64GISelActualAccessor : public GISelAccessor {
132   std::unique_ptr<CallLowering> CallLoweringInfo;
133   std::unique_ptr<InstructionSelector> InstSelector;
134   std::unique_ptr<LegalizerInfo> Legalizer;
135   std::unique_ptr<RegisterBankInfo> RegBankInfo;
136
137   const CallLowering *getCallLowering() const override {
138     return CallLoweringInfo.get();
139   }
140
141   const InstructionSelector *getInstructionSelector() const override {
142     return InstSelector.get();
143   }
144
145   const LegalizerInfo *getLegalizerInfo() const override {
146     return Legalizer.get();
147   }
148
149   const RegisterBankInfo *getRegBankInfo() const override {
150     return RegBankInfo.get();
151   }
152 };
153
154 } // end anonymous namespace
155 #endif
156
157 AArch64Subtarget::AArch64Subtarget(const Triple &TT, const std::string &CPU,
158                                    const std::string &FS,
159                                    const TargetMachine &TM, bool LittleEndian,
160                                    bool ForCodeSize)
161     : AArch64GenSubtargetInfo(TT, CPU, FS), ReserveX18(TT.isOSDarwin()),
162       IsLittle(LittleEndian), TargetTriple(TT), FrameLowering(),
163       InstrInfo(initializeSubtargetDependencies(FS, CPU)), TSInfo(),
164       TLInfo(TM, *this), GISel(), ForCodeSize(ForCodeSize) {
165 #ifndef LLVM_BUILD_GLOBAL_ISEL
166   GISelAccessor *AArch64GISel = new GISelAccessor();
167 #else
168   AArch64GISelActualAccessor *AArch64GISel = new AArch64GISelActualAccessor();
169   AArch64GISel->CallLoweringInfo.reset(
170       new AArch64CallLowering(*getTargetLowering()));
171   AArch64GISel->Legalizer.reset(new AArch64LegalizerInfo());
172
173   auto *RBI = new AArch64RegisterBankInfo(*getRegisterInfo());
174
175   // FIXME: At this point, we can't rely on Subtarget having RBI.
176   // It's awkward to mix passing RBI and the Subtarget; should we pass
177   // TII/TRI as well?
178   AArch64GISel->InstSelector.reset(createAArch64InstructionSelector(
179       *static_cast<const AArch64TargetMachine *>(&TM), *this, *RBI));
180
181   AArch64GISel->RegBankInfo.reset(RBI);
182 #endif
183   setGISelAccessor(*AArch64GISel);
184 }
185
186 const CallLowering *AArch64Subtarget::getCallLowering() const {
187   assert(GISel && "Access to GlobalISel APIs not set");
188   return GISel->getCallLowering();
189 }
190
191 const InstructionSelector *AArch64Subtarget::getInstructionSelector() const {
192   assert(GISel && "Access to GlobalISel APIs not set");
193   return GISel->getInstructionSelector();
194 }
195
196 const LegalizerInfo *AArch64Subtarget::getLegalizerInfo() const {
197   assert(GISel && "Access to GlobalISel APIs not set");
198   return GISel->getLegalizerInfo();
199 }
200
201 const RegisterBankInfo *AArch64Subtarget::getRegBankInfo() const {
202   assert(GISel && "Access to GlobalISel APIs not set");
203   return GISel->getRegBankInfo();
204 }
205
206 /// Find the target operand flags that describe how a global value should be
207 /// referenced for the current subtarget.
208 unsigned char
209 AArch64Subtarget::ClassifyGlobalReference(const GlobalValue *GV,
210                                           const TargetMachine &TM) const {
211   // MachO large model always goes via a GOT, simply to get a single 8-byte
212   // absolute relocation on all global addresses.
213   if (TM.getCodeModel() == CodeModel::Large && isTargetMachO())
214     return AArch64II::MO_GOT;
215
216   if (!TM.shouldAssumeDSOLocal(*GV->getParent(), GV))
217     return AArch64II::MO_GOT;
218
219   // The small code model's direct accesses use ADRP, which cannot
220   // necessarily produce the value 0 (if the code is above 4GB).
221   if (useSmallAddressing() && GV->hasExternalWeakLinkage())
222     return AArch64II::MO_GOT;
223
224   return AArch64II::MO_NO_FLAG;
225 }
226
227 unsigned char AArch64Subtarget::classifyGlobalFunctionReference(
228     const GlobalValue *GV, const TargetMachine &TM) const {
229   // MachO large model always goes via a GOT, because we don't have the
230   // relocations available to do anything else..
231   if (TM.getCodeModel() == CodeModel::Large && isTargetMachO() &&
232       !GV->hasInternalLinkage())
233     return AArch64II::MO_GOT;
234
235   // NonLazyBind goes via GOT unless we know it's available locally.
236   auto *F = dyn_cast<Function>(GV);
237   if (UseNonLazyBind && F && F->hasFnAttribute(Attribute::NonLazyBind) &&
238       !TM.shouldAssumeDSOLocal(*GV->getParent(), GV))
239     return AArch64II::MO_GOT;
240
241   return AArch64II::MO_NO_FLAG;
242 }
243
244 /// This function returns the name of a function which has an interface
245 /// like the non-standard bzero function, if such a function exists on
246 /// the current subtarget and it is considered prefereable over
247 /// memset with zero passed as the second argument. Otherwise it
248 /// returns null.
249 const char *AArch64Subtarget::getBZeroEntry() const {
250   // Prefer bzero on Darwin only.
251   if(isTargetDarwin())
252     return "bzero";
253
254   return nullptr;
255 }
256
257 void AArch64Subtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
258                                            unsigned NumRegionInstrs) const {
259   // LNT run (at least on Cyclone) showed reasonably significant gains for
260   // bi-directional scheduling. 253.perlbmk.
261   Policy.OnlyTopDown = false;
262   Policy.OnlyBottomUp = false;
263   // Enabling or Disabling the latency heuristic is a close call: It seems to
264   // help nearly no benchmark on out-of-order architectures, on the other hand
265   // it regresses register pressure on a few benchmarking.
266   Policy.DisableLatencyHeuristic = DisableLatencySchedHeuristic;
267 }
268
269 bool AArch64Subtarget::enableEarlyIfConversion() const {
270   return EnableEarlyIfConvert;
271 }
272
273 bool AArch64Subtarget::supportsAddressTopByteIgnored() const {
274   if (!UseAddressTopByteIgnored)
275     return false;
276
277   if (TargetTriple.isiOS()) {
278     unsigned Major, Minor, Micro;
279     TargetTriple.getiOSVersion(Major, Minor, Micro);
280     return Major >= 8;
281   }
282
283   return false;
284 }
285
286 std::unique_ptr<PBQPRAConstraint>
287 AArch64Subtarget::getCustomPBQPConstraints() const {
288   return balanceFPOps() ? llvm::make_unique<A57ChainingConstraint>() : nullptr;
289 }