OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.2.2/] [gcc/] [tree-flow-inline.h] - Blame information for rev 199

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 38 julius
/* Inline functions for tree-flow.h
2
   Copyright (C) 2001, 2003, 2005, 2006, 2007 Free Software Foundation, Inc.
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
9
the Free Software Foundation; either version 3, or (at your option)
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
18
along with GCC; see the file COPYING3.  If not see
19
<http://www.gnu.org/licenses/>.  */
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
 
27
/* Initialize the hashtable iterator HTI to point to hashtable TABLE */
28
 
29
static inline void *
30
first_htab_element (htab_iterator *hti, htab_t table)
31
{
32
  hti->htab = table;
33
  hti->slot = table->entries;
34
  hti->limit = hti->slot + htab_size (table);
35
  do
36
    {
37
      PTR x = *(hti->slot);
38
      if (x != HTAB_EMPTY_ENTRY && x != HTAB_DELETED_ENTRY)
39
        break;
40
    } while (++(hti->slot) < hti->limit);
41
 
42
  if (hti->slot < hti->limit)
43
    return *(hti->slot);
44
  return NULL;
45
}
46
 
47
/* Return current non-empty/deleted slot of the hashtable pointed to by HTI,
48
   or NULL if we have  reached the end.  */
49
 
50
static inline bool
51
end_htab_p (htab_iterator *hti)
52
{
53
  if (hti->slot >= hti->limit)
54
    return true;
55
  return false;
56
}
57
 
58
/* Advance the hashtable iterator pointed to by HTI to the next element of the
59
   hashtable.  */
60
 
61
static inline void *
62
next_htab_element (htab_iterator *hti)
63
{
64
  while (++(hti->slot) < hti->limit)
65
    {
66
      PTR x = *(hti->slot);
67
      if (x != HTAB_EMPTY_ENTRY && x != HTAB_DELETED_ENTRY)
68
        return x;
69
    };
70
  return NULL;
71
}
72
 
73
/* Initialize ITER to point to the first referenced variable in the
74
   referenced_vars hashtable, and return that variable.  */
75
 
76
static inline tree
77
first_referenced_var (referenced_var_iterator *iter)
78
{
79
  struct int_tree_map *itm;
80
  itm = (struct int_tree_map *) first_htab_element (&iter->hti,
81
                                                    referenced_vars);
82
  if (!itm)
83
    return NULL;
84
  return itm->to;
85
}
86
 
87
/* Return true if we have hit the end of the referenced variables ITER is
88
   iterating through.  */
89
 
90
static inline bool
91
end_referenced_vars_p (referenced_var_iterator *iter)
92
{
93
  return end_htab_p (&iter->hti);
94
}
95
 
96
/* Make ITER point to the next referenced_var in the referenced_var hashtable,
97
   and return that variable.  */
98
 
99
static inline tree
100
next_referenced_var (referenced_var_iterator *iter)
101
{
102
  struct int_tree_map *itm;
103
  itm = (struct int_tree_map *) next_htab_element (&iter->hti);
104
  if (!itm)
105
    return NULL;
106
  return itm->to;
107
}
108
 
109
/* Fill up VEC with the variables in the referenced vars hashtable.  */
110
 
111
static inline void
112
fill_referenced_var_vec (VEC (tree, heap) **vec)
113
{
114
  referenced_var_iterator rvi;
115
  tree var;
116
  *vec = NULL;
117
  FOR_EACH_REFERENCED_VAR (var, rvi)
118
    VEC_safe_push (tree, heap, *vec, var);
119
}
120
 
121
/* Return the variable annotation for T, which must be a _DECL node.
122
   Return NULL if the variable annotation doesn't already exist.  */
123
static inline var_ann_t
124
var_ann (tree t)
125
{
126
  gcc_assert (t);
127
  gcc_assert (DECL_P (t));
128
  gcc_assert (TREE_CODE (t) != FUNCTION_DECL);
129
  gcc_assert (!t->common.ann || t->common.ann->common.type == VAR_ANN);
130
 
131
  return (var_ann_t) t->common.ann;
132
}
133
 
134
/* Return the variable annotation for T, which must be a _DECL node.
135
   Create the variable annotation if it doesn't exist.  */
136
static inline var_ann_t
137
get_var_ann (tree var)
138
{
139
  var_ann_t ann = var_ann (var);
140
  return (ann) ? ann : create_var_ann (var);
141
}
142
 
143
/* Return the function annotation for T, which must be a FUNCTION_DECL node.
144
   Return NULL if the function annotation doesn't already exist.  */
145
static inline function_ann_t
146
function_ann (tree t)
147
{
148
  gcc_assert (t);
149
  gcc_assert (TREE_CODE (t) == FUNCTION_DECL);
150
  gcc_assert (!t->common.ann || t->common.ann->common.type == FUNCTION_ANN);
151
 
152
  return (function_ann_t) t->common.ann;
153
}
154
 
155
/* Return the function annotation for T, which must be a FUNCTION_DECL node.
156
   Create the function annotation if it doesn't exist.  */
157
static inline function_ann_t
158
get_function_ann (tree var)
159
{
160
  function_ann_t ann = function_ann (var);
161
  gcc_assert (!var->common.ann || var->common.ann->common.type == FUNCTION_ANN);
162
  return (ann) ? ann : create_function_ann (var);
163
}
164
 
165
/* Return the statement annotation for T, which must be a statement
166
   node.  Return NULL if the statement annotation doesn't exist.  */
167
static inline stmt_ann_t
168
stmt_ann (tree t)
169
{
170
#ifdef ENABLE_CHECKING
171
  gcc_assert (is_gimple_stmt (t));
172
#endif
173
  gcc_assert (!t->common.ann || t->common.ann->common.type == STMT_ANN);
174
  return (stmt_ann_t) t->common.ann;
175
}
176
 
177
/* Return the statement annotation for T, which must be a statement
178
   node.  Create the statement annotation if it doesn't exist.  */
179
static inline stmt_ann_t
180
get_stmt_ann (tree stmt)
181
{
182
  stmt_ann_t ann = stmt_ann (stmt);
183
  return (ann) ? ann : create_stmt_ann (stmt);
184
}
185
 
186
/* Return the annotation type for annotation ANN.  */
187
static inline enum tree_ann_type
188
ann_type (tree_ann_t ann)
189
{
190
  return ann->common.type;
191
}
192
 
193
/* Return the basic block for statement T.  */
194
static inline basic_block
195
bb_for_stmt (tree t)
196
{
197
  stmt_ann_t ann;
198
 
199
  if (TREE_CODE (t) == PHI_NODE)
200
    return PHI_BB (t);
201
 
202
  ann = stmt_ann (t);
203
  return ann ? ann->bb : NULL;
204
}
205
 
206
/* Return the may_aliases varray for variable VAR, or NULL if it has
207
   no may aliases.  */
208
static inline VEC(tree, gc) *
209
may_aliases (tree var)
210
{
211
  var_ann_t ann = var_ann (var);
212
  return ann ? ann->may_aliases : NULL;
213
}
214
 
215
/* Return the line number for EXPR, or return -1 if we have no line
216
   number information for it.  */
