PPCSubtarget.cpp 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. //===-- PowerPCSubtarget.cpp - PPC Subtarget Information ------------------===//
  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 implements the PPC specific subclass of TargetSubtargetInfo.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "PPCSubtarget.h"
  13. #include "GISel/PPCCallLowering.h"
  14. #include "GISel/PPCLegalizerInfo.h"
  15. #include "GISel/PPCRegisterBankInfo.h"
  16. #include "PPC.h"
  17. #include "PPCRegisterInfo.h"
  18. #include "PPCTargetMachine.h"
  19. #include "llvm/CodeGen/GlobalISel/InstructionSelect.h"
  20. #include "llvm/CodeGen/MachineFunction.h"
  21. #include "llvm/CodeGen/MachineScheduler.h"
  22. #include "llvm/IR/Attributes.h"
  23. #include "llvm/IR/Function.h"
  24. #include "llvm/IR/GlobalValue.h"
  25. #include "llvm/Support/CommandLine.h"
  26. #include "llvm/Support/TargetRegistry.h"
  27. #include "llvm/Target/TargetMachine.h"
  28. #include <cstdlib>
  29. using namespace llvm;
  30. #define DEBUG_TYPE "ppc-subtarget"
  31. #define GET_SUBTARGETINFO_TARGET_DESC
  32. #define GET_SUBTARGETINFO_CTOR
  33. #include "PPCGenSubtargetInfo.inc"
  34. static cl::opt<bool> UseSubRegLiveness("ppc-track-subreg-liveness",
  35. cl::desc("Enable subregister liveness tracking for PPC"), cl::Hidden);
  36. static cl::opt<bool>
  37. EnableMachinePipeliner("ppc-enable-pipeliner",
  38. cl::desc("Enable Machine Pipeliner for PPC"),
  39. cl::init(false), cl::Hidden);
  40. PPCSubtarget &PPCSubtarget::initializeSubtargetDependencies(StringRef CPU,
  41. StringRef FS) {
  42. initializeEnvironment();
  43. initSubtargetFeatures(CPU, FS);
  44. return *this;
  45. }
  46. PPCSubtarget::PPCSubtarget(const Triple &TT, const std::string &CPU,
  47. const std::string &FS, const PPCTargetMachine &TM)
  48. : PPCGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS), TargetTriple(TT),
  49. IsPPC64(TargetTriple.getArch() == Triple::ppc64 ||
  50. TargetTriple.getArch() == Triple::ppc64le),
  51. TM(TM), FrameLowering(initializeSubtargetDependencies(CPU, FS)),
  52. InstrInfo(*this), TLInfo(TM, *this) {
  53. CallLoweringInfo.reset(new PPCCallLowering(*getTargetLowering()));
  54. Legalizer.reset(new PPCLegalizerInfo(*this));
  55. auto *RBI = new PPCRegisterBankInfo(*getRegisterInfo());
  56. RegBankInfo.reset(RBI);
  57. InstSelector.reset(createPPCInstructionSelector(
  58. *static_cast<const PPCTargetMachine *>(&TM), *this, *RBI));
  59. }
  60. void PPCSubtarget::initializeEnvironment() {
  61. StackAlignment = Align(16);
  62. CPUDirective = PPC::DIR_NONE;
  63. HasMFOCRF = false;
  64. Has64BitSupport = false;
  65. Use64BitRegs = false;
  66. UseCRBits = false;
  67. HasHardFloat = false;
  68. HasAltivec = false;
  69. HasSPE = false;
  70. HasEFPU2 = false;
  71. HasFPU = false;
  72. HasVSX = false;
  73. NeedsTwoConstNR = false;
  74. HasP8Vector = false;
  75. HasP8Altivec = false;
  76. HasP8Crypto = false;
  77. HasP9Vector = false;
  78. HasP9Altivec = false;
  79. HasMMA = false;
  80. HasP10Vector = false;
  81. HasPrefixInstrs = false;
  82. HasPCRelativeMemops = false;
  83. HasFCPSGN = false;
  84. HasFSQRT = false;
  85. HasFRE = false;
  86. HasFRES = false;
  87. HasFRSQRTE = false;
  88. HasFRSQRTES = false;
  89. HasRecipPrec = false;
  90. HasSTFIWX = false;
  91. HasLFIWAX = false;
  92. HasFPRND = false;
  93. HasFPCVT = false;
  94. HasISEL = false;
  95. HasBPERMD = false;
  96. HasExtDiv = false;
  97. HasCMPB = false;
  98. HasLDBRX = false;
  99. IsBookE = false;
  100. HasOnlyMSYNC = false;
  101. IsPPC4xx = false;
  102. IsPPC6xx = false;
  103. IsE500 = false;
  104. FeatureMFTB = false;
  105. AllowsUnalignedFPAccess = false;
  106. DeprecatedDST = false;
  107. HasICBT = false;
  108. HasInvariantFunctionDescriptors = false;
  109. HasPartwordAtomics = false;
  110. HasDirectMove = false;
  111. HasHTM = false;
  112. HasFloat128 = false;
  113. HasFusion = false;
  114. HasStoreFusion = false;
  115. HasAddiLoadFusion = false;
  116. HasAddisLoadFusion = false;
  117. IsISA3_0 = false;
  118. IsISA3_1 = false;
  119. UseLongCalls = false;
  120. SecurePlt = false;
  121. VectorsUseTwoUnits = false;
  122. UsePPCPreRASchedStrategy = false;
  123. UsePPCPostRASchedStrategy = false;
  124. PairedVectorMemops = false;
  125. PredictableSelectIsExpensive = false;
  126. HasModernAIXAs = false;
  127. IsAIX = false;
  128. HasPOPCNTD = POPCNTD_Unavailable;
  129. }
  130. void PPCSubtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) {
  131. // Determine default and user specified characteristics
  132. std::string CPUName = std::string(CPU);
  133. if (CPUName.empty() || CPU == "generic") {
  134. // If cross-compiling with -march=ppc64le without -mcpu
  135. if (TargetTriple.getArch() == Triple::ppc64le)
  136. CPUName = "ppc64le";
  137. else if (TargetTriple.getSubArch() == Triple::PPCSubArch_spe)
  138. CPUName = "e500";
  139. else
  140. CPUName = "generic";
  141. }
  142. // Initialize scheduling itinerary for the specified CPU.
  143. InstrItins = getInstrItineraryForCPU(CPUName);
  144. // Parse features string.
  145. ParseSubtargetFeatures(CPUName, /*TuneCPU*/ CPUName, FS);
  146. // If the user requested use of 64-bit regs, but the cpu selected doesn't
  147. // support it, ignore.
  148. if (IsPPC64 && has64BitSupport())
  149. Use64BitRegs = true;
  150. if ((TargetTriple.isOSFreeBSD() && TargetTriple.getOSMajorVersion() >= 13) ||
  151. TargetTriple.isOSNetBSD() || TargetTriple.isOSOpenBSD() ||
  152. TargetTriple.isMusl())
  153. SecurePlt = true;
  154. if (HasSPE && IsPPC64)
  155. report_fatal_error( "SPE is only supported for 32-bit targets.\n", false);
  156. if (HasSPE && (HasAltivec || HasVSX || HasFPU))
  157. report_fatal_error(
  158. "SPE and traditional floating point cannot both be enabled.\n", false);
  159. // If not SPE, set standard FPU
  160. if (!HasSPE)
  161. HasFPU = true;
  162. StackAlignment = getPlatformStackAlignment();
  163. // Determine endianness.
  164. // FIXME: Part of the TargetMachine.
  165. IsLittleEndian = (TargetTriple.getArch() == Triple::ppc64le ||
  166. TargetTriple.getArch() == Triple::ppcle);
  167. }
  168. bool PPCSubtarget::enableMachineScheduler() const { return true; }
  169. bool PPCSubtarget::enableMachinePipeliner() const {
  170. return getSchedModel().hasInstrSchedModel() && EnableMachinePipeliner;
  171. }
  172. bool PPCSubtarget::useDFAforSMS() const { return false; }
  173. // This overrides the PostRAScheduler bit in the SchedModel for each CPU.
  174. bool PPCSubtarget::enablePostRAScheduler() const { return true; }
  175. PPCGenSubtargetInfo::AntiDepBreakMode PPCSubtarget::getAntiDepBreakMode() const {
  176. return TargetSubtargetInfo::ANTIDEP_ALL;
  177. }
  178. void PPCSubtarget::getCriticalPathRCs(RegClassVector &CriticalPathRCs) const {
  179. CriticalPathRCs.clear();
  180. CriticalPathRCs.push_back(isPPC64() ?
  181. &PPC::G8RCRegClass : &PPC::GPRCRegClass);
  182. }
  183. void PPCSubtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
  184. unsigned NumRegionInstrs) const {
  185. // The GenericScheduler that we use defaults to scheduling bottom up only.
  186. // We want to schedule from both the top and the bottom and so we set
  187. // OnlyBottomUp to false.
  188. // We want to do bi-directional scheduling since it provides a more balanced
  189. // schedule leading to better performance.
  190. Policy.OnlyBottomUp = false;
  191. // Spilling is generally expensive on all PPC cores, so always enable
  192. // register-pressure tracking.
  193. Policy.ShouldTrackPressure = true;
  194. }
  195. bool PPCSubtarget::useAA() const {
  196. return true;
  197. }
  198. bool PPCSubtarget::enableSubRegLiveness() const {
  199. return UseSubRegLiveness;
  200. }
  201. bool PPCSubtarget::isGVIndirectSymbol(const GlobalValue *GV) const {
  202. // Large code model always uses the TOC even for local symbols.
  203. if (TM.getCodeModel() == CodeModel::Large)
  204. return true;
  205. if (TM.shouldAssumeDSOLocal(*GV->getParent(), GV))
  206. return false;
  207. return true;
  208. }
  209. bool PPCSubtarget::isELFv2ABI() const { return TM.isELFv2ABI(); }
  210. bool PPCSubtarget::isPPC64() const { return TM.isPPC64(); }
  211. bool PPCSubtarget::isUsingPCRelativeCalls() const {
  212. return isPPC64() && hasPCRelativeMemops() && isELFv2ABI() &&
  213. CodeModel::Medium == getTargetMachine().getCodeModel();
  214. }
  215. // GlobalISEL
  216. const CallLowering *PPCSubtarget::getCallLowering() const {
  217. return CallLoweringInfo.get();
  218. }
  219. const RegisterBankInfo *PPCSubtarget::getRegBankInfo() const {
  220. return RegBankInfo.get();
  221. }
  222. const LegalizerInfo *PPCSubtarget::getLegalizerInfo() const {
  223. return Legalizer.get();
  224. }
  225. InstructionSelector *PPCSubtarget::getInstructionSelector() const {
  226. return InstSelector.get();
  227. }