Branch data Line data Source code
1 : : // RTL SSA routines for changing instructions -*- C++ -*-
2 : : // Copyright (C) 2020-2025 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 : : #define INCLUDE_ARRAY
23 : : #include "config.h"
24 : : #include "system.h"
25 : : #include "coretypes.h"
26 : : #include "backend.h"
27 : : #include "rtl.h"
28 : : #include "df.h"
29 : : #include "rtl-ssa.h"
30 : : #include "rtl-ssa/internals.h"
31 : : #include "rtl-ssa/internals.inl"
32 : : #include "target.h"
33 : : #include "predict.h"
34 : : #include "memmodel.h" // Needed by emit-rtl.h
35 : : #include "emit-rtl.h"
36 : : #include "cfghooks.h"
37 : : #include "cfgrtl.h"
38 : : #include "sreal.h"
39 : :
40 : : using namespace rtl_ssa;
41 : :
42 : : // See the comment above the declaration.
43 : : void
44 : 0 : insn_change::print (pretty_printer *pp) const
45 : : {
46 : 0 : if (m_is_deletion)
47 : : {
48 : 0 : pp_string (pp, "deletion of ");
49 : 0 : pp_insn (pp, m_insn);
50 : : }
51 : : else
52 : : {
53 : 0 : pp_string (pp, "change to ");
54 : 0 : pp_insn (pp, m_insn);
55 : 0 : pp_newline_and_indent (pp, 2);
56 : 0 : pp_string (pp, "~~~~~~~");
57 : :
58 : 0 : pp_newline_and_indent (pp, 0);
59 : 0 : pp_string (pp, "new cost: ");
60 : 0 : pp_decimal_int (pp, new_cost);
61 : :
62 : 0 : pp_newline_and_indent (pp, 0);
63 : 0 : pp_string (pp, "new uses:");
64 : 0 : pp_newline_and_indent (pp, 2);
65 : 0 : pp_accesses (pp, new_uses);
66 : 0 : pp_indentation (pp) -= 2;
67 : :
68 : 0 : pp_newline_and_indent (pp, 0);
69 : 0 : pp_string (pp, "new defs:");
70 : 0 : pp_newline_and_indent (pp, 2);
71 : 0 : pp_accesses (pp, new_defs);
72 : 0 : pp_indentation (pp) -= 2;
73 : :
74 : 0 : pp_newline_and_indent (pp, 0);
75 : 0 : pp_string (pp, "first insert-after candidate: ");
76 : 0 : move_range.first->print_identifier_and_location (pp);
77 : :
78 : 0 : pp_newline_and_indent (pp, 0);
79 : 0 : pp_string (pp, "last insert-after candidate: ");
80 : 0 : move_range.last->print_identifier_and_location (pp);
81 : : }
82 : 0 : }
83 : :
84 : : // Return a copy of access_array ACCESSES, allocating it on the
85 : : // temporary obstack.
86 : : access_array
87 : 20061522 : function_info::temp_access_array (access_array accesses)
88 : : {
89 : 20061522 : if (accesses.empty ())
90 : 1873380 : return accesses;
91 : :
92 : 18188142 : gcc_assert (obstack_object_size (&m_temp_obstack) == 0);
93 : 18188142 : obstack_grow (&m_temp_obstack, accesses.begin (), accesses.size_bytes ());
94 : 18188142 : return { static_cast<access_info **> (obstack_finish (&m_temp_obstack)),
95 : 18188142 : accesses.size () };
96 : : }
97 : :
98 : : // See the comment above the declaration.
99 : : bool
100 : 2280833 : function_info::verify_insn_changes (array_slice<insn_change *const> changes)
101 : : {
102 : 2280833 : HARD_REG_SET defined_hard_regs, clobbered_hard_regs;
103 : 9123332 : CLEAR_HARD_REG_SET (defined_hard_regs);
104 : 2280833 : CLEAR_HARD_REG_SET (clobbered_hard_regs);
105 : :
106 : 2280833 : insn_info *min_insn = m_first_insn;
107 : 10354322 : for (insn_change *change : changes)
108 : 8078980 : if (!change->is_deletion ())
109 : : {
110 : : // Make sure that the changes can be kept in their current order
111 : : // while honoring all of the move ranges.
112 : 5798147 : min_insn = later_insn (min_insn, change->move_range.first);
113 : 5798161 : while (min_insn != change->insn () && !can_insert_after (min_insn))
114 : 14 : min_insn = min_insn->next_nondebug_insn ();
115 : 5798147 : if (*min_insn > *change->move_range.last)
116 : : {
117 : 5469 : if (dump_file && (dump_flags & TDF_DETAILS))
118 : 0 : fprintf (dump_file, "no viable insn position assignment\n");
119 : 5469 : return false;
120 : : }
121 : :
122 : : // If recog introduced new clobbers of a register as part of
123 : : // the matching process, make sure that they don't conflict
124 : : // with any other new definitions or uses of the register.
125 : : // (We have already checked that they don't conflict with
126 : : // unchanging definitions and uses.)
127 : 15883433 : for (use_info *use : change->new_uses)
128 : : {
129 : 10090755 : unsigned int regno = use->regno ();
130 : 10090755 : if (HARD_REGISTER_NUM_P (regno)
131 : 10090755 : && TEST_HARD_REG_BIT (clobbered_hard_regs, regno))
132 : : {
133 : 0 : if (dump_file && (dump_flags & TDF_DETAILS))
134 : 0 : fprintf (dump_file, "register %d would be clobbered"
135 : : " while it is still live\n", regno);
136 : 0 : return false;
137 : : }
138 : : }
139 : 12344384 : for (def_info *def : change->new_defs)
140 : : {
141 : 6551728 : unsigned int regno = def->regno ();
142 : 6551728 : if (HARD_REGISTER_NUM_P (regno))
143 : : {
144 : 3164455 : if (def->m_is_temp)
145 : : {
146 : : // This is a clobber introduced by recog.
147 : 34805 : gcc_checking_assert (is_a<clobber_info *> (def));
148 : 34805 : if (TEST_HARD_REG_BIT (defined_hard_regs, regno))
149 : : {
150 : 22 : if (dump_file && (dump_flags & TDF_DETAILS))
151 : 0 : fprintf (dump_file, "conflicting definitions of"
152 : : " register %d\n", regno);
153 : 22 : return false;
154 : : }
155 : 34783 : SET_HARD_REG_BIT (clobbered_hard_regs, regno);
156 : : }
157 : 9681356 : else if (is_a<set_info *> (def))
158 : : {
159 : : // REGNO now has a defined value.
160 : 2601587 : SET_HARD_REG_BIT (defined_hard_regs, regno);
161 : 2601587 : CLEAR_HARD_REG_BIT (clobbered_hard_regs, regno);
162 : : }
163 : : }
164 : : }
165 : : }
166 : : return true;
167 : : }
168 : :
169 : : // See the comment above the declaration.
170 : : bool
171 : 8219666 : rtl_ssa::changes_are_worthwhile (array_slice<insn_change *const> changes,
172 : : bool strict_p)
173 : : {
174 : 8219666 : unsigned int old_cost = 0;
175 : 8219666 : sreal weighted_old_cost = 0;
176 : 8219666 : auto entry_count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
177 : 8219666 : {
178 : 8219666 : undo_recog_changes undo (0);
179 : 22683635 : for (insn_change *change : changes)
180 : : {
181 : : // Count zero for the old cost if the old instruction was a no-op
182 : : // move or had an unknown cost. This should reduce the chances of
183 : : // making an unprofitable change.
184 : 14463969 : old_cost += change->old_cost ();
185 : 14463969 : basic_block cfg_bb = change->bb ()->cfg_bb ();
186 : 14463969 : if (optimize_bb_for_speed_p (cfg_bb))
187 : 12845942 : weighted_old_cost += (cfg_bb->count.to_sreal_scale (entry_count)
188 : 12845942 : * change->old_cost ());
189 : :
190 : : }
191 : 8219666 : }
192 : 8219666 : unsigned int new_cost = 0;
193 : 8219666 : sreal weighted_new_cost = 0;
194 : 22588521 : for (insn_change *change : changes)
195 : : {
196 : 14397242 : basic_block cfg_bb = change->bb ()->cfg_bb ();
197 : 14397242 : bool for_speed = optimize_bb_for_speed_p (cfg_bb);
198 : 14397242 : if (!change->is_deletion ()
199 : 14397242 : && INSN_CODE (change->rtl ()) != NOOP_MOVE_INSN_CODE)
200 : : {
201 : 11947972 : change->new_cost = insn_cost (change->rtl (), for_speed);
202 : : /* If the cost is unknown, replacement is not worthwhile. */
203 : 11947972 : if (!change->new_cost)
204 : : {
205 : 28387 : if (dump_file && (dump_flags & TDF_DETAILS))
206 : 0 : fprintf (dump_file,
207 : : "Reject replacement due to unknown insn cost.\n");
208 : 28387 : return false;
209 : : }
210 : 11919585 : new_cost += change->new_cost;
211 : 11919585 : if (for_speed)
212 : 31744929 : weighted_new_cost += (cfg_bb->count.to_sreal_scale (entry_count)
213 : 10581643 : * change->new_cost);
214 : : }
215 : : }
216 : 8191279 : bool ok_p;
217 : 8191279 : if (weighted_new_cost != weighted_old_cost)
218 : 3311483 : ok_p = weighted_new_cost < weighted_old_cost;
219 : 4879796 : else if (strict_p)
220 : 3306733 : ok_p = new_cost < old_cost;
221 : : else
222 : 1573063 : ok_p = new_cost <= old_cost;
223 : 8191279 : if (dump_file && (dump_flags & TDF_DETAILS))
224 : : {
225 : 0 : fprintf (dump_file, "original cost");
226 : 0 : char sep = '=';
227 : 0 : for (const insn_change *change : changes)
228 : : {
229 : 0 : fprintf (dump_file, " %c %d", sep, change->old_cost ());
230 : 0 : sep = '+';
231 : : }
232 : 0 : if (weighted_old_cost != 0)
233 : 0 : fprintf (dump_file, " (weighted: %f)", weighted_old_cost.to_double ());
234 : 0 : fprintf (dump_file, ", replacement cost");
235 : 0 : sep = '=';
236 : 0 : for (const insn_change *change : changes)
237 : 0 : if (!change->is_deletion ())
238 : : {
239 : 0 : if (INSN_CODE (change->rtl ()) == NOOP_MOVE_INSN_CODE)
240 : 0 : fprintf (dump_file, " %c nop", sep);
241 : : else
242 : 0 : fprintf (dump_file, " %c %d", sep, change->new_cost);
243 : : sep = '+';
244 : : }
245 : 0 : if (weighted_new_cost != 0)
246 : 0 : fprintf (dump_file, " (weighted: %f)", weighted_new_cost.to_double ());
247 : 0 : fprintf (dump_file, "; %s\n",
248 : : ok_p ? "keeping replacement" : "rejecting replacement");
249 : : }
250 : 8191279 : if (!ok_p)
251 : : return false;
252 : :
253 : : return true;
254 : : }
255 : :
256 : : // SET has been deleted. Clean up all remaining uses. Such uses are
257 : : // either dead phis or now-redundant live-out uses.
258 : : void
259 : 757367 : function_info::process_uses_of_deleted_def (set_info *set)
260 : : {
261 : 757367 : if (!set->has_any_uses ())
262 : : return;
263 : :
264 : : auto *use = *set->all_uses ().begin ();
265 : 1388558 : do
266 : : {
267 : 1388558 : auto *next_use = use->next_use ();
268 : 1388558 : if (use->is_in_phi ())
269 : : {
270 : : // This call will not recurse.
271 : 29734 : process_uses_of_deleted_def (use->phi ());
272 : 29734 : delete_phi (use->phi ());
273 : : }
274 : : else
275 : : {
276 : 1358824 : gcc_assert (use->is_live_out_use ());
277 : 1358824 : remove_use (use);
278 : : }
279 : 1388558 : use = next_use;
280 : : }
281 : 1388558 : while (use);
282 : 727633 : gcc_assert (!set->has_any_uses ());
283 : : }
284 : :
285 : : // Update the REG_NOTES of INSN, whose pattern has just been changed.
286 : : static void
287 : 10030761 : update_notes (rtx_insn *insn)
288 : : {
289 : 16362235 : for (rtx *note_ptr = ®_NOTES (insn); *note_ptr; )
290 : : {
291 : 6331474 : rtx note = *note_ptr;
292 : 6331474 : bool keep_p = true;
293 : 6331474 : switch (REG_NOTE_KIND (note))
294 : : {
295 : 227800 : case REG_EQUAL:
296 : 227800 : case REG_EQUIV:
297 : 227800 : case REG_NOALIAS:
298 : 227800 : keep_p = (single_set (insn) != nullptr);
299 : 227800 : break;
300 : :
301 : : case REG_UNUSED:
302 : : case REG_DEAD:
303 : : // These notes are stale. We'll recompute REG_UNUSED notes
304 : : // after the update.
305 : : keep_p = false;
306 : : break;
307 : :
308 : : default:
309 : : break;
310 : : }
311 : 227800 : if (keep_p)
312 : 475710 : note_ptr = &XEXP (*note_ptr, 1);
313 : : else
314 : : {
315 : 5855764 : *note_ptr = XEXP (*note_ptr, 1);
316 : 5855764 : free_EXPR_LIST_node (note);
317 : : }
318 : : }
319 : 10030761 : }
320 : :
321 : : // Pick a location for CHANGE's instruction and return the instruction
322 : : // after which it should be placed.
323 : : static insn_info *
324 : 10030761 : choose_insn_placement (insn_change &change)
325 : : {
326 : 10030761 : gcc_checking_assert (change.move_range);
327 : :
328 : 10030761 : insn_info *insn = change.insn ();
329 : 10030761 : insn_info *first = change.move_range.first;
330 : 10030761 : insn_info *last = change.move_range.last;
331 : :
332 : : // Quick(ish) exit if there is only one possible choice.
333 : 10030761 : if (first == last)
334 : : return first;
335 : 650640 : if (first == insn->prev_nondebug_insn () && last == insn)
336 : : return insn;
337 : :
338 : : // For now just use the closest valid choice to the original instruction.
339 : : // If the register usage has changed significantly, it might instead be
340 : : // better to try to take register pressure into account.
341 : 559549 : insn_info *closest = change.move_range.clamp_insn_to_range (insn);
342 : 1119098 : while (closest != insn && !can_insert_after (closest))
343 : 0 : closest = closest->next_nondebug_insn ();
344 : : return closest;
345 : : }
346 : :
347 : : // Record any changes related to CHANGE that need to be queued for later.
348 : : void
349 : 12306103 : function_info::possibly_queue_changes (insn_change &change)
350 : : {
351 : 12306103 : insn_info *insn = change.insn ();
352 : 12306103 : rtx_insn *rtl = insn->rtl ();
353 : :
354 : : // If the instruction could previously throw, we eventually need to call
355 : : // purge_dead_edges to check whether things have changed.
356 : 12306103 : if (find_reg_note (rtl, REG_EH_REGION, nullptr))
357 : 56538 : bitmap_set_bit (m_need_to_purge_dead_edges, insn->bb ()->index ());
358 : :
359 : 24612206 : auto needs_pending_update = [&]()
360 : : {
361 : : // If an instruction became a no-op without the pass explicitly
362 : : // deleting it, queue the deletion for later. Removing the
363 : : // instruction on the fly would require an update to all instructions
364 : : // that use the result of the move, which would be a potential source
365 : : // of quadraticness. Also, definitions shouldn't disappear under
366 : : // the pass's feet.
367 : 12306103 : if (INSN_CODE (rtl) == NOOP_MOVE_INSN_CODE)
368 : : return true;
369 : :
370 : : // If any jumps got turned into unconditional jumps or nops, we need
371 : : // to update the CFG accordingly.
372 : 12297951 : if (JUMP_P (rtl)
373 : 1338 : && (returnjump_p (rtl) || any_uncondjump_p (rtl))
374 : 12306108 : && !single_succ_p (insn->bb ()->cfg_bb ()))
375 : : return true;
376 : :
377 : : // If a previously conditional trap now always fires, execution
378 : : // terminates at that point.
379 : 12297946 : rtx pattern = PATTERN (rtl);
380 : 12297946 : if (GET_CODE (pattern) == TRAP_IF
381 : 0 : && XEXP (pattern, 0) == const1_rtx)
382 : : return true;
383 : :
384 : : return false;
385 : 12306103 : };
386 : :
387 : 12306103 : if (needs_pending_update ()
388 : 12306103 : && bitmap_set_bit (m_queued_insn_update_uids, insn->uid ()))
389 : : {
390 : 7668 : gcc_assert (!change.is_deletion ());
391 : 7668 : m_queued_insn_updates.safe_push (insn);
392 : : }
393 : 12306103 : }
394 : :
395 : : // Remove the instruction described by CHANGE from the underlying RTL
396 : : // and from the insn_info list.
397 : : static void
398 : 2275342 : delete_insn (insn_change &change)
399 : : {
400 : 2275342 : insn_info *insn = change.insn ();
401 : 2275342 : rtx_insn *rtl = change.rtl ();
402 : 2275342 : if (dump_file && (dump_flags & TDF_DETAILS))
403 : 0 : fprintf (dump_file, "deleting insn %d\n", insn->uid ());
404 : 2275342 : set_insn_deleted (rtl);
405 : 2275342 : }
406 : :
407 : : // Move the RTL instruction associated with CHANGE so that it comes
408 : : // immediately after AFTER.
409 : : static void
410 : 21915 : move_insn (insn_change &change, insn_info *after)
411 : : {
412 : 21915 : rtx_insn *rtl = change.rtl ();
413 : 21915 : rtx_insn *after_rtl = after->rtl ();
414 : 21915 : if (dump_file && (dump_flags & TDF_DETAILS))
415 : 0 : fprintf (dump_file, "moving insn %d after insn %d\n",
416 : 0 : INSN_UID (rtl), INSN_UID (after_rtl));
417 : :
418 : : // At the moment we don't support moving instructions between EBBs,
419 : : // but this would be worth adding if it's useful.
420 : 21915 : insn_info *insn = change.insn ();
421 : :
422 : 21915 : bb_info *bb = after->bb ();
423 : 21915 : basic_block cfg_bb = bb->cfg_bb ();
424 : :
425 : 21915 : if (!insn->is_temporary ())
426 : : {
427 : 21915 : gcc_assert (after->ebb () == insn->ebb ());
428 : :
429 : 21915 : if (insn->bb () != bb)
430 : : // Force DF to mark the old block as dirty.
431 : 0 : df_insn_delete (rtl);
432 : 21915 : ::remove_insn (rtl);
433 : : }
434 : :
435 : 21915 : ::add_insn_after (rtl, after_rtl, cfg_bb);
436 : 21915 : }
437 : :
438 : : // The instruction associated with CHANGE is being changed in-place.
439 : : // Update the DF information for its new pattern.
440 : : static void
441 : 10008846 : update_insn_in_place (insn_change &change)
442 : : {
443 : 10008846 : insn_info *insn = change.insn ();
444 : 10008846 : if (dump_file && (dump_flags & TDF_DETAILS))
445 : 0 : fprintf (dump_file, "updating insn %d in-place\n", insn->uid ());
446 : 10008846 : df_insn_rescan (change.rtl ());
447 : 10008846 : }
448 : :
449 : : // Finalize the new list of definitions and uses in CHANGE, removing
450 : : // any uses and definitions that are no longer needed, and converting
451 : : // pending clobbers into actual definitions.
452 : : //
453 : : // POS gives the final position of INSN, which hasn't yet been moved into
454 : : // place. Keep track of any newly-created set_infos being added with this
455 : : // change by adding them to NEW_SETS.
456 : : void
457 : 10030761 : function_info::finalize_new_accesses (insn_change &change, insn_info *pos,
458 : : hash_set<def_info *> &new_sets)
459 : : {
460 : 10030761 : insn_info *insn = change.insn ();
461 : :
462 : : // Get a list of all the things that the instruction now references.
463 : 10030761 : vec_rtx_properties properties;
464 : 10030761 : properties.add_insn (insn->rtl (), true);
465 : :
466 : : // Build up the new list of definitions.
467 : 35219863 : for (rtx_obj_reference ref : properties.refs ())
468 : 25189102 : if (ref.is_write ())
469 : : {
470 : 9742093 : def_info *def = find_access (change.new_defs, ref.regno);
471 : 9742093 : gcc_assert (def);
472 : :
473 : 9742093 : if (def->m_is_temp && is_a<set_info *> (def) && def->last_def ())
474 : : {
475 : : // For temporary sets being added with this change, we keep track of
476 : : // the corresponding permanent def using the last_def link.
477 : : //
478 : : // So if we have one of these, follow it to get the permanent def.
479 : 0 : def = def->last_def ();
480 : 0 : gcc_assert (!def->m_is_temp && !def->m_has_been_superceded);
481 : : }
482 : :
483 : 9742093 : if (def->m_is_temp)
484 : : {
485 : 34879 : if (is_a<clobber_info *> (def))
486 : 34879 : def = allocate<clobber_info> (change.insn (), ref.regno);
487 : 0 : else if (is_a<set_info *> (def))
488 : : {
489 : : // Install the permanent set in the last_def link of the
490 : : // temporary def. This allows us to find the permanent def
491 : : // later in case we see a second write to the same resource.
492 : 0 : def_info *perm_def = allocate<set_info> (change.insn (),
493 : 0 : def->resource ());
494 : :
495 : : // Keep track of the new set so we remember to add it to the
496 : : // def chain later.
497 : 0 : if (new_sets.add (perm_def))
498 : 0 : gcc_unreachable (); // We shouldn't see duplicates here.
499 : :
500 : 0 : def->set_last_def (perm_def);
501 : 0 : def = perm_def;
502 : : }
503 : : else
504 : 0 : gcc_unreachable ();
505 : : }
506 : 9707214 : else if (!def->m_has_been_superceded)
507 : : {
508 : : // This is a second or subsequent definition.
509 : : // See function_info::record_def for a discussion of when
510 : : // this can happen.
511 : 184303 : def->record_reference (ref, false);
512 : 184303 : continue;
513 : : }
514 : : else
515 : : {
516 : 9522911 : def->m_has_been_superceded = false;
517 : :
518 : : // Clobbers can move around, so remove them from their current
519 : : // position and them back in their final position.
520 : : //
521 : : // At the moment, we don't allow sets to move relative to other
522 : : // definitions of the same resource, so we can leave those where
523 : : // they are. It might be useful to relax this in future.
524 : : // The main complication is that removing a set would potentially
525 : : // fuse two adjoining clobber_groups, and adding the set back
526 : : // would require the group to be split again.
527 : 9522911 : if (is_a<clobber_info *> (def))
528 : 901846 : remove_def (def);
529 : 8621065 : else if (ref.is_reg ())
530 : 6432138 : def->set_mode (ref.mode);
531 : 9522911 : def->set_insn (insn);
532 : : }
533 : 9557790 : def->record_reference (ref, true);
534 : 9557790 : m_temp_defs.safe_push (def);
535 : : }
536 : :
537 : : // Also keep any explicitly-recorded call clobbers, which are deliberately
538 : : // excluded from the vec_rtx_properties. Calls shouldn't move, so we can
539 : : // keep the definitions in their current position.
540 : : //
541 : : // If the change describes a set of memory, but the pattern doesn't
542 : : // reference memory, keep the set anyway. This can happen if the
543 : : // old pattern was a parallel that contained a memory clobber, and if
544 : : // the new pattern was recognized without that clobber. Keeping the
545 : : // set avoids a linear-complexity update to the set's users.
546 : : //
547 : : // ??? We could queue an update so that these bogus clobbers are
548 : : // removed later.
549 : 19618934 : for (def_info *def : change.new_defs)
550 : 9588173 : if (def->m_has_been_superceded
551 : 9588173 : && (def->is_call_clobber () || def->is_mem ()))
552 : : {
553 : 0 : def->m_has_been_superceded = false;
554 : 0 : def->set_insn (insn);
555 : 0 : m_temp_defs.safe_push (def);
556 : : }
557 : :
558 : : // Install the new list of definitions in CHANGE.
559 : 10030761 : sort_accesses (m_temp_defs);
560 : 20061522 : access_array accesses = temp_access_array (m_temp_defs);
561 : 10030761 : change.new_defs = def_array (accesses);
562 : 10030761 : m_temp_defs.truncate (0);
563 : :
564 : : // Create temporary copies of use_infos that are already attached to
565 : : // other insns, which could happen if the uses come from unchanging
566 : : // insns or if they have been used by earlier changes. Doing this
567 : : // makes it easier to detect multiple reads below.
568 : 10030761 : auto *unshared_uses_base = XOBNEWVEC (&m_temp_obstack, access_info *,
569 : : change.new_uses.size ());
570 : 10030761 : unsigned int i = 0;
571 : 28634653 : for (use_info *use : change.new_uses)
572 : : {
573 : 18603892 : if (!use->m_has_been_superceded)
574 : : {
575 : 6918092 : use = allocate_temp<use_info> (insn, use->resource (), use->def ());
576 : 6918092 : use->m_has_been_superceded = true;
577 : 6918092 : use->m_is_temp = true;
578 : : }
579 : 18603892 : unshared_uses_base[i++] = use;
580 : : }
581 : 10030761 : auto unshared_uses = use_array (unshared_uses_base, change.new_uses.size ());
582 : :
583 : : // Add (possibly temporary) uses to m_temp_uses for each resource.
584 : : // If there are multiple references to the same resource, aggregate
585 : : // information in the modes and flags.
586 : 10030761 : use_info *mem_use = nullptr;
587 : 35219863 : for (rtx_obj_reference ref : properties.refs ())
588 : 25189102 : if (ref.is_read ())
589 : : {
590 : 15837977 : unsigned int regno = ref.regno;
591 : 15837977 : machine_mode mode = ref.is_reg () ? ref.mode : BLKmode;
592 : 15837977 : use_info *use = find_access (unshared_uses, ref.regno);
593 : 15837977 : if (!use)
594 : : {
595 : : // For now, we only support inferring uses of mem.
596 : 0 : gcc_assert (regno == MEM_REGNO);
597 : :
598 : 0 : if (mem_use)
599 : : {
600 : 0 : mem_use->record_reference (ref, false);
601 : 0 : continue;
602 : : }
603 : :
604 : 0 : resource_info resource { mode, regno };
605 : 0 : auto def = find_def (resource, pos).prev_def (pos);
606 : 0 : auto set = safe_dyn_cast <set_info *> (def);
607 : 0 : gcc_assert (set);
608 : 0 : mem_use = allocate<use_info> (insn, resource, set);
609 : 0 : mem_use->record_reference (ref, true);
610 : 0 : m_temp_uses.safe_push (mem_use);
611 : 0 : continue;
612 : 0 : }
613 : :
614 : 15837977 : if (use->m_has_been_superceded)
615 : : {
616 : : // This is the first reference to the resource.
617 : 15452112 : bool is_temp = use->m_is_temp;
618 : 15452112 : *use = use_info (insn, resource_info { mode, regno }, use->def ());
619 : 15452112 : use->m_is_temp = is_temp;
620 : 15452112 : use->record_reference (ref, true);
621 : 15452112 : m_temp_uses.safe_push (use);
622 : : }
623 : : else
624 : : {
625 : : // Record the mode of the largest use. The choice is arbitrary if
626 : : // the instruction (unusually) references the same register in two
627 : : // different but equal-sized modes.
628 : 385865 : if (HARD_REGISTER_NUM_P (regno)
629 : 385865 : && partial_subreg_p (use->mode (), mode))
630 : 27 : use->set_mode (mode);
631 : 385865 : use->record_reference (ref, false);
632 : : }
633 : : }
634 : :
635 : : // Replace any temporary uses and definitions with real ones.
636 : 25482873 : for (unsigned int i = 0; i < m_temp_uses.length (); ++i)
637 : : {
638 : 15452112 : auto *use = as_a<use_info *> (m_temp_uses[i]);
639 : 15452112 : if (use->m_is_temp)
640 : : {
641 : 6833719 : m_temp_uses[i] = use = allocate<use_info> (*use);
642 : 6833719 : use->m_is_temp = false;
643 : 6833719 : set_info *def = use->def ();
644 : 6833719 : if (!def || !def->m_is_temp)
645 : 6821953 : continue;
646 : :
647 : 11766 : if (auto phi = dyn_cast<phi_info *> (def))
648 : : {
649 : : // Handle cases in which the value was previously not used
650 : : // within the block.
651 : 11766 : gcc_assert (phi->is_degenerate ());
652 : 11766 : phi = create_degenerate_phi (phi->ebb (), phi->input_value (0));
653 : 11766 : use->set_def (phi);
654 : : }
655 : : else
656 : : {
657 : : // The temporary def may also be a set added with this change, in
658 : : // which case the permanent set is stored in the last_def link,
659 : : // and we need to update the use to refer to the permanent set.
660 : 0 : gcc_assert (is_a<set_info *> (def));
661 : 0 : auto perm_set = as_a<set_info *> (def->last_def ());
662 : 0 : gcc_assert (!perm_set->is_temporary ());
663 : 0 : use->set_def (perm_set);
664 : : }
665 : : }
666 : : }
667 : :
668 : : // Install the new list of uses in CHANGE.
669 : 10030761 : sort_accesses (m_temp_uses);
670 : 20061522 : change.new_uses = use_array (temp_access_array (m_temp_uses));
671 : 10030761 : m_temp_uses.truncate (0);
672 : :
673 : : // Record the new instruction-wide properties.
674 : 10030761 : insn->set_properties (properties);
675 : 10030761 : }
676 : :
677 : : // Copy information from CHANGE to its underlying insn_info, given that
678 : : // the insn_info has already been placed appropriately. NEW_SETS contains the
679 : : // new set_infos that are being added as part of this change (as opposed to
680 : : // being moved or repurposed from existing instructions).
681 : : void
682 : 12306103 : function_info::apply_changes_to_insn (insn_change &change,
683 : : hash_set<def_info *> &new_sets)
684 : : {
685 : 12306103 : insn_info *insn = change.insn ();
686 : 12306103 : if (change.is_deletion ())
687 : : {
688 : 2275342 : insn->set_accesses (nullptr, 0, 0);
689 : 2275342 : return;
690 : : }
691 : :
692 : : // Copy the cost.
693 : 10030761 : insn->set_cost (change.new_cost);
694 : :
695 : : // Add all clobbers and newly-created sets. Existing sets and call
696 : : // clobbers never move relative to other definitions, so are OK as-is.
697 : 19588551 : for (def_info *def : change.new_defs)
698 : 9557790 : if ((is_a<clobber_info *> (def) && !def->is_call_clobber ())
699 : 10494515 : || (is_a<set_info *> (def) && new_sets.contains (def)))
700 : 936725 : add_def (def);
701 : :
702 : : // Add all uses, now that their position is final.
703 : 25482873 : for (use_info *use : change.new_uses)
704 : 15452112 : add_use (use);
705 : :
706 : : // Copy the uses and definitions.
707 : 10030761 : unsigned int num_defs = change.new_defs.size ();
708 : 10030761 : unsigned int num_uses = change.new_uses.size ();
709 : 10030761 : if (num_defs + num_uses <= insn->num_defs () + insn->num_uses ())
710 : 9755253 : insn->copy_accesses (change.new_defs, change.new_uses);
711 : : else
712 : : {
713 : 275508 : access_array_builder builder (&m_obstack);
714 : 275508 : builder.reserve (num_defs + num_uses);
715 : :
716 : 620819 : for (def_info *def : change.new_defs)
717 : 345311 : builder.quick_push (def);
718 : 980552 : for (use_info *use : change.new_uses)
719 : 705044 : builder.quick_push (use);
720 : :
721 : 275508 : insn->set_accesses (builder.finish ().begin (), num_defs, num_uses);
722 : 275508 : }
723 : :
724 : 10030761 : insn->m_is_temp = false;
725 : : }
726 : :
727 : : // Add a temporary placeholder instruction after AFTER.
728 : : insn_info *
729 : 21915 : function_info::add_placeholder_after (insn_info *after)
730 : : {
731 : 21915 : insn_info *insn = allocate_temp<insn_info> (after->bb (), nullptr, -1);
732 : 21915 : add_insn_after (insn, after);
733 : 21915 : return insn;
734 : : }
735 : :
736 : : // See the comment above the declaration.
737 : : void
738 : 6529065 : function_info::change_insns (array_slice<insn_change *> changes)
739 : : {
740 : 6529065 : auto watermark = temp_watermark ();
741 : :
742 : 6529065 : insn_info *min_insn = m_first_insn;
743 : 18835168 : for (insn_change *change : changes)
744 : : {
745 : : // Tentatively mark all the old uses and definitions for deletion.
746 : 31162040 : for (use_info *use : change->old_uses ())
747 : : {
748 : 18855937 : use->m_has_been_superceded = true;
749 : 18855937 : remove_use (use);
750 : : }
751 : 24246081 : for (def_info *def : change->old_defs ())
752 : 11939978 : def->m_has_been_superceded = true;
753 : :
754 : 12306103 : if (!change->is_deletion ())
755 : : {
756 : : // Remove any notes that are no longer relevant.
757 : 10030761 : if (!change->insn ()->m_is_temp)
758 : 10030761 : update_notes (change->rtl ());
759 : :
760 : : // Make sure that the placement of this instruction would still
761 : : // leave room for previous instructions.
762 : 10030761 : change->move_range = move_later_than (change->move_range, min_insn);
763 : 10030761 : if (!canonicalize_move_range (change->move_range, change->insn ()))
764 : : // verify_insn_changes is supposed to make sure that this holds.
765 : 0 : gcc_unreachable ();
766 : 10030761 : min_insn = later_insn (min_insn, change->move_range.first);
767 : :
768 : 10030761 : if (change->insn ()->m_is_temp)
769 : : {
770 : 0 : change->m_insn = allocate<insn_info> (change->insn ()->bb (),
771 : : change->rtl (),
772 : : change->insn_uid ());
773 : :
774 : : // Set the flag again so subsequent logic is aware.
775 : : // It will be cleared later on.
776 : 0 : change->m_insn->m_is_temp = true;
777 : : }
778 : : }
779 : : }
780 : :
781 : : // Walk backwards through the changes, allocating specific positions
782 : : // to each one. Update the underlying RTL and its associated DF
783 : : // information.
784 : 6529065 : insn_info *following_insn = nullptr;
785 : 6529065 : auto_vec<insn_info *, 16> placeholders;
786 : 6529065 : placeholders.safe_grow_cleared (changes.size ());
787 : 18835168 : for (unsigned int i = changes.size (); i-- > 0;)
788 : : {
789 : 12306103 : insn_change &change = *changes[i];
790 : 12306103 : insn_info *placeholder = nullptr;
791 : 12306103 : possibly_queue_changes (change);
792 : 12306103 : if (change.is_deletion ())
793 : 2275342 : delete_insn (change);
794 : : else
795 : : {
796 : : // Make sure that this instruction comes before later ones.
797 : 10030761 : if (following_insn)
798 : : {
799 : 3539463 : change.move_range = move_earlier_than (change.move_range,
800 : : following_insn);
801 : 3539463 : if (!canonicalize_move_range (change.move_range,
802 : : change.insn ()))
803 : : // verify_insn_changes is supposed to make sure that this
804 : : // holds.
805 : 0 : gcc_unreachable ();
806 : : }
807 : :
808 : : // Decide which instruction INSN should go after.
809 : 10030761 : insn_info *after = choose_insn_placement (change);
810 : :
811 : : // If INSN is moving, insert a placeholder insn_info at the
812 : : // new location. We can't move INSN itself yet because it
813 : : // might still be referenced by earlier move ranges.
814 : 10030761 : insn_info *insn = change.insn ();
815 : 10030761 : if (after == insn || after == insn->prev_nondebug_insn ())
816 : : {
817 : 10008846 : update_insn_in_place (change);
818 : 10008846 : following_insn = insn;
819 : : }
820 : : else
821 : : {
822 : 21915 : move_insn (change, after);
823 : 21915 : placeholder = add_placeholder_after (after);
824 : 21915 : following_insn = placeholder;
825 : : }
826 : : }
827 : 12306103 : placeholders[i] = placeholder;
828 : : }
829 : :
830 : : // We need to keep track of newly-added sets as these need adding to
831 : : // the def chain later.
832 : 6529065 : hash_set<def_info *> new_sets;
833 : :
834 : : // Finalize the new list of accesses for each change. Don't install them yet,
835 : : // so that we still have access to the old lists below.
836 : : //
837 : : // Note that we do this forwards instead of in the backwards loop above so
838 : : // that any new defs being inserted are processed before new uses of those
839 : : // defs, so that the (initially) temporary uses referring to temporary defs
840 : : // can be easily updated to become permanent uses referring to permanent defs.
841 : 18835168 : for (unsigned i = 0; i < changes.size (); i++)
842 : : {
843 : 12306103 : insn_change &change = *changes[i];
844 : 12306103 : insn_info *placeholder = placeholders[i];
845 : 12306103 : if (!change.is_deletion ())
846 : 20039607 : finalize_new_accesses (change,
847 : 10008846 : placeholder ? placeholder : change.insn (),
848 : : new_sets);
849 : : }
850 : :
851 : : // Remove all definitions that are no longer needed. After the above,
852 : : // the only uses of such definitions should be dead phis and now-redundant
853 : : // live-out uses.
854 : : //
855 : : // In particular, this means that consumers must handle debug
856 : : // instructions before removing a set.
857 : 18835168 : for (insn_change *change : changes)
858 : 24246081 : for (def_info *def : change->old_defs ())
859 : 11939978 : if (def->m_has_been_superceded)
860 : : {
861 : 2417067 : auto *set = dyn_cast<set_info *> (def);
862 : 2275342 : if (set && set->has_any_uses ())
863 : 727633 : process_uses_of_deleted_def (set);
864 : 2417067 : remove_def (def);
865 : : }
866 : :
867 : : // Move the insn_infos to their new locations.
868 : 18835168 : for (unsigned int i = 0; i < changes.size (); ++i)
869 : : {
870 : 12306103 : insn_change &change = *changes[i];
871 : 12306103 : insn_info *insn = change.insn ();
872 : 12306103 : if (change.is_deletion ())
873 : : {
874 : 2275342 : if (rtx_insn *rtl = insn->rtl ())
875 : 2275342 : ::remove_insn (rtl); // Remove the underlying RTL insn.
876 : 2275342 : remove_insn (insn);
877 : : }
878 : 10030761 : else if (insn_info *placeholder = placeholders[i])
879 : : {
880 : : // Check if earlier movements turned a move into a no-op.
881 : 21915 : if (placeholder->prev_nondebug_insn () == insn
882 : 21915 : || placeholder->next_nondebug_insn () == insn)
883 : : {
884 : 0 : remove_insn (placeholder);
885 : 0 : placeholders[i] = nullptr;
886 : : }
887 : : else
888 : : {
889 : 21915 : insn_info *after = placeholder->prev_any_insn ();
890 : 21915 : if (!insn->is_temporary ())
891 : 21915 : remove_insn (insn);
892 : 21915 : replace_nondebug_insn (placeholder, insn);
893 : 21915 : insn->set_bb (after->bb ());
894 : : }
895 : : }
896 : : }
897 : :
898 : : // Apply the changes to the underlying insn_infos.
899 : 18835168 : for (insn_change *change : changes)
900 : 12306103 : apply_changes_to_insn (*change, new_sets);
901 : :
902 : : // Now that the insns and accesses are up to date, add any REG_UNUSED notes.
903 : 18835168 : for (insn_change *change : changes)
904 : 12306103 : if (!change->is_deletion ())
905 : 10030761 : add_reg_unused_notes (change->insn ());
906 : 6529065 : }
907 : :
908 : : // See the comment above the declaration.
909 : : void
910 : 2943136 : function_info::change_insn (insn_change &change)
911 : : {
912 : 2943136 : insn_change *changes[] = { &change };
913 : 2943136 : return change_insns (changes);
914 : : }
915 : :
916 : : // Try to adjust CHANGE so that its pattern can include clobber rtx CLOBBER.
917 : : // Return true on success.
918 : : //
919 : : // ADD_REGNO_CLOBBER is a specialization of function_info::add_regno_clobber
920 : : // for a specific caller-provided predicate.
921 : : static bool
922 : 2520893 : add_clobber (insn_change &change, add_regno_clobber_fn add_regno_clobber,
923 : : rtx clobber)
924 : : {
925 : 2520893 : rtx pat = PATTERN (change.rtl ());
926 : 2520893 : gcc_assert (GET_CODE (clobber) == CLOBBER);
927 : 2520893 : rtx dest = XEXP (clobber, 0);
928 : 2520893 : if (GET_CODE (dest) == SCRATCH)
929 : : {
930 : 127500 : if (reload_completed)
931 : : {
932 : 48461 : if (dump_file && (dump_flags & TDF_DETAILS))
933 : : {
934 : : // ??? Maybe we could try to do some RA here?
935 : 0 : fprintf (dump_file, "instruction requires a scratch"
936 : : " after reload:\n");
937 : 0 : print_rtl_single (dump_file, pat);
938 : : }
939 : 48461 : return false;
940 : : }
941 : : return true;
942 : : }
943 : :
944 : 2393393 : gcc_assert (REG_P (dest));
945 : 4784404 : for (unsigned int regno = REGNO (dest); regno != END_REGNO (dest); ++regno)
946 : 2393393 : if (!add_regno_clobber (change, regno))
947 : : {
948 : 2382 : if (dump_file && (dump_flags & TDF_DETAILS))
949 : : {
950 : 0 : fprintf (dump_file, "cannot clobber live register %d in:\n",
951 : : regno);
952 : 0 : print_rtl_single (dump_file, pat);
953 : : }
954 : 2382 : return false;
955 : : }
956 : : return true;
957 : : }
958 : :
959 : : // See if PARALLEL pattern PAT clobbers any of the registers in ACCESSES.
960 : : // Return one such access if so, otherwise return null.
961 : : static access_info *
962 : 4111470 : find_clobbered_access (access_array accesses, rtx pat)
963 : : {
964 : 4111470 : rtx subpat;
965 : 12884598 : for (int i = 0; i < XVECLEN (pat, 0); ++i)
966 : 8786609 : if (GET_CODE (subpat = XVECEXP (pat, 0, i)) == CLOBBER)
967 : : {
968 : 4532262 : rtx x = XEXP (subpat, 0);
969 : 4532262 : if (REG_P (x))
970 : 13193019 : for (auto *access : accesses)
971 : 8903132 : if (access->regno () >= REGNO (x)
972 : 8903132 : && access->regno () < END_REGNO (x))
973 : : return access;
974 : : }
975 : : return nullptr;
976 : : }
977 : :
978 : : // Try to recognize the new form of the insn associated with CHANGE,
979 : : // adding any clobbers that are necessary to make the instruction match
980 : : // an .md pattern. Return true on success.
981 : : //
982 : : // ADD_REGNO_CLOBBER is a specialization of function_info::add_regno_clobber
983 : : // for a specific caller-provided predicate.
984 : : static bool
985 : 44075732 : recog_level2 (insn_change &change, add_regno_clobber_fn add_regno_clobber)
986 : : {
987 : 44075732 : insn_change_watermark insn_watermark;
988 : 44075732 : rtx_insn *rtl = change.rtl ();
989 : 44075732 : rtx pat = PATTERN (rtl);
990 : 44075732 : int num_clobbers = 0;
991 : 44075732 : int icode = -1;
992 : 44075732 : bool asm_p = asm_noperands (pat) >= 0;
993 : 44075732 : if (asm_p)
994 : : {
995 : 68689 : if (!check_asm_operands (pat))
996 : : {
997 : 59551 : if (dump_file && (dump_flags & TDF_DETAILS))
998 : : {
999 : 0 : fprintf (dump_file, "failed to match this asm instruction:\n");
1000 : 0 : print_rtl_single (dump_file, pat);
1001 : : }
1002 : 59551 : return false;
1003 : : }
1004 : : }
1005 : 44007043 : else if (noop_move_p (rtl))
1006 : : {
1007 : 10657 : INSN_CODE (rtl) = NOOP_MOVE_INSN_CODE;
1008 : 10657 : if (dump_file && (dump_flags & TDF_DETAILS))
1009 : : {
1010 : 0 : fprintf (dump_file, "instruction becomes a no-op:\n");
1011 : 0 : print_rtl_single (dump_file, pat);
1012 : : }
1013 : 10657 : insn_watermark.keep ();
1014 : 10657 : return true;
1015 : : }
1016 : : else
1017 : : {
1018 : 43996386 : icode = ::recog (pat, rtl, &num_clobbers);
1019 : 43996386 : if (icode < 0)
1020 : : {
1021 : 27785134 : if (dump_file && (dump_flags & TDF_DETAILS))
1022 : : {
1023 : 0 : fprintf (dump_file, "failed to match this instruction:\n");
1024 : 0 : print_rtl_single (dump_file, pat);
1025 : : }
1026 : 27785134 : return false;
1027 : : }
1028 : : }
1029 : :
1030 : 16220390 : auto prev_new_defs = change.new_defs;
1031 : 16220390 : auto prev_move_range = change.move_range;
1032 : 16220390 : if (num_clobbers > 0)
1033 : : {
1034 : : // ??? It would be good to have a way of recycling the rtxes on failure,
1035 : : // but any attempt to cache old PARALLELs would at best be a half
1036 : : // measure, since add_clobbers would still generate fresh clobbers
1037 : : // each time. It would be better to have a more general recycling
1038 : : // mechanism that all rtx passes can use.
1039 : 2513008 : rtvec newvec;
1040 : 2513008 : int oldlen;
1041 : 2513008 : if (GET_CODE (pat) == PARALLEL)
1042 : : {
1043 : 29267 : oldlen = XVECLEN (pat, 0);
1044 : 29267 : newvec = rtvec_alloc (num_clobbers + oldlen);
1045 : 87825 : for (int i = 0; i < oldlen; ++i)
1046 : 58558 : RTVEC_ELT (newvec, i) = XVECEXP (pat, 0, i);
1047 : : }
1048 : : else
1049 : : {
1050 : 2483741 : oldlen = 1;
1051 : 2483741 : newvec = rtvec_alloc (num_clobbers + oldlen);
1052 : 2483741 : RTVEC_ELT (newvec, 0) = pat;
1053 : : }
1054 : 2513008 : rtx newpat = gen_rtx_PARALLEL (VOIDmode, newvec);
1055 : 2513008 : add_clobbers (newpat, icode);
1056 : 2513008 : validate_change (rtl, &PATTERN (rtl), newpat, true);
1057 : 4983058 : for (int i = 0; i < num_clobbers; ++i)
1058 : 2520893 : if (!add_clobber (change, add_regno_clobber,
1059 : 2520893 : XVECEXP (newpat, 0, oldlen + i)))
1060 : : {
1061 : 50843 : change.new_defs = prev_new_defs;
1062 : 50843 : change.move_range = prev_move_range;
1063 : 50843 : return false;
1064 : : }
1065 : :
1066 : : pat = newpat;
1067 : : }
1068 : :
1069 : 16169547 : INSN_CODE (rtl) = icode;
1070 : 16169547 : if (recog_data.insn == rtl)
1071 : 0 : recog_data.insn = nullptr;
1072 : :
1073 : : // See if the pattern contains any hard-coded clobbers of registers
1074 : : // that are also inputs to the instruction. The standard rtl semantics
1075 : : // treat such clobbers as earlyclobbers, since there is no way of proving
1076 : : // which clobbers conflict with the inputs and which don't.
1077 : : //
1078 : : // (Non-hard-coded clobbers are handled by constraint satisfaction instead.)
1079 : 16169547 : rtx subpat;
1080 : 16169547 : if (GET_CODE (pat) == PARALLEL)
1081 : 12840366 : for (int i = 0; i < XVECLEN (pat, 0); ++i)
1082 : 8664157 : if (GET_CODE (subpat = XVECEXP (pat, 0, i)) == CLOBBER
1083 : 8664157 : && REG_P (XEXP (subpat, 0)))
1084 : : {
1085 : : // Stub out all operands, so that we can tell which registers
1086 : : // are hard-coded.
1087 : 4111470 : extract_insn (rtl);
1088 : 16634940 : for (int j = 0; j < recog_data.n_operands; ++j)
1089 : 12523470 : *recog_data.operand_loc[j] = pc_rtx;
1090 : :
1091 : 4111470 : auto *use = find_clobbered_access (change.new_uses, pat);
1092 : :
1093 : : // Restore the operands.
1094 : 16634940 : for (int j = 0; j < recog_data.n_operands; ++j)
1095 : 12523470 : *recog_data.operand_loc[j] = recog_data.operand[j];
1096 : :
1097 : 4111470 : if (use)
1098 : : {
1099 : 13481 : if (dump_file && (dump_flags & TDF_DETAILS))
1100 : : {
1101 : 0 : fprintf (dump_file, "register %d is both clobbered"
1102 : : " and used as an input:\n", use->regno ());
1103 : 0 : print_rtl_single (dump_file, pat);
1104 : : }
1105 : 13481 : return false;
1106 : : }
1107 : : }
1108 : :
1109 : : // check_asm_operands checks the constraints after RA, so we don't
1110 : : // need to do it again.
1111 : 16156066 : if (reload_completed && !asm_p)
1112 : : {
1113 : 3654653 : extract_insn (rtl);
1114 : 3654653 : if (!constrain_operands (1, get_preferred_alternatives (rtl)))
1115 : : {
1116 : 2026537 : if (dump_file && (dump_flags & TDF_DETAILS))
1117 : : {
1118 : 0 : if (asm_p)
1119 : : fprintf (dump_file, "asm does not match its constraints:\n");
1120 : 0 : else if (const char *name = get_insn_name (icode))
1121 : 0 : fprintf (dump_file, "instruction does not match the"
1122 : : " constraints for %s:\n", name);
1123 : : else
1124 : 0 : fprintf (dump_file, "instruction does not match its"
1125 : : " constraints:\n");
1126 : 0 : print_rtl_single (dump_file, pat);
1127 : : }
1128 : 2026537 : change.new_defs = prev_new_defs;
1129 : 2026537 : change.move_range = prev_move_range;
1130 : 2026537 : return false;
1131 : : }
1132 : : }
1133 : :
1134 : 14129529 : if (dump_file && (dump_flags & TDF_DETAILS))
1135 : : {
1136 : 0 : const char *name;
1137 : 0 : if (!asm_p && (name = get_insn_name (icode)))
1138 : 0 : fprintf (dump_file, "successfully matched this instruction "
1139 : : "to %s:\n", name);
1140 : : else
1141 : 0 : fprintf (dump_file, "successfully matched this instruction:\n");
1142 : 0 : print_rtl_single (dump_file, pat);
1143 : : }
1144 : :
1145 : 14129529 : insn_watermark.keep ();
1146 : 14129529 : return true;
1147 : 44075732 : }
1148 : :
1149 : : // Try to recognize the new form of the insn associated with CHANGE,
1150 : : // adding and removing clobbers as necessary to make the instruction
1151 : : // match an .md pattern. Return true on success, otherwise leave
1152 : : // CHANGE as it was on entry.
1153 : : //
1154 : : // ADD_REGNO_CLOBBER is a specialization of function_info::add_regno_clobber
1155 : : // for a specific caller-provided predicate.
1156 : : bool
1157 : 38387528 : rtl_ssa::recog_internal (insn_change &change,
1158 : : add_regno_clobber_fn add_regno_clobber)
1159 : : {
1160 : : // Accept all changes to debug instructions.
1161 : 38387528 : insn_info *insn = change.insn ();
1162 : 38387528 : if (insn->is_debug_insn ())
1163 : : return true;
1164 : :
1165 : 38025346 : rtx_insn *rtl = insn->rtl ();
1166 : 38025346 : rtx pat = PATTERN (rtl);
1167 : 38025346 : if (GET_CODE (pat) == PARALLEL && asm_noperands (pat) < 0)
1168 : : {
1169 : : // Try to remove trailing (clobber (scratch)) rtxes, since the new form
1170 : : // of the instruction might not need those scratches. recog will add
1171 : : // back any that are needed.
1172 : 7652594 : int len = XVECLEN (pat, 0);
1173 : 7652594 : int new_len = len;
1174 : 7652594 : while (new_len > 0
1175 : 7766007 : && GET_CODE (XVECEXP (pat, 0, new_len - 1)) == CLOBBER
1176 : 14856726 : && GET_CODE (XEXP (XVECEXP (pat, 0, new_len - 1), 0)) == SCRATCH)
1177 : : new_len -= 1;
1178 : :
1179 : 7652594 : int old_num_changes = num_validated_changes ();
1180 : 7652594 : validate_change_xveclen (rtl, &PATTERN (rtl), new_len, true);
1181 : 7652594 : if (recog_level2 (change, add_regno_clobber))
1182 : : return true;
1183 : 6559320 : cancel_changes (old_num_changes);
1184 : :
1185 : : // Try to remove all trailing clobbers. For example, a pattern that
1186 : : // used to clobber the flags might no longer need to do so.
1187 : 6559320 : int prev_len = new_len;
1188 : 6559320 : while (new_len > 0
1189 : 12798295 : && GET_CODE (XVECEXP (pat, 0, new_len - 1)) == CLOBBER)
1190 : : new_len -= 1;
1191 : 6559320 : if (new_len != prev_len)
1192 : : {
1193 : 6050386 : validate_change_xveclen (rtl, &PATTERN (rtl), new_len, true);
1194 : 6050386 : if (recog_level2 (change, add_regno_clobber))
1195 : : return true;
1196 : 5523437 : cancel_changes (old_num_changes);
1197 : : }
1198 : 6032371 : return false;
1199 : : }
1200 : :
1201 : 30372752 : return recog_level2 (change, add_regno_clobber);
1202 : : }
1203 : :
1204 : : // See the comment above the declaration.
1205 : : bool
1206 : 3861376 : function_info::perform_pending_updates ()
1207 : : {
1208 : 3861376 : bool changed_cfg = false;
1209 : 3861376 : bool changed_jumps = false;
1210 : 3879000 : for (insn_info *insn : m_queued_insn_updates)
1211 : : {
1212 : 7668 : rtx_insn *rtl = insn->rtl ();
1213 : 7668 : if (NOTE_P (rtl))
1214 : : // The insn was later optimized away, typically to a NOTE_INSN_DELETED.
1215 : : ;
1216 : 7180 : else if (JUMP_P (rtl))
1217 : : {
1218 : 145 : if (INSN_CODE (rtl) == NOOP_MOVE_INSN_CODE)
1219 : : {
1220 : 140 : ::delete_insn (rtl);
1221 : 140 : bitmap_set_bit (m_need_to_purge_dead_edges,
1222 : 140 : insn->bb ()->index ());
1223 : : }
1224 : 5 : else if (returnjump_p (rtl) || any_uncondjump_p (rtl))
1225 : : {
1226 : 5 : mark_jump_label (PATTERN (rtl), rtl, 0);
1227 : 5 : update_cfg_for_uncondjump (rtl);
1228 : 5 : changed_cfg = true;
1229 : 5 : changed_jumps = true;
1230 : : }
1231 : : }
1232 : 7035 : else if (INSN_CODE (rtl) == NOOP_MOVE_INSN_CODE)
1233 : 7033 : ::delete_insn (rtl);
1234 : : else
1235 : : {
1236 : 2 : rtx pattern = PATTERN (rtl);
1237 : 2 : if (GET_CODE (pattern) == TRAP_IF
1238 : 0 : && XEXP (pattern, 0) == const1_rtx)
1239 : : {
1240 : 0 : remove_edge (split_block (BLOCK_FOR_INSN (rtl), rtl));
1241 : 0 : emit_barrier_after_bb (BLOCK_FOR_INSN (rtl));
1242 : 0 : changed_cfg = true;
1243 : : }
1244 : : }
1245 : : }
1246 : :
1247 : 3861376 : unsigned int index;
1248 : 3861376 : bitmap_iterator bi;
1249 : 3915601 : EXECUTE_IF_SET_IN_BITMAP (m_need_to_purge_dead_edges, 0, index, bi)
1250 : 54225 : if (purge_dead_edges (BASIC_BLOCK_FOR_FN (m_fn, index)))
1251 : 1956 : changed_cfg = true;
1252 : :
1253 : 3861376 : if (changed_jumps)
1254 : : // This uses its own timevar internally, so we don't need to push
1255 : : // one ourselves.
1256 : 5 : rebuild_jump_labels (get_insns ());
1257 : :
1258 : 3861376 : bitmap_clear (m_need_to_purge_dead_edges);
1259 : 3861376 : bitmap_clear (m_queued_insn_update_uids);
1260 : 3861376 : m_queued_insn_updates.truncate (0);
1261 : :
1262 : 3861376 : if (changed_cfg)
1263 : : {
1264 : 512 : free_dominance_info (CDI_DOMINATORS);
1265 : 512 : free_dominance_info (CDI_POST_DOMINATORS);
1266 : : }
1267 : :
1268 : 3861376 : return changed_cfg;
1269 : : }
1270 : :
1271 : : insn_info *
1272 : 0 : function_info::create_insn (obstack_watermark &watermark,
1273 : : rtx_code insn_code,
1274 : : rtx pat)
1275 : : {
1276 : 0 : rtx_insn *rti = nullptr;
1277 : :
1278 : : // TODO: extend, move in to emit-rtl.cc.
1279 : 0 : switch (insn_code)
1280 : : {
1281 : 0 : case INSN:
1282 : 0 : rti = make_insn_raw (pat);
1283 : 0 : break;
1284 : 0 : default:
1285 : 0 : gcc_unreachable ();
1286 : : }
1287 : :
1288 : 0 : auto insn = change_alloc<insn_info> (watermark, nullptr, rti, INSN_UID (rti));
1289 : 0 : insn->m_is_temp = true;
1290 : 0 : return insn;
1291 : : }
1292 : :
1293 : : // Print a description of CHANGE to PP.
1294 : : void
1295 : 0 : rtl_ssa::pp_insn_change (pretty_printer *pp, const insn_change &change)
1296 : : {
1297 : 0 : change.print (pp);
1298 : 0 : }
1299 : :
1300 : : // Print a description of CHANGE to FILE.
1301 : : void
1302 : 0 : dump (FILE *file, const insn_change &change)
1303 : : {
1304 : 0 : dump_using (file, pp_insn_change, change);
1305 : 0 : }
1306 : :
1307 : : // Debug interface to the dump routine above.
1308 : 0 : void debug (const insn_change &x) { dump (stderr, x); }
|