LCOV - code coverage report
Current view: top level - gcc - cfgexpand.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 88.3 % 3516 3103
Test Date: 2025-08-30 13:27:53 Functions: 92.4 % 105 97
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* A pass for lowering trees to RTL.
       2                 :             :    Copyright (C) 2004-2025 Free Software Foundation, Inc.
       3                 :             : 
       4                 :             : This file is part of GCC.
       5                 :             : 
       6                 :             : GCC is free software; you can redistribute it and/or modify
       7                 :             : it under the terms of the GNU General Public License as published by
       8                 :             : the Free Software Foundation; either version 3, or (at your option)
       9                 :             : any later version.
      10                 :             : 
      11                 :             : GCC is distributed in the hope that it will be useful,
      12                 :             : but WITHOUT ANY WARRANTY; without even the implied warranty of
      13                 :             : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14                 :             : GNU General Public License for more details.
      15                 :             : 
      16                 :             : You should have received a copy of the GNU General Public License
      17                 :             : along with GCC; see the file COPYING3.  If not see
      18                 :             : <http://www.gnu.org/licenses/>.  */
      19                 :             : 
      20                 :             : #include "config.h"
      21                 :             : #include "system.h"
      22                 :             : #include "coretypes.h"
      23                 :             : #include "backend.h"
      24                 :             : #include "target.h"
      25                 :             : #include "rtl.h"
      26                 :             : #include "tree.h"
      27                 :             : #include "gimple.h"
      28                 :             : #include "cfghooks.h"
      29                 :             : #include "tree-pass.h"
      30                 :             : #include "memmodel.h"
      31                 :             : #include "tm_p.h"
      32                 :             : #include "ssa.h"
      33                 :             : #include "optabs.h"
      34                 :             : #include "regs.h" /* For reg_renumber.  */
      35                 :             : #include "emit-rtl.h"
      36                 :             : #include "recog.h"
      37                 :             : #include "cgraph.h"
      38                 :             : #include "diagnostic.h"
      39                 :             : #include "fold-const.h"
      40                 :             : #include "varasm.h"
      41                 :             : #include "stor-layout.h"
      42                 :             : #include "stmt.h"
      43                 :             : #include "print-tree.h"
      44                 :             : #include "cfgrtl.h"
      45                 :             : #include "cfganal.h"
      46                 :             : #include "cfgbuild.h"
      47                 :             : #include "cfgcleanup.h"
      48                 :             : #include "dojump.h"
      49                 :             : #include "explow.h"
      50                 :             : #include "calls.h"
      51                 :             : #include "expr.h"
      52                 :             : #include "internal-fn.h"
      53                 :             : #include "tree-eh.h"
      54                 :             : #include "gimple-iterator.h"
      55                 :             : #include "gimple-expr.h"
      56                 :             : #include "gimple-walk.h"
      57                 :             : #include "tree-cfg.h"
      58                 :             : #include "tree-dfa.h"
      59                 :             : #include "tree-ssa.h"
      60                 :             : #include "except.h"
      61                 :             : #include "gimple-pretty-print.h"
      62                 :             : #include "toplev.h"
      63                 :             : #include "debug.h"
      64                 :             : #include "tree-inline.h"
      65                 :             : #include "value-prof.h"
      66                 :             : #include "tree-ssa-live.h"
      67                 :             : #include "tree-outof-ssa.h"
      68                 :             : #include "cfgloop.h"
      69                 :             : #include "insn-attr.h" /* For INSN_SCHEDULING.  */
      70                 :             : #include "stringpool.h"
      71                 :             : #include "attribs.h"
      72                 :             : #include "asan.h"
      73                 :             : #include "tree-ssa-address.h"
      74                 :             : #include "output.h"
      75                 :             : #include "builtins.h"
      76                 :             : #include "opts.h"
      77                 :             : #include "gimple-range.h"
      78                 :             : #include "rtl-iter.h"
      79                 :             : 
      80                 :             : /* Some systems use __main in a way incompatible with its use in gcc, in these
      81                 :             :    cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
      82                 :             :    give the same symbol without quotes for an alternative entry point.  You
      83                 :             :    must define both, or neither.  */
      84                 :             : #ifndef NAME__MAIN
      85                 :             : #define NAME__MAIN "__main"
      86                 :             : #endif
      87                 :             : 
      88                 :             : /* This variable holds information helping the rewriting of SSA trees
      89                 :             :    into RTL.  */
      90                 :             : struct ssaexpand SA;
      91                 :             : 
      92                 :             : /* This variable holds the currently expanded gimple statement for purposes
      93                 :             :    of comminucating the profile info to the builtin expanders.  */
      94                 :             : gimple *currently_expanding_gimple_stmt;
      95                 :             : 
      96                 :             : static rtx expand_debug_expr (tree);
      97                 :             : 
      98                 :             : static bool defer_stack_allocation (tree, bool);
      99                 :             : 
     100                 :             : static void record_alignment_for_reg_var (unsigned int);
     101                 :             : 
     102                 :             : /* Return an expression tree corresponding to the RHS of GIMPLE
     103                 :             :    statement STMT.  */
     104                 :             : 
     105                 :             : tree
     106                 :     3242926 : gimple_assign_rhs_to_tree (gimple *stmt)
     107                 :             : {
     108                 :     3242926 :   tree t;
     109                 :     3242926 :   switch (gimple_assign_rhs_class (stmt))
     110                 :             :     {
     111                 :         668 :     case GIMPLE_TERNARY_RHS:
     112                 :         668 :       t = build3 (gimple_assign_rhs_code (stmt),
     113                 :         668 :                   TREE_TYPE (gimple_assign_lhs (stmt)),
     114                 :             :                   gimple_assign_rhs1 (stmt), gimple_assign_rhs2 (stmt),
     115                 :             :                   gimple_assign_rhs3 (stmt));
     116                 :         668 :       break;
     117                 :     1107298 :     case GIMPLE_BINARY_RHS:
     118                 :     1107298 :       t = build2 (gimple_assign_rhs_code (stmt),
     119                 :     1107298 :                   TREE_TYPE (gimple_assign_lhs (stmt)),
     120                 :             :                   gimple_assign_rhs1 (stmt), gimple_assign_rhs2 (stmt));
     121                 :     1107298 :       break;
     122                 :      363205 :     case GIMPLE_UNARY_RHS:
     123                 :      363205 :       t = build1 (gimple_assign_rhs_code (stmt),
     124                 :      363205 :                   TREE_TYPE (gimple_assign_lhs (stmt)),
     125                 :             :                   gimple_assign_rhs1 (stmt));
     126                 :      363205 :       break;
     127                 :     1771755 :     case GIMPLE_SINGLE_RHS:
     128                 :     1771755 :       {
     129                 :     1771755 :         t = gimple_assign_rhs1 (stmt);
     130                 :             :         /* Avoid modifying this tree in place below.  */
     131                 :     3462447 :         if ((gimple_has_location (stmt) && CAN_HAVE_LOCATION_P (t)
     132                 :     1648347 :              && gimple_location (stmt) != EXPR_LOCATION (t))
     133                 :     1977682 :             || (gimple_block (stmt) && currently_expanding_to_rtl
     134                 :       46142 :                 && EXPR_P (t)))
     135                 :     1517076 :           t = copy_node (t);
     136                 :             :         break;
     137                 :             :       }
     138                 :           0 :     default:
     139                 :           0 :       gcc_unreachable ();
     140                 :             :     }
     141                 :             : 
     142                 :     3242926 :   if (gimple_has_location (stmt) && CAN_HAVE_LOCATION_P (t))
     143                 :     3047231 :     SET_EXPR_LOCATION (t, gimple_location (stmt));
     144                 :             : 
     145                 :     3242926 :   return t;
     146                 :             : }
     147                 :             : 
     148                 :             : 
     149                 :             : #ifndef STACK_ALIGNMENT_NEEDED
     150                 :             : #define STACK_ALIGNMENT_NEEDED 1
     151                 :             : #endif
     152                 :             : 
     153                 :             : #define SSAVAR(x) (TREE_CODE (x) == SSA_NAME ? SSA_NAME_VAR (x) : x)
     154                 :             : 
     155                 :             : /* Choose either CUR or NEXT as the leader DECL for a partition.
     156                 :             :    Prefer ignored decls, to simplify debug dumps and reduce ambiguity
     157                 :             :    out of the same user variable being in multiple partitions (this is
     158                 :             :    less likely for compiler-introduced temps).  */
     159                 :             : 
     160                 :             : static tree
     161                 :    59429237 : leader_merge (tree cur, tree next)
     162                 :             : {
     163                 :    59429237 :   if (cur == NULL || cur == next)
     164                 :             :     return next;
     165                 :             : 
     166                 :     3197751 :   if (DECL_P (cur) && DECL_IGNORED_P (cur))
     167                 :             :     return cur;
     168                 :             : 
     169                 :     2379808 :   if (DECL_P (next) && DECL_IGNORED_P (next))
     170                 :      156883 :     return next;
     171                 :             : 
     172                 :             :   return cur;
     173                 :             : }
     174                 :             : 
     175                 :             : /* Associate declaration T with storage space X.  If T is no
     176                 :             :    SSA name this is exactly SET_DECL_RTL, otherwise make the
     177                 :             :    partition of T associated with X.  */
     178                 :             : static inline void
     179                 :    70281744 : set_rtl (tree t, rtx x)
     180                 :             : {
     181                 :    70281744 :   gcc_checking_assert (!x
     182                 :             :                        || !(TREE_CODE (t) == SSA_NAME || is_gimple_reg (t))
     183                 :             :                        || (use_register_for_decl (t)
     184                 :             :                            ? (REG_P (x)
     185                 :             :                               || (GET_CODE (x) == CONCAT
     186                 :             :                                   && (REG_P (XEXP (x, 0))
     187                 :             :                                       || SUBREG_P (XEXP (x, 0)))
     188                 :             :                                   && (REG_P (XEXP (x, 1))
     189                 :             :                                       || SUBREG_P (XEXP (x, 1))))
     190                 :             :                               /* We need to accept PARALLELs for RESUT_DECLs
     191                 :             :                                  because of vector types with BLKmode returned
     192                 :             :                                  in multiple registers, but they are supposed
     193                 :             :                                  to be uncoalesced.  */
     194                 :             :                               || (GET_CODE (x) == PARALLEL
     195                 :             :                                   && SSAVAR (t)
     196                 :             :                                   && TREE_CODE (SSAVAR (t)) == RESULT_DECL
     197                 :             :                                   && (GET_MODE (x) == BLKmode
     198                 :             :                                       || !flag_tree_coalesce_vars)))
     199                 :             :                            : (MEM_P (x) || x == pc_rtx
     200                 :             :                               || (GET_CODE (x) == CONCAT
     201                 :             :                                   && MEM_P (XEXP (x, 0))
     202                 :             :                                   && MEM_P (XEXP (x, 1))))));
     203                 :             :   /* Check that the RTL for SSA_NAMEs and gimple-reg PARM_DECLs and
     204                 :             :      RESULT_DECLs has the expected mode.  For memory, we accept
     205                 :             :      unpromoted modes, since that's what we're likely to get.  For
     206                 :             :      PARM_DECLs and RESULT_DECLs, we'll have been called by
     207                 :             :      set_parm_rtl, which will give us the default def, so we don't
     208                 :             :      have to compute it ourselves.  For RESULT_DECLs, we accept mode
     209                 :             :      mismatches too, as long as we have BLKmode or are not coalescing
     210                 :             :      across variables, so that we don't reject BLKmode PARALLELs or
     211                 :             :      unpromoted REGs.  */
     212                 :    65104527 :   gcc_checking_assert (!x || x == pc_rtx || TREE_CODE (t) != SSA_NAME
     213                 :             :                        || (SSAVAR (t)
     214                 :             :                            && TREE_CODE (SSAVAR (t)) == RESULT_DECL
     215                 :             :                            && (promote_ssa_mode (t, NULL) == BLKmode
     216                 :             :                                || !flag_tree_coalesce_vars))
     217                 :             :                        || !use_register_for_decl (t)
     218                 :             :                        || GET_MODE (x) == promote_ssa_mode (t, NULL));
     219                 :             : 
     220                 :             :   if (x)
     221                 :             :     {
     222                 :    65495752 :       bool skip = false;
     223                 :    65495752 :       tree cur = NULL_TREE;
     224                 :             :       rtx xm = x;
     225                 :             : 
     226                 :    65495752 :     retry:
     227                 :    65495752 :       if (MEM_P (xm))
     228                 :     4696681 :         cur = MEM_EXPR (xm);
     229                 :             :       else if (REG_P (xm))
     230                 :    54732556 :         cur = REG_EXPR (xm);
     231                 :             :       else if (SUBREG_P (xm))
     232                 :             :         {
     233                 :           0 :           gcc_assert (subreg_lowpart_p (xm));
     234                 :           0 :           xm = SUBREG_REG (xm);
     235                 :           0 :           goto retry;
     236                 :             :         }
     237                 :             :       else if (GET_CODE (xm) == CONCAT)
     238                 :             :         {
     239                 :      388110 :           xm = XEXP (xm, 0);
     240                 :      388110 :           goto retry;
     241                 :             :         }
     242                 :             :       else if (GET_CODE (xm) == PARALLEL)
     243                 :             :         {
     244                 :        3115 :           xm = XVECEXP (xm, 0, 0);
     245                 :        3115 :           gcc_assert (GET_CODE (xm) == EXPR_LIST);
     246                 :        3115 :           xm = XEXP (xm, 0);
     247                 :        3115 :           goto retry;
     248                 :             :         }
     249                 :     5675290 :       else if (xm == pc_rtx)
     250                 :             :         skip = true;
     251                 :             :       else
     252                 :           0 :         gcc_unreachable ();
     253                 :             : 
     254                 :    59429237 :       tree next = skip ? cur : leader_merge (cur, SSAVAR (t) ? SSAVAR (t) : t);
     255                 :             : 
     256                 :    65104527 :       if (cur != next)
     257                 :             :         {
     258                 :    27456163 :           if (MEM_P (x))
     259                 :     3959244 :             set_mem_attributes (x,
     260                 :     1979622 :                                 next && TREE_CODE (next) == SSA_NAME
     261                 :       12246 :                                 ? TREE_TYPE (next)
     262                 :             :                                 : next, true);
     263                 :             :           else
     264                 :    25476541 :             set_reg_attrs_for_decl_rtl (next, x);
     265                 :             :         }
     266                 :             :     }
     267                 :             : 
     268                 :    70281744 :   if (TREE_CODE (t) == SSA_NAME)
     269                 :             :     {
     270                 :    56943080 :       int part = var_to_partition (SA.map, t);
     271                 :    56943080 :       if (part != NO_PARTITION)
     272                 :             :         {
     273                 :    56943080 :           if (SA.partition_to_pseudo[part])
     274                 :    31171583 :             gcc_assert (SA.partition_to_pseudo[part] == x);
     275                 :    25771497 :           else if (x != pc_rtx)
     276                 :    25768574 :             SA.partition_to_pseudo[part] = x;
     277                 :             :         }
     278                 :             :       /* For the benefit of debug information at -O0 (where
     279                 :             :          vartracking doesn't run) record the place also in the base
     280                 :             :          DECL.  For PARMs and RESULTs, do so only when setting the
     281                 :             :          default def.  */
     282                 :   113883237 :       if (x && x != pc_rtx && SSA_NAME_VAR (t)
     283                 :    74767512 :           && (VAR_P (SSA_NAME_VAR (t))
     284                 :     7344616 :               || SSA_NAME_IS_DEFAULT_DEF (t)))
     285                 :             :         {
     286                 :    17644048 :           tree var = SSA_NAME_VAR (t);
     287                 :             :           /* If we don't yet have something recorded, just record it now.  */
     288                 :    17644048 :           if (!DECL_RTL_SET_P (var))
     289                 :     7440558 :             SET_DECL_RTL (var, x);
     290                 :             :           /* If we have it set already to "multiple places" don't
     291                 :             :              change this.  */
     292                 :    10203490 :           else if (DECL_RTL (var) == pc_rtx)
     293                 :             :             ;
     294                 :             :           /* If we have something recorded and it's not the same place
     295                 :             :              as we want to record now, we have multiple partitions for the
     296                 :             :              same base variable, with different places.  We can't just
     297                 :             :              randomly chose one, hence we have to say that we don't know.
     298                 :             :              This only happens with optimization, and there var-tracking
     299                 :             :              will figure out the right thing.  */
     300                 :     9099050 :           else if (DECL_RTL (var) != x)
     301                 :      232306 :             SET_DECL_RTL (var, pc_rtx);
     302                 :             :         }
     303                 :             :     }
     304                 :             :   else
     305                 :    13338664 :     SET_DECL_RTL (t, x);
     306                 :    70281744 : }
     307                 :             : 
     308                 :             : /* This structure holds data relevant to one variable that will be
     309                 :             :    placed in a stack slot.  */
     310                 :             : class stack_var
     311                 :             : {
     312                 :             : public:
     313                 :             :   /* The Variable.  */
     314                 :             :   tree decl;
     315                 :             : 
     316                 :             :   /* Initially, the size of the variable.  Later, the size of the partition,
     317                 :             :      if this variable becomes it's partition's representative.  */
     318                 :             :   poly_uint64 size;
     319                 :             : 
     320                 :             :   /* The *byte* alignment required for this variable.  Or as, with the
     321                 :             :      size, the alignment for this partition.  */
     322                 :             :   unsigned int alignb;
     323                 :             : 
     324                 :             :   /* The partition representative.  */
     325                 :             :   unsigned representative;
     326                 :             : 
     327                 :             :   /* The next stack variable in the partition, or EOC.  */
     328                 :             :   unsigned next;
     329                 :             : 
     330                 :             :   /* The numbers of conflicting stack variables.  */
     331                 :             :   bitmap conflicts;
     332                 :             : };
     333                 :             : 
     334                 :             : #define EOC  ((unsigned)-1)
     335                 :             : 
     336                 :             : /* We have an array of such objects while deciding allocation.  */
     337                 :             : static class stack_var *stack_vars;
     338                 :             : static unsigned stack_vars_alloc;
     339                 :             : static unsigned stack_vars_num;
     340                 :             : static hash_map<tree, unsigned> *decl_to_stack_part;
     341                 :             : 
     342                 :             : #define INVALID_STACK_INDEX ((unsigned)-1)
     343                 :             : 
     344                 :             : /* Conflict bitmaps go on this obstack.  This allows us to destroy
     345                 :             :    all of them in one big sweep.  */
     346                 :             : static bitmap_obstack stack_var_bitmap_obstack;
     347                 :             : 
     348                 :             : /* An array of indices such that stack_vars[stack_vars_sorted[i]].size
     349                 :             :    is non-decreasing.  */
     350                 :             : static unsigned *stack_vars_sorted;
     351                 :             : 
     352                 :             : /* The phase of the stack frame.  This is the known misalignment of
     353                 :             :    virtual_stack_vars_rtx from PREFERRED_STACK_BOUNDARY.  That is,
     354                 :             :    (frame_offset+frame_phase) % PREFERRED_STACK_BOUNDARY == 0.  */
     355                 :             : static int frame_phase;
     356                 :             : 
     357                 :             : /* Used during expand_used_vars to remember if we saw any decls for
     358                 :             :    which we'd like to enable stack smashing protection.  */
     359                 :             : static bool has_protected_decls;
     360                 :             : 
     361                 :             : /* Used during expand_used_vars.  Remember if we say a character buffer
     362                 :             :    smaller than our cutoff threshold.  Used for -Wstack-protector.  */
     363                 :             : static bool has_short_buffer;
     364                 :             : 
     365                 :             : /* Compute the byte alignment to use for DECL.  Ignore alignment
     366                 :             :    we can't do with expected alignment of the stack boundary.  */
     367                 :             : 
     368                 :             : static unsigned int
     369                 :     6465183 : align_local_variable (tree decl, bool really_expand)
     370                 :             : {
     371                 :     6465183 :   unsigned int align;
     372                 :             : 
     373                 :     6465183 :   if (TREE_CODE (decl) == SSA_NAME)
     374                 :             :     {
     375                 :      442628 :       tree type = TREE_TYPE (decl);
     376                 :      442628 :       machine_mode mode = TYPE_MODE (type);
     377                 :             : 
     378                 :      442628 :       align = TYPE_ALIGN (type);
     379                 :      442628 :       if (mode != BLKmode
     380                 :      442628 :           && align < GET_MODE_ALIGNMENT (mode))
     381                 :         457 :         align = GET_MODE_ALIGNMENT (mode);
     382                 :             :     }
     383                 :             :   else
     384                 :     6022555 :     align = LOCAL_DECL_ALIGNMENT (decl);
     385                 :             : 
     386                 :     6465183 :   if (hwasan_sanitize_stack_p ())
     387                 :         267 :     align = MAX (align, (unsigned) HWASAN_TAG_GRANULE_SIZE * BITS_PER_UNIT);
     388                 :             : 
     389                 :     6465183 :   if (TREE_CODE (decl) != SSA_NAME && really_expand)
     390                 :             :     /* Don't change DECL_ALIGN when called from estimated_stack_frame_size.
     391                 :             :        That is done before IPA and could bump alignment based on host
     392                 :             :        backend even for offloaded code which wants different
     393                 :             :        LOCAL_DECL_ALIGNMENT.  */
     394                 :     1528919 :     SET_DECL_ALIGN (decl, align);
     395                 :             : 
     396                 :     6465183 :   return align / BITS_PER_UNIT;
     397                 :             : }
     398                 :             : 
     399                 :             : /* Align given offset BASE with ALIGN.  Truncate up if ALIGN_UP is true,
     400                 :             :    down otherwise.  Return truncated BASE value.  */
     401                 :             : 
     402                 :             : static inline unsigned HOST_WIDE_INT
     403                 :             : align_base (HOST_WIDE_INT base, unsigned HOST_WIDE_INT align, bool align_up)
     404                 :             : {
     405                 :             :   return align_up ? (base + align - 1) & -align : base & -align;
     406                 :             : }
     407                 :             : 
     408                 :             : /* Allocate SIZE bytes at byte alignment ALIGN from the stack frame.
     409                 :             :    Return the frame offset.  */
     410                 :             : 
     411                 :             : static poly_int64
     412                 :     1719859 : alloc_stack_frame_space (poly_int64 size, unsigned HOST_WIDE_INT align)
     413                 :             : {
     414                 :     1719859 :   poly_int64 offset, new_frame_offset;
     415                 :             : 
     416                 :     1719859 :   if (FRAME_GROWS_DOWNWARD)
     417                 :             :     {
     418                 :     1719859 :       new_frame_offset
     419                 :     1719859 :         = aligned_lower_bound (frame_offset - frame_phase - size,
     420                 :     1719859 :                                align) + frame_phase;
     421                 :     1719859 :       offset = new_frame_offset;
     422                 :             :     }
     423                 :             :   else
     424                 :             :     {
     425                 :             :       new_frame_offset
     426                 :             :         = aligned_upper_bound (frame_offset - frame_phase,
     427                 :             :                                align) + frame_phase;
     428                 :             :       offset = new_frame_offset;
     429                 :             :       new_frame_offset += size;
     430                 :             :     }
     431                 :     1719859 :   frame_offset = new_frame_offset;
     432                 :             : 
     433                 :     1719859 :   if (frame_offset_overflow (frame_offset, cfun->decl))
     434                 :           0 :     frame_offset = offset = 0;
     435                 :             : 
     436                 :     1719859 :   return offset;
     437                 :             : }
     438                 :             : 
     439                 :             : /* Ensure that the stack is aligned to ALIGN bytes.
     440                 :             :    Return the new frame offset.  */
     441                 :             : static poly_int64
     442                 :        1769 : align_frame_offset (unsigned HOST_WIDE_INT align)
     443                 :             : {
     444                 :           0 :   return alloc_stack_frame_space (0, align);
     445                 :             : }
     446                 :             : 
     447                 :             : /* Accumulate DECL into STACK_VARS.  */
     448                 :             : 
     449                 :             : static void
     450                 :     5675290 : add_stack_var (tree decl, bool really_expand)
     451                 :             : {
     452                 :     5675290 :   class stack_var *v;
     453                 :             : 
     454                 :     5675290 :   if (stack_vars_num >= stack_vars_alloc)
     455                 :             :     {
     456                 :     1345781 :       if (stack_vars_alloc)
     457                 :       33625 :         stack_vars_alloc = stack_vars_alloc * 3 / 2;
     458                 :             :       else
     459                 :     1312156 :         stack_vars_alloc = 32;
     460                 :     1345781 :       stack_vars
     461                 :     1345781 :         = XRESIZEVEC (class stack_var, stack_vars, stack_vars_alloc);
     462                 :             :     }
     463                 :     5675290 :   if (!decl_to_stack_part)
     464                 :           0 :     decl_to_stack_part = new hash_map<tree, unsigned>;
     465                 :             : 
     466                 :     5675290 :   v = &stack_vars[stack_vars_num];
     467                 :     5675290 :   decl_to_stack_part->put (decl, stack_vars_num);
     468                 :             : 
     469                 :     5675290 :   v->decl = decl;
     470                 :     5675290 :   tree size = TREE_CODE (decl) == SSA_NAME
     471                 :     5675290 :     ? TYPE_SIZE_UNIT (TREE_TYPE (decl))
     472                 :     5675290 :     : DECL_SIZE_UNIT (decl);
     473                 :     5675290 :   v->size = tree_to_poly_uint64 (size);
     474                 :             :   /* Ensure that all variables have size, so that &a != &b for any two
     475                 :             :      variables that are simultaneously live.  */
     476                 :     5675290 :   if (known_eq (v->size, 0U))
     477                 :       24105 :     v->size = 1;
     478                 :     5675290 :   v->alignb = align_local_variable (decl, really_expand);
     479                 :             :   /* An alignment of zero can mightily confuse us later.  */
     480                 :     5675290 :   gcc_assert (v->alignb != 0);
     481                 :             : 
     482                 :             :   /* All variables are initially in their own partition.  */
     483                 :     5675290 :   v->representative = stack_vars_num;
     484                 :     5675290 :   v->next = EOC;
     485                 :             : 
     486                 :             :   /* All variables initially conflict with no other.  */
     487                 :     5675290 :   v->conflicts = NULL;
     488                 :             : 
     489                 :             :   /* Ensure that this decl doesn't get put onto the list twice.  */
     490                 :     5675290 :   set_rtl (decl, pc_rtx);
     491                 :             : 
     492                 :     5675290 :   stack_vars_num++;
     493                 :     5675290 : }
     494                 :             : 
     495                 :             : /* Make the decls associated with luid's X and Y conflict.  */
     496                 :             : 
     497                 :             : static void
     498                 :    11014882 : add_stack_var_conflict (unsigned x, unsigned y)
     499                 :             : {
     500                 :    11014882 :   class stack_var *a = &stack_vars[x];
     501                 :    11014882 :   class stack_var *b = &stack_vars[y];
     502                 :    11014882 :   if (x == y)
     503                 :             :     return;
     504                 :     9962105 :   if (!a->conflicts)
     505                 :      628714 :     a->conflicts = BITMAP_ALLOC (&stack_var_bitmap_obstack);
     506                 :     9962105 :   if (!b->conflicts)
     507                 :      110657 :     b->conflicts = BITMAP_ALLOC (&stack_var_bitmap_obstack);
     508                 :     9962105 :   bitmap_set_bit (a->conflicts, y);
     509                 :     9962105 :   bitmap_set_bit (b->conflicts, x);
     510                 :             : }
     511                 :             : 
     512                 :             : /* Check whether the decls associated with luid's X and Y conflict.  */
     513                 :             : 
     514                 :             : static bool
     515                 :    11211207 : stack_var_conflict_p (unsigned x, unsigned y)
     516                 :             : {
     517                 :    11211207 :   class stack_var *a = &stack_vars[x];
     518                 :    11211207 :   class stack_var *b = &stack_vars[y];
     519                 :    11211207 :   if (x == y)
     520                 :             :     return false;
     521                 :             :   /* Partitions containing an SSA name result from gimple registers
     522                 :             :      with things like unsupported modes.  They are top-level and
     523                 :             :      hence conflict with everything else.  */
     524                 :    11211207 :   if (TREE_CODE (a->decl) == SSA_NAME || TREE_CODE (b->decl) == SSA_NAME)
     525                 :             :     return true;
     526                 :             : 
     527                 :    11176787 :   if (!a->conflicts || !b->conflicts)
     528                 :             :     return false;
     529                 :    11120783 :   return bitmap_bit_p (a->conflicts, y);
     530                 :             : }
     531                 :             : 
     532                 :             : /* Returns the DECL's index into the stack_vars array.
     533                 :             :    If the DECL does not exist return INVALID_STACK_INDEX.  */
     534                 :             : static unsigned
     535                 :    46110908 : decl_stack_index (tree decl)
     536                 :             : {
     537                 :    46110908 :   if (!decl)
     538                 :             :     return INVALID_STACK_INDEX;
     539                 :    46110908 :   if (!DECL_P (decl))
     540                 :             :     return INVALID_STACK_INDEX;
     541                 :    35500030 :   if (DECL_RTL_IF_SET (decl) != pc_rtx)
     542                 :             :     return INVALID_STACK_INDEX;
     543                 :    24011706 :   unsigned *v = decl_to_stack_part->get (decl);
     544                 :    24011706 :   if (!v)
     545                 :             :     return INVALID_STACK_INDEX;
     546                 :             : 
     547                 :    24011706 :   unsigned indx = *v;
     548                 :    24011706 :   gcc_checking_assert (indx != INVALID_STACK_INDEX);
     549                 :    24011706 :   gcc_checking_assert (indx < stack_vars_num);
     550                 :             :   return indx;
     551                 :             : }
     552                 :             : 
     553                 :             : /* Callback for walk_stmt_ops.  If OP is a decl touched by add_stack_var
     554                 :             :    enter its partition number into bitmap DATA.  */
     555                 :             : 
     556                 :             : static bool
     557                 :    29482790 : visit_op (gimple *, tree op, tree, void *data)
     558                 :             : {
     559                 :    29482790 :   bitmap active = (bitmap)data;
     560                 :    29482790 :   op = get_base_address (op);
     561                 :    29482790 :   unsigned idx = decl_stack_index (op);
     562                 :    29482790 :   if (idx != INVALID_STACK_INDEX)
     563                 :    14820818 :     bitmap_set_bit (active, idx);
     564                 :    29482790 :   return false;
     565                 :             : }
     566                 :             : 
     567                 :             : /* Callback for walk_stmt_ops.  If OP is a decl touched by add_stack_var
     568                 :             :    record conflicts between it and all currently active other partitions
     569                 :             :    from bitmap DATA.  */
     570                 :             : 
     571                 :             : static bool
     572                 :    13430831 : visit_conflict (gimple *, tree op, tree, void *data)
     573                 :             : {
     574                 :    13430831 :   bitmap active = (bitmap)data;
     575                 :    13430831 :   op = get_base_address (op);
     576                 :    13430831 :   unsigned num = decl_stack_index (op);
     577                 :    13430831 :   if (num != INVALID_STACK_INDEX
     578                 :    13430831 :       && bitmap_set_bit (active, num))
     579                 :             :     {
     580                 :      972987 :       bitmap_iterator bi;
     581                 :      972987 :       unsigned i;
     582                 :      972987 :       gcc_assert (num < stack_vars_num);
     583                 :    10611233 :       EXECUTE_IF_SET_IN_BITMAP (active, 0, i, bi)
     584                 :     9638246 :         add_stack_var_conflict (num, i);
     585                 :             :     }
     586                 :    13430831 :   return false;
     587                 :             : }
     588                 :             : 
     589                 :             : /* A cache for ssa name to address of stack variables.
     590                 :             :    When taking into account if a ssa name refers to an
     591                 :             :    address of a stack variable, we need to walk the
     592                 :             :    expressions backwards to find the addresses. This
     593                 :             :    cache is there so we don't need to walk the expressions
     594                 :             :    all the time.  */
     595                 :             : struct vars_ssa_cache
     596                 :             : {
     597                 :             : private:
     598                 :             :   /* Currently an entry is a bitmap of all of the known stack variables
     599                 :             :      addresses that are referenced by the ssa name.
     600                 :             :      When the bitmap is the nullptr, then there is no cache.
     601                 :             :      Currently only empty bitmaps are shared.
     602                 :             :      The reason for why empty cache is not just a null is so we know the
     603                 :             :      cache for an entry is filled in.  */
     604                 :             :   struct entry
     605                 :             :   {
     606                 :             :     bitmap bmap = nullptr;
     607                 :             :   };
     608                 :             :   entry *vars_ssa_caches;
     609                 :             : public:
     610                 :             : 
     611                 :             :   vars_ssa_cache();
     612                 :             :   ~vars_ssa_cache();
     613                 :             :   const_bitmap operator() (tree name);
     614                 :             :   void dump (FILE *file);
     615                 :             : 
     616                 :             : private:
     617                 :             :   /* Can't copy. */
     618                 :             :   vars_ssa_cache(const vars_ssa_cache&) = delete;
     619                 :             :   vars_ssa_cache(vars_ssa_cache&&) = delete;
     620                 :             : 
     621                 :             :   /* The shared empty bitmap.  */
     622                 :             :   bitmap empty;
     623                 :             : 
     624                 :             :   /* Unshare the index, currently only need
     625                 :             :      to unshare if the entry was empty. */
     626                 :     1142013 :   void unshare(int indx)
     627                 :             :   {
     628                 :     1142013 :     if (vars_ssa_caches[indx].bmap == empty)
     629                 :      476742 :         vars_ssa_caches[indx].bmap = BITMAP_ALLOC (&stack_var_bitmap_obstack);
     630                 :     1142013 :   }
     631                 :             :   void create (tree);
     632                 :             :   bool exists (tree use);
     633                 :             :   void add_one (tree old_name, unsigned);
     634                 :             :   bool update (tree old_name, tree use);
     635                 :             : };
     636                 :             : 
     637                 :             : /* Constructor of the cache, create the cache array. */
     638                 :      146937 : vars_ssa_cache::vars_ssa_cache ()
     639                 :             : {
     640                 :    31950153 :   vars_ssa_caches = new entry[num_ssa_names]{};
     641                 :             : 
     642                 :             :   /* Create the shared empty bitmap too. */
     643                 :      146937 :   empty = BITMAP_ALLOC (&stack_var_bitmap_obstack);
     644                 :      146937 : }
     645                 :             : 
     646                 :             : /* Delete the array. The bitmaps will be freed
     647                 :             :    when stack_var_bitmap_obstack is freed.  */
     648                 :      146937 : vars_ssa_cache::~vars_ssa_cache ()
     649                 :             : {
     650                 :      146937 :   delete []vars_ssa_caches;
     651                 :      146937 : }
     652                 :             : 
     653                 :             : /* Create an empty entry for the USE ssa name.  */
     654                 :             : void
     655                 :    10793725 : vars_ssa_cache::create (tree use)
     656                 :             : {
     657                 :    10793725 :   int num = SSA_NAME_VERSION (use);
     658                 :    10793725 :   if (vars_ssa_caches[num].bmap)
     659                 :             :     return;
     660                 :    10793725 :   vars_ssa_caches[num].bmap = empty;
     661                 :             : }
     662                 :             : 
     663                 :             : /* Returns true if the cache for USE exists.  */
     664                 :             : bool
     665                 :    70471499 : vars_ssa_cache::exists (tree use)
     666                 :             : {
     667                 :    70471499 :   int num = SSA_NAME_VERSION (use);
     668                 :    70471499 :   return vars_ssa_caches[num].bmap != nullptr;
     669                 :             : }
     670                 :             : 
     671                 :             : /* Add to USE's bitmap for stack variable IDX.  */
     672                 :             : void
     673                 :      165140 : vars_ssa_cache::add_one (tree use, unsigned idx)
     674                 :             : {
     675                 :      165140 :   gcc_assert (idx != INVALID_STACK_INDEX);
     676                 :      165140 :   int num = SSA_NAME_VERSION (use);
     677                 :      165140 :   gcc_assert (vars_ssa_caches[num].bmap);
     678                 :      165140 :   unshare (num);
     679                 :      165140 :   bitmap_set_bit (vars_ssa_caches[num].bmap, idx);
     680                 :      165140 : }
     681                 :             : 
     682                 :             : /* Update cache of OLD_NAME from the USE's cache. */
     683                 :             : bool
     684                 :    25130174 : vars_ssa_cache::update (tree old_name, tree use)
     685                 :             : {
     686                 :    25130174 :   if (old_name == use)
     687                 :             :     return false;
     688                 :    16117403 :   int num = SSA_NAME_VERSION (use);
     689                 :    16117403 :   int old_num = SSA_NAME_VERSION (old_name);
     690                 :             : 
     691                 :             :   /* If the old name was empty, then there is nothing to be updated. */
     692                 :    16117403 :   if (vars_ssa_caches[num].bmap == empty)
     693                 :             :     return false;
     694                 :      976873 :   unshare (old_num);
     695                 :      976873 :   return bitmap_ior_into (vars_ssa_caches[old_num].bmap, vars_ssa_caches[num].bmap);
     696                 :             : }
     697                 :             : 
     698                 :             : /* Dump out the cache. Note empty and non-filled
     699                 :             :    in ssa names are not printed out. */
     700                 :             : void
     701                 :           0 : vars_ssa_cache::dump (FILE *file)
     702                 :             : {
     703                 :           0 :   fprintf (file, "var ssa address cache\n");
     704                 :           0 :   for (unsigned num = 0; num < num_ssa_names; num++)
     705                 :             :     {
     706                 :           0 :       if (!vars_ssa_caches[num].bmap
     707                 :           0 :           || vars_ssa_caches[num].bmap == empty)
     708                 :           0 :         continue;
     709                 :           0 :       fprintf (file, "_%d refers to:\n", num);
     710                 :           0 :       bitmap_iterator bi;
     711                 :           0 :       unsigned i;
     712                 :           0 :       EXECUTE_IF_SET_IN_BITMAP (vars_ssa_caches[num].bmap, 0, i, bi)
     713                 :             :         {
     714                 :           0 :           fputc ('\t', file);
     715                 :           0 :           print_generic_expr (file, stack_vars[i].decl, dump_flags);
     716                 :             :         }
     717                 :           0 :       fputc ('\n', file);
     718                 :             :   }
     719                 :           0 :   fputc ('\n', file);
     720                 :           0 : }
     721                 :             : 
     722                 :             : /* Returns the filled in cache for NAME.
     723                 :             :    This will fill in the cache if it does not exist already.
     724                 :             :    Returns an empty for ssa names that can't contain pointers
     725                 :             :    (only intergal types and pointer types will contain pointers).  */
     726                 :             : 
     727                 :             : const_bitmap
     728                 :    55066627 : vars_ssa_cache::operator() (tree name)
     729                 :             : {
     730                 :    55066627 :   gcc_assert (TREE_CODE (name) == SSA_NAME);
     731                 :             : 
     732                 :    90824359 :   if (!POINTER_TYPE_P (TREE_TYPE (name))
     733                 :    89681173 :       && !ANY_INTEGRAL_TYPE_P (TREE_TYPE (name)))
     734                 :     2442955 :     return empty;
     735                 :             : 
     736                 :    52623672 :   if (exists (name))
     737                 :    43656943 :     return vars_ssa_caches[SSA_NAME_VERSION (name)].bmap;
     738                 :             : 
     739                 :     8966729 :   auto_vec<std::pair<tree,tree>, 4> work_list;
     740                 :     8966729 :   auto_vec<std::pair<tree,tree>, 4> update_cache_list;
     741                 :             : 
     742                 :     8966729 :   work_list.safe_push (std::make_pair (name, name));
     743                 :             : 
     744                 :    33186156 :   while (!work_list.is_empty ())
     745                 :             :     {
     746                 :    24219427 :       auto item = work_list.pop();
     747                 :    24219427 :       tree use = item.first;
     748                 :    24219427 :       tree old_name = item.second;
     749                 :    24219427 :       if (TREE_CODE (use) == ADDR_EXPR)
     750                 :             :         {
     751                 :      424381 :           tree op = TREE_OPERAND (use, 0);
     752                 :      424381 :           op = get_base_address (op);
     753                 :      424381 :           unsigned idx = decl_stack_index (op);
     754                 :      424381 :           if (idx != INVALID_STACK_INDEX)
     755                 :      165140 :             add_one (old_name, idx);
     756                 :    13425702 :           continue;
     757                 :      424381 :         }
     758                 :             : 
     759                 :    23795046 :       if (TREE_CODE (use) != SSA_NAME)
     760                 :     5871788 :         continue;
     761                 :             : 
     762                 :    31239514 :       if (!POINTER_TYPE_P (TREE_TYPE (use))
     763                 :    31119966 :           && !ANY_INTEGRAL_TYPE_P (TREE_TYPE (use)))
     764                 :       75431 :         continue;
     765                 :             : 
     766                 :             :       /* Mark the old ssa name needs to be update from the use. */
     767                 :    17847827 :       update_cache_list.safe_push (item);
     768                 :             : 
     769                 :             :       /* If the cache exists for the use, don't try to recreate it. */
     770                 :    17847827 :       if (exists (use))
     771                 :             :         {
     772                 :             :           /* Update the cache here, this can reduce the number of
     773                 :             :              times through the update loop below.  */
     774                 :     7054102 :           update (old_name, use);
     775                 :     7054102 :           continue;
     776                 :             :         }
     777                 :             : 
     778                 :             :       /* Create the cache bitmap for the use and also
     779                 :             :          so we don't go into an infinite loop for some phi nodes with loops.  */
     780                 :    10793725 :       create (use);
     781                 :             : 
     782                 :    10793725 :       gimple *g = SSA_NAME_DEF_STMT (use);
     783                 :             :  
     784                 :             :       /* CONSTRUCTOR here is always a vector initialization,
     785                 :             :          walk each element too. */
     786                 :    10793725 :       if (gimple_assign_single_p (g)
     787                 :    10793725 :           && TREE_CODE (gimple_assign_rhs1 (g)) == CONSTRUCTOR)
     788                 :             :         {
     789                 :             :           tree ctr = gimple_assign_rhs1 (g);
     790                 :             :           unsigned i;
     791                 :             :           tree elm;
     792                 :      313841 :           FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctr), i, elm)
     793                 :      218534 :             work_list.safe_push (std::make_pair (elm, use));
     794                 :             :         }
     795                 :             :       /* For assignments, walk each operand for possible addresses.
     796                 :             :          For PHI nodes, walk each argument. */
     797                 :    10698418 :       else if (gassign *a = dyn_cast <gassign *> (g))
     798                 :             :         {
     799                 :             :           /* operand 0 is the lhs. */
     800                 :    19020766 :           for (unsigned i = 1; i < gimple_num_ops (g); i++)
     801                 :    10978289 :             work_list.safe_push (std::make_pair (gimple_op (a, i), use));
     802                 :             :         }
     803                 :    12402658 :       else if (gphi *p = dyn_cast <gphi *> (g))
     804                 :     5664808 :         for (unsigned i = 0; i < gimple_phi_num_args (p); ++i)
     805                 :     4055875 :           work_list.safe_push (std::make_pair (gimple_phi_arg_def (p, i), use));
     806                 :             :     }
     807                 :             : 
     808                 :             :   /* Update the cache. Note a loop is needed as phi nodes could
     809                 :             :      cause a loop to form. The number of times through this loop
     810                 :             :      will be small though.  */
     811                 :     9012739 :   bool changed;
     812                 :    18025478 :   do {
     813                 :     9012739 :     changed = false;
     814                 :     9012739 :     unsigned int i;
     815                 :     9012739 :     std::pair<tree,tree> *e;
     816                 :    45068279 :     FOR_EACH_VEC_ELT_REVERSE (update_cache_list, i, e)
     817                 :             :       {
     818                 :    18076072 :         if (update (e->second, e->first))
     819                 :       52585 :           changed = true;
     820                 :             :       }
     821                 :             :   } while (changed);
     822                 :             : 
     823                 :     8966729 :   return vars_ssa_caches[SSA_NAME_VERSION (name)].bmap;
     824                 :     8966729 : }
     825                 :             : 
     826                 :             : /* Helper function for add_scope_conflicts_1.  For USE on
     827                 :             :    a stmt, if it is a SSA_NAME and in its defining statement
     828                 :             :    is known to be based on some ADDR_EXPR, invoke VISIT
     829                 :             :    on that ADDR_EXPR.  */
     830                 :             : 
     831                 :             : static inline void
     832                 :    55066627 : add_scope_conflicts_2 (vars_ssa_cache &cache, tree name,
     833                 :             :                        bitmap work, walk_stmt_load_store_addr_fn visit)
     834                 :             : {
     835                 :    55066627 :   gcc_assert (TREE_CODE (name) == SSA_NAME);
     836                 :             : 
     837                 :             :   /* Querry the cache for the mapping of addresses that are referendd by
     838                 :             :      ssa name NAME. Querrying it will fill in it.  */
     839                 :    55066627 :   bitmap_iterator bi;
     840                 :    55066627 :   unsigned i;
     841                 :    55066627 :   const_bitmap bmap = cache (name);
     842                 :             :   /* Visit each stack variable that is referenced.  */
     843                 :    57513630 :   EXECUTE_IF_SET_IN_BITMAP (bmap, 0, i, bi)
     844                 :     2447003 :     visit (nullptr, stack_vars[i].decl, nullptr, work);
     845                 :    55066627 : }
     846                 :             : 
     847                 :             : /* Helper routine for add_scope_conflicts, calculating the active partitions
     848                 :             :    at the end of BB, leaving the result in WORK.  We're called to generate
     849                 :             :    conflicts when FOR_CONFLICT is true, otherwise we're just tracking
     850                 :             :    liveness.  */
     851                 :             : 
     852                 :             : static void
     853                 :    16148971 : add_scope_conflicts_1 (vars_ssa_cache &cache, basic_block bb, bitmap work, bool for_conflict)
     854                 :             : {
     855                 :    16148971 :   edge e;
     856                 :    16148971 :   edge_iterator ei;
     857                 :    16148971 :   gimple_stmt_iterator gsi;
     858                 :    16148971 :   walk_stmt_load_store_addr_fn visit;
     859                 :    16148971 :   use_operand_p use_p;
     860                 :    16148971 :   ssa_op_iter iter;
     861                 :    16148971 :   bool had_non_clobbers = false;
     862                 :             : 
     863                 :    16148971 :   bitmap_clear (work);
     864                 :             :   /* The copy what was alive out going from the edges. */
     865                 :    40824297 :   FOR_EACH_EDGE (e, ei, bb->preds)
     866                 :    24675326 :     bitmap_ior_into (work, (bitmap)e->src->aux);
     867                 :             : 
     868                 :    16148971 :   visit = for_conflict ? visit_conflict : visit_op;
     869                 :             : 
     870                 :             :   /* Addresses coming into the bb via phis are alive at the entry point. */
     871                 :    21374075 :   for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
     872                 :     5225104 :     add_scope_conflicts_2 (cache, gimple_phi_result (gsi_stmt (gsi)), work, visit_op);
     873                 :             : 
     874                 :   175490782 :   for (gsi = gsi_after_labels (bb); !gsi_end_p (gsi); gsi_next (&gsi))
     875                 :             :     {
     876                 :   159341811 :       gimple *stmt = gsi_stmt (gsi);
     877                 :             : 
     878                 :             :       /* Debug statements are not considered for liveness. */
     879                 :   159341811 :       if (is_gimple_debug (stmt))
     880                 :    96831638 :         continue;
     881                 :             : 
     882                 :             :       /* If we had `var = {CLOBBER}`, then var is no longer
     883                 :             :          considered alive after this point but might become
     884                 :             :          alive later on. */
     885                 :    62510173 :       if (gimple_clobber_p (stmt))
     886                 :             :         {
     887                 :     3530578 :           tree lhs = gimple_assign_lhs (stmt);
     888                 :             :           /* Handle only plain var clobbers, not partial ones.
     889                 :             :              Nested functions lowering and C++ front-end inserts clobbers
     890                 :             :              which are partial clobbers.  */
     891                 :     3530578 :           if (!VAR_P (lhs))
     892                 :      757672 :             continue;
     893                 :     2772906 :           unsigned indx = decl_stack_index (lhs);
     894                 :     2772906 :           if (indx != INVALID_STACK_INDEX)
     895                 :     2262189 :             bitmap_clear_bit (work, indx);
     896                 :             :         }
     897                 :             :       else
     898                 :             :         {
     899                 :    58979595 :           if (for_conflict && !had_non_clobbers)
     900                 :             :             {
     901                 :             :               /* When we are inheriting live variables from our predecessors
     902                 :             :                  through a CFG merge we might not see an actual mention of
     903                 :             :                  the variables to record the approprate conflict as defs/uses
     904                 :             :                  might be through indirect stores/loads.  For this reason
     905                 :             :                  we have to make sure each live variable conflicts with
     906                 :             :                  each other.  When there's just a single predecessor the
     907                 :             :                  set of conflicts is already up-to-date.
     908                 :             :                  We perform this delayed at the first real instruction to
     909                 :             :                  allow clobbers starting this block to remove variables from
     910                 :             :                  the set of live variables.  */
     911                 :     4856935 :               bitmap_iterator bi;
     912                 :     4856935 :               unsigned i;
     913                 :     4856935 :               if (EDGE_COUNT (bb->preds) > 1)
     914                 :    12419569 :                 EXECUTE_IF_SET_IN_BITMAP (work, 0, i, bi)
     915                 :             :                   {
     916                 :    10985619 :                     class stack_var *a = &stack_vars[i];
     917                 :    10985619 :                     if (!a->conflicts)
     918                 :      252857 :                       a->conflicts = BITMAP_ALLOC (&stack_var_bitmap_obstack);
     919                 :    10985619 :                     bitmap_ior_into (a->conflicts, work);
     920                 :             :                   }
     921                 :     4856935 :               had_non_clobbers = true;
     922                 :             :             }
     923                 :    58979595 :           walk_stmt_load_store_addr_ops (stmt, work, visit, visit, visit);
     924                 :   108821118 :           FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE)
     925                 :    49841523 :             add_scope_conflicts_2 (cache, USE_FROM_PTR (use_p), work, visit);
     926                 :             :         }
     927                 :             :     }
     928                 :             : 
     929                 :             :   /* When there was no real instruction but there's a CFG merge we need
     930                 :             :      to add the conflicts now.  */
     931                 :    16148971 :   if (for_conflict && !had_non_clobbers && EDGE_COUNT (bb->preds) > 1)
     932                 :             :     {
     933                 :      169063 :       bitmap_iterator bi;
     934                 :      169063 :       unsigned i;
     935                 :     1068480 :       EXECUTE_IF_SET_IN_BITMAP (work, 0, i, bi)
     936                 :             :         {
     937                 :      899417 :           class stack_var *a = &stack_vars[i];
     938                 :      899417 :           if (!a->conflicts)
     939                 :       38850 :             a->conflicts = BITMAP_ALLOC (&stack_var_bitmap_obstack);
     940                 :      899417 :           bitmap_ior_into (a->conflicts, work);
     941                 :             :         }
     942                 :             :     }
     943                 :    16148971 : }
     944                 :             : 
     945                 :             : /* Generate stack partition conflicts between all partitions that are
     946                 :             :    simultaneously live.  */
     947                 :             : 
     948                 :             : static void
     949                 :      233631 : add_scope_conflicts (void)
     950                 :             : {
     951                 :             :   /* If there is only one variable, there is nothing to be done as
     952                 :             :      there is only possible partition.  */
     953                 :      233631 :   if (stack_vars_num == 1)
     954                 :       86694 :     return;
     955                 :             : 
     956                 :      146937 :   basic_block bb;
     957                 :      146937 :   bool changed;
     958                 :      146937 :   bitmap work = BITMAP_ALLOC (NULL);
     959                 :      146937 :   int *rpo;
     960                 :      146937 :   int n_bbs;
     961                 :             : 
     962                 :      146937 :   vars_ssa_cache cache;
     963                 :             : 
     964                 :             :   /* We approximate the live range of a stack variable by taking the first
     965                 :             :      mention of its name as starting point(s), and by the end-of-scope
     966                 :             :      death clobber added by gimplify as ending point(s) of the range.
     967                 :             :      This overapproximates in the case we for instance moved an address-taken
     968                 :             :      operation upward, without also moving a dereference to it upwards.
     969                 :             :      But it's conservatively correct as a variable never can hold values
     970                 :             :      before its name is mentioned at least once.
     971                 :             : 
     972                 :             :      We then do a mostly classical bitmap liveness algorithm.  */
     973                 :             : 
     974                 :     5526305 :   FOR_ALL_BB_FN (bb, cfun)
     975                 :     5379368 :     bb->aux = BITMAP_ALLOC (&stack_var_bitmap_obstack);
     976                 :             : 
     977                 :      146937 :   rpo = XNEWVEC (int, last_basic_block_for_fn (cfun));
     978                 :      146937 :   n_bbs = pre_and_rev_post_order_compute (NULL, rpo, false);
     979                 :             : 
     980                 :      146937 :   changed = true;
     981                 :      595422 :   while (changed)
     982                 :             :     {
     983                 :             :       int i;
     984                 :             :       changed = false;
     985                 :    11365025 :       for (i = 0; i < n_bbs; i++)
     986                 :             :         {
     987                 :    11063477 :           bitmap active;
     988                 :    11063477 :           bb = BASIC_BLOCK_FOR_FN (cfun, rpo[i]);
     989                 :    11063477 :           active = (bitmap)bb->aux;
     990                 :    11063477 :           add_scope_conflicts_1 (cache, bb, work, false);
     991                 :    11063477 :           if (bitmap_ior_into (active, work))
     992                 :     4540503 :             changed = true;
     993                 :             :         }
     994                 :             :     }
     995                 :             : 
     996                 :     5232431 :   FOR_EACH_BB_FN (bb, cfun)
     997                 :     5085494 :     add_scope_conflicts_1 (cache, bb, work, true);
     998                 :             : 
     999                 :      146937 :   if (dump_file && (dump_flags & TDF_DETAILS))
    1000                 :           0 :     cache.dump (dump_file);
    1001                 :             : 
    1002                 :      146937 :   free (rpo);
    1003                 :      146937 :   BITMAP_FREE (work);
    1004                 :     5526305 :   FOR_ALL_BB_FN (bb, cfun)
    1005                 :     5379368 :     BITMAP_FREE (bb->aux);
    1006                 :      146937 : }
    1007                 :             : 
    1008                 :             : /* A subroutine of partition_stack_vars.  A comparison function for qsort,
    1009                 :             :    sorting an array of indices by the properties of the object.  */
    1010                 :             : 
    1011                 :             : static int
    1012                 :    19373702 : stack_var_cmp (const void *a, const void *b)
    1013                 :             : {
    1014                 :    19373702 :   unsigned ia = *(const unsigned *)a;
    1015                 :    19373702 :   unsigned ib = *(const unsigned *)b;
    1016                 :    19373702 :   unsigned int aligna = stack_vars[ia].alignb;
    1017                 :    19373702 :   unsigned int alignb = stack_vars[ib].alignb;
    1018                 :    19373702 :   poly_int64 sizea = stack_vars[ia].size;
    1019                 :    19373702 :   poly_int64 sizeb = stack_vars[ib].size;
    1020                 :    19373702 :   tree decla = stack_vars[ia].decl;
    1021                 :    19373702 :   tree declb = stack_vars[ib].decl;
    1022                 :    19373702 :   bool largea, largeb;
    1023                 :    19373702 :   unsigned int uida, uidb;
    1024                 :             : 
    1025                 :             :   /* Primary compare on "large" alignment.  Large comes first.  */
    1026                 :    19373702 :   largea = (aligna * BITS_PER_UNIT > MAX_SUPPORTED_STACK_ALIGNMENT);
    1027                 :    19373702 :   largeb = (alignb * BITS_PER_UNIT > MAX_SUPPORTED_STACK_ALIGNMENT);
    1028                 :    19373702 :   if (largea != largeb)
    1029                 :           0 :     return (int)largeb - (int)largea;
    1030                 :             : 
    1031                 :             :   /* Secondary compare on size, decreasing  */
    1032                 :    19373702 :   int diff = compare_sizes_for_sort (sizeb, sizea);
    1033                 :    19373702 :   if (diff != 0)
    1034                 :     8494195 :     return diff;
    1035                 :             : 
    1036                 :             :   /* Tertiary compare on true alignment, decreasing.  */
    1037                 :    10879507 :   if (aligna < alignb)
    1038                 :             :     return -1;
    1039                 :    10541745 :   if (aligna > alignb)
    1040                 :             :     return 1;
    1041                 :             : 
    1042                 :             :   /* Final compare on ID for sort stability, increasing.
    1043                 :             :      Two SSA names are compared by their version, SSA names come before
    1044                 :             :      non-SSA names, and two normal decls are compared by their DECL_UID.  */
    1045                 :    10262465 :   if (TREE_CODE (decla) == SSA_NAME)
    1046                 :             :     {
    1047                 :       37140 :       if (TREE_CODE (declb) == SSA_NAME)
    1048                 :       32624 :         uida = SSA_NAME_VERSION (decla), uidb = SSA_NAME_VERSION (declb);
    1049                 :             :       else
    1050                 :             :         return -1;
    1051                 :             :     }
    1052                 :    10225325 :   else if (TREE_CODE (declb) == SSA_NAME)
    1053                 :             :     return 1;
    1054                 :             :   else
    1055                 :    10219864 :     uida = DECL_UID (decla), uidb = DECL_UID (declb);
    1056                 :    10252488 :   if (uida < uidb)
    1057                 :             :     return 1;
    1058                 :     5108132 :   if (uida > uidb)
    1059                 :     5108132 :     return -1;
    1060                 :             :   return 0;
    1061                 :             : }
    1062                 :             : 
    1063                 :             : struct part_traits : unbounded_int_hashmap_traits <unsigned , bitmap> {};
    1064                 :             : typedef hash_map<unsigned, bitmap, part_traits> part_hashmap;
    1065                 :             : 
    1066                 :             : /* If the points-to solution *PI points to variables that are in a partition
    1067                 :             :    together with other variables add all partition members to the pointed-to
    1068                 :             :    variables bitmap.  */
    1069                 :             : 
    1070                 :             : static void
    1071                 :     1602124 : add_partitioned_vars_to_ptset (struct pt_solution *pt,
    1072                 :             :                                part_hashmap *decls_to_partitions,
    1073                 :             :                                hash_set<bitmap> *visited, bitmap temp)
    1074                 :             : {
    1075                 :     1602124 :   bitmap_iterator bi;
    1076                 :     1602124 :   unsigned i;
    1077                 :     1602124 :   bitmap *part;
    1078                 :             : 
    1079                 :     1602124 :   if (pt->anything
    1080                 :     1527281 :       || pt->vars == NULL
    1081                 :             :       /* The pointed-to vars bitmap is shared, it is enough to
    1082                 :             :          visit it once.  */
    1083                 :     3129405 :       || visited->add (pt->vars))
    1084                 :     1321107 :     return;
    1085                 :             : 
    1086                 :      281017 :   bitmap_clear (temp);
    1087                 :             : 
    1088                 :             :   /* By using a temporary bitmap to store all members of the partitions
    1089                 :             :      we have to add we make sure to visit each of the partitions only
    1090                 :             :      once.  */
    1091                 :     1236653 :   EXECUTE_IF_SET_IN_BITMAP (pt->vars, 0, i, bi)
    1092                 :      955636 :     if ((!temp
    1093                 :      955636 :          || !bitmap_bit_p (temp, i))
    1094                 :     1538706 :         && (part = decls_to_partitions->get (i)))
    1095                 :      176680 :       bitmap_ior_into (temp, *part);
    1096                 :      281017 :   if (!bitmap_empty_p (temp))
    1097                 :      148766 :     bitmap_ior_into (pt->vars, temp);
    1098                 :             : }
    1099                 :             : 
    1100                 :             : /* Update points-to sets based on partition info, so we can use them on RTL.
    1101                 :             :    The bitmaps representing stack partitions will be saved until expand,
    1102                 :             :    where partitioned decls used as bases in memory expressions will be
    1103                 :             :    rewritten.
    1104                 :             : 
    1105                 :             :    It is not necessary to update TBAA info on accesses to the coalesced
    1106                 :             :    storage since our memory model doesn't allow TBAA to be used for
    1107                 :             :    WAW or WAR dependences.  For RAW when the write is to an old object
    1108                 :             :    the new object would not have been initialized at the point of the
    1109                 :             :    read, invoking undefined behavior.  */
    1110                 :             : 
    1111                 :             : static void
    1112                 :      146937 : update_alias_info_with_stack_vars (void)
    1113                 :             : {
    1114                 :      146937 :   part_hashmap *decls_to_partitions = NULL;
    1115                 :      146937 :   unsigned i, j;
    1116                 :      146937 :   tree var = NULL_TREE;
    1117                 :             : 
    1118                 :     1241897 :   for (i = 0; i < stack_vars_num; i++)
    1119                 :             :     {
    1120                 :     1094960 :       bitmap part = NULL;
    1121                 :     1094960 :       tree name;
    1122                 :     1094960 :       struct ptr_info_def *pi;
    1123                 :             : 
    1124                 :             :       /* Not interested in partitions with single variable.  */
    1125                 :     1094960 :       if (stack_vars[i].representative != i
    1126                 :      839908 :           || stack_vars[i].next == EOC)
    1127                 :     1025311 :         continue;
    1128                 :             : 
    1129                 :       69649 :       if (!decls_to_partitions)
    1130                 :             :         {
    1131                 :       42583 :           decls_to_partitions = new part_hashmap;
    1132                 :       42583 :           cfun->gimple_df->decls_to_pointers = new hash_map<tree, tree>;
    1133                 :             :         }
    1134                 :             : 
    1135                 :             :       /* Create an SSA_NAME that points to the partition for use
    1136                 :             :          as base during alias-oracle queries on RTL for bases that
    1137                 :             :          have been partitioned.  */
    1138                 :       69649 :       if (var == NULL_TREE)
    1139                 :       42583 :         var = create_tmp_var (ptr_type_node);
    1140                 :       69649 :       name = make_ssa_name (var);
    1141                 :             : 
    1142                 :             :       /* Create bitmaps representing partitions.  They will be used for
    1143                 :             :          points-to sets later, so use GGC alloc.  */
    1144                 :       69649 :       part = BITMAP_GGC_ALLOC ();
    1145                 :      394350 :       for (j = i; j != EOC; j = stack_vars[j].next)
    1146                 :             :         {
    1147                 :      324701 :           tree decl = stack_vars[j].decl;
    1148                 :      324701 :           unsigned int uid = DECL_PT_UID (decl);
    1149                 :      324701 :           bitmap_set_bit (part, uid);
    1150                 :      324701 :           decls_to_partitions->put (uid, part);
    1151                 :      324701 :           cfun->gimple_df->decls_to_pointers->put (decl, name);
    1152                 :      324701 :           if (TREE_ADDRESSABLE (decl))
    1153                 :      295148 :             TREE_ADDRESSABLE (name) = 1;
    1154                 :             :         }
    1155                 :             : 
    1156                 :             :       /* Make the SSA name point to all partition members.  */
    1157                 :       69649 :       pi = get_ptr_info (name);
    1158                 :       69649 :       pt_solution_set (&pi->pt, part, false);
    1159                 :             :     }
    1160                 :             : 
    1161                 :             :   /* Make all points-to sets that contain one member of a partition
    1162                 :             :      contain all members of the partition.  */
    1163                 :      146937 :   if (decls_to_partitions)
    1164                 :             :     {
    1165                 :       42583 :       unsigned i;
    1166                 :       42583 :       tree name;
    1167                 :       42583 :       hash_set<bitmap> visited;
    1168                 :       42583 :       bitmap temp = BITMAP_ALLOC (&stack_var_bitmap_obstack);
    1169                 :             : 
    1170                 :    15990997 :       FOR_EACH_SSA_NAME (i, name, cfun)
    1171                 :             :         {
    1172                 :    10339995 :           struct ptr_info_def *pi;
    1173                 :             : 
    1174                 :    18980990 :           if (POINTER_TYPE_P (TREE_TYPE (name))
    1175                 :    10421404 :               && ((pi = SSA_NAME_PTR_INFO (name)) != NULL))
    1176                 :     1516958 :             add_partitioned_vars_to_ptset (&pi->pt, decls_to_partitions,
    1177                 :             :                                            &visited, temp);
    1178                 :             :         }
    1179                 :             : 
    1180                 :       42583 :       add_partitioned_vars_to_ptset (&cfun->gimple_df->escaped,
    1181                 :             :                                      decls_to_partitions, &visited, temp);
    1182                 :       42583 :       add_partitioned_vars_to_ptset (&cfun->gimple_df->escaped_return,
    1183                 :             :                                      decls_to_partitions, &visited, temp);
    1184                 :       42583 :       delete decls_to_partitions;
    1185                 :       42583 :       BITMAP_FREE (temp);
    1186                 :       42583 :     }
    1187                 :      146937 : }
    1188                 :             : 
    1189                 :             : /* A subroutine of partition_stack_vars.  The UNION portion of a UNION/FIND
    1190                 :             :    partitioning algorithm.  Partitions A and B are known to be non-conflicting.
    1191                 :             :    Merge them into a single partition A.  */
    1192                 :             : 
    1193                 :             : static void
    1194                 :      255052 : union_stack_vars (unsigned a, unsigned b)
    1195                 :             : {
    1196                 :      255052 :   class stack_var *vb = &stack_vars[b];
    1197                 :      255052 :   bitmap_iterator bi;
    1198                 :      255052 :   unsigned u;
    1199                 :             : 
    1200                 :      255052 :   gcc_assert (stack_vars[b].next == EOC);
    1201                 :             :    /* Add B to A's partition.  */
    1202                 :      255052 :   stack_vars[b].next = stack_vars[a].next;
    1203                 :      255052 :   stack_vars[b].representative = a;
    1204                 :      255052 :   stack_vars[a].next = b;
    1205                 :             : 
    1206                 :             :   /* Make sure A is big enough to hold B.  */
    1207                 :      255052 :   stack_vars[a].size = upper_bound (stack_vars[a].size, stack_vars[b].size);
    1208                 :             : 
    1209                 :             :   /* Update the required alignment of partition A to account for B.  */
    1210                 :      255052 :   if (stack_vars[a].alignb < stack_vars[b].alignb)
    1211                 :        2103 :     stack_vars[a].alignb = stack_vars[b].alignb;
    1212                 :             : 
    1213                 :             :   /* Update the interference graph and merge the conflicts.  */
    1214                 :      255052 :   if (vb->conflicts)
    1215                 :             :     {
    1216                 :     1577235 :       EXECUTE_IF_SET_IN_BITMAP (vb->conflicts, 0, u, bi)
    1217                 :     1376314 :         add_stack_var_conflict (a, stack_vars[u].representative);
    1218                 :      200921 :       BITMAP_FREE (vb->conflicts);
    1219                 :             :     }
    1220                 :      255052 : }
    1221                 :             : 
    1222                 :             : /* A subroutine of expand_used_vars.  Binpack the variables into
    1223                 :             :    partitions constrained by the interference graph.  The overall
    1224                 :             :    algorithm used is as follows:
    1225                 :             : 
    1226                 :             :         Sort the objects by size in descending order.
    1227                 :             :         For each object A {
    1228                 :             :           S = size(A)
    1229                 :             :           O = 0
    1230                 :             :           loop {
    1231                 :             :             Look for the largest non-conflicting object B with size <= S.
    1232                 :             :             UNION (A, B)
    1233                 :             :           }
    1234                 :             :         }
    1235                 :             : */
    1236                 :             : 
    1237                 :             : static void
    1238                 :      233631 : partition_stack_vars (void)
    1239                 :             : {
    1240                 :      233631 :   unsigned si, sj, n = stack_vars_num;
    1241                 :             : 
    1242                 :      233631 :   stack_vars_sorted = XNEWVEC (unsigned, stack_vars_num);
    1243                 :     1415285 :   for (si = 0; si < n; ++si)
    1244                 :     1181654 :     stack_vars_sorted[si] = si;
    1245                 :             : 
    1246                 :      233631 :   if (n == 1)
    1247                 :             :     return;
    1248                 :             : 
    1249                 :      146937 :   qsort (stack_vars_sorted, n, sizeof (unsigned), stack_var_cmp);
    1250                 :             : 
    1251                 :     1241897 :   for (si = 0; si < n; ++si)
    1252                 :             :     {
    1253                 :     1094960 :       unsigned i = stack_vars_sorted[si];
    1254                 :     1094960 :       unsigned int ialign = stack_vars[i].alignb;
    1255                 :     1094960 :       poly_int64 isize = stack_vars[i].size;
    1256                 :             : 
    1257                 :             :       /* Ignore objects that aren't partition representatives. If we
    1258                 :             :          see a var that is not a partition representative, it must
    1259                 :             :          have been merged earlier.  */
    1260                 :     1094960 :       if (stack_vars[i].representative != i)
    1261                 :      255052 :         continue;
    1262                 :             : 
    1263                 :    12612857 :       for (sj = si + 1; sj < n; ++sj)
    1264                 :             :         {
    1265                 :    11773906 :           unsigned j = stack_vars_sorted[sj];
    1266                 :    11773906 :           unsigned int jalign = stack_vars[j].alignb;
    1267                 :    11773906 :           poly_int64 jsize = stack_vars[j].size;
    1268                 :             : 
    1269                 :             :           /* Ignore objects that aren't partition representatives.  */
    1270                 :    11773906 :           if (stack_vars[j].representative != j)
    1271                 :    11772949 :             continue;
    1272                 :             : 
    1273                 :             :           /* Do not mix objects of "small" (supported) alignment
    1274                 :             :              and "large" (unsupported) alignment.  */
    1275                 :    11212164 :           if ((ialign * BITS_PER_UNIT <= MAX_SUPPORTED_STACK_ALIGNMENT)
    1276                 :    11212164 :               != (jalign * BITS_PER_UNIT <= MAX_SUPPORTED_STACK_ALIGNMENT))
    1277                 :             :             break;
    1278                 :             : 
    1279                 :             :           /* For Address Sanitizer do not mix objects with different
    1280                 :             :              sizes, as the shorter vars wouldn't be adequately protected.
    1281                 :             :              Don't do that for "large" (unsupported) alignment objects,
    1282                 :             :              those aren't protected anyway.  */
    1283                 :    11212164 :           if (asan_sanitize_stack_p ()
    1284                 :        5415 :               && maybe_ne (isize, jsize)
    1285                 :    11213121 :               && ialign * BITS_PER_UNIT <= MAX_SUPPORTED_STACK_ALIGNMENT)
    1286                 :             :             break;
    1287                 :             : 
    1288                 :             :           /* Ignore conflicting objects.  */
    1289                 :    11211207 :           if (stack_var_conflict_p (i, j))
    1290                 :    10956155 :             continue;
    1291                 :             : 
    1292                 :             :           /* UNION the objects, placing J at OFFSET.  */
    1293                 :      255052 :           union_stack_vars (i, j);
    1294                 :             :         }
    1295                 :             :     }
    1296                 :             : 
    1297                 :      146937 :   update_alias_info_with_stack_vars ();
    1298                 :             : }
    1299                 :             : 
    1300                 :             : /* A debugging aid for expand_used_vars.  Dump the generated partitions.  */
    1301                 :             : 
    1302                 :             : static void
    1303                 :          29 : dump_stack_var_partition (void)
    1304                 :             : {
    1305                 :          29 :   unsigned si, i, j, n = stack_vars_num;
    1306                 :             : 
    1307                 :          65 :   for (si = 0; si < n; ++si)
    1308                 :             :     {
    1309                 :          36 :       i = stack_vars_sorted[si];
    1310                 :             : 
    1311                 :             :       /* Skip variables that aren't partition representatives, for now.  */
    1312                 :          36 :       if (stack_vars[i].representative != i)
    1313                 :           3 :         continue;
    1314                 :             : 
    1315                 :          33 :       fprintf (dump_file, "Partition %u: size ", i);
    1316                 :          33 :       print_dec (stack_vars[i].size, dump_file);
    1317                 :          33 :       fprintf (dump_file, " align %u\n", stack_vars[i].alignb);
    1318                 :             : 
    1319                 :         102 :       for (j = i; j != EOC; j = stack_vars[j].next)
    1320                 :             :         {
    1321                 :          36 :           fputc ('\t', dump_file);
    1322                 :          36 :           print_generic_expr (dump_file, stack_vars[j].decl, dump_flags);
    1323                 :             :         }
    1324                 :          33 :       fputc ('\n', dump_file);
    1325                 :             :     }
    1326                 :          29 : }
    1327                 :             : 
    1328                 :             : /* Assign rtl to DECL at BASE + OFFSET.  */
    1329                 :             : 
    1330                 :             : static void
    1331                 :     1971547 : expand_one_stack_var_at (tree decl, rtx base, unsigned base_align,
    1332                 :             :                          poly_int64 offset)
    1333                 :             : {
    1334                 :     1971547 :   unsigned align;
    1335                 :     1971547 :   rtx x;
    1336                 :             : 
    1337                 :             :   /* If this fails, we've overflowed the stack frame.  Error nicely?  */
    1338                 :     2247021 :   gcc_assert (known_eq (offset, trunc_int_for_mode (offset, Pmode)));
    1339                 :             : 
    1340                 :     1971547 :   if (hwasan_sanitize_stack_p ())
    1341                 :          87 :     x = targetm.memtag.add_tag (base, offset,
    1342                 :          87 :                                 hwasan_current_frame_tag ());
    1343                 :             :   else
    1344                 :     2246934 :     x = plus_constant (Pmode, base, offset);
    1345                 :             : 
    1346                 :     3943094 :   x = gen_rtx_MEM (TREE_CODE (decl) == SSA_NAME
    1347                 :      442628 :                    ? TYPE_MODE (TREE_TYPE (decl))
    1348                 :     1528919 :                    : DECL_MODE (decl), x);
    1349                 :             : 
    1350                 :             :   /* Set alignment we actually gave this decl if it isn't an SSA name.
    1351                 :             :      If it is we generate stack slots only accidentally so it isn't as
    1352                 :             :      important, we'll simply set the alignment directly on the MEM.  */
    1353                 :             : 
    1354                 :     1971547 :   if (stack_vars_base_reg_p (base))
    1355                 :     1968551 :     offset -= frame_phase;
    1356                 :     1971547 :   align = known_alignment (offset);
    1357                 :     1971547 :   align *= BITS_PER_UNIT;
    1358                 :     1971547 :   if (align == 0 || align > base_align)
    1359                 :      808631 :     align = base_align;
    1360                 :             : 
    1361                 :     1971547 :   if (TREE_CODE (decl) != SSA_NAME)
    1362                 :             :     {
    1363                 :             :       /* One would think that we could assert that we're not decreasing
    1364                 :             :          alignment here, but (at least) the i386 port does exactly this
    1365                 :             :          via the MINIMUM_ALIGNMENT hook.  */
    1366                 :             : 
    1367                 :     1528919 :       SET_DECL_ALIGN (decl, align);
    1368                 :     1528919 :       DECL_USER_ALIGN (decl) = 0;
    1369                 :             :     }
    1370                 :             : 
    1371                 :     1971547 :   set_rtl (decl, x);
    1372                 :             : 
    1373                 :     1971547 :   set_mem_align (x, align);
    1374                 :     1971547 : }
    1375                 :             : 
    1376                 :      233631 : class stack_vars_data
    1377                 :             : {
    1378                 :             : public:
    1379                 :             :   /* Vector of offset pairs, always end of some padding followed
    1380                 :             :      by start of the padding that needs Address Sanitizer protection.
    1381                 :             :      The vector is in reversed, highest offset pairs come first.  */
    1382                 :             :   auto_vec<HOST_WIDE_INT> asan_vec;
    1383                 :             : 
    1384                 :             :   /* Vector of partition representative decls in between the paddings.  */
    1385                 :             :   auto_vec<tree> asan_decl_vec;
    1386                 :             : 
    1387                 :             :   /* Base pseudo register for Address Sanitizer protected automatic vars.  */
    1388                 :             :   rtx asan_base;
    1389                 :             : 
    1390                 :             :   /* Alignment needed for the Address Sanitizer protected automatic vars.  */
    1391                 :             :   unsigned int asan_alignb;
    1392                 :             : };
    1393                 :             : 
    1394                 :             : /* A subroutine of expand_used_vars.  Give each partition representative
    1395                 :             :    a unique location within the stack frame.  Update each partition member
    1396                 :             :    with that location.  */
    1397                 :             : static void
    1398                 :      235619 : expand_stack_vars (bool (*pred) (unsigned), class stack_vars_data *data)
    1399                 :             : {
    1400                 :      235619 :   unsigned si, i, j, n = stack_vars_num;
    1401                 :      235619 :   poly_uint64 large_size = 0, large_alloc = 0;
    1402                 :      235619 :   rtx large_base = NULL;
    1403                 :      235619 :   rtx large_untagged_base = NULL;
    1404                 :      235619 :   unsigned large_align = 0;
    1405                 :      235619 :   bool large_allocation_done = false;
    1406                 :      235619 :   tree decl;
    1407                 :             : 
    1408                 :             :   /* Determine if there are any variables requiring "large" alignment.
    1409                 :             :      Since these are dynamically allocated, we only process these if
    1410                 :             :      no predicate involved.  */
    1411                 :      235619 :   large_align = stack_vars[stack_vars_sorted[0]].alignb * BITS_PER_UNIT;
    1412                 :      235619 :   if (pred == NULL && large_align > MAX_SUPPORTED_STACK_ALIGNMENT)
    1413                 :             :     {
    1414                 :             :       /* Find the total size of these variables.  */
    1415                 :           0 :       for (si = 0; si < n; ++si)
    1416                 :             :         {
    1417                 :           0 :           unsigned alignb;
    1418                 :             : 
    1419                 :           0 :           i = stack_vars_sorted[si];
    1420                 :           0 :           alignb = stack_vars[i].alignb;
    1421                 :             : 
    1422                 :             :           /* All "large" alignment decls come before all "small" alignment
    1423                 :             :              decls, but "large" alignment decls are not sorted based on
    1424                 :             :              their alignment.  Increase large_align to track the largest
    1425                 :             :              required alignment.  */
    1426                 :           0 :           if ((alignb * BITS_PER_UNIT) > large_align)
    1427                 :             :             large_align = alignb * BITS_PER_UNIT;
    1428                 :             : 
    1429                 :             :           /* Stop when we get to the first decl with "small" alignment.  */
    1430                 :           0 :           if (alignb * BITS_PER_UNIT <= MAX_SUPPORTED_STACK_ALIGNMENT)
    1431                 :             :             break;
    1432                 :             : 
    1433                 :             :           /* Skip variables that aren't partition representatives.  */
    1434                 :           0 :           if (stack_vars[i].representative != i)
    1435                 :           0 :             continue;
    1436                 :             : 
    1437                 :             :           /* Skip variables that have already had rtl assigned.  See also
    1438                 :             :              add_stack_var where we perpetrate this pc_rtx hack.  */
    1439                 :           0 :           decl = stack_vars[i].decl;
    1440                 :           0 :           if (TREE_CODE (decl) == SSA_NAME
    1441                 :           0 :               ? SA.partition_to_pseudo[var_to_partition (SA.map, decl)] != NULL_RTX
    1442                 :           0 :               : DECL_RTL (decl) != pc_rtx)
    1443                 :           0 :             continue;
    1444                 :             : 
    1445                 :           0 :           large_size = aligned_upper_bound (large_size, alignb);
    1446                 :           0 :           large_size += stack_vars[i].size;
    1447                 :             :         }
    1448                 :             :     }
    1449                 :             : 
    1450                 :     1421496 :   for (si = 0; si < n; ++si)
    1451                 :             :     {
    1452                 :     1185877 :       rtx base;
    1453                 :     1185877 :       unsigned base_align, alignb;
    1454                 :     1185877 :       poly_int64 offset = 0;
    1455                 :             : 
    1456                 :     1185877 :       i = stack_vars_sorted[si];
    1457                 :             : 
    1458                 :             :       /* Skip variables that aren't partition representatives, for now.  */
    1459                 :     1185877 :       if (stack_vars[i].representative != i)
    1460                 :     1440940 :         continue;
    1461                 :             : 
    1462                 :             :       /* Skip variables that have already had rtl assigned.  See also
    1463                 :             :          add_stack_var where we perpetrate this pc_rtx hack.  */
    1464                 :      930814 :       decl = stack_vars[i].decl;
    1465                 :      930814 :       if (TREE_CODE (decl) == SSA_NAME
    1466                 :      930814 :           ? SA.partition_to_pseudo[var_to_partition (SA.map, decl)] != NULL_RTX
    1467                 :      927279 :           : DECL_RTL (decl) != pc_rtx)
    1468                 :        3251 :         continue;
    1469                 :             : 
    1470                 :             :       /* Check the predicate to see whether this variable should be
    1471                 :             :          allocated in this pass.  */
    1472                 :      927563 :       if (pred && !pred (i))
    1473                 :         961 :         continue;
    1474                 :             : 
    1475                 :      926602 :       base = (hwasan_sanitize_stack_p ()
    1476                 :      926602 :               ? hwasan_frame_base ()
    1477                 :      926546 :               : virtual_stack_vars_rtx);
    1478                 :      926602 :       alignb = stack_vars[i].alignb;
    1479                 :      926602 :       if (alignb * BITS_PER_UNIT <= MAX_SUPPORTED_STACK_ALIGNMENT)
    1480                 :             :         {
    1481                 :      926602 :           poly_int64 hwasan_orig_offset;
    1482                 :      926602 :           if (hwasan_sanitize_stack_p ())
    1483                 :             :             {
    1484                 :             :               /* There must be no tag granule "shared" between different
    1485                 :             :                  objects.  This means that no HWASAN_TAG_GRANULE_SIZE byte
    1486                 :             :                  chunk can have more than one object in it.
    1487                 :             : 
    1488                 :             :                  We ensure this by forcing the end of the last bit of data to
    1489                 :             :                  be aligned to HWASAN_TAG_GRANULE_SIZE bytes here, and setting
    1490                 :             :                  the start of each variable to be aligned to
    1491                 :             :                  HWASAN_TAG_GRANULE_SIZE bytes in `align_local_variable`.
    1492                 :             : 
    1493                 :             :                  We can't align just one of the start or end, since there are
    1494                 :             :                  untagged things stored on the stack which we do not align to
    1495                 :             :                  HWASAN_TAG_GRANULE_SIZE bytes.  If we only aligned the start
    1496                 :             :                  or the end of tagged objects then untagged objects could end
    1497                 :             :                  up sharing the first granule of a tagged object or sharing the
    1498                 :             :                  last granule of a tagged object respectively.  */
    1499                 :          56 :               hwasan_orig_offset = align_frame_offset (HWASAN_TAG_GRANULE_SIZE);
    1500                 :          56 :               gcc_assert (stack_vars[i].alignb >= HWASAN_TAG_GRANULE_SIZE);
    1501                 :             :             }
    1502                 :             :           /* ASAN description strings don't yet have a syntax for expressing
    1503                 :             :              polynomial offsets.  */
    1504                 :      926602 :           HOST_WIDE_INT prev_offset;
    1505                 :      926602 :           if (asan_sanitize_stack_p ()
    1506                 :        3659 :               && pred
    1507                 :        2991 :               && frame_offset.is_constant (&prev_offset)
    1508                 :      926602 :               && stack_vars[i].size.is_constant ())
    1509                 :             :             {
    1510                 :        2991 :               if (data->asan_vec.is_empty ())
    1511                 :             :                 {
    1512                 :        1595 :                   align_frame_offset (ASAN_RED_ZONE_SIZE);
    1513                 :        1595 :                   prev_offset = frame_offset.to_constant ();
    1514                 :             :                 }
    1515                 :        2991 :               prev_offset = align_base (prev_offset,
    1516                 :             :                                         ASAN_MIN_RED_ZONE_SIZE,
    1517                 :             :                                         !FRAME_GROWS_DOWNWARD);
    1518                 :        2991 :               tree repr_decl = NULL_TREE;
    1519                 :        2991 :               unsigned HOST_WIDE_INT size
    1520                 :        2991 :                 = asan_var_and_redzone_size (stack_vars[i].size.to_constant ());
    1521                 :        2991 :               if (data->asan_vec.is_empty ())
    1522                 :        1595 :                 size = MAX (size, ASAN_RED_ZONE_SIZE);
    1523                 :             : 
    1524                 :        2991 :               unsigned HOST_WIDE_INT alignment = MAX (alignb,
    1525                 :             :                                                       ASAN_MIN_RED_ZONE_SIZE);
    1526                 :        2991 :               offset = alloc_stack_frame_space (size, alignment);
    1527                 :             : 
    1528                 :        2991 :               data->asan_vec.safe_push (prev_offset);
    1529                 :             :               /* Allocating a constant amount of space from a constant
    1530                 :             :                  starting offset must give a constant result.  */
    1531                 :        2991 :               data->asan_vec.safe_push ((offset + stack_vars[i].size)
    1532                 :        2991 :                                         .to_constant ());
    1533                 :             :               /* Find best representative of the partition.
    1534                 :             :                  Prefer those with DECL_NAME, even better
    1535                 :             :                  satisfying asan_protect_stack_decl predicate.  */
    1536                 :        3503 :               for (j = i; j != EOC; j = stack_vars[j].next)
    1537                 :        2995 :                 if (asan_protect_stack_decl (stack_vars[j].decl)
    1538                 :        2995 :                     && DECL_NAME (stack_vars[j].decl))
    1539                 :             :                   {
    1540                 :        2483 :                     repr_decl = stack_vars[j].decl;
    1541                 :        2483 :                     break;
    1542                 :             :                   }
    1543                 :         512 :                 else if (repr_decl == NULL_TREE
    1544                 :         512 :                          && DECL_P (stack_vars[j].decl)
    1545                 :        1024 :                          && DECL_NAME (stack_vars[j].decl))
    1546                 :           0 :                   repr_decl = stack_vars[j].decl;
    1547                 :        2991 :               if (repr_decl == NULL_TREE)
    1548                 :         508 :                 repr_decl = stack_vars[i].decl;
    1549                 :        2991 :               data->asan_decl_vec.safe_push (repr_decl);
    1550                 :             : 
    1551                 :             :               /* Make sure a representative is unpoison if another
    1552                 :             :                  variable in the partition is handled by
    1553                 :             :                  use-after-scope sanitization.  */
    1554                 :        2991 :               if (asan_handled_variables != NULL
    1555                 :        2991 :                   && !asan_handled_variables->contains (repr_decl))
    1556                 :             :                 {
    1557                 :         404 :                   for (j = i; j != EOC; j = stack_vars[j].next)
    1558                 :         204 :                     if (asan_handled_variables->contains (stack_vars[j].decl))
    1559                 :             :                       break;
    1560                 :         202 :                   if (j != EOC)
    1561                 :           2 :                     asan_handled_variables->add (repr_decl);
    1562                 :             :                 }
    1563                 :             : 
    1564                 :        2991 :               data->asan_alignb = MAX (data->asan_alignb, alignb);
    1565                 :        2991 :               if (data->asan_base == NULL)
    1566                 :        1595 :                 data->asan_base = gen_reg_rtx (Pmode);
    1567                 :        2991 :               base = data->asan_base;
    1568                 :             : 
    1569                 :        2991 :               if (!STRICT_ALIGNMENT)
    1570                 :        2991 :                 base_align = crtl->max_used_stack_slot_alignment;
    1571                 :             :               else
    1572                 :             :                 base_align = MAX (crtl->max_used_stack_slot_alignment,
    1573                 :             :                                   GET_MODE_ALIGNMENT (SImode)
    1574                 :             :                                   << ASAN_SHADOW_SHIFT);
    1575                 :             :             }
    1576                 :             :           else
    1577                 :             :             {
    1578                 :      923611 :               offset = alloc_stack_frame_space (stack_vars[i].size, alignb);
    1579                 :      923611 :               base_align = crtl->max_used_stack_slot_alignment;
    1580                 :             : 
    1581                 :      923611 :               if (hwasan_sanitize_stack_p ())
    1582                 :             :                 {
    1583                 :             :                   /* Align again since the point of this alignment is to handle
    1584                 :             :                      the "end" of the object (i.e. smallest address after the
    1585                 :             :                      stack object).  For FRAME_GROWS_DOWNWARD that requires
    1586                 :             :                      aligning the stack before allocating, but for a frame that
    1587                 :             :                      grows upwards that requires aligning the stack after
    1588                 :             :                      allocation.
    1589                 :             : 
    1590                 :             :                      Use `frame_offset` to record the offset value rather than
    1591                 :             :                      `offset` since the `frame_offset` describes the extent
    1592                 :             :                      allocated for this particular variable while `offset`
    1593                 :             :                      describes the address that this variable starts at.  */
    1594                 :          56 :                   align_frame_offset (HWASAN_TAG_GRANULE_SIZE);
    1595                 :          56 :                   hwasan_record_stack_var (virtual_stack_vars_rtx, base,
    1596                 :             :                                            hwasan_orig_offset, frame_offset);
    1597                 :             :                 }
    1598                 :             :             }
    1599                 :             :         }
    1600                 :             :       else
    1601                 :             :         {
    1602                 :             :           /* Large alignment is only processed in the last pass.  */
    1603                 :           0 :           if (pred)
    1604                 :           0 :             continue;
    1605                 :             : 
    1606                 :             :           /* If there were any variables requiring "large" alignment, allocate
    1607                 :             :              space.  */
    1608                 :           0 :           if (maybe_ne (large_size, 0U) && ! large_allocation_done)
    1609                 :             :             {
    1610                 :           0 :               poly_int64 loffset;
    1611                 :           0 :               rtx large_allocsize;
    1612                 :             : 
    1613                 :           0 :               large_allocsize = gen_int_mode (large_size, Pmode);
    1614                 :           0 :               get_dynamic_stack_size (&large_allocsize, 0, large_align, NULL);
    1615                 :           0 :               loffset = alloc_stack_frame_space
    1616                 :           0 :                 (rtx_to_poly_int64 (large_allocsize),
    1617                 :           0 :                  PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT);
    1618                 :           0 :               large_base = get_dynamic_stack_base (loffset, large_align, base);
    1619                 :           0 :               large_allocation_done = true;
    1620                 :             :             }
    1621                 :             : 
    1622                 :           0 :           gcc_assert (large_base != NULL);
    1623                 :           0 :           large_alloc = aligned_upper_bound (large_alloc, alignb);
    1624                 :           0 :           offset = large_alloc;
    1625                 :           0 :           large_alloc += stack_vars[i].size;
    1626                 :           0 :           if (hwasan_sanitize_stack_p ())
    1627                 :             :             {
    1628                 :             :               /* An object with a large alignment requirement means that the
    1629                 :             :                  alignment requirement is greater than the required alignment
    1630                 :             :                  for tags.  */
    1631                 :           0 :               if (!large_untagged_base)
    1632                 :           0 :                 large_untagged_base
    1633                 :           0 :                   = targetm.memtag.untagged_pointer (large_base, NULL_RTX);
    1634                 :             :               /* Ensure the end of the variable is also aligned correctly.  */
    1635                 :           0 :               poly_int64 align_again
    1636                 :           0 :                 = aligned_upper_bound (large_alloc, HWASAN_TAG_GRANULE_SIZE);
    1637                 :             :               /* For large allocations we always allocate a chunk of space
    1638                 :             :                  (which is addressed by large_untagged_base/large_base) and
    1639                 :             :                  then use positive offsets from that.  Hence the farthest
    1640                 :             :                  offset is `align_again` and the nearest offset from the base
    1641                 :             :                  is `offset`.  */
    1642                 :           0 :               hwasan_record_stack_var (large_untagged_base, large_base,
    1643                 :             :                                        offset, align_again);
    1644                 :             :             }
    1645                 :             : 
    1646                 :             :           base = large_base;
    1647                 :             :           base_align = large_align;
    1648                 :             :         }
    1649                 :             : 
    1650                 :             :       /* Create rtl for each variable based on their location within the
    1651                 :             :          partition.  */
    1652                 :     2108256 :       for (j = i; j != EOC; j = stack_vars[j].next)
    1653                 :             :         {
    1654                 :     1181654 :           expand_one_stack_var_at (stack_vars[j].decl,
    1655                 :             :                                    base, base_align, offset);
    1656                 :             :         }
    1657                 :      926602 :       if (hwasan_sanitize_stack_p ())
    1658                 :          56 :         hwasan_increment_frame_tag ();
    1659                 :             :     }
    1660                 :             : 
    1661                 :      235619 :   gcc_assert (known_eq (large_alloc, large_size));
    1662                 :      235619 : }
    1663                 :             : 
    1664                 :             : /* Take into account all sizes of partitions and reset DECL_RTLs.  */
    1665                 :             : static poly_uint64
    1666                 :     1078525 : account_stack_vars (void)
    1667                 :             : {
    1668                 :     1078525 :   unsigned si, j, i, n = stack_vars_num;
    1669                 :     1078525 :   poly_uint64 size = 0;
    1670                 :             : 
    1671                 :     5572161 :   for (si = 0; si < n; ++si)
    1672                 :             :     {
    1673                 :     4493636 :       i = stack_vars_sorted[si];
    1674                 :             : 
    1675                 :             :       /* Skip variables that aren't partition representatives, for now.  */
    1676                 :     4493636 :       if (stack_vars[i].representative != i)
    1677                 :           0 :         continue;
    1678                 :             : 
    1679                 :     8987272 :       size += stack_vars[i].size;
    1680                 :     8987272 :       for (j = i; j != EOC; j = stack_vars[j].next)
    1681                 :     4493636 :         set_rtl (stack_vars[j].decl, NULL);
    1682                 :             :     }
    1683                 :     1078525 :   return size;
    1684                 :             : }
    1685                 :             : 
    1686                 :             : /* Record the RTL assignment X for the default def of PARM.  */
    1687                 :             : 
    1688                 :             : extern void
    1689                 :     4640104 : set_parm_rtl (tree parm, rtx x)
    1690                 :             : {
    1691                 :     4640104 :   gcc_assert (TREE_CODE (parm) == PARM_DECL
    1692                 :             :               || TREE_CODE (parm) == RESULT_DECL);
    1693                 :             : 
    1694                 :     4640104 :   if (x && !MEM_P (x))
    1695                 :             :     {
    1696                 :     3003310 :       unsigned int align = MINIMUM_ALIGNMENT (TREE_TYPE (parm),
    1697                 :             :                                               TYPE_MODE (TREE_TYPE (parm)),
    1698                 :             :                                               TYPE_ALIGN (TREE_TYPE (parm)));
    1699                 :             : 
    1700                 :             :       /* If the variable alignment is very large we'll dynamicaly
    1701                 :             :          allocate it, which means that in-frame portion is just a
    1702                 :             :          pointer.  ??? We've got a pseudo for sure here, do we
    1703                 :             :          actually dynamically allocate its spilling area if needed?
    1704                 :             :          ??? Isn't it a problem when Pmode alignment also exceeds
    1705                 :             :          MAX_SUPPORTED_STACK_ALIGNMENT, as can happen on cris and lm32?  */
    1706                 :     3003310 :       if (align > MAX_SUPPORTED_STACK_ALIGNMENT)
    1707                 :           0 :         align = GET_MODE_ALIGNMENT (Pmode);
    1708                 :             : 
    1709                 :     3003310 :       record_alignment_for_reg_var (align);
    1710                 :             :     }
    1711                 :             : 
    1712                 :     4640104 :   tree ssa = ssa_default_def (cfun, parm);
    1713                 :     4640104 :   if (!ssa)
    1714                 :     1057988 :     return set_rtl (parm, x);
    1715                 :             : 
    1716                 :     3582116 :   int part = var_to_partition (SA.map, ssa);
    1717                 :     3582116 :   gcc_assert (part != NO_PARTITION);
    1718                 :             : 
    1719                 :     3582116 :   bool changed = bitmap_bit_p (SA.partitions_for_parm_default_defs, part);
    1720                 :     3582116 :   gcc_assert (changed);
    1721                 :             : 
    1722                 :     3582116 :   set_rtl (ssa, x);
    1723                 :     3582116 :   gcc_assert (DECL_RTL (parm) == x);
    1724                 :             : }
    1725                 :             : 
    1726                 :             : /* A subroutine of expand_one_var.  Called to immediately assign rtl
    1727                 :             :    to a variable to be allocated in the stack frame.  */
    1728                 :             : 
    1729                 :             : static void
    1730                 :      789893 : expand_one_stack_var_1 (tree var)
    1731                 :             : {
    1732                 :      789893 :   poly_uint64 size;
    1733                 :      789893 :   poly_int64 offset;
    1734                 :      789893 :   unsigned byte_align;
    1735                 :             : 
    1736                 :      789893 :   if (TREE_CODE (var) == SSA_NAME)
    1737                 :             :     {
    1738                 :      439705 :       tree type = TREE_TYPE (var);
    1739                 :      439705 :       size = tree_to_poly_uint64 (TYPE_SIZE_UNIT (type));
    1740                 :             :     }
    1741                 :             :   else
    1742                 :      350188 :     size = tree_to_poly_uint64 (DECL_SIZE_UNIT (var));
    1743                 :             : 
    1744                 :      789893 :   byte_align = align_local_variable (var, true);
    1745                 :             : 
    1746                 :             :   /* We handle highly aligned variables in expand_stack_vars.  */
    1747                 :      789893 :   gcc_assert (byte_align * BITS_PER_UNIT <= MAX_SUPPORTED_STACK_ALIGNMENT);
    1748                 :             : 
    1749                 :      789893 :   rtx base;
    1750                 :      789893 :   if (hwasan_sanitize_stack_p ())
    1751                 :             :     {
    1752                 :             :       /* Allocate zero bytes to align the stack.  */
    1753                 :          31 :       poly_int64 hwasan_orig_offset
    1754                 :          31 :         = align_frame_offset (HWASAN_TAG_GRANULE_SIZE);
    1755                 :          31 :       offset = alloc_stack_frame_space (size, byte_align);
    1756                 :          31 :       align_frame_offset (HWASAN_TAG_GRANULE_SIZE);
    1757                 :          31 :       base = hwasan_frame_base ();
    1758                 :             :       /* Use `frame_offset` to automatically account for machines where the
    1759                 :             :          frame grows upwards.
    1760                 :             : 
    1761                 :             :          `offset` will always point to the "start" of the stack object, which
    1762                 :             :          will be the smallest address, for ! FRAME_GROWS_DOWNWARD this is *not*
    1763                 :             :          the "furthest" offset from the base delimiting the current stack
    1764                 :             :          object.  `frame_offset` will always delimit the extent that the frame.
    1765                 :             :          */
    1766                 :          31 :       hwasan_record_stack_var (virtual_stack_vars_rtx, base,
    1767                 :             :                                hwasan_orig_offset, frame_offset);
    1768                 :             :     }
    1769                 :             :   else
    1770                 :             :     {
    1771                 :      789862 :       offset = alloc_stack_frame_space (size, byte_align);
    1772                 :      789862 :       base = virtual_stack_vars_rtx;
    1773                 :             :     }
    1774                 :             : 
    1775                 :      789893 :   expand_one_stack_var_at (var, base,
    1776                 :             :                            crtl->max_used_stack_slot_alignment, offset);
    1777                 :             : 
    1778                 :      789893 :   if (hwasan_sanitize_stack_p ())
    1779                 :          31 :     hwasan_increment_frame_tag ();
    1780                 :      789893 : }
    1781                 :             : 
    1782                 :             : /* Wrapper for expand_one_stack_var_1 that checks SSA_NAMEs are
    1783                 :             :    already assigned some MEM.  */
    1784                 :             : 
    1785                 :             : static void
    1786                 :      350188 : expand_one_stack_var (tree var)
    1787                 :             : {
    1788                 :      350188 :   if (TREE_CODE (var) == SSA_NAME)
    1789                 :             :     {
    1790                 :           0 :       int part = var_to_partition (SA.map, var);
    1791                 :           0 :       if (part != NO_PARTITION)
    1792                 :             :         {
    1793                 :           0 :           rtx x = SA.partition_to_pseudo[part];
    1794                 :           0 :           gcc_assert (x);
    1795                 :           0 :           gcc_assert (MEM_P (x));
    1796                 :             :           return;
    1797                 :             :         }
    1798                 :             :     }
    1799                 :             : 
    1800                 :      350188 :   return expand_one_stack_var_1 (var);
    1801                 :             : }
    1802                 :             : 
    1803                 :             : /* A subroutine of expand_one_var.  Called to assign rtl to a VAR_DECL
    1804                 :             :    that will reside in a hard register.  */
    1805                 :             : 
    1806                 :             : static void
    1807                 :        1081 : expand_one_hard_reg_var (tree var)
    1808                 :             : {
    1809                 :           0 :   rest_of_decl_compilation (var, 0, 0);
    1810                 :           0 : }
    1811                 :             : 
    1812                 :             : /* Record the alignment requirements of some variable assigned to a
    1813                 :             :    pseudo.  */
    1814                 :             : 
    1815                 :             : static void
    1816                 :    40284249 : record_alignment_for_reg_var (unsigned int align)
    1817                 :             : {
    1818                 :    40284249 :   if (SUPPORTS_STACK_ALIGNMENT
    1819                 :    40284249 :       && crtl->stack_alignment_estimated < align)
    1820                 :             :     {
    1821                 :             :       /* stack_alignment_estimated shouldn't change after stack
    1822                 :             :          realign decision made */
    1823                 :     1698789 :       gcc_assert (!crtl->stack_realign_processed);
    1824                 :     1698789 :       crtl->stack_alignment_estimated = align;
    1825                 :             :     }
    1826                 :             : 
    1827                 :             :   /* stack_alignment_needed > PREFERRED_STACK_BOUNDARY is permitted.
    1828                 :             :      So here we only make sure stack_alignment_needed >= align.  */
    1829                 :    40284249 :   if (crtl->stack_alignment_needed < align)
    1830                 :      550804 :     crtl->stack_alignment_needed = align;
    1831                 :    40284249 :   if (crtl->max_used_stack_slot_alignment < align)
    1832                 :      550804 :     crtl->max_used_stack_slot_alignment = align;
    1833                 :    40284249 : }
    1834                 :             : 
    1835                 :             : /* Create RTL for an SSA partition.  */
    1836                 :             : 
    1837                 :             : static void
    1838                 :    22186458 : expand_one_ssa_partition (tree var)
    1839                 :             : {
    1840                 :    22186458 :   int part = var_to_partition (SA.map, var);
    1841                 :    22186458 :   gcc_assert (part != NO_PARTITION);
    1842                 :             : 
    1843                 :    22186458 :   if (SA.partition_to_pseudo[part])
    1844                 :             :     return;
    1845                 :             : 
    1846                 :    22186458 :   unsigned int align = MINIMUM_ALIGNMENT (TREE_TYPE (var),
    1847                 :             :                                           TYPE_MODE (TREE_TYPE (var)),
    1848                 :             :                                           TYPE_ALIGN (TREE_TYPE (var)));
    1849                 :             : 
    1850                 :             :   /* If the variable alignment is very large we'll dynamicaly allocate
    1851                 :             :      it, which means that in-frame portion is just a pointer.  */
    1852                 :    22186458 :   if (align > MAX_SUPPORTED_STACK_ALIGNMENT)
    1853                 :           0 :     align = GET_MODE_ALIGNMENT (Pmode);
    1854                 :             : 
    1855                 :    22186458 :   record_alignment_for_reg_var (align);
    1856                 :             : 
    1857                 :    22186458 :   if (!use_register_for_decl (var))
    1858                 :             :     {
    1859                 :      442628 :       if (defer_stack_allocation (var, true))
    1860                 :        2923 :         add_stack_var (var, true);
    1861                 :             :       else
    1862                 :      439705 :         expand_one_stack_var_1 (var);
    1863                 :      442628 :       return;
    1864                 :             :     }
    1865                 :             : 
    1866                 :    21743830 :   machine_mode reg_mode = promote_ssa_mode (var, NULL);
    1867                 :    21743830 :   rtx x = gen_reg_rtx (reg_mode);
    1868                 :             : 
    1869                 :    21743830 :   set_rtl (var, x);
    1870                 :             : 
    1871                 :             :   /* For a promoted variable, X will not be used directly but wrapped in a
    1872                 :             :      SUBREG with SUBREG_PROMOTED_VAR_P set, which means that the RTL land
    1873                 :             :      will assume that its upper bits can be inferred from its lower bits.
    1874                 :             :      Therefore, if X isn't initialized on every path from the entry, then
    1875                 :             :      we must do it manually in order to fulfill the above assumption.  */
    1876                 :    21743830 :   if (reg_mode != TYPE_MODE (TREE_TYPE (var))
    1877                 :    21743830 :       && bitmap_bit_p (SA.partitions_for_undefined_values, part))
    1878                 :           0 :     emit_move_insn (x, CONST0_RTX (reg_mode));
    1879                 :             : }
    1880                 :             : 
    1881                 :             : /* Record the association between the RTL generated for partition PART
    1882                 :             :    and the underlying variable of the SSA_NAME VAR.  */
    1883                 :             : 
    1884                 :             : static void
    1885                 :    48484557 : adjust_one_expanded_partition_var (tree var)
    1886                 :             : {
    1887                 :    48484557 :   if (!var)
    1888                 :             :     return;
    1889                 :             : 
    1890                 :    48484557 :   tree decl = SSA_NAME_VAR (var);
    1891                 :             : 
    1892                 :    48484557 :   int part = var_to_partition (SA.map, var);
    1893                 :    48484557 :   if (part == NO_PARTITION)
    1894                 :             :     return;
    1895                 :             : 
    1896                 :    31171583 :   rtx x = SA.partition_to_pseudo[part];
    1897                 :             : 
    1898                 :    31171583 :   gcc_assert (x);
    1899                 :             : 
    1900                 :    31171583 :   set_rtl (var, x);
    1901                 :             : 
    1902                 :    31171583 :   if (!REG_P (x))
    1903                 :             :     return;
    1904                 :             : 
    1905                 :             :   /* Note if the object is a user variable.  */
    1906                 :    29204509 :   if (decl && !DECL_ARTIFICIAL (decl))
    1907                 :     4169267 :     mark_user_reg (x);
    1908                 :             : 
    1909                 :    29204509 :   if (POINTER_TYPE_P (decl ? TREE_TYPE (decl) : TREE_TYPE (var)))
    1910                 :     7467457 :     mark_reg_pointer (x, get_pointer_alignment (var));
    1911                 :             : }
    1912                 :             : 
    1913                 :             : /* A subroutine of expand_one_var.  Called to assign rtl to a VAR_DECL
    1914                 :             :    that will reside in a pseudo register.  */
    1915                 :             : 
    1916                 :             : static void
    1917                 :      585754 : expand_one_register_var (tree var)
    1918                 :             : {
    1919                 :      585754 :   if (TREE_CODE (var) == SSA_NAME)
    1920                 :             :     {
    1921                 :           0 :       int part = var_to_partition (SA.map, var);
    1922                 :           0 :       if (part != NO_PARTITION)
    1923                 :             :         {
    1924                 :           0 :           rtx x = SA.partition_to_pseudo[part];
    1925                 :           0 :           gcc_assert (x);
    1926                 :           0 :           gcc_assert (REG_P (x));
    1927                 :             :           return;
    1928                 :             :         }
    1929                 :           0 :       gcc_unreachable ();
    1930                 :             :     }
    1931                 :             : 
    1932                 :      585754 :   tree decl = var;
    1933                 :      585754 :   tree type = TREE_TYPE (decl);
    1934                 :      585754 :   machine_mode reg_mode = promote_decl_mode (decl, NULL);
    1935                 :      585754 :   rtx x = gen_reg_rtx (reg_mode);
    1936                 :             : 
    1937                 :      585754 :   set_rtl (var, x);
    1938                 :             : 
    1939                 :             :   /* Note if the object is a user variable.  */
    1940                 :      585754 :   if (!DECL_ARTIFICIAL (decl))
    1941                 :       91327 :     mark_user_reg (x);
    1942                 :             : 
    1943                 :      585754 :   if (POINTER_TYPE_P (type))
    1944                 :         173 :     mark_reg_pointer (x, get_pointer_alignment (var));
    1945                 :             : }
    1946                 :             : 
    1947                 :             : /* A subroutine of expand_one_var.  Called to assign rtl to a VAR_DECL that
    1948                 :             :    has some associated error, e.g. its type is error-mark.  We just need
    1949                 :             :    to pick something that won't crash the rest of the compiler.  */
    1950                 :             : 
    1951                 :             : static void
    1952                 :          32 : expand_one_error_var (tree var)
    1953                 :             : {
    1954                 :          32 :   machine_mode mode = DECL_MODE (var);
    1955                 :          32 :   rtx x;
    1956                 :             : 
    1957                 :          32 :   if (mode == BLKmode)
    1958                 :           1 :     x = gen_rtx_MEM (BLKmode, const0_rtx);
    1959                 :          31 :   else if (mode == VOIDmode)
    1960                 :           0 :     x = const0_rtx;
    1961                 :             :   else
    1962                 :          31 :     x = gen_reg_rtx (mode);
    1963                 :             : 
    1964                 :          32 :   SET_DECL_RTL (var, x);
    1965                 :          32 : }
    1966                 :             : 
    1967                 :             : /* A subroutine of expand_one_var.  VAR is a variable that will be
    1968                 :             :    allocated to the local stack frame.  Return true if we wish to
    1969                 :             :    add VAR to STACK_VARS so that it will be coalesced with other
    1970                 :             :    variables.  Return false to allocate VAR immediately.
    1971                 :             : 
    1972                 :             :    This function is used to reduce the number of variables considered
    1973                 :             :    for coalescing, which reduces the size of the quadratic problem.  */
    1974                 :             : 
    1975                 :             : static bool
    1976                 :     6596616 : defer_stack_allocation (tree var, bool toplevel)
    1977                 :             : {
    1978                 :     6596616 :   tree size_unit = TREE_CODE (var) == SSA_NAME
    1979                 :     6596616 :     ? TYPE_SIZE_UNIT (TREE_TYPE (var))
    1980                 :     6596616 :     : DECL_SIZE_UNIT (var);
    1981                 :     6596616 :   poly_uint64 size;
    1982                 :             : 
    1983                 :             :   /* Whether the variable is small enough for immediate allocation not to be
    1984                 :             :      a problem with regard to the frame size.  */
    1985                 :     6596616 :   bool smallish
    1986                 :     6596616 :     = (poly_int_tree_p (size_unit, &size)
    1987                 :     6596616 :        && (estimated_poly_value (size)
    1988                 :     6596616 :            < param_min_size_for_stack_sharing));
    1989                 :             : 
    1990                 :             :   /* If stack protection is enabled, *all* stack variables must be deferred,
    1991                 :             :      so that we can re-order the strings to the top of the frame.
    1992                 :             :      Similarly for Address Sanitizer.  */
    1993                 :     6596616 :   if (flag_stack_protect || asan_sanitize_stack_p ())
    1994                 :       12275 :     return true;
    1995                 :             : 
    1996                 :     6584341 :   unsigned int align = TREE_CODE (var) == SSA_NAME
    1997                 :     6584341 :     ? TYPE_ALIGN (TREE_TYPE (var))
    1998                 :     6142328 :     : DECL_ALIGN (var);
    1999                 :             : 
    2000                 :             :   /* We handle "large" alignment via dynamic allocation.  We want to handle
    2001                 :             :      this extra complication in only one place, so defer them.  */
    2002                 :             :   if (align > MAX_SUPPORTED_STACK_ALIGNMENT)
    2003                 :             :     return true;
    2004                 :             : 
    2005                 :     6584341 :   bool ignored = TREE_CODE (var) == SSA_NAME
    2006                 :     6590515 :     ? !SSAVAR (var) || DECL_IGNORED_P (SSA_NAME_VAR (var))
    2007                 :     6142328 :     : DECL_IGNORED_P (var);
    2008                 :             : 
    2009                 :             :   /* When optimization is enabled, DECL_IGNORED_P variables originally scoped
    2010                 :             :      might be detached from their block and appear at toplevel when we reach
    2011                 :             :      here.  We want to coalesce them with variables from other blocks when
    2012                 :             :      the immediate contribution to the frame size would be noticeable.  */
    2013                 :     6584341 :   if (toplevel && optimize > 0 && ignored && !smallish)
    2014                 :             :     return true;
    2015                 :             : 
    2016                 :             :   /* Variables declared in the outermost scope automatically conflict
    2017                 :             :      with every other variable.  The only reason to want to defer them
    2018                 :             :      at all is that, after sorting, we can more efficiently pack
    2019                 :             :      small variables in the stack frame.  Continue to defer at -O2.  */
    2020                 :     5103862 :   if (toplevel && optimize < 2)
    2021                 :             :     return false;
    2022                 :             : 
    2023                 :             :   /* Without optimization, *most* variables are allocated from the
    2024                 :             :      stack, which makes the quadratic problem large exactly when we
    2025                 :             :      want compilation to proceed as quickly as possible.  On the
    2026                 :             :      other hand, we don't want the function's stack frame size to
    2027                 :             :      get completely out of hand.  So we avoid adding scalars and
    2028                 :             :      "small" aggregates to the list at all.  */
    2029                 :     4475002 :   if (optimize == 0 && smallish)
    2030                 :             :     return false;
    2031                 :             : 
    2032                 :             :   return true;
    2033                 :             : }
    2034                 :             : 
    2035                 :             : /* A subroutine of expand_used_vars.  Expand one variable according to
    2036                 :             :    its flavor.  Variables to be placed on the stack are not actually
    2037                 :             :    expanded yet, merely recorded.
    2038                 :             :    When REALLY_EXPAND is false, only add stack values to be allocated.
    2039                 :             :    Return stack usage this variable is supposed to take.
    2040                 :             : */
    2041                 :             : 
    2042                 :             : static poly_uint64
    2043                 :    15391580 : expand_one_var (tree var, bool toplevel, bool really_expand,
    2044                 :             :                 bitmap forced_stack_var = NULL)
    2045                 :             : {
    2046                 :    15391580 :   unsigned int align = BITS_PER_UNIT;
    2047                 :    15391580 :   tree origvar = var;
    2048                 :             : 
    2049                 :    15391580 :   var = SSAVAR (var);
    2050                 :             : 
    2051                 :    15391580 :   if (TREE_TYPE (var) != error_mark_node && VAR_P (var))
    2052                 :             :     {
    2053                 :    15391580 :       if (is_global_var (var))
    2054                 :      297099 :         return 0;
    2055                 :             : 
    2056                 :             :       /* Because we don't know if VAR will be in register or on stack,
    2057                 :             :          we conservatively assume it will be on stack even if VAR is
    2058                 :             :          eventually put into register after RA pass.  For non-automatic
    2059                 :             :          variables, which won't be on stack, we collect alignment of
    2060                 :             :          type and ignore user specified alignment.  Similarly for
    2061                 :             :          SSA_NAMEs for which use_register_for_decl returns true.  */
    2062                 :    15094481 :       if (TREE_STATIC (var)
    2063                 :    15094481 :           || DECL_EXTERNAL (var)
    2064                 :    30188962 :           || (TREE_CODE (origvar) == SSA_NAME && use_register_for_decl (var)))
    2065                 :           0 :         align = MINIMUM_ALIGNMENT (TREE_TYPE (var),
    2066                 :             :                                    TYPE_MODE (TREE_TYPE (var)),
    2067                 :             :                                    TYPE_ALIGN (TREE_TYPE (var)));
    2068                 :    15094481 :       else if (DECL_HAS_VALUE_EXPR_P (var)
    2069                 :    15094481 :                || (DECL_RTL_SET_P (var) && MEM_P (DECL_RTL (var))))
    2070                 :             :         /* Don't consider debug only variables with DECL_HAS_VALUE_EXPR_P set
    2071                 :             :            or variables which were assigned a stack slot already by
    2072                 :             :            expand_one_stack_var_at - in the latter case DECL_ALIGN has been
    2073                 :             :            changed from the offset chosen to it.  */
    2074                 :       16402 :         align = crtl->stack_alignment_estimated;
    2075                 :             :       else
    2076                 :    15078079 :         align = MINIMUM_ALIGNMENT (var, DECL_MODE (var), DECL_ALIGN (var));
    2077                 :             : 
    2078                 :             :       /* If the variable alignment is very large we'll dynamicaly allocate
    2079                 :             :          it, which means that in-frame portion is just a pointer.  */
    2080                 :    15094481 :       if (align > MAX_SUPPORTED_STACK_ALIGNMENT)
    2081                 :           0 :         align = GET_MODE_ALIGNMENT (Pmode);
    2082                 :             :     }
    2083                 :             : 
    2084                 :    15094481 :   record_alignment_for_reg_var (align);
    2085                 :             : 
    2086                 :    15094481 :   poly_uint64 size;
    2087                 :    15094481 :   if (TREE_CODE (origvar) == SSA_NAME)
    2088                 :             :     {
    2089                 :           0 :       gcc_assert (!VAR_P (var)
    2090                 :             :                   || (!DECL_EXTERNAL (var)
    2091                 :             :                       && !DECL_HAS_VALUE_EXPR_P (var)
    2092                 :             :                       && !TREE_STATIC (var)
    2093                 :             :                       && TREE_TYPE (var) != error_mark_node
    2094                 :             :                       && !DECL_HARD_REGISTER (var)
    2095                 :             :                       && really_expand));
    2096                 :             :     }
    2097                 :    15094481 :   if (!VAR_P (var) && TREE_CODE (origvar) != SSA_NAME)
    2098                 :             :     ;
    2099                 :    15094481 :   else if (DECL_EXTERNAL (var))
    2100                 :             :     ;
    2101                 :    15094481 :   else if (DECL_HAS_VALUE_EXPR_P (var))
    2102                 :             :     ;
    2103                 :    15078172 :   else if (TREE_STATIC (var))
    2104                 :             :     ;
    2105                 :    15078172 :   else if (TREE_CODE (origvar) != SSA_NAME && DECL_RTL_SET_P (var))
    2106                 :             :     ;
    2107                 :    15077943 :   else if (TREE_TYPE (var) == error_mark_node)
    2108                 :             :     {
    2109                 :           0 :       if (really_expand)
    2110                 :           0 :         expand_one_error_var (var);
    2111                 :             :     }
    2112                 :    15077943 :   else if (VAR_P (var) && DECL_HARD_REGISTER (var))
    2113                 :             :     {
    2114                 :        4105 :       if (really_expand)
    2115                 :             :         {
    2116                 :        1081 :           expand_one_hard_reg_var (var);
    2117                 :        1081 :           if (!DECL_HARD_REGISTER (var))
    2118                 :             :             /* Invalid register specification.  */
    2119                 :          32 :             expand_one_error_var (var);
    2120                 :             :         }
    2121                 :             :     }
    2122                 :    15073838 :   else if (use_register_for_decl (var)
    2123                 :    15073838 :            && (!forced_stack_var
    2124                 :      595364 :                || !bitmap_bit_p (forced_stack_var, DECL_UID (var))))
    2125                 :             :     {
    2126                 :     8919850 :       if (really_expand)
    2127                 :      585754 :         expand_one_register_var (origvar);
    2128                 :             :     }
    2129                 :     6153988 :   else if (!poly_int_tree_p (DECL_SIZE_UNIT (var), &size)
    2130                 :     6153988 :            || !valid_constant_size_p (DECL_SIZE_UNIT (var)))
    2131                 :             :     {
    2132                 :             :       /* Reject variables which cover more than half of the address-space.  */
    2133                 :           0 :       if (really_expand)
    2134                 :             :         {
    2135                 :           0 :           if (DECL_NONLOCAL_FRAME (var))
    2136                 :           0 :             error_at (DECL_SOURCE_LOCATION (current_function_decl),
    2137                 :             :                       "total size of local objects is too large");
    2138                 :             :           else
    2139                 :           0 :             error_at (DECL_SOURCE_LOCATION (var),
    2140                 :             :                       "size of variable %q+D is too large", var);
    2141                 :           0 :           expand_one_error_var (var);
    2142                 :             :         }
    2143                 :             :     }
    2144                 :     6153988 :   else if (defer_stack_allocation (var, toplevel))
    2145                 :     5672367 :     add_stack_var (origvar, really_expand);
    2146                 :             :   else
    2147                 :             :     {
    2148                 :      481621 :       if (really_expand)
    2149                 :             :         {
    2150                 :      349949 :           if (lookup_attribute ("naked",
    2151                 :      349949 :                                 DECL_ATTRIBUTES (current_function_decl)))
    2152                 :           0 :             error ("cannot allocate stack for variable %q+D, naked function",
    2153                 :             :                    var);
    2154                 :             : 
    2155                 :      349949 :           expand_one_stack_var (origvar);
    2156                 :             :         }
    2157                 :      481621 :       return size;
    2158                 :             :     }
    2159                 :    14612860 :   return 0;
    2160                 :             : }
    2161                 :             : 
    2162                 :             : /* A subroutine of expand_used_vars.  Walk down through the BLOCK tree
    2163                 :             :    expanding variables.  Those variables that can be put into registers
    2164                 :             :    are allocated pseudos; those that can't are put on the stack.
    2165                 :             : 
    2166                 :             :    TOPLEVEL is true if this is the outermost BLOCK.  */
    2167                 :             : 
    2168                 :             : static void
    2169                 :    16979613 : expand_used_vars_for_block (tree block, bool toplevel, bitmap forced_stack_vars)
    2170                 :             : {
    2171                 :    16979613 :   tree t;
    2172                 :             : 
    2173                 :             :   /* Expand all variables at this level.  */
    2174                 :    35840827 :   for (t = BLOCK_VARS (block); t ; t = DECL_CHAIN (t))
    2175                 :    18861214 :     if (TREE_USED (t)
    2176                 :    18861214 :         && ((!VAR_P (t) && TREE_CODE (t) != RESULT_DECL)
    2177                 :      760164 :             || !DECL_NONSHAREABLE (t)))
    2178                 :      760164 :       expand_one_var (t, toplevel, true, forced_stack_vars);
    2179                 :             : 
    2180                 :             :   /* Expand all variables at containing levels.  */
    2181                 :    32497801 :   for (t = BLOCK_SUBBLOCKS (block); t ; t = BLOCK_CHAIN (t))
    2182                 :    15518188 :     expand_used_vars_for_block (t, false, forced_stack_vars);
    2183                 :    16979613 : }
    2184                 :             : 
    2185                 :             : /* A subroutine of expand_used_vars.  Walk down through the BLOCK tree
    2186                 :             :    and clear TREE_USED on all local variables.  */
    2187                 :             : 
    2188                 :             : static void
    2189                 :    16979613 : clear_tree_used (tree block)
    2190                 :             : {
    2191                 :    16979613 :   tree t;
    2192                 :             : 
    2193                 :    35840827 :   for (t = BLOCK_VARS (block); t ; t = DECL_CHAIN (t))
    2194                 :             :     /* if (!TREE_STATIC (t) && !DECL_EXTERNAL (t)) */
    2195                 :      995542 :     if ((!VAR_P (t) && TREE_CODE (t) != RESULT_DECL)
    2196                 :    18861214 :         || !DECL_NONSHAREABLE (t))
    2197                 :    18861214 :       TREE_USED (t) = 0;
    2198                 :             : 
    2199                 :    32497801 :   for (t = BLOCK_SUBBLOCKS (block); t ; t = BLOCK_CHAIN (t))
    2200                 :    15518188 :     clear_tree_used (t);
    2201                 :    16979613 : }
    2202                 :             : 
    2203                 :             : /* Examine TYPE and determine a bit mask of the following features.  */
    2204                 :             : 
    2205                 :             : #define SPCT_HAS_LARGE_CHAR_ARRAY       1
    2206                 :             : #define SPCT_HAS_SMALL_CHAR_ARRAY       2
    2207                 :             : #define SPCT_HAS_ARRAY                  4
    2208                 :             : #define SPCT_HAS_AGGREGATE              8
    2209                 :             : 
    2210                 :             : static unsigned int
    2211                 :        2637 : stack_protect_classify_type (tree type)
    2212                 :             : {
    2213                 :        2637 :   unsigned int ret = 0;
    2214                 :        2637 :   tree t;
    2215                 :             : 
    2216                 :        2637 :   switch (TREE_CODE (type))
    2217                 :             :     {
    2218                 :         633 :     case ARRAY_TYPE:
    2219                 :         633 :       t = TYPE_MAIN_VARIANT (TREE_TYPE (type));
    2220                 :         633 :       if (t == char_type_node
    2221                 :         175 :           || t == signed_char_type_node
    2222                 :         175 :           || t == unsigned_char_type_node)
    2223                 :             :         {
    2224                 :         458 :           unsigned HOST_WIDE_INT max = param_ssp_buffer_size;
    2225                 :         458 :           unsigned HOST_WIDE_INT len;
    2226                 :             : 
    2227                 :         458 :           if (!TYPE_SIZE_UNIT (type)
    2228                 :         458 :               || !tree_fits_uhwi_p (TYPE_SIZE_UNIT (type)))
    2229                 :             :             len = max;
    2230                 :             :           else
    2231                 :         458 :             len = tree_to_uhwi (TYPE_SIZE_UNIT (type));
    2232                 :             : 
    2233                 :         458 :           if (len < max)
    2234                 :             :             ret = SPCT_HAS_SMALL_CHAR_ARRAY | SPCT_HAS_ARRAY;
    2235                 :             :           else
    2236                 :         426 :             ret = SPCT_HAS_LARGE_CHAR_ARRAY | SPCT_HAS_ARRAY;
    2237                 :             :         }
    2238                 :             :       else
    2239                 :             :         ret = SPCT_HAS_ARRAY;
    2240                 :             :       break;
    2241                 :             : 
    2242                 :        1014 :     case UNION_TYPE:
    2243                 :        1014 :     case QUAL_UNION_TYPE:
    2244                 :        1014 :     case RECORD_TYPE:
    2245                 :        1014 :       ret = SPCT_HAS_AGGREGATE;
    2246                 :       10891 :       for (t = TYPE_FIELDS (type); t ; t = TREE_CHAIN (t))
    2247                 :        9877 :         if (TREE_CODE (t) == FIELD_DECL)
    2248                 :        1685 :           ret |= stack_protect_classify_type (TREE_TYPE (t));
    2249                 :             :       break;
    2250                 :             : 
    2251                 :             :     default:
    2252                 :             :       break;
    2253                 :             :     }
    2254                 :             : 
    2255                 :        2637 :   return ret;
    2256                 :             : }
    2257                 :             : 
    2258                 :             : /* Return nonzero if DECL should be segregated into the "vulnerable" upper
    2259                 :             :    part of the local stack frame.  Remember if we ever return nonzero for
    2260                 :             :    any variable in this function.  The return value is the phase number in
    2261                 :             :    which the variable should be allocated.  */
    2262                 :             : 
    2263                 :             : static int
    2264                 :         952 : stack_protect_decl_phase (tree decl)
    2265                 :             : {
    2266                 :         952 :   unsigned int bits = stack_protect_classify_type (TREE_TYPE (decl));
    2267                 :         952 :   int ret = 0;
    2268                 :             : 
    2269                 :         952 :   if (bits & SPCT_HAS_SMALL_CHAR_ARRAY)
    2270                 :          28 :     has_short_buffer = true;
    2271                 :             : 
    2272                 :         952 :   tree attribs = DECL_ATTRIBUTES (current_function_decl);
    2273                 :         952 :   if (!lookup_attribute ("no_stack_protector", attribs)
    2274                 :         952 :       && (flag_stack_protect == SPCT_FLAG_ALL
    2275                 :         952 :           || flag_stack_protect == SPCT_FLAG_STRONG
    2276                 :         153 :           || (flag_stack_protect == SPCT_FLAG_EXPLICIT
    2277                 :           5 :               && lookup_attribute ("stack_protect", attribs))))
    2278                 :             :     {
    2279                 :         804 :       if ((bits & (SPCT_HAS_SMALL_CHAR_ARRAY | SPCT_HAS_LARGE_CHAR_ARRAY))
    2280                 :         344 :           && !(bits & SPCT_HAS_AGGREGATE))
    2281                 :             :         ret = 1;
    2282                 :         748 :       else if (bits & SPCT_HAS_ARRAY)
    2283                 :             :         ret = 2;
    2284                 :             :     }
    2285                 :             :   else
    2286                 :         148 :     ret = (bits & SPCT_HAS_LARGE_CHAR_ARRAY) != 0;
    2287                 :             : 
    2288                 :         148 :   if (ret)
    2289                 :         615 :     has_protected_decls = true;
    2290                 :             : 
    2291                 :         952 :   return ret;
    2292                 :             : }
    2293                 :             : 
    2294                 :             : /* Two helper routines that check for phase 1 and phase 2.  These are used
    2295                 :             :    as callbacks for expand_stack_vars.  */
    2296                 :             : 
    2297                 :             : static bool
    2298                 :         309 : stack_protect_decl_phase_1 (unsigned i)
    2299                 :             : {
    2300                 :         309 :   return stack_protect_decl_phase (stack_vars[i].decl) == 1;
    2301                 :             : }
    2302                 :             : 
    2303                 :             : static bool
    2304                 :         216 : stack_protect_decl_phase_2 (unsigned i)
    2305                 :             : {
    2306                 :         216 :   return stack_protect_decl_phase (stack_vars[i].decl) == 2;
    2307                 :             : }
    2308                 :             : 
    2309                 :             : /* And helper function that checks for asan phase (with stack protector
    2310                 :             :    it is phase 3).  This is used as callback for expand_stack_vars.
    2311                 :             :    Returns true if any of the vars in the partition need to be protected.  */
    2312                 :             : 
    2313                 :             : static bool
    2314                 :        3574 : asan_decl_phase_3 (unsigned i)
    2315                 :             : {
    2316                 :        4242 :   while (i != EOC)
    2317                 :             :     {
    2318                 :        3574 :       if (asan_protect_stack_decl (stack_vars[i].decl))
    2319                 :             :         return true;
    2320                 :         668 :       i = stack_vars[i].next;
    2321                 :             :     }
    2322                 :             :   return false;
    2323                 :             : }
    2324                 :             : 
    2325                 :             : /* Ensure that variables in different stack protection phases conflict
    2326                 :             :    so that they are not merged and share the same stack slot.
    2327                 :             :    Return true if there are any address taken variables.  */
    2328                 :             : 
    2329                 :             : static bool
    2330                 :         223 : add_stack_protection_conflicts (void)
    2331                 :             : {
    2332                 :         223 :   unsigned i, j, n = stack_vars_num;
    2333                 :         223 :   unsigned char *phase;
    2334                 :         223 :   bool ret = false;
    2335                 :             : 
    2336                 :         223 :   phase = XNEWVEC (unsigned char, n);
    2337                 :         873 :   for (i = 0; i < n; ++i)
    2338                 :             :     {
    2339                 :         427 :       phase[i] = stack_protect_decl_phase (stack_vars[i].decl);
    2340                 :         427 :       if (TREE_ADDRESSABLE (stack_vars[i].decl))
    2341                 :         352 :         ret = true;
    2342                 :             :     }
    2343                 :             : 
    2344                 :         650 :   for (i = 0; i < n; ++i)
    2345                 :             :     {
    2346                 :         427 :       unsigned char ph_i = phase[i];
    2347                 :        1136 :       for (j = i + 1; j < n; ++j)
    2348                 :         709 :         if (ph_i != phase[j])
    2349                 :         322 :           add_stack_var_conflict (i, j);
    2350                 :             :     }
    2351                 :             : 
    2352                 :         223 :   XDELETEVEC (phase);
    2353                 :         223 :   return ret;
    2354                 :             : }
    2355                 :             : 
    2356                 :             : /* Create a decl for the guard at the top of the stack frame.  */
    2357                 :             : 
    2358                 :             : static void
    2359                 :         239 : create_stack_guard (void)
    2360                 :             : {
    2361                 :         239 :   tree guard = build_decl (DECL_SOURCE_LOCATION (current_function_decl),
    2362                 :             :                            VAR_DECL, NULL, ptr_type_node);
    2363                 :         239 :   TREE_THIS_VOLATILE (guard) = 1;
    2364                 :         239 :   TREE_USED (guard) = 1;
    2365                 :         239 :   expand_one_stack_var (guard);
    2366                 :         239 :   crtl->stack_protect_guard = guard;
    2367                 :         239 : }
    2368                 :             : 
    2369                 :             : /* Prepare for expanding variables.  */
    2370                 :             : static void
    2371                 :     7801233 : init_vars_expansion (void)
    2372                 :             : {
    2373                 :             :   /* Conflict bitmaps, and a few related temporary bitmaps, go here.  */
    2374                 :     7801233 :   bitmap_obstack_initialize (&stack_var_bitmap_obstack);
    2375                 :             : 
    2376                 :             :   /* A map from decl to stack partition.  */
    2377                 :     7801233 :   decl_to_stack_part = new hash_map<tree, unsigned>;
    2378                 :             : 
    2379                 :             :   /* Initialize local stack smashing state.  */
    2380                 :     7801233 :   has_protected_decls = false;
    2381                 :     7801233 :   has_short_buffer = false;
    2382                 :     7801233 :   if (hwasan_sanitize_stack_p ())
    2383                 :        1176 :     hwasan_record_frame_init ();
    2384                 :     7801233 : }
    2385                 :             : 
    2386                 :             : /* Free up stack variable graph data.  */
    2387                 :             : static void
    2388                 :     7801233 : fini_vars_expansion (void)
    2389                 :             : {
    2390                 :     7801233 :   bitmap_obstack_release (&stack_var_bitmap_obstack);
    2391                 :     7801233 :   if (stack_vars)
    2392                 :     1312156 :     XDELETEVEC (stack_vars);
    2393                 :     7801233 :   if (stack_vars_sorted)
    2394                 :     1312156 :     XDELETEVEC (stack_vars_sorted);
    2395                 :     7801233 :   stack_vars = NULL;
    2396                 :     7801233 :   stack_vars_sorted = NULL;
    2397                 :     7801233 :   stack_vars_alloc = stack_vars_num = 0;
    2398                 :    15602466 :   delete decl_to_stack_part;
    2399                 :     7801233 :   decl_to_stack_part = NULL;
    2400                 :     7801233 : }
    2401                 :             : 
    2402                 :             : /* Make a fair guess for the size of the stack frame of the function
    2403                 :             :    in NODE.  This doesn't have to be exact, the result is only used in
    2404                 :             :    the inline heuristics.  So we don't want to run the full stack var
    2405                 :             :    packing algorithm (which is quadratic in the number of stack vars).
    2406                 :             :    Instead, we calculate the total size of all stack vars.  This turns
    2407                 :             :    out to be a pretty fair estimate -- packing of stack vars doesn't
    2408                 :             :    happen very often.  */
    2409                 :             : 
    2410                 :             : HOST_WIDE_INT
    2411                 :     6339808 : estimated_stack_frame_size (struct cgraph_node *node)
    2412                 :             : {
    2413                 :     6339808 :   poly_int64 size = 0;
    2414                 :     6339808 :   unsigned i;
    2415                 :     6339808 :   tree var;
    2416                 :     6339808 :   struct function *fn = DECL_STRUCT_FUNCTION (node->decl);
    2417                 :             : 
    2418                 :     6339808 :   push_cfun (fn);
    2419                 :             : 
    2420                 :     6339808 :   init_vars_expansion ();
    2421                 :             : 
    2422                 :    25043532 :   FOR_EACH_LOCAL_DECL (fn, i, var)
    2423                 :    13537112 :     if (auto_var_in_fn_p (var, fn->decl))
    2424                 :    12962550 :       size += expand_one_var (var, true, false);
    2425                 :             : 
    2426                 :     6339808 :   if (stack_vars_num > 0)
    2427                 :             :     {
    2428                 :             :       /* Fake sorting the stack vars for account_stack_vars ().  */
    2429                 :     1078525 :       stack_vars_sorted = XNEWVEC (unsigned , stack_vars_num);
    2430                 :     5572161 :       for (i = 0; i < stack_vars_num; ++i)
    2431                 :     4493636 :         stack_vars_sorted[i] = i;
    2432                 :     1078525 :       size += account_stack_vars ();
    2433                 :             :     }
    2434                 :             : 
    2435                 :     6339808 :   fini_vars_expansion ();
    2436                 :     6339808 :   pop_cfun ();
    2437                 :     6339808 :   return estimated_poly_value (size);
    2438                 :             : }
    2439                 :             : 
    2440                 :             : /* Check if the current function has calls that use a return slot.  */
    2441                 :             : 
    2442                 :             : static bool
    2443                 :         417 : stack_protect_return_slot_p ()
    2444                 :             : {
    2445                 :         417 :   basic_block bb;
    2446                 :             : 
    2447                 :        1860 :   FOR_ALL_BB_FN (bb, cfun)
    2448                 :        2944 :     for (gimple_stmt_iterator gsi = gsi_start_bb (bb);
    2449                 :        3964 :          !gsi_end_p (gsi); gsi_next (&gsi))
    2450                 :             :       {
    2451                 :        2521 :         gimple *stmt = gsi_stmt (gsi);
    2452                 :             :         /* This assumes that calls to internal-only functions never
    2453                 :             :            use a return slot.  */
    2454                 :        2521 :         if (is_gimple_call (stmt)
    2455                 :         534 :             && !gimple_call_internal_p (stmt)
    2456                 :        3046 :             && aggregate_value_p (TREE_TYPE (gimple_call_fntype (stmt)),
    2457                 :         525 :                                   gimple_call_fndecl (stmt)))
    2458                 :         417 :           return true;
    2459                 :             :       }
    2460                 :             :   return false;
    2461                 :             : }
    2462                 :             : 
    2463                 :             : /* Expand all variables used in the function.  */
    2464                 :             : 
    2465                 :             : static rtx_insn *
    2466                 :     1461425 : expand_used_vars (bitmap forced_stack_vars)
    2467                 :             : {
    2468                 :     1461425 :   tree var, outer_block = DECL_INITIAL (current_function_decl);
    2469                 :     1461425 :   auto_vec<tree> maybe_local_decls;
    2470                 :     1461425 :   rtx_insn *var_end_seq = NULL;
    2471                 :     1461425 :   unsigned i;
    2472                 :     1461425 :   unsigned len;
    2473                 :     1461425 :   bool gen_stack_protect_signal = false;
    2474                 :             : 
    2475                 :             :   /* Compute the phase of the stack frame for this function.  */
    2476                 :     1461425 :   {
    2477                 :     1461425 :     int align = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT;
    2478                 :     1461425 :     int off = targetm.starting_frame_offset () % align;
    2479                 :     1461425 :     frame_phase = off ? align - off : 0;
    2480                 :             :   }
    2481                 :             : 
    2482                 :             :   /* Set TREE_USED on all variables in the local_decls.  */
    2483                 :    10452262 :   FOR_EACH_LOCAL_DECL (cfun, i, var)
    2484                 :     7766639 :     TREE_USED (var) = 1;
    2485                 :             :   /* Clear TREE_USED on all variables associated with a block scope.  */
    2486                 :     1461425 :   clear_tree_used (DECL_INITIAL (current_function_decl));
    2487                 :             : 
    2488                 :     1461425 :   init_vars_expansion ();
    2489                 :             : 
    2490                 :     1461425 :   if (targetm.use_pseudo_pic_reg ())
    2491                 :       79621 :     pic_offset_table_rtx = gen_reg_rtx (Pmode);
    2492                 :             : 
    2493                 :    27229999 :   for (i = 0; i < SA.map->num_partitions; i++)
    2494                 :             :     {
    2495                 :    25768574 :       if (bitmap_bit_p (SA.partitions_for_parm_default_defs, i))
    2496                 :     3582116 :         continue;
    2497                 :             : 
    2498                 :    22186458 :       tree var = partition_to_var (SA.map, i);
    2499                 :             : 
    2500                 :    44372916 :       gcc_assert (!virtual_operand_p (var));
    2501                 :             : 
    2502                 :    22186458 :       expand_one_ssa_partition (var);
    2503                 :             :     }
    2504                 :             : 
    2505                 :     1461425 :   if (flag_stack_protect == SPCT_FLAG_STRONG)
    2506                 :         417 :     gen_stack_protect_signal = stack_protect_return_slot_p ();
    2507                 :             : 
    2508                 :             :   /* At this point all variables on the local_decls with TREE_USED
    2509                 :             :      set are not associated with any block scope.  Lay them out.  */
    2510                 :             : 
    2511                 :     1461425 :   len = vec_safe_length (cfun->local_decls);
    2512                 :     9228064 :   FOR_EACH_LOCAL_DECL (cfun, i, var)
    2513                 :             :     {
    2514                 :     7766639 :       bool expand_now = false;
    2515                 :             : 
    2516                 :             :       /* Expanded above already.  */
    2517                 :     7766639 :       if (is_gimple_reg (var))
    2518                 :             :         {
    2519                 :     5422351 :           TREE_USED (var) = 0;
    2520                 :     5422351 :           goto next;
    2521                 :             :         }
    2522                 :             :       /* We didn't set a block for static or extern because it's hard
    2523                 :             :          to tell the difference between a global variable (re)declared
    2524                 :             :          in a local scope, and one that's really declared there to
    2525                 :             :          begin with.  And it doesn't really matter much, since we're
    2526                 :             :          not giving them stack space.  Expand them now.  */
    2527                 :     2344288 :       else if (TREE_STATIC (var) || DECL_EXTERNAL (var))
    2528                 :             :         expand_now = true;
    2529                 :             : 
    2530                 :             :       /* Expand variables not associated with any block now.  Those created by
    2531                 :             :          the optimizers could be live anywhere in the function.  Those that
    2532                 :             :          could possibly have been scoped originally and detached from their
    2533                 :             :          block will have their allocation deferred so we coalesce them with
    2534                 :             :          others when optimization is enabled.  */
    2535                 :     2131931 :       else if (TREE_USED (var))
    2536                 :     1668866 :         expand_now = true;
    2537                 :             : 
    2538                 :             :       /* Finally, mark all variables on the list as used.  We'll use
    2539                 :             :          this in a moment when we expand those associated with scopes.  */
    2540                 :     2344288 :       TREE_USED (var) = 1;
    2541                 :             : 
    2542                 :     2344288 :       if (expand_now)
    2543                 :     1668866 :         expand_one_var (var, true, true, forced_stack_vars);
    2544                 :             : 
    2545                 :      675422 :     next:
    2546                 :     7766639 :       if (DECL_ARTIFICIAL (var) && !DECL_IGNORED_P (var))
    2547                 :             :         {
    2548                 :      424773 :           rtx rtl = DECL_RTL_IF_SET (var);
    2549                 :             : 
    2550                 :             :           /* Keep artificial non-ignored vars in cfun->local_decls
    2551                 :             :              chain until instantiate_decls.  */
    2552                 :      315847 :           if (rtl && (MEM_P (rtl) || GET_CODE (rtl) == CONCAT))
    2553                 :       19578 :             add_local_decl (cfun, var);
    2554                 :      108926 :           else if (rtl == NULL_RTX)
    2555                 :             :             /* If rtl isn't set yet, which can happen e.g. with
    2556                 :             :                -fstack-protector, retry before returning from this
    2557                 :             :                function.  */
    2558                 :      108926 :             maybe_local_decls.safe_push (var);
    2559                 :             :         }
    2560                 :             :     }
    2561                 :             : 
    2562                 :             :   /* We duplicated some of the decls in CFUN->LOCAL_DECLS.
    2563                 :             : 
    2564                 :             :      +-----------------+-----------------+
    2565                 :             :      | ...processed... | ...duplicates...|
    2566                 :             :      +-----------------+-----------------+
    2567                 :             :                        ^
    2568                 :             :                        +-- LEN points here.
    2569                 :             : 
    2570                 :             :      We just want the duplicates, as those are the artificial
    2571                 :             :      non-ignored vars that we want to keep until instantiate_decls.
    2572                 :             :      Move them down and truncate the array.  */
    2573                 :     1461425 :   if (!vec_safe_is_empty (cfun->local_decls))
    2574                 :      824125 :     cfun->local_decls->block_remove (0, len);
    2575                 :             : 
    2576                 :             :   /* At this point, all variables within the block tree with TREE_USED
    2577                 :             :      set are actually used by the optimized function.  Lay them out.  */
    2578                 :     1461425 :   expand_used_vars_for_block (outer_block, true, forced_stack_vars);
    2579                 :             : 
    2580                 :     1461425 :   tree attribs = DECL_ATTRIBUTES (current_function_decl);
    2581                 :     1461425 :   if (stack_vars_num > 0)
    2582                 :             :     {
    2583                 :      233631 :       bool has_addressable_vars = false;
    2584                 :             : 
    2585                 :      233631 :       add_scope_conflicts ();
    2586                 :             : 
    2587                 :             :       /* If stack protection is enabled, we don't share space between
    2588                 :             :          vulnerable data and non-vulnerable data.  */
    2589                 :      233631 :       if (flag_stack_protect != 0
    2590                 :         223 :           && !lookup_attribute ("no_stack_protector", attribs)
    2591                 :      233854 :           && (flag_stack_protect != SPCT_FLAG_EXPLICIT
    2592                 :             :               || (flag_stack_protect == SPCT_FLAG_EXPLICIT
    2593                 :           1 :                   && lookup_attribute ("stack_protect", attribs))))
    2594                 :         223 :         has_addressable_vars = add_stack_protection_conflicts ();
    2595                 :             : 
    2596                 :      233631 :       if (flag_stack_protect == SPCT_FLAG_STRONG && has_addressable_vars)
    2597                 :      233631 :         gen_stack_protect_signal = true;
    2598                 :             : 
    2599                 :             :       /* Now that we have collected all stack variables, and have computed a
    2600                 :             :          minimal interference graph, attempt to save some stack space.  */
    2601                 :      233631 :       partition_stack_vars ();
    2602                 :      233631 :       if (dump_file)
    2603                 :          29 :         dump_stack_var_partition ();
    2604                 :             :     }
    2605                 :             : 
    2606                 :             : 
    2607                 :     1461425 :   if (!lookup_attribute ("no_stack_protector", attribs))
    2608                 :     1461416 :     switch (flag_stack_protect)
    2609                 :             :       {
    2610                 :          19 :       case SPCT_FLAG_ALL:
    2611                 :          19 :         create_stack_guard ();
    2612                 :          19 :         break;
    2613                 :             : 
    2614                 :         417 :       case SPCT_FLAG_STRONG:
    2615                 :         417 :         if (gen_stack_protect_signal
    2616                 :         273 :             || cfun->calls_alloca
    2617                 :         271 :             || has_protected_decls
    2618                 :         680 :             || lookup_attribute ("stack_protect", attribs))
    2619                 :         154 :           create_stack_guard ();
    2620                 :             :         break;
    2621                 :             : 
    2622                 :         144 :       case SPCT_FLAG_DEFAULT:
    2623                 :         144 :         if (cfun->calls_alloca
    2624                 :         141 :             || has_protected_decls
    2625                 :         232 :             || lookup_attribute ("stack_protect", attribs))
    2626                 :          56 :           create_stack_guard ();
    2627                 :             :         break;
    2628                 :             : 
    2629                 :          14 :       case SPCT_FLAG_EXPLICIT:
    2630                 :          14 :         if (lookup_attribute ("stack_protect", attribs))
    2631                 :          10 :           create_stack_guard ();
    2632                 :             :         break;
    2633                 :             : 
    2634                 :             :       default:
    2635                 :             :         break;
    2636                 :             :       }
    2637                 :             : 
    2638                 :             :   /* Assign rtl to each variable based on these partitions.  */
    2639                 :     1461425 :   if (stack_vars_num > 0)
    2640                 :             :     {
    2641                 :      233631 :       class stack_vars_data data;
    2642                 :             : 
    2643                 :      233631 :       data.asan_base = NULL_RTX;
    2644                 :      233631 :       data.asan_alignb = 0;
    2645                 :             : 
    2646                 :             :       /* Reorder decls to be protected by iterating over the variables
    2647                 :             :          array multiple times, and allocating out of each phase in turn.  */
    2648                 :             :       /* ??? We could probably integrate this into the qsort we did
    2649                 :             :          earlier, such that we naturally see these variables first,
    2650                 :             :          and thus naturally allocate things in the right order.  */
    2651                 :      233631 :       if (has_protected_decls)
    2652                 :             :         {
    2653                 :             :           /* Phase 1 contains only character arrays.  */
    2654                 :         129 :           expand_stack_vars (stack_protect_decl_phase_1, &data);
    2655                 :             : 
    2656                 :             :           /* Phase 2 contains other kinds of arrays.  */
    2657                 :         129 :           if (!lookup_attribute ("no_stack_protector", attribs)
    2658                 :         129 :               && (flag_stack_protect == SPCT_FLAG_ALL
    2659                 :         129 :                   || flag_stack_protect == SPCT_FLAG_STRONG
    2660                 :          54 :                   || (flag_stack_protect == SPCT_FLAG_EXPLICIT
    2661                 :           1 :                       && lookup_attribute ("stack_protect", attribs))))
    2662                 :          76 :             expand_stack_vars (stack_protect_decl_phase_2, &data);
    2663                 :             :         }
    2664                 :             : 
    2665                 :      233631 :       if (asan_sanitize_stack_p ())
    2666                 :             :         /* Phase 3, any partitions that need asan protection
    2667                 :             :            in addition to phase 1 and 2.  */
    2668                 :        1783 :         expand_stack_vars (asan_decl_phase_3, &data);
    2669                 :             : 
    2670                 :             :       /* ASAN description strings don't yet have a syntax for expressing
    2671                 :             :          polynomial offsets.  */
    2672                 :      233631 :       HOST_WIDE_INT prev_offset;
    2673                 :      235226 :       if (!data.asan_vec.is_empty ()
    2674                 :        1595 :           && frame_offset.is_constant (&prev_offset))
    2675                 :             :         {
    2676                 :        1595 :           HOST_WIDE_INT offset, sz, redzonesz;
    2677                 :        1595 :           redzonesz = ASAN_RED_ZONE_SIZE;
    2678                 :        1595 :           sz = data.asan_vec[0] - prev_offset;
    2679                 :        1595 :           if (data.asan_alignb > ASAN_RED_ZONE_SIZE
    2680                 :        1595 :               && data.asan_alignb <= 4096
    2681                 :          45 :               && sz + ASAN_RED_ZONE_SIZE >= (int) data.asan_alignb)
    2682                 :          45 :             redzonesz = ((sz + ASAN_RED_ZONE_SIZE + data.asan_alignb - 1)
    2683                 :          45 :                          & ~(data.asan_alignb - HOST_WIDE_INT_1)) - sz;
    2684                 :             :           /* Allocating a constant amount of space from a constant
    2685                 :             :              starting offset must give a constant result.  */
    2686                 :        1595 :           offset = (alloc_stack_frame_space (redzonesz, ASAN_RED_ZONE_SIZE)
    2687                 :        1595 :                     .to_constant ());
    2688                 :        1595 :           data.asan_vec.safe_push (prev_offset);
    2689                 :        1595 :           data.asan_vec.safe_push (offset);
    2690                 :             :           /* Leave space for alignment if STRICT_ALIGNMENT.  */
    2691                 :        1595 :           if (STRICT_ALIGNMENT)
    2692                 :             :             alloc_stack_frame_space ((GET_MODE_ALIGNMENT (SImode)
    2693                 :             :                                       << ASAN_SHADOW_SHIFT)
    2694                 :             :                                      / BITS_PER_UNIT, 1);
    2695                 :             : 
    2696                 :        1595 :           var_end_seq
    2697                 :        3190 :             = asan_emit_stack_protection (virtual_stack_vars_rtx,
    2698                 :             :                                           data.asan_base,
    2699                 :             :                                           data.asan_alignb,
    2700                 :             :                                           data.asan_vec.address (),
    2701                 :             :                                           data.asan_decl_vec.address (),
    2702                 :        1595 :                                           data.asan_vec.length ());
    2703                 :             :         }
    2704                 :             : 
    2705                 :      233631 :       expand_stack_vars (NULL, &data);
    2706                 :      233631 :     }
    2707                 :             : 
    2708                 :     1461425 :   if (hwasan_sanitize_stack_p ())
    2709                 :         432 :     hwasan_emit_prologue ();
    2710                 :     1461425 :   if (asan_sanitize_allocas_p () && cfun->calls_alloca)
    2711                 :         178 :     var_end_seq = asan_emit_allocas_unpoison (virtual_stack_dynamic_rtx,
    2712                 :             :                                               virtual_stack_vars_rtx,
    2713                 :             :                                               var_end_seq);
    2714                 :     1461247 :   else if (hwasan_sanitize_allocas_p () && cfun->calls_alloca)
    2715                 :             :     /* When using out-of-line instrumentation we only want to emit one function
    2716                 :             :        call for clearing the tags in a region of shadow stack.  When there are
    2717                 :             :        alloca calls in this frame we want to emit a call using the
    2718                 :             :        virtual_stack_dynamic_rtx, but when not we use the hwasan_frame_extent
    2719                 :             :        rtx we created in expand_stack_vars.  */
    2720                 :           0 :     var_end_seq = hwasan_emit_untag_frame (virtual_stack_dynamic_rtx,
    2721                 :             :                                            virtual_stack_vars_rtx);
    2722                 :     1461247 :   else if (hwasan_sanitize_stack_p ())
    2723                 :             :     /* If no variables were stored on the stack, `hwasan_get_frame_extent`
    2724                 :             :        will return NULL_RTX and hence `hwasan_emit_untag_frame` will return
    2725                 :             :        NULL (i.e. an empty sequence).  */
    2726                 :         432 :     var_end_seq = hwasan_emit_untag_frame (hwasan_get_frame_extent (),
    2727                 :             :                                            virtual_stack_vars_rtx);
    2728                 :             : 
    2729                 :     1461425 :   fini_vars_expansion ();
    2730                 :             : 
    2731                 :             :   /* If there were any artificial non-ignored vars without rtl
    2732                 :             :      found earlier, see if deferred stack allocation hasn't assigned
    2733                 :             :      rtl to them.  */
    2734                 :     1613695 :   FOR_EACH_VEC_ELT_REVERSE (maybe_local_decls, i, var)
    2735                 :             :     {
    2736                 :      108926 :       rtx rtl = DECL_RTL_IF_SET (var);
    2737                 :             : 
    2738                 :             :       /* Keep artificial non-ignored vars in cfun->local_decls
    2739                 :             :          chain until instantiate_decls.  */
    2740                 :        4488 :       if (rtl && (MEM_P (rtl) || GET_CODE (rtl) == CONCAT))
    2741                 :        4376 :         add_local_decl (cfun, var);
    2742                 :             :     }
    2743                 :             : 
    2744                 :             :   /* If the target requires that FRAME_OFFSET be aligned, do it.  */
    2745                 :     1461425 :   if (STACK_ALIGNMENT_NEEDED)
    2746                 :             :     {
    2747                 :     1461425 :       HOST_WIDE_INT align = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT;
    2748                 :     1461425 :       if (FRAME_GROWS_DOWNWARD)
    2749                 :     1461425 :         frame_offset = aligned_lower_bound (frame_offset, align);
    2750                 :             :       else
    2751                 :             :         frame_offset = aligned_upper_bound (frame_offset, align);
    2752                 :             :     }
    2753                 :             : 
    2754                 :     1461425 :   return var_end_seq;
    2755                 :     1461425 : }
    2756                 :             : 
    2757                 :             : 
    2758                 :             : /* If we need to produce a detailed dump, print the tree representation
    2759                 :             :    for STMT to the dump file.  SINCE is the last RTX after which the RTL
    2760                 :             :    generated for STMT should have been appended.  */
    2761                 :             : 
    2762                 :             : static void
    2763                 :    41644990 : maybe_dump_rtl_for_gimple_stmt (gimple *stmt, rtx_insn *since)
    2764                 :             : {
    2765                 :    41644990 :   if (dump_file && (dump_flags & TDF_DETAILS))
    2766                 :             :     {
    2767                 :         384 :       fprintf (dump_file, "\n;; ");
    2768                 :         384 :       print_gimple_stmt (dump_file, stmt, 0,
    2769                 :             :                          TDF_SLIM | (dump_flags & TDF_LINENO));
    2770                 :         384 :       fprintf (dump_file, "\n");
    2771                 :             : 
    2772                 :         384 :       print_rtl (dump_file, since ? NEXT_INSN (since) : since);
    2773                 :             :     }
    2774                 :    41644990 : }
    2775                 :             : 
    2776                 :             : /* Temporary storage for BB_HEAD and BB_END of bbs until they are converted
    2777                 :             :    to BB_RTL.  */
    2778                 :             : static vec<std::pair <rtx_insn *, rtx_insn *>> head_end_for_bb;
    2779                 :             : 
    2780                 :             : /* Maps the blocks that do not contain tree labels to rtx labels.  */
    2781                 :             : 
    2782                 :             : static hash_map<basic_block, rtx_code_label *> *lab_rtx_for_bb;
    2783                 :             : 
    2784                 :             : /* Returns the label_rtx expression for a label starting basic block BB.  */
    2785                 :             : 
    2786                 :             : static rtx_code_label *
    2787                 :     7743450 : label_rtx_for_bb (basic_block bb)
    2788                 :             : {
    2789                 :     7743450 :   if (bb->flags & BB_RTL)
    2790                 :           0 :     return block_label (bb);
    2791                 :             : 
    2792                 :     7743450 :   if ((unsigned) bb->index < head_end_for_bb.length ()
    2793                 :     7743450 :       && head_end_for_bb[bb->index].first)
    2794                 :             :     {
    2795                 :     1710316 :       if (!LABEL_P (head_end_for_bb[bb->index].first))
    2796                 :             :         {
    2797                 :     1016423 :           head_end_for_bb[bb->index].first
    2798                 :     2032846 :             = emit_label_before (gen_label_rtx (),
    2799                 :     1016423 :                                  head_end_for_bb[bb->index].first);
    2800                 :             :         }
    2801                 :     1710316 :       return as_a <rtx_code_label *> (head_end_for_bb[bb->index].first);
    2802                 :             :     }
    2803                 :             : 
    2804                 :     6033134 :   rtx_code_label **elt = lab_rtx_for_bb->get (bb);
    2805                 :     6033134 :   if (elt)
    2806                 :     1193646 :     return *elt;
    2807                 :             : 
    2808                 :             :   /* Find the tree label if it is present.  */
    2809                 :     4839488 :   gimple_stmt_iterator gsi = gsi_start_bb (bb);
    2810                 :     4839488 :   glabel *lab_stmt;
    2811                 :     4839488 :   if (!gsi_end_p (gsi)
    2812                 :     4705684 :       && (lab_stmt = dyn_cast <glabel *> (gsi_stmt (gsi)))
    2813                 :     5056011 :       && !DECL_NONLOCAL (gimple_label_label (lab_stmt)))
    2814                 :      216523 :     return jump_target_rtx (gimple_label_label (lab_stmt));
    2815                 :             : 
    2816                 :     4622965 :   rtx_code_label *l = gen_label_rtx ();
    2817                 :     4622965 :   lab_rtx_for_bb->put (bb, l);
    2818                 :     4622965 :   return l;
    2819                 :             : }
    2820                 :             : 
    2821                 :             : 
    2822                 :             : /* Wrapper around remove_edge during expansion.  */
    2823                 :             : 
    2824                 :             : void
    2825                 :      128348 : expand_remove_edge (edge e)
    2826                 :             : {
    2827                 :      128348 :   if (current_ir_type () != IR_GIMPLE
    2828                 :      128348 :       && (e->dest->flags & BB_RTL) == 0
    2829                 :      191817 :       && !gimple_seq_empty_p (phi_nodes (e->dest)))
    2830                 :        8510 :     remove_phi_args (e);
    2831                 :      128348 :   remove_edge (e);
    2832                 :      128348 : }
    2833                 :             : 
    2834                 :             : /* Split edge E during expansion and instead of creating a new
    2835                 :             :    bb on that edge, add there BB.  FLAGS should be flags on the
    2836                 :             :    new edge from BB to former E->dest.  */
    2837                 :             : 
    2838                 :             : static void
    2839                 :     1948975 : expand_split_edge (edge e, basic_block bb, int flags)
    2840                 :             : {
    2841                 :     1948975 :   unsigned int dest_idx = e->dest_idx;
    2842                 :     1948975 :   basic_block dest = e->dest;
    2843                 :     1948975 :   redirect_edge_succ (e, bb);
    2844                 :     1948975 :   e = make_single_succ_edge (bb, dest, flags);
    2845                 :     1948975 :   if ((dest->flags & BB_RTL) == 0
    2846                 :     1948975 :       && phi_nodes (dest)
    2847                 :     2109117 :       && e->dest_idx != dest_idx)
    2848                 :             :     {
    2849                 :             :       /* If there are any PHI nodes on dest, swap the new succ edge
    2850                 :             :          with the one moved into false_edge's former position, so that
    2851                 :             :          PHI arguments don't need adjustment.  */
    2852                 :       99234 :       edge e2 = EDGE_PRED (dest, dest_idx);
    2853                 :       99234 :       std::swap (e->dest_idx, e2->dest_idx);
    2854                 :       99234 :       std::swap (EDGE_PRED (dest, e->dest_idx),
    2855                 :             :                  EDGE_PRED (dest, e2->dest_idx));
    2856                 :             :     }
    2857                 :     1948975 : }
    2858                 :             : 
    2859                 :             : 
    2860                 :             : /* A subroutine of expand_gimple_cond.  Given E, a fallthrough edge
    2861                 :             :    of a basic block where we just expanded the conditional at the end,
    2862                 :             :    possibly clean up the CFG and instruction sequence.  LAST is the
    2863                 :             :    last instruction before the just emitted jump sequence.  */
    2864                 :             : 
    2865                 :             : static void
    2866                 :     5142351 : maybe_cleanup_end_of_block (edge e, rtx_insn *last)
    2867                 :             : {
    2868                 :             :   /* Special case: when jumpif decides that the condition is
    2869                 :             :      trivial it emits an unconditional jump (and the necessary
    2870                 :             :      barrier).  But we still have two edges, the fallthru one is
    2871                 :             :      wrong.  purge_dead_edges would clean this up later.  Unfortunately
    2872                 :             :      we have to insert insns (and split edges) before
    2873                 :             :      find_many_sub_basic_blocks and hence before purge_dead_edges.
    2874                 :             :      But splitting edges might create new blocks which depend on the
    2875                 :             :      fact that if there are two edges there's no barrier.  So the
    2876                 :             :      barrier would get lost and verify_flow_info would ICE.  Instead
    2877                 :             :      of auditing all edge splitters to care for the barrier (which
    2878                 :             :      normally isn't there in a cleaned CFG), fix it here.  */
    2879                 :     5142351 :   if (BARRIER_P (get_last_insn ()))
    2880                 :             :     {
    2881                 :         100 :       rtx_insn *insn;
    2882                 :         100 :       expand_remove_edge (e);
    2883                 :             :       /* Now, we have a single successor block, if we have insns to
    2884                 :             :          insert on the remaining edge we potentially will insert
    2885                 :             :          it at the end of this block (if the dest block isn't feasible)
    2886                 :             :          in order to avoid splitting the edge.  This insertion will take
    2887                 :             :          place in front of the last jump.  But we might have emitted
    2888                 :             :          multiple jumps (conditional and one unconditional) to the
    2889                 :             :          same destination.  Inserting in front of the last one then
    2890                 :             :          is a problem.  See PR 40021.  We fix this by deleting all
    2891                 :             :          jumps except the last unconditional one.  */
    2892                 :         100 :       insn = PREV_INSN (get_last_insn ());
    2893                 :             :       /* Make sure we have an unconditional jump.  Otherwise we're
    2894                 :             :          confused.  */
    2895                 :         100 :       gcc_assert (JUMP_P (insn) && !any_condjump_p (insn));
    2896                 :         200 :       for (insn = PREV_INSN (insn); insn != last;)
    2897                 :             :         {
    2898                 :           0 :           insn = PREV_INSN (insn);
    2899                 :           0 :           if (JUMP_P (NEXT_INSN (insn)))
    2900                 :             :             {
    2901                 :           0 :               if (!any_condjump_p (NEXT_INSN (insn)))
    2902                 :             :                 {
    2903                 :           0 :                   gcc_assert (BARRIER_P (NEXT_INSN (NEXT_INSN (insn))));
    2904                 :           0 :                   delete_insn (NEXT_INSN (NEXT_INSN (insn)));
    2905                 :             :                 }
    2906                 :           0 :               delete_insn (NEXT_INSN (insn));
    2907                 :             :             }
    2908                 :             :         }
    2909                 :             :     }
    2910                 :     5142351 : }
    2911                 :             : 
    2912                 :             : /* A subroutine of expand_gimple_basic_block.  Expand one GIMPLE_COND.
    2913                 :             :    Returns a new basic block if we've terminated the current basic
    2914                 :             :    block and created a new one.  */
    2915                 :             : 
    2916                 :             : static basic_block
    2917                 :     5629901 : expand_gimple_cond (basic_block bb, gcond *stmt)
    2918                 :             : {
    2919                 :     5629901 :   basic_block new_bb, dest;
    2920                 :     5629901 :   edge true_edge;
    2921                 :     5629901 :   edge false_edge;
    2922                 :     5629901 :   rtx_insn *last2, *last;
    2923                 :     5629901 :   enum tree_code code;
    2924                 :     5629901 :   tree op0, op1;
    2925                 :             : 
    2926                 :     5629901 :   code = gimple_cond_code (stmt);
    2927                 :     5629901 :   op0 = gimple_cond_lhs (stmt);
    2928                 :     5629901 :   op1 = gimple_cond_rhs (stmt);
    2929                 :             :   /* We're sometimes presented with such code:
    2930                 :             :        D.123_1 = x < y;
    2931                 :             :        if (D.123_1 != 0)
    2932                 :             :          ...
    2933                 :             :      This would expand to two comparisons which then later might
    2934                 :             :      be cleaned up by combine.  But some pattern matchers like if-conversion
    2935                 :             :      work better when there's only one compare, so make up for this
    2936                 :             :      here as special exception if TER would have made the same change.  */
    2937                 :     5629901 :   if (SA.values
    2938                 :     4121339 :       && TREE_CODE (op0) == SSA_NAME
    2939                 :     4120753 :       && TREE_CODE (TREE_TYPE (op0)) == BOOLEAN_TYPE
    2940                 :      383533 :       && TREE_CODE (op1) == INTEGER_CST
    2941                 :      373926 :       && ((gimple_cond_code (stmt) == NE_EXPR
    2942                 :      373914 :            && integer_zerop (op1))
    2943                 :          12 :           || (gimple_cond_code (stmt) == EQ_EXPR
    2944                 :          12 :               && integer_onep (op1)))
    2945                 :     6003827 :       && bitmap_bit_p (SA.values, SSA_NAME_VERSION (op0)))
    2946                 :             :     {
    2947                 :      201809 :       gimple *second = SSA_NAME_DEF_STMT (op0);
    2948                 :      201809 :       if (gimple_code (second) == GIMPLE_ASSIGN)
    2949                 :             :         {
    2950                 :      201809 :           enum tree_code code2 = gimple_assign_rhs_code (second);
    2951                 :      201809 :           if (TREE_CODE_CLASS (code2) == tcc_comparison)
    2952                 :             :             {
    2953                 :         738 :               code = code2;
    2954                 :         738 :               op0 = gimple_assign_rhs1 (second);
    2955                 :         738 :               op1 = gimple_assign_rhs2 (second);
    2956                 :             :             }
    2957                 :             :           /* If jumps are cheap and the target does not support conditional
    2958                 :             :              compare, turn some more codes into jumpy sequences.  */
    2959                 :      201071 :           else if (BRANCH_COST (optimize_insn_for_speed_p (), false) < 4
    2960                 :      201071 :                    && !targetm.have_ccmp ())
    2961                 :             :             {
    2962                 :      201068 :               if ((code2 == BIT_AND_EXPR
    2963                 :       60651 :                    && TYPE_PRECISION (TREE_TYPE (op0)) == 1
    2964                 :       60651 :                    && TREE_CODE (gimple_assign_rhs2 (second)) != INTEGER_CST)
    2965                 :      201068 :                   || code2 == TRUTH_AND_EXPR)
    2966                 :             :                 {
    2967                 :       60651 :                   code = TRUTH_ANDIF_EXPR;
    2968                 :       60651 :                   op0 = gimple_assign_rhs1 (second);
    2969                 :       60651 :                   op1 = gimple_assign_rhs2 (second);
    2970                 :             :                 }
    2971                 :      140417 :               else if (code2 == BIT_IOR_EXPR || code2 == TRUTH_OR_EXPR)
    2972                 :             :                 {
    2973                 :       61275 :                   code = TRUTH_ORIF_EXPR;
    2974                 :       61275 :                   op0 = gimple_assign_rhs1 (second);
    2975                 :       61275 :                   op1 = gimple_assign_rhs2 (second);
    2976                 :             :                 }
    2977                 :             :             }
    2978                 :             :         }
    2979                 :             :     }
    2980                 :             : 
    2981                 :             :   /* Optimize (x % C1) == C2 or (x % C1) != C2 if it is beneficial
    2982                 :             :      into (x - C2) * C3 < C4.  */
    2983                 :     5629901 :   if ((code == EQ_EXPR || code == NE_EXPR)
    2984                 :     4409642 :       && TREE_CODE (op0) == SSA_NAME
    2985                 :     4408882 :       && TREE_CODE (op1) == INTEGER_CST)
    2986                 :     3073043 :     code = maybe_optimize_mod_cmp (code, &op0, &op1);
    2987                 :             : 
    2988                 :             :   /* Optimize (x - y) < 0 into x < y if x - y has undefined overflow.  */
    2989                 :     5629901 :   if (!TYPE_UNSIGNED (TREE_TYPE (op0))
    2990                 :     2269412 :       && (code == LT_EXPR || code == LE_EXPR
    2991                 :     2269412 :           || code == GT_EXPR || code == GE_EXPR)
    2992                 :      684429 :       && integer_zerop (op1)
    2993                 :     5827426 :       && TREE_CODE (op0) == SSA_NAME)
    2994                 :      197525 :     maybe_optimize_sub_cmp_0 (code, &op0, &op1);
    2995                 :             : 
    2996                 :     5629901 :   last2 = last = get_last_insn ();
    2997                 :             : 
    2998                 :     5629901 :   extract_true_false_edges_from_block (bb, &true_edge, &false_edge);
    2999                 :     5629901 :   set_curr_insn_location (gimple_location (stmt));
    3000                 :             : 
    3001                 :             :   /* We can either have a pure conditional jump with one fallthru edge or
    3002                 :             :      two-way jump that needs to be decomposed into two basic blocks.  */
    3003                 :     5629901 :   if (false_edge->dest == bb->next_bb)
    3004                 :             :     {
    3005                 :     2250759 :       jumpif_1 (code, op0, op1, label_rtx_for_bb (true_edge->dest),
    3006                 :             :                 true_edge->probability);
    3007                 :     2250759 :       maybe_dump_rtl_for_gimple_stmt (stmt, last);
    3008                 :     2250759 :       if (true_edge->goto_locus != UNKNOWN_LOCATION)
    3009                 :      341545 :         set_curr_insn_location (true_edge->goto_locus);
    3010                 :     2250759 :       false_edge->flags |= EDGE_FALLTHRU;
    3011                 :     2250759 :       maybe_cleanup_end_of_block (false_edge, last);
    3012                 :     2250759 :       return NULL;
    3013                 :             :     }
    3014                 :     3379142 :   if (true_edge->dest == bb->next_bb)
    3015                 :             :     {
    3016                 :     2891592 :       jumpifnot_1 (code, op0, op1, label_rtx_for_bb (false_edge->dest),
    3017                 :             :                    false_edge->probability);
    3018                 :     2891592 :       maybe_dump_rtl_for_gimple_stmt (stmt, last);
    3019                 :     2891592 :       if (false_edge->goto_locus != UNKNOWN_LOCATION)
    3020                 :       22935 :         set_curr_insn_location (false_edge->goto_locus);
    3021                 :     2891592 :       true_edge->flags |= EDGE_FALLTHRU;
    3022                 :     2891592 :       maybe_cleanup_end_of_block (true_edge, last);
    3023                 :     2891592 :       return NULL;
    3024                 :             :     }
    3025                 :             : 
    3026                 :      487550 :   jumpif_1 (code, op0, op1, label_rtx_for_bb (true_edge->dest),
    3027                 :             :             true_edge->probability);
    3028                 :      487550 :   last = get_last_insn ();
    3029                 :      487550 :   if (false_edge->goto_locus != UNKNOWN_LOCATION)
    3030                 :        1308 :     set_curr_insn_location (false_edge->goto_locus);
    3031                 :      487550 :   emit_jump (label_rtx_for_bb (false_edge->dest));
    3032                 :             : 
    3033                 :      487550 :   head_end_for_bb[bb->index].second = last;
    3034                 :      487550 :   if (BARRIER_P (head_end_for_bb[bb->index].second))
    3035                 :         148 :     head_end_for_bb[bb->index].second
    3036                 :          74 :       = PREV_INSN (head_end_for_bb[bb->index].second);
    3037                 :      975100 :   update_bb_for_insn_chain (head_end_for_bb[bb->index].first,
    3038                 :      487550 :                             head_end_for_bb[bb->index].second, bb);
    3039                 :             : 
    3040                 :      487550 :   new_bb = create_basic_block (NEXT_INSN (last), get_last_insn (), bb);
    3041                 :      487550 :   dest = false_edge->dest;
    3042                 :      487550 :   expand_split_edge (false_edge, new_bb, 0);
    3043                 :      487550 :   false_edge->flags |= EDGE_FALLTHRU;
    3044                 :      487550 :   new_bb->count = false_edge->count ();
    3045                 :      487550 :   loop_p loop = find_common_loop (bb->loop_father, dest->loop_father);
    3046                 :      487550 :   add_bb_to_loop (new_bb, loop);
    3047                 :      487550 :   if (loop->latch == bb
    3048                 :       31056 :       && loop->header == dest)
    3049                 :       31053 :     loop->latch = new_bb;
    3050                 :      487550 :   if (BARRIER_P (BB_END (new_bb)))
    3051                 :      487550 :     BB_END (new_bb) = PREV_INSN (BB_END (new_bb));
    3052                 :      487550 :   update_bb_for_insn (new_bb);
    3053                 :             : 
    3054                 :      487550 :   maybe_dump_rtl_for_gimple_stmt (stmt, last2);
    3055                 :             : 
    3056                 :      487550 :   if (true_edge->goto_locus != UNKNOWN_LOCATION)
    3057                 :             :     {
    3058                 :       59884 :       set_curr_insn_location (true_edge->goto_locus);
    3059                 :       59884 :       true_edge->goto_locus = curr_insn_location ();
    3060                 :             :     }
    3061                 :             : 
    3062                 :             :   return new_bb;
    3063                 :             : }
    3064                 :             : 
    3065                 :             : /* Mark all calls that can have a transaction restart.  */
    3066                 :             : 
    3067                 :             : static void
    3068                 :     6572504 : mark_transaction_restart_calls (gimple *stmt)
    3069                 :             : {
    3070                 :     6572504 :   struct tm_restart_node dummy;
    3071                 :     6572504 :   tm_restart_node **slot;
    3072                 :             : 
    3073                 :     6572504 :   if (!cfun->gimple_df->tm_restart)
    3074                 :     6569520 :     return;
    3075                 :             : 
    3076                 :        2984 :   dummy.stmt = stmt;
    3077                 :        2984 :   slot = cfun->gimple_df->tm_restart->find_slot (&dummy, NO_INSERT);
    3078                 :        2984 :   if (slot)
    3079                 :             :     {
    3080                 :           0 :       struct tm_restart_node *n = *slot;
    3081                 :           0 :       tree list = n->label_or_list;
    3082                 :           0 :       rtx_insn *insn;
    3083                 :             : 
    3084                 :           0 :       for (insn = next_real_insn (get_last_insn ());
    3085                 :           0 :            !CALL_P (insn);
    3086                 :           0 :            insn = next_real_insn (insn))
    3087                 :           0 :         continue;
    3088                 :             : 
    3089                 :           0 :       if (TREE_CODE (list) == LABEL_DECL)
    3090                 :           0 :         add_reg_note (insn, REG_TM, label_rtx (list));
    3091                 :             :       else
    3092                 :           0 :         for (; list ; list = TREE_CHAIN (list))
    3093                 :           0 :           add_reg_note (insn, REG_TM, label_rtx (TREE_VALUE (list)));
    3094                 :           0 :     }
    3095                 :             : }
    3096                 :             : 
    3097                 :             : /* A subroutine of expand_gimple_stmt_1, expanding one GIMPLE_CALL
    3098                 :             :    statement STMT.  */
    3099                 :             : 
    3100                 :             : static void
    3101                 :     6764654 : expand_call_stmt (gcall *stmt)
    3102                 :             : {
    3103                 :     6764654 :   tree exp, decl, lhs;
    3104                 :     6764654 :   bool builtin_p;
    3105                 :     6764654 :   size_t i;
    3106                 :             : 
    3107                 :     6764654 :   if (gimple_call_internal_p (stmt))
    3108                 :             :     {
    3109                 :      155322 :       expand_internal_call (stmt);
    3110                 :      155322 :       return;
    3111                 :             :     }
    3112                 :             : 
    3113                 :             :   /* If this is a call to a built-in function and it has no effect other
    3114                 :             :      than setting the lhs, try to implement it using an internal function
    3115                 :             :      instead.  */
    3116                 :     6609332 :   decl = gimple_call_fndecl (stmt);
    3117                 :     6609332 :   if (gimple_call_lhs (stmt)
    3118                 :     2327092 :       && !gimple_has_side_effects (stmt)
    3119                 :     7312886 :       && (optimize || (decl && called_as_built_in (decl))))
    3120                 :             :     {
    3121                 :      683586 :       internal_fn ifn = replacement_internal_fn (stmt);
    3122                 :      683586 :       if (ifn != IFN_LAST)
    3123                 :             :         {
    3124                 :       36828 :           expand_internal_call (ifn, stmt);
    3125                 :       36828 :           return;
    3126                 :             :         }
    3127                 :             :     }
    3128                 :             : 
    3129                 :     6572504 :   exp = build_vl_exp (CALL_EXPR, gimple_call_num_args (stmt) + 3);
    3130                 :             : 
    3131                 :     6572504 :   CALL_EXPR_FN (exp) = gimple_call_fn (stmt);
    3132                 :     6572504 :   builtin_p = decl && fndecl_built_in_p (decl);
    3133                 :             : 
    3134                 :             :   /* If this is not a builtin function, the function type through which the
    3135                 :             :      call is made may be different from the type of the function.  */
    3136                 :     4619268 :   if (!builtin_p)
    3137                 :     9238536 :     CALL_EXPR_FN (exp)
    3138                 :    13857804 :       = fold_convert (build_pointer_type (gimple_call_fntype (stmt)),
    3139                 :             :                       CALL_EXPR_FN (exp));
    3140                 :             : 
    3141                 :     6572504 :   TREE_TYPE (exp) = gimple_call_return_type (stmt);
    3142                 :     6572504 :   CALL_EXPR_STATIC_CHAIN (exp) = gimple_call_chain (stmt);
    3143                 :             : 
    3144                 :    19871348 :   for (i = 0; i < gimple_call_num_args (stmt); i++)
    3145                 :             :     {
    3146                 :    13298844 :       tree arg = gimple_call_arg (stmt, i);
    3147                 :    13298844 :       gimple *def;
    3148                 :             :       /* TER addresses into arguments of builtin functions so we have a
    3149                 :             :          chance to infer more correct alignment information.  See PR39954.  */
    3150                 :    13298844 :       if (builtin_p
    3151                 :     4010879 :           && TREE_CODE (arg) == SSA_NAME
    3152                 :     1337004 :           && (def = get_gimple_for_ssa_name (arg))
    3153                 :      331522 :           && is_gimple_assign (def)
    3154                 :    13630205 :           && gimple_assign_rhs_code (def) == ADDR_EXPR)
    3155                 :       14303 :         arg = gimple_assign_rhs1 (def);
    3156                 :    13298844 :       CALL_EXPR_ARG (exp, i) = arg;
    3157                 :             :     }
    3158                 :             : 
    3159                 :     6572504 :   if (gimple_has_side_effects (stmt)
    3160                 :             :       /* ???  Downstream in expand_expr_real_1 we assume that expressions
    3161                 :             :          w/o side-effects do not throw so work around this here.  */
    3162                 :     6572504 :       || stmt_could_throw_p (cfun, stmt))
    3163                 :     5908068 :     TREE_SIDE_EFFECTS (exp) = 1;
    3164                 :             : 
    3165                 :     6572504 :   if (gimple_call_nothrow_p (stmt))
    3166                 :     2929978 :     TREE_NOTHROW (exp) = 1;
    3167                 :             : 
    3168                 :     6572504 :   CALL_EXPR_TAILCALL (exp) = gimple_call_tail_p (stmt);
    3169                 :     6572504 :   CALL_EXPR_MUST_TAIL_CALL (exp) = gimple_call_must_tail_p (stmt);
    3170                 :     6572504 :   CALL_EXPR_RETURN_SLOT_OPT (exp) = gimple_call_return_slot_opt_p (stmt);
    3171                 :     6572504 :   if (decl
    3172                 :     6382702 :       && fndecl_built_in_p (decl, BUILT_IN_NORMAL)
    3173                 :     8354484 :       && ALLOCA_FUNCTION_CODE_P (DECL_FUNCTION_CODE (decl)))
    3174                 :       25566 :     CALL_ALLOCA_FOR_VAR_P (exp) = gimple_call_alloca_for_var_p (stmt);
    3175                 :             :   else
    3176                 :     6546938 :     CALL_FROM_THUNK_P (exp) = gimple_call_from_thunk_p (stmt);
    3177                 :     6572504 :   CALL_EXPR_VA_ARG_PACK (exp) = gimple_call_va_arg_pack_p (stmt);
    3178                 :     6572504 :   CALL_EXPR_BY_DESCRIPTOR (exp) = gimple_call_by_descriptor_p (stmt);
    3179                 :     6572504 :   SET_EXPR_LOCATION (exp, gimple_location (stmt));
    3180                 :             : 
    3181                 :             :   /* Must come after copying location.  */
    3182                 :     6572504 :   copy_warning (exp, stmt);
    3183                 :             : 
    3184                 :             :   /* Ensure RTL is created for debug args.  */
    3185                 :    12955206 :   if (decl && DECL_HAS_DEBUG_ARGS_P (decl))
    3186                 :             :     {
    3187                 :       66876 :       vec<tree, va_gc> **debug_args = decl_debug_args_lookup (decl);
    3188                 :       66876 :       unsigned int ix;
    3189                 :       66876 :       tree dtemp;
    3190                 :             : 
    3191                 :       66876 :       if (debug_args)
    3192                 :      145135 :         for (ix = 1; (*debug_args)->iterate (ix, &dtemp); ix += 2)
    3193                 :             :           {
    3194                 :       78259 :             gcc_assert (TREE_CODE (dtemp) == DEBUG_EXPR_DECL);
    3195                 :       78259 :             expand_debug_expr (dtemp);
    3196                 :             :           }
    3197                 :             :     }
    3198                 :             : 
    3199                 :     6572504 :   rtx_insn *before_call = get_last_insn ();
    3200                 :     6572504 :   lhs = gimple_call_lhs (stmt);
    3201                 :     6572504 :   if (lhs)
    3202                 :     2290264 :     expand_assignment (lhs, exp, false);
    3203                 :             :   else
    3204                 :     4282240 :     expand_expr (exp, const0_rtx, VOIDmode, EXPAND_NORMAL);
    3205                 :             : 
    3206                 :             :   /* If the gimple call is an indirect call and has 'nocf_check'
    3207                 :             :      attribute find a generated CALL insn to mark it as no
    3208                 :             :      control-flow verification is needed.  */
    3209                 :     6572504 :   if (gimple_call_nocf_check_p (stmt)
    3210                 :     6572525 :       && !gimple_call_fndecl (stmt))
    3211                 :             :     {
    3212                 :          20 :       rtx_insn *last = get_last_insn ();
    3213                 :          20 :       while (!CALL_P (last)
    3214                 :          34 :              && last != before_call)
    3215                 :          14 :         last = PREV_INSN (last);
    3216                 :             : 
    3217                 :          20 :       if (last != before_call)
    3218                 :          20 :         add_reg_note (last, REG_CALL_NOCF_CHECK, const0_rtx);
    3219                 :             :     }
    3220                 :             : 
    3221                 :     6572504 :   mark_transaction_restart_calls (stmt);
    3222                 :             : }
    3223                 :             : 
    3224                 :             : 
    3225                 :             : /* Generate RTL for an asm statement (explicit assembler code).
    3226                 :             :    STRING is a STRING_CST node containing the assembler code text,
    3227                 :             :    or an ADDR_EXPR containing a STRING_CST.  VOL nonzero means the
    3228                 :             :    insn is volatile; don't optimize it.  */
    3229                 :             : 
    3230                 :             : static void
    3231                 :        2828 : expand_asm_loc (tree string, int vol, location_t locus)
    3232                 :             : {
    3233                 :        2828 :   rtx body;
    3234                 :             : 
    3235                 :        2828 :   body = gen_rtx_ASM_INPUT_loc (VOIDmode,
    3236                 :             :                                 ggc_strdup (TREE_STRING_POINTER (string)),
    3237                 :             :                                 locus);
    3238                 :             : 
    3239                 :        2828 :   MEM_VOLATILE_P (body) = vol;
    3240                 :             : 
    3241                 :             :   /* Non-empty basic ASM implicitly clobbers memory.  */
    3242                 :        2828 :   if (TREE_STRING_LENGTH (string) != 0)
    3243                 :             :     {
    3244                 :         953 :       rtx asm_op, clob;
    3245                 :         953 :       unsigned i, nclobbers;
    3246                 :         953 :       auto_vec<rtx> input_rvec, output_rvec;
    3247                 :         953 :       auto_vec<machine_mode> input_mode;
    3248                 :         953 :       auto_vec<const char *> constraints;
    3249                 :         953 :       auto_vec<rtx> use_rvec;
    3250                 :         953 :       auto_vec<rtx> clobber_rvec;
    3251                 :         953 :       HARD_REG_SET clobbered_regs;
    3252                 :         953 :       CLEAR_HARD_REG_SET (clobbered_regs);
    3253                 :             : 
    3254                 :         953 :       clob = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (VOIDmode));
    3255                 :         953 :       clobber_rvec.safe_push (clob);
    3256                 :             : 
    3257                 :         953 :       if (targetm.md_asm_adjust)
    3258                 :         953 :         targetm.md_asm_adjust (output_rvec, input_rvec, input_mode,
    3259                 :             :                                constraints, use_rvec, clobber_rvec,
    3260                 :             :                                clobbered_regs, locus);
    3261                 :             : 
    3262                 :         953 :       asm_op = body;
    3263                 :         953 :       nclobbers = clobber_rvec.length ();
    3264                 :         953 :       auto nuses = use_rvec.length ();
    3265                 :         953 :       body = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (1 + nuses + nclobbers));
    3266                 :             : 
    3267                 :         953 :       i = 0;
    3268                 :         953 :       XVECEXP (body, 0, i++) = asm_op;
    3269                 :         953 :       for (rtx use : use_rvec)
    3270                 :           0 :         XVECEXP (body, 0, i++) = gen_rtx_USE (VOIDmode, use);
    3271                 :        4765 :       for (rtx clobber : clobber_rvec)
    3272                 :        1906 :         XVECEXP (body, 0, i++) = gen_rtx_CLOBBER (VOIDmode, clobber);
    3273                 :         953 :     }
    3274                 :             : 
    3275                 :        2828 :   emit_insn (body);
    3276                 :        2828 : }
    3277                 :             : 
    3278                 :             : /* Check for overlap between registers marked in CLOBBERED_REGS and
    3279                 :             :    anything inappropriate in T.  Emit error and return the register
    3280                 :             :    variable definition for error, NULL_TREE for ok.  */
    3281                 :             : 
    3282                 :             : static bool
    3283                 :      124378 : tree_conflicts_with_clobbers_p (tree t, HARD_REG_SET *clobbered_regs,
    3284                 :             :                                 location_t loc)
    3285                 :             : {
    3286                 :             :   /* Conflicts between asm-declared register variables and the clobber
    3287                 :             :      list are not allowed.  */
    3288                 :      124378 :   tree overlap = tree_overlaps_hard_reg_set (t, clobbered_regs);
    3289                 :             : 
    3290                 :      124378 :   if (overlap)
    3291                 :             :     {
    3292                 :          21 :       error_at (loc, "%<asm%> specifier for variable %qE conflicts with "
    3293                 :          21 :                 "%<asm%> clobber list", DECL_NAME (overlap));
    3294                 :             : 
    3295                 :             :       /* Reset registerness to stop multiple errors emitted for a single
    3296                 :             :          variable.  */
    3297                 :          21 :       DECL_REGISTER (overlap) = 0;
    3298                 :          21 :       return true;
    3299                 :             :     }
    3300                 :             : 
    3301                 :             :   return false;
    3302                 :             : }
    3303                 :             : 
    3304                 :             : /* Check that the given REGNO spanning NREGS is a valid
    3305                 :             :    asm clobber operand.  Some HW registers cannot be
    3306                 :             :    saved/restored, hence they should not be clobbered by
    3307                 :             :    asm statements.  */
    3308                 :             : static bool
    3309                 :       41535 : asm_clobber_reg_is_valid (int regno, int nregs, const char *regname)
    3310                 :             : {
    3311                 :       41535 :   bool is_valid = true;
    3312                 :       41535 :   HARD_REG_SET regset;
    3313                 :             : 
    3314                 :       41535 :   CLEAR_HARD_REG_SET (regset);
    3315                 :             : 
    3316                 :       41535 :   add_range_to_hard_reg_set (&regset, regno, nregs);
    3317                 :             : 
    3318                 :             :   /* Clobbering the PIC register is an error.  */
    3319                 :       41535 :   if (PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
    3320                 :           0 :       && overlaps_hard_reg_set_p (regset, Pmode, PIC_OFFSET_TABLE_REGNUM))
    3321                 :             :     {
    3322                 :             :       /* ??? Diagnose during gimplification?  */
    3323                 :           0 :       error ("PIC register clobbered by %qs in %<asm%>", regname);
    3324                 :           0 :       is_valid = false;
    3325                 :             :     }
    3326                 :       41535 :   else if (!in_hard_reg_set_p
    3327                 :       41535 :            (accessible_reg_set, reg_raw_mode[regno], regno))
    3328                 :             :     {
    3329                 :             :       /* ??? Diagnose during gimplification?  */
    3330                 :           0 :       error ("the register %qs cannot be clobbered in %<asm%>"
    3331                 :             :              " for the current target", regname);
    3332                 :           0 :       is_valid = false;
    3333                 :             :     }
    3334                 :             : 
    3335                 :             :   /* Clobbering the stack pointer register is deprecated.  GCC expects
    3336                 :             :      the value of the stack pointer after an asm statement to be the same
    3337                 :             :      as it was before, so no asm can validly clobber the stack pointer in
    3338                 :             :      the usual sense.  Adding the stack pointer to the clobber list has
    3339                 :             :      traditionally had some undocumented and somewhat obscure side-effects.  */
    3340                 :       41555 :   if (overlaps_hard_reg_set_p (regset, Pmode, STACK_POINTER_REGNUM))
    3341                 :             :     {
    3342                 :           1 :       crtl->sp_is_clobbered_by_asm = true;
    3343                 :           1 :       if (warning (OPT_Wdeprecated, "listing the stack pointer register"
    3344                 :             :                    " %qs in a clobber list is deprecated", regname))
    3345                 :           1 :         inform (input_location, "the value of the stack pointer after"
    3346                 :             :                 " an %<asm%> statement must be the same as it was before"
    3347                 :             :                 " the statement");
    3348                 :             :     }
    3349                 :             : 
    3350                 :       41535 :   return is_valid;
    3351                 :             : }
    3352                 :             : 
    3353                 :             : /* Generate RTL for an asm statement with arguments.
    3354                 :             :    STRING is the instruction template.
    3355                 :             :    OUTPUTS is a list of output arguments (lvalues); INPUTS a list of inputs.
    3356                 :             :    Each output or input has an expression in the TREE_VALUE and
    3357                 :             :    a tree list in TREE_PURPOSE which in turn contains a constraint
    3358                 :             :    name in TREE_VALUE (or NULL_TREE) and a constraint string
    3359                 :             :    in TREE_PURPOSE.
    3360                 :             :    CLOBBERS is a list of STRING_CST nodes each naming a hard register
    3361                 :             :    that is clobbered by this insn.
    3362                 :             : 
    3363                 :             :    LABELS is a list of labels, and if LABELS is non-NULL, FALLTHRU_BB
    3364                 :             :    should be the fallthru basic block of the asm goto.
    3365                 :             : 
    3366                 :             :    Not all kinds of lvalue that may appear in OUTPUTS can be stored directly.
    3367                 :             :    Some elements of OUTPUTS may be replaced with trees representing temporary
    3368                 :             :    values.  The caller should copy those temporary values to the originally
    3369                 :             :    specified lvalues.
    3370                 :             : 
    3371                 :             :    VOL nonzero means the insn is volatile; don't optimize it.  */
    3372                 :             : 
    3373                 :             : static void
    3374                 :      106906 : expand_asm_stmt (gasm *stmt)
    3375                 :             : {
    3376                 :      106906 :   class save_input_location
    3377                 :             :   {
    3378                 :             :     location_t old;
    3379                 :             : 
    3380                 :             :   public:
    3381                 :      104078 :     explicit save_input_location(location_t where)
    3382                 :      104078 :     {
    3383                 :      104078 :       old = input_location;
    3384                 :      104078 :       input_location = where;
    3385                 :             :     }
    3386                 :             : 
    3387                 :      104078 :     ~save_input_location()
    3388                 :             :     {
    3389                 :      104078 :       input_location = old;
    3390                 :           5 :     }
    3391                 :             :   };
    3392                 :             : 
    3393                 :      106906 :   location_t locus = gimple_location (stmt);
    3394                 :             : 
    3395                 :      106906 :   if (gimple_asm_basic_p (stmt))
    3396                 :             :     {
    3397                 :        2828 :       const char *s = gimple_asm_string (stmt);
    3398                 :        2828 :       tree string = build_string (strlen (s), s);
    3399                 :        2828 :       expand_asm_loc (string, gimple_asm_volatile_p (stmt), locus);
    3400                 :        5661 :       return;
    3401                 :             :     }
    3402                 :             : 
    3403                 :             :   /* There are some legacy diagnostics in here.  */
    3404                 :      104078 :   save_input_location s_i_l(locus);
    3405                 :             : 
    3406                 :      104078 :   unsigned noutputs = gimple_asm_noutputs (stmt);
    3407                 :      104078 :   unsigned ninputs = gimple_asm_ninputs (stmt);
    3408                 :      104078 :   unsigned nlabels = gimple_asm_nlabels (stmt);
    3409                 :      104078 :   unsigned i;
    3410                 :      104078 :   bool error_seen = false;
    3411                 :             : 
    3412                 :             :   /* ??? Diagnose during gimplification?  */
    3413                 :      104078 :   if (ninputs + noutputs + nlabels > MAX_RECOG_OPERANDS)
    3414                 :             :     {
    3415                 :           5 :       error_at (locus, "more than %d operands in %<asm%>", MAX_RECOG_OPERANDS);
    3416                 :           5 :       return;
    3417                 :             :     }
    3418                 :             : 
    3419                 :      104073 :   auto_vec<tree, MAX_RECOG_OPERANDS> output_tvec;
    3420                 :      104073 :   auto_vec<tree, MAX_RECOG_OPERANDS> input_tvec;
    3421                 :      104073 :   auto_vec<const char *, MAX_RECOG_OPERANDS> constraints;
    3422                 :             : 
    3423                 :             :   /* Copy the gimple vectors into new vectors that we can manipulate.  */
    3424                 :             : 
    3425                 :      104073 :   output_tvec.safe_grow (noutputs, true);
    3426                 :      104073 :   input_tvec.safe_grow (ninputs, true);
    3427                 :      104073 :   constraints.safe_grow (noutputs + ninputs, true);
    3428                 :             : 
    3429                 :      176335 :   for (i = 0; i < noutputs; ++i)
    3430                 :             :     {
    3431                 :       72262 :       tree t = gimple_asm_output_op (stmt, i);
    3432                 :       72262 :       output_tvec[i] = TREE_VALUE (t);
    3433                 :       72262 :       constraints[i] = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
    3434                 :             :     }
    3435                 :      156193 :   for (i = 0; i < ninputs; i++)
    3436                 :             :     {
    3437                 :       52120 :       tree t = gimple_asm_input_op (stmt, i);
    3438                 :       52120 :       input_tvec[i] = TREE_VALUE (t);
    3439                 :       52120 :       constraints[i + noutputs]
    3440                 :       52120 :         = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
    3441                 :             :     }
    3442                 :             : 
    3443                 :             :   /* Count the number of meaningful clobbered registers, ignoring what
    3444                 :             :      we would ignore later.  */
    3445                 :      104073 :   auto_vec<rtx> clobber_rvec;
    3446                 :      104073 :   HARD_REG_SET clobbered_regs;
    3447                 :      104073 :   CLEAR_HARD_REG_SET (clobbered_regs);
    3448                 :             : 
    3449                 :      104073 :   if (unsigned n = gimple_asm_nclobbers (stmt))
    3450                 :             :     {
    3451                 :       68553 :       clobber_rvec.reserve (n);
    3452                 :      164659 :       for (i = 0; i < n; i++)
    3453                 :             :         {
    3454                 :       96106 :           tree t = gimple_asm_clobber_op (stmt, i);
    3455                 :       96106 :           const char *regname = TREE_STRING_POINTER (TREE_VALUE (t));
    3456                 :       96106 :           int nregs, j;
    3457                 :             : 
    3458                 :       96106 :           j = decode_reg_name_and_count (regname, &nregs);
    3459                 :       96106 :           if (j < 0)
    3460                 :             :             {
    3461                 :       54571 :               if (j == -2)
    3462                 :             :                 {
    3463                 :             :                   /* ??? Diagnose during gimplification?  */
    3464                 :          15 :                   error_at (locus, "unknown register name %qs in %<asm%>",
    3465                 :             :                             regname);
    3466                 :          15 :                   error_seen = true;
    3467                 :             :                 }
    3468                 :       54556 :               else if (j == -4)
    3469                 :             :                 {
    3470                 :       38817 :                   rtx x = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (VOIDmode));
    3471                 :       38817 :                   clobber_rvec.safe_push (x);
    3472                 :             :                 }
    3473                 :       15739 :               else if (j == -5)
    3474                 :             :                 {
    3475                 :           2 :                   if (targetm.redzone_clobber)
    3476                 :           2 :                     if (rtx x = targetm.redzone_clobber ())
    3477                 :           2 :                       clobber_rvec.safe_push (x);
    3478                 :             :                 }
    3479                 :             :               else
    3480                 :             :                 {
    3481                 :             :                   /* Otherwise we should have -1 == empty string
    3482                 :             :                      or -3 == cc, which is not a register.  */
    3483                 :       15737 :                   gcc_assert (j == -1 || j == -3);
    3484                 :             :                 }
    3485                 :             :             }
    3486                 :             :           else
    3487                 :       83070 :             for (int reg = j; reg < j + nregs; reg++)
    3488                 :             :               {
    3489                 :       41535 :                 if (!asm_clobber_reg_is_valid (reg, nregs, regname))
    3490                 :           0 :                   return;
    3491                 :             : 
    3492                 :       41535 :                 SET_HARD_REG_BIT (clobbered_regs, reg);
    3493                 :       41535 :                 rtx x = gen_rtx_REG (reg_raw_mode[reg], reg);
    3494                 :       41535 :                 clobber_rvec.safe_push (x);
    3495                 :             :               }
    3496                 :             :         }
    3497                 :             :     }
    3498                 :             : 
    3499                 :             :   /* First pass over inputs and outputs checks validity and sets
    3500                 :             :      mark_addressable if needed.  */
    3501                 :             :   /* ??? Diagnose during gimplification?  */
    3502                 :             : 
    3503                 :      176335 :   for (i = 0; i < noutputs; ++i)
    3504                 :             :     {
    3505                 :       72262 :       tree val = output_tvec[i];
    3506                 :       72262 :       tree type = TREE_TYPE (val);
    3507                 :       72262 :       const char *constraint;
    3508                 :       72262 :       bool is_inout;
    3509                 :       72262 :       bool allows_reg;
    3510                 :       72262 :       bool allows_mem;
    3511                 :             : 
    3512                 :             :       /* Try to parse the output constraint.  If that fails, there's
    3513                 :             :          no point in going further.  */
    3514                 :       72262 :       constraint = constraints[i];
    3515                 :       72262 :       if (!parse_output_constraint (&constraint, i, ninputs, noutputs,
    3516                 :             :                                     &allows_mem, &allows_reg, &is_inout,
    3517                 :             :                                     nullptr))
    3518                 :           0 :         return;
    3519                 :             : 
    3520                 :             :       /* If the output is a hard register, verify it doesn't conflict with
    3521                 :             :          any other operand's possible hard register use.  */
    3522                 :       72262 :       if (DECL_P (val)
    3523                 :        7545 :           && REG_P (DECL_RTL (val))
    3524                 :       73213 :           && HARD_REGISTER_P (DECL_RTL (val)))
    3525                 :             :         {
    3526                 :         938 :           unsigned j, output_hregno = REGNO (DECL_RTL (val));
    3527                 :         938 :           bool early_clobber_p = strchr (constraints[i], '&') != NULL;
    3528                 :         938 :           unsigned long match;
    3529                 :             : 
    3530                 :             :           /* Verify the other outputs do not use the same hard register.  */
    3531                 :        1098 :           for (j = i + 1; j < noutputs; ++j)
    3532                 :         160 :             if (DECL_P (output_tvec[j])
    3533                 :         159 :                 && REG_P (DECL_RTL (output_tvec[j]))
    3534                 :         159 :                 && HARD_REGISTER_P (DECL_RTL (output_tvec[j]))
    3535                 :         319 :                 && output_hregno == REGNO (DECL_RTL (output_tvec[j])))
    3536                 :             :               {
    3537                 :           1 :                 error_at (locus, "invalid hard register usage between output "
    3538                 :             :                           "operands");
    3539                 :           1 :                 error_seen = true;
    3540                 :             :               }
    3541                 :             : 
    3542                 :             :           /* Verify matching constraint operands use the same hard register
    3543                 :             :              and that the non-matching constraint operands do not use the same
    3544                 :             :              hard register if the output is an early clobber operand.  */
    3545                 :        1849 :           for (j = 0; j < ninputs; ++j)
    3546                 :         911 :             if (DECL_P (input_tvec[j])
    3547                 :         772 :                 && REG_P (DECL_RTL (input_tvec[j]))
    3548                 :        1683 :                 && HARD_REGISTER_P (DECL_RTL (input_tvec[j])))
    3549                 :             :               {
    3550                 :         772 :                 unsigned input_hregno = REGNO (DECL_RTL (input_tvec[j]));
    3551                 :         772 :                 switch (*constraints[j + noutputs])
    3552                 :             :                   {
    3553                 :         761 :                   case '0':  case '1':  case '2':  case '3':  case '4':
    3554                 :         761 :                   case '5':  case '6':  case '7':  case '8':  case '9':
    3555                 :         761 :                     match = strtoul (constraints[j + noutputs], NULL, 10);
    3556                 :         761 :                     break;
    3557                 :             :                   default:
    3558                 :             :                     match = ULONG_MAX;
    3559                 :             :                     break;
    3560                 :             :                   }
    3561                 :         761 :                 if (i == match
    3562                 :         661 :                     && output_hregno != input_hregno)
    3563                 :             :                   {
    3564                 :           1 :                     error_at (locus, "invalid hard register usage between "
    3565                 :             :                               "output operand and matching constraint operand");
    3566                 :           1 :                     error_seen = true;
    3567                 :             :                   }
    3568                 :         771 :                 else if (early_clobber_p
    3569                 :           4 :                          && i != match
    3570                 :           2 :                          && output_hregno == input_hregno)
    3571                 :             :                   {
    3572                 :           0 :                     error_at (locus, "invalid hard register usage between "
    3573                 :             :                               "earlyclobber operand and input operand");
    3574                 :           0 :                     error_seen = true;
    3575                 :             :                   }
    3576                 :             :               }
    3577                 :             :         }
    3578                 :             : 
    3579                 :       72262 :       if (! allows_reg
    3580                 :       72262 :           && (allows_mem
    3581                 :           0 :               || is_inout
    3582                 :           0 :               || (DECL_P (val)
    3583                 :           0 :                   && REG_P (DECL_RTL (val))
    3584                 :           0 :                   && GET_MODE (DECL_RTL (val)) != TYPE_MODE (type))))
    3585                 :        6276 :         mark_addressable (val);
    3586                 :             :     }
    3587                 :             : 
    3588                 :      156193 :   for (i = 0; i < ninputs; ++i)
    3589                 :             :     {
    3590                 :       52120 :       bool allows_reg, allows_mem;
    3591                 :       52120 :       const char *constraint;
    3592                 :             : 
    3593                 :       52120 :       constraint = constraints[i + noutputs];
    3594                 :       52120 :       if (! parse_input_constraint (&constraint, i, ninputs, noutputs, 0,
    3595                 :       52120 :                                     constraints.address (), &allows_mem,
    3596                 :             :                                     &allows_reg, nullptr))
    3597                 :           0 :         return;
    3598                 :             : 
    3599                 :       52120 :       if (! allows_reg && allows_mem)
    3600                 :        6943 :         mark_addressable (input_tvec[i]);
    3601                 :             :     }
    3602                 :             : 
    3603                 :             :   /* Second pass evaluates arguments.  */
    3604                 :             : 
    3605                 :             :   /* Make sure stack is consistent for asm goto.  */
    3606                 :      104073 :   if (nlabels > 0)
    3607                 :         455 :     do_pending_stack_adjust ();
    3608                 :      104073 :   int old_generating_concat_p = generating_concat_p;
    3609                 :             : 
    3610                 :             :   /* Vector of RTX's of evaluated output operands.  */
    3611                 :      208146 :   auto_vec<rtx, MAX_RECOG_OPERANDS> output_rvec;
    3612                 :      104073 :   auto_vec<int, MAX_RECOG_OPERANDS> inout_opnum;
    3613                 :      104073 :   rtx_insn *after_rtl_seq = NULL, *after_rtl_end = NULL;
    3614                 :             : 
    3615                 :      104073 :   output_rvec.safe_grow (noutputs, true);
    3616                 :             : 
    3617                 :      176335 :   for (i = 0; i < noutputs; ++i)
    3618                 :             :     {
    3619                 :       72262 :       tree val = output_tvec[i];
    3620                 :       72262 :       tree type = TREE_TYPE (val);
    3621                 :       72262 :       bool is_inout, allows_reg, allows_mem, ok;
    3622                 :       72262 :       rtx op;
    3623                 :             : 
    3624                 :       72262 :       ok = parse_output_constraint (&constraints[i], i, ninputs,
    3625                 :             :                                     noutputs, &allows_mem, &allows_reg,
    3626                 :             :                                     &is_inout, nullptr);
    3627                 :       72262 :       gcc_assert (ok);
    3628                 :             : 
    3629                 :             :       /* If an output operand is not a decl or indirect ref and our constraint
    3630                 :             :          allows a register, make a temporary to act as an intermediate.
    3631                 :             :          Make the asm insn write into that, then we will copy it to
    3632                 :             :          the real output operand.  Likewise for promoted variables.  */
    3633                 :             : 
    3634                 :       72262 :       generating_concat_p = 0;
    3635                 :             : 
    3636                 :       72262 :       gcc_assert (TREE_CODE (val) != INDIRECT_REF);
    3637                 :       72262 :       if (((TREE_CODE (val) == MEM_REF
    3638                 :        2599 :             && TREE_CODE (TREE_OPERAND (val, 0)) != ADDR_EXPR)
    3639                 :        2498 :            && allows_mem)
    3640                 :       71868 :           || (DECL_P (val)
    3641                 :        7545 :               && (allows_mem || REG_P (DECL_RTL (val)))
    3642                 :        7788 :               && ! (REG_P (DECL_RTL (val))
    3643                 :         951 :                     && GET_MODE (DECL_RTL (val)) != TYPE_MODE (type)))
    3644                 :       65031 :           || ! allows_reg
    3645                 :       64827 :           || is_inout
    3646                 :       64827 :           || TREE_ADDRESSABLE (type)
    3647                 :      137089 :           || (!tree_fits_poly_int64_p (TYPE_SIZE (type))
    3648                 :           0 :               && !known_size_p (max_int_size_in_bytes (type))))
    3649                 :             :         {
    3650                 :        7435 :           op = expand_expr (val, NULL_RTX, VOIDmode,
    3651                 :             :                             !allows_reg ? EXPAND_MEMORY : EXPAND_WRITE);
    3652                 :        7435 :           if (MEM_P (op))
    3653                 :        6484 :             op = validize_mem (op);
    3654                 :             : 
    3655                 :        7435 :           if (! allows_reg && !MEM_P (op))
    3656                 :             :             {
    3657                 :           0 :               error_at (locus, "output number %d not directly addressable", i);
    3658                 :           0 :               error_seen = true;
    3659                 :             :             }
    3660                 :        7435 :           if ((! allows_mem && MEM_P (op) && GET_MODE (op) != BLKmode)
    3661                 :        7435 :               || GET_CODE (op) == CONCAT)
    3662                 :             :             {
    3663                 :           0 :               rtx old_op = op;
    3664                 :           0 :               op = gen_reg_rtx (GET_MODE (op));
    3665                 :             : 
    3666                 :           0 :               generating_concat_p = old_generating_concat_p;
    3667                 :             : 
    3668                 :           0 :               if (is_inout)
    3669                 :           0 :                 emit_move_insn (op, old_op);
    3670                 :             : 
    3671                 :           0 :               push_to_sequence2 (after_rtl_seq, after_rtl_end);
    3672                 :           0 :               emit_move_insn (old_op, op);
    3673                 :           0 :               after_rtl_seq = get_insns ();
    3674                 :           0 :               after_rtl_end = get_last_insn ();
    3675                 :           0 :               end_sequence ();
    3676                 :             :             }
    3677                 :             :         }
    3678                 :             :       else
    3679                 :             :         {
    3680                 :       64827 :           op = assign_temp (type, 0, 1);
    3681                 :       64827 :           op = validize_mem (op);
    3682                 :       64827 :           if (!MEM_P (op) && TREE_CODE (val) == SSA_NAME)
    3683                 :       61264 :             set_reg_attrs_for_decl_rtl (SSA_NAME_VAR (val), op);
    3684                 :             : 
    3685                 :       64827 :           generating_concat_p = old_generating_concat_p;
    3686                 :             : 
    3687                 :       64827 :           push_to_sequence2 (after_rtl_seq, after_rtl_end);
    3688                 :       64827 :           expand_assignment (val, make_tree (type, op), false);
    3689                 :       64827 :           after_rtl_seq = get_insns ();
    3690                 :       64827 :           after_rtl_end = get_last_insn ();
    3691                 :       64827 :           end_sequence ();
    3692                 :             :         }
    3693                 :       72262 :       output_rvec[i] = op;
    3694                 :             : 
    3695                 :       72262 :       if (is_inout)
    3696                 :           0 :         inout_opnum.safe_push (i);
    3697                 :             :     }
    3698                 :             : 
    3699                 :      104073 :   const char *str = gimple_asm_string (stmt);
    3700                 :      104073 :   if (error_seen)
    3701                 :             :     {
    3702                 :          17 :       ninputs = 0;
    3703                 :          17 :       noutputs = 0;
    3704                 :          17 :       inout_opnum.truncate (0);
    3705                 :          17 :       output_rvec.truncate (0);
    3706                 :          17 :       clobber_rvec.truncate (0);
    3707                 :          17 :       constraints.truncate (0);
    3708                 :          17 :       CLEAR_HARD_REG_SET (clobbered_regs);
    3709                 :             :       str = "";
    3710                 :             :     }
    3711                 :             : 
    3712                 :      208146 :   auto_vec<rtx, MAX_RECOG_OPERANDS> input_rvec;
    3713                 :      104073 :   auto_vec<machine_mode, MAX_RECOG_OPERANDS> input_mode;
    3714                 :             : 
    3715                 :      104073 :   input_rvec.safe_grow (ninputs, true);
    3716                 :      104073 :   input_mode.safe_grow (ninputs, true);
    3717                 :             : 
    3718                 :      104073 :   generating_concat_p = 0;
    3719                 :             : 
    3720                 :      156192 :   for (i = 0; i < ninputs; ++i)
    3721                 :             :     {
    3722                 :       52119 :       tree val = input_tvec[i];
    3723                 :       52119 :       tree type = TREE_TYPE (val);
    3724                 :       52119 :       bool allows_reg, allows_mem, ok;
    3725                 :       52119 :       const char *constraint;
    3726                 :       52119 :       rtx op;
    3727                 :             : 
    3728                 :       52119 :       constraint = constraints[i + noutputs];
    3729                 :       52119 :       ok = parse_input_constraint (&constraint, i, ninputs, noutputs, 0,
    3730                 :       52119 :                                    constraints.address (),
    3731                 :             :                                    &allows_mem, &allows_reg, nullptr);
    3732                 :       52119 :       gcc_assert (ok);
    3733                 :             : 
    3734                 :             :       /* EXPAND_INITIALIZER will not generate code for valid initializer
    3735                 :             :          constants, but will still generate code for other types of operand.
    3736                 :             :          This is the behavior we want for constant constraints.  */
    3737                 :       52119 :       op = expand_expr (val, NULL_RTX, VOIDmode,
    3738                 :             :                         allows_reg ? EXPAND_NORMAL
    3739                 :        8178 :                         : allows_mem ? EXPAND_MEMORY
    3740                 :             :                         : EXPAND_INITIALIZER);
    3741                 :             : 
    3742                 :             :       /* Never pass a CONCAT to an ASM.  */
    3743                 :       52119 :       if (GET_CODE (op) == CONCAT)
    3744                 :           2 :         op = force_reg (GET_MODE (op), op);
    3745                 :       52117 :       else if (MEM_P (op))
    3746                 :       12111 :         op = validize_mem (op);
    3747                 :             : 
    3748                 :       52119 :       if (asm_operand_ok (op, constraint, NULL) <= 0)
    3749                 :             :         {
    3750                 :       24679 :           if (allows_reg && TYPE_MODE (type) != BLKmode)
    3751                 :       24308 :             op = force_reg (TYPE_MODE (type), op);
    3752                 :         371 :           else if (!allows_mem)
    3753                 :          20 :             warning_at (locus, 0, "%<asm%> operand %d probably does not match "
    3754                 :             :                         "constraints", i + noutputs);
    3755                 :         351 :           else if (MEM_P (op))
    3756                 :             :             {
    3757                 :             :               /* We won't recognize either volatile memory or memory
    3758                 :             :                  with a queued address as available a memory_operand
    3759                 :             :                  at this point.  Ignore it: clearly this *is* a memory.  */
    3760                 :             :             }
    3761                 :             :           else
    3762                 :           0 :             gcc_unreachable ();
    3763                 :             :         }
    3764                 :       52119 :       input_rvec[i] = op;
    3765                 :       52119 :       input_mode[i] = TYPE_MODE (type);
    3766                 :             :     }
    3767                 :             : 
    3768                 :             :   /* For in-out operands, copy output rtx to input rtx.  */
    3769                 :      104073 :   unsigned ninout = inout_opnum.length ();
    3770                 :      104073 :   for (i = 0; i < ninout; i++)
    3771                 :             :     {
    3772                 :           0 :       int j = inout_opnum[i];
    3773                 :           0 :       rtx o = output_rvec[j];
    3774                 :             : 
    3775                 :           0 :       input_rvec.safe_push (o);
    3776                 :           0 :       input_mode.safe_push (GET_MODE (o));
    3777                 :             : 
    3778                 :           0 :       char buffer[16];
    3779                 :           0 :       sprintf (buffer, "%d", j);
    3780                 :           0 :       constraints.safe_push (ggc_strdup (buffer));
    3781                 :             :     }
    3782                 :      104073 :   ninputs += ninout;
    3783                 :             : 
    3784                 :             :   /* Sometimes we wish to automatically clobber registers across an asm.
    3785                 :             :      Case in point is when the i386 backend moved from cc0 to a hard reg --
    3786                 :             :      maintaining source-level compatibility means automatically clobbering
    3787                 :             :      the flags register.  */
    3788                 :      104073 :   rtx_insn *after_md_seq = NULL;
    3789                 :      208146 :   auto_vec<rtx> use_rvec;
    3790                 :      104073 :   if (targetm.md_asm_adjust)
    3791                 :      104073 :     after_md_seq
    3792                 :      104073 :         = targetm.md_asm_adjust (output_rvec, input_rvec, input_mode,
    3793                 :             :                                  constraints, use_rvec, clobber_rvec,
    3794                 :             :                                  clobbered_regs, locus);
    3795                 :             : 
    3796                 :             :   /* Do not allow the hook to change the output and input count,
    3797                 :             :      lest it mess up the operand numbering.  */
    3798                 :      208146 :   gcc_assert (output_rvec.length() == noutputs);
    3799                 :      208146 :   gcc_assert (input_rvec.length() == ninputs);
    3800                 :      208146 :   gcc_assert (constraints.length() == noutputs + ninputs);
    3801                 :             : 
    3802                 :             :   /* But it certainly can adjust the uses and clobbers.  */
    3803                 :      104073 :   unsigned nuses = use_rvec.length ();
    3804                 :      104073 :   unsigned nclobbers = clobber_rvec.length ();
    3805                 :             : 
    3806                 :             :   /* Third pass checks for easy conflicts.  */
    3807                 :             :   /* ??? Why are we doing this on trees instead of rtx.  */
    3808                 :             : 
    3809                 :      104073 :   bool clobber_conflict_found = 0;
    3810                 :      176332 :   for (i = 0; i < noutputs; ++i)
    3811                 :       72259 :     if (tree_conflicts_with_clobbers_p (output_tvec[i], &clobbered_regs, locus))
    3812                 :          10 :         clobber_conflict_found = 1;
    3813                 :      156192 :   for (i = 0; i < ninputs - ninout; ++i)
    3814                 :       52119 :     if (tree_conflicts_with_clobbers_p (input_tvec[i], &clobbered_regs, locus))
    3815                 :          11 :         clobber_conflict_found = 1;
    3816                 :             : 
    3817                 :             :   /* Make vectors for the expression-rtx, constraint strings,
    3818                 :             :      and named operands.  */
    3819                 :             : 
    3820                 :      104073 :   rtvec argvec = rtvec_alloc (ninputs);
    3821                 :      104073 :   rtvec constraintvec = rtvec_alloc (ninputs);
    3822                 :      104073 :   rtvec labelvec = rtvec_alloc (nlabels);
    3823                 :             : 
    3824                 :      137101 :   rtx body = gen_rtx_ASM_OPERANDS ((noutputs == 0 ? VOIDmode
    3825                 :             :                                     : GET_MODE (output_rvec[0])),
    3826                 :             :                                    ggc_strdup (str),
    3827                 :             :                                    "", 0, argvec, constraintvec,
    3828                 :             :                                    labelvec, locus);
    3829                 :      104073 :   MEM_VOLATILE_P (body) = gimple_asm_volatile_p (stmt);
    3830                 :             : 
    3831                 :      156192 :   for (i = 0; i < ninputs; ++i)
    3832                 :             :     {
    3833                 :       52119 :       ASM_OPERANDS_INPUT (body, i) = input_rvec[i];
    3834                 :      104238 :       ASM_OPERANDS_INPUT_CONSTRAINT_EXP (body, i)
    3835                 :       52119 :         = gen_rtx_ASM_INPUT_loc (input_mode[i],
    3836                 :             :                                  constraints[i + noutputs],
    3837                 :             :                                  locus);
    3838                 :             :     }
    3839                 :             : 
    3840                 :             :   /* Copy labels to the vector.  */
    3841                 :      104073 :   rtx_code_label *fallthru_label = NULL;
    3842                 :      104073 :   if (nlabels > 0)
    3843                 :             :     {
    3844                 :         455 :       basic_block fallthru_bb = NULL;
    3845                 :         455 :       edge fallthru = find_fallthru_edge (gimple_bb (stmt)->succs);
    3846                 :         455 :       if (fallthru)
    3847                 :         455 :         fallthru_bb = fallthru->dest;
    3848                 :             : 
    3849                 :        1153 :       for (i = 0; i < nlabels; ++i)
    3850                 :             :         {
    3851                 :         698 :           tree label = TREE_VALUE (gimple_asm_label_op (stmt, i));
    3852                 :         698 :           rtx_insn *r;
    3853                 :             :           /* If asm goto has any labels in the fallthru basic block, use
    3854                 :             :              a label that we emit immediately after the asm goto.  Expansion
    3855                 :             :              may insert further instructions into the same basic block after
    3856                 :             :              asm goto and if we don't do this, insertion of instructions on
    3857                 :             :              the fallthru edge might misbehave.  See PR58670.  */
    3858                 :         698 :           if (fallthru_bb && label_to_block (cfun, label) == fallthru_bb)
    3859                 :             :             {
    3860                 :         240 :               if (fallthru_label == NULL_RTX)
    3861                 :         235 :                 fallthru_label = gen_label_rtx ();
    3862                 :             :               r = fallthru_label;
    3863                 :             :             }
    3864                 :             :           else
    3865                 :         458 :             r = label_rtx (label);
    3866                 :         698 :           ASM_OPERANDS_LABEL (body, i) = gen_rtx_LABEL_REF (Pmode, r);
    3867                 :             :         }
    3868                 :             :     }
    3869                 :             : 
    3870                 :             :   /* Now, for each output, construct an rtx
    3871                 :             :      (set OUTPUT (asm_operands INSN OUTPUTCONSTRAINT OUTPUTNUMBER
    3872                 :             :                                ARGVEC CONSTRAINTS OPNAMES))
    3873                 :             :      If there is more than one, put them inside a PARALLEL.  */
    3874                 :             : 
    3875                 :      104073 :   if (noutputs == 0 && nuses == 0 && nclobbers == 0)
    3876                 :             :     {
    3877                 :             :       /* No output operands: put in a raw ASM_OPERANDS rtx.  */
    3878                 :           0 :       if (nlabels > 0)
    3879                 :           0 :         emit_jump_insn (body);
    3880                 :             :       else
    3881                 :           0 :         emit_insn (body);
    3882                 :             :     }
    3883                 :      104073 :   else if (noutputs == 1 && nuses == 0 && nclobbers == 0)
    3884                 :             :     {
    3885                 :          62 :       ASM_OPERANDS_OUTPUT_CONSTRAINT (body) = constraints[0];
    3886                 :          62 :       if (nlabels > 0)
    3887                 :           0 :         emit_jump_insn (gen_rtx_SET (output_rvec[0], body));
    3888                 :             :       else
    3889                 :          62 :         emit_insn (gen_rtx_SET (output_rvec[0], body));
    3890                 :             :     }
    3891                 :             :   else
    3892                 :             :     {
    3893                 :      104011 :       rtx obody = body;
    3894                 :      104011 :       int num = noutputs;
    3895                 :             : 
    3896                 :      104011 :       if (num == 0)
    3897                 :       71045 :         num = 1;
    3898                 :             : 
    3899                 :      104011 :       body = gen_rtx_PARALLEL (VOIDmode,
    3900                 :             :                                rtvec_alloc (num + nuses + nclobbers));
    3901                 :             : 
    3902                 :             :       /* For each output operand, store a SET.  */
    3903                 :      176208 :       for (i = 0; i < noutputs; ++i)
    3904                 :             :         {
    3905                 :       72197 :           rtx src, o = output_rvec[i];
    3906                 :       72197 :           if (i == 0)
    3907                 :             :             {
    3908                 :       32966 :               ASM_OPERANDS_OUTPUT_CONSTRAINT (obody) = constraints[0];
    3909                 :       32966 :               src = obody;
    3910                 :             :             }
    3911                 :             :           else
    3912                 :             :             {
    3913                 :       39231 :               src = gen_rtx_ASM_OPERANDS (GET_MODE (o),
    3914                 :             :                                           ASM_OPERANDS_TEMPLATE (obody),
    3915                 :             :                                           constraints[i], i, argvec,
    3916                 :             :                                           constraintvec, labelvec, locus);
    3917                 :       39231 :               MEM_VOLATILE_P (src) = gimple_asm_volatile_p (stmt);
    3918                 :             :             }
    3919                 :       72197 :           XVECEXP (body, 0, i) = gen_rtx_SET (o, src);
    3920                 :             :         }
    3921                 :             : 
    3922                 :             :       /* If there are no outputs (but there are some clobbers)
    3923                 :             :          store the bare ASM_OPERANDS into the PARALLEL.  */
    3924                 :      104011 :       if (i == 0)
    3925                 :       71045 :         XVECEXP (body, 0, i++) = obody;
    3926                 :             : 
    3927                 :             :       /* Add the uses specified by the target hook.  No checking should
    3928                 :             :          be needed since this doesn't come directly from user code.  */
    3929                 :      104011 :       for (rtx use : use_rvec)
    3930                 :           0 :         XVECEXP (body, 0, i++) = gen_rtx_USE (VOIDmode, use);
    3931                 :             : 
    3932                 :             :       /* Store (clobber REG) for each clobbered register specified.  */
    3933                 :      288364 :       for (unsigned j = 0; j < nclobbers; ++j)
    3934                 :             :         {
    3935                 :      184353 :           rtx clobbered_reg = clobber_rvec[j];
    3936                 :             : 
    3937                 :             :           /* Do sanity check for overlap between clobbers and respectively
    3938                 :             :              input and outputs that hasn't been handled.  Such overlap
    3939                 :             :              should have been detected and reported above.  */
    3940                 :      184353 :           if (!clobber_conflict_found && REG_P (clobbered_reg))
    3941                 :             :             {
    3942                 :             :               /* We test the old body (obody) contents to avoid
    3943                 :             :                  tripping over the under-construction body.  */
    3944                 :      218654 :               for (unsigned k = 0; k < noutputs; ++k)
    3945                 :       73150 :                 if (reg_overlap_mentioned_p (clobbered_reg, output_rvec[k]))
    3946                 :           0 :                   internal_error ("%<asm%> clobber conflict with "
    3947                 :             :                                   "output operand");
    3948                 :             : 
    3949                 :      200394 :               for (unsigned k = 0; k < ninputs - ninout; ++k)
    3950                 :       54890 :                 if (reg_overlap_mentioned_p (clobbered_reg, input_rvec[k]))
    3951                 :           0 :                   internal_error ("%<asm%> clobber conflict with "
    3952                 :             :                                   "input operand");
    3953                 :             :             }
    3954                 :             : 
    3955                 :      184353 :           XVECEXP (body, 0, i++) = gen_rtx_CLOBBER (VOIDmode, clobbered_reg);
    3956                 :             :         }
    3957                 :             : 
    3958                 :      104011 :       if (nlabels > 0)
    3959                 :         455 :         emit_jump_insn (body);
    3960                 :             :       else
    3961                 :      103556 :         emit_insn (body);
    3962                 :             :     }
    3963                 :             : 
    3964                 :      104073 :   generating_concat_p = old_generating_concat_p;
    3965                 :             : 
    3966                 :      104073 :   if (fallthru_label)
    3967                 :         235 :     emit_label (fallthru_label);
    3968                 :             : 
    3969                 :      104073 :   if (after_md_seq)
    3970                 :          71 :     emit_insn (after_md_seq);
    3971                 :      104073 :   if (after_rtl_seq)
    3972                 :             :     {
    3973                 :       26280 :       if (nlabels == 0)
    3974                 :       26155 :         emit_insn (after_rtl_seq);
    3975                 :             :       else
    3976                 :             :         {
    3977                 :         125 :           edge e;
    3978                 :         125 :           edge_iterator ei;
    3979                 :         125 :           unsigned int cnt = EDGE_COUNT (gimple_bb (stmt)->succs);
    3980                 :             : 
    3981                 :         458 :           FOR_EACH_EDGE (e, ei, gimple_bb (stmt)->succs)
    3982                 :             :             {
    3983                 :         333 :               rtx_insn *copy;
    3984                 :         333 :               if (--cnt == 0)
    3985                 :             :                 copy = after_rtl_seq;
    3986                 :             :               else
    3987                 :             :                 {
    3988                 :         208 :                   start_sequence ();
    3989                 :         208 :                   duplicate_insn_chain (after_rtl_seq, after_rtl_end,
    3990                 :             :                                         NULL, NULL);
    3991                 :         208 :                   copy = end_sequence ();
    3992                 :             :                 }
    3993                 :         333 :               prepend_insn_to_edge (copy, e);
    3994                 :             :             }
    3995                 :             :         }
    3996                 :             :     }
    3997                 :             : 
    3998                 :      104073 :   free_temp_slots ();
    3999                 :      104073 :   crtl->has_asm_statement = 1;
    4000                 :      104078 : }
    4001                 :             : 
    4002                 :             : /* Emit code to jump to the address
    4003                 :             :    specified by the pointer expression EXP.  */
    4004                 :             : 
    4005                 :             : static void
    4006                 :         394 : expand_computed_goto (tree exp)
    4007                 :             : {
    4008                 :         394 :   rtx x = expand_normal (exp);
    4009                 :             : 
    4010                 :         394 :   do_pending_stack_adjust ();
    4011                 :         394 :   emit_indirect_jump (x);
    4012                 :         394 : }
    4013                 :             : 
    4014                 :             : /* Generate RTL code for a `goto' statement with target label LABEL.
    4015                 :             :    LABEL should be a LABEL_DECL tree node that was or will later be
    4016                 :             :    defined with `expand_label'.  */
    4017                 :             : 
    4018                 :             : static void
    4019                 :           0 : expand_goto (tree label)
    4020                 :             : {
    4021                 :           0 :   if (flag_checking)
    4022                 :             :     {
    4023                 :             :       /* Check for a nonlocal goto to a containing function.  Should have
    4024                 :             :          gotten translated to __builtin_nonlocal_goto.  */
    4025                 :           0 :       tree context = decl_function_context (label);
    4026                 :           0 :       gcc_assert (!context || context == current_function_decl);
    4027                 :             :     }
    4028                 :             : 
    4029                 :           0 :   emit_jump (jump_target_rtx (label));
    4030                 :           0 : }
    4031                 :             : 
    4032                 :             : /* Output a return with no value.  */
    4033                 :             : 
    4034                 :             : static void
    4035                 :      819298 : expand_null_return_1 (void)
    4036                 :             : {
    4037                 :      819298 :   clear_pending_stack_adjust ();
    4038                 :      819298 :   do_pending_stack_adjust ();
    4039                 :      819298 :   emit_jump (return_label);
    4040                 :      819298 : }
    4041                 :             : 
    4042                 :             : /* Generate RTL to return from the current function, with no value.
    4043                 :             :    (That is, we do not do anything about returning any value.)  */
    4044                 :             : 
    4045                 :             : void
    4046                 :       73449 : expand_null_return (void)
    4047                 :             : {
    4048                 :             :   /* If this function was declared to return a value, but we
    4049                 :             :      didn't, clobber the return registers so that they are not
    4050                 :             :      propagated live to the rest of the function.  */
    4051                 :       73449 :   clobber_return_register ();
    4052                 :             : 
    4053                 :       73449 :   expand_null_return_1 ();
    4054                 :       73449 : }
    4055                 :             : 
    4056                 :             : /* Generate RTL to return from the current function, with value VAL.  */
    4057                 :             : 
    4058                 :             : static void
    4059                 :      745849 : expand_value_return (rtx val)
    4060                 :             : {
    4061                 :             :   /* Copy the value to the return location unless it's already there.  */
    4062                 :             : 
    4063                 :      745849 :   tree decl = DECL_RESULT (current_function_decl);
    4064                 :      745849 :   rtx return_reg = DECL_RTL (decl);
    4065                 :      745849 :   if (return_reg != val)
    4066                 :             :     {
    4067                 :      428605 :       tree funtype = TREE_TYPE (current_function_decl);
    4068                 :      428605 :       tree type = TREE_TYPE (decl);
    4069                 :      428605 :       int unsignedp = TYPE_UNSIGNED (type);
    4070                 :      428605 :       machine_mode old_mode = DECL_MODE (decl);
    4071                 :      428605 :       machine_mode mode;
    4072                 :      428605 :       if (DECL_BY_REFERENCE (decl))
    4073                 :           0 :         mode = promote_function_mode (type, old_mode, &unsignedp, funtype, 2);
    4074                 :             :       else
    4075                 :      428605 :         mode = promote_function_mode (type, old_mode, &unsignedp, funtype, 1);
    4076                 :             : 
    4077                 :      428605 :       if (mode != old_mode)
    4078                 :             :         {
    4079                 :             :           /* Some ABIs require scalar floating point modes to be returned
    4080                 :             :              in a wider scalar integer mode.  We need to explicitly
    4081                 :             :              reinterpret to an integer mode of the correct precision
    4082                 :             :              before extending to the desired result.  */
    4083                 :           8 :           if (SCALAR_INT_MODE_P (mode)
    4084                 :           8 :               && SCALAR_FLOAT_MODE_P (old_mode)
    4085                 :           8 :               && known_gt (GET_MODE_SIZE (mode), GET_MODE_SIZE (old_mode)))
    4086                 :           0 :             val = convert_float_to_wider_int (mode, old_mode, val);
    4087                 :             :           else
    4088                 :           8 :             val = convert_modes (mode, old_mode, val, unsignedp);
    4089                 :             :         }
    4090                 :             : 
    4091                 :      428605 :       if (GET_CODE (return_reg) == PARALLEL)
    4092                 :        2915 :         emit_group_load (return_reg, val, type, int_size_in_bytes (type));
    4093                 :             :       else
    4094                 :      425690 :         emit_move_insn (return_reg, val);
    4095                 :             :     }
    4096                 :             : 
    4097                 :      745849 :   expand_null_return_1 ();
    4098                 :      745849 : }
    4099                 :             : 
    4100                 :             : /* Generate RTL to evaluate the expression RETVAL and return it
    4101                 :             :    from the current function.  */
    4102                 :             : 
    4103                 :             : static void
    4104                 :      748040 : expand_return (tree retval)
    4105                 :             : {
    4106                 :      748040 :   rtx result_rtl;
    4107                 :      748040 :   rtx val = 0;
    4108                 :      748040 :   tree retval_rhs;
    4109                 :             : 
    4110                 :             :   /* If function wants no value, give it none.  */
    4111                 :      748040 :   if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (current_function_decl))))
    4112                 :             :     {
    4113                 :           0 :       expand_normal (retval);
    4114                 :           0 :       expand_null_return ();
    4115                 :           0 :       return;
    4116                 :             :     }
    4117                 :             : 
    4118                 :      748040 :   if (retval == error_mark_node)
    4119                 :             :     {
    4120                 :             :       /* Treat this like a return of no value from a function that
    4121                 :             :          returns a value.  */
    4122                 :           0 :       expand_null_return ();
    4123                 :           0 :       return;
    4124                 :             :     }
    4125                 :      748040 :   else if ((TREE_CODE (retval) == MODIFY_EXPR
    4126                 :      748040 :             || TREE_CODE (retval) == INIT_EXPR)
    4127                 :      748040 :            && TREE_CODE (TREE_OPERAND (retval, 0)) == RESULT_DECL)
    4128                 :      685696 :     retval_rhs = TREE_OPERAND (retval, 1);
    4129                 :             :   else
    4130                 :             :     retval_rhs = retval;
    4131                 :             : 
    4132                 :      748040 :   result_rtl = DECL_RTL (DECL_RESULT (current_function_decl));
    4133                 :             : 
    4134                 :             :   /* If we are returning the RESULT_DECL, then the value has already
    4135                 :             :      been stored into it, so we don't have to do anything special.  */
    4136                 :      748040 :   if (TREE_CODE (retval_rhs) == RESULT_DECL)
    4137                 :       62344 :     expand_value_return (result_rtl);
    4138                 :             : 
    4139                 :             :   /* If the result is an aggregate that is being returned in one (or more)
    4140                 :             :      registers, load the registers here.  */
    4141                 :             : 
    4142                 :      685696 :   else if (retval_rhs != 0
    4143                 :      685696 :            && TYPE_MODE (TREE_TYPE (retval_rhs)) == BLKmode
    4144                 :        4864 :            && REG_P (result_rtl))
    4145                 :             :     {
    4146                 :        3415 :       val = copy_blkmode_to_reg (GET_MODE (result_rtl), retval_rhs);
    4147                 :        3415 :       if (val)
    4148                 :             :         {
    4149                 :             :           /* Use the mode of the result value on the return register.  */
    4150                 :        1224 :           PUT_MODE (result_rtl, GET_MODE (val));
    4151                 :        1224 :           expand_value_return (val);
    4152                 :             :         }
    4153                 :             :       else
    4154                 :        2191 :         expand_null_return ();
    4155                 :             :     }
    4156                 :      682281 :   else if (retval_rhs != 0
    4157                 :      682281 :            && !VOID_TYPE_P (TREE_TYPE (retval_rhs))
    4158                 :      682281 :            && (REG_P (result_rtl)
    4159                 :        5581 :                || (GET_CODE (result_rtl) == PARALLEL)))
    4160                 :             :     {
    4161                 :             :       /* Compute the return value into a temporary (usually a pseudo reg).  */
    4162                 :      679615 :       val
    4163                 :      679615 :         = assign_temp (TREE_TYPE (DECL_RESULT (current_function_decl)), 0, 1);
    4164                 :      679615 :       val = expand_expr (retval_rhs, val, GET_MODE (val), EXPAND_NORMAL);
    4165                 :      679615 :       val = force_not_mem (val);
    4166                 :      679615 :       expand_value_return (val);
    4167                 :             :     }
    4168                 :             :   else
    4169                 :             :     {
    4170                 :             :       /* No hard reg used; calculate value into hard return reg.  */
    4171                 :        2666 :       expand_expr (retval, const0_rtx, VOIDmode, EXPAND_NORMAL);
    4172                 :        2666 :       expand_value_return (result_rtl);
    4173                 :             :     }
    4174                 :             : }
    4175                 :             : 
    4176                 :             : /* Expand a clobber of LHS.  If LHS is stored it in a multi-part
    4177                 :             :    register, tell the rtl optimizers that its value is no longer
    4178                 :             :    needed.  */
    4179                 :             : 
    4180                 :             : static void
    4181                 :     1509638 : expand_clobber (tree lhs)
    4182                 :             : {
    4183                 :     1509638 :   if (DECL_P (lhs))
    4184                 :             :     {
    4185                 :     1231201 :       rtx decl_rtl = DECL_RTL_IF_SET (lhs);
    4186                 :     1231157 :       if (decl_rtl && REG_P (decl_rtl))
    4187                 :             :         {
    4188                 :      168866 :           machine_mode decl_mode = GET_MODE (decl_rtl);
    4189                 :      337732 :           if (maybe_gt (GET_MODE_SIZE (decl_mode),
    4190                 :             :                         REGMODE_NATURAL_SIZE (decl_mode)))
    4191                 :      133933 :             emit_clobber (decl_rtl);
    4192                 :             :         }
    4193                 :             :     }
    4194                 :     1509638 : }
    4195                 :             : 
    4196                 :             : /* A subroutine of expand_gimple_stmt, expanding one gimple statement
    4197                 :             :    STMT that doesn't require special handling for outgoing edges.  That
    4198                 :             :    is no tailcalls and no GIMPLE_COND.  */
    4199                 :             : 
    4200                 :             : static void
    4201                 :    31392123 : expand_gimple_stmt_1 (gimple *stmt)
    4202                 :             : {
    4203                 :    31392123 :   tree op0;
    4204                 :             : 
    4205                 :    31392123 :   set_curr_insn_location (gimple_location (stmt));
    4206                 :             : 
    4207                 :    31392123 :   switch (gimple_code (stmt))
    4208                 :             :     {
    4209                 :         394 :     case GIMPLE_GOTO:
    4210                 :         394 :       op0 = gimple_goto_dest (stmt);
    4211                 :         394 :       if (TREE_CODE (op0) == LABEL_DECL)
    4212                 :           0 :         expand_goto (op0);
    4213                 :             :       else
    4214                 :         394 :         expand_computed_goto (op0);
    4215                 :             :       break;
    4216                 :      631111 :     case GIMPLE_LABEL:
    4217                 :      631111 :       expand_label (gimple_label_label (as_a <glabel *> (stmt)));
    4218                 :      631111 :       break;
    4219                 :             :     case GIMPLE_NOP:
    4220                 :             :     case GIMPLE_PREDICT:
    4221                 :             :       break;
    4222                 :        9267 :     case GIMPLE_SWITCH:
    4223                 :        9267 :       {
    4224                 :        9267 :         gswitch *swtch = as_a <gswitch *> (stmt);
    4225                 :        9267 :         if (gimple_switch_num_labels (swtch) == 1)
    4226                 :           0 :           expand_goto (CASE_LABEL (gimple_switch_default_label (swtch)));
    4227                 :             :         else
    4228                 :        9267 :           expand_case (swtch);
    4229                 :             :       }
    4230                 :             :       break;
    4231                 :      106906 :     case GIMPLE_ASM:
    4232                 :      106906 :       expand_asm_stmt (as_a <gasm *> (stmt));
    4233                 :      106906 :       break;
    4234                 :     6764654 :     case GIMPLE_CALL:
    4235                 :     6764654 :       expand_call_stmt (as_a <gcall *> (stmt));
    4236                 :     6764654 :       break;
    4237                 :             : 
    4238                 :      819298 :     case GIMPLE_RETURN:
    4239                 :      819298 :       {
    4240                 :      819298 :         op0 = gimple_return_retval (as_a <greturn *> (stmt));
    4241                 :             : 
    4242                 :             :         /* If a return doesn't have a location, it very likely represents
    4243                 :             :            multiple user returns so we cannot let it inherit the location
    4244                 :             :            of the last statement of the previous basic block in RTL.  */
    4245                 :      819298 :         if (!gimple_has_location (stmt))
    4246                 :      218351 :           set_curr_insn_location (cfun->function_end_locus);
    4247                 :             : 
    4248                 :      819298 :         if (op0 && op0 != error_mark_node)
    4249                 :             :           {
    4250                 :      748040 :             tree result = DECL_RESULT (current_function_decl);
    4251                 :             : 
    4252                 :             :             /* If we are not returning the current function's RESULT_DECL,
    4253                 :             :                build an assignment to it.  */
    4254                 :      748040 :             if (op0 != result)
    4255                 :             :               {
    4256                 :             :                 /* I believe that a function's RESULT_DECL is unique.  */
    4257                 :      685696 :                 gcc_assert (TREE_CODE (op0) != RESULT_DECL);
    4258                 :             : 
    4259                 :             :                 /* ??? We'd like to use simply expand_assignment here,
    4260                 :             :                    but this fails if the value is of BLKmode but the return
    4261                 :             :                    decl is a register.  expand_return has special handling
    4262                 :             :                    for this combination, which eventually should move
    4263                 :             :                    to common code.  See comments there.  Until then, let's
    4264                 :             :                    build a modify expression :-/  */
    4265                 :      685696 :                 op0 = build2 (MODIFY_EXPR, TREE_TYPE (result),
    4266                 :             :                               result, op0);
    4267                 :             :               }
    4268                 :             :           }
    4269                 :             : 
    4270                 :      748040 :         if (!op0)
    4271                 :       71258 :           expand_null_return ();
    4272                 :             :         else
    4273                 :      748040 :           expand_return (op0);
    4274                 :             :       }
    4275                 :             :       break;
    4276                 :             : 
    4277                 :    23015827 :     case GIMPLE_ASSIGN:
    4278                 :    23015827 :       {
    4279                 :    23015827 :         gassign *assign_stmt = as_a <gassign *> (stmt);
    4280                 :    23015827 :         tree lhs = gimple_assign_lhs (assign_stmt);
    4281                 :             : 
    4282                 :             :         /* Tree expand used to fiddle with |= and &= of two bitfield
    4283                 :             :            COMPONENT_REFs here.  This can't happen with gimple, the LHS
    4284                 :             :            of binary assigns must be a gimple reg.  */
    4285                 :             : 
    4286                 :    23015827 :         if (TREE_CODE (lhs) != SSA_NAME
    4287                 :    36523885 :             || gimple_assign_rhs_class (assign_stmt) == GIMPLE_SINGLE_RHS)
    4288                 :             :           {
    4289                 :    17207491 :             tree rhs = gimple_assign_rhs1 (assign_stmt);
    4290                 :    17207491 :             gcc_assert (gimple_assign_rhs_class (assign_stmt)
    4291                 :             :                         == GIMPLE_SINGLE_RHS);
    4292                 :    32868597 :             if (gimple_has_location (stmt) && CAN_HAVE_LOCATION_P (rhs)
    4293                 :             :                 /* Do not put locations on possibly shared trees.  */
    4294                 :    23123930 :                 && !is_gimple_min_invariant (rhs))
    4295                 :     4796519 :               SET_EXPR_LOCATION (rhs, gimple_location (stmt));
    4296                 :    17207491 :             if (TREE_CLOBBER_P (rhs))
    4297                 :             :               /* This is a clobber to mark the going out of scope for
    4298                 :             :                  this LHS.  */
    4299                 :     1509638 :               expand_clobber (lhs);
    4300                 :             :             else
    4301                 :    15697853 :               expand_assignment (lhs, rhs,
    4302                 :    15697853 :                                  gimple_assign_nontemporal_move_p (
    4303                 :             :                                    assign_stmt));
    4304                 :             :           }
    4305                 :             :         else
    4306                 :             :           {
    4307                 :     5808336 :             rtx target, temp;
    4308                 :     5808336 :             gcc_assert (!gimple_assign_nontemporal_move_p (assign_stmt));
    4309                 :     5808336 :             bool promoted = false;
    4310                 :             : 
    4311                 :     5808336 :             target = expand_expr (lhs, NULL_RTX, VOIDmode, EXPAND_WRITE);
    4312                 :     5808336 :             if (GET_CODE (target) == SUBREG && SUBREG_PROMOTED_VAR_P (target))
    4313                 :             :               promoted = true;
    4314                 :             : 
    4315                 :             :            /* If we store into a promoted register, don't directly
    4316                 :             :               expand to target.  */
    4317                 :             :             temp = promoted ? NULL_RTX : target;
    4318                 :    11616672 :             temp = expand_expr_real_gassign (assign_stmt, temp,
    4319                 :     5808336 :                                              GET_MODE (target), EXPAND_NORMAL);
    4320                 :             : 
    4321                 :     5808336 :             if (temp == target)
    4322                 :             :               ;
    4323                 :      784768 :             else if (promoted)
    4324                 :             :               {
    4325                 :           3 :                 int unsignedp = SUBREG_PROMOTED_SIGN (target);
    4326                 :             :                 /* If TEMP is a VOIDmode constant, use convert_modes to make
    4327                 :             :                    sure that we properly convert it.  */
    4328                 :           3 :                 if (CONSTANT_P (temp) && GET_MODE (temp) == VOIDmode)
    4329                 :             :                   {
    4330                 :           0 :                     temp = convert_modes (GET_MODE (target),
    4331                 :           0 :                                           TYPE_MODE (TREE_TYPE (lhs)),
    4332                 :             :                                           temp, unsignedp);
    4333                 :           0 :                     temp = convert_modes (GET_MODE (SUBREG_REG (target)),
    4334                 :           0 :                                           GET_MODE (target), temp, unsignedp);
    4335                 :             :                   }
    4336                 :             : 
    4337                 :           3 :                 convert_move (SUBREG_REG (target), temp, unsignedp);
    4338                 :             :               }
    4339                 :             :             else
    4340                 :             :               {
    4341                 :      784765 :                 temp = force_operand (temp, target);
    4342                 :      784765 :                 if (temp == target)
    4343                 :             :                   ;
    4344                 :      784765 :                 else if (GET_MODE (target) != BLKmode)
    4345                 :      784764 :                   emit_move_insn (target, temp);
    4346                 :             :                 else
    4347                 :           1 :                   emit_block_move (target, temp, expr_size (lhs),
    4348                 :             :                                    BLOCK_OP_NORMAL);
    4349                 :             :               }
    4350                 :             :           }
    4351                 :             :       }
    4352                 :             :       break;
    4353                 :             : 
    4354                 :           0 :     default:
    4355                 :           0 :       gcc_unreachable ();
    4356                 :             :     }
    4357                 :    31392123 : }
    4358                 :             : 
    4359                 :             : /* Expand one gimple statement STMT and return the last RTL instruction
    4360                 :             :    before any of the newly generated ones.
    4361                 :             : 
    4362                 :             :    In addition to generating the necessary RTL instructions this also
    4363                 :             :    sets REG_EH_REGION notes if necessary and sets the current source
    4364                 :             :    location for diagnostics.  */
    4365                 :             : 
    4366                 :             : static rtx_insn *
    4367                 :    31392123 : expand_gimple_stmt (gimple *stmt)
    4368                 :             : {
    4369                 :    31392123 :   location_t saved_location = input_location;
    4370                 :    31392123 :   rtx_insn *last = get_last_insn ();
    4371                 :    31392123 :   int lp_nr;
    4372                 :             : 
    4373                 :    31392123 :   gcc_assert (cfun);
    4374                 :             : 
    4375                 :             :   /* We need to save and restore the current source location so that errors
    4376                 :             :      discovered during expansion are emitted with the right location.  But
    4377                 :             :      it would be better if the diagnostic routines used the source location
    4378                 :             :      embedded in the tree nodes rather than globals.  */
    4379                 :    31392123 :   if (gimple_has_location (stmt))
    4380                 :    27536426 :     input_location = gimple_location (stmt);
    4381                 :             : 
    4382                 :    31392123 :   expand_gimple_stmt_1 (stmt);
    4383                 :             : 
    4384                 :             :   /* Free any temporaries used to evaluate this statement.  */
    4385                 :    31392123 :   free_temp_slots ();
    4386                 :             : 
    4387                 :    31392123 :   input_location = saved_location;
    4388                 :             : 
    4389                 :             :   /* Mark all insns that may trap.  */
    4390                 :    31392123 :   lp_nr = lookup_stmt_eh_lp (stmt);
    4391                 :    31392123 :   if (lp_nr)
    4392                 :             :     {
    4393                 :      722714 :       rtx_insn *insn;
    4394                 :     4220358 :       for (insn = next_real_insn (last); insn;
    4395                 :     3497644 :            insn = next_real_insn (insn))
    4396                 :             :         {
    4397                 :     3497644 :           if (! find_reg_note (insn, REG_EH_REGION, NULL_RTX)
    4398                 :             :               /* If we want exceptions for non-call insns, any
    4399                 :             :                  may_trap_p instruction may throw.  */
    4400                 :     3497579 :               && GET_CODE (PATTERN (insn)) != CLOBBER
    4401                 :     3497509 :               && GET_CODE (PATTERN (insn)) != USE
    4402                 :     6995153 :               && insn_could_throw_p (insn))
    4403                 :      781632 :             make_reg_eh_region_note (insn, 0, lp_nr);
    4404                 :             :         }
    4405                 :             :     }
    4406                 :             : 
    4407                 :    31392123 :   return last;
    4408                 :             : }
    4409                 :             : 
    4410                 :             : /* A subroutine of expand_gimple_basic_block.  Expand one GIMPLE_CALL
    4411                 :             :    that has CALL_EXPR_TAILCALL set.  Returns non-null if we actually
    4412                 :             :    generated a tail call (something that might be denied by the ABI
    4413                 :             :    rules governing the call; see calls.cc).
    4414                 :             : 
    4415                 :             :    Sets CAN_FALLTHRU if we generated a *conditional* tail call, and
    4416                 :             :    can still reach the rest of BB.  The case here is __builtin_sqrt,
    4417                 :             :    where the NaN result goes through the external function (with a
    4418                 :             :    tailcall) and the normal result happens via a sqrt instruction.  */
    4419                 :             : 
    4420                 :             : static basic_block
    4421                 :      173038 : expand_gimple_tailcall (basic_block bb, gcall *stmt, bool *can_fallthru,
    4422                 :             :                         rtx_insn *asan_epilog_seq)
    4423                 :             : {
    4424                 :      173038 :   rtx_insn *last2, *last, *first = get_last_insn ();
    4425                 :      173038 :   edge e;
    4426                 :      173038 :   edge_iterator ei;
    4427                 :      173038 :   profile_probability probability;
    4428                 :             : 
    4429                 :      173038 :   last2 = last = expand_gimple_stmt (stmt);
    4430                 :             : 
    4431                 :      742191 :   for (last = NEXT_INSN (last); last; last = NEXT_INSN (last))
    4432                 :      693121 :     if (CALL_P (last) && SIBLING_CALL_P (last))
    4433                 :      123968 :       goto found;
    4434                 :             : 
    4435                 :       49070 :   maybe_dump_rtl_for_gimple_stmt (stmt, last2);
    4436                 :             : 
    4437                 :       49070 :   *can_fallthru = true;
    4438                 :       49070 :   return NULL;
    4439                 :             : 
    4440                 :      123968 :  found:
    4441                 :             : 
    4442                 :      123968 :   if (asan_epilog_seq)
    4443                 :             :     {
    4444                 :             :       /* We need to emit a copy of the asan_epilog_seq before
    4445                 :             :          the insns emitted by expand_gimple_stmt above.  The sequence
    4446                 :             :          can contain labels, which need to be remapped.  */
    4447                 :         117 :       hash_map<rtx, rtx> label_map;
    4448                 :         117 :       start_sequence ();
    4449                 :         117 :       emit_note (NOTE_INSN_DELETED);
    4450                 :        1650 :       for (rtx_insn *insn = asan_epilog_seq; insn; insn = NEXT_INSN (insn))
    4451                 :        1533 :         switch (GET_CODE (insn))
    4452                 :             :           {
    4453                 :        1182 :           case INSN:
    4454                 :        1182 :           case CALL_INSN:
    4455                 :        1182 :           case JUMP_INSN:
    4456                 :        1182 :             emit_copy_of_insn_after (insn, get_last_insn ());
    4457                 :        1182 :             break;
    4458                 :         234 :           case CODE_LABEL:
    4459                 :         234 :             label_map.put ((rtx) insn, (rtx) emit_label (gen_label_rtx ()));
    4460                 :         234 :             break;
    4461                 :         117 :           case BARRIER:
    4462                 :         117 :             emit_barrier ();
    4463                 :         117 :             break;
    4464                 :           0 :           default:
    4465                 :           0 :             gcc_unreachable ();
    4466                 :             :           }
    4467                 :        1767 :       for (rtx_insn *insn = get_insns (); insn; insn = NEXT_INSN (insn))
    4468                 :        1650 :         if (JUMP_P (insn))
    4469                 :             :           {
    4470                 :         234 :             subrtx_ptr_iterator::array_type array;
    4471                 :        1521 :             FOR_EACH_SUBRTX_PTR (iter, array, &PATTERN (insn), ALL)
    4472                 :             :               {
    4473                 :        1287 :                 rtx *loc = *iter;
    4474                 :        1287 :                 if (LABEL_REF_P (*loc))
    4475                 :             :                   {
    4476                 :         234 :                     rtx *lab = label_map.get ((rtx) label_ref_label (*loc));
    4477                 :         234 :                     gcc_assert (lab);
    4478                 :         234 :                     set_label_ref_label (*loc, as_a <rtx_insn *> (*lab));
    4479                 :             :                   }
    4480                 :             :               }
    4481                 :         234 :             if (JUMP_LABEL (insn))
    4482                 :             :               {
    4483                 :         234 :                 rtx *lab = label_map.get (JUMP_LABEL (insn));
    4484                 :         234 :                 gcc_assert (lab);
    4485                 :         234 :                 JUMP_LABEL (insn) = *lab;
    4486                 :             :               }
    4487                 :         234 :           }
    4488                 :         117 :       asan_epilog_seq = NEXT_INSN (get_insns ());
    4489                 :         117 :       end_sequence ();
    4490                 :         117 :       emit_insn_before (asan_epilog_seq, NEXT_INSN (first));
    4491                 :         117 :     }
    4492                 :             : 
    4493                 :             :   /* ??? Wouldn't it be better to just reset any pending stack adjust?
    4494                 :             :      Any instructions emitted here are about to be deleted.  */
    4495                 :      123968 :   do_pending_stack_adjust ();
    4496                 :             : 
    4497                 :             :   /* Remove any non-eh, non-abnormal edges that don't go to exit.  */
    4498                 :             :   /* ??? I.e. the fallthrough edge.  HOWEVER!  If there were to be
    4499                 :             :      EH or abnormal edges, we shouldn't have created a tail call in
    4500                 :             :      the first place.  So it seems to me we should just be removing
    4501                 :             :      all edges here, or redirecting the existing fallthru edge to
    4502                 :             :      the exit block.  */
    4503                 :             : 
    4504                 :      123968 :   probability = profile_probability::never ();
    4505                 :             : 
    4506                 :      247930 :   for (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); )
    4507                 :             :     {
    4508                 :      123962 :       if (!(e->flags & (EDGE_ABNORMAL | EDGE_EH)))
    4509                 :             :         {
    4510                 :      123956 :           if (e->dest != EXIT_BLOCK_PTR_FOR_FN (cfun))
    4511                 :       59077 :             e->dest->count -= e->count ();
    4512                 :      123956 :           probability += e->probability;
    4513                 :      123956 :           expand_remove_edge (e);
    4514                 :             :         }
    4515                 :             :       else
    4516                 :           6 :         ei_next (&ei);
    4517                 :             :     }
    4518                 :             : 
    4519                 :             :   /* This is somewhat ugly: the call_expr expander often emits instructions
    4520                 :             :      after the sibcall (to perform the function return).  These confuse the
    4521                 :             :      find_many_sub_basic_blocks code, so we need to get rid of these.  */
    4522                 :      123968 :   last = NEXT_INSN (last);
    4523                 :      123968 :   gcc_assert (BARRIER_P (last));
    4524                 :             : 
    4525                 :      123968 :   *can_fallthru = false;
    4526                 :      152341 :   while (NEXT_INSN (last))
    4527                 :             :     {
    4528                 :             :       /* For instance an sqrt builtin expander expands if with
    4529                 :             :          sibcall in the then and label for `else`.  */
    4530                 :       28373 :       if (LABEL_P (NEXT_INSN (last)))
    4531                 :             :         {
    4532                 :           0 :           *can_fallthru = true;
    4533                 :           0 :           break;
    4534                 :             :         }
    4535                 :       28373 :       delete_insn (NEXT_INSN (last));
    4536                 :             :     }
    4537                 :             : 
    4538                 :      123968 :   e = make_edge (bb, EXIT_BLOCK_PTR_FOR_FN (cfun), EDGE_ABNORMAL
    4539                 :             :                  | EDGE_SIBCALL);
    4540                 :      123968 :   e->probability = probability;
    4541                 :      123968 :   head_end_for_bb[bb->index].second = last;
    4542                 :      247936 :   update_bb_for_insn_chain (head_end_for_bb[bb->index].first,
    4543                 :      123968 :                             head_end_for_bb[bb->index].second, bb);
    4544                 :             : 
    4545                 :      123968 :   if (NEXT_INSN (last))
    4546                 :             :     {
    4547                 :           0 :       bb = create_basic_block (NEXT_INSN (last), get_last_insn (), bb);
    4548                 :             : 
    4549                 :           0 :       last = BB_END (bb);
    4550                 :           0 :       if (BARRIER_P (last))
    4551                 :           0 :         BB_END (bb) = PREV_INSN (last);
    4552                 :             :     }
    4553                 :             : 
    4554                 :      123968 :   maybe_dump_rtl_for_gimple_stmt (stmt, last2);
    4555                 :             : 
    4556                 :      123968 :   return bb;
    4557                 :             : }
    4558                 :             : 
    4559                 :             : /* Return the difference between the floor and the truncated result of
    4560                 :             :    a signed division by OP1 with remainder MOD.  */
    4561                 :             : static rtx
    4562                 :           4 : floor_sdiv_adjust (machine_mode mode, rtx mod, rtx op1)
    4563                 :             : {
    4564                 :             :   /* (mod != 0 ? (op1 / mod < 0 ? -1 : 0) : 0) */
    4565                 :           4 :   return gen_rtx_IF_THEN_ELSE
    4566                 :             :     (mode, gen_rtx_NE (BImode, mod, const0_rtx),
    4567                 :             :      gen_rtx_IF_THEN_ELSE
    4568                 :             :      (mode, gen_rtx_LT (BImode,
    4569                 :             :                         gen_rtx_DIV (mode, op1, mod),
    4570                 :             :                         const0_rtx),
    4571                 :             :       constm1_rtx, const0_rtx),
    4572                 :             :      const0_rtx);
    4573                 :             : }
    4574                 :             : 
    4575                 :             : /* Return the difference between the ceil and the truncated result of
    4576                 :             :    a signed division by OP1 with remainder MOD.  */
    4577                 :             : static rtx
    4578                 :           3 : ceil_sdiv_adjust (machine_mode mode, rtx mod, rtx op1)
    4579                 :             : {
    4580                 :             :   /* (mod != 0 ? (op1 / mod > 0 ? 1 : 0) : 0) */
    4581                 :           3 :   return gen_rtx_IF_THEN_ELSE
    4582                 :             :     (mode, gen_rtx_NE (BImode, mod, const0_rtx),
    4583                 :             :      gen_rtx_IF_THEN_ELSE
    4584                 :             :      (mode, gen_rtx_GT (BImode,
    4585                 :             :                         gen_rtx_DIV (mode, op1, mod),
    4586                 :             :                         const0_rtx),
    4587                 :             :       const1_rtx, const0_rtx),
    4588                 :             :      const0_rtx);
    4589                 :             : }
    4590                 :             : 
    4591                 :             : /* Return the difference between the ceil and the truncated result of
    4592                 :             :    an unsigned division by OP1 with remainder MOD.  */
    4593                 :             : static rtx
    4594                 :           0 : ceil_udiv_adjust (machine_mode mode, rtx mod, rtx op1 ATTRIBUTE_UNUSED)
    4595                 :             : {
    4596                 :             :   /* (mod != 0 ? 1 : 0) */
    4597                 :           0 :   return gen_rtx_IF_THEN_ELSE
    4598                 :             :     (mode, gen_rtx_NE (BImode, mod, const0_rtx),
    4599                 :             :      const1_rtx, const0_rtx);
    4600                 :             : }
    4601                 :             : 
    4602                 :             : /* Return the difference between the rounded and the truncated result
    4603                 :             :    of a signed division by OP1 with remainder MOD.  Halfway cases are
    4604                 :             :    rounded away from zero, rather than to the nearest even number.  */
    4605                 :             : static rtx
    4606                 :           0 : round_sdiv_adjust (machine_mode mode, rtx mod, rtx op1)
    4607                 :             : {
    4608                 :             :   /* (abs (mod) >= abs (op1) - abs (mod)
    4609                 :             :       ? (op1 / mod > 0 ? 1 : -1)
    4610                 :             :       : 0) */
    4611                 :           0 :   return gen_rtx_IF_THEN_ELSE
    4612                 :             :     (mode, gen_rtx_GE (BImode, gen_rtx_ABS (mode, mod),
    4613                 :             :                        gen_rtx_MINUS (mode,
    4614                 :             :                                       gen_rtx_ABS (mode, op1),
    4615                 :             :                                       gen_rtx_ABS (mode, mod))),
    4616                 :             :      gen_rtx_IF_THEN_ELSE
    4617                 :             :      (mode, gen_rtx_GT (BImode,
    4618                 :             :                         gen_rtx_DIV (mode, op1, mod),
    4619                 :             :                         const0_rtx),
    4620                 :             :       const1_rtx, constm1_rtx),
    4621                 :             :      const0_rtx);
    4622                 :             : }
    4623                 :             : 
    4624                 :             : /* Return the difference between the rounded and the truncated result
    4625                 :             :    of a unsigned division by OP1 with remainder MOD.  Halfway cases
    4626                 :             :    are rounded away from zero, rather than to the nearest even
    4627                 :             :    number.  */
    4628                 :             : static rtx
    4629                 :           0 : round_udiv_adjust (machine_mode mode, rtx mod, rtx op1)
    4630                 :             : {
    4631                 :             :   /* (mod >= op1 - mod ? 1 : 0) */
    4632                 :           0 :   return gen_rtx_IF_THEN_ELSE
    4633                 :             :     (mode, gen_rtx_GE (BImode, mod,
    4634                 :             :                        gen_rtx_MINUS (mode, op1, mod)),
    4635                 :             :      const1_rtx, const0_rtx);
    4636                 :             : }
    4637                 :             : 
    4638                 :             : /* Convert X to MODE, that must be Pmode or ptr_mode, without emitting
    4639                 :             :    any rtl.  */
    4640                 :             : 
    4641                 :             : static rtx
    4642                 :     7196003 : convert_debug_memory_address (scalar_int_mode mode, rtx x,
    4643                 :             :                               addr_space_t as)
    4644                 :             : {
    4645                 :             : #ifndef POINTERS_EXTEND_UNSIGNED
    4646                 :             :   gcc_assert (mode == Pmode
    4647                 :             :               || mode == targetm.addr_space.address_mode (as));
    4648                 :             :   gcc_assert (GET_MODE (x) == mode || GET_MODE (x) == VOIDmode);
    4649                 :             : #else
    4650                 :     7196003 :   rtx temp;
    4651                 :             : 
    4652                 :     7196003 :   gcc_assert (targetm.addr_space.valid_pointer_mode (mode, as));
    4653                 :             : 
    4654                 :     7196003 :   if (GET_MODE (x) == mode || GET_MODE (x) == VOIDmode)
    4655                 :             :     return x;
    4656                 :             : 
    4657                 :             :   /* X must have some form of address mode already.  */
    4658                 :           0 :   scalar_int_mode xmode = as_a <scalar_int_mode> (GET_MODE (x));
    4659                 :           0 :   if (GET_MODE_PRECISION (mode) < GET_MODE_PRECISION (xmode))
    4660                 :           0 :     x = lowpart_subreg (mode, x, xmode);
    4661                 :           0 :   else if (POINTERS_EXTEND_UNSIGNED > 0)
    4662                 :           0 :     x = gen_rtx_ZERO_EXTEND (mode, x);
    4663                 :             :   else if (!POINTERS_EXTEND_UNSIGNED)
    4664                 :             :     x = gen_rtx_SIGN_EXTEND (mode, x);
    4665                 :             :   else
    4666                 :             :     {
    4667                 :             :       switch (GET_CODE (x))
    4668                 :             :         {
    4669                 :             :         case SUBREG:
    4670                 :             :           if ((SUBREG_PROMOTED_VAR_P (x)
    4671                 :             :                || (REG_P (SUBREG_REG (x)) && REG_POINTER (SUBREG_REG (x)))
    4672                 :             :                || (GET_CODE (SUBREG_REG (x)) == PLUS
    4673                 :             :                    && REG_P (XEXP (SUBREG_REG (x), 0))
    4674                 :             :                    && REG_POINTER (XEXP (SUBREG_REG (x), 0))
    4675                 :             :                    && CONST_INT_P (XEXP (SUBREG_REG (x), 1))))
    4676                 :             :               && GET_MODE (SUBREG_REG (x)) == mode)
    4677                 :             :             return SUBREG_REG (x);
    4678                 :             :           break;
    4679                 :             :         case LABEL_REF:
    4680                 :             :           temp = gen_rtx_LABEL_REF (mode, label_ref_label (x));
    4681                 :             :           LABEL_REF_NONLOCAL_P (temp) = LABEL_REF_NONLOCAL_P (x);
    4682                 :             :           return temp;
    4683                 :             :         case SYMBOL_REF:
    4684                 :             :           temp = shallow_copy_rtx (x);
    4685                 :             :           PUT_MODE (temp, mode);
    4686                 :             :           return temp;
    4687                 :             :         case CONST:
    4688                 :             :           temp = convert_debug_memory_address (mode, XEXP (x, 0), as);
    4689                 :             :           if (temp)
    4690                 :             :             temp = gen_rtx_CONST (mode, temp);
    4691                 :             :           return temp;
    4692                 :             :         case PLUS:
    4693                 :             :         case MINUS:
    4694                 :             :           if (CONST_INT_P (XEXP (x, 1)))
    4695                 :             :             {
    4696                 :             :               temp = convert_debug_memory_address (mode, XEXP (x, 0), as);
    4697                 :             :               if (temp)
    4698                 :             :                 return gen_rtx_fmt_ee (GET_CODE (x), mode, temp, XEXP (x, 1));
    4699                 :             :             }
    4700                 :             :           break;
    4701                 :             :         default:
    4702                 :             :           break;
    4703                 :             :         }
    4704                 :             :       /* Don't know how to express ptr_extend as operation in debug info.  */
    4705                 :             :       return NULL;
    4706                 :             :     }
    4707                 :             : #endif /* POINTERS_EXTEND_UNSIGNED */
    4708                 :             : 
    4709                 :             :   return x;
    4710                 :             : }
    4711                 :             : 
    4712                 :             : /* Map from SSA_NAMEs to corresponding DEBUG_EXPR_DECLs created
    4713                 :             :    by avoid_deep_ter_for_debug.  */
    4714                 :             : 
    4715                 :             : static hash_map<tree, tree> *deep_ter_debug_map;
    4716                 :             : 
    4717                 :             : /* Split too deep TER chains for debug stmts using debug temporaries.  */
    4718                 :             : 
    4719                 :             : static void
    4720                 :    38272667 : avoid_deep_ter_for_debug (gimple *stmt, int depth)
    4721                 :             : {
    4722                 :    38272667 :   use_operand_p use_p;
    4723                 :    38272667 :   ssa_op_iter iter;
    4724                 :    47505392 :   FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE)
    4725                 :             :     {
    4726                 :     9232725 :       tree use = USE_FROM_PTR (use_p);
    4727                 :     9232725 :       if (TREE_CODE (use) != SSA_NAME || SSA_NAME_IS_DEFAULT_DEF (use))
    4728                 :     7793939 :         continue;
    4729                 :     7923088 :       gimple *g = get_gimple_for_ssa_name (use);
    4730                 :     7923088 :       if (g == NULL)
    4731                 :     6483443 :         continue;
    4732                 :     1439645 :       if ((depth > 6 || !is_gimple_assign (g)) && !stmt_ends_bb_p (g))
    4733                 :             :         {
    4734                 :        3668 :           if (deep_ter_debug_map == NULL)
    4735                 :         658 :             deep_ter_debug_map = new hash_map<tree, tree>;
    4736                 :             : 
    4737                 :        3668 :           tree &vexpr = deep_ter_debug_map->get_or_insert (use);
    4738                 :        3668 :           if (vexpr != NULL)
    4739                 :         859 :             continue;
    4740                 :        2809 :           vexpr = build_debug_expr_decl (TREE_TYPE (use));
    4741                 :        2809 :           gimple *def_temp = gimple_build_debug_bind (vexpr, use, g);
    4742                 :        2809 :           gimple_stmt_iterator gsi = gsi_for_stmt (g);
    4743                 :        2809 :           gsi_insert_after (&gsi, def_temp, GSI_NEW_STMT);
    4744                 :        2809 :           avoid_deep_ter_for_debug (def_temp, 0);
    4745                 :             :         }
    4746                 :             :       else
    4747                 :     1435977 :         avoid_deep_ter_for_debug (g, depth + 1);
    4748                 :             :     }
    4749                 :    38272667 : }
    4750                 :             : 
    4751                 :             : /* Return an RTX equivalent to the value of the parameter DECL.  */
    4752                 :             : 
    4753                 :             : static rtx
    4754                 :      164510 : expand_debug_parm_decl (tree decl)
    4755                 :             : {
    4756                 :      164510 :   rtx incoming = DECL_INCOMING_RTL (decl);
    4757                 :             : 
    4758                 :      164510 :   if (incoming
    4759                 :       18651 :       && GET_MODE (incoming) != BLKmode
    4760                 :      183157 :       && ((REG_P (incoming) && HARD_REGISTER_P (incoming))
    4761                 :        1846 :           || (MEM_P (incoming)
    4762                 :        1760 :               && REG_P (XEXP (incoming, 0))
    4763                 :         768 :               && HARD_REGISTER_P (XEXP (incoming, 0)))))
    4764                 :             :     {
    4765                 :       16829 :       rtx rtl = gen_rtx_ENTRY_VALUE (GET_MODE (incoming));
    4766                 :             : 
    4767                 :             : #ifdef HAVE_window_save
    4768                 :             :       /* DECL_INCOMING_RTL uses the INCOMING_REGNO of parameter registers.
    4769                 :             :          If the target machine has an explicit window save instruction, the
    4770                 :             :          actual entry value is the corresponding OUTGOING_REGNO instead.  */
    4771                 :             :       if (REG_P (incoming)
    4772                 :             :           && OUTGOING_REGNO (REGNO (incoming)) != REGNO (incoming))
    4773                 :             :         incoming
    4774                 :             :           = gen_rtx_REG_offset (incoming, GET_MODE (incoming),
    4775                 :             :                                 OUTGOING_REGNO (REGNO (incoming)), 0);
    4776                 :             :       else if (MEM_P (incoming))
    4777                 :             :         {
    4778                 :             :           rtx reg = XEXP (incoming, 0);
    4779                 :             :           if (OUTGOING_REGNO (REGNO (reg)) != REGNO (reg))
    4780                 :             :             {
    4781                 :             :               reg = gen_raw_REG (GET_MODE (reg), OUTGOING_REGNO (REGNO (reg)));
    4782                 :             :               incoming = replace_equiv_address_nv (incoming, reg);
    4783                 :             :             }
    4784                 :             :           else
    4785                 :             :             incoming = copy_rtx (incoming);
    4786                 :             :         }
    4787                 :             : #endif
    4788                 :             : 
    4789                 :       16829 :       ENTRY_VALUE_EXP (rtl) = incoming;
    4790                 :       16829 :       return rtl;
    4791                 :             :     }
    4792                 :             : 
    4793                 :      147681 :   if (incoming
    4794                 :        1822 :       && GET_MODE (incoming) != BLKmode
    4795                 :        1818 :       && !TREE_ADDRESSABLE (decl)
    4796                 :        1818 :       && MEM_P (incoming)
    4797                 :        1732 :       && (XEXP (incoming, 0) == virtual_incoming_args_rtx
    4798                 :         992 :           || (GET_CODE (XEXP (incoming, 0)) == PLUS
    4799                 :         992 :               && XEXP (XEXP (incoming, 0), 0) == virtual_incoming_args_rtx
    4800                 :         978 :               && CONST_INT_P (XEXP (XEXP (incoming, 0), 1)))))
    4801                 :        1718 :     return copy_rtx (incoming);
    4802                 :             : 
    4803                 :             :   return NULL_RTX;
    4804                 :             : }
    4805                 :             : 
    4806                 :             : /* Return an RTX equivalent to the value of the tree expression EXP.  */
    4807                 :             : 
    4808                 :             : static rtx
    4809                 :    39629777 : expand_debug_expr (tree exp)
    4810                 :             : {
    4811                 :    39629777 :   rtx op0 = NULL_RTX, op1 = NULL_RTX, op2 = NULL_RTX;
    4812                 :    39629777 :   machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
    4813                 :    39629777 :   machine_mode inner_mode = VOIDmode;
    4814                 :    39629777 :   int unsignedp = TYPE_UNSIGNED (TREE_TYPE (exp));
    4815                 :    39629777 :   addr_space_t as;
    4816                 :    39629777 :   scalar_int_mode op0_mode, op1_mode, addr_mode;
    4817                 :             : 
    4818                 :    39629777 :   switch (TREE_CODE_CLASS (TREE_CODE (exp)))
    4819                 :             :     {
    4820                 :     6850123 :     case tcc_expression:
    4821                 :     6850123 :       switch (TREE_CODE (exp))
    4822                 :             :         {
    4823                 :        8726 :         case COND_EXPR:
    4824                 :        8726 :         case DOT_PROD_EXPR:
    4825                 :        8726 :         case SAD_EXPR:
    4826                 :        8726 :         case WIDEN_MULT_PLUS_EXPR:
    4827                 :        8726 :         case WIDEN_MULT_MINUS_EXPR:
    4828                 :        8726 :           goto ternary;
    4829                 :             : 
    4830                 :           0 :         case TRUTH_ANDIF_EXPR:
    4831                 :           0 :         case TRUTH_ORIF_EXPR:
    4832                 :           0 :         case TRUTH_AND_EXPR:
    4833                 :           0 :         case TRUTH_OR_EXPR:
    4834                 :           0 :         case TRUTH_XOR_EXPR:
    4835                 :           0 :           goto binary;
    4836                 :             : 
    4837                 :           0 :         case TRUTH_NOT_EXPR:
    4838                 :           0 :           goto unary;
    4839                 :             : 
    4840                 :             :         default:
    4841                 :             :           break;
    4842                 :             :         }
    4843                 :             :       break;
    4844                 :             : 
    4845                 :        8726 :     ternary:
    4846                 :        8726 :       op2 = expand_debug_expr (TREE_OPERAND (exp, 2));
    4847                 :        8726 :       if (!op2)
    4848                 :             :         return NULL_RTX;
    4849                 :             :       /* Fall through.  */
    4850                 :             : 
    4851                 :        8726 :     binary:
    4852                 :     1237099 :     case tcc_binary:
    4853                 :     1237099 :       if (mode == BLKmode)
    4854                 :             :         return NULL_RTX;
    4855                 :     1237089 :       op1 = expand_debug_expr (TREE_OPERAND (exp, 1));
    4856                 :     1237089 :       if (!op1)
    4857                 :             :         return NULL_RTX;
    4858                 :     1236541 :       switch (TREE_CODE (exp))
    4859                 :             :         {
    4860                 :       61607 :         case LSHIFT_EXPR:
    4861                 :       61607 :         case RSHIFT_EXPR:
    4862                 :       61607 :         case LROTATE_EXPR:
    4863                 :       61607 :         case RROTATE_EXPR:
    4864                 :       61607 :         case WIDEN_LSHIFT_EXPR:
    4865                 :             :           /* Ensure second operand isn't wider than the first one.  */
    4866                 :       61607 :           inner_mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 1)));
    4867                 :       61607 :           if (is_a <scalar_int_mode> (inner_mode, &op1_mode)
    4868                 :       61599 :               && (GET_MODE_UNIT_PRECISION (mode)
    4869                 :       61599 :                   < GET_MODE_PRECISION (op1_mode)))
    4870                 :        5044 :             op1 = lowpart_subreg (GET_MODE_INNER (mode), op1, op1_mode);
    4871                 :             :           break;
    4872                 :             :         default:
    4873                 :             :           break;
    4874                 :             :         }
    4875                 :             :       /* Fall through.  */
    4876                 :             : 
    4877                 :     1826563 :     unary:
    4878                 :     1826563 :     case tcc_unary:
    4879                 :     1826563 :       if (mode == BLKmode)
    4880                 :             :         return NULL_RTX;
    4881                 :     1826561 :       inner_mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
    4882                 :     1826561 :       op0 = expand_debug_expr (TREE_OPERAND (exp, 0));
    4883                 :     1826561 :       if (!op0)
    4884                 :             :         return NULL_RTX;
    4885                 :             :       break;
    4886                 :             : 
    4887                 :       55253 :     case tcc_comparison:
    4888                 :       55253 :       unsignedp = TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0)));
    4889                 :       55253 :       goto binary;
    4890                 :             : 
    4891                 :           0 :     case tcc_type:
    4892                 :           0 :     case tcc_statement:
    4893                 :           0 :       gcc_unreachable ();
    4894                 :             : 
    4895                 :             :     case tcc_constant:
    4896                 :             :     case tcc_exceptional:
    4897                 :             :     case tcc_declaration:
    4898                 :             :     case tcc_reference:
    4899                 :             :     case tcc_vl_exp:
    4900                 :             :       break;
    4901                 :             :     }
    4902                 :             : 
    4903                 :    39627790 :   switch (TREE_CODE (exp))
    4904                 :             :     {
    4905                 :      273284 :     case STRING_CST:
    4906                 :      273284 :       if (!lookup_constant_def (exp))
    4907                 :             :         {
    4908                 :      121367 :           if (strlen (TREE_STRING_POINTER (exp)) + 1
    4909                 :      121367 :               != (size_t) TREE_STRING_LENGTH (exp))
    4910                 :             :             return NULL_RTX;
    4911                 :      120939 :           op0 = gen_rtx_CONST_STRING (Pmode, TREE_STRING_POINTER (exp));
    4912                 :      120372 :           op0 = gen_rtx_MEM (BLKmode, op0);
    4913                 :      120372 :           set_mem_attributes (op0, exp, 0);
    4914                 :      120372 :           return op0;
    4915                 :             :         }
    4916                 :             :       /* Fall through.  */
    4917                 :             : 
    4918                 :     5257559 :     case INTEGER_CST:
    4919                 :     5257559 :       if (TREE_CODE (TREE_TYPE (exp)) == BITINT_TYPE
    4920                 :     5257559 :           && TYPE_MODE (TREE_TYPE (exp)) == BLKmode)
    4921                 :             :         return NULL;
    4922                 :             :       /* FALLTHRU */
    4923                 :     5319604 :     case REAL_CST:
    4924                 :     5319604 :     case FIXED_CST:
    4925                 :     5319604 :       op0 = expand_expr (exp, NULL_RTX, mode, EXPAND_INITIALIZER);
    4926                 :     5319604 :       return op0;
    4927                 :             : 
    4928                 :           0 :     case POLY_INT_CST:
    4929                 :           0 :       return immed_wide_int_const (poly_int_cst_value (exp), mode);
    4930                 :             : 
    4931                 :        4450 :     case COMPLEX_CST:
    4932                 :        4450 :       gcc_assert (COMPLEX_MODE_P (mode));
    4933                 :        4450 :       op0 = expand_debug_expr (TREE_REALPART (exp));
    4934                 :        4450 :       op1 = expand_debug_expr (TREE_IMAGPART (exp));
    4935                 :        4450 :       return gen_rtx_CONCAT (mode, op0, op1);
    4936                 :             : 
    4937                 :     5533245 :     case DEBUG_EXPR_DECL:
    4938                 :     5533245 :       op0 = DECL_RTL_IF_SET (exp);
    4939                 :             : 
    4940                 :     4335960 :       if (op0)
    4941                 :             :         {
    4942                 :     4335960 :           if (GET_MODE (op0) != mode)
    4943                 :           0 :             gcc_assert (VECTOR_TYPE_P (TREE_TYPE (exp)));
    4944                 :             :           else
    4945                 :             :             return op0;
    4946                 :             :         }
    4947                 :             : 
    4948                 :     1197285 :       op0 = gen_rtx_DEBUG_EXPR (mode);
    4949                 :     1197285 :       DEBUG_EXPR_TREE_DECL (op0) = exp;
    4950                 :     1197285 :       SET_DECL_RTL (exp, op0);
    4951                 :             : 
    4952                 :     1197285 :       return op0;
    4953                 :             : 
    4954                 :     5385231 :     case VAR_DECL:
    4955                 :     5385231 :     case PARM_DECL:
    4956                 :     5385231 :     case FUNCTION_DECL:
    4957                 :     5385231 :     case LABEL_DECL:
    4958                 :     5385231 :     case CONST_DECL:
    4959                 :     5385231 :     case RESULT_DECL:
    4960                 :     5385231 :       op0 = DECL_RTL_IF_SET (exp);
    4961                 :             : 
    4962                 :             :       /* This decl was probably optimized away.  */
    4963                 :     3732003 :       if (!op0
    4964                 :             :           /* At least label RTXen are sometimes replaced by
    4965                 :             :              NOTE_INSN_DELETED_LABEL.  Any notes here are not
    4966                 :             :              handled by copy_rtx.  */
    4967                 :     3732003 :           || NOTE_P (op0))
    4968                 :             :         {
    4969                 :     1653229 :           if (!VAR_P (exp)
    4970                 :     1643226 :               || DECL_EXTERNAL (exp)
    4971                 :     1642664 :               || !TREE_STATIC (exp)
    4972                 :      107978 :               || !DECL_NAME (exp)
    4973                 :      107978 :               || DECL_HARD_REGISTER (exp)
    4974                 :      107978 :               || DECL_IN_CONSTANT_POOL (exp)
    4975                 :      107978 :               || mode == VOIDmode
    4976                 :     1761207 :               || symtab_node::get (exp) == NULL)
    4977                 :             :             return NULL;
    4978                 :             : 
    4979                 :       17667 :           op0 = make_decl_rtl_for_debug (exp);
    4980                 :       17667 :           if (!MEM_P (op0)
    4981                 :       17667 :               || GET_CODE (XEXP (op0, 0)) != SYMBOL_REF
    4982                 :       35334 :               || SYMBOL_REF_DECL (XEXP (op0, 0)) != exp)
    4983                 :             :             return NULL;
    4984                 :             :         }
    4985                 :     3732002 :       else if (VAR_P (exp)
    4986                 :     3607058 :                && is_global_var (exp)
    4987                 :     3951499 :                && symtab_node::get (exp) == NULL)
    4988                 :             :         return NULL;
    4989                 :             :       else
    4990                 :     3732002 :         op0 = copy_rtx (op0);
    4991                 :             : 
    4992                 :     3749669 :       if (GET_MODE (op0) == BLKmode
    4993                 :             :           /* If op0 is not BLKmode, but mode is, adjust_mode
    4994                 :             :              below would ICE.  While it is likely a FE bug,
    4995                 :             :              try to be robust here.  See PR43166.  */
    4996                 :      512640 :           || mode == BLKmode
    4997                 :      512640 :           || (mode == VOIDmode && GET_MODE (op0) != VOIDmode))
    4998                 :             :         {
    4999                 :     3237029 :           gcc_assert (MEM_P (op0));
    5000                 :     3237029 :           op0 = adjust_address_nv (op0, mode, 0);
    5001                 :     3237029 :           return op0;
    5002                 :             :         }
    5003                 :             : 
    5004                 :             :       /* Fall through.  */
    5005                 :             : 
    5006                 :      512640 :     adjust_mode:
    5007                 :     9894657 :     case PAREN_EXPR:
    5008                 :     9894657 :     CASE_CONVERT:
    5009                 :     9894657 :       {
    5010                 :     9894657 :         inner_mode = GET_MODE (op0);
    5011                 :             : 
    5012                 :     9894657 :         if (mode == inner_mode)
    5013                 :             :           return op0;
    5014                 :             : 
    5015                 :      153333 :         if (inner_mode == VOIDmode)
    5016                 :             :           {
    5017                 :        5345 :             if (TREE_CODE (exp) == SSA_NAME)
    5018                 :          12 :               inner_mode = TYPE_MODE (TREE_TYPE (exp));
    5019                 :             :             else
    5020                 :        5333 :               inner_mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
    5021                 :        5345 :             if (mode == inner_mode)
    5022                 :             :               return op0;
    5023                 :             :           }
    5024                 :             : 
    5025                 :      150702 :         if (FLOAT_MODE_P (mode) && FLOAT_MODE_P (inner_mode))
    5026                 :             :           {
    5027                 :        6150 :             if (GET_MODE_UNIT_BITSIZE (mode)
    5028                 :       12300 :                 == GET_MODE_UNIT_BITSIZE (inner_mode))
    5029                 :           4 :               op0 = simplify_gen_subreg (mode, op0, inner_mode, 0);
    5030                 :        6146 :             else if (GET_MODE_UNIT_BITSIZE (mode)
    5031                 :       12292 :                      < GET_MODE_UNIT_BITSIZE (inner_mode))
    5032                 :        3517 :               op0 = simplify_gen_unary (FLOAT_TRUNCATE, mode, op0, inner_mode);
    5033                 :             :             else
    5034                 :        2629 :               op0 = simplify_gen_unary (FLOAT_EXTEND, mode, op0, inner_mode);
    5035                 :             :           }
    5036                 :      144552 :         else if (FLOAT_MODE_P (mode))
    5037                 :             :           {
    5038                 :           0 :             gcc_assert (TREE_CODE (exp) != SSA_NAME);
    5039                 :           0 :             if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0))))
    5040                 :           0 :               op0 = simplify_gen_unary (UNSIGNED_FLOAT, mode, op0, inner_mode);
    5041                 :             :             else
    5042                 :           0 :               op0 = simplify_gen_unary (FLOAT, mode, op0, inner_mode);
    5043                 :             :           }
    5044                 :      144552 :         else if (FLOAT_MODE_P (inner_mode))
    5045                 :             :           {
    5046                 :           0 :             if (unsignedp)
    5047                 :           0 :               op0 = simplify_gen_unary (UNSIGNED_FIX, mode, op0, inner_mode);
    5048                 :             :             else
    5049                 :           0 :               op0 = simplify_gen_unary (FIX, mode, op0, inner_mode);
    5050                 :             :           }
    5051                 :      289104 :         else if (GET_MODE_UNIT_PRECISION (mode)
    5052                 :      144552 :                  == GET_MODE_UNIT_PRECISION (inner_mode))
    5053                 :           0 :           op0 = lowpart_subreg (mode, op0, inner_mode);
    5054                 :      289104 :         else if (GET_MODE_UNIT_PRECISION (mode)
    5055                 :      144552 :                  < GET_MODE_UNIT_PRECISION (inner_mode))
    5056                 :       65890 :           op0 = simplify_gen_unary (TRUNCATE, mode, op0, inner_mode);
    5057                 :       78662 :         else if (UNARY_CLASS_P (exp)
    5058                 :       78662 :                  ? TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0)))
    5059                 :           0 :                  : unsignedp)
    5060                 :       53817 :           op0 = simplify_gen_unary (ZERO_EXTEND, mode, op0, inner_mode);
    5061                 :             :         else
    5062                 :       24845 :           op0 = simplify_gen_unary (SIGN_EXTEND, mode, op0, inner_mode);
    5063                 :             : 
    5064                 :             :         return op0;
    5065                 :             :       }
    5066                 :             : 
    5067                 :     2172449 :     case MEM_REF:
    5068                 :     2172449 :       if (!is_gimple_mem_ref_addr (TREE_OPERAND (exp, 0)))
    5069                 :             :         {
    5070                 :      822062 :           tree newexp = fold_binary (MEM_REF, TREE_TYPE (exp),
    5071                 :             :                                      TREE_OPERAND (exp, 0),
    5072                 :             :                                      TREE_OPERAND (exp, 1));
    5073                 :      822062 :           if (newexp)
    5074                 :           0 :             return expand_debug_expr (newexp);
    5075                 :             :         }
    5076                 :             :       /* FALLTHROUGH */
    5077                 :     2172449 :     case INDIRECT_REF:
    5078                 :     2172449 :       inner_mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
    5079                 :     2172449 :       op0 = expand_debug_expr (TREE_OPERAND (exp, 0));
    5080                 :     2172449 :       if (!op0)
    5081                 :             :         return NULL;
    5082                 :             : 
    5083                 :     2168999 :       if (TREE_CODE (exp) == MEM_REF)
    5084                 :             :         {
    5085                 :     2168999 :           if (GET_CODE (op0) == DEBUG_IMPLICIT_PTR
    5086                 :     2122852 :               || (GET_CODE (op0) == PLUS
    5087                 :      313211 :                   && GET_CODE (XEXP (op0, 0)) == DEBUG_IMPLICIT_PTR))
    5088                 :             :             /* (mem (debug_implicit_ptr)) might confuse aliasing.
    5089                 :             :                Instead just use get_inner_reference.  */
    5090                 :       46147 :             goto component_ref;
    5091                 :             : 
    5092                 :     2122852 :           op1 = expand_debug_expr (TREE_OPERAND (exp, 1));
    5093                 :     2122852 :           poly_int64 offset;
    5094                 :     2122852 :           if (!op1 || !poly_int_rtx_p (op1, &offset))
    5095                 :           0 :             return NULL;
    5096                 :             : 
    5097                 :     2122852 :           op0 = plus_constant (inner_mode, op0, offset);
    5098                 :             :         }
    5099                 :             : 
    5100                 :     2122852 :       as = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0))));
    5101                 :             : 
    5102                 :     2122852 :       op0 = convert_debug_memory_address (targetm.addr_space.address_mode (as),
    5103                 :             :                                           op0, as);
    5104                 :     2122852 :       if (op0 == NULL_RTX)
    5105                 :             :         return NULL;
    5106                 :             : 
    5107                 :     2122852 :       op0 = gen_rtx_MEM (mode, op0);
    5108                 :     2122852 :       set_mem_attributes (op0, exp, 0);
    5109                 :     2122852 :       if (TREE_CODE (exp) == MEM_REF
    5110                 :     2122852 :           && !is_gimple_mem_ref_addr (TREE_OPERAND (exp, 0)))
    5111                 :      822062 :         set_mem_expr (op0, NULL_TREE);
    5112                 :     2122852 :       set_mem_addr_space (op0, as);
    5113                 :             : 
    5114                 :     2122852 :       return op0;
    5115                 :             : 
    5116                 :       50383 :     case TARGET_MEM_REF:
    5117                 :       50383 :       if (TREE_CODE (TMR_BASE (exp)) == ADDR_EXPR
    5118                 :       50383 :           && !DECL_RTL_SET_P (TREE_OPERAND (TMR_BASE (exp), 0)))
    5119                 :             :         return NULL;
    5120                 :             : 
    5121                 :       50373 :       op0 = expand_debug_expr
    5122                 :       50373 :             (tree_mem_ref_addr (build_pointer_type (TREE_TYPE (exp)), exp));
    5123                 :       50373 :       if (!op0)
    5124                 :             :         return NULL;
    5125                 :             : 
    5126                 :       50373 :       as = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0))));
    5127                 :       50373 :       op0 = convert_debug_memory_address (targetm.addr_space.address_mode (as),
    5128                 :             :                                           op0, as);
    5129                 :       50373 :       if (op0 == NULL_RTX)
    5130                 :             :         return NULL;
    5131                 :             : 
    5132                 :       50373 :       op0 = gen_rtx_MEM (mode, op0);
    5133                 :             : 
    5134                 :       50373 :       set_mem_attributes (op0, exp, 0);
    5135                 :       50373 :       set_mem_addr_space (op0, as);
    5136                 :             : 
    5137                 :       50373 :       return op0;
    5138                 :             : 
    5139                 :     3581916 :     component_ref:
    5140                 :     3581916 :     case ARRAY_REF:
    5141                 :     3581916 :     case ARRAY_RANGE_REF:
    5142                 :     3581916 :     case COMPONENT_REF:
    5143                 :     3581916 :     case BIT_FIELD_REF:
    5144                 :     3581916 :     case REALPART_EXPR:
    5145                 :     3581916 :     case IMAGPART_EXPR:
    5146                 :     3581916 :     case VIEW_CONVERT_EXPR:
    5147                 :     3581916 :       {
    5148                 :     3581916 :         machine_mode mode1;
    5149                 :     3581916 :         poly_int64 bitsize, bitpos;
    5150                 :     3581916 :         tree offset;
    5151                 :     3581916 :         int reversep, volatilep = 0;
    5152                 :     3581916 :         tree tem
    5153                 :     3581916 :           = get_inner_reference (exp, &bitsize, &bitpos, &offset, &mode1,
    5154                 :             :                                  &unsignedp, &reversep, &volatilep);
    5155                 :     3581916 :         rtx orig_op0;
    5156                 :             : 
    5157                 :     3581916 :         if (known_eq (bitsize, 0))
    5158                 :             :           return NULL;
    5159                 :             : 
    5160                 :     3533465 :         orig_op0 = op0 = expand_debug_expr (tem);
    5161                 :             : 
    5162                 :     3533465 :         if (!op0)
    5163                 :             :           return NULL;
    5164                 :             : 
    5165                 :     3211084 :         if (offset)
    5166                 :             :           {
    5167                 :       13285 :             machine_mode addrmode, offmode;
    5168                 :             : 
    5169                 :       13285 :             if (!MEM_P (op0))
    5170                 :             :               return NULL;
    5171                 :             : 
    5172                 :       13285 :             op0 = XEXP (op0, 0);
    5173                 :       13285 :             addrmode = GET_MODE (op0);
    5174                 :       13285 :             if (addrmode == VOIDmode)
    5175                 :           0 :               addrmode = Pmode;
    5176                 :             : 
    5177                 :       13285 :             op1 = expand_debug_expr (offset);
    5178                 :       13285 :             if (!op1)
    5179                 :             :               return NULL;
    5180                 :             : 
    5181                 :       13283 :             offmode = GET_MODE (op1);
    5182                 :       13283 :             if (offmode == VOIDmode)
    5183                 :           0 :               offmode = TYPE_MODE (TREE_TYPE (offset));
    5184                 :             : 
    5185                 :       13283 :             if (addrmode != offmode)
    5186                 :           0 :               op1 = lowpart_subreg (addrmode, op1, offmode);
    5187                 :             : 
    5188                 :             :             /* Don't use offset_address here, we don't need a
    5189                 :             :                recognizable address, and we don't want to generate
    5190                 :             :                code.  */
    5191                 :       13283 :             op0 = gen_rtx_MEM (mode, simplify_gen_binary (PLUS, addrmode,
    5192                 :             :                                                           op0, op1));
    5193                 :             :           }
    5194                 :             : 
    5195                 :     3211082 :         if (MEM_P (op0))
    5196                 :             :           {
    5197                 :     3082549 :             if (mode1 == VOIDmode)
    5198                 :             :               {
    5199                 :        6039 :                 if (maybe_gt (bitsize, MAX_BITSIZE_MODE_ANY_INT))
    5200                 :      370867 :                   return NULL;
    5201                 :             :                 /* Bitfield.  */
    5202                 :        6039 :                 mode1 = smallest_int_mode_for_size (bitsize).require ();
    5203                 :             :               }
    5204                 :     3082549 :             poly_int64 bytepos = bits_to_bytes_round_down (bitpos);
    5205                 :     3082549 :             if (maybe_ne (bytepos, 0))
    5206                 :             :               {
    5207                 :     1370481 :                 op0 = adjust_address_nv (op0, mode1, bytepos);
    5208                 :     1370481 :                 bitpos = num_trailing_bits (bitpos);
    5209                 :             :               }
    5210                 :     1712068 :             else if (known_eq (bitpos, 0)
    5211                 :     3423324 :                      && known_eq (bitsize, GET_MODE_BITSIZE (mode)))
    5212                 :      487826 :               op0 = adjust_address_nv (op0, mode, 0);
    5213                 :     1224242 :             else if (GET_MODE (op0) != mode1)
    5214                 :        3907 :               op0 = adjust_address_nv (op0, mode1, 0);
    5215                 :             :             else
    5216                 :     1220335 :               op0 = copy_rtx (op0);
    5217                 :     3082549 :             if (op0 == orig_op0)
    5218                 :      134930 :               op0 = shallow_copy_rtx (op0);
    5219                 :     3082549 :             if (TREE_CODE (tem) != SSA_NAME)
    5220                 :     3079328 :               set_mem_attributes (op0, exp, 0);
    5221                 :             :           }
    5222                 :             : 
    5223                 :     3211082 :         if (known_eq (bitpos, 0) && mode == GET_MODE (op0))
    5224                 :             :           return op0;
    5225                 :             : 
    5226                 :      104215 :         if (maybe_lt (bitpos, 0))
    5227                 :             :           return NULL;
    5228                 :             : 
    5229                 :      104213 :         if (GET_MODE (op0) == BLKmode || mode == BLKmode)
    5230                 :             :           return NULL;
    5231                 :             : 
    5232                 :      104202 :         poly_int64 bytepos;
    5233                 :      104871 :         if (multiple_p (bitpos, BITS_PER_UNIT, &bytepos)
    5234                 :      202374 :             && known_eq (bitsize, GET_MODE_BITSIZE (mode1)))
    5235                 :             :           {
    5236                 :      100534 :             machine_mode opmode = GET_MODE (op0);
    5237                 :             : 
    5238                 :      100534 :             if (opmode == VOIDmode)
    5239                 :           0 :               opmode = TYPE_MODE (TREE_TYPE (tem));
    5240                 :             : 
    5241                 :             :             /* This condition may hold if we're expanding the address
    5242                 :             :                right past the end of an array that turned out not to
    5243                 :             :                be addressable (i.e., the address was only computed in
    5244                 :             :                debug stmts).  The gen_subreg below would rightfully
    5245                 :             :                crash, and the address doesn't really exist, so just
    5246                 :             :                drop it.  */
    5247                 :      201068 :             if (known_ge (bitpos, GET_MODE_BITSIZE (opmode)))
    5248                 :             :               return NULL;
    5249                 :             : 
    5250                 :      201028 :             if (multiple_p (bitpos, GET_MODE_BITSIZE (mode)))
    5251                 :      100498 :               return simplify_gen_subreg (mode, op0, opmode, bytepos);
    5252                 :             :           }
    5253                 :             : 
    5254                 :        7368 :         return simplify_gen_ternary (SCALAR_INT_MODE_P (GET_MODE (op0))
    5255                 :        3247 :                                      && TYPE_UNSIGNED (TREE_TYPE (exp))
    5256                 :             :                                      ? SIGN_EXTRACT
    5257                 :             :                                      : ZERO_EXTRACT, mode,
    5258                 :        3684 :                                      GET_MODE (op0) != VOIDmode
    5259                 :             :                                      ? GET_MODE (op0)
    5260                 :           0 :                                      : TYPE_MODE (TREE_TYPE (tem)),
    5261                 :             :                                      op0, gen_int_mode (bitsize, word_mode),
    5262                 :        3684 :                                      gen_int_mode (bitpos, word_mode));
    5263                 :             :       }
    5264                 :             : 
    5265                 :        1427 :     case ABS_EXPR:
    5266                 :        1427 :     case ABSU_EXPR:
    5267                 :        1427 :       return simplify_gen_unary (ABS, mode, op0, mode);
    5268                 :             : 
    5269                 :       14362 :     case NEGATE_EXPR:
    5270                 :       14362 :       return simplify_gen_unary (NEG, mode, op0, mode);
    5271                 :             : 
    5272                 :       18289 :     case BIT_NOT_EXPR:
    5273                 :       18289 :       return simplify_gen_unary (NOT, mode, op0, mode);
    5274                 :             : 
    5275                 :        2310 :     case FLOAT_EXPR:
    5276                 :        2310 :       return simplify_gen_unary (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp,
    5277                 :             :                                                                          0)))
    5278                 :             :                                  ? UNSIGNED_FLOAT : FLOAT, mode, op0,
    5279                 :        2310 :                                  inner_mode);
    5280                 :             : 
    5281                 :         356 :     case FIX_TRUNC_EXPR:
    5282                 :         356 :       return simplify_gen_unary (unsignedp ? UNSIGNED_FIX : FIX, mode, op0,
    5283                 :         356 :                                  inner_mode);
    5284                 :             : 
    5285                 :      202580 :     case POINTER_PLUS_EXPR:
    5286                 :             :       /* For the rare target where pointers are not the same size as
    5287                 :             :          size_t, we need to check for mis-matched modes and correct
    5288                 :             :          the addend.  */
    5289                 :      202580 :       if (op0 && op1
    5290                 :      202580 :           && is_a <scalar_int_mode> (GET_MODE (op0), &op0_mode)
    5291                 :      202480 :           && is_a <scalar_int_mode> (GET_MODE (op1), &op1_mode)
    5292                 :      323290 :           && op0_mode != op1_mode)
    5293                 :             :         {
    5294                 :           0 :           if (GET_MODE_BITSIZE (op0_mode) < GET_MODE_BITSIZE (op1_mode)
    5295                 :             :               /* If OP0 is a partial mode, then we must truncate, even
    5296                 :             :                  if it has the same bitsize as OP1 as GCC's
    5297                 :             :                  representation of partial modes is opaque.  */
    5298                 :           0 :               || (GET_MODE_CLASS (op0_mode) == MODE_PARTIAL_INT
    5299                 :           0 :                   && (GET_MODE_BITSIZE (op0_mode)
    5300                 :           0 :                       == GET_MODE_BITSIZE (op1_mode))))
    5301                 :           0 :             op1 = simplify_gen_unary (TRUNCATE, op0_mode, op1, op1_mode);
    5302                 :             :           else
    5303                 :             :             /* We always sign-extend, regardless of the signedness of
    5304                 :             :                the operand, because the operand is always unsigned
    5305                 :             :                here even if the original C expression is signed.  */
    5306                 :           0 :             op1 = simplify_gen_unary (SIGN_EXTEND, op0_mode, op1, op1_mode);
    5307                 :             :         }
    5308                 :             :       /* Fall through.  */
    5309                 :      600711 :     case PLUS_EXPR:
    5310                 :      600711 :       return simplify_gen_binary (PLUS, mode, op0, op1);
    5311                 :             : 
    5312                 :      120517 :     case MINUS_EXPR:
    5313                 :      120517 :     case POINTER_DIFF_EXPR:
    5314                 :      120517 :       return simplify_gen_binary (MINUS, mode, op0, op1);
    5315                 :             : 
    5316                 :      134449 :     case MULT_EXPR:
    5317                 :      134449 :       return simplify_gen_binary (MULT, mode, op0, op1);
    5318                 :             : 
    5319                 :        3063 :     case RDIV_EXPR:
    5320                 :        3063 :       gcc_assert (FLOAT_MODE_P (mode)
    5321                 :             :                   || ALL_FIXED_POINT_MODE_P (mode));
    5322                 :             :       /* Fall through.  */
    5323                 :       75811 :     case TRUNC_DIV_EXPR:
    5324                 :       75811 :     case EXACT_DIV_EXPR:
    5325                 :       75811 :       if (unsignedp)
    5326                 :       11224 :         return simplify_gen_binary (UDIV, mode, op0, op1);
    5327                 :             :       else
    5328                 :       64587 :         return simplify_gen_binary (DIV, mode, op0, op1);
    5329                 :             : 
    5330                 :        5420 :     case TRUNC_MOD_EXPR:
    5331                 :       10840 :       return simplify_gen_binary (unsignedp ? UMOD : MOD, mode, op0, op1);
    5332                 :             : 
    5333                 :           3 :     case FLOOR_DIV_EXPR:
    5334                 :           3 :       if (unsignedp)
    5335                 :           0 :         return simplify_gen_binary (UDIV, mode, op0, op1);
    5336                 :             :       else
    5337                 :             :         {
    5338                 :           3 :           rtx div = simplify_gen_binary (DIV, mode, op0, op1);
    5339                 :           3 :           rtx mod = simplify_gen_binary (MOD, mode, op0, op1);
    5340                 :           3 :           rtx adj = floor_sdiv_adjust (mode, mod, op1);
    5341                 :           3 :           return simplify_gen_binary (PLUS, mode, div, adj);
    5342                 :             :         }
    5343                 :             : 
    5344                 :           1 :     case FLOOR_MOD_EXPR:
    5345                 :           1 :       if (unsignedp)
    5346                 :           0 :         return simplify_gen_binary (UMOD, mode, op0, op1);
    5347                 :             :       else
    5348                 :             :         {
    5349                 :           1 :           rtx mod = simplify_gen_binary (MOD, mode, op0, op1);
    5350                 :           1 :           rtx adj = floor_sdiv_adjust (mode, mod, op1);
    5351                 :           1 :           adj = simplify_gen_unary (NEG, mode,
    5352                 :             :                                     simplify_gen_binary (MULT, mode, adj, op1),
    5353                 :             :                                     mode);
    5354                 :           1 :           return simplify_gen_binary (PLUS, mode, mod, adj);
    5355                 :             :         }
    5356                 :             : 
    5357                 :           3 :     case CEIL_DIV_EXPR:
    5358                 :           3 :       if (unsignedp)
    5359                 :             :         {
    5360                 :           0 :           rtx div = simplify_gen_binary (UDIV, mode, op0, op1);
    5361                 :           0 :           rtx mod = simplify_gen_binary (UMOD, mode, op0, op1);
    5362                 :           0 :           rtx adj = ceil_udiv_adjust (mode, mod, op1);
    5363                 :           0 :           return simplify_gen_binary (PLUS, mode, div, adj);
    5364                 :             :         }
    5365                 :             :       else
    5366                 :             :         {
    5367                 :           3 :           rtx div = simplify_gen_binary (DIV, mode, op0, op1);
    5368                 :           3 :           rtx mod = simplify_gen_binary (MOD, mode, op0, op1);
    5369                 :           3 :           rtx adj = ceil_sdiv_adjust (mode, mod, op1);
    5370                 :           3 :           return simplify_gen_binary (PLUS, mode, div, adj);
    5371                 :             :         }
    5372                 :             : 
    5373                 :           0 :     case CEIL_MOD_EXPR:
    5374                 :           0 :       if (unsignedp)
    5375                 :             :         {
    5376                 :           0 :           rtx mod = simplify_gen_binary (UMOD, mode, op0, op1);
    5377                 :           0 :           rtx adj = ceil_udiv_adjust (mode, mod, op1);
    5378                 :           0 :           adj = simplify_gen_unary (NEG, mode,
    5379                 :             :                                     simplify_gen_binary (MULT, mode, adj, op1),
    5380                 :             :                                     mode);
    5381                 :           0 :           return simplify_gen_binary (PLUS, mode, mod, adj);
    5382                 :             :         }
    5383                 :             :       else
    5384                 :             :         {
    5385                 :           0 :           rtx mod = simplify_gen_binary (MOD, mode, op0, op1);
    5386                 :           0 :           rtx adj = ceil_sdiv_adjust (mode, mod, op1);
    5387                 :           0 :           adj = simplify_gen_unary (NEG, mode,
    5388                 :             :                                     simplify_gen_binary (MULT, mode, adj, op1),
    5389                 :             :                                     mode);
    5390                 :           0 :           return simplify_gen_binary (PLUS, mode, mod, adj);
    5391                 :             :         }
    5392                 :             : 
    5393                 :           0 :     case ROUND_DIV_EXPR:
    5394                 :           0 :       if (unsignedp)
    5395                 :             :         {
    5396                 :           0 :           rtx div = simplify_gen_binary (UDIV, mode, op0, op1);
    5397                 :           0 :           rtx mod = simplify_gen_binary (UMOD, mode, op0, op1);
    5398                 :           0 :           rtx adj = round_udiv_adjust (mode, mod, op1);
    5399                 :           0 :           return simplify_gen_binary (PLUS, mode, div, adj);
    5400                 :             :         }
    5401                 :             :       else
    5402                 :             :         {
    5403                 :           0 :           rtx div = simplify_gen_binary (DIV, mode, op0, op1);
    5404                 :           0 :           rtx mod = simplify_gen_binary (MOD, mode, op0, op1);
    5405                 :           0 :           rtx adj = round_sdiv_adjust (mode, mod, op1);
    5406                 :           0 :           return simplify_gen_binary (PLUS, mode, div, adj);
    5407                 :             :         }
    5408                 :             : 
    5409                 :           0 :     case ROUND_MOD_EXPR:
    5410                 :           0 :       if (unsignedp)
    5411                 :             :         {
    5412                 :           0 :           rtx mod = simplify_gen_binary (UMOD, mode, op0, op1);
    5413                 :           0 :           rtx adj = round_udiv_adjust (mode, mod, op1);
    5414                 :           0 :           adj = simplify_gen_unary (NEG, mode,
    5415                 :             :                                     simplify_gen_binary (MULT, mode, adj, op1),
    5416                 :             :                                     mode);
    5417                 :           0 :           return simplify_gen_binary (PLUS, mode, mod, adj);
    5418                 :             :         }
    5419                 :             :       else
    5420                 :             :         {
    5421                 :           0 :           rtx mod = simplify_gen_binary (MOD, mode, op0, op1);
    5422                 :           0 :           rtx adj = round_sdiv_adjust (mode, mod, op1);
    5423                 :           0 :           adj = simplify_gen_unary (NEG, mode,
    5424                 :             :                                     simplify_gen_binary (MULT, mode, adj, op1),
    5425                 :             :                                     mode);
    5426                 :           0 :           return simplify_gen_binary (PLUS, mode, mod, adj);
    5427                 :             :         }
    5428                 :             : 
    5429                 :       13728 :     case LSHIFT_EXPR:
    5430                 :       13728 :       return simplify_gen_binary (ASHIFT, mode, op0, op1);
    5431                 :             : 
    5432                 :       47083 :     case RSHIFT_EXPR:
    5433                 :       47083 :       if (unsignedp)
    5434                 :       44134 :         return simplify_gen_binary (LSHIFTRT, mode, op0, op1);
    5435                 :             :       else
    5436                 :        2949 :         return simplify_gen_binary (ASHIFTRT, mode, op0, op1);
    5437                 :             : 
    5438                 :           2 :     case LROTATE_EXPR:
    5439                 :           2 :       return simplify_gen_binary (ROTATE, mode, op0, op1);
    5440                 :             : 
    5441                 :         537 :     case RROTATE_EXPR:
    5442                 :         537 :       return simplify_gen_binary (ROTATERT, mode, op0, op1);
    5443                 :             : 
    5444                 :       14866 :     case MIN_EXPR:
    5445                 :       29732 :       return simplify_gen_binary (unsignedp ? UMIN : SMIN, mode, op0, op1);
    5446                 :             : 
    5447                 :       15742 :     case MAX_EXPR:
    5448                 :       31484 :       return simplify_gen_binary (unsignedp ? UMAX : SMAX, mode, op0, op1);
    5449                 :             : 
    5450                 :       79968 :     case BIT_AND_EXPR:
    5451                 :       79968 :     case TRUTH_AND_EXPR:
    5452                 :       79968 :       return simplify_gen_binary (AND, mode, op0, op1);
    5453                 :             : 
    5454                 :       39825 :     case BIT_IOR_EXPR:
    5455                 :       39825 :     case TRUTH_OR_EXPR:
    5456                 :       39825 :       return simplify_gen_binary (IOR, mode, op0, op1);
    5457                 :             : 
    5458                 :        8707 :     case BIT_XOR_EXPR:
    5459                 :        8707 :     case TRUTH_XOR_EXPR:
    5460                 :        8707 :       return simplify_gen_binary (XOR, mode, op0, op1);
    5461                 :             : 
    5462                 :           0 :     case TRUTH_ANDIF_EXPR:
    5463                 :           0 :       return gen_rtx_IF_THEN_ELSE (mode, op0, op1, const0_rtx);
    5464                 :             : 
    5465                 :           0 :     case TRUTH_ORIF_EXPR:
    5466                 :           0 :       return gen_rtx_IF_THEN_ELSE (mode, op0, const_true_rtx, op1);
    5467                 :             : 
    5468                 :           0 :     case TRUTH_NOT_EXPR:
    5469                 :           0 :       return simplify_gen_relational (EQ, mode, inner_mode, op0, const0_rtx);
    5470                 :             : 
    5471                 :        4807 :     case LT_EXPR:
    5472                 :        4807 :       return simplify_gen_relational (unsignedp ? LTU : LT, mode, inner_mode,
    5473                 :        4807 :                                       op0, op1);
    5474                 :             : 
    5475                 :        3733 :     case LE_EXPR:
    5476                 :        3733 :       return simplify_gen_relational (unsignedp ? LEU : LE, mode, inner_mode,
    5477                 :        3733 :                                       op0, op1);
    5478                 :             : 
    5479                 :        9943 :     case GT_EXPR:
    5480                 :        9943 :       return simplify_gen_relational (unsignedp ? GTU : GT, mode, inner_mode,
    5481                 :        9943 :                                       op0, op1);
    5482                 :             : 
    5483                 :        1226 :     case GE_EXPR:
    5484                 :        1226 :       return simplify_gen_relational (unsignedp ? GEU : GE, mode, inner_mode,
    5485                 :        1226 :                                       op0, op1);
    5486                 :             : 
    5487                 :       19875 :     case EQ_EXPR:
    5488                 :       19875 :       return simplify_gen_relational (EQ, mode, inner_mode, op0, op1);
    5489                 :             : 
    5490                 :       15645 :     case NE_EXPR:
    5491                 :       15645 :       return simplify_gen_relational (NE, mode, inner_mode, op0, op1);
    5492                 :             : 
    5493                 :           0 :     case UNORDERED_EXPR:
    5494                 :           0 :       return simplify_gen_relational (UNORDERED, mode, inner_mode, op0, op1);
    5495                 :             : 
    5496                 :           0 :     case ORDERED_EXPR:
    5497                 :           0 :       return simplify_gen_relational (ORDERED, mode, inner_mode, op0, op1);
    5498                 :             : 
    5499                 :           0 :     case UNLT_EXPR:
    5500                 :           0 :       return simplify_gen_relational (UNLT, mode, inner_mode, op0, op1);
    5501                 :             : 
    5502                 :           0 :     case UNLE_EXPR:
    5503                 :           0 :       return simplify_gen_relational (UNLE, mode, inner_mode, op0, op1);
    5504                 :             : 
    5505                 :           0 :     case UNGT_EXPR:
    5506                 :           0 :       return simplify_gen_relational (UNGT, mode, inner_mode, op0, op1);
    5507                 :             : 
    5508                 :           0 :     case UNGE_EXPR:
    5509                 :           0 :       return simplify_gen_relational (UNGE, mode, inner_mode, op0, op1);
    5510                 :             : 
    5511                 :           0 :     case UNEQ_EXPR:
    5512                 :           0 :       return simplify_gen_relational (UNEQ, mode, inner_mode, op0, op1);
    5513                 :             : 
    5514                 :           0 :     case LTGT_EXPR:
    5515                 :           0 :       return simplify_gen_relational (LTGT, mode, inner_mode, op0, op1);
    5516                 :             : 
    5517                 :        8726 :     case COND_EXPR:
    5518                 :        8726 :       return gen_rtx_IF_THEN_ELSE (mode, op0, op1, op2);
    5519                 :             : 
    5520                 :        9856 :     case COMPLEX_EXPR:
    5521                 :        9856 :       gcc_assert (COMPLEX_MODE_P (mode));
    5522                 :        9856 :       if (GET_MODE (op0) == VOIDmode)
    5523                 :           0 :         op0 = gen_rtx_CONST (GET_MODE_INNER (mode), op0);
    5524                 :        9856 :       if (GET_MODE (op1) == VOIDmode)
    5525                 :           0 :         op1 = gen_rtx_CONST (GET_MODE_INNER (mode), op1);
    5526                 :        9856 :       return gen_rtx_CONCAT (mode, op0, op1);
    5527                 :             : 
    5528                 :           0 :     case CONJ_EXPR:
    5529                 :           0 :       if (GET_CODE (op0) == CONCAT)
    5530                 :           0 :         return gen_rtx_CONCAT (mode, XEXP (op0, 0),
    5531                 :             :                                simplify_gen_unary (NEG, GET_MODE_INNER (mode),
    5532                 :             :                                                    XEXP (op0, 1),
    5533                 :             :                                                    GET_MODE_INNER (mode)));
    5534                 :             :       else
    5535                 :             :         {
    5536                 :           0 :           scalar_mode imode = GET_MODE_INNER (mode);
    5537                 :           0 :           rtx re, im;
    5538                 :             : 
    5539                 :           0 :           if (MEM_P (op0))
    5540                 :             :             {
    5541                 :           0 :               re = adjust_address_nv (op0, imode, 0);
    5542                 :           0 :               im = adjust_address_nv (op0, imode, GET_MODE_SIZE (imode));
    5543                 :             :             }
    5544                 :             :           else
    5545                 :             :             {
    5546                 :           0 :               scalar_int_mode ifmode;
    5547                 :           0 :               scalar_int_mode ihmode;
    5548                 :           0 :               rtx halfsize;
    5549                 :           0 :               if (!int_mode_for_mode (mode).exists (&ifmode)
    5550                 :           0 :                   || !int_mode_for_mode (imode).exists (&ihmode))
    5551                 :           0 :                 return NULL;
    5552                 :           0 :               halfsize = GEN_INT (GET_MODE_BITSIZE (ihmode));
    5553                 :           0 :               re = op0;
    5554                 :           0 :               if (mode != ifmode)
    5555                 :           0 :                 re = gen_rtx_SUBREG (ifmode, re, 0);
    5556                 :           0 :               re = gen_rtx_ZERO_EXTRACT (ihmode, re, halfsize, const0_rtx);
    5557                 :           0 :               if (imode != ihmode)
    5558                 :           0 :                 re = gen_rtx_SUBREG (imode, re, 0);
    5559                 :           0 :               im = copy_rtx (op0);
    5560                 :           0 :               if (mode != ifmode)
    5561                 :           0 :                 im = gen_rtx_SUBREG (ifmode, im, 0);
    5562                 :           0 :               im = gen_rtx_ZERO_EXTRACT (ihmode, im, halfsize, halfsize);
    5563                 :           0 :               if (imode != ihmode)
    5564                 :           0 :                 im = gen_rtx_SUBREG (imode, im, 0);
    5565                 :             :             }
    5566                 :           0 :           im = gen_rtx_NEG (imode, im);
    5567                 :           0 :           return gen_rtx_CONCAT (mode, re, im);
    5568                 :             :         }
    5569                 :             : 
    5570                 :     6841058 :     case ADDR_EXPR:
    5571                 :     6841058 :       op0 = expand_debug_expr (TREE_OPERAND (exp, 0));
    5572                 :     6841058 :       if (!op0 || !MEM_P (op0))
    5573                 :             :         {
    5574                 :     1818280 :           if ((TREE_CODE (TREE_OPERAND (exp, 0)) == VAR_DECL
    5575                 :      410214 :                || TREE_CODE (TREE_OPERAND (exp, 0)) == PARM_DECL
    5576                 :      357200 :                || TREE_CODE (TREE_OPERAND (exp, 0)) == RESULT_DECL)
    5577                 :     1871294 :               && (!TREE_ADDRESSABLE (TREE_OPERAND (exp, 0))
    5578                 :      139443 :                   || target_for_debug_bind (TREE_OPERAND (exp, 0))))
    5579                 :     1327731 :             return gen_rtx_DEBUG_IMPLICIT_PTR (mode, TREE_OPERAND (exp, 0));
    5580                 :             : 
    5581                 :      490549 :           if (handled_component_p (TREE_OPERAND (exp, 0)))
    5582                 :             :             {
    5583                 :      335912 :               poly_int64 bitoffset, bitsize, maxsize, byteoffset;
    5584                 :      335912 :               bool reverse;
    5585                 :      335912 :               tree decl
    5586                 :      335912 :                 = get_ref_base_and_extent (TREE_OPERAND (exp, 0), &bitoffset,
    5587                 :             :                                            &bitsize, &maxsize, &reverse);
    5588                 :      335912 :               if ((VAR_P (decl)
    5589                 :             :                    || TREE_CODE (decl) == PARM_DECL
    5590                 :             :                    || TREE_CODE (decl) == RESULT_DECL)
    5591                 :      306767 :                   && (!TREE_ADDRESSABLE (decl)
    5592                 :       23022 :                       || target_for_debug_bind (decl))
    5593                 :       63975 :                   && multiple_p (bitoffset, BITS_PER_UNIT, &byteoffset)
    5594                 :      283745 :                   && known_gt (bitsize, 0)
    5595                 :      271939 :                   && known_eq (bitsize, maxsize))
    5596                 :             :                 {
    5597                 :      271937 :                   rtx base = gen_rtx_DEBUG_IMPLICIT_PTR (mode, decl);
    5598                 :      271937 :                   return plus_constant (mode, base, byteoffset);
    5599                 :             :                 }
    5600                 :             :             }
    5601                 :             : 
    5602                 :      218612 :           if (TREE_CODE (TREE_OPERAND (exp, 0)) == MEM_REF
    5603                 :      218612 :               && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
    5604                 :             :                  == ADDR_EXPR)
    5605                 :             :             {
    5606                 :       10469 :               op0 = expand_debug_expr (TREE_OPERAND (TREE_OPERAND (exp, 0),
    5607                 :             :                                                      0));
    5608                 :       10469 :               if (op0 != NULL
    5609                 :        7235 :                   && (GET_CODE (op0) == DEBUG_IMPLICIT_PTR
    5610                 :           0 :                       || (GET_CODE (op0) == PLUS
    5611                 :           0 :                           && GET_CODE (XEXP (op0, 0)) == DEBUG_IMPLICIT_PTR
    5612                 :           0 :                           && CONST_INT_P (XEXP (op0, 1)))))
    5613                 :             :                 {
    5614                 :        7235 :                   op1 = expand_debug_expr (TREE_OPERAND (TREE_OPERAND (exp, 0),
    5615                 :             :                                                          1));
    5616                 :        7235 :                   poly_int64 offset;
    5617                 :       14470 :                   if (!op1 || !poly_int_rtx_p (op1, &offset))
    5618                 :             :                     return NULL;
    5619                 :             : 
    5620                 :        7235 :                   return plus_constant (mode, op0, offset);
    5621                 :             :                 }
    5622                 :             :             }
    5623                 :             : 
    5624                 :      211377 :           return NULL;
    5625                 :             :         }
    5626                 :             : 
    5627                 :     5022778 :       as = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)));
    5628                 :     5022778 :       addr_mode = SCALAR_INT_TYPE_MODE (TREE_TYPE (exp));
    5629                 :     5022778 :       op0 = convert_debug_memory_address (addr_mode, XEXP (op0, 0), as);
    5630                 :             : 
    5631                 :     5022778 :       return op0;
    5632                 :             : 
    5633                 :         926 :     case VECTOR_CST:
    5634                 :         926 :       {
    5635                 :         926 :         unsigned HOST_WIDE_INT i, nelts;
    5636                 :             : 
    5637                 :         926 :         if (!VECTOR_CST_NELTS (exp).is_constant (&nelts))
    5638                 :             :           return NULL;
    5639                 :             : 
    5640                 :         926 :         op0 = gen_rtx_CONCATN (mode, rtvec_alloc (nelts));
    5641                 :             : 
    5642                 :        4917 :         for (i = 0; i < nelts; ++i)
    5643                 :             :           {
    5644                 :        3991 :             op1 = expand_debug_expr (VECTOR_CST_ELT (exp, i));
    5645                 :        3991 :             if (!op1)
    5646                 :             :               return NULL;
    5647                 :        3991 :             XVECEXP (op0, 0, i) = op1;
    5648                 :             :           }
    5649                 :             : 
    5650                 :             :         return op0;
    5651                 :             :       }
    5652                 :             : 
    5653                 :         173 :     case CONSTRUCTOR:
    5654                 :         173 :       if (TREE_CLOBBER_P (exp))
    5655                 :             :         return NULL;
    5656                 :         173 :       else if (TREE_CODE (TREE_TYPE (exp)) == VECTOR_TYPE)
    5657                 :             :         {
    5658                 :         173 :           unsigned i;
    5659                 :         173 :           unsigned HOST_WIDE_INT nelts;
    5660                 :         173 :           tree val;
    5661                 :             : 
    5662                 :         173 :           if (!TYPE_VECTOR_SUBPARTS (TREE_TYPE (exp)).is_constant (&nelts))
    5663                 :             :             goto flag_unsupported;
    5664                 :             : 
    5665                 :         173 :           op0 = gen_rtx_CONCATN (mode, rtvec_alloc (nelts));
    5666                 :             : 
    5667                 :         896 :           FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), i, val)
    5668                 :             :             {
    5669                 :         734 :               op1 = expand_debug_expr (val);
    5670                 :         734 :               if (!op1)
    5671                 :    39629777 :                 return NULL;
    5672                 :         723 :               XVECEXP (op0, 0, i) = op1;
    5673                 :             :             }
    5674                 :             : 
    5675                 :         162 :           if (i < nelts)
    5676                 :             :             {
    5677                 :          23 :               op1 = expand_debug_expr
    5678                 :          23 :                 (build_zero_cst (TREE_TYPE (TREE_TYPE (exp))));
    5679                 :             : 
    5680                 :          23 :               if (!op1)
    5681                 :             :                 return NULL;
    5682                 :             : 
    5683                 :         166 :               for (; i < nelts; i++)
    5684                 :         143 :                 XVECEXP (op0, 0, i) = op1;
    5685                 :             :             }
    5686                 :             : 
    5687                 :         162 :           return op0;
    5688                 :             :         }
    5689                 :             :       else
    5690                 :           0 :         goto flag_unsupported;
    5691                 :             : 
    5692                 :             :     case CALL_EXPR:
    5693                 :             :       /* ??? Maybe handle some builtins?  */
    5694                 :             :       return NULL;
    5695                 :             : 
    5696                 :     8837624 :     case SSA_NAME:
    5697                 :     8837624 :       {
    5698                 :     8837624 :         gimple *g = get_gimple_for_ssa_name (exp);
    5699                 :     8837624 :         if (g)
    5700                 :             :           {
    5701                 :     1274244 :             tree t = NULL_TREE;
    5702                 :     1274244 :             if (deep_ter_debug_map)
    5703                 :             :               {
    5704                 :       46486 :                 tree *slot = deep_ter_debug_map->get (exp);
    5705                 :       46486 :                 if (slot)
    5706                 :        7432 :                   t = *slot;
    5707                 :             :               }
    5708                 :        7432 :             if (t == NULL_TREE)
    5709                 :             :               {
    5710                 :     1269621 :                 if (is_gimple_assign (g))
    5711                 :     1269413 :                   t = gimple_assign_rhs_to_tree (g);
    5712                 :             :                 else
    5713                 :             :                   /* expand_debug_expr doesn't handle CALL_EXPR right now.  */
    5714                 :             :                   return NULL;
    5715                 :             :               }
    5716                 :     1274036 :             op0 = expand_debug_expr (t);
    5717                 :     1274036 :             if (!op0)
    5718                 :             :               return NULL;
    5719                 :             :           }
    5720                 :             :         else
    5721                 :             :           {
    5722                 :             :             /* If this is a reference to an incoming value of
    5723                 :             :                parameter that is never used in the code or where the
    5724                 :             :                incoming value is never used in the code, use
    5725                 :             :                PARM_DECL's DECL_RTL if set.  */
    5726                 :     7563380 :             if (SSA_NAME_IS_DEFAULT_DEF (exp)
    5727                 :     1277035 :                 && SSA_NAME_VAR (exp)
    5728                 :     1277035 :                 && TREE_CODE (SSA_NAME_VAR (exp)) == PARM_DECL
    5729                 :     8784275 :                 && has_zero_uses (exp))
    5730                 :             :               {
    5731                 :       18008 :                 op0 = expand_debug_parm_decl (SSA_NAME_VAR (exp));
    5732                 :       18008 :                 if (op0)
    5733                 :       17918 :                   goto adjust_mode;
    5734                 :          90 :                 op0 = expand_debug_expr (SSA_NAME_VAR (exp));
    5735                 :          90 :                 if (op0)
    5736                 :          90 :                   goto adjust_mode;
    5737                 :             :               }
    5738                 :             : 
    5739                 :     7545372 :             int part = var_to_partition (SA.map, exp);
    5740                 :             : 
    5741                 :     7545372 :             if (part == NO_PARTITION)
    5742                 :             :               return NULL;
    5743                 :             : 
    5744                 :     7540293 :             gcc_assert (part >= 0 && (unsigned)part < SA.map->num_partitions);
    5745                 :             : 
    5746                 :     7540293 :             op0 = copy_rtx (SA.partition_to_pseudo[part]);
    5747                 :             :           }
    5748                 :     8811409 :         goto adjust_mode;
    5749                 :             :       }
    5750                 :             : 
    5751                 :             :     case ERROR_MARK:
    5752                 :             :       return NULL;
    5753                 :             : 
    5754                 :             :     /* Vector stuff.  For most of the codes we don't have rtl codes.  */
    5755                 :             :     case REALIGN_LOAD_EXPR:
    5756                 :             :     case VEC_COND_EXPR:
    5757                 :             :     case VEC_PACK_FIX_TRUNC_EXPR:
    5758                 :             :     case VEC_PACK_FLOAT_EXPR:
    5759                 :             :     case VEC_PACK_SAT_EXPR:
    5760                 :             :     case VEC_PACK_TRUNC_EXPR:
    5761                 :             :     case VEC_UNPACK_FIX_TRUNC_HI_EXPR:
    5762                 :             :     case VEC_UNPACK_FIX_TRUNC_LO_EXPR:
    5763                 :             :     case VEC_UNPACK_FLOAT_HI_EXPR:
    5764                 :             :     case VEC_UNPACK_FLOAT_LO_EXPR:
    5765                 :             :     case VEC_UNPACK_HI_EXPR:
    5766                 :             :     case VEC_UNPACK_LO_EXPR:
    5767                 :             :     case VEC_WIDEN_MULT_HI_EXPR:
    5768                 :             :     case VEC_WIDEN_MULT_LO_EXPR:
    5769                 :             :     case VEC_WIDEN_MULT_EVEN_EXPR:
    5770                 :             :     case VEC_WIDEN_MULT_ODD_EXPR:
    5771                 :             :     case VEC_WIDEN_LSHIFT_HI_EXPR:
    5772                 :             :     case VEC_WIDEN_LSHIFT_LO_EXPR:
    5773                 :             :     case VEC_PERM_EXPR:
    5774                 :             :     case VEC_DUPLICATE_EXPR:
    5775                 :             :     case VEC_SERIES_EXPR:
    5776                 :             :     case SAD_EXPR:
    5777                 :             :       return NULL;
    5778                 :             : 
    5779                 :             :     /* Misc codes.  */
    5780                 :             :     case ADDR_SPACE_CONVERT_EXPR:
    5781                 :             :     case FIXED_CONVERT_EXPR:
    5782                 :             :     case OBJ_TYPE_REF:
    5783                 :             :     case WITH_SIZE_EXPR:
    5784                 :             :     case BIT_INSERT_EXPR:
    5785                 :             :       return NULL;
    5786                 :             : 
    5787                 :           0 :     case DOT_PROD_EXPR:
    5788                 :           0 :       if (SCALAR_INT_MODE_P (GET_MODE (op0))
    5789                 :           0 :           && SCALAR_INT_MODE_P (mode))
    5790                 :             :         {
    5791                 :           0 :           op0
    5792                 :           0 :             = simplify_gen_unary (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp,
    5793                 :             :                                                                           0)))
    5794                 :             :                                   ? ZERO_EXTEND : SIGN_EXTEND, mode, op0,
    5795                 :             :                                   inner_mode);
    5796                 :           0 :           op1
    5797                 :           0 :             = simplify_gen_unary (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp,
    5798                 :             :                                                                           1)))
    5799                 :             :                                   ? ZERO_EXTEND : SIGN_EXTEND, mode, op1,
    5800                 :             :                                   inner_mode);
    5801                 :           0 :           op0 = simplify_gen_binary (MULT, mode, op0, op1);
    5802                 :           0 :           return simplify_gen_binary (PLUS, mode, op0, op2);
    5803                 :             :         }
    5804                 :             :       return NULL;
    5805                 :             : 
    5806                 :        4079 :     case WIDEN_MULT_EXPR:
    5807                 :        4079 :     case WIDEN_MULT_PLUS_EXPR:
    5808                 :        4079 :     case WIDEN_MULT_MINUS_EXPR:
    5809                 :        4079 :       if (SCALAR_INT_MODE_P (GET_MODE (op0))
    5810                 :        4079 :           && SCALAR_INT_MODE_P (mode))
    5811                 :             :         {
    5812                 :        4079 :           inner_mode = GET_MODE (op0);
    5813                 :        4079 :           if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0))))
    5814                 :        3464 :             op0 = simplify_gen_unary (ZERO_EXTEND, mode, op0, inner_mode);
    5815                 :             :           else
    5816                 :         615 :             op0 = simplify_gen_unary (SIGN_EXTEND, mode, op0, inner_mode);
    5817                 :        4079 :           if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 1))))
    5818                 :        3464 :             op1 = simplify_gen_unary (ZERO_EXTEND, mode, op1, inner_mode);
    5819                 :             :           else
    5820                 :         615 :             op1 = simplify_gen_unary (SIGN_EXTEND, mode, op1, inner_mode);
    5821                 :        4079 :           op0 = simplify_gen_binary (MULT, mode, op0, op1);
    5822                 :        4079 :           if (TREE_CODE (exp) == WIDEN_MULT_EXPR)
    5823                 :             :             return op0;
    5824                 :           0 :           else if (TREE_CODE (exp) == WIDEN_MULT_PLUS_EXPR)
    5825                 :           0 :             return simplify_gen_binary (PLUS, mode, op0, op2);
    5826                 :             :           else
    5827                 :           0 :             return simplify_gen_binary (MINUS, mode, op2, op0);
    5828                 :             :         }
    5829                 :             :       return NULL;
    5830                 :             : 
    5831                 :             :     case MULT_HIGHPART_EXPR:
    5832                 :             :       /* ??? Similar to the above.  */
    5833                 :             :       return NULL;
    5834                 :             : 
    5835                 :           0 :     case WIDEN_SUM_EXPR:
    5836                 :           0 :     case WIDEN_LSHIFT_EXPR:
    5837                 :           0 :       if (SCALAR_INT_MODE_P (GET_MODE (op0))
    5838                 :           0 :           && SCALAR_INT_MODE_P (mode))
    5839                 :             :         {
    5840                 :           0 :           op0
    5841                 :           0 :             = simplify_gen_unary (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp,
    5842                 :             :                                                                           0)))
    5843                 :             :                                   ? ZERO_EXTEND : SIGN_EXTEND, mode, op0,
    5844                 :             :                                   inner_mode);
    5845                 :           0 :           return simplify_gen_binary (TREE_CODE (exp) == WIDEN_LSHIFT_EXPR
    5846                 :           0 :                                       ? ASHIFT : PLUS, mode, op0, op1);
    5847                 :             :         }
    5848                 :             :       return NULL;
    5849                 :             : 
    5850                 :           0 :     default:
    5851                 :           0 :     flag_unsupported:
    5852                 :           0 :       if (flag_checking)
    5853                 :             :         {
    5854                 :           0 :           debug_tree (exp);
    5855                 :           0 :           gcc_unreachable ();
    5856                 :             :         }
    5857                 :             :       return NULL;
    5858                 :             :     }
    5859                 :             : }
    5860                 :             : 
    5861                 :             : /* Return an RTX equivalent to the source bind value of the tree expression
    5862                 :             :    EXP.  */
    5863                 :             : 
    5864                 :             : static rtx
    5865                 :      147023 : expand_debug_source_expr (tree exp)
    5866                 :             : {
    5867                 :      276782 :   rtx op0 = NULL_RTX;
    5868                 :      276782 :   machine_mode mode = VOIDmode, inner_mode;
    5869                 :             : 
    5870                 :      276782 :   switch (TREE_CODE (exp))
    5871                 :             :     {
    5872                 :      129759 :     case VAR_DECL:
    5873                 :      129759 :       if (DECL_ABSTRACT_ORIGIN (exp))
    5874                 :      129759 :         return expand_debug_source_expr (DECL_ABSTRACT_ORIGIN (exp));
    5875                 :             :       break;
    5876                 :      146502 :     case PARM_DECL:
    5877                 :      146502 :       {
    5878                 :      146502 :         mode = DECL_MODE (exp);
    5879                 :      146502 :         op0 = expand_debug_parm_decl (exp);
    5880                 :      146502 :         if (op0)
    5881                 :             :            break;
    5882                 :             :         /* See if this isn't an argument that has been completely
    5883                 :             :            optimized out.  */
    5884                 :      145873 :         if (!DECL_RTL_SET_P (exp)
    5885                 :      145859 :             && !DECL_INCOMING_RTL (exp)
    5886                 :      291732 :             && DECL_ABSTRACT_ORIGIN (current_function_decl))
    5887                 :             :           {
    5888                 :       43096 :             tree aexp = DECL_ORIGIN (exp);
    5889                 :       43096 :             if (DECL_CONTEXT (aexp)
    5890                 :       43096 :                 == DECL_ABSTRACT_ORIGIN (current_function_decl))
    5891                 :             :               {
    5892                 :       19641 :                 vec<tree, va_gc> **debug_args;
    5893                 :       19641 :                 unsigned int ix;
    5894                 :       19641 :                 tree ddecl;
    5895                 :       19641 :                 debug_args = decl_debug_args_lookup (current_function_decl);
    5896                 :       19641 :                 if (debug_args != NULL)
    5897                 :             :                   {
    5898                 :       24399 :                     for (ix = 0; vec_safe_iterate (*debug_args, ix, &ddecl);
    5899                 :        4762 :                          ix += 2)
    5900                 :       24383 :                       if (ddecl == aexp)
    5901                 :       19621 :                         return gen_rtx_DEBUG_PARAMETER_REF (mode, aexp);
    5902                 :             :                   }
    5903                 :             :               }
    5904                 :             :           }
    5905                 :             :         break;
    5906                 :             :       }
    5907                 :             :     default:
    5908                 :             :       break;
    5909                 :             :     }
    5910                 :             : 
    5911                 :         629 :   if (op0 == NULL_RTX)
    5912                 :      126773 :     return NULL_RTX;
    5913                 :             : 
    5914                 :         629 :   inner_mode = GET_MODE (op0);
    5915                 :         629 :   if (mode == inner_mode)
    5916                 :             :     return op0;
    5917                 :             : 
    5918                 :          21 :   if (FLOAT_MODE_P (mode) && FLOAT_MODE_P (inner_mode))
    5919                 :             :     {
    5920                 :           7 :       if (GET_MODE_UNIT_BITSIZE (mode)
    5921                 :          14 :           == GET_MODE_UNIT_BITSIZE (inner_mode))
    5922                 :           0 :         op0 = simplify_gen_subreg (mode, op0, inner_mode, 0);
    5923                 :           7 :       else if (GET_MODE_UNIT_BITSIZE (mode)
    5924                 :          14 :                < GET_MODE_UNIT_BITSIZE (inner_mode))
    5925                 :           7 :         op0 = simplify_gen_unary (FLOAT_TRUNCATE, mode, op0, inner_mode);
    5926                 :             :       else
    5927                 :           0 :         op0 = simplify_gen_unary (FLOAT_EXTEND, mode, op0, inner_mode);
    5928                 :             :     }
    5929                 :          14 :   else if (FLOAT_MODE_P (mode))
    5930                 :           0 :     gcc_unreachable ();
    5931                 :          14 :   else if (FLOAT_MODE_P (inner_mode))
    5932                 :             :     {
    5933                 :           0 :       if (TYPE_UNSIGNED (TREE_TYPE (exp)))
    5934                 :           0 :         op0 = simplify_gen_unary (UNSIGNED_FIX, mode, op0, inner_mode);
    5935                 :             :       else
    5936                 :           0 :         op0 = simplify_gen_unary (FIX, mode, op0, inner_mode);
    5937                 :             :     }
    5938                 :          28 :   else if (GET_MODE_UNIT_PRECISION (mode)
    5939                 :          14 :            == GET_MODE_UNIT_PRECISION (inner_mode))
    5940                 :           0 :     op0 = lowpart_subreg (mode, op0, inner_mode);
    5941                 :          28 :   else if (GET_MODE_UNIT_PRECISION (mode)
    5942                 :          14 :            < GET_MODE_UNIT_PRECISION (inner_mode))
    5943                 :          14 :     op0 = simplify_gen_unary (TRUNCATE, mode, op0, inner_mode);
    5944                 :           0 :   else if (TYPE_UNSIGNED (TREE_TYPE (exp)))
    5945                 :           0 :     op0 = simplify_gen_unary (ZERO_EXTEND, mode, op0, inner_mode);
    5946                 :             :   else
    5947                 :           0 :     op0 = simplify_gen_unary (SIGN_EXTEND, mode, op0, inner_mode);
    5948                 :             : 
    5949                 :             :   return op0;
    5950                 :             : }
    5951                 :             : 
    5952                 :             : /* Ensure INSN_VAR_LOCATION_LOC (insn) doesn't have unbound complexity.
    5953                 :             :    Allow 4 levels of rtl nesting for most rtl codes, and if we see anything
    5954                 :             :    deeper than that, create DEBUG_EXPRs and emit DEBUG_INSNs before INSN.  */
    5955                 :             : 
    5956                 :             : static void
    5957                 :    48223247 : avoid_complex_debug_insns (rtx_insn *insn, rtx *exp_p, int depth)
    5958                 :             : {
    5959                 :    48223247 :   rtx exp = *exp_p;
    5960                 :             : 
    5961                 :    48223247 :   if (exp == NULL_RTX)
    5962                 :             :     return;
    5963                 :             : 
    5964                 :    48223247 :   if ((OBJECT_P (exp) && !MEM_P (exp)) || GET_CODE (exp) == CLOBBER)
    5965                 :             :     return;
    5966                 :             : 
    5967                 :     6465099 :   if (depth == 4)
    5968                 :             :     {
    5969                 :             :       /* Create DEBUG_EXPR (and DEBUG_EXPR_DECL).  */
    5970                 :       21751 :       rtx dval = make_debug_expr_from_rtl (exp);
    5971                 :             : 
    5972                 :             :       /* Emit a debug bind insn before INSN.  */
    5973                 :       21751 :       rtx bind = gen_rtx_VAR_LOCATION (GET_MODE (exp),
    5974                 :             :                                        DEBUG_EXPR_TREE_DECL (dval), exp,
    5975                 :             :                                        VAR_INIT_STATUS_INITIALIZED);
    5976                 :             : 
    5977                 :       21751 :       emit_debug_insn_before (bind, insn);
    5978                 :       21751 :       *exp_p = dval;
    5979                 :       21751 :       return;
    5980                 :             :     }
    5981                 :             : 
    5982                 :     6443348 :   const char *format_ptr = GET_RTX_FORMAT (GET_CODE (exp));
    5983                 :     6443348 :   int i, j;
    5984                 :    19221062 :   for (i = 0; i < GET_RTX_LENGTH (GET_CODE (exp)); i++)
    5985                 :    12777714 :     switch (*format_ptr++)
    5986                 :             :       {
    5987                 :    11719752 :       case 'e':
    5988                 :    11719752 :         avoid_complex_debug_insns (insn, &XEXP (exp, i), depth + 1);
    5989                 :    11719752 :         break;
    5990                 :             : 
    5991                 :             :       case 'E':
    5992                 :             :       case 'V':
    5993                 :           0 :         for (j = 0; j < XVECLEN (exp, i); j++)
    5994                 :           0 :           avoid_complex_debug_insns (insn, &XVECEXP (exp, i, j), depth + 1);
    5995                 :             :         break;
    5996                 :             : 
    5997                 :             :       default:
    5998                 :             :         break;
    5999                 :             :       }
    6000                 :             : }
    6001                 :             : 
    6002                 :             : /* Expand the _LOCs in debug insns.  We run this after expanding all
    6003                 :             :    regular insns, so that any variables referenced in the function
    6004                 :             :    will have their DECL_RTLs set.  */
    6005                 :             : 
    6006                 :             : static void
    6007                 :      499960 : expand_debug_locations (void)
    6008                 :             : {
    6009                 :      499960 :   rtx_insn *insn;
    6010                 :      499960 :   rtx_insn *last = get_last_insn ();
    6011                 :      499960 :   int save_strict_alias = flag_strict_aliasing;
    6012                 :             : 
    6013                 :             :   /* New alias sets while setting up memory attributes cause
    6014                 :             :      -fcompare-debug failures, even though it doesn't bring about any
    6015                 :             :      codegen changes.  */
    6016                 :      499960 :   flag_strict_aliasing = 0;
    6017                 :             : 
    6018                 :   103629642 :   for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
    6019                 :   103129682 :     if (DEBUG_BIND_INSN_P (insn))
    6020                 :             :       {
    6021                 :    36481744 :         tree value = (tree)INSN_VAR_LOCATION_LOC (insn);
    6022                 :    36481744 :         rtx val;
    6023                 :    36481744 :         rtx_insn *prev_insn, *insn2;
    6024                 :    36481744 :         machine_mode mode;
    6025                 :             : 
    6026                 :    36481744 :         if (value == NULL_TREE)
    6027                 :             :           val = NULL_RTX;
    6028                 :             :         else
    6029                 :             :           {
    6030                 :    20587205 :             if (INSN_VAR_LOCATION_STATUS (insn)
    6031                 :             :                 == VAR_INIT_STATUS_UNINITIALIZED)
    6032                 :      147023 :               val = expand_debug_source_expr (value);
    6033                 :             :             /* The avoid_deep_ter_for_debug function inserts
    6034                 :             :                debug bind stmts after SSA_NAME definition, with the
    6035                 :             :                SSA_NAME as the whole bind location.  Disable temporarily
    6036                 :             :                expansion of that SSA_NAME into the DEBUG_EXPR_DECL
    6037                 :             :                being defined in this DEBUG_INSN.  */
    6038                 :    20440182 :             else if (deep_ter_debug_map && TREE_CODE (value) == SSA_NAME)
    6039                 :             :               {
    6040                 :       49014 :                 tree *slot = deep_ter_debug_map->get (value);
    6041                 :       49014 :                 if (slot)
    6042                 :             :                   {
    6043                 :        3179 :                     if (*slot == INSN_VAR_LOCATION_DECL (insn))
    6044                 :        2809 :                       *slot = NULL_TREE;
    6045                 :             :                     else
    6046                 :             :                       slot = NULL;
    6047                 :             :                   }
    6048                 :       49014 :                 val = expand_debug_expr (value);
    6049                 :       49014 :                 if (slot)
    6050                 :        2809 :                   *slot = INSN_VAR_LOCATION_DECL (insn);
    6051                 :             :               }
    6052                 :             :             else
    6053                 :    20391168 :               val = expand_debug_expr (value);
    6054                 :    20587205 :             gcc_assert (last == get_last_insn ());
    6055                 :             :           }
    6056                 :             : 
    6057                 :    20587205 :         if (!val)
    6058                 :    16279405 :           val = gen_rtx_UNKNOWN_VAR_LOC ();
    6059                 :             :         else
    6060                 :             :           {
    6061                 :    20202339 :             mode = GET_MODE (INSN_VAR_LOCATION (insn));
    6062                 :             : 
    6063                 :    20202339 :             gcc_assert (mode == GET_MODE (val)
    6064                 :             :                         || (GET_MODE (val) == VOIDmode
    6065                 :             :                             && (CONST_SCALAR_INT_P (val)
    6066                 :             :                                 || GET_CODE (val) == CONST_FIXED
    6067                 :             :                                 || GET_CODE (val) == LABEL_REF)));
    6068                 :             :           }
    6069                 :             : 
    6070                 :    36481744 :         INSN_VAR_LOCATION_LOC (insn) = val;
    6071                 :    36481744 :         prev_insn = PREV_INSN (insn);
    6072                 :    72985239 :         for (insn2 = insn; insn2 != prev_insn; insn2 = PREV_INSN (insn2))
    6073                 :    36503495 :           avoid_complex_debug_insns (insn2, &INSN_VAR_LOCATION_LOC (insn2), 0);
    6074                 :             :       }
    6075                 :             : 
    6076                 :      499960 :   flag_strict_aliasing = save_strict_alias;
    6077                 :      499960 : }
    6078                 :             : 
    6079                 :             : /* Performs swapping operands of commutative operations to expand
    6080                 :             :    the expensive one first.  */
    6081                 :             : 
    6082                 :             : static void
    6083                 :     9292726 : reorder_operands (basic_block bb)
    6084                 :             : {
    6085                 :     9292726 :   unsigned int *lattice;  /* Hold cost of each statement.  */
    6086                 :     9292726 :   unsigned int i = 0, n = 0;
    6087                 :     9292726 :   gimple_stmt_iterator gsi;
    6088                 :     9292726 :   gimple_seq stmts;
    6089                 :     9292726 :   gimple *stmt;
    6090                 :     9292726 :   bool swap;
    6091                 :     9292726 :   tree op0, op1;
    6092                 :     9292726 :   ssa_op_iter iter;
    6093                 :     9292726 :   use_operand_p use_p;
    6094                 :     9292726 :   gimple *def0, *def1;
    6095                 :             : 
    6096                 :             :   /* Compute cost of each statement using estimate_num_insns.  */
    6097                 :     9292726 :   stmts = bb_seq (bb);
    6098                 :    91382140 :   for (gsi = gsi_start (stmts); !gsi_end_p (gsi); gsi_next (&gsi))
    6099                 :             :     {
    6100                 :    82089414 :       stmt = gsi_stmt (gsi);
    6101                 :    82089414 :       if (!is_gimple_debug (stmt))
    6102                 :    33877627 :         gimple_set_uid (stmt, n++);
    6103                 :             :     }
    6104                 :     9292726 :   lattice = XNEWVEC (unsigned int, n);
    6105                 :    91382140 :   for (gsi = gsi_start (stmts); !gsi_end_p (gsi); gsi_next (&gsi))
    6106                 :             :     {
    6107                 :    82089414 :       unsigned cost;
    6108                 :    82089414 :       stmt = gsi_stmt (gsi);
    6109                 :    82089414 :       if (is_gimple_debug (stmt))
    6110                 :    48211787 :         continue;
    6111                 :    33877627 :       cost = estimate_num_insns (stmt, &eni_size_weights);
    6112                 :    33877627 :       lattice[i] = cost;
    6113                 :    64142124 :       FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE)
    6114                 :             :         {
    6115                 :    30264497 :           tree use = USE_FROM_PTR (use_p);
    6116                 :    30264497 :           gimple *def_stmt;
    6117                 :    30264497 :           if (TREE_CODE (use) != SSA_NAME)
    6118                 :           0 :             continue;
    6119                 :    30264497 :           def_stmt = get_gimple_for_ssa_name (use);
    6120                 :    30264497 :           if (!def_stmt)
    6121                 :    21453750 :             continue;
    6122                 :     8810747 :           lattice[i] += lattice[gimple_uid (def_stmt)];
    6123                 :             :         }
    6124                 :    33877627 :       i++;
    6125                 :    33877627 :       if (!is_gimple_assign (stmt)
    6126                 :    33877627 :           || !commutative_tree_code (gimple_assign_rhs_code (stmt)))
    6127                 :    29818248 :         continue;
    6128                 :     4059379 :       op0 = gimple_op (stmt, 1);
    6129                 :     4059379 :       op1 = gimple_op (stmt, 2);
    6130                 :     4059379 :       if (TREE_CODE (op0) != SSA_NAME
    6131                 :     4059164 :           || TREE_CODE (op1) != SSA_NAME)
    6132                 :     2590610 :         continue;
    6133                 :             :       /* Swap operands if the second one is more expensive.  */
    6134                 :     1468769 :       def0 = get_gimple_for_ssa_name (op0);
    6135                 :     1468769 :       def1 = get_gimple_for_ssa_name (op1);
    6136                 :     1468769 :       if (!def1)
    6137                 :      807693 :         continue;
    6138                 :      661076 :       swap = false;
    6139                 :      661076 :       if (!def0 || lattice[gimple_uid (def1)] > lattice[gimple_uid (def0)])
    6140                 :      315931 :         swap = true;
    6141                 :      315931 :       if (swap)
    6142                 :             :         {
    6143                 :      315931 :           if (dump_file && (dump_flags & TDF_DETAILS))
    6144                 :             :             {
    6145                 :           2 :               fprintf (dump_file, "Swap operands in stmt:\n");
    6146                 :           2 :               print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
    6147                 :           2 :               fprintf (dump_file, "Cost left opnd=%d, right opnd=%d\n",
    6148                 :           1 :                        def0 ? lattice[gimple_uid (def0)] : 0,
    6149                 :           2 :                        lattice[gimple_uid (def1)]);
    6150                 :             :             }
    6151                 :      315931 :           swap_ssa_operands (stmt, gimple_assign_rhs1_ptr (stmt),
    6152                 :             :                              gimple_assign_rhs2_ptr (stmt));
    6153                 :             :         }
    6154                 :             :     }
    6155                 :     9292726 :   XDELETE (lattice);
    6156                 :     9292726 : }
    6157                 :             : 
    6158                 :             : /* Expand basic block BB from GIMPLE trees to RTL.  */
    6159                 :             : 
    6160                 :             : static basic_block
    6161                 :    12569572 : expand_gimple_basic_block (basic_block bb, rtx_insn *asan_epilog_seq)
    6162                 :             : {
    6163                 :    12569572 :   gimple_stmt_iterator gsi;
    6164                 :    12569572 :   gimple *stmt = NULL;
    6165                 :    12569572 :   rtx_note *note = NULL;
    6166                 :    12569572 :   rtx_insn *last;
    6167                 :    12569572 :   edge e;
    6168                 :    12569572 :   edge_iterator ei;
    6169                 :    12569572 :   bool nondebug_stmt_seen = false;
    6170                 :             : 
    6171                 :    12569572 :   if (dump_file)
    6172                 :         769 :     fprintf (dump_file, "\n;; Generating RTL for gimple basic block %d\n",
    6173                 :             :              bb->index);
    6174                 :             : 
    6175                 :             :   /* Note that since we are now transitioning from GIMPLE to RTL, we
    6176                 :             :      cannot use the gsi_*_bb() routines because they expect the basic
    6177                 :             :      block to be in GIMPLE, instead of RTL.  Therefore, we need to
    6178                 :             :      access the BB sequence directly.  */
    6179                 :    12569572 :   if (optimize)
    6180                 :     9292726 :     reorder_operands (bb);
    6181                 :    12569572 :   rtl_profile_for_bb (bb);
    6182                 :             : 
    6183                 :             :   /* Remove the RETURN_EXPR if we may fall though to the exit
    6184                 :             :      instead.  */
    6185                 :    12569572 :   gsi = gsi_last_bb (bb);
    6186                 :    12569572 :   if (!gsi_end_p (gsi) && gimple_code (gsi_stmt (gsi)) == GIMPLE_RETURN)
    6187                 :             :     {
    6188                 :     1429194 :       greturn *ret_stmt = as_a <greturn *> (gsi_stmt (gsi));
    6189                 :             : 
    6190                 :     1429194 :       gcc_assert (single_succ_p (bb));
    6191                 :     1429194 :       gcc_assert (single_succ (bb) == EXIT_BLOCK_PTR_FOR_FN (cfun));
    6192                 :             : 
    6193                 :     1429194 :       if (bb->next_bb == EXIT_BLOCK_PTR_FOR_FN (cfun)
    6194                 :     1429194 :           && !gimple_return_retval (ret_stmt))
    6195                 :             :         {
    6196                 :      594387 :           gsi_remove (&gsi, false);
    6197                 :      594387 :           single_succ_edge (bb)->flags |= EDGE_FALLTHRU;
    6198                 :             :         }
    6199                 :             :     }
    6200                 :             : 
    6201                 :    12569572 :   gsi = gsi_start_bb (bb);
    6202                 :    12569572 :   if (!gsi_end_p (gsi))
    6203                 :             :     {
    6204                 :    12019930 :       stmt = gsi_stmt (gsi);
    6205                 :    12019930 :       if (gimple_code (stmt) != GIMPLE_LABEL)
    6206                 :    11948867 :         stmt = NULL;
    6207                 :             :     }
    6208                 :             : 
    6209                 :    12569572 :   rtx_code_label **elt = lab_rtx_for_bb->get (bb);
    6210                 :    12569572 :   if ((unsigned) bb->index >= head_end_for_bb.length ())
    6211                 :    12427896 :     head_end_for_bb.safe_grow_cleared (bb->index + 1);
    6212                 :             : 
    6213                 :    12569572 :   if (stmt || elt)
    6214                 :             :     {
    6215                 :     5243670 :       gcc_checking_assert (!note);
    6216                 :     5243670 :       last = get_last_insn ();
    6217                 :             : 
    6218                 :     5243670 :       if (stmt)
    6219                 :             :         {
    6220                 :      620705 :           expand_gimple_stmt (stmt);
    6221                 :      620705 :           gsi_next (&gsi);
    6222                 :             :         }
    6223                 :             : 
    6224                 :     5243670 :       if (elt)
    6225                 :     4622965 :         emit_label (*elt);
    6226                 :             : 
    6227                 :     5243670 :       head_end_for_bb[bb->index].first = NEXT_INSN (last);
    6228                 :     5243670 :       if (NOTE_P (head_end_for_bb[bb->index].first))
    6229                 :           0 :         head_end_for_bb[bb->index].first
    6230                 :           0 :           = NEXT_INSN (head_end_for_bb[bb->index].first);
    6231                 :     5243670 :       gcc_assert (LABEL_P (head_end_for_bb[bb->index].first));
    6232                 :    10487340 :       note = emit_note_after (NOTE_INSN_BASIC_BLOCK,
    6233                 :     5243670 :                               head_end_for_bb[bb->index].first);
    6234                 :             : 
    6235                 :     5243670 :       maybe_dump_rtl_for_gimple_stmt (stmt, last);
    6236                 :             :     }
    6237                 :             :   else
    6238                 :     7325902 :     head_end_for_bb[bb->index].first = note = emit_note (NOTE_INSN_BASIC_BLOCK);
    6239                 :             : 
    6240                 :    12569572 :   if (note)
    6241                 :    12569572 :     NOTE_BASIC_BLOCK (note) = bb;
    6242                 :             : 
    6243                 :    65518711 :   for (; !gsi_end_p (gsi); gsi_next (&gsi))
    6244                 :             :     {
    6245                 :    53560657 :       basic_block new_bb;
    6246                 :             : 
    6247                 :    53560657 :       stmt = gsi_stmt (gsi);
    6248                 :    53560657 :       if (!is_gimple_debug (stmt))
    6249                 :    45211954 :         nondebug_stmt_seen = true;
    6250                 :             : 
    6251                 :             :       /* If this statement is a non-debug one, and we generate debug
    6252                 :             :          insns, then this one might be the last real use of a TERed
    6253                 :             :          SSA_NAME, but where there are still some debug uses further
    6254                 :             :          down.  Expanding the current SSA name in such further debug
    6255                 :             :          uses by their RHS might lead to wrong debug info, as coalescing
    6256                 :             :          might make the operands of such RHS be placed into the same
    6257                 :             :          pseudo as something else.  Like so:
    6258                 :             :            a_1 = a_0 + 1;   // Assume a_1 is TERed and a_0 is dead
    6259                 :             :            use(a_1);
    6260                 :             :            a_2 = ...
    6261                 :             :            #DEBUG ... => a_1
    6262                 :             :          As a_0 and a_2 don't overlap in lifetime, assume they are coalesced.
    6263                 :             :          If we now would expand a_1 by it's RHS (a_0 + 1) in the debug use,
    6264                 :             :          the write to a_2 would actually have clobbered the place which
    6265                 :             :          formerly held a_0.
    6266                 :             : 
    6267                 :             :          So, instead of that, we recognize the situation, and generate
    6268                 :             :          debug temporaries at the last real use of TERed SSA names:
    6269                 :             :            a_1 = a_0 + 1;
    6270                 :             :            #DEBUG #D1 => a_1
    6271                 :             :            use(a_1);
    6272                 :             :            a_2 = ...
    6273                 :             :            #DEBUG ... => #D1
    6274                 :             :          */
    6275                 :    53560657 :       if (MAY_HAVE_DEBUG_BIND_INSNS
    6276                 :    29540151 :           && SA.values
    6277                 :    81888513 :           && !is_gimple_debug (stmt))
    6278                 :             :         {
    6279                 :    20376386 :           ssa_op_iter iter;
    6280                 :    20376386 :           tree op;
    6281                 :    20376386 :           gimple *def;
    6282                 :             : 
    6283                 :    20376386 :           location_t sloc = curr_insn_location ();
    6284                 :             : 
    6285                 :             :           /* Look for SSA names that have their last use here (TERed
    6286                 :             :              names always have only one real use).  */
    6287                 :    38884379 :           FOR_EACH_SSA_TREE_OPERAND (op, stmt, iter, SSA_OP_USE)
    6288                 :    18507993 :             if ((def = get_gimple_for_ssa_name (op))
    6289                 :    18507993 :                 && is_gimple_assign (def))
    6290                 :             :               {
    6291                 :     5113780 :                 imm_use_iterator imm_iter;
    6292                 :     5113780 :                 use_operand_p use_p;
    6293                 :     5113780 :                 bool have_debug_uses = false;
    6294                 :             : 
    6295                 :    10201999 :                 FOR_EACH_IMM_USE_FAST (use_p, imm_iter, op)
    6296                 :             :                   {
    6297                 :     5141527 :                     if (gimple_debug_bind_p (USE_STMT (use_p)))
    6298                 :             :                       {
    6299                 :             :                         have_debug_uses = true;
    6300                 :             :                         break;
    6301                 :             :                       }
    6302                 :             :                   }
    6303                 :             : 
    6304                 :     5113780 :                 if (have_debug_uses)
    6305                 :             :                   {
    6306                 :             :                     /* OP is a TERed SSA name, with DEF its defining
    6307                 :             :                        statement, and where OP is used in further debug
    6308                 :             :                        instructions.  Generate a debug temporary, and
    6309                 :             :                        replace all uses of OP in debug insns with that
    6310                 :             :                        temporary.  */
    6311                 :       53308 :                     gimple *debugstmt;
    6312                 :       53308 :                     tree value = gimple_assign_rhs_to_tree (def);
    6313                 :       53308 :                     tree vexpr = build_debug_expr_decl (TREE_TYPE (value));
    6314                 :       53308 :                     rtx val;
    6315                 :       53308 :                     machine_mode mode;
    6316                 :             : 
    6317                 :       53308 :                     set_curr_insn_location (gimple_location (def));
    6318                 :             : 
    6319                 :       53308 :                     if (DECL_P (value))
    6320                 :         377 :                       mode = DECL_MODE (value);
    6321                 :             :                     else
    6322                 :       52931 :                       mode = TYPE_MODE (TREE_TYPE (value));
    6323                 :             :                     /* FIXME: Is setting the mode really necessary? */
    6324                 :       53308 :                     SET_DECL_MODE (vexpr, mode);
    6325                 :             : 
    6326                 :       53308 :                     val = gen_rtx_VAR_LOCATION
    6327                 :       53308 :                         (mode, vexpr, (rtx)value, VAR_INIT_STATUS_INITIALIZED);
    6328                 :             : 
    6329                 :       53308 :                     emit_debug_insn (val);
    6330                 :             : 
    6331                 :      184687 :                     FOR_EACH_IMM_USE_STMT (debugstmt, imm_iter, op)
    6332                 :             :                       {
    6333                 :      131379 :                         if (!gimple_debug_bind_p (debugstmt))
    6334                 :       53308 :                           continue;
    6335                 :             : 
    6336                 :      238235 :                         FOR_EACH_IMM_USE_ON_STMT (use_p, imm_iter)
    6337                 :       80082 :                           SET_USE (use_p, vexpr);
    6338                 :             : 
    6339                 :       78071 :                         update_stmt (debugstmt);
    6340                 :       53308 :                       }
    6341                 :             :                   }
    6342                 :             :               }
    6343                 :    20376386 :           set_curr_insn_location (sloc);
    6344                 :             :         }
    6345                 :             : 
    6346                 :    53560657 :       currently_expanding_gimple_stmt = stmt;
    6347                 :             : 
    6348                 :             :       /* Expand this statement, then evaluate the resulting RTL and
    6349                 :             :          fixup the CFG accordingly.  */
    6350                 :    53560657 :       if (gimple_code (stmt) == GIMPLE_COND)
    6351                 :             :         {
    6352                 :     5629901 :           new_bb = expand_gimple_cond (bb, as_a <gcond *> (stmt));
    6353                 :     5629901 :           if (new_bb)
    6354                 :             :             {
    6355                 :      487550 :               currently_expanding_gimple_stmt = NULL;
    6356                 :      487550 :               return new_bb;
    6357                 :             :             }
    6358                 :             :         }
    6359                 :    47930756 :       else if (is_gimple_debug (stmt))
    6360                 :             :         {
    6361                 :     8348703 :           location_t sloc = curr_insn_location ();
    6362                 :     8348703 :           gimple_stmt_iterator nsi = gsi;
    6363                 :             : 
    6364                 :    48092564 :           for (;;)
    6365                 :             :             {
    6366                 :    48092564 :               tree var;
    6367                 :    48092564 :               tree value = NULL_TREE;
    6368                 :    48092564 :               rtx val = NULL_RTX;
    6369                 :    48092564 :               machine_mode mode;
    6370                 :             : 
    6371                 :    48092564 :               if (!gimple_debug_nonbind_marker_p (stmt))
    6372                 :             :                 {
    6373                 :    36878722 :                   if (gimple_debug_bind_p (stmt))
    6374                 :             :                     {
    6375                 :    36731699 :                       var = gimple_debug_bind_get_var (stmt);
    6376                 :             : 
    6377                 :    36731699 :                       if (TREE_CODE (var) != DEBUG_EXPR_DECL
    6378                 :    34048640 :                           && TREE_CODE (var) != LABEL_DECL
    6379                 :    70771561 :                           && !target_for_debug_bind (var))
    6380                 :      450286 :                         goto delink_debug_stmt;
    6381                 :             : 
    6382                 :    36281413 :                       if (DECL_P (var) && !VECTOR_TYPE_P (TREE_TYPE (var)))
    6383                 :    36272411 :                         mode = DECL_MODE (var);
    6384                 :             :                       else
    6385                 :        9002 :                         mode = TYPE_MODE (TREE_TYPE (var));
    6386                 :             : 
    6387                 :    36281413 :                       if (gimple_debug_bind_has_value_p (stmt))
    6388                 :    20386874 :                         value = gimple_debug_bind_get_value (stmt);
    6389                 :             : 
    6390                 :    36281413 :                       val = gen_rtx_VAR_LOCATION
    6391                 :    36281413 :                         (mode, var, (rtx)value, VAR_INIT_STATUS_INITIALIZED);
    6392                 :             :                     }
    6393                 :      147023 :                   else if (gimple_debug_source_bind_p (stmt))
    6394                 :             :                     {
    6395                 :      147023 :                       var = gimple_debug_source_bind_get_var (stmt);
    6396                 :             : 
    6397                 :      147023 :                       value = gimple_debug_source_bind_get_value (stmt);
    6398                 :             : 
    6399                 :      147023 :                       if (!VECTOR_TYPE_P (TREE_TYPE (var)))
    6400                 :      147023 :                         mode = DECL_MODE (var);
    6401                 :             :                       else
    6402                 :           0 :                         mode = TYPE_MODE (TREE_TYPE (var));
    6403                 :             : 
    6404                 :      147023 :                       val = gen_rtx_VAR_LOCATION (mode, var, (rtx)value,
    6405                 :             :                                                   VAR_INIT_STATUS_UNINITIALIZED);
    6406                 :             :                     }
    6407                 :             :                   else
    6408                 :           0 :                     gcc_unreachable ();
    6409                 :             :                 }
    6410                 :             :               /* If this function was first compiled with markers
    6411                 :             :                  enabled, but they're now disable (e.g. LTO), drop
    6412                 :             :                  them on the floor.  */
    6413                 :    11213842 :               else if (gimple_debug_nonbind_marker_p (stmt)
    6414                 :    11213842 :                        && !MAY_HAVE_DEBUG_MARKER_INSNS)
    6415                 :           0 :                 goto delink_debug_stmt;
    6416                 :    11213842 :               else if (gimple_debug_begin_stmt_p (stmt))
    6417                 :     3861271 :                 val = GEN_RTX_DEBUG_MARKER_BEGIN_STMT_PAT ();
    6418                 :     7352571 :               else if (gimple_debug_inline_entry_p (stmt))
    6419                 :     7352571 :                 val = GEN_RTX_DEBUG_MARKER_INLINE_ENTRY_PAT ();
    6420                 :             :               else
    6421                 :             :                 gcc_unreachable ();
    6422                 :             : 
    6423                 :    47642278 :               last = get_last_insn ();
    6424                 :             : 
    6425                 :    47642278 :               set_curr_insn_location (gimple_location (stmt));
    6426                 :             : 
    6427                 :    47642278 :               emit_debug_insn (val);
    6428                 :             : 
    6429                 :    47642278 :               if (dump_file && (dump_flags & TDF_DETAILS))
    6430                 :             :                 {
    6431                 :             :                   /* We can't dump the insn with a TREE where an RTX
    6432                 :             :                      is expected.  */
    6433                 :           1 :                   if (GET_CODE (val) == VAR_LOCATION)
    6434                 :             :                     {
    6435                 :           0 :                       gcc_checking_assert (PAT_VAR_LOCATION_LOC (val) == (rtx)value);
    6436                 :           0 :                       PAT_VAR_LOCATION_LOC (val) = const0_rtx;
    6437                 :             :                     }
    6438                 :           1 :                   maybe_dump_rtl_for_gimple_stmt (stmt, last);
    6439                 :           1 :                   if (GET_CODE (val) == VAR_LOCATION)
    6440                 :           0 :                     PAT_VAR_LOCATION_LOC (val) = (rtx)value;
    6441                 :             :                 }
    6442                 :             : 
    6443                 :    48092564 :             delink_debug_stmt:
    6444                 :             :               /* In order not to generate too many debug temporaries,
    6445                 :             :                  we delink all uses of debug statements we already expanded.
    6446                 :             :                  Therefore debug statements between definition and real
    6447                 :             :                  use of TERed SSA names will continue to use the SSA name,
    6448                 :             :                  and not be replaced with debug temps.  */
    6449                 :    48092564 :               delink_stmt_imm_use (stmt);
    6450                 :             : 
    6451                 :    48092564 :               gsi = nsi;
    6452                 :    48092564 :               gsi_next (&nsi);
    6453                 :    48092564 :               if (gsi_end_p (nsi))
    6454                 :             :                 break;
    6455                 :    47404074 :               stmt = gsi_stmt (nsi);
    6456                 :    47404074 :               if (!is_gimple_debug (stmt))
    6457                 :             :                 break;
    6458                 :             :             }
    6459                 :             : 
    6460                 :     8348703 :           set_curr_insn_location (sloc);
    6461                 :             :         }
    6462                 :             :       else
    6463                 :             :         {
    6464                 :    39582053 :           gcall *call_stmt = dyn_cast <gcall *> (stmt);
    6465                 :    39582053 :           if (call_stmt
    6466                 :    39582053 :               && asan_epilog_seq
    6467                 :       18784 :               && gimple_call_tail_p (call_stmt)
    6468                 :    39582187 :               && !gimple_call_must_tail_p (call_stmt))
    6469                 :          17 :             gimple_call_set_tail (call_stmt, false);
    6470                 :             : 
    6471                 :    39582053 :           if (call_stmt && gimple_call_tail_p (call_stmt))
    6472                 :             :             {
    6473                 :      173038 :               bool can_fallthru;
    6474                 :      173038 :               new_bb = expand_gimple_tailcall (bb, call_stmt, &can_fallthru,
    6475                 :             :                                                asan_epilog_seq);
    6476                 :      173038 :               if (new_bb)
    6477                 :             :                 {
    6478                 :      123968 :                   if (can_fallthru)
    6479                 :           0 :                     bb = new_bb;
    6480                 :             :                   else
    6481                 :             :                     {
    6482                 :      123968 :                       currently_expanding_gimple_stmt = NULL;
    6483                 :      123968 :                       return new_bb;
    6484                 :             :                     }
    6485                 :             :                 }
    6486                 :             :             }
    6487                 :             :           else
    6488                 :             :             {
    6489                 :    39409015 :               def_operand_p def_p;
    6490                 :    39409015 :               def_p = SINGLE_SSA_DEF_OPERAND (stmt, SSA_OP_DEF);
    6491                 :             : 
    6492                 :    39409015 :               if (def_p != NULL)
    6493                 :             :                 {
    6494                 :             :                   /* Ignore this stmt if it is in the list of
    6495                 :             :                      replaceable expressions.  */
    6496                 :    33227831 :                   if (SA.values
    6497                 :    41187107 :                       && bitmap_bit_p (SA.values,
    6498                 :    16769911 :                                        SSA_NAME_VERSION (DEF_FROM_PTR (def_p))))
    6499                 :     8810635 :                     continue;
    6500                 :             :                 }
    6501                 :    30598380 :               last = expand_gimple_stmt (stmt);
    6502                 :    30598380 :               maybe_dump_rtl_for_gimple_stmt (stmt, last);
    6503                 :             :             }
    6504                 :             :         }
    6505                 :             :     }
    6506                 :             : 
    6507                 :    11958054 :   currently_expanding_gimple_stmt = NULL;
    6508                 :             : 
    6509                 :             :   /* Expand implicit goto and convert goto_locus.  */
    6510                 :    29013172 :   FOR_EACH_EDGE (e, ei, bb->succs)
    6511                 :             :     {
    6512                 :    17055118 :       if (e->goto_locus != UNKNOWN_LOCATION || !nondebug_stmt_seen)
    6513                 :     3575993 :         set_curr_insn_location (e->goto_locus);
    6514                 :    17055118 :       if ((e->flags & EDGE_FALLTHRU) && e->dest != bb->next_bb)
    6515                 :             :         {
    6516                 :     1625999 :           emit_jump (label_rtx_for_bb (e->dest));
    6517                 :     1625999 :           e->flags &= ~EDGE_FALLTHRU;
    6518                 :             :         }
    6519                 :             :     }
    6520                 :             : 
    6521                 :             :   /* Expanded RTL can create a jump in the last instruction of block.
    6522                 :             :      This later might be assumed to be a jump to successor and break edge insertion.
    6523                 :             :      We need to insert dummy move to prevent this. PR41440. */
    6524                 :    11958054 :   if (single_succ_p (bb)
    6525                 :     5436188 :       && (single_succ_edge (bb)->flags & EDGE_FALLTHRU)
    6526                 :     3080034 :       && (last = get_last_insn ())
    6527                 :    14866153 :       && (JUMP_P (last)
    6528                 :     3079986 :           || (DEBUG_INSN_P (last)
    6529                 :      377255 :               && JUMP_P (prev_nondebug_insn (last)))))
    6530                 :             :     {
    6531                 :          53 :       rtx dummy = gen_reg_rtx (SImode);
    6532                 :          53 :       emit_insn_after_noloc (gen_move_insn (dummy, dummy), last, NULL);
    6533                 :             :     }
    6534                 :             : 
    6535                 :             :   /* A __builtin_unreachable () will insert a barrier that should end
    6536                 :             :      the basic block.  In gimple, any code after it will have already
    6537                 :             :      deleted, even without optimization.  If we emit additional code
    6538                 :             :      here, as we would to adjust the stack after a call, it should be
    6539                 :             :      eventually deleted, but it confuses internal checkers (PR118006)
    6540                 :             :      and optimizers before it does, because we don't expect to find
    6541                 :             :      barriers inside basic blocks.  */
    6542                 :    11958054 :   if (!BARRIER_P (get_last_insn ()))
    6543                 :     8701144 :     do_pending_stack_adjust ();
    6544                 :             :   else
    6545                 :     3256910 :     discard_pending_stack_adjust ();
    6546                 :             : 
    6547                 :             :   /* Find the block tail.  The last insn in the block is the insn
    6548                 :             :      before a barrier and/or table jump insn.  */
    6549                 :    11958054 :   last = get_last_insn ();
    6550                 :    11958054 :   if (BARRIER_P (last))
    6551                 :     3256910 :     last = PREV_INSN (last);
    6552                 :    11958054 :   if (JUMP_TABLE_DATA_P (last))
    6553                 :        9267 :     last = PREV_INSN (PREV_INSN (last));
    6554                 :    11958054 :   if (BARRIER_P (last))
    6555                 :        8295 :     last = PREV_INSN (last);
    6556                 :    11958054 :   head_end_for_bb[bb->index].second = last;
    6557                 :             : 
    6558                 :    23916108 :   update_bb_for_insn_chain (head_end_for_bb[bb->index].first,
    6559                 :    11958054 :                             head_end_for_bb[bb->index].second, bb);
    6560                 :             : 
    6561                 :    11958054 :   return bb;
    6562                 :             : }
    6563                 :             : 
    6564                 :             : 
    6565                 :             : /* Create a basic block for initialization code.  */
    6566                 :             : 
    6567                 :             : static basic_block
    6568                 :     1461425 : construct_init_block (void)
    6569                 :             : {
    6570                 :     1461425 :   basic_block init_block;
    6571                 :     1461425 :   edge e = NULL;
    6572                 :     1461425 :   int flags;
    6573                 :             : 
    6574                 :             :   /* Multiple entry points not supported yet.  */
    6575                 :     1461425 :   gcc_assert (EDGE_COUNT (ENTRY_BLOCK_PTR_FOR_FN (cfun)->succs) == 1);
    6576                 :     1461425 :   init_rtl_bb_info (ENTRY_BLOCK_PTR_FOR_FN (cfun));
    6577                 :     1461425 :   init_rtl_bb_info (EXIT_BLOCK_PTR_FOR_FN (cfun));
    6578                 :     1461425 :   ENTRY_BLOCK_PTR_FOR_FN (cfun)->flags |= BB_RTL;
    6579                 :     1461425 :   EXIT_BLOCK_PTR_FOR_FN (cfun)->flags |= BB_RTL;
    6580                 :             : 
    6581                 :     1461425 :   e = EDGE_SUCC (ENTRY_BLOCK_PTR_FOR_FN (cfun), 0);
    6582                 :             : 
    6583                 :             :   /* When entry edge points to first basic block, we don't need jump,
    6584                 :             :      otherwise we have to jump into proper target.  */
    6585                 :     1461425 :   if (e && e->dest != ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb)
    6586                 :             :     {
    6587                 :           0 :       tree label = gimple_block_label (e->dest);
    6588                 :             : 
    6589                 :           0 :       emit_jump (jump_target_rtx (label));
    6590                 :           0 :       flags = 0;
    6591                 :           0 :     }
    6592                 :             :   else
    6593                 :             :     flags = EDGE_FALLTHRU;
    6594                 :             : 
    6595                 :     1461425 :   init_block = create_basic_block (NEXT_INSN (get_insns ()),
    6596                 :             :                                    get_last_insn (),
    6597                 :     1461425 :                                    ENTRY_BLOCK_PTR_FOR_FN (cfun));
    6598                 :     1461425 :   init_block->count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
    6599                 :     1461425 :   add_bb_to_loop (init_block, ENTRY_BLOCK_PTR_FOR_FN (cfun)->loop_father);
    6600                 :     1461425 :   if (e)
    6601                 :     1461425 :     expand_split_edge (e, init_block, flags);
    6602                 :             :   else
    6603                 :           0 :     make_single_succ_edge (init_block, EXIT_BLOCK_PTR_FOR_FN (cfun),
    6604                 :             :                            EDGE_FALLTHRU);
    6605                 :             : 
    6606                 :     1461425 :   update_bb_for_insn (init_block);
    6607                 :     1461425 :   return init_block;
    6608                 :             : }
    6609                 :             : 
    6610                 :             : /* For each lexical block, set BLOCK_NUMBER to the depth at which it is
    6611                 :             :    found in the block tree.  */
    6612                 :             : 
    6613                 :             : static void
    6614                 :    18441038 : set_block_levels (tree block, int level)
    6615                 :             : {
    6616                 :    35420651 :   while (block)
    6617                 :             :     {
    6618                 :    16979613 :       BLOCK_NUMBER (block) = level;
    6619                 :    16979613 :       set_block_levels (BLOCK_SUBBLOCKS (block), level + 1);
    6620                 :    16979613 :       block = BLOCK_CHAIN (block);
    6621                 :             :     }
    6622                 :    18441038 : }
    6623                 :             : 
    6624                 :             : /* Create a block containing landing pads and similar stuff.  */
    6625                 :             : 
    6626                 :             : static void
    6627                 :     1461425 : construct_exit_block (void)
    6628                 :             : {
    6629                 :     1461425 :   rtx_insn *head = get_last_insn ();
    6630                 :     1461425 :   rtx_insn *end;
    6631                 :     1461425 :   basic_block exit_block;
    6632                 :     1461425 :   edge e, e2;
    6633                 :     1461425 :   unsigned ix;
    6634                 :     1461425 :   edge_iterator ei;
    6635                 :     1461425 :   basic_block prev_bb = EXIT_BLOCK_PTR_FOR_FN (cfun)->prev_bb;
    6636                 :     1461425 :   rtx_insn *orig_end = BB_END (prev_bb);
    6637                 :             : 
    6638                 :     1461425 :   rtl_profile_for_bb (EXIT_BLOCK_PTR_FOR_FN (cfun));
    6639                 :             : 
    6640                 :             :   /* Make sure the locus is set to the end of the function, so that
    6641                 :             :      epilogue line numbers and warnings are set properly.  */
    6642                 :     1461425 :   if (LOCATION_LOCUS (cfun->function_end_locus) != UNKNOWN_LOCATION)
    6643                 :     1145220 :     input_location = cfun->function_end_locus;
    6644                 :             : 
    6645                 :             :   /* Generate rtl for function exit.  */
    6646                 :     1461425 :   expand_function_end ();
    6647                 :             : 
    6648                 :     1461425 :   end = get_last_insn ();
    6649                 :     1461425 :   if (head == end)
    6650                 :           0 :     return;
    6651                 :             :   /* While emitting the function end we could move end of the last basic
    6652                 :             :      block.  */
    6653                 :     1461425 :   BB_END (prev_bb) = orig_end;
    6654                 :     1461425 :   while (NEXT_INSN (head) && NOTE_P (NEXT_INSN (head)))
    6655                 :             :     head = NEXT_INSN (head);
    6656                 :             :   /* But make sure exit_block starts with RETURN_LABEL, otherwise the
    6657                 :             :      bb count counting will be confused.  Any instructions before that
    6658                 :             :      label are emitted for the case where PREV_BB falls through into the
    6659                 :             :      exit block, so append those instructions to prev_bb in that case.  */
    6660                 :     1461425 :   if (NEXT_INSN (head) != return_label)
    6661                 :             :     {
    6662                 :       14725 :       while (NEXT_INSN (head) != return_label)
    6663                 :             :         {
    6664                 :        9777 :           if (!NOTE_P (NEXT_INSN (head)))
    6665                 :        9777 :             BB_END (prev_bb) = NEXT_INSN (head);
    6666                 :        9777 :           head = NEXT_INSN (head);
    6667                 :             :         }
    6668                 :             :     }
    6669                 :     1461425 :   exit_block = create_basic_block (NEXT_INSN (head), end, prev_bb);
    6670                 :     1461425 :   exit_block->count = EXIT_BLOCK_PTR_FOR_FN (cfun)->count;
    6671                 :     1461425 :   add_bb_to_loop (exit_block, EXIT_BLOCK_PTR_FOR_FN (cfun)->loop_father);
    6672                 :             : 
    6673                 :     1461425 :   ix = 0;
    6674                 :     4411512 :   while (ix < EDGE_COUNT (EXIT_BLOCK_PTR_FOR_FN (cfun)->preds))
    6675                 :             :     {
    6676                 :     1488662 :       e = EDGE_PRED (EXIT_BLOCK_PTR_FOR_FN (cfun), ix);
    6677                 :     1488662 :       if (!(e->flags & EDGE_ABNORMAL))
    6678                 :     1364694 :         redirect_edge_succ (e, exit_block);
    6679                 :             :       else
    6680                 :      123968 :         ix++;
    6681                 :             :     }
    6682                 :             : 
    6683                 :     1461425 :   e = make_single_succ_edge (exit_block, EXIT_BLOCK_PTR_FOR_FN (cfun),
    6684                 :             :                              EDGE_FALLTHRU);
    6685                 :     3046818 :   FOR_EACH_EDGE (e2, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds)
    6686                 :     1585393 :     if (e2 != e)
    6687                 :             :       {
    6688                 :      123968 :         exit_block->count -= e2->count ();
    6689                 :             :       }
    6690                 :     1461425 :   update_bb_for_insn (exit_block);
    6691                 :             : }
    6692                 :             : 
    6693                 :             : /* Helper function for discover_nonconstant_array_refs.
    6694                 :             :    Look for ARRAY_REF nodes with non-constant indexes and mark them
    6695                 :             :    addressable.  */
    6696                 :             : 
    6697                 :             : static tree
    6698                 :   163470220 : discover_nonconstant_array_refs_r (tree * tp, int *walk_subtrees,
    6699                 :             :                                    void *data)
    6700                 :             : {
    6701                 :   163470220 :   tree t = *tp;
    6702                 :   163470220 :   bitmap forced_stack_vars = (bitmap)((walk_stmt_info *)data)->info;
    6703                 :             : 
    6704                 :   163470220 :   if (IS_TYPE_OR_DECL_P (t))
    6705                 :    33756959 :     *walk_subtrees = 0;
    6706                 :   129713261 :   else if (REFERENCE_CLASS_P (t) && TREE_THIS_VOLATILE (t))
    6707                 :             :     {
    6708                 :       70523 :       t = get_base_address (t);
    6709                 :       70523 :       if (t && DECL_P (t)
    6710                 :       58231 :           && DECL_MODE (t) != BLKmode
    6711                 :      107040 :           && !TREE_ADDRESSABLE (t))
    6712                 :       32679 :         bitmap_set_bit (forced_stack_vars, DECL_UID (t));
    6713                 :       70523 :       *walk_subtrees = 0;
    6714                 :             :     }
    6715                 :   129642738 :   else if (TREE_CODE (t) == ARRAY_REF || TREE_CODE (t) == ARRAY_RANGE_REF)
    6716                 :             :     {
    6717                 :     6005401 :       while (((TREE_CODE (t) == ARRAY_REF || TREE_CODE (t) == ARRAY_RANGE_REF)
    6718                 :     2876137 :               && is_gimple_min_invariant (TREE_OPERAND (t, 1))
    6719                 :     2409567 :               && (!TREE_OPERAND (t, 2)
    6720                 :       30098 :                   || is_gimple_min_invariant (TREE_OPERAND (t, 2))))
    6721                 :     3624805 :              || (TREE_CODE (t) == COMPONENT_REF
    6722                 :      905683 :                  && (!TREE_OPERAND (t,2)
    6723                 :           0 :                      || is_gimple_min_invariant (TREE_OPERAND (t, 2))))
    6724                 :     2719122 :              || TREE_CODE (t) == BIT_FIELD_REF
    6725                 :             :              || TREE_CODE (t) == REALPART_EXPR
    6726                 :             :              || TREE_CODE (t) == IMAGPART_EXPR
    6727                 :             :              || TREE_CODE (t) == VIEW_CONVERT_EXPR
    6728                 :     6005401 :              || CONVERT_EXPR_P (t))
    6729                 :     3296146 :         t = TREE_OPERAND (t, 0);
    6730                 :             : 
    6731                 :     2709255 :       if (TREE_CODE (t) == ARRAY_REF || TREE_CODE (t) == ARRAY_RANGE_REF)
    6732                 :             :         {
    6733                 :      495541 :           t = get_base_address (t);
    6734                 :      495541 :           if (t && DECL_P (t)
    6735                 :      407369 :               && DECL_MODE (t) != BLKmode
    6736                 :      520762 :               && !TREE_ADDRESSABLE (t))
    6737                 :       16896 :             bitmap_set_bit (forced_stack_vars, DECL_UID (t));
    6738                 :             :         }
    6739                 :             : 
    6740                 :     2709255 :       *walk_subtrees = 0;
    6741                 :             :     }
    6742                 :             :   /* References of size POLY_INT_CST to a fixed-size object must go
    6743                 :             :      through memory.  It's more efficient to force that here than
    6744                 :             :      to create temporary slots on the fly.
    6745                 :             :      RTL expansion expectes TARGET_MEM_REF to always address actual memory.
    6746                 :             :      Also, force to stack non-BLKmode vars accessed through VIEW_CONVERT_EXPR
    6747                 :             :      to BLKmode type.  */
    6748                 :   126933483 :   else if (TREE_CODE (t) == TARGET_MEM_REF
    6749                 :             :            || (TREE_CODE (t) == MEM_REF
    6750                 :   126105925 :                && TYPE_SIZE (TREE_TYPE (t))
    6751                 :             :                && POLY_INT_CST_P (TYPE_SIZE (TREE_TYPE (t))))
    6752                 :   253039408 :            || (TREE_CODE (t) == VIEW_CONVERT_EXPR
    6753                 :      318935 :                && TYPE_MODE (TREE_TYPE (t)) == BLKmode))
    6754                 :             :     {
    6755                 :      905795 :       tree base = get_base_address (t);
    6756                 :      905795 :       if (base
    6757                 :      905795 :           && DECL_P (base)
    6758                 :      268383 :           && !TREE_ADDRESSABLE (base)
    6759                 :      124018 :           && DECL_MODE (base) != BLKmode
    6760                 :      911675 :           && GET_MODE_SIZE (DECL_MODE (base)).is_constant ())
    6761                 :        5880 :         bitmap_set_bit (forced_stack_vars, DECL_UID (base));
    6762                 :      905795 :       *walk_subtrees = 0;
    6763                 :             :     }
    6764                 :             : 
    6765                 :   163470220 :   return NULL_TREE;
    6766                 :             : }
    6767                 :             : 
    6768                 :             : /* If there's a chance to get a pseudo for t then if it would be of float mode
    6769                 :             :    and the actual access is via an integer mode (lowered memcpy or similar
    6770                 :             :    access) then avoid the register expansion if the mode likely is not storage
    6771                 :             :    suitable for raw bits processing (like XFmode on i?86).  */
    6772                 :             : 
    6773                 :             : static void
    6774                 :     6763377 : avoid_type_punning_on_regs (tree t, bitmap forced_stack_vars)
    6775                 :             : {
    6776                 :     6763377 :   machine_mode access_mode = TYPE_MODE (TREE_TYPE (t));
    6777                 :     6763377 :   if (access_mode != BLKmode
    6778                 :     6396519 :       && !SCALAR_INT_MODE_P (access_mode))
    6779                 :             :     return;
    6780                 :     5796432 :   tree base = get_base_address (t);
    6781                 :     5796432 :   if (DECL_P (base)
    6782                 :     4368298 :       && !TREE_ADDRESSABLE (base)
    6783                 :     1254235 :       && FLOAT_MODE_P (DECL_MODE (base))
    6784                 :          62 :       && maybe_lt (GET_MODE_PRECISION (DECL_MODE (base)),
    6785                 :         186 :                    GET_MODE_BITSIZE (GET_MODE_INNER (DECL_MODE (base))))
    6786                 :             :       /* Double check in the expensive way we really would get a pseudo.  */
    6787                 :     5796437 :       && use_register_for_decl (base))
    6788                 :           5 :     bitmap_set_bit (forced_stack_vars, DECL_UID (base));
    6789                 :             : }
    6790                 :             : 
    6791                 :             : /* RTL expansion is not able to compile array references with variable
    6792                 :             :    offsets for arrays stored in single register.  Discover such
    6793                 :             :    expressions and mark variables as addressable to avoid this
    6794                 :             :    scenario.  */
    6795                 :             : 
    6796                 :             : static void
    6797                 :     1461425 : discover_nonconstant_array_refs (bitmap forced_stack_vars)
    6798                 :             : {
    6799                 :     1461425 :   basic_block bb;
    6800                 :     1461425 :   gimple_stmt_iterator gsi;
    6801                 :             : 
    6802                 :     1461425 :   walk_stmt_info wi = {};
    6803                 :     1461425 :   wi.info = forced_stack_vars;
    6804                 :    14016882 :   FOR_EACH_BB_FN (bb, cfun)
    6805                 :   119757018 :     for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
    6806                 :             :       {
    6807                 :    94646104 :         gimple *stmt = gsi_stmt (gsi);
    6808                 :    94646104 :         if (!is_gimple_debug (stmt))
    6809                 :             :           {
    6810                 :    46434301 :             walk_gimple_op (stmt, discover_nonconstant_array_refs_r, &wi);
    6811                 :    46434301 :             gcall *call = dyn_cast <gcall *> (stmt);
    6812                 :     6797545 :             if (call && gimple_call_internal_p (call))
    6813                 :             :               {
    6814                 :      188212 :                 tree cand = NULL_TREE;
    6815                 :      188212 :                 switch (gimple_call_internal_fn (call))
    6816                 :             :                   {
    6817                 :           0 :                   case IFN_LOAD_LANES:
    6818                 :             :                     /* The source must be a MEM.  */
    6819                 :           0 :                     cand = gimple_call_arg (call, 0);
    6820                 :           0 :                     break;
    6821                 :           0 :                   case IFN_STORE_LANES:
    6822                 :             :                     /* The destination must be a MEM.  */
    6823                 :           0 :                     cand = gimple_call_lhs (call);
    6824                 :           0 :                     break;
    6825                 :             :                   default:
    6826                 :             :                     break;
    6827                 :             :                   }
    6828                 :           0 :                 if (cand)
    6829                 :           0 :                   cand = get_base_address (cand);
    6830                 :           0 :                 if (cand
    6831                 :           0 :                     && DECL_P (cand)
    6832                 :           0 :                     && use_register_for_decl (cand))
    6833                 :           0 :                   bitmap_set_bit (forced_stack_vars, DECL_UID (cand));
    6834                 :             :               }
    6835                 :   150274160 :             if (gimple_vdef (stmt))
    6836                 :             :               {
    6837                 :    15450313 :                 tree t = gimple_get_lhs (stmt);
    6838                 :    15450313 :                 if (t && REFERENCE_CLASS_P (t))
    6839                 :     6763377 :                   avoid_type_punning_on_regs (t, forced_stack_vars);
    6840                 :             :               }
    6841                 :             :           }
    6842                 :             :       }
    6843                 :     1461425 : }
    6844                 :             : 
    6845                 :             : /* This function sets crtl->args.internal_arg_pointer to a virtual
    6846                 :             :    register if DRAP is needed.  Local register allocator will replace
    6847                 :             :    virtual_incoming_args_rtx with the virtual register.  */
    6848                 :             : 
    6849                 :             : static void
    6850                 :     1461425 : expand_stack_alignment (void)
    6851                 :             : {
    6852                 :     1461425 :   rtx drap_rtx;
    6853                 :     1461425 :   unsigned int preferred_stack_boundary;
    6854                 :             : 
    6855                 :     1461425 :   if (! SUPPORTS_STACK_ALIGNMENT)
    6856                 :             :     return;
    6857                 :             : 
    6858                 :     1461425 :   if (cfun->calls_alloca
    6859                 :     1446549 :       || cfun->has_nonlocal_label
    6860                 :     1445747 :       || crtl->has_nonlocal_goto)
    6861                 :       16079 :     crtl->need_drap = true;
    6862                 :             : 
    6863                 :             :   /* Call update_stack_boundary here again to update incoming stack
    6864                 :             :      boundary.  It may set incoming stack alignment to a different
    6865                 :             :      value after RTL expansion.  TARGET_FUNCTION_OK_FOR_SIBCALL may
    6866                 :             :      use the minimum incoming stack alignment to check if it is OK
    6867                 :             :      to perform sibcall optimization since sibcall optimization will
    6868                 :             :      only align the outgoing stack to incoming stack boundary.  */
    6869                 :     1461425 :   if (targetm.calls.update_stack_boundary)
    6870                 :     1461425 :     targetm.calls.update_stack_boundary ();
    6871                 :             : 
    6872                 :             :   /* The incoming stack frame has to be aligned at least at
    6873                 :             :      parm_stack_boundary.  */
    6874                 :     1461425 :   gcc_assert (crtl->parm_stack_boundary <= INCOMING_STACK_BOUNDARY);
    6875                 :             : 
    6876                 :             :   /* Update crtl->stack_alignment_estimated and use it later to align
    6877                 :             :      stack.  We check PREFERRED_STACK_BOUNDARY if there may be non-call
    6878                 :             :      exceptions since callgraph doesn't collect incoming stack alignment
    6879                 :             :      in this case.  */
    6880                 :     1461425 :   if (cfun->can_throw_non_call_exceptions
    6881                 :      262912 :       && PREFERRED_STACK_BOUNDARY > crtl->preferred_stack_boundary)
    6882                 :             :     preferred_stack_boundary = PREFERRED_STACK_BOUNDARY;
    6883                 :             :   else
    6884                 :     1433490 :     preferred_stack_boundary = crtl->preferred_stack_boundary;
    6885                 :     1461425 :   if (preferred_stack_boundary > crtl->stack_alignment_estimated)
    6886                 :      706378 :     crtl->stack_alignment_estimated = preferred_stack_boundary;
    6887                 :     1461425 :   if (preferred_stack_boundary > crtl->stack_alignment_needed)
    6888                 :      659195 :     crtl->stack_alignment_needed = preferred_stack_boundary;
    6889                 :             : 
    6890                 :     1461425 :   gcc_assert (crtl->stack_alignment_needed
    6891                 :             :               <= crtl->stack_alignment_estimated);
    6892                 :             : 
    6893                 :     1461425 :   crtl->stack_realign_needed
    6894                 :     1461425 :     = INCOMING_STACK_BOUNDARY < crtl->stack_alignment_estimated;
    6895                 :     1461425 :   crtl->stack_realign_tried = crtl->stack_realign_needed;
    6896                 :             : 
    6897                 :     1461425 :   crtl->stack_realign_processed = true;
    6898                 :             : 
    6899                 :             :   /* Target has to redefine TARGET_GET_DRAP_RTX to support stack
    6900                 :             :      alignment.  */
    6901                 :     1461425 :   gcc_assert (targetm.calls.get_drap_rtx != NULL);
    6902                 :     1461425 :   drap_rtx = targetm.calls.get_drap_rtx ();
    6903                 :             : 
    6904                 :             :   /* stack_realign_drap and drap_rtx must match.  */
    6905                 :     1461425 :   gcc_assert ((stack_realign_drap != 0) == (drap_rtx != NULL));
    6906                 :             : 
    6907                 :             :   /* Do nothing if NULL is returned, which means DRAP is not needed.  */
    6908                 :     1461425 :   if (drap_rtx != NULL)
    6909                 :             :     {
    6910                 :        7147 :       crtl->args.internal_arg_pointer = drap_rtx;
    6911                 :             : 
    6912                 :             :       /* Call fixup_tail_calls to clean up REG_EQUIV note if DRAP is
    6913                 :             :          needed. */
    6914                 :        7147 :       fixup_tail_calls ();
    6915                 :             :     }
    6916                 :             : }
    6917                 :             : 
    6918                 :             : 
    6919                 :             : static void
    6920                 :           0 : expand_main_function (void)
    6921                 :             : {
    6922                 :             : #if (defined(INVOKE__main)                              \
    6923                 :             :      || (!defined(HAS_INIT_SECTION)                     \
    6924                 :             :          && !defined(INIT_SECTION_ASM_OP)               \
    6925                 :             :          && !defined(INIT_ARRAY_SECTION_ASM_OP)))
    6926                 :             :   emit_library_call (init_one_libfunc (NAME__MAIN), LCT_NORMAL, VOIDmode);
    6927                 :             : #endif
    6928                 :           0 : }
    6929                 :             : 
    6930                 :             : 
    6931                 :             : /* Expand code to initialize the stack_protect_guard.  This is invoked at
    6932                 :             :    the beginning of a function to be protected.  */
    6933                 :             : 
    6934                 :             : static void
    6935                 :         238 : stack_protect_prologue (void)
    6936                 :             : {
    6937                 :         238 :   tree guard_decl = targetm.stack_protect_guard ();
    6938                 :         238 :   rtx x, y;
    6939                 :             : 
    6940                 :         238 :   crtl->stack_protect_guard_decl = guard_decl;
    6941                 :         238 :   x = expand_normal (crtl->stack_protect_guard);
    6942                 :             : 
    6943                 :         238 :   if (targetm.have_stack_protect_combined_set () && guard_decl)
    6944                 :             :     {
    6945                 :           0 :       gcc_assert (DECL_P (guard_decl));
    6946                 :           0 :       y = DECL_RTL (guard_decl);
    6947                 :             : 
    6948                 :             :       /* Allow the target to compute address of Y and copy it to X without
    6949                 :             :          leaking Y into a register.  This combined address + copy pattern
    6950                 :             :          allows the target to prevent spilling of any intermediate results by
    6951                 :             :          splitting it after register allocator.  */
    6952                 :           0 :       if (rtx_insn *insn = targetm.gen_stack_protect_combined_set (x, y))
    6953                 :             :         {
    6954                 :           0 :           emit_insn (insn);
    6955                 :           0 :           return;
    6956                 :             :         }
    6957                 :             :     }
    6958                 :             : 
    6959                 :         238 :   if (guard_decl)
    6960                 :         238 :     y = expand_normal (guard_decl);
    6961                 :             :   else
    6962                 :           0 :     y = const0_rtx;
    6963                 :             : 
    6964                 :             :   /* Allow the target to copy from Y to X without leaking Y into a
    6965                 :             :      register.  */
    6966                 :         238 :   if (targetm.have_stack_protect_set ())
    6967                 :         238 :     if (rtx_insn *insn = targetm.gen_stack_protect_set (x, y))
    6968                 :             :       {
    6969                 :         238 :         emit_insn (insn);
    6970                 :         238 :         return;
    6971                 :             :       }
    6972                 :             : 
    6973                 :             :   /* Otherwise do a straight move.  */
    6974                 :           0 :   emit_move_insn (x, y);
    6975                 :             : }
    6976                 :             : 
    6977                 :             : /* Translate the intermediate representation contained in the CFG
    6978                 :             :    from GIMPLE trees to RTL.
    6979                 :             : 
    6980                 :             :    We do conversion per basic block and preserve/update the tree CFG.
    6981                 :             :    This implies we have to do some magic as the CFG can simultaneously
    6982                 :             :    consist of basic blocks containing RTL and GIMPLE trees.  This can
    6983                 :             :    confuse the CFG hooks, so be careful to not manipulate CFG during
    6984                 :             :    the expansion.  */
    6985                 :             : 
    6986                 :             : namespace {
    6987                 :             : 
    6988                 :             : const pass_data pass_data_expand =
    6989                 :             : {
    6990                 :             :   RTL_PASS, /* type */
    6991                 :             :   "expand", /* name */
    6992                 :             :   OPTGROUP_NONE, /* optinfo_flags */
    6993                 :             :   TV_EXPAND, /* tv_id */
    6994                 :             :   ( PROP_ssa | PROP_gimple_leh | PROP_cfg
    6995                 :             :     | PROP_gimple_lcx
    6996                 :             :     | PROP_gimple_lvec
    6997                 :             :     | PROP_gimple_lva), /* properties_required */
    6998                 :             :   PROP_rtl, /* properties_provided */
    6999                 :             :   ( PROP_ssa | PROP_gimple ), /* properties_destroyed */
    7000                 :             :   0, /* todo_flags_start */
    7001                 :             :   0, /* todo_flags_finish */
    7002                 :             : };
    7003                 :             : 
    7004                 :             : class pass_expand : public rtl_opt_pass
    7005                 :             : {
    7006                 :             : public:
    7007                 :      287353 :   pass_expand (gcc::context *ctxt)
    7008                 :      574706 :     : rtl_opt_pass (pass_data_expand, ctxt)
    7009                 :             :   {}
    7010                 :             : 
    7011                 :             :   /* opt_pass methods: */
    7012                 :             :   unsigned int execute (function *) final override;
    7013                 :             : 
    7014                 :             : }; // class pass_expand
    7015                 :             : 
    7016                 :             : unsigned int
    7017                 :     1461425 : pass_expand::execute (function *fun)
    7018                 :             : {
    7019                 :     1461425 :   basic_block bb, init_block;
    7020                 :     1461425 :   edge_iterator ei;
    7021                 :     1461425 :   edge e;
    7022                 :     1461425 :   rtx_insn *var_seq, *var_ret_seq;
    7023                 :     1461425 :   unsigned i;
    7024                 :             : 
    7025                 :     1461425 :   timevar_push (TV_OUT_OF_SSA);
    7026                 :     1461425 :   rewrite_out_of_ssa (&SA);
    7027                 :     1461425 :   timevar_pop (TV_OUT_OF_SSA);
    7028                 :     1461425 :   SA.partition_to_pseudo = XCNEWVEC (rtx, SA.map->num_partitions);
    7029                 :             : 
    7030                 :     1461425 :   if (MAY_HAVE_DEBUG_BIND_STMTS && flag_tree_ter)
    7031                 :             :     {
    7032                 :      499935 :       gimple_stmt_iterator gsi;
    7033                 :     6831672 :       FOR_EACH_BB_FN (bb, cfun)
    7034                 :    82505615 :         for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
    7035                 :   106676022 :           if (gimple_debug_bind_p (gsi_stmt (gsi)))
    7036                 :    36833881 :             avoid_deep_ter_for_debug (gsi_stmt (gsi), 0);
    7037                 :             :     }
    7038                 :             : 
    7039                 :             :   /* Mark arrays indexed with non-constant indices with TREE_ADDRESSABLE.  */
    7040                 :     1461425 :   auto_bitmap forced_stack_vars;
    7041                 :     1461425 :   discover_nonconstant_array_refs (forced_stack_vars);
    7042                 :             : 
    7043                 :             :   /* Make sure all values used by the optimization passes have sane
    7044                 :             :      defaults.  */
    7045                 :     1461425 :   reg_renumber = 0;
    7046                 :             : 
    7047                 :             :   /* Some backends want to know that we are expanding to RTL.  */
    7048                 :     1461425 :   currently_expanding_to_rtl = 1;
    7049                 :             :   /* Dominators are not kept up-to-date as we may create new basic-blocks.  */
    7050                 :     1461425 :   free_dominance_info (CDI_DOMINATORS);
    7051                 :             : 
    7052                 :     1461425 :   rtl_profile_for_bb (ENTRY_BLOCK_PTR_FOR_FN (fun));
    7053                 :             : 
    7054                 :     1461425 :   insn_locations_init ();
    7055                 :     1461425 :   if (!DECL_IS_UNDECLARED_BUILTIN (current_function_decl))
    7056                 :             :     {
    7057                 :             :       /* Eventually, all FEs should explicitly set function_start_locus.  */
    7058                 :     1340770 :       if (LOCATION_LOCUS (fun->function_start_locus) == UNKNOWN_LOCATION)
    7059                 :      624973 :         set_curr_insn_location
    7060                 :      624973 :           (DECL_SOURCE_LOCATION (current_function_decl));
    7061                 :             :       else
    7062                 :      715797 :         set_curr_insn_location (fun->function_start_locus);
    7063                 :             :     }
    7064                 :             :   else
    7065                 :      120655 :     set_curr_insn_location (UNKNOWN_LOCATION);
    7066                 :     1461425 :   prologue_location = curr_insn_location ();
    7067                 :             : 
    7068                 :             : #ifdef INSN_SCHEDULING
    7069                 :     1461425 :   init_sched_attrs ();
    7070                 :             : #endif
    7071                 :             : 
    7072                 :             :   /* Make sure first insn is a note even if we don't want linenums.
    7073                 :             :      This makes sure the first insn will never be deleted.
    7074                 :             :      Also, final expects a note to appear there.  */
    7075                 :     1461425 :   emit_note (NOTE_INSN_DELETED);
    7076                 :             : 
    7077                 :     1461425 :   targetm.expand_to_rtl_hook ();
    7078                 :     1461425 :   crtl->init_stack_alignment ();
    7079                 :     1461425 :   fun->cfg->max_jumptable_ents = 0;
    7080                 :             : 
    7081                 :             :   /* Resovle the function section.  Some targets, like ARM EABI rely on knowledge
    7082                 :             :      of the function section at exapnsion time to predict distance of calls.  */
    7083                 :     1461425 :   resolve_unique_section (current_function_decl, 0, flag_function_sections);
    7084                 :             : 
    7085                 :             :   /* Expand the variables recorded during gimple lowering.  */
    7086                 :     1461425 :   timevar_push (TV_VAR_EXPAND);
    7087                 :     1461425 :   start_sequence ();
    7088                 :             : 
    7089                 :     1461425 :   var_ret_seq = expand_used_vars (forced_stack_vars);
    7090                 :             : 
    7091                 :     1461425 :   var_seq = end_sequence ();
    7092                 :     1461425 :   timevar_pop (TV_VAR_EXPAND);
    7093                 :             : 
    7094                 :             :   /* Honor stack protection warnings.  */
    7095                 :     1461425 :   if (warn_stack_protect)
    7096                 :             :     {
    7097                 :           0 :       if (fun->calls_alloca)
    7098                 :           0 :         warning (OPT_Wstack_protector,
    7099                 :             :                  "stack protector not protecting local variables: "
    7100                 :             :                  "variable length buffer");
    7101                 :           0 :       if (has_short_buffer && !crtl->stack_protect_guard)
    7102                 :           0 :         warning (OPT_Wstack_protector,
    7103                 :             :                  "stack protector not protecting function: "
    7104                 :             :                  "all local arrays are less than %d bytes long",
    7105                 :           0 :                  (int) param_ssp_buffer_size);
    7106                 :             :     }
    7107                 :             : 
    7108                 :             :   /* Temporarily mark PARM_DECLs and RESULT_DECLs we need to expand to
    7109                 :             :      memory addressable so expand_function_start can emit the required
    7110                 :             :      copies.  */
    7111                 :     1461425 :   auto_vec<tree, 16> marked_parms;
    7112                 :     4551558 :   for (tree parm = DECL_ARGUMENTS (current_function_decl); parm;
    7113                 :     3090133 :        parm = DECL_CHAIN (parm))
    7114                 :     3090133 :     if (!TREE_ADDRESSABLE (parm)
    7115                 :     3090133 :         && bitmap_bit_p (forced_stack_vars, DECL_UID (parm)))
    7116                 :             :       {
    7117                 :         143 :         TREE_ADDRESSABLE (parm) = 1;
    7118                 :         143 :         marked_parms.safe_push (parm);
    7119                 :             :       }
    7120                 :     1461425 :   if (DECL_RESULT (current_function_decl)
    7121                 :     1461425 :       && !TREE_ADDRESSABLE (DECL_RESULT (current_function_decl))
    7122                 :     2916185 :       && bitmap_bit_p (forced_stack_vars,
    7123                 :     1454760 :                        DECL_UID (DECL_RESULT (current_function_decl))))
    7124                 :             :     {
    7125                 :           0 :       TREE_ADDRESSABLE (DECL_RESULT (current_function_decl)) = 1;
    7126                 :           0 :       marked_parms.safe_push (DECL_RESULT (current_function_decl));
    7127                 :             :     }
    7128                 :             : 
    7129                 :             :   /* Set up parameters and prepare for return, for the function.  */
    7130                 :     1461425 :   expand_function_start (current_function_decl);
    7131                 :             : 
    7132                 :             :   /* Clear TREE_ADDRESSABLE again.  */
    7133                 :     2922993 :   while (!marked_parms.is_empty ())
    7134                 :         143 :     TREE_ADDRESSABLE (marked_parms.pop ()) = 0;
    7135                 :             : 
    7136                 :             :   /* If we emitted any instructions for setting up the variables,
    7137                 :             :      emit them before the FUNCTION_START note.  */
    7138                 :     1461425 :   if (var_seq)
    7139                 :             :     {
    7140                 :        1656 :       emit_insn_before (var_seq, parm_birth_insn);
    7141                 :             : 
    7142                 :             :       /* In expand_function_end we'll insert the alloca save/restore
    7143                 :             :          before parm_birth_insn.  We've just insertted an alloca call.
    7144                 :             :          Adjust the pointer to match.  */
    7145                 :        1656 :       parm_birth_insn = var_seq;
    7146                 :             :     }
    7147                 :             : 
    7148                 :             :   /* Now propagate the RTL assignment of each partition to the
    7149                 :             :      underlying var of each SSA_NAME.  */
    7150                 :             :   tree name;
    7151                 :             : 
    7152                 :    72139950 :   FOR_EACH_SSA_NAME (i, name, cfun)
    7153                 :             :     {
    7154                 :             :       /* We might have generated new SSA names in
    7155                 :             :          update_alias_info_with_stack_vars.  They will have a NULL
    7156                 :             :          defining statements, and won't be part of the partitioning,
    7157                 :             :          so ignore those.  */
    7158                 :    48554206 :       if (!SSA_NAME_DEF_STMT (name))
    7159                 :       69649 :         continue;
    7160                 :             : 
    7161                 :    48484557 :       adjust_one_expanded_partition_var (name);
    7162                 :             :     }
    7163                 :             : 
    7164                 :             :   /* Clean up RTL of variables that straddle across multiple
    7165                 :             :      partitions, and check that the rtl of any PARM_DECLs that are not
    7166                 :             :      cleaned up is that of their default defs.  */
    7167                 :    72139950 :   FOR_EACH_SSA_NAME (i, name, cfun)
    7168                 :             :     {
    7169                 :    48554206 :       int part;
    7170                 :             : 
    7171                 :             :       /* We might have generated new SSA names in
    7172                 :             :          update_alias_info_with_stack_vars.  They will have a NULL
    7173                 :             :          defining statements, and won't be part of the partitioning,
    7174                 :             :          so ignore those.  */
    7175                 :    48554206 :       if (!SSA_NAME_DEF_STMT (name))
    7176                 :       69649 :         continue;
    7177                 :    48484557 :       part = var_to_partition (SA.map, name);
    7178                 :    48484557 :       if (part == NO_PARTITION)
    7179                 :    17312974 :         continue;
    7180                 :             : 
    7181                 :             :       /* If this decl was marked as living in multiple places, reset
    7182                 :             :          this now to NULL.  */
    7183                 :    31171583 :       tree var = SSA_NAME_VAR (name);
    7184                 :    10427816 :       if (var && DECL_RTL_IF_SET (var) == pc_rtx)
    7185                 :      232306 :         SET_DECL_RTL (var, NULL);
    7186                 :             :       /* Check that the pseudos chosen by assign_parms are those of
    7187                 :             :          the corresponding default defs.  */
    7188                 :    30939277 :       else if (SSA_NAME_IS_DEFAULT_DEF (name)
    7189                 :    30939277 :                && (TREE_CODE (var) == PARM_DECL
    7190                 :     3639261 :                    || TREE_CODE (var) == RESULT_DECL))
    7191                 :             :         {
    7192                 :     3582116 :           rtx in = DECL_RTL_IF_SET (var);
    7193                 :     3582116 :           gcc_assert (in);
    7194                 :     3582116 :           rtx out = SA.partition_to_pseudo[part];
    7195                 :     3582116 :           gcc_assert (in == out);
    7196                 :             : 
    7197                 :             :           /* Now reset VAR's RTL to IN, so that the _EXPR attrs match
    7198                 :             :              those expected by debug backends for each parm and for
    7199                 :             :              the result.  This is particularly important for stabs,
    7200                 :             :              whose register elimination from parm's DECL_RTL may cause
    7201                 :             :              -fcompare-debug differences as SET_DECL_RTL changes reg's
    7202                 :             :              attrs.  So, make sure the RTL already has the parm as the
    7203                 :             :              EXPR, so that it won't change.  */
    7204                 :     3582116 :           SET_DECL_RTL (var, NULL_RTX);
    7205                 :     3582116 :           if (MEM_P (in))
    7206                 :      761051 :             set_mem_attributes (in, var, true);
    7207                 :     3582116 :           SET_DECL_RTL (var, in);
    7208                 :             :         }
    7209                 :             :     }
    7210                 :             : 
    7211                 :             :   /* If this function is `main', emit a call to `__main'
    7212                 :             :      to run global initializers, etc.  */
    7213                 :     1461425 :   if (DECL_NAME (current_function_decl)
    7214                 :     1461425 :       && MAIN_NAME_P (DECL_NAME (current_function_decl))
    7215                 :     1572706 :       && DECL_FILE_SCOPE_P (current_function_decl))
    7216                 :     1461425 :     expand_main_function ();
    7217                 :             : 
    7218                 :             :   /* Initialize the stack_protect_guard field.  This must happen after the
    7219                 :             :      call to __main (if any) so that the external decl is initialized.  */
    7220                 :     1461425 :   if (crtl->stack_protect_guard && targetm.stack_protect_runtime_enabled_p ())
    7221                 :         238 :     stack_protect_prologue ();
    7222                 :             : 
    7223                 :     1461425 :   expand_phi_nodes (&SA);
    7224                 :             : 
    7225                 :             :   /* Release any stale SSA redirection data.  */
    7226                 :     1461425 :   redirect_edge_var_map_empty ();
    7227                 :             : 
    7228                 :             :   /* Register rtl specific functions for cfg.  */
    7229                 :     1461425 :   rtl_register_cfg_hooks ();
    7230                 :             : 
    7231                 :     1461425 :   init_block = construct_init_block ();
    7232                 :             : 
    7233                 :             :   /* Clear EDGE_EXECUTABLE on the entry edge(s).  It is cleaned from the
    7234                 :             :      remaining edges later.  */
    7235                 :     2922850 :   FOR_EACH_EDGE (e, ei, ENTRY_BLOCK_PTR_FOR_FN (fun)->succs)
    7236                 :     1461425 :     e->flags &= ~EDGE_EXECUTABLE;
    7237                 :             : 
    7238                 :             :   /* If the function has too many markers, drop them while expanding.  */
    7239                 :     1461425 :   if (cfun->debug_marker_count
    7240                 :     1461425 :       >= param_max_debug_marker_count)
    7241                 :           1 :     cfun->debug_nonbind_markers = false;
    7242                 :             : 
    7243                 :     1461425 :   enable_ranger (fun);
    7244                 :     1461425 :   lab_rtx_for_bb = new hash_map<basic_block, rtx_code_label *>;
    7245                 :     1461425 :   head_end_for_bb.create (last_basic_block_for_fn (fun));
    7246                 :    14030997 :   FOR_BB_BETWEEN (bb, init_block->next_bb, EXIT_BLOCK_PTR_FOR_FN (fun),
    7247                 :             :                   next_bb)
    7248                 :    12569572 :     bb = expand_gimple_basic_block (bb, var_ret_seq);
    7249                 :     1461425 :   disable_ranger (fun);
    7250                 :    14518547 :   FOR_BB_BETWEEN (bb, init_block->next_bb, EXIT_BLOCK_PTR_FOR_FN (fun),
    7251                 :             :                   next_bb)
    7252                 :             :     {
    7253                 :    13057122 :       if ((bb->flags & BB_RTL) == 0)
    7254                 :             :         {
    7255                 :    12569572 :           bb->il.gimple.seq = NULL;
    7256                 :    12569572 :           bb->il.gimple.phi_nodes = NULL;
    7257                 :    12569572 :           init_rtl_bb_info (bb);
    7258                 :    12569572 :           bb->flags |= BB_RTL;
    7259                 :    12569572 :           BB_HEAD (bb) = head_end_for_bb[bb->index].first;
    7260                 :    12569572 :           BB_END (bb) = head_end_for_bb[bb->index].second;
    7261                 :             :         }
    7262                 :             :       /* These flags have no purpose in RTL land.  */
    7263                 :    13057122 :       if (EDGE_COUNT (bb->succs) == 2)
    7264                 :             :         {
    7265                 :     6252461 :           EDGE_SUCC (bb, 0)->flags &= ~(EDGE_TRUE_VALUE | EDGE_FALSE_VALUE);
    7266                 :     6252461 :           EDGE_SUCC (bb, 1)->flags &= ~(EDGE_TRUE_VALUE | EDGE_FALSE_VALUE);
    7267                 :             :         }
    7268                 :    19104822 :       else if (single_succ_p (bb))
    7269                 :     6047700 :         single_succ_edge (bb)->flags &= ~(EDGE_TRUE_VALUE | EDGE_FALSE_VALUE);
    7270                 :             :     }
    7271                 :     1461425 :   head_end_for_bb.release ();
    7272                 :             : 
    7273                 :     1461425 :   if (MAY_HAVE_DEBUG_BIND_INSNS)
    7274                 :      499960 :     expand_debug_locations ();
    7275                 :             : 
    7276                 :     1461425 :   if (deep_ter_debug_map)
    7277                 :             :     {
    7278                 :         658 :       delete deep_ter_debug_map;
    7279                 :         658 :       deep_ter_debug_map = NULL;
    7280                 :             :     }
    7281                 :             : 
    7282                 :             :   /* Free stuff we no longer need after GIMPLE optimizations.  */
    7283                 :     1461425 :   free_dominance_info (CDI_DOMINATORS);
    7284                 :     1461425 :   free_dominance_info (CDI_POST_DOMINATORS);
    7285                 :     1461425 :   delete_tree_cfg_annotations (fun);
    7286                 :             : 
    7287                 :     1461425 :   timevar_push (TV_OUT_OF_SSA);
    7288                 :     1461425 :   finish_out_of_ssa (&SA);
    7289                 :     1461425 :   timevar_pop (TV_OUT_OF_SSA);
    7290                 :             : 
    7291                 :     1461425 :   timevar_push (TV_POST_EXPAND);
    7292                 :             :   /* We are no longer in SSA form.  */
    7293                 :     1461425 :   fun->gimple_df->in_ssa_p = false;
    7294                 :     1461425 :   loops_state_clear (LOOP_CLOSED_SSA);
    7295                 :             : 
    7296                 :             :   /* Expansion is used by optimization passes too, set maybe_hot_insn_p
    7297                 :             :      conservatively to true until they are all profile aware.  */
    7298                 :     2922850 :   delete lab_rtx_for_bb;
    7299                 :     1461425 :   free_histograms (fun);
    7300                 :             : 
    7301                 :     1461425 :   construct_exit_block ();
    7302                 :     1461425 :   insn_locations_finalize ();
    7303                 :             : 
    7304                 :     1461425 :   if (var_ret_seq)
    7305                 :             :     {
    7306                 :        1796 :       rtx_insn *after = return_label;
    7307                 :        1796 :       rtx_insn *next = NEXT_INSN (after);
    7308                 :        1796 :       if (next && NOTE_INSN_BASIC_BLOCK_P (next))
    7309                 :        1796 :         after = next;
    7310                 :        1796 :       emit_insn_after (var_ret_seq, after);
    7311                 :             :     }
    7312                 :             : 
    7313                 :     1461425 :   if (hwasan_sanitize_stack_p ())
    7314                 :         432 :     hwasan_maybe_emit_frame_base_init ();
    7315                 :             : 
    7316                 :             :   /* Zap the tree EH table.  */
    7317                 :     1461425 :   set_eh_throw_stmt_table (fun, NULL);
    7318                 :             : 
    7319                 :             :   /* We need JUMP_LABEL be set in order to redirect jumps, and hence
    7320                 :             :      split edges which edge insertions might do.  */
    7321                 :     1461425 :   rebuild_jump_labels (get_insns ());
    7322                 :             : 
    7323                 :             :   /* If we have a single successor to the entry block, put the pending insns
    7324                 :             :      after parm birth, but before NOTE_INSNS_FUNCTION_BEG.  */
    7325                 :     1461425 :   if (single_succ_p (ENTRY_BLOCK_PTR_FOR_FN (fun)))
    7326                 :             :     {
    7327                 :     1461425 :       edge e = single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (fun));
    7328                 :     1461425 :       if (e->insns.r)
    7329                 :             :         {
    7330                 :          11 :           rtx_insn *insns = e->insns.r;
    7331                 :          11 :           e->insns.r = NULL;
    7332                 :          11 :           rebuild_jump_labels_chain (insns);
    7333                 :          11 :           if (NOTE_P (parm_birth_insn)
    7334                 :          11 :               && NOTE_KIND (parm_birth_insn) == NOTE_INSN_FUNCTION_BEG)
    7335                 :          11 :             emit_insn_before_noloc (insns, parm_birth_insn, e->dest);
    7336                 :             :           else
    7337                 :           0 :             emit_insn_after_noloc (insns, parm_birth_insn, e->dest);
    7338                 :             :         }
    7339                 :             :     }
    7340                 :             : 
    7341                 :             :   /* Otherwise, as well as for other edges, take the usual way.  */
    7342                 :     1461425 :   commit_edge_insertions ();
    7343                 :             : 
    7344                 :             :   /* We're done expanding trees to RTL.  */
    7345                 :     1461425 :   currently_expanding_to_rtl = 0;
    7346                 :             : 
    7347                 :     1461425 :   flush_mark_addressable_queue ();
    7348                 :             : 
    7349                 :    18188281 :   FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (fun)->next_bb,
    7350                 :             :                   EXIT_BLOCK_PTR_FOR_FN (fun), next_bb)
    7351                 :             :     {
    7352                 :    16726856 :       edge e;
    7353                 :    16726856 :       edge_iterator ei;
    7354                 :    39038332 :       for (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); )
    7355                 :             :         {
    7356                 :             :           /* Clear EDGE_EXECUTABLE.  This flag is never used in the backend.  */
    7357                 :    22311476 :           e->flags &= ~EDGE_EXECUTABLE;
    7358                 :             : 
    7359                 :             :           /* At the moment not all abnormal edges match the RTL
    7360                 :             :              representation.  It is safe to remove them here as
    7361                 :             :              find_many_sub_basic_blocks will rediscover them.
    7362                 :             :              In the future we should get this fixed properly.  */
    7363                 :    22311476 :           if ((e->flags & EDGE_ABNORMAL)
    7364                 :      133897 :               && !(e->flags & EDGE_SIBCALL))
    7365                 :        9929 :             remove_edge (e);
    7366                 :             :           else
    7367                 :    22301547 :             ei_next (&ei);
    7368                 :             :         }
    7369                 :             :     }
    7370                 :             : 
    7371                 :     1461425 :   auto_sbitmap blocks (last_basic_block_for_fn (fun));
    7372                 :     1461425 :   bitmap_ones (blocks);
    7373                 :     1461425 :   find_many_sub_basic_blocks (blocks);
    7374                 :     1461425 :   purge_all_dead_edges ();
    7375                 :             : 
    7376                 :             :   /* After initial rtl generation, call back to finish generating
    7377                 :             :      exception support code.  We need to do this before cleaning up
    7378                 :             :      the CFG as the code does not expect dead landing pads.  */
    7379                 :     1461425 :   if (fun->eh->region_tree != NULL)
    7380                 :       64262 :     finish_eh_generation ();
    7381                 :             : 
    7382                 :             :   /* Call expand_stack_alignment after finishing all
    7383                 :             :      updates to crtl->preferred_stack_boundary.  */
    7384                 :     1461425 :   expand_stack_alignment ();
    7385                 :             : 
    7386                 :             :   /* Fixup REG_EQUIV notes in the prologue if there are tailcalls in this
    7387                 :             :      function.  */
    7388                 :     1461425 :   if (crtl->tail_call_emit)
    7389                 :      113111 :     fixup_tail_calls ();
    7390                 :             : 
    7391                 :     1461425 :   HOST_WIDE_INT patch_area_size, patch_area_entry;
    7392                 :     1461425 :   parse_and_check_patch_area (flag_patchable_function_entry, false,
    7393                 :             :                               &patch_area_size, &patch_area_entry);
    7394                 :             : 
    7395                 :     1461425 :   tree patchable_function_entry_attr
    7396                 :     1461425 :     = lookup_attribute ("patchable_function_entry",
    7397                 :     1461425 :                         DECL_ATTRIBUTES (cfun->decl));
    7398                 :     1461425 :   if (patchable_function_entry_attr)
    7399                 :             :     {
    7400                 :          16 :       tree pp_val = TREE_VALUE (patchable_function_entry_attr);
    7401                 :          16 :       tree patchable_function_entry_value1 = TREE_VALUE (pp_val);
    7402                 :             : 
    7403                 :          16 :       patch_area_size = tree_to_uhwi (patchable_function_entry_value1);
    7404                 :          16 :       patch_area_entry = 0;
    7405                 :          16 :       if (TREE_CHAIN (pp_val) != NULL_TREE)
    7406                 :             :         {
    7407                 :           8 :           tree patchable_function_entry_value2
    7408                 :           8 :             = TREE_VALUE (TREE_CHAIN (pp_val));
    7409                 :           8 :           patch_area_entry = tree_to_uhwi (patchable_function_entry_value2);
    7410                 :             :         }
    7411                 :             :     }
    7412                 :             : 
    7413                 :     1461425 :   if (patch_area_entry > patch_area_size)
    7414                 :             :     {
    7415                 :           0 :       if (patch_area_size > 0)
    7416                 :           0 :         warning (OPT_Wattributes,
    7417                 :             :                  "patchable function entry %wu exceeds size %wu",
    7418                 :             :                  patch_area_entry, patch_area_size);
    7419                 :           0 :       patch_area_entry = 0;
    7420                 :             :     }
    7421                 :             : 
    7422                 :     1461425 :   crtl->patch_area_size = patch_area_size;
    7423                 :     1461425 :   crtl->patch_area_entry = patch_area_entry;
    7424                 :             : 
    7425                 :             :   /* BB subdivision may have created basic blocks that are only reachable
    7426                 :             :      from unlikely bbs but not marked as such in the profile.  */
    7427                 :     1461425 :   if (optimize)
    7428                 :     1030293 :     propagate_unlikely_bbs_forward ();
    7429                 :             : 
    7430                 :             :   /* Remove unreachable blocks, otherwise we cannot compute dominators
    7431                 :             :      which are needed for loop state verification.  As a side-effect
    7432                 :             :      this also compacts blocks.
    7433                 :             :      ???  We cannot remove trivially dead insns here as for example
    7434                 :             :      the DRAP reg on i?86 is not magically live at this point.
    7435                 :             :      gcc.c-torture/execute/ipa-sra-2.c execution, -Os -m32 fails otherwise.  */
    7436                 :     1461425 :   cleanup_cfg (CLEANUP_NO_INSN_DEL);
    7437                 :             : 
    7438                 :     1461425 :   checking_verify_flow_info ();
    7439                 :             : 
    7440                 :             :   /* Initialize pseudos allocated for hard registers.  */
    7441                 :     1461425 :   emit_initial_value_sets ();
    7442                 :             : 
    7443                 :             :   /* And finally unshare all RTL.  */
    7444                 :     1461425 :   unshare_all_rtl ();
    7445                 :             : 
    7446                 :             :   /* There's no need to defer outputting this function any more; we
    7447                 :             :      know we want to output it.  */
    7448                 :     1461425 :   DECL_DEFER_OUTPUT (current_function_decl) = 0;
    7449                 :             : 
    7450                 :             :   /* Now that we're done expanding trees to RTL, we shouldn't have any
    7451                 :             :      more CONCATs anywhere.  */
    7452                 :     1461425 :   generating_concat_p = 0;
    7453                 :             : 
    7454                 :     1461425 :   if (dump_file)
    7455                 :             :     {
    7456                 :         360 :       fprintf (dump_file,
    7457                 :             :                "\n\n;;\n;; Full RTL generated for this function:\n;;\n");
    7458                 :             :       /* And the pass manager will dump RTL for us.  */
    7459                 :             :     }
    7460                 :             : 
    7461                 :             :   /* If we're emitting a nested function, make sure its parent gets
    7462                 :             :      emitted as well.  Doing otherwise confuses debug info.  */
    7463                 :     1461425 :     {
    7464                 :     1461425 :       tree parent;
    7465                 :     1461425 :       for (parent = DECL_CONTEXT (current_function_decl);
    7466                 :     3139870 :            parent != NULL_TREE;
    7467                 :     1678445 :            parent = get_containing_scope (parent))
    7468                 :     1678445 :         if (TREE_CODE (parent) == FUNCTION_DECL)
    7469                 :       72110 :           TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (parent)) = 1;
    7470                 :             :     }
    7471                 :             : 
    7472                 :     1461425 :   TREE_ASM_WRITTEN (current_function_decl) = 1;
    7473                 :             : 
    7474                 :             :   /* After expanding, the return labels are no longer needed. */
    7475                 :     1461425 :   return_label = NULL;
    7476                 :     1461425 :   naked_return_label = NULL;
    7477                 :             : 
    7478                 :             :   /* After expanding, the tm_restart map is no longer needed.  */
    7479                 :     1461425 :   if (fun->gimple_df->tm_restart)
    7480                 :         265 :     fun->gimple_df->tm_restart = NULL;
    7481                 :             : 
    7482                 :             :   /* Tag the blocks with a depth number so that change_scope can find
    7483                 :             :      the common parent easily.  */
    7484                 :     1461425 :   set_block_levels (DECL_INITIAL (fun->decl), 0);
    7485                 :     1461425 :   default_rtl_profile ();
    7486                 :             : 
    7487                 :             :   /* For -dx discard loops now, otherwise IL verify in clean_state will
    7488                 :             :      ICE.  */
    7489                 :     1461425 :   if (rtl_dump_and_exit)
    7490                 :             :     {
    7491                 :          79 :       cfun->curr_properties &= ~PROP_loops;
    7492                 :          79 :       loop_optimizer_finalize ();
    7493                 :             :     }
    7494                 :             : 
    7495                 :     1461425 :   timevar_pop (TV_POST_EXPAND);
    7496                 :             : 
    7497                 :     1461425 :   return 0;
    7498                 :     1461425 : }
    7499                 :             : 
    7500                 :             : } // anon namespace
    7501                 :             : 
    7502                 :             : rtl_opt_pass *
    7503                 :      287353 : make_pass_expand (gcc::context *ctxt)
    7504                 :             : {
    7505                 :      287353 :   return new pass_expand (ctxt);
    7506                 :             : }
        

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