]>
Commit | Line | Data |
---|---|---|
48e1416a | 1 | /* Initialization of uninitialized regs. |
f1717362 | 2 | Copyright (C) 2007-2016 Free Software Foundation, Inc. |
3072d30e | 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 | |
8c4c00c1 | 8 | Software Foundation; either version 3, or (at your option) any later |
3072d30e | 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 | |
8c4c00c1 | 17 | along with GCC; see the file COPYING3. If not see |
18 | <http://www.gnu.org/licenses/>. */ | |
3072d30e | 19 | |
20 | #include "config.h" | |
21 | #include "system.h" | |
22 | #include "coretypes.h" | |
9ef16211 | 23 | #include "backend.h" |
3072d30e | 24 | #include "rtl.h" |
7c29e30e | 25 | #include "tree.h" |
9ef16211 | 26 | #include "df.h" |
7c29e30e | 27 | #include "emit-rtl.h" |
3072d30e | 28 | #include "expr.h" |
29 | #include "tree-pass.h" | |
3072d30e | 30 | |
31 | /* Check all of the uses of pseudo variables. If any use that is MUST | |
32 | uninitialized, add a store of 0 immediately before it. For | |
33 | subregs, this makes combine happy. For full word regs, this makes | |
34 | other optimizations, like the register allocator and the reg-stack | |
35 | happy as well as papers over some problems on the arm and other | |
36 | processors where certain isa constraints cannot be handled by gcc. | |
37 | These are of the form where two operands to an insn my not be the | |
38 | same. The ra will only make them the same if they do not | |
39 | interfere, and this can only happen if one is not initialized. | |
40 | ||
41 | There is also the unfortunate consequence that this may mask some | |
42 | buggy programs where people forget to initialize stack variable. | |
43 | Any programmer with half a brain would look at the uninitialized | |
44 | variable warnings. */ | |
45 | ||
46 | static void | |
47 | initialize_uninitialized_regs (void) | |
48 | { | |
49 | basic_block bb; | |
50 | bitmap already_genned = BITMAP_ALLOC (NULL); | |
51 | ||
deb2741b | 52 | if (optimize == 1) |
53 | { | |
54 | df_live_add_problem (); | |
55 | df_live_set_all_dirty (); | |
56 | } | |
57 | ||
3072d30e | 58 | df_analyze (); |
59 | ||
fc00614f | 60 | FOR_EACH_BB_FN (bb, cfun) |
3072d30e | 61 | { |
570df417 | 62 | rtx_insn *insn; |
3072d30e | 63 | bitmap lr = DF_LR_IN (bb); |
64 | bitmap ur = DF_LIVE_IN (bb); | |
65 | bitmap_clear (already_genned); | |
66 | ||
67 | FOR_BB_INSNS (bb, insn) | |
68 | { | |
be10bb5a | 69 | df_ref use; |
9845d120 | 70 | if (!NONDEBUG_INSN_P (insn)) |
3072d30e | 71 | continue; |
72 | ||
be10bb5a | 73 | FOR_EACH_INSN_USE (use, insn) |
3072d30e | 74 | { |
3072d30e | 75 | unsigned int regno = DF_REF_REGNO (use); |
76 | ||
77 | /* Only do this for the pseudos. */ | |
78 | if (regno < FIRST_PSEUDO_REGISTER) | |
79 | continue; | |
80 | ||
a9d8ab38 | 81 | /* Ignore pseudo PIC register. */ |
82 | if (pic_offset_table_rtx | |
83 | && regno == REGNO (pic_offset_table_rtx)) | |
84 | continue; | |
85 | ||
3072d30e | 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 | { | |
570df417 | 100 | rtx_insn *move_insn; |
3072d30e | 101 | rtx reg = DF_REF_REAL_REG (use); |
102 | ||
48e1416a | 103 | bitmap_set_bit (already_genned, regno); |
3072d30e | 104 | |
105 | start_sequence (); | |
106 | emit_move_insn (reg, CONST0_RTX (GET_MODE (reg))); | |
107 | move_insn = get_insns (); | |
108 | end_sequence (); | |
4d9a38ce | 109 | emit_insn_before (move_insn, insn); |
3072d30e | 110 | if (dump_file) |
48e1416a | 111 | fprintf (dump_file, |
112 | "adding initialization in %s of reg %d at in block %d for insn %d.\n", | |
be10bb5a | 113 | current_function_name (), regno, bb->index, |
114 | INSN_UID (insn)); | |
3072d30e | 115 | } |
116 | } | |
117 | } | |
118 | } | |
119 | ||
deb2741b | 120 | if (optimize == 1) |
dea7b504 | 121 | { |
48e1416a | 122 | if (dump_file) |
dea7b504 | 123 | df_dump (dump_file); |
124 | df_remove_problem (df_live); | |
125 | } | |
deb2741b | 126 | |
3072d30e | 127 | BITMAP_FREE (already_genned); |
128 | } | |
129 | ||
7620bc82 | 130 | namespace { |
131 | ||
132 | const pass_data pass_data_initialize_regs = | |
3072d30e | 133 | { |
cbe8bda8 | 134 | RTL_PASS, /* type */ |
135 | "init-regs", /* name */ | |
136 | OPTGROUP_NONE, /* optinfo_flags */ | |
cbe8bda8 | 137 | TV_NONE, /* tv_id */ |
138 | 0, /* properties_required */ | |
139 | 0, /* properties_provided */ | |
140 | 0, /* properties_destroyed */ | |
141 | 0, /* todo_flags_start */ | |
142 | TODO_df_finish, /* todo_flags_finish */ | |
3072d30e | 143 | }; |
cbe8bda8 | 144 | |
7620bc82 | 145 | class pass_initialize_regs : public rtl_opt_pass |
cbe8bda8 | 146 | { |
147 | public: | |
9af5ce0c | 148 | pass_initialize_regs (gcc::context *ctxt) |
149 | : rtl_opt_pass (pass_data_initialize_regs, ctxt) | |
cbe8bda8 | 150 | {} |
151 | ||
152 | /* opt_pass methods: */ | |
31315c24 | 153 | virtual bool gate (function *) { return optimize > 0; } |
65b0537f | 154 | virtual unsigned int execute (function *) |
155 | { | |
156 | initialize_uninitialized_regs (); | |
157 | return 0; | |
158 | } | |
cbe8bda8 | 159 | |
160 | }; // class pass_initialize_regs | |
161 | ||
7620bc82 | 162 | } // anon namespace |
163 | ||
cbe8bda8 | 164 | rtl_opt_pass * |
165 | make_pass_initialize_regs (gcc::context *ctxt) | |
166 | { | |
167 | return new pass_initialize_regs (ctxt); | |
168 | } |