You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

125 lines
4.4KB

  1. /* Data structures and functions for streaming trees.
  2. Copyright (C) 2011-2020 Free Software Foundation, Inc.
  3. Contributed by Diego Novillo <dnovillo@google.com>
  4. This file is part of GCC.
  5. GCC is free software; you can redistribute it and/or modify it under
  6. the terms of the GNU General Public License as published by the Free
  7. Software Foundation; either version 3, or (at your option) any later
  8. version.
  9. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. 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_TREE_STREAMER_H
  17. #define GCC_TREE_STREAMER_H
  18. #include "streamer-hooks.h"
  19. #include "data-streamer.h"
  20. /* Cache of pickled nodes. Used to avoid writing the same node more
  21. than once. The first time a tree node is streamed out, it is
  22. entered in this cache. Subsequent references to the same node are
  23. resolved by looking it up in this cache.
  24. This is used in two ways:
  25. - On the writing side, the first time T is added to STREAMER_CACHE,
  26. a new reference index is created for T and T is emitted on the
  27. stream. If T needs to be emitted again to the stream, instead of
  28. pickling it again, the reference index is emitted.
  29. - On the reading side, the first time T is read from the stream, it
  30. is reconstructed in memory and a new reference index created for
  31. T. The reconstructed T is inserted in some array so that when
  32. the reference index for T is found in the input stream, it can be
  33. used to look up into the array to get the reconstructed T. */
  34. struct streamer_tree_cache_d
  35. {
  36. /* The mapping between tree nodes and slots into the nodes array. */
  37. hash_map<tree, unsigned> *node_map;
  38. /* The nodes pickled so far. */
  39. vec<tree> nodes;
  40. /* The node hashes (if available). */
  41. vec<hashval_t> hashes;
  42. /* Next index to assign. */
  43. unsigned next_idx;
  44. };
  45. /* In tree-streamer-in.c. */
  46. tree streamer_read_string_cst (class data_in *, class lto_input_block *);
  47. tree streamer_read_chain (class lto_input_block *, class data_in *);
  48. tree streamer_alloc_tree (class lto_input_block *, class data_in *,
  49. enum LTO_tags);
  50. void streamer_read_tree_body (class lto_input_block *, class data_in *, tree);
  51. tree streamer_get_pickled_tree (class lto_input_block *, class data_in *);
  52. void streamer_read_tree_bitfields (class lto_input_block *,
  53. class data_in *, tree);
  54. /* In tree-streamer-out.c. */
  55. void streamer_write_string_cst (struct output_block *,
  56. struct lto_output_stream *, tree);
  57. void streamer_write_chain (struct output_block *, tree, bool);
  58. void streamer_write_tree_header (struct output_block *, tree);
  59. void streamer_write_tree_bitfields (struct output_block *, tree);
  60. void streamer_write_tree_body (struct output_block *, tree, bool);
  61. void streamer_write_integer_cst (struct output_block *, tree, bool);
  62. /* In tree-streamer.c. */
  63. extern unsigned char streamer_mode_table[1 << 8];
  64. void streamer_check_handled_ts_structures (void);
  65. bool streamer_tree_cache_insert (struct streamer_tree_cache_d *, tree,
  66. hashval_t, unsigned *);
  67. void streamer_tree_cache_replace_tree (struct streamer_tree_cache_d *, tree,
  68. unsigned);
  69. void streamer_tree_cache_append (struct streamer_tree_cache_d *, tree,
  70. hashval_t);
  71. bool streamer_tree_cache_lookup (struct streamer_tree_cache_d *, tree,
  72. unsigned *);
  73. struct streamer_tree_cache_d *streamer_tree_cache_create (bool, bool, bool);
  74. void streamer_tree_cache_delete (struct streamer_tree_cache_d *);
  75. /* Return the tree node at slot IX in CACHE. */
  76. static inline tree
  77. streamer_tree_cache_get_tree (struct streamer_tree_cache_d *cache, unsigned ix)
  78. {
  79. return cache->nodes[ix];
  80. }
  81. /* Return the tree hash value at slot IX in CACHE. */
  82. static inline hashval_t
  83. streamer_tree_cache_get_hash (struct streamer_tree_cache_d *cache, unsigned ix)
  84. {
  85. return cache->hashes[ix];
  86. }
  87. static inline void
  88. bp_pack_machine_mode (struct bitpack_d *bp, machine_mode mode)
  89. {
  90. streamer_mode_table[mode] = 1;
  91. bp_pack_enum (bp, machine_mode, 1 << 8, mode);
  92. }
  93. static inline machine_mode
  94. bp_unpack_machine_mode (struct bitpack_d *bp)
  95. {
  96. return (machine_mode)
  97. ((class lto_input_block *)
  98. bp->stream)->mode_table[bp_unpack_enum (bp, machine_mode, 1 << 8)];
  99. }
  100. #endif /* GCC_TREE_STREAMER_H */