1// Implementation of basic-block-related functions for RTL SSA -*- C++ -*-
2// Copyright (C) 2020-2024 Free Software Foundation, Inc.
3//
4// This file is part of GCC.
5//
6// GCC is free software; you can redistribute it and/or modify it under
7// the terms of the GNU General Public License as published by the Free
8// Software Foundation; either version 3, or (at your option) any later
9// version.
10//
11// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12// 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.
15//
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/>.
19
20#define INCLUDE_ALGORITHM
21#define INCLUDE_FUNCTIONAL
22#include "config.h"
23#include "system.h"
24#include "coretypes.h"
25#include "backend.h"
26#include "rtl.h"
27#include "df.h"
28#include "rtl-ssa.h"
29#include "rtl-ssa/internals.h"
30#include "rtl-ssa/internals.inl"
31#include "cfganal.h"
32#include "cfgrtl.h"
33#include "predict.h"
34#include "domwalk.h"
35
36using namespace rtl_ssa;
37
38// Prepare to build information for a function in which all register numbers
39// are less than NUM_REGS and all basic block indices are less than
40// NUM_BB_INDICES
41function_info::build_info::build_info (unsigned int num_regs,
42 unsigned int num_bb_indices)
43 : current_bb (nullptr),
44 current_ebb (nullptr),
45 last_access (num_regs + 1),
46 ebb_live_in_for_debug (nullptr),
47 potential_phi_regs (num_regs),
48 bb_phis (num_bb_indices),
49 bb_mem_live_out (num_bb_indices),
50 bb_to_rpo (num_bb_indices),
51 exit_block_dominator (nullptr)
52{
53 last_access.safe_grow_cleared (len: num_regs + 1);
54
55 bitmap_clear (potential_phi_regs);
56
57 // These arrays shouldn't need to be initialized, since we'll always
58 // write to an entry before reading from it. But poison the contents
59 // when checking, just to make sure we don't accidentally use an
60 // uninitialized value.
61 bb_phis.quick_grow_cleared (len: num_bb_indices);
62 bb_mem_live_out.quick_grow (len: num_bb_indices);
63 bb_to_rpo.quick_grow (len: num_bb_indices);
64 if (flag_checking)
65 {
66 // Can't do this for bb_phis because it has a constructor.
67 memset (s: bb_mem_live_out.address (), c: 0xaf,
68 n: num_bb_indices * sizeof (bb_mem_live_out[0]));
69 memset (s: bb_to_rpo.address (), c: 0xaf,
70 n: num_bb_indices * sizeof (bb_to_rpo[0]));
71 }
72
73 // Start off with an empty set of phi nodes for each block.
74 for (bb_phi_info &info : bb_phis)
75 bitmap_initialize (head: &info.regs, obstack: &bitmap_default_obstack);
76}
77
78function_info::build_info::~build_info ()
79{
80 for (bb_phi_info &info : bb_phis)
81 bitmap_release (head: &info.regs);
82}
83
84// A dom_walker for populating the basic blocks.
85class function_info::bb_walker : public dom_walker
86{
87public:
88 bb_walker (function_info *, build_info &);
89 edge before_dom_children (basic_block) final override;
90 void after_dom_children (basic_block) final override;
91
92private:
93 // Information about the function we're building.
94 function_info *m_function;
95 build_info &m_bi;
96
97 // We should treat the exit block as being the last child of this one.
98 // See the comment in the constructor for more information.
99 basic_block m_exit_block_dominator;
100};
101
102// Prepare to walk the blocks in FUNCTION using BI.
103function_info::bb_walker::bb_walker (function_info *function, build_info &bi)
104 : dom_walker (CDI_DOMINATORS, ALL_BLOCKS, bi.bb_to_rpo.address ()),
105 m_function (function),
106 m_bi (bi),
107 m_exit_block_dominator (bi.exit_block_dominator)
108{
109 // If the exit block is unreachable, process it last.
110 if (!m_exit_block_dominator)
111 m_exit_block_dominator = ENTRY_BLOCK_PTR_FOR_FN (m_function->m_fn);
112}
113
114edge
115function_info::bb_walker::before_dom_children (basic_block bb)
116{
117 m_function->start_block (m_bi, m_function->bb (cfg_bb: bb));
118 return nullptr;
119}
120
121void
122function_info::bb_walker::after_dom_children (basic_block bb)
123{
124 // See the comment in the constructor for details.
125 if (bb == m_exit_block_dominator)
126 {
127 before_dom_children (EXIT_BLOCK_PTR_FOR_FN (m_function->m_fn));
128 after_dom_children (EXIT_BLOCK_PTR_FOR_FN (m_function->m_fn));
129 }
130 m_function->end_block (m_bi, m_function->bb (cfg_bb: bb));
131}
132
133// See the comment above the declaration.
134void
135bb_info::print_identifier (pretty_printer *pp) const
136{
137 char tmp[3 * sizeof (index ()) + 3];
138 snprintf (s: tmp, maxlen: sizeof (tmp), format: "bb%d", index ());
139 pp_string (pp, tmp);
140 if (ebb_info *ebb = this->ebb ())
141 {
142 pp_space (pp);
143 pp_left_bracket (pp);
144 ebb->print_identifier (pp);
145 pp_right_bracket (pp);
146 }
147}
148
149// See the comment above the declaration.
150void
151bb_info::print_full (pretty_printer *pp) const
152{
153 pp_string (pp, "basic block ");
154 print_identifier (pp);
155 pp_colon (pp);
156
157 auto print_insn = [pp](const char *header, const insn_info *insn)
158 {
159 pp_newline_and_indent (pp, 2);
160 pp_string (pp, header);
161 pp_newline_and_indent (pp, 2);
162 if (insn)
163 pp_insn (pp, insn);
164 else
165 pp_string (pp, "<uninitialized>");
166 pp_indentation (pp) -= 4;
167 };
168
169 print_insn ("head:", head_insn ());
170
171 pp_newline (pp);
172 pp_newline_and_indent (pp, 2);
173 pp_string (pp, "contents:");
174 if (!head_insn ())
175 {
176 pp_newline_and_indent (pp, 2);
177 pp_string (pp, "<uninitialized>");
178 pp_indentation (pp) -= 2;
179 }
180 else if (auto insns = real_insns ())
181 {
182 bool is_first = true;
183 for (const insn_info *insn : insns)
184 {
185 if (is_first)
186 is_first = false;
187 else
188 pp_newline (pp);
189 pp_newline_and_indent (pp, 2);
190 pp_insn (pp, insn);
191 pp_indentation (pp) -= 2;
192 }
193 }
194 else
195 {
196 pp_newline_and_indent (pp, 2);
197 pp_string (pp, "none");
198 pp_indentation (pp) -= 2;
199 }
200 pp_indentation (pp) -= 2;
201
202 pp_newline (pp);
203 print_insn ("end:", end_insn ());
204}
205
206// See the comment above the declaration.
207void
208ebb_call_clobbers_info::print_summary (pretty_printer *pp) const
209{
210 pp_string (pp, "call clobbers for ABI ");
211 if (m_abi)
212 pp_decimal_int (pp, m_abi->id ());
213 else
214 pp_string (pp, "<null>");
215}
216
217// See the comment above the declaration.
218void
219ebb_call_clobbers_info::print_full (pretty_printer *pp) const
220{
221 print_summary (pp);
222 pp_colon (pp);
223 pp_newline_and_indent (pp, 2);
224 auto print_node = [](pretty_printer *pp,
225 const insn_call_clobbers_note *note)
226 {
227 if (insn_info *insn = note->insn ())
228 insn->print_identifier_and_location (pp);
229 else
230 pp_string (pp, "<null>");
231 };
232 print (pp, node: root (), printer: print_node);
233 pp_indentation (pp) -= 2;
234}
235
236// See the comment above the declaration.
237void
238ebb_info::print_identifier (pretty_printer *pp) const
239{
240 // first_bb is populated by the constructor and so should always
241 // be nonnull.
242 auto index = first_bb ()->index ();
243 char tmp[3 * sizeof (index) + 4];
244 snprintf (s: tmp, maxlen: sizeof (tmp), format: "ebb%d", index);
245 pp_string (pp, tmp);
246}
247
248// See the comment above the declaration.
249void
250ebb_info::print_full (pretty_printer *pp) const
251{
252 pp_string (pp, "extended basic block ");
253 print_identifier (pp);
254 pp_colon (pp);
255
256 pp_newline_and_indent (pp, 2);
257 if (insn_info *phi_insn = this->phi_insn ())
258 {
259 phi_insn->print_identifier_and_location (pp);
260 pp_colon (pp);
261 if (auto phis = this->phis ())
262 {
263 bool is_first = true;
264 for (const phi_info *phi : phis)
265 {
266 if (is_first)
267 is_first = false;
268 else
269 pp_newline (pp);
270 pp_newline_and_indent (pp, 2);
271 pp_access (pp, phi, flags: PP_ACCESS_SETTER);
272 pp_indentation (pp) -= 2;
273 }
274 }
275 else
276 {
277 pp_newline_and_indent (pp, 2);
278 pp_string (pp, "no phi nodes");
279 pp_indentation (pp) -= 2;
280 }
281 }
282 else
283 pp_string (pp, "no phi insn");
284 pp_indentation (pp) -= 2;
285
286 for (const bb_info *bb : bbs ())
287 {
288 pp_newline (pp);
289 pp_newline_and_indent (pp, 2);
290 pp_bb (pp, bb);
291 pp_indentation (pp) -= 2;
292 }
293
294 for (ebb_call_clobbers_info *ecc : call_clobbers ())
295 {
296 pp_newline (pp);
297 pp_newline_and_indent (pp, 2);
298 pp_ebb_call_clobbers (pp, ecc);
299 pp_indentation (pp) -= 2;
300 }
301}
302
303// Add a dummy use to mark that DEF is live out of BB's EBB at the end of BB.
304void
305function_info::add_live_out_use (bb_info *bb, set_info *def)
306{
307 // There is nothing to do if DEF is an artificial definition at the end
308 // of BB. In that case the definitino is rooted at the end of the block
309 // and we wouldn't gain anything by inserting a use immediately after it.
310 // If we did want to insert a use, we'd need to associate it with a new
311 // instruction that comes after bb->end_insn ().
312 if (def->insn () == bb->end_insn ())
313 return;
314
315 // If the end of the block already has an artificial use, that use
316 // acts to make DEF live at the appropriate point.
317 use_info *use = def->last_nondebug_insn_use ();
318 if (use && use->insn () == bb->end_insn ())
319 return;
320
321 // Currently there is no need to maintain a backward link from the end
322 // instruction to the list of live-out uses. Such a list would be
323 // expensive to update if it was represented using the usual insn_info
324 // access arrays.
325 use = allocate<use_info> (args: bb->end_insn (), args: def->resource (), args: def);
326 use->set_is_live_out_use (true);
327 add_use (use);
328}
329
330// Return true if all nondebug uses of DEF are live-out uses.
331static bool
332all_uses_are_live_out_uses (set_info *def)
333{
334 for (use_info *use : def->all_uses ())
335 if (!use->is_in_debug_insn () && !use->is_live_out_use ())
336 return false;
337 return true;
338}
339
340// SET, if nonnull, is a definition of something that is live out from BB.
341// Return the live-out value itself.
342set_info *
343function_info::live_out_value (bb_info *bb, set_info *set)
344{
345 // Degenerate phis only exist to provide a definition for uses in the
346 // same EBB. The live-out value is the same as the live-in value.
347 if (auto *phi = safe_dyn_cast<phi_info *> (p: set))
348 if (phi->is_degenerate ())
349 {
350 set = phi->input_value (i: 0);
351
352 // Remove the phi if it turned out to be useless. This is
353 // mainly useful for memory, because we don't know ahead of time
354 // whether a block will use memory or not.
355 if (bb == bb->ebb ()->last_bb () && all_uses_are_live_out_uses (def: phi))
356 replace_phi (phi, set);
357 }
358
359 return set;
360}
361
362// Add PHI to EBB and enter it into the function's hash table.
363void
364function_info::append_phi (ebb_info *ebb, phi_info *phi)
365{
366 phi_info *first_phi = ebb->first_phi ();
367 if (first_phi)
368 first_phi->set_prev_phi (phi);
369 phi->set_next_phi (first_phi);
370 ebb->set_first_phi (phi);
371 add_def (phi);
372}
373
374// Remove PHI from its current position in the SSA graph.
375void
376function_info::remove_phi (phi_info *phi)
377{
378 phi_info *next = phi->next_phi ();
379 phi_info *prev = phi->prev_phi ();
380
381 if (next)
382 next->set_prev_phi (prev);
383
384 if (prev)
385 prev->set_next_phi (next);
386 else
387 phi->ebb ()->set_first_phi (next);
388
389 remove_def (phi);
390 phi->clear_phi_links ();
391}
392
393// Remove PHI from the SSA graph and free its memory.
394void
395function_info::delete_phi (phi_info *phi)
396{
397 gcc_assert (!phi->has_any_uses ());
398
399 // Remove the inputs to the phi.
400 for (use_info *input : phi->inputs ())
401 remove_use (input);
402
403 remove_phi (phi);
404
405 phi->set_next_phi (m_free_phis);
406 m_free_phis = phi;
407}
408
409// If possible, remove PHI and replace all uses with NEW_VALUE.
410void
411function_info::replace_phi (phi_info *phi, set_info *new_value)
412{
413 auto update_use = [&](use_info *use)
414 {
415 remove_use (use);
416 use->set_def (new_value);
417 add_use (use);
418 };
419
420 if (new_value)
421 for (use_info *use : phi->nondebug_insn_uses ())
422 if (!use->is_live_out_use ())
423 {
424 // We need to keep the phi around for its local uses.
425 // Turn it into a degenerate phi, if it isn't already.
426 use_info *use = phi->input_use (i: 0);
427 if (use->def () != new_value)
428 update_use (use);
429
430 if (phi->is_degenerate ())
431 return;
432
433 phi->make_degenerate (input: use);
434
435 // Redirect all phi users to NEW_VALUE.
436 while (use_info *phi_use = phi->last_phi_use ())
437 update_use (phi_use);
438
439 return;
440 }
441
442 // Replace the uses. We can discard uses that only existed for the
443 // sake of marking live-out values, since the resource is now transparent
444 // in the phi's EBB.
445 while (use_info *use = phi->last_use ())
446 if (use->is_live_out_use ())
447 remove_use (use);
448 else
449 update_use (use);
450
451 delete_phi (phi);
452}
453
454// Create and return a phi node for EBB. RESOURCE is the resource that
455// the phi node sets (and thus that all the inputs set too). NUM_INPUTS
456// is the number of inputs, which is 1 for a degenerate phi. INPUTS[I]
457// is a set_info that gives the value of input I, or null if the value
458// is either unknown or uninitialized. If NUM_INPUTS > 1, this array
459// is allocated on the main obstack and can be reused for the use array.
460//
461// Add the created phi node to its basic block and enter it into the
462// function's hash table.
463phi_info *
464function_info::create_phi (ebb_info *ebb, resource_info resource,
465 access_info **inputs, unsigned int num_inputs)
466{
467 phi_info *phi = m_free_phis;
468 if (phi)
469 {
470 m_free_phis = phi->next_phi ();
471 *phi = phi_info (ebb->phi_insn (), resource, phi->uid ());
472 }
473 else
474 {
475 phi = allocate<phi_info> (args: ebb->phi_insn (), args: resource, args: m_next_phi_uid);
476 m_next_phi_uid += 1;
477 }
478
479 // Convert the array of set_infos into an array of use_infos. Also work
480 // out what mode the phi should have.
481 machine_mode new_mode = resource.mode;
482 for (unsigned int i = 0; i < num_inputs; ++i)
483 {
484 auto *input = safe_as_a<set_info *> (p: inputs[i]);
485 auto *use = allocate<use_info> (args: phi, args: resource, args: input);
486 add_use (use);
487 inputs[i] = use;
488 if (input)
489 new_mode = combine_modes (mode1: new_mode, mode2: input->mode ());
490 }
491
492 phi->set_inputs (use_array (inputs, num_inputs));
493 phi->set_mode (new_mode);
494
495 append_phi (ebb, phi);
496
497 return phi;
498}
499
500// Create and return a degenerate phi for EBB whose input comes from DEF.
501// This is used in cases where DEF is known to be available on entry to
502// EBB but was not previously used within it. If DEF is for a register,
503// there are two cases:
504//
505// (1) DEF was already live on entry to EBB but was previously transparent
506// within it.
507//
508// (2) DEF was not previously live on entry to EBB and is being made live
509// by this update.
510//
511// At the moment, this function only handles the case in which EBB has a
512// single predecessor block and DEF is defined in that block's EBB.
513phi_info *
514function_info::create_degenerate_phi (ebb_info *ebb, set_info *def)
515{
516 // Allow the function to be called twice in succession for the same def.
517 def_lookup dl = find_def (resource: def->resource (), insn: ebb->phi_insn ());
518 if (set_info *set = dl.matching_set ())
519 return as_a<phi_info *> (p: set);
520
521 access_info *input = def;
522 phi_info *phi = create_phi (ebb, resource: def->resource (), inputs: &input, num_inputs: 1);
523 if (def->is_reg ())
524 {
525 unsigned int regno = def->regno ();
526
527 // Find the single predecessor mentioned above.
528 basic_block pred_cfg_bb = single_pred (bb: ebb->first_bb ()->cfg_bb ());
529 bb_info *pred_bb = this->bb (cfg_bb: pred_cfg_bb);
530
531 if (!bitmap_set_bit (DF_LR_IN (ebb->first_bb ()->cfg_bb ()), regno))
532 {
533 // The register was not previously live on entry to EBB and
534 // might not have been live on exit from PRED_BB either.
535 if (bitmap_set_bit (DF_LR_OUT (pred_cfg_bb), regno))
536 add_live_out_use (bb: pred_bb, def);
537 }
538 else
539 {
540 // The register was previously live in to EBB. Add live-out uses
541 // at the appropriate points.
542 insn_info *next_insn = nullptr;
543 if (def_info *next_def = phi->next_def ())
544 next_insn = next_def->insn ();
545 for (bb_info *bb : ebb->bbs ())
546 {
547 if ((next_insn && *next_insn <= *bb->end_insn ())
548 || !bitmap_bit_p (DF_LR_OUT (bb->cfg_bb ()), regno))
549 break;
550 add_live_out_use (bb, def);
551 }
552 }
553 }
554 return phi;
555}
556
557// Create a bb_info for CFG_BB, given that no such structure currently exists.
558bb_info *
559function_info::create_bb_info (basic_block cfg_bb)
560{
561 bb_info *bb = allocate<bb_info> (args: cfg_bb);
562 gcc_checking_assert (!m_bbs[cfg_bb->index]);
563 m_bbs[cfg_bb->index] = bb;
564 return bb;
565}
566
567// Add BB to the end of the list of blocks.
568void
569function_info::append_bb (bb_info *bb)
570{
571 if (m_last_bb)
572 m_last_bb->set_next_bb (bb);
573 else
574 m_first_bb = bb;
575 bb->set_prev_bb (m_last_bb);
576 m_last_bb = bb;
577}
578
579// Calculate BI.potential_phi_regs and BI.potential_phi_regs_for_debug.
580void
581function_info::calculate_potential_phi_regs (build_info &bi)
582{
583 auto *lr_info = DF_LR_BB_INFO (ENTRY_BLOCK_PTR_FOR_FN (m_fn));
584 bool is_debug = MAY_HAVE_DEBUG_INSNS;
585 for (unsigned int regno = 0; regno < m_num_regs; ++regno)
586 if (regno >= DF_REG_SIZE (DF)
587 // Exclude registers that have a single definition that dominates
588 // all uses. If the definition does not dominate all uses,
589 // the register will be exposed upwards to the entry block but
590 // will not be defined by the entry block.
591 || DF_REG_DEF_COUNT (regno) > 1
592 || (!bitmap_bit_p (&lr_info->def, regno)
593 && bitmap_bit_p (&lr_info->out, regno)))
594 {
595 bitmap_set_bit (map: bi.potential_phi_regs, bitno: regno);
596 if (is_debug)
597 bitmap_set_bit (bi.potential_phi_regs_for_debug, regno);
598 }
599}
600
601// Called while building SSA form using BI. Decide where phi nodes
602// should be placed for each register and initialize BI.bb_phis accordingly.
603void
604function_info::place_phis (build_info &bi)
605{
606 unsigned int num_bb_indices = last_basic_block_for_fn (m_fn);
607
608 // Calculate dominance frontiers.
609 auto_vec<bitmap_head> frontiers;
610 frontiers.safe_grow_cleared (len: num_bb_indices);
611 for (unsigned int i = 0; i < num_bb_indices; ++i)
612 bitmap_initialize (head: &frontiers[i], obstack: &bitmap_default_obstack);
613 compute_dominance_frontiers (frontiers.address ());
614
615 // The normal dominance information doesn't calculate dominators for
616 // the exit block, so we don't get dominance frontiers for them either.
617 // Calculate them by hand.
618 for (edge e : EXIT_BLOCK_PTR_FOR_FN (m_fn)->preds)
619 {
620 basic_block bb = e->src;
621 while (bb != bi.exit_block_dominator)
622 {
623 bitmap_set_bit (&frontiers[bb->index], EXIT_BLOCK);
624 bb = get_immediate_dominator (CDI_DOMINATORS, bb);
625 }
626 }
627
628 // In extreme cases, the number of live-in registers can be much
629 // greater than the number of phi nodes needed in a block (see PR98863).
630 // Try to reduce the number of operations involving live-in sets by using
631 // PENDING as a staging area: registers in PENDING need phi nodes if
632 // they are live on entry to the corresponding block, but do not need
633 // phi nodes otherwise.
634 auto_vec<bitmap_head> unfiltered;
635 unfiltered.safe_grow_cleared (len: num_bb_indices);
636 for (unsigned int i = 0; i < num_bb_indices; ++i)
637 bitmap_initialize (head: &unfiltered[i], obstack: &bitmap_default_obstack);
638
639 // If block B1 defines R and if B2 is in the dominance frontier of B1,
640 // queue a possible phi node for R in B2.
641 auto_bitmap worklist;
642 for (unsigned int b1 = 0; b1 < num_bb_indices; ++b1)
643 {
644 // Only access DF information for blocks that are known to exist.
645 if (bitmap_empty_p (map: &frontiers[b1]))
646 continue;
647
648 // Defs in B1 that are possibly in LR_IN in the dominance frontier
649 // blocks.
650 auto_bitmap b1_def;
651 bitmap_and (b1_def, &DF_LR_BB_INFO (BASIC_BLOCK_FOR_FN (m_fn, b1))->def,
652 DF_LR_OUT (BASIC_BLOCK_FOR_FN (m_fn, b1)));
653
654 bitmap_iterator bmi;
655 unsigned int b2;
656 EXECUTE_IF_SET_IN_BITMAP (&frontiers[b1], 0, b2, bmi)
657 if (bitmap_ior_into (&unfiltered[b2], b1_def)
658 && !bitmap_empty_p (map: &frontiers[b2]))
659 // Propagate the (potential) new phi node definitions in B2.
660 bitmap_set_bit (worklist, b2);
661 }
662
663 while (!bitmap_empty_p (map: worklist))
664 {
665 unsigned int b1 = bitmap_first_set_bit (worklist);
666 bitmap_clear_bit (worklist, b1);
667
668 // Restrict the phi nodes to registers that are live on entry to
669 // the block.
670 bitmap b1_in = DF_LR_IN (BASIC_BLOCK_FOR_FN (m_fn, b1));
671 bitmap b1_phis = &bi.bb_phis[b1].regs;
672 if (!bitmap_ior_and_into (DST: b1_phis, B: &unfiltered[b1], C: b1_in))
673 continue;
674
675 // If block B1 has a phi node for R and if B2 is in the dominance
676 // frontier of B1, queue a possible phi node for R in B2.
677 bitmap_iterator bmi;
678 unsigned int b2;
679 EXECUTE_IF_SET_IN_BITMAP (&frontiers[b1], 0, b2, bmi)
680 if (bitmap_ior_into (&unfiltered[b2], b1_phis)
681 && !bitmap_empty_p (map: &frontiers[b2]))
682 bitmap_set_bit (worklist, b2);
683 }
684
685 basic_block cfg_bb;
686 FOR_ALL_BB_FN (cfg_bb, m_fn)
687 {
688 // Calculate the set of phi nodes for blocks that don't have any
689 // dominance frontiers. We only need to do this once per block.
690 unsigned int i = cfg_bb->index;
691 bb_phi_info &phis = bi.bb_phis[i];
692 if (bitmap_empty_p (map: &frontiers[i]))
693 bitmap_and (&phis.regs, &unfiltered[i], DF_LR_IN (cfg_bb));
694
695 // Create an array that contains all phi inputs for this block.
696 // See the comment above the member variables for more information.
697 phis.num_phis = bitmap_count_bits (&phis.regs);
698 phis.num_preds = EDGE_COUNT (cfg_bb->preds);
699 unsigned int num_inputs = phis.num_phis * phis.num_preds;
700 if (num_inputs != 0)
701 {
702 phis.inputs = XOBNEWVEC (&m_temp_obstack, set_info *, num_inputs);
703 memset (s: phis.inputs, c: 0, n: num_inputs * sizeof (phis.inputs[0]));
704 }
705 }
706
707 // Free the temporary bitmaps.
708 for (unsigned int i = 0; i < num_bb_indices; ++i)
709 {
710 bitmap_release (head: &frontiers[i]);
711 bitmap_release (head: &unfiltered[i]);
712 }
713}
714
715// Called while building SSA form using BI, with BI.current_bb being
716// the entry block.
717//
718// Create the entry block instructions and their definitions. The only
719// useful instruction is the end instruction, which carries definitions
720// for the values that are live on entry to the function. However, it
721// seems simpler to create a head instruction too, rather than force all
722// users of the block information to treat the entry block as a special case.
723void
724function_info::add_entry_block_defs (build_info &bi)
725{
726 bb_info *bb = bi.current_bb;
727 basic_block cfg_bb = bi.current_bb->cfg_bb ();
728 auto *lr_info = DF_LR_BB_INFO (cfg_bb);
729
730 bb->set_head_insn (append_artificial_insn (bb));
731 insn_info *insn = append_artificial_insn (bb);
732 bb->set_end_insn (insn);
733
734 start_insn_accesses ();
735
736 // Using LR to derive the liveness information means that we create an
737 // entry block definition for upwards exposed registers. These registers
738 // are sometimes genuinely uninitialized. However, some targets also
739 // create a pseudo PIC base register and only initialize it later.
740 // Handling that case correctly seems more important than optimizing
741 // uninitialized uses.
742 unsigned int regno;
743 bitmap_iterator in_bi;
744 EXECUTE_IF_SET_IN_BITMAP (&lr_info->out, 0, regno, in_bi)
745 {
746 auto *set = allocate<set_info> (args: insn, args: full_register (regno));
747 append_def (set);
748 m_temp_defs.safe_push (obj: set);
749 bi.record_reg_def (def: set);
750 }
751
752 // Create a definition that reflects the state of memory on entry to
753 // the function.
754 auto *set = allocate<set_info> (args: insn, args: memory);
755 append_def (set);
756 m_temp_defs.safe_push (obj: set);
757 bi.record_mem_def (def: set);
758
759 finish_insn_accesses (insn);
760}
761
762// Lazily calculate the value of BI.ebb_live_in_for_debug for BI.current_ebb.
763void
764function_info::calculate_ebb_live_in_for_debug (build_info &bi)
765{
766 gcc_checking_assert (bitmap_empty_p (bi.tmp_ebb_live_in_for_debug));
767 bi.ebb_live_in_for_debug = bi.tmp_ebb_live_in_for_debug;
768 bitmap_and (bi.ebb_live_in_for_debug, bi.potential_phi_regs_for_debug,
769 DF_LR_IN (bi.current_ebb->first_bb ()->cfg_bb ()));
770 bitmap_tree_view (bi.ebb_live_in_for_debug);
771}
772
773// Called while building SSA form using BI. Create phi nodes for the
774// current EBB.
775void
776function_info::add_phi_nodes (build_info &bi)
777{
778 ebb_info *ebb = bi.current_ebb;
779 basic_block cfg_bb = ebb->first_bb ()->cfg_bb ();
780
781 // Create the register phis for this EBB.
782 bb_phi_info &phis = bi.bb_phis[cfg_bb->index];
783 unsigned int num_preds = phis.num_preds;
784 unsigned int regno;
785 bitmap_iterator in_bi;
786 EXECUTE_IF_SET_IN_BITMAP (&phis.regs, 0, regno, in_bi)
787 {
788 gcc_checking_assert (bitmap_bit_p (bi.potential_phi_regs, regno));
789
790 // Create an array of phi inputs, to be filled in later.
791 auto *inputs = XOBNEWVEC (&m_obstack, access_info *, num_preds);
792 memset (s: inputs, c: 0, n: sizeof (access_info *) * num_preds);
793
794 // Later code works out the correct mode of the phi. Use BLKmode
795 // as a placeholder for now.
796 phi_info *phi = create_phi (ebb, resource: { .mode: E_BLKmode, .regno: regno },
797 inputs, num_inputs: num_preds);
798 bi.record_reg_def (def: phi);
799 }
800
801 bitmap_copy (bi.ebb_def_regs, &phis.regs);
802
803 // Collect the live-in memory definitions and record whether they're
804 // all the same.
805 m_temp_defs.reserve (nelems: num_preds);
806 set_info *mem_value = nullptr;
807 bool mem_phi_is_degenerate = true;
808 edge e;
809 edge_iterator ei;
810 FOR_EACH_EDGE (e, ei, cfg_bb->preds)
811 {
812 bb_info *pred_bb = this->bb (cfg_bb: e->src);
813 if (pred_bb && pred_bb->head_insn ())
814 {
815 mem_value = bi.bb_mem_live_out[pred_bb->index ()];
816 m_temp_defs.quick_push (obj: mem_value);
817 if (mem_value != m_temp_defs[0])
818 mem_phi_is_degenerate = false;
819 }
820 else
821 {
822 m_temp_defs.quick_push (obj: nullptr);
823 mem_phi_is_degenerate = false;
824 }
825 }
826
827 // Create a phi for memory, on the assumption that something in the
828 // EBB will need it.
829 if (mem_phi_is_degenerate)
830 {
831 access_info *input[] = { mem_value };
832 mem_value = create_phi (ebb, resource: memory, inputs: input, num_inputs: 1);
833 }
834 else
835 {
836 obstack_grow (&m_obstack, m_temp_defs.address (),
837 num_preds * sizeof (access_info *));
838 auto *inputs = static_cast<access_info **> (obstack_finish (&m_obstack));
839 mem_value = create_phi (ebb, resource: memory, inputs, num_inputs: num_preds);
840 }
841 bi.record_mem_def (def: mem_value);
842 m_temp_defs.truncate (size: 0);
843}
844
845// Called while building SSA form using BI.
846//
847// If FLAGS is DF_REF_AT_TOP, create the head insn for BI.current_bb
848// and populate its uses and definitions. If FLAGS is 0, do the same
849// for the end insn.
850void
851function_info::add_artificial_accesses (build_info &bi, df_ref_flags flags)
852{
853 bb_info *bb = bi.current_bb;
854 basic_block cfg_bb = bb->cfg_bb ();
855 auto *lr_info = DF_LR_BB_INFO (cfg_bb);
856 df_ref ref;
857
858 insn_info *insn;
859 if (flags == DF_REF_AT_TOP)
860 {
861 if (cfg_bb->index == EXIT_BLOCK)
862 insn = append_artificial_insn (bb);
863 else
864 insn = append_artificial_insn (bb, bb_note (cfg_bb));
865 bb->set_head_insn (insn);
866 }
867 else
868 {
869 insn = append_artificial_insn (bb);
870 bb->set_end_insn (insn);
871 }
872
873 start_insn_accesses ();
874
875 HARD_REG_SET added_regs = {};
876 FOR_EACH_ARTIFICIAL_USE (ref, cfg_bb->index)
877 if ((DF_REF_FLAGS (ref) & DF_REF_AT_TOP) == flags)
878 {
879 unsigned int regno = DF_REF_REGNO (ref);
880 machine_mode mode = GET_MODE (DF_REF_REAL_REG (ref));
881 if (HARD_REGISTER_NUM_P (regno))
882 SET_HARD_REG_BIT (set&: added_regs, bit: regno);
883
884 // A definition must be available.
885 gcc_checking_assert (bitmap_bit_p (&lr_info->in, regno)
886 || (flags != DF_REF_AT_TOP
887 && bitmap_bit_p (&lr_info->def, regno)));
888 m_temp_uses.safe_push (obj: create_reg_use (bi, insn, { .mode: mode, .regno: regno }));
889 }
890
891 // Ensure that global registers and memory are live at the end of any
892 // block that has no successors, such as the exit block and non-local gotos.
893 // Global registers have to be singled out because they are not part of
894 // the DF artifical use list (they are instead treated as used within
895 // every block).
896 if (flags == 0 && EDGE_COUNT (cfg_bb->succs) == 0)
897 {
898 for (unsigned int i = 0; i < FIRST_PSEUDO_REGISTER; ++i)
899 if (global_regs[i] && !TEST_HARD_REG_BIT (set: added_regs, bit: i))
900 {
901 auto mode = reg_raw_mode[i];
902 m_temp_uses.safe_push (obj: create_reg_use (bi, insn, { .mode: mode, .regno: i }));
903 }
904
905 auto *use = allocate<use_info> (args: insn, args: memory, args: bi.current_mem_value ());
906 add_use (use);
907 m_temp_uses.safe_push (obj: use);
908 }
909
910 FOR_EACH_ARTIFICIAL_DEF (ref, cfg_bb->index)
911 if ((DF_REF_FLAGS (ref) & DF_REF_AT_TOP) == flags)
912 {
913 unsigned int regno = DF_REF_REGNO (ref);
914 machine_mode mode = GET_MODE (DF_REF_REAL_REG (ref));
915 resource_info resource { .mode: mode, .regno: regno };
916
917 // We rely on the def set being correct.
918 gcc_checking_assert (bitmap_bit_p (&lr_info->def, regno));
919
920 // If the value isn't used later in the block and isn't live
921 // on exit, we could instead represent the definition as a
922 // clobber_info. However, that case should be relatively
923 // rare and set_info is any case more compact than clobber_info.
924 set_info *def = allocate<set_info> (args: insn, args: resource);
925 append_def (def);
926 m_temp_defs.safe_push (obj: def);
927 bi.record_reg_def (def);
928 }
929
930 // Model the effect of a memory clobber on an incoming edge by adding
931 // a fake definition of memory at the start of the block. We don't need
932 // to add a use of the phi node because memory is implicitly always live.
933 if (flags == DF_REF_AT_TOP && has_abnormal_call_or_eh_pred_edge_p (bb: cfg_bb))
934 {
935 set_info *def = allocate<set_info> (args: insn, args: memory);
936 append_def (def);
937 m_temp_defs.safe_push (obj: def);
938 bi.record_mem_def (def);
939 }
940
941 finish_insn_accesses (insn);
942}
943
944// Called while building SSA form using BI. Create insn_infos for all
945// relevant instructions in BI.current_bb.
946void
947function_info::add_block_contents (build_info &bi)
948{
949 basic_block cfg_bb = bi.current_bb->cfg_bb ();
950 rtx_insn *insn;
951 FOR_BB_INSNS (cfg_bb, insn)
952 if (INSN_P (insn))
953 add_insn_to_block (bi, insn);
954}
955
956// Called while building SSA form using BI. Record live-out register values
957// in the phi inputs of successor blocks and create live-out uses where
958// appropriate. Record the live-out memory value in BI.bb_mem_live_out.
959void
960function_info::record_block_live_out (build_info &bi)
961{
962 bb_info *bb = bi.current_bb;
963 ebb_info *ebb = bi.current_ebb;
964 basic_block cfg_bb = bb->cfg_bb ();
965
966 // Record the live-out register values in the phi inputs of
967 // successor blocks.
968 edge e;
969 edge_iterator ei;
970 FOR_EACH_EDGE (e, ei, cfg_bb->succs)
971 {
972 bb_phi_info &phis = bi.bb_phis[e->dest->index];
973 unsigned int input_i = e->dest_idx * phis.num_phis;
974 unsigned int regno;
975 bitmap_iterator out_bi;
976 EXECUTE_IF_SET_IN_BITMAP (&phis.regs, 0, regno, out_bi)
977 {
978 phis.inputs[input_i]
979 = live_out_value (bb, set: bi.current_reg_value (regno));
980 input_i += 1;
981 }
982 }
983
984 // Add the set of registers that were defined in this BB to the set
985 // of potentially-live registers defined in the EBB.
986 bitmap_ior_into (bi.ebb_def_regs, &DF_LR_BB_INFO (cfg_bb)->def);
987
988 // Iterate through the registers in LIVE_OUT and see whether we need
989 // to add a live-out use for them.
990 auto record_live_out_regs = [&](bitmap live_out)
991 {
992 unsigned int regno;
993 bitmap_iterator out_bi;
994 EXECUTE_IF_AND_IN_BITMAP (bi.ebb_def_regs, live_out, 0, regno, out_bi)
995 {
996 set_info *value = live_out_value (bb, set: bi.current_reg_value (regno));
997 if (value && value->ebb () == ebb)
998 add_live_out_use (bb, def: value);
999 }
1000 };
1001
1002 if (bb == ebb->last_bb ())
1003 // All live-out registers might need live-out uses.
1004 record_live_out_regs (DF_LR_OUT (cfg_bb));
1005 else
1006 // Registers might need live-out uses if they are live on entry
1007 // to a successor block in a different EBB.
1008 FOR_EACH_EDGE (e, ei, cfg_bb->succs)
1009 {
1010 bb_info *dest_bb = this->bb (cfg_bb: e->dest);
1011 if (dest_bb->ebb () != ebb || dest_bb == ebb->first_bb ())
1012 record_live_out_regs (DF_LR_IN (e->dest));
1013 }
1014
1015 // Record the live-out memory value.
1016 bi.bb_mem_live_out[cfg_bb->index]
1017 = live_out_value (bb, set: bi.current_mem_value ());
1018}
1019
1020// Add BB and its contents to the SSA information.
1021void
1022function_info::start_block (build_info &bi, bb_info *bb)
1023{
1024 ebb_info *ebb = bb->ebb ();
1025
1026 // We (need to) add all blocks from one EBB before moving on to the next.
1027 bi.current_bb = bb;
1028 if (bb == ebb->first_bb ())
1029 bi.current_ebb = ebb;
1030 else
1031 gcc_assert (bi.current_ebb == ebb);
1032
1033 // Record the start of this block's definitions in the definitions stack.
1034 bi.old_def_stack_limit.safe_push (obj: bi.def_stack.length ());
1035
1036 // Add the block itself.
1037 append_bb (bb);
1038
1039 // If the block starts an EBB, create the phi insn. This insn should exist
1040 // for all EBBs, even if they don't (yet) need phis.
1041 if (bb == ebb->first_bb ())
1042 ebb->set_phi_insn (append_artificial_insn (bb));
1043
1044 if (bb->index () == ENTRY_BLOCK)
1045 {
1046 add_entry_block_defs (bi);
1047 record_block_live_out (bi);
1048 return;
1049 }
1050
1051 if (EDGE_COUNT (bb->cfg_bb ()->preds) == 0)
1052 {
1053 // Leave unreachable blocks empty, since there is no useful
1054 // liveness information for them, and anything they do will
1055 // be wasted work. In a cleaned-up cfg, the only unreachable
1056 // block we should see is the exit block of a noreturn function.
1057 bb->set_head_insn (append_artificial_insn (bb));
1058 bb->set_end_insn (append_artificial_insn (bb));
1059 return;
1060 }
1061
1062 // If the block starts an EBB, create the phi nodes.
1063 if (bb == ebb->first_bb ())
1064 add_phi_nodes (bi);
1065
1066 // Process the contents of the block.
1067 add_artificial_accesses (bi, flags: DF_REF_AT_TOP);
1068 if (bb->index () != EXIT_BLOCK)
1069 add_block_contents (bi);
1070 add_artificial_accesses (bi, flags: df_ref_flags ());
1071 record_block_live_out (bi);
1072
1073 // If we needed to calculate a live-in set for debug purposes,
1074 // reset it to null at the end of the EBB. Convert the underlying
1075 // bitmap to an empty list view, ready for the next calculation.
1076 if (bi.ebb_live_in_for_debug && bb == ebb->last_bb ())
1077 {
1078 bitmap_clear (bi.tmp_ebb_live_in_for_debug);
1079 bitmap_list_view (bi.tmp_ebb_live_in_for_debug);
1080 bi.ebb_live_in_for_debug = nullptr;
1081 }
1082}
1083
1084// Finish adding BB and the blocks that it dominates to the SSA information.
1085void
1086function_info::end_block (build_info &bi, bb_info *bb)
1087{
1088 // Restore the register last_access information to the state it was
1089 // in before we started processing BB.
1090 unsigned int old_limit = bi.old_def_stack_limit.pop ();
1091 while (bi.def_stack.length () > old_limit)
1092 {
1093 // We pushed a definition in BB if it was the first dominating
1094 // definition (and so the previous entry was null). In other
1095 // cases we pushed the previous dominating definition.
1096 def_info *def = bi.def_stack.pop ();
1097 unsigned int regno = def->regno ();
1098 if (def->bb () == bb)
1099 def = nullptr;
1100 bi.last_access[regno + 1] = def;
1101 }
1102}
1103
1104// Finish setting up the phi nodes for each block, now that we've added
1105// the contents of all blocks.
1106void
1107function_info::populate_phi_inputs (build_info &bi)
1108{
1109 auto_vec<phi_info *, 32> sorted_phis;
1110 for (ebb_info *ebb : ebbs ())
1111 {
1112 if (!ebb->first_phi ())
1113 continue;
1114
1115 // Get a sorted array of EBB's phi nodes.
1116 basic_block cfg_bb = ebb->first_bb ()->cfg_bb ();
1117 bb_phi_info &phis = bi.bb_phis[cfg_bb->index];
1118 sorted_phis.truncate (size: 0);
1119 for (phi_info *phi : ebb->phis ())
1120 sorted_phis.safe_push (obj: phi);
1121 std::sort (first: sorted_phis.address (),
1122 last: sorted_phis.address () + sorted_phis.length (),
1123 comp: compare_access_infos);
1124
1125 // Set the inputs of the non-degenerate register phis. All inputs
1126 // for one edge come before all inputs for the next edge.
1127 set_info **inputs = phis.inputs;
1128 unsigned int phi_i = 0;
1129 bitmap_iterator bmi;
1130 unsigned int regno;
1131 EXECUTE_IF_SET_IN_BITMAP (&phis.regs, 0, regno, bmi)
1132 {
1133 // Skip intervening degenerate phis.
1134 while (sorted_phis[phi_i]->regno () < regno)
1135 phi_i += 1;
1136 phi_info *phi = sorted_phis[phi_i];
1137 gcc_assert (phi->regno () == regno);
1138 for (unsigned int input_i = 0; input_i < phis.num_preds; ++input_i)
1139 if (set_info *input = inputs[input_i * phis.num_phis])
1140 {
1141 use_info *use = phi->input_use (i: input_i);
1142 gcc_assert (!use->def ());
1143 use->set_def (input);
1144 add_use (use);
1145 }
1146 phi_i += 1;
1147 inputs += 1;
1148 }
1149
1150 // Fill in the backedge inputs to any memory phi.
1151 phi_info *mem_phi = sorted_phis.last ();
1152 if (mem_phi->is_mem () && !mem_phi->is_degenerate ())
1153 {
1154 edge e;
1155 edge_iterator ei;
1156 FOR_EACH_EDGE (e, ei, cfg_bb->preds)
1157 {
1158 use_info *use = mem_phi->input_use (i: e->dest_idx);
1159 if (!use->def ())
1160 {
1161 use->set_def (bi.bb_mem_live_out[e->src->index]);
1162 add_use (use);
1163 }
1164 }
1165 }
1166 }
1167}
1168
1169// Return true if it would be better to continue an EBB across NEW_EDGE
1170// rather than across OLD_EDGE, given that both edges are viable candidates.
1171// This is not a total ordering.
1172static bool
1173better_ebb_edge_p (edge new_edge, edge old_edge)
1174{
1175 // Prefer the likeliest edge.
1176 if (new_edge->probability.initialized_p ()
1177 && old_edge->probability.initialized_p ()
1178 && !(old_edge->probability == new_edge->probability))
1179 return old_edge->probability < new_edge->probability;
1180
1181 // If both edges are equally likely, prefer a fallthru edge.
1182 if (new_edge->flags & EDGE_FALLTHRU)
1183 return true;
1184 if (old_edge->flags & EDGE_FALLTHRU)
1185 return false;
1186
1187 // Otherwise just stick with OLD_EDGE.
1188 return false;
1189}
1190
1191// Pick and return the next basic block in an EBB that currently ends with BB.
1192// Return null if the EBB must end with BB.
1193static basic_block
1194choose_next_block_in_ebb (basic_block bb)
1195{
1196 // Although there's nothing in principle wrong with having an EBB that
1197 // starts with the entry block and includes later blocks, there's not
1198 // really much point either. Keeping the entry block separate means
1199 // that uses of arguments consistently occur through phi nodes, rather
1200 // than the arguments sometimes appearing to come from an EBB-local
1201 // definition instead.
1202 if (bb->index == ENTRY_BLOCK)
1203 return nullptr;
1204
1205 bool optimize_for_speed_p = optimize_bb_for_speed_p (bb);
1206 edge best_edge = nullptr;
1207 edge e;
1208 edge_iterator ei;
1209 FOR_EACH_EDGE (e, ei, bb->succs)
1210 if (!(e->flags & EDGE_COMPLEX)
1211 && e->dest->index != EXIT_BLOCK
1212 && single_pred_p (bb: e->dest)
1213 && optimize_for_speed_p == optimize_bb_for_speed_p (e->dest)
1214 && (!best_edge || better_ebb_edge_p (new_edge: e, old_edge: best_edge)))
1215 best_edge = e;
1216
1217 return best_edge ? best_edge->dest : nullptr;
1218}
1219
1220// Partition the function into extended basic blocks. Create the
1221// associated ebb_infos and bb_infos, but don't add the bb_infos
1222// to the function list yet.
1223void
1224function_info::create_ebbs (build_info &bi)
1225{
1226 // Compute the starting reverse postorder. We tweak this later to try
1227 // to get better EBB assignments.
1228 auto *postorder = new int[n_basic_blocks_for_fn (m_fn)];
1229 unsigned int postorder_num
1230 = pre_and_rev_post_order_compute (nullptr, postorder, true);
1231 gcc_assert (int (postorder_num) <= n_basic_blocks_for_fn (m_fn));
1232
1233 // Iterate over the blocks in reverse postorder. In cases where
1234 // multiple possible orders exist, prefer orders that chain blocks
1235 // together into EBBs. If multiple possible EBBs exist, try to pick
1236 // the ones that are most likely to be profitable.
1237 auto_vec<bb_info *, 16> bbs;
1238 unsigned int next_bb_index = 0;
1239 for (unsigned int i = 0; i < postorder_num; ++i)
1240 if (!m_bbs[postorder[i]])
1241 {
1242 // Choose and create the blocks that should form the next EBB.
1243 basic_block cfg_bb = BASIC_BLOCK_FOR_FN (m_fn, postorder[i]);
1244 do
1245 {
1246 // Record the chosen block order in a new RPO.
1247 bi.bb_to_rpo[cfg_bb->index] = next_bb_index++;
1248 bbs.safe_push (obj: create_bb_info (cfg_bb));
1249 cfg_bb = choose_next_block_in_ebb (bb: cfg_bb);
1250 }
1251 while (cfg_bb);
1252
1253 // Create the EBB itself.
1254 auto *ebb = allocate<ebb_info> (args: bbs[0], args: bbs.last ());
1255 for (bb_info *bb : bbs)
1256 bb->set_ebb (ebb);
1257 bbs.truncate (size: 0);
1258 }
1259
1260 delete[] postorder;
1261}
1262
1263// Partition the function's blocks into EBBs and build SSA form for all
1264// EBBs in the function.
1265void
1266function_info::process_all_blocks ()
1267{
1268 auto temps = temp_watermark ();
1269 unsigned int num_bb_indices = last_basic_block_for_fn (m_fn);
1270
1271 build_info bi (m_num_regs, num_bb_indices);
1272
1273 // ??? There is no dominance information associated with the exit block,
1274 // so work out its immediate dominator using predecessor blocks.
1275 for (edge e : EXIT_BLOCK_PTR_FOR_FN (m_fn)->preds)
1276 if (bi.exit_block_dominator)
1277 bi.exit_block_dominator
1278 = nearest_common_dominator (CDI_DOMINATORS,
1279 bi.exit_block_dominator, e->src);
1280 else
1281 bi.exit_block_dominator = e->src;
1282
1283 calculate_potential_phi_regs (bi);
1284 create_ebbs (bi);
1285 place_phis (bi);
1286 bb_walker (this, bi).walk (ENTRY_BLOCK_PTR_FOR_FN (m_fn));
1287 populate_phi_inputs (bi);
1288
1289 if (flag_checking)
1290 {
1291 // The definition stack should be empty and all register definitions
1292 // should be back in their original undefined state.
1293 gcc_assert (bi.def_stack.is_empty ()
1294 && bi.old_def_stack_limit.is_empty ());
1295 for (unsigned int regno = 0; regno < m_num_regs; ++regno)
1296 gcc_assert (!bi.last_access[regno + 1]);
1297 }
1298}
1299
1300// Print a description of CALL_CLOBBERS to PP.
1301void
1302rtl_ssa::pp_ebb_call_clobbers (pretty_printer *pp,
1303 const ebb_call_clobbers_info *call_clobbers)
1304{
1305 if (!call_clobbers)
1306 pp_string (pp, "<null>");
1307 else
1308 call_clobbers->print_full (pp);
1309}
1310
1311// Print a description of BB to PP.
1312void
1313rtl_ssa::pp_bb (pretty_printer *pp, const bb_info *bb)
1314{
1315 if (!bb)
1316 pp_string (pp, "<null>");
1317 else
1318 bb->print_full (pp);
1319}
1320
1321// Print a description of EBB to PP
1322void
1323rtl_ssa::pp_ebb (pretty_printer *pp, const ebb_info *ebb)
1324{
1325 if (!ebb)
1326 pp_string (pp, "<null>");
1327 else
1328 ebb->print_full (pp);
1329}
1330
1331// Print a description of CALL_CLOBBERS to FILE.
1332void
1333dump (FILE *file, const ebb_call_clobbers_info *call_clobbers)
1334{
1335 dump_using (file, printer: pp_ebb_call_clobbers, args: call_clobbers);
1336}
1337
1338// Print a description of BB to FILE.
1339void
1340dump (FILE *file, const bb_info *bb)
1341{
1342 dump_using (file, printer: pp_bb, args: bb);
1343}
1344
1345// Print a description of EBB to FILE.
1346void
1347dump (FILE *file, const ebb_info *ebb)
1348{
1349 dump_using (file, printer: pp_ebb, args: ebb);
1350}
1351
1352// Debug interfaces to the dump routines above.
1353void debug (const ebb_call_clobbers_info *x) { dump (stderr, call_clobbers: x); }
1354void debug (const bb_info *x) { dump (stderr, bb: x); }
1355void debug (const ebb_info *x) { dump (stderr, ebb: x); }
1356

source code of gcc/rtl-ssa/blocks.cc