ARMSubtarget.h 32 KB

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