gimple-ssa.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /* Header file for routines that straddle the border between GIMPLE and
  2. SSA in gimple.
  3. Copyright (C) 2009-2015 Free Software Foundation, Inc.
  4. This file is part of GCC.
  5. GCC is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3, or (at your option)
  8. any later version.
  9. GCC is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with GCC; see the file COPYING3. If not see
  15. <http://www.gnu.org/licenses/>. */
  16. #ifndef GCC_GIMPLE_SSA_H
  17. #define GCC_GIMPLE_SSA_H
  18. #include "hash-map.h"
  19. #include "tree-hasher.h"
  20. #include "tree-ssa-operands.h"
  21. /* This structure is used to map a gimple statement to a label,
  22. or list of labels to represent transaction restart. */
  23. struct GTY((for_user)) tm_restart_node {
  24. gimple stmt;
  25. tree label_or_list;
  26. };
  27. /* Hasher for tm_restart_node. */
  28. struct tm_restart_hasher : ggc_hasher<tm_restart_node *>
  29. {
  30. static hashval_t hash (tm_restart_node *n) { return htab_hash_pointer (n); }
  31. static bool
  32. equal (tm_restart_node *a, tm_restart_node *b)
  33. {
  34. return a == b;
  35. }
  36. };
  37. struct ssa_name_hasher : ggc_hasher<tree>
  38. {
  39. /* Hash a tree in a uid_decl_map. */
  40. static hashval_t
  41. hash (tree item)
  42. {
  43. return item->ssa_name.var->decl_minimal.uid;
  44. }
  45. /* Return true if the DECL_UID in both trees are equal. */
  46. static bool
  47. equal (tree a, tree b)
  48. {
  49. return (a->ssa_name.var->decl_minimal.uid == b->ssa_name.var->decl_minimal.uid);
  50. }
  51. };
  52. /* Gimple dataflow datastructure. All publicly available fields shall have
  53. gimple_ accessor defined, all publicly modifiable fields should have
  54. gimple_set accessor. */
  55. struct GTY(()) gimple_df {
  56. /* A vector of all the noreturn calls passed to modify_stmt.
  57. cleanup_control_flow uses it to detect cases where a mid-block
  58. indirect call has been turned into a noreturn call. When this
  59. happens, all the instructions after the call are no longer
  60. reachable and must be deleted as dead. */
  61. vec<gimple, va_gc> *modified_noreturn_calls;
  62. /* Array of all SSA_NAMEs used in the function. */
  63. vec<tree, va_gc> *ssa_names;
  64. /* Artificial variable used for the virtual operand FUD chain. */
  65. tree vop;
  66. /* The PTA solution for the ESCAPED artificial variable. */
  67. struct pt_solution escaped;
  68. /* A map of decls to artificial ssa-names that point to the partition
  69. of the decl. */
  70. hash_map<tree, tree> * GTY((skip(""))) decls_to_pointers;
  71. /* Free list of SSA_NAMEs. */
  72. vec<tree, va_gc> *free_ssanames;
  73. /* Hashtable holding definition for symbol. If this field is not NULL, it
  74. means that the first reference to this variable in the function is a
  75. USE or a VUSE. In those cases, the SSA renamer creates an SSA name
  76. for this variable with an empty defining statement. */
  77. hash_table<ssa_name_hasher> *default_defs;
  78. /* True if there are any symbols that need to be renamed. */
  79. unsigned int ssa_renaming_needed : 1;
  80. /* True if all virtual operands need to be renamed. */
  81. unsigned int rename_vops : 1;
  82. /* True if the code is in ssa form. */
  83. unsigned int in_ssa_p : 1;
  84. /* True if IPA points-to information was computed for this function. */
  85. unsigned int ipa_pta : 1;
  86. struct ssa_operands ssa_operands;
  87. /* Map gimple stmt to tree label (or list of labels) for transaction
  88. restart and abort. */
  89. hash_table<tm_restart_hasher> *tm_restart;
  90. };
  91. /* Return true when gimple SSA form was built.
  92. gimple_in_ssa_p is queried by gimplifier in various early stages before SSA
  93. infrastructure is initialized. Check for presence of the datastructures
  94. at first place. */
  95. static inline bool
  96. gimple_in_ssa_p (const struct function *fun)
  97. {
  98. return fun && fun->gimple_df && fun->gimple_df->in_ssa_p;
  99. }
  100. /* Artificial variable used for the virtual operand FUD chain. */
  101. static inline tree
  102. gimple_vop (const struct function *fun)
  103. {
  104. gcc_checking_assert (fun && fun->gimple_df);
  105. return fun->gimple_df->vop;
  106. }
  107. /* Return the set of VUSE operand for statement G. */
  108. static inline use_operand_p
  109. gimple_vuse_op (const_gimple g)
  110. {
  111. struct use_optype_d *ops;
  112. const gimple_statement_with_memory_ops *mem_ops_stmt =
  113. dyn_cast <const gimple_statement_with_memory_ops *> (g);
  114. if (!mem_ops_stmt)
  115. return NULL_USE_OPERAND_P;
  116. ops = mem_ops_stmt->use_ops;
  117. if (ops
  118. && USE_OP_PTR (ops)->use == &mem_ops_stmt->vuse)
  119. return USE_OP_PTR (ops);
  120. return NULL_USE_OPERAND_P;
  121. }
  122. /* Return the set of VDEF operand for statement G. */
  123. static inline def_operand_p
  124. gimple_vdef_op (gimple g)
  125. {
  126. gimple_statement_with_memory_ops *mem_ops_stmt =
  127. dyn_cast <gimple_statement_with_memory_ops *> (g);
  128. if (!mem_ops_stmt)
  129. return NULL_DEF_OPERAND_P;
  130. if (mem_ops_stmt->vdef)
  131. return &mem_ops_stmt->vdef;
  132. return NULL_DEF_OPERAND_P;
  133. }
  134. /* Mark statement S as modified, and update it. */
  135. static inline void
  136. update_stmt (gimple s)
  137. {
  138. if (gimple_has_ops (s))
  139. {
  140. gimple_set_modified (s, true);
  141. update_stmt_operands (cfun, s);
  142. }
  143. }
  144. /* Update statement S if it has been optimized. */
  145. static inline void
  146. update_stmt_if_modified (gimple s)
  147. {
  148. if (gimple_modified_p (s))
  149. update_stmt_operands (cfun, s);
  150. }
  151. /* Mark statement S as modified, and update it. */
  152. static inline void
  153. update_stmt_fn (struct function *fn, gimple s)
  154. {
  155. if (gimple_has_ops (s))
  156. {
  157. gimple_set_modified (s, true);
  158. update_stmt_operands (fn, s);
  159. }
  160. }
  161. #endif /* GCC_GIMPLE_SSA_H */