]> gcc.gnu.org Git - gcc.git/blob - gcc/java/java-gimplify.c
re PR middle-end/23401 (Gimplifier produces too many temporaries)
[gcc.git] / gcc / java / java-gimplify.c
1 /* Java(TM) language-specific gimplification routines.
2 Copyright (C) 2003, 2004, 2006, 2007, 2007, 2008
3 Free Software Foundation, Inc.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
11
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>.
20
21 Java and all Java-based marks are trademarks or registered trademarks
22 of Sun Microsystems, Inc. in the United States and other countries.
23 The Free Software Foundation is independent of Sun Microsystems, Inc. */
24
25 #include "config.h"
26 #include "system.h"
27 #include "coretypes.h"
28 #include "tm.h"
29 #include "tree.h"
30 #include "java-tree.h"
31 #include "tree-dump.h"
32 #include "gimple.h"
33 #include "toplev.h"
34
35 static tree java_gimplify_block (tree);
36 static enum gimplify_status java_gimplify_modify_expr (tree *);
37 static enum gimplify_status java_gimplify_self_mod_expr (tree *, gimple_seq *,
38 gimple_seq *);
39
40 static void dump_java_tree (enum tree_dump_index, tree);
41
42 /* Convert a Java tree to GENERIC. */
43
44 void
45 java_genericize (tree fndecl)
46 {
47 dump_java_tree (TDI_original, fndecl);
48
49 /* Genericize with the gimplifier. */
50 gimplify_function_tree (fndecl);
51
52 dump_function (TDI_generic, fndecl);
53 }
54
55 /* Gimplify a Java tree. */
56
57 int
58 java_gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p)
59 {
60 enum tree_code code = TREE_CODE (*expr_p);
61
62 switch (code)
63 {
64 case BLOCK:
65 *expr_p = java_gimplify_block (*expr_p);
66 break;
67
68 case VAR_DECL:
69 *expr_p = java_replace_reference (*expr_p, /* want_lvalue */ false);
70 return GS_UNHANDLED;
71
72 case MODIFY_EXPR:
73 return java_gimplify_modify_expr (expr_p);
74
75 case SAVE_EXPR:
76 /* Note that we can see <save_expr NULL> if the save_expr was
77 already handled by gimplify_save_expr. */
78 if (TREE_OPERAND (*expr_p, 0) != NULL_TREE
79 && TREE_CODE (TREE_OPERAND (*expr_p, 0)) == VAR_DECL)
80 TREE_OPERAND (*expr_p, 0)
81 = java_replace_reference (TREE_OPERAND (*expr_p, 0),
82 /* want_lvalue */ false);
83 return GS_UNHANDLED;
84
85 case POSTINCREMENT_EXPR:
86 case POSTDECREMENT_EXPR:
87 case PREINCREMENT_EXPR:
88 case PREDECREMENT_EXPR:
89 return java_gimplify_self_mod_expr (expr_p, pre_p, post_p);
90
91 /* These should already be lowered before we get here. */
92 case URSHIFT_EXPR:
93 case COMPARE_EXPR:
94 case COMPARE_L_EXPR:
95 case COMPARE_G_EXPR:
96 gcc_unreachable ();
97
98 default:
99 return GS_UNHANDLED;
100 }
101
102 return GS_OK;
103 }
104
105 static enum gimplify_status
106 java_gimplify_modify_expr (tree *modify_expr_p)
107 {
108 tree modify_expr = *modify_expr_p;
109 tree lhs = TREE_OPERAND (modify_expr, 0);
110 tree rhs = TREE_OPERAND (modify_expr, 1);
111 tree lhs_type = TREE_TYPE (lhs);
112
113 /* This is specific to the bytecode compiler. If a variable has
114 LOCAL_SLOT_P set, replace an assignment to it with an assignment
115 to the corresponding variable that holds all its aliases. */
116 if (TREE_CODE (lhs) == VAR_DECL
117 && DECL_LANG_SPECIFIC (lhs)
118 && LOCAL_SLOT_P (lhs)
119 && TREE_CODE (lhs_type) == POINTER_TYPE)
120 {
121 tree new_lhs = java_replace_reference (lhs, /* want_lvalue */ true);
122 tree new_rhs = build1 (NOP_EXPR, TREE_TYPE (new_lhs), rhs);
123 modify_expr = build2 (MODIFY_EXPR, TREE_TYPE (new_lhs),
124 new_lhs, new_rhs);
125 modify_expr = build1 (NOP_EXPR, lhs_type, modify_expr);
126 }
127 else if (lhs_type != TREE_TYPE (rhs))
128 /* Fix up type mismatches to make legal GIMPLE. These are
129 generated in several places, in particular null pointer
130 assignment and subclass assignment. */
131 TREE_OPERAND (modify_expr, 1) = convert (lhs_type, rhs);
132
133 *modify_expr_p = modify_expr;
134 return GS_UNHANDLED;
135 }
136
137 /* Special case handling for volatiles: we need to generate a barrier
138 between the reading and the writing. */
139
140 static enum gimplify_status
141 java_gimplify_self_mod_expr (tree *expr_p, gimple_seq *pre_p ATTRIBUTE_UNUSED,
142 gimple_seq *post_p ATTRIBUTE_UNUSED)
143 {
144 tree lhs = TREE_OPERAND (*expr_p, 0);
145
146 if (TREE_CODE (lhs) == COMPONENT_REF
147 && TREE_THIS_VOLATILE (TREE_OPERAND (lhs, 1)))
148 TREE_THIS_VOLATILE (lhs) = 1;
149
150 return GS_UNHANDLED;
151 }
152
153
154 /* Gimplify BLOCK into a BIND_EXPR. */
155
156 static tree
157 java_gimplify_block (tree java_block)
158 {
159 tree decls = BLOCK_VARS (java_block);
160 tree body = BLOCK_EXPR_BODY (java_block);
161 gimple outer = gimple_current_bind_expr ();
162 tree block;
163
164 /* Don't bother with empty blocks. */
165 if (! body)
166 return build_empty_stmt ();
167
168 if (IS_EMPTY_STMT (body))
169 return body;
170
171 /* Make a proper block. Java blocks are unsuitable for BIND_EXPR
172 because they use BLOCK_SUBBLOCKS for another purpose. */
173 block = make_node (BLOCK);
174 BLOCK_VARS (block) = decls;
175
176 /* The TREE_USED flag on a block determines whether the debug output
177 routines generate info for the variables in that block. */
178 TREE_USED (block) = 1;
179
180 if (outer != NULL)
181 {
182 tree b = gimple_bind_block (outer);
183 BLOCK_SUBBLOCKS (b) = chainon (BLOCK_SUBBLOCKS (b), block);
184 }
185 BLOCK_EXPR_BODY (java_block) = NULL_TREE;
186
187 return build3 (BIND_EXPR, TREE_TYPE (java_block), decls, body, block);
188 }
189
190 /* Dump a tree of some kind. This is a convenience wrapper for the
191 dump_* functions in tree-dump.c. */
192 static void
193 dump_java_tree (enum tree_dump_index phase, tree t)
194 {
195 FILE *stream;
196 int flags;
197
198 stream = dump_begin (phase, &flags);
199 flags |= TDF_SLIM;
200 if (stream)
201 {
202 dump_node (t, flags, stream);
203 dump_end (phase, stream);
204 }
205 }
This page took 0.040491 seconds and 5 git commands to generate.