]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/lib/Driver/ToolChains/Arch/Sparc.cpp
Merge clang 7.0.1 and several follow-up changes
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / lib / Driver / ToolChains / Arch / Sparc.cpp
1 //===--- Sparc.cpp - Tools Implementations ----------------------*- C++ -*-===//
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 #include "Sparc.h"
11 #include "clang/Driver/Driver.h"
12 #include "clang/Driver/DriverDiagnostic.h"
13 #include "clang/Driver/Options.h"
14 #include "llvm/ADT/StringSwitch.h"
15 #include "llvm/Option/ArgList.h"
16
17 using namespace clang::driver;
18 using namespace clang::driver::tools;
19 using namespace clang;
20 using namespace llvm::opt;
21
22 const char *sparc::getSparcAsmModeForCPU(StringRef Name,
23                                          const llvm::Triple &Triple) {
24   if (Triple.getArch() == llvm::Triple::sparcv9) {
25     return llvm::StringSwitch<const char *>(Name)
26         .Case("niagara", "-Av9b")
27         .Case("niagara2", "-Av9b")
28         .Case("niagara3", "-Av9d")
29         .Case("niagara4", "-Av9d")
30         .Default("-Av9");
31   } else {
32     return llvm::StringSwitch<const char *>(Name)
33         .Case("v8", "-Av8")
34         .Case("supersparc", "-Av8")
35         .Case("sparclite", "-Asparclite")
36         .Case("f934", "-Asparclite")
37         .Case("hypersparc", "-Av8")
38         .Case("sparclite86x", "-Asparclite")
39         .Case("sparclet", "-Asparclet")
40         .Case("tsc701", "-Asparclet")
41         .Case("v9", "-Av8plus")
42         .Case("ultrasparc", "-Av8plus")
43         .Case("ultrasparc3", "-Av8plus")
44         .Case("niagara", "-Av8plusb")
45         .Case("niagara2", "-Av8plusb")
46         .Case("niagara3", "-Av8plusd")
47         .Case("niagara4", "-Av8plusd")
48         .Case("ma2100", "-Aleon")
49         .Case("ma2150", "-Aleon")
50         .Case("ma2155", "-Aleon")
51         .Case("ma2450", "-Aleon")
52         .Case("ma2455", "-Aleon")
53         .Case("ma2x5x", "-Aleon")
54         .Case("ma2080", "-Aleon")
55         .Case("ma2085", "-Aleon")
56         .Case("ma2480", "-Aleon")
57         .Case("ma2485", "-Aleon")
58         .Case("ma2x8x", "-Aleon")
59         .Case("myriad2", "-Aleon")
60         .Case("myriad2.1", "-Aleon")
61         .Case("myriad2.2", "-Aleon")
62         .Case("myriad2.3", "-Aleon")
63         .Case("leon2", "-Av8")
64         .Case("at697e", "-Av8")
65         .Case("at697f", "-Av8")
66         .Case("leon3", "-Aleon")
67         .Case("ut699", "-Av8")
68         .Case("gr712rc", "-Aleon")
69         .Case("leon4", "-Aleon")
70         .Case("gr740", "-Aleon")
71         .Default("-Av8");
72   }
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
98   // If unspecified, choose the default based on the platform.
99   // Only the hard-float ABI on Sparc is standardized, and it is the
100   // default. GCC also supports a nonstandard soft-float ABI mode, also
101   // implemented in LLVM. However as this is not standard we set the default
102   // to be hard-float.
103   if (ABI == sparc::FloatABI::Invalid) {
104     ABI = sparc::FloatABI::Hard;
105   }
106
107   return ABI;
108 }
109
110 void sparc::getSparcTargetFeatures(const Driver &D, const ArgList &Args,
111                                    std::vector<StringRef> &Features) {
112   sparc::FloatABI FloatABI = sparc::getSparcFloatABI(D, Args);
113   if (FloatABI == sparc::FloatABI::Soft)
114     Features.push_back("+soft-float");
115 }