Coverage Report

Created: 2024-01-17 10:31

/src/llvm-project/clang/lib/Driver/ToolChains/Arch/Sparc.cpp
Line
Count
Source (jump to first uncovered line)
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
#include "llvm/TargetParser/Host.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
0
                                         const llvm::Triple &Triple) {
24
0
  if (Triple.getArch() == llvm::Triple::sparcv9) {
25
0
    const char *DefV9CPU;
26
27
0
    if (Triple.isOSLinux() || Triple.isOSFreeBSD() || Triple.isOSOpenBSD())
28
0
      DefV9CPU = "-Av9a";
29
0
    else
30
0
      DefV9CPU = "-Av9";
31
32
0
    return llvm::StringSwitch<const char *>(Name)
33
0
        .Case("niagara", "-Av9b")
34
0
        .Case("niagara2", "-Av9b")
35
0
        .Case("niagara3", "-Av9d")
36
0
        .Case("niagara4", "-Av9d")
37
0
        .Default(DefV9CPU);
38
0
  } else {
39
0
    return llvm::StringSwitch<const char *>(Name)
40
0
        .Case("v8", "-Av8")
41
0
        .Case("supersparc", "-Av8")
42
0
        .Case("sparclite", "-Asparclite")
43
0
        .Case("f934", "-Asparclite")
44
0
        .Case("hypersparc", "-Av8")
45
0
        .Case("sparclite86x", "-Asparclite")
46
0
        .Case("sparclet", "-Asparclet")
47
0
        .Case("tsc701", "-Asparclet")
48
0
        .Case("v9", "-Av8plus")
49
0
        .Case("ultrasparc", "-Av8plus")
50
0
        .Case("ultrasparc3", "-Av8plus")
51
0
        .Case("niagara", "-Av8plusb")
52
0
        .Case("niagara2", "-Av8plusb")
53
0
        .Case("niagara3", "-Av8plusd")
54
0
        .Case("niagara4", "-Av8plusd")
55
0
        .Case("ma2100", "-Aleon")
56
0
        .Case("ma2150", "-Aleon")
57
0
        .Case("ma2155", "-Aleon")
58
0
        .Case("ma2450", "-Aleon")
59
0
        .Case("ma2455", "-Aleon")
60
0
        .Case("ma2x5x", "-Aleon")
61
0
        .Case("ma2080", "-Aleon")
62
0
        .Case("ma2085", "-Aleon")
63
0
        .Case("ma2480", "-Aleon")
64
0
        .Case("ma2485", "-Aleon")
65
0
        .Case("ma2x8x", "-Aleon")
66
0
        .Case("leon2", "-Av8")
67
0
        .Case("at697e", "-Av8")
68
0
        .Case("at697f", "-Av8")
69
0
        .Case("leon3", "-Aleon")
70
0
        .Case("ut699", "-Av8")
71
0
        .Case("gr712rc", "-Aleon")
72
0
        .Case("leon4", "-Aleon")
73
0
        .Case("gr740", "-Aleon")
74
0
        .Default("-Av8");
75
0
  }
76
0
}
77
78
sparc::FloatABI sparc::getSparcFloatABI(const Driver &D,
79
0
                                        const ArgList &Args) {
80
0
  sparc::FloatABI ABI = sparc::FloatABI::Invalid;
81
0
  if (Arg *A = Args.getLastArg(options::OPT_msoft_float, options::OPT_mno_fpu,
82
0
                               options::OPT_mhard_float, options::OPT_mfpu,
83
0
                               options::OPT_mfloat_abi_EQ)) {
84
0
    if (A->getOption().matches(options::OPT_msoft_float) ||
85
0
        A->getOption().matches(options::OPT_mno_fpu))
86
0
      ABI = sparc::FloatABI::Soft;
87
0
    else if (A->getOption().matches(options::OPT_mhard_float) ||
88
0
             A->getOption().matches(options::OPT_mfpu))
89
0
      ABI = sparc::FloatABI::Hard;
90
0
    else {
91
0
      ABI = llvm::StringSwitch<sparc::FloatABI>(A->getValue())
92
0
                .Case("soft", sparc::FloatABI::Soft)
93
0
                .Case("hard", sparc::FloatABI::Hard)
94
0
                .Default(sparc::FloatABI::Invalid);
95
0
      if (ABI == sparc::FloatABI::Invalid &&
96
0
          !StringRef(A->getValue()).empty()) {
97
0
        D.Diag(clang::diag::err_drv_invalid_mfloat_abi) << A->getAsString(Args);
98
0
        ABI = sparc::FloatABI::Hard;
99
0
      }
100
0
    }
101
0
  }
102
103
  // If unspecified, choose the default based on the platform.
104
  // Only the hard-float ABI on Sparc is standardized, and it is the
105
  // default. GCC also supports a nonstandard soft-float ABI mode, also
106
  // implemented in LLVM. However as this is not standard we set the default
107
  // to be hard-float.
108
0
  if (ABI == sparc::FloatABI::Invalid) {
109
0
    ABI = sparc::FloatABI::Hard;
110
0
  }
111
112
0
  return ABI;
113
0
}
114
115
std::string sparc::getSparcTargetCPU(const Driver &D, const ArgList &Args,
116
0
                                     const llvm::Triple &Triple) {
117
0
  if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_mcpu_EQ)) {
118
0
    StringRef CPUName = A->getValue();
119
0
    if (CPUName == "native") {
120
0
      std::string CPU = std::string(llvm::sys::getHostCPUName());
121
0
      if (!CPU.empty() && CPU != "generic")
122
0
        return CPU;
123
0
      return "";
124
0
    }
125
0
    return std::string(CPUName);
126
0
  }
