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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
From a96315832872aae9af8ff3f81100b21e82c94072 Mon Sep 17 00:00:00 2001
From: liyancheng <412998149@qq.com>
Date: Sat, 7 Dec 2024 16:27:28 +0800
Subject: [PATCH 1/2] [Struct-reorg] Avoid doing struct split and
reorder_fields together
Rewrite between struct_split and reorder_fields is
incompatible, so avoid doing them together.
---
gcc/ipa-struct-reorg/ipa-struct-reorg.cc | 7 +-
.../struct/rf_rewrite_problem_with_split.c | 134 ++++++++++++++++++
gcc/testsuite/gcc.dg/struct/struct-reorg.exp | 4 +
3 files changed, 143 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/struct/rf_rewrite_problem_with_split.c
diff --git a/gcc/ipa-struct-reorg/ipa-struct-reorg.cc b/gcc/ipa-struct-reorg/ipa-struct-reorg.cc
index b93b8a5b5..af91f15c5 100644
--- a/gcc/ipa-struct-reorg/ipa-struct-reorg.cc
+++ b/gcc/ipa-struct-reorg/ipa-struct-reorg.cc
@@ -8646,8 +8646,11 @@ public:
if (level >= COMPLETE_STRUCT_RELAYOUT)
{
- /* Preserved for backward compatibility. */
- ret_reorg = ipa_struct_reorg ().execute (STRUCT_SPLIT);
+ /* Preserved for backward compatibility.
+ Rewrite between STRUCT_REORDER_FIELDS and STRUCT_SPLIT has unfixed
+ problem, so avoid using them together. */
+ if (!ret)
+ ret_reorg = ipa_struct_reorg ().execute (STRUCT_SPLIT);
if (!ret_reorg)
ret_reorg = ipa_struct_reorg ().execute (COMPLETE_STRUCT_RELAYOUT);
}
diff --git a/gcc/testsuite/gcc.dg/struct/rf_rewrite_problem_with_split.c b/gcc/testsuite/gcc.dg/struct/rf_rewrite_problem_with_split.c
new file mode 100644
index 000000000..da357ec18
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/struct/rf_rewrite_problem_with_split.c
@@ -0,0 +1,134 @@
+/* { dg-do run } */
+#include "stdio.h"
+#include "stdlib.h"
+#include "time.h"
+#include "string.h"
+#include "limits.h"
+#include "float.h"
+#define JOTAI_NUM_RANDS_ 25
+const unsigned rand_primes[JOTAI_NUM_RANDS_] = {179, 103, 479, 647, 229, 37,
+271, 557, 263, 607, 18743, 50359, 21929, 48757, 98179, 12907, 52937, 64579,
+49957, 52567, 507163, 149939, 412157, 680861, 757751};
+int next_i() {
+ int counter = 0;
+ return rand_primes[(++counter)%JOTAI_NUM_RANDS_];
+}
+typedef unsigned long size_t; // Customize by platform.
+typedef long intptr_t; typedef unsigned long uintptr_t;
+typedef long scalar_t__; // Either arithmetic or pointer type.
+typedef int bool;
+#define false 0
+#define true 1
+typedef struct TYPE_2__ TYPE_1__;
+struct pci_dev {int devfn; TYPE_1__* sriov; int /*<<< orphan*/ is_physfn; };
+struct TYPE_2__ {int offset; int stride; } ;
+int EINVAL ;
+int pci_iov_virtfn_devfn(struct pci_dev *dev, int vf_id)
+{
+ if (!dev->is_physfn)
+ return -EINVAL;
+ return (dev->devfn + dev->sriov->offset +
+ dev->sriov->stride * vf_id) & 0xff;
+}
+int main(int argc, char *argv[]) {
+ int opt = 1;
+ switch(opt) {
+ case 0:
+ {
+ int vf_id = 100;
+ int _len_dev0 = 1;
+ struct pci_dev * dev =
+ (struct pci_dev *) malloc(_len_dev0*sizeof(struct pci_dev));
+ for(int _i0 = 0; _i0 < _len_dev0; _i0++) {
+ dev[_i0].devfn = ((-2 * (next_i()%2)) + 1) * next_i();
+ int _len_dev__i0__sriov0 = 1;
+ dev[_i0].sriov =
+ (struct TYPE_2__ *) malloc(_len_dev__i0__sriov0*sizeof(struct TYPE_2__));
+ for(int _j0 = 0; _j0 < _len_dev__i0__sriov0; _j0++) {
+ dev[_i0].sriov->offset = ((-2 * (next_i()%2)) + 1) * next_i();
+ dev[_i0].sriov->stride = ((-2 * (next_i()%2)) + 1) * next_i();
+ }
+ dev[_i0].is_physfn = ((-2 * (next_i()%2)) + 1) * next_i();
+ }
+ int benchRet = pci_iov_virtfn_devfn(dev,vf_id);
+ printf("%d\n", benchRet);
+ for(int _aux = 0; _aux < _len_dev0; _aux++) {
+ free(dev[_aux].sriov);
+ }
+ free(dev);
+ break;
+ }
+ case 1:
+ {
+ int vf_id = 255;
+ int _len_dev0 = 65025;
+ struct pci_dev * dev = (struct pci_dev *) malloc(_len_dev0*sizeof(struct pci_dev));
+ for(int _i0 = 0; _i0 < _len_dev0; _i0++) {
+ dev[_i0].devfn = ((-2 * (next_i()%2)) + 1) * next_i();
+ int _len_dev__i0__sriov0 = 1;
+ dev[_i0].sriov = (struct TYPE_2__ *) malloc(_len_dev__i0__sriov0*sizeof(struct TYPE_2__));
+ for(int _j0 = 0; _j0 < _len_dev__i0__sriov0; _j0++) {
+ dev[_i0].sriov->offset = ((-2 * (next_i()%2)) + 1) * next_i();
+ dev[_i0].sriov->stride = ((-2 * (next_i()%2)) + 1) * next_i();
+ }
+ dev[_i0].is_physfn = ((-2 * (next_i()%2)) + 1) * next_i();
+ }
+ int benchRet = pci_iov_virtfn_devfn(dev,vf_id);
+ printf("%d\n", benchRet);
+ for(int _aux = 0; _aux < _len_dev0; _aux++) {
+ free(dev[_aux].sriov);
+ }
+ free(dev);
+ break;
+ }
+ case 2:
+ {
+ int vf_id = 10;
+ int _len_dev0 = 100;
+ struct pci_dev * dev = (struct pci_dev *) malloc(_len_dev0*sizeof(struct pci_dev));
+ for(int _i0 = 0; _i0 < _len_dev0; _i0++) {
+ dev[_i0].devfn = ((-2 * (next_i()%2)) + 1) * next_i();
+ int _len_dev__i0__sriov0 = 1;
+ dev[_i0].sriov = (struct TYPE_2__ *) malloc(_len_dev__i0__sriov0*sizeof(struct TYPE_2__));
+ for(int _j0 = 0; _j0 < _len_dev__i0__sriov0; _j0++) {
+ dev[_i0].sriov->offset = ((-2 * (next_i()%2)) + 1) * next_i();
+ dev[_i0].sriov->stride = ((-2 * (next_i()%2)) + 1) * next_i();
+ }
+ dev[_i0].is_physfn = ((-2 * (next_i()%2)) + 1) * next_i();
+ }
+ int benchRet = pci_iov_virtfn_devfn(dev,vf_id);
+ printf("%d\n", benchRet);
+ for(int _aux = 0; _aux < _len_dev0; _aux++) {
+ free(dev[_aux].sriov);
+ }
+ free(dev);
+ break;
+ }
+ case 3:
+ {
+ int vf_id = ((-2 * (next_i()%2)) + 1) * next_i();
+ int _len_dev0 = 1;
+ struct pci_dev * dev = (struct pci_dev *) malloc(_len_dev0*sizeof(struct pci_dev));
+ for(int _i0 = 0; _i0 < _len_dev0; _i0++) {
+ dev[_i0].devfn = ((-2 * (next_i()%2)) + 1) * next_i();
+ int _len_dev__i0__sriov0 = 1;
+ dev[_i0].sriov = (struct TYPE_2__ *) malloc(_len_dev__i0__sriov0*sizeof(struct TYPE_2__));
+ for(int _j0 = 0; _j0 < _len_dev__i0__sriov0; _j0++) {
+ dev[_i0].sriov->offset = ((-2 * (next_i()%2)) + 1) * next_i();
+ dev[_i0].sriov->stride = ((-2 * (next_i()%2)) + 1) * next_i();
+ }
+ dev[_i0].is_physfn = ((-2 * (next_i()%2)) + 1) * next_i();
+ }
+ int benchRet = pci_iov_virtfn_devfn(dev,vf_id);
+ printf("%d\n", benchRet);
+ for(int _aux = 0; _aux < _len_dev0; _aux++) {
+ free(dev[_aux].sriov);
+ }
+ free(dev);
+ break;
+ }
+ default:
+ break;
+ }
+ return 0;
+}
\ No newline at end of file
diff --git a/gcc/testsuite/gcc.dg/struct/struct-reorg.exp b/gcc/testsuite/gcc.dg/struct/struct-reorg.exp
index 687f6609f..1ef26229a 100644
--- a/gcc/testsuite/gcc.dg/struct/struct-reorg.exp
+++ b/gcc/testsuite/gcc.dg/struct/struct-reorg.exp
@@ -43,6 +43,10 @@ gcc-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/csr_*.c]] \
gcc-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/rf_*.c]] \
"" "-fipa-reorder-fields -fdump-ipa-all -flto-partition=one -fwhole-program"
+# -fipa-struct-reorg=2
+gcc-dg-runtest $srcdir/$subdir/rf_rewrite_problem_with_split.c \
+ "" "-fipa-struct-reorg=2 -fdump-ipa-all -flto-partition=one -fwhole-program"
+
# -fipa-struct-reorg=3
gcc-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/dfe*.c]] \
"" "-fipa-struct-reorg=3 -fdump-ipa-all -flto-partition=one -fwhole-program"
--
2.25.1
|