data-streamer.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /* Generic streaming support for basic data types.
  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. #include "config.h"
  17. #include "system.h"
  18. #include "coretypes.h"
  19. #include "hash-set.h"
  20. #include "machmode.h"
  21. #include "vec.h"
  22. #include "double-int.h"
  23. #include "input.h"
  24. #include "alias.h"
  25. #include "symtab.h"
  26. #include "options.h"
  27. #include "wide-int.h"
  28. #include "inchash.h"
  29. #include "tree.h"
  30. #include "fold-const.h"
  31. #include "predict.h"
  32. #include "tm.h"
  33. #include "hard-reg-set.h"
  34. #include "input.h"
  35. #include "function.h"
  36. #include "basic-block.h"
  37. #include "tree-ssa-alias.h"
  38. #include "internal-fn.h"
  39. #include "gimple-expr.h"
  40. #include "is-a.h"
  41. #include "gimple.h"
  42. #include "hash-map.h"
  43. #include "plugin-api.h"
  44. #include "ipa-ref.h"
  45. #include "cgraph.h"
  46. #include "data-streamer.h"
  47. /* Pack WORK into BP in a variant of uleb format. */
  48. void
  49. bp_pack_var_len_unsigned (struct bitpack_d *bp, unsigned HOST_WIDE_INT work)
  50. {
  51. do
  52. {
  53. unsigned int half_byte = (work & 0x7);
  54. work >>= 3;
  55. if (work != 0)
  56. /* More half_bytes to follow. */
  57. half_byte |= 0x8;
  58. bp_pack_value (bp, half_byte, 4);
  59. }
  60. while (work != 0);
  61. }
  62. /* Pack WORK into BP in a variant of sleb format. */
  63. void
  64. bp_pack_var_len_int (struct bitpack_d *bp, HOST_WIDE_INT work)
  65. {
  66. int more, half_byte;
  67. do
  68. {
  69. half_byte = (work & 0x7);
  70. /* arithmetic shift */
  71. work >>= 3;
  72. more = !((work == 0 && (half_byte & 0x4) == 0)
  73. || (work == -1 && (half_byte & 0x4) != 0));
  74. if (more)
  75. half_byte |= 0x8;
  76. bp_pack_value (bp, half_byte, 4);
  77. }
  78. while (more);
  79. }
  80. /* Unpack VAL from BP in a variant of uleb format. */
  81. unsigned HOST_WIDE_INT
  82. bp_unpack_var_len_unsigned (struct bitpack_d *bp)
  83. {
  84. unsigned HOST_WIDE_INT result = 0;
  85. int shift = 0;
  86. unsigned HOST_WIDE_INT half_byte;
  87. while (true)
  88. {
  89. half_byte = bp_unpack_value (bp, 4);
  90. result |= (half_byte & 0x7) << shift;
  91. shift += 3;
  92. if ((half_byte & 0x8) == 0)
  93. return result;
  94. }
  95. }
  96. /* Unpack VAL from BP in a variant of sleb format. */
  97. HOST_WIDE_INT
  98. bp_unpack_var_len_int (struct bitpack_d *bp)
  99. {
  100. HOST_WIDE_INT result = 0;
  101. int shift = 0;
  102. unsigned HOST_WIDE_INT half_byte;
  103. while (true)
  104. {
  105. half_byte = bp_unpack_value (bp, 4);
  106. result |= (half_byte & 0x7) << shift;
  107. shift += 3;
  108. if ((half_byte & 0x8) == 0)
  109. {
  110. if ((shift < HOST_BITS_PER_WIDE_INT) && (half_byte & 0x4))
  111. result |= - (HOST_WIDE_INT_1U << shift);
  112. return result;
  113. }
  114. }
  115. }