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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [tree-flow-inline.h] - Blame information for rev 684

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 684 jeremybenn
/* Inline functions for tree-flow.h
2
   Copyright (C) 2001, 2003, 2005, 2006, 2007, 2008, 2010
3
   Free Software Foundation, Inc.
4
   Contributed by Diego Novillo <dnovillo@redhat.com>
5
 
6
This file is part of GCC.
7
 
8
GCC is free software; you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation; either version 3, or (at your option)
11
any later version.
12
 
13
GCC is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
GNU General Public License for more details.
17
 
18
You should have received a copy of the GNU General Public License
19
along with GCC; see the file COPYING3.  If not see
20
<http://www.gnu.org/licenses/>.  */
21
 
22
#ifndef _TREE_FLOW_INLINE_H
23
#define _TREE_FLOW_INLINE_H 1
24
 
25
/* Inline functions for manipulating various data structures defined in
26
   tree-flow.h.  See tree-flow.h for documentation.  */
27
 
28
/* Return true when gimple SSA form was built.
29
   gimple_in_ssa_p is queried by gimplifier in various early stages before SSA
30
   infrastructure is initialized.  Check for presence of the datastructures
31
   at first place.  */
32
static inline bool
33
gimple_in_ssa_p (const struct function *fun)
34
{
35
  return fun && fun->gimple_df && fun->gimple_df->in_ssa_p;
36
}
37
 
38
/* Array of all variables referenced in the function.  */
39
static inline htab_t
40
gimple_referenced_vars (const struct function *fun)
41
{
42
  if (!fun->gimple_df)
43
    return NULL;
44
  return fun->gimple_df->referenced_vars;
45
}
46
 
47
/* Artificial variable used for the virtual operand FUD chain.  */
48
static inline tree
49
gimple_vop (const struct function *fun)
50
{
51
  gcc_checking_assert (fun && fun->gimple_df);
52
  return fun->gimple_df->vop;
53
}
54
 
55
/* Initialize the hashtable iterator HTI to point to hashtable TABLE */
56
 
57
static inline void *
58
first_htab_element (htab_iterator *hti, htab_t table)
59
{
60
  hti->htab = table;
61
  hti->slot = table->entries;
62
  hti->limit = hti->slot + htab_size (table);
63
  do
64
    {
65
      PTR x = *(hti->slot);
66
      if (x != HTAB_EMPTY_ENTRY && x != HTAB_DELETED_ENTRY)
67
        break;
68
    } while (++(hti->slot) < hti->limit);
69
 
70
  if (hti->slot < hti->limit)
71
    return *(hti->slot);
72
  return NULL;
73
}
74
 
75
/* Return current non-empty/deleted slot of the hashtable pointed to by HTI,
76
   or NULL if we have  reached the end.  */
77
 
78
static inline bool
79
end_htab_p (const htab_iterator *hti)
80
{
81
  if (hti->slot >= hti->limit)
82
    return true;
83
  return false;
84
}
85
 
86
/* Advance the hashtable iterator pointed to by HTI to the next element of the
87
   hashtable.  */
88
 
89
static inline void *
90
next_htab_element (htab_iterator *hti)
91
{
92
  while (++(hti->slot) < hti->limit)
93
    {
94
      PTR x = *(hti->slot);
95
      if (x != HTAB_EMPTY_ENTRY && x != HTAB_DELETED_ENTRY)
96
        return x;
97
    };
98
  return NULL;
99
}
100
 
101
/* Get the variable with uid UID from the list of referenced vars.  */
102
 
103
static inline tree
104
referenced_var (unsigned int uid)
105
{
106
  tree var = referenced_var_lookup (cfun, uid);
107
  gcc_assert (var || uid == 0);
108
  return var;
109
}
110
 
111
/* Initialize ITER to point to the first referenced variable in the
112
   referenced_vars hashtable, and return that variable.  */
113
 
114
static inline tree
115
first_referenced_var (struct function *fn, referenced_var_iterator *iter)
116
{
117
  return (tree) first_htab_element (&iter->hti,
118
                                    gimple_referenced_vars (fn));
119
}
120
 
121
/* Return true if we have hit the end of the referenced variables ITER is
122
   iterating through.  */
123
 
124
static inline bool
125
end_referenced_vars_p (const referenced_var_iterator *iter)
126
{
127
  return end_htab_p (&iter->hti);
128
}
129
 
130
/* Make ITER point to the next referenced_var in the referenced_var hashtable,
131
   and return that variable.  */
132
 
133
static inline tree
134
next_referenced_var (referenced_var_iterator *iter)
135
{
136
  return (tree) next_htab_element (&iter->hti);
137
}
138
 
139
/* Return the variable annotation for T, which must be a _DECL node.
140
   Return NULL if the variable annotation doesn't already exist.  */
141
static inline var_ann_t
142
var_ann (const_tree t)
143
{
144
  const var_ann_t *p = DECL_VAR_ANN_PTR (t);
145
  return p ? *p : NULL;
146
}
147
 
148
/* Get the number of the next statement uid to be allocated.  */
149
static inline unsigned int
150
gimple_stmt_max_uid (struct function *fn)
151
{
152
  return fn->last_stmt_uid;
153
}
154
 
155
/* Set the number of the next statement uid to be allocated.  */
156
static inline void
157
set_gimple_stmt_max_uid (struct function *fn, unsigned int maxid)
158
{
159
  fn->last_stmt_uid = maxid;
160
}
161
 
162
/* Set the number of the next statement uid to be allocated.  */
163
static inline unsigned int
164
inc_gimple_stmt_max_uid (struct function *fn)
165
{
166
  return fn->last_stmt_uid++;
167
}
168
 
169
/* Return the line number for EXPR, or return -1 if we have no line
170
   number information for it.  */
171
static inline int
172
get_lineno (const_gimple stmt)
173
{
174
  location_t loc;
175
 
176
  if (!stmt)
177
    return -1;
178
 
179
  loc = gimple_location (stmt);
180
  if (loc == UNKNOWN_LOCATION)
181
    return -1;
182
 
183
  return LOCATION_LINE (loc);
184
}
185
 
