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)
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. */
26 #include "coretypes.h"
30 #include "double-int.h"
38 #include "fold-const.h"
39 #include "java-tree.h"
43 #include "hard-reg-set.h"
46 #include "basic-block.h"
47 #include "tree-ssa-alias.h"
48 #include "internal-fn.h"
49 #include "gimple-expr.h"
54 static tree
java_gimplify_block (tree
);
55 static enum gimplify_status
java_gimplify_modify_expr (tree
*);
56 static enum gimplify_status
java_gimplify_self_mod_expr (tree
*, gimple_seq
*,
59 static void dump_java_tree (enum tree_dump_index
, tree
);
61 /* Convert a Java tree to GENERIC. */
64 java_genericize (tree fndecl
)
66 walk_tree (&DECL_SAVED_TREE (fndecl
), java_replace_references
, NULL
, NULL
);
67 dump_java_tree (TDI_original
, fndecl
);
70 /* Gimplify a Java tree. */
73 java_gimplify_expr (tree
*expr_p
, gimple_seq
*pre_p
, gimple_seq
*post_p
)
75 enum tree_code code
= TREE_CODE (*expr_p
);
80 *expr_p
= java_gimplify_block (*expr_p
);
84 return java_gimplify_modify_expr (expr_p
);
86 case POSTINCREMENT_EXPR
:
87 case POSTDECREMENT_EXPR
:
88 case PREINCREMENT_EXPR
:
89 case PREDECREMENT_EXPR
:
90 return java_gimplify_self_mod_expr (expr_p
, pre_p
, post_p
);
92 /* These should already be lowered before we get here. */
106 static enum gimplify_status
107 java_gimplify_modify_expr (tree
*modify_expr_p
)
109 tree modify_expr
= *modify_expr_p
;
110 tree lhs
= TREE_OPERAND (modify_expr
, 0);
111 tree rhs
= TREE_OPERAND (modify_expr
, 1);
112 tree lhs_type
= TREE_TYPE (lhs
);
114 if (lhs_type
!= TREE_TYPE (rhs
))
115 /* Fix up type mismatches to make legal GIMPLE. These are
116 generated in several places, in particular null pointer
117 assignment and subclass assignment. */
118 TREE_OPERAND (modify_expr
, 1) = convert (lhs_type
, rhs
);
123 /* Special case handling for volatiles: we need to generate a barrier
124 between the reading and the writing. */
126 static enum gimplify_status
127 java_gimplify_self_mod_expr (tree
*expr_p
, gimple_seq
*pre_p ATTRIBUTE_UNUSED
,
128 gimple_seq
*post_p ATTRIBUTE_UNUSED
)
130 tree lhs
= TREE_OPERAND (*expr_p
, 0);
132 if (TREE_CODE (lhs
) == COMPONENT_REF
133 && TREE_THIS_VOLATILE (TREE_OPERAND (lhs
, 1)))
134 TREE_THIS_VOLATILE (lhs
) = 1;
140 /* Gimplify BLOCK into a BIND_EXPR. */
143 java_gimplify_block (tree java_block
)
145 tree decls
= BLOCK_VARS (java_block
);
146 tree body
= BLOCK_EXPR_BODY (java_block
);
147 gbind
*outer
= gimple_current_bind_expr ();
150 /* Don't bother with empty blocks. */
152 return build_empty_stmt (input_location
);
154 if (IS_EMPTY_STMT (body
))
157 /* Make a proper block. Java blocks are unsuitable for BIND_EXPR
158 because they use BLOCK_SUBBLOCKS for another purpose. */
159 block
= make_node (BLOCK
);
160 BLOCK_VARS (block
) = decls
;
162 /* The TREE_USED flag on a block determines whether the debug output
163 routines generate info for the variables in that block. */
164 TREE_USED (block
) = 1;
168 tree b
= gimple_bind_block (outer
);
169 BLOCK_SUBBLOCKS (b
) = chainon (BLOCK_SUBBLOCKS (b
), block
);
171 BLOCK_EXPR_BODY (java_block
) = NULL_TREE
;
173 return build3 (BIND_EXPR
, TREE_TYPE (java_block
), decls
, body
, block
);
176 /* Dump a tree of some kind. This is a convenience wrapper for the
177 dump_* functions in tree-dump.c. */
179 dump_java_tree (enum tree_dump_index phase
, tree t
)
184 stream
= dump_begin (phase
, &flags
);
188 dump_node (t
, flags
, stream
);
189 dump_end (phase
, stream
);