gimple-walk.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* Header file for gimple statement walk support.
  2. Copyright (C) 2013-2019 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU General Public License as published by the Free
  6. Software Foundation; either version 3, or (at your option) any later
  7. version.
  8. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11. 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. #ifndef GCC_GIMPLE_WALK_H
  16. #define GCC_GIMPLE_WALK_H
  17. /* Convenience routines to walk all statements of a gimple function.
  18. Note that this is useful exclusively before the code is converted
  19. into SSA form. Once the program is in SSA form, the standard
  20. operand interface should be used to analyze/modify statements. */
  21. struct walk_stmt_info
  22. {
  23. /* Points to the current statement being walked. */
  24. gimple_stmt_iterator gsi;
  25. gimple *stmt;
  26. /* Additional data that the callback functions may want to carry
  27. through the recursion. */
  28. void *info;
  29. /* Pointer map used to mark visited tree nodes when calling
  30. walk_tree on each operand. If set to NULL, duplicate tree nodes
  31. will be visited more than once. */
  32. hash_set<tree> *pset;
  33. /* Operand returned by the callbacks. This is set when calling
  34. walk_gimple_seq. If the walk_stmt_fn or walk_tree_fn callback
  35. returns non-NULL, this field will contain the tree returned by
  36. the last callback. */
  37. tree callback_result;
  38. /* Indicates whether the operand being examined may be replaced
  39. with something that matches is_gimple_val (if true) or something
  40. slightly more complicated (if false). "Something" technically
  41. means the common subset of is_gimple_lvalue and is_gimple_rhs,
  42. but we never try to form anything more complicated than that, so
  43. we don't bother checking.
  44. Also note that CALLBACK should update this flag while walking the
  45. sub-expressions of a statement. For instance, when walking the
  46. statement 'foo (&var)', the flag VAL_ONLY will initially be set
  47. to true, however, when walking &var, the operand of that
  48. ADDR_EXPR does not need to be a GIMPLE value. */
  49. BOOL_BITFIELD val_only : 1;
  50. /* True if we are currently walking the LHS of an assignment. */
  51. BOOL_BITFIELD is_lhs : 1;
  52. /* Optional. Set to true by the callback functions if they made any
  53. changes. */
  54. BOOL_BITFIELD changed : 1;
  55. /* True if we're interested in location information. */
  56. BOOL_BITFIELD want_locations : 1;
  57. /* True if we've removed the statement that was processed. */
  58. BOOL_BITFIELD removed_stmt : 1;
  59. };
  60. /* Callback for walk_gimple_stmt. Called for every statement found
  61. during traversal. The first argument points to the statement to
  62. walk. The second argument is a flag that the callback sets to
  63. 'true' if it the callback handled all the operands and
  64. sub-statements of the statement (the default value of this flag is
  65. 'false'). The third argument is an anonymous pointer to data
  66. to be used by the callback. */
  67. typedef tree (*walk_stmt_fn) (gimple_stmt_iterator *, bool *,
  68. struct walk_stmt_info *);
  69. extern gimple *walk_gimple_seq_mod (gimple_seq *, walk_stmt_fn, walk_tree_fn,
  70. struct walk_stmt_info *);
  71. extern gimple *walk_gimple_seq (gimple_seq, walk_stmt_fn, walk_tree_fn,
  72. struct walk_stmt_info *);
  73. extern tree walk_gimple_op (gimple *, walk_tree_fn, struct walk_stmt_info *);
  74. extern tree walk_gimple_stmt (gimple_stmt_iterator *, walk_stmt_fn,
  75. walk_tree_fn, struct walk_stmt_info *);
  76. typedef bool (*walk_stmt_load_store_addr_fn) (gimple *, tree, tree, void *);
  77. extern bool walk_stmt_load_store_addr_ops (gimple *, void *,
  78. walk_stmt_load_store_addr_fn,
  79. walk_stmt_load_store_addr_fn,
  80. walk_stmt_load_store_addr_fn);
  81. extern bool walk_stmt_load_store_ops (gimple *, void *,
  82. walk_stmt_load_store_addr_fn,
  83. walk_stmt_load_store_addr_fn);
  84. #endif /* GCC_GIMPLE_WALK_H */