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