always define DYNAMIC_CHAIN_ADDRESS
[official-gcc.git] / gcc / gimple-expr.c
blob2a6ba1aadb919be62589d8eee67f980f814755c5
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
11 version.
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
16 for more details.
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/>. */
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "backend.h"
26 #include "tree.h"
27 #include "gimple.h"
28 #include "hard-reg-set.h"
29 #include "alias.h"
30 #include "fold-const.h"
31 #include "internal-fn.h"
32 #include "tree-eh.h"
33 #include "stringpool.h"
34 #include "gimple-ssa.h"
35 #include "gimplify.h"
36 #include "stor-layout.h"
37 #include "demangle.h"
39 /* ----- Type related ----- */
41 /* Return true if the conversion from INNER_TYPE to OUTER_TYPE is a
42 useless type conversion, otherwise return false.
44 This function implicitly defines the middle-end type system. With
45 the notion of 'a < b' meaning that useless_type_conversion_p (a, b)
46 holds and 'a > b' meaning that useless_type_conversion_p (b, a) holds,
47 the following invariants shall be fulfilled:
49 1) useless_type_conversion_p is transitive.
50 If a < b and b < c then a < c.
52 2) useless_type_conversion_p is not symmetric.
53 From a < b does not follow a > b.
55 3) Types define the available set of operations applicable to values.
56 A type conversion is useless if the operations for the target type
57 is a subset of the operations for the source type. For example
58 casts to void* are useless, casts from void* are not (void* can't
59 be dereferenced or offsetted, but copied, hence its set of operations
60 is a strict subset of that of all other data pointer types). Casts
61 to const T* are useless (can't be written to), casts from const T*
62 to T* are not. */
64 bool
65 useless_type_conversion_p (tree outer_type, tree inner_type)
67 /* Do the following before stripping toplevel qualifiers. */
68 if (POINTER_TYPE_P (inner_type)
69 && POINTER_TYPE_P (outer_type))
71 /* Do not lose casts between pointers to different address spaces. */
72 if (TYPE_ADDR_SPACE (TREE_TYPE (outer_type))
73 != TYPE_ADDR_SPACE (TREE_TYPE (inner_type)))
74 return false;
75 /* Do not lose casts to function pointer types. */
76 if ((TREE_CODE (TREE_TYPE (outer_type)) == FUNCTION_TYPE
77 || TREE_CODE (TREE_TYPE (outer_type)) == METHOD_TYPE)
78 && !(TREE_CODE (TREE_TYPE (inner_type)) == FUNCTION_TYPE
79 || TREE_CODE (TREE_TYPE (inner_type)) == METHOD_TYPE))
80 return false;
83 /* From now on qualifiers on value types do not matter. */
84 inner_type = TYPE_MAIN_VARIANT (inner_type);
85 outer_type = TYPE_MAIN_VARIANT (outer_type);
87 if (inner_type == outer_type)
88 return true;
90 /* Changes in machine mode are never useless conversions unless we
91 deal with aggregate types in which case we defer to later checks. */
92 if (TYPE_MODE (inner_type) != TYPE_MODE (outer_type)
93 && !AGGREGATE_TYPE_P (inner_type))
94 return false;
96 /* If both the inner and outer types are integral types, then the
97 conversion is not necessary if they have the same mode and
98 signedness and precision, and both or neither are boolean. */
99 if (INTEGRAL_TYPE_P (inner_type)
100 && INTEGRAL_TYPE_P (outer_type))
102 /* Preserve changes in signedness or precision. */
103 if (TYPE_UNSIGNED (inner_type) != TYPE_UNSIGNED (outer_type)
104 || TYPE_PRECISION (inner_type) != TYPE_PRECISION (outer_type))
105 return false;
107 /* Preserve conversions to/from BOOLEAN_TYPE if types are not
108 of precision one. */
109 if (((TREE_CODE (inner_type) == BOOLEAN_TYPE)
110 != (TREE_CODE (outer_type) == BOOLEAN_TYPE))
111 && TYPE_PRECISION (outer_type) != 1)
112 return false;
114 /* We don't need to preserve changes in the types minimum or
115 maximum value in general as these do not generate code
116 unless the types precisions are different. */
117 return true;
120 /* Scalar floating point types with the same mode are compatible. */
121 else if (SCALAR_FLOAT_TYPE_P (inner_type)
122 && SCALAR_FLOAT_TYPE_P (outer_type))
123 return true;
125 /* Fixed point types with the same mode are compatible. */
126 else if (FIXED_POINT_TYPE_P (inner_type)
127 && FIXED_POINT_TYPE_P (outer_type))
128 return true;
130 /* We need to take special care recursing to pointed-to types. */
131 else if (POINTER_TYPE_P (inner_type)
132 && POINTER_TYPE_P (outer_type))
134 /* We do not care for const qualification of the pointed-to types
135 as const qualification has no semantic value to the middle-end. */
137 /* Otherwise pointers/references are equivalent. */
138 return true;
141 /* Recurse for complex types. */
142 else if (TREE_CODE (inner_type) == COMPLEX_TYPE
143 && TREE_CODE (outer_type) == COMPLEX_TYPE)
144 return useless_type_conversion_p (TREE_TYPE (outer_type),
145 TREE_TYPE (inner_type));
147 /* Recurse for vector types with the same number of subparts. */
148 else if (TREE_CODE (inner_type) == VECTOR_TYPE
149 && TREE_CODE (outer_type) == VECTOR_TYPE
150 && TYPE_PRECISION (inner_type) == TYPE_PRECISION (outer_type))
151 return useless_type_conversion_p (TREE_TYPE (outer_type),
152 TREE_TYPE (inner_type));
154 else if (TREE_CODE (inner_type) == ARRAY_TYPE
155 && TREE_CODE (outer_type) == ARRAY_TYPE)
157 /* Preserve string attributes. */
158 if (TYPE_STRING_FLAG (inner_type) != TYPE_STRING_FLAG (outer_type))
159 return false;
161 /* Conversions from array types with unknown extent to
162 array types with known extent are not useless. */
163 if (!TYPE_DOMAIN (inner_type)
164 && TYPE_DOMAIN (outer_type))
165 return false;
167 /* Nor are conversions from array types with non-constant size to
168 array types with constant size or to different size. */
169 if (TYPE_SIZE (outer_type)
170 && TREE_CODE (TYPE_SIZE (outer_type)) == INTEGER_CST
171 && (!TYPE_SIZE (inner_type)
172 || TREE_CODE (TYPE_SIZE (inner_type)) != INTEGER_CST
173 || !tree_int_cst_equal (TYPE_SIZE (outer_type),
174 TYPE_SIZE (inner_type))))
175 return false;
177 /* Check conversions between arrays with partially known extents.
178 If the array min/max values are constant they have to match.
179 Otherwise allow conversions to unknown and variable extents.
180 In particular this declares conversions that may change the
181 mode to BLKmode as useless. */
182 if (TYPE_DOMAIN (inner_type)
183 && TYPE_DOMAIN (outer_type)
184 && TYPE_DOMAIN (inner_type) != TYPE_DOMAIN (outer_type))
186 tree inner_min = TYPE_MIN_VALUE (TYPE_DOMAIN (inner_type));
187 tree outer_min = TYPE_MIN_VALUE (TYPE_DOMAIN (outer_type));
188 tree inner_max = TYPE_MAX_VALUE (TYPE_DOMAIN (inner_type));
189 tree outer_max = TYPE_MAX_VALUE (TYPE_DOMAIN (outer_type));
191 /* After gimplification a variable min/max value carries no
192 additional information compared to a NULL value. All that
193 matters has been lowered to be part of the IL. */
194 if (inner_min && TREE_CODE (inner_min) != INTEGER_CST)
195 inner_min = NULL_TREE;
196 if (outer_min && TREE_CODE (outer_min) != INTEGER_CST)
197 outer_min = NULL_TREE;
198 if (inner_max && TREE_CODE (inner_max) != INTEGER_CST)
199 inner_max = NULL_TREE;
200 if (outer_max && TREE_CODE (outer_max) != INTEGER_CST)
201 outer_max = NULL_TREE;
203 /* Conversions NULL / variable <- cst are useless, but not
204 the other way around. */
205 if (outer_min
206 && (!inner_min
207 || !tree_int_cst_equal (inner_min, outer_min)))
208 return false;
209 if (outer_max
210 && (!inner_max
211 || !tree_int_cst_equal (inner_max, outer_max)))
212 return false;
215 /* Recurse on the element check. */
216 return useless_type_conversion_p (TREE_TYPE (outer_type),
217 TREE_TYPE (inner_type));
220 else if ((TREE_CODE (inner_type) == FUNCTION_TYPE
221 || TREE_CODE (inner_type) == METHOD_TYPE)
222 && TREE_CODE (inner_type) == TREE_CODE (outer_type))
224 tree outer_parm, inner_parm;
226 /* If the return types are not compatible bail out. */
227 if (!useless_type_conversion_p (TREE_TYPE (outer_type),
228 TREE_TYPE (inner_type)))
229 return false;
231 /* Method types should belong to a compatible base class. */
232 if (TREE_CODE (inner_type) == METHOD_TYPE
233 && !useless_type_conversion_p (TYPE_METHOD_BASETYPE (outer_type),
234 TYPE_METHOD_BASETYPE (inner_type)))
235 return false;
237 /* A conversion to an unprototyped argument list is ok. */
238 if (!prototype_p (outer_type))
239 return true;
241 /* If the unqualified argument types are compatible the conversion
242 is useless. */
243 if (TYPE_ARG_TYPES (outer_type) == TYPE_ARG_TYPES (inner_type))
244 return true;
246 for (outer_parm = TYPE_ARG_TYPES (outer_type),
247 inner_parm = TYPE_ARG_TYPES (inner_type);
248 outer_parm && inner_parm;
249 outer_parm = TREE_CHAIN (outer_parm),
250 inner_parm = TREE_CHAIN (inner_parm))
251 if (!useless_type_conversion_p
252 (TYPE_MAIN_VARIANT (TREE_VALUE (outer_parm)),
253 TYPE_MAIN_VARIANT (TREE_VALUE (inner_parm))))
254 return false;
256 /* If there is a mismatch in the number of arguments the functions
257 are not compatible. */
258 if (outer_parm || inner_parm)
259 return false;
261 /* Defer to the target if necessary. */
262 if (TYPE_ATTRIBUTES (inner_type) || TYPE_ATTRIBUTES (outer_type))
263 return comp_type_attributes (outer_type, inner_type) != 0;
265 return true;
268 /* For aggregates compare only the size. Accesses to fields do have
269 a type information by themselves and thus we only care if we can i.e.
270 use the types in move operations. */
271 else if (AGGREGATE_TYPE_P (inner_type)
272 && TREE_CODE (inner_type) == TREE_CODE (outer_type))
273 return (!TYPE_SIZE (outer_type)
274 || (TYPE_SIZE (inner_type)
275 && operand_equal_p (TYPE_SIZE (inner_type),
276 TYPE_SIZE (outer_type), 0)));
278 else if (TREE_CODE (inner_type) == OFFSET_TYPE
279 && TREE_CODE (outer_type) == OFFSET_TYPE)
280 return useless_type_conversion_p (TREE_TYPE (outer_type),
281 TREE_TYPE (inner_type))
282 && useless_type_conversion_p
283 (TYPE_OFFSET_BASETYPE (outer_type),
284 TYPE_OFFSET_BASETYPE (inner_type));
286 return false;
290 /* ----- Decl related ----- */
292 /* Set sequence SEQ to be the GIMPLE body for function FN. */
294 void
295 gimple_set_body (tree fndecl, gimple_seq seq)
297 struct function *fn = DECL_STRUCT_FUNCTION (fndecl);
298 if (fn == NULL)
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
302 GIMPLE body. */
303 gcc_assert (seq == NULL);
305 else
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
313 NULL. */
315 gimple_seq
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
323 or CFG form. */
324 bool
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. */
333 const char *
334 gimple_decl_printable_name (tree decl, int verbosity)
336 if (!DECL_NAME (decl))
337 return NULL;
339 if (DECL_ASSEMBLER_NAME_SET_P (decl))
341 const char *str, *mangled_str;
342 int dmgl_opts = DMGL_NO_OPTS;
344 if (verbosity >= 2)
346 dmgl_opts = DMGL_VERBOSE
347 | DMGL_ANSI
348 | DMGL_GNU_V3
349 | DMGL_RET_POSTFIX;
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. */
365 tree
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);
381 return copy;
384 /* Strip off a legitimate source ending from the input string NAME of
385 length LEN. Rather than having to know the names used by all of
386 our front ends, we strip off an ending of a period followed by
387 up to five characters. (Java uses ".class".) */
389 static inline void
390 remove_suffix (char *name, int len)
392 int i;
394 for (i = 2; i < 8 && len > i; i++)
396 if (name[len - i] == '.')
398 name[len - i] = '\0';
399 break;
404 /* Create a new temporary name with PREFIX. Return an identifier. */
406 static GTY(()) unsigned int tmp_var_id_num;
408 tree
409 create_tmp_var_name (const char *prefix)
411 char *tmp_name;
413 if (prefix)
415 char *preftmp = ASTRDUP (prefix);
417 remove_suffix (preftmp, strlen (preftmp));
418 clean_symbol_name (preftmp);
420 prefix = preftmp;
423 ASM_FORMAT_PRIVATE_NAME (tmp_name, prefix ? prefix : "T", tmp_var_id_num++);
424 return get_identifier (tmp_name);
427 /* Create a new temporary variable declaration of type TYPE.
428 Do NOT push it into the current binding. */
430 tree
431 create_tmp_var_raw (tree type, const char *prefix)
433 tree tmp_var;
435 tmp_var = build_decl (input_location,
436 VAR_DECL, prefix ? create_tmp_var_name (prefix) : NULL,
437 type);
439 /* The variable was declared by the compiler. */
440 DECL_ARTIFICIAL (tmp_var) = 1;
441 /* And we don't want debug info for it. */
442 DECL_IGNORED_P (tmp_var) = 1;
444 /* Make the variable writable. */
445 TREE_READONLY (tmp_var) = 0;
447 DECL_EXTERNAL (tmp_var) = 0;
448 TREE_STATIC (tmp_var) = 0;
449 TREE_USED (tmp_var) = 1;
451 return tmp_var;
454 /* Create a new temporary variable declaration of type TYPE. DO push the
455 variable into the current binding. Further, assume that this is called
456 only from gimplification or optimization, at which point the creation of
457 certain types are bugs. */
459 tree
460 create_tmp_var (tree type, const char *prefix)
462 tree tmp_var;
464 /* We don't allow types that are addressable (meaning we can't make copies),
465 or incomplete. We also used to reject every variable size objects here,
466 but now support those for which a constant upper bound can be obtained.
467 The processing for variable sizes is performed in gimple_add_tmp_var,
468 point at which it really matters and possibly reached via paths not going
469 through this function, e.g. after direct calls to create_tmp_var_raw. */
470 gcc_assert (!TREE_ADDRESSABLE (type) && COMPLETE_TYPE_P (type));
472 tmp_var = create_tmp_var_raw (type, prefix);
473 gimple_add_tmp_var (tmp_var);
474 return tmp_var;
477 /* Create a new temporary variable declaration of type TYPE by calling
478 create_tmp_var and if TYPE is a vector or a complex number, mark the new
479 temporary as gimple register. */
481 tree
482 create_tmp_reg (tree type, const char *prefix)
484 tree tmp;
486 tmp = create_tmp_var (type, prefix);
487 if (TREE_CODE (type) == COMPLEX_TYPE
488 || TREE_CODE (type) == VECTOR_TYPE)
489 DECL_GIMPLE_REG_P (tmp) = 1;
491 return tmp;
494 /* Create a new temporary variable declaration of type TYPE by calling
495 create_tmp_var and if TYPE is a vector or a complex number, mark the new
496 temporary as gimple register. */
498 tree
499 create_tmp_reg_fn (struct function *fn, tree type, const char *prefix)
501 tree tmp;
503 tmp = create_tmp_var_raw (type, prefix);
504 gimple_add_tmp_var_fn (fn, tmp);
505 if (TREE_CODE (type) == COMPLEX_TYPE
506 || TREE_CODE (type) == VECTOR_TYPE)
507 DECL_GIMPLE_REG_P (tmp) = 1;
509 return tmp;
513 /* ----- Expression related ----- */
515 /* Extract the operands and code for expression EXPR into *SUBCODE_P,
516 *OP1_P, *OP2_P and *OP3_P respectively. */
518 void
519 extract_ops_from_tree_1 (tree expr, enum tree_code *subcode_p, tree *op1_p,
520 tree *op2_p, tree *op3_p)
522 enum gimple_rhs_class grhs_class;
524 *subcode_p = TREE_CODE (expr);
525 grhs_class = get_gimple_rhs_class (*subcode_p);
527 if (grhs_class == GIMPLE_TERNARY_RHS)
529 *op1_p = TREE_OPERAND (expr, 0);
530 *op2_p = TREE_OPERAND (expr, 1);
531 *op3_p = TREE_OPERAND (expr, 2);
533 else if (grhs_class == GIMPLE_BINARY_RHS)
535 *op1_p = TREE_OPERAND (expr, 0);
536 *op2_p = TREE_OPERAND (expr, 1);
537 *op3_p = NULL_TREE;
539 else if (grhs_class == GIMPLE_UNARY_RHS)
541 *op1_p = TREE_OPERAND (expr, 0);
542 *op2_p = NULL_TREE;
543 *op3_p = NULL_TREE;
545 else if (grhs_class == GIMPLE_SINGLE_RHS)
547 *op1_p = expr;
548 *op2_p = NULL_TREE;
549 *op3_p = NULL_TREE;
551 else
552 gcc_unreachable ();
555 /* Extract operands for a GIMPLE_COND statement out of COND_EXPR tree COND. */
557 void
558 gimple_cond_get_ops_from_tree (tree cond, enum tree_code *code_p,
559 tree *lhs_p, tree *rhs_p)
561 gcc_assert (COMPARISON_CLASS_P (cond)
562 || TREE_CODE (cond) == TRUTH_NOT_EXPR
563 || is_gimple_min_invariant (cond)
564 || SSA_VAR_P (cond));
566 extract_ops_from_tree (cond, code_p, lhs_p, rhs_p);
568 /* Canonicalize conditionals of the form 'if (!VAL)'. */
569 if (*code_p == TRUTH_NOT_EXPR)
571 *code_p = EQ_EXPR;
572 gcc_assert (*lhs_p && *rhs_p == NULL_TREE);
573 *rhs_p = build_zero_cst (TREE_TYPE (*lhs_p));
575 /* Canonicalize conditionals of the form 'if (VAL)' */
576 else if (TREE_CODE_CLASS (*code_p) != tcc_comparison)
578 *code_p = NE_EXPR;
579 gcc_assert (*lhs_p && *rhs_p == NULL_TREE);
580 *rhs_p = build_zero_cst (TREE_TYPE (*lhs_p));
584 /* Return true if T is a valid LHS for a GIMPLE assignment expression. */
586 bool
587 is_gimple_lvalue (tree t)
589 return (is_gimple_addressable (t)
590 || TREE_CODE (t) == WITH_SIZE_EXPR
591 /* These are complex lvalues, but don't have addresses, so they
592 go here. */
593 || TREE_CODE (t) == BIT_FIELD_REF);
596 /* Return true if T is a GIMPLE condition. */
598 bool
599 is_gimple_condexpr (tree t)
601 return (is_gimple_val (t) || (COMPARISON_CLASS_P (t)
602 && !tree_could_throw_p (t)
603 && is_gimple_val (TREE_OPERAND (t, 0))
604 && is_gimple_val (TREE_OPERAND (t, 1))));
607 /* Return true if T is a gimple address. */
609 bool
610 is_gimple_address (const_tree t)
612 tree op;
614 if (TREE_CODE (t) != ADDR_EXPR)
615 return false;
617 op = TREE_OPERAND (t, 0);
618 while (handled_component_p (op))
620 if ((TREE_CODE (op) == ARRAY_REF
621 || TREE_CODE (op) == ARRAY_RANGE_REF)
622 && !is_gimple_val (TREE_OPERAND (op, 1)))
623 return false;
625 op = TREE_OPERAND (op, 0);
628 if (CONSTANT_CLASS_P (op) || TREE_CODE (op) == MEM_REF)
629 return true;
631 switch (TREE_CODE (op))
633 case PARM_DECL:
634 case RESULT_DECL:
635 case LABEL_DECL:
636 case FUNCTION_DECL:
637 case VAR_DECL:
638 case CONST_DECL:
639 return true;
641 default:
642 return false;
646 /* Return true if T is a gimple invariant address. */
648 bool
649 is_gimple_invariant_address (const_tree t)
651 const_tree op;
653 if (TREE_CODE (t) != ADDR_EXPR)
654 return false;
656 op = strip_invariant_refs (TREE_OPERAND (t, 0));
657 if (!op)
658 return false;
660 if (TREE_CODE (op) == MEM_REF)
662 const_tree op0 = TREE_OPERAND (op, 0);
663 return (TREE_CODE (op0) == ADDR_EXPR
664 && (CONSTANT_CLASS_P (TREE_OPERAND (op0, 0))
665 || decl_address_invariant_p (TREE_OPERAND (op0, 0))));
668 return CONSTANT_CLASS_P (op) || decl_address_invariant_p (op);
671 /* Return true if T is a gimple invariant address at IPA level
672 (so addresses of variables on stack are not allowed). */
674 bool
675 is_gimple_ip_invariant_address (const_tree t)
677 const_tree op;
679 if (TREE_CODE (t) != ADDR_EXPR)
680 return false;
682 op = strip_invariant_refs (TREE_OPERAND (t, 0));
683 if (!op)
684 return false;
686 if (TREE_CODE (op) == MEM_REF)
688 const_tree op0 = TREE_OPERAND (op, 0);
689 return (TREE_CODE (op0) == ADDR_EXPR
690 && (CONSTANT_CLASS_P (TREE_OPERAND (op0, 0))
691 || decl_address_ip_invariant_p (TREE_OPERAND (op0, 0))));
694 return CONSTANT_CLASS_P (op) || decl_address_ip_invariant_p (op);
697 /* Return true if T is a GIMPLE minimal invariant. It's a restricted
698 form of function invariant. */
700 bool
701 is_gimple_min_invariant (const_tree t)
703 if (TREE_CODE (t) == ADDR_EXPR)
704 return is_gimple_invariant_address (t);
706 return is_gimple_constant (t);
709 /* Return true if T is a GIMPLE interprocedural invariant. It's a restricted
710 form of gimple minimal invariant. */
712 bool
713 is_gimple_ip_invariant (const_tree t)
715 if (TREE_CODE (t) == ADDR_EXPR)
716 return is_gimple_ip_invariant_address (t);
718 return is_gimple_constant (t);
721 /* Return true if T is a non-aggregate register variable. */
723 bool
724 is_gimple_reg (tree t)
726 if (virtual_operand_p (t))
727 return false;
729 if (TREE_CODE (t) == SSA_NAME)
730 return true;
732 if (!is_gimple_variable (t))
733 return false;
735 if (!is_gimple_reg_type (TREE_TYPE (t)))
736 return false;
738 /* A volatile decl is not acceptable because we can't reuse it as
739 needed. We need to copy it into a temp first. */
740 if (TREE_THIS_VOLATILE (t))
741 return false;
743 /* We define "registers" as things that can be renamed as needed,
744 which with our infrastructure does not apply to memory. */
745 if (needs_to_live_in_memory (t))
746 return false;
748 /* Hard register variables are an interesting case. For those that
749 are call-clobbered, we don't know where all the calls are, since
750 we don't (want to) take into account which operations will turn
751 into libcalls at the rtl level. For those that are call-saved,
752 we don't currently model the fact that calls may in fact change
753 global hard registers, nor do we examine ASM_CLOBBERS at the tree
754 level, and so miss variable changes that might imply. All around,
755 it seems safest to not do too much optimization with these at the
756 tree level at all. We'll have to rely on the rtl optimizers to
757 clean this up, as there we've got all the appropriate bits exposed. */
758 if (TREE_CODE (t) == VAR_DECL && DECL_HARD_REGISTER (t))
759 return false;
761 /* Complex and vector values must have been put into SSA-like form.
762 That is, no assignments to the individual components. */
763 if (TREE_CODE (TREE_TYPE (t)) == COMPLEX_TYPE
764 || TREE_CODE (TREE_TYPE (t)) == VECTOR_TYPE)
765 return DECL_GIMPLE_REG_P (t);
767 return true;
771 /* Return true if T is a GIMPLE rvalue, i.e. an identifier or a constant. */
773 bool
774 is_gimple_val (tree t)
776 /* Make loads from volatiles and memory vars explicit. */
777 if (is_gimple_variable (t)
778 && is_gimple_reg_type (TREE_TYPE (t))
779 && !is_gimple_reg (t))
780 return false;
782 return (is_gimple_variable (t) || is_gimple_min_invariant (t));
785 /* Similarly, but accept hard registers as inputs to asm statements. */
787 bool
788 is_gimple_asm_val (tree t)
790 if (TREE_CODE (t) == VAR_DECL && DECL_HARD_REGISTER (t))
791 return true;
793 return is_gimple_val (t);
796 /* Return true if T is a GIMPLE minimal lvalue. */
798 bool
799 is_gimple_min_lval (tree t)
801 if (!(t = CONST_CAST_TREE (strip_invariant_refs (t))))
802 return false;
803 return (is_gimple_id (t) || TREE_CODE (t) == MEM_REF);
806 /* Return true if T is a valid function operand of a CALL_EXPR. */
808 bool
809 is_gimple_call_addr (tree t)
811 return (TREE_CODE (t) == OBJ_TYPE_REF || is_gimple_val (t));
814 /* Return true if T is a valid address operand of a MEM_REF. */
816 bool
817 is_gimple_mem_ref_addr (tree t)
819 return (is_gimple_reg (t)
820 || TREE_CODE (t) == INTEGER_CST
821 || (TREE_CODE (t) == ADDR_EXPR
822 && (CONSTANT_CLASS_P (TREE_OPERAND (t, 0))
823 || decl_address_invariant_p (TREE_OPERAND (t, 0)))));
826 /* Mark X addressable. Unlike the langhook we expect X to be in gimple
827 form and we don't do any syntax checking. */
829 void
830 mark_addressable (tree x)
832 while (handled_component_p (x))
833 x = TREE_OPERAND (x, 0);
834 if (TREE_CODE (x) == MEM_REF
835 && TREE_CODE (TREE_OPERAND (x, 0)) == ADDR_EXPR)
836 x = TREE_OPERAND (TREE_OPERAND (x, 0), 0);
837 if (TREE_CODE (x) != VAR_DECL
838 && TREE_CODE (x) != PARM_DECL
839 && TREE_CODE (x) != RESULT_DECL)
840 return;
841 TREE_ADDRESSABLE (x) = 1;
843 /* Also mark the artificial SSA_NAME that points to the partition of X. */
844 if (TREE_CODE (x) == VAR_DECL
845 && !DECL_EXTERNAL (x)
846 && !TREE_STATIC (x)
847 && cfun->gimple_df != NULL
848 && cfun->gimple_df->decls_to_pointers != NULL)
850 tree *namep = cfun->gimple_df->decls_to_pointers->get (x);
851 if (namep)
852 TREE_ADDRESSABLE (*namep) = 1;
856 /* Returns true iff T is a valid RHS for an assignment to a renamed
857 user -- or front-end generated artificial -- variable. */
859 bool
860 is_gimple_reg_rhs (tree t)
862 return get_gimple_rhs_class (TREE_CODE (t)) != GIMPLE_INVALID_RHS;
865 #include "gt-gimple-expr.h"