forked from jcmvbkbc/gcc-xtensa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsel-sched-ir.c
6430 lines (5289 loc) · 169 KB
/
sel-sched-ir.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Instruction scheduling pass. Selective scheduler and pipeliner.
Copyright (C) 2006-2013 Free Software Foundation, Inc.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "diagnostic-core.h"
#include "rtl.h"
#include "tm_p.h"
#include "hard-reg-set.h"
#include "regs.h"
#include "function.h"
#include "flags.h"
#include "insn-config.h"
#include "insn-attr.h"
#include "except.h"
#include "recog.h"
#include "params.h"
#include "target.h"
#include "sched-int.h"
#include "ggc.h"
#include "tree.h"
#include "vec.h"
#include "langhooks.h"
#include "rtlhooks-def.h"
#include "emit-rtl.h" /* FIXME: Can go away once crtl is moved to rtl.h. */
#ifdef INSN_SCHEDULING
#include "sel-sched-ir.h"
/* We don't have to use it except for sel_print_insn. */
#include "sel-sched-dump.h"
/* A vector holding bb info for whole scheduling pass. */
vec<sel_global_bb_info_def>
sel_global_bb_info = vNULL;
/* A vector holding bb info. */
vec<sel_region_bb_info_def>
sel_region_bb_info = vNULL;
/* A pool for allocating all lists. */
alloc_pool sched_lists_pool;
/* This contains information about successors for compute_av_set. */
struct succs_info current_succs;
/* Data structure to describe interaction with the generic scheduler utils. */
static struct common_sched_info_def sel_common_sched_info;
/* The loop nest being pipelined. */
struct loop *current_loop_nest;
/* LOOP_NESTS is a vector containing the corresponding loop nest for
each region. */
static vec<loop_p> loop_nests = vNULL;
/* Saves blocks already in loop regions, indexed by bb->index. */
static sbitmap bbs_in_loop_rgns = NULL;
/* CFG hooks that are saved before changing create_basic_block hook. */
static struct cfg_hooks orig_cfg_hooks;
/* Array containing reverse topological index of function basic blocks,
indexed by BB->INDEX. */
static int *rev_top_order_index = NULL;
/* Length of the above array. */
static int rev_top_order_index_len = -1;
/* A regset pool structure. */
static struct
{
/* The stack to which regsets are returned. */
regset *v;
/* Its pointer. */
int n;
/* Its size. */
int s;
/* In VV we save all generated regsets so that, when destructing the
pool, we can compare it with V and check that every regset was returned
back to pool. */
regset *vv;
/* The pointer of VV stack. */
int nn;
/* Its size. */
int ss;
/* The difference between allocated and returned regsets. */
int diff;
} regset_pool = { NULL, 0, 0, NULL, 0, 0, 0 };
/* This represents the nop pool. */
static struct
{
/* The vector which holds previously emitted nops. */
insn_t *v;
/* Its pointer. */
int n;
/* Its size. */
int s;
} nop_pool = { NULL, 0, 0 };
/* The pool for basic block notes. */
static rtx_vec_t bb_note_pool;
/* A NOP pattern used to emit placeholder insns. */
rtx nop_pattern = NULL_RTX;
/* A special instruction that resides in EXIT_BLOCK.
EXIT_INSN is successor of the insns that lead to EXIT_BLOCK. */
rtx exit_insn = NULL_RTX;
/* TRUE if while scheduling current region, which is loop, its preheader
was removed. */
bool preheader_removed = false;
/* Forward static declarations. */
static void fence_clear (fence_t);
static void deps_init_id (idata_t, insn_t, bool);
static void init_id_from_df (idata_t, insn_t, bool);
static expr_t set_insn_init (expr_t, vinsn_t, int);
static void cfg_preds (basic_block, insn_t **, int *);
static void prepare_insn_expr (insn_t, int);
static void free_history_vect (vec<expr_history_def> &);
static void move_bb_info (basic_block, basic_block);
static void remove_empty_bb (basic_block, bool);
static void sel_merge_blocks (basic_block, basic_block);
static void sel_remove_loop_preheader (void);
static bool bb_has_removable_jump_to_p (basic_block, basic_block);
static bool insn_is_the_only_one_in_bb_p (insn_t);
static void create_initial_data_sets (basic_block);
static void free_av_set (basic_block);
static void invalidate_av_set (basic_block);
static void extend_insn_data (void);
static void sel_init_new_insn (insn_t, int);
static void finish_insns (void);
/* Various list functions. */
/* Copy an instruction list L. */
ilist_t
ilist_copy (ilist_t l)
{
ilist_t head = NULL, *tailp = &head;
while (l)
{
ilist_add (tailp, ILIST_INSN (l));
tailp = &ILIST_NEXT (*tailp);
l = ILIST_NEXT (l);
}
return head;
}
/* Invert an instruction list L. */
ilist_t
ilist_invert (ilist_t l)
{
ilist_t res = NULL;
while (l)
{
ilist_add (&res, ILIST_INSN (l));
l = ILIST_NEXT (l);
}
return res;
}
/* Add a new boundary to the LP list with parameters TO, PTR, and DC. */
void
blist_add (blist_t *lp, insn_t to, ilist_t ptr, deps_t dc)
{
bnd_t bnd;
_list_add (lp);
bnd = BLIST_BND (*lp);
BND_TO (bnd) = to;
BND_PTR (bnd) = ptr;
BND_AV (bnd) = NULL;
BND_AV1 (bnd) = NULL;
BND_DC (bnd) = dc;
}
/* Remove the list note pointed to by LP. */
void
blist_remove (blist_t *lp)
{
bnd_t b = BLIST_BND (*lp);
av_set_clear (&BND_AV (b));
av_set_clear (&BND_AV1 (b));
ilist_clear (&BND_PTR (b));
_list_remove (lp);
}
/* Init a fence tail L. */
void
flist_tail_init (flist_tail_t l)
{
FLIST_TAIL_HEAD (l) = NULL;
FLIST_TAIL_TAILP (l) = &FLIST_TAIL_HEAD (l);
}
/* Try to find fence corresponding to INSN in L. */
fence_t
flist_lookup (flist_t l, insn_t insn)
{
while (l)
{
if (FENCE_INSN (FLIST_FENCE (l)) == insn)
return FLIST_FENCE (l);
l = FLIST_NEXT (l);
}
return NULL;
}
/* Init the fields of F before running fill_insns. */
static void
init_fence_for_scheduling (fence_t f)
{
FENCE_BNDS (f) = NULL;
FENCE_PROCESSED_P (f) = false;
FENCE_SCHEDULED_P (f) = false;
}
/* Add new fence consisting of INSN and STATE to the list pointed to by LP. */
static void
flist_add (flist_t *lp, insn_t insn, state_t state, deps_t dc, void *tc,
insn_t last_scheduled_insn, vec<rtx, va_gc> *executing_insns,
int *ready_ticks, int ready_ticks_size, insn_t sched_next,
int cycle, int cycle_issued_insns, int issue_more,
bool starts_cycle_p, bool after_stall_p)
{
fence_t f;
_list_add (lp);
f = FLIST_FENCE (*lp);
FENCE_INSN (f) = insn;
gcc_assert (state != NULL);
FENCE_STATE (f) = state;
FENCE_CYCLE (f) = cycle;
FENCE_ISSUED_INSNS (f) = cycle_issued_insns;
FENCE_STARTS_CYCLE_P (f) = starts_cycle_p;
FENCE_AFTER_STALL_P (f) = after_stall_p;
gcc_assert (dc != NULL);
FENCE_DC (f) = dc;
gcc_assert (tc != NULL || targetm.sched.alloc_sched_context == NULL);
FENCE_TC (f) = tc;
FENCE_LAST_SCHEDULED_INSN (f) = last_scheduled_insn;
FENCE_ISSUE_MORE (f) = issue_more;
FENCE_EXECUTING_INSNS (f) = executing_insns;
FENCE_READY_TICKS (f) = ready_ticks;
FENCE_READY_TICKS_SIZE (f) = ready_ticks_size;
FENCE_SCHED_NEXT (f) = sched_next;
init_fence_for_scheduling (f);
}
/* Remove the head node of the list pointed to by LP. */
static void
flist_remove (flist_t *lp)
{
if (FENCE_INSN (FLIST_FENCE (*lp)))
fence_clear (FLIST_FENCE (*lp));
_list_remove (lp);
}
/* Clear the fence list pointed to by LP. */
void
flist_clear (flist_t *lp)
{
while (*lp)
flist_remove (lp);
}
/* Add ORIGINAL_INSN the def list DL honoring CROSSES_CALL. */
void
def_list_add (def_list_t *dl, insn_t original_insn, bool crosses_call)
{
def_t d;
_list_add (dl);
d = DEF_LIST_DEF (*dl);
d->orig_insn = original_insn;
d->crosses_call = crosses_call;
}
/* Functions to work with target contexts. */
/* Bulk target context. It is convenient for debugging purposes to ensure
that there are no uninitialized (null) target contexts. */
static tc_t bulk_tc = (tc_t) 1;
/* Target hooks wrappers. In the future we can provide some default
implementations for them. */
/* Allocate a store for the target context. */
static tc_t
alloc_target_context (void)
{
return (targetm.sched.alloc_sched_context
? targetm.sched.alloc_sched_context () : bulk_tc);
}
/* Init target context TC.
If CLEAN_P is true, then make TC as it is beginning of the scheduler.
Overwise, copy current backend context to TC. */
static void
init_target_context (tc_t tc, bool clean_p)
{
if (targetm.sched.init_sched_context)
targetm.sched.init_sched_context (tc, clean_p);
}
/* Allocate and initialize a target context. Meaning of CLEAN_P is the same as
int init_target_context (). */
tc_t
create_target_context (bool clean_p)
{
tc_t tc = alloc_target_context ();
init_target_context (tc, clean_p);
return tc;
}
/* Copy TC to the current backend context. */
void
set_target_context (tc_t tc)
{
if (targetm.sched.set_sched_context)
targetm.sched.set_sched_context (tc);
}
/* TC is about to be destroyed. Free any internal data. */
static void
clear_target_context (tc_t tc)
{
if (targetm.sched.clear_sched_context)
targetm.sched.clear_sched_context (tc);
}
/* Clear and free it. */
static void
delete_target_context (tc_t tc)
{
clear_target_context (tc);
if (targetm.sched.free_sched_context)
targetm.sched.free_sched_context (tc);
}
/* Make a copy of FROM in TO.
NB: May be this should be a hook. */
static void
copy_target_context (tc_t to, tc_t from)
{
tc_t tmp = create_target_context (false);
set_target_context (from);
init_target_context (to, false);
set_target_context (tmp);
delete_target_context (tmp);
}
/* Create a copy of TC. */
static tc_t
create_copy_of_target_context (tc_t tc)
{
tc_t copy = alloc_target_context ();
copy_target_context (copy, tc);
return copy;
}
/* Clear TC and initialize it according to CLEAN_P. The meaning of CLEAN_P
is the same as in init_target_context (). */
void
reset_target_context (tc_t tc, bool clean_p)
{
clear_target_context (tc);
init_target_context (tc, clean_p);
}
/* Functions to work with dependence contexts.
Dc (aka deps context, aka deps_t, aka struct deps_desc *) is short for dependence
context. It accumulates information about processed insns to decide if
current insn is dependent on the processed ones. */
/* Make a copy of FROM in TO. */
static void
copy_deps_context (deps_t to, deps_t from)
{
init_deps (to, false);
deps_join (to, from);
}
/* Allocate store for dep context. */
static deps_t
alloc_deps_context (void)
{
return XNEW (struct deps_desc);
}
/* Allocate and initialize dep context. */
static deps_t
create_deps_context (void)
{
deps_t dc = alloc_deps_context ();
init_deps (dc, false);
return dc;
}
/* Create a copy of FROM. */
static deps_t
create_copy_of_deps_context (deps_t from)
{
deps_t to = alloc_deps_context ();
copy_deps_context (to, from);
return to;
}
/* Clean up internal data of DC. */
static void
clear_deps_context (deps_t dc)
{
free_deps (dc);
}
/* Clear and free DC. */
static void
delete_deps_context (deps_t dc)
{
clear_deps_context (dc);
free (dc);
}
/* Clear and init DC. */
static void
reset_deps_context (deps_t dc)
{
clear_deps_context (dc);
init_deps (dc, false);
}
/* This structure describes the dependence analysis hooks for advancing
dependence context. */
static struct sched_deps_info_def advance_deps_context_sched_deps_info =
{
NULL,
NULL, /* start_insn */
NULL, /* finish_insn */
NULL, /* start_lhs */
NULL, /* finish_lhs */
NULL, /* start_rhs */
NULL, /* finish_rhs */
haifa_note_reg_set,
haifa_note_reg_clobber,
haifa_note_reg_use,
NULL, /* note_mem_dep */
NULL, /* note_dep */
0, 0, 0
};
/* Process INSN and add its impact on DC. */
void
advance_deps_context (deps_t dc, insn_t insn)
{
sched_deps_info = &advance_deps_context_sched_deps_info;
deps_analyze_insn (dc, insn);
}
/* Functions to work with DFA states. */
/* Allocate store for a DFA state. */
static state_t
state_alloc (void)
{
return xmalloc (dfa_state_size);
}
/* Allocate and initialize DFA state. */
static state_t
state_create (void)
{
state_t state = state_alloc ();
state_reset (state);
advance_state (state);
return state;
}
/* Free DFA state. */
static void
state_free (state_t state)
{
free (state);
}
/* Make a copy of FROM in TO. */
static void
state_copy (state_t to, state_t from)
{
memcpy (to, from, dfa_state_size);
}
/* Create a copy of FROM. */
static state_t
state_create_copy (state_t from)
{
state_t to = state_alloc ();
state_copy (to, from);
return to;
}
/* Functions to work with fences. */
/* Clear the fence. */
static void
fence_clear (fence_t f)
{
state_t s = FENCE_STATE (f);
deps_t dc = FENCE_DC (f);
void *tc = FENCE_TC (f);
ilist_clear (&FENCE_BNDS (f));
gcc_assert ((s != NULL && dc != NULL && tc != NULL)
|| (s == NULL && dc == NULL && tc == NULL));
free (s);
if (dc != NULL)
delete_deps_context (dc);
if (tc != NULL)
delete_target_context (tc);
vec_free (FENCE_EXECUTING_INSNS (f));
free (FENCE_READY_TICKS (f));
FENCE_READY_TICKS (f) = NULL;
}
/* Init a list of fences with successors of OLD_FENCE. */
void
init_fences (insn_t old_fence)
{
insn_t succ;
succ_iterator si;
bool first = true;
int ready_ticks_size = get_max_uid () + 1;
FOR_EACH_SUCC_1 (succ, si, old_fence,
SUCCS_NORMAL | SUCCS_SKIP_TO_LOOP_EXITS)
{
if (first)
first = false;
else
gcc_assert (flag_sel_sched_pipelining_outer_loops);
flist_add (&fences, succ,
state_create (),
create_deps_context () /* dc */,
create_target_context (true) /* tc */,
NULL_RTX /* last_scheduled_insn */,
NULL, /* executing_insns */
XCNEWVEC (int, ready_ticks_size), /* ready_ticks */
ready_ticks_size,
NULL_RTX /* sched_next */,
1 /* cycle */, 0 /* cycle_issued_insns */,
issue_rate, /* issue_more */
1 /* starts_cycle_p */, 0 /* after_stall_p */);
}
}
/* Merges two fences (filling fields of fence F with resulting values) by
following rules: 1) state, target context and last scheduled insn are
propagated from fallthrough edge if it is available;
2) deps context and cycle is propagated from more probable edge;
3) all other fields are set to corresponding constant values.
INSN, STATE, DC, TC, LAST_SCHEDULED_INSN, EXECUTING_INSNS,
READY_TICKS, READY_TICKS_SIZE, SCHED_NEXT, CYCLE, ISSUE_MORE
and AFTER_STALL_P are the corresponding fields of the second fence. */
static void
merge_fences (fence_t f, insn_t insn,
state_t state, deps_t dc, void *tc,
rtx last_scheduled_insn, vec<rtx, va_gc> *executing_insns,
int *ready_ticks, int ready_ticks_size,
rtx sched_next, int cycle, int issue_more, bool after_stall_p)
{
insn_t last_scheduled_insn_old = FENCE_LAST_SCHEDULED_INSN (f);
gcc_assert (sel_bb_head_p (FENCE_INSN (f))
&& !sched_next && !FENCE_SCHED_NEXT (f));
/* Check if we can decide which path fences came.
If we can't (or don't want to) - reset all. */
if (last_scheduled_insn == NULL
|| last_scheduled_insn_old == NULL
/* This is a case when INSN is reachable on several paths from
one insn (this can happen when pipelining of outer loops is on and
there are two edges: one going around of inner loop and the other -
right through it; in such case just reset everything). */
|| last_scheduled_insn == last_scheduled_insn_old)
{
state_reset (FENCE_STATE (f));
state_free (state);
reset_deps_context (FENCE_DC (f));
delete_deps_context (dc);
reset_target_context (FENCE_TC (f), true);
delete_target_context (tc);
if (cycle > FENCE_CYCLE (f))
FENCE_CYCLE (f) = cycle;
FENCE_LAST_SCHEDULED_INSN (f) = NULL;
FENCE_ISSUE_MORE (f) = issue_rate;
vec_free (executing_insns);
free (ready_ticks);
if (FENCE_EXECUTING_INSNS (f))
FENCE_EXECUTING_INSNS (f)->block_remove (0,
FENCE_EXECUTING_INSNS (f)->length ());
if (FENCE_READY_TICKS (f))
memset (FENCE_READY_TICKS (f), 0, FENCE_READY_TICKS_SIZE (f));
}
else
{
edge edge_old = NULL, edge_new = NULL;
edge candidate;
succ_iterator si;
insn_t succ;
/* Find fallthrough edge. */
gcc_assert (BLOCK_FOR_INSN (insn)->prev_bb);
candidate = find_fallthru_edge_from (BLOCK_FOR_INSN (insn)->prev_bb);
if (!candidate
|| (candidate->src != BLOCK_FOR_INSN (last_scheduled_insn)
&& candidate->src != BLOCK_FOR_INSN (last_scheduled_insn_old)))
{
/* No fallthrough edge leading to basic block of INSN. */
state_reset (FENCE_STATE (f));
state_free (state);
reset_target_context (FENCE_TC (f), true);
delete_target_context (tc);
FENCE_LAST_SCHEDULED_INSN (f) = NULL;
FENCE_ISSUE_MORE (f) = issue_rate;
}
else
if (candidate->src == BLOCK_FOR_INSN (last_scheduled_insn))
{
/* Would be weird if same insn is successor of several fallthrough
edges. */
gcc_assert (BLOCK_FOR_INSN (insn)->prev_bb
!= BLOCK_FOR_INSN (last_scheduled_insn_old));
state_free (FENCE_STATE (f));
FENCE_STATE (f) = state;
delete_target_context (FENCE_TC (f));
FENCE_TC (f) = tc;
FENCE_LAST_SCHEDULED_INSN (f) = last_scheduled_insn;
FENCE_ISSUE_MORE (f) = issue_more;
}
else
{
/* Leave STATE, TC and LAST_SCHEDULED_INSN fields untouched. */
state_free (state);
delete_target_context (tc);
gcc_assert (BLOCK_FOR_INSN (insn)->prev_bb
!= BLOCK_FOR_INSN (last_scheduled_insn));
}
/* Find edge of first predecessor (last_scheduled_insn_old->insn). */
FOR_EACH_SUCC_1 (succ, si, last_scheduled_insn_old,
SUCCS_NORMAL | SUCCS_SKIP_TO_LOOP_EXITS)
{
if (succ == insn)
{
/* No same successor allowed from several edges. */
gcc_assert (!edge_old);
edge_old = si.e1;
}
}
/* Find edge of second predecessor (last_scheduled_insn->insn). */
FOR_EACH_SUCC_1 (succ, si, last_scheduled_insn,
SUCCS_NORMAL | SUCCS_SKIP_TO_LOOP_EXITS)
{
if (succ == insn)
{
/* No same successor allowed from several edges. */
gcc_assert (!edge_new);
edge_new = si.e1;
}
}
/* Check if we can choose most probable predecessor. */
if (edge_old == NULL || edge_new == NULL)
{
reset_deps_context (FENCE_DC (f));
delete_deps_context (dc);
vec_free (executing_insns);
free (ready_ticks);
FENCE_CYCLE (f) = MAX (FENCE_CYCLE (f), cycle);
if (FENCE_EXECUTING_INSNS (f))
FENCE_EXECUTING_INSNS (f)->block_remove (0,
FENCE_EXECUTING_INSNS (f)->length ());
if (FENCE_READY_TICKS (f))
memset (FENCE_READY_TICKS (f), 0, FENCE_READY_TICKS_SIZE (f));
}
else
if (edge_new->probability > edge_old->probability)
{
delete_deps_context (FENCE_DC (f));
FENCE_DC (f) = dc;
vec_free (FENCE_EXECUTING_INSNS (f));
FENCE_EXECUTING_INSNS (f) = executing_insns;
free (FENCE_READY_TICKS (f));
FENCE_READY_TICKS (f) = ready_ticks;
FENCE_READY_TICKS_SIZE (f) = ready_ticks_size;
FENCE_CYCLE (f) = cycle;
}
else
{
/* Leave DC and CYCLE untouched. */
delete_deps_context (dc);
vec_free (executing_insns);
free (ready_ticks);
}
}
/* Fill remaining invariant fields. */
if (after_stall_p)
FENCE_AFTER_STALL_P (f) = 1;
FENCE_ISSUED_INSNS (f) = 0;
FENCE_STARTS_CYCLE_P (f) = 1;
FENCE_SCHED_NEXT (f) = NULL;
}
/* Add a new fence to NEW_FENCES list, initializing it from all
other parameters. */
static void
add_to_fences (flist_tail_t new_fences, insn_t insn,
state_t state, deps_t dc, void *tc, rtx last_scheduled_insn,
vec<rtx, va_gc> *executing_insns, int *ready_ticks,
int ready_ticks_size, rtx sched_next, int cycle,
int cycle_issued_insns, int issue_rate,
bool starts_cycle_p, bool after_stall_p)
{
fence_t f = flist_lookup (FLIST_TAIL_HEAD (new_fences), insn);
if (! f)
{
flist_add (FLIST_TAIL_TAILP (new_fences), insn, state, dc, tc,
last_scheduled_insn, executing_insns, ready_ticks,
ready_ticks_size, sched_next, cycle, cycle_issued_insns,
issue_rate, starts_cycle_p, after_stall_p);
FLIST_TAIL_TAILP (new_fences)
= &FLIST_NEXT (*FLIST_TAIL_TAILP (new_fences));
}
else
{
merge_fences (f, insn, state, dc, tc, last_scheduled_insn,
executing_insns, ready_ticks, ready_ticks_size,
sched_next, cycle, issue_rate, after_stall_p);
}
}
/* Move the first fence in the OLD_FENCES list to NEW_FENCES. */
void
move_fence_to_fences (flist_t old_fences, flist_tail_t new_fences)
{
fence_t f, old;
flist_t *tailp = FLIST_TAIL_TAILP (new_fences);
old = FLIST_FENCE (old_fences);
f = flist_lookup (FLIST_TAIL_HEAD (new_fences),
FENCE_INSN (FLIST_FENCE (old_fences)));
if (f)
{
merge_fences (f, old->insn, old->state, old->dc, old->tc,
old->last_scheduled_insn, old->executing_insns,
old->ready_ticks, old->ready_ticks_size,
old->sched_next, old->cycle, old->issue_more,
old->after_stall_p);
}
else
{
_list_add (tailp);
FLIST_TAIL_TAILP (new_fences) = &FLIST_NEXT (*tailp);
*FLIST_FENCE (*tailp) = *old;
init_fence_for_scheduling (FLIST_FENCE (*tailp));
}
FENCE_INSN (old) = NULL;
}
/* Add a new fence to NEW_FENCES list and initialize most of its data
as a clean one. */
void
add_clean_fence_to_fences (flist_tail_t new_fences, insn_t succ, fence_t fence)
{
int ready_ticks_size = get_max_uid () + 1;
add_to_fences (new_fences,
succ, state_create (), create_deps_context (),
create_target_context (true),
NULL_RTX, NULL,
XCNEWVEC (int, ready_ticks_size), ready_ticks_size,
NULL_RTX, FENCE_CYCLE (fence) + 1,
0, issue_rate, 1, FENCE_AFTER_STALL_P (fence));
}
/* Add a new fence to NEW_FENCES list and initialize all of its data
from FENCE and SUCC. */
void
add_dirty_fence_to_fences (flist_tail_t new_fences, insn_t succ, fence_t fence)
{
int * new_ready_ticks
= XNEWVEC (int, FENCE_READY_TICKS_SIZE (fence));
memcpy (new_ready_ticks, FENCE_READY_TICKS (fence),
FENCE_READY_TICKS_SIZE (fence) * sizeof (int));
add_to_fences (new_fences,
succ, state_create_copy (FENCE_STATE (fence)),
create_copy_of_deps_context (FENCE_DC (fence)),
create_copy_of_target_context (FENCE_TC (fence)),
FENCE_LAST_SCHEDULED_INSN (fence),
vec_safe_copy (FENCE_EXECUTING_INSNS (fence)),
new_ready_ticks,
FENCE_READY_TICKS_SIZE (fence),
FENCE_SCHED_NEXT (fence),
FENCE_CYCLE (fence),
FENCE_ISSUED_INSNS (fence),
FENCE_ISSUE_MORE (fence),
FENCE_STARTS_CYCLE_P (fence),
FENCE_AFTER_STALL_P (fence));
}
/* Functions to work with regset and nop pools. */
/* Returns the new regset from pool. It might have some of the bits set
from the previous usage. */
regset
get_regset_from_pool (void)
{
regset rs;
if (regset_pool.n != 0)
rs = regset_pool.v[--regset_pool.n];
else
/* We need to create the regset. */
{
rs = ALLOC_REG_SET (®_obstack);
if (regset_pool.nn == regset_pool.ss)
regset_pool.vv = XRESIZEVEC (regset, regset_pool.vv,
(regset_pool.ss = 2 * regset_pool.ss + 1));
regset_pool.vv[regset_pool.nn++] = rs;
}
regset_pool.diff++;
return rs;
}
/* Same as above, but returns the empty regset. */
regset
get_clear_regset_from_pool (void)
{
regset rs = get_regset_from_pool ();
CLEAR_REG_SET (rs);
return rs;
}
/* Return regset RS to the pool for future use. */
void
return_regset_to_pool (regset rs)
{
gcc_assert (rs);
regset_pool.diff--;
if (regset_pool.n == regset_pool.s)
regset_pool.v = XRESIZEVEC (regset, regset_pool.v,
(regset_pool.s = 2 * regset_pool.s + 1));
regset_pool.v[regset_pool.n++] = rs;
}
#ifdef ENABLE_CHECKING
/* This is used as a qsort callback for sorting regset pool stacks.
X and XX are addresses of two regsets. They are never equal. */
static int
cmp_v_in_regset_pool (const void *x, const void *xx)
{
uintptr_t r1 = (uintptr_t) *((const regset *) x);
uintptr_t r2 = (uintptr_t) *((const regset *) xx);
if (r1 > r2)
return 1;
else if (r1 < r2)
return -1;
gcc_unreachable ();
}
#endif
/* Free the regset pool possibly checking for memory leaks. */
void
free_regset_pool (void)
{
#ifdef ENABLE_CHECKING
{
regset *v = regset_pool.v;
int i = 0;
int n = regset_pool.n;
regset *vv = regset_pool.vv;
int ii = 0;
int nn = regset_pool.nn;
int diff = 0;
gcc_assert (n <= nn);
/* Sort both vectors so it will be possible to compare them. */
qsort (v, n, sizeof (*v), cmp_v_in_regset_pool);
qsort (vv, nn, sizeof (*vv), cmp_v_in_regset_pool);
while (ii < nn)
{
if (v[i] == vv[ii])
i++;
else
/* VV[II] was lost. */
diff++;
ii++;
}