fix ChangeLog entry for r227407
[official-gcc.git] / gcc / tree-ssa-scopedtables.c
blob1fea69a7967b84577bfa5d9922c38df0b8aa353c
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 "tm.h"
24 #include "alias.h"
25 #include "tree.h"
26 #include "tree-pretty-print.h"
27 #include "tree-pass.h"
28 #include "tree-ssa-scopedtables.h"
29 #include "tree-ssa-threadedge.h"
31 /* Pop entries off the stack until we hit the NULL marker.
32 For each entry popped, use the SRC/DEST pair to restore
33 SRC to its prior value. */
35 void
36 const_and_copies::pop_to_marker (void)
38 while (stack.length () > 0)
40 tree prev_value, dest;
42 dest = stack.pop ();
44 /* A NULL value indicates we should stop unwinding, otherwise
45 pop off the next entry as they're recorded in pairs. */
46 if (dest == NULL)
47 break;
49 if (dump_file && (dump_flags & TDF_DETAILS))
51 fprintf (dump_file, "<<<< COPY ");
52 print_generic_expr (dump_file, dest, 0);
53 fprintf (dump_file, " = ");
54 print_generic_expr (dump_file, SSA_NAME_VALUE (dest), 0);
55 fprintf (dump_file, "\n");
58 prev_value = stack.pop ();
59 set_ssa_name_value (dest, prev_value);
63 /* Record that X has the value Y. */
65 void
66 const_and_copies::record_const_or_copy (tree x, tree y)
68 record_const_or_copy (x, y, SSA_NAME_VALUE (x));
71 /* Record that X has the value Y and that X's previous value is PREV_X. */
73 void
74 const_and_copies::record_const_or_copy (tree x, tree y, tree prev_x)
76 /* Y may be NULL if we are invalidating entries in the table. */
77 if (y && TREE_CODE (y) == SSA_NAME)
79 tree tmp = SSA_NAME_VALUE (y);
80 y = tmp ? tmp : y;
83 if (dump_file && (dump_flags & TDF_DETAILS))
85 fprintf (dump_file, "0>>> COPY ");
86 print_generic_expr (dump_file, x, 0);
87 fprintf (dump_file, " = ");
88 print_generic_expr (dump_file, y, 0);
89 fprintf (dump_file, "\n");
92 set_ssa_name_value (x, y);
93 stack.reserve (2);
94 stack.quick_push (prev_x);
95 stack.quick_push (x);
98 /* A new value has been assigned to LHS. If necessary, invalidate any
99 equivalences that are no longer valid. This includes invaliding
100 LHS and any objects that are currently equivalent to LHS.
102 Finding the objects that are currently marked as equivalent to LHS
103 is a bit tricky. We could walk the ssa names and see if any have
104 SSA_NAME_VALUE that is the same as LHS. That's expensive.
106 However, it's far more efficient to look at the unwinding stack as
107 that will have all context sensitive equivalences which are the only
108 ones that we really have to worry about here. */
109 void
110 const_and_copies::invalidate (tree lhs)
113 /* The stack is an unwinding stack. If the current element is NULL
114 then it's a "stop unwinding" marker. Else the current marker is
115 the SSA_NAME with an equivalence and the prior entry in the stack
116 is what the current element is equivalent to. */
117 for (int i = stack.length() - 1; i >= 0; i--)
119 /* Ignore the stop unwinding markers. */
120 if ((stack)[i] == NULL)
121 continue;
123 /* We want to check the current value of stack[i] to see if
124 it matches LHS. If so, then invalidate. */
125 if (SSA_NAME_VALUE ((stack)[i]) == lhs)
126 record_const_or_copy ((stack)[i], NULL_TREE);
128 /* Remember, we're dealing with two elements in this case. */
129 i--;
132 /* And invalidate any known value for LHS itself. */
133 if (SSA_NAME_VALUE (lhs))
134 record_const_or_copy (lhs, NULL_TREE);