]>
Commit | Line | Data |
---|---|---|
b8698a0f | 1 | /* Initialization of uninitialized regs. |
23a5b65a | 2 | Copyright (C) 2007-2014 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" | |
24 | #include "tree.h" | |
25 | #include "rtl.h" | |
26 | #include "regs.h" | |
27 | #include "expr.h" | |
28 | #include "tree-pass.h" | |
29 | #include "basic-block.h" | |
30 | #include "flags.h" | |
31 | #include "df.h" | |
32 | ||
33 | /* Check all of the uses of pseudo variables. If any use that is MUST | |
34 | uninitialized, add a store of 0 immediately before it. For | |
35 | subregs, this makes combine happy. For full word regs, this makes | |
36 | other optimizations, like the register allocator and the reg-stack | |
37 | happy as well as papers over some problems on the arm and other | |
38 | processors where certain isa constraints cannot be handled by gcc. | |
39 | These are of the form where two operands to an insn my not be the | |
40 | same. The ra will only make them the same if they do not | |
41 | interfere, and this can only happen if one is not initialized. | |
42 | ||
43 | There is also the unfortunate consequence that this may mask some | |
44 | buggy programs where people forget to initialize stack variable. | |
45 | Any programmer with half a brain would look at the uninitialized | |
46 | variable warnings. */ | |
47 | ||
48 | static void | |
49 | initialize_uninitialized_regs (void) | |
50 | { | |
51 | basic_block bb; | |
52 | bitmap already_genned = BITMAP_ALLOC (NULL); | |
53 | ||
89a95777 KZ |
54 | if (optimize == 1) |
55 | { | |
56 | df_live_add_problem (); | |
57 | df_live_set_all_dirty (); | |
58 | } | |
59 | ||
6fb5fa3c DB |
60 | df_analyze (); |
61 | ||
11cd3bed | 62 | FOR_EACH_BB_FN (bb, cfun) |
6fb5fa3c DB |
63 | { |
64 | rtx insn; | |
65 | bitmap lr = DF_LR_IN (bb); | |
66 | bitmap ur = DF_LIVE_IN (bb); | |
67 | bitmap_clear (already_genned); | |
68 | ||
69 | FOR_BB_INSNS (bb, insn) | |
70 | { | |
bfac633a | 71 | df_ref use; |
b5b8b0ac | 72 | if (!NONDEBUG_INSN_P (insn)) |
6fb5fa3c DB |
73 | continue; |
74 | ||
bfac633a | 75 | FOR_EACH_INSN_USE (use, insn) |
6fb5fa3c | 76 | { |
6fb5fa3c DB |
77 | unsigned int regno = DF_REF_REGNO (use); |
78 | ||
79 | /* Only do this for the pseudos. */ | |
80 | if (regno < FIRST_PSEUDO_REGISTER) | |
81 | continue; | |
82 | ||
83 | /* Do not generate multiple moves for the same regno. | |
84 | This is common for sequences of subreg operations. | |
85 | They would be deleted during combine but there is no | |
86 | reason to churn the system. */ | |
87 | if (bitmap_bit_p (already_genned, regno)) | |
88 | continue; | |
89 | ||
90 | /* A use is MUST uninitialized if it reaches the top of | |
91 | the block from the inside of the block (the lr test) | |
92 | and no def for it reaches the top of the block from | |
93 | outside of the block (the ur test). */ | |
94 | if (bitmap_bit_p (lr, regno) | |
95 | && (!bitmap_bit_p (ur, regno))) | |
96 | { | |
97 | rtx move_insn; | |
98 | rtx reg = DF_REF_REAL_REG (use); | |
99 | ||
b8698a0f | 100 | bitmap_set_bit (already_genned, regno); |
6fb5fa3c DB |
101 | |
102 | start_sequence (); | |
103 | emit_move_insn (reg, CONST0_RTX (GET_MODE (reg))); | |
104 | move_insn = get_insns (); | |
105 | end_sequence (); | |
e2d3b294 | 106 | emit_insn_before (move_insn, insn); |
6fb5fa3c | 107 | if (dump_file) |
b8698a0f L |
108 | fprintf (dump_file, |
109 | "adding initialization in %s of reg %d at in block %d for insn %d.\n", | |
bfac633a RS |
110 | current_function_name (), regno, bb->index, |
111 | INSN_UID (insn)); | |
6fb5fa3c DB |
112 | } |
113 | } | |
114 | } | |
115 | } | |
116 | ||
89a95777 | 117 | if (optimize == 1) |
ba49cb7b | 118 | { |
b8698a0f | 119 | if (dump_file) |
ba49cb7b KZ |
120 | df_dump (dump_file); |
121 | df_remove_problem (df_live); | |
122 | } | |
89a95777 | 123 | |
6fb5fa3c DB |
124 | BITMAP_FREE (already_genned); |
125 | } | |
126 | ||
27a4cd48 DM |
127 | namespace { |
128 | ||
129 | const pass_data pass_data_initialize_regs = | |
6fb5fa3c | 130 | { |
27a4cd48 DM |
131 | RTL_PASS, /* type */ |
132 | "init-regs", /* name */ | |
133 | OPTGROUP_NONE, /* optinfo_flags */ | |
27a4cd48 DM |
134 | TV_NONE, /* tv_id */ |
135 | 0, /* properties_required */ | |
136 | 0, /* properties_provided */ | |
137 | 0, /* properties_destroyed */ | |
138 | 0, /* todo_flags_start */ | |
139 | TODO_df_finish, /* todo_flags_finish */ | |
6fb5fa3c | 140 | }; |
27a4cd48 DM |
141 | |
142 | class pass_initialize_regs : public rtl_opt_pass | |
143 | { | |
144 | public: | |
c3284718 RS |
145 | pass_initialize_regs (gcc::context *ctxt) |
146 | : rtl_opt_pass (pass_data_initialize_regs, ctxt) | |
27a4cd48 DM |
147 | {} |
148 | ||
149 | /* opt_pass methods: */ | |
1a3d085c | 150 | virtual bool gate (function *) { return optimize > 0; } |
be55bfe6 TS |
151 | virtual unsigned int execute (function *) |
152 | { | |
153 | initialize_uninitialized_regs (); | |
154 | return 0; | |
155 | } | |
27a4cd48 DM |
156 | |
157 | }; // class pass_initialize_regs | |
158 | ||
159 | } // anon namespace | |
160 | ||
161 | rtl_opt_pass * | |
162 | make_pass_initialize_regs (gcc::context *ctxt) | |
163 | { | |
164 | return new pass_initialize_regs (ctxt); | |
165 | } |