Add testcase of PR c++/92542, already fixed.
[official-gcc.git] / gcc / reorg.c
blobdfd7494bf79d4558efba816c421b6366d5cdcaf4
1 /* Perform instruction reorganizations for delay slot filling.
2 Copyright (C) 1992-2020 Free Software Foundation, Inc.
3 Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu).
4 Hacked by Michael Tiemann (tiemann@cygnus.com).
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 /* Instruction reorganization pass.
24 This pass runs after register allocation and final jump
25 optimization. It should be the last pass to run before peephole.
26 It serves primarily to fill delay slots of insns, typically branch
27 and call insns. Other insns typically involve more complicated
28 interactions of data dependencies and resource constraints, and
29 are better handled by scheduling before register allocation (by the
30 function `schedule_insns').
32 The Branch Penalty is the number of extra cycles that are needed to
33 execute a branch insn. On an ideal machine, branches take a single
34 cycle, and the Branch Penalty is 0. Several RISC machines approach
35 branch delays differently:
37 The MIPS has a single branch delay slot. Most insns
38 (except other branches) can be used to fill this slot. When the
39 slot is filled, two insns execute in two cycles, reducing the
40 branch penalty to zero.
42 The SPARC always has a branch delay slot, but its effects can be
43 annulled when the branch is not taken. This means that failing to
44 find other sources of insns, we can hoist an insn from the branch
45 target that would only be safe to execute knowing that the branch
46 is taken.
48 The HP-PA always has a branch delay slot. For unconditional branches
49 its effects can be annulled when the branch is taken. The effects
50 of the delay slot in a conditional branch can be nullified for forward
51 taken branches, or for untaken backward branches. This means
52 we can hoist insns from the fall-through path for forward branches or
53 steal insns from the target of backward branches.
55 The TMS320C3x and C4x have three branch delay slots. When the three
56 slots are filled, the branch penalty is zero. Most insns can fill the
57 delay slots except jump insns.
59 Three techniques for filling delay slots have been implemented so far:
61 (1) `fill_simple_delay_slots' is the simplest, most efficient way
62 to fill delay slots. This pass first looks for insns which come
63 from before the branch and which are safe to execute after the
64 branch. Then it searches after the insn requiring delay slots or,
65 in the case of a branch, for insns that are after the point at
66 which the branch merges into the fallthrough code, if such a point
67 exists. When such insns are found, the branch penalty decreases
68 and no code expansion takes place.
70 (2) `fill_eager_delay_slots' is more complicated: it is used for
71 scheduling conditional jumps, or for scheduling jumps which cannot
72 be filled using (1). A machine need not have annulled jumps to use
73 this strategy, but it helps (by keeping more options open).
74 `fill_eager_delay_slots' tries to guess the direction the branch
75 will go; if it guesses right 100% of the time, it can reduce the
76 branch penalty as much as `fill_simple_delay_slots' does. If it
77 guesses wrong 100% of the time, it might as well schedule nops. When
78 `fill_eager_delay_slots' takes insns from the fall-through path of
79 the jump, usually there is no code expansion; when it takes insns
80 from the branch target, there is code expansion if it is not the
81 only way to reach that target.
83 (3) `relax_delay_slots' uses a set of rules to simplify code that
84 has been reorganized by (1) and (2). It finds cases where
85 conditional test can be eliminated, jumps can be threaded, extra
86 insns can be eliminated, etc. It is the job of (1) and (2) to do a
87 good job of scheduling locally; `relax_delay_slots' takes care of
88 making the various individual schedules work well together. It is
89 especially tuned to handle the control flow interactions of branch
90 insns. It does nothing for insns with delay slots that do not
91 branch.
93 On machines that use CC0, we are very conservative. We will not make
94 a copy of an insn involving CC0 since we want to maintain a 1-1
95 correspondence between the insn that sets and uses CC0. The insns are
96 allowed to be separated by placing an insn that sets CC0 (but not an insn
97 that uses CC0; we could do this, but it doesn't seem worthwhile) in a
98 delay slot. In that case, we point each insn at the other with REG_CC_USER
99 and REG_CC_SETTER notes. Note that these restrictions affect very few
100 machines because most RISC machines with delay slots will not use CC0
101 (the RT is the only known exception at this point). */
103 #include "config.h"
104 #include "system.h"
105 #include "coretypes.h"
106 #include "backend.h"
107 #include "target.h"
108 #include "rtl.h"
109 #include "tree.h"
110 #include "predict.h"
111 #include "memmodel.h"
112 #include "tm_p.h"
113 #include "expmed.h"
114 #include "insn-config.h"
115 #include "emit-rtl.h"
116 #include "recog.h"
117 #include "insn-attr.h"
118 #include "resource.h"
119 #include "tree-pass.h"
122 /* First, some functions that were used before GCC got a control flow graph.
123 These functions are now only used here in reorg.c, and have therefore
124 been moved here to avoid inadvertent misuse elsewhere in the compiler. */
126 /* Return the last label to mark the same position as LABEL. Return LABEL
127 itself if it is null or any return rtx. */
129 static rtx
130 skip_consecutive_labels (rtx label_or_return)
132 rtx_insn *insn;
134 if (label_or_return && ANY_RETURN_P (label_or_return))
135 return label_or_return;
137 rtx_insn *label = as_a <rtx_insn *> (label_or_return);
139 /* __builtin_unreachable can create a CODE_LABEL followed by a BARRIER.
141 Since reaching the CODE_LABEL is undefined behavior, we can return
142 any code label and we're OK at runtime.
144 However, if we return a CODE_LABEL which leads to a shrinked wrapped
145 epilogue, but the path does not have a prologue, then we will trip
146 a sanity check in the dwarf2 cfi code which wants to verify that
147 the CFIs are all the same on the traces leading to the epilogue.
149 So we explicitly disallow looking through BARRIERS here. */
150 for (insn = label;
151 insn != 0 && !INSN_P (insn) && !BARRIER_P (insn);
152 insn = NEXT_INSN (insn))
153 if (LABEL_P (insn))
154 label = insn;
156 return label;
159 /* INSN uses CC0 and is being moved into a delay slot. Set up REG_CC_SETTER
160 and REG_CC_USER notes so we can find it. */
162 static void
163 link_cc0_insns (rtx_insn *insn)
165 rtx user = next_nonnote_insn (insn);
167 if (NONJUMP_INSN_P (user) && GET_CODE (PATTERN (user)) == SEQUENCE)
168 user = XVECEXP (PATTERN (user), 0, 0);
170 add_reg_note (user, REG_CC_SETTER, insn);
171 add_reg_note (insn, REG_CC_USER, user);
174 /* Insns which have delay slots that have not yet been filled. */
176 static struct obstack unfilled_slots_obstack;
177 static rtx *unfilled_firstobj;
179 /* Define macros to refer to the first and last slot containing unfilled
180 insns. These are used because the list may move and its address
181 should be recomputed at each use. */
183 #define unfilled_slots_base \
184 ((rtx_insn **) obstack_base (&unfilled_slots_obstack))
186 #define unfilled_slots_next \
187 ((rtx_insn **) obstack_next_free (&unfilled_slots_obstack))
189 /* Points to the label before the end of the function, or before a
190 return insn. */
191 static rtx_code_label *function_return_label;
192 /* Likewise for a simple_return. */
193 static rtx_code_label *function_simple_return_label;
195 /* Mapping between INSN_UID's and position in the code since INSN_UID's do
196 not always monotonically increase. */
197 static int *uid_to_ruid;
199 /* Highest valid index in `uid_to_ruid'. */
200 static int max_uid;
202 static int stop_search_p (rtx_insn *, int);
203 static int resource_conflicts_p (struct resources *, struct resources *);
204 static int insn_references_resource_p (rtx, struct resources *, bool);
205 static int insn_sets_resource_p (rtx, struct resources *, bool);
206 static rtx_code_label *find_end_label (rtx);
207 static rtx_insn *emit_delay_sequence (rtx_insn *, const vec<rtx_insn *> &,
208 int);
209 static void add_to_delay_list (rtx_insn *, vec<rtx_insn *> *);
210 static rtx_insn *delete_from_delay_slot (rtx_insn *);
211 static void delete_scheduled_jump (rtx_insn *);
212 static void note_delay_statistics (int, int);
213 static int get_jump_flags (const rtx_insn *, rtx);
214 static int mostly_true_jump (rtx);
215 static rtx get_branch_condition (const rtx_insn *, rtx);
216 static int condition_dominates_p (rtx, const rtx_insn *);
217 static int redirect_with_delay_slots_safe_p (rtx_insn *, rtx, rtx);
218 static int redirect_with_delay_list_safe_p (rtx_insn *, rtx,
219 const vec<rtx_insn *> &);
220 static int check_annul_list_true_false (int, const vec<rtx_insn *> &);
221 static void steal_delay_list_from_target (rtx_insn *, rtx, rtx_sequence *,
222 vec<rtx_insn *> *,
223 struct resources *,
224 struct resources *,
225 struct resources *,
226 int, int *, int *,
227 rtx *);
228 static void steal_delay_list_from_fallthrough (rtx_insn *, rtx, rtx_sequence *,
229 vec<rtx_insn *> *,
230 struct resources *,
231 struct resources *,
232 struct resources *,
233 int, int *, int *);
234 static void try_merge_delay_insns (rtx_insn *, rtx_insn *);
235 static rtx_insn *redundant_insn (rtx, rtx_insn *, const vec<rtx_insn *> &);
236 static int own_thread_p (rtx, rtx, int);
237 static void update_block (rtx_insn *, rtx_insn *);
238 static int reorg_redirect_jump (rtx_jump_insn *, rtx);
239 static void update_reg_dead_notes (rtx_insn *, rtx_insn *);
240 static void fix_reg_dead_note (rtx_insn *, rtx);
241 static void update_reg_unused_notes (rtx_insn *, rtx);
242 static void fill_simple_delay_slots (int);
243 static void fill_slots_from_thread (rtx_jump_insn *, rtx, rtx, rtx,
244 int, int, int, int,
245 int *, vec<rtx_insn *> *);
246 static void fill_eager_delay_slots (void);
247 static void relax_delay_slots (rtx_insn *);
248 static void make_return_insns (rtx_insn *);
250 /* A wrapper around next_active_insn which takes care to return ret_rtx
251 unchanged. */
253 static rtx
254 first_active_target_insn (rtx insn)
256 if (ANY_RETURN_P (insn))
257 return insn;
258 return next_active_insn (as_a <rtx_insn *> (insn));
261 /* Return true iff INSN is a simplejump, or any kind of return insn. */
263 static bool
264 simplejump_or_return_p (rtx insn)
266 return (JUMP_P (insn)
267 && (simplejump_p (as_a <rtx_insn *> (insn))
268 || ANY_RETURN_P (PATTERN (insn))));
271 /* Return TRUE if this insn should stop the search for insn to fill delay
272 slots. LABELS_P indicates that labels should terminate the search.
273 In all cases, jumps terminate the search. */
275 static int
276 stop_search_p (rtx_insn *insn, int labels_p)
278 if (insn == 0)
279 return 1;
281 /* If the insn can throw an exception that is caught within the function,
282 it may effectively perform a jump from the viewpoint of the function.
283 Therefore act like for a jump. */
284 if (can_throw_internal (insn))
285 return 1;
287 switch (GET_CODE (insn))
289 case NOTE:
290 case CALL_INSN:
291 case DEBUG_INSN:
292 return 0;
294 case CODE_LABEL:
295 return labels_p;
297 case JUMP_INSN:
298 case BARRIER:
299 return 1;
301 case INSN:
302 /* OK unless it contains a delay slot or is an `asm' insn of some type.
303 We don't know anything about these. */
304 return (GET_CODE (PATTERN (insn)) == SEQUENCE
305 || GET_CODE (PATTERN (insn)) == ASM_INPUT
306 || asm_noperands (PATTERN (insn)) >= 0);
308 default:
309 gcc_unreachable ();
313 /* Return TRUE if any resources are marked in both RES1 and RES2 or if either
314 resource set contains a volatile memory reference. Otherwise, return FALSE. */
316 static int
317 resource_conflicts_p (struct resources *res1, struct resources *res2)
319 if ((res1->cc && res2->cc) || (res1->memory && res2->memory)
320 || res1->volatil || res2->volatil)
321 return 1;
323 return hard_reg_set_intersect_p (res1->regs, res2->regs);
326 /* Return TRUE if any resource marked in RES, a `struct resources', is
327 referenced by INSN. If INCLUDE_DELAYED_EFFECTS is set, return if the called
328 routine is using those resources.
330 We compute this by computing all the resources referenced by INSN and
331 seeing if this conflicts with RES. It might be faster to directly check
332 ourselves, and this is the way it used to work, but it means duplicating
333 a large block of complex code. */
335 static int
336 insn_references_resource_p (rtx insn, struct resources *res,
337 bool include_delayed_effects)
339 struct resources insn_res;
341 CLEAR_RESOURCE (&insn_res);
342 mark_referenced_resources (insn, &insn_res, include_delayed_effects);
343 return resource_conflicts_p (&insn_res, res);
346 /* Return TRUE if INSN modifies resources that are marked in RES.
347 INCLUDE_DELAYED_EFFECTS is set if the actions of that routine should be
348 included. CC0 is only modified if it is explicitly set; see comments
349 in front of mark_set_resources for details. */
351 static int
352 insn_sets_resource_p (rtx insn, struct resources *res,
353 bool include_delayed_effects)
355 struct resources insn_sets;
357 CLEAR_RESOURCE (&insn_sets);
358 mark_set_resources (insn, &insn_sets, 0,
359 (include_delayed_effects
360 ? MARK_SRC_DEST_CALL
361 : MARK_SRC_DEST));
362 return resource_conflicts_p (&insn_sets, res);
365 /* Find a label at the end of the function or before a RETURN. If there
366 is none, try to make one. If that fails, returns 0.
368 The property of such a label is that it is placed just before the
369 epilogue or a bare RETURN insn, so that another bare RETURN can be
370 turned into a jump to the label unconditionally. In particular, the
371 label cannot be placed before a RETURN insn with a filled delay slot.
373 ??? There may be a problem with the current implementation. Suppose
374 we start with a bare RETURN insn and call find_end_label. It may set
375 function_return_label just before the RETURN. Suppose the machinery
376 is able to fill the delay slot of the RETURN insn afterwards. Then
377 function_return_label is no longer valid according to the property
378 described above and find_end_label will still return it unmodified.
379 Note that this is probably mitigated by the following observation:
380 once function_return_label is made, it is very likely the target of
381 a jump, so filling the delay slot of the RETURN will be much more
382 difficult.
383 KIND is either simple_return_rtx or ret_rtx, indicating which type of
384 return we're looking for. */
386 static rtx_code_label *
387 find_end_label (rtx kind)
389 rtx_insn *insn;
390 rtx_code_label **plabel;
392 if (kind == ret_rtx)
393 plabel = &function_return_label;
394 else
396 gcc_assert (kind == simple_return_rtx);
397 plabel = &function_simple_return_label;
400 /* If we found one previously, return it. */
401 if (*plabel)
402 return *plabel;
404 /* Otherwise, see if there is a label at the end of the function. If there
405 is, it must be that RETURN insns aren't needed, so that is our return
406 label and we don't have to do anything else. */
408 insn = get_last_insn ();
409 while (NOTE_P (insn)
410 || (NONJUMP_INSN_P (insn)
411 && (GET_CODE (PATTERN (insn)) == USE
412 || GET_CODE (PATTERN (insn)) == CLOBBER)))
413 insn = PREV_INSN (insn);
415 /* When a target threads its epilogue we might already have a
416 suitable return insn. If so put a label before it for the
417 function_return_label. */
418 if (BARRIER_P (insn)
419 && JUMP_P (PREV_INSN (insn))
420 && PATTERN (PREV_INSN (insn)) == kind)
422 rtx_insn *temp = PREV_INSN (PREV_INSN (insn));
423 rtx_code_label *label = gen_label_rtx ();
424 LABEL_NUSES (label) = 0;
426 /* Put the label before any USE insns that may precede the RETURN
427 insn. */
428 while (GET_CODE (temp) == USE)
429 temp = PREV_INSN (temp);
431 emit_label_after (label, temp);
432 *plabel = label;
435 else if (LABEL_P (insn))
436 *plabel = as_a <rtx_code_label *> (insn);
437 else
439 rtx_code_label *label = gen_label_rtx ();
440 LABEL_NUSES (label) = 0;
441 /* If the basic block reorder pass moves the return insn to
442 some other place try to locate it again and put our
443 function_return_label there. */
444 while (insn && ! (JUMP_P (insn) && (PATTERN (insn) == kind)))
445 insn = PREV_INSN (insn);
446 if (insn)
448 insn = PREV_INSN (insn);
450 /* Put the label before any USE insns that may precede the
451 RETURN insn. */
452 while (GET_CODE (insn) == USE)
453 insn = PREV_INSN (insn);
455 emit_label_after (label, insn);
457 else
459 if (targetm.have_epilogue () && ! targetm.have_return ())
460 /* The RETURN insn has its delay slot filled so we cannot
461 emit the label just before it. Since we already have
462 an epilogue and cannot emit a new RETURN, we cannot
463 emit the label at all. */
464 return NULL;
466 /* Otherwise, make a new label and emit a RETURN and BARRIER,
467 if needed. */
468 emit_label (label);
469 if (targetm.have_return ())
471 /* The return we make may have delay slots too. */
472 rtx_insn *pat = targetm.gen_return ();
473 rtx_insn *insn = emit_jump_insn (pat);
474 set_return_jump_label (insn);
475 emit_barrier ();
476 if (num_delay_slots (insn) > 0)
477 obstack_ptr_grow (&unfilled_slots_obstack, insn);
480 *plabel = label;
483 /* Show one additional use for this label so it won't go away until
484 we are done. */
485 ++LABEL_NUSES (*plabel);
487 return *plabel;
490 /* Put INSN and LIST together in a SEQUENCE rtx of LENGTH, and replace
491 the pattern of INSN with the SEQUENCE.
493 Returns the insn containing the SEQUENCE that replaces INSN. */
495 static rtx_insn *
496 emit_delay_sequence (rtx_insn *insn, const vec<rtx_insn *> &list, int length)
498 /* Allocate the rtvec to hold the insns and the SEQUENCE. */
499 rtvec seqv = rtvec_alloc (length + 1);
500 rtx seq = gen_rtx_SEQUENCE (VOIDmode, seqv);
501 rtx_insn *seq_insn = make_insn_raw (seq);
503 /* If DELAY_INSN has a location, use it for SEQ_INSN. If DELAY_INSN does
504 not have a location, but one of the delayed insns does, we pick up a
505 location from there later. */
506 INSN_LOCATION (seq_insn) = INSN_LOCATION (insn);
508 /* Unlink INSN from the insn chain, so that we can put it into
509 the SEQUENCE. Remember where we want to emit SEQUENCE in AFTER. */
510 rtx_insn *after = PREV_INSN (insn);
511 remove_insn (insn);
512 SET_NEXT_INSN (insn) = SET_PREV_INSN (insn) = NULL;
514 /* Build our SEQUENCE and rebuild the insn chain. */
515 start_sequence ();
516 XVECEXP (seq, 0, 0) = emit_insn (insn);
518 unsigned int delay_insns = list.length ();
519 gcc_assert (delay_insns == (unsigned int) length);
520 for (unsigned int i = 0; i < delay_insns; i++)
522 rtx_insn *tem = list[i];
523 rtx note, next;
525 /* Show that this copy of the insn isn't deleted. */
526 tem->set_undeleted ();
528 /* Unlink insn from its original place, and re-emit it into
529 the sequence. */
530 SET_NEXT_INSN (tem) = SET_PREV_INSN (tem) = NULL;
531 XVECEXP (seq, 0, i + 1) = emit_insn (tem);
533 /* SPARC assembler, for instance, emit warning when debug info is output
534 into the delay slot. */
535 if (INSN_LOCATION (tem) && !INSN_LOCATION (seq_insn))
536 INSN_LOCATION (seq_insn) = INSN_LOCATION (tem);
537 INSN_LOCATION (tem) = 0;
539 for (note = REG_NOTES (tem); note; note = next)
541 next = XEXP (note, 1);
542 switch (REG_NOTE_KIND (note))
544 case REG_DEAD:
545 /* Remove any REG_DEAD notes because we can't rely on them now
546 that the insn has been moved. */
547 remove_note (tem, note);
548 break;
550 case REG_LABEL_OPERAND:
551 case REG_LABEL_TARGET:
552 /* Keep the label reference count up to date. */
553 if (LABEL_P (XEXP (note, 0)))
554 LABEL_NUSES (XEXP (note, 0)) ++;
555 break;
557 default:
558 break;
562 end_sequence ();
564 /* Splice our SEQUENCE into the insn stream where INSN used to be. */
565 add_insn_after (seq_insn, after, NULL);
567 return seq_insn;
570 /* Add INSN to DELAY_LIST and return the head of the new list. The list must
571 be in the order in which the insns are to be executed. */
573 static void
574 add_to_delay_list (rtx_insn *insn, vec<rtx_insn *> *delay_list)
576 /* If INSN has its block number recorded, clear it since we may
577 be moving the insn to a new block. */
578 clear_hashed_info_for_insn (insn);
579 delay_list->safe_push (insn);
582 /* Delete INSN from the delay slot of the insn that it is in, which may
583 produce an insn with no delay slots. Return the new insn. */
585 static rtx_insn *
586 delete_from_delay_slot (rtx_insn *insn)
588 rtx_insn *trial, *seq_insn, *prev;
589 rtx_sequence *seq;
590 int i;
591 int had_barrier = 0;
593 /* We first must find the insn containing the SEQUENCE with INSN in its
594 delay slot. Do this by finding an insn, TRIAL, where
595 PREV_INSN (NEXT_INSN (TRIAL)) != TRIAL. */
597 for (trial = insn;
598 PREV_INSN (NEXT_INSN (trial)) == trial;
599 trial = NEXT_INSN (trial))
602 seq_insn = PREV_INSN (NEXT_INSN (trial));
603 seq = as_a <rtx_sequence *> (PATTERN (seq_insn));
605 if (NEXT_INSN (seq_insn) && BARRIER_P (NEXT_INSN (seq_insn)))
606 had_barrier = 1;
608 /* Create a delay list consisting of all the insns other than the one
609 we are deleting (unless we were the only one). */
610 auto_vec<rtx_insn *, 5> delay_list;
611 if (seq->len () > 2)
612 for (i = 1; i < seq->len (); i++)
613 if (seq->insn (i) != insn)
614 add_to_delay_list (seq->insn (i), &delay_list);
616 /* Delete the old SEQUENCE, re-emit the insn that used to have the delay
617 list, and rebuild the delay list if non-empty. */
618 prev = PREV_INSN (seq_insn);
619 trial = seq->insn (0);
620 delete_related_insns (seq_insn);
621 add_insn_after (trial, prev, NULL);
623 /* If there was a barrier after the old SEQUENCE, remit it. */
624 if (had_barrier)
625 emit_barrier_after (trial);
627 /* If there are any delay insns, remit them. Otherwise clear the
628 annul flag. */
629 if (!delay_list.is_empty ())
630 trial = emit_delay_sequence (trial, delay_list, XVECLEN (seq, 0) - 2);
631 else if (JUMP_P (trial))
632 INSN_ANNULLED_BRANCH_P (trial) = 0;
634 INSN_FROM_TARGET_P (insn) = 0;
636 /* Show we need to fill this insn again. */
637 obstack_ptr_grow (&unfilled_slots_obstack, trial);
639 return trial;
642 /* Delete INSN, a JUMP_INSN. If it is a conditional jump, we must track down
643 the insn that sets CC0 for it and delete it too. */
645 static void
646 delete_scheduled_jump (rtx_insn *insn)
648 /* Delete the insn that sets cc0 for us. On machines without cc0, we could
649 delete the insn that sets the condition code, but it is hard to find it.
650 Since this case is rare anyway, don't bother trying; there would likely
651 be other insns that became dead anyway, which we wouldn't know to
652 delete. */
654 if (HAVE_cc0 && reg_mentioned_p (cc0_rtx, insn))
656 rtx note = find_reg_note (insn, REG_CC_SETTER, NULL_RTX);
658 /* If a reg-note was found, it points to an insn to set CC0. This
659 insn is in the delay list of some other insn. So delete it from
660 the delay list it was in. */
661 if (note)
663 if (! FIND_REG_INC_NOTE (XEXP (note, 0), NULL_RTX)
664 && sets_cc0_p (PATTERN (XEXP (note, 0))) == 1)
665 delete_from_delay_slot (as_a <rtx_insn *> (XEXP (note, 0)));
667 else
669 /* The insn setting CC0 is our previous insn, but it may be in
670 a delay slot. It will be the last insn in the delay slot, if
671 it is. */
672 rtx_insn *trial = previous_insn (insn);
673 if (NOTE_P (trial))
674 trial = prev_nonnote_insn (trial);
675 if (sets_cc0_p (PATTERN (trial)) != 1
676 || FIND_REG_INC_NOTE (trial, NULL_RTX))
677 return;
678 if (PREV_INSN (NEXT_INSN (trial)) == trial)
679 delete_related_insns (trial);
680 else
681 delete_from_delay_slot (trial);
685 delete_related_insns (insn);
688 /* Counters for delay-slot filling. */
690 #define NUM_REORG_FUNCTIONS 2
691 #define MAX_DELAY_HISTOGRAM 3
692 #define MAX_REORG_PASSES 2
694 static int num_insns_needing_delays[NUM_REORG_FUNCTIONS][MAX_REORG_PASSES];
696 static int num_filled_delays[NUM_REORG_FUNCTIONS][MAX_DELAY_HISTOGRAM+1][MAX_REORG_PASSES];
698 static int reorg_pass_number;
700 static void
701 note_delay_statistics (int slots_filled, int index)
703 num_insns_needing_delays[index][reorg_pass_number]++;
704 if (slots_filled > MAX_DELAY_HISTOGRAM)
705 slots_filled = MAX_DELAY_HISTOGRAM;
706 num_filled_delays[index][slots_filled][reorg_pass_number]++;
709 /* Optimize the following cases:
711 1. When a conditional branch skips over only one instruction,
712 use an annulling branch and put that insn in the delay slot.
713 Use either a branch that annuls when the condition if true or
714 invert the test with a branch that annuls when the condition is
715 false. This saves insns, since otherwise we must copy an insn
716 from the L1 target.
718 (orig) (skip) (otherwise)
719 Bcc.n L1 Bcc',a L1 Bcc,a L1'
720 insn insn insn2
721 L1: L1: L1:
722 insn2 insn2 insn2
723 insn3 insn3 L1':
724 insn3
726 2. When a conditional branch skips over only one instruction,
727 and after that, it unconditionally branches somewhere else,
728 perform the similar optimization. This saves executing the
729 second branch in the case where the inverted condition is true.
731 Bcc.n L1 Bcc',a L2
732 insn insn
733 L1: L1:
734 Bra L2 Bra L2
736 INSN is a JUMP_INSN.
738 This should be expanded to skip over N insns, where N is the number
739 of delay slots required. */
741 static void
742 optimize_skip (rtx_jump_insn *insn, vec<rtx_insn *> *delay_list)
744 rtx_insn *trial = next_nonnote_insn (insn);
745 rtx_insn *next_trial = next_active_insn (trial);
746 int flags;
748 flags = get_jump_flags (insn, JUMP_LABEL (insn));
750 if (trial == 0
751 || !NONJUMP_INSN_P (trial)
752 || GET_CODE (PATTERN (trial)) == SEQUENCE
753 || recog_memoized (trial) < 0
754 || (! eligible_for_annul_false (insn, 0, trial, flags)
755 && ! eligible_for_annul_true (insn, 0, trial, flags))
756 || RTX_FRAME_RELATED_P (trial)
757 || can_throw_internal (trial))
758 return;
760 /* There are two cases where we are just executing one insn (we assume
761 here that a branch requires only one insn; this should be generalized
762 at some point): Where the branch goes around a single insn or where
763 we have one insn followed by a branch to the same label we branch to.
764 In both of these cases, inverting the jump and annulling the delay
765 slot give the same effect in fewer insns. */
766 if (next_trial == next_active_insn (JUMP_LABEL_AS_INSN (insn))
767 || (next_trial != 0
768 && simplejump_or_return_p (next_trial)
769 && JUMP_LABEL (insn) == JUMP_LABEL (next_trial)))
771 if (eligible_for_annul_false (insn, 0, trial, flags))
773 if (invert_jump (insn, JUMP_LABEL (insn), 1))
774 INSN_FROM_TARGET_P (trial) = 1;
775 else if (! eligible_for_annul_true (insn, 0, trial, flags))
776 return;
779 add_to_delay_list (trial, delay_list);
780 next_trial = next_active_insn (trial);
781 update_block (trial, trial);
782 delete_related_insns (trial);
784 /* Also, if we are targeting an unconditional
785 branch, thread our jump to the target of that branch. Don't
786 change this into a RETURN here, because it may not accept what
787 we have in the delay slot. We'll fix this up later. */
788 if (next_trial && simplejump_or_return_p (next_trial))
790 rtx target_label = JUMP_LABEL (next_trial);
791 if (ANY_RETURN_P (target_label))
792 target_label = find_end_label (target_label);
794 if (target_label)
796 /* Recompute the flags based on TARGET_LABEL since threading
797 the jump to TARGET_LABEL may change the direction of the
798 jump (which may change the circumstances in which the
799 delay slot is nullified). */
800 flags = get_jump_flags (insn, target_label);
801 if (eligible_for_annul_true (insn, 0, trial, flags))
802 reorg_redirect_jump (insn, target_label);
806 INSN_ANNULLED_BRANCH_P (insn) = 1;
810 /* Encode and return branch direction and prediction information for
811 INSN assuming it will jump to LABEL.
813 Non conditional branches return no direction information and
814 are predicted as very likely taken. */
816 static int
817 get_jump_flags (const rtx_insn *insn, rtx label)
819 int flags;
821 /* get_jump_flags can be passed any insn with delay slots, these may
822 be INSNs, CALL_INSNs, or JUMP_INSNs. Only JUMP_INSNs have branch
823 direction information, and only if they are conditional jumps.
825 If LABEL is a return, then there is no way to determine the branch
826 direction. */
827 if (JUMP_P (insn)
828 && (condjump_p (insn) || condjump_in_parallel_p (insn))
829 && !ANY_RETURN_P (label)
830 && INSN_UID (insn) <= max_uid
831 && INSN_UID (label) <= max_uid)
832 flags
833 = (uid_to_ruid[INSN_UID (label)] > uid_to_ruid[INSN_UID (insn)])
834 ? ATTR_FLAG_forward : ATTR_FLAG_backward;
835 /* No valid direction information. */
836 else
837 flags = 0;
839 return flags;
842 /* Return truth value of the statement that this branch
843 is mostly taken. If we think that the branch is extremely likely
844 to be taken, we return 2. If the branch is slightly more likely to be
845 taken, return 1. If the branch is slightly less likely to be taken,
846 return 0 and if the branch is highly unlikely to be taken, return -1. */
848 static int
849 mostly_true_jump (rtx jump_insn)
851 /* If branch probabilities are available, then use that number since it
852 always gives a correct answer. */
853 rtx note = find_reg_note (jump_insn, REG_BR_PROB, 0);
854 if (note)
856 int prob = profile_probability::from_reg_br_prob_note (XINT (note, 0))
857 .to_reg_br_prob_base ();
859 if (prob >= REG_BR_PROB_BASE * 9 / 10)
860 return 2;
861 else if (prob >= REG_BR_PROB_BASE / 2)
862 return 1;
863 else if (prob >= REG_BR_PROB_BASE / 10)
864 return 0;
865 else
866 return -1;
869 /* If there is no note, assume branches are not taken.
870 This should be rare. */
871 return 0;
874 /* Return the condition under which INSN will branch to TARGET. If TARGET
875 is zero, return the condition under which INSN will return. If INSN is
876 an unconditional branch, return const_true_rtx. If INSN isn't a simple
877 type of jump, or it doesn't go to TARGET, return 0. */
879 static rtx
880 get_branch_condition (const rtx_insn *insn, rtx target)
882 rtx pat = PATTERN (insn);
883 rtx src;
885 if (condjump_in_parallel_p (insn))
886 pat = XVECEXP (pat, 0, 0);
888 if (ANY_RETURN_P (pat) && pat == target)
889 return const_true_rtx;
891 if (GET_CODE (pat) != SET || SET_DEST (pat) != pc_rtx)
892 return 0;
894 src = SET_SRC (pat);
895 if (GET_CODE (src) == LABEL_REF && label_ref_label (src) == target)
896 return const_true_rtx;
898 else if (GET_CODE (src) == IF_THEN_ELSE
899 && XEXP (src, 2) == pc_rtx
900 && ((GET_CODE (XEXP (src, 1)) == LABEL_REF
901 && label_ref_label (XEXP (src, 1)) == target)
902 || (ANY_RETURN_P (XEXP (src, 1)) && XEXP (src, 1) == target)))
903 return XEXP (src, 0);
905 else if (GET_CODE (src) == IF_THEN_ELSE
906 && XEXP (src, 1) == pc_rtx
907 && ((GET_CODE (XEXP (src, 2)) == LABEL_REF
908 && label_ref_label (XEXP (src, 2)) == target)
909 || (ANY_RETURN_P (XEXP (src, 2)) && XEXP (src, 2) == target)))
911 enum rtx_code rev;
912 rev = reversed_comparison_code (XEXP (src, 0), insn);
913 if (rev != UNKNOWN)
914 return gen_rtx_fmt_ee (rev, GET_MODE (XEXP (src, 0)),
915 XEXP (XEXP (src, 0), 0),
916 XEXP (XEXP (src, 0), 1));
919 return 0;
922 /* Return nonzero if CONDITION is more strict than the condition of
923 INSN, i.e., if INSN will always branch if CONDITION is true. */
925 static int
926 condition_dominates_p (rtx condition, const rtx_insn *insn)
928 rtx other_condition = get_branch_condition (insn, JUMP_LABEL (insn));
929 enum rtx_code code = GET_CODE (condition);
930 enum rtx_code other_code;
932 if (rtx_equal_p (condition, other_condition)
933 || other_condition == const_true_rtx)
934 return 1;
936 else if (condition == const_true_rtx || other_condition == 0)
937 return 0;
939 other_code = GET_CODE (other_condition);
940 if (GET_RTX_LENGTH (code) != 2 || GET_RTX_LENGTH (other_code) != 2
941 || ! rtx_equal_p (XEXP (condition, 0), XEXP (other_condition, 0))
942 || ! rtx_equal_p (XEXP (condition, 1), XEXP (other_condition, 1)))
943 return 0;
945 return comparison_dominates_p (code, other_code);
948 /* Return nonzero if redirecting JUMP to NEWLABEL does not invalidate
949 any insns already in the delay slot of JUMP. */
951 static int
952 redirect_with_delay_slots_safe_p (rtx_insn *jump, rtx newlabel, rtx seq)
954 int flags, i;
955 rtx_sequence *pat = as_a <rtx_sequence *> (PATTERN (seq));
957 /* Make sure all the delay slots of this jump would still
958 be valid after threading the jump. If they are still
959 valid, then return nonzero. */
961 flags = get_jump_flags (jump, newlabel);
962 for (i = 1; i < pat->len (); i++)
963 if (! (
964 #if ANNUL_IFFALSE_SLOTS
965 (INSN_ANNULLED_BRANCH_P (jump)
966 && INSN_FROM_TARGET_P (pat->insn (i)))
967 ? eligible_for_annul_false (jump, i - 1, pat->insn (i), flags) :
968 #endif
969 #if ANNUL_IFTRUE_SLOTS
970 (INSN_ANNULLED_BRANCH_P (jump)
971 && ! INSN_FROM_TARGET_P (XVECEXP (pat, 0, i)))
972 ? eligible_for_annul_true (jump, i - 1, pat->insn (i), flags) :
973 #endif
974 eligible_for_delay (jump, i - 1, pat->insn (i), flags)))
975 break;
977 return (i == pat->len ());
980 /* Return nonzero if redirecting JUMP to NEWLABEL does not invalidate
981 any insns we wish to place in the delay slot of JUMP. */
983 static int
984 redirect_with_delay_list_safe_p (rtx_insn *jump, rtx newlabel,
985 const vec<rtx_insn *> &delay_list)
987 /* Make sure all the insns in DELAY_LIST would still be
988 valid after threading the jump. If they are still
989 valid, then return nonzero. */
991 int flags = get_jump_flags (jump, newlabel);
992 unsigned int delay_insns = delay_list.length ();
993 unsigned int i = 0;
994 for (; i < delay_insns; i++)
995 if (! (
996 #if ANNUL_IFFALSE_SLOTS
997 (INSN_ANNULLED_BRANCH_P (jump)
998 && INSN_FROM_TARGET_P (delay_list[i]))
999 ? eligible_for_annul_false (jump, i, delay_list[i], flags) :
1000 #endif
1001 #if ANNUL_IFTRUE_SLOTS
1002 (INSN_ANNULLED_BRANCH_P (jump)
1003 && ! INSN_FROM_TARGET_P (delay_list[i]))
1004 ? eligible_for_annul_true (jump, i, delay_list[i], flags) :
1005 #endif
1006 eligible_for_delay (jump, i, delay_list[i], flags)))
1007 break;
1009 return i == delay_insns;
1012 /* DELAY_LIST is a list of insns that have already been placed into delay
1013 slots. See if all of them have the same annulling status as ANNUL_TRUE_P.
1014 If not, return 0; otherwise return 1. */
1016 static int
1017 check_annul_list_true_false (int annul_true_p,
1018 const vec<rtx_insn *> &delay_list)
1020 rtx_insn *trial;
1021 unsigned int i;
1022 FOR_EACH_VEC_ELT (delay_list, i, trial)
1023 if ((annul_true_p && INSN_FROM_TARGET_P (trial))
1024 || (!annul_true_p && !INSN_FROM_TARGET_P (trial)))
1025 return 0;
1027 return 1;
1030 /* INSN branches to an insn whose pattern SEQ is a SEQUENCE. Given that
1031 the condition tested by INSN is CONDITION and the resources shown in
1032 OTHER_NEEDED are needed after INSN, see whether INSN can take all the insns
1033 from SEQ's delay list, in addition to whatever insns it may execute
1034 (in DELAY_LIST). SETS and NEEDED are denote resources already set and
1035 needed while searching for delay slot insns. Return the concatenated
1036 delay list if possible, otherwise, return 0.
1038 SLOTS_TO_FILL is the total number of slots required by INSN, and
1039 PSLOTS_FILLED points to the number filled so far (also the number of
1040 insns in DELAY_LIST). It is updated with the number that have been
1041 filled from the SEQUENCE, if any.
1043 PANNUL_P points to a nonzero value if we already know that we need
1044 to annul INSN. If this routine determines that annulling is needed,
1045 it may set that value nonzero.
1047 PNEW_THREAD points to a location that is to receive the place at which
1048 execution should continue. */
1050 static void
1051 steal_delay_list_from_target (rtx_insn *insn, rtx condition, rtx_sequence *seq,
1052 vec<rtx_insn *> *delay_list,
1053 struct resources *sets,
1054 struct resources *needed,
1055 struct resources *other_needed,
1056 int slots_to_fill, int *pslots_filled,
1057 int *pannul_p, rtx *pnew_thread)
1059 int slots_remaining = slots_to_fill - *pslots_filled;
1060 int total_slots_filled = *pslots_filled;
1061 auto_vec<rtx_insn *, 5> new_delay_list;
1062 int must_annul = *pannul_p;
1063 int used_annul = 0;
1064 int i;
1065 struct resources cc_set;
1066 rtx_insn **redundant;
1068 /* We can't do anything if there are more delay slots in SEQ than we
1069 can handle, or if we don't know that it will be a taken branch.
1070 We know that it will be a taken branch if it is either an unconditional
1071 branch or a conditional branch with a stricter branch condition.
1073 Also, exit if the branch has more than one set, since then it is computing
1074 other results that can't be ignored, e.g. the HPPA mov&branch instruction.
1075 ??? It may be possible to move other sets into INSN in addition to
1076 moving the instructions in the delay slots.
1078 We cannot steal the delay list if one of the instructions in the
1079 current delay_list modifies the condition codes and the jump in the
1080 sequence is a conditional jump. We cannot do this because we cannot
1081 change the direction of the jump because the condition codes
1082 will effect the direction of the jump in the sequence. */
1084 CLEAR_RESOURCE (&cc_set);
1086 rtx_insn *trial;
1087 FOR_EACH_VEC_ELT (*delay_list, i, trial)
1089 mark_set_resources (trial, &cc_set, 0, MARK_SRC_DEST_CALL);
1090 if (insn_references_resource_p (seq->insn (0), &cc_set, false))
1091 return;
1094 if (XVECLEN (seq, 0) - 1 > slots_remaining
1095 || ! condition_dominates_p (condition, seq->insn (0))
1096 || ! single_set (seq->insn (0)))
1097 return;
1099 /* On some targets, branches with delay slots can have a limited
1100 displacement. Give the back end a chance to tell us we can't do
1101 this. */
1102 if (! targetm.can_follow_jump (insn, seq->insn (0)))
1103 return;
1105 redundant = XALLOCAVEC (rtx_insn *, XVECLEN (seq, 0));
1106 for (i = 1; i < seq->len (); i++)
1108 rtx_insn *trial = seq->insn (i);
1109 int flags;
1111 if (insn_references_resource_p (trial, sets, false)
1112 || insn_sets_resource_p (trial, needed, false)
1113 || insn_sets_resource_p (trial, sets, false)
1114 /* If TRIAL sets CC0, we can't copy it, so we can't steal this
1115 delay list. */
1116 || (HAVE_cc0 && find_reg_note (trial, REG_CC_USER, NULL_RTX))
1117 /* If TRIAL is from the fallthrough code of an annulled branch insn
1118 in SEQ, we cannot use it. */
1119 || (INSN_ANNULLED_BRANCH_P (seq->insn (0))
1120 && ! INSN_FROM_TARGET_P (trial)))
1121 return;
1123 /* If this insn was already done (usually in a previous delay slot),
1124 pretend we put it in our delay slot. */
1125 redundant[i] = redundant_insn (trial, insn, new_delay_list);
1126 if (redundant[i])
1127 continue;
1129 /* We will end up re-vectoring this branch, so compute flags
1130 based on jumping to the new label. */
1131 flags = get_jump_flags (insn, JUMP_LABEL (seq->insn (0)));
1133 if (! must_annul
1134 && ((condition == const_true_rtx
1135 || (! insn_sets_resource_p (trial, other_needed, false)
1136 && ! may_trap_or_fault_p (PATTERN (trial)))))
1137 ? eligible_for_delay (insn, total_slots_filled, trial, flags)
1138 : (must_annul || (delay_list->is_empty () && new_delay_list.is_empty ()))
1139 && (must_annul = 1,
1140 check_annul_list_true_false (0, *delay_list)
1141 && check_annul_list_true_false (0, new_delay_list)
1142 && eligible_for_annul_false (insn, total_slots_filled,
1143 trial, flags)))
1145 if (must_annul)
1147 /* Frame related instructions cannot go into annulled delay
1148 slots, it messes up the dwarf info. */
1149 if (RTX_FRAME_RELATED_P (trial))
1150 return;
1151 used_annul = 1;
1153 rtx_insn *temp = copy_delay_slot_insn (trial);
1154 INSN_FROM_TARGET_P (temp) = 1;
1155 add_to_delay_list (temp, &new_delay_list);
1156 total_slots_filled++;
1158 if (--slots_remaining == 0)
1159 break;
1161 else
1162 return;
1165 /* Record the effect of the instructions that were redundant and which
1166 we therefore decided not to copy. */
1167 for (i = 1; i < seq->len (); i++)
1168 if (redundant[i])
1170 fix_reg_dead_note (redundant[i], insn);
1171 update_block (seq->insn (i), insn);
1174 /* Show the place to which we will be branching. */
1175 *pnew_thread = first_active_target_insn (JUMP_LABEL (seq->insn (0)));
1177 /* Add any new insns to the delay list and update the count of the
1178 number of slots filled. */
1179 *pslots_filled = total_slots_filled;
1180 if (used_annul)
1181 *pannul_p = 1;
1183 rtx_insn *temp;
1184 FOR_EACH_VEC_ELT (new_delay_list, i, temp)
1185 add_to_delay_list (temp, delay_list);
1188 /* Similar to steal_delay_list_from_target except that SEQ is on the
1189 fallthrough path of INSN. Here we only do something if the delay insn
1190 of SEQ is an unconditional branch. In that case we steal its delay slot
1191 for INSN since unconditional branches are much easier to fill. */
1193 static void
1194 steal_delay_list_from_fallthrough (rtx_insn *insn, rtx condition,
1195 rtx_sequence *seq,
1196 vec<rtx_insn *> *delay_list,
1197 struct resources *sets,
1198 struct resources *needed,
1199 struct resources *other_needed,
1200 int slots_to_fill, int *pslots_filled,
1201 int *pannul_p)
1203 int i;
1204 int flags;
1205 int must_annul = *pannul_p;
1206 int used_annul = 0;
1208 flags = get_jump_flags (insn, JUMP_LABEL (insn));
1210 /* We can't do anything if SEQ's delay insn isn't an
1211 unconditional branch. */
1213 if (! simplejump_or_return_p (seq->insn (0)))
1214 return;
1216 for (i = 1; i < seq->len (); i++)
1218 rtx_insn *trial = seq->insn (i);
1219 rtx_insn *prior_insn;
1221 /* If TRIAL sets CC0, stealing it will move it too far from the use
1222 of CC0. */
1223 if (insn_references_resource_p (trial, sets, false)
1224 || insn_sets_resource_p (trial, needed, false)
1225 || insn_sets_resource_p (trial, sets, false)
1226 || (HAVE_cc0 && sets_cc0_p (PATTERN (trial))))
1228 break;
1230 /* If this insn was already done, we don't need it. */
1231 if ((prior_insn = redundant_insn (trial, insn, *delay_list)))
1233 fix_reg_dead_note (prior_insn, insn);
1234 update_block (trial, insn);
1235 delete_from_delay_slot (trial);
1236 continue;
1239 if (! must_annul
1240 && ((condition == const_true_rtx
1241 || (! insn_sets_resource_p (trial, other_needed, false)
1242 && ! may_trap_or_fault_p (PATTERN (trial)))))
1243 ? eligible_for_delay (insn, *pslots_filled, trial, flags)
1244 : (must_annul || delay_list->is_empty ()) && (must_annul = 1,
1245 check_annul_list_true_false (1, *delay_list)
1246 && eligible_for_annul_true (insn, *pslots_filled, trial, flags)))
1248 if (must_annul)
1249 used_annul = 1;
1250 delete_from_delay_slot (trial);
1251 add_to_delay_list (trial, delay_list);
1253 if (++(*pslots_filled) == slots_to_fill)
1254 break;
1256 else
1257 break;
1260 if (used_annul)
1261 *pannul_p = 1;
1264 /* Try merging insns starting at THREAD which match exactly the insns in
1265 INSN's delay list.
1267 If all insns were matched and the insn was previously annulling, the
1268 annul bit will be cleared.
1270 For each insn that is merged, if the branch is or will be non-annulling,
1271 we delete the merged insn. */
1273 static void
1274 try_merge_delay_insns (rtx_insn *insn, rtx_insn *thread)
1276 rtx_insn *trial, *next_trial;
1277 rtx_insn *delay_insn = as_a <rtx_insn *> (XVECEXP (PATTERN (insn), 0, 0));
1278 int annul_p = JUMP_P (delay_insn) && INSN_ANNULLED_BRANCH_P (delay_insn);
1279 int slot_number = 1;
1280 int num_slots = XVECLEN (PATTERN (insn), 0);
1281 rtx next_to_match = XVECEXP (PATTERN (insn), 0, slot_number);
1282 struct resources set, needed, modified;
1283 auto_vec<std::pair<rtx_insn *, bool>, 10> merged_insns;
1284 int flags;
1286 flags = get_jump_flags (delay_insn, JUMP_LABEL (delay_insn));
1288 CLEAR_RESOURCE (&needed);
1289 CLEAR_RESOURCE (&set);
1291 /* If this is not an annulling branch, take into account anything needed in
1292 INSN's delay slot. This prevents two increments from being incorrectly
1293 folded into one. If we are annulling, this would be the correct
1294 thing to do. (The alternative, looking at things set in NEXT_TO_MATCH
1295 will essentially disable this optimization. This method is somewhat of
1296 a kludge, but I don't see a better way.) */
1297 if (! annul_p)
1298 for (int i = 1; i < num_slots; i++)
1299 if (XVECEXP (PATTERN (insn), 0, i))
1300 mark_referenced_resources (XVECEXP (PATTERN (insn), 0, i), &needed,
1301 true);
1303 for (trial = thread; !stop_search_p (trial, 1); trial = next_trial)
1305 rtx pat = PATTERN (trial);
1306 rtx oldtrial = trial;
1308 next_trial = next_nonnote_insn (trial);
1310 /* TRIAL must be a CALL_INSN or INSN. Skip USE and CLOBBER. */
1311 if (NONJUMP_INSN_P (trial)
1312 && (GET_CODE (pat) == USE || GET_CODE (pat) == CLOBBER))
1313 continue;
1315 if (GET_CODE (next_to_match) == GET_CODE (trial)
1316 /* We can't share an insn that sets cc0. */
1317 && (!HAVE_cc0 || ! sets_cc0_p (pat))
1318 && ! insn_references_resource_p (trial, &set, true)
1319 && ! insn_sets_resource_p (trial, &set, true)
1320 && ! insn_sets_resource_p (trial, &needed, true)
1321 && (trial = try_split (pat, trial, 0)) != 0
1322 /* Update next_trial, in case try_split succeeded. */
1323 && (next_trial = next_nonnote_insn (trial))
1324 /* Likewise THREAD. */
1325 && (thread = oldtrial == thread ? trial : thread)
1326 && rtx_equal_p (PATTERN (next_to_match), PATTERN (trial))
1327 /* Have to test this condition if annul condition is different
1328 from (and less restrictive than) non-annulling one. */
1329 && eligible_for_delay (delay_insn, slot_number - 1, trial, flags))
1332 if (! annul_p)
1334 update_block (trial, thread);
1335 if (trial == thread)
1336 thread = next_active_insn (thread);
1338 delete_related_insns (trial);
1339 INSN_FROM_TARGET_P (next_to_match) = 0;
1341 else
1342 merged_insns.safe_push (std::pair<rtx_insn *, bool> (trial, false));
1344 if (++slot_number == num_slots)
1345 break;
1347 next_to_match = XVECEXP (PATTERN (insn), 0, slot_number);
1350 mark_set_resources (trial, &set, 0, MARK_SRC_DEST_CALL);
1351 mark_referenced_resources (trial, &needed, true);
1354 /* See if we stopped on a filled insn. If we did, try to see if its
1355 delay slots match. */
1356 if (slot_number != num_slots
1357 && trial && NONJUMP_INSN_P (trial)
1358 && GET_CODE (PATTERN (trial)) == SEQUENCE
1359 && !(JUMP_P (XVECEXP (PATTERN (trial), 0, 0))
1360 && INSN_ANNULLED_BRANCH_P (XVECEXP (PATTERN (trial), 0, 0))))
1362 rtx_sequence *pat = as_a <rtx_sequence *> (PATTERN (trial));
1363 rtx filled_insn = XVECEXP (pat, 0, 0);
1365 /* Account for resources set/needed by the filled insn. */
1366 mark_set_resources (filled_insn, &set, 0, MARK_SRC_DEST_CALL);
1367 mark_referenced_resources (filled_insn, &needed, true);
1369 for (int i = 1; i < pat->len (); i++)
1371 rtx_insn *dtrial = pat->insn (i);
1373 CLEAR_RESOURCE (&modified);
1374 /* Account for resources set by the insn following NEXT_TO_MATCH
1375 inside INSN's delay list. */
1376 for (int j = 1; slot_number + j < num_slots; j++)
1377 mark_set_resources (XVECEXP (PATTERN (insn), 0, slot_number + j),
1378 &modified, 0, MARK_SRC_DEST_CALL);
1379 /* Account for resources set by the insn before DTRIAL and inside
1380 TRIAL's delay list. */
1381 for (int j = 1; j < i; j++)
1382 mark_set_resources (XVECEXP (pat, 0, j),
1383 &modified, 0, MARK_SRC_DEST_CALL);
1384 if (! insn_references_resource_p (dtrial, &set, true)
1385 && ! insn_sets_resource_p (dtrial, &set, true)
1386 && ! insn_sets_resource_p (dtrial, &needed, true)
1387 && (!HAVE_cc0 || ! sets_cc0_p (PATTERN (dtrial)))
1388 && rtx_equal_p (PATTERN (next_to_match), PATTERN (dtrial))
1389 /* Check that DTRIAL and NEXT_TO_MATCH does not reference a
1390 resource modified between them (only dtrial is checked because
1391 next_to_match and dtrial shall to be equal in order to hit
1392 this line) */
1393 && ! insn_references_resource_p (dtrial, &modified, true)
1394 && eligible_for_delay (delay_insn, slot_number - 1, dtrial, flags))
1396 if (! annul_p)
1398 rtx_insn *new_rtx;
1400 update_block (dtrial, thread);
1401 new_rtx = delete_from_delay_slot (dtrial);
1402 if (thread->deleted ())
1403 thread = new_rtx;
1404 INSN_FROM_TARGET_P (next_to_match) = 0;
1406 else
1407 merged_insns.safe_push (std::pair<rtx_insn *, bool> (dtrial,
1408 true));
1410 if (++slot_number == num_slots)
1411 break;
1413 next_to_match = XVECEXP (PATTERN (insn), 0, slot_number);
1415 else
1417 /* Keep track of the set/referenced resources for the delay
1418 slots of any trial insns we encounter. */
1419 mark_set_resources (dtrial, &set, 0, MARK_SRC_DEST_CALL);
1420 mark_referenced_resources (dtrial, &needed, true);
1425 /* If all insns in the delay slot have been matched and we were previously
1426 annulling the branch, we need not any more. In that case delete all the
1427 merged insns. Also clear the INSN_FROM_TARGET_P bit of each insn in
1428 the delay list so that we know that it isn't only being used at the
1429 target. */
1430 if (slot_number == num_slots && annul_p)
1432 unsigned int len = merged_insns.length ();
1433 for (unsigned int i = len - 1; i < len; i--)
1434 if (merged_insns[i].second)
1436 update_block (merged_insns[i].first, thread);
1437 rtx_insn *new_rtx = delete_from_delay_slot (merged_insns[i].first);
1438 if (thread->deleted ())
1439 thread = new_rtx;
1441 else
1443 update_block (merged_insns[i].first, thread);
1444 delete_related_insns (merged_insns[i].first);
1447 INSN_ANNULLED_BRANCH_P (delay_insn) = 0;
1449 for (int i = 0; i < XVECLEN (PATTERN (insn), 0); i++)
1450 INSN_FROM_TARGET_P (XVECEXP (PATTERN (insn), 0, i)) = 0;
1454 /* See if INSN is redundant with an insn in front of TARGET. Often this
1455 is called when INSN is a candidate for a delay slot of TARGET.
1456 DELAY_LIST are insns that will be placed in delay slots of TARGET in front
1457 of INSN. Often INSN will be redundant with an insn in a delay slot of
1458 some previous insn. This happens when we have a series of branches to the
1459 same label; in that case the first insn at the target might want to go
1460 into each of the delay slots.
1462 If we are not careful, this routine can take up a significant fraction
1463 of the total compilation time (4%), but only wins rarely. Hence we
1464 speed this routine up by making two passes. The first pass goes back
1465 until it hits a label and sees if it finds an insn with an identical
1466 pattern. Only in this (relatively rare) event does it check for
1467 data conflicts.
1469 We do not split insns we encounter. This could cause us not to find a
1470 redundant insn, but the cost of splitting seems greater than the possible
1471 gain in rare cases. */
1473 static rtx_insn *
1474 redundant_insn (rtx insn, rtx_insn *target, const vec<rtx_insn *> &delay_list)
1476 rtx target_main = target;
1477 rtx ipat = PATTERN (insn);
1478 rtx_insn *trial;
1479 rtx pat;
1480 struct resources needed, set;
1481 int i;
1482 unsigned insns_to_search;
1484 /* If INSN has any REG_UNUSED notes, it can't match anything since we
1485 are allowed to not actually assign to such a register. */
1486 if (find_reg_note (insn, REG_UNUSED, NULL_RTX) != 0)
1487 return 0;
1489 /* Scan backwards looking for a match. */
1490 for (trial = PREV_INSN (target),
1491 insns_to_search = param_max_delay_slot_insn_search;
1492 trial && insns_to_search > 0;
1493 trial = PREV_INSN (trial))
1495 /* (use (insn))s can come immediately after a barrier if the
1496 label that used to precede them has been deleted as dead.
1497 See delete_related_insns. */
1498 if (LABEL_P (trial) || BARRIER_P (trial))
1499 return 0;
1501 if (!INSN_P (trial))
1502 continue;
1503 --insns_to_search;
1505 pat = PATTERN (trial);
1506 if (GET_CODE (pat) == USE || GET_CODE (pat) == CLOBBER)
1507 continue;
1509 if (GET_CODE (trial) == DEBUG_INSN)
1510 continue;
1512 if (rtx_sequence *seq = dyn_cast <rtx_sequence *> (pat))
1514 /* Stop for a CALL and its delay slots because it is difficult to
1515 track its resource needs correctly. */
1516 if (CALL_P (seq->element (0)))
1517 return 0;
1519 /* Stop for an INSN or JUMP_INSN with delayed effects and its delay
1520 slots because it is difficult to track its resource needs
1521 correctly. */
1523 if (INSN_SETS_ARE_DELAYED (seq->insn (0)))
1524 return 0;
1526 if (INSN_REFERENCES_ARE_DELAYED (seq->insn (0)))
1527 return 0;
1529 /* See if any of the insns in the delay slot match, updating
1530 resource requirements as we go. */
1531 for (i = seq->len () - 1; i > 0; i--)
1532 if (GET_CODE (seq->element (i)) == GET_CODE (insn)
1533 && rtx_equal_p (PATTERN (seq->element (i)), ipat)
1534 && ! find_reg_note (seq->element (i), REG_UNUSED, NULL_RTX))
1535 break;
1537 /* If found a match, exit this loop early. */
1538 if (i > 0)
1539 break;
1542 else if (GET_CODE (trial) == GET_CODE (insn) && rtx_equal_p (pat, ipat)
1543 && ! find_reg_note (trial, REG_UNUSED, NULL_RTX))
1544 break;
1547 /* If we didn't find an insn that matches, return 0. */
1548 if (trial == 0)
1549 return 0;
1551 /* See what resources this insn sets and needs. If they overlap, or
1552 if this insn references CC0, it can't be redundant. */
1554 CLEAR_RESOURCE (&needed);
1555 CLEAR_RESOURCE (&set);
1556 mark_set_resources (insn, &set, 0, MARK_SRC_DEST_CALL);
1557 mark_referenced_resources (insn, &needed, true);
1559 /* If TARGET is a SEQUENCE, get the main insn. */
1560 if (NONJUMP_INSN_P (target) && GET_CODE (PATTERN (target)) == SEQUENCE)
1561 target_main = XVECEXP (PATTERN (target), 0, 0);
1563 if (resource_conflicts_p (&needed, &set)
1564 || (HAVE_cc0 && reg_mentioned_p (cc0_rtx, ipat))
1565 /* The insn requiring the delay may not set anything needed or set by
1566 INSN. */
1567 || insn_sets_resource_p (target_main, &needed, true)
1568 || insn_sets_resource_p (target_main, &set, true))
1569 return 0;
1571 /* Insns we pass may not set either NEEDED or SET, so merge them for
1572 simpler tests. */
1573 needed.memory |= set.memory;
1574 needed.regs |= set.regs;
1576 /* This insn isn't redundant if it conflicts with an insn that either is
1577 or will be in a delay slot of TARGET. */
1579 unsigned int j;
1580 rtx_insn *temp;
1581 FOR_EACH_VEC_ELT (delay_list, j, temp)
1582 if (insn_sets_resource_p (temp, &needed, true))
1583 return 0;
1585 if (NONJUMP_INSN_P (target) && GET_CODE (PATTERN (target)) == SEQUENCE)
1586 for (i = 1; i < XVECLEN (PATTERN (target), 0); i++)
1587 if (insn_sets_resource_p (XVECEXP (PATTERN (target), 0, i), &needed,
1588 true))
1589 return 0;
1591 /* Scan backwards until we reach a label or an insn that uses something
1592 INSN sets or sets something insn uses or sets. */
1594 for (trial = PREV_INSN (target),
1595 insns_to_search = param_max_delay_slot_insn_search;
1596 trial && !LABEL_P (trial) && insns_to_search > 0;
1597 trial = PREV_INSN (trial))
1599 if (!INSN_P (trial))
1600 continue;
1601 --insns_to_search;
1603 pat = PATTERN (trial);
1604 if (GET_CODE (pat) == USE || GET_CODE (pat) == CLOBBER)
1605 continue;
1607 if (GET_CODE (trial) == DEBUG_INSN)
1608 continue;
1610 if (rtx_sequence *seq = dyn_cast <rtx_sequence *> (pat))
1612 bool annul_p = false;
1613 rtx_insn *control = seq->insn (0);
1615 /* If this is a CALL_INSN and its delay slots, it is hard to track
1616 the resource needs properly, so give up. */
1617 if (CALL_P (control))
1618 return 0;
1620 /* If this is an INSN or JUMP_INSN with delayed effects, it
1621 is hard to track the resource needs properly, so give up. */
1623 if (INSN_SETS_ARE_DELAYED (control))
1624 return 0;
1626 if (INSN_REFERENCES_ARE_DELAYED (control))
1627 return 0;
1629 if (JUMP_P (control))
1630 annul_p = INSN_ANNULLED_BRANCH_P (control);
1632 /* See if any of the insns in the delay slot match, updating
1633 resource requirements as we go. */
1634 for (i = seq->len () - 1; i > 0; i--)
1636 rtx_insn *candidate = seq->insn (i);
1638 /* If an insn will be annulled if the branch is false, it isn't
1639 considered as a possible duplicate insn. */
1640 if (rtx_equal_p (PATTERN (candidate), ipat)
1641 && ! (annul_p && INSN_FROM_TARGET_P (candidate)))
1643 /* Show that this insn will be used in the sequel. */
1644 INSN_FROM_TARGET_P (candidate) = 0;
1645 return candidate;
1648 /* Unless this is an annulled insn from the target of a branch,
1649 we must stop if it sets anything needed or set by INSN. */
1650 if ((!annul_p || !INSN_FROM_TARGET_P (candidate))
1651 && insn_sets_resource_p (candidate, &needed, true))
1652 return 0;
1655 /* If the insn requiring the delay slot conflicts with INSN, we
1656 must stop. */
1657 if (insn_sets_resource_p (control, &needed, true))
1658 return 0;
1660 else
1662 /* See if TRIAL is the same as INSN. */
1663 pat = PATTERN (trial);
1664 if (rtx_equal_p (pat, ipat))
1665 return trial;
1667 /* Can't go any further if TRIAL conflicts with INSN. */
1668 if (insn_sets_resource_p (trial, &needed, true))
1669 return 0;
1673 return 0;
1676 /* Return 1 if THREAD can only be executed in one way. If LABEL is nonzero,
1677 it is the target of the branch insn being scanned. If ALLOW_FALLTHROUGH
1678 is nonzero, we are allowed to fall into this thread; otherwise, we are
1679 not.
1681 If LABEL is used more than one or we pass a label other than LABEL before
1682 finding an active insn, we do not own this thread. */
1684 static int
1685 own_thread_p (rtx thread, rtx label, int allow_fallthrough)
1687 rtx_insn *active_insn;
1688 rtx_insn *insn;
1690 /* We don't own the function end. */
1691 if (thread == 0 || ANY_RETURN_P (thread))
1692 return 0;
1694 /* We have a non-NULL insn. */
1695 rtx_insn *thread_insn = as_a <rtx_insn *> (thread);
1697 /* Get the first active insn, or THREAD_INSN, if it is an active insn. */
1698 active_insn = next_active_insn (PREV_INSN (thread_insn));
1700 for (insn = thread_insn; insn != active_insn; insn = NEXT_INSN (insn))
1701 if (LABEL_P (insn)
1702 && (insn != label || LABEL_NUSES (insn) != 1))
1703 return 0;
1705 if (allow_fallthrough)
1706 return 1;
1708 /* Ensure that we reach a BARRIER before any insn or label. */
1709 for (insn = prev_nonnote_insn (thread_insn);
1710 insn == 0 || !BARRIER_P (insn);
1711 insn = prev_nonnote_insn (insn))
1712 if (insn == 0
1713 || LABEL_P (insn)
1714 || (NONJUMP_INSN_P (insn)
1715 && GET_CODE (PATTERN (insn)) != USE
1716 && GET_CODE (PATTERN (insn)) != CLOBBER))
1717 return 0;
1719 return 1;
1722 /* Called when INSN is being moved from a location near the target of a jump.
1723 We leave a marker of the form (use (INSN)) immediately in front of WHERE
1724 for mark_target_live_regs. These markers will be deleted at the end.
1726 We used to try to update the live status of registers if WHERE is at
1727 the start of a basic block, but that can't work since we may remove a
1728 BARRIER in relax_delay_slots. */
1730 static void
1731 update_block (rtx_insn *insn, rtx_insn *where)
1733 emit_insn_before (gen_rtx_USE (VOIDmode, insn), where);
1735 /* INSN might be making a value live in a block where it didn't use to
1736 be. So recompute liveness information for this block. */
1737 incr_ticks_for_insn (insn);
1740 /* Similar to REDIRECT_JUMP except that we update the BB_TICKS entry for
1741 the basic block containing the jump. */
1743 static int
1744 reorg_redirect_jump (rtx_jump_insn *jump, rtx nlabel)
1746 incr_ticks_for_insn (jump);
1747 return redirect_jump (jump, nlabel, 1);
1750 /* Called when INSN is being moved forward into a delay slot of DELAYED_INSN.
1751 We check every instruction between INSN and DELAYED_INSN for REG_DEAD notes
1752 that reference values used in INSN. If we find one, then we move the
1753 REG_DEAD note to INSN.
1755 This is needed to handle the case where a later insn (after INSN) has a
1756 REG_DEAD note for a register used by INSN, and this later insn subsequently
1757 gets moved before a CODE_LABEL because it is a redundant insn. In this
1758 case, mark_target_live_regs may be confused into thinking the register
1759 is dead because it sees a REG_DEAD note immediately before a CODE_LABEL. */
1761 static void
1762 update_reg_dead_notes (rtx_insn *insn, rtx_insn *delayed_insn)
1764 rtx link, next;
1765 rtx_insn *p;
1767 for (p = next_nonnote_insn (insn); p != delayed_insn;
1768 p = next_nonnote_insn (p))
1769 for (link = REG_NOTES (p); link; link = next)
1771 next = XEXP (link, 1);
1773 if (REG_NOTE_KIND (link) != REG_DEAD
1774 || !REG_P (XEXP (link, 0)))
1775 continue;
1777 if (reg_referenced_p (XEXP (link, 0), PATTERN (insn)))
1779 /* Move the REG_DEAD note from P to INSN. */
1780 remove_note (p, link);
1781 XEXP (link, 1) = REG_NOTES (insn);
1782 REG_NOTES (insn) = link;
1787 /* Called when an insn redundant with start_insn is deleted. If there
1788 is a REG_DEAD note for the target of start_insn between start_insn
1789 and stop_insn, then the REG_DEAD note needs to be deleted since the
1790 value no longer dies there.
1792 If the REG_DEAD note isn't deleted, then mark_target_live_regs may be
1793 confused into thinking the register is dead. */
1795 static void
1796 fix_reg_dead_note (rtx_insn *start_insn, rtx stop_insn)
1798 rtx link, next;
1799 rtx_insn *p;
1801 for (p = next_nonnote_insn (start_insn); p != stop_insn;
1802 p = next_nonnote_insn (p))
1803 for (link = REG_NOTES (p); link; link = next)
1805 next = XEXP (link, 1);
1807 if (REG_NOTE_KIND (link) != REG_DEAD
1808 || !REG_P (XEXP (link, 0)))
1809 continue;
1811 if (reg_set_p (XEXP (link, 0), PATTERN (start_insn)))
1813 remove_note (p, link);
1814 return;
1819 /* Delete any REG_UNUSED notes that exist on INSN but not on OTHER_INSN.
1821 This handles the case of udivmodXi4 instructions which optimize their
1822 output depending on whether any REG_UNUSED notes are present. We must
1823 make sure that INSN calculates as many results as OTHER_INSN does. */
1825 static void
1826 update_reg_unused_notes (rtx_insn *insn, rtx other_insn)
1828 rtx link, next;
1830 for (link = REG_NOTES (insn); link; link = next)
1832 next = XEXP (link, 1);
1834 if (REG_NOTE_KIND (link) != REG_UNUSED
1835 || !REG_P (XEXP (link, 0)))
1836 continue;
1838 if (!find_regno_note (other_insn, REG_UNUSED, REGNO (XEXP (link, 0))))
1839 remove_note (insn, link);
1843 static vec <rtx> sibling_labels;
1845 /* Return the label before INSN, or put a new label there. If SIBLING is
1846 non-zero, it is another label associated with the new label (if any),
1847 typically the former target of the jump that will be redirected to
1848 the new label. */
1850 static rtx_insn *
1851 get_label_before (rtx_insn *insn, rtx sibling)
1853 rtx_insn *label;
1855 /* Find an existing label at this point
1856 or make a new one if there is none. */
1857 label = prev_nonnote_insn (insn);
1859 if (label == 0 || !LABEL_P (label))
1861 rtx_insn *prev = PREV_INSN (insn);
1863 label = gen_label_rtx ();
1864 emit_label_after (label, prev);
1865 LABEL_NUSES (label) = 0;
1866 if (sibling)
1868 sibling_labels.safe_push (label);
1869 sibling_labels.safe_push (sibling);
1872 return label;
1875 /* Scan a function looking for insns that need a delay slot and find insns to
1876 put into the delay slot.
1878 NON_JUMPS_P is nonzero if we are to only try to fill non-jump insns (such
1879 as calls). We do these first since we don't want jump insns (that are
1880 easier to fill) to get the only insns that could be used for non-jump insns.
1881 When it is zero, only try to fill JUMP_INSNs.
1883 When slots are filled in this manner, the insns (including the
1884 delay_insn) are put together in a SEQUENCE rtx. In this fashion,
1885 it is possible to tell whether a delay slot has really been filled
1886 or not. `final' knows how to deal with this, by communicating
1887 through FINAL_SEQUENCE. */
1889 static void
1890 fill_simple_delay_slots (int non_jumps_p)
1892 rtx_insn *insn, *trial, *next_trial;
1893 rtx pat;
1894 int i;
1895 int num_unfilled_slots = unfilled_slots_next - unfilled_slots_base;
1896 struct resources needed, set;
1897 int slots_to_fill, slots_filled;
1898 auto_vec<rtx_insn *, 5> delay_list;
1900 for (i = 0; i < num_unfilled_slots; i++)
1902 int flags;
1903 /* Get the next insn to fill. If it has already had any slots assigned,
1904 we can't do anything with it. Maybe we'll improve this later. */
1906 insn = unfilled_slots_base[i];
1907 if (insn == 0
1908 || insn->deleted ()
1909 || (NONJUMP_INSN_P (insn)
1910 && GET_CODE (PATTERN (insn)) == SEQUENCE)
1911 || (JUMP_P (insn) && non_jumps_p)
1912 || (!JUMP_P (insn) && ! non_jumps_p))
1913 continue;
1915 /* It may have been that this insn used to need delay slots, but
1916 now doesn't; ignore in that case. This can happen, for example,
1917 on the HP PA RISC, where the number of delay slots depends on
1918 what insns are nearby. */
1919 slots_to_fill = num_delay_slots (insn);
1921 /* Some machine description have defined instructions to have
1922 delay slots only in certain circumstances which may depend on
1923 nearby insns (which change due to reorg's actions).
1925 For example, the PA port normally has delay slots for unconditional
1926 jumps.
1928 However, the PA port claims such jumps do not have a delay slot
1929 if they are immediate successors of certain CALL_INSNs. This
1930 allows the port to favor filling the delay slot of the call with
1931 the unconditional jump. */
1932 if (slots_to_fill == 0)
1933 continue;
1935 /* This insn needs, or can use, some delay slots. SLOTS_TO_FILL
1936 says how many. After initialization, first try optimizing
1938 call _foo call _foo
1939 nop add %o7,.-L1,%o7
1940 b,a L1
1943 If this case applies, the delay slot of the call is filled with
1944 the unconditional jump. This is done first to avoid having the
1945 delay slot of the call filled in the backward scan. Also, since
1946 the unconditional jump is likely to also have a delay slot, that
1947 insn must exist when it is subsequently scanned.
1949 This is tried on each insn with delay slots as some machines
1950 have insns which perform calls, but are not represented as
1951 CALL_INSNs. */
1953 slots_filled = 0;
1954 delay_list.truncate (0);
1956 if (JUMP_P (insn))
1957 flags = get_jump_flags (insn, JUMP_LABEL (insn));
1958 else
1959 flags = get_jump_flags (insn, NULL_RTX);
1961 if ((trial = next_active_insn (insn))
1962 && JUMP_P (trial)
1963 && simplejump_p (trial)
1964 && eligible_for_delay (insn, slots_filled, trial, flags)
1965 && no_labels_between_p (insn, trial)
1966 && ! can_throw_internal (trial))
1968 rtx_insn **tmp;
1969 slots_filled++;
1970 add_to_delay_list (trial, &delay_list);
1972 /* TRIAL may have had its delay slot filled, then unfilled. When
1973 the delay slot is unfilled, TRIAL is placed back on the unfilled
1974 slots obstack. Unfortunately, it is placed on the end of the
1975 obstack, not in its original location. Therefore, we must search
1976 from entry i + 1 to the end of the unfilled slots obstack to
1977 try and find TRIAL. */
1978 tmp = &unfilled_slots_base[i + 1];
1979 while (*tmp != trial && tmp != unfilled_slots_next)
1980 tmp++;
1982 /* Remove the unconditional jump from consideration for delay slot
1983 filling and unthread it. */
1984 if (*tmp == trial)
1985 *tmp = 0;
1987 rtx_insn *next = NEXT_INSN (trial);
1988 rtx_insn *prev = PREV_INSN (trial);
1989 if (prev)
1990 SET_NEXT_INSN (prev) = next;
1991 if (next)
1992 SET_PREV_INSN (next) = prev;
1996 /* Now, scan backwards from the insn to search for a potential
1997 delay-slot candidate. Stop searching when a label or jump is hit.
1999 For each candidate, if it is to go into the delay slot (moved
2000 forward in execution sequence), it must not need or set any resources
2001 that were set by later insns and must not set any resources that
2002 are needed for those insns.
2004 The delay slot insn itself sets resources unless it is a call
2005 (in which case the called routine, not the insn itself, is doing
2006 the setting). */
2008 if (slots_filled < slots_to_fill)
2010 /* If the flags register is dead after the insn, then we want to be
2011 able to accept a candidate that clobbers it. For this purpose,
2012 we need to filter the flags register during life analysis, so
2013 that it doesn't create RAW and WAW dependencies, while still
2014 creating the necessary WAR dependencies. */
2015 bool filter_flags
2016 = (slots_to_fill == 1
2017 && targetm.flags_regnum != INVALID_REGNUM
2018 && find_regno_note (insn, REG_DEAD, targetm.flags_regnum));
2019 struct resources fset;
2020 CLEAR_RESOURCE (&needed);
2021 CLEAR_RESOURCE (&set);
2022 mark_set_resources (insn, &set, 0, MARK_SRC_DEST);
2023 if (filter_flags)
2025 CLEAR_RESOURCE (&fset);
2026 mark_set_resources (insn, &fset, 0, MARK_SRC_DEST);
2028 mark_referenced_resources (insn, &needed, false);
2030 for (trial = prev_nonnote_insn (insn); ! stop_search_p (trial, 1);
2031 trial = next_trial)
2033 next_trial = prev_nonnote_insn (trial);
2035 /* This must be an INSN or CALL_INSN. */
2036 pat = PATTERN (trial);
2038 /* Stand-alone USE and CLOBBER are just for flow. */
2039 if (GET_CODE (pat) == USE || GET_CODE (pat) == CLOBBER)
2040 continue;
2042 /* And DEBUG_INSNs never go into delay slots. */
2043 if (GET_CODE (trial) == DEBUG_INSN)
2044 continue;
2046 /* Check for resource conflict first, to avoid unnecessary
2047 splitting. */
2048 if (! insn_references_resource_p (trial, &set, true)
2049 && ! insn_sets_resource_p (trial,
2050 filter_flags ? &fset : &set,
2051 true)
2052 && ! insn_sets_resource_p (trial, &needed, true)
2053 /* Can't separate set of cc0 from its use. */
2054 && (!HAVE_cc0 || ! (reg_mentioned_p (cc0_rtx, pat) && ! sets_cc0_p (pat)))
2055 && ! can_throw_internal (trial))
2057 trial = try_split (pat, trial, 1);
2058 next_trial = prev_nonnote_insn (trial);
2059 if (eligible_for_delay (insn, slots_filled, trial, flags))
2061 /* In this case, we are searching backward, so if we
2062 find insns to put on the delay list, we want
2063 to put them at the head, rather than the
2064 tail, of the list. */
2066 update_reg_dead_notes (trial, insn);
2067 delay_list.safe_insert (0, trial);
2068 update_block (trial, trial);
2069 delete_related_insns (trial);
2070 if (slots_to_fill == ++slots_filled)
2071 break;
2072 continue;
2076 mark_set_resources (trial, &set, 0, MARK_SRC_DEST_CALL);
2077 if (filter_flags)
2079 mark_set_resources (trial, &fset, 0, MARK_SRC_DEST_CALL);
2080 /* If the flags register is set, then it doesn't create RAW
2081 dependencies any longer and it also doesn't create WAW
2082 dependencies since it's dead after the original insn. */
2083 if (TEST_HARD_REG_BIT (fset.regs, targetm.flags_regnum))
2085 CLEAR_HARD_REG_BIT (needed.regs, targetm.flags_regnum);
2086 CLEAR_HARD_REG_BIT (fset.regs, targetm.flags_regnum);
2089 mark_referenced_resources (trial, &needed, true);
2093 /* If all needed slots haven't been filled, we come here. */
2095 /* Try to optimize case of jumping around a single insn. */
2096 if ((ANNUL_IFTRUE_SLOTS || ANNUL_IFFALSE_SLOTS)
2097 && slots_filled != slots_to_fill
2098 && delay_list.is_empty ()
2099 && JUMP_P (insn)
2100 && (condjump_p (insn) || condjump_in_parallel_p (insn))
2101 && !ANY_RETURN_P (JUMP_LABEL (insn)))
2103 optimize_skip (as_a <rtx_jump_insn *> (insn), &delay_list);
2104 if (!delay_list.is_empty ())
2105 slots_filled += 1;
2108 /* Try to get insns from beyond the insn needing the delay slot.
2109 These insns can neither set or reference resources set in insns being
2110 skipped, cannot set resources in the insn being skipped, and, if this
2111 is a CALL_INSN (or a CALL_INSN is passed), cannot trap (because the
2112 call might not return).
2114 There used to be code which continued past the target label if
2115 we saw all uses of the target label. This code did not work,
2116 because it failed to account for some instructions which were
2117 both annulled and marked as from the target. This can happen as a
2118 result of optimize_skip. Since this code was redundant with
2119 fill_eager_delay_slots anyways, it was just deleted. */
2121 if (slots_filled != slots_to_fill
2122 /* If this instruction could throw an exception which is
2123 caught in the same function, then it's not safe to fill
2124 the delay slot with an instruction from beyond this
2125 point. For example, consider:
2127 int i = 2;
2129 try {
2130 f();
2131 i = 3;
2132 } catch (...) {}
2134 return i;
2136 Even though `i' is a local variable, we must be sure not
2137 to put `i = 3' in the delay slot if `f' might throw an
2138 exception.
2140 Presumably, we should also check to see if we could get
2141 back to this function via `setjmp'. */
2142 && ! can_throw_internal (insn)
2143 && !JUMP_P (insn))
2145 int maybe_never = 0;
2146 rtx pat, trial_delay;
2148 CLEAR_RESOURCE (&needed);
2149 CLEAR_RESOURCE (&set);
2150 mark_set_resources (insn, &set, 0, MARK_SRC_DEST_CALL);
2151 mark_referenced_resources (insn, &needed, true);
2153 if (CALL_P (insn))
2154 maybe_never = 1;
2156 for (trial = next_nonnote_insn (insn); !stop_search_p (trial, 1);
2157 trial = next_trial)
2159 next_trial = next_nonnote_insn (trial);
2161 /* This must be an INSN or CALL_INSN. */
2162 pat = PATTERN (trial);
2164 /* Stand-alone USE and CLOBBER are just for flow. */
2165 if (GET_CODE (pat) == USE || GET_CODE (pat) == CLOBBER)
2166 continue;
2168 /* And DEBUG_INSNs do not go in delay slots. */
2169 if (GET_CODE (trial) == DEBUG_INSN)
2170 continue;
2172 /* If this already has filled delay slots, get the insn needing
2173 the delay slots. */
2174 if (GET_CODE (pat) == SEQUENCE)
2175 trial_delay = XVECEXP (pat, 0, 0);
2176 else
2177 trial_delay = trial;
2179 /* Stop our search when seeing a jump. */
2180 if (JUMP_P (trial_delay))
2181 break;
2183 /* See if we have a resource problem before we try to split. */
2184 if (GET_CODE (pat) != SEQUENCE
2185 && ! insn_references_resource_p (trial, &set, true)
2186 && ! insn_sets_resource_p (trial, &set, true)
2187 && ! insn_sets_resource_p (trial, &needed, true)
2188 && (!HAVE_cc0 && ! (reg_mentioned_p (cc0_rtx, pat) && ! sets_cc0_p (pat)))
2189 && ! (maybe_never && may_trap_or_fault_p (pat))
2190 && (trial = try_split (pat, trial, 0))
2191 && eligible_for_delay (insn, slots_filled, trial, flags)
2192 && ! can_throw_internal (trial))
2194 next_trial = next_nonnote_insn (trial);
2195 add_to_delay_list (trial, &delay_list);
2196 if (HAVE_cc0 && reg_mentioned_p (cc0_rtx, pat))
2197 link_cc0_insns (trial);
2199 delete_related_insns (trial);
2200 if (slots_to_fill == ++slots_filled)
2201 break;
2202 continue;
2205 mark_set_resources (trial, &set, 0, MARK_SRC_DEST_CALL);
2206 mark_referenced_resources (trial, &needed, true);
2208 /* Ensure we don't put insns between the setting of cc and the
2209 comparison by moving a setting of cc into an earlier delay
2210 slot since these insns could clobber the condition code. */
2211 set.cc = 1;
2213 /* If this is a call, we might not get here. */
2214 if (CALL_P (trial_delay))
2215 maybe_never = 1;
2218 /* If there are slots left to fill and our search was stopped by an
2219 unconditional branch, try the insn at the branch target. We can
2220 redirect the branch if it works.
2222 Don't do this if the insn at the branch target is a branch. */
2223 if (slots_to_fill != slots_filled
2224 && trial
2225 && jump_to_label_p (trial)
2226 && simplejump_p (trial)
2227 && (next_trial = next_active_insn (JUMP_LABEL_AS_INSN (trial))) != 0
2228 && ! (NONJUMP_INSN_P (next_trial)
2229 && GET_CODE (PATTERN (next_trial)) == SEQUENCE)
2230 && !JUMP_P (next_trial)
2231 && ! insn_references_resource_p (next_trial, &set, true)
2232 && ! insn_sets_resource_p (next_trial, &set, true)
2233 && ! insn_sets_resource_p (next_trial, &needed, true)
2234 && (!HAVE_cc0 || ! reg_mentioned_p (cc0_rtx, PATTERN (next_trial)))
2235 && ! (maybe_never && may_trap_or_fault_p (PATTERN (next_trial)))
2236 && (next_trial = try_split (PATTERN (next_trial), next_trial, 0))
2237 && eligible_for_delay (insn, slots_filled, next_trial, flags)
2238 && ! can_throw_internal (trial))
2240 /* See comment in relax_delay_slots about necessity of using
2241 next_real_nondebug_insn here. */
2242 rtx_insn *new_label = next_real_nondebug_insn (next_trial);
2244 if (new_label != 0)
2245 new_label = get_label_before (new_label, JUMP_LABEL (trial));
2246 else
2247 new_label = find_end_label (simple_return_rtx);
2249 if (new_label)
2251 add_to_delay_list (copy_delay_slot_insn (next_trial),
2252 &delay_list);
2253 slots_filled++;
2254 reorg_redirect_jump (as_a <rtx_jump_insn *> (trial),
2255 new_label);
2260 /* If this is an unconditional jump, then try to get insns from the
2261 target of the jump. */
2262 rtx_jump_insn *jump_insn;
2263 if ((jump_insn = dyn_cast <rtx_jump_insn *> (insn))
2264 && simplejump_p (jump_insn)
2265 && slots_filled != slots_to_fill)
2266 fill_slots_from_thread (jump_insn, const_true_rtx,
2267 next_active_insn (JUMP_LABEL_AS_INSN (insn)),
2268 NULL, 1, 1, own_thread_p (JUMP_LABEL (insn),
2269 JUMP_LABEL (insn), 0),
2270 slots_to_fill, &slots_filled, &delay_list);
2272 if (!delay_list.is_empty ())
2273 unfilled_slots_base[i]
2274 = emit_delay_sequence (insn, delay_list, slots_filled);
2276 if (slots_to_fill == slots_filled)
2277 unfilled_slots_base[i] = 0;
2279 note_delay_statistics (slots_filled, 0);
2283 /* Follow any unconditional jump at LABEL, for the purpose of redirecting JUMP;
2284 return the ultimate label reached by any such chain of jumps.
2285 Return a suitable return rtx if the chain ultimately leads to a
2286 return instruction.
2287 If LABEL is not followed by a jump, return LABEL.
2288 If the chain loops or we can't find end, return LABEL,
2289 since that tells caller to avoid changing the insn.
2290 If the returned label is obtained by following a crossing jump,
2291 set *CROSSING to true, otherwise set it to false. */
2293 static rtx
2294 follow_jumps (rtx label, rtx_insn *jump, bool *crossing)
2296 rtx_insn *insn;
2297 rtx_insn *next;
2298 int depth;
2300 *crossing = false;
2301 if (ANY_RETURN_P (label))
2302 return label;
2304 rtx_insn *value = as_a <rtx_insn *> (label);
2306 for (depth = 0;
2307 (depth < 10
2308 && (insn = next_active_insn (value)) != 0
2309 && JUMP_P (insn)
2310 && JUMP_LABEL (insn) != NULL_RTX
2311 && ((any_uncondjump_p (insn) && onlyjump_p (insn))
2312 || ANY_RETURN_P (PATTERN (insn)))
2313 && (next = NEXT_INSN (insn))
2314 && BARRIER_P (next));
2315 depth++)
2317 rtx this_label_or_return = JUMP_LABEL (insn);
2319 /* If we have found a cycle, make the insn jump to itself. */
2320 if (this_label_or_return == label)
2321 return label;
2323 /* Cannot follow returns and cannot look through tablejumps. */
2324 if (ANY_RETURN_P (this_label_or_return))
2325 return this_label_or_return;
2327 rtx_insn *this_label = as_a <rtx_insn *> (this_label_or_return);
2328 if (NEXT_INSN (this_label)
2329 && JUMP_TABLE_DATA_P (NEXT_INSN (this_label)))
2330 break;
2332 if (!targetm.can_follow_jump (jump, insn))
2333 break;
2334 if (!*crossing)
2335 *crossing = CROSSING_JUMP_P (jump);
2336 value = this_label;
2338 if (depth == 10)
2339 return label;
2340 return value;
2343 /* Try to find insns to place in delay slots.
2345 INSN is the jump needing SLOTS_TO_FILL delay slots. It tests CONDITION
2346 or is an unconditional branch if CONDITION is const_true_rtx.
2347 *PSLOTS_FILLED is updated with the number of slots that we have filled.
2349 THREAD is a flow-of-control, either the insns to be executed if the
2350 branch is true or if the branch is false, THREAD_IF_TRUE says which.
2352 OPPOSITE_THREAD is the thread in the opposite direction. It is used
2353 to see if any potential delay slot insns set things needed there.
2355 LIKELY is nonzero if it is extremely likely that the branch will be
2356 taken and THREAD_IF_TRUE is set. This is used for the branch at the
2357 end of a loop back up to the top.
2359 OWN_THREAD is true if we are the only user of the thread, i.e. it is
2360 the target of the jump when we are the only jump going there.
2362 If OWN_THREAD is false, it must be the "true" thread of a jump. In that
2363 case, we can only take insns from the head of the thread for our delay
2364 slot. We then adjust the jump to point after the insns we have taken. */
2366 static void
2367 fill_slots_from_thread (rtx_jump_insn *insn, rtx condition,
2368 rtx thread_or_return, rtx opposite_thread, int likely,
2369 int thread_if_true, int own_thread, int slots_to_fill,
2370 int *pslots_filled, vec<rtx_insn *> *delay_list)
2372 rtx new_thread;
2373 struct resources opposite_needed, set, needed;
2374 rtx_insn *trial;
2375 int lose = 0;
2376 int must_annul = 0;
2377 int flags;
2379 /* Validate our arguments. */
2380 gcc_assert (condition != const_true_rtx || thread_if_true);
2381 gcc_assert (own_thread || thread_if_true);
2383 flags = get_jump_flags (insn, JUMP_LABEL (insn));
2385 /* If our thread is the end of subroutine, we can't get any delay
2386 insns from that. */
2387 if (thread_or_return == NULL_RTX || ANY_RETURN_P (thread_or_return))
2388 return;
2390 rtx_insn *thread = as_a <rtx_insn *> (thread_or_return);
2392 /* If this is an unconditional branch, nothing is needed at the
2393 opposite thread. Otherwise, compute what is needed there. */
2394 if (condition == const_true_rtx)
2395 CLEAR_RESOURCE (&opposite_needed);
2396 else
2397 mark_target_live_regs (get_insns (), opposite_thread, &opposite_needed);
2399 /* If the insn at THREAD can be split, do it here to avoid having to
2400 update THREAD and NEW_THREAD if it is done in the loop below. Also
2401 initialize NEW_THREAD. */
2403 new_thread = thread = try_split (PATTERN (thread), thread, 0);
2405 /* Scan insns at THREAD. We are looking for an insn that can be removed
2406 from THREAD (it neither sets nor references resources that were set
2407 ahead of it and it doesn't set anything needs by the insns ahead of
2408 it) and that either can be placed in an annulling insn or aren't
2409 needed at OPPOSITE_THREAD. */
2411 CLEAR_RESOURCE (&needed);
2412 CLEAR_RESOURCE (&set);
2414 /* If we do not own this thread, we must stop as soon as we find
2415 something that we can't put in a delay slot, since all we can do
2416 is branch into THREAD at a later point. Therefore, labels stop
2417 the search if this is not the `true' thread. */
2419 for (trial = thread;
2420 ! stop_search_p (trial, ! thread_if_true) && (! lose || own_thread);
2421 trial = next_nonnote_insn (trial))
2423 rtx pat, old_trial;
2425 /* If we have passed a label, we no longer own this thread. */
2426 if (LABEL_P (trial))
2428 own_thread = 0;
2429 continue;
2432 pat = PATTERN (trial);
2433 if (GET_CODE (pat) == USE || GET_CODE (pat) == CLOBBER)
2434 continue;
2436 if (GET_CODE (trial) == DEBUG_INSN)
2437 continue;
2439 /* If TRIAL conflicts with the insns ahead of it, we lose. Also,
2440 don't separate or copy insns that set and use CC0. */
2441 if (! insn_references_resource_p (trial, &set, true)
2442 && ! insn_sets_resource_p (trial, &set, true)
2443 && ! insn_sets_resource_p (trial, &needed, true)
2444 && (!HAVE_cc0 || (! (reg_mentioned_p (cc0_rtx, pat)
2445 && (! own_thread || ! sets_cc0_p (pat)))))
2446 && ! can_throw_internal (trial))
2448 rtx_insn *prior_insn;
2450 /* If TRIAL is redundant with some insn before INSN, we don't
2451 actually need to add it to the delay list; we can merely pretend
2452 we did. */
2453 if ((prior_insn = redundant_insn (trial, insn, *delay_list)))
2455 fix_reg_dead_note (prior_insn, insn);
2456 if (own_thread)
2458 update_block (trial, thread);
2459 if (trial == thread)
2461 thread = next_active_insn (thread);
2462 if (new_thread == trial)
2463 new_thread = thread;
2466 delete_related_insns (trial);
2468 else
2470 update_reg_unused_notes (prior_insn, trial);
2471 new_thread = next_active_insn (trial);
2474 continue;
2477 /* There are two ways we can win: If TRIAL doesn't set anything
2478 needed at the opposite thread and can't trap, or if it can
2479 go into an annulled delay slot. But we want neither to copy
2480 nor to speculate frame-related insns. */
2481 if (!must_annul
2482 && ((condition == const_true_rtx
2483 && (own_thread || !RTX_FRAME_RELATED_P (trial)))
2484 || (! insn_sets_resource_p (trial, &opposite_needed, true)
2485 && ! may_trap_or_fault_p (pat)
2486 && ! RTX_FRAME_RELATED_P (trial))))
2488 old_trial = trial;
2489 trial = try_split (pat, trial, 0);
2490 if (new_thread == old_trial)
2491 new_thread = trial;
2492 if (thread == old_trial)
2493 thread = trial;
2494 pat = PATTERN (trial);
2495 if (eligible_for_delay (insn, *pslots_filled, trial, flags))
2496 goto winner;
2498 else if (!RTX_FRAME_RELATED_P (trial)
2499 && ((ANNUL_IFTRUE_SLOTS && ! thread_if_true)
2500 || (ANNUL_IFFALSE_SLOTS && thread_if_true)))
2502 old_trial = trial;
2503 trial = try_split (pat, trial, 0);
2504 if (new_thread == old_trial)
2505 new_thread = trial;
2506 if (thread == old_trial)
2507 thread = trial;
2508 pat = PATTERN (trial);
2509 if ((must_annul || delay_list->is_empty ()) && (thread_if_true
2510 ? check_annul_list_true_false (0, *delay_list)
2511 && eligible_for_annul_false (insn, *pslots_filled, trial, flags)
2512 : check_annul_list_true_false (1, *delay_list)
2513 && eligible_for_annul_true (insn, *pslots_filled, trial, flags)))
2515 rtx_insn *temp;
2517 must_annul = 1;
2518 winner:
2520 if (HAVE_cc0 && reg_mentioned_p (cc0_rtx, pat))
2521 link_cc0_insns (trial);
2523 /* If we own this thread, delete the insn. If this is the
2524 destination of a branch, show that a basic block status
2525 may have been updated. In any case, mark the new
2526 starting point of this thread. */
2527 if (own_thread)
2529 rtx note;
2531 update_block (trial, thread);
2532 if (trial == thread)
2534 thread = next_active_insn (thread);
2535 if (new_thread == trial)
2536 new_thread = thread;
2539 /* We are moving this insn, not deleting it. We must
2540 temporarily increment the use count on any referenced
2541 label lest it be deleted by delete_related_insns. */
2542 for (note = REG_NOTES (trial);
2543 note != NULL_RTX;
2544 note = XEXP (note, 1))
2545 if (REG_NOTE_KIND (note) == REG_LABEL_OPERAND
2546 || REG_NOTE_KIND (note) == REG_LABEL_TARGET)
2548 /* REG_LABEL_OPERAND could be
2549 NOTE_INSN_DELETED_LABEL too. */
2550 if (LABEL_P (XEXP (note, 0)))
2551 LABEL_NUSES (XEXP (note, 0))++;
2552 else
2553 gcc_assert (REG_NOTE_KIND (note)
2554 == REG_LABEL_OPERAND);
2556 if (jump_to_label_p (trial))
2557 LABEL_NUSES (JUMP_LABEL (trial))++;
2559 delete_related_insns (trial);
2561 for (note = REG_NOTES (trial);
2562 note != NULL_RTX;
2563 note = XEXP (note, 1))
2564 if (REG_NOTE_KIND (note) == REG_LABEL_OPERAND
2565 || REG_NOTE_KIND (note) == REG_LABEL_TARGET)
2567 /* REG_LABEL_OPERAND could be
2568 NOTE_INSN_DELETED_LABEL too. */
2569 if (LABEL_P (XEXP (note, 0)))
2570 LABEL_NUSES (XEXP (note, 0))--;
2571 else
2572 gcc_assert (REG_NOTE_KIND (note)
2573 == REG_LABEL_OPERAND);
2575 if (jump_to_label_p (trial))
2576 LABEL_NUSES (JUMP_LABEL (trial))--;
2578 else
2579 new_thread = next_active_insn (trial);
2581 temp = own_thread ? trial : copy_delay_slot_insn (trial);
2582 if (thread_if_true)
2583 INSN_FROM_TARGET_P (temp) = 1;
2585 add_to_delay_list (temp, delay_list);
2587 if (slots_to_fill == ++(*pslots_filled))
2589 /* Even though we have filled all the slots, we
2590 may be branching to a location that has a
2591 redundant insn. Skip any if so. */
2592 while (new_thread && ! own_thread
2593 && ! insn_sets_resource_p (new_thread, &set, true)
2594 && ! insn_sets_resource_p (new_thread, &needed,
2595 true)
2596 && ! insn_references_resource_p (new_thread,
2597 &set, true)
2598 && (prior_insn
2599 = redundant_insn (new_thread, insn,
2600 *delay_list)))
2602 /* We know we do not own the thread, so no need
2603 to call update_block and delete_insn. */
2604 fix_reg_dead_note (prior_insn, insn);
2605 update_reg_unused_notes (prior_insn, new_thread);
2606 new_thread
2607 = next_active_insn (as_a<rtx_insn *> (new_thread));
2609 break;
2612 continue;
2617 /* This insn can't go into a delay slot. */
2618 lose = 1;
2619 mark_set_resources (trial, &set, 0, MARK_SRC_DEST_CALL);
2620 mark_referenced_resources (trial, &needed, true);
2622 /* Ensure we don't put insns between the setting of cc and the comparison
2623 by moving a setting of cc into an earlier delay slot since these insns
2624 could clobber the condition code. */
2625 set.cc = 1;
2627 /* If this insn is a register-register copy and the next insn has
2628 a use of our destination, change it to use our source. That way,
2629 it will become a candidate for our delay slot the next time
2630 through this loop. This case occurs commonly in loops that
2631 scan a list.
2633 We could check for more complex cases than those tested below,
2634 but it doesn't seem worth it. It might also be a good idea to try
2635 to swap the two insns. That might do better.
2637 We can't do this if the next insn modifies our destination, because
2638 that would make the replacement into the insn invalid. We also can't
2639 do this if it modifies our source, because it might be an earlyclobber
2640 operand. This latter test also prevents updating the contents of
2641 a PRE_INC. We also can't do this if there's overlap of source and
2642 destination. Overlap may happen for larger-than-register-size modes. */
2644 if (NONJUMP_INSN_P (trial) && GET_CODE (pat) == SET
2645 && REG_P (SET_SRC (pat))
2646 && REG_P (SET_DEST (pat))
2647 && !reg_overlap_mentioned_p (SET_DEST (pat), SET_SRC (pat)))
2649 rtx_insn *next = next_nonnote_insn (trial);
2651 if (next && NONJUMP_INSN_P (next)
2652 && GET_CODE (PATTERN (next)) != USE
2653 && ! reg_set_p (SET_DEST (pat), next)
2654 && ! reg_set_p (SET_SRC (pat), next)
2655 && reg_referenced_p (SET_DEST (pat), PATTERN (next))
2656 && ! modified_in_p (SET_DEST (pat), next))
2657 validate_replace_rtx (SET_DEST (pat), SET_SRC (pat), next);
2661 /* If we stopped on a branch insn that has delay slots, see if we can
2662 steal some of the insns in those slots. */
2663 if (trial && NONJUMP_INSN_P (trial)
2664 && GET_CODE (PATTERN (trial)) == SEQUENCE
2665 && JUMP_P (XVECEXP (PATTERN (trial), 0, 0)))
2667 rtx_sequence *sequence = as_a <rtx_sequence *> (PATTERN (trial));
2668 /* If this is the `true' thread, we will want to follow the jump,
2669 so we can only do this if we have taken everything up to here. */
2670 if (thread_if_true && trial == new_thread)
2672 steal_delay_list_from_target (insn, condition, sequence,
2673 delay_list, &set, &needed,
2674 &opposite_needed, slots_to_fill,
2675 pslots_filled, &must_annul,
2676 &new_thread);
2677 /* If we owned the thread and are told that it branched
2678 elsewhere, make sure we own the thread at the new location. */
2679 if (own_thread && trial != new_thread)
2680 own_thread = own_thread_p (new_thread, new_thread, 0);
2682 else if (! thread_if_true)
2683 steal_delay_list_from_fallthrough (insn, condition, sequence,
2684 delay_list, &set, &needed,
2685 &opposite_needed, slots_to_fill,
2686 pslots_filled, &must_annul);
2689 /* If we haven't found anything for this delay slot and it is very
2690 likely that the branch will be taken, see if the insn at our target
2691 increments or decrements a register with an increment that does not
2692 depend on the destination register. If so, try to place the opposite
2693 arithmetic insn after the jump insn and put the arithmetic insn in the
2694 delay slot. If we can't do this, return. */
2695 if (delay_list->is_empty () && likely
2696 && new_thread && !ANY_RETURN_P (new_thread)
2697 && NONJUMP_INSN_P (new_thread)
2698 && !RTX_FRAME_RELATED_P (new_thread)
2699 && GET_CODE (PATTERN (new_thread)) != ASM_INPUT
2700 && asm_noperands (PATTERN (new_thread)) < 0)
2702 rtx dest;
2703 rtx src;
2705 /* We know "new_thread" is an insn due to NONJUMP_INSN_P (new_thread)
2706 above. */
2707 trial = as_a <rtx_insn *> (new_thread);
2708 rtx pat = PATTERN (trial);
2710 if (!NONJUMP_INSN_P (trial)
2711 || GET_CODE (pat) != SET
2712 || ! eligible_for_delay (insn, 0, trial, flags)
2713 || can_throw_internal (trial))
2714 return;
2716 dest = SET_DEST (pat), src = SET_SRC (pat);
2717 if ((GET_CODE (src) == PLUS || GET_CODE (src) == MINUS)
2718 && rtx_equal_p (XEXP (src, 0), dest)
2719 && (!FLOAT_MODE_P (GET_MODE (src))
2720 || flag_unsafe_math_optimizations)
2721 && ! reg_overlap_mentioned_p (dest, XEXP (src, 1))
2722 && ! side_effects_p (pat))
2724 rtx other = XEXP (src, 1);
2725 rtx new_arith;
2726 rtx_insn *ninsn;
2728 /* If this is a constant adjustment, use the same code with
2729 the negated constant. Otherwise, reverse the sense of the
2730 arithmetic. */
2731 if (CONST_INT_P (other))
2732 new_arith = gen_rtx_fmt_ee (GET_CODE (src), GET_MODE (src), dest,
2733 negate_rtx (GET_MODE (src), other));
2734 else
2735 new_arith = gen_rtx_fmt_ee (GET_CODE (src) == PLUS ? MINUS : PLUS,
2736 GET_MODE (src), dest, other);
2738 ninsn = emit_insn_after (gen_rtx_SET (dest, new_arith), insn);
2740 if (recog_memoized (ninsn) < 0
2741 || (extract_insn (ninsn),
2742 !constrain_operands (1, get_preferred_alternatives (ninsn))))
2744 delete_related_insns (ninsn);
2745 return;
2748 if (own_thread)
2750 update_block (trial, thread);
2751 if (trial == thread)
2753 thread = next_active_insn (thread);
2754 if (new_thread == trial)
2755 new_thread = thread;
2757 delete_related_insns (trial);
2759 else
2760 new_thread = next_active_insn (trial);
2762 ninsn = own_thread ? trial : copy_delay_slot_insn (trial);
2763 if (thread_if_true)
2764 INSN_FROM_TARGET_P (ninsn) = 1;
2766 add_to_delay_list (ninsn, delay_list);
2767 (*pslots_filled)++;
2771 if (!delay_list->is_empty () && must_annul)
2772 INSN_ANNULLED_BRANCH_P (insn) = 1;
2774 /* If we are to branch into the middle of this thread, find an appropriate
2775 label or make a new one if none, and redirect INSN to it. If we hit the
2776 end of the function, use the end-of-function label. */
2777 if (new_thread != thread)
2779 rtx label;
2780 bool crossing = false;
2782 gcc_assert (thread_if_true);
2784 if (new_thread && simplejump_or_return_p (new_thread)
2785 && redirect_with_delay_list_safe_p (insn,
2786 JUMP_LABEL (new_thread),
2787 *delay_list))
2788 new_thread = follow_jumps (JUMP_LABEL (new_thread), insn,
2789 &crossing);
2791 if (ANY_RETURN_P (new_thread))
2792 label = find_end_label (new_thread);
2793 else if (LABEL_P (new_thread))
2794 label = new_thread;
2795 else
2796 label = get_label_before (as_a <rtx_insn *> (new_thread),
2797 JUMP_LABEL (insn));
2799 if (label)
2801 reorg_redirect_jump (insn, label);
2802 if (crossing)
2803 CROSSING_JUMP_P (insn) = 1;
2808 /* Make another attempt to find insns to place in delay slots.
2810 We previously looked for insns located in front of the delay insn
2811 and, for non-jump delay insns, located behind the delay insn.
2813 Here only try to schedule jump insns and try to move insns from either
2814 the target or the following insns into the delay slot. If annulling is
2815 supported, we will be likely to do this. Otherwise, we can do this only
2816 if safe. */
2818 static void
2819 fill_eager_delay_slots (void)
2821 rtx_insn *insn;
2822 int i;
2823 int num_unfilled_slots = unfilled_slots_next - unfilled_slots_base;
2825 for (i = 0; i < num_unfilled_slots; i++)
2827 rtx condition;
2828 rtx target_label, insn_at_target;
2829 rtx_insn *fallthrough_insn;
2830 auto_vec<rtx_insn *, 5> delay_list;
2831 rtx_jump_insn *jump_insn;
2832 int own_target;
2833 int own_fallthrough;
2834 int prediction, slots_to_fill, slots_filled;
2836 insn = unfilled_slots_base[i];
2837 if (insn == 0
2838 || insn->deleted ()
2839 || ! (jump_insn = dyn_cast <rtx_jump_insn *> (insn))
2840 || ! (condjump_p (jump_insn) || condjump_in_parallel_p (jump_insn)))
2841 continue;
2843 slots_to_fill = num_delay_slots (jump_insn);
2844 /* Some machine description have defined instructions to have
2845 delay slots only in certain circumstances which may depend on
2846 nearby insns (which change due to reorg's actions).
2848 For example, the PA port normally has delay slots for unconditional
2849 jumps.
2851 However, the PA port claims such jumps do not have a delay slot
2852 if they are immediate successors of certain CALL_INSNs. This
2853 allows the port to favor filling the delay slot of the call with
2854 the unconditional jump. */
2855 if (slots_to_fill == 0)
2856 continue;
2858 slots_filled = 0;
2859 target_label = JUMP_LABEL (jump_insn);
2860 condition = get_branch_condition (jump_insn, target_label);
2862 if (condition == 0)
2863 continue;
2865 /* Get the next active fallthrough and target insns and see if we own
2866 them. Then see whether the branch is likely true. We don't need
2867 to do a lot of this for unconditional branches. */
2869 insn_at_target = first_active_target_insn (target_label);
2870 own_target = own_thread_p (target_label, target_label, 0);
2872 if (condition == const_true_rtx)
2874 own_fallthrough = 0;
2875 fallthrough_insn = 0;
2876 prediction = 2;
2878 else
2880 fallthrough_insn = next_active_insn (jump_insn);
2881 own_fallthrough = own_thread_p (NEXT_INSN (jump_insn), NULL_RTX, 1);
2882 prediction = mostly_true_jump (jump_insn);
2885 /* If this insn is expected to branch, first try to get insns from our
2886 target, then our fallthrough insns. If it is not expected to branch,
2887 try the other order. */
2889 if (prediction > 0)
2891 fill_slots_from_thread (jump_insn, condition, insn_at_target,
2892 fallthrough_insn, prediction == 2, 1,
2893 own_target,
2894 slots_to_fill, &slots_filled, &delay_list);
2896 if (delay_list.is_empty () && own_fallthrough)
2898 /* Even though we didn't find anything for delay slots,
2899 we might have found a redundant insn which we deleted
2900 from the thread that was filled. So we have to recompute
2901 the next insn at the target. */
2902 target_label = JUMP_LABEL (jump_insn);
2903 insn_at_target = first_active_target_insn (target_label);
2905 fill_slots_from_thread (jump_insn, condition, fallthrough_insn,
2906 insn_at_target, 0, 0, own_fallthrough,
2907 slots_to_fill, &slots_filled,
2908 &delay_list);
2911 else
2913 if (own_fallthrough)
2914 fill_slots_from_thread (jump_insn, condition, fallthrough_insn,
2915 insn_at_target, 0, 0, own_fallthrough,
2916 slots_to_fill, &slots_filled, &delay_list);
2918 if (delay_list.is_empty ())
2919 fill_slots_from_thread (jump_insn, condition, insn_at_target,
2920 next_active_insn (insn), 0, 1, own_target,
2921 slots_to_fill, &slots_filled, &delay_list);
2924 if (!delay_list.is_empty ())
2925 unfilled_slots_base[i]
2926 = emit_delay_sequence (jump_insn, delay_list, slots_filled);
2928 if (slots_to_fill == slots_filled)
2929 unfilled_slots_base[i] = 0;
2931 note_delay_statistics (slots_filled, 1);
2935 static void delete_computation (rtx_insn *insn);
2937 /* Recursively delete prior insns that compute the value (used only by INSN
2938 which the caller is deleting) stored in the register mentioned by NOTE
2939 which is a REG_DEAD note associated with INSN. */
2941 static void
2942 delete_prior_computation (rtx note, rtx_insn *insn)
2944 rtx_insn *our_prev;
2945 rtx reg = XEXP (note, 0);
2947 for (our_prev = prev_nonnote_insn (insn);
2948 our_prev && (NONJUMP_INSN_P (our_prev)
2949 || CALL_P (our_prev));
2950 our_prev = prev_nonnote_insn (our_prev))
2952 rtx pat = PATTERN (our_prev);
2954 /* If we reach a CALL which is not calling a const function
2955 or the callee pops the arguments, then give up. */
2956 if (CALL_P (our_prev)
2957 && (! RTL_CONST_CALL_P (our_prev)
2958 || GET_CODE (pat) != SET || GET_CODE (SET_SRC (pat)) != CALL))
2959 break;
2961 /* If we reach a SEQUENCE, it is too complex to try to
2962 do anything with it, so give up. We can be run during
2963 and after reorg, so SEQUENCE rtl can legitimately show
2964 up here. */
2965 if (GET_CODE (pat) == SEQUENCE)
2966 break;
2968 if (GET_CODE (pat) == USE
2969 && NONJUMP_INSN_P (XEXP (pat, 0)))
2970 /* reorg creates USEs that look like this. We leave them
2971 alone because reorg needs them for its own purposes. */
2972 break;
2974 if (reg_set_p (reg, pat))
2976 if (side_effects_p (pat) && !CALL_P (our_prev))
2977 break;
2979 if (GET_CODE (pat) == PARALLEL)
2981 /* If we find a SET of something else, we can't
2982 delete the insn. */
2984 int i;
2986 for (i = 0; i < XVECLEN (pat, 0); i++)
2988 rtx part = XVECEXP (pat, 0, i);
2990 if (GET_CODE (part) == SET
2991 && SET_DEST (part) != reg)
2992 break;
2995 if (i == XVECLEN (pat, 0))
2996 delete_computation (our_prev);
2998 else if (GET_CODE (pat) == SET
2999 && REG_P (SET_DEST (pat)))
3001 int dest_regno = REGNO (SET_DEST (pat));
3002 int dest_endregno = END_REGNO (SET_DEST (pat));
3003 int regno = REGNO (reg);
3004 int endregno = END_REGNO (reg);
3006 if (dest_regno >= regno
3007 && dest_endregno <= endregno)
3008 delete_computation (our_prev);
3010 /* We may have a multi-word hard register and some, but not
3011 all, of the words of the register are needed in subsequent
3012 insns. Write REG_UNUSED notes for those parts that were not
3013 needed. */
3014 else if (dest_regno <= regno
3015 && dest_endregno >= endregno)
3017 int i;
3019 add_reg_note (our_prev, REG_UNUSED, reg);
3021 for (i = dest_regno; i < dest_endregno; i++)
3022 if (! find_regno_note (our_prev, REG_UNUSED, i))
3023 break;
3025 if (i == dest_endregno)
3026 delete_computation (our_prev);
3030 break;
3033 /* If PAT references the register that dies here, it is an
3034 additional use. Hence any prior SET isn't dead. However, this
3035 insn becomes the new place for the REG_DEAD note. */
3036 if (reg_overlap_mentioned_p (reg, pat))
3038 XEXP (note, 1) = REG_NOTES (our_prev);
3039 REG_NOTES (our_prev) = note;
3040 break;
3045 /* Delete INSN and recursively delete insns that compute values used only
3046 by INSN. This uses the REG_DEAD notes computed during flow analysis.
3048 Look at all our REG_DEAD notes. If a previous insn does nothing other
3049 than set a register that dies in this insn, we can delete that insn
3050 as well.
3052 On machines with CC0, if CC0 is used in this insn, we may be able to
3053 delete the insn that set it. */
3055 static void
3056 delete_computation (rtx_insn *insn)
3058 rtx note, next;
3060 if (HAVE_cc0 && reg_referenced_p (cc0_rtx, PATTERN (insn)))
3062 rtx_insn *prev = prev_nonnote_insn (insn);
3063 /* We assume that at this stage
3064 CC's are always set explicitly
3065 and always immediately before the jump that
3066 will use them. So if the previous insn
3067 exists to set the CC's, delete it
3068 (unless it performs auto-increments, etc.). */
3069 if (prev && NONJUMP_INSN_P (prev)
3070 && sets_cc0_p (PATTERN (prev)))
3072 if (sets_cc0_p (PATTERN (prev)) > 0
3073 && ! side_effects_p (PATTERN (prev)))
3074 delete_computation (prev);
3075 else
3076 /* Otherwise, show that cc0 won't be used. */
3077 add_reg_note (prev, REG_UNUSED, cc0_rtx);
3081 for (note = REG_NOTES (insn); note; note = next)
3083 next = XEXP (note, 1);
3085 if (REG_NOTE_KIND (note) != REG_DEAD
3086 /* Verify that the REG_NOTE is legitimate. */
3087 || !REG_P (XEXP (note, 0)))
3088 continue;
3090 delete_prior_computation (note, insn);
3093 delete_related_insns (insn);
3096 /* If all INSN does is set the pc, delete it,
3097 and delete the insn that set the condition codes for it
3098 if that's what the previous thing was. */
3100 static void
3101 delete_jump (rtx_insn *insn)
3103 rtx set = single_set (insn);
3105 if (set && GET_CODE (SET_DEST (set)) == PC)
3106 delete_computation (insn);
3109 static rtx_insn *
3110 label_before_next_insn (rtx_insn *x, rtx scan_limit)
3112 rtx_insn *insn = next_active_insn (x);
3113 while (insn)
3115 insn = PREV_INSN (insn);
3116 if (insn == scan_limit || insn == NULL_RTX)
3117 return NULL;
3118 if (LABEL_P (insn))
3119 break;
3121 return insn;
3124 /* Return TRUE if there is a NOTE_INSN_SWITCH_TEXT_SECTIONS note in between
3125 BEG and END. */
3127 static bool
3128 switch_text_sections_between_p (const rtx_insn *beg, const rtx_insn *end)
3130 const rtx_insn *p;
3131 for (p = beg; p != end; p = NEXT_INSN (p))
3132 if (NOTE_P (p) && NOTE_KIND (p) == NOTE_INSN_SWITCH_TEXT_SECTIONS)
3133 return true;
3134 return false;
3138 /* Once we have tried two ways to fill a delay slot, make a pass over the
3139 code to try to improve the results and to do such things as more jump
3140 threading. */
3142 static void
3143 relax_delay_slots (rtx_insn *first)
3145 rtx_insn *insn, *next;
3146 rtx_sequence *pat;
3147 rtx_insn *delay_insn;
3148 rtx target_label;
3150 /* Look at every JUMP_INSN and see if we can improve it. */
3151 for (insn = first; insn; insn = next)
3153 rtx_insn *other, *prior_insn;
3154 bool crossing;
3156 next = next_active_insn (insn);
3158 /* If this is a jump insn, see if it now jumps to a jump, jumps to
3159 the next insn, or jumps to a label that is not the last of a
3160 group of consecutive labels. */
3161 if (is_a <rtx_jump_insn *> (insn)
3162 && (condjump_p (insn) || condjump_in_parallel_p (insn))
3163 && !ANY_RETURN_P (target_label = JUMP_LABEL (insn)))
3165 rtx_jump_insn *jump_insn = as_a <rtx_jump_insn *> (insn);
3166 target_label
3167 = skip_consecutive_labels (follow_jumps (target_label, jump_insn,
3168 &crossing));
3169 if (ANY_RETURN_P (target_label))
3170 target_label = find_end_label (target_label);
3172 if (target_label
3173 && next_active_insn (as_a<rtx_insn *> (target_label)) == next
3174 && ! condjump_in_parallel_p (jump_insn)
3175 && ! (next && switch_text_sections_between_p (jump_insn, next)))
3177 delete_jump (jump_insn);
3178 continue;
3181 if (target_label && target_label != JUMP_LABEL (jump_insn))
3183 reorg_redirect_jump (jump_insn, target_label);
3184 if (crossing)
3185 CROSSING_JUMP_P (jump_insn) = 1;
3188 /* See if this jump conditionally branches around an unconditional
3189 jump. If so, invert this jump and point it to the target of the
3190 second jump. Check if it's possible on the target. */
3191 if (next && simplejump_or_return_p (next)
3192 && any_condjump_p (jump_insn)
3193 && target_label
3194 && (next_active_insn (as_a<rtx_insn *> (target_label))
3195 == next_active_insn (next))
3196 && no_labels_between_p (jump_insn, next)
3197 && targetm.can_follow_jump (jump_insn, next))
3199 rtx label = JUMP_LABEL (next);
3201 /* Be careful how we do this to avoid deleting code or
3202 labels that are momentarily dead. See similar optimization
3203 in jump.c.
3205 We also need to ensure we properly handle the case when
3206 invert_jump fails. */
3208 ++LABEL_NUSES (target_label);
3209 if (!ANY_RETURN_P (label))
3210 ++LABEL_NUSES (label);
3212 if (invert_jump (jump_insn, label, 1))
3214 delete_related_insns (next);
3215 next = jump_insn;
3218 if (!ANY_RETURN_P (label))
3219 --LABEL_NUSES (label);
3221 if (--LABEL_NUSES (target_label) == 0)
3222 delete_related_insns (target_label);
3224 continue;
3228 /* If this is an unconditional jump and the previous insn is a
3229 conditional jump, try reversing the condition of the previous
3230 insn and swapping our targets. The next pass might be able to
3231 fill the slots.
3233 Don't do this if we expect the conditional branch to be true, because
3234 we would then be making the more common case longer. */
3236 if (simplejump_or_return_p (insn)
3237 && (other = prev_active_insn (insn)) != 0
3238 && any_condjump_p (other)
3239 && no_labels_between_p (other, insn)
3240 && mostly_true_jump (other) < 0)
3242 rtx other_target = JUMP_LABEL (other);
3243 target_label = JUMP_LABEL (insn);
3245 if (invert_jump (as_a <rtx_jump_insn *> (other), target_label, 0))
3246 reorg_redirect_jump (as_a <rtx_jump_insn *> (insn), other_target);
3249 /* Now look only at cases where we have a filled delay slot. */
3250 if (!NONJUMP_INSN_P (insn) || GET_CODE (PATTERN (insn)) != SEQUENCE)
3251 continue;
3253 pat = as_a <rtx_sequence *> (PATTERN (insn));
3254 delay_insn = pat->insn (0);
3256 /* See if the first insn in the delay slot is redundant with some
3257 previous insn. Remove it from the delay slot if so; then set up
3258 to reprocess this insn. */
3259 if ((prior_insn = redundant_insn (pat->insn (1), delay_insn, vNULL)))
3261 fix_reg_dead_note (prior_insn, insn);
3262 update_block (pat->insn (1), insn);
3263 delete_from_delay_slot (pat->insn (1));
3264 next = prev_active_insn (next);
3265 continue;
3268 /* See if we have a RETURN insn with a filled delay slot followed
3269 by a RETURN insn with an unfilled a delay slot. If so, we can delete
3270 the first RETURN (but not its delay insn). This gives the same
3271 effect in fewer instructions.
3273 Only do so if optimizing for size since this results in slower, but
3274 smaller code. */
3275 if (optimize_function_for_size_p (cfun)
3276 && ANY_RETURN_P (PATTERN (delay_insn))
3277 && next
3278 && JUMP_P (next)
3279 && PATTERN (next) == PATTERN (delay_insn))
3281 rtx_insn *after;
3282 int i;
3284 /* Delete the RETURN and just execute the delay list insns.
3286 We do this by deleting the INSN containing the SEQUENCE, then
3287 re-emitting the insns separately, and then deleting the RETURN.
3288 This allows the count of the jump target to be properly
3289 decremented.
3291 Note that we need to change the INSN_UID of the re-emitted insns
3292 since it is used to hash the insns for mark_target_live_regs and
3293 the re-emitted insns will no longer be wrapped up in a SEQUENCE.
3295 Clear the from target bit, since these insns are no longer
3296 in delay slots. */
3297 for (i = 0; i < XVECLEN (pat, 0); i++)
3298 INSN_FROM_TARGET_P (XVECEXP (pat, 0, i)) = 0;
3300 rtx_insn *prev = PREV_INSN (insn);
3301 delete_related_insns (insn);
3302 gcc_assert (GET_CODE (pat) == SEQUENCE);
3303 add_insn_after (delay_insn, prev, NULL);
3304 after = delay_insn;
3305 for (i = 1; i < pat->len (); i++)
3306 after = emit_copy_of_insn_after (pat->insn (i), after);
3307 delete_scheduled_jump (delay_insn);
3308 continue;
3311 /* Now look only at the cases where we have a filled JUMP_INSN. */
3312 rtx_jump_insn *delay_jump_insn =
3313 dyn_cast <rtx_jump_insn *> (delay_insn);
3314 if (! delay_jump_insn || !(condjump_p (delay_jump_insn)
3315 || condjump_in_parallel_p (delay_jump_insn)))
3316 continue;
3318 target_label = JUMP_LABEL (delay_jump_insn);
3319 if (target_label && ANY_RETURN_P (target_label))
3320 continue;
3322 /* If this jump goes to another unconditional jump, thread it, but
3323 don't convert a jump into a RETURN here. */
3324 rtx trial = skip_consecutive_labels (follow_jumps (target_label,
3325 delay_jump_insn,
3326 &crossing));
3327 if (ANY_RETURN_P (trial))
3328 trial = find_end_label (trial);
3330 if (trial && trial != target_label
3331 && redirect_with_delay_slots_safe_p (delay_jump_insn, trial, insn))
3333 reorg_redirect_jump (delay_jump_insn, trial);
3334 target_label = trial;
3335 if (crossing)
3336 CROSSING_JUMP_P (delay_jump_insn) = 1;
3339 /* If the first insn at TARGET_LABEL is redundant with a previous
3340 insn, redirect the jump to the following insn and process again.
3341 We use next_real_nondebug_insn instead of next_active_insn so we
3342 don't skip USE-markers, or we'll end up with incorrect
3343 liveness info. */
3344 trial = next_real_nondebug_insn (target_label);
3345 if (trial && GET_CODE (PATTERN (trial)) != SEQUENCE
3346 && redundant_insn (trial, insn, vNULL)
3347 && ! can_throw_internal (trial))
3349 /* Figure out where to emit the special USE insn so we don't
3350 later incorrectly compute register live/death info. */
3351 rtx_insn *tmp = next_active_insn (as_a<rtx_insn *> (trial));
3352 if (tmp == 0)
3353 tmp = find_end_label (simple_return_rtx);
3355 if (tmp)
3357 /* Insert the special USE insn and update dataflow info.
3358 We know "trial" is an insn here as it is the output of
3359 next_real_nondebug_insn () above. */
3360 update_block (as_a <rtx_insn *> (trial), tmp);
3362 /* Now emit a label before the special USE insn, and
3363 redirect our jump to the new label. */
3364 target_label = get_label_before (PREV_INSN (tmp), target_label);
3365 reorg_redirect_jump (delay_jump_insn, target_label);
3366 next = insn;
3367 continue;
3371 /* Similarly, if it is an unconditional jump with one insn in its
3372 delay list and that insn is redundant, thread the jump. */
3373 rtx_sequence *trial_seq =
3374 trial ? dyn_cast <rtx_sequence *> (PATTERN (trial)) : NULL;
3375 if (trial_seq
3376 && trial_seq->len () == 2
3377 && JUMP_P (trial_seq->insn (0))
3378 && simplejump_or_return_p (trial_seq->insn (0))
3379 && redundant_insn (trial_seq->insn (1), insn, vNULL))
3381 rtx temp_label = JUMP_LABEL (trial_seq->insn (0));
3382 if (ANY_RETURN_P (temp_label))
3383 temp_label = find_end_label (temp_label);
3385 if (temp_label
3386 && redirect_with_delay_slots_safe_p (delay_jump_insn,
3387 temp_label, insn))
3389 update_block (trial_seq->insn (1), insn);
3390 reorg_redirect_jump (delay_jump_insn, temp_label);
3391 next = insn;
3392 continue;
3396 /* See if we have a simple (conditional) jump that is useless. */
3397 if (!CROSSING_JUMP_P (delay_jump_insn)
3398 && !INSN_ANNULLED_BRANCH_P (delay_jump_insn)
3399 && !condjump_in_parallel_p (delay_jump_insn)
3400 && prev_active_insn (as_a<rtx_insn *> (target_label)) == insn
3401 && !BARRIER_P (prev_nonnote_insn (as_a<rtx_insn *> (target_label)))
3402 /* If the last insn in the delay slot sets CC0 for some insn,
3403 various code assumes that it is in a delay slot. We could
3404 put it back where it belonged and delete the register notes,
3405 but it doesn't seem worthwhile in this uncommon case. */
3406 && (!HAVE_cc0
3407 || ! find_reg_note (XVECEXP (pat, 0, XVECLEN (pat, 0) - 1),
3408 REG_CC_USER, NULL_RTX)))
3410 rtx_insn *after;
3411 int i;
3413 /* All this insn does is execute its delay list and jump to the
3414 following insn. So delete the jump and just execute the delay
3415 list insns.
3417 We do this by deleting the INSN containing the SEQUENCE, then
3418 re-emitting the insns separately, and then deleting the jump.
3419 This allows the count of the jump target to be properly
3420 decremented.
3422 Note that we need to change the INSN_UID of the re-emitted insns
3423 since it is used to hash the insns for mark_target_live_regs and
3424 the re-emitted insns will no longer be wrapped up in a SEQUENCE.
3426 Clear the from target bit, since these insns are no longer
3427 in delay slots. */
3428 for (i = 0; i < XVECLEN (pat, 0); i++)
3429 INSN_FROM_TARGET_P (XVECEXP (pat, 0, i)) = 0;
3431 rtx_insn *prev = PREV_INSN (insn);
3432 delete_related_insns (insn);
3433 gcc_assert (GET_CODE (pat) == SEQUENCE);
3434 add_insn_after (delay_jump_insn, prev, NULL);
3435 after = delay_jump_insn;
3436 for (i = 1; i < pat->len (); i++)
3437 after = emit_copy_of_insn_after (pat->insn (i), after);
3438 delete_scheduled_jump (delay_jump_insn);
3439 continue;
3442 /* See if this is an unconditional jump around a single insn which is
3443 identical to the one in its delay slot. In this case, we can just
3444 delete the branch and the insn in its delay slot. */
3445 if (next && NONJUMP_INSN_P (next)
3446 && label_before_next_insn (next, insn) == target_label
3447 && simplejump_p (insn)
3448 && XVECLEN (pat, 0) == 2
3449 && rtx_equal_p (PATTERN (next), PATTERN (pat->insn (1))))
3451 delete_related_insns (insn);
3452 continue;
3455 /* See if this jump (with its delay slots) conditionally branches
3456 around an unconditional jump (without delay slots). If so, invert
3457 this jump and point it to the target of the second jump. We cannot
3458 do this for annulled jumps, though. Again, don't convert a jump to
3459 a RETURN here. */
3460 if (! INSN_ANNULLED_BRANCH_P (delay_jump_insn)
3461 && any_condjump_p (delay_jump_insn)
3462 && next && simplejump_or_return_p (next)
3463 && (next_active_insn (as_a<rtx_insn *> (target_label))
3464 == next_active_insn (next))
3465 && no_labels_between_p (insn, next))
3467 rtx label = JUMP_LABEL (next);
3468 rtx old_label = JUMP_LABEL (delay_jump_insn);
3470 if (ANY_RETURN_P (label))
3471 label = find_end_label (label);
3473 /* find_end_label can generate a new label. Check this first. */
3474 if (label
3475 && no_labels_between_p (insn, next)
3476 && redirect_with_delay_slots_safe_p (delay_jump_insn,
3477 label, insn))
3479 /* Be careful how we do this to avoid deleting code or labels
3480 that are momentarily dead. See similar optimization in
3481 jump.c */
3482 if (old_label)
3483 ++LABEL_NUSES (old_label);
3485 if (invert_jump (delay_jump_insn, label, 1))
3487 int i;
3489 /* Must update the INSN_FROM_TARGET_P bits now that
3490 the branch is reversed, so that mark_target_live_regs
3491 will handle the delay slot insn correctly. */
3492 for (i = 1; i < XVECLEN (PATTERN (insn), 0); i++)
3494 rtx slot = XVECEXP (PATTERN (insn), 0, i);
3495 INSN_FROM_TARGET_P (slot) = ! INSN_FROM_TARGET_P (slot);
3498 delete_related_insns (next);
3499 next = insn;
3502 if (old_label && --LABEL_NUSES (old_label) == 0)
3503 delete_related_insns (old_label);
3504 continue;
3508 /* If we own the thread opposite the way this insn branches, see if we
3509 can merge its delay slots with following insns. */
3510 if (INSN_FROM_TARGET_P (pat->insn (1))
3511 && own_thread_p (NEXT_INSN (insn), 0, 1))
3512 try_merge_delay_insns (insn, next);
3513 else if (! INSN_FROM_TARGET_P (pat->insn (1))
3514 && own_thread_p (target_label, target_label, 0))
3515 try_merge_delay_insns (insn,
3516 next_active_insn (as_a<rtx_insn *> (target_label)));
3518 /* If we get here, we haven't deleted INSN. But we may have deleted
3519 NEXT, so recompute it. */
3520 next = next_active_insn (insn);
3525 /* Look for filled jumps to the end of function label. We can try to convert
3526 them into RETURN insns if the insns in the delay slot are valid for the
3527 RETURN as well. */
3529 static void
3530 make_return_insns (rtx_insn *first)
3532 rtx_insn *insn;
3533 rtx_jump_insn *jump_insn;
3534 rtx real_return_label = function_return_label;
3535 rtx real_simple_return_label = function_simple_return_label;
3536 int slots, i;
3538 /* See if there is a RETURN insn in the function other than the one we
3539 made for END_OF_FUNCTION_LABEL. If so, set up anything we can't change
3540 into a RETURN to jump to it. */
3541 for (insn = first; insn; insn = NEXT_INSN (insn))
3542 if (JUMP_P (insn) && ANY_RETURN_P (PATTERN (insn)))
3544 rtx t = get_label_before (insn, NULL_RTX);
3545 if (PATTERN (insn) == ret_rtx)
3546 real_return_label = t;
3547 else
3548 real_simple_return_label = t;
3549 break;
3552 /* Show an extra usage of REAL_RETURN_LABEL so it won't go away if it
3553 was equal to END_OF_FUNCTION_LABEL. */
3554 if (real_return_label)
3555 LABEL_NUSES (real_return_label)++;
3556 if (real_simple_return_label)
3557 LABEL_NUSES (real_simple_return_label)++;
3559 /* Clear the list of insns to fill so we can use it. */
3560 obstack_free (&unfilled_slots_obstack, unfilled_firstobj);
3562 for (insn = first; insn; insn = NEXT_INSN (insn))
3564 int flags;
3565 rtx kind, real_label;
3567 /* Only look at filled JUMP_INSNs that go to the end of function
3568 label. */
3569 if (!NONJUMP_INSN_P (insn))
3570 continue;
3572 if (GET_CODE (PATTERN (insn)) != SEQUENCE)
3573 continue;
3575 rtx_sequence *pat = as_a <rtx_sequence *> (PATTERN (insn));
3577 if (!jump_to_label_p (pat->insn (0)))
3578 continue;
3580 if (JUMP_LABEL (pat->insn (0)) == function_return_label)
3582 kind = ret_rtx;
3583 real_label = real_return_label;
3585 else if (JUMP_LABEL (pat->insn (0)) == function_simple_return_label)
3587 kind = simple_return_rtx;
3588 real_label = real_simple_return_label;
3590 else
3591 continue;
3593 jump_insn = as_a <rtx_jump_insn *> (pat->insn (0));
3595 /* If we can't make the jump into a RETURN, try to redirect it to the best
3596 RETURN and go on to the next insn. */
3597 if (!reorg_redirect_jump (jump_insn, kind))
3599 /* Make sure redirecting the jump will not invalidate the delay
3600 slot insns. */
3601 if (redirect_with_delay_slots_safe_p (jump_insn, real_label, insn))
3602 reorg_redirect_jump (jump_insn, real_label);
3603 continue;
3606 /* See if this RETURN can accept the insns current in its delay slot.
3607 It can if it has more or an equal number of slots and the contents
3608 of each is valid. */
3610 flags = get_jump_flags (jump_insn, JUMP_LABEL (jump_insn));
3611 slots = num_delay_slots (jump_insn);
3612 if (slots >= XVECLEN (pat, 0) - 1)
3614 for (i = 1; i < XVECLEN (pat, 0); i++)
3615 if (! (
3616 #if ANNUL_IFFALSE_SLOTS
3617 (INSN_ANNULLED_BRANCH_P (jump_insn)
3618 && INSN_FROM_TARGET_P (pat->insn (i)))
3619 ? eligible_for_annul_false (jump_insn, i - 1,
3620 pat->insn (i), flags) :
3621 #endif
3622 #if ANNUL_IFTRUE_SLOTS
3623 (INSN_ANNULLED_BRANCH_P (jump_insn)
3624 && ! INSN_FROM_TARGET_P (pat->insn (i)))
3625 ? eligible_for_annul_true (jump_insn, i - 1,
3626 pat->insn (i), flags) :
3627 #endif
3628 eligible_for_delay (jump_insn, i - 1,
3629 pat->insn (i), flags)))
3630 break;
3632 else
3633 i = 0;
3635 if (i == XVECLEN (pat, 0))
3636 continue;
3638 /* We have to do something with this insn. If it is an unconditional
3639 RETURN, delete the SEQUENCE and output the individual insns,
3640 followed by the RETURN. Then set things up so we try to find
3641 insns for its delay slots, if it needs some. */
3642 if (ANY_RETURN_P (PATTERN (jump_insn)))
3644 rtx_insn *after = PREV_INSN (insn);
3646 delete_related_insns (insn);
3647 insn = jump_insn;
3648 for (i = 1; i < pat->len (); i++)
3649 after = emit_copy_of_insn_after (pat->insn (i), after);
3650 add_insn_after (insn, after, NULL);
3651 emit_barrier_after (insn);
3653 if (slots)
3654 obstack_ptr_grow (&unfilled_slots_obstack, insn);
3656 else
3657 /* It is probably more efficient to keep this with its current
3658 delay slot as a branch to a RETURN. */
3659 reorg_redirect_jump (jump_insn, real_label);
3662 /* Now delete REAL_RETURN_LABEL if we never used it. Then try to fill any
3663 new delay slots we have created. */
3664 if (real_return_label != NULL_RTX && --LABEL_NUSES (real_return_label) == 0)
3665 delete_related_insns (real_return_label);
3666 if (real_simple_return_label != NULL_RTX
3667 && --LABEL_NUSES (real_simple_return_label) == 0)
3668 delete_related_insns (real_simple_return_label);
3670 fill_simple_delay_slots (1);
3671 fill_simple_delay_slots (0);
3674 /* Try to find insns to place in delay slots. */
3676 static void
3677 dbr_schedule (rtx_insn *first)
3679 rtx_insn *insn, *next, *epilogue_insn = 0;
3680 int i;
3681 bool need_return_insns;
3683 /* If the current function has no insns other than the prologue and
3684 epilogue, then do not try to fill any delay slots. */
3685 if (n_basic_blocks_for_fn (cfun) == NUM_FIXED_BLOCKS)
3686 return;
3688 /* Find the highest INSN_UID and allocate and initialize our map from
3689 INSN_UID's to position in code. */
3690 for (max_uid = 0, insn = first; insn; insn = NEXT_INSN (insn))
3692 if (INSN_UID (insn) > max_uid)
3693 max_uid = INSN_UID (insn);
3694 if (NOTE_P (insn)
3695 && NOTE_KIND (insn) == NOTE_INSN_EPILOGUE_BEG)
3696 epilogue_insn = insn;
3699 uid_to_ruid = XNEWVEC (int, max_uid + 1);
3700 for (i = 0, insn = first; insn; i++, insn = NEXT_INSN (insn))
3701 uid_to_ruid[INSN_UID (insn)] = i;
3703 /* Initialize the list of insns that need filling. */
3704 if (unfilled_firstobj == 0)
3706 gcc_obstack_init (&unfilled_slots_obstack);
3707 unfilled_firstobj = XOBNEWVAR (&unfilled_slots_obstack, rtx, 0);
3710 for (insn = next_active_insn (first); insn; insn = next_active_insn (insn))
3712 rtx target;
3714 /* Skip vector tables. We can't get attributes for them. */
3715 if (JUMP_TABLE_DATA_P (insn))
3716 continue;
3718 if (JUMP_P (insn))
3719 INSN_ANNULLED_BRANCH_P (insn) = 0;
3720 INSN_FROM_TARGET_P (insn) = 0;
3722 if (num_delay_slots (insn) > 0)
3723 obstack_ptr_grow (&unfilled_slots_obstack, insn);
3725 /* Ensure all jumps go to the last of a set of consecutive labels. */
3726 if (JUMP_P (insn)
3727 && (condjump_p (insn) || condjump_in_parallel_p (insn))
3728 && !ANY_RETURN_P (JUMP_LABEL (insn))
3729 && ((target = skip_consecutive_labels (JUMP_LABEL (insn)))
3730 != JUMP_LABEL (insn)))
3731 redirect_jump (as_a <rtx_jump_insn *> (insn), target, 1);
3734 init_resource_info (epilogue_insn);
3736 /* Show we haven't computed an end-of-function label yet. */
3737 function_return_label = function_simple_return_label = NULL;
3739 /* Initialize the statistics for this function. */
3740 memset (num_insns_needing_delays, 0, sizeof num_insns_needing_delays);
3741 memset (num_filled_delays, 0, sizeof num_filled_delays);
3743 /* Now do the delay slot filling. Try everything twice in case earlier
3744 changes make more slots fillable. */
3746 for (reorg_pass_number = 0;
3747 reorg_pass_number < MAX_REORG_PASSES;
3748 reorg_pass_number++)
3750 fill_simple_delay_slots (1);
3751 fill_simple_delay_slots (0);
3752 if (!targetm.no_speculation_in_delay_slots_p ())
3753 fill_eager_delay_slots ();
3754 relax_delay_slots (first);
3757 /* If we made an end of function label, indicate that it is now
3758 safe to delete it by undoing our prior adjustment to LABEL_NUSES.
3759 If it is now unused, delete it. */
3760 if (function_return_label && --LABEL_NUSES (function_return_label) == 0)
3761 delete_related_insns (function_return_label);
3762 if (function_simple_return_label
3763 && --LABEL_NUSES (function_simple_return_label) == 0)
3764 delete_related_insns (function_simple_return_label);
3766 need_return_insns = false;
3767 need_return_insns |= targetm.have_return () && function_return_label != 0;
3768 need_return_insns |= (targetm.have_simple_return ()
3769 && function_simple_return_label != 0);
3770 if (need_return_insns)
3771 make_return_insns (first);
3773 /* Delete any USE insns made by update_block; subsequent passes don't need
3774 them or know how to deal with them. */
3775 for (insn = first; insn; insn = next)
3777 next = NEXT_INSN (insn);
3779 if (NONJUMP_INSN_P (insn) && GET_CODE (PATTERN (insn)) == USE
3780 && INSN_P (XEXP (PATTERN (insn), 0)))
3781 next = delete_related_insns (insn);
3784 obstack_free (&unfilled_slots_obstack, unfilled_firstobj);
3786 /* It is not clear why the line below is needed, but it does seem to be. */
3787 unfilled_firstobj = XOBNEWVAR (&unfilled_slots_obstack, rtx, 0);
3789 if (dump_file)
3791 int i, j, need_comma;
3792 int total_delay_slots[MAX_DELAY_HISTOGRAM + 1];
3793 int total_annul_slots[MAX_DELAY_HISTOGRAM + 1];
3795 for (reorg_pass_number = 0;
3796 reorg_pass_number < MAX_REORG_PASSES;
3797 reorg_pass_number++)
3799 fprintf (dump_file, ";; Reorg pass #%d:\n", reorg_pass_number + 1);
3800 for (i = 0; i < NUM_REORG_FUNCTIONS; i++)
3802 need_comma = 0;
3803 fprintf (dump_file, ";; Reorg function #%d\n", i);
3805 fprintf (dump_file, ";; %d insns needing delay slots\n;; ",
3806 num_insns_needing_delays[i][reorg_pass_number]);
3808 for (j = 0; j < MAX_DELAY_HISTOGRAM + 1; j++)
3809 if (num_filled_delays[i][j][reorg_pass_number])
3811 if (need_comma)
3812 fprintf (dump_file, ", ");
3813 need_comma = 1;
3814 fprintf (dump_file, "%d got %d delays",
3815 num_filled_delays[i][j][reorg_pass_number], j);
3817 fprintf (dump_file, "\n");
3820 memset (total_delay_slots, 0, sizeof total_delay_slots);
3821 memset (total_annul_slots, 0, sizeof total_annul_slots);
3822 for (insn = first; insn; insn = NEXT_INSN (insn))
3824 if (! insn->deleted ()
3825 && NONJUMP_INSN_P (insn)
3826 && GET_CODE (PATTERN (insn)) != USE
3827 && GET_CODE (PATTERN (insn)) != CLOBBER)
3829 if (GET_CODE (PATTERN (insn)) == SEQUENCE)
3831 rtx control;
3832 j = XVECLEN (PATTERN (insn), 0) - 1;
3833 if (j > MAX_DELAY_HISTOGRAM)
3834 j = MAX_DELAY_HISTOGRAM;
3835 control = XVECEXP (PATTERN (insn), 0, 0);
3836 if (JUMP_P (control) && INSN_ANNULLED_BRANCH_P (control))
3837 total_annul_slots[j]++;
3838 else
3839 total_delay_slots[j]++;
3841 else if (num_delay_slots (insn) > 0)
3842 total_delay_slots[0]++;
3845 fprintf (dump_file, ";; Reorg totals: ");
3846 need_comma = 0;
3847 for (j = 0; j < MAX_DELAY_HISTOGRAM + 1; j++)
3849 if (total_delay_slots[j])
3851 if (need_comma)
3852 fprintf (dump_file, ", ");
3853 need_comma = 1;
3854 fprintf (dump_file, "%d got %d delays", total_delay_slots[j], j);
3857 fprintf (dump_file, "\n");
3859 if (ANNUL_IFTRUE_SLOTS || ANNUL_IFFALSE_SLOTS)
3861 fprintf (dump_file, ";; Reorg annuls: ");
3862 need_comma = 0;
3863 for (j = 0; j < MAX_DELAY_HISTOGRAM + 1; j++)
3865 if (total_annul_slots[j])
3867 if (need_comma)
3868 fprintf (dump_file, ", ");
3869 need_comma = 1;
3870 fprintf (dump_file, "%d got %d delays", total_annul_slots[j], j);
3873 fprintf (dump_file, "\n");
3876 fprintf (dump_file, "\n");
3879 if (!sibling_labels.is_empty ())
3881 update_alignments (sibling_labels);
3882 sibling_labels.release ();
3885 free_resource_info ();
3886 free (uid_to_ruid);
3887 crtl->dbr_scheduled_p = true;
3890 /* Run delay slot optimization. */
3891 static unsigned int
3892 rest_of_handle_delay_slots (void)
3894 if (DELAY_SLOTS)
3895 dbr_schedule (get_insns ());
3897 return 0;
3900 namespace {
3902 const pass_data pass_data_delay_slots =
3904 RTL_PASS, /* type */
3905 "dbr", /* name */
3906 OPTGROUP_NONE, /* optinfo_flags */
3907 TV_DBR_SCHED, /* tv_id */
3908 0, /* properties_required */
3909 0, /* properties_provided */
3910 0, /* properties_destroyed */
3911 0, /* todo_flags_start */
3912 0, /* todo_flags_finish */
3915 class pass_delay_slots : public rtl_opt_pass
3917 public:
3918 pass_delay_slots (gcc::context *ctxt)
3919 : rtl_opt_pass (pass_data_delay_slots, ctxt)
3922 /* opt_pass methods: */
3923 virtual bool gate (function *);
3924 virtual unsigned int execute (function *)
3926 return rest_of_handle_delay_slots ();
3929 }; // class pass_delay_slots
3931 bool
3932 pass_delay_slots::gate (function *)
3934 /* At -O0 dataflow info isn't updated after RA. */
3935 if (DELAY_SLOTS)
3936 return optimize > 0 && flag_delayed_branch && !crtl->dbr_scheduled_p;
3938 return false;
3941 } // anon namespace
3943 rtl_opt_pass *
3944 make_pass_delay_slots (gcc::context *ctxt)
3946 return new pass_delay_slots (ctxt);
3949 /* Machine dependent reorg pass. */
3951 namespace {
3953 const pass_data pass_data_machine_reorg =
3955 RTL_PASS, /* type */
3956 "mach", /* name */
3957 OPTGROUP_NONE, /* optinfo_flags */
3958 TV_MACH_DEP, /* tv_id */
3959 0, /* properties_required */
3960 0, /* properties_provided */
3961 0, /* properties_destroyed */
3962 0, /* todo_flags_start */
3963 0, /* todo_flags_finish */
3966 class pass_machine_reorg : public rtl_opt_pass
3968 public:
3969 pass_machine_reorg (gcc::context *ctxt)
3970 : rtl_opt_pass (pass_data_machine_reorg, ctxt)
3973 /* opt_pass methods: */
3974 virtual bool gate (function *)
3976 return targetm.machine_dependent_reorg != 0;
3979 virtual unsigned int execute (function *)
3981 targetm.machine_dependent_reorg ();
3982 return 0;
3985 }; // class pass_machine_reorg
3987 } // anon namespace
3989 rtl_opt_pass *
3990 make_pass_machine_reorg (gcc::context *ctxt)
3992 return new pass_machine_reorg (ctxt);