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

[RFA, Fortran, try 11] Emulated tls rewrite

On 07/21/2010 07:32 PM, Jack Howarth wrote:
> FAIL: gfortran.dg/gomp/appendix-a/a.22.6.f90  -O  (test for excess errors)
> Excess errors:
> .../testsuite/gfortran.dg/gomp/appendix-a/a.22.6.f90:4:0: sorry, unimplemented: thread-local COMMON data not implemented

I managed to reproduce this problem reliably.  It has to do with the Fortran
front end (indirectly) invoking varpool_finalize_decl much later than the C
front ends do.  Without the decls being finalized, the IPA pass doesn't get
to see them and they don't get lowered.

I talked to Richi about this ordering problem on IRC, and changing the 
generic ordering of decls vs compilation unit finalization appears to run
into problems with C++ and Java and their aliases.  An acceptable solution
appears to be to hack the Fortran front end to do it by hand.

An incremental diff, excluding the testsuite, from #9 is below and the
full patch from HEAD is attached.



diff --git a/gcc/fortran/f95-lang.c b/gcc/fortran/f95-lang.c
index 5b67621..9d0bf44 100644
--- a/gcc/fortran/f95-lang.c
+++ b/gcc/fortran/f95-lang.c
@@ -88,6 +88,7 @@ static void gfc_init_builtin_functions (void);
 /* Each front end provides its own.  */
 static bool gfc_init (void);
 static void gfc_finish (void);
+static void gfc_write_global_declarations (void);
 static void gfc_print_identifier (FILE *, tree, int);
 void do_function_end (void);
 int global_bindings_p (void);
@@ -99,6 +100,7 @@ static void gfc_init_ts (void);
@@ -127,6 +129,7 @@ static void gfc_init_ts (void);
 #define LANG_HOOKS_NAME                 "GNU Fortran"
 #define LANG_HOOKS_INIT                 gfc_init
 #define LANG_HOOKS_FINISH               gfc_finish
+#define LANG_HOOKS_WRITE_GLOBALS	gfc_write_global_declarations
 #define LANG_HOOKS_INIT_OPTIONS         gfc_init_options
 #define LANG_HOOKS_HANDLE_OPTION        gfc_handle_option
 #define LANG_HOOKS_POST_OPTIONS		gfc_post_options
@@ -282,6 +285,33 @@ gfc_finish (void)
+/* ??? This is something of a hack.
+   Emulated tls lowering needs to see all TLS variables before we call
+   cgraph_finalize_compilation_unit.  The C/C++ front ends manage this
+   by calling decl_rest_of_compilation on each global and static variable
+   as they are seen.  The Fortran front end waits until this hook.
+   A Correct solution is for cgraph_finalize_compilation_unit not to be
+   called during the WRITE_GLOBALS langhook, and have that hook only do what
+   its name suggests and write out globals.  But the C++ and Java front ends
+   have (unspecified) problems with aliases that gets in the way.  It has
+   been suggested that these problems would be solved by completing the
+   conversion to cgraph-based aliases.  */
+static void
+gfc_write_global_declarations (void)
+  tree decl;
+  /* Finalize all of the globals.  */
+  for (decl = getdecls(); decl ; decl = DECL_CHAIN (decl))
+    rest_of_decl_compilation (decl, true, true);
+  write_global_declarations ();
 static void
 gfc_print_identifier (FILE * file ATTRIBUTE_UNUSED,
 		      tree node ATTRIBUTE_UNUSED,

Attachment: emutls-11
Description: Text document

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