217
static inline int
218
get_lineno (tree expr)
219
{
220
  if (expr == NULL_TREE)
221
    return -1;
222
 
223
  if (TREE_CODE (expr) == COMPOUND_EXPR)
224
    expr = TREE_OPERAND (expr, 0);
225
 
226
  if (! EXPR_HAS_LOCATION (expr))
227
    return -1;
228
 
229
  return EXPR_LINENO (expr);
230
}
231
 
232
/* Return the file name for EXPR, or return "???" if we have no
233
   filename information.  */
234
static inline const char *
235
get_filename (tree expr)
236
{
237
  const char *filename;
238
  if (expr == NULL_TREE)
239
    return "???";
240
 
241
  if (TREE_CODE (expr) == COMPOUND_EXPR)
242
    expr = TREE_OPERAND (expr, 0);
243
 
244
  if (EXPR_HAS_LOCATION (expr) && (filename = EXPR_FILENAME (expr)))
245
    return filename;
246
  else
247
    return "???";
248
}
249
 
250
/* Return true if T is a noreturn call.  */
251
static inline bool
252
noreturn_call_p (tree t)
253
{
254
  tree call = get_call_expr_in (t);
255
  return call != 0 && (call_expr_flags (call) & ECF_NORETURN) != 0;
256
}
257
 
258
/* Mark statement T as modified.  */
259
static inline void
260
mark_stmt_modified (tree t)
261
{
262
  stmt_ann_t ann;
263
  if (TREE_CODE (t) == PHI_NODE)
264
    return;
265
 
266
  ann = stmt_ann (t);
267
  if (ann == NULL)
268
    ann = create_stmt_ann (t);
269
  else if (noreturn_call_p (t))
270
    VEC_safe_push (tree, gc, modified_noreturn_calls, t);
271
  ann->modified = 1;
272
}
273
 
274
/* Mark statement T as modified, and update it.  */
275
static inline void
276
update_stmt (tree t)
277
{
278
  if (TREE_CODE (t) == PHI_NODE)
279
    return;
280
  mark_stmt_modified (t);
281
  update_stmt_operands (t);
282
}
283
 
284
static inline void
285
update_stmt_if_modified (tree t)
286
{
287
  if (stmt_modified_p (t))
288
    update_stmt_operands (t);
289
}
290
 
291
/* Return true if T is marked as modified, false otherwise.  */
292
static inline bool
293
stmt_modified_p (tree t)
294
{
295
  stmt_ann_t ann = stmt_ann (t);
296
 
297
  /* Note that if the statement doesn't yet have an annotation, we consider it
298
     modified.  This will force the next call to update_stmt_operands to scan
299
     the statement.  */
300
  return ann ? ann->modified : true;
301
}
302
 
303
/* Delink an immediate_uses node from its chain.  */
304
static inline void
305
delink_imm_use (ssa_use_operand_t *linknode)
306
{
307
  /* Return if this node is not in a list.  */
308
  if (linknode->prev == NULL)
309
    return;
310
 
311
  linknode->prev->next = linknode->next;
312
  linknode->next->prev = linknode->prev;
313
  linknode->prev = NULL;
314
  linknode->next = NULL;
315
}
316
 
317
/* Link ssa_imm_use node LINKNODE into the chain for LIST.  */
318
static inline void
319
link_imm_use_to_list (ssa_use_operand_t *linknode, ssa_use_operand_t *list)
320
{
321
  /* Link the new node at the head of the list.  If we are in the process of
322
     traversing the list, we won't visit any new nodes added to it.  */
323
  linknode->prev = list;
324
  linknode->next = list->next;
325
  list->next->prev = linknode;
326
  list->next = linknode;
327
}
328
 
329
/* Link ssa_imm_use node LINKNODE into the chain for DEF.  */
330
static inline void
331
link_imm_use (ssa_use_operand_t *linknode, tree def)
332
{
333
  ssa_use_operand_t *root;
334
 
335
  if (!def || TREE_CODE (def) != SSA_NAME)
336
    linknode->prev = NULL;
337
  else
338
    {
339
      root = &(SSA_NAME_IMM_USE_NODE (def));
340
#ifdef ENABLE_CHECKING
341
      if (linknode->use)
342
        gcc_assert (*(linknode->use) == def);
343
#endif
344
      link_imm_use_to_list (linknode, root);
345
    }
346
}
347
 
348
/* Set the value of a use pointed to by USE to VAL.  */
349
static inline void
350
set_ssa_use_from_ptr (use_operand_p use, tree val)
351
{
352
  delink_imm_use (use);
353
  *(use->use) = val;
354
  link_imm_use (use, val);
355
}
356
 
357
/* Link ssa_imm_use node LINKNODE into the chain for DEF, with use occurring
358
   in STMT.  */
359
static inline void
360
link_imm_use_stmt (ssa_use_operand_t *linknode, tree def, tree stmt)
361
{
362
  if (stmt)
363
    link_imm_use (linknode, def);
364
  else
365
    link_imm_use (linknode, NULL);
366
  linknode->stmt = stmt;
367
}
368
 
369
/* Relink a new node in place of an old node in the list.  */
370
static inline void
371
relink_imm_use (ssa_use_operand_t *node, ssa_use_operand_t *old)
372
{
373
  /* The node one had better be in the same list.  */
374
  gcc_assert (*(old->use) == *(node->use));
375
  node->prev = old->prev;
376
  node->next = old->next;
377
  if (old->prev)
378
    {
379
      old->prev->next = node;
380
      old->next->prev = node;
381
      /* Remove the old node from the list.  */
382
      old->prev = NULL;
383
    }
384
}
385
 
386
/* Relink ssa_imm_use node LINKNODE into the chain for OLD, with use occurring
387
   in STMT.  */
388
static inline void
389
relink_imm_use_stmt (ssa_use_operand_t *linknode, ssa_use_operand_t *old, tree stmt)
390
{
391
  if (stmt)
392
    relink_imm_use (linknode, old);
393
  else
394
    link_imm_use (linknode, NULL);
395
  linknode->stmt = stmt;
396
}
397
 
398
 
399
/* Return true is IMM has reached the end of the immediate use list.  */
400
static inline bool
401
end_readonly_imm_use_p (imm_use_iterator *imm)
402
{
403
  return (imm->imm_use == imm->end_p);
404
}
405
 
406
/* Initialize iterator IMM to process the list for VAR.  */
407
static inline use_operand_p
408
first_readonly_imm_use (imm_use_iterator *imm, tree var)
409
{
410
  gcc_assert (TREE_CODE (var) == SSA_NAME);
411
 
412
  imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
413
  imm->imm_use = imm->end_p->next;
414
#ifdef ENABLE_CHECKING
415
  imm->iter_node.next = imm->imm_use->next;
416
#endif
417
  if (end_readonly_imm_use_p (imm))
418
    return NULL_USE_OPERAND_P;
419
  return imm->imm_use;
420
}
421
 
422
/* Bump IMM to the next use in the list.  */
423
static inline use_operand_p
424
next_readonly_imm_use (imm_use_iterator *imm)
425
{
426
  use_operand_p old = imm->imm_use;
427
 
428
#ifdef ENABLE_CHECKING
429
  /* If this assertion fails, it indicates the 'next' pointer has changed
430
     since we the last bump.  This indicates that the list is being modified
431
     via stmt changes, or SET_USE, or somesuch thing, and you need to be
432
     using the SAFE version of the iterator.  */
433
  gcc_assert (imm->iter_node.next == old->next);
434
  imm->iter_node.next = old->next->next;
435
#endif
436
 
437
  imm->imm_use = old->next;
438
  if (end_readonly_imm_use_p (imm))
439
    return old;
440
  return imm->imm_use;
441
}
442
 
