]>
Commit | Line | Data |
---|---|---|
b8698a0f | 1 | /* Initialization of uninitialized regs. |
5624e564 | 2 | Copyright (C) 2007-2015 Free Software Foundation, Inc. |
6fb5fa3c DB |
3 | |
4 | This file is part of GCC. | |
5 | ||
6 | GCC is free software; you can redistribute it and/or modify it under | |
7 | the terms of the GNU General Public License as published by the Free | |
9dcd6f09 | 8 | Software Foundation; either version 3, or (at your option) any later |
6fb5fa3c DB |
9 | version. |
10 | ||
11 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
12 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
14 | for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
9dcd6f09 NC |
17 | along with GCC; see the file COPYING3. If not see |
18 | <http://www.gnu.org/licenses/>. */ | |
6fb5fa3c DB |
19 | |
20 | #include "config.h" | |
21 | #include "system.h" | |
22 | #include "coretypes.h" | |
23 | #include "tm.h" | |
40e23961 MC |
24 | #include "input.h" |
25 | #include "alias.h" | |
26 | #include "symtab.h" | |
6fb5fa3c DB |
27 | #include "tree.h" |
28 | #include "rtl.h" | |
29 | #include "regs.h" | |
36566b39 PK |
30 | #include "hard-reg-set.h" |
31 | #include "function.h" | |
32 | #include "flags.h" | |
36566b39 PK |
33 | #include "insn-config.h" |
34 | #include "expmed.h" | |
35 | #include "dojump.h" | |
36 | #include "explow.h" | |
37 | #include "calls.h" | |
38 | #include "emit-rtl.h" | |
39 | #include "varasm.h" | |
40 | #include "stmt.h" | |
6fb5fa3c DB |
41 | #include "expr.h" |
42 | #include "tree-pass.h" | |
60393bbc | 43 | #include "predict.h" |
60393bbc AM |
44 | #include "dominance.h" |
45 | #include "cfg.h" | |
6fb5fa3c | 46 | #include "basic-block.h" |
6fb5fa3c DB |
47 | #include "df.h" |
48 | ||
49 | /* Check all of the uses of pseudo variables. If any use that is MUST | |
50 | uninitialized, add a store of 0 immediately before it. For | |
51 | subregs, this makes combine happy. For full word regs, this makes | |
52 | other optimizations, like the register allocator and the reg-stack | |
53 | happy as well as papers over some problems on the arm and other | |
54 | processors where certain isa constraints cannot be handled by gcc. | |
55 | These are of the form where two operands to an insn my not be the | |
56 | same. The ra will only make them the same if they do not | |
57 | interfere, and this can only happen if one is not initialized. | |
58 | ||
59 | There is also the unfortunate consequence that this may mask some | |
60 | buggy programs where people forget to initialize stack variable. | |
61 | Any programmer with half a brain would look at the uninitialized | |
62 | variable warnings. */ | |
63 | ||
64 | static void | |
65 | initialize_uninitialized_regs (void) | |
66 | { | |
67 | basic_block bb; | |
68 | bitmap already_genned = BITMAP_ALLOC (NULL); | |
69 | ||
89a95777 KZ |
70 | if (optimize == 1) |
71 | { | |
72 | df_live_add_problem (); | |
73 | df_live_set_all_dirty (); | |
74 | } | |
75 | ||
6fb5fa3c DB |
76 | df_analyze (); |
77 | ||
11cd3bed | 78 | FOR_EACH_BB_FN (bb, cfun) |
6fb5fa3c | 79 | { |
44bd2006 | 80 | rtx_insn *insn; |
6fb5fa3c DB |
81 | bitmap lr = DF_LR_IN (bb); |
82 | bitmap ur = DF_LIVE_IN (bb); | |
83 | bitmap_clear (already_genned); | |
84 | ||
85 | FOR_BB_INSNS (bb, insn) | |
86 | { | |
bfac633a | 87 | df_ref use; |
b5b8b0ac | 88 | if (!NONDEBUG_INSN_P (insn)) |
6fb5fa3c DB |
89 | continue; |
90 | ||
bfac633a | 91 | FOR_EACH_INSN_USE (use, insn) |
6fb5fa3c | 92 | { |
6fb5fa3c DB |
93 | unsigned int regno = DF_REF_REGNO (use); |
94 | ||
95 | /* Only do this for the pseudos. */ | |
96 | if (regno < FIRST_PSEUDO_REGISTER) | |
97 | continue; | |
98 | ||
bcb21886 KY |
99 | /* Ignore pseudo PIC register. */ |
100 | if (pic_offset_table_rtx | |
101 | && regno == REGNO (pic_offset_table_rtx)) | |
102 | continue; | |
103 | ||
6fb5fa3c DB |
104 | /* Do not generate multiple moves for the same regno. |
105 | This is common for sequences of subreg operations. | |
106 | They would be deleted during combine but there is no | |
107 | reason to churn the system. */ | |
108 | if (bitmap_bit_p (already_genned, regno)) | |
109 | continue; | |
110 | ||
111 | /* A use is MUST uninitialized if it reaches the top of | |
112 | the block from the inside of the block (the lr test) | |
113 | and no def for it reaches the top of the block from | |
114 | outside of the block (the ur test). */ | |
115 | if (bitmap_bit_p (lr, regno) | |
116 | && (!bitmap_bit_p (ur, regno))) | |
117 | { | |
44bd2006 | 118 | rtx_insn *move_insn; |
6fb5fa3c DB |
119 | rtx reg = DF_REF_REAL_REG (use); |
120 | ||
b8698a0f | 121 | bitmap_set_bit (already_genned, regno); |
6fb5fa3c DB |
122 | |
123 | start_sequence (); | |
124 | emit_move_insn (reg, CONST0_RTX (GET_MODE (reg))); | |
125 | move_insn = get_insns (); | |
126 | end_sequence (); | |
e2d3b294 | 127 | emit_insn_before (move_insn, insn); |
6fb5fa3c | 128 | if (dump_file) |
b8698a0f L |
129 | fprintf (dump_file, |
130 | "adding initialization in %s of reg %d at in block %d for insn %d.\n", | |
bfac633a RS |
131 | current_function_name (), regno, bb->index, |
132 | INSN_UID (insn)); | |
6fb5fa3c DB |
133 | } |
134 | } | |
135 | } | |
136 | } | |
137 | ||
89a95777 | 138 | if (optimize == 1) |
ba49cb7b | 139 | { |
b8698a0f | 140 | if (dump_file) |
ba49cb7b KZ |
141 | df_dump (dump_file); |
142 | df_remove_problem (df_live); | |
143 | } | |
89a95777 | 144 | |
6fb5fa3c DB |
145 | BITMAP_FREE (already_genned); |
146 | } | |
147 | ||
27a4cd48 DM |
148 | namespace { |
149 | ||
150 | const pass_data pass_data_initialize_regs = | |
6fb5fa3c | 151 | { |
27a4cd48 DM |
152 | RTL_PASS, /* type */ |
153 | "init-regs", /* name */ | |
154 | OPTGROUP_NONE, /* optinfo_flags */ | |
27a4cd48 DM |
155 | TV_NONE, /* tv_id */ |
156 | 0, /* properties_required */ | |
157 | 0, /* properties_provided */ | |
158 | 0, /* properties_destroyed */ | |
159 | 0, /* todo_flags_start */ | |
160 | TODO_df_finish, /* todo_flags_finish */ | |
6fb5fa3c | 161 | }; |
27a4cd48 DM |
162 | |
163 | class pass_initialize_regs : public rtl_opt_pass | |
164 | { | |
165 | public: | |
c3284718 RS |
166 | pass_initialize_regs (gcc::context *ctxt) |
167 | : rtl_opt_pass (pass_data_initialize_regs, ctxt) | |
27a4cd48 DM |
168 | {} |
169 | ||
170 | /* opt_pass methods: */ | |
1a3d085c | 171 | virtual bool gate (function *) { return optimize > 0; } |
be55bfe6 TS |
172 | virtual unsigned int execute (function *) |
173 | { | |
174 | initialize_uninitialized_regs (); | |
175 | return 0; | |
176 | } | |
27a4cd48 DM |
177 | |
178 | }; // class pass_initialize_regs | |
179 | ||
180 | } // anon namespace | |
181 | ||
182 | rtl_opt_pass * | |
183 | make_pass_initialize_regs (gcc::context *ctxt) | |
184 | { | |
185 | return new pass_initialize_regs (ctxt); | |
186 | } |