]>
Commit | Line | Data |
---|---|---|
6fb5fa3c DB |
1 | /* Initialization of uninitialized regs. |
2 | Copyright (C) 2007 Free Software Foundation, | |
3 | Inc. | |
4 | ||
5 | This file is part of GCC. | |
6 | ||
7 | GCC is free software; you can redistribute it and/or modify it under | |
8 | the terms of the GNU General Public License as published by the Free | |
9dcd6f09 | 9 | Software Foundation; either version 3, or (at your option) any later |
6fb5fa3c DB |
10 | version. |
11 | ||
12 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
13 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 | for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
9dcd6f09 NC |
18 | along with GCC; see the file COPYING3. If not see |
19 | <http://www.gnu.org/licenses/>. */ | |
6fb5fa3c DB |
20 | |
21 | #include "config.h" | |
22 | #include "system.h" | |
23 | #include "coretypes.h" | |
24 | #include "tm.h" | |
25 | #include "tree.h" | |
26 | #include "rtl.h" | |
27 | #include "regs.h" | |
28 | #include "expr.h" | |
29 | #include "tree-pass.h" | |
30 | #include "basic-block.h" | |
31 | #include "flags.h" | |
32 | #include "df.h" | |
33 | ||
34 | /* Check all of the uses of pseudo variables. If any use that is MUST | |
35 | uninitialized, add a store of 0 immediately before it. For | |
36 | subregs, this makes combine happy. For full word regs, this makes | |
37 | other optimizations, like the register allocator and the reg-stack | |
38 | happy as well as papers over some problems on the arm and other | |
39 | processors where certain isa constraints cannot be handled by gcc. | |
40 | These are of the form where two operands to an insn my not be the | |
41 | same. The ra will only make them the same if they do not | |
42 | interfere, and this can only happen if one is not initialized. | |
43 | ||
44 | There is also the unfortunate consequence that this may mask some | |
45 | buggy programs where people forget to initialize stack variable. | |
46 | Any programmer with half a brain would look at the uninitialized | |
47 | variable warnings. */ | |
48 | ||
49 | static void | |
50 | initialize_uninitialized_regs (void) | |
51 | { | |
52 | basic_block bb; | |
53 | bitmap already_genned = BITMAP_ALLOC (NULL); | |
54 | ||
89a95777 KZ |
55 | if (optimize == 1) |
56 | { | |
57 | df_live_add_problem (); | |
58 | df_live_set_all_dirty (); | |
59 | } | |
60 | ||
6fb5fa3c DB |
61 | df_analyze (); |
62 | ||
63 | FOR_EACH_BB (bb) | |
64 | { | |
65 | rtx insn; | |
66 | bitmap lr = DF_LR_IN (bb); | |
67 | bitmap ur = DF_LIVE_IN (bb); | |
68 | bitmap_clear (already_genned); | |
69 | ||
70 | FOR_BB_INSNS (bb, insn) | |
71 | { | |
72 | unsigned int uid = INSN_UID (insn); | |
73 | struct df_ref **use_rec; | |
74 | if (!INSN_P (insn)) | |
75 | continue; | |
76 | ||
77 | for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++) | |
78 | { | |
79 | struct df_ref *use = *use_rec; | |
80 | unsigned int regno = DF_REF_REGNO (use); | |
81 | ||
82 | /* Only do this for the pseudos. */ | |
83 | if (regno < FIRST_PSEUDO_REGISTER) | |
84 | continue; | |
85 | ||
86 | /* Do not generate multiple moves for the same regno. | |
87 | This is common for sequences of subreg operations. | |
88 | They would be deleted during combine but there is no | |
89 | reason to churn the system. */ | |
90 | if (bitmap_bit_p (already_genned, regno)) | |
91 | continue; | |
92 | ||
93 | /* A use is MUST uninitialized if it reaches the top of | |
94 | the block from the inside of the block (the lr test) | |
95 | and no def for it reaches the top of the block from | |
96 | outside of the block (the ur test). */ | |
97 | if (bitmap_bit_p (lr, regno) | |
98 | && (!bitmap_bit_p (ur, regno))) | |
99 | { | |
100 | rtx move_insn; | |
101 | rtx reg = DF_REF_REAL_REG (use); | |
102 | ||
103 | bitmap_set_bit (already_genned, regno); | |
104 | ||
105 | start_sequence (); | |
106 | emit_move_insn (reg, CONST0_RTX (GET_MODE (reg))); | |
107 | move_insn = get_insns (); | |
108 | end_sequence (); | |
e2d3b294 | 109 | emit_insn_before (move_insn, insn); |
6fb5fa3c DB |
110 | if (dump_file) |
111 | fprintf (dump_file, | |
112 | "adding initialization in %s of reg %d at in block %d for insn %d.\n", | |
113 | current_function_name (), regno, bb->index, uid); | |
114 | } | |
115 | } | |
116 | } | |
117 | } | |
118 | ||
89a95777 KZ |
119 | if (optimize == 1) |
120 | df_remove_problem (df_live); | |
121 | ||
6fb5fa3c DB |
122 | BITMAP_FREE (already_genned); |
123 | } | |
124 | ||
125 | static bool | |
126 | gate_initialize_regs (void) | |
127 | { | |
128 | return optimize > 0; | |
129 | } | |
130 | ||
131 | static unsigned int | |
132 | rest_of_handle_initialize_regs (void) | |
133 | { | |
6fb5fa3c | 134 | initialize_uninitialized_regs (); |
6fb5fa3c DB |
135 | return 0; |
136 | } | |
137 | ||
138 | struct tree_opt_pass pass_initialize_regs = | |
139 | { | |
140 | "init-regs", /* name */ | |
141 | gate_initialize_regs, /* gate */ | |
142 | rest_of_handle_initialize_regs, /* execute */ | |
143 | NULL, /* sub */ | |
144 | NULL, /* next */ | |
145 | 0, /* static_pass_number */ | |
146 | 0, /* tv_id */ | |
147 | 0, /* properties_required */ | |
148 | 0, /* properties_provided */ | |
149 | 0, /* properties_destroyed */ | |
150 | 0, /* todo_flags_start */ | |
151 | TODO_dump_func | | |
152 | TODO_df_finish, /* todo_flags_finish */ | |
153 | 0 /* letter */ | |
154 | }; |