443
/* Return true if VAR has no uses.  */
444
static inline bool
445
has_zero_uses (tree var)
446
{
447
  ssa_use_operand_t *ptr;
448
  ptr = &(SSA_NAME_IMM_USE_NODE (var));
449
  /* A single use means there is no items in the list.  */
450
  return (ptr == ptr->next);
451
}
452
 
453
/* Return true if VAR has a single use.  */
454
static inline bool
455
has_single_use (tree var)
456
{
457
  ssa_use_operand_t *ptr;
458
  ptr = &(SSA_NAME_IMM_USE_NODE (var));
459
  /* A single use means there is one item in the list.  */
460
  return (ptr != ptr->next && ptr == ptr->next->next);
461
}
462
 
463
/* If VAR has only a single immediate use, return true, and set USE_P and STMT
464
   to the use pointer and stmt of occurrence.  */
465
static inline bool
466
single_imm_use (tree var, use_operand_p *use_p, tree *stmt)
467
{
468
  ssa_use_operand_t *ptr;
469
 
470
  ptr = &(SSA_NAME_IMM_USE_NODE (var));
471
  if (ptr != ptr->next && ptr == ptr->next->next)
472
    {
473
      *use_p = ptr->next;
474
      *stmt = ptr->next->stmt;
475
      return true;
476
    }
477
  *use_p = NULL_USE_OPERAND_P;
478
  *stmt = NULL_TREE;
479
  return false;
480
}
481
 
482
/* Return the number of immediate uses of VAR.  */
483
static inline unsigned int
484
num_imm_uses (tree var)
485
{
486
  ssa_use_operand_t *ptr, *start;
487
  unsigned int num;
488
 
489
  start = &(SSA_NAME_IMM_USE_NODE (var));
490
  num = 0;
491
  for (ptr = start->next; ptr != start; ptr = ptr->next)
492
     num++;
493
 
494
  return num;
495
}
496
 
497
 
498
/* Return the tree pointer to by USE.  */
499
static inline tree
500
get_use_from_ptr (use_operand_p use)
501
{
502
  return *(use->use);
503
}
504
 
505
/* Return the tree pointer to by DEF.  */
506
static inline tree
507
get_def_from_ptr (def_operand_p def)
508
{
509
  return *def;
510
}
511
 
512
/* Return a def_operand_p pointer for the result of PHI.  */
513
static inline def_operand_p
514
get_phi_result_ptr (tree phi)
515
{
516
  return &(PHI_RESULT_TREE (phi));
517
}
518
 
519
/* Return a use_operand_p pointer for argument I of phinode PHI.  */
520
static inline use_operand_p
521
get_phi_arg_def_ptr (tree phi, int i)
522
{
523
  return &(PHI_ARG_IMM_USE_NODE (phi,i));
524
}
525
 
526
 
527
/* Return the bitmap of addresses taken by STMT, or NULL if it takes
528
   no addresses.  */
529
static inline bitmap
530
addresses_taken (tree stmt)
531
{
532
  stmt_ann_t ann = stmt_ann (stmt);
533
  return ann ? ann->addresses_taken : NULL;
534
}
535
 
536
/* Return the PHI nodes for basic block BB, or NULL if there are no
537
   PHI nodes.  */
538
static inline tree
539
phi_nodes (basic_block bb)
540
{
541
  return bb->phi_nodes;
542
}
543
 
544
/* Set list of phi nodes of a basic block BB to L.  */
545
 
546
static inline void
547
set_phi_nodes (basic_block bb, tree l)
548
{
549
  tree phi;
550
 
551
  bb->phi_nodes = l;
552
  for (phi = l; phi; phi = PHI_CHAIN (phi))
553
    set_bb_for_stmt (phi, bb);
554
}
555
 
556
/* Return the phi argument which contains the specified use.  */
557
 
558
static inline int
559
phi_arg_index_from_use (use_operand_p use)
560
{
561
  struct phi_arg_d *element, *root;
562
  int index;
563
  tree phi;
564
 
565
  /* Since the use is the first thing in a PHI argument element, we can
566
     calculate its index based on casting it to an argument, and performing
567
     pointer arithmetic.  */
568
 
569
  phi = USE_STMT (use);
570
  gcc_assert (TREE_CODE (phi) == PHI_NODE);
571
 
572
  element = (struct phi_arg_d *)use;
573
  root = &(PHI_ARG_ELT (phi, 0));
574
  index = element - root;
575
 
576
#ifdef ENABLE_CHECKING
577
  /* Make sure the calculation doesn't have any leftover bytes.  If it does,
578
     then imm_use is likely not the first element in phi_arg_d.  */
579
  gcc_assert (
580
          (((char *)element - (char *)root) % sizeof (struct phi_arg_d)) == 0);
581
  gcc_assert (index >= 0 && index < PHI_ARG_CAPACITY (phi));
582
#endif
583
 
584
 return index;
585
}
586
 
587
/* Mark VAR as used, so that it'll be preserved during rtl expansion.  */
588
 
589
static inline void
590
set_is_used (tree var)
591
{
592
  var_ann_t ann = get_var_ann (var);
593
  ann->used = 1;
594
}
595
 
596
 
597
/*  -----------------------------------------------------------------------  */
598
 
599
/* Return true if T is an executable statement.  */
600
static inline bool
601
is_exec_stmt (tree t)
602
{
603
  return (t && !IS_EMPTY_STMT (t) && t != error_mark_node);
604
}
605
 
606
 
607
/* Return true if this stmt can be the target of a control transfer stmt such
608
   as a goto.  */
609
static inline bool
610
is_label_stmt (tree t)
611
{
612
  if (t)
613
    switch (TREE_CODE (t))
614
      {
615
        case LABEL_DECL:
616
        case LABEL_EXPR:
617
        case CASE_LABEL_EXPR:
618
          return true;
619
        default:
620
          return false;
621
      }
622
  return false;
623
}
624
 
625
/* PHI nodes should contain only ssa_names and invariants.  A test
626
   for ssa_name is definitely simpler; don't let invalid contents
627
   slip in in the meantime.  */
628
 
629
static inline bool
630
phi_ssa_name_p (tree t)
631
{
632
  if (TREE_CODE (t) == SSA_NAME)
633
    return true;
634
#ifdef ENABLE_CHECKING
635
  gcc_assert (is_gimple_min_invariant (t));
636
#endif
637
  return false;
638
}
639
 
640
/*  -----------------------------------------------------------------------  */
641
 
642
/* Return a block_stmt_iterator that points to beginning of basic
643
   block BB.  */
644
static inline block_stmt_iterator
645
bsi_start (basic_block bb)
646
{
647
  block_stmt_iterator bsi;
648
  if (bb->stmt_list)
649
    bsi.tsi = tsi_start (bb->stmt_list);
650
  else
651
    {
652
      gcc_assert (bb->index < NUM_FIXED_BLOCKS);
653
      bsi.tsi.ptr = NULL;
654
      bsi.tsi.container = NULL;
655
    }
656
  bsi.bb = bb;
657
  return bsi;
658
}
659
 
660
/* Return a block statement iterator that points to the first non-label
661
   statement in block BB.  */
662
 
