This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Remove wpa-fixup pass
- From: Jan Hubicka <hubicka at ucw dot cz>
- To: gcc-patches at gcc dot gnu dot org, dnovillo at google dot com, rguenther at suse dot de
- Date: Tue, 20 Apr 2010 22:45:47 +0200
- Subject: Remove wpa-fixup pass
Hi,
the WPA fixup pass is fixing call statements of functions that was found to be nothrow.
The same is done by fixup_cfg pass hidden in inliner's transform method. So I've
removed WPA fixup pass since it is a lot more complex. This results in checking failure
because statement verifier avoids testing of throw flags only when cgraph_state
is IPA_SSA, while transfrom is called during expansion.
To avoid the problem I simply temporarily change cgraph state. It is a hack,
but I guess it is better than introducing another state variable somewhere
or adding a flag in struct_function.
Bootstrapped/regtested x86_64-linux, OK?
Honza
* timevar.def (TV_WHOPR_WPA_FIXUP): Remove.
* lto-section-in.c (lto_section_name): Remove wpa_fixup.
* lto-wpa-fixup.c: Remove.
* Makefile.in (lto-wpa-fixup.o): Remove.
* passes.c (init_optimization_passes): Remove pass_ipa_lto_wpa_fixup.
(execute_all_ipa_transforms): Set cgraph_state to CGRAPH_STATE_IPA_SSA.
* lto-streamer.c (lto_get_section_name): Remove wpa_fixup section.
* lto/lto.c (lto_fixup_tree): Do not call wpa fixup.
(materialize_cgraph): Likewise.
Index: timevar.def
===================================================================
--- timevar.def (revision 158563)
+++ timevar.def (working copy)
@@ -57,7 +57,6 @@ DEFTIMEVAR (TV_LTO , "
DEFTIMEVAR (TV_WHOPR_WPA , "whopr wpa")
DEFTIMEVAR (TV_WHOPR_WPA_IO , "whopr wpa I/O")
DEFTIMEVAR (TV_WHOPR_LTRANS , "whopr ltrans")
-DEFTIMEVAR (TV_WHOPR_WPA_FIXUP , "whopr wpa fixup")
DEFTIMEVAR (TV_WHOPR_WPA_LTRANS_EXEC , "whopr wpa->ltrans")
DEFTIMEVAR (TV_IPA_REFERENCE , "ipa reference")
DEFTIMEVAR (TV_IPA_PURE_CONST , "ipa pure const")
Index: lto-section-in.c
===================================================================
--- lto-section-in.c (revision 158563)
+++ lto-section-in.c (working copy)
@@ -55,7 +55,6 @@ const char *lto_section_name[LTO_N_SECTI
"ipa_pure_const",
"ipa_reference",
"symtab",
- "wpa_fixup",
"opts"
};
Index: lto-wpa-fixup.c
===================================================================
--- lto-wpa-fixup.c (revision 158563)
+++ lto-wpa-fixup.c (working copy)
@@ -1,282 +0,0 @@
-/* Write and read any fix-up information generated by the WPA mode.
-
- Copyright 2009 Free Software Foundation, Inc.
- Contributed by Doug Kwan <dougkwan@google.com>
-
-This file is part of GCC.
-
-GCC is free software; you can redistribute it and/or modify it under
-the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 3, or (at your option) any later
-version.
-
-GCC is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-for more details.
-
-You should have received a copy of the GNU General Public License
-along with GCC; see the file COPYING3. If not see
-<http://www.gnu.org/licenses/>. */
-
-#include "config.h"
-#include "system.h"
-#include "coretypes.h"
-#include "tm.h"
-#include "toplev.h"
-#include "tree.h"
-#include "expr.h"
-#include "flags.h"
-#include "cgraph.h"
-#include "function.h"
-#include "diagnostic.h"
-#include "vec.h"
-#include "bitmap.h"
-#include "timevar.h"
-#include "tree-flow.h"
-#include "tree-pass.h"
-#include "lto-streamer.h"
-
-/* LTO fix-up.
-
- In WPA mode, LTO cannot access function bodies. Some modifications in
- IR require additional updates in function bodies, which are not possible
- in WPA mode. So we write out information about these modifications for
- LTRANS to fix up the function bodies accordingly. */
-
-/* The vectors records function DECLs having multiple copies with different
- exception throwing attributes. We do not mark a DECL if all copies of it
- have the same exception throwing attribute. */
-static bitmap lto_nothrow_fndecls;
-
-/* We need to fix up GIMPLE bodies due to changes in exception setting.
- Consider this example:
-
- a.h:
- class a {
- public:
- a();
- ~a();
- };
-
- main.cc:
- #include "a.h"
-
- int
- main (int argc, char **argv)
- {
- a x;
- return 0;
- }
-
- a.cc:
- #include "a.h"
- a::a() {}
- a::~a() {}
-
- When main.cc is compiled, gcc only sees the constructor declaration, so
- the constructor and hence the call to it are marked as exception throwing.
- When a.cc is compiled, the body of the constructor is available and is
- obviously not exception throwing. Thus DECL of a::a in a.o has the NOTHROW
- attribute. When LTO runs, two DECLs of a::a with different exception
- attributes are merged. We want the merged DECL to be not exception
- throwing for better generated code. To do that, we need to fix up any
- function calls that have been marked as exception throwing. */
-
-/* Fix up all the call statements whose target fndecls might have changed
- to NOTHROW. Note that this problem is not WPA specific. We can also
- run into this problem in normal LTO with multiple input files. */
-
-void
-lto_fixup_nothrow_decls (void)
-{
- struct cgraph_node *node;
- struct cgraph_edge *edge;
- struct function *caller_function;
- gimple call_stmt;
-
- /* Quit if we are in WPA mode or have not marked any DECLs. */
- if (flag_wpa || !lto_nothrow_fndecls)
- return;
-
- /* For each node that has been marked, go over all call edges to it. */
- for (node = cgraph_nodes; node; node = node->next)
- if (bitmap_bit_p (lto_nothrow_fndecls, DECL_UID (node->decl)))
- {
- gcc_assert (TREE_NOTHROW (node->decl));
- for (edge = node->callers; edge; edge = edge->next_caller)
- {
- caller_function = DECL_STRUCT_FUNCTION (edge->caller->decl);
- call_stmt = edge->call_stmt;
- gcc_assert (call_stmt);
- if (lookup_stmt_eh_lp_fn (caller_function, call_stmt) != 0)
- remove_stmt_from_eh_lp_fn (caller_function, call_stmt);
- }
- }
-}
-
-/* Mark FNDECL as becoming not exception throwing. */
-
-void
-lto_mark_nothrow_fndecl (tree fndecl)
-{
- gcc_assert (TREE_CODE (fndecl) == FUNCTION_DECL);
- if (!lto_nothrow_fndecls)
- lto_nothrow_fndecls = lto_bitmap_alloc ();
-
- bitmap_set_bit (lto_nothrow_fndecls, DECL_UID (fndecl));
-}
-
-/* Write out fix-up information. Currently the only WPA fix-up
- information is the list of DECLs marked as not exception throwing. SET
- is a cgraph node set whose fix-up information is to be written. */
-
-static void
-lto_output_wpa_fixup (cgraph_node_set set)
-{
- struct lto_simple_output_block *ob;
- cgraph_node_set_iterator csi;
- tree fndecl;
- bitmap seen_decls;
- VEC(tree, heap) *decls = NULL;
- unsigned HOST_WIDE_INT i, count;
-
- ob = lto_create_simple_output_block (LTO_section_wpa_fixup);
-
- /* Accumulate the DECLs to be written out. Since we do not want
- duplicates, we need to use a bitmap and a vector to save the
- DECLs we want. Note that we need to check if lto_nothrow_fndecls
- is NULL. This happens when no DECL has been marked. */
- seen_decls = lto_bitmap_alloc ();
- if (lto_nothrow_fndecls)
- for (csi = csi_start (set); !csi_end_p (csi); csi_next (&csi))
- {
- struct cgraph_edge *e;
- struct cgraph_node *n;
-
- n = csi_node (csi);
- fndecl = n->decl;
-
- /* Check if the N's function is in the set of nothrow functions. */
- if (!bitmap_bit_p (seen_decls, DECL_UID (fndecl)))
- {
- bitmap_set_bit (seen_decls, (DECL_UID (fndecl)));
- if (bitmap_bit_p (lto_nothrow_fndecls, DECL_UID (fndecl)))
- VEC_safe_push (tree, heap, decls, fndecl);
- }
-
- /* Now check the callees and also add them if they are nothrow. This
- is needed because node N may end up in a different partition than
- its callees. In which case, when the file holding N is compiled,
- the calls it makes to nothrow functions will not be fixed up,
- causing verification issues. */
- for (e = n->callees; e; e = e->next_callee)
- {
- fndecl = e->callee->decl;
- if (!bitmap_bit_p (seen_decls, DECL_UID (fndecl)))
- {
- bitmap_set_bit (seen_decls, (DECL_UID (fndecl)));
- if (bitmap_bit_p (lto_nothrow_fndecls, DECL_UID (fndecl)))
- VEC_safe_push (tree, heap, decls, fndecl);
- }
- }
- }
-
- /* Write out number of DECLs, followed by the DECLs. */
- count = VEC_length (tree, decls);
- lto_output_uleb128_stream (ob->main_stream, count);
- for (i = 0; i < count; i++)
- {
- fndecl = VEC_index (tree, decls, i);
- lto_output_fn_decl_index (ob->decl_state, ob->main_stream, fndecl);
- }
-
- /* Release resources. */
- lto_destroy_simple_output_block (ob);
- VEC_free(tree, heap, decls);
- lto_bitmap_free (seen_decls);
-}
-
-/* Read in WPA fix-up information from one file. FILE_DATA points to
- DECL information of the file where as IB is the input block for the
- WPA fix-up section. */
-
-static void
-lto_input_wpa_fixup_1 (struct lto_file_decl_data *file_data,
- struct lto_input_block *ib)
-{
- unsigned HOST_WIDE_INT i, count, decl_index;
- tree fndecl;
-
- count = lto_input_uleb128 (ib);
- for (i = 0; i < count; i++)
- {
- decl_index = lto_input_uleb128 (ib);
- fndecl = lto_file_decl_data_get_fn_decl (file_data, decl_index);
- lto_mark_nothrow_fndecl (fndecl);
- }
-}
-
-/* Read in WPA fix-up information. */
-
-static void
-lto_input_wpa_fixup (void)
-{
- struct lto_file_decl_data ** file_data_vec
- = lto_get_file_decl_data ();
- struct lto_file_decl_data * file_data;
- int i = 0;
-
- /* Fix up information is only used in LTRANS mode. */
- if (!flag_ltrans)
- return;
-
- while ((file_data = file_data_vec[i++]))
- {
- const char *data;
- size_t len;
- struct lto_input_block *ib
- = lto_create_simple_input_block (file_data, LTO_section_wpa_fixup,
- &data, &len);
-
- lto_input_wpa_fixup_1 (file_data, ib);
- lto_destroy_simple_input_block (file_data, LTO_section_wpa_fixup, ib,
- data, len);
- }
-}
-
-/* Gate function for all lto streaming passes. */
-
-static bool
-gate_wpa_fixup (void)
-{
- return (flag_wpa || flag_ltrans) && gate_lto_out ();
-}
-
-struct ipa_opt_pass_d pass_ipa_lto_wpa_fixup =
-{
- {
- IPA_PASS,
- "lto_wpa_fixup", /* name */
- gate_wpa_fixup, /* gate */
- NULL, /* execute */
- NULL, /* sub */
- NULL, /* next */
- 0, /* static_pass_number */
- TV_WHOPR_WPA_FIXUP, /* tv_id */
- 0, /* properties_required */
- 0, /* properties_provided */
- 0, /* properties_destroyed */
- 0, /* todo_flags_start */
- TODO_dump_func /* todo_flags_finish */
- },
- NULL, /* generate_summary */
- lto_output_wpa_fixup, /* write_summary */
- lto_input_wpa_fixup, /* read_summary */
- NULL, /* function_read_summary */
- NULL, /* stmt_fixup */
- 0, /* TODOs */
- NULL, /* function_transform */
- NULL /* variable_transform */
-};
-
Index: lto/lto.c
===================================================================
--- lto/lto.c (revision 158563)
+++ lto/lto.c (working copy)
@@ -1560,28 +1561,6 @@ lto_fixup_tree (tree *tp, int *walk_subt
if (t != prevailing)
{
- if (TREE_CODE (t) == FUNCTION_DECL
- && TREE_NOTHROW (prevailing) != TREE_NOTHROW (t))
- {
- /* If the prevailing definition does not throw but the
- declaration (T) was considered throwing, then we
- simply add PREVAILING to the list of throwing
- functions. However, if the opposite is true, then
- the call to PREVAILING was generated assuming that
- the function didn't throw, which means that CFG
- cleanup may have removed surrounding try/catch
- regions.
-
- Note that we currently accept these cases even when
- they occur within a single file. It's certainly a
- user error, but we silently allow the compiler to
- remove surrounding try/catch regions. Perhaps we
- could emit a warning here, instead of silently
- accepting the conflicting declaration. */
- if (TREE_NOTHROW (prevailing))
- lto_mark_nothrow_fndecl (prevailing);
- }
-
/* Also replace t with prevailing defintion. We don't want to
insert the other defintion in the seen set as we want to
replace all instances of it. */
@@ -1947,8 +1952,8 @@ materialize_cgraph (void)
for (i = 0; VEC_iterate (tree, lto_global_var_decls, i, decl); i++)
rest_of_decl_compilation (decl, 1, 0);
- /* Fix up any calls to DECLs that have become not exception throwing. */
- lto_fixup_nothrow_decls ();
+ if (!quiet_flag)
+ fprintf (stderr, "\n");
timevar_pop (lto_timer);
}
Index: Makefile.in
===================================================================
--- Makefile.in (revision 158563)
+++ Makefile.in (working copy)
@@ -1258,7 +1258,6 @@ OBJS-common = \
lto-symtab.o \
lto-opts.o \
lto-streamer.o \
- lto-wpa-fixup.o \
lto-compress.o \
mcf.o \
mode-switching.o \
@@ -2251,10 +2250,6 @@ lto-opts.o: lto-opts.c $(CONFIG_H) $(SYS
lto-streamer.o: lto-streamer.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
$(TM_H) $(TREE_H) $(GIMPLE_H) $(BITMAP_H) $(LTO_STREAMER_H) $(FLAGS_H) \
$(TREE_FLOW_H) $(DIAGNOSTIC_H) $(LTO_SYMTAB_H) $(TOPLEV_H)
-lto-wpa-fixup.o: lto-wpa-fixup.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
- $(TM_H) $(TOPLEV_H) $(TREE_H) $(EXPR_H) $(FLAGS_H) $(CGRAPH_H) \
- $(FUNCTION_H) $(DIAGNOSTIC_H) $(BITMAP_H) $(TIMEVAR_H) \
- $(TREE_FLOW_H) $(TREE_PASS_H) $(LTO_STREAMER_H)
langhooks.o : langhooks.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
$(TREE_H) $(TOPLEV_H) $(TREE_INLINE_H) $(RTL_H) insn-config.h $(INTEGRATE_H) \
langhooks.h $(TARGET_H) $(LANGHOOKS_DEF_H) $(FLAGS_H) $(GGC_H) $(DIAGNOSTIC_H) \
Index: passes.c
===================================================================
--- passes.c (revision 158563)
+++ passes.c (working copy)
@@ -814,7 +814,6 @@ init_optimization_passes (void)
p = &all_lto_gen_passes;
NEXT_PASS (pass_ipa_lto_gimple_out);
- NEXT_PASS (pass_ipa_lto_wpa_fixup);
NEXT_PASS (pass_ipa_lto_finish_out); /* This must be the last LTO pass. */
*p = NULL;
@@ -1487,10 +1486,20 @@ execute_one_ipa_transform_pass (struct c
void
execute_all_ipa_transforms (void)
{
+ enum cgraph_state old_state = cgraph_state;
struct cgraph_node *node;
if (!cfun)
return;
node = cgraph_node (current_function_decl);
+
+ /* Statement verification skip verification of nothorw when
+ state is IPA_SSA because we do not modify function bodies
+ after setting the flag on function. Instead we leave it
+ to fixup_cfg to do such a transformation. We need to temporarily
+ change the cgraph state so statement verifier before
+ transform do not fire. */
+ cgraph_state = CGRAPH_STATE_IPA_SSA;
+
if (node->ipa_transforms_to_apply)
{
unsigned int i;
@@ -1504,6 +1513,7 @@ execute_all_ipa_transforms (void)
VEC_free (ipa_opt_pass, heap, node->ipa_transforms_to_apply);
node->ipa_transforms_to_apply = NULL;
}
+ cgraph_state = old_state;
}
/* Execute PASS. */
Index: lto-streamer.c
===================================================================
--- lto-streamer.c (revision 158563)
+++ lto-streamer.c (working copy)
@@ -169,9 +169,6 @@ lto_get_section_name (int section_type,
case LTO_section_ipa_reference:
return concat (LTO_SECTION_NAME_PREFIX, ".reference", NULL);
- case LTO_section_wpa_fixup:
- return concat (LTO_SECTION_NAME_PREFIX, ".wpa_fixup", NULL);
-
case LTO_section_opts:
return concat (LTO_SECTION_NAME_PREFIX, ".opts", NULL);