* config/msp430/msp430.c (msp430_asm_integer): Support addition
[official-gcc.git] / gcc / init-regs.c
blob9c41574c3180170db5fdc78a475896df542b536e
1 /* Initialization of uninitialized regs.
2 Copyright (C) 2007-2015 Free Software Foundation, Inc.
4 This file is part of GCC.
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
8 Software Foundation; either version 3, or (at your option) any later
9 version.
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.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "tm.h"
24 #include "hash-set.h"
25 #include "vec.h"
26 #include "input.h"
27 #include "alias.h"
28 #include "symtab.h"
29 #include "inchash.h"
30 #include "tree.h"
31 #include "rtl.h"
32 #include "regs.h"
33 #include "hashtab.h"
34 #include "hard-reg-set.h"
35 #include "function.h"
36 #include "flags.h"
37 #include "statistics.h"
38 #include "insn-config.h"
39 #include "expmed.h"
40 #include "dojump.h"
41 #include "explow.h"
42 #include "calls.h"
43 #include "emit-rtl.h"
44 #include "varasm.h"
45 #include "stmt.h"
46 #include "expr.h"
47 #include "tree-pass.h"
48 #include "predict.h"
49 #include "dominance.h"
50 #include "cfg.h"
51 #include "basic-block.h"
52 #include "df.h"
54 /* Check all of the uses of pseudo variables. If any use that is MUST
55 uninitialized, add a store of 0 immediately before it. For
56 subregs, this makes combine happy. For full word regs, this makes
57 other optimizations, like the register allocator and the reg-stack
58 happy as well as papers over some problems on the arm and other
59 processors where certain isa constraints cannot be handled by gcc.
60 These are of the form where two operands to an insn my not be the
61 same. The ra will only make them the same if they do not
62 interfere, and this can only happen if one is not initialized.
64 There is also the unfortunate consequence that this may mask some
65 buggy programs where people forget to initialize stack variable.
66 Any programmer with half a brain would look at the uninitialized
67 variable warnings. */
69 static void
70 initialize_uninitialized_regs (void)
72 basic_block bb;
73 bitmap already_genned = BITMAP_ALLOC (NULL);
75 if (optimize == 1)
77 df_live_add_problem ();
78 df_live_set_all_dirty ();
81 df_analyze ();
83 FOR_EACH_BB_FN (bb, cfun)
85 rtx_insn *insn;
86 bitmap lr = DF_LR_IN (bb);
87 bitmap ur = DF_LIVE_IN (bb);
88 bitmap_clear (already_genned);
90 FOR_BB_INSNS (bb, insn)
92 df_ref use;
93 if (!NONDEBUG_INSN_P (insn))
94 continue;
96 FOR_EACH_INSN_USE (use, insn)
98 unsigned int regno = DF_REF_REGNO (use);
100 /* Only do this for the pseudos. */
101 if (regno < FIRST_PSEUDO_REGISTER)
102 continue;
104 /* Ignore pseudo PIC register. */
105 if (pic_offset_table_rtx
106 && regno == REGNO (pic_offset_table_rtx))
107 continue;
109 /* Do not generate multiple moves for the same regno.
110 This is common for sequences of subreg operations.
111 They would be deleted during combine but there is no
112 reason to churn the system. */
113 if (bitmap_bit_p (already_genned, regno))
114 continue;
116 /* A use is MUST uninitialized if it reaches the top of
117 the block from the inside of the block (the lr test)
118 and no def for it reaches the top of the block from
119 outside of the block (the ur test). */
120 if (bitmap_bit_p (lr, regno)
121 && (!bitmap_bit_p (ur, regno)))
123 rtx_insn *move_insn;
124 rtx reg = DF_REF_REAL_REG (use);
126 bitmap_set_bit (already_genned, regno);
128 start_sequence ();
129 emit_move_insn (reg, CONST0_RTX (GET_MODE (reg)));
130 move_insn = get_insns ();
131 end_sequence ();
132 emit_insn_before (move_insn, insn);
133 if (dump_file)
134 fprintf (dump_file,
135 "adding initialization in %s of reg %d at in block %d for insn %d.\n",
136 current_function_name (), regno, bb->index,
137 INSN_UID (insn));
143 if (optimize == 1)
145 if (dump_file)
146 df_dump (dump_file);
147 df_remove_problem (df_live);
150 BITMAP_FREE (already_genned);
153 namespace {
155 const pass_data pass_data_initialize_regs =
157 RTL_PASS, /* type */
158 "init-regs", /* name */
159 OPTGROUP_NONE, /* optinfo_flags */
160 TV_NONE, /* tv_id */
161 0, /* properties_required */
162 0, /* properties_provided */
163 0, /* properties_destroyed */
164 0, /* todo_flags_start */
165 TODO_df_finish, /* todo_flags_finish */
168 class pass_initialize_regs : public rtl_opt_pass
170 public:
171 pass_initialize_regs (gcc::context *ctxt)
172 : rtl_opt_pass (pass_data_initialize_regs, ctxt)
175 /* opt_pass methods: */
176 virtual bool gate (function *) { return optimize > 0; }
177 virtual unsigned int execute (function *)
179 initialize_uninitialized_regs ();
180 return 0;
183 }; // class pass_initialize_regs
185 } // anon namespace
187 rtl_opt_pass *
188 make_pass_initialize_regs (gcc::context *ctxt)
190 return new pass_initialize_regs (ctxt);