diff mbox

Fix emutls bootstrap issues

Message ID 20111114173450.GA31042@kam.mff.cuni.cz
State New
Headers show

Commit Message

Jan Hubicka Nov. 14, 2011, 5:34 p.m. UTC
Hi,
emutls is creating variables late that confuses varpool since
varpool_finalize_decl is supposed to be used only before cgraph construction.

This patch fixes the problem by introducing varpool_add_new_variable
that works same as cgraph_add_new_function (i.e. allows middle-end/back-end
to create new variables after varpool construction).

Bootstrapped/regtested x86_64-linux, comitted.

2011-11-14  Jan Hubicka  <jh@suse.cz>

	PR middle-end/50598
	* cgraph.h (varpool_externally_visible_p): Declare.
	(varpool_add_new_variable): Declare.
	* tree-emultls.c (get_emutls_init_templ_addr,
	new_emutls_decl): Use varpool_add_new_variable.
	* ipa.c (varpool_externally_visible_p): Export.
	* varpool.c (varpool_add_new_variable): New function.
diff mbox

Patch

Index: cgraph.h
===================================================================
--- cgraph.h    (revision 181310)
+++ cgraph.h    (working copy)
@@ -641,6 +641,7 @@  void debug_varpool_node_set (varpool_nod
 void free_varpool_node_set (varpool_node_set);
 void ipa_discover_readonly_nonaddressable_vars (void);
 bool cgraph_comdat_can_be_unshared_p (struct cgraph_node *);
+bool varpool_externally_visible_p (struct varpool_node *, bool);

 /* In predict.c  */
 bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e);
@@ -681,6 +682,7 @@  bool const_value_known_p (tree);
 bool varpool_for_node_and_aliases (struct varpool_node *,
                            bool (*) (struct varpool_node *, void *),
                        void *, bool);
+void varpool_add_new_variable (tree);

 /* Walk all reachable static variables.  */
 #define FOR_EACH_STATIC_VARIABLE(node) \
Index: tree-emutls.c
===================================================================
--- tree-emutls.c    (revision 181310)
+++ tree-emutls.c    (working copy)
@@ -262,7 +262,7 @@  get_emutls_init_templ_addr (tree decl)
   if (DECL_EXTERNAL (to))
     varpool_node (to);
   else
-    varpool_finalize_decl (to);
+    varpool_add_new_variable (to);
   return build_fold_addr_expr (to);
 }

@@ -334,7 +334,7 @@  new_emutls_decl (tree decl, tree alias_o
   if (DECL_EXTERNAL (to))
     varpool_node (to);
   else if (!alias_of)
-    varpool_finalize_decl (to);
+    varpool_add_new_variable (to);
   else 
     varpool_create_variable_alias (to,
                    varpool_node_for_asm
Index: ipa.c
===================================================================
--- ipa.c    (revision 181310)
+++ ipa.c    (working copy)
@@ -647,7 +647,7 @@  cgraph_externally_visible_p (struct cgra

 /* Return true when variable VNODE should be considered externally visible. 
*/

-static bool
+bool
 varpool_externally_visible_p (struct varpool_node *vnode, bool aliased)
 {
   if (!DECL_COMDAT (vnode->decl) && !TREE_PUBLIC (vnode->decl))
Index: varpool.c
===================================================================
--- varpool.c    (revision 181310)
+++ varpool.c    (working copy)
@@ -414,6 +414,20 @@  varpool_finalize_decl (tree decl)
     varpool_assemble_pending_decls ();
 }

+/* Add the variable DECL to the varpool.
+   Unlike varpool_finalize_decl function is intended to be used
+   by middle end and allows insertion of new variable at arbitrary point
+   of compilation.  */
+void
+varpool_add_new_variable (tree decl)
+{
+  struct varpool_node *node;
+  varpool_finalize_decl (decl);
+  node = varpool_node (decl);
+  if (varpool_externally_visible_p (node, false))
+    node->externally_visible = true;
+}
+
 /* Return variable availability.  See cgraph.h for description of individual
    return values.  */
 enum availability