LCOV - code coverage report
Current view: top level - gcc - explow.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 75.8 % 880 667
Test Date: 2026-05-30 15:37:04 Functions: 91.5 % 47 43
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Subroutines for manipulating rtx's in semantically interesting ways.
       2              :    Copyright (C) 1987-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 it under
       7              : the terms of the GNU General Public License as published by the Free
       8              : Software Foundation; either version 3, or (at your option) any later
       9              : version.
      10              : 
      11              : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      12              : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      13              : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      14              : 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              : 
      21              : #include "config.h"
      22              : #include "system.h"
      23              : #include "coretypes.h"
      24              : #include "target.h"
      25              : #include "function.h"
      26              : #include "rtl.h"
      27              : #include "tree.h"
      28              : #include "memmodel.h"
      29              : #include "tm_p.h"
      30              : #include "optabs.h"
      31              : #include "expmed.h"
      32              : #include "profile-count.h"
      33              : #include "emit-rtl.h"
      34              : #include "recog.h"
      35              : #include "diagnostic-core.h"
      36              : #include "stor-layout.h"
      37              : #include "langhooks.h"
      38              : #include "except.h"
      39              : #include "dojump.h"
      40              : #include "explow.h"
      41              : #include "expr.h"
      42              : #include "stringpool.h"
      43              : #include "common/common-target.h"
      44              : #include "output.h"
      45              : 
      46              : static rtx break_out_memory_refs (rtx);
      47              : 
      48              : 
      49              : /* Truncate and perhaps sign-extend C as appropriate for MODE.  */
      50              : 
      51              : HOST_WIDE_INT
      52   5941088070 : trunc_int_for_mode (HOST_WIDE_INT c, machine_mode mode)
      53              : {
      54              :   /* Not scalar_int_mode because we also allow pointer bound modes.  */
      55   5941088070 :   scalar_mode smode = as_a <scalar_mode> (mode);
      56   5941088070 :   int width = GET_MODE_PRECISION (smode);
      57              : 
      58              :   /* You want to truncate to a _what_?  */
      59   5941088070 :   gcc_assert (SCALAR_INT_MODE_P (mode));
      60              : 
      61              :   /* Canonicalize BImode to 0 and STORE_FLAG_VALUE.  */
      62   5941088070 :   if (smode == BImode)
      63            0 :     return c & 1 ? STORE_FLAG_VALUE : 0;
      64              : 
      65              :   /* Sign-extend for the requested mode.  */
      66              : 
      67   5941088070 :   if (width < HOST_BITS_PER_WIDE_INT)
      68              :     {
      69   4698480342 :       HOST_WIDE_INT sign = 1;
      70   4698480342 :       sign <<= width - 1;
      71   4698480342 :       c &= (sign << 1) - 1;
      72   4698480342 :       c ^= sign;
      73   4698480342 :       c -= sign;
      74              :     }
      75              : 
      76              :   return c;
      77              : }
      78              : 
      79              : /* Likewise for polynomial values, using the sign-extended representation
      80              :    for each individual coefficient.  */
      81              : 
      82              : poly_int64
      83   1339628922 : trunc_int_for_mode (poly_int64 x, machine_mode mode)
      84              : {
      85   2679257844 :   for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
      86   1339628922 :     x.coeffs[i] = trunc_int_for_mode (x.coeffs[i], mode);
      87   1339628922 :   return x;
      88              : }
      89              : 
      90              : /* Return an rtx for the sum of X and the integer C, given that X has
      91              :    mode MODE.  INPLACE is true if X can be modified inplace or false
      92              :    if it must be treated as immutable.  */
      93              : 
      94              : rtx
      95    827574785 : plus_constant (machine_mode mode, rtx x, poly_int64 c, bool inplace)
      96              : {
      97    827574785 :   RTX_CODE code;
      98    827574785 :   rtx y;
      99    827574785 :   rtx tem;
     100    827574785 :   int all_constant = 0;
     101              : 
     102    827574785 :   gcc_assert (GET_MODE (x) == VOIDmode || GET_MODE (x) == mode);
     103              : 
     104    827574785 :   if (known_eq (c, 0))
     105              :     return x;
     106              : 
     107    785144458 :  restart:
     108              : 
     109    785809850 :   code = GET_CODE (x);
     110    785809850 :   y = x;
     111              : 
     112    785809850 :   switch (code)
     113              :     {
     114    590816207 :     CASE_CONST_SCALAR_INT:
     115    590816207 :       return immed_wide_int_const (wi::add (rtx_mode_t (x, mode), c), mode);
     116       463946 :     case MEM:
     117              :       /* If this is a reference to the constant pool, try replacing it with
     118              :          a reference to a new constant.  If the resulting address isn't
     119              :          valid, don't return it because we have no way to validize it.  */
     120       463946 :       if (GET_CODE (XEXP (x, 0)) == SYMBOL_REF
     121       463946 :           && CONSTANT_POOL_ADDRESS_P (XEXP (x, 0)))
     122              :         {
     123            0 :           rtx cst = get_pool_constant (XEXP (x, 0));
     124              : 
     125            0 :           if (GET_CODE (cst) == CONST_VECTOR
     126            0 :               && GET_MODE_INNER (GET_MODE (cst)) == mode)
     127              :             {
     128            0 :               cst = gen_lowpart (mode, cst);
     129            0 :               gcc_assert (cst);
     130              :             }
     131            0 :           else if (GET_MODE (cst) == VOIDmode
     132            0 :                    && get_pool_mode (XEXP (x, 0)) != mode)
     133              :             break;
     134            0 :           if (GET_MODE (cst) == VOIDmode || GET_MODE (cst) == mode)
     135              :             {
     136            0 :               tem = plus_constant (mode, cst, c);
     137            0 :               tem = force_const_mem (GET_MODE (x), tem);
     138              :               /* Targets may disallow some constants in the constant pool, thus
     139              :                  force_const_mem may return NULL_RTX.  */
     140            0 :               if (tem && memory_address_p (GET_MODE (tem), XEXP (tem, 0)))
     141            0 :                 return tem;
     142              :             }
     143              :         }
     144              :       break;
     145              : 
     146       665392 :     case CONST:
     147              :       /* If adding to something entirely constant, set a flag
     148              :          so that we can add a CONST around the result.  */
     149       665392 :       if (inplace && shared_const_p (x))
     150              :         inplace = false;
     151       665392 :       x = XEXP (x, 0);
     152       665392 :       all_constant = 1;
     153       665392 :       goto restart;
     154              : 
     155              :     case SYMBOL_REF:
     156              :     case LABEL_REF:
     157              :       all_constant = 1;
     158              :       break;
     159              : 
     160     39835123 :     case PLUS:
     161              :       /* The interesting case is adding the integer to a sum.  Look
     162              :          for constant term in the sum and combine with C.  For an
     163              :          integer constant term or a constant term that is not an
     164              :          explicit integer, we combine or group them together anyway.
     165              : 
     166              :          We may not immediately return from the recursive call here, lest
     167              :          all_constant gets lost.  */
     168              : 
     169     39835123 :       if (CONSTANT_P (XEXP (x, 1)))
     170              :         {
     171     38005580 :           rtx term = plus_constant (mode, XEXP (x, 1), c, inplace);
     172     38005580 :           if (term == const0_rtx)
     173       304072 :             x = XEXP (x, 0);
     174     37701508 :           else if (inplace)
     175            0 :             XEXP (x, 1) = term;
     176              :           else
     177     37701508 :             x = gen_rtx_PLUS (mode, XEXP (x, 0), term);
     178     38005580 :           c = 0;
     179              :         }
     180      1829543 :       else if (rtx *const_loc = find_constant_term_loc (&y))
     181              :         {
     182            0 :           if (!inplace)
     183              :             {
     184              :               /* We need to be careful since X may be shared and we can't
     185              :                  modify it in place.  */
     186            0 :               x = copy_rtx (x);
     187            0 :               const_loc = find_constant_term_loc (&x);
     188              :             }
     189            0 :           *const_loc = plus_constant (mode, *const_loc, c, true);
     190            0 :           c = 0;
     191              :         }
     192              :       break;
     193              : 
     194              :     default:
     195              :       if (CONST_POLY_INT_P (x))
     196              :         return immed_wide_int_const (const_poly_int_value (x) + c, mode);
     197              :       break;
     198              :     }
     199              : 
     200    194328251 :   if (maybe_ne (c, 0))
     201    156322671 :     x = gen_rtx_PLUS (mode, x, gen_int_mode (c, mode));
     202              : 
     203    194328251 :   if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == LABEL_REF)
     204              :     return x;
     205    194326686 :   else if (all_constant)
     206      7836506 :     return gen_rtx_CONST (mode, x);
     207              :   else
     208              :     return x;
     209              : }
     210              : 
     211              : /* If X is a sum, return a new sum like X but lacking any constant terms.
     212              :    Add all the removed constant terms into *CONSTPTR.
     213              :    X itself is not altered.  The result != X if and only if
     214              :    it is not isomorphic to X.  */
     215              : 
     216              : rtx
     217       628116 : eliminate_constant_term (rtx x, rtx *constptr)
     218              : {
     219       628116 :   rtx x0, x1;
     220       628116 :   rtx tem;
     221              : 
     222       628116 :   if (GET_CODE (x) != PLUS)
     223              :     return x;
     224              : 
     225              :   /* First handle constants appearing at this level explicitly.  */
     226       281704 :   if (CONST_INT_P (XEXP (x, 1))
     227       106458 :       && (tem = simplify_binary_operation (PLUS, GET_MODE (x), *constptr,
     228              :                                            XEXP (x, 1))) != 0
     229       388162 :       && CONST_INT_P (tem))
     230              :     {
     231       106458 :       *constptr = tem;
     232       106458 :       return eliminate_constant_term (XEXP (x, 0), constptr);
     233              :     }
     234              : 
     235       175246 :   tem = const0_rtx;
     236       175246 :   x0 = eliminate_constant_term (XEXP (x, 0), &tem);
     237       175246 :   x1 = eliminate_constant_term (XEXP (x, 1), &tem);
     238       175246 :   if ((x1 != XEXP (x, 1) || x0 != XEXP (x, 0))
     239            0 :       && (tem = simplify_binary_operation (PLUS, GET_MODE (x),
     240              :                                            *constptr, tem)) != 0
     241       175246 :       && CONST_INT_P (tem))
     242              :     {
     243            0 :       *constptr = tem;
     244            0 :       return gen_rtx_PLUS (GET_MODE (x), x0, x1);
     245              :     }
     246              : 
     247              :   return x;
     248              : }
     249              : 
     250              : 
     251              : /* Return a copy of X in which all memory references
     252              :    and all constants that involve symbol refs
     253              :    have been replaced with new temporary registers.
     254              :    Also emit code to load the memory locations and constants
     255              :    into those registers.
     256              : 
     257              :    If X contains no such constants or memory references,
     258              :    X itself (not a copy) is returned.
     259              : 
     260              :    If a constant is found in the address that is not a legitimate constant
     261              :    in an insn, it is left alone in the hope that it might be valid in the
     262              :    address.
     263              : 
     264              :    X may contain no arithmetic except addition, subtraction and multiplication.
     265              :    Values returned by expand_expr with 1 for sum_ok fit this constraint.  */
     266              : 
     267              : static rtx
     268     40816468 : break_out_memory_refs (rtx x)
     269              : {
     270     40816468 :   if (MEM_P (x)
     271     40816468 :       || (CONSTANT_P (x) && CONSTANT_ADDRESS_P (x)
     272     12713543 :           && GET_MODE (x) != VOIDmode))
     273       482294 :     x = force_reg (GET_MODE (x), x);
     274     40334174 :   else if (GET_CODE (x) == PLUS || GET_CODE (x) == MINUS
     275     27012350 :            || GET_CODE (x) == MULT)
     276              :     {
     277     13750401 :       rtx op0 = break_out_memory_refs (XEXP (x, 0));
     278     13750401 :       rtx op1 = break_out_memory_refs (XEXP (x, 1));
     279              : 
     280     13750401 :       if (op0 != XEXP (x, 0) || op1 != XEXP (x, 1))
     281       215035 :         x = simplify_gen_binary (GET_CODE (x), GET_MODE (x), op0, op1);
     282              :     }
     283              : 
     284     40816468 :   return x;
     285              : }
     286              : 
     287              : /* Given X, a memory address in address space AS' pointer mode, convert it to
     288              :    an address in the address space's address mode, or vice versa (TO_MODE says
     289              :    which way).  We take advantage of the fact that pointers are not allowed to
     290              :    overflow by commuting arithmetic operations over conversions so that address
     291              :    arithmetic insns can be used. IN_CONST is true if this conversion is inside
     292              :    a CONST. NO_EMIT is true if no insns should be emitted, and instead
     293              :    it should return NULL if it can't be simplified without emitting insns.  */
     294              : 
     295              : rtx
     296     31951401 : convert_memory_address_addr_space_1 (scalar_int_mode to_mode ATTRIBUTE_UNUSED,
     297              :                                      rtx x, addr_space_t as ATTRIBUTE_UNUSED,
     298              :                                      bool in_const ATTRIBUTE_UNUSED,
     299              :                                      bool no_emit ATTRIBUTE_UNUSED)
     300              : {
     301              : #ifndef POINTERS_EXTEND_UNSIGNED
     302              :   gcc_assert (GET_MODE (x) == to_mode || GET_MODE (x) == VOIDmode);
     303              :   return x;
     304              : #else /* defined(POINTERS_EXTEND_UNSIGNED) */
     305     31951401 :   scalar_int_mode pointer_mode, address_mode, from_mode;
     306     31951401 :   rtx temp;
     307     31951401 :   enum rtx_code code;
     308              : 
     309              :   /* If X already has the right mode, just return it.  */
     310     31951401 :   if (GET_MODE (x) == to_mode)
     311              :     return x;
     312              : 
     313         4493 :   pointer_mode = targetm.addr_space.pointer_mode (as);
     314         4493 :   address_mode = targetm.addr_space.address_mode (as);
     315         4493 :   from_mode = to_mode == pointer_mode ? address_mode : pointer_mode;
     316              : 
     317              :   /* Here we handle some special cases.  If none of them apply, fall through
     318              :      to the default case.  */
     319         4493 :   switch (GET_CODE (x))
     320              :     {
     321         4293 :     CASE_CONST_SCALAR_INT:
     322        12879 :       if (GET_MODE_SIZE (to_mode) < GET_MODE_SIZE (from_mode))
     323              :         code = TRUNCATE;
     324         4293 :       else if (POINTERS_EXTEND_UNSIGNED < 0)
     325              :         break;
     326         4293 :       else if (POINTERS_EXTEND_UNSIGNED > 0)
     327         4293 :         code = ZERO_EXTEND;
     328              :       else
     329              :         code = SIGN_EXTEND;
     330         4293 :       temp = simplify_unary_operation (code, to_mode, x, from_mode);
     331         4293 :       if (temp)
     332              :         return temp;
     333              :       break;
     334              : 
     335           13 :     case SUBREG:
     336            1 :       if ((SUBREG_PROMOTED_VAR_P (x) || REG_POINTER (SUBREG_REG (x)))
     337           13 :           && GET_MODE (SUBREG_REG (x)) == to_mode)
     338              :         return SUBREG_REG (x);
     339              :       break;
     340              : 
     341            0 :     case LABEL_REF:
     342            0 :       temp = gen_rtx_LABEL_REF (to_mode, label_ref_label (x));
     343            0 :       LABEL_REF_NONLOCAL_P (temp) = LABEL_REF_NONLOCAL_P (x);
     344            0 :       return temp;
     345              : 
     346          136 :     case SYMBOL_REF:
     347          136 :       temp = shallow_copy_rtx (x);
     348          136 :       PUT_MODE (temp, to_mode);
     349          136 :       return temp;
     350              : 
     351            1 :     case CONST:
     352            1 :       {
     353            1 :         auto *last = no_emit ? nullptr : get_last_insn ();
     354            1 :         temp = convert_memory_address_addr_space_1 (to_mode, XEXP (x, 0), as,
     355              :                                                     true, no_emit);
     356            1 :         if (temp && (no_emit || last == get_last_insn ()))
     357            1 :           return gen_rtx_CONST (to_mode, temp);
     358              :         return temp;
     359              :       }
     360              : 
     361           28 :     case PLUS:
     362           28 :     case MULT:
     363              :       /* For addition we can safely permute the conversion and addition
     364              :          operation if one operand is a constant and converting the constant
     365              :          does not change it or if one operand is a constant and we are
     366              :          using a ptr_extend instruction  (POINTERS_EXTEND_UNSIGNED < 0).
     367              :          We can always safely permute them if we are making the address
     368              :          narrower. Inside a CONST RTL, this is safe for both pointers
     369              :          zero or sign extended as pointers cannot wrap. */
     370           56 :       if (GET_MODE_SIZE (to_mode) < GET_MODE_SIZE (from_mode)
     371           28 :           || (GET_CODE (x) == PLUS
     372           22 :               && CONST_INT_P (XEXP (x, 1))
     373            9 :               && ((in_const && POINTERS_EXTEND_UNSIGNED != 0)
     374              :                   || XEXP (x, 1) == convert_memory_address_addr_space_1
     375            8 :                                      (to_mode, XEXP (x, 1), as, in_const,
     376              :                                       no_emit)
     377            8 :                   || POINTERS_EXTEND_UNSIGNED < 0)))
     378              :         {
     379            9 :           temp = convert_memory_address_addr_space_1 (to_mode, XEXP (x, 0),
     380              :                                                       as, in_const, no_emit);
     381            9 :           return (temp ? gen_rtx_fmt_ee (GET_CODE (x), to_mode,
     382              :                                          temp, XEXP (x, 1))
     383              :                        : temp);
     384              :         }
     385              :       break;
     386              : 
     387            0 :     case UNSPEC:
     388              :       /* Assume that all UNSPECs in a constant address can be converted
     389              :          operand-by-operand.  We could add a target hook if some targets
     390              :          require different behavior.  */
     391            0 :       if (in_const && GET_MODE (x) == from_mode)
     392              :         {
     393            0 :           unsigned int n = XVECLEN (x, 0);
     394            0 :           rtvec v = gen_rtvec (n);
     395            0 :           for (unsigned int i = 0; i < n; ++i)
     396              :             {
     397            0 :               rtx op = XVECEXP (x, 0, i);
     398            0 :               if (GET_MODE (op) == from_mode)
     399            0 :                 op = convert_memory_address_addr_space_1 (to_mode, op, as,
     400              :                                                           in_const, no_emit);
     401            0 :               RTVEC_ELT (v, i) = op;
     402              :             }
     403            0 :           return gen_rtx_UNSPEC (to_mode, v, XINT (x, 1));
     404              :         }
     405              :       break;
     406              : 
     407              :     default:
     408              :       break;
     409              :     }
     410              : 
     411           42 :   if (no_emit)
     412              :     return NULL_RTX;
     413              : 
     414           42 :   return convert_modes (to_mode, from_mode,
     415           42 :                         x, POINTERS_EXTEND_UNSIGNED);
     416              : #endif /* defined(POINTERS_EXTEND_UNSIGNED) */
     417              : }
     418              : 
     419              : /* Given X, a memory address in address space AS' pointer mode, convert it to
     420              :    an address in the address space's address mode, or vice versa (TO_MODE says
     421              :    which way).  We take advantage of the fact that pointers are not allowed to
     422              :    overflow by commuting arithmetic operations over conversions so that address
     423              :    arithmetic insns can be used.  */
     424              : 
     425              : rtx
     426     31951362 : convert_memory_address_addr_space (scalar_int_mode to_mode, rtx x,
     427              :                                    addr_space_t as)
     428              : {
     429     31951362 :   return convert_memory_address_addr_space_1 (to_mode, x, as, false, false);
     430              : }
     431              : 
     432              : 
     433              : /* Return something equivalent to X but valid as a memory address for something
     434              :    of mode MODE in the named address space AS.  When X is not itself valid,
     435              :    this works by copying X or subexpressions of it into registers.  */
     436              : 
     437              : rtx
     438     30010079 : memory_address_addr_space (machine_mode mode, rtx x, addr_space_t as)
     439              : {
     440     30010079 :   rtx oldx = x;
     441     30010079 :   scalar_int_mode address_mode = targetm.addr_space.address_mode (as);
     442              : 
     443     30010079 :   x = convert_memory_address_addr_space (address_mode, x, as);
     444              : 
     445              :   /* By passing constant addresses through registers
     446              :      we get a chance to cse them.  */
     447     30010079 :   if (! cse_not_expected && CONSTANT_P (x) && CONSTANT_ADDRESS_P (x))
     448      1259137 :     x = force_reg (address_mode, x);
     449              : 
     450              :   /* We get better cse by rejecting indirect addressing at this stage.
     451              :      Let the combiner create indirect addresses where appropriate.
     452              :      For now, generate the code so that the subexpressions useful to share
     453              :      are visible.  But not if cse won't be done!  */
     454              :   else
     455              :     {
     456     28750942 :       if (! cse_not_expected && !REG_P (x))
     457     13315666 :         x = break_out_memory_refs (x);
     458              : 
     459              :       /* At this point, any valid address is accepted.  */
     460     28750942 :       if (memory_address_addr_space_p (mode, x, as))
     461     28068800 :         goto done;
     462              : 
     463              :       /* If it was valid before but breaking out memory refs invalidated it,
     464              :          use it the old way.  */
     465       682142 :       if (memory_address_addr_space_p (mode, oldx, as))
     466              :         {
     467        11353 :           x = oldx;
     468        11353 :           goto done;
     469              :         }
     470              : 
     471              :       /* Perform machine-dependent transformations on X
     472              :          in certain cases.  This is not necessary since the code
     473              :          below can handle all possible cases, but machine-dependent
     474              :          transformations can make better code.  */
     475       670789 :       {
     476       670789 :         rtx orig_x = x;
     477       670789 :         x = targetm.addr_space.legitimize_address (x, oldx, mode, as);
     478       670789 :         if (orig_x != x && memory_address_addr_space_p (mode, x, as))
     479       163104 :           goto done;
     480              :       }
     481              : 
     482              :       /* PLUS and MULT can appear in special ways
     483              :          as the result of attempts to make an address usable for indexing.
     484              :          Usually they are dealt with by calling force_operand, below.
     485              :          But a sum containing constant terms is special
     486              :          if removing them makes the sum a valid address:
     487              :          then we generate that address in a register
     488              :          and index off of it.  We do this because it often makes
     489              :          shorter code, and because the addresses thus generated
     490              :          in registers often become common subexpressions.  */
     491       507685 :       if (GET_CODE (x) == PLUS)
     492              :         {
     493       171166 :           rtx constant_term = const0_rtx;
     494       171166 :           rtx y = eliminate_constant_term (x, &constant_term);
     495       171166 :           if (constant_term == const0_rtx
     496       171166 :               || ! memory_address_addr_space_p (mode, y, as))
     497       171156 :             x = force_operand (x, NULL_RTX);
     498              :           else
     499              :             {
     500           10 :               y = gen_rtx_PLUS (GET_MODE (x), copy_to_reg (y), constant_term);
     501           10 :               if (! memory_address_addr_space_p (mode, y, as))
     502            8 :                 x = force_operand (x, NULL_RTX);
     503              :               else
     504              :                 x = y;
     505              :             }
     506              :         }
     507              : 
     508       336519 :       else if (GET_CODE (x) == MULT || GET_CODE (x) == MINUS)
     509            0 :         x = force_operand (x, NULL_RTX);
     510              : 
     511              :       /* If we have a register that's an invalid address,
     512              :          it must be a hard reg of the wrong class.  Copy it to a pseudo.  */
     513       336519 :       else if (REG_P (x))
     514            0 :         x = copy_to_reg (x);
     515              : 
     516              :       /* Last resort: copy the value to a register, since
     517              :          the register is a valid address.  */
     518              :       else
     519       336519 :         x = force_reg (address_mode, x);
     520              :     }
     521              : 
     522     30010079 :  done:
     523              : 
     524     30010079 :   gcc_assert (memory_address_addr_space_p (mode, x, as));
     525              :   /* If we didn't change the address, we are done.  Otherwise, mark
     526              :      a reg as a pointer if we have REG or REG + CONST_INT.  */
     527     30010079 :   if (oldx == x)
     528              :     return x;
     529      2391561 :   else if (REG_P (x))
     530      2138275 :     mark_reg_pointer (x, BITS_PER_UNIT);
     531       253286 :   else if (GET_CODE (x) == PLUS
     532       253283 :            && REG_P (XEXP (x, 0))
     533       120095 :            && CONST_INT_P (XEXP (x, 1)))
     534          374 :     mark_reg_pointer (XEXP (x, 0), BITS_PER_UNIT);
     535              : 
     536              :   /* OLDX may have been the address on a temporary.  Update the address
     537              :      to indicate that X is now used.  */
     538      2391561 :   update_temp_slot_address (oldx, x);
     539              : 
     540      2391561 :   return x;
     541              : }
     542              : 
     543              : /* Convert a mem ref into one with a valid memory address.
     544              :    Pass through anything else unchanged.  */
     545              : 
     546              : rtx
     547      5982834 : validize_mem (rtx ref)
     548              : {
     549      5982834 :   if (!MEM_P (ref))
     550              :     return ref;
     551      3470142 :   ref = use_anchored_address (ref);
     552      6940284 :   if (memory_address_addr_space_p (GET_MODE (ref), XEXP (ref, 0),
     553      3470142 :                                    MEM_ADDR_SPACE (ref)))
     554              :     return ref;
     555              : 
     556              :   /* Don't alter REF itself, since that is probably a stack slot.  */
     557        24496 :   return replace_equiv_address (ref, XEXP (ref, 0));
     558              : }
     559              : 
     560              : /* If X is a memory reference to a member of an object block, try rewriting
     561              :    it to use an anchor instead.  Return the new memory reference on success
     562              :    and the old one on failure.  */
     563              : 
     564              : rtx
     565     24318107 : use_anchored_address (rtx x)
     566              : {
     567     24318107 :   rtx base;
     568     24318107 :   HOST_WIDE_INT offset;
     569     24318107 :   machine_mode mode;
     570              : 
     571     24318107 :   if (!flag_section_anchors)
     572              :     return x;
     573              : 
     574            0 :   if (!MEM_P (x))
     575              :     return x;
     576              : 
     577              :   /* Split the address into a base and offset.  */
     578            0 :   base = XEXP (x, 0);
     579            0 :   offset = 0;
     580            0 :   if (GET_CODE (base) == CONST
     581            0 :       && GET_CODE (XEXP (base, 0)) == PLUS
     582            0 :       && CONST_INT_P (XEXP (XEXP (base, 0), 1)))
     583              :     {
     584            0 :       offset += INTVAL (XEXP (XEXP (base, 0), 1));
     585            0 :       base = XEXP (XEXP (base, 0), 0);
     586              :     }
     587              : 
     588              :   /* Check whether BASE is suitable for anchors.  */
     589            0 :   if (GET_CODE (base) != SYMBOL_REF
     590            0 :       || !SYMBOL_REF_HAS_BLOCK_INFO_P (base)
     591            0 :       || SYMBOL_REF_ANCHOR_P (base)
     592            0 :       || SYMBOL_REF_BLOCK (base) == NULL
     593            0 :       || !targetm.use_anchors_for_symbol_p (base))
     594            0 :     return x;
     595              : 
     596              :   /* Decide where BASE is going to be.  */
     597            0 :   place_block_symbol (base);
     598              : 
     599              :   /* Get the anchor we need to use.  */
     600            0 :   offset += SYMBOL_REF_BLOCK_OFFSET (base);
     601            0 :   base = get_section_anchor (SYMBOL_REF_BLOCK (base), offset,
     602            0 :                              SYMBOL_REF_TLS_MODEL (base));
     603              : 
     604              :   /* Work out the offset from the anchor.  */
     605            0 :   offset -= SYMBOL_REF_BLOCK_OFFSET (base);
     606              : 
     607              :   /* If we're going to run a CSE pass, force the anchor into a register.
     608              :      We will then be able to reuse registers for several accesses, if the
     609              :      target costs say that that's worthwhile.  */
     610            0 :   mode = GET_MODE (base);
     611            0 :   if (!cse_not_expected)
     612            0 :     base = force_reg (mode, base);
     613              : 
     614            0 :   return replace_equiv_address (x, plus_constant (mode, base, offset));
     615              : }
     616              : 
     617              : /* Copy the value or contents of X to a new temp reg and return that reg.  */
     618              : 
     619              : rtx
     620       746984 : copy_to_reg (rtx x)
     621              : {
     622       746984 :   rtx temp = gen_reg_rtx (GET_MODE (x));
     623              : 
     624              :   /* If not an operand, must be an address with PLUS and MULT so
     625              :      do the computation.  */
     626       746984 :   if (! general_operand (x, VOIDmode))
     627           54 :     x = force_operand (x, temp);
     628              : 
     629       746984 :   if (x != temp)
     630       746974 :     emit_move_insn (temp, x);
     631              : 
     632       746984 :   return temp;
     633              : }
     634              : 
     635              : /* Like copy_to_reg but always give the new register mode Pmode
     636              :    in case X is a constant.  */
     637              : 
     638              : rtx
     639       470361 : copy_addr_to_reg (rtx x)
     640              : {
     641       610488 :   return copy_to_mode_reg (Pmode, x);
     642              : }
     643              : 
     644              : /* Like copy_to_reg but always give the new register mode MODE
     645              :    in case X is a constant.  */
     646              : 
     647              : rtx
     648      3338080 : copy_to_mode_reg (machine_mode mode, rtx x)
     649              : {
     650      3338080 :   rtx temp = gen_reg_rtx (mode);
     651              : 
     652              :   /* If not an operand, must be an address with PLUS and MULT so
     653              :      do the computation.  */
     654      3338080 :   if (! general_operand (x, VOIDmode))
     655       580476 :     x = force_operand (x, temp);
     656              : 
     657      3338080 :   gcc_assert (GET_MODE (x) == mode || GET_MODE (x) == VOIDmode);
     658      3338080 :   if (x != temp)
     659      2981538 :     emit_move_insn (temp, x);
     660      3338080 :   return temp;
     661              : }
     662              : 
     663              : /* Load X into a register if it is not already one.
     664              :    Use mode MODE for the register.
     665              :    X should be valid for mode MODE, but it may be a constant which
     666              :    is valid for all integer modes; that's why caller must specify MODE.
     667              : 
     668              :    The caller must not alter the value in the register we return,
     669              :    since we mark it as a "constant" register.  */
     670              : 
     671              : rtx
     672      8503943 : force_reg (machine_mode mode, rtx x)
     673              : {
     674      8503943 :   rtx temp, set;
     675      8503943 :   rtx_insn *insn;
     676              : 
     677      8503943 :   if (REG_P (x))
     678              :     return x;
     679              : 
     680      7218577 :   if (general_operand (x, mode))
     681              :     {
     682      6971247 :       temp = gen_reg_rtx (mode);
     683      6971247 :       insn = emit_move_insn (temp, x);
     684              :     }
     685              :   else
     686              :     {
     687       247330 :       temp = force_operand (x, NULL_RTX);
     688       247330 :       if (REG_P (temp))
     689         2889 :         insn = get_last_insn ();
     690              :       else
     691              :         {
     692       244441 :           rtx temp2 = gen_reg_rtx (mode);
     693       244441 :           insn = emit_move_insn (temp2, temp);
     694       244441 :           temp = temp2;
     695              :         }
     696              :     }
     697              : 
     698              :   /* Let optimizers know that TEMP's value never changes
     699              :      and that X can be substituted for it.  Don't get confused
     700              :      if INSN set something else (such as a SUBREG of TEMP).  */
     701      7218577 :   if (CONSTANT_P (x)
     702      2749124 :       && (set = single_set (insn)) != 0
     703      2749124 :       && SET_DEST (set) == temp
     704      9965916 :       && ! rtx_equal_p (x, SET_SRC (set)))
     705       631768 :     set_unique_reg_note (insn, REG_EQUAL, x);
     706              : 
     707              :   /* Let optimizers know that TEMP is a pointer, and if so, the
     708              :      known alignment of that pointer.  */
     709      7218577 :   {
     710      7218577 :     unsigned align = 0;
     711      7218577 :     if (GET_CODE (x) == SYMBOL_REF)
     712              :       {
     713      1444438 :         align = BITS_PER_UNIT;
     714      1444438 :         if (SYMBOL_REF_DECL (x) && DECL_P (SYMBOL_REF_DECL (x)))
     715      1441238 :           align = DECL_ALIGN (SYMBOL_REF_DECL (x));
     716              :       }
     717      5774139 :     else if (GET_CODE (x) == LABEL_REF)
     718              :       align = BITS_PER_UNIT;
     719      5766864 :     else if (GET_CODE (x) == CONST
     720       123813 :              && GET_CODE (XEXP (x, 0)) == PLUS
     721       112387 :              && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
     722       109727 :              && CONST_INT_P (XEXP (XEXP (x, 0), 1)))
     723              :       {
     724       109727 :         rtx s = XEXP (XEXP (x, 0), 0);
     725       109727 :         rtx c = XEXP (XEXP (x, 0), 1);
     726       109727 :         unsigned sa, ca;
     727              : 
     728       109727 :         sa = BITS_PER_UNIT;
     729       109727 :         if (SYMBOL_REF_DECL (s) && DECL_P (SYMBOL_REF_DECL (s)))
     730       109727 :           sa = DECL_ALIGN (SYMBOL_REF_DECL (s));
     731              : 
     732       109727 :         if (INTVAL (c) == 0)
     733              :           align = sa;
     734              :         else
     735              :           {
     736       109727 :             ca = ctz_hwi (INTVAL (c)) * BITS_PER_UNIT;
     737       109727 :             align = MIN (sa, ca);
     738              :           }
     739              :       }
     740              : 
     741      7208102 :     if (align || (MEM_P (x) && MEM_POINTER (x)))
     742      2501907 :       mark_reg_pointer (temp, align);
     743              :   }
     744              : 
     745              :   return temp;
     746              : }
     747              : 
     748              : /* Like simplify_gen_subreg, but force OP into a new register if the
     749              :    subreg cannot be formed directly.  */
     750              : 
     751              : rtx
     752       818353 : force_subreg (machine_mode outermode, rtx op,
     753              :               machine_mode innermode, poly_uint64 byte)
     754              : {
     755       818353 :   rtx x = simplify_gen_subreg (outermode, op, innermode, byte);
     756       818353 :   if (x)
     757              :     return x;
     758              : 
     759         6829 :   auto *start = get_last_insn ();
     760         6829 :   op = copy_to_mode_reg (innermode, op);
     761         6829 :   rtx res = simplify_gen_subreg (outermode, op, innermode, byte);
     762         6829 :   if (!res)
     763         6817 :     delete_insns_since (start);
     764              :   return res;
     765              : }
     766              : 
     767              : /* Try to return an rvalue expression for the OUTERMODE lowpart of OP,
     768              :    which has mode INNERMODE.  Allow OP to be forced into a new register
     769              :    if necessary.
     770              : 
     771              :    Return null on failure.  */
     772              : 
     773              : rtx
     774         5136 : force_lowpart_subreg (machine_mode outermode, rtx op,
     775              :                       machine_mode innermode)
     776              : {
     777         5136 :   auto byte = subreg_lowpart_offset (outermode, innermode);
     778         5136 :   return force_subreg (outermode, op, innermode, byte);
     779              : }
     780              : 
     781              : /* Try to return an rvalue expression for the OUTERMODE highpart of OP,
     782              :    which has mode INNERMODE.  Allow OP to be forced into a new register
     783              :    if necessary.
     784              : 
     785              :    Return null on failure.  */
     786              : 
     787              : rtx
     788           91 : force_highpart_subreg (machine_mode outermode, rtx op,
     789              :                        machine_mode innermode)
     790              : {
     791           91 :   auto byte = subreg_highpart_offset (outermode, innermode);
     792           91 :   return force_subreg (outermode, op, innermode, byte);
     793              : }
     794              : 
     795              : /* If X is a memory ref, copy its contents to a new temp reg and return
     796              :    that reg.  Otherwise, return X.  */
     797              : 
     798              : rtx
     799      1160008 : force_not_mem (rtx x)
     800              : {
     801      1160008 :   rtx temp;
     802              : 
     803      1160008 :   if (!MEM_P (x) || GET_MODE (x) == BLKmode)
     804              :     return x;
     805              : 
     806        10840 :   temp = gen_reg_rtx (GET_MODE (x));
     807              : 
     808        10840 :   if (MEM_POINTER (x))
     809         1267 :     REG_POINTER (temp) = 1;
     810              : 
     811        10840 :   emit_move_insn (temp, x);
     812        10840 :   return temp;
     813              : }
     814              : 
     815              : /* Copy X to TARGET (if it's nonzero and a reg)
     816              :    or to a new temp reg and return that reg.
     817              :    MODE is the mode to use for X in case it is a constant.  */
     818              : 
     819              : rtx
     820       177969 : copy_to_suggested_reg (rtx x, rtx target, machine_mode mode)
     821              : {
     822       177969 :   rtx temp;
     823              : 
     824       177969 :   if (target && REG_P (target))
     825              :     temp = target;
     826              :   else
     827       177950 :     temp = gen_reg_rtx (mode);
     828              : 
     829       177969 :   emit_move_insn (temp, x);
     830       177969 :   return temp;
     831              : }
     832              : 
     833              : /* Return the mode to use to pass or return a scalar of TYPE and MODE.
     834              :    PUNSIGNEDP points to the signedness of the type and may be adjusted
     835              :    to show what signedness to use on extension operations.
     836              : 
     837              :    FOR_RETURN is nonzero if the caller is promoting the return value
     838              :    of FNDECL, else it is for promoting args.  */
     839              : 
     840              : machine_mode
     841     35369706 : promote_function_mode (const_tree type, machine_mode mode, int *punsignedp,
     842              :                        const_tree funtype, int for_return)
     843              : {
     844              :   /* Called without a type node for a libcall.  */
     845     35369706 :   if (type == NULL_TREE)
     846              :     {
     847       204693 :       if (INTEGRAL_MODE_P (mode))
     848        34124 :         return targetm.calls.promote_function_mode (NULL_TREE, mode,
     849              :                                                     punsignedp, funtype,
     850        34124 :                                                     for_return);
     851              :       else
     852              :         return mode;
     853              :     }
     854              : 
     855     35165013 :   if (BITINT_TYPE_P (type))
     856              :     {
     857        44146 :       if (TYPE_MODE (type) == BLKmode)
     858        44146 :         return mode;
     859              : 
     860        25499 :       struct bitint_info info;
     861        25499 :       bool ok;
     862        25499 :       ok = targetm.c.bitint_type_info (TYPE_PRECISION (type), &info);
     863        25499 :       gcc_assert (ok);
     864              : 
     865        25499 :       if (!info.extended)
     866              :         return mode;
     867              :     }
     868     35120867 :   switch (TREE_CODE (type))
     869              :     {
     870     32055837 :     case INTEGER_TYPE:   case ENUMERAL_TYPE:   case BOOLEAN_TYPE:
     871     32055837 :     case REAL_TYPE:      case OFFSET_TYPE:     case FIXED_POINT_TYPE:
     872     32055837 :     case POINTER_TYPE:   case REFERENCE_TYPE:  case BITINT_TYPE:
     873     32055837 :       return targetm.calls.promote_function_mode (type, mode, punsignedp, funtype,
     874     32055837 :                                                   for_return);
     875              : 
     876              :     default:
     877              :       return mode;
     878              :     }
     879              : }
     880              : /* Return the mode to use to store a scalar of TYPE and MODE.
     881              :    PUNSIGNEDP points to the signedness of the type and may be adjusted
     882              :    to show what signedness to use on extension operations.  */
     883              : 
     884              : machine_mode
     885     76193009 : promote_mode (const_tree type ATTRIBUTE_UNUSED, machine_mode mode,
     886              :               int *punsignedp ATTRIBUTE_UNUSED)
     887              : {
     888              : #ifdef PROMOTE_MODE
     889     76193009 :   enum tree_code code;
     890     76193009 :   int unsignedp;
     891     76193009 :   scalar_mode smode;
     892              : #endif
     893              : 
     894              :   /* For libcalls this is invoked without TYPE from the backends
     895              :      TARGET_PROMOTE_FUNCTION_MODE hooks.  Don't do anything in that
     896              :      case.  */
     897     76193009 :   if (type == NULL_TREE)
     898              :     return mode;
     899              : 
     900              :   /* FIXME: this is the same logic that was there until GCC 4.4, but we
     901              :      probably want to test POINTERS_EXTEND_UNSIGNED even if PROMOTE_MODE
     902              :      is not defined.  The affected targets are S390, SPARC.  */
     903              : #ifdef PROMOTE_MODE
     904     76193009 :   code = TREE_CODE (type);
     905     76193009 :   unsignedp = *punsignedp;
     906              : 
     907     76193009 :   if (BITINT_TYPE_P (type))
     908              :     {
     909        35395 :       if (TYPE_MODE (type) == BLKmode)
     910        35395 :         return mode;
     911              : 
     912        35383 :       struct bitint_info info;
     913        35383 :       bool ok;
     914        35383 :       ok = targetm.c.bitint_type_info (TYPE_PRECISION (type), &info);
     915        35383 :       gcc_assert (ok);
     916              : 
     917        35383 :       if (!info.extended)
     918              :         return mode;
     919              :     }
     920     76157614 :   switch (code)
     921              :     {
     922     54952658 :     case INTEGER_TYPE:   case ENUMERAL_TYPE:   case BOOLEAN_TYPE:
     923     54952658 :     case REAL_TYPE:      case OFFSET_TYPE:     case FIXED_POINT_TYPE:
     924     54952658 :     case BITINT_TYPE:
     925              :       /* Values of these types always have scalar mode.  */
     926     54952658 :       smode = as_a <scalar_mode> (mode);
     927     54952658 :       PROMOTE_MODE (smode, unsignedp, type);
     928     54952658 :       *punsignedp = unsignedp;
     929     54952658 :       return smode;
     930              : 
     931              : #ifdef POINTERS_EXTEND_UNSIGNED
     932     16968196 :     case REFERENCE_TYPE:
     933     16968196 :     case POINTER_TYPE:
     934     16968196 :       *punsignedp = POINTERS_EXTEND_UNSIGNED;
     935     16968196 :       return targetm.addr_space.address_mode
     936     16968196 :                (TYPE_ADDR_SPACE (TREE_TYPE (type)));
     937              : #endif
     938              : 
     939              :     default:
     940              :       return mode;
     941              :     }
     942              : #else
     943              :   return mode;
     944              : #endif
     945              : }
     946              : 
     947              : 
     948              : /* Use one of promote_mode or promote_function_mode to find the promoted
     949              :    mode of DECL.  If PUNSIGNEDP is not NULL, store there the unsignedness
     950              :    of DECL after promotion.  */
     951              : 
     952              : machine_mode
     953      8853315 : promote_decl_mode (const_tree decl, int *punsignedp)
     954              : {
     955      8853315 :   tree type = TREE_TYPE (decl);
     956      8853315 :   int unsignedp = TYPE_UNSIGNED (type);
     957      8853315 :   machine_mode mode = DECL_MODE (decl);
     958      8853315 :   machine_mode pmode;
     959              : 
     960      8853315 :   if (TREE_CODE (decl) == RESULT_DECL && !DECL_BY_REFERENCE (decl))
     961      7149400 :     pmode = promote_function_mode (type, mode, &unsignedp,
     962      3574700 :                                    TREE_TYPE (current_function_decl), 1);
     963      5278615 :   else if (TREE_CODE (decl) == RESULT_DECL || TREE_CODE (decl) == PARM_DECL)
     964      9426454 :     pmode = promote_function_mode (type, mode, &unsignedp,
     965      4713227 :                                    TREE_TYPE (current_function_decl), 2);
     966              :   else
     967       565388 :     pmode = promote_mode (type, mode, &unsignedp);
     968              : 
     969      8853315 :   if (punsignedp)
     970       961697 :     *punsignedp = unsignedp;
     971      8853315 :   return pmode;
     972              : }
     973              : 
     974              : /* Return the promoted mode for name.  If it is a named SSA_NAME, it
     975              :    is the same as promote_decl_mode.  Otherwise, it is the promoted
     976              :    mode of a temp decl of same type as the SSA_NAME, if we had created
     977              :    one.  */
     978              : 
     979              : machine_mode
     980     80228699 : promote_ssa_mode (const_tree name, int *punsignedp)
     981              : {
     982     80228699 :   gcc_assert (TREE_CODE (name) == SSA_NAME);
     983              : 
     984              :   /* Partitions holding parms and results must be promoted as expected
     985              :      by function.cc.  */
     986     80228699 :   if (SSA_NAME_VAR (name)
     987     21557478 :       && (TREE_CODE (SSA_NAME_VAR (name)) == PARM_DECL
     988     16895424 :           || TREE_CODE (SSA_NAME_VAR (name)) == RESULT_DECL))
     989              :     {
     990      8268549 :       machine_mode mode = promote_decl_mode (SSA_NAME_VAR (name), punsignedp);
     991      8268549 :       if (mode != BLKmode)
     992              :         return mode;
     993              :     }
     994              : 
     995     71960252 :   tree type = TREE_TYPE (name);
     996     71960252 :   int unsignedp = TYPE_UNSIGNED (type);
     997     71960252 :   machine_mode pmode = promote_mode (type, TYPE_MODE (type), &unsignedp);
     998     71960252 :   if (punsignedp)
     999      2065287 :     *punsignedp = unsignedp;
    1000              : 
    1001              :   return pmode;
    1002              : }
    1003              : 
    1004              : 
    1005              : 
    1006              : /* Controls the behavior of {anti_,}adjust_stack.  */
    1007              : static bool suppress_reg_args_size;
    1008              : 
    1009              : /* A helper for adjust_stack and anti_adjust_stack.  */
    1010              : 
    1011              : static void
    1012      1930716 : adjust_stack_1 (rtx adjust, bool anti_p)
    1013              : {
    1014      1930716 :   rtx temp;
    1015      1930716 :   rtx_insn *insn;
    1016              : 
    1017              :   /* Hereafter anti_p means subtract_p.  */
    1018      1930716 :   if (!STACK_GROWS_DOWNWARD)
    1019              :     anti_p = !anti_p;
    1020              : 
    1021      4072416 :   temp = expand_binop (Pmode,
    1022              :                        anti_p ? sub_optab : add_optab,
    1023              :                        stack_pointer_rtx, adjust, stack_pointer_rtx, 0,
    1024              :                        OPTAB_LIB_WIDEN);
    1025              : 
    1026      1930716 :   if (temp != stack_pointer_rtx)
    1027            0 :     insn = emit_move_insn (stack_pointer_rtx, temp);
    1028              :   else
    1029              :     {
    1030      1930716 :       insn = get_last_insn ();
    1031      1930716 :       temp = single_set (insn);
    1032      1930716 :       gcc_assert (temp != NULL && SET_DEST (temp) == stack_pointer_rtx);
    1033              :     }
    1034              : 
    1035      1930716 :   if (!suppress_reg_args_size)
    1036      1902751 :     add_args_size_note (insn, stack_pointer_delta);
    1037      1930716 : }
    1038              : 
    1039              : /* Adjust the stack pointer by ADJUST (an rtx for a number of bytes).
    1040              :    This pops when ADJUST is positive.  ADJUST need not be constant.  */
    1041              : 
    1042              : void
    1043       879496 : adjust_stack (rtx adjust)
    1044              : {
    1045       879496 :   if (adjust == const0_rtx)
    1046       879496 :     return;
    1047              : 
    1048              :   /* We expect all variable sized adjustments to be multiple of
    1049              :      PREFERRED_STACK_BOUNDARY.  */
    1050       879496 :   poly_int64 const_adjust;
    1051       879496 :   if (poly_int_rtx_p (adjust, &const_adjust))
    1052       879496 :     stack_pointer_delta -= const_adjust;
    1053              : 
    1054       879496 :   adjust_stack_1 (adjust, false);
    1055              : }
    1056              : 
    1057              : /* Adjust the stack pointer by minus ADJUST (an rtx for a number of bytes).
    1058              :    This pushes when ADJUST is positive.  ADJUST need not be constant.  */
    1059              : 
    1060              : void
    1061      3268196 : anti_adjust_stack (rtx adjust)
    1062              : {
    1063      3268196 :   if (adjust == const0_rtx)
    1064      3268196 :     return;
    1065              : 
    1066              :   /* We expect all variable sized adjustments to be multiple of
    1067              :      PREFERRED_STACK_BOUNDARY.  */
    1068      1051220 :   poly_int64 const_adjust;
    1069      1051220 :   if (poly_int_rtx_p (adjust, &const_adjust))
    1070      1051220 :     stack_pointer_delta += const_adjust;
    1071              : 
    1072      1051220 :   adjust_stack_1 (adjust, true);
    1073              : }
    1074              : 
    1075              : /* Round the size of a block to be pushed up to the boundary required
    1076              :    by this machine.  SIZE is the desired size, which need not be constant.  */
    1077              : 
    1078              : static rtx
    1079        27922 : round_push (rtx size)
    1080              : {
    1081        27922 :   rtx align_rtx, alignm1_rtx;
    1082              : 
    1083        27922 :   if (!SUPPORTS_STACK_ALIGNMENT
    1084        27922 :       || crtl->preferred_stack_boundary == MAX_SUPPORTED_STACK_ALIGNMENT)
    1085              :     {
    1086            0 :       int align = crtl->preferred_stack_boundary / BITS_PER_UNIT;
    1087              : 
    1088            0 :       if (align == 1)
    1089              :         return size;
    1090              : 
    1091            0 :       if (CONST_INT_P (size))
    1092              :         {
    1093            0 :           HOST_WIDE_INT new_size = (INTVAL (size) + align - 1) / align * align;
    1094              : 
    1095            0 :           if (INTVAL (size) != new_size)
    1096            0 :             size = GEN_INT (new_size);
    1097            0 :           return size;
    1098              :         }
    1099              : 
    1100            0 :       align_rtx = GEN_INT (align);
    1101            0 :       alignm1_rtx = GEN_INT (align - 1);
    1102              :     }
    1103              :   else
    1104              :     {
    1105              :       /* If crtl->preferred_stack_boundary might still grow, use
    1106              :          virtual_preferred_stack_boundary_rtx instead.  This will be
    1107              :          substituted by the right value in vregs pass and optimized
    1108              :          during combine.  */
    1109        27922 :       align_rtx = virtual_preferred_stack_boundary_rtx;
    1110        28605 :       alignm1_rtx = force_operand (plus_constant (Pmode, align_rtx, -1),
    1111              :                                    NULL_RTX);
    1112              :     }
    1113              : 
    1114              :   /* CEIL_DIV_EXPR needs to worry about the addition overflowing,
    1115              :      but we know it can't.  So add ourselves and then do
    1116              :      TRUNC_DIV_EXPR.  */
    1117        28605 :   size = expand_binop (Pmode, add_optab, size, alignm1_rtx,
    1118              :                        NULL_RTX, 1, OPTAB_LIB_WIDEN);
    1119        28605 :   size = expand_divmod (0, TRUNC_DIV_EXPR, Pmode, size, align_rtx,
    1120              :                         NULL_RTX, 1);
    1121        27922 :   size = expand_mult (Pmode, size, align_rtx, NULL_RTX, 1);
    1122              : 
    1123        27922 :   return size;
    1124              : }
    1125              : 
    1126              : /* Save the stack pointer for the purpose in SAVE_LEVEL.  PSAVE is a pointer
    1127              :    to a previously-created save area.  If no save area has been allocated,
    1128              :    this function will allocate one.  If a save area is specified, it
    1129              :    must be of the proper mode.  */
    1130              : 
    1131              : void
    1132         3695 : emit_stack_save (enum save_level save_level, rtx *psave)
    1133              : {
    1134         3695 :   rtx sa = *psave;
    1135              :   /* The default is that we use a move insn and save in a Pmode object.  */
    1136         3695 :   rtx_insn *(*fcn) (rtx, rtx) = gen_move_insn;
    1137         3695 :   machine_mode mode = STACK_SAVEAREA_MODE (save_level);
    1138              : 
    1139              :   /* See if this machine has anything special to do for this kind of save.  */
    1140         3695 :   switch (save_level)
    1141              :     {
    1142         1976 :     case SAVE_BLOCK:
    1143         1976 :       if (targetm.have_save_stack_block ())
    1144            0 :         fcn = targetm.gen_save_stack_block;
    1145              :       break;
    1146            0 :     case SAVE_FUNCTION:
    1147            0 :       if (targetm.have_save_stack_function ())
    1148            0 :         fcn = targetm.gen_save_stack_function;
    1149              :       break;
    1150         1719 :     case SAVE_NONLOCAL:
    1151         1719 :       if (targetm.have_save_stack_nonlocal ())
    1152         1719 :         fcn = targetm.gen_save_stack_nonlocal;
    1153              :       break;
    1154              :     default:
    1155              :       break;
    1156              :     }
    1157              : 
    1158              :   /* If there is no save area and we have to allocate one, do so.  Otherwise
    1159              :      verify the save area is the proper mode.  */
    1160              : 
    1161         3695 :   if (sa == 0)
    1162              :     {
    1163         2459 :       if (mode != VOIDmode)
    1164              :         {
    1165         2459 :           if (save_level == SAVE_NONLOCAL)
    1166          966 :             *psave = sa = assign_stack_local (mode, GET_MODE_SIZE (mode), 0);
    1167              :           else
    1168         1976 :             *psave = sa = gen_reg_rtx (mode);
    1169              :         }
    1170              :     }
    1171              : 
    1172         2459 :   do_pending_stack_adjust ();
    1173         3695 :   if (sa != 0)
    1174         3695 :     sa = validize_mem (sa);
    1175         3695 :   emit_insn (fcn (sa, stack_pointer_rtx));
    1176         3695 : }
    1177              : 
    1178              : /* Restore the stack pointer for the purpose in SAVE_LEVEL.  SA is the save
    1179              :    area made by emit_stack_save.  If it is zero, we have nothing to do.  */
    1180              : 
    1181              : void
    1182         3261 : emit_stack_restore (enum save_level save_level, rtx sa)
    1183              : {
    1184              :   /* The default is that we use a move insn.  */
    1185         3261 :   rtx_insn *(*fcn) (rtx, rtx) = gen_move_insn;
    1186              : 
    1187              :   /* If stack_realign_drap, the x86 backend emits a prologue that aligns both
    1188              :      STACK_POINTER and HARD_FRAME_POINTER.
    1189              :      If stack_realign_fp, the x86 backend emits a prologue that aligns only
    1190              :      STACK_POINTER. This renders the HARD_FRAME_POINTER unusable for accessing
    1191              :      aligned variables, which is reflected in ix86_can_eliminate.
    1192              :      We normally still have the realigned STACK_POINTER that we can use.
    1193              :      But if there is a stack restore still present at reload, it can trigger
    1194              :      mark_not_eliminable for the STACK_POINTER, leaving no way to eliminate
    1195              :      FRAME_POINTER into a hard reg.
    1196              :      To prevent this situation, we force need_drap if we emit a stack
    1197              :      restore.  */
    1198         3261 :   if (SUPPORTS_STACK_ALIGNMENT)
    1199         3261 :     crtl->need_drap = true;
    1200              : 
    1201              :   /* See if this machine has anything special to do for this kind of save.  */
    1202         3261 :   switch (save_level)
    1203              :     {
    1204         1875 :     case SAVE_BLOCK:
    1205         1875 :       if (targetm.have_restore_stack_block ())
    1206            0 :         fcn = targetm.gen_restore_stack_block;
    1207              :       break;
    1208            0 :     case SAVE_FUNCTION:
    1209            0 :       if (targetm.have_restore_stack_function ())
    1210            0 :         fcn = targetm.gen_restore_stack_function;
    1211              :       break;
    1212         1386 :     case SAVE_NONLOCAL:
    1213         1386 :       if (targetm.have_restore_stack_nonlocal ())
    1214         1386 :         fcn = targetm.gen_restore_stack_nonlocal;
    1215              :       break;
    1216              :     default:
    1217              :       break;
    1218              :     }
    1219              : 
    1220         3261 :   if (sa != 0)
    1221              :     {
    1222         3261 :       sa = validize_mem (sa);
    1223              :       /* These clobbers prevent the scheduler from moving
    1224              :          references to variable arrays below the code
    1225              :          that deletes (pops) the arrays.  */
    1226         3261 :       emit_clobber (gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (VOIDmode)));
    1227         3261 :       emit_clobber (gen_rtx_MEM (BLKmode, stack_pointer_rtx));
    1228              :     }
    1229              : 
    1230         3261 :   discard_pending_stack_adjust ();
    1231              : 
    1232         3261 :   emit_insn (fcn (stack_pointer_rtx, sa));
    1233         3261 : }
    1234              : 
    1235              : /* Invoke emit_stack_save on the nonlocal_goto_save_area for the current
    1236              :    function.  This should be called whenever we allocate or deallocate
    1237              :    dynamic stack space.  */
    1238              : 
    1239              : void
    1240          395 : update_nonlocal_goto_save_area (void)
    1241              : {
    1242          395 :   tree t_save;
    1243          395 :   rtx r_save;
    1244              : 
    1245              :   /* The nonlocal_goto_save_area object is an array of N pointers.  The
    1246              :      first one is used for the frame pointer save; the rest are sized by
    1247              :      STACK_SAVEAREA_MODE.  Create a reference to array index 1, the first
    1248              :      of the stack save area slots.  */
    1249          395 :   t_save = build4 (ARRAY_REF,
    1250          395 :                    TREE_TYPE (TREE_TYPE (cfun->nonlocal_goto_save_area)),
    1251          395 :                    cfun->nonlocal_goto_save_area,
    1252              :                    integer_one_node, NULL_TREE, NULL_TREE);
    1253          395 :   r_save = expand_expr (t_save, NULL_RTX, VOIDmode, EXPAND_WRITE);
    1254              : 
    1255          395 :   emit_stack_save (SAVE_NONLOCAL, &r_save);
    1256          395 : }
    1257              : 
    1258              : /* Record a new stack level for the current function.  This should be called
    1259              :    whenever we allocate or deallocate dynamic stack space.  */
    1260              : 
    1261              : void
    1262        29668 : record_new_stack_level (void)
    1263              : {
    1264              :   /* Record the new stack level for nonlocal gotos.  */
    1265        29668 :   if (cfun->nonlocal_goto_save_area)
    1266            2 :     update_nonlocal_goto_save_area ();
    1267              : 
    1268              :   /* Record the new stack level for SJLJ exceptions.  */
    1269        29668 :   if (targetm_common.except_unwind_info (&global_options) == UI_SJLJ)
    1270            0 :     update_sjlj_context ();
    1271        29668 : }
    1272              : 
    1273              : /* Return an rtx doing runtime alignment to REQUIRED_ALIGN on TARGET.  */
    1274              : 
    1275              : rtx
    1276        27922 : align_dynamic_address (rtx target, unsigned required_align)
    1277              : {
    1278        27922 :   if (required_align == BITS_PER_UNIT)
    1279              :     return target;
    1280              : 
    1281              :   /* CEIL_DIV_EXPR needs to worry about the addition overflowing,
    1282              :      but we know it can't.  So add ourselves and then do
    1283              :      TRUNC_DIV_EXPR.  */
    1284        27100 :   target = expand_binop (Pmode, add_optab, target,
    1285        26439 :                          gen_int_mode (required_align / BITS_PER_UNIT - 1,
    1286        26439 :                                        Pmode),
    1287              :                          NULL_RTX, 1, OPTAB_LIB_WIDEN);
    1288        27100 :   target = expand_divmod (0, TRUNC_DIV_EXPR, Pmode, target,
    1289        26439 :                           gen_int_mode (required_align / BITS_PER_UNIT,
    1290        26439 :                                         Pmode),
    1291              :                           NULL_RTX, 1);
    1292        27100 :   target = expand_mult (Pmode, target,
    1293        26439 :                         gen_int_mode (required_align / BITS_PER_UNIT,
    1294        26439 :                                       Pmode),
    1295              :                         NULL_RTX, 1);
    1296              : 
    1297        26439 :   return target;
    1298              : }
    1299              : 
    1300              : /* Return an rtx through *PSIZE, representing the size of an area of memory to
    1301              :    be dynamically pushed on the stack.
    1302              : 
    1303              :    *PSIZE is an rtx representing the size of the area.
    1304              : 
    1305              :    SIZE_ALIGN is the alignment (in bits) that we know SIZE has.  This
    1306              :    parameter may be zero.  If so, a proper value will be extracted
    1307              :    from SIZE if it is constant, otherwise BITS_PER_UNIT will be assumed.
    1308              : 
    1309              :    REQUIRED_ALIGN is the alignment (in bits) required for the region
    1310              :    of memory.
    1311              : 
    1312              :    If PSTACK_USAGE_SIZE is not NULL it points to a value that is increased for
    1313              :    the additional size returned.  */
    1314              : void
    1315        27922 : get_dynamic_stack_size (rtx *psize, unsigned size_align,
    1316              :                         unsigned required_align,
    1317              :                         HOST_WIDE_INT *pstack_usage_size)
    1318              : {
    1319        27922 :   rtx size = *psize;
    1320              : 
    1321              :   /* Ensure the size is in the proper mode.  */
    1322        28551 :   if (GET_MODE (size) != VOIDmode && GET_MODE (size) != Pmode)
    1323        12399 :     size = convert_to_mode (Pmode, size, 1);
    1324              : 
    1325        27922 :   if (CONST_INT_P (size))
    1326              :     {
    1327         4404 :       unsigned HOST_WIDE_INT lsb;
    1328              : 
    1329         4404 :       lsb = INTVAL (size);
    1330         4404 :       lsb &= -lsb;
    1331              : 
    1332              :       /* Watch out for overflow truncating to "unsigned".  */
    1333         4404 :       if (lsb > UINT_MAX / BITS_PER_UNIT)
    1334              :         size_align = 1u << (HOST_BITS_PER_INT - 1);
    1335              :       else
    1336         4404 :         size_align = (unsigned)lsb * BITS_PER_UNIT;
    1337              :     }
    1338        23518 :   else if (size_align < BITS_PER_UNIT)
    1339              :     size_align = BITS_PER_UNIT;
    1340              : 
    1341              :   /* We can't attempt to minimize alignment necessary, because we don't
    1342              :      know the final value of preferred_stack_boundary yet while executing
    1343              :      this code.  */
    1344        27922 :   if (crtl->preferred_stack_boundary < PREFERRED_STACK_BOUNDARY)
    1345         7236 :     crtl->preferred_stack_boundary = PREFERRED_STACK_BOUNDARY;
    1346              : 
    1347              :   /* We will need to ensure that the address we return is aligned to
    1348              :      REQUIRED_ALIGN.  At this point in the compilation, we don't always
    1349              :      know the final value of the STACK_DYNAMIC_OFFSET used in function.cc
    1350              :      (it might depend on the size of the outgoing parameter lists, for
    1351              :      example), so we must preventively align the value.  We leave space
    1352              :      in SIZE for the hole that might result from the alignment operation.  */
    1353              : 
    1354        27922 :   unsigned known_align = REGNO_POINTER_ALIGN (VIRTUAL_STACK_DYNAMIC_REGNUM);
    1355        27922 :   if (known_align == 0)
    1356            0 :     known_align = BITS_PER_UNIT;
    1357        27922 :   if (required_align > known_align)
    1358              :     {
    1359        17619 :       unsigned extra = (required_align - known_align) / BITS_PER_UNIT;
    1360        18236 :       size = plus_constant (Pmode, size, extra);
    1361        17619 :       size = force_operand (size, NULL_RTX);
    1362        17619 :       if (size_align > known_align)
    1363              :         size_align = known_align;
    1364              : 
    1365        17619 :       if (flag_stack_usage_info && pstack_usage_size)
    1366            0 :         *pstack_usage_size += extra;
    1367              :     }
    1368              : 
    1369              :   /* Round the size to a multiple of the required stack alignment.
    1370              :      Since the stack is presumed to be rounded before this allocation,
    1371              :      this will maintain the required alignment.
    1372              : 
    1373              :      If the stack grows downward, we could save an insn by subtracting
    1374              :      SIZE from the stack pointer and then aligning the stack pointer.
    1375              :      The problem with this is that the stack pointer may be unaligned
    1376              :      between the execution of the subtraction and alignment insns and
    1377              :      some machines do not allow this.  Even on those that do, some
    1378              :      signal handlers malfunction if a signal should occur between those
    1379              :      insns.  Since this is an extremely rare event, we have no reliable
    1380              :      way of knowing which systems have this problem.  So we avoid even
    1381              :      momentarily mis-aligning the stack.  */
    1382        27922 :   if (size_align % MAX_SUPPORTED_STACK_ALIGNMENT != 0)
    1383              :     {
    1384        27922 :       size = round_push (size);
    1385              : 
    1386        27922 :       if (flag_stack_usage_info && pstack_usage_size)
    1387              :         {
    1388            1 :           int align = crtl->preferred_stack_boundary / BITS_PER_UNIT;
    1389            1 :           *pstack_usage_size =
    1390            1 :             (*pstack_usage_size + align - 1) / align * align;
    1391              :         }
    1392              :     }
    1393              : 
    1394        27922 :   *psize = size;
    1395        27922 : }
    1396              : 
    1397              : /* Return the number of bytes to "protect" on the stack for -fstack-check.
    1398              : 
    1399              :    "protect" in the context of -fstack-check means how many bytes we need
    1400              :    to always ensure are available on the stack; as a consequence, this is
    1401              :    also how many bytes are first skipped when probing the stack.
    1402              : 
    1403              :    On some targets we want to reuse the -fstack-check prologue support
    1404              :    to give a degree of protection against stack clashing style attacks.
    1405              : 
    1406              :    In that scenario we do not want to skip bytes before probing as that
    1407              :    would render the stack clash protections useless.
    1408              : 
    1409              :    So we never use STACK_CHECK_PROTECT directly.  Instead we indirectly
    1410              :    use it through this helper, which allows to provide different values
    1411              :    for -fstack-check and -fstack-clash-protection.  */
    1412              : 
    1413              : HOST_WIDE_INT
    1414            0 : get_stack_check_protect (void)
    1415              : {
    1416            0 :   if (flag_stack_clash_protection)
    1417              :     return 0;
    1418              : 
    1419            0 :  return STACK_CHECK_PROTECT;
    1420              : }
    1421              : 
    1422              : /* Return an rtx representing the address of an area of memory dynamically
    1423              :    pushed on the stack.
    1424              : 
    1425              :    Any required stack pointer alignment is preserved.
    1426              : 
    1427              :    SIZE is an rtx representing the size of the area.
    1428              : 
    1429              :    SIZE_ALIGN is the alignment (in bits) that we know SIZE has.  This
    1430              :    parameter may be zero.  If so, a proper value will be extracted
    1431              :    from SIZE if it is constant, otherwise BITS_PER_UNIT will be assumed.
    1432              : 
    1433              :    REQUIRED_ALIGN is the alignment (in bits) required for the region
    1434              :    of memory.
    1435              : 
    1436              :    MAX_SIZE is an upper bound for SIZE, if SIZE is not constant, or -1 if
    1437              :    no such upper bound is known.
    1438              : 
    1439              :    If CANNOT_ACCUMULATE is set to TRUE, the caller guarantees that the
    1440              :    stack space allocated by the generated code cannot be added with itself
    1441              :    in the course of the execution of the function.  It is always safe to
    1442              :    pass FALSE here and the following criterion is sufficient in order to
    1443              :    pass TRUE: every path in the CFG that starts at the allocation point and
    1444              :    loops to it executes the associated deallocation code.  */
    1445              : 
    1446              : rtx
    1447        28216 : allocate_dynamic_stack_space (rtx size, unsigned size_align,
    1448              :                               unsigned required_align,
    1449              :                               HOST_WIDE_INT max_size,
    1450              :                               bool cannot_accumulate)
    1451              : {
    1452        28216 :   HOST_WIDE_INT stack_usage_size = -1;
    1453        28216 :   rtx_code_label *final_label;
    1454        28216 :   rtx final_target, target;
    1455        28216 :   rtx addr = (virtuals_instantiated
    1456        28216 :               ? plus_constant (Pmode, stack_pointer_rtx,
    1457              :                                get_stack_dynamic_offset ())
    1458        28216 :               : virtual_stack_dynamic_rtx);
    1459              : 
    1460              :   /* If we're asking for zero bytes, it doesn't matter what we point
    1461              :      to since we can't dereference it.  But return a reasonable
    1462              :      address anyway.  */
    1463        28216 :   if (size == const0_rtx)
    1464              :     return addr;
    1465              : 
    1466              :   /* Otherwise, show we're calling alloca or equivalent.  */
    1467        27922 :   cfun->calls_alloca = 1;
    1468              : 
    1469              :   /* If stack usage info is requested, look into the size we are passed.
    1470              :      We need to do so this early to avoid the obfuscation that may be
    1471              :      introduced later by the various alignment operations.  */
    1472        27922 :   if (flag_stack_usage_info)
    1473              :     {
    1474            1 :       if (CONST_INT_P (size))
    1475            0 :         stack_usage_size = INTVAL (size);
    1476            1 :       else if (REG_P (size))
    1477              :         {
    1478              :           /* Look into the last emitted insn and see if we can deduce
    1479              :              something for the register.  */
    1480            1 :           rtx_insn *insn;
    1481            1 :           rtx set, note;
    1482            1 :           insn = get_last_insn ();
    1483            1 :           if ((set = single_set (insn)) && rtx_equal_p (SET_DEST (set), size))
    1484              :             {
    1485            1 :               if (CONST_INT_P (SET_SRC (set)))
    1486            0 :                 stack_usage_size = INTVAL (SET_SRC (set));
    1487            1 :               else if ((note = find_reg_equal_equiv_note (insn))
    1488            1 :                        && CONST_INT_P (XEXP (note, 0)))
    1489            0 :                 stack_usage_size = INTVAL (XEXP (note, 0));
    1490              :             }
    1491              :         }
    1492              : 
    1493              :       /* If the size is not constant, try the maximum size.  */
    1494            1 :       if (stack_usage_size < 0)
    1495            1 :         stack_usage_size = max_size;
    1496              : 
    1497              :       /* If the size is still not constant, we can't say anything.  */
    1498            1 :       if (stack_usage_size < 0)
    1499              :         {
    1500            1 :           current_function_has_unbounded_dynamic_stack_size = 1;
    1501            1 :           stack_usage_size = 0;
    1502              :         }
    1503              :     }
    1504              : 
    1505        27922 :   get_dynamic_stack_size (&size, size_align, required_align, &stack_usage_size);
    1506              : 
    1507        28605 :   target = gen_reg_rtx (Pmode);
    1508              : 
    1509              :   /* The size is supposed to be fully adjusted at this point so record it
    1510              :      if stack usage info is requested.  */
    1511        27922 :   if (flag_stack_usage_info)
    1512              :     {
    1513            1 :       current_function_dynamic_stack_size += stack_usage_size;
    1514              : 
    1515              :       /* ??? This is gross but the only safe stance in the absence
    1516              :          of stack usage oriented flow analysis.  */
    1517            1 :       if (!cannot_accumulate)
    1518            0 :         current_function_has_unbounded_dynamic_stack_size = 1;
    1519              :     }
    1520              : 
    1521        27922 :   do_pending_stack_adjust ();
    1522              : 
    1523        27922 :   final_label = NULL;
    1524        27922 :   final_target = NULL_RTX;
    1525              : 
    1526              :   /* If we are splitting the stack, we need to ask the backend whether
    1527              :      there is enough room on the current stack.  If there isn't, or if
    1528              :      the backend doesn't know how to tell is, then we need to call a
    1529              :      function to allocate memory in some other way.  This memory will
    1530              :      be released when we release the current stack segment.  The
    1531              :      effect is that stack allocation becomes less efficient, but at
    1532              :      least it doesn't cause a stack overflow.  */
    1533        27922 :   if (flag_split_stack)
    1534              :     {
    1535           10 :       rtx_code_label *available_label;
    1536           10 :       rtx ask, space, func;
    1537              : 
    1538           10 :       available_label = NULL;
    1539              : 
    1540           10 :       if (targetm.have_split_stack_space_check ())
    1541              :         {
    1542           10 :           available_label = gen_label_rtx ();
    1543              : 
    1544              :           /* This instruction will branch to AVAILABLE_LABEL if there
    1545              :              are SIZE bytes available on the stack.  */
    1546           10 :           emit_insn (targetm.gen_split_stack_space_check
    1547           10 :                      (size, available_label));
    1548              :         }
    1549              : 
    1550              :       /* The __morestack_allocate_stack_space function will allocate
    1551              :          memory using malloc.  If the alignment of the memory returned
    1552              :          by malloc does not meet REQUIRED_ALIGN, we increase SIZE to
    1553              :          make sure we allocate enough space.  */
    1554           10 :       if (MALLOC_ABI_ALIGNMENT >= required_align)
    1555            6 :         ask = size;
    1556              :       else
    1557            4 :         ask = expand_binop (Pmode, add_optab, size,
    1558            4 :                             gen_int_mode (required_align / BITS_PER_UNIT - 1,
    1559            4 :                                           Pmode),
    1560              :                             NULL_RTX, 1, OPTAB_LIB_WIDEN);
    1561              : 
    1562           10 :       func = init_one_libfunc ("__morestack_allocate_stack_space");
    1563              : 
    1564           10 :       space = emit_library_call_value (func, target, LCT_NORMAL, Pmode,
    1565           10 :                                        ask, Pmode);
    1566              : 
    1567           10 :       if (available_label == NULL_RTX)
    1568              :         return space;
    1569              : 
    1570           10 :       final_target = gen_reg_rtx (Pmode);
    1571              : 
    1572           10 :       emit_move_insn (final_target, space);
    1573              : 
    1574           10 :       final_label = gen_label_rtx ();
    1575           10 :       emit_jump (final_label);
    1576              : 
    1577           10 :       emit_label (available_label);
    1578              :     }
    1579              : 
    1580              :  /* We ought to be called always on the toplevel and stack ought to be aligned
    1581              :     properly.  */
    1582        55844 :   gcc_assert (multiple_p (stack_pointer_delta,
    1583              :                           PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT));
    1584              : 
    1585              :   /* If needed, check that we have the required amount of stack.  Take into
    1586              :      account what has already been checked.  */
    1587        27922 :   if (STACK_CHECK_MOVING_SP)
    1588              :     ;
    1589              :   else if (flag_stack_check == GENERIC_STACK_CHECK)
    1590              :     probe_stack_range (STACK_OLD_CHECK_PROTECT + STACK_CHECK_MAX_FRAME_SIZE,
    1591              :                        size);
    1592              :   else if (flag_stack_check == STATIC_BUILTIN_STACK_CHECK)
    1593              :     probe_stack_range (get_stack_check_protect (), size);
    1594              : 
    1595              :   /* Don't let anti_adjust_stack emit notes.  */
    1596        27922 :   suppress_reg_args_size = true;
    1597              : 
    1598              :   /* Perform the required allocation from the stack.  Some systems do
    1599              :      this differently than simply incrementing/decrementing from the
    1600              :      stack pointer, such as acquiring the space by calling malloc().  */
    1601        27922 :   if (targetm.have_allocate_stack ())
    1602              :     {
    1603            0 :       class expand_operand ops[2];
    1604              :       /* We don't have to check against the predicate for operand 0 since
    1605              :          TARGET is known to be a pseudo of the proper mode, which must
    1606              :          be valid for the operand.  */
    1607            0 :       create_fixed_operand (&ops[0], target);
    1608            0 :       create_convert_operand_to (&ops[1], size, STACK_SIZE_MODE, true);
    1609            0 :       expand_insn (targetm.code_for_allocate_stack, 2, ops);
    1610              :     }
    1611              :   else
    1612              :     {
    1613        27922 :       poly_int64 saved_stack_pointer_delta;
    1614              : 
    1615        27922 :       if (!STACK_GROWS_DOWNWARD)
    1616              :         emit_move_insn (target, force_operand (addr, target));
    1617              : 
    1618              :       /* Check stack bounds if necessary.  */
    1619        27922 :       if (crtl->limit_stack)
    1620              :         {
    1621            0 :           rtx available;
    1622            0 :           rtx_code_label *space_available = gen_label_rtx ();
    1623            0 :           if (STACK_GROWS_DOWNWARD)
    1624            0 :             available = expand_binop (Pmode, sub_optab,
    1625              :                                       stack_pointer_rtx, stack_limit_rtx,
    1626              :                                       NULL_RTX, 1, OPTAB_WIDEN);
    1627              :           else
    1628              :             available = expand_binop (Pmode, sub_optab,
    1629              :                                       stack_limit_rtx, stack_pointer_rtx,
    1630              :                                       NULL_RTX, 1, OPTAB_WIDEN);
    1631              : 
    1632            0 :           emit_cmp_and_jump_insns (available, size, GEU, NULL_RTX, Pmode, 1,
    1633              :                                    space_available);
    1634            0 :           if (targetm.have_trap ())
    1635            0 :             emit_insn (targetm.gen_trap ());
    1636              :           else
    1637            0 :             error ("stack limits not supported on this target");
    1638            0 :           emit_barrier ();
    1639            0 :           emit_label (space_available);
    1640              :         }
    1641              : 
    1642        27922 :       saved_stack_pointer_delta = stack_pointer_delta;
    1643              : 
    1644              :       /* If stack checking or stack clash protection is requested,
    1645              :          then probe the stack while allocating space from it.  */
    1646        27922 :       if (flag_stack_check && STACK_CHECK_MOVING_SP)
    1647            9 :         anti_adjust_stack_and_probe (size, false);
    1648        27913 :       else if (flag_stack_clash_protection)
    1649           16 :         anti_adjust_stack_and_probe_stack_clash (size);
    1650              :       else
    1651        27897 :         anti_adjust_stack (size);
    1652              : 
    1653              :       /* Even if size is constant, don't modify stack_pointer_delta.
    1654              :          The constant size alloca should preserve
    1655              :          crtl->preferred_stack_boundary alignment.  */
    1656        27922 :       stack_pointer_delta = saved_stack_pointer_delta;
    1657              : 
    1658        27922 :       if (STACK_GROWS_DOWNWARD)
    1659        27922 :         emit_move_insn (target, force_operand (addr, target));
    1660              :     }
    1661              : 
    1662        27922 :   suppress_reg_args_size = false;
    1663              : 
    1664              :   /* Finish up the split stack handling.  */
    1665        27922 :   if (final_label != NULL_RTX)
    1666              :     {
    1667           10 :       gcc_assert (flag_split_stack);
    1668           10 :       emit_move_insn (final_target, target);
    1669           10 :       emit_label (final_label);
    1670           10 :       target = final_target;
    1671              :     }
    1672              : 
    1673        27922 :   target = align_dynamic_address (target, required_align);
    1674              : 
    1675              :   /* Now that we've committed to a return value, mark its alignment.  */
    1676        27922 :   mark_reg_pointer (target, required_align);
    1677              : 
    1678              :   /* Record the new stack level.  */
    1679        27922 :   record_new_stack_level ();
    1680              : 
    1681        27922 :   return target;
    1682              : }
    1683              : 
    1684              : /* Return an rtx representing the address of an area of memory already
    1685              :    statically pushed onto the stack in the virtual stack vars area.  (It is
    1686              :    assumed that the area is allocated in the function prologue.)
    1687              : 
    1688              :    Any required stack pointer alignment is preserved.
    1689              : 
    1690              :    OFFSET is the offset of the area into the virtual stack vars area.
    1691              : 
    1692              :    REQUIRED_ALIGN is the alignment (in bits) required for the region
    1693              :    of memory.
    1694              : 
    1695              :    BASE is the rtx of the base of this virtual stack vars area.
    1696              :    The only time this is not `virtual_stack_vars_rtx` is when tagging pointers
    1697              :    on the stack.  */
    1698              : 
    1699              : rtx
    1700            0 : get_dynamic_stack_base (poly_int64 offset, unsigned required_align, rtx base)
    1701              : {
    1702            0 :   rtx target;
    1703              : 
    1704            0 :   if (crtl->preferred_stack_boundary < PREFERRED_STACK_BOUNDARY)
    1705            0 :     crtl->preferred_stack_boundary = PREFERRED_STACK_BOUNDARY;
    1706              : 
    1707            0 :   target = gen_reg_rtx (Pmode);
    1708            0 :   emit_move_insn (target, base);
    1709            0 :   target = expand_binop (Pmode, add_optab, target,
    1710            0 :                          gen_int_mode (offset, Pmode),
    1711              :                          NULL_RTX, 1, OPTAB_LIB_WIDEN);
    1712            0 :   target = align_dynamic_address (target, required_align);
    1713              : 
    1714              :   /* Now that we've committed to a return value, mark its alignment.  */
    1715            0 :   mark_reg_pointer (target, required_align);
    1716              : 
    1717            0 :   return target;
    1718              : }
    1719              : 
    1720              : /* A front end may want to override GCC's stack checking by providing a
    1721              :    run-time routine to call to check the stack, so provide a mechanism for
    1722              :    calling that routine.  */
    1723              : 
    1724              : static GTY(()) rtx stack_check_libfunc;
    1725              : 
    1726              : void
    1727            0 : set_stack_check_libfunc (const char *libfunc_name)
    1728              : {
    1729            0 :   gcc_assert (stack_check_libfunc == NULL_RTX);
    1730            0 :   stack_check_libfunc = gen_rtx_SYMBOL_REF (Pmode, libfunc_name);
    1731            0 :   tree ptype
    1732            0 :     = Pmode == ptr_mode
    1733            0 :       ? ptr_type_node
    1734            0 :       : lang_hooks.types.type_for_mode (Pmode, 1);
    1735            0 :   tree ftype
    1736            0 :     = build_function_type_list (void_type_node, ptype, NULL_TREE);
    1737            0 :   tree decl = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL,
    1738              :                           get_identifier (libfunc_name), ftype);
    1739            0 :   DECL_EXTERNAL (decl) = 1;
    1740            0 :   SET_SYMBOL_REF_DECL (stack_check_libfunc, decl);
    1741            0 : }
    1742              : 
    1743              : /* Emit one stack probe at ADDRESS, an address within the stack.  */
    1744              : 
    1745              : void
    1746          133 : emit_stack_probe (rtx address)
    1747              : {
    1748          133 :   if (targetm.have_probe_stack_address ())
    1749              :     {
    1750            0 :       class expand_operand ops[1];
    1751            0 :       insn_code icode = targetm.code_for_probe_stack_address;
    1752            0 :       create_address_operand (ops, address);
    1753            0 :       maybe_legitimize_operands (icode, 0, 1, ops);
    1754            0 :       expand_insn (icode, 1, ops);
    1755              :     }
    1756              :   else
    1757              :     {
    1758          133 :       rtx memref = gen_rtx_MEM (word_mode, address);
    1759              : 
    1760          133 :       MEM_VOLATILE_P (memref) = 1;
    1761          133 :       memref = validize_mem (memref);
    1762              : 
    1763              :       /* See if we have an insn to probe the stack.  */
    1764          133 :       if (targetm.have_probe_stack ())
    1765          133 :         emit_insn (targetm.gen_probe_stack (memref));
    1766              :       else
    1767            0 :         emit_move_insn (memref, const0_rtx);
    1768              :     }
    1769          133 : }
    1770              : 
    1771              : /* Probe a range of stack addresses from FIRST to FIRST+SIZE, inclusive.
    1772              :    FIRST is a constant and size is a Pmode RTX.  These are offsets from
    1773              :    the current stack pointer.  STACK_GROWS_DOWNWARD says whether to add
    1774              :    or subtract them from the stack pointer.  */
    1775              : 
    1776              : #define PROBE_INTERVAL (1 << STACK_CHECK_PROBE_INTERVAL_EXP)
    1777              : 
    1778              : #if STACK_GROWS_DOWNWARD
    1779              : #define STACK_GROW_OP MINUS
    1780              : #define STACK_GROW_OPTAB sub_optab
    1781              : #define STACK_GROW_OFF(off) -(off)
    1782              : #else
    1783              : #define STACK_GROW_OP PLUS
    1784              : #define STACK_GROW_OPTAB add_optab
    1785              : #define STACK_GROW_OFF(off) (off)
    1786              : #endif
    1787              : 
    1788              : void
    1789            0 : probe_stack_range (HOST_WIDE_INT first, rtx size)
    1790              : {
    1791              :   /* First ensure SIZE is Pmode.  */
    1792            0 :   if (GET_MODE (size) != VOIDmode && GET_MODE (size) != Pmode)
    1793            0 :     size = convert_to_mode (Pmode, size, 1);
    1794              : 
    1795              :   /* Next see if we have a function to check the stack.  */
    1796            0 :   if (stack_check_libfunc)
    1797              :     {
    1798            0 :       rtx addr = memory_address (Pmode,
    1799              :                                  gen_rtx_fmt_ee (STACK_GROW_OP, Pmode,
    1800              :                                                  stack_pointer_rtx,
    1801              :                                                  plus_constant (Pmode,
    1802              :                                                                 size, first)));
    1803            0 :       emit_library_call (stack_check_libfunc, LCT_THROW, VOIDmode,
    1804            0 :                          addr, Pmode);
    1805              :     }
    1806              : 
    1807              :   /* Next see if we have an insn to check the stack.  */
    1808            0 :   else if (targetm.have_check_stack ())
    1809              :     {
    1810            0 :       class expand_operand ops[1];
    1811            0 :       rtx addr = memory_address (Pmode,
    1812              :                                  gen_rtx_fmt_ee (STACK_GROW_OP, Pmode,
    1813              :                                                  stack_pointer_rtx,
    1814              :                                                  plus_constant (Pmode,
    1815              :                                                                 size, first)));
    1816            0 :       bool success;
    1817            0 :       create_input_operand (&ops[0], addr, Pmode);
    1818            0 :       success = maybe_expand_insn (targetm.code_for_check_stack, 1, ops);
    1819            0 :       gcc_assert (success);
    1820              :     }
    1821              : 
    1822              :   /* Otherwise we have to generate explicit probes.  If we have a constant
    1823              :      small number of them to generate, that's the easy case.  */
    1824            0 :   else if (CONST_INT_P (size) && INTVAL (size) < 7 * PROBE_INTERVAL)
    1825              :     {
    1826              :       HOST_WIDE_INT isize = INTVAL (size), i;
    1827              :       rtx addr;
    1828              : 
    1829              :       /* Probe at FIRST + N * PROBE_INTERVAL for values of N from 1 until
    1830              :          it exceeds SIZE.  If only one probe is needed, this will not
    1831              :          generate any code.  Then probe at FIRST + SIZE.  */
    1832            0 :       for (i = PROBE_INTERVAL; i < isize; i += PROBE_INTERVAL)
    1833              :         {
    1834            0 :           addr = memory_address (Pmode,
    1835              :                                  plus_constant (Pmode, stack_pointer_rtx,
    1836              :                                                 STACK_GROW_OFF (first + i)));
    1837            0 :           emit_stack_probe (addr);
    1838              :         }
    1839              : 
    1840            0 :       addr = memory_address (Pmode,
    1841              :                              plus_constant (Pmode, stack_pointer_rtx,
    1842              :                                             STACK_GROW_OFF (first + isize)));
    1843            0 :       emit_stack_probe (addr);
    1844            0 :     }
    1845              : 
    1846              :   /* In the variable case, do the same as above, but in a loop.  Note that we
    1847              :      must be extra careful with variables wrapping around because we might be
    1848              :      at the very top (or the very bottom) of the address space and we have to
    1849              :      be able to handle this case properly; in particular, we use an equality
    1850              :      test for the loop condition.  */
    1851              :   else
    1852              :     {
    1853            0 :       rtx rounded_size, rounded_size_op, test_addr, last_addr, temp;
    1854            0 :       rtx_code_label *loop_lab = gen_label_rtx ();
    1855            0 :       rtx_code_label *end_lab = gen_label_rtx ();
    1856              : 
    1857              :       /* Step 1: round SIZE to the previous multiple of the interval.  */
    1858              : 
    1859              :       /* ROUNDED_SIZE = SIZE & -PROBE_INTERVAL  */
    1860            0 :       rounded_size
    1861            0 :         = simplify_gen_binary (AND, Pmode, size,
    1862            0 :                                gen_int_mode (-PROBE_INTERVAL, Pmode));
    1863            0 :       rounded_size_op = force_operand (rounded_size, NULL_RTX);
    1864              : 
    1865              : 
    1866              :       /* Step 2: compute initial and final value of the loop counter.  */
    1867              : 
    1868              :       /* TEST_ADDR = SP + FIRST.  */
    1869            0 :       test_addr = force_operand (gen_rtx_fmt_ee (STACK_GROW_OP, Pmode,
    1870              :                                                  stack_pointer_rtx,
    1871              :                                                  gen_int_mode (first, Pmode)),
    1872              :                                  NULL_RTX);
    1873              : 
    1874              :       /* LAST_ADDR = SP + FIRST + ROUNDED_SIZE.  */
    1875            0 :       last_addr = force_operand (gen_rtx_fmt_ee (STACK_GROW_OP, Pmode,
    1876              :                                                  test_addr,
    1877              :                                                  rounded_size_op), NULL_RTX);
    1878              : 
    1879              : 
    1880              :       /* Step 3: the loop
    1881              : 
    1882              :          while (TEST_ADDR != LAST_ADDR)
    1883              :            {
    1884              :              TEST_ADDR = TEST_ADDR + PROBE_INTERVAL
    1885              :              probe at TEST_ADDR
    1886              :            }
    1887              : 
    1888              :          probes at FIRST + N * PROBE_INTERVAL for values of N from 1
    1889              :          until it is equal to ROUNDED_SIZE.  */
    1890              : 
    1891            0 :       emit_label (loop_lab);
    1892              : 
    1893              :       /* Jump to END_LAB if TEST_ADDR == LAST_ADDR.  */
    1894            0 :       emit_cmp_and_jump_insns (test_addr, last_addr, EQ, NULL_RTX, Pmode, 1,
    1895              :                                end_lab);
    1896              : 
    1897              :       /* TEST_ADDR = TEST_ADDR + PROBE_INTERVAL.  */
    1898            0 :       temp = expand_binop (Pmode, STACK_GROW_OPTAB, test_addr,
    1899            0 :                            gen_int_mode (PROBE_INTERVAL, Pmode), test_addr,
    1900              :                            1, OPTAB_WIDEN);
    1901              : 
    1902              :       /* There is no guarantee that expand_binop constructs its result
    1903              :          in TEST_ADDR.  So copy into TEST_ADDR if necessary.  */
    1904            0 :       if (temp != test_addr)
    1905            0 :         emit_move_insn (test_addr, temp);
    1906              : 
    1907              :       /* Probe at TEST_ADDR.  */
    1908            0 :       emit_stack_probe (test_addr);
    1909              : 
    1910            0 :       emit_jump (loop_lab);
    1911              : 
    1912            0 :       emit_label (end_lab);
    1913              : 
    1914              : 
    1915              :       /* Step 4: probe at FIRST + SIZE if we cannot assert at compile-time
    1916              :          that SIZE is equal to ROUNDED_SIZE.  */
    1917              : 
    1918              :       /* TEMP = SIZE - ROUNDED_SIZE.  */
    1919            0 :       temp = simplify_gen_binary (MINUS, Pmode, size, rounded_size);
    1920            0 :       if (temp != const0_rtx)
    1921              :         {
    1922            0 :           rtx addr;
    1923              : 
    1924            0 :           if (CONST_INT_P (temp))
    1925              :             {
    1926              :               /* Use [base + disp} addressing mode if supported.  */
    1927            0 :               HOST_WIDE_INT offset = INTVAL (temp);
    1928            0 :               addr = memory_address (Pmode,
    1929              :                                      plus_constant (Pmode, last_addr,
    1930              :                                                     STACK_GROW_OFF (offset)));
    1931              :             }
    1932              :           else
    1933              :             {
    1934              :               /* Manual CSE if the difference is not known at compile-time.  */
    1935            0 :               temp = gen_rtx_MINUS (Pmode, size, rounded_size_op);
    1936            0 :               addr = memory_address (Pmode,
    1937              :                                      gen_rtx_fmt_ee (STACK_GROW_OP, Pmode,
    1938              :                                                      last_addr, temp));
    1939              :             }
    1940              : 
    1941            0 :           emit_stack_probe (addr);
    1942              :         }
    1943              :     }
    1944              : 
    1945              :   /* Make sure nothing is scheduled before we are done.  */
    1946            0 :   emit_insn (gen_blockage ());
    1947            0 : }
    1948              : 
    1949              : /* Compute parameters for stack clash probing a dynamic stack
    1950              :    allocation of SIZE bytes.
    1951              : 
    1952              :    We compute ROUNDED_SIZE, LAST_ADDR, RESIDUAL and PROBE_INTERVAL.
    1953              : 
    1954              :    Additionally we conditionally dump the type of probing that will
    1955              :    be needed given the values computed.  */
    1956              : 
    1957              : void
    1958           16 : compute_stack_clash_protection_loop_data (rtx *rounded_size, rtx *last_addr,
    1959              :                                           rtx *residual,
    1960              :                                           HOST_WIDE_INT *probe_interval,
    1961              :                                           rtx size)
    1962              : {
    1963              :   /* Round SIZE down to STACK_CLASH_PROTECTION_PROBE_INTERVAL */
    1964           16 :   *probe_interval
    1965           16 :     = 1 << param_stack_clash_protection_probe_interval;
    1966           16 :   *rounded_size = simplify_gen_binary (AND, Pmode, size,
    1967              :                                         GEN_INT (-*probe_interval));
    1968              : 
    1969              :   /* Compute the value of the stack pointer for the last iteration.
    1970              :      It's just SP + ROUNDED_SIZE.  */
    1971           16 :   rtx rounded_size_op = force_operand (*rounded_size, NULL_RTX);
    1972           16 :   *last_addr = force_operand (gen_rtx_fmt_ee (STACK_GROW_OP, Pmode,
    1973              :                                               stack_pointer_rtx,
    1974              :                                               rounded_size_op),
    1975              :                               NULL_RTX);
    1976              : 
    1977              :   /* Compute any residuals not allocated by the loop above.  Residuals
    1978              :      are just the ROUNDED_SIZE - SIZE.  */
    1979           16 :   *residual = simplify_gen_binary (MINUS, Pmode, size, *rounded_size);
    1980              : 
    1981              :   /* Dump key information to make writing tests easy.  */
    1982           16 :   if (dump_file)
    1983              :     {
    1984            9 :       if (*rounded_size == CONST0_RTX (Pmode))
    1985            0 :         fprintf (dump_file,
    1986              :                  "Stack clash skipped dynamic allocation and probing loop.\n");
    1987            9 :       else if (CONST_INT_P (*rounded_size)
    1988            0 :                && INTVAL (*rounded_size) <= 4 * *probe_interval)
    1989            0 :         fprintf (dump_file,
    1990              :                  "Stack clash dynamic allocation and probing inline.\n");
    1991            9 :       else if (CONST_INT_P (*rounded_size))
    1992            0 :         fprintf (dump_file,
    1993              :                  "Stack clash dynamic allocation and probing in "
    1994              :                  "rotated loop.\n");
    1995              :       else
    1996            9 :         fprintf (dump_file,
    1997              :                  "Stack clash dynamic allocation and probing in loop.\n");
    1998              : 
    1999            9 :       if (*residual != CONST0_RTX (Pmode))
    2000            9 :         fprintf (dump_file,
    2001              :                  "Stack clash dynamic allocation and probing residuals.\n");
    2002              :       else
    2003            0 :         fprintf (dump_file,
    2004              :                  "Stack clash skipped dynamic allocation and "
    2005              :                  "probing residuals.\n");
    2006              :     }
    2007           16 : }
    2008              : 
    2009              : /* Emit the start of an allocate/probe loop for stack
    2010              :    clash protection.
    2011              : 
    2012              :    LOOP_LAB and END_LAB are returned for use when we emit the
    2013              :    end of the loop.
    2014              : 
    2015              :    LAST addr is the value for SP which stops the loop.  */
    2016              : void
    2017           16 : emit_stack_clash_protection_probe_loop_start (rtx *loop_lab,
    2018              :                                               rtx *end_lab,
    2019              :                                               rtx last_addr,
    2020              :                                               bool rotated)
    2021              : {
    2022              :   /* Essentially we want to emit any setup code, the top of loop
    2023              :      label and the comparison at the top of the loop.  */
    2024           16 :   *loop_lab = gen_label_rtx ();
    2025           16 :   *end_lab = gen_label_rtx ();
    2026              : 
    2027           16 :   emit_label (*loop_lab);
    2028           16 :   if (!rotated)
    2029           16 :     emit_cmp_and_jump_insns (stack_pointer_rtx, last_addr, EQ, NULL_RTX,
    2030           16 :                              Pmode, 1, *end_lab);
    2031           16 : }
    2032              : 
    2033              : /* Emit the end of a stack clash probing loop.
    2034              : 
    2035              :    This consists of just the jump back to LOOP_LAB and
    2036              :    emitting END_LOOP after the loop.  */
    2037              : 
    2038              : void
    2039           16 : emit_stack_clash_protection_probe_loop_end (rtx loop_lab, rtx end_loop,
    2040              :                                             rtx last_addr, bool rotated)
    2041              : {
    2042           16 :   if (rotated)
    2043            0 :     emit_cmp_and_jump_insns (stack_pointer_rtx, last_addr, NE, NULL_RTX,
    2044            0 :                              Pmode, 1, loop_lab);
    2045              :   else
    2046           16 :     emit_jump (loop_lab);
    2047              : 
    2048           16 :   emit_label (end_loop);
    2049              : 
    2050           16 : }
    2051              : 
    2052              : /* Adjust the stack pointer by minus SIZE (an rtx for a number of bytes)
    2053              :    while probing it.  This pushes when SIZE is positive.  SIZE need not
    2054              :    be constant.
    2055              : 
    2056              :    This is subtly different than anti_adjust_stack_and_probe to try and
    2057              :    prevent stack-clash attacks
    2058              : 
    2059              :      1. It must assume no knowledge of the probing state, any allocation
    2060              :         must probe.
    2061              : 
    2062              :         Consider the case of a 1 byte alloca in a loop.  If the sum of the
    2063              :         allocations is large, then this could be used to jump the guard if
    2064              :         probes were not emitted.
    2065              : 
    2066              :      2. It never skips probes, whereas anti_adjust_stack_and_probe will
    2067              :         skip the probe on the first PROBE_INTERVAL on the assumption it
    2068              :         was already done in the prologue and in previous allocations.
    2069              : 
    2070              :      3. It only allocates and probes SIZE bytes, it does not need to
    2071              :         allocate/probe beyond that because this probing style does not
    2072              :         guarantee signal handling capability if the guard is hit.  */
    2073              : 
    2074              : void
    2075           16 : anti_adjust_stack_and_probe_stack_clash (rtx size)
    2076              : {
    2077              :   /* First ensure SIZE is Pmode.  */
    2078           16 :   if (GET_MODE (size) != VOIDmode && GET_MODE (size) != Pmode)
    2079            0 :     size = convert_to_mode (Pmode, size, 1);
    2080              : 
    2081              :   /* We can get here with a constant size on some targets.  */
    2082           16 :   rtx rounded_size, last_addr, residual;
    2083           16 :   HOST_WIDE_INT probe_interval, probe_range;
    2084           16 :   bool target_probe_range_p = false;
    2085           16 :   compute_stack_clash_protection_loop_data (&rounded_size, &last_addr,
    2086              :                                             &residual, &probe_interval, size);
    2087              : 
    2088              :   /* Get the back-end specific probe ranges.  */
    2089           16 :   probe_range = targetm.stack_clash_protection_alloca_probe_range ();
    2090           16 :   target_probe_range_p = probe_range != 0;
    2091           16 :   gcc_assert (probe_range >= 0);
    2092              : 
    2093              :   /* If no back-end specific range defined, default to the top of the newly
    2094              :      allocated range.  */
    2095           16 :   if (probe_range == 0)
    2096           32 :     probe_range = probe_interval - GET_MODE_SIZE (word_mode);
    2097              : 
    2098           16 :   if (rounded_size != CONST0_RTX (Pmode))
    2099              :     {
    2100           16 :       if (CONST_INT_P (rounded_size)
    2101            0 :           && INTVAL (rounded_size) <= 4 * probe_interval)
    2102              :         {
    2103            0 :           for (HOST_WIDE_INT i = 0;
    2104            0 :                i < INTVAL (rounded_size);
    2105            0 :                i += probe_interval)
    2106              :             {
    2107            0 :               anti_adjust_stack (GEN_INT (probe_interval));
    2108              :               /* The prologue does not probe residuals.  Thus the offset
    2109              :                  here to probe just beyond what the prologue had already
    2110              :                  allocated.  */
    2111            0 :               emit_stack_probe (plus_constant (Pmode, stack_pointer_rtx,
    2112            0 :                                                probe_range));
    2113              : 
    2114            0 :               emit_insn (gen_blockage ());
    2115              :             }
    2116              :         }
    2117              :       else
    2118              :         {
    2119           16 :           rtx loop_lab, end_loop;
    2120           16 :           bool rotate_loop = CONST_INT_P (rounded_size);
    2121           16 :           emit_stack_clash_protection_probe_loop_start (&loop_lab, &end_loop,
    2122              :                                                         last_addr, rotate_loop);
    2123              : 
    2124           16 :           anti_adjust_stack (GEN_INT (probe_interval));
    2125              : 
    2126              :           /* The prologue does not probe residuals.  Thus the offset here
    2127              :              to probe just beyond what the prologue had already
    2128              :              allocated.  */
    2129           16 :           emit_stack_probe (plus_constant (Pmode, stack_pointer_rtx,
    2130           16 :                                            probe_range));
    2131              : 
    2132           16 :           emit_stack_clash_protection_probe_loop_end (loop_lab, end_loop,
    2133              :                                                       last_addr, rotate_loop);
    2134           16 :           emit_insn (gen_blockage ());
    2135              :         }
    2136              :     }
    2137              : 
    2138           16 :   if (residual != CONST0_RTX (Pmode))
    2139              :     {
    2140           16 :       rtx label = NULL_RTX;
    2141              :       /* RESIDUAL could be zero at runtime and in that case *sp could
    2142              :          hold live data.  Furthermore, we do not want to probe into the
    2143              :          red zone.
    2144              : 
    2145              :          If TARGET_PROBE_RANGE_P then the target has promised it's safe to
    2146              :          probe at offset 0.  In which case we no longer have to check for
    2147              :          RESIDUAL == 0.  However we still need to probe at the right offset
    2148              :          when RESIDUAL > PROBE_RANGE, in which case we probe at PROBE_RANGE.
    2149              : 
    2150              :          If !TARGET_PROBE_RANGE_P then go ahead and just guard the probe at *sp
    2151              :          on RESIDUAL != 0 at runtime if RESIDUAL is not a compile time constant.
    2152              :          */
    2153           16 :       anti_adjust_stack (residual);
    2154              : 
    2155           16 :       if (!CONST_INT_P (residual))
    2156              :         {
    2157           16 :           label = gen_label_rtx ();
    2158           16 :           rtx_code op = target_probe_range_p ? LT : EQ;
    2159           16 :           rtx probe_cmp_value = target_probe_range_p
    2160            0 :             ? gen_rtx_CONST_INT (GET_MODE (residual), probe_range)
    2161           16 :             : CONST0_RTX (GET_MODE (residual));
    2162              : 
    2163           16 :           if (target_probe_range_p)
    2164            0 :             emit_stack_probe (stack_pointer_rtx);
    2165              : 
    2166           16 :           emit_cmp_and_jump_insns (residual, probe_cmp_value,
    2167           16 :                                    op, NULL_RTX, Pmode, 1, label);
    2168              :         }
    2169              : 
    2170           16 :       rtx x = NULL_RTX;
    2171              : 
    2172              :       /* If RESIDUAL isn't a constant and TARGET_PROBE_RANGE_P then we probe up
    2173              :          by the ABI defined safe value.  */
    2174           16 :       if (!CONST_INT_P (residual) && target_probe_range_p)
    2175            0 :         x = GEN_INT (probe_range);
    2176              :       /* If RESIDUAL is a constant but smaller than the ABI defined safe value,
    2177              :          we still want to probe up, but the safest amount if a word.  */
    2178            0 :       else if (target_probe_range_p)
    2179              :         {
    2180            0 :           if (INTVAL (residual) <= probe_range)
    2181            0 :             x = GEN_INT (GET_MODE_SIZE (word_mode));
    2182              :           else
    2183            0 :             x = GEN_INT (probe_range);
    2184              :         }
    2185              :       else
    2186              :       /* If nothing else, probe at the top of the new allocation.  */
    2187           32 :         x = plus_constant (Pmode, residual, -GET_MODE_SIZE (word_mode));
    2188              : 
    2189           16 :       emit_stack_probe (gen_rtx_PLUS (Pmode, stack_pointer_rtx, x));
    2190              : 
    2191           16 :       emit_insn (gen_blockage ());
    2192           16 :       if (!CONST_INT_P (residual))
    2193           16 :           emit_label (label);
    2194              :     }
    2195           16 : }
    2196              : 
    2197              : 
    2198              : /* Adjust the stack pointer by minus SIZE (an rtx for a number of bytes)
    2199              :    while probing it.  This pushes when SIZE is positive.  SIZE need not
    2200              :    be constant.  If ADJUST_BACK is true, adjust back the stack pointer
    2201              :    by plus SIZE at the end.  */
    2202              : 
    2203              : void
    2204           41 : anti_adjust_stack_and_probe (rtx size, bool adjust_back)
    2205              : {
    2206              :   /* We skip the probe for the first interval + a small dope of 4 words and
    2207              :      probe that many bytes past the specified size to maintain a protection
    2208              :      area at the botton of the stack.  */
    2209           41 :   const int dope = 4 * UNITS_PER_WORD;
    2210              : 
    2211              :   /* First ensure SIZE is Pmode.  */
    2212           41 :   if (GET_MODE (size) != VOIDmode && GET_MODE (size) != Pmode)
    2213            0 :     size = convert_to_mode (Pmode, size, 1);
    2214              : 
    2215              :   /* If we have a constant small number of probes to generate, that's the
    2216              :      easy case.  */
    2217           41 :   if (CONST_INT_P (size) && INTVAL (size) < 7 * PROBE_INTERVAL)
    2218              :     {
    2219              :       HOST_WIDE_INT isize = INTVAL (size), i;
    2220              :       bool first_probe = true;
    2221              : 
    2222              :       /* Adjust SP and probe at PROBE_INTERVAL + N * PROBE_INTERVAL for
    2223              :          values of N from 1 until it exceeds SIZE.  If only one probe is
    2224              :          needed, this will not generate any code.  Then adjust and probe
    2225              :          to PROBE_INTERVAL + SIZE.  */
    2226           32 :       for (i = PROBE_INTERVAL; i < isize; i += PROBE_INTERVAL)
    2227              :         {
    2228            0 :           if (first_probe)
    2229              :             {
    2230            0 :               anti_adjust_stack (GEN_INT (2 * PROBE_INTERVAL + dope));
    2231            0 :               first_probe = false;
    2232              :             }
    2233              :           else
    2234            0 :             anti_adjust_stack (GEN_INT (PROBE_INTERVAL));
    2235            0 :           emit_stack_probe (stack_pointer_rtx);
    2236              :         }
    2237              : 
    2238           32 :       if (first_probe)
    2239           32 :         anti_adjust_stack (plus_constant (Pmode, size, PROBE_INTERVAL + dope));
    2240              :       else
    2241            0 :         anti_adjust_stack (plus_constant (Pmode, size, PROBE_INTERVAL - i));
    2242           32 :       emit_stack_probe (stack_pointer_rtx);
    2243           32 :     }
    2244              : 
    2245              :   /* In the variable case, do the same as above, but in a loop.  Note that we
    2246              :      must be extra careful with variables wrapping around because we might be
    2247              :      at the very top (or the very bottom) of the address space and we have to
    2248              :      be able to handle this case properly; in particular, we use an equality
    2249              :      test for the loop condition.  */
    2250              :   else
    2251              :     {
    2252            9 :       rtx rounded_size, rounded_size_op, last_addr, temp;
    2253            9 :       rtx_code_label *loop_lab = gen_label_rtx ();
    2254            9 :       rtx_code_label *end_lab = gen_label_rtx ();
    2255              : 
    2256              : 
    2257              :       /* Step 1: round SIZE to the previous multiple of the interval.  */
    2258              : 
    2259              :       /* ROUNDED_SIZE = SIZE & -PROBE_INTERVAL  */
    2260            9 :       rounded_size
    2261            9 :         = simplify_gen_binary (AND, Pmode, size,
    2262            9 :                                gen_int_mode (-PROBE_INTERVAL, Pmode));
    2263            9 :       rounded_size_op = force_operand (rounded_size, NULL_RTX);
    2264              : 
    2265              : 
    2266              :       /* Step 2: compute initial and final value of the loop counter.  */
    2267              : 
    2268              :       /* SP = SP_0 + PROBE_INTERVAL.  */
    2269            9 :       anti_adjust_stack (GEN_INT (PROBE_INTERVAL + dope));
    2270              : 
    2271              :       /* LAST_ADDR = SP_0 + PROBE_INTERVAL + ROUNDED_SIZE.  */
    2272            9 :       last_addr = force_operand (gen_rtx_fmt_ee (STACK_GROW_OP, Pmode,
    2273              :                                                  stack_pointer_rtx,
    2274              :                                                  rounded_size_op), NULL_RTX);
    2275              : 
    2276              : 
    2277              :       /* Step 3: the loop
    2278              : 
    2279              :          while (SP != LAST_ADDR)
    2280              :            {
    2281              :              SP = SP + PROBE_INTERVAL
    2282              :              probe at SP
    2283              :            }
    2284              : 
    2285              :          adjusts SP and probes at PROBE_INTERVAL + N * PROBE_INTERVAL for
    2286              :          values of N from 1 until it is equal to ROUNDED_SIZE.  */
    2287              : 
    2288            9 :       emit_label (loop_lab);
    2289              : 
    2290              :       /* Jump to END_LAB if SP == LAST_ADDR.  */
    2291            9 :       emit_cmp_and_jump_insns (stack_pointer_rtx, last_addr, EQ, NULL_RTX,
    2292            9 :                                Pmode, 1, end_lab);
    2293              : 
    2294              :       /* SP = SP + PROBE_INTERVAL and probe at SP.  */
    2295            9 :       anti_adjust_stack (GEN_INT (PROBE_INTERVAL));
    2296            9 :       emit_stack_probe (stack_pointer_rtx);
    2297              : 
    2298            9 :       emit_jump (loop_lab);
    2299              : 
    2300            9 :       emit_label (end_lab);
    2301              : 
    2302              : 
    2303              :       /* Step 4: adjust SP and probe at PROBE_INTERVAL + SIZE if we cannot
    2304              :          assert at compile-time that SIZE is equal to ROUNDED_SIZE.  */
    2305              : 
    2306              :       /* TEMP = SIZE - ROUNDED_SIZE.  */
    2307            9 :       temp = simplify_gen_binary (MINUS, Pmode, size, rounded_size);
    2308            9 :       if (temp != const0_rtx)
    2309              :         {
    2310              :           /* Manual CSE if the difference is not known at compile-time.  */
    2311            9 :           if (GET_CODE (temp) != CONST_INT)
    2312            9 :             temp = gen_rtx_MINUS (Pmode, size, rounded_size_op);
    2313            9 :           anti_adjust_stack (temp);
    2314            9 :           emit_stack_probe (stack_pointer_rtx);
    2315              :         }
    2316              :     }
    2317              : 
    2318              :   /* Adjust back and account for the additional first interval.  */
    2319           41 :   if (adjust_back)
    2320           32 :     adjust_stack (plus_constant (Pmode, size, PROBE_INTERVAL + dope));
    2321              :   else
    2322            9 :     adjust_stack (GEN_INT (PROBE_INTERVAL + dope));
    2323           41 : }
    2324              : 
    2325              : /* Return an rtx representing the register or memory location
    2326              :    in which a scalar value of data type VALTYPE
    2327              :    was returned by a function call to function FUNC.
    2328              :    FUNC is a FUNCTION_DECL, FNTYPE a FUNCTION_TYPE node if the precise
    2329              :    function is known, otherwise 0.
    2330              :    OUTGOING is 1 if on a machine with register windows this function
    2331              :    should return the register in which the function will put its result
    2332              :    and 0 otherwise.  */
    2333              : 
    2334              : rtx
    2335    101365941 : hard_function_value (const_tree valtype, const_tree func, const_tree fntype,
    2336              :                      int outgoing ATTRIBUTE_UNUSED)
    2337              : {
    2338    101365941 :   rtx val;
    2339              : 
    2340    200244437 :   val = targetm.calls.function_value (valtype, func ? func : fntype, outgoing);
    2341              : 
    2342    101365941 :   if (REG_P (val)
    2343    100474790 :       && GET_MODE (val) == BLKmode)
    2344              :     {
    2345       132618 :       unsigned HOST_WIDE_INT bytes = arg_int_size_in_bytes (valtype);
    2346       132618 :       opt_scalar_int_mode tmpmode;
    2347              : 
    2348              :       /* int_size_in_bytes can return -1.  We don't need a check here
    2349              :          since the value of bytes will then be large enough that no
    2350              :          mode will match anyway.  */
    2351              : 
    2352       478835 :       FOR_EACH_MODE_IN_CLASS (tmpmode, MODE_INT)
    2353              :         {
    2354              :           /* Have we found a large enough mode?  */
    2355       957670 :           if (GET_MODE_SIZE (tmpmode.require ()) >= bytes)
    2356              :             break;
    2357              :         }
    2358              : 
    2359       132618 :       PUT_MODE (val, tmpmode.require ());
    2360              :     }
    2361    101365941 :   return val;
    2362              : }
    2363              : 
    2364              : /* Return an rtx representing the register or memory location
    2365              :    in which a scalar value of mode MODE was returned by a library call.  */
    2366              : 
    2367              : rtx
    2368       105472 : hard_libcall_value (machine_mode mode, rtx fun)
    2369              : {
    2370       105472 :   return targetm.calls.libcall_value (mode, fun);
    2371              : }
    2372              : 
    2373              : /* Look up the tree code for a given rtx code
    2374              :    to provide the arithmetic operation for real_arithmetic.
    2375              :    The function returns an int because the caller may not know
    2376              :    what `enum tree_code' means.  */
    2377              : 
    2378              : int
    2379         5343 : rtx_to_tree_code (enum rtx_code code)
    2380              : {
    2381         5343 :   enum tree_code tcode;
    2382              : 
    2383         5343 :   switch (code)
    2384              :     {
    2385              :     case PLUS:
    2386              :       tcode = PLUS_EXPR;
    2387              :       break;
    2388              :     case MINUS:
    2389              :       tcode = MINUS_EXPR;
    2390              :       break;
    2391              :     case MULT:
    2392              :       tcode = MULT_EXPR;
    2393              :       break;
    2394              :     case DIV:
    2395              :       tcode = RDIV_EXPR;
    2396              :       break;
    2397              :     case SMIN:
    2398              :       tcode = MIN_EXPR;
    2399              :       break;
    2400              :     case SMAX:
    2401              :       tcode = MAX_EXPR;
    2402              :       break;
    2403              :     default:
    2404              :       tcode = LAST_AND_UNUSED_TREE_CODE;
    2405              :       break;
    2406              :     }
    2407         5343 :   return ((int) tcode);
    2408              : }
    2409              : 
    2410              : #include "gt-explow.h"
        

Generated by: LCOV version 2.4-beta

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