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 analyzed, 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 analyzed? */
158 #include "coretypes.h"
162 #include "insn-config.h"
164 #include "function.h"
167 #include "hard-reg-set.h"
168 #include "basic-block.h"
174 #define FOR_EACH_BB_IN_BITMAP(BITMAP, MIN, BB, CODE) \
177 unsigned int node_; \
178 EXECUTE_IF_SET_IN_BITMAP (BITMAP, MIN, node_, \
179 {(BB) = BASIC_BLOCK (node_); CODE;}); \
183 static struct obstack df_ref_obstack
;
184 static struct df
*ddf
;
186 static void df_reg_table_realloc
PARAMS((struct df
*, int));
188 static void df_def_table_realloc
PARAMS((struct df
*, int));
190 static void df_insn_table_realloc
PARAMS((struct df
*, unsigned int));
191 static void df_bitmaps_alloc
PARAMS((struct df
*, int));
192 static void df_bitmaps_free
PARAMS((struct df
*, int));
193 static void df_free
PARAMS((struct df
*));
194 static void df_alloc
PARAMS((struct df
*, int));
196 static rtx df_reg_clobber_gen
PARAMS((unsigned int));
197 static rtx df_reg_use_gen
PARAMS((unsigned int));
199 static inline struct df_link
*df_link_create
PARAMS((struct ref
*,
201 static struct df_link
*df_ref_unlink
PARAMS((struct df_link
**, struct ref
*));
202 static void df_def_unlink
PARAMS((struct df
*, struct ref
*));
203 static void df_use_unlink
PARAMS((struct df
*, struct ref
*));
204 static void df_insn_refs_unlink
PARAMS ((struct df
*, basic_block
, rtx
));
206 static void df_bb_refs_unlink
PARAMS ((struct df
*, basic_block
));
207 static void df_refs_unlink
PARAMS ((struct df
*, bitmap
));
210 static struct ref
*df_ref_create
PARAMS((struct df
*,
212 enum df_ref_type
, enum df_ref_flags
));
213 static void df_ref_record_1
PARAMS((struct df
*, rtx
, rtx
*,
214 rtx
, enum df_ref_type
,
216 static void df_ref_record
PARAMS((struct df
*, rtx
, rtx
*,
217 rtx
, enum df_ref_type
,
219 static void df_def_record_1
PARAMS((struct df
*, rtx
, basic_block
, rtx
));
220 static void df_defs_record
PARAMS((struct df
*, rtx
, basic_block
, rtx
));
221 static void df_uses_record
PARAMS((struct df
*, rtx
*,
222 enum df_ref_type
, basic_block
, rtx
,
224 static void df_insn_refs_record
PARAMS((struct df
*, basic_block
, rtx
));
225 static void df_bb_refs_record
PARAMS((struct df
*, basic_block
));
226 static void df_refs_record
PARAMS((struct df
*, bitmap
));
228 static void df_bb_reg_def_chain_create
PARAMS((struct df
*, basic_block
));
229 static void df_reg_def_chain_create
PARAMS((struct df
*, bitmap
));
230 static void df_bb_reg_use_chain_create
PARAMS((struct df
*, basic_block
));
231 static void df_reg_use_chain_create
PARAMS((struct df
*, bitmap
));
232 static void df_bb_du_chain_create
PARAMS((struct df
*, basic_block
, bitmap
));
233 static void df_du_chain_create
PARAMS((struct df
*, bitmap
));
234 static void df_bb_ud_chain_create
PARAMS((struct df
*, basic_block
));
235 static void df_ud_chain_create
PARAMS((struct df
*, bitmap
));
236 static void df_bb_rd_local_compute
PARAMS((struct df
*, basic_block
));
237 static void df_rd_local_compute
PARAMS((struct df
*, bitmap
));
238 static void df_bb_ru_local_compute
PARAMS((struct df
*, basic_block
));
239 static void df_ru_local_compute
PARAMS((struct df
*, bitmap
));
240 static void df_bb_lr_local_compute
PARAMS((struct df
*, basic_block
));
241 static void df_lr_local_compute
PARAMS((struct df
*, bitmap
));
242 static void df_bb_reg_info_compute
PARAMS((struct df
*, basic_block
, bitmap
));
243 static void df_reg_info_compute
PARAMS((struct df
*, bitmap
));
245 static int df_bb_luids_set
PARAMS((struct df
*df
, basic_block
));
246 static int df_luids_set
PARAMS((struct df
*df
, bitmap
));
248 static int df_modified_p
PARAMS ((struct df
*, bitmap
));
249 static int df_refs_queue
PARAMS ((struct df
*));
250 static int df_refs_process
PARAMS ((struct df
*));
251 static int df_bb_refs_update
PARAMS ((struct df
*, basic_block
));
252 static int df_refs_update
PARAMS ((struct df
*));
253 static void df_analyse_1
PARAMS((struct df
*, bitmap
, int, int));
255 static void df_insns_modify
PARAMS((struct df
*, basic_block
,
257 static int df_rtx_mem_replace
PARAMS ((rtx
*, void *));
258 static int df_rtx_reg_replace
PARAMS ((rtx
*, void *));
259 void df_refs_reg_replace
PARAMS ((struct df
*, bitmap
,
260 struct df_link
*, rtx
, rtx
));
262 static int df_def_dominates_all_uses_p
PARAMS((struct df
*, struct ref
*def
));
263 static int df_def_dominates_uses_p
PARAMS((struct df
*,
264 struct ref
*def
, bitmap
));
265 static struct ref
*df_bb_regno_last_use_find
PARAMS((struct df
*, basic_block
,
267 static struct ref
*df_bb_regno_first_def_find
PARAMS((struct df
*, basic_block
,
269 static struct ref
*df_bb_insn_regno_last_use_find
PARAMS((struct df
*,
272 static struct ref
*df_bb_insn_regno_first_def_find
PARAMS((struct df
*,
276 static void df_chain_dump
PARAMS((struct df_link
*, FILE *file
));
277 static void df_chain_dump_regno
PARAMS((struct df_link
*, FILE *file
));
278 static void df_regno_debug
PARAMS ((struct df
*, unsigned int, FILE *));
279 static void df_ref_debug
PARAMS ((struct df
*, struct ref
*, FILE *));
280 static void df_rd_transfer_function
PARAMS ((int, int *, bitmap
, bitmap
,
281 bitmap
, bitmap
, void *));
282 static void df_ru_transfer_function
PARAMS ((int, int *, bitmap
, bitmap
,
283 bitmap
, bitmap
, void *));
284 static void df_lr_transfer_function
PARAMS ((int, int *, bitmap
, bitmap
,
285 bitmap
, bitmap
, void *));
286 static void hybrid_search_bitmap
PARAMS ((basic_block
, bitmap
*, bitmap
*,
287 bitmap
*, bitmap
*, enum df_flow_dir
,
288 enum df_confluence_op
,
289 transfer_function_bitmap
,
290 sbitmap
, sbitmap
, void *));
291 static void hybrid_search_sbitmap
PARAMS ((basic_block
, sbitmap
*, sbitmap
*,
292 sbitmap
*, sbitmap
*, enum df_flow_dir
,
293 enum df_confluence_op
,
294 transfer_function_sbitmap
,
295 sbitmap
, sbitmap
, void *));
296 static inline bool read_modify_subreg_p
PARAMS ((rtx
));
299 /* Local memory allocation/deallocation routines. */
302 /* Increase the insn info table to have space for at least SIZE + 1
305 df_insn_table_realloc (df
, size
)
310 if (size
<= df
->insn_size
)
313 /* Make the table a little larger than requested, so we don't need
314 to enlarge it so often. */
315 size
+= df
->insn_size
/ 4;
317 df
->insns
= (struct insn_info
*)
318 xrealloc (df
->insns
, size
* sizeof (struct insn_info
));
320 memset (df
->insns
+ df
->insn_size
, 0,
321 (size
- df
->insn_size
) * sizeof (struct insn_info
));
323 df
->insn_size
= size
;
325 if (! df
->insns_modified
)
327 df
->insns_modified
= BITMAP_XMALLOC ();
328 bitmap_zero (df
->insns_modified
);
333 /* Increase the reg info table by SIZE more elements. */
335 df_reg_table_realloc (df
, size
)
339 /* Make table 25 percent larger by default. */
341 size
= df
->reg_size
/ 4;
343 size
+= df
->reg_size
;
344 if (size
< max_reg_num ())
345 size
= max_reg_num ();
347 df
->regs
= (struct reg_info
*)
348 xrealloc (df
->regs
, size
* sizeof (struct reg_info
));
350 /* Zero the new entries. */
351 memset (df
->regs
+ df
->reg_size
, 0,
352 (size
- df
->reg_size
) * sizeof (struct reg_info
));
359 /* Not currently used. */
361 df_def_table_realloc (df
, size
)
368 /* Make table 25 percent larger by default. */
370 size
= df
->def_size
/ 4;
372 df
->def_size
+= size
;
373 df
->defs
= xrealloc (df
->defs
,
374 df
->def_size
* sizeof (*df
->defs
));
376 /* Allocate a new block of memory and link into list of blocks
377 that will need to be freed later. */
379 refs
= xmalloc (size
* sizeof (*refs
));
381 /* Link all the new refs together, overloading the chain field. */
382 for (i
= 0; i
< size
- 1; i
++)
383 refs
[i
].chain
= (struct df_link
*) (refs
+ i
+ 1);
384 refs
[size
- 1].chain
= 0;
390 /* Allocate bitmaps for each basic block. */
392 df_bitmaps_alloc (df
, flags
)
399 /* Free the bitmaps if they need resizing. */
400 if ((flags
& DF_LR
) && df
->n_regs
< (unsigned int) max_reg_num ())
401 dflags
|= DF_LR
| DF_RU
;
402 if ((flags
& DF_RU
) && df
->n_uses
< df
->use_id
)
404 if ((flags
& DF_RD
) && df
->n_defs
< df
->def_id
)
408 df_bitmaps_free (df
, dflags
);
410 df
->n_defs
= df
->def_id
;
411 df
->n_uses
= df
->use_id
;
415 struct bb_info
*bb_info
= DF_BB_INFO (df
, bb
);
417 if (flags
& DF_RD
&& ! bb_info
->rd_in
)
419 /* Allocate bitmaps for reaching definitions. */
420 bb_info
->rd_kill
= BITMAP_XMALLOC ();
421 bitmap_zero (bb_info
->rd_kill
);
422 bb_info
->rd_gen
= BITMAP_XMALLOC ();
423 bitmap_zero (bb_info
->rd_gen
);
424 bb_info
->rd_in
= BITMAP_XMALLOC ();
425 bb_info
->rd_out
= BITMAP_XMALLOC ();
426 bb_info
->rd_valid
= 0;
429 if (flags
& DF_RU
&& ! bb_info
->ru_in
)
431 /* Allocate bitmaps for upward exposed uses. */
432 bb_info
->ru_kill
= BITMAP_XMALLOC ();
433 bitmap_zero (bb_info
->ru_kill
);
434 /* Note the lack of symmetry. */
435 bb_info
->ru_gen
= BITMAP_XMALLOC ();
436 bitmap_zero (bb_info
->ru_gen
);
437 bb_info
->ru_in
= BITMAP_XMALLOC ();
438 bb_info
->ru_out
= BITMAP_XMALLOC ();
439 bb_info
->ru_valid
= 0;
442 if (flags
& DF_LR
&& ! bb_info
->lr_in
)
444 /* Allocate bitmaps for live variables. */
445 bb_info
->lr_def
= BITMAP_XMALLOC ();
446 bitmap_zero (bb_info
->lr_def
);
447 bb_info
->lr_use
= BITMAP_XMALLOC ();
448 bitmap_zero (bb_info
->lr_use
);
449 bb_info
->lr_in
= BITMAP_XMALLOC ();
450 bb_info
->lr_out
= BITMAP_XMALLOC ();
451 bb_info
->lr_valid
= 0;
457 /* Free bitmaps for each basic block. */
459 df_bitmaps_free (df
, flags
)
460 struct df
*df ATTRIBUTE_UNUSED
;
467 struct bb_info
*bb_info
= DF_BB_INFO (df
, bb
);
472 if ((flags
& DF_RD
) && bb_info
->rd_in
)
474 /* Free bitmaps for reaching definitions. */
475 BITMAP_XFREE (bb_info
->rd_kill
);
476 bb_info
->rd_kill
= NULL
;
477 BITMAP_XFREE (bb_info
->rd_gen
);
478 bb_info
->rd_gen
= NULL
;
479 BITMAP_XFREE (bb_info
->rd_in
);
480 bb_info
->rd_in
= NULL
;
481 BITMAP_XFREE (bb_info
->rd_out
);
482 bb_info
->rd_out
= NULL
;
485 if ((flags
& DF_RU
) && bb_info
->ru_in
)
487 /* Free bitmaps for upward exposed uses. */
488 BITMAP_XFREE (bb_info
->ru_kill
);
489 bb_info
->ru_kill
= NULL
;
490 BITMAP_XFREE (bb_info
->ru_gen
);
491 bb_info
->ru_gen
= NULL
;
492 BITMAP_XFREE (bb_info
->ru_in
);
493 bb_info
->ru_in
= NULL
;
494 BITMAP_XFREE (bb_info
->ru_out
);
495 bb_info
->ru_out
= NULL
;
498 if ((flags
& DF_LR
) && bb_info
->lr_in
)
500 /* Free bitmaps for live variables. */
501 BITMAP_XFREE (bb_info
->lr_def
);
502 bb_info
->lr_def
= NULL
;
503 BITMAP_XFREE (bb_info
->lr_use
);
504 bb_info
->lr_use
= NULL
;
505 BITMAP_XFREE (bb_info
->lr_in
);
506 bb_info
->lr_in
= NULL
;
507 BITMAP_XFREE (bb_info
->lr_out
);
508 bb_info
->lr_out
= NULL
;
511 df
->flags
&= ~(flags
& (DF_RD
| DF_RU
| DF_LR
));
515 /* Allocate and initialize dataflow memory. */
517 df_alloc (df
, n_regs
)
524 gcc_obstack_init (&df_ref_obstack
);
526 /* Perhaps we should use LUIDs to save memory for the insn_refs
527 table. This is only a small saving; a few pointers. */
528 n_insns
= get_max_uid () + 1;
532 /* Approximate number of defs by number of insns. */
533 df
->def_size
= n_insns
;
534 df
->defs
= xmalloc (df
->def_size
* sizeof (*df
->defs
));
538 /* Approximate number of uses by twice number of insns. */
539 df
->use_size
= n_insns
* 2;
540 df
->uses
= xmalloc (df
->use_size
* sizeof (*df
->uses
));
543 df
->n_bbs
= last_basic_block
;
545 /* Allocate temporary working array used during local dataflow analysis. */
546 df
->reg_def_last
= xmalloc (df
->n_regs
* sizeof (struct ref
*));
548 df_insn_table_realloc (df
, n_insns
);
550 df_reg_table_realloc (df
, df
->n_regs
);
552 df
->bbs_modified
= BITMAP_XMALLOC ();
553 bitmap_zero (df
->bbs_modified
);
557 df
->bbs
= xcalloc (last_basic_block
, sizeof (struct bb_info
));
559 df
->all_blocks
= BITMAP_XMALLOC ();
561 bitmap_set_bit (df
->all_blocks
, bb
->index
);
565 /* Free all the dataflow info. */
570 df_bitmaps_free (df
, DF_ALL
);
598 if (df
->bbs_modified
)
599 BITMAP_XFREE (df
->bbs_modified
);
600 df
->bbs_modified
= 0;
602 if (df
->insns_modified
)
603 BITMAP_XFREE (df
->insns_modified
);
604 df
->insns_modified
= 0;
606 BITMAP_XFREE (df
->all_blocks
);
609 obstack_free (&df_ref_obstack
, NULL
);
612 /* Local miscellaneous routines. */
614 /* Return a USE for register REGNO. */
615 static rtx
df_reg_use_gen (regno
)
621 reg
= regno_reg_rtx
[regno
];
623 use
= gen_rtx_USE (GET_MODE (reg
), reg
);
628 /* Return a CLOBBER for register REGNO. */
629 static rtx
df_reg_clobber_gen (regno
)
635 reg
= regno_reg_rtx
[regno
];
637 use
= gen_rtx_CLOBBER (GET_MODE (reg
), reg
);
641 /* Local chain manipulation routines. */
643 /* Create a link in a def-use or use-def chain. */
644 static inline struct df_link
*
645 df_link_create (ref
, next
)
647 struct df_link
*next
;
649 struct df_link
*link
;
651 link
= (struct df_link
*) obstack_alloc (&df_ref_obstack
,
659 /* Add REF to chain head pointed to by PHEAD. */
660 static struct df_link
*
661 df_ref_unlink (phead
, ref
)
662 struct df_link
**phead
;
665 struct df_link
*link
= *phead
;
671 /* Only a single ref. It must be the one we want.
672 If not, the def-use and use-def chains are likely to
674 if (link
->ref
!= ref
)
676 /* Now have an empty chain. */
681 /* Multiple refs. One of them must be us. */
682 if (link
->ref
== ref
)
687 for (; link
->next
; link
= link
->next
)
689 if (link
->next
->ref
== ref
)
691 /* Unlink from list. */
692 link
->next
= link
->next
->next
;
703 /* Unlink REF from all def-use/use-def chains, etc. */
705 df_ref_remove (df
, ref
)
709 if (DF_REF_REG_DEF_P (ref
))
711 df_def_unlink (df
, ref
);
712 df_ref_unlink (&df
->insns
[DF_REF_INSN_UID (ref
)].defs
, ref
);
716 df_use_unlink (df
, ref
);
717 df_ref_unlink (&df
->insns
[DF_REF_INSN_UID (ref
)].uses
, ref
);
723 /* Unlink DEF from use-def and reg-def chains. */
725 df_def_unlink (df
, def
)
726 struct df
*df ATTRIBUTE_UNUSED
;
729 struct df_link
*du_link
;
730 unsigned int dregno
= DF_REF_REGNO (def
);
732 /* Follow def-use chain to find all the uses of this def. */
733 for (du_link
= DF_REF_CHAIN (def
); du_link
; du_link
= du_link
->next
)
735 struct ref
*use
= du_link
->ref
;
737 /* Unlink this def from the use-def chain. */
738 df_ref_unlink (&DF_REF_CHAIN (use
), def
);
740 DF_REF_CHAIN (def
) = 0;
742 /* Unlink def from reg-def chain. */
743 df_ref_unlink (&df
->regs
[dregno
].defs
, def
);
745 df
->defs
[DF_REF_ID (def
)] = 0;
749 /* Unlink use from def-use and reg-use chains. */
751 df_use_unlink (df
, use
)
752 struct df
*df ATTRIBUTE_UNUSED
;
755 struct df_link
*ud_link
;
756 unsigned int uregno
= DF_REF_REGNO (use
);
758 /* Follow use-def chain to find all the defs of this use. */
759 for (ud_link
= DF_REF_CHAIN (use
); ud_link
; ud_link
= ud_link
->next
)
761 struct ref
*def
= ud_link
->ref
;
763 /* Unlink this use from the def-use chain. */
764 df_ref_unlink (&DF_REF_CHAIN (def
), use
);
766 DF_REF_CHAIN (use
) = 0;
768 /* Unlink use from reg-use chain. */
769 df_ref_unlink (&df
->regs
[uregno
].uses
, use
);
771 df
->uses
[DF_REF_ID (use
)] = 0;
774 /* Local routines for recording refs. */
777 /* Create a new ref of type DF_REF_TYPE for register REG at address
778 LOC within INSN of BB. */
780 df_ref_create (df
, reg
, loc
, insn
, ref_type
, ref_flags
)
785 enum df_ref_type ref_type
;
786 enum df_ref_flags ref_flags
;
788 struct ref
*this_ref
;
790 this_ref
= (struct ref
*) obstack_alloc (&df_ref_obstack
,
792 DF_REF_REG (this_ref
) = reg
;
793 DF_REF_LOC (this_ref
) = loc
;
794 DF_REF_INSN (this_ref
) = insn
;
795 DF_REF_CHAIN (this_ref
) = 0;
796 DF_REF_TYPE (this_ref
) = ref_type
;
797 DF_REF_FLAGS (this_ref
) = ref_flags
;
799 if (ref_type
== DF_REF_REG_DEF
)
801 if (df
->def_id
>= df
->def_size
)
803 /* Make table 25 percent larger. */
804 df
->def_size
+= (df
->def_size
/ 4);
805 df
->defs
= xrealloc (df
->defs
,
806 df
->def_size
* sizeof (*df
->defs
));
808 DF_REF_ID (this_ref
) = df
->def_id
;
809 df
->defs
[df
->def_id
++] = this_ref
;
813 if (df
->use_id
>= df
->use_size
)
815 /* Make table 25 percent larger. */
816 df
->use_size
+= (df
->use_size
/ 4);
817 df
->uses
= xrealloc (df
->uses
,
818 df
->use_size
* sizeof (*df
->uses
));
820 DF_REF_ID (this_ref
) = df
->use_id
;
821 df
->uses
[df
->use_id
++] = this_ref
;
827 /* Create a new reference of type DF_REF_TYPE for a single register REG,
828 used inside the LOC rtx of INSN. */
830 df_ref_record_1 (df
, reg
, loc
, insn
, ref_type
, ref_flags
)
835 enum df_ref_type ref_type
;
836 enum df_ref_flags ref_flags
;
838 df_ref_create (df
, reg
, loc
, insn
, ref_type
, ref_flags
);
842 /* Create new references of type DF_REF_TYPE for each part of register REG
843 at address LOC within INSN of BB. */
845 df_ref_record (df
, reg
, loc
, insn
, ref_type
, ref_flags
)
850 enum df_ref_type ref_type
;
851 enum df_ref_flags ref_flags
;
855 if (GET_CODE (reg
) != REG
&& GET_CODE (reg
) != SUBREG
)
858 /* For the reg allocator we are interested in some SUBREG rtx's, but not
859 all. Notably only those representing a word extraction from a multi-word
860 reg. As written in the docu those should have the form
861 (subreg:SI (reg:M A) N), with size(SImode) > size(Mmode).
862 XXX Is that true? We could also use the global word_mode variable. */
863 if (GET_CODE (reg
) == SUBREG
864 && (GET_MODE_SIZE (GET_MODE (reg
)) < GET_MODE_SIZE (word_mode
)
865 || GET_MODE_SIZE (GET_MODE (reg
))
866 >= GET_MODE_SIZE (GET_MODE (SUBREG_REG (reg
)))))
868 loc
= &SUBREG_REG (reg
);
872 regno
= REGNO (GET_CODE (reg
) == SUBREG
? SUBREG_REG (reg
) : reg
);
873 if (regno
< FIRST_PSEUDO_REGISTER
)
878 if (! (df
->flags
& DF_HARD_REGS
))
881 /* GET_MODE (reg) is correct here. We don't want to go into a SUBREG
882 for the mode, because we only want to add references to regs, which
883 are really referenced. E.g. a (subreg:SI (reg:DI 0) 0) does _not_
884 reference the whole reg 0 in DI mode (which would also include
885 reg 1, at least, if 0 and 1 are SImode registers). */
886 endregno
= HARD_REGNO_NREGS (regno
, GET_MODE (reg
));
887 if (GET_CODE (reg
) == SUBREG
)
888 regno
+= subreg_regno_offset (regno
, GET_MODE (SUBREG_REG (reg
)),
889 SUBREG_BYTE (reg
), GET_MODE (reg
));
892 for (i
= regno
; i
< endregno
; i
++)
893 df_ref_record_1 (df
, regno_reg_rtx
[i
],
894 loc
, insn
, ref_type
, ref_flags
);
898 df_ref_record_1 (df
, reg
, loc
, insn
, ref_type
, ref_flags
);
902 /* Writes to paradoxical subregs, or subregs which are too narrow
903 are read-modify-write. */
906 read_modify_subreg_p (x
)
909 unsigned int isize
, osize
;
910 if (GET_CODE (x
) != SUBREG
)
912 isize
= GET_MODE_SIZE (GET_MODE (SUBREG_REG (x
)));
913 osize
= GET_MODE_SIZE (GET_MODE (x
));
916 if (isize
<= UNITS_PER_WORD
)
918 if (osize
>= UNITS_PER_WORD
)
923 /* Process all the registers defined in the rtx, X. */
925 df_def_record_1 (df
, x
, bb
, insn
)
931 rtx
*loc
= &SET_DEST (x
);
933 enum df_ref_flags flags
= 0;
935 /* Some targets place small structures in registers for
936 return values of functions. */
937 if (GET_CODE (dst
) == PARALLEL
&& GET_MODE (dst
) == BLKmode
)
941 for (i
= XVECLEN (dst
, 0) - 1; i
>= 0; i
--)
942 df_def_record_1 (df
, XVECEXP (dst
, 0, i
), bb
, insn
);
946 #ifdef CLASS_CANNOT_CHANGE_MODE
947 if (GET_CODE (dst
) == SUBREG
948 && CLASS_CANNOT_CHANGE_MODE_P (GET_MODE (dst
),
949 GET_MODE (SUBREG_REG (dst
))))
950 flags
|= DF_REF_MODE_CHANGE
;
953 /* May be, we should flag the use of strict_low_part somehow. Might be
954 handy for the reg allocator. */
955 while (GET_CODE (dst
) == STRICT_LOW_PART
956 || GET_CODE (dst
) == ZERO_EXTRACT
957 || GET_CODE (dst
) == SIGN_EXTRACT
958 || read_modify_subreg_p (dst
))
960 /* Strict low part always contains SUBREG, but we don't want to make
961 it appear outside, as whole register is always considered. */
962 if (GET_CODE (dst
) == STRICT_LOW_PART
)
964 loc
= &XEXP (dst
, 0);
967 #ifdef CLASS_CANNOT_CHANGE_MODE
968 if (GET_CODE (dst
) == SUBREG
969 && CLASS_CANNOT_CHANGE_MODE_P (GET_MODE (dst
),
970 GET_MODE (SUBREG_REG (dst
))))
971 flags
|= DF_REF_MODE_CHANGE
;
973 loc
= &XEXP (dst
, 0);
975 flags
|= DF_REF_READ_WRITE
;
978 if (GET_CODE (dst
) == REG
979 || (GET_CODE (dst
) == SUBREG
&& GET_CODE (SUBREG_REG (dst
)) == REG
))
980 df_ref_record (df
, dst
, loc
, insn
, DF_REF_REG_DEF
, flags
);
984 /* Process all the registers defined in the pattern rtx, X. */
986 df_defs_record (df
, x
, bb
, insn
)
992 RTX_CODE code
= GET_CODE (x
);
994 if (code
== SET
|| code
== CLOBBER
)
996 /* Mark the single def within the pattern. */
997 df_def_record_1 (df
, x
, bb
, insn
);
999 else if (code
== PARALLEL
)
1003 /* Mark the multiple defs within the pattern. */
1004 for (i
= XVECLEN (x
, 0) - 1; i
>= 0; i
--)
1006 code
= GET_CODE (XVECEXP (x
, 0, i
));
1007 if (code
== SET
|| code
== CLOBBER
)
1008 df_def_record_1 (df
, XVECEXP (x
, 0, i
), bb
, insn
);
1014 /* Process all the registers used in the rtx at address LOC. */
1016 df_uses_record (df
, loc
, ref_type
, bb
, insn
, flags
)
1019 enum df_ref_type ref_type
;
1022 enum df_ref_flags flags
;
1030 code
= GET_CODE (x
);
1045 /* If we are clobbering a MEM, mark any registers inside the address
1047 if (GET_CODE (XEXP (x
, 0)) == MEM
)
1048 df_uses_record (df
, &XEXP (XEXP (x
, 0), 0),
1049 DF_REF_REG_MEM_STORE
, bb
, insn
, flags
);
1051 /* If we're clobbering a REG then we have a def so ignore. */
1055 df_uses_record (df
, &XEXP (x
, 0), DF_REF_REG_MEM_LOAD
, bb
, insn
, flags
);
1059 /* While we're here, optimize this case. */
1061 /* In case the SUBREG is not of a register, don't optimize. */
1062 if (GET_CODE (SUBREG_REG (x
)) != REG
)
1064 loc
= &SUBREG_REG (x
);
1065 df_uses_record (df
, loc
, ref_type
, bb
, insn
, flags
);
1068 #ifdef CLASS_CANNOT_CHANGE_MODE
1069 if (CLASS_CANNOT_CHANGE_MODE_P (GET_MODE (x
),
1070 GET_MODE (SUBREG_REG (x
))))
1071 flags
|= DF_REF_MODE_CHANGE
;
1074 /* ... Fall through ... */
1077 /* See a register (or subreg) other than being set. */
1078 df_ref_record (df
, x
, loc
, insn
, ref_type
, flags
);
1083 rtx dst
= SET_DEST (x
);
1085 df_uses_record (df
, &SET_SRC (x
), DF_REF_REG_USE
, bb
, insn
, 0);
1087 switch (GET_CODE (dst
))
1089 enum df_ref_flags use_flags
;
1091 if (read_modify_subreg_p (dst
))
1093 use_flags
= DF_REF_READ_WRITE
;
1094 #ifdef CLASS_CANNOT_CHANGE_MODE
1095 if (CLASS_CANNOT_CHANGE_MODE_P (GET_MODE (dst
),
1096 GET_MODE (SUBREG_REG (dst
))))
1097 use_flags
|= DF_REF_MODE_CHANGE
;
1099 df_uses_record (df
, &SUBREG_REG (dst
), DF_REF_REG_USE
, bb
,
1103 /* ... FALLTHRU ... */
1109 df_uses_record (df
, &XEXP (dst
, 0),
1110 DF_REF_REG_MEM_STORE
,
1113 case STRICT_LOW_PART
:
1114 /* A strict_low_part uses the whole reg not only the subreg. */
1115 dst
= XEXP (dst
, 0);
1116 if (GET_CODE (dst
) != SUBREG
)
1118 use_flags
= DF_REF_READ_WRITE
;
1119 #ifdef CLASS_CANNOT_CHANGE_MODE
1120 if (CLASS_CANNOT_CHANGE_MODE_P (GET_MODE (dst
),
1121 GET_MODE (SUBREG_REG (dst
))))
1122 use_flags
|= DF_REF_MODE_CHANGE
;
1124 df_uses_record (df
, &SUBREG_REG (dst
), DF_REF_REG_USE
, bb
,
1129 df_uses_record (df
, &XEXP (dst
, 0), DF_REF_REG_USE
, bb
, insn
,
1131 df_uses_record (df
, &XEXP (dst
, 1), DF_REF_REG_USE
, bb
, insn
, 0);
1132 df_uses_record (df
, &XEXP (dst
, 2), DF_REF_REG_USE
, bb
, insn
, 0);
1133 dst
= XEXP (dst
, 0);
1145 case UNSPEC_VOLATILE
:
1149 /* Traditional and volatile asm instructions must be considered to use
1150 and clobber all hard registers, all pseudo-registers and all of
1151 memory. So must TRAP_IF and UNSPEC_VOLATILE operations.
1153 Consider for instance a volatile asm that changes the fpu rounding
1154 mode. An insn should not be moved across this even if it only uses
1155 pseudo-regs because it might give an incorrectly rounded result.
1157 For now, just mark any regs we can find in ASM_OPERANDS as
1160 /* For all ASM_OPERANDS, we must traverse the vector of input operands.
1161 We can not just fall through here since then we would be confused
1162 by the ASM_INPUT rtx inside ASM_OPERANDS, which do not indicate
1163 traditional asms unlike their normal usage. */
1164 if (code
== ASM_OPERANDS
)
1168 for (j
= 0; j
< ASM_OPERANDS_INPUT_LENGTH (x
); j
++)
1169 df_uses_record (df
, &ASM_OPERANDS_INPUT (x
, j
),
1170 DF_REF_REG_USE
, bb
, insn
, 0);
1182 /* Catch the def of the register being modified. */
1183 df_ref_record (df
, XEXP (x
, 0), &XEXP (x
, 0), insn
, DF_REF_REG_DEF
, DF_REF_READ_WRITE
);
1185 /* ... Fall through to handle uses ... */
1191 /* Recursively scan the operands of this expression. */
1193 const char *fmt
= GET_RTX_FORMAT (code
);
1196 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1200 /* Tail recursive case: save a function call level. */
1206 df_uses_record (df
, &XEXP (x
, i
), ref_type
, bb
, insn
, flags
);
1208 else if (fmt
[i
] == 'E')
1211 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1212 df_uses_record (df
, &XVECEXP (x
, i
, j
), ref_type
,
1220 /* Record all the df within INSN of basic block BB. */
1222 df_insn_refs_record (df
, bb
, insn
)
1233 /* Record register defs */
1234 df_defs_record (df
, PATTERN (insn
), bb
, insn
);
1236 if (df
->flags
& DF_EQUIV_NOTES
)
1237 for (note
= REG_NOTES (insn
); note
;
1238 note
= XEXP (note
, 1))
1240 switch (REG_NOTE_KIND (note
))
1244 df_uses_record (df
, &XEXP (note
, 0), DF_REF_REG_USE
,
1251 if (GET_CODE (insn
) == CALL_INSN
)
1256 /* Record the registers used to pass arguments. */
1257 for (note
= CALL_INSN_FUNCTION_USAGE (insn
); note
;
1258 note
= XEXP (note
, 1))
1260 if (GET_CODE (XEXP (note
, 0)) == USE
)
1261 df_uses_record (df
, &XEXP (XEXP (note
, 0), 0), DF_REF_REG_USE
,
1265 /* The stack ptr is used (honorarily) by a CALL insn. */
1266 x
= df_reg_use_gen (STACK_POINTER_REGNUM
);
1267 df_uses_record (df
, &XEXP (x
, 0), DF_REF_REG_USE
, bb
, insn
, 0);
1269 if (df
->flags
& DF_HARD_REGS
)
1271 /* Calls may also reference any of the global registers,
1272 so they are recorded as used. */
1273 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1276 x
= df_reg_use_gen (i
);
1277 df_uses_record (df
, &SET_DEST (x
),
1278 DF_REF_REG_USE
, bb
, insn
, 0);
1283 /* Record the register uses. */
1284 df_uses_record (df
, &PATTERN (insn
),
1285 DF_REF_REG_USE
, bb
, insn
, 0);
1288 if (GET_CODE (insn
) == CALL_INSN
)
1292 if (df
->flags
& DF_HARD_REGS
)
1294 /* Kill all registers invalidated by a call. */
1295 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1296 if (TEST_HARD_REG_BIT (regs_invalidated_by_call
, i
))
1298 rtx reg_clob
= df_reg_clobber_gen (i
);
1299 df_defs_record (df
, reg_clob
, bb
, insn
);
1303 /* There may be extra registers to be clobbered. */
1304 for (note
= CALL_INSN_FUNCTION_USAGE (insn
);
1306 note
= XEXP (note
, 1))
1307 if (GET_CODE (XEXP (note
, 0)) == CLOBBER
)
1308 df_defs_record (df
, XEXP (note
, 0), bb
, insn
);
1314 /* Record all the refs within the basic block BB. */
1316 df_bb_refs_record (df
, bb
)
1322 /* Scan the block an insn at a time from beginning to end. */
1323 for (insn
= bb
->head
; ; insn
= NEXT_INSN (insn
))
1327 /* Record defs within INSN. */
1328 df_insn_refs_record (df
, bb
, insn
);
1330 if (insn
== bb
->end
)
1336 /* Record all the refs in the basic blocks specified by BLOCKS. */
1338 df_refs_record (df
, blocks
)
1344 FOR_EACH_BB_IN_BITMAP (blocks
, 0, bb
,
1346 df_bb_refs_record (df
, bb
);
1350 /* Dataflow analysis routines. */
1353 /* Create reg-def chains for basic block BB. These are a list of
1354 definitions for each register. */
1356 df_bb_reg_def_chain_create (df
, bb
)
1362 /* Perhaps the defs should be sorted using a depth first search
1363 of the CFG (or possibly a breadth first search). We currently
1364 scan the basic blocks in reverse order so that the first defs
1365 appear at the start of the chain. */
1367 for (insn
= bb
->end
; insn
&& insn
!= PREV_INSN (bb
->head
);
1368 insn
= PREV_INSN (insn
))
1370 struct df_link
*link
;
1371 unsigned int uid
= INSN_UID (insn
);
1373 if (! INSN_P (insn
))
1376 for (link
= df
->insns
[uid
].defs
; link
; link
= link
->next
)
1378 struct ref
*def
= link
->ref
;
1379 unsigned int dregno
= DF_REF_REGNO (def
);
1380 /* Don't add ref's to the chain two times. I.e. only add
1381 new refs. XXX the same could be done by testing if the current
1382 insn is a modified (or a new) one. This would be faster. */
1383 if (DF_REF_ID (def
) < df
->def_id_save
)
1386 df
->regs
[dregno
].defs
1387 = df_link_create (def
, df
->regs
[dregno
].defs
);
1393 /* Create reg-def chains for each basic block within BLOCKS. These
1394 are a list of definitions for each register. */
1396 df_reg_def_chain_create (df
, blocks
)
1402 FOR_EACH_BB_IN_BITMAP
/*_REV*/ (blocks
, 0, bb
,
1404 df_bb_reg_def_chain_create (df
, bb
);
1409 /* Create reg-use chains for basic block BB. These are a list of uses
1410 for each register. */
1412 df_bb_reg_use_chain_create (df
, bb
)
1418 /* Scan in forward order so that the last uses appear at the
1419 start of the chain. */
1421 for (insn
= bb
->head
; insn
&& insn
!= NEXT_INSN (bb
->end
);
1422 insn
= NEXT_INSN (insn
))
1424 struct df_link
*link
;
1425 unsigned int uid
= INSN_UID (insn
);
1427 if (! INSN_P (insn
))
1430 for (link
= df
->insns
[uid
].uses
; link
; link
= link
->next
)
1432 struct ref
*use
= link
->ref
;
1433 unsigned int uregno
= DF_REF_REGNO (use
);
1434 /* Don't add ref's to the chain two times. I.e. only add
1435 new refs. XXX the same could be done by testing if the current
1436 insn is a modified (or a new) one. This would be faster. */
1437 if (DF_REF_ID (use
) < df
->use_id_save
)
1440 df
->regs
[uregno
].uses
1441 = df_link_create (use
, df
->regs
[uregno
].uses
);
1447 /* Create reg-use chains for each basic block within BLOCKS. These
1448 are a list of uses for each register. */
1450 df_reg_use_chain_create (df
, blocks
)
1456 FOR_EACH_BB_IN_BITMAP (blocks
, 0, bb
,
1458 df_bb_reg_use_chain_create (df
, bb
);
1463 /* Create def-use chains from reaching use bitmaps for basic block BB. */
1465 df_bb_du_chain_create (df
, bb
, ru
)
1470 struct bb_info
*bb_info
= DF_BB_INFO (df
, bb
);
1473 bitmap_copy (ru
, bb_info
->ru_out
);
1475 /* For each def in BB create a linked list (chain) of uses
1476 reached from the def. */
1477 for (insn
= bb
->end
; insn
&& insn
!= PREV_INSN (bb
->head
);
1478 insn
= PREV_INSN (insn
))
1480 struct df_link
*def_link
;
1481 struct df_link
*use_link
;
1482 unsigned int uid
= INSN_UID (insn
);
1484 if (! INSN_P (insn
))
1487 /* For each def in insn... */
1488 for (def_link
= df
->insns
[uid
].defs
; def_link
; def_link
= def_link
->next
)
1490 struct ref
*def
= def_link
->ref
;
1491 unsigned int dregno
= DF_REF_REGNO (def
);
1493 DF_REF_CHAIN (def
) = 0;
1495 /* While the reg-use chains are not essential, it
1496 is _much_ faster to search these short lists rather
1497 than all the reaching uses, especially for large functions. */
1498 for (use_link
= df
->regs
[dregno
].uses
; use_link
;
1499 use_link
= use_link
->next
)
1501 struct ref
*use
= use_link
->ref
;
1503 if (bitmap_bit_p (ru
, DF_REF_ID (use
)))
1506 = df_link_create (use
, DF_REF_CHAIN (def
));
1508 bitmap_clear_bit (ru
, DF_REF_ID (use
));
1513 /* For each use in insn... */
1514 for (use_link
= df
->insns
[uid
].uses
; use_link
; use_link
= use_link
->next
)
1516 struct ref
*use
= use_link
->ref
;
1517 bitmap_set_bit (ru
, DF_REF_ID (use
));
1523 /* Create def-use chains from reaching use bitmaps for basic blocks
1526 df_du_chain_create (df
, blocks
)
1533 ru
= BITMAP_XMALLOC ();
1535 FOR_EACH_BB_IN_BITMAP (blocks
, 0, bb
,
1537 df_bb_du_chain_create (df
, bb
, ru
);
1544 /* Create use-def chains from reaching def bitmaps for basic block BB. */
1546 df_bb_ud_chain_create (df
, bb
)
1550 struct bb_info
*bb_info
= DF_BB_INFO (df
, bb
);
1551 struct ref
**reg_def_last
= df
->reg_def_last
;
1554 memset (reg_def_last
, 0, df
->n_regs
* sizeof (struct ref
*));
1556 /* For each use in BB create a linked list (chain) of defs
1557 that reach the use. */
1558 for (insn
= bb
->head
; insn
&& insn
!= NEXT_INSN (bb
->end
);
1559 insn
= NEXT_INSN (insn
))
1561 unsigned int uid
= INSN_UID (insn
);
1562 struct df_link
*use_link
;
1563 struct df_link
*def_link
;
1565 if (! INSN_P (insn
))
1568 /* For each use in insn... */
1569 for (use_link
= df
->insns
[uid
].uses
; use_link
; use_link
= use_link
->next
)
1571 struct ref
*use
= use_link
->ref
;
1572 unsigned int regno
= DF_REF_REGNO (use
);
1574 DF_REF_CHAIN (use
) = 0;
1576 /* Has regno been defined in this BB yet? If so, use
1577 the last def as the single entry for the use-def
1578 chain for this use. Otherwise, we need to add all
1579 the defs using this regno that reach the start of
1581 if (reg_def_last
[regno
])
1584 = df_link_create (reg_def_last
[regno
], 0);
1588 /* While the reg-def chains are not essential, it is
1589 _much_ faster to search these short lists rather than
1590 all the reaching defs, especially for large
1592 for (def_link
= df
->regs
[regno
].defs
; def_link
;
1593 def_link
= def_link
->next
)
1595 struct ref
*def
= def_link
->ref
;
1597 if (bitmap_bit_p (bb_info
->rd_in
, DF_REF_ID (def
)))
1600 = df_link_create (def
, DF_REF_CHAIN (use
));
1607 /* For each def in insn...record the last def of each reg. */
1608 for (def_link
= df
->insns
[uid
].defs
; def_link
; def_link
= def_link
->next
)
1610 struct ref
*def
= def_link
->ref
;
1611 int dregno
= DF_REF_REGNO (def
);
1613 reg_def_last
[dregno
] = def
;
1619 /* Create use-def chains from reaching def bitmaps for basic blocks
1622 df_ud_chain_create (df
, blocks
)
1628 FOR_EACH_BB_IN_BITMAP (blocks
, 0, bb
,
1630 df_bb_ud_chain_create (df
, bb
);
1637 df_rd_transfer_function (bb
, changed
, in
, out
, gen
, kill
, data
)
1638 int bb ATTRIBUTE_UNUSED
;
1640 bitmap in
, out
, gen
, kill
;
1641 void *data ATTRIBUTE_UNUSED
;
1643 *changed
= bitmap_union_of_diff (out
, gen
, in
, kill
);
1646 df_ru_transfer_function (bb
, changed
, in
, out
, gen
, kill
, data
)
1647 int bb ATTRIBUTE_UNUSED
;
1649 bitmap in
, out
, gen
, kill
;
1650 void *data ATTRIBUTE_UNUSED
;
1652 *changed
= bitmap_union_of_diff (in
, gen
, out
, kill
);
1656 df_lr_transfer_function (bb
, changed
, in
, out
, use
, def
, data
)
1657 int bb ATTRIBUTE_UNUSED
;
1659 bitmap in
, out
, use
, def
;
1660 void *data ATTRIBUTE_UNUSED
;
1662 *changed
= bitmap_union_of_diff (in
, use
, out
, def
);
1666 /* Compute local reaching def info for basic block BB. */
1668 df_bb_rd_local_compute (df
, bb
)
1672 struct bb_info
*bb_info
= DF_BB_INFO (df
, bb
);
1675 for (insn
= bb
->head
; insn
&& insn
!= NEXT_INSN (bb
->end
);
1676 insn
= NEXT_INSN (insn
))
1678 unsigned int uid
= INSN_UID (insn
);
1679 struct df_link
*def_link
;
1681 if (! INSN_P (insn
))
1684 for (def_link
= df
->insns
[uid
].defs
; def_link
; def_link
= def_link
->next
)
1686 struct ref
*def
= def_link
->ref
;
1687 unsigned int regno
= DF_REF_REGNO (def
);
1688 struct df_link
*def2_link
;
1690 for (def2_link
= df
->regs
[regno
].defs
; def2_link
;
1691 def2_link
= def2_link
->next
)
1693 struct ref
*def2
= def2_link
->ref
;
1695 /* Add all defs of this reg to the set of kills. This
1696 is greedy since many of these defs will not actually
1697 be killed by this BB but it keeps things a lot
1699 bitmap_set_bit (bb_info
->rd_kill
, DF_REF_ID (def2
));
1701 /* Zap from the set of gens for this BB. */
1702 bitmap_clear_bit (bb_info
->rd_gen
, DF_REF_ID (def2
));
1705 bitmap_set_bit (bb_info
->rd_gen
, DF_REF_ID (def
));
1709 bb_info
->rd_valid
= 1;
1713 /* Compute local reaching def info for each basic block within BLOCKS. */
1715 df_rd_local_compute (df
, blocks
)
1721 FOR_EACH_BB_IN_BITMAP (blocks
, 0, bb
,
1723 df_bb_rd_local_compute (df
, bb
);
1728 /* Compute local reaching use (upward exposed use) info for basic
1731 df_bb_ru_local_compute (df
, bb
)
1735 /* This is much more tricky than computing reaching defs. With
1736 reaching defs, defs get killed by other defs. With upwards
1737 exposed uses, these get killed by defs with the same regno. */
1739 struct bb_info
*bb_info
= DF_BB_INFO (df
, bb
);
1743 for (insn
= bb
->end
; insn
&& insn
!= PREV_INSN (bb
->head
);
1744 insn
= PREV_INSN (insn
))
1746 unsigned int uid
= INSN_UID (insn
);
1747 struct df_link
*def_link
;
1748 struct df_link
*use_link
;
1750 if (! INSN_P (insn
))
1753 for (def_link
= df
->insns
[uid
].defs
; def_link
; def_link
= def_link
->next
)
1755 struct ref
*def
= def_link
->ref
;
1756 unsigned int dregno
= DF_REF_REGNO (def
);
1758 for (use_link
= df
->regs
[dregno
].uses
; use_link
;
1759 use_link
= use_link
->next
)
1761 struct ref
*use
= use_link
->ref
;
1763 /* Add all uses of this reg to the set of kills. This
1764 is greedy since many of these uses will not actually
1765 be killed by this BB but it keeps things a lot
1767 bitmap_set_bit (bb_info
->ru_kill
, DF_REF_ID (use
));
1769 /* Zap from the set of gens for this BB. */
1770 bitmap_clear_bit (bb_info
->ru_gen
, DF_REF_ID (use
));
1774 for (use_link
= df
->insns
[uid
].uses
; use_link
; use_link
= use_link
->next
)
1776 struct ref
*use
= use_link
->ref
;
1777 /* Add use to set of gens in this BB. */
1778 bitmap_set_bit (bb_info
->ru_gen
, DF_REF_ID (use
));
1781 bb_info
->ru_valid
= 1;
1785 /* Compute local reaching use (upward exposed use) info for each basic
1786 block within BLOCKS. */
1788 df_ru_local_compute (df
, blocks
)
1794 FOR_EACH_BB_IN_BITMAP (blocks
, 0, bb
,
1796 df_bb_ru_local_compute (df
, bb
);
1801 /* Compute local live variable info for basic block BB. */
1803 df_bb_lr_local_compute (df
, bb
)
1807 struct bb_info
*bb_info
= DF_BB_INFO (df
, bb
);
1810 for (insn
= bb
->end
; insn
&& insn
!= PREV_INSN (bb
->head
);
1811 insn
= PREV_INSN (insn
))
1813 unsigned int uid
= INSN_UID (insn
);
1814 struct df_link
*link
;
1816 if (! INSN_P (insn
))
1819 for (link
= df
->insns
[uid
].defs
; link
; link
= link
->next
)
1821 struct ref
*def
= link
->ref
;
1822 unsigned int dregno
= DF_REF_REGNO (def
);
1824 /* Add def to set of defs in this BB. */
1825 bitmap_set_bit (bb_info
->lr_def
, dregno
);
1827 bitmap_clear_bit (bb_info
->lr_use
, dregno
);
1830 for (link
= df
->insns
[uid
].uses
; link
; link
= link
->next
)
1832 struct ref
*use
= link
->ref
;
1833 /* Add use to set of uses in this BB. */
1834 bitmap_set_bit (bb_info
->lr_use
, DF_REF_REGNO (use
));
1837 bb_info
->lr_valid
= 1;
1841 /* Compute local live variable info for each basic block within BLOCKS. */
1843 df_lr_local_compute (df
, blocks
)
1849 FOR_EACH_BB_IN_BITMAP (blocks
, 0, bb
,
1851 df_bb_lr_local_compute (df
, bb
);
1856 /* Compute register info: lifetime, bb, and number of defs and uses
1857 for basic block BB. */
1859 df_bb_reg_info_compute (df
, bb
, live
)
1864 struct reg_info
*reg_info
= df
->regs
;
1865 struct bb_info
*bb_info
= DF_BB_INFO (df
, bb
);
1868 bitmap_copy (live
, bb_info
->lr_out
);
1870 for (insn
= bb
->end
; insn
&& insn
!= PREV_INSN (bb
->head
);
1871 insn
= PREV_INSN (insn
))
1873 unsigned int uid
= INSN_UID (insn
);
1875 struct df_link
*link
;
1877 if (! INSN_P (insn
))
1880 for (link
= df
->insns
[uid
].defs
; link
; link
= link
->next
)
1882 struct ref
*def
= link
->ref
;
1883 unsigned int dregno
= DF_REF_REGNO (def
);
1885 /* Kill this register. */
1886 bitmap_clear_bit (live
, dregno
);
1887 reg_info
[dregno
].n_defs
++;
1890 for (link
= df
->insns
[uid
].uses
; link
; link
= link
->next
)
1892 struct ref
*use
= link
->ref
;
1893 unsigned int uregno
= DF_REF_REGNO (use
);
1895 /* This register is now live. */
1896 bitmap_set_bit (live
, uregno
);
1897 reg_info
[uregno
].n_uses
++;
1900 /* Increment lifetimes of all live registers. */
1901 EXECUTE_IF_SET_IN_BITMAP (live
, 0, regno
,
1903 reg_info
[regno
].lifetime
++;
1909 /* Compute register info: lifetime, bb, and number of defs and uses. */
1911 df_reg_info_compute (df
, blocks
)
1918 live
= BITMAP_XMALLOC ();
1920 FOR_EACH_BB_IN_BITMAP (blocks
, 0, bb
,
1922 df_bb_reg_info_compute (df
, bb
, live
);
1925 BITMAP_XFREE (live
);
1929 /* Assign LUIDs for BB. */
1931 df_bb_luids_set (df
, bb
)
1938 /* The LUIDs are monotonically increasing for each basic block. */
1940 for (insn
= bb
->head
; ; insn
= NEXT_INSN (insn
))
1943 DF_INSN_LUID (df
, insn
) = luid
++;
1944 DF_INSN_LUID (df
, insn
) = luid
;
1946 if (insn
== bb
->end
)
1953 /* Assign LUIDs for each basic block within BLOCKS. */
1955 df_luids_set (df
, blocks
)
1962 FOR_EACH_BB_IN_BITMAP (blocks
, 0, bb
,
1964 total
+= df_bb_luids_set (df
, bb
);
1969 /* Perform dataflow analysis using existing DF structure for blocks
1970 within BLOCKS. If BLOCKS is zero, use all basic blocks in the CFG. */
1972 df_analyse_1 (df
, blocks
, flags
, update
)
1985 if (flags
& DF_UD_CHAIN
)
1986 aflags
|= DF_RD
| DF_RD_CHAIN
;
1988 if (flags
& DF_DU_CHAIN
)
1992 aflags
|= DF_RU_CHAIN
;
1994 if (flags
& DF_REG_INFO
)
1998 blocks
= df
->all_blocks
;
2003 df_refs_update (df
);
2004 /* More fine grained incremental dataflow analysis would be
2005 nice. For now recompute the whole shebang for the
2008 df_refs_unlink (df
, blocks
);
2010 /* All the def-use, use-def chains can be potentially
2011 modified by changes in one block. The size of the
2012 bitmaps can also change. */
2016 /* Scan the function for all register defs and uses. */
2018 df_refs_record (df
, blocks
);
2020 /* Link all the new defs and uses to the insns. */
2021 df_refs_process (df
);
2024 /* Allocate the bitmaps now the total number of defs and uses are
2025 known. If the number of defs or uses have changed, then
2026 these bitmaps need to be reallocated. */
2027 df_bitmaps_alloc (df
, aflags
);
2029 /* Set the LUIDs for each specified basic block. */
2030 df_luids_set (df
, blocks
);
2032 /* Recreate reg-def and reg-use chains from scratch so that first
2033 def is at the head of the reg-def chain and the last use is at
2034 the head of the reg-use chain. This is only important for
2035 regs local to a basic block as it speeds up searching. */
2036 if (aflags
& DF_RD_CHAIN
)
2038 df_reg_def_chain_create (df
, blocks
);
2041 if (aflags
& DF_RU_CHAIN
)
2043 df_reg_use_chain_create (df
, blocks
);
2046 df
->dfs_order
= xmalloc (sizeof (int) * n_basic_blocks
);
2047 df
->rc_order
= xmalloc (sizeof (int) * n_basic_blocks
);
2048 df
->rts_order
= xmalloc (sizeof (int) * n_basic_blocks
);
2049 df
->inverse_dfs_map
= xmalloc (sizeof (int) * last_basic_block
);
2050 df
->inverse_rc_map
= xmalloc (sizeof (int) * last_basic_block
);
2051 df
->inverse_rts_map
= xmalloc (sizeof (int) * last_basic_block
);
2053 flow_depth_first_order_compute (df
->dfs_order
, df
->rc_order
);
2054 flow_reverse_top_sort_order_compute (df
->rts_order
);
2055 for (i
= 0; i
< n_basic_blocks
; i
++)
2057 df
->inverse_dfs_map
[df
->dfs_order
[i
]] = i
;
2058 df
->inverse_rc_map
[df
->rc_order
[i
]] = i
;
2059 df
->inverse_rts_map
[df
->rts_order
[i
]] = i
;
2063 /* Compute the sets of gens and kills for the defs of each bb. */
2064 df_rd_local_compute (df
, df
->flags
& DF_RD
? blocks
: df
->all_blocks
);
2066 bitmap
*in
= xmalloc (sizeof (bitmap
) * last_basic_block
);
2067 bitmap
*out
= xmalloc (sizeof (bitmap
) * last_basic_block
);
2068 bitmap
*gen
= xmalloc (sizeof (bitmap
) * last_basic_block
);
2069 bitmap
*kill
= xmalloc (sizeof (bitmap
) * last_basic_block
);
2072 in
[bb
->index
] = DF_BB_INFO (df
, bb
)->rd_in
;
2073 out
[bb
->index
] = DF_BB_INFO (df
, bb
)->rd_out
;
2074 gen
[bb
->index
] = DF_BB_INFO (df
, bb
)->rd_gen
;
2075 kill
[bb
->index
] = DF_BB_INFO (df
, bb
)->rd_kill
;
2077 iterative_dataflow_bitmap (in
, out
, gen
, kill
, df
->all_blocks
,
2078 FORWARD
, UNION
, df_rd_transfer_function
,
2079 df
->inverse_rc_map
, NULL
);
2087 if (aflags
& DF_UD_CHAIN
)
2089 /* Create use-def chains. */
2090 df_ud_chain_create (df
, df
->all_blocks
);
2092 if (! (flags
& DF_RD
))
2098 /* Compute the sets of gens and kills for the upwards exposed
2100 df_ru_local_compute (df
, df
->flags
& DF_RU
? blocks
: df
->all_blocks
);
2102 bitmap
*in
= xmalloc (sizeof (bitmap
) * last_basic_block
);
2103 bitmap
*out
= xmalloc (sizeof (bitmap
) * last_basic_block
);
2104 bitmap
*gen
= xmalloc (sizeof (bitmap
) * last_basic_block
);
2105 bitmap
*kill
= xmalloc (sizeof (bitmap
) * last_basic_block
);
2108 in
[bb
->index
] = DF_BB_INFO (df
, bb
)->ru_in
;
2109 out
[bb
->index
] = DF_BB_INFO (df
, bb
)->ru_out
;
2110 gen
[bb
->index
] = DF_BB_INFO (df
, bb
)->ru_gen
;
2111 kill
[bb
->index
] = DF_BB_INFO (df
, bb
)->ru_kill
;
2113 iterative_dataflow_bitmap (in
, out
, gen
, kill
, df
->all_blocks
,
2114 BACKWARD
, UNION
, df_ru_transfer_function
,
2115 df
->inverse_rts_map
, NULL
);
2123 if (aflags
& DF_DU_CHAIN
)
2125 /* Create def-use chains. */
2126 df_du_chain_create (df
, df
->all_blocks
);
2128 if (! (flags
& DF_RU
))
2132 /* Free up bitmaps that are no longer required. */
2134 df_bitmaps_free (df
, dflags
);
2138 /* Compute the sets of defs and uses of live variables. */
2139 df_lr_local_compute (df
, df
->flags
& DF_LR
? blocks
: df
->all_blocks
);
2141 bitmap
*in
= xmalloc (sizeof (bitmap
) * last_basic_block
);
2142 bitmap
*out
= xmalloc (sizeof (bitmap
) * last_basic_block
);
2143 bitmap
*use
= xmalloc (sizeof (bitmap
) * last_basic_block
);
2144 bitmap
*def
= xmalloc (sizeof (bitmap
) * last_basic_block
);
2147 in
[bb
->index
] = DF_BB_INFO (df
, bb
)->lr_in
;
2148 out
[bb
->index
] = DF_BB_INFO (df
, bb
)->lr_out
;
2149 use
[bb
->index
] = DF_BB_INFO (df
, bb
)->lr_use
;
2150 def
[bb
->index
] = DF_BB_INFO (df
, bb
)->lr_def
;
2152 iterative_dataflow_bitmap (in
, out
, use
, def
, df
->all_blocks
,
2153 BACKWARD
, UNION
, df_lr_transfer_function
,
2154 df
->inverse_rts_map
, NULL
);
2162 if (aflags
& DF_REG_INFO
)
2164 df_reg_info_compute (df
, df
->all_blocks
);
2166 free (df
->dfs_order
);
2167 free (df
->rc_order
);
2168 free (df
->rts_order
);
2169 free (df
->inverse_rc_map
);
2170 free (df
->inverse_dfs_map
);
2171 free (df
->inverse_rts_map
);
2175 /* Initialize dataflow analysis. */
2181 df
= xcalloc (1, sizeof (struct df
));
2183 /* Squirrel away a global for debugging. */
2190 /* Start queuing refs. */
2195 df
->def_id_save
= df
->def_id
;
2196 df
->use_id_save
= df
->use_id
;
2197 /* ???? Perhaps we should save current obstack state so that we can
2203 /* Process queued refs. */
2205 df_refs_process (df
)
2210 /* Build new insn-def chains. */
2211 for (i
= df
->def_id_save
; i
!= df
->def_id
; i
++)
2213 struct ref
*def
= df
->defs
[i
];
2214 unsigned int uid
= DF_REF_INSN_UID (def
);
2216 /* Add def to head of def list for INSN. */
2218 = df_link_create (def
, df
->insns
[uid
].defs
);
2221 /* Build new insn-use chains. */
2222 for (i
= df
->use_id_save
; i
!= df
->use_id
; i
++)
2224 struct ref
*use
= df
->uses
[i
];
2225 unsigned int uid
= DF_REF_INSN_UID (use
);
2227 /* Add use to head of use list for INSN. */
2229 = df_link_create (use
, df
->insns
[uid
].uses
);
2235 /* Update refs for basic block BB. */
2237 df_bb_refs_update (df
, bb
)
2244 /* While we have to scan the chain of insns for this BB, we don't
2245 need to allocate and queue a long chain of BB/INSN pairs. Using
2246 a bitmap for insns_modified saves memory and avoids queuing
2249 for (insn
= bb
->head
; ; insn
= NEXT_INSN (insn
))
2253 uid
= INSN_UID (insn
);
2255 if (bitmap_bit_p (df
->insns_modified
, uid
))
2257 /* Delete any allocated refs of this insn. MPH, FIXME. */
2258 df_insn_refs_unlink (df
, bb
, insn
);
2260 /* Scan the insn for refs. */
2261 df_insn_refs_record (df
, bb
, insn
);
2265 if (insn
== bb
->end
)
2272 /* Process all the modified/deleted insns that were queued. */
2280 if ((unsigned int) max_reg_num () >= df
->reg_size
)
2281 df_reg_table_realloc (df
, 0);
2285 FOR_EACH_BB_IN_BITMAP (df
->bbs_modified
, 0, bb
,
2287 count
+= df_bb_refs_update (df
, bb
);
2290 df_refs_process (df
);
2295 /* Return nonzero if any of the requested blocks in the bitmap
2296 BLOCKS have been modified. */
2298 df_modified_p (df
, blocks
)
2309 if (bitmap_bit_p (df
->bbs_modified
, bb
->index
)
2310 && (! blocks
|| (blocks
== (bitmap
) -1) || bitmap_bit_p (blocks
, bb
->index
)))
2320 /* Analyze dataflow info for the basic blocks specified by the bitmap
2321 BLOCKS, or for the whole CFG if BLOCKS is zero, or just for the
2322 modified blocks if BLOCKS is -1. */
2324 df_analyse (df
, blocks
, flags
)
2331 /* We could deal with additional basic blocks being created by
2332 rescanning everything again. */
2333 if (df
->n_bbs
&& df
->n_bbs
!= (unsigned int) last_basic_block
)
2336 update
= df_modified_p (df
, blocks
);
2337 if (update
|| (flags
!= df
->flags
))
2343 /* Recompute everything from scratch. */
2346 /* Allocate and initialize data structures. */
2347 df_alloc (df
, max_reg_num ());
2348 df_analyse_1 (df
, 0, flags
, 0);
2353 if (blocks
== (bitmap
) -1)
2354 blocks
= df
->bbs_modified
;
2359 df_analyse_1 (df
, blocks
, flags
, 1);
2360 bitmap_zero (df
->bbs_modified
);
2361 bitmap_zero (df
->insns_modified
);
2368 /* Free all the dataflow info and the DF structure. */
2378 /* Unlink INSN from its reference information. */
2380 df_insn_refs_unlink (df
, bb
, insn
)
2382 basic_block bb ATTRIBUTE_UNUSED
;
2385 struct df_link
*link
;
2388 uid
= INSN_UID (insn
);
2390 /* Unlink all refs defined by this insn. */
2391 for (link
= df
->insns
[uid
].defs
; link
; link
= link
->next
)
2392 df_def_unlink (df
, link
->ref
);
2394 /* Unlink all refs used by this insn. */
2395 for (link
= df
->insns
[uid
].uses
; link
; link
= link
->next
)
2396 df_use_unlink (df
, link
->ref
);
2398 df
->insns
[uid
].defs
= 0;
2399 df
->insns
[uid
].uses
= 0;
2404 /* Unlink all the insns within BB from their reference information. */
2406 df_bb_refs_unlink (df
, bb
)
2412 /* Scan the block an insn at a time from beginning to end. */
2413 for (insn
= bb
->head
; ; insn
= NEXT_INSN (insn
))
2417 /* Unlink refs for INSN. */
2418 df_insn_refs_unlink (df
, bb
, insn
);
2420 if (insn
== bb
->end
)
2426 /* Unlink all the refs in the basic blocks specified by BLOCKS.
2427 Not currently used. */
2429 df_refs_unlink (df
, blocks
)
2437 FOR_EACH_BB_IN_BITMAP (blocks
, 0, bb
,
2439 df_bb_refs_unlink (df
, bb
);
2445 df_bb_refs_unlink (df
, bb
);
2450 /* Functions to modify insns. */
2453 /* Delete INSN and all its reference information. */
2455 df_insn_delete (df
, bb
, insn
)
2457 basic_block bb ATTRIBUTE_UNUSED
;
2460 /* If the insn is a jump, we should perhaps call delete_insn to
2461 handle the JUMP_LABEL? */
2463 /* We should not be deleting the NOTE_INSN_BASIC_BLOCK or label. */
2464 if (insn
== bb
->head
)
2467 /* Delete the insn. */
2470 df_insn_modify (df
, bb
, insn
);
2472 return NEXT_INSN (insn
);
2476 /* Mark that INSN within BB may have changed (created/modified/deleted).
2477 This may be called multiple times for the same insn. There is no
2478 harm calling this function if the insn wasn't changed; it will just
2479 slow down the rescanning of refs. */
2481 df_insn_modify (df
, bb
, insn
)
2488 uid
= INSN_UID (insn
);
2489 if (uid
>= df
->insn_size
)
2490 df_insn_table_realloc (df
, uid
);
2492 bitmap_set_bit (df
->bbs_modified
, bb
->index
);
2493 bitmap_set_bit (df
->insns_modified
, uid
);
2495 /* For incremental updating on the fly, perhaps we could make a copy
2496 of all the refs of the original insn and turn them into
2497 anti-refs. When df_refs_update finds these anti-refs, it annihilates
2498 the original refs. If validate_change fails then these anti-refs
2499 will just get ignored. */
2503 typedef struct replace_args
{
2511 /* Replace mem pointed to by PX with its associated pseudo register.
2512 DATA is actually a pointer to a structure describing the
2513 instruction currently being scanned and the MEM we are currently
2516 df_rtx_mem_replace (px
, data
)
2520 replace_args
*args
= (replace_args
*) data
;
2523 if (mem
== NULL_RTX
)
2526 switch (GET_CODE (mem
))
2532 /* We're not interested in the MEM associated with a
2533 CONST_DOUBLE, so there's no need to traverse into one. */
2537 /* This is not a MEM. */
2541 if (!rtx_equal_p (args
->match
, mem
))
2542 /* This is not the MEM we are currently replacing. */
2545 /* Actually replace the MEM. */
2546 validate_change (args
->insn
, px
, args
->replacement
, 1);
2554 df_insn_mem_replace (df
, bb
, insn
, mem
, reg
)
2565 args
.replacement
= reg
;
2568 /* Search and replace all matching mems within insn. */
2569 for_each_rtx (&insn
, df_rtx_mem_replace
, &args
);
2572 df_insn_modify (df
, bb
, insn
);
2574 /* ???? FIXME. We may have a new def or one or more new uses of REG
2575 in INSN. REG should be a new pseudo so it won't affect the
2576 dataflow information that we currently have. We should add
2577 the new uses and defs to INSN and then recreate the chains
2578 when df_analyse is called. */
2579 return args
.modified
;
2583 /* Replace one register with another. Called through for_each_rtx; PX
2584 points to the rtx being scanned. DATA is actually a pointer to a
2585 structure of arguments. */
2587 df_rtx_reg_replace (px
, data
)
2592 replace_args
*args
= (replace_args
*) data
;
2597 if (x
== args
->match
)
2599 validate_change (args
->insn
, px
, args
->replacement
, 1);
2607 /* Replace the reg within every ref on CHAIN that is within the set
2608 BLOCKS of basic blocks with NEWREG. Also update the regs within
2611 df_refs_reg_replace (df
, blocks
, chain
, oldreg
, newreg
)
2614 struct df_link
*chain
;
2618 struct df_link
*link
;
2622 blocks
= df
->all_blocks
;
2624 args
.match
= oldreg
;
2625 args
.replacement
= newreg
;
2628 for (link
= chain
; link
; link
= link
->next
)
2630 struct ref
*ref
= link
->ref
;
2631 rtx insn
= DF_REF_INSN (ref
);
2633 if (! INSN_P (insn
))
2636 if (bitmap_bit_p (blocks
, DF_REF_BBNO (ref
)))
2638 df_ref_reg_replace (df
, ref
, oldreg
, newreg
);
2640 /* Replace occurrences of the reg within the REG_NOTES. */
2641 if ((! link
->next
|| DF_REF_INSN (ref
)
2642 != DF_REF_INSN (link
->next
->ref
))
2643 && REG_NOTES (insn
))
2646 for_each_rtx (®_NOTES (insn
), df_rtx_reg_replace
, &args
);
2651 /* Temporary check to ensure that we have a grip on which
2652 regs should be replaced. */
2659 /* Replace all occurrences of register OLDREG with register NEWREG in
2660 blocks defined by bitmap BLOCKS. This also replaces occurrences of
2661 OLDREG in the REG_NOTES but only for insns containing OLDREG. This
2662 routine expects the reg-use and reg-def chains to be valid. */
2664 df_reg_replace (df
, blocks
, oldreg
, newreg
)
2670 unsigned int oldregno
= REGNO (oldreg
);
2672 df_refs_reg_replace (df
, blocks
, df
->regs
[oldregno
].defs
, oldreg
, newreg
);
2673 df_refs_reg_replace (df
, blocks
, df
->regs
[oldregno
].uses
, oldreg
, newreg
);
2678 /* Try replacing the reg within REF with NEWREG. Do not modify
2679 def-use/use-def chains. */
2681 df_ref_reg_replace (df
, ref
, oldreg
, newreg
)
2687 /* Check that insn was deleted by being converted into a NOTE. If
2688 so ignore this insn. */
2689 if (! INSN_P (DF_REF_INSN (ref
)))
2692 if (oldreg
&& oldreg
!= DF_REF_REG (ref
))
2695 if (! validate_change (DF_REF_INSN (ref
), DF_REF_LOC (ref
), newreg
, 1))
2698 df_insn_modify (df
, DF_REF_BB (ref
), DF_REF_INSN (ref
));
2704 df_bb_def_use_swap (df
, bb
, def_insn
, use_insn
, regno
)
2715 struct df_link
*link
;
2717 def
= df_bb_insn_regno_first_def_find (df
, bb
, def_insn
, regno
);
2721 use
= df_bb_insn_regno_last_use_find (df
, bb
, use_insn
, regno
);
2725 /* The USE no longer exists. */
2726 use_uid
= INSN_UID (use_insn
);
2727 df_use_unlink (df
, use
);
2728 df_ref_unlink (&df
->insns
[use_uid
].uses
, use
);
2730 /* The DEF requires shifting so remove it from DEF_INSN
2731 and add it to USE_INSN by reusing LINK. */
2732 def_uid
= INSN_UID (def_insn
);
2733 link
= df_ref_unlink (&df
->insns
[def_uid
].defs
, def
);
2735 link
->next
= df
->insns
[use_uid
].defs
;
2736 df
->insns
[use_uid
].defs
= link
;
2739 link
= df_ref_unlink (&df
->regs
[regno
].defs
, def
);
2741 link
->next
= df
->regs
[regno
].defs
;
2742 df
->insns
[regno
].defs
= link
;
2745 DF_REF_INSN (def
) = use_insn
;
2750 /* Record df between FIRST_INSN and LAST_INSN inclusive. All new
2751 insns must be processed by this routine. */
2753 df_insns_modify (df
, bb
, first_insn
, last_insn
)
2761 for (insn
= first_insn
; ; insn
= NEXT_INSN (insn
))
2765 /* A non-const call should not have slipped through the net. If
2766 it does, we need to create a new basic block. Ouch. The
2767 same applies for a label. */
2768 if ((GET_CODE (insn
) == CALL_INSN
2769 && ! CONST_OR_PURE_CALL_P (insn
))
2770 || GET_CODE (insn
) == CODE_LABEL
)
2773 uid
= INSN_UID (insn
);
2775 if (uid
>= df
->insn_size
)
2776 df_insn_table_realloc (df
, uid
);
2778 df_insn_modify (df
, bb
, insn
);
2780 if (insn
== last_insn
)
2786 /* Emit PATTERN before INSN within BB. */
2788 df_pattern_emit_before (df
, pattern
, bb
, insn
)
2789 struct df
*df ATTRIBUTE_UNUSED
;
2795 rtx prev_insn
= PREV_INSN (insn
);
2797 /* We should not be inserting before the start of the block. */
2798 if (insn
== bb
->head
)
2800 ret_insn
= emit_insn_before (pattern
, insn
);
2801 if (ret_insn
== insn
)
2804 df_insns_modify (df
, bb
, NEXT_INSN (prev_insn
), ret_insn
);
2809 /* Emit PATTERN after INSN within BB. */
2811 df_pattern_emit_after (df
, pattern
, bb
, insn
)
2819 ret_insn
= emit_insn_after (pattern
, insn
);
2820 if (ret_insn
== insn
)
2823 df_insns_modify (df
, bb
, NEXT_INSN (insn
), ret_insn
);
2828 /* Emit jump PATTERN after INSN within BB. */
2830 df_jump_pattern_emit_after (df
, pattern
, bb
, insn
)
2838 ret_insn
= emit_jump_insn_after (pattern
, insn
);
2839 if (ret_insn
== insn
)
2842 df_insns_modify (df
, bb
, NEXT_INSN (insn
), ret_insn
);
2847 /* Move INSN within BB before BEFORE_INSN within BEFORE_BB.
2849 This function should only be used to move loop invariant insns
2850 out of a loop where it has been proven that the def-use info
2851 will still be valid. */
2853 df_insn_move_before (df
, bb
, insn
, before_bb
, before_insn
)
2857 basic_block before_bb
;
2860 struct df_link
*link
;
2864 return df_pattern_emit_before (df
, insn
, before_bb
, before_insn
);
2866 uid
= INSN_UID (insn
);
2868 /* Change bb for all df defined and used by this insn. */
2869 for (link
= df
->insns
[uid
].defs
; link
; link
= link
->next
)
2870 DF_REF_BB (link
->ref
) = before_bb
;
2871 for (link
= df
->insns
[uid
].uses
; link
; link
= link
->next
)
2872 DF_REF_BB (link
->ref
) = before_bb
;
2874 /* The lifetimes of the registers used in this insn will be reduced
2875 while the lifetimes of the registers defined in this insn
2876 are likely to be increased. */
2878 /* ???? Perhaps all the insns moved should be stored on a list
2879 which df_analyse removes when it recalculates data flow. */
2881 return emit_insn_before (insn
, before_insn
);
2884 /* Functions to query dataflow information. */
2888 df_insn_regno_def_p (df
, bb
, insn
, regno
)
2890 basic_block bb ATTRIBUTE_UNUSED
;
2895 struct df_link
*link
;
2897 uid
= INSN_UID (insn
);
2899 for (link
= df
->insns
[uid
].defs
; link
; link
= link
->next
)
2901 struct ref
*def
= link
->ref
;
2903 if (DF_REF_REGNO (def
) == regno
)
2912 df_def_dominates_all_uses_p (df
, def
)
2913 struct df
*df ATTRIBUTE_UNUSED
;
2916 struct df_link
*du_link
;
2918 /* Follow def-use chain to find all the uses of this def. */
2919 for (du_link
= DF_REF_CHAIN (def
); du_link
; du_link
= du_link
->next
)
2921 struct ref
*use
= du_link
->ref
;
2922 struct df_link
*ud_link
;
2924 /* Follow use-def chain to check all the defs for this use. */
2925 for (ud_link
= DF_REF_CHAIN (use
); ud_link
; ud_link
= ud_link
->next
)
2926 if (ud_link
->ref
!= def
)
2934 df_insn_dominates_all_uses_p (df
, bb
, insn
)
2936 basic_block bb ATTRIBUTE_UNUSED
;
2940 struct df_link
*link
;
2942 uid
= INSN_UID (insn
);
2944 for (link
= df
->insns
[uid
].defs
; link
; link
= link
->next
)
2946 struct ref
*def
= link
->ref
;
2948 if (! df_def_dominates_all_uses_p (df
, def
))
2956 /* Return nonzero if all DF dominates all the uses within the bitmap
2959 df_def_dominates_uses_p (df
, def
, blocks
)
2960 struct df
*df ATTRIBUTE_UNUSED
;
2964 struct df_link
*du_link
;
2966 /* Follow def-use chain to find all the uses of this def. */
2967 for (du_link
= DF_REF_CHAIN (def
); du_link
; du_link
= du_link
->next
)
2969 struct ref
*use
= du_link
->ref
;
2970 struct df_link
*ud_link
;
2972 /* Only worry about the uses within BLOCKS. For example,
2973 consider a register defined within a loop that is live at the
2975 if (bitmap_bit_p (blocks
, DF_REF_BBNO (use
)))
2977 /* Follow use-def chain to check all the defs for this use. */
2978 for (ud_link
= DF_REF_CHAIN (use
); ud_link
; ud_link
= ud_link
->next
)
2979 if (ud_link
->ref
!= def
)
2987 /* Return nonzero if all the defs of INSN within BB dominates
2988 all the corresponding uses. */
2990 df_insn_dominates_uses_p (df
, bb
, insn
, blocks
)
2992 basic_block bb ATTRIBUTE_UNUSED
;
2997 struct df_link
*link
;
2999 uid
= INSN_UID (insn
);
3001 for (link
= df
->insns
[uid
].defs
; link
; link
= link
->next
)
3003 struct ref
*def
= link
->ref
;
3005 /* Only consider the defs within BLOCKS. */
3006 if (bitmap_bit_p (blocks
, DF_REF_BBNO (def
))
3007 && ! df_def_dominates_uses_p (df
, def
, blocks
))
3014 /* Return the basic block that REG referenced in or NULL if referenced
3015 in multiple basic blocks. */
3017 df_regno_bb (df
, regno
)
3021 struct df_link
*defs
= df
->regs
[regno
].defs
;
3022 struct df_link
*uses
= df
->regs
[regno
].uses
;
3023 struct ref
*def
= defs
? defs
->ref
: 0;
3024 struct ref
*use
= uses
? uses
->ref
: 0;
3025 basic_block bb_def
= def
? DF_REF_BB (def
) : 0;
3026 basic_block bb_use
= use
? DF_REF_BB (use
) : 0;
3028 /* Compare blocks of first def and last use. ???? FIXME. What if
3029 the reg-def and reg-use lists are not correctly ordered. */
3030 return bb_def
== bb_use
? bb_def
: 0;
3034 /* Return nonzero if REG used in multiple basic blocks. */
3036 df_reg_global_p (df
, reg
)
3040 return df_regno_bb (df
, REGNO (reg
)) != 0;
3044 /* Return total lifetime (in insns) of REG. */
3046 df_reg_lifetime (df
, reg
)
3050 return df
->regs
[REGNO (reg
)].lifetime
;
3054 /* Return nonzero if REG live at start of BB. */
3056 df_bb_reg_live_start_p (df
, bb
, reg
)
3057 struct df
*df ATTRIBUTE_UNUSED
;
3061 struct bb_info
*bb_info
= DF_BB_INFO (df
, bb
);
3063 #ifdef ENABLE_CHECKING
3064 if (! bb_info
->lr_in
)
3068 return bitmap_bit_p (bb_info
->lr_in
, REGNO (reg
));
3072 /* Return nonzero if REG live at end of BB. */
3074 df_bb_reg_live_end_p (df
, bb
, reg
)
3075 struct df
*df ATTRIBUTE_UNUSED
;
3079 struct bb_info
*bb_info
= DF_BB_INFO (df
, bb
);
3081 #ifdef ENABLE_CHECKING
3082 if (! bb_info
->lr_in
)
3086 return bitmap_bit_p (bb_info
->lr_out
, REGNO (reg
));
3090 /* Return -1 if life of REG1 before life of REG2, 1 if life of REG1
3091 after life of REG2, or 0, if the lives overlap. */
3093 df_bb_regs_lives_compare (df
, bb
, reg1
, reg2
)
3099 unsigned int regno1
= REGNO (reg1
);
3100 unsigned int regno2
= REGNO (reg2
);
3107 /* The regs must be local to BB. */
3108 if (df_regno_bb (df
, regno1
) != bb
3109 || df_regno_bb (df
, regno2
) != bb
)
3112 def2
= df_bb_regno_first_def_find (df
, bb
, regno2
);
3113 use1
= df_bb_regno_last_use_find (df
, bb
, regno1
);
3115 if (DF_INSN_LUID (df
, DF_REF_INSN (def2
))
3116 > DF_INSN_LUID (df
, DF_REF_INSN (use1
)))
3119 def1
= df_bb_regno_first_def_find (df
, bb
, regno1
);
3120 use2
= df_bb_regno_last_use_find (df
, bb
, regno2
);
3122 if (DF_INSN_LUID (df
, DF_REF_INSN (def1
))
3123 > DF_INSN_LUID (df
, DF_REF_INSN (use2
)))
3130 /* Return last use of REGNO within BB. */
3132 df_bb_regno_last_use_find (df
, bb
, regno
)
3134 basic_block bb ATTRIBUTE_UNUSED
;
3137 struct df_link
*link
;
3139 /* This assumes that the reg-use list is ordered such that for any
3140 BB, the last use is found first. However, since the BBs are not
3141 ordered, the first use in the chain is not necessarily the last
3142 use in the function. */
3143 for (link
= df
->regs
[regno
].uses
; link
; link
= link
->next
)
3145 struct ref
*use
= link
->ref
;
3147 if (DF_REF_BB (use
) == bb
)
3154 /* Return first def of REGNO within BB. */
3156 df_bb_regno_first_def_find (df
, bb
, regno
)
3158 basic_block bb ATTRIBUTE_UNUSED
;
3161 struct df_link
*link
;
3163 /* This assumes that the reg-def list is ordered such that for any
3164 BB, the first def is found first. However, since the BBs are not
3165 ordered, the first def in the chain is not necessarily the first
3166 def in the function. */
3167 for (link
= df
->regs
[regno
].defs
; link
; link
= link
->next
)
3169 struct ref
*def
= link
->ref
;
3171 if (DF_REF_BB (def
) == bb
)
3178 /* Return first use of REGNO inside INSN within BB. */
3180 df_bb_insn_regno_last_use_find (df
, bb
, insn
, regno
)
3182 basic_block bb ATTRIBUTE_UNUSED
;
3187 struct df_link
*link
;
3189 uid
= INSN_UID (insn
);
3191 for (link
= df
->insns
[uid
].uses
; link
; link
= link
->next
)
3193 struct ref
*use
= link
->ref
;
3195 if (DF_REF_REGNO (use
) == regno
)
3203 /* Return first def of REGNO inside INSN within BB. */
3205 df_bb_insn_regno_first_def_find (df
, bb
, insn
, regno
)
3207 basic_block bb ATTRIBUTE_UNUSED
;
3212 struct df_link
*link
;
3214 uid
= INSN_UID (insn
);
3216 for (link
= df
->insns
[uid
].defs
; link
; link
= link
->next
)
3218 struct ref
*def
= link
->ref
;
3220 if (DF_REF_REGNO (def
) == regno
)
3228 /* Return insn using REG if the BB contains only a single
3229 use and def of REG. */
3231 df_bb_single_def_use_insn_find (df
, bb
, insn
, reg
)
3239 struct df_link
*du_link
;
3241 def
= df_bb_insn_regno_first_def_find (df
, bb
, insn
, REGNO (reg
));
3246 du_link
= DF_REF_CHAIN (def
);
3253 /* Check if def is dead. */
3257 /* Check for multiple uses. */
3261 return DF_REF_INSN (use
);
3264 /* Functions for debugging/dumping dataflow information. */
3267 /* Dump a def-use or use-def chain for REF to FILE. */
3269 df_chain_dump (link
, file
)
3270 struct df_link
*link
;
3273 fprintf (file
, "{ ");
3274 for (; link
; link
= link
->next
)
3276 fprintf (file
, "%c%d ",
3277 DF_REF_REG_DEF_P (link
->ref
) ? 'd' : 'u',
3278 DF_REF_ID (link
->ref
));
3280 fprintf (file
, "}");
3284 df_chain_dump_regno (link
, file
)
3285 struct df_link
*link
;
3288 fprintf (file
, "{ ");
3289 for (; link
; link
= link
->next
)
3291 fprintf (file
, "%c%d(%d) ",
3292 DF_REF_REG_DEF_P (link
->ref
) ? 'd' : 'u',
3293 DF_REF_ID (link
->ref
),
3294 DF_REF_REGNO (link
->ref
));
3296 fprintf (file
, "}");
3299 /* Dump dataflow info. */
3301 df_dump (df
, flags
, file
)
3312 fprintf (file
, "\nDataflow summary:\n");
3313 fprintf (file
, "n_regs = %d, n_defs = %d, n_uses = %d, n_bbs = %d\n",
3314 df
->n_regs
, df
->n_defs
, df
->n_uses
, df
->n_bbs
);
3320 fprintf (file
, "Reaching defs:\n");
3323 struct bb_info
*bb_info
= DF_BB_INFO (df
, bb
);
3325 if (! bb_info
->rd_in
)
3328 fprintf (file
, "bb %d in \t", bb
->index
);
3329 dump_bitmap (file
, bb_info
->rd_in
);
3330 fprintf (file
, "bb %d gen \t", bb
->index
);
3331 dump_bitmap (file
, bb_info
->rd_gen
);
3332 fprintf (file
, "bb %d kill\t", bb
->index
);
3333 dump_bitmap (file
, bb_info
->rd_kill
);
3334 fprintf (file
, "bb %d out \t", bb
->index
);
3335 dump_bitmap (file
, bb_info
->rd_out
);
3339 if (flags
& DF_UD_CHAIN
)
3341 fprintf (file
, "Use-def chains:\n");
3342 for (j
= 0; j
< df
->n_defs
; j
++)
3346 fprintf (file
, "d%d bb %d luid %d insn %d reg %d ",
3347 j
, DF_REF_BBNO (df
->defs
[j
]),
3348 DF_INSN_LUID (df
, DF_REF_INSN (df
->defs
[j
])),
3349 DF_REF_INSN_UID (df
->defs
[j
]),
3350 DF_REF_REGNO (df
->defs
[j
]));
3351 if (df
->defs
[j
]->flags
& DF_REF_READ_WRITE
)
3352 fprintf (file
, "read/write ");
3353 df_chain_dump (DF_REF_CHAIN (df
->defs
[j
]), file
);
3354 fprintf (file
, "\n");
3361 fprintf (file
, "Reaching uses:\n");
3364 struct bb_info
*bb_info
= DF_BB_INFO (df
, bb
);
3366 if (! bb_info
->ru_in
)
3369 fprintf (file
, "bb %d in \t", bb
->index
);
3370 dump_bitmap (file
, bb_info
->ru_in
);
3371 fprintf (file
, "bb %d gen \t", bb
->index
);
3372 dump_bitmap (file
, bb_info
->ru_gen
);
3373 fprintf (file
, "bb %d kill\t", bb
->index
);
3374 dump_bitmap (file
, bb_info
->ru_kill
);
3375 fprintf (file
, "bb %d out \t", bb
->index
);
3376 dump_bitmap (file
, bb_info
->ru_out
);
3380 if (flags
& DF_DU_CHAIN
)
3382 fprintf (file
, "Def-use chains:\n");
3383 for (j
= 0; j
< df
->n_uses
; j
++)
3387 fprintf (file
, "u%d bb %d luid %d insn %d reg %d ",
3388 j
, DF_REF_BBNO (df
->uses
[j
]),
3389 DF_INSN_LUID (df
, DF_REF_INSN (df
->uses
[j
])),
3390 DF_REF_INSN_UID (df
->uses
[j
]),
3391 DF_REF_REGNO (df
->uses
[j
]));
3392 if (df
->uses
[j
]->flags
& DF_REF_READ_WRITE
)
3393 fprintf (file
, "read/write ");
3394 df_chain_dump (DF_REF_CHAIN (df
->uses
[j
]), file
);
3395 fprintf (file
, "\n");
3402 fprintf (file
, "Live regs:\n");
3405 struct bb_info
*bb_info
= DF_BB_INFO (df
, bb
);
3407 if (! bb_info
->lr_in
)
3410 fprintf (file
, "bb %d in \t", bb
->index
);
3411 dump_bitmap (file
, bb_info
->lr_in
);
3412 fprintf (file
, "bb %d use \t", bb
->index
);
3413 dump_bitmap (file
, bb_info
->lr_use
);
3414 fprintf (file
, "bb %d def \t", bb
->index
);
3415 dump_bitmap (file
, bb_info
->lr_def
);
3416 fprintf (file
, "bb %d out \t", bb
->index
);
3417 dump_bitmap (file
, bb_info
->lr_out
);
3421 if (flags
& (DF_REG_INFO
| DF_RD_CHAIN
| DF_RU_CHAIN
))
3423 struct reg_info
*reg_info
= df
->regs
;
3425 fprintf (file
, "Register info:\n");
3426 for (j
= 0; j
< df
->n_regs
; j
++)
3428 if (((flags
& DF_REG_INFO
)
3429 && (reg_info
[j
].n_uses
|| reg_info
[j
].n_defs
))
3430 || ((flags
& DF_RD_CHAIN
) && reg_info
[j
].defs
)
3431 || ((flags
& DF_RU_CHAIN
) && reg_info
[j
].uses
))
3433 fprintf (file
, "reg %d", j
);
3434 if ((flags
& DF_RD_CHAIN
) && (flags
& DF_RU_CHAIN
))
3436 basic_block bb
= df_regno_bb (df
, j
);
3439 fprintf (file
, " bb %d", bb
->index
);
3441 fprintf (file
, " bb ?");
3443 if (flags
& DF_REG_INFO
)
3445 fprintf (file
, " life %d", reg_info
[j
].lifetime
);
3448 if ((flags
& DF_REG_INFO
) || (flags
& DF_RD_CHAIN
))
3450 fprintf (file
, " defs ");
3451 if (flags
& DF_REG_INFO
)
3452 fprintf (file
, "%d ", reg_info
[j
].n_defs
);
3453 if (flags
& DF_RD_CHAIN
)
3454 df_chain_dump (reg_info
[j
].defs
, file
);
3457 if ((flags
& DF_REG_INFO
) || (flags
& DF_RU_CHAIN
))
3459 fprintf (file
, " uses ");
3460 if (flags
& DF_REG_INFO
)
3461 fprintf (file
, "%d ", reg_info
[j
].n_uses
);
3462 if (flags
& DF_RU_CHAIN
)
3463 df_chain_dump (reg_info
[j
].uses
, file
);
3466 fprintf (file
, "\n");
3470 fprintf (file
, "\n");
3475 df_insn_debug (df
, insn
, file
)
3483 uid
= INSN_UID (insn
);
3484 if (uid
>= df
->insn_size
)
3487 if (df
->insns
[uid
].defs
)
3488 bbi
= DF_REF_BBNO (df
->insns
[uid
].defs
->ref
);
3489 else if (df
->insns
[uid
].uses
)
3490 bbi
= DF_REF_BBNO (df
->insns
[uid
].uses
->ref
);
3494 fprintf (file
, "insn %d bb %d luid %d defs ",
3495 uid
, bbi
, DF_INSN_LUID (df
, insn
));
3496 df_chain_dump (df
->insns
[uid
].defs
, file
);
3497 fprintf (file
, " uses ");
3498 df_chain_dump (df
->insns
[uid
].uses
, file
);
3499 fprintf (file
, "\n");
3503 df_insn_debug_regno (df
, insn
, file
)
3511 uid
= INSN_UID (insn
);
3512 if (uid
>= df
->insn_size
)
3515 if (df
->insns
[uid
].defs
)
3516 bbi
= DF_REF_BBNO (df
->insns
[uid
].defs
->ref
);
3517 else if (df
->insns
[uid
].uses
)
3518 bbi
= DF_REF_BBNO (df
->insns
[uid
].uses
->ref
);
3522 fprintf (file
, "insn %d bb %d luid %d defs ",
3523 uid
, bbi
, DF_INSN_LUID (df
, insn
));
3524 df_chain_dump_regno (df
->insns
[uid
].defs
, file
);
3525 fprintf (file
, " uses ");
3526 df_chain_dump_regno (df
->insns
[uid
].uses
, file
);
3527 fprintf (file
, "\n");
3531 df_regno_debug (df
, regno
, file
)
3536 if (regno
>= df
->reg_size
)
3539 fprintf (file
, "reg %d life %d defs ",
3540 regno
, df
->regs
[regno
].lifetime
);
3541 df_chain_dump (df
->regs
[regno
].defs
, file
);
3542 fprintf (file
, " uses ");
3543 df_chain_dump (df
->regs
[regno
].uses
, file
);
3544 fprintf (file
, "\n");
3549 df_ref_debug (df
, ref
, file
)
3554 fprintf (file
, "%c%d ",
3555 DF_REF_REG_DEF_P (ref
) ? 'd' : 'u',
3557 fprintf (file
, "reg %d bb %d luid %d insn %d chain ",
3560 DF_INSN_LUID (df
, DF_REF_INSN (ref
)),
3561 INSN_UID (DF_REF_INSN (ref
)));
3562 df_chain_dump (DF_REF_CHAIN (ref
), file
);
3563 fprintf (file
, "\n");
3568 debug_df_insn (insn
)
3571 df_insn_debug (ddf
, insn
, stderr
);
3580 df_regno_debug (ddf
, REGNO (reg
), stderr
);
3585 debug_df_regno (regno
)
3588 df_regno_debug (ddf
, regno
, stderr
);
3596 df_ref_debug (ddf
, ref
, stderr
);
3601 debug_df_defno (defno
)
3604 df_ref_debug (ddf
, ddf
->defs
[defno
], stderr
);
3609 debug_df_useno (defno
)
3612 df_ref_debug (ddf
, ddf
->uses
[defno
], stderr
);
3617 debug_df_chain (link
)
3618 struct df_link
*link
;
3620 df_chain_dump (link
, stderr
);
3621 fputc ('\n', stderr
);
3624 /* Hybrid search algorithm from "Implementation Techniques for
3625 Efficient Data-Flow Analysis of Large Programs". */
3627 hybrid_search_bitmap (block
, in
, out
, gen
, kill
, dir
,
3628 conf_op
, transfun
, visited
, pending
,
3631 bitmap
*in
, *out
, *gen
, *kill
;
3632 enum df_flow_dir dir
;
3633 enum df_confluence_op conf_op
;
3634 transfer_function_bitmap transfun
;
3640 int i
= block
->index
;
3642 basic_block bb
= block
;
3643 SET_BIT (visited
, block
->index
);
3644 if (TEST_BIT (pending
, block
->index
))
3648 /* Calculate <conf_op> of predecessor_outs */
3649 bitmap_zero (in
[i
]);
3650 for (e
= bb
->pred
; e
!= 0; e
= e
->pred_next
)
3652 if (e
->src
== ENTRY_BLOCK_PTR
)
3657 bitmap_a_or_b (in
[i
], in
[i
], out
[e
->src
->index
]);
3660 bitmap_a_and_b (in
[i
], in
[i
], out
[e
->src
->index
]);
3667 /* Calculate <conf_op> of successor ins */
3668 bitmap_zero (out
[i
]);
3669 for (e
= bb
->succ
; e
!= 0; e
= e
->succ_next
)
3671 if (e
->dest
== EXIT_BLOCK_PTR
)
3676 bitmap_a_or_b (out
[i
], out
[i
], in
[e
->dest
->index
]);
3679 bitmap_a_and_b (out
[i
], out
[i
], in
[e
->dest
->index
]);
3685 (*transfun
)(i
, &changed
, in
[i
], out
[i
], gen
[i
], kill
[i
], data
);
3686 RESET_BIT (pending
, i
);
3691 for (e
= bb
->succ
; e
!= 0; e
= e
->succ_next
)
3693 if (e
->dest
== EXIT_BLOCK_PTR
|| e
->dest
->index
== i
)
3695 SET_BIT (pending
, e
->dest
->index
);
3700 for (e
= bb
->pred
; e
!= 0; e
= e
->pred_next
)
3702 if (e
->src
== ENTRY_BLOCK_PTR
|| e
->dest
->index
== i
)
3704 SET_BIT (pending
, e
->src
->index
);
3711 for (e
= bb
->succ
; e
!= 0; e
= e
->succ_next
)
3713 if (e
->dest
== EXIT_BLOCK_PTR
|| e
->dest
->index
== i
)
3715 if (!TEST_BIT (visited
, e
->dest
->index
))
3716 hybrid_search_bitmap (e
->dest
, in
, out
, gen
, kill
, dir
,
3717 conf_op
, transfun
, visited
, pending
,
3723 for (e
= bb
->pred
; e
!= 0; e
= e
->pred_next
)
3725 if (e
->src
== ENTRY_BLOCK_PTR
|| e
->src
->index
== i
)
3727 if (!TEST_BIT (visited
, e
->src
->index
))
3728 hybrid_search_bitmap (e
->src
, in
, out
, gen
, kill
, dir
,
3729 conf_op
, transfun
, visited
, pending
,
3736 /* Hybrid search for sbitmaps, rather than bitmaps. */
3738 hybrid_search_sbitmap (block
, in
, out
, gen
, kill
, dir
,
3739 conf_op
, transfun
, visited
, pending
,
3742 sbitmap
*in
, *out
, *gen
, *kill
;
3743 enum df_flow_dir dir
;
3744 enum df_confluence_op conf_op
;
3745 transfer_function_sbitmap transfun
;
3751 int i
= block
->index
;
3753 basic_block bb
= block
;
3754 SET_BIT (visited
, block
->index
);
3755 if (TEST_BIT (pending
, block
->index
))
3759 /* Calculate <conf_op> of predecessor_outs */
3760 sbitmap_zero (in
[i
]);
3761 for (e
= bb
->pred
; e
!= 0; e
= e
->pred_next
)
3763 if (e
->src
== ENTRY_BLOCK_PTR
)
3768 sbitmap_a_or_b (in
[i
], in
[i
], out
[e
->src
->index
]);
3771 sbitmap_a_and_b (in
[i
], in
[i
], out
[e
->src
->index
]);
3778 /* Calculate <conf_op> of successor ins */
3779 sbitmap_zero (out
[i
]);
3780 for (e
= bb
->succ
; e
!= 0; e
= e
->succ_next
)
3782 if (e
->dest
== EXIT_BLOCK_PTR
)
3787 sbitmap_a_or_b (out
[i
], out
[i
], in
[e
->dest
->index
]);
3790 sbitmap_a_and_b (out
[i
], out
[i
], in
[e
->dest
->index
]);
3796 (*transfun
)(i
, &changed
, in
[i
], out
[i
], gen
[i
], kill
[i
], data
);
3797 RESET_BIT (pending
, i
);
3802 for (e
= bb
->succ
; e
!= 0; e
= e
->succ_next
)
3804 if (e
->dest
== EXIT_BLOCK_PTR
|| e
->dest
->index
== i
)
3806 SET_BIT (pending
, e
->dest
->index
);
3811 for (e
= bb
->pred
; e
!= 0; e
= e
->pred_next
)
3813 if (e
->src
== ENTRY_BLOCK_PTR
|| e
->dest
->index
== i
)
3815 SET_BIT (pending
, e
->src
->index
);
3822 for (e
= bb
->succ
; e
!= 0; e
= e
->succ_next
)
3824 if (e
->dest
== EXIT_BLOCK_PTR
|| e
->dest
->index
== i
)
3826 if (!TEST_BIT (visited
, e
->dest
->index
))
3827 hybrid_search_sbitmap (e
->dest
, in
, out
, gen
, kill
, dir
,
3828 conf_op
, transfun
, visited
, pending
,
3834 for (e
= bb
->pred
; e
!= 0; e
= e
->pred_next
)
3836 if (e
->src
== ENTRY_BLOCK_PTR
|| e
->src
->index
== i
)
3838 if (!TEST_BIT (visited
, e
->src
->index
))
3839 hybrid_search_sbitmap (e
->src
, in
, out
, gen
, kill
, dir
,
3840 conf_op
, transfun
, visited
, pending
,
3851 in, out = Filled in by function.
3852 blocks = Blocks to analyze.
3853 dir = Dataflow direction.
3854 conf_op = Confluence operation.
3855 transfun = Transfer function.
3856 order = Order to iterate in. (Should map block numbers -> order)
3857 data = Whatever you want. It's passed to the transfer function.
3859 This function will perform iterative bitvector dataflow, producing
3860 the in and out sets. Even if you only want to perform it for a
3861 small number of blocks, the vectors for in and out must be large
3862 enough for *all* blocks, because changing one block might affect
3863 others. However, it'll only put what you say to analyze on the
3866 For forward problems, you probably want to pass in a mapping of
3867 block number to rc_order (like df->inverse_rc_map).
3870 iterative_dataflow_sbitmap (in
, out
, gen
, kill
, blocks
,
3871 dir
, conf_op
, transfun
, order
, data
)
3872 sbitmap
*in
, *out
, *gen
, *kill
;
3874 enum df_flow_dir dir
;
3875 enum df_confluence_op conf_op
;
3876 transfer_function_sbitmap transfun
;
3883 sbitmap visited
, pending
;
3884 pending
= sbitmap_alloc (last_basic_block
);
3885 visited
= sbitmap_alloc (last_basic_block
);
3886 sbitmap_zero (pending
);
3887 sbitmap_zero (visited
);
3888 worklist
= fibheap_new ();
3889 EXECUTE_IF_SET_IN_BITMAP (blocks
, 0, i
,
3891 fibheap_insert (worklist
, order
[i
], (void *) (size_t) i
);
3892 SET_BIT (pending
, i
);
3894 sbitmap_copy (out
[i
], gen
[i
]);
3896 sbitmap_copy (in
[i
], gen
[i
]);
3898 while (sbitmap_first_set_bit (pending
) != -1)
3900 while (!fibheap_empty (worklist
))
3902 i
= (size_t) fibheap_extract_min (worklist
);
3903 bb
= BASIC_BLOCK (i
);
3904 if (!TEST_BIT (visited
, bb
->index
))
3905 hybrid_search_sbitmap (bb
, in
, out
, gen
, kill
, dir
,
3906 conf_op
, transfun
, visited
, pending
, data
);
3908 if (sbitmap_first_set_bit (pending
) != -1)
3910 EXECUTE_IF_SET_IN_BITMAP (blocks
, 0, i
,
3912 fibheap_insert (worklist
, order
[i
], (void *) (size_t) i
);
3914 sbitmap_zero (visited
);
3921 sbitmap_free (pending
);
3922 sbitmap_free (visited
);
3923 fibheap_delete (worklist
);
3926 /* Exactly the same as iterative_dataflow_sbitmap, except it works on
3929 iterative_dataflow_bitmap (in
, out
, gen
, kill
, blocks
,
3930 dir
, conf_op
, transfun
, order
, data
)
3931 bitmap
*in
, *out
, *gen
, *kill
;
3933 enum df_flow_dir dir
;
3934 enum df_confluence_op conf_op
;
3935 transfer_function_bitmap transfun
;
3942 sbitmap visited
, pending
;
3943 pending
= sbitmap_alloc (last_basic_block
);
3944 visited
= sbitmap_alloc (last_basic_block
);
3945 sbitmap_zero (pending
);
3946 sbitmap_zero (visited
);
3947 worklist
= fibheap_new ();
3948 EXECUTE_IF_SET_IN_BITMAP (blocks
, 0, i
,
3950 fibheap_insert (worklist
, order
[i
], (void *) (size_t) i
);
3951 SET_BIT (pending
, i
);
3953 bitmap_copy (out
[i
], gen
[i
]);
3955 bitmap_copy (in
[i
], gen
[i
]);
3957 while (sbitmap_first_set_bit (pending
) != -1)
3959 while (!fibheap_empty (worklist
))
3961 i
= (size_t) fibheap_extract_min (worklist
);
3962 bb
= BASIC_BLOCK (i
);
3963 if (!TEST_BIT (visited
, bb
->index
))
3964 hybrid_search_bitmap (bb
, in
, out
, gen
, kill
, dir
,
3965 conf_op
, transfun
, visited
, pending
, data
);
3967 if (sbitmap_first_set_bit (pending
) != -1)
3969 EXECUTE_IF_SET_IN_BITMAP (blocks
, 0, i
,
3971 fibheap_insert (worklist
, order
[i
], (void *) (size_t) i
);
3973 sbitmap_zero (visited
);
3980 sbitmap_free (pending
);
3981 sbitmap_free (visited
);
3982 fibheap_delete (worklist
);