1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
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
|