tree-affine.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /* Operations with affine combinations of trees.
  2. Copyright (C) 2005-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
  5. under the terms of the GNU General Public License as published by the
  6. Free Software Foundation; either version 3, or (at your option) any
  7. later version.
  8. GCC is distributed in the hope that it will be useful, but WITHOUT
  9. ANY 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. /* Affine combination of trees. We keep track of at most MAX_AFF_ELTS elements
  16. to make things simpler; this is sufficient in most cases. */
  17. #ifndef GCC_TREE_AFFINE_H
  18. #define GCC_TREE_AFFINE_H
  19. #define MAX_AFF_ELTS 8
  20. /* Element of an affine combination. */
  21. struct aff_comb_elt
  22. {
  23. /* The value of the element. */
  24. tree val;
  25. /* Its coefficient in the combination. */
  26. widest_int coef;
  27. };
  28. struct aff_tree
  29. {
  30. /* Type of the result of the combination. */
  31. tree type;
  32. /* Constant offset. */
  33. poly_widest_int offset;
  34. /* Number of elements of the combination. */
  35. unsigned n;
  36. /* Elements and their coefficients. Type of elements may be different from
  37. TYPE, but their sizes must be the same (STRIP_NOPS is applied to the
  38. elements).
  39. The coefficients are always sign extended from the precision of TYPE
  40. (regardless of signedness of TYPE). */
  41. struct aff_comb_elt elts[MAX_AFF_ELTS];
  42. /* Remainder of the expression. Usually NULL, used only if there are more
  43. than MAX_AFF_ELTS elements. Type of REST will be either sizetype for
  44. TYPE of POINTER_TYPEs or TYPE. */
  45. tree rest;
  46. };
  47. struct name_expansion;
  48. void aff_combination_const (aff_tree *, tree, const poly_widest_int &);
  49. void aff_combination_elt (aff_tree *, tree, tree);
  50. void aff_combination_scale (aff_tree *, const widest_int &);
  51. void aff_combination_mult (aff_tree *, aff_tree *, aff_tree *);
  52. void aff_combination_add (aff_tree *, aff_tree *);
  53. void aff_combination_add_elt (aff_tree *, tree, const widest_int &);
  54. void aff_combination_remove_elt (aff_tree *, unsigned);
  55. void aff_combination_convert (aff_tree *, tree);
  56. void tree_to_aff_combination (tree, tree, aff_tree *);
  57. tree aff_combination_to_tree (aff_tree *);
  58. void unshare_aff_combination (aff_tree *);
  59. bool aff_combination_constant_multiple_p (aff_tree *, aff_tree *,
  60. poly_widest_int *);
  61. void aff_combination_expand (aff_tree *, hash_map<tree, name_expansion *> **);
  62. void tree_to_aff_combination_expand (tree, tree, aff_tree *,
  63. hash_map<tree, name_expansion *> **);
  64. tree get_inner_reference_aff (tree, aff_tree *, poly_widest_int *);
  65. void free_affine_expand_cache (hash_map<tree, name_expansion *> **);
  66. bool aff_comb_cannot_overlap_p (aff_tree *, const poly_widest_int &,
  67. const poly_widest_int &);
  68. /* Debugging functions. */
  69. void debug_aff (aff_tree *);
  70. /* Return AFF's type. */
  71. inline tree
  72. aff_combination_type (aff_tree *aff)
  73. {
  74. return aff->type;
  75. }
  76. /* Return true if AFF is actually ZERO. */
  77. inline bool
  78. aff_combination_zero_p (aff_tree *aff)
  79. {
  80. if (!aff)
  81. return true;
  82. if (aff->n == 0 && known_eq (aff->offset, 0))
  83. return true;
  84. return false;
  85. }
  86. /* Return true if AFF is actually const. */
  87. inline bool
  88. aff_combination_const_p (aff_tree *aff)
  89. {
  90. return (aff == NULL || aff->n == 0);
  91. }
  92. /* Return true iff AFF contains one (negated) singleton variable. Users need
  93. to make sure AFF points to a valid combination. */
  94. inline bool
  95. aff_combination_singleton_var_p (aff_tree *aff)
  96. {
  97. return (aff->n == 1
  98. && known_eq (aff->offset, 0)
  99. && (aff->elts[0].coef == 1 || aff->elts[0].coef == -1));
  100. }
  101. #endif /* GCC_TREE_AFFINE_H */