Skip to content

Commit 7de981a

Browse files
author
Simon Dardis
committed
Reland "[mips] Teach the driver to accept -m(no-)gpopt."
This patch teaches the driver to pass -mgpopt by default to the backend when it is supported, i.e. we are using -mno-abicalls. Reviewers: atanasyan, slthakur Differential Revision: https://reviews.llvm.org/D35548 This version fixes a logic error that generated warnings incorrectly and gets rid of spurious arguments to the backend when -mgpopt is not used. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@308619 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent c176e5d commit 7de981a

File tree

6 files changed

+66
-0
lines changed

6 files changed

+66
-0
lines changed

include/clang/Basic/DiagnosticDriverKinds.td

+4
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,10 @@ def warn_target_unsupported_nanlegacy : Warning<
279279
def warn_target_unsupported_compact_branches : Warning<
280280
"ignoring '-mcompact-branches=' option because the '%0' architecture does not"
281281
" support it">, InGroup<UnsupportedCB>;
282+
def warn_drv_unsupported_gpopt : Warning<
283+
"ignoring '-mgpopt' option as it cannot be used with %select{|the implicit"
284+
" usage of}0-mabicalls">,
285+
InGroup<UnsupportedGPOpt>;
282286

283287
def warn_drv_unable_to_find_directory_expected : Warning<
284288
"unable to find %0 directory, expected to be in '%1'">,

include/clang/Basic/DiagnosticGroups.td

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def DoublePromotion : DiagGroup<"double-promotion">;
6161
def EnumTooLarge : DiagGroup<"enum-too-large">;
6262
def UnsupportedNan : DiagGroup<"unsupported-nan">;
6363
def UnsupportedCB : DiagGroup<"unsupported-cb">;
64+
def UnsupportedGPOpt : DiagGroup<"unsupported-gpopt">;
6465
def NonLiteralNullConversion : DiagGroup<"non-literal-null-conversion">;
6566
def NullConversion : DiagGroup<"null-conversion">;
6667
def ImplicitConversionFloatingPointToBool :

include/clang/Driver/Options.td

+6
Original file line numberDiff line numberDiff line change
@@ -2035,6 +2035,12 @@ def mfp64 : Flag<["-"], "mfp64">, Group<m_Group>,
20352035
HelpText<"Use 64-bit floating point registers (MIPS only)">;
20362036
def mfp32 : Flag<["-"], "mfp32">, Group<m_Group>,
20372037
HelpText<"Use 32-bit floating point registers (MIPS only)">;
2038+
def mgpopt : Flag<["-"], "mgpopt">, Group<m_Group>,
2039+
HelpText<"Use GP relative accesses for symbols known to be in a small"
2040+
" data section (MIPS)">;
2041+
def mno_gpopt : Flag<["-"], "mno-gpopt">, Group<m_Group>,
2042+
HelpText<"Do not use GP relative accesses for symbols known to be in a small"
2043+
" data section (MIPS)">;
20382044
def mnan_EQ : Joined<["-"], "mnan=">, Group<m_Group>;
20392045
def mabicalls : Flag<["-"], "mabicalls">, Group<m_Group>,
20402046
HelpText<"Enable SVR4-style position-independent code (Mips only)">;

lib/Driver/ToolChains/Clang.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -1462,6 +1462,30 @@ void Clang::AddMIPSTargetArgs(const ArgList &Args,
14621462
A->claim();
14631463
}
14641464

