tree-affine.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* Operations with affine combinations of trees.
  2. Copyright (C) 2005-2015 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. #include "hash-map.h"
  20. #include "wide-int.h"
  21. #define MAX_AFF_ELTS 8
  22. /* Element of an affine combination. */
  23. struct aff_comb_elt
  24. {
  25. /* The value of the element. */
  26. tree val;
  27. /* Its coefficient in the combination. */
  28. widest_int coef;
  29. };
  30. struct aff_tree
  31. {
  32. /* Type of the result of the combination. */
  33. tree type;
  34. /* Constant offset. */
  35. widest_int offset;
  36. /* Number of elements of the combination. */
  37. unsigned n;
  38. /* Elements and their coefficients. Type of elements may be different from
  39. TYPE, but their sizes must be the same (STRIP_NOPS is applied to the
  40. elements).
  41. The coefficients are always sign extended from the precision of TYPE
  42. (regardless of signedness of TYPE). */
  43. struct aff_comb_elt elts[MAX_AFF_ELTS];
  44. /* Remainder of the expression. Usually NULL, used only if there are more
  45. than MAX_AFF_ELTS elements. Type of REST will be either sizetype for
  46. TYPE of POINTER_TYPEs or TYPE. */
  47. tree rest;
  48. };
  49. struct name_expansion;
  50. widest_int wide_int_ext_for_comb (const widest_int &, aff_tree *);
  51. void aff_combination_const (aff_tree *, tree, const widest_int &);
  52. void aff_combination_elt (aff_tree *, tree, tree);
  53. void aff_combination_scale (aff_tree *, const widest_int &);
  54. void aff_combination_mult (aff_tree *, aff_tree *, aff_tree *);
  55. void aff_combination_add (aff_tree *, aff_tree *);
  56. void aff_combination_add_elt (aff_tree *, tree, const widest_int &);
  57. void aff_combination_remove_elt (aff_tree *, unsigned);
  58. void aff_combination_convert (aff_tree *, tree);
  59. void tree_to_aff_combination (tree, tree, aff_tree *);
  60. tree aff_combination_to_tree (aff_tree *);
  61. void unshare_aff_combination (aff_tree *);
  62. bool aff_combination_constant_multiple_p (aff_tree *, aff_tree *, widest_int *);
  63. void aff_combination_expand (aff_tree *, hash_map<tree, name_expansion *> **);
  64. void tree_to_aff_combination_expand (tree, tree, aff_tree *,
  65. hash_map<tree, name_expansion *> **);
  66. tree get_inner_reference_aff (tree, aff_tree *, widest_int *);
  67. void free_affine_expand_cache (hash_map<tree, name_expansion *> **);
  68. bool aff_comb_cannot_overlap_p (aff_tree *, const widest_int &,
  69. const widest_int &);
  70. /* Debugging functions. */
  71. void debug_aff (aff_tree *);
  72. /* Return true if AFF is actually ZERO. */
  73. static inline bool
  74. aff_combination_zero_p (aff_tree *aff)
  75. {
  76. if (!aff)
  77. return true;
  78. if (aff->n == 0 && aff->offset == 0)
  79. return true;
  80. return false;
  81. }
  82. #endif /* GCC_TREE_AFFINE_H */