Fix type in the changelog entry,
[official-gcc.git] / gcc / java / java-gimplify.c
blobc6e7657b5fb82154bbef7d52711b1e928826f4ec
1 /* Java(TM) language-specific gimplification routines.
2 Copyright (C) 2003-2015 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
11 GCC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>.
20 Java and all Java-based marks are trademarks or registered trademarks
21 of Sun Microsystems, Inc. in the United States and other countries.
22 The Free Software Foundation is independent of Sun Microsystems, Inc. */
24 #include "config.h"
25 #include "system.h"
26 #include "coretypes.h"
27 #include "alias.h"
28 #include "tm.h"
29 #include "function.h"
30 #include "cfghooks.h"
31 #include "basic-block.h"
32 #include "tree.h"
33 #include "gimple.h"
34 #include "hard-reg-set.h"
35 #include "options.h"
36 #include "fold-const.h"
37 #include "java-tree.h"
38 #include "dumpfile.h"
39 #include "internal-fn.h"
40 #include "gimplify.h"
42 static tree java_gimplify_block (tree);
43 static enum gimplify_status java_gimplify_modify_expr (tree *);
44 static enum gimplify_status java_gimplify_self_mod_expr (tree *, gimple_seq *,
45 gimple_seq *);
47 static void dump_java_tree (enum tree_dump_index, tree);
49 /* Convert a Java tree to GENERIC. */
51 void
52 java_genericize (tree fndecl)
54 walk_tree (&DECL_SAVED_TREE (fndecl), java_replace_references, NULL, NULL);
55 dump_java_tree (TDI_original, fndecl);
58 /* Gimplify a Java tree. */
60 int
61 java_gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p)
63 enum tree_code code = TREE_CODE (*expr_p);
65 switch (code)
67 case BLOCK:
68 *expr_p = java_gimplify_block (*expr_p);
69 break;
71 case MODIFY_EXPR:
72 return java_gimplify_modify_expr (expr_p);
74 case POSTINCREMENT_EXPR:
75 case POSTDECREMENT_EXPR:
76 case PREINCREMENT_EXPR:
77 case PREDECREMENT_EXPR:
78 return java_gimplify_self_mod_expr (expr_p, pre_p, post_p);
80 /* These should already be lowered before we get here. */
81 case URSHIFT_EXPR:
82 case COMPARE_EXPR:
83 case COMPARE_L_EXPR:
84 case COMPARE_G_EXPR:
85 gcc_unreachable ();
87 default:
88 return GS_UNHANDLED;
91 return GS_OK;
94 static enum gimplify_status
95 java_gimplify_modify_expr (tree *modify_expr_p)
97 tree modify_expr = *modify_expr_p;
98 tree lhs = TREE_OPERAND (modify_expr, 0);
99 tree rhs = TREE_OPERAND (modify_expr, 1);
100 tree lhs_type = TREE_TYPE (lhs);
102 if (lhs_type != TREE_TYPE (rhs))
103 /* Fix up type mismatches to make legal GIMPLE. These are
104 generated in several places, in particular null pointer
105 assignment and subclass assignment. */
106 TREE_OPERAND (modify_expr, 1) = convert (lhs_type, rhs);
108 return GS_UNHANDLED;
111 /* Special case handling for volatiles: we need to generate a barrier
112 between the reading and the writing. */
114 static enum gimplify_status
115 java_gimplify_self_mod_expr (tree *expr_p, gimple_seq *pre_p ATTRIBUTE_UNUSED,
116 gimple_seq *post_p ATTRIBUTE_UNUSED)
118 tree lhs = TREE_OPERAND (*expr_p, 0);
120 if (TREE_CODE (lhs) == COMPONENT_REF
121 && TREE_THIS_VOLATILE (TREE_OPERAND (lhs, 1)))
122 TREE_THIS_VOLATILE (lhs) = 1;
124 return GS_UNHANDLED;
128 /* Gimplify BLOCK into a BIND_EXPR. */
130 static tree
131 java_gimplify_block (tree java_block)
133 tree decls = BLOCK_VARS (java_block);
134 tree body = BLOCK_EXPR_BODY (java_block);
135 gbind *outer = gimple_current_bind_expr ();
136 tree block;
138 /* Don't bother with empty blocks. */
139 if (! body)
140 return build_empty_stmt (input_location);
142 if (IS_EMPTY_STMT (body))
143 return body;
145 /* Make a proper block. Java blocks are unsuitable for BIND_EXPR
146 because they use BLOCK_SUBBLOCKS for another purpose. */
147 block = make_node (BLOCK);
148 BLOCK_VARS (block) = decls;
150 /* The TREE_USED flag on a block determines whether the debug output
151 routines generate info for the variables in that block. */
152 TREE_USED (block) = 1;
154 if (outer != NULL)
156 tree b = gimple_bind_block (outer);
157 BLOCK_SUBBLOCKS (b) = chainon (BLOCK_SUBBLOCKS (b), block);
159 BLOCK_EXPR_BODY (java_block) = NULL_TREE;
161 return build3 (BIND_EXPR, TREE_TYPE (java_block), decls, body, block);
164 /* Dump a tree of some kind. This is a convenience wrapper for the
165 dump_* functions in tree-dump.c. */
166 static void
167 dump_java_tree (enum tree_dump_index phase, tree t)
169 FILE *stream;
170 int flags;
172 stream = dump_begin (phase, &flags);
173 flags |= TDF_SLIM;
174 if (stream)
176 dump_node (t, flags, stream);
177 dump_end (phase, stream);