Mercurial > hg > graal-compiler
annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IntegerConvertNode.java @ 19529:8fc336a04d77
Create TYPE fields for LIRInstruction and CompositeValue. Renaming NodeClass#get to NodeClass#create.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Fri, 20 Feb 2015 22:22:55 +0100 |
parents | 880717e44675 |
children | 93c50cefb9e8 |
rev | line source |
---|---|
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
1 /* |
19403
7e2c87dae93e
Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19364
diff
changeset
|
2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
4 * |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
8 * |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
14 * |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
18 * |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
21 * questions. |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
22 */ |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
23 package com.oracle.graal.nodes.calc; |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
24 |
18646
290dc460feb3
use better types to simplify instantiation of Serializable lambdas
Doug Simon <doug.simon@oracle.com>
parents:
18188
diff
changeset
|
25 import java.io.*; |
17418
393fe459eadc
Don't cache op field in arithmetic nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
17369
diff
changeset
|
26 import java.util.function.*; |
393fe459eadc
Don't cache op field in arithmetic nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
17369
diff
changeset
|
27 |
17344
98e60bdf6d05
Use ArithmeticOpTable for primitive convert operations.
Roland Schatz <roland.schatz@oracle.com>
parents:
17328
diff
changeset
|
28 import com.oracle.graal.api.meta.*; |
17418
393fe459eadc
Don't cache op field in arithmetic nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
17369
diff
changeset
|
29 import com.oracle.graal.compiler.common.type.*; |
18646
290dc460feb3
use better types to simplify instantiation of Serializable lambdas
Doug Simon <doug.simon@oracle.com>
parents:
18188
diff
changeset
|
30 import com.oracle.graal.compiler.common.type.ArithmeticOpTable.*; |
19403
7e2c87dae93e
Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19364
diff
changeset
|
31 import com.oracle.graal.graph.*; |
17344
98e60bdf6d05
Use ArithmeticOpTable for primitive convert operations.
Roland Schatz <roland.schatz@oracle.com>
parents:
17328
diff
changeset
|
32 import com.oracle.graal.graph.spi.*; |
16841
cbd42807a31f
moved NodeInfo and friends into separate com.oracle.graal.nodeinfo project so that annotation processor can be applied to the base Node class
Doug Simon <doug.simon@oracle.com>
parents:
16811
diff
changeset
|
33 import com.oracle.graal.nodeinfo.*; |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
34 import com.oracle.graal.nodes.*; |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
35 import com.oracle.graal.nodes.spi.*; |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
36 |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
37 /** |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
38 * An {@code IntegerConvert} converts an integer to an integer of different width. |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
39 */ |
16811
5d468add216f
added @NodeInfo annotations to all Node classes
Doug Simon <doug.simon@oracle.com>
parents:
16248
diff
changeset
|
40 @NodeInfo |
17419
83c3dd41ca64
Simplify ArithmeticOpTable implementation and make it type safe.
Roland Schatz <roland.schatz@oracle.com>
parents:
17418
diff
changeset
|
41 public abstract class IntegerConvertNode<OP, REV> extends UnaryNode implements ConvertNode, ArithmeticLIRLowerable { |
19529
8fc336a04d77
Create TYPE fields for LIRInstruction and CompositeValue. Renaming NodeClass#get to NodeClass#create.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19471
diff
changeset
|
42 @SuppressWarnings("rawtypes") public static final NodeClass<IntegerConvertNode> TYPE = NodeClass.create(IntegerConvertNode.class); |
17344
98e60bdf6d05
Use ArithmeticOpTable for primitive convert operations.
Roland Schatz <roland.schatz@oracle.com>
parents:
17328
diff
changeset
|
43 |
18646
290dc460feb3
use better types to simplify instantiation of Serializable lambdas
Doug Simon <doug.simon@oracle.com>
parents:
18188
diff
changeset
|
44 protected final SerializableIntegerConvertFunction<OP> getOp; |
290dc460feb3
use better types to simplify instantiation of Serializable lambdas
Doug Simon <doug.simon@oracle.com>
parents:
18188
diff
changeset
|
45 protected final SerializableIntegerConvertFunction<REV> getReverseOp; |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
46 |
18124
689092d5cf44
Store explicit input bit width in IntegerConvertNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
17419
diff
changeset
|
47 protected final int inputBits; |
17328
c9bb0da795d4
Backed out of changeset 17322:655f3e6b467b
Doug Simon <doug.simon@oracle.com>
parents:
17327
diff
changeset
|
48 protected final int resultBits; |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
49 |
18646
290dc460feb3
use better types to simplify instantiation of Serializable lambdas
Doug Simon <doug.simon@oracle.com>
parents:
18188
diff
changeset
|
50 protected interface SerializableIntegerConvertFunction<T> extends Function<ArithmeticOpTable, IntegerConvertOp<T>>, Serializable { |
290dc460feb3
use better types to simplify instantiation of Serializable lambdas
Doug Simon <doug.simon@oracle.com>
parents:
18188
diff
changeset
|
51 } |
290dc460feb3
use better types to simplify instantiation of Serializable lambdas
Doug Simon <doug.simon@oracle.com>
parents:
18188
diff
changeset
|
52 |
19471
880717e44675
Use typed NodeClass in node constructors.
Roland Schatz <roland.schatz@oracle.com>
parents:
19410
diff
changeset
|
53 protected IntegerConvertNode(NodeClass<? extends IntegerConvertNode<OP, REV>> c, SerializableIntegerConvertFunction<OP> getOp, SerializableIntegerConvertFunction<REV> getReverseOp, int inputBits, |
880717e44675
Use typed NodeClass in node constructors.
Roland Schatz <roland.schatz@oracle.com>
parents:
19410
diff
changeset
|
54 int resultBits, ValueNode input) { |
19403
7e2c87dae93e
Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19364
diff
changeset
|
55 super(c, getOp.apply(ArithmeticOpTable.forStamp(input.stamp())).foldStamp(inputBits, resultBits, input.stamp()), input); |
17418
393fe459eadc
Don't cache op field in arithmetic nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
17369
diff
changeset
|
56 this.getOp = getOp; |
393fe459eadc
Don't cache op field in arithmetic nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
17369
diff
changeset
|
57 this.getReverseOp = getReverseOp; |
18124
689092d5cf44
Store explicit input bit width in IntegerConvertNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
17419
diff
changeset
|
58 this.inputBits = inputBits; |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
59 this.resultBits = resultBits; |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
60 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
61 |
18124
689092d5cf44
Store explicit input bit width in IntegerConvertNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
17419
diff
changeset
|
62 public int getInputBits() { |
689092d5cf44
Store explicit input bit width in IntegerConvertNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
17419
diff
changeset
|
63 return inputBits; |
689092d5cf44
Store explicit input bit width in IntegerConvertNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
17419
diff
changeset
|
64 } |
689092d5cf44
Store explicit input bit width in IntegerConvertNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
17419
diff
changeset
|
65 |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
66 public int getResultBits() { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
67 return resultBits; |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
68 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
69 |
17419
83c3dd41ca64
Simplify ArithmeticOpTable implementation and make it type safe.
Roland Schatz <roland.schatz@oracle.com>
parents:
17418
diff
changeset
|
70 protected final IntegerConvertOp<OP> getOp(ValueNode forValue) { |
17418
393fe459eadc
Don't cache op field in arithmetic nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
17369
diff
changeset
|
71 return getOp.apply(ArithmeticOpTable.forStamp(forValue.stamp())); |
393fe459eadc
Don't cache op field in arithmetic nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
17369
diff
changeset
|
72 } |
393fe459eadc
Don't cache op field in arithmetic nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
17369
diff
changeset
|
73 |
17344
98e60bdf6d05
Use ArithmeticOpTable for primitive convert operations.
Roland Schatz <roland.schatz@oracle.com>
parents:
17328
diff
changeset
|
74 @Override |
18720
ab9d3ff6829b
Pass constant reflection into ConvertNode.convert
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18646
diff
changeset
|
75 public Constant convert(Constant c, ConstantReflectionProvider constantReflection) { |
17418
393fe459eadc
Don't cache op field in arithmetic nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
17369
diff
changeset
|
76 return getOp(getValue()).foldConstant(getInputBits(), getResultBits(), c); |
17344
98e60bdf6d05
Use ArithmeticOpTable for primitive convert operations.
Roland Schatz <roland.schatz@oracle.com>
parents:
17328
diff
changeset
|
77 } |
98e60bdf6d05
Use ArithmeticOpTable for primitive convert operations.
Roland Schatz <roland.schatz@oracle.com>
parents:
17328
diff
changeset
|
78 |
98e60bdf6d05
Use ArithmeticOpTable for primitive convert operations.
Roland Schatz <roland.schatz@oracle.com>
parents:
17328
diff
changeset
|
79 @Override |
18720
ab9d3ff6829b
Pass constant reflection into ConvertNode.convert
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18646
diff
changeset
|
80 public Constant reverse(Constant c, ConstantReflectionProvider constantReflection) { |
17419
83c3dd41ca64
Simplify ArithmeticOpTable implementation and make it type safe.
Roland Schatz <roland.schatz@oracle.com>
parents:
17418
diff
changeset
|
81 IntegerConvertOp<REV> reverse = getReverseOp.apply(ArithmeticOpTable.forStamp(stamp())); |
17418
393fe459eadc
Don't cache op field in arithmetic nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
17369
diff
changeset
|
82 return reverse.foldConstant(getResultBits(), getInputBits(), c); |
17344
98e60bdf6d05
Use ArithmeticOpTable for primitive convert operations.
Roland Schatz <roland.schatz@oracle.com>
parents:
17328
diff
changeset
|
83 } |
98e60bdf6d05
Use ArithmeticOpTable for primitive convert operations.
Roland Schatz <roland.schatz@oracle.com>
parents:
17328
diff
changeset
|
84 |
98e60bdf6d05
Use ArithmeticOpTable for primitive convert operations.
Roland Schatz <roland.schatz@oracle.com>
parents:
17328
diff
changeset
|
85 @Override |
98e60bdf6d05
Use ArithmeticOpTable for primitive convert operations.
Roland Schatz <roland.schatz@oracle.com>
parents:
17328
diff
changeset
|
86 public boolean inferStamp() { |
18124
689092d5cf44
Store explicit input bit width in IntegerConvertNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
17419
diff
changeset
|
87 return updateStamp(getOp(getValue()).foldStamp(inputBits, resultBits, getValue().stamp())); |
17344
98e60bdf6d05
Use ArithmeticOpTable for primitive convert operations.
Roland Schatz <roland.schatz@oracle.com>
parents:
17328
diff
changeset
|
88 } |
98e60bdf6d05
Use ArithmeticOpTable for primitive convert operations.
Roland Schatz <roland.schatz@oracle.com>
parents:
17328
diff
changeset
|
89 |
98e60bdf6d05
Use ArithmeticOpTable for primitive convert operations.
Roland Schatz <roland.schatz@oracle.com>
parents:
17328
diff
changeset
|
90 @Override |
98e60bdf6d05
Use ArithmeticOpTable for primitive convert operations.
Roland Schatz <roland.schatz@oracle.com>
parents:
17328
diff
changeset
|
91 public ValueNode canonical(CanonicalizerTool tool, ValueNode forValue) { |
19364
2d6a2f18fe8c
Add graph builder folding support for integer conversion nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18845
diff
changeset
|
92 ValueNode synonym = findSynonym(getOp(forValue), forValue, inputBits, resultBits, stamp()); |
2d6a2f18fe8c
Add graph builder folding support for integer conversion nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18845
diff
changeset
|
93 if (synonym != null) { |
2d6a2f18fe8c
Add graph builder folding support for integer conversion nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18845
diff
changeset
|
94 return synonym; |
2d6a2f18fe8c
Add graph builder folding support for integer conversion nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18845
diff
changeset
|
95 } |
2d6a2f18fe8c
Add graph builder folding support for integer conversion nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18845
diff
changeset
|
96 return this; |
2d6a2f18fe8c
Add graph builder folding support for integer conversion nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18845
diff
changeset
|
97 } |
2d6a2f18fe8c
Add graph builder folding support for integer conversion nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18845
diff
changeset
|
98 |
2d6a2f18fe8c
Add graph builder folding support for integer conversion nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18845
diff
changeset
|
99 protected static <T> ValueNode findSynonym(IntegerConvertOp<T> operation, ValueNode value, int inputBits, int resultBits, Stamp stamp) { |
18124
689092d5cf44
Store explicit input bit width in IntegerConvertNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
17419
diff
changeset
|
100 if (inputBits == resultBits) { |
689092d5cf44
Store explicit input bit width in IntegerConvertNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
17419
diff
changeset
|
101 return value; |
689092d5cf44
Store explicit input bit width in IntegerConvertNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
17419
diff
changeset
|
102 } else if (value.isConstant()) { |
19364
2d6a2f18fe8c
Add graph builder folding support for integer conversion nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18845
diff
changeset
|
103 return ConstantNode.forPrimitive(stamp, operation.foldConstant(inputBits, resultBits, value.asConstant())); |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
104 } |
19364
2d6a2f18fe8c
Add graph builder folding support for integer conversion nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18845
diff
changeset
|
105 return null; |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
106 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
107 |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
108 public static ValueNode convert(ValueNode input, Stamp stamp) { |
15756
10830a8ab30d
ConditionalNode's boolean materialization canonicalization needs to insert a convert
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
15413
diff
changeset
|
109 return convert(input, stamp, false); |
10830a8ab30d
ConditionalNode's boolean materialization canonicalization needs to insert a convert
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
15413
diff
changeset
|
110 } |
10830a8ab30d
ConditionalNode's boolean materialization canonicalization needs to insert a convert
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
15413
diff
changeset
|
111 |
16248
c5b2a3c22318
refactor more Canonicalizable implementations to not add new nodes to the graph
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16216
diff
changeset
|
112 public static ValueNode convert(ValueNode input, Stamp stamp, StructuredGraph graph) { |
c5b2a3c22318
refactor more Canonicalizable implementations to not add new nodes to the graph
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16216
diff
changeset
|
113 ValueNode convert = convert(input, stamp, false); |
c5b2a3c22318
refactor more Canonicalizable implementations to not add new nodes to the graph
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16216
diff
changeset
|
114 if (!convert.isAlive()) { |
c5b2a3c22318
refactor more Canonicalizable implementations to not add new nodes to the graph
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16216
diff
changeset
|
115 assert !convert.isDeleted(); |
c5b2a3c22318
refactor more Canonicalizable implementations to not add new nodes to the graph
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16216
diff
changeset
|
116 convert = graph.addOrUnique(convert); |
c5b2a3c22318
refactor more Canonicalizable implementations to not add new nodes to the graph
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16216
diff
changeset
|
117 } |
c5b2a3c22318
refactor more Canonicalizable implementations to not add new nodes to the graph
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16216
diff
changeset
|
118 return convert; |
c5b2a3c22318
refactor more Canonicalizable implementations to not add new nodes to the graph
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16216
diff
changeset
|
119 } |
c5b2a3c22318
refactor more Canonicalizable implementations to not add new nodes to the graph
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16216
diff
changeset
|
120 |
15756
10830a8ab30d
ConditionalNode's boolean materialization canonicalization needs to insert a convert
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
15413
diff
changeset
|
121 public static ValueNode convertUnsigned(ValueNode input, Stamp stamp) { |
10830a8ab30d
ConditionalNode's boolean materialization canonicalization needs to insert a convert
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
15413
diff
changeset
|
122 return convert(input, stamp, true); |
10830a8ab30d
ConditionalNode's boolean materialization canonicalization needs to insert a convert
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
15413
diff
changeset
|
123 } |
10830a8ab30d
ConditionalNode's boolean materialization canonicalization needs to insert a convert
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
15413
diff
changeset
|
124 |
10830a8ab30d
ConditionalNode's boolean materialization canonicalization needs to insert a convert
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
15413
diff
changeset
|
125 public static ValueNode convert(ValueNode input, Stamp stamp, boolean zeroExtend) { |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
126 IntegerStamp fromStamp = (IntegerStamp) input.stamp(); |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
127 IntegerStamp toStamp = (IntegerStamp) stamp; |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
128 |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
129 ValueNode result; |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
130 if (toStamp.getBits() == fromStamp.getBits()) { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
131 result = input; |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
132 } else if (toStamp.getBits() < fromStamp.getBits()) { |
18845
f57d86eb036f
removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents:
18720
diff
changeset
|
133 result = new NarrowNode(input, fromStamp.getBits(), toStamp.getBits()); |
15756
10830a8ab30d
ConditionalNode's boolean materialization canonicalization needs to insert a convert
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
15413
diff
changeset
|
134 } else if (zeroExtend) { |
10830a8ab30d
ConditionalNode's boolean materialization canonicalization needs to insert a convert
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
15413
diff
changeset
|
135 // toStamp.getBits() > fromStamp.getBits() |
18845
f57d86eb036f
removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents:
18720
diff
changeset
|
136 result = new ZeroExtendNode(input, toStamp.getBits()); |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
137 } else { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
138 // toStamp.getBits() > fromStamp.getBits() |
18845
f57d86eb036f
removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents:
18720
diff
changeset
|
139 result = new SignExtendNode(input, toStamp.getBits()); |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
140 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
141 |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
142 IntegerStamp resultStamp = (IntegerStamp) result.stamp(); |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
143 assert toStamp.getBits() == resultStamp.getBits(); |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14707
diff
changeset
|
144 return result; |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
145 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
146 } |