annotate graal/GraalCompiler/src/com/sun/c1x/opt/InstructionSubstituter.java @ 2616:3558ca7088c0

FrameState and Graphviz changes: * removed popx, pushx methods from GraphBuilder * FrameState subclass of Value * added String shortName() to Node * added GraphvizPrinter option to use short names * small hack in GraphvizPrinter: omit FrameState->Local connections * added GraalGraphviz to implicit classpatch (read from GRAAL env var)
author Lukas Stadler <lukas.stadler@jku.at>
date Mon, 09 May 2011 17:00:25 +0200
parents 3fca504f28ba
children 0f69be73d5ce
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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) {
3fca504f28ba Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
92 if (i != null) {
3fca504f28ba Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
93 return getSubst(i);
3fca504f28ba Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
94 }
3fca504f28ba Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
95 return i;
3fca504f28ba Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
96 }
3fca504f28ba Reinsert phi simplifier (does not seem to be optional). Disabled canonicalizer.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
97 }