!210 [sync] PR-201: [Sync] Sync patch from openeuler/gcc

From: @openeuler-sync-bot 
Reviewed-by: @eastb233 
Signed-off-by: @eastb233
This commit is contained in:
openeuler-ci-bot 2022-09-24 02:53:52 +00:00 committed by Gitee
commit 404b6b59b8
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 155 additions and 1 deletions

View File

@ -0,0 +1,146 @@
From b66a843505f32685f428c502f1a88e0f681b4acd Mon Sep 17 00:00:00 2001
From: eastb233 <xiezhiheng@huawei.com>
Date: Thu, 15 Sep 2022 17:57:00 +0800
Subject: [PATCH] [Struct Reorg] Type simplify limitation when in structure
optimizaiton
When enable structure optimization, we should not simplify
TYPE NODE. But now we unconditionally skip the simplification
under structure optimization regardless of whether it takes
effect. So add the same limitation as the optimization has.
---
gcc/ipa-struct-reorg/ipa-struct-reorg.c | 72 ++++++++++++-------------
gcc/tree.c | 13 ++++-
2 files changed, 47 insertions(+), 38 deletions(-)
diff --git a/gcc/ipa-struct-reorg/ipa-struct-reorg.c b/gcc/ipa-struct-reorg/ipa-struct-reorg.c
index 8d3da35400d..54c20ca3f33 100644
--- a/gcc/ipa-struct-reorg/ipa-struct-reorg.c
+++ b/gcc/ipa-struct-reorg/ipa-struct-reorg.c
@@ -104,6 +104,42 @@ along with GCC; see the file COPYING3. If not see
#define VOID_POINTER_P(type) (POINTER_TYPE_P (type) && VOID_TYPE_P (TREE_TYPE (type)))
+/* Check whether in C language or LTO with only C language. */
+bool
+lang_c_p (void)
+{
+ const char *language_string = lang_hooks.name;
+
+ if (!language_string)
+ {
+ return false;
+ }
+
+ if (lang_GNU_C ())
+ {
+ return true;
+ }
+ else if (strcmp (language_string, "GNU GIMPLE") == 0) // for LTO check
+ {
+ unsigned i = 0;
+ tree t = NULL_TREE;
+
+ FOR_EACH_VEC_SAFE_ELT (all_translation_units, i, t)
+ {
+ language_string = TRANSLATION_UNIT_LANGUAGE (t);
+ if (language_string == NULL
+ || strncmp (language_string, "GNU C", 5)
+ || (language_string[5] != '\0'
+ && !(ISDIGIT (language_string[5]))))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+ return false;
+}
+
namespace {
using namespace struct_reorg;
@@ -163,42 +199,6 @@ handled_type (tree type)
return false;
}
-/* Check whether in C language or LTO with only C language. */
-bool
-lang_c_p (void)
-{
- const char *language_string = lang_hooks.name;
-
- if (!language_string)
- {
- return false;
- }
-
- if (lang_GNU_C ())
- {
- return true;
- }
- else if (strcmp (language_string, "GNU GIMPLE") == 0) // for LTO check
- {
- unsigned i = 0;
- tree t = NULL_TREE;
-
- FOR_EACH_VEC_SAFE_ELT (all_translation_units, i, t)
- {
- language_string = TRANSLATION_UNIT_LANGUAGE (t);
- if (language_string == NULL
- || strncmp (language_string, "GNU C", 5)
- || (language_string[5] != '\0'
- && !(ISDIGIT (language_string[5]))))
- {
- return false;
- }
- }
- return true;
- }
- return false;
-}
-
/* Get the number of pointer layers. */
int
diff --git a/gcc/tree.c b/gcc/tree.c
index c2075d73586..84a440b3576 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -128,6 +128,9 @@ const char *const tree_code_class_strings[] =
/* obstack.[ch] explicitly declined to prototype this. */
extern int _obstack_allocated_p (struct obstack *h, void *obj);
+/* Check whether in C language or LTO with only C language. */
+extern bool lang_c_p (void);
+
/* Statistics-gathering stuff. */
static uint64_t tree_code_counts[MAX_TREE_CODES];
@@ -5219,7 +5222,10 @@ fld_simplified_type_name (tree type)
/* Simplify type will cause that struct A and struct A within
struct B are different type pointers, so skip it in structure
optimizations. */
- if (flag_ipa_struct_layout || flag_ipa_struct_reorg)
+ if ((flag_ipa_struct_layout || flag_ipa_struct_reorg)
+ && lang_c_p ()
+ && flag_lto_partition == LTO_PARTITION_ONE
+ && (in_lto_p || flag_whole_program))
return TYPE_NAME (type);
if (!TYPE_NAME (type) || TREE_CODE (TYPE_NAME (type)) != TYPE_DECL)
@@ -5463,7 +5469,10 @@ fld_simplified_type (tree t, class free_lang_data_d *fld)
/* Simplify type will cause that struct A and struct A within
struct B are different type pointers, so skip it in structure
optimizations. */
- if (flag_ipa_struct_layout || flag_ipa_struct_reorg)
+ if ((flag_ipa_struct_layout || flag_ipa_struct_reorg)
+ && lang_c_p ()
+ && flag_lto_partition == LTO_PARTITION_ONE
+ && (in_lto_p || flag_whole_program))
return t;
if (POINTER_TYPE_P (t))
return fld_incomplete_type_of (t, fld);
--
2.21.0.windows.1

View File

@ -61,7 +61,7 @@
Summary: Various compilers (C, C++, Objective-C, ...)
Name: gcc
Version: %{gcc_version}
Release: 15
Release: 16
License: GPLv3+ and GPLv3+ with exceptions and GPLv2+ with exceptions and LGPLv2+ and BSD
URL: https://gcc.gnu.org
@ -161,6 +161,7 @@ Patch42: 0042-DFE-Fix-bugs.patch
Patch45: 0045-Transposed-SLP-Enable-Transposed-SLP.patch
Patch46: 0046-ArrayWidenCompare-Add-a-new-optimization-for-array-c.patch
Patch47: 0047-DFE-Fix-the-bug-caused-by-inconsistent-types.patch
Patch48: 0048-Struct-Reorg-Type-simplify-limitation-when-in-struct.patch
%global gcc_target_platform %{_arch}-linux-gnu
@ -662,6 +663,7 @@ not stable, so plugins must be rebuilt any time GCC is updated.
%patch45 -p1
%patch46 -p1
%patch47 -p1
%patch48 -p1
%build
@ -2682,6 +2684,12 @@ end
%doc rpm.doc/changelogs/libcc1/ChangeLog*
%changelog
* Fri Sep 16 2022 eastb233 <xiezhiheng@huawei.com> - 10.3.1-16
- Type:Sync
- ID:NA
- SUG:NA
- DESC:Sync patch from openeuler/gcc
* Thu Sep 8 2022 benniaobufeijiushiji <linda7@huawei.com> - 10.3.1-15
- Type:Sync
- ID:NA