cselib.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /* Common subexpression elimination for GNU compiler.
  2. Copyright (C) 1987-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_CSELIB_H
  16. #define GCC_CSELIB_H
  17. /* Describe a value. */
  18. struct cselib_val
  19. {
  20. /* The hash value. */
  21. unsigned int hash;
  22. /* A unique id assigned to values. */
  23. int uid;
  24. /* A VALUE rtx that points back to this structure. */
  25. rtx val_rtx;
  26. /* All rtl expressions that hold this value at the current time during a
  27. scan. */
  28. struct elt_loc_list *locs;
  29. /* If this value is used as an address, points to a list of values that
  30. use it as an address in a MEM. */
  31. struct elt_list *addr_list;
  32. struct cselib_val *next_containing_mem;
  33. };
  34. /* A list of rtl expressions that hold the same value. */
  35. struct elt_loc_list {
  36. /* Next element in the list. */
  37. struct elt_loc_list *next;
  38. /* An rtl expression that holds the value. */
  39. rtx loc;
  40. /* The insn that made the equivalence. */
  41. rtx_insn *setting_insn;
  42. };
  43. /* Describe a single set that is part of an insn. */
  44. struct cselib_set
  45. {
  46. rtx src;
  47. rtx dest;
  48. cselib_val *src_elt;
  49. cselib_val *dest_addr_elt;
  50. };
  51. enum cselib_record_what
  52. {
  53. CSELIB_RECORD_MEMORY = 1,
  54. CSELIB_PRESERVE_CONSTANTS = 2
  55. };
  56. extern void (*cselib_discard_hook) (cselib_val *);
  57. extern void (*cselib_record_sets_hook) (rtx_insn *insn, struct cselib_set *sets,
  58. int n_sets);
  59. extern cselib_val *cselib_lookup (rtx, machine_mode,
  60. int, machine_mode);
  61. extern cselib_val *cselib_lookup_from_insn (rtx, machine_mode,
  62. int, machine_mode, rtx_insn *);
  63. extern void cselib_init (int);
  64. extern void cselib_clear_table (void);
  65. extern void cselib_finish (void);
  66. extern void cselib_process_insn (rtx_insn *);
  67. extern bool fp_setter_insn (rtx_insn *);
  68. extern machine_mode cselib_reg_set_mode (const_rtx);
  69. extern int rtx_equal_for_cselib_1 (rtx, rtx, machine_mode, int);
  70. extern int references_value_p (const_rtx, int);
  71. extern rtx cselib_expand_value_rtx (rtx, bitmap, int);
  72. typedef rtx (*cselib_expand_callback)(rtx, bitmap, int, void *);
  73. extern rtx cselib_expand_value_rtx_cb (rtx, bitmap, int,
  74. cselib_expand_callback, void *);
  75. extern bool cselib_dummy_expand_value_rtx_cb (rtx, bitmap, int,
  76. cselib_expand_callback, void *);
  77. extern rtx cselib_subst_to_values (rtx, machine_mode);
  78. extern rtx cselib_subst_to_values_from_insn (rtx, machine_mode, rtx_insn *);
  79. extern void cselib_invalidate_rtx (rtx, const_rtx = NULL);
  80. extern void cselib_reset_table (unsigned int);
  81. extern unsigned int cselib_get_next_uid (void);
  82. extern void cselib_preserve_value (cselib_val *);
  83. extern bool cselib_preserved_value_p (cselib_val *);
  84. extern void cselib_preserve_only_values (void);
  85. extern void cselib_preserve_cfa_base_value (cselib_val *, unsigned int);
  86. extern void cselib_add_permanent_equiv (cselib_val *, rtx, rtx_insn *);
  87. extern bool cselib_have_permanent_equivalences (void);
  88. extern void cselib_set_value_sp_based (cselib_val *);
  89. extern bool cselib_sp_based_value_p (cselib_val *);
  90. extern void dump_cselib_table (FILE *);
  91. /* Return the canonical value for VAL, following the equivalence chain
  92. towards the earliest (== lowest uid) equivalent value. */
  93. static inline cselib_val *
  94. canonical_cselib_val (cselib_val *val)
  95. {
  96. cselib_val *canon;
  97. if (!val->locs || val->locs->next
  98. || !val->locs->loc || GET_CODE (val->locs->loc) != VALUE
  99. || val->uid < CSELIB_VAL_PTR (val->locs->loc)->uid)
  100. return val;
  101. canon = CSELIB_VAL_PTR (val->locs->loc);
  102. gcc_checking_assert (canonical_cselib_val (canon) == canon);
  103. return canon;
  104. }
  105. /* Return nonzero if we can prove that X and Y contain the same value, taking
  106. our gathered information into account. */
  107. static inline int
  108. rtx_equal_for_cselib_p (rtx x, rtx y)
  109. {
  110. if (x == y)
  111. return 1;
  112. return rtx_equal_for_cselib_1 (x, y, VOIDmode, 0);
  113. }
  114. #endif /* GCC_CSELIB_H */