This is the mail archive of the gcc-patches@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]

[PATCH][lto] Enable LTO for gfortran


This patch enables LTO support for gfortran.  It does however fail
to build a two-file hello-world:

$ cat t.f
      program blah
      call foo
      end
$ cat t2.f
      subroutine foo
      write (*,*) 'Hello world!'
      end

which is because lto1 ICEs in registering the following type:

#7  0x080dc48f in lto_read_in_decl_state (data_in=0xbffff2ac, 
data=0x8d40418, 
    state=0x8d3c698) at /home/richard/src/lto/gcc/lto/lto.c:213
213		    decls[j] = gimple_register_type (decls[j]);
(gdb) call debug_tree (decls[j])
 <pointer_type 0xb7bd2e00
    type <function_decl 0xb7bd1c00 _gfortran_transfer_character
        type <function_type 0xb7bd2d90 type <void_type 0xb7cb69a0>
            QI
            size <integer_cst 0xb7caa310 constant 8>
            unit size <integer_cst 0xb7caa32c constant 1>
            align 8 symtab 0 alias set -1 canonical type 0xb7bd1c00
            arg-types <tree_list 0xb7bd6364 value <pointer_type 
0xb7bd28c0>
                chain <tree_list 0xb7bd6380 value <pointer_type 
0xb7cb6a10>
                    chain <tree_list 0xb7bd639c value <integer_type 
0xb7cb6310>
                        chain <tree_list 0xb7bd63b8 value <void_type 
0xb7cb69a0>>>>>
            pointer_to_this <pointer_type 0xb7bd2e00>>
        public external QI file (null) line 0 col 0 align 8>
    unsigned SI
    size <integer_cst 0xb7bd6054 type <pointer_type 0xb7bd2700> constant 
32>
    unit size <integer_cst 0xb7bd608c type <integer_type 0xb7bd2770 
bit_size_type> constant 4>
    align 32 symtab 0 alias set -1 canonical type 0xb7bd2d90>

which - uhm - looks fishy ;)

What is the approach to debug this?

Thanks,
Richard.

2009-06-14  Richard Guenther  <rguenther@suse.de>

	fortran/
	* options.c (gfc_post_options): Handle -flto and -fwhopr.

	* c.opt (flto, fwhopr): Move ...
	* common.opt (flto, fwhopr): ... here.

Index: gcc/fortran/options.c
===================================================================
*** gcc/fortran/options.c	(revision 148471)
--- gcc/fortran/options.c	(working copy)
*************** gfc_post_options (const char **pfilename
*** 242,247 ****
--- 242,269 ----
    if (flag_whole_program)
      gfc_option.flag_whole_file = 1;
  
+   if (flag_lto || flag_whopr)
+     {
+ #ifdef ENABLE_LTO
+       flag_generate_lto = 1;
+ 
+       /* When generating IL, do not operate in whole-program mode.
+ 	 Otherwise, symbols will be privatized too early, causing link
+ 	 errors later.  */
+       flag_whole_program = 0;
+ 
+       /* But do enable whole-file mode.  */
+       gfc_option.flag_whole_file = 1;
+ #else
+       error ("LTO support has not been enabled in this configuration");
+ #endif
+     }
+ 
+   /* Reconcile -flto and -fwhopr.  Set additional flags as appropriate and
+      check option consistency.  */
+   if (flag_lto && flag_whopr)
+     error ("-flto and -fwhopr are mutually exclusive");
+ 
    /* -fbounds-check is equivalent to -fcheck=bounds */
    if (flag_bounds_check)
      gfc_option.rtcheck |= GFC_RTCHECK_BOUNDS;
Index: gcc/c.opt
===================================================================
*** gcc/c.opt	(revision 148471)
--- gcc/c.opt	(working copy)
*************** flax-vector-conversions
*** 648,657 ****
  C ObjC C++ ObjC++
  Allow implicit conversions between vectors with differing numbers of subparts and/or differing element types.
  
- flto
- C C++ Var(flag_lto)
- Enable link-time optimization.
- 
  fms-extensions
  C ObjC C++ ObjC++
  Don't warn about uses of Microsoft extensions
--- 648,653 ----
*************** fweak
*** 825,834 ****
  C++ ObjC++
  Emit common-like symbols as weak symbols
  
- fwhopr
- C C++ Var(flag_whopr)
- Enable partitioned link-time optimization.
- 
  fwide-exec-charset=
  C ObjC C++ ObjC++ Joined RejectNegative
  -fwide-exec-charset=<cset>	Convert all wide strings and character constants to character set <cset>
--- 821,826 ----
Index: gcc/common.opt
===================================================================
*** gcc/common.opt	(revision 148471)
--- gcc/common.opt	(working copy)
*************** floop-optimize
*** 730,735 ****
--- 730,739 ----
  Common
  Does nothing.  Preserved for backward compatibility.
  
+ flto
+ Common Var(flag_lto)
+ Enable link-time optimization.
+ 
  ; The initial value of -1 comes from Z_DEFAULT_COMPRESSION in zlib.h.
  flto-compression-level=
  Common Joined UInteger Var(flag_lto_compression_level) Init(-1)
*************** fweb
*** 1386,1391 ****
--- 1390,1399 ----
  Common Report Var(flag_web) Init(2) Optimization
  Construct webs and split unrelated uses of single variable
  
+ fwhopr
+ Common Var(flag_whopr)
+ Enable partitioned link-time optimization.
+ 
  ftree-builtin-call-dce
  Common Report Var(flag_tree_builtin_call_dce) Init(0) Optimization
  Enable conditional dead code elimination for builtin calls


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