LCOV - code coverage report
Current view: top level - gcc - stack-ptr-mod.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 100.0 % 23 23
Test Date: 2024-04-20 14:03:02 Functions: 100.0 % 3 3
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Discover if the stack pointer is modified in a function.
       2                 :             :    Copyright (C) 2007-2024 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                 :             : #include "config.h"
      21                 :             : #include "system.h"
      22                 :             : #include "coretypes.h"
      23                 :             : #include "backend.h"
      24                 :             : #include "rtl.h"
      25                 :             : #include "df.h"
      26                 :             : #include "memmodel.h"
      27                 :             : #include "emit-rtl.h"
      28                 :             : #include "tree-pass.h"
      29                 :             : 
      30                 :             : /* Determine if the stack pointer is constant over the life of the function.
      31                 :             :    Only useful before prologues have been emitted.  */
      32                 :             : 
      33                 :             : static void
      34                 :    62017587 : notice_stack_pointer_modification_1 (rtx x, const_rtx pat ATTRIBUTE_UNUSED,
      35                 :             :                                      void *data ATTRIBUTE_UNUSED)
      36                 :             : {
      37                 :    62017587 :   if (x == stack_pointer_rtx
      38                 :             :       /* The stack pointer is only modified indirectly as the result
      39                 :             :          of a push until later.  See the comments in rtl.texi
      40                 :             :          regarding Embedded Side-Effects on Addresses.  */
      41                 :    61862129 :       || (MEM_P (x)
      42                 :     7587388 :           && GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == RTX_AUTOINC
      43                 :       35499 :           && XEXP (XEXP (x, 0), 0) == stack_pointer_rtx))
      44                 :      190957 :     crtl->sp_is_unchanging = 0;
      45                 :    62017587 : }
      46                 :             : 
      47                 :             :   /* Some targets can emit simpler epilogues if they know that sp was
      48                 :             :      not ever modified during the function.  After reload, of course,
      49                 :             :      we've already emitted the epilogue so there's no sense searching.  */
      50                 :             : 
      51                 :             : namespace {
      52                 :             : 
      53                 :             : const pass_data pass_data_stack_ptr_mod =
      54                 :             : {
      55                 :             :   RTL_PASS, /* type */
      56                 :             :   "*stack_ptr_mod", /* name */
      57                 :             :   OPTGROUP_NONE, /* optinfo_flags */
      58                 :             :   TV_NONE, /* tv_id */
      59                 :             :   0, /* properties_required */
      60                 :             :   0, /* properties_provided */
      61                 :             :   0, /* properties_destroyed */
      62                 :             :   0, /* todo_flags_start */
      63                 :             :   0, /* todo_flags_finish */
      64                 :             : };
      65                 :             : 
      66                 :             : class pass_stack_ptr_mod : public rtl_opt_pass
      67                 :             : {
      68                 :             : public:
      69                 :      281914 :   pass_stack_ptr_mod (gcc::context *ctxt)
      70                 :      563828 :     : rtl_opt_pass (pass_data_stack_ptr_mod, ctxt)
      71                 :             :   {}
      72                 :             : 
      73                 :             :   /* opt_pass methods: */
      74                 :             :   unsigned int execute (function *) final override;
      75                 :             : 
      76                 :             : }; // class pass_stack_ptr_mod
      77                 :             : 
      78                 :             : unsigned int
      79                 :     1426763 : pass_stack_ptr_mod::execute (function *fun)
      80                 :             : {
      81                 :     1426763 :   basic_block bb;
      82                 :     1426763 :   rtx_insn *insn;
      83                 :             : 
      84                 :             :   /* Assume that the stack pointer is unchanging if alloca hasn't
      85                 :             :      been used.  */
      86                 :     1426763 :   crtl->sp_is_unchanging = !fun->calls_alloca;
      87                 :     1426763 :   if (crtl->sp_is_unchanging)
      88                 :    11721645 :     FOR_EACH_BB_FN (bb, fun)
      89                 :   119426063 :       FOR_BB_INSNS (bb, insn)
      90                 :             :         {
      91                 :   109116313 :           if (INSN_P (insn))
      92                 :             :             {
      93                 :             :               /* Check if insn modifies the stack pointer.  */
      94                 :    89750960 :               note_stores (insn, notice_stack_pointer_modification_1, NULL);
      95                 :    89750960 :               if (! crtl->sp_is_unchanging)
      96                 :             :                 return 0;
      97                 :             :             }
      98                 :             :         }
      99                 :             : 
     100                 :             :   /* The value coming into this pass was 0, and the exit block uses
     101                 :             :      are based on this.  If the value is now 1, we need to redo the
     102                 :             :      exit block uses.  */
     103                 :     1235806 :   if (df && crtl->sp_is_unchanging)
     104                 :     1220938 :     df_update_exit_block_uses ();
     105                 :             : 
     106                 :             :   return 0;
     107                 :             : }
     108                 :             : 
     109                 :             : } // anon namespace
     110                 :             : 
     111                 :             : rtl_opt_pass *
     112                 :      281914 : make_pass_stack_ptr_mod (gcc::context *ctxt)
     113                 :             : {
     114                 :      281914 :   return new pass_stack_ptr_mod (ctxt);
     115                 :             : }
        

Generated by: LCOV version 2.1-beta

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