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