186
/* Delink an immediate_uses node from its chain.  */
187
static inline void
188
delink_imm_use (ssa_use_operand_t *linknode)
189
{
190
  /* Return if this node is not in a list.  */
191
  if (linknode->prev == NULL)
192
    return;
193
 
194
  linknode->prev->next = linknode->next;
195
  linknode->next->prev = linknode->prev;
196
  linknode->prev = NULL;
197
  linknode->next = NULL;
198
}
199
 
200
/* Link ssa_imm_use node LINKNODE into the chain for LIST.  */
201
static inline void
202
link_imm_use_to_list (ssa_use_operand_t *linknode, ssa_use_operand_t *list)
203
{
204
  /* Link the new node at the head of the list.  If we are in the process of
205
     traversing the list, we won't visit any new nodes added to it.  */
206
  linknode->prev = list;
207
  linknode->next = list->next;
208
  list->next->prev = linknode;
209
  list->next = linknode;
210
}
211
 
212
/* Link ssa_imm_use node LINKNODE into the chain for DEF.  */
213
static inline void
214
link_imm_use (ssa_use_operand_t *linknode, tree def)
215
{
216
  ssa_use_operand_t *root;
217
 
218
  if (!def || TREE_CODE (def) != SSA_NAME)
219
    linknode->prev = NULL;
220
  else
221
    {
222
      root = &(SSA_NAME_IMM_USE_NODE (def));
223
      if (linknode->use)
224
        gcc_checking_assert (*(linknode->use) == def);
225
      link_imm_use_to_list (linknode, root);
226
    }
227
}
228
 
229
/* Set the value of a use pointed to by USE to VAL.  */
230
static inline void
231
set_ssa_use_from_ptr (use_operand_p use, tree val)
232
{
233
  delink_imm_use (use);
234
  *(use->use) = val;
235
  link_imm_use (use, val);
236
}
237
 
238
/* Link ssa_imm_use node LINKNODE into the chain for DEF, with use occurring
239
   in STMT.  */
240
static inline void
241
link_imm_use_stmt (ssa_use_operand_t *linknode, tree def, gimple stmt)
242
{
243
  if (stmt)
244
    link_imm_use (linknode, def);
245
  else
246
    link_imm_use (linknode, NULL);
247
  linknode->loc.stmt = stmt;
248
}
249
 
250
/* Relink a new node in place of an old node in the list.  */
251
static inline void
252
relink_imm_use (ssa_use_operand_t *node, ssa_use_operand_t *old)
253
{
254
  /* The node one had better be in the same list.  */
255
  gcc_checking_assert (*(old->use) == *(node->use));
256
  node->prev = old->prev;
257
  node->next = old->next;
258
  if (old->prev)
259
    {
260
      old->prev->next = node;
261
      old->next->prev = node;
262
      /* Remove the old node from the list.  */
263
      old->prev = NULL;
264
    }
265
}
266
 
267
/* Relink ssa_imm_use node LINKNODE into the chain for OLD, with use occurring
268
   in STMT.  */
269
static inline void
270
relink_imm_use_stmt (ssa_use_operand_t *linknode, ssa_use_operand_t *old,
271
                     gimple stmt)
272
{
273
  if (stmt)
274
    relink_imm_use (linknode, old);
275
  else
276
    link_imm_use (linknode, NULL);
277
  linknode->loc.stmt = stmt;
278
}
279
 
280
 
281
/* Return true is IMM has reached the end of the immediate use list.  */
282
static inline bool
283
end_readonly_imm_use_p (const imm_use_iterator *imm)
284
{
285
  return (imm->imm_use == imm->end_p);
286
}
287
 
288
/* Initialize iterator IMM to process the list for VAR.  */
289
static inline use_operand_p
290
first_readonly_imm_use (imm_use_iterator *imm, tree var)
291
{
292
  imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
293
  imm->imm_use = imm->end_p->next;
294
#ifdef ENABLE_CHECKING
295
  imm->iter_node.next = imm->imm_use->next;
296
#endif
297
  if (end_readonly_imm_use_p (imm))
298
    return NULL_USE_OPERAND_P;
299
  return imm->imm_use;
300
}
301
 
302
/* Bump IMM to the next use in the list.  */
303
static inline use_operand_p
304
next_readonly_imm_use (imm_use_iterator *imm)
305
{
306
  use_operand_p old = imm->imm_use;
307
 
308
#ifdef ENABLE_CHECKING
309
  /* If this assertion fails, it indicates the 'next' pointer has changed
310
     since the last bump.  This indicates that the list is being modified
311
     via stmt changes, or SET_USE, or somesuch thing, and you need to be
312
     using the SAFE version of the iterator.  */
313
  gcc_assert (imm->iter_node.next == old->next);
314
  imm->iter_node.next = old->next->next;
315
#endif
316
 
317
  imm->imm_use = old->next;
318
  if (end_readonly_imm_use_p (imm))
319
    return NULL_USE_OPERAND_P;
320
  return imm->imm_use;
321
}
322
 
323
/* tree-cfg.c */
324
extern bool has_zero_uses_1 (const ssa_use_operand_t *head);
325
extern bool single_imm_use_1 (const ssa_use_operand_t *head,
326
                              use_operand_p *use_p, gimple *stmt);
327
 
328
/* Return true if VAR has no nondebug uses.  */
329
static inline bool
330
has_zero_uses (const_tree var)
331
{
332
  const ssa_use_operand_t *const ptr = &(SSA_NAME_IMM_USE_NODE (var));
333
 
334
  /* A single use_operand means there is no items in the list.  */
335
  if (ptr == ptr->next)
336
    return true;
337
 
338
  /* If there are debug stmts, we have to look at each use and see
339
     whether there are any nondebug uses.  */
340
  if (!MAY_HAVE_DEBUG_STMTS)
341
    return false;
342
 
343
  return has_zero_uses_1 (ptr);
344
}
345
 
