annotate gcc/tree-ssa-coalesce.c @ 143:76e1cf5455ef

add cbc_gc test
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 23 Dec 2018 19:24:05 +0900
parents 84e7813d76e9
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 /* Coalesce SSA_NAMES together for the out-of-ssa pass.
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2 Copyright (C) 2004-2018 Free Software Foundation, Inc.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 Contributed by Andrew MacLeod <amacleod@redhat.com>
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 This file is part of GCC.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 GCC is free software; you can redistribute it and/or modify
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 it under the terms of the GNU General Public License as published by
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 the Free Software Foundation; either version 3, or (at your option)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 any later version.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 GCC is distributed in the hope that it will be useful,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 GNU General Public License for more details.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 along with GCC; see the file COPYING3. If not see
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 <http://www.gnu.org/licenses/>. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 #include "config.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 #include "system.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 #include "coretypes.h"
111
kono
parents: 67
diff changeset
24 #include "backend.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 #include "tree.h"
111
kono
parents: 67
diff changeset
26 #include "gimple.h"
kono
parents: 67
diff changeset
27 #include "predict.h"
kono
parents: 67
diff changeset
28 #include "memmodel.h"
kono
parents: 67
diff changeset
29 #include "tm_p.h"
kono
parents: 67
diff changeset
30 #include "ssa.h"
kono
parents: 67
diff changeset
31 #include "tree-ssa.h"
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
32 #include "tree-pretty-print.h"
111
kono
parents: 67
diff changeset
33 #include "diagnostic-core.h"
kono
parents: 67
diff changeset
34 #include "dumpfile.h"
kono
parents: 67
diff changeset
35 #include "gimple-iterator.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 #include "tree-ssa-live.h"
111
kono
parents: 67
diff changeset
37 #include "tree-ssa-coalesce.h"
kono
parents: 67
diff changeset
38 #include "explow.h"
kono
parents: 67
diff changeset
39 #include "tree-dfa.h"
kono
parents: 67
diff changeset
40 #include "stor-layout.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
41
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 /* This set of routines implements a coalesce_list. This is an object which
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 is used to track pairs of ssa_names which are desirable to coalesce
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
44 together to avoid copies. Costs are associated with each pair, and when
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
45 all desired information has been collected, the object can be used to
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 order the pairs for processing. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 /* This structure defines a pair entry. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49
111
kono
parents: 67
diff changeset
50 struct coalesce_pair
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 int first_element;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 int second_element;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 int cost;
111
kono
parents: 67
diff changeset
55
kono
parents: 67
diff changeset
56 /* A count of the number of unique partitions this pair would conflict
kono
parents: 67
diff changeset
57 with if coalescing was successful. This is the secondary sort key,
kono
parents: 67
diff changeset
58 given two pairs with equal costs, we will prefer the pair with a smaller
kono
parents: 67
diff changeset
59 conflict set.
kono
parents: 67
diff changeset
60
kono
parents: 67
diff changeset
61 This is lazily initialized when we discover two coalescing pairs have
kono
parents: 67
diff changeset
62 the same primary cost.
kono
parents: 67
diff changeset
63
kono
parents: 67
diff changeset
64 Note this is not updated and propagated as pairs are coalesced. */
kono
parents: 67
diff changeset
65 int conflict_count;
kono
parents: 67
diff changeset
66
kono
parents: 67
diff changeset
67 /* The order in which coalescing pairs are discovered is recorded in this
kono
parents: 67
diff changeset
68 field, which is used as the final tie breaker when sorting coalesce
kono
parents: 67
diff changeset
69 pairs. */
kono
parents: 67
diff changeset
70 int index;
kono
parents: 67
diff changeset
71 };
kono
parents: 67
diff changeset
72
kono
parents: 67
diff changeset
73 /* This represents a conflict graph. Implemented as an array of bitmaps.
kono
parents: 67
diff changeset
74 A full matrix is used for conflicts rather than just upper triangular form.
kono
parents: 67
diff changeset
75 this makes it much simpler and faster to perform conflict merges. */
kono
parents: 67
diff changeset
76
kono
parents: 67
diff changeset
77 struct ssa_conflicts
kono
parents: 67
diff changeset
78 {
kono
parents: 67
diff changeset
79 bitmap_obstack obstack; /* A place to allocate our bitmaps. */
kono
parents: 67
diff changeset
80 vec<bitmap> conflicts;
kono
parents: 67
diff changeset
81 };
kono
parents: 67
diff changeset
82
kono
parents: 67
diff changeset
83 /* The narrow API of the qsort comparison function doesn't allow easy
kono
parents: 67
diff changeset
84 access to additional arguments. So we have two globals (ick) to hold
kono
parents: 67
diff changeset
85 the data we need. They're initialized before the call to qsort and
kono
parents: 67
diff changeset
86 wiped immediately after. */
kono
parents: 67
diff changeset
87 static ssa_conflicts *conflicts_;
kono
parents: 67
diff changeset
88 static var_map map_;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
89
111
kono
parents: 67
diff changeset
90 /* Coalesce pair hashtable helpers. */
kono
parents: 67
diff changeset
91
kono
parents: 67
diff changeset
92 struct coalesce_pair_hasher : nofree_ptr_hash <coalesce_pair>
kono
parents: 67
diff changeset
93 {
kono
parents: 67
diff changeset
94 static inline hashval_t hash (const coalesce_pair *);
kono
parents: 67
diff changeset
95 static inline bool equal (const coalesce_pair *, const coalesce_pair *);
kono
parents: 67
diff changeset
96 };
kono
parents: 67
diff changeset
97
kono
parents: 67
diff changeset
98 /* Hash function for coalesce list. Calculate hash for PAIR. */
kono
parents: 67
diff changeset
99
kono
parents: 67
diff changeset
100 inline hashval_t
kono
parents: 67
diff changeset
101 coalesce_pair_hasher::hash (const coalesce_pair *pair)
kono
parents: 67
diff changeset
102 {
kono
parents: 67
diff changeset
103 hashval_t a = (hashval_t)(pair->first_element);
kono
parents: 67
diff changeset
104 hashval_t b = (hashval_t)(pair->second_element);
kono
parents: 67
diff changeset
105
kono
parents: 67
diff changeset
106 return b * (b - 1) / 2 + a;
kono
parents: 67
diff changeset
107 }
kono
parents: 67
diff changeset
108
kono
parents: 67
diff changeset
109 /* Equality function for coalesce list hash table. Compare PAIR1 and PAIR2,
kono
parents: 67
diff changeset
110 returning TRUE if the two pairs are equivalent. */
kono
parents: 67
diff changeset
111
kono
parents: 67
diff changeset
112 inline bool
kono
parents: 67
diff changeset
113 coalesce_pair_hasher::equal (const coalesce_pair *p1, const coalesce_pair *p2)
kono
parents: 67
diff changeset
114 {
kono
parents: 67
diff changeset
115 return (p1->first_element == p2->first_element
kono
parents: 67
diff changeset
116 && p1->second_element == p2->second_element);
kono
parents: 67
diff changeset
117 }
kono
parents: 67
diff changeset
118
kono
parents: 67
diff changeset
119 typedef hash_table<coalesce_pair_hasher> coalesce_table_type;
kono
parents: 67
diff changeset
120 typedef coalesce_table_type::iterator coalesce_iterator_type;
kono
parents: 67
diff changeset
121
kono
parents: 67
diff changeset
122
kono
parents: 67
diff changeset
123 struct cost_one_pair
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 int first_element;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 int second_element;
111
kono
parents: 67
diff changeset
127 cost_one_pair *next;
kono
parents: 67
diff changeset
128 };
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
129
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 /* This structure maintains the list of coalesce pairs. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
131
111
kono
parents: 67
diff changeset
132 struct coalesce_list
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 {
111
kono
parents: 67
diff changeset
134 coalesce_table_type *list; /* Hash table. */
kono
parents: 67
diff changeset
135 coalesce_pair **sorted; /* List when sorted. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 int num_sorted; /* Number in the sorted list. */
111
kono
parents: 67
diff changeset
137 cost_one_pair *cost_one_list;/* Single use coalesces with cost 1. */
kono
parents: 67
diff changeset
138 };
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
139
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
140 #define NO_BEST_COALESCE -1
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 #define MUST_COALESCE_COST INT_MAX
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
142
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
143
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
144 /* Return cost of execution of copy instruction with FREQUENCY. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
145
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 static inline int
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
147 coalesce_cost (int frequency, bool optimize_for_size)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 /* Base costs on BB frequencies bounded by 1. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 int cost = frequency;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
151
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 if (!cost)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 cost = 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
154
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 if (optimize_for_size)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
156 cost = 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
157
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 return cost;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
160
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
161
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
162 /* Return the cost of executing a copy instruction in basic block BB. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
163
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
164 static inline int
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
165 coalesce_cost_bb (basic_block bb)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
167 return coalesce_cost (bb->count.to_frequency (cfun),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
168 optimize_bb_for_size_p (bb));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
169 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
170
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
171
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
172 /* Return the cost of executing a copy instruction on edge E. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
173
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
174 static inline int
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 coalesce_cost_edge (edge e)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 {
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
177 int mult = 1;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
178
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
179 /* Inserting copy on critical edge costs more than inserting it elsewhere. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
180 if (EDGE_CRITICAL_P (e))
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
181 mult = 2;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
182 if (e->flags & EDGE_ABNORMAL)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
183 return MUST_COALESCE_COST;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
184 if (e->flags & EDGE_EH)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
185 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
186 edge e2;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
187 edge_iterator ei;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
188 FOR_EACH_EDGE (e2, ei, e->dest->preds)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
189 if (e2 != e)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
190 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
191 /* Putting code on EH edge that leads to BB
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
192 with multiple predecestors imply splitting of
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
193 edge too. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
194 if (mult < 2)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
195 mult = 2;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
196 /* If there are multiple EH predecestors, we
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
197 also copy EH regions and produce separate
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
198 landing pad. This is expensive. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
199 if (e2->flags & EDGE_EH)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
200 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
201 mult = 5;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
202 break;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
203 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
204 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
205 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
206
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
207 return coalesce_cost (EDGE_FREQUENCY (e),
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
208 optimize_edge_for_size_p (e)) * mult;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
209 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
210
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
211
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
212 /* Retrieve a pair to coalesce from the cost_one_list in CL. Returns the
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
213 2 elements via P1 and P2. 1 is returned by the function if there is a pair,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
214 NO_BEST_COALESCE is returned if there aren't any. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
215
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
216 static inline int
111
kono
parents: 67
diff changeset
217 pop_cost_one_pair (coalesce_list *cl, int *p1, int *p2)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
218 {
111
kono
parents: 67
diff changeset
219 cost_one_pair *ptr;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
220
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
221 ptr = cl->cost_one_list;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
222 if (!ptr)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
223 return NO_BEST_COALESCE;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
224
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
225 *p1 = ptr->first_element;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
226 *p2 = ptr->second_element;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
227 cl->cost_one_list = ptr->next;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
228
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
229 free (ptr);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
230
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
231 return 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
232 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
233
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
234 /* Retrieve the most expensive remaining pair to coalesce from CL. Returns the
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
235 2 elements via P1 and P2. Their calculated cost is returned by the function.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
236 NO_BEST_COALESCE is returned if the coalesce list is empty. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
237
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
238 static inline int
111
kono
parents: 67
diff changeset
239 pop_best_coalesce (coalesce_list *cl, int *p1, int *p2)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
240 {
111
kono
parents: 67
diff changeset
241 coalesce_pair *node;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
242 int ret;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
243
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
244 if (cl->sorted == NULL)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
245 return pop_cost_one_pair (cl, p1, p2);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
246
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
247 if (cl->num_sorted == 0)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
248 return pop_cost_one_pair (cl, p1, p2);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
249
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
250 node = cl->sorted[--(cl->num_sorted)];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
251 *p1 = node->first_element;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
252 *p2 = node->second_element;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
253 ret = node->cost;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
254 free (node);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
255
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
256 return ret;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
257 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
258
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
259
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
260 /* Create a new empty coalesce list object and return it. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
261
111
kono
parents: 67
diff changeset
262 static inline coalesce_list *
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
263 create_coalesce_list (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
264 {
111
kono
parents: 67
diff changeset
265 coalesce_list *list;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
266 unsigned size = num_ssa_names * 3;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
267
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
268 if (size < 40)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
269 size = 40;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
270
111
kono
parents: 67
diff changeset
271 list = (coalesce_list *) xmalloc (sizeof (struct coalesce_list));
kono
parents: 67
diff changeset
272 list->list = new coalesce_table_type (size);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
273 list->sorted = NULL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
274 list->num_sorted = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
275 list->cost_one_list = NULL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
276 return list;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
277 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
278
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
279
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
280 /* Delete coalesce list CL. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
281
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
282 static inline void
111
kono
parents: 67
diff changeset
283 delete_coalesce_list (coalesce_list *cl)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
284 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
285 gcc_assert (cl->cost_one_list == NULL);
111
kono
parents: 67
diff changeset
286 delete cl->list;
kono
parents: 67
diff changeset
287 cl->list = NULL;
kono
parents: 67
diff changeset
288 free (cl->sorted);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
289 gcc_assert (cl->num_sorted == 0);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
290 free (cl);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
291 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
292
111
kono
parents: 67
diff changeset
293 /* Return the number of unique coalesce pairs in CL. */
kono
parents: 67
diff changeset
294
kono
parents: 67
diff changeset
295 static inline int
kono
parents: 67
diff changeset
296 num_coalesce_pairs (coalesce_list *cl)
kono
parents: 67
diff changeset
297 {
kono
parents: 67
diff changeset
298 return cl->list->elements ();
kono
parents: 67
diff changeset
299 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
300
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
301 /* Find a matching coalesce pair object in CL for the pair P1 and P2. If
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
302 one isn't found, return NULL if CREATE is false, otherwise create a new
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
303 coalesce pair object and return it. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
304
111
kono
parents: 67
diff changeset
305 static coalesce_pair *
kono
parents: 67
diff changeset
306 find_coalesce_pair (coalesce_list *cl, int p1, int p2, bool create)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
307 {
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
308 struct coalesce_pair p;
111
kono
parents: 67
diff changeset
309 coalesce_pair **slot;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
310 unsigned int hash;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
311
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
312 /* Normalize so that p1 is the smaller value. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
313 if (p2 < p1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
314 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
315 p.first_element = p2;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
316 p.second_element = p1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
317 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
318 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
319 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
320 p.first_element = p1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
321 p.second_element = p2;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
322 }
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
323
111
kono
parents: 67
diff changeset
324 hash = coalesce_pair_hasher::hash (&p);
kono
parents: 67
diff changeset
325 slot = cl->list->find_slot_with_hash (&p, hash, create ? INSERT : NO_INSERT);
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
326 if (!slot)
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
327 return NULL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
328
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
329 if (!*slot)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
330 {
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
331 struct coalesce_pair * pair = XNEW (struct coalesce_pair);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
332 gcc_assert (cl->sorted == NULL);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
333 pair->first_element = p.first_element;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
334 pair->second_element = p.second_element;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
335 pair->cost = 0;
111
kono
parents: 67
diff changeset
336 pair->index = num_coalesce_pairs (cl);
kono
parents: 67
diff changeset
337 pair->conflict_count = 0;
kono
parents: 67
diff changeset
338 *slot = pair;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
339 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
340
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
341 return (struct coalesce_pair *) *slot;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
342 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
343
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
344 static inline void
111
kono
parents: 67
diff changeset
345 add_cost_one_coalesce (coalesce_list *cl, int p1, int p2)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
346 {
111
kono
parents: 67
diff changeset
347 cost_one_pair *pair;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
348
111
kono
parents: 67
diff changeset
349 pair = XNEW (cost_one_pair);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
350 pair->first_element = p1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
351 pair->second_element = p2;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
352 pair->next = cl->cost_one_list;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
353 cl->cost_one_list = pair;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
354 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
355
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
356
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
357 /* Add a coalesce between P1 and P2 in list CL with a cost of VALUE. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
358
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
359 static inline void
111
kono
parents: 67
diff changeset
360 add_coalesce (coalesce_list *cl, int p1, int p2, int value)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
361 {
111
kono
parents: 67
diff changeset
362 coalesce_pair *node;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
363
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
364 gcc_assert (cl->sorted == NULL);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
365 if (p1 == p2)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
366 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
367
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
368 node = find_coalesce_pair (cl, p1, p2, true);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
369
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
370 /* Once the value is at least MUST_COALESCE_COST - 1, leave it that way. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
371 if (node->cost < MUST_COALESCE_COST - 1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
372 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
373 if (value < MUST_COALESCE_COST - 1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
374 node->cost += value;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
375 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
376 node->cost = value;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
377 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
378 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
379
111
kono
parents: 67
diff changeset
380 /* Compute and record how many unique conflicts would exist for the
kono
parents: 67
diff changeset
381 representative partition for each coalesce pair in CL.
kono
parents: 67
diff changeset
382
kono
parents: 67
diff changeset
383 CONFLICTS is the conflict graph and MAP is the current partition view. */
kono
parents: 67
diff changeset
384
kono
parents: 67
diff changeset
385 static void
kono
parents: 67
diff changeset
386 initialize_conflict_count (coalesce_pair *p,
kono
parents: 67
diff changeset
387 ssa_conflicts *conflicts,
kono
parents: 67
diff changeset
388 var_map map)
kono
parents: 67
diff changeset
389 {
kono
parents: 67
diff changeset
390 int p1 = var_to_partition (map, ssa_name (p->first_element));
kono
parents: 67
diff changeset
391 int p2 = var_to_partition (map, ssa_name (p->second_element));
kono
parents: 67
diff changeset
392
kono
parents: 67
diff changeset
393 /* 4 cases. If both P1 and P2 have conflicts, then build their
kono
parents: 67
diff changeset
394 union and count the members. Else handle the degenerate cases
kono
parents: 67
diff changeset
395 in the obvious ways. */
kono
parents: 67
diff changeset
396 if (conflicts->conflicts[p1] && conflicts->conflicts[p2])
kono
parents: 67
diff changeset
397 p->conflict_count = bitmap_count_unique_bits (conflicts->conflicts[p1],
kono
parents: 67
diff changeset
398 conflicts->conflicts[p2]);
kono
parents: 67
diff changeset
399 else if (conflicts->conflicts[p1])
kono
parents: 67
diff changeset
400 p->conflict_count = bitmap_count_bits (conflicts->conflicts[p1]);
kono
parents: 67
diff changeset
401 else if (conflicts->conflicts[p2])
kono
parents: 67
diff changeset
402 p->conflict_count = bitmap_count_bits (conflicts->conflicts[p2]);
kono
parents: 67
diff changeset
403 else
kono
parents: 67
diff changeset
404 p->conflict_count = 0;
kono
parents: 67
diff changeset
405 }
kono
parents: 67
diff changeset
406
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
407
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
408 /* Comparison function to allow qsort to sort P1 and P2 in Ascending order. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
409
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
410 static int
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
411 compare_pairs (const void *p1, const void *p2)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
412 {
111
kono
parents: 67
diff changeset
413 coalesce_pair *const *const pp1 = (coalesce_pair *const *) p1;
kono
parents: 67
diff changeset
414 coalesce_pair *const *const pp2 = (coalesce_pair *const *) p2;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
415 int result;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
416
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
417 result = (* pp1)->cost - (* pp2)->cost;
111
kono
parents: 67
diff changeset
418 /* We use the size of the resulting conflict set as the secondary sort key.
kono
parents: 67
diff changeset
419 Given two equal costing coalesce pairs, we want to prefer the pair that
kono
parents: 67
diff changeset
420 has the smaller conflict set. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
421 if (result == 0)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
422 {
111
kono
parents: 67
diff changeset
423 if (flag_expensive_optimizations)
kono
parents: 67
diff changeset
424 {
kono
parents: 67
diff changeset
425 /* Lazily initialize the conflict counts as it's fairly expensive
kono
parents: 67
diff changeset
426 to compute. */
kono
parents: 67
diff changeset
427 if ((*pp2)->conflict_count == 0)
kono
parents: 67
diff changeset
428 initialize_conflict_count (*pp2, conflicts_, map_);
kono
parents: 67
diff changeset
429 if ((*pp1)->conflict_count == 0)
kono
parents: 67
diff changeset
430 initialize_conflict_count (*pp1, conflicts_, map_);
kono
parents: 67
diff changeset
431
kono
parents: 67
diff changeset
432 result = (*pp2)->conflict_count - (*pp1)->conflict_count;
kono
parents: 67
diff changeset
433 }
kono
parents: 67
diff changeset
434
kono
parents: 67
diff changeset
435 /* And if everything else is equal, then sort based on which
kono
parents: 67
diff changeset
436 coalesce pair was found first. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
437 if (result == 0)
111
kono
parents: 67
diff changeset
438 result = (*pp2)->index - (*pp1)->index;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
439 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
440
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
441 return result;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
442 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
443
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
444 /* Iterate over CL using ITER, returning values in PAIR. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
445
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
446 #define FOR_EACH_PARTITION_PAIR(PAIR, ITER, CL) \
111
kono
parents: 67
diff changeset
447 FOR_EACH_HASH_TABLE_ELEMENT (*(CL)->list, (PAIR), coalesce_pair_p, (ITER))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
448
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
449
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
450 /* Prepare CL for removal of preferred pairs. When finished they are sorted
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
451 in order from most important coalesce to least important. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
452
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
453 static void
111
kono
parents: 67
diff changeset
454 sort_coalesce_list (coalesce_list *cl, ssa_conflicts *conflicts, var_map map)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
455 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
456 unsigned x, num;
111
kono
parents: 67
diff changeset
457 coalesce_pair *p;
kono
parents: 67
diff changeset
458 coalesce_iterator_type ppi;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
459
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
460 gcc_assert (cl->sorted == NULL);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
461
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
462 num = num_coalesce_pairs (cl);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
463 cl->num_sorted = num;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
464 if (num == 0)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
465 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
466
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
467 /* Allocate a vector for the pair pointers. */
111
kono
parents: 67
diff changeset
468 cl->sorted = XNEWVEC (coalesce_pair *, num);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
469
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
470 /* Populate the vector with pointers to the pairs. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
471 x = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
472 FOR_EACH_PARTITION_PAIR (p, ppi, cl)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
473 cl->sorted[x++] = p;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
474 gcc_assert (x == num);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
475
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
476 /* Already sorted. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
477 if (num == 1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
478 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
479
111
kono
parents: 67
diff changeset
480 /* We don't want to depend on qsort_r, so we have to stuff away
kono
parents: 67
diff changeset
481 additional data into globals so it can be referenced in
kono
parents: 67
diff changeset
482 compare_pairs. */
kono
parents: 67
diff changeset
483 conflicts_ = conflicts;
kono
parents: 67
diff changeset
484 map_ = map;
kono
parents: 67
diff changeset
485 qsort (cl->sorted, num, sizeof (coalesce_pair *), compare_pairs);
kono
parents: 67
diff changeset
486 conflicts_ = NULL;
kono
parents: 67
diff changeset
487 map_ = NULL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
488 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
489
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
490
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
491 /* Send debug info for coalesce list CL to file F. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
492
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
493 static void
111
kono
parents: 67
diff changeset
494 dump_coalesce_list (FILE *f, coalesce_list *cl)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
495 {
111
kono
parents: 67
diff changeset
496 coalesce_pair *node;
kono
parents: 67
diff changeset
497 coalesce_iterator_type ppi;
kono
parents: 67
diff changeset
498
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
499 int x;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
500 tree var;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
501
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
502 if (cl->sorted == NULL)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
503 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
504 fprintf (f, "Coalesce List:\n");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
505 FOR_EACH_PARTITION_PAIR (node, ppi, cl)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
506 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
507 tree var1 = ssa_name (node->first_element);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
508 tree var2 = ssa_name (node->second_element);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
509 print_generic_expr (f, var1, TDF_SLIM);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
510 fprintf (f, " <-> ");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
511 print_generic_expr (f, var2, TDF_SLIM);
111
kono
parents: 67
diff changeset
512 fprintf (f, " (%1d, %1d), ", node->cost, node->conflict_count);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
513 fprintf (f, "\n");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
514 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
515 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
516 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
517 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
518 fprintf (f, "Sorted Coalesce list:\n");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
519 for (x = cl->num_sorted - 1 ; x >=0; x--)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
520 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
521 node = cl->sorted[x];
111
kono
parents: 67
diff changeset
522 fprintf (f, "(%d, %d) ", node->cost, node->conflict_count);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
523 var = ssa_name (node->first_element);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
524 print_generic_expr (f, var, TDF_SLIM);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
525 fprintf (f, " <-> ");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
526 var = ssa_name (node->second_element);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
527 print_generic_expr (f, var, TDF_SLIM);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
528 fprintf (f, "\n");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
529 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
530 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
531 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
532
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
533
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
534 /* Return an empty new conflict graph for SIZE elements. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
535
111
kono
parents: 67
diff changeset
536 static inline ssa_conflicts *
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
537 ssa_conflicts_new (unsigned size)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
538 {
111
kono
parents: 67
diff changeset
539 ssa_conflicts *ptr;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
540
111
kono
parents: 67
diff changeset
541 ptr = XNEW (ssa_conflicts);
kono
parents: 67
diff changeset
542 bitmap_obstack_initialize (&ptr->obstack);
kono
parents: 67
diff changeset
543 ptr->conflicts.create (size);
kono
parents: 67
diff changeset
544 ptr->conflicts.safe_grow_cleared (size);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
545 return ptr;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
546 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
547
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
548
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
549 /* Free storage for conflict graph PTR. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
550
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
551 static inline void
111
kono
parents: 67
diff changeset
552 ssa_conflicts_delete (ssa_conflicts *ptr)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
553 {
111
kono
parents: 67
diff changeset
554 bitmap_obstack_release (&ptr->obstack);
kono
parents: 67
diff changeset
555 ptr->conflicts.release ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
556 free (ptr);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
557 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
558
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
559
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
560 /* Test if elements X and Y conflict in graph PTR. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
561
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
562 static inline bool
111
kono
parents: 67
diff changeset
563 ssa_conflicts_test_p (ssa_conflicts *ptr, unsigned x, unsigned y)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
564 {
111
kono
parents: 67
diff changeset
565 bitmap bx = ptr->conflicts[x];
kono
parents: 67
diff changeset
566 bitmap by = ptr->conflicts[y];
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
567
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
568 gcc_checking_assert (x != y);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
569
111
kono
parents: 67
diff changeset
570 if (bx)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
571 /* Avoid the lookup if Y has no conflicts. */
111
kono
parents: 67
diff changeset
572 return by ? bitmap_bit_p (bx, y) : false;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
573 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
574 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
575 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
576
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
577
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
578 /* Add a conflict with Y to the bitmap for X in graph PTR. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
579
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
580 static inline void
111
kono
parents: 67
diff changeset
581 ssa_conflicts_add_one (ssa_conflicts *ptr, unsigned x, unsigned y)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
582 {
111
kono
parents: 67
diff changeset
583 bitmap bx = ptr->conflicts[x];
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
584 /* If there are no conflicts yet, allocate the bitmap and set bit. */
111
kono
parents: 67
diff changeset
585 if (! bx)
kono
parents: 67
diff changeset
586 bx = ptr->conflicts[x] = BITMAP_ALLOC (&ptr->obstack);
kono
parents: 67
diff changeset
587 bitmap_set_bit (bx, y);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
588 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
589
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
590
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
591 /* Add conflicts between X and Y in graph PTR. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
592
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
593 static inline void
111
kono
parents: 67
diff changeset
594 ssa_conflicts_add (ssa_conflicts *ptr, unsigned x, unsigned y)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
595 {
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
596 gcc_checking_assert (x != y);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
597 ssa_conflicts_add_one (ptr, x, y);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
598 ssa_conflicts_add_one (ptr, y, x);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
599 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
600
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
601
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
602 /* Merge all Y's conflict into X in graph PTR. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
603
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
604 static inline void
111
kono
parents: 67
diff changeset
605 ssa_conflicts_merge (ssa_conflicts *ptr, unsigned x, unsigned y)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
606 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
607 unsigned z;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
608 bitmap_iterator bi;
111
kono
parents: 67
diff changeset
609 bitmap bx = ptr->conflicts[x];
kono
parents: 67
diff changeset
610 bitmap by = ptr->conflicts[y];
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
611
111
kono
parents: 67
diff changeset
612 gcc_checking_assert (x != y);
kono
parents: 67
diff changeset
613 if (! by)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
614 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
615
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
616 /* Add a conflict between X and every one Y has. If the bitmap doesn't
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
617 exist, then it has already been coalesced, and we don't need to add a
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
618 conflict. */
111
kono
parents: 67
diff changeset
619 EXECUTE_IF_SET_IN_BITMAP (by, 0, z, bi)
kono
parents: 67
diff changeset
620 {
kono
parents: 67
diff changeset
621 bitmap bz = ptr->conflicts[z];
kono
parents: 67
diff changeset
622 if (bz)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
623 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
624 bool was_there = bitmap_clear_bit (bz, y);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
625 gcc_checking_assert (was_there);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
626 bitmap_set_bit (bz, x);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
627 }
111
kono
parents: 67
diff changeset
628 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
629
111
kono
parents: 67
diff changeset
630 if (bx)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
631 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
632 /* If X has conflicts, add Y's to X. */
111
kono
parents: 67
diff changeset
633 bitmap_ior_into (bx, by);
kono
parents: 67
diff changeset
634 BITMAP_FREE (by);
kono
parents: 67
diff changeset
635 ptr->conflicts[y] = NULL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
636 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
637 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
638 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
639 /* If X has no conflicts, simply use Y's. */
111
kono
parents: 67
diff changeset
640 ptr->conflicts[x] = by;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
641 ptr->conflicts[y] = NULL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
642 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
643 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
644
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
645
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
646 /* Dump a conflicts graph. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
647
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
648 static void
111
kono
parents: 67
diff changeset
649 ssa_conflicts_dump (FILE *file, ssa_conflicts *ptr)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
650 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
651 unsigned x;
111
kono
parents: 67
diff changeset
652 bitmap b;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
653
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
654 fprintf (file, "\nConflict graph:\n");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
655
111
kono
parents: 67
diff changeset
656 FOR_EACH_VEC_ELT (ptr->conflicts, x, b)
kono
parents: 67
diff changeset
657 if (b)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
658 {
111
kono
parents: 67
diff changeset
659 fprintf (file, "%d: ", x);
kono
parents: 67
diff changeset
660 dump_bitmap (file, b);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
661 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
662 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
663
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
664
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
665 /* This structure is used to efficiently record the current status of live
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
666 SSA_NAMES when building a conflict graph.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
667 LIVE_BASE_VAR has a bit set for each base variable which has at least one
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
668 ssa version live.
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
669 LIVE_BASE_PARTITIONS is an array of bitmaps using the basevar table as an
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
670 index, and is used to track what partitions of each base variable are
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
671 live. This makes it easy to add conflicts between just live partitions
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
672 with the same base variable.
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
673 The values in LIVE_BASE_PARTITIONS are only valid if the base variable is
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
674 marked as being live. This delays clearing of these bitmaps until
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
675 they are actually needed again. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
676
111
kono
parents: 67
diff changeset
677 struct live_track
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
678 {
111
kono
parents: 67
diff changeset
679 bitmap_obstack obstack; /* A place to allocate our bitmaps. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
680 bitmap live_base_var; /* Indicates if a basevar is live. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
681 bitmap *live_base_partitions; /* Live partitions for each basevar. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
682 var_map map; /* Var_map being used for partition mapping. */
111
kono
parents: 67
diff changeset
683 };
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
684
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
685
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
686 /* This routine will create a new live track structure based on the partitions
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
687 in MAP. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
688
111
kono
parents: 67
diff changeset
689 static live_track *
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
690 new_live_track (var_map map)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
691 {
111
kono
parents: 67
diff changeset
692 live_track *ptr;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
693 int lim, x;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
694
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
695 /* Make sure there is a partition view in place. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
696 gcc_assert (map->partition_to_base_index != NULL);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
697
111
kono
parents: 67
diff changeset
698 ptr = (live_track *) xmalloc (sizeof (live_track));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
699 ptr->map = map;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
700 lim = num_basevars (map);
111
kono
parents: 67
diff changeset
701 bitmap_obstack_initialize (&ptr->obstack);
kono
parents: 67
diff changeset
702 ptr->live_base_partitions = (bitmap *) xmalloc (sizeof (bitmap *) * lim);
kono
parents: 67
diff changeset
703 ptr->live_base_var = BITMAP_ALLOC (&ptr->obstack);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
704 for (x = 0; x < lim; x++)
111
kono
parents: 67
diff changeset
705 ptr->live_base_partitions[x] = BITMAP_ALLOC (&ptr->obstack);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
706 return ptr;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
707 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
708
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
709
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
710 /* This routine will free the memory associated with PTR. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
711
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
712 static void
111
kono
parents: 67
diff changeset
713 delete_live_track (live_track *ptr)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
714 {
111
kono
parents: 67
diff changeset
715 bitmap_obstack_release (&ptr->obstack);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
716 free (ptr->live_base_partitions);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
717 free (ptr);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
718 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
719
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
720
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
721 /* This function will remove PARTITION from the live list in PTR. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
722
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
723 static inline void
111
kono
parents: 67
diff changeset
724 live_track_remove_partition (live_track *ptr, int partition)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
725 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
726 int root;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
727
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
728 root = basevar_index (ptr->map, partition);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
729 bitmap_clear_bit (ptr->live_base_partitions[root], partition);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
730 /* If the element list is empty, make the base variable not live either. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
731 if (bitmap_empty_p (ptr->live_base_partitions[root]))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
732 bitmap_clear_bit (ptr->live_base_var, root);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
733 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
734
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
735
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
736 /* This function will adds PARTITION to the live list in PTR. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
737
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
738 static inline void
111
kono
parents: 67
diff changeset
739 live_track_add_partition (live_track *ptr, int partition)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
740 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
741 int root;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
742
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
743 root = basevar_index (ptr->map, partition);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
744 /* If this base var wasn't live before, it is now. Clear the element list
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
745 since it was delayed until needed. */
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
746 if (bitmap_set_bit (ptr->live_base_var, root))
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
747 bitmap_clear (ptr->live_base_partitions[root]);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
748 bitmap_set_bit (ptr->live_base_partitions[root], partition);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
749
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
750 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
751
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
752
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
753 /* Clear the live bit for VAR in PTR. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
754
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
755 static inline void
111
kono
parents: 67
diff changeset
756 live_track_clear_var (live_track *ptr, tree var)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
757 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
758 int p;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
759
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
760 p = var_to_partition (ptr->map, var);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
761 if (p != NO_PARTITION)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
762 live_track_remove_partition (ptr, p);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
763 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
764
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
765
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
766 /* Return TRUE if VAR is live in PTR. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
767
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
768 static inline bool
111
kono
parents: 67
diff changeset
769 live_track_live_p (live_track *ptr, tree var)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
770 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
771 int p, root;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
772
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
773 p = var_to_partition (ptr->map, var);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
774 if (p != NO_PARTITION)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
775 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
776 root = basevar_index (ptr->map, p);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
777 if (bitmap_bit_p (ptr->live_base_var, root))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
778 return bitmap_bit_p (ptr->live_base_partitions[root], p);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
779 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
780 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
781 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
782
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
783
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
784 /* This routine will add USE to PTR. USE will be marked as live in both the
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
785 ssa live map and the live bitmap for the root of USE. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
786
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
787 static inline void
111
kono
parents: 67
diff changeset
788 live_track_process_use (live_track *ptr, tree use)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
789 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
790 int p;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
791
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
792 p = var_to_partition (ptr->map, use);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
793 if (p == NO_PARTITION)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
794 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
795
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
796 /* Mark as live in the appropriate live list. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
797 live_track_add_partition (ptr, p);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
798 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
799
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
800
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
801 /* This routine will process a DEF in PTR. DEF will be removed from the live
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
802 lists, and if there are any other live partitions with the same base
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
803 variable, conflicts will be added to GRAPH. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
804
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
805 static inline void
111
kono
parents: 67
diff changeset
806 live_track_process_def (live_track *ptr, tree def, ssa_conflicts *graph)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
807 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
808 int p, root;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
809 bitmap b;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
810 unsigned x;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
811 bitmap_iterator bi;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
812
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
813 p = var_to_partition (ptr->map, def);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
814 if (p == NO_PARTITION)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
815 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
816
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
817 /* Clear the liveness bit. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
818 live_track_remove_partition (ptr, p);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
819
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
820 /* If the bitmap isn't empty now, conflicts need to be added. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
821 root = basevar_index (ptr->map, p);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
822 if (bitmap_bit_p (ptr->live_base_var, root))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
823 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
824 b = ptr->live_base_partitions[root];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
825 EXECUTE_IF_SET_IN_BITMAP (b, 0, x, bi)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
826 ssa_conflicts_add (graph, p, x);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
827 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
828 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
829
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
830
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
831 /* Initialize PTR with the partitions set in INIT. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
832
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
833 static inline void
111
kono
parents: 67
diff changeset
834 live_track_init (live_track *ptr, bitmap init)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
835 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
836 unsigned p;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
837 bitmap_iterator bi;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
838
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
839 /* Mark all live on exit partitions. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
840 EXECUTE_IF_SET_IN_BITMAP (init, 0, p, bi)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
841 live_track_add_partition (ptr, p);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
842 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
843
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
844
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
845 /* This routine will clear all live partitions in PTR. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
846
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
847 static inline void
111
kono
parents: 67
diff changeset
848 live_track_clear_base_vars (live_track *ptr)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
849 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
850 /* Simply clear the live base list. Anything marked as live in the element
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
851 lists will be cleared later if/when the base variable ever comes alive
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
852 again. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
853 bitmap_clear (ptr->live_base_var);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
854 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
855
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
856
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
857 /* Build a conflict graph based on LIVEINFO. Any partitions which are in the
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
858 partition view of the var_map liveinfo is based on get entries in the
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
859 conflict graph. Only conflicts between ssa_name partitions with the same
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
860 base variable are added. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
861
111
kono
parents: 67
diff changeset
862 static ssa_conflicts *
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
863 build_ssa_conflict_graph (tree_live_info_p liveinfo)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
864 {
111
kono
parents: 67
diff changeset
865 ssa_conflicts *graph;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
866 var_map map;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
867 basic_block bb;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
868 ssa_op_iter iter;
111
kono
parents: 67
diff changeset
869 live_track *live;
kono
parents: 67
diff changeset
870 basic_block entry;
kono
parents: 67
diff changeset
871
kono
parents: 67
diff changeset
872 /* If inter-variable coalescing is enabled, we may attempt to
kono
parents: 67
diff changeset
873 coalesce variables from different base variables, including
kono
parents: 67
diff changeset
874 different parameters, so we have to make sure default defs live
kono
parents: 67
diff changeset
875 at the entry block conflict with each other. */
kono
parents: 67
diff changeset
876 if (flag_tree_coalesce_vars)
kono
parents: 67
diff changeset
877 entry = single_succ (ENTRY_BLOCK_PTR_FOR_FN (cfun));
kono
parents: 67
diff changeset
878 else
kono
parents: 67
diff changeset
879 entry = NULL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
880
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
881 map = live_var_map (liveinfo);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
882 graph = ssa_conflicts_new (num_var_partitions (map));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
883
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
884 live = new_live_track (map);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
885
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
886 for (unsigned i = 0; liveinfo->map->vec_bbs.iterate (i, &bb); ++i)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
887 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
888 /* Start with live on exit temporaries. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
889 live_track_init (live, live_on_exit (liveinfo, bb));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
890
111
kono
parents: 67
diff changeset
891 for (gimple_stmt_iterator gsi = gsi_last_bb (bb); !gsi_end_p (gsi);
kono
parents: 67
diff changeset
892 gsi_prev (&gsi))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
893 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
894 tree var;
111
kono
parents: 67
diff changeset
895 gimple *stmt = gsi_stmt (gsi);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
896
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
897 /* A copy between 2 partitions does not introduce an interference
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
898 by itself. If they did, you would never be able to coalesce
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
899 two things which are copied. If the two variables really do
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
900 conflict, they will conflict elsewhere in the program.
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
901
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
902 This is handled by simply removing the SRC of the copy from the
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
903 live list, and processing the stmt normally. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
904 if (is_gimple_assign (stmt))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
905 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
906 tree lhs = gimple_assign_lhs (stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
907 tree rhs1 = gimple_assign_rhs1 (stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
908 if (gimple_assign_copy_p (stmt)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
909 && TREE_CODE (lhs) == SSA_NAME
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
910 && TREE_CODE (rhs1) == SSA_NAME)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
911 live_track_clear_var (live, rhs1);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
912 }
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
913 else if (is_gimple_debug (stmt))
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
914 continue;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
915
111
kono
parents: 67
diff changeset
916 /* For stmts with more than one SSA_NAME definition pretend all the
kono
parents: 67
diff changeset
917 SSA_NAME outputs but the first one are live at this point, so
kono
parents: 67
diff changeset
918 that conflicts are added in between all those even when they are
kono
parents: 67
diff changeset
919 actually not really live after the asm, because expansion might
kono
parents: 67
diff changeset
920 copy those into pseudos after the asm and if multiple outputs
kono
parents: 67
diff changeset
921 share the same partition, it might overwrite those that should
kono
parents: 67
diff changeset
922 be live. E.g.
kono
parents: 67
diff changeset
923 asm volatile (".." : "=r" (a) : "=r" (b) : "0" (a), "1" (a));
kono
parents: 67
diff changeset
924 return a;
kono
parents: 67
diff changeset
925 See PR70593. */
kono
parents: 67
diff changeset
926 bool first = true;
kono
parents: 67
diff changeset
927 FOR_EACH_SSA_TREE_OPERAND (var, stmt, iter, SSA_OP_DEF)
kono
parents: 67
diff changeset
928 if (first)
kono
parents: 67
diff changeset
929 first = false;
kono
parents: 67
diff changeset
930 else
kono
parents: 67
diff changeset
931 live_track_process_use (live, var);
kono
parents: 67
diff changeset
932
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
933 FOR_EACH_SSA_TREE_OPERAND (var, stmt, iter, SSA_OP_DEF)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
934 live_track_process_def (live, var, graph);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
935
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
936 FOR_EACH_SSA_TREE_OPERAND (var, stmt, iter, SSA_OP_USE)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
937 live_track_process_use (live, var);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
938 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
939
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
940 /* If result of a PHI is unused, looping over the statements will not
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
941 record any conflicts since the def was never live. Since the PHI node
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
942 is going to be translated out of SSA form, it will insert a copy.
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
943 There must be a conflict recorded between the result of the PHI and
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
944 any variables that are live. Otherwise the out-of-ssa translation
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
945 may create incorrect code. */
111
kono
parents: 67
diff changeset
946 for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi);
kono
parents: 67
diff changeset
947 gsi_next (&gsi))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
948 {
111
kono
parents: 67
diff changeset
949 gphi *phi = gsi.phi ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
950 tree result = PHI_RESULT (phi);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
951 if (virtual_operand_p (result))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
952 continue;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
953 if (live_track_live_p (live, result))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
954 live_track_process_def (live, result, graph);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
955 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
956
111
kono
parents: 67
diff changeset
957 /* Pretend there are defs for params' default defs at the start
kono
parents: 67
diff changeset
958 of the (post-)entry block. This will prevent PARM_DECLs from
kono
parents: 67
diff changeset
959 coalescing into the same partition. Although RESULT_DECLs'
kono
parents: 67
diff changeset
960 default defs don't have a useful initial value, we have to
kono
parents: 67
diff changeset
961 prevent them from coalescing with PARM_DECLs' default defs
kono
parents: 67
diff changeset
962 too, otherwise assign_parms would attempt to assign different
kono
parents: 67
diff changeset
963 RTL to the same partition. */
kono
parents: 67
diff changeset
964 if (bb == entry)
kono
parents: 67
diff changeset
965 {
kono
parents: 67
diff changeset
966 unsigned i;
kono
parents: 67
diff changeset
967 tree var;
kono
parents: 67
diff changeset
968
kono
parents: 67
diff changeset
969 FOR_EACH_SSA_NAME (i, var, cfun)
kono
parents: 67
diff changeset
970 {
kono
parents: 67
diff changeset
971 if (!SSA_NAME_IS_DEFAULT_DEF (var)
kono
parents: 67
diff changeset
972 || !SSA_NAME_VAR (var)
kono
parents: 67
diff changeset
973 || VAR_P (SSA_NAME_VAR (var)))
kono
parents: 67
diff changeset
974 continue;
kono
parents: 67
diff changeset
975
kono
parents: 67
diff changeset
976 live_track_process_def (live, var, graph);
kono
parents: 67
diff changeset
977 /* Process a use too, so that it remains live and
kono
parents: 67
diff changeset
978 conflicts with other parms' default defs, even unused
kono
parents: 67
diff changeset
979 ones. */
kono
parents: 67
diff changeset
980 live_track_process_use (live, var);
kono
parents: 67
diff changeset
981 }
kono
parents: 67
diff changeset
982 }
kono
parents: 67
diff changeset
983
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
984 live_track_clear_base_vars (live);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
985 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
986
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
987 delete_live_track (live);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
988 return graph;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
989 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
990
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
991 /* Print a failure to coalesce a MUST_COALESCE pair X and Y. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
992
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
993 static inline void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
994 fail_abnormal_edge_coalesce (int x, int y)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
995 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
996 fprintf (stderr, "\nUnable to coalesce ssa_names %d and %d",x, y);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
997 fprintf (stderr, " which are marked as MUST COALESCE.\n");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
998 print_generic_expr (stderr, ssa_name (x), TDF_SLIM);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
999 fprintf (stderr, " and ");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1000 print_generic_stmt (stderr, ssa_name (y), TDF_SLIM);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1001
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1002 internal_error ("SSA corruption");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1003 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1004
111
kono
parents: 67
diff changeset
1005 /* If VAR is an SSA_NAME associated with a PARM_DECL or a RESULT_DECL,
kono
parents: 67
diff changeset
1006 and the DECL's default def is unused (i.e., it was introduced by
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1007 create_default_def for out-of-ssa), mark VAR and the default def for
111
kono
parents: 67
diff changeset
1008 coalescing. */
kono
parents: 67
diff changeset
1009
kono
parents: 67
diff changeset
1010 static void
kono
parents: 67
diff changeset
1011 coalesce_with_default (tree var, coalesce_list *cl, bitmap used_in_copy)
kono
parents: 67
diff changeset
1012 {
kono
parents: 67
diff changeset
1013 if (SSA_NAME_IS_DEFAULT_DEF (var)
kono
parents: 67
diff changeset
1014 || !SSA_NAME_VAR (var)
kono
parents: 67
diff changeset
1015 || VAR_P (SSA_NAME_VAR (var)))
kono
parents: 67
diff changeset
1016 return;
kono
parents: 67
diff changeset
1017
kono
parents: 67
diff changeset
1018 tree ssa = ssa_default_def (cfun, SSA_NAME_VAR (var));
kono
parents: 67
diff changeset
1019 if (!has_zero_uses (ssa))
kono
parents: 67
diff changeset
1020 return;
kono
parents: 67
diff changeset
1021
kono
parents: 67
diff changeset
1022 add_cost_one_coalesce (cl, SSA_NAME_VERSION (ssa), SSA_NAME_VERSION (var));
kono
parents: 67
diff changeset
1023 bitmap_set_bit (used_in_copy, SSA_NAME_VERSION (var));
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1024 /* Default defs will have their used_in_copy bits set at the beginning of
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1025 populate_coalesce_list_for_outofssa. */
111
kono
parents: 67
diff changeset
1026 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1027
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1028
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1029 /* Given var_map MAP for a region, this function creates and returns a coalesce
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1030 list as well as recording related ssa names in USED_IN_COPIES for use later
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1031 in the out-of-ssa or live range computation process. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1032
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1033 static coalesce_list *
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1034 create_coalesce_list_for_region (var_map map, bitmap used_in_copy)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1035 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1036 gimple_stmt_iterator gsi;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1037 basic_block bb;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1038 coalesce_list *cl = create_coalesce_list ();
111
kono
parents: 67
diff changeset
1039 gimple *stmt;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1040 int v1, v2, cost;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1041
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1042 for (unsigned j = 0; map->vec_bbs.iterate (j, &bb); ++j)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1043 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1044 tree arg;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1045
111
kono
parents: 67
diff changeset
1046 for (gphi_iterator gpi = gsi_start_phis (bb);
kono
parents: 67
diff changeset
1047 !gsi_end_p (gpi);
kono
parents: 67
diff changeset
1048 gsi_next (&gpi))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1049 {
111
kono
parents: 67
diff changeset
1050 gphi *phi = gpi.phi ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1051 size_t i;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1052 int ver;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1053 tree res;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1054 bool saw_copy = false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1055
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1056 res = gimple_phi_result (phi);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1057 if (virtual_operand_p (res))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1058 continue;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1059 ver = SSA_NAME_VERSION (res);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1060
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1061 /* Register ssa_names and coalesces between the args and the result
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1062 of all PHI. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1063 for (i = 0; i < gimple_phi_num_args (phi); i++)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1064 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1065 edge e = gimple_phi_arg_edge (phi, i);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1066 arg = PHI_ARG_DEF (phi, i);
111
kono
parents: 67
diff changeset
1067 if (TREE_CODE (arg) != SSA_NAME)
kono
parents: 67
diff changeset
1068 continue;
kono
parents: 67
diff changeset
1069
kono
parents: 67
diff changeset
1070 if (gimple_can_coalesce_p (arg, res)
kono
parents: 67
diff changeset
1071 || (e->flags & EDGE_ABNORMAL))
kono
parents: 67
diff changeset
1072 {
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1073 saw_copy = true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1074 bitmap_set_bit (used_in_copy, SSA_NAME_VERSION (arg));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1075 if ((e->flags & EDGE_ABNORMAL) == 0)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1076 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1077 int cost = coalesce_cost_edge (e);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1078 if (cost == 1 && has_single_use (arg))
111
kono
parents: 67
diff changeset
1079 add_cost_one_coalesce (cl, ver, SSA_NAME_VERSION (arg));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1080 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1081 add_coalesce (cl, ver, SSA_NAME_VERSION (arg), cost);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1082 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1083 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1084 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1085 if (saw_copy)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1086 bitmap_set_bit (used_in_copy, ver);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1087 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1088
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1089 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1090 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1091 stmt = gsi_stmt (gsi);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1092
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1093 if (is_gimple_debug (stmt))
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1094 continue;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1095
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1096 /* Check for copy coalesces. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1097 switch (gimple_code (stmt))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1098 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1099 case GIMPLE_ASSIGN:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1100 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1101 tree lhs = gimple_assign_lhs (stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1102 tree rhs1 = gimple_assign_rhs1 (stmt);
111
kono
parents: 67
diff changeset
1103 if (gimple_assign_ssa_name_copy_p (stmt)
kono
parents: 67
diff changeset
1104 && gimple_can_coalesce_p (lhs, rhs1))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1105 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1106 v1 = SSA_NAME_VERSION (lhs);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1107 v2 = SSA_NAME_VERSION (rhs1);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1108 cost = coalesce_cost_bb (bb);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1109 add_coalesce (cl, v1, v2, cost);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1110 bitmap_set_bit (used_in_copy, v1);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1111 bitmap_set_bit (used_in_copy, v2);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1112 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1113 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1114 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1115
111
kono
parents: 67
diff changeset
1116 case GIMPLE_RETURN:
kono
parents: 67
diff changeset
1117 {
kono
parents: 67
diff changeset
1118 tree res = DECL_RESULT (current_function_decl);
kono
parents: 67
diff changeset
1119 if (VOID_TYPE_P (TREE_TYPE (res))
kono
parents: 67
diff changeset
1120 || !is_gimple_reg (res))
kono
parents: 67
diff changeset
1121 break;
kono
parents: 67
diff changeset
1122 tree rhs1 = gimple_return_retval (as_a <greturn *> (stmt));
kono
parents: 67
diff changeset
1123 if (!rhs1)
kono
parents: 67
diff changeset
1124 break;
kono
parents: 67
diff changeset
1125 tree lhs = ssa_default_def (cfun, res);
kono
parents: 67
diff changeset
1126 gcc_assert (lhs);
kono
parents: 67
diff changeset
1127 if (TREE_CODE (rhs1) == SSA_NAME
kono
parents: 67
diff changeset
1128 && gimple_can_coalesce_p (lhs, rhs1))
kono
parents: 67
diff changeset
1129 {
kono
parents: 67
diff changeset
1130 v1 = SSA_NAME_VERSION (lhs);
kono
parents: 67
diff changeset
1131 v2 = SSA_NAME_VERSION (rhs1);
kono
parents: 67
diff changeset
1132 cost = coalesce_cost_bb (bb);
kono
parents: 67
diff changeset
1133 add_coalesce (cl, v1, v2, cost);
kono
parents: 67
diff changeset
1134 bitmap_set_bit (used_in_copy, v1);
kono
parents: 67
diff changeset
1135 bitmap_set_bit (used_in_copy, v2);
kono
parents: 67
diff changeset
1136 }
kono
parents: 67
diff changeset
1137 break;
kono
parents: 67
diff changeset
1138 }
kono
parents: 67
diff changeset
1139
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1140 case GIMPLE_ASM:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1141 {
111
kono
parents: 67
diff changeset
1142 gasm *asm_stmt = as_a <gasm *> (stmt);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1143 unsigned long noutputs, i;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1144 unsigned long ninputs;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1145 tree *outputs, link;
111
kono
parents: 67
diff changeset
1146 noutputs = gimple_asm_noutputs (asm_stmt);
kono
parents: 67
diff changeset
1147 ninputs = gimple_asm_ninputs (asm_stmt);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1148 outputs = (tree *) alloca (noutputs * sizeof (tree));
111
kono
parents: 67
diff changeset
1149 for (i = 0; i < noutputs; ++i)
kono
parents: 67
diff changeset
1150 {
kono
parents: 67
diff changeset
1151 link = gimple_asm_output_op (asm_stmt, i);
kono
parents: 67
diff changeset
1152 outputs[i] = TREE_VALUE (link);
kono
parents: 67
diff changeset
1153 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1154
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1155 for (i = 0; i < ninputs; ++i)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1156 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1157 const char *constraint;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1158 tree input;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1159 char *end;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1160 unsigned long match;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1161
111
kono
parents: 67
diff changeset
1162 link = gimple_asm_input_op (asm_stmt, i);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1163 constraint
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1164 = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link)));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1165 input = TREE_VALUE (link);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1166
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1167 if (TREE_CODE (input) != SSA_NAME)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1168 continue;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1169
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1170 match = strtoul (constraint, &end, 10);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1171 if (match >= noutputs || end == constraint)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1172 continue;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1173
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1174 if (TREE_CODE (outputs[match]) != SSA_NAME)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1175 continue;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1176
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1177 v1 = SSA_NAME_VERSION (outputs[match]);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1178 v2 = SSA_NAME_VERSION (input);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1179
111
kono
parents: 67
diff changeset
1180 if (gimple_can_coalesce_p (outputs[match], input))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1181 {
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1182 cost = coalesce_cost (REG_BR_PROB_BASE,
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1183 optimize_bb_for_size_p (bb));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1184 add_coalesce (cl, v1, v2, cost);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1185 bitmap_set_bit (used_in_copy, v1);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1186 bitmap_set_bit (used_in_copy, v2);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1187 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1188 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1189 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1190 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1191
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1192 default:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1193 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1194 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1195 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1196 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1197
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1198 return cl;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1199 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1200
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1201
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1202 /* Hashtable support for storing SSA names hashed by their SSA_NAME_VAR. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1203
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1204 struct ssa_name_var_hash : nofree_ptr_hash <tree_node>
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1205 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1206 static inline hashval_t hash (const tree_node *);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1207 static inline int equal (const tree_node *, const tree_node *);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1208 };
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1209
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1210 inline hashval_t
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1211 ssa_name_var_hash::hash (const_tree n)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1212 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1213 return DECL_UID (SSA_NAME_VAR (n));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1214 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1215
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1216 inline int
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1217 ssa_name_var_hash::equal (const tree_node *n1, const tree_node *n2)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1218 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1219 return SSA_NAME_VAR (n1) == SSA_NAME_VAR (n2);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1220 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1221
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1222
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1223 /* This function populates coalesce list CL as well as recording related ssa
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1224 names in USED_IN_COPIES for use later in the out-of-ssa process. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1225
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1226 static void
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1227 populate_coalesce_list_for_outofssa (coalesce_list *cl, bitmap used_in_copy)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1228 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1229 tree var;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1230 tree first;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1231 int v1, v2, cost;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1232 unsigned i;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1233
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1234 /* Process result decls and live on entry variables for entry into the
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1235 coalesce list. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1236 first = NULL_TREE;
111
kono
parents: 67
diff changeset
1237 FOR_EACH_SSA_NAME (i, var, cfun)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1238 {
111
kono
parents: 67
diff changeset
1239 if (!virtual_operand_p (var))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1240 {
111
kono
parents: 67
diff changeset
1241 coalesce_with_default (var, cl, used_in_copy);
kono
parents: 67
diff changeset
1242
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1243 /* Add coalesces between all the result decls. */
111
kono
parents: 67
diff changeset
1244 if (SSA_NAME_VAR (var)
kono
parents: 67
diff changeset
1245 && TREE_CODE (SSA_NAME_VAR (var)) == RESULT_DECL)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1246 {
111
kono
parents: 67
diff changeset
1247 bitmap_set_bit (used_in_copy, SSA_NAME_VERSION (var));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1248 if (first == NULL_TREE)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1249 first = var;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1250 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1251 {
111
kono
parents: 67
diff changeset
1252 gcc_assert (gimple_can_coalesce_p (var, first));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1253 v1 = SSA_NAME_VERSION (first);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1254 v2 = SSA_NAME_VERSION (var);
111
kono
parents: 67
diff changeset
1255 cost = coalesce_cost_bb (EXIT_BLOCK_PTR_FOR_FN (cfun));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1256 add_coalesce (cl, v1, v2, cost);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1257 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1258 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1259 /* Mark any default_def variables as being in the coalesce list
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1260 since they will have to be coalesced with the base variable. If
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1261 not marked as present, they won't be in the coalesce view. */
111
kono
parents: 67
diff changeset
1262 if (SSA_NAME_IS_DEFAULT_DEF (var)
kono
parents: 67
diff changeset
1263 && (!has_zero_uses (var)
kono
parents: 67
diff changeset
1264 || (SSA_NAME_VAR (var)
kono
parents: 67
diff changeset
1265 && !VAR_P (SSA_NAME_VAR (var)))))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1266 bitmap_set_bit (used_in_copy, SSA_NAME_VERSION (var));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1267 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1268 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1269
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1270 /* If this optimization is disabled, we need to coalesce all the
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1271 names originating from the same SSA_NAME_VAR so debug info
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1272 remains undisturbed. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1273 if (!flag_tree_coalesce_vars)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1274 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1275 tree a;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1276 hash_table<ssa_name_var_hash> ssa_name_hash (10);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1277
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1278 FOR_EACH_SSA_NAME (i, a, cfun)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1279 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1280 if (SSA_NAME_VAR (a)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1281 && !DECL_IGNORED_P (SSA_NAME_VAR (a))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1282 && (!has_zero_uses (a) || !SSA_NAME_IS_DEFAULT_DEF (a)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1283 || !VAR_P (SSA_NAME_VAR (a))))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1284 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1285 tree *slot = ssa_name_hash.find_slot (a, INSERT);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1286
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1287 if (!*slot)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1288 *slot = a;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1289 else
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1290 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1291 /* If the variable is a PARM_DECL or a RESULT_DECL, we
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1292 _require_ that all the names originating from it be
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1293 coalesced, because there must be a single partition
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1294 containing all the names so that it can be assigned
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1295 the canonical RTL location of the DECL safely.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1296 If in_lto_p, a function could have been compiled
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1297 originally with optimizations and only the link
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1298 performed at -O0, so we can't actually require it. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1299 const int cost
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1300 = (TREE_CODE (SSA_NAME_VAR (a)) == VAR_DECL || in_lto_p)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1301 ? MUST_COALESCE_COST - 1 : MUST_COALESCE_COST;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1302 add_coalesce (cl, SSA_NAME_VERSION (a),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1303 SSA_NAME_VERSION (*slot), cost);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1304 bitmap_set_bit (used_in_copy, SSA_NAME_VERSION (a));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1305 bitmap_set_bit (used_in_copy, SSA_NAME_VERSION (*slot));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1306 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1307 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1308 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1309 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1310 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1311
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1312
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1313 /* Attempt to coalesce ssa versions X and Y together using the partition
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1314 mapping in MAP and checking conflicts in GRAPH. Output any debug info to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1315 DEBUG, if it is nun-NULL. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1316
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1317 static inline bool
111
kono
parents: 67
diff changeset
1318 attempt_coalesce (var_map map, ssa_conflicts *graph, int x, int y,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1319 FILE *debug)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1320 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1321 int z;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1322 tree var1, var2;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1323 int p1, p2;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1324
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1325 p1 = var_to_partition (map, ssa_name (x));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1326 p2 = var_to_partition (map, ssa_name (y));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1327
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1328 if (debug)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1329 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1330 fprintf (debug, "(%d)", x);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1331 print_generic_expr (debug, partition_to_var (map, p1), TDF_SLIM);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1332 fprintf (debug, " & (%d)", y);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1333 print_generic_expr (debug, partition_to_var (map, p2), TDF_SLIM);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1334 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1335
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1336 if (p1 == p2)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1337 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1338 if (debug)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1339 fprintf (debug, ": Already Coalesced.\n");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1340 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1341 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1342
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1343 if (debug)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1344 fprintf (debug, " [map: %d, %d] ", p1, p2);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1345
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1346
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1347 if (!ssa_conflicts_test_p (graph, p1, p2))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1348 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1349 var1 = partition_to_var (map, p1);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1350 var2 = partition_to_var (map, p2);
111
kono
parents: 67
diff changeset
1351
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1352 z = var_union (map, var1, var2);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1353 if (z == NO_PARTITION)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1354 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1355 if (debug)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1356 fprintf (debug, ": Unable to perform partition union.\n");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1357 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1358 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1359
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1360 /* z is the new combined partition. Remove the other partition from
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1361 the list, and merge the conflicts. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1362 if (z == p1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1363 ssa_conflicts_merge (graph, p1, p2);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1364 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1365 ssa_conflicts_merge (graph, p2, p1);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1366
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1367 if (debug)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1368 fprintf (debug, ": Success -> %d\n", z);
111
kono
parents: 67
diff changeset
1369
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1370 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1371 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1372
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1373 if (debug)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1374 fprintf (debug, ": Fail due to conflict\n");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1375
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1376 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1377 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1378
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1379
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1380 /* Attempt to Coalesce partitions in MAP which occur in the list CL using
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1381 GRAPH. Debug output is sent to DEBUG if it is non-NULL. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1382
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1383 static void
111
kono
parents: 67
diff changeset
1384 coalesce_partitions (var_map map, ssa_conflicts *graph, coalesce_list *cl,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1385 FILE *debug)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1386 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1387 int x = 0, y = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1388 tree var1, var2;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1389 int cost;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1390 basic_block bb;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1391 edge e;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1392 edge_iterator ei;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1393
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1394 /* First, coalesce all the copies across abnormal edges. These are not placed
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1395 in the coalesce list because they do not need to be sorted, and simply
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1396 consume extra memory/compilation time in large programs. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1397
111
kono
parents: 67
diff changeset
1398 FOR_EACH_BB_FN (bb, cfun)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1399 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1400 FOR_EACH_EDGE (e, ei, bb->preds)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1401 if (e->flags & EDGE_ABNORMAL)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1402 {
111
kono
parents: 67
diff changeset
1403 gphi_iterator gsi;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1404 for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1405 gsi_next (&gsi))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1406 {
111
kono
parents: 67
diff changeset
1407 gphi *phi = gsi.phi ();
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1408 tree res = PHI_RESULT (phi);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1409 if (virtual_operand_p (res))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1410 continue;
111
kono
parents: 67
diff changeset
1411 tree arg = PHI_ARG_DEF (phi, e->dest_idx);
kono
parents: 67
diff changeset
1412 if (SSA_NAME_IS_DEFAULT_DEF (arg)
kono
parents: 67
diff changeset
1413 && (!SSA_NAME_VAR (arg)
kono
parents: 67
diff changeset
1414 || TREE_CODE (SSA_NAME_VAR (arg)) != PARM_DECL))
kono
parents: 67
diff changeset
1415 continue;
kono
parents: 67
diff changeset
1416
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1417 int v1 = SSA_NAME_VERSION (res);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1418 int v2 = SSA_NAME_VERSION (arg);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1419
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1420 if (debug)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1421 fprintf (debug, "Abnormal coalesce: ");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1422
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1423 if (!attempt_coalesce (map, graph, v1, v2, debug))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1424 fail_abnormal_edge_coalesce (v1, v2);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1425 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1426 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1427 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1428
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1429 /* Now process the items in the coalesce list. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1430
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1431 while ((cost = pop_best_coalesce (cl, &x, &y)) != NO_BEST_COALESCE)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1432 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1433 var1 = ssa_name (x);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1434 var2 = ssa_name (y);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1435
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1436 /* Assert the coalesces have the same base variable. */
111
kono
parents: 67
diff changeset
1437 gcc_assert (gimple_can_coalesce_p (var1, var2));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1438
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1439 if (debug)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1440 fprintf (debug, "Coalesce list: ");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1441 attempt_coalesce (map, graph, x, y, debug);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1442 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1443 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1444
111
kono
parents: 67
diff changeset
1445
kono
parents: 67
diff changeset
1446 /* Output partition map MAP with coalescing plan PART to file F. */
kono
parents: 67
diff changeset
1447
kono
parents: 67
diff changeset
1448 void
kono
parents: 67
diff changeset
1449 dump_part_var_map (FILE *f, partition part, var_map map)
kono
parents: 67
diff changeset
1450 {
kono
parents: 67
diff changeset
1451 int t;
kono
parents: 67
diff changeset
1452 unsigned x, y;
kono
parents: 67
diff changeset
1453 int p;
kono
parents: 67
diff changeset
1454
kono
parents: 67
diff changeset
1455 fprintf (f, "\nCoalescible Partition map \n\n");
kono
parents: 67
diff changeset
1456
kono
parents: 67
diff changeset
1457 for (x = 0; x < map->num_partitions; x++)
kono
parents: 67
diff changeset
1458 {
kono
parents: 67
diff changeset
1459 if (map->view_to_partition != NULL)
kono
parents: 67
diff changeset
1460 p = map->view_to_partition[x];
kono
parents: 67
diff changeset
1461 else
kono
parents: 67
diff changeset
1462 p = x;
kono
parents: 67
diff changeset
1463
kono
parents: 67
diff changeset
1464 if (ssa_name (p) == NULL_TREE
kono
parents: 67
diff changeset
1465 || virtual_operand_p (ssa_name (p)))
kono
parents: 67
diff changeset
1466 continue;
kono
parents: 67
diff changeset
1467
kono
parents: 67
diff changeset
1468 t = 0;
kono
parents: 67
diff changeset
1469 for (y = 1; y < num_ssa_names; y++)
kono
parents: 67
diff changeset
1470 {
kono
parents: 67
diff changeset
1471 tree var = version_to_var (map, y);
kono
parents: 67
diff changeset
1472 if (!var)
kono
parents: 67
diff changeset
1473 continue;
kono
parents: 67
diff changeset
1474 int q = var_to_partition (map, var);
kono
parents: 67
diff changeset
1475 p = partition_find (part, q);
kono
parents: 67
diff changeset
1476 gcc_assert (map->partition_to_base_index[q]
kono
parents: 67
diff changeset
1477 == map->partition_to_base_index[p]);
kono
parents: 67
diff changeset
1478
kono
parents: 67
diff changeset
1479 if (p == (int)x)
kono
parents: 67
diff changeset
1480 {
kono
parents: 67
diff changeset
1481 if (t++ == 0)
kono
parents: 67
diff changeset
1482 {
kono
parents: 67
diff changeset
1483 fprintf (f, "Partition %d, base %d (", x,
kono
parents: 67
diff changeset
1484 map->partition_to_base_index[q]);
kono
parents: 67
diff changeset
1485 print_generic_expr (f, partition_to_var (map, q), TDF_SLIM);
kono
parents: 67
diff changeset
1486 fprintf (f, " - ");
kono
parents: 67
diff changeset
1487 }
kono
parents: 67
diff changeset
1488 fprintf (f, "%d ", y);
kono
parents: 67
diff changeset
1489 }
kono
parents: 67
diff changeset
1490 }
kono
parents: 67
diff changeset
1491 if (t != 0)
kono
parents: 67
diff changeset
1492 fprintf (f, ")\n");
kono
parents: 67
diff changeset
1493 }
kono
parents: 67
diff changeset
1494 fprintf (f, "\n");
kono
parents: 67
diff changeset
1495 }
kono
parents: 67
diff changeset
1496
kono
parents: 67
diff changeset
1497 /* Given SSA_NAMEs NAME1 and NAME2, return true if they are candidates for
kono
parents: 67
diff changeset
1498 coalescing together, false otherwise.
kono
parents: 67
diff changeset
1499
kono
parents: 67
diff changeset
1500 This must stay consistent with compute_samebase_partition_bases and
kono
parents: 67
diff changeset
1501 compute_optimized_partition_bases. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1502
111
kono
parents: 67
diff changeset
1503 bool
kono
parents: 67
diff changeset
1504 gimple_can_coalesce_p (tree name1, tree name2)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1505 {
111
kono
parents: 67
diff changeset
1506 /* First check the SSA_NAME's associated DECL. Without
kono
parents: 67
diff changeset
1507 optimization, we only want to coalesce if they have the same DECL
kono
parents: 67
diff changeset
1508 or both have no associated DECL. */
kono
parents: 67
diff changeset
1509 tree var1 = SSA_NAME_VAR (name1);
kono
parents: 67
diff changeset
1510 tree var2 = SSA_NAME_VAR (name2);
kono
parents: 67
diff changeset
1511 var1 = (var1 && (!VAR_P (var1) || !DECL_IGNORED_P (var1))) ? var1 : NULL_TREE;
kono
parents: 67
diff changeset
1512 var2 = (var2 && (!VAR_P (var2) || !DECL_IGNORED_P (var2))) ? var2 : NULL_TREE;
kono
parents: 67
diff changeset
1513 if (var1 != var2 && !flag_tree_coalesce_vars)
kono
parents: 67
diff changeset
1514 return false;
kono
parents: 67
diff changeset
1515
kono
parents: 67
diff changeset
1516 /* Now check the types. If the types are the same, then we should
kono
parents: 67
diff changeset
1517 try to coalesce V1 and V2. */
kono
parents: 67
diff changeset
1518 tree t1 = TREE_TYPE (name1);
kono
parents: 67
diff changeset
1519 tree t2 = TREE_TYPE (name2);
kono
parents: 67
diff changeset
1520 if (t1 == t2)
kono
parents: 67
diff changeset
1521 {
kono
parents: 67
diff changeset
1522 check_modes:
kono
parents: 67
diff changeset
1523 /* If the base variables are the same, we're good: none of the
kono
parents: 67
diff changeset
1524 other tests below could possibly fail. */
kono
parents: 67
diff changeset
1525 var1 = SSA_NAME_VAR (name1);
kono
parents: 67
diff changeset
1526 var2 = SSA_NAME_VAR (name2);
kono
parents: 67
diff changeset
1527 if (var1 == var2)
kono
parents: 67
diff changeset
1528 return true;
kono
parents: 67
diff changeset
1529
kono
parents: 67
diff changeset
1530 /* We don't want to coalesce two SSA names if one of the base
kono
parents: 67
diff changeset
1531 variables is supposed to be a register while the other is
kono
parents: 67
diff changeset
1532 supposed to be on the stack. Anonymous SSA names most often
kono
parents: 67
diff changeset
1533 take registers, but when not optimizing, user variables
kono
parents: 67
diff changeset
1534 should go on the stack, so coalescing them with the anonymous
kono
parents: 67
diff changeset
1535 variable as the partition leader would end up assigning the
kono
parents: 67
diff changeset
1536 user variable to a register. Don't do that! */
kono
parents: 67
diff changeset
1537 bool reg1 = use_register_for_decl (name1);
kono
parents: 67
diff changeset
1538 bool reg2 = use_register_for_decl (name2);
kono
parents: 67
diff changeset
1539 if (reg1 != reg2)
kono
parents: 67
diff changeset
1540 return false;
kono
parents: 67
diff changeset
1541
kono
parents: 67
diff changeset
1542 /* Check that the promoted modes and unsignedness are the same.
kono
parents: 67
diff changeset
1543 We don't want to coalesce if the promoted modes would be
kono
parents: 67
diff changeset
1544 different, or if they would sign-extend differently. Only
kono
parents: 67
diff changeset
1545 PARM_DECLs and RESULT_DECLs have different promotion rules,
kono
parents: 67
diff changeset
1546 so skip the test if both are variables, or both are anonymous
kono
parents: 67
diff changeset
1547 SSA_NAMEs. */
kono
parents: 67
diff changeset
1548 int unsigned1, unsigned2;
kono
parents: 67
diff changeset
1549 return ((!var1 || VAR_P (var1)) && (!var2 || VAR_P (var2)))
kono
parents: 67
diff changeset
1550 || ((promote_ssa_mode (name1, &unsigned1)
kono
parents: 67
diff changeset
1551 == promote_ssa_mode (name2, &unsigned2))
kono
parents: 67
diff changeset
1552 && unsigned1 == unsigned2);
kono
parents: 67
diff changeset
1553 }
kono
parents: 67
diff changeset
1554
kono
parents: 67
diff changeset
1555 /* If alignment requirements are different, we can't coalesce. */
kono
parents: 67
diff changeset
1556 if (MINIMUM_ALIGNMENT (t1,
kono
parents: 67
diff changeset
1557 var1 ? DECL_MODE (var1) : TYPE_MODE (t1),
kono
parents: 67
diff changeset
1558 var1 ? LOCAL_DECL_ALIGNMENT (var1) : TYPE_ALIGN (t1))
kono
parents: 67
diff changeset
1559 != MINIMUM_ALIGNMENT (t2,
kono
parents: 67
diff changeset
1560 var2 ? DECL_MODE (var2) : TYPE_MODE (t2),
kono
parents: 67
diff changeset
1561 var2 ? LOCAL_DECL_ALIGNMENT (var2) : TYPE_ALIGN (t2)))
kono
parents: 67
diff changeset
1562 return false;
kono
parents: 67
diff changeset
1563
kono
parents: 67
diff changeset
1564 /* If the types are not the same, see whether they are compatible. This
kono
parents: 67
diff changeset
1565 (for example) allows coalescing when the types are fundamentally the
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1566 same, but just have different names. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1567 if (types_compatible_p (t1, t2))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1568 goto check_modes;
111
kono
parents: 67
diff changeset
1569
kono
parents: 67
diff changeset
1570 return false;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1571 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1572
111
kono
parents: 67
diff changeset
1573 /* Fill in MAP's partition_to_base_index, with one index for each
kono
parents: 67
diff changeset
1574 partition of SSA names USED_IN_COPIES and related by CL coalesce
kono
parents: 67
diff changeset
1575 possibilities. This must match gimple_can_coalesce_p in the
kono
parents: 67
diff changeset
1576 optimized case. */
kono
parents: 67
diff changeset
1577
kono
parents: 67
diff changeset
1578 static void
kono
parents: 67
diff changeset
1579 compute_optimized_partition_bases (var_map map, bitmap used_in_copies,
kono
parents: 67
diff changeset
1580 coalesce_list *cl)
kono
parents: 67
diff changeset
1581 {
kono
parents: 67
diff changeset
1582 int parts = num_var_partitions (map);
kono
parents: 67
diff changeset
1583 partition tentative = partition_new (parts);
kono
parents: 67
diff changeset
1584
kono
parents: 67
diff changeset
1585 /* Partition the SSA versions so that, for each coalescible
kono
parents: 67
diff changeset
1586 pair, both of its members are in the same partition in
kono
parents: 67
diff changeset
1587 TENTATIVE. */
kono
parents: 67
diff changeset
1588 gcc_assert (!cl->sorted);
kono
parents: 67
diff changeset
1589 coalesce_pair *node;
kono
parents: 67
diff changeset
1590 coalesce_iterator_type ppi;
kono
parents: 67
diff changeset
1591 FOR_EACH_PARTITION_PAIR (node, ppi, cl)
kono
parents: 67
diff changeset
1592 {
kono
parents: 67
diff changeset
1593 tree v1 = ssa_name (node->first_element);
kono
parents: 67
diff changeset
1594 int p1 = partition_find (tentative, var_to_partition (map, v1));
kono
parents: 67
diff changeset
1595 tree v2 = ssa_name (node->second_element);
kono
parents: 67
diff changeset
1596 int p2 = partition_find (tentative, var_to_partition (map, v2));
kono
parents: 67
diff changeset
1597
kono
parents: 67
diff changeset
1598 if (p1 == p2)
kono
parents: 67
diff changeset
1599 continue;
kono
parents: 67
diff changeset
1600
kono
parents: 67
diff changeset
1601 partition_union (tentative, p1, p2);
kono
parents: 67
diff changeset
1602 }
kono
parents: 67
diff changeset
1603
kono
parents: 67
diff changeset
1604 /* We have to deal with cost one pairs too. */
kono
parents: 67
diff changeset
1605 for (cost_one_pair *co = cl->cost_one_list; co; co = co->next)
kono
parents: 67
diff changeset
1606 {
kono
parents: 67
diff changeset
1607 tree v1 = ssa_name (co->first_element);
kono
parents: 67
diff changeset
1608 int p1 = partition_find (tentative, var_to_partition (map, v1));
kono
parents: 67
diff changeset
1609 tree v2 = ssa_name (co->second_element);
kono
parents: 67
diff changeset
1610 int p2 = partition_find (tentative, var_to_partition (map, v2));
kono
parents: 67
diff changeset
1611
kono
parents: 67
diff changeset
1612 if (p1 == p2)
kono
parents: 67
diff changeset
1613 continue;
kono
parents: 67
diff changeset
1614
kono
parents: 67
diff changeset
1615 partition_union (tentative, p1, p2);
kono
parents: 67
diff changeset
1616 }
kono
parents: 67
diff changeset
1617
kono
parents: 67
diff changeset
1618 /* And also with abnormal edges. */
kono
parents: 67
diff changeset
1619 basic_block bb;
kono
parents: 67
diff changeset
1620 edge e;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1621 unsigned i;
111
kono
parents: 67
diff changeset
1622 edge_iterator ei;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1623 for (i = 0; map->vec_bbs.iterate (i, &bb); ++i)
111
kono
parents: 67
diff changeset
1624 {
kono
parents: 67
diff changeset
1625 FOR_EACH_EDGE (e, ei, bb->preds)
kono
parents: 67
diff changeset
1626 if (e->flags & EDGE_ABNORMAL)
kono
parents: 67
diff changeset
1627 {
kono
parents: 67
diff changeset
1628 gphi_iterator gsi;
kono
parents: 67
diff changeset
1629 for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi);
kono
parents: 67
diff changeset
1630 gsi_next (&gsi))
kono
parents: 67
diff changeset
1631 {
kono
parents: 67
diff changeset
1632 gphi *phi = gsi.phi ();
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1633 tree res = PHI_RESULT (phi);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1634 if (virtual_operand_p (res))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1635 continue;
111
kono
parents: 67
diff changeset
1636 tree arg = PHI_ARG_DEF (phi, e->dest_idx);
kono
parents: 67
diff changeset
1637 if (SSA_NAME_IS_DEFAULT_DEF (arg)
kono
parents: 67
diff changeset
1638 && (!SSA_NAME_VAR (arg)
kono
parents: 67
diff changeset
1639 || TREE_CODE (SSA_NAME_VAR (arg)) != PARM_DECL))
kono
parents: 67
diff changeset
1640 continue;
kono
parents: 67
diff changeset
1641
kono
parents: 67
diff changeset
1642 int p1 = partition_find (tentative, var_to_partition (map, res));
kono
parents: 67
diff changeset
1643 int p2 = partition_find (tentative, var_to_partition (map, arg));
kono
parents: 67
diff changeset
1644
kono
parents: 67
diff changeset
1645 if (p1 == p2)
kono
parents: 67
diff changeset
1646 continue;
kono
parents: 67
diff changeset
1647
kono
parents: 67
diff changeset
1648 partition_union (tentative, p1, p2);
kono
parents: 67
diff changeset
1649 }
kono
parents: 67
diff changeset
1650 }
kono
parents: 67
diff changeset
1651 }
kono
parents: 67
diff changeset
1652
kono
parents: 67
diff changeset
1653 map->partition_to_base_index = XCNEWVEC (int, parts);
kono
parents: 67
diff changeset
1654 auto_vec<unsigned int> index_map (parts);
kono
parents: 67
diff changeset
1655 if (parts)
kono
parents: 67
diff changeset
1656 index_map.quick_grow (parts);
kono
parents: 67
diff changeset
1657
kono
parents: 67
diff changeset
1658 const unsigned no_part = -1;
kono
parents: 67
diff changeset
1659 unsigned count = parts;
kono
parents: 67
diff changeset
1660 while (count)
kono
parents: 67
diff changeset
1661 index_map[--count] = no_part;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1662
111
kono
parents: 67
diff changeset
1663 /* Initialize MAP's mapping from partition to base index, using
kono
parents: 67
diff changeset
1664 as base indices an enumeration of the TENTATIVE partitions in
kono
parents: 67
diff changeset
1665 which each SSA version ended up, so that we compute conflicts
kono
parents: 67
diff changeset
1666 between all SSA versions that ended up in the same potential
kono
parents: 67
diff changeset
1667 coalesce partition. */
kono
parents: 67
diff changeset
1668 bitmap_iterator bi;
kono
parents: 67
diff changeset
1669 EXECUTE_IF_SET_IN_BITMAP (used_in_copies, 0, i, bi)
kono
parents: 67
diff changeset
1670 {
kono
parents: 67
diff changeset
1671 int pidx = var_to_partition (map, ssa_name (i));
kono
parents: 67
diff changeset
1672 int base = partition_find (tentative, pidx);
kono
parents: 67
diff changeset
1673 if (index_map[base] != no_part)
kono
parents: 67
diff changeset
1674 continue;
kono
parents: 67
diff changeset
1675 index_map[base] = count++;
kono
parents: 67
diff changeset
1676 }
kono
parents: 67
diff changeset
1677
kono
parents: 67
diff changeset
1678 map->num_basevars = count;
kono
parents: 67
diff changeset
1679
kono
parents: 67
diff changeset
1680 EXECUTE_IF_SET_IN_BITMAP (used_in_copies, 0, i, bi)
kono
parents: 67
diff changeset
1681 {
kono
parents: 67
diff changeset
1682 int pidx = var_to_partition (map, ssa_name (i));
kono
parents: 67
diff changeset
1683 int base = partition_find (tentative, pidx);
kono
parents: 67
diff changeset
1684 gcc_assert (index_map[base] < count);
kono
parents: 67
diff changeset
1685 map->partition_to_base_index[pidx] = index_map[base];
kono
parents: 67
diff changeset
1686 }
kono
parents: 67
diff changeset
1687
kono
parents: 67
diff changeset
1688 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 67
diff changeset
1689 dump_part_var_map (dump_file, tentative, map);
kono
parents: 67
diff changeset
1690
kono
parents: 67
diff changeset
1691 partition_delete (tentative);
kono
parents: 67
diff changeset
1692 }
kono
parents: 67
diff changeset
1693
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1694 /* Given an initial var_map MAP, coalesce variables and return a partition map
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1695 with the resulting coalesce. Note that this function is called in either
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1696 live range computation context or out-of-ssa context, indicated by MAP. */
111
kono
parents: 67
diff changeset
1697
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1698 extern void
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1699 coalesce_ssa_name (var_map map)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1700 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1701 tree_live_info_p liveinfo;
111
kono
parents: 67
diff changeset
1702 ssa_conflicts *graph;
kono
parents: 67
diff changeset
1703 coalesce_list *cl;
kono
parents: 67
diff changeset
1704 auto_bitmap used_in_copies;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1705
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1706 bitmap_tree_view (used_in_copies);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1707 cl = create_coalesce_list_for_region (map, used_in_copies);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1708 if (map->outofssa_p)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1709 populate_coalesce_list_for_outofssa (cl, used_in_copies);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1710 bitmap_list_view (used_in_copies);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1711
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1712 if (dump_file && (dump_flags & TDF_DETAILS))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1713 dump_var_map (dump_file, map);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1714
111
kono
parents: 67
diff changeset
1715 partition_view_bitmap (map, used_in_copies);
kono
parents: 67
diff changeset
1716
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1717 compute_optimized_partition_bases (map, used_in_copies, cl);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1718
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1719 if (num_var_partitions (map) < 1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1720 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1721 delete_coalesce_list (cl);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1722 return;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1723 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1724
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1725 if (dump_file && (dump_flags & TDF_DETAILS))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1726 dump_var_map (dump_file, map);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1727
111
kono
parents: 67
diff changeset
1728 liveinfo = calculate_live_ranges (map, false);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1729
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1730 if (dump_file && (dump_flags & TDF_DETAILS))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1731 dump_live_info (dump_file, liveinfo, LIVEDUMP_ENTRY);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1732
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1733 /* Build a conflict graph. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1734 graph = build_ssa_conflict_graph (liveinfo);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1735 delete_tree_live_info (liveinfo);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1736 if (dump_file && (dump_flags & TDF_DETAILS))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1737 ssa_conflicts_dump (dump_file, graph);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1738
111
kono
parents: 67
diff changeset
1739 sort_coalesce_list (cl, graph, map);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1740
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1741 if (dump_file && (dump_flags & TDF_DETAILS))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1742 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1743 fprintf (dump_file, "\nAfter sorting:\n");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1744 dump_coalesce_list (dump_file, cl);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1745 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1746
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1747 /* First, coalesce all live on entry variables to their base variable.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1748 This will ensure the first use is coming from the correct location. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1749
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1750 if (dump_file && (dump_flags & TDF_DETAILS))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1751 dump_var_map (dump_file, map);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1752
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1753 /* Now coalesce everything in the list. */
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1754 coalesce_partitions (map, graph, cl,
111
kono
parents: 67
diff changeset
1755 ((dump_flags & TDF_DETAILS) ? dump_file : NULL));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1756
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1757 delete_coalesce_list (cl);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1758 ssa_conflicts_delete (graph);
111
kono
parents: 67
diff changeset
1759 }
kono
parents: 67
diff changeset
1760