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
|
From 3cddb0b4960e5983404bbebb11e31ffb62e98350 Mon Sep 17 00:00:00 2001
From: zhongyunde <zhongyunde@huawei.com>
Date: Sat, 13 May 2023 10:04:02 +0800
Subject: [PATCH 1/5] [gimple] Factor the code to avoid depending auto feature
The lambda function with captrue can't use a function pointer
to express, so use a class to model.
---
gcc/config/aarch64/aarch64.c | 8 +--
gcc/gimple-match-head.c | 115 ++++++++++++++++++++++++-----------
2 files changed, 85 insertions(+), 38 deletions(-)
diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index 85dbd3898..10e037325 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -3098,10 +3098,10 @@ aarch64_maxmin_plus_const (rtx_code code, rtx *operands, bool generate_p)
== x <= y ? x - y : 0 [z == y]
== x < y ? x - y : 0 [z == y]
== x < y + 1 ? x - (y + 1) : -1 [z == y + 1]. */
- auto maxmin_val = rtx_mode_t (maxmin_op, mode);
- auto add_val = rtx_mode_t (add_op, mode);
- auto sub_val = wi::neg (add_val);
- auto diff = wi::sub (maxmin_val, sub_val);
+ rtx_mode_t maxmin_val = rtx_mode_t (maxmin_op, mode);
+ rtx_mode_t add_val = rtx_mode_t (add_op, mode);
+ wide_int sub_val = wi::neg (add_val);
+ wide_int diff = wi::sub (maxmin_val, sub_val);
if (!(diff == 0
|| (diff == 1 && wi::gt_p (maxmin_val, sub_val, sgn))
|| (diff == -1 && wi::lt_p (maxmin_val, sub_val, sgn))))
diff --git a/gcc/gimple-match-head.c b/gcc/gimple-match-head.c
index c1dea1734..061aef39c 100644
--- a/gcc/gimple-match-head.c
+++ b/gcc/gimple-match-head.c
@@ -1023,10 +1023,87 @@ gimple_extract (gimple *stmt, gimple_match_op *res_op,
bool
gimple_extract_op (gimple *stmt, gimple_match_op *res_op)
{
- auto nop = [](tree op) { return op; };
+ /* This function is not called by other function now, so leave the
+ lambda to minimize modifiers. */
+ tree (*nop)(tree) = [](tree op)
+ {
+ return op;
+ };
return gimple_extract (stmt, res_op, nop, nop);
}
+/* The std=gnu++98 doesn't support c++ auto feature, and the origin
+ lambda capture some variables, so they can't be replaced with a
+ simple function pointer. */
+class __lambda_valueize
+{
+ typedef tree (*tree_op_func)(tree);
+
+ public:
+ inline tree operator () (tree op) const
+ {
+ return do_valueize (op, top_valueize, valueized);
+ }
+
+ private:
+ tree_op_func &top_valueize;
+ bool &valueized;
+
+ public:
+ __lambda_valueize (tree_op_func &_top_valueize, bool &_valueized)
+ : top_valueize{_top_valueize}, valueized {_valueized}
+ {}
+};
+
+class __lambda_condition
+{
+ typedef tree (*tree_op_func)(tree);
+
+ public:
+ inline tree operator () (tree op) const
+ {
+ bool cond_valueized = false;
+ tree lhs = do_valueize (TREE_OPERAND (op, 0), top_valueize,
+ cond_valueized);
+ tree rhs = do_valueize (TREE_OPERAND (op, 1), top_valueize,
+ cond_valueized);
+ gimple_match_op res_op2 (res_op->cond, TREE_CODE (op),
+ TREE_TYPE (op), lhs, rhs);
+ if ((gimple_resimplify2 (seq, &res_op2, valueize) || cond_valueized)
+ && res_op2.code.is_tree_code ())
+ {
+ if (TREE_CODE_CLASS ((tree_code) res_op2.code) == tcc_comparison)
+ {
+ valueized = true;
+ return build2 (res_op2.code, TREE_TYPE (op), res_op2.ops[0],
+ res_op2.ops[1]);
+ }
+ else if (res_op2.code == SSA_NAME
+ || res_op2.code == INTEGER_CST
+ || res_op2.code == VECTOR_CST)
+ {
+ valueized = true;
+ return res_op2.ops[0];
+ }
+ }
+ return do_valueize (op, top_valueize, valueized);
+ }
+
+ private:
+ tree_op_func &top_valueize;
+ tree_op_func &valueize;
+ bool &valueized;
+ gimple_match_op *&res_op;
+ gimple_seq *&seq;
+
+ public:
+ __lambda_condition (tree_op_func &_top_valueize, tree_op_func &_valueize,
+ bool &_valueized, gimple_match_op *&_res_op, gimple_seq *&_seq)
+ : top_valueize{_top_valueize}, valueize{_valueize}, valueized {_valueized},
+ res_op {_res_op}, seq {_seq}
+ {}
+};
+
/* The main STMT based simplification entry. It is used by the fold_stmt
and the fold_stmt_to_constant APIs. */
@@ -1035,39 +1112,9 @@ gimple_simplify (gimple *stmt, gimple_match_op *res_op, gimple_seq *seq,
tree (*valueize)(tree), tree (*top_valueize)(tree))
{
bool valueized = false;
- auto valueize_op = [&](tree op)
- {
- return do_valueize (op, top_valueize, valueized);
- };
- auto valueize_condition = [&](tree op) -> tree
- {
- bool cond_valueized = false;
- tree lhs = do_valueize (TREE_OPERAND (op, 0), top_valueize,
- cond_valueized);
- tree rhs = do_valueize (TREE_OPERAND (op, 1), top_valueize,
- cond_valueized);
- gimple_match_op res_op2 (res_op->cond, TREE_CODE (op),
- TREE_TYPE (op), lhs, rhs);
- if ((gimple_resimplify2 (seq, &res_op2, valueize)
- || cond_valueized)
- && res_op2.code.is_tree_code ())
- {
- if (TREE_CODE_CLASS ((tree_code) res_op2.code) == tcc_comparison)
- {
- valueized = true;
- return build2 (res_op2.code, TREE_TYPE (op),
- res_op2.ops[0], res_op2.ops[1]);
- }
- else if (res_op2.code == SSA_NAME
- || res_op2.code == INTEGER_CST
- || res_op2.code == VECTOR_CST)
- {
- valueized = true;
- return res_op2.ops[0];
- }
- }
- return valueize_op (op);
- };
+ __lambda_valueize valueize_op = __lambda_valueize{top_valueize, valueized};
+ __lambda_condition valueize_condition = __lambda_condition{top_valueize,
+ valueize, valueized, res_op, seq};
if (!gimple_extract (stmt, res_op, valueize_op, valueize_condition))
return false;
--
2.33.0
|