663
static inline block_stmt_iterator
664
bsi_after_labels (basic_block bb)
665
{
666
  block_stmt_iterator bsi = bsi_start (bb);
667
 
668
  while (!bsi_end_p (bsi) && TREE_CODE (bsi_stmt (bsi)) == LABEL_EXPR)
669
    bsi_next (&bsi);
670
 
671
  return bsi;
672
}
673
 
674
/* Return a block statement iterator that points to the end of basic
675
   block BB.  */
676
static inline block_stmt_iterator
677
bsi_last (basic_block bb)
678
{
679
  block_stmt_iterator bsi;
680
  if (bb->stmt_list)
681
    bsi.tsi = tsi_last (bb->stmt_list);
682
  else
683
    {
684
      gcc_assert (bb->index < NUM_FIXED_BLOCKS);
685
      bsi.tsi.ptr = NULL;
686
      bsi.tsi.container = NULL;
687
    }
688
  bsi.bb = bb;
689
  return bsi;
690
}
691
 
692
/* Return true if block statement iterator I has reached the end of
693
   the basic block.  */
694
static inline bool
695
bsi_end_p (block_stmt_iterator i)
696
{
697
  return tsi_end_p (i.tsi);
698
}
699
 
700
/* Modify block statement iterator I so that it is at the next
701
   statement in the basic block.  */
702
static inline void
703
bsi_next (block_stmt_iterator *i)
704
{
705
  tsi_next (&i->tsi);
706
}
707
 
708
/* Modify block statement iterator I so that it is at the previous
709
   statement in the basic block.  */
710
static inline void
711
bsi_prev (block_stmt_iterator *i)
712
{
713
  tsi_prev (&i->tsi);
714
}
715
 
716
/* Return the statement that block statement iterator I is currently
717
   at.  */
718
static inline tree
719
bsi_stmt (block_stmt_iterator i)
720
{
721
  return tsi_stmt (i.tsi);
722
}
723
 
724
/* Return a pointer to the statement that block statement iterator I
725
   is currently at.  */
726
static inline tree *
727
bsi_stmt_ptr (block_stmt_iterator i)
728
{
729
  return tsi_stmt_ptr (i.tsi);
730
}
731
 
732
/* Returns the loop of the statement STMT.  */
733
 
734
static inline struct loop *
735
loop_containing_stmt (tree stmt)
736
{
737
  basic_block bb = bb_for_stmt (stmt);
738
  if (!bb)
739
    return NULL;
740
 
741
  return bb->loop_father;
742
}
743
 
744
/* Return true if VAR is a clobbered by function calls.  */
745
static inline bool
746
is_call_clobbered (tree var)
747
{
748
  if (!MTAG_P (var))
749
    return DECL_CALL_CLOBBERED (var);
750
  else
751
    return bitmap_bit_p (call_clobbered_vars, DECL_UID (var));
752
}
753
 
754
/* Mark variable VAR as being clobbered by function calls.  */
755
static inline void
756
mark_call_clobbered (tree var, unsigned int escape_type)
757
{
758
  var_ann (var)->escape_mask |= escape_type;
759
  if (!MTAG_P (var))
760
    DECL_CALL_CLOBBERED (var) = true;
761
  bitmap_set_bit (call_clobbered_vars, DECL_UID (var));
762
}
763
 
764
/* Clear the call-clobbered attribute from variable VAR.  */
765
static inline void
766
clear_call_clobbered (tree var)
767
{
768
  var_ann_t ann = var_ann (var);
769
  ann->escape_mask = 0;
770
  if (MTAG_P (var) && TREE_CODE (var) != STRUCT_FIELD_TAG)
771
    MTAG_GLOBAL (var) = 0;
772
  if (!MTAG_P (var))
773
    DECL_CALL_CLOBBERED (var) = false;
774
  bitmap_clear_bit (call_clobbered_vars, DECL_UID (var));
775
}
776
 
777
/* Mark variable VAR as being non-addressable.  */
778
static inline void
779
mark_non_addressable (tree var)
780
{
781
  if (!MTAG_P (var))
782
    DECL_CALL_CLOBBERED (var) = false;
783
  bitmap_clear_bit (call_clobbered_vars, DECL_UID (var));
784
  TREE_ADDRESSABLE (var) = 0;
785
}
786
 
787
/* Return the common annotation for T.  Return NULL if the annotation
788
   doesn't already exist.  */
789
static inline tree_ann_common_t
790
tree_common_ann (tree t)
791
{
792
  return &t->common.ann->common;
793
}
794
 
795
/* Return a common annotation for T.  Create the constant annotation if it
796
   doesn't exist.  */
797
static inline tree_ann_common_t
798
get_tree_common_ann (tree t)
799
{
800
  tree_ann_common_t ann = tree_common_ann (t);
801
  return (ann) ? ann : create_tree_common_ann (t);
802
}
803
 
804
/*  -----------------------------------------------------------------------  */
805
 
806
/* The following set of routines are used to iterator over various type of
807
   SSA operands.  */
808
 
809
/* Return true if PTR is finished iterating.  */
810
static inline bool
811
op_iter_done (ssa_op_iter *ptr)
812
{
813
  return ptr->done;
814
}
815
 
816
/* Get the next iterator use value for PTR.  */
817
static inline use_operand_p
818
op_iter_next_use (ssa_op_iter *ptr)
819
{
820
  use_operand_p use_p;
821
#ifdef ENABLE_CHECKING
822
  gcc_assert (ptr->iter_type == ssa_op_iter_use);
823
#endif
824
  if (ptr->uses)
825
    {
826
      use_p = USE_OP_PTR (ptr->uses);
827
      ptr->uses = ptr->uses->next;
828
      return use_p;
829
    }
830
  if (ptr->vuses)
831
    {
832
      use_p = VUSE_OP_PTR (ptr->vuses);
833
      ptr->vuses = ptr->vuses->next;
834
      return use_p;
835
    }
836
  if (ptr->mayuses)
837
    {
838
      use_p = MAYDEF_OP_PTR (ptr->mayuses);
839
      ptr->mayuses = ptr->mayuses->next;
840
      return use_p;
841
    }
842
  if (ptr->mustkills)
843
    {
844
      use_p = MUSTDEF_KILL_PTR (ptr->mustkills);
845
      ptr->mustkills = ptr->mustkills->next;
846
      return use_p;
847
    }
848
  if (ptr->phi_i < ptr->num_phi)
849
    {
850
      return PHI_ARG_DEF_PTR (ptr->phi_stmt, (ptr->phi_i)++);
851
    }
852
  ptr->done = true;
853
  return NULL_USE_OPERAND_P;
854
}
855
 
856
/* Get the next iterator def value for PTR.  */
857
static inline def_operand_p
858
op_iter_next_def (ssa_op_iter *ptr)
859
{
860
  def_operand_p def_p;
861
#ifdef ENABLE_CHECKING
862
  gcc_assert (ptr->iter_type == ssa_op_iter_def);
863
#endif
864
  if (ptr->defs)
865
    {
866
      def_p = DEF_OP_PTR (ptr->defs);
867
      ptr->defs = ptr->defs->next;
868
      return def_p;
869
    }
870
  if (ptr->mustdefs)
871
    {
872
      def_p = MUSTDEF_RESULT_PTR (ptr->mustdefs);
873
      ptr->mustdefs = ptr->mustdefs->next;
874
      return def_p;
875
    }
876
  if (ptr->maydefs)
877
    {
878
      def_p = MAYDEF_RESULT_PTR (ptr->maydefs);
879
      ptr->maydefs = ptr->maydefs->next;
880
      return def_p;
881
    }
882
  ptr->done = true;
883
  return NULL_DEF_OPERAND_P;
884
}
885
 
