LCOV - code coverage report
Current view: top level - gcc - gimple-expr.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 93.3 % 374 349
Test Date: 2026-10-17 16:30:31 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 "attribs.h"
      39              : #include "target.h"
      40              : 
      41              : /* ----- Type related -----  */
      42              : 
      43              : /* Return true if the conversion from INNER_TYPE to OUTER_TYPE is a
      44              :    useless type conversion, otherwise return false.
      45              : 
      46              :    This function implicitly defines the middle-end type system.  With
      47              :    the notion of 'a < b' meaning that useless_type_conversion_p (a, b)
      48              :    holds and 'a > b' meaning that useless_type_conversion_p (b, a) holds,
      49              :    the following invariants shall be fulfilled:
      50              : 
      51              :      1) useless_type_conversion_p is transitive.
      52              :         If a < b and b < c then a < c.
      53              : 
      54              :      2) useless_type_conversion_p is not symmetric.
      55              :         From a < b does not follow a > b.
      56              : 
      57              :      3) Types define the available set of operations applicable to values.
      58              :         A type conversion is useless if the operations for the target type
      59              :         is a subset of the operations for the source type.  For example
      60              :         casts to void* are useless, casts from void* are not (void* can't
      61              :         be dereferenced or offsetted, but copied, hence its set of operations
      62              :         is a strict subset of that of all other data pointer types).  Casts
      63              :         to const T* are useless (can't be written to), casts from const T*
      64              :         to T* are not.  */
      65              : 
      66              : bool
      67  12333836887 : useless_type_conversion_p (tree outer_type, tree inner_type)
      68              : {
      69              :   /* Do the following before stripping toplevel qualifiers.  */
      70  12334203296 :   if (POINTER_TYPE_P (inner_type)
      71   3112079462 :       && POINTER_TYPE_P (outer_type))
      72              :     {
      73              :       /* Do not lose casts between pointers to different address spaces.  */
      74   3087195052 :       if (TYPE_ADDR_SPACE (TREE_TYPE (outer_type))
      75   3087195052 :           != TYPE_ADDR_SPACE (TREE_TYPE (inner_type)))
      76              :         return false;
      77              :       /* Do not lose casts to function pointer types.  */
      78   6095968066 :       if (FUNC_OR_METHOD_TYPE_P (TREE_TYPE (outer_type))
      79   3094927969 :           && !FUNC_OR_METHOD_TYPE_P (TREE_TYPE (inner_type)))
      80              :         return false;
      81              :     }
      82              : 
      83              :   /* From now on qualifiers on value types do not matter.  */
      84  12332388319 :   inner_type = TYPE_MAIN_VARIANT (inner_type);
      85  12332388319 :   outer_type = TYPE_MAIN_VARIANT (outer_type);
      86              : 
      87  12332388319 :   if (inner_type == outer_type)
      88              :     return true;
      89              : 
      90              :   /* Changes in machine mode are never useless conversions because the RTL
      91              :      middle-end expects explicit conversions between modes.  */
      92   1109172678 :   if (TYPE_MODE (inner_type) != TYPE_MODE (outer_type))
      93              :     return false;
      94              : 
      95              :   /* If both the inner and outer types are integral types, then the
      96              :      conversion is not necessary if they have the same mode and
      97              :      signedness and precision, and both or neither are boolean.  */
      98    997039868 :   if (INTEGRAL_TYPE_P (inner_type)
      99    182308905 :       && INTEGRAL_TYPE_P (outer_type))
     100              :     {
     101              :       /* Preserve changes in signedness or precision.  */
     102    167111893 :       if (TYPE_UNSIGNED (inner_type) != TYPE_UNSIGNED (outer_type)
     103    167111893 :           || TYPE_PRECISION (inner_type) != TYPE_PRECISION (outer_type))
     104              :         return false;
     105              : 
     106              :       /* Preserve conversions to/from BOOLEAN_TYPE if types are not
     107              :          of precision one.  */
     108     67872383 :       if (((TREE_CODE (inner_type) == BOOLEAN_TYPE)
     109     67872383 :            != (TREE_CODE (outer_type) == BOOLEAN_TYPE))
     110     67872383 :           && TYPE_PRECISION (outer_type) != 1)
     111              :         return false;
     112              : 
     113              :       /* Preserve conversions to/from BITINT_TYPE.  While we don't
     114              :          need to care that much about such conversions within a function's
     115              :          body, we need to prevent changing BITINT_TYPE to INTEGER_TYPE
     116              :          of the same precision or vice versa when passed to functions,
     117              :          especially for varargs.  */
     118     67819503 :       if (BITINT_TYPE_P (inner_type) != BITINT_TYPE_P (outer_type))
     119              :         return false;
     120              : 
     121              :       /* We don't need to preserve changes in the types minimum or
     122              :          maximum value in general as these do not generate code
     123              :          unless the types precisions are different.  */
     124              :       return true;
     125              :     }
     126              : 
     127              :   /* Scalar floating point types with the same mode are compatible.  */
     128    829927975 :   else if (SCALAR_FLOAT_TYPE_P (inner_type)
     129       606011 :            && SCALAR_FLOAT_TYPE_P (outer_type))
     130              :     return true;
     131              : 
     132              :   /* Fixed point types with the same mode are compatible.  */
     133    829325920 :   else if (FIXED_POINT_TYPE_P (inner_type)
     134            0 :            && FIXED_POINT_TYPE_P (outer_type))
     135            0 :     return TYPE_SATURATING (inner_type) == TYPE_SATURATING (outer_type);
     136              : 
     137              :   /* We need to take special care recursing to pointed-to types.  */
     138    829325920 :   else if (POINTER_TYPE_P (inner_type)
     139    799965933 :            && POINTER_TYPE_P (outer_type))
     140              :     {
     141              :       /* We do not care for const qualification of the pointed-to types
     142              :          as const qualification has no semantic value to the middle-end.  */
     143              : 
     144              :       /* Otherwise pointers/references are equivalent.  */
     145              :       return true;
     146              :     }
     147              : 
     148              :   /* Recurse for complex types.  */
     149     47995441 :   else if (TREE_CODE (inner_type) == COMPLEX_TYPE
     150        34897 :            && TREE_CODE (outer_type) == COMPLEX_TYPE)
     151        33374 :     return useless_type_conversion_p (TREE_TYPE (outer_type),
     152        66748 :                                       TREE_TYPE (inner_type));
     153              : 
     154              :   /* Recurse for vector types with the same number of subparts.  */
     155     47962067 :   else if (VECTOR_TYPE_P (inner_type)
     156      9751176 :            && VECTOR_TYPE_P (outer_type))
     157     19416748 :     return (known_eq (TYPE_VECTOR_SUBPARTS (inner_type),
     158              :                       TYPE_VECTOR_SUBPARTS (outer_type))
     159      9701421 :             && useless_type_conversion_p (TREE_TYPE (outer_type),
     160      9701421 :                                           TREE_TYPE (inner_type))
     161     19093505 :             && targetm.compatible_vector_types_p (inner_type, outer_type));
     162              : 
     163     38253693 :   else if (TREE_CODE (inner_type) == ARRAY_TYPE
     164       622092 :            && TREE_CODE (outer_type) == ARRAY_TYPE)
     165              :     {
     166              :       /* Preserve various attributes.  */
     167       459113 :       if (TYPE_REVERSE_STORAGE_ORDER (inner_type)
     168       459113 :           != TYPE_REVERSE_STORAGE_ORDER (outer_type))
     169              :         return false;
     170       459113 :       if (TYPE_STRING_FLAG (inner_type) != TYPE_STRING_FLAG (outer_type))
     171              :         return false;
     172              : 
     173              :       /* Conversions from array types with unknown extent to
     174              :          array types with known extent are not useless.  */
     175       445296 :       if (!TYPE_DOMAIN (inner_type) && TYPE_DOMAIN (outer_type))
     176              :         return false;
     177              : 
     178              :       /* Nor are conversions from array types with non-constant size to
     179              :          array types with constant size or to different size.  */
     180       442878 :       if (TYPE_SIZE (outer_type)
     181       426088 :           && TREE_CODE (TYPE_SIZE (outer_type)) == INTEGER_CST
     182       856390 :           && (!TYPE_SIZE (inner_type)
     183       411770 :               || TREE_CODE (TYPE_SIZE (inner_type)) != INTEGER_CST
     184       409914 :               || !tree_int_cst_equal (TYPE_SIZE (outer_type),
     185       409914 :                                       TYPE_SIZE (inner_type))))
     186              :         return false;
     187              : 
     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       401564 :       if (TYPE_DOMAIN (inner_type)
     194       401562 :           && TYPE_DOMAIN (outer_type)
     195       803112 :           && TYPE_DOMAIN (inner_type) != TYPE_DOMAIN (outer_type))
     196              :         {
     197        84929 :           tree inner_min = TYPE_MIN_VALUE (TYPE_DOMAIN (inner_type));
     198        84929 :           tree outer_min = TYPE_MIN_VALUE (TYPE_DOMAIN (outer_type));
     199        84929 :           tree inner_max = TYPE_MAX_VALUE (TYPE_DOMAIN (inner_type));
     200        84929 :           tree outer_max = TYPE_MAX_VALUE (TYPE_DOMAIN (outer_type));
     201              : 
     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        84929 :           if (inner_min && TREE_CODE (inner_min) != INTEGER_CST)
     206            0 :             inner_min = NULL_TREE;
     207        84929 :           if (outer_min && TREE_CODE (outer_min) != INTEGER_CST)
     208            0 :             outer_min = NULL_TREE;
     209        84929 :           if (inner_max && TREE_CODE (inner_max) != INTEGER_CST)
     210        10740 :             inner_max = NULL_TREE;
     211        84929 :           if (outer_max && TREE_CODE (outer_max) != INTEGER_CST)
     212        15081 :             outer_max = NULL_TREE;
     213              : 
     214              :           /* Conversions NULL / variable <- cst are useless, but not
     215              :              the other way around.  */
     216        84929 :           if (outer_min
     217        84929 :               && (!inner_min
     218        84929 :                   || !tree_int_cst_equal (inner_min, outer_min)))
     219              :             return false;
     220        76077 :           if (outer_max
     221        76077 :               && (!inner_max
     222        60984 :                   || !tree_int_cst_equal (inner_max, outer_max)))
     223              :             return false;
     224              :         }
     225              : 
     226              :       /* Recurse on the element check.  */
     227       333035 :       return useless_type_conversion_p (TREE_TYPE (outer_type),
     228       666070 :                                         TREE_TYPE (inner_type));
     229              :     }
     230              : 
     231     37794580 :   else if (FUNC_OR_METHOD_TYPE_P (inner_type)
     232       331489 :            && TREE_CODE (inner_type) == TREE_CODE (outer_type))
     233              :     {
     234       323202 :       tree outer_parm, inner_parm;
     235              : 
     236              :       /* If the return types are not compatible bail out.  */
     237       323202 :       if (!useless_type_conversion_p (TREE_TYPE (outer_type),
     238       323202 :                                       TREE_TYPE (inner_type)))
     239              :         return false;
     240              : 
     241              :       /* Method types should belong to a compatible base class.  */
     242       314736 :       if (TREE_CODE (inner_type) == METHOD_TYPE
     243       328715 :           && !useless_type_conversion_p (TYPE_METHOD_BASETYPE (outer_type),
     244        13979 :                                          TYPE_METHOD_BASETYPE (inner_type)))
     245              :         return false;
     246              : 
     247              :       /* A conversion to an unprototyped argument list is ok.  */
     248       306231 :       if (!prototype_p (outer_type))
     249              :         return true;
     250              : 
     251              :       /* If the unqualified argument types are compatible the conversion
     252              :          is useless.  */
     253       306154 :       if (TYPE_ARG_TYPES (outer_type) == TYPE_ARG_TYPES (inner_type))
     254              :         return true;
     255              : 
     256       300592 :       for (outer_parm = TYPE_ARG_TYPES (outer_type),
     257       300592 :            inner_parm = TYPE_ARG_TYPES (inner_type);
     258      1246439 :            outer_parm && inner_parm;
     259       945847 :            outer_parm = TREE_CHAIN (outer_parm),
     260       945847 :            inner_parm = TREE_CHAIN (inner_parm))
     261      1900666 :         if (!useless_type_conversion_p
     262       950333 :                (TYPE_MAIN_VARIANT (TREE_VALUE (outer_parm)),
     263       950333 :                 TYPE_MAIN_VARIANT (TREE_VALUE (inner_parm))))
     264              :           return false;
     265              : 
     266              :       /* If there is a mismatch in the number of arguments the functions
     267              :          are not compatible.  */
     268       296106 :       if (outer_parm || inner_parm)
     269              :         return false;
     270              : 
     271              :       /* Defer to the target if necessary.  */
     272       294507 :       if (TYPE_ATTRIBUTES (inner_type) || TYPE_ATTRIBUTES (outer_type))
     273       286242 :         return comp_type_attributes (outer_type, inner_type) != 0;
     274              : 
     275              :       return true;
     276              :     }
     277              : 
     278              :   /* For aggregates we rely on TYPE_CANONICAL exclusively and require
     279              :      explicit conversions for types involving to be structurally
     280              :      compared types.  */
     281     37471378 :   else if (AGGREGATE_TYPE_P (inner_type)
     282      3572386 :            && TREE_CODE (inner_type) == TREE_CODE (outer_type))
     283      2420783 :     return TYPE_CANONICAL (inner_type)
     284      2420783 :            && TYPE_CANONICAL (inner_type) == TYPE_CANONICAL (outer_type);
     285              : 
     286     35050595 :   else if (TREE_CODE (inner_type) == OFFSET_TYPE
     287         9938 :            && TREE_CODE (outer_type) == OFFSET_TYPE)
     288         2648 :     return useless_type_conversion_p (TREE_TYPE (outer_type),
     289         2648 :                                       TREE_TYPE (inner_type))
     290         5116 :            && useless_type_conversion_p
     291         2468 :                 (TYPE_OFFSET_BASETYPE (outer_type),
     292         2468 :                  TYPE_OFFSET_BASETYPE (inner_type));
     293              : 
     294              :   return false;
     295              : }
     296              : 
     297              : 
     298              : /* ----- Decl related -----  */
     299              : 
     300              : /* Set sequence SEQ to be the GIMPLE body for function FN.  */
     301              : 
     302              : void
     303    124169670 : gimple_set_body (tree fndecl, gimple_seq seq)
     304              : {
     305    124169670 :   struct function *fn = DECL_STRUCT_FUNCTION (fndecl);
     306    124169670 :   if (fn == NULL)
     307              :     {
     308              :       /* If FNDECL still does not have a function structure associated
     309              :          with it, then it does not make sense for it to receive a
     310              :          GIMPLE body.  */
     311           62 :       gcc_assert (seq == NULL);
     312              :     }
     313              :   else
     314    124169608 :     fn->gimple_body = seq;
     315    124169670 : }
     316              : 
     317              : 
     318              : /* Return the body of GIMPLE statements for function FN.  After the
     319              :    CFG pass, the function body doesn't exist anymore because it has
     320              :    been split up into basic blocks.  In this case, it returns
     321              :    NULL.  */
     322              : 
     323              : gimple_seq
     324    456023314 : gimple_body (tree fndecl)
     325              : {
     326    456023314 :   struct function *fn = DECL_STRUCT_FUNCTION (fndecl);
     327    456023314 :   return fn ? fn->gimple_body : NULL;
     328              : }
     329              : 
     330              : /* Return true when FNDECL has Gimple body either in unlowered
     331              :    or CFG form.  */
     332              : bool
     333    418379640 : gimple_has_body_p (tree fndecl)
     334              : {
     335    418379640 :   struct function *fn = DECL_STRUCT_FUNCTION (fndecl);
     336    418379640 :   return (gimple_body (fndecl) || (fn && fn->cfg && !(fn->curr_properties & PROP_rtl)));
     337              : }
     338              : 
     339              : /* Return a printable name for symbol DECL.  */
     340              : 
     341              : const char *
     342        34393 : gimple_decl_printable_name (tree decl, int verbosity)
     343              : {
     344        34393 :   if (!DECL_NAME (decl))
     345              :     return NULL;
     346              : 
     347        34393 :   if (HAS_DECL_ASSEMBLER_NAME_P (decl) && DECL_ASSEMBLER_NAME_SET_P (decl))
     348              :     {
     349        34031 :       int dmgl_opts = DMGL_NO_OPTS;
     350              : 
     351        34031 :       if (verbosity >= 2)
     352              :         {
     353         4194 :           dmgl_opts = DMGL_VERBOSE
     354              :                       | DMGL_ANSI
     355              :                       | DMGL_GNU_V3
     356              :                       | DMGL_RET_POSTFIX;
     357         4194 :           if (TREE_CODE (decl) == FUNCTION_DECL)
     358         4121 :             dmgl_opts |= DMGL_PARAMS;
     359              :         }
     360              : 
     361        34031 :       const char *mangled_str
     362        34031 :         = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME_RAW (decl));
     363        34031 :       const char *str = cplus_demangle_v3 (mangled_str, dmgl_opts);
     364        34031 :       return str ? str : mangled_str;
     365              :     }
     366              : 
     367          362 :   return IDENTIFIER_POINTER (DECL_NAME (decl));
     368              : }
     369              : 
     370              : 
     371              : /* Create a new VAR_DECL and copy information from VAR to it.  */
     372              : 
     373              : tree
     374      1545142 : copy_var_decl (tree var, tree name, tree type)
     375              : {
     376      1545142 :   tree copy = build_decl (DECL_SOURCE_LOCATION (var), VAR_DECL, name, type);
     377              : 
     378      1545142 :   TREE_ADDRESSABLE (copy) = TREE_ADDRESSABLE (var);
     379      1545142 :   TREE_THIS_VOLATILE (copy) = TREE_THIS_VOLATILE (var);
     380      1545142 :   DECL_NOT_GIMPLE_REG_P (copy) = DECL_NOT_GIMPLE_REG_P (var);
     381      1545142 :   DECL_ARTIFICIAL (copy) = DECL_ARTIFICIAL (var);
     382      1545142 :   DECL_IGNORED_P (copy) = DECL_IGNORED_P (var);
     383      1545142 :   DECL_CONTEXT (copy) = DECL_CONTEXT (var);
     384      1545142 :   TREE_USED (copy) = 1;
     385      1545142 :   DECL_SEEN_IN_BIND_EXPR_P (copy) = 1;
     386      1545142 :   DECL_ATTRIBUTES (copy) = DECL_ATTRIBUTES (var);
     387      1545142 :   if (DECL_USER_ALIGN (var))
     388              :     {
     389          145 :       SET_DECL_ALIGN (copy, DECL_ALIGN (var));
     390          145 :       DECL_USER_ALIGN (copy) = 1;
     391              :     }
     392              : 
     393      1545142 :   copy_warning (copy, var);
     394      1545142 :   return copy;
     395              : }
     396              : 
     397              : /* Strip off a legitimate source ending from the input string NAME of
     398              :    length LEN.  Rather than having to know the names used by all of
     399              :    our front ends, we strip off an ending of a period followed by
     400              :    up to four characters.  (like ".cpp".)  */
     401              : 
     402              : static inline void
     403     24297801 : remove_suffix (char *name, int len)
     404              : {
     405     24297801 :   int i;
     406              : 
     407     91752706 :   for (i = 2; i < 7 && len > i; i++)
     408     68600958 :     if (name[len - i] == '.')
     409              :       {
     410      1146053 :         name[len - i] = '\0';
     411      1146053 :         break;
     412              :       }
     413     24297801 : }
     414              : 
     415              : /* Create a new temporary name with PREFIX.  Return an identifier.  */
     416              : 
     417              : static GTY(()) unsigned int tmp_var_id_num;
     418              : 
     419              : tree
     420     24297801 : create_tmp_var_name (const char *prefix)
     421              : {
     422     24297801 :   char *tmp_name;
     423              : 
     424     24297801 :   if (prefix)
     425              :     {
     426     24297801 :       char *preftmp = ASTRDUP (prefix);
     427              : 
     428     24297801 :       remove_suffix (preftmp, strlen (preftmp));
     429     24297801 :       prefix = preftmp;
     430              :     }
     431              : 
     432     24297801 :   ASM_FORMAT_PRIVATE_NAME (tmp_name, prefix ? prefix : "T", tmp_var_id_num++);
     433     24297801 :   return get_identifier (tmp_name);
     434              : }
     435              : 
     436              : /* Create a new temporary variable declaration of type TYPE.
     437              :    Do NOT push it into the current binding.  */
     438              : 
     439              : tree
     440     27844019 : create_tmp_var_raw (tree type, const char *prefix)
     441              : {
     442     27844019 :   tree tmp_var;
     443              : 
     444     48439534 :   tmp_var = build_decl (input_location,
     445     20595515 :                         VAR_DECL, prefix ? create_tmp_var_name (prefix) : NULL,
     446              :                         type);
     447              : 
     448              :   /* The variable was declared by the compiler.  */
     449     27844019 :   DECL_ARTIFICIAL (tmp_var) = 1;
     450              :   /* And we don't want debug info for it.  */
     451     27844019 :   DECL_IGNORED_P (tmp_var) = 1;
     452              :   /* And we don't want even the fancy names of those printed in
     453              :      -fdump-final-insns= dumps.  */
     454     27844019 :   DECL_NAMELESS (tmp_var) = 1;
     455              : 
     456              :   /* Make the variable writable.  */
     457     27844019 :   TREE_READONLY (tmp_var) = 0;
     458              : 
     459     27844019 :   DECL_EXTERNAL (tmp_var) = 0;
     460     27844019 :   TREE_STATIC (tmp_var) = 0;
     461     27844019 :   TREE_USED (tmp_var) = 1;
     462              : 
     463     27844019 :   return tmp_var;
     464              : }
     465              : 
     466              : /* Create a new temporary variable declaration of type TYPE.  DO push the
     467              :    variable into the current binding.  Further, assume that this is called
     468              :    only from gimplification or optimization, at which point the creation of
     469              :    certain types are bugs.  */
     470              : 
     471              : tree
     472     15437064 : create_tmp_var (tree type, const char *prefix)
     473              : {
     474     15437064 :   tree tmp_var;
     475              : 
     476              :   /* We don't allow types that are addressable (meaning we can't make copies),
     477              :      or incomplete.  We also used to reject every variable size objects here,
     478              :      but now support those for which a constant upper bound can be obtained.
     479              :      The processing for variable sizes is performed in gimple_add_tmp_var,
     480              :      point at which it really matters and possibly reached via paths not going
     481              :      through this function, e.g. after direct calls to create_tmp_var_raw.  */
     482     15437064 :   gcc_assert (!TREE_ADDRESSABLE (type) && COMPLETE_TYPE_P (type));
     483              : 
     484     15437064 :   tmp_var = create_tmp_var_raw (type, prefix);
     485     15437064 :   gimple_add_tmp_var (tmp_var);
     486     15437064 :   return tmp_var;
     487              : }
     488              : 
     489              : /* Create a new temporary variable declaration of type TYPE by calling
     490              :    create_tmp_var and if TYPE is a vector or a complex number, mark the new
     491              :    temporary as gimple register.  */
     492              : 
     493              : tree
     494      3643415 : create_tmp_reg (tree type, const char *prefix)
     495              : {
     496      3643415 :   return create_tmp_var (type, prefix);
     497              : }
     498              : 
     499              : /* Create a new temporary variable declaration of type TYPE by calling
     500              :    create_tmp_var and if TYPE is a vector or a complex number, mark the new
     501              :    temporary as gimple register.  */
     502              : 
     503              : tree
     504        29813 : create_tmp_reg_fn (struct function *fn, tree type, const char *prefix)
     505              : {
     506        29813 :   tree tmp;
     507              : 
     508        29813 :   tmp = create_tmp_var_raw (type, prefix);
     509        29813 :   gimple_add_tmp_var_fn (fn, tmp);
     510              : 
     511        29813 :   return tmp;
     512              : }
     513              : 
     514              : 
     515              : /* ----- Expression related -----  */
     516              : 
     517              : /* Extract the operands and code for expression EXPR into *SUBCODE_P,
     518              :    *OP1_P, *OP2_P and *OP3_P respectively.  */
     519              : 
     520              : void
     521    181171069 : extract_ops_from_tree (tree expr, enum tree_code *subcode_p, tree *op1_p,
     522              :                        tree *op2_p, tree *op3_p)
     523              : {
     524    181171069 :   *subcode_p = TREE_CODE (expr);
     525    181171069 :   switch (get_gimple_rhs_class (*subcode_p))
     526              :     {
     527       107021 :     case GIMPLE_TERNARY_RHS:
     528       107021 :       {
     529       107021 :         *op1_p = TREE_OPERAND (expr, 0);
     530       107021 :         *op2_p = TREE_OPERAND (expr, 1);
     531       107021 :         *op3_p = TREE_OPERAND (expr, 2);
     532       107021 :         break;
     533              :       }
     534     21572313 :     case GIMPLE_BINARY_RHS:
     535     21572313 :       {
     536     21572313 :         *op1_p = TREE_OPERAND (expr, 0);
     537     21572313 :         *op2_p = TREE_OPERAND (expr, 1);
     538     21572313 :         *op3_p = NULL_TREE;
     539     21572313 :         break;
     540              :       }
     541     12035374 :     case GIMPLE_UNARY_RHS:
     542     12035374 :       {
     543     12035374 :         *op1_p = TREE_OPERAND (expr, 0);
     544     12035374 :         *op2_p = NULL_TREE;
     545     12035374 :         *op3_p = NULL_TREE;
     546     12035374 :         break;
     547              :       }
     548    147456361 :     case GIMPLE_SINGLE_RHS:
     549    147456361 :       {
     550    147456361 :         *op1_p = expr;
     551    147456361 :         *op2_p = NULL_TREE;
     552    147456361 :         *op3_p = NULL_TREE;
     553    147456361 :         break;
     554              :       }
     555            0 :     default:
     556            0 :       gcc_unreachable ();
     557              :     }
     558    181171069 : }
     559              : 
     560              : /* Extract operands for a GIMPLE_COND statement out of COND_EXPR tree COND.  */
     561              : 
     562              : void
     563      6177523 : gimple_cond_get_ops_from_tree (tree cond, enum tree_code *code_p,
     564              :                                tree *lhs_p, tree *rhs_p)
     565              : {
     566      6177523 :   gcc_assert (COMPARISON_CLASS_P (cond)
     567              :               || TREE_CODE (cond) == TRUTH_NOT_EXPR
     568              :               || is_gimple_min_invariant (cond)
     569              :               || SSA_VAR_P (cond));
     570      6177523 :   gcc_checking_assert (!tree_could_throw_p (cond));
     571              : 
     572      6177523 :   extract_ops_from_tree (cond, code_p, lhs_p, rhs_p);
     573              : 
     574              :   /* Canonicalize conditionals of the form 'if (!VAL)'.  */
     575      6177523 :   if (*code_p == TRUTH_NOT_EXPR)
     576              :     {
     577            0 :       *code_p = EQ_EXPR;
     578            0 :       gcc_assert (*lhs_p && *rhs_p == NULL_TREE);
     579            0 :       *rhs_p = build_zero_cst (TREE_TYPE (*lhs_p));
     580              :     }
     581              :   /* Canonicalize conditionals of the form 'if (VAL)'  */
     582      6177523 :   else if (TREE_CODE_CLASS (*code_p) != tcc_comparison)
     583              :     {
     584      1862360 :       *code_p = NE_EXPR;
     585      1862360 :       gcc_assert (*lhs_p && *rhs_p == NULL_TREE);
     586      1862360 :       *rhs_p = build_zero_cst (TREE_TYPE (*lhs_p));
     587              :     }
     588      6177523 : }
     589              : 
     590              : /*  Return true if T is a valid LHS for a GIMPLE assignment expression.  */
     591              : 
     592              : bool
     593    267760756 : is_gimple_lvalue (tree t)
     594              : {
     595    267760756 :   return (is_gimple_addressable (t)
     596     15386653 :           || TREE_CODE (t) == WITH_SIZE_EXPR
     597              :           /* These are complex lvalues, but don't have addresses, so they
     598              :              go here.  */
     599    283123319 :           || TREE_CODE (t) == BIT_FIELD_REF);
     600              : }
     601              : 
     602              : /* Helper for is_gimple_condexpr and is_gimple_condexpr_for_cond.  */
     603              : 
     604              : static bool
     605     10439584 : is_gimple_condexpr_1 (tree t, bool allow_traps, bool allow_cplx)
     606              : {
     607     10439584 :   tree op0;
     608     10439584 :   return (is_gimple_val (t)
     609     10439584 :           || (COMPARISON_CLASS_P (t)
     610      7186279 :               && (allow_traps || !tree_could_throw_p (t))
     611      7179274 :               && ((op0 = TREE_OPERAND (t, 0)), true)
     612      7179274 :               && (allow_cplx || TREE_CODE (TREE_TYPE (op0)) != COMPLEX_TYPE)
     613      7179274 :               && is_gimple_val (op0)
     614      5568394 :               && is_gimple_val (TREE_OPERAND (t, 1))));
     615              : }
     616              : 
     617              : /* Like is_gimple_condexpr, but does not allow T to trap.  */
     618              : 
     619              : bool
     620      6694169 : is_gimple_condexpr_for_cond (tree t)
     621              : {
     622      6694169 :   return is_gimple_condexpr_1 (t, false, true);
     623              : }
     624              : 
     625              : /* Canonicalize a tree T for use in a COND_EXPR as conditional.  Returns
     626              :    a canonicalized tree that is valid for a COND_EXPR or NULL_TREE, if
     627              :    we failed to create one.  */
     628              : 
     629              : tree
     630      3745415 : canonicalize_cond_expr_cond (tree t)
     631              : {
     632              :   /* Strip conversions around boolean operations.  */
     633      3591619 :   if (CONVERT_EXPR_P (t)
     634      3745415 :       && (truth_value_p (TREE_CODE (TREE_OPERAND (t, 0)))
     635       152723 :           || TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0)))
     636              :              == BOOLEAN_TYPE))
     637         1087 :     t = TREE_OPERAND (t, 0);
     638              : 
     639              :   /* For !x use x == 0.  */
     640      3745415 :   if (TREE_CODE (t) == TRUTH_NOT_EXPR)
     641              :     {
     642        24438 :       tree top0 = TREE_OPERAND (t, 0);
     643        24438 :       t = build2 (EQ_EXPR, TREE_TYPE (t),
     644        24438 :                   top0, build_int_cst (TREE_TYPE (top0), 0));
     645              :     }
     646              :   /* For cmp ? 1 : 0 use cmp.  */
     647      3720977 :   else if (TREE_CODE (t) == COND_EXPR
     648       103782 :            && COMPARISON_CLASS_P (TREE_OPERAND (t, 0))
     649       101978 :            && integer_onep (TREE_OPERAND (t, 1))
     650      3822955 :            && integer_zerop (TREE_OPERAND (t, 2)))
     651              :     {
     652       101978 :       tree top0 = TREE_OPERAND (t, 0);
     653       101978 :       t = build2 (TREE_CODE (top0), TREE_TYPE (t),
     654       101978 :                   TREE_OPERAND (top0, 0), TREE_OPERAND (top0, 1));
     655              :     }
     656              :   /* For x ^ y use x != y.  */
     657      3618999 :   else if (TREE_CODE (t) == BIT_XOR_EXPR)
     658            0 :     t = build2 (NE_EXPR, TREE_TYPE (t),
     659            0 :                 TREE_OPERAND (t, 0), TREE_OPERAND (t, 1));
     660              : 
     661              :   /* We don't know where this will be used so allow both traps and
     662              :      _Complex.  The caller is responsible for more precise checking.  */
     663      3745415 :   if (is_gimple_condexpr_1 (t, true, true))
     664      1320195 :     return t;
     665              : 
     666              :   return NULL_TREE;
     667              : }
     668              : 
     669              : /* Return true if T is a gimple address.  */
     670              : 
     671              : bool
     672            0 : is_gimple_address (const_tree t)
     673              : {
     674            0 :   tree op;
     675              : 
     676            0 :   if (TREE_CODE (t) != ADDR_EXPR)
     677              :     return false;
     678              : 
     679            0 :   op = TREE_OPERAND (t, 0);
     680            0 :   while (handled_component_p (op))
     681              :     {
     682            0 :       if ((TREE_CODE (op) == ARRAY_REF
     683            0 :            || TREE_CODE (op) == ARRAY_RANGE_REF)
     684            0 :           && !is_gimple_val (TREE_OPERAND (op, 1)))
     685              :             return false;
     686              : 
     687            0 :       op = TREE_OPERAND (op, 0);
     688              :     }
     689              : 
     690            0 :   if (CONSTANT_CLASS_P (op)
     691            0 :       || TREE_CODE (op) == TARGET_MEM_REF
     692            0 :       || TREE_CODE (op) == MEM_REF)
     693              :     return true;
     694              : 
     695            0 :   switch (TREE_CODE (op))
     696              :     {
     697              :     case PARM_DECL:
     698              :     case RESULT_DECL:
     699              :     case LABEL_DECL:
     700              :     case FUNCTION_DECL:
     701              :     case VAR_DECL:
     702              :     case CONST_DECL:
     703              :       return true;
     704              : 
     705              :     default:
     706              :       return false;
     707              :     }
     708              : }
     709              : 
     710              : /* Return true if T is a gimple invariant address.  */
     711              : 
     712              : bool
     713   6120706439 : is_gimple_invariant_address (const_tree t)
     714              : {
     715   6120706439 :   const_tree op;
     716              : 
     717   6120706439 :   if (TREE_CODE (t) != ADDR_EXPR)
     718              :     return false;
     719              : 
     720   6120706439 :   op = strip_invariant_refs (TREE_OPERAND (t, 0));
     721   6120706439 :   if (!op)
     722              :     return false;
     723              : 
     724   6108351871 :   if (TREE_CODE (op) == MEM_REF)
     725              :     {
     726    503718933 :       const_tree op0 = TREE_OPERAND (op, 0);
     727    503718933 :       return (TREE_CODE (op0) == ADDR_EXPR
     728    503718933 :               && (CONSTANT_CLASS_P (TREE_OPERAND (op0, 0))
     729    169572235 :                   || decl_address_invariant_p (TREE_OPERAND (op0, 0))));
     730              :     }
     731              : 
     732   5604632938 :   return CONSTANT_CLASS_P (op) || decl_address_invariant_p (op);
     733              : }
     734              : 
     735              : /* Return true if T is a gimple invariant address at IPA level
     736              :    (so addresses of variables on stack are not allowed).  */
     737              : 
     738              : bool
     739      2554466 : is_gimple_ip_invariant_address (const_tree t)
     740              : {
     741      2554466 :   const_tree op;
     742              : 
     743      2554466 :   if (TREE_CODE (t) != ADDR_EXPR)
     744              :     return false;
     745              : 
     746      2554466 :   op = strip_invariant_refs (TREE_OPERAND (t, 0));
     747      2554466 :   if (!op)
     748              :     return false;
     749              : 
     750      2552986 :   if (TREE_CODE (op) == MEM_REF)
     751              :     {
     752       125432 :       const_tree op0 = TREE_OPERAND (op, 0);
     753       125432 :       return (TREE_CODE (op0) == ADDR_EXPR
     754       125432 :               && (CONSTANT_CLASS_P (TREE_OPERAND (op0, 0))
     755        94272 :                   || decl_address_ip_invariant_p (TREE_OPERAND (op0, 0))));
     756              :     }
     757              : 
     758      2427554 :   return CONSTANT_CLASS_P (op) || decl_address_ip_invariant_p (op);
     759              : }
     760              : 
     761              : /* Return true if T is a GIMPLE minimal invariant.  It's a restricted
     762              :    form of function invariant.  */
     763              : 
     764              : bool
     765  23392293959 : is_gimple_min_invariant (const_tree t)
     766              : {
     767  23392293959 :   if (TREE_CODE (t) == ADDR_EXPR)
     768   6119437243 :     return is_gimple_invariant_address (t);
     769              : 
     770  17272856716 :   return is_gimple_constant (t);
     771              : }
     772              : 
     773              : /* Return true if T is a GIMPLE interprocedural invariant.  It's a restricted
     774              :    form of gimple minimal invariant.  */
     775              : 
     776              : bool
     777     26961382 : is_gimple_ip_invariant (const_tree t)
     778              : {
     779     26961382 :   if (TREE_CODE (t) == ADDR_EXPR)
     780      2553246 :     return is_gimple_ip_invariant_address (t);
     781              : 
     782     24408136 :   return is_gimple_constant (t);
     783              : }
     784              : 
     785              : /* Return true if T is a non-aggregate register variable.  */
     786              : 
     787              : bool
     788  46092921899 : is_gimple_reg (tree t)
     789              : {
     790  80423877108 :   if (virtual_operand_p (t))
     791              :     return false;
     792              : 
     793  45936999391 :   if (TREE_CODE (t) == SSA_NAME)
     794              :     return true;
     795              : 
     796  16994389086 :   if (!is_gimple_variable (t))
     797              :     return false;
     798              : 
     799   5770288066 :   if (!is_gimple_reg_type (TREE_TYPE (t)))
     800              :     return false;
     801              : 
     802              :   /* A volatile decl is not acceptable because we can't reuse it as
     803              :      needed.  We need to copy it into a temp first.  */
     804   2270449902 :   if (TREE_THIS_VOLATILE (t))
     805              :     return false;
     806              : 
     807              :   /* We define "registers" as things that can be renamed as needed,
     808              :      which with our infrastructure does not apply to memory.  */
     809   2027057343 :   if (needs_to_live_in_memory (t))
     810              :     return false;
     811              : 
     812              :   /* Hard register variables are an interesting case.  For those that
     813              :      are call-clobbered, we don't know where all the calls are, since
     814              :      we don't (want to) take into account which operations will turn
     815              :      into libcalls at the rtl level.  For those that are call-saved,
     816              :      we don't currently model the fact that calls may in fact change
     817              :      global hard registers, nor do we examine ASM_CLOBBERS at the tree
     818              :      level, and so miss variable changes that might imply.  All around,
     819              :      it seems safest to not do too much optimization with these at the
     820              :      tree level at all.  We'll have to rely on the rtl optimizers to
     821              :      clean this up, as there we've got all the appropriate bits exposed.  */
     822   1191931052 :   if (VAR_P (t) && DECL_HARD_REGISTER (t))
     823              :     return false;
     824              : 
     825              :   /* Variables can be marked as having partial definitions, avoid
     826              :      putting them into SSA form.  */
     827   1190483700 :   return !DECL_NOT_GIMPLE_REG_P (t);
     828              : }
     829              : 
     830              : 
     831              : /* Return true if T is a GIMPLE rvalue, i.e. an identifier or a constant.  */
     832              : 
     833              : bool
     834   9347127531 : is_gimple_val (tree t)
     835              : {
     836              :   /* Make loads from volatiles and memory vars explicit.  */
     837   9347127531 :   if (is_gimple_variable (t)
     838   4965590928 :       && is_gimple_reg_type (TREE_TYPE (t))
     839  14287292460 :       && !is_gimple_reg (t))
     840              :     return false;
     841              : 
     842              :   /* These eventually expand into constants, so treat them like that.  */
     843   9336482702 :   if (TREE_CODE (t) == OMP_NEXT_VARIANT
     844   9336482702 :       || TREE_CODE (t) == OMP_TARGET_DEVICE_MATCHES)
     845              :     return true;
     846              : 
     847   9336482650 :   return (is_gimple_variable (t) || is_gimple_min_invariant (t));
     848              : }
     849              : 
     850              : /* Similarly, but accept hard registers as inputs to asm statements.  */
     851              : 
     852              : bool
     853        44057 : is_gimple_asm_val (tree t)
     854              : {
     855        44057 :   if (VAR_P (t) && DECL_HARD_REGISTER (t))
     856              :     return true;
     857              : 
     858        43179 :   return is_gimple_val (t);
     859              : }
     860              : 
     861              : /* Return true if T is a GIMPLE minimal lvalue.  */
     862              : 
     863              : bool
     864     31115382 : is_gimple_min_lval (tree t)
     865              : {
     866     31115382 :   if (!(t = const_cast<tree> (strip_invariant_refs (t))))
     867              :     return false;
     868     31115367 :   return (is_gimple_id (t) || TREE_CODE (t) == MEM_REF);
     869              : }
     870              : 
     871              : /* Return true if T is a valid function operand of a CALL_EXPR.  */
     872              : 
     873              : bool
     874   1087943109 : is_gimple_call_addr (tree t)
     875              : {
     876   1087943109 :   return (TREE_CODE (t) == OBJ_TYPE_REF || is_gimple_val (t));
     877              : }
     878              : 
     879              : /* Return true if T is a valid address operand of a MEM_REF.  */
     880              : 
     881              : bool
     882   1460653778 : is_gimple_mem_ref_addr (tree t)
     883              : {
     884   1460653778 :   return (is_gimple_reg (t)
     885    400637319 :           || poly_int_tree_p (t)
     886   1860893240 :           || (TREE_CODE (t) == ADDR_EXPR
     887    397690168 :               && (CONSTANT_CLASS_P (TREE_OPERAND (t, 0))
     888    395580326 :                   || decl_address_invariant_p (TREE_OPERAND (t, 0)))));
     889              : }
     890              : 
     891              : /* Hold trees marked addressable during expand.  */
     892              : 
     893              : static hash_set<tree> *mark_addressable_queue;
     894              : 
     895              : /* Mark X as addressable or queue it up if called during expand.  We
     896              :    don't want to apply it immediately during expand because decls are
     897              :    made addressable at that point due to RTL-only concerns, such as
     898              :    uses of memcpy for block moves, and TREE_ADDRESSABLE changes
     899              :    is_gimple_reg, which might make it seem like a variable that used
     900              :    to be a gimple_reg shouldn't have been an SSA name.  So we queue up
     901              :    this flag setting and only apply it when we're done with GIMPLE and
     902              :    only RTL issues matter.  */
     903              : 
     904              : static void
     905     11528017 : mark_addressable_1 (tree x)
     906              : {
     907     11528017 :   if (!currently_expanding_to_rtl)
     908              :     {
     909     11456243 :       TREE_ADDRESSABLE (x) = 1;
     910     11456243 :       return;
     911              :     }
     912              : 
     913        71774 :   if (!mark_addressable_queue)
     914        16861 :     mark_addressable_queue = new hash_set<tree>();
     915        71774 :   mark_addressable_queue->add (x);
     916              : }
     917              : 
     918              : /* Adaptor for mark_addressable_1 for use in hash_set traversal.  */
     919              : 
     920              : static bool
     921        47304 : mark_addressable_2 (tree const &x, void * ATTRIBUTE_UNUSED = NULL)
     922              : {
     923        47304 :   mark_addressable_1 (x);
     924        47304 :   return false;
     925              : }
     926              : 
     927              : /* Mark all queued trees as addressable, and empty the queue.  To be
     928              :    called right after clearing CURRENTLY_EXPANDING_TO_RTL.  */
     929              : 
     930              : void
     931      1516700 : flush_mark_addressable_queue ()
     932              : {
     933      1516700 :   gcc_assert (!currently_expanding_to_rtl);
     934      1516700 :   if (mark_addressable_queue)
     935              :     {
     936        16861 :       mark_addressable_queue->traverse<void*, mark_addressable_2> (NULL);
     937        33722 :       delete mark_addressable_queue;
     938        16861 :       mark_addressable_queue = NULL;
     939              :     }
     940      1516700 : }
     941              : 
     942              : /* Mark X addressable.  Unlike the langhook we expect X to be in gimple
     943              :    form and we don't do any syntax checking.  */
     944              : 
     945              : void
     946     35013344 : mark_addressable (tree x)
     947              : {
     948     35013344 :   if (TREE_CODE (x) == WITH_SIZE_EXPR)
     949            0 :     x = TREE_OPERAND (x, 0);
     950     40650651 :   while (handled_component_p (x))
     951      5637307 :     x = TREE_OPERAND (x, 0);
     952     35013344 :   if ((TREE_CODE (x) == MEM_REF
     953     35013344 :        || TREE_CODE (x) == TARGET_MEM_REF)
     954     35013344 :       && TREE_CODE (TREE_OPERAND (x, 0)) == ADDR_EXPR)
     955        11741 :     x = TREE_OPERAND (TREE_OPERAND (x, 0), 0);
     956     35013344 :   if (!VAR_P (x)
     957              :       && TREE_CODE (x) != PARM_DECL
     958              :       && TREE_CODE (x) != RESULT_DECL)
     959              :     return;
     960     11468555 :   mark_addressable_1 (x);
     961              : 
     962              :   /* Also mark the artificial SSA_NAME that points to the partition of X.  */
     963     11468555 :   if (VAR_P (x)
     964     10797370 :       && !DECL_EXTERNAL (x)
     965      9554903 :       && !TREE_STATIC (x)
     966      6142073 :       && cfun->gimple_df != NULL
     967     17610628 :       && cfun->gimple_df->decls_to_pointers != NULL)
     968              :     {
     969        19157 :       tree *namep = cfun->gimple_df->decls_to_pointers->get (x);
     970        19157 :       if (namep)
     971        12158 :         mark_addressable_1 (*namep);
     972              :     }
     973              : }
     974              : 
     975              : /* Returns true iff T is a valid RHS for an assignment to a renamed
     976              :    user -- or front-end generated artificial -- variable.  */
     977              : 
     978              : bool
     979       814886 : is_gimple_reg_rhs (tree t)
     980              : {
     981       814886 :   return get_gimple_rhs_class (TREE_CODE (t)) != GIMPLE_INVALID_RHS;
     982              : }
     983              : 
     984              : #include "gt-gimple-expr.h"
        

Generated by: LCOV version 2.5.0-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.