2015-05-05 Yvan Roux <yvan.roux@linaro.org>
[official-gcc.git] / gcc / tree-ssa-scopedtables.c
blobc336a902a0582751f9654ddaedb6e3a80ac38c56
1 /* Header file for SSA dominator optimizations.
2 Copyright (C) 2013-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 "hash-table.h"
24 #include "tm.h"
25 #include "hash-set.h"
26 #include "machmode.h"
27 #include "vec.h"
28 #include "double-int.h"
29 #include "input.h"
30 #include "alias.h"
31 #include "symtab.h"
32 #include "wide-int.h"
33 #include "inchash.h"
34 #include "real.h"
35 #include "tree.h"
36 #include "tree-pretty-print.h"
37 #include "tree-pass.h"
38 #include "tree-ssa-scopedtables.h"
39 #include "tree-ssa-threadedge.h"
41 const_and_copies::const_and_copies (FILE *file, int flags)
43 stack.create (20);
44 dump_file = file;
45 dump_flags = flags;
48 /* Pop entries off the stack until we hit the NULL marker.
49 For each entry popped, use the SRC/DEST pair to restore
50 SRC to its prior value. */
52 void
53 const_and_copies::pop_to_marker (void)
55 while (stack.length () > 0)
57 tree prev_value, dest;
59 dest = stack.pop ();
61 /* A NULL value indicates we should stop unwinding, otherwise
62 pop off the next entry as they're recorded in pairs. */
63 if (dest == NULL)
64 break;
66 if (dump_file && (dump_flags & TDF_DETAILS))
68 fprintf (dump_file, "<<<< COPY ");
69 print_generic_expr (dump_file, dest, 0);
70 fprintf (dump_file, " = ");
71 print_generic_expr (dump_file, SSA_NAME_VALUE (dest), 0);
72 fprintf (dump_file, "\n");
75 prev_value = stack.pop ();
76 set_ssa_name_value (dest, prev_value);
80 /* Record that X has the value Y. */
82 void
83 const_and_copies::record_const_or_copy (tree x, tree y)
85 record_const_or_copy (x, y, SSA_NAME_VALUE (x));
88 /* Record that X has the value Y and that X's previous value is PREV_X. */
90 void
91 const_and_copies::record_const_or_copy (tree x, tree y, tree prev_x)
93 /* Y may be NULL if we are invalidating entries in the table. */
94 if (y && TREE_CODE (y) == SSA_NAME)
96 tree tmp = SSA_NAME_VALUE (y);
97 y = tmp ? tmp : y;
100 if (dump_file && (dump_flags & TDF_DETAILS))
102 fprintf (dump_file, "0>>> COPY ");
103 print_generic_expr (dump_file, x, 0);
104 fprintf (dump_file, " = ");
105 print_generic_expr (dump_file, y, 0);
106 fprintf (dump_file, "\n");
109 set_ssa_name_value (x, y);
110 stack.reserve (2);
111 stack.quick_push (prev_x);
112 stack.quick_push (x);
115 /* A new value has been assigned to LHS. If necessary, invalidate any
116 equivalences that are no longer valid. This includes invaliding
117 LHS and any objects that are currently equivalent to LHS.
119 Finding the objects that are currently marked as equivalent to LHS
120 is a bit tricky. We could walk the ssa names and see if any have
121 SSA_NAME_VALUE that is the same as LHS. That's expensive.
123 However, it's far more efficient to look at the unwinding stack as
124 that will have all context sensitive equivalences which are the only
125 ones that we really have to worry about here. */
126 void
127 const_and_copies::invalidate (tree lhs)
130 /* The stack is an unwinding stack. If the current element is NULL
131 then it's a "stop unwinding" marker. Else the current marker is
132 the SSA_NAME with an equivalence and the prior entry in the stack
133 is what the current element is equivalent to. */
134 for (int i = stack.length() - 1; i >= 0; i--)
136 /* Ignore the stop unwinding markers. */
137 if ((stack)[i] == NULL)
138 continue;
140 /* We want to check the current value of stack[i] to see if
141 it matches LHS. If so, then invalidate. */
142 if (SSA_NAME_VALUE ((stack)[i]) == lhs)
143 record_const_or_copy ((stack)[i], NULL_TREE);
145 /* Remember, we're dealing with two elements in this case. */
146 i--;
149 /* And invalidate any known value for LHS itself. */
150 if (SSA_NAME_VALUE (lhs))
151 record_const_or_copy (lhs, NULL_TREE);