This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Intermodule constant propagation


> On Nov 24, 2003, at 00:13, Mircea Namolaru wrote:
> >We would like to add several interprocedural optimizations to gcc, 
> >starting
> >with constant propagation.
> >
> >We are thinking of implementing a flow insensitive form of the
> >interprocedural
> >constant propagation algorithm described in [1][2], based on the new
> >intermodule code 
> >(http://gcc.gnu.org/ml/gcc-patches/2003-05/msg01665.html).
> >
> >We would appreciate any feedback regarding gcc interprocedural
> >optimizations
> >(work done or in development, potential problems etc).
> 
> 
> Jan Hubicka and I were just talking about this on IRC today.
> 
> Here is the ideas both Jan and I agreed on (for the tree-ssa branch):
> Have a flag called -fwhole-prgram which tells GCC that the whole
> program is being compiled at this point and have variables which
> were global be static.
Hi,
here is the patch I was experimenting with on whole program
optimizations.  It does not make the functions/variables to become
local, but it does make the optimizations to happen (it global functions
are elliminated, inlined once, changed calling conventions and so on).
This is not nice, so first I would like to see this solved before I will
consider applying this.

What are the opinions about this?  Shall cgraph code simply remove
PUBLIC flags or shall we maintain this information somewhere separately
so we don't confuse it with pretty well defined PUBLIC flag comming out
from front-end?

The patch is also just a start - it does not elliminate unused variables
and does not take any effort for backends to use this...

The program makes quite considerable difference on byte benchmark as
many of tests are simply optimized out :)
It would be nice to run it on SPEC, but I first need to figure out how
to hook our current intermodule code into SPEC build system...
Any hints here?

Honza

	* cgraphunit.c (decide_is_function_needed): Support flag_whole_program
	(cgraph_mark_local_functions): Do not check TREE_PUBLIC
	* common.opt (fwhole-program): New option.
	* flags.h (flag_whole_program): Declare.
	* opts.c (common_handle_option): Handle -fwhole-program
Index: common.opt
===================================================================
RCS file: /cvs/gcc/gcc/gcc/common.opt,v
retrieving revision 1.21
diff -c -3 -p -r1.21 common.opt
*** common.opt	21 Nov 2003 04:05:04 -0000	1.21
--- common.opt	24 Nov 2003 17:51:26 -0000
*************** fweb
*** 719,724 ****
--- 719,728 ----
  Common
  Construct webs and split unrelated uses of single variable
  
+ fwhole-program
+ Common
+ Perform whole program optimizations
+ 
  fwrapv
  Common
  Assume signed arithmetic overflow wraps around
Index: flags.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/flags.h,v
retrieving revision 1.126
diff -c -3 -p -r1.126 flags.h
*** flags.h	20 Oct 2003 21:46:33 -0000	1.126
--- flags.h	24 Nov 2003 17:51:29 -0000
*************** extern int flag_signaling_nans;
*** 717,722 ****
--- 717,725 ----
  
  extern int flag_unit_at_a_time;
  
+ /* Perform whole program optimizations.  */
+ extern int flag_whole_program;
+ 
  extern int flag_web;
  
  /* Nonzero means that we defer emitting functions until they are actually
Index: opts.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/opts.c,v
retrieving revision 1.46
diff -c -3 -p -r1.46 opts.c
*** opts.c	21 Nov 2003 04:05:05 -0000	1.46
--- opts.c	24 Nov 2003 17:52:10 -0000
*************** common_handle_option (size_t scode, cons
*** 1404,1409 ****
--- 1404,1413 ----
      case OPT_fweb:
        flag_web = value;
        break;
+ 
+     case OPT_fwhole_program:
+       flag_whole_program = value;
+       break;
        
      case OPT_fwrapv:
        flag_wrapv = value;
Index: doc/invoke.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/invoke.texi,v
retrieving revision 1.364
diff -c -3 -p -r1.364 invoke.texi
*** doc/invoke.texi	21 Nov 2003 11:42:58 -0000	1.364
--- doc/invoke.texi	24 Nov 2003 17:53:22 -0000
*************** in the following sections.
*** 295,301 ****
  -fstrength-reduce  -fstrict-aliasing  -ftracer  -fthread-jumps @gol
  -funroll-all-loops  -funroll-loops  -fpeel-loops @gol
  -funswitch-loops  -fold-unroll-loops  -fold-unroll-all-loops @gol
! --param @var{name}=@var{value}
  -O  -O0  -O1  -O2  -O3  -Os}
  
  @item Preprocessor Options
--- 295,301 ----
  -fstrength-reduce  -fstrict-aliasing  -ftracer  -fthread-jumps @gol
  -funroll-all-loops  -funroll-loops  -fpeel-loops @gol
  -funswitch-loops  -fold-unroll-loops  -fold-unroll-all-loops @gol
! -fwhole-program --param @var{name}=@var{value}
  -O  -O0  -O1  -O2  -O3  -Os}
  
  @item Preprocessor Options
*************** better job.
*** 4587,4592 ****
--- 4587,4599 ----
  Parse the whole compilation unit before starting to produce code.
  This allows some extra optimizations to take place but consumes more
  memory.
+ 
+ @item -fwhole-program
+ @opindex fwhole-program
+ Assume that the whole program is exposed in the current compialation unit.
+ All public symbols defined by program with exception of function main and those
+ marged by attribute @code{used} are assumed to be local and may be altered by
+ compiler.
  
  @item -funroll-loops
  @opindex funroll-loops
Index: cgraphunit.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cgraphunit.c,v
retrieving revision 1.39
diff -c -3 -p -r1.39 cgraphunit.c
*** cgraphunit.c	21 Nov 2003 06:52:22 -0000	1.39
--- cgraphunit.c	24 Nov 2003 17:57:52 -0000
*************** decide_is_function_needed (struct cgraph
*** 79,85 ****
  
    /* Externally visible functions must be output.  The exception is
       COMDAT functions that must be output only when they are needed.  */
!   if (TREE_PUBLIC (decl) && !DECL_COMDAT (decl) && !DECL_EXTERNAL (decl))
      return true;
  
    /* Constructors and destructors are reachable from the runtime by
--- 79,88 ----
  
    /* Externally visible functions must be output.  The exception is
       COMDAT functions that must be output only when they are needed.  */
!   if ((TREE_PUBLIC (decl) && !flag_whole_program)
!       && !DECL_COMDAT (decl) && !DECL_EXTERNAL (decl))
!     return true;
!   if (MAIN_NAME_P (DECL_NAME (decl)))
      return true;
  
    /* Constructors and destructors are reachable from the runtime by
*************** cgraph_mark_local_functions (void)
*** 1338,1346 ****
    /* Figure out functions we want to assemble.  */
    for (node = cgraph_nodes; node; node = node->next)
      {
!       node->local.local = (!node->needed
! 		           && DECL_SAVED_TREE (node->decl)
! 		           && !TREE_PUBLIC (node->decl));
        if (cgraph_dump_file && node->local.local)
  	fprintf (cgraph_dump_file, " %s", cgraph_node_name (node));
      }
--- 1341,1348 ----
    /* Figure out functions we want to assemble.  */
    for (node = cgraph_nodes; node; node = node->next)
      {
!       node->local.local = (!node->needed && DECL_SAVED_TREE (node->decl)
! 			   && !DECL_COMDAT (node->decl))
        if (cgraph_dump_file && node->local.local)
  	fprintf (cgraph_dump_file, " %s", cgraph_node_name (node));
      }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]