346
/* Return true if VAR has a single nondebug use.  */
347
static inline bool
348
has_single_use (const_tree var)
349
{
350
  const ssa_use_operand_t *const ptr = &(SSA_NAME_IMM_USE_NODE (var));
351
 
352
  /* If there aren't any uses whatsoever, we're done.  */
353
  if (ptr == ptr->next)
354
    return false;
355
 
356
  /* If there's a single use, check that it's not a debug stmt.  */
357
  if (ptr == ptr->next->next)
358
    return !is_gimple_debug (USE_STMT (ptr->next));
359
 
360
  /* If there are debug stmts, we have to look at each of them.  */
361
  if (!MAY_HAVE_DEBUG_STMTS)
362
    return false;
363
 
364
  return single_imm_use_1 (ptr, NULL, NULL);
365
}
366
 
367
 
368
/* If VAR has only a single immediate nondebug use, return true, and
369
   set USE_P and STMT to the use pointer and stmt of occurrence.  */
370
static inline bool
371
single_imm_use (const_tree var, use_operand_p *use_p, gimple *stmt)
372
{
373
  const ssa_use_operand_t *const ptr = &(SSA_NAME_IMM_USE_NODE (var));
374
 
375
  /* If there aren't any uses whatsoever, we're done.  */
376
  if (ptr == ptr->next)
377
    {
378
    return_false:
379
      *use_p = NULL_USE_OPERAND_P;
380
      *stmt = NULL;
381
      return false;
382
    }
383
 
384
  /* If there's a single use, check that it's not a debug stmt.  */
385
  if (ptr == ptr->next->next)
386
    {
387
      if (!is_gimple_debug (USE_STMT (ptr->next)))
388
        {
389
          *use_p = ptr->next;
390
          *stmt = ptr->next->loc.stmt;
391
          return true;
392
        }
393
      else
394
        goto return_false;
395
    }
396
 
397
  /* If there are debug stmts, we have to look at each of them.  */
398
  if (!MAY_HAVE_DEBUG_STMTS)
399
    goto return_false;
400
 
401
  return single_imm_use_1 (ptr, use_p, stmt);
402
}
403
 
404
/* Return the number of nondebug immediate uses of VAR.  */
405
static inline unsigned int
406
num_imm_uses (const_tree var)
407
{
408
  const ssa_use_operand_t *const start = &(SSA_NAME_IMM_USE_NODE (var));
409
  const ssa_use_operand_t *ptr;
410
  unsigned int num = 0;
411
 
412
  if (!MAY_HAVE_DEBUG_STMTS)
413
    for (ptr = start->next; ptr != start; ptr = ptr->next)
414
      num++;
415
  else
416
    for (ptr = start->next; ptr != start; ptr = ptr->next)
417
      if (!is_gimple_debug (USE_STMT (ptr)))
418
        num++;
419
 
420
  return num;
421
}
422
 
423
/* Return the tree pointed-to by USE.  */
424
static inline tree
425
get_use_from_ptr (use_operand_p use)
426
{
427
  return *(use->use);
428
}
429
 
430
/* Return the tree pointed-to by DEF.  */
431
static inline tree
432
get_def_from_ptr (def_operand_p def)
433
{
434
  return *def;
435
}
436
 
437
/* Return a use_operand_p pointer for argument I of PHI node GS.  */
438
 
439
static inline use_operand_p
440
gimple_phi_arg_imm_use_ptr (gimple gs, int i)
441
{
442
  return &gimple_phi_arg (gs, i)->imm_use;
443
}
444
 
445
/* Return the tree operand for argument I of PHI node GS.  */
446
 
447
static inline tree
448
gimple_phi_arg_def (gimple gs, size_t index)
449
{
450
  struct phi_arg_d *pd = gimple_phi_arg (gs, index);
451
  return get_use_from_ptr (&pd->imm_use);
452
}
453
 
454
/* Return a pointer to the tree operand for argument I of PHI node GS.  */
455
 
456
static inline tree *
457
gimple_phi_arg_def_ptr (gimple gs, size_t index)
458
{
459
  return &gimple_phi_arg (gs, index)->def;
460
}
461
 
462
/* Return the edge associated with argument I of phi node GS.  */
463
 
464
static inline edge
465
gimple_phi_arg_edge (gimple gs, size_t i)
466
{
467
  return EDGE_PRED (gimple_bb (gs), i);
468
}
469
 
470
/* Return the source location of gimple argument I of phi node GS.  */
471
 
472
static inline source_location
473
gimple_phi_arg_location (gimple gs, size_t i)
474
{
475
  return gimple_phi_arg (gs, i)->locus;
476
}
477
 
478
/* Return the source location of the argument on edge E of phi node GS.  */
479
 
480
static inline source_location
481
gimple_phi_arg_location_from_edge (gimple gs, edge e)
482
{
483
  return gimple_phi_arg (gs, e->dest_idx)->locus;
484
}
485
 
486
/* Set the source location of gimple argument I of phi node GS to LOC.  */
487
 
488
static inline void
489
gimple_phi_arg_set_location (gimple gs, size_t i, source_location loc)
490
{
491
  gimple_phi_arg (gs, i)->locus = loc;
492
}
493
 
494
/* Return TRUE if argument I of phi node GS has a location record.  */
495
 
496
static inline bool
497
gimple_phi_arg_has_location (gimple gs, size_t i)
498
{
499
  return gimple_phi_arg_location (gs, i) != UNKNOWN_LOCATION;
500
}
501
 
502
 
503
/* Return the PHI nodes for basic block BB, or NULL if there are no
504
   PHI nodes.  */
505
static inline gimple_seq
506
phi_nodes (const_basic_block bb)
507
{
508
  gcc_checking_assert (!(bb->flags & BB_RTL));
509
  if (!bb->il.gimple)
510
    return NULL;
511
  return bb->il.gimple->phi_nodes;
512
}
513
 
514
/* Set PHI nodes of a basic block BB to SEQ.  */
515
 
516
static inline void
517
set_phi_nodes (basic_block bb, gimple_seq seq)
518
{
519
  gimple_stmt_iterator i;
520
 
521
  gcc_checking_assert (!(bb->flags & BB_RTL));
522
  bb->il.gimple->phi_nodes = seq;
523
  if (seq)
524
    for (i = gsi_start (seq); !gsi_end_p (i); gsi_next (&i))
525
      gimple_set_bb (gsi_stmt (i), bb);
526
}
527
 
528
/* Return the phi argument which contains the specified use.  */
529
 
