* config/pa/linux-atomic.c (__kernel_cmpxchg): Reorder arguments to
[official-gcc.git] / gcc / tree-ssa-scopedtables.c
blob4c3e04360649f428b1cf1e905794740a14131b80
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 "symtab.h"
26 #include "tree.h"
27 #include "tree-pretty-print.h"
28 #include "tree-pass.h"
29 #include "tree-ssa-scopedtables.h"
30 #include "tree-ssa-threadedge.h"
32 const_and_copies::const_and_copies (FILE *file, int flags)
34 stack.create (20);
35 dump_file = file;
36 dump_flags = flags;
39 /* Pop entries off the stack until we hit the NULL marker.
40 For each entry popped, use the SRC/DEST pair to restore
41 SRC to its prior value. */
43 void
44 const_and_copies::pop_to_marker (void)
46 while (stack.length () > 0)
48 tree prev_value, dest;
50 dest = stack.pop ();
52 /* A NULL value indicates we should stop unwinding, otherwise
53 pop off the next entry as they're recorded in pairs. */
54 if (dest == NULL)
55 break;
57 if (dump_file && (dump_flags & TDF_DETAILS))
59 fprintf (dump_file, "<<<< COPY ");
60 print_generic_expr (dump_file, dest, 0);
61 fprintf (dump_file, " = ");
62 print_generic_expr (dump_file, SSA_NAME_VALUE (dest), 0);
63 fprintf (dump_file, "\n");
66 prev_value = stack.pop ();
67 set_ssa_name_value (dest, prev_value);
71 /* Record that X has the value Y. */
73 void
74 const_and_copies::record_const_or_copy (tree x, tree y)
76 record_const_or_copy (x, y, SSA_NAME_VALUE (x));
79 /* Record that X has the value Y and that X's previous value is PREV_X. */
81 void
82 const_and_copies::record_const_or_copy (tree x, tree y, tree prev_x)
84 /* Y may be NULL if we are invalidating entries in the table. */
85 if (y && TREE_CODE (y) == SSA_NAME)
87 tree tmp = SSA_NAME_VALUE (y);
88 y = tmp ? tmp : y;
91 if (dump_file && (dump_flags & TDF_DETAILS))
93 fprintf (dump_file, "0>>> COPY ");
94 print_generic_expr (dump_file, x, 0);
95 fprintf (dump_file, " = ");
96 print_generic_expr (dump_file, y, 0);
97 fprintf (dump_file, "\n");
100 set_ssa_name_value (x, y);
101 stack.reserve (2);
102 stack.quick_push (prev_x);
103 stack.quick_push (x);
106 /* A new value has been assigned to LHS. If necessary, invalidate any
107 equivalences that are no longer valid. This includes invaliding
108 LHS and any objects that are currently equivalent to LHS.
110 Finding the objects that are currently marked as equivalent to LHS
111 is a bit tricky. We could walk the ssa names and see if any have
112 SSA_NAME_VALUE that is the same as LHS. That's expensive.
114 However, it's far more efficient to look at the unwinding stack as
115 that will have all context sensitive equivalences which are the only
116 ones that we really have to worry about here. */
117 void
118 const_and_copies::invalidate (tree lhs)
121 /* The stack is an unwinding stack. If the current element is NULL
122 then it's a "stop unwinding" marker. Else the current marker is
123 the SSA_NAME with an equivalence and the prior entry in the stack
124 is what the current element is equivalent to. */
125 for (int i = stack.length() - 1; i >= 0; i--)
127 /* Ignore the stop unwinding markers. */
128 if ((stack)[i] == NULL)
129 continue;
131 /* We want to check the current value of stack[i] to see if
132 it matches LHS. If so, then invalidate. */
133 if (SSA_NAME_VALUE ((stack)[i]) == lhs)
134 record_const_or_copy ((stack)[i], NULL_TREE);
136 /* Remember, we're dealing with two elements in this case. */
137 i--;
140 /* And invalidate any known value for LHS itself. */
141 if (SSA_NAME_VALUE (lhs))
142 record_const_or_copy (lhs, NULL_TREE);