SystemZ.cpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //===--- SystemZ.cpp - SystemZ Helpers for Tools ----------------*- 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 "SystemZ.h"
  9. #include "clang/Config/config.h"
  10. #include "clang/Driver/DriverDiagnostic.h"
  11. #include "clang/Driver/Options.h"
  12. #include "llvm/Option/ArgList.h"
  13. #include "llvm/Support/Host.h"
  14. using namespace clang::driver;
  15. using namespace clang::driver::tools;
  16. using namespace clang;
  17. using namespace llvm::opt;
  18. systemz::FloatABI systemz::getSystemZFloatABI(const Driver &D,
  19. const ArgList &Args) {
  20. // Hard float is the default.
  21. systemz::FloatABI ABI = systemz::FloatABI::Hard;
  22. if (Args.hasArg(options::OPT_mfloat_abi_EQ))
  23. D.Diag(diag::err_drv_unsupported_opt)
  24. << Args.getLastArg(options::OPT_mfloat_abi_EQ)->getAsString(Args);
  25. if (Arg *A = Args.getLastArg(clang::driver::options::OPT_msoft_float,
  26. options::OPT_mhard_float))
  27. if (A->getOption().matches(clang::driver::options::OPT_msoft_float))
  28. ABI = systemz::FloatABI::Soft;
  29. return ABI;
  30. }
  31. std::string systemz::getSystemZTargetCPU(const ArgList &Args) {
  32. if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_march_EQ)) {
  33. llvm::StringRef CPUName = A->getValue();
  34. if (CPUName == "native") {
  35. std::string CPU = std::string(llvm::sys::getHostCPUName());
  36. if (!CPU.empty() && CPU != "generic")
  37. return CPU;
  38. else
  39. return "";
  40. }
  41. return std::string(CPUName);
  42. }
  43. return CLANG_SYSTEMZ_DEFAULT_ARCH;
  44. }
  45. void systemz::getSystemZTargetFeatures(const Driver &D, const ArgList &Args,
  46. std::vector<llvm::StringRef> &Features) {
  47. // -m(no-)htm overrides use of the transactional-execution facility.
  48. if (Arg *A = Args.getLastArg(options::OPT_mhtm, options::OPT_mno_htm)) {
  49. if (A->getOption().matches(options::OPT_mhtm))
  50. Features.push_back("+transactional-execution");
  51. else
  52. Features.push_back("-transactional-execution");
  53. }
  54. // -m(no-)vx overrides use of the vector facility.
  55. if (Arg *A = Args.getLastArg(options::OPT_mvx, options::OPT_mno_vx)) {
  56. if (A->getOption().matches(options::OPT_mvx))
  57. Features.push_back("+vector");
  58. else
  59. Features.push_back("-vector");
  60. }
  61. systemz::FloatABI FloatABI = systemz::getSystemZFloatABI(D, Args);
  62. if (FloatABI == systemz::FloatABI::Soft)
  63. Features.push_back("+soft-float");
  64. }