Skip to content

Commit e0d1c29

Browse files
koachanbrad0
authored andcommitted
[SPARC][clang] Add SPARC target feature flags
This adds some SPARC feature flags to clang, for those that we have in common with GCC: -m[no-]fpu -m[no-]fsmuld -m[no-]popc -m[no-]vis -m[no-]vis2 -m[no-]vis3 -m[hard/soft]-quad-float All have the same meanings as GCC's options (https://gcc.gnu.org/onlinedocs/gcc/SPARC-Options.html). This fixes, among other things, the -mno-fpu part of bug #40792 Reviewed By: nickdesaulniers Differential Revision: https://reviews.llvm.org/D139768
1 parent c9861e5 commit e0d1c29

File tree

3 files changed

+101
-4
lines changed

3 files changed

+101
-4
lines changed

clang/include/clang/Driver/Options.td

+18
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ def m_arm_Features_Group : OptionGroup<"<arm features group>">,
164164
Group<m_Group>, DocName<"ARM">;
165165
def m_hexagon_Features_Group : OptionGroup<"<hexagon features group>">,
166166
Group<m_Group>, DocName<"Hexagon">;
167+
def m_sparc_Features_Group : OptionGroup<"<sparc features group>">,
168+
Group<m_Group>, DocName<"SPARC">;
167169
// The features added by this group will not be added to target features.
168170
// These are explicitly handled.
169171
def m_hexagon_Features_HVX_Group : OptionGroup<"<hexagon features group>">,
@@ -4525,6 +4527,22 @@ def mnvs : Flag<["-"], "mnvs">, Group<m_hexagon_Features_Group>,
45254527
def mno_nvs : Flag<["-"], "mno-nvs">, Group<m_hexagon_Features_Group>,
45264528
Flags<[CC1Option]>, HelpText<"Disable generation of new-value stores">;
45274529

4530+
// SPARC feature flags
4531+
def mfpu : Flag<["-"], "mfpu">, Group<m_sparc_Features_Group>;
4532+
def mno_fpu : Flag<["-"], "mno-fpu">, Group<m_sparc_Features_Group>;
4533+
def mfsmuld : Flag<["-"], "mfsmuld">, Group<m_sparc_Features_Group>;
4534+
def mno_fsmuld : Flag<["-"], "mno-fsmuld">, Group<m_sparc_Features_Group>;
4535+
def mpopc : Flag<["-"], "mpopc">, Group<m_sparc_Features_Group>;
4536+
def mno_popc : Flag<["-"], "mno-popc">, Group<m_sparc_Features_Group>;
4537+
def mvis : Flag<["-"], "mvis">, Group<m_sparc_Features_Group>;
4538+
def mno_vis : Flag<["-"], "mno-vis">, Group<m_sparc_Features_Group>;
4539+
def mvis2 : Flag<["-"], "mvis2">, Group<m_sparc_Features_Group>;
4540+
def mno_vis2 : Flag<["-"], "mno-vis2">, Group<m_sparc_Features_Group>;
4541+
def mvis3 : Flag<["-"], "mvis3">, Group<m_sparc_Features_Group>;
4542+
def mno_vis3 : Flag<["-"], "mno-vis3">, Group<m_sparc_Features_Group>;
4543+
def mhard_quad_float : Flag<["-"], "mhard-quad-float">, Group<m_sparc_Features_Group>;
4544+
def msoft_quad_float : Flag<["-"], "msoft-quad-float">, Group<m_sparc_Features_Group>;
4545+
45284546
// M68k features flags
45294547
def m68000 : Flag<["-"], "m68000">, Group<m_m68k_Features_Group>;
45304548
def m68010 : Flag<["-"], "m68010">, Group<m_m68k_Features_Group>;

clang/lib/Driver/ToolChains/Arch/Sparc.cpp

