1 /* Dataflow support routines.
2 Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
3 Contributed by Michael P. Hayes (m.hayes@elec.canterbury.ac.nz,
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
26 This file provides some dataflow routines for computing reaching defs,
27 upward exposed uses, live variables, def-use chains, and use-def
28 chains. The global dataflow is performed using simple iterative
29 methods with a worklist and could be sped up by ordering the blocks
30 with a depth first search order.
32 A `struct ref' data structure (ref) is allocated for every register
33 reference (def or use) and this records the insn and bb the ref is
34 found within. The refs are linked together in chains of uses and defs
35 for each insn and for each register. Each ref also has a chain field
36 that links all the use refs for a def or all the def refs for a use.
37 This is used to create use-def or def-use chains.
42 Here's an example of using the dataflow routines.
48 df_analyse (df, 0, DF_ALL);
50 df_dump (df, DF_ALL, stderr);
55 df_init simply creates a poor man's object (df) that needs to be
56 passed to all the dataflow routines. df_finish destroys this
57 object and frees up any allocated memory.
59 df_analyse performs the following:
61 1. Records defs and uses by scanning the insns in each basic block
62 or by scanning the insns queued by df_insn_modify.
63 2. Links defs and uses into insn-def and insn-use chains.
64 3. Links defs and uses into reg-def and reg-use chains.
65 4. Assigns LUIDs to each insn (for modified blocks).
66 5. Calculates local reaching definitions.
67 6. Calculates global reaching definitions.
68 7. Creates use-def chains.
69 8. Calculates local reaching uses (upwards exposed uses).
70 9. Calculates global reaching uses.
71 10. Creates def-use chains.
72 11. Calculates local live registers.
73 12. Calculates global live registers.
74 13. Calculates register lifetimes and determines local registers.
79 Note that the dataflow information is not updated for every newly
80 deleted or created insn. If the dataflow information requires
81 updating then all the changed, new, or deleted insns needs to be
82 marked with df_insn_modify (or df_insns_modify) either directly or
83 indirectly (say through calling df_insn_delete). df_insn_modify
84 marks all the modified insns to get processed the next time df_analyse
87 Beware that tinkering with insns may invalidate the dataflow information.
88 The philosophy behind these routines is that once the dataflow
89 information has been gathered, the user should store what they require
90 before they tinker with any insn. Once a reg is replaced, for example,
91 then the reg-def/reg-use chains will point to the wrong place. Once a
92 whole lot of changes have been made, df_analyse can be called again
93 to update the dataflow information. Currently, this is not very smart
94 with regard to propagating changes to the dataflow so it should not
100 The basic object is a REF (reference) and this may either be a DEF
101 (definition) or a USE of a register.
103 These are linked into a variety of lists; namely reg-def, reg-use,
104 insn-def, insn-use, def-use, and use-def lists. For example,
105 the reg-def lists contain all the refs that define a given register
106 while the insn-use lists contain all the refs used by an insn.
108 Note that the reg-def and reg-use chains are generally short (except for the
109 hard registers) and thus it is much faster to search these chains
110 rather than searching the def or use bitmaps.
112 If the insns are in SSA form then the reg-def and use-def lists
113 should only contain the single defining ref.
117 1) Incremental dataflow analysis.
119 Note that if a loop invariant insn is hoisted (or sunk), we do not
120 need to change the def-use or use-def chains. All we have to do is to
121 change the bb field for all the associated defs and uses and to
122 renumber the LUIDs for the original and new basic blocks of the insn.
124 When shadowing loop mems we create new uses and defs for new pseudos
125 so we do not affect the existing dataflow information.
127 My current strategy is to queue up all modified, created, or deleted
128 insns so when df_analyse is called we can easily determine all the new
129 or deleted refs. Currently the global dataflow information is
130 recomputed from scratch but this could be propagated more efficiently.
132 2) Improved global data flow computation using depth first search.
134 3) Reduced memory requirements.
136 We could operate a pool of ref structures. When a ref is deleted it
137 gets returned to the pool (say by linking on to a chain of free refs).
138 This will require a pair of bitmaps for defs and uses so that we can
139 tell which ones have been changed. Alternatively, we could
140 periodically squeeze the def and use tables and associated bitmaps and
141 renumber the def and use ids.
143 4) Ordering of reg-def and reg-use lists.
145 Should the first entry in the def list be the first def (within a BB)?
146 Similarly, should the first entry in the use list be the last use
149 5) Working with a sub-CFG.
151 Often the whole CFG does not need to be analysed, for example,
152 when optimising a loop, only certain registers are of interest.
153 Perhaps there should be a bitmap argument to df_analyse to specify
154 which registers should be analysed? */
160 #include "insn-config.h"
162 #include "function.h"
165 #include "hard-reg-set.h"
166 #include "basic-block.h"
172 #define FOR_EACH_BB_IN_BITMAP(BITMAP, MIN, BB, CODE) \
174 unsigned int node_; \
175 EXECUTE_IF_SET_IN_BITMAP (BITMAP, MIN, node_, \
176 {(BB) = BASIC_BLOCK (node_); CODE;});} while (0)
178 static struct obstack df_ref_obstack
;
179 static struct df
*ddf
;
181 static void df_reg_table_realloc
PARAMS((struct df
*, int));
183 static void df_def_table_realloc
PARAMS((struct df
*, int));
185 static void df_insn_table_realloc
PARAMS((struct df
*, unsigned int));
186 static void df_bitmaps_alloc
PARAMS((struct df
*, int));
187 static void df_bitmaps_free
PARAMS((struct df
*, int));
188 static void df_free
PARAMS((struct df
*));
189 static void df_alloc
PARAMS((struct df
*, int));
191 static rtx df_reg_clobber_gen
PARAMS((unsigned int));
192 static rtx df_reg_use_gen
PARAMS((unsigned int));
194 static inline struct df_link
*df_link_create
PARAMS((struct ref
*,
196 static struct df_link
*df_ref_unlink
PARAMS((struct df_link
**, struct ref
*));
197 static void df_def_unlink
PARAMS((struct df
*, struct ref
*));
198 static void df_use_unlink
PARAMS((struct df
*, struct ref
*));
199 static void df_insn_refs_unlink
PARAMS ((struct df
*, basic_block
, rtx
));
201 static void df_bb_refs_unlink
PARAMS ((struct df
*, basic_block
));
202 static void df_refs_unlink
PARAMS ((struct df
*, bitmap
));
205 static struct ref
*df_ref_create
PARAMS((struct df
*,
207 enum df_ref_type
, enum df_ref_flags
));
208 static void df_ref_record_1
PARAMS((struct df
*, rtx
, rtx
*,
209 rtx
, enum df_ref_type
,
211 static void df_ref_record
PARAMS((struct df
*, rtx
, rtx
*,
212 rtx
, enum df_ref_type
,
214 static void df_def_record_1
PARAMS((struct df
*, rtx
, basic_block
, rtx
));
215 static void df_defs_record
PARAMS((struct df
*, rtx
, basic_block
, rtx
));
216 static void df_uses_record
PARAMS((struct df
*, rtx
*,
217 enum df_ref_type
, basic_block
, rtx
,
219 static void df_insn_refs_record
PARAMS((struct df
*, basic_block
, rtx
));
220 static void df_bb_refs_record
PARAMS((struct df
*, basic_block
));
221 static void df_refs_record
PARAMS((struct df
*, bitmap
));
223 static void df_bb_reg_def_chain_create
PARAMS((struct df
*, basic_block
));
224 static void df_reg_def_chain_create
PARAMS((struct df
*, bitmap
));
225 static void df_bb_reg_use_chain_create
PARAMS((struct df
*, basic_block
));
226 static void df_reg_use_chain_create
PARAMS((struct df
*, bitmap
));
227 static void df_bb_du_chain_create
PARAMS((struct df
*, basic_block
, bitmap
));
228 static void df_du_chain_create
PARAMS((struct df
*, bitmap
));
229 static void df_bb_ud_chain_create
PARAMS((struct df
*, basic_block
));
230 static void df_ud_chain_create
PARAMS((struct df
*, bitmap
));
231 static void df_bb_rd_local_compute
PARAMS((struct df
*, basic_block
));
232 static void df_rd_local_compute
PARAMS((struct df
*, bitmap
));
233 static void df_bb_ru_local_compute
PARAMS((struct df
*, basic_block
));
234 static void df_ru_local_compute
PARAMS((struct df
*, bitmap
));
235 static void df_bb_lr_local_compute
PARAMS((struct df
*, basic_block
));
236 static void df_lr_local_compute
PARAMS((struct df
*, bitmap
));
237 static void df_bb_reg_info_compute
PARAMS((struct df
*, basic_block
, bitmap
));
238 static void df_reg_info_compute
PARAMS((struct df
*, bitmap
));
240 static int df_bb_luids_set
PARAMS((struct df
*df
, basic_block
));
241 static int df_luids_set
PARAMS((struct df
*df
, bitmap
));
243 static int df_modified_p
PARAMS ((struct df
*, bitmap
));
244 static int df_refs_queue
PARAMS ((struct df
*));
245 static int df_refs_process
PARAMS ((struct df
*));
246 static int df_bb_refs_update
PARAMS ((struct df
*, basic_block
));
247 static int df_refs_update
PARAMS ((struct df
*));
248 static void df_analyse_1
PARAMS((struct df
*, bitmap
, int, int));
250 static void df_insns_modify
PARAMS((struct df
*, basic_block
,
252 static int df_rtx_mem_replace
PARAMS ((rtx
*, void *));
253 static int df_rtx_reg_replace
PARAMS ((rtx
*, void *));
254 void df_refs_reg_replace
PARAMS ((struct df
*, bitmap
,
255 struct df_link
*, rtx
, rtx
));
257 static int df_def_dominates_all_uses_p
PARAMS((struct df
*, struct ref
*def
));
258 static int df_def_dominates_uses_p
PARAMS((struct df
*,
259 struct ref
*def
, bitmap
));
260 static struct ref
*df_bb_regno_last_use_find
PARAMS((struct df
*, basic_block
,
262 static struct ref
*df_bb_regno_first_def_find
PARAMS((struct df
*, basic_block
,
264 static struct ref
*df_bb_insn_regno_last_use_find
PARAMS((struct df
*,
267 static struct ref
*df_bb_insn_regno_first_def_find
PARAMS((struct df
*,
271 static void df_chain_dump
PARAMS((struct df_link
*, FILE *file
));
272 static void df_chain_dump_regno
PARAMS((struct df_link
*, FILE *file
));
273 static void df_regno_debug
PARAMS ((struct df
*, unsigned int, FILE *));
274 static void df_ref_debug
PARAMS ((struct df
*, struct ref
*, FILE *));
275 static void df_rd_transfer_function
PARAMS ((int, int *, bitmap
, bitmap
,
276 bitmap
, bitmap
, void *));
277 static void df_ru_transfer_function
PARAMS ((int, int *, bitmap
, bitmap
,
278 bitmap
, bitmap
, void *));
279 static void df_lr_transfer_function
PARAMS ((int, int *, bitmap
, bitmap
,
280 bitmap
, bitmap
, void *));
281 static void hybrid_search_bitmap
PARAMS ((basic_block
, bitmap
*, bitmap
*,
282 bitmap
*, bitmap
*, enum df_flow_dir
,
283 enum df_confluence_op
,
284 transfer_function_bitmap
,
285 sbitmap
, sbitmap
, void *));
286 static void hybrid_search_sbitmap
PARAMS ((basic_block
, sbitmap
*, sbitmap
*,
287 sbitmap
*, sbitmap
*, enum df_flow_dir
,
288 enum df_confluence_op
,
289 transfer_function_sbitmap
,
290 sbitmap
, sbitmap
, void *));
291 static inline bool read_modify_subreg_p
PARAMS ((rtx
));
294 /* Local memory allocation/deallocation routines. */
297 /* Increase the insn info table to have space for at least SIZE + 1
300 df_insn_table_realloc (df
, size
)
305 if (size
<= df
->insn_size
)
308 /* Make the table a little larger than requested, so we don't need
309 to enlarge it so often. */
310 size
+= df
->insn_size
/ 4;
312 df
->insns
= (struct insn_info
*)
313 xrealloc (df
->insns
, size
* sizeof (struct insn_info
));
315 memset (df
->insns
+ df
->insn_size
, 0,
316 (size
- df
->insn_size
) * sizeof (struct insn_info
));
318 df
->insn_size
= size
;
320 if (! df
->insns_modified
)
322 df
->insns_modified
= BITMAP_XMALLOC ();
323 bitmap_zero (df
->insns_modified
);
328 /* Increase the reg info table by SIZE more elements. */
330 df_reg_table_realloc (df
, size
)
334 /* Make table 25 percent larger by default. */
336 size
= df
->reg_size
/ 4;
338 size
+= df
->reg_size
;
339 if (size
< max_reg_num ())
340 size
= max_reg_num ();
342 df
->regs
= (struct reg_info
*)
343 xrealloc (df
->regs
, size
* sizeof (struct reg_info
));
345 /* Zero the new entries. */
346 memset (df
->regs
+ df
->reg_size
, 0,
347 (size
- df
->reg_size
) * sizeof (struct reg_info
));
354 /* Not currently used. */
356 df_def_table_realloc (df
, size
)
363 /* Make table 25 percent larger by default. */
365 size
= df
->def_size
/ 4;
367 df
->def_size
+= size
;
368 df
->defs
= xrealloc (df
->defs
,
369 df
->def_size
* sizeof (*df
->defs
));
371 /* Allocate a new block of memory and link into list of blocks
372 that will need to be freed later. */
374 refs
= xmalloc (size
* sizeof (*refs
));
376 /* Link all the new refs together, overloading the chain field. */
377 for (i
= 0; i
< size
- 1; i
++)
378 refs
[i
].chain
= (struct df_link
*)(refs
+ i
+ 1);
379 refs
[size
- 1].chain
= 0;
385 /* Allocate bitmaps for each basic block. */
387 df_bitmaps_alloc (df
, flags
)
394 /* Free the bitmaps if they need resizing. */
395 if ((flags
& DF_LR
) && df
->n_regs
< (unsigned int)max_reg_num ())
396 dflags
|= DF_LR
| DF_RU
;
397 if ((flags
& DF_RU
) && df
->n_uses
< df
->use_id
)
399 if ((flags
& DF_RD
) && df
->n_defs
< df
->def_id
)
403 df_bitmaps_free (df
, dflags
);
405 df
->n_defs
= df
->def_id
;
406 df
->n_uses
= df
->use_id
;
410 struct bb_info
*bb_info
= DF_BB_INFO (df
, bb
);
412 if (flags
& DF_RD
&& ! bb_info
->rd_in
)
414 /* Allocate bitmaps for reaching definitions. */
415 bb_info
->rd_kill
= BITMAP_XMALLOC ();
416 bitmap_zero (bb_info
->rd_kill
);
417 bb_info
->rd_gen
= BITMAP_XMALLOC ();
418 bitmap_zero (bb_info
->rd_gen
);
419 bb_info
->rd_in
= BITMAP_XMALLOC ();
420 bb_info
->rd_out
= BITMAP_XMALLOC ();
421 bb_info
->rd_valid
= 0;
424 if (flags
& DF_RU
&& ! bb_info
->ru_in
)
426 /* Allocate bitmaps for upward exposed uses. */
427 bb_info
->ru_kill
= BITMAP_XMALLOC ();
428 bitmap_zero (bb_info
->ru_kill
);
429 /* Note the lack of symmetry. */
430 bb_info
->ru_gen
= BITMAP_XMALLOC ();
431 bitmap_zero (bb_info
->ru_gen
);
432 bb_info
->ru_in
= BITMAP_XMALLOC ();
433 bb_info
->ru_out
= BITMAP_XMALLOC ();
434 bb_info
->ru_valid
= 0;
437 if (flags
& DF_LR
&& ! bb_info
->lr_in
)
439 /* Allocate bitmaps for live variables. */
440 bb_info
->lr_def
= BITMAP_XMALLOC ();
441 bitmap_zero (bb_info
->lr_def
);
442 bb_info
->lr_use
= BITMAP_XMALLOC ();
443 bitmap_zero (bb_info
->lr_use
);
444 bb_info
->lr_in
= BITMAP_XMALLOC ();
445 bb_info
->lr_out
= BITMAP_XMALLOC ();
446 bb_info
->lr_valid
= 0;
452 /* Free bitmaps for each basic block. */
454 df_bitmaps_free (df
, flags
)
455 struct df
*df ATTRIBUTE_UNUSED
;
462 struct bb_info
*bb_info
= DF_BB_INFO (df
, bb
);
467 if ((flags
& DF_RD
) && bb_info
->rd_in
)
469 /* Free bitmaps for reaching definitions. */
470 BITMAP_XFREE (bb_info
->rd_kill
);
471 bb_info
->rd_kill
= NULL
;
472 BITMAP_XFREE (bb_info
->rd_gen
);
473 bb_info
->rd_gen
= NULL
;
474 BITMAP_XFREE (bb_info
->rd_in
);
475 bb_info
->rd_in
= NULL
;
476 BITMAP_XFREE (bb_info
->rd_out
);
477 bb_info
->rd_out
= NULL
;
480 if ((flags
& DF_RU
) && bb_info
->ru_in
)
482 /* Free bitmaps for upward exposed uses. */
483 BITMAP_XFREE (bb_info
->ru_kill
);
484 bb_info
->ru_kill
= NULL
;
485 BITMAP_XFREE (bb_info
->ru_gen
);
486 bb_info
->ru_gen
= NULL
;
487 BITMAP_XFREE (bb_info
->ru_in
);
488 bb_info
->ru_in
= NULL
;
489 BITMAP_XFREE (bb_info
->ru_out
);
490 bb_info
->ru_out
= NULL
;
493 if ((flags
& DF_LR
) && bb_info
->lr_in
)
495 /* Free bitmaps for live variables. */
496 BITMAP_XFREE (bb_info
->lr_def
);
497 bb_info
->lr_def
= NULL
;
498 BITMAP_XFREE (bb_info
->lr_use
);
499 bb_info
->lr_use
= NULL
;
500 BITMAP_XFREE (bb_info
->lr_in
);
501 bb_info
->lr_in
= NULL
;
502 BITMAP_XFREE (bb_info
->lr_out
);
503 bb_info
->lr_out
= NULL
;
506 df
->flags
&= ~(flags
& (DF_RD
| DF_RU
| DF_LR
));
510 /* Allocate and initialize dataflow memory. */
512 df_alloc (df
, n_regs
)
519 gcc_obstack_init (&df_ref_obstack
);
521 /* Perhaps we should use LUIDs to save memory for the insn_refs
522 table. This is only a small saving; a few pointers. */
523 n_insns
= get_max_uid () + 1;
527 /* Approximate number of defs by number of insns. */
528 df
->def_size
= n_insns
;
529 df
->defs
= xmalloc (df
->def_size
* sizeof (*df
->defs
));
533 /* Approximate number of uses by twice number of insns. */
534 df
->use_size
= n_insns
* 2;
535 df
->uses
= xmalloc (df
->use_size
* sizeof (*df
->uses
));
538 df
->n_bbs
= last_basic_block
;
540 /* Allocate temporary working array used during local dataflow analysis. */
541 df
->reg_def_last
= xmalloc (df
->n_regs
* sizeof (struct ref
*));
543 df_insn_table_realloc (df
, n_insns
);
545 df_reg_table_realloc (df
, df
->n_regs
);
547 df
->bbs_modified
= BITMAP_XMALLOC ();
548 bitmap_zero (df
->bbs_modified
);
552 df
->bbs
= xcalloc (last_basic_block
, sizeof (struct bb_info
));
554 df
->all_blocks
= BITMAP_XMALLOC ();
556 bitmap_set_bit (df
->all_blocks
, bb
->index
);
560 /* Free all the dataflow info. */
565 df_bitmaps_free (df
, DF_ALL
);
593 if (df
->bbs_modified
)
594 BITMAP_XFREE (df
->bbs_modified
);
595 df
->bbs_modified
= 0;
597 if (df
->insns_modified
)
598 BITMAP_XFREE (df
->insns_modified
);
599 df
->insns_modified
= 0;
601 BITMAP_XFREE (df
->all_blocks
);
604 obstack_free (&df_ref_obstack
, NULL
);
607 /* Local miscellaneous routines. */
609 /* Return a USE for register REGNO. */
610 static rtx
df_reg_use_gen (regno
)
616 reg
= regno_reg_rtx
[regno
];
618 use
= gen_rtx_USE (GET_MODE (reg
), reg
);
623 /* Return a CLOBBER for register REGNO. */
624 static rtx
df_reg_clobber_gen (regno
)
630 reg
= regno_reg_rtx
[regno
];
632 use
= gen_rtx_CLOBBER (GET_MODE (reg
), reg
);
636 /* Local chain manipulation routines. */
638 /* Create a link in a def-use or use-def chain. */
639 static inline struct df_link
*
640 df_link_create (ref
, next
)
642 struct df_link
*next
;
644 struct df_link
*link
;
646 link
= (struct df_link
*) obstack_alloc (&df_ref_obstack
,
654 /* Add REF to chain head pointed to by PHEAD. */
655 static struct df_link
*
656 df_ref_unlink (phead
, ref
)
657 struct df_link
**phead
;
660 struct df_link
*link
= *phead
;
666 /* Only a single ref. It must be the one we want.
667 If not, the def-use and use-def chains are likely to
669 if (link
->ref
!= ref
)
671 /* Now have an empty chain. */
676 /* Multiple refs. One of them must be us. */
677 if (link
->ref
== ref
)
682 for (; link
->next
; link
= link
->next
)
684 if (link
->next
->ref
== ref
)
686 /* Unlink from list. */
687 link
->next
= link
->next
->next
;
698 /* Unlink REF from all def-use/use-def chains, etc. */
700 df_ref_remove (df
, ref
)
704 if (DF_REF_REG_DEF_P (ref
))
706 df_def_unlink (df
, ref
);
707 df_ref_unlink (&df
->insns
[DF_REF_INSN_UID (ref
)].defs
, ref
);
711 df_use_unlink (df
, ref
);
712 df_ref_unlink (&df
->insns
[DF_REF_INSN_UID (ref
)].uses
, ref
);
718 /* Unlink DEF from use-def and reg-def chains. */
720 df_def_unlink (df
, def
)
721 struct df
*df ATTRIBUTE_UNUSED
;
724 struct df_link
*du_link
;
725 unsigned int dregno
= DF_REF_REGNO (def
);
727 /* Follow def-use chain to find all the uses of this def. */
728 for (du_link
= DF_REF_CHAIN (def
); du_link
; du_link
= du_link
->next
)
730 struct ref
*use
= du_link
->ref
;
732 /* Unlink this def from the use-def chain. */
733 df_ref_unlink (&DF_REF_CHAIN (use
), def
);
735 DF_REF_CHAIN (def
) = 0;
737 /* Unlink def from reg-def chain. */
738 df_ref_unlink (&df
->regs
[dregno
].defs
, def
);
740 df
->defs
[DF_REF_ID (def
)] = 0;
744 /* Unlink use from def-use and reg-use chains. */
746 df_use_unlink (df
, use
)
747 struct df
*df ATTRIBUTE_UNUSED
;
750 struct df_link
*ud_link
;
751 unsigned int uregno
= DF_REF_REGNO (use
);
753 /* Follow use-def chain to find all the defs of this use. */
754 for (ud_link
= DF_REF_CHAIN (use
); ud_link
; ud_link
= ud_link
->next
)
756 struct ref
*def
= ud_link
->ref
;
758 /* Unlink this use from the def-use chain. */
759 df_ref_unlink (&DF_REF_CHAIN (def
), use
);
761 DF_REF_CHAIN (use
) = 0;
763 /* Unlink use from reg-use chain. */
764 df_ref_unlink (&df
->regs
[uregno
].uses
, use
);
766 df
->uses
[DF_REF_ID (use
)] = 0;
769 /* Local routines for recording refs. */
772 /* Create a new ref of type DF_REF_TYPE for register REG at address
773 LOC within INSN of BB. */
775 df_ref_create (df
, reg
, loc
, insn
, ref_type
, ref_flags
)
780 enum df_ref_type ref_type
;
781 enum df_ref_flags ref_flags
;
783 struct ref
*this_ref
;
786 this_ref
= (struct ref
*) obstack_alloc (&df_ref_obstack
,
788 DF_REF_REG (this_ref
) = reg
;
789 DF_REF_LOC (this_ref
) = loc
;
790 DF_REF_INSN (this_ref
) = insn
;
791 DF_REF_CHAIN (this_ref
) = 0;
792 DF_REF_TYPE (this_ref
) = ref_type
;
793 DF_REF_FLAGS (this_ref
) = ref_flags
;
794 uid
= INSN_UID (insn
);
796 if (ref_type
== DF_REF_REG_DEF
)
798 if (df
->def_id
>= df
->def_size
)
800 /* Make table 25 percent larger. */
801 df
->def_size
+= (df
->def_size
/ 4);
802 df
->defs
= xrealloc (df
->defs
,
803 df
->def_size
* sizeof (*df
->defs
));
805 DF_REF_ID (this_ref
) = df
->def_id
;
806 df
->defs
[df
->def_id
++] = this_ref
;
810 if (df
->use_id
>= df
->use_size
)
812 /* Make table 25 percent larger. */
813 df
->use_size
+= (df
->use_size
/ 4);
814 df
->uses
= xrealloc (df
->uses
,
815 df
->use_size
* sizeof (*df
->uses
));
817 DF_REF_ID (this_ref
) = df
->use_id
;
818 df
->uses
[df
->use_id
++] = this_ref
;
824 /* Create a new reference of type DF_REF_TYPE for a single register REG,
825 used inside the LOC rtx of INSN. */
827 df_ref_record_1 (df
, reg
, loc
, insn
, ref_type
, ref_flags
)
832 enum df_ref_type ref_type
;
833 enum df_ref_flags ref_flags
;
835 df_ref_create (df
, reg
, loc
, insn
, ref_type
, ref_flags
);
839 /* Create new references of type DF_REF_TYPE for each part of register REG
840 at address LOC within INSN of BB. */
842 df_ref_record (df
, reg
, loc
, insn
, ref_type
, ref_flags
)
847 enum df_ref_type ref_type
;
848 enum df_ref_flags ref_flags
;
852 if (GET_CODE (reg
) != REG
&& GET_CODE (reg
) != SUBREG
)
855 /* For the reg allocator we are interested in some SUBREG rtx's, but not
856 all. Notably only those representing a word extraction from a multi-word
857 reg. As written in the docu those should have the form
858 (subreg:SI (reg:M A) N), with size(SImode) > size(Mmode).
859 XXX Is that true? We could also use the global word_mode variable. */
860 if (GET_CODE (reg
) == SUBREG
861 && (GET_MODE_SIZE (GET_MODE (reg
)) < GET_MODE_SIZE (word_mode
)
862 || GET_MODE_SIZE (GET_MODE (reg
))
863 >= GET_MODE_SIZE (GET_MODE (SUBREG_REG (reg
)))))
865 loc
= &SUBREG_REG (reg
);
869 regno
= REGNO (GET_CODE (reg
) == SUBREG
? SUBREG_REG (reg
) : reg
);
870 if (regno
< FIRST_PSEUDO_REGISTER
)
875 if (! (df
->flags
& DF_HARD_REGS
))
878 /* GET_MODE (reg) is correct here. We don't want to go into a SUBREG
879 for the mode, because we only want to add references to regs, which
880 are really referenced. E.g. a (subreg:SI (reg:DI 0) 0) does _not_
881 reference the whole reg 0 in DI mode (which would also include
882 reg 1, at least, if 0 and 1 are SImode registers). */
883 endregno
= HARD_REGNO_NREGS (regno
, GET_MODE (reg
));
884 if (GET_CODE (reg
) == SUBREG
)
885 regno
+= subreg_regno_offset (regno
, GET_MODE (SUBREG_REG (reg
)),
886 SUBREG_BYTE (reg
), GET_MODE (reg
));
889 for (i
= regno
; i
< endregno
; i
++)
890 df_ref_record_1 (df
, regno_reg_rtx
[i
],
891 loc
, insn
, ref_type
, ref_flags
);
895 df_ref_record_1 (df
, reg
, loc
, insn
, ref_type
, ref_flags
);
899 /* Writes to paradoxical subregs, or subregs which are too narrow
900 are read-modify-write. */
903 read_modify_subreg_p (x
)
906 unsigned int isize
, osize
;
907 if (GET_CODE (x
) != SUBREG
)
909 isize
= GET_MODE_SIZE (GET_MODE (SUBREG_REG (x
)));
910 osize
= GET_MODE_SIZE (GET_MODE (x
));
913 if (isize
<= UNITS_PER_WORD
)
915 if (osize
>= UNITS_PER_WORD
)
920 /* Process all the registers defined in the rtx, X. */
922 df_def_record_1 (df
, x
, bb
, insn
)
928 rtx
*loc
= &SET_DEST (x
);
930 enum df_ref_flags flags
= 0;
932 /* Some targets place small structures in registers for
933 return values of functions. */
934 if (GET_CODE (dst
) == PARALLEL
&& GET_MODE (dst
) == BLKmode
)
938 for (i
= XVECLEN (dst
, 0) - 1; i
>= 0; i
--)
939 df_def_record_1 (df
, XVECEXP (dst
, 0, i
), bb
, insn
);
943 #ifdef CLASS_CANNOT_CHANGE_MODE
944 if (GET_CODE (dst
) == SUBREG
945 && CLASS_CANNOT_CHANGE_MODE_P (GET_MODE (dst
),
946 GET_MODE (SUBREG_REG (dst
))))
947 flags
|= DF_REF_MODE_CHANGE
;
950 /* May be, we should flag the use of strict_low_part somehow. Might be
951 handy for the reg allocator. */
952 while (GET_CODE (dst
) == STRICT_LOW_PART
953 || GET_CODE (dst
) == ZERO_EXTRACT
954 || GET_CODE (dst
) == SIGN_EXTRACT
955 || read_modify_subreg_p (dst
))
957 /* Strict low part always contains SUBREG, but we don't want to make
958 it appear outside, as whole register is always considered. */
959 if (GET_CODE (dst
) == STRICT_LOW_PART
)
961 loc
= &XEXP (dst
, 0);
964 #ifdef CLASS_CANNOT_CHANGE_MODE
965 if (GET_CODE (dst
) == SUBREG
966 && CLASS_CANNOT_CHANGE_MODE_P (GET_MODE (dst
),
967 GET_MODE (SUBREG_REG (dst
))))
968 flags
|= DF_REF_MODE_CHANGE
;
970 loc
= &XEXP (dst
, 0);
972 flags
|= DF_REF_READ_WRITE
;
975 if (GET_CODE (dst
) == REG
976 || (GET_CODE (dst
) == SUBREG
&& GET_CODE (SUBREG_REG (dst
)) == REG
))
977 df_ref_record (df
, dst
, loc
, insn
, DF_REF_REG_DEF
, flags
);
981 /* Process all the registers defined in the pattern rtx, X. */
983 df_defs_record (df
, x
, bb
, insn
)
989 RTX_CODE code
= GET_CODE (x
);
991 if (code
== SET
|| code
== CLOBBER
)
993 /* Mark the single def within the pattern. */
994 df_def_record_1 (df
, x
, bb
, insn
);
996 else if (code
== PARALLEL
)
1000 /* Mark the multiple defs within the pattern. */
1001 for (i
= XVECLEN (x
, 0) - 1; i
>= 0; i
--)
1003 code
= GET_CODE (XVECEXP (x
, 0, i
));
1004 if (code
== SET
|| code
== CLOBBER
)
1005 df_def_record_1 (df
, XVECEXP (x
, 0, i
), bb
, insn
);
1011 /* Process all the registers used in the rtx at address LOC. */
1013 df_uses_record (df
, loc
, ref_type
, bb
, insn
, flags
)
1016 enum df_ref_type ref_type
;
1019 enum df_ref_flags flags
;
1027 code
= GET_CODE (x
);
1042 /* If we are clobbering a MEM, mark any registers inside the address
1044 if (GET_CODE (XEXP (x
, 0)) == MEM
)
1045 df_uses_record (df
, &XEXP (XEXP (x
, 0), 0),
1046 DF_REF_REG_MEM_STORE
, bb
, insn
, flags
);
1048 /* If we're clobbering a REG then we have a def so ignore. */
1052 df_uses_record (df
, &XEXP (x
, 0), DF_REF_REG_MEM_LOAD
, bb
, insn
, flags
);
1056 /* While we're here, optimize this case. */
1058 /* In case the SUBREG is not of a register, don't optimize. */
1059 if (GET_CODE (SUBREG_REG (x
)) != REG
)
1061 loc
= &SUBREG_REG (x
);
1062 df_uses_record (df
, loc
, ref_type
, bb
, insn
, flags
);
1065 #ifdef CLASS_CANNOT_CHANGE_MODE
1066 if (CLASS_CANNOT_CHANGE_MODE_P (GET_MODE (x
),
1067 GET_MODE (SUBREG_REG (x
))))
1068 flags
|= DF_REF_MODE_CHANGE
;
1071 /* ... Fall through ... */
1074 /* See a register (or subreg) other than being set. */
1075 df_ref_record (df
, x
, loc
, insn
, ref_type
, flags
);
1080 rtx dst
= SET_DEST (x
);
1082 df_uses_record (df
, &SET_SRC (x
), DF_REF_REG_USE
, bb
, insn
, 0);
1084 switch (GET_CODE (dst
))
1086 enum df_ref_flags use_flags
;
1088 if (read_modify_subreg_p (dst
))
1090 use_flags
= DF_REF_READ_WRITE
;
1091 #ifdef CLASS_CANNOT_CHANGE_MODE
1092 if (CLASS_CANNOT_CHANGE_MODE_P (GET_MODE (dst
),
1093 GET_MODE (SUBREG_REG (dst
))))
1094 use_flags
|= DF_REF_MODE_CHANGE
;
1096 df_uses_record (df
, &SUBREG_REG (dst
), DF_REF_REG_USE
, bb
,
1100 /* ... FALLTHRU ... */
1106 df_uses_record (df
, &XEXP (dst
, 0),
1107 DF_REF_REG_MEM_STORE
,
1110 case STRICT_LOW_PART
:
1111 /* A strict_low_part uses the whole reg not only the subreg. */
1112 dst
= XEXP (dst
, 0);
1113 if (GET_CODE (dst
) != SUBREG
)
1115 use_flags
= DF_REF_READ_WRITE
;
1116 #ifdef CLASS_CANNOT_CHANGE_MODE
1117 if (CLASS_CANNOT_CHANGE_MODE_P (GET_MODE (dst
),
1118 GET_MODE (SUBREG_REG (dst
))))
1119 use_flags
|= DF_REF_MODE_CHANGE
;
1121 df_uses_record (df
, &SUBREG_REG (dst
), DF_REF_REG_USE
, bb
,
1126 df_uses_record (df
, &XEXP (dst
, 0), DF_REF_REG_USE
, bb
, insn
,
1128 df_uses_record (df
, &XEXP (dst
, 1), DF_REF_REG_USE
, bb
, insn
, 0);
1129 df_uses_record (df
, &XEXP (dst
, 2), DF_REF_REG_USE
, bb
, insn
, 0);
1130 dst
= XEXP (dst
, 0);
1142 case UNSPEC_VOLATILE
:
1146 /* Traditional and volatile asm instructions must be considered to use
1147 and clobber all hard registers, all pseudo-registers and all of
1148 memory. So must TRAP_IF and UNSPEC_VOLATILE operations.
1150 Consider for instance a volatile asm that changes the fpu rounding
1151 mode. An insn should not be moved across this even if it only uses
1152 pseudo-regs because it might give an incorrectly rounded result.
1154 For now, just mark any regs we can find in ASM_OPERANDS as
1157 /* For all ASM_OPERANDS, we must traverse the vector of input operands.
1158 We can not just fall through here since then we would be confused
1159 by the ASM_INPUT rtx inside ASM_OPERANDS, which do not indicate
1160 traditional asms unlike their normal usage. */
1161 if (code
== ASM_OPERANDS
)
1165 for (j
= 0; j
< ASM_OPERANDS_INPUT_LENGTH (x
); j
++)
1166 df_uses_record (df
, &ASM_OPERANDS_INPUT (x
, j
),
1167 DF_REF_REG_USE
, bb
, insn
, 0);
1179 /* Catch the def of the register being modified. */
1180 df_ref_record (df
, XEXP (x
, 0), &XEXP (x
, 0), insn
, DF_REF_REG_DEF
, DF_REF_READ_WRITE
);
1182 /* ... Fall through to handle uses ... */
1188 /* Recursively scan the operands of this expression. */
1190 const char *fmt
= GET_RTX_FORMAT (code
);
1193 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1197 /* Tail recursive case: save a function call level. */
1203 df_uses_record (df
, &XEXP (x
, i
), ref_type
, bb
, insn
, flags
);
1205 else if (fmt
[i
] == 'E')
1208 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1209 df_uses_record (df
, &XVECEXP (x
, i
, j
), ref_type
,
1217 /* Record all the df within INSN of basic block BB. */
1219 df_insn_refs_record (df
, bb
, insn
)
1230 /* Record register defs */
1231 df_defs_record (df
, PATTERN (insn
), bb
, insn
);
1233 if (df
->flags
& DF_EQUIV_NOTES
)
1234 for (note
= REG_NOTES (insn
); note
;
1235 note
= XEXP (note
, 1))
1237 switch (REG_NOTE_KIND (note
))
1241 df_uses_record (df
, &XEXP (note
, 0), DF_REF_REG_USE
,
1248 if (GET_CODE (insn
) == CALL_INSN
)
1253 /* Record the registers used to pass arguments. */
1254 for (note
= CALL_INSN_FUNCTION_USAGE (insn
); note
;
1255 note
= XEXP (note
, 1))
1257 if (GET_CODE (XEXP (note
, 0)) == USE
)
1258 df_uses_record (df
, &XEXP (XEXP (note
, 0), 0), DF_REF_REG_USE
,
1262 /* The stack ptr is used (honorarily) by a CALL insn. */
1263 x
= df_reg_use_gen (STACK_POINTER_REGNUM
);
1264 df_uses_record (df
, &XEXP (x
, 0), DF_REF_REG_USE
, bb
, insn
, 0);
1266 if (df
->flags
& DF_HARD_REGS
)
1268 /* Calls may also reference any of the global registers,
1269 so they are recorded as used. */
1270 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1273 x
= df_reg_use_gen (i
);
1274 df_uses_record (df
, &SET_DEST (x
),
1275 DF_REF_REG_USE
, bb
, insn
, 0);
1280 /* Record the register uses. */
1281 df_uses_record (df
, &PATTERN (insn
),
1282 DF_REF_REG_USE
, bb
, insn
, 0);
1285 if (GET_CODE (insn
) == CALL_INSN
)
1289 if (df
->flags
& DF_HARD_REGS
)
1291 /* Kill all registers invalidated by a call. */
1292 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1293 if (TEST_HARD_REG_BIT (regs_invalidated_by_call
, i
))
1295 rtx reg_clob
= df_reg_clobber_gen (i
);
1296 df_defs_record (df
, reg_clob
, bb
, insn
);
1300 /* There may be extra registers to be clobbered. */
1301 for (note
= CALL_INSN_FUNCTION_USAGE (insn
);
1303 note
= XEXP (note
, 1))
1304 if (GET_CODE (XEXP (note
, 0)) == CLOBBER
)
1305 df_defs_record (df
, XEXP (note
, 0), bb
, insn
);
1311 /* Record all the refs within the basic block BB. */
1313 df_bb_refs_record (df
, bb
)
1319 /* Scan the block an insn at a time from beginning to end. */
1320 for (insn
= bb
->head
; ; insn
= NEXT_INSN (insn
))
1324 /* Record defs within INSN. */
1325 df_insn_refs_record (df
, bb
, insn
);
1327 if (insn
== bb
->end
)
1333 /* Record all the refs in the basic blocks specified by BLOCKS. */
1335 df_refs_record (df
, blocks
)
1341 FOR_EACH_BB_IN_BITMAP (blocks
, 0, bb
,
1343 df_bb_refs_record (df
, bb
);
1347 /* Dataflow analysis routines. */
1350 /* Create reg-def chains for basic block BB. These are a list of
1351 definitions for each register. */
1353 df_bb_reg_def_chain_create (df
, bb
)
1359 /* Perhaps the defs should be sorted using a depth first search
1360 of the CFG (or possibly a breadth first search). We currently
1361 scan the basic blocks in reverse order so that the first defs
1362 appear at the start of the chain. */
1364 for (insn
= bb
->end
; insn
&& insn
!= PREV_INSN (bb
->head
);
1365 insn
= PREV_INSN (insn
))
1367 struct df_link
*link
;
1368 unsigned int uid
= INSN_UID (insn
);
1370 if (! INSN_P (insn
))
1373 for (link
= df
->insns
[uid
].defs
; link
; link
= link
->next
)
1375 struct ref
*def
= link
->ref
;
1376 unsigned int dregno
= DF_REF_REGNO (def
);
1377 /* Don't add ref's to the chain two times. I.e. only add
1378 new refs. XXX the same could be done by testing if the current
1379 insn is a modified (or a new) one. This would be faster. */
1380 if (DF_REF_ID (def
) < df
->def_id_save
)
1383 df
->regs
[dregno
].defs
1384 = df_link_create (def
, df
->regs
[dregno
].defs
);
1390 /* Create reg-def chains for each basic block within BLOCKS. These
1391 are a list of definitions for each register. */
1393 df_reg_def_chain_create (df
, blocks
)
1399 FOR_EACH_BB_IN_BITMAP
/*_REV*/ (blocks
, 0, bb
,
1401 df_bb_reg_def_chain_create (df
, bb
);
1406 /* Create reg-use chains for basic block BB. These are a list of uses
1407 for each register. */
1409 df_bb_reg_use_chain_create (df
, bb
)
1415 /* Scan in forward order so that the last uses appear at the
1416 start of the chain. */
1418 for (insn
= bb
->head
; insn
&& insn
!= NEXT_INSN (bb
->end
);
1419 insn
= NEXT_INSN (insn
))
1421 struct df_link
*link
;
1422 unsigned int uid
= INSN_UID (insn
);
1424 if (! INSN_P (insn
))
1427 for (link
= df
->insns
[uid
].uses
; link
; link
= link
->next
)
1429 struct ref
*use
= link
->ref
;
1430 unsigned int uregno
= DF_REF_REGNO (use
);
1431 /* Don't add ref's to the chain two times. I.e. only add
1432 new refs. XXX the same could be done by testing if the current
1433 insn is a modified (or a new) one. This would be faster. */
1434 if (DF_REF_ID (use
) < df
->use_id_save
)
1437 df
->regs
[uregno
].uses
1438 = df_link_create (use
, df
->regs
[uregno
].uses
);
1444 /* Create reg-use chains for each basic block within BLOCKS. These
1445 are a list of uses for each register. */
1447 df_reg_use_chain_create (df
, blocks
)
1453 FOR_EACH_BB_IN_BITMAP (blocks
, 0, bb
,
1455 df_bb_reg_use_chain_create (df
, bb
);
1460 /* Create def-use chains from reaching use bitmaps for basic block BB. */
1462 df_bb_du_chain_create (df
, bb
, ru
)
1467 struct bb_info
*bb_info
= DF_BB_INFO (df
, bb
);
1470 bitmap_copy (ru
, bb_info
->ru_out
);
1472 /* For each def in BB create a linked list (chain) of uses
1473 reached from the def. */
1474 for (insn
= bb
->end
; insn
&& insn
!= PREV_INSN (bb
->head
);
1475 insn
= PREV_INSN (insn
))
1477 struct df_link
*def_link
;
1478 struct df_link
*use_link
;
1479 unsigned int uid
= INSN_UID (insn
);
1481 if (! INSN_P (insn
))
1484 /* For each def in insn... */
1485 for (def_link
= df
->insns
[uid
].defs
; def_link
; def_link
= def_link
->next
)
1487 struct ref
*def
= def_link
->ref
;
1488 unsigned int dregno
= DF_REF_REGNO (def
);
1490 DF_REF_CHAIN (def
) = 0;
1492 /* While the reg-use chains are not essential, it
1493 is _much_ faster to search these short lists rather
1494 than all the reaching uses, especially for large functions. */
1495 for (use_link
= df
->regs
[dregno
].uses
; use_link
;
1496 use_link
= use_link
->next
)
1498 struct ref
*use
= use_link
->ref
;
1500 if (bitmap_bit_p (ru
, DF_REF_ID (use
)))
1503 = df_link_create (use
, DF_REF_CHAIN (def
));
1505 bitmap_clear_bit (ru
, DF_REF_ID (use
));
1510 /* For each use in insn... */
1511 for (use_link
= df
->insns
[uid
].uses
; use_link
; use_link
= use_link
->next
)
1513 struct ref
*use
= use_link
->ref
;
1514 bitmap_set_bit (ru
, DF_REF_ID (use
));
1520 /* Create def-use chains from reaching use bitmaps for basic blocks
1523 df_du_chain_create (df
, blocks
)
1530 ru
= BITMAP_XMALLOC ();
1532 FOR_EACH_BB_IN_BITMAP (blocks
, 0, bb
,
1534 df_bb_du_chain_create (df
, bb
, ru
);
1541 /* Create use-def chains from reaching def bitmaps for basic block BB. */
1543 df_bb_ud_chain_create (df
, bb
)
1547 struct bb_info
*bb_info
= DF_BB_INFO (df
, bb
);
1548 struct ref
**reg_def_last
= df
->reg_def_last
;
1551 memset (reg_def_last
, 0, df
->n_regs
* sizeof (struct ref
*));
1553 /* For each use in BB create a linked list (chain) of defs
1554 that reach the use. */
1555 for (insn
= bb
->head
; insn
&& insn
!= NEXT_INSN (bb
->end
);
1556 insn
= NEXT_INSN (insn
))
1558 unsigned int uid
= INSN_UID (insn
);
1559 struct df_link
*use_link
;
1560 struct df_link
*def_link
;
1562 if (! INSN_P (insn
))
1565 /* For each use in insn... */
1566 for (use_link
= df
->insns
[uid
].uses
; use_link
; use_link
= use_link
->next
)
1568 struct ref
*use
= use_link
->ref
;
1569 unsigned int regno
= DF_REF_REGNO (use
);
1571 DF_REF_CHAIN (use
) = 0;
1573 /* Has regno been defined in this BB yet? If so, use
1574 the last def as the single entry for the use-def
1575 chain for this use. Otherwise, we need to add all
1576 the defs using this regno that reach the start of
1578 if (reg_def_last
[regno
])
1581 = df_link_create (reg_def_last
[regno
], 0);
1585 /* While the reg-def chains are not essential, it is
1586 _much_ faster to search these short lists rather than
1587 all the reaching defs, especially for large
1589 for (def_link
= df
->regs
[regno
].defs
; def_link
;
1590 def_link
= def_link
->next
)
1592 struct ref
*def
= def_link
->ref
;
1594 if (bitmap_bit_p (bb_info
->rd_in
, DF_REF_ID (def
)))
1597 = df_link_create (def
, DF_REF_CHAIN (use
));
1604 /* For each def in insn...record the last def of each reg. */
1605 for (def_link
= df
->insns
[uid
].defs
; def_link
; def_link
= def_link
->next
)
1607 struct ref
*def
= def_link
->ref
;
1608 int dregno
= DF_REF_REGNO (def
);
1610 reg_def_last
[dregno
] = def
;
1616 /* Create use-def chains from reaching def bitmaps for basic blocks
1619 df_ud_chain_create (df
, blocks
)
1625 FOR_EACH_BB_IN_BITMAP (blocks
, 0, bb
,
1627 df_bb_ud_chain_create (df
, bb
);
1634 df_rd_transfer_function (bb
, changed
, in
, out
, gen
, kill
, data
)
1635 int bb ATTRIBUTE_UNUSED
;
1637 bitmap in
, out
, gen
, kill
;
1638 void *data ATTRIBUTE_UNUSED
;
1640 *changed
= bitmap_union_of_diff (out
, gen
, in
, kill
);
1643 df_ru_transfer_function (bb
, changed
, in
, out
, gen
, kill
, data
)
1644 int bb ATTRIBUTE_UNUSED
;
1646 bitmap in
, out
, gen
, kill
;
1647 void *data ATTRIBUTE_UNUSED
;
1649 *changed
= bitmap_union_of_diff (in
, gen
, out
, kill
);
1653 df_lr_transfer_function (bb
, changed
, in
, out
, use
, def
, data
)
1654 int bb ATTRIBUTE_UNUSED
;
1656 bitmap in
, out
, use
, def
;
1657 void *data ATTRIBUTE_UNUSED
;
1659 *changed
= bitmap_union_of_diff (in
, use
, out
, def
);
1663 /* Compute local reaching def info for basic block BB. */
1665 df_bb_rd_local_compute (df
, bb
)
1669 struct bb_info
*bb_info
= DF_BB_INFO (df
, bb
);
1672 for (insn
= bb
->head
; insn
&& insn
!= NEXT_INSN (bb
->end
);
1673 insn
= NEXT_INSN (insn
))
1675 unsigned int uid
= INSN_UID (insn
);
1676 struct df_link
*def_link
;
1678 if (! INSN_P (insn
))
1681 for (def_link
= df
->insns
[uid
].defs
; def_link
; def_link
= def_link
->next
)
1683 struct ref
*def
= def_link
->ref
;
1684 unsigned int regno
= DF_REF_REGNO (def
);
1685 struct df_link
*def2_link
;
1687 for (def2_link
= df
->regs
[regno
].defs
; def2_link
;
1688 def2_link
= def2_link
->next
)
1690 struct ref
*def2
= def2_link
->ref
;
1692 /* Add all defs of this reg to the set of kills. This
1693 is greedy since many of these defs will not actually
1694 be killed by this BB but it keeps things a lot
1696 bitmap_set_bit (bb_info
->rd_kill
, DF_REF_ID (def2
));
1698 /* Zap from the set of gens for this BB. */
1699 bitmap_clear_bit (bb_info
->rd_gen
, DF_REF_ID (def2
));
1702 bitmap_set_bit (bb_info
->rd_gen
, DF_REF_ID (def
));
1706 bb_info
->rd_valid
= 1;
1710 /* Compute local reaching def info for each basic block within BLOCKS. */
1712 df_rd_local_compute (df
, blocks
)
1718 FOR_EACH_BB_IN_BITMAP (blocks
, 0, bb
,
1720 df_bb_rd_local_compute (df
, bb
);
1725 /* Compute local reaching use (upward exposed use) info for basic
1728 df_bb_ru_local_compute (df
, bb
)
1732 /* This is much more tricky than computing reaching defs. With
1733 reaching defs, defs get killed by other defs. With upwards
1734 exposed uses, these get killed by defs with the same regno. */
1736 struct bb_info
*bb_info
= DF_BB_INFO (df
, bb
);
1740 for (insn
= bb
->end
; insn
&& insn
!= PREV_INSN (bb
->head
);
1741 insn
= PREV_INSN (insn
))
1743 unsigned int uid
= INSN_UID (insn
);
1744 struct df_link
*def_link
;
1745 struct df_link
*use_link
;
1747 if (! INSN_P (insn
))
1750 for (def_link
= df
->insns
[uid
].defs
; def_link
; def_link
= def_link
->next
)
1752 struct ref
*def
= def_link
->ref
;
1753 unsigned int dregno
= DF_REF_REGNO (def
);
1755 for (use_link
= df
->regs
[dregno
].uses
; use_link
;
1756 use_link
= use_link
->next
)
1758 struct ref
*use
= use_link
->ref
;
1760 /* Add all uses of this reg to the set of kills. This
1761 is greedy since many of these uses will not actually
1762 be killed by this BB but it keeps things a lot
1764 bitmap_set_bit (bb_info
->ru_kill
, DF_REF_ID (use
));
1766 /* Zap from the set of gens for this BB. */
1767 bitmap_clear_bit (bb_info
->ru_gen
, DF_REF_ID (use
));
1771 for (use_link
= df
->insns
[uid
].uses
; use_link
; use_link
= use_link
->next
)
1773 struct ref
*use
= use_link
->ref
;
1774 /* Add use to set of gens in this BB. */
1775 bitmap_set_bit (bb_info
->ru_gen
, DF_REF_ID (use
));
1778 bb_info
->ru_valid
= 1;
1782 /* Compute local reaching use (upward exposed use) info for each basic
1783 block within BLOCKS. */
1785 df_ru_local_compute (df
, blocks
)
1791 FOR_EACH_BB_IN_BITMAP (blocks
, 0, bb
,
1793 df_bb_ru_local_compute (df
, bb
);
1798 /* Compute local live variable info for basic block BB. */
1800 df_bb_lr_local_compute (df
, bb
)
1804 struct bb_info
*bb_info
= DF_BB_INFO (df
, bb
);
1807 for (insn
= bb
->end
; insn
&& insn
!= PREV_INSN (bb
->head
);
1808 insn
= PREV_INSN (insn
))
1810 unsigned int uid
= INSN_UID (insn
);
1811 struct df_link
*link
;
1813 if (! INSN_P (insn
))
1816 for (link
= df
->insns
[uid
].defs
; link
; link
= link
->next
)
1818 struct ref
*def
= link
->ref
;
1819 unsigned int dregno
= DF_REF_REGNO (def
);
1821 /* Add def to set of defs in this BB. */
1822 bitmap_set_bit (bb_info
->lr_def
, dregno
);
1824 bitmap_clear_bit (bb_info
->lr_use
, dregno
);
1827 for (link
= df
->insns
[uid
].uses
; link
; link
= link
->next
)
1829 struct ref
*use
= link
->ref
;
1830 /* Add use to set of uses in this BB. */
1831 bitmap_set_bit (bb_info
->lr_use
, DF_REF_REGNO (use
));
1834 bb_info
->lr_valid
= 1;
1838 /* Compute local live variable info for each basic block within BLOCKS. */
1840 df_lr_local_compute (df
, blocks
)
1846 FOR_EACH_BB_IN_BITMAP (blocks
, 0, bb
,
1848 df_bb_lr_local_compute (df
, bb
);
1853 /* Compute register info: lifetime, bb, and number of defs and uses
1854 for basic block BB. */
1856 df_bb_reg_info_compute (df
, bb
, live
)
1861 struct reg_info
*reg_info
= df
->regs
;
1862 struct bb_info
*bb_info
= DF_BB_INFO (df
, bb
);
1865 bitmap_copy (live
, bb_info
->lr_out
);
1867 for (insn
= bb
->end
; insn
&& insn
!= PREV_INSN (bb
->head
);
1868 insn
= PREV_INSN (insn
))
1870 unsigned int uid
= INSN_UID (insn
);
1872 struct df_link
*link
;
1874 if (! INSN_P (insn
))
1877 for (link
= df
->insns
[uid
].defs
; link
; link
= link
->next
)
1879 struct ref
*def
= link
->ref
;
1880 unsigned int dregno
= DF_REF_REGNO (def
);
1882 /* Kill this register. */
1883 bitmap_clear_bit (live
, dregno
);
1884 reg_info
[dregno
].n_defs
++;
1887 for (link
= df
->insns
[uid
].uses
; link
; link
= link
->next
)
1889 struct ref
*use
= link
->ref
;
1890 unsigned int uregno
= DF_REF_REGNO (use
);
1892 /* This register is now live. */
1893 bitmap_set_bit (live
, uregno
);
1894 reg_info
[uregno
].n_uses
++;
1897 /* Increment lifetimes of all live registers. */
1898 EXECUTE_IF_SET_IN_BITMAP (live
, 0, regno
,
1900 reg_info
[regno
].lifetime
++;
1906 /* Compute register info: lifetime, bb, and number of defs and uses. */
1908 df_reg_info_compute (df
, blocks
)
1915 live
= BITMAP_XMALLOC ();
1917 FOR_EACH_BB_IN_BITMAP (blocks
, 0, bb
,
1919 df_bb_reg_info_compute (df
, bb
, live
);
1922 BITMAP_XFREE (live
);
1926 /* Assign LUIDs for BB. */
1928 df_bb_luids_set (df
, bb
)
1935 /* The LUIDs are monotonically increasing for each basic block. */
1937 for (insn
= bb
->head
; ; insn
= NEXT_INSN (insn
))
1940 DF_INSN_LUID (df
, insn
) = luid
++;
1941 DF_INSN_LUID (df
, insn
) = luid
;
1943 if (insn
== bb
->end
)
1950 /* Assign LUIDs for each basic block within BLOCKS. */
1952 df_luids_set (df
, blocks
)
1959 FOR_EACH_BB_IN_BITMAP (blocks
, 0, bb
,
1961 total
+= df_bb_luids_set (df
, bb
);
1966 /* Perform dataflow analysis using existing DF structure for blocks
1967 within BLOCKS. If BLOCKS is zero, use all basic blocks in the CFG. */
1969 df_analyse_1 (df
, blocks
, flags
, update
)
1982 if (flags
& DF_UD_CHAIN
)
1983 aflags
|= DF_RD
| DF_RD_CHAIN
;
1985 if (flags
& DF_DU_CHAIN
)
1989 aflags
|= DF_RU_CHAIN
;
1991 if (flags
& DF_REG_INFO
)
1995 blocks
= df
->all_blocks
;
2000 df_refs_update (df
);
2001 /* More fine grained incremental dataflow analysis would be
2002 nice. For now recompute the whole shebang for the
2005 df_refs_unlink (df
, blocks
);
2007 /* All the def-use, use-def chains can be potentially
2008 modified by changes in one block. The size of the
2009 bitmaps can also change. */
2013 /* Scan the function for all register defs and uses. */
2015 df_refs_record (df
, blocks
);
2017 /* Link all the new defs and uses to the insns. */
2018 df_refs_process (df
);
2021 /* Allocate the bitmaps now the total number of defs and uses are
2022 known. If the number of defs or uses have changed, then
2023 these bitmaps need to be reallocated. */
2024 df_bitmaps_alloc (df
, aflags
);
2026 /* Set the LUIDs for each specified basic block. */
2027 df_luids_set (df
, blocks
);
2029 /* Recreate reg-def and reg-use chains from scratch so that first
2030 def is at the head of the reg-def chain and the last use is at
2031 the head of the reg-use chain. This is only important for
2032 regs local to a basic block as it speeds up searching. */
2033 if (aflags
& DF_RD_CHAIN
)
2035 df_reg_def_chain_create (df
, blocks
);
2038 if (aflags
& DF_RU_CHAIN
)
2040 df_reg_use_chain_create (df
, blocks
);
2043 df
->dfs_order
= xmalloc (sizeof(int) * n_basic_blocks
);
2044 df
->rc_order
= xmalloc (sizeof(int) * n_basic_blocks
);
2045 df
->rts_order
= xmalloc (sizeof(int) * n_basic_blocks
);
2046 df
->inverse_dfs_map
= xmalloc (sizeof(int) * last_basic_block
);
2047 df
->inverse_rc_map
= xmalloc (sizeof(int) * last_basic_block
);
2048 df
->inverse_rts_map
= xmalloc (sizeof(int) * last_basic_block
);
2050 flow_depth_first_order_compute (df
->dfs_order
, df
->rc_order
);
2051 flow_reverse_top_sort_order_compute (df
->rts_order
);
2052 for (i
= 0; i
< n_basic_blocks
; i
++)
2054 df
->inverse_dfs_map
[df
->dfs_order
[i
]] = i
;
2055 df
->inverse_rc_map
[df
->rc_order
[i
]] = i
;
2056 df
->inverse_rts_map
[df
->rts_order
[i
]] = i
;
2060 /* Compute the sets of gens and kills for the defs of each bb. */
2061 df_rd_local_compute (df
, df
->flags
& DF_RD
? blocks
: df
->all_blocks
);
2063 bitmap
*in
= xmalloc (sizeof (bitmap
) * last_basic_block
);
2064 bitmap
*out
= xmalloc (sizeof (bitmap
) * last_basic_block
);
2065 bitmap
*gen
= xmalloc (sizeof (bitmap
) * last_basic_block
);
2066 bitmap
*kill
= xmalloc (sizeof (bitmap
) * last_basic_block
);
2069 in
[bb
->index
] = DF_BB_INFO (df
, bb
)->rd_in
;
2070 out
[bb
->index
] = DF_BB_INFO (df
, bb
)->rd_out
;
2071 gen
[bb
->index
] = DF_BB_INFO (df
, bb
)->rd_gen
;
2072 kill
[bb
->index
] = DF_BB_INFO (df
, bb
)->rd_kill
;
2074 iterative_dataflow_bitmap (in
, out
, gen
, kill
, df
->all_blocks
,
2075 FORWARD
, UNION
, df_rd_transfer_function
,
2076 df
->inverse_rc_map
, NULL
);
2084 if (aflags
& DF_UD_CHAIN
)
2086 /* Create use-def chains. */
2087 df_ud_chain_create (df
, df
->all_blocks
);
2089 if (! (flags
& DF_RD
))
2095 /* Compute the sets of gens and kills for the upwards exposed
2097 df_ru_local_compute (df
, df
->flags
& DF_RU
? blocks
: df
->all_blocks
);
2099 bitmap
*in
= xmalloc (sizeof (bitmap
) * last_basic_block
);
2100 bitmap
*out
= xmalloc (sizeof (bitmap
) * last_basic_block
);
2101 bitmap
*gen
= xmalloc (sizeof (bitmap
) * last_basic_block
);
2102 bitmap
*kill
= xmalloc (sizeof (bitmap
) * last_basic_block
);
2105 in
[bb
->index
] = DF_BB_INFO (df
, bb
)->ru_in
;
2106 out
[bb
->index
] = DF_BB_INFO (df
, bb
)->ru_out
;
2107 gen
[bb
->index
] = DF_BB_INFO (df
, bb
)->ru_gen
;
2108 kill
[bb
->index
] = DF_BB_INFO (df
, bb
)->ru_kill
;
2110 iterative_dataflow_bitmap (in
, out
, gen
, kill
, df
->all_blocks
,
2111 BACKWARD
, UNION
, df_ru_transfer_function
,
2112 df
->inverse_rts_map
, NULL
);
2120 if (aflags
& DF_DU_CHAIN
)
2122 /* Create def-use chains. */
2123 df_du_chain_create (df
, df
->all_blocks
);
2125 if (! (flags
& DF_RU
))
2129 /* Free up bitmaps that are no longer required. */
2131 df_bitmaps_free (df
, dflags
);
2135 /* Compute the sets of defs and uses of live variables. */
2136 df_lr_local_compute (df
, df
->flags
& DF_LR
? blocks
: df
->all_blocks
);
2138 bitmap
*in
= xmalloc (sizeof (bitmap
) * last_basic_block
);
2139 bitmap
*out
= xmalloc (sizeof (bitmap
) * last_basic_block
);
2140 bitmap
*use
= xmalloc (sizeof (bitmap
) * last_basic_block
);
2141 bitmap
*def
= xmalloc (sizeof (bitmap
) * last_basic_block
);
2144 in
[bb
->index
] = DF_BB_INFO (df
, bb
)->lr_in
;
2145 out
[bb
->index
] = DF_BB_INFO (df
, bb
)->lr_out
;
2146 use
[bb
->index
] = DF_BB_INFO (df
, bb
)->lr_use
;
2147 def
[bb
->index
] = DF_BB_INFO (df
, bb
)->lr_def
;
2149 iterative_dataflow_bitmap (in
, out
, use
, def
, df
->all_blocks
,
2150 BACKWARD
, UNION
, df_lr_transfer_function
,
2151 df
->inverse_rts_map
, NULL
);
2159 if (aflags
& DF_REG_INFO
)
2161 df_reg_info_compute (df
, df
->all_blocks
);
2163 free (df
->dfs_order
);
2164 free (df
->rc_order
);
2165 free (df
->rts_order
);
2166 free (df
->inverse_rc_map
);
2167 free (df
->inverse_dfs_map
);
2168 free (df
->inverse_rts_map
);
2172 /* Initialize dataflow analysis. */
2178 df
= xcalloc (1, sizeof (struct df
));
2180 /* Squirrel away a global for debugging. */
2187 /* Start queuing refs. */
2192 df
->def_id_save
= df
->def_id
;
2193 df
->use_id_save
= df
->use_id
;
2194 /* ???? Perhaps we should save current obstack state so that we can
2200 /* Process queued refs. */
2202 df_refs_process (df
)
2207 /* Build new insn-def chains. */
2208 for (i
= df
->def_id_save
; i
!= df
->def_id
; i
++)
2210 struct ref
*def
= df
->defs
[i
];
2211 unsigned int uid
= DF_REF_INSN_UID (def
);
2213 /* Add def to head of def list for INSN. */
2215 = df_link_create (def
, df
->insns
[uid
].defs
);
2218 /* Build new insn-use chains. */
2219 for (i
= df
->use_id_save
; i
!= df
->use_id
; i
++)
2221 struct ref
*use
= df
->uses
[i
];
2222 unsigned int uid
= DF_REF_INSN_UID (use
);
2224 /* Add use to head of use list for INSN. */
2226 = df_link_create (use
, df
->insns
[uid
].uses
);
2232 /* Update refs for basic block BB. */
2234 df_bb_refs_update (df
, bb
)
2241 /* While we have to scan the chain of insns for this BB, we don't
2242 need to allocate and queue a long chain of BB/INSN pairs. Using
2243 a bitmap for insns_modified saves memory and avoids queuing
2246 for (insn
= bb
->head
; ; insn
= NEXT_INSN (insn
))
2250 uid
= INSN_UID (insn
);
2252 if (bitmap_bit_p (df
->insns_modified
, uid
))
2254 /* Delete any allocated refs of this insn. MPH, FIXME. */
2255 df_insn_refs_unlink (df
, bb
, insn
);
2257 /* Scan the insn for refs. */
2258 df_insn_refs_record (df
, bb
, insn
);
2262 if (insn
== bb
->end
)
2269 /* Process all the modified/deleted insns that were queued. */
2277 if ((unsigned int)max_reg_num () >= df
->reg_size
)
2278 df_reg_table_realloc (df
, 0);
2282 FOR_EACH_BB_IN_BITMAP (df
->bbs_modified
, 0, bb
,
2284 count
+= df_bb_refs_update (df
, bb
);
2287 df_refs_process (df
);
2292 /* Return nonzero if any of the requested blocks in the bitmap
2293 BLOCKS have been modified. */
2295 df_modified_p (df
, blocks
)
2306 if (bitmap_bit_p (df
->bbs_modified
, bb
->index
)
2307 && (! blocks
|| (blocks
== (bitmap
) -1) || bitmap_bit_p (blocks
, bb
->index
)))
2317 /* Analyse dataflow info for the basic blocks specified by the bitmap
2318 BLOCKS, or for the whole CFG if BLOCKS is zero, or just for the
2319 modified blocks if BLOCKS is -1. */
2321 df_analyse (df
, blocks
, flags
)
2328 /* We could deal with additional basic blocks being created by
2329 rescanning everything again. */
2330 if (df
->n_bbs
&& df
->n_bbs
!= (unsigned int) last_basic_block
)
2333 update
= df_modified_p (df
, blocks
);
2334 if (update
|| (flags
!= df
->flags
))
2340 /* Recompute everything from scratch. */
2343 /* Allocate and initialize data structures. */
2344 df_alloc (df
, max_reg_num ());
2345 df_analyse_1 (df
, 0, flags
, 0);
2350 if (blocks
== (bitmap
) -1)
2351 blocks
= df
->bbs_modified
;
2356 df_analyse_1 (df
, blocks
, flags
, 1);
2357 bitmap_zero (df
->bbs_modified
);
2358 bitmap_zero (df
->insns_modified
);
2365 /* Free all the dataflow info and the DF structure. */
2375 /* Unlink INSN from its reference information. */
2377 df_insn_refs_unlink (df
, bb
, insn
)
2379 basic_block bb ATTRIBUTE_UNUSED
;
2382 struct df_link
*link
;
2385 uid
= INSN_UID (insn
);
2387 /* Unlink all refs defined by this insn. */
2388 for (link
= df
->insns
[uid
].defs
; link
; link
= link
->next
)
2389 df_def_unlink (df
, link
->ref
);
2391 /* Unlink all refs used by this insn. */
2392 for (link
= df
->insns
[uid
].uses
; link
; link
= link
->next
)
2393 df_use_unlink (df
, link
->ref
);
2395 df
->insns
[uid
].defs
= 0;
2396 df
->insns
[uid
].uses
= 0;
2401 /* Unlink all the insns within BB from their reference information. */
2403 df_bb_refs_unlink (df
, bb
)
2409 /* Scan the block an insn at a time from beginning to end. */
2410 for (insn
= bb
->head
; ; insn
= NEXT_INSN (insn
))
2414 /* Unlink refs for INSN. */
2415 df_insn_refs_unlink (df
, bb
, insn
);
2417 if (insn
== bb
->end
)
2423 /* Unlink all the refs in the basic blocks specified by BLOCKS.
2424 Not currently used. */
2426 df_refs_unlink (df
, blocks
)
2434 FOR_EACH_BB_IN_BITMAP (blocks
, 0, bb
,
2436 df_bb_refs_unlink (df
, bb
);
2442 df_bb_refs_unlink (df
, bb
);
2447 /* Functions to modify insns. */
2450 /* Delete INSN and all its reference information. */
2452 df_insn_delete (df
, bb
, insn
)
2454 basic_block bb ATTRIBUTE_UNUSED
;
2457 /* If the insn is a jump, we should perhaps call delete_insn to
2458 handle the JUMP_LABEL? */
2460 /* We should not be deleting the NOTE_INSN_BASIC_BLOCK or label. */
2461 if (insn
== bb
->head
)
2464 /* Delete the insn. */
2467 df_insn_modify (df
, bb
, insn
);
2469 return NEXT_INSN (insn
);
2473 /* Mark that INSN within BB may have changed (created/modified/deleted).
2474 This may be called multiple times for the same insn. There is no
2475 harm calling this function if the insn wasn't changed; it will just
2476 slow down the rescanning of refs. */
2478 df_insn_modify (df
, bb
, insn
)
2485 uid
= INSN_UID (insn
);
2486 if (uid
>= df
->insn_size
)
2487 df_insn_table_realloc (df
, uid
);
2489 bitmap_set_bit (df
->bbs_modified
, bb
->index
);
2490 bitmap_set_bit (df
->insns_modified
, uid
);
2492 /* For incremental updating on the fly, perhaps we could make a copy
2493 of all the refs of the original insn and turn them into
2494 anti-refs. When df_refs_update finds these anti-refs, it annihilates
2495 the original refs. If validate_change fails then these anti-refs
2496 will just get ignored. */
2500 typedef struct replace_args
2509 /* Replace mem pointed to by PX with its associated pseudo register.
2510 DATA is actually a pointer to a structure describing the
2511 instruction currently being scanned and the MEM we are currently
2514 df_rtx_mem_replace (px
, data
)
2518 replace_args
*args
= (replace_args
*) data
;
2521 if (mem
== NULL_RTX
)
2524 switch (GET_CODE (mem
))
2530 /* We're not interested in the MEM associated with a
2531 CONST_DOUBLE, so there's no need to traverse into one. */
2535 /* This is not a MEM. */
2539 if (!rtx_equal_p (args
->match
, mem
))
2540 /* This is not the MEM we are currently replacing. */
2543 /* Actually replace the MEM. */
2544 validate_change (args
->insn
, px
, args
->replacement
, 1);
2552 df_insn_mem_replace (df
, bb
, insn
, mem
, reg
)
2563 args
.replacement
= reg
;
2566 /* Search and replace all matching mems within insn. */
2567 for_each_rtx (&insn
, df_rtx_mem_replace
, &args
);
2570 df_insn_modify (df
, bb
, insn
);
2572 /* ???? FIXME. We may have a new def or one or more new uses of REG
2573 in INSN. REG should be a new pseudo so it won't affect the
2574 dataflow information that we currently have. We should add
2575 the new uses and defs to INSN and then recreate the chains
2576 when df_analyse is called. */
2577 return args
.modified
;
2581 /* Replace one register with another. Called through for_each_rtx; PX
2582 points to the rtx being scanned. DATA is actually a pointer to a
2583 structure of arguments. */
2585 df_rtx_reg_replace (px
, data
)
2590 replace_args
*args
= (replace_args
*) data
;
2595 if (x
== args
->match
)
2597 validate_change (args
->insn
, px
, args
->replacement
, 1);
2605 /* Replace the reg within every ref on CHAIN that is within the set
2606 BLOCKS of basic blocks with NEWREG. Also update the regs within
2609 df_refs_reg_replace (df
, blocks
, chain
, oldreg
, newreg
)
2612 struct df_link
*chain
;
2616 struct df_link
*link
;
2620 blocks
= df
->all_blocks
;
2622 args
.match
= oldreg
;
2623 args
.replacement
= newreg
;
2626 for (link
= chain
; link
; link
= link
->next
)
2628 struct ref
*ref
= link
->ref
;
2629 rtx insn
= DF_REF_INSN (ref
);
2631 if (! INSN_P (insn
))
2634 if (bitmap_bit_p (blocks
, DF_REF_BBNO (ref
)))
2636 df_ref_reg_replace (df
, ref
, oldreg
, newreg
);
2638 /* Replace occurrences of the reg within the REG_NOTES. */
2639 if ((! link
->next
|| DF_REF_INSN (ref
)
2640 != DF_REF_INSN (link
->next
->ref
))
2641 && REG_NOTES (insn
))
2644 for_each_rtx (®_NOTES (insn
), df_rtx_reg_replace
, &args
);
2649 /* Temporary check to ensure that we have a grip on which
2650 regs should be replaced. */
2657 /* Replace all occurrences of register OLDREG with register NEWREG in
2658 blocks defined by bitmap BLOCKS. This also replaces occurrences of
2659 OLDREG in the REG_NOTES but only for insns containing OLDREG. This
2660 routine expects the reg-use and reg-def chains to be valid. */
2662 df_reg_replace (df
, blocks
, oldreg
, newreg
)
2668 unsigned int oldregno
= REGNO (oldreg
);
2670 df_refs_reg_replace (df
, blocks
, df
->regs
[oldregno
].defs
, oldreg
, newreg
);
2671 df_refs_reg_replace (df
, blocks
, df
->regs
[oldregno
].uses
, oldreg
, newreg
);
2676 /* Try replacing the reg within REF with NEWREG. Do not modify
2677 def-use/use-def chains. */
2679 df_ref_reg_replace (df
, ref
, oldreg
, newreg
)
2685 /* Check that insn was deleted by being converted into a NOTE. If
2686 so ignore this insn. */
2687 if (! INSN_P (DF_REF_INSN (ref
)))
2690 if (oldreg
&& oldreg
!= DF_REF_REG (ref
))
2693 if (! validate_change (DF_REF_INSN (ref
), DF_REF_LOC (ref
), newreg
, 1))
2696 df_insn_modify (df
, DF_REF_BB (ref
), DF_REF_INSN (ref
));
2702 df_bb_def_use_swap (df
, bb
, def_insn
, use_insn
, regno
)
2713 struct df_link
*link
;
2715 def
= df_bb_insn_regno_first_def_find (df
, bb
, def_insn
, regno
);
2719 use
= df_bb_insn_regno_last_use_find (df
, bb
, use_insn
, regno
);
2723 /* The USE no longer exists. */
2724 use_uid
= INSN_UID (use_insn
);
2725 df_use_unlink (df
, use
);
2726 df_ref_unlink (&df
->insns
[use_uid
].uses
, use
);
2728 /* The DEF requires shifting so remove it from DEF_INSN
2729 and add it to USE_INSN by reusing LINK. */
2730 def_uid
= INSN_UID (def_insn
);
2731 link
= df_ref_unlink (&df
->insns
[def_uid
].defs
, def
);
2733 link
->next
= df
->insns
[use_uid
].defs
;
2734 df
->insns
[use_uid
].defs
= link
;
2737 link
= df_ref_unlink (&df
->regs
[regno
].defs
, def
);
2739 link
->next
= df
->regs
[regno
].defs
;
2740 df
->insns
[regno
].defs
= link
;
2743 DF_REF_INSN (def
) = use_insn
;
2748 /* Record df between FIRST_INSN and LAST_INSN inclusive. All new
2749 insns must be processed by this routine. */
2751 df_insns_modify (df
, bb
, first_insn
, last_insn
)
2759 for (insn
= first_insn
; ; insn
= NEXT_INSN (insn
))
2763 /* A non-const call should not have slipped through the net. If
2764 it does, we need to create a new basic block. Ouch. The
2765 same applies for a label. */
2766 if ((GET_CODE (insn
) == CALL_INSN
2767 && ! CONST_OR_PURE_CALL_P (insn
))
2768 || GET_CODE (insn
) == CODE_LABEL
)
2771 uid
= INSN_UID (insn
);
2773 if (uid
>= df
->insn_size
)
2774 df_insn_table_realloc (df
, uid
);
2776 df_insn_modify (df
, bb
, insn
);
2778 if (insn
== last_insn
)
2784 /* Emit PATTERN before INSN within BB. */
2786 df_pattern_emit_before (df
, pattern
, bb
, insn
)
2787 struct df
*df ATTRIBUTE_UNUSED
;
2793 rtx prev_insn
= PREV_INSN (insn
);
2795 /* We should not be inserting before the start of the block. */
2796 if (insn
== bb
->head
)
2798 ret_insn
= emit_insn_before (pattern
, insn
);
2799 if (ret_insn
== insn
)
2802 df_insns_modify (df
, bb
, NEXT_INSN (prev_insn
), ret_insn
);
2807 /* Emit PATTERN after INSN within BB. */
2809 df_pattern_emit_after (df
, pattern
, bb
, insn
)
2817 ret_insn
= emit_insn_after (pattern
, insn
);
2818 if (ret_insn
== insn
)
2821 df_insns_modify (df
, bb
, NEXT_INSN (insn
), ret_insn
);
2826 /* Emit jump PATTERN after INSN within BB. */
2828 df_jump_pattern_emit_after (df
, pattern
, bb
, insn
)
2836 ret_insn
= emit_jump_insn_after (pattern
, insn
);
2837 if (ret_insn
== insn
)
2840 df_insns_modify (df
, bb
, NEXT_INSN (insn
), ret_insn
);
2845 /* Move INSN within BB before BEFORE_INSN within BEFORE_BB.
2847 This function should only be used to move loop invariant insns
2848 out of a loop where it has been proven that the def-use info
2849 will still be valid. */
2851 df_insn_move_before (df
, bb
, insn
, before_bb
, before_insn
)
2855 basic_block before_bb
;
2858 struct df_link
*link
;
2862 return df_pattern_emit_before (df
, insn
, before_bb
, before_insn
);
2864 uid
= INSN_UID (insn
);
2866 /* Change bb for all df defined and used by this insn. */
2867 for (link
= df
->insns
[uid
].defs
; link
; link
= link
->next
)
2868 DF_REF_BB (link
->ref
) = before_bb
;
2869 for (link
= df
->insns
[uid
].uses
; link
; link
= link
->next
)
2870 DF_REF_BB (link
->ref
) = before_bb
;
2872 /* The lifetimes of the registers used in this insn will be reduced
2873 while the lifetimes of the registers defined in this insn
2874 are likely to be increased. */
2876 /* ???? Perhaps all the insns moved should be stored on a list
2877 which df_analyse removes when it recalculates data flow. */
2879 return emit_insn_before (insn
, before_insn
);
2882 /* Functions to query dataflow information. */
2886 df_insn_regno_def_p (df
, bb
, insn
, regno
)
2888 basic_block bb ATTRIBUTE_UNUSED
;
2893 struct df_link
*link
;
2895 uid
= INSN_UID (insn
);
2897 for (link
= df
->insns
[uid
].defs
; link
; link
= link
->next
)
2899 struct ref
*def
= link
->ref
;
2901 if (DF_REF_REGNO (def
) == regno
)
2910 df_def_dominates_all_uses_p (df
, def
)
2911 struct df
*df ATTRIBUTE_UNUSED
;
2914 struct df_link
*du_link
;
2916 /* Follow def-use chain to find all the uses of this def. */
2917 for (du_link
= DF_REF_CHAIN (def
); du_link
; du_link
= du_link
->next
)
2919 struct ref
*use
= du_link
->ref
;
2920 struct df_link
*ud_link
;
2922 /* Follow use-def chain to check all the defs for this use. */
2923 for (ud_link
= DF_REF_CHAIN (use
); ud_link
; ud_link
= ud_link
->next
)
2924 if (ud_link
->ref
!= def
)
2932 df_insn_dominates_all_uses_p (df
, bb
, insn
)
2934 basic_block bb ATTRIBUTE_UNUSED
;
2938 struct df_link
*link
;
2940 uid
= INSN_UID (insn
);
2942 for (link
= df
->insns
[uid
].defs
; link
; link
= link
->next
)
2944 struct ref
*def
= link
->ref
;
2946 if (! df_def_dominates_all_uses_p (df
, def
))
2954 /* Return nonzero if all DF dominates all the uses within the bitmap
2957 df_def_dominates_uses_p (df
, def
, blocks
)
2958 struct df
*df ATTRIBUTE_UNUSED
;
2962 struct df_link
*du_link
;
2964 /* Follow def-use chain to find all the uses of this def. */
2965 for (du_link
= DF_REF_CHAIN (def
); du_link
; du_link
= du_link
->next
)
2967 struct ref
*use
= du_link
->ref
;
2968 struct df_link
*ud_link
;
2970 /* Only worry about the uses within BLOCKS. For example,
2971 consider a register defined within a loop that is live at the
2973 if (bitmap_bit_p (blocks
, DF_REF_BBNO (use
)))
2975 /* Follow use-def chain to check all the defs for this use. */
2976 for (ud_link
= DF_REF_CHAIN (use
); ud_link
; ud_link
= ud_link
->next
)
2977 if (ud_link
->ref
!= def
)
2985 /* Return nonzero if all the defs of INSN within BB dominates
2986 all the corresponding uses. */
2988 df_insn_dominates_uses_p (df
, bb
, insn
, blocks
)
2990 basic_block bb ATTRIBUTE_UNUSED
;
2995 struct df_link
*link
;
2997 uid
= INSN_UID (insn
);
2999 for (link
= df
->insns
[uid
].defs
; link
; link
= link
->next
)
3001 struct ref
*def
= link
->ref
;
3003 /* Only consider the defs within BLOCKS. */
3004 if (bitmap_bit_p (blocks
, DF_REF_BBNO (def
))
3005 && ! df_def_dominates_uses_p (df
, def
, blocks
))
3012 /* Return the basic block that REG referenced in or NULL if referenced
3013 in multiple basic blocks. */
3015 df_regno_bb (df
, regno
)
3019 struct df_link
*defs
= df
->regs
[regno
].defs
;
3020 struct df_link
*uses
= df
->regs
[regno
].uses
;
3021 struct ref
*def
= defs
? defs
->ref
: 0;
3022 struct ref
*use
= uses
? uses
->ref
: 0;
3023 basic_block bb_def
= def
? DF_REF_BB (def
) : 0;
3024 basic_block bb_use
= use
? DF_REF_BB (use
) : 0;
3026 /* Compare blocks of first def and last use. ???? FIXME. What if
3027 the reg-def and reg-use lists are not correctly ordered. */
3028 return bb_def
== bb_use
? bb_def
: 0;
3032 /* Return nonzero if REG used in multiple basic blocks. */
3034 df_reg_global_p (df
, reg
)
3038 return df_regno_bb (df
, REGNO (reg
)) != 0;
3042 /* Return total lifetime (in insns) of REG. */
3044 df_reg_lifetime (df
, reg
)
3048 return df
->regs
[REGNO (reg
)].lifetime
;
3052 /* Return nonzero if REG live at start of BB. */
3054 df_bb_reg_live_start_p (df
, bb
, reg
)
3055 struct df
*df ATTRIBUTE_UNUSED
;
3059 struct bb_info
*bb_info
= DF_BB_INFO (df
, bb
);
3061 #ifdef ENABLE_CHECKING
3062 if (! bb_info
->lr_in
)
3066 return bitmap_bit_p (bb_info
->lr_in
, REGNO (reg
));
3070 /* Return nonzero if REG live at end of BB. */
3072 df_bb_reg_live_end_p (df
, bb
, reg
)
3073 struct df
*df ATTRIBUTE_UNUSED
;
3077 struct bb_info
*bb_info
= DF_BB_INFO (df
, bb
);
3079 #ifdef ENABLE_CHECKING
3080 if (! bb_info
->lr_in
)
3084 return bitmap_bit_p (bb_info
->lr_out
, REGNO (reg
));
3088 /* Return -1 if life of REG1 before life of REG2, 1 if life of REG1
3089 after life of REG2, or 0, if the lives overlap. */
3091 df_bb_regs_lives_compare (df
, bb
, reg1
, reg2
)
3097 unsigned int regno1
= REGNO (reg1
);
3098 unsigned int regno2
= REGNO (reg2
);
3105 /* The regs must be local to BB. */
3106 if (df_regno_bb (df
, regno1
) != bb
3107 || df_regno_bb (df
, regno2
) != bb
)
3110 def2
= df_bb_regno_first_def_find (df
, bb
, regno2
);
3111 use1
= df_bb_regno_last_use_find (df
, bb
, regno1
);
3113 if (DF_INSN_LUID (df
, DF_REF_INSN (def2
))
3114 > DF_INSN_LUID (df
, DF_REF_INSN (use1
)))
3117 def1
= df_bb_regno_first_def_find (df
, bb
, regno1
);
3118 use2
= df_bb_regno_last_use_find (df
, bb
, regno2
);
3120 if (DF_INSN_LUID (df
, DF_REF_INSN (def1
))
3121 > DF_INSN_LUID (df
, DF_REF_INSN (use2
)))
3128 /* Return last use of REGNO within BB. */
3130 df_bb_regno_last_use_find (df
, bb
, regno
)
3132 basic_block bb ATTRIBUTE_UNUSED
;
3135 struct df_link
*link
;
3137 /* This assumes that the reg-use list is ordered such that for any
3138 BB, the last use is found first. However, since the BBs are not
3139 ordered, the first use in the chain is not necessarily the last
3140 use in the function. */
3141 for (link
= df
->regs
[regno
].uses
; link
; link
= link
->next
)
3143 struct ref
*use
= link
->ref
;
3145 if (DF_REF_BB (use
) == bb
)
3152 /* Return first def of REGNO within BB. */
3154 df_bb_regno_first_def_find (df
, bb
, regno
)
3156 basic_block bb ATTRIBUTE_UNUSED
;
3159 struct df_link
*link
;
3161 /* This assumes that the reg-def list is ordered such that for any
3162 BB, the first def is found first. However, since the BBs are not
3163 ordered, the first def in the chain is not necessarily the first
3164 def in the function. */
3165 for (link
= df
->regs
[regno
].defs
; link
; link
= link
->next
)
3167 struct ref
*def
= link
->ref
;
3169 if (DF_REF_BB (def
) == bb
)
3176 /* Return first use of REGNO inside INSN within BB. */
3178 df_bb_insn_regno_last_use_find (df
, bb
, insn
, regno
)
3180 basic_block bb ATTRIBUTE_UNUSED
;
3185 struct df_link
*link
;
3187 uid
= INSN_UID (insn
);
3189 for (link
= df
->insns
[uid
].uses
; link
; link
= link
->next
)
3191 struct ref
*use
= link
->ref
;
3193 if (DF_REF_REGNO (use
) == regno
)
3201 /* Return first def of REGNO inside INSN within BB. */
3203 df_bb_insn_regno_first_def_find (df
, bb
, insn
, regno
)
3205 basic_block bb ATTRIBUTE_UNUSED
;
3210 struct df_link
*link
;
3212 uid
= INSN_UID (insn
);
3214 for (link
= df
->insns
[uid
].defs
; link
; link
= link
->next
)
3216 struct ref
*def
= link
->ref
;
3218 if (DF_REF_REGNO (def
) == regno
)
3226 /* Return insn using REG if the BB contains only a single
3227 use and def of REG. */
3229 df_bb_single_def_use_insn_find (df
, bb
, insn
, reg
)
3237 struct df_link
*du_link
;
3239 def
= df_bb_insn_regno_first_def_find (df
, bb
, insn
, REGNO (reg
));
3244 du_link
= DF_REF_CHAIN (def
);
3251 /* Check if def is dead. */
3255 /* Check for multiple uses. */
3259 return DF_REF_INSN (use
);
3262 /* Functions for debugging/dumping dataflow information. */
3265 /* Dump a def-use or use-def chain for REF to FILE. */
3267 df_chain_dump (link
, file
)
3268 struct df_link
*link
;
3271 fprintf (file
, "{ ");
3272 for (; link
; link
= link
->next
)
3274 fprintf (file
, "%c%d ",
3275 DF_REF_REG_DEF_P (link
->ref
) ? 'd' : 'u',
3276 DF_REF_ID (link
->ref
));
3278 fprintf (file
, "}");
3282 df_chain_dump_regno (link
, file
)
3283 struct df_link
*link
;
3286 fprintf (file
, "{ ");
3287 for (; link
; link
= link
->next
)
3289 fprintf (file
, "%c%d(%d) ",
3290 DF_REF_REG_DEF_P (link
->ref
) ? 'd' : 'u',
3291 DF_REF_ID (link
->ref
),
3292 DF_REF_REGNO (link
->ref
));
3294 fprintf (file
, "}");
3297 /* Dump dataflow info. */
3299 df_dump (df
, flags
, file
)
3310 fprintf (file
, "\nDataflow summary:\n");
3311 fprintf (file
, "n_regs = %d, n_defs = %d, n_uses = %d, n_bbs = %d\n",
3312 df
->n_regs
, df
->n_defs
, df
->n_uses
, df
->n_bbs
);
3318 fprintf (file
, "Reaching defs:\n");
3321 struct bb_info
*bb_info
= DF_BB_INFO (df
, bb
);
3323 if (! bb_info
->rd_in
)
3326 fprintf (file
, "bb %d in \t", bb
->index
);
3327 dump_bitmap (file
, bb_info
->rd_in
);
3328 fprintf (file
, "bb %d gen \t", bb
->index
);
3329 dump_bitmap (file
, bb_info
->rd_gen
);
3330 fprintf (file
, "bb %d kill\t", bb
->index
);
3331 dump_bitmap (file
, bb_info
->rd_kill
);
3332 fprintf (file
, "bb %d out \t", bb
->index
);
3333 dump_bitmap (file
, bb_info
->rd_out
);
3337 if (flags
& DF_UD_CHAIN
)
3339 fprintf (file
, "Use-def chains:\n");
3340 for (j
= 0; j
< df
->n_defs
; j
++)
3344 fprintf (file
, "d%d bb %d luid %d insn %d reg %d ",
3345 j
, DF_REF_BBNO (df
->defs
[j
]),
3346 DF_INSN_LUID (df
, DF_REF_INSN (df
->defs
[j
])),
3347 DF_REF_INSN_UID (df
->defs
[j
]),
3348 DF_REF_REGNO (df
->defs
[j
]));
3349 if (df
->defs
[j
]->flags
& DF_REF_READ_WRITE
)
3350 fprintf (file
, "read/write ");
3351 df_chain_dump (DF_REF_CHAIN (df
->defs
[j
]), file
);
3352 fprintf (file
, "\n");
3359 fprintf (file
, "Reaching uses:\n");
3362 struct bb_info
*bb_info
= DF_BB_INFO (df
, bb
);
3364 if (! bb_info
->ru_in
)
3367 fprintf (file
, "bb %d in \t", bb
->index
);
3368 dump_bitmap (file
, bb_info
->ru_in
);
3369 fprintf (file
, "bb %d gen \t", bb
->index
);
3370 dump_bitmap (file
, bb_info
->ru_gen
);
3371 fprintf (file
, "bb %d kill\t", bb
->index
);
3372 dump_bitmap (file
, bb_info
->ru_kill
);
3373 fprintf (file
, "bb %d out \t", bb
->index
);
3374 dump_bitmap (file
, bb_info
->ru_out
);
3378 if (flags
& DF_DU_CHAIN
)
3380 fprintf (file
, "Def-use chains:\n");
3381 for (j
= 0; j
< df
->n_uses
; j
++)
3385 fprintf (file
, "u%d bb %d luid %d insn %d reg %d ",
3386 j
, DF_REF_BBNO (df
->uses
[j
]),
3387 DF_INSN_LUID (df
, DF_REF_INSN (df
->uses
[j
])),
3388 DF_REF_INSN_UID (df
->uses
[j
]),
3389 DF_REF_REGNO (df
->uses
[j
]));
3390 if (df
->uses
[j
]->flags
& DF_REF_READ_WRITE
)
3391 fprintf (file
, "read/write ");
3392 df_chain_dump (DF_REF_CHAIN (df
->uses
[j
]), file
);
3393 fprintf (file
, "\n");
3400 fprintf (file
, "Live regs:\n");
3403 struct bb_info
*bb_info
= DF_BB_INFO (df
, bb
);
3405 if (! bb_info
->lr_in
)
3408 fprintf (file
, "bb %d in \t", bb
->index
);
3409 dump_bitmap (file
, bb_info
->lr_in
);
3410 fprintf (file
, "bb %d use \t", bb
->index
);
3411 dump_bitmap (file
, bb_info
->lr_use
);
3412 fprintf (file
, "bb %d def \t", bb
->index
);
3413 dump_bitmap (file
, bb_info
->lr_def
);
3414 fprintf (file
, "bb %d out \t", bb
->index
);
3415 dump_bitmap (file
, bb_info
->lr_out
);
3419 if (flags
& (DF_REG_INFO
| DF_RD_CHAIN
| DF_RU_CHAIN
))
3421 struct reg_info
*reg_info
= df
->regs
;
3423 fprintf (file
, "Register info:\n");
3424 for (j
= 0; j
< df
->n_regs
; j
++)
3426 if (((flags
& DF_REG_INFO
)
3427 && (reg_info
[j
].n_uses
|| reg_info
[j
].n_defs
))
3428 || ((flags
& DF_RD_CHAIN
) && reg_info
[j
].defs
)
3429 || ((flags
& DF_RU_CHAIN
) && reg_info
[j
].uses
))
3431 fprintf (file
, "reg %d", j
);
3432 if ((flags
& DF_RD_CHAIN
) && (flags
& DF_RU_CHAIN
))
3434 basic_block bb
= df_regno_bb (df
, j
);
3437 fprintf (file
, " bb %d", bb
->index
);
3439 fprintf (file
, " bb ?");
3441 if (flags
& DF_REG_INFO
)
3443 fprintf (file
, " life %d", reg_info
[j
].lifetime
);
3446 if ((flags
& DF_REG_INFO
) || (flags
& DF_RD_CHAIN
))
3448 fprintf (file
, " defs ");
3449 if (flags
& DF_REG_INFO
)
3450 fprintf (file
, "%d ", reg_info
[j
].n_defs
);
3451 if (flags
& DF_RD_CHAIN
)
3452 df_chain_dump (reg_info
[j
].defs
, file
);
3455 if ((flags
& DF_REG_INFO
) || (flags
& DF_RU_CHAIN
))
3457 fprintf (file
, " uses ");
3458 if (flags
& DF_REG_INFO
)
3459 fprintf (file
, "%d ", reg_info
[j
].n_uses
);
3460 if (flags
& DF_RU_CHAIN
)
3461 df_chain_dump (reg_info
[j
].uses
, file
);
3464 fprintf (file
, "\n");
3468 fprintf (file
, "\n");
3473 df_insn_debug (df
, insn
, file
)
3481 uid
= INSN_UID (insn
);
3482 if (uid
>= df
->insn_size
)
3485 if (df
->insns
[uid
].defs
)
3486 bbi
= DF_REF_BBNO (df
->insns
[uid
].defs
->ref
);
3487 else if (df
->insns
[uid
].uses
)
3488 bbi
= DF_REF_BBNO (df
->insns
[uid
].uses
->ref
);
3492 fprintf (file
, "insn %d bb %d luid %d defs ",
3493 uid
, bbi
, DF_INSN_LUID (df
, insn
));
3494 df_chain_dump (df
->insns
[uid
].defs
, file
);
3495 fprintf (file
, " uses ");
3496 df_chain_dump (df
->insns
[uid
].uses
, file
);
3497 fprintf (file
, "\n");
3501 df_insn_debug_regno (df
, insn
, file
)
3509 uid
= INSN_UID (insn
);
3510 if (uid
>= df
->insn_size
)
3513 if (df
->insns
[uid
].defs
)
3514 bbi
= DF_REF_BBNO (df
->insns
[uid
].defs
->ref
);
3515 else if (df
->insns
[uid
].uses
)
3516 bbi
= DF_REF_BBNO (df
->insns
[uid
].uses
->ref
);
3520 fprintf (file
, "insn %d bb %d luid %d defs ",
3521 uid
, bbi
, DF_INSN_LUID (df
, insn
));
3522 df_chain_dump_regno (df
->insns
[uid
].defs
, file
);
3523 fprintf (file
, " uses ");
3524 df_chain_dump_regno (df
->insns
[uid
].uses
, file
);
3525 fprintf (file
, "\n");
3529 df_regno_debug (df
, regno
, file
)
3534 if (regno
>= df
->reg_size
)
3537 fprintf (file
, "reg %d life %d defs ",
3538 regno
, df
->regs
[regno
].lifetime
);
3539 df_chain_dump (df
->regs
[regno
].defs
, file
);
3540 fprintf (file
, " uses ");
3541 df_chain_dump (df
->regs
[regno
].uses
, file
);
3542 fprintf (file
, "\n");
3547 df_ref_debug (df
, ref
, file
)
3552 fprintf (file
, "%c%d ",
3553 DF_REF_REG_DEF_P (ref
) ? 'd' : 'u',
3555 fprintf (file
, "reg %d bb %d luid %d insn %d chain ",
3558 DF_INSN_LUID (df
, DF_REF_INSN (ref
)),
3559 INSN_UID (DF_REF_INSN (ref
)));
3560 df_chain_dump (DF_REF_CHAIN (ref
), file
);
3561 fprintf (file
, "\n");
3566 debug_df_insn (insn
)
3569 df_insn_debug (ddf
, insn
, stderr
);
3578 df_regno_debug (ddf
, REGNO (reg
), stderr
);
3583 debug_df_regno (regno
)
3586 df_regno_debug (ddf
, regno
, stderr
);
3594 df_ref_debug (ddf
, ref
, stderr
);
3599 debug_df_defno (defno
)
3602 df_ref_debug (ddf
, ddf
->defs
[defno
], stderr
);
3607 debug_df_useno (defno
)
3610 df_ref_debug (ddf
, ddf
->uses
[defno
], stderr
);
3615 debug_df_chain (link
)
3616 struct df_link
*link
;
3618 df_chain_dump (link
, stderr
);
3619 fputc ('\n', stderr
);
3622 /* Hybrid search algorithm from "Implementation Techniques for
3623 Efficient Data-Flow Analysis of Large Programs". */
3625 hybrid_search_bitmap (block
, in
, out
, gen
, kill
, dir
,
3626 conf_op
, transfun
, visited
, pending
,
3629 bitmap
*in
, *out
, *gen
, *kill
;
3630 enum df_flow_dir dir
;
3631 enum df_confluence_op conf_op
;
3632 transfer_function_bitmap transfun
;
3638 int i
= block
->index
;
3640 basic_block bb
= block
;
3641 SET_BIT (visited
, block
->index
);
3642 if (TEST_BIT (pending
, block
->index
))
3646 /* Calculate <conf_op> of predecessor_outs */
3647 bitmap_zero (in
[i
]);
3648 for (e
= bb
->pred
; e
!= 0; e
= e
->pred_next
)
3650 if (e
->src
== ENTRY_BLOCK_PTR
)
3655 bitmap_a_or_b (in
[i
], in
[i
], out
[e
->src
->index
]);
3658 bitmap_a_and_b (in
[i
], in
[i
], out
[e
->src
->index
]);
3665 /* Calculate <conf_op> of successor ins */
3666 bitmap_zero(out
[i
]);
3667 for (e
= bb
->succ
; e
!= 0; e
= e
->succ_next
)
3669 if (e
->dest
== EXIT_BLOCK_PTR
)
3674 bitmap_a_or_b (out
[i
], out
[i
], in
[e
->dest
->index
]);
3677 bitmap_a_and_b (out
[i
], out
[i
], in
[e
->dest
->index
]);
3683 (*transfun
)(i
, &changed
, in
[i
], out
[i
], gen
[i
], kill
[i
], data
);
3684 RESET_BIT (pending
, i
);
3689 for (e
= bb
->succ
; e
!= 0; e
= e
->succ_next
)
3691 if (e
->dest
== EXIT_BLOCK_PTR
|| e
->dest
->index
== i
)
3693 SET_BIT (pending
, e
->dest
->index
);
3698 for (e
= bb
->pred
; e
!= 0; e
= e
->pred_next
)
3700 if (e
->src
== ENTRY_BLOCK_PTR
|| e
->dest
->index
== i
)
3702 SET_BIT (pending
, e
->src
->index
);
3709 for (e
= bb
->succ
; e
!= 0; e
= e
->succ_next
)
3711 if (e
->dest
== EXIT_BLOCK_PTR
|| e
->dest
->index
== i
)
3713 if (!TEST_BIT (visited
, e
->dest
->index
))
3714 hybrid_search_bitmap (e
->dest
, in
, out
, gen
, kill
, dir
,
3715 conf_op
, transfun
, visited
, pending
,
3721 for (e
= bb
->pred
; e
!= 0; e
= e
->pred_next
)
3723 if (e
->src
== ENTRY_BLOCK_PTR
|| e
->src
->index
== i
)
3725 if (!TEST_BIT (visited
, e
->src
->index
))
3726 hybrid_search_bitmap (e
->src
, in
, out
, gen
, kill
, dir
,
3727 conf_op
, transfun
, visited
, pending
,
3734 /* Hybrid search for sbitmaps, rather than bitmaps. */
3736 hybrid_search_sbitmap (block
, in
, out
, gen
, kill
, dir
,
3737 conf_op
, transfun
, visited
, pending
,
3740 sbitmap
*in
, *out
, *gen
, *kill
;
3741 enum df_flow_dir dir
;
3742 enum df_confluence_op conf_op
;
3743 transfer_function_sbitmap transfun
;
3749 int i
= block
->index
;
3751 basic_block bb
= block
;
3752 SET_BIT (visited
, block
->index
);
3753 if (TEST_BIT (pending
, block
->index
))
3757 /* Calculate <conf_op> of predecessor_outs */
3758 sbitmap_zero (in
[i
]);
3759 for (e
= bb
->pred
; e
!= 0; e
= e
->pred_next
)
3761 if (e
->src
== ENTRY_BLOCK_PTR
)
3766 sbitmap_a_or_b (in
[i
], in
[i
], out
[e
->src
->index
]);
3769 sbitmap_a_and_b (in
[i
], in
[i
], out
[e
->src
->index
]);
3776 /* Calculate <conf_op> of successor ins */
3777 sbitmap_zero(out
[i
]);
3778 for (e
= bb
->succ
; e
!= 0; e
= e
->succ_next
)
3780 if (e
->dest
== EXIT_BLOCK_PTR
)
3785 sbitmap_a_or_b (out
[i
], out
[i
], in
[e
->dest
->index
]);
3788 sbitmap_a_and_b (out
[i
], out
[i
], in
[e
->dest
->index
]);
3794 (*transfun
)(i
, &changed
, in
[i
], out
[i
], gen
[i
], kill
[i
], data
);
3795 RESET_BIT (pending
, i
);
3800 for (e
= bb
->succ
; e
!= 0; e
= e
->succ_next
)
3802 if (e
->dest
== EXIT_BLOCK_PTR
|| e
->dest
->index
== i
)
3804 SET_BIT (pending
, e
->dest
->index
);
3809 for (e
= bb
->pred
; e
!= 0; e
= e
->pred_next
)
3811 if (e
->src
== ENTRY_BLOCK_PTR
|| e
->dest
->index
== i
)
3813 SET_BIT (pending
, e
->src
->index
);
3820 for (e
= bb
->succ
; e
!= 0; e
= e
->succ_next
)
3822 if (e
->dest
== EXIT_BLOCK_PTR
|| e
->dest
->index
== i
)
3824 if (!TEST_BIT (visited
, e
->dest
->index
))
3825 hybrid_search_sbitmap (e
->dest
, in
, out
, gen
, kill
, dir
,
3826 conf_op
, transfun
, visited
, pending
,
3832 for (e
= bb
->pred
; e
!= 0; e
= e
->pred_next
)
3834 if (e
->src
== ENTRY_BLOCK_PTR
|| e
->src
->index
== i
)
3836 if (!TEST_BIT (visited
, e
->src
->index
))
3837 hybrid_search_sbitmap (e
->src
, in
, out
, gen
, kill
, dir
,
3838 conf_op
, transfun
, visited
, pending
,
3849 in, out = Filled in by function.
3850 blocks = Blocks to analyze.
3851 dir = Dataflow direction.
3852 conf_op = Confluence operation.
3853 transfun = Transfer function.
3854 order = Order to iterate in. (Should map block numbers -> order)
3855 data = Whatever you want. It's passed to the transfer function.
3857 This function will perform iterative bitvector dataflow, producing
3858 the in and out sets. Even if you only want to perform it for a
3859 small number of blocks, the vectors for in and out must be large
3860 enough for *all* blocks, because changing one block might affect
3861 others. However, it'll only put what you say to analyze on the
3864 For forward problems, you probably want to pass in a mapping of
3865 block number to rc_order (like df->inverse_rc_map).
3868 iterative_dataflow_sbitmap (in
, out
, gen
, kill
, blocks
,
3869 dir
, conf_op
, transfun
, order
, data
)
3870 sbitmap
*in
, *out
, *gen
, *kill
;
3872 enum df_flow_dir dir
;
3873 enum df_confluence_op conf_op
;
3874 transfer_function_sbitmap transfun
;
3881 sbitmap visited
, pending
;
3882 pending
= sbitmap_alloc (last_basic_block
);
3883 visited
= sbitmap_alloc (last_basic_block
);
3884 sbitmap_zero (pending
);
3885 sbitmap_zero (visited
);
3886 worklist
= fibheap_new ();
3887 EXECUTE_IF_SET_IN_BITMAP (blocks
, 0, i
,
3889 fibheap_insert (worklist
, order
[i
], (void *) (size_t) i
);
3890 SET_BIT (pending
, i
);
3892 sbitmap_copy (out
[i
], gen
[i
]);
3894 sbitmap_copy (in
[i
], gen
[i
]);
3896 while (sbitmap_first_set_bit (pending
) != -1)
3898 while (!fibheap_empty (worklist
))
3900 i
= (size_t) fibheap_extract_min (worklist
);
3901 bb
= BASIC_BLOCK (i
);
3902 if (!TEST_BIT (visited
, bb
->index
))
3903 hybrid_search_sbitmap (bb
, in
, out
, gen
, kill
, dir
,
3904 conf_op
, transfun
, visited
, pending
, data
);
3906 if (sbitmap_first_set_bit (pending
) != -1)
3908 EXECUTE_IF_SET_IN_BITMAP (blocks
, 0, i
,
3910 fibheap_insert (worklist
, order
[i
], (void *) (size_t) i
);
3912 sbitmap_zero (visited
);
3919 sbitmap_free (pending
);
3920 sbitmap_free (visited
);
3921 fibheap_delete (worklist
);
3924 /* Exactly the same as iterative_dataflow_sbitmap, except it works on
3927 iterative_dataflow_bitmap (in
, out
, gen
, kill
, blocks
,
3928 dir
, conf_op
, transfun
, order
, data
)
3929 bitmap
*in
, *out
, *gen
, *kill
;
3931 enum df_flow_dir dir
;
3932 enum df_confluence_op conf_op
;
3933 transfer_function_bitmap transfun
;
3940 sbitmap visited
, pending
;
3941 pending
= sbitmap_alloc (last_basic_block
);
3942 visited
= sbitmap_alloc (last_basic_block
);
3943 sbitmap_zero (pending
);
3944 sbitmap_zero (visited
);
3945 worklist
= fibheap_new ();
3946 EXECUTE_IF_SET_IN_BITMAP (blocks
, 0, i
,
3948 fibheap_insert (worklist
, order
[i
], (void *) (size_t) i
);
3949 SET_BIT (pending
, i
);
3951 bitmap_copy (out
[i
], gen
[i
]);
3953 bitmap_copy (in
[i
], gen
[i
]);
3955 while (sbitmap_first_set_bit (pending
) != -1)
3957 while (!fibheap_empty (worklist
))
3959 i
= (size_t) fibheap_extract_min (worklist
);
3960 bb
= BASIC_BLOCK (i
);
3961 if (!TEST_BIT (visited
, bb
->index
))
3962 hybrid_search_bitmap (bb
, in
, out
, gen
, kill
, dir
,
3963 conf_op
, transfun
, visited
, pending
, data
);
3965 if (sbitmap_first_set_bit (pending
) != -1)
3967 EXECUTE_IF_SET_IN_BITMAP (blocks
, 0, i
,
3969 fibheap_insert (worklist
, order
[i
], (void *) (size_t) i
);
3971 sbitmap_zero (visited
);
3978 sbitmap_free (pending
);
3979 sbitmap_free (visited
);
3980 fibheap_delete (worklist
);