annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/RightShiftNode.java @ 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
author Doug Simon <doug.simon@oracle.com>
date Mon, 18 Aug 2014 14:04:21 +0200
parents cbd42807a31f
children 0fe4732e5181
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
16215
b558af6ff4bc don't pass stamps to arithmetic node constructors
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16207
diff changeset
2 * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
8 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * accompanied this code).
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * questions.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 */
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
23 package com.oracle.graal.nodes.calc;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24
5507
dc71b06d09f8 Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5504
diff changeset
25 import com.oracle.graal.api.meta.*;
15198
2c0cfbf454b5 Move LIRTypeTool and Stamp to graal.compiler.common.
Josef Eisl <josef.eisl@jku.at>
parents: 15130
diff changeset
26 import com.oracle.graal.compiler.common.type.*;
11881
da9db8331658 moved Canonicalizable and Simplifiable to the com.oracle.graal.graph project (GRAAL-506)
Doug Simon <doug.simon@oracle.com>
parents: 11880
diff changeset
27 import com.oracle.graal.graph.spi.*;
15299
60406b8d6ad1 Move ArithmeticLIRGenerator to graal.lir (errors).
Josef Eisl <josef.eisl@jku.at>
parents: 15261
diff changeset
28 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: 16811
diff changeset
29 import com.oracle.graal.nodeinfo.*;
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
30 import com.oracle.graal.nodes.*;
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
31 import com.oracle.graal.nodes.spi.*;
16585
0d3a4532a28c better stamps for RightShiftNode
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16217
diff changeset
32 import com.oracle.graal.nodes.type.*;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
33
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
34 @NodeInfo(shortName = ">>")
16811
5d468add216f added @NodeInfo annotations to all Node classes
Doug Simon <doug.simon@oracle.com>
parents: 16585
diff changeset
35 public class RightShiftNode extends ShiftNode {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
36
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
37 public static RightShiftNode create(ValueNode x, ValueNode y) {
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
38 return new RightShiftNodeGen(x, y);
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
39 }
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
40
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
41 protected RightShiftNode(ValueNode x, ValueNode y) {
16215
b558af6ff4bc don't pass stamps to arithmetic node constructors
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16207
diff changeset
42 super(x, y);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
43 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
44
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
45 @Override
16585
0d3a4532a28c better stamps for RightShiftNode
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16217
diff changeset
46 public boolean inferStamp() {
0d3a4532a28c better stamps for RightShiftNode
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16217
diff changeset
47 return updateStamp(StampTool.rightShift(getX().stamp(), getY().stamp()));
0d3a4532a28c better stamps for RightShiftNode
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16217
diff changeset
48 }
0d3a4532a28c better stamps for RightShiftNode
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16217
diff changeset
49
0d3a4532a28c better stamps for RightShiftNode
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16217
diff changeset
50 @Override
11851
04b039d82e86 Simplify constant folding.
Roland Schatz <roland.schatz@oracle.com>
parents: 11289
diff changeset
51 public Constant evalConst(Constant... inputs) {
04b039d82e86 Simplify constant folding.
Roland Schatz <roland.schatz@oracle.com>
parents: 11289
diff changeset
52 assert inputs.length == 2;
14633
da2431cc1506 Rename ValueNode kind() to getKind().
Josef Eisl <josef.eisl@jku.at>
parents: 14024
diff changeset
53 if (getKind() == Kind.Int) {
11851
04b039d82e86 Simplify constant folding.
Roland Schatz <roland.schatz@oracle.com>
parents: 11289
diff changeset
54 return Constant.forInt(inputs[0].asInt() >> inputs[1].asInt());
04b039d82e86 Simplify constant folding.
Roland Schatz <roland.schatz@oracle.com>
parents: 11289
diff changeset
55 } else {
14633
da2431cc1506 Rename ValueNode kind() to getKind().
Josef Eisl <josef.eisl@jku.at>
parents: 14024
diff changeset
56 assert getKind() == Kind.Long;
11851
04b039d82e86 Simplify constant folding.
Roland Schatz <roland.schatz@oracle.com>
parents: 11289
diff changeset
57 return Constant.forLong(inputs[0].asLong() >> inputs[1].asLong());
04b039d82e86 Simplify constant folding.
Roland Schatz <roland.schatz@oracle.com>
parents: 11289
diff changeset
58 }
04b039d82e86 Simplify constant folding.
Roland Schatz <roland.schatz@oracle.com>
parents: 11289
diff changeset
59 }
04b039d82e86 Simplify constant folding.
Roland Schatz <roland.schatz@oracle.com>
parents: 11289
diff changeset
60
04b039d82e86 Simplify constant folding.
Roland Schatz <roland.schatz@oracle.com>
parents: 11289
diff changeset
61 @Override
16217
561070049e73 implement Canonicalizable.Binary in the BinaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16215
diff changeset
62 public ValueNode canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) {
561070049e73 implement Canonicalizable.Binary in the BinaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16215
diff changeset
63 if (forX.stamp() instanceof IntegerStamp && ((IntegerStamp) forX.stamp()).isPositive()) {
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
64 return UnsignedRightShiftNode.create(forX, forY);
5657
d71eb56d6bb0 new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents: 5540
diff changeset
65 }
16217
561070049e73 implement Canonicalizable.Binary in the BinaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16215
diff changeset
66 if (forX.isConstant() && forY.isConstant()) {
561070049e73 implement Canonicalizable.Binary in the BinaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16215
diff changeset
67 return ConstantNode.forPrimitive(evalConst(forX.asConstant(), forY.asConstant()));
561070049e73 implement Canonicalizable.Binary in the BinaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16215
diff changeset
68 } else if (forY.isConstant()) {
561070049e73 implement Canonicalizable.Binary in the BinaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16215
diff changeset
69 int amount = forY.asConstant().asInt();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
70 int originalAmout = amount;
14711
ba4b79da6351 canonicalize certain shift-compare expressions
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14633
diff changeset
71 int mask = getShiftAmountMask();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
72 amount &= mask;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
73 if (amount == 0) {
16217
561070049e73 implement Canonicalizable.Binary in the BinaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16215
diff changeset
74 return forX;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
75 }
16217
561070049e73 implement Canonicalizable.Binary in the BinaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16215
diff changeset
76 if (forX instanceof ShiftNode) {
561070049e73 implement Canonicalizable.Binary in the BinaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16215
diff changeset
77 ShiftNode other = (ShiftNode) forX;
16207
df6f2365b153 rename of x() to getX(), y() to getY() and object() to getValue()
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15299
diff changeset
78 if (other.getY().isConstant()) {
df6f2365b153 rename of x() to getX(), y() to getY() and object() to getValue()
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15299
diff changeset
79 int otherAmount = other.getY().asConstant().asInt() & mask;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
80 if (other instanceof RightShiftNode) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
81 int total = amount + otherAmount;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
82 if (total != (total & mask)) {
16207
df6f2365b153 rename of x() to getX(), y() to getY() and object() to getValue()
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15299
diff changeset
83 assert other.getX().stamp() instanceof IntegerStamp;
df6f2365b153 rename of x() to getX(), y() to getY() and object() to getValue()
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15299
diff changeset
84 IntegerStamp istamp = (IntegerStamp) other.getX().stamp();
10603
2e7e7a22940f RightShiftNode: fix canonicalization for negative input
Bernhard Urban <bernhard.urban@jku.at>
parents: 10575
diff changeset
85
2e7e7a22940f RightShiftNode: fix canonicalization for negative input
Bernhard Urban <bernhard.urban@jku.at>
parents: 10575
diff changeset
86 if (istamp.isPositive()) {
16217
561070049e73 implement Canonicalizable.Binary in the BinaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16215
diff changeset
87 return ConstantNode.forIntegerKind(getKind(), 0);
10603
2e7e7a22940f RightShiftNode: fix canonicalization for negative input
Bernhard Urban <bernhard.urban@jku.at>
parents: 10575
diff changeset
88 }
2e7e7a22940f RightShiftNode: fix canonicalization for negative input
Bernhard Urban <bernhard.urban@jku.at>
parents: 10575
diff changeset
89 if (istamp.isStrictlyNegative()) {
16217
561070049e73 implement Canonicalizable.Binary in the BinaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16215
diff changeset
90 return ConstantNode.forIntegerKind(getKind(), -1L);
10603
2e7e7a22940f RightShiftNode: fix canonicalization for negative input
Bernhard Urban <bernhard.urban@jku.at>
parents: 10575
diff changeset
91 }
2e7e7a22940f RightShiftNode: fix canonicalization for negative input
Bernhard Urban <bernhard.urban@jku.at>
parents: 10575
diff changeset
92
2e7e7a22940f RightShiftNode: fix canonicalization for negative input
Bernhard Urban <bernhard.urban@jku.at>
parents: 10575
diff changeset
93 /*
2e7e7a22940f RightShiftNode: fix canonicalization for negative input
Bernhard Urban <bernhard.urban@jku.at>
parents: 10575
diff changeset
94 * if we cannot replace both shifts with a constant, replace them by a
2e7e7a22940f RightShiftNode: fix canonicalization for negative input
Bernhard Urban <bernhard.urban@jku.at>
parents: 10575
diff changeset
95 * full shift for this kind
2e7e7a22940f RightShiftNode: fix canonicalization for negative input
Bernhard Urban <bernhard.urban@jku.at>
parents: 10575
diff changeset
96 */
2e7e7a22940f RightShiftNode: fix canonicalization for negative input
Bernhard Urban <bernhard.urban@jku.at>
parents: 10575
diff changeset
97 assert total >= mask;
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
98 return RightShiftNode.create(other.getX(), ConstantNode.forInt(mask));
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
99 }
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
100 return RightShiftNode.create(other.getX(), ConstantNode.forInt(total));
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
101 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
102 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
103 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
104 if (originalAmout != amount) {
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
105 return RightShiftNode.create(forX, ConstantNode.forInt(amount));
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
106 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
107 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
108 return this;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
109 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
110
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
111 @Override
15130
ec22234bde0d Pass more restricted interfaces to ArithmeticLIRLowerable and LocationNode in LIR generation.
Roland Schatz <roland.schatz@oracle.com>
parents: 14950
diff changeset
112 public void generate(NodeMappableLIRBuilder builder, ArithmeticLIRGenerator gen) {
16207
df6f2365b153 rename of x() to getX(), y() to getY() and object() to getValue()
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15299
diff changeset
113 builder.setResult(this, gen.emitShr(builder.operand(getX()), builder.operand(getY())));
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
114 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
115 }