From patchwork Thu Oct 19 14:02:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xi Ruoyao X-Patchwork-Id: 155582 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp405812vqb; Thu, 19 Oct 2023 07:04:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGxXGas8baEInbz34I9FN4fx7sEyKYGuZ86dudh9bY18LO2jpSac3CuecH47mD84CBgG3yd X-Received: by 2002:ac8:5c91:0:b0:41c:70b2:32f9 with SMTP id r17-20020ac85c91000000b0041c70b232f9mr2631618qta.41.1697724274676; Thu, 19 Oct 2023 07:04:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697724274; cv=pass; d=google.com; s=arc-20160816; b=HGIpNhcP2LoxwXkoRUoxrhOtEouRTBqxAMf2U3aUZ5dgslEZQnQ0LbaaR7J2mbWgFj fxNhdAmak7n4JAPRhg0m73NwQhub8Gfl1ecUlbebzjW2vakbk92GwxclE4rJyZvKEh+1 +eMtsQkMnlfbTA4FMMsG+WQU9y5vYK3WRv37wvKb2sddC6PTyYeqRuNy67JHgkqFd+e1 2My6/1e0JsMlwcPSsLITmMgIJ1O7OLLfNdrGNvTK7+urTl/gdjvhNL5ux5gfuW5WADdb wlcgQCJNJrRL7uo5ikCPkwxP2a/uepDDOH73NKuUfHvFQraziHbXFzo96CCfMYo4KTj0 QVxA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=Yk+7U5gOR4xB7cqIZejIPHgOepJykBd9O7Q2Y9+vOUU=; fh=Q6zU0KPK9mkW4WcCQLO/dI9yShCKJrND2oM6Xx6eTlQ=; b=Z7l8QzJ1PCdP8Ryb+fGB4dGNrHAy1b3AL1bYscoUdpIj02y4X2u0TRqg1K7YnxWeuK GIz22SJXlWoYd6zOtIGekl6Fd6G2f4iGWd9TDr6JXZF1625Xu8NPEDgy6ZGkGVS9Yn0h mnOzaD4LO0n+varDEzg5BBhCykMMc+COzLT1DNA6j8Zeb9Yn88Wwiu/Smw1daIBztPRd Zd3cbmLEdRWB0TRKRDexfv+YxQo1MZDHwpOK28xAPIAUNY2ZrXjne3P2ZjXLgn2nSUDg NeoPkvTCoHbs2Laq+fz60KlcsdSni8UMl9zHb9X6rLHkAqW4WUrkhhVVLX7pS3YiLvaK eTxg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@xry111.site header.s=default header.b=YovxfX8k; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=xry111.site Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id v3-20020a05622a144300b004197196b0f0si1658454qtx.617.2023.10.19.07.04.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 07:04:34 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@xry111.site header.s=default header.b=YovxfX8k; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=xry111.site Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D3DB23856954 for ; Thu, 19 Oct 2023 14:04:04 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from xry111.site (xry111.site [IPv6:2001:470:683e::1]) by sourceware.org (Postfix) with ESMTPS id 5020A3857705 for ; Thu, 19 Oct 2023 14:03:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5020A3857705 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=xry111.site Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=xry111.site ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5020A3857705 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:470:683e::1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697724210; cv=none; b=qOkZ860y2S/3vVY8SZo8Sx96nakURe3sX/EQLbaHfHeYIEcjGjs7juX+pUBAIqhn9hCaZ9ngmFwcEC2kjhKntdiza6fyhXaPGYqfuHSUDv8ZT+G9gHDF0NC2VU8q5kQGCHdd2L719IRkJg0st+aBBQgSBL7x3qiUw8B8mh+AGfQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697724210; c=relaxed/simple; bh=3CxuVQd8zd/jbgf/CUNnmEJBvSDjciG9WHAhTH7zeZQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=PC5o3QEZK5aMHhyhuAKUKJQnEcxxj9sCPSl19OVP7YWmlLX1sNhpGd7960WcCBKEKmTL72rjfslzHAcRoGIDTpGypQ4YWmeGtc78BtavXFAg5FI9pBiaFQZ7aq76EsiGfYd9L/HXcebc/oA6N+UTU3U6ZjjrVCb8vUux03ZQ99M= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xry111.site; s=default; t=1697724206; bh=3CxuVQd8zd/jbgf/CUNnmEJBvSDjciG9WHAhTH7zeZQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YovxfX8kZuZkukyqV7NnCx3vVGolCRIU0mrKGi4en7yuTjoA04sAek8vXTCOLMSAJ aihDmSfd373vlen5Zmyrt1icTyYEaXg9sOWdMWYDXeBTDRwguObG/KP+vn+BZVt2do q3CTZvu9xpoGng0pxmMc8ZePGX4Y7EbqBh+bbq7g= Received: from stargazer.. (unknown [IPv6:240e:358:1126:f000:dc73:854d:832e:2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id CF6B266AF5; Thu, 19 Oct 2023 10:03:21 -0400 (EDT) From: Xi Ruoyao To: gcc-patches@gcc.gnu.org Cc: chenglulu , i@xen0n.name, xuchenghua@loongson.cn, mengqinggang , Xi Ruoyao Subject: [PATCH 1/5] LoongArch: Add enum-style -mexplicit-relocs= option Date: Thu, 19 Oct 2023 22:02:56 +0800 Message-ID: <20231019140300.50323-2-xry111@xry111.site> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231019140300.50323-1-xry111@xry111.site> References: <20231019140300.50323-1-xry111@xry111.site> MIME-Version: 1.0 X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, LIKELY_SPAM_FROM, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780192928972414526 X-GMAIL-MSGID: 1780192928972414526 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 adecaec3eda..8e412f7536e 100644 --- a/gcc/config/loongarch/genopts/loongarch-strings +++ b/gcc/config/loongarch/genopts/loongarch-strings @@ -63,3 +63,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 4a2d7438f1b..e1fe0c7086e 100644 --- a/gcc/config/loongarch/genopts/loongarch.opt.in +++ b/gcc/config/loongarch/genopts/loongarch.opt.in @@ -170,10 +170,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 769efcb70fb..6e2a6987910 100644 --- a/gcc/config/loongarch/loongarch-def.h +++ b/gcc/config/loongarch/loongarch-def.h @@ -99,6 +99,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 a3e0510493b..072558c28f1 100644 --- a/gcc/config/loongarch/loongarch-str.h +++ b/gcc/config/loongarch/loongarch-str.h @@ -62,4 +62,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 73f0c160e5f..5df8b12ed92 100644 --- a/gcc/config/loongarch/loongarch.cc +++ b/gcc/config/loongarch/loongarch.cc @@ -7387,6 +7387,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; @@ -7417,7 +7436,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) { @@ -7721,7 +7740,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 da3ec2add9a..184e8bea6a5 100644 --- a/gcc/config/loongarch/loongarch.h +++ b/gcc/config/loongarch/loongarch.h @@ -1231,3 +1231,6 @@ struct GTY (()) machine_function (TARGET_HARD_FLOAT_ABI ? (TARGET_DOUBLE_FLOAT_ABI ? 8 : 4) : 0) #define FUNCTION_VALUE_REGNO_P(N) ((N) == GP_RETURN || (N) == FP_RETURN) + +#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 6215abcac04..02946608327 100644 --- a/gcc/config/loongarch/loongarch.opt +++ b/gcc/config/loongarch/loongarch.opt @@ -177,10 +177,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)