PPCSubtarget.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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/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. // Bool members corresponding to the SubtargetFeatures defined in tablegen.
  79. #define GET_SUBTARGETINFO_MACRO(ATTRIBUTE, DEFAULT, GETTER) \
  80. bool ATTRIBUTE = DEFAULT;
  81. #include "PPCGenSubtargetInfo.inc"
  82. /// Which cpu directive was used.
  83. unsigned CPUDirective;
  84. bool IsPPC64;
  85. bool IsLittleEndian;
  86. POPCNTDKind HasPOPCNTD;
  87. const PPCTargetMachine &TM;
  88. PPCFrameLowering FrameLowering;
  89. PPCInstrInfo InstrInfo;
  90. PPCTargetLowering TLInfo;
  91. SelectionDAGTargetInfo TSInfo;
  92. /// GlobalISel related APIs.
  93. std::unique_ptr<CallLowering> CallLoweringInfo;
  94. std::unique_ptr<LegalizerInfo> Legalizer;
  95. std::unique_ptr<RegisterBankInfo> RegBankInfo;
  96. std::unique_ptr<InstructionSelector> InstSelector;
  97. public:
  98. /// This constructor initializes the data members to match that
  99. /// of the specified triple.
  100. ///
  101. PPCSubtarget(const Triple &TT, const std::string &CPU,
  102. const std::string &TuneCPU, const std::string &FS,
  103. const PPCTargetMachine &TM);
  104. /// ParseSubtargetFeatures - Parses features string setting specified
  105. /// subtarget options. Definition of function is auto generated by tblgen.
  106. void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS);
  107. /// getStackAlignment - Returns the minimum alignment known to hold of the
  108. /// stack frame on entry to the function and which must be maintained by every
  109. /// function for this subtarget.
  110. Align getStackAlignment() const { return StackAlignment; }
  111. /// getCPUDirective - Returns the -m directive specified for the cpu.
  112. ///
  113. unsigned getCPUDirective() const { return CPUDirective; }
  114. /// getInstrItins - Return the instruction itineraries based on subtarget
  115. /// selection.
  116. const InstrItineraryData *getInstrItineraryData() const override {
  117. return &InstrItins;
  118. }
  119. const PPCFrameLowering *getFrameLowering() const override {
  120. return &FrameLowering;
  121. }
  122. const PPCInstrInfo *getInstrInfo() const override { return &InstrInfo; }
  123. const PPCTargetLowering *getTargetLowering() const override {
  124. return &TLInfo;
  125. }
  126. const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
  127. return &TSInfo;
  128. }
  129. const PPCRegisterInfo *getRegisterInfo() const override {
  130. return &getInstrInfo()->getRegisterInfo();
  131. }
  132. const PPCTargetMachine &getTargetMachine() const { return TM; }
  133. /// initializeSubtargetDependencies - Initializes using a CPU, a TuneCPU, and
  134. /// feature string so that we can use initializer lists for subtarget
  135. /// initialization.
  136. PPCSubtarget &initializeSubtargetDependencies(StringRef CPU,
  137. StringRef TuneCPU,
  138. StringRef FS);
  139. private:
  140. void initializeEnvironment();
  141. void initSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS);
  142. public:
  143. /// isPPC64 - Return true if we are generating code for 64-bit pointer mode.
  144. ///
  145. bool isPPC64() const;
  146. // useSoftFloat - Return true if soft-float option is turned on.
  147. bool useSoftFloat() const {
  148. if (isAIXABI() && !HasHardFloat)
  149. report_fatal_error("soft-float is not yet supported on AIX.");
  150. return !HasHardFloat;
  151. }
  152. // isLittleEndian - True if generating little-endian code
  153. bool isLittleEndian() const { return IsLittleEndian; }
  154. // Getters for SubtargetFeatures defined in tablegen.
  155. #define GET_SUBTARGETINFO_MACRO(ATTRIBUTE, DEFAULT, GETTER) \
  156. bool GETTER() const { return ATTRIBUTE; }
  157. #include "PPCGenSubtargetInfo.inc"
  158. Align getPlatformStackAlignment() const {
  159. return Align(16);
  160. }
  161. unsigned getRedZoneSize() const {
  162. if (isPPC64())
  163. // 288 bytes = 18*8 (FPRs) + 18*8 (GPRs, GPR13 reserved)
  164. return 288;
  165. // AIX PPC32: 220 bytes = 18*8 (FPRs) + 19*4 (GPRs);
  166. // PPC32 SVR4ABI has no redzone.
  167. return isAIXABI() ? 220 : 0;
  168. }
  169. bool needsSwapsForVSXMemOps() const {
  170. return hasVSX() && isLittleEndian() && !hasP9Vector();
  171. }
  172. POPCNTDKind hasPOPCNTD() const { return HasPOPCNTD; }
  173. const Triple &getTargetTriple() const { return TargetTriple; }
  174. bool isTargetELF() const { return TargetTriple.isOSBinFormatELF(); }
  175. bool isTargetMachO() const { return TargetTriple.isOSBinFormatMachO(); }
  176. bool isTargetLinux() const { return TargetTriple.isOSLinux(); }
  177. bool isAIXABI() const { return TargetTriple.isOSAIX(); }
  178. bool isSVR4ABI() const { return !isAIXABI(); }
  179. bool isELFv2ABI() const;
  180. bool is64BitELFABI() const { return isSVR4ABI() && isPPC64(); }
  181. bool is32BitELFABI() const { return isSVR4ABI() && !isPPC64(); }
  182. bool isUsingPCRelativeCalls() const;
  183. /// Originally, this function return hasISEL(). Now we always enable it,
  184. /// but may expand the ISEL instruction later.
  185. bool enableEarlyIfConversion() const override { return true; }
  186. /// Scheduling customization.
  187. bool enableMachineScheduler() const override;
  188. /// Pipeliner customization.
  189. bool enableMachinePipeliner() const override;
  190. /// Machine Pipeliner customization
  191. bool useDFAforSMS() const override;
  192. /// This overrides the PostRAScheduler bit in the SchedModel for each CPU.
  193. bool enablePostRAScheduler() const override;
  194. AntiDepBreakMode getAntiDepBreakMode() const override;
  195. void getCriticalPathRCs(RegClassVector &CriticalPathRCs) const override;
  196. void overrideSchedPolicy(MachineSchedPolicy &Policy,
  197. unsigned NumRegionInstrs) const override;
  198. bool useAA() const override;
  199. bool enableSubRegLiveness() const override;
  200. /// True if the GV will be accessed via an indirect symbol.
  201. bool isGVIndirectSymbol(const GlobalValue *GV) const;
  202. /// True if the ABI is descriptor based.
  203. bool usesFunctionDescriptors() const {
  204. // Both 32-bit and 64-bit AIX are descriptor based. For ELF only the 64-bit
  205. // v1 ABI uses descriptors.
  206. return isAIXABI() || (is64BitELFABI() && !isELFv2ABI());
  207. }
  208. unsigned descriptorTOCAnchorOffset() const {
  209. assert(usesFunctionDescriptors() &&
  210. "Should only be called when the target uses descriptors.");
  211. return IsPPC64 ? 8 : 4;
  212. }
  213. unsigned descriptorEnvironmentPointerOffset() const {
  214. assert(usesFunctionDescriptors() &&
  215. "Should only be called when the target uses descriptors.");
  216. return IsPPC64 ? 16 : 8;
  217. }
  218. MCRegister getEnvironmentPointerRegister() const {
  219. assert(usesFunctionDescriptors() &&
  220. "Should only be called when the target uses descriptors.");
  221. return IsPPC64 ? PPC::X11 : PPC::R11;
  222. }
  223. MCRegister getTOCPointerRegister() const {
  224. assert((is64BitELFABI() || isAIXABI()) &&
  225. "Should only be called when the target is a TOC based ABI.");
  226. return IsPPC64 ? PPC::X2 : PPC::R2;
  227. }
  228. MCRegister getStackPointerRegister() const {
  229. return IsPPC64 ? PPC::X1 : PPC::R1;
  230. }
  231. bool isXRaySupported() const override { return IsPPC64 && IsLittleEndian; }
  232. bool isPredictableSelectIsExpensive() const {
  233. return PredictableSelectIsExpensive;
  234. }
  235. // Select allocation orders of GPRC and G8RC. It should be strictly consistent
  236. // with corresponding AltOrders in PPCRegisterInfo.td.
  237. unsigned getGPRAllocationOrderIdx() const {
  238. if (is64BitELFABI())
  239. return 1;
  240. if (isAIXABI())
  241. return 2;
  242. return 0;
  243. }
  244. // GlobalISEL
  245. const CallLowering *getCallLowering() const override;
  246. const RegisterBankInfo *getRegBankInfo() const override;
  247. const LegalizerInfo *getLegalizerInfo() const override;
  248. InstructionSelector *getInstructionSelector() const override;
  249. };
  250. } // End llvm namespace
  251. #endif