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