886
/* Get the next iterator tree value for PTR.  */
887
static inline tree
888
op_iter_next_tree (ssa_op_iter *ptr)
889
{
890
  tree val;
891
#ifdef ENABLE_CHECKING
892
  gcc_assert (ptr->iter_type == ssa_op_iter_tree);
893
#endif
894
  if (ptr->uses)
895
    {
896
      val = USE_OP (ptr->uses);
897
      ptr->uses = ptr->uses->next;
898
      return val;
899
    }
900
  if (ptr->vuses)
901
    {
902
      val = VUSE_OP (ptr->vuses);
903
      ptr->vuses = ptr->vuses->next;
904
      return val;
905
    }
906
  if (ptr->mayuses)
907
    {
908
      val = MAYDEF_OP (ptr->mayuses);
909
      ptr->mayuses = ptr->mayuses->next;
910
      return val;
911
    }
912
  if (ptr->mustkills)
913
    {
914
      val = MUSTDEF_KILL (ptr->mustkills);
915
      ptr->mustkills = ptr->mustkills->next;
916
      return val;
917
    }
918
  if (ptr->defs)
919
    {
920
      val = DEF_OP (ptr->defs);
921
      ptr->defs = ptr->defs->next;
922
      return val;
923
    }
924
  if (ptr->mustdefs)
925
    {
926
      val = MUSTDEF_RESULT (ptr->mustdefs);
927
      ptr->mustdefs = ptr->mustdefs->next;
928
      return val;
929
    }
930
  if (ptr->maydefs)
931
    {
932
      val = MAYDEF_RESULT (ptr->maydefs);
933
      ptr->maydefs = ptr->maydefs->next;
934
      return val;
935
    }
936
 
937
  ptr->done = true;
938
  return NULL_TREE;
939
 
940
}
941
 
942
 
943
/* This functions clears the iterator PTR, and marks it done.  This is normally
944
   used to prevent warnings in the compile about might be uninitialized
945
   components.  */
946
 
947
static inline void
948
clear_and_done_ssa_iter (ssa_op_iter *ptr)
949
{
950
  ptr->defs = NULL;
951
  ptr->uses = NULL;
952
  ptr->vuses = NULL;
953
  ptr->maydefs = NULL;
954
  ptr->mayuses = NULL;
955
  ptr->mustdefs = NULL;
956
  ptr->mustkills = NULL;
957
  ptr->iter_type = ssa_op_iter_none;
958
  ptr->phi_i = 0;
959
  ptr->num_phi = 0;
960
  ptr->phi_stmt = NULL_TREE;
961
  ptr->done = true;
962
}
963
 
964
/* Initialize the iterator PTR to the virtual defs in STMT.  */
965
static inline void
966
op_iter_init (ssa_op_iter *ptr, tree stmt, int flags)
967
{
968
#ifdef ENABLE_CHECKING
969
  gcc_assert (stmt_ann (stmt));
970
#endif
971
 
972
  ptr->defs = (flags & SSA_OP_DEF) ? DEF_OPS (stmt) : NULL;
973
  ptr->uses = (flags & SSA_OP_USE) ? USE_OPS (stmt) : NULL;
974
  ptr->vuses = (flags & SSA_OP_VUSE) ? VUSE_OPS (stmt) : NULL;
975
  ptr->maydefs = (flags & SSA_OP_VMAYDEF) ? MAYDEF_OPS (stmt) : NULL;
976
  ptr->mayuses = (flags & SSA_OP_VMAYUSE) ? MAYDEF_OPS (stmt) : NULL;
977
  ptr->mustdefs = (flags & SSA_OP_VMUSTDEF) ? MUSTDEF_OPS (stmt) : NULL;
978
  ptr->mustkills = (flags & SSA_OP_VMUSTKILL) ? MUSTDEF_OPS (stmt) : NULL;
979
  ptr->done = false;
980
 
981
  ptr->phi_i = 0;
982
  ptr->num_phi = 0;
983
  ptr->phi_stmt = NULL_TREE;
984
}
985
 
986
/* Initialize iterator PTR to the use operands in STMT based on FLAGS. Return
987
   the first use.  */
988
static inline use_operand_p
989
op_iter_init_use (ssa_op_iter *ptr, tree stmt, int flags)
990
{
991
  gcc_assert ((flags & SSA_OP_ALL_DEFS) == 0);
992
  op_iter_init (ptr, stmt, flags);
993
  ptr->iter_type = ssa_op_iter_use;
994
  return op_iter_next_use (ptr);
995
}
996
 
997
/* Initialize iterator PTR to the def operands in STMT based on FLAGS. Return
998
   the first def.  */
999
static inline def_operand_p
1000
op_iter_init_def (ssa_op_iter *ptr, tree stmt, int flags)
1001
{
1002
  gcc_assert ((flags & (SSA_OP_ALL_USES | SSA_OP_VIRTUAL_KILLS)) == 0);
1003
  op_iter_init (ptr, stmt, flags);
1004
  ptr->iter_type = ssa_op_iter_def;
1005
  return op_iter_next_def (ptr);
1006
}
1007
 
1008
/* Initialize iterator PTR to the operands in STMT based on FLAGS. Return
1009
   the first operand as a tree.  */
1010
static inline tree
1011
op_iter_init_tree (ssa_op_iter *ptr, tree stmt, int flags)
1012
{
1013
  op_iter_init (ptr, stmt, flags);
1014
  ptr->iter_type = ssa_op_iter_tree;
1015
  return op_iter_next_tree (ptr);
1016
}
1017
 
1018
/* Get the next iterator mustdef value for PTR, returning the mustdef values in
1019
   KILL and DEF.  */
1020
static inline void
1021
op_iter_next_maymustdef (use_operand_p *use, def_operand_p *def,
1022
                         ssa_op_iter *ptr)
1023
{
1024
#ifdef ENABLE_CHECKING
1025
  gcc_assert (ptr->iter_type == ssa_op_iter_maymustdef);
1026
#endif
1027
  if (ptr->mayuses)
1028
    {
1029
      *def = MAYDEF_RESULT_PTR (ptr->mayuses);
1030
      *use = MAYDEF_OP_PTR (ptr->mayuses);
1031
      ptr->mayuses = ptr->mayuses->next;
1032
      return;
1033
    }
1034
 
1035
  if (ptr->mustkills)
1036
    {
1037
      *def = MUSTDEF_RESULT_PTR (ptr->mustkills);
1038
      *use = MUSTDEF_KILL_PTR (ptr->mustkills);
1039
      ptr->mustkills = ptr->mustkills->next;
1040
      return;
1041
    }
1042
 
1043
  *def = NULL_DEF_OPERAND_P;
1044
  *use = NULL_USE_OPERAND_P;
1045
  ptr->done = true;
1046
  return;
1047
}
1048
 
1049
 
1050
/* Initialize iterator PTR to the operands in STMT.  Return the first operands
1051
   in USE and DEF.  */