127
128
0
  if (Triple.getArch() == llvm::Triple::sparc && Triple.isOSSolaris())
129
0
    return "v9";
130
0
  return "";
131
0
}
132
133
void sparc::getSparcTargetFeatures(const Driver &D, const ArgList &Args,
134
0
                                   std::vector<StringRef> &Features) {
135
0
  sparc::FloatABI FloatABI = sparc::getSparcFloatABI(D, Args);
136
0
  if (FloatABI == sparc::FloatABI::Soft)
137
0
    Features.push_back("+soft-float");
138
139
0
  if (Arg *A = Args.getLastArg(options::OPT_mfsmuld, options::OPT_mno_fsmuld)) {
140
0
    if (A->getOption().matches(options::OPT_mfsmuld))
141
0
      Features.push_back("+fsmuld");
142
0
    else
143
0
      Features.push_back("-fsmuld");
144
0
  }
145
146
0
  if (Arg *A = Args.getLastArg(options::OPT_mpopc, options::OPT_mno_popc)) {
147
0
    if (A->getOption().matches(options::OPT_mpopc))
148
0
      Features.push_back("+popc");
149
0
    else
150
0
      Features.push_back("-popc");
151
0
  }
152
153
0
  if (Arg *A = Args.getLastArg(options::OPT_mvis, options::OPT_mno_vis)) {
154
0
    if (A->getOption().matches(options::OPT_mvis))
155
0
      Features.push_back("+vis");
156
0
    else
157
0
      Features.push_back("-vis");
158
0
  }
159
160
0
  if (Arg *A = Args.getLastArg(options::OPT_mvis2, options::OPT_mno_vis2)) {
161
0
    if (A->getOption().matches(options::OPT_mvis2))
162
0
      Features.push_back("+vis2");
163
0
    else
164
0
      Features.push_back("-vis2");
165
0
  }
166
167
0
  if (Arg *A = Args.getLastArg(options::OPT_mvis3, options::OPT_mno_vis3)) {
168
0
    if (A->getOption().matches(options::OPT_mvis3))
169
0
      Features.push_back("+vis3");
170
0
    else
171
0
      Features.push_back("-vis3");
172
0
  }
173
174
0
  if (Arg *A = Args.getLastArg(options::OPT_mhard_quad_float,
175
0
                               options::OPT_msoft_quad_float)) {
176
0
    if (A->getOption().matches(options::OPT_mhard_quad_float))
177
0
      Features.push_back("+hard-quad-float");
178
0
    else
179
0
      Features.push_back("-hard-quad-float");
180
0
  }
181
0
}