This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Make EXIT_BLOCK_EXPR and LABELED_BLOCK_EXPR Java specific nodes
- From: Steven Bosscher <stevenb at suse dot de>
- To: gcc-patches at gcc dot gnu dot org, java-patches at gcc dot gnu dot org
- Date: Fri, 19 Nov 2004 00:24:19 +0100
- Subject: Make EXIT_BLOCK_EXPR and LABELED_BLOCK_EXPR Java specific nodes
- Organization: SUSE Labs
Hi,
These two nodes from the subject are only used by Java, so
I've turned them into language specific tree nodes.
Bootstrapped and tested c,c++,java on x86_64-suse-linux-gnu.
OK?
Gr.
Steven
gcc/
* expr.c (expand_expr_real_1): Remove cases for EXIT_BLOCK_EXPR
and LABELED_BLOCK_EXPR.
* gimplify.c (gimplify_labeled_block_expr): Remove.
(gimplify_exit_block_expr): Remove.
(gimplify_expr): Don't call them.
* tree-inline.c (copy_body_r): Don't handle EXIT_BLOCK_EXPR
and LABELED_BLOCK_EXPR.
(estimate_num_insns_1): Likewise.
(walk_tree): Likewise.
* tree-pretty-print.c (dump_generic_node): Don't handle
EXIT_BLOCK_EXPR and LABELED_BLOCK_EXPR.
* tree.def (EXIT_BLOCK_EXPR): Moved to java-tree.def.
(LABELED_BLOCK_EXPR): Likewise.
* tree.h (LABELED_BLOCK_LABEL): Moved to java-tree.h.
(LABELED_BLOCK_BODY): Likewise.
(EXIT_BLOCK_LABELED_BLOCK): Likewise.
(EXIT_BLOCK_RETURN): Removed.
java/
* java-gimplify.c (java_gimplify_labeled_block_expr): New function.
(java_gimplify_exit_block_expr): New function.
(java_gimplify_expr): Use them to gimplify EXIT_BLOCK_EXPR and
LABELED_BLOCK_EXPR.
* java-tree.def (LABELED_BLOCK_EXPR): Moved from tree.def.
(EXIT_BLOCK_EXPR): Likewise.
* java-tree.h (LABELED_BLOCK_LABEL): Moved from tree.h.
(LABELED_BLOCK_BODY): Likewise.
(EXIT_BLOCK_LABELED_BLOCK): Likewise.
* jcf-write.c (generate_bytecode_insns): Don't handle the unused
EXIT_BLOCK_RETURN operand. Use EXIT_BLOCK_LABELED_BLOCK instead of
TREE_OPERAND.
* lang.c (java_tree_inlining_walk_subtrees): Handle EXIT_BLOCK_EXPR.
(java_dump_tree): Use LABELED_BLOCK_LABEL, LABELED_BLOCK_BODY, and
EXIT_BLOCK_LABELED_BLOCK instead of TREE_OPERAND. Don't handle the
second operand of EXIT_BLOCK_EXPR.
* parse.y (find_expr_with_wfl): Use LABELED_BLOCK_BODY instead of
TREE_OPERAND.
(build_bc_statement): Use build1 to build EXIT_BLOCK_EXPR nodes.
Index: expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/expr.c,v
retrieving revision 1.741
diff -u -3 -p -r1.741 expr.c
--- expr.c 14 Nov 2004 13:05:19 -0000 1.741
+++ expr.c 18 Nov 2004 22:58:23 -0000
@@ -8137,8 +8137,6 @@ expand_expr_real_1 (tree exp, rtx target
case POSTDECREMENT_EXPR:
case LOOP_EXPR:
case EXIT_EXPR:
- case LABELED_BLOCK_EXPR:
- case EXIT_BLOCK_EXPR:
case TRUTH_ANDIF_EXPR:
case TRUTH_ORIF_EXPR:
/* Lowered by gimplify.c. */
Index: gimplify.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gimplify.c,v
retrieving revision 2.85
diff -u -3 -p -r2.85 gimplify.c
--- gimplify.c 13 Nov 2004 21:11:04 -0000 2.85
+++ gimplify.c 18 Nov 2004 22:58:24 -0000
@@ -1210,43 +1210,6 @@ gimplify_case_label_expr (tree *expr_p)
return GS_ALL_DONE;
}
-/* Gimplify a LABELED_BLOCK_EXPR into a LABEL_EXPR following
- a (possibly empty) body. */
-
-static enum gimplify_status
-gimplify_labeled_block_expr (tree *expr_p)
-{
- tree body = LABELED_BLOCK_BODY (*expr_p);
- tree label = LABELED_BLOCK_LABEL (*expr_p);
- tree t;
-
- DECL_CONTEXT (label) = current_function_decl;
- t = build (LABEL_EXPR, void_type_node, label);
- if (body != NULL_TREE)
- t = build (COMPOUND_EXPR, void_type_node, body, t);
- *expr_p = t;
-
- return GS_OK;
-}
-
-/* Gimplify a EXIT_BLOCK_EXPR into a GOTO_EXPR. */
-
-static enum gimplify_status
-gimplify_exit_block_expr (tree *expr_p)
-{
- tree labeled_block = TREE_OPERAND (*expr_p, 0);
- tree label;
-
- /* First operand must be a LABELED_BLOCK_EXPR, which should
- already be lowered (or partially lowered) when we get here. */
- gcc_assert (TREE_CODE (labeled_block) == LABELED_BLOCK_EXPR);
-
- label = LABELED_BLOCK_LABEL (labeled_block);
- *expr_p = build1 (GOTO_EXPR, void_type_node, label);
-
- return GS_OK;
-}
-
/* Build a GOTO to the LABEL_DECL pointed to by LABEL_P, building it first
if necessary. */
@@ -3703,14 +3666,6 @@ gimplify_expr (tree *expr_p, tree *pre_p
ret = gimplify_switch_expr (expr_p, pre_p);
break;
- case LABELED_BLOCK_EXPR:
- ret = gimplify_labeled_block_expr (expr_p);
- break;
-
- case EXIT_BLOCK_EXPR:
- ret = gimplify_exit_block_expr (expr_p);
- break;
-
case EXIT_EXPR:
ret = gimplify_exit_expr (expr_p);
break;
Index: tree-inline.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-inline.c,v
retrieving revision 1.150
diff -u -3 -p -r1.150 tree-inline.c
--- tree-inline.c 8 Nov 2004 22:40:08 -0000 1.150
+++ tree-inline.c 18 Nov 2004 22:58:24 -0000
@@ -512,25 +512,6 @@ copy_body_r (tree *tp, int *walk_subtree
remap_save_expr (tp, id->decl_map, walk_subtrees);
else if (TREE_CODE (*tp) == BIND_EXPR)
copy_bind_expr (tp, walk_subtrees, id);
- else if (TREE_CODE (*tp) == LABELED_BLOCK_EXPR)
- {
- /* We need a new copy of this labeled block; the EXIT_BLOCK_EXPR
- will refer to it, so save a copy ready for remapping. We
- save it in the decl_map, although it isn't a decl. */
- tree new_block = copy_node (*tp);
- insert_decl_map (id, *tp, new_block);
- *tp = new_block;
- }
- else if (TREE_CODE (*tp) == EXIT_BLOCK_EXPR)
- {
- splay_tree_node n
- = splay_tree_lookup (id->decl_map,
- (splay_tree_key) TREE_OPERAND (*tp, 0));
- /* We _must_ have seen the enclosing LABELED_BLOCK_EXPR. */
- gcc_assert (n);
- *tp = copy_node (*tp);
- TREE_OPERAND (*tp, 0) = (tree) n->value;
- }
/* Types may need remapping as well. */
else if (TYPE_P (*tp))
*tp = remap_type (*tp, id);
@@ -1174,14 +1155,12 @@ estimate_num_insns_1 (tree *tp, int *wal
case FILTER_EXPR: /* ??? */
case COMPOUND_EXPR:
case BIND_EXPR:
- case LABELED_BLOCK_EXPR:
case WITH_CLEANUP_EXPR:
case NOP_EXPR:
case VIEW_CONVERT_EXPR:
case SAVE_EXPR:
case ADDR_EXPR:
case COMPLEX_EXPR:
- case EXIT_BLOCK_EXPR:
case CASE_LABEL_EXPR:
case SSA_NAME:
case CATCH_EXPR:
@@ -2080,8 +2059,7 @@ walk_tree (tree *tp, walk_tree_fn func,
}
}
- else if (code != EXIT_BLOCK_EXPR
- && code != SAVE_EXPR
+ else if (code != SAVE_EXPR
&& code != BIND_EXPR
&& IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code)))
{
@@ -2171,9 +2149,6 @@ walk_tree (tree *tp, walk_tree_fn func,
case CONSTRUCTOR:
WALK_SUBTREE_TAIL (CONSTRUCTOR_ELTS (*tp));
- case EXIT_BLOCK_EXPR:
- WALK_SUBTREE_TAIL (TREE_OPERAND (*tp, 1));
-
case SAVE_EXPR:
WALK_SUBTREE_TAIL (TREE_OPERAND (*tp, 0));
Index: tree-pretty-print.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-pretty-print.c,v
retrieving revision 2.47
diff -u -3 -p -r2.47 tree-pretty-print.c
--- tree-pretty-print.c 27 Oct 2004 17:45:20 -0000 2.47
+++ tree-pretty-print.c 18 Nov 2004 22:58:24 -0000
@@ -1247,48 +1247,6 @@ dump_generic_node (pretty_printer *buffe
pp_string (buffer, " [non-local]");
break;
- case LABELED_BLOCK_EXPR:
- op0 = LABELED_BLOCK_LABEL (node);
- /* If this is for break or continue, don't bother printing it. */
- if (DECL_NAME (op0))
- {
- const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
- if (strcmp (name, "break") == 0
- || strcmp (name, "continue") == 0)
- {
- dump_generic_node (buffer, LABELED_BLOCK_BODY (node), spc, flags, false);
- break;
- }
- }
- dump_generic_node (buffer, LABELED_BLOCK_LABEL (node), spc, flags, false);
- pp_string (buffer, ": {");
- if (!(flags & TDF_SLIM))
- newline_and_indent (buffer, spc+2);
- dump_generic_node (buffer, LABELED_BLOCK_BODY (node), spc+2, flags, true);
- if (!flags)
- newline_and_indent (buffer, spc);
- pp_character (buffer, '}');
- is_expr = false;
- break;
-
- case EXIT_BLOCK_EXPR:
- op0 = LABELED_BLOCK_LABEL (EXIT_BLOCK_LABELED_BLOCK (node));
- /* If this is for a break or continue, print it accordingly. */
- if (DECL_NAME (op0))
- {
- const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
- if (strcmp (name, "break") == 0
- || strcmp (name, "continue") == 0)
- {
- pp_string (buffer, name);
- break;
- }
- }
- pp_string (buffer, "<<<exit block ");
- dump_generic_node (buffer, op0, spc, flags, false);
- pp_string (buffer, ">>>");
- break;
-
case EXC_PTR_EXPR:
pp_string (buffer, "<<<exception object>>>");
break;
Index: tree.def
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.def,v
retrieving revision 1.103
diff -u -3 -p -r1.103 tree.def
--- tree.def 28 Sep 2004 13:14:28 -0000 1.103
+++ tree.def 18 Nov 2004 22:58:24 -0000
@@ -499,11 +499,6 @@ DEFTREECODE (VEC_COND_EXPR, "vec_cond_ex
nodes for the function. */
DEFTREECODE (BIND_EXPR, "bind_expr", tcc_expression, 3)
-/* A labeled block. Operand 0 is the label that will be generated to
- mark the end of the block.
- Operand 1 is the labeled block body. */
-DEFTREECODE (LABELED_BLOCK_EXPR, "labeled_block_expr", tcc_expression, 2)
-
/* Function call. Operand 0 is the function.
Operand 1 is the argument list, a list of expressions
made out of a chain of TREE_LIST nodes.
@@ -806,11 +801,6 @@ DEFTREECODE (EXIT_EXPR, "exit_expr", tcc
The type should be void and the value should be ignored. */
DEFTREECODE (LOOP_EXPR, "loop_expr", tcc_statement, 1)
-/* Exit a labeled block, possibly returning a value. Operand 0 is a
- LABELED_BLOCK_EXPR to exit. Operand 1 is the value to return. It
- may be left null. */
-DEFTREECODE (EXIT_BLOCK_EXPR, "exit_block_expr", tcc_statement, 2)
-
/* Switch expression.
TREE_TYPE is the original type of the condition, before any
Index: tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.h,v
retrieving revision 1.657
diff -u -3 -p -r1.657 tree.h
--- tree.h 17 Nov 2004 22:06:00 -0000 1.657
+++ tree.h 18 Nov 2004 22:58:25 -0000
@@ -1157,17 +1157,6 @@ struct tree_vec GTY(())
#define REF_ORIGINAL(NODE) TREE_CHAIN (TREE_CHECK3 (NODE, \
INDIRECT_REF, ALIGN_INDIRECT_REF, MISALIGNED_INDIRECT_REF))
-/* In a LABELED_BLOCK_EXPR node. */
-#define LABELED_BLOCK_LABEL(NODE) \
- TREE_OPERAND_CHECK_CODE (NODE, LABELED_BLOCK_EXPR, 0)
-#define LABELED_BLOCK_BODY(NODE) \
- TREE_OPERAND_CHECK_CODE (NODE, LABELED_BLOCK_EXPR, 1)
-
-/* In an EXIT_BLOCK_EXPR node. */
-#define EXIT_BLOCK_LABELED_BLOCK(NODE) \
- TREE_OPERAND_CHECK_CODE (NODE, EXIT_BLOCK_EXPR, 0)
-#define EXIT_BLOCK_RETURN(NODE) TREE_OPERAND_CHECK_CODE (NODE, EXIT_BLOCK_EXPR, 1)
-
/* In a LOOP_EXPR node. */
#define LOOP_EXPR_BODY(NODE) TREE_OPERAND_CHECK_CODE (NODE, LOOP_EXPR, 0)
Index: java/java-gimplify.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/java-gimplify.c,v
retrieving revision 1.16
diff -u -3 -p -r1.16 java-gimplify.c
--- java/java-gimplify.c 30 Sep 2004 02:16:45 -0000 1.16
+++ java/java-gimplify.c 18 Nov 2004 22:58:28 -0000
@@ -32,6 +32,8 @@ The Free Software Foundation is independ
#include "tree-gimple.h"
#include "toplev.h"
+static tree java_gimplify_labeled_block_expr (tree);
+static tree java_gimplify_exit_block_expr (tree);
static tree java_gimplify_case_expr (tree);
static tree java_gimplify_default_expr (tree);
static tree java_gimplify_block (tree);
@@ -79,6 +81,14 @@ java_gimplify_expr (tree *expr_p, tree *
SET_EXPR_LOCATION (*expr_p, input_location);
break;
+ case LABELED_BLOCK_EXPR:
+ *expr_p = java_gimplify_labeled_block_expr (*expr_p);
+ break;
+
+ case EXIT_BLOCK_EXPR:
+ *expr_p = java_gimplify_exit_block_expr (*expr_p);
+ break;
+
case CASE_EXPR:
*expr_p = java_gimplify_case_expr (*expr_p);
break;
@@ -164,6 +174,39 @@ java_gimplify_expr (tree *expr_p, tree *
return GS_OK;
}
+/* Gimplify a LABELED_BLOCK_EXPR into a LABEL_EXPR following
+ a (possibly empty) body. */
+
+static tree
+java_gimplify_labeled_block_expr (tree expr)
+{
+ tree body = LABELED_BLOCK_BODY (expr);
+ tree label = LABELED_BLOCK_LABEL (expr);
+ tree t;
+
+ DECL_CONTEXT (label) = current_function_decl;
+ t = build (LABEL_EXPR, void_type_node, label);
+ if (body != NULL_TREE)
+ t = build (COMPOUND_EXPR, void_type_node, body, t);
+ return t;
+}
+
+/* Gimplify a EXIT_BLOCK_EXPR into a GOTO_EXPR. */
+
+static tree
+java_gimplify_exit_block_expr (tree expr)
+{
+ tree labeled_block = EXIT_BLOCK_LABELED_BLOCK (expr);
+ tree label;
+
+ /* First operand must be a LABELED_BLOCK_EXPR, which should
+ already be lowered (or partially lowered) when we get here. */
+ gcc_assert (TREE_CODE (labeled_block) == LABELED_BLOCK_EXPR);
+
+ label = LABELED_BLOCK_LABEL (labeled_block);
+ return build1 (GOTO_EXPR, void_type_node, label);
+}
+
/* This is specific to the bytecode compiler. If a variable has
LOCAL_SLOT_P set, replace an assignment to it with an assignment to
the corresponding variable that holds all its aliases. */
Index: java/java-tree.def
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/java-tree.def,v
retrieving revision 1.20
diff -u -3 -p -r1.20 java-tree.def
--- java/java-tree.def 30 Sep 2004 02:16:00 -0000 1.20
+++ java/java-tree.def 18 Nov 2004 22:58:28 -0000
@@ -41,6 +41,14 @@ DEFTREECODE (NEW_CLASS_EXPR, "new_class_
/* Defines `this' as an expression. */
DEFTREECODE (THIS_EXPR, "this", tcc_unary, 0)
+/* A labeled block. Operand 0 is the label that will be generated to
+ mark the end of the block. Operand 1 is the labeled block body. */
+DEFTREECODE (LABELED_BLOCK_EXPR, "labeled_block_expr", tcc_expression, 2)
+
+/* Exit a labeled block, possibly returning a value. Operand 0 is a
+ LABELED_BLOCK_EXPR to exit. */
+DEFTREECODE (EXIT_BLOCK_EXPR, "exit_block_expr", tcc_statement, 1)
+
/* Case statement expression.
Operand 1 is the case value. */
DEFTREECODE (CASE_EXPR, "case", tcc_expression, 1)
Index: java/java-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/java-tree.h,v
retrieving revision 1.220
diff -u -3 -p -r1.220 java-tree.h
--- java/java-tree.h 5 Oct 2004 17:07:13 -0000 1.220
+++ java/java-tree.h 18 Nov 2004 22:58:29 -0000
@@ -1815,6 +1815,16 @@ enum
#undef DEBUG_JAVA_BINDING_LEVELS
+/* In a LABELED_BLOCK_EXPR node. */
+#define LABELED_BLOCK_LABEL(NODE) \
+ TREE_OPERAND_CHECK_CODE (NODE, LABELED_BLOCK_EXPR, 0)
+#define LABELED_BLOCK_BODY(NODE) \
+ TREE_OPERAND_CHECK_CODE (NODE, LABELED_BLOCK_EXPR, 1)
+
+/* In an EXIT_BLOCK_EXPR node. */
+#define EXIT_BLOCK_LABELED_BLOCK(NODE) \
+ TREE_OPERAND_CHECK_CODE (NODE, EXIT_BLOCK_EXPR, 0)
+
/* In an EXPR_WITH_FILE_LOCATION node. */
#define EXPR_WFL_EMIT_LINE_NOTE(NODE) \
(EXPR_WITH_FILE_LOCATION_CHECK (NODE)->common.public_flag)
Index: java/jcf-write.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/jcf-write.c,v
retrieving revision 1.157
diff -u -3 -p -r1.157 jcf-write.c
--- java/jcf-write.c 30 Sep 2004 02:16:45 -0000 1.157
+++ java/jcf-write.c 18 Nov 2004 22:58:29 -0000
@@ -1898,8 +1898,7 @@ generate_bytecode_insns (tree exp, int t
case EXIT_BLOCK_EXPR:
{
struct jcf_block *label = state->labeled_blocks;
- if (TREE_OPERAND (exp, 1) != NULL) goto notimpl;
- while (label->u.labeled_block != TREE_OPERAND (exp, 0))
+ while (label->u.labeled_block != EXIT_BLOCK_LABELED_BLOCK (exp))
label = label->next;
call_cleanups (label, state);
emit_goto (label, state);
@@ -2653,7 +2652,6 @@ generate_bytecode_insns (tree exp, int t
}
}
/* fall through */
- notimpl:
default:
error("internal error in generate_bytecode_insn - tree code not implemented: %s",
tree_code_name [(int) TREE_CODE (exp)]);
Index: java/lang.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/lang.c,v
retrieving revision 1.162
diff -u -3 -p -r1.162 lang.c
--- java/lang.c 15 Oct 2004 18:43:10 -0000 1.162
+++ java/lang.c 18 Nov 2004 22:58:29 -0000
@@ -731,6 +731,10 @@ java_tree_inlining_walk_subtrees (tree *
WALK_SUBTREE (BLOCK_EXPR_BODY (t));
return NULL_TREE;
+ case EXIT_BLOCK_EXPR:
+ *subtrees = 0;
+ return NULL_TREE;
+
default:
return NULL_TREE;
}
@@ -921,13 +925,12 @@ java_dump_tree (void *dump_info, tree t)
return true;
case LABELED_BLOCK_EXPR:
- dump_child ("label", TREE_OPERAND (t, 0));
- dump_child ("block", TREE_OPERAND (t, 1));
+ dump_child ("label", LABELED_BLOCK_LABEL (t));
+ dump_child ("block", LABELED_BLOCK_BODY (t));
return true;
case EXIT_BLOCK_EXPR:
- dump_child ("block", TREE_OPERAND (t, 0));
- dump_child ("val", TREE_OPERAND (t, 1));
+ dump_child ("block", EXIT_BLOCK_LABELED_BLOCK (t));
return true;
case BLOCK:
Index: java/parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.520
diff -u -3 -p -r1.520 parse.y
--- java/parse.y 9 Nov 2004 14:33:32 -0000 1.520
+++ java/parse.y 18 Nov 2004 22:58:31 -0000
@@ -3255,7 +3255,7 @@ find_expr_with_wfl (tree node)
continue;
case LABELED_BLOCK_EXPR:
- node = TREE_OPERAND (node, 1);
+ node = LABELED_BLOCK_BODY (node);
continue;
default:
@@ -11747,8 +11747,6 @@ java_complete_lhs (tree node)
return node;
case EXIT_BLOCK_EXPR:
- /* We don't complete operand 1, because it's the return value of
- the EXIT_BLOCK_EXPR which doesn't exist it Java */
return patch_bc_statement (node);
case CASE_EXPR:
@@ -15269,8 +15267,7 @@ build_bc_statement (int location, int is
}
/* Unlabeled break/continue will be handled during the
break/continue patch operation */
- break_continue = build2 (EXIT_BLOCK_EXPR, NULL_TREE,
- label_block_expr, NULL_TREE);
+ break_continue = build1 (EXIT_BLOCK_EXPR, NULL_TREE, label_block_expr);
IS_BREAK_STMT_P (break_continue) = is_break;
TREE_SIDE_EFFECTS (break_continue) = 1;