1052
static inline void
1053
op_iter_init_maydef (ssa_op_iter *ptr, tree stmt, use_operand_p *use,
1054
                     def_operand_p *def)
1055
{
1056
  gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1057
 
1058
  op_iter_init (ptr, stmt, SSA_OP_VMAYUSE);
1059
  ptr->iter_type = ssa_op_iter_maymustdef;
1060
  op_iter_next_maymustdef (use, def, ptr);
1061
}
1062
 
1063
 
1064
/* Initialize iterator PTR to the operands in STMT.  Return the first operands
1065
   in KILL and DEF.  */
1066
static inline void
1067
op_iter_init_mustdef (ssa_op_iter *ptr, tree stmt, use_operand_p *kill,
1068
                     def_operand_p *def)
1069
{
1070
  gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1071
 
1072
  op_iter_init (ptr, stmt, SSA_OP_VMUSTKILL);
1073
  ptr->iter_type = ssa_op_iter_maymustdef;
1074
  op_iter_next_maymustdef (kill, def, ptr);
1075
}
1076
 
1077
/* Initialize iterator PTR to the operands in STMT.  Return the first operands
1078
   in KILL and DEF.  */
1079
static inline void
1080
op_iter_init_must_and_may_def (ssa_op_iter *ptr, tree stmt,
1081
                               use_operand_p *kill, def_operand_p *def)
1082
{
1083
  gcc_assert (TREE_CODE (stmt) != PHI_NODE);
1084
 
1085
  op_iter_init (ptr, stmt, SSA_OP_VMUSTKILL|SSA_OP_VMAYUSE);
1086
  ptr->iter_type = ssa_op_iter_maymustdef;
1087
  op_iter_next_maymustdef (kill, def, ptr);
1088
}
1089
 
1090
 
1091
/* If there is a single operand in STMT matching FLAGS, return it.  Otherwise
1092
   return NULL.  */
1093
static inline tree
1094
single_ssa_tree_operand (tree stmt, int flags)
1095
{
1096
  tree var;
1097
  ssa_op_iter iter;
1098
 
1099
  var = op_iter_init_tree (&iter, stmt, flags);
1100
  if (op_iter_done (&iter))
1101
    return NULL_TREE;
1102
  op_iter_next_tree (&iter);
1103
  if (op_iter_done (&iter))
1104
    return var;
1105
  return NULL_TREE;
1106
}
1107
 
1108
 
1109
/* If there is a single operand in STMT matching FLAGS, return it.  Otherwise
1110
   return NULL.  */
1111
static inline use_operand_p
1112
single_ssa_use_operand (tree stmt, int flags)
1113
{
1114
  use_operand_p var;
1115
  ssa_op_iter iter;
1116
 
1117
  var = op_iter_init_use (&iter, stmt, flags);
1118
  if (op_iter_done (&iter))
1119
    return NULL_USE_OPERAND_P;
1120
  op_iter_next_use (&iter);
1121
  if (op_iter_done (&iter))
1122
    return var;
1123
  return NULL_USE_OPERAND_P;
1124
}
1125
 
1126
 
1127
 
1128
/* If there is a single operand in STMT matching FLAGS, return it.  Otherwise
1129
   return NULL.  */
1130
static inline def_operand_p
1131
single_ssa_def_operand (tree stmt, int flags)
1132
{
1133
  def_operand_p var;
1134
  ssa_op_iter iter;
1135
 
1136
  var = op_iter_init_def (&iter, stmt, flags);
1137
  if (op_iter_done (&iter))
1138
    return NULL_DEF_OPERAND_P;
1139
  op_iter_next_def (&iter);
1140
  if (op_iter_done (&iter))
1141
    return var;
1142
  return NULL_DEF_OPERAND_P;
1143
}
1144
 
1145
 
1146
/* Return true if there are zero operands in STMT matching the type
1147
   given in FLAGS.  */
1148
static inline bool
1149
zero_ssa_operands (tree stmt, int flags)
1150
{
1151
  ssa_op_iter iter;
1152
 
1153
  op_iter_init_tree (&iter, stmt, flags);
1154
  return op_iter_done (&iter);
1155
}
1156
 
1157
 
1158
/* Return the number of operands matching FLAGS in STMT.  */
1159
static inline int
1160
num_ssa_operands (tree stmt, int flags)
1161
{
1162
  ssa_op_iter iter;
1163
  tree t;
1164
  int num = 0;
1165
 
1166
  FOR_EACH_SSA_TREE_OPERAND (t, stmt, iter, flags)
1167
    num++;
1168
  return num;
1169
}
1170
 
1171
 
1172
/* Delink all immediate_use information for STMT.  */
1173
static inline void
1174
delink_stmt_imm_use (tree stmt)
1175
{
1176
   ssa_op_iter iter;
1177
   use_operand_p use_p;
1178
 
1179
   if (ssa_operands_active ())
1180
     FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter,
1181
                               (SSA_OP_ALL_USES | SSA_OP_ALL_KILLS))
1182
       delink_imm_use (use_p);
1183
}
1184
 
1185
 
1186
/* This routine will compare all the operands matching FLAGS in STMT1 to those
1187
   in STMT2.  TRUE is returned if they are the same.  STMTs can be NULL.  */
1188
static inline bool
1189
compare_ssa_operands_equal (tree stmt1, tree stmt2, int flags)
1190
{
1191
  ssa_op_iter iter1, iter2;
1192
  tree op1 = NULL_TREE;
1193
  tree op2 = NULL_TREE;
1194
  bool look1, look2;
1195
 
1196
  if (stmt1 == stmt2)
1197
    return true;
1198
 
1199
  look1 = stmt1 && stmt_ann (stmt1);
1200
  look2 = stmt2 && stmt_ann (stmt2);
1201
 
1202
  if (look1)
1203
    {
1204
      op1 = op_iter_init_tree (&iter1, stmt1, flags);
1205
      if (!look2)
1206
        return op_iter_done (&iter1);
1207
    }
1208
  else
1209
    clear_and_done_ssa_iter (&iter1);
1210
 
1211
  if (look2)
1212
    {
1213
      op2 = op_iter_init_tree (&iter2, stmt2, flags);
1214
      if (!look1)
1215
        return op_iter_done (&iter2);
1216
    }
1217
  else
1218
    clear_and_done_ssa_iter (&iter2);
1219
 
1220
  while (!op_iter_done (&iter1) && !op_iter_done (&iter2))
1221
    {
1222
      if (op1 != op2)
1223
        return false;
1224
      op1 = op_iter_next_tree (&iter1);
1225
      op2 = op_iter_next_tree (&iter2);
1226
    }
1227
 
1228
  return (op_iter_done (&iter1) && op_iter_done (&iter2));
1229
}
1230
 
1231
 
1232
/* If there is a single DEF in the PHI node which matches FLAG, return it.
1233
   Otherwise return NULL_DEF_OPERAND_P.  */
1234
static inline tree
1235
single_phi_def (tree stmt, int flags)
1236
{
1237
  tree def = PHI_RESULT (stmt);
1238
  if ((flags & SSA_OP_DEF) && is_gimple_reg (def))
1239
    return def;
1240
  if ((flags & SSA_OP_VIRTUAL_DEFS) && !is_gimple_reg (def))
1241
    return def;
1242
  return NULL_TREE;
1243
}
1244
 
