testsuite: Correct vec-rlmi-rlnm.c testsuite expected result
[official-gcc.git] / gcc / gimple-range-cache.cc
blob13b9933cc019813add3297cdbab8c9c2ab362f49
1 /* Gimple ranger SSA cache implementation.
2 Copyright (C) 2017-2020 Free Software Foundation, Inc.
3 Contributed by Andrew MacLeod <amacleod@redhat.com>.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "backend.h"
25 #include "insn-codes.h"
26 #include "tree.h"
27 #include "gimple.h"
28 #include "ssa.h"
29 #include "gimple-pretty-print.h"
30 #include "gimple-range.h"
32 // During contructor, allocate the vector of ssa_names.
34 non_null_ref::non_null_ref ()
36 m_nn.create (0);
37 m_nn.safe_grow_cleared (num_ssa_names);
38 bitmap_obstack_initialize (&m_bitmaps);
41 // Free any bitmaps which were allocated,a swell as the vector itself.
43 non_null_ref::~non_null_ref ()
45 bitmap_obstack_release (&m_bitmaps);
46 m_nn.release ();
49 // Return true if NAME has a non-null dereference in block bb. If this is the
50 // first query for NAME, calculate the summary first.
52 bool
53 non_null_ref::non_null_deref_p (tree name, basic_block bb)
55 if (!POINTER_TYPE_P (TREE_TYPE (name)))
56 return false;
58 unsigned v = SSA_NAME_VERSION (name);
59 if (!m_nn[v])
60 process_name (name);
62 return bitmap_bit_p (m_nn[v], bb->index);
65 // Allocate an populate the bitmap for NAME. An ON bit for a block
66 // index indicates there is a non-null reference in that block. In
67 // order to populate the bitmap, a quick run of all the immediate uses
68 // are made and the statement checked to see if a non-null dereference
69 // is made on that statement.
71 void
72 non_null_ref::process_name (tree name)
74 unsigned v = SSA_NAME_VERSION (name);
75 use_operand_p use_p;
76 imm_use_iterator iter;
77 bitmap b;
79 // Only tracked for pointers.
80 if (!POINTER_TYPE_P (TREE_TYPE (name)))
81 return;
83 // Already processed if a bitmap has been allocated.
84 if (m_nn[v])
85 return;
87 b = BITMAP_ALLOC (&m_bitmaps);
89 // Loop over each immediate use and see if it implies a non-null value.
90 FOR_EACH_IMM_USE_FAST (use_p, iter, name)
92 gimple *s = USE_STMT (use_p);
93 unsigned index = gimple_bb (s)->index;
94 tree value;
95 enum tree_code comp_code;
97 // If bit is already set for this block, dont bother looking again.
98 if (bitmap_bit_p (b, index))
99 continue;
101 // If we can infer a != 0 range, then set the bit for this BB
102 if (infer_value_range (s, name, &comp_code, &value))
104 if (comp_code == NE_EXPR && integer_zerop (value))
105 bitmap_set_bit (b, index);
109 m_nn[v] = b;
112 // -------------------------------------------------------------------------
114 // This class implements a cache of ranges indexed by basic block. It
115 // represents all that is known about an SSA_NAME on entry to each
116 // block. It caches a range-for-type varying range so it doesn't need
117 // to be reformed all the time. If a range is ever always associated
118 // with a type, we can use that instead. Whenever varying is being
119 // set for a block, the cache simply points to this cached one rather
120 // than create a new one each time.
122 class ssa_block_ranges
124 public:
125 ssa_block_ranges (tree t, irange_allocator *allocator);
126 ~ssa_block_ranges ();
128 void set_bb_range (const basic_block bb, const irange &r);
129 void set_bb_varying (const basic_block bb);
130 bool get_bb_range (irange &r, const basic_block bb);
131 bool bb_range_p (const basic_block bb);
133 void dump(FILE *f);
134 private:
135 vec<irange *> m_tab;
136 irange *m_type_range;
137 tree m_type;
138 irange_allocator *m_irange_allocator;
142 // Initialize a block cache for an ssa_name of type T.
144 ssa_block_ranges::ssa_block_ranges (tree t, irange_allocator *allocator)
146 gcc_checking_assert (TYPE_P (t));
147 m_type = t;
148 m_irange_allocator = allocator;
150 m_tab.create (0);
151 m_tab.safe_grow_cleared (last_basic_block_for_fn (cfun));
153 // Create the cached type range.
154 m_type_range = m_irange_allocator->allocate (2);
155 m_type_range->set_varying (t);
157 m_tab[ENTRY_BLOCK_PTR_FOR_FN (cfun)->index] = m_type_range;
160 // Destruct block range.
162 ssa_block_ranges::~ssa_block_ranges ()
164 m_tab.release ();
167 // Set the range for block BB to be R.
169 void
170 ssa_block_ranges::set_bb_range (const basic_block bb, const irange &r)
172 irange *m = m_irange_allocator->allocate (r);
173 m_tab[bb->index] = m;
176 // Set the range for block BB to the range for the type.
178 void
179 ssa_block_ranges::set_bb_varying (const basic_block bb)
181 m_tab[bb->index] = m_type_range;
184 // Return the range associated with block BB in R. Return false if
185 // there is no range.
187 bool
188 ssa_block_ranges::get_bb_range (irange &r, const basic_block bb)
190 irange *m = m_tab[bb->index];
191 if (m)
193 r = *m;
194 return true;
196 return false;
199 // Return true if a range is present.
201 bool
202 ssa_block_ranges::bb_range_p (const basic_block bb)
204 return m_tab[bb->index] != NULL;
208 // Print the list of known ranges for file F in a nice format.
210 void
211 ssa_block_ranges::dump (FILE *f)
213 basic_block bb;
214 int_range_max r;
216 FOR_EACH_BB_FN (bb, cfun)
217 if (get_bb_range (r, bb))
219 fprintf (f, "BB%d -> ", bb->index);
220 r.dump (f);
221 fprintf (f, "\n");
225 // -------------------------------------------------------------------------
227 // Initialize the block cache.
229 block_range_cache::block_range_cache ()
231 m_ssa_ranges.create (0);
232 m_ssa_ranges.safe_grow_cleared (num_ssa_names);
233 m_irange_allocator = new irange_allocator;
236 // Remove any m_block_caches which have been created.
238 block_range_cache::~block_range_cache ()
240 unsigned x;
241 for (x = 0; x < m_ssa_ranges.length (); ++x)
243 if (m_ssa_ranges[x])
244 delete m_ssa_ranges[x];
246 delete m_irange_allocator;
247 // Release the vector itself.
248 m_ssa_ranges.release ();
251 // Return a reference to the m_block_cache for NAME. If it has not been
252 // accessed yet, allocate it.
254 ssa_block_ranges &
255 block_range_cache::get_block_ranges (tree name)
257 unsigned v = SSA_NAME_VERSION (name);
258 if (v >= m_ssa_ranges.length ())
259 m_ssa_ranges.safe_grow_cleared (num_ssa_names + 1);
261 if (!m_ssa_ranges[v])
262 m_ssa_ranges[v] = new ssa_block_ranges (TREE_TYPE (name), m_irange_allocator);
264 return *(m_ssa_ranges[v]);
267 // Set the range for NAME on entry to block BB to R.
269 void
270 block_range_cache::set_bb_range (tree name, const basic_block bb,
271 const irange &r)
273 return get_block_ranges (name).set_bb_range (bb, r);
276 // Set the range for NAME on entry to block BB to varying.
278 void
279 block_range_cache::set_bb_varying (tree name, const basic_block bb)
281 return get_block_ranges (name).set_bb_varying (bb);
284 // Return the range for NAME on entry to BB in R. Return true if there
285 // is one.
287 bool
288 block_range_cache::get_bb_range (irange &r, tree name, const basic_block bb)
290 return get_block_ranges (name).get_bb_range (r, bb);
293 // Return true if NAME has a range set in block BB.
295 bool
296 block_range_cache::bb_range_p (tree name, const basic_block bb)
298 return get_block_ranges (name).bb_range_p (bb);
301 // Print all known block caches to file F.
303 void
304 block_range_cache::dump (FILE *f)
306 unsigned x;
307 for (x = 0; x < m_ssa_ranges.length (); ++x)
309 if (m_ssa_ranges[x])
311 fprintf (f, " Ranges for ");
312 print_generic_expr (f, ssa_name (x), TDF_NONE);
313 fprintf (f, ":\n");
314 m_ssa_ranges[x]->dump (f);
315 fprintf (f, "\n");
320 // Print all known ranges on entry to blobk BB to file F.
322 void
323 block_range_cache::dump (FILE *f, basic_block bb, bool print_varying)
325 unsigned x;
326 int_range_max r;
327 bool summarize_varying = false;
328 for (x = 1; x < m_ssa_ranges.length (); ++x)
330 if (!gimple_range_ssa_p (ssa_name (x)))
331 continue;
332 if (m_ssa_ranges[x] && m_ssa_ranges[x]->get_bb_range (r, bb))
334 if (!print_varying && r.varying_p ())
336 summarize_varying = true;
337 continue;
339 print_generic_expr (f, ssa_name (x), TDF_NONE);
340 fprintf (f, "\t");
341 r.dump(f);
342 fprintf (f, "\n");
345 // If there were any varying entries, lump them all together.
346 if (summarize_varying)
348 fprintf (f, "VARYING_P on entry : ");
349 for (x = 1; x < num_ssa_names; ++x)
351 if (!gimple_range_ssa_p (ssa_name (x)))
352 continue;
353 if (m_ssa_ranges[x] && m_ssa_ranges[x]->get_bb_range (r, bb))
355 if (r.varying_p ())
357 print_generic_expr (f, ssa_name (x), TDF_NONE);
358 fprintf (f, " ");
362 fprintf (f, "\n");
366 // -------------------------------------------------------------------------
368 // Initialize a global cache.
370 ssa_global_cache::ssa_global_cache ()
372 m_tab.create (0);
373 m_tab.safe_grow_cleared (num_ssa_names);
374 m_irange_allocator = new irange_allocator;
377 // Deconstruct a global cache.
379 ssa_global_cache::~ssa_global_cache ()
381 m_tab.release ();
382 delete m_irange_allocator;
385 // Retrieve the global range of NAME from cache memory if it exists.
386 // Return the value in R.
388 bool
389 ssa_global_cache::get_global_range (irange &r, tree name) const
391 unsigned v = SSA_NAME_VERSION (name);
392 if (v >= m_tab.length ())
393 return false;
395 irange *stow = m_tab[v];
396 if (!stow)
397 return false;
398 r = *stow;
399 return true;
402 // Set the range for NAME to R in the global cache.
404 void
405 ssa_global_cache::set_global_range (tree name, const irange &r)
407 unsigned v = SSA_NAME_VERSION (name);
408 if (v >= m_tab.length ())
409 m_tab.safe_grow_cleared (num_ssa_names + 1);
411 irange *m = m_tab[v];
412 if (m && m->fits_p (r))
413 *m = r;
414 else
415 m_tab[v] = m_irange_allocator->allocate (r);
418 // Set the range for NAME to R in the glonbal cache.
420 void
421 ssa_global_cache::clear_global_range (tree name)
423 unsigned v = SSA_NAME_VERSION (name);
424 if (v >= m_tab.length ())
425 m_tab.safe_grow_cleared (num_ssa_names + 1);
426 m_tab[v] = NULL;
429 // Clear the global cache.
431 void
432 ssa_global_cache::clear ()
434 memset (m_tab.address(), 0, m_tab.length () * sizeof (irange *));
437 // Dump the contents of the global cache to F.
439 void
440 ssa_global_cache::dump (FILE *f)
442 unsigned x;
443 int_range_max r;
444 fprintf (f, "Non-varying global ranges:\n");
445 fprintf (f, "=========================:\n");
446 for ( x = 1; x < num_ssa_names; x++)
447 if (gimple_range_ssa_p (ssa_name (x)) &&
448 get_global_range (r, ssa_name (x)) && !r.varying_p ())
450 print_generic_expr (f, ssa_name (x), TDF_NONE);
451 fprintf (f, " : ");
452 r.dump (f);
453 fprintf (f, "\n");
455 fputc ('\n', f);
458 // --------------------------------------------------------------------------
460 ranger_cache::ranger_cache (range_query &q) : query (q)
462 m_workback.create (0);
463 m_workback.safe_grow_cleared (last_basic_block_for_fn (cfun));
464 m_update_list.create (0);
465 m_update_list.safe_grow_cleared (last_basic_block_for_fn (cfun));
466 m_update_list.truncate (0);
467 m_poor_value_list.create (0);
468 m_poor_value_list.safe_grow_cleared (20);
469 m_poor_value_list.truncate (0);
472 ranger_cache::~ranger_cache ()
474 m_poor_value_list.release ();
475 m_workback.release ();
476 m_update_list.release ();
479 // Push a request for a new lookup in block BB of name. Return true if
480 // the request is actually made (ie, isn't a duplicate).
482 bool
483 ranger_cache::push_poor_value (basic_block bb, tree name)
485 if (m_poor_value_list.length ())
487 // Don't push anything else to the same block. If there are multiple
488 // things required, another request will come during a later evaluation
489 // and this prevents oscillation building uneccessary depth.
490 if ((m_poor_value_list.last ()).bb == bb)
491 return false;
494 struct update_record rec;
495 rec.bb = bb;
496 rec.calc = name;
497 m_poor_value_list.safe_push (rec);
498 return true;
501 // Provide lookup for the gori-computes class to access the best known range
502 // of an ssa_name in any given basic block. Note, this does no additonal
503 // lookups, just accesses the data that is already known.
505 void
506 ranger_cache::ssa_range_in_bb (irange &r, tree name, basic_block bb)
508 gimple *s = SSA_NAME_DEF_STMT (name);
509 basic_block def_bb = ((s && gimple_bb (s)) ? gimple_bb (s) :
510 ENTRY_BLOCK_PTR_FOR_FN (cfun));
511 if (bb == def_bb)
513 // NAME is defined in this block, so request its current value
514 if (!m_globals.get_global_range (r, name))
516 // If it doesn't have a value calculated, it means it's a
517 // "poor" value being used in some calculation. Queue it up
518 // as a poor value to be improved later.
519 r = gimple_range_global (name);
520 if (push_poor_value (bb, name))
522 if (DEBUG_RANGE_CACHE)
524 fprintf (dump_file,
525 "*CACHE* no global def in bb %d for ", bb->index);
526 print_generic_expr (dump_file, name, TDF_SLIM);
527 fprintf (dump_file, " depth : %d\n",
528 m_poor_value_list.length ());
533 // Look for the on-entry value of name in BB from the cache.
534 else if (!m_on_entry.get_bb_range (r, name, bb))
536 // If it has no entry then mark this as a poor value.
537 if (push_poor_value (bb, name))
539 if (DEBUG_RANGE_CACHE)
541 fprintf (dump_file,
542 "*CACHE* no on entry range in bb %d for ", bb->index);
543 print_generic_expr (dump_file, name, TDF_SLIM);
544 fprintf (dump_file, " depth : %d\n", m_poor_value_list.length ());
547 // Try to pick up any known global value as a best guess for now.
548 if (!m_globals.get_global_range (r, name))
549 r = gimple_range_global (name);
552 // Check if pointers have any non-null dereferences. Non-call
553 // exceptions mean we could throw in the middle of the block, so just
554 // punt for now on those.
555 if (r.varying_p () && m_non_null.non_null_deref_p (name, bb) &&
556 !cfun->can_throw_non_call_exceptions)
557 r = range_nonzero (TREE_TYPE (name));
560 // Return a static range for NAME on entry to basic block BB in R. If
561 // calc is true, fill any cache entries required between BB and the
562 // def block for NAME. Otherwise, return false if the cache is empty.
564 bool
565 ranger_cache::block_range (irange &r, basic_block bb, tree name, bool calc)
567 gcc_checking_assert (gimple_range_ssa_p (name));
569 if (calc)
571 gimple *def_stmt = SSA_NAME_DEF_STMT (name);
572 basic_block def_bb = NULL;
573 if (def_stmt)
574 def_bb = gimple_bb (def_stmt);;
575 if (!def_bb)
577 // If we get to the entry block, this better be a default def
578 // or range_on_entry was called for a block not dominated by
579 // the def.
580 gcc_checking_assert (SSA_NAME_IS_DEFAULT_DEF (name));
581 def_bb = ENTRY_BLOCK_PTR_FOR_FN (cfun);
584 // There is no range on entry for the definition block.
585 if (def_bb == bb)
586 return false;
588 // Otherwise, go figure out what is known in predecessor blocks.
589 fill_block_cache (name, bb, def_bb);
590 gcc_checking_assert (m_on_entry.bb_range_p (name, bb));
592 return m_on_entry.get_bb_range (r, name, bb);
595 // Add BB to the list of blocks to update, unless it's already in the list.
597 void
598 ranger_cache::add_to_update (basic_block bb)
600 if (!m_update_list.contains (bb))
601 m_update_list.quick_push (bb);
604 // If there is anything in the iterative update_list, continue
605 // processing NAME until the list of blocks is empty.
607 void
608 ranger_cache::iterative_cache_update (tree name)
610 basic_block bb;
611 edge_iterator ei;
612 edge e;
613 int_range_max new_range;
614 int_range_max current_range;
615 int_range_max e_range;
617 // Process each block by seeing if its calculated range on entry is
618 // the same as its cached value. If there is a difference, update
619 // the cache to reflect the new value, and check to see if any
620 // successors have cache entries which may need to be checked for
621 // updates.
623 while (m_update_list.length () > 0)
625 bb = m_update_list.pop ();
626 gcc_checking_assert (m_on_entry.bb_range_p (name, bb));
627 m_on_entry.get_bb_range (current_range, name, bb);
629 // Calculate the "new" range on entry by unioning the pred edges.
630 new_range.set_undefined ();
631 FOR_EACH_EDGE (e, ei, bb->preds)
633 if (DEBUG_RANGE_CACHE)
634 fprintf (dump_file, " edge %d->%d :", e->src->index, bb->index);
635 // Get whatever range we can for this edge.
636 if (!outgoing_edge_range_p (e_range, e, name))
638 ssa_range_in_bb (e_range, name, e->src);
639 if (DEBUG_RANGE_CACHE)
641 fprintf (dump_file, "No outgoing edge range, picked up ");
642 e_range.dump(dump_file);
643 fprintf (dump_file, "\n");
646 else
648 if (DEBUG_RANGE_CACHE)
650 fprintf (dump_file, "outgoing range :");
651 e_range.dump(dump_file);
652 fprintf (dump_file, "\n");
655 new_range.union_ (e_range);
656 if (new_range.varying_p ())
657 break;
660 if (DEBUG_RANGE_CACHE)
662 fprintf (dump_file, "FWD visiting block %d for ", bb->index);
663 print_generic_expr (dump_file, name, TDF_SLIM);
664 fprintf (dump_file, " starting range : ");
665 current_range.dump (dump_file);
666 fprintf (dump_file, "\n");
669 // If the range on entry has changed, update it.
670 if (new_range != current_range)
672 if (DEBUG_RANGE_CACHE)
674 fprintf (dump_file, " Updating range to ");
675 new_range.dump (dump_file);
676 fprintf (dump_file, "\n Updating blocks :");
678 m_on_entry.set_bb_range (name, bb, new_range);
679 // Mark each successor that has a range to re-check its range
680 FOR_EACH_EDGE (e, ei, bb->succs)
681 if (m_on_entry.bb_range_p (name, e->dest))
683 if (DEBUG_RANGE_CACHE)
684 fprintf (dump_file, " bb%d",e->dest->index);
685 add_to_update (e->dest);
687 if (DEBUG_RANGE_CACHE)
688 fprintf (dump_file, "\n");
691 if (DEBUG_RANGE_CACHE)
693 fprintf (dump_file, "DONE visiting blocks for ");
694 print_generic_expr (dump_file, name, TDF_SLIM);
695 fprintf (dump_file, "\n");
699 // Make sure that the range-on-entry cache for NAME is set for block BB.
700 // Work back through the CFG to DEF_BB ensuring the range is calculated
701 // on the block/edges leading back to that point.
703 void
704 ranger_cache::fill_block_cache (tree name, basic_block bb, basic_block def_bb)
706 edge_iterator ei;
707 edge e;
708 int_range_max block_result;
709 int_range_max undefined;
710 unsigned poor_list_start = m_poor_value_list.length ();
712 // At this point we shouldn't be looking at the def, entry or exit block.
713 gcc_checking_assert (bb != def_bb && bb != ENTRY_BLOCK_PTR_FOR_FN (cfun) &&
714 bb != EXIT_BLOCK_PTR_FOR_FN (cfun));
716 // If the block cache is set, then we've already visited this block.
717 if (m_on_entry.bb_range_p (name, bb))
718 return;
720 // Visit each block back to the DEF. Initialize each one to UNDEFINED.
721 // m_visited at the end will contain all the blocks that we needed to set
722 // the range_on_entry cache for.
723 m_workback.truncate (0);
724 m_workback.quick_push (bb);
725 undefined.set_undefined ();
726 m_on_entry.set_bb_range (name, bb, undefined);
727 gcc_checking_assert (m_update_list.length () == 0);
729 if (DEBUG_RANGE_CACHE)
731 fprintf (dump_file, "\n");
732 print_generic_expr (dump_file, name, TDF_SLIM);
733 fprintf (dump_file, " : ");
736 while (m_workback.length () > 0)
738 basic_block node = m_workback.pop ();
739 if (DEBUG_RANGE_CACHE)
741 fprintf (dump_file, "BACK visiting block %d for ", node->index);
742 print_generic_expr (dump_file, name, TDF_SLIM);
743 fprintf (dump_file, "\n");
746 FOR_EACH_EDGE (e, ei, node->preds)
748 basic_block pred = e->src;
749 int_range_max r;
751 if (DEBUG_RANGE_CACHE)
752 fprintf (dump_file, " %d->%d ",e->src->index, e->dest->index);
754 // If the pred block is the def block add this BB to update list.
755 if (pred == def_bb)
757 add_to_update (node);
758 continue;
761 // If the pred is entry but NOT def, then it is used before
762 // defined, it'll get set to [] and no need to update it.
763 if (pred == ENTRY_BLOCK_PTR_FOR_FN (cfun))
765 if (DEBUG_RANGE_CACHE)
766 fprintf (dump_file, "entry: bail.");
767 continue;
770 // Regardless of whether we have visited pred or not, if the
771 // pred has a non-null reference, revisit this block.
772 if (m_non_null.non_null_deref_p (name, pred))
774 if (DEBUG_RANGE_CACHE)
775 fprintf (dump_file, "nonnull: update ");
776 add_to_update (node);
779 // If the pred block already has a range, or if it can contribute
780 // something new. Ie, the edge generates a range of some sort.
781 if (m_on_entry.get_bb_range (r, name, pred))
783 if (DEBUG_RANGE_CACHE)
784 fprintf (dump_file, "has cache, ");
785 if (!r.undefined_p () || has_edge_range_p (e, name))
787 add_to_update (node);
788 if (DEBUG_RANGE_CACHE)
789 fprintf (dump_file, "update. ");
791 continue;
794 if (DEBUG_RANGE_CACHE)
795 fprintf (dump_file, "pushing undefined pred block. ");
796 // If the pred hasn't been visited (has no range), add it to
797 // the list.
798 gcc_checking_assert (!m_on_entry.bb_range_p (name, pred));
799 m_on_entry.set_bb_range (name, pred, undefined);
800 m_workback.quick_push (pred);
804 if (DEBUG_RANGE_CACHE)
805 fprintf (dump_file, "\n");
807 // Now fill in the marked blocks with values.
808 iterative_cache_update (name);
809 if (DEBUG_RANGE_CACHE)
810 fprintf (dump_file, " iterative update done.\n");
812 // Now that the cache has been updated, check to see if there were any
813 // SSA_NAMES used in filling the cache which were "poor values".
814 // We can evaluate them, and inject any new values into the iteration
815 // list, and see if it improves any on-entry values.
816 if (poor_list_start != m_poor_value_list.length ())
818 gcc_checking_assert (poor_list_start < m_poor_value_list.length ());
819 while (poor_list_start < m_poor_value_list.length ())
821 // Find a range for this unresolved value.
822 // Note, this may spawn new cache filling cycles, but by the time it
823 // is finished, the work vectors will all be back to the same state
824 // as before the call. The update record vector will always be
825 // returned to the current state upon return.
826 struct update_record rec = m_poor_value_list.pop ();
827 basic_block calc_bb = rec.bb;
828 int_range_max tmp;
830 // The update work list should be empty at this point.
831 gcc_checking_assert (m_update_list.length () == 0);
833 if (DEBUG_RANGE_CACHE)
835 fprintf (dump_file, "(%d:%d)Calculating ",
836 m_poor_value_list.length () + 1, poor_list_start);
837 print_generic_expr (dump_file, name, TDF_SLIM);
838 fprintf (dump_file, " used poor value for ");
839 print_generic_expr (dump_file, rec.calc, TDF_SLIM);
840 fprintf (dump_file, " in bb%d, trying to improve:\n",
841 calc_bb->index);
844 // It must have at least one edge, pick edge 0. we just want to
845 // calculate a range at the exit from the block so the caches feeding
846 // this block will be filled up.
847 gcc_checking_assert (EDGE_SUCC (calc_bb, 0));
848 query.range_on_edge (tmp, EDGE_SUCC (calc_bb, 0), rec.calc);
850 if (DEBUG_RANGE_CACHE)
851 fprintf (dump_file, " Checking successors of bb%d :",
852 calc_bb->index);
854 // Try recalculating any successor blocks with the new value.
855 // Note that even if this value is refined from the initial value,
856 // it may not affect the calculation, but the iterative update
857 // will resolve that efficently.
858 FOR_EACH_EDGE (e, ei, calc_bb->succs)
860 if (DEBUG_RANGE_CACHE)
861 fprintf (dump_file, "bb%d: ", e->dest->index);
862 // Only update active cache entries.
863 if (m_on_entry.bb_range_p (name, e->dest))
865 if (DEBUG_RANGE_CACHE)
866 fprintf (dump_file, "update ");
867 add_to_update (e->dest);
870 if (DEBUG_RANGE_CACHE)
871 fprintf (dump_file, "\n");
872 // Now see if there is a new value.
873 iterative_cache_update (name);