+49-4
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,14 @@ const char *sparc::getSparcAsmModeForCPU(StringRef Name,
8282
sparc::FloatABI sparc::getSparcFloatABI(const Driver &D,
8383
const ArgList &Args) {
8484
sparc::FloatABI ABI = sparc::FloatABI::Invalid;
85-
if (Arg *A = Args.getLastArg(clang::driver::options::OPT_msoft_float,
86-
options::OPT_mhard_float,
85+
if (Arg *A = Args.getLastArg(options::OPT_msoft_float, options::OPT_mno_fpu,
86+
options::OPT_mhard_float, options::OPT_mfpu,
8787
options::OPT_mfloat_abi_EQ)) {
88-
if (A->getOption().matches(clang::driver::options::OPT_msoft_float))
88+
if (A->getOption().matches(options::OPT_msoft_float) ||
89+
A->getOption().matches(options::OPT_mno_fpu))
8990
ABI = sparc::FloatABI::Soft;
90-
else if (A->getOption().matches(options::OPT_mhard_float))
91+
else if (A->getOption().matches(options::OPT_mhard_float) ||
92+
A->getOption().matches(options::OPT_mfpu))
9193
ABI = sparc::FloatABI::Hard;
9294
else {
9395
ABI = llvm::StringSwitch<sparc::FloatABI>(A->getValue())
@@ -143,4 +145,47 @@ void sparc::getSparcTargetFeatures(const Driver &D, const ArgList &Args,
143145
sparc::FloatABI FloatABI = sparc::getSparcFloatABI(D, Args);
144146
if (FloatABI == sparc::FloatABI::Soft)
145147
Features.push_back("+soft-float");
148+
149+
if (Arg *A = Args.getLastArg(options::OPT_mfsmuld, options::OPT_mno_fsmuld)) {
150+
if (A->getOption().matches(options::OPT_mfsmuld))
151+
Features.push_back("+fsmuld");
152+
else
153+
Features.push_back("-fsmuld");
154+
}
155+
156+
if (Arg *A = Args.getLastArg(options::OPT_mpopc, options::OPT_mno_popc)) {
157+
if (A->getOption().matches(options::OPT_mpopc))
158+
Features.push_back("+popc");
159+
else
160+
Features.push_back("-popc");
161+
}
162+
163+
if (Arg *A = Args.getLastArg(options::OPT_mvis, options::OPT_mno_vis)) {
164+
if (A->getOption().matches(options::OPT_mvis))
165+
Features.push_back("+vis");
166+
else
167+
Features.push_back("-vis");
168+
}
169+
170+
if (Arg *A = Args.getLastArg(options::OPT_mvis2, options::OPT_mno_vis2)) {
171+
if (A->getOption().matches(options::OPT_mvis2))
172+
Features.push_back("+vis2");
173+
else
174+
Features.push_back("-vis2");
175+
}
176+
177+
if (Arg *A = Args.getLastArg(options::OPT_mvis3, options::OPT_mno_vis3)) {
178+
if (A->getOption().matches(options::OPT_mvis3))
179+
Features.push_back("+vis3");
180+
else
181+
Features.push_back("-vis3");
182+
}
183+
184+
if (Arg *A = Args.getLastArg(options::OPT_mhard_quad_float,
185+
options::OPT_msoft_quad_float)) {
186+
if (A->getOption().matches(options::OPT_mhard_quad_float))
187+
Features.push_back("+hard-quad-float");
188+
else
189+
Features.push_back("-hard-quad-float");
190+
}
146191
}
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: %clang --target=sparc -mfpu %s -### 2>&1 | FileCheck -check-prefix=FPU %s
2+
// RUN: %clang --target=sparc -mno-fpu %s -### 2>&1 | FileCheck -check-prefix=NO-FPU %s
3+
// FPU: "-mfloat-abi" "hard"
4+
// NO-FPU: "-mfloat-abi" "soft"
5+
6+
// RUN: %clang --target=sparc -mfsmuld %s -### 2>&1 | FileCheck -check-prefix=FSMULD %s
7+
// RUN: %clang --target=sparc -mno-fsmuld %s -### 2>&1 | FileCheck -check-prefix=NO-FSMULD %s
8+
// FSMULD: "-target-feature" "+fsmuld"
9+
// NO-FSMULD: "-target-feature" "-fsmuld"
10+
11+
// RUN: %clang --target=sparc -mpopc %s -### 2>&1 | FileCheck -check-prefix=POPC %s
12+
// RUN: %clang --target=sparc -mno-popc %s -### 2>&1 | FileCheck -check-prefix=NO-POPC %s
13+
// POPC: "-target-feature" "+popc"
14+
// NO-POPC: "-target-feature" "-popc"
15+
16+
// RUN: %clang --target=sparc -mvis %s -### 2>&1 | FileCheck -check-prefix=VIS %s
17+
// RUN: %clang --target=sparc -mno-vis %s -### 2>&1 | FileCheck -check-prefix=NO-VIS %s
18+
// VIS: "-target-feature" "+vis"
19+
// NO-VIS: "-target-feature" "-vis"
20+
21+
// RUN: %clang --target=sparc -mvis2 %s -### 2>&1 | FileCheck -check-prefix=VIS2 %s
22+
// RUN: %clang --target=sparc -mno-vis2 %s -### 2>&1 | FileCheck -check-prefix=NO-VIS2 %s
23+
// VIS2: "-target-feature" "+vis2"
24+
// NO-VIS2: "-target-feature" "-vis2"
25+
26+
// RUN: %clang --target=sparc -mvis3 %s -### 2>&1 | FileCheck -check-prefix=VIS3 %s
27+
// RUN: %clang --target=sparc -mno-vis3 %s -### 2>&1 | FileCheck -check-prefix=NO-VIS3 %s
28+
// VIS3: "-target-feature" "+vis3"
29+
// NO-VIS3: "-target-feature" "-vis3"
30+
31+
// RUN: %clang --target=sparc -mhard-quad-float %s -### 2>&1 | FileCheck -check-prefix=HARD-QUAD-FLOAT %s
32+
// RUN: %clang --target=sparc -msoft-quad-float %s -### 2>&1 | FileCheck -check-prefix=SOFT-QUAD-FLOAT %s
33+
// HARD-QUAD-FLOAT: "-target-feature" "+hard-quad-float"
34+
// SOFT-QUAD-FLOAT: "-target-feature" "-hard-quad-float"

0 commit comments

Comments
 (0)