Mercurial > hg > graal-jvmci-8
comparison graal/GraalCompiler/src/com/sun/c1x/ir/UnsafeCast.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/ir/UnsafeCast.java@9ec15d6914ca |
children |
comparison
equal
deleted
inserted
replaced
2508:fea94949e0a2 | 2509:16b9a8b5ad39 |
---|---|
1 /* | |
2 * Copyright (c) 2010, 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.ir; | |
24 | |
25 import com.sun.c1x.debug.*; | |
26 import com.sun.cri.bytecode.*; | |
27 import com.sun.cri.ci.*; | |
28 import com.sun.cri.ri.*; | |
29 | |
30 /** | |
31 * The {@code UnsafeCast} instruction represents a {@link Bytecodes#UNSAFE_CAST}. | |
32 * | |
33 * @author Doug Simon | |
34 */ | |
35 public final class UnsafeCast extends Instruction { | |
36 | |
37 public final RiType toType; | |
38 | |
39 /** | |
40 * The instruction that produced the value being unsafe cast. | |
41 */ | |
42 private Value value; | |
43 | |
44 /** | |
45 * Denotes if this is a redundant cast at the machine level. That is the source | |
46 * and the destination kind are implemented by the same machine kind. | |
47 */ | |
48 public final boolean redundant; | |
49 | |
50 /** | |
51 * Creates a new UnsafeCast instruction. | |
52 * | |
53 * @param toType the the being cast to | |
54 * @param value the value being cast | |
55 */ | |
56 public UnsafeCast(RiType toType, Value value, boolean redundant) { | |
57 super(toType.kind().stackKind()); | |
58 this.toType = toType; | |
59 this.value = value; | |
60 this.redundant = redundant; | |
61 } | |
62 | |
63 /** | |
64 * Gets the first non-redundant value derived from this value. If this | |
65 * value is not {@linkplain #redundant}, then it is returned. Otherwise, | |
66 * the first value found by following {@link #value()} that is not an | |
67 * unsafe cast or is not redundant is returned. | |
68 */ | |
69 public Value nonRedundantReplacement() { | |
70 if (!redundant) { | |
71 return this; | |
72 } | |
73 if (!(value instanceof UnsafeCast)) { | |
74 return value; | |
75 } | |
76 return ((UnsafeCast) value).nonRedundantReplacement(); | |
77 } | |
78 | |
79 /** | |
80 * Gets the instruction that produced the value being unsafe cast. | |
81 */ | |
82 public Value value() { | |
83 return value; | |
84 } | |
85 | |
86 @Override | |
87 public RiType declaredType() { | |
88 return toType; | |
89 } | |
90 | |
91 @Override | |
92 public RiType exactType() { | |
93 return declaredType().exactType(); | |
94 } | |
95 | |
96 @Override | |
97 public void accept(ValueVisitor v) { | |
98 v.visitUnsafeCast(this); | |
99 } | |
100 | |
101 /** | |
102 * Iterates over the input values to this instruction. | |
103 * @param closure the closure to apply | |
104 */ | |
105 @Override | |
106 public void inputValuesDo(ValueClosure closure) { | |
107 value = closure.apply(value); | |
108 } | |
109 | |
110 @Override | |
111 public void print(LogStream out) { | |
112 out.print("unsafe_cast("). | |
113 print(value). | |
114 print(") "). | |
115 print(CiUtil.toJavaName(toType)); | |
116 } | |
117 } |