PPCSubtarget.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. //===-- PPCSubtarget.h - Define Subtarget for the PPC ----------*- 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 PowerPC specific subclass of TargetSubtargetInfo.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #ifndef LLVM_LIB_TARGET_POWERPC_PPCSUBTARGET_H
  13. #define LLVM_LIB_TARGET_POWERPC_PPCSUBTARGET_H
  14. #include "PPCFrameLowering.h"
  15. #include "PPCISelLowering.h"
  16. #include "PPCInstrInfo.h"
  17. #include "llvm/ADT/Triple.h"
  18. #include "llvm/CodeGen/GlobalISel/CallLowering.h"
  19. #include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"
  20. #include "llvm/CodeGen/GlobalISel/RegisterBankInfo.h"
  21. #include "llvm/CodeGen/SelectionDAGTargetInfo.h"
  22. #include "llvm/CodeGen/TargetSubtargetInfo.h"
  23. #include "llvm/IR/DataLayout.h"
  24. #include "llvm/MC/MCInstrItineraries.h"
  25. #include <string>
  26. #define GET_SUBTARGETINFO_HEADER
  27. #include "PPCGenSubtargetInfo.inc"
  28. // GCC #defines PPC on Linux but we use it as our namespace name
  29. #undef PPC
  30. namespace llvm {
  31. class StringRef;
  32. namespace PPC {
  33. // -m directive values.
  34. enum {
  35. DIR_NONE,
  36. DIR_32,
  37. DIR_440,
  38. DIR_601,
  39. DIR_602,
  40. DIR_603,
  41. DIR_7400,
  42. DIR_750,
  43. DIR_970,
  44. DIR_A2,
  45. DIR_E500,
  46. DIR_E500mc,
  47. DIR_E5500,
  48. DIR_PWR3,
  49. DIR_PWR4,
  50. DIR_PWR5,
  51. DIR_PWR5X,
  52. DIR_PWR6,
  53. DIR_PWR6X,
  54. DIR_PWR7,
  55. DIR_PWR8,
  56. DIR_PWR9,
  57. DIR_PWR10,
  58. DIR_PWR_FUTURE,
  59. DIR_64
  60. };
  61. }
  62. class GlobalValue;
  63. class PPCSubtarget : public PPCGenSubtargetInfo {
  64. public:
  65. enum POPCNTDKind {
  66. POPCNTD_Unavailable,
  67. POPCNTD_Slow,
  68. POPCNTD_Fast
  69. };
  70. protected:
  71. /// TargetTriple - What processor and OS we're targeting.
  72. Triple TargetTriple;
  73. /// stackAlignment - The minimum alignment known to hold of the stack frame on
  74. /// entry to the function and which must be maintained by every function.
  75. Align StackAlignment;
  76. /// Selected instruction itineraries (one entry per itinerary class.)
  77. InstrItineraryData InstrItins;
  78. /// Which cpu directive was used.
  79. unsigned CPUDirective;
  80. /// Used by the ISel to turn in optimizations for POWER4-derived architectures
  81. bool HasMFOCRF;
  82. bool Has64BitSupport;
  83. bool Use64BitRegs;
  84. bool UseCRBits;
  85. bool HasHardFloat;
  86. bool IsPPC64;
  87. bool HasAltivec;
  88. bool HasFPU;
  89. bool HasSPE;
  90. bool HasEFPU2;
  91. bool HasVSX;
  92. bool NeedsTwoConstNR;
  93. bool HasP8Vector;
  94. bool HasP8Altivec;
  95. bool HasP8Crypto;
  96. bool HasP9Vector;
  97. bool HasP9Altivec;
  98. bool HasP10Vector;
  99. bool HasPrefixInstrs;
  100. bool HasPCRelativeMemops;
  101. bool HasMMA;
  102. bool HasROPProtect;
  103. bool HasPrivileged;
  104. bool HasFCPSGN;
  105. bool HasFSQRT;
  106. bool HasFRE, HasFRES, HasFRSQRTE, HasFRSQRTES;
  107. bool HasRecipPrec;
  108. bool HasSTFIWX;
  109. bool HasLFIWAX;
  110. bool HasFPRND;
  111. bool HasFPCVT;
  112. bool HasISEL;
  113. bool HasBPERMD;
  114. bool HasExtDiv;
  115. bool HasCMPB;
  116. bool HasLDBRX;
  117. bool IsBookE;
  118. bool HasOnlyMSYNC;
  119. bool IsE500;
  120. bool IsPPC4xx;
  121. bool IsPPC6xx;
  122. bool FeatureMFTB;
  123. bool AllowsUnalignedFPAccess;
  124. bool DeprecatedDST;
  125. bool IsLittleEndian;
  126. bool HasICBT;
  127. bool HasInvariantFunctionDescriptors;
  128. bool HasPartwordAtomics;
  129. bool HasQuadwordAtomics;
  130. bool HasDirectMove;
  131. bool HasHTM;
  132. bool HasFloat128;
  133. bool HasFusion;
  134. bool HasStoreFusion;
  135. bool HasAddiLoadFusion;
  136. bool HasAddisLoadFusion;
  137. bool HasArithAddFusion;
  138. bool HasAddLogicalFusion;
  139. bool HasLogicalAddFusion;
  140. bool HasLogicalFusion;
  141. bool HasSha3Fusion;
  142. bool HasCompareFusion;
  143. bool HasWideImmFusion;
  144. bool HasZeroMoveFusion;
  145. bool HasBack2BackFusion;
  146. bool IsISA2_06;
  147. bool IsISA2_07;
  148. bool IsISA3_0;
  149. bool IsISA3_1;
  150. bool UseLongCalls;
  151. bool SecurePlt;
  152. bool VectorsUseTwoUnits;
  153. bool UsePPCPreRASchedStrategy;
  154. bool UsePPCPostRASchedStrategy;
  155. bool PairedVectorMemops;
  156. bool PredictableSelectIsExpensive;
  157. bool HasModernAIXAs;
  158. bool IsAIX;
  159. POPCNTDKind HasPOPCNTD;
  160. const PPCTargetMachine &TM;
  161. PPCFrameLowering FrameLowering;
  162. PPCInstrInfo InstrInfo;
  163. PPCTargetLowering TLInfo;
  164. SelectionDAGTargetInfo TSInfo;
  165. /// GlobalISel related APIs.
  166. std::unique_ptr<CallLowering> CallLoweringInfo;
  167. std::unique_ptr<LegalizerInfo> Legalizer;
  168. std::unique_ptr<RegisterBankInfo> RegBankInfo;
  169. std::unique_ptr<InstructionSelector> InstSelector;
  170. public:
  171. /// This constructor initializes the data members to match that
  172. /// of the specified triple.
  173. ///
  174. PPCSubtarget(const Triple &TT, const std::string &CPU, const std::string &FS,
  175. const PPCTargetMachine &TM);
  176. /// ParseSubtargetFeatures - Parses features string setting specified
  177. /// subtarget options. Definition of function is auto generated by tblgen.
  178. void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS);
  179. /// getStackAlignment - Returns the minimum alignment known to hold of the
  180. /// stack frame on entry to the function and which must be maintained by every
  181. /// function for this subtarget.
  182. Align getStackAlignment() const { return StackAlignment; }
  183. /// getCPUDirective - Returns the -m directive specified for the cpu.
  184. ///
  185. unsigned getCPUDirective() const { return CPUDirective; }
  186. /// getInstrItins - Return the instruction itineraries based on subtarget
  187. /// selection.
  188. const InstrItineraryData *getInstrItineraryData() const override {
  189. return &InstrItins;
  190. }
  191. const PPCFrameLowering *getFrameLowering() const override {
  192. return &FrameLowering;
  193. }
  194. const PPCInstrInfo *getInstrInfo() const override { return &InstrInfo; }
  195. const PPCTargetLowering *getTargetLowering() const override {
  196. return &TLInfo;
  197. }
  198. const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
  199. return &TSInfo;
  200. }
  201. const PPCRegisterInfo *getRegisterInfo() const override {
  202. return &getInstrInfo()->getRegisterInfo();
  203. }
  204. const PPCTargetMachine &getTargetMachine() const { return TM; }
  205. /// initializeSubtargetDependencies - Initializes using a CPU and feature string
  206. /// so that we can use initializer lists for subtarget initialization.
  207. PPCSubtarget &initializeSubtargetDependencies(StringRef CPU, StringRef FS);
  208. private:
  209. void initializeEnvironment();
  210. void initSubtargetFeatures(StringRef CPU, StringRef FS);
  211. public:
  212. /// isPPC64 - Return true if we are generating code for 64-bit pointer mode.
  213. ///
  214. bool isPPC64() const;
  215. /// has64BitSupport - Return true if the selected CPU supports 64-bit
  216. /// instructions, regardless of whether we are in 32-bit or 64-bit mode.
  217. bool has64BitSupport() const { return Has64BitSupport; }
  218. // useSoftFloat - Return true if soft-float option is turned on.
  219. bool useSoftFloat() const {
  220. if (isAIXABI() && !HasHardFloat)
  221. report_fatal_error("soft-float is not yet supported on AIX.");
  222. return !HasHardFloat;
  223. }
  224. /// use64BitRegs - Return true if in 64-bit mode or if we should use 64-bit
  225. /// registers in 32-bit mode when possible. This can only true if
  226. /// has64BitSupport() returns true.
  227. bool use64BitRegs() const { return Use64BitRegs; }
  228. /// useCRBits - Return true if we should store and manipulate i1 values in
  229. /// the individual condition register bits.
  230. bool useCRBits() const { return UseCRBits; }
  231. // isLittleEndian - True if generating little-endian code
  232. bool isLittleEndian() const { return IsLittleEndian; }
  233. // Specific obvious features.
  234. bool hasFCPSGN() const { return HasFCPSGN; }
  235. bool hasFSQRT() const { return HasFSQRT; }
  236. bool hasFRE() const { return HasFRE; }
  237. bool hasFRES() const { return HasFRES; }
  238. bool hasFRSQRTE() const { return HasFRSQRTE; }
  239. bool hasFRSQRTES() const { return HasFRSQRTES; }
  240. bool hasRecipPrec() const { return HasRecipPrec; }
  241. bool hasSTFIWX() const { return HasSTFIWX; }
  242. bool hasLFIWAX() const { return HasLFIWAX; }
  243. bool hasFPRND() const { return HasFPRND; }
  244. bool hasFPCVT() const { return HasFPCVT; }
  245. bool hasAltivec() const { return HasAltivec; }
  246. bool hasSPE() const { return HasSPE; }
  247. bool hasEFPU2() const { return HasEFPU2; }
  248. bool hasFPU() const { return HasFPU; }
  249. bool hasVSX() const { return HasVSX; }
  250. bool needsTwoConstNR() const { return NeedsTwoConstNR; }
  251. bool hasP8Vector() const { return HasP8Vector; }
  252. bool hasP8Altivec() const { return HasP8Altivec; }
  253. bool hasP8Crypto() const { return HasP8Crypto; }
  254. bool hasP9Vector() const { return HasP9Vector; }
  255. bool hasP9Altivec() const { return HasP9Altivec; }
  256. bool hasP10Vector() const { return HasP10Vector; }
  257. bool hasPrefixInstrs() const { return HasPrefixInstrs; }
  258. bool hasPCRelativeMemops() const { return HasPCRelativeMemops; }
  259. bool hasMMA() const { return HasMMA; }
  260. bool hasROPProtect() const { return HasROPProtect; }
  261. bool hasPrivileged() const { return HasPrivileged; }
  262. bool pairedVectorMemops() const { return PairedVectorMemops; }
  263. bool hasMFOCRF() const { return HasMFOCRF; }
  264. bool hasISEL() const { return HasISEL; }
  265. bool hasBPERMD() const { return HasBPERMD; }
  266. bool hasExtDiv() const { return HasExtDiv; }
  267. bool hasCMPB() const { return HasCMPB; }
  268. bool hasLDBRX() const { return HasLDBRX; }
  269. bool isBookE() const { return IsBookE; }
  270. bool hasOnlyMSYNC() const { return HasOnlyMSYNC; }
  271. bool isPPC4xx() const { return IsPPC4xx; }
  272. bool isPPC6xx() const { return IsPPC6xx; }
  273. bool isSecurePlt() const {return SecurePlt; }
  274. bool vectorsUseTwoUnits() const {return VectorsUseTwoUnits; }
  275. bool isE500() const { return IsE500; }
  276. bool isFeatureMFTB() const { return FeatureMFTB; }
  277. bool allowsUnalignedFPAccess() const { return AllowsUnalignedFPAccess; }
  278. bool isDeprecatedDST() const { return DeprecatedDST; }
  279. bool hasICBT() const { return HasICBT; }
  280. bool hasInvariantFunctionDescriptors() const {
  281. return HasInvariantFunctionDescriptors;
  282. }
  283. bool usePPCPreRASchedStrategy() const { return UsePPCPreRASchedStrategy; }
  284. bool usePPCPostRASchedStrategy() const { return UsePPCPostRASchedStrategy; }
  285. bool hasPartwordAtomics() const { return HasPartwordAtomics; }
  286. bool hasQuadwordAtomics() const { return HasQuadwordAtomics; }
  287. bool hasDirectMove() const { return HasDirectMove; }
  288. Align getPlatformStackAlignment() const {
  289. return Align(16);
  290. }
  291. unsigned getRedZoneSize() const {
  292. if (isPPC64())
  293. // 288 bytes = 18*8 (FPRs) + 18*8 (GPRs, GPR13 reserved)
  294. return 288;
  295. // AIX PPC32: 220 bytes = 18*8 (FPRs) + 19*4 (GPRs);
  296. // PPC32 SVR4ABI has no redzone.
  297. return isAIXABI() ? 220 : 0;
  298. }
  299. bool hasHTM() const { return HasHTM; }
  300. bool hasFloat128() const { return HasFloat128; }
  301. bool isISA2_06() const { return IsISA2_06; }
  302. bool isISA2_07() const { return IsISA2_07; }
  303. bool isISA3_0() const { return IsISA3_0; }
  304. bool isISA3_1() const { return IsISA3_1; }
  305. bool useLongCalls() const { return UseLongCalls; }
  306. bool hasFusion() const { return HasFusion; }
  307. bool hasStoreFusion() const { return HasStoreFusion; }
  308. bool hasAddiLoadFusion() const { return HasAddiLoadFusion; }
  309. bool hasAddisLoadFusion() const { return HasAddisLoadFusion; }
  310. bool hasArithAddFusion() const { return HasArithAddFusion; }
  311. bool hasAddLogicalFusion() const { return HasAddLogicalFusion; }
  312. bool hasLogicalAddFusion() const { return HasLogicalAddFusion; }
  313. bool hasLogicalFusion() const { return HasLogicalFusion; }
  314. bool hasCompareFusion() const { return HasCompareFusion; }
  315. bool hasWideImmFusion() const { return HasWideImmFusion; }
  316. bool hasSha3Fusion() const { return HasSha3Fusion; }
  317. bool hasZeroMoveFusion() const { return HasZeroMoveFusion; }
  318. bool hasBack2BackFusion() const { return HasBack2BackFusion; }
  319. bool needsSwapsForVSXMemOps() const {
  320. return hasVSX() && isLittleEndian() && !hasP9Vector();
  321. }
  322. POPCNTDKind hasPOPCNTD() const { return HasPOPCNTD; }
  323. const Triple &getTargetTriple() const { return TargetTriple; }
  324. bool isTargetELF() const { return TargetTriple.isOSBinFormatELF(); }
  325. bool isTargetMachO() const { return TargetTriple.isOSBinFormatMachO(); }
  326. bool isTargetLinux() const { return TargetTriple.isOSLinux(); }
  327. bool isAIXABI() const { return TargetTriple.isOSAIX(); }
  328. bool isSVR4ABI() const { return !isAIXABI(); }
  329. bool isELFv2ABI() const;
  330. bool is64BitELFABI() const { return isSVR4ABI() && isPPC64(); }
  331. bool is32BitELFABI() const { return isSVR4ABI() && !isPPC64(); }
  332. bool isUsingPCRelativeCalls() const;
  333. /// Originally, this function return hasISEL(). Now we always enable it,
  334. /// but may expand the ISEL instruction later.
  335. bool enableEarlyIfConversion() const override { return true; }
  336. /// Scheduling customization.
  337. bool enableMachineScheduler() const override;
  338. /// Pipeliner customization.
  339. bool enableMachinePipeliner() const override;
  340. /// Machine Pipeliner customization
  341. bool useDFAforSMS() const override;
  342. /// This overrides the PostRAScheduler bit in the SchedModel for each CPU.
  343. bool enablePostRAScheduler() const override;
  344. AntiDepBreakMode getAntiDepBreakMode() const override;
  345. void getCriticalPathRCs(RegClassVector &CriticalPathRCs) const override;
  346. void overrideSchedPolicy(MachineSchedPolicy &Policy,
  347. unsigned NumRegionInstrs) const override;
  348. bool useAA() const override;
  349. bool enableSubRegLiveness() const override;
  350. /// True if the GV will be accessed via an indirect symbol.
  351. bool isGVIndirectSymbol(const GlobalValue *GV) const;
  352. /// True if the ABI is descriptor based.
  353. bool usesFunctionDescriptors() const {
  354. // Both 32-bit and 64-bit AIX are descriptor based. For ELF only the 64-bit
  355. // v1 ABI uses descriptors.
  356. return isAIXABI() || (is64BitELFABI() && !isELFv2ABI());
  357. }
  358. unsigned descriptorTOCAnchorOffset() const {
  359. assert(usesFunctionDescriptors() &&
  360. "Should only be called when the target uses descriptors.");
  361. return IsPPC64 ? 8 : 4;
  362. }
  363. unsigned descriptorEnvironmentPointerOffset() const {
  364. assert(usesFunctionDescriptors() &&
  365. "Should only be called when the target uses descriptors.");
  366. return IsPPC64 ? 16 : 8;
  367. }
  368. MCRegister getEnvironmentPointerRegister() const {
  369. assert(usesFunctionDescriptors() &&
  370. "Should only be called when the target uses descriptors.");
  371. return IsPPC64 ? PPC::X11 : PPC::R11;
  372. }
  373. MCRegister getTOCPointerRegister() const {
  374. assert((is64BitELFABI() || isAIXABI()) &&
  375. "Should only be called when the target is a TOC based ABI.");
  376. return IsPPC64 ? PPC::X2 : PPC::R2;
  377. }
  378. MCRegister getStackPointerRegister() const {
  379. return IsPPC64 ? PPC::X1 : PPC::R1;
  380. }
  381. bool isXRaySupported() const override { return IsPPC64 && IsLittleEndian; }
  382. bool isPredictableSelectIsExpensive() const {
  383. return PredictableSelectIsExpensive;
  384. }
  385. // Select allocation orders of GPRC and G8RC. It should be strictly consistent
  386. // with corresponding AltOrders in PPCRegisterInfo.td.
  387. unsigned getGPRAllocationOrderIdx() const {
  388. if (is64BitELFABI())
  389. return 1;
  390. if (isAIXABI())
  391. return 2;
  392. return 0;
  393. }
  394. // GlobalISEL
  395. const CallLowering *getCallLowering() const override;
  396. const RegisterBankInfo *getRegBankInfo() const override;
  397. const LegalizerInfo *getLegalizerInfo() const override;
  398. InstructionSelector *getInstructionSelector() const override;
  399. };
  400. } // End llvm namespace
  401. #endif