PPCSubtarget.cpp 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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/MC/TargetRegistry.h"
  26. #include "llvm/Support/CommandLine.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. HasROPProtect = false;
  81. HasPrivileged = false;
  82. HasP10Vector = false;
  83. HasPrefixInstrs = false;
  84. HasPCRelativeMemops = false;
  85. HasFCPSGN = false;
  86. HasFSQRT = false;
  87. HasFRE = false;
  88. HasFRES = false;
  89. HasFRSQRTE = false;
  90. HasFRSQRTES = false;
  91. HasRecipPrec = false;
  92. HasSTFIWX = false;
  93. HasLFIWAX = false;
  94. HasFPRND = false;
  95. HasFPCVT = false;
  96. HasISEL = false;
  97. HasBPERMD = false;
  98. HasExtDiv = false;
  99. HasCMPB = false;
  100. HasLDBRX = false;
  101. IsBookE = false;
  102. HasOnlyMSYNC = false;
  103. IsPPC4xx = false;
  104. IsPPC6xx = false;
  105. IsE500 = false;
  106. FeatureMFTB = false;
  107. AllowsUnalignedFPAccess = false;
  108. DeprecatedDST = false;
  109. HasICBT = false;
  110. HasInvariantFunctionDescriptors = false;
  111. HasPartwordAtomics = false;
  112. HasQuadwordAtomics = false;
  113. HasDirectMove = false;
  114. HasHTM = false;
  115. HasFloat128 = false;
  116. HasFusion = false;
  117. HasStoreFusion = false;
  118. HasAddiLoadFusion = false;
  119. HasAddisLoadFusion = false;
  120. HasArithAddFusion = false;
  121. HasAddLogicalFusion = false;
  122. HasLogicalAddFusion = false;
  123. HasLogicalFusion = false;
  124. HasSha3Fusion = false;
  125. HasCompareFusion = false;
  126. HasWideImmFusion = false;
  127. HasZeroMoveFusion = false;
  128. HasBack2BackFusion = false;
  129. IsISA2_06 = false;
  130. IsISA2_07 = false;
  131. IsISA3_0 = false;
  132. IsISA3_1 = false;
  133. UseLongCalls = false;
  134. SecurePlt = false;
  135. VectorsUseTwoUnits = false;
  136. UsePPCPreRASchedStrategy = false;
  137. UsePPCPostRASchedStrategy = false;
  138. PairedVectorMemops = false;
  139. PredictableSelectIsExpensive = false;
  140. HasModernAIXAs = false;
  141. IsAIX = false;
  142. HasPOPCNTD = POPCNTD_Unavailable;
  143. }
  144. void PPCSubtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) {
  145. // Determine default and user specified characteristics
  146. std::string CPUName = std::string(CPU);
  147. if (CPUName.empty() || CPU == "generic") {
  148. // If cross-compiling with -march=ppc64le without -mcpu
  149. if (TargetTriple.getArch() == Triple::ppc64le)
  150. CPUName = "ppc64le";
  151. else if (TargetTriple.getSubArch() == Triple::PPCSubArch_spe)
  152. CPUName = "e500";
  153. else
  154. CPUName = "generic";
  155. }
  156. // Initialize scheduling itinerary for the specified CPU.
  157. InstrItins = getInstrItineraryForCPU(CPUName);
  158. // Parse features string.
  159. ParseSubtargetFeatures(CPUName, /*TuneCPU*/ CPUName, FS);
  160. // If the user requested use of 64-bit regs, but the cpu selected doesn't
  161. // support it, ignore.
  162. if (IsPPC64 && has64BitSupport())
  163. Use64BitRegs = true;
  164. if ((TargetTriple.isOSFreeBSD() && TargetTriple.getOSMajorVersion() >= 13) ||
  165. TargetTriple.isOSNetBSD() || TargetTriple.isOSOpenBSD() ||
  166. TargetTriple.isMusl())
  167. SecurePlt = true;
  168. if (HasSPE && IsPPC64)
  169. report_fatal_error( "SPE is only supported for 32-bit targets.\n", false);
  170. if (HasSPE && (HasAltivec || HasVSX || HasFPU))
  171. report_fatal_error(
  172. "SPE and traditional floating point cannot both be enabled.\n", false);
  173. // If not SPE, set standard FPU
  174. if (!HasSPE)
  175. HasFPU = true;
  176. StackAlignment = getPlatformStackAlignment();
  177. // Determine endianness.
  178. IsLittleEndian = TM.isLittleEndian();
  179. }
  180. bool PPCSubtarget::enableMachineScheduler() const { return true; }
  181. bool PPCSubtarget::enableMachinePipeliner() const {
  182. return getSchedModel().hasInstrSchedModel() && EnableMachinePipeliner;
  183. }
  184. bool PPCSubtarget::useDFAforSMS() const { return false; }
  185. // This overrides the PostRAScheduler bit in the SchedModel for each CPU.
  186. bool PPCSubtarget::enablePostRAScheduler() const { return true; }
  187. PPCGenSubtargetInfo::AntiDepBreakMode PPCSubtarget::getAntiDepBreakMode() const {
  188. return TargetSubtargetInfo::ANTIDEP_ALL;
  189. }
  190. void PPCSubtarget::getCriticalPathRCs(RegClassVector &CriticalPathRCs) const {
  191. CriticalPathRCs.clear();
  192. CriticalPathRCs.push_back(isPPC64() ?
  193. &PPC::G8RCRegClass : &PPC::GPRCRegClass);
  194. }
  195. void PPCSubtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
  196. unsigned NumRegionInstrs) const {
  197. // The GenericScheduler that we use defaults to scheduling bottom up only.
  198. // We want to schedule from both the top and the bottom and so we set
  199. // OnlyBottomUp to false.
  200. // We want to do bi-directional scheduling since it provides a more balanced
  201. // schedule leading to better performance.
  202. Policy.OnlyBottomUp = false;
  203. // Spilling is generally expensive on all PPC cores, so always enable
  204. // register-pressure tracking.
  205. Policy.ShouldTrackPressure = true;
  206. }
  207. bool PPCSubtarget::useAA() const {
  208. return true;
  209. }
  210. bool PPCSubtarget::enableSubRegLiveness() const {
  211. return UseSubRegLiveness;
  212. }
  213. bool PPCSubtarget::isGVIndirectSymbol(const GlobalValue *GV) const {
  214. // Large code model always uses the TOC even for local symbols.
  215. if (TM.getCodeModel() == CodeModel::Large)
  216. return true;
  217. if (TM.shouldAssumeDSOLocal(*GV->getParent(), GV))
  218. return false;
  219. return true;
  220. }
  221. bool PPCSubtarget::isELFv2ABI() const { return TM.isELFv2ABI(); }
  222. bool PPCSubtarget::isPPC64() const { return TM.isPPC64(); }
  223. bool PPCSubtarget::isUsingPCRelativeCalls() const {
  224. return isPPC64() && hasPCRelativeMemops() && isELFv2ABI() &&
  225. CodeModel::Medium == getTargetMachine().getCodeModel();
  226. }
  227. // GlobalISEL
  228. const CallLowering *PPCSubtarget::getCallLowering() const {
  229. return CallLoweringInfo.get();
  230. }
  231. const RegisterBankInfo *PPCSubtarget::getRegBankInfo() const {
  232. return RegBankInfo.get();
  233. }
  234. const LegalizerInfo *PPCSubtarget::getLegalizerInfo() const {
  235. return Legalizer.get();
  236. }
  237. InstructionSelector *PPCSubtarget::getInstructionSelector() const {
  238. return InstSelector.get();
  239. }