forked from riscvarchive/riscv-gcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdf-scan.c
4234 lines (3542 loc) · 118 KB
/
df-scan.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
/* Scanning of rtl for dataflow analysis.
Copyright (C) 1999-2020 Free Software Foundation, Inc.
Originally contributed by Michael P. Hayes
Major rewrite contributed by Danny Berlin ([email protected])
and Kenneth Zadeck ([email protected]).
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 "backend.h"
#include "target.h"
#include "rtl.h"
#include "tree.h"
#include "df.h"
#include "memmodel.h"
#include "tm_p.h"
#include "regs.h"
#include "emit-rtl.h" /* FIXME: Can go away once crtl is moved to rtl.h. */
#include "dumpfile.h"
#include "calls.h"
#include "function-abi.h"
/* The set of hard registers in eliminables[i].from. */
static HARD_REG_SET elim_reg_set;
/* Initialize ur_in and ur_out as if all hard registers were partially
available. */
class df_collection_rec
{
public:
auto_vec<df_ref, 128> def_vec;
auto_vec<df_ref, 32> use_vec;
auto_vec<df_ref, 32> eq_use_vec;
auto_vec<df_mw_hardreg *, 32> mw_vec;
};
static void df_ref_record (enum df_ref_class, class df_collection_rec *,
rtx, rtx *,
basic_block, struct df_insn_info *,
enum df_ref_type, int ref_flags);
static void df_def_record_1 (class df_collection_rec *, rtx *,
basic_block, struct df_insn_info *,
int ref_flags);
static void df_defs_record (class df_collection_rec *, rtx,
basic_block, struct df_insn_info *,
int ref_flags);
static void df_uses_record (class df_collection_rec *,
rtx *, enum df_ref_type,
basic_block, struct df_insn_info *,
int ref_flags);
static void df_install_ref_incremental (df_ref);
static void df_insn_refs_collect (class df_collection_rec*,
basic_block, struct df_insn_info *);
static void df_canonize_collection_rec (class df_collection_rec *);
static void df_get_regular_block_artificial_uses (bitmap);
static void df_get_eh_block_artificial_uses (bitmap);
static void df_record_entry_block_defs (bitmap);
static void df_record_exit_block_uses (bitmap);
static void df_get_exit_block_use_set (bitmap);
static void df_get_entry_block_def_set (bitmap);
static void df_grow_ref_info (struct df_ref_info *, unsigned int);
static void df_ref_chain_delete_du_chain (df_ref);
static void df_ref_chain_delete (df_ref);
static void df_refs_add_to_chains (class df_collection_rec *,
basic_block, rtx_insn *, unsigned int);
static bool df_insn_refs_verify (class df_collection_rec *, basic_block,
rtx_insn *, bool);
static void df_entry_block_defs_collect (class df_collection_rec *, bitmap);
static void df_exit_block_uses_collect (class df_collection_rec *, bitmap);
static void df_install_ref (df_ref, struct df_reg_info *,
struct df_ref_info *, bool);
static int df_ref_compare (df_ref, df_ref);
static int df_ref_ptr_compare (const void *, const void *);
static int df_mw_compare (const df_mw_hardreg *, const df_mw_hardreg *);
static int df_mw_ptr_compare (const void *, const void *);
static void df_insn_info_delete (unsigned int);
/* Indexed by hardware reg number, is true if that register is ever
used in the current function.
In df-scan.c, this is set up to record the hard regs used
explicitly. Reload adds in the hard regs used for holding pseudo
regs. Final uses it to generate the code in the function prologue
and epilogue to save and restore registers as needed. */
static bool regs_ever_live[FIRST_PSEUDO_REGISTER];
/* Flags used to tell df_refs_add_to_chains() which vectors it should copy. */
static const unsigned int copy_defs = 0x1;
static const unsigned int copy_uses = 0x2;
static const unsigned int copy_eq_uses = 0x4;
static const unsigned int copy_mw = 0x8;
static const unsigned int copy_all = copy_defs | copy_uses | copy_eq_uses
| copy_mw;
/*----------------------------------------------------------------------------
SCANNING DATAFLOW PROBLEM
There are several ways in which scanning looks just like the other
dataflow problems. It shares the all the mechanisms for local info
as well as basic block info. Where it differs is when and how often
it gets run. It also has no need for the iterative solver.
----------------------------------------------------------------------------*/
/* Problem data for the scanning dataflow function. */
struct df_scan_problem_data
{
object_allocator<df_base_ref> *ref_base_pool;
object_allocator<df_artificial_ref> *ref_artificial_pool;
object_allocator<df_regular_ref> *ref_regular_pool;
object_allocator<df_insn_info> *insn_pool;
object_allocator<df_reg_info> *reg_pool;
object_allocator<df_mw_hardreg> *mw_reg_pool;
bitmap_obstack reg_bitmaps;
bitmap_obstack insn_bitmaps;
};
/* Internal function to shut down the scanning problem. */
static void
df_scan_free_internal (void)
{
struct df_scan_problem_data *problem_data
= (struct df_scan_problem_data *) df_scan->problem_data;
free (df->def_info.refs);
free (df->def_info.begin);
free (df->def_info.count);
memset (&df->def_info, 0, (sizeof (struct df_ref_info)));
free (df->use_info.refs);
free (df->use_info.begin);
free (df->use_info.count);
memset (&df->use_info, 0, (sizeof (struct df_ref_info)));
free (df->def_regs);
df->def_regs = NULL;
free (df->use_regs);
df->use_regs = NULL;
free (df->eq_use_regs);
df->eq_use_regs = NULL;
df->regs_size = 0;
DF_REG_SIZE (df) = 0;
free (df->insns);
df->insns = NULL;
DF_INSN_SIZE () = 0;
free (df_scan->block_info);
df_scan->block_info = NULL;
df_scan->block_info_size = 0;
bitmap_clear (&df->hardware_regs_used);
bitmap_clear (&df->regular_block_artificial_uses);
bitmap_clear (&df->eh_block_artificial_uses);
BITMAP_FREE (df->entry_block_defs);
BITMAP_FREE (df->exit_block_uses);
bitmap_clear (&df->insns_to_delete);
bitmap_clear (&df->insns_to_rescan);
bitmap_clear (&df->insns_to_notes_rescan);
delete problem_data->ref_base_pool;
delete problem_data->ref_artificial_pool;
delete problem_data->ref_regular_pool;
delete problem_data->insn_pool;
delete problem_data->reg_pool;
delete problem_data->mw_reg_pool;
bitmap_obstack_release (&problem_data->reg_bitmaps);
bitmap_obstack_release (&problem_data->insn_bitmaps);
free (df_scan->problem_data);
}
/* Free basic block info. */
static void
df_scan_free_bb_info (basic_block bb, void *vbb_info)
{
struct df_scan_bb_info *bb_info = (struct df_scan_bb_info *) vbb_info;
unsigned int bb_index = bb->index;
rtx_insn *insn;
FOR_BB_INSNS (bb, insn)
if (INSN_P (insn))
df_insn_info_delete (INSN_UID (insn));
if (bb_index < df_scan->block_info_size)
bb_info = df_scan_get_bb_info (bb_index);
/* Get rid of any artificial uses or defs. */
df_ref_chain_delete_du_chain (bb_info->artificial_defs);
df_ref_chain_delete_du_chain (bb_info->artificial_uses);
df_ref_chain_delete (bb_info->artificial_defs);
df_ref_chain_delete (bb_info->artificial_uses);
bb_info->artificial_defs = NULL;
bb_info->artificial_uses = NULL;
}
/* Allocate the problem data for the scanning problem. This should be
called when the problem is created or when the entire function is to
be rescanned. */
void
df_scan_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
{
struct df_scan_problem_data *problem_data;
basic_block bb;
/* Given the number of pools, this is really faster than tearing
everything apart. */
if (df_scan->problem_data)
df_scan_free_internal ();
problem_data = XNEW (struct df_scan_problem_data);
df_scan->problem_data = problem_data;
df_scan->computed = true;
problem_data->ref_base_pool = new object_allocator<df_base_ref>
("df_scan ref base");
problem_data->ref_artificial_pool = new object_allocator<df_artificial_ref>
("df_scan ref artificial");
problem_data->ref_regular_pool = new object_allocator<df_regular_ref>
("df_scan ref regular");
problem_data->insn_pool = new object_allocator<df_insn_info>
("df_scan insn");
problem_data->reg_pool = new object_allocator<df_reg_info>
("df_scan reg");
problem_data->mw_reg_pool = new object_allocator<df_mw_hardreg>
("df_scan mw_reg");
bitmap_obstack_initialize (&problem_data->reg_bitmaps);
bitmap_obstack_initialize (&problem_data->insn_bitmaps);
df_grow_reg_info ();
df_grow_insn_info ();
df_grow_bb_info (df_scan);
FOR_ALL_BB_FN (bb, cfun)
{
unsigned int bb_index = bb->index;
struct df_scan_bb_info *bb_info = df_scan_get_bb_info (bb_index);
bb_info->artificial_defs = NULL;
bb_info->artificial_uses = NULL;
}
bitmap_initialize (&df->hardware_regs_used, &problem_data->reg_bitmaps);
bitmap_initialize (&df->regular_block_artificial_uses, &problem_data->reg_bitmaps);
bitmap_initialize (&df->eh_block_artificial_uses, &problem_data->reg_bitmaps);
df->entry_block_defs = BITMAP_ALLOC (&problem_data->reg_bitmaps);
df->exit_block_uses = BITMAP_ALLOC (&problem_data->reg_bitmaps);
bitmap_initialize (&df->insns_to_delete, &problem_data->insn_bitmaps);
bitmap_initialize (&df->insns_to_rescan, &problem_data->insn_bitmaps);
bitmap_initialize (&df->insns_to_notes_rescan, &problem_data->insn_bitmaps);
df_scan->optional_p = false;
}
/* Free all of the data associated with the scan problem. */
static void
df_scan_free (void)
{
if (df_scan->problem_data)
df_scan_free_internal ();
if (df->blocks_to_analyze)
{
BITMAP_FREE (df->blocks_to_analyze);
df->blocks_to_analyze = NULL;
}
free (df_scan);
}
/* Dump the preamble for DF_SCAN dump. */
static void
df_scan_start_dump (FILE *file ATTRIBUTE_UNUSED)
{
int i;
int dcount = 0;
int ucount = 0;
int ecount = 0;
int icount = 0;
int ccount = 0;
basic_block bb;
rtx_insn *insn;
fprintf (file, ";; fully invalidated by EH \t");
df_print_regset
(file, bitmap_view<HARD_REG_SET> (eh_edge_abi.full_reg_clobbers ()));
fprintf (file, ";; hardware regs used \t");
df_print_regset (file, &df->hardware_regs_used);
fprintf (file, ";; regular block artificial uses \t");
df_print_regset (file, &df->regular_block_artificial_uses);
fprintf (file, ";; eh block artificial uses \t");
df_print_regset (file, &df->eh_block_artificial_uses);
fprintf (file, ";; entry block defs \t");
df_print_regset (file, df->entry_block_defs);
fprintf (file, ";; exit block uses \t");
df_print_regset (file, df->exit_block_uses);
fprintf (file, ";; regs ever live \t");
for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
if (df_regs_ever_live_p (i))
fprintf (file, " %d [%s]", i, reg_names[i]);
fprintf (file, "\n;; ref usage \t");
for (i = 0; i < (int)df->regs_inited; i++)
if (DF_REG_DEF_COUNT (i) || DF_REG_USE_COUNT (i) || DF_REG_EQ_USE_COUNT (i))
{
const char * sep = "";
fprintf (file, "r%d={", i);
if (DF_REG_DEF_COUNT (i))
{
fprintf (file, "%dd", DF_REG_DEF_COUNT (i));
sep = ",";
dcount += DF_REG_DEF_COUNT (i);
}
if (DF_REG_USE_COUNT (i))
{
fprintf (file, "%s%du", sep, DF_REG_USE_COUNT (i));
sep = ",";
ucount += DF_REG_USE_COUNT (i);
}
if (DF_REG_EQ_USE_COUNT (i))
{
fprintf (file, "%s%de", sep, DF_REG_EQ_USE_COUNT (i));
ecount += DF_REG_EQ_USE_COUNT (i);
}
fprintf (file, "} ");
}
FOR_EACH_BB_FN (bb, cfun)
FOR_BB_INSNS (bb, insn)
if (INSN_P (insn))
{
if (CALL_P (insn))
ccount++;
else
icount++;
}
fprintf (file, "\n;; total ref usage %d{%dd,%du,%de}"
" in %d{%d regular + %d call} insns.\n",
dcount + ucount + ecount, dcount, ucount, ecount,
icount + ccount, icount, ccount);
}
/* Dump the bb_info for a given basic block. */
static void
df_scan_start_block (basic_block bb, FILE *file)
{
struct df_scan_bb_info *bb_info
= df_scan_get_bb_info (bb->index);
if (bb_info)
{
fprintf (file, ";; bb %d artificial_defs: ", bb->index);
df_refs_chain_dump (bb_info->artificial_defs, true, file);
fprintf (file, "\n;; bb %d artificial_uses: ", bb->index);
df_refs_chain_dump (bb_info->artificial_uses, true, file);
fprintf (file, "\n");
}
#if 0
{
rtx_insn *insn;
FOR_BB_INSNS (bb, insn)
if (INSN_P (insn))
df_insn_debug (insn, false, file);
}
#endif
}
static const struct df_problem problem_SCAN =
{
DF_SCAN, /* Problem id. */
DF_NONE, /* Direction. */
df_scan_alloc, /* Allocate the problem specific data. */
NULL, /* Reset global information. */
df_scan_free_bb_info, /* Free basic block info. */
NULL, /* Local compute function. */
NULL, /* Init the solution specific data. */
NULL, /* Iterative solver. */
NULL, /* Confluence operator 0. */
NULL, /* Confluence operator n. */
NULL, /* Transfer function. */
NULL, /* Finalize function. */
df_scan_free, /* Free all of the problem information. */
NULL, /* Remove this problem from the stack of dataflow problems. */
df_scan_start_dump, /* Debugging. */
df_scan_start_block, /* Debugging start block. */
NULL, /* Debugging end block. */
NULL, /* Debugging start insn. */
NULL, /* Debugging end insn. */
NULL, /* Incremental solution verify start. */
NULL, /* Incremental solution verify end. */
NULL, /* Dependent problem. */
sizeof (struct df_scan_bb_info),/* Size of entry of block_info array. */
TV_DF_SCAN, /* Timing variable. */
false /* Reset blocks on dropping out of blocks_to_analyze. */
};
/* Create a new DATAFLOW instance and add it to an existing instance
of DF. The returned structure is what is used to get at the
solution. */
void
df_scan_add_problem (void)
{
df_add_problem (&problem_SCAN);
}
/*----------------------------------------------------------------------------
Storage Allocation Utilities
----------------------------------------------------------------------------*/
/* First, grow the reg_info information. If the current size is less than
the number of pseudos, grow to 25% more than the number of
pseudos.
Second, assure that all of the slots up to max_reg_num have been
filled with reg_info structures. */
void
df_grow_reg_info (void)
{
unsigned int max_reg = max_reg_num ();
unsigned int new_size = max_reg;
struct df_scan_problem_data *problem_data
= (struct df_scan_problem_data *) df_scan->problem_data;
unsigned int i;
if (df->regs_size < new_size)
{
new_size += new_size / 4;
df->def_regs = XRESIZEVEC (struct df_reg_info *, df->def_regs, new_size);
df->use_regs = XRESIZEVEC (struct df_reg_info *, df->use_regs, new_size);
df->eq_use_regs = XRESIZEVEC (struct df_reg_info *, df->eq_use_regs,
new_size);
df->def_info.begin = XRESIZEVEC (unsigned, df->def_info.begin, new_size);
df->def_info.count = XRESIZEVEC (unsigned, df->def_info.count, new_size);
df->use_info.begin = XRESIZEVEC (unsigned, df->use_info.begin, new_size);
df->use_info.count = XRESIZEVEC (unsigned, df->use_info.count, new_size);
df->regs_size = new_size;
}
for (i = df->regs_inited; i < max_reg; i++)
{
struct df_reg_info *reg_info;
// TODO
reg_info = problem_data->reg_pool->allocate ();
memset (reg_info, 0, sizeof (struct df_reg_info));
df->def_regs[i] = reg_info;
reg_info = problem_data->reg_pool->allocate ();
memset (reg_info, 0, sizeof (struct df_reg_info));
df->use_regs[i] = reg_info;
reg_info = problem_data->reg_pool->allocate ();
memset (reg_info, 0, sizeof (struct df_reg_info));
df->eq_use_regs[i] = reg_info;
df->def_info.begin[i] = 0;
df->def_info.count[i] = 0;
df->use_info.begin[i] = 0;
df->use_info.count[i] = 0;
}
df->regs_inited = max_reg;
}
/* Grow the ref information. */
static void
df_grow_ref_info (struct df_ref_info *ref_info, unsigned int new_size)
{
if (ref_info->refs_size < new_size)
{
ref_info->refs = XRESIZEVEC (df_ref, ref_info->refs, new_size);
memset (ref_info->refs + ref_info->refs_size, 0,
(new_size - ref_info->refs_size) *sizeof (df_ref));
ref_info->refs_size = new_size;
}
}
/* Check and grow the ref information if necessary. This routine
guarantees total_size + BITMAP_ADDEND amount of entries in refs
array. It updates ref_info->refs_size only and does not change
ref_info->total_size. */
static void
df_check_and_grow_ref_info (struct df_ref_info *ref_info,
unsigned bitmap_addend)
{
if (ref_info->refs_size < ref_info->total_size + bitmap_addend)
{
int new_size = ref_info->total_size + bitmap_addend;
new_size += ref_info->total_size / 4;
df_grow_ref_info (ref_info, new_size);
}
}
/* Grow the ref information. If the current size is less than the
number of instructions, grow to 25% more than the number of
instructions. */
void
df_grow_insn_info (void)
{
unsigned int new_size = get_max_uid () + 1;
if (DF_INSN_SIZE () < new_size)
{
new_size += new_size / 4;
df->insns = XRESIZEVEC (struct df_insn_info *, df->insns, new_size);
memset (df->insns + df->insns_size, 0,
(new_size - DF_INSN_SIZE ()) *sizeof (struct df_insn_info *));
DF_INSN_SIZE () = new_size;
}
}
/*----------------------------------------------------------------------------
PUBLIC INTERFACES FOR SMALL GRAIN CHANGES TO SCANNING.
----------------------------------------------------------------------------*/
/* Rescan all of the block_to_analyze or all of the blocks in the
function if df_set_blocks if blocks_to_analyze is NULL; */
void
df_scan_blocks (void)
{
basic_block bb;
df->def_info.ref_order = DF_REF_ORDER_NO_TABLE;
df->use_info.ref_order = DF_REF_ORDER_NO_TABLE;
df_get_regular_block_artificial_uses (&df->regular_block_artificial_uses);
df_get_eh_block_artificial_uses (&df->eh_block_artificial_uses);
bitmap_ior_into (&df->eh_block_artificial_uses,
&df->regular_block_artificial_uses);
/* ENTRY and EXIT blocks have special defs/uses. */
df_get_entry_block_def_set (df->entry_block_defs);
df_record_entry_block_defs (df->entry_block_defs);
df_get_exit_block_use_set (df->exit_block_uses);
df_record_exit_block_uses (df->exit_block_uses);
df_set_bb_dirty (BASIC_BLOCK_FOR_FN (cfun, ENTRY_BLOCK));
df_set_bb_dirty (BASIC_BLOCK_FOR_FN (cfun, EXIT_BLOCK));
/* Regular blocks */
FOR_EACH_BB_FN (bb, cfun)
{
unsigned int bb_index = bb->index;
df_bb_refs_record (bb_index, true);
}
}
/* Create new refs under address LOC within INSN. This function is
only used externally. REF_FLAGS must be either 0 or DF_REF_IN_NOTE,
depending on whether LOC is inside PATTERN (INSN) or a note. */
void
df_uses_create (rtx *loc, rtx_insn *insn, int ref_flags)
{
gcc_assert (!(ref_flags & ~DF_REF_IN_NOTE));
df_uses_record (NULL, loc, DF_REF_REG_USE,
BLOCK_FOR_INSN (insn),
DF_INSN_INFO_GET (insn),
ref_flags);
}
static void
df_install_ref_incremental (df_ref ref)
{
struct df_reg_info **reg_info;
struct df_ref_info *ref_info;
df_ref *ref_ptr;
bool add_to_table;
rtx_insn *insn = DF_REF_INSN (ref);
basic_block bb = BLOCK_FOR_INSN (insn);
if (DF_REF_REG_DEF_P (ref))
{
reg_info = df->def_regs;
ref_info = &df->def_info;
ref_ptr = &DF_INSN_DEFS (insn);
add_to_table = ref_info->ref_order != DF_REF_ORDER_NO_TABLE;
}
else if (DF_REF_FLAGS (ref) & DF_REF_IN_NOTE)
{
reg_info = df->eq_use_regs;
ref_info = &df->use_info;
ref_ptr = &DF_INSN_EQ_USES (insn);
switch (ref_info->ref_order)
{
case DF_REF_ORDER_UNORDERED_WITH_NOTES:
case DF_REF_ORDER_BY_REG_WITH_NOTES:
case DF_REF_ORDER_BY_INSN_WITH_NOTES:
add_to_table = true;
break;
default:
add_to_table = false;
break;
}
}
else
{
reg_info = df->use_regs;
ref_info = &df->use_info;
ref_ptr = &DF_INSN_USES (insn);
add_to_table = ref_info->ref_order != DF_REF_ORDER_NO_TABLE;
}
/* Do not add if ref is not in the right blocks. */
if (add_to_table && df->analyze_subset)
add_to_table = bitmap_bit_p (df->blocks_to_analyze, bb->index);
df_install_ref (ref, reg_info[DF_REF_REGNO (ref)], ref_info, add_to_table);
if (add_to_table)
switch (ref_info->ref_order)
{
case DF_REF_ORDER_UNORDERED_WITH_NOTES:
case DF_REF_ORDER_BY_REG_WITH_NOTES:
case DF_REF_ORDER_BY_INSN_WITH_NOTES:
ref_info->ref_order = DF_REF_ORDER_UNORDERED_WITH_NOTES;
break;
default:
ref_info->ref_order = DF_REF_ORDER_UNORDERED;
break;
}
while (*ref_ptr && df_ref_compare (*ref_ptr, ref) < 0)
ref_ptr = &DF_REF_NEXT_LOC (*ref_ptr);
DF_REF_NEXT_LOC (ref) = *ref_ptr;
*ref_ptr = ref;
#if 0
if (dump_file)
{
fprintf (dump_file, "adding ref ");
df_ref_debug (ref, dump_file);
}
#endif
/* By adding the ref directly, df_insn_rescan my not find any
differences even though the block will have changed. So we need
to mark the block dirty ourselves. */
if (!DEBUG_INSN_P (DF_REF_INSN (ref)))
df_set_bb_dirty (bb);
}
/*----------------------------------------------------------------------------
UTILITIES TO CREATE AND DESTROY REFS AND CHAINS.
----------------------------------------------------------------------------*/
static void
df_free_ref (df_ref ref)
{
struct df_scan_problem_data *problem_data
= (struct df_scan_problem_data *) df_scan->problem_data;
switch (DF_REF_CLASS (ref))
{
case DF_REF_BASE:
problem_data->ref_base_pool->remove ((df_base_ref *) (ref));
break;
case DF_REF_ARTIFICIAL:
problem_data->ref_artificial_pool->remove
((df_artificial_ref *) (ref));
break;
case DF_REF_REGULAR:
problem_data->ref_regular_pool->remove
((df_regular_ref *) (ref));
break;
}
}
/* Unlink and delete REF at the reg_use, reg_eq_use or reg_def chain.
Also delete the def-use or use-def chain if it exists. */
static void
df_reg_chain_unlink (df_ref ref)
{
df_ref next = DF_REF_NEXT_REG (ref);
df_ref prev = DF_REF_PREV_REG (ref);
int id = DF_REF_ID (ref);
struct df_reg_info *reg_info;
df_ref *refs = NULL;
if (DF_REF_REG_DEF_P (ref))
{
int regno = DF_REF_REGNO (ref);
reg_info = DF_REG_DEF_GET (regno);
refs = df->def_info.refs;
}
else
{
if (DF_REF_FLAGS (ref) & DF_REF_IN_NOTE)
{
reg_info = DF_REG_EQ_USE_GET (DF_REF_REGNO (ref));
switch (df->use_info.ref_order)
{
case DF_REF_ORDER_UNORDERED_WITH_NOTES:
case DF_REF_ORDER_BY_REG_WITH_NOTES:
case DF_REF_ORDER_BY_INSN_WITH_NOTES:
refs = df->use_info.refs;
break;
default:
break;
}
}
else
{
reg_info = DF_REG_USE_GET (DF_REF_REGNO (ref));
refs = df->use_info.refs;
}
}
if (refs)
{
if (df->analyze_subset)
{
if (bitmap_bit_p (df->blocks_to_analyze, DF_REF_BBNO (ref)))
refs[id] = NULL;
}
else
refs[id] = NULL;
}
/* Delete any def-use or use-def chains that start here. It is
possible that there is trash in this field. This happens for
insns that have been deleted when rescanning has been deferred
and the chain problem has also been deleted. The chain tear down
code skips deleted insns. */
if (df_chain && DF_REF_CHAIN (ref))
df_chain_unlink (ref);
reg_info->n_refs--;
if (DF_REF_FLAGS_IS_SET (ref, DF_HARD_REG_LIVE))
{
gcc_assert (DF_REF_REGNO (ref) < FIRST_PSEUDO_REGISTER);
df->hard_regs_live_count[DF_REF_REGNO (ref)]--;
}
/* Unlink from the reg chain. If there is no prev, this is the
first of the list. If not, just join the next and prev. */
if (prev)
DF_REF_NEXT_REG (prev) = next;
else
{
gcc_assert (reg_info->reg_chain == ref);
reg_info->reg_chain = next;
}
if (next)
DF_REF_PREV_REG (next) = prev;
df_free_ref (ref);
}
/* Initialize INSN_INFO to describe INSN. */
static void
df_insn_info_init_fields (df_insn_info *insn_info, rtx_insn *insn)
{
memset (insn_info, 0, sizeof (struct df_insn_info));
insn_info->insn = insn;
}
/* Create the insn record for INSN. If there was one there, zero it
out. */
struct df_insn_info *
df_insn_create_insn_record (rtx_insn *insn)
{
struct df_scan_problem_data *problem_data
= (struct df_scan_problem_data *) df_scan->problem_data;
struct df_insn_info *insn_rec;
df_grow_insn_info ();
insn_rec = DF_INSN_INFO_GET (insn);
if (!insn_rec)
{
insn_rec = problem_data->insn_pool->allocate ();
DF_INSN_INFO_SET (insn, insn_rec);
}
df_insn_info_init_fields (insn_rec, insn);
return insn_rec;
}
/* Delete all du chain (DF_REF_CHAIN()) of all refs in the ref chain. */
static void
df_ref_chain_delete_du_chain (df_ref ref)
{
for (; ref; ref = DF_REF_NEXT_LOC (ref))
/* CHAIN is allocated by DF_CHAIN. So make sure to
pass df_scan instance for the problem. */
if (DF_REF_CHAIN (ref))
df_chain_unlink (ref);
}
/* Delete all refs in the ref chain. */
static void
df_ref_chain_delete (df_ref ref)
{
df_ref next;
for (; ref; ref = next)
{
next = DF_REF_NEXT_LOC (ref);
df_reg_chain_unlink (ref);
}
}
/* Delete the hardreg chain. */
static void
df_mw_hardreg_chain_delete (struct df_mw_hardreg *hardregs)
{
struct df_scan_problem_data *problem_data
= (struct df_scan_problem_data *) df_scan->problem_data;
df_mw_hardreg *next;
for (; hardregs; hardregs = next)
{
next = DF_MWS_NEXT (hardregs);
problem_data->mw_reg_pool->remove (hardregs);
}
}
/* Remove the contents of INSN_INFO (but don't free INSN_INFO itself). */
static void
df_insn_info_free_fields (df_insn_info *insn_info)
{
/* In general, notes do not have the insn_info fields
initialized. However, combine deletes insns by changing them
to notes. How clever. So we cannot just check if it is a
valid insn before short circuiting this code, we need to see
if we actually initialized it. */
df_mw_hardreg_chain_delete (insn_info->mw_hardregs);
if (df_chain)
{
df_ref_chain_delete_du_chain (insn_info->defs);
df_ref_chain_delete_du_chain (insn_info->uses);
df_ref_chain_delete_du_chain (insn_info->eq_uses);
}
df_ref_chain_delete (insn_info->defs);
df_ref_chain_delete (insn_info->uses);
df_ref_chain_delete (insn_info->eq_uses);
}
/* Delete all of the refs information from the insn with UID.
Internal helper for df_insn_delete, df_insn_rescan, and other
df-scan routines that don't have to work in deferred mode
and do not have to mark basic blocks for re-processing. */
static void
df_insn_info_delete (unsigned int uid)
{
struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid);
bitmap_clear_bit (&df->insns_to_delete, uid);
bitmap_clear_bit (&df->insns_to_rescan, uid);
bitmap_clear_bit (&df->insns_to_notes_rescan, uid);
if (insn_info)
{
struct df_scan_problem_data *problem_data
= (struct df_scan_problem_data *) df_scan->problem_data;
df_insn_info_free_fields (insn_info);
problem_data->insn_pool->remove (insn_info);
DF_INSN_UID_SET (uid, NULL);
}
}
/* Delete all of the refs information from INSN, either right now
or marked for later in deferred mode. */
void
df_insn_delete (rtx_insn *insn)
{
unsigned int uid;
basic_block bb;
gcc_checking_assert (INSN_P (insn));
if (!df)
return;
uid = INSN_UID (insn);
bb = BLOCK_FOR_INSN (insn);
/* ??? bb can be NULL after pass_free_cfg. At that point, DF should
not exist anymore (as mentioned in df-core.c: "The only requirement
[for DF] is that there be a correct control flow graph." Clearly
that isn't the case after pass_free_cfg. But DF is freed much later
because some back-ends want to use DF info even though the CFG is
already gone. It's not clear to me whether that is safe, actually.
In any case, we expect BB to be non-NULL at least up to register
allocation, so disallow a non-NULL BB up to there. Not perfect
but better than nothing... */
gcc_checking_assert (bb != NULL || reload_completed);
df_grow_bb_info (df_scan);
df_grow_reg_info ();
/* The block must be marked as dirty now, rather than later as in
df_insn_rescan and df_notes_rescan because it may not be there at
rescanning time and the mark would blow up.
DEBUG_INSNs do not make a block's data flow solution dirty (at
worst the LUIDs are no longer contiguous). */
if (bb != NULL && NONDEBUG_INSN_P (insn))
df_set_bb_dirty (bb);
/* The client has deferred rescanning. */
if (df->changeable_flags & DF_DEFER_INSN_RESCAN)
{
struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid);
if (insn_info)
{
bitmap_clear_bit (&df->insns_to_rescan, uid);
bitmap_clear_bit (&df->insns_to_notes_rescan, uid);
bitmap_set_bit (&df->insns_to_delete, uid);
}
if (dump_file)
fprintf (dump_file, "deferring deletion of insn with uid = %d.\n", uid);
return;
}
if (dump_file)
fprintf (dump_file, "deleting insn with uid = %d.\n", uid);
df_insn_info_delete (uid);
}
/* Free all of the refs and the mw_hardregs in COLLECTION_REC. */
static void
df_free_collection_rec (class df_collection_rec *collection_rec)
{
unsigned int ix;
struct df_scan_problem_data *problem_data
= (struct df_scan_problem_data *) df_scan->problem_data;
df_ref ref;
struct df_mw_hardreg *mw;
FOR_EACH_VEC_ELT (collection_rec->def_vec, ix, ref)
df_free_ref (ref);
FOR_EACH_VEC_ELT (collection_rec->use_vec, ix, ref)
df_free_ref (ref);
FOR_EACH_VEC_ELT (collection_rec->eq_use_vec, ix, ref)
df_free_ref (ref);