Mercurial > hg > graal-compiler
annotate graal/GraalCompiler/src/com/sun/c1x/ir/Convert.java @ 2805:c3f64b66fc78
Towards removing the next pointer from Constant and ArithmeticOp
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Fri, 27 May 2011 19:57:56 +0200 |
parents | 092e628ddd5d |
children | 5526d82388be |
rev | line source |
---|---|
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
1 /* |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
2 * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
4 * |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
8 * |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
13 * accompanied this code). |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
14 * |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
18 * |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
21 * questions. |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
22 */ |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
23 package com.sun.c1x.ir; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
24 |
2594
092e628ddd5d
changed Constant and Convert, more StoreIndexed changes
Lukas Stadler <lukas.stadler@jku.at>
parents:
2509
diff
changeset
|
25 import com.oracle.graal.graph.*; |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
26 import com.sun.c1x.debug.*; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
27 import com.sun.c1x.util.*; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
28 import com.sun.cri.bytecode.*; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
29 import com.sun.cri.ci.*; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
30 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
31 /** |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
32 * The {@code Convert} class represents a conversion between primitive types. |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
33 */ |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
34 public final class Convert extends Instruction { |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
35 |
2594
092e628ddd5d
changed Constant and Convert, more StoreIndexed changes
Lukas Stadler <lukas.stadler@jku.at>
parents:
2509
diff
changeset
|
36 private static final int INPUT_COUNT = 1; |
092e628ddd5d
changed Constant and Convert, more StoreIndexed changes
Lukas Stadler <lukas.stadler@jku.at>
parents:
2509
diff
changeset
|
37 private static final int INPUT_VALUE = 0; |
092e628ddd5d
changed Constant and Convert, more StoreIndexed changes
Lukas Stadler <lukas.stadler@jku.at>
parents:
2509
diff
changeset
|
38 |
092e628ddd5d
changed Constant and Convert, more StoreIndexed changes
Lukas Stadler <lukas.stadler@jku.at>
parents:
2509
diff
changeset
|
39 private static final int SUCCESSOR_COUNT = 0; |
092e628ddd5d
changed Constant and Convert, more StoreIndexed changes
Lukas Stadler <lukas.stadler@jku.at>
parents:
2509
diff
changeset
|
40 |
092e628ddd5d
changed Constant and Convert, more StoreIndexed changes
Lukas Stadler <lukas.stadler@jku.at>
parents:
2509
diff
changeset
|
41 @Override |
092e628ddd5d
changed Constant and Convert, more StoreIndexed changes
Lukas Stadler <lukas.stadler@jku.at>
parents:
2509
diff
changeset
|
42 protected int inputCount() { |
092e628ddd5d
changed Constant and Convert, more StoreIndexed changes
Lukas Stadler <lukas.stadler@jku.at>
parents:
2509
diff
changeset
|
43 return super.inputCount() + INPUT_COUNT; |
092e628ddd5d
changed Constant and Convert, more StoreIndexed changes
Lukas Stadler <lukas.stadler@jku.at>
parents:
2509
diff
changeset
|
44 } |
092e628ddd5d
changed Constant and Convert, more StoreIndexed changes
Lukas Stadler <lukas.stadler@jku.at>
parents:
2509
diff
changeset
|
45 |
092e628ddd5d
changed Constant and Convert, more StoreIndexed changes
Lukas Stadler <lukas.stadler@jku.at>
parents:
2509
diff
changeset
|
46 @Override |
092e628ddd5d
changed Constant and Convert, more StoreIndexed changes
Lukas Stadler <lukas.stadler@jku.at>
parents:
2509
diff
changeset
|
47 protected int successorCount() { |
092e628ddd5d
changed Constant and Convert, more StoreIndexed changes
Lukas Stadler <lukas.stadler@jku.at>
parents:
2509
diff
changeset
|
48 return super.successorCount() + SUCCESSOR_COUNT; |
092e628ddd5d
changed Constant and Convert, more StoreIndexed changes
Lukas Stadler <lukas.stadler@jku.at>
parents:
2509
diff
changeset
|
49 } |
092e628ddd5d
changed Constant and Convert, more StoreIndexed changes
Lukas Stadler <lukas.stadler@jku.at>
parents:
2509
diff
changeset
|
50 |
092e628ddd5d
changed Constant and Convert, more StoreIndexed changes
Lukas Stadler <lukas.stadler@jku.at>
parents:
2509
diff
changeset
|
51 /** |
092e628ddd5d
changed Constant and Convert, more StoreIndexed changes
Lukas Stadler <lukas.stadler@jku.at>
parents:
2509
diff
changeset
|
52 * The instruction which produces the input value to this instruction. |
092e628ddd5d
changed Constant and Convert, more StoreIndexed changes
Lukas Stadler <lukas.stadler@jku.at>
parents:
2509
diff
changeset
|
53 */ |
092e628ddd5d
changed Constant and Convert, more StoreIndexed changes
Lukas Stadler <lukas.stadler@jku.at>
parents:
2509
diff
changeset
|
54 public Value value() { |
092e628ddd5d
changed Constant and Convert, more StoreIndexed changes
Lukas Stadler <lukas.stadler@jku.at>
parents:
2509
diff
changeset
|
55 return (Value) inputs().get(super.inputCount() + INPUT_VALUE); |
092e628ddd5d
changed Constant and Convert, more StoreIndexed changes
Lukas Stadler <lukas.stadler@jku.at>
parents:
2509
diff
changeset
|
56 } |
092e628ddd5d
changed Constant and Convert, more StoreIndexed changes
Lukas Stadler <lukas.stadler@jku.at>
parents:
2509
diff
changeset
|
57 |
092e628ddd5d
changed Constant and Convert, more StoreIndexed changes
Lukas Stadler <lukas.stadler@jku.at>
parents:
2509
diff
changeset
|
58 public Value setValue(Value n) { |
092e628ddd5d
changed Constant and Convert, more StoreIndexed changes
Lukas Stadler <lukas.stadler@jku.at>
parents:
2509
diff
changeset
|
59 return (Value) inputs().set(super.inputCount() + INPUT_VALUE, n); |
092e628ddd5d
changed Constant and Convert, more StoreIndexed changes
Lukas Stadler <lukas.stadler@jku.at>
parents:
2509
diff
changeset
|
60 } |
092e628ddd5d
changed Constant and Convert, more StoreIndexed changes
Lukas Stadler <lukas.stadler@jku.at>
parents:
2509
diff
changeset
|
61 |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
62 /** |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
63 * The opcode for this conversion operation. |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
64 */ |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
65 public final int opcode; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
66 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
67 /** |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
68 * Constructs a new Convert instance. |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
69 * @param opcode the bytecode representing the operation |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
70 * @param value the instruction producing the input value |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
71 * @param kind the result type of this instruction |
2594
092e628ddd5d
changed Constant and Convert, more StoreIndexed changes
Lukas Stadler <lukas.stadler@jku.at>
parents:
2509
diff
changeset
|
72 * @param graph |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
73 */ |
2594
092e628ddd5d
changed Constant and Convert, more StoreIndexed changes
Lukas Stadler <lukas.stadler@jku.at>
parents:
2509
diff
changeset
|
74 public Convert(int opcode, Value value, CiKind kind, Graph graph) { |
092e628ddd5d
changed Constant and Convert, more StoreIndexed changes
Lukas Stadler <lukas.stadler@jku.at>
parents:
2509
diff
changeset
|
75 super(kind, INPUT_COUNT, SUCCESSOR_COUNT, graph); |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
76 this.opcode = opcode; |
2594
092e628ddd5d
changed Constant and Convert, more StoreIndexed changes
Lukas Stadler <lukas.stadler@jku.at>
parents:
2509
diff
changeset
|
77 setValue(value); |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
78 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
79 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
80 @Override |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
81 public void accept(ValueVisitor v) { |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
82 v.visitConvert(this); |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
83 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
84 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
85 @Override |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
86 public int valueNumber() { |
2594
092e628ddd5d
changed Constant and Convert, more StoreIndexed changes
Lukas Stadler <lukas.stadler@jku.at>
parents:
2509
diff
changeset
|
87 return Util.hash1(opcode, value()); |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
88 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
89 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
90 @Override |
2805
c3f64b66fc78
Towards removing the next pointer from Constant and ArithmeticOp
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2594
diff
changeset
|
91 public boolean valueEqual(Node i) { |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
92 if (i instanceof Convert) { |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
93 Convert o = (Convert) i; |
2594
092e628ddd5d
changed Constant and Convert, more StoreIndexed changes
Lukas Stadler <lukas.stadler@jku.at>
parents:
2509
diff
changeset
|
94 return opcode == o.opcode && value() == o.value(); |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
95 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
96 return false; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
97 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
98 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
99 @Override |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
100 public void print(LogStream out) { |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
101 out.print(Bytecodes.nameOf(opcode)).print('(').print(value()).print(')'); |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
102 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
103 } |