gimple-ssa.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /* Header file for routines that straddle the border between GIMPLE and
  2. SSA in gimple.
  3. Copyright (C) 2009-2019 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 "tree-ssa-operands.h"
  19. /* This structure is used to map a gimple statement to a label,
  20. or list of labels to represent transaction restart. */
  21. struct GTY((for_user)) tm_restart_node {
  22. gimple *stmt;
  23. tree label_or_list;
  24. };
  25. /* Hasher for tm_restart_node. */
  26. struct tm_restart_hasher : ggc_ptr_hash<tm_restart_node>
  27. {
  28. static hashval_t hash (tm_restart_node *n) { return htab_hash_pointer (n); }
  29. static bool
  30. equal (tm_restart_node *a, tm_restart_node *b)
  31. {
  32. return a == b;
  33. }
  34. };
  35. extern void gt_ggc_mx (gimple *&);
  36. extern void gt_pch_nx (gimple *&);
  37. struct ssa_name_hasher : ggc_ptr_hash<tree_node>
  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. /* Array of all SSA_NAMEs used in the function. */
  57. vec<tree, va_gc> *ssa_names;
  58. /* Artificial variable used for the virtual operand FUD chain. */
  59. tree vop;
  60. /* The PTA solution for the ESCAPED artificial variable. */
  61. struct pt_solution escaped;
  62. /* A map of decls to artificial ssa-names that point to the partition
  63. of the decl. */
  64. hash_map<tree, tree> * GTY((skip(""))) decls_to_pointers;
  65. /* Free list of SSA_NAMEs. */
  66. vec<tree, va_gc> *free_ssanames;
  67. /* Queue of SSA_NAMEs to be freed at the next opportunity. */
  68. vec<tree, va_gc> *free_ssanames_queue;
  69. /* Hashtable holding definition for symbol. If this field is not NULL, it
  70. means that the first reference to this variable in the function is a
  71. USE or a VUSE. In those cases, the SSA renamer creates an SSA name
  72. for this variable with an empty defining statement. */
  73. hash_table<ssa_name_hasher> *default_defs;
  74. /* True if there are any symbols that need to be renamed. */
  75. unsigned int ssa_renaming_needed : 1;
  76. /* True if all virtual operands need to be renamed. */
  77. unsigned int rename_vops : 1;
  78. /* True if the code is in ssa form. */
  79. unsigned int in_ssa_p : 1;
  80. /* True if IPA points-to information was computed for this function. */
  81. unsigned int ipa_pta : 1;
  82. struct ssa_operands ssa_operands;
  83. /* Map gimple stmt to tree label (or list of labels) for transaction
  84. restart and abort. */
  85. hash_table<tm_restart_hasher> *tm_restart;
  86. };
  87. /* Return true when gimple SSA form was built.
  88. gimple_in_ssa_p is queried by gimplifier in various early stages before SSA
  89. infrastructure is initialized. Check for presence of the datastructures
  90. at first place. */
  91. static inline bool
  92. gimple_in_ssa_p (const struct function *fun)
  93. {
  94. return fun && fun->gimple_df && fun->gimple_df->in_ssa_p;
  95. }
  96. /* Artificial variable used for the virtual operand FUD chain. */
  97. static inline tree
  98. gimple_vop (const struct function *fun)
  99. {
  100. gcc_checking_assert (fun && fun->gimple_df);
  101. return fun->gimple_df->vop;
  102. }
  103. /* Return the set of VUSE operand for statement G. */
  104. static inline use_operand_p
  105. gimple_vuse_op (const gimple *g)
  106. {
  107. struct use_optype_d *ops;
  108. const gimple_statement_with_memory_ops *mem_ops_stmt =
  109. dyn_cast <const gimple_statement_with_memory_ops *> (g);
  110. if (!mem_ops_stmt)
  111. return NULL_USE_OPERAND_P;
  112. ops = mem_ops_stmt->use_ops;
  113. if (ops
  114. && USE_OP_PTR (ops)->use == &mem_ops_stmt->vuse)
  115. return USE_OP_PTR (ops);
  116. return NULL_USE_OPERAND_P;
  117. }
  118. /* Return the set of VDEF operand for statement G. */
  119. static inline def_operand_p
  120. gimple_vdef_op (gimple *g)
  121. {
  122. gimple_statement_with_memory_ops *mem_ops_stmt =
  123. dyn_cast <gimple_statement_with_memory_ops *> (g);
  124. if (!mem_ops_stmt)
  125. return NULL_DEF_OPERAND_P;
  126. if (mem_ops_stmt->vdef)
  127. return &mem_ops_stmt->vdef;
  128. return NULL_DEF_OPERAND_P;
  129. }
  130. /* Mark statement S as modified, and update it. */
  131. static inline void
  132. update_stmt (gimple *s)
  133. {
  134. if (gimple_has_ops (s))
  135. {
  136. gimple_set_modified (s, true);
  137. update_stmt_operands (cfun, s);
  138. }
  139. }
  140. /* Update statement S if it has been optimized. */
  141. static inline void
  142. update_stmt_if_modified (gimple *s)
  143. {
  144. if (gimple_modified_p (s))
  145. update_stmt_operands (cfun, s);
  146. }
  147. /* Mark statement S as modified, and update it. */
  148. static inline void
  149. update_stmt_fn (struct function *fn, gimple *s)
  150. {
  151. if (gimple_has_ops (s))
  152. {
  153. gimple_set_modified (s, true);
  154. update_stmt_operands (fn, s);
  155. }
  156. }
  157. #endif /* GCC_GIMPLE_SSA_H */