Mercurial > hg > truffle
annotate graal/GraalCompiler/src/com/sun/c1x/opt/InstructionSubstituter.java @ 2653:7c8ad40c1f88
No need for stateAfter on volatile field loads.
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Wed, 11 May 2011 15:11:33 +0200 |
parents | 0f69be73d5ce |
children | 7ed72769d51a |
rev | line source |
---|---|
2532
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
1 /* |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
2 * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
4 * |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
8 * |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
13 * accompanied this code). |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
14 * |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
18 * |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
21 * questions. |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
22 */ |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
23 package com.sun.c1x.opt; |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
24 |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
25 import com.sun.c1x.ir.*; |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
26 import com.sun.c1x.value.*; |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
27 import com.sun.c1x.graph.IR; |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
28 |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
29 /** |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
30 * This class allows instructions to be substituted within an IR graph. It allows |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
31 * registering substitutions and iterates over the instructions of a program and replaces |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
32 * the occurrence of each instruction with its substitution, if it has one. |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
33 */ |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
34 public final class InstructionSubstituter implements BlockClosure, ValueClosure { |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
35 |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
36 final IR ir; |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
37 boolean hasSubstitution; |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
38 |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
39 public InstructionSubstituter(IR ir) { |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
40 this.ir = ir; |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
41 } |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
42 |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
43 public void apply(BlockBegin block) { |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
44 Instruction last = null; |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
45 if (block.exceptionHandlerStates() != null) { |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
46 for (FrameState s : block.exceptionHandlerStates()) { |
2616
3558ca7088c0
FrameState and Graphviz changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
2532
diff
changeset
|
47 s.inputValuesDo(this); |
2532
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
48 } |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
49 } |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
50 for (Instruction n = block; n != null; n = last.next()) { |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
51 n.allValuesDo(this); |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
52 if (n.subst != null && last != null) { |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
53 // this instruction has a substitution, skip it |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
54 last.resetNext(n.next()); |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
55 } else { |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
56 last = n; |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
57 } |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
58 } |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
59 } |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
60 |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
61 public void finish() { |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
62 if (hasSubstitution) { |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
63 ir.startBlock.iterateAnyOrder(this, false); |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
64 } |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
65 } |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
66 |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
67 public boolean hasSubst(Value i) { |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
68 return i.subst != null; |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
69 } |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
70 |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
71 public void setSubst(Value i, Value n) { |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
72 if (i == n) { |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
73 i.subst = null; |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
74 } else { |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
75 hasSubstitution = true; |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
76 i.subst = n; |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
77 } |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
78 } |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
79 |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
80 public Value getSubst(Value i) { |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
81 Value p = i; |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
82 while (true) { |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
83 if (p.subst == null) { |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
84 break; |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
85 } |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
86 p = p.subst; |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
87 } |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
88 return p; |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
89 } |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
90 |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
91 public Value apply(Value i) { |
2635
0f69be73d5ce
More frame state fixes.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2616
diff
changeset
|
92 if (i instanceof FrameState) { |
0f69be73d5ce
More frame state fixes.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2616
diff
changeset
|
93 FrameState state = (FrameState) i; |
0f69be73d5ce
More frame state fixes.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2616
diff
changeset
|
94 state.inputValuesDo(this); |
0f69be73d5ce
More frame state fixes.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2616
diff
changeset
|
95 } |
2532
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
96 if (i != null) { |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
97 return getSubst(i); |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
98 } |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
99 return i; |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
100 } |
3fca504f28ba
Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
101 } |