Merge trunk version 204659 into gupc branch.
[official-gcc.git] / gcc / gimple-expr.c
blob886369af5c4bfd9104d6cb7191c00d02e953c451
1 /* Gimple decl, type, and expression support functions.
3 Copyright (C) 2007-2013 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 "tm.h"
26 #include "tree.h"
27 #include "langhooks.h"
28 #include "gimple.h"
29 #include "demangle.h"
31 /* ----- Type related ----- */
33 /* Return true if the conversion from INNER_TYPE to OUTER_TYPE is a
34 useless type conversion, otherwise return false.
36 This function implicitly defines the middle-end type system. With
37 the notion of 'a < b' meaning that useless_type_conversion_p (a, b)
38 holds and 'a > b' meaning that useless_type_conversion_p (b, a) holds,
39 the following invariants shall be fulfilled:
41 1) useless_type_conversion_p is transitive.
42 If a < b and b < c then a < c.
44 2) useless_type_conversion_p is not symmetric.
45 From a < b does not follow a > b.
47 3) Types define the available set of operations applicable to values.
48 A type conversion is useless if the operations for the target type
49 is a subset of the operations for the source type. For example
50 casts to void* are useless, casts from void* are not (void* can't
51 be dereferenced or offsetted, but copied, hence its set of operations
52 is a strict subset of that of all other data pointer types). Casts
53 to const T* are useless (can't be written to), casts from const T*
54 to T* are not. */
56 bool
57 useless_type_conversion_p (tree outer_type, tree inner_type)
59 /* Do the following before stripping toplevel qualifiers. */
60 if (POINTER_TYPE_P (inner_type)
61 && POINTER_TYPE_P (outer_type))
63 int i_shared = upc_shared_type_p (TREE_TYPE (inner_type));
64 int o_shared = upc_shared_type_p (TREE_TYPE (outer_type));
66 /* Retain conversions from a UPC shared pointer to
67 a regular C pointer. */
68 if (!o_shared && i_shared)
69 return false;
71 /* Retain conversions between incompatible UPC shared pointers. */
72 if (o_shared && i_shared
73 && !lang_hooks.types_compatible_p (inner_type, outer_type))
74 return false;
76 /* Do not lose casts between pointers to different address spaces. */
77 if (TYPE_ADDR_SPACE (TREE_TYPE (outer_type))
78 != TYPE_ADDR_SPACE (TREE_TYPE (inner_type)))
79 return false;
82 /* From now on qualifiers on value types do not matter. */
83 inner_type = TYPE_MAIN_VARIANT (inner_type);
84 outer_type = TYPE_MAIN_VARIANT (outer_type);
86 if (inner_type == outer_type)
87 return true;
89 /* If we know the canonical types, compare them. */
90 if (TYPE_CANONICAL (inner_type)
91 && TYPE_CANONICAL (inner_type) == TYPE_CANONICAL (outer_type))
92 return true;
94 /* Changes in machine mode are never useless conversions unless we
95 deal with aggregate types in which case we defer to later checks. */
96 if (TYPE_MODE (inner_type) != TYPE_MODE (outer_type)
97 && !AGGREGATE_TYPE_P (inner_type))
98 return false;
100 /* If both the inner and outer types are integral types, then the
101 conversion is not necessary if they have the same mode and
102 signedness and precision, and both or neither are boolean. */
103 if (INTEGRAL_TYPE_P (inner_type)
104 && INTEGRAL_TYPE_P (outer_type))
106 /* Preserve changes in signedness or precision. */
107 if (TYPE_UNSIGNED (inner_type) != TYPE_UNSIGNED (outer_type)
108 || TYPE_PRECISION (inner_type) != TYPE_PRECISION (outer_type))
109 return false;
111 /* Preserve conversions to/from BOOLEAN_TYPE if types are not
112 of precision one. */
113 if (((TREE_CODE (inner_type) == BOOLEAN_TYPE)
114 != (TREE_CODE (outer_type) == BOOLEAN_TYPE))
115 && TYPE_PRECISION (outer_type) != 1)
116 return false;
118 /* We don't need to preserve changes in the types minimum or
119 maximum value in general as these do not generate code
120 unless the types precisions are different. */
121 return true;
124 /* Scalar floating point types with the same mode are compatible. */
125 else if (SCALAR_FLOAT_TYPE_P (inner_type)
126 && SCALAR_FLOAT_TYPE_P (outer_type))
127 return true;
129 /* Fixed point types with the same mode are compatible. */
130 else if (FIXED_POINT_TYPE_P (inner_type)
131 && FIXED_POINT_TYPE_P (outer_type))
132 return true;
134 /* We need to take special care recursing to pointed-to types. */
135 else if (POINTER_TYPE_P (inner_type)
136 && POINTER_TYPE_P (outer_type))
138 /* Do not lose casts to function pointer types. */
139 if ((TREE_CODE (TREE_TYPE (outer_type)) == FUNCTION_TYPE
140 || TREE_CODE (TREE_TYPE (outer_type)) == METHOD_TYPE)
141 && !(TREE_CODE (TREE_TYPE (inner_type)) == FUNCTION_TYPE
142 || TREE_CODE (TREE_TYPE (inner_type)) == METHOD_TYPE))
143 return false;
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. */
149 return true;
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))
170 return false;
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))
176 return false;
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))))
186 return false;
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. */
216 if (outer_min
217 && (!inner_min
218 || !tree_int_cst_equal (inner_min, outer_min)))
219 return false;
220 if (outer_max
221 && (!inner_max
222 || !tree_int_cst_equal (inner_max, outer_max)))
223 return false;
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)))
240 return false;
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)))
246 return false;
248 /* A conversion to an unprototyped argument list is ok. */
249 if (!prototype_p (outer_type))
250 return true;
252 /* If the unqualified argument types are compatible the conversion
253 is useless. */
254 if (TYPE_ARG_TYPES (outer_type) == TYPE_ARG_TYPES (inner_type))
255 return true;
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))))
265 return false;
267 /* If there is a mismatch in the number of arguments the functions
268 are not compatible. */
269 if (outer_parm || inner_parm)
270 return false;
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;
276 return true;
279 /* For aggregates we rely on TYPE_CANONICAL exclusively and require
280 explicit conversions for types involving to be structurally
281 compared types. */
282 else if (AGGREGATE_TYPE_P (inner_type)
283 && TREE_CODE (inner_type) == TREE_CODE (outer_type))
284 return false;
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 /* 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. */
389 bool
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;
398 if (var1 != var2)
399 return false;
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);
405 if (t1 == t2)
406 return true;
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))
418 return true;
420 return false;
424 /* ----- Expression related ----- */
426 /* Extract the operands and code for expression EXPR into *SUBCODE_P,
427 *OP1_P, *OP2_P and *OP3_P respectively. */
429 void
430 extract_ops_from_tree_1 (tree expr, enum tree_code *subcode_p, tree *op1_p,
431 tree *op2_p, tree *op3_p)
433 enum gimple_rhs_class grhs_class;
435 *subcode_p = TREE_CODE (expr);
436 grhs_class = get_gimple_rhs_class (*subcode_p);
438 if (grhs_class == GIMPLE_TERNARY_RHS)
440 *op1_p = TREE_OPERAND (expr, 0);
441 *op2_p = TREE_OPERAND (expr, 1);
442 *op3_p = TREE_OPERAND (expr, 2);
444 else if (grhs_class == GIMPLE_BINARY_RHS)
446 *op1_p = TREE_OPERAND (expr, 0);
447 *op2_p = TREE_OPERAND (expr, 1);
448 *op3_p = NULL_TREE;
450 else if (grhs_class == GIMPLE_UNARY_RHS)
452 *op1_p = TREE_OPERAND (expr, 0);
453 *op2_p = NULL_TREE;
454 *op3_p = NULL_TREE;
456 else if (grhs_class == GIMPLE_SINGLE_RHS)
458 *op1_p = expr;
459 *op2_p = NULL_TREE;
460 *op3_p = NULL_TREE;
462 else
463 gcc_unreachable ();
466 /* Extract operands for a GIMPLE_COND statement out of COND_EXPR tree COND. */
468 void
469 gimple_cond_get_ops_from_tree (tree cond, enum tree_code *code_p,
470 tree *lhs_p, tree *rhs_p)
472 gcc_assert (TREE_CODE_CLASS (TREE_CODE (cond)) == tcc_comparison
473 || TREE_CODE (cond) == TRUTH_NOT_EXPR
474 || is_gimple_min_invariant (cond)
475 || SSA_VAR_P (cond));
477 extract_ops_from_tree (cond, code_p, lhs_p, rhs_p);
479 /* Canonicalize conditionals of the form 'if (!VAL)'. */
480 if (*code_p == TRUTH_NOT_EXPR)
482 *code_p = EQ_EXPR;
483 gcc_assert (*lhs_p && *rhs_p == NULL_TREE);
484 *rhs_p = build_zero_cst (TREE_TYPE (*lhs_p));
486 /* Canonicalize conditionals of the form 'if (VAL)' */
487 else if (TREE_CODE_CLASS (*code_p) != tcc_comparison)
489 *code_p = NE_EXPR;
490 gcc_assert (*lhs_p && *rhs_p == NULL_TREE);
491 *rhs_p = build_zero_cst (TREE_TYPE (*lhs_p));
495 /* Return true if T is a valid LHS for a GIMPLE assignment expression. */
497 bool
498 is_gimple_lvalue (tree t)
500 return (is_gimple_addressable (t)
501 || TREE_CODE (t) == WITH_SIZE_EXPR
502 /* These are complex lvalues, but don't have addresses, so they
503 go here. */
504 || TREE_CODE (t) == BIT_FIELD_REF);
507 /* Return true if T is a GIMPLE condition. */
509 bool
510 is_gimple_condexpr (tree t)
512 return (is_gimple_val (t) || (COMPARISON_CLASS_P (t)
513 && !tree_could_throw_p (t)
514 && is_gimple_val (TREE_OPERAND (t, 0))
515 && is_gimple_val (TREE_OPERAND (t, 1))));
518 /* Return true if T is a gimple address. */
520 bool
521 is_gimple_address (const_tree t)
523 tree op;
525 if (TREE_CODE (t) != ADDR_EXPR)
526 return false;
528 op = TREE_OPERAND (t, 0);
529 while (handled_component_p (op))
531 if ((TREE_CODE (op) == ARRAY_REF
532 || TREE_CODE (op) == ARRAY_RANGE_REF)
533 && !is_gimple_val (TREE_OPERAND (op, 1)))
534 return false;
536 op = TREE_OPERAND (op, 0);
539 if (CONSTANT_CLASS_P (op) || TREE_CODE (op) == MEM_REF)
540 return true;
542 switch (TREE_CODE (op))
544 case PARM_DECL:
545 case RESULT_DECL:
546 case LABEL_DECL:
547 case FUNCTION_DECL:
548 case VAR_DECL:
549 case CONST_DECL:
550 return true;
552 default:
553 return false;
557 /* Return true if T is a gimple invariant address. */
559 bool
560 is_gimple_invariant_address (const_tree t)
562 const_tree op;
564 if (TREE_CODE (t) != ADDR_EXPR)
565 return false;
567 op = strip_invariant_refs (TREE_OPERAND (t, 0));
568 if (!op)
569 return false;
571 if (TREE_CODE (op) == MEM_REF)
573 const_tree op0 = TREE_OPERAND (op, 0);
574 return (TREE_CODE (op0) == ADDR_EXPR
575 && (CONSTANT_CLASS_P (TREE_OPERAND (op0, 0))
576 || decl_address_invariant_p (TREE_OPERAND (op0, 0))));
579 return CONSTANT_CLASS_P (op) || decl_address_invariant_p (op);
582 /* Return true if T is a gimple invariant address at IPA level
583 (so addresses of variables on stack are not allowed). */
585 bool
586 is_gimple_ip_invariant_address (const_tree t)
588 const_tree op;
590 if (TREE_CODE (t) != ADDR_EXPR)
591 return false;
593 op = strip_invariant_refs (TREE_OPERAND (t, 0));
594 if (!op)
595 return false;
597 if (TREE_CODE (op) == MEM_REF)
599 const_tree op0 = TREE_OPERAND (op, 0);
600 return (TREE_CODE (op0) == ADDR_EXPR
601 && (CONSTANT_CLASS_P (TREE_OPERAND (op0, 0))
602 || decl_address_ip_invariant_p (TREE_OPERAND (op0, 0))));
605 return CONSTANT_CLASS_P (op) || decl_address_ip_invariant_p (op);
608 /* Return true if T is a GIMPLE minimal invariant. It's a restricted
609 form of function invariant. */
611 bool
612 is_gimple_min_invariant (const_tree t)
614 if (TREE_CODE (t) == ADDR_EXPR)
615 return is_gimple_invariant_address (t);
617 return is_gimple_constant (t);
620 /* Return true if T is a GIMPLE interprocedural invariant. It's a restricted
621 form of gimple minimal invariant. */
623 bool
624 is_gimple_ip_invariant (const_tree t)
626 if (TREE_CODE (t) == ADDR_EXPR)
627 return is_gimple_ip_invariant_address (t);
629 return is_gimple_constant (t);
632 /* Return true if T is a non-aggregate register variable. */
634 bool
635 is_gimple_reg (tree t)
637 if (virtual_operand_p (t))
638 return false;
640 if (TREE_CODE (t) == SSA_NAME)
641 return true;
643 if (!is_gimple_variable (t))
644 return false;
646 if (!is_gimple_reg_type (TREE_TYPE (t)))
647 return false;
649 /* A volatile decl is not acceptable because we can't reuse it as
650 needed. We need to copy it into a temp first. */
651 if (TREE_THIS_VOLATILE (t))
652 return false;
654 /* We define "registers" as things that can be renamed as needed,
655 which with our infrastructure does not apply to memory. */
656 if (needs_to_live_in_memory (t))
657 return false;
659 /* Hard register variables are an interesting case. For those that
660 are call-clobbered, we don't know where all the calls are, since
661 we don't (want to) take into account which operations will turn
662 into libcalls at the rtl level. For those that are call-saved,
663 we don't currently model the fact that calls may in fact change
664 global hard registers, nor do we examine ASM_CLOBBERS at the tree
665 level, and so miss variable changes that might imply. All around,
666 it seems safest to not do too much optimization with these at the
667 tree level at all. We'll have to rely on the rtl optimizers to
668 clean this up, as there we've got all the appropriate bits exposed. */
669 if (TREE_CODE (t) == VAR_DECL && DECL_HARD_REGISTER (t))
670 return false;
672 /* Complex and vector values must have been put into SSA-like form.
673 That is, no assignments to the individual components. */
674 if (TREE_CODE (TREE_TYPE (t)) == COMPLEX_TYPE
675 || TREE_CODE (TREE_TYPE (t)) == VECTOR_TYPE)
676 return DECL_GIMPLE_REG_P (t);
678 return true;
682 /* Return true if T is a GIMPLE rvalue, i.e. an identifier or a constant. */
684 bool
685 is_gimple_val (tree t)
687 /* Make loads from volatiles and memory vars explicit. */
688 if (is_gimple_variable (t)
689 && is_gimple_reg_type (TREE_TYPE (t))
690 && !is_gimple_reg (t))
691 return false;
693 return (is_gimple_variable (t) || is_gimple_min_invariant (t));
696 /* Similarly, but accept hard registers as inputs to asm statements. */
698 bool
699 is_gimple_asm_val (tree t)
701 if (TREE_CODE (t) == VAR_DECL && DECL_HARD_REGISTER (t))
702 return true;
704 return is_gimple_val (t);
707 /* Return true if T is a GIMPLE minimal lvalue. */
709 bool
710 is_gimple_min_lval (tree t)
712 if (!(t = CONST_CAST_TREE (strip_invariant_refs (t))))
713 return false;
714 return (is_gimple_id (t) || TREE_CODE (t) == MEM_REF);
717 /* Return true if T is a valid function operand of a CALL_EXPR. */
719 bool
720 is_gimple_call_addr (tree t)
722 return (TREE_CODE (t) == OBJ_TYPE_REF || is_gimple_val (t));
725 /* Return true if T is a valid address operand of a MEM_REF. */
727 bool
728 is_gimple_mem_ref_addr (tree t)
730 return (is_gimple_reg (t)
731 || TREE_CODE (t) == INTEGER_CST
732 || (TREE_CODE (t) == ADDR_EXPR
733 && (CONSTANT_CLASS_P (TREE_OPERAND (t, 0))
734 || decl_address_invariant_p (TREE_OPERAND (t, 0)))));