]> gcc.gnu.org Git - gcc.git/blame - gcc/tree-flow-inline.h
re PR c++/16276 ([3.4 only] G++ generates local references to linkonce sections)
[gcc.git] / gcc / tree-flow-inline.h
CommitLineData
6de9cd9a
DN
1/* Inline functions for tree-flow.h
2 Copyright (C) 2001, 2003 Free Software Foundation, Inc.
3 Contributed by Diego Novillo <dnovillo@redhat.com>
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12GCC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING. If not, write to
19the Free Software Foundation, 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA. */
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
0566b51e
DB
28/* Return the variable annotation for T, which must be a _DECL node.
29 Return NULL if the variable annotation doesn't already exist. */
6de9cd9a
DN
30static inline var_ann_t
31var_ann (tree t)
32{
33#if defined ENABLE_CHECKING
34 if (t == NULL_TREE
35 || !DECL_P (t)
36 || (t->common.ann
37 && t->common.ann->common.type != VAR_ANN))
38 abort ();
39#endif
40
41 return (var_ann_t) t->common.ann;
42}
43
0566b51e
DB
44/* Return the variable annotation for T, which must be a _DECL node.
45 Create the variable annotation if it doesn't exist. */
6de9cd9a
DN
46static inline var_ann_t
47get_var_ann (tree var)
48{
49 var_ann_t ann = var_ann (var);
50 return (ann) ? ann : create_var_ann (var);
51}
52
0566b51e
DB
53/* Return the statement annotation for T, which must be a statement
54 node. Return NULL if the statement annotation doesn't exist. */
6de9cd9a
DN
55static inline stmt_ann_t
56stmt_ann (tree t)
57{
58#if defined ENABLE_CHECKING
c8a6f154 59 if (!is_gimple_stmt (t))
6de9cd9a
DN
60 abort ();
61#endif
62
63 return (stmt_ann_t) t->common.ann;
64}
65
0566b51e
DB
66/* Return the statement annotation for T, which must be a statement
67 node. Create the statement annotation if it doesn't exist. */
6de9cd9a
DN
68static inline stmt_ann_t
69get_stmt_ann (tree stmt)
70{
71 stmt_ann_t ann = stmt_ann (stmt);
72 return (ann) ? ann : create_stmt_ann (stmt);
73}
74
6de9cd9a 75
0566b51e 76/* Return the annotation type for annotation ANN. */
6de9cd9a 77static inline enum tree_ann_type
06d72ee6 78ann_type (tree_ann_t ann)
6de9cd9a
DN
79{
80 return ann->common.type;
81}
82
0566b51e 83/* Return the basic block for statement T. */
6de9cd9a
DN
84static inline basic_block
85bb_for_stmt (tree t)
86{
87 stmt_ann_t ann = stmt_ann (t);
88 return ann ? ann->bb : NULL;
89}
90
0566b51e
DB
91/* Return the may_aliases varray for variable VAR, or NULL if it has
92 no may aliases. */
6de9cd9a
DN
93static inline varray_type
94may_aliases (tree var)
95{
96 var_ann_t ann = var_ann (var);
97 return ann ? ann->may_aliases : NULL;
98}
99
0566b51e
DB
100/* Return the line number for EXPR, or return -1 if we have no line
101 number information for it. */
6de9cd9a
DN
102static inline int
103get_lineno (tree expr)
104{
105 if (expr == NULL_TREE)
106 return -1;
107
108 if (TREE_CODE (expr) == COMPOUND_EXPR)
109 expr = TREE_OPERAND (expr, 0);
110
9506ac2b 111 if (! EXPR_HAS_LOCATION (expr))
6de9cd9a
DN
112 return -1;
113
114 return EXPR_LINENO (expr);
115}
116
0566b51e
DB
117/* Return the file name for EXPR, or return "???" if we have no
118 filename information. */
6de9cd9a
DN
119static inline const char *
120get_filename (tree expr)
121{
9506ac2b 122 const char *filename;
6de9cd9a
DN
123 if (expr == NULL_TREE)
124 return "???";
125
126 if (TREE_CODE (expr) == COMPOUND_EXPR)
127 expr = TREE_OPERAND (expr, 0);
128
9506ac2b
PB
129 if (EXPR_HAS_LOCATION (expr) && (filename = EXPR_FILENAME (expr)))
130 return filename;
6de9cd9a
DN
131 else
132 return "???";
133}
134
0566b51e 135/* Mark statement T as modified. */
6de9cd9a
DN
136static inline void
137modify_stmt (tree t)
138{
139 stmt_ann_t ann = stmt_ann (t);
140 if (ann == NULL)
141 ann = create_stmt_ann (t);
142 ann->modified = 1;
143}
144
0566b51e 145/* Mark statement T as unmodified. */
6de9cd9a
DN
146static inline void
147unmodify_stmt (tree t)
148{
149 stmt_ann_t ann = stmt_ann (t);
150 if (ann == NULL)
151 ann = create_stmt_ann (t);
152 ann->modified = 0;
153}
154
0566b51e 155/* Return true if T is marked as modified, false otherwise. */
6de9cd9a
DN
156static inline bool
157stmt_modified_p (tree t)
158{
159 stmt_ann_t ann = stmt_ann (t);
160
161 /* Note that if the statement doesn't yet have an annotation, we consider it
162 modified. This will force the next call to get_stmt_operands to scan the
163 statement. */
164 return ann ? ann->modified : true;
165}
166
0566b51e
DB
167/* Return the definitions present in ANN, a statement annotation.
168 Return NULL if this annotation contains no definitions. */
6de9cd9a
DN
169static inline def_optype
170get_def_ops (stmt_ann_t ann)
171{
1a24f92f 172 return ann ? ann->operands.def_ops : NULL;
6de9cd9a
DN
173}
174
0566b51e
DB
175/* Return the uses present in ANN, a statement annotation.
176 Return NULL if this annotation contains no uses. */
6de9cd9a
DN
177static inline use_optype
178get_use_ops (stmt_ann_t ann)
179{
1a24f92f 180 return ann ? ann->operands.use_ops : NULL;
6de9cd9a
DN
181}
182
0566b51e
DB
183/* Return the virtual may-defs present in ANN, a statement
184 annotation.
185 Return NULL if this annotation contains no virtual may-defs. */
a32b97a2
BB
186static inline v_may_def_optype
187get_v_may_def_ops (stmt_ann_t ann)
6de9cd9a 188{
1a24f92f 189 return ann ? ann->operands.v_may_def_ops : NULL;
6de9cd9a
DN
190}
191
0566b51e
DB
192/* Return the virtual uses present in ANN, a statement annotation.
193 Return NULL if this annotation contains no virtual uses. */
6de9cd9a
DN
194static inline vuse_optype
195get_vuse_ops (stmt_ann_t ann)
196{
1a24f92f 197 return ann ? ann->operands.vuse_ops : NULL;
6de9cd9a
DN
198}
199
0566b51e
DB
200/* Return the virtual must-defs present in ANN, a statement
201 annotation. Return NULL if this annotation contains no must-defs.*/
a32b97a2
BB
202static inline v_must_def_optype
203get_v_must_def_ops (stmt_ann_t ann)
204{
1a24f92f 205 return ann ? ann->operands.v_must_def_ops : NULL;
a32b97a2
BB
206}
207
d00ad49b
AM
208/* Return the tree pointer to by USE. */
209static inline tree
210get_use_from_ptr (use_operand_p use)
211{
212 return *(use.use);
213}
214
215/* Return the tree pointer to by DEF. */
216static inline tree
217get_def_from_ptr (def_operand_p def)
218{
219 return *(def.def);
220}
221
0566b51e 222/* Return a pointer to the tree that is at INDEX in the USES array. */
d00ad49b 223static inline use_operand_p
6de9cd9a
DN
224get_use_op_ptr (use_optype uses, unsigned int index)
225{
226#ifdef ENABLE_CHECKING
227 if (index >= uses->num_uses)
228 abort();
229#endif
230 return uses->uses[index];
231}
232
d00ad49b
AM
233/* Return a def_operand_p pointer for element INDEX of DEFS. */
234static inline def_operand_p
6de9cd9a
DN
235get_def_op_ptr (def_optype defs, unsigned int index)
236{
237#ifdef ENABLE_CHECKING
238 if (index >= defs->num_defs)
239 abort();
240#endif
241 return defs->defs[index];
242}
243
0566b51e 244
d00ad49b 245/* Return the def_operand_p that is the V_MAY_DEF_RESULT for the V_MAY_DEF
0566b51e 246 at INDEX in the V_MAY_DEFS array. */
d00ad49b 247static inline def_operand_p
a32b97a2 248get_v_may_def_result_ptr(v_may_def_optype v_may_defs, unsigned int index)
6de9cd9a 249{
d00ad49b 250 def_operand_p op;
6de9cd9a 251#ifdef ENABLE_CHECKING
a32b97a2 252 if (index >= v_may_defs->num_v_may_defs)
6de9cd9a
DN
253 abort();
254#endif
1a24f92f 255 op.def = &(v_may_defs->v_may_defs[index].def);
d00ad49b 256 return op;
6de9cd9a
DN
257}
258
d00ad49b 259/* Return a use_operand_p that is the V_MAY_DEF_OP for the V_MAY_DEF at
0566b51e 260 INDEX in the V_MAY_DEFS array. */
d00ad49b 261static inline use_operand_p
a32b97a2 262get_v_may_def_op_ptr(v_may_def_optype v_may_defs, unsigned int index)
6de9cd9a 263{
d00ad49b 264 use_operand_p op;
6de9cd9a 265#ifdef ENABLE_CHECKING
a32b97a2 266 if (index >= v_may_defs->num_v_may_defs)
6de9cd9a
DN
267 abort();
268#endif
1a24f92f 269 op.use = &(v_may_defs->v_may_defs[index].use);
d00ad49b 270 return op;
6de9cd9a
DN
271}
272
d00ad49b
AM
273/* Return a use_operand_p that is at INDEX in the VUSES array. */
274static inline use_operand_p
6de9cd9a
DN
275get_vuse_op_ptr(vuse_optype vuses, unsigned int index)
276{
d00ad49b 277 use_operand_p op;
6de9cd9a
DN
278#ifdef ENABLE_CHECKING
279 if (index >= vuses->num_vuses)
280 abort();
281#endif
d00ad49b
AM
282 op.use = &(vuses->vuses[index]);
283 return op;
6de9cd9a
DN
284}
285
d00ad49b 286/* Return a def_operand_p that is the V_MUST_DEF_OP for the
0566b51e 287 V_MUST_DEF at INDEX in the V_MUST_DEFS array. */
d00ad49b 288static inline def_operand_p
a32b97a2
BB
289get_v_must_def_op_ptr (v_must_def_optype v_must_defs, unsigned int index)
290{
d00ad49b 291 def_operand_p op;
a32b97a2
BB
292#ifdef ENABLE_CHECKING
293 if (index >= v_must_defs->num_v_must_defs)
294 abort();
295#endif
d00ad49b
AM
296 op.def = &(v_must_defs->v_must_defs[index]);
297 return op;
298}
299
300/* Return a def_operand_p pointer for the result of PHI. */
301static inline def_operand_p
302get_phi_result_ptr (tree phi)
303{
304 def_operand_p op;
305 op.def = &(PHI_RESULT_TREE (phi));
306 return op;
a32b97a2
BB
307}
308
d00ad49b
AM
309/* Return a use_operand_p pointer for argument I of phinode PHI. */
310static inline use_operand_p
311get_phi_arg_def_ptr (tree phi, int i)
312{
313 use_operand_p op;
314 op.use = &(PHI_ARG_DEF_TREE (phi, i));
315 return op;
316}
317
0566b51e
DB
318/* Return the bitmap of addresses taken by STMT, or NULL if it takes
319 no addresses. */
6de9cd9a
DN
320static inline bitmap
321addresses_taken (tree stmt)
322{
323 stmt_ann_t ann = stmt_ann (stmt);
324 return ann ? ann->addresses_taken : NULL;
325}
326
0566b51e
DB
327/* Return the immediate uses of STMT, or NULL if this information is
328 not computed. */
6de9cd9a
DN
329static dataflow_t
330get_immediate_uses (tree stmt)
331{
332 stmt_ann_t ann = stmt_ann (stmt);
333 return ann ? ann->df : NULL;
334}
335
0566b51e
DB
336/* Return the number of immediate uses present in the dataflow
337 information at DF. */
6de9cd9a
DN
338static inline int
339num_immediate_uses (dataflow_t df)
340{
341 varray_type imm;
342
343 if (!df)
344 return 0;
345
346 imm = df->immediate_uses;
347 if (!imm)
348 return df->uses[1] ? 2 : 1;
349
350 return VARRAY_ACTIVE_SIZE (imm) + 2;
351}
352
0566b51e 353/* Return the tree that is at NUM in the immediate use DF array. */
6de9cd9a
DN
354static inline tree
355immediate_use (dataflow_t df, int num)
356{
e54d0214
DN
357 if (!df)
358 return NULL_TREE;
359
6de9cd9a
DN
360#ifdef ENABLE_CHECKING
361 if (num >= num_immediate_uses (df))
362 abort ();
363#endif
364 if (num < 2)
365 return df->uses[num];
366 return VARRAY_TREE (df->immediate_uses, num - 2);
367}
368
0566b51e 369/* Return the basic_block annotation for BB. */
6de9cd9a
DN
370static inline bb_ann_t
371bb_ann (basic_block bb)
372{
373 return (bb_ann_t)bb->tree_annotations;
374}
375
0566b51e
DB
376/* Return the PHI nodes for basic block BB, or NULL if there are no
377 PHI nodes. */
6de9cd9a
DN
378static inline tree
379phi_nodes (basic_block bb)
380{
381 if (bb->index < 0)
382 return NULL;
383 return bb_ann (bb)->phi_nodes;
384}
385
386/* Set list of phi nodes of a basic block BB to L. */
387
388static inline void
389set_phi_nodes (basic_block bb, tree l)
390{
391 tree phi;
392
393 bb_ann (bb)->phi_nodes = l;
17192884 394 for (phi = l; phi; phi = PHI_CHAIN (phi))
6de9cd9a
DN
395 set_bb_for_stmt (phi, bb);
396}
397
398/* Return the phi index number for an edge. */
399static inline int
400phi_arg_from_edge (tree phi, edge e)
401{
402 int i;
403#if defined ENABLE_CHECKING
404 if (!phi || TREE_CODE (phi) != PHI_NODE)
405 abort();
406#endif
407
408 for (i = 0; i < PHI_NUM_ARGS (phi); i++)
409 if (PHI_ARG_EDGE (phi, i) == e)
410 return i;
411
412 return -1;
413}
414
727a31fa
RH
415/* Mark VAR as used, so that it'll be preserved during rtl expansion. */
416
417static inline void
418set_is_used (tree var)
419{
420 var_ann_t ann = get_var_ann (var);
421 ann->used = 1;
422}
423
424
6de9cd9a
DN
425/* ----------------------------------------------------------------------- */
426
0566b51e 427/* Return true if T is an executable statement. */
6de9cd9a
DN
428static inline bool
429is_exec_stmt (tree t)
430{
431 return (t && !IS_EMPTY_STMT (t) && t != error_mark_node);
432}
433
434
435/* Return true if this stmt can be the target of a control transfer stmt such
436 as a goto. */
437static inline bool
438is_label_stmt (tree t)
439{
440 if (t)
441 switch (TREE_CODE (t))
442 {
443 case LABEL_DECL:
444 case LABEL_EXPR:
445 case CASE_LABEL_EXPR:
446 return true;
447 default:
448 return false;
449 }
450 return false;
451}
452
0566b51e 453/* Set the default definition for VAR to DEF. */
6de9cd9a
DN
454static inline void
455set_default_def (tree var, tree def)
456{
727a31fa 457 var_ann_t ann = get_var_ann (var);
6de9cd9a
DN
458 ann->default_def = def;
459}
460
0566b51e
DB
461/* Return the default definition for variable VAR, or NULL if none
462 exists. */
6de9cd9a
DN
463static inline tree
464default_def (tree var)
465{
466 var_ann_t ann = var_ann (var);
467 return ann ? ann->default_def : NULL_TREE;
468}
469
470/* PHI nodes should contain only ssa_names and invariants. A test
471 for ssa_name is definitely simpler; don't let invalid contents
472 slip in in the meantime. */
473
474static inline bool
475phi_ssa_name_p (tree t)
476{
477 if (TREE_CODE (t) == SSA_NAME)
478 return true;
479#ifdef ENABLE_CHECKING
480 if (!is_gimple_min_invariant (t))
481 abort ();
482#endif
483 return false;
484}
485
486/* ----------------------------------------------------------------------- */
487
0566b51e
DB
488/* Return a block_stmt_iterator that points to beginning of basic
489 block BB. */
6de9cd9a
DN
490static inline block_stmt_iterator
491bsi_start (basic_block bb)
492{
493 block_stmt_iterator bsi;
494 if (bb->stmt_list)
495 bsi.tsi = tsi_start (bb->stmt_list);
496 else
497 {
498#ifdef ENABLE_CHECKING
499 if (bb->index >= 0)
500 abort ();
501#endif
502 bsi.tsi.ptr = NULL;
503 bsi.tsi.container = NULL;
504 }
505 bsi.bb = bb;
506 return bsi;
507}
508
d7621d3c
ZD
509/* Return a block statement iterator that points to the last label in
510 block BB. */
511
512static inline block_stmt_iterator
513bsi_after_labels (basic_block bb)
514{
515 block_stmt_iterator bsi;
516 tree_stmt_iterator next;
517
518 bsi.bb = bb;
519
520 if (!bb->stmt_list)
521 {
522#ifdef ENABLE_CHECKING
523 if (bb->index >= 0)
524 abort ();
525#endif
526 bsi.tsi.ptr = NULL;
527 bsi.tsi.container = NULL;
528 return bsi;
529 }
530
531 bsi.tsi = tsi_start (bb->stmt_list);
532 if (tsi_end_p (bsi.tsi))
533 return bsi;
534
535 /* Ensure that there are some labels. The rationale is that we want
536 to insert after the bsi that is returned, and these insertions should
537 be placed at the start of the basic block. This would not work if the
538 first statement was not label; rather fail here than enable the user
539 proceed in wrong way. */
540 if (TREE_CODE (tsi_stmt (bsi.tsi)) != LABEL_EXPR)
541 abort ();
542
543 next = bsi.tsi;
544 tsi_next (&next);
545
546 while (!tsi_end_p (next)
547 && TREE_CODE (tsi_stmt (next)) == LABEL_EXPR)
548 {
549 bsi.tsi = next;
550 tsi_next (&next);
551 }
552
553 return bsi;
554}
555
0566b51e
DB
556/* Return a block statement iterator that points to the end of basic
557 block BB. */
6de9cd9a
DN
558static inline block_stmt_iterator
559bsi_last (basic_block bb)
560{
561 block_stmt_iterator bsi;
562 if (bb->stmt_list)
563 bsi.tsi = tsi_last (bb->stmt_list);
564 else
565 {
566#ifdef ENABLE_CHECKING
567 if (bb->index >= 0)
568 abort ();
569#endif
570 bsi.tsi.ptr = NULL;
571 bsi.tsi.container = NULL;
572 }
573 bsi.bb = bb;
574 return bsi;
575}
576
0566b51e
DB
577/* Return true if block statement iterator I has reached the end of
578 the basic block. */
6de9cd9a
DN
579static inline bool
580bsi_end_p (block_stmt_iterator i)
581{
582 return tsi_end_p (i.tsi);
583}
584
0566b51e
DB
585/* Modify block statement iterator I so that it is at the next
586 statement in the basic block. */
6de9cd9a
DN
587static inline void
588bsi_next (block_stmt_iterator *i)
589{
590 tsi_next (&i->tsi);
591}
592
0566b51e
DB
593/* Modify block statement iterator I so that it is at the previous
594 statement in the basic block. */
6de9cd9a
DN
595static inline void
596bsi_prev (block_stmt_iterator *i)
597{
598 tsi_prev (&i->tsi);
599}
600
0566b51e
DB
601/* Return the statement that block statement iterator I is currently
602 at. */
6de9cd9a
DN
603static inline tree
604bsi_stmt (block_stmt_iterator i)
605{
606 return tsi_stmt (i.tsi);
607}
608
0566b51e
DB
609/* Return a pointer to the statement that block statement iterator I
610 is currently at. */
6de9cd9a
DN
611static inline tree *
612bsi_stmt_ptr (block_stmt_iterator i)
613{
614 return tsi_stmt_ptr (i.tsi);
615}
616
9baba81b
SP
617/* Returns the loop of the statement STMT. */
618
619static inline struct loop *
620loop_containing_stmt (tree stmt)
621{
622 basic_block bb = bb_for_stmt (stmt);
623 if (!bb)
624 return NULL;
625
626 return bb->loop_father;
627}
628
0566b51e 629/* Return true if VAR is a clobbered by function calls. */
6de9cd9a
DN
630static inline bool
631is_call_clobbered (tree var)
632{
633 return needs_to_live_in_memory (var)
634 || bitmap_bit_p (call_clobbered_vars, var_ann (var)->uid);
635}
636
0566b51e 637/* Mark variable VAR as being clobbered by function calls. */
6de9cd9a
DN
638static inline void
639mark_call_clobbered (tree var)
640{
641 var_ann_t ann = var_ann (var);
642 /* Call-clobbered variables need to live in memory. */
643 DECL_NEEDS_TO_LIVE_IN_MEMORY_INTERNAL (var) = 1;
644 bitmap_set_bit (call_clobbered_vars, ann->uid);
645}
646
0566b51e 647/* Mark variable VAR as being non-addressable. */
6de9cd9a
DN
648static inline void
649mark_non_addressable (tree var)
650{
651 bitmap_clear_bit (call_clobbered_vars, var_ann (var)->uid);
652 DECL_NEEDS_TO_LIVE_IN_MEMORY_INTERNAL (var) = 0;
653 TREE_ADDRESSABLE (var) = 0;
654}
655
06d72ee6
DB
656/* Return the common annotation for T. Return NULL if the annotation
657 doesn't already exist. */
658static inline tree_ann_t
659tree_ann (tree t)
660{
661 return t->common.ann;
662}
663
664/* Return a common annotation for T. Create the constant annotation if it
665 doesn't exist. */
666static inline tree_ann_t
667get_tree_ann (tree t)
668{
669 tree_ann_t ann = tree_ann (t);
670 return (ann) ? ann : create_tree_ann (t);
671}
672
6de9cd9a 673#endif /* _TREE_FLOW_INLINE_H */
This page took 0.262348 seconds and 5 git commands to generate.