530
static inline int
531
phi_arg_index_from_use (use_operand_p use)
532
{
533
  struct phi_arg_d *element, *root;
534
  size_t index;
535
  gimple phi;
536
 
537
  /* Since the use is the first thing in a PHI argument element, we can
538
     calculate its index based on casting it to an argument, and performing
539
     pointer arithmetic.  */
540
 
541
  phi = USE_STMT (use);
542
 
543
  element = (struct phi_arg_d *)use;
544
  root = gimple_phi_arg (phi, 0);
545
  index = element - root;
546
 
547
  /* Make sure the calculation doesn't have any leftover bytes.  If it does,
548
     then imm_use is likely not the first element in phi_arg_d.  */
549
  gcc_checking_assert ((((char *)element - (char *)root)
550
                        % sizeof (struct phi_arg_d)) == 0
551
                       && index < gimple_phi_capacity (phi));
552
 
553
 return index;
554
}
555
 
556
/* Mark VAR as used, so that it'll be preserved during rtl expansion.  */
557
 
558
static inline void
559
set_is_used (tree var)
560
{
561
  var_ann_t ann = var_ann (var);
562
  ann->used = true;
563
}
564
 
565
/* Clear VAR's used flag.  */
566
 
567
static inline void
568
clear_is_used (tree var)
569
{
570
  var_ann_t ann = var_ann (var);
571
  ann->used = false;
572
}
573
 
574
/* Return true if VAR is marked as used.  */
575
 
576
static inline bool
577
is_used_p (tree var)
578
{
579
  var_ann_t ann = var_ann (var);
580
  return ann->used;
581
}
582
 
583
/* Return true if T (assumed to be a DECL) is a global variable.
584
   A variable is considered global if its storage is not automatic.  */
585
 
586
static inline bool
587
is_global_var (const_tree t)
588
{
589
  return (TREE_STATIC (t) || DECL_EXTERNAL (t));
590
}
591
 
592
 
593
/* Return true if VAR may be aliased.  A variable is considered as
594
   maybe aliased if it has its address taken by the local TU
595
   or possibly by another TU and might be modified through a pointer.  */
596
 
597
static inline bool
598
may_be_aliased (const_tree var)
599
{
600
  return (TREE_CODE (var) != CONST_DECL
601
          && !((TREE_STATIC (var) || TREE_PUBLIC (var) || DECL_EXTERNAL (var))
602
               && TREE_READONLY (var)
603
               && !TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (var)))
604
          && (TREE_PUBLIC (var)
605
              || DECL_EXTERNAL (var)
606
              || TREE_ADDRESSABLE (var)));
607
}
608
 
609
 
610
/* PHI nodes should contain only ssa_names and invariants.  A test
611
   for ssa_name is definitely simpler; don't let invalid contents
612
   slip in in the meantime.  */
613
 
614
static inline bool
615
phi_ssa_name_p (const_tree t)
616
{
617
  if (TREE_CODE (t) == SSA_NAME)
618
    return true;
619
  gcc_checking_assert (is_gimple_min_invariant (t));
620
  return false;
621
}
622
 
623
 
624
/* Returns the loop of the statement STMT.  */
625
 
626
static inline struct loop *
627
loop_containing_stmt (gimple stmt)
628
{
629
  basic_block bb = gimple_bb (stmt);
630
  if (!bb)
631
    return NULL;
632
 
633
  return bb->loop_father;
634
}
635
 
636
 
637
/*  -----------------------------------------------------------------------  */
638
 
639
/* The following set of routines are used to iterator over various type of
640
   SSA operands.  */
641
 
642
/* Return true if PTR is finished iterating.  */
643
static inline bool
644
op_iter_done (const ssa_op_iter *ptr)
645
{
646
  return ptr->done;
647
}
648
 
649
/* Get the next iterator use value for PTR.  */
650
static inline use_operand_p
651
op_iter_next_use (ssa_op_iter *ptr)
652
{
653
  use_operand_p use_p;
654
  gcc_checking_assert (ptr->iter_type == ssa_op_iter_use);
655
  if (ptr->uses)
656
    {
657
      use_p = USE_OP_PTR (ptr->uses);
658
      ptr->uses = ptr->uses->next;
659
      return use_p;
660
    }
661
  if (ptr->phi_i < ptr->num_phi)
662
    {
663
      return PHI_ARG_DEF_PTR (ptr->phi_stmt, (ptr->phi_i)++);
664
    }
665
  ptr->done = true;
666
  return NULL_USE_OPERAND_P;
667
}
668
 
669
/* Get the next iterator def value for PTR.  */
670
static inline def_operand_p
671
op_iter_next_def (ssa_op_iter *ptr)
672
{
673
  def_operand_p def_p;
674
  gcc_checking_assert (ptr->iter_type == ssa_op_iter_def);
675
  if (ptr->defs)
676
    {
677
      def_p = DEF_OP_PTR (ptr->defs);
678
      ptr->defs = ptr->defs->next;
679
      return def_p;
680
    }
681
  ptr->done = true;
682
  return NULL_DEF_OPERAND_P;
683
}
684
 
685
/* Get the next iterator tree value for PTR.  */
686
static inline tree
687
op_iter_next_tree (ssa_op_iter *ptr)
688
{
689
  tree val;
690
  gcc_checking_assert (ptr->iter_type == ssa_op_iter_tree);
691
  if (ptr->uses)
692
    {
693
      val = USE_OP (ptr->uses);
694
      ptr->uses = ptr->uses->next;
695
      return val;
696
    }
697
  if (ptr->defs)
698
    {
699
      val = DEF_OP (ptr->defs);
700
      ptr->defs = ptr->defs->next;
701
      return val;
702
    }
703
 
704
  ptr->done = true;
705
  return NULL_TREE;
706
 
707
}
708
 
709
 
710
/* This functions clears the iterator PTR, and marks it done.  This is normally
711
   used to prevent warnings in the compile about might be uninitialized
712
   components.  */
713
 
714
static inline void
715
clear_and_done_ssa_iter (ssa_op_iter *ptr)
716
{
717
  ptr->defs = NULL;
718
  ptr->uses = NULL;
719
  ptr->iter_type = ssa_op_iter_none;
720
  ptr->phi_i = 0;
721
  ptr->num_phi = 0;
722
  ptr->phi_stmt = NULL;
723
  ptr->done = true;
724
}
725
 
