1169689Skan/* Inline functions for tree-flow.h
2169689Skan   Copyright (C) 2001, 2003, 2005, 2006 Free Software Foundation, Inc.
3169689Skan   Contributed by Diego Novillo <dnovillo@redhat.com>
4169689Skan
5169689SkanThis file is part of GCC.
6169689Skan
7169689SkanGCC is free software; you can redistribute it and/or modify
8169689Skanit under the terms of the GNU General Public License as published by
9169689Skanthe Free Software Foundation; either version 2, or (at your option)
10169689Skanany later version.
11169689Skan
12169689SkanGCC is distributed in the hope that it will be useful,
13169689Skanbut WITHOUT ANY WARRANTY; without even the implied warranty of
14169689SkanMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15169689SkanGNU General Public License for more details.
16169689Skan
17169689SkanYou should have received a copy of the GNU General Public License
18169689Skanalong with GCC; see the file COPYING.  If not, write to
19169689Skanthe Free Software Foundation, 51 Franklin Street, Fifth Floor,
20169689SkanBoston, MA 02110-1301, USA.  */
21169689Skan
22169689Skan#ifndef _TREE_FLOW_INLINE_H
23169689Skan#define _TREE_FLOW_INLINE_H 1
24169689Skan
25169689Skan/* Inline functions for manipulating various data structures defined in
26169689Skan   tree-flow.h.  See tree-flow.h for documentation.  */
27169689Skan
28169689Skan/* Initialize the hashtable iterator HTI to point to hashtable TABLE */
29169689Skan
30169689Skanstatic inline void *
31169689Skanfirst_htab_element (htab_iterator *hti, htab_t table)
32169689Skan{
33169689Skan  hti->htab = table;
34169689Skan  hti->slot = table->entries;
35169689Skan  hti->limit = hti->slot + htab_size (table);
36169689Skan  do
37169689Skan    {
38169689Skan      PTR x = *(hti->slot);
39169689Skan      if (x != HTAB_EMPTY_ENTRY && x != HTAB_DELETED_ENTRY)
40169689Skan	break;
41169689Skan    } while (++(hti->slot) < hti->limit);
42169689Skan
43169689Skan  if (hti->slot < hti->limit)
44169689Skan    return *(hti->slot);
45169689Skan  return NULL;
46169689Skan}
47169689Skan
48169689Skan/* Return current non-empty/deleted slot of the hashtable pointed to by HTI,
49169689Skan   or NULL if we have  reached the end.  */
50169689Skan
51169689Skanstatic inline bool
52169689Skanend_htab_p (htab_iterator *hti)
53169689Skan{
54169689Skan  if (hti->slot >= hti->limit)
55169689Skan    return true;
56169689Skan  return false;
57169689Skan}
58169689Skan
59169689Skan/* Advance the hashtable iterator pointed to by HTI to the next element of the
60169689Skan   hashtable.  */
61169689Skan
62169689Skanstatic inline void *
63169689Skannext_htab_element (htab_iterator *hti)
64169689Skan{
65169689Skan  while (++(hti->slot) < hti->limit)
66169689Skan    {
67169689Skan      PTR x = *(hti->slot);
68169689Skan      if (x != HTAB_EMPTY_ENTRY && x != HTAB_DELETED_ENTRY)
69169689Skan	return x;
70169689Skan    };
71169689Skan  return NULL;
72169689Skan}
73169689Skan
74169689Skan/* Initialize ITER to point to the first referenced variable in the
75169689Skan   referenced_vars hashtable, and return that variable.  */
76169689Skan
77169689Skanstatic inline tree
78169689Skanfirst_referenced_var (referenced_var_iterator *iter)
79169689Skan{
80169689Skan  struct int_tree_map *itm;
81169689Skan  itm = (struct int_tree_map *) first_htab_element (&iter->hti,
82169689Skan                                                    referenced_vars);
83169689Skan  if (!itm)
84169689Skan    return NULL;
85169689Skan  return itm->to;
86169689Skan}
87169689Skan
88169689Skan/* Return true if we have hit the end of the referenced variables ITER is
89169689Skan   iterating through.  */
90169689Skan
91169689Skanstatic inline bool
92169689Skanend_referenced_vars_p (referenced_var_iterator *iter)
93169689Skan{
94169689Skan  return end_htab_p (&iter->hti);
95169689Skan}
96169689Skan
97169689Skan/* Make ITER point to the next referenced_var in the referenced_var hashtable,
98169689Skan   and return that variable.  */
99169689Skan
100169689Skanstatic inline tree
101169689Skannext_referenced_var (referenced_var_iterator *iter)
102169689Skan{
103169689Skan  struct int_tree_map *itm;
104169689Skan  itm = (struct int_tree_map *) next_htab_element (&iter->hti);
105169689Skan  if (!itm)
106169689Skan    return NULL;
107169689Skan  return itm->to;
108169689Skan}
109169689Skan
110169689Skan/* Fill up VEC with the variables in the referenced vars hashtable.  */
111169689Skan
112169689Skanstatic inline void
113169689Skanfill_referenced_var_vec (VEC (tree, heap) **vec)
114169689Skan{
115169689Skan  referenced_var_iterator rvi;
116169689Skan  tree var;
117169689Skan  *vec = NULL;
118169689Skan  FOR_EACH_REFERENCED_VAR (var, rvi)
119169689Skan    VEC_safe_push (tree, heap, *vec, var);
120169689Skan}
121169689Skan
122169689Skan/* Return the variable annotation for T, which must be a _DECL node.
123169689Skan   Return NULL if the variable annotation doesn't already exist.  */
124169689Skanstatic inline var_ann_t
125169689Skanvar_ann (tree t)
126169689Skan{
127169689Skan  gcc_assert (t);
128169689Skan  gcc_assert (DECL_P (t));
129169689Skan  gcc_assert (TREE_CODE (t) != FUNCTION_DECL);
130169689Skan  gcc_assert (!t->common.ann || t->common.ann->common.type == VAR_ANN);
131169689Skan
132169689Skan  return (var_ann_t) t->common.ann;
133169689Skan}
134169689Skan
135169689Skan/* Return the variable annotation for T, which must be a _DECL node.
136169689Skan   Create the variable annotation if it doesn't exist.  */
137169689Skanstatic inline var_ann_t
138169689Skanget_var_ann (tree var)
139169689Skan{
140169689Skan  var_ann_t ann = var_ann (var);
141169689Skan  return (ann) ? ann : create_var_ann (var);
142169689Skan}
143169689Skan
144169689Skan/* Return the function annotation for T, which must be a FUNCTION_DECL node.
145169689Skan   Return NULL if the function annotation doesn't already exist.  */
146169689Skanstatic inline function_ann_t
147169689Skanfunction_ann (tree t)
148169689Skan{
149169689Skan  gcc_assert (t);
150169689Skan  gcc_assert (TREE_CODE (t) == FUNCTION_DECL);
151169689Skan  gcc_assert (!t->common.ann || t->common.ann->common.type == FUNCTION_ANN);
152169689Skan
153169689Skan  return (function_ann_t) t->common.ann;
154169689Skan}
155169689Skan
156169689Skan/* Return the function annotation for T, which must be a FUNCTION_DECL node.
157169689Skan   Create the function annotation if it doesn't exist.  */
158169689Skanstatic inline function_ann_t
159169689Skanget_function_ann (tree var)
160169689Skan{
161169689Skan  function_ann_t ann = function_ann (var);
162169689Skan  gcc_assert (!var->common.ann || var->common.ann->common.type == FUNCTION_ANN);
163169689Skan  return (ann) ? ann : create_function_ann (var);
164169689Skan}
165169689Skan
166169689Skan/* Return the statement annotation for T, which must be a statement
167169689Skan   node.  Return NULL if the statement annotation doesn't exist.  */
168169689Skanstatic inline stmt_ann_t
169169689Skanstmt_ann (tree t)
170169689Skan{
171169689Skan#ifdef ENABLE_CHECKING
172169689Skan  gcc_assert (is_gimple_stmt (t));
173169689Skan#endif
174169689Skan  gcc_assert (!t->common.ann || t->common.ann->common.type == STMT_ANN);
175169689Skan  return (stmt_ann_t) t->common.ann;
176169689Skan}
177169689Skan
178169689Skan/* Return the statement annotation for T, which must be a statement
179169689Skan   node.  Create the statement annotation if it doesn't exist.  */
180169689Skanstatic inline stmt_ann_t
181169689Skanget_stmt_ann (tree stmt)
182169689Skan{
183169689Skan  stmt_ann_t ann = stmt_ann (stmt);
184169689Skan  return (ann) ? ann : create_stmt_ann (stmt);
185169689Skan}
186169689Skan
187169689Skan/* Return the annotation type for annotation ANN.  */
188169689Skanstatic inline enum tree_ann_type
189169689Skanann_type (tree_ann_t ann)
190169689Skan{
191169689Skan  return ann->common.type;
192169689Skan}
193169689Skan
194169689Skan/* Return the basic block for statement T.  */
195169689Skanstatic inline basic_block
196169689Skanbb_for_stmt (tree t)
197169689Skan{
198169689Skan  stmt_ann_t ann;
199169689Skan
200169689Skan  if (TREE_CODE (t) == PHI_NODE)
201169689Skan    return PHI_BB (t);
202169689Skan
203169689Skan  ann = stmt_ann (t);
204169689Skan  return ann ? ann->bb : NULL;
205169689Skan}
206169689Skan
207169689Skan/* Return the may_aliases varray for variable VAR, or NULL if it has
208169689Skan   no may aliases.  */
209169689Skanstatic inline VEC(tree, gc) *
210169689Skanmay_aliases (tree var)
211169689Skan{
212169689Skan  var_ann_t ann = var_ann (var);
213169689Skan  return ann ? ann->may_aliases : NULL;
214169689Skan}
215169689Skan
216169689Skan/* Return the line number for EXPR, or return -1 if we have no line
217169689Skan   number information for it.  */
218169689Skanstatic inline int
219169689Skanget_lineno (tree expr)
220169689Skan{
221169689Skan  if (expr == NULL_TREE)
222169689Skan    return -1;
223169689Skan
224169689Skan  if (TREE_CODE (expr) == COMPOUND_EXPR)
225169689Skan    expr = TREE_OPERAND (expr, 0);
226169689Skan
227169689Skan  if (! EXPR_HAS_LOCATION (expr))
228169689Skan    return -1;
229169689Skan
230169689Skan  return EXPR_LINENO (expr);
231169689Skan}
232169689Skan
233169689Skan/* Return the file name for EXPR, or return "???" if we have no
234169689Skan   filename information.  */
235169689Skanstatic inline const char *
236169689Skanget_filename (tree expr)
237169689Skan{
238169689Skan  const char *filename;
239169689Skan  if (expr == NULL_TREE)
240169689Skan    return "???";
241169689Skan
242169689Skan  if (TREE_CODE (expr) == COMPOUND_EXPR)
243169689Skan    expr = TREE_OPERAND (expr, 0);
244169689Skan
245169689Skan  if (EXPR_HAS_LOCATION (expr) && (filename = EXPR_FILENAME (expr)))
246169689Skan    return filename;
247169689Skan  else
248169689Skan    return "???";
249169689Skan}
250169689Skan
251169689Skan/* Return true if T is a noreturn call.  */
252169689Skanstatic inline bool
253169689Skannoreturn_call_p (tree t)
254169689Skan{
255169689Skan  tree call = get_call_expr_in (t);
256169689Skan  return call != 0 && (call_expr_flags (call) & ECF_NORETURN) != 0;
257169689Skan}
258169689Skan
259169689Skan/* Mark statement T as modified.  */
260169689Skanstatic inline void
261169689Skanmark_stmt_modified (tree t)
262169689Skan{
263169689Skan  stmt_ann_t ann;
264169689Skan  if (TREE_CODE (t) == PHI_NODE)
265169689Skan    return;
266169689Skan
267169689Skan  ann = stmt_ann (t);
268169689Skan  if (ann == NULL)
269169689Skan    ann = create_stmt_ann (t);
270169689Skan  else if (noreturn_call_p (t))
271169689Skan    VEC_safe_push (tree, gc, modified_noreturn_calls, t);
272169689Skan  ann->modified = 1;
273169689Skan}
274169689Skan
275169689Skan/* Mark statement T as modified, and update it.  */
276169689Skanstatic inline void
277169689Skanupdate_stmt (tree t)
278169689Skan{
279169689Skan  if (TREE_CODE (t) == PHI_NODE)
280169689Skan    return;
281169689Skan  mark_stmt_modified (t);
282169689Skan  update_stmt_operands (t);
283169689Skan}
284169689Skan
285169689Skanstatic inline void
286169689Skanupdate_stmt_if_modified (tree t)
287169689Skan{
288169689Skan  if (stmt_modified_p (t))
289169689Skan    update_stmt_operands (t);
290169689Skan}
291169689Skan
292169689Skan/* Return true if T is marked as modified, false otherwise.  */
293169689Skanstatic inline bool
294169689Skanstmt_modified_p (tree t)
295169689Skan{
296169689Skan  stmt_ann_t ann = stmt_ann (t);
297169689Skan
298169689Skan  /* Note that if the statement doesn't yet have an annotation, we consider it
299169689Skan     modified.  This will force the next call to update_stmt_operands to scan
300169689Skan     the statement.  */
301169689Skan  return ann ? ann->modified : true;
302169689Skan}
303169689Skan
304169689Skan/* Delink an immediate_uses node from its chain.  */
305169689Skanstatic inline void
306169689Skandelink_imm_use (ssa_use_operand_t *linknode)
307169689Skan{
308169689Skan  /* Return if this node is not in a list.  */
309169689Skan  if (linknode->prev == NULL)
310169689Skan    return;
311169689Skan
312169689Skan  linknode->prev->next = linknode->next;
313169689Skan  linknode->next->prev = linknode->prev;
314169689Skan  linknode->prev = NULL;
315169689Skan  linknode->next = NULL;
316169689Skan}
317169689Skan
318169689Skan/* Link ssa_imm_use node LINKNODE into the chain for LIST.  */
319169689Skanstatic inline void
320169689Skanlink_imm_use_to_list (ssa_use_operand_t *linknode, ssa_use_operand_t *list)
321169689Skan{
322169689Skan  /* Link the new node at the head of the list.  If we are in the process of
323169689Skan     traversing the list, we won't visit any new nodes added to it.  */
324169689Skan  linknode->prev = list;
325169689Skan  linknode->next = list->next;
326169689Skan  list->next->prev = linknode;
327169689Skan  list->next = linknode;
328169689Skan}
329169689Skan
330169689Skan/* Link ssa_imm_use node LINKNODE into the chain for DEF.  */
331169689Skanstatic inline void
332169689Skanlink_imm_use (ssa_use_operand_t *linknode, tree def)
333169689Skan{
334169689Skan  ssa_use_operand_t *root;
335169689Skan
336169689Skan  if (!def || TREE_CODE (def) != SSA_NAME)
337169689Skan    linknode->prev = NULL;
338169689Skan  else
339169689Skan    {
340169689Skan      root = &(SSA_NAME_IMM_USE_NODE (def));
341169689Skan#ifdef ENABLE_CHECKING
342169689Skan      if (linknode->use)
343169689Skan        gcc_assert (*(linknode->use) == def);
344169689Skan#endif
345169689Skan      link_imm_use_to_list (linknode, root);
346169689Skan    }
347169689Skan}
348169689Skan
349169689Skan/* Set the value of a use pointed to by USE to VAL.  */
350169689Skanstatic inline void
351169689Skanset_ssa_use_from_ptr (use_operand_p use, tree val)
352169689Skan{
353169689Skan  delink_imm_use (use);
354169689Skan  *(use->use) = val;
355169689Skan  link_imm_use (use, val);
356169689Skan}
357169689Skan
358169689Skan/* Link ssa_imm_use node LINKNODE into the chain for DEF, with use occurring
359169689Skan   in STMT.  */
360169689Skanstatic inline void
361169689Skanlink_imm_use_stmt (ssa_use_operand_t *linknode, tree def, tree stmt)
362169689Skan{
363169689Skan  if (stmt)
364169689Skan    link_imm_use (linknode, def);
365169689Skan  else
366169689Skan    link_imm_use (linknode, NULL);
367169689Skan  linknode->stmt = stmt;
368169689Skan}
369169689Skan
370169689Skan/* Relink a new node in place of an old node in the list.  */
371169689Skanstatic inline void
372169689Skanrelink_imm_use (ssa_use_operand_t *node, ssa_use_operand_t *old)
373169689Skan{
374169689Skan  /* The node one had better be in the same list.  */
375169689Skan  gcc_assert (*(old->use) == *(node->use));
376169689Skan  node->prev = old->prev;
377169689Skan  node->next = old->next;
378169689Skan  if (old->prev)
379169689Skan    {
380169689Skan      old->prev->next = node;
381169689Skan      old->next->prev = node;
382169689Skan      /* Remove the old node from the list.  */
383169689Skan      old->prev = NULL;
384169689Skan    }
385169689Skan}
386169689Skan
387169689Skan/* Relink ssa_imm_use node LINKNODE into the chain for OLD, with use occurring
388169689Skan   in STMT.  */
389169689Skanstatic inline void
390169689Skanrelink_imm_use_stmt (ssa_use_operand_t *linknode, ssa_use_operand_t *old, tree stmt)
391169689Skan{
392169689Skan  if (stmt)
393169689Skan    relink_imm_use (linknode, old);
394169689Skan  else
395169689Skan    link_imm_use (linknode, NULL);
396169689Skan  linknode->stmt = stmt;
397169689Skan}
398169689Skan
399169689Skan
400169689Skan/* Return true is IMM has reached the end of the immediate use list.  */
401169689Skanstatic inline bool
402169689Skanend_readonly_imm_use_p (imm_use_iterator *imm)
403169689Skan{
404169689Skan  return (imm->imm_use == imm->end_p);
405169689Skan}
406169689Skan
407169689Skan/* Initialize iterator IMM to process the list for VAR.  */
408169689Skanstatic inline use_operand_p
409169689Skanfirst_readonly_imm_use (imm_use_iterator *imm, tree var)
410169689Skan{
411169689Skan  gcc_assert (TREE_CODE (var) == SSA_NAME);
412169689Skan
413169689Skan  imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
414169689Skan  imm->imm_use = imm->end_p->next;
415169689Skan#ifdef ENABLE_CHECKING
416169689Skan  imm->iter_node.next = imm->imm_use->next;
417169689Skan#endif
418169689Skan  if (end_readonly_imm_use_p (imm))
419169689Skan    return NULL_USE_OPERAND_P;
420169689Skan  return imm->imm_use;
421169689Skan}
422169689Skan
423169689Skan/* Bump IMM to the next use in the list.  */
424169689Skanstatic inline use_operand_p
425169689Skannext_readonly_imm_use (imm_use_iterator *imm)
426169689Skan{
427169689Skan  use_operand_p old = imm->imm_use;
428169689Skan
429169689Skan#ifdef ENABLE_CHECKING
430169689Skan  /* If this assertion fails, it indicates the 'next' pointer has changed
431169689Skan     since we the last bump.  This indicates that the list is being modified
432169689Skan     via stmt changes, or SET_USE, or somesuch thing, and you need to be
433169689Skan     using the SAFE version of the iterator.  */
434169689Skan  gcc_assert (imm->iter_node.next == old->next);
435169689Skan  imm->iter_node.next = old->next->next;
436169689Skan#endif
437169689Skan
438169689Skan  imm->imm_use = old->next;
439169689Skan  if (end_readonly_imm_use_p (imm))
440169689Skan    return old;
441169689Skan  return imm->imm_use;
442169689Skan}
443169689Skan
444169689Skan/* Return true if VAR has no uses.  */
445169689Skanstatic inline bool
446169689Skanhas_zero_uses (tree var)
447169689Skan{
448169689Skan  ssa_use_operand_t *ptr;
449169689Skan  ptr = &(SSA_NAME_IMM_USE_NODE (var));
450169689Skan  /* A single use means there is no items in the list.  */
451169689Skan  return (ptr == ptr->next);
452169689Skan}
453169689Skan
454169689Skan/* Return true if VAR has a single use.  */
455169689Skanstatic inline bool
456169689Skanhas_single_use (tree var)
457169689Skan{
458169689Skan  ssa_use_operand_t *ptr;
459169689Skan  ptr = &(SSA_NAME_IMM_USE_NODE (var));
460169689Skan  /* A single use means there is one item in the list.  */
461169689Skan  return (ptr != ptr->next && ptr == ptr->next->next);
462169689Skan}
463169689Skan
464169689Skan/* If VAR has only a single immediate use, return true, and set USE_P and STMT
465169689Skan   to the use pointer and stmt of occurrence.  */
466169689Skanstatic inline bool
467169689Skansingle_imm_use (tree var, use_operand_p *use_p, tree *stmt)
468169689Skan{
469169689Skan  ssa_use_operand_t *ptr;
470169689Skan
471169689Skan  ptr = &(SSA_NAME_IMM_USE_NODE (var));
472169689Skan  if (ptr != ptr->next && ptr == ptr->next->next)
473169689Skan    {
474169689Skan      *use_p = ptr->next;
475169689Skan      *stmt = ptr->next->stmt;
476169689Skan      return true;
477169689Skan    }
478169689Skan  *use_p = NULL_USE_OPERAND_P;
479169689Skan  *stmt = NULL_TREE;
480169689Skan  return false;
481169689Skan}
482169689Skan
483169689Skan/* Return the number of immediate uses of VAR.  */
484169689Skanstatic inline unsigned int
485169689Skannum_imm_uses (tree var)
486169689Skan{
487169689Skan  ssa_use_operand_t *ptr, *start;
488169689Skan  unsigned int num;
489169689Skan
490169689Skan  start = &(SSA_NAME_IMM_USE_NODE (var));
491169689Skan  num = 0;
492169689Skan  for (ptr = start->next; ptr != start; ptr = ptr->next)
493169689Skan     num++;
494169689Skan
495169689Skan  return num;
496169689Skan}
497169689Skan
498169689Skan
499169689Skan/* Return the tree pointer to by USE.  */
500169689Skanstatic inline tree
501169689Skanget_use_from_ptr (use_operand_p use)
502169689Skan{
503169689Skan  return *(use->use);
504169689Skan}
505169689Skan
506169689Skan/* Return the tree pointer to by DEF.  */
507169689Skanstatic inline tree
508169689Skanget_def_from_ptr (def_operand_p def)
509169689Skan{
510169689Skan  return *def;
511169689Skan}
512169689Skan
513169689Skan/* Return a def_operand_p pointer for the result of PHI.  */
514169689Skanstatic inline def_operand_p
515169689Skanget_phi_result_ptr (tree phi)
516169689Skan{
517169689Skan  return &(PHI_RESULT_TREE (phi));
518169689Skan}
519169689Skan
520169689Skan/* Return a use_operand_p pointer for argument I of phinode PHI.  */
521169689Skanstatic inline use_operand_p
522169689Skanget_phi_arg_def_ptr (tree phi, int i)
523169689Skan{
524169689Skan  return &(PHI_ARG_IMM_USE_NODE (phi,i));
525169689Skan}
526169689Skan
527169689Skan
528169689Skan/* Return the bitmap of addresses taken by STMT, or NULL if it takes
529169689Skan   no addresses.  */
530169689Skanstatic inline bitmap
531169689Skanaddresses_taken (tree stmt)
532169689Skan{
533169689Skan  stmt_ann_t ann = stmt_ann (stmt);
534169689Skan  return ann ? ann->addresses_taken : NULL;
535169689Skan}
536169689Skan
537169689Skan/* Return the PHI nodes for basic block BB, or NULL if there are no
538169689Skan   PHI nodes.  */
539169689Skanstatic inline tree
540169689Skanphi_nodes (basic_block bb)
541169689Skan{
542169689Skan  return bb->phi_nodes;
543169689Skan}
544169689Skan
545169689Skan/* Set list of phi nodes of a basic block BB to L.  */
546169689Skan
547169689Skanstatic inline void
548169689Skanset_phi_nodes (basic_block bb, tree l)
549169689Skan{
550169689Skan  tree phi;
551169689Skan
552169689Skan  bb->phi_nodes = l;
553169689Skan  for (phi = l; phi; phi = PHI_CHAIN (phi))
554169689Skan    set_bb_for_stmt (phi, bb);
555169689Skan}
556169689Skan
557169689Skan/* Return the phi argument which contains the specified use.  */
558169689Skan
559169689Skanstatic inline int
560169689Skanphi_arg_index_from_use (use_operand_p use)
561169689Skan{
562169689Skan  struct phi_arg_d *element, *root;
563169689Skan  int index;
564169689Skan  tree phi;
565169689Skan
566169689Skan  /* Since the use is the first thing in a PHI argument element, we can
567169689Skan     calculate its index based on casting it to an argument, and performing
568169689Skan     pointer arithmetic.  */
569169689Skan
570169689Skan  phi = USE_STMT (use);
571169689Skan  gcc_assert (TREE_CODE (phi) == PHI_NODE);
572169689Skan
573169689Skan  element = (struct phi_arg_d *)use;
574169689Skan  root = &(PHI_ARG_ELT (phi, 0));
575169689Skan  index = element - root;
576169689Skan
577169689Skan#ifdef ENABLE_CHECKING
578169689Skan  /* Make sure the calculation doesn't have any leftover bytes.  If it does,
579169689Skan     then imm_use is likely not the first element in phi_arg_d.  */
580169689Skan  gcc_assert (
581169689Skan	  (((char *)element - (char *)root) % sizeof (struct phi_arg_d)) == 0);
582169689Skan  gcc_assert (index >= 0 && index < PHI_ARG_CAPACITY (phi));
583169689Skan#endif
584169689Skan
585169689Skan return index;
586169689Skan}
587169689Skan
588169689Skan/* Mark VAR as used, so that it'll be preserved during rtl expansion.  */
589169689Skan
590169689Skanstatic inline void
591169689Skanset_is_used (tree var)
592169689Skan{
593169689Skan  var_ann_t ann = get_var_ann (var);
594169689Skan  ann->used = 1;
595169689Skan}
596169689Skan
597169689Skan
598169689Skan/*  -----------------------------------------------------------------------  */
599169689Skan
600169689Skan/* Return true if T is an executable statement.  */
601169689Skanstatic inline bool
602169689Skanis_exec_stmt (tree t)
603169689Skan{
604169689Skan  return (t && !IS_EMPTY_STMT (t) && t != error_mark_node);
605169689Skan}
606169689Skan
607169689Skan
608169689Skan/* Return true if this stmt can be the target of a control transfer stmt such
609169689Skan   as a goto.  */
610169689Skanstatic inline bool
611169689Skanis_label_stmt (tree t)
612169689Skan{
613169689Skan  if (t)
614169689Skan    switch (TREE_CODE (t))
615169689Skan      {
616169689Skan	case LABEL_DECL:
617169689Skan	case LABEL_EXPR:
618169689Skan	case CASE_LABEL_EXPR:
619169689Skan	  return true;
620169689Skan	default:
621169689Skan	  return false;
622169689Skan      }
623169689Skan  return false;
624169689Skan}
625169689Skan
626169689Skan/* PHI nodes should contain only ssa_names and invariants.  A test
627169689Skan   for ssa_name is definitely simpler; don't let invalid contents
628169689Skan   slip in in the meantime.  */
629169689Skan
630169689Skanstatic inline bool
631169689Skanphi_ssa_name_p (tree t)
632169689Skan{
633169689Skan  if (TREE_CODE (t) == SSA_NAME)
634169689Skan    return true;
635169689Skan#ifdef ENABLE_CHECKING
636169689Skan  gcc_assert (is_gimple_min_invariant (t));
637169689Skan#endif
638169689Skan  return false;
639169689Skan}
640169689Skan
641169689Skan/*  -----------------------------------------------------------------------  */
642169689Skan
643169689Skan/* Return a block_stmt_iterator that points to beginning of basic
644169689Skan   block BB.  */
645169689Skanstatic inline block_stmt_iterator
646169689Skanbsi_start (basic_block bb)
647169689Skan{
648169689Skan  block_stmt_iterator bsi;
649169689Skan  if (bb->stmt_list)
650169689Skan    bsi.tsi = tsi_start (bb->stmt_list);
651169689Skan  else
652169689Skan    {
653169689Skan      gcc_assert (bb->index < NUM_FIXED_BLOCKS);
654169689Skan      bsi.tsi.ptr = NULL;
655169689Skan      bsi.tsi.container = NULL;
656169689Skan    }
657169689Skan  bsi.bb = bb;
658169689Skan  return bsi;
659169689Skan}
660169689Skan
661169689Skan/* Return a block statement iterator that points to the first non-label
662169689Skan   statement in block BB.  */
663169689Skan
664169689Skanstatic inline block_stmt_iterator
665169689Skanbsi_after_labels (basic_block bb)
666169689Skan{
667169689Skan  block_stmt_iterator bsi = bsi_start (bb);
668169689Skan
669169689Skan  while (!bsi_end_p (bsi) && TREE_CODE (bsi_stmt (bsi)) == LABEL_EXPR)
670169689Skan    bsi_next (&bsi);
671169689Skan
672169689Skan  return bsi;
673169689Skan}
674169689Skan
675169689Skan/* Return a block statement iterator that points to the end of basic
676169689Skan   block BB.  */
677169689Skanstatic inline block_stmt_iterator
678169689Skanbsi_last (basic_block bb)
679169689Skan{
680169689Skan  block_stmt_iterator bsi;
681169689Skan  if (bb->stmt_list)
682169689Skan    bsi.tsi = tsi_last (bb->stmt_list);
683169689Skan  else
684169689Skan    {
685169689Skan      gcc_assert (bb->index < NUM_FIXED_BLOCKS);
686169689Skan      bsi.tsi.ptr = NULL;
687169689Skan      bsi.tsi.container = NULL;
688169689Skan    }
689169689Skan  bsi.bb = bb;
690169689Skan  return bsi;
691169689Skan}
692169689Skan
693169689Skan/* Return true if block statement iterator I has reached the end of
694169689Skan   the basic block.  */
695169689Skanstatic inline bool
696169689Skanbsi_end_p (block_stmt_iterator i)
697169689Skan{
698169689Skan  return tsi_end_p (i.tsi);
699169689Skan}
700169689Skan
701169689Skan/* Modify block statement iterator I so that it is at the next
702169689Skan   statement in the basic block.  */
703169689Skanstatic inline void
704169689Skanbsi_next (block_stmt_iterator *i)
705169689Skan{
706169689Skan  tsi_next (&i->tsi);
707169689Skan}
708169689Skan
709169689Skan/* Modify block statement iterator I so that it is at the previous
710169689Skan   statement in the basic block.  */
711169689Skanstatic inline void
712169689Skanbsi_prev (block_stmt_iterator *i)
713169689Skan{
714169689Skan  tsi_prev (&i->tsi);
715169689Skan}
716169689Skan
717169689Skan/* Return the statement that block statement iterator I is currently
718169689Skan   at.  */
719169689Skanstatic inline tree
720169689Skanbsi_stmt (block_stmt_iterator i)
721169689Skan{
722169689Skan  return tsi_stmt (i.tsi);
723169689Skan}
724169689Skan
725169689Skan/* Return a pointer to the statement that block statement iterator I
726169689Skan   is currently at.  */
727169689Skanstatic inline tree *
728169689Skanbsi_stmt_ptr (block_stmt_iterator i)
729169689Skan{
730169689Skan  return tsi_stmt_ptr (i.tsi);
731169689Skan}
732169689Skan
733169689Skan/* Returns the loop of the statement STMT.  */
734169689Skan
735169689Skanstatic inline struct loop *
736169689Skanloop_containing_stmt (tree stmt)
737169689Skan{
738169689Skan  basic_block bb = bb_for_stmt (stmt);
739169689Skan  if (!bb)
740169689Skan    return NULL;
741169689Skan
742169689Skan  return bb->loop_father;
743169689Skan}
744169689Skan
745169689Skan/* Return true if VAR is a clobbered by function calls.  */
746169689Skanstatic inline bool
747169689Skanis_call_clobbered (tree var)
748169689Skan{
749169689Skan  if (!MTAG_P (var))
750169689Skan    return DECL_CALL_CLOBBERED (var);
751169689Skan  else
752169689Skan    return bitmap_bit_p (call_clobbered_vars, DECL_UID (var));
753169689Skan}
754169689Skan
755169689Skan/* Mark variable VAR as being clobbered by function calls.  */
756169689Skanstatic inline void
757169689Skanmark_call_clobbered (tree var, unsigned int escape_type)
758169689Skan{
759169689Skan  var_ann (var)->escape_mask |= escape_type;
760169689Skan  if (!MTAG_P (var))
761169689Skan    DECL_CALL_CLOBBERED (var) = true;
762169689Skan  bitmap_set_bit (call_clobbered_vars, DECL_UID (var));
763169689Skan}
764169689Skan
765169689Skan/* Clear the call-clobbered attribute from variable VAR.  */
766169689Skanstatic inline void
767169689Skanclear_call_clobbered (tree var)
768169689Skan{
769169689Skan  var_ann_t ann = var_ann (var);
770169689Skan  ann->escape_mask = 0;
771169689Skan  if (MTAG_P (var) && TREE_CODE (var) != STRUCT_FIELD_TAG)
772169689Skan    MTAG_GLOBAL (var) = 0;
773169689Skan  if (!MTAG_P (var))
774169689Skan    DECL_CALL_CLOBBERED (var) = false;
775169689Skan  bitmap_clear_bit (call_clobbered_vars, DECL_UID (var));
776169689Skan}
777169689Skan
778169689Skan/* Mark variable VAR as being non-addressable.  */
779169689Skanstatic inline void
780169689Skanmark_non_addressable (tree var)
781169689Skan{
782169689Skan  if (!MTAG_P (var))
783169689Skan    DECL_CALL_CLOBBERED (var) = false;
784169689Skan  bitmap_clear_bit (call_clobbered_vars, DECL_UID (var));
785169689Skan  TREE_ADDRESSABLE (var) = 0;
786169689Skan}
787169689Skan
788169689Skan/* Return the common annotation for T.  Return NULL if the annotation
789169689Skan   doesn't already exist.  */
790169689Skanstatic inline tree_ann_common_t
791169689Skantree_common_ann (tree t)
792169689Skan{
793169689Skan  return &t->common.ann->common;
794169689Skan}
795169689Skan
796169689Skan/* Return a common annotation for T.  Create the constant annotation if it
797169689Skan   doesn't exist.  */
798169689Skanstatic inline tree_ann_common_t
799169689Skanget_tree_common_ann (tree t)
800169689Skan{
801169689Skan  tree_ann_common_t ann = tree_common_ann (t);
802169689Skan  return (ann) ? ann : create_tree_common_ann (t);
803169689Skan}
804169689Skan
805169689Skan/*  -----------------------------------------------------------------------  */
806169689Skan
807169689Skan/* The following set of routines are used to iterator over various type of
808169689Skan   SSA operands.  */
809169689Skan
810169689Skan/* Return true if PTR is finished iterating.  */
811169689Skanstatic inline bool
812169689Skanop_iter_done (ssa_op_iter *ptr)
813169689Skan{
814169689Skan  return ptr->done;
815169689Skan}
816169689Skan
817169689Skan/* Get the next iterator use value for PTR.  */
818169689Skanstatic inline use_operand_p
819169689Skanop_iter_next_use (ssa_op_iter *ptr)
820169689Skan{
821169689Skan  use_operand_p use_p;
822169689Skan#ifdef ENABLE_CHECKING
823169689Skan  gcc_assert (ptr->iter_type == ssa_op_iter_use);
824169689Skan#endif
825169689Skan  if (ptr->uses)
826169689Skan    {
827169689Skan      use_p = USE_OP_PTR (ptr->uses);
828169689Skan      ptr->uses = ptr->uses->next;
829169689Skan      return use_p;
830169689Skan    }
831169689Skan  if (ptr->vuses)
832169689Skan    {
833169689Skan      use_p = VUSE_OP_PTR (ptr->vuses);
834169689Skan      ptr->vuses = ptr->vuses->next;
835169689Skan      return use_p;
836169689Skan    }
837169689Skan  if (ptr->mayuses)
838169689Skan    {
839169689Skan      use_p = MAYDEF_OP_PTR (ptr->mayuses);
840169689Skan      ptr->mayuses = ptr->mayuses->next;
841169689Skan      return use_p;
842169689Skan    }
843169689Skan  if (ptr->mustkills)
844169689Skan    {
845169689Skan      use_p = MUSTDEF_KILL_PTR (ptr->mustkills);
846169689Skan      ptr->mustkills = ptr->mustkills->next;
847169689Skan      return use_p;
848169689Skan    }
849169689Skan  if (ptr->phi_i < ptr->num_phi)
850169689Skan    {
851169689Skan      return PHI_ARG_DEF_PTR (ptr->phi_stmt, (ptr->phi_i)++);
852169689Skan    }
853169689Skan  ptr->done = true;
854169689Skan  return NULL_USE_OPERAND_P;
855169689Skan}
856169689Skan
857169689Skan/* Get the next iterator def value for PTR.  */
858169689Skanstatic inline def_operand_p
859169689Skanop_iter_next_def (ssa_op_iter *ptr)
860169689Skan{
861169689Skan  def_operand_p def_p;
862169689Skan#ifdef ENABLE_CHECKING
863169689Skan  gcc_assert (ptr->iter_type == ssa_op_iter_def);
864169689Skan#endif
865169689Skan  if (ptr->defs)
866169689Skan    {
867169689Skan      def_p = DEF_OP_PTR (ptr->defs);
868169689Skan      ptr->defs = ptr->defs->next;
869169689Skan      return def_p;
870169689Skan    }
871169689Skan  if (ptr->mustdefs)
872169689Skan    {
873169689Skan      def_p = MUSTDEF_RESULT_PTR (ptr->mustdefs);
874169689Skan      ptr->mustdefs = ptr->mustdefs->next;
875169689Skan      return def_p;
876169689Skan    }
877169689Skan  if (ptr->maydefs)
878169689Skan    {
879169689Skan      def_p = MAYDEF_RESULT_PTR (ptr->maydefs);
880169689Skan      ptr->maydefs = ptr->maydefs->next;
881169689Skan      return def_p;
882169689Skan    }
883169689Skan  ptr->done = true;
884169689Skan  return NULL_DEF_OPERAND_P;
885169689Skan}
886169689Skan
887169689Skan/* Get the next iterator tree value for PTR.  */
888169689Skanstatic inline tree
889169689Skanop_iter_next_tree (ssa_op_iter *ptr)
890169689Skan{
891169689Skan  tree val;
892169689Skan#ifdef ENABLE_CHECKING
893169689Skan  gcc_assert (ptr->iter_type == ssa_op_iter_tree);
894169689Skan#endif
895169689Skan  if (ptr->uses)
896169689Skan    {
897169689Skan      val = USE_OP (ptr->uses);
898169689Skan      ptr->uses = ptr->uses->next;
899169689Skan      return val;
900169689Skan    }
901169689Skan  if (ptr->vuses)
902169689Skan    {
903169689Skan      val = VUSE_OP (ptr->vuses);
904169689Skan      ptr->vuses = ptr->vuses->next;
905169689Skan      return val;
906169689Skan    }
907169689Skan  if (ptr->mayuses)
908169689Skan    {
909169689Skan      val = MAYDEF_OP (ptr->mayuses);
910169689Skan      ptr->mayuses = ptr->mayuses->next;
911169689Skan      return val;
912169689Skan    }
913169689Skan  if (ptr->mustkills)
914169689Skan    {
915169689Skan      val = MUSTDEF_KILL (ptr->mustkills);
916169689Skan      ptr->mustkills = ptr->mustkills->next;
917169689Skan      return val;
918169689Skan    }
919169689Skan  if (ptr->defs)
920169689Skan    {
921169689Skan      val = DEF_OP (ptr->defs);
922169689Skan      ptr->defs = ptr->defs->next;
923169689Skan      return val;
924169689Skan    }
925169689Skan  if (ptr->mustdefs)
926169689Skan    {
927169689Skan      val = MUSTDEF_RESULT (ptr->mustdefs);
928169689Skan      ptr->mustdefs = ptr->mustdefs->next;
929169689Skan      return val;
930169689Skan    }
931169689Skan  if (ptr->maydefs)
932169689Skan    {
933169689Skan      val = MAYDEF_RESULT (ptr->maydefs);
934169689Skan      ptr->maydefs = ptr->maydefs->next;
935169689Skan      return val;
936169689Skan    }
937169689Skan
938169689Skan  ptr->done = true;
939169689Skan  return NULL_TREE;
940169689Skan
941169689Skan}
942169689Skan
943169689Skan
944169689Skan/* This functions clears the iterator PTR, and marks it done.  This is normally
945169689Skan   used to prevent warnings in the compile about might be uninitialized
946169689Skan   components.  */
947169689Skan
948169689Skanstatic inline void
949169689Skanclear_and_done_ssa_iter (ssa_op_iter *ptr)
950169689Skan{
951169689Skan  ptr->defs = NULL;
952169689Skan  ptr->uses = NULL;
953169689Skan  ptr->vuses = NULL;
954169689Skan  ptr->maydefs = NULL;
955169689Skan  ptr->mayuses = NULL;
956169689Skan  ptr->mustdefs = NULL;
957169689Skan  ptr->mustkills = NULL;
958169689Skan  ptr->iter_type = ssa_op_iter_none;
959169689Skan  ptr->phi_i = 0;
960169689Skan  ptr->num_phi = 0;
961169689Skan  ptr->phi_stmt = NULL_TREE;
962169689Skan  ptr->done = true;
963169689Skan}
964169689Skan
965169689Skan/* Initialize the iterator PTR to the virtual defs in STMT.  */
966169689Skanstatic inline void
967169689Skanop_iter_init (ssa_op_iter *ptr, tree stmt, int flags)
968169689Skan{
969169689Skan#ifdef ENABLE_CHECKING
970169689Skan  gcc_assert (stmt_ann (stmt));
971169689Skan#endif
972169689Skan
973169689Skan  ptr->defs = (flags & SSA_OP_DEF) ? DEF_OPS (stmt) : NULL;
974169689Skan  ptr->uses = (flags & SSA_OP_USE) ? USE_OPS (stmt) : NULL;
975169689Skan  ptr->vuses = (flags & SSA_OP_VUSE) ? VUSE_OPS (stmt) : NULL;
976169689Skan  ptr->maydefs = (flags & SSA_OP_VMAYDEF) ? MAYDEF_OPS (stmt) : NULL;
977169689Skan  ptr->mayuses = (flags & SSA_OP_VMAYUSE) ? MAYDEF_OPS (stmt) : NULL;
978169689Skan  ptr->mustdefs = (flags & SSA_OP_VMUSTDEF) ? MUSTDEF_OPS (stmt) : NULL;
979169689Skan  ptr->mustkills = (flags & SSA_OP_VMUSTKILL) ? MUSTDEF_OPS (stmt) : NULL;
980169689Skan  ptr->done = false;
981169689Skan
982169689Skan  ptr->phi_i = 0;
983169689Skan  ptr->num_phi = 0;
984169689Skan  ptr->phi_stmt = NULL_TREE;
985169689Skan}
986169689Skan
987169689Skan/* Initialize iterator PTR to the use operands in STMT based on FLAGS. Return
988169689Skan   the first use.  */
989169689Skanstatic inline use_operand_p
990169689Skanop_iter_init_use (ssa_op_iter *ptr, tree stmt, int flags)
991169689Skan{
992169689Skan  gcc_assert ((flags & SSA_OP_ALL_DEFS) == 0);
993169689Skan  op_iter_init (ptr, stmt, flags);
994169689Skan  ptr->iter_type = ssa_op_iter_use;
995169689Skan  return op_iter_next_use (ptr);
996169689Skan}
997169689Skan
998169689Skan/* Initialize iterator PTR to the def operands in STMT based on FLAGS. Return
999169689Skan   the first def.  */
1000169689Skanstatic inline def_operand_p
1001169689Skanop_iter_init_def (ssa_op_iter *ptr, tree stmt, int flags)
1002169689Skan{
1003169689Skan  gcc_assert ((flags & (SSA_OP_ALL_USES | SSA_OP_VIRTUAL_KILLS)) == 0);
1004169689Skan  op_iter_init (ptr, stmt, flags);
1005169689Skan  ptr->iter_type = ssa_op_iter_def;
1006169689Skan  return op_iter_next_def (ptr);
1007169689Skan}
1008169689Skan
1009169689Skan/* Initialize iterator PTR to the operands in STMT based on FLAGS. Return
1010169689Skan   the first operand as a tree.  */
1011169689Skanstatic inline tree
1012169689Skanop_iter_init_tree (ssa_op_iter *ptr, tree stmt, int flags)
1013169689Skan{
1014169689Skan  op_iter_init (ptr, stmt, flags);
1015169689Skan  ptr->iter_type = ssa_op_iter_tree;
1016169689Skan  return op_iter_next_tree (ptr);
1017169689Skan}
1018169689Skan
1019169689Skan/* Get the next iterator mustdef value for PTR, returning the mustdef values in
1020169689Skan   KILL and DEF.  */
1021169689Skanstatic inline void
1022169689Skanop_iter_next_maymustdef (use_operand_p *use, def_operand_p *def,
1023169689Skan			 ssa_op_iter *ptr)
1024169689Skan{
1025169689Skan#ifdef ENABLE_CHECKING
1026169689Skan  gcc_assert (ptr->iter_type == ssa_op_iter_maymustdef);
1027169689Skan#endif
1028169689Skan  if (ptr->mayuses)
1029169689Skan    {
1030169689Skan      *def = MAYDEF_RESULT_PTR (ptr->mayuses);
1031169689Skan      *use = MAYDEF_OP_PTR (ptr->mayuses);
1032169689Skan      ptr->mayuses = ptr->mayuses->next;
1033169689Skan      return;
1034169689Skan    }
1035169689Skan
1036169689Skan  if (ptr->mustkills)
1037169689Skan    {
1038169689Skan      *def = MUSTDEF_RESULT_PTR (ptr->mustkills);
1039169689Skan      *use = MUSTDEF_KILL_PTR (ptr->mustkills);
1040169689Skan      ptr->mustkills = ptr->mustkills->next;
1041169689Skan      return;
1042169689Skan    }
1043169689Skan
1044169689Skan  *def = NULL_DEF_OPERAND_P;
1045169689Skan  *use = NULL_USE_OPERAND_P;
1046169689Skan  ptr->done = true;
1047169689Skan  return;
1048169689Skan}
1049169689Skan
1050169689Skan
1051169689Skan/* Initialize iterator PTR to the operands in STMT.  Return the first operands
1052169689Skan   in USE and DEF.  */
1053169689Skanstatic inline void
1054169689Skanop_iter_init_maydef (ssa_op_iter *ptr, tree stmt, use_operand_p *use,
1055169689Skan		     def_operand_p *def)
1056169689Skan{
1057169689Skan  gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1058169689Skan
1059169689Skan  op_iter_init (ptr, stmt, SSA_OP_VMAYUSE);
1060169689Skan  ptr->iter_type = ssa_op_iter_maymustdef;
1061169689Skan  op_iter_next_maymustdef (use, def, ptr);
1062169689Skan}
1063169689Skan
1064169689Skan
1065169689Skan/* Initialize iterator PTR to the operands in STMT.  Return the first operands
1066169689Skan   in KILL and DEF.  */
1067169689Skanstatic inline void
1068169689Skanop_iter_init_mustdef (ssa_op_iter *ptr, tree stmt, use_operand_p *kill,
1069169689Skan		     def_operand_p *def)
1070169689Skan{
1071169689Skan  gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1072169689Skan
1073169689Skan  op_iter_init (ptr, stmt, SSA_OP_VMUSTKILL);
1074169689Skan  ptr->iter_type = ssa_op_iter_maymustdef;
1075169689Skan  op_iter_next_maymustdef (kill, def, ptr);
1076169689Skan}
1077169689Skan
1078169689Skan/* Initialize iterator PTR to the operands in STMT.  Return the first operands
1079169689Skan   in KILL and DEF.  */
1080169689Skanstatic inline void
1081169689Skanop_iter_init_must_and_may_def (ssa_op_iter *ptr, tree stmt,
1082169689Skan			       use_operand_p *kill, def_operand_p *def)
1083169689Skan{
1084169689Skan  gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1085169689Skan
1086169689Skan  op_iter_init (ptr, stmt, SSA_OP_VMUSTKILL|SSA_OP_VMAYUSE);
1087169689Skan  ptr->iter_type = ssa_op_iter_maymustdef;
1088169689Skan  op_iter_next_maymustdef (kill, def, ptr);
1089169689Skan}
1090169689Skan
1091169689Skan
1092169689Skan/* If there is a single operand in STMT matching FLAGS, return it.  Otherwise
1093169689Skan   return NULL.  */
1094169689Skanstatic inline tree
1095169689Skansingle_ssa_tree_operand (tree stmt, int flags)
1096169689Skan{
1097169689Skan  tree var;
1098169689Skan  ssa_op_iter iter;
1099169689Skan
1100169689Skan  var = op_iter_init_tree (&iter, stmt, flags);
1101169689Skan  if (op_iter_done (&iter))
1102169689Skan    return NULL_TREE;
1103169689Skan  op_iter_next_tree (&iter);
1104169689Skan  if (op_iter_done (&iter))
1105169689Skan    return var;
1106169689Skan  return NULL_TREE;
1107169689Skan}
1108169689Skan
1109169689Skan
1110169689Skan/* If there is a single operand in STMT matching FLAGS, return it.  Otherwise
1111169689Skan   return NULL.  */
1112169689Skanstatic inline use_operand_p
1113169689Skansingle_ssa_use_operand (tree stmt, int flags)
1114169689Skan{
1115169689Skan  use_operand_p var;
1116169689Skan  ssa_op_iter iter;
1117169689Skan
1118169689Skan  var = op_iter_init_use (&iter, stmt, flags);
1119169689Skan  if (op_iter_done (&iter))
1120169689Skan    return NULL_USE_OPERAND_P;
1121169689Skan  op_iter_next_use (&iter);
1122169689Skan  if (op_iter_done (&iter))
1123169689Skan    return var;
1124169689Skan  return NULL_USE_OPERAND_P;
1125169689Skan}
1126169689Skan
1127169689Skan
1128169689Skan
1129169689Skan/* If there is a single operand in STMT matching FLAGS, return it.  Otherwise
1130169689Skan   return NULL.  */
1131169689Skanstatic inline def_operand_p
1132169689Skansingle_ssa_def_operand (tree stmt, int flags)
1133169689Skan{
1134169689Skan  def_operand_p var;
1135169689Skan  ssa_op_iter iter;
1136169689Skan
1137169689Skan  var = op_iter_init_def (&iter, stmt, flags);
1138169689Skan  if (op_iter_done (&iter))
1139169689Skan    return NULL_DEF_OPERAND_P;
1140169689Skan  op_iter_next_def (&iter);
1141169689Skan  if (op_iter_done (&iter))
1142169689Skan    return var;
1143169689Skan  return NULL_DEF_OPERAND_P;
1144169689Skan}
1145169689Skan
1146169689Skan
1147169689Skan/* Return true if there are zero operands in STMT matching the type
1148169689Skan   given in FLAGS.  */
1149169689Skanstatic inline bool
1150169689Skanzero_ssa_operands (tree stmt, int flags)
1151169689Skan{
1152169689Skan  ssa_op_iter iter;
1153169689Skan
1154169689Skan  op_iter_init_tree (&iter, stmt, flags);
1155169689Skan  return op_iter_done (&iter);
1156169689Skan}
1157169689Skan
1158169689Skan
1159169689Skan/* Return the number of operands matching FLAGS in STMT.  */
1160169689Skanstatic inline int
1161169689Skannum_ssa_operands (tree stmt, int flags)
1162169689Skan{
1163169689Skan  ssa_op_iter iter;
1164169689Skan  tree t;
1165169689Skan  int num = 0;
1166169689Skan
1167169689Skan  FOR_EACH_SSA_TREE_OPERAND (t, stmt, iter, flags)
1168169689Skan    num++;
1169169689Skan  return num;
1170169689Skan}
1171169689Skan
1172169689Skan
1173169689Skan/* Delink all immediate_use information for STMT.  */
1174169689Skanstatic inline void
1175169689Skandelink_stmt_imm_use (tree stmt)
1176169689Skan{
1177169689Skan   ssa_op_iter iter;
1178169689Skan   use_operand_p use_p;
1179169689Skan
1180169689Skan   if (ssa_operands_active ())
1181169689Skan     FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter,
1182169689Skan			       (SSA_OP_ALL_USES | SSA_OP_ALL_KILLS))
1183169689Skan       delink_imm_use (use_p);
1184169689Skan}
1185169689Skan
1186169689Skan
1187169689Skan/* This routine will compare all the operands matching FLAGS in STMT1 to those
1188169689Skan   in STMT2.  TRUE is returned if they are the same.  STMTs can be NULL.  */
1189169689Skanstatic inline bool
1190169689Skancompare_ssa_operands_equal (tree stmt1, tree stmt2, int flags)
1191169689Skan{
1192169689Skan  ssa_op_iter iter1, iter2;
1193169689Skan  tree op1 = NULL_TREE;
1194169689Skan  tree op2 = NULL_TREE;
1195169689Skan  bool look1, look2;
1196169689Skan
1197169689Skan  if (stmt1 == stmt2)
1198169689Skan    return true;
1199169689Skan
1200169689Skan  look1 = stmt1 && stmt_ann (stmt1);
1201169689Skan  look2 = stmt2 && stmt_ann (stmt2);
1202169689Skan
1203169689Skan  if (look1)
1204169689Skan    {
1205169689Skan      op1 = op_iter_init_tree (&iter1, stmt1, flags);
1206169689Skan      if (!look2)
1207169689Skan        return op_iter_done (&iter1);
1208169689Skan    }
1209169689Skan  else
1210169689Skan    clear_and_done_ssa_iter (&iter1);
1211169689Skan
1212169689Skan  if (look2)
1213169689Skan    {
1214169689Skan      op2 = op_iter_init_tree (&iter2, stmt2, flags);
1215169689Skan      if (!look1)
1216169689Skan        return op_iter_done (&iter2);
1217169689Skan    }
1218169689Skan  else
1219169689Skan    clear_and_done_ssa_iter (&iter2);
1220169689Skan
1221169689Skan  while (!op_iter_done (&iter1) && !op_iter_done (&iter2))
1222169689Skan    {
1223169689Skan      if (op1 != op2)
1224169689Skan	return false;
1225169689Skan      op1 = op_iter_next_tree (&iter1);
1226169689Skan      op2 = op_iter_next_tree (&iter2);
1227169689Skan    }
1228169689Skan
1229169689Skan  return (op_iter_done (&iter1) && op_iter_done (&iter2));
1230169689Skan}
1231169689Skan
1232169689Skan
1233169689Skan/* If there is a single DEF in the PHI node which matches FLAG, return it.
1234169689Skan   Otherwise return NULL_DEF_OPERAND_P.  */
1235169689Skanstatic inline tree
1236169689Skansingle_phi_def (tree stmt, int flags)
1237169689Skan{
1238169689Skan  tree def = PHI_RESULT (stmt);
1239169689Skan  if ((flags & SSA_OP_DEF) && is_gimple_reg (def))
1240169689Skan    return def;
1241169689Skan  if ((flags & SSA_OP_VIRTUAL_DEFS) && !is_gimple_reg (def))
1242169689Skan    return def;
1243169689Skan  return NULL_TREE;
1244169689Skan}
1245169689Skan
1246169689Skan/* Initialize the iterator PTR for uses matching FLAGS in PHI.  FLAGS should
1247169689Skan   be either SSA_OP_USES or SSA_OP_VIRTUAL_USES.  */
1248169689Skanstatic inline use_operand_p
1249169689Skanop_iter_init_phiuse (ssa_op_iter *ptr, tree phi, int flags)
1250169689Skan{
1251169689Skan  tree phi_def = PHI_RESULT (phi);
1252169689Skan  int comp;
1253169689Skan
1254169689Skan  clear_and_done_ssa_iter (ptr);
1255169689Skan  ptr->done = false;
1256169689Skan
1257169689Skan  gcc_assert ((flags & (SSA_OP_USE | SSA_OP_VIRTUAL_USES)) != 0);
1258169689Skan
1259169689Skan  comp = (is_gimple_reg (phi_def) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
1260169689Skan
1261169689Skan  /* If the PHI node doesn't the operand type we care about, we're done.  */
1262169689Skan  if ((flags & comp) == 0)
1263169689Skan    {
1264169689Skan      ptr->done = true;
1265169689Skan      return NULL_USE_OPERAND_P;
1266169689Skan    }
1267169689Skan
1268169689Skan  ptr->phi_stmt = phi;
1269169689Skan  ptr->num_phi = PHI_NUM_ARGS (phi);
1270169689Skan  ptr->iter_type = ssa_op_iter_use;
1271169689Skan  return op_iter_next_use (ptr);
1272169689Skan}
1273169689Skan
1274169689Skan
1275169689Skan/* Start an iterator for a PHI definition.  */
1276169689Skan
1277169689Skanstatic inline def_operand_p
1278169689Skanop_iter_init_phidef (ssa_op_iter *ptr, tree phi, int flags)
1279169689Skan{
1280169689Skan  tree phi_def = PHI_RESULT (phi);
1281169689Skan  int comp;
1282169689Skan
1283169689Skan  clear_and_done_ssa_iter (ptr);
1284169689Skan  ptr->done = false;
1285169689Skan
1286169689Skan  gcc_assert ((flags & (SSA_OP_DEF | SSA_OP_VIRTUAL_DEFS)) != 0);
1287169689Skan
1288169689Skan  comp = (is_gimple_reg (phi_def) ? SSA_OP_DEF : SSA_OP_VIRTUAL_DEFS);
1289169689Skan
1290169689Skan  /* If the PHI node doesn't the operand type we care about, we're done.  */
1291169689Skan  if ((flags & comp) == 0)
1292169689Skan    {
1293169689Skan      ptr->done = true;
1294169689Skan      return NULL_USE_OPERAND_P;
1295169689Skan    }
1296169689Skan
1297169689Skan  ptr->iter_type = ssa_op_iter_def;
1298169689Skan  /* The first call to op_iter_next_def will terminate the iterator since
1299169689Skan     all the fields are NULL.  Simply return the result here as the first and
1300169689Skan     therefore only result.  */
1301169689Skan  return PHI_RESULT_PTR (phi);
1302169689Skan}
1303169689Skan
1304169689Skan/* Return true is IMM has reached the end of the immediate use stmt list.  */
1305169689Skan
1306169689Skanstatic inline bool
1307169689Skanend_imm_use_stmt_p (imm_use_iterator *imm)
1308169689Skan{
1309169689Skan  return (imm->imm_use == imm->end_p);
1310169689Skan}
1311169689Skan
1312169689Skan/* Finished the traverse of an immediate use stmt list IMM by removing the
1313169689Skan   placeholder node from the list.  */
1314169689Skan
1315169689Skanstatic inline void
1316169689Skanend_imm_use_stmt_traverse (imm_use_iterator *imm)
1317169689Skan{
1318169689Skan  delink_imm_use (&(imm->iter_node));
1319169689Skan}
1320169689Skan
1321169689Skan/* Immediate use traversal of uses within a stmt require that all the
1322169689Skan   uses on a stmt be sequentially listed.  This routine is used to build up
1323169689Skan   this sequential list by adding USE_P to the end of the current list
1324169689Skan   currently delimited by HEAD and LAST_P.  The new LAST_P value is
1325169689Skan   returned.  */
1326169689Skan
1327169689Skanstatic inline use_operand_p
1328169689Skanmove_use_after_head (use_operand_p use_p, use_operand_p head,
1329169689Skan		      use_operand_p last_p)
1330169689Skan{
1331169689Skan  gcc_assert (USE_FROM_PTR (use_p) == USE_FROM_PTR (head));
1332169689Skan  /* Skip head when we find it.  */
1333169689Skan  if (use_p != head)
1334169689Skan    {
1335169689Skan      /* If use_p is already linked in after last_p, continue.  */
1336169689Skan      if (last_p->next == use_p)
1337169689Skan	last_p = use_p;
1338169689Skan      else
1339169689Skan	{
1340169689Skan	  /* Delink from current location, and link in at last_p.  */
1341169689Skan	  delink_imm_use (use_p);
1342169689Skan	  link_imm_use_to_list (use_p, last_p);
1343169689Skan	  last_p = use_p;
1344169689Skan	}
1345169689Skan    }
1346169689Skan  return last_p;
1347169689Skan}
1348169689Skan
1349169689Skan
1350169689Skan/* This routine will relink all uses with the same stmt as HEAD into the list
1351169689Skan   immediately following HEAD for iterator IMM.  */
1352169689Skan
1353169689Skanstatic inline void
1354169689Skanlink_use_stmts_after (use_operand_p head, imm_use_iterator *imm)
1355169689Skan{
1356169689Skan  use_operand_p use_p;
1357169689Skan  use_operand_p last_p = head;
1358169689Skan  tree head_stmt = USE_STMT (head);
1359169689Skan  tree use = USE_FROM_PTR (head);
1360169689Skan  ssa_op_iter op_iter;
1361169689Skan  int flag;
1362169689Skan
1363169689Skan  /* Only look at virtual or real uses, depending on the type of HEAD.  */
1364169689Skan  flag = (is_gimple_reg (use) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
1365169689Skan
1366169689Skan  if (TREE_CODE (head_stmt) == PHI_NODE)
1367169689Skan    {
1368169689Skan      FOR_EACH_PHI_ARG (use_p, head_stmt, op_iter, flag)
1369169689Skan	if (USE_FROM_PTR (use_p) == use)
1370169689Skan	  last_p = move_use_after_head (use_p, head, last_p);
1371169689Skan    }
1372169689Skan  else
1373169689Skan    {
1374169689Skan      FOR_EACH_SSA_USE_OPERAND (use_p, head_stmt, op_iter, flag)
1375169689Skan	if (USE_FROM_PTR (use_p) == use)
1376169689Skan	  last_p = move_use_after_head (use_p, head, last_p);
1377169689Skan    }
1378169689Skan  /* LInk iter node in after last_p.  */
1379169689Skan  if (imm->iter_node.prev != NULL)
1380169689Skan    delink_imm_use (&imm->iter_node);
1381169689Skan  link_imm_use_to_list (&(imm->iter_node), last_p);
1382169689Skan}
1383169689Skan
1384169689Skan/* Initialize IMM to traverse over uses of VAR.  Return the first statement.  */
1385169689Skanstatic inline tree
1386169689Skanfirst_imm_use_stmt (imm_use_iterator *imm, tree var)
1387169689Skan{
1388169689Skan  gcc_assert (TREE_CODE (var) == SSA_NAME);
1389169689Skan
1390169689Skan  imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
1391169689Skan  imm->imm_use = imm->end_p->next;
1392169689Skan  imm->next_imm_name = NULL_USE_OPERAND_P;
1393169689Skan
1394169689Skan  /* iter_node is used as a marker within the immediate use list to indicate
1395169689Skan     where the end of the current stmt's uses are.  Initialize it to NULL
1396169689Skan     stmt and use, which indicates a marker node.  */
1397169689Skan  imm->iter_node.prev = NULL_USE_OPERAND_P;
1398169689Skan  imm->iter_node.next = NULL_USE_OPERAND_P;
1399169689Skan  imm->iter_node.stmt = NULL_TREE;
1400169689Skan  imm->iter_node.use = NULL_USE_OPERAND_P;
1401169689Skan
1402169689Skan  if (end_imm_use_stmt_p (imm))
1403169689Skan    return NULL_TREE;
1404169689Skan
1405169689Skan  link_use_stmts_after (imm->imm_use, imm);
1406169689Skan
1407169689Skan  return USE_STMT (imm->imm_use);
1408169689Skan}
1409169689Skan
1410169689Skan/* Bump IMM to the next stmt which has a use of var.  */
1411169689Skan
1412169689Skanstatic inline tree
1413169689Skannext_imm_use_stmt (imm_use_iterator *imm)
1414169689Skan{
1415169689Skan  imm->imm_use = imm->iter_node.next;
1416169689Skan  if (end_imm_use_stmt_p (imm))
1417169689Skan    {
1418169689Skan      if (imm->iter_node.prev != NULL)
1419169689Skan	delink_imm_use (&imm->iter_node);
1420169689Skan      return NULL_TREE;
1421169689Skan    }
1422169689Skan
1423169689Skan  link_use_stmts_after (imm->imm_use, imm);
1424169689Skan  return USE_STMT (imm->imm_use);
1425169689Skan
1426169689Skan}
1427169689Skan
1428169689Skan/* This routine will return the first use on the stmt IMM currently refers
1429169689Skan   to.  */
1430169689Skan
1431169689Skanstatic inline use_operand_p
1432169689Skanfirst_imm_use_on_stmt (imm_use_iterator *imm)
1433169689Skan{
1434169689Skan  imm->next_imm_name = imm->imm_use->next;
1435169689Skan  return imm->imm_use;
1436169689Skan}
1437169689Skan
1438169689Skan/*  Return TRUE if the last use on the stmt IMM refers to has been visited.  */
1439169689Skan
1440169689Skanstatic inline bool
1441169689Skanend_imm_use_on_stmt_p (imm_use_iterator *imm)
1442169689Skan{
1443169689Skan  return (imm->imm_use == &(imm->iter_node));
1444169689Skan}
1445169689Skan
1446169689Skan/* Bump to the next use on the stmt IMM refers to, return NULL if done.  */
1447169689Skan
1448169689Skanstatic inline use_operand_p
1449169689Skannext_imm_use_on_stmt (imm_use_iterator *imm)
1450169689Skan{
1451169689Skan  imm->imm_use = imm->next_imm_name;
1452169689Skan  if (end_imm_use_on_stmt_p (imm))
1453169689Skan    return NULL_USE_OPERAND_P;
1454169689Skan  else
1455169689Skan    {
1456169689Skan      imm->next_imm_name = imm->imm_use->next;
1457169689Skan      return imm->imm_use;
1458169689Skan    }
1459169689Skan}
1460169689Skan
1461169689Skan/* Return true if VAR cannot be modified by the program.  */
1462169689Skan
1463169689Skanstatic inline bool
1464169689Skanunmodifiable_var_p (tree var)
1465169689Skan{
1466169689Skan  if (TREE_CODE (var) == SSA_NAME)
1467169689Skan    var = SSA_NAME_VAR (var);
1468169689Skan
1469169689Skan  if (MTAG_P (var))
1470169689Skan    return TREE_READONLY (var) && (TREE_STATIC (var) || MTAG_GLOBAL (var));
1471169689Skan
1472169689Skan  return TREE_READONLY (var) && (TREE_STATIC (var) || DECL_EXTERNAL (var));
1473169689Skan}
1474169689Skan
1475169689Skan/* Return true if REF, an ARRAY_REF, has an INDIRECT_REF somewhere in it.  */
1476169689Skan
1477169689Skanstatic inline bool
1478169689Skanarray_ref_contains_indirect_ref (tree ref)
1479169689Skan{
1480169689Skan  gcc_assert (TREE_CODE (ref) == ARRAY_REF);
1481169689Skan
1482169689Skan  do {
1483169689Skan    ref = TREE_OPERAND (ref, 0);
1484169689Skan  } while (handled_component_p (ref));
1485169689Skan
1486169689Skan  return TREE_CODE (ref) == INDIRECT_REF;
1487169689Skan}
1488169689Skan
1489169689Skan/* Return true if REF, a handled component reference, has an ARRAY_REF
1490169689Skan   somewhere in it.  */
1491169689Skan
1492169689Skanstatic inline bool
1493169689Skanref_contains_array_ref (tree ref)
1494169689Skan{
1495169689Skan  gcc_assert (handled_component_p (ref));
1496169689Skan
1497169689Skan  do {
1498169689Skan    if (TREE_CODE (ref) == ARRAY_REF)
1499169689Skan      return true;
1500169689Skan    ref = TREE_OPERAND (ref, 0);
1501169689Skan  } while (handled_component_p (ref));
1502169689Skan
1503169689Skan  return false;
1504169689Skan}
1505169689Skan
1506169689Skan/* Given a variable VAR, lookup and return a pointer to the list of
1507169689Skan   subvariables for it.  */
1508169689Skan
1509169689Skanstatic inline subvar_t *
1510169689Skanlookup_subvars_for_var (tree var)
1511169689Skan{
1512169689Skan  var_ann_t ann = var_ann (var);
1513169689Skan  gcc_assert (ann);
1514169689Skan  return &ann->subvars;
1515169689Skan}
1516169689Skan
1517169689Skan/* Given a variable VAR, return a linked list of subvariables for VAR, or
1518169689Skan   NULL, if there are no subvariables.  */
1519169689Skan
1520169689Skanstatic inline subvar_t
1521169689Skanget_subvars_for_var (tree var)
1522169689Skan{
1523169689Skan  subvar_t subvars;
1524169689Skan
1525169689Skan  gcc_assert (SSA_VAR_P (var));
1526169689Skan
1527169689Skan  if (TREE_CODE (var) == SSA_NAME)
1528169689Skan    subvars = *(lookup_subvars_for_var (SSA_NAME_VAR (var)));
1529169689Skan  else
1530169689Skan    subvars = *(lookup_subvars_for_var (var));
1531169689Skan  return subvars;
1532169689Skan}
1533169689Skan
1534169689Skan/* Return the subvariable of VAR at offset OFFSET.  */
1535169689Skan
1536169689Skanstatic inline tree
1537169689Skanget_subvar_at (tree var, unsigned HOST_WIDE_INT offset)
1538169689Skan{
1539169689Skan  subvar_t sv;
1540169689Skan
1541169689Skan  for (sv = get_subvars_for_var (var); sv; sv = sv->next)
1542169689Skan    if (SFT_OFFSET (sv->var) == offset)
1543169689Skan      return sv->var;
1544169689Skan
1545169689Skan  return NULL_TREE;
1546169689Skan}
1547169689Skan
1548169689Skan/* Return true if V is a tree that we can have subvars for.
1549169689Skan   Normally, this is any aggregate type.  Also complex
1550169689Skan   types which are not gimple registers can have subvars.  */
1551169689Skan
1552169689Skanstatic inline bool
1553169689Skanvar_can_have_subvars (tree v)
1554169689Skan{
1555169689Skan  /* Volatile variables should never have subvars.  */
1556169689Skan  if (TREE_THIS_VOLATILE (v))
1557169689Skan    return false;
1558169689Skan
1559169689Skan  /* Non decls or memory tags can never have subvars.  */
1560169689Skan  if (!DECL_P (v) || MTAG_P (v))
1561169689Skan    return false;
1562169689Skan
1563169689Skan  /* Aggregates can have subvars.  */
1564169689Skan  if (AGGREGATE_TYPE_P (TREE_TYPE (v)))
1565169689Skan    return true;
1566169689Skan
1567169689Skan  /* Complex types variables which are not also a gimple register can
1568169689Skan    have subvars. */
1569169689Skan  if (TREE_CODE (TREE_TYPE (v)) == COMPLEX_TYPE
1570169689Skan      && !DECL_COMPLEX_GIMPLE_REG_P (v))
1571169689Skan    return true;
1572169689Skan
1573169689Skan  return false;
1574169689Skan}
1575169689Skan
1576169689Skan
1577169689Skan/* Return true if OFFSET and SIZE define a range that overlaps with some
1578169689Skan   portion of the range of SV, a subvar.  If there was an exact overlap,
1579169689Skan   *EXACT will be set to true upon return. */
1580169689Skan
1581169689Skanstatic inline bool
1582169689Skanoverlap_subvar (unsigned HOST_WIDE_INT offset, unsigned HOST_WIDE_INT size,
1583169689Skan		tree sv,  bool *exact)
1584169689Skan{
1585169689Skan  /* There are three possible cases of overlap.
1586169689Skan     1. We can have an exact overlap, like so:
1587169689Skan     |offset, offset + size             |
1588169689Skan     |sv->offset, sv->offset + sv->size |
1589169689Skan
1590169689Skan     2. We can have offset starting after sv->offset, like so:
1591169689Skan
1592169689Skan           |offset, offset + size              |
1593169689Skan     |sv->offset, sv->offset + sv->size  |
1594169689Skan
1595169689Skan     3. We can have offset starting before sv->offset, like so:
1596169689Skan
1597169689Skan     |offset, offset + size    |
1598169689Skan       |sv->offset, sv->offset + sv->size|
1599169689Skan  */
1600169689Skan
1601169689Skan  if (exact)
1602169689Skan    *exact = false;
1603169689Skan  if (offset == SFT_OFFSET (sv) && size == SFT_SIZE (sv))
1604169689Skan    {
1605169689Skan      if (exact)
1606169689Skan	*exact = true;
1607169689Skan      return true;
1608169689Skan    }
1609169689Skan  else if (offset >= SFT_OFFSET (sv)
1610169689Skan	   && offset < (SFT_OFFSET (sv) + SFT_SIZE (sv)))
1611169689Skan    {
1612169689Skan      return true;
1613169689Skan    }
1614169689Skan  else if (offset < SFT_OFFSET (sv)
1615169689Skan	   && (size > SFT_OFFSET (sv) - offset))
1616169689Skan    {
1617169689Skan      return true;
1618169689Skan    }
1619169689Skan  return false;
1620169689Skan
1621169689Skan}
1622169689Skan
1623169689Skan#endif /* _TREE_FLOW_INLINE_H  */
1624