annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/NarrowNode.java @ 19403:61d3cb8e1280

Add generic parameter to NodeClass. Change Graph#getNodes(Class) to Graph#getNodes(NodeClass).
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Mon, 16 Feb 2015 17:47:43 +0100
parents 7e2c87dae93e
children 8fc336a04d77
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14000
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
1 /*
19396
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
17344
98e60bdf6d05 Use ArithmeticOpTable for primitive convert operations.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
25 import com.oracle.graal.compiler.common.type.*;
19364
2d6a2f18fe8c Add graph builder folding support for integer conversion nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18998
diff changeset
26 import com.oracle.graal.compiler.common.type.ArithmeticOpTable.*;
17419
83c3dd41ca64 Simplify ArithmeticOpTable implementation and make it type safe.
Roland Schatz <roland.schatz@oracle.com>
parents: 17418
diff changeset
27 import com.oracle.graal.compiler.common.type.ArithmeticOpTable.IntegerConvertOp.Narrow;
83c3dd41ca64 Simplify ArithmeticOpTable implementation and make it type safe.
Roland Schatz <roland.schatz@oracle.com>
parents: 17418
diff changeset
28 import com.oracle.graal.compiler.common.type.ArithmeticOpTable.IntegerConvertOp.SignExtend;
19396
7e2c87dae93e Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19364
diff changeset
29 import com.oracle.graal.graph.*;
14000
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
30 import com.oracle.graal.graph.spi.*;
15299
60406b8d6ad1 Move ArithmeticLIRGenerator to graal.lir (errors).
Josef Eisl <josef.eisl@jku.at>
parents: 15261
diff changeset
31 import com.oracle.graal.lir.gen.*;
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: 16822
diff changeset
32 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
33 import com.oracle.graal.nodes.*;
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.spi.*;
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
35
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 * The {@code NarrowNode} converts an integer to a narrower integer.
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
38 */
16822
5d468add216f added @NodeInfo annotations to all Node classes
Doug Simon <doug.simon@oracle.com>
parents: 16216
diff changeset
39 @NodeInfo
18998
ec0733b5a90a Allow final modifier on node subclasses and start adding the modifier to leaf classes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18845
diff changeset
40 public final class NarrowNode extends IntegerConvertNode<Narrow, SignExtend> {
14000
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
41
19403
61d3cb8e1280 Add generic parameter to NodeClass. Change Graph#getNodes(Class) to Graph#getNodes(NodeClass).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19396
diff changeset
42 public static final NodeClass<NarrowNode> TYPE = NodeClass.get(NarrowNode.class);
19396
7e2c87dae93e Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19364
diff changeset
43
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18646
diff changeset
44 public NarrowNode(ValueNode input, int resultBits) {
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18646
diff changeset
45 this(input, PrimitiveStamp.getBits(input.stamp()), resultBits);
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18646
diff changeset
46 assert 0 < resultBits && resultBits <= PrimitiveStamp.getBits(input.stamp());
16895
06c15e88d383 added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents: 16841
diff changeset
47 }
06c15e88d383 added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents: 16841
diff changeset
48
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18646
diff changeset
49 public NarrowNode(ValueNode input, int inputBits, int resultBits) {
19396
7e2c87dae93e Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19364
diff changeset
50 super(TYPE, ArithmeticOpTable::getNarrow, ArithmeticOpTable::getSignExtend, inputBits, resultBits, input);
14000
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
51 }
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
52
19364
2d6a2f18fe8c Add graph builder folding support for integer conversion nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18998
diff changeset
53 public static ValueNode create(ValueNode input, int resultBits) {
2d6a2f18fe8c Add graph builder folding support for integer conversion nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18998
diff changeset
54 return create(input, PrimitiveStamp.getBits(input.stamp()), resultBits);
2d6a2f18fe8c Add graph builder folding support for integer conversion nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18998
diff changeset
55 }
2d6a2f18fe8c Add graph builder folding support for integer conversion nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18998
diff changeset
56
2d6a2f18fe8c Add graph builder folding support for integer conversion nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18998
diff changeset
57 public static ValueNode create(ValueNode input, int inputBits, int resultBits) {
2d6a2f18fe8c Add graph builder folding support for integer conversion nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18998
diff changeset
58 IntegerConvertOp<Narrow> signExtend = ArithmeticOpTable.forStamp(input.stamp()).getNarrow();
2d6a2f18fe8c Add graph builder folding support for integer conversion nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18998
diff changeset
59 ValueNode synonym = findSynonym(signExtend, input, inputBits, resultBits, signExtend.foldStamp(inputBits, resultBits, input.stamp()));
2d6a2f18fe8c Add graph builder folding support for integer conversion nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18998
diff changeset
60 if (synonym != null) {
2d6a2f18fe8c Add graph builder folding support for integer conversion nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18998
diff changeset
61 return synonym;
2d6a2f18fe8c Add graph builder folding support for integer conversion nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18998
diff changeset
62 } else {
2d6a2f18fe8c Add graph builder folding support for integer conversion nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18998
diff changeset
63 return new NarrowNode(input, inputBits, resultBits);
2d6a2f18fe8c Add graph builder folding support for integer conversion nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18998
diff changeset
64 }
2d6a2f18fe8c Add graph builder folding support for integer conversion nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18998
diff changeset
65 }
2d6a2f18fe8c Add graph builder folding support for integer conversion nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18998
diff changeset
66
14000
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
67 @Override
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
68 public boolean isLossless() {
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
69 return false;
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
70 }
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
71
14122
2a7d7da912e1 Don't narrow NarrowableArithmetic by default.
Roland Schatz <roland.schatz@oracle.com>
parents: 14026
diff changeset
72 @Override
16216
388b787a5fe6 implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16156
diff changeset
73 public ValueNode canonical(CanonicalizerTool tool, ValueNode forValue) {
17344
98e60bdf6d05 Use ArithmeticOpTable for primitive convert operations.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
74 ValueNode ret = super.canonical(tool, forValue);
16216
388b787a5fe6 implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16156
diff changeset
75 if (ret != this) {
14025
9738280055ce Reduce bit width of integer operations where possible.
Roland Schatz <roland.schatz@oracle.com>
parents: 14000
diff changeset
76 return ret;
9738280055ce Reduce bit width of integer operations where possible.
Roland Schatz <roland.schatz@oracle.com>
parents: 14000
diff changeset
77 }
9738280055ce Reduce bit width of integer operations where possible.
Roland Schatz <roland.schatz@oracle.com>
parents: 14000
diff changeset
78
16216
388b787a5fe6 implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16156
diff changeset
79 if (forValue instanceof NarrowNode) {
14026
57a2d00ef771 Source comments in integer conversion nodes.
Roland Schatz <roland.schatz@oracle.com>
parents: 14025
diff changeset
80 // zzzzzzzz yyyyxxxx -(narrow)-> yyyyxxxx -(narrow)-> xxxx
57a2d00ef771 Source comments in integer conversion nodes.
Roland Schatz <roland.schatz@oracle.com>
parents: 14025
diff changeset
81 // ==> zzzzzzzz yyyyxxxx -(narrow)-> xxxx
16216
388b787a5fe6 implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16156
diff changeset
82 NarrowNode other = (NarrowNode) forValue;
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18646
diff changeset
83 return new NarrowNode(other.getValue(), other.getInputBits(), getResultBits());
16216
388b787a5fe6 implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16156
diff changeset
84 } else if (forValue instanceof IntegerConvertNode) {
14000
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
85 // SignExtendNode or ZeroExtendNode
17419
83c3dd41ca64 Simplify ArithmeticOpTable implementation and make it type safe.
Roland Schatz <roland.schatz@oracle.com>
parents: 17418
diff changeset
86 IntegerConvertNode<?, ?> other = (IntegerConvertNode<?, ?>) forValue;
14000
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
87 if (getResultBits() == other.getInputBits()) {
14026
57a2d00ef771 Source comments in integer conversion nodes.
Roland Schatz <roland.schatz@oracle.com>
parents: 14025
diff changeset
88 // xxxx -(extend)-> yyyy xxxx -(narrow)-> xxxx
57a2d00ef771 Source comments in integer conversion nodes.
Roland Schatz <roland.schatz@oracle.com>
parents: 14025
diff changeset
89 // ==> no-op
16156
0993768dfc8e new UnaryNode base class
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15911
diff changeset
90 return other.getValue();
14000
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
91 } else if (getResultBits() < other.getInputBits()) {
14026
57a2d00ef771 Source comments in integer conversion nodes.
Roland Schatz <roland.schatz@oracle.com>
parents: 14025
diff changeset
92 // yyyyxxxx -(extend)-> zzzzzzzz yyyyxxxx -(narrow)-> xxxx
57a2d00ef771 Source comments in integer conversion nodes.
Roland Schatz <roland.schatz@oracle.com>
parents: 14025
diff changeset
93 // ==> yyyyxxxx -(narrow)-> xxxx
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18646
diff changeset
94 return new NarrowNode(other.getValue(), other.getInputBits(), getResultBits());
14000
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
95 } else {
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
96 if (other instanceof SignExtendNode) {
14026
57a2d00ef771 Source comments in integer conversion nodes.
Roland Schatz <roland.schatz@oracle.com>
parents: 14025
diff changeset
97 // sxxx -(sign-extend)-> ssssssss sssssxxx -(narrow)-> sssssxxx
57a2d00ef771 Source comments in integer conversion nodes.
Roland Schatz <roland.schatz@oracle.com>
parents: 14025
diff changeset
98 // ==> sxxx -(sign-extend)-> sssssxxx
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18646
diff changeset
99 return new SignExtendNode(other.getValue(), other.getInputBits(), getResultBits());
14000
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
100 } else if (other instanceof ZeroExtendNode) {
14026
57a2d00ef771 Source comments in integer conversion nodes.
Roland Schatz <roland.schatz@oracle.com>
parents: 14025
diff changeset
101 // xxxx -(zero-extend)-> 00000000 00000xxx -(narrow)-> 0000xxxx
57a2d00ef771 Source comments in integer conversion nodes.
Roland Schatz <roland.schatz@oracle.com>
parents: 14025
diff changeset
102 // ==> xxxx -(zero-extend)-> 0000xxxx
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18646
diff changeset
103 return new ZeroExtendNode(other.getValue(), other.getInputBits(), getResultBits());
14000
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
104 }
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
105 }
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
106 }
14122
2a7d7da912e1 Don't narrow NarrowableArithmetic by default.
Roland Schatz <roland.schatz@oracle.com>
parents: 14026
diff changeset
107 return this;
14000
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
108 }
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
109
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
110 @Override
15130
ec22234bde0d Pass more restricted interfaces to ArithmeticLIRLowerable and LocationNode in LIR generation.
Roland Schatz <roland.schatz@oracle.com>
parents: 14950
diff changeset
111 public void generate(NodeMappableLIRBuilder builder, ArithmeticLIRGenerator gen) {
16156
0993768dfc8e new UnaryNode base class
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15911
diff changeset
112 builder.setResult(this, gen.emitNarrow(builder.operand(getValue()), getResultBits()));
14000
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
113 }
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
114 }