Line data Source code
1 : /* Instruction scheduling pass. This file contains definitions used
2 : internally in the scheduler.
3 : Copyright (C) 2006-2026 Free Software Foundation, Inc.
4 :
5 : This file is part of GCC.
6 :
7 : GCC is free software; you can redistribute it and/or modify it under
8 : the terms of the GNU General Public License as published by the Free
9 : Software Foundation; either version 3, or (at your option) any later
10 : version.
11 :
12 : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 : WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 : for more details.
16 :
17 : You should have received a copy of the GNU General Public License
18 : along with GCC; see the file COPYING3. If not see
19 : <http://www.gnu.org/licenses/>. */
20 :
21 : #ifndef GCC_SEL_SCHED_IR_H
22 : #define GCC_SEL_SCHED_IR_H
23 :
24 : /* tc_t is a short for target context. This is a state of the target
25 : backend. */
26 : typedef void *tc_t;
27 :
28 : /* List data types used for av sets, fences, paths, and boundaries. */
29 :
30 : /* Forward declarations for types that are part of some list nodes. */
31 : struct _list_node;
32 :
33 : /* List backend. */
34 : typedef struct _list_node *_list_t;
35 : #define _LIST_NEXT(L) ((L)->next)
36 :
37 : /* Instruction data that is part of vinsn type. */
38 : struct idata_def;
39 : typedef struct idata_def *idata_t;
40 :
41 : /* A virtual instruction, i.e. an instruction as seen by the scheduler. */
42 : struct vinsn_def;
43 : typedef struct vinsn_def *vinsn_t;
44 :
45 : /* Instruction. */
46 : typedef rtx_insn *insn_t;
47 :
48 : /* List of insns. */
49 : typedef _list_t ilist_t;
50 : #define ILIST_INSN(L) ((L)->u.insn)
51 : #define ILIST_NEXT(L) (_LIST_NEXT (L))
52 :
53 : /* This lists possible transformations that done locally, i.e. in
54 : moveup_expr. */
55 : enum local_trans_type
56 : {
57 : TRANS_SUBSTITUTION,
58 : TRANS_SPECULATION
59 : };
60 :
61 : /* This struct is used to record the history of expression's
62 : transformations. */
63 : struct expr_history_def_1
64 : {
65 : /* UID of the insn. */
66 : unsigned uid;
67 :
68 : /* How the expression looked like. */
69 : vinsn_t old_expr_vinsn;
70 :
71 : /* How the expression looks after the transformation. */
72 : vinsn_t new_expr_vinsn;
73 :
74 : /* And its speculative status. */
75 : ds_t spec_ds;
76 :
77 : /* Type of the transformation. */
78 : enum local_trans_type type;
79 : };
80 :
81 : typedef struct expr_history_def_1 expr_history_def;
82 :
83 :
84 : /* Expression information. */
85 : struct _expr
86 : {
87 : /* Insn description. */
88 : vinsn_t vinsn;
89 :
90 : /* SPEC is the degree of speculativeness.
91 : FIXME: now spec is increased when an rhs is moved through a
92 : conditional, thus showing only control speculativeness. In the
93 : future we'd like to count data spec separately to allow a better
94 : control on scheduling. */
95 : int spec;
96 :
97 : /* Degree of speculativeness measured as probability of executing
98 : instruction's original basic block given relative to
99 : the current scheduling point. */
100 : int usefulness;
101 :
102 : /* A priority of this expression. */
103 : int priority;
104 :
105 : /* A priority adjustment of this expression. */
106 : int priority_adj;
107 :
108 : /* Number of times the insn was scheduled. */
109 : int sched_times;
110 :
111 : /* A basic block index this was originated from. Zero when there is
112 : more than one originator. */
113 : int orig_bb_index;
114 :
115 : /* Instruction should be of SPEC_DONE_DS type in order to be moved to this
116 : point. */
117 : ds_t spec_done_ds;
118 :
119 : /* SPEC_TO_CHECK_DS hold speculation types that should be checked
120 : (used only during move_op ()). */
121 : ds_t spec_to_check_ds;
122 :
123 : /* Cycle on which original insn was scheduled. Zero when it has not yet
124 : been scheduled or more than one originator. */
125 : int orig_sched_cycle;
126 :
127 : /* This vector contains the history of insn's transformations. */
128 : vec<expr_history_def> history_of_changes;
129 :
130 : /* True (1) when original target (register or memory) of this instruction
131 : is available for scheduling, false otherwise. -1 means we're not sure;
132 : please run find_used_regs to clarify. */
133 : signed char target_available;
134 :
135 : /* True when this expression needs a speculation check to be scheduled.
136 : This is used during find_used_regs. */
137 : bool needs_spec_check_p : 1;
138 :
139 : /* True when the expression was substituted. Used for statistical
140 : purposes. */
141 : bool was_substituted : 1;
142 :
143 : /* True when the expression was renamed. */
144 : bool was_renamed : 1;
145 :
146 : /* True when expression can't be moved. */
147 : bool cant_move : 1;
148 : };
149 :
150 : typedef struct _expr expr_def;
151 : typedef expr_def *expr_t;
152 :
153 : #define EXPR_VINSN(EXPR) ((EXPR)->vinsn)
154 : #define EXPR_INSN_RTX(EXPR) (VINSN_INSN_RTX (EXPR_VINSN (EXPR)))
155 : #define EXPR_PATTERN(EXPR) (VINSN_PATTERN (EXPR_VINSN (EXPR)))
156 : #define EXPR_LHS(EXPR) (VINSN_LHS (EXPR_VINSN (EXPR)))
157 : #define EXPR_RHS(EXPR) (VINSN_RHS (EXPR_VINSN (EXPR)))
158 : #define EXPR_TYPE(EXPR) (VINSN_TYPE (EXPR_VINSN (EXPR)))
159 : #define EXPR_SEPARABLE_P(EXPR) (VINSN_SEPARABLE_P (EXPR_VINSN (EXPR)))
160 :
161 : #define EXPR_SPEC(EXPR) ((EXPR)->spec)
162 : #define EXPR_USEFULNESS(EXPR) ((EXPR)->usefulness)
163 : #define EXPR_PRIORITY(EXPR) ((EXPR)->priority)
164 : #define EXPR_PRIORITY_ADJ(EXPR) ((EXPR)->priority_adj)
165 : #define EXPR_SCHED_TIMES(EXPR) ((EXPR)->sched_times)
166 : #define EXPR_ORIG_BB_INDEX(EXPR) ((EXPR)->orig_bb_index)
167 : #define EXPR_ORIG_SCHED_CYCLE(EXPR) ((EXPR)->orig_sched_cycle)
168 : #define EXPR_SPEC_DONE_DS(EXPR) ((EXPR)->spec_done_ds)
169 : #define EXPR_SPEC_TO_CHECK_DS(EXPR) ((EXPR)->spec_to_check_ds)
170 : #define EXPR_HISTORY_OF_CHANGES(EXPR) ((EXPR)->history_of_changes)
171 : #define EXPR_TARGET_AVAILABLE(EXPR) ((EXPR)->target_available)
172 : #define EXPR_NEEDS_SPEC_CHECK_P(EXPR) ((EXPR)->needs_spec_check_p)
173 : #define EXPR_WAS_SUBSTITUTED(EXPR) ((EXPR)->was_substituted)
174 : #define EXPR_WAS_RENAMED(EXPR) ((EXPR)->was_renamed)
175 : #define EXPR_CANT_MOVE(EXPR) ((EXPR)->cant_move)
176 :
177 : /* Insn definition for list of original insns in find_used_regs. */
178 : struct _def
179 : {
180 : insn_t orig_insn;
181 :
182 : /* FIXME: Get rid of CROSSED_CALL_ABIS in each def, since if we're moving up
183 : rhs from two different places, but only one of the code motion paths
184 : crosses a call, we can't use any of the call_used_regs, no matter which
185 : path or whether all paths crosses a call. Thus we should move
186 : CROSSED_CALL_ABIS to static params. */
187 : unsigned int crossed_call_abis;
188 : };
189 : typedef struct _def *def_t;
190 :
191 :
192 : /* Availability sets are sets of expressions we're scheduling. */
193 : typedef _list_t av_set_t;
194 : #define _AV_SET_EXPR(L) (&(L)->u.expr)
195 : #define _AV_SET_NEXT(L) (_LIST_NEXT (L))
196 :
197 :
198 : /* Boundary of the current fence group. */
199 : struct _bnd
200 : {
201 : /* The actual boundary instruction. */
202 : insn_t to;
203 :
204 : /* Its path to the fence. */
205 : ilist_t ptr;
206 :
207 : /* Availability set at the boundary. */
208 : av_set_t av;
209 :
210 : /* This set moved to the fence. */
211 : av_set_t av1;
212 :
213 : /* Deps context at this boundary. As long as we have one boundary per fence,
214 : this is just a pointer to the same deps context as in the corresponding
215 : fence. */
216 : deps_t dc;
217 : };
218 : typedef struct _bnd *bnd_t;
219 : #define BND_TO(B) ((B)->to)
220 :
221 : /* PTR stands not for pointer as you might think, but as a Path To Root of the
222 : current instruction group from boundary B. */
223 : #define BND_PTR(B) ((B)->ptr)
224 : #define BND_AV(B) ((B)->av)
225 : #define BND_AV1(B) ((B)->av1)
226 : #define BND_DC(B) ((B)->dc)
227 :
228 : /* List of boundaries. */
229 : typedef _list_t blist_t;
230 : #define BLIST_BND(L) (&(L)->u.bnd)
231 : #define BLIST_NEXT(L) (_LIST_NEXT (L))
232 :
233 :
234 : /* Fence information. A fence represents current scheduling point and also
235 : blocks code motion through it when pipelining. */
236 : struct _fence
237 : {
238 : /* Insn before which we gather an instruction group.*/
239 : insn_t insn;
240 :
241 : /* Modeled state of the processor pipeline. */
242 : state_t state;
243 :
244 : /* Current cycle that is being scheduled on this fence. */
245 : int cycle;
246 :
247 : /* Number of insns that were scheduled on the current cycle.
248 : This information has to be local to a fence. */
249 : int cycle_issued_insns;
250 :
251 : /* At the end of fill_insns () this field holds the list of the instructions
252 : that are inner boundaries of the scheduled parallel group. */
253 : ilist_t bnds;
254 :
255 : /* Deps context at this fence. It is used to model dependencies at the
256 : fence so that insn ticks can be properly evaluated. */
257 : deps_t dc;
258 :
259 : /* Target context at this fence. Used to save and load any local target
260 : scheduling information when changing fences. */
261 : tc_t tc;
262 :
263 : /* A vector of insns that are scheduled but not yet completed. */
264 : vec<rtx_insn *, va_gc> *executing_insns;
265 :
266 : /* A vector indexed by UIDs that caches the earliest cycle on which
267 : an insn can be scheduled on this fence. */
268 : int *ready_ticks;
269 :
270 : /* Its size. */
271 : int ready_ticks_size;
272 :
273 : /* Insn, which has been scheduled last on this fence. */
274 : rtx_insn *last_scheduled_insn;
275 :
276 : /* The last value of can_issue_more variable on this fence. */
277 : int issue_more;
278 :
279 : /* If non-NULL force the next scheduled insn to be SCHED_NEXT. */
280 : rtx_insn *sched_next;
281 :
282 : /* True if fill_insns processed this fence. */
283 : bool processed_p : 1;
284 :
285 : /* True if fill_insns actually scheduled something on this fence. */
286 : bool scheduled_p : 1;
287 :
288 : /* True when the next insn scheduled here would start a cycle. */
289 : bool starts_cycle_p : 1;
290 :
291 : /* True when the next insn scheduled here would be scheduled after a stall. */
292 : bool after_stall_p : 1;
293 : };
294 : typedef struct _fence *fence_t;
295 :
296 : #define FENCE_INSN(F) ((F)->insn)
297 : #define FENCE_STATE(F) ((F)->state)
298 : #define FENCE_BNDS(F) ((F)->bnds)
299 : #define FENCE_PROCESSED_P(F) ((F)->processed_p)
300 : #define FENCE_SCHEDULED_P(F) ((F)->scheduled_p)
301 : #define FENCE_ISSUED_INSNS(F) ((F)->cycle_issued_insns)
302 : #define FENCE_CYCLE(F) ((F)->cycle)
303 : #define FENCE_STARTS_CYCLE_P(F) ((F)->starts_cycle_p)
304 : #define FENCE_AFTER_STALL_P(F) ((F)->after_stall_p)
305 : #define FENCE_DC(F) ((F)->dc)
306 : #define FENCE_TC(F) ((F)->tc)
307 : #define FENCE_LAST_SCHEDULED_INSN(F) ((F)->last_scheduled_insn)
308 : #define FENCE_ISSUE_MORE(F) ((F)->issue_more)
309 : #define FENCE_EXECUTING_INSNS(F) ((F)->executing_insns)
310 : #define FENCE_READY_TICKS(F) ((F)->ready_ticks)
311 : #define FENCE_READY_TICKS_SIZE(F) ((F)->ready_ticks_size)
312 : #define FENCE_SCHED_NEXT(F) ((F)->sched_next)
313 :
314 : /* List of fences. */
315 : typedef _list_t flist_t;
316 : #define FLIST_FENCE(L) (&(L)->u.fence)
317 : #define FLIST_NEXT(L) (_LIST_NEXT (L))
318 :
319 : /* List of fences with pointer to the tail node. */
320 : struct flist_tail_def
321 : {
322 : flist_t head;
323 : flist_t *tailp;
324 : };
325 :
326 : typedef struct flist_tail_def *flist_tail_t;
327 : #define FLIST_TAIL_HEAD(L) ((L)->head)
328 : #define FLIST_TAIL_TAILP(L) ((L)->tailp)
329 :
330 : /* List node information. A list node can be any of the types above. */
331 : struct _list_node
332 : {
333 : _list_t next;
334 :
335 : union
336 : {
337 : rtx x;
338 : insn_t insn;
339 : struct _bnd bnd;
340 : expr_def expr;
341 : struct _fence fence;
342 : struct _def def;
343 : void *data;
344 : } u;
345 : };
346 :
347 :
348 : /* _list_t functions.
349 : All of _*list_* functions are used through accessor macros, thus
350 : we can't move them in sel-sched-ir.cc. */
351 : extern object_allocator<_list_node> sched_lists_pool;
352 :
353 : inline _list_t
354 209628 : _list_alloc (void)
355 : {
356 209628 : return sched_lists_pool.allocate ();
357 : }
358 :
359 : inline void
360 209628 : _list_add (_list_t *lp)
361 : {
362 242260 : _list_t l = _list_alloc ();
363 :
364 209628 : _LIST_NEXT (l) = *lp;
365 183482 : *lp = l;
366 : }
367 :
368 : inline void
369 1918 : _list_remove_nofree (_list_t *lp)
370 : {
371 1918 : _list_t n = *lp;
372 :
373 1918 : *lp = _LIST_NEXT (n);
374 : }
375 :
376 : inline void
377 207084 : _list_remove (_list_t *lp)
378 : {
379 207084 : _list_t n = *lp;
380 :
381 207084 : *lp = _LIST_NEXT (n);
382 44971 : sched_lists_pool.remove (n);
383 : }
384 :
385 : inline void
386 11395 : _list_clear (_list_t *l)
387 : {
388 38863 : while (*l)
389 27468 : _list_remove (l);
390 11395 : }
391 :
392 :
393 : /* List iterator backend. */
394 : struct _list_iterator
395 : {
396 : /* The list we're iterating. */
397 : _list_t *lp;
398 :
399 : /* True when this iterator supports removing. */
400 : bool can_remove_p;
401 :
402 : /* True when we've actually removed something. */
403 : bool removed_p;
404 : };
405 :
406 : inline void
407 637515 : _list_iter_start (_list_iterator *ip, _list_t *lp, bool can_remove_p)
408 : {
409 691489 : ip->lp = lp;
410 406386 : ip->can_remove_p = can_remove_p;
411 688700 : ip->removed_p = false;
412 : }
413 :
414 : inline void
415 902632 : _list_iter_next (_list_iterator *ip)
416 : {
417 495307 : if (!ip->removed_p)
418 693658 : ip->lp = &_LIST_NEXT (*ip->lp);
419 : else
420 134617 : ip->removed_p = false;
421 : }
422 :
423 : inline void
424 134645 : _list_iter_remove (_list_iterator *ip)
425 : {
426 134645 : gcc_assert (!ip->removed_p && ip->can_remove_p);
427 134645 : _list_remove (ip->lp);
428 134645 : ip->removed_p = true;
429 134645 : }
430 :
431 : inline void
432 1918 : _list_iter_remove_nofree (_list_iterator *ip)
433 : {
434 1918 : gcc_assert (!ip->removed_p && ip->can_remove_p);
435 1918 : _list_remove_nofree (ip->lp);
436 1918 : ip->removed_p = true;
437 1918 : }
438 :
439 : /* General macros to traverse a list. FOR_EACH_* interfaces are
440 : implemented using these. */
441 : #define _FOR_EACH(TYPE, ELEM, I, L) \
442 : for (_list_iter_start (&(I), &(L), false); \
443 : _list_iter_cond_##TYPE (*(I).lp, &(ELEM)); \
444 : _list_iter_next (&(I)))
445 :
446 : #define _FOR_EACH_1(TYPE, ELEM, I, LP) \
447 : for (_list_iter_start (&(I), (LP), true); \
448 : _list_iter_cond_##TYPE (*(I).lp, &(ELEM)); \
449 : _list_iter_next (&(I)))
450 :
451 :
452 : /* ilist_t functions. */
453 :
454 : inline void
455 61418 : ilist_add (ilist_t *lp, insn_t insn)
456 : {
457 61418 : _list_add (lp);
458 61418 : ILIST_INSN (*lp) = insn;
459 : }
460 : #define ilist_remove(LP) (_list_remove (LP))
461 : #define ilist_clear(LP) (_list_clear (LP))
462 :
463 : inline bool
464 1003 : ilist_is_in_p (ilist_t l, insn_t insn)
465 : {
466 21393 : while (l)
467 : {
468 17504 : if (ILIST_INSN (l) == insn)
469 : return true;
470 17428 : l = ILIST_NEXT (l);
471 : }
472 :
473 : return false;
474 : }
475 :
476 : /* Used through _FOR_EACH. */
477 : inline bool
478 8271 : _list_iter_cond_insn (ilist_t l, insn_t *ip)
479 : {
480 8271 : if (l)
481 : {
482 5678 : *ip = ILIST_INSN (l);
483 5678 : return true;
484 : }
485 :
486 : return false;
487 : }
488 :
489 : #define ilist_iter_remove(IP) (_list_iter_remove (IP))
490 :
491 : typedef _list_iterator ilist_iterator;
492 : #define FOR_EACH_INSN(INSN, I, L) _FOR_EACH (insn, (INSN), (I), (L))
493 : #define FOR_EACH_INSN_1(INSN, I, LP) _FOR_EACH_1 (insn, (INSN), (I), (LP))
494 :
495 :
496 : /* Av set iterators. */
497 : typedef _list_iterator av_set_iterator;
498 : #define FOR_EACH_EXPR(EXPR, I, AV) _FOR_EACH (expr, (EXPR), (I), (AV))
499 : #define FOR_EACH_EXPR_1(EXPR, I, AV) _FOR_EACH_1 (expr, (EXPR), (I), (AV))
500 :
501 : inline bool
502 1536988 : _list_iter_cond_expr (av_set_t av, expr_t *exprp)
503 : {
504 1536988 : if (av)
505 : {
506 978164 : *exprp = _AV_SET_EXPR (av);
507 920767 : return true;
508 : }
509 :
510 : return false;
511 : }
512 :
513 :
514 : /* Def list iterators. */
515 : typedef _list_t def_list_t;
516 : typedef _list_iterator def_list_iterator;
517 :
518 : #define DEF_LIST_NEXT(L) (_LIST_NEXT (L))
519 : #define DEF_LIST_DEF(L) (&(L)->u.def)
520 :
521 : #define FOR_EACH_DEF(DEF, I, DEF_LIST) _FOR_EACH (def, (DEF), (I), (DEF_LIST))
522 :
523 : inline bool
524 12438 : _list_iter_cond_def (def_list_t def_list, def_t *def)
525 : {
526 12438 : if (def_list)
527 : {
528 7027 : *def = DEF_LIST_DEF (def_list);
529 7027 : return true;
530 : }
531 :
532 : return false;
533 : }
534 :
535 :
536 : /* InstructionData. Contains information about insn pattern. */
537 : struct idata_def
538 : {
539 : /* Type of the insn.
540 : o CALL_INSN - Call insn
541 : o JUMP_INSN - Jump insn
542 : o INSN - INSN that cannot be cloned
543 : o USE - INSN that can be cloned
544 : o SET - INSN that can be cloned and separable into lhs and rhs
545 : o PC - simplejump. Insns that simply redirect control flow should not
546 : have any dependencies. Sched-deps.c, though, might consider them as
547 : producers or consumers of certain registers. To avoid that we handle
548 : dependency for simple jumps ourselves. */
549 : int type;
550 :
551 : /* If insn is a SET, this is its left hand side. */
552 : rtx lhs;
553 :
554 : /* If insn is a SET, this is its right hand side. */
555 : rtx rhs;
556 :
557 : /* Registers that are set/used by this insn. This info is now gathered
558 : via sched-deps.cc. The downside of this is that we also use live info
559 : from flow that is accumulated in the basic blocks. These two infos
560 : can be slightly inconsistent, hence in the beginning we make a pass
561 : through CFG and calculating the conservative solution for the info in
562 : basic blocks. When this scheduler will be switched to use dataflow,
563 : this can be unified as df gives us both per basic block and per
564 : instruction info. Actually, we don't do that pass and just hope
565 : for the best. */
566 : regset reg_sets;
567 :
568 : regset reg_clobbers;
569 :
570 : regset reg_uses;
571 : };
572 :
573 : #define IDATA_TYPE(ID) ((ID)->type)
574 : #define IDATA_LHS(ID) ((ID)->lhs)
575 : #define IDATA_RHS(ID) ((ID)->rhs)
576 : #define IDATA_REG_SETS(ID) ((ID)->reg_sets)
577 : #define IDATA_REG_USES(ID) ((ID)->reg_uses)
578 : #define IDATA_REG_CLOBBERS(ID) ((ID)->reg_clobbers)
579 :
580 : /* Type to represent all needed info to emit an insn.
581 : This is a virtual equivalent of the insn.
582 : Every insn in the stream has an associated vinsn. This is used
583 : to reduce memory consumption basing on the fact that many insns
584 : don't change through the scheduler.
585 :
586 : vinsn can be either normal or unique.
587 : * Normal vinsn is the one, that can be cloned multiple times and typically
588 : corresponds to normal instruction.
589 :
590 : * Unique vinsn derivates from CALL, ASM, JUMP (for a while) and other
591 : unusual stuff. Such a vinsn is described by its INSN field, which is a
592 : reference to the original instruction. */
593 : struct vinsn_def
594 : {
595 : /* Associated insn. */
596 : rtx_insn *insn_rtx;
597 :
598 : /* Its description. */
599 : struct idata_def id;
600 :
601 : /* Hash of vinsn. It is computed either from pattern or from rhs using
602 : hash_rtx. It is not placed in ID for faster compares. */
603 : unsigned hash;
604 :
605 : /* Hash of the insn_rtx pattern. */
606 : unsigned hash_rtx;
607 :
608 : /* Smart pointer counter. */
609 : int count;
610 :
611 : /* Cached cost of the vinsn. To access it please use vinsn_cost (). */
612 : int cost;
613 :
614 : /* Mark insns that may trap so we don't move them through jumps. */
615 : bool may_trap_p;
616 : };
617 :
618 : #define VINSN_INSN_RTX(VI) ((VI)->insn_rtx)
619 : #define VINSN_PATTERN(VI) (PATTERN (VINSN_INSN_RTX (VI)))
620 :
621 : #define VINSN_ID(VI) (&((VI)->id))
622 : #define VINSN_HASH(VI) ((VI)->hash)
623 : #define VINSN_HASH_RTX(VI) ((VI)->hash_rtx)
624 : #define VINSN_TYPE(VI) (IDATA_TYPE (VINSN_ID (VI)))
625 : #define VINSN_SEPARABLE_P(VI) (VINSN_TYPE (VI) == SET)
626 : #define VINSN_CLONABLE_P(VI) (VINSN_SEPARABLE_P (VI) || VINSN_TYPE (VI) == USE)
627 : #define VINSN_UNIQUE_P(VI) (!VINSN_CLONABLE_P (VI))
628 : #define VINSN_LHS(VI) (IDATA_LHS (VINSN_ID (VI)))
629 : #define VINSN_RHS(VI) (IDATA_RHS (VINSN_ID (VI)))
630 : #define VINSN_REG_SETS(VI) (IDATA_REG_SETS (VINSN_ID (VI)))
631 : #define VINSN_REG_USES(VI) (IDATA_REG_USES (VINSN_ID (VI)))
632 : #define VINSN_REG_CLOBBERS(VI) (IDATA_REG_CLOBBERS (VINSN_ID (VI)))
633 : #define VINSN_COUNT(VI) ((VI)->count)
634 : #define VINSN_MAY_TRAP_P(VI) ((VI)->may_trap_p)
635 :
636 :
637 : /* An entry of the hashtable describing transformations happened when
638 : moving up through an insn. */
639 : struct transformed_insns
640 : {
641 : /* Previous vinsn. Used to find the proper element. */
642 : vinsn_t vinsn_old;
643 :
644 : /* A new vinsn. */
645 : vinsn_t vinsn_new;
646 :
647 : /* Speculative status. */
648 : ds_t ds;
649 :
650 : /* Type of transformation happened. */
651 : enum local_trans_type type;
652 :
653 : /* Whether a conflict on the target register happened. */
654 : bool was_target_conflict : 1;
655 :
656 : /* Whether a check was needed. */
657 : bool needs_check : 1;
658 : };
659 :
660 : /* Indexed by INSN_LUID, the collection of all data associated with
661 : a single instruction that is in the stream. */
662 8515 : class _sel_insn_data
663 : {
664 : public:
665 : /* The expression that contains vinsn for this insn and some
666 : flow-sensitive data like priority. */
667 : expr_def expr;
668 :
669 : /* If (WS_LEVEL == GLOBAL_LEVEL) then AV is empty. */
670 : int ws_level;
671 :
672 : /* A number that helps in defining a traversing order for a region. */
673 : int seqno;
674 :
675 : /* A liveness data computed above this insn. */
676 : regset live;
677 :
678 : /* An INSN_UID bit is set when deps analysis result is already known. */
679 : bitmap analyzed_deps;
680 :
681 : /* An INSN_UID bit is set when a hard dep was found, not set when
682 : no dependence is found. This is meaningful only when the analyzed_deps
683 : bitmap has its bit set. */
684 : bitmap found_deps;
685 :
686 : /* An INSN_UID bit is set when this is a bookkeeping insn generated from
687 : a parent with this uid. If a parent is a bookkeeping copy, all its
688 : originators are transitively included in this set. */
689 : bitmap originators;
690 :
691 : /* A hashtable caching the result of insn transformations through this one. */
692 : htab_t transformed_insns;
693 :
694 : /* A context incapsulating this insn. */
695 : class deps_desc deps_context;
696 :
697 : /* This field is initialized at the beginning of scheduling and is used
698 : to handle sched group instructions. If it is non-null, then it points
699 : to the instruction, which should be forced to schedule next. Such
700 : instructions are unique. */
701 : insn_t sched_next;
702 :
703 : /* Cycle at which insn was scheduled. It is greater than zero if insn was
704 : scheduled. This is used for bundling. */
705 : int sched_cycle;
706 :
707 : /* Cycle at which insn's data will be fully ready. */
708 : int ready_cycle;
709 :
710 : /* Speculations that are being checked by this insn. */
711 : ds_t spec_checked_ds;
712 :
713 : /* Whether the live set valid or not. */
714 : bool live_valid_p : 1;
715 : /* Insn is an ASM. */
716 : bool asm_p : 1;
717 :
718 : /* True when an insn is scheduled after we've determined that a stall is
719 : required.
720 : This is used when emulating the Haifa scheduler for bundling. */
721 : bool after_stall_p : 1;
722 : };
723 :
724 : typedef class _sel_insn_data sel_insn_data_def;
725 : typedef sel_insn_data_def *sel_insn_data_t;
726 :
727 : extern vec<sel_insn_data_def> s_i_d;
728 :
729 : /* Accessor macros for s_i_d. */
730 : #define SID(INSN) (&s_i_d[INSN_LUID (INSN)])
731 : #define SID_BY_UID(UID) (&s_i_d[LUID_BY_UID (UID)])
732 :
733 : extern sel_insn_data_def insn_sid (insn_t);
734 :
735 : #define INSN_ASM_P(INSN) (SID (INSN)->asm_p)
736 : #define INSN_SCHED_NEXT(INSN) (SID (INSN)->sched_next)
737 : #define INSN_ANALYZED_DEPS(INSN) (SID (INSN)->analyzed_deps)
738 : #define INSN_FOUND_DEPS(INSN) (SID (INSN)->found_deps)
739 : #define INSN_DEPS_CONTEXT(INSN) (SID (INSN)->deps_context)
740 : #define INSN_ORIGINATORS(INSN) (SID (INSN)->originators)
741 : #define INSN_ORIGINATORS_BY_UID(UID) (SID_BY_UID (UID)->originators)
742 : #define INSN_TRANSFORMED_INSNS(INSN) (SID (INSN)->transformed_insns)
743 :
744 : #define INSN_EXPR(INSN) (&SID (INSN)->expr)
745 : #define INSN_LIVE(INSN) (SID (INSN)->live)
746 : #define INSN_LIVE_VALID_P(INSN) (SID (INSN)->live_valid_p)
747 : #define INSN_VINSN(INSN) (EXPR_VINSN (INSN_EXPR (INSN)))
748 : #define INSN_TYPE(INSN) (VINSN_TYPE (INSN_VINSN (INSN)))
749 : #define INSN_SIMPLEJUMP_P(INSN) (INSN_TYPE (INSN) == PC)
750 : #define INSN_LHS(INSN) (VINSN_LHS (INSN_VINSN (INSN)))
751 : #define INSN_RHS(INSN) (VINSN_RHS (INSN_VINSN (INSN)))
752 : #define INSN_REG_SETS(INSN) (VINSN_REG_SETS (INSN_VINSN (INSN)))
753 : #define INSN_REG_CLOBBERS(INSN) (VINSN_REG_CLOBBERS (INSN_VINSN (INSN)))
754 : #define INSN_REG_USES(INSN) (VINSN_REG_USES (INSN_VINSN (INSN)))
755 : #define INSN_SCHED_TIMES(INSN) (EXPR_SCHED_TIMES (INSN_EXPR (INSN)))
756 : #define INSN_SEQNO(INSN) (SID (INSN)->seqno)
757 : #define INSN_AFTER_STALL_P(INSN) (SID (INSN)->after_stall_p)
758 : #define INSN_SCHED_CYCLE(INSN) (SID (INSN)->sched_cycle)
759 : #define INSN_READY_CYCLE(INSN) (SID (INSN)->ready_cycle)
760 : #define INSN_SPEC_CHECKED_DS(INSN) (SID (INSN)->spec_checked_ds)
761 :
762 : /* A global level shows whether an insn is valid or not. */
763 : extern int global_level;
764 :
765 : #define INSN_WS_LEVEL(INSN) (SID (INSN)->ws_level)
766 :
767 : extern av_set_t get_av_set (insn_t);
768 : extern int get_av_level (insn_t);
769 :
770 : #define AV_SET(INSN) (get_av_set (INSN))
771 : #define AV_LEVEL(INSN) (get_av_level (INSN))
772 : #define AV_SET_VALID_P(INSN) (AV_LEVEL (INSN) == global_level)
773 :
774 : /* A list of fences currently in the works. */
775 : extern flist_t fences;
776 :
777 : /* A NOP pattern used as a placeholder for real insns. */
778 : extern rtx nop_pattern;
779 :
780 : /* An insn that 'contained' in EXIT block. */
781 : extern rtx_insn *exit_insn;
782 :
783 : /* Provide a separate luid for the insn. */
784 : #define INSN_INIT_TODO_LUID (1)
785 :
786 : /* Initialize s_s_i_d. */
787 : #define INSN_INIT_TODO_SSID (2)
788 :
789 : /* Initialize data for simplejump. */
790 : #define INSN_INIT_TODO_SIMPLEJUMP (4)
791 :
792 : /* Return true if INSN is a local NOP. The nop is local in the sense that
793 : it was emitted by the scheduler as a temporary insn and will soon be
794 : deleted. These nops are identified by their pattern. */
795 : #define INSN_NOP_P(INSN) (PATTERN (INSN) == nop_pattern)
796 :
797 : /* Return true if INSN is linked into instruction stream.
798 : NB: It is impossible for INSN to have one field null and the other not
799 : null: gcc_assert ((PREV_INSN (INSN) == NULL_RTX)
800 : == (NEXT_INSN (INSN) == NULL_RTX)) is valid. */
801 : #define INSN_IN_STREAM_P(INSN) (PREV_INSN (INSN) && NEXT_INSN (INSN))
802 :
803 : /* Return true if INSN is in current fence. */
804 : #define IN_CURRENT_FENCE_P(INSN) (flist_lookup (fences, INSN) != NULL)
805 :
806 : /* Marks loop as being considered for pipelining. */
807 : #define MARK_LOOP_FOR_PIPELINING(LOOP) ((LOOP)->aux = (void *)(size_t)(1))
808 : #define LOOP_MARKED_FOR_PIPELINING_P(LOOP) ((size_t)((LOOP)->aux))
809 :
810 : /* Saved loop preheader to transfer when scheduling the loop. */
811 : #define LOOP_PREHEADER_BLOCKS(LOOP) ((size_t)((LOOP)->aux) == 1 \
812 : ? NULL \
813 : : ((vec<basic_block> *) (LOOP)->aux))
814 : #define SET_LOOP_PREHEADER_BLOCKS(LOOP,BLOCKS) ((LOOP)->aux \
815 : = (BLOCKS != NULL \
816 : ? BLOCKS \
817 : : (LOOP)->aux))
818 :
819 : extern bitmap blocks_to_reschedule;
820 :
821 :
822 : /* A variable to track which part of rtx we are scanning in
823 : sched-deps.cc: sched_analyze_insn (). */
824 : enum deps_where_t
825 : {
826 : DEPS_IN_INSN,
827 : DEPS_IN_LHS,
828 : DEPS_IN_RHS,
829 : DEPS_IN_NOWHERE
830 : };
831 :
832 :
833 : /* Per basic block data for the whole CFG. */
834 : struct sel_global_bb_info_def
835 : {
836 : /* For each bb header this field contains a set of live registers.
837 : For all other insns this field has a NULL.
838 : We also need to know LV sets for the instructions, that are immediately
839 : after the border of the region. */
840 : regset lv_set;
841 :
842 : /* Status of LV_SET.
843 : true - block has usable LV_SET.
844 : false - block's LV_SET should be recomputed. */
845 : bool lv_set_valid_p;
846 : };
847 :
848 : typedef sel_global_bb_info_def *sel_global_bb_info_t;
849 :
850 :
851 : /* Per basic block data. This array is indexed by basic block index. */
852 : extern vec<sel_global_bb_info_def> sel_global_bb_info;
853 :
854 : extern void sel_extend_global_bb_info (void);
855 : extern void sel_finish_global_bb_info (void);
856 :
857 : /* Get data for BB. */
858 : #define SEL_GLOBAL_BB_INFO(BB) \
859 : (&sel_global_bb_info[(BB)->index])
860 :
861 : /* Access macros. */
862 : #define BB_LV_SET(BB) (SEL_GLOBAL_BB_INFO (BB)->lv_set)
863 : #define BB_LV_SET_VALID_P(BB) (SEL_GLOBAL_BB_INFO (BB)->lv_set_valid_p)
864 :
865 : /* Per basic block data for the region. */
866 : struct sel_region_bb_info_def
867 : {
868 : /* This insn stream is constructed in such a way that it should be
869 : traversed by PREV_INSN field - (*not* NEXT_INSN). */
870 : rtx_insn *note_list;
871 :
872 : /* Cached availability set at the beginning of a block.
873 : See also AV_LEVEL () for conditions when this av_set can be used. */
874 : av_set_t av_set;
875 :
876 : /* If (AV_LEVEL == GLOBAL_LEVEL) then AV is valid. */
877 : int av_level;
878 : };
879 :
880 : typedef sel_region_bb_info_def *sel_region_bb_info_t;
881 :
882 :
883 : /* Per basic block data. This array is indexed by basic block index. */
884 : extern vec<sel_region_bb_info_def> sel_region_bb_info;
885 :
886 : /* Get data for BB. */
887 : #define SEL_REGION_BB_INFO(BB) (&sel_region_bb_info[(BB)->index])
888 :
889 : /* Get BB's note_list.
890 : A note_list is a list of various notes that was scattered across BB
891 : before scheduling, and will be appended at the beginning of BB after
892 : scheduling is finished. */
893 : #define BB_NOTE_LIST(BB) (SEL_REGION_BB_INFO (BB)->note_list)
894 :
895 : #define BB_AV_SET(BB) (SEL_REGION_BB_INFO (BB)->av_set)
896 : #define BB_AV_LEVEL(BB) (SEL_REGION_BB_INFO (BB)->av_level)
897 : #define BB_AV_SET_VALID_P(BB) (BB_AV_LEVEL (BB) == global_level)
898 :
899 : /* Used in bb_in_ebb_p. */
900 : extern bitmap_head *forced_ebb_heads;
901 :
902 : /* The loop nest being pipelined. */
903 : extern class loop *current_loop_nest;
904 :
905 : /* Saves pipelined blocks. Bitmap is indexed by bb->index. */
906 : extern sbitmap bbs_pipelined;
907 :
908 : /* Various flags. */
909 : extern bool enable_moveup_set_path_p;
910 : extern bool pipelining_p;
911 : extern bool bookkeeping_p;
912 : extern int max_insns_to_rename;
913 : extern bool preheader_removed;
914 :
915 : /* Software lookahead window size.
916 : According to the results in Nakatani and Ebcioglu [1993], window size of 16
917 : is enough to extract most ILP in integer code. */
918 : #define MAX_WS (param_selsched_max_lookahead)
919 :
920 : extern regset sel_all_regs;
921 :
922 :
923 : /* Successor iterator backend. */
924 : struct succ_iterator
925 : {
926 : /* True if we're at BB end. */
927 : bool bb_end;
928 :
929 : /* An edge on which we're iterating. */
930 : edge e1;
931 :
932 : /* The previous edge saved after skipping empty blocks. */
933 : edge e2;
934 :
935 : /* Edge iterator used when there are successors in other basic blocks. */
936 : edge_iterator ei;
937 :
938 : /* Successor block we're traversing. */
939 : basic_block bb;
940 :
941 : /* Flags that are passed to the iterator. We return only successors
942 : that comply to these flags. */
943 : short flags;
944 :
945 : /* When flags include SUCCS_ALL, this will be set to the exact type
946 : of the successor we're traversing now. */
947 : short current_flags;
948 :
949 : /* If skip to loop exits, save here information about loop exits. */
950 : int current_exit;
951 : vec<edge> loop_exits;
952 : };
953 :
954 : /* A structure returning all successor's information. */
955 : struct succs_info
956 : {
957 : /* Flags that these successors were computed with. */
958 : short flags;
959 :
960 : /* Successors that correspond to the flags. */
961 : insn_vec_t succs_ok;
962 :
963 : /* Their probabilities. As of now, we don't need this for other
964 : successors. */
965 : vec<int> probs_ok;
966 :
967 : /* Other successors. */
968 : insn_vec_t succs_other;
969 :
970 : /* Probability of all successors. */
971 : int all_prob;
972 :
973 : /* The number of all successors. */
974 : int all_succs_n;
975 :
976 : /* The number of good successors. */
977 : int succs_ok_n;
978 : };
979 :
980 : /* Some needed definitions. */
981 : extern basic_block after_recovery;
982 :
983 : extern rtx_insn *sel_bb_head (basic_block);
984 : extern rtx_insn *sel_bb_end (basic_block);
985 : extern bool sel_bb_empty_p (basic_block);
986 : extern bool in_current_region_p (basic_block);
987 :
988 : /* True when BB is a header of the inner loop. */
989 : inline bool
990 418 : inner_loop_header_p (basic_block bb)
991 : {
992 418 : class loop *inner_loop;
993 :
994 418 : if (!current_loop_nest)
995 : return false;
996 :
997 266 : if (bb == EXIT_BLOCK_PTR_FOR_FN (cfun))
998 : return false;
999 :
1000 266 : inner_loop = bb->loop_father;
1001 266 : if (inner_loop == current_loop_nest)
1002 : return false;
1003 :
1004 : /* If successor belongs to another loop. */
1005 119 : if (bb == inner_loop->header
1006 119 : && flow_bb_inside_loop_p (current_loop_nest, bb))
1007 : {
1008 : /* Could be '=' here because of wrong loop depths. */
1009 60 : gcc_assert (loop_depth (inner_loop) >= loop_depth (current_loop_nest));
1010 : return true;
1011 : }
1012 :
1013 : return false;
1014 : }
1015 :
1016 : /* Return exit edges of LOOP, filtering out edges with the same dest bb. */
1017 : inline vec<edge>
1018 30 : get_loop_exit_edges_unique_dests (const class loop *loop)
1019 : {
1020 30 : vec<edge> edges = vNULL;
1021 30 : struct loop_exit *exit;
1022 :
1023 30 : gcc_assert (loop->latch != EXIT_BLOCK_PTR_FOR_FN (cfun)
1024 : && current_loops->state & LOOPS_HAVE_RECORDED_EXITS);
1025 :
1026 75 : for (exit = loop->exits->next; exit->e; exit = exit->next)
1027 : {
1028 : int i;
1029 : edge e;
1030 63 : bool was_dest = false;
1031 :
1032 63 : for (i = 0; edges.iterate (i, &e); i++)
1033 18 : if (e->dest == exit->e->dest)
1034 : {
1035 : was_dest = true;
1036 : break;
1037 : }
1038 :
1039 45 : if (!was_dest)
1040 45 : edges.safe_push (exit->e);
1041 : }
1042 30 : return edges;
1043 : }
1044 :
1045 : inline bool
1046 28489 : sel_bb_empty_or_nop_p (basic_block bb)
1047 : {
1048 28489 : insn_t first = sel_bb_head (bb), last;
1049 :
1050 28489 : if (first == NULL_RTX)
1051 : return true;
1052 :
1053 28482 : if (!INSN_NOP_P (first))
1054 : return false;
1055 :
1056 1138 : if (bb == EXIT_BLOCK_PTR_FOR_FN (cfun))
1057 : return false;
1058 :
1059 73 : last = sel_bb_end (bb);
1060 73 : if (first != last)
1061 3 : return false;
1062 :
1063 : return true;
1064 : }
1065 :
1066 : /* Collect all loop exits recursively, skipping empty BBs between them.
1067 : E.g. if BB is a loop header which has several loop exits,
1068 : traverse all of them and if any of them turns out to be another loop header
1069 : (after skipping empty BBs), add its loop exits to the resulting vector
1070 : as well. */
1071 : inline vec<edge>
1072 403 : get_all_loop_exits (basic_block bb)
1073 : {
1074 403 : vec<edge> exits = vNULL;
1075 :
1076 : /* If bb is empty, and we're skipping to loop exits, then
1077 : consider bb as a possible gate to the inner loop now. */
1078 403 : while (sel_bb_empty_or_nop_p (bb)
1079 7 : && in_current_region_p (bb)
1080 403 : && EDGE_COUNT (bb->succs) > 0)
1081 : {
1082 0 : bb = single_succ (bb);
1083 :
1084 : /* This empty block could only lead outside the region. */
1085 0 : gcc_assert (! in_current_region_p (bb));
1086 : }
1087 :
1088 : /* And now check whether we should skip over inner loop. */
1089 403 : if (inner_loop_header_p (bb))
1090 : {
1091 30 : class loop *this_loop;
1092 30 : class loop *pred_loop = NULL;
1093 30 : int i;
1094 30 : unsigned this_depth;
1095 30 : edge e;
1096 :
1097 30 : for (this_loop = bb->loop_father;
1098 60 : this_loop && this_loop != current_loop_nest;
1099 30 : this_loop = loop_outer (this_loop))
1100 30 : pred_loop = this_loop;
1101 :
1102 30 : this_loop = pred_loop;
1103 30 : gcc_assert (this_loop != NULL);
1104 :
1105 30 : exits = get_loop_exit_edges_unique_dests (this_loop);
1106 30 : this_depth = loop_depth (this_loop);
1107 :
1108 : /* Traverse all loop headers. Be careful not to go back
1109 : to the outer loop's header (see PR 84206). */
1110 75 : for (i = 0; exits.iterate (i, &e); i++)
1111 45 : if ((in_current_region_p (e->dest)
1112 15 : || (inner_loop_header_p (e->dest)))
1113 75 : && loop_depth (e->dest->loop_father) >= this_depth)
1114 : {
1115 0 : auto_vec<edge> next_exits = get_all_loop_exits (e->dest);
1116 :
1117 0 : if (next_exits.exists ())
1118 : {
1119 : int j;
1120 : edge ne;
1121 :
1122 : /* Add all loop exits for the current edge into the
1123 : resulting vector. */
1124 0 : for (j = 0; next_exits.iterate (j, &ne); j++)
1125 0 : exits.safe_push (ne);
1126 :
1127 : /* Remove the original edge. */
1128 0 : exits.ordered_remove (i);
1129 :
1130 : /* Decrease the loop counter so we won't skip anything. */
1131 0 : i--;
1132 0 : continue;
1133 0 : }
1134 0 : }
1135 : }
1136 :
1137 403 : return exits;
1138 : }
1139 :
1140 : /* Flags to pass to compute_succs_info and FOR_EACH_SUCC.
1141 : Any successor will fall into exactly one category. */
1142 :
1143 : /* Include normal successors. */
1144 : #define SUCCS_NORMAL (1)
1145 :
1146 : /* Include back-edge successors. */
1147 : #define SUCCS_BACK (2)
1148 :
1149 : /* Include successors that are outside of the current region. */
1150 : #define SUCCS_OUT (4)
1151 :
1152 : /* When pipelining of the outer loops is enabled, skip innermost loops
1153 : to their exits. */
1154 : #define SUCCS_SKIP_TO_LOOP_EXITS (8)
1155 :
1156 : /* Include all successors. */
1157 : #define SUCCS_ALL (SUCCS_NORMAL | SUCCS_BACK | SUCCS_OUT)
1158 :
1159 : /* We need to return a succ_iterator to avoid 'uninitialized' warning
1160 : during bootstrap. */
1161 : inline succ_iterator
1162 28136 : _succ_iter_start (insn_t *succp, insn_t insn, int flags)
1163 : {
1164 28136 : succ_iterator i;
1165 :
1166 28136 : basic_block bb = BLOCK_FOR_INSN (insn);
1167 :
1168 28136 : gcc_assert (INSN_P (insn) || NOTE_INSN_BASIC_BLOCK_P (insn));
1169 :
1170 28136 : i.flags = flags;
1171 :
1172 : /* Avoid 'uninitialized' warning. */
1173 28136 : *succp = NULL;
1174 28136 : i.e1 = NULL;
1175 28136 : i.e2 = NULL;
1176 28136 : i.bb = bb;
1177 28136 : i.current_flags = 0;
1178 28136 : i.current_exit = -1;
1179 28136 : i.loop_exits.create (0);
1180 :
1181 28136 : if (bb != EXIT_BLOCK_PTR_FOR_FN (cfun) && BB_END (bb) != insn)
1182 : {
1183 11028 : i.bb_end = false;
1184 :
1185 : /* Avoid 'uninitialized' warning. */
1186 11028 : i.ei.index = 0;
1187 11028 : i.ei.container = 0;
1188 : }
1189 : else
1190 : {
1191 17108 : i.ei = ei_start (bb->succs);
1192 17108 : i.bb_end = true;
1193 : }
1194 :
1195 28136 : return i;
1196 : }
1197 :
1198 : inline bool
1199 64658 : _succ_iter_cond (succ_iterator *ip, insn_t *succp, insn_t insn,
1200 : bool check (edge, succ_iterator *))
1201 : {
1202 64658 : if (!ip->bb_end)
1203 : {
1204 : /* When we're in a middle of a basic block, return
1205 : the next insn immediately, but only when SUCCS_NORMAL is set. */
1206 22056 : if (*succp != NULL || (ip->flags & SUCCS_NORMAL) == 0)
1207 : return false;
1208 :
1209 11028 : *succp = NEXT_INSN (insn);
1210 11028 : ip->current_flags = SUCCS_NORMAL;
1211 11028 : return true;
1212 : }
1213 : else
1214 : {
1215 42662 : while (1)
1216 : {
1217 42632 : edge e_tmp = NULL;
1218 :
1219 : /* First, try loop exits, if we have them. */
1220 42632 : if (ip->loop_exits.exists ())
1221 : {
1222 75 : do
1223 : {
1224 75 : ip->loop_exits.iterate (ip->current_exit, &e_tmp);
1225 75 : ip->current_exit++;
1226 : }
1227 135 : while (e_tmp && !check (e_tmp, ip));
1228 :
1229 60 : if (!e_tmp)
1230 30 : ip->loop_exits.release ();
1231 : }
1232 :
1233 : /* If we have found a successor, then great. */
1234 42632 : if (e_tmp)
1235 : {
1236 30 : ip->e1 = e_tmp;
1237 30 : break;
1238 : }
1239 :
1240 : /* If not, then try the next edge. */
1241 45099 : while (ei_cond (ip->ei, &(ip->e1)))
1242 : {
1243 28044 : basic_block bb = ip->e1->dest;
1244 :
1245 : /* Consider bb as a possible loop header. */
1246 28044 : if ((ip->flags & SUCCS_SKIP_TO_LOOP_EXITS)
1247 3574 : && flag_sel_sched_pipelining_outer_loops
1248 28494 : && (!in_current_region_p (bb)
1249 200 : || BLOCK_TO_BB (ip->bb->index)
1250 200 : < BLOCK_TO_BB (bb->index)))
1251 : {
1252 : /* Get all loop exits recursively. */
1253 403 : ip->loop_exits = get_all_loop_exits (bb);
1254 :
1255 403 : if (ip->loop_exits.exists ())
1256 : {
1257 30 : ip->current_exit = 0;
1258 : /* Move the iterator now, because we won't do
1259 : succ_iter_next until loop exits will end. */
1260 30 : ei_next (&(ip->ei));
1261 30 : break;
1262 : }
1263 : }
1264 :
1265 : /* bb is not a loop header, check as usual. */
1266 28014 : if (check (ip->e1, ip))
1267 : break;
1268 :
1269 2497 : ei_next (&(ip->ei));
1270 : }
1271 :
1272 : /* If loop_exits are non null, we have found an inner loop;
1273 : do one more iteration to fetch an edge from these exits. */
1274 42602 : if (ip->loop_exits.exists ())
1275 30 : continue;
1276 :
1277 : /* Otherwise, we've found an edge in a usual way. Break now. */
1278 : break;
1279 30 : }
1280 :
1281 42602 : if (ip->e1)
1282 : {
1283 25547 : basic_block bb = ip->e2->dest;
1284 :
1285 25547 : if (bb == EXIT_BLOCK_PTR_FOR_FN (cfun) || bb == after_recovery)
1286 755 : *succp = exit_insn;
1287 : else
1288 : {
1289 24792 : *succp = sel_bb_head (bb);
1290 :
1291 24792 : gcc_assert (ip->flags != SUCCS_NORMAL
1292 : || *succp == NEXT_INSN (bb_note (bb)));
1293 24792 : gcc_assert (BLOCK_FOR_INSN (*succp) == bb);
1294 : }
1295 :
1296 : return true;
1297 : }
1298 : else
1299 : return false;
1300 : }
1301 : }
1302 :
1303 : inline void
1304 36522 : _succ_iter_next (succ_iterator *ip)
1305 : {
1306 36522 : gcc_assert (!ip->e2 || ip->e1);
1307 :
1308 36522 : if (ip->bb_end && ip->e1 && !ip->loop_exits.exists ())
1309 25464 : ei_next (&(ip->ei));
1310 36522 : }
1311 :
1312 : /* Returns true when E1 is an eligible successor edge, possibly skipping
1313 : empty blocks. When E2P is not null, the resulting edge is written there.
1314 : FLAGS are used to specify whether back edges and out-of-region edges
1315 : should be considered. */
1316 : inline bool
1317 28059 : _eligible_successor_edge_p (edge e1, succ_iterator *ip)
1318 : {
1319 28059 : edge e2 = e1;
1320 28059 : basic_block bb;
1321 28059 : int flags = ip->flags;
1322 28059 : bool src_outside_rgn = !in_current_region_p (e1->src);
1323 :
1324 28059 : gcc_assert (flags != 0);
1325 :
1326 28059 : if (src_outside_rgn)
1327 : {
1328 : /* Any successor of the block that is outside current region is
1329 : ineligible, except when we're skipping to loop exits. */
1330 45 : gcc_assert (flags & (SUCCS_OUT | SUCCS_SKIP_TO_LOOP_EXITS));
1331 :
1332 45 : if (flags & SUCCS_OUT)
1333 : return false;
1334 : }
1335 :
1336 28059 : bb = e2->dest;
1337 :
1338 : /* Skip empty blocks, but be careful not to leave the region. */
1339 28206 : while (1)
1340 : {
1341 28206 : if (!sel_bb_empty_p (bb))
1342 : {
1343 28086 : edge ne;
1344 28086 : basic_block nbb;
1345 :
1346 28086 : if (!sel_bb_empty_or_nop_p (bb))
1347 : break;
1348 :
1349 70 : ne = EDGE_SUCC (bb, 0);
1350 70 : nbb = ne->dest;
1351 :
1352 70 : if (!in_current_region_p (nbb)
1353 70 : && !(flags & SUCCS_OUT))
1354 : break;
1355 :
1356 70 : e2 = ne;
1357 70 : bb = nbb;
1358 70 : continue;
1359 70 : }
1360 :
1361 120 : if (!in_current_region_p (bb)
1362 120 : && !(flags & SUCCS_OUT))
1363 : return false;
1364 :
1365 77 : if (EDGE_COUNT (bb->succs) == 0)
1366 : return false;
1367 :
1368 77 : e2 = EDGE_SUCC (bb, 0);
1369 77 : bb = e2->dest;
1370 : }
1371 :
1372 : /* Save the second edge for later checks. */
1373 28016 : ip->e2 = e2;
1374 :
1375 28016 : if (in_current_region_p (bb))
1376 : {
1377 : /* BLOCK_TO_BB sets topological order of the region here.
1378 : It is important to use real predecessor here, which is ip->bb,
1379 : as we may well have e1->src outside current region,
1380 : when skipping to loop exits. */
1381 16894 : bool succeeds_in_top_order = (BLOCK_TO_BB (ip->bb->index)
1382 16894 : < BLOCK_TO_BB (bb->index));
1383 :
1384 : /* This is true for the all cases except the last one. */
1385 16894 : ip->current_flags = SUCCS_NORMAL;
1386 :
1387 : /* We are advancing forward in the region, as usual. */
1388 16894 : if (succeeds_in_top_order)
1389 : {
1390 : /* We are skipping to loop exits here. */
1391 14553 : gcc_assert (!src_outside_rgn
1392 : || flag_sel_sched_pipelining_outer_loops);
1393 14553 : return !!(flags & SUCCS_NORMAL);
1394 : }
1395 :
1396 : /* This is a back edge. During pipelining we ignore back edges,
1397 : but only when it leads to the same loop. It can lead to the header
1398 : of the outer loop, which will also be the preheader of
1399 : the current loop. */
1400 2341 : if (pipelining_p
1401 1790 : && e1->src->loop_father == bb->loop_father)
1402 1790 : return !!(flags & SUCCS_NORMAL);
1403 :
1404 : /* A back edge should be requested explicitly. */
1405 551 : ip->current_flags = SUCCS_BACK;
1406 551 : return !!(flags & SUCCS_BACK);
1407 : }
1408 :
1409 11122 : ip->current_flags = SUCCS_OUT;
1410 11122 : return !!(flags & SUCCS_OUT);
1411 : }
1412 :
1413 : #define FOR_EACH_SUCC_1(SUCC, ITER, INSN, FLAGS) \
1414 : for ((ITER) = _succ_iter_start (&(SUCC), (INSN), (FLAGS)); \
1415 : _succ_iter_cond (&(ITER), &(SUCC), (INSN), _eligible_successor_edge_p); \
1416 : _succ_iter_next (&(ITER)))
1417 :
1418 : #define FOR_EACH_SUCC(SUCC, ITER, INSN) \
1419 : FOR_EACH_SUCC_1 (SUCC, ITER, INSN, SUCCS_NORMAL)
1420 :
1421 : /* Return the current edge along which a successor was built. */
1422 : #define SUCC_ITER_EDGE(ITER) ((ITER)->e1)
1423 :
1424 : /* Return the next block of BB not running into inconsistencies. */
1425 : inline basic_block
1426 1469 : bb_next_bb (basic_block bb)
1427 : {
1428 1469 : switch (EDGE_COUNT (bb->succs))
1429 : {
1430 16 : case 0:
1431 16 : return bb->next_bb;
1432 :
1433 473 : case 1:
1434 473 : return single_succ (bb);
1435 :
1436 972 : case 2:
1437 972 : return FALLTHRU_EDGE (bb)->dest;
1438 :
1439 8 : default:
1440 8 : return bb->next_bb;
1441 : }
1442 : }
1443 :
1444 :
1445 :
1446 : /* Functions that are used in sel-sched.cc. */
1447 :
1448 : /* List functions. */
1449 : extern ilist_t ilist_copy (ilist_t);
1450 : extern ilist_t ilist_invert (ilist_t);
1451 : extern void blist_add (blist_t *, insn_t, ilist_t, deps_t);
1452 : extern void blist_remove (blist_t *);
1453 : extern void flist_tail_init (flist_tail_t);
1454 :
1455 : extern fence_t flist_lookup (flist_t, insn_t);
1456 : extern void flist_clear (flist_t *);
1457 : extern void def_list_add (def_list_t *, insn_t, unsigned int);
1458 :
1459 : /* Target context functions. */
1460 : extern tc_t create_target_context (bool);
1461 : extern void set_target_context (tc_t);
1462 : extern void reset_target_context (tc_t, bool);
1463 :
1464 : /* Deps context functions. */
1465 : extern void advance_deps_context (deps_t, insn_t);
1466 :
1467 : /* Fences functions. */
1468 : extern void init_fences (insn_t);
1469 : extern void add_clean_fence_to_fences (flist_tail_t, insn_t, fence_t);
1470 : extern void add_dirty_fence_to_fences (flist_tail_t, insn_t, fence_t);
1471 : extern void move_fence_to_fences (flist_t, flist_tail_t);
1472 :
1473 : /* Pool functions. */
1474 : extern regset get_regset_from_pool (void);
1475 : extern regset get_clear_regset_from_pool (void);
1476 : extern void return_regset_to_pool (regset);
1477 : extern void free_regset_pool (void);
1478 :
1479 : extern insn_t get_nop_from_pool (insn_t);
1480 : extern void return_nop_to_pool (insn_t, bool);
1481 : extern void free_nop_pool (void);
1482 :
1483 : /* Vinsns functions. */
1484 : extern bool vinsn_separable_p (vinsn_t);
1485 : extern bool vinsn_cond_branch_p (vinsn_t);
1486 : extern void recompute_vinsn_lhs_rhs (vinsn_t);
1487 : extern int sel_vinsn_cost (vinsn_t);
1488 : extern insn_t sel_gen_insn_from_rtx_after (rtx, expr_t, int, insn_t);
1489 : extern insn_t sel_gen_recovery_insn_from_rtx_after (rtx, expr_t, int, insn_t);
1490 : extern insn_t sel_gen_insn_from_expr_after (expr_t, vinsn_t, int, insn_t);
1491 : extern insn_t sel_move_insn (expr_t, int, insn_t);
1492 : extern void vinsn_attach (vinsn_t);
1493 : extern void vinsn_detach (vinsn_t);
1494 : extern vinsn_t vinsn_copy (vinsn_t, bool);
1495 : extern bool vinsn_equal_p (vinsn_t, vinsn_t);
1496 :
1497 : /* EXPR functions. */
1498 : extern void copy_expr (expr_t, expr_t);
1499 : extern void copy_expr_onside (expr_t, expr_t);
1500 : extern void merge_expr_data (expr_t, expr_t, insn_t);
1501 : extern void merge_expr (expr_t, expr_t, insn_t);
1502 : extern void clear_expr (expr_t);
1503 : extern unsigned expr_dest_regno (expr_t);
1504 : extern rtx expr_dest_reg (expr_t);
1505 : extern int find_in_history_vect (vec<expr_history_def> ,
1506 : rtx, vinsn_t, bool);
1507 : extern void insert_in_history_vect (vec<expr_history_def> *,
1508 : unsigned, enum local_trans_type,
1509 : vinsn_t, vinsn_t, ds_t);
1510 : extern void mark_unavailable_targets (av_set_t, av_set_t, regset);
1511 : extern int speculate_expr (expr_t, ds_t);
1512 :
1513 : /* Av set functions. */
1514 : extern void av_set_add (av_set_t *, expr_t);
1515 : extern void av_set_iter_remove (av_set_iterator *);
1516 : extern expr_t av_set_lookup (av_set_t, vinsn_t);
1517 : extern expr_t merge_with_other_exprs (av_set_t *, av_set_iterator *, expr_t);
1518 : extern bool av_set_is_in_p (av_set_t, vinsn_t);
1519 : extern av_set_t av_set_copy (av_set_t);
1520 : extern void av_set_union_and_clear (av_set_t *, av_set_t *, insn_t);
1521 : extern void av_set_union_and_live (av_set_t *, av_set_t *, regset, regset, insn_t);
1522 : extern void av_set_clear (av_set_t *);
1523 : extern void av_set_leave_one_nonspec (av_set_t *);
1524 : extern expr_t av_set_element (av_set_t, int);
1525 : extern void av_set_substract_cond_branches (av_set_t *);
1526 : extern void av_set_split_usefulness (av_set_t, int, int);
1527 : extern void av_set_code_motion_filter (av_set_t *, av_set_t);
1528 :
1529 : extern void sel_init_global_and_expr (bb_vec_t);
1530 : extern void sel_finish_global_and_expr (void);
1531 :
1532 : extern regset compute_live (insn_t);
1533 : extern bool register_unavailable_p (regset, rtx);
1534 :
1535 : /* Dependence analysis functions. */
1536 : extern void sel_clear_has_dependence (void);
1537 : extern ds_t has_dependence_p (expr_t, insn_t, ds_t **);
1538 :
1539 : extern int tick_check_p (expr_t, deps_t, fence_t);
1540 :
1541 : /* Functions to work with insns. */
1542 : extern bool lhs_of_insn_equals_to_dest_p (insn_t, rtx);
1543 : extern void get_dest_and_mode (rtx, rtx *, machine_mode *);
1544 :
1545 : extern bool bookkeeping_can_be_created_if_moved_through_p (insn_t);
1546 : extern bool sel_remove_insn (insn_t, bool, bool);
1547 : extern bool bb_header_p (insn_t);
1548 :
1549 : /* Basic block and CFG functions. */
1550 :
1551 : extern rtx_insn *sel_bb_head (basic_block);
1552 : extern bool sel_bb_head_p (insn_t);
1553 : extern rtx_insn *sel_bb_end (basic_block);
1554 : extern bool sel_bb_end_p (insn_t);
1555 : extern bool sel_bb_empty_p (basic_block);
1556 :
1557 : extern bool in_current_region_p (basic_block);
1558 : extern basic_block fallthru_bb_of_jump (const rtx_insn *);
1559 :
1560 : extern void sel_init_bbs (bb_vec_t);
1561 : extern void sel_finish_bbs (void);
1562 :
1563 : extern struct succs_info * compute_succs_info (insn_t, short);
1564 : extern void free_succs_info (struct succs_info *);
1565 : extern bool sel_insn_has_single_succ_p (insn_t, int);
1566 : extern bool sel_num_cfg_preds_gt_1 (insn_t);
1567 : extern int get_seqno_by_preds (rtx_insn *);
1568 :
1569 : extern bool bb_ends_ebb_p (basic_block);
1570 : extern bool in_same_ebb_p (insn_t, insn_t);
1571 :
1572 : extern bool tidy_control_flow (basic_block, bool);
1573 : extern void free_bb_note_pool (void);
1574 :
1575 : extern void purge_empty_blocks (void);
1576 : extern basic_block sel_split_edge (edge);
1577 : extern basic_block sel_create_recovery_block (insn_t);
1578 : extern bool sel_redirect_edge_and_branch (edge, basic_block);
1579 : extern void sel_redirect_edge_and_branch_force (edge, basic_block);
1580 : extern void sel_init_pipelining (void);
1581 : extern void sel_finish_pipelining (void);
1582 : extern void sel_sched_region (int);
1583 : extern loop_p get_loop_nest_for_rgn (unsigned int);
1584 : extern bool considered_for_pipelining_p (class loop *);
1585 : extern void make_region_from_loop_preheader (vec<basic_block> *&);
1586 : extern void sel_add_loop_preheaders (bb_vec_t *);
1587 : extern bool sel_is_loop_preheader_p (basic_block);
1588 : extern void clear_outdated_rtx_info (basic_block);
1589 : extern void free_data_sets (basic_block);
1590 : extern void exchange_data_sets (basic_block, basic_block);
1591 :
1592 : extern void sel_register_cfg_hooks (void);
1593 : extern void sel_unregister_cfg_hooks (void);
1594 :
1595 : /* Expression transformation routines. */
1596 : extern rtx_insn *create_insn_rtx_from_pattern (rtx, rtx);
1597 : extern vinsn_t create_vinsn_from_insn_rtx (rtx_insn *, bool);
1598 : extern rtx_insn *create_copy_of_insn_rtx (rtx);
1599 : extern void change_vinsn_in_expr (expr_t, vinsn_t);
1600 :
1601 : /* Various initialization functions. */
1602 : extern void init_lv_sets (void);
1603 : extern void free_lv_sets (void);
1604 : extern void setup_nop_and_exit_insns (void);
1605 : extern void free_nop_and_exit_insns (void);
1606 : extern void free_data_for_scheduled_insn (insn_t);
1607 : extern void setup_nop_vinsn (void);
1608 : extern void free_nop_vinsn (void);
1609 : extern void sel_set_sched_flags (void);
1610 : extern void sel_setup_sched_infos (void);
1611 : extern void alloc_sched_pools (void);
1612 : extern void free_sched_pools (void);
1613 :
1614 : #endif /* GCC_SEL_SCHED_IR_H */
|