]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/init-regs.c
Eliminate FOR_EACH_BB macro.
[thirdparty/gcc.git] / gcc / init-regs.c
CommitLineData
48e1416a 1/* Initialization of uninitialized regs.
711789cc 2 Copyright (C) 2007-2013 Free Software Foundation, Inc.
3072d30e 3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
8c4c00c1 8Software Foundation; either version 3, or (at your option) any later
3072d30e 9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for more details.
15
16You should have received a copy of the GNU General Public License
8c4c00c1 17along 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"
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
48static void
49initialize_uninitialized_regs (void)
50{
51 basic_block bb;
52 bitmap already_genned = BITMAP_ALLOC (NULL);
53
deb2741b 54 if (optimize == 1)
55 {
56 df_live_add_problem ();
57 df_live_set_all_dirty ();
58 }
59
3072d30e 60 df_analyze ();
61
fc00614f 62 FOR_EACH_BB_FN (bb, cfun)
3072d30e 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 {
71 unsigned int uid = INSN_UID (insn);
ed6e85ae 72 df_ref *use_rec;
9845d120 73 if (!NONDEBUG_INSN_P (insn))
3072d30e 74 continue;
75
76 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
77 {
ed6e85ae 78 df_ref use = *use_rec;
3072d30e 79 unsigned int regno = DF_REF_REGNO (use);
80
81 /* Only do this for the pseudos. */
82 if (regno < FIRST_PSEUDO_REGISTER)
83 continue;
84
85 /* Do not generate multiple moves for the same regno.
86 This is common for sequences of subreg operations.
87 They would be deleted during combine but there is no
88 reason to churn the system. */
89 if (bitmap_bit_p (already_genned, regno))
90 continue;
91
92 /* A use is MUST uninitialized if it reaches the top of
93 the block from the inside of the block (the lr test)
94 and no def for it reaches the top of the block from
95 outside of the block (the ur test). */
96 if (bitmap_bit_p (lr, regno)
97 && (!bitmap_bit_p (ur, regno)))
98 {
99 rtx move_insn;
100 rtx reg = DF_REF_REAL_REG (use);
101
48e1416a 102 bitmap_set_bit (already_genned, regno);
3072d30e 103
104 start_sequence ();
105 emit_move_insn (reg, CONST0_RTX (GET_MODE (reg)));
106 move_insn = get_insns ();
107 end_sequence ();
4d9a38ce 108 emit_insn_before (move_insn, insn);
3072d30e 109 if (dump_file)
48e1416a 110 fprintf (dump_file,
111 "adding initialization in %s of reg %d at in block %d for insn %d.\n",
3072d30e 112 current_function_name (), regno, bb->index, uid);
113 }
114 }
115 }
116 }
117
deb2741b 118 if (optimize == 1)
dea7b504 119 {
48e1416a 120 if (dump_file)
dea7b504 121 df_dump (dump_file);
122 df_remove_problem (df_live);
123 }
deb2741b 124
3072d30e 125 BITMAP_FREE (already_genned);
126}
127
128static bool
129gate_initialize_regs (void)
130{
131 return optimize > 0;
132}
133
134static unsigned int
135rest_of_handle_initialize_regs (void)
136{
3072d30e 137 initialize_uninitialized_regs ();
3072d30e 138 return 0;
139}
140
cbe8bda8 141namespace {
142
143const pass_data pass_data_initialize_regs =
3072d30e 144{
cbe8bda8 145 RTL_PASS, /* type */
146 "init-regs", /* name */
147 OPTGROUP_NONE, /* optinfo_flags */
148 true, /* has_gate */
149 true, /* has_execute */
150 TV_NONE, /* tv_id */
151 0, /* properties_required */
152 0, /* properties_provided */
153 0, /* properties_destroyed */
154 0, /* todo_flags_start */
155 TODO_df_finish, /* todo_flags_finish */
3072d30e 156};
cbe8bda8 157
158class pass_initialize_regs : public rtl_opt_pass
159{
160public:
9af5ce0c 161 pass_initialize_regs (gcc::context *ctxt)
162 : rtl_opt_pass (pass_data_initialize_regs, ctxt)
cbe8bda8 163 {}
164
165 /* opt_pass methods: */
166 bool gate () { return gate_initialize_regs (); }
167 unsigned int execute () { return rest_of_handle_initialize_regs (); }
168
169}; // class pass_initialize_regs
170
171} // anon namespace
172
173rtl_opt_pass *
174make_pass_initialize_regs (gcc::context *ctxt)
175{
176 return new pass_initialize_regs (ctxt);
177}