LCOV - code coverage report
Current view: top level - gcc - gimple-expr.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 93.4 % 377 352
Test Date: 2026-05-30 15:37:04 Functions: 97.1 % 34 33
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Gimple decl, type, and expression support functions.
       2              : 
       3              :    Copyright (C) 2007-2026 Free Software Foundation, Inc.
       4              :    Contributed by Aldy Hernandez <aldyh@redhat.com>
       5              : 
       6              : This file is part of GCC.
       7              : 
       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.
      12              : 
      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.
      17              : 
      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/>.  */
      21              : 
      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 "stringpool.h"
      29              : #include "gimple-ssa.h"
      30              : #include "fold-const.h"
      31              : #include "tree-eh.h"
      32              : #include "gimplify.h"
      33              : #include "stor-layout.h"
      34              : #include "demangle.h"
      35              : #include "hash-set.h"
      36              : #include "rtl.h"
      37              : #include "tree-pass.h"
      38              : #include "stringpool.h"
      39              : #include "attribs.h"
      40              : #include "target.h"
      41              : 
      42              : /* ----- Type related -----  */
      43              : 
      44              : /* Return true if the conversion from INNER_TYPE to OUTER_TYPE is a
      45              :    useless type conversion, otherwise return false.
      46              : 
      47              :    This function implicitly defines the middle-end type system.  With
      48              :    the notion of 'a < b' meaning that useless_type_conversion_p (a, b)
      49              :    holds and 'a > b' meaning that useless_type_conversion_p (b, a) holds,
      50              :    the following invariants shall be fulfilled:
      51              : 
      52              :      1) useless_type_conversion_p is transitive.
      53              :         If a < b and b < c then a < c.
      54              : 
      55              :      2) useless_type_conversion_p is not symmetric.
      56              :         From a < b does not follow a > b.
      57              : 
      58              :      3) Types define the available set of operations applicable to values.
      59              :         A type conversion is useless if the operations for the target type
      60              :         is a subset of the operations for the source type.  For example
      61              :         casts to void* are useless, casts from void* are not (void* can't
      62              :         be dereferenced or offsetted, but copied, hence its set of operations
      63              :         is a strict subset of that of all other data pointer types).  Casts
      64              :         to const T* are useless (can't be written to), casts from const T*
      65              :         to T* are not.  */
      66              : 
      67              : bool
      68  11849690521 : useless_type_conversion_p (tree outer_type, tree inner_type)
      69              : {
      70              :   /* Do the following before stripping toplevel qualifiers.  */
      71  11850227193 :   if (POINTER_TYPE_P (inner_type)
      72   2975176258 :       && POINTER_TYPE_P (outer_type))
      73              :     {
      74              :       /* Do not lose casts between pointers to different address spaces.  */
      75   2946010903 :       if (TYPE_ADDR_SPACE (TREE_TYPE (outer_type))
      76   2946010903 :           != TYPE_ADDR_SPACE (TREE_TYPE (inner_type)))
      77              :         return false;
      78              :       /* Do not lose casts to function pointer types.  */
      79   5816165091 :       if (FUNC_OR_METHOD_TYPE_P (TREE_TYPE (outer_type))
      80   2953156554 :           && !FUNC_OR_METHOD_TYPE_P (TREE_TYPE (inner_type)))
      81              :         return false;
      82              :     }
      83              : 
      84              :   /* From now on qualifiers on value types do not matter.  */
      85  11848736433 :   inner_type = TYPE_MAIN_VARIANT (inner_type);
      86  11848736433 :   outer_type = TYPE_MAIN_VARIANT (outer_type);
      87              : 
      88  11848736433 :   if (inner_type == outer_type)
      89              :     return true;
      90              : 
      91              :   /* Changes in machine mode are never useless conversions because the RTL
      92              :      middle-end expects explicit conversions between modes.  */
      93   1054945018 :   if (TYPE_MODE (inner_type) != TYPE_MODE (outer_type))
      94              :     return false;
      95              : 
      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    947590279 :   if (INTEGRAL_TYPE_P (inner_type)
     100    175308249 :       && INTEGRAL_TYPE_P (outer_type))
     101              :     {
     102              :       /* Preserve changes in signedness or precision.  */
     103    163035860 :       if (TYPE_UNSIGNED (inner_type) != TYPE_UNSIGNED (outer_type)
     104    163035860 :           || TYPE_PRECISION (inner_type) != TYPE_PRECISION (outer_type))
     105              :         return false;
     106              : 
     107              :       /* Preserve conversions to/from BOOLEAN_TYPE if types are not
     108              :          of precision one.  */
     109     66749899 :       if (((TREE_CODE (inner_type) == BOOLEAN_TYPE)
     110     66749899 :            != (TREE_CODE (outer_type) == BOOLEAN_TYPE))
     111     66749899 :           && TYPE_PRECISION (outer_type) != 1)
     112              :         return false;
     113              : 
     114              :       /* Preserve conversions to/from BITINT_TYPE.  While we don't
     115              :          need to care that much about such conversions within a function's
     116              :          body, we need to prevent changing BITINT_TYPE to INTEGER_TYPE
     117              :          of the same precision or vice versa when passed to functions,
     118              :          especially for varargs.  */
     119     66706274 :       if (BITINT_TYPE_P (inner_type) != BITINT_TYPE_P (outer_type))
     120              :         return false;
     121              : 
     122              :       /* We don't need to preserve changes in the types minimum or
     123              :          maximum value in general as these do not generate code
     124              :          unless the types precisions are different.  */
     125              :       return true;
     126              :     }
     127              : 
     128              :   /* Scalar floating point types with the same mode are compatible.  */
     129    784554419 :   else if (SCALAR_FLOAT_TYPE_P (inner_type)
     130       596732 :            && SCALAR_FLOAT_TYPE_P (outer_type))
     131              :     return true;
     132              : 
     133              :   /* Fixed point types with the same mode are compatible.  */
     134    783960871 :   else if (FIXED_POINT_TYPE_P (inner_type)
     135            0 :            && FIXED_POINT_TYPE_P (outer_type))
     136            0 :     return TYPE_SATURATING (inner_type) == TYPE_SATURATING (outer_type);
     137              : 
     138              :   /* We need to take special care recursing to pointed-to types.  */
     139    783960871 :   else if (POINTER_TYPE_P (inner_type)
     140    757567327 :            && POINTER_TYPE_P (outer_type))
     141              :     {
     142              :       /* We do not care for const qualification of the pointed-to types
     143              :          as const qualification has no semantic value to the middle-end.  */
     144              : 
     145              :       /* Otherwise pointers/references are equivalent.  */
     146              :       return true;
     147              :     }
     148              : 
     149              :   /* Recurse for complex types.  */
     150     47223889 :   else if (TREE_CODE (inner_type) == COMPLEX_TYPE
     151        34624 :            && TREE_CODE (outer_type) == COMPLEX_TYPE)
     152        33445 :     return useless_type_conversion_p (TREE_TYPE (outer_type),
     153        66890 :                                       TREE_TYPE (inner_type));
     154              : 
     155              :   /* Recurse for vector types with the same number of subparts.  */
     156     47190444 :   else if (VECTOR_TYPE_P (inner_type)
     157      9677336 :            && VECTOR_TYPE_P (outer_type))
     158     19282534 :     return (known_eq (TYPE_VECTOR_SUBPARTS (inner_type),
     159              :                       TYPE_VECTOR_SUBPARTS (outer_type))
     160      9634366 :             && useless_type_conversion_p (TREE_TYPE (outer_type),
     161      9634366 :                                           TREE_TYPE (inner_type))
     162     18970362 :             && targetm.compatible_vector_types_p (inner_type, outer_type));
     163              : 
     164     37549177 :   else if (TREE_CODE (inner_type) == ARRAY_TYPE
     165       837019 :            && TREE_CODE (outer_type) == ARRAY_TYPE)
     166              :     {
     167              :       /* Preserve various attributes.  */
     168       680150 :       if (TYPE_REVERSE_STORAGE_ORDER (inner_type)
     169       680150 :           != TYPE_REVERSE_STORAGE_ORDER (outer_type))
     170              :         return false;
     171       680150 :       if (TYPE_STRING_FLAG (inner_type) != TYPE_STRING_FLAG (outer_type))
     172              :         return false;
     173              : 
     174              :       /* Conversions from array types with unknown extent to
     175              :          array types with known extent are not useless.  */
     176       645512 :       if (!TYPE_DOMAIN (inner_type) && TYPE_DOMAIN (outer_type))
     177              :         return false;
     178              : 
     179              :       /* Nor are conversions from array types with non-constant size to
     180              :          array types with constant size or to different size.  */
     181       643086 :       if (TYPE_SIZE (outer_type)
     182       627427 :           && TREE_CODE (TYPE_SIZE (outer_type)) == INTEGER_CST
     183      1245442 :           && (!TYPE_SIZE (inner_type)
     184       600660 :               || TREE_CODE (TYPE_SIZE (inner_type)) != INTEGER_CST
     185       598806 :               || !tree_int_cst_equal (TYPE_SIZE (outer_type),
     186       598806 :                                       TYPE_SIZE (inner_type))))
     187        40761 :         return false;
     188              : 
     189              :       /* Check conversions between arrays with partially known extents.
     190              :          If the array min/max values are constant they have to match.
     191              :          Otherwise allow conversions to unknown and variable extents.
     192              :          In particular this declares conversions that may change the
     193              :          mode to BLKmode as useless.  */
     194       602325 :       if (TYPE_DOMAIN (inner_type)
     195       602323 :           && TYPE_DOMAIN (outer_type)
     196      1204626 :           && TYPE_DOMAIN (inner_type) != TYPE_DOMAIN (outer_type))
     197              :         {
     198       137284 :           tree inner_min = TYPE_MIN_VALUE (TYPE_DOMAIN (inner_type));
     199       137284 :           tree outer_min = TYPE_MIN_VALUE (TYPE_DOMAIN (outer_type));
     200       137284 :           tree inner_max = TYPE_MAX_VALUE (TYPE_DOMAIN (inner_type));
     201       137284 :           tree outer_max = TYPE_MAX_VALUE (TYPE_DOMAIN (outer_type));
     202              : 
     203              :           /* After gimplification a variable min/max value carries no
     204              :              additional information compared to a NULL value.  All that
     205              :              matters has been lowered to be part of the IL.  */
     206       137284 :           if (inner_min && TREE_CODE (inner_min) != INTEGER_CST)
     207            0 :             inner_min = NULL_TREE;
     208       137284 :           if (outer_min && TREE_CODE (outer_min) != INTEGER_CST)
     209            0 :             outer_min = NULL_TREE;
     210       137284 :           if (inner_max && TREE_CODE (inner_max) != INTEGER_CST)
     211        23237 :             inner_max = NULL_TREE;
     212       137284 :           if (outer_max && TREE_CODE (outer_max) != INTEGER_CST)
     213        27542 :             outer_max = NULL_TREE;
     214              : 
     215              :           /* Conversions NULL / variable <- cst are useless, but not
     216              :              the other way around.  */
     217       137284 :           if (outer_min
     218       137284 :               && (!inner_min
     219       137284 :                   || !tree_int_cst_equal (inner_min, outer_min)))
     220         8561 :             return false;
     221       128723 :           if (outer_max
     222       128723 :               && (!inner_max
     223       101169 :                   || !tree_int_cst_equal (inner_max, outer_max)))
     224        90537 :             return false;
     225              :         }
     226              : 
     227              :       /* Recurse on the element check.  */
     228       503227 :       return useless_type_conversion_p (TREE_TYPE (outer_type),
     229      1006454 :                                         TREE_TYPE (inner_type));
     230              :     }
     231              : 
     232     36869027 :   else if (FUNC_OR_METHOD_TYPE_P (inner_type)
     233       328468 :            && TREE_CODE (inner_type) == TREE_CODE (outer_type))
     234              :     {
     235       322808 :       tree outer_parm, inner_parm;
     236              : 
     237              :       /* If the return types are not compatible bail out.  */
     238       322808 :       if (!useless_type_conversion_p (TREE_TYPE (outer_type),
     239       322808 :                                       TREE_TYPE (inner_type)))
     240              :         return false;
     241              : 
     242              :       /* Method types should belong to a compatible base class.  */
     243       314494 :       if (TREE_CODE (inner_type) == METHOD_TYPE
     244       329116 :           && !useless_type_conversion_p (TYPE_METHOD_BASETYPE (outer_type),
     245        14622 :                                          TYPE_METHOD_BASETYPE (inner_type)))
     246              :         return false;
     247              : 
     248              :       /* A conversion to an unprototyped argument list is ok.  */
     249       306344 :       if (!prototype_p (outer_type))
     250              :         return true;
     251              : 
     252              :       /* If the unqualified argument types are compatible the conversion
     253              :          is useless.  */
     254       306237 :       if (TYPE_ARG_TYPES (outer_type) == TYPE_ARG_TYPES (inner_type))
     255              :         return true;
     256              : 
     257       301779 :       for (outer_parm = TYPE_ARG_TYPES (outer_type),
     258       301779 :            inner_parm = TYPE_ARG_TYPES (inner_type);
     259      1258481 :            outer_parm && inner_parm;
     260       956702 :            outer_parm = TREE_CHAIN (outer_parm),
     261       956702 :            inner_parm = TREE_CHAIN (inner_parm))
     262      1919314 :         if (!useless_type_conversion_p
     263       959657 :                (TYPE_MAIN_VARIANT (TREE_VALUE (outer_parm)),
     264       959657 :                 TYPE_MAIN_VARIANT (TREE_VALUE (inner_parm))))
     265              :           return false;
     266              : 
     267              :       /* If there is a mismatch in the number of arguments the functions
     268              :          are not compatible.  */
     269       298824 :       if (outer_parm || inner_parm)
     270              :         return false;
     271              : 
     272              :       /* Defer to the target if necessary.  */
     273       297199 :       if (TYPE_ATTRIBUTES (inner_type) || TYPE_ATTRIBUTES (outer_type))
     274       286504 :         return comp_type_attributes (outer_type, inner_type) != 0;
     275              : 
     276              :       return true;
     277              :     }
     278              : 
     279              :   /* For aggregates we rely on TYPE_CANONICAL exclusively and require
     280              :      explicit conversions for types involving to be structurally
     281              :      compared types.  */
     282     36546219 :   else if (AGGREGATE_TYPE_P (inner_type)
     283      3387472 :            && TREE_CODE (inner_type) == TREE_CODE (outer_type))
     284      2355348 :     return TYPE_CANONICAL (inner_type)
     285      2355348 :            && TYPE_CANONICAL (inner_type) == TYPE_CANONICAL (outer_type);
     286              : 
     287     34190871 :   else if (TREE_CODE (inner_type) == OFFSET_TYPE
     288         9904 :            && TREE_CODE (outer_type) == OFFSET_TYPE)
     289         2550 :     return useless_type_conversion_p (TREE_TYPE (outer_type),
     290         2550 :                                       TREE_TYPE (inner_type))
     291         4920 :            && useless_type_conversion_p
     292         2370 :                 (TYPE_OFFSET_BASETYPE (outer_type),
     293         2370 :                  TYPE_OFFSET_BASETYPE (inner_type));
     294              : 
     295              :   return false;
     296              : }
     297              : 
     298              : 
     299              : /* ----- Decl related -----  */
     300              : 
     301              : /* Set sequence SEQ to be the GIMPLE body for function FN.  */
     302              : 
     303              : void
     304    117711076 : gimple_set_body (tree fndecl, gimple_seq seq)
     305              : {
     306    117711076 :   struct function *fn = DECL_STRUCT_FUNCTION (fndecl);
     307    117711076 :   if (fn == NULL)
     308              :     {
     309              :       /* If FNDECL still does not have a function structure associated
     310              :          with it, then it does not make sense for it to receive a
     311              :          GIMPLE body.  */
     312           62 :       gcc_assert (seq == NULL);
     313              :     }
     314              :   else
     315    117711014 :     fn->gimple_body = seq;
     316    117711076 : }
     317              : 
     318              : 
     319              : /* Return the body of GIMPLE statements for function FN.  After the
     320              :    CFG pass, the function body doesn't exist anymore because it has
     321              :    been split up into basic blocks.  In this case, it returns
     322              :    NULL.  */
     323              : 
     324              : gimple_seq
     325    435155754 : gimple_body (tree fndecl)
     326              : {
     327    435155754 :   struct function *fn = DECL_STRUCT_FUNCTION (fndecl);
     328    435155754 :   return fn ? fn->gimple_body : NULL;
     329              : }
     330              : 
     331              : /* Return true when FNDECL has Gimple body either in unlowered
     332              :    or CFG form.  */
     333              : bool
     334    399505607 : gimple_has_body_p (tree fndecl)
     335              : {
     336    399505607 :   struct function *fn = DECL_STRUCT_FUNCTION (fndecl);
     337    399505607 :   return (gimple_body (fndecl) || (fn && fn->cfg && !(fn->curr_properties & PROP_rtl)));
     338              : }
     339              : 
     340              : /* Return a printable name for symbol DECL.  */
     341              : 
     342              : const char *
     343        33901 : gimple_decl_printable_name (tree decl, int verbosity)
     344              : {
     345        33901 :   if (!DECL_NAME (decl))
     346              :     return NULL;
     347              : 
     348        33901 :   if (HAS_DECL_ASSEMBLER_NAME_P (decl) && DECL_ASSEMBLER_NAME_SET_P (decl))
     349              :     {
     350        33540 :       int dmgl_opts = DMGL_NO_OPTS;
     351              : 
     352        33540 :       if (verbosity >= 2)
     353              :         {
     354         4509 :           dmgl_opts = DMGL_VERBOSE
     355              :                       | DMGL_ANSI
     356              :                       | DMGL_GNU_V3
     357              :                       | DMGL_RET_POSTFIX;
     358         4509 :           if (TREE_CODE (decl) == FUNCTION_DECL)
     359         4436 :             dmgl_opts |= DMGL_PARAMS;
     360              :         }
     361              : 
     362        33540 :       const char *mangled_str
     363        33540 :         = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME_RAW (decl));
     364        33540 :       const char *str = cplus_demangle_v3 (mangled_str, dmgl_opts);
     365        65672 :       return str ? str : mangled_str;
     366              :     }
     367              : 
     368          361 :   return IDENTIFIER_POINTER (DECL_NAME (decl));
     369              : }
     370              : 
     371              : 
     372              : /* Create a new VAR_DECL and copy information from VAR to it.  */
     373              : 
     374              : tree
     375      1515169 : copy_var_decl (tree var, tree name, tree type)
     376              : {
     377      1515169 :   tree copy = build_decl (DECL_SOURCE_LOCATION (var), VAR_DECL, name, type);
     378              : 
     379      1515169 :   TREE_ADDRESSABLE (copy) = TREE_ADDRESSABLE (var);
     380      1515169 :   TREE_THIS_VOLATILE (copy) = TREE_THIS_VOLATILE (var);
     381      1515169 :   DECL_NOT_GIMPLE_REG_P (copy) = DECL_NOT_GIMPLE_REG_P (var);
     382      1515169 :   DECL_ARTIFICIAL (copy) = DECL_ARTIFICIAL (var);
     383      1515169 :   DECL_IGNORED_P (copy) = DECL_IGNORED_P (var);
     384      1515169 :   DECL_CONTEXT (copy) = DECL_CONTEXT (var);
     385      1515169 :   TREE_USED (copy) = 1;
     386      1515169 :   DECL_SEEN_IN_BIND_EXPR_P (copy) = 1;
     387      1515169 :   DECL_ATTRIBUTES (copy) = DECL_ATTRIBUTES (var);
     388      1515169 :   if (DECL_USER_ALIGN (var))
     389              :     {
     390          145 :       SET_DECL_ALIGN (copy, DECL_ALIGN (var));
     391          145 :       DECL_USER_ALIGN (copy) = 1;
     392              :     }
     393              : 
     394      1515169 :   copy_warning (copy, var);
     395      1515169 :   return copy;
     396              : }
     397              : 
     398              : /* Strip off a legitimate source ending from the input string NAME of
     399              :    length LEN.  Rather than having to know the names used by all of
     400              :    our front ends, we strip off an ending of a period followed by
     401              :    up to four characters.  (like ".cpp".)  */
     402              : 
     403              : static inline void
     404     23770828 : remove_suffix (char *name, int len)
     405              : {
     406     23770828 :   int i;
     407              : 
     408     89861265 :   for (i = 2; i < 7 && len > i; i++)
     409     67236340 :     if (name[len - i] == '.')
     410              :       {
     411      1145903 :         name[len - i] = '\0';
     412      1145903 :         break;
     413              :       }
     414     23770828 : }
     415              : 
     416              : /* Create a new temporary name with PREFIX.  Return an identifier.  */
     417              : 
     418              : static GTY(()) unsigned int tmp_var_id_num;
     419              : 
     420              : tree
     421     23770828 : create_tmp_var_name (const char *prefix)
     422              : {
     423     23770828 :   char *tmp_name;
     424              : 
     425     23770828 :   if (prefix)
     426              :     {
     427     23770828 :       char *preftmp = ASTRDUP (prefix);
     428              : 
     429     23770828 :       remove_suffix (preftmp, strlen (preftmp));
     430     23770828 :       prefix = preftmp;
     431              :     }
     432              : 
     433     23770828 :   ASM_FORMAT_PRIVATE_NAME (tmp_name, prefix ? prefix : "T", tmp_var_id_num++);
     434     23770828 :   return get_identifier (tmp_name);
     435              : }
     436              : 
     437              : /* Create a new temporary variable declaration of type TYPE.
     438              :    Do NOT push it into the current binding.  */
     439              : 
     440              : tree
     441     27080317 : create_tmp_var_raw (tree type, const char *prefix)
     442              : {
     443     27080317 :   tree tmp_var;
     444              : 
     445     47202145 :   tmp_var = build_decl (input_location,
     446     20121828 :                         VAR_DECL, prefix ? create_tmp_var_name (prefix) : NULL,
     447              :                         type);
     448              : 
     449              :   /* The variable was declared by the compiler.  */
     450     27080317 :   DECL_ARTIFICIAL (tmp_var) = 1;
     451              :   /* And we don't want debug info for it.  */
     452     27080317 :   DECL_IGNORED_P (tmp_var) = 1;
     453              :   /* And we don't want even the fancy names of those printed in
     454              :      -fdump-final-insns= dumps.  */
     455     27080317 :   DECL_NAMELESS (tmp_var) = 1;
     456              : 
     457              :   /* Make the variable writable.  */
     458     27080317 :   TREE_READONLY (tmp_var) = 0;
     459              : 
     460     27080317 :   DECL_EXTERNAL (tmp_var) = 0;
     461     27080317 :   TREE_STATIC (tmp_var) = 0;
     462     27080317 :   TREE_USED (tmp_var) = 1;
     463              : 
     464     27080317 :   return tmp_var;
     465              : }
     466              : 
     467              : /* Create a new temporary variable declaration of type TYPE.  DO push the
     468              :    variable into the current binding.  Further, assume that this is called
     469              :    only from gimplification or optimization, at which point the creation of
     470              :    certain types are bugs.  */
     471              : 
     472              : tree
     473     15030491 : create_tmp_var (tree type, const char *prefix)
     474              : {
     475     15030491 :   tree tmp_var;
     476              : 
     477              :   /* We don't allow types that are addressable (meaning we can't make copies),
     478              :      or incomplete.  We also used to reject every variable size objects here,
     479              :      but now support those for which a constant upper bound can be obtained.
     480              :      The processing for variable sizes is performed in gimple_add_tmp_var,
     481              :      point at which it really matters and possibly reached via paths not going
     482              :      through this function, e.g. after direct calls to create_tmp_var_raw.  */
     483     15030491 :   gcc_assert (!TREE_ADDRESSABLE (type) && COMPLETE_TYPE_P (type));
     484              : 
     485     15030491 :   tmp_var = create_tmp_var_raw (type, prefix);
     486     15030491 :   gimple_add_tmp_var (tmp_var);
     487     15030491 :   return tmp_var;
     488              : }
     489              : 
     490              : /* Create a new temporary variable declaration of type TYPE by calling
     491              :    create_tmp_var and if TYPE is a vector or a complex number, mark the new
     492              :    temporary as gimple register.  */
     493              : 
     494              : tree
     495      3556293 : create_tmp_reg (tree type, const char *prefix)
     496              : {
     497      3556293 :   return create_tmp_var (type, prefix);
     498              : }
     499              : 
     500              : /* Create a new temporary variable declaration of type TYPE by calling
     501              :    create_tmp_var and if TYPE is a vector or a complex number, mark the new
     502              :    temporary as gimple register.  */
     503              : 
     504              : tree
     505        23810 : create_tmp_reg_fn (struct function *fn, tree type, const char *prefix)
     506              : {
     507        23810 :   tree tmp;
     508              : 
     509        23810 :   tmp = create_tmp_var_raw (type, prefix);
     510        23810 :   gimple_add_tmp_var_fn (fn, tmp);
     511              : 
     512        23810 :   return tmp;
     513              : }
     514              : 
     515              : 
     516              : /* ----- Expression related -----  */
     517              : 
     518              : /* Extract the operands and code for expression EXPR into *SUBCODE_P,
     519              :    *OP1_P, *OP2_P and *OP3_P respectively.  */
     520              : 
     521              : void
     522    175263667 : extract_ops_from_tree (tree expr, enum tree_code *subcode_p, tree *op1_p,
     523              :                        tree *op2_p, tree *op3_p)
     524              : {
     525    175263667 :   *subcode_p = TREE_CODE (expr);
     526    175263667 :   switch (get_gimple_rhs_class (*subcode_p))
     527              :     {
     528       105699 :     case GIMPLE_TERNARY_RHS:
     529       105699 :       {
     530       105699 :         *op1_p = TREE_OPERAND (expr, 0);
     531       105699 :         *op2_p = TREE_OPERAND (expr, 1);
     532       105699 :         *op3_p = TREE_OPERAND (expr, 2);
     533       105699 :         break;
     534              :       }
     535     21186316 :     case GIMPLE_BINARY_RHS:
     536     21186316 :       {
     537     21186316 :         *op1_p = TREE_OPERAND (expr, 0);
     538     21186316 :         *op2_p = TREE_OPERAND (expr, 1);
     539     21186316 :         *op3_p = NULL_TREE;
     540     21186316 :         break;
     541              :       }
     542     11622648 :     case GIMPLE_UNARY_RHS:
     543     11622648 :       {
     544     11622648 :         *op1_p = TREE_OPERAND (expr, 0);
     545     11622648 :         *op2_p = NULL_TREE;
     546     11622648 :         *op3_p = NULL_TREE;
     547     11622648 :         break;
     548              :       }
     549    142349004 :     case GIMPLE_SINGLE_RHS:
     550    142349004 :       {
     551    142349004 :         *op1_p = expr;
     552    142349004 :         *op2_p = NULL_TREE;
     553    142349004 :         *op3_p = NULL_TREE;
     554    142349004 :         break;
     555              :       }
     556            0 :     default:
     557            0 :       gcc_unreachable ();
     558              :     }
     559    175263667 : }
     560              : 
     561              : /* Extract operands for a GIMPLE_COND statement out of COND_EXPR tree COND.  */
     562              : 
     563              : void
     564      6051427 : gimple_cond_get_ops_from_tree (tree cond, enum tree_code *code_p,
     565              :                                tree *lhs_p, tree *rhs_p)
     566              : {
     567      6051427 :   gcc_assert (COMPARISON_CLASS_P (cond)
     568              :               || TREE_CODE (cond) == TRUTH_NOT_EXPR
     569              :               || is_gimple_min_invariant (cond)
     570              :               || SSA_VAR_P (cond));
     571      6051427 :   gcc_checking_assert (!tree_could_throw_p (cond));
     572              : 
     573      6051427 :   extract_ops_from_tree (cond, code_p, lhs_p, rhs_p);
     574              : 
     575              :   /* Canonicalize conditionals of the form 'if (!VAL)'.  */
     576      6051427 :   if (*code_p == TRUTH_NOT_EXPR)
     577              :     {
     578            0 :       *code_p = EQ_EXPR;
     579            0 :       gcc_assert (*lhs_p && *rhs_p == NULL_TREE);
     580            0 :       *rhs_p = build_zero_cst (TREE_TYPE (*lhs_p));
     581              :     }
     582              :   /* Canonicalize conditionals of the form 'if (VAL)'  */
     583      6051427 :   else if (TREE_CODE_CLASS (*code_p) != tcc_comparison)
     584              :     {
     585      1814425 :       *code_p = NE_EXPR;
     586      1814425 :       gcc_assert (*lhs_p && *rhs_p == NULL_TREE);
     587      1814425 :       *rhs_p = build_zero_cst (TREE_TYPE (*lhs_p));
     588              :     }
     589      6051427 : }
     590              : 
     591              : /*  Return true if T is a valid LHS for a GIMPLE assignment expression.  */
     592              : 
     593              : bool
     594    256122018 : is_gimple_lvalue (tree t)
     595              : {
     596    256122018 :   return (is_gimple_addressable (t)
     597     14252057 :           || TREE_CODE (t) == WITH_SIZE_EXPR
     598              :           /* These are complex lvalues, but don't have addresses, so they
     599              :              go here.  */
     600    270349975 :           || TREE_CODE (t) == BIT_FIELD_REF);
     601              : }
     602              : 
     603              : /* Helper for is_gimple_condexpr and is_gimple_condexpr_for_cond.  */
     604              : 
     605              : static bool
     606     10175274 : is_gimple_condexpr_1 (tree t, bool allow_traps, bool allow_cplx)
     607              : {
     608     10175274 :   tree op0;
     609     10175274 :   return (is_gimple_val (t)
     610     10175274 :           || (COMPARISON_CLASS_P (t)
     611      7010278 :               && (allow_traps || !tree_could_throw_p (t))
     612      7003402 :               && ((op0 = TREE_OPERAND (t, 0)), true)
     613      7003402 :               && (allow_cplx || TREE_CODE (TREE_TYPE (op0)) != COMPLEX_TYPE)
     614      7003402 :               && is_gimple_val (op0)
     615      5436667 :               && is_gimple_val (TREE_OPERAND (t, 1))));
     616              : }
     617              : 
     618              : /* Like is_gimple_condexpr, but does not allow T to trap.  */
     619              : 
     620              : bool
     621      6550650 : is_gimple_condexpr_for_cond (tree t)
     622              : {
     623      6550650 :   return is_gimple_condexpr_1 (t, false, true);
     624              : }
     625              : 
     626              : /* Canonicalize a tree T for use in a COND_EXPR as conditional.  Returns
     627              :    a canonicalized tree that is valid for a COND_EXPR or NULL_TREE, if
     628              :    we failed to create one.  */
     629              : 
     630              : tree
     631      3624624 : canonicalize_cond_expr_cond (tree t)
     632              : {
     633              :   /* Strip conversions around boolean operations.  */
     634      3473798 :   if (CONVERT_EXPR_P (t)
     635      3624624 :       && (truth_value_p (TREE_CODE (TREE_OPERAND (t, 0)))
     636       149704 :           || TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0)))
     637              :              == BOOLEAN_TYPE))
     638         1126 :     t = TREE_OPERAND (t, 0);
     639              : 
     640              :   /* For !x use x == 0.  */
     641      3624624 :   if (TREE_CODE (t) == TRUTH_NOT_EXPR)
     642              :     {
     643        22490 :       tree top0 = TREE_OPERAND (t, 0);
     644        22490 :       t = build2 (EQ_EXPR, TREE_TYPE (t),
     645        22490 :                   top0, build_int_cst (TREE_TYPE (top0), 0));
     646              :     }
     647              :   /* For cmp ? 1 : 0 use cmp.  */
     648      3602134 :   else if (TREE_CODE (t) == COND_EXPR
     649       101009 :            && COMPARISON_CLASS_P (TREE_OPERAND (t, 0))
     650        99295 :            && integer_onep (TREE_OPERAND (t, 1))
     651      3701429 :            && integer_zerop (TREE_OPERAND (t, 2)))
     652              :     {
     653        99295 :       tree top0 = TREE_OPERAND (t, 0);
     654        99295 :       t = build2 (TREE_CODE (top0), TREE_TYPE (t),
     655        99295 :                   TREE_OPERAND (top0, 0), TREE_OPERAND (top0, 1));
     656              :     }
     657              :   /* For x ^ y use x != y.  */
     658      3502839 :   else if (TREE_CODE (t) == BIT_XOR_EXPR)
     659            0 :     t = build2 (NE_EXPR, TREE_TYPE (t),
     660            0 :                 TREE_OPERAND (t, 0), TREE_OPERAND (t, 1));
     661              : 
     662              :   /* We don't know where this will be used so allow both traps and
     663              :      _Complex.  The caller is responsible for more precise checking.  */
     664      3624624 :   if (is_gimple_condexpr_1 (t, true, true))
     665      1274924 :     return t;
     666              : 
     667              :   return NULL_TREE;
     668              : }
     669              : 
     670              : /* Return true if T is a gimple address.  */
     671              : 
     672              : bool
     673            0 : is_gimple_address (const_tree t)
     674              : {
     675            0 :   tree op;
     676              : 
     677            0 :   if (TREE_CODE (t) != ADDR_EXPR)
     678              :     return false;
     679              : 
     680            0 :   op = TREE_OPERAND (t, 0);
     681            0 :   while (handled_component_p (op))
     682              :     {
     683            0 :       if ((TREE_CODE (op) == ARRAY_REF
     684            0 :            || TREE_CODE (op) == ARRAY_RANGE_REF)
     685            0 :           && !is_gimple_val (TREE_OPERAND (op, 1)))
     686              :             return false;
     687              : 
     688            0 :       op = TREE_OPERAND (op, 0);
     689              :     }
     690              : 
     691            0 :   if (CONSTANT_CLASS_P (op)
     692            0 :       || TREE_CODE (op) == TARGET_MEM_REF
     693            0 :       || TREE_CODE (op) == MEM_REF)
     694              :     return true;
     695              : 
     696            0 :   switch (TREE_CODE (op))
     697              :     {
     698              :     case PARM_DECL:
     699              :     case RESULT_DECL:
     700              :     case LABEL_DECL:
     701              :     case FUNCTION_DECL:
     702              :     case VAR_DECL:
     703              :     case CONST_DECL:
     704              :       return true;
     705              : 
     706              :     default:
     707              :       return false;
     708              :     }
     709              : }
     710              : 
     711              : /* Return true if T is a gimple invariant address.  */
     712              : 
     713              : bool
     714   5757954045 : is_gimple_invariant_address (const_tree t)
     715              : {
     716   5757954045 :   const_tree op;
     717              : 
     718   5757954045 :   if (TREE_CODE (t) != ADDR_EXPR)
     719              :     return false;
     720              : 
     721   5757954045 :   op = strip_invariant_refs (TREE_OPERAND (t, 0));
     722   5757954045 :   if (!op)
     723              :     return false;
     724              : 
     725   5745814724 :   if (TREE_CODE (op) == MEM_REF)
     726              :     {
     727    461211390 :       const_tree op0 = TREE_OPERAND (op, 0);
     728    461211390 :       return (TREE_CODE (op0) == ADDR_EXPR
     729    461211390 :               && (CONSTANT_CLASS_P (TREE_OPERAND (op0, 0))
     730    156430258 :                   || decl_address_invariant_p (TREE_OPERAND (op0, 0))));
     731              :     }
     732              : 
     733   5284603334 :   return CONSTANT_CLASS_P (op) || decl_address_invariant_p (op);
     734              : }
     735              : 
     736              : /* Return true if T is a gimple invariant address at IPA level
     737              :    (so addresses of variables on stack are not allowed).  */
     738              : 
     739              : bool
     740      2381455 : is_gimple_ip_invariant_address (const_tree t)
     741              : {
     742      2381455 :   const_tree op;
     743              : 
     744      2381455 :   if (TREE_CODE (t) != ADDR_EXPR)
     745              :     return false;
     746              : 
     747      2381455 :   op = strip_invariant_refs (TREE_OPERAND (t, 0));
     748      2381455 :   if (!op)
     749              :     return false;
     750              : 
     751      2380040 :   if (TREE_CODE (op) == MEM_REF)
     752              :     {
     753       116594 :       const_tree op0 = TREE_OPERAND (op, 0);
     754       116594 :       return (TREE_CODE (op0) == ADDR_EXPR
     755       116594 :               && (CONSTANT_CLASS_P (TREE_OPERAND (op0, 0))
     756        87961 :                   || decl_address_ip_invariant_p (TREE_OPERAND (op0, 0))));
     757              :     }
     758              : 
     759      2263446 :   return CONSTANT_CLASS_P (op) || decl_address_ip_invariant_p (op);
     760              : }
     761              : 
     762              : /* Return true if T is a GIMPLE minimal invariant.  It's a restricted
     763              :    form of function invariant.  */
     764              : 
     765              : bool
     766  22277261417 : is_gimple_min_invariant (const_tree t)
     767              : {
     768  22277261417 :   if (TREE_CODE (t) == ADDR_EXPR)
     769   5756728133 :     return is_gimple_invariant_address (t);
     770              : 
     771  16520533284 :   return is_gimple_constant (t);
     772              : }
     773              : 
     774              : /* Return true if T is a GIMPLE interprocedural invariant.  It's a restricted
     775              :    form of gimple minimal invariant.  */
     776              : 
     777              : bool
     778     25805114 : is_gimple_ip_invariant (const_tree t)
     779              : {
     780     25805114 :   if (TREE_CODE (t) == ADDR_EXPR)
     781      2380267 :     return is_gimple_ip_invariant_address (t);
     782              : 
     783     23424847 :   return is_gimple_constant (t);
     784              : }
     785              : 
     786              : /* Return true if T is a non-aggregate register variable.  */
     787              : 
     788              : bool
     789  44332736111 : is_gimple_reg (tree t)
     790              : {
     791  77353840148 :   if (virtual_operand_p (t))
     792              :     return false;
     793              : 
     794  44184963428 :   if (TREE_CODE (t) == SSA_NAME)
     795              :     return true;
     796              : 
     797  16367929132 :   if (!is_gimple_variable (t))
     798              :     return false;
     799              : 
     800   5574724606 :   if (!is_gimple_reg_type (TREE_TYPE (t)))
     801              :     return false;
     802              : 
     803              :   /* A volatile decl is not acceptable because we can't reuse it as
     804              :      needed.  We need to copy it into a temp first.  */
     805   2206985115 :   if (TREE_THIS_VOLATILE (t))
     806              :     return false;
     807              : 
     808              :   /* We define "registers" as things that can be renamed as needed,
     809              :      which with our infrastructure does not apply to memory.  */
     810   1964941003 :   if (needs_to_live_in_memory (t))
     811              :     return false;
     812              : 
     813              :   /* Hard register variables are an interesting case.  For those that
     814              :      are call-clobbered, we don't know where all the calls are, since
     815              :      we don't (want to) take into account which operations will turn
     816              :      into libcalls at the rtl level.  For those that are call-saved,
     817              :      we don't currently model the fact that calls may in fact change
     818              :      global hard registers, nor do we examine ASM_CLOBBERS at the tree
     819              :      level, and so miss variable changes that might imply.  All around,
     820              :      it seems safest to not do too much optimization with these at the
     821              :      tree level at all.  We'll have to rely on the rtl optimizers to
     822              :      clean this up, as there we've got all the appropriate bits exposed.  */
     823   1153273745 :   if (VAR_P (t) && DECL_HARD_REGISTER (t))
     824              :     return false;
     825              : 
     826              :   /* Variables can be marked as having partial definitions, avoid
     827              :      putting them into SSA form.  */
     828   1151823742 :   return !DECL_NOT_GIMPLE_REG_P (t);
     829              : }
     830              : 
     831              : 
     832              : /* Return true if T is a GIMPLE rvalue, i.e. an identifier or a constant.  */
     833              : 
     834              : bool
     835   9009386355 : is_gimple_val (tree t)
     836              : {
     837              :   /* Make loads from volatiles and memory vars explicit.  */
     838   9009386355 :   if (is_gimple_variable (t)
     839   4798268416 :       && is_gimple_reg_type (TREE_TYPE (t))
     840  13783599080 :       && !is_gimple_reg (t))
     841              :     return false;
     842              : 
     843              :   /* These eventually expand into constants, so treat them like that.  */
     844   8998991217 :   if (TREE_CODE (t) == OMP_NEXT_VARIANT
     845   8998991217 :       || TREE_CODE (t) == OMP_TARGET_DEVICE_MATCHES)
     846              :     return true;
     847              : 
     848   8998991165 :   return (is_gimple_variable (t) || is_gimple_min_invariant (t));
     849              : }
     850              : 
     851              : /* Similarly, but accept hard registers as inputs to asm statements.  */
     852              : 
     853              : bool
     854        43385 : is_gimple_asm_val (tree t)
     855              : {
     856        43385 :   if (VAR_P (t) && DECL_HARD_REGISTER (t))
     857              :     return true;
     858              : 
     859        42508 :   return is_gimple_val (t);
     860              : }
     861              : 
     862              : /* Return true if T is a GIMPLE minimal lvalue.  */
     863              : 
     864              : bool
     865     30147065 : is_gimple_min_lval (tree t)
     866              : {
     867     30147065 :   if (!(t = const_cast<tree> (strip_invariant_refs (t))))
     868              :     return false;
     869     30147050 :   return (is_gimple_id (t) || TREE_CODE (t) == MEM_REF);
     870              : }
     871              : 
     872              : /* Return true if T is a valid function operand of a CALL_EXPR.  */
     873              : 
     874              : bool
     875   1043625562 : is_gimple_call_addr (tree t)
     876              : {
     877   1043625562 :   return (TREE_CODE (t) == OBJ_TYPE_REF || is_gimple_val (t));
     878              : }
     879              : 
     880              : /* Return true if T is a valid address operand of a MEM_REF.  */
     881              : 
     882              : bool
     883   1394550189 : is_gimple_mem_ref_addr (tree t)
     884              : {
     885   1394550189 :   return (is_gimple_reg (t)
     886    383119281 :           || poly_int_tree_p (t)
     887   1777279934 :           || (TREE_CODE (t) == ADDR_EXPR
     888    380442886 :               && (CONSTANT_CLASS_P (TREE_OPERAND (t, 0))
     889    378619686 :                   || decl_address_invariant_p (TREE_OPERAND (t, 0)))));
     890              : }
     891              : 
     892              : /* Hold trees marked addressable during expand.  */
     893              : 
     894              : static hash_set<tree> *mark_addressable_queue;
     895              : 
     896              : /* Mark X as addressable or queue it up if called during expand.  We
     897              :    don't want to apply it immediately during expand because decls are
     898              :    made addressable at that point due to RTL-only concerns, such as
     899              :    uses of memcpy for block moves, and TREE_ADDRESSABLE changes
     900              :    is_gimple_reg, which might make it seem like a variable that used
     901              :    to be a gimple_reg shouldn't have been an SSA name.  So we queue up
     902              :    this flag setting and only apply it when we're done with GIMPLE and
     903              :    only RTL issues matter.  */
     904              : 
     905              : static void
     906     10900900 : mark_addressable_1 (tree x)
     907              : {
     908     10900900 :   if (!currently_expanding_to_rtl)
     909              :     {
     910     10840671 :       TREE_ADDRESSABLE (x) = 1;
     911     10840671 :       return;
     912              :     }
     913              : 
     914        60229 :   if (!mark_addressable_queue)
     915        14748 :     mark_addressable_queue = new hash_set<tree>();
     916        60229 :   mark_addressable_queue->add (x);
     917              : }
     918              : 
     919              : /* Adaptor for mark_addressable_1 for use in hash_set traversal.  */
     920              : 
     921              : static bool
     922        36939 : mark_addressable_2 (tree const &x, void * ATTRIBUTE_UNUSED = NULL)
     923              : {
     924        36939 :   mark_addressable_1 (x);
     925        36939 :   return false;
     926              : }
     927              : 
     928              : /* Mark all queued trees as addressable, and empty the queue.  To be
     929              :    called right after clearing CURRENTLY_EXPANDING_TO_RTL.  */
     930              : 
     931              : void
     932      1482261 : flush_mark_addressable_queue ()
     933              : {
     934      1482261 :   gcc_assert (!currently_expanding_to_rtl);
     935      1482261 :   if (mark_addressable_queue)
     936              :     {
     937        51687 :       mark_addressable_queue->traverse<void*, mark_addressable_2> (NULL);
     938        29496 :       delete mark_addressable_queue;
     939        14748 :       mark_addressable_queue = NULL;
     940              :     }
     941      1482261 : }
     942              : 
     943              : /* Mark X addressable.  Unlike the langhook we expect X to be in gimple
     944              :    form and we don't do any syntax checking.  */
     945              : 
     946              : void
     947     33308079 : mark_addressable (tree x)
     948              : {
     949     33308079 :   if (TREE_CODE (x) == WITH_SIZE_EXPR)
     950            0 :     x = TREE_OPERAND (x, 0);
     951     38639392 :   while (handled_component_p (x))
     952      5331313 :     x = TREE_OPERAND (x, 0);
     953     33308079 :   if ((TREE_CODE (x) == MEM_REF
     954     33308079 :        || TREE_CODE (x) == TARGET_MEM_REF)
     955     33308079 :       && TREE_CODE (TREE_OPERAND (x, 0)) == ADDR_EXPR)
     956        11010 :     x = TREE_OPERAND (TREE_OPERAND (x, 0), 0);
     957     33308079 :   if (!VAR_P (x)
     958              :       && TREE_CODE (x) != PARM_DECL
     959              :       && TREE_CODE (x) != RESULT_DECL)
     960              :     return;
     961     10855674 :   mark_addressable_1 (x);
     962              : 
     963              :   /* Also mark the artificial SSA_NAME that points to the partition of X.  */
     964     10855674 :   if (VAR_P (x)
     965     10257258 :       && !DECL_EXTERNAL (x)
     966      9114086 :       && !TREE_STATIC (x)
     967      5774613 :       && cfun->gimple_df != NULL
     968     16630287 :       && cfun->gimple_df->decls_to_pointers != NULL)
     969              :     {
     970        14354 :       tree *namep = cfun->gimple_df->decls_to_pointers->get (x);
     971        14354 :       if (namep)
     972         8287 :         mark_addressable_1 (*namep);
     973              :     }
     974              : }
     975              : 
     976              : /* Returns true iff T is a valid RHS for an assignment to a renamed
     977              :    user -- or front-end generated artificial -- variable.  */
     978              : 
     979              : bool
     980       812657 : is_gimple_reg_rhs (tree t)
     981              : {
     982       812657 :   return get_gimple_rhs_class (TREE_CODE (t)) != GIMPLE_INVALID_RHS;
     983              : }
     984              : 
     985              : #include "gt-gimple-expr.h"
        

Generated by: LCOV version 2.4-beta

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.