726
/* Initialize the iterator PTR to the virtual defs in STMT.  */
727
static inline void
728
op_iter_init (ssa_op_iter *ptr, gimple stmt, int flags)
729
{
730
  /* PHI nodes require a different iterator initialization path.  We
731
     do not support iterating over virtual defs or uses without
732
     iterating over defs or uses at the same time.  */
733
  gcc_checking_assert (gimple_code (stmt) != GIMPLE_PHI
734
                       && (!(flags & SSA_OP_VDEF) || (flags & SSA_OP_DEF))
735
                       && (!(flags & SSA_OP_VUSE) || (flags & SSA_OP_USE)));
736
  ptr->defs = (flags & (SSA_OP_DEF|SSA_OP_VDEF)) ? gimple_def_ops (stmt) : NULL;
737
  if (!(flags & SSA_OP_VDEF)
738
      && ptr->defs
739
      && gimple_vdef (stmt) != NULL_TREE)
740
    ptr->defs = ptr->defs->next;
741
  ptr->uses = (flags & (SSA_OP_USE|SSA_OP_VUSE)) ? gimple_use_ops (stmt) : NULL;
742
  if (!(flags & SSA_OP_VUSE)
743
      && ptr->uses
744
      && gimple_vuse (stmt) != NULL_TREE)
745
    ptr->uses = ptr->uses->next;
746
  ptr->done = false;
747
 
748
  ptr->phi_i = 0;
749
  ptr->num_phi = 0;
750
  ptr->phi_stmt = NULL;
751
}
752
 
753
/* Initialize iterator PTR to the use operands in STMT based on FLAGS. Return
754
   the first use.  */
755
static inline use_operand_p
756
op_iter_init_use (ssa_op_iter *ptr, gimple stmt, int flags)
757
{
758
  gcc_checking_assert ((flags & SSA_OP_ALL_DEFS) == 0
759
                       && (flags & SSA_OP_USE));
760
  op_iter_init (ptr, stmt, flags);
761
  ptr->iter_type = ssa_op_iter_use;
762
  return op_iter_next_use (ptr);
763
}
764
 
765
/* Initialize iterator PTR to the def operands in STMT based on FLAGS. Return
766
   the first def.  */
767
static inline def_operand_p
768
op_iter_init_def (ssa_op_iter *ptr, gimple stmt, int flags)
769
{
770
  gcc_checking_assert ((flags & SSA_OP_ALL_USES) == 0
771
                       && (flags & SSA_OP_DEF));
772
  op_iter_init (ptr, stmt, flags);
773
  ptr->iter_type = ssa_op_iter_def;
774
  return op_iter_next_def (ptr);
775
}
776
 
777
/* Initialize iterator PTR to the operands in STMT based on FLAGS. Return
778
   the first operand as a tree.  */
779
static inline tree
780
op_iter_init_tree (ssa_op_iter *ptr, gimple stmt, int flags)
781
{
782
  op_iter_init (ptr, stmt, flags);
783
  ptr->iter_type = ssa_op_iter_tree;
784
  return op_iter_next_tree (ptr);
785
}
786
 
787
 
788
/* If there is a single operand in STMT matching FLAGS, return it.  Otherwise
789
   return NULL.  */
790
static inline tree
791
single_ssa_tree_operand (gimple stmt, int flags)
792
{
793
  tree var;
794
  ssa_op_iter iter;
795
 
796
  var = op_iter_init_tree (&iter, stmt, flags);
797
  if (op_iter_done (&iter))
798
    return NULL_TREE;
799
  op_iter_next_tree (&iter);
800
  if (op_iter_done (&iter))
801
    return var;
802
  return NULL_TREE;
803
}
804
 
805
 
806
/* If there is a single operand in STMT matching FLAGS, return it.  Otherwise
807
   return NULL.  */
808
static inline use_operand_p
809
single_ssa_use_operand (gimple stmt, int flags)
810
{
811
  use_operand_p var;
812
  ssa_op_iter iter;
813
 
814
  var = op_iter_init_use (&iter, stmt, flags);
815
  if (op_iter_done (&iter))
816
    return NULL_USE_OPERAND_P;
817
  op_iter_next_use (&iter);
818
  if (op_iter_done (&iter))
819
    return var;
820
  return NULL_USE_OPERAND_P;
821
}
822
 
823
 
824
 
825
/* If there is a single operand in STMT matching FLAGS, return it.  Otherwise
826
   return NULL.  */
827
static inline def_operand_p
828
single_ssa_def_operand (gimple stmt, int flags)
829
{
830
  def_operand_p var;
831
  ssa_op_iter iter;
832
 
833
  var = op_iter_init_def (&iter, stmt, flags);
834
  if (op_iter_done (&iter))
835
    return NULL_DEF_OPERAND_P;
836
  op_iter_next_def (&iter);
837
  if (op_iter_done (&iter))
838
    return var;
839
  return NULL_DEF_OPERAND_P;
840
}
841
 
842
 
843
/* Return true if there are zero operands in STMT matching the type
844
   given in FLAGS.  */
845
static inline bool
846
zero_ssa_operands (gimple stmt, int flags)
847
{
848
  ssa_op_iter iter;
849
 
850
  op_iter_init_tree (&iter, stmt, flags);
851
  return op_iter_done (&iter);
852
}
853
 
854
 
855
/* Return the number of operands matching FLAGS in STMT.  */
856
static inline int
857
num_ssa_operands (gimple stmt, int flags)
858
{
859
  ssa_op_iter iter;
860
  tree t;
861
  int num = 0;
862
 
863
  gcc_checking_assert (gimple_code (stmt) != GIMPLE_PHI);
864
  FOR_EACH_SSA_TREE_OPERAND (t, stmt, iter, flags)
865
    num++;
866
  return num;
867
}
868
 
869
static inline use_operand_p
870
op_iter_init_phiuse (ssa_op_iter *ptr, gimple phi, int flags);
871
 
872
/* Delink all immediate_use information for STMT.  */
873
static inline void
874
delink_stmt_imm_use (gimple stmt)
875
{
876
   ssa_op_iter iter;
877
   use_operand_p use_p;
878
 
879
   if (ssa_operands_active ())
880
     FOR_EACH_PHI_OR_STMT_USE (use_p, stmt, iter, SSA_OP_ALL_USES)
881
       delink_imm_use (use_p);
882
}
883
 
