2010-05-28 Segher Boessenkool <segher@kernel.crashing.org>
[official-gcc.git] / gcc / tree-affine.c
blobc6c28bd970e74e4a86d2dc348402afe929f55a24
1 /* Operations with affine combinations of trees.
2 Copyright (C) 2005, 2007, 2008, 2010 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 3, or (at your option) any
9 later version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "tree.h"
24 #include "output.h"
25 #include "diagnostic.h"
26 #include "tree-pretty-print.h"
27 #include "tree-dump.h"
28 #include "pointer-set.h"
29 #include "tree-affine.h"
30 #include "gimple.h"
31 #include "flags.h"
33 /* Extends CST as appropriate for the affine combinations COMB. */
35 double_int
36 double_int_ext_for_comb (double_int cst, aff_tree *comb)
38 return double_int_sext (cst, TYPE_PRECISION (comb->type));
41 /* Initializes affine combination COMB so that its value is zero in TYPE. */
43 static void
44 aff_combination_zero (aff_tree *comb, tree type)
46 comb->type = type;
47 comb->offset = double_int_zero;
48 comb->n = 0;
49 comb->rest = NULL_TREE;
52 /* Sets COMB to CST. */
54 void
55 aff_combination_const (aff_tree *comb, tree type, double_int cst)
57 aff_combination_zero (comb, type);
58 comb->offset = double_int_ext_for_comb (cst, comb);
61 /* Sets COMB to single element ELT. */
63 void
64 aff_combination_elt (aff_tree *comb, tree type, tree elt)
66 aff_combination_zero (comb, type);
68 comb->n = 1;
69 comb->elts[0].val = elt;
70 comb->elts[0].coef = double_int_one;
73 /* Scales COMB by SCALE. */
75 void
76 aff_combination_scale (aff_tree *comb, double_int scale)
78 unsigned i, j;
80 scale = double_int_ext_for_comb (scale, comb);
81 if (double_int_one_p (scale))
82 return;
84 if (double_int_zero_p (scale))
86 aff_combination_zero (comb, comb->type);
87 return;
90 comb->offset
91 = double_int_ext_for_comb (double_int_mul (scale, comb->offset), comb);
92 for (i = 0, j = 0; i < comb->n; i++)
94 double_int new_coef;
96 new_coef
97 = double_int_ext_for_comb (double_int_mul (scale, comb->elts[i].coef),
98 comb);
99 /* A coefficient may become zero due to overflow. Remove the zero
100 elements. */
101 if (double_int_zero_p (new_coef))
102 continue;
103 comb->elts[j].coef = new_coef;
104 comb->elts[j].val = comb->elts[i].val;
105 j++;
107 comb->n = j;
109 if (comb->rest)
111 tree type = comb->type;
112 if (POINTER_TYPE_P (type))
113 type = sizetype;
114 if (comb->n < MAX_AFF_ELTS)
116 comb->elts[comb->n].coef = scale;
117 comb->elts[comb->n].val = comb->rest;
118 comb->rest = NULL_TREE;
119 comb->n++;
121 else
122 comb->rest = fold_build2 (MULT_EXPR, type, comb->rest,
123 double_int_to_tree (type, scale));
127 /* Adds ELT * SCALE to COMB. */
129 void
130 aff_combination_add_elt (aff_tree *comb, tree elt, double_int scale)
132 unsigned i;
133 tree type;
135 scale = double_int_ext_for_comb (scale, comb);
136 if (double_int_zero_p (scale))
137 return;
139 for (i = 0; i < comb->n; i++)
140 if (operand_equal_p (comb->elts[i].val, elt, 0))
142 double_int new_coef;
144 new_coef = double_int_add (comb->elts[i].coef, scale);
145 new_coef = double_int_ext_for_comb (new_coef, comb);
146 if (!double_int_zero_p (new_coef))
148 comb->elts[i].coef = new_coef;
149 return;
152 comb->n--;
153 comb->elts[i] = comb->elts[comb->n];
155 if (comb->rest)
157 gcc_assert (comb->n == MAX_AFF_ELTS - 1);
158 comb->elts[comb->n].coef = double_int_one;
159 comb->elts[comb->n].val = comb->rest;
160 comb->rest = NULL_TREE;
161 comb->n++;
163 return;
165 if (comb->n < MAX_AFF_ELTS)
167 comb->elts[comb->n].coef = scale;
168 comb->elts[comb->n].val = elt;
169 comb->n++;
170 return;
173 type = comb->type;
174 if (POINTER_TYPE_P (type))
175 type = sizetype;
177 if (double_int_one_p (scale))
178 elt = fold_convert (type, elt);
179 else
180 elt = fold_build2 (MULT_EXPR, type,
181 fold_convert (type, elt),
182 double_int_to_tree (type, scale));
184 if (comb->rest)
185 comb->rest = fold_build2 (PLUS_EXPR, type, comb->rest,
186 elt);
187 else
188 comb->rest = elt;
191 /* Adds CST to C. */
193 static void
194 aff_combination_add_cst (aff_tree *c, double_int cst)
196 c->offset = double_int_ext_for_comb (double_int_add (c->offset, cst), c);
199 /* Adds COMB2 to COMB1. */
201 void
202 aff_combination_add (aff_tree *comb1, aff_tree *comb2)
204 unsigned i;
206 aff_combination_add_cst (comb1, comb2->offset);
207 for (i = 0; i < comb2->n; i++)
208 aff_combination_add_elt (comb1, comb2->elts[i].val, comb2->elts[i].coef);
209 if (comb2->rest)
210 aff_combination_add_elt (comb1, comb2->rest, double_int_one);
213 /* Converts affine combination COMB to TYPE. */
215 void
216 aff_combination_convert (aff_tree *comb, tree type)
218 unsigned i, j;
219 tree comb_type = comb->type;
221 if (TYPE_PRECISION (type) > TYPE_PRECISION (comb_type))
223 tree val = fold_convert (type, aff_combination_to_tree (comb));
224 tree_to_aff_combination (val, type, comb);
225 return;
228 comb->type = type;
229 if (comb->rest && !POINTER_TYPE_P (type))
230 comb->rest = fold_convert (type, comb->rest);
232 if (TYPE_PRECISION (type) == TYPE_PRECISION (comb_type))
233 return;
235 comb->offset = double_int_ext_for_comb (comb->offset, comb);
236 for (i = j = 0; i < comb->n; i++)
238 double_int new_coef = double_int_ext_for_comb (comb->elts[i].coef, comb);
239 if (double_int_zero_p (new_coef))
240 continue;
241 comb->elts[j].coef = new_coef;
242 comb->elts[j].val = fold_convert (type, comb->elts[i].val);
243 j++;
246 comb->n = j;
247 if (comb->n < MAX_AFF_ELTS && comb->rest)
249 comb->elts[comb->n].coef = double_int_one;
250 comb->elts[comb->n].val = comb->rest;
251 comb->rest = NULL_TREE;
252 comb->n++;
256 /* Splits EXPR into an affine combination of parts. */
258 void
259 tree_to_aff_combination (tree expr, tree type, aff_tree *comb)
261 aff_tree tmp;
262 enum tree_code code;
263 tree cst, core, toffset;
264 HOST_WIDE_INT bitpos, bitsize;
265 enum machine_mode mode;
266 int unsignedp, volatilep;
268 STRIP_NOPS (expr);
270 code = TREE_CODE (expr);
271 switch (code)
273 case INTEGER_CST:
274 aff_combination_const (comb, type, tree_to_double_int (expr));
275 return;
277 case POINTER_PLUS_EXPR:
278 tree_to_aff_combination (TREE_OPERAND (expr, 0), type, comb);
279 tree_to_aff_combination (TREE_OPERAND (expr, 1), sizetype, &tmp);
280 aff_combination_add (comb, &tmp);
281 return;
283 case PLUS_EXPR:
284 case MINUS_EXPR:
285 tree_to_aff_combination (TREE_OPERAND (expr, 0), type, comb);
286 tree_to_aff_combination (TREE_OPERAND (expr, 1), type, &tmp);
287 if (code == MINUS_EXPR)
288 aff_combination_scale (&tmp, double_int_minus_one);
289 aff_combination_add (comb, &tmp);
290 return;
292 case MULT_EXPR:
293 cst = TREE_OPERAND (expr, 1);
294 if (TREE_CODE (cst) != INTEGER_CST)
295 break;
296 tree_to_aff_combination (TREE_OPERAND (expr, 0), type, comb);
297 aff_combination_scale (comb, tree_to_double_int (cst));
298 return;
300 case NEGATE_EXPR:
301 tree_to_aff_combination (TREE_OPERAND (expr, 0), type, comb);
302 aff_combination_scale (comb, double_int_minus_one);
303 return;
305 case BIT_NOT_EXPR:
306 /* ~x = -x - 1 */
307 tree_to_aff_combination (TREE_OPERAND (expr, 0), type, comb);
308 aff_combination_scale (comb, double_int_minus_one);
309 aff_combination_add_cst (comb, double_int_minus_one);
310 return;
312 case ADDR_EXPR:
313 core = get_inner_reference (TREE_OPERAND (expr, 0), &bitsize, &bitpos,
314 &toffset, &mode, &unsignedp, &volatilep,
315 false);
316 if (bitpos % BITS_PER_UNIT != 0)
317 break;
318 aff_combination_const (comb, type,
319 uhwi_to_double_int (bitpos / BITS_PER_UNIT));
320 core = build_fold_addr_expr (core);
321 if (TREE_CODE (core) == ADDR_EXPR)
322 aff_combination_add_elt (comb, core, double_int_one);
323 else
325 tree_to_aff_combination (core, type, &tmp);
326 aff_combination_add (comb, &tmp);
328 if (toffset)
330 tree_to_aff_combination (toffset, type, &tmp);
331 aff_combination_add (comb, &tmp);
333 return;
335 default:
336 break;
339 aff_combination_elt (comb, type, expr);
342 /* Creates EXPR + ELT * SCALE in TYPE. EXPR is taken from affine
343 combination COMB. */
345 static tree
346 add_elt_to_tree (tree expr, tree type, tree elt, double_int scale,
347 aff_tree *comb)
349 enum tree_code code;
350 tree type1 = type;
351 if (POINTER_TYPE_P (type))
352 type1 = sizetype;
354 scale = double_int_ext_for_comb (scale, comb);
355 elt = fold_convert (type1, elt);
357 if (double_int_one_p (scale))
359 if (!expr)
360 return fold_convert (type, elt);
362 if (POINTER_TYPE_P (type))
363 return fold_build2 (POINTER_PLUS_EXPR, type, expr, elt);
364 return fold_build2 (PLUS_EXPR, type, expr, elt);
367 if (double_int_minus_one_p (scale))
369 if (!expr)
370 return fold_convert (type, fold_build1 (NEGATE_EXPR, type1, elt));
372 if (POINTER_TYPE_P (type))
374 elt = fold_build1 (NEGATE_EXPR, type1, elt);
375 return fold_build2 (POINTER_PLUS_EXPR, type, expr, elt);
377 return fold_build2 (MINUS_EXPR, type, expr, elt);
380 if (!expr)
381 return fold_convert (type,
382 fold_build2 (MULT_EXPR, type1, elt,
383 double_int_to_tree (type1, scale)));
385 if (double_int_negative_p (scale))
387 code = MINUS_EXPR;
388 scale = double_int_neg (scale);
390 else
391 code = PLUS_EXPR;
393 elt = fold_build2 (MULT_EXPR, type1, elt,
394 double_int_to_tree (type1, scale));
395 if (POINTER_TYPE_P (type))
397 if (code == MINUS_EXPR)
398 elt = fold_build1 (NEGATE_EXPR, type1, elt);
399 return fold_build2 (POINTER_PLUS_EXPR, type, expr, elt);
401 return fold_build2 (code, type, expr, elt);
404 /* Makes tree from the affine combination COMB. */
406 tree
407 aff_combination_to_tree (aff_tree *comb)
409 tree type = comb->type;
410 tree expr = comb->rest;
411 unsigned i;
412 double_int off, sgn;
413 tree type1 = type;
414 if (POINTER_TYPE_P (type))
415 type1 = sizetype;
417 gcc_assert (comb->n == MAX_AFF_ELTS || comb->rest == NULL_TREE);
419 for (i = 0; i < comb->n; i++)
420 expr = add_elt_to_tree (expr, type, comb->elts[i].val, comb->elts[i].coef,
421 comb);
423 /* Ensure that we get x - 1, not x + (-1) or x + 0xff..f if x is
424 unsigned. */
425 if (double_int_negative_p (comb->offset))
427 off = double_int_neg (comb->offset);
428 sgn = double_int_minus_one;
430 else
432 off = comb->offset;
433 sgn = double_int_one;
435 return add_elt_to_tree (expr, type, double_int_to_tree (type1, off), sgn,
436 comb);
439 /* Copies the tree elements of COMB to ensure that they are not shared. */
441 void
442 unshare_aff_combination (aff_tree *comb)
444 unsigned i;
446 for (i = 0; i < comb->n; i++)
447 comb->elts[i].val = unshare_expr (comb->elts[i].val);
448 if (comb->rest)
449 comb->rest = unshare_expr (comb->rest);
452 /* Remove M-th element from COMB. */
454 void
455 aff_combination_remove_elt (aff_tree *comb, unsigned m)
457 comb->n--;
458 if (m <= comb->n)
459 comb->elts[m] = comb->elts[comb->n];
460 if (comb->rest)
462 comb->elts[comb->n].coef = double_int_one;
463 comb->elts[comb->n].val = comb->rest;
464 comb->rest = NULL_TREE;
465 comb->n++;
469 /* Adds C * COEF * VAL to R. VAL may be NULL, in that case only
470 C * COEF is added to R. */
473 static void
474 aff_combination_add_product (aff_tree *c, double_int coef, tree val,
475 aff_tree *r)
477 unsigned i;
478 tree aval, type;
480 for (i = 0; i < c->n; i++)
482 aval = c->elts[i].val;
483 if (val)
485 type = TREE_TYPE (aval);
486 aval = fold_build2 (MULT_EXPR, type, aval,
487 fold_convert (type, val));
490 aff_combination_add_elt (r, aval,
491 double_int_mul (coef, c->elts[i].coef));
494 if (c->rest)
496 aval = c->rest;
497 if (val)
499 type = TREE_TYPE (aval);
500 aval = fold_build2 (MULT_EXPR, type, aval,
501 fold_convert (type, val));
504 aff_combination_add_elt (r, aval, coef);
507 if (val)
508 aff_combination_add_elt (r, val,
509 double_int_mul (coef, c->offset));
510 else
511 aff_combination_add_cst (r, double_int_mul (coef, c->offset));
514 /* Multiplies C1 by C2, storing the result to R */
516 void
517 aff_combination_mult (aff_tree *c1, aff_tree *c2, aff_tree *r)
519 unsigned i;
520 gcc_assert (TYPE_PRECISION (c1->type) == TYPE_PRECISION (c2->type));
522 aff_combination_zero (r, c1->type);
524 for (i = 0; i < c2->n; i++)
525 aff_combination_add_product (c1, c2->elts[i].coef, c2->elts[i].val, r);
526 if (c2->rest)
527 aff_combination_add_product (c1, double_int_one, c2->rest, r);
528 aff_combination_add_product (c1, c2->offset, NULL, r);
531 /* Returns the element of COMB whose value is VAL, or NULL if no such
532 element exists. If IDX is not NULL, it is set to the index of VAL in
533 COMB. */
535 static struct aff_comb_elt *
536 aff_combination_find_elt (aff_tree *comb, tree val, unsigned *idx)
538 unsigned i;
540 for (i = 0; i < comb->n; i++)
541 if (operand_equal_p (comb->elts[i].val, val, 0))
543 if (idx)
544 *idx = i;
546 return &comb->elts[i];
549 return NULL;
552 /* Element of the cache that maps ssa name NAME to its expanded form
553 as an affine expression EXPANSION. */
555 struct name_expansion
557 aff_tree expansion;
559 /* True if the expansion for the name is just being generated. */
560 unsigned in_progress : 1;
563 /* Expands SSA names in COMB recursively. CACHE is used to cache the
564 results. */
566 void
567 aff_combination_expand (aff_tree *comb ATTRIBUTE_UNUSED,
568 struct pointer_map_t **cache ATTRIBUTE_UNUSED)
570 unsigned i;
571 aff_tree to_add, current, curre;
572 tree e, rhs;
573 gimple def;
574 double_int scale;
575 void **slot;
576 struct name_expansion *exp;
578 aff_combination_zero (&to_add, comb->type);
579 for (i = 0; i < comb->n; i++)
581 tree type, name;
582 enum tree_code code;
584 e = comb->elts[i].val;
585 type = TREE_TYPE (e);
586 name = e;
587 /* Look through some conversions. */
588 if (TREE_CODE (e) == NOP_EXPR
589 && (TYPE_PRECISION (type)
590 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (e, 0)))))
591 name = TREE_OPERAND (e, 0);
592 if (TREE_CODE (name) != SSA_NAME)
593 continue;
594 def = SSA_NAME_DEF_STMT (name);
595 if (!is_gimple_assign (def) || gimple_assign_lhs (def) != name)
596 continue;
598 code = gimple_assign_rhs_code (def);
599 if (code != SSA_NAME
600 && !IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code))
601 && (get_gimple_rhs_class (code) != GIMPLE_SINGLE_RHS
602 || !is_gimple_min_invariant (gimple_assign_rhs1 (def))))
603 continue;
605 /* We do not know whether the reference retains its value at the
606 place where the expansion is used. */
607 if (TREE_CODE_CLASS (code) == tcc_reference)
608 continue;
610 if (!*cache)
611 *cache = pointer_map_create ();
612 slot = pointer_map_insert (*cache, e);
613 exp = (struct name_expansion *) *slot;
615 if (!exp)
617 exp = XNEW (struct name_expansion);
618 exp->in_progress = 1;
619 *slot = exp;
620 /* In principle this is a generally valid folding, but
621 it is not unconditionally an optimization, so do it
622 here and not in fold_unary. */
623 /* Convert (T1)(X *+- CST) into (T1)X *+- (T1)CST if T1 is wider
624 than the type of X and overflow for the type of X is
625 undefined. */
626 if (e != name
627 && INTEGRAL_TYPE_P (type)
628 && INTEGRAL_TYPE_P (TREE_TYPE (name))
629 && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (name))
630 && TYPE_PRECISION (type) > TYPE_PRECISION (TREE_TYPE (name))
631 && (code == PLUS_EXPR || code == MINUS_EXPR || code == MULT_EXPR)
632 && TREE_CODE (gimple_assign_rhs2 (def)) == INTEGER_CST)
633 rhs = fold_build2 (code, type,
634 fold_convert (type, gimple_assign_rhs1 (def)),
635 fold_convert (type, gimple_assign_rhs2 (def)));
636 else
638 rhs = gimple_assign_rhs_to_tree (def);
639 if (e != name)
640 rhs = fold_convert (type, rhs);
642 tree_to_aff_combination_expand (rhs, comb->type, &current, cache);
643 exp->expansion = current;
644 exp->in_progress = 0;
646 else
648 /* Since we follow the definitions in the SSA form, we should not
649 enter a cycle unless we pass through a phi node. */
650 gcc_assert (!exp->in_progress);
651 current = exp->expansion;
654 /* Accumulate the new terms to TO_ADD, so that we do not modify
655 COMB while traversing it; include the term -coef * E, to remove
656 it from COMB. */
657 scale = comb->elts[i].coef;
658 aff_combination_zero (&curre, comb->type);
659 aff_combination_add_elt (&curre, e, double_int_neg (scale));
660 aff_combination_scale (&current, scale);
661 aff_combination_add (&to_add, &current);
662 aff_combination_add (&to_add, &curre);
664 aff_combination_add (comb, &to_add);
667 /* Similar to tree_to_aff_combination, but follows SSA name definitions
668 and expands them recursively. CACHE is used to cache the expansions
669 of the ssa names, to avoid exponential time complexity for cases
670 like
672 a1 = a0 + a0;
673 a2 = a1 + a1;
674 a3 = a2 + a2;
675 ... */
677 void
678 tree_to_aff_combination_expand (tree expr, tree type, aff_tree *comb,
679 struct pointer_map_t **cache)
681 tree_to_aff_combination (expr, type, comb);
682 aff_combination_expand (comb, cache);
685 /* Frees memory occupied by struct name_expansion in *VALUE. Callback for
686 pointer_map_traverse. */
688 static bool
689 free_name_expansion (const void *key ATTRIBUTE_UNUSED, void **value,
690 void *data ATTRIBUTE_UNUSED)
692 struct name_expansion *const exp = (struct name_expansion *) *value;
694 free (exp);
695 return true;
698 /* Frees memory allocated for the CACHE used by
699 tree_to_aff_combination_expand. */
701 void
702 free_affine_expand_cache (struct pointer_map_t **cache)
704 if (!*cache)
705 return;
707 pointer_map_traverse (*cache, free_name_expansion, NULL);
708 pointer_map_destroy (*cache);
709 *cache = NULL;
712 /* If VAL != CST * DIV for any constant CST, returns false.
713 Otherwise, if VAL != 0 (and hence CST != 0), and *MULT_SET is true,
714 additionally compares CST and MULT, and if they are different,
715 returns false. Finally, if neither of these two cases occur,
716 true is returned, and if CST != 0, CST is stored to MULT and
717 MULT_SET is set to true. */
719 static bool
720 double_int_constant_multiple_p (double_int val, double_int div,
721 bool *mult_set, double_int *mult)
723 double_int rem, cst;
725 if (double_int_zero_p (val))
726 return true;
728 if (double_int_zero_p (div))
729 return false;
731 cst = double_int_sdivmod (val, div, FLOOR_DIV_EXPR, &rem);
732 if (!double_int_zero_p (rem))
733 return false;
735 if (*mult_set && !double_int_equal_p (*mult, cst))
736 return false;
738 *mult_set = true;
739 *mult = cst;
740 return true;
743 /* Returns true if VAL = X * DIV for some constant X. If this is the case,
744 X is stored to MULT. */
746 bool
747 aff_combination_constant_multiple_p (aff_tree *val, aff_tree *div,
748 double_int *mult)
750 bool mult_set = false;
751 unsigned i;
753 if (val->n == 0 && double_int_zero_p (val->offset))
755 *mult = double_int_zero;
756 return true;
758 if (val->n != div->n)
759 return false;
761 if (val->rest || div->rest)
762 return false;
764 if (!double_int_constant_multiple_p (val->offset, div->offset,
765 &mult_set, mult))
766 return false;
768 for (i = 0; i < div->n; i++)
770 struct aff_comb_elt *elt
771 = aff_combination_find_elt (val, div->elts[i].val, NULL);
772 if (!elt)
773 return false;
774 if (!double_int_constant_multiple_p (elt->coef, div->elts[i].coef,
775 &mult_set, mult))
776 return false;
779 gcc_assert (mult_set);
780 return true;
783 /* Prints the affine VAL to the FILE. */
785 void
786 print_aff (FILE *file, aff_tree *val)
788 unsigned i;
789 bool uns = TYPE_UNSIGNED (val->type);
790 if (POINTER_TYPE_P (val->type))
791 uns = false;
792 fprintf (file, "{\n type = ");
793 print_generic_expr (file, val->type, TDF_VOPS|TDF_MEMSYMS);
794 fprintf (file, "\n offset = ");
795 dump_double_int (file, val->offset, uns);
796 if (val->n > 0)
798 fprintf (file, "\n elements = {\n");
799 for (i = 0; i < val->n; i++)
801 fprintf (file, " [%d] = ", i);
802 print_generic_expr (file, val->elts[i].val, TDF_VOPS|TDF_MEMSYMS);
804 fprintf (file, " * ");
805 dump_double_int (file, val->elts[i].coef, uns);
806 if (i != val->n - 1)
807 fprintf (file, ", \n");
809 fprintf (file, "\n }");
811 if (val->rest)
813 fprintf (file, "\n rest = ");
814 print_generic_expr (file, val->rest, TDF_VOPS|TDF_MEMSYMS);
816 fprintf (file, "\n}");
819 /* Prints the affine VAL to the standard error, used for debugging. */
821 void
822 debug_aff (aff_tree *val)
824 print_aff (stderr, val);
825 fprintf (stderr, "\n");
828 /* Returns address of the reference REF in ADDR. The size of the accessed
829 location is stored to SIZE. */
831 void
832 get_inner_reference_aff (tree ref, aff_tree *addr, double_int *size)
834 HOST_WIDE_INT bitsize, bitpos;
835 tree toff;
836 enum machine_mode mode;
837 int uns, vol;
838 aff_tree tmp;
839 tree base = get_inner_reference (ref, &bitsize, &bitpos, &toff, &mode,
840 &uns, &vol, false);
841 tree base_addr = build_fold_addr_expr (base);
843 /* ADDR = &BASE + TOFF + BITPOS / BITS_PER_UNIT. */
845 tree_to_aff_combination (base_addr, sizetype, addr);
847 if (toff)
849 tree_to_aff_combination (toff, sizetype, &tmp);
850 aff_combination_add (addr, &tmp);
853 aff_combination_const (&tmp, sizetype,
854 shwi_to_double_int (bitpos / BITS_PER_UNIT));
855 aff_combination_add (addr, &tmp);
857 *size = shwi_to_double_int ((bitsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT);