This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[ast-optimizer-branch] Define new simplification langhook [patch]
- From: Diego Novillo <dnovillo at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 6 Jun 2002 00:05:13 -0400
- Subject: [ast-optimizer-branch] Define new simplification langhook [patch]
- Organization: Red Hat Canada
This patch introduces a new langhook for the simplifier and
enables -ftree-ssa at optimization levels >= 1.
I haven't dealt with langhooks much in the past. Could somebody
take a look and tell me what's missing? Is there any
documentation I should be updating for instance?
The patch bootstrap fine and it also uncovered a bug with
-Wunused. The simplifier will not check the status of the
warning flag when discarding expressions without side effects.
This produces these failures on the testsuite which I'll be
fixing shortly:
FAIL: gcc.dg/20020220-2.c (test for warnings
FAIL: gcc.dg/20020304-1.c (test for excess errors)
FAIL: gcc.dg/20020426-2.c execution test
FAIL: gcc.dg/uninit-A.c (test for excess errors)
2002-06-05 Diego Novillo <dnovillo@redhat.com>
* Makefile.in (BOOT_CFLAGS): Remove -ftree-ssa.
* c-decl.c (c_expand_body): Call optimize_function_tree if tree SSA
is enabled.
* c-lang.c (LANG_HOOKS_SIMPLIFY_FUNCTION_TREE): Define.
* c-simplify.c (simplify_tree): Rename to c_simplify_function_tree.
Update all callers.
Dump function body before and after simplification if
-fdump-tree-simple is used.
(simplify_expr): Document FIXME for simplification of BIT_FIELD_REF
nodes.
* c-tree.h (simplify_tree): Rename to c_simplify_function_tree.
* langhooks-def.h (LANG_HOOKS_SIMPLIFY_FUNCTION_TREE): Define
(LANGHOOKS_INITIALIZER): Add LANG_HOOKS_SIMPLIFY_FUNCTION_TREE.
(lhd_simplify_function_tree): Declare.
* langhooks.c (lhd_simplify_function_tree): New function.
* langhooks.h (lang_hooks): Add simplify_function_tree function
pointer.
* toplev.c (parse_options_and_default_flags): Set flag_tree_ssa to
1 at optimization levels >= 1.
Revert to default warning when -Wuninitialized is used without -O.
* tree-cfg.c (tree_find_basic_blocks): Rename argument 't' to
'fnbody'.
* tree-optimize.c: Include langhooks.h.
(optimize_tree): Rename to optimize_function_tree. Update all
users.
Rename argument 't' to 'fndecl'.
Call simplify langhook before building SSA.
(build_tree_ssa): Rename argument 't' to 'fndecl'.
Adjust call to tree_find_basic_blocks to pass body of the function.
* tree-optimize.h (optimize_tree): Rename to
optimize_function_tree.
* tree-simple.c (is_simple_unary_expr): Document FIXME on
BIT_FIELD_REF nodes.
* tree-ssa.c: Add whitespace.
* testsuite/lib/c-torture.exp: Remove -ftree-ssa flag.
Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Makefile.in,v
retrieving revision 1.701.2.30
diff -d -p -d -u -p -r1.701.2.30 Makefile.in
--- Makefile.in 3 Jun 2002 21:58:59 -0000 1.701.2.30
+++ Makefile.in 5 Jun 2002 23:55:53 -0000
@@ -67,7 +67,7 @@ XCFLAGS =
TCFLAGS =
CFLAGS = -g
STAGE1_CFLAGS = -g @stage1_cflags@
-BOOT_CFLAGS = -g -O2 -ftree-ssa
+BOOT_CFLAGS = -g -O2
# The warning flags are separate from BOOT_CFLAGS because people tend to
# override optimization flags and we'd like them to still have warnings
Index: c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.239.2.20
diff -d -p -d -u -p -r1.239.2.20 c-decl.c
--- c-decl.c 3 Jun 2002 21:59:01 -0000 1.239.2.20
+++ c-decl.c 5 Jun 2002 23:55:54 -0000
@@ -6885,55 +6885,7 @@ c_expand_body (fndecl, nested_p, can_def
/* Invoke the SSA tree optimizer. */
if (flag_tree_ssa)
- {
- FILE *dump_file;
- int dump_flags;
- tree fn = DECL_SAVED_TREE (fndecl);
-
- /* Debugging dump before simplification. */
- dump_file = dump_begin (TDI_simple, &dump_flags);
- if (dump_file)
- {
- fprintf (dump_file, "\n%s() (ORIGINAL)\n",
- IDENTIFIER_POINTER (DECL_NAME (current_function_decl)));
-
- if (dump_flags & TDF_UNPARSE)
- print_c_tree (dump_file, fn);
- else
- dump_node (fn, TDF_SLIM | dump_flags, dump_file);
-
- dump_end (TDI_simple, dump_file);
- }
-
- /* Simplify the function. */
- simplify_tree (fndecl);
-
-#if 0
- /* Transform BREAK_STMTs, CONTINUE_STMTs, SWITCH_STMTs and GOTO_STMTs. */
- double_chain_stmts (fn);
- break_continue_elimination (fndecl);
- goto_elimination (fndecl);
- double_chain_free (fn);
-#endif
-
- /* Debugging dump after simplification. */
- dump_file = dump_begin (TDI_simple, &dump_flags);
- if (dump_file)
- {
- fprintf (dump_file, "\n%s() (SIMPLIFIED)\n",
- IDENTIFIER_POINTER (DECL_NAME (current_function_decl)));
-
- if (dump_flags & TDF_UNPARSE)
- print_c_tree (dump_file, fn);
- else
- dump_node (fn, TDF_SLIM | dump_flags, dump_file);
-
- dump_end (TDI_simple, dump_file);
- }
-
- /* Apply the SSA optimizations. */
- optimize_tree (fn);
- }
+ optimize_function_tree (fndecl);
/* Set up parameters and prepare for return, for the function. */
expand_function_start (fndecl, 0);
Index: c-lang.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-lang.c,v
retrieving revision 1.53.2.7
diff -d -p -d -u -p -r1.53.2.7 c-lang.c
--- c-lang.c 29 May 2002 14:59:57 -0000 1.53.2.7
+++ c-lang.c 5 Jun 2002 23:55:54 -0000
@@ -114,6 +114,11 @@ static void c_init_options PARAMS ((void
#undef LANG_HOOKS_TYPE_PROMOTES_TO
#define LANG_HOOKS_TYPE_PROMOTES_TO c_type_promotes_to
+/* Hooks for tree simplification. */
+#undef LANG_HOOKS_SIMPLIFY_FUNCTION_TREE
+#define LANG_HOOKS_SIMPLIFY_FUNCTION_TREE \
+ c_simplify_function_tree
+
/* ### When changing hooks, consider if ObjC needs changing too!! ### */
/* Each front end provides its own. */
Index: c-simplify.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/c-simplify.c,v
retrieving revision 1.1.2.19
diff -d -p -d -u -p -r1.1.2.19 c-simplify.c
--- c-simplify.c 28 May 2002 01:29:55 -0000 1.1.2.19
+++ c-simplify.c 5 Jun 2002 23:55:54 -0000
@@ -100,27 +100,33 @@ static int stmt_expr_level;
/* Simplification of statement trees. */
-/** {{{ simplify_tree ()
+/** {{{ c_simplify_function_tree ()
- Entry point to the simplification pass. FN is the FUNCTION_DECL node
- for the function we want to simplify. */
+ Entry point to the simplification pass. FNDECL is the FUNCTION_DECL
+ node for the function we want to simplify. */
-void
-simplify_tree (fn)
- tree fn;
+int
+c_simplify_function_tree (fndecl)
+ tree fndecl;
{
- tree fn_body;
-
- /* Don't bother doing anything if the program has errors. */
- if (errorcount || sorrycount)
- return;
+ tree fnbody;
- fn_body = COMPOUND_BODY (DECL_SAVED_TREE (fn));
- if (fn_body == NULL)
- return;
+ fnbody = COMPOUND_BODY (DECL_SAVED_TREE (fndecl));
+ if (fnbody == NULL)
+ return 1;
/* Debugging dumps. */
dump_file = dump_begin (TDI_simple, &dump_flags);
+ if (dump_file)
+ {
+ fprintf (dump_file, "\n%s() (ORIGINAL)\n",
+ IDENTIFIER_POINTER (DECL_NAME (fndecl)));
+
+ if (dump_flags & TDF_UNPARSE)
+ print_c_tree (dump_file, fnbody);
+ else
+ dump_node (fnbody, TDF_SLIM | dump_flags, dump_file);
+ }
/* Create a new binding level for the temporaries created by the
simplification process. */
@@ -128,16 +134,29 @@ simplify_tree (fn)
/* Simplify the function's body. */
stmt_expr_level = 0;
- simplify_stmt (fn_body);
+ simplify_stmt (fnbody);
/* Declare the new temporary variables. */
- declare_tmp_vars (getdecls(), fn_body);
+ declare_tmp_vars (getdecls(), fnbody);
/* Restore the binding level. */
poplevel (1, 1, 0);
+ /* Debugging dump after simplification. */
if (dump_file)
- dump_end (TDI_simple, dump_file);
+ {
+ fprintf (dump_file, "\n%s() (SIMPLIFIED)\n",
+ IDENTIFIER_POINTER (DECL_NAME (fndecl)));
+
+ if (dump_flags & TDF_UNPARSE)
+ print_c_tree (dump_file, fnbody);
+ else
+ dump_node (fnbody, TDF_SLIM | dump_flags, dump_file);
+
+ dump_end (TDI_simple, dump_file);
+ }
+
+ return 1;
}
/* }}} */
@@ -1072,6 +1091,9 @@ simplify_expr (expr_p, pre_p, post_p, si
simplify_expr_wfl (expr_p, pre_p, post_p, simple_test_f, stmt);
break;
+ /* FIXME: This breaks stage2. I still haven't figured out why. When
+ fixing remember to undo a similar change in
+ is_simple_unary_expr. */
case BIT_FIELD_REF:
#if 0
simplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p, is_simple_id);
Index: c-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-tree.h,v
retrieving revision 1.64.2.11
diff -d -p -d -u -p -r1.64.2.11 c-tree.h
--- c-tree.h 29 May 2002 15:00:02 -0000 1.64.2.11
+++ c-tree.h 5 Jun 2002 23:55:54 -0000
@@ -388,7 +388,7 @@ extern tree static_ctors;
extern tree static_dtors;
/* In c-simplify.c */
-extern void simplify_tree PARAMS ((tree));
+extern int c_simplify_function_tree PARAMS ((tree));
/* In c-pretty-print.c */
extern void print_c_tree PARAMS ((FILE*, tree));
Index: langhooks-def.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/langhooks-def.h,v
retrieving revision 1.8.2.5
diff -d -p -d -u -p -r1.8.2.5 langhooks-def.h
--- langhooks-def.h 29 May 2002 15:02:45 -0000 1.8.2.5
+++ langhooks-def.h 5 Jun 2002 23:55:54 -0000
@@ langhooks-def.h PA
void lhd_tree_inlining_end_inlining PARAMS ((tree));
tree lhd_tree_inlining_convert_parm_for_inlining PARAMS ((tree, tree, tree));
+/* Declarations for tree simplification hooks. */
+int lhd_simplify_function_tree PARAMS ((tree));
+
#define LANG_HOOKS_NAME "GNU unknown"
#define LANG_HOOKS_IDENTIFIER_SIZE sizeof (struct lang_identifier)
#define LANG_HOOKS_INIT lhd_do_nothing
@@ -167,6 +170,10 @@ tree lhd_tree_inlining_convert_parm_for_
LANG_HOOKS_FUNCTION_MARK \
}
+/* Hooks for tree simplification. */
+#define LANG_HOOKS_SIMPLIFY_FUNCTION_TREE \
+ lhd_simplify_function_tree
+
/* Tree dump hooks. */
int lhd_tree_dump_dump_tree PARAMS ((void *, tree));
int lhd_tree_dump_type_quals PARAMS ((tree));
@@ -258,7 +265,8 @@ int lhd_tree_dump_type_quals PARAMS ((
LANG_HOOKS_TREE_INLINING_INITIALIZER, \
LANG_HOOKS_TREE_DUMP_INITIALIZER, \
LANG_HOOKS_DECLS, \
- LANG_HOOKS_FOR_TYPES_INITIALIZER \
+ LANG_HOOKS_FOR_TYPES_INITIALIZER, \
+ LANG_HOOKS_SIMPLIFY_FUNCTION_TREE \
}
#endif /* GCC_LANG_HOOKS_DEF_H */
Index: langhooks.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/langhooks.c,v
retrieving revision 1.14.2.5
diff -d -p -d -u -p -r1.14.2.5 langhooks.c
--- langhooks.c 3 Jun 2002 21:59:30 -0000 1.14.2.5
+++ langhooks.c 5 Jun 2002 23:55:54 -0000
@@ -421,3 +421,13 @@ lhd_tree_dump_type_quals (t)
{
return TYPE_QUALS (t);
}
+
+/* lang_hooks.simplify_function_tree re-writes the body of function FNDECL
+ into SIMPLE form. */
+
+int
+lhd_simplify_function_tree (fndecl)
+ tree fndecl ATTRIBUTE_UNUSED;
+{
+ return 0;
+}
Index: langhooks.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/langhooks.h,v
retrieving revision 1.15.2.6
diff -d -p -d -u -p -r1.15.2.6 langhooks.h
--- langhooks.h 3 Jun 2002 21:59:30 -0000 1.15.2.6
+++ langhooks.h 5 Jun 2002 23:55:54 -0000
@@ -351,6 +351,8 @@ struct lang_hooks
struct lang_hooks_for_types types;
+ int (*simplify_function_tree) PARAMS ((tree));
+
/* Whenever you add entries here, make sure you adjust langhooks-def.h
and langhooks.c accordingly. */
};
Index: toplev.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/toplev.c,v
retrieving revision 1.494.2.15
diff -d -p -d -u -p -r1.494.2.15 toplev.c
--- toplev.c 3 Jun 2002 21:59:34 -0000 1.494.2.15
+++ toplev.c 5 Jun 2002 23:55:56 -0000
@@ -4707,6 +4707,7 @@ parse_options_and_default_flags (argc, a
flag_crossjumping = 1;
flag_if_conversion = 1;
flag_if_conversion2 = 1;
+ flag_tree_ssa = 1;
}
if (optimize >= 2)
@@ -4854,10 +4855,8 @@ parse_options_and_default_flags (argc, a
/* The c_decode_option function and decode_option hook set
this to `2' if -Wall is used, so we can avoid giving out
- lots of errors for people who don't realize what -Wall does.
- However, when -ftree-ssa is used, -O is not necessary for finding
- uses of uninitialized variables. */
- if (warn_uninitialized == 1 && !flag_tree_ssa)
+ lots of errors for people who don't realize what -Wall does. */
+ if (warn_uninitialized == 1)
warning ("-Wuninitialized is not supported without -O");
}
Index: tree-cfg.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-cfg.c,v
retrieving revision 1.1.2.17
diff -d -p -d -u -p -r1.1.2.17 tree-cfg.c
--- tree-cfg.c 3 Jun 2002 21:59:36 -0000 1.1.2.17
+++ tree-cfg.c 5 Jun 2002 23:55:56 -0000
@@ -94,11 +94,12 @@ static void insert_after_loop_body PARAM
/* {{{ tree_find_basic_blocks()
- Entry point to the CFG builder for trees. */
+ Entry point to the CFG builder for trees. FNBODY is the body of the
+ function to process. */
void
-tree_find_basic_blocks (t)
- tree t;
+tree_find_basic_blocks (fnbody)
+ tree fnbody;
{
/* Initialize the basic block array. */
n_basic_blocks = 0;
@@ -116,7 +117,7 @@ tree_find_basic_blocks (t)
VARRAY_BB_INIT (binding_stack, 5, "binding_stack");
/* Find the basic blocks for the flowgraph. */
- make_blocks (t, NULL, NULL, NULL);
+ make_blocks (fnbody, NULL, NULL, NULL);
if (n_basic_blocks > 0)
{
Index: tree-optimize.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-optimize.c,v
retrieving revision 1.1.2.8
diff -d -p -d -u -p -r1.1.2.8 tree-optimize.c
--- tree-optimize.c 8 May 2002 21:14:32 -0000 1.1.2.8
+++ tree-optimize.c 5 Jun 2002 23:55:56 -0000
@@ -33,24 +33,41 @@ Boston, MA 02111-1307, USA. */
#include "flags.h"
#include "tree-optimize.h"
#include "tree-flow.h"
+#include "langhooks.h"
/* Local functions. */
static void init_tree_flow PARAMS ((void));
-/* {{{ optimize_tree()
+
+/* {{{ optimize_function_tree ()
Main entry point to the tree SSA transformation routines. */
void
-optimize_tree (t)
- tree t;
+optimize_function_tree (fndecl)
+ tree fndecl;
{
/* Don't bother doing anything if the program has errors. */
if (errorcount || sorrycount)
return;
+ /* Simplify the function. Don't try to optimize the function if
+ simplification failed. */
+ if (!(*lang_hooks.simplify_function_tree) (fndecl))
+ return;
+
+#if 0
+ /* Transform BREAK_STMTs, CONTINUE_STMTs, SWITCH_STMTs and GOTO_STMTs. */
+ double_chain_stmts (fn);
+ break_continue_elimination (fndecl);
+ goto_elimination (fndecl);
+ double_chain_free (fn);
+#endif
+
/* Build the SSA representation for the function. */
- build_tree_ssa (t);
+ build_tree_ssa (fndecl);
+
+ /* Begin optimization passes. */
if (n_basic_blocks > 0 && ! (errorcount || sorrycount))
if (flag_tree_ssa_pre)
tree_perform_ssapre ();
@@ -68,14 +85,14 @@ optimize_tree (t)
Main entry point to the tree SSA analysis routines. */
void
-build_tree_ssa (t)
- tree t;
+build_tree_ssa (fndecl)
+ tree fndecl;
{
/* Initialize flow data. */
init_flow ();
init_tree_flow ();
- tree_find_basic_blocks (t);
+ tree_find_basic_blocks (DECL_SAVED_TREE (fndecl));
if (n_basic_blocks > 0 && ! (errorcount || sorrycount))
{
Index: tree-optimize.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-optimize.h,v
retrieving revision 1.1.2.2
diff -d -p -d -u -p -r1.1.2.2 tree-optimize.h
--- tree-optimize.h 15 Oct 2001 01:06:59 -0000 1.1.2.2
+++ tree-optimize.h 5 Jun 2002 23:55:56 -0000
@@ -24,7 +24,7 @@ Boston, MA 02111-1307, USA. */
/* {{{ Function prototypes. */
-void optimize_tree PARAMS ((tree));
+void optimize_function_tree PARAMS ((tree));
void build_tree_ssa PARAMS ((tree));
/* }}} */
Index: tree-simple.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-simple.c,v
retrieving revision 1.1.2.10
diff -d -p -d -u -p -r1.1.2.10 tree-simple.c
--- tree-simple.c 28 May 2002 01:29:56 -0000 1.1.2.10
+++ tree-simple.c 5 Jun 2002 23:55:56 -0000
@@ -593,6 +593,8 @@ is_simple_unary_expr (t)
/* Addition to the original grammar. Allow BIT_FIELD_REF nodes where
operand 0 is a SIMPLE identifier and operands 1 and 2 are SIMPLE
values. */
+ /* FIXME: This breaks stage2. I still haven't figured out why. When
+ fixing remember to undo a similar change in simplify_expr. */
if (TREE_CODE (t) == BIT_FIELD_REF)
return 1;
#if 0
Index: tree-ssa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa.c,v
retrieving revision 1.1.2.14
diff -d -p -d -u -p -r1.1.2.14 tree-ssa.c
--- tree-ssa.c 3 Jun 2002 21:59:38 -0000 1.1.2.14
+++ tree-ssa.c 5 Jun 2002 23:56:08 -0000
@@ -40,6 +40,7 @@ Boston, MA 02111-1307, USA. */
this would require a shared function-as-trees infrastructure. */
#include "c-common.h"
#include "bitmap.h"
+
/* Nonzero to warn about variables used before they are initialized. Used
by analyze_rdefs(). */
Index: testsuite/lib/c-torture.exp
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/lib/c-torture.exp,v
retrieving revision 1.16.10.2
diff -d -p -d -u -p -r1.16.10.2 c-torture.exp
--- testsuite/lib/c-torture.exp 29 May 2002 15:08:34 -0000 1.16.10.2
+++ testsuite/lib/c-torture.exp 5 Jun 2002 23:56:24 -0000
@@ -33,14 +33,14 @@ if ![info exists TORTURE_OPTIONS] {
# items below, even though -O3 is also specified, because some ports may
# choose to disable inlining functions by default, even when optimizing.
set TORTURE_OPTIONS [list \
- { -O0 -ftree-ssa -Wunreachable-code -Wuninitialized } \
- { -O1 -ftree-ssa -Wunreachable-code -Wuninitialized } \
- { -O2 -ftree-ssa -Wunreachable-code -Wuninitialized } \
- { -O3 -fomit-frame-pointer -ftree-ssa -Wunreachable-code -Wuninitialized } \
- { -O3 -fomit-frame-pointer -funroll-loops -ftree-ssa -Wunreachable-code -Wuninitialized } \
- { -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions -ftree-ssa -Wunreachable-code -Wuninitialized } \
- { -O3 -g -ftree-ssa -Wunreachable-code -Wuninitialized } \
- { -Os -ftree-ssa -Wunreachable-code -Wuninitialized } ]
+ { -O0 } \
+ { -O1 } \
+ { -O2 } \
+ { -O3 -fomit-frame-pointer } \
+ { -O3 -fomit-frame-pointer -funroll-loops } \
+ { -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions } \
+ { -O3 -g } \
+ { -Os } ]
}