1 //===-- ARMSubtarget.h - Define Subtarget for the ARM ----------*- 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 ARM specific subclass of TargetSubtargetInfo.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_LIB_TARGET_ARM_ARMSUBTARGET_H
14 #define LLVM_LIB_TARGET_ARM_ARMSUBTARGET_H
15 
16 #include "ARMBaseInstrInfo.h"
17 #include "ARMBaseRegisterInfo.h"
18 #include "ARMConstantPoolValue.h"
19 #include "ARMFrameLowering.h"
20 #include "ARMISelLowering.h"
21 #include "ARMSelectionDAGInfo.h"
22 #include "llvm/ADT/Triple.h"
23 #include "llvm/CodeGen/GlobalISel/CallLowering.h"
24 #include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
25 #include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"
26 #include "llvm/CodeGen/GlobalISel/RegisterBankInfo.h"
27 #include "llvm/CodeGen/MachineFunction.h"
28 #include "llvm/CodeGen/TargetSubtargetInfo.h"
29 #include "llvm/MC/MCInstrItineraries.h"
30 #include "llvm/MC/MCSchedule.h"
31 #include "llvm/Target/TargetOptions.h"
32 #include <memory>
33 #include <string>
34 
35 #define GET_SUBTARGETINFO_HEADER
36 #include "ARMGenSubtargetInfo.inc"
37 
38 namespace llvm {
39 
40 class ARMBaseTargetMachine;
41 class GlobalValue;
42 class StringRef;
43 
44 class ARMSubtarget : public ARMGenSubtargetInfo {
45 protected:
46   enum ARMProcFamilyEnum {
47     Others,
48 
49     CortexA12,
50     CortexA15,
51     CortexA17,
52     CortexA32,
53     CortexA35,
54     CortexA5,
55     CortexA53,
56     CortexA55,
57     CortexA57,
58     CortexA7,
59     CortexA72,
60     CortexA73,
61     CortexA75,
62     CortexA76,
63     CortexA8,
64     CortexA9,
65     CortexM3,
66     CortexR4,
67     CortexR4F,
68     CortexR5,
69     CortexR52,
70     CortexR7,
71     Exynos,
72     Krait,
73     Kryo,
74     NeoverseN1,
75     Swift
76   };
77   enum ARMProcClassEnum {
78     None,
79 
80     AClass,
81     MClass,
82     RClass
83   };
84   enum ARMArchEnum {
85     ARMv2,
86     ARMv2a,
87     ARMv3,
88     ARMv3m,
89     ARMv4,
90     ARMv4t,
91     ARMv5,
92     ARMv5t,
93     ARMv5te,
94     ARMv5tej,
95     ARMv6,
96     ARMv6k,
97     ARMv6kz,
98     ARMv6m,
99     ARMv6sm,
100     ARMv6t2,
101     ARMv7a,
102     ARMv7em,
103     ARMv7m,
104     ARMv7r,
105     ARMv7ve,
106     ARMv81a,
107     ARMv82a,
108     ARMv83a,
109     ARMv84a,
110     ARMv85a,
111     ARMv86a,
112     ARMv8a,
113     ARMv8mBaseline,
114     ARMv8mMainline,
115     ARMv8r,
116     ARMv81mMainline,
117   };
118 
119 public:
120   /// What kind of timing do load multiple/store multiple instructions have.
121   enum ARMLdStMultipleTiming {
122     /// Can load/store 2 registers/cycle.
123     DoubleIssue,
124     /// Can load/store 2 registers/cycle, but needs an extra cycle if the access
125     /// is not 64-bit aligned.
126     DoubleIssueCheckUnalignedAccess,
127     /// Can load/store 1 register/cycle.
128     SingleIssue,
129     /// Can load/store 1 register/cycle, but needs an extra cycle for address
130     /// computation and potentially also for register writeback.
131     SingleIssuePlusExtras,
132   };
133 
134 protected:
135   /// ARMProcFamily - ARM processor family: Cortex-A8, Cortex-A9, and others.
136   ARMProcFamilyEnum ARMProcFamily = Others;
137 
138   /// ARMProcClass - ARM processor class: None, AClass, RClass or MClass.
139   ARMProcClassEnum ARMProcClass = None;
140 
141   /// ARMArch - ARM architecture
142   ARMArchEnum ARMArch = ARMv4t;
143 
144   /// HasV4TOps, HasV5TOps, HasV5TEOps,
145   /// HasV6Ops, HasV6MOps, HasV6KOps, HasV6T2Ops, HasV7Ops, HasV8Ops -
146   /// Specify whether target support specific ARM ISA variants.
147   bool HasV4TOps = false;
148   bool HasV5TOps = false;
149   bool HasV5TEOps = false;
150   bool HasV6Ops = false;
151   bool HasV6MOps = false;
152   bool HasV6KOps = false;
153   bool HasV6T2Ops = false;
154   bool HasV7Ops = false;
155   bool HasV8Ops = false;
156   bool HasV8_1aOps = false;
157   bool HasV8_2aOps = false;
158   bool HasV8_3aOps = false;
159   bool HasV8_4aOps = false;
160   bool HasV8_5aOps = false;
161   bool HasV8_6aOps = false;
162   bool HasV8MBaselineOps = false;
163   bool HasV8MMainlineOps = false;
164   bool HasV8_1MMainlineOps = false;
165   bool HasMVEIntegerOps = false;
166   bool HasMVEFloatOps = false;
167   bool HasCDEOps = false;
168 
169   /// HasVFPv2, HasVFPv3, HasVFPv4, HasFPARMv8, HasNEON - Specify what
170   /// floating point ISAs are supported.
171   bool HasVFPv2 = false;
172   bool HasVFPv3 = false;
173   bool HasVFPv4 = false;
174   bool HasFPARMv8 = false;
175   bool HasNEON = false;
176   bool HasFPRegs = false;
177   bool HasFPRegs16 = false;
178   bool HasFPRegs64 = false;
179 
180   /// Versions of the VFP flags restricted to single precision, or to
181   /// 16 d-registers, or both.
182   bool HasVFPv2SP = false;
183   bool HasVFPv3SP = false;
184   bool HasVFPv4SP = false;
185   bool HasFPARMv8SP = false;
186   bool HasVFPv3D16 = false;
187   bool HasVFPv4D16 = false;
188   bool HasFPARMv8D16 = false;
189   bool HasVFPv3D16SP = false;
190   bool HasVFPv4D16SP = false;
191   bool HasFPARMv8D16SP = false;
192 
193   /// HasDotProd - True if the ARMv8.2A dot product instructions are supported.
194   bool HasDotProd = false;
195 
196   /// UseNEONForSinglePrecisionFP - if the NEONFP attribute has been
197   /// specified. Use the method useNEONForSinglePrecisionFP() to
198   /// determine if NEON should actually be used.
199   bool UseNEONForSinglePrecisionFP = false;
200 
201   /// UseMulOps - True if non-microcoded fused integer multiply-add and
202   /// multiply-subtract instructions should be used.
203   bool UseMulOps = false;
204 
205   /// SlowFPVMLx - If the VFP2 / NEON instructions are available, indicates
206   /// whether the FP VML[AS] instructions are slow (if so, don't use them).
207   bool SlowFPVMLx = false;
208 
209   /// SlowFPVFMx - If the VFP4 / NEON instructions are available, indicates
210   /// whether the FP VFM[AS] instructions are slow (if so, don't use them).
211   bool SlowFPVFMx = false;
212 
213   /// HasVMLxForwarding - If true, NEON has special multiplier accumulator
214   /// forwarding to allow mul + mla being issued back to back.
215   bool HasVMLxForwarding = false;
216 
217   /// SlowFPBrcc - True if floating point compare + branch is slow.
218   bool SlowFPBrcc = false;
219 
220   /// InThumbMode - True if compiling for Thumb, false for ARM.
221   bool InThumbMode = false;
222 
223   /// UseSoftFloat - True if we're using software floating point features.
224   bool UseSoftFloat = false;
225 
226   /// UseMISched - True if MachineScheduler should be used for this subtarget.
227   bool UseMISched = false;
228 
229   /// DisablePostRAScheduler - False if scheduling should happen again after
230   /// register allocation.
231   bool DisablePostRAScheduler = false;
232 
233   /// HasThumb2 - True if Thumb2 instructions are supported.
234   bool HasThumb2 = false;
235 
236   /// NoARM - True if subtarget does not support ARM mode execution.
237   bool NoARM = false;
238 
239   /// ReserveR9 - True if R9 is not available as a general purpose register.
240   bool ReserveR9 = false;
241 
242   /// NoMovt - True if MOVT / MOVW pairs are not used for materialization of
243   /// 32-bit imms (including global addresses).
244   bool NoMovt = false;
245 
246   /// SupportsTailCall - True if the OS supports tail call. The dynamic linker
247   /// must be able to synthesize call stubs for interworking between ARM and
248   /// Thumb.
249   bool SupportsTailCall = false;
250 
251   /// HasFP16 - True if subtarget supports half-precision FP conversions
252   bool HasFP16 = false;
253 
254   /// HasFullFP16 - True if subtarget supports half-precision FP operations
255   bool HasFullFP16 = false;
256 
257   /// HasFP16FML - True if subtarget supports half-precision FP fml operations
258   bool HasFP16FML = false;
259 
260   /// HasBF16 - True if subtarget supports BFloat16 floating point operations
261   bool HasBF16 = false;
262 
263   /// HasMatMulInt8 - True if subtarget supports 8-bit integer matrix multiply
264   bool HasMatMulInt8 = false;
265 
266   /// HasD32 - True if subtarget has the full 32 double precision
267   /// FP registers for VFPv3.
268   bool HasD32 = false;
269 
270   /// HasHardwareDivide - True if subtarget supports [su]div in Thumb mode
271   bool HasHardwareDivideInThumb = false;
272 
273   /// HasHardwareDivideInARM - True if subtarget supports [su]div in ARM mode
274   bool HasHardwareDivideInARM = false;
275 
276   /// HasDataBarrier - True if the subtarget supports DMB / DSB data barrier
277   /// instructions.
278   bool HasDataBarrier = false;
279 
280   /// HasFullDataBarrier - True if the subtarget supports DFB data barrier
281   /// instruction.
282   bool HasFullDataBarrier = false;
283 
284   /// HasV7Clrex - True if the subtarget supports CLREX instructions
285   bool HasV7Clrex = false;
286 
287   /// HasAcquireRelease - True if the subtarget supports v8 atomics (LDA/LDAEX etc)
288   /// instructions
289   bool HasAcquireRelease = false;
290 
291   /// Pref32BitThumb - If true, codegen would prefer 32-bit Thumb instructions
292   /// over 16-bit ones.
293   bool Pref32BitThumb = false;
294 
295   /// AvoidCPSRPartialUpdate - If true, codegen would avoid using instructions
296   /// that partially update CPSR and add false dependency on the previous
297   /// CPSR setting instruction.
298   bool AvoidCPSRPartialUpdate = false;
299 
300   /// CheapPredicableCPSRDef - If true, disable +1 predication cost
301   /// for instructions updating CPSR. Enabled for Cortex-A57.
302   bool CheapPredicableCPSRDef = false;
303 
304   /// AvoidMOVsShifterOperand - If true, codegen should avoid using flag setting
305   /// movs with shifter operand (i.e. asr, lsl, lsr).
306   bool AvoidMOVsShifterOperand = false;
307 
308   /// HasRetAddrStack - Some processors perform return stack prediction. CodeGen should
309   /// avoid issue "normal" call instructions to callees which do not return.
310   bool HasRetAddrStack = false;
311 
312   /// HasBranchPredictor - True if the subtarget has a branch predictor. Having
313   /// a branch predictor or not changes the expected cost of taking a branch
314   /// which affects the choice of whether to use predicated instructions.
315   bool HasBranchPredictor = true;
316 
317   /// HasMPExtension - True if the subtarget supports Multiprocessing
318   /// extension (ARMv7 only).
319   bool HasMPExtension = false;
320 
321   /// HasVirtualization - True if the subtarget supports the Virtualization
322   /// extension.
323   bool HasVirtualization = false;
324 
325   /// HasFP64 - If true, the floating point unit supports double
326   /// precision.
327   bool HasFP64 = false;
328 
329   /// If true, the processor supports the Performance Monitor Extensions. These
330   /// include a generic cycle-counter as well as more fine-grained (often
331   /// implementation-specific) events.
332   bool HasPerfMon = false;
333 
334   /// HasTrustZone - if true, processor supports TrustZone security extensions
335   bool HasTrustZone = false;
336 
337   /// Has8MSecExt - if true, processor supports ARMv8-M Security Extensions
338   bool Has8MSecExt = false;
339 
340   /// HasSHA2 - if true, processor supports SHA1 and SHA256
341   bool HasSHA2 = false;
342 
343   /// HasAES - if true, processor supports AES
344   bool HasAES = false;
345 
346   /// HasCrypto - if true, processor supports Cryptography extensions
347   bool HasCrypto = false;
348 
349   /// HasCRC - if true, processor supports CRC instructions
350   bool HasCRC = false;
351 
352   /// HasRAS - if true, the processor supports RAS extensions
353   bool HasRAS = false;
354 
355   /// HasLOB - if true, the processor supports the Low Overhead Branch extension
356   bool HasLOB = false;
357 
358   /// If true, the instructions "vmov.i32 d0, #0" and "vmov.i32 q0, #0" are
359   /// particularly effective at zeroing a VFP register.
360   bool HasZeroCycleZeroing = false;
361 
362   /// HasFPAO - if true, processor  does positive address offset computation faster
363   bool HasFPAO = false;
364 
365   /// HasFuseAES - if true, processor executes back to back AES instruction
366   /// pairs faster.
367   bool HasFuseAES = false;
368 
369   /// HasFuseLiterals - if true, processor executes back to back
370   /// bottom and top halves of literal generation faster.
371   bool HasFuseLiterals = false;
372 
373   /// If true, if conversion may decide to leave some instructions unpredicated.
374   bool IsProfitableToUnpredicate = false;
375 
376   /// If true, VMOV will be favored over VGETLNi32.
377   bool HasSlowVGETLNi32 = false;
378 
379   /// If true, VMOV will be favored over VDUP.
380   bool HasSlowVDUP32 = false;
381 
382   /// If true, VMOVSR will be favored over VMOVDRR.
383   bool PreferVMOVSR = false;
384 
385   /// If true, ISHST barriers will be used for Release semantics.
386   bool PreferISHST = false;
387 
388   /// If true, a VLDM/VSTM starting with an odd register number is considered to
389   /// take more microops than single VLDRS/VSTRS.
390   bool SlowOddRegister = false;
391 
392   /// If true, loading into a D subregister will be penalized.
393   bool SlowLoadDSubregister = false;
394 
395   /// If true, use a wider stride when allocating VFP registers.
396   bool UseWideStrideVFP = false;
397 
398   /// If true, the AGU and NEON/FPU units are multiplexed.
399   bool HasMuxedUnits = false;
400 
401   /// If true, VMOVS will never be widened to VMOVD.
402   bool DontWidenVMOVS = false;
403 
404   /// If true, splat a register between VFP and NEON instructions.
405   bool SplatVFPToNeon = false;
406 
407   /// If true, run the MLx expansion pass.
408   bool ExpandMLx = false;
409 
410   /// If true, VFP/NEON VMLA/VMLS have special RAW hazards.
411   bool HasVMLxHazards = false;
412 
413   // If true, read thread pointer from coprocessor register.
414   bool ReadTPHard = false;
415 
416   /// If true, VMOVRS, VMOVSR and VMOVS will be converted from VFP to NEON.
417   bool UseNEONForFPMovs = false;
418 
419   /// If true, VLDn instructions take an extra cycle for unaligned accesses.
420   bool CheckVLDnAlign = false;
421 
422   /// If true, VFP instructions are not pipelined.
423   bool NonpipelinedVFP = false;
424 
425   /// StrictAlign - If true, the subtarget disallows unaligned memory
426   /// accesses for some types.  For details, see
427   /// ARMTargetLowering::allowsMisalignedMemoryAccesses().
428   bool StrictAlign = false;
429 
430   /// RestrictIT - If true, the subtarget disallows generation of deprecated IT
431   ///  blocks to conform to ARMv8 rule.
432   bool RestrictIT = false;
433 
434   /// HasDSP - If true, the subtarget supports the DSP (saturating arith
435   /// and such) instructions.
436   bool HasDSP = false;
437 
438   /// NaCl TRAP instruction is generated instead of the regular TRAP.
439   bool UseNaClTrap = false;
440 
441   /// Generate calls via indirect call instructions.
442   bool GenLongCalls = false;
443 
444   /// Generate code that does not contain data access to code sections.
445   bool GenExecuteOnly = false;
446 
447   /// Target machine allowed unsafe FP math (such as use of NEON fp)
448   bool UnsafeFPMath = false;
449 
450   /// UseSjLjEH - If true, the target uses SjLj exception handling (e.g. iOS).
451   bool UseSjLjEH = false;
452 
453   /// Has speculation barrier
454   bool HasSB = false;
455 
456   /// Implicitly convert an instruction to a different one if its immediates
457   /// cannot be encoded. For example, ADD r0, r1, #FFFFFFFF -> SUB r0, r1, #1.
458   bool NegativeImmediates = true;
459 
460   /// stackAlignment - The minimum alignment known to hold of the stack frame on
461   /// entry to the function and which must be maintained by every function.
462   Align stackAlignment = Align(4);
463 
464   /// CPUString - String name of used CPU.
465   std::string CPUString;
466 
467   unsigned MaxInterleaveFactor = 1;
468 
469   /// Clearance before partial register updates (in number of instructions)
470   unsigned PartialUpdateClearance = 0;
471 
472   /// What kind of timing do load multiple/store multiple have (double issue,
473   /// single issue etc).
474   ARMLdStMultipleTiming LdStMultipleTiming = SingleIssue;
475 
476   /// The adjustment that we need to apply to get the operand latency from the
477   /// operand cycle returned by the itinerary data for pre-ISel operands.
478   int PreISelOperandLatencyAdjustment = 2;
479 
480   /// What alignment is preferred for loop bodies, in log2(bytes).
481   unsigned PrefLoopLogAlignment = 0;
482 
483   /// The cost factor for MVE instructions, representing the multiple beats an
484   // instruction can take. The default is 2, (set in initSubtargetFeatures so
485   // that we can use subtarget features less than 2).
486   unsigned MVEVectorCostFactor = 0;
487 
488   /// OptMinSize - True if we're optimising for minimum code size, equal to
489   /// the function attribute.
490   bool OptMinSize = false;
491 
492   /// IsLittle - The target is Little Endian
493   bool IsLittle;
494 
495   /// TargetTriple - What processor and OS we're targeting.
496   Triple TargetTriple;
497 
498   /// SchedModel - Processor specific instruction costs.
499   MCSchedModel SchedModel;
500 
501   /// Selected instruction itineraries (one entry per itinerary class.)
502   InstrItineraryData InstrItins;
503 
504   /// Options passed via command line that could influence the target
505   const TargetOptions &Options;
506 
507   const ARMBaseTargetMachine &TM;
508 
509 public:
510   /// This constructor initializes the data members to match that
511   /// of the specified triple.
512   ///
513   ARMSubtarget(const Triple &TT, const std::string &CPU, const std::string &FS,
514                const ARMBaseTargetMachine &TM, bool IsLittle,
515                bool MinSize = false);
516 
517   /// getMaxInlineSizeThreshold - Returns the maximum memset / memcpy size
518   /// that still makes it profitable to inline the call.
519   unsigned getMaxInlineSizeThreshold() const {
520     return 64;
521   }
522 
523   /// ParseSubtargetFeatures - Parses features string setting specified
524   /// subtarget options.  Definition of function is auto generated by tblgen.
525   void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
526 
527   /// initializeSubtargetDependencies - Initializes using a CPU and feature string
528   /// so that we can use initializer lists for subtarget initialization.
529   ARMSubtarget &initializeSubtargetDependencies(StringRef CPU, StringRef FS);
530 
531   const ARMSelectionDAGInfo *getSelectionDAGInfo() const override {
532     return &TSInfo;
533   }
534 
535   const ARMBaseInstrInfo *getInstrInfo() const override {
536     return InstrInfo.get();
537   }
538 
539   const ARMTargetLowering *getTargetLowering() const override {
540     return &TLInfo;
541   }
542 
543   const ARMFrameLowering *getFrameLowering() const override {
544     return FrameLowering.get();
545   }
546 
547   const ARMBaseRegisterInfo *getRegisterInfo() const override {
548     return &InstrInfo->getRegisterInfo();
549   }
550 
551   const CallLowering *getCallLowering() const override;
552   InstructionSelector *getInstructionSelector() const override;
553   const LegalizerInfo *getLegalizerInfo() const override;
554   const RegisterBankInfo *getRegBankInfo() const override;
555 
556 private:
557   ARMSelectionDAGInfo TSInfo;
558   // Either Thumb1FrameLowering or ARMFrameLowering.
559   std::unique_ptr<ARMFrameLowering> FrameLowering;
560   // Either Thumb1InstrInfo or Thumb2InstrInfo.
561   std::unique_ptr<ARMBaseInstrInfo> InstrInfo;
562   ARMTargetLowering   TLInfo;
563 
564   /// GlobalISel related APIs.
565   std::unique_ptr<CallLowering> CallLoweringInfo;
566   std::unique_ptr<InstructionSelector> InstSelector;
567   std::unique_ptr<LegalizerInfo> Legalizer;
568   std::unique_ptr<RegisterBankInfo> RegBankInfo;
569 
570   void initializeEnvironment();
571   void initSubtargetFeatures(StringRef CPU, StringRef FS);
572   ARMFrameLowering *initializeFrameLowering(StringRef CPU, StringRef FS);
573 
574   std::bitset<8> CoprocCDE = {};
575 public:
576   void computeIssueWidth();
577 
578   bool hasV4TOps()  const { return HasV4TOps;  }
579   bool hasV5TOps()  const { return HasV5TOps;  }
580   bool hasV5TEOps() const { return HasV5TEOps; }
581   bool hasV6Ops()   const { return HasV6Ops;   }
582   bool hasV6MOps()  const { return HasV6MOps;  }
583   bool hasV6KOps()  const { return HasV6KOps; }
584   bool hasV6T2Ops() const { return HasV6T2Ops; }
585   bool hasV7Ops()   const { return HasV7Ops;  }
586   bool hasV8Ops()   const { return HasV8Ops;  }
587   bool hasV8_1aOps() const { return HasV8_1aOps; }
588   bool hasV8_2aOps() const { return HasV8_2aOps; }
589   bool hasV8_3aOps() const { return HasV8_3aOps; }
590   bool hasV8_4aOps() const { return HasV8_4aOps; }
591   bool hasV8_5aOps() const { return HasV8_5aOps; }
592   bool hasV8_6aOps() const { return HasV8_6aOps; }
593   bool hasV8MBaselineOps() const { return HasV8MBaselineOps; }
594   bool hasV8MMainlineOps() const { return HasV8MMainlineOps; }
595   bool hasV8_1MMainlineOps() const { return HasV8_1MMainlineOps; }
596   bool hasMVEIntegerOps() const { return HasMVEIntegerOps; }
597   bool hasMVEFloatOps() const { return HasMVEFloatOps; }
598   bool hasCDEOps() const { return HasCDEOps; }
599   bool hasFPRegs() const { return HasFPRegs; }
600   bool hasFPRegs16() const { return HasFPRegs16; }
601   bool hasFPRegs64() const { return HasFPRegs64; }
602 
603   /// @{
604   /// These functions are obsolete, please consider adding subtarget features
605   /// or properties instead of calling them.
606   bool isCortexA5() const { return ARMProcFamily == CortexA5; }
607   bool isCortexA7() const { return ARMProcFamily == CortexA7; }
608   bool isCortexA8() const { return ARMProcFamily == CortexA8; }
609   bool isCortexA9() const { return ARMProcFamily == CortexA9; }
610   bool isCortexA15() const { return ARMProcFamily == CortexA15; }
611   bool isSwift()    const { return ARMProcFamily == Swift; }
612   bool isCortexM3() const { return ARMProcFamily == CortexM3; }
613   bool isLikeA9() const { return isCortexA9() || isCortexA15() || isKrait(); }
614   bool isCortexR5() const { return ARMProcFamily == CortexR5; }
615   bool isKrait() const { return ARMProcFamily == Krait; }
616   /// @}
617 
618   bool hasARMOps() const { return !NoARM; }
619 
620   bool hasVFP2Base() const { return HasVFPv2SP; }
621   bool hasVFP3Base() const { return HasVFPv3D16SP; }
622   bool hasVFP4Base() const { return HasVFPv4D16SP; }
623   bool hasFPARMv8Base() const { return HasFPARMv8D16SP; }
624   bool hasNEON() const { return HasNEON;  }
625   bool hasSHA2() const { return HasSHA2; }
626   bool hasAES() const { return HasAES; }
627   bool hasCrypto() const { return HasCrypto; }
628   bool hasDotProd() const { return HasDotProd; }
629   bool hasCRC() const { return HasCRC; }
630   bool hasRAS() const { return HasRAS; }
631   bool hasLOB() const { return HasLOB; }
632   bool hasVirtualization() const { return HasVirtualization; }
633 
634   bool useNEONForSinglePrecisionFP() const {
635     return hasNEON() && UseNEONForSinglePrecisionFP;
636   }
637 
638   bool hasDivideInThumbMode() const { return HasHardwareDivideInThumb; }
639   bool hasDivideInARMMode() const { return HasHardwareDivideInARM; }
640   bool hasDataBarrier() const { return HasDataBarrier; }
641   bool hasFullDataBarrier() const { return HasFullDataBarrier; }
642   bool hasV7Clrex() const { return HasV7Clrex; }
643   bool hasAcquireRelease() const { return HasAcquireRelease; }
644 
645   bool hasAnyDataBarrier() const {
646     return HasDataBarrier || (hasV6Ops() && !isThumb());
647   }
648 
649   bool useMulOps() const { return UseMulOps; }
650   bool useFPVMLx() const { return !SlowFPVMLx; }
651   bool useFPVFMx() const {
652     return !isTargetDarwin() && hasVFP4Base() && !SlowFPVFMx;
653   }
654   bool useFPVFMx16() const { return useFPVFMx() && hasFullFP16(); }
655   bool useFPVFMx64() const { return useFPVFMx() && hasFP64(); }
656   bool hasVMLxForwarding() const { return HasVMLxForwarding; }
657   bool isFPBrccSlow() const { return SlowFPBrcc; }
658   bool hasFP64() const { return HasFP64; }
659   bool hasPerfMon() const { return HasPerfMon; }
660   bool hasTrustZone() const { return HasTrustZone; }
661   bool has8MSecExt() const { return Has8MSecExt; }
662   bool hasZeroCycleZeroing() const { return HasZeroCycleZeroing; }
663   bool hasFPAO() const { return HasFPAO; }
664   bool isProfitableToUnpredicate() const { return IsProfitableToUnpredicate; }
665   bool hasSlowVGETLNi32() const { return HasSlowVGETLNi32; }
666   bool hasSlowVDUP32() const { return HasSlowVDUP32; }
667   bool preferVMOVSR() const { return PreferVMOVSR; }
668   bool preferISHSTBarriers() const { return PreferISHST; }
669   bool expandMLx() const { return ExpandMLx; }
670   bool hasVMLxHazards() const { return HasVMLxHazards; }
671   bool hasSlowOddRegister() const { return SlowOddRegister; }
672   bool hasSlowLoadDSubregister() const { return SlowLoadDSubregister; }
673   bool useWideStrideVFP() const { return UseWideStrideVFP; }
674   bool hasMuxedUnits() const { return HasMuxedUnits; }
675   bool dontWidenVMOVS() const { return DontWidenVMOVS; }
676   bool useSplatVFPToNeon() const { return SplatVFPToNeon; }
677   bool useNEONForFPMovs() const { return UseNEONForFPMovs; }
678   bool checkVLDnAccessAlignment() const { return CheckVLDnAlign; }
679   bool nonpipelinedVFP() const { return NonpipelinedVFP; }
680   bool prefers32BitThumb() const { return Pref32BitThumb; }
681   bool avoidCPSRPartialUpdate() const { return AvoidCPSRPartialUpdate; }
682   bool cheapPredicableCPSRDef() const { return CheapPredicableCPSRDef; }
683   bool avoidMOVsShifterOperand() const { return AvoidMOVsShifterOperand; }
684   bool hasRetAddrStack() const { return HasRetAddrStack; }
685   bool hasBranchPredictor() const { return HasBranchPredictor; }
686   bool hasMPExtension() const { return HasMPExtension; }
687   bool hasDSP() const { return HasDSP; }
688   bool useNaClTrap() const { return UseNaClTrap; }
689   bool useSjLjEH() const { return UseSjLjEH; }
690   bool hasSB() const { return HasSB; }
691   bool genLongCalls() const { return GenLongCalls; }
692   bool genExecuteOnly() const { return GenExecuteOnly; }
693   bool hasBaseDSP() const {
694     if (isThumb())
695       return hasDSP();
696     else
697       return hasV5TEOps();
698   }
699 
700   bool hasFP16() const { return HasFP16; }
701   bool hasD32() const { return HasD32; }
702   bool hasFullFP16() const { return HasFullFP16; }
703   bool hasFP16FML() const { return HasFP16FML; }
704 
705   bool hasFuseAES() const { return HasFuseAES; }
706   bool hasFuseLiterals() const { return HasFuseLiterals; }
707   /// Return true if the CPU supports any kind of instruction fusion.
708   bool hasFusion() const { return hasFuseAES() || hasFuseLiterals(); }
709 
710   bool hasMatMulInt8() const { return HasMatMulInt8; }
711 
712   const Triple &getTargetTriple() const { return TargetTriple; }
713 
714   bool isTargetDarwin() const { return TargetTriple.isOSDarwin(); }
715   bool isTargetIOS() const { return TargetTriple.isiOS(); }
716   bool isTargetWatchOS() const { return TargetTriple.isWatchOS(); }
717   bool isTargetWatchABI() const { return TargetTriple.isWatchABI(); }
718   bool isTargetLinux() const { return TargetTriple.isOSLinux(); }
719   bool isTargetNaCl() const { return TargetTriple.isOSNaCl(); }
720   bool isTargetNetBSD() const { return TargetTriple.isOSNetBSD(); }
721   bool isTargetWindows() const { return TargetTriple.isOSWindows(); }
722 
723   bool isTargetCOFF() const { return TargetTriple.isOSBinFormatCOFF(); }
724   bool isTargetELF() const { return TargetTriple.isOSBinFormatELF(); }
725   bool isTargetMachO() const { return TargetTriple.isOSBinFormatMachO(); }
726 
727   // ARM EABI is the bare-metal EABI described in ARM ABI documents and
728   // can be accessed via -target arm-none-eabi. This is NOT GNUEABI.
729   // FIXME: Add a flag for bare-metal for that target and set Triple::EABI
730   // even for GNUEABI, so we can make a distinction here and still conform to
731   // the EABI on GNU (and Android) mode. This requires change in Clang, too.
732   // FIXME: The Darwin exception is temporary, while we move users to
733   // "*-*-*-macho" triples as quickly as possible.
734   bool isTargetAEABI() const {
735     return (TargetTriple.getEnvironment() == Triple::EABI ||
736             TargetTriple.getEnvironment() == Triple::EABIHF) &&
737            !isTargetDarwin() && !isTargetWindows();
738   }
739   bool isTargetGNUAEABI() const {
740     return (TargetTriple.getEnvironment() == Triple::GNUEABI ||
741             TargetTriple.getEnvironment() == Triple::GNUEABIHF) &&
742            !isTargetDarwin() && !isTargetWindows();
743   }
744   bool isTargetMuslAEABI() const {
745     return (TargetTriple.getEnvironment() == Triple::MuslEABI ||
746             TargetTriple.getEnvironment() == Triple::MuslEABIHF) &&
747            !isTargetDarwin() && !isTargetWindows();
748   }
749 
750   // ARM Targets that support EHABI exception handling standard
751   // Darwin uses SjLj. Other targets might need more checks.
752   bool isTargetEHABICompatible() const {
753     return (TargetTriple.getEnvironment() == Triple::EABI ||
754             TargetTriple.getEnvironment() == Triple::GNUEABI ||
755             TargetTriple.getEnvironment() == Triple::MuslEABI ||
756             TargetTriple.getEnvironment() == Triple::EABIHF ||
757             TargetTriple.getEnvironment() == Triple::GNUEABIHF ||
758             TargetTriple.getEnvironment() == Triple::MuslEABIHF ||
759             isTargetAndroid()) &&
760            !isTargetDarwin() && !isTargetWindows();
761   }
762 
763   bool isTargetHardFloat() const;
764 
765   bool isTargetAndroid() const { return TargetTriple.isAndroid(); }
766 
767   bool isXRaySupported() const override;
768 
769   bool isAPCS_ABI() const;
770   bool isAAPCS_ABI() const;
771   bool isAAPCS16_ABI() const;
772 
773   bool isROPI() const;
774   bool isRWPI() const;
775 
776   bool useMachineScheduler() const { return UseMISched; }
777   bool disablePostRAScheduler() const { return DisablePostRAScheduler; }
778   bool useSoftFloat() const { return UseSoftFloat; }
779   bool isThumb() const { return InThumbMode; }
780   bool hasMinSize() const { return OptMinSize; }
781   bool isThumb1Only() const { return InThumbMode && !HasThumb2; }
782   bool isThumb2() const { return InThumbMode && HasThumb2; }
783   bool hasThumb2() const { return HasThumb2; }
784   bool isMClass() const { return ARMProcClass == MClass; }
785   bool isRClass() const { return ARMProcClass == RClass; }
786   bool isAClass() const { return ARMProcClass == AClass; }
787   bool isReadTPHard() const { return ReadTPHard; }
788 
789   bool isR9Reserved() const {
790     return isTargetMachO() ? (ReserveR9 || !HasV6Ops) : ReserveR9;
791   }
792 
793   bool useR7AsFramePointer() const {
794     return isTargetDarwin() || (!isTargetWindows() && isThumb());
795   }
796 
797   /// Returns true if the frame setup is split into two separate pushes (first
798   /// r0-r7,lr then r8-r11), principally so that the frame pointer is adjacent
799   /// to lr. This is always required on Thumb1-only targets, as the push and
800   /// pop instructions can't access the high registers.
801   bool splitFramePushPop(const MachineFunction &MF) const {
802     return (useR7AsFramePointer() &&
803             MF.getTarget().Options.DisableFramePointerElim(MF)) ||
804            isThumb1Only();
805   }
806 
807   bool useStride4VFPs() const;
808 
809   bool useMovt() const;
810 
811   bool supportsTailCall() const { return SupportsTailCall; }
812 
813   bool allowsUnalignedMem() const { return !StrictAlign; }
814 
815   bool restrictIT() const { return RestrictIT; }
816 
817   const std::string & getCPUString() const { return CPUString; }
818 
819   bool isLittle() const { return IsLittle; }
820 
821   unsigned getMispredictionPenalty() const;
822 
823   /// Returns true if machine scheduler should be enabled.
824   bool enableMachineScheduler() const override;
825 
826   /// True for some subtargets at > -O0.
827   bool enablePostRAScheduler() const override;
828 
829   /// True for some subtargets at > -O0.
830   bool enablePostRAMachineScheduler() const override;
831 
832   /// Check whether this subtarget wants to use subregister liveness.
833   bool enableSubRegLiveness() const override;
834 
835   /// Enable use of alias analysis during code generation (during MI
836   /// scheduling, DAGCombine, etc.).
837   bool useAA() const override { return true; }
838 
839   // enableAtomicExpand- True if we need to expand our atomics.
840   bool enableAtomicExpand() const override;
841 
842   /// getInstrItins - Return the instruction itineraries based on subtarget
843   /// selection.
844   const InstrItineraryData *getInstrItineraryData() const override {
845     return &InstrItins;
846   }
847 
848   /// getStackAlignment - Returns the minimum alignment known to hold of the
849   /// stack frame on entry to the function and which must be maintained by every
850   /// function for this subtarget.
851   Align getStackAlignment() const { return stackAlignment; }
852 
853   unsigned getMaxInterleaveFactor() const { return MaxInterleaveFactor; }
854 
855   unsigned getPartialUpdateClearance() const { return PartialUpdateClearance; }
856 
857   ARMLdStMultipleTiming getLdStMultipleTiming() const {
858     return LdStMultipleTiming;
859   }
860 
861   int getPreISelOperandLatencyAdjustment() const {
862     return PreISelOperandLatencyAdjustment;
863   }
864 
865   /// True if the GV will be accessed via an indirect symbol.
866   bool isGVIndirectSymbol(const GlobalValue *GV) const;
867 
868   /// Returns the constant pool modifier needed to access the GV.
869   bool isGVInGOT(const GlobalValue *GV) const;
870 
871   /// True if fast-isel is used.
872   bool useFastISel() const;
873 
874   /// Returns the correct return opcode for the current feature set.
875   /// Use BX if available to allow mixing thumb/arm code, but fall back
876   /// to plain mov pc,lr on ARMv4.
877   unsigned getReturnOpcode() const {
878     if (isThumb())
879       return ARM::tBX_RET;
880     if (hasV4TOps())
881       return ARM::BX_RET;
882     return ARM::MOVPCLR;
883   }
884 
885   /// Allow movt+movw for PIC global address calculation.
886   /// ELF does not have GOT relocations for movt+movw.
887   /// ROPI does not use GOT.
888   bool allowPositionIndependentMovt() const {
889     return isROPI() || !isTargetELF();
890   }
891 
892   unsigned getPrefLoopLogAlignment() const { return PrefLoopLogAlignment; }
893 
894   unsigned getMVEVectorCostFactor() const { return MVEVectorCostFactor; }
895 
896   bool ignoreCSRForAllocationOrder(const MachineFunction &MF,
897                                    unsigned PhysReg) const override;
898   unsigned getGPRAllocationOrder(const MachineFunction &MF) const;
899 };
900 
901 } // end namespace llvm
902 
903 #endif  // LLVM_LIB_TARGET_ARM_ARMSUBTARGET_H
904