blob: 553faf56afa9e474ded6a315ba91b6e714026afe [file] [log] [blame]
Tim Northover3b0846e2014-05-24 12:50:23 +00001//===--- AArch64Subtarget.h - Define Subtarget for the AArch64 -*- 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 declares the AArch64 specific subclass of TargetSubtarget.
11//
12//===----------------------------------------------------------------------===//
13
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000014#ifndef LLVM_LIB_TARGET_AARCH64_AARCH64SUBTARGET_H
15#define LLVM_LIB_TARGET_AARCH64_AARCH64SUBTARGET_H
Tim Northover3b0846e2014-05-24 12:50:23 +000016
Eric Christopher29aab7b2014-06-10 17:44:12 +000017#include "AArch64FrameLowering.h"
Eric Christopher841da852014-06-10 23:26:45 +000018#include "AArch64ISelLowering.h"
Benjamin Kramer1f8930e2014-07-25 11:42:14 +000019#include "AArch64InstrInfo.h"
Tim Northover3b0846e2014-05-24 12:50:23 +000020#include "AArch64RegisterInfo.h"
Eric Christopherfcb06ca2014-06-10 18:21:53 +000021#include "AArch64SelectionDAGInfo.h"
Quentin Colombet61d71a12017-08-15 22:31:51 +000022#include "llvm/CodeGen/GlobalISel/CallLowering.h"
23#include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
24#include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"
25#include "llvm/CodeGen/GlobalISel/RegisterBankInfo.h"
Eric Christopher6f2a2032014-06-10 18:06:23 +000026#include "llvm/IR/DataLayout.h"
Eric Christopher29aab7b2014-06-10 17:44:12 +000027#include "llvm/Target/TargetSubtargetInfo.h"
Tim Northover3b0846e2014-05-24 12:50:23 +000028#include <string>
29
30#define GET_SUBTARGETINFO_HEADER
31#include "AArch64GenSubtargetInfo.inc"
32
33namespace llvm {
34class GlobalValue;
35class StringRef;
Daniel Sandersa73f1fd2015-06-10 12:11:26 +000036class Triple;
Tim Northover3b0846e2014-05-24 12:50:23 +000037
Ahmed Bougacha5e402ee2016-07-27 14:31:46 +000038class AArch64Subtarget final : public AArch64GenSubtargetInfo {
Matthias Braun651cff42016-06-02 18:03:53 +000039public:
40 enum ARMProcFamilyEnum : uint8_t {
MinSeong Kima7385eb2016-01-05 12:51:59 +000041 Others,
42 CortexA35,
43 CortexA53,
Sam Parkerb252ffd2017-08-21 08:43:06 +000044 CortexA55,
MinSeong Kima7385eb2016-01-05 12:51:59 +000045 CortexA57,
Silviu Barangaaee40fc2016-06-21 15:53:54 +000046 CortexA72,
47 CortexA73,
Sam Parkerb252ffd2017-08-21 08:43:06 +000048 CortexA75,
MinSeong Kima7385eb2016-01-05 12:51:59 +000049 Cyclone,
Chad Rosiercd2be7f2016-02-12 15:51:51 +000050 ExynosM1,
Chad Rosier201fc1e2016-11-15 21:34:12 +000051 Falkor,
Pankaj Gode0aab2e32016-06-20 11:13:31 +000052 Kryo,
Joel Jones28520882017-03-07 19:42:40 +000053 ThunderX2T99,
Joel Jonesab0f3b42017-02-17 18:34:24 +000054 ThunderX,
55 ThunderXT81,
56 ThunderXT83,
57 ThunderXT88
MinSeong Kima7385eb2016-01-05 12:51:59 +000058 };
Tim Northover3b0846e2014-05-24 12:50:23 +000059
Matthias Braun651cff42016-06-02 18:03:53 +000060protected:
Tim Northover3b0846e2014-05-24 12:50:23 +000061 /// ARMProcFamily - ARM processor family: Cortex-A53, Cortex-A57, and others.
Matthias Braun27b66922016-05-27 22:14:09 +000062 ARMProcFamilyEnum ARMProcFamily = Others;
Tim Northover3b0846e2014-05-24 12:50:23 +000063
Matthias Braun27b66922016-05-27 22:14:09 +000064 bool HasV8_1aOps = false;
65 bool HasV8_2aOps = false;
Sam Parker9d957642017-08-10 09:41:00 +000066 bool HasV8_3aOps = false;
Vladimir Sukharev439328e2015-04-01 14:49:29 +000067
Matthias Braun27b66922016-05-27 22:14:09 +000068 bool HasFPARMv8 = false;
69 bool HasNEON = false;
70 bool HasCrypto = false;
Sjoerd Meijer79876332017-08-09 14:59:54 +000071 bool HasDotProd = false;
Matthias Braun27b66922016-05-27 22:14:09 +000072 bool HasCRC = false;
Joel Jones75818bc2016-11-30 22:25:24 +000073 bool HasLSE = false;
Sjoerd Meijerd906bf12016-06-03 14:03:27 +000074 bool HasRAS = false;
Chad Rosier58fb5f52017-01-16 16:28:43 +000075 bool HasRDM = false;
Matthias Braun27b66922016-05-27 22:14:09 +000076 bool HasPerfMon = false;
77 bool HasFullFP16 = false;
78 bool HasSPE = false;
Balaram Makam2aba753e2017-03-31 18:16:53 +000079 bool HasLSLFast = false;
Amara Emerson9f3a2452017-07-13 15:19:56 +000080 bool HasSVE = false;
Sam Parker71a474d2017-08-10 09:52:55 +000081 bool HasRCPC = false;
Tim Northover3b0846e2014-05-24 12:50:23 +000082
83 // HasZeroCycleRegMove - Has zero-cycle register mov instructions.
Matthias Braun27b66922016-05-27 22:14:09 +000084 bool HasZeroCycleRegMove = false;
Tim Northover3b0846e2014-05-24 12:50:23 +000085
86 // HasZeroCycleZeroing - Has zero-cycle zeroing instructions.
Matthias Braun27b66922016-05-27 22:14:09 +000087 bool HasZeroCycleZeroing = false;
Tim Northover3b0846e2014-05-24 12:50:23 +000088
Akira Hatanakaf53b0402015-07-29 14:17:26 +000089 // StrictAlign - Disallow unaligned memory accesses.
Matthias Braun27b66922016-05-27 22:14:09 +000090 bool StrictAlign = false;
Sanne Woudad4658ee2017-03-28 10:02:56 +000091
92 // NegativeImmediates - transform instructions with negative immediates
93 bool NegativeImmediates = true;
94
Adam Nemete29686e2017-05-15 21:15:01 +000095 // Enable 64-bit vectorization in SLP.
96 unsigned MinVectorRegisterBitWidth = 64;
97
Matthias Braun651cff42016-06-02 18:03:53 +000098 bool UseAA = false;
99 bool PredictableSelectIsExpensive = false;
100 bool BalanceFPOps = false;
101 bool CustomAsCheapAsMove = false;
102 bool UsePostRAScheduler = false;
103 bool Misaligned128StoreIsSlow = false;
Evandro Menezes7784cac2017-01-24 17:34:31 +0000104 bool Paired128IsSlow = false;
Matthias Braun651cff42016-06-02 18:03:53 +0000105 bool UseAlternateSExtLoadCVTF32Pattern = false;
Matthias Braun46a52382016-10-04 19:28:21 +0000106 bool HasArithmeticBccFusion = false;
107 bool HasArithmeticCbzFusion = false;
Evandro Menezesb21fb292017-02-01 02:54:39 +0000108 bool HasFuseAES = false;
Evandro Menezes455382e2017-02-01 02:54:42 +0000109 bool HasFuseLiterals = false;
Matthias Braun651cff42016-06-02 18:03:53 +0000110 bool DisableLatencySchedHeuristic = false;
Evandro Menezeseff2bd92016-10-24 16:14:58 +0000111 bool UseRSqrt = false;
Matthias Braun651cff42016-06-02 18:03:53 +0000112 uint8_t MaxInterleaveFactor = 2;
113 uint8_t VectorInsertExtractBaseCost = 3;
114 uint16_t CacheLineSize = 0;
115 uint16_t PrefetchDistance = 0;
116 uint16_t MinPrefetchStride = 1;
117 unsigned MaxPrefetchIterationsAhead = UINT_MAX;
Evandro Menezesa3a0a602016-06-10 16:00:18 +0000118 unsigned PrefFunctionAlignment = 0;
119 unsigned PrefLoopAlignment = 0;
Evandro Menezese45de8a2016-09-26 15:32:33 +0000120 unsigned MaxJumpTableSize = 0;
Matthew Simpson78fd46b2017-05-09 20:18:12 +0000121 unsigned WideningBaseCost = 0;
Akira Hatanakaf53b0402015-07-29 14:17:26 +0000122
Akira Hatanaka0d4c9ea2015-07-25 00:18:31 +0000123 // ReserveX18 - X18 is not available as a general purpose register.
124 bool ReserveX18;
125
Eric Christopher8b770652015-01-26 19:03:15 +0000126 bool IsLittle;
127
Tim Northover3b0846e2014-05-24 12:50:23 +0000128 /// TargetTriple - What processor and OS we're targeting.
129 Triple TargetTriple;
130
Eric Christopher29aab7b2014-06-10 17:44:12 +0000131 AArch64FrameLowering FrameLowering;
Eric Christopherf63bc642014-06-10 22:57:25 +0000132 AArch64InstrInfo InstrInfo;
Eric Christopherfcb06ca2014-06-10 18:21:53 +0000133 AArch64SelectionDAGInfo TSInfo;
Eric Christopher7c9d4e02014-06-11 00:46:34 +0000134 AArch64TargetLowering TLInfo;
Quentin Colombet61d71a12017-08-15 22:31:51 +0000135
136 /// GlobalISel related APIs.
137 std::unique_ptr<CallLowering> CallLoweringInfo;
138 std::unique_ptr<InstructionSelector> InstSelector;
139 std::unique_ptr<LegalizerInfo> Legalizer;
140 std::unique_ptr<RegisterBankInfo> RegBankInfo;
Quentin Colombetba2a0162016-02-16 19:26:02 +0000141
Eric Christopher7c9d4e02014-06-11 00:46:34 +0000142private:
143 /// initializeSubtargetDependencies - Initializes using CPUString and the
144 /// passed in feature string so that we can use initializer lists for
145 /// subtarget initialization.
Matthias Brauna827ed82016-10-03 20:17:02 +0000146 AArch64Subtarget &initializeSubtargetDependencies(StringRef FS,
147 StringRef CPUString);
Eric Christopher29aab7b2014-06-10 17:44:12 +0000148
Matthias Braun651cff42016-06-02 18:03:53 +0000149 /// Initialize properties based on the selected processor family.
150 void initializeProperties();
151
Tim Northover3b0846e2014-05-24 12:50:23 +0000152public:
153 /// This constructor initializes the data members to match that
154 /// of the specified triple.
Daniel Sandersa73f1fd2015-06-10 12:11:26 +0000155 AArch64Subtarget(const Triple &TT, const std::string &CPU,
Eric Christophera0de2532015-03-18 20:37:30 +0000156 const std::string &FS, const TargetMachine &TM,
Daniel Sandersa1b2db792017-05-19 11:08:33 +0000157 bool LittleEndian);
Tim Northover3b0846e2014-05-24 12:50:23 +0000158
Eric Christopherd9134482014-08-04 21:25:23 +0000159 const AArch64SelectionDAGInfo *getSelectionDAGInfo() const override {
160 return &TSInfo;
161 }
162 const AArch64FrameLowering *getFrameLowering() const override {
Eric Christopher29aab7b2014-06-10 17:44:12 +0000163 return &FrameLowering;
164 }
Eric Christopherd9134482014-08-04 21:25:23 +0000165 const AArch64TargetLowering *getTargetLowering() const override {
Eric Christopher7c9d4e02014-06-11 00:46:34 +0000166 return &TLInfo;
Eric Christopher841da852014-06-10 23:26:45 +0000167 }
Eric Christopherd9134482014-08-04 21:25:23 +0000168 const AArch64InstrInfo *getInstrInfo() const override { return &InstrInfo; }
Eric Christophera0de2532015-03-18 20:37:30 +0000169 const AArch64RegisterInfo *getRegisterInfo() const override {
170 return &getInstrInfo()->getRegisterInfo();
171 }
Quentin Colombetba2a0162016-02-16 19:26:02 +0000172 const CallLowering *getCallLowering() const override;
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000173 const InstructionSelector *getInstructionSelector() const override;
Tim Northover69fa84a2016-10-14 22:18:18 +0000174 const LegalizerInfo *getLegalizerInfo() const override;
Quentin Colombetc17f7442016-04-06 17:26:03 +0000175 const RegisterBankInfo *getRegBankInfo() const override;
Eric Christopher09696d32015-03-12 02:04:46 +0000176 const Triple &getTargetTriple() const { return TargetTriple; }
Tim Northover3b0846e2014-05-24 12:50:23 +0000177 bool enableMachineScheduler() const override { return true; }
Matthias Braun39a2afc2015-06-13 03:42:16 +0000178 bool enablePostRAScheduler() const override {
Matthias Braun651cff42016-06-02 18:03:53 +0000179 return UsePostRAScheduler;
180 }
181
182 /// Returns ARM processor family.
183 /// Avoid this function! CPU specifics should be kept local to this class
184 /// and preferably modeled with SubtargetFeatures or properties in
185 /// initializeProperties().
186 ARMProcFamilyEnum getProcFamily() const {
187 return ARMProcFamily;
Chad Rosier486e0872014-09-12 17:40:39 +0000188 }
Tim Northover3b0846e2014-05-24 12:50:23 +0000189
Vladimir Sukharev439328e2015-04-01 14:49:29 +0000190 bool hasV8_1aOps() const { return HasV8_1aOps; }
Oliver Stannard7cc0c4e2015-11-26 15:23:32 +0000191 bool hasV8_2aOps() const { return HasV8_2aOps; }
Sam Parker9d957642017-08-10 09:41:00 +0000192 bool hasV8_3aOps() const { return HasV8_3aOps; }
Vladimir Sukharev439328e2015-04-01 14:49:29 +0000193
Tim Northover3b0846e2014-05-24 12:50:23 +0000194 bool hasZeroCycleRegMove() const { return HasZeroCycleRegMove; }
195
196 bool hasZeroCycleZeroing() const { return HasZeroCycleZeroing; }
197
Akira Hatanakaf53b0402015-07-29 14:17:26 +0000198 bool requiresStrictAlign() const { return StrictAlign; }
199
Dean Michael Berris3234d3a2016-11-17 05:15:37 +0000200 bool isXRaySupported() const override { return true; }
201
Adam Nemete29686e2017-05-15 21:15:01 +0000202 unsigned getMinVectorRegisterBitWidth() const {
203 return MinVectorRegisterBitWidth;
204 }
205
Akira Hatanaka0d4c9ea2015-07-25 00:18:31 +0000206 bool isX18Reserved() const { return ReserveX18; }
Tim Northover3b0846e2014-05-24 12:50:23 +0000207 bool hasFPARMv8() const { return HasFPARMv8; }
208 bool hasNEON() const { return HasNEON; }
209 bool hasCrypto() const { return HasCrypto; }
Sjoerd Meijer79876332017-08-09 14:59:54 +0000210 bool hasDotProd() const { return HasDotProd; }
Tim Northover3b0846e2014-05-24 12:50:23 +0000211 bool hasCRC() const { return HasCRC; }
Joel Jones75818bc2016-11-30 22:25:24 +0000212 bool hasLSE() const { return HasLSE; }
Sjoerd Meijerd906bf12016-06-03 14:03:27 +0000213 bool hasRAS() const { return HasRAS; }
Chad Rosier58fb5f52017-01-16 16:28:43 +0000214 bool hasRDM() const { return HasRDM; }
Matthias Braun651cff42016-06-02 18:03:53 +0000215 bool balanceFPOps() const { return BalanceFPOps; }
216 bool predictableSelectIsExpensive() const {
217 return PredictableSelectIsExpensive;
218 }
219 bool hasCustomCheapAsMoveHandling() const { return CustomAsCheapAsMove; }
220 bool isMisaligned128StoreSlow() const { return Misaligned128StoreIsSlow; }
Evandro Menezes7784cac2017-01-24 17:34:31 +0000221 bool isPaired128Slow() const { return Paired128IsSlow; }
Matthias Braun651cff42016-06-02 18:03:53 +0000222 bool useAlternateSExtLoadCVTF32Pattern() const {
223 return UseAlternateSExtLoadCVTF32Pattern;
224 }
Matthias Braun46a52382016-10-04 19:28:21 +0000225 bool hasArithmeticBccFusion() const { return HasArithmeticBccFusion; }
226 bool hasArithmeticCbzFusion() const { return HasArithmeticCbzFusion; }
Evandro Menezesb21fb292017-02-01 02:54:39 +0000227 bool hasFuseAES() const { return HasFuseAES; }
Evandro Menezes455382e2017-02-01 02:54:42 +0000228 bool hasFuseLiterals() const { return HasFuseLiterals; }
Florian Hahnf934add2017-07-12 20:53:22 +0000229
230 /// \brief Return true if the CPU supports any kind of instruction fusion.
231 bool hasFusion() const {
232 return hasArithmeticBccFusion() || hasArithmeticCbzFusion() ||
233 hasFuseAES() || hasFuseLiterals();
234 }
235
Evandro Menezeseff2bd92016-10-24 16:14:58 +0000236 bool useRSqrt() const { return UseRSqrt; }
Matthias Braun651cff42016-06-02 18:03:53 +0000237 unsigned getMaxInterleaveFactor() const { return MaxInterleaveFactor; }
238 unsigned getVectorInsertExtractBaseCost() const {
239 return VectorInsertExtractBaseCost;
240 }
241 unsigned getCacheLineSize() const { return CacheLineSize; }
242 unsigned getPrefetchDistance() const { return PrefetchDistance; }
243 unsigned getMinPrefetchStride() const { return MinPrefetchStride; }
244 unsigned getMaxPrefetchIterationsAhead() const {
245 return MaxPrefetchIterationsAhead;
246 }
Evandro Menezesa3a0a602016-06-10 16:00:18 +0000247 unsigned getPrefFunctionAlignment() const { return PrefFunctionAlignment; }
248 unsigned getPrefLoopAlignment() const { return PrefLoopAlignment; }
Matthias Braun651cff42016-06-02 18:03:53 +0000249
Evandro Menezese45de8a2016-09-26 15:32:33 +0000250 unsigned getMaximumJumpTableSize() const { return MaxJumpTableSize; }
251
Matthew Simpson78fd46b2017-05-09 20:18:12 +0000252 unsigned getWideningBaseCost() const { return WideningBaseCost; }
253
Tim Northover339c83e2015-11-10 00:44:23 +0000254 /// CPU has TBI (top byte of addresses is ignored during HW address
255 /// translation) and OS enables it.
256 bool supportsAddressTopByteIgnored() const;
257
Ahmed Bougachab0ff6432015-09-01 16:23:45 +0000258 bool hasPerfMon() const { return HasPerfMon; }
Oliver Stannard7cc0c4e2015-11-26 15:23:32 +0000259 bool hasFullFP16() const { return HasFullFP16; }
Oliver Stannarda34e4702015-12-01 10:48:51 +0000260 bool hasSPE() const { return HasSPE; }
Balaram Makam2aba753e2017-03-31 18:16:53 +0000261 bool hasLSLFast() const { return HasLSLFast; }
Amara Emerson9f3a2452017-07-13 15:19:56 +0000262 bool hasSVE() const { return HasSVE; }
Sam Parker71a474d2017-08-10 09:52:55 +0000263 bool hasRCPC() const { return HasRCPC; }
Tim Northover3b0846e2014-05-24 12:50:23 +0000264
Eric Christopher8b770652015-01-26 19:03:15 +0000265 bool isLittleEndian() const { return IsLittle; }
Tim Northover3b0846e2014-05-24 12:50:23 +0000266
267 bool isTargetDarwin() const { return TargetTriple.isOSDarwin(); }
Chad Rosierb481bdf2014-08-06 16:56:58 +0000268 bool isTargetIOS() const { return TargetTriple.isiOS(); }
269 bool isTargetLinux() const { return TargetTriple.isOSLinux(); }
270 bool isTargetWindows() const { return TargetTriple.isOSWindows(); }
Evgeniy Stepanov5fe279e2015-10-08 21:21:24 +0000271 bool isTargetAndroid() const { return TargetTriple.isAndroid(); }
Petr Hoseka7d59162017-02-24 03:10:10 +0000272 bool isTargetFuchsia() const { return TargetTriple.isOSFuchsia(); }
Tim Northover3b0846e2014-05-24 12:50:23 +0000273
Chad Rosierb481bdf2014-08-06 16:56:58 +0000274 bool isTargetCOFF() const { return TargetTriple.isOSBinFormatCOFF(); }
Tim Northover3b0846e2014-05-24 12:50:23 +0000275 bool isTargetELF() const { return TargetTriple.isOSBinFormatELF(); }
Tim Northover3b0846e2014-05-24 12:50:23 +0000276 bool isTargetMachO() const { return TargetTriple.isOSBinFormatMachO(); }
277
Matthias Braun651cff42016-06-02 18:03:53 +0000278 bool useAA() const override { return UseAA; }
Chad Rosierc9f94772014-09-08 14:31:49 +0000279
Petr Hosek9eb0a1e2017-04-04 19:51:53 +0000280 bool useSmallAddressing() const {
281 switch (TLInfo.getTargetMachine().getCodeModel()) {
282 case CodeModel::Kernel:
283 // Kernel is currently allowed only for Fuchsia targets,
284 // where it is the same as Small for almost all purposes.
285 case CodeModel::Small:
286 return true;
287 default:
288 return false;
289 }
290 }
291
Tim Northover3b0846e2014-05-24 12:50:23 +0000292 /// ParseSubtargetFeatures - Parses features string setting specified
293 /// subtarget options. Definition of function is auto generated by tblgen.
294 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
295
296 /// ClassifyGlobalReference - Find the target operand flags that describe
297 /// how a global value should be referenced for the current subtarget.
298 unsigned char ClassifyGlobalReference(const GlobalValue *GV,
299 const TargetMachine &TM) const;
300
Tim Northover879a0b22017-04-17 17:27:56 +0000301 unsigned char classifyGlobalFunctionReference(const GlobalValue *GV,
302 const TargetMachine &TM) const;
303
Tim Northover3b0846e2014-05-24 12:50:23 +0000304 /// This function returns the name of a function which has an interface
305 /// like the non-standard bzero function, if such a function exists on
306 /// the current subtarget and it is considered prefereable over
307 /// memset with zero passed as the second argument. Otherwise it
308 /// returns null.
309 const char *getBZeroEntry() const;
310
Duncan P. N. Exon Smith63298722016-07-01 00:23:27 +0000311 void overrideSchedPolicy(MachineSchedPolicy &Policy,
Tim Northover3b0846e2014-05-24 12:50:23 +0000312 unsigned NumRegionInstrs) const override;
313
314 bool enableEarlyIfConversion() const override;
Lang Hames8f31f442014-10-09 18:20:51 +0000315
316 std::unique_ptr<PBQPRAConstraint> getCustomPBQPConstraints() const override;
Martin Storsjo2f24e932017-07-17 20:05:19 +0000317
318 bool isCallingConvWin64(CallingConv::ID CC) const {
319 switch (CC) {
320 case CallingConv::C:
321 return isTargetWindows();
322 case CallingConv::Win64:
323 return true;
324 default:
325 return false;
326 }
327 }
Tim Northover3b0846e2014-05-24 12:50:23 +0000328};
Alexander Kornienkof00654e2015-06-23 09:49:53 +0000329} // End llvm namespace
Tim Northover3b0846e2014-05-24 12:50:23 +0000330
Benjamin Kramera7c40ef2014-08-13 16:26:38 +0000331#endif