1465+
Arg *GPOpt = Args.getLastArg(options::OPT_mgpopt, options::OPT_mno_gpopt);
1466+
Arg *ABICalls =
1467+
Args.getLastArg(options::OPT_mabicalls, options::OPT_mno_abicalls);
1468+
1469+
// -mabicalls is the default for many MIPS environments, even with -fno-pic.
1470+
// -mgpopt is the default for static, -fno-pic environments but these two
1471+
// options conflict. We want to be certain that -mno-abicalls -mgpopt is
1472+
// the only case where -mllvm -mgpopt is passed.
1473+
// NOTE: We need a warning here or in the backend to warn when -mgpopt is
1474+
// passed explicitly when compiling something with -mabicalls
1475+
// (implictly) in affect. Currently the warning is in the backend.
1476+
bool NoABICalls =
1477+
ABICalls && ABICalls->getOption().matches(options::OPT_mno_abicalls);
1478+
bool WantGPOpt = GPOpt && GPOpt->getOption().matches(options::OPT_mgpopt);
1479+
// We quietly ignore -mno-gpopt as the backend defaults to -mno-gpopt.
1480+
if (NoABICalls && (!GPOpt || WantGPOpt)) {
1481+
CmdArgs.push_back("-mllvm");
1482+
CmdArgs.push_back("-mgpopt");
1483+
} else if ((!ABICalls || (!NoABICalls && ABICalls)) && WantGPOpt)
1484+
D.Diag(diag::warn_drv_unsupported_gpopt) << (ABICalls ? 0 : 1);
1485+
1486+
if (GPOpt)
1487+
GPOpt->claim();
1488+
14651489
if (Arg *A = Args.getLastArg(options::OPT_mcompact_branches_EQ)) {
14661490
StringRef Val = StringRef(A->getValue());
14671491
if (mips::hasCompactBranches(CPUName)) {

test/Driver/mips-features.c

+25
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,31 @@
1010
// RUN: | FileCheck --check-prefix=CHECK-MNOABICALLS %s
1111
// CHECK-MNOABICALLS: "-target-feature" "+noabicalls"
1212
//
13+
// -mgpopt
14+
// RUN: %clang -target mips-linux-gnu -### -c %s -mno-gpopt -mgpopt -Wno-unsupported-gpopt 2>&1 \
15+
// RUN: | FileCheck --check-prefix=CHECK-MGPOPT-DEF-ABICALLS %s
16+
// CHECK-MGPOPT-DEF-ABICALLS-NOT: "-mllvm" "-mgpopt"
17+
//
18+
// -mabicalls -mgpopt
19+
// RUN: %clang -target mips-linux-gnu -### -c %s -mabicalls -mno-gpopt -mgpopt -Wno-unsupported-gpopt 2>&1 \
20+
// RUN: | FileCheck --check-prefix=CHECK-MGPOPT-EXPLICIT-ABICALLS %s
21+
// CHECK-MGPOPT-EXPLICIT-ABICALLS-NOT: "-mllvm" "-mgpopt"
22+
//
23+
// -mno-abicalls -mgpopt
24+
// RUN: %clang -target mips-linux-gnu -### -c %s -mno-abicalls -mno-gpopt -mgpopt 2>&1 \
25+
// RUN: | FileCheck --check-prefix=CHECK-MGPOPT %s
26+
// CHECK-MGPOPT: "-mllvm" "-mgpopt"
27+
//
28+
// -mno-abicalls -mno-gpopt
29+
// RUN: %clang -target mips-linux-gnu -### -c %s -mno-abicalls -mgpopt -mno-gpopt 2>&1 \
30+
// RUN: | FileCheck --check-prefix=CHECK-MNOGPOPT %s
31+
// CHECK-MNOGPOPT-NOT: "-mllvm" "-mgpopt"
32+
//
33+
// -mno-abicalls
34+
// RUN: %clang -target mips-linux-gnu -### -c %s -mno-abicalls 2>&1 \
35+
// RUN: | FileCheck --check-prefix=CHECK-MGPOPTDEF %s
36+
// CHECK-MGPOPTDEF: "-mllvm" "-mgpopt"
37+
//
1338
// -mips16
1439
// RUN: %clang -target mips-linux-gnu -### -c %s \
1540
// RUN: -mno-mips16 -mips16 2>&1 \

test/Driver/mips-gpopt-warning.c

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// REQUIRES: mips-registered-target
2+
// RUN: %clang -### -c -target mips-mti-elf %s -mgpopt 2>&1 | FileCheck -check-prefix=IMPLICIT %s
3+
// IMPLICIT: warning: ignoring '-mgpopt' option as it cannot be used with the implicit usage of-mabicalls
4+
5+
// RUN: %clang -### -c -target mips-mti-elf %s -mgpopt -mabicalls 2>&1 | FileCheck -check-prefix=EXPLICIT %s
6+
// EXPLICIT: warning: ignoring '-mgpopt' option as it cannot be used with -mabicalls

0 commit comments

Comments
 (0)