234 lines
9.1 KiB
Diff
234 lines
9.1 KiB
Diff
From 56403837a7859f0a7ccbc56c055261c9adf22fb8 Mon Sep 17 00:00:00 2001
|
|
From: Xi Ruoyao <xry111@xry111.site>
|
|
Date: Mon, 23 Oct 2023 15:23:11 +0800
|
|
Subject: [PATCH 015/188] LoongArch: Add enum-style -mexplicit-relocs= option
|
|
|
|
To take a better balance between scheduling and relaxation when -flto is
|
|
enabled, add three-way -mexplicit-relocs={auto,none,always} options.
|
|
The old -mexplicit-relocs and -mno-explicit-relocs options are still
|
|
supported, they are mapped to -mexplicit-relocs=always and
|
|
-mexplicit-relocs=none.
|
|
|
|
The default choice is determined by probing assembler capabilities at
|
|
build time. If the assembler does not supports explicit relocs at all,
|
|
the default will be none; if it supports explicit relocs but not
|
|
relaxation, the default will be always; if both explicit relocs and
|
|
relaxation are supported, the default will be auto.
|
|
|
|
Currently auto is same as none. We will make auto more clever in
|
|
following changes.
|
|
|
|
gcc/ChangeLog:
|
|
|
|
* config/loongarch/genopts/loongarch-strings: Add strings for
|
|
-mexplicit-relocs={auto,none,always}.
|
|
* config/loongarch/genopts/loongarch.opt.in: Add options for
|
|
-mexplicit-relocs={auto,none,always}.
|
|
* config/loongarch/loongarch-str.h: Regenerate.
|
|
* config/loongarch/loongarch.opt: Regenerate.
|
|
* config/loongarch/loongarch-def.h
|
|
(EXPLICIT_RELOCS_AUTO): Define.
|
|
(EXPLICIT_RELOCS_NONE): Define.
|
|
(EXPLICIT_RELOCS_ALWAYS): Define.
|
|
(N_EXPLICIT_RELOCS_TYPES): Define.
|
|
* config/loongarch/loongarch.cc
|
|
(loongarch_option_override_internal): Error out if the old-style
|
|
-m[no-]explicit-relocs option is used with
|
|
-mexplicit-relocs={auto,none,always} together. Map
|
|
-mno-explicit-relocs to -mexplicit-relocs=none and
|
|
-mexplicit-relocs to -mexplicit-relocs=always for backward
|
|
compatibility. Set a proper default for -mexplicit-relocs=
|
|
based on configure-time probed linker capability. Update a
|
|
diagnostic message to mention -mexplicit-relocs=always instead
|
|
of the old-style -mexplicit-relocs.
|
|
(loongarch_handle_model_attribute): Update a diagnostic message
|
|
to mention -mexplicit-relocs=always instead of the old-style
|
|
-mexplicit-relocs.
|
|
* config/loongarch/loongarch.h (TARGET_EXPLICIT_RELOCS): Define.
|
|
---
|
|
.../loongarch/genopts/loongarch-strings | 6 +++++
|
|
gcc/config/loongarch/genopts/loongarch.opt.in | 21 ++++++++++++++--
|
|
gcc/config/loongarch/loongarch-def.h | 6 +++++
|
|
gcc/config/loongarch/loongarch-str.h | 5 ++++
|
|
gcc/config/loongarch/loongarch.cc | 24 +++++++++++++++++--
|
|
gcc/config/loongarch/loongarch.h | 3 +++
|
|
gcc/config/loongarch/loongarch.opt | 21 ++++++++++++++--
|
|
7 files changed, 80 insertions(+), 6 deletions(-)
|
|
|
|
diff --git a/gcc/config/loongarch/genopts/loongarch-strings b/gcc/config/loongarch/genopts/loongarch-strings
|
|
index eb5086fe3..6c8a42af2 100644
|
|
--- a/gcc/config/loongarch/genopts/loongarch-strings
|
|
+++ b/gcc/config/loongarch/genopts/loongarch-strings
|
|
@@ -65,3 +65,9 @@ STR_CMODEL_TS tiny-static
|
|
STR_CMODEL_MEDIUM medium
|
|
STR_CMODEL_LARGE large
|
|
STR_CMODEL_EXTREME extreme
|
|
+
|
|
+# -mexplicit-relocs
|
|
+OPTSTR_EXPLICIT_RELOCS explicit-relocs
|
|
+STR_EXPLICIT_RELOCS_AUTO auto
|
|
+STR_EXPLICIT_RELOCS_NONE none
|
|
+STR_EXPLICIT_RELOCS_ALWAYS always
|
|
diff --git a/gcc/config/loongarch/genopts/loongarch.opt.in b/gcc/config/loongarch/genopts/loongarch.opt.in
|
|
index 74cf4a7f7..e7df1964a 100644
|
|
--- a/gcc/config/loongarch/genopts/loongarch.opt.in
|
|
+++ b/gcc/config/loongarch/genopts/loongarch.opt.in
|
|
@@ -176,10 +176,27 @@ mmax-inline-memcpy-size=
|
|
Target Joined RejectNegative UInteger Var(loongarch_max_inline_memcpy_size) Init(1024)
|
|
-mmax-inline-memcpy-size=SIZE Set the max size of memcpy to inline, default is 1024.
|
|
|
|
-mexplicit-relocs
|
|
-Target Var(TARGET_EXPLICIT_RELOCS) Init(HAVE_AS_EXPLICIT_RELOCS & !HAVE_AS_MRELAX_OPTION)
|
|
+Enum
|
|
+Name(explicit_relocs) Type(int)
|
|
+The code model option names for -mexplicit-relocs:
|
|
+
|
|
+EnumValue
|
|
+Enum(explicit_relocs) String(@@STR_EXPLICIT_RELOCS_AUTO@@) Value(EXPLICIT_RELOCS_AUTO)
|
|
+
|
|
+EnumValue
|
|
+Enum(explicit_relocs) String(@@STR_EXPLICIT_RELOCS_NONE@@) Value(EXPLICIT_RELOCS_NONE)
|
|
+
|
|
+EnumValue
|
|
+Enum(explicit_relocs) String(@@STR_EXPLICIT_RELOCS_ALWAYS@@) Value(EXPLICIT_RELOCS_ALWAYS)
|
|
+
|
|
+mexplicit-relocs=
|
|
+Target RejectNegative Joined Enum(explicit_relocs) Var(la_opt_explicit_relocs) Init(M_OPT_UNSET)
|
|
Use %reloc() assembly operators.
|
|
|
|
+mexplicit-relocs
|
|
+Target Var(la_opt_explicit_relocs_backward) Init(M_OPT_UNSET)
|
|
+Use %reloc() assembly operators (for backward compatibility).
|
|
+
|
|
; The code model option names for -mcmodel.
|
|
Enum
|
|
Name(cmodel) Type(int)
|
|
diff --git a/gcc/config/loongarch/loongarch-def.h b/gcc/config/loongarch/loongarch-def.h
|
|
index eb8e53b20..4757de14b 100644
|
|
--- a/gcc/config/loongarch/loongarch-def.h
|
|
+++ b/gcc/config/loongarch/loongarch-def.h
|
|
@@ -100,6 +100,12 @@ extern const char* loongarch_cmodel_strings[];
|
|
#define CMODEL_EXTREME 5
|
|
#define N_CMODEL_TYPES 6
|
|
|
|
+/* enum explicit_relocs */
|
|
+#define EXPLICIT_RELOCS_AUTO 0
|
|
+#define EXPLICIT_RELOCS_NONE 1
|
|
+#define EXPLICIT_RELOCS_ALWAYS 2
|
|
+#define N_EXPLICIT_RELOCS_TYPES 3
|
|
+
|
|
/* The common default value for variables whose assignments
|
|
are triggered by command-line options. */
|
|
|
|
diff --git a/gcc/config/loongarch/loongarch-str.h b/gcc/config/loongarch/loongarch-str.h
|
|
index ecfebf9db..037e9e583 100644
|
|
--- a/gcc/config/loongarch/loongarch-str.h
|
|
+++ b/gcc/config/loongarch/loongarch-str.h
|
|
@@ -64,4 +64,9 @@ along with GCC; see the file COPYING3. If not see
|
|
#define STR_CMODEL_LARGE "large"
|
|
#define STR_CMODEL_EXTREME "extreme"
|
|
|
|
+#define OPTSTR_EXPLICIT_RELOCS "explicit-relocs"
|
|
+#define STR_EXPLICIT_RELOCS_AUTO "auto"
|
|
+#define STR_EXPLICIT_RELOCS_NONE "none"
|
|
+#define STR_EXPLICIT_RELOCS_ALWAYS "always"
|
|
+
|
|
#endif /* LOONGARCH_STR_H */
|
|
diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc
|
|
index e22a64600..3258c8655 100644
|
|
--- a/gcc/config/loongarch/loongarch.cc
|
|
+++ b/gcc/config/loongarch/loongarch.cc
|
|
@@ -7383,6 +7383,25 @@ loongarch_option_override_internal (struct gcc_options *opts,
|
|
loongarch_update_gcc_opt_status (&la_target, opts, opts_set);
|
|
loongarch_cpu_option_override (&la_target, opts, opts_set);
|
|
|
|
+ if (la_opt_explicit_relocs != M_OPT_UNSET
|
|
+ && la_opt_explicit_relocs_backward != M_OPT_UNSET)
|
|
+ error ("do not use %qs (with %qs) and %qs (without %qs) together",
|
|
+ "-mexplicit-relocs=", "=",
|
|
+ la_opt_explicit_relocs_backward ? "-mexplicit-relocs"
|
|
+ : "-mno-explicit-relocs", "=");
|
|
+
|
|
+ if (la_opt_explicit_relocs_backward != M_OPT_UNSET)
|
|
+ la_opt_explicit_relocs = (la_opt_explicit_relocs_backward
|
|
+ ? EXPLICIT_RELOCS_ALWAYS
|
|
+ : EXPLICIT_RELOCS_NONE);
|
|
+
|
|
+ if (la_opt_explicit_relocs == M_OPT_UNSET)
|
|
+ la_opt_explicit_relocs = (HAVE_AS_EXPLICIT_RELOCS
|
|
+ ? (HAVE_AS_MRELAX_OPTION
|
|
+ ? EXPLICIT_RELOCS_AUTO
|
|
+ : EXPLICIT_RELOCS_ALWAYS)
|
|
+ : EXPLICIT_RELOCS_NONE);
|
|
+
|
|
if (TARGET_ABI_LP64)
|
|
flag_pcc_struct_return = 0;
|
|
|
|
@@ -7413,7 +7432,7 @@ loongarch_option_override_internal (struct gcc_options *opts,
|
|
case CMODEL_EXTREME:
|
|
if (!TARGET_EXPLICIT_RELOCS)
|
|
error ("code model %qs needs %s",
|
|
- "extreme", "-mexplicit-relocs");
|
|
+ "extreme", "-mexplicit-relocs=always");
|
|
|
|
if (opts->x_flag_plt)
|
|
{
|
|
@@ -7717,7 +7736,8 @@ loongarch_handle_model_attribute (tree *node, tree name, tree arg, int,
|
|
if (!TARGET_EXPLICIT_RELOCS)
|
|
{
|
|
error_at (DECL_SOURCE_LOCATION (decl),
|
|
- "%qE attribute requires %s", name, "-mexplicit-relocs");
|
|
+ "%qE attribute requires %s", name,
|
|
+ "-mexplicit-relocs=always");
|
|
*no_add_attrs = true;
|
|
return NULL_TREE;
|
|
}
|
|
diff --git a/gcc/config/loongarch/loongarch.h b/gcc/config/loongarch/loongarch.h
|
|
index f7ddfc452..6e8ac293a 100644
|
|
--- a/gcc/config/loongarch/loongarch.h
|
|
+++ b/gcc/config/loongarch/loongarch.h
|
|
@@ -1236,3 +1236,6 @@ struct GTY (()) machine_function
|
|
we just need "ibar" to avoid instruction hazard here. */
|
|
#undef CLEAR_INSN_CACHE
|
|
#define CLEAR_INSN_CACHE(beg, end) __builtin_loongarch_ibar (0)
|
|
+
|
|
+#define TARGET_EXPLICIT_RELOCS \
|
|
+ (la_opt_explicit_relocs == EXPLICIT_RELOCS_ALWAYS)
|
|
diff --git a/gcc/config/loongarch/loongarch.opt b/gcc/config/loongarch/loongarch.opt
|
|
index 34bd832bd..44376fd77 100644
|
|
--- a/gcc/config/loongarch/loongarch.opt
|
|
+++ b/gcc/config/loongarch/loongarch.opt
|
|
@@ -183,10 +183,27 @@ mmax-inline-memcpy-size=
|
|
Target Joined RejectNegative UInteger Var(loongarch_max_inline_memcpy_size) Init(1024)
|
|
-mmax-inline-memcpy-size=SIZE Set the max size of memcpy to inline, default is 1024.
|
|
|
|
-mexplicit-relocs
|
|
-Target Var(TARGET_EXPLICIT_RELOCS) Init(HAVE_AS_EXPLICIT_RELOCS & !HAVE_AS_MRELAX_OPTION)
|
|
+Enum
|
|
+Name(explicit_relocs) Type(int)
|
|
+The code model option names for -mexplicit-relocs:
|
|
+
|
|
+EnumValue
|
|
+Enum(explicit_relocs) String(auto) Value(EXPLICIT_RELOCS_AUTO)
|
|
+
|
|
+EnumValue
|
|
+Enum(explicit_relocs) String(none) Value(EXPLICIT_RELOCS_NONE)
|
|
+
|
|
+EnumValue
|
|
+Enum(explicit_relocs) String(always) Value(EXPLICIT_RELOCS_ALWAYS)
|
|
+
|
|
+mexplicit-relocs=
|
|
+Target RejectNegative Joined Enum(explicit_relocs) Var(la_opt_explicit_relocs) Init(M_OPT_UNSET)
|
|
Use %reloc() assembly operators.
|
|
|
|
+mexplicit-relocs
|
|
+Target Var(la_opt_explicit_relocs_backward) Init(M_OPT_UNSET)
|
|
+Use %reloc() assembly operators (for backward compatibility).
|
|
+
|
|
; The code model option names for -mcmodel.
|
|
Enum
|
|
Name(cmodel) Type(int)
|
|
--
|
|
2.43.0
|
|
|