forked from illumos/gcc
/
df-scan.c
4540 lines (3807 loc) · 125 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, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
Originally contributed by Michael P. Hayes
(m.hayes@elec.canterbury.ac.nz, mhayes@redhat.com)
Major rewrite contributed by Danny Berlin (dberlin@dberlin.org)
and Kenneth Zadeck (zadeck@naturalbridge.com).
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 "rtl.h"
#include "tm_p.h"
#include "insn-config.h"
#include "recog.h"
#include "function.h"
#include "regs.h"
#include "output.h"
#include "alloc-pool.h"
#include "flags.h"
#include "hard-reg-set.h"
#include "basic-block.h"
#include "sbitmap.h"
#include "bitmap.h"
#include "timevar.h"
#include "tree.h"
#include "target.h"
#include "target-def.h"
#include "df.h"
#include "tree-pass.h"
#include "emit-rtl.h" /* FIXME: Can go away once crtl is moved to rtl.h. */
DEF_VEC_P(df_ref);
DEF_VEC_ALLOC_P_STACK(df_ref);
#define VEC_df_ref_stack_alloc(alloc) VEC_stack_alloc (df_ref, alloc)
typedef struct df_mw_hardreg *df_mw_hardreg_ptr;
DEF_VEC_P(df_mw_hardreg_ptr);
DEF_VEC_ALLOC_P_STACK(df_mw_hardreg_ptr);
#define VEC_df_mw_hardreg_ptr_stack_alloc(alloc) \
VEC_stack_alloc (df_mw_hardreg_ptr, alloc)
#ifndef HAVE_epilogue
#define HAVE_epilogue 0
#endif
#ifndef HAVE_prologue
#define HAVE_prologue 0
#endif
#ifndef HAVE_sibcall_epilogue
#define HAVE_sibcall_epilogue 0
#endif
#ifndef EPILOGUE_USES
#define EPILOGUE_USES(REGNO) 0
#endif
/* The following two macros free the vecs that hold either the refs or
the mw refs. They are a little tricky because the vec has 0
elements is special and is not to be freed. */
#define df_scan_free_ref_vec(V) \
do { \
if (V && *V) \
free (V); \
} while (0)
#define df_scan_free_mws_vec(V) \
do { \
if (V && *V) \
free (V); \
} while (0)
/* 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. */
struct df_collection_rec
{
VEC(df_ref,stack) *def_vec;
VEC(df_ref,stack) *use_vec;
VEC(df_ref,stack) *eq_use_vec;
VEC(df_mw_hardreg_ptr,stack) *mw_vec;
};
static df_ref df_null_ref_rec[1];
static struct df_mw_hardreg * df_null_mw_rec[1];
static void df_ref_record (enum df_ref_class, struct df_collection_rec *,
rtx, rtx *,
basic_block, struct df_insn_info *,
enum df_ref_type, int ref_flags);
static void df_def_record_1 (struct df_collection_rec *, rtx,
basic_block, struct df_insn_info *,
int ref_flags);
static void df_defs_record (struct df_collection_rec *, rtx,
basic_block, struct df_insn_info *,
int ref_flags);
static void df_uses_record (struct 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 df_ref df_ref_create_structure (enum df_ref_class,
struct df_collection_rec *, rtx, rtx *,
basic_block, struct df_insn_info *,
enum df_ref_type, int ref_flags);
static void df_insn_refs_collect (struct df_collection_rec*,
basic_block, struct df_insn_info *);
static void df_canonize_collection_rec (struct 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 (struct df_collection_rec *,
basic_block, rtx);
static bool df_insn_refs_verify (struct df_collection_rec *, basic_block, rtx, bool);
static void df_entry_block_defs_collect (struct df_collection_rec *, bitmap);
static void df_exit_block_uses_collect (struct 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 (const void *, const void *);
static int df_mw_compare (const void *, const void *);
/* 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];
/*----------------------------------------------------------------------------
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
{
alloc_pool ref_base_pool;
alloc_pool ref_artificial_pool;
alloc_pool ref_regular_pool;
alloc_pool insn_pool;
alloc_pool reg_pool;
alloc_pool mw_reg_pool;
bitmap_obstack reg_bitmaps;
bitmap_obstack insn_bitmaps;
};
typedef struct df_scan_bb_info *df_scan_bb_info_t;
/* 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;
unsigned int i;
basic_block bb;
/* The vectors that hold the refs are not pool allocated because
they come in many sizes. This makes them impossible to delete
all at once. */
for (i = 0; i < DF_INSN_SIZE(); i++)
{
struct df_insn_info *insn_info = DF_INSN_UID_GET(i);
/* Skip the insns that have no insn_info or have been
deleted. */
if (insn_info)
{
df_scan_free_ref_vec (insn_info->defs);
df_scan_free_ref_vec (insn_info->uses);
df_scan_free_ref_vec (insn_info->eq_uses);
df_scan_free_mws_vec (insn_info->mw_hardregs);
}
}
FOR_ALL_BB (bb)
{
unsigned int bb_index = bb->index;
struct df_scan_bb_info *bb_info = df_scan_get_bb_info (bb_index);
if (bb_info)
{
df_scan_free_ref_vec (bb_info->artificial_defs);
df_scan_free_ref_vec (bb_info->artificial_uses);
}
}
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);
free_alloc_pool (problem_data->ref_base_pool);
free_alloc_pool (problem_data->ref_artificial_pool);
free_alloc_pool (problem_data->ref_regular_pool);
free_alloc_pool (problem_data->insn_pool);
free_alloc_pool (problem_data->reg_pool);
free_alloc_pool (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;
/* See if bb_info is initialized. */
if (bb_info->artificial_defs)
{
rtx insn;
FOR_BB_INSNS (bb, insn)
{
if (INSN_P (insn))
/* Record defs within INSN. */
df_insn_delete (bb, 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. */
if (bb_info->artificial_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;
unsigned int insn_num = get_max_uid () + 1;
unsigned int block_size = 400;
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
= create_alloc_pool ("df_scan ref base",
sizeof (struct df_base_ref), block_size);
problem_data->ref_artificial_pool
= create_alloc_pool ("df_scan ref artificial",
sizeof (struct df_artificial_ref), block_size);
problem_data->ref_regular_pool
= create_alloc_pool ("df_scan ref regular",
sizeof (struct df_regular_ref), block_size);
problem_data->insn_pool
= create_alloc_pool ("df_scan insn",
sizeof (struct df_insn_info), block_size);
problem_data->reg_pool
= create_alloc_pool ("df_scan reg",
sizeof (struct df_reg_info), block_size);
problem_data->mw_reg_pool
= create_alloc_pool ("df_scan mw_reg",
sizeof (struct df_mw_hardreg), block_size);
bitmap_obstack_initialize (&problem_data->reg_bitmaps);
bitmap_obstack_initialize (&problem_data->insn_bitmaps);
insn_num += insn_num / 4;
df_grow_reg_info ();
df_grow_insn_info ();
df_grow_bb_info (df_scan);
FOR_ALL_BB (bb)
{
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;
fprintf (file, ";; invalidated by call \t");
df_print_regset (file, regs_invalidated_by_call_regset);
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 (bb)
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;
FOR_BB_INSNS (bb, insn)
if (INSN_P (insn))
df_insn_debug (insn, false, file);
}
#endif
}
static 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, /* 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;
reg_info = (struct df_reg_info *) pool_alloc (problem_data->reg_pool);
memset (reg_info, 0, sizeof (struct df_reg_info));
df->def_regs[i] = reg_info;
reg_info = (struct df_reg_info *) pool_alloc (problem_data->reg_pool);
memset (reg_info, 0, sizeof (struct df_reg_info));
df->use_regs[i] = reg_info;
reg_info = (struct df_reg_info *) pool_alloc (problem_data->reg_pool);
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 (ENTRY_BLOCK));
df_set_bb_dirty (BASIC_BLOCK (EXIT_BLOCK));
/* Regular blocks */
FOR_EACH_BB (bb)
{
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, 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);
}
/* Create a new ref of type DF_REF_TYPE for register REG at address
LOC within INSN of BB. This function is only used externally. */
df_ref
df_ref_create (rtx reg, rtx *loc, rtx insn,
basic_block bb,
enum df_ref_type ref_type,
int ref_flags)
{
enum df_ref_class cl;
df_grow_reg_info ();
/* You cannot hack artificial refs. */
gcc_assert (insn);
if (loc)
cl = DF_REF_REGULAR;
else
cl = DF_REF_BASE;
return df_ref_create_structure (cl, NULL, reg, loc, bb,
DF_INSN_INFO_GET (insn),
ref_type, 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_rec;
df_ref **ref_rec_ptr;
unsigned int count = 0;
bool add_to_table;
rtx 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_rec_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_rec_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_rec_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;
}
ref_rec = *ref_rec_ptr;
while (*ref_rec)
{
count++;
ref_rec++;
}
ref_rec = *ref_rec_ptr;
if (count)
{
ref_rec = XRESIZEVEC (df_ref, ref_rec, count+2);
*ref_rec_ptr = ref_rec;
ref_rec[count] = ref;
ref_rec[count+1] = NULL;
qsort (ref_rec, count + 1, sizeof (df_ref), df_ref_compare);
}
else
{
df_ref *ref_rec = XNEWVEC (df_ref, 2);
ref_rec[0] = ref;
ref_rec[1] = NULL;
*ref_rec_ptr = ref_rec;
}
#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:
pool_free (problem_data->ref_base_pool, ref);
break;
case DF_REF_ARTIFICIAL:
pool_free (problem_data->ref_artificial_pool, ref);
break;
case DF_REF_REGULAR:
pool_free (problem_data->ref_regular_pool, 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);
}
/* Remove REF from VEC. */
static void
df_ref_compress_rec (df_ref **vec_ptr, df_ref ref)
{
df_ref *vec = *vec_ptr;
if (vec[1])
{
while (*vec && *vec != ref)
vec++;
while (*vec)
{
*vec = *(vec+1);
vec++;
}
}
else
{
free (vec);
*vec_ptr = df_null_ref_rec;
}
}
/* Unlink REF from all def-use/use-def chains, etc. */
void
df_ref_remove (df_ref ref)
{
#if 0
if (dump_file)
{
fprintf (dump_file, "removing ref ");
df_ref_debug (ref, dump_file);
}
#endif
if (DF_REF_REG_DEF_P (ref))
{
if (DF_REF_IS_ARTIFICIAL (ref))
{
struct df_scan_bb_info *bb_info
= df_scan_get_bb_info (DF_REF_BBNO (ref));
df_ref_compress_rec (&bb_info->artificial_defs, ref);
}
else
{
unsigned int uid = DF_REF_INSN_UID (ref);
struct df_insn_info *insn_rec = DF_INSN_UID_GET (uid);
df_ref_compress_rec (&insn_rec->defs, ref);
}
}
else
{
if (DF_REF_IS_ARTIFICIAL (ref))
{
struct df_scan_bb_info *bb_info
= df_scan_get_bb_info (DF_REF_BBNO (ref));
df_ref_compress_rec (&bb_info->artificial_uses, ref);
}
else