Sparc.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. //===--- Sparc.cpp - Tools Implementations ----------------------*- 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. #include "Sparc.h"
  9. #include "clang/Driver/Driver.h"
  10. #include "clang/Driver/DriverDiagnostic.h"
  11. #include "clang/Driver/Options.h"
  12. #include "llvm/ADT/StringSwitch.h"
  13. #include "llvm/Option/ArgList.h"
  14. using namespace clang::driver;
  15. using namespace clang::driver::tools;
  16. using namespace clang;
  17. using namespace llvm::opt;
  18. const char *sparc::getSparcAsmModeForCPU(StringRef Name,
  19. const llvm::Triple &Triple) {
  20. if (Triple.getArch() == llvm::Triple::sparcv9) {
  21. const char *DefV9CPU;
  22. if (Triple.isOSLinux() || Triple.isOSFreeBSD() || Triple.isOSOpenBSD())
  23. DefV9CPU = "-Av9a";
  24. else
  25. DefV9CPU = "-Av9";
  26. return llvm::StringSwitch<const char *>(Name)
  27. .Case("niagara", "-Av9b")
  28. .Case("niagara2", "-Av9b")
  29. .Case("niagara3", "-Av9d")
  30. .Case("niagara4", "-Av9d")
  31. .Default(DefV9CPU);
  32. } else {
  33. return llvm::StringSwitch<const char *>(Name)
  34. .Case("v8", "-Av8")
  35. .Case("supersparc", "-Av8")
  36. .Case("sparclite", "-Asparclite")
  37. .Case("f934", "-Asparclite")
  38. .Case("hypersparc", "-Av8")
  39. .Case("sparclite86x", "-Asparclite")
  40. .Case("sparclet", "-Asparclet")
  41. .Case("tsc701", "-Asparclet")
  42. .Case("v9", "-Av8plus")
  43. .Case("ultrasparc", "-Av8plus")
  44. .Case("ultrasparc3", "-Av8plus")
  45. .Case("niagara", "-Av8plusb")
  46. .Case("niagara2", "-Av8plusb")
  47. .Case("niagara3", "-Av8plusd")
  48. .Case("niagara4", "-Av8plusd")
  49. .Case("ma2100", "-Aleon")
  50. .Case("ma2150", "-Aleon")
  51. .Case("ma2155", "-Aleon")
  52. .Case("ma2450", "-Aleon")
  53. .Case("ma2455", "-Aleon")
  54. .Case("ma2x5x", "-Aleon")
  55. .Case("ma2080", "-Aleon")
  56. .Case("ma2085", "-Aleon")
  57. .Case("ma2480", "-Aleon")
  58. .Case("ma2485", "-Aleon")
  59. .Case("ma2x8x", "-Aleon")
  60. .Case("myriad2", "-Aleon")
  61. .Case("myriad2.1", "-Aleon")
  62. .Case("myriad2.2", "-Aleon")
  63. .Case("myriad2.3", "-Aleon")
  64. .Case("leon2", "-Av8")
  65. .Case("at697e", "-Av8")
  66. .Case("at697f", "-Av8")
  67. .Case("leon3", "-Aleon")
  68. .Case("ut699", "-Av8")
  69. .Case("gr712rc", "-Aleon")
  70. .Case("leon4", "-Aleon")
  71. .Case("gr740", "-Aleon")
  72. .Default("-Av8");
  73. }
  74. }
  75. sparc::FloatABI sparc::getSparcFloatABI(const Driver &D,
  76. const ArgList &Args) {
  77. sparc::FloatABI ABI = sparc::FloatABI::Invalid;
  78. if (Arg *A = Args.getLastArg(clang::driver::options::OPT_msoft_float,
  79. options::OPT_mhard_float,
  80. options::OPT_mfloat_abi_EQ)) {
  81. if (A->getOption().matches(clang::driver::options::OPT_msoft_float))
  82. ABI = sparc::FloatABI::Soft;
  83. else if (A->getOption().matches(options::OPT_mhard_float))
  84. ABI = sparc::FloatABI::Hard;
  85. else {
  86. ABI = llvm::StringSwitch<sparc::FloatABI>(A->getValue())
  87. .Case("soft", sparc::FloatABI::Soft)
  88. .Case("hard", sparc::FloatABI::Hard)
  89. .Default(sparc::FloatABI::Invalid);
  90. if (ABI == sparc::FloatABI::Invalid &&
  91. !StringRef(A->getValue()).empty()) {
  92. D.Diag(clang::diag::err_drv_invalid_mfloat_abi) << A->getAsString(Args);
  93. ABI = sparc::FloatABI::Hard;
  94. }
  95. }
  96. }
  97. // If unspecified, choose the default based on the platform.
  98. // Only the hard-float ABI on Sparc is standardized, and it is the
  99. // default. GCC also supports a nonstandard soft-float ABI mode, also
  100. // implemented in LLVM. However as this is not standard we set the default
  101. // to be hard-float.
  102. if (ABI == sparc::FloatABI::Invalid) {
  103. ABI = sparc::FloatABI::Hard;
  104. }
  105. return ABI;
  106. }
  107. void sparc::getSparcTargetFeatures(const Driver &D, const ArgList &Args,
  108. std::vector<StringRef> &Features) {
  109. sparc::FloatABI FloatABI = sparc::getSparcFloatABI(D, Args);
  110. if (FloatABI == sparc::FloatABI::Soft)
  111. Features.push_back("+soft-float");
  112. }