java-gimplify.c 5.0 KB

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