]>
Commit | Line | Data |
---|---|---|
6de9cd9a | 1 | /* Inline functions for tree-flow.h |
9dcd6f09 | 2 | Copyright (C) 2001, 2003, 2005, 2006, 2007 Free Software Foundation, Inc. |
6de9cd9a DN |
3 | Contributed by Diego Novillo <dnovillo@redhat.com> |
4 | ||
5 | This file is part of GCC. | |
6 | ||
7 | GCC is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9dcd6f09 | 9 | the Free Software Foundation; either version 3, or (at your option) |
6de9cd9a DN |
10 | any later version. |
11 | ||
12 | GCC is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
9dcd6f09 NC |
18 | along with GCC; see the file COPYING3. If not see |
19 | <http://www.gnu.org/licenses/>. */ | |
6de9cd9a DN |
20 | |
21 | #ifndef _TREE_FLOW_INLINE_H | |
22 | #define _TREE_FLOW_INLINE_H 1 | |
23 | ||
24 | /* Inline functions for manipulating various data structures defined in | |
25 | tree-flow.h. See tree-flow.h for documentation. */ | |
26 | ||
5cd4ec7f JH |
27 | /* Return true when gimple SSA form was built. |
28 | gimple_in_ssa_p is queried by gimplifier in various early stages before SSA | |
29 | infrastructure is initialized. Check for presence of the datastructures | |
30 | at first place. */ | |
31 | static inline bool | |
9566a759 | 32 | gimple_in_ssa_p (const struct function *fun) |
5cd4ec7f JH |
33 | { |
34 | return fun && fun->gimple_df && fun->gimple_df->in_ssa_p; | |
35 | } | |
36 | ||
37 | /* 'true' after aliases have been computed (see compute_may_aliases). */ | |
38 | static inline bool | |
9566a759 | 39 | gimple_aliases_computed_p (const struct function *fun) |
5cd4ec7f JH |
40 | { |
41 | gcc_assert (fun && fun->gimple_df); | |
42 | return fun->gimple_df->aliases_computed_p; | |
43 | } | |
44 | ||
45 | /* Addressable variables in the function. If bit I is set, then | |
46 | REFERENCED_VARS (I) has had its address taken. Note that | |
47 | CALL_CLOBBERED_VARS and ADDRESSABLE_VARS are not related. An | |
48 | addressable variable is not necessarily call-clobbered (e.g., a | |
49 | local addressable whose address does not escape) and not all | |
50 | call-clobbered variables are addressable (e.g., a local static | |
51 | variable). */ | |
52 | static inline bitmap | |
9566a759 | 53 | gimple_addressable_vars (const struct function *fun) |
5cd4ec7f JH |
54 | { |
55 | gcc_assert (fun && fun->gimple_df); | |
56 | return fun->gimple_df->addressable_vars; | |
57 | } | |
58 | ||
59 | /* Call clobbered variables in the function. If bit I is set, then | |
60 | REFERENCED_VARS (I) is call-clobbered. */ | |
61 | static inline bitmap | |
9566a759 | 62 | gimple_call_clobbered_vars (const struct function *fun) |
5cd4ec7f JH |
63 | { |
64 | gcc_assert (fun && fun->gimple_df); | |
65 | return fun->gimple_df->call_clobbered_vars; | |
66 | } | |
67 | ||
68 | /* Array of all variables referenced in the function. */ | |
69 | static inline htab_t | |
9566a759 | 70 | gimple_referenced_vars (const struct function *fun) |
5cd4ec7f JH |
71 | { |
72 | if (!fun->gimple_df) | |
73 | return NULL; | |
74 | return fun->gimple_df->referenced_vars; | |
75 | } | |
76 | ||
77 | /* Artificial variable used to model the effects of function calls. */ | |
78 | static inline tree | |
9566a759 | 79 | gimple_global_var (const struct function *fun) |
5cd4ec7f JH |
80 | { |
81 | gcc_assert (fun && fun->gimple_df); | |
82 | return fun->gimple_df->global_var; | |
83 | } | |
84 | ||
85 | /* Artificial variable used to model the effects of nonlocal | |
86 | variables. */ | |
87 | static inline tree | |
9566a759 | 88 | gimple_nonlocal_all (const struct function *fun) |
5cd4ec7f JH |
89 | { |
90 | gcc_assert (fun && fun->gimple_df); | |
91 | return fun->gimple_df->nonlocal_all; | |
92 | } | |
adb6509f JH |
93 | |
94 | /* Hashtable of variables annotations. Used for static variables only; | |
95 | local variables have direct pointer in the tree node. */ | |
96 | static inline htab_t | |
9566a759 | 97 | gimple_var_anns (const struct function *fun) |
adb6509f JH |
98 | { |
99 | return fun->gimple_df->var_anns; | |
100 | } | |
101 | ||
a3648cfc DB |
102 | /* Initialize the hashtable iterator HTI to point to hashtable TABLE */ |
103 | ||
104 | static inline void * | |
105 | first_htab_element (htab_iterator *hti, htab_t table) | |
106 | { | |
107 | hti->htab = table; | |
108 | hti->slot = table->entries; | |
109 | hti->limit = hti->slot + htab_size (table); | |
110 | do | |
111 | { | |
112 | PTR x = *(hti->slot); | |
113 | if (x != HTAB_EMPTY_ENTRY && x != HTAB_DELETED_ENTRY) | |
114 | break; | |
115 | } while (++(hti->slot) < hti->limit); | |
116 | ||
117 | if (hti->slot < hti->limit) | |
118 | return *(hti->slot); | |
119 | return NULL; | |
120 | } | |
121 | ||
122 | /* Return current non-empty/deleted slot of the hashtable pointed to by HTI, | |
123 | or NULL if we have reached the end. */ | |
124 | ||
125 | static inline bool | |
9566a759 | 126 | end_htab_p (const htab_iterator *hti) |
a3648cfc DB |
127 | { |
128 | if (hti->slot >= hti->limit) | |
129 | return true; | |
130 | return false; | |
131 | } | |
132 | ||
206048bd | 133 | /* Advance the hashtable iterator pointed to by HTI to the next element of the |
a3648cfc DB |
134 | hashtable. */ |
135 | ||
136 | static inline void * | |
137 | next_htab_element (htab_iterator *hti) | |
138 | { | |
139 | while (++(hti->slot) < hti->limit) | |
140 | { | |
141 | PTR x = *(hti->slot); | |
142 | if (x != HTAB_EMPTY_ENTRY && x != HTAB_DELETED_ENTRY) | |
143 | return x; | |
144 | }; | |
145 | return NULL; | |
146 | } | |
147 | ||
148 | /* Initialize ITER to point to the first referenced variable in the | |
149 | referenced_vars hashtable, and return that variable. */ | |
150 | ||
151 | static inline tree | |
152 | first_referenced_var (referenced_var_iterator *iter) | |
153 | { | |
9fc5a389 RG |
154 | return (tree) first_htab_element (&iter->hti, |
155 | gimple_referenced_vars (cfun)); | |
a3648cfc DB |
156 | } |
157 | ||
158 | /* Return true if we have hit the end of the referenced variables ITER is | |
159 | iterating through. */ | |
160 | ||
161 | static inline bool | |
9566a759 | 162 | end_referenced_vars_p (const referenced_var_iterator *iter) |
a3648cfc DB |
163 | { |
164 | return end_htab_p (&iter->hti); | |
165 | } | |
166 | ||
167 | /* Make ITER point to the next referenced_var in the referenced_var hashtable, | |
168 | and return that variable. */ | |
169 | ||
170 | static inline tree | |
171 | next_referenced_var (referenced_var_iterator *iter) | |
172 | { | |
9fc5a389 | 173 | return (tree) next_htab_element (&iter->hti); |
a3648cfc | 174 | } |
b9d33488 DB |
175 | |
176 | /* Fill up VEC with the variables in the referenced vars hashtable. */ | |
177 | ||
178 | static inline void | |
179 | fill_referenced_var_vec (VEC (tree, heap) **vec) | |
180 | { | |
181 | referenced_var_iterator rvi; | |
182 | tree var; | |
183 | *vec = NULL; | |
184 | FOR_EACH_REFERENCED_VAR (var, rvi) | |
185 | VEC_safe_push (tree, heap, *vec, var); | |
186 | } | |
187 | ||
0566b51e DB |
188 | /* Return the variable annotation for T, which must be a _DECL node. |
189 | Return NULL if the variable annotation doesn't already exist. */ | |
6de9cd9a | 190 | static inline var_ann_t |
9566a759 | 191 | var_ann (const_tree t) |
6de9cd9a | 192 | { |
1e128c5f GB |
193 | gcc_assert (t); |
194 | gcc_assert (DECL_P (t)); | |
3bfdb124 | 195 | gcc_assert (TREE_CODE (t) != FUNCTION_DECL); |
6ac5a246 | 196 | if (!MTAG_P (t) && (TREE_STATIC (t) || DECL_EXTERNAL (t))) |
adb6509f JH |
197 | { |
198 | struct static_var_ann_d *sann | |
199 | = ((struct static_var_ann_d *) | |
200 | htab_find_with_hash (gimple_var_anns (cfun), t, DECL_UID (t))); | |
201 | if (!sann) | |
202 | return NULL; | |
2c5cfd1f | 203 | gcc_assert (sann->ann.common.type == VAR_ANN); |
adb6509f JH |
204 | return &sann->ann; |
205 | } | |
07beea0d AH |
206 | gcc_assert (!t->base.ann |
207 | || t->base.ann->common.type == VAR_ANN); | |
6de9cd9a | 208 | |
07beea0d | 209 | return (var_ann_t) t->base.ann; |
6de9cd9a DN |
210 | } |
211 | ||
0566b51e DB |
212 | /* Return the variable annotation for T, which must be a _DECL node. |
213 | Create the variable annotation if it doesn't exist. */ | |
6de9cd9a DN |
214 | static inline var_ann_t |
215 | get_var_ann (tree var) | |
216 | { | |
217 | var_ann_t ann = var_ann (var); | |
218 | return (ann) ? ann : create_var_ann (var); | |
219 | } | |
220 | ||
3bfdb124 DB |
221 | /* Return the function annotation for T, which must be a FUNCTION_DECL node. |
222 | Return NULL if the function annotation doesn't already exist. */ | |
223 | static inline function_ann_t | |
9566a759 | 224 | function_ann (const_tree t) |
3bfdb124 DB |
225 | { |
226 | gcc_assert (t); | |
227 | gcc_assert (TREE_CODE (t) == FUNCTION_DECL); | |
07beea0d AH |
228 | gcc_assert (!t->base.ann |
229 | || t->base.ann->common.type == FUNCTION_ANN); | |
3bfdb124 | 230 | |
07beea0d | 231 | return (function_ann_t) t->base.ann; |
3bfdb124 DB |
232 | } |
233 | ||
234 | /* Return the function annotation for T, which must be a FUNCTION_DECL node. | |
235 | Create the function annotation if it doesn't exist. */ | |
236 | static inline function_ann_t | |
237 | get_function_ann (tree var) | |
238 | { | |
239 | function_ann_t ann = function_ann (var); | |
07beea0d | 240 | gcc_assert (!var->base.ann || var->base.ann->common.type == FUNCTION_ANN); |
3bfdb124 DB |
241 | return (ann) ? ann : create_function_ann (var); |
242 | } | |
243 | ||
83737db2 DB |
244 | /* Return true if T has a statement annotation attached to it. */ |
245 | ||
246 | static inline bool | |
247 | has_stmt_ann (tree t) | |
248 | { | |
249 | #ifdef ENABLE_CHECKING | |
250 | gcc_assert (is_gimple_stmt (t)); | |
251 | #endif | |
07beea0d | 252 | return t->base.ann && t->base.ann->common.type == STMT_ANN; |
83737db2 DB |
253 | } |
254 | ||
0566b51e DB |
255 | /* Return the statement annotation for T, which must be a statement |
256 | node. Return NULL if the statement annotation doesn't exist. */ | |
6de9cd9a DN |
257 | static inline stmt_ann_t |
258 | stmt_ann (tree t) | |
259 | { | |
1e128c5f GB |
260 | #ifdef ENABLE_CHECKING |
261 | gcc_assert (is_gimple_stmt (t)); | |
6de9cd9a | 262 | #endif |
07beea0d AH |
263 | gcc_assert (!t->base.ann || t->base.ann->common.type == STMT_ANN); |
264 | return (stmt_ann_t) t->base.ann; | |
6de9cd9a DN |
265 | } |
266 | ||
0566b51e DB |
267 | /* Return the statement annotation for T, which must be a statement |
268 | node. Create the statement annotation if it doesn't exist. */ | |
6de9cd9a DN |
269 | static inline stmt_ann_t |
270 | get_stmt_ann (tree stmt) | |
271 | { | |
272 | stmt_ann_t ann = stmt_ann (stmt); | |
273 | return (ann) ? ann : create_stmt_ann (stmt); | |
274 | } | |
275 | ||
0566b51e | 276 | /* Return the annotation type for annotation ANN. */ |
6de9cd9a | 277 | static inline enum tree_ann_type |
06d72ee6 | 278 | ann_type (tree_ann_t ann) |
6de9cd9a DN |
279 | { |
280 | return ann->common.type; | |
281 | } | |
282 | ||
0566b51e | 283 | /* Return the basic block for statement T. */ |
6de9cd9a DN |
284 | static inline basic_block |
285 | bb_for_stmt (tree t) | |
286 | { | |
30d396e3 ZD |
287 | stmt_ann_t ann; |
288 | ||
289 | if (TREE_CODE (t) == PHI_NODE) | |
290 | return PHI_BB (t); | |
291 | ||
292 | ann = stmt_ann (t); | |
6de9cd9a DN |
293 | return ann ? ann->bb : NULL; |
294 | } | |
295 | ||
306219a2 | 296 | /* Return the may_aliases bitmap for variable VAR, or NULL if it has |
0566b51e | 297 | no may aliases. */ |
306219a2 | 298 | static inline bitmap |
9566a759 | 299 | may_aliases (const_tree var) |
6de9cd9a | 300 | { |
306219a2 | 301 | return MTAG_ALIASES (var); |
6de9cd9a DN |
302 | } |
303 | ||
0566b51e DB |
304 | /* Return the line number for EXPR, or return -1 if we have no line |
305 | number information for it. */ | |
6de9cd9a | 306 | static inline int |
ac545c64 | 307 | get_lineno (const_tree expr) |
6de9cd9a DN |
308 | { |
309 | if (expr == NULL_TREE) | |
310 | return -1; | |
311 | ||
312 | if (TREE_CODE (expr) == COMPOUND_EXPR) | |
313 | expr = TREE_OPERAND (expr, 0); | |
314 | ||
9506ac2b | 315 | if (! EXPR_HAS_LOCATION (expr)) |
6de9cd9a DN |
316 | return -1; |
317 | ||
318 | return EXPR_LINENO (expr); | |
319 | } | |
320 | ||
7ded35b4 RS |
321 | /* Return true if T is a noreturn call. */ |
322 | static inline bool | |
323 | noreturn_call_p (tree t) | |
324 | { | |
325 | tree call = get_call_expr_in (t); | |
326 | return call != 0 && (call_expr_flags (call) & ECF_NORETURN) != 0; | |
327 | } | |
328 | ||
0566b51e | 329 | /* Mark statement T as modified. */ |
6de9cd9a | 330 | static inline void |
f430bae8 | 331 | mark_stmt_modified (tree t) |
6de9cd9a | 332 | { |
f430bae8 AM |
333 | stmt_ann_t ann; |
334 | if (TREE_CODE (t) == PHI_NODE) | |
335 | return; | |
336 | ||
337 | ann = stmt_ann (t); | |
6de9cd9a DN |
338 | if (ann == NULL) |
339 | ann = create_stmt_ann (t); | |
5cd4ec7f JH |
340 | else if (noreturn_call_p (t) && cfun->gimple_df) |
341 | VEC_safe_push (tree, gc, MODIFIED_NORETURN_CALLS (cfun), t); | |
6de9cd9a DN |
342 | ann->modified = 1; |
343 | } | |
344 | ||
f430bae8 | 345 | /* Mark statement T as modified, and update it. */ |
6de9cd9a | 346 | static inline void |
f430bae8 | 347 | update_stmt (tree t) |
6de9cd9a | 348 | { |
f430bae8 AM |
349 | if (TREE_CODE (t) == PHI_NODE) |
350 | return; | |
351 | mark_stmt_modified (t); | |
352 | update_stmt_operands (t); | |
353 | } | |
354 | ||
355 | static inline void | |
356 | update_stmt_if_modified (tree t) | |
357 | { | |
358 | if (stmt_modified_p (t)) | |
359 | update_stmt_operands (t); | |
360 | } | |
361 | ||
0566b51e | 362 | /* Return true if T is marked as modified, false otherwise. */ |
6de9cd9a DN |
363 | static inline bool |
364 | stmt_modified_p (tree t) | |
365 | { | |
366 | stmt_ann_t ann = stmt_ann (t); | |
367 | ||
368 | /* Note that if the statement doesn't yet have an annotation, we consider it | |
f430bae8 AM |
369 | modified. This will force the next call to update_stmt_operands to scan |
370 | the statement. */ | |
6de9cd9a DN |
371 | return ann ? ann->modified : true; |
372 | } | |
373 | ||
f430bae8 AM |
374 | /* Delink an immediate_uses node from its chain. */ |
375 | static inline void | |
f47c96aa | 376 | delink_imm_use (ssa_use_operand_t *linknode) |
f430bae8 AM |
377 | { |
378 | /* Return if this node is not in a list. */ | |
379 | if (linknode->prev == NULL) | |
380 | return; | |
381 | ||
382 | linknode->prev->next = linknode->next; | |
383 | linknode->next->prev = linknode->prev; | |
384 | linknode->prev = NULL; | |
385 | linknode->next = NULL; | |
386 | } | |
387 | ||
388 | /* Link ssa_imm_use node LINKNODE into the chain for LIST. */ | |
389 | static inline void | |
f47c96aa | 390 | link_imm_use_to_list (ssa_use_operand_t *linknode, ssa_use_operand_t *list) |
f430bae8 AM |
391 | { |
392 | /* Link the new node at the head of the list. If we are in the process of | |
be12e697 | 393 | traversing the list, we won't visit any new nodes added to it. */ |
f430bae8 AM |
394 | linknode->prev = list; |
395 | linknode->next = list->next; | |
396 | list->next->prev = linknode; | |
397 | list->next = linknode; | |
398 | } | |
399 | ||
400 | /* Link ssa_imm_use node LINKNODE into the chain for DEF. */ | |
401 | static inline void | |
f47c96aa | 402 | link_imm_use (ssa_use_operand_t *linknode, tree def) |
f430bae8 | 403 | { |
f47c96aa | 404 | ssa_use_operand_t *root; |
f430bae8 AM |
405 | |
406 | if (!def || TREE_CODE (def) != SSA_NAME) | |
407 | linknode->prev = NULL; | |
408 | else | |
409 | { | |
410 | root = &(SSA_NAME_IMM_USE_NODE (def)); | |
411 | #ifdef ENABLE_CHECKING | |
412 | if (linknode->use) | |
413 | gcc_assert (*(linknode->use) == def); | |
414 | #endif | |
415 | link_imm_use_to_list (linknode, root); | |
416 | } | |
417 | } | |
418 | ||
206048bd | 419 | /* Set the value of a use pointed to by USE to VAL. */ |
f430bae8 AM |
420 | static inline void |
421 | set_ssa_use_from_ptr (use_operand_p use, tree val) | |
422 | { | |
423 | delink_imm_use (use); | |
424 | *(use->use) = val; | |
425 | link_imm_use (use, val); | |
426 | } | |
427 | ||
0fa2e4df | 428 | /* Link ssa_imm_use node LINKNODE into the chain for DEF, with use occurring |
f430bae8 AM |
429 | in STMT. */ |
430 | static inline void | |
f47c96aa | 431 | link_imm_use_stmt (ssa_use_operand_t *linknode, tree def, tree stmt) |
f430bae8 AM |
432 | { |
433 | if (stmt) | |
434 | link_imm_use (linknode, def); | |
435 | else | |
436 | link_imm_use (linknode, NULL); | |
437 | linknode->stmt = stmt; | |
438 | } | |
439 | ||
440 | /* Relink a new node in place of an old node in the list. */ | |
441 | static inline void | |
f47c96aa | 442 | relink_imm_use (ssa_use_operand_t *node, ssa_use_operand_t *old) |
f430bae8 | 443 | { |
f430bae8 | 444 | /* The node one had better be in the same list. */ |
0e61db61 | 445 | gcc_assert (*(old->use) == *(node->use)); |
f430bae8 AM |
446 | node->prev = old->prev; |
447 | node->next = old->next; | |
448 | if (old->prev) | |
449 | { | |
450 | old->prev->next = node; | |
451 | old->next->prev = node; | |
452 | /* Remove the old node from the list. */ | |
453 | old->prev = NULL; | |
454 | } | |
f430bae8 AM |
455 | } |
456 | ||
0fa2e4df | 457 | /* Relink ssa_imm_use node LINKNODE into the chain for OLD, with use occurring |
f430bae8 AM |
458 | in STMT. */ |
459 | static inline void | |
f47c96aa | 460 | relink_imm_use_stmt (ssa_use_operand_t *linknode, ssa_use_operand_t *old, tree stmt) |
f430bae8 AM |
461 | { |
462 | if (stmt) | |
463 | relink_imm_use (linknode, old); | |
464 | else | |
465 | link_imm_use (linknode, NULL); | |
466 | linknode->stmt = stmt; | |
467 | } | |
468 | ||
f430bae8 | 469 | |
f652d14b | 470 | /* Return true is IMM has reached the end of the immediate use list. */ |
f430bae8 | 471 | static inline bool |
9566a759 | 472 | end_readonly_imm_use_p (const imm_use_iterator *imm) |
f430bae8 AM |
473 | { |
474 | return (imm->imm_use == imm->end_p); | |
475 | } | |
476 | ||
477 | /* Initialize iterator IMM to process the list for VAR. */ | |
478 | static inline use_operand_p | |
479 | first_readonly_imm_use (imm_use_iterator *imm, tree var) | |
480 | { | |
481 | gcc_assert (TREE_CODE (var) == SSA_NAME); | |
482 | ||
483 | imm->end_p = &(SSA_NAME_IMM_USE_NODE (var)); | |
484 | imm->imm_use = imm->end_p->next; | |
485 | #ifdef ENABLE_CHECKING | |
486 | imm->iter_node.next = imm->imm_use->next; | |
487 | #endif | |
488 | if (end_readonly_imm_use_p (imm)) | |
489 | return NULL_USE_OPERAND_P; | |
490 | return imm->imm_use; | |
491 | } | |
492 | ||
d566f6ef | 493 | /* Bump IMM to the next use in the list. */ |
f430bae8 AM |
494 | static inline use_operand_p |
495 | next_readonly_imm_use (imm_use_iterator *imm) | |
496 | { | |
497 | use_operand_p old = imm->imm_use; | |
498 | ||
499 | #ifdef ENABLE_CHECKING | |
dc377e87 BF |
500 | /* If this assertion fails, it indicates the 'next' pointer has changed |
501 | since the last bump. This indicates that the list is being modified | |
f430bae8 AM |
502 | via stmt changes, or SET_USE, or somesuch thing, and you need to be |
503 | using the SAFE version of the iterator. */ | |
504 | gcc_assert (imm->iter_node.next == old->next); | |
505 | imm->iter_node.next = old->next->next; | |
506 | #endif | |
507 | ||
508 | imm->imm_use = old->next; | |
509 | if (end_readonly_imm_use_p (imm)) | |
510 | return old; | |
511 | return imm->imm_use; | |
512 | } | |
513 | ||
514 | /* Return true if VAR has no uses. */ | |
515 | static inline bool | |
9566a759 | 516 | has_zero_uses (const_tree var) |
f430bae8 | 517 | { |
9566a759 | 518 | const ssa_use_operand_t *const ptr = &(SSA_NAME_IMM_USE_NODE (var)); |
f430bae8 AM |
519 | /* A single use means there is no items in the list. */ |
520 | return (ptr == ptr->next); | |
521 | } | |
522 | ||
523 | /* Return true if VAR has a single use. */ | |
524 | static inline bool | |
9566a759 | 525 | has_single_use (const_tree var) |
f430bae8 | 526 | { |
9566a759 | 527 | const ssa_use_operand_t *const ptr = &(SSA_NAME_IMM_USE_NODE (var)); |
f430bae8 AM |
528 | /* A single use means there is one item in the list. */ |
529 | return (ptr != ptr->next && ptr == ptr->next->next); | |
530 | } | |
531 | ||
7290d709 | 532 | |
f430bae8 | 533 | /* If VAR has only a single immediate use, return true, and set USE_P and STMT |
f652d14b | 534 | to the use pointer and stmt of occurrence. */ |
f430bae8 | 535 | static inline bool |
9566a759 | 536 | single_imm_use (const_tree var, use_operand_p *use_p, tree *stmt) |
f430bae8 | 537 | { |
9566a759 | 538 | const ssa_use_operand_t *const ptr = &(SSA_NAME_IMM_USE_NODE (var)); |
f430bae8 AM |
539 | if (ptr != ptr->next && ptr == ptr->next->next) |
540 | { | |
541 | *use_p = ptr->next; | |
542 | *stmt = ptr->next->stmt; | |
543 | return true; | |
544 | } | |
545 | *use_p = NULL_USE_OPERAND_P; | |
546 | *stmt = NULL_TREE; | |
547 | return false; | |
548 | } | |
549 | ||
550 | /* Return the number of immediate uses of VAR. */ | |
551 | static inline unsigned int | |
9566a759 | 552 | num_imm_uses (const_tree var) |
f430bae8 | 553 | { |
9566a759 KG |
554 | const ssa_use_operand_t *const start = &(SSA_NAME_IMM_USE_NODE (var)); |
555 | const ssa_use_operand_t *ptr; | |
556 | unsigned int num = 0; | |
f430bae8 | 557 | |
f430bae8 AM |
558 | for (ptr = start->next; ptr != start; ptr = ptr->next) |
559 | num++; | |
560 | ||
561 | return num; | |
562 | } | |
563 | ||
d00ad49b AM |
564 | /* Return the tree pointer to by USE. */ |
565 | static inline tree | |
566 | get_use_from_ptr (use_operand_p use) | |
567 | { | |
f430bae8 | 568 | return *(use->use); |
d00ad49b AM |
569 | } |
570 | ||
571 | /* Return the tree pointer to by DEF. */ | |
572 | static inline tree | |
573 | get_def_from_ptr (def_operand_p def) | |
574 | { | |
f47c96aa | 575 | return *def; |
d00ad49b AM |
576 | } |
577 | ||
578 | /* Return a def_operand_p pointer for the result of PHI. */ | |
579 | static inline def_operand_p | |
580 | get_phi_result_ptr (tree phi) | |
581 | { | |
f47c96aa | 582 | return &(PHI_RESULT_TREE (phi)); |
a32b97a2 BB |
583 | } |
584 | ||
d00ad49b AM |
585 | /* Return a use_operand_p pointer for argument I of phinode PHI. */ |
586 | static inline use_operand_p | |
587 | get_phi_arg_def_ptr (tree phi, int i) | |
588 | { | |
f430bae8 | 589 | return &(PHI_ARG_IMM_USE_NODE (phi,i)); |
6de9cd9a DN |
590 | } |
591 | ||
e54d0214 | 592 | |
f430bae8 AM |
593 | /* Return the bitmap of addresses taken by STMT, or NULL if it takes |
594 | no addresses. */ | |
595 | static inline bitmap | |
596 | addresses_taken (tree stmt) | |
597 | { | |
598 | stmt_ann_t ann = stmt_ann (stmt); | |
599 | return ann ? ann->addresses_taken : NULL; | |
6de9cd9a DN |
600 | } |
601 | ||
0566b51e DB |
602 | /* Return the PHI nodes for basic block BB, or NULL if there are no |
603 | PHI nodes. */ | |
6de9cd9a | 604 | static inline tree |
9678086d | 605 | phi_nodes (const_basic_block bb) |
6de9cd9a | 606 | { |
7506e1cb ZD |
607 | gcc_assert (!(bb->flags & BB_RTL)); |
608 | if (!bb->il.tree) | |
609 | return NULL; | |
610 | return bb->il.tree->phi_nodes; | |
611 | } | |
612 | ||
613 | /* Return pointer to the list of PHI nodes for basic block BB. */ | |
614 | ||
615 | static inline tree * | |
616 | phi_nodes_ptr (basic_block bb) | |
617 | { | |
618 | gcc_assert (!(bb->flags & BB_RTL)); | |
619 | return &bb->il.tree->phi_nodes; | |
6de9cd9a DN |
620 | } |
621 | ||
622 | /* Set list of phi nodes of a basic block BB to L. */ | |
623 | ||
624 | static inline void | |
625 | set_phi_nodes (basic_block bb, tree l) | |
626 | { | |
627 | tree phi; | |
628 | ||
7506e1cb ZD |
629 | gcc_assert (!(bb->flags & BB_RTL)); |
630 | bb->il.tree->phi_nodes = l; | |
17192884 | 631 | for (phi = l; phi; phi = PHI_CHAIN (phi)) |
6de9cd9a DN |
632 | set_bb_for_stmt (phi, bb); |
633 | } | |
634 | ||
f430bae8 AM |
635 | /* Return the phi argument which contains the specified use. */ |
636 | ||
637 | static inline int | |
638 | phi_arg_index_from_use (use_operand_p use) | |
639 | { | |
640 | struct phi_arg_d *element, *root; | |
641 | int index; | |
642 | tree phi; | |
643 | ||
f652d14b | 644 | /* Since the use is the first thing in a PHI argument element, we can |
f430bae8 AM |
645 | calculate its index based on casting it to an argument, and performing |
646 | pointer arithmetic. */ | |
647 | ||
648 | phi = USE_STMT (use); | |
649 | gcc_assert (TREE_CODE (phi) == PHI_NODE); | |
650 | ||
651 | element = (struct phi_arg_d *)use; | |
652 | root = &(PHI_ARG_ELT (phi, 0)); | |
653 | index = element - root; | |
654 | ||
655 | #ifdef ENABLE_CHECKING | |
656 | /* Make sure the calculation doesn't have any leftover bytes. If it does, | |
f652d14b | 657 | then imm_use is likely not the first element in phi_arg_d. */ |
f430bae8 AM |
658 | gcc_assert ( |
659 | (((char *)element - (char *)root) % sizeof (struct phi_arg_d)) == 0); | |
660 | gcc_assert (index >= 0 && index < PHI_ARG_CAPACITY (phi)); | |
661 | #endif | |
662 | ||
663 | return index; | |
664 | } | |
665 | ||
727a31fa RH |
666 | /* Mark VAR as used, so that it'll be preserved during rtl expansion. */ |
667 | ||
668 | static inline void | |
669 | set_is_used (tree var) | |
670 | { | |
671 | var_ann_t ann = get_var_ann (var); | |
672 | ann->used = 1; | |
673 | } | |
674 | ||
6de9cd9a | 675 | |
1c2e50d8 RG |
676 | /* Return true if T (assumed to be a DECL) is a global variable. */ |
677 | ||
678 | static inline bool | |
9566a759 | 679 | is_global_var (const_tree t) |
1c2e50d8 RG |
680 | { |
681 | if (MTAG_P (t)) | |
682 | return (TREE_STATIC (t) || MTAG_GLOBAL (t)); | |
683 | else | |
684 | return (TREE_STATIC (t) || DECL_EXTERNAL (t)); | |
685 | } | |
686 | ||
6de9cd9a DN |
687 | /* PHI nodes should contain only ssa_names and invariants. A test |
688 | for ssa_name is definitely simpler; don't let invalid contents | |
689 | slip in in the meantime. */ | |
690 | ||
691 | static inline bool | |
9566a759 | 692 | phi_ssa_name_p (const_tree t) |
6de9cd9a DN |
693 | { |
694 | if (TREE_CODE (t) == SSA_NAME) | |
695 | return true; | |
696 | #ifdef ENABLE_CHECKING | |
1e128c5f | 697 | gcc_assert (is_gimple_min_invariant (t)); |
6de9cd9a DN |
698 | #endif |
699 | return false; | |
700 | } | |
701 | ||
702 | /* ----------------------------------------------------------------------- */ | |
703 | ||
7506e1cb ZD |
704 | /* Returns the list of statements in BB. */ |
705 | ||
706 | static inline tree | |
22ea9ec0 | 707 | bb_stmt_list (const_basic_block bb) |
7506e1cb ZD |
708 | { |
709 | gcc_assert (!(bb->flags & BB_RTL)); | |
710 | return bb->il.tree->stmt_list; | |
711 | } | |
712 | ||
713 | /* Sets the list of statements in BB to LIST. */ | |
714 | ||
715 | static inline void | |
716 | set_bb_stmt_list (basic_block bb, tree list) | |
717 | { | |
718 | gcc_assert (!(bb->flags & BB_RTL)); | |
719 | bb->il.tree->stmt_list = list; | |
720 | } | |
721 | ||
0566b51e DB |
722 | /* Return a block_stmt_iterator that points to beginning of basic |
723 | block BB. */ | |
6de9cd9a DN |
724 | static inline block_stmt_iterator |
725 | bsi_start (basic_block bb) | |
726 | { | |
727 | block_stmt_iterator bsi; | |
7506e1cb | 728 | if (bb->index < NUM_FIXED_BLOCKS) |
6de9cd9a | 729 | { |
6de9cd9a DN |
730 | bsi.tsi.ptr = NULL; |
731 | bsi.tsi.container = NULL; | |
732 | } | |
7506e1cb ZD |
733 | else |
734 | bsi.tsi = tsi_start (bb_stmt_list (bb)); | |
6de9cd9a DN |
735 | bsi.bb = bb; |
736 | return bsi; | |
737 | } | |
738 | ||
93954fcc | 739 | /* Return a block statement iterator that points to the first non-label |
35771d34 | 740 | statement in block BB. */ |
d7621d3c ZD |
741 | |
742 | static inline block_stmt_iterator | |
743 | bsi_after_labels (basic_block bb) | |
744 | { | |
35771d34 | 745 | block_stmt_iterator bsi = bsi_start (bb); |
d7621d3c | 746 | |
35771d34 PB |
747 | while (!bsi_end_p (bsi) && TREE_CODE (bsi_stmt (bsi)) == LABEL_EXPR) |
748 | bsi_next (&bsi); | |
d7621d3c ZD |
749 | |
750 | return bsi; | |
751 | } | |
752 | ||
0566b51e DB |
753 | /* Return a block statement iterator that points to the end of basic |
754 | block BB. */ | |
6de9cd9a DN |
755 | static inline block_stmt_iterator |
756 | bsi_last (basic_block bb) | |
757 | { | |
758 | block_stmt_iterator bsi; | |
7506e1cb ZD |
759 | |
760 | if (bb->index < NUM_FIXED_BLOCKS) | |
6de9cd9a | 761 | { |
6de9cd9a DN |
762 | bsi.tsi.ptr = NULL; |
763 | bsi.tsi.container = NULL; | |
764 | } | |
7506e1cb ZD |
765 | else |
766 | bsi.tsi = tsi_last (bb_stmt_list (bb)); | |
6de9cd9a DN |
767 | bsi.bb = bb; |
768 | return bsi; | |
769 | } | |
770 | ||
0566b51e DB |
771 | /* Return true if block statement iterator I has reached the end of |
772 | the basic block. */ | |
6de9cd9a DN |
773 | static inline bool |
774 | bsi_end_p (block_stmt_iterator i) | |
775 | { | |
776 | return tsi_end_p (i.tsi); | |
777 | } | |
778 | ||
0566b51e DB |
779 | /* Modify block statement iterator I so that it is at the next |
780 | statement in the basic block. */ | |
6de9cd9a DN |
781 | static inline void |
782 | bsi_next (block_stmt_iterator *i) | |
783 | { | |
784 | tsi_next (&i->tsi); | |
785 | } | |
786 | ||
0566b51e DB |
787 | /* Modify block statement iterator I so that it is at the previous |
788 | statement in the basic block. */ | |
6de9cd9a DN |
789 | static inline void |
790 | bsi_prev (block_stmt_iterator *i) | |
791 | { | |
792 | tsi_prev (&i->tsi); | |
793 | } | |
794 | ||
0566b51e DB |
795 | /* Return the statement that block statement iterator I is currently |
796 | at. */ | |
6de9cd9a DN |
797 | static inline tree |
798 | bsi_stmt (block_stmt_iterator i) | |
799 | { | |
800 | return tsi_stmt (i.tsi); | |
801 | } | |
802 | ||
0566b51e DB |
803 | /* Return a pointer to the statement that block statement iterator I |
804 | is currently at. */ | |
6de9cd9a DN |
805 | static inline tree * |
806 | bsi_stmt_ptr (block_stmt_iterator i) | |
807 | { | |
808 | return tsi_stmt_ptr (i.tsi); | |
809 | } | |
810 | ||
9baba81b SP |
811 | /* Returns the loop of the statement STMT. */ |
812 | ||
813 | static inline struct loop * | |
814 | loop_containing_stmt (tree stmt) | |
815 | { | |
816 | basic_block bb = bb_for_stmt (stmt); | |
817 | if (!bb) | |
818 | return NULL; | |
819 | ||
820 | return bb->loop_father; | |
821 | } | |
822 | ||
38635499 DN |
823 | |
824 | /* Return the memory partition tag associated with symbol SYM. */ | |
825 | ||
826 | static inline tree | |
827 | memory_partition (tree sym) | |
828 | { | |
829 | tree tag; | |
830 | ||
831 | /* MPTs belong to their own partition. */ | |
832 | if (TREE_CODE (sym) == MEMORY_PARTITION_TAG) | |
833 | return sym; | |
834 | ||
835 | gcc_assert (!is_gimple_reg (sym)); | |
836 | tag = get_var_ann (sym)->mpt; | |
837 | ||
838 | #if defined ENABLE_CHECKING | |
839 | if (tag) | |
840 | gcc_assert (TREE_CODE (tag) == MEMORY_PARTITION_TAG); | |
841 | #endif | |
842 | ||
843 | return tag; | |
844 | } | |
845 | ||
38635499 DN |
846 | /* Return true if NAME is a memory factoring SSA name (i.e., an SSA |
847 | name for a memory partition. */ | |
848 | ||
849 | static inline bool | |
9566a759 | 850 | factoring_name_p (const_tree name) |
38635499 DN |
851 | { |
852 | return TREE_CODE (SSA_NAME_VAR (name)) == MEMORY_PARTITION_TAG; | |
853 | } | |
854 | ||
0566b51e | 855 | /* Return true if VAR is a clobbered by function calls. */ |
6de9cd9a | 856 | static inline bool |
9566a759 | 857 | is_call_clobbered (const_tree var) |
6de9cd9a | 858 | { |
fe1f8f44 | 859 | if (!MTAG_P (var)) |
b730fa61 | 860 | return var_ann (var)->call_clobbered; |
fe1f8f44 | 861 | else |
5cd4ec7f | 862 | return bitmap_bit_p (gimple_call_clobbered_vars (cfun), DECL_UID (var)); |
6de9cd9a DN |
863 | } |
864 | ||
0566b51e | 865 | /* Mark variable VAR as being clobbered by function calls. */ |
6de9cd9a | 866 | static inline void |
d16a5e36 | 867 | mark_call_clobbered (tree var, unsigned int escape_type) |
6de9cd9a | 868 | { |
d16a5e36 | 869 | var_ann (var)->escape_mask |= escape_type; |
fe1f8f44 | 870 | if (!MTAG_P (var)) |
b730fa61 | 871 | var_ann (var)->call_clobbered = true; |
5cd4ec7f | 872 | bitmap_set_bit (gimple_call_clobbered_vars (cfun), DECL_UID (var)); |
6de9cd9a DN |
873 | } |
874 | ||
90e34bd6 DN |
875 | /* Clear the call-clobbered attribute from variable VAR. */ |
876 | static inline void | |
877 | clear_call_clobbered (tree var) | |
878 | { | |
d16a5e36 DB |
879 | var_ann_t ann = var_ann (var); |
880 | ann->escape_mask = 0; | |
326eda4b DB |
881 | if (MTAG_P (var) && TREE_CODE (var) != STRUCT_FIELD_TAG) |
882 | MTAG_GLOBAL (var) = 0; | |
fe1f8f44 | 883 | if (!MTAG_P (var)) |
b730fa61 | 884 | var_ann (var)->call_clobbered = false; |
5cd4ec7f | 885 | bitmap_clear_bit (gimple_call_clobbered_vars (cfun), DECL_UID (var)); |
90e34bd6 DN |
886 | } |
887 | ||
06d72ee6 DB |
888 | /* Return the common annotation for T. Return NULL if the annotation |
889 | doesn't already exist. */ | |
93c094b5 | 890 | static inline tree_ann_common_t |
9566a759 | 891 | tree_common_ann (const_tree t) |
06d72ee6 | 892 | { |
6ac5a246 JH |
893 | /* Watch out static variables with unshared annotations. */ |
894 | if (DECL_P (t) && TREE_CODE (t) == VAR_DECL) | |
895 | return &var_ann (t)->common; | |
07beea0d | 896 | return &t->base.ann->common; |
06d72ee6 DB |
897 | } |
898 | ||
899 | /* Return a common annotation for T. Create the constant annotation if it | |
900 | doesn't exist. */ | |
93c094b5 JH |
901 | static inline tree_ann_common_t |
902 | get_tree_common_ann (tree t) | |
06d72ee6 | 903 | { |
93c094b5 JH |
904 | tree_ann_common_t ann = tree_common_ann (t); |
905 | return (ann) ? ann : create_tree_common_ann (t); | |
06d72ee6 DB |
906 | } |
907 | ||
4c124b4c AM |
908 | /* ----------------------------------------------------------------------- */ |
909 | ||
910 | /* The following set of routines are used to iterator over various type of | |
911 | SSA operands. */ | |
912 | ||
913 | /* Return true if PTR is finished iterating. */ | |
914 | static inline bool | |
9566a759 | 915 | op_iter_done (const ssa_op_iter *ptr) |
4c124b4c AM |
916 | { |
917 | return ptr->done; | |
918 | } | |
919 | ||
920 | /* Get the next iterator use value for PTR. */ | |
921 | static inline use_operand_p | |
922 | op_iter_next_use (ssa_op_iter *ptr) | |
923 | { | |
f47c96aa AM |
924 | use_operand_p use_p; |
925 | #ifdef ENABLE_CHECKING | |
926 | gcc_assert (ptr->iter_type == ssa_op_iter_use); | |
927 | #endif | |
928 | if (ptr->uses) | |
4c124b4c | 929 | { |
f47c96aa AM |
930 | use_p = USE_OP_PTR (ptr->uses); |
931 | ptr->uses = ptr->uses->next; | |
932 | return use_p; | |
4c124b4c | 933 | } |
f47c96aa | 934 | if (ptr->vuses) |
4c124b4c | 935 | { |
38635499 DN |
936 | use_p = VUSE_OP_PTR (ptr->vuses, ptr->vuse_index); |
937 | if (++(ptr->vuse_index) >= VUSE_NUM (ptr->vuses)) | |
938 | { | |
939 | ptr->vuse_index = 0; | |
940 | ptr->vuses = ptr->vuses->next; | |
941 | } | |
f47c96aa | 942 | return use_p; |
4c124b4c | 943 | } |
f47c96aa | 944 | if (ptr->mayuses) |
4c124b4c | 945 | { |
38635499 DN |
946 | use_p = VDEF_OP_PTR (ptr->mayuses, ptr->mayuse_index); |
947 | if (++(ptr->mayuse_index) >= VDEF_NUM (ptr->mayuses)) | |
948 | { | |
949 | ptr->mayuse_index = 0; | |
950 | ptr->mayuses = ptr->mayuses->next; | |
951 | } | |
f47c96aa AM |
952 | return use_p; |
953 | } | |
954 | if (ptr->phi_i < ptr->num_phi) | |
955 | { | |
956 | return PHI_ARG_DEF_PTR (ptr->phi_stmt, (ptr->phi_i)++); | |
4c124b4c AM |
957 | } |
958 | ptr->done = true; | |
959 | return NULL_USE_OPERAND_P; | |
960 | } | |
961 | ||
962 | /* Get the next iterator def value for PTR. */ | |
963 | static inline def_operand_p | |
964 | op_iter_next_def (ssa_op_iter *ptr) | |
965 | { | |
f47c96aa AM |
966 | def_operand_p def_p; |
967 | #ifdef ENABLE_CHECKING | |
968 | gcc_assert (ptr->iter_type == ssa_op_iter_def); | |
969 | #endif | |
970 | if (ptr->defs) | |
4c124b4c | 971 | { |
f47c96aa AM |
972 | def_p = DEF_OP_PTR (ptr->defs); |
973 | ptr->defs = ptr->defs->next; | |
974 | return def_p; | |
4c124b4c | 975 | } |
38635499 | 976 | if (ptr->vdefs) |
4c124b4c | 977 | { |
38635499 DN |
978 | def_p = VDEF_RESULT_PTR (ptr->vdefs); |
979 | ptr->vdefs = ptr->vdefs->next; | |
f47c96aa | 980 | return def_p; |
4c124b4c AM |
981 | } |
982 | ptr->done = true; | |
983 | return NULL_DEF_OPERAND_P; | |
984 | } | |
985 | ||
986 | /* Get the next iterator tree value for PTR. */ | |
987 | static inline tree | |
988 | op_iter_next_tree (ssa_op_iter *ptr) | |
989 | { | |
f47c96aa AM |
990 | tree val; |
991 | #ifdef ENABLE_CHECKING | |
992 | gcc_assert (ptr->iter_type == ssa_op_iter_tree); | |
993 | #endif | |
994 | if (ptr->uses) | |
4c124b4c | 995 | { |
f47c96aa AM |
996 | val = USE_OP (ptr->uses); |
997 | ptr->uses = ptr->uses->next; | |
998 | return val; | |
4c124b4c | 999 | } |
f47c96aa | 1000 | if (ptr->vuses) |
4c124b4c | 1001 | { |
38635499 DN |
1002 | val = VUSE_OP (ptr->vuses, ptr->vuse_index); |
1003 | if (++(ptr->vuse_index) >= VUSE_NUM (ptr->vuses)) | |
1004 | { | |
1005 | ptr->vuse_index = 0; | |
1006 | ptr->vuses = ptr->vuses->next; | |
1007 | } | |
f47c96aa | 1008 | return val; |
4c124b4c | 1009 | } |
f47c96aa | 1010 | if (ptr->mayuses) |
4c124b4c | 1011 | { |
38635499 DN |
1012 | val = VDEF_OP (ptr->mayuses, ptr->mayuse_index); |
1013 | if (++(ptr->mayuse_index) >= VDEF_NUM (ptr->mayuses)) | |
1014 | { | |
1015 | ptr->mayuse_index = 0; | |
1016 | ptr->mayuses = ptr->mayuses->next; | |
1017 | } | |
f47c96aa | 1018 | return val; |
52328bf6 | 1019 | } |
f47c96aa | 1020 | if (ptr->defs) |
4c124b4c | 1021 | { |
f47c96aa AM |
1022 | val = DEF_OP (ptr->defs); |
1023 | ptr->defs = ptr->defs->next; | |
1024 | return val; | |
4c124b4c | 1025 | } |
38635499 | 1026 | if (ptr->vdefs) |
4c124b4c | 1027 | { |
38635499 DN |
1028 | val = VDEF_RESULT (ptr->vdefs); |
1029 | ptr->vdefs = ptr->vdefs->next; | |
f47c96aa | 1030 | return val; |
4c124b4c | 1031 | } |
f47c96aa AM |
1032 | |
1033 | ptr->done = true; | |
1034 | return NULL_TREE; | |
1035 | ||
1036 | } | |
1037 | ||
1038 | ||
395bda42 | 1039 | /* This functions clears the iterator PTR, and marks it done. This is normally |
c83eecad | 1040 | used to prevent warnings in the compile about might be uninitialized |
f47c96aa AM |
1041 | components. */ |
1042 | ||
1043 | static inline void | |
1044 | clear_and_done_ssa_iter (ssa_op_iter *ptr) | |
1045 | { | |
1046 | ptr->defs = NULL; | |
1047 | ptr->uses = NULL; | |
1048 | ptr->vuses = NULL; | |
38635499 | 1049 | ptr->vdefs = NULL; |
f47c96aa | 1050 | ptr->mayuses = NULL; |
f47c96aa AM |
1051 | ptr->iter_type = ssa_op_iter_none; |
1052 | ptr->phi_i = 0; | |
1053 | ptr->num_phi = 0; | |
1054 | ptr->phi_stmt = NULL_TREE; | |
4c124b4c | 1055 | ptr->done = true; |
38635499 DN |
1056 | ptr->vuse_index = 0; |
1057 | ptr->mayuse_index = 0; | |
4c124b4c AM |
1058 | } |
1059 | ||
1060 | /* Initialize the iterator PTR to the virtual defs in STMT. */ | |
1061 | static inline void | |
1062 | op_iter_init (ssa_op_iter *ptr, tree stmt, int flags) | |
1063 | { | |
f47c96aa AM |
1064 | #ifdef ENABLE_CHECKING |
1065 | gcc_assert (stmt_ann (stmt)); | |
1066 | #endif | |
4c124b4c | 1067 | |
f47c96aa AM |
1068 | ptr->defs = (flags & SSA_OP_DEF) ? DEF_OPS (stmt) : NULL; |
1069 | ptr->uses = (flags & SSA_OP_USE) ? USE_OPS (stmt) : NULL; | |
1070 | ptr->vuses = (flags & SSA_OP_VUSE) ? VUSE_OPS (stmt) : NULL; | |
38635499 DN |
1071 | ptr->vdefs = (flags & SSA_OP_VDEF) ? VDEF_OPS (stmt) : NULL; |
1072 | ptr->mayuses = (flags & SSA_OP_VMAYUSE) ? VDEF_OPS (stmt) : NULL; | |
4c124b4c | 1073 | ptr->done = false; |
f47c96aa AM |
1074 | |
1075 | ptr->phi_i = 0; | |
1076 | ptr->num_phi = 0; | |
1077 | ptr->phi_stmt = NULL_TREE; | |
38635499 DN |
1078 | ptr->vuse_index = 0; |
1079 | ptr->mayuse_index = 0; | |
4c124b4c AM |
1080 | } |
1081 | ||
1082 | /* Initialize iterator PTR to the use operands in STMT based on FLAGS. Return | |
1083 | the first use. */ | |
1084 | static inline use_operand_p | |
1085 | op_iter_init_use (ssa_op_iter *ptr, tree stmt, int flags) | |
1086 | { | |
66d3fe47 | 1087 | gcc_assert ((flags & SSA_OP_ALL_DEFS) == 0); |
4c124b4c | 1088 | op_iter_init (ptr, stmt, flags); |
f47c96aa | 1089 | ptr->iter_type = ssa_op_iter_use; |
4c124b4c AM |
1090 | return op_iter_next_use (ptr); |
1091 | } | |
1092 | ||
1093 | /* Initialize iterator PTR to the def operands in STMT based on FLAGS. Return | |
1094 | the first def. */ | |
1095 | static inline def_operand_p | |
1096 | op_iter_init_def (ssa_op_iter *ptr, tree stmt, int flags) | |
1097 | { | |
38635499 | 1098 | gcc_assert ((flags & SSA_OP_ALL_USES) == 0); |
4c124b4c | 1099 | op_iter_init (ptr, stmt, flags); |
f47c96aa | 1100 | ptr->iter_type = ssa_op_iter_def; |
4c124b4c AM |
1101 | return op_iter_next_def (ptr); |
1102 | } | |
1103 | ||
1104 | /* Initialize iterator PTR to the operands in STMT based on FLAGS. Return | |
1105 | the first operand as a tree. */ | |
1106 | static inline tree | |
1107 | op_iter_init_tree (ssa_op_iter *ptr, tree stmt, int flags) | |
1108 | { | |
1109 | op_iter_init (ptr, stmt, flags); | |
f47c96aa | 1110 | ptr->iter_type = ssa_op_iter_tree; |
4c124b4c AM |
1111 | return op_iter_next_tree (ptr); |
1112 | } | |
1113 | ||
52328bf6 DB |
1114 | /* Get the next iterator mustdef value for PTR, returning the mustdef values in |
1115 | KILL and DEF. */ | |
1116 | static inline void | |
38635499 | 1117 | op_iter_next_vdef (vuse_vec_p *use, def_operand_p *def, |
f47c96aa | 1118 | ssa_op_iter *ptr) |
52328bf6 | 1119 | { |
f47c96aa | 1120 | #ifdef ENABLE_CHECKING |
38635499 | 1121 | gcc_assert (ptr->iter_type == ssa_op_iter_vdef); |
f47c96aa AM |
1122 | #endif |
1123 | if (ptr->mayuses) | |
52328bf6 | 1124 | { |
38635499 DN |
1125 | *def = VDEF_RESULT_PTR (ptr->mayuses); |
1126 | *use = VDEF_VECT (ptr->mayuses); | |
f47c96aa | 1127 | ptr->mayuses = ptr->mayuses->next; |
52328bf6 DB |
1128 | return; |
1129 | } | |
db30731a | 1130 | |
f47c96aa | 1131 | *def = NULL_DEF_OPERAND_P; |
38635499 | 1132 | *use = NULL; |
db30731a JL |
1133 | ptr->done = true; |
1134 | return; | |
1135 | } | |
1136 | ||
f47c96aa | 1137 | |
4c124b4c | 1138 | static inline void |
38635499 DN |
1139 | op_iter_next_mustdef (use_operand_p *use, def_operand_p *def, |
1140 | ssa_op_iter *ptr) | |
4c124b4c | 1141 | { |
38635499 DN |
1142 | vuse_vec_p vp; |
1143 | op_iter_next_vdef (&vp, def, ptr); | |
1144 | if (vp != NULL) | |
1145 | { | |
1146 | gcc_assert (VUSE_VECT_NUM_ELEM (*vp) == 1); | |
1147 | *use = VUSE_ELEMENT_PTR (*vp, 0); | |
1148 | } | |
1149 | else | |
1150 | *use = NULL_USE_OPERAND_P; | |
4c124b4c | 1151 | } |
52328bf6 DB |
1152 | |
1153 | /* Initialize iterator PTR to the operands in STMT. Return the first operands | |
38635499 | 1154 | in USE and DEF. */ |
52328bf6 | 1155 | static inline void |
38635499 | 1156 | op_iter_init_vdef (ssa_op_iter *ptr, tree stmt, vuse_vec_p *use, |
52328bf6 DB |
1157 | def_operand_p *def) |
1158 | { | |
f47c96aa AM |
1159 | gcc_assert (TREE_CODE (stmt) != PHI_NODE); |
1160 | ||
38635499 DN |
1161 | op_iter_init (ptr, stmt, SSA_OP_VMAYUSE); |
1162 | ptr->iter_type = ssa_op_iter_vdef; | |
1163 | op_iter_next_vdef (use, def, ptr); | |
f47c96aa AM |
1164 | } |
1165 | ||
1166 | ||
395bda42 | 1167 | /* If there is a single operand in STMT matching FLAGS, return it. Otherwise |
d7770457 | 1168 | return NULL. */ |
f47c96aa AM |
1169 | static inline tree |
1170 | single_ssa_tree_operand (tree stmt, int flags) | |
1171 | { | |
1172 | tree var; | |
1173 | ssa_op_iter iter; | |
1174 | ||
1175 | var = op_iter_init_tree (&iter, stmt, flags); | |
1176 | if (op_iter_done (&iter)) | |
1177 | return NULL_TREE; | |
1178 | op_iter_next_tree (&iter); | |
1179 | if (op_iter_done (&iter)) | |
1180 | return var; | |
1181 | return NULL_TREE; | |
1182 | } | |
1183 | ||
1184 | ||
395bda42 | 1185 | /* If there is a single operand in STMT matching FLAGS, return it. Otherwise |
d7770457 | 1186 | return NULL. */ |
f47c96aa AM |
1187 | static inline use_operand_p |
1188 | single_ssa_use_operand (tree stmt, int flags) | |
1189 | { | |
1190 | use_operand_p var; | |
1191 | ssa_op_iter iter; | |
1192 | ||
1193 | var = op_iter_init_use (&iter, stmt, flags); | |
1194 | if (op_iter_done (&iter)) | |
1195 | return NULL_USE_OPERAND_P; | |
1196 | op_iter_next_use (&iter); | |
1197 | if (op_iter_done (&iter)) | |
1198 | return var; | |
1199 | return NULL_USE_OPERAND_P; | |
1200 | } | |
1201 | ||
1202 | ||
1203 | ||
395bda42 | 1204 | /* If there is a single operand in STMT matching FLAGS, return it. Otherwise |
d7770457 | 1205 | return NULL. */ |
f47c96aa AM |
1206 | static inline def_operand_p |
1207 | single_ssa_def_operand (tree stmt, int flags) | |
1208 | { | |
1209 | def_operand_p var; | |
1210 | ssa_op_iter iter; | |
1211 | ||
1212 | var = op_iter_init_def (&iter, stmt, flags); | |
1213 | if (op_iter_done (&iter)) | |
1214 | return NULL_DEF_OPERAND_P; | |
1215 | op_iter_next_def (&iter); | |
1216 | if (op_iter_done (&iter)) | |
1217 | return var; | |
1218 | return NULL_DEF_OPERAND_P; | |
1219 | } | |
1220 | ||
1221 | ||
e1bb14ca DB |
1222 | /* Return true if there are zero operands in STMT matching the type |
1223 | given in FLAGS. */ | |
f47c96aa AM |
1224 | static inline bool |
1225 | zero_ssa_operands (tree stmt, int flags) | |
1226 | { | |
1227 | ssa_op_iter iter; | |
1228 | ||
1229 | op_iter_init_tree (&iter, stmt, flags); | |
1230 | return op_iter_done (&iter); | |
db30731a JL |
1231 | } |
1232 | ||
f47c96aa | 1233 | |
395bda42 | 1234 | /* Return the number of operands matching FLAGS in STMT. */ |
f47c96aa AM |
1235 | static inline int |
1236 | num_ssa_operands (tree stmt, int flags) | |
1237 | { | |
1238 | ssa_op_iter iter; | |
66d3fe47 | 1239 | tree t; |
f47c96aa AM |
1240 | int num = 0; |
1241 | ||
66d3fe47 | 1242 | FOR_EACH_SSA_TREE_OPERAND (t, stmt, iter, flags) |
f47c96aa | 1243 | num++; |
f47c96aa AM |
1244 | return num; |
1245 | } | |
1246 | ||
1247 | ||
1248 | /* Delink all immediate_use information for STMT. */ | |
1249 | static inline void | |
1250 | delink_stmt_imm_use (tree stmt) | |
1251 | { | |
1252 | ssa_op_iter iter; | |
1253 | use_operand_p use_p; | |
1254 | ||
1255 | if (ssa_operands_active ()) | |
38635499 | 1256 | FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_ALL_USES) |
f47c96aa AM |
1257 | delink_imm_use (use_p); |
1258 | } | |
1259 | ||
1260 | ||
1261 | /* This routine will compare all the operands matching FLAGS in STMT1 to those | |
1262 | in STMT2. TRUE is returned if they are the same. STMTs can be NULL. */ | |
1263 | static inline bool | |
1264 | compare_ssa_operands_equal (tree stmt1, tree stmt2, int flags) | |
1265 | { | |
1266 | ssa_op_iter iter1, iter2; | |
1267 | tree op1 = NULL_TREE; | |
1268 | tree op2 = NULL_TREE; | |
1269 | bool look1, look2; | |
1270 | ||
1271 | if (stmt1 == stmt2) | |
1272 | return true; | |
1273 | ||
1274 | look1 = stmt1 && stmt_ann (stmt1); | |
1275 | look2 = stmt2 && stmt_ann (stmt2); | |
1276 | ||
1277 | if (look1) | |
1278 | { | |
1279 | op1 = op_iter_init_tree (&iter1, stmt1, flags); | |
1280 | if (!look2) | |
1281 | return op_iter_done (&iter1); | |
1282 | } | |
1283 | else | |
1284 | clear_and_done_ssa_iter (&iter1); | |
1285 | ||
1286 | if (look2) | |
1287 | { | |
1288 | op2 = op_iter_init_tree (&iter2, stmt2, flags); | |
1289 | if (!look1) | |
1290 | return op_iter_done (&iter2); | |
1291 | } | |
1292 | else | |
1293 | clear_and_done_ssa_iter (&iter2); | |
1294 | ||
1295 | while (!op_iter_done (&iter1) && !op_iter_done (&iter2)) | |
1296 | { | |
1297 | if (op1 != op2) | |
1298 | return false; | |
1299 | op1 = op_iter_next_tree (&iter1); | |
1300 | op2 = op_iter_next_tree (&iter2); | |
1301 | } | |
1302 | ||
1303 | return (op_iter_done (&iter1) && op_iter_done (&iter2)); | |
1304 | } | |
1305 | ||
1306 | ||
1307 | /* If there is a single DEF in the PHI node which matches FLAG, return it. | |
1308 | Otherwise return NULL_DEF_OPERAND_P. */ | |
1309 | static inline tree | |
1310 | single_phi_def (tree stmt, int flags) | |
1311 | { | |
1312 | tree def = PHI_RESULT (stmt); | |
1313 | if ((flags & SSA_OP_DEF) && is_gimple_reg (def)) | |
1314 | return def; | |
1315 | if ((flags & SSA_OP_VIRTUAL_DEFS) && !is_gimple_reg (def)) | |
1316 | return def; | |
1317 | return NULL_TREE; | |
1318 | } | |
1319 | ||
1320 | /* Initialize the iterator PTR for uses matching FLAGS in PHI. FLAGS should | |
263bb8fb | 1321 | be either SSA_OP_USES or SSA_OP_VIRTUAL_USES. */ |
f47c96aa AM |
1322 | static inline use_operand_p |
1323 | op_iter_init_phiuse (ssa_op_iter *ptr, tree phi, int flags) | |
1324 | { | |
1325 | tree phi_def = PHI_RESULT (phi); | |
1326 | int comp; | |
1327 | ||
1328 | clear_and_done_ssa_iter (ptr); | |
1329 | ptr->done = false; | |
1330 | ||
1331 | gcc_assert ((flags & (SSA_OP_USE | SSA_OP_VIRTUAL_USES)) != 0); | |
1332 | ||
1333 | comp = (is_gimple_reg (phi_def) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES); | |
1334 | ||
395bda42 | 1335 | /* If the PHI node doesn't the operand type we care about, we're done. */ |
f47c96aa AM |
1336 | if ((flags & comp) == 0) |
1337 | { | |
1338 | ptr->done = true; | |
1339 | return NULL_USE_OPERAND_P; | |
1340 | } | |
1341 | ||
1342 | ptr->phi_stmt = phi; | |
1343 | ptr->num_phi = PHI_NUM_ARGS (phi); | |
1344 | ptr->iter_type = ssa_op_iter_use; | |
1345 | return op_iter_next_use (ptr); | |
1346 | } | |
1347 | ||
1348 | ||
395bda42 | 1349 | /* Start an iterator for a PHI definition. */ |
f47c96aa AM |
1350 | |
1351 | static inline def_operand_p | |
1352 | op_iter_init_phidef (ssa_op_iter *ptr, tree phi, int flags) | |
1353 | { | |
1354 | tree phi_def = PHI_RESULT (phi); | |
1355 | int comp; | |
1356 | ||
1357 | clear_and_done_ssa_iter (ptr); | |
1358 | ptr->done = false; | |
1359 | ||
1360 | gcc_assert ((flags & (SSA_OP_DEF | SSA_OP_VIRTUAL_DEFS)) != 0); | |
1361 | ||
1362 | comp = (is_gimple_reg (phi_def) ? SSA_OP_DEF : SSA_OP_VIRTUAL_DEFS); | |
1363 | ||
395bda42 | 1364 | /* If the PHI node doesn't the operand type we care about, we're done. */ |
f47c96aa AM |
1365 | if ((flags & comp) == 0) |
1366 | { | |
1367 | ptr->done = true; | |
1368 | return NULL_USE_OPERAND_P; | |
1369 | } | |
1370 | ||
1371 | ptr->iter_type = ssa_op_iter_def; | |
1372 | /* The first call to op_iter_next_def will terminate the iterator since | |
1373 | all the fields are NULL. Simply return the result here as the first and | |
1374 | therefore only result. */ | |
1375 | return PHI_RESULT_PTR (phi); | |
1376 | } | |
1377 | ||
6c00f606 AM |
1378 | /* Return true is IMM has reached the end of the immediate use stmt list. */ |
1379 | ||
1380 | static inline bool | |
9566a759 | 1381 | end_imm_use_stmt_p (const imm_use_iterator *imm) |
6c00f606 AM |
1382 | { |
1383 | return (imm->imm_use == imm->end_p); | |
1384 | } | |
1385 | ||
1386 | /* Finished the traverse of an immediate use stmt list IMM by removing the | |
1387 | placeholder node from the list. */ | |
1388 | ||
1389 | static inline void | |
1390 | end_imm_use_stmt_traverse (imm_use_iterator *imm) | |
1391 | { | |
1392 | delink_imm_use (&(imm->iter_node)); | |
1393 | } | |
1394 | ||
1395 | /* Immediate use traversal of uses within a stmt require that all the | |
1396 | uses on a stmt be sequentially listed. This routine is used to build up | |
1397 | this sequential list by adding USE_P to the end of the current list | |
1398 | currently delimited by HEAD and LAST_P. The new LAST_P value is | |
1399 | returned. */ | |
1400 | ||
1401 | static inline use_operand_p | |
1402 | move_use_after_head (use_operand_p use_p, use_operand_p head, | |
1403 | use_operand_p last_p) | |
1404 | { | |
1405 | gcc_assert (USE_FROM_PTR (use_p) == USE_FROM_PTR (head)); | |
1406 | /* Skip head when we find it. */ | |
1407 | if (use_p != head) | |
1408 | { | |
1409 | /* If use_p is already linked in after last_p, continue. */ | |
1410 | if (last_p->next == use_p) | |
1411 | last_p = use_p; | |
1412 | else | |
1413 | { | |
1414 | /* Delink from current location, and link in at last_p. */ | |
1415 | delink_imm_use (use_p); | |
1416 | link_imm_use_to_list (use_p, last_p); | |
1417 | last_p = use_p; | |
1418 | } | |
1419 | } | |
1420 | return last_p; | |
1421 | } | |
1422 | ||
1423 | ||
1424 | /* This routine will relink all uses with the same stmt as HEAD into the list | |
1425 | immediately following HEAD for iterator IMM. */ | |
1426 | ||
1427 | static inline void | |
1428 | link_use_stmts_after (use_operand_p head, imm_use_iterator *imm) | |
1429 | { | |
1430 | use_operand_p use_p; | |
1431 | use_operand_p last_p = head; | |
1432 | tree head_stmt = USE_STMT (head); | |
1433 | tree use = USE_FROM_PTR (head); | |
1434 | ssa_op_iter op_iter; | |
1435 | int flag; | |
1436 | ||
1437 | /* Only look at virtual or real uses, depending on the type of HEAD. */ | |
1438 | flag = (is_gimple_reg (use) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES); | |
1439 | ||
1440 | if (TREE_CODE (head_stmt) == PHI_NODE) | |
1441 | { | |
1442 | FOR_EACH_PHI_ARG (use_p, head_stmt, op_iter, flag) | |
1443 | if (USE_FROM_PTR (use_p) == use) | |
1444 | last_p = move_use_after_head (use_p, head, last_p); | |
1445 | } | |
1446 | else | |
1447 | { | |
1448 | FOR_EACH_SSA_USE_OPERAND (use_p, head_stmt, op_iter, flag) | |
1449 | if (USE_FROM_PTR (use_p) == use) | |
1450 | last_p = move_use_after_head (use_p, head, last_p); | |
1451 | } | |
1452 | /* LInk iter node in after last_p. */ | |
1453 | if (imm->iter_node.prev != NULL) | |
1454 | delink_imm_use (&imm->iter_node); | |
1455 | link_imm_use_to_list (&(imm->iter_node), last_p); | |
1456 | } | |
1457 | ||
1458 | /* Initialize IMM to traverse over uses of VAR. Return the first statement. */ | |
1459 | static inline tree | |
1460 | first_imm_use_stmt (imm_use_iterator *imm, tree var) | |
1461 | { | |
1462 | gcc_assert (TREE_CODE (var) == SSA_NAME); | |
1463 | ||
1464 | imm->end_p = &(SSA_NAME_IMM_USE_NODE (var)); | |
1465 | imm->imm_use = imm->end_p->next; | |
1466 | imm->next_imm_name = NULL_USE_OPERAND_P; | |
1467 | ||
1468 | /* iter_node is used as a marker within the immediate use list to indicate | |
bca50406 KH |
1469 | where the end of the current stmt's uses are. Initialize it to NULL |
1470 | stmt and use, which indicates a marker node. */ | |
6c00f606 AM |
1471 | imm->iter_node.prev = NULL_USE_OPERAND_P; |
1472 | imm->iter_node.next = NULL_USE_OPERAND_P; | |
1473 | imm->iter_node.stmt = NULL_TREE; | |
1474 | imm->iter_node.use = NULL_USE_OPERAND_P; | |
1475 | ||
1476 | if (end_imm_use_stmt_p (imm)) | |
1477 | return NULL_TREE; | |
1478 | ||
1479 | link_use_stmts_after (imm->imm_use, imm); | |
1480 | ||
1481 | return USE_STMT (imm->imm_use); | |
1482 | } | |
1483 | ||
1484 | /* Bump IMM to the next stmt which has a use of var. */ | |
1485 | ||
1486 | static inline tree | |
1487 | next_imm_use_stmt (imm_use_iterator *imm) | |
1488 | { | |
1489 | imm->imm_use = imm->iter_node.next; | |
1490 | if (end_imm_use_stmt_p (imm)) | |
1491 | { | |
1492 | if (imm->iter_node.prev != NULL) | |
1493 | delink_imm_use (&imm->iter_node); | |
1494 | return NULL_TREE; | |
1495 | } | |
1496 | ||
1497 | link_use_stmts_after (imm->imm_use, imm); | |
1498 | return USE_STMT (imm->imm_use); | |
6c00f606 AM |
1499 | } |
1500 | ||
1501 | /* This routine will return the first use on the stmt IMM currently refers | |
1502 | to. */ | |
1503 | ||
1504 | static inline use_operand_p | |
1505 | first_imm_use_on_stmt (imm_use_iterator *imm) | |
1506 | { | |
1507 | imm->next_imm_name = imm->imm_use->next; | |
1508 | return imm->imm_use; | |
1509 | } | |
1510 | ||
1511 | /* Return TRUE if the last use on the stmt IMM refers to has been visited. */ | |
1512 | ||
1513 | static inline bool | |
9566a759 | 1514 | end_imm_use_on_stmt_p (const imm_use_iterator *imm) |
6c00f606 AM |
1515 | { |
1516 | return (imm->imm_use == &(imm->iter_node)); | |
1517 | } | |
1518 | ||
1519 | /* Bump to the next use on the stmt IMM refers to, return NULL if done. */ | |
1520 | ||
1521 | static inline use_operand_p | |
1522 | next_imm_use_on_stmt (imm_use_iterator *imm) | |
1523 | { | |
1524 | imm->imm_use = imm->next_imm_name; | |
1525 | if (end_imm_use_on_stmt_p (imm)) | |
1526 | return NULL_USE_OPERAND_P; | |
1527 | else | |
1528 | { | |
1529 | imm->next_imm_name = imm->imm_use->next; | |
1530 | return imm->imm_use; | |
1531 | } | |
1532 | } | |
f47c96aa | 1533 | |
db30731a JL |
1534 | /* Return true if VAR cannot be modified by the program. */ |
1535 | ||
1536 | static inline bool | |
9566a759 | 1537 | unmodifiable_var_p (const_tree var) |
db30731a JL |
1538 | { |
1539 | if (TREE_CODE (var) == SSA_NAME) | |
1540 | var = SSA_NAME_VAR (var); | |
326eda4b DB |
1541 | |
1542 | if (MTAG_P (var)) | |
1543 | return TREE_READONLY (var) && (TREE_STATIC (var) || MTAG_GLOBAL (var)); | |
1544 | ||
db30731a JL |
1545 | return TREE_READONLY (var) && (TREE_STATIC (var) || DECL_EXTERNAL (var)); |
1546 | } | |
1547 | ||
8d66aeca | 1548 | /* Return true if REF, an ARRAY_REF, has an INDIRECT_REF somewhere in it. */ |
b1347638 DB |
1549 | |
1550 | static inline bool | |
9566a759 | 1551 | array_ref_contains_indirect_ref (const_tree ref) |
b1347638 | 1552 | { |
8d66aeca RG |
1553 | gcc_assert (TREE_CODE (ref) == ARRAY_REF); |
1554 | ||
1555 | do { | |
1556 | ref = TREE_OPERAND (ref, 0); | |
1557 | } while (handled_component_p (ref)); | |
1558 | ||
1559 | return TREE_CODE (ref) == INDIRECT_REF; | |
b1347638 DB |
1560 | } |
1561 | ||
8d66aeca RG |
1562 | /* Return true if REF, a handled component reference, has an ARRAY_REF |
1563 | somewhere in it. */ | |
c75ab022 DB |
1564 | |
1565 | static inline bool | |
9566a759 | 1566 | ref_contains_array_ref (const_tree ref) |
c75ab022 | 1567 | { |
8d66aeca RG |
1568 | gcc_assert (handled_component_p (ref)); |
1569 | ||
1570 | do { | |
1571 | if (TREE_CODE (ref) == ARRAY_REF) | |
1572 | return true; | |
1573 | ref = TREE_OPERAND (ref, 0); | |
1574 | } while (handled_component_p (ref)); | |
1575 | ||
c75ab022 DB |
1576 | return false; |
1577 | } | |
1578 | ||
1579 | /* Given a variable VAR, lookup and return a pointer to the list of | |
1580 | subvariables for it. */ | |
1581 | ||
1582 | static inline subvar_t * | |
9566a759 | 1583 | lookup_subvars_for_var (const_tree var) |
c75ab022 DB |
1584 | { |
1585 | var_ann_t ann = var_ann (var); | |
1586 | gcc_assert (ann); | |
1587 | return &ann->subvars; | |
1588 | } | |
1589 | ||
1590 | /* Given a variable VAR, return a linked list of subvariables for VAR, or | |
1591 | NULL, if there are no subvariables. */ | |
1592 | ||
1593 | static inline subvar_t | |
1594 | get_subvars_for_var (tree var) | |
1595 | { | |
1596 | subvar_t subvars; | |
1597 | ||
1598 | gcc_assert (SSA_VAR_P (var)); | |
1599 | ||
1600 | if (TREE_CODE (var) == SSA_NAME) | |
1601 | subvars = *(lookup_subvars_for_var (SSA_NAME_VAR (var))); | |
1602 | else | |
1603 | subvars = *(lookup_subvars_for_var (var)); | |
1604 | return subvars; | |
1605 | } | |
1606 | ||
e8ca4159 DN |
1607 | /* Return the subvariable of VAR at offset OFFSET. */ |
1608 | ||
1609 | static inline tree | |
1610 | get_subvar_at (tree var, unsigned HOST_WIDE_INT offset) | |
1611 | { | |
eee717aa | 1612 | subvar_t sv = get_subvars_for_var (var); |
8ad6aff3 RG |
1613 | int low, high; |
1614 | ||
1615 | low = 0; | |
1616 | high = VEC_length (tree, sv) - 1; | |
1617 | while (low <= high) | |
1618 | { | |
1619 | int mid = (low + high) / 2; | |
1620 | tree subvar = VEC_index (tree, sv, mid); | |
1621 | if (SFT_OFFSET (subvar) == offset) | |
1622 | return subvar; | |
1623 | else if (SFT_OFFSET (subvar) < offset) | |
1624 | low = mid + 1; | |
1625 | else | |
1626 | high = mid - 1; | |
1627 | } | |
1628 | ||
1629 | return NULL_TREE; | |
1630 | } | |
1631 | ||
1632 | ||
1633 | /* Return the first subvariable in SV that overlaps [offset, offset + size[. | |
1634 | NULL_TREE is returned, if there is no overlapping subvariable, else *I | |
1635 | is set to the index in the SV vector of the first overlap. */ | |
1636 | ||
1637 | static inline tree | |
1638 | get_first_overlapping_subvar (subvar_t sv, unsigned HOST_WIDE_INT offset, | |
1639 | unsigned HOST_WIDE_INT size, unsigned int *i) | |
1640 | { | |
1641 | int low = 0; | |
1642 | int high = VEC_length (tree, sv) - 1; | |
1643 | int mid; | |
eee717aa RG |
1644 | tree subvar; |
1645 | ||
8ad6aff3 RG |
1646 | if (low > high) |
1647 | return NULL_TREE; | |
1648 | ||
1649 | /* Binary search for offset. */ | |
1650 | do | |
1651 | { | |
1652 | mid = (low + high) / 2; | |
1653 | subvar = VEC_index (tree, sv, mid); | |
1654 | if (SFT_OFFSET (subvar) == offset) | |
1655 | { | |
1656 | *i = mid; | |
1657 | return subvar; | |
1658 | } | |
1659 | else if (SFT_OFFSET (subvar) < offset) | |
1660 | low = mid + 1; | |
1661 | else | |
1662 | high = mid - 1; | |
1663 | } | |
1664 | while (low <= high); | |
1665 | ||
1666 | /* As we didn't find a subvar with offset, adjust to return the | |
1667 | first overlapping one. */ | |
1668 | if (SFT_OFFSET (subvar) < offset | |
1669 | && SFT_OFFSET (subvar) + SFT_SIZE (subvar) <= offset) | |
1670 | { | |
1671 | mid += 1; | |
1672 | if ((unsigned)mid >= VEC_length (tree, sv)) | |
1673 | return NULL_TREE; | |
1674 | subvar = VEC_index (tree, sv, mid); | |
1675 | } | |
1676 | else if (SFT_OFFSET (subvar) > offset | |
1677 | && size <= SFT_OFFSET (subvar) - offset) | |
1678 | { | |
1679 | mid -= 1; | |
1680 | if (mid < 0) | |
1681 | return NULL_TREE; | |
1682 | subvar = VEC_index (tree, sv, mid); | |
1683 | } | |
1684 | ||
1685 | if (overlap_subvar (offset, size, subvar, NULL)) | |
1686 | { | |
1687 | *i = mid; | |
eee717aa | 1688 | return subvar; |
8ad6aff3 | 1689 | } |
e8ca4159 DN |
1690 | |
1691 | return NULL_TREE; | |
1692 | } | |
1693 | ||
8ad6aff3 | 1694 | |
c75ab022 | 1695 | /* Return true if V is a tree that we can have subvars for. |
a916f21d | 1696 | Normally, this is any aggregate type. Also complex |
8ae5e6f2 | 1697 | types which are not gimple registers can have subvars. */ |
c75ab022 DB |
1698 | |
1699 | static inline bool | |
9566a759 | 1700 | var_can_have_subvars (const_tree v) |
c75ab022 | 1701 | { |
1651647c AP |
1702 | /* Volatile variables should never have subvars. */ |
1703 | if (TREE_THIS_VOLATILE (v)) | |
1704 | return false; | |
1705 | ||
8ae5e6f2 AP |
1706 | /* Non decls or memory tags can never have subvars. */ |
1707 | if (!DECL_P (v) || MTAG_P (v)) | |
1708 | return false; | |
1709 | ||
a916f21d RG |
1710 | /* Aggregates can have subvars. */ |
1711 | if (AGGREGATE_TYPE_P (TREE_TYPE (v))) | |
8ae5e6f2 AP |
1712 | return true; |
1713 | ||
1714 | /* Complex types variables which are not also a gimple register can | |
1715 | have subvars. */ | |
1716 | if (TREE_CODE (TREE_TYPE (v)) == COMPLEX_TYPE | |
0890b981 | 1717 | && !DECL_GIMPLE_REG_P (v)) |
8ae5e6f2 AP |
1718 | return true; |
1719 | ||
1720 | return false; | |
c75ab022 DB |
1721 | } |
1722 | ||
1723 | ||
013cc86f DB |
1724 | /* Return true if OFFSET and SIZE define a range that overlaps with some |
1725 | portion of the range of SV, a subvar. If there was an exact overlap, | |
1726 | *EXACT will be set to true upon return. */ | |
1727 | ||
1728 | static inline bool | |
e8ca4159 | 1729 | overlap_subvar (unsigned HOST_WIDE_INT offset, unsigned HOST_WIDE_INT size, |
9566a759 | 1730 | const_tree sv, bool *exact) |
013cc86f DB |
1731 | { |
1732 | /* There are three possible cases of overlap. | |
1733 | 1. We can have an exact overlap, like so: | |
1734 | |offset, offset + size | | |
1735 | |sv->offset, sv->offset + sv->size | | |
1736 | ||
1737 | 2. We can have offset starting after sv->offset, like so: | |
1738 | ||
1739 | |offset, offset + size | | |
1740 | |sv->offset, sv->offset + sv->size | | |
1741 | ||
1742 | 3. We can have offset starting before sv->offset, like so: | |
1743 | ||
1744 | |offset, offset + size | | |
1745 | |sv->offset, sv->offset + sv->size| | |
1746 | */ | |
1747 | ||
1748 | if (exact) | |
1749 | *exact = false; | |
3c0b6c43 | 1750 | if (offset == SFT_OFFSET (sv) && size == SFT_SIZE (sv)) |
013cc86f DB |
1751 | { |
1752 | if (exact) | |
1753 | *exact = true; | |
1754 | return true; | |
1755 | } | |
3c0b6c43 DB |
1756 | else if (offset >= SFT_OFFSET (sv) |
1757 | && offset < (SFT_OFFSET (sv) + SFT_SIZE (sv))) | |
013cc86f DB |
1758 | { |
1759 | return true; | |
1760 | } | |
3c0b6c43 DB |
1761 | else if (offset < SFT_OFFSET (sv) |
1762 | && (size > SFT_OFFSET (sv) - offset)) | |
013cc86f DB |
1763 | { |
1764 | return true; | |
1765 | } | |
1766 | return false; | |
1767 | ||
1768 | } | |
c75ab022 | 1769 | |
cfaab3a9 DN |
1770 | /* Return the memory tag associated with symbol SYM. */ |
1771 | ||
1772 | static inline tree | |
1773 | symbol_mem_tag (tree sym) | |
1774 | { | |
1775 | tree tag = get_var_ann (sym)->symbol_mem_tag; | |
1776 | ||
1777 | #if defined ENABLE_CHECKING | |
1778 | if (tag) | |
1779 | gcc_assert (TREE_CODE (tag) == SYMBOL_MEMORY_TAG); | |
1780 | #endif | |
1781 | ||
1782 | return tag; | |
1783 | } | |
1784 | ||
1785 | ||
1786 | /* Set the memory tag associated with symbol SYM. */ | |
1787 | ||
1788 | static inline void | |
1789 | set_symbol_mem_tag (tree sym, tree tag) | |
1790 | { | |
1791 | #if defined ENABLE_CHECKING | |
1792 | if (tag) | |
1793 | gcc_assert (TREE_CODE (tag) == SYMBOL_MEMORY_TAG); | |
1794 | #endif | |
1795 | ||
1796 | get_var_ann (sym)->symbol_mem_tag = tag; | |
1797 | } | |
1798 | ||
83737db2 DB |
1799 | /* Get the value handle of EXPR. This is the only correct way to get |
1800 | the value handle for a "thing". If EXPR does not have a value | |
1801 | handle associated, it returns NULL_TREE. | |
1802 | NB: If EXPR is min_invariant, this function is *required* to return | |
1803 | EXPR. */ | |
1804 | ||
1805 | static inline tree | |
1806 | get_value_handle (tree expr) | |
1807 | { | |
1808 | if (TREE_CODE (expr) == SSA_NAME) | |
1809 | return SSA_NAME_VALUE (expr); | |
b71b4522 | 1810 | else if (DECL_P (expr) || TREE_CODE (expr) == TREE_LIST |
83737db2 DB |
1811 | || TREE_CODE (expr) == CONSTRUCTOR) |
1812 | { | |
1813 | tree_ann_common_t ann = tree_common_ann (expr); | |
1814 | return ((ann) ? ann->value_handle : NULL_TREE); | |
1815 | } | |
1816 | else if (is_gimple_min_invariant (expr)) | |
1817 | return expr; | |
1818 | else if (EXPR_P (expr)) | |
1819 | { | |
1820 | tree_ann_common_t ann = tree_common_ann (expr); | |
1821 | return ((ann) ? ann->value_handle : NULL_TREE); | |
1822 | } | |
1823 | else | |
1824 | gcc_unreachable (); | |
1825 | } | |
1826 | ||
456cde30 JH |
1827 | /* Accessor to tree-ssa-operands.c caches. */ |
1828 | static inline struct ssa_operands * | |
9566a759 | 1829 | gimple_ssa_operands (const struct function *fun) |
456cde30 JH |
1830 | { |
1831 | return &fun->gimple_df->ssa_operands; | |
1832 | } | |
e9e0aa2c DN |
1833 | |
1834 | /* Map describing reference statistics for function FN. */ | |
1835 | static inline struct mem_ref_stats_d * | |
9566a759 | 1836 | gimple_mem_ref_stats (const struct function *fn) |
e9e0aa2c DN |
1837 | { |
1838 | return &fn->gimple_df->mem_ref_stats; | |
1839 | } | |
6de9cd9a | 1840 | #endif /* _TREE_FLOW_INLINE_H */ |