1 /* Gimple decl, type, and expression support functions.
3 Copyright (C) 2007-2015 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 "fold-const.h"
31 #include "hard-reg-set.h"
33 #include "basic-block.h"
34 #include "tree-ssa-alias.h"
35 #include "internal-fn.h"
37 #include "gimple-expr.h"
39 #include "stringpool.h"
41 #include "stor-layout.h"
43 #include "gimple-ssa.h"
45 /* ----- Type related ----- */
47 /* Return true if the conversion from INNER_TYPE to OUTER_TYPE is a
48 useless type conversion, otherwise return false.
50 This function implicitly defines the middle-end type system. With
51 the notion of 'a < b' meaning that useless_type_conversion_p (a, b)
52 holds and 'a > b' meaning that useless_type_conversion_p (b, a) holds,
53 the following invariants shall be fulfilled:
55 1) useless_type_conversion_p is transitive.
56 If a < b and b < c then a < c.
58 2) useless_type_conversion_p is not symmetric.
59 From a < b does not follow a > b.
61 3) Types define the available set of operations applicable to values.
62 A type conversion is useless if the operations for the target type
63 is a subset of the operations for the source type. For example
64 casts to void* are useless, casts from void* are not (void* can't
65 be dereferenced or offsetted, but copied, hence its set of operations
66 is a strict subset of that of all other data pointer types). Casts
67 to const T* are useless (can't be written to), casts from const T*
71 useless_type_conversion_p (tree outer_type
, tree inner_type
)
73 /* Do the following before stripping toplevel qualifiers. */
74 if (POINTER_TYPE_P (inner_type
)
75 && POINTER_TYPE_P (outer_type
))
77 /* Do not lose casts between pointers to different address spaces. */
78 if (TYPE_ADDR_SPACE (TREE_TYPE (outer_type
))
79 != TYPE_ADDR_SPACE (TREE_TYPE (inner_type
)))
81 /* Do not lose casts to function pointer types. */
82 if ((TREE_CODE (TREE_TYPE (outer_type
)) == FUNCTION_TYPE
83 || TREE_CODE (TREE_TYPE (outer_type
)) == METHOD_TYPE
)
84 && !(TREE_CODE (TREE_TYPE (inner_type
)) == FUNCTION_TYPE
85 || TREE_CODE (TREE_TYPE (inner_type
)) == METHOD_TYPE
))
89 /* From now on qualifiers on value types do not matter. */
90 inner_type
= TYPE_MAIN_VARIANT (inner_type
);
91 outer_type
= TYPE_MAIN_VARIANT (outer_type
);
93 if (inner_type
== outer_type
)
96 /* If we know the canonical types, compare them. */
97 if (TYPE_CANONICAL (inner_type
)
98 && TYPE_CANONICAL (inner_type
) == TYPE_CANONICAL (outer_type
))
101 /* Changes in machine mode are never useless conversions unless we
102 deal with aggregate types in which case we defer to later checks. */
103 if (TYPE_MODE (inner_type
) != TYPE_MODE (outer_type
)
104 && !AGGREGATE_TYPE_P (inner_type
))
107 /* If both the inner and outer types are integral types, then the
108 conversion is not necessary if they have the same mode and
109 signedness and precision, and both or neither are boolean. */
110 if (INTEGRAL_TYPE_P (inner_type
)
111 && INTEGRAL_TYPE_P (outer_type
))
113 /* Preserve changes in signedness or precision. */
114 if (TYPE_UNSIGNED (inner_type
) != TYPE_UNSIGNED (outer_type
)
115 || TYPE_PRECISION (inner_type
) != TYPE_PRECISION (outer_type
))
118 /* Preserve conversions to/from BOOLEAN_TYPE if types are not
120 if (((TREE_CODE (inner_type
) == BOOLEAN_TYPE
)
121 != (TREE_CODE (outer_type
) == BOOLEAN_TYPE
))
122 && TYPE_PRECISION (outer_type
) != 1)
125 /* We don't need to preserve changes in the types minimum or
126 maximum value in general as these do not generate code
127 unless the types precisions are different. */
131 /* Scalar floating point types with the same mode are compatible. */
132 else if (SCALAR_FLOAT_TYPE_P (inner_type
)
133 && SCALAR_FLOAT_TYPE_P (outer_type
))
136 /* Fixed point types with the same mode are compatible. */
137 else if (FIXED_POINT_TYPE_P (inner_type
)
138 && FIXED_POINT_TYPE_P (outer_type
))
141 /* We need to take special care recursing to pointed-to types. */
142 else if (POINTER_TYPE_P (inner_type
)
143 && POINTER_TYPE_P (outer_type
))
145 /* We do not care for const qualification of the pointed-to types
146 as const qualification has no semantic value to the middle-end. */
148 /* Otherwise pointers/references are equivalent. */
152 /* Recurse for complex types. */
153 else if (TREE_CODE (inner_type
) == COMPLEX_TYPE
154 && TREE_CODE (outer_type
) == COMPLEX_TYPE
)
155 return useless_type_conversion_p (TREE_TYPE (outer_type
),
156 TREE_TYPE (inner_type
));
158 /* Recurse for vector types with the same number of subparts. */
159 else if (TREE_CODE (inner_type
) == VECTOR_TYPE
160 && TREE_CODE (outer_type
) == VECTOR_TYPE
161 && TYPE_PRECISION (inner_type
) == TYPE_PRECISION (outer_type
))
162 return useless_type_conversion_p (TREE_TYPE (outer_type
),
163 TREE_TYPE (inner_type
));
165 else if (TREE_CODE (inner_type
) == ARRAY_TYPE
166 && TREE_CODE (outer_type
) == ARRAY_TYPE
)
168 /* Preserve string attributes. */
169 if (TYPE_STRING_FLAG (inner_type
) != TYPE_STRING_FLAG (outer_type
))
172 /* Conversions from array types with unknown extent to
173 array types with known extent are not useless. */
174 if (!TYPE_DOMAIN (inner_type
)
175 && TYPE_DOMAIN (outer_type
))
178 /* Nor are conversions from array types with non-constant size to
179 array types with constant size or to different size. */
180 if (TYPE_SIZE (outer_type
)
181 && TREE_CODE (TYPE_SIZE (outer_type
)) == INTEGER_CST
182 && (!TYPE_SIZE (inner_type
)
183 || TREE_CODE (TYPE_SIZE (inner_type
)) != INTEGER_CST
184 || !tree_int_cst_equal (TYPE_SIZE (outer_type
),
185 TYPE_SIZE (inner_type
))))
188 /* Check conversions between arrays with partially known extents.
189 If the array min/max values are constant they have to match.
190 Otherwise allow conversions to unknown and variable extents.
191 In particular this declares conversions that may change the
192 mode to BLKmode as useless. */
193 if (TYPE_DOMAIN (inner_type
)
194 && TYPE_DOMAIN (outer_type
)
195 && TYPE_DOMAIN (inner_type
) != TYPE_DOMAIN (outer_type
))
197 tree inner_min
= TYPE_MIN_VALUE (TYPE_DOMAIN (inner_type
));
198 tree outer_min
= TYPE_MIN_VALUE (TYPE_DOMAIN (outer_type
));
199 tree inner_max
= TYPE_MAX_VALUE (TYPE_DOMAIN (inner_type
));
200 tree outer_max
= TYPE_MAX_VALUE (TYPE_DOMAIN (outer_type
));
202 /* After gimplification a variable min/max value carries no
203 additional information compared to a NULL value. All that
204 matters has been lowered to be part of the IL. */
205 if (inner_min
&& TREE_CODE (inner_min
) != INTEGER_CST
)
206 inner_min
= NULL_TREE
;
207 if (outer_min
&& TREE_CODE (outer_min
) != INTEGER_CST
)
208 outer_min
= NULL_TREE
;
209 if (inner_max
&& TREE_CODE (inner_max
) != INTEGER_CST
)
210 inner_max
= NULL_TREE
;
211 if (outer_max
&& TREE_CODE (outer_max
) != INTEGER_CST
)
212 outer_max
= NULL_TREE
;
214 /* Conversions NULL / variable <- cst are useless, but not
215 the other way around. */
218 || !tree_int_cst_equal (inner_min
, outer_min
)))
222 || !tree_int_cst_equal (inner_max
, outer_max
)))
226 /* Recurse on the element check. */
227 return useless_type_conversion_p (TREE_TYPE (outer_type
),
228 TREE_TYPE (inner_type
));
231 else if ((TREE_CODE (inner_type
) == FUNCTION_TYPE
232 || TREE_CODE (inner_type
) == METHOD_TYPE
)
233 && TREE_CODE (inner_type
) == TREE_CODE (outer_type
))
235 tree outer_parm
, inner_parm
;
237 /* If the return types are not compatible bail out. */
238 if (!useless_type_conversion_p (TREE_TYPE (outer_type
),
239 TREE_TYPE (inner_type
)))
242 /* Method types should belong to a compatible base class. */
243 if (TREE_CODE (inner_type
) == METHOD_TYPE
244 && !useless_type_conversion_p (TYPE_METHOD_BASETYPE (outer_type
),
245 TYPE_METHOD_BASETYPE (inner_type
)))
248 /* A conversion to an unprototyped argument list is ok. */
249 if (!prototype_p (outer_type
))
252 /* If the unqualified argument types are compatible the conversion
254 if (TYPE_ARG_TYPES (outer_type
) == TYPE_ARG_TYPES (inner_type
))
257 for (outer_parm
= TYPE_ARG_TYPES (outer_type
),
258 inner_parm
= TYPE_ARG_TYPES (inner_type
);
259 outer_parm
&& inner_parm
;
260 outer_parm
= TREE_CHAIN (outer_parm
),
261 inner_parm
= TREE_CHAIN (inner_parm
))
262 if (!useless_type_conversion_p
263 (TYPE_MAIN_VARIANT (TREE_VALUE (outer_parm
)),
264 TYPE_MAIN_VARIANT (TREE_VALUE (inner_parm
))))
267 /* If there is a mismatch in the number of arguments the functions
268 are not compatible. */
269 if (outer_parm
|| inner_parm
)
272 /* Defer to the target if necessary. */
273 if (TYPE_ATTRIBUTES (inner_type
) || TYPE_ATTRIBUTES (outer_type
))
274 return comp_type_attributes (outer_type
, inner_type
) != 0;
279 /* For aggregates we rely on TYPE_CANONICAL exclusively and require
280 explicit conversions for types involving to be structurally
282 else if (AGGREGATE_TYPE_P (inner_type
)
283 && TREE_CODE (inner_type
) == TREE_CODE (outer_type
))
290 /* ----- Decl related ----- */
292 /* Set sequence SEQ to be the GIMPLE body for function FN. */
295 gimple_set_body (tree fndecl
, gimple_seq seq
)
297 struct function
*fn
= DECL_STRUCT_FUNCTION (fndecl
);
300 /* If FNDECL still does not have a function structure associated
301 with it, then it does not make sense for it to receive a
303 gcc_assert (seq
== NULL
);
306 fn
->gimple_body
= seq
;
310 /* Return the body of GIMPLE statements for function FN. After the
311 CFG pass, the function body doesn't exist anymore because it has
312 been split up into basic blocks. In this case, it returns
316 gimple_body (tree fndecl
)
318 struct function
*fn
= DECL_STRUCT_FUNCTION (fndecl
);
319 return fn
? fn
->gimple_body
: NULL
;
322 /* Return true when FNDECL has Gimple body either in unlowered
325 gimple_has_body_p (tree fndecl
)
327 struct function
*fn
= DECL_STRUCT_FUNCTION (fndecl
);
328 return (gimple_body (fndecl
) || (fn
&& fn
->cfg
));
331 /* Return a printable name for symbol DECL. */
334 gimple_decl_printable_name (tree decl
, int verbosity
)
336 if (!DECL_NAME (decl
))
339 if (DECL_ASSEMBLER_NAME_SET_P (decl
))
341 const char *str
, *mangled_str
;
342 int dmgl_opts
= DMGL_NO_OPTS
;
346 dmgl_opts
= DMGL_VERBOSE
350 if (TREE_CODE (decl
) == FUNCTION_DECL
)
351 dmgl_opts
|= DMGL_PARAMS
;
354 mangled_str
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
355 str
= cplus_demangle_v3 (mangled_str
, dmgl_opts
);
356 return (str
) ? str
: mangled_str
;
359 return IDENTIFIER_POINTER (DECL_NAME (decl
));
363 /* Create a new VAR_DECL and copy information from VAR to it. */
366 copy_var_decl (tree var
, tree name
, tree type
)
368 tree copy
= build_decl (DECL_SOURCE_LOCATION (var
), VAR_DECL
, name
, type
);
370 TREE_ADDRESSABLE (copy
) = TREE_ADDRESSABLE (var
);
371 TREE_THIS_VOLATILE (copy
) = TREE_THIS_VOLATILE (var
);
372 DECL_GIMPLE_REG_P (copy
) = DECL_GIMPLE_REG_P (var
);
373 DECL_ARTIFICIAL (copy
) = DECL_ARTIFICIAL (var
);
374 DECL_IGNORED_P (copy
) = DECL_IGNORED_P (var
);
375 DECL_CONTEXT (copy
) = DECL_CONTEXT (var
);
376 TREE_NO_WARNING (copy
) = TREE_NO_WARNING (var
);
377 TREE_USED (copy
) = 1;
378 DECL_SEEN_IN_BIND_EXPR_P (copy
) = 1;
379 DECL_ATTRIBUTES (copy
) = DECL_ATTRIBUTES (var
);
384 /* Given SSA_NAMEs NAME1 and NAME2, return true if they are candidates for
385 coalescing together, false otherwise.
387 This must stay consistent with var_map_base_init in tree-ssa-live.c. */
390 gimple_can_coalesce_p (tree name1
, tree name2
)
392 /* First check the SSA_NAME's associated DECL. We only want to
393 coalesce if they have the same DECL or both have no associated DECL. */
394 tree var1
= SSA_NAME_VAR (name1
);
395 tree var2
= SSA_NAME_VAR (name2
);
396 var1
= (var1
&& (!VAR_P (var1
) || !DECL_IGNORED_P (var1
))) ? var1
: NULL_TREE
;
397 var2
= (var2
&& (!VAR_P (var2
) || !DECL_IGNORED_P (var2
))) ? var2
: NULL_TREE
;
401 /* Now check the types. If the types are the same, then we should
402 try to coalesce V1 and V2. */
403 tree t1
= TREE_TYPE (name1
);
404 tree t2
= TREE_TYPE (name2
);
408 /* If the types are not the same, check for a canonical type match. This
409 (for example) allows coalescing when the types are fundamentally the
410 same, but just have different names.
412 Note pointer types with different address spaces may have the same
413 canonical type. Those are rejected for coalescing by the
414 types_compatible_p check. */
415 if (TYPE_CANONICAL (t1
)
416 && TYPE_CANONICAL (t1
) == TYPE_CANONICAL (t2
)
417 && types_compatible_p (t1
, t2
))
423 /* Strip off a legitimate source ending from the input string NAME of
424 length LEN. Rather than having to know the names used by all of
425 our front ends, we strip off an ending of a period followed by
426 up to five characters. (Java uses ".class".) */
429 remove_suffix (char *name
, int len
)
433 for (i
= 2; i
< 8 && len
> i
; i
++)
435 if (name
[len
- i
] == '.')
437 name
[len
- i
] = '\0';
443 /* Create a new temporary name with PREFIX. Return an identifier. */
445 static GTY(()) unsigned int tmp_var_id_num
;
448 create_tmp_var_name (const char *prefix
)
454 char *preftmp
= ASTRDUP (prefix
);
456 remove_suffix (preftmp
, strlen (preftmp
));
457 clean_symbol_name (preftmp
);
462 ASM_FORMAT_PRIVATE_NAME (tmp_name
, prefix
? prefix
: "T", tmp_var_id_num
++);
463 return get_identifier (tmp_name
);
466 /* Create a new temporary variable declaration of type TYPE.
467 Do NOT push it into the current binding. */
470 create_tmp_var_raw (tree type
, const char *prefix
)
474 tmp_var
= build_decl (input_location
,
475 VAR_DECL
, prefix
? create_tmp_var_name (prefix
) : NULL
,
478 /* The variable was declared by the compiler. */
479 DECL_ARTIFICIAL (tmp_var
) = 1;
480 /* And we don't want debug info for it. */
481 DECL_IGNORED_P (tmp_var
) = 1;
483 /* Make the variable writable. */
484 TREE_READONLY (tmp_var
) = 0;
486 DECL_EXTERNAL (tmp_var
) = 0;
487 TREE_STATIC (tmp_var
) = 0;
488 TREE_USED (tmp_var
) = 1;
493 /* Create a new temporary variable declaration of type TYPE. DO push the
494 variable into the current binding. Further, assume that this is called
495 only from gimplification or optimization, at which point the creation of
496 certain types are bugs. */
499 create_tmp_var (tree type
, const char *prefix
)
503 /* We don't allow types that are addressable (meaning we can't make copies),
504 or incomplete. We also used to reject every variable size objects here,
505 but now support those for which a constant upper bound can be obtained.
506 The processing for variable sizes is performed in gimple_add_tmp_var,
507 point at which it really matters and possibly reached via paths not going
508 through this function, e.g. after direct calls to create_tmp_var_raw. */
509 gcc_assert (!TREE_ADDRESSABLE (type
) && COMPLETE_TYPE_P (type
));
511 tmp_var
= create_tmp_var_raw (type
, prefix
);
512 gimple_add_tmp_var (tmp_var
);
516 /* Create a new temporary variable declaration of type TYPE by calling
517 create_tmp_var and if TYPE is a vector or a complex number, mark the new
518 temporary as gimple register. */
521 create_tmp_reg (tree type
, const char *prefix
)
525 tmp
= create_tmp_var (type
, prefix
);
526 if (TREE_CODE (type
) == COMPLEX_TYPE
527 || TREE_CODE (type
) == VECTOR_TYPE
)
528 DECL_GIMPLE_REG_P (tmp
) = 1;
533 /* Create a new temporary variable declaration of type TYPE by calling
534 create_tmp_var and if TYPE is a vector or a complex number, mark the new
535 temporary as gimple register. */
538 create_tmp_reg_fn (struct function
*fn
, tree type
, const char *prefix
)
542 tmp
= create_tmp_var_raw (type
, prefix
);
543 gimple_add_tmp_var_fn (fn
, tmp
);
544 if (TREE_CODE (type
) == COMPLEX_TYPE
545 || TREE_CODE (type
) == VECTOR_TYPE
)
546 DECL_GIMPLE_REG_P (tmp
) = 1;
552 /* ----- Expression related ----- */
554 /* Extract the operands and code for expression EXPR into *SUBCODE_P,
555 *OP1_P, *OP2_P and *OP3_P respectively. */
558 extract_ops_from_tree_1 (tree expr
, enum tree_code
*subcode_p
, tree
*op1_p
,
559 tree
*op2_p
, tree
*op3_p
)
561 enum gimple_rhs_class grhs_class
;
563 *subcode_p
= TREE_CODE (expr
);
564 grhs_class
= get_gimple_rhs_class (*subcode_p
);
566 if (grhs_class
== GIMPLE_TERNARY_RHS
)
568 *op1_p
= TREE_OPERAND (expr
, 0);
569 *op2_p
= TREE_OPERAND (expr
, 1);
570 *op3_p
= TREE_OPERAND (expr
, 2);
572 else if (grhs_class
== GIMPLE_BINARY_RHS
)
574 *op1_p
= TREE_OPERAND (expr
, 0);
575 *op2_p
= TREE_OPERAND (expr
, 1);
578 else if (grhs_class
== GIMPLE_UNARY_RHS
)
580 *op1_p
= TREE_OPERAND (expr
, 0);
584 else if (grhs_class
== GIMPLE_SINGLE_RHS
)
594 /* Extract operands for a GIMPLE_COND statement out of COND_EXPR tree COND. */
597 gimple_cond_get_ops_from_tree (tree cond
, enum tree_code
*code_p
,
598 tree
*lhs_p
, tree
*rhs_p
)
600 gcc_assert (COMPARISON_CLASS_P (cond
)
601 || TREE_CODE (cond
) == TRUTH_NOT_EXPR
602 || is_gimple_min_invariant (cond
)
603 || SSA_VAR_P (cond
));
605 extract_ops_from_tree (cond
, code_p
, lhs_p
, rhs_p
);
607 /* Canonicalize conditionals of the form 'if (!VAL)'. */
608 if (*code_p
== TRUTH_NOT_EXPR
)
611 gcc_assert (*lhs_p
&& *rhs_p
== NULL_TREE
);
612 *rhs_p
= build_zero_cst (TREE_TYPE (*lhs_p
));
614 /* Canonicalize conditionals of the form 'if (VAL)' */
615 else if (TREE_CODE_CLASS (*code_p
) != tcc_comparison
)
618 gcc_assert (*lhs_p
&& *rhs_p
== NULL_TREE
);
619 *rhs_p
= build_zero_cst (TREE_TYPE (*lhs_p
));
623 /* Return true if T is a valid LHS for a GIMPLE assignment expression. */
626 is_gimple_lvalue (tree t
)
628 return (is_gimple_addressable (t
)
629 || TREE_CODE (t
) == WITH_SIZE_EXPR
630 /* These are complex lvalues, but don't have addresses, so they
632 || TREE_CODE (t
) == BIT_FIELD_REF
);
635 /* Return true if T is a GIMPLE condition. */
638 is_gimple_condexpr (tree t
)
640 return (is_gimple_val (t
) || (COMPARISON_CLASS_P (t
)
641 && !tree_could_throw_p (t
)
642 && is_gimple_val (TREE_OPERAND (t
, 0))
643 && is_gimple_val (TREE_OPERAND (t
, 1))));
646 /* Return true if T is a gimple address. */
649 is_gimple_address (const_tree t
)
653 if (TREE_CODE (t
) != ADDR_EXPR
)
656 op
= TREE_OPERAND (t
, 0);
657 while (handled_component_p (op
))
659 if ((TREE_CODE (op
) == ARRAY_REF
660 || TREE_CODE (op
) == ARRAY_RANGE_REF
)
661 && !is_gimple_val (TREE_OPERAND (op
, 1)))
664 op
= TREE_OPERAND (op
, 0);
667 if (CONSTANT_CLASS_P (op
) || TREE_CODE (op
) == MEM_REF
)
670 switch (TREE_CODE (op
))
685 /* Return true if T is a gimple invariant address. */
688 is_gimple_invariant_address (const_tree t
)
692 if (TREE_CODE (t
) != ADDR_EXPR
)
695 op
= strip_invariant_refs (TREE_OPERAND (t
, 0));
699 if (TREE_CODE (op
) == MEM_REF
)
701 const_tree op0
= TREE_OPERAND (op
, 0);
702 return (TREE_CODE (op0
) == ADDR_EXPR
703 && (CONSTANT_CLASS_P (TREE_OPERAND (op0
, 0))
704 || decl_address_invariant_p (TREE_OPERAND (op0
, 0))));
707 return CONSTANT_CLASS_P (op
) || decl_address_invariant_p (op
);
710 /* Return true if T is a gimple invariant address at IPA level
711 (so addresses of variables on stack are not allowed). */
714 is_gimple_ip_invariant_address (const_tree t
)
718 if (TREE_CODE (t
) != ADDR_EXPR
)
721 op
= strip_invariant_refs (TREE_OPERAND (t
, 0));
725 if (TREE_CODE (op
) == MEM_REF
)
727 const_tree op0
= TREE_OPERAND (op
, 0);
728 return (TREE_CODE (op0
) == ADDR_EXPR
729 && (CONSTANT_CLASS_P (TREE_OPERAND (op0
, 0))
730 || decl_address_ip_invariant_p (TREE_OPERAND (op0
, 0))));
733 return CONSTANT_CLASS_P (op
) || decl_address_ip_invariant_p (op
);
736 /* Return true if T is a GIMPLE minimal invariant. It's a restricted
737 form of function invariant. */
740 is_gimple_min_invariant (const_tree t
)
742 if (TREE_CODE (t
) == ADDR_EXPR
)
743 return is_gimple_invariant_address (t
);
745 return is_gimple_constant (t
);
748 /* Return true if T is a GIMPLE interprocedural invariant. It's a restricted
749 form of gimple minimal invariant. */
752 is_gimple_ip_invariant (const_tree t
)
754 if (TREE_CODE (t
) == ADDR_EXPR
)
755 return is_gimple_ip_invariant_address (t
);
757 return is_gimple_constant (t
);
760 /* Return true if T is a non-aggregate register variable. */
763 is_gimple_reg (tree t
)
765 if (virtual_operand_p (t
))
768 if (TREE_CODE (t
) == SSA_NAME
)
771 if (!is_gimple_variable (t
))
774 if (!is_gimple_reg_type (TREE_TYPE (t
)))
777 /* A volatile decl is not acceptable because we can't reuse it as
778 needed. We need to copy it into a temp first. */
779 if (TREE_THIS_VOLATILE (t
))
782 /* We define "registers" as things that can be renamed as needed,
783 which with our infrastructure does not apply to memory. */
784 if (needs_to_live_in_memory (t
))
787 /* Hard register variables are an interesting case. For those that
788 are call-clobbered, we don't know where all the calls are, since
789 we don't (want to) take into account which operations will turn
790 into libcalls at the rtl level. For those that are call-saved,
791 we don't currently model the fact that calls may in fact change
792 global hard registers, nor do we examine ASM_CLOBBERS at the tree
793 level, and so miss variable changes that might imply. All around,
794 it seems safest to not do too much optimization with these at the
795 tree level at all. We'll have to rely on the rtl optimizers to
796 clean this up, as there we've got all the appropriate bits exposed. */
797 if (TREE_CODE (t
) == VAR_DECL
&& DECL_HARD_REGISTER (t
))
800 /* Complex and vector values must have been put into SSA-like form.
801 That is, no assignments to the individual components. */
802 if (TREE_CODE (TREE_TYPE (t
)) == COMPLEX_TYPE
803 || TREE_CODE (TREE_TYPE (t
)) == VECTOR_TYPE
)
804 return DECL_GIMPLE_REG_P (t
);
810 /* Return true if T is a GIMPLE rvalue, i.e. an identifier or a constant. */
813 is_gimple_val (tree t
)
815 /* Make loads from volatiles and memory vars explicit. */
816 if (is_gimple_variable (t
)
817 && is_gimple_reg_type (TREE_TYPE (t
))
818 && !is_gimple_reg (t
))
821 return (is_gimple_variable (t
) || is_gimple_min_invariant (t
));
824 /* Similarly, but accept hard registers as inputs to asm statements. */
827 is_gimple_asm_val (tree t
)
829 if (TREE_CODE (t
) == VAR_DECL
&& DECL_HARD_REGISTER (t
))
832 return is_gimple_val (t
);
835 /* Return true if T is a GIMPLE minimal lvalue. */
838 is_gimple_min_lval (tree t
)
840 if (!(t
= CONST_CAST_TREE (strip_invariant_refs (t
))))
842 return (is_gimple_id (t
) || TREE_CODE (t
) == MEM_REF
);
845 /* Return true if T is a valid function operand of a CALL_EXPR. */
848 is_gimple_call_addr (tree t
)
850 return (TREE_CODE (t
) == OBJ_TYPE_REF
|| is_gimple_val (t
));
853 /* Return true if T is a valid address operand of a MEM_REF. */
856 is_gimple_mem_ref_addr (tree t
)
858 return (is_gimple_reg (t
)
859 || TREE_CODE (t
) == INTEGER_CST
860 || (TREE_CODE (t
) == ADDR_EXPR
861 && (CONSTANT_CLASS_P (TREE_OPERAND (t
, 0))
862 || decl_address_invariant_p (TREE_OPERAND (t
, 0)))));
865 /* Mark X addressable. Unlike the langhook we expect X to be in gimple
866 form and we don't do any syntax checking. */
869 mark_addressable (tree x
)
871 while (handled_component_p (x
))
872 x
= TREE_OPERAND (x
, 0);
873 if (TREE_CODE (x
) == MEM_REF
874 && TREE_CODE (TREE_OPERAND (x
, 0)) == ADDR_EXPR
)
875 x
= TREE_OPERAND (TREE_OPERAND (x
, 0), 0);
876 if (TREE_CODE (x
) != VAR_DECL
877 && TREE_CODE (x
) != PARM_DECL
878 && TREE_CODE (x
) != RESULT_DECL
)
880 TREE_ADDRESSABLE (x
) = 1;
882 /* Also mark the artificial SSA_NAME that points to the partition of X. */
883 if (TREE_CODE (x
) == VAR_DECL
884 && !DECL_EXTERNAL (x
)
886 && cfun
->gimple_df
!= NULL
887 && cfun
->gimple_df
->decls_to_pointers
!= NULL
)
889 tree
*namep
= cfun
->gimple_df
->decls_to_pointers
->get (x
);
891 TREE_ADDRESSABLE (*namep
) = 1;
895 /* Returns true iff T is a valid RHS for an assignment to a renamed
896 user -- or front-end generated artificial -- variable. */
899 is_gimple_reg_rhs (tree t
)
901 return get_gimple_rhs_class (TREE_CODE (t
)) != GIMPLE_INVALID_RHS
;
904 #include "gt-gimple-expr.h"