xref: /netbsd-src/external/gpl3/gcc.old/dist/gcc/tree-affine.h (revision 8feb0f0b7eaff0608f8350bbfa3098827b4bb91b)
11debfc3dSmrg /* Operations with affine combinations of trees.
2*8feb0f0bSmrg    Copyright (C) 2005-2020 Free Software Foundation, Inc.
31debfc3dSmrg 
41debfc3dSmrg This file is part of GCC.
51debfc3dSmrg 
61debfc3dSmrg GCC is free software; you can redistribute it and/or modify it
71debfc3dSmrg under the terms of the GNU General Public License as published by the
81debfc3dSmrg Free Software Foundation; either version 3, or (at your option) any
91debfc3dSmrg later version.
101debfc3dSmrg 
111debfc3dSmrg GCC is distributed in the hope that it will be useful, but WITHOUT
121debfc3dSmrg ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
131debfc3dSmrg FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
141debfc3dSmrg for more details.
151debfc3dSmrg 
161debfc3dSmrg You should have received a copy of the GNU General Public License
171debfc3dSmrg along with GCC; see the file COPYING3.  If not see
181debfc3dSmrg <http://www.gnu.org/licenses/>.  */
191debfc3dSmrg 
201debfc3dSmrg /* Affine combination of trees.  We keep track of at most MAX_AFF_ELTS elements
211debfc3dSmrg    to make things simpler; this is sufficient in most cases.  */
221debfc3dSmrg 
231debfc3dSmrg #ifndef GCC_TREE_AFFINE_H
241debfc3dSmrg #define GCC_TREE_AFFINE_H
251debfc3dSmrg 
261debfc3dSmrg 
271debfc3dSmrg #define MAX_AFF_ELTS 8
281debfc3dSmrg 
291debfc3dSmrg /* Element of an affine combination.  */
301debfc3dSmrg 
31*8feb0f0bSmrg class aff_comb_elt
321debfc3dSmrg {
33*8feb0f0bSmrg public:
341debfc3dSmrg   /* The value of the element.  */
351debfc3dSmrg   tree val;
361debfc3dSmrg 
371debfc3dSmrg   /* Its coefficient in the combination.  */
381debfc3dSmrg   widest_int coef;
391debfc3dSmrg };
401debfc3dSmrg 
41*8feb0f0bSmrg class aff_tree
421debfc3dSmrg {
43*8feb0f0bSmrg public:
441debfc3dSmrg   /* Type of the result of the combination.  */
451debfc3dSmrg   tree type;
461debfc3dSmrg 
471debfc3dSmrg   /* Constant offset.  */
48a2dc1f3fSmrg   poly_widest_int offset;
491debfc3dSmrg 
501debfc3dSmrg   /* Number of elements of the combination.  */
511debfc3dSmrg   unsigned n;
521debfc3dSmrg 
531debfc3dSmrg   /* Elements and their coefficients.  Type of elements may be different from
541debfc3dSmrg      TYPE, but their sizes must be the same (STRIP_NOPS is applied to the
551debfc3dSmrg      elements).
561debfc3dSmrg 
571debfc3dSmrg      The coefficients are always sign extended from the precision of TYPE
581debfc3dSmrg      (regardless of signedness of TYPE).  */
59*8feb0f0bSmrg   class aff_comb_elt elts[MAX_AFF_ELTS];
601debfc3dSmrg 
611debfc3dSmrg   /* Remainder of the expression.  Usually NULL, used only if there are more
621debfc3dSmrg      than MAX_AFF_ELTS elements.  Type of REST will be either sizetype for
631debfc3dSmrg      TYPE of POINTER_TYPEs or TYPE.  */
641debfc3dSmrg   tree rest;
651debfc3dSmrg };
661debfc3dSmrg 
67*8feb0f0bSmrg class name_expansion;
681debfc3dSmrg 
69a2dc1f3fSmrg void aff_combination_const (aff_tree *, tree, const poly_widest_int &);
701debfc3dSmrg void aff_combination_elt (aff_tree *, tree, tree);
711debfc3dSmrg void aff_combination_scale (aff_tree *, const widest_int &);
721debfc3dSmrg void aff_combination_mult (aff_tree *, aff_tree *, aff_tree *);
731debfc3dSmrg void aff_combination_add (aff_tree *, aff_tree *);
741debfc3dSmrg void aff_combination_add_elt (aff_tree *, tree, const widest_int &);
751debfc3dSmrg void aff_combination_remove_elt (aff_tree *, unsigned);
761debfc3dSmrg void aff_combination_convert (aff_tree *, tree);
771debfc3dSmrg void tree_to_aff_combination (tree, tree, aff_tree *);
781debfc3dSmrg tree aff_combination_to_tree (aff_tree *);
791debfc3dSmrg void unshare_aff_combination (aff_tree *);
80a2dc1f3fSmrg bool aff_combination_constant_multiple_p (aff_tree *, aff_tree *,
81a2dc1f3fSmrg 					  poly_widest_int *);
821debfc3dSmrg void aff_combination_expand (aff_tree *, hash_map<tree, name_expansion *> **);
831debfc3dSmrg void tree_to_aff_combination_expand (tree, tree, aff_tree *,
841debfc3dSmrg 				     hash_map<tree, name_expansion *> **);
85a2dc1f3fSmrg tree get_inner_reference_aff (tree, aff_tree *, poly_widest_int *);
861debfc3dSmrg void free_affine_expand_cache (hash_map<tree, name_expansion *> **);
87a2dc1f3fSmrg bool aff_comb_cannot_overlap_p (aff_tree *, const poly_widest_int &,
88a2dc1f3fSmrg 				const poly_widest_int &);
891debfc3dSmrg 
901debfc3dSmrg /* Debugging functions.  */
911debfc3dSmrg void debug_aff (aff_tree *);
921debfc3dSmrg 
93a2dc1f3fSmrg /* Return AFF's type.  */
94a2dc1f3fSmrg inline tree
aff_combination_type(aff_tree * aff)95a2dc1f3fSmrg aff_combination_type (aff_tree *aff)
96a2dc1f3fSmrg {
97a2dc1f3fSmrg   return aff->type;
98a2dc1f3fSmrg }
99a2dc1f3fSmrg 
1001debfc3dSmrg /* Return true if AFF is actually ZERO.  */
101a2dc1f3fSmrg inline bool
aff_combination_zero_p(aff_tree * aff)1021debfc3dSmrg aff_combination_zero_p (aff_tree *aff)
1031debfc3dSmrg {
1041debfc3dSmrg   if (!aff)
1051debfc3dSmrg     return true;
1061debfc3dSmrg 
107a2dc1f3fSmrg   if (aff->n == 0 && known_eq (aff->offset, 0))
1081debfc3dSmrg     return true;
1091debfc3dSmrg 
1101debfc3dSmrg   return false;
1111debfc3dSmrg }
1121debfc3dSmrg 
113a2dc1f3fSmrg /* Return true if AFF is actually const.  */
114a2dc1f3fSmrg inline bool
aff_combination_const_p(aff_tree * aff)115a2dc1f3fSmrg aff_combination_const_p (aff_tree *aff)
116a2dc1f3fSmrg {
117a2dc1f3fSmrg   return (aff == NULL || aff->n == 0);
118a2dc1f3fSmrg }
119a2dc1f3fSmrg 
120a2dc1f3fSmrg /* Return true iff AFF contains one (negated) singleton variable.  Users need
121a2dc1f3fSmrg    to make sure AFF points to a valid combination.  */
122a2dc1f3fSmrg inline bool
aff_combination_singleton_var_p(aff_tree * aff)123a2dc1f3fSmrg aff_combination_singleton_var_p (aff_tree *aff)
124a2dc1f3fSmrg {
125a2dc1f3fSmrg   return (aff->n == 1
126a2dc1f3fSmrg 	  && known_eq (aff->offset, 0)
127a2dc1f3fSmrg 	  && (aff->elts[0].coef == 1 || aff->elts[0].coef == -1));
128a2dc1f3fSmrg }
1291debfc3dSmrg #endif /* GCC_TREE_AFFINE_H */
130