1 /* Gimple IR support functions.
3 Copyright 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
4 Contributed by Aldy Hernandez <aldyh@redhat.com>
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
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/>. */
24 #include "coretypes.h"
29 #include "hard-reg-set.h"
30 #include "basic-block.h"
33 #include "diagnostic.h"
34 #include "tree-flow.h"
35 #include "value-prof.h"
40 /* Global type table. FIXME lto, it should be possible to re-use some
41 of the type hashing routines in tree.c (type_hash_canon, type_hash_lookup,
42 etc), but those assume that types were built with the various
43 build_*_type routines which is not the case with the streamer. */
44 static htab_t gimple_types
;
45 static struct pointer_map_t
*type_hash_cache
;
47 /* Global type comparison cache. */
48 static htab_t gtc_visited
;
49 static struct obstack gtc_ob
;
51 /* All the tuples have their operand vector (if present) at the very bottom
52 of the structure. Therefore, the offset required to find the
53 operands vector the size of the structure minus the size of the 1
54 element tree array at the end (see gimple_ops). */
55 #define DEFGSSTRUCT(SYM, STRUCT, HAS_TREE_OP) \
56 (HAS_TREE_OP ? sizeof (struct STRUCT) - sizeof (tree) : 0),
57 EXPORTED_CONST
size_t gimple_ops_offset_
[] = {
58 #include "gsstruct.def"
62 #define DEFGSSTRUCT(SYM, STRUCT, HAS_TREE_OP) sizeof(struct STRUCT),
63 static const size_t gsstruct_code_size
[] = {
64 #include "gsstruct.def"
68 #define DEFGSCODE(SYM, NAME, GSSCODE) NAME,
69 const char *const gimple_code_name
[] = {
74 #define DEFGSCODE(SYM, NAME, GSSCODE) GSSCODE,
75 EXPORTED_CONST
enum gimple_statement_structure_enum gss_for_code_
[] = {
80 #ifdef GATHER_STATISTICS
83 int gimple_alloc_counts
[(int) gimple_alloc_kind_all
];
84 int gimple_alloc_sizes
[(int) gimple_alloc_kind_all
];
86 /* Keep in sync with gimple.h:enum gimple_alloc_kind. */
87 static const char * const gimple_alloc_kind_names
[] = {
95 #endif /* GATHER_STATISTICS */
97 /* A cache of gimple_seq objects. Sequences are created and destroyed
98 fairly often during gimplification. */
99 static GTY ((deletable
)) struct gimple_seq_d
*gimple_seq_cache
;
101 /* Private API manipulation functions shared only with some
103 extern void gimple_set_stored_syms (gimple
, bitmap
, bitmap_obstack
*);
104 extern void gimple_set_loaded_syms (gimple
, bitmap
, bitmap_obstack
*);
106 /* Gimple tuple constructors.
107 Note: Any constructor taking a ``gimple_seq'' as a parameter, can
108 be passed a NULL to start with an empty sequence. */
110 /* Set the code for statement G to CODE. */
113 gimple_set_code (gimple g
, enum gimple_code code
)
115 g
->gsbase
.code
= code
;
118 /* Return the number of bytes needed to hold a GIMPLE statement with
122 gimple_size (enum gimple_code code
)
124 return gsstruct_code_size
[gss_for_code (code
)];
127 /* Allocate memory for a GIMPLE statement with code CODE and NUM_OPS
131 gimple_alloc_stat (enum gimple_code code
, unsigned num_ops MEM_STAT_DECL
)
136 size
= gimple_size (code
);
138 size
+= sizeof (tree
) * (num_ops
- 1);
140 #ifdef GATHER_STATISTICS
142 enum gimple_alloc_kind kind
= gimple_alloc_kind (code
);
143 gimple_alloc_counts
[(int) kind
]++;
144 gimple_alloc_sizes
[(int) kind
] += size
;
148 stmt
= (gimple
) ggc_alloc_cleared_stat (size PASS_MEM_STAT
);
149 gimple_set_code (stmt
, code
);
150 gimple_set_num_ops (stmt
, num_ops
);
152 /* Do not call gimple_set_modified here as it has other side
153 effects and this tuple is still not completely built. */
154 stmt
->gsbase
.modified
= 1;
159 /* Set SUBCODE to be the code of the expression computed by statement G. */
162 gimple_set_subcode (gimple g
, unsigned subcode
)
164 /* We only have 16 bits for the RHS code. Assert that we are not
166 gcc_assert (subcode
< (1 << 16));
167 g
->gsbase
.subcode
= subcode
;
172 /* Build a tuple with operands. CODE is the statement to build (which
173 must be one of the GIMPLE_WITH_OPS tuples). SUBCODE is the sub-code
174 for the new tuple. NUM_OPS is the number of operands to allocate. */
176 #define gimple_build_with_ops(c, s, n) \
177 gimple_build_with_ops_stat (c, s, n MEM_STAT_INFO)
180 gimple_build_with_ops_stat (enum gimple_code code
, unsigned subcode
,
181 unsigned num_ops MEM_STAT_DECL
)
183 gimple s
= gimple_alloc_stat (code
, num_ops PASS_MEM_STAT
);
184 gimple_set_subcode (s
, subcode
);
190 /* Build a GIMPLE_RETURN statement returning RETVAL. */
193 gimple_build_return (tree retval
)
195 gimple s
= gimple_build_with_ops (GIMPLE_RETURN
, ERROR_MARK
, 1);
197 gimple_return_set_retval (s
, retval
);
201 /* Reset alias information on call S. */
204 gimple_call_reset_alias_info (gimple s
)
206 if (gimple_call_flags (s
) & ECF_CONST
)
207 memset (gimple_call_use_set (s
), 0, sizeof (struct pt_solution
));
209 pt_solution_reset (gimple_call_use_set (s
));
210 if (gimple_call_flags (s
) & (ECF_CONST
|ECF_PURE
|ECF_NOVOPS
))
211 memset (gimple_call_clobber_set (s
), 0, sizeof (struct pt_solution
));
213 pt_solution_reset (gimple_call_clobber_set (s
));
216 /* Helper for gimple_build_call, gimple_build_call_vec and
217 gimple_build_call_from_tree. Build the basic components of a
218 GIMPLE_CALL statement to function FN with NARGS arguments. */
221 gimple_build_call_1 (tree fn
, unsigned nargs
)
223 gimple s
= gimple_build_with_ops (GIMPLE_CALL
, ERROR_MARK
, nargs
+ 3);
224 if (TREE_CODE (fn
) == FUNCTION_DECL
)
225 fn
= build_fold_addr_expr (fn
);
226 gimple_set_op (s
, 1, fn
);
227 gimple_call_reset_alias_info (s
);
232 /* Build a GIMPLE_CALL statement to function FN with the arguments
233 specified in vector ARGS. */
236 gimple_build_call_vec (tree fn
, VEC(tree
, heap
) *args
)
239 unsigned nargs
= VEC_length (tree
, args
);
240 gimple call
= gimple_build_call_1 (fn
, nargs
);
242 for (i
= 0; i
< nargs
; i
++)
243 gimple_call_set_arg (call
, i
, VEC_index (tree
, args
, i
));
249 /* Build a GIMPLE_CALL statement to function FN. NARGS is the number of
250 arguments. The ... are the arguments. */
253 gimple_build_call (tree fn
, unsigned nargs
, ...)
259 gcc_assert (TREE_CODE (fn
) == FUNCTION_DECL
|| is_gimple_call_addr (fn
));
261 call
= gimple_build_call_1 (fn
, nargs
);
263 va_start (ap
, nargs
);
264 for (i
= 0; i
< nargs
; i
++)
265 gimple_call_set_arg (call
, i
, va_arg (ap
, tree
));
272 /* Build a GIMPLE_CALL statement from CALL_EXPR T. Note that T is
273 assumed to be in GIMPLE form already. Minimal checking is done of
277 gimple_build_call_from_tree (tree t
)
281 tree fndecl
= get_callee_fndecl (t
);
283 gcc_assert (TREE_CODE (t
) == CALL_EXPR
);
285 nargs
= call_expr_nargs (t
);
286 call
= gimple_build_call_1 (fndecl
? fndecl
: CALL_EXPR_FN (t
), nargs
);
288 for (i
= 0; i
< nargs
; i
++)
289 gimple_call_set_arg (call
, i
, CALL_EXPR_ARG (t
, i
));
291 gimple_set_block (call
, TREE_BLOCK (t
));
293 /* Carry all the CALL_EXPR flags to the new GIMPLE_CALL. */
294 gimple_call_set_chain (call
, CALL_EXPR_STATIC_CHAIN (t
));
295 gimple_call_set_tail (call
, CALL_EXPR_TAILCALL (t
));
296 gimple_call_set_cannot_inline (call
, CALL_CANNOT_INLINE_P (t
));
297 gimple_call_set_return_slot_opt (call
, CALL_EXPR_RETURN_SLOT_OPT (t
));
298 gimple_call_set_from_thunk (call
, CALL_FROM_THUNK_P (t
));
299 gimple_call_set_va_arg_pack (call
, CALL_EXPR_VA_ARG_PACK (t
));
300 gimple_set_no_warning (call
, TREE_NO_WARNING (t
));
306 /* Extract the operands and code for expression EXPR into *SUBCODE_P,
307 *OP1_P and *OP2_P respectively. */
310 extract_ops_from_tree (tree expr
, enum tree_code
*subcode_p
, tree
*op1_p
,
313 enum gimple_rhs_class grhs_class
;
315 *subcode_p
= TREE_CODE (expr
);
316 grhs_class
= get_gimple_rhs_class (*subcode_p
);
318 if (grhs_class
== GIMPLE_BINARY_RHS
)
320 *op1_p
= TREE_OPERAND (expr
, 0);
321 *op2_p
= TREE_OPERAND (expr
, 1);
323 else if (grhs_class
== GIMPLE_UNARY_RHS
)
325 *op1_p
= TREE_OPERAND (expr
, 0);
328 else if (grhs_class
== GIMPLE_SINGLE_RHS
)
338 /* Build a GIMPLE_ASSIGN statement.
340 LHS of the assignment.
341 RHS of the assignment which can be unary or binary. */
344 gimple_build_assign_stat (tree lhs
, tree rhs MEM_STAT_DECL
)
346 enum tree_code subcode
;
349 extract_ops_from_tree (rhs
, &subcode
, &op1
, &op2
);
350 return gimple_build_assign_with_ops_stat (subcode
, lhs
, op1
, op2
355 /* Build a GIMPLE_ASSIGN statement with sub-code SUBCODE and operands
356 OP1 and OP2. If OP2 is NULL then SUBCODE must be of class
357 GIMPLE_UNARY_RHS or GIMPLE_SINGLE_RHS. */
360 gimple_build_assign_with_ops_stat (enum tree_code subcode
, tree lhs
, tree op1
,
361 tree op2 MEM_STAT_DECL
)
366 /* Need 1 operand for LHS and 1 or 2 for the RHS (depending on the
368 num_ops
= get_gimple_rhs_num_ops (subcode
) + 1;
370 p
= gimple_build_with_ops_stat (GIMPLE_ASSIGN
, (unsigned)subcode
, num_ops
372 gimple_assign_set_lhs (p
, lhs
);
373 gimple_assign_set_rhs1 (p
, op1
);
376 gcc_assert (num_ops
> 2);
377 gimple_assign_set_rhs2 (p
, op2
);
384 /* Build a new GIMPLE_ASSIGN tuple and append it to the end of *SEQ_P.
386 DST/SRC are the destination and source respectively. You can pass
387 ungimplified trees in DST or SRC, in which case they will be
388 converted to a gimple operand if necessary.
390 This function returns the newly created GIMPLE_ASSIGN tuple. */
393 gimplify_assign (tree dst
, tree src
, gimple_seq
*seq_p
)
395 tree t
= build2 (MODIFY_EXPR
, TREE_TYPE (dst
), dst
, src
);
396 gimplify_and_add (t
, seq_p
);
398 return gimple_seq_last_stmt (*seq_p
);
402 /* Build a GIMPLE_COND statement.
404 PRED is the condition used to compare LHS and the RHS.
405 T_LABEL is the label to jump to if the condition is true.
406 F_LABEL is the label to jump to otherwise. */
409 gimple_build_cond (enum tree_code pred_code
, tree lhs
, tree rhs
,
410 tree t_label
, tree f_label
)
414 gcc_assert (TREE_CODE_CLASS (pred_code
) == tcc_comparison
);
415 p
= gimple_build_with_ops (GIMPLE_COND
, pred_code
, 4);
416 gimple_cond_set_lhs (p
, lhs
);
417 gimple_cond_set_rhs (p
, rhs
);
418 gimple_cond_set_true_label (p
, t_label
);
419 gimple_cond_set_false_label (p
, f_label
);
424 /* Extract operands for a GIMPLE_COND statement out of COND_EXPR tree COND. */
427 gimple_cond_get_ops_from_tree (tree cond
, enum tree_code
*code_p
,
428 tree
*lhs_p
, tree
*rhs_p
)
430 location_t loc
= EXPR_LOCATION (cond
);
431 gcc_assert (TREE_CODE_CLASS (TREE_CODE (cond
)) == tcc_comparison
432 || TREE_CODE (cond
) == TRUTH_NOT_EXPR
433 || is_gimple_min_invariant (cond
)
434 || SSA_VAR_P (cond
));
436 extract_ops_from_tree (cond
, code_p
, lhs_p
, rhs_p
);
438 /* Canonicalize conditionals of the form 'if (!VAL)'. */
439 if (*code_p
== TRUTH_NOT_EXPR
)
442 gcc_assert (*lhs_p
&& *rhs_p
== NULL_TREE
);
443 *rhs_p
= fold_convert_loc (loc
, TREE_TYPE (*lhs_p
), integer_zero_node
);
445 /* Canonicalize conditionals of the form 'if (VAL)' */
446 else if (TREE_CODE_CLASS (*code_p
) != tcc_comparison
)
449 gcc_assert (*lhs_p
&& *rhs_p
== NULL_TREE
);
450 *rhs_p
= fold_convert_loc (loc
, TREE_TYPE (*lhs_p
), integer_zero_node
);
455 /* Build a GIMPLE_COND statement from the conditional expression tree
456 COND. T_LABEL and F_LABEL are as in gimple_build_cond. */
459 gimple_build_cond_from_tree (tree cond
, tree t_label
, tree f_label
)
464 gimple_cond_get_ops_from_tree (cond
, &code
, &lhs
, &rhs
);
465 return gimple_build_cond (code
, lhs
, rhs
, t_label
, f_label
);
468 /* Set code, lhs, and rhs of a GIMPLE_COND from a suitable
469 boolean expression tree COND. */
472 gimple_cond_set_condition_from_tree (gimple stmt
, tree cond
)
477 gimple_cond_get_ops_from_tree (cond
, &code
, &lhs
, &rhs
);
478 gimple_cond_set_condition (stmt
, code
, lhs
, rhs
);
481 /* Build a GIMPLE_LABEL statement for LABEL. */
484 gimple_build_label (tree label
)
486 gimple p
= gimple_build_with_ops (GIMPLE_LABEL
, ERROR_MARK
, 1);
487 gimple_label_set_label (p
, label
);
491 /* Build a GIMPLE_GOTO statement to label DEST. */
494 gimple_build_goto (tree dest
)
496 gimple p
= gimple_build_with_ops (GIMPLE_GOTO
, ERROR_MARK
, 1);
497 gimple_goto_set_dest (p
, dest
);
502 /* Build a GIMPLE_NOP statement. */
505 gimple_build_nop (void)
507 return gimple_alloc (GIMPLE_NOP
, 0);
511 /* Build a GIMPLE_BIND statement.
512 VARS are the variables in BODY.
513 BLOCK is the containing block. */
516 gimple_build_bind (tree vars
, gimple_seq body
, tree block
)
518 gimple p
= gimple_alloc (GIMPLE_BIND
, 0);
519 gimple_bind_set_vars (p
, vars
);
521 gimple_bind_set_body (p
, body
);
523 gimple_bind_set_block (p
, block
);
527 /* Helper function to set the simple fields of a asm stmt.
529 STRING is a pointer to a string that is the asm blocks assembly code.
530 NINPUT is the number of register inputs.
531 NOUTPUT is the number of register outputs.
532 NCLOBBERS is the number of clobbered registers.
536 gimple_build_asm_1 (const char *string
, unsigned ninputs
, unsigned noutputs
,
537 unsigned nclobbers
, unsigned nlabels
)
540 int size
= strlen (string
);
542 /* ASMs with labels cannot have outputs. This should have been
543 enforced by the front end. */
544 gcc_assert (nlabels
== 0 || noutputs
== 0);
546 p
= gimple_build_with_ops (GIMPLE_ASM
, ERROR_MARK
,
547 ninputs
+ noutputs
+ nclobbers
+ nlabels
);
549 p
->gimple_asm
.ni
= ninputs
;
550 p
->gimple_asm
.no
= noutputs
;
551 p
->gimple_asm
.nc
= nclobbers
;
552 p
->gimple_asm
.nl
= nlabels
;
553 p
->gimple_asm
.string
= ggc_alloc_string (string
, size
);
555 #ifdef GATHER_STATISTICS
556 gimple_alloc_sizes
[(int) gimple_alloc_kind (GIMPLE_ASM
)] += size
;
562 /* Build a GIMPLE_ASM statement.
564 STRING is the assembly code.
565 NINPUT is the number of register inputs.
566 NOUTPUT is the number of register outputs.
567 NCLOBBERS is the number of clobbered registers.
568 INPUTS is a vector of the input register parameters.
569 OUTPUTS is a vector of the output register parameters.
570 CLOBBERS is a vector of the clobbered register parameters.
571 LABELS is a vector of destination labels. */
574 gimple_build_asm_vec (const char *string
, VEC(tree
,gc
)* inputs
,
575 VEC(tree
,gc
)* outputs
, VEC(tree
,gc
)* clobbers
,
576 VEC(tree
,gc
)* labels
)
581 p
= gimple_build_asm_1 (string
,
582 VEC_length (tree
, inputs
),
583 VEC_length (tree
, outputs
),
584 VEC_length (tree
, clobbers
),
585 VEC_length (tree
, labels
));
587 for (i
= 0; i
< VEC_length (tree
, inputs
); i
++)
588 gimple_asm_set_input_op (p
, i
, VEC_index (tree
, inputs
, i
));
590 for (i
= 0; i
< VEC_length (tree
, outputs
); i
++)
591 gimple_asm_set_output_op (p
, i
, VEC_index (tree
, outputs
, i
));
593 for (i
= 0; i
< VEC_length (tree
, clobbers
); i
++)
594 gimple_asm_set_clobber_op (p
, i
, VEC_index (tree
, clobbers
, i
));
596 for (i
= 0; i
< VEC_length (tree
, labels
); i
++)
597 gimple_asm_set_label_op (p
, i
, VEC_index (tree
, labels
, i
));
602 /* Build a GIMPLE_CATCH statement.
604 TYPES are the catch types.
605 HANDLER is the exception handler. */
608 gimple_build_catch (tree types
, gimple_seq handler
)
610 gimple p
= gimple_alloc (GIMPLE_CATCH
, 0);
611 gimple_catch_set_types (p
, types
);
613 gimple_catch_set_handler (p
, handler
);
618 /* Build a GIMPLE_EH_FILTER statement.
620 TYPES are the filter's types.
621 FAILURE is the filter's failure action. */
624 gimple_build_eh_filter (tree types
, gimple_seq failure
)
626 gimple p
= gimple_alloc (GIMPLE_EH_FILTER
, 0);
627 gimple_eh_filter_set_types (p
, types
);
629 gimple_eh_filter_set_failure (p
, failure
);
634 /* Build a GIMPLE_EH_MUST_NOT_THROW statement. */
637 gimple_build_eh_must_not_throw (tree decl
)
639 gimple p
= gimple_alloc (GIMPLE_EH_MUST_NOT_THROW
, 1);
641 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
642 gcc_assert (flags_from_decl_or_type (decl
) & ECF_NORETURN
);
643 gimple_eh_must_not_throw_set_fndecl (p
, decl
);
648 /* Build a GIMPLE_TRY statement.
650 EVAL is the expression to evaluate.
651 CLEANUP is the cleanup expression.
652 KIND is either GIMPLE_TRY_CATCH or GIMPLE_TRY_FINALLY depending on
653 whether this is a try/catch or a try/finally respectively. */
656 gimple_build_try (gimple_seq eval
, gimple_seq cleanup
,
657 enum gimple_try_flags kind
)
661 gcc_assert (kind
== GIMPLE_TRY_CATCH
|| kind
== GIMPLE_TRY_FINALLY
);
662 p
= gimple_alloc (GIMPLE_TRY
, 0);
663 gimple_set_subcode (p
, kind
);
665 gimple_try_set_eval (p
, eval
);
667 gimple_try_set_cleanup (p
, cleanup
);
672 /* Construct a GIMPLE_WITH_CLEANUP_EXPR statement.
674 CLEANUP is the cleanup expression. */
677 gimple_build_wce (gimple_seq cleanup
)
679 gimple p
= gimple_alloc (GIMPLE_WITH_CLEANUP_EXPR
, 0);
681 gimple_wce_set_cleanup (p
, cleanup
);
687 /* Build a GIMPLE_RESX statement. */
690 gimple_build_resx (int region
)
692 gimple p
= gimple_build_with_ops (GIMPLE_RESX
, ERROR_MARK
, 0);
693 p
->gimple_eh_ctrl
.region
= region
;
698 /* The helper for constructing a gimple switch statement.
699 INDEX is the switch's index.
700 NLABELS is the number of labels in the switch excluding the default.
701 DEFAULT_LABEL is the default label for the switch statement. */
704 gimple_build_switch_nlabels (unsigned nlabels
, tree index
, tree default_label
)
706 /* nlabels + 1 default label + 1 index. */
707 gimple p
= gimple_build_with_ops (GIMPLE_SWITCH
, ERROR_MARK
,
708 1 + (default_label
!= NULL
) + nlabels
);
709 gimple_switch_set_index (p
, index
);
711 gimple_switch_set_default_label (p
, default_label
);
716 /* Build a GIMPLE_SWITCH statement.
718 INDEX is the switch's index.
719 NLABELS is the number of labels in the switch excluding the DEFAULT_LABEL.
720 ... are the labels excluding the default. */
723 gimple_build_switch (unsigned nlabels
, tree index
, tree default_label
, ...)
727 gimple p
= gimple_build_switch_nlabels (nlabels
, index
, default_label
);
729 /* Store the rest of the labels. */
730 va_start (al
, default_label
);
731 offset
= (default_label
!= NULL
);
732 for (i
= 0; i
< nlabels
; i
++)
733 gimple_switch_set_label (p
, i
+ offset
, va_arg (al
, tree
));
740 /* Build a GIMPLE_SWITCH statement.
742 INDEX is the switch's index.
743 DEFAULT_LABEL is the default label
744 ARGS is a vector of labels excluding the default. */
747 gimple_build_switch_vec (tree index
, tree default_label
, VEC(tree
, heap
) *args
)
749 unsigned i
, offset
, nlabels
= VEC_length (tree
, args
);
750 gimple p
= gimple_build_switch_nlabels (nlabels
, index
, default_label
);
752 /* Copy the labels from the vector to the switch statement. */
753 offset
= (default_label
!= NULL
);
754 for (i
= 0; i
< nlabels
; i
++)
755 gimple_switch_set_label (p
, i
+ offset
, VEC_index (tree
, args
, i
));
760 /* Build a GIMPLE_EH_DISPATCH statement. */
763 gimple_build_eh_dispatch (int region
)
765 gimple p
= gimple_build_with_ops (GIMPLE_EH_DISPATCH
, ERROR_MARK
, 0);
766 p
->gimple_eh_ctrl
.region
= region
;
770 /* Build a new GIMPLE_DEBUG_BIND statement.
772 VAR is bound to VALUE; block and location are taken from STMT. */
775 gimple_build_debug_bind_stat (tree var
, tree value
, gimple stmt MEM_STAT_DECL
)
777 gimple p
= gimple_build_with_ops_stat (GIMPLE_DEBUG
,
778 (unsigned)GIMPLE_DEBUG_BIND
, 2
781 gimple_debug_bind_set_var (p
, var
);
782 gimple_debug_bind_set_value (p
, value
);
785 gimple_set_block (p
, gimple_block (stmt
));
786 gimple_set_location (p
, gimple_location (stmt
));
793 /* Build a GIMPLE_OMP_CRITICAL statement.
795 BODY is the sequence of statements for which only one thread can execute.
796 NAME is optional identifier for this critical block. */
799 gimple_build_omp_critical (gimple_seq body
, tree name
)
801 gimple p
= gimple_alloc (GIMPLE_OMP_CRITICAL
, 0);
802 gimple_omp_critical_set_name (p
, name
);
804 gimple_omp_set_body (p
, body
);
809 /* Build a GIMPLE_OMP_FOR statement.
811 BODY is sequence of statements inside the for loop.
812 CLAUSES, are any of the OMP loop construct's clauses: private, firstprivate,
813 lastprivate, reductions, ordered, schedule, and nowait.
814 COLLAPSE is the collapse count.
815 PRE_BODY is the sequence of statements that are loop invariant. */
818 gimple_build_omp_for (gimple_seq body
, tree clauses
, size_t collapse
,
821 gimple p
= gimple_alloc (GIMPLE_OMP_FOR
, 0);
823 gimple_omp_set_body (p
, body
);
824 gimple_omp_for_set_clauses (p
, clauses
);
825 p
->gimple_omp_for
.collapse
= collapse
;
826 p
->gimple_omp_for
.iter
= GGC_CNEWVEC (struct gimple_omp_for_iter
, collapse
);
828 gimple_omp_for_set_pre_body (p
, pre_body
);
834 /* Build a GIMPLE_OMP_PARALLEL statement.
836 BODY is sequence of statements which are executed in parallel.
837 CLAUSES, are the OMP parallel construct's clauses.
838 CHILD_FN is the function created for the parallel threads to execute.
839 DATA_ARG are the shared data argument(s). */
842 gimple_build_omp_parallel (gimple_seq body
, tree clauses
, tree child_fn
,
845 gimple p
= gimple_alloc (GIMPLE_OMP_PARALLEL
, 0);
847 gimple_omp_set_body (p
, body
);
848 gimple_omp_parallel_set_clauses (p
, clauses
);
849 gimple_omp_parallel_set_child_fn (p
, child_fn
);
850 gimple_omp_parallel_set_data_arg (p
, data_arg
);
856 /* Build a GIMPLE_OMP_TASK statement.
858 BODY is sequence of statements which are executed by the explicit task.
859 CLAUSES, are the OMP parallel construct's clauses.
860 CHILD_FN is the function created for the parallel threads to execute.
861 DATA_ARG are the shared data argument(s).
862 COPY_FN is the optional function for firstprivate initialization.
863 ARG_SIZE and ARG_ALIGN are size and alignment of the data block. */
866 gimple_build_omp_task (gimple_seq body
, tree clauses
, tree child_fn
,
867 tree data_arg
, tree copy_fn
, tree arg_size
,
870 gimple p
= gimple_alloc (GIMPLE_OMP_TASK
, 0);
872 gimple_omp_set_body (p
, body
);
873 gimple_omp_task_set_clauses (p
, clauses
);
874 gimple_omp_task_set_child_fn (p
, child_fn
);
875 gimple_omp_task_set_data_arg (p
, data_arg
);
876 gimple_omp_task_set_copy_fn (p
, copy_fn
);
877 gimple_omp_task_set_arg_size (p
, arg_size
);
878 gimple_omp_task_set_arg_align (p
, arg_align
);
884 /* Build a GIMPLE_OMP_SECTION statement for a sections statement.
886 BODY is the sequence of statements in the section. */
889 gimple_build_omp_section (gimple_seq body
)
891 gimple p
= gimple_alloc (GIMPLE_OMP_SECTION
, 0);
893 gimple_omp_set_body (p
, body
);
899 /* Build a GIMPLE_OMP_MASTER statement.
901 BODY is the sequence of statements to be executed by just the master. */
904 gimple_build_omp_master (gimple_seq body
)
906 gimple p
= gimple_alloc (GIMPLE_OMP_MASTER
, 0);
908 gimple_omp_set_body (p
, body
);
914 /* Build a GIMPLE_OMP_CONTINUE statement.
916 CONTROL_DEF is the definition of the control variable.
917 CONTROL_USE is the use of the control variable. */
920 gimple_build_omp_continue (tree control_def
, tree control_use
)
922 gimple p
= gimple_alloc (GIMPLE_OMP_CONTINUE
, 0);
923 gimple_omp_continue_set_control_def (p
, control_def
);
924 gimple_omp_continue_set_control_use (p
, control_use
);
928 /* Build a GIMPLE_OMP_ORDERED statement.
930 BODY is the sequence of statements inside a loop that will executed in
934 gimple_build_omp_ordered (gimple_seq body
)
936 gimple p
= gimple_alloc (GIMPLE_OMP_ORDERED
, 0);
938 gimple_omp_set_body (p
, body
);
944 /* Build a GIMPLE_OMP_RETURN statement.
945 WAIT_P is true if this is a non-waiting return. */
948 gimple_build_omp_return (bool wait_p
)
950 gimple p
= gimple_alloc (GIMPLE_OMP_RETURN
, 0);
952 gimple_omp_return_set_nowait (p
);
958 /* Build a GIMPLE_OMP_SECTIONS statement.
960 BODY is a sequence of section statements.
961 CLAUSES are any of the OMP sections contsruct's clauses: private,
962 firstprivate, lastprivate, reduction, and nowait. */
965 gimple_build_omp_sections (gimple_seq body
, tree clauses
)
967 gimple p
= gimple_alloc (GIMPLE_OMP_SECTIONS
, 0);
969 gimple_omp_set_body (p
, body
);
970 gimple_omp_sections_set_clauses (p
, clauses
);
976 /* Build a GIMPLE_OMP_SECTIONS_SWITCH. */
979 gimple_build_omp_sections_switch (void)
981 return gimple_alloc (GIMPLE_OMP_SECTIONS_SWITCH
, 0);
985 /* Build a GIMPLE_OMP_SINGLE statement.
987 BODY is the sequence of statements that will be executed once.
988 CLAUSES are any of the OMP single construct's clauses: private, firstprivate,
989 copyprivate, nowait. */
992 gimple_build_omp_single (gimple_seq body
, tree clauses
)
994 gimple p
= gimple_alloc (GIMPLE_OMP_SINGLE
, 0);
996 gimple_omp_set_body (p
, body
);
997 gimple_omp_single_set_clauses (p
, clauses
);
1003 /* Build a GIMPLE_OMP_ATOMIC_LOAD statement. */
1006 gimple_build_omp_atomic_load (tree lhs
, tree rhs
)
1008 gimple p
= gimple_alloc (GIMPLE_OMP_ATOMIC_LOAD
, 0);
1009 gimple_omp_atomic_load_set_lhs (p
, lhs
);
1010 gimple_omp_atomic_load_set_rhs (p
, rhs
);
1014 /* Build a GIMPLE_OMP_ATOMIC_STORE statement.
1016 VAL is the value we are storing. */
1019 gimple_build_omp_atomic_store (tree val
)
1021 gimple p
= gimple_alloc (GIMPLE_OMP_ATOMIC_STORE
, 0);
1022 gimple_omp_atomic_store_set_val (p
, val
);
1026 /* Build a GIMPLE_PREDICT statement. PREDICT is one of the predictors from
1027 predict.def, OUTCOME is NOT_TAKEN or TAKEN. */
1030 gimple_build_predict (enum br_predictor predictor
, enum prediction outcome
)
1032 gimple p
= gimple_alloc (GIMPLE_PREDICT
, 0);
1033 /* Ensure all the predictors fit into the lower bits of the subcode. */
1034 gcc_assert ((int) END_PREDICTORS
<= GF_PREDICT_TAKEN
);
1035 gimple_predict_set_predictor (p
, predictor
);
1036 gimple_predict_set_outcome (p
, outcome
);
1040 #if defined ENABLE_GIMPLE_CHECKING
1041 /* Complain of a gimple type mismatch and die. */
1044 gimple_check_failed (const_gimple gs
, const char *file
, int line
,
1045 const char *function
, enum gimple_code code
,
1046 enum tree_code subcode
)
1048 internal_error ("gimple check: expected %s(%s), have %s(%s) in %s, at %s:%d",
1049 gimple_code_name
[code
],
1050 tree_code_name
[subcode
],
1051 gimple_code_name
[gimple_code (gs
)],
1052 gs
->gsbase
.subcode
> 0
1053 ? tree_code_name
[gs
->gsbase
.subcode
]
1055 function
, trim_filename (file
), line
);
1057 #endif /* ENABLE_GIMPLE_CHECKING */
1060 /* Allocate a new GIMPLE sequence in GC memory and return it. If
1061 there are free sequences in GIMPLE_SEQ_CACHE return one of those
1065 gimple_seq_alloc (void)
1067 gimple_seq seq
= gimple_seq_cache
;
1070 gimple_seq_cache
= gimple_seq_cache
->next_free
;
1071 gcc_assert (gimple_seq_cache
!= seq
);
1072 memset (seq
, 0, sizeof (*seq
));
1076 seq
= (gimple_seq
) ggc_alloc_cleared (sizeof (*seq
));
1077 #ifdef GATHER_STATISTICS
1078 gimple_alloc_counts
[(int) gimple_alloc_kind_seq
]++;
1079 gimple_alloc_sizes
[(int) gimple_alloc_kind_seq
] += sizeof (*seq
);
1086 /* Return SEQ to the free pool of GIMPLE sequences. */
1089 gimple_seq_free (gimple_seq seq
)
1094 gcc_assert (gimple_seq_first (seq
) == NULL
);
1095 gcc_assert (gimple_seq_last (seq
) == NULL
);
1097 /* If this triggers, it's a sign that the same list is being freed
1099 gcc_assert (seq
!= gimple_seq_cache
|| gimple_seq_cache
== NULL
);
1101 /* Add SEQ to the pool of free sequences. */
1102 seq
->next_free
= gimple_seq_cache
;
1103 gimple_seq_cache
= seq
;
1107 /* Link gimple statement GS to the end of the sequence *SEQ_P. If
1108 *SEQ_P is NULL, a new sequence is allocated. */
1111 gimple_seq_add_stmt (gimple_seq
*seq_p
, gimple gs
)
1113 gimple_stmt_iterator si
;
1119 *seq_p
= gimple_seq_alloc ();
1121 si
= gsi_last (*seq_p
);
1122 gsi_insert_after (&si
, gs
, GSI_NEW_STMT
);
1126 /* Append sequence SRC to the end of sequence *DST_P. If *DST_P is
1127 NULL, a new sequence is allocated. */
1130 gimple_seq_add_seq (gimple_seq
*dst_p
, gimple_seq src
)
1132 gimple_stmt_iterator si
;
1138 *dst_p
= gimple_seq_alloc ();
1140 si
= gsi_last (*dst_p
);
1141 gsi_insert_seq_after (&si
, src
, GSI_NEW_STMT
);
1145 /* Helper function of empty_body_p. Return true if STMT is an empty
1149 empty_stmt_p (gimple stmt
)
1151 if (gimple_code (stmt
) == GIMPLE_NOP
)
1153 if (gimple_code (stmt
) == GIMPLE_BIND
)
1154 return empty_body_p (gimple_bind_body (stmt
));
1159 /* Return true if BODY contains nothing but empty statements. */
1162 empty_body_p (gimple_seq body
)
1164 gimple_stmt_iterator i
;
1166 if (gimple_seq_empty_p (body
))
1168 for (i
= gsi_start (body
); !gsi_end_p (i
); gsi_next (&i
))
1169 if (!empty_stmt_p (gsi_stmt (i
))
1170 && !is_gimple_debug (gsi_stmt (i
)))
1177 /* Perform a deep copy of sequence SRC and return the result. */
1180 gimple_seq_copy (gimple_seq src
)
1182 gimple_stmt_iterator gsi
;
1183 gimple_seq new_seq
= gimple_seq_alloc ();
1186 for (gsi
= gsi_start (src
); !gsi_end_p (gsi
); gsi_next (&gsi
))
1188 stmt
= gimple_copy (gsi_stmt (gsi
));
1189 gimple_seq_add_stmt (&new_seq
, stmt
);
1196 /* Walk all the statements in the sequence SEQ calling walk_gimple_stmt
1197 on each one. WI is as in walk_gimple_stmt.
1199 If walk_gimple_stmt returns non-NULL, the walk is stopped, the
1200 value is stored in WI->CALLBACK_RESULT and the statement that
1201 produced the value is returned.
1203 Otherwise, all the statements are walked and NULL returned. */
1206 walk_gimple_seq (gimple_seq seq
, walk_stmt_fn callback_stmt
,
1207 walk_tree_fn callback_op
, struct walk_stmt_info
*wi
)
1209 gimple_stmt_iterator gsi
;
1211 for (gsi
= gsi_start (seq
); !gsi_end_p (gsi
); gsi_next (&gsi
))
1213 tree ret
= walk_gimple_stmt (&gsi
, callback_stmt
, callback_op
, wi
);
1216 /* If CALLBACK_STMT or CALLBACK_OP return a value, WI must exist
1219 wi
->callback_result
= ret
;
1220 return gsi_stmt (gsi
);
1225 wi
->callback_result
= NULL_TREE
;
1231 /* Helper function for walk_gimple_stmt. Walk operands of a GIMPLE_ASM. */
1234 walk_gimple_asm (gimple stmt
, walk_tree_fn callback_op
,
1235 struct walk_stmt_info
*wi
)
1239 const char **oconstraints
;
1241 const char *constraint
;
1242 bool allows_mem
, allows_reg
, is_inout
;
1244 noutputs
= gimple_asm_noutputs (stmt
);
1245 oconstraints
= (const char **) alloca ((noutputs
) * sizeof (const char *));
1250 for (i
= 0; i
< noutputs
; i
++)
1252 op
= gimple_asm_output_op (stmt
, i
);
1253 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op
)));
1254 oconstraints
[i
] = constraint
;
1255 parse_output_constraint (&constraint
, i
, 0, 0, &allows_mem
, &allows_reg
,
1258 wi
->val_only
= (allows_reg
|| !allows_mem
);
1259 ret
= walk_tree (&TREE_VALUE (op
), callback_op
, wi
, NULL
);
1264 n
= gimple_asm_ninputs (stmt
);
1265 for (i
= 0; i
< n
; i
++)
1267 op
= gimple_asm_input_op (stmt
, i
);
1268 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op
)));
1269 parse_input_constraint (&constraint
, 0, 0, noutputs
, 0,
1270 oconstraints
, &allows_mem
, &allows_reg
);
1273 wi
->val_only
= (allows_reg
|| !allows_mem
);
1274 /* Although input "m" is not really a LHS, we need a lvalue. */
1275 wi
->is_lhs
= !wi
->val_only
;
1277 ret
= walk_tree (&TREE_VALUE (op
), callback_op
, wi
, NULL
);
1285 wi
->val_only
= true;
1288 n
= gimple_asm_nlabels (stmt
);
1289 for (i
= 0; i
< n
; i
++)
1291 op
= gimple_asm_label_op (stmt
, i
);
1292 ret
= walk_tree (&TREE_VALUE (op
), callback_op
, wi
, NULL
);
1301 /* Helper function of WALK_GIMPLE_STMT. Walk every tree operand in
1302 STMT. CALLBACK_OP and WI are as in WALK_GIMPLE_STMT.
1304 CALLBACK_OP is called on each operand of STMT via walk_tree.
1305 Additional parameters to walk_tree must be stored in WI. For each operand
1306 OP, walk_tree is called as:
1308 walk_tree (&OP, CALLBACK_OP, WI, WI->PSET)
1310 If CALLBACK_OP returns non-NULL for an operand, the remaining
1311 operands are not scanned.
1313 The return value is that returned by the last call to walk_tree, or
1314 NULL_TREE if no CALLBACK_OP is specified. */
1317 walk_gimple_op (gimple stmt
, walk_tree_fn callback_op
,
1318 struct walk_stmt_info
*wi
)
1320 struct pointer_set_t
*pset
= (wi
) ? wi
->pset
: NULL
;
1322 tree ret
= NULL_TREE
;
1324 switch (gimple_code (stmt
))
1327 /* Walk the RHS operands. If the LHS is of a non-renamable type or
1328 is a register variable, we may use a COMPONENT_REF on the RHS. */
1331 tree lhs
= gimple_assign_lhs (stmt
);
1333 = (is_gimple_reg_type (TREE_TYPE (lhs
)) && !is_gimple_reg (lhs
))
1334 || !gimple_assign_single_p (stmt
);
1337 for (i
= 1; i
< gimple_num_ops (stmt
); i
++)
1339 ret
= walk_tree (gimple_op_ptr (stmt
, i
), callback_op
, wi
,
1345 /* Walk the LHS. If the RHS is appropriate for a memory, we
1346 may use a COMPONENT_REF on the LHS. */
1349 /* If the RHS has more than 1 operand, it is not appropriate
1351 wi
->val_only
= !is_gimple_mem_rhs (gimple_assign_rhs1 (stmt
))
1352 || !gimple_assign_single_p (stmt
);
1356 ret
= walk_tree (gimple_op_ptr (stmt
, 0), callback_op
, wi
, pset
);
1362 wi
->val_only
= true;
1371 ret
= walk_tree (gimple_call_chain_ptr (stmt
), callback_op
, wi
, pset
);
1375 ret
= walk_tree (gimple_call_fn_ptr (stmt
), callback_op
, wi
, pset
);
1379 for (i
= 0; i
< gimple_call_num_args (stmt
); i
++)
1381 ret
= walk_tree (gimple_call_arg_ptr (stmt
, i
), callback_op
, wi
,
1390 ret
= walk_tree (gimple_call_lhs_ptr (stmt
), callback_op
, wi
, pset
);
1399 ret
= walk_tree (gimple_catch_types_ptr (stmt
), callback_op
, wi
,
1405 case GIMPLE_EH_FILTER
:
1406 ret
= walk_tree (gimple_eh_filter_types_ptr (stmt
), callback_op
, wi
,
1413 ret
= walk_gimple_asm (stmt
, callback_op
, wi
);
1418 case GIMPLE_OMP_CONTINUE
:
1419 ret
= walk_tree (gimple_omp_continue_control_def_ptr (stmt
),
1420 callback_op
, wi
, pset
);
1424 ret
= walk_tree (gimple_omp_continue_control_use_ptr (stmt
),
1425 callback_op
, wi
, pset
);
1430 case GIMPLE_OMP_CRITICAL
:
1431 ret
= walk_tree (gimple_omp_critical_name_ptr (stmt
), callback_op
, wi
,
1437 case GIMPLE_OMP_FOR
:
1438 ret
= walk_tree (gimple_omp_for_clauses_ptr (stmt
), callback_op
, wi
,
1442 for (i
= 0; i
< gimple_omp_for_collapse (stmt
); i
++)
1444 ret
= walk_tree (gimple_omp_for_index_ptr (stmt
, i
), callback_op
,
1448 ret
= walk_tree (gimple_omp_for_initial_ptr (stmt
, i
), callback_op
,
1452 ret
= walk_tree (gimple_omp_for_final_ptr (stmt
, i
), callback_op
,
1456 ret
= walk_tree (gimple_omp_for_incr_ptr (stmt
, i
), callback_op
,
1463 case GIMPLE_OMP_PARALLEL
:
1464 ret
= walk_tree (gimple_omp_parallel_clauses_ptr (stmt
), callback_op
,
1468 ret
= walk_tree (gimple_omp_parallel_child_fn_ptr (stmt
), callback_op
,
1472 ret
= walk_tree (gimple_omp_parallel_data_arg_ptr (stmt
), callback_op
,
1478 case GIMPLE_OMP_TASK
:
1479 ret
= walk_tree (gimple_omp_task_clauses_ptr (stmt
), callback_op
,
1483 ret
= walk_tree (gimple_omp_task_child_fn_ptr (stmt
), callback_op
,
1487 ret
= walk_tree (gimple_omp_task_data_arg_ptr (stmt
), callback_op
,
1491 ret
= walk_tree (gimple_omp_task_copy_fn_ptr (stmt
), callback_op
,
1495 ret
= walk_tree (gimple_omp_task_arg_size_ptr (stmt
), callback_op
,
1499 ret
= walk_tree (gimple_omp_task_arg_align_ptr (stmt
), callback_op
,
1505 case GIMPLE_OMP_SECTIONS
:
1506 ret
= walk_tree (gimple_omp_sections_clauses_ptr (stmt
), callback_op
,
1511 ret
= walk_tree (gimple_omp_sections_control_ptr (stmt
), callback_op
,
1518 case GIMPLE_OMP_SINGLE
:
1519 ret
= walk_tree (gimple_omp_single_clauses_ptr (stmt
), callback_op
, wi
,
1525 case GIMPLE_OMP_ATOMIC_LOAD
:
1526 ret
= walk_tree (gimple_omp_atomic_load_lhs_ptr (stmt
), callback_op
, wi
,
1531 ret
= walk_tree (gimple_omp_atomic_load_rhs_ptr (stmt
), callback_op
, wi
,
1537 case GIMPLE_OMP_ATOMIC_STORE
:
1538 ret
= walk_tree (gimple_omp_atomic_store_val_ptr (stmt
), callback_op
,
1544 /* Tuples that do not have operands. */
1547 case GIMPLE_OMP_RETURN
:
1548 case GIMPLE_PREDICT
:
1553 enum gimple_statement_structure_enum gss
;
1554 gss
= gimple_statement_structure (stmt
);
1555 if (gss
== GSS_WITH_OPS
|| gss
== GSS_WITH_MEM_OPS
)
1556 for (i
= 0; i
< gimple_num_ops (stmt
); i
++)
1558 ret
= walk_tree (gimple_op_ptr (stmt
, i
), callback_op
, wi
, pset
);
1570 /* Walk the current statement in GSI (optionally using traversal state
1571 stored in WI). If WI is NULL, no state is kept during traversal.
1572 The callback CALLBACK_STMT is called. If CALLBACK_STMT indicates
1573 that it has handled all the operands of the statement, its return
1574 value is returned. Otherwise, the return value from CALLBACK_STMT
1575 is discarded and its operands are scanned.
1577 If CALLBACK_STMT is NULL or it didn't handle the operands,
1578 CALLBACK_OP is called on each operand of the statement via
1579 walk_gimple_op. If walk_gimple_op returns non-NULL for any
1580 operand, the remaining operands are not scanned. In this case, the
1581 return value from CALLBACK_OP is returned.
1583 In any other case, NULL_TREE is returned. */
1586 walk_gimple_stmt (gimple_stmt_iterator
*gsi
, walk_stmt_fn callback_stmt
,
1587 walk_tree_fn callback_op
, struct walk_stmt_info
*wi
)
1591 gimple stmt
= gsi_stmt (*gsi
);
1596 if (wi
&& wi
->want_locations
&& gimple_has_location (stmt
))
1597 input_location
= gimple_location (stmt
);
1601 /* Invoke the statement callback. Return if the callback handled
1602 all of STMT operands by itself. */
1605 bool handled_ops
= false;
1606 tree_ret
= callback_stmt (gsi
, &handled_ops
, wi
);
1610 /* If CALLBACK_STMT did not handle operands, it should not have
1611 a value to return. */
1612 gcc_assert (tree_ret
== NULL
);
1614 /* Re-read stmt in case the callback changed it. */
1615 stmt
= gsi_stmt (*gsi
);
1618 /* If CALLBACK_OP is defined, invoke it on every operand of STMT. */
1621 tree_ret
= walk_gimple_op (stmt
, callback_op
, wi
);
1626 /* If STMT can have statements inside (e.g. GIMPLE_BIND), walk them. */
1627 switch (gimple_code (stmt
))
1630 ret
= walk_gimple_seq (gimple_bind_body (stmt
), callback_stmt
,
1633 return wi
->callback_result
;
1637 ret
= walk_gimple_seq (gimple_catch_handler (stmt
), callback_stmt
,
1640 return wi
->callback_result
;
1643 case GIMPLE_EH_FILTER
:
1644 ret
= walk_gimple_seq (gimple_eh_filter_failure (stmt
), callback_stmt
,
1647 return wi
->callback_result
;
1651 ret
= walk_gimple_seq (gimple_try_eval (stmt
), callback_stmt
, callback_op
,
1654 return wi
->callback_result
;
1656 ret
= walk_gimple_seq (gimple_try_cleanup (stmt
), callback_stmt
,
1659 return wi
->callback_result
;
1662 case GIMPLE_OMP_FOR
:
1663 ret
= walk_gimple_seq (gimple_omp_for_pre_body (stmt
), callback_stmt
,
1666 return wi
->callback_result
;
1669 case GIMPLE_OMP_CRITICAL
:
1670 case GIMPLE_OMP_MASTER
:
1671 case GIMPLE_OMP_ORDERED
:
1672 case GIMPLE_OMP_SECTION
:
1673 case GIMPLE_OMP_PARALLEL
:
1674 case GIMPLE_OMP_TASK
:
1675 case GIMPLE_OMP_SECTIONS
:
1676 case GIMPLE_OMP_SINGLE
:
1677 ret
= walk_gimple_seq (gimple_omp_body (stmt
), callback_stmt
, callback_op
,
1680 return wi
->callback_result
;
1683 case GIMPLE_WITH_CLEANUP_EXPR
:
1684 ret
= walk_gimple_seq (gimple_wce_cleanup (stmt
), callback_stmt
,
1687 return wi
->callback_result
;
1691 gcc_assert (!gimple_has_substatements (stmt
));
1699 /* Set sequence SEQ to be the GIMPLE body for function FN. */
1702 gimple_set_body (tree fndecl
, gimple_seq seq
)
1704 struct function
*fn
= DECL_STRUCT_FUNCTION (fndecl
);
1707 /* If FNDECL still does not have a function structure associated
1708 with it, then it does not make sense for it to receive a
1710 gcc_assert (seq
== NULL
);
1713 fn
->gimple_body
= seq
;
1717 /* Return the body of GIMPLE statements for function FN. */
1720 gimple_body (tree fndecl
)
1722 struct function
*fn
= DECL_STRUCT_FUNCTION (fndecl
);
1723 return fn
? fn
->gimple_body
: NULL
;
1726 /* Return true when FNDECL has Gimple body either in unlowered
1729 gimple_has_body_p (tree fndecl
)
1731 struct function
*fn
= DECL_STRUCT_FUNCTION (fndecl
);
1732 return (gimple_body (fndecl
) || (fn
&& fn
->cfg
));
1735 /* Detect flags from a GIMPLE_CALL. This is just like
1736 call_expr_flags, but for gimple tuples. */
1739 gimple_call_flags (const_gimple stmt
)
1742 tree decl
= gimple_call_fndecl (stmt
);
1746 flags
= flags_from_decl_or_type (decl
);
1749 t
= TREE_TYPE (gimple_call_fn (stmt
));
1750 if (t
&& TREE_CODE (t
) == POINTER_TYPE
)
1751 flags
= flags_from_decl_or_type (TREE_TYPE (t
));
1760 /* Return true if GS is a copy assignment. */
1763 gimple_assign_copy_p (gimple gs
)
1765 return gimple_code (gs
) == GIMPLE_ASSIGN
1766 && get_gimple_rhs_class (gimple_assign_rhs_code (gs
))
1767 == GIMPLE_SINGLE_RHS
1768 && is_gimple_val (gimple_op (gs
, 1));
1772 /* Return true if GS is a SSA_NAME copy assignment. */
1775 gimple_assign_ssa_name_copy_p (gimple gs
)
1777 return (gimple_code (gs
) == GIMPLE_ASSIGN
1778 && (get_gimple_rhs_class (gimple_assign_rhs_code (gs
))
1779 == GIMPLE_SINGLE_RHS
)
1780 && TREE_CODE (gimple_assign_lhs (gs
)) == SSA_NAME
1781 && TREE_CODE (gimple_assign_rhs1 (gs
)) == SSA_NAME
);
1785 /* Return true if GS is an assignment with a singleton RHS, i.e.,
1786 there is no operator associated with the assignment itself.
1787 Unlike gimple_assign_copy_p, this predicate returns true for
1788 any RHS operand, including those that perform an operation
1789 and do not have the semantics of a copy, such as COND_EXPR. */
1792 gimple_assign_single_p (gimple gs
)
1794 return (gimple_code (gs
) == GIMPLE_ASSIGN
1795 && get_gimple_rhs_class (gimple_assign_rhs_code (gs
))
1796 == GIMPLE_SINGLE_RHS
);
1799 /* Return true if GS is an assignment with a unary RHS, but the
1800 operator has no effect on the assigned value. The logic is adapted
1801 from STRIP_NOPS. This predicate is intended to be used in tuplifying
1802 instances in which STRIP_NOPS was previously applied to the RHS of
1805 NOTE: In the use cases that led to the creation of this function
1806 and of gimple_assign_single_p, it is typical to test for either
1807 condition and to proceed in the same manner. In each case, the
1808 assigned value is represented by the single RHS operand of the
1809 assignment. I suspect there may be cases where gimple_assign_copy_p,
1810 gimple_assign_single_p, or equivalent logic is used where a similar
1811 treatment of unary NOPs is appropriate. */
1814 gimple_assign_unary_nop_p (gimple gs
)
1816 return (gimple_code (gs
) == GIMPLE_ASSIGN
1817 && (CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (gs
))
1818 || gimple_assign_rhs_code (gs
) == NON_LVALUE_EXPR
)
1819 && gimple_assign_rhs1 (gs
) != error_mark_node
1820 && (TYPE_MODE (TREE_TYPE (gimple_assign_lhs (gs
)))
1821 == TYPE_MODE (TREE_TYPE (gimple_assign_rhs1 (gs
)))));
1824 /* Set BB to be the basic block holding G. */
1827 gimple_set_bb (gimple stmt
, basic_block bb
)
1829 stmt
->gsbase
.bb
= bb
;
1831 /* If the statement is a label, add the label to block-to-labels map
1832 so that we can speed up edge creation for GIMPLE_GOTOs. */
1833 if (cfun
->cfg
&& gimple_code (stmt
) == GIMPLE_LABEL
)
1838 t
= gimple_label_label (stmt
);
1839 uid
= LABEL_DECL_UID (t
);
1842 unsigned old_len
= VEC_length (basic_block
, label_to_block_map
);
1843 LABEL_DECL_UID (t
) = uid
= cfun
->cfg
->last_label_uid
++;
1844 if (old_len
<= (unsigned) uid
)
1846 unsigned new_len
= 3 * uid
/ 2 + 1;
1848 VEC_safe_grow_cleared (basic_block
, gc
, label_to_block_map
,
1853 VEC_replace (basic_block
, label_to_block_map
, uid
, bb
);
1858 /* Modify the RHS of the assignment pointed-to by GSI using the
1859 operands in the expression tree EXPR.
1861 NOTE: The statement pointed-to by GSI may be reallocated if it
1862 did not have enough operand slots.
1864 This function is useful to convert an existing tree expression into
1865 the flat representation used for the RHS of a GIMPLE assignment.
1866 It will reallocate memory as needed to expand or shrink the number
1867 of operand slots needed to represent EXPR.
1869 NOTE: If you find yourself building a tree and then calling this
1870 function, you are most certainly doing it the slow way. It is much
1871 better to build a new assignment or to use the function
1872 gimple_assign_set_rhs_with_ops, which does not require an
1873 expression tree to be built. */
1876 gimple_assign_set_rhs_from_tree (gimple_stmt_iterator
*gsi
, tree expr
)
1878 enum tree_code subcode
;
1881 extract_ops_from_tree (expr
, &subcode
, &op1
, &op2
);
1882 gimple_assign_set_rhs_with_ops (gsi
, subcode
, op1
, op2
);
1886 /* Set the RHS of assignment statement pointed-to by GSI to CODE with
1887 operands OP1 and OP2.
1889 NOTE: The statement pointed-to by GSI may be reallocated if it
1890 did not have enough operand slots. */
1893 gimple_assign_set_rhs_with_ops (gimple_stmt_iterator
*gsi
, enum tree_code code
,
1896 unsigned new_rhs_ops
= get_gimple_rhs_num_ops (code
);
1897 gimple stmt
= gsi_stmt (*gsi
);
1899 /* If the new CODE needs more operands, allocate a new statement. */
1900 if (gimple_num_ops (stmt
) < new_rhs_ops
+ 1)
1902 tree lhs
= gimple_assign_lhs (stmt
);
1903 gimple new_stmt
= gimple_alloc (gimple_code (stmt
), new_rhs_ops
+ 1);
1904 memcpy (new_stmt
, stmt
, gimple_size (gimple_code (stmt
)));
1905 gsi_replace (gsi
, new_stmt
, true);
1908 /* The LHS needs to be reset as this also changes the SSA name
1910 gimple_assign_set_lhs (stmt
, lhs
);
1913 gimple_set_num_ops (stmt
, new_rhs_ops
+ 1);
1914 gimple_set_subcode (stmt
, code
);
1915 gimple_assign_set_rhs1 (stmt
, op1
);
1916 if (new_rhs_ops
> 1)
1917 gimple_assign_set_rhs2 (stmt
, op2
);
1921 /* Return the LHS of a statement that performs an assignment,
1922 either a GIMPLE_ASSIGN or a GIMPLE_CALL. Returns NULL_TREE
1923 for a call to a function that returns no value, or for a
1924 statement other than an assignment or a call. */
1927 gimple_get_lhs (const_gimple stmt
)
1929 enum gimple_code code
= gimple_code (stmt
);
1931 if (code
== GIMPLE_ASSIGN
)
1932 return gimple_assign_lhs (stmt
);
1933 else if (code
== GIMPLE_CALL
)
1934 return gimple_call_lhs (stmt
);
1940 /* Set the LHS of a statement that performs an assignment,
1941 either a GIMPLE_ASSIGN or a GIMPLE_CALL. */
1944 gimple_set_lhs (gimple stmt
, tree lhs
)
1946 enum gimple_code code
= gimple_code (stmt
);
1948 if (code
== GIMPLE_ASSIGN
)
1949 gimple_assign_set_lhs (stmt
, lhs
);
1950 else if (code
== GIMPLE_CALL
)
1951 gimple_call_set_lhs (stmt
, lhs
);
1956 /* Replace the LHS of STMT, an assignment, either a GIMPLE_ASSIGN or a
1957 GIMPLE_CALL, with NLHS, in preparation for modifying the RHS to an
1958 expression with a different value.
1960 This will update any annotations (say debug bind stmts) referring
1961 to the original LHS, so that they use the RHS instead. This is
1962 done even if NLHS and LHS are the same, for it is understood that
1963 the RHS will be modified afterwards, and NLHS will not be assigned
1964 an equivalent value.
1966 Adjusting any non-annotation uses of the LHS, if needed, is a
1967 responsibility of the caller.
1969 The effect of this call should be pretty much the same as that of
1970 inserting a copy of STMT before STMT, and then removing the
1971 original stmt, at which time gsi_remove() would have update
1972 annotations, but using this function saves all the inserting,
1973 copying and removing. */
1976 gimple_replace_lhs (gimple stmt
, tree nlhs
)
1978 if (MAY_HAVE_DEBUG_STMTS
)
1980 tree lhs
= gimple_get_lhs (stmt
);
1982 gcc_assert (SSA_NAME_DEF_STMT (lhs
) == stmt
);
1984 insert_debug_temp_for_var_def (NULL
, lhs
);
1987 gimple_set_lhs (stmt
, nlhs
);
1990 /* Return a deep copy of statement STMT. All the operands from STMT
1991 are reallocated and copied using unshare_expr. The DEF, USE, VDEF
1992 and VUSE operand arrays are set to empty in the new copy. */
1995 gimple_copy (gimple stmt
)
1997 enum gimple_code code
= gimple_code (stmt
);
1998 unsigned num_ops
= gimple_num_ops (stmt
);
1999 gimple copy
= gimple_alloc (code
, num_ops
);
2002 /* Shallow copy all the fields from STMT. */
2003 memcpy (copy
, stmt
, gimple_size (code
));
2005 /* If STMT has sub-statements, deep-copy them as well. */
2006 if (gimple_has_substatements (stmt
))
2011 switch (gimple_code (stmt
))
2014 new_seq
= gimple_seq_copy (gimple_bind_body (stmt
));
2015 gimple_bind_set_body (copy
, new_seq
);
2016 gimple_bind_set_vars (copy
, unshare_expr (gimple_bind_vars (stmt
)));
2017 gimple_bind_set_block (copy
, gimple_bind_block (stmt
));
2021 new_seq
= gimple_seq_copy (gimple_catch_handler (stmt
));
2022 gimple_catch_set_handler (copy
, new_seq
);
2023 t
= unshare_expr (gimple_catch_types (stmt
));
2024 gimple_catch_set_types (copy
, t
);
2027 case GIMPLE_EH_FILTER
:
2028 new_seq
= gimple_seq_copy (gimple_eh_filter_failure (stmt
));
2029 gimple_eh_filter_set_failure (copy
, new_seq
);
2030 t
= unshare_expr (gimple_eh_filter_types (stmt
));
2031 gimple_eh_filter_set_types (copy
, t
);
2035 new_seq
= gimple_seq_copy (gimple_try_eval (stmt
));
2036 gimple_try_set_eval (copy
, new_seq
);
2037 new_seq
= gimple_seq_copy (gimple_try_cleanup (stmt
));
2038 gimple_try_set_cleanup (copy
, new_seq
);
2041 case GIMPLE_OMP_FOR
:
2042 new_seq
= gimple_seq_copy (gimple_omp_for_pre_body (stmt
));
2043 gimple_omp_for_set_pre_body (copy
, new_seq
);
2044 t
= unshare_expr (gimple_omp_for_clauses (stmt
));
2045 gimple_omp_for_set_clauses (copy
, t
);
2046 copy
->gimple_omp_for
.iter
2047 = GGC_NEWVEC (struct gimple_omp_for_iter
,
2048 gimple_omp_for_collapse (stmt
));
2049 for (i
= 0; i
< gimple_omp_for_collapse (stmt
); i
++)
2051 gimple_omp_for_set_cond (copy
, i
,
2052 gimple_omp_for_cond (stmt
, i
));
2053 gimple_omp_for_set_index (copy
, i
,
2054 gimple_omp_for_index (stmt
, i
));
2055 t
= unshare_expr (gimple_omp_for_initial (stmt
, i
));
2056 gimple_omp_for_set_initial (copy
, i
, t
);
2057 t
= unshare_expr (gimple_omp_for_final (stmt
, i
));
2058 gimple_omp_for_set_final (copy
, i
, t
);
2059 t
= unshare_expr (gimple_omp_for_incr (stmt
, i
));
2060 gimple_omp_for_set_incr (copy
, i
, t
);
2064 case GIMPLE_OMP_PARALLEL
:
2065 t
= unshare_expr (gimple_omp_parallel_clauses (stmt
));
2066 gimple_omp_parallel_set_clauses (copy
, t
);
2067 t
= unshare_expr (gimple_omp_parallel_child_fn (stmt
));
2068 gimple_omp_parallel_set_child_fn (copy
, t
);
2069 t
= unshare_expr (gimple_omp_parallel_data_arg (stmt
));
2070 gimple_omp_parallel_set_data_arg (copy
, t
);
2073 case GIMPLE_OMP_TASK
:
2074 t
= unshare_expr (gimple_omp_task_clauses (stmt
));
2075 gimple_omp_task_set_clauses (copy
, t
);
2076 t
= unshare_expr (gimple_omp_task_child_fn (stmt
));
2077 gimple_omp_task_set_child_fn (copy
, t
);
2078 t
= unshare_expr (gimple_omp_task_data_arg (stmt
));
2079 gimple_omp_task_set_data_arg (copy
, t
);
2080 t
= unshare_expr (gimple_omp_task_copy_fn (stmt
));
2081 gimple_omp_task_set_copy_fn (copy
, t
);
2082 t
= unshare_expr (gimple_omp_task_arg_size (stmt
));
2083 gimple_omp_task_set_arg_size (copy
, t
);
2084 t
= unshare_expr (gimple_omp_task_arg_align (stmt
));
2085 gimple_omp_task_set_arg_align (copy
, t
);
2088 case GIMPLE_OMP_CRITICAL
:
2089 t
= unshare_expr (gimple_omp_critical_name (stmt
));
2090 gimple_omp_critical_set_name (copy
, t
);
2093 case GIMPLE_OMP_SECTIONS
:
2094 t
= unshare_expr (gimple_omp_sections_clauses (stmt
));
2095 gimple_omp_sections_set_clauses (copy
, t
);
2096 t
= unshare_expr (gimple_omp_sections_control (stmt
));
2097 gimple_omp_sections_set_control (copy
, t
);
2100 case GIMPLE_OMP_SINGLE
:
2101 case GIMPLE_OMP_SECTION
:
2102 case GIMPLE_OMP_MASTER
:
2103 case GIMPLE_OMP_ORDERED
:
2105 new_seq
= gimple_seq_copy (gimple_omp_body (stmt
));
2106 gimple_omp_set_body (copy
, new_seq
);
2109 case GIMPLE_WITH_CLEANUP_EXPR
:
2110 new_seq
= gimple_seq_copy (gimple_wce_cleanup (stmt
));
2111 gimple_wce_set_cleanup (copy
, new_seq
);
2119 /* Make copy of operands. */
2122 for (i
= 0; i
< num_ops
; i
++)
2123 gimple_set_op (copy
, i
, unshare_expr (gimple_op (stmt
, i
)));
2125 /* Clear out SSA operand vectors on COPY. */
2126 if (gimple_has_ops (stmt
))
2128 gimple_set_def_ops (copy
, NULL
);
2129 gimple_set_use_ops (copy
, NULL
);
2132 if (gimple_has_mem_ops (stmt
))
2134 gimple_set_vdef (copy
, gimple_vdef (stmt
));
2135 gimple_set_vuse (copy
, gimple_vuse (stmt
));
2138 /* SSA operands need to be updated. */
2139 gimple_set_modified (copy
, true);
2146 /* Set the MODIFIED flag to MODIFIEDP, iff the gimple statement G has
2147 a MODIFIED field. */
2150 gimple_set_modified (gimple s
, bool modifiedp
)
2152 if (gimple_has_ops (s
))
2154 s
->gsbase
.modified
= (unsigned) modifiedp
;
2158 && is_gimple_call (s
)
2159 && gimple_call_noreturn_p (s
))
2160 VEC_safe_push (gimple
, gc
, MODIFIED_NORETURN_CALLS (cfun
), s
);
2165 /* Return true if statement S has side-effects. We consider a
2166 statement to have side effects if:
2168 - It is a GIMPLE_CALL not marked with ECF_PURE or ECF_CONST.
2169 - Any of its operands are marked TREE_THIS_VOLATILE or TREE_SIDE_EFFECTS. */
2172 gimple_has_side_effects (const_gimple s
)
2176 if (is_gimple_debug (s
))
2179 /* We don't have to scan the arguments to check for
2180 volatile arguments, though, at present, we still
2181 do a scan to check for TREE_SIDE_EFFECTS. */
2182 if (gimple_has_volatile_ops (s
))
2185 if (is_gimple_call (s
))
2187 unsigned nargs
= gimple_call_num_args (s
);
2189 if (!(gimple_call_flags (s
) & (ECF_CONST
| ECF_PURE
)))
2191 else if (gimple_call_flags (s
) & ECF_LOOPING_CONST_OR_PURE
)
2192 /* An infinite loop is considered a side effect. */
2195 if (gimple_call_lhs (s
)
2196 && TREE_SIDE_EFFECTS (gimple_call_lhs (s
)))
2198 gcc_assert (gimple_has_volatile_ops (s
));
2202 if (TREE_SIDE_EFFECTS (gimple_call_fn (s
)))
2205 for (i
= 0; i
< nargs
; i
++)
2206 if (TREE_SIDE_EFFECTS (gimple_call_arg (s
, i
)))
2208 gcc_assert (gimple_has_volatile_ops (s
));
2216 for (i
= 0; i
< gimple_num_ops (s
); i
++)
2217 if (TREE_SIDE_EFFECTS (gimple_op (s
, i
)))
2219 gcc_assert (gimple_has_volatile_ops (s
));
2227 /* Return true if the RHS of statement S has side effects.
2228 We may use it to determine if it is admissable to replace
2229 an assignment or call with a copy of a previously-computed
2230 value. In such cases, side-effects due the the LHS are
2234 gimple_rhs_has_side_effects (const_gimple s
)
2238 if (is_gimple_call (s
))
2240 unsigned nargs
= gimple_call_num_args (s
);
2242 if (!(gimple_call_flags (s
) & (ECF_CONST
| ECF_PURE
)))
2245 /* We cannot use gimple_has_volatile_ops here,
2246 because we must ignore a volatile LHS. */
2247 if (TREE_SIDE_EFFECTS (gimple_call_fn (s
))
2248 || TREE_THIS_VOLATILE (gimple_call_fn (s
)))
2250 gcc_assert (gimple_has_volatile_ops (s
));
2254 for (i
= 0; i
< nargs
; i
++)
2255 if (TREE_SIDE_EFFECTS (gimple_call_arg (s
, i
))
2256 || TREE_THIS_VOLATILE (gimple_call_arg (s
, i
)))
2261 else if (is_gimple_assign (s
))
2263 /* Skip the first operand, the LHS. */
2264 for (i
= 1; i
< gimple_num_ops (s
); i
++)
2265 if (TREE_SIDE_EFFECTS (gimple_op (s
, i
))
2266 || TREE_THIS_VOLATILE (gimple_op (s
, i
)))
2268 gcc_assert (gimple_has_volatile_ops (s
));
2272 else if (is_gimple_debug (s
))
2276 /* For statements without an LHS, examine all arguments. */
2277 for (i
= 0; i
< gimple_num_ops (s
); i
++)
2278 if (TREE_SIDE_EFFECTS (gimple_op (s
, i
))
2279 || TREE_THIS_VOLATILE (gimple_op (s
, i
)))
2281 gcc_assert (gimple_has_volatile_ops (s
));
2290 /* Helper for gimple_could_trap_p and gimple_assign_rhs_could_trap_p.
2291 Return true if S can trap. If INCLUDE_LHS is true and S is a
2292 GIMPLE_ASSIGN, the LHS of the assignment is also checked.
2293 Otherwise, only the RHS of the assignment is checked. */
2296 gimple_could_trap_p_1 (gimple s
, bool include_lhs
)
2299 tree t
, div
= NULL_TREE
;
2302 start
= (is_gimple_assign (s
) && !include_lhs
) ? 1 : 0;
2304 for (i
= start
; i
< gimple_num_ops (s
); i
++)
2305 if (tree_could_trap_p (gimple_op (s
, i
)))
2308 switch (gimple_code (s
))
2311 return gimple_asm_volatile_p (s
);
2314 t
= gimple_call_fndecl (s
);
2315 /* Assume that calls to weak functions may trap. */
2316 if (!t
|| !DECL_P (t
) || DECL_WEAK (t
))
2321 t
= gimple_expr_type (s
);
2322 op
= gimple_assign_rhs_code (s
);
2323 if (get_gimple_rhs_class (op
) == GIMPLE_BINARY_RHS
)
2324 div
= gimple_assign_rhs2 (s
);
2325 return (operation_could_trap_p (op
, FLOAT_TYPE_P (t
),
2326 (INTEGRAL_TYPE_P (t
)
2327 && TYPE_OVERFLOW_TRAPS (t
)),
2339 /* Return true if statement S can trap. */
2342 gimple_could_trap_p (gimple s
)
2344 return gimple_could_trap_p_1 (s
, true);
2348 /* Return true if RHS of a GIMPLE_ASSIGN S can trap. */
2351 gimple_assign_rhs_could_trap_p (gimple s
)
2353 gcc_assert (is_gimple_assign (s
));
2354 return gimple_could_trap_p_1 (s
, false);
2358 /* Print debugging information for gimple stmts generated. */
2361 dump_gimple_statistics (void)
2363 #ifdef GATHER_STATISTICS
2364 int i
, total_tuples
= 0, total_bytes
= 0;
2366 fprintf (stderr
, "\nGIMPLE statements\n");
2367 fprintf (stderr
, "Kind Stmts Bytes\n");
2368 fprintf (stderr
, "---------------------------------------\n");
2369 for (i
= 0; i
< (int) gimple_alloc_kind_all
; ++i
)
2371 fprintf (stderr
, "%-20s %7d %10d\n", gimple_alloc_kind_names
[i
],
2372 gimple_alloc_counts
[i
], gimple_alloc_sizes
[i
]);
2373 total_tuples
+= gimple_alloc_counts
[i
];
2374 total_bytes
+= gimple_alloc_sizes
[i
];
2376 fprintf (stderr
, "---------------------------------------\n");
2377 fprintf (stderr
, "%-20s %7d %10d\n", "Total", total_tuples
, total_bytes
);
2378 fprintf (stderr
, "---------------------------------------\n");
2380 fprintf (stderr
, "No gimple statistics\n");
2385 /* Return the number of operands needed on the RHS of a GIMPLE
2386 assignment for an expression with tree code CODE. */
2389 get_gimple_rhs_num_ops (enum tree_code code
)
2391 enum gimple_rhs_class rhs_class
= get_gimple_rhs_class (code
);
2393 if (rhs_class
== GIMPLE_UNARY_RHS
|| rhs_class
== GIMPLE_SINGLE_RHS
)
2395 else if (rhs_class
== GIMPLE_BINARY_RHS
)
2401 #define DEFTREECODE(SYM, STRING, TYPE, NARGS) \
2403 ((TYPE) == tcc_unary ? GIMPLE_UNARY_RHS \
2404 : ((TYPE) == tcc_binary \
2405 || (TYPE) == tcc_comparison) ? GIMPLE_BINARY_RHS \
2406 : ((TYPE) == tcc_constant \
2407 || (TYPE) == tcc_declaration \
2408 || (TYPE) == tcc_reference) ? GIMPLE_SINGLE_RHS \
2409 : ((SYM) == TRUTH_AND_EXPR \
2410 || (SYM) == TRUTH_OR_EXPR \
2411 || (SYM) == TRUTH_XOR_EXPR) ? GIMPLE_BINARY_RHS \
2412 : (SYM) == TRUTH_NOT_EXPR ? GIMPLE_UNARY_RHS \
2413 : ((SYM) == COND_EXPR \
2414 || (SYM) == CONSTRUCTOR \
2415 || (SYM) == OBJ_TYPE_REF \
2416 || (SYM) == ASSERT_EXPR \
2417 || (SYM) == ADDR_EXPR \
2418 || (SYM) == WITH_SIZE_EXPR \
2419 || (SYM) == SSA_NAME \
2420 || (SYM) == POLYNOMIAL_CHREC \
2421 || (SYM) == DOT_PROD_EXPR \
2422 || (SYM) == VEC_COND_EXPR \
2423 || (SYM) == REALIGN_LOAD_EXPR) ? GIMPLE_SINGLE_RHS \
2424 : GIMPLE_INVALID_RHS),
2425 #define END_OF_BASE_TREE_CODES (unsigned char) GIMPLE_INVALID_RHS,
2427 const unsigned char gimple_rhs_class_table
[] = {
2428 #include "all-tree.def"
2432 #undef END_OF_BASE_TREE_CODES
2434 /* For the definitive definition of GIMPLE, see doc/tree-ssa.texi. */
2436 /* Validation of GIMPLE expressions. */
2438 /* Return true if OP is an acceptable tree node to be used as a GIMPLE
2442 is_gimple_operand (const_tree op
)
2444 return op
&& get_gimple_rhs_class (TREE_CODE (op
)) == GIMPLE_SINGLE_RHS
;
2447 /* Returns true iff T is a valid RHS for an assignment to a renamed
2448 user -- or front-end generated artificial -- variable. */
2451 is_gimple_reg_rhs (tree t
)
2453 return get_gimple_rhs_class (TREE_CODE (t
)) != GIMPLE_INVALID_RHS
;
2456 /* Returns true iff T is a valid RHS for an assignment to an un-renamed
2457 LHS, or for a call argument. */
2460 is_gimple_mem_rhs (tree t
)
2462 /* If we're dealing with a renamable type, either source or dest must be
2463 a renamed variable. */
2464 if (is_gimple_reg_type (TREE_TYPE (t
)))
2465 return is_gimple_val (t
);
2467 return is_gimple_val (t
) || is_gimple_lvalue (t
);
2470 /* Return true if T is a valid LHS for a GIMPLE assignment expression. */
2473 is_gimple_lvalue (tree t
)
2475 return (is_gimple_addressable (t
)
2476 || TREE_CODE (t
) == WITH_SIZE_EXPR
2477 /* These are complex lvalues, but don't have addresses, so they
2479 || TREE_CODE (t
) == BIT_FIELD_REF
);
2482 /* Return true if T is a GIMPLE condition. */
2485 is_gimple_condexpr (tree t
)
2487 return (is_gimple_val (t
) || (COMPARISON_CLASS_P (t
)
2488 && !tree_could_trap_p (t
)
2489 && is_gimple_val (TREE_OPERAND (t
, 0))
2490 && is_gimple_val (TREE_OPERAND (t
, 1))));
2493 /* Return true if T is something whose address can be taken. */
2496 is_gimple_addressable (tree t
)
2498 return (is_gimple_id (t
) || handled_component_p (t
) || INDIRECT_REF_P (t
));
2501 /* Return true if T is a valid gimple constant. */
2504 is_gimple_constant (const_tree t
)
2506 switch (TREE_CODE (t
))
2516 /* Vector constant constructors are gimple invariant. */
2518 if (TREE_TYPE (t
) && TREE_CODE (TREE_TYPE (t
)) == VECTOR_TYPE
)
2519 return TREE_CONSTANT (t
);
2528 /* Return true if T is a gimple address. */
2531 is_gimple_address (const_tree t
)
2535 if (TREE_CODE (t
) != ADDR_EXPR
)
2538 op
= TREE_OPERAND (t
, 0);
2539 while (handled_component_p (op
))
2541 if ((TREE_CODE (op
) == ARRAY_REF
2542 || TREE_CODE (op
) == ARRAY_RANGE_REF
)
2543 && !is_gimple_val (TREE_OPERAND (op
, 1)))
2546 op
= TREE_OPERAND (op
, 0);
2549 if (CONSTANT_CLASS_P (op
) || INDIRECT_REF_P (op
))
2552 switch (TREE_CODE (op
))
2567 /* Strip out all handled components that produce invariant
2571 strip_invariant_refs (const_tree op
)
2573 while (handled_component_p (op
))
2575 switch (TREE_CODE (op
))
2578 case ARRAY_RANGE_REF
:
2579 if (!is_gimple_constant (TREE_OPERAND (op
, 1))
2580 || TREE_OPERAND (op
, 2) != NULL_TREE
2581 || TREE_OPERAND (op
, 3) != NULL_TREE
)
2586 if (TREE_OPERAND (op
, 2) != NULL_TREE
)
2592 op
= TREE_OPERAND (op
, 0);
2598 /* Return true if T is a gimple invariant address. */
2601 is_gimple_invariant_address (const_tree t
)
2605 if (TREE_CODE (t
) != ADDR_EXPR
)
2608 op
= strip_invariant_refs (TREE_OPERAND (t
, 0));
2610 return op
&& (CONSTANT_CLASS_P (op
) || decl_address_invariant_p (op
));
2613 /* Return true if T is a gimple invariant address at IPA level
2614 (so addresses of variables on stack are not allowed). */
2617 is_gimple_ip_invariant_address (const_tree t
)
2621 if (TREE_CODE (t
) != ADDR_EXPR
)
2624 op
= strip_invariant_refs (TREE_OPERAND (t
, 0));
2626 return op
&& (CONSTANT_CLASS_P (op
) || decl_address_ip_invariant_p (op
));
2629 /* Return true if T is a GIMPLE minimal invariant. It's a restricted
2630 form of function invariant. */
2633 is_gimple_min_invariant (const_tree t
)
2635 if (TREE_CODE (t
) == ADDR_EXPR
)
2636 return is_gimple_invariant_address (t
);
2638 return is_gimple_constant (t
);
2641 /* Return true if T is a GIMPLE interprocedural invariant. It's a restricted
2642 form of gimple minimal invariant. */
2645 is_gimple_ip_invariant (const_tree t
)
2647 if (TREE_CODE (t
) == ADDR_EXPR
)
2648 return is_gimple_ip_invariant_address (t
);
2650 return is_gimple_constant (t
);
2653 /* Return true if T looks like a valid GIMPLE statement. */
2656 is_gimple_stmt (tree t
)
2658 const enum tree_code code
= TREE_CODE (t
);
2663 /* The only valid NOP_EXPR is the empty statement. */
2664 return IS_EMPTY_STMT (t
);
2668 /* These are only valid if they're void. */
2669 return TREE_TYPE (t
) == NULL
|| VOID_TYPE_P (TREE_TYPE (t
));
2675 case CASE_LABEL_EXPR
:
2676 case TRY_CATCH_EXPR
:
2677 case TRY_FINALLY_EXPR
:
2678 case EH_FILTER_EXPR
:
2681 case STATEMENT_LIST
:
2691 /* These are always void. */
2697 /* These are valid regardless of their type. */
2705 /* Return true if T is a variable. */
2708 is_gimple_variable (tree t
)
2710 return (TREE_CODE (t
) == VAR_DECL
2711 || TREE_CODE (t
) == PARM_DECL
2712 || TREE_CODE (t
) == RESULT_DECL
2713 || TREE_CODE (t
) == SSA_NAME
);
2716 /* Return true if T is a GIMPLE identifier (something with an address). */
2719 is_gimple_id (tree t
)
2721 return (is_gimple_variable (t
)
2722 || TREE_CODE (t
) == FUNCTION_DECL
2723 || TREE_CODE (t
) == LABEL_DECL
2724 || TREE_CODE (t
) == CONST_DECL
2725 /* Allow string constants, since they are addressable. */
2726 || TREE_CODE (t
) == STRING_CST
);
2729 /* Return true if TYPE is a suitable type for a scalar register variable. */
2732 is_gimple_reg_type (tree type
)
2734 return !AGGREGATE_TYPE_P (type
);
2737 /* Return true if T is a non-aggregate register variable. */
2740 is_gimple_reg (tree t
)
2742 if (TREE_CODE (t
) == SSA_NAME
)
2743 t
= SSA_NAME_VAR (t
);
2745 if (!is_gimple_variable (t
))
2748 if (!is_gimple_reg_type (TREE_TYPE (t
)))
2751 /* A volatile decl is not acceptable because we can't reuse it as
2752 needed. We need to copy it into a temp first. */
2753 if (TREE_THIS_VOLATILE (t
))
2756 /* We define "registers" as things that can be renamed as needed,
2757 which with our infrastructure does not apply to memory. */
2758 if (needs_to_live_in_memory (t
))
2761 /* Hard register variables are an interesting case. For those that
2762 are call-clobbered, we don't know where all the calls are, since
2763 we don't (want to) take into account which operations will turn
2764 into libcalls at the rtl level. For those that are call-saved,
2765 we don't currently model the fact that calls may in fact change
2766 global hard registers, nor do we examine ASM_CLOBBERS at the tree
2767 level, and so miss variable changes that might imply. All around,
2768 it seems safest to not do too much optimization with these at the
2769 tree level at all. We'll have to rely on the rtl optimizers to
2770 clean this up, as there we've got all the appropriate bits exposed. */
2771 if (TREE_CODE (t
) == VAR_DECL
&& DECL_HARD_REGISTER (t
))
2774 /* Complex and vector values must have been put into SSA-like form.
2775 That is, no assignments to the individual components. */
2776 if (TREE_CODE (TREE_TYPE (t
)) == COMPLEX_TYPE
2777 || TREE_CODE (TREE_TYPE (t
)) == VECTOR_TYPE
)
2778 return DECL_GIMPLE_REG_P (t
);
2784 /* Return true if T is a GIMPLE variable whose address is not needed. */
2787 is_gimple_non_addressable (tree t
)
2789 if (TREE_CODE (t
) == SSA_NAME
)
2790 t
= SSA_NAME_VAR (t
);
2792 return (is_gimple_variable (t
) && ! needs_to_live_in_memory (t
));
2795 /* Return true if T is a GIMPLE rvalue, i.e. an identifier or a constant. */
2798 is_gimple_val (tree t
)
2800 /* Make loads from volatiles and memory vars explicit. */
2801 if (is_gimple_variable (t
)
2802 && is_gimple_reg_type (TREE_TYPE (t
))
2803 && !is_gimple_reg (t
))
2806 return (is_gimple_variable (t
) || is_gimple_min_invariant (t
));
2809 /* Similarly, but accept hard registers as inputs to asm statements. */
2812 is_gimple_asm_val (tree t
)
2814 if (TREE_CODE (t
) == VAR_DECL
&& DECL_HARD_REGISTER (t
))
2817 return is_gimple_val (t
);
2820 /* Return true if T is a GIMPLE minimal lvalue. */
2823 is_gimple_min_lval (tree t
)
2825 if (!(t
= CONST_CAST_TREE (strip_invariant_refs (t
))))
2827 return (is_gimple_id (t
) || TREE_CODE (t
) == INDIRECT_REF
);
2830 /* Return true if T is a typecast operation. */
2833 is_gimple_cast (tree t
)
2835 return (CONVERT_EXPR_P (t
)
2836 || TREE_CODE (t
) == FIX_TRUNC_EXPR
);
2839 /* Return true if T is a valid function operand of a CALL_EXPR. */
2842 is_gimple_call_addr (tree t
)
2844 return (TREE_CODE (t
) == OBJ_TYPE_REF
|| is_gimple_val (t
));
2847 /* If T makes a function call, return the corresponding CALL_EXPR operand.
2848 Otherwise, return NULL_TREE. */
2851 get_call_expr_in (tree t
)
2853 if (TREE_CODE (t
) == MODIFY_EXPR
)
2854 t
= TREE_OPERAND (t
, 1);
2855 if (TREE_CODE (t
) == WITH_SIZE_EXPR
)
2856 t
= TREE_OPERAND (t
, 0);
2857 if (TREE_CODE (t
) == CALL_EXPR
)
2863 /* Given a memory reference expression T, return its base address.
2864 The base address of a memory reference expression is the main
2865 object being referenced. For instance, the base address for
2866 'array[i].fld[j]' is 'array'. You can think of this as stripping
2867 away the offset part from a memory address.
2869 This function calls handled_component_p to strip away all the inner
2870 parts of the memory reference until it reaches the base object. */
2873 get_base_address (tree t
)
2875 while (handled_component_p (t
))
2876 t
= TREE_OPERAND (t
, 0);
2879 || TREE_CODE (t
) == STRING_CST
2880 || TREE_CODE (t
) == CONSTRUCTOR
2881 || INDIRECT_REF_P (t
))
2888 recalculate_side_effects (tree t
)
2890 enum tree_code code
= TREE_CODE (t
);
2891 int len
= TREE_OPERAND_LENGTH (t
);
2894 switch (TREE_CODE_CLASS (code
))
2896 case tcc_expression
:
2902 case PREDECREMENT_EXPR
:
2903 case PREINCREMENT_EXPR
:
2904 case POSTDECREMENT_EXPR
:
2905 case POSTINCREMENT_EXPR
:
2906 /* All of these have side-effects, no matter what their
2915 case tcc_comparison
: /* a comparison expression */
2916 case tcc_unary
: /* a unary arithmetic expression */
2917 case tcc_binary
: /* a binary arithmetic expression */
2918 case tcc_reference
: /* a reference */
2919 case tcc_vl_exp
: /* a function call */
2920 TREE_SIDE_EFFECTS (t
) = TREE_THIS_VOLATILE (t
);
2921 for (i
= 0; i
< len
; ++i
)
2923 tree op
= TREE_OPERAND (t
, i
);
2924 if (op
&& TREE_SIDE_EFFECTS (op
))
2925 TREE_SIDE_EFFECTS (t
) = 1;
2930 /* No side-effects. */
2938 /* Canonicalize a tree T for use in a COND_EXPR as conditional. Returns
2939 a canonicalized tree that is valid for a COND_EXPR or NULL_TREE, if
2940 we failed to create one. */
2943 canonicalize_cond_expr_cond (tree t
)
2945 /* Strip conversions around boolean operations. */
2946 if (CONVERT_EXPR_P (t
)
2947 && truth_value_p (TREE_CODE (TREE_OPERAND (t
, 0))))
2948 t
= TREE_OPERAND (t
, 0);
2950 /* For (bool)x use x != 0. */
2951 if (CONVERT_EXPR_P (t
)
2952 && TREE_CODE (TREE_TYPE (t
)) == BOOLEAN_TYPE
)
2954 tree top0
= TREE_OPERAND (t
, 0);
2955 t
= build2 (NE_EXPR
, TREE_TYPE (t
),
2956 top0
, build_int_cst (TREE_TYPE (top0
), 0));
2958 /* For !x use x == 0. */
2959 else if (TREE_CODE (t
) == TRUTH_NOT_EXPR
)
2961 tree top0
= TREE_OPERAND (t
, 0);
2962 t
= build2 (EQ_EXPR
, TREE_TYPE (t
),
2963 top0
, build_int_cst (TREE_TYPE (top0
), 0));
2965 /* For cmp ? 1 : 0 use cmp. */
2966 else if (TREE_CODE (t
) == COND_EXPR
2967 && COMPARISON_CLASS_P (TREE_OPERAND (t
, 0))
2968 && integer_onep (TREE_OPERAND (t
, 1))
2969 && integer_zerop (TREE_OPERAND (t
, 2)))
2971 tree top0
= TREE_OPERAND (t
, 0);
2972 t
= build2 (TREE_CODE (top0
), TREE_TYPE (t
),
2973 TREE_OPERAND (top0
, 0), TREE_OPERAND (top0
, 1));
2976 if (is_gimple_condexpr (t
))
2982 /* Build a GIMPLE_CALL identical to STMT but skipping the arguments in
2983 the positions marked by the set ARGS_TO_SKIP. */
2986 gimple_call_copy_skip_args (gimple stmt
, bitmap args_to_skip
)
2989 tree fn
= gimple_call_fn (stmt
);
2990 int nargs
= gimple_call_num_args (stmt
);
2991 VEC(tree
, heap
) *vargs
= VEC_alloc (tree
, heap
, nargs
);
2994 for (i
= 0; i
< nargs
; i
++)
2995 if (!bitmap_bit_p (args_to_skip
, i
))
2996 VEC_quick_push (tree
, vargs
, gimple_call_arg (stmt
, i
));
2998 new_stmt
= gimple_build_call_vec (fn
, vargs
);
2999 VEC_free (tree
, heap
, vargs
);
3000 if (gimple_call_lhs (stmt
))
3001 gimple_call_set_lhs (new_stmt
, gimple_call_lhs (stmt
));
3003 gimple_set_vuse (new_stmt
, gimple_vuse (stmt
));
3004 gimple_set_vdef (new_stmt
, gimple_vdef (stmt
));
3006 gimple_set_block (new_stmt
, gimple_block (stmt
));
3007 if (gimple_has_location (stmt
))
3008 gimple_set_location (new_stmt
, gimple_location (stmt
));
3010 /* Carry all the flags to the new GIMPLE_CALL. */
3011 gimple_call_set_chain (new_stmt
, gimple_call_chain (stmt
));
3012 gimple_call_set_tail (new_stmt
, gimple_call_tail_p (stmt
));
3013 gimple_call_set_cannot_inline (new_stmt
, gimple_call_cannot_inline_p (stmt
));
3014 gimple_call_set_return_slot_opt (new_stmt
, gimple_call_return_slot_opt_p (stmt
));
3015 gimple_call_set_from_thunk (new_stmt
, gimple_call_from_thunk_p (stmt
));
3016 gimple_call_set_va_arg_pack (new_stmt
, gimple_call_va_arg_pack_p (stmt
));
3018 gimple_set_modified (new_stmt
, true);
3024 static hashval_t
gimple_type_hash (const void *);
3026 /* Structure used to maintain a cache of some type pairs compared by
3027 gimple_types_compatible_p when comparing aggregate types. There are
3028 four possible values for SAME_P:
3030 -2: The pair (T1, T2) has just been inserted in the table.
3031 -1: The pair (T1, T2) is currently being compared.
3032 0: T1 and T2 are different types.
3033 1: T1 and T2 are the same type.
3035 This table is only used when comparing aggregate types to avoid
3036 infinite recursion due to self-referential types. */
3043 typedef struct type_pair_d
*type_pair_t
;
3045 /* Return a hash value for the type pair pointed-to by P. */
3048 type_pair_hash (const void *p
)
3050 const struct type_pair_d
*pair
= (const struct type_pair_d
*) p
;
3051 hashval_t val1
= pair
->uid1
;
3052 hashval_t val2
= pair
->uid2
;
3053 return (iterative_hash_hashval_t (val2
, val1
)
3054 ^ iterative_hash_hashval_t (val1
, val2
));
3057 /* Compare two type pairs pointed-to by P1 and P2. */
3060 type_pair_eq (const void *p1
, const void *p2
)
3062 const struct type_pair_d
*pair1
= (const struct type_pair_d
*) p1
;
3063 const struct type_pair_d
*pair2
= (const struct type_pair_d
*) p2
;
3064 return ((pair1
->uid1
== pair2
->uid1
&& pair1
->uid2
== pair2
->uid2
)
3065 || (pair1
->uid1
== pair2
->uid2
&& pair1
->uid2
== pair2
->uid1
));
3068 /* Lookup the pair of types T1 and T2 in *VISITED_P. Insert a new
3069 entry if none existed. */
3072 lookup_type_pair (tree t1
, tree t2
, htab_t
*visited_p
, struct obstack
*ob_p
)
3074 struct type_pair_d pair
;
3078 if (*visited_p
== NULL
)
3080 *visited_p
= htab_create (251, type_pair_hash
, type_pair_eq
, NULL
);
3081 gcc_obstack_init (ob_p
);
3084 pair
.uid1
= TYPE_UID (t1
);
3085 pair
.uid2
= TYPE_UID (t2
);
3086 slot
= htab_find_slot (*visited_p
, &pair
, INSERT
);
3089 p
= *((type_pair_t
*) slot
);
3092 p
= XOBNEW (ob_p
, struct type_pair_d
);
3093 p
->uid1
= TYPE_UID (t1
);
3094 p
->uid2
= TYPE_UID (t2
);
3103 /* Return true if T1 and T2 have the same name. If FOR_COMPLETION_P is
3104 true then if any type has no name return false, otherwise return
3105 true if both types have no names. */
3108 compare_type_names_p (tree t1
, tree t2
, bool for_completion_p
)
3110 tree name1
= TYPE_NAME (t1
);
3111 tree name2
= TYPE_NAME (t2
);
3113 /* Consider anonymous types all unique for completion. */
3114 if (for_completion_p
3115 && (!name1
|| !name2
))
3118 if (name1
&& TREE_CODE (name1
) == TYPE_DECL
)
3120 name1
= DECL_NAME (name1
);
3121 if (for_completion_p
3125 gcc_assert (!name1
|| TREE_CODE (name1
) == IDENTIFIER_NODE
);
3127 if (name2
&& TREE_CODE (name2
) == TYPE_DECL
)
3129 name2
= DECL_NAME (name2
);
3130 if (for_completion_p
3134 gcc_assert (!name2
|| TREE_CODE (name2
) == IDENTIFIER_NODE
);
3136 /* Identifiers can be compared with pointer equality rather
3137 than a string comparison. */
3144 /* Return true if the field decls F1 and F2 are at the same offset. */
3147 compare_field_offset (tree f1
, tree f2
)
3149 if (DECL_OFFSET_ALIGN (f1
) == DECL_OFFSET_ALIGN (f2
))
3150 return (operand_equal_p (DECL_FIELD_OFFSET (f1
),
3151 DECL_FIELD_OFFSET (f2
), 0)
3152 && tree_int_cst_equal (DECL_FIELD_BIT_OFFSET (f1
),
3153 DECL_FIELD_BIT_OFFSET (f2
)));
3155 /* Fortran and C do not always agree on what DECL_OFFSET_ALIGN
3156 should be, so handle differing ones specially by decomposing
3157 the offset into a byte and bit offset manually. */
3158 if (host_integerp (DECL_FIELD_OFFSET (f1
), 0)
3159 && host_integerp (DECL_FIELD_OFFSET (f2
), 0))
3161 unsigned HOST_WIDE_INT byte_offset1
, byte_offset2
;
3162 unsigned HOST_WIDE_INT bit_offset1
, bit_offset2
;
3163 bit_offset1
= TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (f1
));
3164 byte_offset1
= (TREE_INT_CST_LOW (DECL_FIELD_OFFSET (f1
))
3165 + bit_offset1
/ BITS_PER_UNIT
);
3166 bit_offset2
= TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (f2
));
3167 byte_offset2
= (TREE_INT_CST_LOW (DECL_FIELD_OFFSET (f2
))
3168 + bit_offset2
/ BITS_PER_UNIT
);
3169 if (byte_offset1
!= byte_offset2
)
3171 return bit_offset1
% BITS_PER_UNIT
== bit_offset2
% BITS_PER_UNIT
;
3177 /* Return 1 iff T1 and T2 are structurally identical.
3178 Otherwise, return 0. */
3181 gimple_types_compatible_p (tree t1
, tree t2
)
3183 type_pair_t p
= NULL
;
3185 /* Check first for the obvious case of pointer identity. */
3189 /* Check that we have two types to compare. */
3190 if (t1
== NULL_TREE
|| t2
== NULL_TREE
)
3193 /* Can't be the same type if the types don't have the same code. */
3194 if (TREE_CODE (t1
) != TREE_CODE (t2
))
3197 /* Can't be the same type if they have different CV qualifiers. */
3198 if (TYPE_QUALS (t1
) != TYPE_QUALS (t2
))
3201 /* Void types are always the same. */
3202 if (TREE_CODE (t1
) == VOID_TYPE
)
3205 /* For numerical types do some simple checks before doing three
3206 hashtable queries. */
3207 if (INTEGRAL_TYPE_P (t1
)
3208 || SCALAR_FLOAT_TYPE_P (t1
)
3209 || FIXED_POINT_TYPE_P (t1
)
3210 || TREE_CODE (t1
) == VECTOR_TYPE
3211 || TREE_CODE (t1
) == COMPLEX_TYPE
3212 || TREE_CODE (t1
) == OFFSET_TYPE
)
3214 /* Can't be the same type if they have different alignment,
3215 sign, precision or mode. */
3216 if (TYPE_ALIGN (t1
) != TYPE_ALIGN (t2
)
3217 || TYPE_PRECISION (t1
) != TYPE_PRECISION (t2
)
3218 || TYPE_MODE (t1
) != TYPE_MODE (t2
)
3219 || TYPE_UNSIGNED (t1
) != TYPE_UNSIGNED (t2
))
3222 if (TREE_CODE (t1
) == INTEGER_TYPE
3223 && (TYPE_IS_SIZETYPE (t1
) != TYPE_IS_SIZETYPE (t2
)
3224 || TYPE_STRING_FLAG (t1
) != TYPE_STRING_FLAG (t2
)))
3227 /* That's all we need to check for float and fixed-point types. */
3228 if (SCALAR_FLOAT_TYPE_P (t1
)
3229 || FIXED_POINT_TYPE_P (t1
))
3232 /* Perform cheap tail-recursion for vector and complex types. */
3233 if (TREE_CODE (t1
) == VECTOR_TYPE
3234 || TREE_CODE (t1
) == COMPLEX_TYPE
)
3235 return gimple_types_compatible_p (TREE_TYPE (t1
), TREE_TYPE (t2
));
3237 /* For integral types fall thru to more complex checks. */
3240 /* If the hash values of t1 and t2 are different the types can't
3241 possibly be the same. This helps keeping the type-pair hashtable
3242 small, only tracking comparisons for hash collisions. */
3243 if (gimple_type_hash (t1
) != gimple_type_hash (t2
))
3246 /* If we've visited this type pair before (in the case of aggregates
3247 with self-referential types), and we made a decision, return it. */
3248 p
= lookup_type_pair (t1
, t2
, >c_visited
, >c_ob
);
3249 if (p
->same_p
== 0 || p
->same_p
== 1)
3251 /* We have already decided whether T1 and T2 are the
3252 same, return the cached result. */
3253 return p
->same_p
== 1;
3255 else if (p
->same_p
== -1)
3257 /* We are currently comparing this pair of types, assume
3258 that they are the same and let the caller decide. */
3262 gcc_assert (p
->same_p
== -2);
3264 /* Mark the (T1, T2) comparison in progress. */
3267 /* If their attributes are not the same they can't be the same type. */
3268 if (!attribute_list_equal (TYPE_ATTRIBUTES (t1
), TYPE_ATTRIBUTES (t2
)))
3269 goto different_types
;
3271 /* Do type-specific comparisons. */
3272 switch (TREE_CODE (t1
))
3275 /* Array types are the same if the element types are the same and
3276 the number of elements are the same. */
3277 if (!gimple_types_compatible_p (TREE_TYPE (t1
), TREE_TYPE (t2
))
3278 || TYPE_STRING_FLAG (t1
) != TYPE_STRING_FLAG (t2
)
3279 || TYPE_NONALIASED_COMPONENT (t1
) != TYPE_NONALIASED_COMPONENT (t2
))
3280 goto different_types
;
3283 tree i1
= TYPE_DOMAIN (t1
);
3284 tree i2
= TYPE_DOMAIN (t2
);
3286 /* For an incomplete external array, the type domain can be
3287 NULL_TREE. Check this condition also. */
3288 if (i1
== NULL_TREE
&& i2
== NULL_TREE
)
3290 else if (i1
== NULL_TREE
|| i2
== NULL_TREE
)
3291 goto different_types
;
3292 /* If for a complete array type the possibly gimplified sizes
3293 are different the types are different. */
3294 else if (((TYPE_SIZE (i1
) != NULL
) ^ (TYPE_SIZE (i2
) != NULL
))
3297 && !operand_equal_p (TYPE_SIZE (i1
), TYPE_SIZE (i2
), 0)))
3298 goto different_types
;
3301 tree min1
= TYPE_MIN_VALUE (i1
);
3302 tree min2
= TYPE_MIN_VALUE (i2
);
3303 tree max1
= TYPE_MAX_VALUE (i1
);
3304 tree max2
= TYPE_MAX_VALUE (i2
);
3306 /* The minimum/maximum values have to be the same. */
3308 || (min1
&& min2
&& operand_equal_p (min1
, min2
, 0)))
3310 || (max1
&& max2
&& operand_equal_p (max1
, max2
, 0))))
3313 goto different_types
;
3318 /* Method types should belong to the same class. */
3319 if (!gimple_types_compatible_p (TYPE_METHOD_BASETYPE (t1
),
3320 TYPE_METHOD_BASETYPE (t2
)))
3321 goto different_types
;
3326 /* Function types are the same if the return type and arguments types
3328 if (!gimple_types_compatible_p (TREE_TYPE (t1
), TREE_TYPE (t2
)))
3329 goto different_types
;
3332 if (!targetm
.comp_type_attributes (t1
, t2
))
3333 goto different_types
;
3335 if (TYPE_ARG_TYPES (t1
) == TYPE_ARG_TYPES (t2
))
3339 tree parms1
, parms2
;
3341 for (parms1
= TYPE_ARG_TYPES (t1
), parms2
= TYPE_ARG_TYPES (t2
);
3343 parms1
= TREE_CHAIN (parms1
), parms2
= TREE_CHAIN (parms2
))
3345 if (!gimple_types_compatible_p (TREE_VALUE (parms1
),
3346 TREE_VALUE (parms2
)))
3347 goto different_types
;
3350 if (parms1
|| parms2
)
3351 goto different_types
;
3359 if (!gimple_types_compatible_p (TREE_TYPE (t1
), TREE_TYPE (t2
))
3360 || !gimple_types_compatible_p (TYPE_OFFSET_BASETYPE (t1
),
3361 TYPE_OFFSET_BASETYPE (t2
)))
3362 goto different_types
;
3368 case REFERENCE_TYPE
:
3370 /* If the two pointers have different ref-all attributes,
3371 they can't be the same type. */
3372 if (TYPE_REF_CAN_ALIAS_ALL (t1
) != TYPE_REF_CAN_ALIAS_ALL (t2
))
3373 goto different_types
;
3375 /* If one pointer points to an incomplete type variant of
3376 the other pointed-to type they are the same. */
3377 if (TREE_CODE (TREE_TYPE (t1
)) == TREE_CODE (TREE_TYPE (t2
))
3378 && RECORD_OR_UNION_TYPE_P (TREE_TYPE (t1
))
3379 && (!COMPLETE_TYPE_P (TREE_TYPE (t1
))
3380 || !COMPLETE_TYPE_P (TREE_TYPE (t2
)))
3381 && compare_type_names_p (TYPE_MAIN_VARIANT (TREE_TYPE (t1
)),
3382 TYPE_MAIN_VARIANT (TREE_TYPE (t2
)), true))
3384 /* Replace the pointed-to incomplete type with the
3386 if (COMPLETE_TYPE_P (TREE_TYPE (t2
)))
3387 TREE_TYPE (t1
) = TREE_TYPE (t2
);
3389 TREE_TYPE (t2
) = TREE_TYPE (t1
);
3393 /* Otherwise, pointer and reference types are the same if the
3394 pointed-to types are the same. */
3395 if (gimple_types_compatible_p (TREE_TYPE (t1
), TREE_TYPE (t2
)))
3398 goto different_types
;
3404 tree min1
= TYPE_MIN_VALUE (t1
);
3405 tree max1
= TYPE_MAX_VALUE (t1
);
3406 tree min2
= TYPE_MIN_VALUE (t2
);
3407 tree max2
= TYPE_MAX_VALUE (t2
);
3408 bool min_equal_p
= false;
3409 bool max_equal_p
= false;
3411 /* If either type has a minimum value, the other type must
3413 if (min1
== NULL_TREE
&& min2
== NULL_TREE
)
3415 else if (min1
&& min2
&& operand_equal_p (min1
, min2
, 0))
3418 /* Likewise, if either type has a maximum value, the other
3419 type must have the same. */
3420 if (max1
== NULL_TREE
&& max2
== NULL_TREE
)
3422 else if (max1
&& max2
&& operand_equal_p (max1
, max2
, 0))
3425 if (!min_equal_p
|| !max_equal_p
)
3426 goto different_types
;
3433 /* FIXME lto, we cannot check bounds on enumeral types because
3434 different front ends will produce different values.
3435 In C, enumeral types are integers, while in C++ each element
3436 will have its own symbolic value. We should decide how enums
3437 are to be represented in GIMPLE and have each front end lower
3441 /* For enumeral types, all the values must be the same. */
3442 if (TYPE_VALUES (t1
) == TYPE_VALUES (t2
))
3445 for (v1
= TYPE_VALUES (t1
), v2
= TYPE_VALUES (t2
);
3447 v1
= TREE_CHAIN (v1
), v2
= TREE_CHAIN (v2
))
3449 tree c1
= TREE_VALUE (v1
);
3450 tree c2
= TREE_VALUE (v2
);
3452 if (TREE_CODE (c1
) == CONST_DECL
)
3453 c1
= DECL_INITIAL (c1
);
3455 if (TREE_CODE (c2
) == CONST_DECL
)
3456 c2
= DECL_INITIAL (c2
);
3458 if (tree_int_cst_equal (c1
, c2
) != 1)
3459 goto different_types
;
3462 /* If one enumeration has more values than the other, they
3463 are not the same. */
3465 goto different_types
;
3472 case QUAL_UNION_TYPE
:
3476 /* If one type requires structural equality checks and the
3477 other doesn't, do not merge the types. */
3478 if (TYPE_STRUCTURAL_EQUALITY_P (t1
)
3479 != TYPE_STRUCTURAL_EQUALITY_P (t2
))
3480 goto different_types
;
3482 /* The struct tags shall compare equal. */
3483 if (!compare_type_names_p (TYPE_MAIN_VARIANT (t1
),
3484 TYPE_MAIN_VARIANT (t2
), false))
3485 goto different_types
;
3487 /* For aggregate types, all the fields must be the same. */
3488 for (f1
= TYPE_FIELDS (t1
), f2
= TYPE_FIELDS (t2
);
3490 f1
= TREE_CHAIN (f1
), f2
= TREE_CHAIN (f2
))
3492 /* The fields must have the same name, offset and type. */
3493 if (DECL_NAME (f1
) != DECL_NAME (f2
)
3494 || DECL_NONADDRESSABLE_P (f1
) != DECL_NONADDRESSABLE_P (f2
)
3495 || !compare_field_offset (f1
, f2
)
3496 || !gimple_types_compatible_p (TREE_TYPE (f1
),
3498 goto different_types
;
3501 /* If one aggregate has more fields than the other, they
3502 are not the same. */
3504 goto different_types
;
3513 /* Common exit path for types that are not compatible. */
3518 /* Common exit path for types that are compatible. */
3527 /* Per pointer state for the SCC finding. The on_sccstack flag
3528 is not strictly required, it is true when there is no hash value
3529 recorded for the type and false otherwise. But querying that
3534 unsigned int dfsnum
;
3540 static unsigned int next_dfs_num
;
3543 iterative_hash_gimple_type (tree
, hashval_t
, VEC(tree
, heap
) **,
3544 struct pointer_map_t
*, struct obstack
*);
3546 /* DFS visit the edge from the callers type with state *STATE to T.
3547 Update the callers type hash V with the hash for T if it is not part
3548 of the SCC containing the callers type and return it.
3549 SCCSTACK, SCCSTATE and SCCSTATE_OBSTACK are state for the DFS walk done. */
3552 visit (tree t
, struct sccs
*state
, hashval_t v
,
3553 VEC (tree
, heap
) **sccstack
,
3554 struct pointer_map_t
*sccstate
,
3555 struct obstack
*sccstate_obstack
)
3557 struct sccs
*cstate
= NULL
;
3560 /* If there is a hash value recorded for this type then it can't
3561 possibly be part of our parent SCC. Simply mix in its hash. */
3562 if ((slot
= pointer_map_contains (type_hash_cache
, t
)))
3563 return iterative_hash_hashval_t ((hashval_t
) (size_t) *slot
, v
);
3565 if ((slot
= pointer_map_contains (sccstate
, t
)) != NULL
)
3566 cstate
= (struct sccs
*)*slot
;
3570 /* Not yet visited. DFS recurse. */
3571 tem
= iterative_hash_gimple_type (t
, v
,
3572 sccstack
, sccstate
, sccstate_obstack
);
3574 cstate
= (struct sccs
*)* pointer_map_contains (sccstate
, t
);
3575 state
->low
= MIN (state
->low
, cstate
->low
);
3576 /* If the type is no longer on the SCC stack and thus is not part
3577 of the parents SCC mix in its hash value. Otherwise we will
3578 ignore the type for hashing purposes and return the unaltered
3580 if (!cstate
->on_sccstack
)
3583 if (cstate
->dfsnum
< state
->dfsnum
3584 && cstate
->on_sccstack
)
3585 state
->low
= MIN (cstate
->dfsnum
, state
->low
);
3587 /* We are part of our parents SCC, skip this type during hashing
3588 and return the unaltered hash value. */
3592 /* Hash NAME with the previous hash value V and return it. */
3595 iterative_hash_name (tree name
, hashval_t v
)
3599 if (TREE_CODE (name
) == TYPE_DECL
)
3600 name
= DECL_NAME (name
);
3603 gcc_assert (TREE_CODE (name
) == IDENTIFIER_NODE
);
3604 return iterative_hash_object (IDENTIFIER_HASH_VALUE (name
), v
);
3607 /* Returning a hash value for gimple type TYPE combined with VAL.
3608 SCCSTACK, SCCSTATE and SCCSTATE_OBSTACK are state for the DFS walk done.
3610 To hash a type we end up hashing in types that are reachable.
3611 Through pointers we can end up with cycles which messes up the
3612 required property that we need to compute the same hash value
3613 for structurally equivalent types. To avoid this we have to
3614 hash all types in a cycle (the SCC) in a commutative way. The
3615 easiest way is to not mix in the hashes of the SCC members at
3616 all. To make this work we have to delay setting the hash
3617 values of the SCC until it is complete. */
3620 iterative_hash_gimple_type (tree type
, hashval_t val
,
3621 VEC(tree
, heap
) **sccstack
,
3622 struct pointer_map_t
*sccstate
,
3623 struct obstack
*sccstate_obstack
)
3629 #ifdef ENABLE_CHECKING
3630 /* Not visited during this DFS walk nor during previous walks. */
3631 gcc_assert (!pointer_map_contains (type_hash_cache
, type
)
3632 && !pointer_map_contains (sccstate
, type
));
3634 state
= XOBNEW (sccstate_obstack
, struct sccs
);
3635 *pointer_map_insert (sccstate
, type
) = state
;
3637 VEC_safe_push (tree
, heap
, *sccstack
, type
);
3638 state
->dfsnum
= next_dfs_num
++;
3639 state
->low
= state
->dfsnum
;
3640 state
->on_sccstack
= true;
3642 /* Combine a few common features of types so that types are grouped into
3643 smaller sets; when searching for existing matching types to merge,
3644 only existing types having the same features as the new type will be
3646 v
= iterative_hash_hashval_t (TREE_CODE (type
), 0);
3647 v
= iterative_hash_hashval_t (TYPE_QUALS (type
), v
);
3648 v
= iterative_hash_hashval_t (TREE_ADDRESSABLE (type
), v
);
3650 /* Do not hash the types size as this will cause differences in
3651 hash values for the complete vs. the incomplete type variant. */
3653 /* Incorporate common features of numerical types. */
3654 if (INTEGRAL_TYPE_P (type
)
3655 || SCALAR_FLOAT_TYPE_P (type
)
3656 || FIXED_POINT_TYPE_P (type
))
3658 v
= iterative_hash_hashval_t (TYPE_PRECISION (type
), v
);
3659 v
= iterative_hash_hashval_t (TYPE_MODE (type
), v
);
3660 v
= iterative_hash_hashval_t (TYPE_UNSIGNED (type
), v
);
3663 /* For pointer and reference types, fold in information about the type
3664 pointed to but do not recurse into possibly incomplete types to
3665 avoid hash differences for complete vs. incomplete types. */
3666 if (POINTER_TYPE_P (type
))
3668 if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (type
)))
3670 v
= iterative_hash_hashval_t (TREE_CODE (TREE_TYPE (type
)), v
);
3671 v
= iterative_hash_name
3672 (TYPE_NAME (TYPE_MAIN_VARIANT (TREE_TYPE (type
))), v
);
3675 v
= visit (TREE_TYPE (type
), state
, v
,
3676 sccstack
, sccstate
, sccstate_obstack
);
3679 /* For integer types hash the types min/max values and the string flag. */
3680 if (TREE_CODE (type
) == INTEGER_TYPE
)
3682 /* OMP lowering can introduce error_mark_node in place of
3683 random local decls in types. */
3684 if (TYPE_MIN_VALUE (type
) != error_mark_node
)
3685 v
= iterative_hash_expr (TYPE_MIN_VALUE (type
), v
);
3686 if (TYPE_MAX_VALUE (type
) != error_mark_node
)
3687 v
= iterative_hash_expr (TYPE_MAX_VALUE (type
), v
);
3688 v
= iterative_hash_hashval_t (TYPE_STRING_FLAG (type
), v
);
3691 /* For array types hash their domain and the string flag. */
3692 if (TREE_CODE (type
) == ARRAY_TYPE
3693 && TYPE_DOMAIN (type
))
3695 v
= iterative_hash_hashval_t (TYPE_STRING_FLAG (type
), v
);
3696 v
= visit (TYPE_DOMAIN (type
), state
, v
,
3697 sccstack
, sccstate
, sccstate_obstack
);
3700 /* Recurse for aggregates with a single element type. */
3701 if (TREE_CODE (type
) == ARRAY_TYPE
3702 || TREE_CODE (type
) == COMPLEX_TYPE
3703 || TREE_CODE (type
) == VECTOR_TYPE
)
3704 v
= visit (TREE_TYPE (type
), state
, v
,
3705 sccstack
, sccstate
, sccstate_obstack
);
3707 /* Incorporate function return and argument types. */
3708 if (TREE_CODE (type
) == FUNCTION_TYPE
|| TREE_CODE (type
) == METHOD_TYPE
)
3713 /* For method types also incorporate their parent class. */
3714 if (TREE_CODE (type
) == METHOD_TYPE
)
3715 v
= visit (TYPE_METHOD_BASETYPE (type
), state
, v
,
3716 sccstack
, sccstate
, sccstate_obstack
);
3718 v
= visit (TREE_TYPE (type
), state
, v
,
3719 sccstack
, sccstate
, sccstate_obstack
);
3721 for (p
= TYPE_ARG_TYPES (type
), na
= 0; p
; p
= TREE_CHAIN (p
))
3723 v
= visit (TREE_VALUE (p
), state
, v
,
3724 sccstack
, sccstate
, sccstate_obstack
);
3728 v
= iterative_hash_hashval_t (na
, v
);
3731 if (TREE_CODE (type
) == RECORD_TYPE
3732 || TREE_CODE (type
) == UNION_TYPE
3733 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
3738 v
= iterative_hash_name (TYPE_NAME (TYPE_MAIN_VARIANT (type
)), v
);
3740 for (f
= TYPE_FIELDS (type
), nf
= 0; f
; f
= TREE_CHAIN (f
))
3742 v
= iterative_hash_name (DECL_NAME (f
), v
);
3743 v
= visit (TREE_TYPE (f
), state
, v
,
3744 sccstack
, sccstate
, sccstate_obstack
);
3748 v
= iterative_hash_hashval_t (nf
, v
);
3751 /* Record hash for us. */
3754 /* See if we found an SCC. */
3755 if (state
->low
== state
->dfsnum
)
3759 /* Pop off the SCC and set its hash values. */
3762 struct sccs
*cstate
;
3763 x
= VEC_pop (tree
, *sccstack
);
3764 gcc_assert (!pointer_map_contains (type_hash_cache
, x
));
3765 cstate
= (struct sccs
*)*pointer_map_contains (sccstate
, x
);
3766 cstate
->on_sccstack
= false;
3767 slot
= pointer_map_insert (type_hash_cache
, x
);
3768 *slot
= (void *) (size_t) cstate
->hash
;
3773 return iterative_hash_hashval_t (v
, val
);
3777 /* Returns a hash value for P (assumed to be a type). The hash value
3778 is computed using some distinguishing features of the type. Note
3779 that we cannot use pointer hashing here as we may be dealing with
3780 two distinct instances of the same type.
3782 This function should produce the same hash value for two compatible
3783 types according to gimple_types_compatible_p. */
3786 gimple_type_hash (const void *p
)
3788 const_tree t
= (const_tree
) p
;
3789 VEC(tree
, heap
) *sccstack
= NULL
;
3790 struct pointer_map_t
*sccstate
;
3791 struct obstack sccstate_obstack
;
3795 if (type_hash_cache
== NULL
)
3796 type_hash_cache
= pointer_map_create ();
3798 if ((slot
= pointer_map_contains (type_hash_cache
, p
)) != NULL
)
3799 return iterative_hash_hashval_t ((hashval_t
) (size_t) *slot
, 0);
3801 /* Perform a DFS walk and pre-hash all reachable types. */
3803 sccstate
= pointer_map_create ();
3804 gcc_obstack_init (&sccstate_obstack
);
3805 val
= iterative_hash_gimple_type (CONST_CAST_TREE (t
), 0,
3806 &sccstack
, sccstate
, &sccstate_obstack
);
3807 VEC_free (tree
, heap
, sccstack
);
3808 pointer_map_destroy (sccstate
);
3809 obstack_free (&sccstate_obstack
, NULL
);
3815 /* Returns nonzero if P1 and P2 are equal. */
3818 gimple_type_eq (const void *p1
, const void *p2
)
3820 const_tree t1
= (const_tree
) p1
;
3821 const_tree t2
= (const_tree
) p2
;
3822 return gimple_types_compatible_p (CONST_CAST_TREE (t1
), CONST_CAST_TREE (t2
));
3826 /* Register type T in the global type table gimple_types.
3827 If another type T', compatible with T, already existed in
3828 gimple_types then return T', otherwise return T. This is used by
3829 LTO to merge identical types read from different TUs. */
3832 gimple_register_type (tree t
)
3836 gcc_assert (TYPE_P (t
));
3838 /* Always register the main variant first. This is important so we
3839 pick up the non-typedef variants as canonical, otherwise we'll end
3840 up taking typedef ids for structure tags during comparison. */
3841 if (TYPE_MAIN_VARIANT (t
) != t
)
3842 gimple_register_type (TYPE_MAIN_VARIANT (t
));
3844 if (gimple_types
== NULL
)
3845 gimple_types
= htab_create (16381, gimple_type_hash
, gimple_type_eq
, 0);
3847 slot
= htab_find_slot (gimple_types
, t
, INSERT
);
3849 && *(tree
*)slot
!= t
)
3851 tree new_type
= (tree
) *((tree
*) slot
);
3853 /* Do not merge types with different addressability. */
3854 gcc_assert (TREE_ADDRESSABLE (t
) == TREE_ADDRESSABLE (new_type
));
3856 /* If t is not its main variant then make t unreachable from its
3857 main variant list. Otherwise we'd queue up a lot of duplicates
3859 if (t
!= TYPE_MAIN_VARIANT (t
))
3861 tree tem
= TYPE_MAIN_VARIANT (t
);
3862 while (tem
&& TYPE_NEXT_VARIANT (tem
) != t
)
3863 tem
= TYPE_NEXT_VARIANT (tem
);
3865 TYPE_NEXT_VARIANT (tem
) = TYPE_NEXT_VARIANT (t
);
3866 TYPE_NEXT_VARIANT (t
) = NULL_TREE
;
3869 /* If we are a pointer then remove us from the pointer-to or
3870 reference-to chain. Otherwise we'd queue up a lot of duplicates
3872 if (TREE_CODE (t
) == POINTER_TYPE
)
3874 if (TYPE_POINTER_TO (TREE_TYPE (t
)) == t
)
3875 TYPE_POINTER_TO (TREE_TYPE (t
)) = TYPE_NEXT_PTR_TO (t
);
3878 tree tem
= TYPE_POINTER_TO (TREE_TYPE (t
));
3879 while (tem
&& TYPE_NEXT_PTR_TO (tem
) != t
)
3880 tem
= TYPE_NEXT_PTR_TO (tem
);
3882 TYPE_NEXT_PTR_TO (tem
) = TYPE_NEXT_PTR_TO (t
);
3884 TYPE_NEXT_PTR_TO (t
) = NULL_TREE
;
3886 else if (TREE_CODE (t
) == REFERENCE_TYPE
)
3888 if (TYPE_REFERENCE_TO (TREE_TYPE (t
)) == t
)
3889 TYPE_REFERENCE_TO (TREE_TYPE (t
)) = TYPE_NEXT_REF_TO (t
);
3892 tree tem
= TYPE_REFERENCE_TO (TREE_TYPE (t
));
3893 while (tem
&& TYPE_NEXT_REF_TO (tem
) != t
)
3894 tem
= TYPE_NEXT_REF_TO (tem
);
3896 TYPE_NEXT_REF_TO (tem
) = TYPE_NEXT_REF_TO (t
);
3898 TYPE_NEXT_REF_TO (t
) = NULL_TREE
;
3910 /* Show statistics on references to the global type table gimple_types. */
3913 print_gimple_types_stats (void)
3916 fprintf (stderr
, "GIMPLE type table: size %ld, %ld elements, "
3917 "%ld searches, %ld collisions (ratio: %f)\n",
3918 (long) htab_size (gimple_types
),
3919 (long) htab_elements (gimple_types
),
3920 (long) gimple_types
->searches
,
3921 (long) gimple_types
->collisions
,
3922 htab_collisions (gimple_types
));
3924 fprintf (stderr
, "GIMPLE type table is empty\n");
3926 fprintf (stderr
, "GIMPLE type comparison table: size %ld, %ld "
3927 "elements, %ld searches, %ld collisions (ratio: %f)\n",
3928 (long) htab_size (gtc_visited
),
3929 (long) htab_elements (gtc_visited
),
3930 (long) gtc_visited
->searches
,
3931 (long) gtc_visited
->collisions
,
3932 htab_collisions (gtc_visited
));
3934 fprintf (stderr
, "GIMPLE type comparison table is empty\n");
3937 /* Free the gimple type hashtables used for LTO type merging. */
3940 free_gimple_type_tables (void)
3942 /* Last chance to print stats for the tables. */
3943 if (flag_lto_report
)
3944 print_gimple_types_stats ();
3948 htab_delete (gimple_types
);
3949 gimple_types
= NULL
;
3951 if (type_hash_cache
)
3953 pointer_map_destroy (type_hash_cache
);
3954 type_hash_cache
= NULL
;
3958 htab_delete (gtc_visited
);
3959 obstack_free (>c_ob
, NULL
);
3965 /* Return a type the same as TYPE except unsigned or
3966 signed according to UNSIGNEDP. */
3969 gimple_signed_or_unsigned_type (bool unsignedp
, tree type
)
3973 type1
= TYPE_MAIN_VARIANT (type
);
3974 if (type1
== signed_char_type_node
3975 || type1
== char_type_node
3976 || type1
== unsigned_char_type_node
)
3977 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
3978 if (type1
== integer_type_node
|| type1
== unsigned_type_node
)
3979 return unsignedp
? unsigned_type_node
: integer_type_node
;
3980 if (type1
== short_integer_type_node
|| type1
== short_unsigned_type_node
)
3981 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
3982 if (type1
== long_integer_type_node
|| type1
== long_unsigned_type_node
)
3983 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
3984 if (type1
== long_long_integer_type_node
3985 || type1
== long_long_unsigned_type_node
)
3987 ? long_long_unsigned_type_node
3988 : long_long_integer_type_node
;
3989 #if HOST_BITS_PER_WIDE_INT >= 64
3990 if (type1
== intTI_type_node
|| type1
== unsigned_intTI_type_node
)
3991 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
3993 if (type1
== intDI_type_node
|| type1
== unsigned_intDI_type_node
)
3994 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
3995 if (type1
== intSI_type_node
|| type1
== unsigned_intSI_type_node
)
3996 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
3997 if (type1
== intHI_type_node
|| type1
== unsigned_intHI_type_node
)
3998 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
3999 if (type1
== intQI_type_node
|| type1
== unsigned_intQI_type_node
)
4000 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
4002 #define GIMPLE_FIXED_TYPES(NAME) \
4003 if (type1 == short_ ## NAME ## _type_node \
4004 || type1 == unsigned_short_ ## NAME ## _type_node) \
4005 return unsignedp ? unsigned_short_ ## NAME ## _type_node \
4006 : short_ ## NAME ## _type_node; \
4007 if (type1 == NAME ## _type_node \
4008 || type1 == unsigned_ ## NAME ## _type_node) \
4009 return unsignedp ? unsigned_ ## NAME ## _type_node \
4010 : NAME ## _type_node; \
4011 if (type1 == long_ ## NAME ## _type_node \
4012 || type1 == unsigned_long_ ## NAME ## _type_node) \
4013 return unsignedp ? unsigned_long_ ## NAME ## _type_node \
4014 : long_ ## NAME ## _type_node; \
4015 if (type1 == long_long_ ## NAME ## _type_node \
4016 || type1 == unsigned_long_long_ ## NAME ## _type_node) \
4017 return unsignedp ? unsigned_long_long_ ## NAME ## _type_node \
4018 : long_long_ ## NAME ## _type_node;
4020 #define GIMPLE_FIXED_MODE_TYPES(NAME) \
4021 if (type1 == NAME ## _type_node \
4022 || type1 == u ## NAME ## _type_node) \
4023 return unsignedp ? u ## NAME ## _type_node \
4024 : NAME ## _type_node;
4026 #define GIMPLE_FIXED_TYPES_SAT(NAME) \
4027 if (type1 == sat_ ## short_ ## NAME ## _type_node \
4028 || type1 == sat_ ## unsigned_short_ ## NAME ## _type_node) \
4029 return unsignedp ? sat_ ## unsigned_short_ ## NAME ## _type_node \
4030 : sat_ ## short_ ## NAME ## _type_node; \
4031 if (type1 == sat_ ## NAME ## _type_node \
4032 || type1 == sat_ ## unsigned_ ## NAME ## _type_node) \
4033 return unsignedp ? sat_ ## unsigned_ ## NAME ## _type_node \
4034 : sat_ ## NAME ## _type_node; \
4035 if (type1 == sat_ ## long_ ## NAME ## _type_node \
4036 || type1 == sat_ ## unsigned_long_ ## NAME ## _type_node) \
4037 return unsignedp ? sat_ ## unsigned_long_ ## NAME ## _type_node \
4038 : sat_ ## long_ ## NAME ## _type_node; \
4039 if (type1 == sat_ ## long_long_ ## NAME ## _type_node \
4040 || type1 == sat_ ## unsigned_long_long_ ## NAME ## _type_node) \
4041 return unsignedp ? sat_ ## unsigned_long_long_ ## NAME ## _type_node \
4042 : sat_ ## long_long_ ## NAME ## _type_node;
4044 #define GIMPLE_FIXED_MODE_TYPES_SAT(NAME) \
4045 if (type1 == sat_ ## NAME ## _type_node \
4046 || type1 == sat_ ## u ## NAME ## _type_node) \
4047 return unsignedp ? sat_ ## u ## NAME ## _type_node \
4048 : sat_ ## NAME ## _type_node;
4050 GIMPLE_FIXED_TYPES (fract
);
4051 GIMPLE_FIXED_TYPES_SAT (fract
);
4052 GIMPLE_FIXED_TYPES (accum
);
4053 GIMPLE_FIXED_TYPES_SAT (accum
);
4055 GIMPLE_FIXED_MODE_TYPES (qq
);
4056 GIMPLE_FIXED_MODE_TYPES (hq
);
4057 GIMPLE_FIXED_MODE_TYPES (sq
);
4058 GIMPLE_FIXED_MODE_TYPES (dq
);
4059 GIMPLE_FIXED_MODE_TYPES (tq
);
4060 GIMPLE_FIXED_MODE_TYPES_SAT (qq
);
4061 GIMPLE_FIXED_MODE_TYPES_SAT (hq
);
4062 GIMPLE_FIXED_MODE_TYPES_SAT (sq
);
4063 GIMPLE_FIXED_MODE_TYPES_SAT (dq
);
4064 GIMPLE_FIXED_MODE_TYPES_SAT (tq
);
4065 GIMPLE_FIXED_MODE_TYPES (ha
);
4066 GIMPLE_FIXED_MODE_TYPES (sa
);
4067 GIMPLE_FIXED_MODE_TYPES (da
);
4068 GIMPLE_FIXED_MODE_TYPES (ta
);
4069 GIMPLE_FIXED_MODE_TYPES_SAT (ha
);
4070 GIMPLE_FIXED_MODE_TYPES_SAT (sa
);
4071 GIMPLE_FIXED_MODE_TYPES_SAT (da
);
4072 GIMPLE_FIXED_MODE_TYPES_SAT (ta
);
4074 /* For ENUMERAL_TYPEs in C++, must check the mode of the types, not
4075 the precision; they have precision set to match their range, but
4076 may use a wider mode to match an ABI. If we change modes, we may
4077 wind up with bad conversions. For INTEGER_TYPEs in C, must check
4078 the precision as well, so as to yield correct results for
4079 bit-field types. C++ does not have these separate bit-field
4080 types, and producing a signed or unsigned variant of an
4081 ENUMERAL_TYPE may cause other problems as well. */
4082 if (!INTEGRAL_TYPE_P (type
)
4083 || TYPE_UNSIGNED (type
) == unsignedp
)
4086 #define TYPE_OK(node) \
4087 (TYPE_MODE (type) == TYPE_MODE (node) \
4088 && TYPE_PRECISION (type) == TYPE_PRECISION (node))
4089 if (TYPE_OK (signed_char_type_node
))
4090 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
4091 if (TYPE_OK (integer_type_node
))
4092 return unsignedp
? unsigned_type_node
: integer_type_node
;
4093 if (TYPE_OK (short_integer_type_node
))
4094 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
4095 if (TYPE_OK (long_integer_type_node
))
4096 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
4097 if (TYPE_OK (long_long_integer_type_node
))
4099 ? long_long_unsigned_type_node
4100 : long_long_integer_type_node
);
4102 #if HOST_BITS_PER_WIDE_INT >= 64
4103 if (TYPE_OK (intTI_type_node
))
4104 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
4106 if (TYPE_OK (intDI_type_node
))
4107 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
4108 if (TYPE_OK (intSI_type_node
))
4109 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
4110 if (TYPE_OK (intHI_type_node
))
4111 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
4112 if (TYPE_OK (intQI_type_node
))
4113 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
4115 #undef GIMPLE_FIXED_TYPES
4116 #undef GIMPLE_FIXED_MODE_TYPES
4117 #undef GIMPLE_FIXED_TYPES_SAT
4118 #undef GIMPLE_FIXED_MODE_TYPES_SAT
4121 return build_nonstandard_integer_type (TYPE_PRECISION (type
), unsignedp
);
4125 /* Return an unsigned type the same as TYPE in other respects. */
4128 gimple_unsigned_type (tree type
)
4130 return gimple_signed_or_unsigned_type (true, type
);
4134 /* Return a signed type the same as TYPE in other respects. */
4137 gimple_signed_type (tree type
)
4139 return gimple_signed_or_unsigned_type (false, type
);
4143 /* Return the typed-based alias set for T, which may be an expression
4144 or a type. Return -1 if we don't do anything special. */
4147 gimple_get_alias_set (tree t
)
4151 /* Permit type-punning when accessing a union, provided the access
4152 is directly through the union. For example, this code does not
4153 permit taking the address of a union member and then storing
4154 through it. Even the type-punning allowed here is a GCC
4155 extension, albeit a common and useful one; the C standard says
4156 that such accesses have implementation-defined behavior. */
4158 TREE_CODE (u
) == COMPONENT_REF
|| TREE_CODE (u
) == ARRAY_REF
;
4159 u
= TREE_OPERAND (u
, 0))
4160 if (TREE_CODE (u
) == COMPONENT_REF
4161 && TREE_CODE (TREE_TYPE (TREE_OPERAND (u
, 0))) == UNION_TYPE
)
4164 /* That's all the expressions we handle specially. */
4168 /* For convenience, follow the C standard when dealing with
4169 character types. Any object may be accessed via an lvalue that
4170 has character type. */
4171 if (t
== char_type_node
4172 || t
== signed_char_type_node
4173 || t
== unsigned_char_type_node
)
4176 /* Allow aliasing between signed and unsigned variants of the same
4177 type. We treat the signed variant as canonical. */
4178 if (TREE_CODE (t
) == INTEGER_TYPE
&& TYPE_UNSIGNED (t
))
4180 tree t1
= gimple_signed_type (t
);
4182 /* t1 == t can happen for boolean nodes which are always unsigned. */
4184 return get_alias_set (t1
);
4186 else if (POINTER_TYPE_P (t
))
4188 /* From the common C and C++ langhook implementation:
4190 Unfortunately, there is no canonical form of a pointer type.
4191 In particular, if we have `typedef int I', then `int *', and
4192 `I *' are different types. So, we have to pick a canonical
4193 representative. We do this below.
4195 Technically, this approach is actually more conservative that
4196 it needs to be. In particular, `const int *' and `int *'
4197 should be in different alias sets, according to the C and C++
4198 standard, since their types are not the same, and so,
4199 technically, an `int **' and `const int **' cannot point at
4202 But, the standard is wrong. In particular, this code is
4207 const int* const* cipp = ipp;
4208 And, it doesn't make sense for that to be legal unless you
4209 can dereference IPP and CIPP. So, we ignore cv-qualifiers on
4210 the pointed-to types. This issue has been reported to the
4213 /* In addition to the above canonicalization issue with LTO
4214 we should also canonicalize `T (*)[]' to `T *' avoiding
4215 alias issues with pointer-to element types and pointer-to
4218 Likewise we need to deal with the situation of incomplete
4219 pointed-to types and make `*(struct X **)&a' and
4220 `*(struct X {} **)&a' alias. Otherwise we will have to
4221 guarantee that all pointer-to incomplete type variants
4222 will be replaced by pointer-to complete type variants if
4225 With LTO the convenient situation of using `void *' to
4226 access and store any pointer type will also become
4227 more apparent (and `void *' is just another pointer-to
4228 incomplete type). Assigning alias-set zero to `void *'
4229 and all pointer-to incomplete types is a not appealing
4230 solution. Assigning an effective alias-set zero only
4231 affecting pointers might be - by recording proper subset
4232 relationships of all pointer alias-sets.
4234 Pointer-to function types are another grey area which
4235 needs caution. Globbing them all into one alias-set
4236 or the above effective zero set would work. */
4238 /* For now just assign the same alias-set to all pointers.
4239 That's simple and avoids all the above problems. */
4240 if (t
!= ptr_type_node
)
4241 return get_alias_set (ptr_type_node
);
4248 /* Data structure used to count the number of dereferences to PTR
4249 inside an expression. */
4253 unsigned num_stores
;
4257 /* Helper for count_uses_and_derefs. Called by walk_tree to look for
4258 (ALIGN/MISALIGNED_)INDIRECT_REF nodes for the pointer passed in DATA. */
4261 count_ptr_derefs (tree
*tp
, int *walk_subtrees
, void *data
)
4263 struct walk_stmt_info
*wi_p
= (struct walk_stmt_info
*) data
;
4264 struct count_ptr_d
*count_p
= (struct count_ptr_d
*) wi_p
->info
;
4266 /* Do not walk inside ADDR_EXPR nodes. In the expression &ptr->fld,
4267 pointer 'ptr' is *not* dereferenced, it is simply used to compute
4268 the address of 'fld' as 'ptr + offsetof(fld)'. */
4269 if (TREE_CODE (*tp
) == ADDR_EXPR
)
4275 if (INDIRECT_REF_P (*tp
) && TREE_OPERAND (*tp
, 0) == count_p
->ptr
)
4278 count_p
->num_stores
++;
4280 count_p
->num_loads
++;
4286 /* Count the number of direct and indirect uses for pointer PTR in
4287 statement STMT. The number of direct uses is stored in
4288 *NUM_USES_P. Indirect references are counted separately depending
4289 on whether they are store or load operations. The counts are
4290 stored in *NUM_STORES_P and *NUM_LOADS_P. */
4293 count_uses_and_derefs (tree ptr
, gimple stmt
, unsigned *num_uses_p
,
4294 unsigned *num_loads_p
, unsigned *num_stores_p
)
4303 /* Find out the total number of uses of PTR in STMT. */
4304 FOR_EACH_SSA_TREE_OPERAND (use
, stmt
, i
, SSA_OP_USE
)
4308 /* Now count the number of indirect references to PTR. This is
4309 truly awful, but we don't have much choice. There are no parent
4310 pointers inside INDIRECT_REFs, so an expression like
4311 '*x_1 = foo (x_1, *x_1)' needs to be traversed piece by piece to
4312 find all the indirect and direct uses of x_1 inside. The only
4313 shortcut we can take is the fact that GIMPLE only allows
4314 INDIRECT_REFs inside the expressions below. */
4315 if (is_gimple_assign (stmt
)
4316 || gimple_code (stmt
) == GIMPLE_RETURN
4317 || gimple_code (stmt
) == GIMPLE_ASM
4318 || is_gimple_call (stmt
))
4320 struct walk_stmt_info wi
;
4321 struct count_ptr_d count
;
4324 count
.num_stores
= 0;
4325 count
.num_loads
= 0;
4327 memset (&wi
, 0, sizeof (wi
));
4329 walk_gimple_op (stmt
, count_ptr_derefs
, &wi
);
4331 *num_stores_p
= count
.num_stores
;
4332 *num_loads_p
= count
.num_loads
;
4335 gcc_assert (*num_uses_p
>= *num_loads_p
+ *num_stores_p
);
4338 /* From a tree operand OP return the base of a load or store operation
4339 or NULL_TREE if OP is not a load or a store. */
4342 get_base_loadstore (tree op
)
4344 while (handled_component_p (op
))
4345 op
= TREE_OPERAND (op
, 0);
4347 || INDIRECT_REF_P (op
)
4348 || TREE_CODE (op
) == TARGET_MEM_REF
)
4353 /* For the statement STMT call the callbacks VISIT_LOAD, VISIT_STORE and
4354 VISIT_ADDR if non-NULL on loads, store and address-taken operands
4355 passing the STMT, the base of the operand and DATA to it. The base
4356 will be either a decl, an indirect reference (including TARGET_MEM_REF)
4357 or the argument of an address expression.
4358 Returns the results of these callbacks or'ed. */
4361 walk_stmt_load_store_addr_ops (gimple stmt
, void *data
,
4362 bool (*visit_load
)(gimple
, tree
, void *),
4363 bool (*visit_store
)(gimple
, tree
, void *),
4364 bool (*visit_addr
)(gimple
, tree
, void *))
4368 if (gimple_assign_single_p (stmt
))
4373 lhs
= get_base_loadstore (gimple_assign_lhs (stmt
));
4375 ret
|= visit_store (stmt
, lhs
, data
);
4377 rhs
= gimple_assign_rhs1 (stmt
);
4378 while (handled_component_p (rhs
))
4379 rhs
= TREE_OPERAND (rhs
, 0);
4382 if (TREE_CODE (rhs
) == ADDR_EXPR
)
4383 ret
|= visit_addr (stmt
, TREE_OPERAND (rhs
, 0), data
);
4384 else if (TREE_CODE (rhs
) == TARGET_MEM_REF
4385 && TMR_BASE (rhs
) != NULL_TREE
4386 && TREE_CODE (TMR_BASE (rhs
)) == ADDR_EXPR
)
4387 ret
|= visit_addr (stmt
, TREE_OPERAND (TMR_BASE (rhs
), 0), data
);
4388 else if (TREE_CODE (rhs
) == OBJ_TYPE_REF
4389 && TREE_CODE (OBJ_TYPE_REF_OBJECT (rhs
)) == ADDR_EXPR
)
4390 ret
|= visit_addr (stmt
, TREE_OPERAND (OBJ_TYPE_REF_OBJECT (rhs
),
4392 lhs
= gimple_assign_lhs (stmt
);
4393 if (TREE_CODE (lhs
) == TARGET_MEM_REF
4394 && TMR_BASE (lhs
) != NULL_TREE
4395 && TREE_CODE (TMR_BASE (lhs
)) == ADDR_EXPR
)
4396 ret
|= visit_addr (stmt
, TREE_OPERAND (TMR_BASE (lhs
), 0), data
);
4400 rhs
= get_base_loadstore (rhs
);
4402 ret
|= visit_load (stmt
, rhs
, data
);
4406 && (is_gimple_assign (stmt
)
4407 || gimple_code (stmt
) == GIMPLE_COND
))
4409 for (i
= 0; i
< gimple_num_ops (stmt
); ++i
)
4410 if (gimple_op (stmt
, i
)
4411 && TREE_CODE (gimple_op (stmt
, i
)) == ADDR_EXPR
)
4412 ret
|= visit_addr (stmt
, TREE_OPERAND (gimple_op (stmt
, i
), 0), data
);
4414 else if (is_gimple_call (stmt
))
4418 tree lhs
= gimple_call_lhs (stmt
);
4421 lhs
= get_base_loadstore (lhs
);
4423 ret
|= visit_store (stmt
, lhs
, data
);
4426 if (visit_load
|| visit_addr
)
4427 for (i
= 0; i
< gimple_call_num_args (stmt
); ++i
)
4429 tree rhs
= gimple_call_arg (stmt
, i
);
4431 && TREE_CODE (rhs
) == ADDR_EXPR
)
4432 ret
|= visit_addr (stmt
, TREE_OPERAND (rhs
, 0), data
);
4433 else if (visit_load
)
4435 rhs
= get_base_loadstore (rhs
);
4437 ret
|= visit_load (stmt
, rhs
, data
);
4441 && gimple_call_chain (stmt
)
4442 && TREE_CODE (gimple_call_chain (stmt
)) == ADDR_EXPR
)
4443 ret
|= visit_addr (stmt
, TREE_OPERAND (gimple_call_chain (stmt
), 0),
4446 && gimple_call_return_slot_opt_p (stmt
)
4447 && gimple_call_lhs (stmt
) != NULL_TREE
4448 && TREE_ADDRESSABLE (TREE_TYPE (gimple_call_lhs (stmt
))))
4449 ret
|= visit_addr (stmt
, gimple_call_lhs (stmt
), data
);
4451 else if (gimple_code (stmt
) == GIMPLE_ASM
)
4454 const char *constraint
;
4455 const char **oconstraints
;
4456 bool allows_mem
, allows_reg
, is_inout
;
4457 noutputs
= gimple_asm_noutputs (stmt
);
4458 oconstraints
= XALLOCAVEC (const char *, noutputs
);
4459 if (visit_store
|| visit_addr
)
4460 for (i
= 0; i
< gimple_asm_noutputs (stmt
); ++i
)
4462 tree link
= gimple_asm_output_op (stmt
, i
);
4463 tree op
= get_base_loadstore (TREE_VALUE (link
));
4464 if (op
&& visit_store
)
4465 ret
|= visit_store (stmt
, op
, data
);
4468 constraint
= TREE_STRING_POINTER
4469 (TREE_VALUE (TREE_PURPOSE (link
)));
4470 oconstraints
[i
] = constraint
;
4471 parse_output_constraint (&constraint
, i
, 0, 0, &allows_mem
,
4472 &allows_reg
, &is_inout
);
4473 if (op
&& !allows_reg
&& allows_mem
)
4474 ret
|= visit_addr (stmt
, op
, data
);
4477 if (visit_load
|| visit_addr
)
4478 for (i
= 0; i
< gimple_asm_ninputs (stmt
); ++i
)
4480 tree link
= gimple_asm_input_op (stmt
, i
);
4481 tree op
= TREE_VALUE (link
);
4483 && TREE_CODE (op
) == ADDR_EXPR
)
4484 ret
|= visit_addr (stmt
, TREE_OPERAND (op
, 0), data
);
4485 else if (visit_load
|| visit_addr
)
4487 op
= get_base_loadstore (op
);
4491 ret
|= visit_load (stmt
, op
, data
);
4494 constraint
= TREE_STRING_POINTER
4495 (TREE_VALUE (TREE_PURPOSE (link
)));
4496 parse_input_constraint (&constraint
, 0, 0, noutputs
,
4498 &allows_mem
, &allows_reg
);
4499 if (!allows_reg
&& allows_mem
)
4500 ret
|= visit_addr (stmt
, op
, data
);
4506 else if (gimple_code (stmt
) == GIMPLE_RETURN
)
4508 tree op
= gimple_return_retval (stmt
);
4512 && TREE_CODE (op
) == ADDR_EXPR
)
4513 ret
|= visit_addr (stmt
, TREE_OPERAND (op
, 0), data
);
4514 else if (visit_load
)
4516 op
= get_base_loadstore (op
);
4518 ret
|= visit_load (stmt
, op
, data
);
4523 && gimple_code (stmt
) == GIMPLE_PHI
)
4525 for (i
= 0; i
< gimple_phi_num_args (stmt
); ++i
)
4527 tree op
= PHI_ARG_DEF (stmt
, i
);
4528 if (TREE_CODE (op
) == ADDR_EXPR
)
4529 ret
|= visit_addr (stmt
, TREE_OPERAND (op
, 0), data
);
4536 /* Like walk_stmt_load_store_addr_ops but with NULL visit_addr. IPA-CP
4537 should make a faster clone for this case. */
4540 walk_stmt_load_store_ops (gimple stmt
, void *data
,
4541 bool (*visit_load
)(gimple
, tree
, void *),
4542 bool (*visit_store
)(gimple
, tree
, void *))
4544 return walk_stmt_load_store_addr_ops (stmt
, data
,
4545 visit_load
, visit_store
, NULL
);
4548 /* Helper for gimple_ior_addresses_taken_1. */
4551 gimple_ior_addresses_taken_1 (gimple stmt ATTRIBUTE_UNUSED
,
4552 tree addr
, void *data
)
4554 bitmap addresses_taken
= (bitmap
)data
;
4555 addr
= get_base_address (addr
);
4559 bitmap_set_bit (addresses_taken
, DECL_UID (addr
));
4565 /* Set the bit for the uid of all decls that have their address taken
4566 in STMT in the ADDRESSES_TAKEN bitmap. Returns true if there
4567 were any in this stmt. */
4570 gimple_ior_addresses_taken (bitmap addresses_taken
, gimple stmt
)
4572 return walk_stmt_load_store_addr_ops (stmt
, addresses_taken
, NULL
, NULL
,
4573 gimple_ior_addresses_taken_1
);
4577 /* Return a printable name for symbol DECL. */
4580 gimple_decl_printable_name (tree decl
, int verbosity
)
4582 if (!DECL_NAME (decl
))
4585 if (DECL_ASSEMBLER_NAME_SET_P (decl
))
4587 const char *str
, *mangled_str
;
4588 int dmgl_opts
= DMGL_NO_OPTS
;
4592 dmgl_opts
= DMGL_VERBOSE
4596 if (TREE_CODE (decl
) == FUNCTION_DECL
)
4597 dmgl_opts
|= DMGL_PARAMS
;
4600 mangled_str
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
4601 str
= cplus_demangle_v3 (mangled_str
, dmgl_opts
);
4602 return (str
) ? str
: mangled_str
;
4605 return IDENTIFIER_POINTER (DECL_NAME (decl
));
4609 /* Fold a OBJ_TYPE_REF expression to the address of a function.
4610 KNOWN_TYPE carries the true type of OBJ_TYPE_REF_OBJECT(REF). Adapted
4611 from cp_fold_obj_type_ref, but it tolerates types with no binfo
4615 gimple_fold_obj_type_ref (tree ref
, tree known_type
)
4617 HOST_WIDE_INT index
;
4622 if (TYPE_BINFO (known_type
) == NULL_TREE
)
4625 v
= BINFO_VIRTUALS (TYPE_BINFO (known_type
));
4626 index
= tree_low_cst (OBJ_TYPE_REF_TOKEN (ref
), 1);
4630 i
+= (TARGET_VTABLE_USES_DESCRIPTORS
4631 ? TARGET_VTABLE_USES_DESCRIPTORS
: 1);
4635 fndecl
= TREE_VALUE (v
);
4637 #ifdef ENABLE_CHECKING
4638 gcc_assert (tree_int_cst_equal (OBJ_TYPE_REF_TOKEN (ref
),
4639 DECL_VINDEX (fndecl
)));
4642 cgraph_node (fndecl
)->local
.vtable_method
= true;
4644 return build_fold_addr_expr (fndecl
);
4647 #include "gt-gimple.h"