Mercurial > hg > CbC > CbC_gcc
annotate gcc/tree-ssa-operands.c @ 112:ab0bcb71f44d
merge gcc 7
author | mir3636 |
---|---|
date | Fri, 10 Nov 2017 19:46:38 +0900 |
parents | 04ced10e8804 1b10fe6932e1 |
children | f81c5aa9f14f |
rev | line source |
---|---|
0 | 1 /* SSA operands management for trees. |
111 | 2 Copyright (C) 2003-2017 Free Software Foundation, Inc. |
0 | 3 |
4 This file is part of GCC. | |
5 | |
6 GCC is free software; you can redistribute it and/or modify | |
7 it under the terms of the GNU General Public License as published by | |
8 the Free Software Foundation; either version 3, or (at your option) | |
9 any later version. | |
10 | |
11 GCC is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with GCC; see the file COPYING3. If not see | |
18 <http://www.gnu.org/licenses/>. */ | |
19 | |
20 #include "config.h" | |
21 #include "system.h" | |
22 #include "coretypes.h" | |
111 | 23 #include "backend.h" |
0 | 24 #include "tree.h" |
111 | 25 #include "gimple.h" |
26 #include "timevar.h" | |
27 #include "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
|
28 #include "gimple-pretty-print.h" |
112 | 29 <<<<<<< local |
111 | 30 #include "diagnostic-core.h" |
31 #include "stmt.h" | |
32 #include "print-tree.h" | |
33 #include "dumpfile.h" | |
34 | |
112 | 35 ======= |
0 | 36 #include "tree-flow.h" |
37 #include "tree-inline.h" | |
38 #include "tree-pass.h" | |
39 #include "ggc.h" | |
40 #include "timevar.h" | |
41 #include "langhooks.h" | |
42 #include "ipa-reference.h" | |
1 | 43 #ifndef noCbC |
44 #include "cbc-tree.h" | |
45 #endif | |
112 | 46 >>>>>>> other |
0 | 47 |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
48 /* This file contains the code required to manage the operands cache of the |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
49 SSA optimizer. For every stmt, we maintain an operand cache in the stmt |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
50 annotation. This cache contains operands that will be of interest to |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
51 optimizers and other passes wishing to manipulate the IL. |
0 | 52 |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
53 The operand type are broken up into REAL and VIRTUAL operands. The real |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
54 operands are represented as pointers into the stmt's operand tree. Thus |
0 | 55 any manipulation of the real operands will be reflected in the actual tree. |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
56 Virtual operands are represented solely in the cache, although the base |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
57 variable for the SSA_NAME may, or may not occur in the stmt's tree. |
0 | 58 Manipulation of the virtual operands will not be reflected in the stmt tree. |
59 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
60 The routines in this file are concerned with creating this operand cache |
0 | 61 from a stmt tree. |
62 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
63 The operand tree is the parsed by the various get_* routines which look |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
64 through the stmt tree for the occurrence of operands which may be of |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
65 interest, and calls are made to the append_* routines whenever one is |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
66 found. There are 4 of these routines, each representing one of the |
0 | 67 4 types of operands. Defs, Uses, Virtual Uses, and Virtual May Defs. |
68 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
69 The append_* routines check for duplication, and simply keep a list of |
0 | 70 unique objects for each operand type in the build_* extendable vectors. |
71 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
72 Once the stmt tree is completely parsed, the finalize_ssa_operands() |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
73 routine is called, which proceeds to perform the finalization routine |
0 | 74 on each of the 4 operand vectors which have been built up. |
75 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
76 If the stmt had a previous operand cache, the finalization routines |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
77 attempt to match up the new operands with the old ones. If it's a perfect |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
78 match, the old vector is simply reused. If it isn't a perfect match, then |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
79 a new vector is created and the new operands are placed there. For |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
80 virtual operands, if the previous cache had SSA_NAME version of a |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
81 variable, and that same variable occurs in the same operands cache, then |
0 | 82 the new cache vector will also get the same SSA_NAME. |
83 | |
84 i.e., if a stmt had a VUSE of 'a_5', and 'a' occurs in the new | |
85 operand vector for VUSE, then the new vector will also be modified | |
86 such that it contains 'a_5' rather than 'a'. */ | |
87 | |
88 | |
89 /* Flags to describe operand properties in helpers. */ | |
90 | |
91 /* By default, operands are loaded. */ | |
92 #define opf_use 0 | |
93 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
94 /* Operand is the target of an assignment expression or a |
0 | 95 call-clobbered variable. */ |
96 #define opf_def (1 << 0) | |
97 | |
98 /* No virtual operands should be created in the expression. This is used | |
99 when traversing ADDR_EXPR nodes which have different semantics than | |
100 other expressions. Inside an ADDR_EXPR node, the only operands that we | |
101 need to consider are indices into arrays. For instance, &a.b[i] should | |
102 generate a USE of 'i' but it should not generate a VUSE for 'a' nor a | |
103 VUSE for 'b'. */ | |
104 #define opf_no_vops (1 << 1) | |
105 | |
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
|
106 /* Operand is in a place where address-taken does not imply addressable. */ |
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
|
107 #define opf_non_addressable (1 << 3) |
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
|
108 |
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
|
109 /* Operand is in a place where opf_non_addressable does not apply. */ |
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
|
110 #define opf_not_non_addressable (1 << 4) |
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
|
111 |
111 | 112 /* Operand is having its address taken. */ |
113 #define opf_address_taken (1 << 5) | |
0 | 114 |
115 /* Array for building all the use operands. */ | |
111 | 116 static vec<tree *> build_uses; |
0 | 117 |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
118 /* The built VDEF operand. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
119 static tree build_vdef; |
0 | 120 |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
121 /* The built VUSE operand. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
122 static tree build_vuse; |
0 | 123 |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
124 /* Bitmap obstack for our datastructures that needs to survive across |
0 | 125 compilations of multiple functions. */ |
126 static bitmap_obstack operands_bitmap_obstack; | |
127 | |
111 | 128 static void get_expr_operands (struct function *, gimple *, tree *, int); |
0 | 129 |
130 /* Number of functions with initialized ssa_operands. */ | |
131 static int n_initialized = 0; | |
132 | |
111 | 133 /* Accessor to tree-ssa-operands.c caches. */ |
134 static inline struct ssa_operands * | |
135 gimple_ssa_operands (const struct function *fun) | |
0 | 136 { |
111 | 137 return &fun->gimple_df->ssa_operands; |
0 | 138 } |
139 | |
140 | |
141 /* Return true if the SSA operands cache is active. */ | |
142 | |
143 bool | |
111 | 144 ssa_operands_active (struct function *fun) |
0 | 145 { |
111 | 146 if (fun == NULL) |
0 | 147 return false; |
148 | |
111 | 149 return fun->gimple_df && gimple_ssa_operands (fun)->ops_active; |
0 | 150 } |
151 | |
152 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
153 /* Create the VOP variable, an artificial global variable to act as a |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
154 representative of all of the virtual operands FUD chain. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
155 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
156 static void |
111 | 157 create_vop_var (struct function *fn) |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
158 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
159 tree global_var; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
160 |
111 | 161 gcc_assert (fn->gimple_df->vop == NULL_TREE); |
0 | 162 |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
163 global_var = build_decl (BUILTINS_LOCATION, VAR_DECL, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
164 get_identifier (".MEM"), |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
165 void_type_node); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
166 DECL_ARTIFICIAL (global_var) = 1; |
111 | 167 DECL_IGNORED_P (global_var) = 1; |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
168 TREE_READONLY (global_var) = 0; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
169 DECL_EXTERNAL (global_var) = 1; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
170 TREE_STATIC (global_var) = 1; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
171 TREE_USED (global_var) = 1; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
172 DECL_CONTEXT (global_var) = NULL_TREE; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
173 TREE_THIS_VOLATILE (global_var) = 0; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
174 TREE_ADDRESSABLE (global_var) = 0; |
111 | 175 VAR_DECL_IS_VIRTUAL_OPERAND (global_var) = 1; |
0 | 176 |
111 | 177 fn->gimple_df->vop = global_var; |
0 | 178 } |
179 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
180 /* These are the sizes of the operand memory buffer in bytes which gets |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
181 allocated each time more operands space is required. The final value is |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
182 the amount that is allocated every time after that. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
183 In 1k we can fit 25 use operands (or 63 def operands) on a host with |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
184 8 byte pointers, that would be 10 statements each with 1 def and 2 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
185 uses. */ |
0 | 186 |
187 #define OP_SIZE_INIT 0 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
188 #define OP_SIZE_1 (1024 - sizeof (void *)) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
189 #define OP_SIZE_2 (1024 * 4 - sizeof (void *)) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
190 #define OP_SIZE_3 (1024 * 16 - sizeof (void *)) |
0 | 191 |
192 /* Initialize the operand cache routines. */ | |
193 | |
194 void | |
111 | 195 init_ssa_operands (struct function *fn) |
0 | 196 { |
197 if (!n_initialized++) | |
198 { | |
111 | 199 build_uses.create (10); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
200 build_vuse = NULL_TREE; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
201 build_vdef = NULL_TREE; |
0 | 202 bitmap_obstack_initialize (&operands_bitmap_obstack); |
203 } | |
204 | |
111 | 205 gcc_assert (gimple_ssa_operands (fn)->operand_memory == NULL); |
206 gimple_ssa_operands (fn)->operand_memory_index | |
207 = gimple_ssa_operands (fn)->ssa_operand_mem_size; | |
208 gimple_ssa_operands (fn)->ops_active = true; | |
209 gimple_ssa_operands (fn)->ssa_operand_mem_size = OP_SIZE_INIT; | |
210 create_vop_var (fn); | |
0 | 211 } |
212 | |
213 | |
214 /* Dispose of anything required by the operand routines. */ | |
215 | |
216 void | |
111 | 217 fini_ssa_operands (struct function *fn) |
0 | 218 { |
219 struct ssa_operand_memory_d *ptr; | |
220 | |
221 if (!--n_initialized) | |
222 { | |
111 | 223 build_uses.release (); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
224 build_vdef = NULL_TREE; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
225 build_vuse = NULL_TREE; |
0 | 226 } |
227 | |
111 | 228 gimple_ssa_operands (fn)->free_uses = NULL; |
0 | 229 |
111 | 230 while ((ptr = gimple_ssa_operands (fn)->operand_memory) != NULL) |
0 | 231 { |
111 | 232 gimple_ssa_operands (fn)->operand_memory |
233 = gimple_ssa_operands (fn)->operand_memory->next; | |
0 | 234 ggc_free (ptr); |
235 } | |
236 | |
111 | 237 gimple_ssa_operands (fn)->ops_active = false; |
0 | 238 |
239 if (!n_initialized) | |
240 bitmap_obstack_release (&operands_bitmap_obstack); | |
241 | |
111 | 242 fn->gimple_df->vop = NULL_TREE; |
0 | 243 } |
244 | |
245 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
246 /* Return memory for an operand of size SIZE. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
247 |
0 | 248 static inline void * |
111 | 249 ssa_operand_alloc (struct function *fn, unsigned size) |
0 | 250 { |
251 char *ptr; | |
252 | |
111 | 253 gcc_assert (size == sizeof (struct use_optype_d)); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
254 |
111 | 255 if (gimple_ssa_operands (fn)->operand_memory_index + size |
256 >= gimple_ssa_operands (fn)->ssa_operand_mem_size) | |
0 | 257 { |
258 struct ssa_operand_memory_d *ptr; | |
259 | |
111 | 260 switch (gimple_ssa_operands (fn)->ssa_operand_mem_size) |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
261 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
262 case OP_SIZE_INIT: |
111 | 263 gimple_ssa_operands (fn)->ssa_operand_mem_size = OP_SIZE_1; |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
264 break; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
265 case OP_SIZE_1: |
111 | 266 gimple_ssa_operands (fn)->ssa_operand_mem_size = OP_SIZE_2; |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
267 break; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
268 case OP_SIZE_2: |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
269 case OP_SIZE_3: |
111 | 270 gimple_ssa_operands (fn)->ssa_operand_mem_size = OP_SIZE_3; |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
271 break; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
272 default: |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
273 gcc_unreachable (); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
274 } |
0 | 275 |
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
|
276 |
111 | 277 ptr = (ssa_operand_memory_d *) ggc_internal_alloc |
278 (sizeof (void *) + gimple_ssa_operands (fn)->ssa_operand_mem_size); | |
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
|
279 |
111 | 280 ptr->next = gimple_ssa_operands (fn)->operand_memory; |
281 gimple_ssa_operands (fn)->operand_memory = ptr; | |
282 gimple_ssa_operands (fn)->operand_memory_index = 0; | |
0 | 283 } |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
284 |
111 | 285 ptr = &(gimple_ssa_operands (fn)->operand_memory |
286 ->mem[gimple_ssa_operands (fn)->operand_memory_index]); | |
287 gimple_ssa_operands (fn)->operand_memory_index += size; | |
0 | 288 return ptr; |
289 } | |
290 | |
291 | |
292 /* Allocate a USE operand. */ | |
293 | |
294 static inline struct use_optype_d * | |
111 | 295 alloc_use (struct function *fn) |
0 | 296 { |
297 struct use_optype_d *ret; | |
111 | 298 if (gimple_ssa_operands (fn)->free_uses) |
0 | 299 { |
111 | 300 ret = gimple_ssa_operands (fn)->free_uses; |
301 gimple_ssa_operands (fn)->free_uses | |
302 = gimple_ssa_operands (fn)->free_uses->next; | |
0 | 303 } |
304 else | |
305 ret = (struct use_optype_d *) | |
111 | 306 ssa_operand_alloc (fn, sizeof (struct use_optype_d)); |
0 | 307 return ret; |
308 } | |
309 | |
310 | |
311 /* Adds OP to the list of uses of statement STMT after LAST. */ | |
312 | |
313 static inline use_optype_p | |
111 | 314 add_use_op (struct function *fn, gimple *stmt, tree *op, use_optype_p last) |
0 | 315 { |
316 use_optype_p new_use; | |
317 | |
111 | 318 new_use = alloc_use (fn); |
0 | 319 USE_OP_PTR (new_use)->use = op; |
320 link_imm_use_stmt (USE_OP_PTR (new_use), *op, stmt); | |
321 last->next = new_use; | |
322 new_use->next = NULL; | |
323 return new_use; | |
324 } | |
325 | |
326 | |
327 | |
328 /* Takes elements from build_defs and turns them into def operands of STMT. | |
111 | 329 TODO -- Make build_defs vec of tree *. */ |
0 | 330 |
331 static inline void | |
111 | 332 finalize_ssa_defs (struct function *fn, gimple *stmt) |
0 | 333 { |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
334 /* Pre-pend the vdef we may have built. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
335 if (build_vdef != NULL_TREE) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
336 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
337 tree oldvdef = gimple_vdef (stmt); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
338 if (oldvdef |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
339 && TREE_CODE (oldvdef) == SSA_NAME) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
340 oldvdef = SSA_NAME_VAR (oldvdef); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
341 if (oldvdef != build_vdef) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
342 gimple_set_vdef (stmt, build_vdef); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
343 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
344 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
345 /* Clear and unlink a no longer necessary VDEF. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
346 if (build_vdef == NULL_TREE |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
347 && gimple_vdef (stmt) != NULL_TREE) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
348 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
349 if (TREE_CODE (gimple_vdef (stmt)) == SSA_NAME) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
350 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
351 unlink_stmt_vdef (stmt); |
111 | 352 release_ssa_name_fn (fn, gimple_vdef (stmt)); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
353 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
354 gimple_set_vdef (stmt, NULL_TREE); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
355 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
356 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
357 /* If we have a non-SSA_NAME VDEF, mark it for renaming. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
358 if (gimple_vdef (stmt) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
359 && TREE_CODE (gimple_vdef (stmt)) != SSA_NAME) |
0 | 360 { |
111 | 361 fn->gimple_df->rename_vops = 1; |
362 fn->gimple_df->ssa_renaming_needed = 1; | |
0 | 363 } |
364 } | |
365 | |
366 | |
111 | 367 /* Takes elements from build_uses and turns them into use operands of STMT. */ |
0 | 368 |
369 static inline void | |
111 | 370 finalize_ssa_uses (struct function *fn, gimple *stmt) |
0 | 371 { |
372 unsigned new_i; | |
373 struct use_optype_d new_list; | |
374 use_optype_p old_ops, ptr, last; | |
375 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
376 /* Pre-pend the VUSE we may have built. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
377 if (build_vuse != NULL_TREE) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
378 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
379 tree oldvuse = gimple_vuse (stmt); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
380 if (oldvuse |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
381 && TREE_CODE (oldvuse) == SSA_NAME) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
382 oldvuse = SSA_NAME_VAR (oldvuse); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
383 if (oldvuse != (build_vuse != NULL_TREE |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
384 ? build_vuse : build_vdef)) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
385 gimple_set_vuse (stmt, NULL_TREE); |
111 | 386 build_uses.safe_insert (0, gimple_vuse_ptr (stmt)); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
387 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
388 |
0 | 389 new_list.next = NULL; |
390 last = &new_list; | |
391 | |
392 old_ops = gimple_use_ops (stmt); | |
393 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
394 /* Clear a no longer necessary VUSE. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
395 if (build_vuse == NULL_TREE |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
396 && gimple_vuse (stmt) != NULL_TREE) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
397 gimple_set_vuse (stmt, NULL_TREE); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
398 |
0 | 399 /* If there is anything in the old list, free it. */ |
400 if (old_ops) | |
401 { | |
111 | 402 for (ptr = old_ops; ptr->next; ptr = ptr->next) |
0 | 403 delink_imm_use (USE_OP_PTR (ptr)); |
111 | 404 delink_imm_use (USE_OP_PTR (ptr)); |
405 ptr->next = gimple_ssa_operands (fn)->free_uses; | |
406 gimple_ssa_operands (fn)->free_uses = old_ops; | |
0 | 407 } |
408 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
409 /* If we added a VUSE, make sure to set the operand if it is not already |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
410 present and mark it for renaming. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
411 if (build_vuse != NULL_TREE |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
412 && gimple_vuse (stmt) == NULL_TREE) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
413 { |
111 | 414 gimple_set_vuse (stmt, gimple_vop (fn)); |
415 fn->gimple_df->rename_vops = 1; | |
416 fn->gimple_df->ssa_renaming_needed = 1; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
417 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
418 |
0 | 419 /* Now create nodes for all the new nodes. */ |
111 | 420 for (new_i = 0; new_i < build_uses.length (); new_i++) |
421 { | |
422 tree *op = build_uses[new_i]; | |
423 last = add_use_op (fn, stmt, op, last); | |
424 } | |
0 | 425 |
426 /* Now set the stmt's operands. */ | |
427 gimple_set_use_ops (stmt, new_list.next); | |
428 } | |
429 | |
430 | |
431 /* Clear the in_list bits and empty the build array for VDEFs and | |
432 VUSEs. */ | |
433 | |
434 static inline void | |
435 cleanup_build_arrays (void) | |
436 { | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
437 build_vdef = NULL_TREE; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
438 build_vuse = NULL_TREE; |
111 | 439 build_uses.truncate (0); |
0 | 440 } |
441 | |
442 | |
443 /* Finalize all the build vectors, fill the new ones into INFO. */ | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
444 |
0 | 445 static inline void |
111 | 446 finalize_ssa_stmt_operands (struct function *fn, gimple *stmt) |
0 | 447 { |
111 | 448 finalize_ssa_defs (fn, stmt); |
449 finalize_ssa_uses (fn, stmt); | |
0 | 450 cleanup_build_arrays (); |
451 } | |
452 | |
453 | |
454 /* Start the process of building up operands vectors in INFO. */ | |
455 | |
456 static inline void | |
457 start_ssa_stmt_operands (void) | |
458 { | |
111 | 459 gcc_assert (build_uses.length () == 0); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
460 gcc_assert (build_vuse == NULL_TREE); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
461 gcc_assert (build_vdef == NULL_TREE); |
0 | 462 } |
463 | |
464 | |
465 /* Add USE_P to the list of pointers to operands. */ | |
466 | |
467 static inline void | |
468 append_use (tree *use_p) | |
469 { | |
111 | 470 build_uses.safe_push (use_p); |
0 | 471 } |
472 | |
473 | |
474 /* Add VAR to the set of variables that require a VDEF operator. */ | |
475 | |
476 static inline void | |
477 append_vdef (tree var) | |
478 { | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
479 gcc_assert ((build_vdef == NULL_TREE |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
480 || build_vdef == var) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
481 && (build_vuse == NULL_TREE |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
482 || build_vuse == var)); |
0 | 483 |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
484 build_vdef = var; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
485 build_vuse = var; |
0 | 486 } |
487 | |
488 | |
489 /* Add VAR to the set of variables that require a VUSE operator. */ | |
490 | |
491 static inline void | |
492 append_vuse (tree var) | |
493 { | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
494 gcc_assert (build_vuse == NULL_TREE |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
495 || build_vuse == var); |
0 | 496 |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
497 build_vuse = var; |
0 | 498 } |
499 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
500 /* Add virtual operands for STMT. FLAGS is as in get_expr_operands. */ |
0 | 501 |
502 static void | |
111 | 503 add_virtual_operand (struct function *fn, |
504 gimple *stmt ATTRIBUTE_UNUSED, int flags) | |
0 | 505 { |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
506 /* Add virtual operands to the stmt, unless the caller has specifically |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
507 requested not to do that (used when adding operands inside an |
0 | 508 ADDR_EXPR expression). */ |
509 if (flags & opf_no_vops) | |
510 return; | |
511 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
512 gcc_assert (!is_gimple_debug (stmt)); |
0 | 513 |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
514 if (flags & opf_def) |
111 | 515 append_vdef (gimple_vop (fn)); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
516 else |
111 | 517 append_vuse (gimple_vop (fn)); |
0 | 518 } |
519 | |
520 | |
521 /* Add *VAR_P to the appropriate operand array for statement STMT. | |
522 FLAGS is as in get_expr_operands. If *VAR_P is a GIMPLE register, | |
523 it will be added to the statement's real operands, otherwise it is | |
524 added to virtual operands. */ | |
525 | |
526 static void | |
111 | 527 add_stmt_operand (struct function *fn, tree *var_p, gimple *stmt, int flags) |
0 | 528 { |
111 | 529 tree var = *var_p; |
0 | 530 |
531 gcc_assert (SSA_VAR_P (*var_p)); | |
532 | |
111 | 533 if (is_gimple_reg (var)) |
0 | 534 { |
535 /* The variable is a GIMPLE register. Add it to real operands. */ | |
536 if (flags & opf_def) | |
111 | 537 ; |
0 | 538 else |
539 append_use (var_p); | |
111 | 540 if (DECL_P (*var_p)) |
541 fn->gimple_df->ssa_renaming_needed = 1; | |
0 | 542 } |
543 else | |
111 | 544 { |
545 /* Mark statements with volatile operands. */ | |
546 if (!(flags & opf_no_vops) | |
547 && TREE_THIS_VOLATILE (var)) | |
548 gimple_set_has_volatile_ops (stmt, true); | |
549 | |
550 /* The variable is a memory access. Add virtual operands. */ | |
551 add_virtual_operand (fn, stmt, flags); | |
552 } | |
0 | 553 } |
554 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
555 /* Mark the base address of REF as having its address taken. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
556 REF may be a single variable whose address has been taken or any |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
557 other valid GIMPLE memory reference (structure reference, array, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
558 etc). */ |
0 | 559 |
560 static void | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
561 mark_address_taken (tree ref) |
0 | 562 { |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
563 tree var; |
0 | 564 |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
565 /* Note that it is *NOT OKAY* to use the target of a COMPONENT_REF |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
566 as the only thing we take the address of. If VAR is a structure, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
567 taking the address of a field means that the whole structure may |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
568 be referenced using pointer arithmetic. See PR 21407 and the |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
569 ensuing mailing list discussion. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
570 var = get_base_address (ref); |
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
|
571 if (var) |
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
|
572 { |
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
|
573 if (DECL_P (var)) |
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
|
574 TREE_ADDRESSABLE (var) = 1; |
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
|
575 else if (TREE_CODE (var) == MEM_REF |
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
|
576 && TREE_CODE (TREE_OPERAND (var, 0)) == ADDR_EXPR |
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
|
577 && DECL_P (TREE_OPERAND (TREE_OPERAND (var, 0), 0))) |
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
|
578 TREE_ADDRESSABLE (TREE_OPERAND (TREE_OPERAND (var, 0), 0)) = 1; |
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
|
579 } |
0 | 580 } |
581 | |
582 | |
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
|
583 /* A subroutine of get_expr_operands to handle MEM_REF. |
0 | 584 |
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
|
585 STMT is the statement being processed, EXPR is the MEM_REF |
0 | 586 that got us here. |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
587 |
111 | 588 FLAGS is as in get_expr_operands. */ |
0 | 589 |
590 static void | |
111 | 591 get_mem_ref_operands (struct function *fn, |
592 gimple *stmt, tree expr, int flags) | |
0 | 593 { |
594 tree *pptr = &TREE_OPERAND (expr, 0); | |
595 | |
111 | 596 if (!(flags & opf_no_vops) |
597 && TREE_THIS_VOLATILE (expr)) | |
0 | 598 gimple_set_has_volatile_ops (stmt, true); |
599 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
600 /* Add the VOP. */ |
111 | 601 add_virtual_operand (fn, stmt, flags); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
602 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
603 /* If requested, add a USE operand for the base pointer. */ |
111 | 604 get_expr_operands (fn, stmt, pptr, |
605 opf_non_addressable | opf_use | |
606 | (flags & (opf_no_vops|opf_not_non_addressable))); | |
0 | 607 } |
608 | |
609 | |
610 /* A subroutine of get_expr_operands to handle TARGET_MEM_REF. */ | |
611 | |
612 static void | |
111 | 613 get_tmr_operands (struct function *fn, gimple *stmt, tree expr, int flags) |
0 | 614 { |
111 | 615 if (!(flags & opf_no_vops) |
616 && TREE_THIS_VOLATILE (expr)) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
617 gimple_set_has_volatile_ops (stmt, true); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
618 |
0 | 619 /* First record the real operands. */ |
111 | 620 get_expr_operands (fn, stmt, |
621 &TMR_BASE (expr), opf_use | (flags & opf_no_vops)); | |
622 get_expr_operands (fn, stmt, | |
623 &TMR_INDEX (expr), opf_use | (flags & opf_no_vops)); | |
624 get_expr_operands (fn, stmt, | |
625 &TMR_INDEX2 (expr), opf_use | (flags & opf_no_vops)); | |
0 | 626 |
111 | 627 add_virtual_operand (fn, stmt, flags); |
0 | 628 } |
629 | |
630 | |
631 /* If STMT is a call that may clobber globals and other symbols that | |
632 escape, add them to the VDEF/VUSE lists for it. */ | |
633 | |
634 static void | |
111 | 635 maybe_add_call_vops (struct function *fn, gcall *stmt) |
0 | 636 { |
637 int call_flags = gimple_call_flags (stmt); | |
638 | |
639 /* If aliases have been computed already, add VDEF or VUSE | |
640 operands for all the symbols that have been found to be | |
641 call-clobbered. */ | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
642 if (!(call_flags & ECF_NOVOPS)) |
0 | 643 { |
111 | 644 /* A 'pure' or a 'const' function never call-clobbers anything. */ |
645 if (!(call_flags & (ECF_PURE | ECF_CONST))) | |
646 add_virtual_operand (fn, stmt, opf_def); | |
0 | 647 else if (!(call_flags & ECF_CONST)) |
111 | 648 add_virtual_operand (fn, stmt, opf_use); |
0 | 649 } |
650 } | |
651 | |
652 | |
653 /* Scan operands in the ASM_EXPR stmt referred to in INFO. */ | |
654 | |
655 static void | |
111 | 656 get_asm_stmt_operands (struct function *fn, gasm *stmt) |
0 | 657 { |
658 size_t i, noutputs; | |
659 const char **oconstraints; | |
660 const char *constraint; | |
661 bool allows_mem, allows_reg, is_inout; | |
662 | |
663 noutputs = gimple_asm_noutputs (stmt); | |
664 oconstraints = (const char **) alloca ((noutputs) * sizeof (const char *)); | |
665 | |
666 /* Gather all output operands. */ | |
667 for (i = 0; i < gimple_asm_noutputs (stmt); i++) | |
668 { | |
669 tree link = gimple_asm_output_op (stmt, i); | |
670 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link))); | |
671 oconstraints[i] = constraint; | |
672 parse_output_constraint (&constraint, i, 0, 0, &allows_mem, | |
673 &allows_reg, &is_inout); | |
674 | |
675 /* This should have been split in gimplify_asm_expr. */ | |
676 gcc_assert (!allows_reg || !is_inout); | |
677 | |
678 /* Memory operands are addressable. Note that STMT needs the | |
679 address of this operand. */ | |
680 if (!allows_reg && allows_mem) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
681 mark_address_taken (TREE_VALUE (link)); |
0 | 682 |
111 | 683 get_expr_operands (fn, stmt, |
684 &TREE_VALUE (link), opf_def | opf_not_non_addressable); | |
0 | 685 } |
686 | |
687 /* Gather all input operands. */ | |
688 for (i = 0; i < gimple_asm_ninputs (stmt); i++) | |
689 { | |
690 tree link = gimple_asm_input_op (stmt, i); | |
691 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link))); | |
692 parse_input_constraint (&constraint, 0, 0, noutputs, 0, oconstraints, | |
693 &allows_mem, &allows_reg); | |
694 | |
695 /* Memory operands are addressable. Note that STMT needs the | |
696 address of this operand. */ | |
697 if (!allows_reg && allows_mem) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
698 mark_address_taken (TREE_VALUE (link)); |
0 | 699 |
111 | 700 get_expr_operands (fn, stmt, &TREE_VALUE (link), opf_not_non_addressable); |
0 | 701 } |
702 | |
703 /* Clobber all memory and addressable symbols for asm ("" : : : "memory"); */ | |
111 | 704 if (gimple_asm_clobbers_memory_p (stmt)) |
705 add_virtual_operand (fn, stmt, opf_def); | |
0 | 706 } |
707 | |
708 | |
709 /* Recursively scan the expression pointed to by EXPR_P in statement | |
710 STMT. FLAGS is one of the OPF_* constants modifying how to | |
711 interpret the operands found. */ | |
712 | |
713 static void | |
111 | 714 get_expr_operands (struct function *fn, gimple *stmt, tree *expr_p, int flags) |
0 | 715 { |
716 enum tree_code code; | |
717 enum tree_code_class codeclass; | |
718 tree expr = *expr_p; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
719 int uflags = opf_use; |
0 | 720 |
721 if (expr == NULL) | |
722 return; | |
723 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
724 if (is_gimple_debug (stmt)) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
725 uflags |= (flags & opf_no_vops); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
726 |
0 | 727 code = TREE_CODE (expr); |
728 codeclass = TREE_CODE_CLASS (code); | |
729 | |
730 switch (code) | |
731 { | |
732 case ADDR_EXPR: | |
733 /* Taking the address of a variable does not represent a | |
734 reference to it, but the fact that the statement takes its | |
735 address will be of interest to some passes (e.g. alias | |
736 resolution). */ | |
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
|
737 if ((!(flags & opf_non_addressable) |
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
|
738 || (flags & opf_not_non_addressable)) |
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
|
739 && !is_gimple_debug (stmt)) |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
740 mark_address_taken (TREE_OPERAND (expr, 0)); |
0 | 741 |
742 /* Otherwise, there may be variables referenced inside but there | |
743 should be no VUSEs created, since the referenced objects are | |
744 not really accessed. The only operands that we should find | |
745 here are ARRAY_REF indices which will always be real operands | |
746 (GIMPLE does not allow non-registers as array indices). */ | |
747 flags |= opf_no_vops; | |
111 | 748 get_expr_operands (fn, stmt, &TREE_OPERAND (expr, 0), |
749 flags | opf_not_non_addressable | opf_address_taken); | |
0 | 750 return; |
751 | |
752 case SSA_NAME: | |
753 case VAR_DECL: | |
754 case PARM_DECL: | |
755 case RESULT_DECL: | |
111 | 756 if (!(flags & opf_address_taken)) |
757 add_stmt_operand (fn, expr_p, stmt, flags); | |
0 | 758 return; |
759 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
760 case DEBUG_EXPR_DECL: |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
761 gcc_assert (gimple_debug_bind_p (stmt)); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
762 return; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
763 |
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
|
764 case MEM_REF: |
111 | 765 get_mem_ref_operands (fn, stmt, expr, flags); |
0 | 766 return; |
767 | |
768 case TARGET_MEM_REF: | |
111 | 769 get_tmr_operands (fn, stmt, expr, flags); |
0 | 770 return; |
771 | |
772 case ARRAY_REF: | |
773 case ARRAY_RANGE_REF: | |
774 case COMPONENT_REF: | |
775 case REALPART_EXPR: | |
776 case IMAGPART_EXPR: | |
777 { | |
111 | 778 if (!(flags & opf_no_vops) |
779 && TREE_THIS_VOLATILE (expr)) | |
0 | 780 gimple_set_has_volatile_ops (stmt, true); |
781 | |
111 | 782 get_expr_operands (fn, stmt, &TREE_OPERAND (expr, 0), flags); |
0 | 783 |
784 if (code == COMPONENT_REF) | |
785 { | |
111 | 786 if (!(flags & opf_no_vops) |
787 && TREE_THIS_VOLATILE (TREE_OPERAND (expr, 1))) | |
0 | 788 gimple_set_has_volatile_ops (stmt, true); |
111 | 789 get_expr_operands (fn, stmt, &TREE_OPERAND (expr, 2), uflags); |
0 | 790 } |
791 else if (code == ARRAY_REF || code == ARRAY_RANGE_REF) | |
792 { | |
111 | 793 get_expr_operands (fn, stmt, &TREE_OPERAND (expr, 1), uflags); |
794 get_expr_operands (fn, stmt, &TREE_OPERAND (expr, 2), uflags); | |
795 get_expr_operands (fn, stmt, &TREE_OPERAND (expr, 3), uflags); | |
0 | 796 } |
797 | |
798 return; | |
799 } | |
800 | |
801 case WITH_SIZE_EXPR: | |
802 /* WITH_SIZE_EXPR is a pass-through reference to its first argument, | |
803 and an rvalue reference to its second argument. */ | |
111 | 804 get_expr_operands (fn, stmt, &TREE_OPERAND (expr, 1), uflags); |
805 get_expr_operands (fn, stmt, &TREE_OPERAND (expr, 0), flags); | |
0 | 806 return; |
807 | |
808 case COND_EXPR: | |
809 case VEC_COND_EXPR: | |
111 | 810 case VEC_PERM_EXPR: |
811 get_expr_operands (fn, stmt, &TREE_OPERAND (expr, 0), uflags); | |
812 get_expr_operands (fn, stmt, &TREE_OPERAND (expr, 1), uflags); | |
813 get_expr_operands (fn, stmt, &TREE_OPERAND (expr, 2), uflags); | |
0 | 814 return; |
815 | |
816 case CONSTRUCTOR: | |
817 { | |
818 /* General aggregate CONSTRUCTORs have been decomposed, but they | |
819 are still in use as the COMPLEX_EXPR equivalent for vectors. */ | |
820 constructor_elt *ce; | |
821 unsigned HOST_WIDE_INT idx; | |
822 | |
111 | 823 /* A volatile constructor is actually TREE_CLOBBER_P, transfer |
824 the volatility to the statement, don't use TREE_CLOBBER_P for | |
825 mirroring the other uses of THIS_VOLATILE in this file. */ | |
826 if (!(flags & opf_no_vops) | |
827 && TREE_THIS_VOLATILE (expr)) | |
828 gimple_set_has_volatile_ops (stmt, true); | |
829 | |
0 | 830 for (idx = 0; |
111 | 831 vec_safe_iterate (CONSTRUCTOR_ELTS (expr), idx, &ce); |
0 | 832 idx++) |
111 | 833 get_expr_operands (fn, stmt, &ce->value, uflags); |
0 | 834 |
835 return; | |
836 } | |
837 | |
838 case BIT_FIELD_REF: | |
111 | 839 if (!(flags & opf_no_vops) |
840 && TREE_THIS_VOLATILE (expr)) | |
0 | 841 gimple_set_has_volatile_ops (stmt, true); |
842 /* FALLTHRU */ | |
843 | |
844 case VIEW_CONVERT_EXPR: | |
845 do_unary: | |
111 | 846 get_expr_operands (fn, stmt, &TREE_OPERAND (expr, 0), flags); |
0 | 847 return; |
848 | |
111 | 849 case BIT_INSERT_EXPR: |
0 | 850 case COMPOUND_EXPR: |
851 case OBJ_TYPE_REF: | |
852 case ASSERT_EXPR: | |
853 do_binary: | |
854 { | |
111 | 855 get_expr_operands (fn, stmt, &TREE_OPERAND (expr, 0), flags); |
856 get_expr_operands (fn, stmt, &TREE_OPERAND (expr, 1), flags); | |
0 | 857 return; |
858 } | |
859 | |
860 case DOT_PROD_EXPR: | |
111 | 861 case SAD_EXPR: |
0 | 862 case REALIGN_LOAD_EXPR: |
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
|
863 case WIDEN_MULT_PLUS_EXPR: |
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
|
864 case WIDEN_MULT_MINUS_EXPR: |
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
|
865 case FMA_EXPR: |
0 | 866 { |
111 | 867 get_expr_operands (fn, stmt, &TREE_OPERAND (expr, 0), flags); |
868 get_expr_operands (fn, stmt, &TREE_OPERAND (expr, 1), flags); | |
869 get_expr_operands (fn, stmt, &TREE_OPERAND (expr, 2), flags); | |
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
|
870 return; |
0 | 871 } |
872 | |
873 case FUNCTION_DECL: | |
874 case LABEL_DECL: | |
875 case CONST_DECL: | |
876 case CASE_LABEL_EXPR: | |
877 /* Expressions that make no memory references. */ | |
878 return; | |
879 | |
880 default: | |
881 if (codeclass == tcc_unary) | |
882 goto do_unary; | |
883 if (codeclass == tcc_binary || codeclass == tcc_comparison) | |
884 goto do_binary; | |
885 if (codeclass == tcc_constant || codeclass == tcc_type) | |
886 return; | |
887 } | |
888 | |
889 /* If we get here, something has gone wrong. */ | |
111 | 890 if (flag_checking) |
891 { | |
892 fprintf (stderr, "unhandled expression in get_expr_operands():\n"); | |
893 debug_tree (expr); | |
894 fputs ("\n", stderr); | |
895 gcc_unreachable (); | |
896 } | |
0 | 897 } |
898 | |
899 | |
900 /* Parse STMT looking for operands. When finished, the various | |
901 build_* operand vectors will have potential operands in them. */ | |
902 | |
903 static void | |
111 | 904 parse_ssa_operands (struct function *fn, gimple *stmt) |
0 | 905 { |
906 enum gimple_code code = gimple_code (stmt); | |
111 | 907 size_t i, n, start = 0; |
0 | 908 |
111 | 909 switch (code) |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
910 { |
111 | 911 case GIMPLE_ASM: |
912 get_asm_stmt_operands (fn, as_a <gasm *> (stmt)); | |
913 break; | |
914 | |
915 case GIMPLE_TRANSACTION: | |
916 /* The start of a transaction is a memory barrier. */ | |
917 add_virtual_operand (fn, stmt, opf_def | opf_use); | |
918 break; | |
919 | |
920 case GIMPLE_DEBUG: | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
921 if (gimple_debug_bind_p (stmt) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
922 && gimple_debug_bind_has_value_p (stmt)) |
111 | 923 get_expr_operands (fn, stmt, gimple_debug_bind_get_value_ptr (stmt), |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
924 opf_use | opf_no_vops); |
111 | 925 break; |
926 | |
927 case GIMPLE_RETURN: | |
928 append_vuse (gimple_vop (fn)); | |
929 goto do_default; | |
0 | 930 |
111 | 931 case GIMPLE_CALL: |
932 /* Add call-clobbered operands, if needed. */ | |
933 maybe_add_call_vops (fn, as_a <gcall *> (stmt)); | |
934 /* FALLTHRU */ | |
0 | 935 |
111 | 936 case GIMPLE_ASSIGN: |
937 get_expr_operands (fn, stmt, gimple_op_ptr (stmt, 0), opf_def); | |
938 start = 1; | |
939 /* FALLTHRU */ | |
0 | 940 |
111 | 941 default: |
942 do_default: | |
943 n = gimple_num_ops (stmt); | |
944 for (i = start; i < n; i++) | |
945 get_expr_operands (fn, stmt, gimple_op_ptr (stmt, i), opf_use); | |
946 break; | |
0 | 947 } |
948 } | |
949 | |
950 | |
951 /* Create an operands cache for STMT. */ | |
952 | |
953 static void | |
111 | 954 build_ssa_operands (struct function *fn, gimple *stmt) |
0 | 955 { |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
956 /* Initially assume that the statement has no volatile operands. */ |
0 | 957 gimple_set_has_volatile_ops (stmt, false); |
958 | |
959 start_ssa_stmt_operands (); | |
111 | 960 parse_ssa_operands (fn, stmt); |
961 finalize_ssa_stmt_operands (fn, stmt); | |
962 } | |
963 | |
964 /* Verifies SSA statement operands. */ | |
965 | |
966 DEBUG_FUNCTION bool | |
967 verify_ssa_operands (struct function *fn, gimple *stmt) | |
968 { | |
969 use_operand_p use_p; | |
970 def_operand_p def_p; | |
971 ssa_op_iter iter; | |
972 unsigned i; | |
973 tree def; | |
974 bool volatile_p = gimple_has_volatile_ops (stmt); | |
975 | |
976 /* build_ssa_operands w/o finalizing them. */ | |
977 gimple_set_has_volatile_ops (stmt, false); | |
978 start_ssa_stmt_operands (); | |
979 parse_ssa_operands (fn, stmt); | |
980 | |
981 /* Now verify the built operands are the same as present in STMT. */ | |
982 def = gimple_vdef (stmt); | |
983 if (def | |
984 && TREE_CODE (def) == SSA_NAME) | |
985 def = SSA_NAME_VAR (def); | |
986 if (build_vdef != def) | |
987 { | |
988 error ("virtual definition of statement not up-to-date"); | |
989 return true; | |
990 } | |
991 if (gimple_vdef (stmt) | |
992 && ((def_p = gimple_vdef_op (stmt)) == NULL_DEF_OPERAND_P | |
993 || DEF_FROM_PTR (def_p) != gimple_vdef (stmt))) | |
994 { | |
995 error ("virtual def operand missing for stmt"); | |
996 return true; | |
997 } | |
998 | |
999 tree use = gimple_vuse (stmt); | |
1000 if (use | |
1001 && TREE_CODE (use) == SSA_NAME) | |
1002 use = SSA_NAME_VAR (use); | |
1003 if (build_vuse != use) | |
1004 { | |
1005 error ("virtual use of statement not up-to-date"); | |
1006 return true; | |
1007 } | |
1008 if (gimple_vuse (stmt) | |
1009 && ((use_p = gimple_vuse_op (stmt)) == NULL_USE_OPERAND_P | |
1010 || USE_FROM_PTR (use_p) != gimple_vuse (stmt))) | |
1011 { | |
1012 error ("virtual use operand missing for stmt"); | |
1013 return true; | |
1014 } | |
1015 | |
1016 FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE) | |
1017 { | |
1018 tree *op; | |
1019 FOR_EACH_VEC_ELT (build_uses, i, op) | |
1020 { | |
1021 if (use_p->use == op) | |
1022 { | |
1023 build_uses[i] = NULL; | |
1024 break; | |
1025 } | |
1026 } | |
1027 if (i == build_uses.length ()) | |
1028 { | |
1029 error ("excess use operand for stmt"); | |
1030 debug_generic_expr (USE_FROM_PTR (use_p)); | |
1031 return true; | |
1032 } | |
1033 } | |
1034 | |
1035 tree *op; | |
1036 FOR_EACH_VEC_ELT (build_uses, i, op) | |
1037 if (op != NULL) | |
1038 { | |
1039 error ("use operand missing for stmt"); | |
1040 debug_generic_expr (*op); | |
1041 return true; | |
1042 } | |
1043 | |
1044 if (gimple_has_volatile_ops (stmt) != volatile_p) | |
1045 { | |
1046 error ("stmt volatile flag not up-to-date"); | |
1047 return true; | |
1048 } | |
1049 | |
1050 cleanup_build_arrays (); | |
1051 return false; | |
0 | 1052 } |
1053 | |
1054 | |
1055 /* Releases the operands of STMT back to their freelists, and clears | |
1056 the stmt operand lists. */ | |
1057 | |
1058 void | |
111 | 1059 free_stmt_operands (struct function *fn, gimple *stmt) |
0 | 1060 { |
1061 use_optype_p uses = gimple_use_ops (stmt), last_use; | |
1062 | |
1063 if (uses) | |
1064 { | |
1065 for (last_use = uses; last_use->next; last_use = last_use->next) | |
1066 delink_imm_use (USE_OP_PTR (last_use)); | |
1067 delink_imm_use (USE_OP_PTR (last_use)); | |
111 | 1068 last_use->next = gimple_ssa_operands (fn)->free_uses; |
1069 gimple_ssa_operands (fn)->free_uses = uses; | |
0 | 1070 gimple_set_use_ops (stmt, NULL); |
1071 } | |
1072 | |
1073 if (gimple_has_mem_ops (stmt)) | |
1074 { | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
1075 gimple_set_vuse (stmt, NULL_TREE); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
1076 gimple_set_vdef (stmt, NULL_TREE); |
0 | 1077 } |
1078 } | |
1079 | |
1080 | |
1081 /* Get the operands of statement STMT. */ | |
1082 | |
1083 void | |
111 | 1084 update_stmt_operands (struct function *fn, gimple *stmt) |
0 | 1085 { |
1086 /* If update_stmt_operands is called before SSA is initialized, do | |
1087 nothing. */ | |
111 | 1088 if (!ssa_operands_active (fn)) |
0 | 1089 return; |
1090 | |
1091 timevar_push (TV_TREE_OPS); | |
1092 | |
1093 gcc_assert (gimple_modified_p (stmt)); | |
111 | 1094 build_ssa_operands (fn, stmt); |
0 | 1095 gimple_set_modified (stmt, false); |
1096 | |
1097 timevar_pop (TV_TREE_OPS); | |
1098 } | |
1099 | |
1100 | |
1101 /* Swap operands EXP0 and EXP1 in statement STMT. No attempt is done | |
1102 to test the validity of the swap operation. */ | |
1103 | |
1104 void | |
111 | 1105 swap_ssa_operands (gimple *stmt, tree *exp0, tree *exp1) |
0 | 1106 { |
1107 tree op0, op1; | |
1108 op0 = *exp0; | |
1109 op1 = *exp1; | |
1110 | |
111 | 1111 if (op0 != op1) |
0 | 1112 { |
111 | 1113 /* Attempt to preserve the relative positions of these two operands in |
1114 their * respective immediate use lists by adjusting their use pointer | |
1115 to point to the new operand position. */ | |
0 | 1116 use_optype_p use0, use1, ptr; |
1117 use0 = use1 = NULL; | |
1118 | |
1119 /* Find the 2 operands in the cache, if they are there. */ | |
1120 for (ptr = gimple_use_ops (stmt); ptr; ptr = ptr->next) | |
1121 if (USE_OP_PTR (ptr)->use == exp0) | |
1122 { | |
1123 use0 = ptr; | |
1124 break; | |
1125 } | |
1126 | |
1127 for (ptr = gimple_use_ops (stmt); ptr; ptr = ptr->next) | |
1128 if (USE_OP_PTR (ptr)->use == exp1) | |
1129 { | |
1130 use1 = ptr; | |
1131 break; | |
1132 } | |
1133 | |
111 | 1134 /* And adjust their location to point to the new position of the |
1135 operand. */ | |
1136 if (use0) | |
1137 USE_OP_PTR (use0)->use = exp1; | |
1138 if (use1) | |
1139 USE_OP_PTR (use1)->use = exp0; | |
1140 | |
1141 /* Now swap the data. */ | |
1142 *exp0 = op1; | |
1143 *exp1 = op0; | |
0 | 1144 } |
1145 } | |
1146 | |
1147 | |
1148 /* Scan the immediate_use list for VAR making sure its linked properly. | |
1149 Return TRUE if there is a problem and emit an error message to F. */ | |
1150 | |
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
|
1151 DEBUG_FUNCTION bool |
0 | 1152 verify_imm_links (FILE *f, tree var) |
1153 { | |
1154 use_operand_p ptr, prev, list; | |
111 | 1155 unsigned int count; |
0 | 1156 |
1157 gcc_assert (TREE_CODE (var) == SSA_NAME); | |
1158 | |
1159 list = &(SSA_NAME_IMM_USE_NODE (var)); | |
1160 gcc_assert (list->use == NULL); | |
1161 | |
1162 if (list->prev == NULL) | |
1163 { | |
1164 gcc_assert (list->next == NULL); | |
1165 return false; | |
1166 } | |
1167 | |
1168 prev = list; | |
1169 count = 0; | |
1170 for (ptr = list->next; ptr != list; ) | |
1171 { | |
1172 if (prev != ptr->prev) | |
111 | 1173 { |
1174 fprintf (f, "prev != ptr->prev\n"); | |
1175 goto error; | |
1176 } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
1177 |
0 | 1178 if (ptr->use == NULL) |
111 | 1179 { |
1180 fprintf (f, "ptr->use == NULL\n"); | |
1181 goto error; /* 2 roots, or SAFE guard node. */ | |
1182 } | |
0 | 1183 else if (*(ptr->use) != var) |
111 | 1184 { |
1185 fprintf (f, "*(ptr->use) != var\n"); | |
1186 goto error; | |
1187 } | |
0 | 1188 |
1189 prev = ptr; | |
1190 ptr = ptr->next; | |
1191 | |
111 | 1192 count++; |
1193 if (count == 0) | |
1194 { | |
1195 fprintf (f, "number of immediate uses doesn't fit unsigned int\n"); | |
1196 goto error; | |
1197 } | |
0 | 1198 } |
1199 | |
1200 /* Verify list in the other direction. */ | |
1201 prev = list; | |
1202 for (ptr = list->prev; ptr != list; ) | |
1203 { | |
1204 if (prev != ptr->next) | |
111 | 1205 { |
1206 fprintf (f, "prev != ptr->next\n"); | |
1207 goto error; | |
1208 } | |
0 | 1209 prev = ptr; |
1210 ptr = ptr->prev; | |
111 | 1211 if (count == 0) |
1212 { | |
1213 fprintf (f, "count-- < 0\n"); | |
1214 goto error; | |
1215 } | |
1216 count--; | |
0 | 1217 } |
1218 | |
1219 if (count != 0) | |
111 | 1220 { |
1221 fprintf (f, "count != 0\n"); | |
1222 goto error; | |
1223 } | |
0 | 1224 |
1225 return false; | |
1226 | |
1227 error: | |
1228 if (ptr->loc.stmt && gimple_modified_p (ptr->loc.stmt)) | |
1229 { | |
1230 fprintf (f, " STMT MODIFIED. - <%p> ", (void *)ptr->loc.stmt); | |
1231 print_gimple_stmt (f, ptr->loc.stmt, 0, TDF_SLIM); | |
1232 } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
1233 fprintf (f, " IMM ERROR : (use_p : tree - %p:%p)", (void *)ptr, |
0 | 1234 (void *)ptr->use); |
1235 print_generic_expr (f, USE_FROM_PTR (ptr), TDF_SLIM); | |
111 | 1236 fprintf (f, "\n"); |
0 | 1237 return true; |
1238 } | |
1239 | |
1240 | |
1241 /* Dump all the immediate uses to FILE. */ | |
1242 | |
1243 void | |
1244 dump_immediate_uses_for (FILE *file, tree var) | |
1245 { | |
1246 imm_use_iterator iter; | |
1247 use_operand_p use_p; | |
1248 | |
1249 gcc_assert (var && TREE_CODE (var) == SSA_NAME); | |
1250 | |
1251 print_generic_expr (file, var, TDF_SLIM); | |
1252 fprintf (file, " : -->"); | |
1253 if (has_zero_uses (var)) | |
1254 fprintf (file, " no uses.\n"); | |
1255 else | |
1256 if (has_single_use (var)) | |
1257 fprintf (file, " single use.\n"); | |
1258 else | |
1259 fprintf (file, "%d uses.\n", num_imm_uses (var)); | |
1260 | |
1261 FOR_EACH_IMM_USE_FAST (use_p, iter, var) | |
1262 { | |
1263 if (use_p->loc.stmt == NULL && use_p->use == NULL) | |
1264 fprintf (file, "***end of stmt iterator marker***\n"); | |
1265 else | |
1266 if (!is_gimple_reg (USE_FROM_PTR (use_p))) | |
1267 print_gimple_stmt (file, USE_STMT (use_p), 0, TDF_VOPS|TDF_MEMSYMS); | |
1268 else | |
1269 print_gimple_stmt (file, USE_STMT (use_p), 0, TDF_SLIM); | |
1270 } | |
111 | 1271 fprintf (file, "\n"); |
0 | 1272 } |
1273 | |
1274 | |
1275 /* Dump all the immediate uses to FILE. */ | |
1276 | |
1277 void | |
1278 dump_immediate_uses (FILE *file) | |
1279 { | |
1280 tree var; | |
1281 unsigned int x; | |
1282 | |
1283 fprintf (file, "Immediate_uses: \n\n"); | |
111 | 1284 FOR_EACH_SSA_NAME (x, var, cfun) |
0 | 1285 { |
1286 dump_immediate_uses_for (file, var); | |
1287 } | |
1288 } | |
1289 | |
1290 | |
1291 /* Dump def-use edges on stderr. */ | |
1292 | |
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
|
1293 DEBUG_FUNCTION void |
0 | 1294 debug_immediate_uses (void) |
1295 { | |
1296 dump_immediate_uses (stderr); | |
1297 } | |
1298 | |
1299 | |
1300 /* Dump def-use edges on stderr. */ | |
1301 | |
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
|
1302 DEBUG_FUNCTION void |
0 | 1303 debug_immediate_uses_for (tree var) |
1304 { | |
1305 dump_immediate_uses_for (stderr, var); | |
1306 } | |
1307 | |
1308 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
1309 /* Unlink STMTs virtual definition from the IL by propagating its use. */ |
0 | 1310 |
1311 void | |
111 | 1312 unlink_stmt_vdef (gimple *stmt) |
0 | 1313 { |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
1314 use_operand_p use_p; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
1315 imm_use_iterator iter; |
111 | 1316 gimple *use_stmt; |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
1317 tree vdef = gimple_vdef (stmt); |
111 | 1318 tree vuse = gimple_vuse (stmt); |
0 | 1319 |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
1320 if (!vdef |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
1321 || TREE_CODE (vdef) != SSA_NAME) |
0 | 1322 return; |
1323 | |
111 | 1324 FOR_EACH_IMM_USE_STMT (use_stmt, iter, vdef) |
0 | 1325 { |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
1326 FOR_EACH_IMM_USE_ON_STMT (use_p, iter) |
111 | 1327 SET_USE (use_p, vuse); |
0 | 1328 } |
1329 | |
111 | 1330 if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (vdef)) |
1331 SSA_NAME_OCCURS_IN_ABNORMAL_PHI (vuse) = 1; | |
0 | 1332 } |
1333 | |
111 | 1334 /* Return true if the var whose chain of uses starts at PTR has a |
1335 single nondebug use. Set USE_P and STMT to that single nondebug | |
1336 use, if so, or to NULL otherwise. */ | |
1337 bool | |
1338 single_imm_use_1 (const ssa_use_operand_t *head, | |
1339 use_operand_p *use_p, gimple **stmt) | |
1340 { | |
1341 ssa_use_operand_t *ptr, *single_use = 0; | |
1342 | |
1343 for (ptr = head->next; ptr != head; ptr = ptr->next) | |
1344 if (USE_STMT(ptr) && !is_gimple_debug (USE_STMT (ptr))) | |
1345 { | |
1346 if (single_use) | |
1347 { | |
1348 single_use = NULL; | |
1349 break; | |
1350 } | |
1351 single_use = ptr; | |
1352 } | |
1353 | |
1354 if (use_p) | |
1355 *use_p = single_use; | |
1356 | |
1357 if (stmt) | |
1358 *stmt = single_use ? single_use->loc.stmt : NULL; | |
1359 | |
1360 return single_use; | |
1361 } | |
1362 |