annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/AndNode.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 f7c6b33489c9
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 /*
19396
7e2c87dae93e Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19371
diff changeset
2 * Copyright (c) 2011, 2015, 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
17196
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 16982
diff changeset
25 import com.oracle.graal.api.code.*;
5507
dc71b06d09f8 Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5504
diff changeset
26 import com.oracle.graal.api.meta.*;
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.*;
19371
1e49642dd130 More constant folding during parsing for arithmetic nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18998
diff changeset
28 import com.oracle.graal.compiler.common.type.ArithmeticOpTable.*;
1e49642dd130 More constant folding during parsing for arithmetic nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18998
diff changeset
29 import com.oracle.graal.compiler.common.type.ArithmeticOpTable.BinaryOp.*;
19396
7e2c87dae93e Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19371
diff changeset
30 import com.oracle.graal.graph.*;
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
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.*;
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
34 import com.oracle.graal.nodes.*;
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
35 import com.oracle.graal.nodes.spi.*;
16217
561070049e73 implement Canonicalizable.Binary in the BinaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16215
diff changeset
36 import com.oracle.graal.nodes.util.*;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
37
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
38 @NodeInfo(shortName = "&")
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
39 public final class AndNode extends BinaryArithmeticNode<And> implements NarrowableArithmeticNode {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
40
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
41 public static final NodeClass<AndNode> TYPE = NodeClass.create(AndNode.class);
19396
7e2c87dae93e Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19371
diff changeset
42
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18646
diff changeset
43 public AndNode(ValueNode x, ValueNode y) {
19396
7e2c87dae93e Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19371
diff changeset
44 super(TYPE, ArithmeticOpTable::getAnd, x, y);
11851
04b039d82e86 Simplify constant folding.
Roland Schatz <roland.schatz@oracle.com>
parents: 11289
diff changeset
45 }
04b039d82e86 Simplify constant folding.
Roland Schatz <roland.schatz@oracle.com>
parents: 11289
diff changeset
46
19371
1e49642dd130 More constant folding during parsing for arithmetic nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18998
diff changeset
47 public static ValueNode create(ValueNode x, ValueNode y) {
1e49642dd130 More constant folding during parsing for arithmetic nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18998
diff changeset
48 BinaryOp<And> op = ArithmeticOpTable.forStamp(x.stamp()).getAnd();
1e49642dd130 More constant folding during parsing for arithmetic nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18998
diff changeset
49 Stamp stamp = op.foldStamp(x.stamp(), y.stamp());
1e49642dd130 More constant folding during parsing for arithmetic nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18998
diff changeset
50 ConstantNode tryConstantFold = tryConstantFold(op, x, y, stamp);
1e49642dd130 More constant folding during parsing for arithmetic nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18998
diff changeset
51 if (tryConstantFold != null) {
1e49642dd130 More constant folding during parsing for arithmetic nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18998
diff changeset
52 return tryConstantFold;
1e49642dd130 More constant folding during parsing for arithmetic nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18998
diff changeset
53 } else {
1e49642dd130 More constant folding during parsing for arithmetic nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18998
diff changeset
54 return new AndNode(x, y);
1e49642dd130 More constant folding during parsing for arithmetic nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18998
diff changeset
55 }
1e49642dd130 More constant folding during parsing for arithmetic nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18998
diff changeset
56 }
1e49642dd130 More constant folding during parsing for arithmetic nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18998
diff changeset
57
11851
04b039d82e86 Simplify constant folding.
Roland Schatz <roland.schatz@oracle.com>
parents: 11289
diff changeset
58 @Override
16217
561070049e73 implement Canonicalizable.Binary in the BinaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16215
diff changeset
59 public ValueNode canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) {
17199
88012c1750a0 Move bit logic nodes into the arithmetic node hierarchies.
Roland Schatz <roland.schatz@oracle.com>
parents: 17197
diff changeset
60 ValueNode ret = super.canonical(tool, forX, forY);
88012c1750a0 Move bit logic nodes into the arithmetic node hierarchies.
Roland Schatz <roland.schatz@oracle.com>
parents: 17197
diff changeset
61 if (ret != this) {
88012c1750a0 Move bit logic nodes into the arithmetic node hierarchies.
Roland Schatz <roland.schatz@oracle.com>
parents: 17197
diff changeset
62 return ret;
88012c1750a0 Move bit logic nodes into the arithmetic node hierarchies.
Roland Schatz <roland.schatz@oracle.com>
parents: 17197
diff changeset
63 }
88012c1750a0 Move bit logic nodes into the arithmetic node hierarchies.
Roland Schatz <roland.schatz@oracle.com>
parents: 17197
diff changeset
64
16217
561070049e73 implement Canonicalizable.Binary in the BinaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16215
diff changeset
65 if (GraphUtil.unproxify(forX) == GraphUtil.unproxify(forY)) {
561070049e73 implement Canonicalizable.Binary in the BinaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16215
diff changeset
66 return forX;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
67 }
16217
561070049e73 implement Canonicalizable.Binary in the BinaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16215
diff changeset
68 if (forX.isConstant() && !forY.isConstant()) {
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18646
diff changeset
69 return new AndNode(forY, forX);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
70 }
17199
88012c1750a0 Move bit logic nodes into the arithmetic node hierarchies.
Roland Schatz <roland.schatz@oracle.com>
parents: 17197
diff changeset
71 if (forY.isConstant()) {
18188
8652481a1110 Introduce new Constant interface for use in high-level graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 18187
diff changeset
72 Constant c = forY.asConstant();
17418
393fe459eadc Don't cache op field in arithmetic nodes.
Roland Schatz <roland.schatz@oracle.com>
parents: 17309
diff changeset
73 if (getOp(forX, forY).isNeutral(c)) {
16217
561070049e73 implement Canonicalizable.Binary in the BinaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16215
diff changeset
74 return forX;
14024
34c07ef28bc9 Support integer arithmetic for arbitrary types.
Roland Schatz <roland.schatz@oracle.com>
parents: 11883
diff changeset
75 }
17199
88012c1750a0 Move bit logic nodes into the arithmetic node hierarchies.
Roland Schatz <roland.schatz@oracle.com>
parents: 17197
diff changeset
76
18188
8652481a1110 Introduce new Constant interface for use in high-level graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 18187
diff changeset
77 if (c instanceof PrimitiveConstant && ((PrimitiveConstant) c).getKind().isNumericInteger()) {
8652481a1110 Introduce new Constant interface for use in high-level graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 18187
diff changeset
78 long rawY = ((PrimitiveConstant) c).asLong();
17199
88012c1750a0 Move bit logic nodes into the arithmetic node hierarchies.
Roland Schatz <roland.schatz@oracle.com>
parents: 17197
diff changeset
79 long mask = CodeUtil.mask(PrimitiveStamp.getBits(stamp()));
88012c1750a0 Move bit logic nodes into the arithmetic node hierarchies.
Roland Schatz <roland.schatz@oracle.com>
parents: 17197
diff changeset
80 if ((rawY & mask) == 0) {
88012c1750a0 Move bit logic nodes into the arithmetic node hierarchies.
Roland Schatz <roland.schatz@oracle.com>
parents: 17197
diff changeset
81 return ConstantNode.forIntegerStamp(stamp(), 0);
15038
5f6603f00e49 minor sign/zero extension tweaks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 14950
diff changeset
82 }
17199
88012c1750a0 Move bit logic nodes into the arithmetic node hierarchies.
Roland Schatz <roland.schatz@oracle.com>
parents: 17197
diff changeset
83 if (forX instanceof SignExtendNode) {
88012c1750a0 Move bit logic nodes into the arithmetic node hierarchies.
Roland Schatz <roland.schatz@oracle.com>
parents: 17197
diff changeset
84 SignExtendNode ext = (SignExtendNode) forX;
88012c1750a0 Move bit logic nodes into the arithmetic node hierarchies.
Roland Schatz <roland.schatz@oracle.com>
parents: 17197
diff changeset
85 if (rawY == ((1L << ext.getInputBits()) - 1)) {
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18646
diff changeset
86 return new ZeroExtendNode(ext.getValue(), ext.getResultBits());
17199
88012c1750a0 Move bit logic nodes into the arithmetic node hierarchies.
Roland Schatz <roland.schatz@oracle.com>
parents: 17197
diff changeset
87 }
88012c1750a0 Move bit logic nodes into the arithmetic node hierarchies.
Roland Schatz <roland.schatz@oracle.com>
parents: 17197
diff changeset
88 }
16217
561070049e73 implement Canonicalizable.Binary in the BinaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16215
diff changeset
89 IntegerStamp xStamp = (IntegerStamp) forX.stamp();
14593
9e05e9770c1e eliminate useless masking
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 14025
diff changeset
90 if (((xStamp.upMask() | xStamp.downMask()) & ~rawY) == 0) {
9e05e9770c1e eliminate useless masking
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 14025
diff changeset
91 // No bits are set which are outside the mask, so the mask will have no effect.
16217
561070049e73 implement Canonicalizable.Binary in the BinaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16215
diff changeset
92 return forX;
14593
9e05e9770c1e eliminate useless masking
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 14025
diff changeset
93 }
9e05e9770c1e eliminate useless masking
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 14025
diff changeset
94 }
9e05e9770c1e eliminate useless masking
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 14025
diff changeset
95
17199
88012c1750a0 Move bit logic nodes into the arithmetic node hierarchies.
Roland Schatz <roland.schatz@oracle.com>
parents: 17197
diff changeset
96 return reassociate(this, ValueNode.isConstantPredicate(), forX, forY);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
97 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
98 return this;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
99 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
100
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
101 @Override
15130
ec22234bde0d Pass more restricted interfaces to ArithmeticLIRLowerable and LocationNode in LIR generation.
Roland Schatz <roland.schatz@oracle.com>
parents: 14950
diff changeset
102 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: 16156
diff changeset
103 builder.setResult(this, gen.emitAnd(builder.operand(getX()), builder.operand(getY())));
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
104 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
105 }