LLVM 18.0.0git
AArch64Subtarget.h
Go to the documentation of this file.
1//===--- AArch64Subtarget.h - Define Subtarget for the AArch64 -*- C++ -*--===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file declares the AArch64 specific subclass of TargetSubtarget.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_LIB_TARGET_AARCH64_AARCH64SUBTARGET_H
14#define LLVM_LIB_TARGET_AARCH64_AARCH64SUBTARGET_H
15
17#include "AArch64ISelLowering.h"
18#include "AArch64InstrInfo.h"
19#include "AArch64RegisterInfo.h"
27#include "llvm/IR/DataLayout.h"
28#include <string>
29
30#define GET_SUBTARGETINFO_HEADER
31#include "AArch64GenSubtargetInfo.inc"
32
33namespace llvm {
34class GlobalValue;
35class StringRef;
36class Triple;
37
39public:
40 enum ARMProcFamilyEnum : uint8_t {
90 TSV110
91 };
92
93protected:
94 /// ARMProcFamily - ARM processor family: Cortex-A53, Cortex-A57, and others.
96
97 // Enable 64-bit vectorization in SLP.
99
100// Bool members corresponding to the SubtargetFeatures defined in tablegen
101#define GET_SUBTARGETINFO_MACRO(ATTRIBUTE, DEFAULT, GETTER) \
102 bool ATTRIBUTE = DEFAULT;
103#include "AArch64GenSubtargetInfo.inc"
104
110 unsigned MaxPrefetchIterationsAhead = UINT_MAX;
114 unsigned MaxJumpTableSize = 0;
115
116 // ReserveXRegister[i] - X#i is not available as a general purpose register.
118
119 // ReserveXRegisterForRA[i] - X#i is not available for register allocator.
121
122 // CustomCallUsedXRegister[i] - X#i call saved.
124
126
131 unsigned VScaleForTuning = 2;
133
134 /// TargetTriple - What processor and OS we're targeting.
136
141
142 /// GlobalISel related APIs.
143 std::unique_ptr<CallLowering> CallLoweringInfo;
144 std::unique_ptr<InlineAsmLowering> InlineAsmLoweringInfo;
145 std::unique_ptr<InstructionSelector> InstSelector;
146 std::unique_ptr<LegalizerInfo> Legalizer;
147 std::unique_ptr<RegisterBankInfo> RegBankInfo;
148
149private:
150 /// initializeSubtargetDependencies - Initializes using CPUString and the
151 /// passed in feature string so that we can use initializer lists for
152 /// subtarget initialization.
153 AArch64Subtarget &initializeSubtargetDependencies(StringRef FS,
154 StringRef CPUString,
155 StringRef TuneCPUString);
156
157 /// Initialize properties based on the selected processor family.
158 void initializeProperties();
159
160public:
161 /// This constructor initializes the data members to match that
162 /// of the specified triple.
163 AArch64Subtarget(const Triple &TT, StringRef CPU, StringRef TuneCPU,
164 StringRef FS, const TargetMachine &TM, bool LittleEndian,
165 unsigned MinSVEVectorSizeInBitsOverride = 0,
166 unsigned MaxSVEVectorSizeInBitsOverride = 0,
167 bool StreamingSVEMode = false,
168 bool StreamingCompatibleSVEMode = false);
169
170// Getters for SubtargetFeatures defined in tablegen
171#define GET_SUBTARGETINFO_MACRO(ATTRIBUTE, DEFAULT, GETTER) \
172 bool GETTER() const { return ATTRIBUTE; }
173#include "AArch64GenSubtargetInfo.inc"
174
176 return &TSInfo;
177 }
178 const AArch64FrameLowering *getFrameLowering() const override {
179 return &FrameLowering;
180 }
181 const AArch64TargetLowering *getTargetLowering() const override {
182 return &TLInfo;
183 }
184 const AArch64InstrInfo *getInstrInfo() const override { return &InstrInfo; }
185 const AArch64RegisterInfo *getRegisterInfo() const override {
186 return &getInstrInfo()->getRegisterInfo();
187 }
188 const CallLowering *getCallLowering() const override;
189 const InlineAsmLowering *getInlineAsmLowering() const override;
191 const LegalizerInfo *getLegalizerInfo() const override;
192 const RegisterBankInfo *getRegBankInfo() const override;
193 const Triple &getTargetTriple() const { return TargetTriple; }
194 bool enableMachineScheduler() const override { return true; }
195 bool enablePostRAScheduler() const override { return usePostRAScheduler(); }
196
197 /// Returns ARM processor family.
198 /// Avoid this function! CPU specifics should be kept local to this class
199 /// and preferably modeled with SubtargetFeatures or properties in
200 /// initializeProperties().
202 return ARMProcFamily;
203 }
204
205 bool isXRaySupported() const override { return true; }
206
207 /// Returns true if the function has a streaming body.
208 bool isStreaming() const { return StreamingSVEMode; }
209
210 /// Returns true if the function has a streaming-compatible body.
211 bool isStreamingCompatible() const;
212
213 /// Returns true if the target has NEON and the function at runtime is known
214 /// to have NEON enabled (e.g. the function is known not to be in streaming-SVE
215 /// mode, which disables NEON instructions).
216 bool isNeonAvailable() const;
217
218 /// Returns true if the target has SVE and can use the full range of SVE
219 /// instructions, for example because it knows the function is known not to be
220 /// in streaming-SVE mode or when the target has FEAT_FA64 enabled.
221 bool isSVEAvailable() const;
222
224 // Don't assume any minimum vector size when PSTATE.SM may not be 0, because
225 // we don't yet support streaming-compatible codegen support that we trust
226 // is safe for functions that may be executed in streaming-SVE mode.
227 // By returning '0' here, we disable vectorization.
228 if (!isSVEAvailable() && !isNeonAvailable())
229 return 0;
231 }
232
233 bool isXRegisterReserved(size_t i) const { return ReserveXRegister[i]; }
234 bool isXRegisterReservedForRA(size_t i) const { return ReserveXRegisterForRA[i]; }
235 unsigned getNumXRegisterReserved() const {
236 BitVector AllReservedX(AArch64::GPR64commonRegClass.getNumRegs());
237 AllReservedX |= ReserveXRegister;
238 AllReservedX |= ReserveXRegisterForRA;
239 return AllReservedX.count();
240 }
241 bool isXRegCustomCalleeSaved(size_t i) const {
242 return CustomCallSavedXRegs[i];
243 }
245
246 /// Return true if the CPU supports any kind of instruction fusion.
247 bool hasFusion() const {
248 return hasArithmeticBccFusion() || hasArithmeticCbzFusion() ||
249 hasFuseAES() || hasFuseArithmeticLogic() || hasFuseCCSelect() ||
250 hasFuseAdrpAdd() || hasFuseLiterals();
251 }
252
253 unsigned getMaxInterleaveFactor() const { return MaxInterleaveFactor; }
254 unsigned getVectorInsertExtractBaseCost() const;
255 unsigned getCacheLineSize() const override { return CacheLineSize; }
256 unsigned getPrefetchDistance() const override { return PrefetchDistance; }
257 unsigned getMinPrefetchStride(unsigned NumMemAccesses,
258 unsigned NumStridedMemAccesses,
259 unsigned NumPrefetches,
260 bool HasCall) const override {
261 return MinPrefetchStride;
262 }
263 unsigned getMaxPrefetchIterationsAhead() const override {
265 }
268 }
270
273 }
274
275 unsigned getMaximumJumpTableSize() const { return MaxJumpTableSize; }
276
277 /// CPU has TBI (top byte of addresses is ignored during HW address
278 /// translation) and OS enables it.
280
281 bool isLittleEndian() const { return IsLittle; }
282
283 bool isTargetDarwin() const { return TargetTriple.isOSDarwin(); }
284 bool isTargetIOS() const { return TargetTriple.isiOS(); }
285 bool isTargetLinux() const { return TargetTriple.isOSLinux(); }
286 bool isTargetWindows() const { return TargetTriple.isOSWindows(); }
287 bool isTargetAndroid() const { return TargetTriple.isAndroid(); }
288 bool isTargetFuchsia() const { return TargetTriple.isOSFuchsia(); }
290
291 bool isTargetCOFF() const { return TargetTriple.isOSBinFormatCOFF(); }
292 bool isTargetELF() const { return TargetTriple.isOSBinFormatELF(); }
294
295 bool isTargetILP32() const {
296 return TargetTriple.isArch32Bit() ||
298 }
299
300 bool useAA() const override;
301
302 bool addrSinkUsingGEPs() const override {
303 // Keeping GEPs inbounds is important for exploiting AArch64
304 // addressing-modes in ILP32 mode.
305 return useAA() || isTargetILP32();
306 }
307
308 bool useSmallAddressing() const {
311 // Kernel is currently allowed only for Fuchsia targets,
312 // where it is the same as Small for almost all purposes.
313 case CodeModel::Small:
314 return true;
315 default:
316 return false;
317 }
318 }
319
320 /// ParseSubtargetFeatures - Parses features string setting specified
321 /// subtarget options. Definition of function is auto generated by tblgen.
323
324 /// ClassifyGlobalReference - Find the target operand flags that describe
325 /// how a global value should be referenced for the current subtarget.
326 unsigned ClassifyGlobalReference(const GlobalValue *GV,
327 const TargetMachine &TM) const;
328
330 const TargetMachine &TM) const;
331
332 /// This function is design to compatible with the function def in other
333 /// targets and escape build error about the virtual function def in base
334 /// class TargetSubtargetInfo. Updeate me if AArch64 target need to use it.
335 unsigned char
337 return 0;
338 }
339
341 unsigned NumRegionInstrs) const override;
342
343 bool enableEarlyIfConversion() const override;
344
345 std::unique_ptr<PBQPRAConstraint> getCustomPBQPConstraints() const override;
346
348 switch (CC) {
349 case CallingConv::C:
352 return isTargetWindows();
354 return true;
355 default:
356 return false;
357 }
358 }
359
360 /// Return whether FrameLowering should always set the "extended frame
361 /// present" bit in FP, or set it based on a symbol in the runtime.
363 // Older OS versions (particularly system unwinders) are confused by the
364 // Swift extended frame, so when building code that might be run on them we
365 // must dynamically query the concurrency library to determine whether
366 // extended frames should be flagged as present.
367 const Triple &TT = getTargetTriple();
368
369 unsigned Major = TT.getOSVersion().getMajor();
370 switch(TT.getOS()) {
371 default:
372 return false;
373 case Triple::IOS:
374 case Triple::TvOS:
375 return Major < 15;
376 case Triple::WatchOS:
377 return Major < 8;
378 case Triple::MacOSX:
379 case Triple::Darwin:
380 return Major < 12;
381 }
382 }
383
384 void mirFileLoaded(MachineFunction &MF) const override;
385
386 bool hasSVEorSME() const { return hasSVE() || hasSME(); }
387
388 // Return the known range for the bit length of SVE data registers. A value
389 // of 0 means nothing is known about that particular limit beyong what's
390 // implied by the architecture.
391 unsigned getMaxSVEVectorSizeInBits() const {
393 "Tried to get SVE vector length without SVE support!");
395 }
396
397 unsigned getMinSVEVectorSizeInBits() const {
399 "Tried to get SVE vector length without SVE support!");
401 }
402
404 if (!isNeonAvailable())
405 return hasSVEorSME();
406
407 // Prefer NEON unless larger SVE registers are available.
408 return hasSVEorSME() && getMinSVEVectorSizeInBits() >= 256;
409 }
410
413 return false;
416 }
417
418 unsigned getVScaleForTuning() const { return VScaleForTuning; }
419
421 return DefaultSVETFOpts;
422 }
423
424 const char* getChkStkName() const {
425 if (isWindowsArm64EC())
426 return "__chkstk_arm64ec";
427 return "__chkstk";
428 }
429
430 const char* getSecurityCheckCookieName() const {
431 if (isWindowsArm64EC())
432 return "__security_check_cookie_arm64ec";
433 return "__security_check_cookie";
434 }
435};
436} // End llvm namespace
437
438#endif
This file describes how to lower LLVM calls to machine code calls.
This file describes how to lower LLVM inline asm to machine code INLINEASM.
Interface for Targets to specify which operations they can successfully select and how the others sho...
const char LLVMTargetMachineRef TM
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const AArch64RegisterInfo & getRegisterInfo() const
getRegisterInfo - TargetInstrInfo is a superset of MRegister info.
const AArch64SelectionDAGInfo * getSelectionDAGInfo() const override
const CallLowering * getCallLowering() const override
bool isNeonAvailable() const
Returns true if the target has NEON and the function at runtime is known to have NEON enabled (e....
const AArch64RegisterInfo * getRegisterInfo() const override
TailFoldingOpts DefaultSVETFOpts
unsigned getMinPrefetchStride(unsigned NumMemAccesses, unsigned NumStridedMemAccesses, unsigned NumPrefetches, bool HasCall) const override
bool addrSinkUsingGEPs() const override
std::unique_ptr< InstructionSelector > InstSelector
ARMProcFamilyEnum ARMProcFamily
ARMProcFamily - ARM processor family: Cortex-A53, Cortex-A57, and others.
std::unique_ptr< RegisterBankInfo > RegBankInfo
bool useSVEForFixedLengthVectors(EVT VT) const
const AArch64InstrInfo * getInstrInfo() const override
bool useSmallAddressing() const
bool hasFusion() const
Return true if the CPU supports any kind of instruction fusion.
AArch64SelectionDAGInfo TSInfo
const char * getSecurityCheckCookieName() const
unsigned getMaximumJumpTableSize() const
bool isStreamingCompatible() const
Returns true if the function has a streaming-compatible body.
void overrideSchedPolicy(MachineSchedPolicy &Policy, unsigned NumRegionInstrs) const override
AArch64FrameLowering FrameLowering
bool enableEarlyIfConversion() const override
const InlineAsmLowering * getInlineAsmLowering() const override
unsigned getCacheLineSize() const override
unsigned getVectorInsertExtractBaseCost() const
ARMProcFamilyEnum getProcFamily() const
Returns ARM processor family.
std::unique_ptr< CallLowering > CallLoweringInfo
GlobalISel related APIs.
bool isXRegisterReservedForRA(size_t i) const
unsigned getNumXRegisterReserved() const
unsigned classifyGlobalFunctionReference(const GlobalValue *GV, const TargetMachine &TM) const
bool useAA() const override
const AArch64TargetLowering * getTargetLowering() const override
Align getPrefLoopAlignment() const
Align getPrefFunctionAlignment() const
unsigned getMaxBytesForLoopAlignment() const
bool supportsAddressTopByteIgnored() const
CPU has TBI (top byte of addresses is ignored during HW address translation) and OS enables it.
unsigned getMaxInterleaveFactor() const
unsigned char classifyGlobalFunctionReference(const GlobalValue *GV) const override
This function is design to compatible with the function def in other targets and escape build error a...
const Triple & getTargetTriple() const
bool isCallingConvWin64(CallingConv::ID CC) const
const char * getChkStkName() const
bool isXRegCustomCalleeSaved(size_t i) const
void mirFileLoaded(MachineFunction &MF) const override
Triple TargetTriple
TargetTriple - What processor and OS we're targeting.
InstructionSelector * getInstructionSelector() const override
TailFoldingOpts getSVETailFoldingDefaultOpts() const
bool useSVEForFixedLengthVectors() const
unsigned ClassifyGlobalReference(const GlobalValue *GV, const TargetMachine &TM) const
ClassifyGlobalReference - Find the target operand flags that describe how a global value should be re...
void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS)
ParseSubtargetFeatures - Parses features string setting specified subtarget options.
unsigned getMinVectorRegisterBitWidth() const
bool isStreaming() const
Returns true if the function has a streaming body.
bool isSVEAvailable() const
Returns true if the target has SVE and can use the full range of SVE instructions,...
bool isXRegisterReserved(size_t i) const
unsigned getMaxPrefetchIterationsAhead() const override
const LegalizerInfo * getLegalizerInfo() const override
bool enableMachineScheduler() const override
bool enablePostRAScheduler() const override
std::unique_ptr< PBQPRAConstraint > getCustomPBQPConstraints() const override
unsigned getMaxSVEVectorSizeInBits() const
unsigned getVScaleForTuning() const
unsigned getMinSVEVectorSizeInBits() const
AArch64InstrInfo InstrInfo
AArch64TargetLowering TLInfo
const RegisterBankInfo * getRegBankInfo() const override
std::unique_ptr< LegalizerInfo > Legalizer
std::unique_ptr< InlineAsmLowering > InlineAsmLoweringInfo
bool isXRaySupported() const override
bool hasCustomCallingConv() const
const AArch64FrameLowering * getFrameLowering() const override
bool swiftAsyncContextIsDynamicallySet() const
Return whether FrameLowering should always set the "extended frame present" bit in FP,...
unsigned getPrefetchDistance() const override
size_type count() const
count - Returns the number of bits which are set.
Definition: BitVector.h:162
bool any() const
any - Returns true if any bit is set.
Definition: BitVector.h:170
Holds all the information related to register banks.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
const TargetMachine & getTargetMachine() const
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:78
CodeModel::Model getCodeModel() const
Returns the code model.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
bool isAndroid() const
Tests whether the target is Android.
Definition: Triple.h:725
bool isOSBinFormatMachO() const
Tests whether the environment is MachO.
Definition: Triple.h:688
bool isOSBinFormatCOFF() const
Tests whether the OS uses the COFF binary format.
Definition: Triple.h:680
EnvironmentType getEnvironment() const
Get the parsed environment type of this triple.
Definition: Triple.h:372
bool isOSWindows() const
Tests whether the OS is Windows.
Definition: Triple.h:584
bool isOSLinux() const
Tests whether the OS is Linux.
Definition: Triple.h:638
bool isOSDarwin() const
Is this a "Darwin" OS (macOS, iOS, tvOS, watchOS, or DriverKit).
Definition: Triple.h:518
bool isWindowsArm64EC() const
Definition: Triple.h:600
bool isiOS() const
Is this an iOS triple.
Definition: Triple.h:494
bool isArch32Bit() const
Test whether the architecture is 32-bit.
Definition: Triple.cpp:1469
bool isOSFuchsia() const
Definition: Triple.h:548
bool isOSBinFormatELF() const
Tests whether the OS uses the ELF binary format.
Definition: Triple.h:675
static constexpr unsigned SVEBitsPerBlock
@ Swift
Calling convention for Swift.
Definition: CallingConv.h:69
@ Fast
Attempts to make calls as fast as possible (e.g.
Definition: CallingConv.h:41
@ Win64
The C convention as implemented on Windows/x86-64 and AArch64.
Definition: CallingConv.h:156
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
TailFoldingOpts
An enum to describe what types of loops we should attempt to tail-fold: Disabled: None Reductions: Lo...
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
Extended Value Type.
Definition: ValueTypes.h:34
uint64_t getFixedSizeInBits() const
Return the size of the specified fixed width value type in bits.
Definition: ValueTypes.h:359
bool isFixedLengthVector() const
Definition: ValueTypes.h:170
Define a generic scheduling policy for targets that don't provide their own MachineSchedStrategy.