884
 
885
/* If there is a single DEF in the PHI node which matches FLAG, return it.
886
   Otherwise return NULL_DEF_OPERAND_P.  */
887
static inline tree
888
single_phi_def (gimple stmt, int flags)
889
{
890
  tree def = PHI_RESULT (stmt);
891
  if ((flags & SSA_OP_DEF) && is_gimple_reg (def))
892
    return def;
893
  if ((flags & SSA_OP_VIRTUAL_DEFS) && !is_gimple_reg (def))
894
    return def;
895
  return NULL_TREE;
896
}
897
 
898
/* Initialize the iterator PTR for uses matching FLAGS in PHI.  FLAGS should
899
   be either SSA_OP_USES or SSA_OP_VIRTUAL_USES.  */
900
static inline use_operand_p
901
op_iter_init_phiuse (ssa_op_iter *ptr, gimple phi, int flags)
902
{
903
  tree phi_def = gimple_phi_result (phi);
904
  int comp;
905
 
906
  clear_and_done_ssa_iter (ptr);
907
  ptr->done = false;
908
 
909
  gcc_checking_assert ((flags & (SSA_OP_USE | SSA_OP_VIRTUAL_USES)) != 0);
910
 
911
  comp = (is_gimple_reg (phi_def) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
912
 
913
  /* If the PHI node doesn't the operand type we care about, we're done.  */
914
  if ((flags & comp) == 0)
915
    {
916
      ptr->done = true;
917
      return NULL_USE_OPERAND_P;
918
    }
919
 
920
  ptr->phi_stmt = phi;
921
  ptr->num_phi = gimple_phi_num_args (phi);
922
  ptr->iter_type = ssa_op_iter_use;
923
  return op_iter_next_use (ptr);
924
}
925
 
926
 
927
/* Start an iterator for a PHI definition.  */
928
 
929
static inline def_operand_p
930
op_iter_init_phidef (ssa_op_iter *ptr, gimple phi, int flags)
931
{
932
  tree phi_def = PHI_RESULT (phi);
933
  int comp;
934
 
935
  clear_and_done_ssa_iter (ptr);
936
  ptr->done = false;
937
 
938
  gcc_checking_assert ((flags & (SSA_OP_DEF | SSA_OP_VIRTUAL_DEFS)) != 0);
939
 
940
  comp = (is_gimple_reg (phi_def) ? SSA_OP_DEF : SSA_OP_VIRTUAL_DEFS);
941
 
942
  /* If the PHI node doesn't have the operand type we care about,
943
     we're done.  */
944
  if ((flags & comp) == 0)
945
    {
946
      ptr->done = true;
947
      return NULL_DEF_OPERAND_P;
948
    }
949
 
950
  ptr->iter_type = ssa_op_iter_def;
951
  /* The first call to op_iter_next_def will terminate the iterator since
952
     all the fields are NULL.  Simply return the result here as the first and
953
     therefore only result.  */
954
  return PHI_RESULT_PTR (phi);
955
}
956
 
957
/* Return true is IMM has reached the end of the immediate use stmt list.  */
958
 
959
static inline bool
960
end_imm_use_stmt_p (const imm_use_iterator *imm)
961
{
962
  return (imm->imm_use == imm->end_p);
963
}
964
 
965
/* Finished the traverse of an immediate use stmt list IMM by removing the
966
   placeholder node from the list.  */
967
 
968
static inline void
969
end_imm_use_stmt_traverse (imm_use_iterator *imm)
970
{
971
  delink_imm_use (&(imm->iter_node));
972
}
973
 
974
/* Immediate use traversal of uses within a stmt require that all the
975
   uses on a stmt be sequentially listed.  This routine is used to build up
976
   this sequential list by adding USE_P to the end of the current list
977
   currently delimited by HEAD and LAST_P.  The new LAST_P value is
978
   returned.  */
979
 
980
static inline use_operand_p
981
move_use_after_head (use_operand_p use_p, use_operand_p head,
982
                      use_operand_p last_p)
983
{
984
  gcc_checking_assert (USE_FROM_PTR (use_p) == USE_FROM_PTR (head));
985
  /* Skip head when we find it.  */
986
  if (use_p != head)
987
    {
988
      /* If use_p is already linked in after last_p, continue.  */
989
      if (last_p->next == use_p)
990
        last_p = use_p;
991
      else
992
        {
993
          /* Delink from current location, and link in at last_p.  */
994
          delink_imm_use (use_p);
995
          link_imm_use_to_list (use_p, last_p);
996
          last_p = use_p;
997
        }
998
    }
999
  return last_p;
1000
}
1001
 
1002
 
1003
/* This routine will relink all uses with the same stmt as HEAD into the list
1004
   immediately following HEAD for iterator IMM.  */
1005
 
1006
static inline void
1007
link_use_stmts_after (use_operand_p head, imm_use_iterator *imm)
1008
{
1009
  use_operand_p use_p;
1010
  use_operand_p last_p = head;
1011
  gimple head_stmt = USE_STMT (head);
1012
  tree use = USE_FROM_PTR (head);
1013
  ssa_op_iter op_iter;
1014
  int flag;
1015
 
1016
  /* Only look at virtual or real uses, depending on the type of HEAD.  */
1017
  flag = (is_gimple_reg (use) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
1018
 
1019
  if (gimple_code (head_stmt) == GIMPLE_PHI)
1020
    {
1021
      FOR_EACH_PHI_ARG (use_p, head_stmt, op_iter, flag)
1022
        if (USE_FROM_PTR (use_p) == use)
1023
          last_p = move_use_after_head (use_p, head, last_p);
1024
    }
1025
  else
1026
    {
1027
      if (flag == SSA_OP_USE)
1028
        {
1029
          FOR_EACH_SSA_USE_OPERAND (use_p, head_stmt, op_iter, flag)
1030
            if (USE_FROM_PTR (use_p) == use)
1031
              last_p = move_use_after_head (use_p, head, last_p);
1032
        }
1033
      else if ((use_p = gimple_vuse_op (head_stmt)) != NULL_USE_OPERAND_P)
1034
        {
1035
          if (USE_FROM_PTR (use_p) == use)
1036
            last_p = move_use_after_head (use_p, head, last_p);
1037
        }
1038
    }
1039
  /* Link iter node in after last_p.  */
1040
  if (imm->iter_node.prev != NULL)
1041
    delink_imm_use (&imm->iter_node);
1042
  link_imm_use_to_list (&(imm->iter_node), last_p);
1043
}
1044
 
1045
/* Initialize IMM to traverse over uses of VAR.  Return the first statement.  */
1046
static inline gimple
1047
first_imm_use_stmt (imm_use_iterator *imm, tree var)
1048
{
1049
  imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
1050
  imm->imm_use = imm->end_p->next;
1051
  imm->next_imm_name = NULL_USE_OPERAND_P;
1052
 
1053
  /* iter_node is used as a marker within the immediate use list to indicate
1054
     where the end of the current stmt's uses are.  Initialize it to NULL
1055
     stmt and use, which indicates a marker node.  */
1056
  imm->iter_node.prev = NULL_USE_OPERAND_P;
1057
  imm->iter_node.next = NULL_USE_OPERAND_P;
1058
  imm->iter_node.loc.stmt = NULL;
1059
  imm->iter_node.use = NULL;
1060
 
1061
  if (end_imm_use_stmt_p (imm))
1062
    return NULL;
1063
 
1064
  link_use_stmts_after (imm->imm_use, imm);
1065
 
1066
  return USE_STMT (imm->imm_use);
1067
}
1068
 
1069
/* Bump IMM to the next stmt which has a use of var.  */
1070
 
1071
static inline gimple
1072
next_imm_use_stmt (imm_use_iterator *imm)
1073
{
1074
  imm->imm_use = imm->iter_node.next;
1075
  if (end_imm_use_stmt_p (imm))
1076
    {
1077
      if (imm->iter_node.prev != NULL)
1078
        delink_imm_use (&imm->iter_node);
1079
      return NULL;
1080
    }
1081
 
1082
  link_use_stmts_after (imm->imm_use, imm);
1083
  return USE_STMT (imm->imm_use);
1084
}
1085
 
1086
/* This routine will return the first use on the stmt IMM currently refers
1087
   to.  */
1088
 
1089
static inline use_operand_p
1090
first_imm_use_on_stmt (imm_use_iterator *imm)
1091
{
1092
  imm->next_imm_name = imm->imm_use->next;
1093
  return imm->imm_use;
1094
}
1095
 
1096
/*  Return TRUE if the last use on the stmt IMM refers to has been visited.  */
1097
 
1098
static inline bool
1099
end_imm_use_on_stmt_p (const imm_use_iterator *imm)
1100
{
1101
  return (imm->imm_use == &(imm->iter_node));
1102
}
1103
 
1104
/* Bump to the next use on the stmt IMM refers to, return NULL if done.  */
1105
 
1106
static inline use_operand_p
1107
next_imm_use_on_stmt (imm_use_iterator *imm)
1108
{
1109
  imm->imm_use = imm->next_imm_name;
1110
  if (end_imm_use_on_stmt_p (imm))
1111
    return NULL_USE_OPERAND_P;
1112
  else
1113
    {
1114
      imm->next_imm_name = imm->imm_use->next;
1115
      return imm->imm_use;
1116
    }
1117
}
1118
 
1119
/* Return true if VAR cannot be modified by the program.  */
1120
 
1121
static inline bool
1122
unmodifiable_var_p (const_tree var)
1123
{
1124
  if (TREE_CODE (var) == SSA_NAME)
1125
    var = SSA_NAME_VAR (var);
1126
 
1127
  return TREE_READONLY (var) && (TREE_STATIC (var) || DECL_EXTERNAL (var));
1128
}
1129
 
1130
/* Return true if REF, a handled component reference, has an ARRAY_REF
1131
   somewhere in it.  */
1132
 
1133
static inline bool
1134
ref_contains_array_ref (const_tree ref)
1135
{
1136
  gcc_checking_assert (handled_component_p (ref));
1137
 
1138
  do {
1139
    if (TREE_CODE (ref) == ARRAY_REF)
1140
      return true;
1141
    ref = TREE_OPERAND (ref, 0);
1142
  } while (handled_component_p (ref));
1143
 
1144
  return false;
1145
}
1146
 
1147
/* Return true if REF has an VIEW_CONVERT_EXPR somewhere in it.  */
1148
 
1149
static inline bool
1150
contains_view_convert_expr_p (const_tree ref)
1151
{
1152
  while (handled_component_p (ref))
1153
    {
1154
      if (TREE_CODE (ref) == VIEW_CONVERT_EXPR)
1155
        return true;
1156
      ref = TREE_OPERAND (ref, 0);
1157
    }
1158
 
1159
  return false;
1160
}
1161
 
1162
/* Return true, if the two ranges [POS1, SIZE1] and [POS2, SIZE2]
1163
   overlap.  SIZE1 and/or SIZE2 can be (unsigned)-1 in which case the
1164
   range is open-ended.  Otherwise return false.  */
1165
 
1166
static inline bool
1167
ranges_overlap_p (unsigned HOST_WIDE_INT pos1,
1168
                  unsigned HOST_WIDE_INT size1,
1169
                  unsigned HOST_WIDE_INT pos2,
1170
                  unsigned HOST_WIDE_INT size2)
1171
{
1172
  if (pos1 >= pos2
1173
      && (size2 == (unsigned HOST_WIDE_INT)-1
1174
          || pos1 < (pos2 + size2)))
1175
    return true;
1176
  if (pos2 >= pos1
1177
      && (size1 == (unsigned HOST_WIDE_INT)-1
1178
          || pos2 < (pos1 + size1)))
1179
    return true;
1180
 
1181
  return false;
1182
}
1183
 
1184
/* Accessor to tree-ssa-operands.c caches.  */
1185
static inline struct ssa_operands *
1186
gimple_ssa_operands (const struct function *fun)
1187
{
1188
  return &fun->gimple_df->ssa_operands;
1189
}
1190
 
1191
/* Given an edge_var_map V, return the PHI arg definition.  */
1192
 
1193
static inline tree
1194
redirect_edge_var_map_def (edge_var_map *v)
1195
{
1196
  return v->def;
1197
}
1198
 
1199
/* Given an edge_var_map V, return the PHI result.  */
1200
 
1201
static inline tree
1202
redirect_edge_var_map_result (edge_var_map *v)
1203
{
1204
  return v->result;
1205
}
1206
 
1207
/* Given an edge_var_map V, return the PHI arg location.  */
1208
 
1209
static inline source_location
1210
redirect_edge_var_map_location (edge_var_map *v)
1211
{
1212
  return v->locus;
1213
}
1214
 
1215
 
1216
/* Return an SSA_NAME node for variable VAR defined in statement STMT
1217
   in function cfun.  */
1218
 
1219
static inline tree
1220
make_ssa_name (tree var, gimple stmt)
1221
{
1222
  return make_ssa_name_fn (cfun, var, stmt);
1223
}
1224
 
1225
/* Returns the base object and a constant BITS_PER_UNIT offset in *POFFSET that
1226
   denotes the starting address of the memory access EXP.
1227
   Returns NULL_TREE if the offset is not constant or any component
1228
   is not BITS_PER_UNIT-aligned.
1229
   VALUEIZE if non-NULL is used to valueize SSA names.  It should return
1230
   its argument or a constant if the argument is known to be constant.  */
1231
 
1232
static inline tree
1233
get_addr_base_and_unit_offset_1 (tree exp, HOST_WIDE_INT *poffset,
1234
                                 tree (*valueize) (tree))
1235
{
1236
  HOST_WIDE_INT byte_offset = 0;
1237
 
1238
  /* Compute cumulative byte-offset for nested component-refs and array-refs,
1239
     and find the ultimate containing object.  */
1240
  while (1)
1241
    {
1242
      switch (TREE_CODE (exp))
1243
        {
1244
        case BIT_FIELD_REF:
1245
          return NULL_TREE;
1246
 
1247
        case COMPONENT_REF:
1248
          {
1249
            tree field = TREE_OPERAND (exp, 1);
1250
            tree this_offset = component_ref_field_offset (exp);
1251
            HOST_WIDE_INT hthis_offset;
1252
 
1253
            if (!this_offset
1254
                || TREE_CODE (this_offset) != INTEGER_CST
1255
                || (TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (field))
1256
                    % BITS_PER_UNIT))
1257
              return NULL_TREE;
1258
 
1259
            hthis_offset = TREE_INT_CST_LOW (this_offset);
1260
            hthis_offset += (TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (field))
1261
                             / BITS_PER_UNIT);
1262
            byte_offset += hthis_offset;
1263
          }
1264
          break;
1265
 
1266
        case ARRAY_REF:
1267
        case ARRAY_RANGE_REF:
1268
          {
1269
            tree index = TREE_OPERAND (exp, 1);
1270
            tree low_bound, unit_size;
1271
 
1272
            if (valueize
1273
                && TREE_CODE (index) == SSA_NAME)
1274
              index = (*valueize) (index);
1275
 
1276
            /* If the resulting bit-offset is constant, track it.  */
1277
            if (TREE_CODE (index) == INTEGER_CST
1278
                && (low_bound = array_ref_low_bound (exp),
1279
                    TREE_CODE (low_bound) == INTEGER_CST)
1280
                && (unit_size = array_ref_element_size (exp),
1281
                    TREE_CODE (unit_size) == INTEGER_CST))
1282
              {
1283
                HOST_WIDE_INT hindex = TREE_INT_CST_LOW (index);
1284
 
1285
                hindex -= TREE_INT_CST_LOW (low_bound);
1286
                hindex *= TREE_INT_CST_LOW (unit_size);
1287
                byte_offset += hindex;
1288
              }
1289
            else
1290
              return NULL_TREE;
1291
          }
1292
          break;
1293
 
1294
        case REALPART_EXPR:
1295
          break;
1296
 
1297
        case IMAGPART_EXPR:
1298
          byte_offset += TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (exp)));
1299
          break;
1300
 
1301
        case VIEW_CONVERT_EXPR:
1302
          break;
1303
 
1304
        case MEM_REF:
1305
          {
1306
            tree base = TREE_OPERAND (exp, 0);
1307
            if (valueize
1308
                && TREE_CODE (base) == SSA_NAME)
1309
              base = (*valueize) (base);
1310
 
1311
            /* Hand back the decl for MEM[&decl, off].  */
1312
            if (TREE_CODE (base) == ADDR_EXPR)
1313
              {
1314
                if (!integer_zerop (TREE_OPERAND (exp, 1)))
1315
                  {
1316
                    double_int off = mem_ref_offset (exp);
1317
                    gcc_assert (off.high == -1 || off.high == 0);
1318
                    byte_offset += double_int_to_shwi (off);
1319
                  }
1320
                exp = TREE_OPERAND (base, 0);
1321
              }
1322
            goto done;
1323
          }
1324
 
1325
        case TARGET_MEM_REF:
1326
          {
1327
            tree base = TREE_OPERAND (exp, 0);
1328
            if (valueize
1329
                && TREE_CODE (base) == SSA_NAME)
1330
              base = (*valueize) (base);
1331
 
1332
            /* Hand back the decl for MEM[&decl, off].  */
1333
            if (TREE_CODE (base) == ADDR_EXPR)
1334
              {
1335
                if (TMR_INDEX (exp) || TMR_INDEX2 (exp))
1336
                  return NULL_TREE;
1337
                if (!integer_zerop (TMR_OFFSET (exp)))
1338
                  {
1339
                    double_int off = mem_ref_offset (exp);
1340
                    gcc_assert (off.high == -1 || off.high == 0);
1341
                    byte_offset += double_int_to_shwi (off);
1342
                  }
1343
                exp = TREE_OPERAND (base, 0);
1344
              }
1345
            goto done;
1346
          }
1347
 
1348
        default:
1349
          goto done;
1350
        }
1351
 
1352
      exp = TREE_OPERAND (exp, 0);
1353
    }
1354
done:
1355
 
1356
  *poffset = byte_offset;
1357
  return exp;
1358
}
1359
 
1360
#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.