tree-streamer.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /* Data structures and functions for streaming trees.
  2. Copyright (C) 2011-2015 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 "lto-streamer.h"
  20. #include "data-streamer.h"
  21. #include "hash-map.h"
  22. /* Cache of pickled nodes. Used to avoid writing the same node more
  23. than once. The first time a tree node is streamed out, it is
  24. entered in this cache. Subsequent references to the same node are
  25. resolved by looking it up in this cache.
  26. This is used in two ways:
  27. - On the writing side, the first time T is added to STREAMER_CACHE,
  28. a new reference index is created for T and T is emitted on the
  29. stream. If T needs to be emitted again to the stream, instead of
  30. pickling it again, the reference index is emitted.
  31. - On the reading side, the first time T is read from the stream, it
  32. is reconstructed in memory and a new reference index created for
  33. T. The reconstructed T is inserted in some array so that when
  34. the reference index for T is found in the input stream, it can be
  35. used to look up into the array to get the reconstructed T. */
  36. struct streamer_tree_cache_d
  37. {
  38. /* The mapping between tree nodes and slots into the nodes array. */
  39. hash_map<tree, unsigned> *node_map;
  40. /* The nodes pickled so far. */
  41. vec<tree> nodes;
  42. /* The node hashes (if available). */
  43. vec<hashval_t> hashes;
  44. /* Next index to assign. */
  45. unsigned next_idx;
  46. };
  47. /* Return true if tree node EXPR should be streamed as a builtin. For
  48. these nodes, we just emit the class and function code. */
  49. static inline bool
  50. streamer_handle_as_builtin_p (tree expr)
  51. {
  52. return (TREE_CODE (expr) == FUNCTION_DECL
  53. && DECL_IS_BUILTIN (expr)
  54. && (DECL_BUILT_IN_CLASS (expr) == BUILT_IN_NORMAL
  55. || DECL_BUILT_IN_CLASS (expr) == BUILT_IN_MD));
  56. }
  57. /* In tree-streamer-in.c. */
  58. tree streamer_read_string_cst (struct data_in *, struct lto_input_block *);
  59. tree streamer_read_chain (struct lto_input_block *, struct data_in *);
  60. tree streamer_alloc_tree (struct lto_input_block *, struct data_in *,
  61. enum LTO_tags);
  62. void streamer_read_tree_body (struct lto_input_block *, struct data_in *, tree);
  63. tree streamer_get_pickled_tree (struct lto_input_block *, struct data_in *);
  64. tree streamer_get_builtin_tree (struct lto_input_block *, struct data_in *);
  65. void streamer_read_tree_bitfields (struct lto_input_block *,
  66. struct data_in *, tree);
  67. /* In tree-streamer-out.c. */
  68. void streamer_write_string_cst (struct output_block *,
  69. struct lto_output_stream *, tree);
  70. void streamer_write_chain (struct output_block *, tree, bool);
  71. void streamer_write_tree_header (struct output_block *, tree);
  72. void streamer_write_tree_bitfields (struct output_block *, tree);
  73. void streamer_write_tree_body (struct output_block *, tree, bool);
  74. void streamer_write_integer_cst (struct output_block *, tree, bool);
  75. void streamer_write_builtin (struct output_block *, tree);
  76. /* In tree-streamer.c. */
  77. extern unsigned char streamer_mode_table[1 << 8];
  78. void streamer_check_handled_ts_structures (void);
  79. bool streamer_tree_cache_insert (struct streamer_tree_cache_d *, tree,
  80. hashval_t, unsigned *);
  81. void streamer_tree_cache_replace_tree (struct streamer_tree_cache_d *, tree,
  82. unsigned);
  83. void streamer_tree_cache_append (struct streamer_tree_cache_d *, tree,
  84. hashval_t);
  85. bool streamer_tree_cache_lookup (struct streamer_tree_cache_d *, tree,
  86. unsigned *);
  87. struct streamer_tree_cache_d *streamer_tree_cache_create (bool, bool, bool);
  88. void streamer_tree_cache_delete (struct streamer_tree_cache_d *);
  89. /* Return the tree node at slot IX in CACHE. */
  90. static inline tree
  91. streamer_tree_cache_get_tree (struct streamer_tree_cache_d *cache, unsigned ix)
  92. {
  93. return cache->nodes[ix];
  94. }
  95. /* Return the tree hash value at slot IX in CACHE. */
  96. static inline hashval_t
  97. streamer_tree_cache_get_hash (struct streamer_tree_cache_d *cache, unsigned ix)
  98. {
  99. return cache->hashes[ix];
  100. }
  101. static inline void
  102. bp_pack_machine_mode (struct bitpack_d *bp, machine_mode mode)
  103. {
  104. streamer_mode_table[mode] = 1;
  105. bp_pack_enum (bp, machine_mode, 1 << 8, mode);
  106. }
  107. static inline machine_mode
  108. bp_unpack_machine_mode (struct bitpack_d *bp)
  109. {
  110. return (machine_mode)
  111. ((struct lto_input_block *)
  112. bp->stream)->mode_table[bp_unpack_enum (bp, machine_mode, 1 << 8)];
  113. }
  114. #endif /* GCC_TREE_STREAMER_H */