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