91 lines
3.1 KiB
Diff
91 lines
3.1 KiB
Diff
|
|
From 0ee0f0ebeb098787cb9698887c237606b6ab10c6 Mon Sep 17 00:00:00 2001
|
||
|
|
From: huangxiaoquan <huangxiaoquan1@huawei.com>
|
||
|
|
Date: Wed, 1 Sep 2021 17:07:22 +0800
|
||
|
|
Subject: [PATCH 24/24] [StructReorderFields] Add lto and whole-program gate
|
||
|
|
|
||
|
|
Only enable struct reorder fields optimizations in lto or whole-program.
|
||
|
|
This prevents some .c files from being struct reorder fields optimized
|
||
|
|
while some of them are not optimized during project compilation.
|
||
|
|
|
||
|
|
diff --git a/gcc/ipa-struct-reorg/ipa-struct-reorg.c b/gcc/ipa-struct-reorg/ipa-struct-reorg.c
|
||
|
|
index b0d4fe80797..2bf41e0d83b 100644
|
||
|
|
--- a/gcc/ipa-struct-reorg/ipa-struct-reorg.c
|
||
|
|
+++ b/gcc/ipa-struct-reorg/ipa-struct-reorg.c
|
||
|
|
@@ -6655,7 +6655,9 @@ pass_ipa_struct_reorg::gate (function *)
|
||
|
|
&& flag_lto_partition == LTO_PARTITION_ONE
|
||
|
|
/* Only enable struct optimizations in C since other
|
||
|
|
languages' grammar forbid. */
|
||
|
|
- && lang_c_p ());
|
||
|
|
+ && lang_c_p ()
|
||
|
|
+ /* Only enable struct optimizations in lto or whole_program. */
|
||
|
|
+ && (in_lto_p || flag_whole_program));
|
||
|
|
}
|
||
|
|
|
||
|
|
const pass_data pass_data_ipa_reorder_fields =
|
||
|
|
@@ -6699,7 +6701,9 @@ pass_ipa_reorder_fields::gate (function *)
|
||
|
|
&& flag_lto_partition == LTO_PARTITION_ONE
|
||
|
|
/* Only enable struct optimizations in C since other
|
||
|
|
languages' grammar forbid. */
|
||
|
|
- && lang_c_p ());
|
||
|
|
+ && lang_c_p ()
|
||
|
|
+ /* Only enable struct optimizations in lto or whole_program. */
|
||
|
|
+ && (in_lto_p || flag_whole_program));
|
||
|
|
}
|
||
|
|
|
||
|
|
} // anon namespace
|
||
|
|
diff --git a/gcc/testsuite/gcc.dg/struct/struct_reorg-1.c b/gcc/testsuite/gcc.dg/struct/struct_reorg-1.c
|
||
|
|
index 6565fe8dd63..23444fe8b0d 100644
|
||
|
|
--- a/gcc/testsuite/gcc.dg/struct/struct_reorg-1.c
|
||
|
|
+++ b/gcc/testsuite/gcc.dg/struct/struct_reorg-1.c
|
||
|
|
@@ -1,5 +1,5 @@
|
||
|
|
// { dg-do compile }
|
||
|
|
-// { dg-options "-O3 -flto-partition=one -fipa-struct-reorg -fdump-ipa-all" }
|
||
|
|
+// { dg-options "-O3 -flto-partition=one -fipa-struct-reorg -fdump-ipa-all -fwhole-program" }
|
||
|
|
|
||
|
|
struct a
|
||
|
|
{
|
||
|
|
@@ -21,4 +21,10 @@ int g(void)
|
||
|
|
return b->t;
|
||
|
|
}
|
||
|
|
|
||
|
|
+int main()
|
||
|
|
+{
|
||
|
|
+ f ();
|
||
|
|
+ return g ();
|
||
|
|
+}
|
||
|
|
+
|
||
|
|
/* { dg-final { scan-ipa-dump "No structures to transform." "struct_reorg" } } */
|
||
|
|
diff --git a/gcc/testsuite/gcc.dg/struct/struct_reorg-3.c b/gcc/testsuite/gcc.dg/struct/struct_reorg-3.c
|
||
|
|
index 5864ad46fd3..2d1f95c9935 100644
|
||
|
|
--- a/gcc/testsuite/gcc.dg/struct/struct_reorg-3.c
|
||
|
|
+++ b/gcc/testsuite/gcc.dg/struct/struct_reorg-3.c
|
||
|
|
@@ -1,5 +1,5 @@
|
||
|
|
// { dg-do compile }
|
||
|
|
-// { dg-options "-O3 -flto-partition=one -fipa-struct-reorg -fdump-ipa-all" }
|
||
|
|
+// { dg-options "-O3 -flto-partition=one -fipa-struct-reorg -fdump-ipa-all -fwhole-program" }
|
||
|
|
|
||
|
|
#include <stdlib.h>
|
||
|
|
typedef struct {
|
||
|
|
@@ -10,7 +10,7 @@ typedef struct {
|
||
|
|
compile_stack_elt_t *stack;
|
||
|
|
unsigned size;
|
||
|
|
} compile_stack_type;
|
||
|
|
-void f (const char *p, const char *pend, int c)
|
||
|
|
+__attribute__((noinline)) void f (const char *p, const char *pend, int c)
|
||
|
|
{
|
||
|
|
compile_stack_type compile_stack;
|
||
|
|
while (p != pend)
|
||
|
|
@@ -20,4 +20,9 @@ void f (const char *p, const char *pend, int c)
|
||
|
|
* sizeof (compile_stack_elt_t));
|
||
|
|
}
|
||
|
|
|
||
|
|
+int main()
|
||
|
|
+{
|
||
|
|
+ f (NULL, NULL, 1);
|
||
|
|
+}
|
||
|
|
+
|
||
|
|
/* { dg-final { scan-ipa-dump "Number of structures to transform is 1" "struct_reorg" } } */
|
||
|
|
--
|
||
|
|
2.21.0.windows.1
|
||
|
|
|