1245
/* Initialize the iterator PTR for uses matching FLAGS in PHI.  FLAGS should
1246
   be either SSA_OP_USES or SSA_OP_VIRTUAL_USES.  */
1247
static inline use_operand_p
1248
op_iter_init_phiuse (ssa_op_iter *ptr, tree phi, int flags)
1249
{
1250
  tree phi_def = PHI_RESULT (phi);
1251
  int comp;
1252
 
1253
  clear_and_done_ssa_iter (ptr);
1254
  ptr->done = false;
1255
 
1256
  gcc_assert ((flags & (SSA_OP_USE | SSA_OP_VIRTUAL_USES)) != 0);
1257
 
1258
  comp = (is_gimple_reg (phi_def) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
1259
 
1260
  /* If the PHI node doesn't the operand type we care about, we're done.  */
1261
  if ((flags & comp) == 0)
1262
    {
1263
      ptr->done = true;
1264
      return NULL_USE_OPERAND_P;
1265
    }
1266
 
1267
  ptr->phi_stmt = phi;
1268
  ptr->num_phi = PHI_NUM_ARGS (phi);
1269
  ptr->iter_type = ssa_op_iter_use;
1270
  return op_iter_next_use (ptr);
1271
}
1272
 
1273
 
1274
/* Start an iterator for a PHI definition.  */
1275
 
1276
static inline def_operand_p
1277
op_iter_init_phidef (ssa_op_iter *ptr, tree phi, int flags)
1278
{
1279
  tree phi_def = PHI_RESULT (phi);
1280
  int comp;
1281
 
1282
  clear_and_done_ssa_iter (ptr);
1283
  ptr->done = false;
1284
 
1285
  gcc_assert ((flags & (SSA_OP_DEF | SSA_OP_VIRTUAL_DEFS)) != 0);
1286
 
1287
  comp = (is_gimple_reg (phi_def) ? SSA_OP_DEF : SSA_OP_VIRTUAL_DEFS);
1288
 
1289
  /* If the PHI node doesn't the operand type we care about, we're done.  */
1290
  if ((flags & comp) == 0)
1291
    {
1292
      ptr->done = true;
1293
      return NULL_USE_OPERAND_P;
1294
    }
1295
 
1296
  ptr->iter_type = ssa_op_iter_def;
1297
  /* The first call to op_iter_next_def will terminate the iterator since
1298
     all the fields are NULL.  Simply return the result here as the first and
1299
     therefore only result.  */
1300
  return PHI_RESULT_PTR (phi);
1301
}
1302
 
1303
/* Return true is IMM has reached the end of the immediate use stmt list.  */
1304
 
1305
static inline bool
1306
end_imm_use_stmt_p (imm_use_iterator *imm)
1307
{
1308
  return (imm->imm_use == imm->end_p);
1309
}
1310
 
1311
/* Finished the traverse of an immediate use stmt list IMM by removing the
1312
   placeholder node from the list.  */
1313
 
1314
static inline void
1315
end_imm_use_stmt_traverse (imm_use_iterator *imm)
1316
{
1317
  delink_imm_use (&(imm->iter_node));
1318
}
1319
 
1320
/* Immediate use traversal of uses within a stmt require that all the
1321
   uses on a stmt be sequentially listed.  This routine is used to build up
1322
   this sequential list by adding USE_P to the end of the current list
1323
   currently delimited by HEAD and LAST_P.  The new LAST_P value is
1324
   returned.  */
1325
 
1326
static inline use_operand_p
1327
move_use_after_head (use_operand_p use_p, use_operand_p head,
1328
                      use_operand_p last_p)
1329
{
1330
  gcc_assert (USE_FROM_PTR (use_p) == USE_FROM_PTR (head));
1331
  /* Skip head when we find it.  */
1332
  if (use_p != head)
1333
    {
1334
      /* If use_p is already linked in after last_p, continue.  */
1335
      if (last_p->next == use_p)
1336
        last_p = use_p;
1337
      else
1338
        {
1339
          /* Delink from current location, and link in at last_p.  */
1340
          delink_imm_use (use_p);
1341
          link_imm_use_to_list (use_p, last_p);
1342
          last_p = use_p;
1343
        }
1344
    }
1345
  return last_p;
1346
}
1347
 
1348
 
1349
/* This routine will relink all uses with the same stmt as HEAD into the list
1350
   immediately following HEAD for iterator IMM.  */
1351
 
1352
static inline void
1353
link_use_stmts_after (use_operand_p head, imm_use_iterator *imm)
1354
{
1355
  use_operand_p use_p;
1356
  use_operand_p last_p = head;
1357
  tree head_stmt = USE_STMT (head);
1358
  tree use = USE_FROM_PTR (head);
1359
  ssa_op_iter op_iter;
1360
  int flag;
1361
 
1362
  /* Only look at virtual or real uses, depending on the type of HEAD.  */
1363
  flag = (is_gimple_reg (use) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
1364
 
1365
  if (TREE_CODE (head_stmt) == PHI_NODE)
1366
    {
1367
      FOR_EACH_PHI_ARG (use_p, head_stmt, op_iter, flag)
1368
        if (USE_FROM_PTR (use_p) == use)
1369
          last_p = move_use_after_head (use_p, head, last_p);
1370
    }
1371
  else
1372
    {
1373
      FOR_EACH_SSA_USE_OPERAND (use_p, head_stmt, op_iter, flag)
1374
        if (USE_FROM_PTR (use_p) == use)
1375
          last_p = move_use_after_head (use_p, head, last_p);
1376
    }
1377
  /* LInk iter node in after last_p.  */
1378
  if (imm->iter_node.prev != NULL)
1379
    delink_imm_use (&imm->iter_node);
1380
  link_imm_use_to_list (&(imm->iter_node), last_p);
1381
}
1382
 
1383
/* Initialize IMM to traverse over uses of VAR.  Return the first statement.  */
1384
static inline tree
1385
first_imm_use_stmt (imm_use_iterator *imm, tree var)
1386
{
1387
  gcc_assert (TREE_CODE (var) == SSA_NAME);
1388
 
1389
  imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
1390
  imm->imm_use = imm->end_p->next;
1391
  imm->next_imm_name = NULL_USE_OPERAND_P;
1392
 
1393
  /* iter_node is used as a marker within the immediate use list to indicate
1394
     where the end of the current stmt's uses are.  Initialize it to NULL
1395
     stmt and use, which indicates a marker node.  */
1396
  imm->iter_node.prev = NULL_USE_OPERAND_P;
1397
  imm->iter_node.next = NULL_USE_OPERAND_P;
1398
  imm->iter_node.stmt = NULL_TREE;
1399
  imm->iter_node.use = NULL_USE_OPERAND_P;
1400
 
1401
  if (end_imm_use_stmt_p (imm))
1402
    return NULL_TREE;
1403
 
1404
  link_use_stmts_after (imm->imm_use, imm);
1405
 
1406
  return USE_STMT (imm->imm_use);
1407
}
1408
 
1409
/* Bump IMM to the next stmt which has a use of var.  */
1410
 
1411
static inline tree
1412
next_imm_use_stmt (imm_use_iterator *imm)
1413
{
1414
  imm->imm_use = imm->iter_node.next;
1415
  if (end_imm_use_stmt_p (imm))
1416
    {
1417
      if (imm->iter_node.prev != NULL)
1418
        delink_imm_use (&imm->iter_node);
1419
      return NULL_TREE;
1420
    }
1421
 
1422
  link_use_stmts_after (imm->imm_use, imm);
1423
  return USE_STMT (imm->imm_use);
1424
 
1425
}
1426
 
1427
/* This routine will return the first use on the stmt IMM currently refers
1428
   to.  */
1429
 
1430
static inline use_operand_p
1431
first_imm_use_on_stmt (imm_use_iterator *imm)
1432
{
1433
  imm->next_imm_name = imm->imm_use->next;
1434
  return imm->imm_use;
1435
}
1436
 
1437
/*  Return TRUE if the last use on the stmt IMM refers to has been visited.  */
1438
 
1439
static inline bool
1440
end_imm_use_on_stmt_p (imm_use_iterator *imm)
1441
{
1442
  return (imm->imm_use == &(imm->iter_node));
1443
}
1444
 
1445
/* Bump to the next use on the stmt IMM refers to, return NULL if done.  */
1446
 
1447
static inline use_operand_p
1448
next_imm_use_on_stmt (imm_use_iterator *imm)
1449
{
1450
  imm->imm_use = imm->next_imm_name;
1451
  if (end_imm_use_on_stmt_p (imm))
1452
    return NULL_USE_OPERAND_P;
1453
  else
1454
    {
1455
      imm->next_imm_name = imm->imm_use->next;
1456
      return imm->imm_use;
1457
    }
1458
}
1459
 
1460
/* Return true if VAR cannot be modified by the program.  */
1461
 
1462
static inline bool
1463
unmodifiable_var_p (tree var)
1464
{
1465
  if (TREE_CODE (var) == SSA_NAME)
1466
    var = SSA_NAME_VAR (var);
1467
 
1468
  if (MTAG_P (var))
1469
    return TREE_READONLY (var) && (TREE_STATIC (var) || MTAG_GLOBAL (var));
1470
 
1471
  return TREE_READONLY (var) && (TREE_STATIC (var) || DECL_EXTERNAL (var));
1472
}
1473
 
1474
/* Return true if REF, an ARRAY_REF, has an INDIRECT_REF somewhere in it.  */
1475
 
1476
static inline bool
1477
array_ref_contains_indirect_ref (tree ref)
1478
{
1479
  gcc_assert (TREE_CODE (ref) == ARRAY_REF);
1480
 
1481
  do {
1482
    ref = TREE_OPERAND (ref, 0);
1483
  } while (handled_component_p (ref));
1484
 
1485
  return TREE_CODE (ref) == INDIRECT_REF;
1486
}
1487
 
1488
/* Return true if REF, a handled component reference, has an ARRAY_REF
1489
   somewhere in it.  */
1490
 
1491
static inline bool
1492
ref_contains_array_ref (tree ref)
1493
{
1494
  gcc_assert (handled_component_p (ref));
1495
 
1496
  do {
1497
    if (TREE_CODE (ref) == ARRAY_REF)
1498
      return true;
1499
    ref = TREE_OPERAND (ref, 0);
1500
  } while (handled_component_p (ref));
1501
 
1502
  return false;
1503
}
1504
 
1505
/* Given a variable VAR, lookup and return a pointer to the list of
1506
   subvariables for it.  */
1507
 
1508
static inline subvar_t *
1509
lookup_subvars_for_var (tree var)
1510
{
1511
  var_ann_t ann = var_ann (var);
1512
  gcc_assert (ann);
1513
  return &ann->subvars;
1514
}
1515
 
1516
/* Given a variable VAR, return a linked list of subvariables for VAR, or
1517
   NULL, if there are no subvariables.  */
1518
 
1519
static inline subvar_t
1520
get_subvars_for_var (tree var)
1521
{
1522
  subvar_t subvars;
1523
 
1524
  gcc_assert (SSA_VAR_P (var));
1525
 
1526
  if (TREE_CODE (var) == SSA_NAME)
1527
    subvars = *(lookup_subvars_for_var (SSA_NAME_VAR (var)));
1528
  else
1529
    subvars = *(lookup_subvars_for_var (var));
1530
  return subvars;
1531
}
1532
 
1533
/* Return the subvariable of VAR at offset OFFSET.  */
1534
 
1535
static inline tree
1536
get_subvar_at (tree var, unsigned HOST_WIDE_INT offset)
1537
{
1538
  subvar_t sv;
1539
 
1540
  for (sv = get_subvars_for_var (var); sv; sv = sv->next)
1541
    if (SFT_OFFSET (sv->var) == offset)
1542
      return sv->var;
1543
 
1544
  return NULL_TREE;
1545
}
1546
 
1547
/* Return true if V is a tree that we can have subvars for.
1548
   Normally, this is any aggregate type.  Also complex
1549
   types which are not gimple registers can have subvars.  */
1550
 
1551
static inline bool
1552
var_can_have_subvars (tree v)
1553
{
1554
  /* Volatile variables should never have subvars.  */
1555
  if (TREE_THIS_VOLATILE (v))
1556
    return false;
1557
 
1558
  /* Non decls or memory tags can never have subvars.  */
1559
  if (!DECL_P (v) || MTAG_P (v))
1560
    return false;
1561
 
1562
  /* Aggregates can have subvars.  */
1563
  if (AGGREGATE_TYPE_P (TREE_TYPE (v)))
1564
    return true;
1565
 
1566
  /* Complex types variables which are not also a gimple register can
1567
    have subvars. */
1568
  if (TREE_CODE (TREE_TYPE (v)) == COMPLEX_TYPE
1569
      && !DECL_COMPLEX_GIMPLE_REG_P (v))
1570
    return true;
1571
 
1572
  return false;
1573
}
1574
 
1575
 
1576
/* Return true if OFFSET and SIZE define a range that overlaps with some
1577
   portion of the range of SV, a subvar.  If there was an exact overlap,
1578
   *EXACT will be set to true upon return. */
1579
 
1580
static inline bool
1581
overlap_subvar (unsigned HOST_WIDE_INT offset, unsigned HOST_WIDE_INT size,
1582
                tree sv,  bool *exact)
1583
{
1584
  /* There are three possible cases of overlap.
1585
     1. We can have an exact overlap, like so:
1586
     |offset, offset + size             |
1587
     |sv->offset, sv->offset + sv->size |
1588
 
1589
     2. We can have offset starting after sv->offset, like so:
1590
 
1591
           |offset, offset + size              |
1592
     |sv->offset, sv->offset + sv->size  |
1593
 
1594
     3. We can have offset starting before sv->offset, like so:
1595
 
1596
     |offset, offset + size    |
1597
       |sv->offset, sv->offset + sv->size|
1598
  */
1599
 
1600
  if (exact)
1601
    *exact = false;
1602
  if (offset == SFT_OFFSET (sv) && size == SFT_SIZE (sv))
1603
    {
1604
      if (exact)
1605
        *exact = true;
1606
      return true;
1607
    }
1608
  else if (offset >= SFT_OFFSET (sv)
1609
           && offset < (SFT_OFFSET (sv) + SFT_SIZE (sv)))
1610
    {
1611
      return true;
1612
    }
1613
  else if (offset < SFT_OFFSET (sv)
1614
           && (size > SFT_OFFSET (sv) - offset))
1615
    {
1616
      return true;
1617
    }
1618
  return false;
1619
 
1620
}
1621
 
1622
#endif /* _TREE_FLOW_INLINE_H  */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.