LCOV - code coverage report
Current view: top level - gcc - cfgexpand.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 88.3 % 3532 3117
Test Date: 2025-07-05 13:26:22 Functions: 91.6 % 107 98
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                 :     3141228 : gimple_assign_rhs_to_tree (gimple *stmt)
     107                 :             : {
     108                 :     3141228 :   tree t;
     109                 :     3141228 :   switch (gimple_assign_rhs_class (stmt))
     110                 :             :     {
     111                 :         857 :     case GIMPLE_TERNARY_RHS:
     112                 :         857 :       t = build3 (gimple_assign_rhs_code (stmt),
     113                 :         857 :                   TREE_TYPE (gimple_assign_lhs (stmt)),
     114                 :             :                   gimple_assign_rhs1 (stmt), gimple_assign_rhs2 (stmt),
     115                 :             :                   gimple_assign_rhs3 (stmt));
     116                 :         857 :       break;
     117                 :     1076949 :     case GIMPLE_BINARY_RHS:
     118                 :     1076949 :       t = build2 (gimple_assign_rhs_code (stmt),
     119                 :     1076949 :                   TREE_TYPE (gimple_assign_lhs (stmt)),
     120                 :             :                   gimple_assign_rhs1 (stmt), gimple_assign_rhs2 (stmt));
     121                 :     1076949 :       break;
     122                 :      355892 :     case GIMPLE_UNARY_RHS:
     123                 :      355892 :       t = build1 (gimple_assign_rhs_code (stmt),
     124                 :      355892 :                   TREE_TYPE (gimple_assign_lhs (stmt)),
     125                 :             :                   gimple_assign_rhs1 (stmt));
     126                 :      355892 :       break;
     127                 :     1707530 :     case GIMPLE_SINGLE_RHS:
     128                 :     1707530 :       {
     129                 :     1707530 :         t = gimple_assign_rhs1 (stmt);
     130                 :             :         /* Avoid modifying this tree in place below.  */
     131                 :     3343790 :         if ((gimple_has_location (stmt) && CAN_HAVE_LOCATION_P (t)
     132                 :     1594841 :              && gimple_location (stmt) != EXPR_LOCATION (t))
     133                 :     1909460 :             || (gimple_block (stmt) && currently_expanding_to_rtl
     134                 :       45375 :                 && EXPR_P (t)))
     135                 :     1466203 :           t = copy_node (t);
     136                 :             :         break;
     137                 :             :       }
     138                 :           0 :     default:
     139                 :           0 :       gcc_unreachable ();
     140                 :             :     }
     141                 :             : 
     142                 :     3141228 :   if (gimple_has_location (stmt) && CAN_HAVE_LOCATION_P (t))
     143                 :     2961059 :     SET_EXPR_LOCATION (t, gimple_location (stmt));
     144                 :             : 
     145                 :     3141228 :   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                 :    59146192 : leader_merge (tree cur, tree next)
     162                 :             : {
     163                 :    59146192 :   if (cur == NULL || cur == next)
     164                 :             :     return next;
     165                 :             : 
     166                 :     3176267 :   if (DECL_P (cur) && DECL_IGNORED_P (cur))
     167                 :             :     return cur;
     168                 :             : 
     169                 :     2368231 :   if (DECL_P (next) && DECL_IGNORED_P (next))
     170                 :      154803 :     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                 :    70030448 : set_rtl (tree t, rtx x)
     180                 :             : {
     181                 :    70030448 :   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                 :    64848787 :   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                 :    65239892 :       bool skip = false;
     223                 :    65239892 :       tree cur = NULL_TREE;
     224                 :             :       rtx xm = x;
     225                 :             : 
     226                 :    65239892 :     retry:
     227                 :    65239892 :       if (MEM_P (xm))
     228                 :     4719033 :         cur = MEM_EXPR (xm);
     229                 :             :       else if (REG_P (xm))
     230                 :    54427159 :         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                 :      387958 :           xm = XEXP (xm, 0);
     240                 :      387958 :           goto retry;
     241                 :             :         }
     242                 :             :       else if (GET_CODE (xm) == PARALLEL)
     243                 :             :         {
     244                 :        3147 :           xm = XVECEXP (xm, 0, 0);
     245                 :        3147 :           gcc_assert (GET_CODE (xm) == EXPR_LIST);
     246                 :        3147 :           xm = XEXP (xm, 0);
     247                 :        3147 :           goto retry;
     248                 :             :         }
     249                 :     5702595 :       else if (xm == pc_rtx)
     250                 :             :         skip = true;
     251                 :             :       else
     252                 :           0 :         gcc_unreachable ();
     253                 :             : 
     254                 :    59146192 :       tree next = skip ? cur : leader_merge (cur, SSAVAR (t) ? SSAVAR (t) : t);
     255                 :             : 
     256                 :    64848787 :       if (cur != next)
     257                 :             :         {
     258                 :    27358326 :           if (MEM_P (x))
     259                 :     4000488 :             set_mem_attributes (x,
     260                 :     2000244 :                                 next && TREE_CODE (next) == SSA_NAME
     261                 :       12174 :                                 ? TREE_TYPE (next)
     262                 :             :                                 : next, true);
     263                 :             :           else
     264                 :    25358082 :             set_reg_attrs_for_decl_rtl (next, x);
     265                 :             :         }
     266                 :             :     }
     267                 :             : 
     268                 :    70030448 :   if (TREE_CODE (t) == SSA_NAME)
     269                 :             :     {
     270                 :    56593796 :       int part = var_to_partition (SA.map, t);
     271                 :    56593796 :       if (part != NO_PARTITION)
     272                 :             :         {
     273                 :    56593796 :           if (SA.partition_to_pseudo[part])
     274                 :    30983110 :             gcc_assert (SA.partition_to_pseudo[part] == x);
     275                 :    25610686 :           else if (x != pc_rtx)
     276                 :    25607824 :             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                 :   113184730 :       if (x && x != pc_rtx && SSA_NAME_VAR (t)
     283                 :    74275269 :           && (VAR_P (SSA_NAME_VAR (t))
     284                 :     7322591 :               || SSA_NAME_IS_DEFAULT_DEF (t)))
     285                 :             :         {
     286                 :    17501228 :           tree var = SSA_NAME_VAR (t);
     287                 :             :           /* If we don't yet have something recorded, just record it now.  */
     288                 :    17501228 :           if (!DECL_RTL_SET_P (var))
     289                 :     7377076 :             SET_DECL_RTL (var, x);
     290                 :             :           /* If we have it set already to "multiple places" don't
     291                 :             :              change this.  */
     292                 :    10124152 :           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                 :     9030496 :           else if (DECL_RTL (var) != x)
     301                 :      225094 :             SET_DECL_RTL (var, pc_rtx);
     302                 :             :         }
     303                 :             :     }
     304                 :             :   else
     305                 :    13436652 :     SET_DECL_RTL (t, x);
     306                 :    70030448 : }
     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                 :     6493245 : align_local_variable (tree decl, bool really_expand)
     370                 :             : {
     371                 :     6493245 :   unsigned int align;
     372                 :             : 
     373                 :     6493245 :   if (TREE_CODE (decl) == SSA_NAME)
     374                 :             :     {
     375                 :      442008 :       tree type = TREE_TYPE (decl);
     376                 :      442008 :       machine_mode mode = TYPE_MODE (type);
     377                 :             : 
     378                 :      442008 :       align = TYPE_ALIGN (type);
     379                 :      442008 :       if (mode != BLKmode
     380                 :      442008 :           && align < GET_MODE_ALIGNMENT (mode))
     381                 :         456 :         align = GET_MODE_ALIGNMENT (mode);
     382                 :             :     }
     383                 :             :   else
     384                 :     6051237 :     align = LOCAL_DECL_ALIGNMENT (decl);
     385                 :             : 
     386                 :     6493245 :   if (hwasan_sanitize_stack_p ())
     387                 :         270 :     align = MAX (align, (unsigned) HWASAN_TAG_GRANULE_SIZE * BITS_PER_UNIT);
     388                 :             : 
     389                 :     6493245 :   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                 :     1550203 :     SET_DECL_ALIGN (decl, align);
     395                 :             : 
     396                 :     6493245 :   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                 :     1734116 : alloc_stack_frame_space (poly_int64 size, unsigned HOST_WIDE_INT align)
     413                 :             : {
     414                 :     1734116 :   poly_int64 offset, new_frame_offset;
     415                 :             : 
     416                 :     1734116 :   if (FRAME_GROWS_DOWNWARD)
     417                 :             :     {
     418                 :     1734116 :       new_frame_offset
     419                 :     1734116 :         = aligned_lower_bound (frame_offset - frame_phase - size,
     420                 :     1734116 :                                align) + frame_phase;
     421                 :     1734116 :       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                 :     1734116 :   frame_offset = new_frame_offset;
     432                 :             : 
     433                 :     1734116 :   if (frame_offset_overflow (frame_offset, cfun->decl))
     434                 :           0 :     frame_offset = offset = 0;
     435                 :             : 
     436                 :     1734116 :   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                 :        1720 : 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                 :     5702595 : add_stack_var (tree decl, bool really_expand)
     451                 :             : {
     452                 :     5702595 :   class stack_var *v;
     453                 :             : 
     454                 :     5702595 :   if (stack_vars_num >= stack_vars_alloc)
     455                 :             :     {
     456                 :     1345542 :       if (stack_vars_alloc)
     457                 :       33641 :         stack_vars_alloc = stack_vars_alloc * 3 / 2;
     458                 :             :       else
     459                 :     1311901 :         stack_vars_alloc = 32;
     460                 :     1345542 :       stack_vars
     461                 :     1345542 :         = XRESIZEVEC (class stack_var, stack_vars, stack_vars_alloc);
     462                 :             :     }
     463                 :     5702595 :   if (!decl_to_stack_part)
     464                 :           0 :     decl_to_stack_part = new hash_map<tree, unsigned>;
     465                 :             : 
     466                 :     5702595 :   v = &stack_vars[stack_vars_num];
     467                 :     5702595 :   decl_to_stack_part->put (decl, stack_vars_num);
     468                 :             : 
     469                 :     5702595 :   v->decl = decl;
     470                 :     5702595 :   tree size = TREE_CODE (decl) == SSA_NAME
     471                 :     5702595 :     ? TYPE_SIZE_UNIT (TREE_TYPE (decl))
     472                 :     5702595 :     : DECL_SIZE_UNIT (decl);
     473                 :     5702595 :   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                 :     5702595 :   if (known_eq (v->size, 0U))
     477                 :       23832 :     v->size = 1;
     478                 :     5702595 :   v->alignb = align_local_variable (decl, really_expand);
     479                 :             :   /* An alignment of zero can mightily confuse us later.  */
     480                 :     5702595 :   gcc_assert (v->alignb != 0);
     481                 :             : 
     482                 :             :   /* All variables are initially in their own partition.  */
     483                 :     5702595 :   v->representative = stack_vars_num;
     484                 :     5702595 :   v->next = EOC;
     485                 :             : 
     486                 :             :   /* All variables initially conflict with no other.  */
     487                 :     5702595 :   v->conflicts = NULL;
     488                 :             : 
     489                 :             :   /* Ensure that this decl doesn't get put onto the list twice.  */
     490                 :     5702595 :   set_rtl (decl, pc_rtx);
     491                 :             : 
     492                 :     5702595 :   stack_vars_num++;
     493                 :     5702595 : }
     494                 :             : 
     495                 :             : /* Make the decls associated with luid's X and Y conflict.  */
     496                 :             : 
     497                 :             : static void
     498                 :    11145006 : add_stack_var_conflict (unsigned x, unsigned y)
     499                 :             : {
     500                 :    11145006 :   class stack_var *a = &stack_vars[x];
     501                 :    11145006 :   class stack_var *b = &stack_vars[y];
     502                 :    11145006 :   if (x == y)
     503                 :             :     return;
     504                 :    10086983 :   if (!a->conflicts)
     505                 :      638752 :     a->conflicts = BITMAP_ALLOC (&stack_var_bitmap_obstack);
     506                 :    10086983 :   if (!b->conflicts)
     507                 :      111567 :     b->conflicts = BITMAP_ALLOC (&stack_var_bitmap_obstack);
     508                 :    10086983 :   bitmap_set_bit (a->conflicts, y);
     509                 :    10086983 :   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                 :    11276360 : stack_var_conflict_p (unsigned x, unsigned y)
     516                 :             : {
     517                 :    11276360 :   class stack_var *a = &stack_vars[x];
     518                 :    11276360 :   class stack_var *b = &stack_vars[y];
     519                 :    11276360 :   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                 :    11276360 :   if (TREE_CODE (a->decl) == SSA_NAME || TREE_CODE (b->decl) == SSA_NAME)
     525                 :             :     return true;
     526                 :             : 
     527                 :    11242092 :   if (!a->conflicts || !b->conflicts)
     528                 :             :     return false;
     529                 :    11186759 :   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                 :    46370556 : decl_stack_index (tree decl)
     536                 :             : {
     537                 :    46370556 :   if (!decl)
     538                 :             :     return INVALID_STACK_INDEX;
     539                 :    46370556 :   if (!DECL_P (decl))
     540                 :             :     return INVALID_STACK_INDEX;
     541                 :    35652610 :   if (DECL_RTL_IF_SET (decl) != pc_rtx)
     542                 :             :     return INVALID_STACK_INDEX;
     543                 :    23895583 :   unsigned *v = decl_to_stack_part->get (decl);
     544                 :    23895583 :   if (!v)
     545                 :             :     return INVALID_STACK_INDEX;
     546                 :             : 
     547                 :    23895583 :   unsigned indx = *v;
     548                 :    23895583 :   gcc_checking_assert (indx != INVALID_STACK_INDEX);
     549                 :    23895583 :   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                 :    29607391 : visit_op (gimple *, tree op, tree, void *data)
     558                 :             : {
     559                 :    29607391 :   bitmap active = (bitmap)data;
     560                 :    29607391 :   op = get_base_address (op);
     561                 :    29607391 :   unsigned idx = decl_stack_index (op);
     562                 :    29607391 :   if (idx != INVALID_STACK_INDEX)
     563                 :    14730721 :     bitmap_set_bit (active, idx);
     564                 :    29607391 :   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                 :    13493682 : visit_conflict (gimple *, tree op, tree, void *data)
     573                 :             : {
     574                 :    13493682 :   bitmap active = (bitmap)data;
     575                 :    13493682 :   op = get_base_address (op);
     576                 :    13493682 :   unsigned num = decl_stack_index (op);
     577                 :    13493682 :   if (num != INVALID_STACK_INDEX
     578                 :    13493682 :       && bitmap_set_bit (active, num))
     579                 :             :     {
     580                 :      977069 :       bitmap_iterator bi;
     581                 :      977069 :       unsigned i;
     582                 :      977069 :       gcc_assert (num < stack_vars_num);
     583                 :    10667648 :       EXECUTE_IF_SET_IN_BITMAP (active, 0, i, bi)
     584                 :     9690579 :         add_stack_var_conflict (num, i);
     585                 :             :     }
     586                 :    13493682 :   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                 :     1108524 :   void unshare(int indx)
     627                 :             :   {
     628                 :     1108524 :     if (vars_ssa_caches[indx].bmap == empty)
     629                 :      465449 :         vars_ssa_caches[indx].bmap = BITMAP_ALLOC (&stack_var_bitmap_obstack);
     630                 :     1108524 :   }
     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                 :      149875 : vars_ssa_cache::vars_ssa_cache ()
     639                 :             : {
     640                 :    31718779 :   vars_ssa_caches = new entry[num_ssa_names]{};
     641                 :             : 
     642                 :             :   /* Create the shared empty bitmap too. */
     643                 :      149875 :   empty = BITMAP_ALLOC (&stack_var_bitmap_obstack);
     644                 :      149875 : }
     645                 :             : 
     646                 :             : /* Delete the array. The bitmaps will be freed
     647                 :             :    when stack_var_bitmap_obstack is freed.  */
     648                 :      149875 : vars_ssa_cache::~vars_ssa_cache ()
     649                 :             : {
     650                 :      149875 :   delete []vars_ssa_caches;
     651                 :      149875 : }
     652                 :             : 
     653                 :             : /* Create an empty entry for the USE ssa name.  */
     654                 :             : void
     655                 :    10767265 : vars_ssa_cache::create (tree use)
     656                 :             : {
     657                 :    10767265 :   int num = SSA_NAME_VERSION (use);
     658                 :    10767265 :   if (vars_ssa_caches[num].bmap)
     659                 :             :     return;
     660                 :    10767265 :   vars_ssa_caches[num].bmap = empty;
     661                 :             : }
     662                 :             : 
     663                 :             : /* Returns true if the cache for USE exists.  */
     664                 :             : bool
     665                 :    70390610 : vars_ssa_cache::exists (tree use)
     666                 :             : {
     667                 :    70390610 :   int num = SSA_NAME_VERSION (use);
     668                 :    70390610 :   return vars_ssa_caches[num].bmap != nullptr;
     669                 :             : }
     670                 :             : 
     671                 :             : /* Add to USE's bitmap for stack variable IDX.  */
     672                 :             : void
     673                 :      160995 : vars_ssa_cache::add_one (tree use, unsigned idx)
     674                 :             : {
     675                 :      160995 :   gcc_assert (idx != INVALID_STACK_INDEX);
     676                 :      160995 :   int num = SSA_NAME_VERSION (use);
     677                 :      160995 :   gcc_assert (vars_ssa_caches[num].bmap);
     678                 :      160995 :   unshare (num);
     679                 :      160995 :   bitmap_set_bit (vars_ssa_caches[num].bmap, idx);
     680                 :      160995 : }
     681                 :             : 
     682                 :             : /* Update cache of OLD_NAME from the USE's cache. */
     683                 :             : bool
     684                 :    24993974 : vars_ssa_cache::update (tree old_name, tree use)
     685                 :             : {
     686                 :    24993974 :   if (old_name == use)
     687                 :             :     return false;
     688                 :    16009864 :   int num = SSA_NAME_VERSION (use);
     689                 :    16009864 :   int old_num = SSA_NAME_VERSION (old_name);
     690                 :             : 
     691                 :             :   /* If the old name was empty, then there is nothing to be updated. */
     692                 :    16009864 :   if (vars_ssa_caches[num].bmap == empty)
     693                 :             :     return false;
     694                 :      947529 :   unshare (old_num);
     695                 :      947529 :   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                 :    55053333 : vars_ssa_cache::operator() (tree name)
     729                 :             : {
     730                 :    55053333 :   gcc_assert (TREE_CODE (name) == SSA_NAME);
     731                 :             : 
     732                 :    90831387 :   if (!POINTER_TYPE_P (TREE_TYPE (name))
     733                 :    89711810 :       && !ANY_INTEGRAL_TYPE_P (TREE_TYPE (name)))
     734                 :     2431316 :     return empty;
     735                 :             : 
     736                 :    52622017 :   if (exists (name))
     737                 :    43683206 :     return vars_ssa_caches[SSA_NAME_VERSION (name)].bmap;
     738                 :             : 
     739                 :     8938811 :   auto_vec<std::pair<tree,tree>, 4> work_list;
     740                 :     8938811 :   auto_vec<std::pair<tree,tree>, 4> update_cache_list;
     741                 :             : 
     742                 :     8938811 :   work_list.safe_push (std::make_pair (name, name));
     743                 :             : 
     744                 :    33061319 :   while (!work_list.is_empty ())
     745                 :             :     {
     746                 :    24122508 :       auto item = work_list.pop();
     747                 :    24122508 :       tree use = item.first;
     748                 :    24122508 :       tree old_name = item.second;
     749                 :    24122508 :       if (TREE_CODE (use) == ADDR_EXPR)
     750                 :             :         {
     751                 :      416567 :           tree op = TREE_OPERAND (use, 0);
     752                 :      416567 :           op = get_base_address (op);
     753                 :      416567 :           unsigned idx = decl_stack_index (op);
     754                 :      416567 :           if (idx != INVALID_STACK_INDEX)
     755                 :      160995 :             add_one (old_name, idx);
     756                 :    13355243 :           continue;
     757                 :      416567 :         }
     758                 :             : 
     759                 :    23705941 :       if (TREE_CODE (use) != SSA_NAME)
     760                 :     5861797 :         continue;
     761                 :             : 
     762                 :    31148209 :       if (!POINTER_TYPE_P (TREE_TYPE (use))
     763                 :    31030497 :           && !ANY_INTEGRAL_TYPE_P (TREE_TYPE (use)))
     764                 :       75551 :         continue;
     765                 :             : 
     766                 :             :       /* Mark the old ssa name needs to be update from the use. */
     767                 :    17768593 :       update_cache_list.safe_push (item);
     768                 :             : 
     769                 :             :       /* If the cache exists for the use, don't try to recreate it. */
     770                 :    17768593 :       if (exists (use))
     771                 :             :         {
     772                 :             :           /* Update the cache here, this can reduce the number of
     773                 :             :              times through the update loop below.  */
     774                 :     7001328 :           update (old_name, use);
     775                 :     7001328 :           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                 :    10767265 :       create (use);
     781                 :             : 
     782                 :    10767265 :       gimple *g = SSA_NAME_DEF_STMT (use);
     783                 :             :  
     784                 :             :       /* CONSTRUCTOR here is always a vector initialization,
     785                 :             :          walk each element too. */
     786                 :    10767265 :       if (gimple_assign_single_p (g)
     787                 :    10767265 :           && TREE_CODE (gimple_assign_rhs1 (g)) == CONSTRUCTOR)
     788                 :             :         {
     789                 :             :           tree ctr = gimple_assign_rhs1 (g);
     790                 :             :           unsigned i;
     791                 :             :           tree elm;
     792                 :      310694 :           FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctr), i, elm)
     793                 :      216424 :             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                 :    10672995 :       else if (gassign *a = dyn_cast <gassign *> (g))
     798                 :             :         {
     799                 :             :           /* operand 0 is the lhs. */
     800                 :    18975464 :           for (unsigned i = 1; i < gimple_num_ops (g); i++)
     801                 :    10954451 :             work_list.safe_push (std::make_pair (gimple_op (a, i), use));
     802                 :             :         }
     803                 :    12368432 :       else if (gphi *p = dyn_cast <gphi *> (g))
     804                 :     5613989 :         for (unsigned i = 0; i < gimple_phi_num_args (p); ++i)
     805                 :     4012822 :           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                 :     8984078 :   bool changed;
     812                 :    17968156 :   do {
     813                 :     8984078 :     changed = false;
     814                 :     8984078 :     unsigned int i;
     815                 :     8984078 :     std::pair<tree,tree> *e;
     816                 :    44899613 :     FOR_EACH_VEC_ELT_REVERSE (update_cache_list, i, e)
     817                 :             :       {
     818                 :    17992646 :         if (update (e->second, e->first))
     819                 :       51764 :           changed = true;
     820                 :             :       }
     821                 :             :   } while (changed);
     822                 :             : 
     823                 :     8938811 :   return vars_ssa_caches[SSA_NAME_VERSION (name)].bmap;
     824                 :     8938811 : }
     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                 :    55053333 : add_scope_conflicts_2 (vars_ssa_cache &cache, tree name,
     833                 :             :                        bitmap work, walk_stmt_load_store_addr_fn visit)
     834                 :             : {
     835                 :    55053333 :   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                 :    55053333 :   bitmap_iterator bi;
     840                 :    55053333 :   unsigned i;
     841                 :    55053333 :   const_bitmap bmap = cache (name);
     842                 :             :   /* Visit each stack variable that is referenced.  */
     843                 :    57443201 :   EXECUTE_IF_SET_IN_BITMAP (bmap, 0, i, bi)
     844                 :     2389868 :     visit (nullptr, stack_vars[i].decl, nullptr, work);
     845                 :    55053333 : }
     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                 :    16073043 : add_scope_conflicts_1 (vars_ssa_cache &cache, basic_block bb, bitmap work, bool for_conflict)
     854                 :             : {
     855                 :    16073043 :   edge e;
     856                 :    16073043 :   edge_iterator ei;
     857                 :    16073043 :   gimple_stmt_iterator gsi;
     858                 :    16073043 :   walk_stmt_load_store_addr_fn visit;
     859                 :    16073043 :   use_operand_p use_p;
     860                 :    16073043 :   ssa_op_iter iter;
     861                 :    16073043 :   bool had_non_clobbers = false;
     862                 :             : 
     863                 :    16073043 :   bitmap_clear (work);
     864                 :             :   /* The copy what was alive out going from the edges. */
     865                 :    40627798 :   FOR_EACH_EDGE (e, ei, bb->preds)
     866                 :    24554755 :     bitmap_ior_into (work, (bitmap)e->src->aux);
     867                 :             : 
     868                 :    16073043 :   visit = for_conflict ? visit_conflict : visit_op;
     869                 :             : 
     870                 :             :   /* Addresses coming into the bb via phis are alive at the entry point. */
     871                 :    21276916 :   for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
     872                 :     5203873 :     add_scope_conflicts_2 (cache, gimple_phi_result (gsi_stmt (gsi)), work, visit_op);
     873                 :             : 
     874                 :   173157021 :   for (gsi = gsi_after_labels (bb); !gsi_end_p (gsi); gsi_next (&gsi))
     875                 :             :     {
     876                 :   157083978 :       gimple *stmt = gsi_stmt (gsi);
     877                 :             : 
     878                 :             :       /* Debug statements are not considered for liveness. */
     879                 :   157083978 :       if (is_gimple_debug (stmt))
     880                 :    94620730 :         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                 :    62463248 :       if (gimple_clobber_p (stmt))
     886                 :             :         {
     887                 :     3588309 :           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                 :     3588309 :           if (!VAR_P (lhs))
     892                 :      735393 :             continue;
     893                 :     2852916 :           unsigned indx = decl_stack_index (lhs);
     894                 :     2852916 :           if (indx != INVALID_STACK_INDEX)
     895                 :     2272880 :             bitmap_clear_bit (work, indx);
     896                 :             :         }
     897                 :             :       else
     898                 :             :         {
     899                 :    58874939 :           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                 :     4834574 :               bitmap_iterator bi;
     912                 :     4834574 :               unsigned i;
     913                 :     4834574 :               if (EDGE_COUNT (bb->preds) > 1)
     914                 :    12420722 :                 EXECUTE_IF_SET_IN_BITMAP (work, 0, i, bi)
     915                 :             :                   {
     916                 :    10994859 :                     class stack_var *a = &stack_vars[i];
     917                 :    10994859 :                     if (!a->conflicts)
     918                 :      262232 :                       a->conflicts = BITMAP_ALLOC (&stack_var_bitmap_obstack);
     919                 :    10994859 :                     bitmap_ior_into (a->conflicts, work);
     920                 :             :                   }
     921                 :     4834574 :               had_non_clobbers = true;
     922                 :             :             }
     923                 :    58874939 :           walk_stmt_load_store_addr_ops (stmt, work, visit, visit, visit);
     924                 :   108724399 :           FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE)
     925                 :    49849460 :             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                 :    16073043 :   if (for_conflict && !had_non_clobbers && EDGE_COUNT (bb->preds) > 1)
     932                 :             :     {
     933                 :      167218 :       bitmap_iterator bi;
     934                 :      167218 :       unsigned i;
     935                 :     1066705 :       EXECUTE_IF_SET_IN_BITMAP (work, 0, i, bi)
     936                 :             :         {
     937                 :      899487 :           class stack_var *a = &stack_vars[i];
     938                 :      899487 :           if (!a->conflicts)
     939                 :       39384 :             a->conflicts = BITMAP_ALLOC (&stack_var_bitmap_obstack);
     940                 :      899487 :           bitmap_ior_into (a->conflicts, work);
     941                 :             :         }
     942                 :             :     }
     943                 :    16073043 : }
     944                 :             : 
     945                 :             : /* Generate stack partition conflicts between all partitions that are
     946                 :             :    simultaneously live.  */
     947                 :             : 
     948                 :             : static void
     949                 :      236484 : 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                 :      236484 :   if (stack_vars_num == 1)
     954                 :       86609 :     return;
     955                 :             : 
     956                 :      149875 :   basic_block bb;
     957                 :      149875 :   bool changed;
     958                 :      149875 :   bitmap work = BITMAP_ALLOC (NULL);
     959                 :      149875 :   int *rpo;
     960                 :      149875 :   int n_bbs;
     961                 :             : 
     962                 :      149875 :   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                 :     5513092 :   FOR_ALL_BB_FN (bb, cfun)
     975                 :     5363217 :     bb->aux = BITMAP_ALLOC (&stack_var_bitmap_obstack);
     976                 :             : 
     977                 :      149875 :   rpo = XNEWVEC (int, last_basic_block_for_fn (cfun));
     978                 :      149875 :   n_bbs = pre_and_rev_post_order_compute (NULL, rpo, false);
     979                 :             : 
     980                 :      149875 :   changed = true;
     981                 :      607151 :   while (changed)
     982                 :             :     {
     983                 :             :       int i;
     984                 :             :       changed = false;
     985                 :    11316977 :       for (i = 0; i < n_bbs; i++)
     986                 :             :         {
     987                 :    11009576 :           bitmap active;
     988                 :    11009576 :           bb = BASIC_BLOCK_FOR_FN (cfun, rpo[i]);
     989                 :    11009576 :           active = (bitmap)bb->aux;
     990                 :    11009576 :           add_scope_conflicts_1 (cache, bb, work, false);
     991                 :    11009576 :           if (bitmap_ior_into (active, work))
     992                 :     4515246 :             changed = true;
     993                 :             :         }
     994                 :             :     }
     995                 :             : 
     996                 :     5213342 :   FOR_EACH_BB_FN (bb, cfun)
     997                 :     5063467 :     add_scope_conflicts_1 (cache, bb, work, true);
     998                 :             : 
     999                 :      149875 :   if (dump_file && (dump_flags & TDF_DETAILS))
    1000                 :           0 :     cache.dump (dump_file);
    1001                 :             : 
    1002                 :      149875 :   free (rpo);
    1003                 :      149875 :   BITMAP_FREE (work);
    1004                 :     5513092 :   FOR_ALL_BB_FN (bb, cfun)
    1005                 :     5363217 :     BITMAP_FREE (bb->aux);
    1006                 :      149875 : }
    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                 :    19674759 : stack_var_cmp (const void *a, const void *b)
    1013                 :             : {
    1014                 :    19674759 :   unsigned ia = *(const unsigned *)a;
    1015                 :    19674759 :   unsigned ib = *(const unsigned *)b;
    1016                 :    19674759 :   unsigned int aligna = stack_vars[ia].alignb;
    1017                 :    19674759 :   unsigned int alignb = stack_vars[ib].alignb;
    1018                 :    19674759 :   poly_int64 sizea = stack_vars[ia].size;
    1019                 :    19674759 :   poly_int64 sizeb = stack_vars[ib].size;
    1020                 :    19674759 :   tree decla = stack_vars[ia].decl;
    1021                 :    19674759 :   tree declb = stack_vars[ib].decl;
    1022                 :    19674759 :   bool largea, largeb;
    1023                 :    19674759 :   unsigned int uida, uidb;
    1024                 :             : 
    1025                 :             :   /* Primary compare on "large" alignment.  Large comes first.  */
    1026                 :    19674759 :   largea = (aligna * BITS_PER_UNIT > MAX_SUPPORTED_STACK_ALIGNMENT);
    1027                 :    19674759 :   largeb = (alignb * BITS_PER_UNIT > MAX_SUPPORTED_STACK_ALIGNMENT);
    1028                 :    19674759 :   if (largea != largeb)
    1029                 :           0 :     return (int)largeb - (int)largea;
    1030                 :             : 
    1031                 :             :   /* Secondary compare on size, decreasing  */
    1032                 :    19674759 :   int diff = compare_sizes_for_sort (sizeb, sizea);
    1033                 :    19674759 :   if (diff != 0)
    1034                 :     8616876 :     return diff;
    1035                 :             : 
    1036                 :             :   /* Tertiary compare on true alignment, decreasing.  */
    1037                 :    11057883 :   if (aligna < alignb)
    1038                 :             :     return -1;
    1039                 :    10712617 :   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                 :    10426040 :   if (TREE_CODE (decla) == SSA_NAME)
    1046                 :             :     {
    1047                 :       36734 :       if (TREE_CODE (declb) == SSA_NAME)
    1048                 :       32199 :         uida = SSA_NAME_VERSION (decla), uidb = SSA_NAME_VERSION (declb);
    1049                 :             :       else
    1050                 :             :         return -1;
    1051                 :             :     }
    1052                 :    10389306 :   else if (TREE_CODE (declb) == SSA_NAME)
    1053                 :             :     return 1;
    1054                 :             :   else
    1055                 :    10383853 :     uida = DECL_UID (decla), uidb = DECL_UID (declb);
    1056                 :    10416052 :   if (uida < uidb)
    1057                 :             :     return 1;
    1058                 :     5196939 :   if (uida > uidb)
    1059                 :     5196939 :     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                 :     1629546 : add_partitioned_vars_to_ptset (struct pt_solution *pt,
    1072                 :             :                                part_hashmap *decls_to_partitions,
    1073                 :             :                                hash_set<bitmap> *visited, bitmap temp)
    1074                 :             : {
    1075                 :     1629546 :   bitmap_iterator bi;
    1076                 :     1629546 :   unsigned i;
    1077                 :     1629546 :   bitmap *part;
    1078                 :             : 
    1079                 :     1629546 :   if (pt->anything
    1080                 :     1556236 :       || pt->vars == NULL
    1081                 :             :       /* The pointed-to vars bitmap is shared, it is enough to
    1082                 :             :          visit it once.  */
    1083                 :     3185782 :       || visited->add (pt->vars))
    1084                 :     1334719 :     return;
    1085                 :             : 
    1086                 :      294827 :   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                 :     1296963 :   EXECUTE_IF_SET_IN_BITMAP (pt->vars, 0, i, bi)
    1092                 :     1002136 :     if ((!temp
    1093                 :     1002136 :          || !bitmap_bit_p (temp, i))
    1094                 :     1623509 :         && (part = decls_to_partitions->get (i)))
    1095                 :      182470 :       bitmap_ior_into (temp, *part);
    1096                 :      294827 :   if (!bitmap_empty_p (temp))
    1097                 :      154027 :     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                 :      149875 : update_alias_info_with_stack_vars (void)
    1113                 :             : {
    1114                 :      149875 :   part_hashmap *decls_to_partitions = NULL;
    1115                 :      149875 :   unsigned i, j;
    1116                 :      149875 :   tree var = NULL_TREE;
    1117                 :             : 
    1118                 :     1264827 :   for (i = 0; i < stack_vars_num; i++)
    1119                 :             :     {
    1120                 :     1114952 :       bitmap part = NULL;
    1121                 :     1114952 :       tree name;
    1122                 :     1114952 :       struct ptr_info_def *pi;
    1123                 :             : 
    1124                 :             :       /* Not interested in partitions with single variable.  */
    1125                 :     1114952 :       if (stack_vars[i].representative != i
    1126                 :      853597 :           || stack_vars[i].next == EOC)
    1127                 :     1042479 :         continue;
    1128                 :             : 
    1129                 :       72473 :       if (!decls_to_partitions)
    1130                 :             :         {
    1131                 :       44776 :           decls_to_partitions = new part_hashmap;
    1132                 :       44776 :           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                 :       72473 :       if (var == NULL_TREE)
    1139                 :       44776 :         var = create_tmp_var (ptr_type_node);
    1140                 :       72473 :       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                 :       72473 :       part = BITMAP_GGC_ALLOC ();
    1145                 :      406301 :       for (j = i; j != EOC; j = stack_vars[j].next)
    1146                 :             :         {
    1147                 :      333828 :           tree decl = stack_vars[j].decl;
    1148                 :      333828 :           unsigned int uid = DECL_PT_UID (decl);
    1149                 :      333828 :           bitmap_set_bit (part, uid);
    1150                 :      333828 :           decls_to_partitions->put (uid, part);
    1151                 :      333828 :           cfun->gimple_df->decls_to_pointers->put (decl, name);
    1152                 :      333828 :           if (TREE_ADDRESSABLE (decl))
    1153                 :      296847 :             TREE_ADDRESSABLE (name) = 1;
    1154                 :             :         }
    1155                 :             : 
    1156                 :             :       /* Make the SSA name point to all partition members.  */
    1157                 :       72473 :       pi = get_ptr_info (name);
    1158                 :       72473 :       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                 :      149875 :   if (decls_to_partitions)
    1164                 :             :     {
    1165                 :       44776 :       unsigned i;
    1166                 :       44776 :       tree name;
    1167                 :       44776 :       hash_set<bitmap> visited;
    1168                 :       44776 :       bitmap temp = BITMAP_ALLOC (&stack_var_bitmap_obstack);
    1169                 :             : 
    1170                 :    16231711 :       FOR_EACH_SSA_NAME (i, name, cfun)
    1171                 :             :         {
    1172                 :    10556058 :           struct ptr_info_def *pi;
    1173                 :             : 
    1174                 :    19384281 :           if (POINTER_TYPE_P (TREE_TYPE (name))
    1175                 :    10636110 :               && ((pi = SSA_NAME_PTR_INFO (name)) != NULL))
    1176                 :     1539994 :             add_partitioned_vars_to_ptset (&pi->pt, decls_to_partitions,
    1177                 :             :                                            &visited, temp);
    1178                 :             :         }
    1179                 :             : 
    1180                 :       44776 :       add_partitioned_vars_to_ptset (&cfun->gimple_df->escaped,
    1181                 :             :                                      decls_to_partitions, &visited, temp);
    1182                 :       44776 :       add_partitioned_vars_to_ptset (&cfun->gimple_df->escaped_return,
    1183                 :             :                                      decls_to_partitions, &visited, temp);
    1184                 :       44776 :       delete decls_to_partitions;
    1185                 :       44776 :       BITMAP_FREE (temp);
    1186                 :       44776 :     }
    1187                 :      149875 : }
    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                 :      261355 : union_stack_vars (unsigned a, unsigned b)
    1195                 :             : {
    1196                 :      261355 :   class stack_var *vb = &stack_vars[b];
    1197                 :      261355 :   bitmap_iterator bi;
    1198                 :      261355 :   unsigned u;
    1199                 :             : 
    1200                 :      261355 :   gcc_assert (stack_vars[b].next == EOC);
    1201                 :             :    /* Add B to A's partition.  */
    1202                 :      261355 :   stack_vars[b].next = stack_vars[a].next;
    1203                 :      261355 :   stack_vars[b].representative = a;
    1204                 :      261355 :   stack_vars[a].next = b;
    1205                 :             : 
    1206                 :             :   /* Make sure A is big enough to hold B.  */
    1207                 :      261355 :   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                 :      261355 :   if (stack_vars[a].alignb < stack_vars[b].alignb)
    1211                 :        2635 :     stack_vars[a].alignb = stack_vars[b].alignb;
    1212                 :             : 
    1213                 :             :   /* Update the interference graph and merge the conflicts.  */
    1214                 :      261355 :   if (vb->conflicts)
    1215                 :             :     {
    1216                 :     1662247 :       EXECUTE_IF_SET_IN_BITMAP (vb->conflicts, 0, u, bi)
    1217                 :     1454105 :         add_stack_var_conflict (a, stack_vars[u].representative);
    1218                 :      208142 :       BITMAP_FREE (vb->conflicts);
    1219                 :             :     }
    1220                 :      261355 : }
    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                 :      236484 : partition_stack_vars (void)
    1239                 :             : {
    1240                 :      236484 :   unsigned si, sj, n = stack_vars_num;
    1241                 :             : 
    1242                 :      236484 :   stack_vars_sorted = XNEWVEC (unsigned, stack_vars_num);
    1243                 :     1438045 :   for (si = 0; si < n; ++si)
    1244                 :     1201561 :     stack_vars_sorted[si] = si;
    1245                 :             : 
    1246                 :      236484 :   if (n == 1)
    1247                 :             :     return;
    1248                 :             : 
    1249                 :      149875 :   qsort (stack_vars_sorted, n, sizeof (unsigned), stack_var_cmp);
    1250                 :             : 
    1251                 :     1264827 :   for (si = 0; si < n; ++si)
    1252                 :             :     {
    1253                 :     1114952 :       unsigned i = stack_vars_sorted[si];
    1254                 :     1114952 :       unsigned int ialign = stack_vars[i].alignb;
    1255                 :     1114952 :       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                 :     1114952 :       if (stack_vars[i].representative != i)
    1261                 :      261355 :         continue;
    1262                 :             : 
    1263                 :    12719548 :       for (sj = si + 1; sj < n; ++sj)
    1264                 :             :         {
    1265                 :    11866864 :           unsigned j = stack_vars_sorted[sj];
    1266                 :    11866864 :           unsigned int jalign = stack_vars[j].alignb;
    1267                 :    11866864 :           poly_int64 jsize = stack_vars[j].size;
    1268                 :             : 
    1269                 :             :           /* Ignore objects that aren't partition representatives.  */
    1270                 :    11866864 :           if (stack_vars[j].representative != j)
    1271                 :    11865951 :             continue;
    1272                 :             : 
    1273                 :             :           /* Do not mix objects of "small" (supported) alignment
    1274                 :             :              and "large" (unsupported) alignment.  */
    1275                 :    11277273 :           if ((ialign * BITS_PER_UNIT <= MAX_SUPPORTED_STACK_ALIGNMENT)
    1276                 :    11277273 :               != (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                 :    11277273 :           if (asan_sanitize_stack_p ()
    1284                 :        5097 :               && maybe_ne (isize, jsize)
    1285                 :    11278186 :               && ialign * BITS_PER_UNIT <= MAX_SUPPORTED_STACK_ALIGNMENT)
    1286                 :             :             break;
    1287                 :             : 
    1288                 :             :           /* Ignore conflicting objects.  */
    1289                 :    11276360 :           if (stack_var_conflict_p (i, j))
    1290                 :    11015005 :             continue;
    1291                 :             : 
    1292                 :             :           /* UNION the objects, placing J at OFFSET.  */
    1293                 :      261355 :           union_stack_vars (i, j);
    1294                 :             :         }
    1295                 :             :     }
    1296                 :             : 
    1297                 :      149875 :   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                 :     1992211 : expand_one_stack_var_at (tree decl, rtx base, unsigned base_align,
    1332                 :             :                          poly_int64 offset)
    1333                 :             : {
    1334                 :     1992211 :   unsigned align;
    1335                 :     1992211 :   rtx x;
    1336                 :             : 
    1337                 :             :   /* If this fails, we've overflowed the stack frame.  Error nicely?  */
    1338                 :     2277503 :   gcc_assert (known_eq (offset, trunc_int_for_mode (offset, Pmode)));
    1339                 :             : 
    1340                 :     1992211 :   if (hwasan_sanitize_stack_p ())
    1341                 :          90 :     x = targetm.memtag.add_tag (base, offset,
    1342                 :          90 :                                 hwasan_current_frame_tag ());
    1343                 :             :   else
    1344                 :     2277413 :     x = plus_constant (Pmode, base, offset);
    1345                 :             : 
    1346                 :     3984422 :   x = gen_rtx_MEM (TREE_CODE (decl) == SSA_NAME
    1347                 :      442008 :                    ? TYPE_MODE (TREE_TYPE (decl))
    1348                 :     1550203 :                    : 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                 :     1992211 :   if (stack_vars_base_reg_p (base))
    1355                 :     1989292 :     offset -= frame_phase;
    1356                 :     1992211 :   align = known_alignment (offset);
    1357                 :     1992211 :   align *= BITS_PER_UNIT;
    1358                 :     1992211 :   if (align == 0 || align > base_align)
    1359                 :      822849 :     align = base_align;
    1360                 :             : 
    1361                 :     1992211 :   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                 :     1550203 :       SET_DECL_ALIGN (decl, align);
    1368                 :     1550203 :       DECL_USER_ALIGN (decl) = 0;
    1369                 :             :     }
    1370                 :             : 
    1371                 :     1992211 :   set_rtl (decl, x);
    1372                 :             : 
    1373                 :     1992211 :   set_mem_align (x, align);
    1374                 :     1992211 : }
    1375                 :             : 
    1376                 :      236484 : 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                 :      238417 : expand_stack_vars (bool (*pred) (unsigned), class stack_vars_data *data)
    1399                 :             : {
    1400                 :      238417 :   unsigned si, i, j, n = stack_vars_num;
    1401                 :      238417 :   poly_uint64 large_size = 0, large_alloc = 0;
    1402                 :      238417 :   rtx large_base = NULL;
    1403                 :      238417 :   rtx large_untagged_base = NULL;
    1404                 :      238417 :   unsigned large_align = 0;
    1405                 :      238417 :   bool large_allocation_done = false;
    1406                 :      238417 :   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                 :      238417 :   large_align = stack_vars[stack_vars_sorted[0]].alignb * BITS_PER_UNIT;
    1412                 :      238417 :   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                 :     1444063 :   for (si = 0; si < n; ++si)
    1451                 :             :     {
    1452                 :     1205646 :       rtx base;
    1453                 :     1205646 :       unsigned base_align, alignb;
    1454                 :     1205646 :       poly_int64 offset = 0;
    1455                 :             : 
    1456                 :     1205646 :       i = stack_vars_sorted[si];
    1457                 :             : 
    1458                 :             :       /* Skip variables that aren't partition representatives, for now.  */
    1459                 :     1205646 :       if (stack_vars[i].representative != i)
    1460                 :     1467012 :         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                 :      944280 :       decl = stack_vars[i].decl;
    1465                 :      944280 :       if (TREE_CODE (decl) == SSA_NAME
    1466                 :      944280 :           ? SA.partition_to_pseudo[var_to_partition (SA.map, decl)] != NULL_RTX
    1467                 :      940866 :           : DECL_RTL (decl) != pc_rtx)
    1468                 :        3174 :         continue;
    1469                 :             : 
    1470                 :             :       /* Check the predicate to see whether this variable should be
    1471                 :             :          allocated in this pass.  */
    1472                 :      941106 :       if (pred && !pred (i))
    1473                 :         900 :         continue;
    1474                 :             : 
    1475                 :      940206 :       base = (hwasan_sanitize_stack_p ()
    1476                 :      940206 :               ? hwasan_frame_base ()
    1477                 :      940150 :               : virtual_stack_vars_rtx);
    1478                 :      940206 :       alignb = stack_vars[i].alignb;
    1479                 :      940206 :       if (alignb * BITS_PER_UNIT <= MAX_SUPPORTED_STACK_ALIGNMENT)
    1480                 :             :         {
    1481                 :      940206 :           poly_int64 hwasan_orig_offset;
    1482                 :      940206 :           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                 :      940206 :           HOST_WIDE_INT prev_offset;
    1505                 :      940206 :           if (asan_sanitize_stack_p ()
    1506                 :        3521 :               && pred
    1507                 :        2914 :               && frame_offset.is_constant (&prev_offset)
    1508                 :      940206 :               && stack_vars[i].size.is_constant ())
    1509                 :             :             {
    1510                 :        2914 :               if (data->asan_vec.is_empty ())
    1511                 :             :                 {
    1512                 :        1540 :                   align_frame_offset (ASAN_RED_ZONE_SIZE);
    1513                 :        1540 :                   prev_offset = frame_offset.to_constant ();
    1514                 :             :                 }
    1515                 :        2914 :               prev_offset = align_base (prev_offset,
    1516                 :             :                                         ASAN_MIN_RED_ZONE_SIZE,
    1517                 :             :                                         !FRAME_GROWS_DOWNWARD);
    1518                 :        2914 :               tree repr_decl = NULL_TREE;
    1519                 :        2914 :               unsigned HOST_WIDE_INT size
    1520                 :        2914 :                 = asan_var_and_redzone_size (stack_vars[i].size.to_constant ());
    1521                 :        2914 :               if (data->asan_vec.is_empty ())
    1522                 :        1540 :                 size = MAX (size, ASAN_RED_ZONE_SIZE);
    1523                 :             : 
    1524                 :        2914 :               unsigned HOST_WIDE_INT alignment = MAX (alignb,
    1525                 :             :                                                       ASAN_MIN_RED_ZONE_SIZE);
    1526                 :        2914 :               offset = alloc_stack_frame_space (size, alignment);
    1527                 :             : 
    1528                 :        2914 :               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                 :        2914 :               data->asan_vec.safe_push ((offset + stack_vars[i].size)
    1532                 :        2914 :                                         .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                 :        3422 :               for (j = i; j != EOC; j = stack_vars[j].next)
    1537                 :        2918 :                 if (asan_protect_stack_decl (stack_vars[j].decl)
    1538                 :        2918 :                     && DECL_NAME (stack_vars[j].decl))
    1539                 :             :                   {
    1540                 :        2410 :                     repr_decl = stack_vars[j].decl;
    1541                 :        2410 :                     break;
    1542                 :             :                   }
    1543                 :         508 :                 else if (repr_decl == NULL_TREE
    1544                 :         508 :                          && DECL_P (stack_vars[j].decl)
    1545                 :        1016 :                          && DECL_NAME (stack_vars[j].decl))
    1546                 :           0 :                   repr_decl = stack_vars[j].decl;
    1547                 :        2914 :               if (repr_decl == NULL_TREE)
    1548                 :         504 :                 repr_decl = stack_vars[i].decl;
    1549                 :        2914 :               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                 :        2914 :               if (asan_handled_variables != NULL
    1555                 :        2914 :                   && !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                 :        2914 :               data->asan_alignb = MAX (data->asan_alignb, alignb);
    1565                 :        2914 :               if (data->asan_base == NULL)
    1566                 :        1540 :                 data->asan_base = gen_reg_rtx (Pmode);
    1567                 :        2914 :               base = data->asan_base;
    1568                 :             : 
    1569                 :        2914 :               if (!STRICT_ALIGNMENT)
    1570                 :        2914 :                 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                 :      937292 :               offset = alloc_stack_frame_space (stack_vars[i].size, alignb);
    1579                 :      937292 :               base_align = crtl->max_used_stack_slot_alignment;
    1580                 :             : 
    1581                 :      937292 :               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                 :     2141767 :       for (j = i; j != EOC; j = stack_vars[j].next)
    1653                 :             :         {
    1654                 :     1201561 :           expand_one_stack_var_at (stack_vars[j].decl,
    1655                 :             :                                    base, base_align, offset);
    1656                 :             :         }
    1657                 :      940206 :       if (hwasan_sanitize_stack_p ())
    1658                 :          56 :         hwasan_increment_frame_tag ();
    1659                 :             :     }
    1660                 :             : 
    1661                 :      238417 :   gcc_assert (known_eq (large_alloc, large_size));
    1662                 :      238417 : }
    1663                 :             : 
    1664                 :             : /* Take into account all sizes of partitions and reset DECL_RTLs.  */
    1665                 :             : static poly_uint64
    1666                 :     1075417 : account_stack_vars (void)
    1667                 :             : {
    1668                 :     1075417 :   unsigned si, j, i, n = stack_vars_num;
    1669                 :     1075417 :   poly_uint64 size = 0;
    1670                 :             : 
    1671                 :     5576451 :   for (si = 0; si < n; ++si)
    1672                 :             :     {
    1673                 :     4501034 :       i = stack_vars_sorted[si];
    1674                 :             : 
    1675                 :             :       /* Skip variables that aren't partition representatives, for now.  */
    1676                 :     4501034 :       if (stack_vars[i].representative != i)
    1677                 :           0 :         continue;
    1678                 :             : 
    1679                 :     9002068 :       size += stack_vars[i].size;
    1680                 :     9002068 :       for (j = i; j != EOC; j = stack_vars[j].next)
    1681                 :     4501034 :         set_rtl (stack_vars[j].decl, NULL);
    1682                 :             :     }
    1683                 :     1075417 :   return size;
    1684                 :             : }
    1685                 :             : 
    1686                 :             : /* Record the RTL assignment X for the default def of PARM.  */
    1687                 :             : 
    1688                 :             : extern void
    1689                 :     4627341 : set_parm_rtl (tree parm, rtx x)
    1690                 :             : {
    1691                 :     4627341 :   gcc_assert (TREE_CODE (parm) == PARM_DECL
    1692                 :             :               || TREE_CODE (parm) == RESULT_DECL);
    1693                 :             : 
    1694                 :     4627341 :   if (x && !MEM_P (x))
    1695                 :             :     {
    1696                 :     2992293 :       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                 :     2992293 :       if (align > MAX_SUPPORTED_STACK_ALIGNMENT)
    1707                 :           0 :         align = GET_MODE_ALIGNMENT (Pmode);
    1708                 :             : 
    1709                 :     2992293 :       record_alignment_for_reg_var (align);
    1710                 :             :     }
    1711                 :             : 
    1712                 :     4627341 :   tree ssa = ssa_default_def (cfun, parm);
    1713                 :     4627341 :   if (!ssa)
    1714                 :     1056168 :     return set_rtl (parm, x);
    1715                 :             : 
    1716                 :     3571173 :   int part = var_to_partition (SA.map, ssa);
    1717                 :     3571173 :   gcc_assert (part != NO_PARTITION);
    1718                 :             : 
    1719                 :     3571173 :   bool changed = bitmap_bit_p (SA.partitions_for_parm_default_defs, part);
    1720                 :     3571173 :   gcc_assert (changed);
    1721                 :             : 
    1722                 :     3571173 :   set_rtl (ssa, x);
    1723                 :     3571173 :   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                 :      790650 : expand_one_stack_var_1 (tree var)
    1731                 :             : {
    1732                 :      790650 :   poly_uint64 size;
    1733                 :      790650 :   poly_int64 offset;
    1734                 :      790650 :   unsigned byte_align;
    1735                 :             : 
    1736                 :      790650 :   if (TREE_CODE (var) == SSA_NAME)
    1737                 :             :     {
    1738                 :      439146 :       tree type = TREE_TYPE (var);
    1739                 :      439146 :       size = tree_to_poly_uint64 (TYPE_SIZE_UNIT (type));
    1740                 :             :     }
    1741                 :             :   else
    1742                 :      351504 :     size = tree_to_poly_uint64 (DECL_SIZE_UNIT (var));
    1743                 :             : 
    1744                 :      790650 :   byte_align = align_local_variable (var, true);
    1745                 :             : 
    1746                 :             :   /* We handle highly aligned variables in expand_stack_vars.  */
    1747                 :      790650 :   gcc_assert (byte_align * BITS_PER_UNIT <= MAX_SUPPORTED_STACK_ALIGNMENT);
    1748                 :             : 
    1749                 :      790650 :   rtx base;
    1750                 :      790650 :   if (hwasan_sanitize_stack_p ())
    1751                 :             :     {
    1752                 :             :       /* Allocate zero bytes to align the stack.  */
    1753                 :          34 :       poly_int64 hwasan_orig_offset
    1754                 :          34 :         = align_frame_offset (HWASAN_TAG_GRANULE_SIZE);
    1755                 :          34 :       offset = alloc_stack_frame_space (size, byte_align);
    1756                 :          34 :       align_frame_offset (HWASAN_TAG_GRANULE_SIZE);
    1757                 :          34 :       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                 :          34 :       hwasan_record_stack_var (virtual_stack_vars_rtx, base,
    1767                 :             :                                hwasan_orig_offset, frame_offset);
    1768                 :             :     }
    1769                 :             :   else
    1770                 :             :     {
    1771                 :      790616 :       offset = alloc_stack_frame_space (size, byte_align);
    1772                 :      790616 :       base = virtual_stack_vars_rtx;
    1773                 :             :     }
    1774                 :             : 
    1775                 :      790650 :   expand_one_stack_var_at (var, base,
    1776                 :             :                            crtl->max_used_stack_slot_alignment, offset);
    1777                 :             : 
    1778                 :      790650 :   if (hwasan_sanitize_stack_p ())
    1779                 :          34 :     hwasan_increment_frame_tag ();
    1780                 :      790650 : }
    1781                 :             : 
    1782                 :             : /* Wrapper for expand_one_stack_var_1 that checks SSA_NAMEs are
    1783                 :             :    already assigned some MEM.  */
    1784                 :             : 
    1785                 :             : static void
    1786                 :      351504 : expand_one_stack_var (tree var)
    1787                 :             : {
    1788                 :      351504 :   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                 :      351504 :   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                 :        1090 : 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                 :    40157476 : record_alignment_for_reg_var (unsigned int align)
    1817                 :             : {
    1818                 :    40157476 :   if (SUPPORTS_STACK_ALIGNMENT
    1819                 :    40157476 :       && crtl->stack_alignment_estimated < align)
    1820                 :             :     {
    1821                 :             :       /* stack_alignment_estimated shouldn't change after stack
    1822                 :             :          realign decision made */
    1823                 :     1694891 :       gcc_assert (!crtl->stack_realign_processed);
    1824                 :     1694891 :       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                 :    40157476 :   if (crtl->stack_alignment_needed < align)
    1830                 :      550723 :     crtl->stack_alignment_needed = align;
    1831                 :    40157476 :   if (crtl->max_used_stack_slot_alignment < align)
    1832                 :      550723 :     crtl->max_used_stack_slot_alignment = align;
    1833                 :    40157476 : }
    1834                 :             : 
    1835                 :             : /* Create RTL for an SSA partition.  */
    1836                 :             : 
    1837                 :             : static void
    1838                 :    22036651 : expand_one_ssa_partition (tree var)
    1839                 :             : {
    1840                 :    22036651 :   int part = var_to_partition (SA.map, var);
    1841                 :    22036651 :   gcc_assert (part != NO_PARTITION);
    1842                 :             : 
    1843                 :    22036651 :   if (SA.partition_to_pseudo[part])
    1844                 :             :     return;
    1845                 :             : 
    1846                 :    22036651 :   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                 :    22036651 :   if (align > MAX_SUPPORTED_STACK_ALIGNMENT)
    1853                 :           0 :     align = GET_MODE_ALIGNMENT (Pmode);
    1854                 :             : 
    1855                 :    22036651 :   record_alignment_for_reg_var (align);
    1856                 :             : 
    1857                 :    22036651 :   if (!use_register_for_decl (var))
    1858                 :             :     {
    1859                 :      442008 :       if (defer_stack_allocation (var, true))
    1860                 :        2862 :         add_stack_var (var, true);
    1861                 :             :       else
    1862                 :      439146 :         expand_one_stack_var_1 (var);
    1863                 :      442008 :       return;
    1864                 :             :     }
    1865                 :             : 
    1866                 :    21594643 :   machine_mode reg_mode = promote_ssa_mode (var, NULL);
    1867                 :    21594643 :   rtx x = gen_reg_rtx (reg_mode);
    1868                 :             : 
    1869                 :    21594643 :   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                 :    21594643 :   if (reg_mode != TYPE_MODE (TREE_TYPE (var))
    1877                 :    21594643 :       && 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                 :    48311054 : adjust_one_expanded_partition_var (tree var)
    1886                 :             : {
    1887                 :    48311054 :   if (!var)
    1888                 :             :     return;
    1889                 :             : 
    1890                 :    48311054 :   tree decl = SSA_NAME_VAR (var);
    1891                 :             : 
    1892                 :    48311054 :   int part = var_to_partition (SA.map, var);
    1893                 :    48311054 :   if (part == NO_PARTITION)
    1894                 :             :     return;
    1895                 :             : 
    1896                 :    30983110 :   rtx x = SA.partition_to_pseudo[part];
    1897                 :             : 
    1898                 :    30983110 :   gcc_assert (x);
    1899                 :             : 
    1900                 :    30983110 :   set_rtl (var, x);
    1901                 :             : 
    1902                 :    30983110 :   if (!REG_P (x))
    1903                 :             :     return;
    1904                 :             : 
    1905                 :             :   /* Note if the object is a user variable.  */
    1906                 :    29015631 :   if (decl && !DECL_ARTIFICIAL (decl))
    1907                 :     4144503 :     mark_user_reg (x);
    1908                 :             : 
    1909                 :    29015631 :   if (POINTER_TYPE_P (decl ? TREE_TYPE (decl) : TREE_TYPE (var)))
    1910                 :     7396801 :     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                 :      629514 : expand_one_register_var (tree var)
    1918                 :             : {
    1919                 :      629514 :   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                 :      629514 :   tree decl = var;
    1933                 :      629514 :   tree type = TREE_TYPE (decl);
    1934                 :      629514 :   machine_mode reg_mode = promote_decl_mode (decl, NULL);
    1935                 :      629514 :   rtx x = gen_reg_rtx (reg_mode);
    1936                 :             : 
    1937                 :      629514 :   set_rtl (var, x);
    1938                 :             : 
    1939                 :             :   /* Note if the object is a user variable.  */
    1940                 :      629514 :   if (!DECL_ARTIFICIAL (decl))
    1941                 :      115106 :     mark_user_reg (x);
    1942                 :             : 
    1943                 :      629514 :   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                 :          37 : expand_one_error_var (tree var)
    1953                 :             : {
    1954                 :          37 :   machine_mode mode = DECL_MODE (var);
    1955                 :          37 :   rtx x;
    1956                 :             : 
    1957                 :          37 :   if (mode == BLKmode)
    1958                 :           1 :     x = gen_rtx_MEM (BLKmode, const0_rtx);
    1959                 :          36 :   else if (mode == VOIDmode)
    1960                 :           0 :     x = const0_rtx;
    1961                 :             :   else
    1962                 :          36 :     x = gen_reg_rtx (mode);
    1963                 :             : 
    1964                 :          37 :   SET_DECL_RTL (var, x);
    1965                 :          37 : }
    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                 :     6626102 : defer_stack_allocation (tree var, bool toplevel)
    1977                 :             : {
    1978                 :     6626102 :   tree size_unit = TREE_CODE (var) == SSA_NAME
    1979                 :     6626102 :     ? TYPE_SIZE_UNIT (TREE_TYPE (var))
    1980                 :     6626102 :     : DECL_SIZE_UNIT (var);
    1981                 :     6626102 :   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                 :     6626102 :   bool smallish
    1986                 :     6626102 :     = (poly_int_tree_p (size_unit, &size)
    1987                 :     6626102 :        && (estimated_poly_value (size)
    1988                 :     6626102 :            < 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                 :     6626102 :   if (flag_stack_protect || asan_sanitize_stack_p ())
    1994                 :       11933 :     return true;
    1995                 :             : 
    1996                 :     6614169 :   unsigned int align = TREE_CODE (var) == SSA_NAME
    1997                 :     6614169 :     ? TYPE_ALIGN (TREE_TYPE (var))
    1998                 :     6172716 :     : 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                 :     6614169 :   bool ignored = TREE_CODE (var) == SSA_NAME
    2006                 :     6620307 :     ? !SSAVAR (var) || DECL_IGNORED_P (SSA_NAME_VAR (var))
    2007                 :     6172716 :     : 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                 :     6614169 :   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                 :     5123077 :   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                 :     4498009 :   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                 :    15422776 : expand_one_var (tree var, bool toplevel, bool really_expand,
    2044                 :             :                 bitmap forced_stack_var = NULL)
    2045                 :             : {
    2046                 :    15422776 :   unsigned int align = BITS_PER_UNIT;
    2047                 :    15422776 :   tree origvar = var;
    2048                 :             : 
    2049                 :    15422776 :   var = SSAVAR (var);
    2050                 :             : 
    2051                 :    15422776 :   if (TREE_TYPE (var) != error_mark_node && VAR_P (var))
    2052                 :             :     {
    2053                 :    15422776 :       if (is_global_var (var))
    2054                 :      294244 :         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                 :    15128532 :       if (TREE_STATIC (var)
    2063                 :    15128532 :           || DECL_EXTERNAL (var)
    2064                 :    30257064 :           || (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                 :    15128532 :       else if (DECL_HAS_VALUE_EXPR_P (var)
    2069                 :    15128532 :                || (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                 :       16108 :         align = crtl->stack_alignment_estimated;
    2075                 :             :       else
    2076                 :    15112424 :         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                 :    15128532 :       if (align > MAX_SUPPORTED_STACK_ALIGNMENT)
    2081                 :           0 :         align = GET_MODE_ALIGNMENT (Pmode);
    2082                 :             :     }
    2083                 :             : 
    2084                 :    15128532 :   record_alignment_for_reg_var (align);
    2085                 :             : 
    2086                 :    15128532 :   poly_uint64 size;
    2087                 :    15128532 :   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                 :    15128532 :   if (!VAR_P (var) && TREE_CODE (origvar) != SSA_NAME)
    2098                 :             :     ;
    2099                 :    15128532 :   else if (DECL_EXTERNAL (var))
    2100                 :             :     ;
    2101                 :    15128532 :   else if (DECL_HAS_VALUE_EXPR_P (var))
    2102                 :             :     ;
    2103                 :    15112569 :   else if (TREE_STATIC (var))
    2104                 :             :     ;
    2105                 :    15112569 :   else if (TREE_CODE (origvar) != SSA_NAME && DECL_RTL_SET_P (var))
    2106                 :             :     ;
    2107                 :    15112288 :   else if (TREE_TYPE (var) == error_mark_node)
    2108                 :             :     {
    2109                 :           0 :       if (really_expand)
    2110                 :           0 :         expand_one_error_var (var);
    2111                 :             :     }
    2112                 :    15112288 :   else if (VAR_P (var) && DECL_HARD_REGISTER (var))
    2113                 :             :     {
    2114                 :        4126 :       if (really_expand)
    2115                 :             :         {
    2116                 :        1090 :           expand_one_hard_reg_var (var);
    2117                 :        1090 :           if (!DECL_HARD_REGISTER (var))
    2118                 :             :             /* Invalid register specification.  */
    2119                 :          37 :             expand_one_error_var (var);
    2120                 :             :         }
    2121                 :             :     }
    2122                 :    15108162 :   else if (use_register_for_decl (var)
    2123                 :    15108162 :            && (!forced_stack_var
    2124                 :      639119 :                || !bitmap_bit_p (forced_stack_var, DECL_UID (var))))
    2125                 :             :     {
    2126                 :     8924068 :       if (really_expand)
    2127                 :      629514 :         expand_one_register_var (origvar);
    2128                 :             :     }
    2129                 :     6184094 :   else if (!poly_int_tree_p (DECL_SIZE_UNIT (var), &size)
    2130                 :     6184094 :            || !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                 :     6184094 :   else if (defer_stack_allocation (var, toplevel))
    2145                 :     5699733 :     add_stack_var (origvar, really_expand);
    2146                 :             :   else
    2147                 :             :     {
    2148                 :      484361 :       if (really_expand)
    2149                 :             :         {
    2150                 :      351265 :           if (lookup_attribute ("naked",
    2151                 :      351265 :                                 DECL_ATTRIBUTES (current_function_decl)))
    2152                 :           0 :             error ("cannot allocate stack for variable %q+D, naked function",
    2153                 :             :                    var);
    2154                 :             : 
    2155                 :      351265 :           expand_one_stack_var (origvar);
    2156                 :             :         }
    2157                 :      484361 :       return size;
    2158                 :             :     }
    2159                 :    14644171 :   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                 :    16628330 : expand_used_vars_for_block (tree block, bool toplevel, bitmap forced_stack_vars)
    2170                 :             : {
    2171                 :    16628330 :   tree t;
    2172                 :             : 
    2173                 :             :   /* Expand all variables at this level.  */
    2174                 :    35047966 :   for (t = BLOCK_VARS (block); t ; t = DECL_CHAIN (t))
    2175                 :    18419636 :     if (TREE_USED (t)
    2176                 :    18419636 :         && ((!VAR_P (t) && TREE_CODE (t) != RESULT_DECL)
    2177                 :      789263 :             || !DECL_NONSHAREABLE (t)))
    2178                 :      789263 :       expand_one_var (t, toplevel, true, forced_stack_vars);
    2179                 :             : 
    2180                 :             :   /* Expand all variables at containing levels.  */
    2181                 :    31800558 :   for (t = BLOCK_SUBBLOCKS (block); t ; t = BLOCK_CHAIN (t))
    2182                 :    15172228 :     expand_used_vars_for_block (t, false, forced_stack_vars);
    2183                 :    16628330 : }
    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                 :    16628330 : clear_tree_used (tree block)
    2190                 :             : {
    2191                 :    16628330 :   tree t;
    2192                 :             : 
    2193                 :    35047966 :   for (t = BLOCK_VARS (block); t ; t = DECL_CHAIN (t))
    2194                 :             :     /* if (!TREE_STATIC (t) && !DECL_EXTERNAL (t)) */
    2195                 :      987070 :     if ((!VAR_P (t) && TREE_CODE (t) != RESULT_DECL)
    2196                 :    18419636 :         || !DECL_NONSHAREABLE (t))
    2197                 :    18419636 :       TREE_USED (t) = 0;
    2198                 :             : 
    2199                 :    31800558 :   for (t = BLOCK_SUBBLOCKS (block); t ; t = BLOCK_CHAIN (t))
    2200                 :    15172228 :     clear_tree_used (t);
    2201                 :    16628330 : }
    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                 :        2625 : stack_protect_classify_type (tree type)
    2212                 :             : {
    2213                 :        2625 :   unsigned int ret = 0;
    2214                 :        2625 :   tree t;
    2215                 :             : 
    2216                 :        2625 :   switch (TREE_CODE (type))
    2217                 :             :     {
    2218                 :         625 :     case ARRAY_TYPE:
    2219                 :         625 :       t = TYPE_MAIN_VARIANT (TREE_TYPE (type));
    2220                 :         625 :       if (t == char_type_node
    2221                 :         175 :           || t == signed_char_type_node
    2222                 :         175 :           || t == unsigned_char_type_node)
    2223                 :             :         {
    2224                 :         450 :           unsigned HOST_WIDE_INT max = param_ssp_buffer_size;
    2225                 :         450 :           unsigned HOST_WIDE_INT len;
    2226                 :             : 
    2227                 :         450 :           if (!TYPE_SIZE_UNIT (type)
    2228                 :         450 :               || !tree_fits_uhwi_p (TYPE_SIZE_UNIT (type)))
    2229                 :             :             len = max;
    2230                 :             :           else
    2231                 :         450 :             len = tree_to_uhwi (TYPE_SIZE_UNIT (type));
    2232                 :             : 
    2233                 :         450 :           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                 :        1010 :     case UNION_TYPE:
    2243                 :        1010 :     case QUAL_UNION_TYPE:
    2244                 :        1010 :     case RECORD_TYPE:
    2245                 :        1010 :       ret = SPCT_HAS_AGGREGATE;
    2246                 :       10875 :       for (t = TYPE_FIELDS (type); t ; t = TREE_CHAIN (t))
    2247                 :        9865 :         if (TREE_CODE (t) == FIELD_DECL)
    2248                 :        1673 :           ret |= stack_protect_classify_type (TREE_TYPE (t));
    2249                 :             :       break;
    2250                 :             : 
    2251                 :             :     default:
    2252                 :             :       break;
    2253                 :             :     }
    2254                 :             : 
    2255                 :        2625 :   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                 :          24 :     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                 :        3436 : asan_decl_phase_3 (unsigned i)
    2315                 :             : {
    2316                 :        4043 :   while (i != EOC)
    2317                 :             :     {
    2318                 :        3436 :       if (asan_protect_stack_decl (stack_vars[i].decl))
    2319                 :             :         return true;
    2320                 :         607 :       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                 :     7724511 : init_vars_expansion (void)
    2372                 :             : {
    2373                 :             :   /* Conflict bitmaps, and a few related temporary bitmaps, go here.  */
    2374                 :     7724511 :   bitmap_obstack_initialize (&stack_var_bitmap_obstack);
    2375                 :             : 
    2376                 :             :   /* A map from decl to stack partition.  */
    2377                 :     7724511 :   decl_to_stack_part = new hash_map<tree, unsigned>;
    2378                 :             : 
    2379                 :             :   /* Initialize local stack smashing state.  */
    2380                 :     7724511 :   has_protected_decls = false;
    2381                 :     7724511 :   has_short_buffer = false;
    2382                 :     7724511 :   if (hwasan_sanitize_stack_p ())
    2383                 :        1197 :     hwasan_record_frame_init ();
    2384                 :     7724511 : }
    2385                 :             : 
    2386                 :             : /* Free up stack variable graph data.  */
    2387                 :             : static void
    2388                 :     7724511 : fini_vars_expansion (void)
    2389                 :             : {
    2390                 :     7724511 :   bitmap_obstack_release (&stack_var_bitmap_obstack);
    2391                 :     7724511 :   if (stack_vars)
    2392                 :     1311901 :     XDELETEVEC (stack_vars);
    2393                 :     7724511 :   if (stack_vars_sorted)
    2394                 :     1311901 :     XDELETEVEC (stack_vars_sorted);
    2395                 :     7724511 :   stack_vars = NULL;
    2396                 :     7724511 :   stack_vars_sorted = NULL;
    2397                 :     7724511 :   stack_vars_alloc = stack_vars_num = 0;
    2398                 :    15449022 :   delete decl_to_stack_part;
    2399                 :     7724511 :   decl_to_stack_part = NULL;
    2400                 :     7724511 : }
    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                 :     6268409 : estimated_stack_frame_size (struct cgraph_node *node)
    2412                 :             : {
    2413                 :     6268409 :   poly_int64 size = 0;
    2414                 :     6268409 :   unsigned i;
    2415                 :     6268409 :   tree var;
    2416                 :     6268409 :   struct function *fn = DECL_STRUCT_FUNCTION (node->decl);
    2417                 :             : 
    2418                 :     6268409 :   push_cfun (fn);
    2419                 :             : 
    2420                 :     6268409 :   init_vars_expansion ();
    2421                 :             : 
    2422                 :    24879872 :   FOR_EACH_LOCAL_DECL (fn, i, var)
    2423                 :    13503824 :     if (auto_var_in_fn_p (var, fn->decl))
    2424                 :    12931842 :       size += expand_one_var (var, true, false);
    2425                 :             : 
    2426                 :     6268409 :   if (stack_vars_num > 0)
    2427                 :             :     {
    2428                 :             :       /* Fake sorting the stack vars for account_stack_vars ().  */
    2429                 :     1075417 :       stack_vars_sorted = XNEWVEC (unsigned , stack_vars_num);
    2430                 :     5576451 :       for (i = 0; i < stack_vars_num; ++i)
    2431                 :     4501034 :         stack_vars_sorted[i] = i;
    2432                 :     1075417 :       size += account_stack_vars ();
    2433                 :             :     }
    2434                 :             : 
    2435                 :     6268409 :   fini_vars_expansion ();
    2436                 :     6268409 :   pop_cfun ();
    2437                 :     6268409 :   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                 :        1859 :   FOR_ALL_BB_FN (bb, cfun)
    2448                 :        2942 :     for (gimple_stmt_iterator gsi = gsi_start_bb (bb);
    2449                 :        3962 :          !gsi_end_p (gsi); gsi_next (&gsi))
    2450                 :             :       {
    2451                 :        2520 :         gimple *stmt = gsi_stmt (gsi);
    2452                 :             :         /* This assumes that calls to internal-only functions never
    2453                 :             :            use a return slot.  */
    2454                 :        2520 :         if (is_gimple_call (stmt)
    2455                 :         534 :             && !gimple_call_internal_p (stmt)
    2456                 :        3045 :             && 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                 :     1456102 : expand_used_vars (bitmap forced_stack_vars)
    2467                 :             : {
    2468                 :     1456102 :   tree var, outer_block = DECL_INITIAL (current_function_decl);
    2469                 :     1456102 :   auto_vec<tree> maybe_local_decls;
    2470                 :     1456102 :   rtx_insn *var_end_seq = NULL;
    2471                 :     1456102 :   unsigned i;
    2472                 :     1456102 :   unsigned len;
    2473                 :     1456102 :   bool gen_stack_protect_signal = false;
    2474                 :             : 
    2475                 :             :   /* Compute the phase of the stack frame for this function.  */
    2476                 :     1456102 :   {
    2477                 :     1456102 :     int align = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT;
    2478                 :     1456102 :     int off = targetm.starting_frame_offset () % align;
    2479                 :     1456102 :     frame_phase = off ? align - off : 0;
    2480                 :             :   }
    2481                 :             : 
    2482                 :             :   /* Set TREE_USED on all variables in the local_decls.  */
    2483                 :    10445539 :   FOR_EACH_LOCAL_DECL (cfun, i, var)
    2484                 :     7769954 :     TREE_USED (var) = 1;
    2485                 :             :   /* Clear TREE_USED on all variables associated with a block scope.  */
    2486                 :     1456102 :   clear_tree_used (DECL_INITIAL (current_function_decl));
    2487                 :             : 
    2488                 :     1456102 :   init_vars_expansion ();
    2489                 :             : 
    2490                 :     1456102 :   if (targetm.use_pseudo_pic_reg ())
    2491                 :       79530 :     pic_offset_table_rtx = gen_reg_rtx (Pmode);
    2492                 :             : 
    2493                 :    27063926 :   for (i = 0; i < SA.map->num_partitions; i++)
    2494                 :             :     {
    2495                 :    25607824 :       if (bitmap_bit_p (SA.partitions_for_parm_default_defs, i))
    2496                 :     3571173 :         continue;
    2497                 :             : 
    2498                 :    22036651 :       tree var = partition_to_var (SA.map, i);
    2499                 :             : 
    2500                 :    44073302 :       gcc_assert (!virtual_operand_p (var));
    2501                 :             : 
    2502                 :    22036651 :       expand_one_ssa_partition (var);
    2503                 :             :     }
    2504                 :             : 
    2505                 :     1456102 :   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                 :     1456102 :   len = vec_safe_length (cfun->local_decls);
    2512                 :     9226056 :   FOR_EACH_LOCAL_DECL (cfun, i, var)
    2513                 :             :     {
    2514                 :     7769954 :       bool expand_now = false;
    2515                 :             : 
    2516                 :             :       /* Expanded above already.  */
    2517                 :     7769954 :       if (is_gimple_reg (var))
    2518                 :             :         {
    2519                 :     5362531 :           TREE_USED (var) = 0;
    2520                 :     5362531 :           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                 :     2407423 :       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                 :     2196690 :       else if (TREE_USED (var))
    2536                 :     1701671 :         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                 :     2407423 :       TREE_USED (var) = 1;
    2541                 :             : 
    2542                 :     2407423 :       if (expand_now)
    2543                 :     1701671 :         expand_one_var (var, true, true, forced_stack_vars);
    2544                 :             : 
    2545                 :      705752 :     next:
    2546                 :     7769954 :       if (DECL_ARTIFICIAL (var) && !DECL_IGNORED_P (var))
    2547                 :             :         {
    2548                 :      423609 :           rtx rtl = DECL_RTL_IF_SET (var);
    2549                 :             : 
    2550                 :             :           /* Keep artificial non-ignored vars in cfun->local_decls
    2551                 :             :              chain until instantiate_decls.  */
    2552                 :      320982 :           if (rtl && (MEM_P (rtl) || GET_CODE (rtl) == CONCAT))
    2553                 :       18939 :             add_local_decl (cfun, var);
    2554                 :      102627 :           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                 :      102627 :             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                 :     1456102 :   if (!vec_safe_is_empty (cfun->local_decls))
    2574                 :      822884 :     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                 :     1456102 :   expand_used_vars_for_block (outer_block, true, forced_stack_vars);
    2579                 :             : 
    2580                 :     1456102 :   tree attribs = DECL_ATTRIBUTES (current_function_decl);
    2581                 :     1456102 :   if (stack_vars_num > 0)
    2582                 :             :     {
    2583                 :      236484 :       bool has_addressable_vars = false;
    2584                 :             : 
    2585                 :      236484 :       add_scope_conflicts ();
    2586                 :             : 
    2587                 :             :       /* If stack protection is enabled, we don't share space between
    2588                 :             :          vulnerable data and non-vulnerable data.  */
    2589                 :      236484 :       if (flag_stack_protect != 0
    2590                 :         223 :           && !lookup_attribute ("no_stack_protector", attribs)
    2591                 :      236707 :           && (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                 :      236484 :       if (flag_stack_protect == SPCT_FLAG_STRONG && has_addressable_vars)
    2597                 :      236484 :         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                 :      236484 :       partition_stack_vars ();
    2602                 :      236484 :       if (dump_file)
    2603                 :          29 :         dump_stack_var_partition ();
    2604                 :             :     }
    2605                 :             : 
    2606                 :             : 
    2607                 :     1456102 :   if (!lookup_attribute ("no_stack_protector", attribs))
    2608                 :     1456093 :     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                 :         142 :       case SPCT_FLAG_DEFAULT:
    2623                 :         142 :         if (cfun->calls_alloca
    2624                 :         139 :             || has_protected_decls
    2625                 :         228 :             || 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                 :     1456102 :   if (stack_vars_num > 0)
    2640                 :             :     {
    2641                 :      236484 :       class stack_vars_data data;
    2642                 :             : 
    2643                 :      236484 :       data.asan_base = NULL_RTX;
    2644                 :      236484 :       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                 :      236484 :       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                 :      236484 :       if (asan_sanitize_stack_p ())
    2666                 :             :         /* Phase 3, any partitions that need asan protection
    2667                 :             :            in addition to phase 1 and 2.  */
    2668                 :        1728 :         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                 :      236484 :       HOST_WIDE_INT prev_offset;
    2673                 :      238024 :       if (!data.asan_vec.is_empty ()
    2674                 :        1540 :           && frame_offset.is_constant (&prev_offset))
    2675                 :             :         {
    2676                 :        1540 :           HOST_WIDE_INT offset, sz, redzonesz;
    2677                 :        1540 :           redzonesz = ASAN_RED_ZONE_SIZE;
    2678                 :        1540 :           sz = data.asan_vec[0] - prev_offset;
    2679                 :        1540 :           if (data.asan_alignb > ASAN_RED_ZONE_SIZE
    2680                 :        1540 :               && 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                 :        1540 :           offset = (alloc_stack_frame_space (redzonesz, ASAN_RED_ZONE_SIZE)
    2687                 :        1540 :                     .to_constant ());
    2688                 :        1540 :           data.asan_vec.safe_push (prev_offset);
    2689                 :        1540 :           data.asan_vec.safe_push (offset);
    2690                 :             :           /* Leave space for alignment if STRICT_ALIGNMENT.  */
    2691                 :        1540 :           if (STRICT_ALIGNMENT)
    2692                 :             :             alloc_stack_frame_space ((GET_MODE_ALIGNMENT (SImode)
    2693                 :             :                                       << ASAN_SHADOW_SHIFT)
    2694                 :             :                                      / BITS_PER_UNIT, 1);
    2695                 :             : 
    2696                 :        1540 :           var_end_seq
    2697                 :        3080 :             = 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                 :        1540 :                                           data.asan_vec.length ());
    2703                 :             :         }
    2704                 :             : 
    2705                 :      236484 :       expand_stack_vars (NULL, &data);
    2706                 :      236484 :     }
    2707                 :             : 
    2708                 :     1456102 :   if (hwasan_sanitize_stack_p ())
    2709                 :         453 :     hwasan_emit_prologue ();
    2710                 :     1456102 :   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                 :     1455924 :   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                 :     1455924 :   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                 :         453 :     var_end_seq = hwasan_emit_untag_frame (hwasan_get_frame_extent (),
    2727                 :             :                                            virtual_stack_vars_rtx);
    2728                 :             : 
    2729                 :     1456102 :   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                 :     1600392 :   FOR_EACH_VEC_ELT_REVERSE (maybe_local_decls, i, var)
    2735                 :             :     {
    2736                 :      102627 :       rtx rtl = DECL_RTL_IF_SET (var);
    2737                 :             : 
    2738                 :             :       /* Keep artificial non-ignored vars in cfun->local_decls
    2739                 :             :          chain until instantiate_decls.  */
    2740                 :        4155 :       if (rtl && (MEM_P (rtl) || GET_CODE (rtl) == CONCAT))
    2741                 :        4037 :         add_local_decl (cfun, var);
    2742                 :             :     }
    2743                 :             : 
    2744                 :             :   /* If the target requires that FRAME_OFFSET be aligned, do it.  */
    2745                 :     1456102 :   if (STACK_ALIGNMENT_NEEDED)
    2746                 :             :     {
    2747                 :     1456102 :       HOST_WIDE_INT align = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT;
    2748                 :     1456102 :       if (FRAME_GROWS_DOWNWARD)
    2749                 :     1456102 :         frame_offset = aligned_lower_bound (frame_offset, align);
    2750                 :             :       else
    2751                 :             :         frame_offset = aligned_upper_bound (frame_offset, align);
    2752                 :             :     }
    2753                 :             : 
    2754                 :     1456102 :   return var_end_seq;
    2755                 :     1456102 : }
    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                 :    41514397 : maybe_dump_rtl_for_gimple_stmt (gimple *stmt, rtx_insn *since)
    2764                 :             : {
    2765                 :    41514397 :   if (dump_file && (dump_flags & TDF_DETAILS))
    2766                 :             :     {
    2767                 :         383 :       fprintf (dump_file, "\n;; ");
    2768                 :         383 :       print_gimple_stmt (dump_file, stmt, 0,
    2769                 :             :                          TDF_SLIM | (dump_flags & TDF_LINENO));
    2770                 :         383 :       fprintf (dump_file, "\n");
    2771                 :             : 
    2772                 :         383 :       print_rtl (dump_file, since ? NEXT_INSN (since) : since);
    2773                 :             :     }
    2774                 :    41514397 : }
    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                 :     7691630 : label_rtx_for_bb (basic_block bb)
    2788                 :             : {
    2789                 :     7691630 :   if (bb->flags & BB_RTL)
    2790                 :           0 :     return block_label (bb);
    2791                 :             : 
    2792                 :     7691630 :   if ((unsigned) bb->index < head_end_for_bb.length ()
    2793                 :     7691630 :       && head_end_for_bb[bb->index].first)
    2794                 :             :     {
    2795                 :     1696507 :       if (!LABEL_P (head_end_for_bb[bb->index].first))
    2796                 :             :         {
    2797                 :     1008351 :           head_end_for_bb[bb->index].first
    2798                 :     2016702 :             = emit_label_before (gen_label_rtx (),
    2799                 :     1008351 :                                  head_end_for_bb[bb->index].first);
    2800                 :             :         }
    2801                 :     1696507 :       return as_a <rtx_code_label *> (head_end_for_bb[bb->index].first);
    2802                 :             :     }
    2803                 :             : 
    2804                 :     5995123 :   rtx_code_label **elt = lab_rtx_for_bb->get (bb);
    2805                 :     5995123 :   if (elt)
    2806                 :     1189001 :     return *elt;
    2807                 :             : 
    2808                 :             :   /* Find the tree label if it is present.  */
    2809                 :     4806122 :   gimple_stmt_iterator gsi = gsi_start_bb (bb);
    2810                 :     4806122 :   glabel *lab_stmt;
    2811                 :     4806122 :   if (!gsi_end_p (gsi)
    2812                 :     4671847 :       && (lab_stmt = dyn_cast <glabel *> (gsi_stmt (gsi)))
    2813                 :     5018780 :       && !DECL_NONLOCAL (gimple_label_label (lab_stmt)))
    2814                 :      212658 :     return jump_target_rtx (gimple_label_label (lab_stmt));
    2815                 :             : 
    2816                 :     4593464 :   rtx_code_label *l = gen_label_rtx ();
    2817                 :     4593464 :   lab_rtx_for_bb->put (bb, l);
    2818                 :     4593464 :   return l;
    2819                 :             : }
    2820                 :             : 
    2821                 :             : 
    2822                 :             : /* Wrapper around remove_edge during expansion.  */
    2823                 :             : 
    2824                 :             : void
    2825                 :      128498 : expand_remove_edge (edge e)
    2826                 :             : {
    2827                 :      128498 :   if (current_ir_type () != IR_GIMPLE
    2828                 :      128498 :       && (e->dest->flags & BB_RTL) == 0
    2829                 :      193200 :       && !gimple_seq_empty_p (phi_nodes (e->dest)))
    2830                 :        8322 :     remove_phi_args (e);
    2831                 :      128498 :   remove_edge (e);
    2832                 :      128498 : }
    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                 :     1944191 : expand_split_edge (edge e, basic_block bb, int flags)
    2840                 :             : {
    2841                 :     1944191 :   unsigned int dest_idx = e->dest_idx;
    2842                 :     1944191 :   basic_block dest = e->dest;
    2843                 :     1944191 :   redirect_edge_succ (e, bb);
    2844                 :     1944191 :   e = make_single_succ_edge (bb, dest, flags);
    2845                 :     1944191 :   if ((dest->flags & BB_RTL) == 0
    2846                 :     1944191 :       && phi_nodes (dest)
    2847                 :     2104713 :       && 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                 :       99500 :       edge e2 = EDGE_PRED (dest, dest_idx);
    2853                 :       99500 :       std::swap (e->dest_idx, e2->dest_idx);
    2854                 :       99500 :       std::swap (EDGE_PRED (dest, e->dest_idx),
    2855                 :             :                  EDGE_PRED (dest, e2->dest_idx));
    2856                 :             :     }
    2857                 :     1944191 : }
    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                 :     5101392 : 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                 :     5101392 :   if (BARRIER_P (get_last_insn ()))
    2880                 :             :     {
    2881                 :         101 :       rtx_insn *insn;
    2882                 :         101 :       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                 :         101 :       insn = PREV_INSN (get_last_insn ());
    2893                 :             :       /* Make sure we have an unconditional jump.  Otherwise we're
    2894                 :             :          confused.  */
    2895                 :         101 :       gcc_assert (JUMP_P (insn) && !any_condjump_p (insn));
    2896                 :         202 :       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                 :     5101392 : }
    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                 :     5589481 : expand_gimple_cond (basic_block bb, gcond *stmt)
    2918                 :             : {
    2919                 :     5589481 :   basic_block new_bb, dest;
    2920                 :     5589481 :   edge true_edge;
    2921                 :     5589481 :   edge false_edge;
    2922                 :     5589481 :   rtx_insn *last2, *last;
    2923                 :     5589481 :   enum tree_code code;
    2924                 :     5589481 :   tree op0, op1;
    2925                 :             : 
    2926                 :     5589481 :   code = gimple_cond_code (stmt);
    2927                 :     5589481 :   op0 = gimple_cond_lhs (stmt);
    2928                 :     5589481 :   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                 :     5589481 :   if (SA.values
    2938                 :     4086609 :       && TREE_CODE (op0) == SSA_NAME
    2939                 :     4086029 :       && TREE_CODE (TREE_TYPE (op0)) == BOOLEAN_TYPE
    2940                 :      382867 :       && TREE_CODE (op1) == INTEGER_CST
    2941                 :      373306 :       && ((gimple_cond_code (stmt) == NE_EXPR
    2942                 :      373294 :            && integer_zerop (op1))
    2943                 :          12 :           || (gimple_cond_code (stmt) == EQ_EXPR
    2944                 :          12 :               && integer_onep (op1)))
    2945                 :     5962787 :       && bitmap_bit_p (SA.values, SSA_NAME_VERSION (op0)))
    2946                 :             :     {
    2947                 :      201250 :       gimple *second = SSA_NAME_DEF_STMT (op0);
    2948                 :      201250 :       if (gimple_code (second) == GIMPLE_ASSIGN)
    2949                 :             :         {
    2950                 :      201250 :           enum tree_code code2 = gimple_assign_rhs_code (second);
    2951                 :      201250 :           if (TREE_CODE_CLASS (code2) == tcc_comparison)
    2952                 :             :             {
    2953                 :         737 :               code = code2;
    2954                 :         737 :               op0 = gimple_assign_rhs1 (second);
    2955                 :         737 :               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                 :      200513 :           else if (BRANCH_COST (optimize_insn_for_speed_p (), false) < 4
    2960                 :      200513 :                    && !targetm.have_ccmp ())
    2961                 :             :             {
    2962                 :      200510 :               if ((code2 == BIT_AND_EXPR
    2963                 :       58800 :                    && TYPE_PRECISION (TREE_TYPE (op0)) == 1
    2964                 :       58800 :                    && TREE_CODE (gimple_assign_rhs2 (second)) != INTEGER_CST)
    2965                 :      200510 :                   || code2 == TRUTH_AND_EXPR)
    2966                 :             :                 {
    2967                 :       58800 :                   code = TRUTH_ANDIF_EXPR;
    2968                 :       58800 :                   op0 = gimple_assign_rhs1 (second);
    2969                 :       58800 :                   op1 = gimple_assign_rhs2 (second);
    2970                 :             :                 }
    2971                 :      141710 :               else if (code2 == BIT_IOR_EXPR || code2 == TRUTH_OR_EXPR)
    2972                 :             :                 {
    2973                 :       62787 :                   code = TRUTH_ORIF_EXPR;
    2974                 :       62787 :                   op0 = gimple_assign_rhs1 (second);
    2975                 :       62787 :                   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                 :     5589481 :   if ((code == EQ_EXPR || code == NE_EXPR)
    2984                 :     4377185 :       && TREE_CODE (op0) == SSA_NAME
    2985                 :     4376430 :       && TREE_CODE (op1) == INTEGER_CST)
    2986                 :     3055730 :     code = maybe_optimize_mod_cmp (code, &op0, &op1);
    2987                 :             : 
    2988                 :             :   /* Optimize (x - y) < 0 into x < y if x - y has undefined overflow.  */
    2989                 :     5589481 :   if (!TYPE_UNSIGNED (TREE_TYPE (op0))
    2990                 :     2262518 :       && (code == LT_EXPR || code == LE_EXPR
    2991                 :     2262518 :           || code == GT_EXPR || code == GE_EXPR)
    2992                 :      680923 :       && integer_zerop (op1)
    2993                 :     5785623 :       && TREE_CODE (op0) == SSA_NAME)
    2994                 :      196142 :     maybe_optimize_sub_cmp_0 (code, &op0, &op1);
    2995                 :             : 
    2996                 :     5589481 :   last2 = last = get_last_insn ();
    2997                 :             : 
    2998                 :     5589481 :   extract_true_false_edges_from_block (bb, &true_edge, &false_edge);
    2999                 :     5589481 :   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                 :     5589481 :   if (false_edge->dest == bb->next_bb)
    3004                 :             :     {
    3005                 :     2196533 :       jumpif_1 (code, op0, op1, label_rtx_for_bb (true_edge->dest),
    3006                 :             :                 true_edge->probability);
    3007                 :     2196533 :       maybe_dump_rtl_for_gimple_stmt (stmt, last);
    3008                 :     2196533 :       if (true_edge->goto_locus != UNKNOWN_LOCATION)
    3009                 :     1564745 :         set_curr_insn_location (true_edge->goto_locus);
    3010                 :     2196533 :       false_edge->flags |= EDGE_FALLTHRU;
    3011                 :     2196533 :       maybe_cleanup_end_of_block (false_edge, last);
    3012                 :     2196533 :       return NULL;
    3013                 :             :     }
    3014                 :     3392948 :   if (true_edge->dest == bb->next_bb)
    3015                 :             :     {
    3016                 :     2904859 :       jumpifnot_1 (code, op0, op1, label_rtx_for_bb (false_edge->dest),
    3017                 :             :                    false_edge->probability);
    3018                 :     2904859 :       maybe_dump_rtl_for_gimple_stmt (stmt, last);
    3019                 :     2904859 :       if (false_edge->goto_locus != UNKNOWN_LOCATION)
    3020                 :     2577335 :         set_curr_insn_location (false_edge->goto_locus);
    3021                 :     2904859 :       true_edge->flags |= EDGE_FALLTHRU;
    3022                 :     2904859 :       maybe_cleanup_end_of_block (true_edge, last);
    3023                 :     2904859 :       return NULL;
    3024                 :             :     }
    3025                 :             : 
    3026                 :      488089 :   jumpif_1 (code, op0, op1, label_rtx_for_bb (true_edge->dest),
    3027                 :             :             true_edge->probability);
    3028                 :      488089 :   last = get_last_insn ();
    3029                 :      488089 :   if (false_edge->goto_locus != UNKNOWN_LOCATION)
    3030                 :      267565 :     set_curr_insn_location (false_edge->goto_locus);
    3031                 :      488089 :   emit_jump (label_rtx_for_bb (false_edge->dest));
    3032                 :             : 
    3033                 :      488089 :   head_end_for_bb[bb->index].second = last;
    3034                 :      488089 :   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                 :      976178 :   update_bb_for_insn_chain (head_end_for_bb[bb->index].first,
    3038                 :      488089 :                             head_end_for_bb[bb->index].second, bb);
    3039                 :             : 
    3040                 :      488089 :   new_bb = create_basic_block (NEXT_INSN (last), get_last_insn (), bb);
    3041                 :      488089 :   dest = false_edge->dest;
    3042                 :      488089 :   expand_split_edge (false_edge, new_bb, 0);
    3043                 :      488089 :   false_edge->flags |= EDGE_FALLTHRU;
    3044                 :      488089 :   new_bb->count = false_edge->count ();
    3045                 :      488089 :   loop_p loop = find_common_loop (bb->loop_father, dest->loop_father);
    3046                 :      488089 :   add_bb_to_loop (new_bb, loop);
    3047                 :      488089 :   if (loop->latch == bb
    3048                 :       31264 :       && loop->header == dest)
    3049                 :       31261 :     loop->latch = new_bb;
    3050                 :      488089 :   if (BARRIER_P (BB_END (new_bb)))
    3051                 :      488089 :     BB_END (new_bb) = PREV_INSN (BB_END (new_bb));
    3052                 :      488089 :   update_bb_for_insn (new_bb);
    3053                 :             : 
    3054                 :      488089 :   maybe_dump_rtl_for_gimple_stmt (stmt, last2);
    3055                 :             : 
    3056                 :      488089 :   if (true_edge->goto_locus != UNKNOWN_LOCATION)
    3057                 :             :     {
    3058                 :      267551 :       set_curr_insn_location (true_edge->goto_locus);
    3059                 :      267551 :       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                 :     6537474 : mark_transaction_restart_calls (gimple *stmt)
    3069                 :             : {
    3070                 :     6537474 :   struct tm_restart_node dummy;
    3071                 :     6537474 :   tm_restart_node **slot;
    3072                 :             : 
    3073                 :     6537474 :   if (!cfun->gimple_df->tm_restart)
    3074                 :     6534490 :     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                 :     6729038 : expand_call_stmt (gcall *stmt)
    3102                 :             : {
    3103                 :     6729038 :   tree exp, decl, lhs;
    3104                 :     6729038 :   bool builtin_p;
    3105                 :     6729038 :   size_t i;
    3106                 :             : 
    3107                 :     6729038 :   if (gimple_call_internal_p (stmt))
    3108                 :             :     {
    3109                 :      154510 :       expand_internal_call (stmt);
    3110                 :      154510 :       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                 :     6574528 :   decl = gimple_call_fndecl (stmt);
    3117                 :     6574528 :   if (gimple_call_lhs (stmt)
    3118                 :     2337897 :       && !gimple_has_side_effects (stmt)
    3119                 :     7284011 :       && (optimize || (decl && called_as_built_in (decl))))
    3120                 :             :     {
    3121                 :      689363 :       internal_fn ifn = replacement_internal_fn (stmt);
    3122                 :      689363 :       if (ifn != IFN_LAST)
    3123                 :             :         {
    3124                 :       37054 :           expand_internal_call (ifn, stmt);
    3125                 :       37054 :           return;
    3126                 :             :         }
    3127                 :             :     }
    3128                 :             : 
    3129                 :     6537474 :   exp = build_vl_exp (CALL_EXPR, gimple_call_num_args (stmt) + 3);
    3130                 :             : 
    3131                 :     6537474 :   CALL_EXPR_FN (exp) = gimple_call_fn (stmt);
    3132                 :     6537474 :   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                 :     4593962 :   if (!builtin_p)
    3137                 :     9187924 :     CALL_EXPR_FN (exp)
    3138                 :    13781886 :       = fold_convert (build_pointer_type (gimple_call_fntype (stmt)),
    3139                 :             :                       CALL_EXPR_FN (exp));
    3140                 :             : 
    3141                 :     6537474 :   TREE_TYPE (exp) = gimple_call_return_type (stmt);
    3142                 :     6537474 :   CALL_EXPR_STATIC_CHAIN (exp) = gimple_call_chain (stmt);
    3143                 :             : 
    3144                 :    19790986 :   for (i = 0; i < gimple_call_num_args (stmt); i++)
    3145                 :             :     {
    3146                 :    13253512 :       tree arg = gimple_call_arg (stmt, i);
    3147                 :    13253512 :       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                 :    13253512 :       if (builtin_p
    3151                 :     4002033 :           && TREE_CODE (arg) == SSA_NAME
    3152                 :     1327218 :           && (def = get_gimple_for_ssa_name (arg))
    3153                 :      329033 :           && is_gimple_assign (def)
    3154                 :    13582384 :           && gimple_assign_rhs_code (def) == ADDR_EXPR)
    3155                 :       14360 :         arg = gimple_assign_rhs1 (def);
    3156                 :    13253512 :       CALL_EXPR_ARG (exp, i) = arg;
    3157                 :             :     }
    3158                 :             : 
    3159                 :     6537474 :   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                 :     6537474 :       || stmt_could_throw_p (cfun, stmt))
    3163                 :     5867336 :     TREE_SIDE_EFFECTS (exp) = 1;
    3164                 :             : 
    3165                 :     6537474 :   if (gimple_call_nothrow_p (stmt))
    3166                 :     2908669 :     TREE_NOTHROW (exp) = 1;
    3167                 :             : 
    3168                 :     6537474 :   CALL_EXPR_TAILCALL (exp) = gimple_call_tail_p (stmt);
    3169                 :     6537474 :   CALL_EXPR_MUST_TAIL_CALL (exp) = gimple_call_must_tail_p (stmt);
    3170                 :     6537474 :   CALL_EXPR_RETURN_SLOT_OPT (exp) = gimple_call_return_slot_opt_p (stmt);
    3171                 :     6537474 :   if (decl
    3172                 :     6349166 :       && fndecl_built_in_p (decl, BUILT_IN_NORMAL)
    3173                 :     8309889 :       && ALLOCA_FUNCTION_CODE_P (DECL_FUNCTION_CODE (decl)))
    3174                 :       25653 :     CALL_ALLOCA_FOR_VAR_P (exp) = gimple_call_alloca_for_var_p (stmt);
    3175                 :             :   else
    3176                 :     6511821 :     CALL_FROM_THUNK_P (exp) = gimple_call_from_thunk_p (stmt);
    3177                 :     6537474 :   CALL_EXPR_VA_ARG_PACK (exp) = gimple_call_va_arg_pack_p (stmt);
    3178                 :     6537474 :   CALL_EXPR_BY_DESCRIPTOR (exp) = gimple_call_by_descriptor_p (stmt);
    3179                 :     6537474 :   SET_EXPR_LOCATION (exp, gimple_location (stmt));
    3180                 :             : 
    3181                 :             :   /* Must come after copying location.  */
    3182                 :     6537474 :   copy_warning (exp, stmt);
    3183                 :             : 
    3184                 :             :   /* Ensure RTL is created for debug args.  */
    3185                 :    12886640 :   if (decl && DECL_HAS_DEBUG_ARGS_P (decl))
    3186                 :             :     {
    3187                 :       65463 :       vec<tree, va_gc> **debug_args = decl_debug_args_lookup (decl);
    3188                 :       65463 :       unsigned int ix;
    3189                 :       65463 :       tree dtemp;
    3190                 :             : 
    3191                 :       65463 :       if (debug_args)
    3192                 :      141934 :         for (ix = 1; (*debug_args)->iterate (ix, &dtemp); ix += 2)
    3193                 :             :           {
    3194                 :       76471 :             gcc_assert (TREE_CODE (dtemp) == DEBUG_EXPR_DECL);
    3195                 :       76471 :             expand_debug_expr (dtemp);
    3196                 :             :           }
    3197                 :             :     }
    3198                 :             : 
    3199                 :     6537474 :   rtx_insn *before_call = get_last_insn ();
    3200                 :     6537474 :   lhs = gimple_call_lhs (stmt);
    3201                 :     6537474 :   if (lhs)
    3202                 :     2300843 :     expand_assignment (lhs, exp, false);
    3203                 :             :   else
    3204                 :     4236631 :     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                 :     6537474 :   if (gimple_call_nocf_check_p (stmt)
    3210                 :     6537495 :       && !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                 :     6537474 :   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                 :        2805 : expand_asm_loc (tree string, int vol, location_t locus)
    3232                 :             : {
    3233                 :        2805 :   rtx body;
    3234                 :             : 
    3235                 :        2805 :   body = gen_rtx_ASM_INPUT_loc (VOIDmode,
    3236                 :             :                                 ggc_strdup (TREE_STRING_POINTER (string)),
    3237                 :             :                                 locus);
    3238                 :             : 
    3239                 :        2805 :   MEM_VOLATILE_P (body) = vol;
    3240                 :             : 
    3241                 :             :   /* Non-empty basic ASM implicitly clobbers memory.  */
    3242                 :        2805 :   if (TREE_STRING_LENGTH (string) != 0)
    3243                 :             :     {
    3244                 :         930 :       rtx asm_op, clob;
    3245                 :         930 :       unsigned i, nclobbers;
    3246                 :         930 :       auto_vec<rtx> input_rvec, output_rvec;
    3247                 :         930 :       auto_vec<machine_mode> input_mode;
    3248                 :         930 :       auto_vec<const char *> constraints;
    3249                 :         930 :       auto_vec<rtx> use_rvec;
    3250                 :         930 :       auto_vec<rtx> clobber_rvec;
    3251                 :         930 :       HARD_REG_SET clobbered_regs;
    3252                 :         930 :       CLEAR_HARD_REG_SET (clobbered_regs);
    3253                 :             : 
    3254                 :         930 :       clob = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (VOIDmode));
    3255                 :         930 :       clobber_rvec.safe_push (clob);
    3256                 :             : 
    3257                 :         930 :       if (targetm.md_asm_adjust)
    3258                 :         930 :         targetm.md_asm_adjust (output_rvec, input_rvec, input_mode,
    3259                 :             :                                constraints, use_rvec, clobber_rvec,
    3260                 :             :                                clobbered_regs, locus);
    3261                 :             : 
    3262                 :         930 :       asm_op = body;
    3263                 :         930 :       nclobbers = clobber_rvec.length ();
    3264                 :         930 :       auto nuses = use_rvec.length ();
    3265                 :         930 :       body = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (1 + nuses + nclobbers));
    3266                 :             : 
    3267                 :         930 :       i = 0;
    3268                 :         930 :       XVECEXP (body, 0, i++) = asm_op;
    3269                 :         930 :       for (rtx use : use_rvec)
    3270                 :           0 :         XVECEXP (body, 0, i++) = gen_rtx_USE (VOIDmode, use);
    3271                 :        4650 :       for (rtx clobber : clobber_rvec)
    3272                 :        1860 :         XVECEXP (body, 0, i++) = gen_rtx_CLOBBER (VOIDmode, clobber);
    3273                 :         930 :     }
    3274                 :             : 
    3275                 :        2805 :   emit_insn (body);
    3276                 :        2805 : }
    3277                 :             : 
    3278                 :             : /* Return the number of times character C occurs in string S.  */
    3279                 :             : static int
    3280                 :      123599 : n_occurrences (int c, const char *s)
    3281                 :             : {
    3282                 :      123599 :   int n = 0;
    3283                 :      323637 :   while (*s)
    3284                 :      200038 :     n += (*s++ == c);
    3285                 :      123599 :   return n;
    3286                 :             : }
    3287                 :             : 
    3288                 :             : /* A subroutine of expand_asm_operands.  Check that all operands have
    3289                 :             :    the same number of alternatives.  Return true if so.  */
    3290                 :             : 
    3291                 :             : static bool
    3292                 :      103837 : check_operand_nalternatives (const vec<const char *> &constraints)
    3293                 :             : {
    3294                 :      103837 :   unsigned len = constraints.length();
    3295                 :      103837 :   if (len > 0)
    3296                 :             :     {
    3297                 :       39977 :       int nalternatives = n_occurrences (',', constraints[0]);
    3298                 :             : 
    3299                 :       39977 :       if (nalternatives + 1 > MAX_RECOG_ALTERNATIVES)
    3300                 :             :         {
    3301                 :           0 :           error ("too many alternatives in %<asm%>");
    3302                 :           0 :           return false;
    3303                 :             :         }
    3304                 :             : 
    3305                 :      123599 :       for (unsigned i = 1; i < len; ++i)
    3306                 :      167244 :         if (n_occurrences (',', constraints[i]) != nalternatives)
    3307                 :             :           {
    3308                 :           0 :             error ("operand constraints for %<asm%> differ "
    3309                 :             :                    "in number of alternatives");
    3310                 :           0 :             return false;
    3311                 :             :           }
    3312                 :             :     }
    3313                 :             :   return true;
    3314                 :             : }
    3315                 :             : 
    3316                 :             : /* Check for overlap between registers marked in CLOBBERED_REGS and
    3317                 :             :    anything inappropriate in T.  Emit error and return the register
    3318                 :             :    variable definition for error, NULL_TREE for ok.  */
    3319                 :             : 
    3320                 :             : static bool
    3321                 :      123590 : tree_conflicts_with_clobbers_p (tree t, HARD_REG_SET *clobbered_regs,
    3322                 :             :                                 location_t loc)
    3323                 :             : {
    3324                 :             :   /* Conflicts between asm-declared register variables and the clobber
    3325                 :             :      list are not allowed.  */
    3326                 :      123590 :   tree overlap = tree_overlaps_hard_reg_set (t, clobbered_regs);
    3327                 :             : 
    3328                 :      123590 :   if (overlap)
    3329                 :             :     {
    3330                 :          21 :       error_at (loc, "%<asm%> specifier for variable %qE conflicts with "
    3331                 :          21 :                 "%<asm%> clobber list", DECL_NAME (overlap));
    3332                 :             : 
    3333                 :             :       /* Reset registerness to stop multiple errors emitted for a single
    3334                 :             :          variable.  */
    3335                 :          21 :       DECL_REGISTER (overlap) = 0;
    3336                 :          21 :       return true;
    3337                 :             :     }
    3338                 :             : 
    3339                 :             :   return false;
    3340                 :             : }
    3341                 :             : 
    3342                 :             : /* Check that the given REGNO spanning NREGS is a valid
    3343                 :             :    asm clobber operand.  Some HW registers cannot be
    3344                 :             :    saved/restored, hence they should not be clobbered by
    3345                 :             :    asm statements.  */
    3346                 :             : static bool
    3347                 :       41525 : asm_clobber_reg_is_valid (int regno, int nregs, const char *regname)
    3348                 :             : {
    3349                 :       41525 :   bool is_valid = true;
    3350                 :       41525 :   HARD_REG_SET regset;
    3351                 :             : 
    3352                 :       41525 :   CLEAR_HARD_REG_SET (regset);
    3353                 :             : 
    3354                 :       41525 :   add_range_to_hard_reg_set (&regset, regno, nregs);
    3355                 :             : 
    3356                 :             :   /* Clobbering the PIC register is an error.  */
    3357                 :       41525 :   if (PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
    3358                 :           0 :       && overlaps_hard_reg_set_p (regset, Pmode, PIC_OFFSET_TABLE_REGNUM))
    3359                 :             :     {
    3360                 :             :       /* ??? Diagnose during gimplification?  */
    3361                 :           0 :       error ("PIC register clobbered by %qs in %<asm%>", regname);
    3362                 :           0 :       is_valid = false;
    3363                 :             :     }
    3364                 :       41525 :   else if (!in_hard_reg_set_p
    3365                 :       41525 :            (accessible_reg_set, reg_raw_mode[regno], regno))
    3366                 :             :     {
    3367                 :             :       /* ??? Diagnose during gimplification?  */
    3368                 :           0 :       error ("the register %qs cannot be clobbered in %<asm%>"
    3369                 :             :              " for the current target", regname);
    3370                 :           0 :       is_valid = false;
    3371                 :             :     }
    3372                 :             : 
    3373                 :             :   /* Clobbering the stack pointer register is deprecated.  GCC expects
    3374                 :             :      the value of the stack pointer after an asm statement to be the same
    3375                 :             :      as it was before, so no asm can validly clobber the stack pointer in
    3376                 :             :      the usual sense.  Adding the stack pointer to the clobber list has
    3377                 :             :      traditionally had some undocumented and somewhat obscure side-effects.  */
    3378                 :       41545 :   if (overlaps_hard_reg_set_p (regset, Pmode, STACK_POINTER_REGNUM))
    3379                 :             :     {
    3380                 :           1 :       crtl->sp_is_clobbered_by_asm = true;
    3381                 :           1 :       if (warning (OPT_Wdeprecated, "listing the stack pointer register"
    3382                 :             :                    " %qs in a clobber list is deprecated", regname))
    3383                 :           1 :         inform (input_location, "the value of the stack pointer after"
    3384                 :             :                 " an %<asm%> statement must be the same as it was before"
    3385                 :             :                 " the statement");
    3386                 :             :     }
    3387                 :             : 
    3388                 :       41525 :   return is_valid;
    3389                 :             : }
    3390                 :             : 
    3391                 :             : /* Generate RTL for an asm statement with arguments.
    3392                 :             :    STRING is the instruction template.
    3393                 :             :    OUTPUTS is a list of output arguments (lvalues); INPUTS a list of inputs.
    3394                 :             :    Each output or input has an expression in the TREE_VALUE and
    3395                 :             :    a tree list in TREE_PURPOSE which in turn contains a constraint
    3396                 :             :    name in TREE_VALUE (or NULL_TREE) and a constraint string
    3397                 :             :    in TREE_PURPOSE.
    3398                 :             :    CLOBBERS is a list of STRING_CST nodes each naming a hard register
    3399                 :             :    that is clobbered by this insn.
    3400                 :             : 
    3401                 :             :    LABELS is a list of labels, and if LABELS is non-NULL, FALLTHRU_BB
    3402                 :             :    should be the fallthru basic block of the asm goto.
    3403                 :             : 
    3404                 :             :    Not all kinds of lvalue that may appear in OUTPUTS can be stored directly.
    3405                 :             :    Some elements of OUTPUTS may be replaced with trees representing temporary
    3406                 :             :    values.  The caller should copy those temporary values to the originally
    3407                 :             :    specified lvalues.
    3408                 :             : 
    3409                 :             :    VOL nonzero means the insn is volatile; don't optimize it.  */
    3410                 :             : 
    3411                 :             : static void
    3412                 :      106647 : expand_asm_stmt (gasm *stmt)
    3413                 :             : {
    3414                 :      106647 :   class save_input_location
    3415                 :             :   {
    3416                 :             :     location_t old;
    3417                 :             : 
    3418                 :             :   public:
    3419                 :      103842 :     explicit save_input_location(location_t where)
    3420                 :      103842 :     {
    3421                 :      103842 :       old = input_location;
    3422                 :      103842 :       input_location = where;
    3423                 :             :     }
    3424                 :             : 
    3425                 :      103842 :     ~save_input_location()
    3426                 :             :     {
    3427                 :      103842 :       input_location = old;
    3428                 :           5 :     }
    3429                 :             :   };
    3430                 :             : 
    3431                 :      106647 :   location_t locus = gimple_location (stmt);
    3432                 :             : 
    3433                 :      106647 :   if (gimple_asm_basic_p (stmt))
    3434                 :             :     {
    3435                 :        2805 :       const char *s = gimple_asm_string (stmt);
    3436                 :        2805 :       tree string = build_string (strlen (s), s);
    3437                 :        2805 :       expand_asm_loc (string, gimple_asm_volatile_p (stmt), locus);
    3438                 :        5615 :       return;
    3439                 :             :     }
    3440                 :             : 
    3441                 :             :   /* There are some legacy diagnostics in here.  */
    3442                 :      103842 :   save_input_location s_i_l(locus);
    3443                 :             : 
    3444                 :      103842 :   unsigned noutputs = gimple_asm_noutputs (stmt);
    3445                 :      103842 :   unsigned ninputs = gimple_asm_ninputs (stmt);
    3446                 :      103842 :   unsigned nlabels = gimple_asm_nlabels (stmt);
    3447                 :      103842 :   unsigned i;
    3448                 :      103842 :   bool error_seen = false;
    3449                 :             : 
    3450                 :             :   /* ??? Diagnose during gimplification?  */
    3451                 :      103842 :   if (ninputs + noutputs + nlabels > MAX_RECOG_OPERANDS)
    3452                 :             :     {
    3453                 :           5 :       error_at (locus, "more than %d operands in %<asm%>", MAX_RECOG_OPERANDS);
    3454                 :           5 :       return;
    3455                 :             :     }
    3456                 :             : 
    3457                 :      103837 :   auto_vec<tree, MAX_RECOG_OPERANDS> output_tvec;
    3458                 :      103837 :   auto_vec<tree, MAX_RECOG_OPERANDS> input_tvec;
    3459                 :      103837 :   auto_vec<const char *, MAX_RECOG_OPERANDS> constraints;
    3460                 :             : 
    3461                 :             :   /* Copy the gimple vectors into new vectors that we can manipulate.  */
    3462                 :             : 
    3463                 :      103837 :   output_tvec.safe_grow (noutputs, true);
    3464                 :      103837 :   input_tvec.safe_grow (ninputs, true);
    3465                 :      103837 :   constraints.safe_grow (noutputs + ninputs, true);
    3466                 :             : 
    3467                 :      175526 :   for (i = 0; i < noutputs; ++i)
    3468                 :             :     {
    3469                 :       71689 :       tree t = gimple_asm_output_op (stmt, i);
    3470                 :       71689 :       output_tvec[i] = TREE_VALUE (t);
    3471                 :       71689 :       constraints[i] = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
    3472                 :             :     }
    3473                 :      155747 :   for (i = 0; i < ninputs; i++)
    3474                 :             :     {
    3475                 :       51910 :       tree t = gimple_asm_input_op (stmt, i);
    3476                 :       51910 :       input_tvec[i] = TREE_VALUE (t);
    3477                 :       51910 :       constraints[i + noutputs]
    3478                 :       51910 :         = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
    3479                 :             :     }
    3480                 :             : 
    3481                 :             :   /* ??? Diagnose during gimplification?  */
    3482                 :      103837 :   if (! check_operand_nalternatives (constraints))
    3483                 :             :     return;
    3484                 :             : 
    3485                 :             :   /* Count the number of meaningful clobbered registers, ignoring what
    3486                 :             :      we would ignore later.  */
    3487                 :      103837 :   auto_vec<rtx> clobber_rvec;
    3488                 :      103837 :   HARD_REG_SET clobbered_regs;
    3489                 :      103837 :   CLEAR_HARD_REG_SET (clobbered_regs);
    3490                 :             : 
    3491                 :      103837 :   if (unsigned n = gimple_asm_nclobbers (stmt))
    3492                 :             :     {
    3493                 :       68523 :       clobber_rvec.reserve (n);
    3494                 :      164599 :       for (i = 0; i < n; i++)
    3495                 :             :         {
    3496                 :       96076 :           tree t = gimple_asm_clobber_op (stmt, i);
    3497                 :       96076 :           const char *regname = TREE_STRING_POINTER (TREE_VALUE (t));
    3498                 :       96076 :           int nregs, j;
    3499                 :             : 
    3500                 :       96076 :           j = decode_reg_name_and_count (regname, &nregs);
    3501                 :       96076 :           if (j < 0)
    3502                 :             :             {
    3503                 :       54551 :               if (j == -2)
    3504                 :             :                 {
    3505                 :             :                   /* ??? Diagnose during gimplification?  */
    3506                 :          15 :                   error_at (locus, "unknown register name %qs in %<asm%>",
    3507                 :             :                             regname);
    3508                 :          15 :                   error_seen = true;
    3509                 :             :                 }
    3510                 :       54536 :               else if (j == -4)
    3511                 :             :                 {
    3512                 :       38811 :                   rtx x = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (VOIDmode));
    3513                 :       38811 :                   clobber_rvec.safe_push (x);
    3514                 :             :                 }
    3515                 :       15725 :               else if (j == -5)
    3516                 :             :                 {
    3517                 :           2 :                   if (targetm.redzone_clobber)
    3518                 :           2 :                     if (rtx x = targetm.redzone_clobber ())
    3519                 :           2 :                       clobber_rvec.safe_push (x);
    3520                 :             :                 }
    3521                 :             :               else
    3522                 :             :                 {
    3523                 :             :                   /* Otherwise we should have -1 == empty string
    3524                 :             :                      or -3 == cc, which is not a register.  */
    3525                 :       15723 :                   gcc_assert (j == -1 || j == -3);
    3526                 :             :                 }
    3527                 :             :             }
    3528                 :             :           else
    3529                 :       83050 :             for (int reg = j; reg < j + nregs; reg++)
    3530                 :             :               {
    3531                 :       41525 :                 if (!asm_clobber_reg_is_valid (reg, nregs, regname))
    3532                 :           0 :                   return;
    3533                 :             : 
    3534                 :       41525 :                 SET_HARD_REG_BIT (clobbered_regs, reg);
    3535                 :       41525 :                 rtx x = gen_rtx_REG (reg_raw_mode[reg], reg);
    3536                 :       41525 :                 clobber_rvec.safe_push (x);
    3537                 :             :               }
    3538                 :             :         }
    3539                 :             :     }
    3540                 :             : 
    3541                 :             :   /* First pass over inputs and outputs checks validity and sets
    3542                 :             :      mark_addressable if needed.  */
    3543                 :             :   /* ??? Diagnose during gimplification?  */
    3544                 :             : 
    3545                 :      175526 :   for (i = 0; i < noutputs; ++i)
    3546                 :             :     {
    3547                 :       71689 :       tree val = output_tvec[i];
    3548                 :       71689 :       tree type = TREE_TYPE (val);
    3549                 :       71689 :       const char *constraint;
    3550                 :       71689 :       bool is_inout;
    3551                 :       71689 :       bool allows_reg;
    3552                 :       71689 :       bool allows_mem;
    3553                 :             : 
    3554                 :             :       /* Try to parse the output constraint.  If that fails, there's
    3555                 :             :          no point in going further.  */
    3556                 :       71689 :       constraint = constraints[i];
    3557                 :       71689 :       if (!parse_output_constraint (&constraint, i, ninputs, noutputs,
    3558                 :             :                                     &allows_mem, &allows_reg, &is_inout))
    3559                 :           0 :         return;
    3560                 :             : 
    3561                 :             :       /* If the output is a hard register, verify it doesn't conflict with
    3562                 :             :          any other operand's possible hard register use.  */
    3563                 :       71689 :       if (DECL_P (val)
    3564                 :        7545 :           && REG_P (DECL_RTL (val))
    3565                 :       72646 :           && HARD_REGISTER_P (DECL_RTL (val)))
    3566                 :             :         {
    3567                 :         940 :           unsigned j, output_hregno = REGNO (DECL_RTL (val));
    3568                 :         940 :           bool early_clobber_p = strchr (constraints[i], '&') != NULL;
    3569                 :         940 :           unsigned long match;
    3570                 :             : 
    3571                 :             :           /* Verify the other outputs do not use the same hard register.  */
    3572                 :        1101 :           for (j = i + 1; j < noutputs; ++j)
    3573                 :         161 :             if (DECL_P (output_tvec[j])
    3574                 :         159 :                 && REG_P (DECL_RTL (output_tvec[j]))
    3575                 :         159 :                 && HARD_REGISTER_P (DECL_RTL (output_tvec[j]))
    3576                 :         320 :                 && output_hregno == REGNO (DECL_RTL (output_tvec[j])))
    3577                 :             :               {
    3578                 :           1 :                 error_at (locus, "invalid hard register usage between output "
    3579                 :             :                           "operands");
    3580                 :           1 :                 error_seen = true;
    3581                 :             :               }
    3582                 :             : 
    3583                 :             :           /* Verify matching constraint operands use the same hard register
    3584                 :             :              and that the non-matching constraint operands do not use the same
    3585                 :             :              hard register if the output is an early clobber operand.  */
    3586                 :        1853 :           for (j = 0; j < ninputs; ++j)
    3587                 :         913 :             if (DECL_P (input_tvec[j])
    3588                 :         774 :                 && REG_P (DECL_RTL (input_tvec[j]))
    3589                 :        1687 :                 && HARD_REGISTER_P (DECL_RTL (input_tvec[j])))
    3590                 :             :               {
    3591                 :         774 :                 unsigned input_hregno = REGNO (DECL_RTL (input_tvec[j]));
    3592                 :         774 :                 switch (*constraints[j + noutputs])
    3593                 :             :                   {
    3594                 :         762 :                   case '0':  case '1':  case '2':  case '3':  case '4':
    3595                 :         762 :                   case '5':  case '6':  case '7':  case '8':  case '9':
    3596                 :         762 :                     match = strtoul (constraints[j + noutputs], NULL, 10);
    3597                 :         762 :                     break;
    3598                 :             :                   default:
    3599                 :             :                     match = ULONG_MAX;
    3600                 :             :                     break;
    3601                 :             :                   }
    3602                 :         762 :                 if (i == match
    3603                 :         661 :                     && output_hregno != input_hregno)
    3604                 :             :                   {
    3605                 :           1 :                     error_at (locus, "invalid hard register usage between "
    3606                 :             :                               "output operand and matching constraint operand");
    3607                 :           1 :                     error_seen = true;
    3608                 :             :                   }
    3609                 :         773 :                 else if (early_clobber_p
    3610                 :           6 :                          && i != match
    3611                 :           4 :                          && output_hregno == input_hregno)
    3612                 :             :                   {
    3613                 :           2 :                     error_at (locus, "invalid hard register usage between "
    3614                 :             :                               "earlyclobber operand and input operand");
    3615                 :           2 :                     error_seen = true;
    3616                 :             :                   }
    3617                 :             :               }
    3618                 :             :         }
    3619                 :             : 
    3620                 :       71689 :       if (! allows_reg
    3621                 :       71689 :           && (allows_mem
    3622                 :           0 :               || is_inout
    3623                 :           0 :               || (DECL_P (val)
    3624                 :           0 :                   && REG_P (DECL_RTL (val))
    3625                 :           0 :                   && GET_MODE (DECL_RTL (val)) != TYPE_MODE (type))))
    3626                 :        6275 :         mark_addressable (val);
    3627                 :             :     }
    3628                 :             : 
    3629                 :      155747 :   for (i = 0; i < ninputs; ++i)
    3630                 :             :     {
    3631                 :       51910 :       bool allows_reg, allows_mem;
    3632                 :       51910 :       const char *constraint;
    3633                 :             : 
    3634                 :       51910 :       constraint = constraints[i + noutputs];
    3635                 :       51910 :       if (! parse_input_constraint (&constraint, i, ninputs, noutputs, 0,
    3636                 :       51910 :                                     constraints.address (),
    3637                 :             :                                     &allows_mem, &allows_reg))
    3638                 :           0 :         return;
    3639                 :             : 
    3640                 :       51910 :       if (! allows_reg && allows_mem)
    3641                 :        6960 :         mark_addressable (input_tvec[i]);
    3642                 :             :     }
    3643                 :             : 
    3644                 :             :   /* Second pass evaluates arguments.  */
    3645                 :             : 
    3646                 :             :   /* Make sure stack is consistent for asm goto.  */
    3647                 :      103837 :   if (nlabels > 0)
    3648                 :         445 :     do_pending_stack_adjust ();
    3649                 :      103837 :   int old_generating_concat_p = generating_concat_p;
    3650                 :             : 
    3651                 :             :   /* Vector of RTX's of evaluated output operands.  */
    3652                 :      207674 :   auto_vec<rtx, MAX_RECOG_OPERANDS> output_rvec;
    3653                 :      103837 :   auto_vec<int, MAX_RECOG_OPERANDS> inout_opnum;
    3654                 :      103837 :   rtx_insn *after_rtl_seq = NULL, *after_rtl_end = NULL;
    3655                 :             : 
    3656                 :      103837 :   output_rvec.safe_grow (noutputs, true);
    3657                 :             : 
    3658                 :      175526 :   for (i = 0; i < noutputs; ++i)
    3659                 :             :     {
    3660                 :       71689 :       tree val = output_tvec[i];
    3661                 :       71689 :       tree type = TREE_TYPE (val);
    3662                 :       71689 :       bool is_inout, allows_reg, allows_mem, ok;
    3663                 :       71689 :       rtx op;
    3664                 :             : 
    3665                 :       71689 :       ok = parse_output_constraint (&constraints[i], i, ninputs,
    3666                 :             :                                     noutputs, &allows_mem, &allows_reg,
    3667                 :             :                                     &is_inout);
    3668                 :       71689 :       gcc_assert (ok);
    3669                 :             : 
    3670                 :             :       /* If an output operand is not a decl or indirect ref and our constraint
    3671                 :             :          allows a register, make a temporary to act as an intermediate.
    3672                 :             :          Make the asm insn write into that, then we will copy it to
    3673                 :             :          the real output operand.  Likewise for promoted variables.  */
    3674                 :             : 
    3675                 :       71689 :       generating_concat_p = 0;
    3676                 :             : 
    3677                 :       71689 :       gcc_assert (TREE_CODE (val) != INDIRECT_REF);
    3678                 :       71689 :       if (((TREE_CODE (val) == MEM_REF
    3679                 :        2583 :             && TREE_CODE (TREE_OPERAND (val, 0)) != ADDR_EXPR)
    3680                 :        2482 :            && allows_mem)
    3681                 :       71295 :           || (DECL_P (val)
    3682                 :        7545 :               && (allows_mem || REG_P (DECL_RTL (val)))
    3683                 :        7799 :               && ! (REG_P (DECL_RTL (val))
    3684                 :         957 :                     && GET_MODE (DECL_RTL (val)) != TYPE_MODE (type)))
    3685                 :       64453 :           || ! allows_reg
    3686                 :       64249 :           || is_inout
    3687                 :       64249 :           || TREE_ADDRESSABLE (type)
    3688                 :      135938 :           || (!tree_fits_poly_int64_p (TYPE_SIZE (type))
    3689                 :           0 :               && !known_size_p (max_int_size_in_bytes (type))))
    3690                 :             :         {
    3691                 :        7440 :           op = expand_expr (val, NULL_RTX, VOIDmode,
    3692                 :             :                             !allows_reg ? EXPAND_MEMORY : EXPAND_WRITE);
    3693                 :        7440 :           if (MEM_P (op))
    3694                 :        6483 :             op = validize_mem (op);
    3695                 :             : 
    3696                 :        7440 :           if (! allows_reg && !MEM_P (op))
    3697                 :             :             {
    3698                 :           0 :               error_at (locus, "output number %d not directly addressable", i);
    3699                 :           0 :               error_seen = true;
    3700                 :             :             }
    3701                 :        7440 :           if ((! allows_mem && MEM_P (op) && GET_MODE (op) != BLKmode)
    3702                 :        7440 :               || GET_CODE (op) == CONCAT)
    3703                 :             :             {
    3704                 :           0 :               rtx old_op = op;
    3705                 :           0 :               op = gen_reg_rtx (GET_MODE (op));
    3706                 :             : 
    3707                 :           0 :               generating_concat_p = old_generating_concat_p;
    3708                 :             : 
    3709                 :           0 :               if (is_inout)
    3710                 :           0 :                 emit_move_insn (op, old_op);
    3711                 :             : 
    3712                 :           0 :               push_to_sequence2 (after_rtl_seq, after_rtl_end);
    3713                 :           0 :               emit_move_insn (old_op, op);
    3714                 :           0 :               after_rtl_seq = get_insns ();
    3715                 :           0 :               after_rtl_end = get_last_insn ();
    3716                 :           0 :               end_sequence ();
    3717                 :             :             }
    3718                 :             :         }
    3719                 :             :       else
    3720                 :             :         {
    3721                 :       64249 :           op = assign_temp (type, 0, 1);
    3722                 :       64249 :           op = validize_mem (op);
    3723                 :       64249 :           if (!MEM_P (op) && TREE_CODE (val) == SSA_NAME)
    3724                 :       60707 :             set_reg_attrs_for_decl_rtl (SSA_NAME_VAR (val), op);
    3725                 :             : 
    3726                 :       64249 :           generating_concat_p = old_generating_concat_p;
    3727                 :             : 
    3728                 :       64249 :           push_to_sequence2 (after_rtl_seq, after_rtl_end);
    3729                 :       64249 :           expand_assignment (val, make_tree (type, op), false);
    3730                 :       64249 :           after_rtl_seq = get_insns ();
    3731                 :       64249 :           after_rtl_end = get_last_insn ();
    3732                 :       64249 :           end_sequence ();
    3733                 :             :         }
    3734                 :       71689 :       output_rvec[i] = op;
    3735                 :             : 
    3736                 :       71689 :       if (is_inout)
    3737                 :           0 :         inout_opnum.safe_push (i);
    3738                 :             :     }
    3739                 :             : 
    3740                 :      103837 :   const char *str = gimple_asm_string (stmt);
    3741                 :      103837 :   if (error_seen)
    3742                 :             :     {
    3743                 :          19 :       ninputs = 0;
    3744                 :          19 :       noutputs = 0;
    3745                 :          19 :       inout_opnum.truncate (0);
    3746                 :          19 :       output_rvec.truncate (0);
    3747                 :          19 :       clobber_rvec.truncate (0);
    3748                 :          19 :       constraints.truncate (0);
    3749                 :          19 :       CLEAR_HARD_REG_SET (clobbered_regs);
    3750                 :             :       str = "";
    3751                 :             :     }
    3752                 :             : 
    3753                 :      207674 :   auto_vec<rtx, MAX_RECOG_OPERANDS> input_rvec;
    3754                 :      103837 :   auto_vec<machine_mode, MAX_RECOG_OPERANDS> input_mode;
    3755                 :             : 
    3756                 :      103837 :   input_rvec.safe_grow (ninputs, true);
    3757                 :      103837 :   input_mode.safe_grow (ninputs, true);
    3758                 :             : 
    3759                 :      103837 :   generating_concat_p = 0;
    3760                 :             : 
    3761                 :      155744 :   for (i = 0; i < ninputs; ++i)
    3762                 :             :     {
    3763                 :       51907 :       tree val = input_tvec[i];
    3764                 :       51907 :       tree type = TREE_TYPE (val);
    3765                 :       51907 :       bool allows_reg, allows_mem, ok;
    3766                 :       51907 :       const char *constraint;
    3767                 :       51907 :       rtx op;
    3768                 :             : 
    3769                 :       51907 :       constraint = constraints[i + noutputs];
    3770                 :       51907 :       ok = parse_input_constraint (&constraint, i, ninputs, noutputs, 0,
    3771                 :       51907 :                                    constraints.address (),
    3772                 :             :                                    &allows_mem, &allows_reg);
    3773                 :       51907 :       gcc_assert (ok);
    3774                 :             : 
    3775                 :             :       /* EXPAND_INITIALIZER will not generate code for valid initializer
    3776                 :             :          constants, but will still generate code for other types of operand.
    3777                 :             :          This is the behavior we want for constant constraints.  */
    3778                 :       51907 :       op = expand_expr (val, NULL_RTX, VOIDmode,
    3779                 :             :                         allows_reg ? EXPAND_NORMAL
    3780                 :        8195 :                         : allows_mem ? EXPAND_MEMORY
    3781                 :             :                         : EXPAND_INITIALIZER);
    3782                 :             : 
    3783                 :             :       /* Never pass a CONCAT to an ASM.  */
    3784                 :       51907 :       if (GET_CODE (op) == CONCAT)
    3785                 :           2 :         op = force_reg (GET_MODE (op), op);
    3786                 :       51905 :       else if (MEM_P (op))
    3787                 :       12125 :         op = validize_mem (op);
    3788                 :             : 
    3789                 :       51907 :       if (asm_operand_ok (op, constraint, NULL) <= 0)
    3790                 :             :         {
    3791                 :       24515 :           if (allows_reg && TYPE_MODE (type) != BLKmode)
    3792                 :       24127 :             op = force_reg (TYPE_MODE (type), op);
    3793                 :         388 :           else if (!allows_mem)
    3794                 :          20 :             warning_at (locus, 0, "%<asm%> operand %d probably does not match "
    3795                 :             :                         "constraints", i + noutputs);
    3796                 :         368 :           else if (MEM_P (op))
    3797                 :             :             {
    3798                 :             :               /* We won't recognize either volatile memory or memory
    3799                 :             :                  with a queued address as available a memory_operand
    3800                 :             :                  at this point.  Ignore it: clearly this *is* a memory.  */
    3801                 :             :             }
    3802                 :             :           else
    3803                 :           0 :             gcc_unreachable ();
    3804                 :             :         }
    3805                 :       51907 :       input_rvec[i] = op;
    3806                 :       51907 :       input_mode[i] = TYPE_MODE (type);
    3807                 :             :     }
    3808                 :             : 
    3809                 :             :   /* For in-out operands, copy output rtx to input rtx.  */
    3810                 :      103837 :   unsigned ninout = inout_opnum.length ();
    3811                 :      103837 :   for (i = 0; i < ninout; i++)
    3812                 :             :     {
    3813                 :           0 :       int j = inout_opnum[i];
    3814                 :           0 :       rtx o = output_rvec[j];
    3815                 :             : 
    3816                 :           0 :       input_rvec.safe_push (o);
    3817                 :           0 :       input_mode.safe_push (GET_MODE (o));
    3818                 :             : 
    3819                 :           0 :       char buffer[16];
    3820                 :           0 :       sprintf (buffer, "%d", j);
    3821                 :           0 :       constraints.safe_push (ggc_strdup (buffer));
    3822                 :             :     }
    3823                 :      103837 :   ninputs += ninout;
    3824                 :             : 
    3825                 :             :   /* Sometimes we wish to automatically clobber registers across an asm.
    3826                 :             :      Case in point is when the i386 backend moved from cc0 to a hard reg --
    3827                 :             :      maintaining source-level compatibility means automatically clobbering
    3828                 :             :      the flags register.  */
    3829                 :      103837 :   rtx_insn *after_md_seq = NULL;
    3830                 :      207674 :   auto_vec<rtx> use_rvec;
    3831                 :      103837 :   if (targetm.md_asm_adjust)
    3832                 :      103837 :     after_md_seq
    3833                 :      103837 :         = targetm.md_asm_adjust (output_rvec, input_rvec, input_mode,
    3834                 :             :                                  constraints, use_rvec, clobber_rvec,
    3835                 :             :                                  clobbered_regs, locus);
    3836                 :             : 
    3837                 :             :   /* Do not allow the hook to change the output and input count,
    3838                 :             :      lest it mess up the operand numbering.  */
    3839                 :      207674 :   gcc_assert (output_rvec.length() == noutputs);
    3840                 :      207674 :   gcc_assert (input_rvec.length() == ninputs);
    3841                 :      207674 :   gcc_assert (constraints.length() == noutputs + ninputs);
    3842                 :             : 
    3843                 :             :   /* But it certainly can adjust the uses and clobbers.  */
    3844                 :      103837 :   unsigned nuses = use_rvec.length ();
    3845                 :      103837 :   unsigned nclobbers = clobber_rvec.length ();
    3846                 :             : 
    3847                 :             :   /* Third pass checks for easy conflicts.  */
    3848                 :             :   /* ??? Why are we doing this on trees instead of rtx.  */
    3849                 :             : 
    3850                 :      103837 :   bool clobber_conflict_found = 0;
    3851                 :      175520 :   for (i = 0; i < noutputs; ++i)
    3852                 :       71683 :     if (tree_conflicts_with_clobbers_p (output_tvec[i], &clobbered_regs, locus))
    3853                 :          10 :         clobber_conflict_found = 1;
    3854                 :      155744 :   for (i = 0; i < ninputs - ninout; ++i)
    3855                 :       51907 :     if (tree_conflicts_with_clobbers_p (input_tvec[i], &clobbered_regs, locus))
    3856                 :          11 :         clobber_conflict_found = 1;
    3857                 :             : 
    3858                 :             :   /* Make vectors for the expression-rtx, constraint strings,
    3859                 :             :      and named operands.  */
    3860                 :             : 
    3861                 :      103837 :   rtvec argvec = rtvec_alloc (ninputs);
    3862                 :      103837 :   rtvec constraintvec = rtvec_alloc (ninputs);
    3863                 :      103837 :   rtvec labelvec = rtvec_alloc (nlabels);
    3864                 :             : 
    3865                 :      136642 :   rtx body = gen_rtx_ASM_OPERANDS ((noutputs == 0 ? VOIDmode
    3866                 :             :                                     : GET_MODE (output_rvec[0])),
    3867                 :             :                                    ggc_strdup (str),
    3868                 :             :                                    "", 0, argvec, constraintvec,
    3869                 :             :                                    labelvec, locus);
    3870                 :      103837 :   MEM_VOLATILE_P (body) = gimple_asm_volatile_p (stmt);
    3871                 :             : 
    3872                 :      155744 :   for (i = 0; i < ninputs; ++i)
    3873                 :             :     {
    3874                 :       51907 :       ASM_OPERANDS_INPUT (body, i) = input_rvec[i];
    3875                 :      103814 :       ASM_OPERANDS_INPUT_CONSTRAINT_EXP (body, i)
    3876                 :       51907 :         = gen_rtx_ASM_INPUT_loc (input_mode[i],
    3877                 :             :                                  constraints[i + noutputs],
    3878                 :             :                                  locus);
    3879                 :             :     }
    3880                 :             : 
    3881                 :             :   /* Copy labels to the vector.  */
    3882                 :      103837 :   rtx_code_label *fallthru_label = NULL;
    3883                 :      103837 :   if (nlabels > 0)
    3884                 :             :     {
    3885                 :         445 :       basic_block fallthru_bb = NULL;
    3886                 :         445 :       edge fallthru = find_fallthru_edge (gimple_bb (stmt)->succs);
    3887                 :         445 :       if (fallthru)
    3888                 :         445 :         fallthru_bb = fallthru->dest;
    3889                 :             : 
    3890                 :        1133 :       for (i = 0; i < nlabels; ++i)
    3891                 :             :         {
    3892                 :         688 :           tree label = TREE_VALUE (gimple_asm_label_op (stmt, i));
    3893                 :         688 :           rtx_insn *r;
    3894                 :             :           /* If asm goto has any labels in the fallthru basic block, use
    3895                 :             :              a label that we emit immediately after the asm goto.  Expansion
    3896                 :             :              may insert further instructions into the same basic block after
    3897                 :             :              asm goto and if we don't do this, insertion of instructions on
    3898                 :             :              the fallthru edge might misbehave.  See PR58670.  */
    3899                 :         688 :           if (fallthru_bb && label_to_block (cfun, label) == fallthru_bb)
    3900                 :             :             {
    3901                 :         240 :               if (fallthru_label == NULL_RTX)
    3902                 :         235 :                 fallthru_label = gen_label_rtx ();
    3903                 :             :               r = fallthru_label;
    3904                 :             :             }
    3905                 :             :           else
    3906                 :         448 :             r = label_rtx (label);
    3907                 :         688 :           ASM_OPERANDS_LABEL (body, i) = gen_rtx_LABEL_REF (Pmode, r);
    3908                 :             :         }
    3909                 :             :     }
    3910                 :             : 
    3911                 :             :   /* Now, for each output, construct an rtx
    3912                 :             :      (set OUTPUT (asm_operands INSN OUTPUTCONSTRAINT OUTPUTNUMBER
    3913                 :             :                                ARGVEC CONSTRAINTS OPNAMES))
    3914                 :             :      If there is more than one, put them inside a PARALLEL.  */
    3915                 :             : 
    3916                 :      103837 :   if (noutputs == 0 && nuses == 0 && nclobbers == 0)
    3917                 :             :     {
    3918                 :             :       /* No output operands: put in a raw ASM_OPERANDS rtx.  */
    3919                 :           0 :       if (nlabels > 0)
    3920                 :           0 :         emit_jump_insn (body);
    3921                 :             :       else
    3922                 :           0 :         emit_insn (body);
    3923                 :             :     }
    3924                 :      103837 :   else if (noutputs == 1 && nuses == 0 && nclobbers == 0)
    3925                 :             :     {
    3926                 :          62 :       ASM_OPERANDS_OUTPUT_CONSTRAINT (body) = constraints[0];
    3927                 :          62 :       if (nlabels > 0)
    3928                 :           0 :         emit_jump_insn (gen_rtx_SET (output_rvec[0], body));
    3929                 :             :       else
    3930                 :          62 :         emit_insn (gen_rtx_SET (output_rvec[0], body));
    3931                 :             :     }
    3932                 :             :   else
    3933                 :             :     {
    3934                 :      103775 :       rtx obody = body;
    3935                 :      103775 :       int num = noutputs;
    3936                 :             : 
    3937                 :      103775 :       if (num == 0)
    3938                 :       71032 :         num = 1;
    3939                 :             : 
    3940                 :      103775 :       body = gen_rtx_PARALLEL (VOIDmode,
    3941                 :             :                                rtvec_alloc (num + nuses + nclobbers));
    3942                 :             : 
    3943                 :             :       /* For each output operand, store a SET.  */
    3944                 :      175396 :       for (i = 0; i < noutputs; ++i)
    3945                 :             :         {
    3946                 :       71621 :           rtx src, o = output_rvec[i];
    3947                 :       71621 :           if (i == 0)
    3948                 :             :             {
    3949                 :       32743 :               ASM_OPERANDS_OUTPUT_CONSTRAINT (obody) = constraints[0];
    3950                 :       32743 :               src = obody;
    3951                 :             :             }
    3952                 :             :           else
    3953                 :             :             {
    3954                 :       38878 :               src = gen_rtx_ASM_OPERANDS (GET_MODE (o),
    3955                 :             :                                           ASM_OPERANDS_TEMPLATE (obody),
    3956                 :             :                                           constraints[i], i, argvec,
    3957                 :             :                                           constraintvec, labelvec, locus);
    3958                 :       38878 :               MEM_VOLATILE_P (src) = gimple_asm_volatile_p (stmt);
    3959                 :             :             }
    3960                 :       71621 :           XVECEXP (body, 0, i) = gen_rtx_SET (o, src);
    3961                 :             :         }
    3962                 :             : 
    3963                 :             :       /* If there are no outputs (but there are some clobbers)
    3964                 :             :          store the bare ASM_OPERANDS into the PARALLEL.  */
    3965                 :      103775 :       if (i == 0)
    3966                 :       71032 :         XVECEXP (body, 0, i++) = obody;
    3967                 :             : 
    3968                 :             :       /* Add the uses specified by the target hook.  No checking should
    3969                 :             :          be needed since this doesn't come directly from user code.  */
    3970                 :      103775 :       for (rtx use : use_rvec)
    3971                 :           0 :         XVECEXP (body, 0, i++) = gen_rtx_USE (VOIDmode, use);
    3972                 :             : 
    3973                 :             :       /* Store (clobber REG) for each clobbered register specified.  */
    3974                 :      287876 :       for (unsigned j = 0; j < nclobbers; ++j)
    3975                 :             :         {
    3976                 :      184101 :           rtx clobbered_reg = clobber_rvec[j];
    3977                 :             : 
    3978                 :             :           /* Do sanity check for overlap between clobbers and respectively
    3979                 :             :              input and outputs that hasn't been handled.  Such overlap
    3980                 :             :              should have been detected and reported above.  */
    3981                 :      184101 :           if (!clobber_conflict_found && REG_P (clobbered_reg))
    3982                 :             :             {
    3983                 :             :               /* We test the old body (obody) contents to avoid
    3984                 :             :                  tripping over the under-construction body.  */
    3985                 :      217822 :               for (unsigned k = 0; k < noutputs; ++k)
    3986                 :       72564 :                 if (reg_overlap_mentioned_p (clobbered_reg, output_rvec[k]))
    3987                 :           0 :                   internal_error ("%<asm%> clobber conflict with "
    3988                 :             :                                   "output operand");
    3989                 :             : 
    3990                 :      199936 :               for (unsigned k = 0; k < ninputs - ninout; ++k)
    3991                 :       54678 :                 if (reg_overlap_mentioned_p (clobbered_reg, input_rvec[k]))
    3992                 :           0 :                   internal_error ("%<asm%> clobber conflict with "
    3993                 :             :                                   "input operand");
    3994                 :             :             }
    3995                 :             : 
    3996                 :      184101 :           XVECEXP (body, 0, i++) = gen_rtx_CLOBBER (VOIDmode, clobbered_reg);
    3997                 :             :         }
    3998                 :             : 
    3999                 :      103775 :       if (nlabels > 0)
    4000                 :         445 :         emit_jump_insn (body);
    4001                 :             :       else
    4002                 :      103330 :         emit_insn (body);
    4003                 :             :     }
    4004                 :             : 
    4005                 :      103837 :   generating_concat_p = old_generating_concat_p;
    4006                 :             : 
    4007                 :      103837 :   if (fallthru_label)
    4008                 :         235 :     emit_label (fallthru_label);
    4009                 :             : 
    4010                 :      103837 :   if (after_md_seq)
    4011                 :          71 :     emit_insn (after_md_seq);
    4012                 :      103837 :   if (after_rtl_seq)
    4013                 :             :     {
    4014                 :       26059 :       if (nlabels == 0)
    4015                 :       25934 :         emit_insn (after_rtl_seq);
    4016                 :             :       else
    4017                 :             :         {
    4018                 :         125 :           edge e;
    4019                 :         125 :           edge_iterator ei;
    4020                 :         125 :           unsigned int cnt = EDGE_COUNT (gimple_bb (stmt)->succs);
    4021                 :             : 
    4022                 :         458 :           FOR_EACH_EDGE (e, ei, gimple_bb (stmt)->succs)
    4023                 :             :             {
    4024                 :         333 :               rtx_insn *copy;
    4025                 :         333 :               if (--cnt == 0)
    4026                 :             :                 copy = after_rtl_seq;
    4027                 :             :               else
    4028                 :             :                 {
    4029                 :         208 :                   start_sequence ();
    4030                 :         208 :                   duplicate_insn_chain (after_rtl_seq, after_rtl_end,
    4031                 :             :                                         NULL, NULL);
    4032                 :         208 :                   copy = end_sequence ();
    4033                 :             :                 }
    4034                 :         333 :               prepend_insn_to_edge (copy, e);
    4035                 :             :             }
    4036                 :             :         }
    4037                 :             :     }
    4038                 :             : 
    4039                 :      103837 :   free_temp_slots ();
    4040                 :      103837 :   crtl->has_asm_statement = 1;
    4041                 :      103842 : }
    4042                 :             : 
    4043                 :             : /* Emit code to jump to the address
    4044                 :             :    specified by the pointer expression EXP.  */
    4045                 :             : 
    4046                 :             : static void
    4047                 :         394 : expand_computed_goto (tree exp)
    4048                 :             : {
    4049                 :         394 :   rtx x = expand_normal (exp);
    4050                 :             : 
    4051                 :         394 :   do_pending_stack_adjust ();
    4052                 :         394 :   emit_indirect_jump (x);
    4053                 :         394 : }
    4054                 :             : 
    4055                 :             : /* Generate RTL code for a `goto' statement with target label LABEL.
    4056                 :             :    LABEL should be a LABEL_DECL tree node that was or will later be
    4057                 :             :    defined with `expand_label'.  */
    4058                 :             : 
    4059                 :             : static void
    4060                 :           0 : expand_goto (tree label)
    4061                 :             : {
    4062                 :           0 :   if (flag_checking)
    4063                 :             :     {
    4064                 :             :       /* Check for a nonlocal goto to a containing function.  Should have
    4065                 :             :          gotten translated to __builtin_nonlocal_goto.  */
    4066                 :           0 :       tree context = decl_function_context (label);
    4067                 :           0 :       gcc_assert (!context || context == current_function_decl);
    4068                 :             :     }
    4069                 :             : 
    4070                 :           0 :   emit_jump (jump_target_rtx (label));
    4071                 :           0 : }
    4072                 :             : 
    4073                 :             : /* Output a return with no value.  */
    4074                 :             : 
    4075                 :             : static void
    4076                 :      816452 : expand_null_return_1 (void)
    4077                 :             : {
    4078                 :      816452 :   clear_pending_stack_adjust ();
    4079                 :      816452 :   do_pending_stack_adjust ();
    4080                 :      816452 :   emit_jump (return_label);
    4081                 :      816452 : }
    4082                 :             : 
    4083                 :             : /* Generate RTL to return from the current function, with no value.
    4084                 :             :    (That is, we do not do anything about returning any value.)  */
    4085                 :             : 
    4086                 :             : void
    4087                 :       73359 : expand_null_return (void)
    4088                 :             : {
    4089                 :             :   /* If this function was declared to return a value, but we
    4090                 :             :      didn't, clobber the return registers so that they are not
    4091                 :             :      propagated live to the rest of the function.  */
    4092                 :       73359 :   clobber_return_register ();
    4093                 :             : 
    4094                 :       73359 :   expand_null_return_1 ();
    4095                 :       73359 : }
    4096                 :             : 
    4097                 :             : /* Generate RTL to return from the current function, with value VAL.  */
    4098                 :             : 
    4099                 :             : static void
    4100                 :      743093 : expand_value_return (rtx val)
    4101                 :             : {
    4102                 :             :   /* Copy the value to the return location unless it's already there.  */
    4103                 :             : 
    4104                 :      743093 :   tree decl = DECL_RESULT (current_function_decl);
    4105                 :      743093 :   rtx return_reg = DECL_RTL (decl);
    4106                 :      743093 :   if (return_reg != val)
    4107                 :             :     {
    4108                 :      427190 :       tree funtype = TREE_TYPE (current_function_decl);
    4109                 :      427190 :       tree type = TREE_TYPE (decl);
    4110                 :      427190 :       int unsignedp = TYPE_UNSIGNED (type);
    4111                 :      427190 :       machine_mode old_mode = DECL_MODE (decl);
    4112                 :      427190 :       machine_mode mode;
    4113                 :      427190 :       if (DECL_BY_REFERENCE (decl))
    4114                 :           0 :         mode = promote_function_mode (type, old_mode, &unsignedp, funtype, 2);
    4115                 :             :       else
    4116                 :      427190 :         mode = promote_function_mode (type, old_mode, &unsignedp, funtype, 1);
    4117                 :             : 
    4118                 :      427190 :       if (mode != old_mode)
    4119                 :             :         {
    4120                 :             :           /* Some ABIs require scalar floating point modes to be returned
    4121                 :             :              in a wider scalar integer mode.  We need to explicitly
    4122                 :             :              reinterpret to an integer mode of the correct precision
    4123                 :             :              before extending to the desired result.  */
    4124                 :           8 :           if (SCALAR_INT_MODE_P (mode)
    4125                 :           8 :               && SCALAR_FLOAT_MODE_P (old_mode)
    4126                 :           8 :               && known_gt (GET_MODE_SIZE (mode), GET_MODE_SIZE (old_mode)))
    4127                 :           0 :             val = convert_float_to_wider_int (mode, old_mode, val);
    4128                 :             :           else
    4129                 :           8 :             val = convert_modes (mode, old_mode, val, unsignedp);
    4130                 :             :         }
    4131                 :             : 
    4132                 :      427190 :       if (GET_CODE (return_reg) == PARALLEL)
    4133                 :        2950 :         emit_group_load (return_reg, val, type, int_size_in_bytes (type));
    4134                 :             :       else
    4135                 :      424240 :         emit_move_insn (return_reg, val);
    4136                 :             :     }
    4137                 :             : 
    4138                 :      743093 :   expand_null_return_1 ();
    4139                 :      743093 : }
    4140                 :             : 
    4141                 :             : /* Generate RTL to evaluate the expression RETVAL and return it
    4142                 :             :    from the current function.  */
    4143                 :             : 
    4144                 :             : static void
    4145                 :      745861 : expand_return (tree retval)
    4146                 :             : {
    4147                 :      745861 :   rtx result_rtl;
    4148                 :      745861 :   rtx val = 0;
    4149                 :      745861 :   tree retval_rhs;
    4150                 :             : 
    4151                 :             :   /* If function wants no value, give it none.  */
    4152                 :      745861 :   if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (current_function_decl))))
    4153                 :             :     {
    4154                 :           0 :       expand_normal (retval);
    4155                 :           0 :       expand_null_return ();
    4156                 :           0 :       return;
    4157                 :             :     }
    4158                 :             : 
    4159                 :      745861 :   if (retval == error_mark_node)
    4160                 :             :     {
    4161                 :             :       /* Treat this like a return of no value from a function that
    4162                 :             :          returns a value.  */
    4163                 :           0 :       expand_null_return ();
    4164                 :           0 :       return;
    4165                 :             :     }
    4166                 :      745861 :   else if ((TREE_CODE (retval) == MODIFY_EXPR
    4167                 :      745861 :             || TREE_CODE (retval) == INIT_EXPR)
    4168                 :      745861 :            && TREE_CODE (TREE_OPERAND (retval, 0)) == RESULT_DECL)
    4169                 :      683559 :     retval_rhs = TREE_OPERAND (retval, 1);
    4170                 :             :   else
    4171                 :             :     retval_rhs = retval;
    4172                 :             : 
    4173                 :      745861 :   result_rtl = DECL_RTL (DECL_RESULT (current_function_decl));
    4174                 :             : 
    4175                 :             :   /* If we are returning the RESULT_DECL, then the value has already
    4176                 :             :      been stored into it, so we don't have to do anything special.  */
    4177                 :      745861 :   if (TREE_CODE (retval_rhs) == RESULT_DECL)
    4178                 :       62302 :     expand_value_return (result_rtl);
    4179                 :             : 
    4180                 :             :   /* If the result is an aggregate that is being returned in one (or more)
    4181                 :             :      registers, load the registers here.  */
    4182                 :             : 
    4183                 :      683559 :   else if (retval_rhs != 0
    4184                 :      683559 :            && TYPE_MODE (TREE_TYPE (retval_rhs)) == BLKmode
    4185                 :        5442 :            && REG_P (result_rtl))
    4186                 :             :     {
    4187                 :        3989 :       val = copy_blkmode_to_reg (GET_MODE (result_rtl), retval_rhs);
    4188                 :        3989 :       if (val)
    4189                 :             :         {
    4190                 :             :           /* Use the mode of the result value on the return register.  */
    4191                 :        1221 :           PUT_MODE (result_rtl, GET_MODE (val));
    4192                 :        1221 :           expand_value_return (val);
    4193                 :             :         }
    4194                 :             :       else
    4195                 :        2768 :         expand_null_return ();
    4196                 :             :     }
    4197                 :      679570 :   else if (retval_rhs != 0
    4198                 :      679570 :            && !VOID_TYPE_P (TREE_TYPE (retval_rhs))
    4199                 :      679570 :            && (REG_P (result_rtl)
    4200                 :        5604 :                || (GET_CODE (result_rtl) == PARALLEL)))
    4201                 :             :     {
    4202                 :             :       /* Compute the return value into a temporary (usually a pseudo reg).  */
    4203                 :      676916 :       val
    4204                 :      676916 :         = assign_temp (TREE_TYPE (DECL_RESULT (current_function_decl)), 0, 1);
    4205                 :      676916 :       val = expand_expr (retval_rhs, val, GET_MODE (val), EXPAND_NORMAL);
    4206                 :      676916 :       val = force_not_mem (val);
    4207                 :      676916 :       expand_value_return (val);
    4208                 :             :     }
    4209                 :             :   else
    4210                 :             :     {
    4211                 :             :       /* No hard reg used; calculate value into hard return reg.  */
    4212                 :        2654 :       expand_expr (retval, const0_rtx, VOIDmode, EXPAND_NORMAL);
    4213                 :        2654 :       expand_value_return (result_rtl);
    4214                 :             :     }
    4215                 :             : }
    4216                 :             : 
    4217                 :             : /* Expand a clobber of LHS.  If LHS is stored it in a multi-part
    4218                 :             :    register, tell the rtl optimizers that its value is no longer
    4219                 :             :    needed.  */
    4220                 :             : 
    4221                 :             : static void
    4222                 :     1531934 : expand_clobber (tree lhs)
    4223                 :             : {
    4224                 :     1531934 :   if (DECL_P (lhs))
    4225                 :             :     {
    4226                 :     1260626 :       rtx decl_rtl = DECL_RTL_IF_SET (lhs);
    4227                 :     1260582 :       if (decl_rtl && REG_P (decl_rtl))
    4228                 :             :         {
    4229                 :      196528 :           machine_mode decl_mode = GET_MODE (decl_rtl);
    4230                 :      393056 :           if (maybe_gt (GET_MODE_SIZE (decl_mode),
    4231                 :             :                         REGMODE_NATURAL_SIZE (decl_mode)))
    4232                 :      156332 :             emit_clobber (decl_rtl);
    4233                 :             :         }
    4234                 :             :     }
    4235                 :     1531934 : }
    4236                 :             : 
    4237                 :             : /* A subroutine of expand_gimple_stmt, expanding one gimple statement
    4238                 :             :    STMT that doesn't require special handling for outgoing edges.  That
    4239                 :             :    is no tailcalls and no GIMPLE_COND.  */
    4240                 :             : 
    4241                 :             : static void
    4242                 :    31331451 : expand_gimple_stmt_1 (gimple *stmt)
    4243                 :             : {
    4244                 :    31331451 :   tree op0;
    4245                 :             : 
    4246                 :    31331451 :   set_curr_insn_location (gimple_location (stmt));
    4247                 :             : 
    4248                 :    31331451 :   switch (gimple_code (stmt))
    4249                 :             :     {
    4250                 :         394 :     case GIMPLE_GOTO:
    4251                 :         394 :       op0 = gimple_goto_dest (stmt);
    4252                 :         394 :       if (TREE_CODE (op0) == LABEL_DECL)
    4253                 :           0 :         expand_goto (op0);
    4254                 :             :       else
    4255                 :         394 :         expand_computed_goto (op0);
    4256                 :             :       break;
    4257                 :      623394 :     case GIMPLE_LABEL:
    4258                 :      623394 :       expand_label (gimple_label_label (as_a <glabel *> (stmt)));
    4259                 :      623394 :       break;
    4260                 :             :     case GIMPLE_NOP:
    4261                 :             :     case GIMPLE_PREDICT:
    4262                 :             :       break;
    4263                 :        9049 :     case GIMPLE_SWITCH:
    4264                 :        9049 :       {
    4265                 :        9049 :         gswitch *swtch = as_a <gswitch *> (stmt);
    4266                 :        9049 :         if (gimple_switch_num_labels (swtch) == 1)
    4267                 :           0 :           expand_goto (CASE_LABEL (gimple_switch_default_label (swtch)));
    4268                 :             :         else
    4269                 :        9049 :           expand_case (swtch);
    4270                 :             :       }
    4271                 :             :       break;
    4272                 :      106647 :     case GIMPLE_ASM:
    4273                 :      106647 :       expand_asm_stmt (as_a <gasm *> (stmt));
    4274                 :      106647 :       break;
    4275                 :     6729038 :     case GIMPLE_CALL:
    4276                 :     6729038 :       expand_call_stmt (as_a <gcall *> (stmt));
    4277                 :     6729038 :       break;
    4278                 :             : 
    4279                 :      816452 :     case GIMPLE_RETURN:
    4280                 :      816452 :       {
    4281                 :      816452 :         op0 = gimple_return_retval (as_a <greturn *> (stmt));
    4282                 :             : 
    4283                 :             :         /* If a return doesn't have a location, it very likely represents
    4284                 :             :            multiple user returns so we cannot let it inherit the location
    4285                 :             :            of the last statement of the previous basic block in RTL.  */
    4286                 :      816452 :         if (!gimple_has_location (stmt))
    4287                 :      218481 :           set_curr_insn_location (cfun->function_end_locus);
    4288                 :             : 
    4289                 :      816452 :         if (op0 && op0 != error_mark_node)
    4290                 :             :           {
    4291                 :      745861 :             tree result = DECL_RESULT (current_function_decl);
    4292                 :             : 
    4293                 :             :             /* If we are not returning the current function's RESULT_DECL,
    4294                 :             :                build an assignment to it.  */
    4295                 :      745861 :             if (op0 != result)
    4296                 :             :               {
    4297                 :             :                 /* I believe that a function's RESULT_DECL is unique.  */
    4298                 :      683559 :                 gcc_assert (TREE_CODE (op0) != RESULT_DECL);
    4299                 :             : 
    4300                 :             :                 /* ??? We'd like to use simply expand_assignment here,
    4301                 :             :                    but this fails if the value is of BLKmode but the return
    4302                 :             :                    decl is a register.  expand_return has special handling
    4303                 :             :                    for this combination, which eventually should move
    4304                 :             :                    to common code.  See comments there.  Until then, let's
    4305                 :             :                    build a modify expression :-/  */
    4306                 :      683559 :                 op0 = build2 (MODIFY_EXPR, TREE_TYPE (result),
    4307                 :             :                               result, op0);
    4308                 :             :               }
    4309                 :             :           }
    4310                 :             : 
    4311                 :      745861 :         if (!op0)
    4312                 :       70591 :           expand_null_return ();
    4313                 :             :         else
    4314                 :      745861 :           expand_return (op0);
    4315                 :             :       }
    4316                 :             :       break;
    4317                 :             : 
    4318                 :    23001915 :     case GIMPLE_ASSIGN:
    4319                 :    23001915 :       {
    4320                 :    23001915 :         gassign *assign_stmt = as_a <gassign *> (stmt);
    4321                 :    23001915 :         tree lhs = gimple_assign_lhs (assign_stmt);
    4322                 :             : 
    4323                 :             :         /* Tree expand used to fiddle with |= and &= of two bitfield
    4324                 :             :            COMPONENT_REFs here.  This can't happen with gimple, the LHS
    4325                 :             :            of binary assigns must be a gimple reg.  */
    4326                 :             : 
    4327                 :    23001915 :         if (TREE_CODE (lhs) != SSA_NAME
    4328                 :    36447572 :             || gimple_assign_rhs_class (assign_stmt) == GIMPLE_SINGLE_RHS)
    4329                 :             :           {
    4330                 :    17215207 :             tree rhs = gimple_assign_rhs1 (assign_stmt);
    4331                 :    17215207 :             gcc_assert (gimple_assign_rhs_class (assign_stmt)
    4332                 :             :                         == GIMPLE_SINGLE_RHS);
    4333                 :    32819291 :             if (gimple_has_location (stmt) && CAN_HAVE_LOCATION_P (rhs)
    4334                 :             :                 /* Do not put locations on possibly shared trees.  */
    4335                 :    23140456 :                 && !is_gimple_min_invariant (rhs))
    4336                 :     4819874 :               SET_EXPR_LOCATION (rhs, gimple_location (stmt));
    4337                 :    17215207 :             if (TREE_CLOBBER_P (rhs))
    4338                 :             :               /* This is a clobber to mark the going out of scope for
    4339                 :             :                  this LHS.  */
    4340                 :     1531934 :               expand_clobber (lhs);
    4341                 :             :             else
    4342                 :    15683273 :               expand_assignment (lhs, rhs,
    4343                 :    15683273 :                                  gimple_assign_nontemporal_move_p (
    4344                 :             :                                    assign_stmt));
    4345                 :             :           }
    4346                 :             :         else
    4347                 :             :           {
    4348                 :     5786708 :             rtx target, temp;
    4349                 :     5786708 :             gcc_assert (!gimple_assign_nontemporal_move_p (assign_stmt));
    4350                 :     5786708 :             bool promoted = false;
    4351                 :             : 
    4352                 :     5786708 :             target = expand_expr (lhs, NULL_RTX, VOIDmode, EXPAND_WRITE);
    4353                 :     5786708 :             if (GET_CODE (target) == SUBREG && SUBREG_PROMOTED_VAR_P (target))
    4354                 :             :               promoted = true;
    4355                 :             : 
    4356                 :             :            /* If we store into a promoted register, don't directly
    4357                 :             :               expand to target.  */
    4358                 :             :             temp = promoted ? NULL_RTX : target;
    4359                 :    11573416 :             temp = expand_expr_real_gassign (assign_stmt, temp,
    4360                 :     5786708 :                                              GET_MODE (target), EXPAND_NORMAL);
    4361                 :             : 
    4362                 :     5786708 :             if (temp == target)
    4363                 :             :               ;
    4364                 :      780829 :             else if (promoted)
    4365                 :             :               {
    4366                 :           3 :                 int unsignedp = SUBREG_PROMOTED_SIGN (target);
    4367                 :             :                 /* If TEMP is a VOIDmode constant, use convert_modes to make
    4368                 :             :                    sure that we properly convert it.  */
    4369                 :           3 :                 if (CONSTANT_P (temp) && GET_MODE (temp) == VOIDmode)
    4370                 :             :                   {
    4371                 :           0 :                     temp = convert_modes (GET_MODE (target),
    4372                 :           0 :                                           TYPE_MODE (TREE_TYPE (lhs)),
    4373                 :             :                                           temp, unsignedp);
    4374                 :           0 :                     temp = convert_modes (GET_MODE (SUBREG_REG (target)),
    4375                 :           0 :                                           GET_MODE (target), temp, unsignedp);
    4376                 :             :                   }
    4377                 :             : 
    4378                 :           3 :                 convert_move (SUBREG_REG (target), temp, unsignedp);
    4379                 :             :               }
    4380                 :             :             else
    4381                 :             :               {
    4382                 :      780826 :                 temp = force_operand (temp, target);
    4383                 :      780826 :                 if (temp == target)
    4384                 :             :                   ;
    4385                 :      780826 :                 else if (GET_MODE (target) != BLKmode)
    4386                 :      780825 :                   emit_move_insn (target, temp);
    4387                 :             :                 else
    4388                 :           1 :                   emit_block_move (target, temp, expr_size (lhs),
    4389                 :             :                                    BLOCK_OP_NORMAL);
    4390                 :             :               }
    4391                 :             :           }
    4392                 :             :       }
    4393                 :             :       break;
    4394                 :             : 
    4395                 :           0 :     default:
    4396                 :           0 :       gcc_unreachable ();
    4397                 :             :     }
    4398                 :    31331451 : }
    4399                 :             : 
    4400                 :             : /* Expand one gimple statement STMT and return the last RTL instruction
    4401                 :             :    before any of the newly generated ones.
    4402                 :             : 
    4403                 :             :    In addition to generating the necessary RTL instructions this also
    4404                 :             :    sets REG_EH_REGION notes if necessary and sets the current source
    4405                 :             :    location for diagnostics.  */
    4406                 :             : 
    4407                 :             : static rtx_insn *
    4408                 :    31331451 : expand_gimple_stmt (gimple *stmt)
    4409                 :             : {
    4410                 :    31331451 :   location_t saved_location = input_location;
    4411                 :    31331451 :   rtx_insn *last = get_last_insn ();
    4412                 :    31331451 :   int lp_nr;
    4413                 :             : 
    4414                 :    31331451 :   gcc_assert (cfun);
    4415                 :             : 
    4416                 :             :   /* We need to save and restore the current source location so that errors
    4417                 :             :      discovered during expansion are emitted with the right location.  But
    4418                 :             :      it would be better if the diagnostic routines used the source location
    4419                 :             :      embedded in the tree nodes rather than globals.  */
    4420                 :    31331451 :   if (gimple_has_location (stmt))
    4421                 :    27432941 :     input_location = gimple_location (stmt);
    4422                 :             : 
    4423                 :    31331451 :   expand_gimple_stmt_1 (stmt);
    4424                 :             : 
    4425                 :             :   /* Free any temporaries used to evaluate this statement.  */
    4426                 :    31331451 :   free_temp_slots ();
    4427                 :             : 
    4428                 :    31331451 :   input_location = saved_location;
    4429                 :             : 
    4430                 :             :   /* Mark all insns that may trap.  */
    4431                 :    31331451 :   lp_nr = lookup_stmt_eh_lp (stmt);
    4432                 :    31331451 :   if (lp_nr)
    4433                 :             :     {
    4434                 :      716826 :       rtx_insn *insn;
    4435                 :     4182790 :       for (insn = next_real_insn (last); insn;
    4436                 :     3465964 :            insn = next_real_insn (insn))
    4437                 :             :         {
    4438                 :     3465964 :           if (! find_reg_note (insn, REG_EH_REGION, NULL_RTX)
    4439                 :             :               /* If we want exceptions for non-call insns, any
    4440                 :             :                  may_trap_p instruction may throw.  */
    4441                 :     3465899 :               && GET_CODE (PATTERN (insn)) != CLOBBER
    4442                 :     3465829 :               && GET_CODE (PATTERN (insn)) != USE
    4443                 :     6931793 :               && insn_could_throw_p (insn))
    4444                 :      775984 :             make_reg_eh_region_note (insn, 0, lp_nr);
    4445                 :             :         }
    4446                 :             :     }
    4447                 :             : 
    4448                 :    31331451 :   return last;
    4449                 :             : }
    4450                 :             : 
    4451                 :             : /* A subroutine of expand_gimple_basic_block.  Expand one GIMPLE_CALL
    4452                 :             :    that has CALL_EXPR_TAILCALL set.  Returns non-null if we actually
    4453                 :             :    generated a tail call (something that might be denied by the ABI
    4454                 :             :    rules governing the call; see calls.cc).
    4455                 :             : 
    4456                 :             :    Sets CAN_FALLTHRU if we generated a *conditional* tail call, and
    4457                 :             :    can still reach the rest of BB.  The case here is __builtin_sqrt,
    4458                 :             :    where the NaN result goes through the external function (with a
    4459                 :             :    tailcall) and the normal result happens via a sqrt instruction.  */
    4460                 :             : 
    4461                 :             : static basic_block
    4462                 :      173054 : expand_gimple_tailcall (basic_block bb, gcall *stmt, bool *can_fallthru,
    4463                 :             :                         rtx_insn *asan_epilog_seq)
    4464                 :             : {
    4465                 :      173054 :   rtx_insn *last2, *last, *first = get_last_insn ();
    4466                 :      173054 :   edge e;
    4467                 :      173054 :   edge_iterator ei;
    4468                 :      173054 :   profile_probability probability;
    4469                 :             : 
    4470                 :      173054 :   last2 = last = expand_gimple_stmt (stmt);
    4471                 :             : 
    4472                 :      739358 :   for (last = NEXT_INSN (last); last; last = NEXT_INSN (last))
    4473                 :      690466 :     if (CALL_P (last) && SIBLING_CALL_P (last))
    4474                 :      124162 :       goto found;
    4475                 :             : 
    4476                 :       48892 :   maybe_dump_rtl_for_gimple_stmt (stmt, last2);
    4477                 :             : 
    4478                 :       48892 :   *can_fallthru = true;
    4479                 :       48892 :   return NULL;
    4480                 :             : 
    4481                 :      124162 :  found:
    4482                 :             : 
    4483                 :      124162 :   if (asan_epilog_seq)
    4484                 :             :     {
    4485                 :             :       /* We need to emit a copy of the asan_epilog_seq before
    4486                 :             :          the insns emitted by expand_gimple_stmt above.  The sequence
    4487                 :             :          can contain labels, which need to be remapped.  */
    4488                 :          73 :       hash_map<rtx, rtx> label_map;
    4489                 :          73 :       start_sequence ();
    4490                 :          73 :       emit_note (NOTE_INSN_DELETED);
    4491                 :        1086 :       for (rtx_insn *insn = asan_epilog_seq; insn; insn = NEXT_INSN (insn))
    4492                 :        1013 :         switch (GET_CODE (insn))
    4493                 :             :           {
    4494                 :         794 :           case INSN:
    4495                 :         794 :           case CALL_INSN:
    4496                 :         794 :           case JUMP_INSN:
    4497                 :         794 :             emit_copy_of_insn_after (insn, get_last_insn ());
    4498                 :         794 :             break;
    4499                 :         146 :           case CODE_LABEL:
    4500                 :         146 :             label_map.put ((rtx) insn, (rtx) emit_label (gen_label_rtx ()));
    4501                 :         146 :             break;
    4502                 :          73 :           case BARRIER:
    4503                 :          73 :             emit_barrier ();
    4504                 :          73 :             break;
    4505                 :           0 :           default:
    4506                 :           0 :             gcc_unreachable ();
    4507                 :             :           }
    4508                 :        1159 :       for (rtx_insn *insn = get_insns (); insn; insn = NEXT_INSN (insn))
    4509                 :        1086 :         if (JUMP_P (insn))
    4510                 :             :           {
    4511                 :         146 :             subrtx_ptr_iterator::array_type array;
    4512                 :         949 :             FOR_EACH_SUBRTX_PTR (iter, array, &PATTERN (insn), ALL)
    4513                 :             :               {
    4514                 :         803 :                 rtx *loc = *iter;
    4515                 :         803 :                 if (LABEL_REF_P (*loc))
    4516                 :             :                   {
    4517                 :         146 :                     rtx *lab = label_map.get ((rtx) label_ref_label (*loc));
    4518                 :         146 :                     gcc_assert (lab);
    4519                 :         146 :                     set_label_ref_label (*loc, as_a <rtx_insn *> (*lab));
    4520                 :             :                   }
    4521                 :             :               }
    4522                 :         146 :             if (JUMP_LABEL (insn))
    4523                 :             :               {
    4524                 :         146 :                 rtx *lab = label_map.get (JUMP_LABEL (insn));
    4525                 :         146 :                 gcc_assert (lab);
    4526                 :         146 :                 JUMP_LABEL (insn) = *lab;
    4527                 :             :               }
    4528                 :         146 :           }
    4529                 :          73 :       asan_epilog_seq = NEXT_INSN (get_insns ());
    4530                 :          73 :       end_sequence ();
    4531                 :          73 :       emit_insn_before (asan_epilog_seq, NEXT_INSN (first));
    4532                 :          73 :     }
    4533                 :             : 
    4534                 :             :   /* ??? Wouldn't it be better to just reset any pending stack adjust?
    4535                 :             :      Any instructions emitted here are about to be deleted.  */
    4536                 :      124162 :   do_pending_stack_adjust ();
    4537                 :             : 
    4538                 :             :   /* Remove any non-eh, non-abnormal edges that don't go to exit.  */
    4539                 :             :   /* ??? I.e. the fallthrough edge.  HOWEVER!  If there were to be
    4540                 :             :      EH or abnormal edges, we shouldn't have created a tail call in
    4541                 :             :      the first place.  So it seems to me we should just be removing
    4542                 :             :      all edges here, or redirecting the existing fallthru edge to
    4543                 :             :      the exit block.  */
    4544                 :             : 
    4545                 :      124162 :   probability = profile_probability::never ();
    4546                 :             : 
    4547                 :      248323 :   for (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); )
    4548                 :             :     {
    4549                 :      124161 :       if (!(e->flags & (EDGE_ABNORMAL | EDGE_EH)))
    4550                 :             :         {
    4551                 :      124155 :           if (e->dest != EXIT_BLOCK_PTR_FOR_FN (cfun))
    4552                 :       60359 :             e->dest->count -= e->count ();
    4553                 :      124155 :           probability += e->probability;
    4554                 :      124155 :           expand_remove_edge (e);
    4555                 :             :         }
    4556                 :             :       else
    4557                 :           6 :         ei_next (&ei);
    4558                 :             :     }
    4559                 :             : 
    4560                 :             :   /* This is somewhat ugly: the call_expr expander often emits instructions
    4561                 :             :      after the sibcall (to perform the function return).  These confuse the
    4562                 :             :      find_many_sub_basic_blocks code, so we need to get rid of these.  */
    4563                 :      124162 :   last = NEXT_INSN (last);
    4564                 :      124162 :   gcc_assert (BARRIER_P (last));
    4565                 :             : 
    4566                 :      124162 :   *can_fallthru = false;
    4567                 :      153887 :   while (NEXT_INSN (last))
    4568                 :             :     {
    4569                 :             :       /* For instance an sqrt builtin expander expands if with
    4570                 :             :          sibcall in the then and label for `else`.  */
    4571                 :       29725 :       if (LABEL_P (NEXT_INSN (last)))
    4572                 :             :         {
    4573                 :           0 :           *can_fallthru = true;
    4574                 :           0 :           break;
    4575                 :             :         }
    4576                 :       29725 :       delete_insn (NEXT_INSN (last));
    4577                 :             :     }
    4578                 :             : 
    4579                 :      124162 :   e = make_edge (bb, EXIT_BLOCK_PTR_FOR_FN (cfun), EDGE_ABNORMAL
    4580                 :             :                  | EDGE_SIBCALL);
    4581                 :      124162 :   e->probability = probability;
    4582                 :      124162 :   head_end_for_bb[bb->index].second = last;
    4583                 :      248324 :   update_bb_for_insn_chain (head_end_for_bb[bb->index].first,
    4584                 :      124162 :                             head_end_for_bb[bb->index].second, bb);
    4585                 :             : 
    4586                 :      124162 :   if (NEXT_INSN (last))
    4587                 :             :     {
    4588                 :           0 :       bb = create_basic_block (NEXT_INSN (last), get_last_insn (), bb);
    4589                 :             : 
    4590                 :           0 :       last = BB_END (bb);
    4591                 :           0 :       if (BARRIER_P (last))
    4592                 :           0 :         BB_END (bb) = PREV_INSN (last);
    4593                 :             :     }
    4594                 :             : 
    4595                 :      124162 :   maybe_dump_rtl_for_gimple_stmt (stmt, last2);
    4596                 :             : 
    4597                 :      124162 :   return bb;
    4598                 :             : }
    4599                 :             : 
    4600                 :             : /* Return the difference between the floor and the truncated result of
    4601                 :             :    a signed division by OP1 with remainder MOD.  */
    4602                 :             : static rtx
    4603                 :           4 : floor_sdiv_adjust (machine_mode mode, rtx mod, rtx op1)
    4604                 :             : {
    4605                 :             :   /* (mod != 0 ? (op1 / mod < 0 ? -1 : 0) : 0) */
    4606                 :           4 :   return gen_rtx_IF_THEN_ELSE
    4607                 :             :     (mode, gen_rtx_NE (BImode, mod, const0_rtx),
    4608                 :             :      gen_rtx_IF_THEN_ELSE
    4609                 :             :      (mode, gen_rtx_LT (BImode,
    4610                 :             :                         gen_rtx_DIV (mode, op1, mod),
    4611                 :             :                         const0_rtx),
    4612                 :             :       constm1_rtx, const0_rtx),
    4613                 :             :      const0_rtx);
    4614                 :             : }
    4615                 :             : 
    4616                 :             : /* Return the difference between the ceil and the truncated result of
    4617                 :             :    a signed division by OP1 with remainder MOD.  */
    4618                 :             : static rtx
    4619                 :           3 : ceil_sdiv_adjust (machine_mode mode, rtx mod, rtx op1)
    4620                 :             : {
    4621                 :             :   /* (mod != 0 ? (op1 / mod > 0 ? 1 : 0) : 0) */
    4622                 :           3 :   return gen_rtx_IF_THEN_ELSE
    4623                 :             :     (mode, gen_rtx_NE (BImode, mod, const0_rtx),
    4624                 :             :      gen_rtx_IF_THEN_ELSE
    4625                 :             :      (mode, gen_rtx_GT (BImode,
    4626                 :             :                         gen_rtx_DIV (mode, op1, mod),
    4627                 :             :                         const0_rtx),
    4628                 :             :       const1_rtx, const0_rtx),
    4629                 :             :      const0_rtx);
    4630                 :             : }
    4631                 :             : 
    4632                 :             : /* Return the difference between the ceil and the truncated result of
    4633                 :             :    an unsigned division by OP1 with remainder MOD.  */
    4634                 :             : static rtx
    4635                 :           0 : ceil_udiv_adjust (machine_mode mode, rtx mod, rtx op1 ATTRIBUTE_UNUSED)
    4636                 :             : {
    4637                 :             :   /* (mod != 0 ? 1 : 0) */
    4638                 :           0 :   return gen_rtx_IF_THEN_ELSE
    4639                 :             :     (mode, gen_rtx_NE (BImode, mod, const0_rtx),
    4640                 :             :      const1_rtx, const0_rtx);
    4641                 :             : }
    4642                 :             : 
    4643                 :             : /* Return the difference between the rounded and the truncated result
    4644                 :             :    of a signed division by OP1 with remainder MOD.  Halfway cases are
    4645                 :             :    rounded away from zero, rather than to the nearest even number.  */
    4646                 :             : static rtx
    4647                 :           0 : round_sdiv_adjust (machine_mode mode, rtx mod, rtx op1)
    4648                 :             : {
    4649                 :             :   /* (abs (mod) >= abs (op1) - abs (mod)
    4650                 :             :       ? (op1 / mod > 0 ? 1 : -1)
    4651                 :             :       : 0) */
    4652                 :           0 :   return gen_rtx_IF_THEN_ELSE
    4653                 :             :     (mode, gen_rtx_GE (BImode, gen_rtx_ABS (mode, mod),
    4654                 :             :                        gen_rtx_MINUS (mode,
    4655                 :             :                                       gen_rtx_ABS (mode, op1),
    4656                 :             :                                       gen_rtx_ABS (mode, mod))),
    4657                 :             :      gen_rtx_IF_THEN_ELSE
    4658                 :             :      (mode, gen_rtx_GT (BImode,
    4659                 :             :                         gen_rtx_DIV (mode, op1, mod),
    4660                 :             :                         const0_rtx),
    4661                 :             :       const1_rtx, constm1_rtx),
    4662                 :             :      const0_rtx);
    4663                 :             : }
    4664                 :             : 
    4665                 :             : /* Return the difference between the rounded and the truncated result
    4666                 :             :    of a unsigned division by OP1 with remainder MOD.  Halfway cases
    4667                 :             :    are rounded away from zero, rather than to the nearest even
    4668                 :             :    number.  */
    4669                 :             : static rtx
    4670                 :           0 : round_udiv_adjust (machine_mode mode, rtx mod, rtx op1)
    4671                 :             : {
    4672                 :             :   /* (mod >= op1 - mod ? 1 : 0) */
    4673                 :           0 :   return gen_rtx_IF_THEN_ELSE
    4674                 :             :     (mode, gen_rtx_GE (BImode, mod,
    4675                 :             :                        gen_rtx_MINUS (mode, op1, mod)),
    4676                 :             :      const1_rtx, const0_rtx);
    4677                 :             : }
    4678                 :             : 
    4679                 :             : /* Convert X to MODE, that must be Pmode or ptr_mode, without emitting
    4680                 :             :    any rtl.  */
    4681                 :             : 
    4682                 :             : static rtx
    4683                 :     7010039 : convert_debug_memory_address (scalar_int_mode mode, rtx x,
    4684                 :             :                               addr_space_t as)
    4685                 :             : {
    4686                 :             : #ifndef POINTERS_EXTEND_UNSIGNED
    4687                 :             :   gcc_assert (mode == Pmode
    4688                 :             :               || mode == targetm.addr_space.address_mode (as));
    4689                 :             :   gcc_assert (GET_MODE (x) == mode || GET_MODE (x) == VOIDmode);
    4690                 :             : #else
    4691                 :     7010039 :   rtx temp;
    4692                 :             : 
    4693                 :     7010039 :   gcc_assert (targetm.addr_space.valid_pointer_mode (mode, as));
    4694                 :             : 
    4695                 :     7010039 :   if (GET_MODE (x) == mode || GET_MODE (x) == VOIDmode)
    4696                 :             :     return x;
    4697                 :             : 
    4698                 :             :   /* X must have some form of address mode already.  */
    4699                 :           0 :   scalar_int_mode xmode = as_a <scalar_int_mode> (GET_MODE (x));
    4700                 :           0 :   if (GET_MODE_PRECISION (mode) < GET_MODE_PRECISION (xmode))
    4701                 :           0 :     x = lowpart_subreg (mode, x, xmode);
    4702                 :           0 :   else if (POINTERS_EXTEND_UNSIGNED > 0)
    4703                 :           0 :     x = gen_rtx_ZERO_EXTEND (mode, x);
    4704                 :             :   else if (!POINTERS_EXTEND_UNSIGNED)
    4705                 :             :     x = gen_rtx_SIGN_EXTEND (mode, x);
    4706                 :             :   else
    4707                 :             :     {
    4708                 :             :       switch (GET_CODE (x))
    4709                 :             :         {
    4710                 :             :         case SUBREG:
    4711                 :             :           if ((SUBREG_PROMOTED_VAR_P (x)
    4712                 :             :                || (REG_P (SUBREG_REG (x)) && REG_POINTER (SUBREG_REG (x)))
    4713                 :             :                || (GET_CODE (SUBREG_REG (x)) == PLUS
    4714                 :             :                    && REG_P (XEXP (SUBREG_REG (x), 0))
    4715                 :             :                    && REG_POINTER (XEXP (SUBREG_REG (x), 0))
    4716                 :             :                    && CONST_INT_P (XEXP (SUBREG_REG (x), 1))))
    4717                 :             :               && GET_MODE (SUBREG_REG (x)) == mode)
    4718                 :             :             return SUBREG_REG (x);
    4719                 :             :           break;
    4720                 :             :         case LABEL_REF:
    4721                 :             :           temp = gen_rtx_LABEL_REF (mode, label_ref_label (x));
    4722                 :             :           LABEL_REF_NONLOCAL_P (temp) = LABEL_REF_NONLOCAL_P (x);
    4723                 :             :           return temp;
    4724                 :             :         case SYMBOL_REF:
    4725                 :             :           temp = shallow_copy_rtx (x);
    4726                 :             :           PUT_MODE (temp, mode);
    4727                 :             :           return temp;
    4728                 :             :         case CONST:
    4729                 :             :           temp = convert_debug_memory_address (mode, XEXP (x, 0), as);
    4730                 :             :           if (temp)
    4731                 :             :             temp = gen_rtx_CONST (mode, temp);
    4732                 :             :           return temp;
    4733                 :             :         case PLUS:
    4734                 :             :         case MINUS:
    4735                 :             :           if (CONST_INT_P (XEXP (x, 1)))
    4736                 :             :             {
    4737                 :             :               temp = convert_debug_memory_address (mode, XEXP (x, 0), as);
    4738                 :             :               if (temp)
    4739                 :             :                 return gen_rtx_fmt_ee (GET_CODE (x), mode, temp, XEXP (x, 1));
    4740                 :             :             }
    4741                 :             :           break;
    4742                 :             :         default:
    4743                 :             :           break;
    4744                 :             :         }
    4745                 :             :       /* Don't know how to express ptr_extend as operation in debug info.  */
    4746                 :             :       return NULL;
    4747                 :             :     }
    4748                 :             : #endif /* POINTERS_EXTEND_UNSIGNED */
    4749                 :             : 
    4750                 :             :   return x;
    4751                 :             : }
    4752                 :             : 
    4753                 :             : /* Map from SSA_NAMEs to corresponding DEBUG_EXPR_DECLs created
    4754                 :             :    by avoid_deep_ter_for_debug.  */
    4755                 :             : 
    4756                 :             : static hash_map<tree, tree> *deep_ter_debug_map;
    4757                 :             : 
    4758                 :             : /* Split too deep TER chains for debug stmts using debug temporaries.  */
    4759                 :             : 
    4760                 :             : static void
    4761                 :    37248719 : avoid_deep_ter_for_debug (gimple *stmt, int depth)
    4762                 :             : {
    4763                 :    37248719 :   use_operand_p use_p;
    4764                 :    37248719 :   ssa_op_iter iter;
    4765                 :    46337556 :   FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE)
    4766                 :             :     {
    4767                 :     9088837 :       tree use = USE_FROM_PTR (use_p);
    4768                 :     9088837 :       if (TREE_CODE (use) != SSA_NAME || SSA_NAME_IS_DEFAULT_DEF (use))
    4769                 :     7673919 :         continue;
    4770                 :     7812250 :       gimple *g = get_gimple_for_ssa_name (use);
    4771                 :     7812250 :       if (g == NULL)
    4772                 :     6396680 :         continue;
    4773                 :     1415570 :       if ((depth > 6 || !is_gimple_assign (g)) && !stmt_ends_bb_p (g))
    4774                 :             :         {
    4775                 :        3249 :           if (deep_ter_debug_map == NULL)
    4776                 :         656 :             deep_ter_debug_map = new hash_map<tree, tree>;
    4777                 :             : 
    4778                 :        3249 :           tree &vexpr = deep_ter_debug_map->get_or_insert (use);
    4779                 :        3249 :           if (vexpr != NULL)
    4780                 :         652 :             continue;
    4781                 :        2597 :           vexpr = build_debug_expr_decl (TREE_TYPE (use));
    4782                 :        2597 :           gimple *def_temp = gimple_build_debug_bind (vexpr, use, g);
    4783                 :        2597 :           gimple_stmt_iterator gsi = gsi_for_stmt (g);
    4784                 :        2597 :           gsi_insert_after (&gsi, def_temp, GSI_NEW_STMT);
    4785                 :        2597 :           avoid_deep_ter_for_debug (def_temp, 0);
    4786                 :             :         }
    4787                 :             :       else
    4788                 :     1412321 :         avoid_deep_ter_for_debug (g, depth + 1);
    4789                 :             :     }
    4790                 :    37248719 : }
    4791                 :             : 
    4792                 :             : /* Return an RTX equivalent to the value of the parameter DECL.  */
    4793                 :             : 
    4794                 :             : static rtx
    4795                 :      158906 : expand_debug_parm_decl (tree decl)
    4796                 :             : {
    4797                 :      158906 :   rtx incoming = DECL_INCOMING_RTL (decl);
    4798                 :             : 
    4799                 :      158906 :   if (incoming
    4800                 :       18493 :       && GET_MODE (incoming) != BLKmode
    4801                 :      177395 :       && ((REG_P (incoming) && HARD_REGISTER_P (incoming))
    4802                 :        1844 :           || (MEM_P (incoming)
    4803                 :        1758 :               && REG_P (XEXP (incoming, 0))
    4804                 :         766 :               && HARD_REGISTER_P (XEXP (incoming, 0)))))
    4805                 :             :     {
    4806                 :       16673 :       rtx rtl = gen_rtx_ENTRY_VALUE (GET_MODE (incoming));
    4807                 :             : 
    4808                 :             : #ifdef HAVE_window_save
    4809                 :             :       /* DECL_INCOMING_RTL uses the INCOMING_REGNO of parameter registers.
    4810                 :             :          If the target machine has an explicit window save instruction, the
    4811                 :             :          actual entry value is the corresponding OUTGOING_REGNO instead.  */
    4812                 :             :       if (REG_P (incoming)
    4813                 :             :           && OUTGOING_REGNO (REGNO (incoming)) != REGNO (incoming))
    4814                 :             :         incoming
    4815                 :             :           = gen_rtx_REG_offset (incoming, GET_MODE (incoming),
    4816                 :             :                                 OUTGOING_REGNO (REGNO (incoming)), 0);
    4817                 :             :       else if (MEM_P (incoming))
    4818                 :             :         {
    4819                 :             :           rtx reg = XEXP (incoming, 0);
    4820                 :             :           if (OUTGOING_REGNO (REGNO (reg)) != REGNO (reg))
    4821                 :             :             {
    4822                 :             :               reg = gen_raw_REG (GET_MODE (reg), OUTGOING_REGNO (REGNO (reg)));
    4823                 :             :               incoming = replace_equiv_address_nv (incoming, reg);
    4824                 :             :             }
    4825                 :             :           else
    4826                 :             :             incoming = copy_rtx (incoming);
    4827                 :             :         }
    4828                 :             : #endif
    4829                 :             : 
    4830                 :       16673 :       ENTRY_VALUE_EXP (rtl) = incoming;
    4831                 :       16673 :       return rtl;
    4832                 :             :     }
    4833                 :             : 
    4834                 :      142233 :   if (incoming
    4835                 :        1820 :       && GET_MODE (incoming) != BLKmode
    4836                 :        1816 :       && !TREE_ADDRESSABLE (decl)
    4837                 :        1816 :       && MEM_P (incoming)
    4838                 :        1730 :       && (XEXP (incoming, 0) == virtual_incoming_args_rtx
    4839                 :         992 :           || (GET_CODE (XEXP (incoming, 0)) == PLUS
    4840                 :         992 :               && XEXP (XEXP (incoming, 0), 0) == virtual_incoming_args_rtx
    4841                 :         978 :               && CONST_INT_P (XEXP (XEXP (incoming, 0), 1)))))
    4842                 :        1716 :     return copy_rtx (incoming);
    4843                 :             : 
    4844                 :             :   return NULL_RTX;
    4845                 :             : }
    4846                 :             : 
    4847                 :             : /* Return an RTX equivalent to the value of the tree expression EXP.  */
    4848                 :             : 
    4849                 :             : static rtx
    4850                 :    38565170 : expand_debug_expr (tree exp)
    4851                 :             : {
    4852                 :    38565170 :   rtx op0 = NULL_RTX, op1 = NULL_RTX, op2 = NULL_RTX;
    4853                 :    38565170 :   machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
    4854                 :    38565170 :   machine_mode inner_mode = VOIDmode;
    4855                 :    38565170 :   int unsignedp = TYPE_UNSIGNED (TREE_TYPE (exp));
    4856                 :    38565170 :   addr_space_t as;
    4857                 :    38565170 :   scalar_int_mode op0_mode, op1_mode, addr_mode;
    4858                 :             : 
    4859                 :    38565170 :   switch (TREE_CODE_CLASS (TREE_CODE (exp)))
    4860                 :             :     {
    4861                 :     6656956 :     case tcc_expression:
    4862                 :     6656956 :       switch (TREE_CODE (exp))
    4863                 :             :         {
    4864                 :        9341 :         case COND_EXPR:
    4865                 :        9341 :         case DOT_PROD_EXPR:
    4866                 :        9341 :         case SAD_EXPR:
    4867                 :        9341 :         case WIDEN_MULT_PLUS_EXPR:
    4868                 :        9341 :         case WIDEN_MULT_MINUS_EXPR:
    4869                 :        9341 :           goto ternary;
    4870                 :             : 
    4871                 :           0 :         case TRUTH_ANDIF_EXPR:
    4872                 :           0 :         case TRUTH_ORIF_EXPR:
    4873                 :           0 :         case TRUTH_AND_EXPR:
    4874                 :           0 :         case TRUTH_OR_EXPR:
    4875                 :           0 :         case TRUTH_XOR_EXPR:
    4876                 :           0 :           goto binary;
    4877                 :             : 
    4878                 :           0 :         case TRUTH_NOT_EXPR:
    4879                 :           0 :           goto unary;
    4880                 :             : 
    4881                 :             :         default:
    4882                 :             :           break;
    4883                 :             :         }
    4884                 :             :       break;
    4885                 :             : 
    4886                 :        9341 :     ternary:
    4887                 :        9341 :       op2 = expand_debug_expr (TREE_OPERAND (exp, 2));
    4888                 :        9341 :       if (!op2)
    4889                 :             :         return NULL_RTX;
    4890                 :             :       /* Fall through.  */
    4891                 :             : 
    4892                 :        9341 :     binary:
    4893                 :     1199954 :     case tcc_binary:
    4894                 :     1199954 :       if (mode == BLKmode)
    4895                 :             :         return NULL_RTX;
    4896                 :     1199944 :       op1 = expand_debug_expr (TREE_OPERAND (exp, 1));
    4897                 :     1199944 :       if (!op1)
    4898                 :             :         return NULL_RTX;
    4899                 :     1199268 :       switch (TREE_CODE (exp))
    4900                 :             :         {
    4901                 :       61027 :         case LSHIFT_EXPR:
    4902                 :       61027 :         case RSHIFT_EXPR:
    4903                 :       61027 :         case LROTATE_EXPR:
    4904                 :       61027 :         case RROTATE_EXPR:
    4905                 :       61027 :         case WIDEN_LSHIFT_EXPR:
    4906                 :             :           /* Ensure second operand isn't wider than the first one.  */
    4907                 :       61027 :           inner_mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 1)));
    4908                 :       61027 :           if (is_a <scalar_int_mode> (inner_mode, &op1_mode)
    4909                 :       61019 :               && (GET_MODE_UNIT_PRECISION (mode)
    4910                 :       61019 :                   < GET_MODE_PRECISION (op1_mode)))
    4911                 :        5034 :             op1 = lowpart_subreg (GET_MODE_INNER (mode), op1, op1_mode);
    4912                 :             :           break;
    4913                 :             :         default:
    4914                 :             :           break;
    4915                 :             :         }
    4916                 :             :       /* Fall through.  */
    4917                 :             : 
    4918                 :     1773958 :     unary:
    4919                 :     1773958 :     case tcc_unary:
    4920                 :     1773958 :       if (mode == BLKmode)
    4921                 :             :         return NULL_RTX;
    4922                 :     1773956 :       inner_mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
    4923                 :     1773956 :       op0 = expand_debug_expr (TREE_OPERAND (exp, 0));
    4924                 :     1773956 :       if (!op0)
    4925                 :             :         return NULL_RTX;
    4926                 :             :       break;
    4927                 :             : 
    4928                 :       55593 :     case tcc_comparison:
    4929                 :       55593 :       unsignedp = TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0)));
    4930                 :       55593 :       goto binary;
    4931                 :             : 
    4932                 :           0 :     case tcc_type:
    4933                 :           0 :     case tcc_statement:
    4934                 :           0 :       gcc_unreachable ();
    4935                 :             : 
    4936                 :             :     case tcc_constant:
    4937                 :             :     case tcc_exceptional:
    4938                 :             :     case tcc_declaration:
    4939                 :             :     case tcc_reference:
    4940                 :             :     case tcc_vl_exp:
    4941                 :             :       break;
    4942                 :             :     }
    4943                 :             : 
    4944                 :    38563016 :   switch (TREE_CODE (exp))
    4945                 :             :     {
    4946                 :      260908 :     case STRING_CST:
    4947                 :      260908 :       if (!lookup_constant_def (exp))
    4948                 :             :         {
    4949                 :      111847 :           if (strlen (TREE_STRING_POINTER (exp)) + 1
    4950                 :      111847 :               != (size_t) TREE_STRING_LENGTH (exp))
    4951                 :             :             return NULL_RTX;
    4952                 :      111473 :           op0 = gen_rtx_CONST_STRING (Pmode, TREE_STRING_POINTER (exp));
    4953                 :      110914 :           op0 = gen_rtx_MEM (BLKmode, op0);
    4954                 :      110914 :           set_mem_attributes (op0, exp, 0);
    4955                 :      110914 :           return op0;
    4956                 :             :         }
    4957                 :             :       /* Fall through.  */
    4958                 :             : 
    4959                 :     5134879 :     case INTEGER_CST:
    4960                 :     5134879 :       if (TREE_CODE (TREE_TYPE (exp)) == BITINT_TYPE
    4961                 :     5134879 :           && TYPE_MODE (TREE_TYPE (exp)) == BLKmode)
    4962                 :             :         return NULL;
    4963                 :             :       /* FALLTHRU */
    4964                 :     5197086 :     case REAL_CST:
    4965                 :     5197086 :     case FIXED_CST:
    4966                 :     5197086 :       op0 = expand_expr (exp, NULL_RTX, mode, EXPAND_INITIALIZER);
    4967                 :     5197086 :       return op0;
    4968                 :             : 
    4969                 :           0 :     case POLY_INT_CST:
    4970                 :           0 :       return immed_wide_int_const (poly_int_cst_value (exp), mode);
    4971                 :             : 
    4972                 :        4436 :     case COMPLEX_CST:
    4973                 :        4436 :       gcc_assert (COMPLEX_MODE_P (mode));
    4974                 :        4436 :       op0 = expand_debug_expr (TREE_REALPART (exp));
    4975                 :        4436 :       op1 = expand_debug_expr (TREE_IMAGPART (exp));
    4976                 :        4436 :       return gen_rtx_CONCAT (mode, op0, op1);
    4977                 :             : 
    4978                 :     5270373 :     case DEBUG_EXPR_DECL:
    4979                 :     5270373 :       op0 = DECL_RTL_IF_SET (exp);
    4980                 :             : 
    4981                 :     4136824 :       if (op0)
    4982                 :             :         {
    4983                 :     4136824 :           if (GET_MODE (op0) != mode)
    4984                 :           0 :             gcc_assert (VECTOR_TYPE_P (TREE_TYPE (exp)));
    4985                 :             :           else
    4986                 :             :             return op0;
    4987                 :             :         }
    4988                 :             : 
    4989                 :     1133549 :       op0 = gen_rtx_DEBUG_EXPR (mode);
    4990                 :     1133549 :       DEBUG_EXPR_TREE_DECL (op0) = exp;
    4991                 :     1133549 :       SET_DECL_RTL (exp, op0);
    4992                 :             : 
    4993                 :     1133549 :       return op0;
    4994                 :             : 
    4995                 :     5226822 :     case VAR_DECL:
    4996                 :     5226822 :     case PARM_DECL:
    4997                 :     5226822 :     case FUNCTION_DECL:
    4998                 :     5226822 :     case LABEL_DECL:
    4999                 :     5226822 :     case CONST_DECL:
    5000                 :     5226822 :     case RESULT_DECL:
    5001                 :     5226822 :       op0 = DECL_RTL_IF_SET (exp);
    5002                 :             : 
    5003                 :             :       /* This decl was probably optimized away.  */
    5004                 :     3639744 :       if (!op0
    5005                 :             :           /* At least label RTXen are sometimes replaced by
    5006                 :             :              NOTE_INSN_DELETED_LABEL.  Any notes here are not
    5007                 :             :              handled by copy_rtx.  */
    5008                 :     3639744 :           || NOTE_P (op0))
    5009                 :             :         {
    5010                 :     1587079 :           if (!VAR_P (exp)
    5011                 :     1577710 :               || DECL_EXTERNAL (exp)
    5012                 :     1577136 :               || !TREE_STATIC (exp)
    5013                 :      103942 :               || !DECL_NAME (exp)
    5014                 :      103942 :               || DECL_HARD_REGISTER (exp)
    5015                 :      103942 :               || DECL_IN_CONSTANT_POOL (exp)
    5016                 :      103942 :               || mode == VOIDmode
    5017                 :     1691021 :               || symtab_node::get (exp) == NULL)
    5018                 :             :             return NULL;
    5019                 :             : 
    5020                 :       17453 :           op0 = make_decl_rtl_for_debug (exp);
    5021                 :       17453 :           if (!MEM_P (op0)
    5022                 :       17453 :               || GET_CODE (XEXP (op0, 0)) != SYMBOL_REF
    5023                 :       34906 :               || SYMBOL_REF_DECL (XEXP (op0, 0)) != exp)
    5024                 :             :             return NULL;
    5025                 :             :         }
    5026                 :     3639743 :       else if (VAR_P (exp)
    5027                 :     3519147 :                && is_global_var (exp)
    5028                 :     3854244 :                && symtab_node::get (exp) == NULL)
    5029                 :             :         return NULL;
    5030                 :             :       else
    5031                 :     3639743 :         op0 = copy_rtx (op0);
    5032                 :             : 
    5033                 :     3657196 :       if (GET_MODE (op0) == BLKmode
    5034                 :             :           /* If op0 is not BLKmode, but mode is, adjust_mode
    5035                 :             :              below would ICE.  While it is likely a FE bug,
    5036                 :             :              try to be robust here.  See PR43166.  */
    5037                 :      502424 :           || mode == BLKmode
    5038                 :      502424 :           || (mode == VOIDmode && GET_MODE (op0) != VOIDmode))
    5039                 :             :         {
    5040                 :     3154772 :           gcc_assert (MEM_P (op0));
    5041                 :     3154772 :           op0 = adjust_address_nv (op0, mode, 0);
    5042                 :     3154772 :           return op0;
    5043                 :             :         }
    5044                 :             : 
    5045                 :             :       /* Fall through.  */
    5046                 :             : 
    5047                 :      502424 :     adjust_mode:
    5048                 :     9761939 :     case PAREN_EXPR:
    5049                 :     9761939 :     CASE_CONVERT:
    5050                 :     9761939 :       {
    5051                 :     9761939 :         inner_mode = GET_MODE (op0);
    5052                 :             : 
    5053                 :     9761939 :         if (mode == inner_mode)
    5054                 :             :           return op0;
    5055                 :             : 
    5056                 :      151639 :         if (inner_mode == VOIDmode)
    5057                 :             :           {
    5058                 :        5236 :             if (TREE_CODE (exp) == SSA_NAME)
    5059                 :          12 :               inner_mode = TYPE_MODE (TREE_TYPE (exp));
    5060                 :             :             else
    5061                 :        5224 :               inner_mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
    5062                 :        5236 :             if (mode == inner_mode)
    5063                 :             :               return op0;
    5064                 :             :           }
    5065                 :             : 
    5066                 :      149123 :         if (FLOAT_MODE_P (mode) && FLOAT_MODE_P (inner_mode))
    5067                 :             :           {
    5068                 :        6156 :             if (GET_MODE_UNIT_BITSIZE (mode)
    5069                 :       12312 :                 == GET_MODE_UNIT_BITSIZE (inner_mode))
    5070                 :           4 :               op0 = simplify_gen_subreg (mode, op0, inner_mode, 0);
    5071                 :        6152 :             else if (GET_MODE_UNIT_BITSIZE (mode)
    5072                 :       12304 :                      < GET_MODE_UNIT_BITSIZE (inner_mode))
    5073                 :        3517 :               op0 = simplify_gen_unary (FLOAT_TRUNCATE, mode, op0, inner_mode);
    5074                 :             :             else
    5075                 :        2635 :               op0 = simplify_gen_unary (FLOAT_EXTEND, mode, op0, inner_mode);
    5076                 :             :           }
    5077                 :      142967 :         else if (FLOAT_MODE_P (mode))
    5078                 :             :           {
    5079                 :           0 :             gcc_assert (TREE_CODE (exp) != SSA_NAME);
    5080                 :           0 :             if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0))))
    5081                 :           0 :               op0 = simplify_gen_unary (UNSIGNED_FLOAT, mode, op0, inner_mode);
    5082                 :             :             else
    5083                 :           0 :               op0 = simplify_gen_unary (FLOAT, mode, op0, inner_mode);
    5084                 :             :           }
    5085                 :      142967 :         else if (FLOAT_MODE_P (inner_mode))
    5086                 :             :           {
    5087                 :           0 :             if (unsignedp)
    5088                 :           0 :               op0 = simplify_gen_unary (UNSIGNED_FIX, mode, op0, inner_mode);
    5089                 :             :             else
    5090                 :           0 :               op0 = simplify_gen_unary (FIX, mode, op0, inner_mode);
    5091                 :             :           }
    5092                 :      285934 :         else if (GET_MODE_UNIT_PRECISION (mode)
    5093                 :      142967 :                  == GET_MODE_UNIT_PRECISION (inner_mode))
    5094                 :           0 :           op0 = lowpart_subreg (mode, op0, inner_mode);
    5095                 :      285934 :         else if (GET_MODE_UNIT_PRECISION (mode)
    5096                 :      142967 :                  < GET_MODE_UNIT_PRECISION (inner_mode))
    5097                 :       64246 :           op0 = simplify_gen_unary (TRUNCATE, mode, op0, inner_mode);
    5098                 :       78721 :         else if (UNARY_CLASS_P (exp)
    5099                 :       78721 :                  ? TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0)))
    5100                 :           0 :                  : unsignedp)
    5101                 :       54393 :           op0 = simplify_gen_unary (ZERO_EXTEND, mode, op0, inner_mode);
    5102                 :             :         else
    5103                 :       24328 :           op0 = simplify_gen_unary (SIGN_EXTEND, mode, op0, inner_mode);
    5104                 :             : 
    5105                 :             :         return op0;
    5106                 :             :       }
    5107                 :             : 
    5108                 :     2108940 :     case MEM_REF:
    5109                 :     2108940 :       if (!is_gimple_mem_ref_addr (TREE_OPERAND (exp, 0)))
    5110                 :             :         {
    5111                 :      793576 :           tree newexp = fold_binary (MEM_REF, TREE_TYPE (exp),
    5112                 :             :                                      TREE_OPERAND (exp, 0),
    5113                 :             :                                      TREE_OPERAND (exp, 1));
    5114                 :      793576 :           if (newexp)
    5115                 :           0 :             return expand_debug_expr (newexp);
    5116                 :             :         }
    5117                 :             :       /* FALLTHROUGH */
    5118                 :     2108940 :     case INDIRECT_REF:
    5119                 :     2108940 :       inner_mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
    5120                 :     2108940 :       op0 = expand_debug_expr (TREE_OPERAND (exp, 0));
    5121                 :     2108940 :       if (!op0)
    5122                 :             :         return NULL;
    5123                 :             : 
    5124                 :     2105654 :       if (TREE_CODE (exp) == MEM_REF)
    5125                 :             :         {
    5126                 :     2105654 :           if (GET_CODE (op0) == DEBUG_IMPLICIT_PTR
    5127                 :     2062525 :               || (GET_CODE (op0) == PLUS
    5128                 :      311261 :                   && GET_CODE (XEXP (op0, 0)) == DEBUG_IMPLICIT_PTR))
    5129                 :             :             /* (mem (debug_implicit_ptr)) might confuse aliasing.
    5130                 :             :                Instead just use get_inner_reference.  */
    5131                 :       43129 :             goto component_ref;
    5132                 :             : 
    5133                 :     2062525 :           op1 = expand_debug_expr (TREE_OPERAND (exp, 1));
    5134                 :     2062525 :           poly_int64 offset;
    5135                 :     2062525 :           if (!op1 || !poly_int_rtx_p (op1, &offset))
    5136                 :           0 :             return NULL;
    5137                 :             : 
    5138                 :     2062525 :           op0 = plus_constant (inner_mode, op0, offset);
    5139                 :             :         }
    5140                 :             : 
    5141                 :     2062525 :       as = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0))));
    5142                 :             : 
    5143                 :     2062525 :       op0 = convert_debug_memory_address (targetm.addr_space.address_mode (as),
    5144                 :             :                                           op0, as);
    5145                 :     2062525 :       if (op0 == NULL_RTX)
    5146                 :             :         return NULL;
    5147                 :             : 
    5148                 :     2062525 :       op0 = gen_rtx_MEM (mode, op0);
    5149                 :     2062525 :       set_mem_attributes (op0, exp, 0);
    5150                 :     2062525 :       if (TREE_CODE (exp) == MEM_REF
    5151                 :     2062525 :           && !is_gimple_mem_ref_addr (TREE_OPERAND (exp, 0)))
    5152                 :      793576 :         set_mem_expr (op0, NULL_TREE);
    5153                 :     2062525 :       set_mem_addr_space (op0, as);
    5154                 :             : 
    5155                 :     2062525 :       return op0;
    5156                 :             : 
    5157                 :       46126 :     case TARGET_MEM_REF:
    5158                 :       46126 :       if (TREE_CODE (TMR_BASE (exp)) == ADDR_EXPR
    5159                 :       46126 :           && !DECL_RTL_SET_P (TREE_OPERAND (TMR_BASE (exp), 0)))
    5160                 :             :         return NULL;
    5161                 :             : 
    5162                 :       46116 :       op0 = expand_debug_expr
    5163                 :       46116 :             (tree_mem_ref_addr (build_pointer_type (TREE_TYPE (exp)), exp));
    5164                 :       46116 :       if (!op0)
    5165                 :             :         return NULL;
    5166                 :             : 
    5167                 :       46116 :       as = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0))));
    5168                 :       46116 :       op0 = convert_debug_memory_address (targetm.addr_space.address_mode (as),
    5169                 :             :                                           op0, as);
    5170                 :       46116 :       if (op0 == NULL_RTX)
    5171                 :             :         return NULL;
    5172                 :             : 
    5173                 :       46116 :       op0 = gen_rtx_MEM (mode, op0);
    5174                 :             : 
    5175                 :       46116 :       set_mem_attributes (op0, exp, 0);
    5176                 :       46116 :       set_mem_addr_space (op0, as);
    5177                 :             : 
    5178                 :       46116 :       return op0;
    5179                 :             : 
    5180                 :     3488777 :     component_ref:
    5181                 :     3488777 :     case ARRAY_REF:
    5182                 :     3488777 :     case ARRAY_RANGE_REF:
    5183                 :     3488777 :     case COMPONENT_REF:
    5184                 :     3488777 :     case BIT_FIELD_REF:
    5185                 :     3488777 :     case REALPART_EXPR:
    5186                 :     3488777 :     case IMAGPART_EXPR:
    5187                 :     3488777 :     case VIEW_CONVERT_EXPR:
    5188                 :     3488777 :       {
    5189                 :     3488777 :         machine_mode mode1;
    5190                 :     3488777 :         poly_int64 bitsize, bitpos;
    5191                 :     3488777 :         tree offset;
    5192                 :     3488777 :         int reversep, volatilep = 0;
    5193                 :     3488777 :         tree tem
    5194                 :     3488777 :           = get_inner_reference (exp, &bitsize, &bitpos, &offset, &mode1,
    5195                 :             :                                  &unsignedp, &reversep, &volatilep);
    5196                 :     3488777 :         rtx orig_op0;
    5197                 :             : 
    5198                 :     3488777 :         if (known_eq (bitsize, 0))
    5199                 :             :           return NULL;
    5200                 :             : 
    5201                 :     3441307 :         orig_op0 = op0 = expand_debug_expr (tem);
    5202                 :             : 
    5203                 :     3441307 :         if (!op0)
    5204                 :             :           return NULL;
    5205                 :             : 
    5206                 :     3130754 :         if (offset)
    5207                 :             :           {
    5208                 :       13784 :             machine_mode addrmode, offmode;
    5209                 :             : 
    5210                 :       13784 :             if (!MEM_P (op0))
    5211                 :             :               return NULL;
    5212                 :             : 
    5213                 :       13784 :             op0 = XEXP (op0, 0);
    5214                 :       13784 :             addrmode = GET_MODE (op0);
    5215                 :       13784 :             if (addrmode == VOIDmode)
    5216                 :           0 :               addrmode = Pmode;
    5217                 :             : 
    5218                 :       13784 :             op1 = expand_debug_expr (offset);
    5219                 :       13784 :             if (!op1)
    5220                 :             :               return NULL;
    5221                 :             : 
    5222                 :       13782 :             offmode = GET_MODE (op1);
    5223                 :       13782 :             if (offmode == VOIDmode)
    5224                 :           0 :               offmode = TYPE_MODE (TREE_TYPE (offset));
    5225                 :             : 
    5226                 :       13782 :             if (addrmode != offmode)
    5227                 :           0 :               op1 = lowpart_subreg (addrmode, op1, offmode);
    5228                 :             : 
    5229                 :             :             /* Don't use offset_address here, we don't need a
    5230                 :             :                recognizable address, and we don't want to generate
    5231                 :             :                code.  */
    5232                 :       13782 :             op0 = gen_rtx_MEM (mode, simplify_gen_binary (PLUS, addrmode,
    5233                 :             :                                                           op0, op1));
    5234                 :             :           }
    5235                 :             : 
    5236                 :     3130752 :         if (MEM_P (op0))
    5237                 :             :           {
    5238                 :     3003432 :             if (mode1 == VOIDmode)
    5239                 :             :               {
    5240                 :        6304 :                 if (maybe_gt (bitsize, MAX_BITSIZE_MODE_ANY_INT))
    5241                 :      358067 :                   return NULL;
    5242                 :             :                 /* Bitfield.  */
    5243                 :        6304 :                 mode1 = smallest_int_mode_for_size (bitsize).require ();
    5244                 :             :               }
    5245                 :     3003432 :             poly_int64 bytepos = bits_to_bytes_round_down (bitpos);
    5246                 :     3003432 :             if (maybe_ne (bytepos, 0))
    5247                 :             :               {
    5248                 :     1320233 :                 op0 = adjust_address_nv (op0, mode1, bytepos);
    5249                 :     1320233 :                 bitpos = num_trailing_bits (bitpos);
    5250                 :             :               }
    5251                 :     1683199 :             else if (known_eq (bitpos, 0)
    5252                 :     3365599 :                      && known_eq (bitsize, GET_MODE_BITSIZE (mode)))
    5253                 :      477671 :               op0 = adjust_address_nv (op0, mode, 0);
    5254                 :     1205528 :             else if (GET_MODE (op0) != mode1)
    5255                 :        3955 :               op0 = adjust_address_nv (op0, mode1, 0);
    5256                 :             :             else
    5257                 :     1201573 :               op0 = copy_rtx (op0);
    5258                 :     3003432 :             if (op0 == orig_op0)
    5259                 :      132353 :               op0 = shallow_copy_rtx (op0);
    5260                 :     3003432 :             if (TREE_CODE (tem) != SSA_NAME)
    5261                 :     3000303 :               set_mem_attributes (op0, exp, 0);
    5262                 :             :           }
    5263                 :             : 
    5264                 :     3130752 :         if (known_eq (bitpos, 0) && mode == GET_MODE (op0))
    5265                 :             :           return op0;
    5266                 :             : 
    5267                 :      104671 :         if (maybe_lt (bitpos, 0))
    5268                 :             :           return NULL;
    5269                 :             : 
    5270                 :      104669 :         if (GET_MODE (op0) == BLKmode || mode == BLKmode)
    5271                 :             :           return NULL;
    5272                 :             : 
    5273                 :      104658 :         poly_int64 bytepos;
    5274                 :      105328 :         if (multiple_p (bitpos, BITS_PER_UNIT, &bytepos)
    5275                 :      202828 :             && known_eq (bitsize, GET_MODE_BITSIZE (mode1)))
    5276                 :             :           {
    5277                 :      100760 :             machine_mode opmode = GET_MODE (op0);
    5278                 :             : 
    5279                 :      100760 :             if (opmode == VOIDmode)
    5280                 :           0 :               opmode = TYPE_MODE (TREE_TYPE (tem));
    5281                 :             : 
    5282                 :             :             /* This condition may hold if we're expanding the address
    5283                 :             :                right past the end of an array that turned out not to
    5284                 :             :                be addressable (i.e., the address was only computed in
    5285                 :             :                debug stmts).  The gen_subreg below would rightfully
    5286                 :             :                crash, and the address doesn't really exist, so just
    5287                 :             :                drop it.  */
    5288                 :      201520 :             if (known_ge (bitpos, GET_MODE_BITSIZE (opmode)))
    5289                 :             :               return NULL;
    5290                 :             : 
    5291                 :      201462 :             if (multiple_p (bitpos, GET_MODE_BITSIZE (mode)))
    5292                 :      100715 :               return simplify_gen_subreg (mode, op0, opmode, bytepos);
    5293                 :             :           }
    5294                 :             : 
    5295                 :        7828 :         return simplify_gen_ternary (SCALAR_INT_MODE_P (GET_MODE (op0))
    5296                 :        3476 :                                      && TYPE_UNSIGNED (TREE_TYPE (exp))
    5297                 :             :                                      ? SIGN_EXTRACT
    5298                 :             :                                      : ZERO_EXTRACT, mode,
    5299                 :        3914 :                                      GET_MODE (op0) != VOIDmode
    5300                 :             :                                      ? GET_MODE (op0)
    5301                 :           0 :                                      : TYPE_MODE (TREE_TYPE (tem)),
    5302                 :             :                                      op0, gen_int_mode (bitsize, word_mode),
    5303                 :        3914 :                                      gen_int_mode (bitpos, word_mode));
    5304                 :             :       }
    5305                 :             : 
    5306                 :        1807 :     case ABS_EXPR:
    5307                 :        1807 :     case ABSU_EXPR:
    5308                 :        1807 :       return simplify_gen_unary (ABS, mode, op0, mode);
    5309                 :             : 
    5310                 :       13996 :     case NEGATE_EXPR:
    5311                 :       13996 :       return simplify_gen_unary (NEG, mode, op0, mode);
    5312                 :             : 
    5313                 :       18155 :     case BIT_NOT_EXPR:
    5314                 :       18155 :       return simplify_gen_unary (NOT, mode, op0, mode);
    5315                 :             : 
    5316                 :        2312 :     case FLOAT_EXPR:
    5317                 :        2312 :       return simplify_gen_unary (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp,
    5318                 :             :                                                                          0)))
    5319                 :             :                                  ? UNSIGNED_FLOAT : FLOAT, mode, op0,
    5320                 :        2312 :                                  inner_mode);
    5321                 :             : 
    5322                 :         356 :     case FIX_TRUNC_EXPR:
    5323                 :         356 :       return simplify_gen_unary (unsignedp ? UNSIGNED_FIX : FIX, mode, op0,
    5324                 :         356 :                                  inner_mode);
    5325                 :             : 
    5326                 :      191150 :     case POINTER_PLUS_EXPR:
    5327                 :             :       /* For the rare target where pointers are not the same size as
    5328                 :             :          size_t, we need to check for mis-matched modes and correct
    5329                 :             :          the addend.  */
    5330                 :      191150 :       if (op0 && op1
    5331                 :      191150 :           && is_a <scalar_int_mode> (GET_MODE (op0), &op0_mode)
    5332                 :      191049 :           && is_a <scalar_int_mode> (GET_MODE (op1), &op1_mode)
    5333                 :      306051 :           && op0_mode != op1_mode)
    5334                 :             :         {
    5335                 :           0 :           if (GET_MODE_BITSIZE (op0_mode) < GET_MODE_BITSIZE (op1_mode)
    5336                 :             :               /* If OP0 is a partial mode, then we must truncate, even
    5337                 :             :                  if it has the same bitsize as OP1 as GCC's
    5338                 :             :                  representation of partial modes is opaque.  */
    5339                 :           0 :               || (GET_MODE_CLASS (op0_mode) == MODE_PARTIAL_INT
    5340                 :           0 :                   && (GET_MODE_BITSIZE (op0_mode)
    5341                 :           0 :                       == GET_MODE_BITSIZE (op1_mode))))
    5342                 :           0 :             op1 = simplify_gen_unary (TRUNCATE, op0_mode, op1, op1_mode);
    5343                 :             :           else
    5344                 :             :             /* We always sign-extend, regardless of the signedness of
    5345                 :             :                the operand, because the operand is always unsigned
    5346                 :             :                here even if the original C expression is signed.  */
    5347                 :           0 :             op1 = simplify_gen_unary (SIGN_EXTEND, op0_mode, op1, op1_mode);
    5348                 :             :         }
    5349                 :             :       /* Fall through.  */
    5350                 :      580469 :     case PLUS_EXPR:
    5351                 :      580469 :       return simplify_gen_binary (PLUS, mode, op0, op1);
    5352                 :             : 
    5353                 :      117215 :     case MINUS_EXPR:
    5354                 :      117215 :     case POINTER_DIFF_EXPR:
    5355                 :      117215 :       return simplify_gen_binary (MINUS, mode, op0, op1);
    5356                 :             : 
    5357                 :      126177 :     case MULT_EXPR:
    5358                 :      126177 :       return simplify_gen_binary (MULT, mode, op0, op1);
    5359                 :             : 
    5360                 :       73745 :     case RDIV_EXPR:
    5361                 :       73745 :     case TRUNC_DIV_EXPR:
    5362                 :       73745 :     case EXACT_DIV_EXPR:
    5363                 :       73745 :       if (unsignedp)
    5364                 :       11363 :         return simplify_gen_binary (UDIV, mode, op0, op1);
    5365                 :             :       else
    5366                 :       62382 :         return simplify_gen_binary (DIV, mode, op0, op1);
    5367                 :             : 
    5368                 :        5029 :     case TRUNC_MOD_EXPR:
    5369                 :       10058 :       return simplify_gen_binary (unsignedp ? UMOD : MOD, mode, op0, op1);
    5370                 :             : 
    5371                 :           3 :     case FLOOR_DIV_EXPR:
    5372                 :           3 :       if (unsignedp)
    5373                 :           0 :         return simplify_gen_binary (UDIV, mode, op0, op1);
    5374                 :             :       else
    5375                 :             :         {
    5376                 :           3 :           rtx div = simplify_gen_binary (DIV, mode, op0, op1);
    5377                 :           3 :           rtx mod = simplify_gen_binary (MOD, mode, op0, op1);
    5378                 :           3 :           rtx adj = floor_sdiv_adjust (mode, mod, op1);
    5379                 :           3 :           return simplify_gen_binary (PLUS, mode, div, adj);
    5380                 :             :         }
    5381                 :             : 
    5382                 :           1 :     case FLOOR_MOD_EXPR:
    5383                 :           1 :       if (unsignedp)
    5384                 :           0 :         return simplify_gen_binary (UMOD, mode, op0, op1);
    5385                 :             :       else
    5386                 :             :         {
    5387                 :           1 :           rtx mod = simplify_gen_binary (MOD, mode, op0, op1);
    5388                 :           1 :           rtx adj = floor_sdiv_adjust (mode, mod, op1);
    5389                 :           1 :           adj = simplify_gen_unary (NEG, mode,
    5390                 :             :                                     simplify_gen_binary (MULT, mode, adj, op1),
    5391                 :             :                                     mode);
    5392                 :           1 :           return simplify_gen_binary (PLUS, mode, mod, adj);
    5393                 :             :         }
    5394                 :             : 
    5395                 :           3 :     case CEIL_DIV_EXPR:
    5396                 :           3 :       if (unsignedp)
    5397                 :             :         {
    5398                 :           0 :           rtx div = simplify_gen_binary (UDIV, mode, op0, op1);
    5399                 :           0 :           rtx mod = simplify_gen_binary (UMOD, mode, op0, op1);
    5400                 :           0 :           rtx adj = ceil_udiv_adjust (mode, mod, op1);
    5401                 :           0 :           return simplify_gen_binary (PLUS, mode, div, adj);
    5402                 :             :         }
    5403                 :             :       else
    5404                 :             :         {
    5405                 :           3 :           rtx div = simplify_gen_binary (DIV, mode, op0, op1);
    5406                 :           3 :           rtx mod = simplify_gen_binary (MOD, mode, op0, op1);
    5407                 :           3 :           rtx adj = ceil_sdiv_adjust (mode, mod, op1);
    5408                 :           3 :           return simplify_gen_binary (PLUS, mode, div, adj);
    5409                 :             :         }
    5410                 :             : 
    5411                 :           0 :     case CEIL_MOD_EXPR:
    5412                 :           0 :       if (unsignedp)
    5413                 :             :         {
    5414                 :           0 :           rtx mod = simplify_gen_binary (UMOD, mode, op0, op1);
    5415                 :           0 :           rtx adj = ceil_udiv_adjust (mode, mod, op1);
    5416                 :           0 :           adj = simplify_gen_unary (NEG, mode,
    5417                 :             :                                     simplify_gen_binary (MULT, mode, adj, op1),
    5418                 :             :                                     mode);
    5419                 :           0 :           return simplify_gen_binary (PLUS, mode, mod, adj);
    5420                 :             :         }
    5421                 :             :       else
    5422                 :             :         {
    5423                 :           0 :           rtx mod = simplify_gen_binary (MOD, mode, op0, op1);
    5424                 :           0 :           rtx adj = ceil_sdiv_adjust (mode, mod, op1);
    5425                 :           0 :           adj = simplify_gen_unary (NEG, mode,
    5426                 :             :                                     simplify_gen_binary (MULT, mode, adj, op1),
    5427                 :             :                                     mode);
    5428                 :           0 :           return simplify_gen_binary (PLUS, mode, mod, adj);
    5429                 :             :         }
    5430                 :             : 
    5431                 :           0 :     case ROUND_DIV_EXPR:
    5432                 :           0 :       if (unsignedp)
    5433                 :             :         {
    5434                 :           0 :           rtx div = simplify_gen_binary (UDIV, mode, op0, op1);
    5435                 :           0 :           rtx mod = simplify_gen_binary (UMOD, mode, op0, op1);
    5436                 :           0 :           rtx adj = round_udiv_adjust (mode, mod, op1);
    5437                 :           0 :           return simplify_gen_binary (PLUS, mode, div, adj);
    5438                 :             :         }
    5439                 :             :       else
    5440                 :             :         {
    5441                 :           0 :           rtx div = simplify_gen_binary (DIV, mode, op0, op1);
    5442                 :           0 :           rtx mod = simplify_gen_binary (MOD, mode, op0, op1);
    5443                 :           0 :           rtx adj = round_sdiv_adjust (mode, mod, op1);
    5444                 :           0 :           return simplify_gen_binary (PLUS, mode, div, adj);
    5445                 :             :         }
    5446                 :             : 
    5447                 :           0 :     case ROUND_MOD_EXPR:
    5448                 :           0 :       if (unsignedp)
    5449                 :             :         {
    5450                 :           0 :           rtx mod = simplify_gen_binary (UMOD, mode, op0, op1);
    5451                 :           0 :           rtx adj = round_udiv_adjust (mode, mod, op1);
    5452                 :           0 :           adj = simplify_gen_unary (NEG, mode,
    5453                 :             :                                     simplify_gen_binary (MULT, mode, adj, op1),
    5454                 :             :                                     mode);
    5455                 :           0 :           return simplify_gen_binary (PLUS, mode, mod, adj);
    5456                 :             :         }
    5457                 :             :       else
    5458                 :             :         {
    5459                 :           0 :           rtx mod = simplify_gen_binary (MOD, mode, op0, op1);
    5460                 :           0 :           rtx adj = round_sdiv_adjust (mode, mod, op1);
    5461                 :           0 :           adj = simplify_gen_unary (NEG, mode,
    5462                 :             :                                     simplify_gen_binary (MULT, mode, adj, op1),
    5463                 :             :                                     mode);
    5464                 :           0 :           return simplify_gen_binary (PLUS, mode, mod, adj);
    5465                 :             :         }
    5466                 :             : 
    5467                 :       14198 :     case LSHIFT_EXPR:
    5468                 :       14198 :       return simplify_gen_binary (ASHIFT, mode, op0, op1);
    5469                 :             : 
    5470                 :       46087 :     case RSHIFT_EXPR:
    5471                 :       46087 :       if (unsignedp)
    5472                 :       43176 :         return simplify_gen_binary (LSHIFTRT, mode, op0, op1);
    5473                 :             :       else
    5474                 :        2911 :         return simplify_gen_binary (ASHIFTRT, mode, op0, op1);
    5475                 :             : 
    5476                 :           2 :     case LROTATE_EXPR:
    5477                 :           2 :       return simplify_gen_binary (ROTATE, mode, op0, op1);
    5478                 :             : 
    5479                 :         483 :     case RROTATE_EXPR:
    5480                 :         483 :       return simplify_gen_binary (ROTATERT, mode, op0, op1);
    5481                 :             : 
    5482                 :       13893 :     case MIN_EXPR:
    5483                 :       27786 :       return simplify_gen_binary (unsignedp ? UMIN : SMIN, mode, op0, op1);
    5484                 :             : 
    5485                 :       14954 :     case MAX_EXPR:
    5486                 :       29908 :       return simplify_gen_binary (unsignedp ? UMAX : SMAX, mode, op0, op1);
    5487                 :             : 
    5488                 :       78225 :     case BIT_AND_EXPR:
    5489                 :       78225 :     case TRUTH_AND_EXPR:
    5490                 :       78225 :       return simplify_gen_binary (AND, mode, op0, op1);
    5491                 :             : 
    5492                 :       40774 :     case BIT_IOR_EXPR:
    5493                 :       40774 :     case TRUTH_OR_EXPR:
    5494                 :       40774 :       return simplify_gen_binary (IOR, mode, op0, op1);
    5495                 :             : 
    5496                 :        8658 :     case BIT_XOR_EXPR:
    5497                 :        8658 :     case TRUTH_XOR_EXPR:
    5498                 :        8658 :       return simplify_gen_binary (XOR, mode, op0, op1);
    5499                 :             : 
    5500                 :           0 :     case TRUTH_ANDIF_EXPR:
    5501                 :           0 :       return gen_rtx_IF_THEN_ELSE (mode, op0, op1, const0_rtx);
    5502                 :             : 
    5503                 :           0 :     case TRUTH_ORIF_EXPR:
    5504                 :           0 :       return gen_rtx_IF_THEN_ELSE (mode, op0, const_true_rtx, op1);
    5505                 :             : 
    5506                 :           0 :     case TRUTH_NOT_EXPR:
    5507                 :           0 :       return simplify_gen_relational (EQ, mode, inner_mode, op0, const0_rtx);
    5508                 :             : 
    5509                 :        4786 :     case LT_EXPR:
    5510                 :        4786 :       return simplify_gen_relational (unsignedp ? LTU : LT, mode, inner_mode,
    5511                 :        4786 :                                       op0, op1);
    5512                 :             : 
    5513                 :        3720 :     case LE_EXPR:
    5514                 :        3720 :       return simplify_gen_relational (unsignedp ? LEU : LE, mode, inner_mode,
    5515                 :        3720 :                                       op0, op1);
    5516                 :             : 
    5517                 :       10050 :     case GT_EXPR:
    5518                 :       10050 :       return simplify_gen_relational (unsignedp ? GTU : GT, mode, inner_mode,
    5519                 :       10050 :                                       op0, op1);
    5520                 :             : 
    5521                 :        1228 :     case GE_EXPR:
    5522                 :        1228 :       return simplify_gen_relational (unsignedp ? GEU : GE, mode, inner_mode,
    5523                 :        1228 :                                       op0, op1);
    5524                 :             : 
    5525                 :       19721 :     case EQ_EXPR:
    5526                 :       19721 :       return simplify_gen_relational (EQ, mode, inner_mode, op0, op1);
    5527                 :             : 
    5528                 :       16066 :     case NE_EXPR:
    5529                 :       16066 :       return simplify_gen_relational (NE, mode, inner_mode, op0, op1);
    5530                 :             : 
    5531                 :           0 :     case UNORDERED_EXPR:
    5532                 :           0 :       return simplify_gen_relational (UNORDERED, mode, inner_mode, op0, op1);
    5533                 :             : 
    5534                 :           0 :     case ORDERED_EXPR:
    5535                 :           0 :       return simplify_gen_relational (ORDERED, mode, inner_mode, op0, op1);
    5536                 :             : 
    5537                 :           0 :     case UNLT_EXPR:
    5538                 :           0 :       return simplify_gen_relational (UNLT, mode, inner_mode, op0, op1);
    5539                 :             : 
    5540                 :           0 :     case UNLE_EXPR:
    5541                 :           0 :       return simplify_gen_relational (UNLE, mode, inner_mode, op0, op1);
    5542                 :             : 
    5543                 :           0 :     case UNGT_EXPR:
    5544                 :           0 :       return simplify_gen_relational (UNGT, mode, inner_mode, op0, op1);
    5545                 :             : 
    5546                 :           0 :     case UNGE_EXPR:
    5547                 :           0 :       return simplify_gen_relational (UNGE, mode, inner_mode, op0, op1);
    5548                 :             : 
    5549                 :           0 :     case UNEQ_EXPR:
    5550                 :           0 :       return simplify_gen_relational (UNEQ, mode, inner_mode, op0, op1);
    5551                 :             : 
    5552                 :           0 :     case LTGT_EXPR:
    5553                 :           0 :       return simplify_gen_relational (LTGT, mode, inner_mode, op0, op1);
    5554                 :             : 
    5555                 :        9341 :     case COND_EXPR:
    5556                 :        9341 :       return gen_rtx_IF_THEN_ELSE (mode, op0, op1, op2);
    5557                 :             : 
    5558                 :        9040 :     case COMPLEX_EXPR:
    5559                 :        9040 :       gcc_assert (COMPLEX_MODE_P (mode));
    5560                 :        9040 :       if (GET_MODE (op0) == VOIDmode)
    5561                 :           0 :         op0 = gen_rtx_CONST (GET_MODE_INNER (mode), op0);
    5562                 :        9040 :       if (GET_MODE (op1) == VOIDmode)
    5563                 :           0 :         op1 = gen_rtx_CONST (GET_MODE_INNER (mode), op1);
    5564                 :        9040 :       return gen_rtx_CONCAT (mode, op0, op1);
    5565                 :             : 
    5566                 :           0 :     case CONJ_EXPR:
    5567                 :           0 :       if (GET_CODE (op0) == CONCAT)
    5568                 :           0 :         return gen_rtx_CONCAT (mode, XEXP (op0, 0),
    5569                 :             :                                simplify_gen_unary (NEG, GET_MODE_INNER (mode),
    5570                 :             :                                                    XEXP (op0, 1),
    5571                 :             :                                                    GET_MODE_INNER (mode)));
    5572                 :             :       else
    5573                 :             :         {
    5574                 :           0 :           scalar_mode imode = GET_MODE_INNER (mode);
    5575                 :           0 :           rtx re, im;
    5576                 :             : 
    5577                 :           0 :           if (MEM_P (op0))
    5578                 :             :             {
    5579                 :           0 :               re = adjust_address_nv (op0, imode, 0);
    5580                 :           0 :               im = adjust_address_nv (op0, imode, GET_MODE_SIZE (imode));
    5581                 :             :             }
    5582                 :             :           else
    5583                 :             :             {
    5584                 :           0 :               scalar_int_mode ifmode;
    5585                 :           0 :               scalar_int_mode ihmode;
    5586                 :           0 :               rtx halfsize;
    5587                 :           0 :               if (!int_mode_for_mode (mode).exists (&ifmode)
    5588                 :           0 :                   || !int_mode_for_mode (imode).exists (&ihmode))
    5589                 :           0 :                 return NULL;
    5590                 :           0 :               halfsize = GEN_INT (GET_MODE_BITSIZE (ihmode));
    5591                 :           0 :               re = op0;
    5592                 :           0 :               if (mode != ifmode)
    5593                 :           0 :                 re = gen_rtx_SUBREG (ifmode, re, 0);
    5594                 :           0 :               re = gen_rtx_ZERO_EXTRACT (ihmode, re, halfsize, const0_rtx);
    5595                 :           0 :               if (imode != ihmode)
    5596                 :           0 :                 re = gen_rtx_SUBREG (imode, re, 0);
    5597                 :           0 :               im = copy_rtx (op0);
    5598                 :           0 :               if (mode != ifmode)
    5599                 :           0 :                 im = gen_rtx_SUBREG (ifmode, im, 0);
    5600                 :           0 :               im = gen_rtx_ZERO_EXTRACT (ihmode, im, halfsize, halfsize);
    5601                 :           0 :               if (imode != ihmode)
    5602                 :           0 :                 im = gen_rtx_SUBREG (imode, im, 0);
    5603                 :             :             }
    5604                 :           0 :           im = gen_rtx_NEG (imode, im);
    5605                 :           0 :           return gen_rtx_CONCAT (mode, re, im);
    5606                 :             :         }
    5607                 :             : 
    5608                 :     6647276 :     case ADDR_EXPR:
    5609                 :     6647276 :       op0 = expand_debug_expr (TREE_OPERAND (exp, 0));
    5610                 :     6647276 :       if (!op0 || !MEM_P (op0))
    5611                 :             :         {
    5612                 :     1745878 :           if ((TREE_CODE (TREE_OPERAND (exp, 0)) == VAR_DECL
    5613                 :      398020 :                || TREE_CODE (TREE_OPERAND (exp, 0)) == PARM_DECL
    5614                 :      346086 :                || TREE_CODE (TREE_OPERAND (exp, 0)) == RESULT_DECL)
    5615                 :     1797812 :               && (!TREE_ADDRESSABLE (TREE_OPERAND (exp, 0))
    5616                 :      134044 :                   || target_for_debug_bind (TREE_OPERAND (exp, 0))))
    5617                 :     1271667 :             return gen_rtx_DEBUG_IMPLICIT_PTR (mode, TREE_OPERAND (exp, 0));
    5618                 :             : 
    5619                 :      474211 :           if (handled_component_p (TREE_OPERAND (exp, 0)))
    5620                 :             :             {
    5621                 :      327205 :               poly_int64 bitoffset, bitsize, maxsize, byteoffset;
    5622                 :      327205 :               bool reverse;
    5623                 :      327205 :               tree decl
    5624                 :      327205 :                 = get_ref_base_and_extent (TREE_OPERAND (exp, 0), &bitoffset,
    5625                 :             :                                            &bitsize, &maxsize, &reverse);
    5626                 :      327205 :               if ((VAR_P (decl)
    5627                 :             :                    || TREE_CODE (decl) == PARM_DECL
    5628                 :             :                    || TREE_CODE (decl) == RESULT_DECL)
    5629                 :      298420 :                   && (!TREE_ADDRESSABLE (decl)
    5630                 :       22728 :                       || target_for_debug_bind (decl))
    5631                 :       62926 :                   && multiple_p (bitoffset, BITS_PER_UNIT, &byteoffset)
    5632                 :      275692 :                   && known_gt (bitsize, 0)
    5633                 :      264281 :                   && known_eq (bitsize, maxsize))
    5634                 :             :                 {
    5635                 :      264279 :                   rtx base = gen_rtx_DEBUG_IMPLICIT_PTR (mode, decl);
    5636                 :      264279 :                   return plus_constant (mode, base, byteoffset);
    5637                 :             :                 }
    5638                 :             :             }
    5639                 :             : 
    5640                 :      209932 :           if (TREE_CODE (TREE_OPERAND (exp, 0)) == MEM_REF
    5641                 :      209932 :               && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
    5642                 :             :                  == ADDR_EXPR)
    5643                 :             :             {
    5644                 :        8761 :               op0 = expand_debug_expr (TREE_OPERAND (TREE_OPERAND (exp, 0),
    5645                 :             :                                                      0));
    5646                 :        8761 :               if (op0 != NULL
    5647                 :        5655 :                   && (GET_CODE (op0) == DEBUG_IMPLICIT_PTR
    5648                 :           0 :                       || (GET_CODE (op0) == PLUS
    5649                 :           0 :                           && GET_CODE (XEXP (op0, 0)) == DEBUG_IMPLICIT_PTR
    5650                 :           0 :                           && CONST_INT_P (XEXP (op0, 1)))))
    5651                 :             :                 {
    5652                 :        5655 :                   op1 = expand_debug_expr (TREE_OPERAND (TREE_OPERAND (exp, 0),
    5653                 :             :                                                          1));
    5654                 :        5655 :                   poly_int64 offset;
    5655                 :       11310 :                   if (!op1 || !poly_int_rtx_p (op1, &offset))
    5656                 :             :                     return NULL;
    5657                 :             : 
    5658                 :        5655 :                   return plus_constant (mode, op0, offset);
    5659                 :             :                 }
    5660                 :             :             }
    5661                 :             : 
    5662                 :      204277 :           return NULL;
    5663                 :             :         }
    5664                 :             : 
    5665                 :     4901398 :       as = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)));
    5666                 :     4901398 :       addr_mode = SCALAR_INT_TYPE_MODE (TREE_TYPE (exp));
    5667                 :     4901398 :       op0 = convert_debug_memory_address (addr_mode, XEXP (op0, 0), as);
    5668                 :             : 
    5669                 :     4901398 :       return op0;
    5670                 :             : 
    5671                 :         992 :     case VECTOR_CST:
    5672                 :         992 :       {
    5673                 :         992 :         unsigned HOST_WIDE_INT i, nelts;
    5674                 :             : 
    5675                 :         992 :         if (!VECTOR_CST_NELTS (exp).is_constant (&nelts))
    5676                 :             :           return NULL;
    5677                 :             : 
    5678                 :         992 :         op0 = gen_rtx_CONCATN (mode, rtvec_alloc (nelts));
    5679                 :             : 
    5680                 :        5243 :         for (i = 0; i < nelts; ++i)
    5681                 :             :           {
    5682                 :        4251 :             op1 = expand_debug_expr (VECTOR_CST_ELT (exp, i));
    5683                 :        4251 :             if (!op1)
    5684                 :             :               return NULL;
    5685                 :        4251 :             XVECEXP (op0, 0, i) = op1;
    5686                 :             :           }
    5687                 :             : 
    5688                 :             :         return op0;
    5689                 :             :       }
    5690                 :             : 
    5691                 :         281 :     case CONSTRUCTOR:
    5692                 :         281 :       if (TREE_CLOBBER_P (exp))
    5693                 :             :         return NULL;
    5694                 :         281 :       else if (TREE_CODE (TREE_TYPE (exp)) == VECTOR_TYPE)
    5695                 :             :         {
    5696                 :         281 :           unsigned i;
    5697                 :         281 :           unsigned HOST_WIDE_INT nelts;
    5698                 :         281 :           tree val;
    5699                 :             : 
    5700                 :         281 :           if (!TYPE_VECTOR_SUBPARTS (TREE_TYPE (exp)).is_constant (&nelts))
    5701                 :             :             goto flag_unsupported;
    5702                 :             : 
    5703                 :         281 :           op0 = gen_rtx_CONCATN (mode, rtvec_alloc (nelts));
    5704                 :             : 
    5705                 :        1444 :           FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), i, val)
    5706                 :             :             {
    5707                 :        1174 :               op1 = expand_debug_expr (val);
    5708                 :        1174 :               if (!op1)
    5709                 :    38565170 :                 return NULL;
    5710                 :        1163 :               XVECEXP (op0, 0, i) = op1;
    5711                 :             :             }
    5712                 :             : 
    5713                 :         270 :           if (i < nelts)
    5714                 :             :             {
    5715                 :          23 :               op1 = expand_debug_expr
    5716                 :          23 :                 (build_zero_cst (TREE_TYPE (TREE_TYPE (exp))));
    5717                 :             : 
    5718                 :          23 :               if (!op1)
    5719                 :             :                 return NULL;
    5720                 :             : 
    5721                 :         166 :               for (; i < nelts; i++)
    5722                 :         143 :                 XVECEXP (op0, 0, i) = op1;
    5723                 :             :             }
    5724                 :             : 
    5725                 :         270 :           return op0;
    5726                 :             :         }
    5727                 :             :       else
    5728                 :           0 :         goto flag_unsupported;
    5729                 :             : 
    5730                 :             :     case CALL_EXPR:
    5731                 :             :       /* ??? Maybe handle some builtins?  */
    5732                 :             :       return NULL;
    5733                 :             : 
    5734                 :     8730322 :     case SSA_NAME:
    5735                 :     8730322 :       {
    5736                 :     8730322 :         gimple *g = get_gimple_for_ssa_name (exp);
    5737                 :     8730322 :         if (g)
    5738                 :             :           {
    5739                 :     1263300 :             tree t = NULL_TREE;
    5740                 :     1263300 :             if (deep_ter_debug_map)
    5741                 :             :               {
    5742                 :       45548 :                 tree *slot = deep_ter_debug_map->get (exp);
    5743                 :       45548 :                 if (slot)
    5744                 :        6887 :                   t = *slot;
    5745                 :             :               }
    5746                 :        6887 :             if (t == NULL_TREE)
    5747                 :             :               {
    5748                 :     1259010 :                 if (is_gimple_assign (g))
    5749                 :     1258798 :                   t = gimple_assign_rhs_to_tree (g);
    5750                 :             :                 else
    5751                 :             :                   /* expand_debug_expr doesn't handle CALL_EXPR right now.  */
    5752                 :             :                   return NULL;
    5753                 :             :               }
    5754                 :     1263088 :             op0 = expand_debug_expr (t);
    5755                 :     1263088 :             if (!op0)
    5756                 :             :               return NULL;
    5757                 :             :           }
    5758                 :             :         else
    5759                 :             :           {
    5760                 :             :             /* If this is a reference to an incoming value of
    5761                 :             :                parameter that is never used in the code or where the
    5762                 :             :                incoming value is never used in the code, use
    5763                 :             :                PARM_DECL's DECL_RTL if set.  */
    5764                 :     7467022 :             if (SSA_NAME_IS_DEFAULT_DEF (exp)
    5765                 :     1245894 :                 && SSA_NAME_VAR (exp)
    5766                 :     1245894 :                 && TREE_CODE (SSA_NAME_VAR (exp)) == PARM_DECL
    5767                 :     8659754 :                 && has_zero_uses (exp))
    5768                 :             :               {
    5769                 :       17852 :                 op0 = expand_debug_parm_decl (SSA_NAME_VAR (exp));
    5770                 :       17852 :                 if (op0)
    5771                 :       17762 :                   goto adjust_mode;
    5772                 :          90 :                 op0 = expand_debug_expr (SSA_NAME_VAR (exp));
    5773                 :          90 :                 if (op0)
    5774                 :          90 :                   goto adjust_mode;
    5775                 :             :               }
    5776                 :             : 
    5777                 :     7449170 :             int part = var_to_partition (SA.map, exp);
    5778                 :             : 
    5779                 :     7449170 :             if (part == NO_PARTITION)
    5780                 :             :               return NULL;
    5781                 :             : 
    5782                 :     7444416 :             gcc_assert (part >= 0 && (unsigned)part < SA.map->num_partitions);
    5783                 :             : 
    5784                 :     7444416 :             op0 = copy_rtx (SA.partition_to_pseudo[part]);
    5785                 :             :           }
    5786                 :     8704341 :         goto adjust_mode;
    5787                 :             :       }
    5788                 :             : 
    5789                 :             :     case ERROR_MARK:
    5790                 :             :       return NULL;
    5791                 :             : 
    5792                 :             :     /* Vector stuff.  For most of the codes we don't have rtl codes.  */
    5793                 :             :     case REALIGN_LOAD_EXPR:
    5794                 :             :     case VEC_COND_EXPR:
    5795                 :             :     case VEC_PACK_FIX_TRUNC_EXPR:
    5796                 :             :     case VEC_PACK_FLOAT_EXPR:
    5797                 :             :     case VEC_PACK_SAT_EXPR:
    5798                 :             :     case VEC_PACK_TRUNC_EXPR:
    5799                 :             :     case VEC_UNPACK_FIX_TRUNC_HI_EXPR:
    5800                 :             :     case VEC_UNPACK_FIX_TRUNC_LO_EXPR:
    5801                 :             :     case VEC_UNPACK_FLOAT_HI_EXPR:
    5802                 :             :     case VEC_UNPACK_FLOAT_LO_EXPR:
    5803                 :             :     case VEC_UNPACK_HI_EXPR:
    5804                 :             :     case VEC_UNPACK_LO_EXPR:
    5805                 :             :     case VEC_WIDEN_MULT_HI_EXPR:
    5806                 :             :     case VEC_WIDEN_MULT_LO_EXPR:
    5807                 :             :     case VEC_WIDEN_MULT_EVEN_EXPR:
    5808                 :             :     case VEC_WIDEN_MULT_ODD_EXPR:
    5809                 :             :     case VEC_WIDEN_LSHIFT_HI_EXPR:
    5810                 :             :     case VEC_WIDEN_LSHIFT_LO_EXPR:
    5811                 :             :     case VEC_PERM_EXPR:
    5812                 :             :     case VEC_DUPLICATE_EXPR:
    5813                 :             :     case VEC_SERIES_EXPR:
    5814                 :             :     case SAD_EXPR:
    5815                 :             :       return NULL;
    5816                 :             : 
    5817                 :             :     /* Misc codes.  */
    5818                 :             :     case ADDR_SPACE_CONVERT_EXPR:
    5819                 :             :     case FIXED_CONVERT_EXPR:
    5820                 :             :     case OBJ_TYPE_REF:
    5821                 :             :     case WITH_SIZE_EXPR:
    5822                 :             :     case BIT_INSERT_EXPR:
    5823                 :             :       return NULL;
    5824                 :             : 
    5825                 :           0 :     case DOT_PROD_EXPR:
    5826                 :           0 :       if (SCALAR_INT_MODE_P (GET_MODE (op0))
    5827                 :           0 :           && SCALAR_INT_MODE_P (mode))
    5828                 :             :         {
    5829                 :           0 :           op0
    5830                 :           0 :             = simplify_gen_unary (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp,
    5831                 :             :                                                                           0)))
    5832                 :             :                                   ? ZERO_EXTEND : SIGN_EXTEND, mode, op0,
    5833                 :             :                                   inner_mode);
    5834                 :           0 :           op1
    5835                 :           0 :             = simplify_gen_unary (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp,
    5836                 :             :                                                                           1)))
    5837                 :             :                                   ? ZERO_EXTEND : SIGN_EXTEND, mode, op1,
    5838                 :             :                                   inner_mode);
    5839                 :           0 :           op0 = simplify_gen_binary (MULT, mode, op0, op1);
    5840                 :           0 :           return simplify_gen_binary (PLUS, mode, op0, op2);
    5841                 :             :         }
    5842                 :             :       return NULL;
    5843                 :             : 
    5844                 :        4083 :     case WIDEN_MULT_EXPR:
    5845                 :        4083 :     case WIDEN_MULT_PLUS_EXPR:
    5846                 :        4083 :     case WIDEN_MULT_MINUS_EXPR:
    5847                 :        4083 :       if (SCALAR_INT_MODE_P (GET_MODE (op0))
    5848                 :        4083 :           && SCALAR_INT_MODE_P (mode))
    5849                 :             :         {
    5850                 :        4083 :           inner_mode = GET_MODE (op0);
    5851                 :        4083 :           if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0))))
    5852                 :        3464 :             op0 = simplify_gen_unary (ZERO_EXTEND, mode, op0, inner_mode);
    5853                 :             :           else
    5854                 :         619 :             op0 = simplify_gen_unary (SIGN_EXTEND, mode, op0, inner_mode);
    5855                 :        4083 :           if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 1))))
    5856                 :        3464 :             op1 = simplify_gen_unary (ZERO_EXTEND, mode, op1, inner_mode);
    5857                 :             :           else
    5858                 :         619 :             op1 = simplify_gen_unary (SIGN_EXTEND, mode, op1, inner_mode);
    5859                 :        4083 :           op0 = simplify_gen_binary (MULT, mode, op0, op1);
    5860                 :        4083 :           if (TREE_CODE (exp) == WIDEN_MULT_EXPR)
    5861                 :             :             return op0;
    5862                 :           0 :           else if (TREE_CODE (exp) == WIDEN_MULT_PLUS_EXPR)
    5863                 :           0 :             return simplify_gen_binary (PLUS, mode, op0, op2);
    5864                 :             :           else
    5865                 :           0 :             return simplify_gen_binary (MINUS, mode, op2, op0);
    5866                 :             :         }
    5867                 :             :       return NULL;
    5868                 :             : 
    5869                 :             :     case MULT_HIGHPART_EXPR:
    5870                 :             :       /* ??? Similar to the above.  */
    5871                 :             :       return NULL;
    5872                 :             : 
    5873                 :           0 :     case WIDEN_SUM_EXPR:
    5874                 :           0 :     case WIDEN_LSHIFT_EXPR:
    5875                 :           0 :       if (SCALAR_INT_MODE_P (GET_MODE (op0))
    5876                 :           0 :           && SCALAR_INT_MODE_P (mode))
    5877                 :             :         {
    5878                 :           0 :           op0
    5879                 :           0 :             = simplify_gen_unary (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp,
    5880                 :             :                                                                           0)))
    5881                 :             :                                   ? ZERO_EXTEND : SIGN_EXTEND, mode, op0,
    5882                 :             :                                   inner_mode);
    5883                 :           0 :           return simplify_gen_binary (TREE_CODE (exp) == WIDEN_LSHIFT_EXPR
    5884                 :           0 :                                       ? ASHIFT : PLUS, mode, op0, op1);
    5885                 :             :         }
    5886                 :             :       return NULL;
    5887                 :             : 
    5888                 :           0 :     default:
    5889                 :           0 :     flag_unsupported:
    5890                 :           0 :       if (flag_checking)
    5891                 :             :         {
    5892                 :           0 :           debug_tree (exp);
    5893                 :           0 :           gcc_unreachable ();
    5894                 :             :         }
    5895                 :             :       return NULL;
    5896                 :             :     }
    5897                 :             : }
    5898                 :             : 
    5899                 :             : /* Return an RTX equivalent to the source bind value of the tree expression
    5900                 :             :    EXP.  */
    5901                 :             : 
    5902                 :             : static rtx
    5903                 :      141571 : expand_debug_source_expr (tree exp)
    5904                 :             : {
    5905                 :      266884 :   rtx op0 = NULL_RTX;
    5906                 :      266884 :   machine_mode mode = VOIDmode, inner_mode;
    5907                 :             : 
    5908                 :      266884 :   switch (TREE_CODE (exp))
    5909                 :             :     {
    5910                 :      125313 :     case VAR_DECL:
    5911                 :      125313 :       if (DECL_ABSTRACT_ORIGIN (exp))
    5912                 :      125313 :         return expand_debug_source_expr (DECL_ABSTRACT_ORIGIN (exp));
    5913                 :             :       break;
    5914                 :      141054 :     case PARM_DECL:
    5915                 :      141054 :       {
    5916                 :      141054 :         mode = DECL_MODE (exp);
    5917                 :      141054 :         op0 = expand_debug_parm_decl (exp);
    5918                 :      141054 :         if (op0)
    5919                 :             :            break;
    5920                 :             :         /* See if this isn't an argument that has been completely
    5921                 :             :            optimized out.  */
    5922                 :      140427 :         if (!DECL_RTL_SET_P (exp)
    5923                 :      140413 :             && !DECL_INCOMING_RTL (exp)
    5924                 :      280840 :             && DECL_ABSTRACT_ORIGIN (current_function_decl))
    5925                 :             :           {
    5926                 :       41708 :             tree aexp = DECL_ORIGIN (exp);
    5927                 :       41708 :             if (DECL_CONTEXT (aexp)
    5928                 :       41708 :                 == DECL_ABSTRACT_ORIGIN (current_function_decl))
    5929                 :             :               {
    5930                 :       18614 :                 vec<tree, va_gc> **debug_args;
    5931                 :       18614 :                 unsigned int ix;
    5932                 :       18614 :                 tree ddecl;
    5933                 :       18614 :                 debug_args = decl_debug_args_lookup (current_function_decl);
    5934                 :       18614 :                 if (debug_args != NULL)
    5935                 :             :                   {
    5936                 :       23096 :                     for (ix = 0; vec_safe_iterate (*debug_args, ix, &ddecl);
    5937                 :        4486 :                          ix += 2)
    5938                 :       23080 :                       if (ddecl == aexp)
    5939                 :       18594 :                         return gen_rtx_DEBUG_PARAMETER_REF (mode, aexp);
    5940                 :             :                   }
    5941                 :             :               }
    5942                 :             :           }
    5943                 :             :         break;
    5944                 :             :       }
    5945                 :             :     default:
    5946                 :             :       break;
    5947                 :             :     }
    5948                 :             : 
    5949                 :         627 :   if (op0 == NULL_RTX)
    5950                 :      122350 :     return NULL_RTX;
    5951                 :             : 
    5952                 :         627 :   inner_mode = GET_MODE (op0);
    5953                 :         627 :   if (mode == inner_mode)
    5954                 :             :     return op0;
    5955                 :             : 
    5956                 :          21 :   if (FLOAT_MODE_P (mode) && FLOAT_MODE_P (inner_mode))
    5957                 :             :     {
    5958                 :           7 :       if (GET_MODE_UNIT_BITSIZE (mode)
    5959                 :          14 :           == GET_MODE_UNIT_BITSIZE (inner_mode))
    5960                 :           0 :         op0 = simplify_gen_subreg (mode, op0, inner_mode, 0);
    5961                 :           7 :       else if (GET_MODE_UNIT_BITSIZE (mode)
    5962                 :          14 :                < GET_MODE_UNIT_BITSIZE (inner_mode))
    5963                 :           7 :         op0 = simplify_gen_unary (FLOAT_TRUNCATE, mode, op0, inner_mode);
    5964                 :             :       else
    5965                 :           0 :         op0 = simplify_gen_unary (FLOAT_EXTEND, mode, op0, inner_mode);
    5966                 :             :     }
    5967                 :          14 :   else if (FLOAT_MODE_P (mode))
    5968                 :           0 :     gcc_unreachable ();
    5969                 :          14 :   else if (FLOAT_MODE_P (inner_mode))
    5970                 :             :     {
    5971                 :           0 :       if (TYPE_UNSIGNED (TREE_TYPE (exp)))
    5972                 :           0 :         op0 = simplify_gen_unary (UNSIGNED_FIX, mode, op0, inner_mode);
    5973                 :             :       else
    5974                 :           0 :         op0 = simplify_gen_unary (FIX, mode, op0, inner_mode);
    5975                 :             :     }
    5976                 :          28 :   else if (GET_MODE_UNIT_PRECISION (mode)
    5977                 :          14 :            == GET_MODE_UNIT_PRECISION (inner_mode))
    5978                 :           0 :     op0 = lowpart_subreg (mode, op0, inner_mode);
    5979                 :          28 :   else if (GET_MODE_UNIT_PRECISION (mode)
    5980                 :          14 :            < GET_MODE_UNIT_PRECISION (inner_mode))
    5981                 :          14 :     op0 = simplify_gen_unary (TRUNCATE, mode, op0, inner_mode);
    5982                 :           0 :   else if (TYPE_UNSIGNED (TREE_TYPE (exp)))
    5983                 :           0 :     op0 = simplify_gen_unary (ZERO_EXTEND, mode, op0, inner_mode);
    5984                 :             :   else
    5985                 :           0 :     op0 = simplify_gen_unary (SIGN_EXTEND, mode, op0, inner_mode);
    5986                 :             : 
    5987                 :             :   return op0;
    5988                 :             : }
    5989                 :             : 
    5990                 :             : /* Ensure INSN_VAR_LOCATION_LOC (insn) doesn't have unbound complexity.
    5991                 :             :    Allow 4 levels of rtl nesting for most rtl codes, and if we see anything
    5992                 :             :    deeper than that, create DEBUG_EXPRs and emit DEBUG_INSNs before INSN.  */
    5993                 :             : 
    5994                 :             : static void
    5995                 :    46926645 : avoid_complex_debug_insns (rtx_insn *insn, rtx *exp_p, int depth)
    5996                 :             : {
    5997                 :    46926645 :   rtx exp = *exp_p;
    5998                 :             : 
    5999                 :    46926645 :   if (exp == NULL_RTX)
    6000                 :             :     return;
    6001                 :             : 
    6002                 :    46926645 :   if ((OBJECT_P (exp) && !MEM_P (exp)) || GET_CODE (exp) == CLOBBER)
    6003                 :             :     return;
    6004                 :             : 
    6005                 :     6271969 :   if (depth == 4)
    6006                 :             :     {
    6007                 :             :       /* Create DEBUG_EXPR (and DEBUG_EXPR_DECL).  */
    6008                 :       21503 :       rtx dval = make_debug_expr_from_rtl (exp);
    6009                 :             : 
    6010                 :             :       /* Emit a debug bind insn before INSN.  */
    6011                 :       21503 :       rtx bind = gen_rtx_VAR_LOCATION (GET_MODE (exp),
    6012                 :             :                                        DEBUG_EXPR_TREE_DECL (dval), exp,
    6013                 :             :                                        VAR_INIT_STATUS_INITIALIZED);
    6014                 :             : 
    6015                 :       21503 :       emit_debug_insn_before (bind, insn);
    6016                 :       21503 :       *exp_p = dval;
    6017                 :       21503 :       return;
    6018                 :             :     }
    6019                 :             : 
    6020                 :     6250466 :   const char *format_ptr = GET_RTX_FORMAT (GET_CODE (exp));
    6021                 :     6250466 :   int i, j;
    6022                 :    18643731 :   for (i = 0; i < GET_RTX_LENGTH (GET_CODE (exp)); i++)
    6023                 :    12393265 :     switch (*format_ptr++)
    6024                 :             :       {
    6025                 :    11376265 :       case 'e':
    6026                 :    11376265 :         avoid_complex_debug_insns (insn, &XEXP (exp, i), depth + 1);
    6027                 :    11376265 :         break;
    6028                 :             : 
    6029                 :             :       case 'E':
    6030                 :             :       case 'V':
    6031                 :           0 :         for (j = 0; j < XVECLEN (exp, i); j++)
    6032                 :           0 :           avoid_complex_debug_insns (insn, &XVECEXP (exp, i, j), depth + 1);
    6033                 :             :         break;
    6034                 :             : 
    6035                 :             :       default:
    6036                 :             :         break;
    6037                 :             :       }
    6038                 :             : }
    6039                 :             : 
    6040                 :             : /* Expand the _LOCs in debug insns.  We run this after expanding all
    6041                 :             :    regular insns, so that any variables referenced in the function
    6042                 :             :    will have their DECL_RTLs set.  */
    6043                 :             : 
    6044                 :             : static void
    6045                 :      495850 : expand_debug_locations (void)
    6046                 :             : {
    6047                 :      495850 :   rtx_insn *insn;
    6048                 :      495850 :   rtx_insn *last = get_last_insn ();
    6049                 :      495850 :   int save_strict_alias = flag_strict_aliasing;
    6050                 :             : 
    6051                 :             :   /* New alias sets while setting up memory attributes cause
    6052                 :             :      -fcompare-debug failures, even though it doesn't bring about any
    6053                 :             :      codegen changes.  */
    6054                 :      495850 :   flag_strict_aliasing = 0;
    6055                 :             : 
    6056                 :   101936022 :   for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
    6057                 :   101440172 :     if (DEBUG_BIND_INSN_P (insn))
    6058                 :             :       {
    6059                 :    35528877 :         tree value = (tree)INSN_VAR_LOCATION_LOC (insn);
    6060                 :    35528877 :         rtx val;
    6061                 :    35528877 :         rtx_insn *prev_insn, *insn2;
    6062                 :    35528877 :         machine_mode mode;
    6063                 :             : 
    6064                 :    35528877 :         if (value == NULL_TREE)
    6065                 :             :           val = NULL_RTX;
    6066                 :             :         else
    6067                 :             :           {
    6068                 :    20035167 :             if (INSN_VAR_LOCATION_STATUS (insn)
    6069                 :             :                 == VAR_INIT_STATUS_UNINITIALIZED)
    6070                 :      141571 :               val = expand_debug_source_expr (value);
    6071                 :             :             /* The avoid_deep_ter_for_debug function inserts
    6072                 :             :                debug bind stmts after SSA_NAME definition, with the
    6073                 :             :                SSA_NAME as the whole bind location.  Disable temporarily
    6074                 :             :                expansion of that SSA_NAME into the DEBUG_EXPR_DECL
    6075                 :             :                being defined in this DEBUG_INSN.  */
    6076                 :    19893596 :             else if (deep_ter_debug_map && TREE_CODE (value) == SSA_NAME)
    6077                 :             :               {
    6078                 :       55659 :                 tree *slot = deep_ter_debug_map->get (value);
    6079                 :       55659 :                 if (slot)
    6080                 :             :                   {
    6081                 :        2910 :                     if (*slot == INSN_VAR_LOCATION_DECL (insn))
    6082                 :        2597 :                       *slot = NULL_TREE;
    6083                 :             :                     else
    6084                 :             :                       slot = NULL;
    6085                 :             :                   }
    6086                 :       55659 :                 val = expand_debug_expr (value);
    6087                 :       55659 :                 if (slot)
    6088                 :        2597 :                   *slot = INSN_VAR_LOCATION_DECL (insn);
    6089                 :             :               }
    6090                 :             :             else
    6091                 :    19837937 :               val = expand_debug_expr (value);
    6092                 :    20035167 :             gcc_assert (last == get_last_insn ());
    6093                 :             :           }
    6094                 :             : 
    6095                 :    20035167 :         if (!val)
    6096                 :    15864044 :           val = gen_rtx_UNKNOWN_VAR_LOC ();
    6097                 :             :         else
    6098                 :             :           {
    6099                 :    19664833 :             mode = GET_MODE (INSN_VAR_LOCATION (insn));
    6100                 :             : 
    6101                 :    19664833 :             gcc_assert (mode == GET_MODE (val)
    6102                 :             :                         || (GET_MODE (val) == VOIDmode
    6103                 :             :                             && (CONST_SCALAR_INT_P (val)
    6104                 :             :                                 || GET_CODE (val) == CONST_FIXED
    6105                 :             :                                 || GET_CODE (val) == LABEL_REF)));
    6106                 :             :           }
    6107                 :             : 
    6108                 :    35528877 :         INSN_VAR_LOCATION_LOC (insn) = val;
    6109                 :    35528877 :         prev_insn = PREV_INSN (insn);
    6110                 :    71079257 :         for (insn2 = insn; insn2 != prev_insn; insn2 = PREV_INSN (insn2))
    6111                 :    35550380 :           avoid_complex_debug_insns (insn2, &INSN_VAR_LOCATION_LOC (insn2), 0);
    6112                 :             :       }
    6113                 :             : 
    6114                 :      495850 :   flag_strict_aliasing = save_strict_alias;
    6115                 :      495850 : }
    6116                 :             : 
    6117                 :             : /* Performs swapping operands of commutative operations to expand
    6118                 :             :    the expensive one first.  */
    6119                 :             : 
    6120                 :             : static void
    6121                 :     9216402 : reorder_operands (basic_block bb)
    6122                 :             : {
    6123                 :     9216402 :   unsigned int *lattice;  /* Hold cost of each statement.  */
    6124                 :     9216402 :   unsigned int i = 0, n = 0;
    6125                 :     9216402 :   gimple_stmt_iterator gsi;
    6126                 :     9216402 :   gimple_seq stmts;
    6127                 :     9216402 :   gimple *stmt;
    6128                 :     9216402 :   bool swap;
    6129                 :     9216402 :   tree op0, op1;
    6130                 :     9216402 :   ssa_op_iter iter;
    6131                 :     9216402 :   use_operand_p use_p;
    6132                 :     9216402 :   gimple *def0, *def1;
    6133                 :             : 
    6134                 :             :   /* Compute cost of each statement using estimate_num_insns.  */
    6135                 :     9216402 :   stmts = bb_seq (bb);
    6136                 :    90105585 :   for (gsi = gsi_start (stmts); !gsi_end_p (gsi); gsi_next (&gsi))
    6137                 :             :     {
    6138                 :    80889183 :       stmt = gsi_stmt (gsi);
    6139                 :    80889183 :       if (!is_gimple_debug (stmt))
    6140                 :    33698742 :         gimple_set_uid (stmt, n++);
    6141                 :             :     }
    6142                 :     9216402 :   lattice = XNEWVEC (unsigned int, n);
    6143                 :    90105585 :   for (gsi = gsi_start (stmts); !gsi_end_p (gsi); gsi_next (&gsi))
    6144                 :             :     {
    6145                 :    80889183 :       unsigned cost;
    6146                 :    80889183 :       stmt = gsi_stmt (gsi);
    6147                 :    80889183 :       if (is_gimple_debug (stmt))
    6148                 :    47190441 :         continue;
    6149                 :    33698742 :       cost = estimate_num_insns (stmt, &eni_size_weights);
    6150                 :    33698742 :       lattice[i] = cost;
    6151                 :    63760519 :       FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE)
    6152                 :             :         {
    6153                 :    30061777 :           tree use = USE_FROM_PTR (use_p);
    6154                 :    30061777 :           gimple *def_stmt;
    6155                 :    30061777 :           if (TREE_CODE (use) != SSA_NAME)
    6156                 :           0 :             continue;
    6157                 :    30061777 :           def_stmt = get_gimple_for_ssa_name (use);
    6158                 :    30061777 :           if (!def_stmt)
    6159                 :    21344896 :             continue;
    6160                 :     8716881 :           lattice[i] += lattice[gimple_uid (def_stmt)];
    6161                 :             :         }
    6162                 :    33698742 :       i++;
    6163                 :    33698742 :       if (!is_gimple_assign (stmt)
    6164                 :    33698742 :           || !commutative_tree_code (gimple_assign_rhs_code (stmt)))
    6165                 :    29654904 :         continue;
    6166                 :     4043838 :       op0 = gimple_op (stmt, 1);
    6167                 :     4043838 :       op1 = gimple_op (stmt, 2);
    6168                 :     4043838 :       if (TREE_CODE (op0) != SSA_NAME
    6169                 :     4043623 :           || TREE_CODE (op1) != SSA_NAME)
    6170                 :     2578681 :         continue;
    6171                 :             :       /* Swap operands if the second one is more expensive.  */
    6172                 :     1465157 :       def0 = get_gimple_for_ssa_name (op0);
    6173                 :     1465157 :       def1 = get_gimple_for_ssa_name (op1);
    6174                 :     1465157 :       if (!def1)
    6175                 :      806243 :         continue;
    6176                 :      658914 :       swap = false;
    6177                 :      658914 :       if (!def0 || lattice[gimple_uid (def1)] > lattice[gimple_uid (def0)])
    6178                 :      313207 :         swap = true;
    6179                 :      313207 :       if (swap)
    6180                 :             :         {
    6181                 :      313207 :           if (dump_file && (dump_flags & TDF_DETAILS))
    6182                 :             :             {
    6183                 :           2 :               fprintf (dump_file, "Swap operands in stmt:\n");
    6184                 :           2 :               print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
    6185                 :           2 :               fprintf (dump_file, "Cost left opnd=%d, right opnd=%d\n",
    6186                 :           1 :                        def0 ? lattice[gimple_uid (def0)] : 0,
    6187                 :           2 :                        lattice[gimple_uid (def1)]);
    6188                 :             :             }
    6189                 :      313207 :           swap_ssa_operands (stmt, gimple_assign_rhs1_ptr (stmt),
    6190                 :             :                              gimple_assign_rhs2_ptr (stmt));
    6191                 :             :         }
    6192                 :             :     }
    6193                 :     9216402 :   XDELETE (lattice);
    6194                 :     9216402 : }
    6195                 :             : 
    6196                 :             : /* Expand basic block BB from GIMPLE trees to RTL.  */
    6197                 :             : 
    6198                 :             : static basic_block
    6199                 :    12518571 : expand_gimple_basic_block (basic_block bb, rtx_insn *asan_epilog_seq)
    6200                 :             : {
    6201                 :    12518571 :   gimple_stmt_iterator gsi;
    6202                 :    12518571 :   gimple *stmt = NULL;
    6203                 :    12518571 :   rtx_note *note = NULL;
    6204                 :    12518571 :   rtx_insn *last;
    6205                 :    12518571 :   edge e;
    6206                 :    12518571 :   edge_iterator ei;
    6207                 :    12518571 :   bool nondebug_stmt_seen = false;
    6208                 :             : 
    6209                 :    12518571 :   if (dump_file)
    6210                 :         770 :     fprintf (dump_file, "\n;; Generating RTL for gimple basic block %d\n",
    6211                 :             :              bb->index);
    6212                 :             : 
    6213                 :             :   /* Note that since we are now transitioning from GIMPLE to RTL, we
    6214                 :             :      cannot use the gsi_*_bb() routines because they expect the basic
    6215                 :             :      block to be in GIMPLE, instead of RTL.  Therefore, we need to
    6216                 :             :      access the BB sequence directly.  */
    6217                 :    12518571 :   if (optimize)
    6218                 :     9216402 :     reorder_operands (bb);
    6219                 :    12518571 :   rtl_profile_for_bb (bb);
    6220                 :             : 
    6221                 :             :   /* Remove the RETURN_EXPR if we may fall though to the exit
    6222                 :             :      instead.  */
    6223                 :    12518571 :   gsi = gsi_last_bb (bb);
    6224                 :    12518571 :   if (!gsi_end_p (gsi) && gimple_code (gsi_stmt (gsi)) == GIMPLE_RETURN)
    6225                 :             :     {
    6226                 :     1424173 :       greturn *ret_stmt = as_a <greturn *> (gsi_stmt (gsi));
    6227                 :             : 
    6228                 :     1424173 :       gcc_assert (single_succ_p (bb));
    6229                 :     1424173 :       gcc_assert (single_succ (bb) == EXIT_BLOCK_PTR_FOR_FN (cfun));
    6230                 :             : 
    6231                 :     1424173 :       if (bb->next_bb == EXIT_BLOCK_PTR_FOR_FN (cfun)
    6232                 :     1424173 :           && !gimple_return_retval (ret_stmt))
    6233                 :             :         {
    6234                 :      592458 :           gsi_remove (&gsi, false);
    6235                 :      592458 :           single_succ_edge (bb)->flags |= EDGE_FALLTHRU;
    6236                 :             :         }
    6237                 :             :     }
    6238                 :             : 
    6239                 :    12518571 :   gsi = gsi_start_bb (bb);
    6240                 :    12518571 :   if (!gsi_end_p (gsi))
    6241                 :             :     {
    6242                 :    11976171 :       stmt = gsi_stmt (gsi);
    6243                 :    11976171 :       if (gimple_code (stmt) != GIMPLE_LABEL)
    6244                 :    11905510 :         stmt = NULL;
    6245                 :             :     }
    6246                 :             : 
    6247                 :    12518571 :   rtx_code_label **elt = lab_rtx_for_bb->get (bb);
    6248                 :    12518571 :   if ((unsigned) bb->index >= head_end_for_bb.length ())
    6249                 :    12387168 :     head_end_for_bb.safe_grow_cleared (bb->index + 1);
    6250                 :             : 
    6251                 :    12518571 :   if (stmt || elt)
    6252                 :             :     {
    6253                 :     5206525 :       gcc_checking_assert (!note);
    6254                 :     5206525 :       last = get_last_insn ();
    6255                 :             : 
    6256                 :     5206525 :       if (stmt)
    6257                 :             :         {
    6258                 :      613061 :           expand_gimple_stmt (stmt);
    6259                 :      613061 :           gsi_next (&gsi);
    6260                 :             :         }
    6261                 :             : 
    6262                 :     5206525 :       if (elt)
    6263                 :     4593464 :         emit_label (*elt);
    6264                 :             : 
    6265                 :     5206525 :       head_end_for_bb[bb->index].first = NEXT_INSN (last);
    6266                 :     5206525 :       if (NOTE_P (head_end_for_bb[bb->index].first))
    6267                 :           0 :         head_end_for_bb[bb->index].first
    6268                 :           0 :           = NEXT_INSN (head_end_for_bb[bb->index].first);
    6269                 :     5206525 :       gcc_assert (LABEL_P (head_end_for_bb[bb->index].first));
    6270                 :    10413050 :       note = emit_note_after (NOTE_INSN_BASIC_BLOCK,
    6271                 :     5206525 :                               head_end_for_bb[bb->index].first);
    6272                 :             : 
    6273                 :     5206525 :       maybe_dump_rtl_for_gimple_stmt (stmt, last);
    6274                 :             :     }
    6275                 :             :   else
    6276                 :     7312046 :     head_end_for_bb[bb->index].first = note = emit_note (NOTE_INSN_BASIC_BLOCK);
    6277                 :             : 
    6278                 :    12518571 :   if (note)
    6279                 :    12518571 :     NOTE_BASIC_BLOCK (note) = bb;
    6280                 :             : 
    6281                 :    65228226 :   for (; !gsi_end_p (gsi); gsi_next (&gsi))
    6282                 :             :     {
    6283                 :    53321906 :       basic_block new_bb;
    6284                 :             : 
    6285                 :    53321906 :       stmt = gsi_stmt (gsi);
    6286                 :    53321906 :       if (!is_gimple_debug (stmt))
    6287                 :    45024640 :         nondebug_stmt_seen = true;
    6288                 :             : 
    6289                 :             :       /* If this statement is a non-debug one, and we generate debug
    6290                 :             :          insns, then this one might be the last real use of a TERed
    6291                 :             :          SSA_NAME, but where there are still some debug uses further
    6292                 :             :          down.  Expanding the current SSA name in such further debug
    6293                 :             :          uses by their RHS might lead to wrong debug info, as coalescing
    6294                 :             :          might make the operands of such RHS be placed into the same
    6295                 :             :          pseudo as something else.  Like so:
    6296                 :             :            a_1 = a_0 + 1;   // Assume a_1 is TERed and a_0 is dead
    6297                 :             :            use(a_1);
    6298                 :             :            a_2 = ...
    6299                 :             :            #DEBUG ... => a_1
    6300                 :             :          As a_0 and a_2 don't overlap in lifetime, assume they are coalesced.
    6301                 :             :          If we now would expand a_1 by it's RHS (a_0 + 1) in the debug use,
    6302                 :             :          the write to a_2 would actually have clobbered the place which
    6303                 :             :          formerly held a_0.
    6304                 :             : 
    6305                 :             :          So, instead of that, we recognize the situation, and generate
    6306                 :             :          debug temporaries at the last real use of TERed SSA names:
    6307                 :             :            a_1 = a_0 + 1;
    6308                 :             :            #DEBUG #D1 => a_1
    6309                 :             :            use(a_1);
    6310                 :             :            a_2 = ...
    6311                 :             :            #DEBUG ... => #D1
    6312                 :             :          */
    6313                 :    53321906 :       if (MAY_HAVE_DEBUG_BIND_INSNS
    6314                 :    29360260 :           && SA.values
    6315                 :    81471972 :           && !is_gimple_debug (stmt))
    6316                 :             :         {
    6317                 :    20244413 :           ssa_op_iter iter;
    6318                 :    20244413 :           tree op;
    6319                 :    20244413 :           gimple *def;
    6320                 :             : 
    6321                 :    20244413 :           location_t sloc = curr_insn_location ();
    6322                 :             : 
    6323                 :             :           /* Look for SSA names that have their last use here (TERed
    6324                 :             :              names always have only one real use).  */
    6325                 :    38590549 :           FOR_EACH_SSA_TREE_OPERAND (op, stmt, iter, SSA_OP_USE)
    6326                 :    18346136 :             if ((def = get_gimple_for_ssa_name (op))
    6327                 :    18346136 :                 && is_gimple_assign (def))
    6328                 :             :               {
    6329                 :     5047243 :                 imm_use_iterator imm_iter;
    6330                 :     5047243 :                 use_operand_p use_p;
    6331                 :     5047243 :                 bool have_debug_uses = false;
    6332                 :             : 
    6333                 :    10069757 :                 FOR_EACH_IMM_USE_FAST (use_p, imm_iter, op)
    6334                 :             :                   {
    6335                 :     5071496 :                     if (gimple_debug_bind_p (USE_STMT (use_p)))
    6336                 :             :                       {
    6337                 :             :                         have_debug_uses = true;
    6338                 :             :                         break;
    6339                 :             :                       }
    6340                 :             :                   }
    6341                 :             : 
    6342                 :     5047243 :                 if (have_debug_uses)
    6343                 :             :                   {
    6344                 :             :                     /* OP is a TERed SSA name, with DEF its defining
    6345                 :             :                        statement, and where OP is used in further debug
    6346                 :             :                        instructions.  Generate a debug temporary, and
    6347                 :             :                        replace all uses of OP in debug insns with that
    6348                 :             :                        temporary.  */
    6349                 :       48982 :                     gimple *debugstmt;
    6350                 :       48982 :                     tree value = gimple_assign_rhs_to_tree (def);
    6351                 :       48982 :                     tree vexpr = build_debug_expr_decl (TREE_TYPE (value));
    6352                 :       48982 :                     rtx val;
    6353                 :       48982 :                     machine_mode mode;
    6354                 :             : 
    6355                 :       48982 :                     set_curr_insn_location (gimple_location (def));
    6356                 :             : 
    6357                 :       48982 :                     if (DECL_P (value))
    6358                 :         375 :                       mode = DECL_MODE (value);
    6359                 :             :                     else
    6360                 :       48607 :                       mode = TYPE_MODE (TREE_TYPE (value));
    6361                 :             :                     /* FIXME: Is setting the mode really necessary? */
    6362                 :       48982 :                     SET_DECL_MODE (vexpr, mode);
    6363                 :             : 
    6364                 :       48982 :                     val = gen_rtx_VAR_LOCATION
    6365                 :       48982 :                         (mode, vexpr, (rtx)value, VAR_INIT_STATUS_INITIALIZED);
    6366                 :             : 
    6367                 :       48982 :                     emit_debug_insn (val);
    6368                 :             : 
    6369                 :      170114 :                     FOR_EACH_IMM_USE_STMT (debugstmt, imm_iter, op)
    6370                 :             :                       {
    6371                 :      121132 :                         if (!gimple_debug_bind_p (debugstmt))
    6372                 :       48982 :                           continue;
    6373                 :             : 
    6374                 :      220460 :                         FOR_EACH_IMM_USE_ON_STMT (use_p, imm_iter)
    6375                 :       74155 :                           SET_USE (use_p, vexpr);
    6376                 :             : 
    6377                 :       72150 :                         update_stmt (debugstmt);
    6378                 :       48982 :                       }
    6379                 :             :                   }
    6380                 :             :               }
    6381                 :    20244413 :           set_curr_insn_location (sloc);
    6382                 :             :         }
    6383                 :             : 
    6384                 :    53321906 :       currently_expanding_gimple_stmt = stmt;
    6385                 :             : 
    6386                 :             :       /* Expand this statement, then evaluate the resulting RTL and
    6387                 :             :          fixup the CFG accordingly.  */
    6388                 :    53321906 :       if (gimple_code (stmt) == GIMPLE_COND)
    6389                 :             :         {
    6390                 :     5589481 :           new_bb = expand_gimple_cond (bb, as_a <gcond *> (stmt));
    6391                 :     5589481 :           if (new_bb)
    6392                 :             :             {
    6393                 :      488089 :               currently_expanding_gimple_stmt = NULL;
    6394                 :      488089 :               return new_bb;
    6395                 :             :             }
    6396                 :             :         }
    6397                 :    47732425 :       else if (is_gimple_debug (stmt))
    6398                 :             :         {
    6399                 :     8297266 :           location_t sloc = curr_insn_location ();
    6400                 :     8297266 :           gimple_stmt_iterator nsi = gsi;
    6401                 :             : 
    6402                 :    47074144 :           for (;;)
    6403                 :             :             {
    6404                 :    47074144 :               tree var;
    6405                 :    47074144 :               tree value = NULL_TREE;
    6406                 :    47074144 :               rtx val = NULL_RTX;
    6407                 :    47074144 :               machine_mode mode;
    6408                 :             : 
    6409                 :    47074144 :               if (!gimple_debug_nonbind_marker_p (stmt))
    6410                 :             :                 {
    6411                 :    35875606 :                   if (gimple_debug_bind_p (stmt))
    6412                 :             :                     {
    6413                 :    35734035 :                       var = gimple_debug_bind_get_var (stmt);
    6414                 :             : 
    6415                 :    35734035 :                       if (TREE_CODE (var) != DEBUG_EXPR_DECL
    6416                 :    33153254 :                           && TREE_CODE (var) != LABEL_DECL
    6417                 :    68878502 :                           && !target_for_debug_bind (var))
    6418                 :      395711 :                         goto delink_debug_stmt;
    6419                 :             : 
    6420                 :    35338324 :                       if (DECL_P (var) && !VECTOR_TYPE_P (TREE_TYPE (var)))
    6421                 :    35329097 :                         mode = DECL_MODE (var);
    6422                 :             :                       else
    6423                 :        9227 :                         mode = TYPE_MODE (TREE_TYPE (var));
    6424                 :             : 
    6425                 :    35338324 :                       if (gimple_debug_bind_has_value_p (stmt))
    6426                 :    19844614 :                         value = gimple_debug_bind_get_value (stmt);
    6427                 :             : 
    6428                 :    35338324 :                       val = gen_rtx_VAR_LOCATION
    6429                 :    35338324 :                         (mode, var, (rtx)value, VAR_INIT_STATUS_INITIALIZED);
    6430                 :             :                     }
    6431                 :      141571 :                   else if (gimple_debug_source_bind_p (stmt))
    6432                 :             :                     {
    6433                 :      141571 :                       var = gimple_debug_source_bind_get_var (stmt);
    6434                 :             : 
    6435                 :      141571 :                       value = gimple_debug_source_bind_get_value (stmt);
    6436                 :             : 
    6437                 :      141571 :                       if (!VECTOR_TYPE_P (TREE_TYPE (var)))
    6438                 :      141571 :                         mode = DECL_MODE (var);
    6439                 :             :                       else
    6440                 :           0 :                         mode = TYPE_MODE (TREE_TYPE (var));
    6441                 :             : 
    6442                 :      141571 :                       val = gen_rtx_VAR_LOCATION (mode, var, (rtx)value,
    6443                 :             :                                                   VAR_INIT_STATUS_UNINITIALIZED);
    6444                 :             :                     }
    6445                 :             :                   else
    6446                 :           0 :                     gcc_unreachable ();
    6447                 :             :                 }
    6448                 :             :               /* If this function was first compiled with markers
    6449                 :             :                  enabled, but they're now disable (e.g. LTO), drop
    6450                 :             :                  them on the floor.  */
    6451                 :    11198538 :               else if (gimple_debug_nonbind_marker_p (stmt)
    6452                 :    11198538 :                        && !MAY_HAVE_DEBUG_MARKER_INSNS)
    6453                 :           0 :                 goto delink_debug_stmt;
    6454                 :    11198538 :               else if (gimple_debug_begin_stmt_p (stmt))
    6455                 :     4030151 :                 val = GEN_RTX_DEBUG_MARKER_BEGIN_STMT_PAT ();
    6456                 :     7168387 :               else if (gimple_debug_inline_entry_p (stmt))
    6457                 :     7168387 :                 val = GEN_RTX_DEBUG_MARKER_INLINE_ENTRY_PAT ();
    6458                 :             :               else
    6459                 :             :                 gcc_unreachable ();
    6460                 :             : 
    6461                 :    46678433 :               last = get_last_insn ();
    6462                 :             : 
    6463                 :    46678433 :               set_curr_insn_location (gimple_location (stmt));
    6464                 :             : 
    6465                 :    46678433 :               emit_debug_insn (val);
    6466                 :             : 
    6467                 :    46678433 :               if (dump_file && (dump_flags & TDF_DETAILS))
    6468                 :             :                 {
    6469                 :             :                   /* We can't dump the insn with a TREE where an RTX
    6470                 :             :                      is expected.  */
    6471                 :           1 :                   if (GET_CODE (val) == VAR_LOCATION)
    6472                 :             :                     {
    6473                 :           0 :                       gcc_checking_assert (PAT_VAR_LOCATION_LOC (val) == (rtx)value);
    6474                 :           0 :                       PAT_VAR_LOCATION_LOC (val) = const0_rtx;
    6475                 :             :                     }
    6476                 :           1 :                   maybe_dump_rtl_for_gimple_stmt (stmt, last);
    6477                 :           1 :                   if (GET_CODE (val) == VAR_LOCATION)
    6478                 :           0 :                     PAT_VAR_LOCATION_LOC (val) = (rtx)value;
    6479                 :             :                 }
    6480                 :             : 
    6481                 :    47074144 :             delink_debug_stmt:
    6482                 :             :               /* In order not to generate too many debug temporaries,
    6483                 :             :                  we delink all uses of debug statements we already expanded.
    6484                 :             :                  Therefore debug statements between definition and real
    6485                 :             :                  use of TERed SSA names will continue to use the SSA name,
    6486                 :             :                  and not be replaced with debug temps.  */
    6487                 :    47074144 :               delink_stmt_imm_use (stmt);
    6488                 :             : 
    6489                 :    47074144 :               gsi = nsi;
    6490                 :    47074144 :               gsi_next (&nsi);
    6491                 :    47074144 :               if (gsi_end_p (nsi))
    6492                 :             :                 break;
    6493                 :    46388478 :               stmt = gsi_stmt (nsi);
    6494                 :    46388478 :               if (!is_gimple_debug (stmt))
    6495                 :             :                 break;
    6496                 :             :             }
    6497                 :             : 
    6498                 :     8297266 :           set_curr_insn_location (sloc);
    6499                 :             :         }
    6500                 :             :       else
    6501                 :             :         {
    6502                 :    39435159 :           gcall *call_stmt = dyn_cast <gcall *> (stmt);
    6503                 :    39435159 :           if (call_stmt
    6504                 :    39435159 :               && asan_epilog_seq
    6505                 :       17658 :               && gimple_call_tail_p (call_stmt)
    6506                 :    39435244 :               && !gimple_call_must_tail_p (call_stmt))
    6507                 :          12 :             gimple_call_set_tail (call_stmt, false);
    6508                 :             : 
    6509                 :    39435159 :           if (call_stmt && gimple_call_tail_p (call_stmt))
    6510                 :             :             {
    6511                 :      173054 :               bool can_fallthru;
    6512                 :      173054 :               new_bb = expand_gimple_tailcall (bb, call_stmt, &can_fallthru,
    6513                 :             :                                                asan_epilog_seq);
    6514                 :      173054 :               if (new_bb)
    6515                 :             :                 {
    6516                 :      124162 :                   if (can_fallthru)
    6517                 :           0 :                     bb = new_bb;
    6518                 :             :                   else
    6519                 :             :                     {
    6520                 :      124162 :                       currently_expanding_gimple_stmt = NULL;
    6521                 :      124162 :                       return new_bb;
    6522                 :             :                     }
    6523                 :             :                 }
    6524                 :             :             }
    6525                 :             :           else
    6526                 :             :             {
    6527                 :    39262105 :               def_operand_p def_p;
    6528                 :    39262105 :               def_p = SINGLE_SSA_DEF_OPERAND (stmt, SSA_OP_DEF);
    6529                 :             : 
    6530                 :    39262105 :               if (def_p != NULL)
    6531                 :             :                 {
    6532                 :             :                   /* Ignore this stmt if it is in the list of
    6533                 :             :                      replaceable expressions.  */
    6534                 :    32975570 :                   if (SA.values
    6535                 :    40888663 :                       && bitmap_bit_p (SA.values,
    6536                 :    16629862 :                                        SSA_NAME_VERSION (DEF_FROM_PTR (def_p))))
    6537                 :     8716769 :                     continue;
    6538                 :             :                 }
    6539                 :    30545336 :               last = expand_gimple_stmt (stmt);
    6540                 :    30545336 :               maybe_dump_rtl_for_gimple_stmt (stmt, last);
    6541                 :             :             }
    6542                 :             :         }
    6543                 :             :     }
    6544                 :             : 
    6545                 :    11906320 :   currently_expanding_gimple_stmt = NULL;
    6546                 :             : 
    6547                 :             :   /* Expand implicit goto and convert goto_locus.  */
    6548                 :    28869206 :   FOR_EACH_EDGE (e, ei, bb->succs)
    6549                 :             :     {
    6550                 :    16962886 :       if (e->goto_locus != UNKNOWN_LOCATION || !nondebug_stmt_seen)
    6551                 :    11676861 :         set_curr_insn_location (e->goto_locus);
    6552                 :    16962886 :       if ((e->flags & EDGE_FALLTHRU) && e->dest != bb->next_bb)
    6553                 :             :         {
    6554                 :     1614060 :           emit_jump (label_rtx_for_bb (e->dest));
    6555                 :     1614060 :           e->flags &= ~EDGE_FALLTHRU;
    6556                 :             :         }
    6557                 :             :     }
    6558                 :             : 
    6559                 :             :   /* Expanded RTL can create a jump in the last instruction of block.
    6560                 :             :      This later might be assumed to be a jump to successor and break edge insertion.
    6561                 :             :      We need to insert dummy move to prevent this. PR41440. */
    6562                 :    11906320 :   if (single_succ_p (bb)
    6563                 :     5438275 :       && (single_succ_edge (bb)->flags & EDGE_FALLTHRU)
    6564                 :     3096667 :       && (last = get_last_insn ())
    6565                 :    14834161 :       && (JUMP_P (last)
    6566                 :     3096619 :           || (DEBUG_INSN_P (last)
    6567                 :      375678 :               && JUMP_P (prev_nondebug_insn (last)))))
    6568                 :             :     {
    6569                 :          53 :       rtx dummy = gen_reg_rtx (SImode);
    6570                 :          53 :       emit_insn_after_noloc (gen_move_insn (dummy, dummy), last, NULL);
    6571                 :             :     }
    6572                 :             : 
    6573                 :             :   /* A __builtin_unreachable () will insert a barrier that should end
    6574                 :             :      the basic block.  In gimple, any code after it will have already
    6575                 :             :      deleted, even without optimization.  If we emit additional code
    6576                 :             :      here, as we would to adjust the stack after a call, it should be
    6577                 :             :      eventually deleted, but it confuses internal checkers (PR118006)
    6578                 :             :      and optimizers before it does, because we don't expect to find
    6579                 :             :      barriers inside basic blocks.  */
    6580                 :    11906320 :   if (!BARRIER_P (get_last_insn ()))
    6581                 :     8672921 :     do_pending_stack_adjust ();
    6582                 :             :   else
    6583                 :     3233399 :     discard_pending_stack_adjust ();
    6584                 :             : 
    6585                 :             :   /* Find the block tail.  The last insn in the block is the insn
    6586                 :             :      before a barrier and/or table jump insn.  */
    6587                 :    11906320 :   last = get_last_insn ();
    6588                 :    11906320 :   if (BARRIER_P (last))
    6589                 :     3233399 :     last = PREV_INSN (last);
    6590                 :    11906320 :   if (JUMP_TABLE_DATA_P (last))
    6591                 :        9049 :     last = PREV_INSN (PREV_INSN (last));
    6592                 :    11906320 :   if (BARRIER_P (last))
    6593                 :        8080 :     last = PREV_INSN (last);
    6594                 :    11906320 :   head_end_for_bb[bb->index].second = last;
    6595                 :             : 
    6596                 :    23812640 :   update_bb_for_insn_chain (head_end_for_bb[bb->index].first,
    6597                 :    11906320 :                             head_end_for_bb[bb->index].second, bb);
    6598                 :             : 
    6599                 :    11906320 :   return bb;
    6600                 :             : }
    6601                 :             : 
    6602                 :             : 
    6603                 :             : /* Create a basic block for initialization code.  */
    6604                 :             : 
    6605                 :             : static basic_block
    6606                 :     1456102 : construct_init_block (void)
    6607                 :             : {
    6608                 :     1456102 :   basic_block init_block;
    6609                 :     1456102 :   edge e = NULL;
    6610                 :     1456102 :   int flags;
    6611                 :             : 
    6612                 :             :   /* Multiple entry points not supported yet.  */
    6613                 :     1456102 :   gcc_assert (EDGE_COUNT (ENTRY_BLOCK_PTR_FOR_FN (cfun)->succs) == 1);
    6614                 :     1456102 :   init_rtl_bb_info (ENTRY_BLOCK_PTR_FOR_FN (cfun));
    6615                 :     1456102 :   init_rtl_bb_info (EXIT_BLOCK_PTR_FOR_FN (cfun));
    6616                 :     1456102 :   ENTRY_BLOCK_PTR_FOR_FN (cfun)->flags |= BB_RTL;
    6617                 :     1456102 :   EXIT_BLOCK_PTR_FOR_FN (cfun)->flags |= BB_RTL;
    6618                 :             : 
    6619                 :     1456102 :   e = EDGE_SUCC (ENTRY_BLOCK_PTR_FOR_FN (cfun), 0);
    6620                 :             : 
    6621                 :             :   /* When entry edge points to first basic block, we don't need jump,
    6622                 :             :      otherwise we have to jump into proper target.  */
    6623                 :     1456102 :   if (e && e->dest != ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb)
    6624                 :             :     {
    6625                 :           0 :       tree label = gimple_block_label (e->dest);
    6626                 :             : 
    6627                 :           0 :       emit_jump (jump_target_rtx (label));
    6628                 :           0 :       flags = 0;
    6629                 :           0 :     }
    6630                 :             :   else
    6631                 :             :     flags = EDGE_FALLTHRU;
    6632                 :             : 
    6633                 :     1456102 :   init_block = create_basic_block (NEXT_INSN (get_insns ()),
    6634                 :             :                                    get_last_insn (),
    6635                 :     1456102 :                                    ENTRY_BLOCK_PTR_FOR_FN (cfun));
    6636                 :     1456102 :   init_block->count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
    6637                 :     1456102 :   add_bb_to_loop (init_block, ENTRY_BLOCK_PTR_FOR_FN (cfun)->loop_father);
    6638                 :     1456102 :   if (e)
    6639                 :     1456102 :     expand_split_edge (e, init_block, flags);
    6640                 :             :   else
    6641                 :           0 :     make_single_succ_edge (init_block, EXIT_BLOCK_PTR_FOR_FN (cfun),
    6642                 :             :                            EDGE_FALLTHRU);
    6643                 :             : 
    6644                 :     1456102 :   update_bb_for_insn (init_block);
    6645                 :     1456102 :   return init_block;
    6646                 :             : }
    6647                 :             : 
    6648                 :             : /* For each lexical block, set BLOCK_NUMBER to the depth at which it is
    6649                 :             :    found in the block tree.  */
    6650                 :             : 
    6651                 :             : static void
    6652                 :    18084432 : set_block_levels (tree block, int level)
    6653                 :             : {
    6654                 :    34712762 :   while (block)
    6655                 :             :     {
    6656                 :    16628330 :       BLOCK_NUMBER (block) = level;
    6657                 :    16628330 :       set_block_levels (BLOCK_SUBBLOCKS (block), level + 1);
    6658                 :    16628330 :       block = BLOCK_CHAIN (block);
    6659                 :             :     }
    6660                 :    18084432 : }
    6661                 :             : 
    6662                 :             : /* Create a block containing landing pads and similar stuff.  */
    6663                 :             : 
    6664                 :             : static void
    6665                 :     1456102 : construct_exit_block (void)
    6666                 :             : {
    6667                 :     1456102 :   rtx_insn *head = get_last_insn ();
    6668                 :     1456102 :   rtx_insn *end;
    6669                 :     1456102 :   basic_block exit_block;
    6670                 :     1456102 :   edge e, e2;
    6671                 :     1456102 :   unsigned ix;
    6672                 :     1456102 :   edge_iterator ei;
    6673                 :     1456102 :   basic_block prev_bb = EXIT_BLOCK_PTR_FOR_FN (cfun)->prev_bb;
    6674                 :     1456102 :   rtx_insn *orig_end = BB_END (prev_bb);
    6675                 :             : 
    6676                 :     1456102 :   rtl_profile_for_bb (EXIT_BLOCK_PTR_FOR_FN (cfun));
    6677                 :             : 
    6678                 :             :   /* Make sure the locus is set to the end of the function, so that
    6679                 :             :      epilogue line numbers and warnings are set properly.  */
    6680                 :     1456102 :   if (LOCATION_LOCUS (cfun->function_end_locus) != UNKNOWN_LOCATION)
    6681                 :     1139569 :     input_location = cfun->function_end_locus;
    6682                 :             : 
    6683                 :             :   /* Generate rtl for function exit.  */
    6684                 :     1456102 :   expand_function_end ();
    6685                 :             : 
    6686                 :     1456102 :   end = get_last_insn ();
    6687                 :     1456102 :   if (head == end)
    6688                 :           0 :     return;
    6689                 :             :   /* While emitting the function end we could move end of the last basic
    6690                 :             :      block.  */
    6691                 :     1456102 :   BB_END (prev_bb) = orig_end;
    6692                 :     1456102 :   while (NEXT_INSN (head) && NOTE_P (NEXT_INSN (head)))
    6693                 :             :     head = NEXT_INSN (head);
    6694                 :             :   /* But make sure exit_block starts with RETURN_LABEL, otherwise the
    6695                 :             :      bb count counting will be confused.  Any instructions before that
    6696                 :             :      label are emitted for the case where PREV_BB falls through into the
    6697                 :             :      exit block, so append those instructions to prev_bb in that case.  */
    6698                 :     1456102 :   if (NEXT_INSN (head) != return_label)
    6699                 :             :     {
    6700                 :       14810 :       while (NEXT_INSN (head) != return_label)
    6701                 :             :         {
    6702                 :        9819 :           if (!NOTE_P (NEXT_INSN (head)))
    6703                 :        9819 :             BB_END (prev_bb) = NEXT_INSN (head);
    6704                 :        9819 :           head = NEXT_INSN (head);
    6705                 :             :         }
    6706                 :             :     }
    6707                 :     1456102 :   exit_block = create_basic_block (NEXT_INSN (head), end, prev_bb);
    6708                 :     1456102 :   exit_block->count = EXIT_BLOCK_PTR_FOR_FN (cfun)->count;
    6709                 :     1456102 :   add_bb_to_loop (exit_block, EXIT_BLOCK_PTR_FOR_FN (cfun)->loop_father);
    6710                 :             : 
    6711                 :     1456102 :   ix = 0;
    6712                 :     4397122 :   while (ix < EDGE_COUNT (EXIT_BLOCK_PTR_FOR_FN (cfun)->preds))
    6713                 :             :     {
    6714                 :     1484918 :       e = EDGE_PRED (EXIT_BLOCK_PTR_FOR_FN (cfun), ix);
    6715                 :     1484918 :       if (!(e->flags & EDGE_ABNORMAL))
    6716                 :     1360756 :         redirect_edge_succ (e, exit_block);
    6717                 :             :       else
    6718                 :      124162 :         ix++;
    6719                 :             :     }
    6720                 :             : 
    6721                 :     1456102 :   e = make_single_succ_edge (exit_block, EXIT_BLOCK_PTR_FOR_FN (cfun),
    6722                 :             :                              EDGE_FALLTHRU);
    6723                 :     3036366 :   FOR_EACH_EDGE (e2, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds)
    6724                 :     1580264 :     if (e2 != e)
    6725                 :             :       {
    6726                 :      124162 :         exit_block->count -= e2->count ();
    6727                 :             :       }
    6728                 :     1456102 :   update_bb_for_insn (exit_block);
    6729                 :             : }
    6730                 :             : 
    6731                 :             : /* Helper function for discover_nonconstant_array_refs.
    6732                 :             :    Look for ARRAY_REF nodes with non-constant indexes and mark them
    6733                 :             :    addressable.  */
    6734                 :             : 
    6735                 :             : static tree
    6736                 :   162685980 : discover_nonconstant_array_refs_r (tree * tp, int *walk_subtrees,
    6737                 :             :                                    void *data)
    6738                 :             : {
    6739                 :   162685980 :   tree t = *tp;
    6740                 :   162685980 :   bitmap forced_stack_vars = (bitmap)((walk_stmt_info *)data)->info;
    6741                 :             : 
    6742                 :   162685980 :   if (IS_TYPE_OR_DECL_P (t))
    6743                 :    33758390 :     *walk_subtrees = 0;
    6744                 :   128927590 :   else if (REFERENCE_CLASS_P (t) && TREE_THIS_VOLATILE (t))
    6745                 :             :     {
    6746                 :       70374 :       t = get_base_address (t);
    6747                 :       70374 :       if (t && DECL_P (t)
    6748                 :       58241 :           && DECL_MODE (t) != BLKmode
    6749                 :      106848 :           && !TREE_ADDRESSABLE (t))
    6750                 :       32641 :         bitmap_set_bit (forced_stack_vars, DECL_UID (t));
    6751                 :       70374 :       *walk_subtrees = 0;
    6752                 :             :     }
    6753                 :   128857216 :   else if (TREE_CODE (t) == ARRAY_REF || TREE_CODE (t) == ARRAY_RANGE_REF)
    6754                 :             :     {
    6755                 :     5995184 :       while (((TREE_CODE (t) == ARRAY_REF || TREE_CODE (t) == ARRAY_RANGE_REF)
    6756                 :     2872260 :               && is_gimple_min_invariant (TREE_OPERAND (t, 1))
    6757                 :     2406224 :               && (!TREE_OPERAND (t, 2)
    6758                 :       30151 :                   || is_gimple_min_invariant (TREE_OPERAND (t, 2))))
    6759                 :     3617984 :              || (TREE_CODE (t) == COMPONENT_REF
    6760                 :      902793 :                  && (!TREE_OPERAND (t,2)
    6761                 :           0 :                      || is_gimple_min_invariant (TREE_OPERAND (t, 2))))
    6762                 :     2715191 :              || TREE_CODE (t) == BIT_FIELD_REF
    6763                 :             :              || TREE_CODE (t) == REALPART_EXPR
    6764                 :             :              || TREE_CODE (t) == IMAGPART_EXPR
    6765                 :             :              || TREE_CODE (t) == VIEW_CONVERT_EXPR
    6766                 :     5995184 :              || CONVERT_EXPR_P (t))
    6767                 :     3289860 :         t = TREE_OPERAND (t, 0);
    6768                 :             : 
    6769                 :     2705324 :       if (TREE_CODE (t) == ARRAY_REF || TREE_CODE (t) == ARRAY_RANGE_REF)
    6770                 :             :         {
    6771                 :      495060 :           t = get_base_address (t);
    6772                 :      495060 :           if (t && DECL_P (t)
    6773                 :      406754 :               && DECL_MODE (t) != BLKmode
    6774                 :      519862 :               && !TREE_ADDRESSABLE (t))
    6775                 :       16520 :             bitmap_set_bit (forced_stack_vars, DECL_UID (t));
    6776                 :             :         }
    6777                 :             : 
    6778                 :     2705324 :       *walk_subtrees = 0;
    6779                 :             :     }
    6780                 :             :   /* References of size POLY_INT_CST to a fixed-size object must go
    6781                 :             :      through memory.  It's more efficient to force that here than
    6782                 :             :      to create temporary slots on the fly.
    6783                 :             :      RTL expansion expectes TARGET_MEM_REF to always address actual memory.
    6784                 :             :      Also, force to stack non-BLKmode vars accessed through VIEW_CONVERT_EXPR
    6785                 :             :      to BLKmode type.  */
    6786                 :   126151892 :   else if (TREE_CODE (t) == TARGET_MEM_REF
    6787                 :             :            || (TREE_CODE (t) == MEM_REF
    6788                 :   125303977 :                && TYPE_SIZE (TREE_TYPE (t))
    6789                 :             :                && POLY_INT_CST_P (TYPE_SIZE (TREE_TYPE (t))))
    6790                 :   251455869 :            || (TREE_CODE (t) == VIEW_CONVERT_EXPR
    6791                 :      314260 :                && TYPE_MODE (TREE_TYPE (t)) == BLKmode))
    6792                 :             :     {
    6793                 :      925924 :       tree base = get_base_address (t);
    6794                 :      925924 :       if (base
    6795                 :      925924 :           && DECL_P (base)
    6796                 :      270710 :           && !TREE_ADDRESSABLE (base)
    6797                 :      126322 :           && DECL_MODE (base) != BLKmode
    6798                 :      931850 :           && GET_MODE_SIZE (DECL_MODE (base)).is_constant ())
    6799                 :        5926 :         bitmap_set_bit (forced_stack_vars, DECL_UID (base));
    6800                 :      925924 :       *walk_subtrees = 0;
    6801                 :             :     }
    6802                 :             : 
    6803                 :   162685980 :   return NULL_TREE;
    6804                 :             : }
    6805                 :             : 
    6806                 :             : /* If there's a chance to get a pseudo for t then if it would be of float mode
    6807                 :             :    and the actual access is via an integer mode (lowered memcpy or similar
    6808                 :             :    access) then avoid the register expansion if the mode likely is not storage
    6809                 :             :    suitable for raw bits processing (like XFmode on i?86).  */
    6810                 :             : 
    6811                 :             : static void
    6812                 :     6714371 : avoid_type_punning_on_regs (tree t, bitmap forced_stack_vars)
    6813                 :             : {
    6814                 :     6714371 :   machine_mode access_mode = TYPE_MODE (TREE_TYPE (t));
    6815                 :     6714371 :   if (access_mode != BLKmode
    6816                 :     6354164 :       && !SCALAR_INT_MODE_P (access_mode))
    6817                 :             :     return;
    6818                 :     5749982 :   tree base = get_base_address (t);
    6819                 :     5749982 :   if (DECL_P (base)
    6820                 :     4338557 :       && !TREE_ADDRESSABLE (base)
    6821                 :     1224101 :       && FLOAT_MODE_P (DECL_MODE (base))
    6822                 :          62 :       && maybe_lt (GET_MODE_PRECISION (DECL_MODE (base)),
    6823                 :         186 :                    GET_MODE_BITSIZE (GET_MODE_INNER (DECL_MODE (base))))
    6824                 :             :       /* Double check in the expensive way we really would get a pseudo.  */
    6825                 :     5749987 :       && use_register_for_decl (base))
    6826                 :           5 :     bitmap_set_bit (forced_stack_vars, DECL_UID (base));
    6827                 :             : }
    6828                 :             : 
    6829                 :             : /* RTL expansion is not able to compile array references with variable
    6830                 :             :    offsets for arrays stored in single register.  Discover such
    6831                 :             :    expressions and mark variables as addressable to avoid this
    6832                 :             :    scenario.  */
    6833                 :             : 
    6834                 :             : static void
    6835                 :     1456102 : discover_nonconstant_array_refs (bitmap forced_stack_vars)
    6836                 :             : {
    6837                 :     1456102 :   basic_block bb;
    6838                 :     1456102 :   gimple_stmt_iterator gsi;
    6839                 :             : 
    6840                 :     1456102 :   walk_stmt_info wi = {};
    6841                 :     1456102 :   wi.info = forced_stack_vars;
    6842                 :    13960474 :   FOR_EACH_BB_FN (bb, cfun)
    6843                 :   118436526 :     for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
    6844                 :             :       {
    6845                 :    93427782 :         gimple *stmt = gsi_stmt (gsi);
    6846                 :    93427782 :         if (!is_gimple_debug (stmt))
    6847                 :             :           {
    6848                 :    46237325 :             walk_gimple_op (stmt, discover_nonconstant_array_refs_r, &wi);
    6849                 :    46237325 :             gcall *call = dyn_cast <gcall *> (stmt);
    6850                 :     6761927 :             if (call && gimple_call_internal_p (call))
    6851                 :             :               {
    6852                 :      187397 :                 tree cand = NULL_TREE;
    6853                 :      187397 :                 switch (gimple_call_internal_fn (call))
    6854                 :             :                   {
    6855                 :           0 :                   case IFN_LOAD_LANES:
    6856                 :             :                     /* The source must be a MEM.  */
    6857                 :           0 :                     cand = gimple_call_arg (call, 0);
    6858                 :           0 :                     break;
    6859                 :           0 :                   case IFN_STORE_LANES:
    6860                 :             :                     /* The destination must be a MEM.  */
    6861                 :           0 :                     cand = gimple_call_lhs (call);
    6862                 :           0 :                     break;
    6863                 :             :                   default:
    6864                 :             :                     break;
    6865                 :             :                   }
    6866                 :           0 :                 if (cand)
    6867                 :           0 :                   cand = get_base_address (cand);
    6868                 :           0 :                 if (cand
    6869                 :           0 :                     && DECL_P (cand)
    6870                 :           0 :                     && use_register_for_decl (cand))
    6871                 :           0 :                   bitmap_set_bit (forced_stack_vars, DECL_UID (cand));
    6872                 :             :               }
    6873                 :   148915254 :             if (gimple_vdef (stmt))
    6874                 :             :               {
    6875                 :    15458266 :                 tree t = gimple_get_lhs (stmt);
    6876                 :    15458266 :                 if (t && REFERENCE_CLASS_P (t))
    6877                 :     6714371 :                   avoid_type_punning_on_regs (t, forced_stack_vars);
    6878                 :             :               }
    6879                 :             :           }
    6880                 :             :       }
    6881                 :     1456102 : }
    6882                 :             : 
    6883                 :             : /* This function sets crtl->args.internal_arg_pointer to a virtual
    6884                 :             :    register if DRAP is needed.  Local register allocator will replace
    6885                 :             :    virtual_incoming_args_rtx with the virtual register.  */
    6886                 :             : 
    6887                 :             : static void
    6888                 :     1456102 : expand_stack_alignment (void)
    6889                 :             : {
    6890                 :     1456102 :   rtx drap_rtx;
    6891                 :     1456102 :   unsigned int preferred_stack_boundary;
    6892                 :             : 
    6893                 :     1456102 :   if (! SUPPORTS_STACK_ALIGNMENT)
    6894                 :             :     return;
    6895                 :             : 
    6896                 :     1456102 :   if (cfun->calls_alloca
    6897                 :     1441198 :       || cfun->has_nonlocal_label
    6898                 :     1440396 :       || crtl->has_nonlocal_goto)
    6899                 :       16107 :     crtl->need_drap = true;
    6900                 :             : 
    6901                 :             :   /* Call update_stack_boundary here again to update incoming stack
    6902                 :             :      boundary.  It may set incoming stack alignment to a different
    6903                 :             :      value after RTL expansion.  TARGET_FUNCTION_OK_FOR_SIBCALL may
    6904                 :             :      use the minimum incoming stack alignment to check if it is OK
    6905                 :             :      to perform sibcall optimization since sibcall optimization will
    6906                 :             :      only align the outgoing stack to incoming stack boundary.  */
    6907                 :     1456102 :   if (targetm.calls.update_stack_boundary)
    6908                 :     1456102 :     targetm.calls.update_stack_boundary ();
    6909                 :             : 
    6910                 :             :   /* The incoming stack frame has to be aligned at least at
    6911                 :             :      parm_stack_boundary.  */
    6912                 :     1456102 :   gcc_assert (crtl->parm_stack_boundary <= INCOMING_STACK_BOUNDARY);
    6913                 :             : 
    6914                 :             :   /* Update crtl->stack_alignment_estimated and use it later to align
    6915                 :             :      stack.  We check PREFERRED_STACK_BOUNDARY if there may be non-call
    6916                 :             :      exceptions since callgraph doesn't collect incoming stack alignment
    6917                 :             :      in this case.  */
    6918                 :     1456102 :   if (cfun->can_throw_non_call_exceptions
    6919                 :      262734 :       && PREFERRED_STACK_BOUNDARY > crtl->preferred_stack_boundary)
    6920                 :             :     preferred_stack_boundary = PREFERRED_STACK_BOUNDARY;
    6921                 :             :   else
    6922                 :     1428169 :     preferred_stack_boundary = crtl->preferred_stack_boundary;
    6923                 :     1456102 :   if (preferred_stack_boundary > crtl->stack_alignment_estimated)
    6924                 :      701190 :     crtl->stack_alignment_estimated = preferred_stack_boundary;
    6925                 :     1456102 :   if (preferred_stack_boundary > crtl->stack_alignment_needed)
    6926                 :      653727 :     crtl->stack_alignment_needed = preferred_stack_boundary;
    6927                 :             : 
    6928                 :     1456102 :   gcc_assert (crtl->stack_alignment_needed
    6929                 :             :               <= crtl->stack_alignment_estimated);
    6930                 :             : 
    6931                 :     1456102 :   crtl->stack_realign_needed
    6932                 :     1456102 :     = INCOMING_STACK_BOUNDARY < crtl->stack_alignment_estimated;
    6933                 :     1456102 :   crtl->stack_realign_tried = crtl->stack_realign_needed;
    6934                 :             : 
    6935                 :     1456102 :   crtl->stack_realign_processed = true;
    6936                 :             : 
    6937                 :             :   /* Target has to redefine TARGET_GET_DRAP_RTX to support stack
    6938                 :             :      alignment.  */
    6939                 :     1456102 :   gcc_assert (targetm.calls.get_drap_rtx != NULL);
    6940                 :     1456102 :   drap_rtx = targetm.calls.get_drap_rtx ();
    6941                 :             : 
    6942                 :             :   /* stack_realign_drap and drap_rtx must match.  */
    6943                 :     1456102 :   gcc_assert ((stack_realign_drap != 0) == (drap_rtx != NULL));
    6944                 :             : 
    6945                 :             :   /* Do nothing if NULL is returned, which means DRAP is not needed.  */
    6946                 :     1456102 :   if (drap_rtx != NULL)
    6947                 :             :     {
    6948                 :        7133 :       crtl->args.internal_arg_pointer = drap_rtx;
    6949                 :             : 
    6950                 :             :       /* Call fixup_tail_calls to clean up REG_EQUIV note if DRAP is
    6951                 :             :          needed. */
    6952                 :        7133 :       fixup_tail_calls ();
    6953                 :             :     }
    6954                 :             : }
    6955                 :             : 
    6956                 :             : 
    6957                 :             : static void
    6958                 :           0 : expand_main_function (void)
    6959                 :             : {
    6960                 :             : #if (defined(INVOKE__main)                              \
    6961                 :             :      || (!defined(HAS_INIT_SECTION)                     \
    6962                 :             :          && !defined(INIT_SECTION_ASM_OP)               \
    6963                 :             :          && !defined(INIT_ARRAY_SECTION_ASM_OP)))
    6964                 :             :   emit_library_call (init_one_libfunc (NAME__MAIN), LCT_NORMAL, VOIDmode);
    6965                 :             : #endif
    6966                 :           0 : }
    6967                 :             : 
    6968                 :             : 
    6969                 :             : /* Expand code to initialize the stack_protect_guard.  This is invoked at
    6970                 :             :    the beginning of a function to be protected.  */
    6971                 :             : 
    6972                 :             : static void
    6973                 :         238 : stack_protect_prologue (void)
    6974                 :             : {
    6975                 :         238 :   tree guard_decl = targetm.stack_protect_guard ();
    6976                 :         238 :   rtx x, y;
    6977                 :             : 
    6978                 :         238 :   crtl->stack_protect_guard_decl = guard_decl;
    6979                 :         238 :   x = expand_normal (crtl->stack_protect_guard);
    6980                 :             : 
    6981                 :         238 :   if (targetm.have_stack_protect_combined_set () && guard_decl)
    6982                 :             :     {
    6983                 :           0 :       gcc_assert (DECL_P (guard_decl));
    6984                 :           0 :       y = DECL_RTL (guard_decl);
    6985                 :             : 
    6986                 :             :       /* Allow the target to compute address of Y and copy it to X without
    6987                 :             :          leaking Y into a register.  This combined address + copy pattern
    6988                 :             :          allows the target to prevent spilling of any intermediate results by
    6989                 :             :          splitting it after register allocator.  */
    6990                 :           0 :       if (rtx_insn *insn = targetm.gen_stack_protect_combined_set (x, y))
    6991                 :             :         {
    6992                 :           0 :           emit_insn (insn);
    6993                 :           0 :           return;
    6994                 :             :         }
    6995                 :             :     }
    6996                 :             : 
    6997                 :         238 :   if (guard_decl)
    6998                 :         238 :     y = expand_normal (guard_decl);
    6999                 :             :   else
    7000                 :           0 :     y = const0_rtx;
    7001                 :             : 
    7002                 :             :   /* Allow the target to copy from Y to X without leaking Y into a
    7003                 :             :      register.  */
    7004                 :         238 :   if (targetm.have_stack_protect_set ())
    7005                 :         238 :     if (rtx_insn *insn = targetm.gen_stack_protect_set (x, y))
    7006                 :             :       {
    7007                 :         238 :         emit_insn (insn);
    7008                 :         238 :         return;
    7009                 :             :       }
    7010                 :             : 
    7011                 :             :   /* Otherwise do a straight move.  */
    7012                 :           0 :   emit_move_insn (x, y);
    7013                 :             : }
    7014                 :             : 
    7015                 :             : /* Translate the intermediate representation contained in the CFG
    7016                 :             :    from GIMPLE trees to RTL.
    7017                 :             : 
    7018                 :             :    We do conversion per basic block and preserve/update the tree CFG.
    7019                 :             :    This implies we have to do some magic as the CFG can simultaneously
    7020                 :             :    consist of basic blocks containing RTL and GIMPLE trees.  This can
    7021                 :             :    confuse the CFG hooks, so be careful to not manipulate CFG during
    7022                 :             :    the expansion.  */
    7023                 :             : 
    7024                 :             : namespace {
    7025                 :             : 
    7026                 :             : const pass_data pass_data_expand =
    7027                 :             : {
    7028                 :             :   RTL_PASS, /* type */
    7029                 :             :   "expand", /* name */
    7030                 :             :   OPTGROUP_NONE, /* optinfo_flags */
    7031                 :             :   TV_EXPAND, /* tv_id */
    7032                 :             :   ( PROP_ssa | PROP_gimple_leh | PROP_cfg
    7033                 :             :     | PROP_gimple_lcx
    7034                 :             :     | PROP_gimple_lvec
    7035                 :             :     | PROP_gimple_lva), /* properties_required */
    7036                 :             :   PROP_rtl, /* properties_provided */
    7037                 :             :   ( PROP_ssa | PROP_gimple ), /* properties_destroyed */
    7038                 :             :   0, /* todo_flags_start */
    7039                 :             :   0, /* todo_flags_finish */
    7040                 :             : };
    7041                 :             : 
    7042                 :             : class pass_expand : public rtl_opt_pass
    7043                 :             : {
    7044                 :             : public:
    7045                 :      286686 :   pass_expand (gcc::context *ctxt)
    7046                 :      573372 :     : rtl_opt_pass (pass_data_expand, ctxt)
    7047                 :             :   {}
    7048                 :             : 
    7049                 :             :   /* opt_pass methods: */
    7050                 :             :   unsigned int execute (function *) final override;
    7051                 :             : 
    7052                 :             : }; // class pass_expand
    7053                 :             : 
    7054                 :             : unsigned int
    7055                 :     1456102 : pass_expand::execute (function *fun)
    7056                 :             : {
    7057                 :     1456102 :   basic_block bb, init_block;
    7058                 :     1456102 :   edge_iterator ei;
    7059                 :     1456102 :   edge e;
    7060                 :     1456102 :   rtx_insn *var_seq, *var_ret_seq;
    7061                 :     1456102 :   unsigned i;
    7062                 :             : 
    7063                 :     1456102 :   timevar_push (TV_OUT_OF_SSA);
    7064                 :     1456102 :   rewrite_out_of_ssa (&SA);
    7065                 :     1456102 :   timevar_pop (TV_OUT_OF_SSA);
    7066                 :     1456102 :   SA.partition_to_pseudo = XCNEWVEC (rtx, SA.map->num_partitions);
    7067                 :             : 
    7068                 :     1456102 :   if (MAY_HAVE_DEBUG_BIND_STMTS && flag_tree_ter)
    7069                 :             :     {
    7070                 :      495825 :       gimple_stmt_iterator gsi;
    7071                 :     6760428 :       FOR_EACH_BB_FN (bb, cfun)
    7072                 :    81210096 :         for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
    7073                 :   104514691 :           if (gimple_debug_bind_p (gsi_stmt (gsi)))
    7074                 :    35833801 :             avoid_deep_ter_for_debug (gsi_stmt (gsi), 0);
    7075                 :             :     }
    7076                 :             : 
    7077                 :             :   /* Mark arrays indexed with non-constant indices with TREE_ADDRESSABLE.  */
    7078                 :     1456102 :   auto_bitmap forced_stack_vars;
    7079                 :     1456102 :   discover_nonconstant_array_refs (forced_stack_vars);
    7080                 :             : 
    7081                 :             :   /* Make sure all values used by the optimization passes have sane
    7082                 :             :      defaults.  */
    7083                 :     1456102 :   reg_renumber = 0;
    7084                 :             : 
    7085                 :             :   /* Some backends want to know that we are expanding to RTL.  */
    7086                 :     1456102 :   currently_expanding_to_rtl = 1;
    7087                 :             :   /* Dominators are not kept up-to-date as we may create new basic-blocks.  */
    7088                 :     1456102 :   free_dominance_info (CDI_DOMINATORS);
    7089                 :             : 
    7090                 :     1456102 :   rtl_profile_for_bb (ENTRY_BLOCK_PTR_FOR_FN (fun));
    7091                 :             : 
    7092                 :     1456102 :   insn_locations_init ();
    7093                 :     1456102 :   if (!DECL_IS_UNDECLARED_BUILTIN (current_function_decl))
    7094                 :             :     {
    7095                 :             :       /* Eventually, all FEs should explicitly set function_start_locus.  */
    7096                 :     1335042 :       if (LOCATION_LOCUS (fun->function_start_locus) == UNKNOWN_LOCATION)
    7097                 :      622314 :         set_curr_insn_location
    7098                 :      622314 :           (DECL_SOURCE_LOCATION (current_function_decl));
    7099                 :             :       else
    7100                 :      712728 :         set_curr_insn_location (fun->function_start_locus);
    7101                 :             :     }
    7102                 :             :   else
    7103                 :      121060 :     set_curr_insn_location (UNKNOWN_LOCATION);
    7104                 :     1456102 :   prologue_location = curr_insn_location ();
    7105                 :             : 
    7106                 :             : #ifdef INSN_SCHEDULING
    7107                 :     1456102 :   init_sched_attrs ();
    7108                 :             : #endif
    7109                 :             : 
    7110                 :             :   /* Make sure first insn is a note even if we don't want linenums.
    7111                 :             :      This makes sure the first insn will never be deleted.
    7112                 :             :      Also, final expects a note to appear there.  */
    7113                 :     1456102 :   emit_note (NOTE_INSN_DELETED);
    7114                 :             : 
    7115                 :     1456102 :   targetm.expand_to_rtl_hook ();
    7116                 :     1456102 :   crtl->init_stack_alignment ();
    7117                 :     1456102 :   fun->cfg->max_jumptable_ents = 0;
    7118                 :             : 
    7119                 :             :   /* Resovle the function section.  Some targets, like ARM EABI rely on knowledge
    7120                 :             :      of the function section at exapnsion time to predict distance of calls.  */
    7121                 :     1456102 :   resolve_unique_section (current_function_decl, 0, flag_function_sections);
    7122                 :             : 
    7123                 :             :   /* Expand the variables recorded during gimple lowering.  */
    7124                 :     1456102 :   timevar_push (TV_VAR_EXPAND);
    7125                 :     1456102 :   start_sequence ();
    7126                 :             : 
    7127                 :     1456102 :   var_ret_seq = expand_used_vars (forced_stack_vars);
    7128                 :             : 
    7129                 :     1456102 :   var_seq = end_sequence ();
    7130                 :     1456102 :   timevar_pop (TV_VAR_EXPAND);
    7131                 :             : 
    7132                 :             :   /* Honor stack protection warnings.  */
    7133                 :     1456102 :   if (warn_stack_protect)
    7134                 :             :     {
    7135                 :           0 :       if (fun->calls_alloca)
    7136                 :           0 :         warning (OPT_Wstack_protector,
    7137                 :             :                  "stack protector not protecting local variables: "
    7138                 :             :                  "variable length buffer");
    7139                 :           0 :       if (has_short_buffer && !crtl->stack_protect_guard)
    7140                 :           0 :         warning (OPT_Wstack_protector,
    7141                 :             :                  "stack protector not protecting function: "
    7142                 :             :                  "all local arrays are less than %d bytes long",
    7143                 :           0 :                  (int) param_ssp_buffer_size);
    7144                 :             :     }
    7145                 :             : 
    7146                 :             :   /* Temporarily mark PARM_DECLs and RESULT_DECLs we need to expand to
    7147                 :             :      memory addressable so expand_function_start can emit the required
    7148                 :             :      copies.  */
    7149                 :     1456102 :   auto_vec<tree, 16> marked_parms;
    7150                 :     4538907 :   for (tree parm = DECL_ARGUMENTS (current_function_decl); parm;
    7151                 :     3082805 :        parm = DECL_CHAIN (parm))
    7152                 :     3082805 :     if (!TREE_ADDRESSABLE (parm)
    7153                 :     3082805 :         && bitmap_bit_p (forced_stack_vars, DECL_UID (parm)))
    7154                 :             :       {
    7155                 :         135 :         TREE_ADDRESSABLE (parm) = 1;
    7156                 :         135 :         marked_parms.safe_push (parm);
    7157                 :             :       }
    7158                 :     1456102 :   if (DECL_RESULT (current_function_decl)
    7159                 :     1456102 :       && !TREE_ADDRESSABLE (DECL_RESULT (current_function_decl))
    7160                 :     2905550 :       && bitmap_bit_p (forced_stack_vars,
    7161                 :     1449448 :                        DECL_UID (DECL_RESULT (current_function_decl))))
    7162                 :             :     {
    7163                 :           0 :       TREE_ADDRESSABLE (DECL_RESULT (current_function_decl)) = 1;
    7164                 :           0 :       marked_parms.safe_push (DECL_RESULT (current_function_decl));
    7165                 :             :     }
    7166                 :             : 
    7167                 :             :   /* Set up parameters and prepare for return, for the function.  */
    7168                 :     1456102 :   expand_function_start (current_function_decl);
    7169                 :             : 
    7170                 :             :   /* Clear TREE_ADDRESSABLE again.  */
    7171                 :     2912339 :   while (!marked_parms.is_empty ())
    7172                 :         135 :     TREE_ADDRESSABLE (marked_parms.pop ()) = 0;
    7173                 :             : 
    7174                 :             :   /* If we emitted any instructions for setting up the variables,
    7175                 :             :      emit them before the FUNCTION_START note.  */
    7176                 :     1456102 :   if (var_seq)
    7177                 :             :     {
    7178                 :        1604 :       emit_insn_before (var_seq, parm_birth_insn);
    7179                 :             : 
    7180                 :             :       /* In expand_function_end we'll insert the alloca save/restore
    7181                 :             :          before parm_birth_insn.  We've just insertted an alloca call.
    7182                 :             :          Adjust the pointer to match.  */
    7183                 :        1604 :       parm_birth_insn = var_seq;
    7184                 :             :     }
    7185                 :             : 
    7186                 :             :   /* Now propagate the RTL assignment of each partition to the
    7187                 :             :      underlying var of each SSA_NAME.  */
    7188                 :             :   tree name;
    7189                 :             : 
    7190                 :    71607342 :   FOR_EACH_SSA_NAME (i, name, cfun)
    7191                 :             :     {
    7192                 :             :       /* We might have generated new SSA names in
    7193                 :             :          update_alias_info_with_stack_vars.  They will have a NULL
    7194                 :             :          defining statements, and won't be part of the partitioning,
    7195                 :             :          so ignore those.  */
    7196                 :    48383527 :       if (!SSA_NAME_DEF_STMT (name))
    7197                 :       72473 :         continue;
    7198                 :             : 
    7199                 :    48311054 :       adjust_one_expanded_partition_var (name);
    7200                 :             :     }
    7201                 :             : 
    7202                 :             :   /* Clean up RTL of variables that straddle across multiple
    7203                 :             :      partitions, and check that the rtl of any PARM_DECLs that are not
    7204                 :             :      cleaned up is that of their default defs.  */
    7205                 :    71607342 :   FOR_EACH_SSA_NAME (i, name, cfun)
    7206                 :             :     {
    7207                 :    48383527 :       int part;
    7208                 :             : 
    7209                 :             :       /* We might have generated new SSA names in
    7210                 :             :          update_alias_info_with_stack_vars.  They will have a NULL
    7211                 :             :          defining statements, and won't be part of the partitioning,
    7212                 :             :          so ignore those.  */
    7213                 :    48383527 :       if (!SSA_NAME_DEF_STMT (name))
    7214                 :       72473 :         continue;
    7215                 :    48311054 :       part = var_to_partition (SA.map, name);
    7216                 :    48311054 :       if (part == NO_PARTITION)
    7217                 :    17327944 :         continue;
    7218                 :             : 
    7219                 :             :       /* If this decl was marked as living in multiple places, reset
    7220                 :             :          this now to NULL.  */
    7221                 :    30983110 :       tree var = SSA_NAME_VAR (name);
    7222                 :    10346492 :       if (var && DECL_RTL_IF_SET (var) == pc_rtx)
    7223                 :      225094 :         SET_DECL_RTL (var, NULL);
    7224                 :             :       /* Check that the pseudos chosen by assign_parms are those of
    7225                 :             :          the corresponding default defs.  */
    7226                 :    30758016 :       else if (SSA_NAME_IS_DEFAULT_DEF (name)
    7227                 :    30758016 :                && (TREE_CODE (var) == PARM_DECL
    7228                 :     3628652 :                    || TREE_CODE (var) == RESULT_DECL))
    7229                 :             :         {
    7230                 :     3571173 :           rtx in = DECL_RTL_IF_SET (var);
    7231                 :     3571173 :           gcc_assert (in);
    7232                 :     3571173 :           rtx out = SA.partition_to_pseudo[part];
    7233                 :     3571173 :           gcc_assert (in == out);
    7234                 :             : 
    7235                 :             :           /* Now reset VAR's RTL to IN, so that the _EXPR attrs match
    7236                 :             :              those expected by debug backends for each parm and for
    7237                 :             :              the result.  This is particularly important for stabs,
    7238                 :             :              whose register elimination from parm's DECL_RTL may cause
    7239                 :             :              -fcompare-debug differences as SET_DECL_RTL changes reg's
    7240                 :             :              attrs.  So, make sure the RTL already has the parm as the
    7241                 :             :              EXPR, so that it won't change.  */
    7242                 :     3571173 :           SET_DECL_RTL (var, NULL_RTX);
    7243                 :     3571173 :           if (MEM_P (in))
    7244                 :      762259 :             set_mem_attributes (in, var, true);
    7245                 :     3571173 :           SET_DECL_RTL (var, in);
    7246                 :             :         }
    7247                 :             :     }
    7248                 :             : 
    7249                 :             :   /* If this function is `main', emit a call to `__main'
    7250                 :             :      to run global initializers, etc.  */
    7251                 :     1456102 :   if (DECL_NAME (current_function_decl)
    7252                 :     1456102 :       && MAIN_NAME_P (DECL_NAME (current_function_decl))
    7253                 :     1566726 :       && DECL_FILE_SCOPE_P (current_function_decl))
    7254                 :     1456102 :     expand_main_function ();
    7255                 :             : 
    7256                 :             :   /* Initialize the stack_protect_guard field.  This must happen after the
    7257                 :             :      call to __main (if any) so that the external decl is initialized.  */
    7258                 :     1456102 :   if (crtl->stack_protect_guard && targetm.stack_protect_runtime_enabled_p ())
    7259                 :         238 :     stack_protect_prologue ();
    7260                 :             : 
    7261                 :     1456102 :   expand_phi_nodes (&SA);
    7262                 :             : 
    7263                 :             :   /* Release any stale SSA redirection data.  */
    7264                 :     1456102 :   redirect_edge_var_map_empty ();
    7265                 :             : 
    7266                 :             :   /* Register rtl specific functions for cfg.  */
    7267                 :     1456102 :   rtl_register_cfg_hooks ();
    7268                 :             : 
    7269                 :     1456102 :   init_block = construct_init_block ();
    7270                 :             : 
    7271                 :             :   /* Clear EDGE_EXECUTABLE on the entry edge(s).  It is cleaned from the
    7272                 :             :      remaining edges later.  */
    7273                 :     2912204 :   FOR_EACH_EDGE (e, ei, ENTRY_BLOCK_PTR_FOR_FN (fun)->succs)
    7274                 :     1456102 :     e->flags &= ~EDGE_EXECUTABLE;
    7275                 :             : 
    7276                 :             :   /* If the function has too many markers, drop them while expanding.  */
    7277                 :     1456102 :   if (cfun->debug_marker_count
    7278                 :     1456102 :       >= param_max_debug_marker_count)
    7279                 :           1 :     cfun->debug_nonbind_markers = false;
    7280                 :             : 
    7281                 :     1456102 :   enable_ranger (fun);
    7282                 :     1456102 :   lab_rtx_for_bb = new hash_map<basic_block, rtx_code_label *>;
    7283                 :     1456102 :   head_end_for_bb.create (last_basic_block_for_fn (fun));
    7284                 :    13974673 :   FOR_BB_BETWEEN (bb, init_block->next_bb, EXIT_BLOCK_PTR_FOR_FN (fun),
    7285                 :             :                   next_bb)
    7286                 :    12518571 :     bb = expand_gimple_basic_block (bb, var_ret_seq);
    7287                 :     1456102 :   disable_ranger (fun);
    7288                 :    14462762 :   FOR_BB_BETWEEN (bb, init_block->next_bb, EXIT_BLOCK_PTR_FOR_FN (fun),
    7289                 :             :                   next_bb)
    7290                 :             :     {
    7291                 :    13006660 :       if ((bb->flags & BB_RTL) == 0)
    7292                 :             :         {
    7293                 :    12518571 :           bb->il.gimple.seq = NULL;
    7294                 :    12518571 :           bb->il.gimple.phi_nodes = NULL;
    7295                 :    12518571 :           init_rtl_bb_info (bb);
    7296                 :    12518571 :           bb->flags |= BB_RTL;
    7297                 :    12518571 :           BB_HEAD (bb) = head_end_for_bb[bb->index].first;
    7298                 :    12518571 :           BB_END (bb) = head_end_for_bb[bb->index].second;
    7299                 :             :         }
    7300                 :             :       /* These flags have no purpose in RTL land.  */
    7301                 :    13006660 :       if (EDGE_COUNT (bb->succs) == 2)
    7302                 :             :         {
    7303                 :     6207089 :           EDGE_SUCC (bb, 0)->flags &= ~(EDGE_TRUE_VALUE | EDGE_FALSE_VALUE);
    7304                 :     6207089 :           EDGE_SUCC (bb, 1)->flags &= ~(EDGE_TRUE_VALUE | EDGE_FALSE_VALUE);
    7305                 :             :         }
    7306                 :    19057180 :       else if (single_succ_p (bb))
    7307                 :     6050520 :         single_succ_edge (bb)->flags &= ~(EDGE_TRUE_VALUE | EDGE_FALSE_VALUE);
    7308                 :             :     }
    7309                 :     1456102 :   head_end_for_bb.release ();
    7310                 :             : 
    7311                 :     1456102 :   if (MAY_HAVE_DEBUG_BIND_INSNS)
    7312                 :      495850 :     expand_debug_locations ();
    7313                 :             : 
    7314                 :     1456102 :   if (deep_ter_debug_map)
    7315                 :             :     {
    7316                 :         656 :       delete deep_ter_debug_map;
    7317                 :         656 :       deep_ter_debug_map = NULL;
    7318                 :             :     }
    7319                 :             : 
    7320                 :             :   /* Free stuff we no longer need after GIMPLE optimizations.  */
    7321                 :     1456102 :   free_dominance_info (CDI_DOMINATORS);
    7322                 :     1456102 :   free_dominance_info (CDI_POST_DOMINATORS);
    7323                 :     1456102 :   delete_tree_cfg_annotations (fun);
    7324                 :             : 
    7325                 :     1456102 :   timevar_push (TV_OUT_OF_SSA);
    7326                 :     1456102 :   finish_out_of_ssa (&SA);
    7327                 :     1456102 :   timevar_pop (TV_OUT_OF_SSA);
    7328                 :             : 
    7329                 :     1456102 :   timevar_push (TV_POST_EXPAND);
    7330                 :             :   /* We are no longer in SSA form.  */
    7331                 :     1456102 :   fun->gimple_df->in_ssa_p = false;
    7332                 :     1456102 :   loops_state_clear (LOOP_CLOSED_SSA);
    7333                 :             : 
    7334                 :             :   /* Expansion is used by optimization passes too, set maybe_hot_insn_p
    7335                 :             :      conservatively to true until they are all profile aware.  */
    7336                 :     2912204 :   delete lab_rtx_for_bb;
    7337                 :     1456102 :   free_histograms (fun);
    7338                 :             : 
    7339                 :     1456102 :   construct_exit_block ();
    7340                 :     1456102 :   insn_locations_finalize ();
    7341                 :             : 
    7342                 :     1456102 :   if (var_ret_seq)
    7343                 :             :     {
    7344                 :        1744 :       rtx_insn *after = return_label;
    7345                 :        1744 :       rtx_insn *next = NEXT_INSN (after);
    7346                 :        1744 :       if (next && NOTE_INSN_BASIC_BLOCK_P (next))
    7347                 :        1744 :         after = next;
    7348                 :        1744 :       emit_insn_after (var_ret_seq, after);
    7349                 :             :     }
    7350                 :             : 
    7351                 :     1456102 :   if (hwasan_sanitize_stack_p ())
    7352                 :         453 :     hwasan_maybe_emit_frame_base_init ();
    7353                 :             : 
    7354                 :             :   /* Zap the tree EH table.  */
    7355                 :     1456102 :   set_eh_throw_stmt_table (fun, NULL);
    7356                 :             : 
    7357                 :             :   /* We need JUMP_LABEL be set in order to redirect jumps, and hence
    7358                 :             :      split edges which edge insertions might do.  */
    7359                 :     1456102 :   rebuild_jump_labels (get_insns ());
    7360                 :             : 
    7361                 :             :   /* If we have a single successor to the entry block, put the pending insns
    7362                 :             :      after parm birth, but before NOTE_INSNS_FUNCTION_BEG.  */
    7363                 :     1456102 :   if (single_succ_p (ENTRY_BLOCK_PTR_FOR_FN (fun)))
    7364                 :             :     {
    7365                 :     1456102 :       edge e = single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (fun));
    7366                 :     1456102 :       if (e->insns.r)
    7367                 :             :         {
    7368                 :          11 :           rtx_insn *insns = e->insns.r;
    7369                 :          11 :           e->insns.r = NULL;
    7370                 :          11 :           rebuild_jump_labels_chain (insns);
    7371                 :          11 :           if (NOTE_P (parm_birth_insn)
    7372                 :          11 :               && NOTE_KIND (parm_birth_insn) == NOTE_INSN_FUNCTION_BEG)
    7373                 :          11 :             emit_insn_before_noloc (insns, parm_birth_insn, e->dest);
    7374                 :             :           else
    7375                 :           0 :             emit_insn_after_noloc (insns, parm_birth_insn, e->dest);
    7376                 :             :         }
    7377                 :             :     }
    7378                 :             : 
    7379                 :             :   /* Otherwise, as well as for other edges, take the usual way.  */
    7380                 :     1456102 :   commit_edge_insertions ();
    7381                 :             : 
    7382                 :             :   /* We're done expanding trees to RTL.  */
    7383                 :     1456102 :   currently_expanding_to_rtl = 0;
    7384                 :             : 
    7385                 :     1456102 :   flush_mark_addressable_queue ();
    7386                 :             : 
    7387                 :    18111494 :   FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (fun)->next_bb,
    7388                 :             :                   EXIT_BLOCK_PTR_FOR_FN (fun), next_bb)
    7389                 :             :     {
    7390                 :    16655392 :       edge e;
    7391                 :    16655392 :       edge_iterator ei;
    7392                 :    38855445 :       for (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); )
    7393                 :             :         {
    7394                 :             :           /* Clear EDGE_EXECUTABLE.  This flag is never used in the backend.  */
    7395                 :    22200053 :           e->flags &= ~EDGE_EXECUTABLE;
    7396                 :             : 
    7397                 :             :           /* At the moment not all abnormal edges match the RTL
    7398                 :             :              representation.  It is safe to remove them here as
    7399                 :             :              find_many_sub_basic_blocks will rediscover them.
    7400                 :             :              In the future we should get this fixed properly.  */
    7401                 :    22200053 :           if ((e->flags & EDGE_ABNORMAL)
    7402                 :      134091 :               && !(e->flags & EDGE_SIBCALL))
    7403                 :        9929 :             remove_edge (e);
    7404                 :             :           else
    7405                 :    22190124 :             ei_next (&ei);
    7406                 :             :         }
    7407                 :             :     }
    7408                 :             : 
    7409                 :     1456102 :   auto_sbitmap blocks (last_basic_block_for_fn (fun));
    7410                 :     1456102 :   bitmap_ones (blocks);
    7411                 :     1456102 :   find_many_sub_basic_blocks (blocks);
    7412                 :     1456102 :   purge_all_dead_edges ();
    7413                 :             : 
    7414                 :             :   /* After initial rtl generation, call back to finish generating
    7415                 :             :      exception support code.  We need to do this before cleaning up
    7416                 :             :      the CFG as the code does not expect dead landing pads.  */
    7417                 :     1456102 :   if (fun->eh->region_tree != NULL)
    7418                 :       63961 :     finish_eh_generation ();
    7419                 :             : 
    7420                 :             :   /* Call expand_stack_alignment after finishing all
    7421                 :             :      updates to crtl->preferred_stack_boundary.  */
    7422                 :     1456102 :   expand_stack_alignment ();
    7423                 :             : 
    7424                 :             :   /* Fixup REG_EQUIV notes in the prologue if there are tailcalls in this
    7425                 :             :      function.  */
    7426                 :     1456102 :   if (crtl->tail_call_emit)
    7427                 :      112008 :     fixup_tail_calls ();
    7428                 :             : 
    7429                 :     1456102 :   HOST_WIDE_INT patch_area_size, patch_area_entry;
    7430                 :     1456102 :   parse_and_check_patch_area (flag_patchable_function_entry, false,
    7431                 :             :                               &patch_area_size, &patch_area_entry);
    7432                 :             : 
    7433                 :     1456102 :   tree patchable_function_entry_attr
    7434                 :     1456102 :     = lookup_attribute ("patchable_function_entry",
    7435                 :     1456102 :                         DECL_ATTRIBUTES (cfun->decl));
    7436                 :     1456102 :   if (patchable_function_entry_attr)
    7437                 :             :     {
    7438                 :          16 :       tree pp_val = TREE_VALUE (patchable_function_entry_attr);
    7439                 :          16 :       tree patchable_function_entry_value1 = TREE_VALUE (pp_val);
    7440                 :             : 
    7441                 :          16 :       patch_area_size = tree_to_uhwi (patchable_function_entry_value1);
    7442                 :          16 :       patch_area_entry = 0;
    7443                 :          16 :       if (TREE_CHAIN (pp_val) != NULL_TREE)
    7444                 :             :         {
    7445                 :           8 :           tree patchable_function_entry_value2
    7446                 :           8 :             = TREE_VALUE (TREE_CHAIN (pp_val));
    7447                 :           8 :           patch_area_entry = tree_to_uhwi (patchable_function_entry_value2);
    7448                 :             :         }
    7449                 :             :     }
    7450                 :             : 
    7451                 :     1456102 :   if (patch_area_entry > patch_area_size)
    7452                 :             :     {
    7453                 :           0 :       if (patch_area_size > 0)
    7454                 :           0 :         warning (OPT_Wattributes,
    7455                 :             :                  "patchable function entry %wu exceeds size %wu",
    7456                 :             :                  patch_area_entry, patch_area_size);
    7457                 :           0 :       patch_area_entry = 0;
    7458                 :             :     }
    7459                 :             : 
    7460                 :     1456102 :   crtl->patch_area_size = patch_area_size;
    7461                 :     1456102 :   crtl->patch_area_entry = patch_area_entry;
    7462                 :             : 
    7463                 :             :   /* BB subdivision may have created basic blocks that are only reachable
    7464                 :             :      from unlikely bbs but not marked as such in the profile.  */
    7465                 :     1456102 :   if (optimize)
    7466                 :     1023856 :     propagate_unlikely_bbs_forward ();
    7467                 :             : 
    7468                 :             :   /* Remove unreachable blocks, otherwise we cannot compute dominators
    7469                 :             :      which are needed for loop state verification.  As a side-effect
    7470                 :             :      this also compacts blocks.
    7471                 :             :      ???  We cannot remove trivially dead insns here as for example
    7472                 :             :      the DRAP reg on i?86 is not magically live at this point.
    7473                 :             :      gcc.c-torture/execute/ipa-sra-2.c execution, -Os -m32 fails otherwise.  */
    7474                 :     1456102 :   cleanup_cfg (CLEANUP_NO_INSN_DEL);
    7475                 :             : 
    7476                 :     1456102 :   checking_verify_flow_info ();
    7477                 :             : 
    7478                 :             :   /* Initialize pseudos allocated for hard registers.  */
    7479                 :     1456102 :   emit_initial_value_sets ();
    7480                 :             : 
    7481                 :             :   /* And finally unshare all RTL.  */
    7482                 :     1456102 :   unshare_all_rtl ();
    7483                 :             : 
    7484                 :             :   /* There's no need to defer outputting this function any more; we
    7485                 :             :      know we want to output it.  */
    7486                 :     1456102 :   DECL_DEFER_OUTPUT (current_function_decl) = 0;
    7487                 :             : 
    7488                 :             :   /* Now that we're done expanding trees to RTL, we shouldn't have any
    7489                 :             :      more CONCATs anywhere.  */
    7490                 :     1456102 :   generating_concat_p = 0;
    7491                 :             : 
    7492                 :     1456102 :   if (dump_file)
    7493                 :             :     {
    7494                 :         359 :       fprintf (dump_file,
    7495                 :             :                "\n\n;;\n;; Full RTL generated for this function:\n;;\n");
    7496                 :             :       /* And the pass manager will dump RTL for us.  */
    7497                 :             :     }
    7498                 :             : 
    7499                 :             :   /* If we're emitting a nested function, make sure its parent gets
    7500                 :             :      emitted as well.  Doing otherwise confuses debug info.  */
    7501                 :     1456102 :     {
    7502                 :     1456102 :       tree parent;
    7503                 :     1456102 :       for (parent = DECL_CONTEXT (current_function_decl);
    7504                 :     3120383 :            parent != NULL_TREE;
    7505                 :     1664281 :            parent = get_containing_scope (parent))
    7506                 :     1664281 :         if (TREE_CODE (parent) == FUNCTION_DECL)
    7507                 :       71388 :           TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (parent)) = 1;
    7508                 :             :     }
    7509                 :             : 
    7510                 :     1456102 :   TREE_ASM_WRITTEN (current_function_decl) = 1;
    7511                 :             : 
    7512                 :             :   /* After expanding, the return labels are no longer needed. */
    7513                 :     1456102 :   return_label = NULL;
    7514                 :     1456102 :   naked_return_label = NULL;
    7515                 :             : 
    7516                 :             :   /* After expanding, the tm_restart map is no longer needed.  */
    7517                 :     1456102 :   if (fun->gimple_df->tm_restart)
    7518                 :         265 :     fun->gimple_df->tm_restart = NULL;
    7519                 :             : 
    7520                 :             :   /* Tag the blocks with a depth number so that change_scope can find
    7521                 :             :      the common parent easily.  */
    7522                 :     1456102 :   set_block_levels (DECL_INITIAL (fun->decl), 0);
    7523                 :     1456102 :   default_rtl_profile ();
    7524                 :             : 
    7525                 :             :   /* For -dx discard loops now, otherwise IL verify in clean_state will
    7526                 :             :      ICE.  */
    7527                 :     1456102 :   if (rtl_dump_and_exit)
    7528                 :             :     {
    7529                 :          79 :       cfun->curr_properties &= ~PROP_loops;
    7530                 :          79 :       loop_optimizer_finalize ();
    7531                 :             :     }
    7532                 :             : 
    7533                 :     1456102 :   timevar_pop (TV_POST_EXPAND);
    7534                 :             : 
    7535                 :     1456102 :   return 0;
    7536                 :     1456102 : }
    7537                 :             : 
    7538                 :             : } // anon namespace
    7539                 :             : 
    7540                 :             : rtl_opt_pass *
    7541                 :      286686 : make_pass_expand (gcc::context *ctxt)
    7542                 :             : {
    7543                 :      286686 :   return new pass_expand (ctxt);
    7544                 :             : }
        

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.