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