annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/ZeroExtendNode.java @ 19526: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 61d3cb8e1280
children 93c50cefb9e8
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
17196
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 16919
diff changeset
25 import com.oracle.graal.api.code.*;
15414
997bfb063417 Fix bug in CompareNode canonicalization.
Roland Schatz <roland.schatz@oracle.com>
parents: 15413
diff changeset
26 import com.oracle.graal.compiler.common.calc.*;
15198
2c0cfbf454b5 Move LIRTypeTool and Stamp to graal.compiler.common.
Josef Eisl <josef.eisl@jku.at>
parents: 15132
diff changeset
27 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: 18845
diff changeset
28 import com.oracle.graal.compiler.common.type.ArithmeticOpTable.*;
2d6a2f18fe8c Add graph builder folding support for integer conversion nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18845
diff changeset
29 import com.oracle.graal.compiler.common.type.ArithmeticOpTable.IntegerConvertOp.*;
19396
7e2c87dae93e Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19364
diff changeset
30 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
31 import com.oracle.graal.graph.spi.*;
15299
60406b8d6ad1 Move ArithmeticLIRGenerator to graal.lir (errors).
Josef Eisl <josef.eisl@jku.at>
parents: 15198
diff changeset
32 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
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 * The {@code ZeroExtendNode} converts an integer to a wider integer using zero extension.
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
39 */
16822
5d468add216f added @NodeInfo annotations to all Node classes
Doug Simon <doug.simon@oracle.com>
parents: 16216
diff changeset
40 @NodeInfo
19396
7e2c87dae93e Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19364
diff changeset
41 public final class ZeroExtendNode extends IntegerConvertNode<ZeroExtend, Narrow> {
7e2c87dae93e Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19364
diff changeset
42
19526
8fc336a04d77 Create TYPE fields for LIRInstruction and CompositeValue. Renaming NodeClass#get to NodeClass#create.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19403
diff changeset
43 public static final NodeClass<ZeroExtendNode> TYPE = NodeClass.create(ZeroExtendNode.class);
14000
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
44
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18646
diff changeset
45 public ZeroExtendNode(ValueNode input, int resultBits) {
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18646
diff changeset
46 this(input, PrimitiveStamp.getBits(input.stamp()), resultBits);
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18646
diff changeset
47 assert 0 < PrimitiveStamp.getBits(input.stamp()) && PrimitiveStamp.getBits(input.stamp()) <= resultBits;
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
48 }
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
49
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18646
diff changeset
50 public ZeroExtendNode(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
51 super(TYPE, ArithmeticOpTable::getZeroExtend, ArithmeticOpTable::getNarrow, inputBits, resultBits, input);
14000
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
52 }
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
53
19364
2d6a2f18fe8c Add graph builder folding support for integer conversion nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18845
diff changeset
54 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: 18845
diff changeset
55 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: 18845
diff changeset
56 }
2d6a2f18fe8c Add graph builder folding support for integer conversion nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18845
diff changeset
57
2d6a2f18fe8c Add graph builder folding support for integer conversion nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18845
diff changeset
58 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: 18845
diff changeset
59 IntegerConvertOp<ZeroExtend> signExtend = ArithmeticOpTable.forStamp(input.stamp()).getZeroExtend();
2d6a2f18fe8c Add graph builder folding support for integer conversion nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18845
diff changeset
60 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: 18845
diff changeset
61 if (synonym != null) {
2d6a2f18fe8c Add graph builder folding support for integer conversion nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18845
diff changeset
62 return synonym;
2d6a2f18fe8c Add graph builder folding support for integer conversion nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18845
diff changeset
63 } else {
2d6a2f18fe8c Add graph builder folding support for integer conversion nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18845
diff changeset
64 return new ZeroExtendNode(input, inputBits, resultBits);
2d6a2f18fe8c Add graph builder folding support for integer conversion nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18845
diff changeset
65 }
2d6a2f18fe8c Add graph builder folding support for integer conversion nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18845
diff changeset
66 }
2d6a2f18fe8c Add graph builder folding support for integer conversion nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18845
diff changeset
67
14000
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
68 @Override
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
69 public boolean isLossless() {
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
70 return true;
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
71 }
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
72
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
73 @Override
17344
98e60bdf6d05 Use ArithmeticOpTable for primitive convert operations.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
74 public boolean preservesOrder(Condition cond) {
98e60bdf6d05 Use ArithmeticOpTable for primitive convert operations.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
75 switch (cond) {
15414
997bfb063417 Fix bug in CompareNode canonicalization.
Roland Schatz <roland.schatz@oracle.com>
parents: 15413
diff changeset
76 case GE:
997bfb063417 Fix bug in CompareNode canonicalization.
Roland Schatz <roland.schatz@oracle.com>
parents: 15413
diff changeset
77 case GT:
997bfb063417 Fix bug in CompareNode canonicalization.
Roland Schatz <roland.schatz@oracle.com>
parents: 15413
diff changeset
78 case LE:
997bfb063417 Fix bug in CompareNode canonicalization.
Roland Schatz <roland.schatz@oracle.com>
parents: 15413
diff changeset
79 case LT:
997bfb063417 Fix bug in CompareNode canonicalization.
Roland Schatz <roland.schatz@oracle.com>
parents: 15413
diff changeset
80 return false;
997bfb063417 Fix bug in CompareNode canonicalization.
Roland Schatz <roland.schatz@oracle.com>
parents: 15413
diff changeset
81 default:
997bfb063417 Fix bug in CompareNode canonicalization.
Roland Schatz <roland.schatz@oracle.com>
parents: 15413
diff changeset
82 return true;
997bfb063417 Fix bug in CompareNode canonicalization.
Roland Schatz <roland.schatz@oracle.com>
parents: 15413
diff changeset
83 }
997bfb063417 Fix bug in CompareNode canonicalization.
Roland Schatz <roland.schatz@oracle.com>
parents: 15413
diff changeset
84 }
997bfb063417 Fix bug in CompareNode canonicalization.
Roland Schatz <roland.schatz@oracle.com>
parents: 15413
diff changeset
85
997bfb063417 Fix bug in CompareNode canonicalization.
Roland Schatz <roland.schatz@oracle.com>
parents: 15413
diff changeset
86 @Override
16216
388b787a5fe6 implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16156
diff changeset
87 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
88 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
89 if (ret != this) {
14025
9738280055ce Reduce bit width of integer operations where possible.
Roland Schatz <roland.schatz@oracle.com>
parents: 14000
diff changeset
90 return ret;
9738280055ce Reduce bit width of integer operations where possible.
Roland Schatz <roland.schatz@oracle.com>
parents: 14000
diff changeset
91 }
9738280055ce Reduce bit width of integer operations where possible.
Roland Schatz <roland.schatz@oracle.com>
parents: 14000
diff changeset
92
16216
388b787a5fe6 implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16156
diff changeset
93 if (forValue instanceof ZeroExtendNode) {
14026
57a2d00ef771 Source comments in integer conversion nodes.
Roland Schatz <roland.schatz@oracle.com>
parents: 14025
diff changeset
94 // xxxx -(zero-extend)-> 0000 xxxx -(zero-extend)-> 00000000 0000xxxx
57a2d00ef771 Source comments in integer conversion nodes.
Roland Schatz <roland.schatz@oracle.com>
parents: 14025
diff changeset
95 // ==> xxxx -(zero-extend)-> 00000000 0000xxxx
16216
388b787a5fe6 implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16156
diff changeset
96 ZeroExtendNode other = (ZeroExtendNode) forValue;
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18646
diff changeset
97 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
98 }
16216
388b787a5fe6 implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16156
diff changeset
99 if (forValue instanceof NarrowNode) {
388b787a5fe6 implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16156
diff changeset
100 NarrowNode narrow = (NarrowNode) forValue;
16156
0993768dfc8e new UnaryNode base class
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15414
diff changeset
101 Stamp inputStamp = narrow.getValue().stamp();
15038
5f6603f00e49 minor sign/zero extension tweaks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 14950
diff changeset
102 if (inputStamp instanceof IntegerStamp && inputStamp.isCompatible(stamp())) {
5f6603f00e49 minor sign/zero extension tweaks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 14950
diff changeset
103 IntegerStamp istamp = (IntegerStamp) inputStamp;
17196
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 16919
diff changeset
104 long mask = CodeUtil.mask(PrimitiveStamp.getBits(narrow.stamp()));
15038
5f6603f00e49 minor sign/zero extension tweaks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 14950
diff changeset
105 if (((istamp.upMask() | istamp.downMask()) & ~mask) == 0) {
5f6603f00e49 minor sign/zero extension tweaks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 14950
diff changeset
106 // The original value is in the range of the masked zero extended result so
5f6603f00e49 minor sign/zero extension tweaks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 14950
diff changeset
107 // simply return the original input.
16156
0993768dfc8e new UnaryNode base class
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15414
diff changeset
108 return narrow.getValue();
15038
5f6603f00e49 minor sign/zero extension tweaks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 14950
diff changeset
109 }
5f6603f00e49 minor sign/zero extension tweaks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 14950
diff changeset
110 }
5f6603f00e49 minor sign/zero extension tweaks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 14950
diff changeset
111 }
14000
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
112
14025
9738280055ce Reduce bit width of integer operations where possible.
Roland Schatz <roland.schatz@oracle.com>
parents: 14000
diff changeset
113 return this;
14000
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
114 }
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
115
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
116 @Override
15130
ec22234bde0d Pass more restricted interfaces to ArithmeticLIRLowerable and LocationNode in LIR generation.
Roland Schatz <roland.schatz@oracle.com>
parents: 14950
diff changeset
117 public void generate(NodeMappableLIRBuilder builder, ArithmeticLIRGenerator gen) {
16156
0993768dfc8e new UnaryNode base class
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15414
diff changeset
118 builder.setResult(this, gen.emitZeroExtend(builder.operand(getValue()), getInputBits(), getResultBits()));
14000
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
119 }
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
120 }