LCOV - code coverage report
Current view: top level - gcc - cfgexpand.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 88.4 % 3538 3129
Test Date: 2026-08-01 15:33:25 Functions: 94.3 % 106 100
Legend: Lines:     hit not hit

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

Generated by: LCOV version 2.4-beta

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