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-09-19 16:22:48 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  12215381209 : useless_type_conversion_p (tree outer_type, tree inner_type)
      68              : {
      69              :   /* Do the following before stripping toplevel qualifiers.  */
      70  12215746495 :   if (POINTER_TYPE_P (inner_type)
      71   3070924792 :       && POINTER_TYPE_P (outer_type))
      72              :     {
      73              :       /* Do not lose casts between pointers to different address spaces.  */
      74   3046286160 :       if (TYPE_ADDR_SPACE (TREE_TYPE (outer_type))
      75   3046286160 :           != TYPE_ADDR_SPACE (TREE_TYPE (inner_type)))
      76              :         return false;
      77              :       /* Do not lose casts to function pointer types.  */
      78   6014632297 :       if (FUNC_OR_METHOD_TYPE_P (TREE_TYPE (outer_type))
      79   3053870895 :           && !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  12213933683 :   inner_type = TYPE_MAIN_VARIANT (inner_type);
      85  12213933683 :   outer_type = TYPE_MAIN_VARIANT (outer_type);
      86              : 
      87  12213933683 :   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   1096106907 :   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    985368693 :   if (INTEGRAL_TYPE_P (inner_type)
      99    182936689 :       && INTEGRAL_TYPE_P (outer_type))
     100              :     {
     101              :       /* Preserve changes in signedness or precision.  */
     102    167608133 :       if (TYPE_UNSIGNED (inner_type) != TYPE_UNSIGNED (outer_type)
     103    167608133 :           || 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     68670683 :       if (((TREE_CODE (inner_type) == BOOLEAN_TYPE)
     109     68670683 :            != (TREE_CODE (outer_type) == BOOLEAN_TYPE))
     110     68670683 :           && 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     68617547 :       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    817760560 :   else if (SCALAR_FLOAT_TYPE_P (inner_type)
     129       603297 :            && SCALAR_FLOAT_TYPE_P (outer_type))
     130              :     return true;
     131              : 
     132              :   /* Fixed point types with the same mode are compatible.  */
     133    817161223 :   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    817161223 :   else if (POINTER_TYPE_P (inner_type)
     139    787648558 :            && 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     48022547 :   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     47989173 :   else if (VECTOR_TYPE_P (inner_type)
     156      9806556 :            && VECTOR_TYPE_P (outer_type))
     157     19527756 :     return (known_eq (TYPE_VECTOR_SUBPARTS (inner_type),
     158              :                       TYPE_VECTOR_SUBPARTS (outer_type))
     159      9756925 :             && useless_type_conversion_p (TREE_TYPE (outer_type),
     160      9756925 :                                           TREE_TYPE (inner_type))
     161     19174748 :             && targetm.compatible_vector_types_p (inner_type, outer_type));
     162              : 
     163     38225295 :   else if (TREE_CODE (inner_type) == ARRAY_TYPE
     164       617934 :            && TREE_CODE (outer_type) == ARRAY_TYPE)
     165              :     {
     166              :       /* Preserve various attributes.  */
     167       457484 :       if (TYPE_REVERSE_STORAGE_ORDER (inner_type)
     168       457484 :           != TYPE_REVERSE_STORAGE_ORDER (outer_type))
     169              :         return false;
     170       457484 :       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       443664 :       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       441246 :       if (TYPE_SIZE (outer_type)
     181       424421 :           && TREE_CODE (TYPE_SIZE (outer_type)) == INTEGER_CST
     182       853363 :           && (!TYPE_SIZE (inner_type)
     183       410375 :               || TREE_CODE (TYPE_SIZE (inner_type)) != INTEGER_CST
     184       408519 :               || !tree_int_cst_equal (TYPE_SIZE (outer_type),
     185       408519 :                                       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       399926 :       if (TYPE_DOMAIN (inner_type)
     194       399924 :           && TYPE_DOMAIN (outer_type)
     195       799836 :           && TYPE_DOMAIN (inner_type) != TYPE_DOMAIN (outer_type))
     196              :         {
     197        84142 :           tree inner_min = TYPE_MIN_VALUE (TYPE_DOMAIN (inner_type));
     198        84142 :           tree outer_min = TYPE_MIN_VALUE (TYPE_DOMAIN (outer_type));
     199        84142 :           tree inner_max = TYPE_MAX_VALUE (TYPE_DOMAIN (inner_type));
     200        84142 :           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        84142 :           if (inner_min && TREE_CODE (inner_min) != INTEGER_CST)
     206            0 :             inner_min = NULL_TREE;
     207        84142 :           if (outer_min && TREE_CODE (outer_min) != INTEGER_CST)
     208            0 :             outer_min = NULL_TREE;
     209        84142 :           if (inner_max && TREE_CODE (inner_max) != INTEGER_CST)
     210        10468 :             inner_max = NULL_TREE;
     211        84142 :           if (outer_max && TREE_CODE (outer_max) != INTEGER_CST)
     212        14809 :             outer_max = NULL_TREE;
     213              : 
     214              :           /* Conversions NULL / variable <- cst are useless, but not
     215              :              the other way around.  */
     216        84142 :           if (outer_min
     217        84142 :               && (!inner_min
     218        84142 :                   || !tree_int_cst_equal (inner_min, outer_min)))
     219              :             return false;
     220        75269 :           if (outer_max
     221        75269 :               && (!inner_max
     222        60448 :                   || !tree_int_cst_equal (inner_max, outer_max)))
     223              :             return false;
     224              :         }
     225              : 
     226              :       /* Recurse on the element check.  */
     227       331912 :       return useless_type_conversion_p (TREE_TYPE (outer_type),
     228       663824 :                                         TREE_TYPE (inner_type));
     229              :     }
     230              : 
     231     37767811 :   else if (FUNC_OR_METHOD_TYPE_P (inner_type)
     232       328953 :            && TREE_CODE (inner_type) == TREE_CODE (outer_type))
     233              :     {
     234       323081 :       tree outer_parm, inner_parm;
     235              : 
     236              :       /* If the return types are not compatible bail out.  */
     237       323081 :       if (!useless_type_conversion_p (TREE_TYPE (outer_type),
     238       323081 :                                       TREE_TYPE (inner_type)))
     239              :         return false;
     240              : 
     241              :       /* Method types should belong to a compatible base class.  */
     242       314825 :       if (TREE_CODE (inner_type) == METHOD_TYPE
     243       328705 :           && !useless_type_conversion_p (TYPE_METHOD_BASETYPE (outer_type),
     244        13880 :                                          TYPE_METHOD_BASETYPE (inner_type)))
     245              :         return false;
     246              : 
     247              :       /* A conversion to an unprototyped argument list is ok.  */
     248       306348 :       if (!prototype_p (outer_type))
     249              :         return true;
     250              : 
     251              :       /* If the unqualified argument types are compatible the conversion
     252              :          is useless.  */
     253       306268 :       if (TYPE_ARG_TYPES (outer_type) == TYPE_ARG_TYPES (inner_type))
     254              :         return true;
     255              : 
     256       300706 :       for (outer_parm = TYPE_ARG_TYPES (outer_type),
     257       300706 :            inner_parm = TYPE_ARG_TYPES (inner_type);
     258      1246824 :            outer_parm && inner_parm;
     259       946118 :            outer_parm = TREE_CHAIN (outer_parm),
     260       946118 :            inner_parm = TREE_CHAIN (inner_parm))
     261      1901078 :         if (!useless_type_conversion_p
     262       950539 :                (TYPE_MAIN_VARIANT (TREE_VALUE (outer_parm)),
     263       950539 :                 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       296285 :       if (outer_parm || inner_parm)
     269              :         return false;
     270              : 
     271              :       /* Defer to the target if necessary.  */
     272       294683 :       if (TYPE_ATTRIBUTES (inner_type) || TYPE_ATTRIBUTES (outer_type))
     273       286456 :         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     37444730 :   else if (AGGREGATE_TYPE_P (inner_type)
     282      3542303 :            && TREE_CODE (inner_type) == TREE_CODE (outer_type))
     283      2405363 :     return TYPE_CANONICAL (inner_type)
     284      2405363 :            && TYPE_CANONICAL (inner_type) == TYPE_CANONICAL (outer_type);
     285              : 
     286     35039367 :   else if (TREE_CODE (inner_type) == OFFSET_TYPE
     287         9937 :            && 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    123732687 : gimple_set_body (tree fndecl, gimple_seq seq)
     304              : {
     305    123732687 :   struct function *fn = DECL_STRUCT_FUNCTION (fndecl);
     306    123732687 :   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    123732625 :     fn->gimple_body = seq;
     315    123732687 : }
     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    450838344 : gimple_body (tree fndecl)
     325              : {
     326    450838344 :   struct function *fn = DECL_STRUCT_FUNCTION (fndecl);
     327    450838344 :   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    413518485 : gimple_has_body_p (tree fndecl)
     334              : {
     335    413518485 :   struct function *fn = DECL_STRUCT_FUNCTION (fndecl);
     336    413518485 :   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        34096 : gimple_decl_printable_name (tree decl, int verbosity)
     343              : {
     344        34096 :   if (!DECL_NAME (decl))
     345              :     return NULL;
     346              : 
     347        34096 :   if (HAS_DECL_ASSEMBLER_NAME_P (decl) && DECL_ASSEMBLER_NAME_SET_P (decl))
     348              :     {
     349        33734 :       int dmgl_opts = DMGL_NO_OPTS;
     350              : 
     351        33734 :       if (verbosity >= 2)
     352              :         {
     353         4191 :           dmgl_opts = DMGL_VERBOSE
     354              :                       | DMGL_ANSI
     355              :                       | DMGL_GNU_V3
     356              :                       | DMGL_RET_POSTFIX;
     357         4191 :           if (TREE_CODE (decl) == FUNCTION_DECL)
     358         4118 :             dmgl_opts |= DMGL_PARAMS;
     359              :         }
     360              : 
     361        33734 :       const char *mangled_str
     362        33734 :         = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME_RAW (decl));
     363        33734 :       const char *str = cplus_demangle_v3 (mangled_str, dmgl_opts);
     364        33734 :       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      1545124 : copy_var_decl (tree var, tree name, tree type)
     375              : {
     376      1545124 :   tree copy = build_decl (DECL_SOURCE_LOCATION (var), VAR_DECL, name, type);
     377              : 
     378      1545124 :   TREE_ADDRESSABLE (copy) = TREE_ADDRESSABLE (var);
     379      1545124 :   TREE_THIS_VOLATILE (copy) = TREE_THIS_VOLATILE (var);
     380      1545124 :   DECL_NOT_GIMPLE_REG_P (copy) = DECL_NOT_GIMPLE_REG_P (var);
     381      1545124 :   DECL_ARTIFICIAL (copy) = DECL_ARTIFICIAL (var);
     382      1545124 :   DECL_IGNORED_P (copy) = DECL_IGNORED_P (var);
     383      1545124 :   DECL_CONTEXT (copy) = DECL_CONTEXT (var);
     384      1545124 :   TREE_USED (copy) = 1;
     385      1545124 :   DECL_SEEN_IN_BIND_EXPR_P (copy) = 1;
     386      1545124 :   DECL_ATTRIBUTES (copy) = DECL_ATTRIBUTES (var);
     387      1545124 :   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      1545124 :   copy_warning (copy, var);
     394      1545124 :   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     24272115 : remove_suffix (char *name, int len)
     404              : {
     405     24272115 :   int i;
     406              : 
     407     91662825 :   for (i = 2; i < 7 && len > i; i++)
     408     68543710 :     if (name[len - i] == '.')
     409              :       {
     410      1153000 :         name[len - i] = '\0';
     411      1153000 :         break;
     412              :       }
     413     24272115 : }
     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     24272115 : create_tmp_var_name (const char *prefix)
     421              : {
     422     24272115 :   char *tmp_name;
     423              : 
     424     24272115 :   if (prefix)
     425              :     {
     426     24272115 :       char *preftmp = ASTRDUP (prefix);
     427              : 
     428     24272115 :       remove_suffix (preftmp, strlen (preftmp));
     429     24272115 :       prefix = preftmp;
     430              :     }
     431              : 
     432     24272115 :   ASM_FORMAT_PRIVATE_NAME (tmp_name, prefix ? prefix : "T", tmp_var_id_num++);
     433     24272115 :   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     27770322 : create_tmp_var_raw (tree type, const char *prefix)
     441              : {
     442     27770322 :   tree tmp_var;
     443              : 
     444     48346558 :   tmp_var = build_decl (input_location,
     445     20576236 :                         VAR_DECL, prefix ? create_tmp_var_name (prefix) : NULL,
     446              :                         type);
     447              : 
     448              :   /* The variable was declared by the compiler.  */
     449     27770322 :   DECL_ARTIFICIAL (tmp_var) = 1;
     450              :   /* And we don't want debug info for it.  */
     451     27770322 :   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     27770322 :   DECL_NAMELESS (tmp_var) = 1;
     455              : 
     456              :   /* Make the variable writable.  */
     457     27770322 :   TREE_READONLY (tmp_var) = 0;
     458              : 
     459     27770322 :   DECL_EXTERNAL (tmp_var) = 0;
     460     27770322 :   TREE_STATIC (tmp_var) = 0;
     461     27770322 :   TREE_USED (tmp_var) = 1;
     462              : 
     463     27770322 :   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     15438748 : create_tmp_var (tree type, const char *prefix)
     473              : {
     474     15438748 :   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     15438748 :   gcc_assert (!TREE_ADDRESSABLE (type) && COMPLETE_TYPE_P (type));
     483              : 
     484     15438748 :   tmp_var = create_tmp_var_raw (type, prefix);
     485     15438748 :   gimple_add_tmp_var (tmp_var);
     486     15438748 :   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      3696103 : create_tmp_reg (tree type, const char *prefix)
     495              : {
     496      3696103 :   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        28301 : create_tmp_reg_fn (struct function *fn, tree type, const char *prefix)
     505              : {
     506        28301 :   tree tmp;
     507              : 
     508        28301 :   tmp = create_tmp_var_raw (type, prefix);
     509        28301 :   gimple_add_tmp_var_fn (fn, tmp);
     510              : 
     511        28301 :   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    179755529 : extract_ops_from_tree (tree expr, enum tree_code *subcode_p, tree *op1_p,
     522              :                        tree *op2_p, tree *op3_p)
     523              : {
     524    179755529 :   *subcode_p = TREE_CODE (expr);
     525    179755529 :   switch (get_gimple_rhs_class (*subcode_p))
     526              :     {
     527       106416 :     case GIMPLE_TERNARY_RHS:
     528       106416 :       {
     529       106416 :         *op1_p = TREE_OPERAND (expr, 0);
     530       106416 :         *op2_p = TREE_OPERAND (expr, 1);
     531       106416 :         *op3_p = TREE_OPERAND (expr, 2);
     532       106416 :         break;
     533              :       }
     534     21528198 :     case GIMPLE_BINARY_RHS:
     535     21528198 :       {
     536     21528198 :         *op1_p = TREE_OPERAND (expr, 0);
     537     21528198 :         *op2_p = TREE_OPERAND (expr, 1);
     538     21528198 :         *op3_p = NULL_TREE;
     539     21528198 :         break;
     540              :       }
     541     11997509 :     case GIMPLE_UNARY_RHS:
     542     11997509 :       {
     543     11997509 :         *op1_p = TREE_OPERAND (expr, 0);
     544     11997509 :         *op2_p = NULL_TREE;
     545     11997509 :         *op3_p = NULL_TREE;
     546     11997509 :         break;
     547              :       }
     548    146123406 :     case GIMPLE_SINGLE_RHS:
     549    146123406 :       {
     550    146123406 :         *op1_p = expr;
     551    146123406 :         *op2_p = NULL_TREE;
     552    146123406 :         *op3_p = NULL_TREE;
     553    146123406 :         break;
     554              :       }
     555            0 :     default:
     556            0 :       gcc_unreachable ();
     557              :     }
     558    179755529 : }
     559              : 
     560              : /* Extract operands for a GIMPLE_COND statement out of COND_EXPR tree COND.  */
     561              : 
     562              : void
     563      6169997 : gimple_cond_get_ops_from_tree (tree cond, enum tree_code *code_p,
     564              :                                tree *lhs_p, tree *rhs_p)
     565              : {
     566      6169997 :   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      6169997 :   gcc_checking_assert (!tree_could_throw_p (cond));
     571              : 
     572      6169997 :   extract_ops_from_tree (cond, code_p, lhs_p, rhs_p);
     573              : 
     574              :   /* Canonicalize conditionals of the form 'if (!VAL)'.  */
     575      6169997 :   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      6169997 :   else if (TREE_CODE_CLASS (*code_p) != tcc_comparison)
     583              :     {
     584      1866687 :       *code_p = NE_EXPR;
     585      1866687 :       gcc_assert (*lhs_p && *rhs_p == NULL_TREE);
     586      1866687 :       *rhs_p = build_zero_cst (TREE_TYPE (*lhs_p));
     587              :     }
     588      6169997 : }
     589              : 
     590              : /*  Return true if T is a valid LHS for a GIMPLE assignment expression.  */
     591              : 
     592              : bool
     593    266469471 : is_gimple_lvalue (tree t)
     594              : {
     595    266469471 :   return (is_gimple_addressable (t)
     596     15219125 :           || TREE_CODE (t) == WITH_SIZE_EXPR
     597              :           /* These are complex lvalues, but don't have addresses, so they
     598              :              go here.  */
     599    281664506 :           || 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     10427187 : is_gimple_condexpr_1 (tree t, bool allow_traps, bool allow_cplx)
     606              : {
     607     10427187 :   tree op0;
     608     10427187 :   return (is_gimple_val (t)
     609     10427187 :           || (COMPARISON_CLASS_P (t)
     610      7157022 :               && (allow_traps || !tree_could_throw_p (t))
     611      7150005 :               && ((op0 = TREE_OPERAND (t, 0)), true)
     612      7150005 :               && (allow_cplx || TREE_CODE (TREE_TYPE (op0)) != COMPLEX_TYPE)
     613      7150005 :               && is_gimple_val (op0)
     614      5549012 :               && 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      6691828 : is_gimple_condexpr_for_cond (tree t)
     621              : {
     622      6691828 :   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      3735359 : canonicalize_cond_expr_cond (tree t)
     631              : {
     632              :   /* Strip conversions around boolean operations.  */
     633      3581914 :   if (CONVERT_EXPR_P (t)
     634      3735359 :       && (truth_value_p (TREE_CODE (TREE_OPERAND (t, 0)))
     635       152381 :           || TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0)))
     636              :              == BOOLEAN_TYPE))
     637         1078 :     t = TREE_OPERAND (t, 0);
     638              : 
     639              :   /* For !x use x == 0.  */
     640      3735359 :   if (TREE_CODE (t) == TRUTH_NOT_EXPR)
     641              :     {
     642        24311 :       tree top0 = TREE_OPERAND (t, 0);
     643        24311 :       t = build2 (EQ_EXPR, TREE_TYPE (t),
     644        24311 :                   top0, build_int_cst (TREE_TYPE (top0), 0));
     645              :     }
     646              :   /* For cmp ? 1 : 0 use cmp.  */
     647      3711048 :   else if (TREE_CODE (t) == COND_EXPR
     648       103207 :            && COMPARISON_CLASS_P (TREE_OPERAND (t, 0))
     649       101435 :            && integer_onep (TREE_OPERAND (t, 1))
     650      3812483 :            && integer_zerop (TREE_OPERAND (t, 2)))
     651              :     {
     652       101435 :       tree top0 = TREE_OPERAND (t, 0);
     653       101435 :       t = build2 (TREE_CODE (top0), TREE_TYPE (t),
     654       101435 :                   TREE_OPERAND (top0, 0), TREE_OPERAND (top0, 1));
     655              :     }
     656              :   /* For x ^ y use x != y.  */
     657      3609613 :   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      3735359 :   if (is_gimple_condexpr_1 (t, true, true))
     664      1314055 :     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   6020450550 : is_gimple_invariant_address (const_tree t)
     714              : {
     715   6020450550 :   const_tree op;
     716              : 
     717   6020450550 :   if (TREE_CODE (t) != ADDR_EXPR)
     718              :     return false;
     719              : 
     720   6020450550 :   op = strip_invariant_refs (TREE_OPERAND (t, 0));
     721   6020450550 :   if (!op)
     722              :     return false;
     723              : 
     724   6008084370 :   if (TREE_CODE (op) == MEM_REF)
     725              :     {
     726    490681827 :       const_tree op0 = TREE_OPERAND (op, 0);
     727    490681827 :       return (TREE_CODE (op0) == ADDR_EXPR
     728    490681827 :               && (CONSTANT_CLASS_P (TREE_OPERAND (op0, 0))
     729    164813023 :                   || decl_address_invariant_p (TREE_OPERAND (op0, 0))));
     730              :     }
     731              : 
     732   5517402543 :   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      2500529 : is_gimple_ip_invariant_address (const_tree t)
     740              : {
     741      2500529 :   const_tree op;
     742              : 
     743      2500529 :   if (TREE_CODE (t) != ADDR_EXPR)
     744              :     return false;
     745              : 
     746      2500529 :   op = strip_invariant_refs (TREE_OPERAND (t, 0));
     747      2500529 :   if (!op)
     748              :     return false;
     749              : 
     750      2499084 :   if (TREE_CODE (op) == MEM_REF)
     751              :     {
     752       121758 :       const_tree op0 = TREE_OPERAND (op, 0);
     753       121758 :       return (TREE_CODE (op0) == ADDR_EXPR
     754       121758 :               && (CONSTANT_CLASS_P (TREE_OPERAND (op0, 0))
     755        90843 :                   || decl_address_ip_invariant_p (TREE_OPERAND (op0, 0))));
     756              :     }
     757              : 
     758      2377326 :   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  23170004506 : is_gimple_min_invariant (const_tree t)
     766              : {
     767  23170004506 :   if (TREE_CODE (t) == ADDR_EXPR)
     768   6019193256 :     return is_gimple_invariant_address (t);
     769              : 
     770  17150811250 :   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     26740696 : is_gimple_ip_invariant (const_tree t)
     778              : {
     779     26740696 :   if (TREE_CODE (t) == ADDR_EXPR)
     780      2499309 :     return is_gimple_ip_invariant_address (t);
     781              : 
     782     24241387 :   return is_gimple_constant (t);
     783              : }
     784              : 
     785              : /* Return true if T is a non-aggregate register variable.  */
     786              : 
     787              : bool
     788  45750747341 : is_gimple_reg (tree t)
     789              : {
     790  79836392824 :   if (virtual_operand_p (t))
     791              :     return false;
     792              : 
     793  45596233955 :   if (TREE_CODE (t) == SSA_NAME)
     794              :     return true;
     795              : 
     796  16866172592 :   if (!is_gimple_variable (t))
     797              :     return false;
     798              : 
     799   5734601653 :   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   2259811594 :   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   2016796801 :   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   1184365346 :   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   1182917994 :   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   9271020892 : is_gimple_val (tree t)
     835              : {
     836              :   /* Make loads from volatiles and memory vars explicit.  */
     837   9271020892 :   if (is_gimple_variable (t)
     838   4932793687 :       && is_gimple_reg_type (TREE_TYPE (t))
     839  14178544216 :       && !is_gimple_reg (t))
     840              :     return false;
     841              : 
     842              :   /* These eventually expand into constants, so treat them like that.  */
     843   9260409623 :   if (TREE_CODE (t) == OMP_NEXT_VARIANT
     844   9260409623 :       || TREE_CODE (t) == OMP_TARGET_DEVICE_MATCHES)
     845              :     return true;
     846              : 
     847   9260409571 :   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        44019 : is_gimple_asm_val (tree t)
     854              : {
     855        44019 :   if (VAR_P (t) && DECL_HARD_REGISTER (t))
     856              :     return true;
     857              : 
     858        43141 :   return is_gimple_val (t);
     859              : }
     860              : 
     861              : /* Return true if T is a GIMPLE minimal lvalue.  */
     862              : 
     863              : bool
     864     30938551 : is_gimple_min_lval (tree t)
     865              : {
     866     30938551 :   if (!(t = const_cast<tree> (strip_invariant_refs (t))))
     867              :     return false;
     868     30938536 :   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   1071683392 : is_gimple_call_addr (tree t)
     875              : {
     876   1071683392 :   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   1443075962 : is_gimple_mem_ref_addr (tree t)
     883              : {
     884   1443075962 :   return (is_gimple_reg (t)
     885    396394437 :           || poly_int_tree_p (t)
     886   1839077250 :           || (TREE_CODE (t) == ADDR_EXPR
     887    393508718 :               && (CONSTANT_CLASS_P (TREE_OPERAND (t, 0))
     888    391405848 :                   || 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     11351739 : mark_addressable_1 (tree x)
     906              : {
     907     11351739 :   if (!currently_expanding_to_rtl)
     908              :     {
     909     11280001 :       TREE_ADDRESSABLE (x) = 1;
     910     11280001 :       return;
     911              :     }
     912              : 
     913        71738 :   if (!mark_addressable_queue)
     914        16796 :     mark_addressable_queue = new hash_set<tree>();
     915        71738 :   mark_addressable_queue->add (x);
     916              : }
     917              : 
     918              : /* Adaptor for mark_addressable_1 for use in hash_set traversal.  */
     919              : 
     920              : static bool
     921        47234 : mark_addressable_2 (tree const &x, void * ATTRIBUTE_UNUSED = NULL)
     922              : {
     923        47234 :   mark_addressable_1 (x);
     924        47234 :   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      1512163 : flush_mark_addressable_queue ()
     932              : {
     933      1512163 :   gcc_assert (!currently_expanding_to_rtl);
     934      1512163 :   if (mark_addressable_queue)
     935              :     {
     936        16796 :       mark_addressable_queue->traverse<void*, mark_addressable_2> (NULL);
     937        33592 :       delete mark_addressable_queue;
     938        16796 :       mark_addressable_queue = NULL;
     939              :     }
     940      1512163 : }
     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     34509786 : mark_addressable (tree x)
     947              : {
     948     34509786 :   if (TREE_CODE (x) == WITH_SIZE_EXPR)
     949            0 :     x = TREE_OPERAND (x, 0);
     950     40074520 :   while (handled_component_p (x))
     951      5564734 :     x = TREE_OPERAND (x, 0);
     952     34509786 :   if ((TREE_CODE (x) == MEM_REF
     953     34509786 :        || TREE_CODE (x) == TARGET_MEM_REF)
     954     34509786 :       && TREE_CODE (TREE_OPERAND (x, 0)) == ADDR_EXPR)
     955        11813 :     x = TREE_OPERAND (TREE_OPERAND (x, 0), 0);
     956     34509786 :   if (!VAR_P (x)
     957              :       && TREE_CODE (x) != PARM_DECL
     958              :       && TREE_CODE (x) != RESULT_DECL)
     959              :     return;
     960     11292320 :   mark_addressable_1 (x);
     961              : 
     962              :   /* Also mark the artificial SSA_NAME that points to the partition of X.  */
     963     11292320 :   if (VAR_P (x)
     964     10625481 :       && !DECL_EXTERNAL (x)
     965      9460699 :       && !TREE_STATIC (x)
     966      6061309 :       && cfun->gimple_df != NULL
     967     17353629 :       && cfun->gimple_df->decls_to_pointers != NULL)
     968              :     {
     969        19193 :       tree *namep = cfun->gimple_df->decls_to_pointers->get (x);
     970        19193 :       if (namep)
     971        12185 :         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       814410 : is_gimple_reg_rhs (tree t)
     980              : {
     981       814410 :   return get_gimple_rhs_class (TREE_CODE (t)) != GIMPLE_INVALID_RHS;
     982              : }
     983              : 
     984              : #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.