PPCSubtarget.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. //===- PowerPCSubtarget.cpp - PPC Subtarget Information -------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file implements the PPC specific subclass of TargetSubtarget.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "PPCSubtarget.h"
  14. #include "PPC.h"
  15. #include "llvm/Module.h"
  16. #include "llvm/Target/TargetMachine.h"
  17. #include "PPCGenSubtarget.inc"
  18. #include <cstdlib>
  19. using namespace llvm;
  20. #if defined(__APPLE__)
  21. #include <mach/mach.h>
  22. #include <mach/mach_host.h>
  23. #include <mach/host_info.h>
  24. #include <mach/machine.h>
  25. /// GetCurrentPowerPCFeatures - Returns the current CPUs features.
  26. static const char *GetCurrentPowerPCCPU() {
  27. host_basic_info_data_t hostInfo;
  28. mach_msg_type_number_t infoCount;
  29. infoCount = HOST_BASIC_INFO_COUNT;
  30. host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo,
  31. &infoCount);
  32. if (hostInfo.cpu_type != CPU_TYPE_POWERPC) return "generic";
  33. switch(hostInfo.cpu_subtype) {
  34. case CPU_SUBTYPE_POWERPC_601: return "601";
  35. case CPU_SUBTYPE_POWERPC_602: return "602";
  36. case CPU_SUBTYPE_POWERPC_603: return "603";
  37. case CPU_SUBTYPE_POWERPC_603e: return "603e";
  38. case CPU_SUBTYPE_POWERPC_603ev: return "603ev";
  39. case CPU_SUBTYPE_POWERPC_604: return "604";
  40. case CPU_SUBTYPE_POWERPC_604e: return "604e";
  41. case CPU_SUBTYPE_POWERPC_620: return "620";
  42. case CPU_SUBTYPE_POWERPC_750: return "750";
  43. case CPU_SUBTYPE_POWERPC_7400: return "7400";
  44. case CPU_SUBTYPE_POWERPC_7450: return "7450";
  45. case CPU_SUBTYPE_POWERPC_970: return "970";
  46. default: ;
  47. }
  48. return "generic";
  49. }
  50. #endif
  51. PPCSubtarget::PPCSubtarget(const TargetMachine &tm, const Module &M,
  52. const std::string &FS, bool is64Bit)
  53. : TM(tm)
  54. , StackAlignment(16)
  55. , DarwinDirective(PPC::DIR_NONE)
  56. , IsGigaProcessor(false)
  57. , Has64BitSupport(false)
  58. , Use64BitRegs(false)
  59. , IsPPC64(is64Bit)
  60. , HasAltivec(false)
  61. , HasFSQRT(false)
  62. , HasSTFIWX(false)
  63. , HasLazyResolverStubs(false)
  64. , DarwinVers(0) {
  65. // Determine default and user specified characteristics
  66. std::string CPU = "generic";
  67. #if defined(__APPLE__)
  68. CPU = GetCurrentPowerPCCPU();
  69. #endif
  70. // Parse features string.
  71. ParseSubtargetFeatures(FS, CPU);
  72. // If we are generating code for ppc64, verify that options make sense.
  73. if (is64Bit) {
  74. Has64BitSupport = true;
  75. // Silently force 64-bit register use on ppc64.
  76. Use64BitRegs = true;
  77. }
  78. // If the user requested use of 64-bit regs, but the cpu selected doesn't
  79. // support it, ignore.
  80. if (use64BitRegs() && !has64BitSupport())
  81. Use64BitRegs = false;
  82. // Set the boolean corresponding to the current target triple, or the default
  83. // if one cannot be determined, to true.
  84. const std::string &TT = M.getTargetTriple();
  85. if (TT.length() > 7) {
  86. // Determine which version of darwin this is.
  87. size_t DarwinPos = TT.find("-darwin");
  88. if (DarwinPos != std::string::npos) {
  89. if (isdigit(TT[DarwinPos+7]))
  90. DarwinVers = atoi(&TT[DarwinPos+7]);
  91. else
  92. DarwinVers = 8; // Minimum supported darwin is Tiger.
  93. }
  94. } else if (TT.empty()) {
  95. // Try to autosense the subtarget from the host compiler.
  96. #if defined(__APPLE__)
  97. #if __APPLE_CC__ > 5400
  98. DarwinVers = 9; // GCC 5400+ is Leopard.
  99. #else
  100. DarwinVers = 8; // Minimum supported darwin is Tiger.
  101. #endif
  102. #endif
  103. }
  104. // Set up darwin-specific properties.
  105. if (isDarwin()) {
  106. HasLazyResolverStubs = true;
  107. AsmFlavor = NewMnemonic;
  108. } else {
  109. AsmFlavor = OldMnemonic;
  110. }
  111. }
  112. /// SetJITMode - This is called to inform the subtarget info that we are
  113. /// producing code for the JIT.
  114. void PPCSubtarget::SetJITMode() {
  115. // JIT mode doesn't want lazy resolver stubs, it knows exactly where
  116. // everything is. This matters for PPC64, which codegens in PIC mode without
  117. // stubs.
  118. HasLazyResolverStubs = false;
  119. }
  120. /// hasLazyResolverStub - Return true if accesses to the specified global have
  121. /// to go through a dyld lazy resolution stub. This means that an extra load
  122. /// is required to get the address of the global.
  123. bool PPCSubtarget::hasLazyResolverStub(const GlobalValue *GV) const {
  124. // We never hae stubs if HasLazyResolverStubs=false or if in static mode.
  125. if (!HasLazyResolverStubs || TM.getRelocationModel() == Reloc::Static)
  126. return false;
  127. // If symbol visibility is hidden, the extra load is not needed if
  128. // the symbol is definitely defined in the current translation unit.
  129. bool isDecl = GV->isDeclaration() && !GV->hasNotBeenReadFromBitcode();
  130. if (GV->hasHiddenVisibility() && !isDecl && !GV->hasCommonLinkage())
  131. return false;
  132. return GV->hasWeakLinkage() || GV->hasLinkOnceLinkage() ||
  133. GV->hasCommonLinkage() || isDecl;
  134. }